@eventuras/scribo 0.8.3 → 0.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App.d.ts +11 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/MarkdownEditor.d.ts +18 -0
- package/dist/MarkdownEditor.d.ts.map +1 -0
- package/dist/MarkdownEditor2.js +111 -0
- package/dist/MarkdownEditor2.js.map +1 -0
- package/dist/MarkdownInput.d.ts +27 -0
- package/dist/MarkdownInput.d.ts.map +1 -0
- package/dist/MarkdownInput.js +57 -0
- package/dist/MarkdownInput.js.map +1 -0
- package/dist/callout.js +5 -0
- package/dist/context/SharedHistoryContext.d.ts +11 -0
- package/dist/context/SharedHistoryContext.d.ts.map +1 -0
- package/dist/context/SharedHistoryContext.js +12 -0
- package/dist/context/SharedHistoryContext.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/main.d.ts +5 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +4 -0
- package/dist/nodes/EditorNodes.d.ts +4 -0
- package/dist/nodes/EditorNodes.d.ts.map +1 -0
- package/dist/nodes/EditorNodes.js +39 -0
- package/dist/nodes/EditorNodes.js.map +1 -0
- package/dist/nodes/callout/CalloutComponent.d.ts +6 -0
- package/dist/nodes/callout/CalloutComponent.d.ts.map +1 -0
- package/dist/nodes/callout/CalloutComponent.js +53 -0
- package/dist/nodes/callout/CalloutComponent.js.map +1 -0
- package/dist/nodes/callout/CalloutNode.d.ts +27 -0
- package/dist/nodes/callout/CalloutNode.d.ts.map +1 -0
- package/dist/nodes/callout/CalloutNode.js +153 -0
- package/dist/nodes/callout/CalloutNode.js.map +1 -0
- package/dist/nodes/callout/CalloutTransformer.d.ts +3 -0
- package/dist/nodes/callout/CalloutTransformer.d.ts.map +1 -0
- package/dist/nodes/callout/CalloutTransformer.js +48 -0
- package/dist/nodes/callout/CalloutTransformer.js.map +1 -0
- package/dist/nodes/callout/calloutPlugin.d.ts +3 -0
- package/dist/nodes/callout/calloutPlugin.d.ts.map +1 -0
- package/dist/nodes/callout/calloutPlugin.js +34 -0
- package/dist/nodes/callout/calloutPlugin.js.map +1 -0
- package/dist/nodes/callout/index.d.ts +6 -0
- package/dist/nodes/callout/index.d.ts.map +1 -0
- package/dist/nodes/schedule/ScheduleItemComponent.d.ts +9 -0
- package/dist/nodes/schedule/ScheduleItemComponent.d.ts.map +1 -0
- package/dist/nodes/schedule/ScheduleItemComponent.js +167 -0
- package/dist/nodes/schedule/ScheduleItemComponent.js.map +1 -0
- package/dist/nodes/schedule/ScheduleItemNode.d.ts +31 -0
- package/dist/nodes/schedule/ScheduleItemNode.d.ts.map +1 -0
- package/dist/nodes/schedule/ScheduleItemNode.js +94 -0
- package/dist/nodes/schedule/ScheduleItemNode.js.map +1 -0
- package/dist/nodes/schedule/ScheduleTransformer.d.ts +22 -0
- package/dist/nodes/schedule/ScheduleTransformer.d.ts.map +1 -0
- package/dist/nodes/schedule/ScheduleTransformer.js +60 -0
- package/dist/nodes/schedule/ScheduleTransformer.js.map +1 -0
- package/dist/nodes/schedule/index.d.ts +5 -0
- package/dist/nodes/schedule/index.d.ts.map +1 -0
- package/dist/nodes/schedule/schedulePlugin.d.ts +3 -0
- package/dist/nodes/schedule/schedulePlugin.d.ts.map +1 -0
- package/dist/nodes/schedule/schedulePlugin.js +33 -0
- package/dist/nodes/schedule/schedulePlugin.js.map +1 -0
- package/dist/plugins/AutoLinkPlugin.d.ts +3 -0
- package/dist/plugins/AutoLinkPlugin.d.ts.map +1 -0
- package/dist/plugins/AutoLinkPlugin.js +22 -0
- package/dist/plugins/AutoLinkPlugin.js.map +1 -0
- package/dist/plugins/FloatingLinkEditorPlugin.d.ts +7 -0
- package/dist/plugins/FloatingLinkEditorPlugin.d.ts.map +1 -0
- package/dist/plugins/FloatingLinkEditorPlugin2.js +302 -0
- package/dist/plugins/FloatingLinkEditorPlugin2.js.map +1 -0
- package/dist/plugins/HistoryPlugin.d.ts +26 -0
- package/dist/plugins/HistoryPlugin.d.ts.map +1 -0
- package/dist/plugins/LinkPlugin.d.ts +3 -0
- package/dist/plugins/LinkPlugin.d.ts.map +1 -0
- package/dist/plugins/LinkPlugin.js +18 -0
- package/dist/plugins/LinkPlugin.js.map +1 -0
- package/dist/plugins/ToolbarPlugin.d.ts +7 -0
- package/dist/plugins/ToolbarPlugin.d.ts.map +1 -0
- package/dist/plugins/ToolbarPlugin.js +372 -0
- package/dist/plugins/ToolbarPlugin.js.map +1 -0
- package/dist/schedule.js +4 -0
- package/dist/scribo.css +1977 -0
- package/dist/themes/EditorTheme.d.ts +4 -0
- package/dist/themes/EditorTheme.d.ts.map +1 -0
- package/dist/themes/EditorTheme2.js +107 -0
- package/dist/themes/EditorTheme2.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/ui/ContentEditable.d.ts +6 -0
- package/dist/ui/ContentEditable.d.ts.map +1 -0
- package/dist/ui/ContentEditable2.js +14 -0
- package/dist/ui/ContentEditable2.js.map +1 -0
- package/dist/ui/DropDown.d.ts +18 -0
- package/dist/ui/DropDown.d.ts.map +1 -0
- package/dist/ui/DropDown.js +162 -0
- package/dist/ui/DropDown.js.map +1 -0
- package/dist/ui/Placeholder.d.ts +6 -0
- package/dist/ui/Placeholder.d.ts.map +1 -0
- package/dist/ui/Placeholder2.js +13 -0
- package/dist/ui/Placeholder2.js.map +1 -0
- package/dist/utils/environment.d.ts +24 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/environment.js +20 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/getSelectedNode.d.ts +3 -0
- package/dist/utils/getSelectedNode.d.ts.map +1 -0
- package/dist/utils/getSelectedNode.js +23 -0
- package/dist/utils/getSelectedNode.js.map +1 -0
- package/dist/utils/setFloatingElemPosition.d.ts +2 -0
- package/dist/utils/setFloatingElemPosition.d.ts.map +1 -0
- package/dist/utils/setFloatingElemPositionForLinkEditor.d.ts +2 -0
- package/dist/utils/setFloatingElemPositionForLinkEditor.d.ts.map +1 -0
- package/dist/utils/setFloatingElemPositionForLinkEditor.js +33 -0
- package/dist/utils/setFloatingElemPositionForLinkEditor.js.map +1 -0
- package/dist/utils/url.d.ts +11 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +33 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +55 -38
- package/src/MarkdownEditor.css +61 -47
- package/src/MarkdownEditor.tsx +76 -29
- package/src/MarkdownInput.tsx +9 -10
- package/src/context/SharedHistoryContext.tsx +8 -16
- package/src/main.tsx +3 -3
- package/src/nodes/EditorNodes.ts +10 -10
- package/src/nodes/callout/Callout.css +94 -0
- package/src/nodes/callout/CalloutComponent.tsx +61 -0
- package/src/nodes/callout/CalloutNode.ts +197 -0
- package/src/nodes/callout/CalloutTransformer.ts +87 -0
- package/src/nodes/callout/calloutPlugin.ts +37 -0
- package/src/nodes/callout/index.ts +5 -0
- package/src/nodes/schedule/ScheduleItem.css +140 -0
- package/src/nodes/schedule/ScheduleItemComponent.tsx +195 -0
- package/src/nodes/schedule/ScheduleItemNode.ts +135 -0
- package/src/nodes/schedule/ScheduleTransformer.ts +80 -0
- package/src/nodes/schedule/index.ts +4 -0
- package/src/nodes/schedule/schedulePlugin.ts +33 -0
- package/src/plugins/AutoLinkPlugin.tsx +5 -10
- package/src/plugins/FloatingLinkEditorPlugin.tsx +42 -66
- package/src/plugins/HistoryPlugin.tsx +20 -30
- package/src/plugins/LinkPlugin.tsx +2 -3
- package/src/plugins/ToolbarPlugin.tsx +129 -141
- package/src/themes/EditorTheme.css +9 -5
- package/src/themes/EditorTheme.ts +89 -90
- package/src/types.ts +27 -0
- package/src/ui/ContentEditable.tsx +5 -5
- package/src/ui/DropDown.tsx +23 -41
- package/src/ui/Placeholder.tsx +21 -21
- package/src/utils/environment.ts +6 -12
- package/src/utils/getSelectedNode.ts +3 -5
- package/src/utils/setFloatingElemPosition.ts +2 -5
- package/src/utils/setFloatingElemPositionForLinkEditor.ts +1 -1
- package/src/utils/url.ts +4 -10
- package/tsconfig.json +8 -0
- package/CHANGELOG.md +0 -65
- package/README.md +0 -126
- package/RELEASE.md +0 -102
- package/eslint.config.js +0 -4
- package/src/App.css +0 -35
- package/src/App.tsx +0 -42
- package/src/index.tsx +0 -13
- package/tsconfig.node.json +0 -11
- package/vite.config.site.ts +0 -19
- package/vite.config.ts +0 -33
- /package/{src → dist}/vite-env.d.ts +0 -0
|
@@ -7,43 +7,38 @@
|
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
import type {JSX} from 'react';
|
|
10
|
+
import type { JSX } from 'react';
|
|
11
11
|
|
|
12
12
|
import './FloatingLinkEditorPlugin.css';
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
$isLinkNode,
|
|
18
|
-
TOGGLE_LINK_COMMAND,
|
|
19
|
-
} from '@lexical/link';
|
|
20
|
-
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
21
|
-
import {$findMatchingParent, mergeRegister} from '@lexical/utils';
|
|
14
|
+
import { $createLinkNode, $isAutoLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
|
|
15
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
16
|
+
import { $findMatchingParent, mergeRegister } from '@lexical/utils';
|
|
22
17
|
import {
|
|
23
18
|
$getSelection,
|
|
24
19
|
$isLineBreakNode,
|
|
25
20
|
$isNodeSelection,
|
|
26
21
|
$isRangeSelection,
|
|
27
|
-
BaseSelection,
|
|
22
|
+
type BaseSelection,
|
|
28
23
|
CLICK_COMMAND,
|
|
29
24
|
COMMAND_PRIORITY_CRITICAL,
|
|
30
25
|
COMMAND_PRIORITY_HIGH,
|
|
31
26
|
COMMAND_PRIORITY_LOW,
|
|
32
27
|
getDOMSelection,
|
|
33
28
|
KEY_ESCAPE_COMMAND,
|
|
34
|
-
LexicalEditor,
|
|
29
|
+
type LexicalEditor,
|
|
35
30
|
SELECTION_CHANGE_COMMAND,
|
|
36
31
|
} from 'lexical';
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import {createPortal} from 'react-dom';
|
|
32
|
+
import type * as React from 'react';
|
|
33
|
+
import { type Dispatch, useCallback, useEffect, useRef, useState } from 'react';
|
|
34
|
+
import { createPortal } from 'react-dom';
|
|
40
35
|
|
|
41
|
-
import {getSelectedNode} from '../utils/getSelectedNode';
|
|
42
|
-
import {setFloatingElemPositionForLinkEditor} from '../utils/setFloatingElemPositionForLinkEditor';
|
|
43
|
-
import {sanitizeUrl} from '../utils/url';
|
|
36
|
+
import { getSelectedNode } from '../utils/getSelectedNode';
|
|
37
|
+
import { setFloatingElemPositionForLinkEditor } from '../utils/setFloatingElemPositionForLinkEditor';
|
|
38
|
+
import { sanitizeUrl } from '../utils/url';
|
|
44
39
|
|
|
45
40
|
function preventDefault(
|
|
46
|
-
event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLElement
|
|
41
|
+
event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLElement>
|
|
47
42
|
): void {
|
|
48
43
|
event.preventDefault();
|
|
49
44
|
}
|
|
@@ -55,21 +50,19 @@ function FloatingLinkEditor({
|
|
|
55
50
|
anchorElem,
|
|
56
51
|
isLinkEditMode,
|
|
57
52
|
setIsLinkEditMode,
|
|
58
|
-
}: {
|
|
53
|
+
}: Readonly<{
|
|
59
54
|
editor: LexicalEditor;
|
|
60
55
|
isLink: boolean;
|
|
61
56
|
setIsLink: Dispatch<boolean>;
|
|
62
57
|
anchorElem: HTMLElement;
|
|
63
58
|
isLinkEditMode: boolean;
|
|
64
59
|
setIsLinkEditMode: Dispatch<boolean>;
|
|
65
|
-
}): JSX.Element {
|
|
60
|
+
}>): JSX.Element {
|
|
66
61
|
const editorRef = useRef<HTMLDivElement | null>(null);
|
|
67
62
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
68
63
|
const [linkUrl, setLinkUrl] = useState('');
|
|
69
64
|
const [editedLinkUrl, setEditedLinkUrl] = useState('https://');
|
|
70
|
-
const [lastSelection, setLastSelection] = useState<BaseSelection | null>(
|
|
71
|
-
null,
|
|
72
|
-
);
|
|
65
|
+
const [lastSelection, setLastSelection] = useState<BaseSelection | null>(null);
|
|
73
66
|
|
|
74
67
|
const $updateLinkEditor = useCallback(() => {
|
|
75
68
|
const selection = $getSelection();
|
|
@@ -126,12 +119,8 @@ function FloatingLinkEditor({
|
|
|
126
119
|
domRect = element.getBoundingClientRect();
|
|
127
120
|
}
|
|
128
121
|
}
|
|
129
|
-
} else if (
|
|
130
|
-
|
|
131
|
-
rootElement.contains(nativeSelection.anchorNode)
|
|
132
|
-
) {
|
|
133
|
-
domRect =
|
|
134
|
-
nativeSelection.focusNode?.parentElement?.getBoundingClientRect();
|
|
122
|
+
} else if (nativeSelection !== null && rootElement.contains(nativeSelection.anchorNode)) {
|
|
123
|
+
domRect = nativeSelection.focusNode?.parentElement?.getBoundingClientRect();
|
|
135
124
|
}
|
|
136
125
|
|
|
137
126
|
if (domRect) {
|
|
@@ -139,7 +128,7 @@ function FloatingLinkEditor({
|
|
|
139
128
|
setFloatingElemPositionForLinkEditor(domRect, editorElem, anchorElem);
|
|
140
129
|
}
|
|
141
130
|
setLastSelection(selection);
|
|
142
|
-
} else if (
|
|
131
|
+
} else if (activeElement?.className !== 'link-input') {
|
|
143
132
|
if (rootElement !== null) {
|
|
144
133
|
setFloatingElemPositionForLinkEditor(null, editorElem, anchorElem);
|
|
145
134
|
}
|
|
@@ -177,7 +166,7 @@ function FloatingLinkEditor({
|
|
|
177
166
|
|
|
178
167
|
useEffect(() => {
|
|
179
168
|
return mergeRegister(
|
|
180
|
-
editor.registerUpdateListener(({editorState}) => {
|
|
169
|
+
editor.registerUpdateListener(({ editorState }) => {
|
|
181
170
|
editorState.read(() => {
|
|
182
171
|
$updateLinkEditor();
|
|
183
172
|
});
|
|
@@ -189,7 +178,7 @@ function FloatingLinkEditor({
|
|
|
189
178
|
$updateLinkEditor();
|
|
190
179
|
return true;
|
|
191
180
|
},
|
|
192
|
-
COMMAND_PRIORITY_LOW
|
|
181
|
+
COMMAND_PRIORITY_LOW
|
|
193
182
|
),
|
|
194
183
|
editor.registerCommand(
|
|
195
184
|
KEY_ESCAPE_COMMAND,
|
|
@@ -200,8 +189,8 @@ function FloatingLinkEditor({
|
|
|
200
189
|
}
|
|
201
190
|
return false;
|
|
202
191
|
},
|
|
203
|
-
COMMAND_PRIORITY_HIGH
|
|
204
|
-
)
|
|
192
|
+
COMMAND_PRIORITY_HIGH
|
|
193
|
+
)
|
|
205
194
|
);
|
|
206
195
|
}, [editor, $updateLinkEditor, setIsLink, isLink]);
|
|
207
196
|
|
|
@@ -234,9 +223,7 @@ function FloatingLinkEditor({
|
|
|
234
223
|
};
|
|
235
224
|
}, [editorRef, setIsLink, setIsLinkEditMode, isLink]);
|
|
236
225
|
|
|
237
|
-
const monitorInputInteraction = (
|
|
238
|
-
event: React.KeyboardEvent<HTMLInputElement>,
|
|
239
|
-
) => {
|
|
226
|
+
const monitorInputInteraction = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
240
227
|
if (event.key === 'Enter') {
|
|
241
228
|
handleLinkSubmission(event);
|
|
242
229
|
} else if (event.key === 'Escape') {
|
|
@@ -246,18 +233,13 @@ function FloatingLinkEditor({
|
|
|
246
233
|
};
|
|
247
234
|
|
|
248
235
|
const handleLinkSubmission = (
|
|
249
|
-
event:
|
|
250
|
-
| React.KeyboardEvent<HTMLInputElement>
|
|
251
|
-
| React.MouseEvent<HTMLElement>,
|
|
236
|
+
event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLElement>
|
|
252
237
|
) => {
|
|
253
238
|
event.preventDefault();
|
|
254
239
|
if (lastSelection !== null) {
|
|
255
240
|
if (linkUrl !== '') {
|
|
256
241
|
editor.update(() => {
|
|
257
|
-
editor.dispatchCommand(
|
|
258
|
-
TOGGLE_LINK_COMMAND,
|
|
259
|
-
sanitizeUrl(editedLinkUrl),
|
|
260
|
-
);
|
|
242
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl(editedLinkUrl));
|
|
261
243
|
const selection = $getSelection();
|
|
262
244
|
if ($isRangeSelection(selection)) {
|
|
263
245
|
const parent = getSelectedNode(selection).getParent();
|
|
@@ -279,7 +261,7 @@ function FloatingLinkEditor({
|
|
|
279
261
|
|
|
280
262
|
return (
|
|
281
263
|
<div ref={editorRef} className="link-editor">
|
|
282
|
-
{
|
|
264
|
+
{isLink && isLinkEditMode && (
|
|
283
265
|
<>
|
|
284
266
|
<input
|
|
285
267
|
ref={inputRef}
|
|
@@ -312,12 +294,10 @@ function FloatingLinkEditor({
|
|
|
312
294
|
/>
|
|
313
295
|
</div>
|
|
314
296
|
</>
|
|
315
|
-
)
|
|
297
|
+
)}
|
|
298
|
+
{isLink && !isLinkEditMode && (
|
|
316
299
|
<div className="link-view">
|
|
317
|
-
<a
|
|
318
|
-
href={sanitizeUrl(linkUrl)}
|
|
319
|
-
target="_blank"
|
|
320
|
-
rel="noopener noreferrer">
|
|
300
|
+
<a href={sanitizeUrl(linkUrl)} target="_blank" rel="noopener noreferrer">
|
|
321
301
|
{linkUrl}
|
|
322
302
|
</a>
|
|
323
303
|
<div
|
|
@@ -350,7 +330,7 @@ function useFloatingLinkEditorToolbar(
|
|
|
350
330
|
editor: LexicalEditor,
|
|
351
331
|
anchorElem: HTMLElement,
|
|
352
332
|
isLinkEditMode: boolean,
|
|
353
|
-
setIsLinkEditMode: Dispatch<boolean
|
|
333
|
+
setIsLinkEditMode: Dispatch<boolean>
|
|
354
334
|
): JSX.Element | null {
|
|
355
335
|
const [activeEditor, setActiveEditor] = useState(editor);
|
|
356
336
|
const [isLink, setIsLink] = useState(false);
|
|
@@ -361,10 +341,7 @@ function useFloatingLinkEditorToolbar(
|
|
|
361
341
|
if ($isRangeSelection(selection)) {
|
|
362
342
|
const focusNode = getSelectedNode(selection);
|
|
363
343
|
const focusLinkNode = $findMatchingParent(focusNode, $isLinkNode);
|
|
364
|
-
const focusAutoLinkNode = $findMatchingParent(
|
|
365
|
-
focusNode,
|
|
366
|
-
$isAutoLinkNode,
|
|
367
|
-
);
|
|
344
|
+
const focusAutoLinkNode = $findMatchingParent(focusNode, $isAutoLinkNode);
|
|
368
345
|
if (!(focusLinkNode || focusAutoLinkNode)) {
|
|
369
346
|
setIsLink(false);
|
|
370
347
|
return;
|
|
@@ -380,8 +357,7 @@ function useFloatingLinkEditorToolbar(
|
|
|
380
357
|
(linkNode && !linkNode.is(focusLinkNode)) ||
|
|
381
358
|
(focusAutoLinkNode && !focusAutoLinkNode.is(autoLinkNode)) ||
|
|
382
359
|
(autoLinkNode &&
|
|
383
|
-
(!autoLinkNode.is(focusAutoLinkNode) ||
|
|
384
|
-
autoLinkNode.getIsUnlinked()))
|
|
360
|
+
(!autoLinkNode.is(focusAutoLinkNode) || autoLinkNode.getIsUnlinked()))
|
|
385
361
|
);
|
|
386
362
|
});
|
|
387
363
|
if (!badNode) {
|
|
@@ -405,7 +381,7 @@ function useFloatingLinkEditorToolbar(
|
|
|
405
381
|
}
|
|
406
382
|
}
|
|
407
383
|
return mergeRegister(
|
|
408
|
-
editor.registerUpdateListener(({editorState}) => {
|
|
384
|
+
editor.registerUpdateListener(({ editorState }) => {
|
|
409
385
|
editorState.read(() => {
|
|
410
386
|
$updateToolbar();
|
|
411
387
|
});
|
|
@@ -417,7 +393,7 @@ function useFloatingLinkEditorToolbar(
|
|
|
417
393
|
setActiveEditor(newEditor);
|
|
418
394
|
return false;
|
|
419
395
|
},
|
|
420
|
-
COMMAND_PRIORITY_CRITICAL
|
|
396
|
+
COMMAND_PRIORITY_CRITICAL
|
|
421
397
|
),
|
|
422
398
|
editor.registerCommand(
|
|
423
399
|
CLICK_COMMAND,
|
|
@@ -433,8 +409,8 @@ function useFloatingLinkEditorToolbar(
|
|
|
433
409
|
}
|
|
434
410
|
return false;
|
|
435
411
|
},
|
|
436
|
-
COMMAND_PRIORITY_LOW
|
|
437
|
-
)
|
|
412
|
+
COMMAND_PRIORITY_LOW
|
|
413
|
+
)
|
|
438
414
|
);
|
|
439
415
|
}, [editor]);
|
|
440
416
|
|
|
@@ -447,7 +423,7 @@ function useFloatingLinkEditorToolbar(
|
|
|
447
423
|
isLinkEditMode={isLinkEditMode}
|
|
448
424
|
setIsLinkEditMode={setIsLinkEditMode}
|
|
449
425
|
/>,
|
|
450
|
-
anchorElem
|
|
426
|
+
anchorElem
|
|
451
427
|
);
|
|
452
428
|
}
|
|
453
429
|
|
|
@@ -461,20 +437,20 @@ export default function FloatingLinkEditorPlugin({
|
|
|
461
437
|
setIsLinkEditMode: Dispatch<boolean>;
|
|
462
438
|
}): JSX.Element | null {
|
|
463
439
|
const [editor] = useLexicalComposerContext();
|
|
464
|
-
|
|
440
|
+
|
|
465
441
|
// Use document.body as default, but only in browser environment
|
|
466
442
|
const defaultAnchorElem = typeof document !== 'undefined' ? document.body : null;
|
|
467
443
|
const effectiveAnchorElem = anchorElem ?? defaultAnchorElem;
|
|
468
|
-
|
|
444
|
+
|
|
469
445
|
// Don't render if we don't have a valid anchor element
|
|
470
446
|
if (!effectiveAnchorElem) {
|
|
471
447
|
return null;
|
|
472
448
|
}
|
|
473
|
-
|
|
449
|
+
|
|
474
450
|
return useFloatingLinkEditorToolbar(
|
|
475
451
|
editor,
|
|
476
452
|
effectiveAnchorElem,
|
|
477
453
|
isLinkEditMode,
|
|
478
|
-
setIsLinkEditMode
|
|
454
|
+
setIsLinkEditMode
|
|
479
455
|
);
|
|
480
456
|
}
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import {mergeRegister} from '@lexical/utils';
|
|
10
|
+
import { mergeRegister } from '@lexical/utils';
|
|
11
|
+
import type { EditorState, LexicalEditor, LexicalNode, NodeKey } from 'lexical';
|
|
13
12
|
import {
|
|
14
13
|
$isRangeSelection,
|
|
15
14
|
$isRootNode,
|
|
@@ -50,7 +49,7 @@ type IntentionallyMarkedAsDirtyElement = boolean;
|
|
|
50
49
|
function getDirtyNodes(
|
|
51
50
|
editorState: EditorState,
|
|
52
51
|
dirtyLeaves: Set<NodeKey>,
|
|
53
|
-
dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement
|
|
52
|
+
dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>
|
|
54
53
|
): Array<LexicalNode> {
|
|
55
54
|
const nodeMap = editorState._nodeMap;
|
|
56
55
|
const nodes = [];
|
|
@@ -83,7 +82,7 @@ function getChangeType(
|
|
|
83
82
|
nextEditorState: EditorState,
|
|
84
83
|
dirtyLeavesSet: Set<NodeKey>,
|
|
85
84
|
dirtyElementsSet: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
|
|
86
|
-
isComposing: boolean
|
|
85
|
+
isComposing: boolean
|
|
87
86
|
): ChangeType {
|
|
88
87
|
if (
|
|
89
88
|
prevEditorState === null ||
|
|
@@ -108,11 +107,7 @@ function getChangeType(
|
|
|
108
107
|
return OTHER;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
const dirtyNodes = getDirtyNodes(
|
|
112
|
-
nextEditorState,
|
|
113
|
-
dirtyLeavesSet,
|
|
114
|
-
dirtyElementsSet,
|
|
115
|
-
);
|
|
110
|
+
const dirtyNodes = getDirtyNodes(nextEditorState, dirtyLeavesSet, dirtyElementsSet);
|
|
116
111
|
|
|
117
112
|
if (dirtyNodes.length === 0) {
|
|
118
113
|
return OTHER;
|
|
@@ -191,7 +186,7 @@ function getChangeType(
|
|
|
191
186
|
function isTextNodeUnchanged(
|
|
192
187
|
key: NodeKey,
|
|
193
188
|
prevEditorState: EditorState,
|
|
194
|
-
nextEditorState: EditorState
|
|
189
|
+
nextEditorState: EditorState
|
|
195
190
|
): boolean {
|
|
196
191
|
const prevNode = prevEditorState._nodeMap.get(key);
|
|
197
192
|
const nextNode = nextEditorState._nodeMap.get(key);
|
|
@@ -224,14 +219,14 @@ function isTextNodeUnchanged(
|
|
|
224
219
|
|
|
225
220
|
function createMergeActionGetter(
|
|
226
221
|
editor: LexicalEditor,
|
|
227
|
-
delay: number
|
|
222
|
+
delay: number
|
|
228
223
|
): (
|
|
229
224
|
prevEditorState: null | EditorState,
|
|
230
225
|
nextEditorState: EditorState,
|
|
231
226
|
currentHistoryEntry: null | HistoryStateEntry,
|
|
232
227
|
dirtyLeaves: Set<NodeKey>,
|
|
233
228
|
dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>,
|
|
234
|
-
tags: Set<string
|
|
229
|
+
tags: Set<string>
|
|
235
230
|
) => MergeAction {
|
|
236
231
|
let prevChangeTime = Date.now();
|
|
237
232
|
let prevChangeType = OTHER;
|
|
@@ -242,7 +237,7 @@ function createMergeActionGetter(
|
|
|
242
237
|
currentHistoryEntry,
|
|
243
238
|
dirtyLeaves,
|
|
244
239
|
dirtyElements,
|
|
245
|
-
tags
|
|
240
|
+
tags
|
|
246
241
|
) => {
|
|
247
242
|
const changeTime = Date.now();
|
|
248
243
|
|
|
@@ -259,15 +254,13 @@ function createMergeActionGetter(
|
|
|
259
254
|
nextEditorState,
|
|
260
255
|
dirtyLeaves,
|
|
261
256
|
dirtyElements,
|
|
262
|
-
editor.isComposing()
|
|
257
|
+
editor.isComposing()
|
|
263
258
|
);
|
|
264
259
|
|
|
265
260
|
const mergeAction = (() => {
|
|
266
|
-
const isSameEditor =
|
|
267
|
-
currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
261
|
+
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
268
262
|
const shouldPushHistory = tags.has('history-push');
|
|
269
|
-
const shouldMergeHistory =
|
|
270
|
-
!shouldPushHistory && isSameEditor && tags.has('history-merge');
|
|
263
|
+
const shouldMergeHistory = !shouldPushHistory && isSameEditor && tags.has('history-merge');
|
|
271
264
|
|
|
272
265
|
if (shouldMergeHistory) {
|
|
273
266
|
return HISTORY_MERGE;
|
|
@@ -302,10 +295,7 @@ function createMergeActionGetter(
|
|
|
302
295
|
// due to some node transform reverting the change.
|
|
303
296
|
if (dirtyLeaves.size === 1) {
|
|
304
297
|
const dirtyLeafKey = Array.from(dirtyLeaves)[0];
|
|
305
|
-
if (
|
|
306
|
-
dirtyLeafKey &&
|
|
307
|
-
isTextNodeUnchanged(dirtyLeafKey, prevEditorState, nextEditorState)
|
|
308
|
-
) {
|
|
298
|
+
if (dirtyLeafKey && isTextNodeUnchanged(dirtyLeafKey, prevEditorState, nextEditorState)) {
|
|
309
299
|
return HISTORY_MERGE;
|
|
310
300
|
}
|
|
311
301
|
}
|
|
@@ -394,7 +384,7 @@ function clearHistory(historyState: HistoryState) {
|
|
|
394
384
|
export function registerHistory(
|
|
395
385
|
editor: LexicalEditor,
|
|
396
386
|
historyState: HistoryState,
|
|
397
|
-
delay: number
|
|
387
|
+
delay: number
|
|
398
388
|
): () => void {
|
|
399
389
|
const getMergeAction = createMergeActionGetter(editor, delay);
|
|
400
390
|
|
|
@@ -426,7 +416,7 @@ export function registerHistory(
|
|
|
426
416
|
current,
|
|
427
417
|
dirtyLeaves,
|
|
428
418
|
dirtyElements,
|
|
429
|
-
tags
|
|
419
|
+
tags
|
|
430
420
|
);
|
|
431
421
|
|
|
432
422
|
if (mergeAction === HISTORY_PUSH) {
|
|
@@ -459,7 +449,7 @@ export function registerHistory(
|
|
|
459
449
|
undo(editor, historyState);
|
|
460
450
|
return true;
|
|
461
451
|
},
|
|
462
|
-
COMMAND_PRIORITY_EDITOR
|
|
452
|
+
COMMAND_PRIORITY_EDITOR
|
|
463
453
|
),
|
|
464
454
|
editor.registerCommand(
|
|
465
455
|
REDO_COMMAND,
|
|
@@ -467,7 +457,7 @@ export function registerHistory(
|
|
|
467
457
|
redo(editor, historyState);
|
|
468
458
|
return true;
|
|
469
459
|
},
|
|
470
|
-
COMMAND_PRIORITY_EDITOR
|
|
460
|
+
COMMAND_PRIORITY_EDITOR
|
|
471
461
|
),
|
|
472
462
|
editor.registerCommand(
|
|
473
463
|
CLEAR_EDITOR_COMMAND,
|
|
@@ -475,7 +465,7 @@ export function registerHistory(
|
|
|
475
465
|
clearHistory(historyState);
|
|
476
466
|
return false;
|
|
477
467
|
},
|
|
478
|
-
COMMAND_PRIORITY_EDITOR
|
|
468
|
+
COMMAND_PRIORITY_EDITOR
|
|
479
469
|
),
|
|
480
470
|
editor.registerCommand(
|
|
481
471
|
CLEAR_HISTORY_COMMAND,
|
|
@@ -485,9 +475,9 @@ export function registerHistory(
|
|
|
485
475
|
editor.dispatchCommand(CAN_UNDO_COMMAND, false);
|
|
486
476
|
return true;
|
|
487
477
|
},
|
|
488
|
-
COMMAND_PRIORITY_EDITOR
|
|
478
|
+
COMMAND_PRIORITY_EDITOR
|
|
489
479
|
),
|
|
490
|
-
editor.registerUpdateListener(applyChange)
|
|
480
|
+
editor.registerUpdateListener(applyChange)
|
|
491
481
|
);
|
|
492
482
|
|
|
493
483
|
const unregisterUpdateListener = editor.registerUpdateListener(applyChange);
|
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { LinkPlugin as LexicalLinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
|
10
|
-
import type {JSX} from 'react';
|
|
11
|
-
import * as React from 'react';
|
|
10
|
+
import type { JSX } from 'react';
|
|
12
11
|
|
|
13
|
-
import {validateUrl} from '../utils/url';
|
|
12
|
+
import { validateUrl } from '../utils/url';
|
|
14
13
|
|
|
15
14
|
export default function LinkPlugin(): JSX.Element {
|
|
16
15
|
return <LexicalLinkPlugin validateUrl={validateUrl} />;
|