@mdxeditor/editor 0.21.1 → 0.22.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/MdastBreakVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastBreakVisitor.js +10 -0
- package/dist/plugins/core/index.js +2 -0
- package/dist/plugins/image/ImageEditor.d.ts +1 -1
- package/dist/plugins/image/ImageEditor.js +16 -3
- package/dist/plugins/image/LexicalImageVisitor.js +1 -2
- package/dist/plugins/image/index.d.ts +12 -2
- package/dist/plugins/image/index.js +4 -1
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ import { MdastTextVisitor } from "./MdastTextVisitor.js";
|
|
|
17
17
|
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
18
18
|
import { noop } from "../../utils/fp.js";
|
|
19
19
|
import { controlOrMeta } from "../../utils/detectMac.js";
|
|
20
|
+
import { MdastBreakVisitor } from "./MdastBreakVisitor.js";
|
|
20
21
|
import { system } from "../../gurx/realmFactory.js";
|
|
21
22
|
import { realmPlugin } from "../../gurx/react.js";
|
|
22
23
|
const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
|
|
@@ -384,6 +385,7 @@ const [
|
|
|
384
385
|
realm.pubKey("addImportVisitor", MdastTextVisitor);
|
|
385
386
|
realm.pubKey("addImportVisitor", MdastFormattingVisitor);
|
|
386
387
|
realm.pubKey("addImportVisitor", MdastInlineCodeVisitor);
|
|
388
|
+
realm.pubKey("addImportVisitor", MdastBreakVisitor);
|
|
387
389
|
realm.pubKey("addLexicalNode", ParagraphNode);
|
|
388
390
|
realm.pubKey("addLexicalNode", TextNode);
|
|
389
391
|
realm.pubKey("addExportVisitor", LexicalRootVisitor);
|
|
@@ -6,4 +6,4 @@ export interface ImageEditorProps {
|
|
|
6
6
|
width: number | 'inherit';
|
|
7
7
|
height: number | 'inherit';
|
|
8
8
|
}
|
|
9
|
-
export declare function ImageEditor({ src, title, nodeKey, width, height }: ImageEditorProps): JSX.Element;
|
|
9
|
+
export declare function ImageEditor({ src, title, nodeKey, width, height }: ImageEditorProps): JSX.Element | null;
|
|
@@ -41,6 +41,8 @@ function ImageEditor({ src, title, nodeKey, width, height }) {
|
|
|
41
41
|
const activeEditorRef = React__default.useRef(null);
|
|
42
42
|
const [isResizing, setIsResizing] = React__default.useState(false);
|
|
43
43
|
const [disableImageResize] = imagePluginHooks.useEmitterValues("disableImageResize");
|
|
44
|
+
const [imagePreviewHandler] = imagePluginHooks.useEmitterValues("imagePreviewHandler");
|
|
45
|
+
const [imageSource, setImageSource] = React__default.useState(null);
|
|
44
46
|
const onDelete = React__default.useCallback(
|
|
45
47
|
(payload) => {
|
|
46
48
|
if (isSelected && $isNodeSelection($getSelection())) {
|
|
@@ -87,6 +89,17 @@ function ImageEditor({ src, title, nodeKey, width, height }) {
|
|
|
87
89
|
},
|
|
88
90
|
[editor, setSelected]
|
|
89
91
|
);
|
|
92
|
+
React__default.useEffect(() => {
|
|
93
|
+
if (imagePreviewHandler) {
|
|
94
|
+
const callPreviewHandler = async () => {
|
|
95
|
+
const updatedSrc = await imagePreviewHandler(src);
|
|
96
|
+
setImageSource(updatedSrc);
|
|
97
|
+
};
|
|
98
|
+
callPreviewHandler().catch(console.error);
|
|
99
|
+
} else {
|
|
100
|
+
setImageSource(src);
|
|
101
|
+
}
|
|
102
|
+
}, [src, imagePreviewHandler]);
|
|
90
103
|
React__default.useEffect(() => {
|
|
91
104
|
let isMounted = true;
|
|
92
105
|
const unregister = mergeRegister(
|
|
@@ -160,7 +173,7 @@ function ImageEditor({ src, title, nodeKey, width, height }) {
|
|
|
160
173
|
};
|
|
161
174
|
const draggable = $isNodeSelection(selection);
|
|
162
175
|
const isFocused = isSelected;
|
|
163
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: null }, /* @__PURE__ */ React__default.createElement("div", { className: styles.imageWrapper, "data-editor-block-type": "image" }, /* @__PURE__ */ React__default.createElement("div", { draggable }, /* @__PURE__ */ React__default.createElement(
|
|
176
|
+
return imageSource !== null ? /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: null }, /* @__PURE__ */ React__default.createElement("div", { className: styles.imageWrapper, "data-editor-block-type": "image" }, /* @__PURE__ */ React__default.createElement("div", { draggable }, /* @__PURE__ */ React__default.createElement(
|
|
164
177
|
LazyImage,
|
|
165
178
|
{
|
|
166
179
|
width,
|
|
@@ -168,11 +181,11 @@ function ImageEditor({ src, title, nodeKey, width, height }) {
|
|
|
168
181
|
className: classNames({
|
|
169
182
|
[styles.focusedImage]: isFocused
|
|
170
183
|
}),
|
|
171
|
-
src,
|
|
184
|
+
src: imageSource,
|
|
172
185
|
title: title || "",
|
|
173
186
|
imageRef
|
|
174
187
|
}
|
|
175
|
-
)), draggable && isFocused && !disableImageResize && /* @__PURE__ */ React__default.createElement(ImageResizer, { editor, imageRef, onResizeStart, onResizeEnd })));
|
|
188
|
+
)), draggable && isFocused && !disableImageResize && /* @__PURE__ */ React__default.createElement(ImageResizer, { editor, imageRef, onResizeStart, onResizeEnd }))) : null;
|
|
176
189
|
}
|
|
177
190
|
export {
|
|
178
191
|
ImageEditor
|
|
@@ -10,7 +10,6 @@ const LexicalImageVisitor = {
|
|
|
10
10
|
if (lexicalNode.getWidth() !== "inherit") {
|
|
11
11
|
img.width = lexicalNode.getWidth();
|
|
12
12
|
}
|
|
13
|
-
img.src = lexicalNode.getSrc();
|
|
14
13
|
if (lexicalNode.getAltText()) {
|
|
15
14
|
img.alt = lexicalNode.getAltText();
|
|
16
15
|
}
|
|
@@ -19,7 +18,7 @@ const LexicalImageVisitor = {
|
|
|
19
18
|
}
|
|
20
19
|
actions.appendToParent(mdastParent, {
|
|
21
20
|
type: "html",
|
|
22
|
-
value: img.outerHTML.replace(/>$/, "
|
|
21
|
+
value: img.outerHTML.replace(/>$/, ` src="${lexicalNode.getSrc()}" />`)
|
|
23
22
|
});
|
|
24
23
|
} else {
|
|
25
24
|
actions.appendToParent(mdastParent, {
|
|
@@ -14,6 +14,7 @@ import type { RangeSelection, Klass, LexicalNode, TextFormatType, ElementNode, D
|
|
|
14
14
|
import { CreateImageNodeOptions } from './ImageNode';
|
|
15
15
|
export * from './ImageNode';
|
|
16
16
|
export type ImageUploadHandler = ((image: File) => Promise<string>) | null;
|
|
17
|
+
export type ImagePreviewHandler = ((imageSource: string) => Promise<string>) | null;
|
|
17
18
|
/** @internal */
|
|
18
19
|
export declare const imageSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
19
20
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
@@ -124,11 +125,13 @@ export declare const imageSystem: SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
124
125
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
125
126
|
disableImageResize: RealmNode<boolean>;
|
|
126
127
|
insertImage: RealmNode<string>;
|
|
128
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
127
129
|
}>;
|
|
128
130
|
interface ImagePluginParams {
|
|
129
131
|
imageUploadHandler?: ImageUploadHandler;
|
|
130
132
|
imageAutocompleteSuggestions?: string[];
|
|
131
133
|
disableImageResize?: boolean;
|
|
134
|
+
imagePreviewHandler?: ImagePreviewHandler;
|
|
132
135
|
}
|
|
133
136
|
export declare const
|
|
134
137
|
/** @internal */
|
|
@@ -241,6 +244,7 @@ imagePlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
|
241
244
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
242
245
|
disableImageResize: RealmNode<boolean>;
|
|
243
246
|
insertImage: RealmNode<string>;
|
|
247
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
244
248
|
}>, ImagePluginParams>,
|
|
245
249
|
/** @internal */
|
|
246
250
|
imagePluginHooks: {
|
|
@@ -249,6 +253,7 @@ imagePluginHooks: {
|
|
|
249
253
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
250
254
|
disableImageResize: RealmNode<boolean>;
|
|
251
255
|
insertImage: RealmNode<string>;
|
|
256
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
252
257
|
} & {
|
|
253
258
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
254
259
|
inFocus: RealmNode<boolean>;
|
|
@@ -302,11 +307,12 @@ imagePluginHooks: {
|
|
|
302
307
|
insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
|
|
303
308
|
onBlur: RealmNode<FocusEvent>;
|
|
304
309
|
}>;
|
|
305
|
-
useEmitter: <K extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "imageUploadHandler" | "imageAutocompleteSuggestions" | "disableImageResize" | "insertImage">(key: K, callback: (value: ValueForKey<{
|
|
310
|
+
useEmitter: <K extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "imageUploadHandler" | "imageAutocompleteSuggestions" | "disableImageResize" | "insertImage" | "imagePreviewHandler">(key: K, callback: (value: ValueForKey<{
|
|
306
311
|
imageUploadHandler: RealmNode<ImageUploadHandler>;
|
|
307
312
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
308
313
|
disableImageResize: RealmNode<boolean>;
|
|
309
314
|
insertImage: RealmNode<string>;
|
|
315
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
310
316
|
} & {
|
|
311
317
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
312
318
|
inFocus: RealmNode<boolean>;
|
|
@@ -365,6 +371,7 @@ imagePluginHooks: {
|
|
|
365
371
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
366
372
|
disableImageResize: RealmNode<boolean>;
|
|
367
373
|
insertImage: RealmNode<string>;
|
|
374
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
368
375
|
} & {
|
|
369
376
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
370
377
|
inFocus: RealmNode<boolean>;
|
|
@@ -422,6 +429,7 @@ imagePluginHooks: {
|
|
|
422
429
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
423
430
|
disableImageResize: RealmNode<boolean>;
|
|
424
431
|
insertImage: RealmNode<string>;
|
|
432
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
425
433
|
} & {
|
|
426
434
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
427
435
|
inFocus: RealmNode<boolean>;
|
|
@@ -480,6 +488,7 @@ imagePluginHooks: {
|
|
|
480
488
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
481
489
|
disableImageResize: RealmNode<boolean>;
|
|
482
490
|
insertImage: RealmNode<string>;
|
|
491
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
483
492
|
} & {
|
|
484
493
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
485
494
|
inFocus: RealmNode<boolean>;
|
|
@@ -533,11 +542,12 @@ imagePluginHooks: {
|
|
|
533
542
|
insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
|
|
534
543
|
onBlur: RealmNode<FocusEvent>;
|
|
535
544
|
}>) => void;
|
|
536
|
-
usePublisher: <K_2 extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "imageUploadHandler" | "imageAutocompleteSuggestions" | "disableImageResize" | "insertImage">(key: K_2) => (value: ValueForKey<{
|
|
545
|
+
usePublisher: <K_2 extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "imageUploadHandler" | "imageAutocompleteSuggestions" | "disableImageResize" | "insertImage" | "imagePreviewHandler">(key: K_2) => (value: ValueForKey<{
|
|
537
546
|
imageUploadHandler: RealmNode<ImageUploadHandler>;
|
|
538
547
|
imageAutocompleteSuggestions: RealmNode<string[]>;
|
|
539
548
|
disableImageResize: RealmNode<boolean>;
|
|
540
549
|
insertImage: RealmNode<string>;
|
|
550
|
+
imagePreviewHandler: RealmNode<ImagePreviewHandler>;
|
|
541
551
|
} & {
|
|
542
552
|
activeEditor: RealmNode<LexicalEditor | null>;
|
|
543
553
|
inFocus: RealmNode<boolean>;
|
|
@@ -13,6 +13,7 @@ const imageSystem = system(
|
|
|
13
13
|
const imageAutocompleteSuggestions = r.node([]);
|
|
14
14
|
const disableImageResize = r.node(false);
|
|
15
15
|
const imageUploadHandler = r.node(null);
|
|
16
|
+
const imagePreviewHandler = r.node(null);
|
|
16
17
|
r.sub(r.pipe(insertImage, r.o.withLatestFrom(rootEditor)), ([src, theEditor]) => {
|
|
17
18
|
theEditor == null ? void 0 : theEditor.update(() => {
|
|
18
19
|
const imageNode = $createImageNode({ altText: "", src, title: "" });
|
|
@@ -86,7 +87,8 @@ const imageSystem = system(
|
|
|
86
87
|
imageUploadHandler,
|
|
87
88
|
imageAutocompleteSuggestions,
|
|
88
89
|
disableImageResize,
|
|
89
|
-
insertImage
|
|
90
|
+
insertImage,
|
|
91
|
+
imagePreviewHandler
|
|
90
92
|
};
|
|
91
93
|
},
|
|
92
94
|
[coreSystem]
|
|
@@ -103,6 +105,7 @@ const [
|
|
|
103
105
|
realm.pubKey("imageUploadHandler", (params == null ? void 0 : params.imageUploadHandler) || null);
|
|
104
106
|
realm.pubKey("imageAutocompleteSuggestions", (params == null ? void 0 : params.imageAutocompleteSuggestions) || []);
|
|
105
107
|
realm.pubKey("disableImageResize", Boolean(params == null ? void 0 : params.disableImageResize));
|
|
108
|
+
realm.pubKey("imagePreviewHandler", (params == null ? void 0 : params.imagePreviewHandler) || null);
|
|
106
109
|
},
|
|
107
110
|
init: (realm) => {
|
|
108
111
|
realm.pubKey("addImportVisitor", MdastImageVisitor);
|