@mdxeditor/editor 3.47.0 → 3.49.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/index.d.ts
CHANGED
|
@@ -1122,7 +1122,7 @@ export declare interface EditingImageDialogState {
|
|
|
1122
1122
|
export declare interface EditLinkDialog {
|
|
1123
1123
|
type: 'edit';
|
|
1124
1124
|
initialUrl: string;
|
|
1125
|
-
|
|
1125
|
+
hasInitialText: boolean;
|
|
1126
1126
|
url: string;
|
|
1127
1127
|
title: string;
|
|
1128
1128
|
linkNodeKey: string;
|
|
@@ -1966,6 +1966,10 @@ export declare const linkDialogPlugin: (params?: {
|
|
|
1966
1966
|
* Invoked when a link is clicked in read-only mode
|
|
1967
1967
|
*/
|
|
1968
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;
|
|
1969
1973
|
} | undefined) => RealmPlugin;
|
|
1970
1974
|
|
|
1971
1975
|
/**
|
|
@@ -2028,7 +2032,14 @@ export declare class MarkdownParseError extends Error {
|
|
|
2028
2032
|
|
|
2029
2033
|
/* Excluded from this release type: MarkdownParseOptions */
|
|
2030
2034
|
|
|
2031
|
-
|
|
2035
|
+
/**
|
|
2036
|
+
* Emits a processing error when such happens
|
|
2037
|
+
* @group Core
|
|
2038
|
+
*/
|
|
2039
|
+
export declare const markdownProcessingError$: NodeRef<{
|
|
2040
|
+
error: string;
|
|
2041
|
+
source: string;
|
|
2042
|
+
} | null>;
|
|
2032
2043
|
|
|
2033
2044
|
/**
|
|
2034
2045
|
* A plugin that adds markdown shortcuts to the editor.
|
|
@@ -2832,6 +2843,8 @@ export declare type SerializedTableNode = Spread<{
|
|
|
2832
2843
|
*/
|
|
2833
2844
|
export declare const setMarkdown$: NodeRef<string>;
|
|
2834
2845
|
|
|
2846
|
+
/* Excluded from this release type: showLinkTitleField$ */
|
|
2847
|
+
|
|
2835
2848
|
/**
|
|
2836
2849
|
* A component that displays the focused live code block's name.
|
|
2837
2850
|
* For this component to work, you must enable the `sandpackPlugin` for the editor.
|
|
@@ -3044,6 +3057,7 @@ export declare class UnrecognizedMarkdownConstructError extends Error {
|
|
|
3044
3057
|
* @group Link Dialog
|
|
3045
3058
|
*/
|
|
3046
3059
|
export declare const updateLink$: NodeRef<{
|
|
3060
|
+
text: string | undefined;
|
|
3047
3061
|
url: string | undefined;
|
|
3048
3062
|
title: string | undefined;
|
|
3049
3063
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -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";
|
|
@@ -327,6 +327,7 @@ export {
|
|
|
327
327
|
searchOpen$,
|
|
328
328
|
searchPlugin,
|
|
329
329
|
setMarkdown$,
|
|
330
|
+
showLinkTitleField$,
|
|
330
331
|
spellCheck$,
|
|
331
332
|
switchFromPreviewToLinkEdit$,
|
|
332
333
|
syntaxExtensions$,
|
|
@@ -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
|
};
|