@mdxeditor/editor 1.0.0 → 1.1.0
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/importMarkdownToLexical.js +4 -0
- package/dist/plugins/codeblock/index.d.ts +10 -10
- package/dist/plugins/codemirror/index.d.ts +14 -14
- package/dist/plugins/core/NestedLexicalEditor.d.ts +0 -4
- package/dist/plugins/core/NestedLexicalEditor.js +3 -4
- package/dist/plugins/core/index.d.ts +9 -9
- package/dist/plugins/core/index.js +8 -6
- package/dist/plugins/diff-source/DiffViewer.js +49 -9
- package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
- package/dist/plugins/diff-source/SourceEditor.js +34 -18
- package/dist/plugins/diff-source/index.d.ts +10 -10
- package/dist/plugins/diff-source/index.js +2 -1
- package/dist/plugins/directives/index.d.ts +10 -10
- package/dist/plugins/frontmatter/index.d.ts +10 -10
- package/dist/plugins/headings/index.d.ts +10 -10
- package/dist/plugins/image/index.d.ts +10 -10
- package/dist/plugins/jsx/index.d.ts +10 -10
- package/dist/plugins/link/index.d.ts +1 -1
- package/dist/plugins/link-dialog/index.d.ts +8 -8
- package/dist/plugins/link-dialog/index.js +3 -0
- package/dist/plugins/lists/index.d.ts +10 -10
- package/dist/plugins/markdown-shortcut/index.d.ts +1 -1
- package/dist/plugins/quote/index.d.ts +7 -7
- package/dist/plugins/sandpack/index.d.ts +14 -14
- package/dist/plugins/table/index.d.ts +10 -10
- package/dist/plugins/thematic-break/index.d.ts +10 -10
- package/dist/plugins/toolbar/index.d.ts +8 -8
- package/dist/style.css +195 -183
- package/dist/styles/ui.module.css.js +92 -92
- package/dist/utils/lexicalHelpers.d.ts +1 -1
- package/dist/utils/lexicalHelpers.js +16 -12
- package/package.json +19 -16
- package/dist/node_modules/react-diff-view/style/index.css.js +0 -4
|
@@ -3,6 +3,7 @@ function isParent(node) {
|
|
|
3
3
|
return node.children instanceof Array;
|
|
4
4
|
}
|
|
5
5
|
function importMarkdownToLexical({ root, markdown, visitors, syntaxExtensions, mdastExtensions }) {
|
|
6
|
+
var _a;
|
|
6
7
|
const mdastRoot = fromMarkdown(markdown, {
|
|
7
8
|
extensions: syntaxExtensions,
|
|
8
9
|
mdastExtensions
|
|
@@ -10,6 +11,9 @@ function importMarkdownToLexical({ root, markdown, visitors, syntaxExtensions, m
|
|
|
10
11
|
if (mdastRoot.children.length === 0) {
|
|
11
12
|
mdastRoot.children.push({ type: "paragraph", children: [] });
|
|
12
13
|
}
|
|
14
|
+
if (((_a = mdastRoot.children.at(-1)) == null ? void 0 : _a.type) !== "paragraph") {
|
|
15
|
+
mdastRoot.children.push({ type: "paragraph", children: [] });
|
|
16
|
+
}
|
|
13
17
|
importMdastTreeToLexical({ root, mdastRoot, visitors });
|
|
14
18
|
}
|
|
15
19
|
function importMdastTreeToLexical({ root, mdastRoot, visitors }) {
|
|
@@ -97,7 +97,7 @@ export declare const codeBlockSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
97
97
|
placeholder: RealmNode<ReactNode>;
|
|
98
98
|
autoFocus: RealmNode<boolean | {
|
|
99
99
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
100
|
-
preventScroll
|
|
100
|
+
preventScroll?: boolean | undefined;
|
|
101
101
|
}>;
|
|
102
102
|
readOnly: RealmNode<boolean>;
|
|
103
103
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -152,7 +152,7 @@ export declare const codeBlockSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
152
152
|
placeholder: RealmNode<ReactNode>;
|
|
153
153
|
autoFocus: RealmNode<boolean | {
|
|
154
154
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
155
|
-
preventScroll
|
|
155
|
+
preventScroll?: boolean | undefined;
|
|
156
156
|
}>;
|
|
157
157
|
readOnly: RealmNode<boolean>;
|
|
158
158
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -230,7 +230,7 @@ codeBlockPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
230
230
|
placeholder: RealmNode<ReactNode>;
|
|
231
231
|
autoFocus: RealmNode<boolean | {
|
|
232
232
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
233
|
-
preventScroll
|
|
233
|
+
preventScroll?: boolean | undefined;
|
|
234
234
|
}>;
|
|
235
235
|
readOnly: RealmNode<boolean>;
|
|
236
236
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -285,7 +285,7 @@ codeBlockPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
285
285
|
placeholder: RealmNode<ReactNode>;
|
|
286
286
|
autoFocus: RealmNode<boolean | {
|
|
287
287
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
288
|
-
preventScroll
|
|
288
|
+
preventScroll?: boolean | undefined;
|
|
289
289
|
}>;
|
|
290
290
|
readOnly: RealmNode<boolean>;
|
|
291
291
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -355,7 +355,7 @@ codeBlockPluginHooks: {
|
|
|
355
355
|
placeholder: RealmNode<ReactNode>;
|
|
356
356
|
autoFocus: RealmNode<boolean | {
|
|
357
357
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
358
|
-
preventScroll
|
|
358
|
+
preventScroll?: boolean | undefined;
|
|
359
359
|
}>;
|
|
360
360
|
readOnly: RealmNode<boolean>;
|
|
361
361
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -416,7 +416,7 @@ codeBlockPluginHooks: {
|
|
|
416
416
|
placeholder: RealmNode<ReactNode>;
|
|
417
417
|
autoFocus: RealmNode<boolean | {
|
|
418
418
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
419
|
-
preventScroll
|
|
419
|
+
preventScroll?: boolean | undefined;
|
|
420
420
|
}>;
|
|
421
421
|
readOnly: RealmNode<boolean>;
|
|
422
422
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -477,7 +477,7 @@ codeBlockPluginHooks: {
|
|
|
477
477
|
placeholder: RealmNode<ReactNode>;
|
|
478
478
|
autoFocus: RealmNode<boolean | {
|
|
479
479
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
480
|
-
preventScroll
|
|
480
|
+
preventScroll?: boolean | undefined;
|
|
481
481
|
}>;
|
|
482
482
|
readOnly: RealmNode<boolean>;
|
|
483
483
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -537,7 +537,7 @@ codeBlockPluginHooks: {
|
|
|
537
537
|
placeholder: RealmNode<ReactNode>;
|
|
538
538
|
autoFocus: RealmNode<boolean | {
|
|
539
539
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
540
|
-
preventScroll
|
|
540
|
+
preventScroll?: boolean | undefined;
|
|
541
541
|
}>;
|
|
542
542
|
readOnly: RealmNode<boolean>;
|
|
543
543
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -598,7 +598,7 @@ codeBlockPluginHooks: {
|
|
|
598
598
|
placeholder: RealmNode<ReactNode>;
|
|
599
599
|
autoFocus: RealmNode<boolean | {
|
|
600
600
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
601
|
-
preventScroll
|
|
601
|
+
preventScroll?: boolean | undefined;
|
|
602
602
|
}>;
|
|
603
603
|
readOnly: RealmNode<boolean>;
|
|
604
604
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -659,7 +659,7 @@ codeBlockPluginHooks: {
|
|
|
659
659
|
placeholder: RealmNode<ReactNode>;
|
|
660
660
|
autoFocus: RealmNode<boolean | {
|
|
661
661
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
662
|
-
preventScroll
|
|
662
|
+
preventScroll?: boolean | undefined;
|
|
663
663
|
}>;
|
|
664
664
|
readOnly: RealmNode<boolean>;
|
|
665
665
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -45,7 +45,7 @@ export declare const codeMirrorSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
|
|
|
45
45
|
placeholder: RealmNode<ReactNode>;
|
|
46
46
|
autoFocus: RealmNode<boolean | {
|
|
47
47
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
48
|
-
preventScroll
|
|
48
|
+
preventScroll?: boolean | undefined;
|
|
49
49
|
}>;
|
|
50
50
|
readOnly: RealmNode<boolean>;
|
|
51
51
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -100,7 +100,7 @@ export declare const codeMirrorSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
|
|
|
100
100
|
placeholder: RealmNode<ReactNode>;
|
|
101
101
|
autoFocus: RealmNode<boolean | {
|
|
102
102
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
103
|
-
preventScroll
|
|
103
|
+
preventScroll?: boolean | undefined;
|
|
104
104
|
}>;
|
|
105
105
|
readOnly: RealmNode<boolean>;
|
|
106
106
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -155,7 +155,7 @@ export declare const codeMirrorSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
|
|
|
155
155
|
placeholder: RealmNode<ReactNode>;
|
|
156
156
|
autoFocus: RealmNode<boolean | {
|
|
157
157
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
158
|
-
preventScroll
|
|
158
|
+
preventScroll?: boolean | undefined;
|
|
159
159
|
}>;
|
|
160
160
|
readOnly: RealmNode<boolean>;
|
|
161
161
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -215,7 +215,7 @@ export declare const codeMirrorSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
|
|
|
215
215
|
placeholder: RealmNode<ReactNode>;
|
|
216
216
|
autoFocus: RealmNode<boolean | {
|
|
217
217
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
218
|
-
preventScroll
|
|
218
|
+
preventScroll?: boolean | undefined;
|
|
219
219
|
}>;
|
|
220
220
|
readOnly: RealmNode<boolean>;
|
|
221
221
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -284,7 +284,7 @@ codeMirrorPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
284
284
|
placeholder: RealmNode<ReactNode>;
|
|
285
285
|
autoFocus: RealmNode<boolean | {
|
|
286
286
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
287
|
-
preventScroll
|
|
287
|
+
preventScroll?: boolean | undefined;
|
|
288
288
|
}>;
|
|
289
289
|
readOnly: RealmNode<boolean>;
|
|
290
290
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -339,7 +339,7 @@ codeMirrorPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
339
339
|
placeholder: RealmNode<ReactNode>;
|
|
340
340
|
autoFocus: RealmNode<boolean | {
|
|
341
341
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
342
|
-
preventScroll
|
|
342
|
+
preventScroll?: boolean | undefined;
|
|
343
343
|
}>;
|
|
344
344
|
readOnly: RealmNode<boolean>;
|
|
345
345
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -394,7 +394,7 @@ codeMirrorPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
394
394
|
placeholder: RealmNode<ReactNode>;
|
|
395
395
|
autoFocus: RealmNode<boolean | {
|
|
396
396
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
397
|
-
preventScroll
|
|
397
|
+
preventScroll?: boolean | undefined;
|
|
398
398
|
}>;
|
|
399
399
|
readOnly: RealmNode<boolean>;
|
|
400
400
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -454,7 +454,7 @@ codeMirrorPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
454
454
|
placeholder: RealmNode<ReactNode>;
|
|
455
455
|
autoFocus: RealmNode<boolean | {
|
|
456
456
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
457
|
-
preventScroll
|
|
457
|
+
preventScroll?: boolean | undefined;
|
|
458
458
|
}>;
|
|
459
459
|
readOnly: RealmNode<boolean>;
|
|
460
460
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -531,7 +531,7 @@ codeMirrorHooks: {
|
|
|
531
531
|
placeholder: RealmNode<ReactNode>;
|
|
532
532
|
autoFocus: RealmNode<boolean | {
|
|
533
533
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
534
|
-
preventScroll
|
|
534
|
+
preventScroll?: boolean | undefined;
|
|
535
535
|
}>;
|
|
536
536
|
readOnly: RealmNode<boolean>;
|
|
537
537
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -598,7 +598,7 @@ codeMirrorHooks: {
|
|
|
598
598
|
placeholder: RealmNode<ReactNode>;
|
|
599
599
|
autoFocus: RealmNode<boolean | {
|
|
600
600
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
601
|
-
preventScroll
|
|
601
|
+
preventScroll?: boolean | undefined;
|
|
602
602
|
}>;
|
|
603
603
|
readOnly: RealmNode<boolean>;
|
|
604
604
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -665,7 +665,7 @@ codeMirrorHooks: {
|
|
|
665
665
|
placeholder: RealmNode<ReactNode>;
|
|
666
666
|
autoFocus: RealmNode<boolean | {
|
|
667
667
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
668
|
-
preventScroll
|
|
668
|
+
preventScroll?: boolean | undefined;
|
|
669
669
|
}>;
|
|
670
670
|
readOnly: RealmNode<boolean>;
|
|
671
671
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -731,7 +731,7 @@ codeMirrorHooks: {
|
|
|
731
731
|
placeholder: RealmNode<ReactNode>;
|
|
732
732
|
autoFocus: RealmNode<boolean | {
|
|
733
733
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
734
|
-
preventScroll
|
|
734
|
+
preventScroll?: boolean | undefined;
|
|
735
735
|
}>;
|
|
736
736
|
readOnly: RealmNode<boolean>;
|
|
737
737
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -798,7 +798,7 @@ codeMirrorHooks: {
|
|
|
798
798
|
placeholder: RealmNode<ReactNode>;
|
|
799
799
|
autoFocus: RealmNode<boolean | {
|
|
800
800
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
801
|
-
preventScroll
|
|
801
|
+
preventScroll?: boolean | undefined;
|
|
802
802
|
}>;
|
|
803
803
|
readOnly: RealmNode<boolean>;
|
|
804
804
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -865,7 +865,7 @@ codeMirrorHooks: {
|
|
|
865
865
|
placeholder: RealmNode<ReactNode>;
|
|
866
866
|
autoFocus: RealmNode<boolean | {
|
|
867
867
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
868
|
-
preventScroll
|
|
868
|
+
preventScroll?: boolean | undefined;
|
|
869
869
|
}>;
|
|
870
870
|
readOnly: RealmNode<boolean>;
|
|
871
871
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -72,10 +72,6 @@ export interface NestedEditorProps<T extends Mdast.Content> {
|
|
|
72
72
|
* Whether or not the editor edits blocks (multiple paragraphs)
|
|
73
73
|
*/
|
|
74
74
|
block?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* An emitter (usually constructed in the lexical node) that will activate the editor when the node is focused.
|
|
77
|
-
*/
|
|
78
|
-
focusEmitter?: VoidEmitter;
|
|
79
75
|
}
|
|
80
76
|
/**
|
|
81
77
|
* A nested editor React component that allows editing of the contents of complex markdown nodes that have nested markdown content (for example, custom directives or JSX elements). See the {@link NestedEditorProps} for more details on the compoment props.
|
|
@@ -44,7 +44,7 @@ function useLexicalNodeRemove() {
|
|
|
44
44
|
}
|
|
45
45
|
const NestedLexicalEditor = function(props) {
|
|
46
46
|
const { getContent, getUpdatedMdastNode, contentEditableProps, block = false } = props;
|
|
47
|
-
const { mdastNode, lexicalNode } = useNestedEditorContext();
|
|
47
|
+
const { mdastNode, lexicalNode, focusEmitter } = useNestedEditorContext();
|
|
48
48
|
const updateMdastNode = useMdastNodeUpdater();
|
|
49
49
|
const removeNode = useLexicalNodeRemove();
|
|
50
50
|
const content = getContent(mdastNode);
|
|
@@ -66,11 +66,10 @@ const NestedLexicalEditor = function(props) {
|
|
|
66
66
|
return editor2;
|
|
67
67
|
});
|
|
68
68
|
React__default.useEffect(() => {
|
|
69
|
-
|
|
70
|
-
(_a = props.focusEmitter) == null ? void 0 : _a.subscribe(() => {
|
|
69
|
+
focusEmitter == null ? void 0 : focusEmitter.subscribe(() => {
|
|
71
70
|
editor.focus();
|
|
72
71
|
});
|
|
73
|
-
}, [editor,
|
|
72
|
+
}, [editor, focusEmitter]);
|
|
74
73
|
React__default.useEffect(() => {
|
|
75
74
|
editor.update(() => {
|
|
76
75
|
$getRoot().clear();
|
|
@@ -60,7 +60,7 @@ export declare const coreSystem: SystemSpec<[], (r: Realm) => {
|
|
|
60
60
|
placeholder: RealmNode<React.ReactNode>;
|
|
61
61
|
autoFocus: RealmNode<boolean | {
|
|
62
62
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
63
|
-
preventScroll
|
|
63
|
+
preventScroll?: boolean | undefined;
|
|
64
64
|
}>;
|
|
65
65
|
readOnly: RealmNode<boolean>;
|
|
66
66
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -90,7 +90,7 @@ interface CorePluginParams {
|
|
|
90
90
|
placeholder?: React.ReactNode;
|
|
91
91
|
autoFocus: boolean | {
|
|
92
92
|
defaultSelection?: 'rootStart' | 'rootEnd';
|
|
93
|
-
preventScroll?: boolean;
|
|
93
|
+
preventScroll?: boolean | undefined;
|
|
94
94
|
};
|
|
95
95
|
onChange: (markdown: string) => void;
|
|
96
96
|
onBlur?: (e: FocusEvent) => void;
|
|
@@ -131,7 +131,7 @@ corePlugin: PluginConstructor<SystemSpec<[], (r: Realm) => {
|
|
|
131
131
|
placeholder: RealmNode<React.ReactNode>;
|
|
132
132
|
autoFocus: RealmNode<boolean | {
|
|
133
133
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
134
|
-
preventScroll
|
|
134
|
+
preventScroll?: boolean | undefined;
|
|
135
135
|
}>;
|
|
136
136
|
readOnly: RealmNode<boolean>;
|
|
137
137
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -189,7 +189,7 @@ corePluginHooks: {
|
|
|
189
189
|
placeholder: RealmNode<React.ReactNode>;
|
|
190
190
|
autoFocus: RealmNode<boolean | {
|
|
191
191
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
192
|
-
preventScroll
|
|
192
|
+
preventScroll?: boolean | undefined;
|
|
193
193
|
}>;
|
|
194
194
|
readOnly: RealmNode<boolean>;
|
|
195
195
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -245,7 +245,7 @@ corePluginHooks: {
|
|
|
245
245
|
placeholder: RealmNode<React.ReactNode>;
|
|
246
246
|
autoFocus: RealmNode<boolean | {
|
|
247
247
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
248
|
-
preventScroll
|
|
248
|
+
preventScroll?: boolean | undefined;
|
|
249
249
|
}>;
|
|
250
250
|
readOnly: RealmNode<boolean>;
|
|
251
251
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -301,7 +301,7 @@ corePluginHooks: {
|
|
|
301
301
|
placeholder: RealmNode<React.ReactNode>;
|
|
302
302
|
autoFocus: RealmNode<boolean | {
|
|
303
303
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
304
|
-
preventScroll
|
|
304
|
+
preventScroll?: boolean | undefined;
|
|
305
305
|
}>;
|
|
306
306
|
readOnly: RealmNode<boolean>;
|
|
307
307
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -356,7 +356,7 @@ corePluginHooks: {
|
|
|
356
356
|
placeholder: RealmNode<React.ReactNode>;
|
|
357
357
|
autoFocus: RealmNode<boolean | {
|
|
358
358
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
359
|
-
preventScroll
|
|
359
|
+
preventScroll?: boolean | undefined;
|
|
360
360
|
}>;
|
|
361
361
|
readOnly: RealmNode<boolean>;
|
|
362
362
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -412,7 +412,7 @@ corePluginHooks: {
|
|
|
412
412
|
placeholder: RealmNode<React.ReactNode>;
|
|
413
413
|
autoFocus: RealmNode<boolean | {
|
|
414
414
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
415
|
-
preventScroll
|
|
415
|
+
preventScroll?: boolean | undefined;
|
|
416
416
|
}>;
|
|
417
417
|
readOnly: RealmNode<boolean>;
|
|
418
418
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -468,7 +468,7 @@ corePluginHooks: {
|
|
|
468
468
|
placeholder: RealmNode<React.ReactNode>;
|
|
469
469
|
autoFocus: RealmNode<boolean | {
|
|
470
470
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
471
|
-
preventScroll
|
|
471
|
+
preventScroll?: boolean | undefined;
|
|
472
472
|
}>;
|
|
473
473
|
readOnly: RealmNode<boolean>;
|
|
474
474
|
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
@@ -2,7 +2,7 @@ import { createEmptyHistoryState } from "@lexical/react/LexicalHistoryPlugin.js"
|
|
|
2
2
|
import { $isHeadingNode } from "@lexical/rich-text";
|
|
3
3
|
import { $setBlocksType } from "@lexical/selection";
|
|
4
4
|
import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
|
|
5
|
-
import { createCommand, SELECTION_CHANGE_COMMAND, $getRoot, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
|
|
5
|
+
import { createCommand, SELECTION_CHANGE_COMMAND, $getRoot, COMMAND_PRIORITY_CRITICAL, $setSelection, BLUR_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
|
|
6
6
|
import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
|
|
7
7
|
import { importMarkdownToLexical } from "../../importMarkdownToLexical.js";
|
|
8
8
|
import { LexicalLinebreakVisitor } from "./LexicalLinebreakVisitor.js";
|
|
@@ -137,8 +137,8 @@ const coreSystem = system((r) => {
|
|
|
137
137
|
const addToMarkdownExtension = createAppendNodeFor(toMarkdownExtensions);
|
|
138
138
|
const setMarkdown = r.node();
|
|
139
139
|
r.sub(
|
|
140
|
-
r.pipe(setMarkdown, r.o.withLatestFrom(rootEditor, importVisitors, mdastExtensions, syntaxExtensions)),
|
|
141
|
-
([theNewMarkdownValue, editor, importVisitors2, mdastExtensions2, syntaxExtensions2]) => {
|
|
140
|
+
r.pipe(setMarkdown, r.o.withLatestFrom(rootEditor, importVisitors, mdastExtensions, syntaxExtensions, inFocus)),
|
|
141
|
+
([theNewMarkdownValue, editor, importVisitors2, mdastExtensions2, syntaxExtensions2, inFocus2]) => {
|
|
142
142
|
editor == null ? void 0 : editor.update(() => {
|
|
143
143
|
$getRoot().clear();
|
|
144
144
|
importMarkdownToLexical({
|
|
@@ -148,6 +148,9 @@ const coreSystem = system((r) => {
|
|
|
148
148
|
markdown: theNewMarkdownValue,
|
|
149
149
|
syntaxExtensions: syntaxExtensions2
|
|
150
150
|
});
|
|
151
|
+
if (!inFocus2) {
|
|
152
|
+
$setSelection(null);
|
|
153
|
+
}
|
|
151
154
|
});
|
|
152
155
|
}
|
|
153
156
|
);
|
|
@@ -169,8 +172,7 @@ const coreSystem = system((r) => {
|
|
|
169
172
|
}
|
|
170
173
|
setTimeout(
|
|
171
174
|
() => theRootEditor.focus(noop, {
|
|
172
|
-
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
173
|
-
preventScroll: autoFocusValue.preventScroll ?? false
|
|
175
|
+
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
174
176
|
})
|
|
175
177
|
);
|
|
176
178
|
}
|
|
@@ -296,7 +298,7 @@ const coreSystem = system((r) => {
|
|
|
296
298
|
$insertNodeToNearestRoot(node);
|
|
297
299
|
}
|
|
298
300
|
if (Object.hasOwn(node, "select") && typeof node.select === "function") {
|
|
299
|
-
setTimeout(() => node.select()
|
|
301
|
+
setTimeout(() => node.select());
|
|
300
302
|
}
|
|
301
303
|
});
|
|
302
304
|
}
|
|
@@ -1,17 +1,57 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
|
-
import { parseDiff, Diff, Hunk } from "react-diff-view";
|
|
3
|
-
import { formatLines, diffLines } from "unidiff";
|
|
4
|
-
import "../../node_modules/react-diff-view/style/index.css.js";
|
|
5
|
-
import { corePluginHooks } from "../core/index.js";
|
|
6
2
|
import { diffSourcePluginHooks } from "./index.js";
|
|
3
|
+
import { corePluginHooks } from "../core/index.js";
|
|
4
|
+
import { MergeView } from "@codemirror/merge";
|
|
5
|
+
import { EditorState } from "@codemirror/state";
|
|
6
|
+
import { EditorView } from "@codemirror/view";
|
|
7
|
+
import { COMMON_STATE_CONFIG_EXTENSIONS } from "./SourceEditor.js";
|
|
7
8
|
const DiffViewer = () => {
|
|
8
9
|
const [newText] = corePluginHooks.useEmitterValues("markdown");
|
|
9
10
|
const [oldText] = diffSourcePluginHooks.useEmitterValues("diffMarkdown");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
|
|
12
|
+
return /* @__PURE__ */ React__default.createElement(CmMergeView, { oldMarkdown: oldText, newMarkdown: newText, onUpdate: updateMarkdown });
|
|
13
|
+
};
|
|
14
|
+
const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
|
|
15
|
+
const cmMergeViewRef = React__default.useRef(null);
|
|
16
|
+
const ref = React__default.useCallback(
|
|
17
|
+
(el) => {
|
|
18
|
+
var _a;
|
|
19
|
+
if (el !== null) {
|
|
20
|
+
cmMergeViewRef.current = new MergeView({
|
|
21
|
+
renderRevertControl: () => {
|
|
22
|
+
const el2 = document.createElement("button");
|
|
23
|
+
el2.classList.add("cm-merge-revert");
|
|
24
|
+
el2.appendChild(document.createTextNode("⮕"));
|
|
25
|
+
return el2;
|
|
26
|
+
},
|
|
27
|
+
parent: el,
|
|
28
|
+
orientation: "a-b",
|
|
29
|
+
revertControls: "a-to-b",
|
|
30
|
+
gutter: true,
|
|
31
|
+
collapseUnchanged: { margin: 2, minSize: 3 },
|
|
32
|
+
a: {
|
|
33
|
+
doc: oldMarkdown,
|
|
34
|
+
extensions: [...COMMON_STATE_CONFIG_EXTENSIONS, EditorState.readOnly.of(true)]
|
|
35
|
+
},
|
|
36
|
+
b: {
|
|
37
|
+
doc: newMarkdown,
|
|
38
|
+
extensions: [
|
|
39
|
+
...COMMON_STATE_CONFIG_EXTENSIONS,
|
|
40
|
+
EditorView.updateListener.of(({ state }) => {
|
|
41
|
+
const md = state.doc.toString();
|
|
42
|
+
onUpdate(md);
|
|
43
|
+
})
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
(_a = cmMergeViewRef.current) == null ? void 0 : _a.destroy();
|
|
49
|
+
cmMergeViewRef.current = null;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[newMarkdown, oldMarkdown, onUpdate]
|
|
53
|
+
);
|
|
54
|
+
return /* @__PURE__ */ React__default.createElement("div", { ref });
|
|
15
55
|
};
|
|
16
56
|
export {
|
|
17
57
|
DiffViewer
|
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
import { markdown } from "@codemirror/lang-markdown";
|
|
2
|
-
import {
|
|
2
|
+
import { EditorState } from "@codemirror/state";
|
|
3
|
+
import { lineNumbers, EditorView } from "@codemirror/view";
|
|
4
|
+
import { basicLight } from "cm6-theme-basic-light";
|
|
5
|
+
import { basicSetup } from "codemirror";
|
|
3
6
|
import React__default from "react";
|
|
4
7
|
import { diffSourcePluginHooks } from "./index.js";
|
|
5
8
|
import { corePluginHooks } from "../core/index.js";
|
|
6
|
-
|
|
9
|
+
const COMMON_STATE_CONFIG_EXTENSIONS = [basicSetup, basicLight, markdown(), lineNumbers()];
|
|
7
10
|
const SourceEditor = () => {
|
|
8
|
-
const [
|
|
11
|
+
const [markdown2, readOnly] = corePluginHooks.useEmitterValues("markdown", "readOnly");
|
|
9
12
|
const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
const editorViewRef = React__default.useRef(null);
|
|
14
|
+
const ref = React__default.useCallback(
|
|
15
|
+
(el) => {
|
|
16
|
+
var _a;
|
|
17
|
+
if (el !== null) {
|
|
18
|
+
const extensions = [
|
|
19
|
+
...COMMON_STATE_CONFIG_EXTENSIONS,
|
|
20
|
+
EditorView.updateListener.of(({ state }) => {
|
|
21
|
+
updateMarkdown(state.doc.toString());
|
|
22
|
+
})
|
|
23
|
+
];
|
|
24
|
+
if (readOnly) {
|
|
25
|
+
extensions.push(EditorState.readOnly.of(true));
|
|
26
|
+
}
|
|
27
|
+
el.innerHTML = "";
|
|
28
|
+
editorViewRef.current = new EditorView({
|
|
29
|
+
parent: el,
|
|
30
|
+
state: EditorState.create({ doc: markdown2, extensions })
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
(_a = editorViewRef.current) == null ? void 0 : _a.destroy();
|
|
34
|
+
editorViewRef.current = null;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[markdown2, readOnly, updateMarkdown]
|
|
38
|
+
);
|
|
39
|
+
return /* @__PURE__ */ React__default.createElement("div", { ref, className: "cm-sourceView" });
|
|
25
40
|
};
|
|
26
41
|
export {
|
|
42
|
+
COMMON_STATE_CONFIG_EXTENSIONS,
|
|
27
43
|
SourceEditor
|
|
28
44
|
};
|
|
@@ -46,7 +46,7 @@ export declare const diffSourceSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
|
|
|
46
46
|
placeholder: RealmNode<ReactNode>;
|
|
47
47
|
autoFocus: RealmNode<boolean | {
|
|
48
48
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
49
|
-
preventScroll
|
|
49
|
+
preventScroll?: boolean | undefined;
|
|
50
50
|
}>;
|
|
51
51
|
readOnly: RealmNode<boolean>;
|
|
52
52
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -101,7 +101,7 @@ export declare const diffSourceSystem: SystemSpec<[SystemSpec<[], (r: Realm) =>
|
|
|
101
101
|
placeholder: RealmNode<ReactNode>;
|
|
102
102
|
autoFocus: RealmNode<boolean | {
|
|
103
103
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
104
|
-
preventScroll
|
|
104
|
+
preventScroll?: boolean | undefined;
|
|
105
105
|
}>;
|
|
106
106
|
readOnly: RealmNode<boolean>;
|
|
107
107
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -163,7 +163,7 @@ diffSourcePlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
163
163
|
placeholder: RealmNode<ReactNode>;
|
|
164
164
|
autoFocus: RealmNode<boolean | {
|
|
165
165
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
166
|
-
preventScroll
|
|
166
|
+
preventScroll?: boolean | undefined;
|
|
167
167
|
}>;
|
|
168
168
|
readOnly: RealmNode<boolean>;
|
|
169
169
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -218,7 +218,7 @@ diffSourcePlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
218
218
|
placeholder: RealmNode<ReactNode>;
|
|
219
219
|
autoFocus: RealmNode<boolean | {
|
|
220
220
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
221
|
-
preventScroll
|
|
221
|
+
preventScroll?: boolean | undefined;
|
|
222
222
|
}>;
|
|
223
223
|
readOnly: RealmNode<boolean>;
|
|
224
224
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -287,7 +287,7 @@ diffSourcePluginHooks: {
|
|
|
287
287
|
placeholder: RealmNode<ReactNode>;
|
|
288
288
|
autoFocus: RealmNode<boolean | {
|
|
289
289
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
290
|
-
preventScroll
|
|
290
|
+
preventScroll?: boolean | undefined;
|
|
291
291
|
}>;
|
|
292
292
|
readOnly: RealmNode<boolean>;
|
|
293
293
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -347,7 +347,7 @@ diffSourcePluginHooks: {
|
|
|
347
347
|
placeholder: RealmNode<ReactNode>;
|
|
348
348
|
autoFocus: RealmNode<boolean | {
|
|
349
349
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
350
|
-
preventScroll
|
|
350
|
+
preventScroll?: boolean | undefined;
|
|
351
351
|
}>;
|
|
352
352
|
readOnly: RealmNode<boolean>;
|
|
353
353
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -407,7 +407,7 @@ diffSourcePluginHooks: {
|
|
|
407
407
|
placeholder: RealmNode<ReactNode>;
|
|
408
408
|
autoFocus: RealmNode<boolean | {
|
|
409
409
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
410
|
-
preventScroll
|
|
410
|
+
preventScroll?: boolean | undefined;
|
|
411
411
|
}>;
|
|
412
412
|
readOnly: RealmNode<boolean>;
|
|
413
413
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -466,7 +466,7 @@ diffSourcePluginHooks: {
|
|
|
466
466
|
placeholder: RealmNode<ReactNode>;
|
|
467
467
|
autoFocus: RealmNode<boolean | {
|
|
468
468
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
469
|
-
preventScroll
|
|
469
|
+
preventScroll?: boolean | undefined;
|
|
470
470
|
}>;
|
|
471
471
|
readOnly: RealmNode<boolean>;
|
|
472
472
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -526,7 +526,7 @@ diffSourcePluginHooks: {
|
|
|
526
526
|
placeholder: RealmNode<ReactNode>;
|
|
527
527
|
autoFocus: RealmNode<boolean | {
|
|
528
528
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
529
|
-
preventScroll
|
|
529
|
+
preventScroll?: boolean | undefined;
|
|
530
530
|
}>;
|
|
531
531
|
readOnly: RealmNode<boolean>;
|
|
532
532
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -586,7 +586,7 @@ diffSourcePluginHooks: {
|
|
|
586
586
|
placeholder: RealmNode<ReactNode>;
|
|
587
587
|
autoFocus: RealmNode<boolean | {
|
|
588
588
|
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
589
|
-
preventScroll
|
|
589
|
+
preventScroll?: boolean | undefined;
|
|
590
590
|
}>;
|
|
591
591
|
readOnly: RealmNode<boolean>;
|
|
592
592
|
composerChildren: RealmNode<ComponentType<{}>[]>;
|
|
@@ -23,7 +23,8 @@ const diffSourceSystem = system(
|
|
|
23
23
|
r.o.withLatestFrom(markdownSourceEditorValue)
|
|
24
24
|
),
|
|
25
25
|
([{ current }, markdownSourceFromEditor]) => {
|
|
26
|
-
if (current === "source") {
|
|
26
|
+
if (current === "source" || current === "diff") {
|
|
27
|
+
console.log("setting markdown", markdownSourceFromEditor);
|
|
27
28
|
r.pub(setMarkdown, markdownSourceFromEditor);
|
|
28
29
|
}
|
|
29
30
|
}
|