@octanejs/lexical 0.2.6 → 0.2.8
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/package.json +5 -5
- package/src/LexicalAutoEmbedPlugin.tsrx +73 -61
- package/src/LexicalAutoFocusPlugin.tsrx +14 -11
- package/src/LexicalAutoLinkPlugin.tsrx +6 -5
- package/src/LexicalBlockWithAlignableContents.tsrx +13 -14
- package/src/LexicalCharacterLimitPlugin.tsrx +3 -1
- package/src/LexicalCheckListPlugin.tsrx +4 -4
- package/src/LexicalClearEditorPlugin.tsrx +3 -4
- package/src/LexicalClickableLinkPlugin.tsrx +4 -5
- package/src/LexicalComposer.tsrx +1 -1
- package/src/LexicalContentEditable.tsrx +11 -9
- package/src/LexicalDraggableBlockPlugin.tsrx +17 -15
- package/src/LexicalEditorRefPlugin.tsrx +2 -2
- package/src/LexicalErrorBoundary.tsrx +10 -6
- package/src/LexicalHistoryPlugin.tsrx +5 -5
- package/src/LexicalLinkPlugin.tsrx +4 -5
- package/src/LexicalListPlugin.tsrx +7 -8
- package/src/LexicalMarkdownShortcutPlugin.tsrx +4 -6
- package/src/LexicalNestedComposer.tsrx +9 -6
- package/src/LexicalNodeContextMenuPlugin.tsrx +15 -13
- package/src/LexicalNodeEventPlugin.tsrx +5 -6
- package/src/LexicalNodeMenuPlugin.tsrx +29 -20
- package/src/LexicalOnChangePlugin.tsrx +11 -15
- package/src/LexicalPlainTextPlugin.tsrx +4 -5
- package/src/LexicalRichTextPlugin.tsrx +4 -5
- package/src/LexicalSelectionAlwaysOnDisplay.tsrx +3 -4
- package/src/LexicalTabIndentationPlugin.tsrx +8 -9
- package/src/LexicalTableOfContentsPlugin.tsrx +83 -82
- package/src/LexicalTablePlugin.tsrx +24 -27
- package/src/LexicalTypeaheadMenuPlugin.tsrx +48 -31
- package/src/shared/LexicalContentEditableElement.tsrx +52 -47
- package/src/shared/LexicalDecorators.tsrx +24 -22
- package/src/shared/LexicalMenu.tsrx +52 -38
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/lexical",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -112,18 +112,18 @@
|
|
|
112
112
|
"@lexical/text": "0.51.0",
|
|
113
113
|
"@lexical/utils": "0.51.0",
|
|
114
114
|
"@lexical/yjs": "0.51.0",
|
|
115
|
-
"@octanejs/floating-ui": "0.1.
|
|
115
|
+
"@octanejs/floating-ui": "0.1.65",
|
|
116
116
|
"lexical": "0.51.0",
|
|
117
117
|
"yjs": "^13.6.31"
|
|
118
118
|
},
|
|
119
119
|
"peerDependencies": {
|
|
120
|
-
"octane": "^0.
|
|
120
|
+
"octane": "^0.12.0"
|
|
121
121
|
},
|
|
122
122
|
"devDependencies": {
|
|
123
123
|
"@lexical/react": "0.51.0",
|
|
124
|
-
"@tsrx/react": "^0.
|
|
124
|
+
"@tsrx/react": "^0.4.5",
|
|
125
125
|
"esbuild": "^0.28.1",
|
|
126
|
-
"octane": "0.
|
|
126
|
+
"octane": "0.12.0",
|
|
127
127
|
"react": "19.2.7",
|
|
128
128
|
"react-dom": "19.2.7",
|
|
129
129
|
"typescript": "^5.9.3",
|
|
@@ -30,7 +30,11 @@ export type { EmbedConfig, EmbedMatchResult } from './LexicalAutoEmbedPluginUtil
|
|
|
30
30
|
type LexicalAutoEmbedPluginProps<TEmbedConfig extends EmbedConfig> = {
|
|
31
31
|
embedConfigs: TEmbedConfig[];
|
|
32
32
|
onOpenEmbedModalForConfig?: (embedConfig: TEmbedConfig) => void;
|
|
33
|
-
getMenuOptions: (
|
|
33
|
+
getMenuOptions: (
|
|
34
|
+
activeEmbedConfig: TEmbedConfig,
|
|
35
|
+
embedFn: () => void,
|
|
36
|
+
dismissFn: () => void,
|
|
37
|
+
) => AutoEmbedOption[];
|
|
34
38
|
menuRenderFn?: MenuRenderFn<AutoEmbedOption>;
|
|
35
39
|
menuCommandPriority?: CommandListenerPriority;
|
|
36
40
|
};
|
|
@@ -55,24 +59,27 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>(
|
|
|
55
59
|
setActiveEmbedConfig(null);
|
|
56
60
|
}, []);
|
|
57
61
|
|
|
58
|
-
const checkIfLinkNodeIsEmbeddable = useCallback(
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const checkIfLinkNodeIsEmbeddable = useCallback(
|
|
63
|
+
async (key: NodeKey) => {
|
|
64
|
+
const url = editor.read('latest', function () {
|
|
65
|
+
const linkNode = $getNodeByKey(key);
|
|
66
|
+
if ($isLinkNode(linkNode)) {
|
|
67
|
+
return linkNode.getURL();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (url === undefined) {
|
|
71
|
+
return;
|
|
63
72
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (urlMatch != null) {
|
|
71
|
-
setActiveEmbedConfig(embedConfig);
|
|
72
|
-
setNodeKey(key);
|
|
73
|
+
for (const embedConfig of embedConfigs) {
|
|
74
|
+
const urlMatch = await Promise.resolve(embedConfig.parseUrl(url));
|
|
75
|
+
if (urlMatch != null) {
|
|
76
|
+
setActiveEmbedConfig(embedConfig);
|
|
77
|
+
setNodeKey(key);
|
|
78
|
+
}
|
|
73
79
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
80
|
+
},
|
|
81
|
+
[editor, embedConfigs],
|
|
82
|
+
);
|
|
76
83
|
|
|
77
84
|
useEffect(() => {
|
|
78
85
|
let isSingleTokenPaste = false;
|
|
@@ -89,7 +96,8 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>(
|
|
|
89
96
|
editor.registerCommand(
|
|
90
97
|
PASTE_COMMAND,
|
|
91
98
|
(event) => {
|
|
92
|
-
isSingleTokenPaste =
|
|
99
|
+
isSingleTokenPaste =
|
|
100
|
+
objectKlassEquals(event, ClipboardEvent) &&
|
|
93
101
|
event.clipboardData !== null &&
|
|
94
102
|
/^\S+$/.test(event.clipboardData.getData('text/plain'));
|
|
95
103
|
if (isSingleTokenPaste) {
|
|
@@ -101,8 +109,8 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>(
|
|
|
101
109
|
},
|
|
102
110
|
COMMAND_PRIORITY_BEFORE_EDITOR,
|
|
103
111
|
),
|
|
104
|
-
...[LinkNode, AutoLinkNode].map(
|
|
105
|
-
|
|
112
|
+
...[LinkNode, AutoLinkNode].map((Klass) =>
|
|
113
|
+
editor.registerMutationListener(Klass, listener, {
|
|
106
114
|
skipInitialization: true,
|
|
107
115
|
}),
|
|
108
116
|
),
|
|
@@ -126,32 +134,35 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>(
|
|
|
126
134
|
);
|
|
127
135
|
}, [editor, embedConfigs, onOpenEmbedModalForConfig]);
|
|
128
136
|
|
|
129
|
-
const embedLinkViaActiveEmbedConfig = useCallback(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
const embedLinkViaActiveEmbedConfig = useCallback(
|
|
138
|
+
async function () {
|
|
139
|
+
if (activeEmbedConfig != null && nodeKey != null) {
|
|
140
|
+
const linkNode = editor.read('latest', () => {
|
|
141
|
+
const node = $getNodeByKey(nodeKey);
|
|
142
|
+
if ($isLinkNode(node)) {
|
|
143
|
+
return node;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
});
|
|
138
147
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
if ($isLinkNode(linkNode)) {
|
|
149
|
+
const result = await Promise.resolve(activeEmbedConfig.parseUrl(linkNode.__url));
|
|
150
|
+
if (result != null) {
|
|
151
|
+
editor.update(() => {
|
|
152
|
+
if (!$getSelection()) {
|
|
153
|
+
linkNode.selectEnd();
|
|
154
|
+
}
|
|
155
|
+
activeEmbedConfig.insertNode(editor, result);
|
|
156
|
+
if (linkNode.isAttached()) {
|
|
157
|
+
linkNode.remove();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
163
|
+
},
|
|
164
|
+
[activeEmbedConfig, editor, nodeKey],
|
|
165
|
+
);
|
|
155
166
|
|
|
156
167
|
const options = useMemo(() => {
|
|
157
168
|
return activeEmbedConfig != null && nodeKey != null
|
|
@@ -159,26 +170,27 @@ export function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>(
|
|
|
159
170
|
: [];
|
|
160
171
|
}, [activeEmbedConfig, embedLinkViaActiveEmbedConfig, getMenuOptions, nodeKey, reset]);
|
|
161
172
|
|
|
162
|
-
const onSelectOption = useCallback(
|
|
163
|
-
selectedOption: AutoEmbedOption,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}, [editor]);
|
|
173
|
+
const onSelectOption = useCallback(
|
|
174
|
+
(selectedOption: AutoEmbedOption, targetNode: LexicalNode | null, closeMenu: () => void) => {
|
|
175
|
+
editor.update(() => {
|
|
176
|
+
selectedOption.onSelect(targetNode);
|
|
177
|
+
closeMenu();
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
[editor],
|
|
181
|
+
);
|
|
172
182
|
|
|
173
183
|
if (nodeKey == null) {
|
|
174
184
|
return null;
|
|
175
185
|
}
|
|
176
|
-
return
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
return (
|
|
187
|
+
<LexicalNodeMenuPlugin
|
|
188
|
+
nodeKey={nodeKey}
|
|
189
|
+
onClose={reset}
|
|
190
|
+
onSelectOption={onSelectOption}
|
|
191
|
+
options={options}
|
|
192
|
+
menuRenderFn={menuRenderFn}
|
|
193
|
+
commandPriority={menuCommandPriority}
|
|
194
|
+
/>
|
|
195
|
+
);
|
|
184
196
|
}
|
|
@@ -12,17 +12,20 @@ export function AutoFocusPlugin(props: Props) {
|
|
|
12
12
|
const defaultSelection = props.defaultSelection;
|
|
13
13
|
|
|
14
14
|
useEffect(() => {
|
|
15
|
-
editor.focus(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
rootElement !== null ? getActiveElement(rootElement) : null;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
editor.focus(
|
|
16
|
+
() => {
|
|
17
|
+
const rootElement = editor.getRootElement();
|
|
18
|
+
// getActiveElement rather than document.activeElement (shadow-root safe).
|
|
19
|
+
const activeElement = rootElement !== null ? getActiveElement(rootElement) : null;
|
|
20
|
+
if (
|
|
21
|
+
rootElement !== null &&
|
|
22
|
+
(activeElement === null || !rootElement.contains(activeElement))
|
|
23
|
+
) {
|
|
24
|
+
rootElement.focus({ preventScroll: true });
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{ defaultSelection },
|
|
28
|
+
);
|
|
26
29
|
}, [defaultSelection, editor]);
|
|
27
30
|
|
|
28
31
|
return null;
|
|
@@ -28,11 +28,12 @@ export function AutoLinkPlugin(props: Props) {
|
|
|
28
28
|
}, null);
|
|
29
29
|
|
|
30
30
|
useEffect(
|
|
31
|
-
() =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
() =>
|
|
32
|
+
registerAutoLink(editor, {
|
|
33
|
+
changeHandlers: onChange ? [onChange] : [],
|
|
34
|
+
excludeParents: excludeParents ?? [],
|
|
35
|
+
matchers,
|
|
36
|
+
}),
|
|
36
37
|
[editor, matchers, onChange, excludeParents],
|
|
37
38
|
);
|
|
38
39
|
|
|
@@ -21,16 +21,15 @@ import type { ElementFormatType, NodeKey } from 'lexical';
|
|
|
21
21
|
import { useEffect, useRef } from 'octane';
|
|
22
22
|
import type { OctaneNode } from 'octane';
|
|
23
23
|
|
|
24
|
-
type Props =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
focus: string;
|
|
32
|
-
}>;
|
|
24
|
+
type Props = Readonly<{
|
|
25
|
+
children: OctaneNode;
|
|
26
|
+
format?: ElementFormatType | null;
|
|
27
|
+
nodeKey: NodeKey;
|
|
28
|
+
className: Readonly<{
|
|
29
|
+
base: string;
|
|
30
|
+
focus: string;
|
|
33
31
|
}>;
|
|
32
|
+
}>;
|
|
34
33
|
|
|
35
34
|
export function BlockWithAlignableContents(props: Props) {
|
|
36
35
|
const nodeKey = props.nodeKey;
|
|
@@ -90,9 +89,9 @@ export function BlockWithAlignableContents(props: Props) {
|
|
|
90
89
|
|
|
91
90
|
const cls = [className.base, isSelected ? className.focus : null].filter(Boolean).join(' ');
|
|
92
91
|
|
|
93
|
-
return
|
|
94
|
-
class={cls}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
return (
|
|
93
|
+
<div class={cls} ref={ref} style={{ textAlign: format ? format : undefined }}>
|
|
94
|
+
{props.children}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
98
97
|
}
|
|
@@ -36,7 +36,9 @@ type RendererProps = {
|
|
|
36
36
|
function DefaultRenderer(props: RendererProps) @{
|
|
37
37
|
<span
|
|
38
38
|
class={'characters-limit ' + (props.remainingCharacters < 0 ? 'characters-limit-exceeded' : '')}
|
|
39
|
-
>
|
|
39
|
+
>
|
|
40
|
+
{props.remainingCharacters as unknown as string}
|
|
41
|
+
</span>
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
type Props = {
|
|
@@ -12,9 +12,9 @@ export function CheckListPlugin(props: Props) {
|
|
|
12
12
|
const disableTakeFocusOnClick =
|
|
13
13
|
props.disableTakeFocusOnClick === undefined ? false : props.disableTakeFocusOnClick;
|
|
14
14
|
|
|
15
|
-
useEffect(
|
|
16
|
-
editor,
|
|
17
|
-
disableTakeFocusOnClick,
|
|
18
|
-
|
|
15
|
+
useEffect(
|
|
16
|
+
() => registerCheckList(editor, { disableTakeFocusOnClick }),
|
|
17
|
+
[editor, disableTakeFocusOnClick],
|
|
18
|
+
);
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
@@ -4,10 +4,9 @@ import { useLexicalComposerContext } from './LexicalComposerContext';
|
|
|
4
4
|
import { registerClearEditor } from '@lexical/extension';
|
|
5
5
|
import { useLayoutEffect } from 'octane';
|
|
6
6
|
|
|
7
|
-
type Props =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}>;
|
|
7
|
+
type Props = Readonly<{
|
|
8
|
+
onClear?: () => void;
|
|
9
|
+
}>;
|
|
11
10
|
|
|
12
11
|
export function ClearEditorPlugin(props: Props) {
|
|
13
12
|
const [editor] = useLexicalComposerContext();
|
|
@@ -13,10 +13,9 @@ export function ClickableLinkPlugin(props: Props) {
|
|
|
13
13
|
const [editor] = useLexicalComposerContext();
|
|
14
14
|
const newTab = props.newTab !== false;
|
|
15
15
|
const disabled = props.disabled === true;
|
|
16
|
-
useEffect(
|
|
17
|
-
editor,
|
|
18
|
-
newTab,
|
|
19
|
-
|
|
20
|
-
]);
|
|
16
|
+
useEffect(
|
|
17
|
+
() => registerClickableLink(editor, namedSignals({ disabled, newTab })),
|
|
18
|
+
[editor, newTab, disabled],
|
|
19
|
+
);
|
|
21
20
|
return null;
|
|
22
21
|
}
|
package/src/LexicalComposer.tsrx
CHANGED
|
@@ -33,7 +33,7 @@ function initializeEditor(editor: LexicalEditor, initialEditorState?: InitialEdi
|
|
|
33
33
|
// when the editor lives in a shadow root.
|
|
34
34
|
const activeElement =
|
|
35
35
|
CAN_USE_DOM && rootElement !== null ? getActiveElement(rootElement) : null;
|
|
36
|
-
if ($getSelection() !== null || activeElement !== null && activeElement === rootElement) {
|
|
36
|
+
if ($getSelection() !== null || (activeElement !== null && activeElement === rootElement)) {
|
|
37
37
|
paragraph.select();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -19,15 +19,17 @@ export { ContentEditableElement } from './shared/LexicalContentEditableElement.t
|
|
|
19
19
|
* context) plus an optional `placeholder`; when a `placeholder` is provided an
|
|
20
20
|
* `aria-placeholder` string is also required for accessibility.
|
|
21
21
|
*/
|
|
22
|
-
export type ContentEditableProps =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
export type ContentEditableProps = Omit<ContentEditableElementProps, 'editor'> &
|
|
23
|
+
(
|
|
24
|
+
| {
|
|
25
|
+
'aria-placeholder'?: void;
|
|
26
|
+
placeholder?: null;
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
'aria-placeholder': string;
|
|
30
|
+
placeholder: ((isEditable: boolean) => OctaneNode) | OctaneNode;
|
|
31
|
+
}
|
|
32
|
+
);
|
|
31
33
|
|
|
32
34
|
function Placeholder(props: {
|
|
33
35
|
editor: LexicalEditor;
|
|
@@ -78,8 +78,7 @@ function getCollapsedMargins(elem: HTMLElement): {
|
|
|
78
78
|
const getMargin = (element: Element | null, margin: 'marginTop' | 'marginBottom'): number =>
|
|
79
79
|
element && view ? parseFloat(view.getComputedStyle(element)[margin]) : 0;
|
|
80
80
|
|
|
81
|
-
const { marginTop = '0', marginBottom = '0' } =
|
|
82
|
-
view ? view.getComputedStyle(elem) : {};
|
|
81
|
+
const { marginTop = '0', marginBottom = '0' } = view ? view.getComputedStyle(elem) : {};
|
|
83
82
|
const prevElemSiblingMarginBottom = getMargin(elem.previousElementSibling, 'marginBottom');
|
|
84
83
|
const nextElemSiblingMarginTop = getMargin(elem.nextElementSibling, 'marginTop');
|
|
85
84
|
const collapsedTopMargin = Math.max(parseFloat(marginTop), prevElemSiblingMarginBottom);
|
|
@@ -146,7 +145,10 @@ function getBlockElement(
|
|
|
146
145
|
top: domRect.top - marginTop,
|
|
147
146
|
});
|
|
148
147
|
|
|
149
|
-
const {
|
|
148
|
+
const {
|
|
149
|
+
result,
|
|
150
|
+
reason: { isOnTopSide, isOnBottomSide },
|
|
151
|
+
} = rect.contains(point);
|
|
150
152
|
|
|
151
153
|
if (result) {
|
|
152
154
|
blockElem = elem;
|
|
@@ -184,13 +186,11 @@ function setMenuPosition(
|
|
|
184
186
|
|
|
185
187
|
const targetRect = targetElem.getBoundingClientRect();
|
|
186
188
|
const targetView = targetElem.ownerDocument.defaultView;
|
|
187
|
-
const targetStyle =
|
|
188
|
-
targetView ? targetView.getComputedStyle(targetElem) : null;
|
|
189
|
+
const targetStyle = targetView ? targetView.getComputedStyle(targetElem) : null;
|
|
189
190
|
const floatingElemRect = floatingElem.getBoundingClientRect();
|
|
190
191
|
const anchorElementRect = anchorElem.getBoundingClientRect();
|
|
191
192
|
|
|
192
|
-
let targetCalculateHeight =
|
|
193
|
-
targetStyle ? parseInt(targetStyle.lineHeight, 10) : NaN;
|
|
193
|
+
let targetCalculateHeight = targetStyle ? parseInt(targetStyle.lineHeight, 10) : NaN;
|
|
194
194
|
if (isNaN(targetCalculateHeight)) {
|
|
195
195
|
targetCalculateHeight = targetRect.bottom - targetRect.top;
|
|
196
196
|
}
|
|
@@ -284,12 +284,15 @@ function useDraggableBlockMenu(
|
|
|
284
284
|
const isDraggingBlockRef = useRef(false);
|
|
285
285
|
const [draggableBlockElem, setDraggableBlockElemState] = useState<HTMLElement | null>(null);
|
|
286
286
|
|
|
287
|
-
const setDraggableBlockElem = useCallback(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
onElementChanged
|
|
291
|
-
|
|
292
|
-
|
|
287
|
+
const setDraggableBlockElem = useCallback(
|
|
288
|
+
(elem: HTMLElement | null) => {
|
|
289
|
+
setDraggableBlockElemState(elem);
|
|
290
|
+
if (onElementChanged) {
|
|
291
|
+
onElementChanged(elem);
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
[onElementChanged],
|
|
295
|
+
);
|
|
293
296
|
|
|
294
297
|
useEffect(() => {
|
|
295
298
|
function onMouseMove(event: MouseEvent) {
|
|
@@ -365,8 +368,7 @@ function useDraggableBlockMenu(
|
|
|
365
368
|
}
|
|
366
369
|
const { dataTransfer, pageY } = event;
|
|
367
370
|
const target = getComposedEventTarget(event);
|
|
368
|
-
const dragData =
|
|
369
|
-
dataTransfer != null ? dataTransfer.getData(DRAG_DATA_FORMAT) : '';
|
|
371
|
+
const dragData = dataTransfer != null ? dataTransfer.getData(DRAG_DATA_FORMAT) : '';
|
|
370
372
|
const draggedNode = $getNodeByKey(dragData);
|
|
371
373
|
if (!draggedNode) {
|
|
372
374
|
return false;
|
|
@@ -5,8 +5,8 @@ import type { LexicalEditor } from 'lexical';
|
|
|
5
5
|
import { useEffect } from 'octane';
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
8
|
-
editorRef:
|
|
9
|
-
|
|
8
|
+
editorRef:
|
|
9
|
+
((editor: LexicalEditor | null) => void) | { current: LexicalEditor | null | undefined };
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export function EditorRefPlugin(props: Props) {
|
|
@@ -29,11 +29,15 @@ export function LexicalErrorBoundary(props: LexicalErrorBoundaryProps) @{
|
|
|
29
29
|
componentStack: '',
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
return props.fallback === undefined
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
return props.fallback === undefined ? (
|
|
33
|
+
<div style={{ border: '1px solid #f00', color: '#f00', padding: '8px' }}>
|
|
34
|
+
An error was thrown.
|
|
35
|
+
</div>
|
|
36
|
+
) : (
|
|
37
|
+
props.fallback
|
|
38
|
+
);
|
|
37
39
|
}}
|
|
38
|
-
>
|
|
40
|
+
>
|
|
41
|
+
{props.children}
|
|
42
|
+
</ErrorBoundary>
|
|
39
43
|
}
|
|
@@ -16,12 +16,12 @@ type Props = {
|
|
|
16
16
|
export function HistoryPlugin(props: Props) {
|
|
17
17
|
const [editor] = useLexicalComposerContext();
|
|
18
18
|
const externalHistoryState = props.externalHistoryState;
|
|
19
|
-
const delay =
|
|
20
|
-
props.delay === undefined ? 1000 : props.delay;
|
|
19
|
+
const delay = props.delay === undefined ? 1000 : props.delay;
|
|
21
20
|
|
|
22
|
-
const historyState = useMemo(
|
|
23
|
-
externalHistoryState,
|
|
24
|
-
|
|
21
|
+
const historyState = useMemo(
|
|
22
|
+
() => externalHistoryState || createEmptyHistoryState(),
|
|
23
|
+
[externalHistoryState],
|
|
24
|
+
);
|
|
25
25
|
|
|
26
26
|
useEffect(() => registerHistory(editor, historyState, delay), [delay, editor, historyState]);
|
|
27
27
|
|
|
@@ -23,11 +23,10 @@ export function LinkPlugin(props: Props) {
|
|
|
23
23
|
}
|
|
24
24
|
}, null);
|
|
25
25
|
|
|
26
|
-
useEffect(
|
|
27
|
-
editor,
|
|
28
|
-
validateUrl,
|
|
29
|
-
|
|
30
|
-
]);
|
|
26
|
+
useEffect(
|
|
27
|
+
() => registerLink(editor, namedSignals({ attributes, validateUrl })),
|
|
28
|
+
[editor, validateUrl, attributes],
|
|
29
|
+
);
|
|
31
30
|
|
|
32
31
|
return null;
|
|
33
32
|
}
|
|
@@ -15,21 +15,20 @@ import { useEffect } from 'octane';
|
|
|
15
15
|
*/
|
|
16
16
|
export interface ListPluginProps {
|
|
17
17
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
* When `true`, enforces strict indentation rules for list items, ensuring
|
|
19
|
+
* consistent structure. When `false` (default), indentation is more flexible.
|
|
20
|
+
*/
|
|
21
21
|
hasStrictIndent?: boolean;
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
* When `true`, splitting a numbered list will preserve the numbering
|
|
24
|
+
* continuity. When `false` (default), the new split list resets to 1.
|
|
25
|
+
*/
|
|
26
26
|
shouldPreserveNumbering?: boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function ListPlugin(props: ListPluginProps) {
|
|
30
30
|
const [editor] = useLexicalComposerContext();
|
|
31
|
-
const hasStrictIndent =
|
|
32
|
-
props.hasStrictIndent === undefined ? false : props.hasStrictIndent;
|
|
31
|
+
const hasStrictIndent = props.hasStrictIndent === undefined ? false : props.hasStrictIndent;
|
|
33
32
|
const shouldPreserveNumbering =
|
|
34
33
|
props.shouldPreserveNumbering === undefined ? false : props.shouldPreserveNumbering;
|
|
35
34
|
|
|
@@ -40,15 +40,13 @@ function defaultTransformers(): Transformer[] {
|
|
|
40
40
|
|
|
41
41
|
export const DEFAULT_TRANSFORMERS: Transformer[] = /* @__PURE__ */ defaultTransformers();
|
|
42
42
|
|
|
43
|
-
type Props =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}>;
|
|
43
|
+
type Props = Readonly<{
|
|
44
|
+
transformers?: Transformer[];
|
|
45
|
+
}>;
|
|
47
46
|
|
|
48
47
|
export function MarkdownShortcutPlugin(props: Props) {
|
|
49
48
|
const [editor] = useLexicalComposerContext();
|
|
50
|
-
const transformers =
|
|
51
|
-
props.transformers === undefined ? DEFAULT_TRANSFORMERS : props.transformers;
|
|
49
|
+
const transformers = props.transformers === undefined ? DEFAULT_TRANSFORMERS : props.transformers;
|
|
52
50
|
|
|
53
51
|
useEffect(() => registerMarkdownShortcuts(editor, transformers), [editor, transformers]);
|
|
54
52
|
|
|
@@ -64,7 +64,7 @@ export function LexicalNestedComposer(props: LexicalNestedComposerProps) {
|
|
|
64
64
|
|
|
65
65
|
if (!initialNodes) {
|
|
66
66
|
if (!(createEditorArgs && createEditorArgs.nodes)) {
|
|
67
|
-
const parentNodes = initialEditor._nodes = new Map(parentEditor._nodes);
|
|
67
|
+
const parentNodes = (initialEditor._nodes = new Map(parentEditor._nodes));
|
|
68
68
|
if (!explicitNamespace) {
|
|
69
69
|
initialEditor._config.namespace = parentEditor._config.namespace;
|
|
70
70
|
}
|
|
@@ -119,8 +119,9 @@ export function LexicalNestedComposer(props: LexicalNestedComposerProps) {
|
|
|
119
119
|
const yjsDocMap = collabContext ? collabContext.yjsDocMap : undefined;
|
|
120
120
|
|
|
121
121
|
const isCollabReady =
|
|
122
|
-
skipCollabChecks ||
|
|
123
|
-
|
|
122
|
+
skipCollabChecks ||
|
|
123
|
+
wasCollabPreviouslyReadyRef.current ||
|
|
124
|
+
(yjsDocMap && yjsDocMap.has(initialEditor.getKey()));
|
|
124
125
|
|
|
125
126
|
useEffect(() => {
|
|
126
127
|
if (isCollabReady) {
|
|
@@ -136,7 +137,9 @@ export function LexicalNestedComposer(props: LexicalNestedComposerProps) {
|
|
|
136
137
|
}
|
|
137
138
|
}, [initialEditor, parentEditor, skipEditableListener]);
|
|
138
139
|
|
|
139
|
-
return
|
|
140
|
-
{
|
|
141
|
-
|
|
140
|
+
return (
|
|
141
|
+
<LexicalComposerContext value={composerContext}>
|
|
142
|
+
{!isCollabActive || isCollabReady ? props.children : null}
|
|
143
|
+
</LexicalComposerContext>
|
|
144
|
+
);
|
|
142
145
|
}
|