@mdxeditor/editor 4.0.4 → 4.1.1
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/MDXEditor.js +138 -53
- package/dist/RealmWithPlugins.js +27 -9
- package/dist/exportMarkdownFromLexical.js +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.js +6 -6
- package/dist/mdastUtilHtmlComment.js +2 -1
- package/dist/plugins/codeblock/CodeBlockNode.js +4 -5
- package/dist/plugins/codeblock/index.js +1 -1
- package/dist/plugins/codemirror/CodeMirrorEditor.js +1 -1
- package/dist/plugins/core/GenericHTMLNode.js +2 -5
- package/dist/plugins/core/NestedLexicalEditor.js +58 -38
- package/dist/plugins/core/index.js +26 -30
- package/dist/plugins/core/lexicalExtensions.js +143 -0
- package/dist/plugins/diff-source/SourceEditor.js +1 -1
- package/dist/plugins/directives/DirectiveNode.js +1 -4
- package/dist/plugins/frontmatter/FrontmatterNode.js +1 -4
- package/dist/plugins/frontmatter/index.js +1 -1
- package/dist/plugins/headings/index.js +2 -1
- package/dist/plugins/image/ImageDialog.js +1 -2
- package/dist/plugins/image/ImageEditor.js +1 -2
- package/dist/plugins/image/ImageNode.js +1 -4
- package/dist/plugins/image/index.js +4 -6
- package/dist/plugins/jsx/LexicalJsxNode.js +1 -4
- package/dist/plugins/jsx/LexicalMdxExpressionNode.js +1 -4
- package/dist/plugins/link-dialog/LinkDialog.js +3 -3
- package/dist/plugins/link-dialog/index.js +16 -4
- package/dist/plugins/lists/index.js +3 -3
- package/dist/plugins/markdown-shortcut/index.js +1 -1
- package/dist/plugins/search/index.js +259 -179
- package/dist/plugins/table/TableEditor.js +38 -24
- package/dist/plugins/table/TableNode.js +1 -4
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +2 -2
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +1 -1
- package/dist/plugins/toolbar/primitives/toolbar.js +1 -1
- package/dist/realmSession.js +38 -0
- package/dist/style.css +1511 -1525
- package/dist/utils/lexicalHelpers.js +53 -74
- package/package.json +23 -12
- package/dist/plugins/core/SharedHistoryPlugin.js +0 -10
- package/dist/styles/globals.css.js +0 -1
package/dist/MDXEditor.js
CHANGED
|
@@ -2,22 +2,18 @@ import { usePublisher, useCellValue, useCellValues, useRealm } from "@mdxeditor/
|
|
|
2
2
|
import React__default from "react";
|
|
3
3
|
import { corePlugin, editorRootElementRef$, editorWrapperElementRef$, rootEditor$, useTranslation, contentEditableRef$, contentEditableWrapperElement$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, bottomAreaChildren$, viewMode$, activeEditor$, exportVisitors$, toMarkdownExtensions$, toMarkdownOptions$, jsxComponentDescriptors$, jsxIsAvailable$, insertMarkdown$, setMarkdown$, markdownSourceEditorValue$, markdown$ } from "./plugins/core/index.js";
|
|
4
4
|
import { RealmWithPlugins } from "./RealmWithPlugins.js";
|
|
5
|
-
import {
|
|
5
|
+
import { LexicalExtensionEditorComposer } from "@lexical/react/LexicalExtensionEditorComposer";
|
|
6
6
|
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
7
7
|
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
8
8
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
9
9
|
import classNames from "classnames";
|
|
10
10
|
import { defaultSvgIcons } from "./defaultSvgIcons.js";
|
|
11
|
-
import { lexicalTheme } from "./styles/lexicalTheme.js";
|
|
12
11
|
import styles from "./styles/ui.module.css.js";
|
|
13
12
|
import { noop } from "./utils/fp.js";
|
|
14
13
|
import { getSelectionAsMarkdown } from "./utils/lexicalHelpers.js";
|
|
15
14
|
const LexicalProvider = ({ children }) => {
|
|
16
15
|
const rootEditor = useCellValue(rootEditor$);
|
|
17
|
-
|
|
18
|
-
return [rootEditor, createLexicalComposerContext(null, lexicalTheme)];
|
|
19
|
-
}, [rootEditor]);
|
|
20
|
-
return /* @__PURE__ */ React__default.createElement(LexicalComposerContext.Provider, { value: composerContextValue }, children);
|
|
16
|
+
return /* @__PURE__ */ React__default.createElement(LexicalExtensionEditorComposer, { initialEditor: rootEditor }, children);
|
|
21
17
|
};
|
|
22
18
|
const RichTextEditor = () => {
|
|
23
19
|
const t = useTranslation();
|
|
@@ -96,56 +92,145 @@ const EditorRootElement = ({ children, className, overlayContainer }) => {
|
|
|
96
92
|
}, [className, editorRootElementRef, overlayContainer, setEditorRootElementRef, setEditorWrapperElementRef]);
|
|
97
93
|
return /* @__PURE__ */ React__default.createElement("div", { className: classNames("mdxeditor", styles.editorRoot, styles.editorWrapper, className), ref: wrapperElementRef }, children);
|
|
98
94
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (viewMode === "source" || viewMode === "diff") {
|
|
108
|
-
return realm.getValue(markdownSourceEditorValue$);
|
|
109
|
-
}
|
|
110
|
-
return realm.getValue(markdown$);
|
|
111
|
-
},
|
|
112
|
-
setMarkdown: (markdown) => {
|
|
113
|
-
realm.pub(setMarkdown$, markdown);
|
|
114
|
-
},
|
|
115
|
-
insertMarkdown: (markdown) => {
|
|
116
|
-
realm.pub(insertMarkdown$, markdown);
|
|
117
|
-
},
|
|
118
|
-
focus: (callbackFn, opts) => {
|
|
119
|
-
var _a;
|
|
120
|
-
(_a = realm.getValue(rootEditor$)) == null ? void 0 : _a.focus(callbackFn, opts);
|
|
121
|
-
},
|
|
122
|
-
getContentEditableHTML: () => {
|
|
123
|
-
var _a;
|
|
124
|
-
return ((_a = realm.getValue(contentEditableRef$)) == null ? void 0 : _a.current.innerHTML) ?? "";
|
|
125
|
-
},
|
|
126
|
-
getSelectionMarkdown: () => {
|
|
127
|
-
const viewMode = realm.getValue(viewMode$);
|
|
128
|
-
if (viewMode === "source" || viewMode === "diff") {
|
|
129
|
-
return "";
|
|
130
|
-
}
|
|
131
|
-
const activeEditor = realm.getValue(activeEditor$);
|
|
132
|
-
if (!activeEditor) {
|
|
133
|
-
return "";
|
|
134
|
-
}
|
|
135
|
-
realm.getValue(exportVisitors$);
|
|
136
|
-
realm.getValue(toMarkdownExtensions$);
|
|
137
|
-
realm.getValue(toMarkdownOptions$);
|
|
138
|
-
realm.getValue(jsxComponentDescriptors$);
|
|
139
|
-
realm.getValue(jsxIsAvailable$);
|
|
140
|
-
return getSelectionAsMarkdown(activeEditor);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
95
|
+
function createMethods(realm) {
|
|
96
|
+
return {
|
|
97
|
+
getMarkdown: () => {
|
|
98
|
+
const viewMode = realm.getValue(viewMode$);
|
|
99
|
+
if (viewMode === "source" || viewMode === "diff") {
|
|
100
|
+
return realm.getValue(markdownSourceEditorValue$);
|
|
101
|
+
}
|
|
102
|
+
return realm.getValue(markdown$);
|
|
143
103
|
},
|
|
144
|
-
|
|
145
|
-
|
|
104
|
+
setMarkdown: (markdown) => {
|
|
105
|
+
realm.pub(setMarkdown$, markdown);
|
|
106
|
+
},
|
|
107
|
+
insertMarkdown: (markdown) => {
|
|
108
|
+
realm.pub(insertMarkdown$, markdown);
|
|
109
|
+
},
|
|
110
|
+
focus: (callbackFn, opts) => {
|
|
111
|
+
var _a;
|
|
112
|
+
(_a = realm.getValue(rootEditor$)) == null ? void 0 : _a.focus(callbackFn, opts);
|
|
113
|
+
},
|
|
114
|
+
getContentEditableHTML: () => {
|
|
115
|
+
var _a;
|
|
116
|
+
return ((_a = realm.getValue(contentEditableRef$)) == null ? void 0 : _a.current.innerHTML) ?? "";
|
|
117
|
+
},
|
|
118
|
+
getSelectionMarkdown: () => {
|
|
119
|
+
const viewMode = realm.getValue(viewMode$);
|
|
120
|
+
if (viewMode === "source" || viewMode === "diff") {
|
|
121
|
+
return "";
|
|
122
|
+
}
|
|
123
|
+
const activeEditor = realm.getValue(activeEditor$);
|
|
124
|
+
if (!activeEditor) {
|
|
125
|
+
return "";
|
|
126
|
+
}
|
|
127
|
+
const visitors = realm.getValue(exportVisitors$);
|
|
128
|
+
const toMarkdownExtensions = realm.getValue(toMarkdownExtensions$);
|
|
129
|
+
const toMarkdownOptions = realm.getValue(toMarkdownOptions$);
|
|
130
|
+
const jsxComponentDescriptors = realm.getValue(jsxComponentDescriptors$);
|
|
131
|
+
const jsxIsAvailable = realm.getValue(jsxIsAvailable$);
|
|
132
|
+
return getSelectionAsMarkdown(activeEditor, {
|
|
133
|
+
visitors,
|
|
134
|
+
toMarkdownExtensions,
|
|
135
|
+
toMarkdownOptions,
|
|
136
|
+
jsxComponentDescriptors,
|
|
137
|
+
jsxIsAvailable
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const Methods = ({ onReady, onDispose }) => {
|
|
143
|
+
const realm = useRealm();
|
|
144
|
+
const methods = React__default.useMemo(() => createMethods(realm), [realm]);
|
|
145
|
+
React__default.useLayoutEffect(() => {
|
|
146
|
+
onReady(methods);
|
|
147
|
+
return () => {
|
|
148
|
+
onDispose(methods);
|
|
149
|
+
};
|
|
150
|
+
}, [methods, onDispose, onReady]);
|
|
146
151
|
return null;
|
|
147
152
|
};
|
|
148
153
|
const MDXEditor = React__default.forwardRef((props, ref) => {
|
|
154
|
+
const realmMethods = React__default.useRef(null);
|
|
155
|
+
const replayingRealmMethods = React__default.useRef(null);
|
|
156
|
+
const pendingMethodCalls = React__default.useRef([]);
|
|
157
|
+
const preReadyMarkdown = React__default.useRef(props.trim === false ? props.markdown : props.markdown.trim());
|
|
158
|
+
const callWhenReady = React__default.useCallback((call) => {
|
|
159
|
+
const methods = realmMethods.current;
|
|
160
|
+
if (methods && replayingRealmMethods.current === null) {
|
|
161
|
+
call(methods);
|
|
162
|
+
} else {
|
|
163
|
+
pendingMethodCalls.current.push(call);
|
|
164
|
+
}
|
|
165
|
+
}, []);
|
|
166
|
+
const publicMethods = React__default.useMemo(
|
|
167
|
+
() => ({
|
|
168
|
+
getMarkdown: () => {
|
|
169
|
+
var _a;
|
|
170
|
+
return ((_a = realmMethods.current) == null ? void 0 : _a.getMarkdown()) ?? preReadyMarkdown.current;
|
|
171
|
+
},
|
|
172
|
+
setMarkdown: (markdown) => {
|
|
173
|
+
preReadyMarkdown.current = markdown;
|
|
174
|
+
callWhenReady((methods) => {
|
|
175
|
+
methods.setMarkdown(markdown);
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
insertMarkdown: (markdown) => {
|
|
179
|
+
callWhenReady((methods) => {
|
|
180
|
+
methods.insertMarkdown(markdown);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
focus: (callbackFn, opts) => {
|
|
184
|
+
callWhenReady((methods) => {
|
|
185
|
+
methods.focus(callbackFn, opts);
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
getContentEditableHTML: () => {
|
|
189
|
+
var _a;
|
|
190
|
+
return ((_a = realmMethods.current) == null ? void 0 : _a.getContentEditableHTML()) ?? "";
|
|
191
|
+
},
|
|
192
|
+
getSelectionMarkdown: () => {
|
|
193
|
+
var _a;
|
|
194
|
+
return ((_a = realmMethods.current) == null ? void 0 : _a.getSelectionMarkdown()) ?? "";
|
|
195
|
+
}
|
|
196
|
+
}),
|
|
197
|
+
[callWhenReady]
|
|
198
|
+
);
|
|
199
|
+
const attachRealmMethods = React__default.useCallback((methods) => {
|
|
200
|
+
realmMethods.current = methods;
|
|
201
|
+
if (replayingRealmMethods.current === methods) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (pendingMethodCalls.current.length === 0) {
|
|
205
|
+
preReadyMarkdown.current = methods.getMarkdown();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
replayingRealmMethods.current = methods;
|
|
209
|
+
const replayNext = () => {
|
|
210
|
+
if (realmMethods.current !== methods) {
|
|
211
|
+
if (replayingRealmMethods.current === methods) {
|
|
212
|
+
replayingRealmMethods.current = null;
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const call = pendingMethodCalls.current.shift();
|
|
217
|
+
if (!call) {
|
|
218
|
+
replayingRealmMethods.current = null;
|
|
219
|
+
preReadyMarkdown.current = methods.getMarkdown();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
call(methods);
|
|
223
|
+
queueMicrotask(replayNext);
|
|
224
|
+
};
|
|
225
|
+
replayNext();
|
|
226
|
+
}, []);
|
|
227
|
+
const detachRealmMethods = React__default.useCallback((methods) => {
|
|
228
|
+
if (realmMethods.current === methods) {
|
|
229
|
+
preReadyMarkdown.current = methods.getMarkdown();
|
|
230
|
+
realmMethods.current = null;
|
|
231
|
+
}
|
|
232
|
+
}, []);
|
|
233
|
+
React__default.useImperativeHandle(ref, () => publicMethods, [publicMethods]);
|
|
149
234
|
return /* @__PURE__ */ React__default.createElement(
|
|
150
235
|
RealmWithPlugins,
|
|
151
236
|
{
|
|
@@ -175,7 +260,7 @@ const MDXEditor = React__default.forwardRef((props, ref) => {
|
|
|
175
260
|
]
|
|
176
261
|
},
|
|
177
262
|
/* @__PURE__ */ React__default.createElement(EditorRootElement, { className: props.className, overlayContainer: props.overlayContainer }, /* @__PURE__ */ React__default.createElement(LexicalProvider, null, /* @__PURE__ */ React__default.createElement(RichTextEditor, null))),
|
|
178
|
-
/* @__PURE__ */ React__default.createElement(Methods, {
|
|
263
|
+
/* @__PURE__ */ React__default.createElement(Methods, { onReady: attachRealmMethods, onDispose: detachRealmMethods })
|
|
179
264
|
);
|
|
180
265
|
});
|
|
181
266
|
export {
|
package/dist/RealmWithPlugins.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
2
|
import { Realm, RealmContext } from "@mdxeditor/gurx";
|
|
3
|
-
import {
|
|
3
|
+
import { disposeRealmSession } from "./realmSession.js";
|
|
4
4
|
function realmPlugin(plugin) {
|
|
5
5
|
return function(params) {
|
|
6
6
|
return {
|
|
@@ -20,23 +20,41 @@ function realmPlugin(plugin) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function RealmWithPlugins({ children, plugins }) {
|
|
23
|
-
const theRealm = React__default.
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const [theRealm, setTheRealm] = React__default.useState(null);
|
|
24
|
+
React__default.useEffect(() => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const realm = new Realm();
|
|
27
|
+
try {
|
|
26
28
|
for (const plugin of plugins) {
|
|
27
|
-
(_a = plugin.init) == null ? void 0 : _a.call(plugin,
|
|
29
|
+
(_a = plugin.init) == null ? void 0 : _a.call(plugin, realm);
|
|
28
30
|
}
|
|
29
31
|
for (const plugin of plugins) {
|
|
30
|
-
(_b = plugin.postInit) == null ? void 0 : _b.call(plugin,
|
|
32
|
+
(_b = plugin.postInit) == null ? void 0 : _b.call(plugin, realm);
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
try {
|
|
36
|
+
disposeRealmSession(realm);
|
|
37
|
+
} catch (cleanupError) {
|
|
38
|
+
throw new AggregateError([error, cleanupError], "Realm plugin initialization and cleanup both failed");
|
|
31
39
|
}
|
|
32
|
-
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
setTheRealm(realm);
|
|
43
|
+
return () => {
|
|
44
|
+
disposeRealmSession(realm);
|
|
45
|
+
};
|
|
33
46
|
}, []);
|
|
34
47
|
React__default.useEffect(() => {
|
|
35
48
|
var _a;
|
|
36
|
-
|
|
37
|
-
(
|
|
49
|
+
if (theRealm) {
|
|
50
|
+
for (const plugin of plugins) {
|
|
51
|
+
(_a = plugin.update) == null ? void 0 : _a.call(plugin, theRealm);
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
54
|
});
|
|
55
|
+
if (!theRealm) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
40
58
|
return /* @__PURE__ */ React__default.createElement(RealmContext.Provider, { value: theRealm }, children);
|
|
41
59
|
}
|
|
42
60
|
export {
|
|
@@ -15,7 +15,7 @@ function exportLexicalTreeToMdast({
|
|
|
15
15
|
let unistRoot = null;
|
|
16
16
|
const referredComponents = /* @__PURE__ */ new Set();
|
|
17
17
|
const knownImportSources = /* @__PURE__ */ new Map();
|
|
18
|
-
visitors = visitors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
18
|
+
visitors = [...visitors].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
19
19
|
visit(root, null);
|
|
20
20
|
function registerReferredComponent(componentName, importStatement) {
|
|
21
21
|
referredComponents.add(componentName);
|
package/dist/index.d.ts
CHANGED
|
@@ -571,7 +571,7 @@ export declare class CodeBlockNode extends DecoratorNode<JSX.Element> {
|
|
|
571
571
|
static getType(): string;
|
|
572
572
|
static clone(node: CodeBlockNode): CodeBlockNode;
|
|
573
573
|
afterCloneFrom(prevNode: this): void;
|
|
574
|
-
static importJSON(serializedNode:
|
|
574
|
+
static importJSON(serializedNode: SerializedLexicalNode & Record<string, unknown>): CodeBlockNode;
|
|
575
575
|
static importDOM(): DOMConversionMap;
|
|
576
576
|
constructor(code: string, language: string, meta: string, key?: NodeKey);
|
|
577
577
|
exportJSON(): SerializedCodeBlockNode;
|
|
@@ -1394,11 +1394,10 @@ export declare function getSelectedNode(selection: RangeSelection): TextNode | E
|
|
|
1394
1394
|
/**
|
|
1395
1395
|
* Gets the markdown representation of the current selection in the Lexical editor.
|
|
1396
1396
|
* Returns an empty string if there is no selection or if the selection is collapsed.
|
|
1397
|
-
*
|
|
1398
|
-
* Note: Selects entire nodes, not partial selections within nodes.
|
|
1397
|
+
* Uses the same visitors and serialization options as the editor's full markdown export.
|
|
1399
1398
|
* @group Utils
|
|
1400
1399
|
*/
|
|
1401
|
-
export declare function getSelectionAsMarkdown(editor: LexicalEditor,
|
|
1400
|
+
export declare function getSelectionAsMarkdown(editor: LexicalEditor, exportParams: Omit<ExportMarkdownFromLexicalOptions, 'root'>): string;
|
|
1402
1401
|
|
|
1403
1402
|
/**
|
|
1404
1403
|
* Gets the coordinates of the selection in the Lexical editor.
|
|
@@ -2311,7 +2310,8 @@ export declare interface MDXEditorMethods {
|
|
|
2311
2310
|
*/
|
|
2312
2311
|
getContentEditableHTML: () => string;
|
|
2313
2312
|
/**
|
|
2314
|
-
* Gets the markdown representation of the
|
|
2313
|
+
* Gets the markdown representation of the active root or nested editor selection
|
|
2314
|
+
* using the editor's configured visitors and serialization options.
|
|
2315
2315
|
* Returns an empty string if there is no selection, if selection is collapsed, or if editor is in source/diff mode.
|
|
2316
2316
|
*/
|
|
2317
2317
|
getSelectionMarkdown: () => string;
|
|
@@ -2458,7 +2458,7 @@ export declare const muteChange$: NodeRef<boolean>;
|
|
|
2458
2458
|
export declare const NESTED_EDITOR_UPDATED_COMMAND: LexicalCommand<undefined>;
|
|
2459
2459
|
|
|
2460
2460
|
/**
|
|
2461
|
-
* React
|
|
2461
|
+
* React components registered inside each nested editor's standard Lexical composer context. Useful for Lexical plugins wrapped as React components.
|
|
2462
2462
|
* @group Core
|
|
2463
2463
|
*/
|
|
2464
2464
|
export declare const nestedEditorChildren$: NodeRef<default_2.ComponentType<{}>[]>;
|
|
@@ -2536,7 +2536,7 @@ export declare const NestedLexicalEditor: <T extends Mdast.RootContent>(props: {
|
|
|
2536
2536
|
* Whether or not the editor edits blocks (multiple paragraphs)
|
|
2537
2537
|
*/
|
|
2538
2538
|
block?: boolean;
|
|
2539
|
-
}) => JSX_2.Element;
|
|
2539
|
+
}) => JSX_2.Element | null;
|
|
2540
2540
|
|
|
2541
2541
|
/**
|
|
2542
2542
|
* The state of the image dialog when it is in new mode.
|
|
@@ -2620,6 +2620,8 @@ export declare interface PreviewLinkDialog {
|
|
|
2620
2620
|
type: 'preview';
|
|
2621
2621
|
title: string;
|
|
2622
2622
|
url: string;
|
|
2623
|
+
/** The fail-closed URL used only for automatic preview navigation. */
|
|
2624
|
+
href?: string;
|
|
2623
2625
|
linkNodeKey: string;
|
|
2624
2626
|
rectangle: RectData;
|
|
2625
2627
|
}
|
|
@@ -3110,7 +3112,7 @@ export declare function useEditorSearch(): {
|
|
|
3110
3112
|
cursor: number;
|
|
3111
3113
|
setSearch: (term: string | null) => void;
|
|
3112
3114
|
search: string;
|
|
3113
|
-
currentRange: Range;
|
|
3115
|
+
currentRange: Range | null;
|
|
3114
3116
|
isSearchOpen: boolean;
|
|
3115
3117
|
setIsSearchOpen: (value: boolean) => void;
|
|
3116
3118
|
openSearch: () => void;
|
|
@@ -3121,8 +3123,8 @@ export declare function useEditorSearch(): {
|
|
|
3121
3123
|
ignoreIfInView?: boolean;
|
|
3122
3124
|
behavior?: ScrollBehavior;
|
|
3123
3125
|
}) => void;
|
|
3124
|
-
replace: (
|
|
3125
|
-
replaceAll: (
|
|
3126
|
+
replace: (replacement: string, onUpdate?: () => void) => void;
|
|
3127
|
+
replaceAll: (replacement: string, onUpdate?: () => void) => void;
|
|
3126
3128
|
};
|
|
3127
3129
|
|
|
3128
3130
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* empty css */
|
|
2
2
|
export * from "@mdxeditor/gurx";
|
|
3
3
|
import { MDXEditor } from "./MDXEditor.js";
|
|
4
4
|
import { defaultSvgIcons } from "./defaultSvgIcons.js";
|
|
@@ -62,13 +62,13 @@ import { RealmWithPlugins, realmPlugin } from "./RealmWithPlugins.js";
|
|
|
62
62
|
import { DEFAULT_FORMAT, IS_BOLD, IS_CODE, IS_HIGHLIGHT, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE } from "./FormatConstants.js";
|
|
63
63
|
import { lexicalTheme } from "./styles/lexicalTheme.js";
|
|
64
64
|
import * as lexical from "lexical";
|
|
65
|
-
import { htmlTags, isMdastHTMLNode } from "./plugins/core/MdastHTMLNode.js";
|
|
66
|
-
import { $createGenericHTMLNode, $isGenericHTMLNode, GenericHTMLNode, TYPE_NAME } from "./plugins/core/GenericHTMLNode.js";
|
|
67
|
-
import { $convertTableElement, $createTableNode, $isTableNode, TableNode } from "./plugins/table/TableNode.js";
|
|
68
|
-
import { $createImageNode, $isImageNode, ImageNode } from "./plugins/image/ImageNode.js";
|
|
69
|
-
import { $createFrontmatterNode, $isFrontmatterNode, FrontmatterNode } from "./plugins/frontmatter/FrontmatterNode.js";
|
|
70
65
|
import { $convertPreElement, $createCodeBlockNode, $isCodeBlockNode, CodeBlockNode, useCodeBlockEditorContext } from "./plugins/codeblock/CodeBlockNode.js";
|
|
66
|
+
import { $convertTableElement, $createTableNode, $isTableNode, TableNode } from "./plugins/table/TableNode.js";
|
|
71
67
|
import { $createDirectiveNode, $isDirectiveNode, DirectiveNode } from "./plugins/directives/DirectiveNode.js";
|
|
68
|
+
import { $createFrontmatterNode, $isFrontmatterNode, FrontmatterNode } from "./plugins/frontmatter/FrontmatterNode.js";
|
|
69
|
+
import { $createGenericHTMLNode, $isGenericHTMLNode, GenericHTMLNode, TYPE_NAME } from "./plugins/core/GenericHTMLNode.js";
|
|
70
|
+
import { $createImageNode, $isImageNode, ImageNode } from "./plugins/image/ImageNode.js";
|
|
71
|
+
import { htmlTags, isMdastHTMLNode } from "./plugins/core/MdastHTMLNode.js";
|
|
72
72
|
export {
|
|
73
73
|
$convertPreElement,
|
|
74
74
|
$convertTableElement,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { factorySpace } from "micromark-factory-space";
|
|
2
2
|
import { markdownLineEnding } from "micromark-util-character";
|
|
3
|
-
|
|
3
|
+
const codes = { dash: 45, eof: null, exclamationMark: 33, greaterThan: 62 };
|
|
4
|
+
const types = { data: "data", lineEnding: "lineEnding", linePrefix: "linePrefix" };
|
|
4
5
|
function commentFromMarkdown(_options) {
|
|
5
6
|
return {
|
|
6
7
|
canContainEols: ["comment"],
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
import { useCellValue } from "@mdxeditor/gurx";
|
|
8
5
|
import { DecoratorNode } from "lexical";
|
|
9
6
|
import React__default from "react";
|
|
@@ -54,7 +51,9 @@ class CodeBlockNode extends DecoratorNode {
|
|
|
54
51
|
this.__focusEmitter = voidEmitter();
|
|
55
52
|
}
|
|
56
53
|
static importJSON(serializedNode) {
|
|
57
|
-
const
|
|
54
|
+
const code = typeof serializedNode.code === "string" ? serializedNode.code : "";
|
|
55
|
+
const language = typeof serializedNode.language === "string" ? serializedNode.language : "";
|
|
56
|
+
const meta = typeof serializedNode.meta === "string" ? serializedNode.meta : "";
|
|
58
57
|
return $createCodeBlockNode({
|
|
59
58
|
code,
|
|
60
59
|
language,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CodeBlockVisitor } from "./CodeBlockVisitor.js";
|
|
2
2
|
import { MdastCodeVisitor } from "./MdastCodeVisitor.js";
|
|
3
|
-
import { Appender, defaultCodeBlockLanguage$, insertDecoratorNode$,
|
|
3
|
+
import { Appender, codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, insertDecoratorNode$, addExportVisitor$, addLexicalNode$, addImportVisitor$, addActivePlugin$ } from "../core/index.js";
|
|
4
4
|
import { $createCodeBlockNode, CodeBlockNode } from "./CodeBlockNode.js";
|
|
5
5
|
import { $convertPreElement, $isCodeBlockNode, useCodeBlockEditorContext } from "./CodeBlockNode.js";
|
|
6
6
|
import { Signal, withLatestFrom, map } from "@mdxeditor/gurx";
|
|
@@ -5,7 +5,7 @@ import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
|
|
|
5
5
|
import { useTranslation, readOnly$, iconComponentFor$ } from "../core/index.js";
|
|
6
6
|
import { languages } from "@codemirror/language-data";
|
|
7
7
|
import { EditorState } from "@codemirror/state";
|
|
8
|
-
import { lineNumbers, keymap
|
|
8
|
+
import { EditorView, lineNumbers, keymap } from "@codemirror/view";
|
|
9
9
|
import { indentWithTab } from "@codemirror/commands";
|
|
10
10
|
import { basicLight } from "cm6-theme-basic-light";
|
|
11
11
|
import { basicSetup } from "codemirror";
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
import { ElementNode, $applyNodeReplacement } from "lexical";
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { $applyNodeReplacement, ElementNode } from "lexical";
|
|
8
5
|
const TYPE_NAME = "generic-html";
|
|
9
6
|
class GenericHTMLNode extends ElementNode {
|
|
10
7
|
/**
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FOCUS_COMMAND, COMMAND_PRIORITY_LOW, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_CRITICAL, $getNodeByKey, $addUpdateTag, $getRoot } from "lexical";
|
|
2
2
|
import React__default from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { rootEditor$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, jsxIsAvailable$, nestedEditorChildren$, lexicalTheme$, editorInFocus$, historyState$, NESTED_EDITOR_UPDATED_COMMAND } from "./index.js";
|
|
4
4
|
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
5
5
|
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { LexicalExtensionEditorComposer } from "@lexical/react/LexicalExtensionEditorComposer";
|
|
7
7
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
8
8
|
import classNames from "classnames";
|
|
9
9
|
import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
|
|
10
10
|
import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
|
|
11
11
|
import styles from "../../styles/ui.module.css.js";
|
|
12
|
-
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
13
12
|
import { mergeRegister } from "@lexical/utils";
|
|
14
13
|
import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
|
|
15
14
|
import { useRealm, useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
15
|
+
import { createExtensionEditor, editorHasSharedHistory } from "./lexicalExtensions.js";
|
|
16
16
|
const NestedEditorsContext = React__default.createContext(void 0);
|
|
17
17
|
function useNestedEditorContext() {
|
|
18
18
|
const context = React__default.useContext(NestedEditorsContext);
|
|
@@ -49,7 +49,7 @@ function useLexicalNodeRemove() {
|
|
|
49
49
|
}
|
|
50
50
|
const NestedLexicalEditor = function(props) {
|
|
51
51
|
const { getContent, getUpdatedMdastNode, contentEditableProps, block = false } = props;
|
|
52
|
-
const { mdastNode, lexicalNode, focusEmitter } = useNestedEditorContext();
|
|
52
|
+
const { parentEditor, mdastNode, lexicalNode, focusEmitter } = useNestedEditorContext();
|
|
53
53
|
const updateMdastNode = useMdastNodeUpdater();
|
|
54
54
|
const removeNode = useLexicalNodeRemove();
|
|
55
55
|
const content = getContent(mdastNode);
|
|
@@ -80,45 +80,62 @@ const NestedLexicalEditor = function(props) {
|
|
|
80
80
|
lexicalTheme$
|
|
81
81
|
);
|
|
82
82
|
const setEditorInFocus = usePublisher(editorInFocus$);
|
|
83
|
-
const [editor] = React__default.useState(
|
|
84
|
-
|
|
83
|
+
const [editor, setEditor] = React__default.useState(null);
|
|
84
|
+
React__default.useEffect(() => {
|
|
85
|
+
if (!rootEditor) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const editor2 = createExtensionEditor({
|
|
89
|
+
name: "@mdxeditor/nested",
|
|
85
90
|
nodes: usedLexicalNodes,
|
|
86
|
-
theme:
|
|
87
|
-
namespace: "NestedEditor"
|
|
91
|
+
theme: lexicalTheme,
|
|
92
|
+
namespace: "NestedEditor",
|
|
93
|
+
parentEditor,
|
|
94
|
+
historyMode: editorHasSharedHistory(rootEditor) ? "nested-shared" : "nested-external",
|
|
95
|
+
historyState: realm.getValue(historyState$),
|
|
96
|
+
initialEditorState: () => {
|
|
97
|
+
let theContent = content;
|
|
98
|
+
if (block) {
|
|
99
|
+
if (theContent.length === 0) {
|
|
100
|
+
theContent = [{ type: "paragraph", children: [] }];
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
theContent = [{ type: "paragraph", children: content }];
|
|
104
|
+
}
|
|
105
|
+
importMdastTreeToLexical({
|
|
106
|
+
root: $getRoot(),
|
|
107
|
+
mdastRoot: {
|
|
108
|
+
type: "root",
|
|
109
|
+
children: theContent
|
|
110
|
+
},
|
|
111
|
+
visitors: importVisitors,
|
|
112
|
+
directiveDescriptors,
|
|
113
|
+
codeBlockEditorDescriptors,
|
|
114
|
+
defaultCodeBlockLanguage,
|
|
115
|
+
jsxComponentDescriptors
|
|
116
|
+
});
|
|
117
|
+
}
|
|
88
118
|
});
|
|
89
|
-
|
|
90
|
-
|
|
119
|
+
setEditor(editor2);
|
|
120
|
+
return () => {
|
|
121
|
+
editor2.dispose();
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
91
124
|
React__default.useEffect(() => {
|
|
125
|
+
if (!editor) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
92
128
|
focusEmitter.subscribe(() => {
|
|
93
129
|
editor.focus();
|
|
94
130
|
});
|
|
131
|
+
return () => {
|
|
132
|
+
focusEmitter.subscribe(() => void 0);
|
|
133
|
+
};
|
|
95
134
|
}, [editor, focusEmitter]);
|
|
96
135
|
React__default.useEffect(() => {
|
|
97
|
-
editor
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (block) {
|
|
101
|
-
if (theContent.length === 0) {
|
|
102
|
-
theContent = [{ type: "paragraph", children: [] }];
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
theContent = [{ type: "paragraph", children: content }];
|
|
106
|
-
}
|
|
107
|
-
importMdastTreeToLexical({
|
|
108
|
-
root: $getRoot(),
|
|
109
|
-
mdastRoot: {
|
|
110
|
-
type: "root",
|
|
111
|
-
children: theContent
|
|
112
|
-
},
|
|
113
|
-
visitors: importVisitors,
|
|
114
|
-
directiveDescriptors,
|
|
115
|
-
codeBlockEditorDescriptors,
|
|
116
|
-
defaultCodeBlockLanguage,
|
|
117
|
-
jsxComponentDescriptors
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}, [editor, block, importVisitors]);
|
|
121
|
-
React__default.useEffect(() => {
|
|
136
|
+
if (!editor) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
122
139
|
function updateParentNode() {
|
|
123
140
|
editor.getEditorState().read(() => {
|
|
124
141
|
const mdast = exportLexicalTreeToMdast({
|
|
@@ -198,14 +215,17 @@ const NestedLexicalEditor = function(props) {
|
|
|
198
215
|
updateMdastNode,
|
|
199
216
|
rootEditor
|
|
200
217
|
]);
|
|
201
|
-
|
|
218
|
+
if (!editor) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
return /* @__PURE__ */ React__default.createElement(LexicalExtensionEditorComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(
|
|
202
222
|
RichTextPlugin,
|
|
203
223
|
{
|
|
204
224
|
contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { ...contentEditableProps, className: classNames(styles.nestedEditor, contentEditableProps == null ? void 0 : contentEditableProps.className) }),
|
|
205
225
|
placeholder: null,
|
|
206
226
|
ErrorBoundary: LexicalErrorBoundary
|
|
207
227
|
}
|
|
208
|
-
),
|
|
228
|
+
), nestedEditorChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })));
|
|
209
229
|
};
|
|
210
230
|
export {
|
|
211
231
|
NestedEditorsContext,
|