@mdxeditor/editor 1.8.1 → 1.9.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/plugins/core/ui/DownshiftAutoComplete.d.ts +7 -3
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +18 -2
- package/dist/plugins/image/ImageDialog.js +1 -0
- package/dist/plugins/link-dialog/LinkDialog.js +1 -0
- package/dist/plugins/link-dialog/index.js +41 -25
- package/dist/style.css +234 -228
- package/dist/styles/lexical-theme.module.css.js +19 -19
- package/dist/styles/ui.module.css.js +100 -100
- package/dist/utils/lexicalHelpers.js +16 -7
- package/package.json +1 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Control, UseFormSetValue } from 'react-hook-form';
|
|
3
|
-
|
|
2
|
+
import { Control, UseFormSetValue, UseFormRegister } from 'react-hook-form';
|
|
3
|
+
interface DownshiftAutoCompleteProps {
|
|
4
4
|
suggestions: string[];
|
|
5
5
|
control: Control<any, any>;
|
|
6
6
|
setValue: UseFormSetValue<any>;
|
|
7
|
+
register: UseFormRegister<any>;
|
|
7
8
|
placeholder: string;
|
|
8
9
|
inputName: string;
|
|
9
10
|
autofocus?: boolean;
|
|
10
11
|
initialInputValue: string;
|
|
11
|
-
}
|
|
12
|
+
}
|
|
13
|
+
export declare const DownshiftAutoComplete: React.FC<DownshiftAutoCompleteProps>;
|
|
14
|
+
export declare const DownshiftAutoCompleteWithSuggestions: React.FC<DownshiftAutoCompleteProps>;
|
|
15
|
+
export {};
|
|
@@ -4,7 +4,22 @@ import { Controller } from "react-hook-form";
|
|
|
4
4
|
import styles from "../../../styles/ui.module.css.js";
|
|
5
5
|
import DropDownIcon from "../../../icons/arrow_drop_down.svg.js";
|
|
6
6
|
const MAX_SUGGESTIONS = 20;
|
|
7
|
-
const DownshiftAutoComplete = (
|
|
7
|
+
const DownshiftAutoComplete = (props) => {
|
|
8
|
+
if (props.suggestions.length > 0) {
|
|
9
|
+
return /* @__PURE__ */ React__default.createElement(DownshiftAutoCompleteWithSuggestions, { ...props });
|
|
10
|
+
} else {
|
|
11
|
+
return /* @__PURE__ */ React__default.createElement("input", { className: styles.textInput, size: 40, autoFocus: true, ...props.register(props.inputName) });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const DownshiftAutoCompleteWithSuggestions = ({
|
|
15
|
+
autofocus,
|
|
16
|
+
suggestions,
|
|
17
|
+
control,
|
|
18
|
+
inputName,
|
|
19
|
+
placeholder,
|
|
20
|
+
initialInputValue,
|
|
21
|
+
setValue
|
|
22
|
+
}) => {
|
|
8
23
|
const [items, setItems] = React__default.useState(suggestions.slice(0, MAX_SUGGESTIONS));
|
|
9
24
|
const enableAutoComplete = suggestions.length > 0;
|
|
10
25
|
const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
|
|
@@ -62,5 +77,6 @@ const DownshiftAutoComplete = ({ autofocus, suggestions, control, inputName, pla
|
|
|
62
77
|
)))));
|
|
63
78
|
};
|
|
64
79
|
export {
|
|
65
|
-
DownshiftAutoComplete
|
|
80
|
+
DownshiftAutoComplete,
|
|
81
|
+
DownshiftAutoCompleteWithSuggestions
|
|
66
82
|
};
|
|
@@ -49,6 +49,7 @@ const ImageDialog = () => {
|
|
|
49
49
|
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "src" }, "Or add an image from an URL:"), /* @__PURE__ */ React__default.createElement(
|
|
50
50
|
DownshiftAutoComplete,
|
|
51
51
|
{
|
|
52
|
+
register,
|
|
52
53
|
initialInputValue: state.type === "editing" ? state.initialValues.src || "" : "",
|
|
53
54
|
inputName: "src",
|
|
54
55
|
suggestions: imageAutocompleteSuggestions,
|
|
@@ -44,6 +44,7 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
|
|
|
44
44
|
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "link-url" }, "URL"), /* @__PURE__ */ React__default.createElement(
|
|
45
45
|
DownshiftAutoComplete,
|
|
46
46
|
{
|
|
47
|
+
register,
|
|
47
48
|
initialInputValue: url,
|
|
48
49
|
inputName: "url",
|
|
49
50
|
suggestions: linkAutocompleteSuggestions,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TOGGLE_LINK_COMMAND, $isLinkNode } from "@lexical/link";
|
|
2
|
-
import { $isRangeSelection, KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, COMMAND_PRIORITY_HIGH } from "lexical";
|
|
2
|
+
import { $isRangeSelection, KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, COMMAND_PRIORITY_HIGH, $createTextNode, $insertNodes } from "lexical";
|
|
3
3
|
import { IS_APPLE } from "../../utils/detectMac.js";
|
|
4
4
|
import { getSelectionRectangle, getSelectedNode } from "../../utils/lexicalHelpers.js";
|
|
5
5
|
import { coreSystem } from "../core/index.js";
|
|
@@ -93,7 +93,7 @@ const linkDialogSystem = system(
|
|
|
93
93
|
(event) => {
|
|
94
94
|
if (event.key === "k" && (IS_APPLE ? event.metaKey : event.ctrlKey)) {
|
|
95
95
|
const selection = $getSelection();
|
|
96
|
-
if ($isRangeSelection(selection)
|
|
96
|
+
if ($isRangeSelection(selection)) {
|
|
97
97
|
r.pub(openLinkEditDialog, true);
|
|
98
98
|
event.stopPropagation();
|
|
99
99
|
event.preventDefault();
|
|
@@ -127,32 +127,48 @@ const linkDialogSystem = system(
|
|
|
127
127
|
),
|
|
128
128
|
linkDialogState
|
|
129
129
|
);
|
|
130
|
-
r.sub(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
130
|
+
r.sub(
|
|
131
|
+
r.pipe(updateLink, r.o.withLatestFrom(activeEditor, linkDialogState, currentSelection)),
|
|
132
|
+
([payload, editor, state, selection]) => {
|
|
133
|
+
const url = payload.url.trim();
|
|
134
|
+
const title = payload.title.trim();
|
|
135
|
+
if (url.trim() !== "") {
|
|
136
|
+
if (selection == null ? void 0 : selection.isCollapsed()) {
|
|
137
|
+
const linkContent = title || url;
|
|
138
|
+
editor == null ? void 0 : editor.update(
|
|
139
|
+
() => {
|
|
140
|
+
if (!getLinkNodeInSelection(selection)) {
|
|
141
|
+
const node = $createTextNode(linkContent);
|
|
142
|
+
$insertNodes([node]);
|
|
143
|
+
node.select();
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{ discrete: true }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title });
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
editor == null ? void 0 : editor.update(() => {
|
|
152
|
+
const node = getLinkNodeInSelection($getSelection());
|
|
153
|
+
node == null ? void 0 : node.setTitle(title);
|
|
154
|
+
});
|
|
155
|
+
}, 100);
|
|
156
|
+
r.pub(linkDialogState, {
|
|
157
|
+
type: "preview",
|
|
158
|
+
linkNodeKey: state.linkNodeKey,
|
|
159
|
+
rectangle: state.rectangle,
|
|
160
|
+
url
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
if (state.type === "edit" && state.initialUrl !== "") {
|
|
164
|
+
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
165
|
+
}
|
|
166
|
+
r.pub(linkDialogState, {
|
|
167
|
+
type: "inactive"
|
|
139
168
|
});
|
|
140
|
-
});
|
|
141
|
-
r.pub(linkDialogState, {
|
|
142
|
-
type: "preview",
|
|
143
|
-
linkNodeKey: state.linkNodeKey,
|
|
144
|
-
rectangle: state.rectangle,
|
|
145
|
-
url
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
if (state.type === "edit" && state.initialUrl !== "") {
|
|
149
|
-
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
150
169
|
}
|
|
151
|
-
r.pub(linkDialogState, {
|
|
152
|
-
type: "inactive"
|
|
153
|
-
});
|
|
154
170
|
}
|
|
155
|
-
|
|
171
|
+
);
|
|
156
172
|
r.link(
|
|
157
173
|
r.pipe(
|
|
158
174
|
cancelLinkEdit,
|