mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-24 07:29:30 +01:00
add undo/redo disabled/enable
This commit is contained in:
6
packages/editor-mobile/package-lock.json
generated
6
packages/editor-mobile/package-lock.json
generated
@@ -14304,7 +14304,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/notesnook-editor": {
|
"node_modules/notesnook-editor": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "git+ssh://git@github.com/streetwriters/notesnook-editor.git#97094dba0bfdaaede6ab24e65079d6b305fe471c",
|
"resolved": "git+ssh://git@github.com/streetwriters/notesnook-editor.git#09d20523bff6e3bb1cc04327023cfe74c3828e00",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@_ueberdosis/prosemirror-tables": "^1.1.3",
|
"@_ueberdosis/prosemirror-tables": "^1.1.3",
|
||||||
"@mdi/js": "^6.9.96",
|
"@mdi/js": "^6.9.96",
|
||||||
@@ -34152,8 +34152,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"notesnook-editor": {
|
"notesnook-editor": {
|
||||||
"version": "git+ssh://git@github.com/streetwriters/notesnook-editor.git#97094dba0bfdaaede6ab24e65079d6b305fe471c",
|
"version": "git+ssh://git@github.com/streetwriters/notesnook-editor.git#09d20523bff6e3bb1cc04327023cfe74c3828e00",
|
||||||
"from": "notesnook-editor@github:streetwriters/notesnook-editor#develop",
|
"from": "notesnook-editor@https://github.com/streetwriters/notesnook-editor.git#develop",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@_ueberdosis/prosemirror-tables": "^1.1.3",
|
"@_ueberdosis/prosemirror-tables": "^1.1.3",
|
||||||
"@mdi/js": "^6.9.96",
|
"@mdi/js": "^6.9.96",
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ const Tiptap = () => {
|
|||||||
post(EventTypes.pro);
|
post(EventTypes.pro);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const editor = useTiptap(
|
const _editor = useTiptap(
|
||||||
{
|
{
|
||||||
onUpdate: ({ editor }) => {
|
onUpdate: ({ editor }) => {
|
||||||
global.editorController.contentChange(editor as Editor);
|
global.editorController.contentChange(editor as Editor);
|
||||||
@@ -114,10 +114,17 @@ const Tiptap = () => {
|
|||||||
},
|
},
|
||||||
[layout, initialProps.readonly, tick]
|
[layout, initialProps.readonly, tick]
|
||||||
);
|
);
|
||||||
const controller = useEditorController(editor, setTick);
|
|
||||||
|
const update = () => {
|
||||||
|
setTick((tick) => tick + 1);
|
||||||
|
setLayout(false);
|
||||||
|
setImmediate(() => setLayout(true));
|
||||||
|
};
|
||||||
|
|
||||||
|
const controller = useEditorController(_editor, update);
|
||||||
const controllerRef = useRef(controller);
|
const controllerRef = useRef(controller);
|
||||||
globalThis.editorController = controller;
|
globalThis.editorController = controller;
|
||||||
globalThis.editor = editor;
|
globalThis.editor = _editor;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInitialProps({ ...settings });
|
setInitialProps({ ...settings });
|
||||||
@@ -139,8 +146,8 @@ const Tiptap = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Header
|
<Header
|
||||||
hasRedo={false}
|
hasRedo={_editor?.can().redo() || false}
|
||||||
hasUndo={false}
|
hasUndo={_editor?.can().undo() || false}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
noHeader={initialProps.noHeader || false}
|
noHeader={initialProps.noHeader || false}
|
||||||
/>
|
/>
|
||||||
@@ -164,7 +171,7 @@ const Tiptap = () => {
|
|||||||
controller={controllerRef}
|
controller={controllerRef}
|
||||||
title={controller.title}
|
title={controller.title}
|
||||||
/>
|
/>
|
||||||
<StatusBar container={containerRef} editor={editor} />
|
<StatusBar container={containerRef} editor={_editor} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
@@ -192,11 +199,11 @@ const Tiptap = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{initialProps.noToolbar ? null : (
|
{initialProps.noToolbar || !layout ? null : (
|
||||||
<Toolbar
|
<Toolbar
|
||||||
sx={{ pl: "10px", pt: "5px", minHeight: 45 }}
|
sx={{ pl: "10px", pt: "5px", minHeight: 45 }}
|
||||||
theme={toolbarTheme}
|
theme={toolbarTheme}
|
||||||
editor={editor}
|
editor={_editor}
|
||||||
location="bottom"
|
location="bottom"
|
||||||
tools={[...settings.tools]}
|
tools={[...settings.tools]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -115,7 +115,10 @@ export default React.memo(
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ArrowULeftTopIcon size={28} color={"var(--nn_pri)"} />
|
<ArrowULeftTopIcon
|
||||||
|
size={28}
|
||||||
|
color={!hasUndo ? "var(--nn_nav)" : "var(--nn_pri)"}
|
||||||
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -134,7 +137,10 @@ export default React.memo(
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ArrowURightTopIcon size={28} color={"var(--nn_pri)"} />
|
<ArrowURightTopIcon
|
||||||
|
size={28}
|
||||||
|
color={!hasRedo ? "var(--nn_nav)" : "var(--nn_pri)"}
|
||||||
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
{!settings.premium && (
|
{!settings.premium && (
|
||||||
<Button
|
<Button
|
||||||
@@ -221,9 +227,15 @@ export default React.memo(
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
(prev, next) =>
|
(prev, next) => {
|
||||||
prev.noHeader !== next.noHeader ||
|
if (
|
||||||
prev.settings.premium !== next.settings.premium ||
|
prev.noHeader !== next.noHeader ||
|
||||||
prev.hasRedo !== next.hasRedo ||
|
prev.settings.premium !== next.settings.premium ||
|
||||||
prev.hasUndo !== next.hasUndo
|
prev.hasRedo !== next.hasRedo ||
|
||||||
|
prev.hasUndo !== next.hasUndo
|
||||||
|
)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useRef,
|
useRef,
|
||||||
useState
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useEditorThemeStore } from "../state/theme";
|
import { useEditorThemeStore } from "../state/theme";
|
||||||
import { EventTypes, isReactNative, post, timerFn } from "../utils";
|
import { EventTypes, isReactNative, post, timerFn } from "../utils";
|
||||||
@@ -47,13 +47,13 @@ export type EditorController = {
|
|||||||
|
|
||||||
export function useEditorController(
|
export function useEditorController(
|
||||||
editor: Editor | null,
|
editor: Editor | null,
|
||||||
update: Dispatch<SetStateAction<number>>
|
update: () => void
|
||||||
): EditorController {
|
): EditorController {
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const htmlContentRef = useRef<string | null>(null);
|
const htmlContentRef = useRef<string | null>(null);
|
||||||
const timers = useRef<Timers>({
|
const timers = useRef<Timers>({
|
||||||
selectionChange: null,
|
selectionChange: null,
|
||||||
change: null
|
change: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectionChange = useCallback((editor: Editor) => {
|
const selectionChange = useCallback((editor: Editor) => {
|
||||||
@@ -119,7 +119,7 @@ export function useEditorController(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onUpdate = () => {
|
const onUpdate = () => {
|
||||||
update((tick) => tick + 1);
|
update();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMessage = useCallback(
|
const onMessage = useCallback(
|
||||||
@@ -132,7 +132,7 @@ export function useEditorController(
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "native:html":
|
case "native:html":
|
||||||
htmlContentRef.current = value;
|
htmlContentRef.current = value;
|
||||||
update((tick) => tick + 1);
|
update();
|
||||||
break;
|
break;
|
||||||
case "native:theme":
|
case "native:theme":
|
||||||
useEditorThemeStore.getState().setColors(message.value);
|
useEditorThemeStore.getState().setColors(message.value);
|
||||||
@@ -194,6 +194,6 @@ export function useEditorController(
|
|||||||
openFilePicker,
|
openFilePicker,
|
||||||
downloadAttachment,
|
downloadAttachment,
|
||||||
content: htmlContentRef,
|
content: htmlContentRef,
|
||||||
onUpdate: onUpdate
|
onUpdate: onUpdate,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user