@mdxeditor/editor 2.1.0 → 2.2.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.
@@ -1,9 +1,9 @@
1
- import { realmPlugin } from "../../RealmWithPlugins.js";
2
- import { $wrapNodeInElement } from "@lexical/utils";
1
+ import { $wrapNodeInElement, mergeRegister } from "@lexical/utils";
3
2
  import { Signal, Cell, withLatestFrom, Action, mapTo, map } from "@mdxeditor/gurx";
4
3
  import { $getNodeByKey, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, 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
+ import { realmPlugin } from "../../RealmWithPlugins.js";
5
5
  import { CAN_USE_DOM } from "../../utils/detectMac.js";
6
- import { rootEditor$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
6
+ import { activeEditor$, createActiveEditorSubscription$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
7
7
  import { ImageDialog } from "./ImageDialog.js";
8
8
  import { $createImageNode, ImageNode, $isImageNode } from "./ImageNode.js";
9
9
  import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
@@ -17,7 +17,7 @@ const imageDialogState$ = Cell(
17
17
  { type: "inactive" },
18
18
  (r) => {
19
19
  r.sub(
20
- r.pipe(saveImage$, withLatestFrom(rootEditor$, imageUploadHandler$, imageDialogState$)),
20
+ r.pipe(saveImage$, withLatestFrom(activeEditor$, imageUploadHandler$, imageDialogState$)),
21
21
  ([values, theEditor, imageUploadHandler, dialogState]) => {
22
22
  const handler = dialogState.type === "editing" ? (src) => {
23
23
  theEditor == null ? void 0 : theEditor.update(() => {
@@ -47,67 +47,68 @@ const imageDialogState$ = Cell(
47
47
  }
48
48
  }
49
49
  );
50
- r.sub(rootEditor$, (editor) => {
51
- editor == null ? void 0 : editor.registerCommand(
52
- INSERT_IMAGE_COMMAND,
53
- (payload) => {
54
- const imageNode = $createImageNode(payload);
55
- $insertNodes([imageNode]);
56
- if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
57
- $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
58
- }
59
- return true;
60
- },
61
- COMMAND_PRIORITY_EDITOR
62
- );
50
+ r.pub(createActiveEditorSubscription$, (editor) => {
63
51
  const theUploadHandler = r.getValue(imageUploadHandler$);
64
- editor == null ? void 0 : editor.registerCommand(
65
- DRAGSTART_COMMAND,
66
- (event) => {
67
- return onDragStart(event);
68
- },
69
- COMMAND_PRIORITY_HIGH
70
- );
71
- editor == null ? void 0 : editor.registerCommand(
72
- DRAGOVER_COMMAND,
73
- (event) => {
74
- return onDragover(event);
75
- },
76
- COMMAND_PRIORITY_LOW
77
- );
78
- editor == null ? void 0 : editor.registerCommand(
79
- DROP_COMMAND,
80
- (event) => {
81
- return onDrop(event, editor, r.getValue(imageUploadHandler$));
82
- },
83
- COMMAND_PRIORITY_HIGH
84
- );
85
- if (theUploadHandler === null) {
86
- return;
87
- }
88
- editor == null ? void 0 : editor.registerCommand(
89
- PASTE_COMMAND,
90
- (event) => {
91
- var _a;
92
- let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
93
- cbPayload = cbPayload.filter((i) => /image/.test(i.type));
94
- if (!cbPayload.length || cbPayload.length === 0) {
95
- return false;
96
- }
97
- const imageUploadHandlerValue = r.getValue(imageUploadHandler$);
98
- Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
99
- urls.forEach((url) => {
100
- editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
101
- src: url,
102
- altText: ""
52
+ return mergeRegister(
53
+ editor == null ? void 0 : editor.registerCommand(
54
+ INSERT_IMAGE_COMMAND,
55
+ (payload) => {
56
+ const imageNode = $createImageNode(payload);
57
+ $insertNodes([imageNode]);
58
+ if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
59
+ $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
60
+ }
61
+ return true;
62
+ },
63
+ COMMAND_PRIORITY_EDITOR
64
+ ),
65
+ editor == null ? void 0 : editor.registerCommand(
66
+ DRAGSTART_COMMAND,
67
+ (event) => {
68
+ return onDragStart(event);
69
+ },
70
+ COMMAND_PRIORITY_HIGH
71
+ ),
72
+ editor == null ? void 0 : editor.registerCommand(
73
+ DRAGOVER_COMMAND,
74
+ (event) => {
75
+ return onDragover(event);
76
+ },
77
+ COMMAND_PRIORITY_LOW
78
+ ),
79
+ editor == null ? void 0 : editor.registerCommand(
80
+ DROP_COMMAND,
81
+ (event) => {
82
+ return onDrop(event, editor, r.getValue(imageUploadHandler$));
83
+ },
84
+ COMMAND_PRIORITY_HIGH
85
+ ),
86
+ ...theUploadHandler !== null ? [
87
+ editor == null ? void 0 : editor.registerCommand(
88
+ PASTE_COMMAND,
89
+ (event) => {
90
+ var _a;
91
+ let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
92
+ cbPayload = cbPayload.filter((i) => /image/.test(i.type));
93
+ if (!cbPayload.length || cbPayload.length === 0) {
94
+ return false;
95
+ }
96
+ const imageUploadHandlerValue = r.getValue(imageUploadHandler$);
97
+ Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
98
+ urls.forEach((url) => {
99
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
100
+ src: url,
101
+ altText: ""
102
+ });
103
+ });
104
+ }).catch((e) => {
105
+ throw e;
103
106
  });
104
- });
105
- }).catch((e) => {
106
- throw e;
107
- });
108
- return true;
109
- },
110
- COMMAND_PRIORITY_CRITICAL
107
+ return true;
108
+ },
109
+ COMMAND_PRIORITY_CRITICAL
110
+ )
111
+ ] : []
111
112
  );
112
113
  });
113
114
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "2.1.0",
14
+ "version": "2.2.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",
@@ -104,7 +104,6 @@
104
104
  "@types/node": "^20.2.5",
105
105
  "@types/react": "^18.2.7",
106
106
  "@types/react-dom": "^18.2.4",
107
- "@types/testing-library__jest-dom": "^6.0.0",
108
107
  "@types/unist": "^3.0.2",
109
108
  "@typescript-eslint/eslint-plugin": "^6.17.0",
110
109
  "@typescript-eslint/parser": "^6.17.0",