@mdxeditor/editor 3.29.2 → 3.30.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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
1
3
|
import { Config } from 'mdast-util-from-markdown/lib';
|
|
2
4
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
3
5
|
import { DecoratorNode } from 'lexical';
|
|
@@ -1068,6 +1070,20 @@ export declare const disableImageResize$: NodeRef<boolean>;
|
|
|
1068
1070
|
|
|
1069
1071
|
export declare const disableImageSettingsButton$: NodeRef<boolean>;
|
|
1070
1072
|
|
|
1073
|
+
/**
|
|
1074
|
+
* Holds the custom EditImageToolbar component.
|
|
1075
|
+
* @group Image
|
|
1076
|
+
*/
|
|
1077
|
+
export declare const editImageToolbarComponent$: NodeRef<FC<EditImageToolbarProps>>;
|
|
1078
|
+
|
|
1079
|
+
declare interface EditImageToolbarProps {
|
|
1080
|
+
nodeKey: string;
|
|
1081
|
+
imageSource: string;
|
|
1082
|
+
initialImagePath: string | null;
|
|
1083
|
+
title: string;
|
|
1084
|
+
alt: string;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1071
1087
|
/**
|
|
1072
1088
|
* The state of the image dialog when it is in editing an existing node.
|
|
1073
1089
|
* @group Image
|
|
@@ -1324,7 +1340,7 @@ export declare const imageAutocompleteSuggestions$: NodeRef<string[]>;
|
|
|
1324
1340
|
* Holds the current state of the image dialog.
|
|
1325
1341
|
* @group Image
|
|
1326
1342
|
*/
|
|
1327
|
-
export declare const imageDialogState$: NodeRef<
|
|
1343
|
+
export declare const imageDialogState$: NodeRef<EditingImageDialogState | InactiveImageDialogState | NewImageDialogState>;
|
|
1328
1344
|
|
|
1329
1345
|
/**
|
|
1330
1346
|
* A lexical node that represents an image. Use {@link "$createImageNode"} to construct one.
|
|
@@ -1378,6 +1394,7 @@ export declare const imagePlugin: (params?: {
|
|
|
1378
1394
|
disableImageSettingsButton?: boolean | undefined;
|
|
1379
1395
|
imagePreviewHandler?: ImagePreviewHandler | undefined;
|
|
1380
1396
|
ImageDialog?: FC<{}> | (() => JSX.Element) | undefined;
|
|
1397
|
+
EditImageToolbar?: FC<{}> | (() => JSX.Element) | undefined;
|
|
1381
1398
|
} | undefined) => RealmPlugin;
|
|
1382
1399
|
|
|
1383
1400
|
/**
|
|
@@ -2522,6 +2539,12 @@ export declare interface SandpackConfig {
|
|
|
2522
2539
|
presets: SandpackPreset[];
|
|
2523
2540
|
}
|
|
2524
2541
|
|
|
2542
|
+
export declare const SandpackEditor: ({ nodeKey, code, focusEmitter, preset }: SandpackEditorProps) => default_2.JSX.Element;
|
|
2543
|
+
|
|
2544
|
+
export declare interface SandpackEditorProps extends CodeBlockEditorProps {
|
|
2545
|
+
preset: SandpackPreset;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2525
2548
|
/**
|
|
2526
2549
|
* A plugin that adds support for sandpack code blocks in the editor.
|
|
2527
2550
|
* @group Sandpack
|
package/dist/index.js
CHANGED
|
@@ -10,13 +10,14 @@ import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-br
|
|
|
10
10
|
import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
|
|
11
11
|
import { insertTable$, tablePlugin } from "./plugins/table/index.js";
|
|
12
12
|
import { disableAutoLink$, linkPlugin } from "./plugins/link/index.js";
|
|
13
|
-
import { INSERT_IMAGE_COMMAND, closeImageDialog$, disableImageResize$, disableImageSettingsButton$, imageAutocompleteSuggestions$, imageDialogState$, imagePlugin, imagePreviewHandler$, imageUploadHandler$, insertImage$, openEditImageDialog$, openNewImageDialog$, saveImage$ } from "./plugins/image/index.js";
|
|
13
|
+
import { INSERT_IMAGE_COMMAND, closeImageDialog$, disableImageResize$, disableImageSettingsButton$, editImageToolbarComponent$, imageAutocompleteSuggestions$, imageDialogState$, imagePlugin, imagePreviewHandler$, imageUploadHandler$, insertImage$, openEditImageDialog$, openNewImageDialog$, saveImage$ } from "./plugins/image/index.js";
|
|
14
14
|
import { frontmatterDialogOpen$, frontmatterPlugin, hasFrontmatter$, insertFrontmatter$, removeFrontmatter$ } from "./plugins/frontmatter/index.js";
|
|
15
15
|
import { quotePlugin } from "./plugins/quote/index.js";
|
|
16
16
|
import { maxLengthPlugin } from "./plugins/maxlength/index.js";
|
|
17
17
|
import { insertJsx$, isMdastJsxNode, jsxPlugin } from "./plugins/jsx/index.js";
|
|
18
18
|
import { GenericJsxEditor } from "./jsx-editors/GenericJsxEditor.js";
|
|
19
19
|
import { insertSandpack$, sandpackConfig$, sandpackPlugin } from "./plugins/sandpack/index.js";
|
|
20
|
+
import { SandpackEditor } from "./plugins/sandpack/SandpackEditor.js";
|
|
20
21
|
import { codeBlockLanguages$, codeMirrorAutoLoadLanguageSupport$, codeMirrorExtensions$, codeMirrorPlugin, insertCodeMirror$ } from "./plugins/codemirror/index.js";
|
|
21
22
|
import { COMMON_STATE_CONFIG_EXTENSIONS, CodeMirrorEditor } from "./plugins/codemirror/CodeMirrorEditor.js";
|
|
22
23
|
import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$ } from "./plugins/codeblock/index.js";
|
|
@@ -138,6 +139,7 @@ export {
|
|
|
138
139
|
PropertyPopover,
|
|
139
140
|
RealmWithPlugins,
|
|
140
141
|
Root,
|
|
142
|
+
SandpackEditor,
|
|
141
143
|
Select,
|
|
142
144
|
SelectButtonTrigger,
|
|
143
145
|
SelectContent,
|
|
@@ -214,6 +216,7 @@ export {
|
|
|
214
216
|
disableAutoLink$,
|
|
215
217
|
disableImageResize$,
|
|
216
218
|
disableImageSettingsButton$,
|
|
219
|
+
editImageToolbarComponent$,
|
|
217
220
|
editorInFocus$,
|
|
218
221
|
editorRootElementRef$,
|
|
219
222
|
editorWrappers$,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import { $getNodeByKey } from "lexical";
|
|
5
|
+
import React__default from "react";
|
|
6
|
+
import { disableImageSettingsButton$, openEditImageDialog$ } from "./index.js";
|
|
7
|
+
import styles from "../../styles/ui.module.css.js";
|
|
8
|
+
import { iconComponentFor$, readOnly$, useTranslation } from "../core/index.js";
|
|
9
|
+
function EditImageToolbar({ nodeKey, imageSource, initialImagePath, title, alt }) {
|
|
10
|
+
const [disableImageSettingsButton, iconComponentFor, readOnly] = useCellValues(disableImageSettingsButton$, iconComponentFor$, readOnly$);
|
|
11
|
+
const [editor] = useLexicalComposerContext();
|
|
12
|
+
const openEditImageDialog = usePublisher(openEditImageDialog$);
|
|
13
|
+
const t = useTranslation();
|
|
14
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.editImageToolbar }, /* @__PURE__ */ React__default.createElement(
|
|
15
|
+
"button",
|
|
16
|
+
{
|
|
17
|
+
className: styles.iconButton,
|
|
18
|
+
type: "button",
|
|
19
|
+
title: t("imageEditor.deleteImage", "Delete image"),
|
|
20
|
+
disabled: readOnly,
|
|
21
|
+
onClick: (e) => {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
editor.update(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = $getNodeByKey(nodeKey)) == null ? void 0 : _a.remove();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
iconComponentFor("delete_small")
|
|
30
|
+
), !disableImageSettingsButton && /* @__PURE__ */ React__default.createElement(
|
|
31
|
+
"button",
|
|
32
|
+
{
|
|
33
|
+
type: "button",
|
|
34
|
+
className: classNames(styles.iconButton, styles.editImageButton),
|
|
35
|
+
title: t("imageEditor.editImage", "Edit image"),
|
|
36
|
+
disabled: readOnly,
|
|
37
|
+
onClick: () => {
|
|
38
|
+
openEditImageDialog({
|
|
39
|
+
nodeKey,
|
|
40
|
+
initialValues: {
|
|
41
|
+
src: !initialImagePath ? imageSource : initialImagePath,
|
|
42
|
+
title,
|
|
43
|
+
altText: alt
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
iconComponentFor("settings")
|
|
49
|
+
));
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
EditImageToolbar
|
|
53
|
+
};
|
|
@@ -2,14 +2,14 @@ import React__default from "react";
|
|
|
2
2
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
3
|
import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection";
|
|
4
4
|
import { mergeRegister } from "@lexical/utils";
|
|
5
|
+
import { useCellValues } from "@mdxeditor/gurx";
|
|
5
6
|
import classNames from "classnames";
|
|
6
7
|
import { $isNodeSelection, $getSelection, $getNodeByKey, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, DRAGSTART_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND } from "lexical";
|
|
7
|
-
import { disableImageResize$,
|
|
8
|
+
import { disableImageResize$, imagePreviewHandler$, editImageToolbarComponent$ } from "./index.js";
|
|
8
9
|
import styles from "../../styles/ui.module.css.js";
|
|
9
|
-
import {
|
|
10
|
+
import { readOnly$ } from "../core/index.js";
|
|
10
11
|
import { $isImageNode } from "./ImageNode.js";
|
|
11
12
|
import ImageResizer from "./ImageResizer.js";
|
|
12
|
-
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
13
13
|
const imageCache = /* @__PURE__ */ new Set();
|
|
14
14
|
function useSuspenseImage(src) {
|
|
15
15
|
if (!imageCache.has(src)) {
|
|
@@ -48,14 +48,12 @@ function LazyImage({
|
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
|
|
51
|
-
const [disableImageResize,
|
|
51
|
+
const [disableImageResize, imagePreviewHandler, readOnly, EditImageToolbar] = useCellValues(
|
|
52
52
|
disableImageResize$,
|
|
53
|
-
disableImageSettingsButton$,
|
|
54
53
|
imagePreviewHandler$,
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
readOnly$,
|
|
55
|
+
editImageToolbarComponent$
|
|
57
56
|
);
|
|
58
|
-
const openEditImageDialog = usePublisher(openEditImageDialog$);
|
|
59
57
|
const imageRef = React__default.useRef(null);
|
|
60
58
|
const buttonRef = React__default.useRef(null);
|
|
61
59
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
@@ -65,7 +63,6 @@ function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
|
|
|
65
63
|
const [isResizing, setIsResizing] = React__default.useState(false);
|
|
66
64
|
const [imageSource, setImageSource] = React__default.useState(null);
|
|
67
65
|
const [initialImagePath, setInitialImagePath] = React__default.useState(null);
|
|
68
|
-
const t = useTranslation();
|
|
69
66
|
const onDelete = React__default.useCallback(
|
|
70
67
|
(payload) => {
|
|
71
68
|
if (isSelected && $isNodeSelection($getSelection())) {
|
|
@@ -226,42 +223,16 @@ function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
|
|
|
226
223
|
alt: alt ?? "",
|
|
227
224
|
imageRef
|
|
228
225
|
}
|
|
229
|
-
)), draggable && isFocused && !disableImageResize && /* @__PURE__ */ React__default.createElement(ImageResizer, { editor, imageRef, onResizeStart, onResizeEnd }), readOnly || /* @__PURE__ */ React__default.createElement(
|
|
230
|
-
|
|
226
|
+
)), draggable && isFocused && !disableImageResize && /* @__PURE__ */ React__default.createElement(ImageResizer, { editor, imageRef, onResizeStart, onResizeEnd }), readOnly || /* @__PURE__ */ React__default.createElement(
|
|
227
|
+
EditImageToolbar,
|
|
231
228
|
{
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
var _a;
|
|
240
|
-
(_a = $getNodeByKey(nodeKey)) == null ? void 0 : _a.remove();
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
iconComponentFor("delete_small")
|
|
245
|
-
), !disableImageSettingsButton && /* @__PURE__ */ React__default.createElement(
|
|
246
|
-
"button",
|
|
247
|
-
{
|
|
248
|
-
type: "button",
|
|
249
|
-
className: classNames(styles.iconButton, styles.editImageButton),
|
|
250
|
-
title: t("imageEditor.editImage", "Edit image"),
|
|
251
|
-
disabled: readOnly,
|
|
252
|
-
onClick: () => {
|
|
253
|
-
openEditImageDialog({
|
|
254
|
-
nodeKey,
|
|
255
|
-
initialValues: {
|
|
256
|
-
src: !initialImagePath ? imageSource : initialImagePath,
|
|
257
|
-
title: title ?? "",
|
|
258
|
-
altText: alt ?? ""
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
iconComponentFor("settings")
|
|
264
|
-
)))) : null;
|
|
229
|
+
nodeKey,
|
|
230
|
+
imageSource,
|
|
231
|
+
initialImagePath,
|
|
232
|
+
title: title ?? "",
|
|
233
|
+
alt: alt ?? ""
|
|
234
|
+
}
|
|
235
|
+
))) : null;
|
|
265
236
|
}
|
|
266
237
|
export {
|
|
267
238
|
ImageEditor
|
|
@@ -4,6 +4,7 @@ import { $insertNodes, $isRootOrShadowRoot, $createParagraphNode, $getNodeByKey,
|
|
|
4
4
|
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
5
5
|
import { CAN_USE_DOM } from "../../utils/detectMac.js";
|
|
6
6
|
import { activeEditor$, createActiveEditorSubscription$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
|
|
7
|
+
import { EditImageToolbar } from "./EditImageToolbar.js";
|
|
7
8
|
import { ImageDialog } from "./ImageDialog.js";
|
|
8
9
|
import { $createImageNode, ImageNode, $isImageNode } from "./ImageNode.js";
|
|
9
10
|
import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
|
|
@@ -156,6 +157,7 @@ const closeImageDialog$ = Action((r) => {
|
|
|
156
157
|
});
|
|
157
158
|
const disableImageSettingsButton$ = Cell(false);
|
|
158
159
|
const saveImage$ = Signal();
|
|
160
|
+
const editImageToolbarComponent$ = Cell(EditImageToolbar);
|
|
159
161
|
const imagePlugin = realmPlugin({
|
|
160
162
|
init(realm, params) {
|
|
161
163
|
realm.pubIn({
|
|
@@ -167,7 +169,8 @@ const imagePlugin = realmPlugin({
|
|
|
167
169
|
[imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) ?? [],
|
|
168
170
|
[disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
|
|
169
171
|
[disableImageSettingsButton$]: Boolean(params == null ? void 0 : params.disableImageSettingsButton),
|
|
170
|
-
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null
|
|
172
|
+
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null,
|
|
173
|
+
[editImageToolbarComponent$]: (params == null ? void 0 : params.EditImageToolbar) ?? EditImageToolbar
|
|
171
174
|
});
|
|
172
175
|
},
|
|
173
176
|
update(realm, params) {
|
|
@@ -175,7 +178,8 @@ const imagePlugin = realmPlugin({
|
|
|
175
178
|
[imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) ?? null,
|
|
176
179
|
[imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) ?? [],
|
|
177
180
|
[disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
|
|
178
|
-
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null
|
|
181
|
+
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null,
|
|
182
|
+
[editImageToolbarComponent$]: (params == null ? void 0 : params.EditImageToolbar) ?? EditImageToolbar
|
|
179
183
|
});
|
|
180
184
|
}
|
|
181
185
|
});
|
|
@@ -317,6 +321,7 @@ export {
|
|
|
317
321
|
closeImageDialog$,
|
|
318
322
|
disableImageResize$,
|
|
319
323
|
disableImageSettingsButton$,
|
|
324
|
+
editImageToolbarComponent$,
|
|
320
325
|
imageAutocompleteSuggestions$,
|
|
321
326
|
imageDialogState$,
|
|
322
327
|
imagePlugin,
|