@mdxeditor/editor 3.0.2 → 3.0.3
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 +24 -8
- package/dist/plugins/image/index.js +28 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -291,6 +291,11 @@ export declare const applyListType$: NodeRef<"" | ListType>;
|
|
|
291
291
|
|
|
292
292
|
/* Excluded from this release type: autoFocus$ */
|
|
293
293
|
|
|
294
|
+
declare interface BaseImageParameters {
|
|
295
|
+
altText?: string;
|
|
296
|
+
title?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
294
299
|
/**
|
|
295
300
|
* The type of the block that the current selection is in.
|
|
296
301
|
* @group Core
|
|
@@ -984,7 +989,7 @@ export declare const disableImageSettingsButton$: NodeRef<boolean>;
|
|
|
984
989
|
export declare type EditingImageDialogState = {
|
|
985
990
|
type: 'editing';
|
|
986
991
|
nodeKey: string;
|
|
987
|
-
initialValues: Omit<
|
|
992
|
+
initialValues: Omit<SaveImageParameters, 'file'>;
|
|
988
993
|
};
|
|
989
994
|
|
|
990
995
|
/**
|
|
@@ -1056,6 +1061,10 @@ export declare type FallbackOption = {
|
|
|
1056
1061
|
fallback: () => React_2.ReactNode;
|
|
1057
1062
|
};
|
|
1058
1063
|
|
|
1064
|
+
declare interface FileImageParameters extends BaseImageParameters {
|
|
1065
|
+
file: File;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1059
1068
|
/**
|
|
1060
1069
|
* Fetches a value from the Lexical editor read cycle.
|
|
1061
1070
|
* @group Utils
|
|
@@ -1384,12 +1393,7 @@ export declare const InsertImage: React_2.ForwardRefExoticComponent<Omit<Record<
|
|
|
1384
1393
|
/**
|
|
1385
1394
|
* @group Image
|
|
1386
1395
|
*/
|
|
1387
|
-
export declare
|
|
1388
|
-
src?: string;
|
|
1389
|
-
altText?: string;
|
|
1390
|
-
title?: string;
|
|
1391
|
-
file: FileList;
|
|
1392
|
-
}
|
|
1396
|
+
export declare type InsertImageParameters = FileImageParameters | SrcImageParameters;
|
|
1393
1397
|
|
|
1394
1398
|
/* Excluded from this release type: InsertImagePayload */
|
|
1395
1399
|
|
|
@@ -2387,7 +2391,15 @@ declare type SandpackProviderProps = React_2.ComponentProps<typeof SandpackProvi
|
|
|
2387
2391
|
* Saves the data from the image dialog
|
|
2388
2392
|
* @group Image
|
|
2389
2393
|
*/
|
|
2390
|
-
export declare const saveImage$: NodeRef<
|
|
2394
|
+
export declare const saveImage$: NodeRef<SaveImageParameters>;
|
|
2395
|
+
|
|
2396
|
+
/**
|
|
2397
|
+
* @group Image
|
|
2398
|
+
*/
|
|
2399
|
+
export declare interface SaveImageParameters extends BaseImageParameters {
|
|
2400
|
+
src?: string;
|
|
2401
|
+
file: FileList;
|
|
2402
|
+
}
|
|
2391
2403
|
|
|
2392
2404
|
/**
|
|
2393
2405
|
* A toolbar primitive you can use to build dropdowns, such as the block type select.
|
|
@@ -2503,6 +2515,10 @@ export declare const SingleChoiceToggleGroup: <T extends string>({ value, onChan
|
|
|
2503
2515
|
|
|
2504
2516
|
/* Excluded from this release type: SingleToggleGroup */
|
|
2505
2517
|
|
|
2518
|
+
declare interface SrcImageParameters extends BaseImageParameters {
|
|
2519
|
+
src: string;
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2506
2522
|
/**
|
|
2507
2523
|
* An action that switches the link dialog from preview mode to edit mode.
|
|
2508
2524
|
* @group Link Dialog
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $wrapNodeInElement, mergeRegister } from "@lexical/utils";
|
|
2
|
-
import { Signal,
|
|
3
|
-
import { $
|
|
2
|
+
import { Signal, withLatestFrom, Cell, Action, mapTo, map } from "@mdxeditor/gurx";
|
|
3
|
+
import { $insertNodes, $isRootOrShadowRoot, $createParagraphNode, $getNodeByKey, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, createCommand, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
|
|
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";
|
|
@@ -8,7 +8,31 @@ import { ImageDialog } from "./ImageDialog.js";
|
|
|
8
8
|
import { $createImageNode, ImageNode, $isImageNode } from "./ImageNode.js";
|
|
9
9
|
import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
|
|
10
10
|
import { MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor } from "./MdastImageVisitor.js";
|
|
11
|
-
const
|
|
11
|
+
const internalInsertImage$ = Signal((r) => {
|
|
12
|
+
r.sub(r.pipe(internalInsertImage$, withLatestFrom(activeEditor$)), ([values, theEditor]) => {
|
|
13
|
+
theEditor == null ? void 0 : theEditor.update(() => {
|
|
14
|
+
const imageNode = $createImageNode({ altText: values.altText ?? "", src: values.src, title: values.title ?? "" });
|
|
15
|
+
$insertNodes([imageNode]);
|
|
16
|
+
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
17
|
+
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const insertImage$ = Signal((r) => {
|
|
23
|
+
r.sub(r.pipe(insertImage$, withLatestFrom(imageUploadHandler$)), ([values, imageUploadHandler]) => {
|
|
24
|
+
const handler = (src) => {
|
|
25
|
+
r.pub(internalInsertImage$, { ...values, src });
|
|
26
|
+
};
|
|
27
|
+
if ("file" in values) {
|
|
28
|
+
imageUploadHandler == null ? void 0 : imageUploadHandler(values.file).then(handler).catch((e) => {
|
|
29
|
+
throw e;
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
handler(values.src);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
12
36
|
const imageAutocompleteSuggestions$ = Cell([]);
|
|
13
37
|
const disableImageResize$ = Cell(false);
|
|
14
38
|
const imageUploadHandler$ = Cell(null);
|
|
@@ -29,13 +53,7 @@ const imageDialogState$ = Cell(
|
|
|
29
53
|
});
|
|
30
54
|
r.pub(imageDialogState$, { type: "inactive" });
|
|
31
55
|
} : (src) => {
|
|
32
|
-
|
|
33
|
-
const imageNode = $createImageNode({ altText: values.altText ?? "", src, title: values.title ?? "" });
|
|
34
|
-
$insertNodes([imageNode]);
|
|
35
|
-
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
36
|
-
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
56
|
+
r.pub(internalInsertImage$, { ...values, src });
|
|
39
57
|
r.pub(imageDialogState$, { type: "inactive" });
|
|
40
58
|
};
|
|
41
59
|
if (values.file.length > 0) {
|