@mdxeditor/editor 3.50.0 → 3.51.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,9 +1122,10 @@ export declare interface EditingImageDialogState {
|
|
|
1122
1122
|
export declare interface EditLinkDialog {
|
|
1123
1123
|
type: 'edit';
|
|
1124
1124
|
initialUrl: string;
|
|
1125
|
-
hasInitialText: boolean;
|
|
1126
1125
|
url: string;
|
|
1127
1126
|
title: string;
|
|
1127
|
+
text: string;
|
|
1128
|
+
withAnchorText: boolean;
|
|
1128
1129
|
linkNodeKey: string;
|
|
1129
1130
|
rectangle: RectData;
|
|
1130
1131
|
}
|
|
@@ -2866,7 +2867,7 @@ export declare type SerializedTableNode = Spread<{
|
|
|
2866
2867
|
*/
|
|
2867
2868
|
export declare const setMarkdown$: NodeRef<string>;
|
|
2868
2869
|
|
|
2869
|
-
|
|
2870
|
+
export declare const showLinkTitleField$: NodeRef<boolean>;
|
|
2870
2871
|
|
|
2871
2872
|
/**
|
|
2872
2873
|
* A component that displays the focused live code block's name.
|
|
@@ -13,6 +13,7 @@ createCommand();
|
|
|
13
13
|
function LinkEditForm({
|
|
14
14
|
url,
|
|
15
15
|
title,
|
|
16
|
+
text,
|
|
16
17
|
onSubmit,
|
|
17
18
|
onCancel,
|
|
18
19
|
linkAutocompleteSuggestions,
|
|
@@ -29,8 +30,7 @@ function LinkEditForm({
|
|
|
29
30
|
values: {
|
|
30
31
|
url,
|
|
31
32
|
title,
|
|
32
|
-
text
|
|
33
|
-
// text is only for freshly created links with no content, it always starts empty
|
|
33
|
+
text
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
const t = useTranslation();
|
|
@@ -46,6 +46,12 @@ function LinkEditForm({
|
|
|
46
46
|
e.stopPropagation();
|
|
47
47
|
onCancel();
|
|
48
48
|
},
|
|
49
|
+
onKeyDown: (e) => {
|
|
50
|
+
if (e.key === "Escape") {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
onCancel();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
49
55
|
className: classNames(styles.multiFieldForm, styles.linkDialogEditForm)
|
|
50
56
|
},
|
|
51
57
|
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "link-url" }, t("createLink.url", "URL")), /* @__PURE__ */ React__default.createElement(
|
|
@@ -153,11 +159,12 @@ const LinkDialog = () => {
|
|
|
153
159
|
{
|
|
154
160
|
url: linkDialogState.url,
|
|
155
161
|
title: linkDialogState.title,
|
|
162
|
+
text: linkDialogState.text,
|
|
156
163
|
onSubmit: updateLink,
|
|
157
164
|
onCancel: cancelLinkEdit.bind(null),
|
|
158
165
|
linkAutocompleteSuggestions,
|
|
159
166
|
showLinkTitleField,
|
|
160
|
-
showAnchorTextField:
|
|
167
|
+
showAnchorTextField: linkDialogState.withAnchorText
|
|
161
168
|
}
|
|
162
169
|
),
|
|
163
170
|
linkDialogState.type === "preview" && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $createLinkNode, TOGGLE_LINK_COMMAND,
|
|
1
|
+
import { $isLinkNode, $createLinkNode, TOGGLE_LINK_COMMAND, LinkNode } from "@lexical/link";
|
|
2
2
|
import { Signal, Cell, Action, withLatestFrom, map, filter } from "@mdxeditor/gurx";
|
|
3
|
-
import { KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_HIGH, $createTextNode, $insertNodes, $getNearestNodeFromDOMNode } from "lexical";
|
|
3
|
+
import { KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_HIGH, $getNodeByKey, $createTextNode, $insertNodes, $isTextNode, $getNearestNodeFromDOMNode } from "lexical";
|
|
4
4
|
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
5
5
|
import { IS_APPLE } from "../../utils/detectMac.js";
|
|
6
6
|
import { getSelectionRectangle, getSelectedNode } from "../../utils/lexicalHelpers.js";
|
|
@@ -64,28 +64,29 @@ const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
|
|
|
64
64
|
COMMAND_PRIORITY_HIGH
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
|
-
r.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
r.sub(r.pipe(switchFromPreviewToLinkEdit$, withLatestFrom(linkDialogState$, activeEditor$)), ([, state, editor]) => {
|
|
68
|
+
if (state.type === "preview") {
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
editor == null ? void 0 : editor.getEditorState().read(() => {
|
|
71
|
+
const node = $getNodeByKey(state.linkNodeKey);
|
|
72
|
+
const withAnchorText = $isLinkNode(node) ? node.getTextContent().length > 0 && node.getChildrenSize() <= 1 : false;
|
|
73
|
+
const text = withAnchorText && node ? node.getTextContent() : "";
|
|
74
|
+
r.pub(linkDialogState$, {
|
|
74
75
|
type: "edit",
|
|
75
76
|
initialUrl: state.url,
|
|
76
|
-
hasInitialText: true,
|
|
77
77
|
url: state.url,
|
|
78
78
|
title: state.title,
|
|
79
|
+
text,
|
|
80
|
+
withAnchorText,
|
|
79
81
|
linkNodeKey: state.linkNodeKey,
|
|
80
82
|
rectangle: state.rectangle
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error("Cannot switch to edit mode when not in preview mode");
|
|
88
|
+
}
|
|
89
|
+
});
|
|
89
90
|
r.sub(r.pipe(updateLink$, withLatestFrom(activeEditor$, linkDialogState$, currentSelection$)), ([payload, editor, state, selection]) => {
|
|
90
91
|
var _a, _b, _c;
|
|
91
92
|
const text = ((_a = payload.text) == null ? void 0 : _a.trim()) ?? "";
|
|
@@ -105,11 +106,15 @@ const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
|
|
|
105
106
|
} else {
|
|
106
107
|
linkNode.setURL(url);
|
|
107
108
|
linkNode.setTitle(title);
|
|
109
|
+
updateLinkText(linkNode.getFirstChild(), text);
|
|
108
110
|
}
|
|
109
111
|
},
|
|
110
112
|
{ discrete: true }
|
|
111
113
|
);
|
|
112
114
|
} else {
|
|
115
|
+
editor == null ? void 0 : editor.update(() => {
|
|
116
|
+
updateLinkText(selection == null ? void 0 : selection.anchor.getNode(), text);
|
|
117
|
+
});
|
|
113
118
|
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title });
|
|
114
119
|
}
|
|
115
120
|
r.pub(linkDialogState$, {
|
|
@@ -204,29 +209,24 @@ const openLinkEditDialog$ = Action((r) => {
|
|
|
204
209
|
editor == null ? void 0 : editor.focus(() => {
|
|
205
210
|
setTimeout(() => {
|
|
206
211
|
editor.getEditorState().read(() => {
|
|
207
|
-
const
|
|
212
|
+
const linkNode = getLinkNodeInSelection(selection);
|
|
208
213
|
const rectangle = getSelectionRectangle(editor);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
url: "",
|
|
226
|
-
linkNodeKey: "",
|
|
227
|
-
rectangle
|
|
228
|
-
});
|
|
229
|
-
}
|
|
214
|
+
const initialUrl = (linkNode == null ? void 0 : linkNode.getURL()) ?? "";
|
|
215
|
+
const url = (linkNode == null ? void 0 : linkNode.getURL()) ?? "";
|
|
216
|
+
const title = (linkNode == null ? void 0 : linkNode.getTitle()) ?? "";
|
|
217
|
+
const linkNodeKey = (linkNode == null ? void 0 : linkNode.getKey()) ?? "";
|
|
218
|
+
const withAnchorText = linkNode ? linkNode.getTextContent().length > 0 && linkNode.getChildrenSize() <= 1 : Boolean(selection == null ? void 0 : selection.isCollapsed());
|
|
219
|
+
const text = withAnchorText && linkNode ? linkNode.getTextContent() : "";
|
|
220
|
+
r.pub(linkDialogState$, {
|
|
221
|
+
type: "edit",
|
|
222
|
+
initialUrl,
|
|
223
|
+
url,
|
|
224
|
+
title,
|
|
225
|
+
text,
|
|
226
|
+
withAnchorText,
|
|
227
|
+
linkNodeKey,
|
|
228
|
+
rectangle
|
|
229
|
+
});
|
|
230
230
|
});
|
|
231
231
|
});
|
|
232
232
|
});
|
|
@@ -262,6 +262,12 @@ const onReadOnlyClickLinkCallback$ = Cell(null, (r) => {
|
|
|
262
262
|
});
|
|
263
263
|
});
|
|
264
264
|
});
|
|
265
|
+
function updateLinkText(node, text) {
|
|
266
|
+
if ($isTextNode(node) && text) {
|
|
267
|
+
node.setTextContent(text);
|
|
268
|
+
node.selectStart();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
265
271
|
const showLinkTitleField$ = Cell(true);
|
|
266
272
|
const linkDialogPlugin = realmPlugin({
|
|
267
273
|
init(r, params) {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "3.
|
|
14
|
+
"version": "3.51.0",
|
|
15
15
|
"description": "React component for rich text markdown editing",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "vite build",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"prettier": "^3.1.1",
|
|
147
147
|
"react": "^19.1.0",
|
|
148
148
|
"react-dom": "^19.1.0",
|
|
149
|
-
"semantic-release": "^
|
|
149
|
+
"semantic-release": "^25.0.2",
|
|
150
150
|
"svgo": "^3.3.2",
|
|
151
151
|
"terser": "^5.26.0",
|
|
152
152
|
"typedoc": "^0.25.13",
|
|
@@ -162,7 +162,8 @@
|
|
|
162
162
|
"vitest": "^1.1.1"
|
|
163
163
|
},
|
|
164
164
|
"publishConfig": {
|
|
165
|
-
"access": "public"
|
|
165
|
+
"access": "public",
|
|
166
|
+
"provenance": true
|
|
166
167
|
},
|
|
167
168
|
"engines": {
|
|
168
169
|
"node": ">=16"
|