@mdxeditor/editor 3.46.1 → 3.48.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/MDXEditor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usePublisher, useCellValue, useCellValues, useRealm } from "@mdxeditor/gurx";
|
|
2
2
|
import React__default from "react";
|
|
3
|
-
import { corePlugin, editorRootElementRef$, rootEditor$, useTranslation, contentEditableRef$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, bottomAreaChildren$, insertMarkdown$, setMarkdown$, viewMode$, markdownSourceEditorValue$, markdown$ } from "./plugins/core/index.js";
|
|
3
|
+
import { corePlugin, editorRootElementRef$, rootEditor$, useTranslation, contentEditableRef$, contentEditableWrapperElement$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, bottomAreaChildren$, insertMarkdown$, setMarkdown$, viewMode$, markdownSourceEditorValue$, markdown$ } from "./plugins/core/index.js";
|
|
4
4
|
import { RealmWithPlugins } from "./RealmWithPlugins.js";
|
|
5
5
|
import { createLexicalComposerContext, LexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
6
6
|
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
@@ -21,8 +21,10 @@ const LexicalProvider = ({ children }) => {
|
|
|
21
21
|
const RichTextEditor = () => {
|
|
22
22
|
const t = useTranslation();
|
|
23
23
|
const setContentEditableRef = usePublisher(contentEditableRef$);
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const setEditorRootWrapperElement = usePublisher(contentEditableWrapperElement$);
|
|
25
|
+
const onRef = (el) => {
|
|
26
|
+
setEditorRootWrapperElement(el);
|
|
27
|
+
setContentEditableRef({ current: el });
|
|
26
28
|
};
|
|
27
29
|
const [contentEditableClassName, spellCheck, composerChildren, topAreaChildren, editorWrappers, placeholder, bottomAreaChildren] = useCellValues(
|
|
28
30
|
contentEditableClassName$,
|
package/dist/index.d.ts
CHANGED
|
@@ -689,6 +689,8 @@ export declare const contentEditableClassName$: NodeRef<string>;
|
|
|
689
689
|
*/
|
|
690
690
|
export declare const contentEditableRef$: NodeRef<default_2.RefObject<HTMLDivElement> | null>;
|
|
691
691
|
|
|
692
|
+
export declare const contentEditableWrapperElement$: NodeRef<HTMLDivElement | null>;
|
|
693
|
+
|
|
692
694
|
/**
|
|
693
695
|
* Returns true if the user is pressing the control key on Windows or the meta key on Mac.
|
|
694
696
|
* @group Utils
|
|
@@ -1120,7 +1122,7 @@ export declare interface EditingImageDialogState {
|
|
|
1120
1122
|
export declare interface EditLinkDialog {
|
|
1121
1123
|
type: 'edit';
|
|
1122
1124
|
initialUrl: string;
|
|
1123
|
-
|
|
1125
|
+
hasInitialText: boolean;
|
|
1124
1126
|
url: string;
|
|
1125
1127
|
title: string;
|
|
1126
1128
|
linkNodeKey: string;
|
|
@@ -1964,6 +1966,10 @@ export declare const linkDialogPlugin: (params?: {
|
|
|
1964
1966
|
* Invoked when a link is clicked in read-only mode
|
|
1965
1967
|
*/
|
|
1966
1968
|
onReadOnlyClickLinkCallback?: ReadOnlyClickLinkCallback | undefined;
|
|
1969
|
+
/**
|
|
1970
|
+
* If true, show the "Link title" field in link dialogs (this sets mouseover text, NOT anchor text)
|
|
1971
|
+
*/
|
|
1972
|
+
showLinkTitleField?: boolean | undefined;
|
|
1967
1973
|
} | undefined) => RealmPlugin;
|
|
1968
1974
|
|
|
1969
1975
|
/**
|
|
@@ -2830,6 +2836,8 @@ export declare type SerializedTableNode = Spread<{
|
|
|
2830
2836
|
*/
|
|
2831
2837
|
export declare const setMarkdown$: NodeRef<string>;
|
|
2832
2838
|
|
|
2839
|
+
/* Excluded from this release type: showLinkTitleField$ */
|
|
2840
|
+
|
|
2833
2841
|
/**
|
|
2834
2842
|
* A component that displays the focused live code block's name.
|
|
2835
2843
|
* For this component to work, you must enable the `sandpackPlugin` for the editor.
|
|
@@ -3042,6 +3050,7 @@ export declare class UnrecognizedMarkdownConstructError extends Error {
|
|
|
3042
3050
|
* @group Link Dialog
|
|
3043
3051
|
*/
|
|
3044
3052
|
export declare const updateLink$: NodeRef<{
|
|
3053
|
+
text: string | undefined;
|
|
3045
3054
|
url: string | undefined;
|
|
3046
3055
|
title: string | undefined;
|
|
3047
3056
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { MDXEditor } from "./MDXEditor.js";
|
|
|
4
4
|
import { defaultSvgIcons } from "./defaultSvgIcons.js";
|
|
5
5
|
import { MarkdownParseError, UnrecognizedMarkdownConstructError, importMarkdownToLexical, importMdastTreeToLexical } from "./importMarkdownToLexical.js";
|
|
6
6
|
import { exportLexicalTreeToMdast, exportMarkdownFromLexical } from "./exportMarkdownFromLexical.js";
|
|
7
|
-
import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addBottomAreaChild$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, bottomAreaChildren$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, contentEditableRef$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialMarkdownNormalize$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
|
|
7
|
+
import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addBottomAreaChild$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, bottomAreaChildren$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, contentEditableRef$, contentEditableWrapperElement$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialMarkdownNormalize$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
|
|
8
8
|
import { ALL_HEADING_LEVELS, allowedHeadingLevels$, headingsPlugin } from "./plugins/headings/index.js";
|
|
9
9
|
import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-break/index.js";
|
|
10
10
|
import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
|
|
@@ -24,7 +24,7 @@ import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLang
|
|
|
24
24
|
import { directivesPlugin, insertDirective$ } from "./plugins/directives/index.js";
|
|
25
25
|
import { ADMONITION_TYPES, AdmonitionDirectiveDescriptor } from "./directive-editors/AdmonitionDirectiveDescriptor.js";
|
|
26
26
|
import { GenericDirectiveEditor } from "./directive-editors/GenericDirectiveEditor.js";
|
|
27
|
-
import { applyLinkChanges$, cancelLinkEdit$, linkAutocompleteSuggestions$, linkDialogPlugin, linkDialogState$, onClickLinkCallback$, onReadOnlyClickLinkCallback$, onWindowChange$, openLinkEditDialog$, removeLink$, switchFromPreviewToLinkEdit$, updateLink$ } from "./plugins/link-dialog/index.js";
|
|
27
|
+
import { applyLinkChanges$, cancelLinkEdit$, linkAutocompleteSuggestions$, linkDialogPlugin, linkDialogState$, onClickLinkCallback$, onReadOnlyClickLinkCallback$, onWindowChange$, openLinkEditDialog$, removeLink$, showLinkTitleField$, switchFromPreviewToLinkEdit$, updateLink$ } from "./plugins/link-dialog/index.js";
|
|
28
28
|
import { toolbarClassName$, toolbarContents$, toolbarPlugin } from "./plugins/toolbar/index.js";
|
|
29
29
|
import { cmExtensions$, diffMarkdown$, diffSourcePlugin, readOnlyDiff$ } from "./plugins/diff-source/index.js";
|
|
30
30
|
import { markdownShortcutPlugin } from "./plugins/markdown-shortcut/index.js";
|
|
@@ -206,6 +206,7 @@ export {
|
|
|
206
206
|
composerChildren$,
|
|
207
207
|
contentEditableClassName$,
|
|
208
208
|
contentEditableRef$,
|
|
209
|
+
contentEditableWrapperElement$,
|
|
209
210
|
controlOrMeta,
|
|
210
211
|
convertSelectionToNode$,
|
|
211
212
|
corePlugin,
|
|
@@ -326,6 +327,7 @@ export {
|
|
|
326
327
|
searchOpen$,
|
|
327
328
|
searchPlugin,
|
|
328
329
|
setMarkdown$,
|
|
330
|
+
showLinkTitleField$,
|
|
329
331
|
spellCheck$,
|
|
330
332
|
switchFromPreviewToLinkEdit$,
|
|
331
333
|
syntaxExtensions$,
|
|
@@ -190,6 +190,7 @@ function rebind() {
|
|
|
190
190
|
return activeEditorValue ? subs.map((s) => s(activeEditorValue)) : [];
|
|
191
191
|
}, []);
|
|
192
192
|
}
|
|
193
|
+
const contentEditableWrapperElement$ = Cell(null);
|
|
193
194
|
const activeEditorSubscriptions$ = Cell([], (r) => {
|
|
194
195
|
r.pipe(r.combine(activeEditorSubscriptions$, activeEditor$), rebind());
|
|
195
196
|
});
|
|
@@ -624,6 +625,7 @@ export {
|
|
|
624
625
|
composerChildren$,
|
|
625
626
|
contentEditableClassName$,
|
|
626
627
|
contentEditableRef$,
|
|
628
|
+
contentEditableWrapperElement$,
|
|
627
629
|
convertSelectionToNode$,
|
|
628
630
|
corePlugin,
|
|
629
631
|
createActiveEditorSubscription$,
|
|
@@ -7,10 +7,18 @@ import styles from "../../styles/ui.module.css.js";
|
|
|
7
7
|
import classNames from "classnames";
|
|
8
8
|
import { createCommand } from "lexical";
|
|
9
9
|
import { useForm } from "react-hook-form";
|
|
10
|
-
import { linkDialogState$, linkAutocompleteSuggestions$, onClickLinkCallback$, onWindowChange$, updateLink$, cancelLinkEdit$, switchFromPreviewToLinkEdit$, removeLink$ } from "./index.js";
|
|
10
|
+
import { linkDialogState$, linkAutocompleteSuggestions$, onClickLinkCallback$, showLinkTitleField$, onWindowChange$, updateLink$, cancelLinkEdit$, switchFromPreviewToLinkEdit$, removeLink$ } from "./index.js";
|
|
11
11
|
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
12
12
|
createCommand();
|
|
13
|
-
function LinkEditForm({
|
|
13
|
+
function LinkEditForm({
|
|
14
|
+
url,
|
|
15
|
+
title,
|
|
16
|
+
onSubmit,
|
|
17
|
+
onCancel,
|
|
18
|
+
linkAutocompleteSuggestions,
|
|
19
|
+
showLinkTitleField,
|
|
20
|
+
showAnchorTextField
|
|
21
|
+
}) {
|
|
14
22
|
const {
|
|
15
23
|
register,
|
|
16
24
|
handleSubmit,
|
|
@@ -20,7 +28,9 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
|
|
|
20
28
|
} = useForm({
|
|
21
29
|
values: {
|
|
22
30
|
url,
|
|
23
|
-
title
|
|
31
|
+
title,
|
|
32
|
+
text: ""
|
|
33
|
+
// text is only for freshly created links with no content, it always starts empty
|
|
24
34
|
}
|
|
25
35
|
});
|
|
26
36
|
const t = useTranslation();
|
|
@@ -51,7 +61,8 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
|
|
|
51
61
|
autofocus: true
|
|
52
62
|
}
|
|
53
63
|
)),
|
|
54
|
-
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "link-title" }, t("createLink.
|
|
64
|
+
showAnchorTextField ? /* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "link-text", title: t("createLink.textTooltip", "The text to be displayed for the link") }, t("createLink.text", "Anchor text")), /* @__PURE__ */ React__default.createElement("input", { id: "link-text", className: styles.textInput, size: 40, ...register("text") })) : null,
|
|
65
|
+
showLinkTitleField ? /* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "link-title", title: t("createLink.titleTooltip", "The link's title attribute, shown on hover") }, t("createLink.title", "Link title")), /* @__PURE__ */ React__default.createElement("input", { id: "link-title", className: styles.textInput, size: 40, ...register("title") })) : null,
|
|
55
66
|
/* @__PURE__ */ React__default.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "var(--spacing-2)" } }, /* @__PURE__ */ React__default.createElement(
|
|
56
67
|
"button",
|
|
57
68
|
{
|
|
@@ -74,13 +85,22 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
|
|
|
74
85
|
);
|
|
75
86
|
}
|
|
76
87
|
const LinkDialog = () => {
|
|
77
|
-
const [
|
|
88
|
+
const [
|
|
89
|
+
editorRootElementRef,
|
|
90
|
+
activeEditor,
|
|
91
|
+
iconComponentFor,
|
|
92
|
+
linkDialogState,
|
|
93
|
+
linkAutocompleteSuggestions,
|
|
94
|
+
onClickLinkCallback,
|
|
95
|
+
showLinkTitleField
|
|
96
|
+
] = useCellValues(
|
|
78
97
|
editorRootElementRef$,
|
|
79
98
|
activeEditor$,
|
|
80
99
|
iconComponentFor$,
|
|
81
100
|
linkDialogState$,
|
|
82
101
|
linkAutocompleteSuggestions$,
|
|
83
|
-
onClickLinkCallback
|
|
102
|
+
onClickLinkCallback$,
|
|
103
|
+
showLinkTitleField$
|
|
84
104
|
);
|
|
85
105
|
const publishWindowChange = usePublisher(onWindowChange$);
|
|
86
106
|
const updateLink = usePublisher(updateLink$);
|
|
@@ -135,7 +155,9 @@ const LinkDialog = () => {
|
|
|
135
155
|
title: linkDialogState.title,
|
|
136
156
|
onSubmit: updateLink,
|
|
137
157
|
onCancel: cancelLinkEdit.bind(null),
|
|
138
|
-
linkAutocompleteSuggestions
|
|
158
|
+
linkAutocompleteSuggestions,
|
|
159
|
+
showLinkTitleField,
|
|
160
|
+
showAnchorTextField: !linkDialogState.hasInitialText
|
|
139
161
|
}
|
|
140
162
|
),
|
|
141
163
|
linkDialogState.type === "preview" && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
|
|
@@ -73,6 +73,7 @@ const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
|
|
|
73
73
|
return {
|
|
74
74
|
type: "edit",
|
|
75
75
|
initialUrl: state.url,
|
|
76
|
+
hasInitialText: true,
|
|
76
77
|
url: state.url,
|
|
77
78
|
title: state.title,
|
|
78
79
|
linkNodeKey: state.linkNodeKey,
|
|
@@ -86,12 +87,13 @@ const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
|
|
|
86
87
|
linkDialogState$
|
|
87
88
|
);
|
|
88
89
|
r.sub(r.pipe(updateLink$, withLatestFrom(activeEditor$, linkDialogState$, currentSelection$)), ([payload, editor, state, selection]) => {
|
|
89
|
-
var _a, _b;
|
|
90
|
-
const
|
|
91
|
-
const
|
|
90
|
+
var _a, _b, _c;
|
|
91
|
+
const text = ((_a = payload.text) == null ? void 0 : _a.trim()) ?? "";
|
|
92
|
+
const url = ((_b = payload.url) == null ? void 0 : _b.trim()) ?? "";
|
|
93
|
+
const title = ((_c = payload.title) == null ? void 0 : _c.trim()) ?? "";
|
|
92
94
|
if (url !== "") {
|
|
93
95
|
if (selection == null ? void 0 : selection.isCollapsed()) {
|
|
94
|
-
const linkContent = title || url;
|
|
96
|
+
const linkContent = text || title || url;
|
|
95
97
|
editor == null ? void 0 : editor.update(
|
|
96
98
|
() => {
|
|
97
99
|
const linkNode = getLinkNodeInSelection(selection);
|
|
@@ -208,7 +210,7 @@ const openLinkEditDialog$ = Action((r) => {
|
|
|
208
210
|
r.pub(linkDialogState$, {
|
|
209
211
|
type: "edit",
|
|
210
212
|
initialUrl: node.getURL(),
|
|
211
|
-
|
|
213
|
+
hasInitialText: true,
|
|
212
214
|
url: node.getURL(),
|
|
213
215
|
title: node.getTitle() ?? "",
|
|
214
216
|
linkNodeKey: node.getKey(),
|
|
@@ -218,7 +220,7 @@ const openLinkEditDialog$ = Action((r) => {
|
|
|
218
220
|
r.pub(linkDialogState$, {
|
|
219
221
|
type: "edit",
|
|
220
222
|
initialUrl: "",
|
|
221
|
-
|
|
223
|
+
hasInitialText: !(selection == null ? void 0 : selection.isCollapsed()),
|
|
222
224
|
title: "",
|
|
223
225
|
url: "",
|
|
224
226
|
linkNodeKey: "",
|
|
@@ -260,11 +262,13 @@ const onReadOnlyClickLinkCallback$ = Cell(null, (r) => {
|
|
|
260
262
|
});
|
|
261
263
|
});
|
|
262
264
|
});
|
|
265
|
+
const showLinkTitleField$ = Cell(true);
|
|
263
266
|
const linkDialogPlugin = realmPlugin({
|
|
264
267
|
init(r, params) {
|
|
265
268
|
r.pub(addComposerChild$, (params == null ? void 0 : params.LinkDialog) ?? LinkDialog);
|
|
266
269
|
r.pub(onClickLinkCallback$, (params == null ? void 0 : params.onClickLinkCallback) ?? null);
|
|
267
270
|
r.pub(onReadOnlyClickLinkCallback$, (params == null ? void 0 : params.onReadOnlyClickLinkCallback) ?? null);
|
|
271
|
+
r.pub(showLinkTitleField$, (params == null ? void 0 : params.showLinkTitleField) ?? true);
|
|
268
272
|
},
|
|
269
273
|
update(r, params = {}) {
|
|
270
274
|
r.pub(linkAutocompleteSuggestions$, params.linkAutocompleteSuggestions ?? []);
|
|
@@ -281,6 +285,7 @@ export {
|
|
|
281
285
|
onWindowChange$,
|
|
282
286
|
openLinkEditDialog$,
|
|
283
287
|
removeLink$,
|
|
288
|
+
showLinkTitleField$,
|
|
284
289
|
switchFromPreviewToLinkEdit$,
|
|
285
290
|
updateLink$
|
|
286
291
|
};
|