@mdxeditor/editor 4.0.4 → 4.1.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.
Files changed (40) hide show
  1. package/dist/MDXEditor.js +138 -53
  2. package/dist/RealmWithPlugins.js +27 -9
  3. package/dist/exportMarkdownFromLexical.js +1 -1
  4. package/dist/index.d.ts +12 -10
  5. package/dist/index.js +6 -6
  6. package/dist/mdastUtilHtmlComment.js +2 -1
  7. package/dist/plugins/codeblock/CodeBlockNode.js +4 -5
  8. package/dist/plugins/codeblock/index.js +1 -1
  9. package/dist/plugins/codemirror/CodeMirrorEditor.js +1 -1
  10. package/dist/plugins/core/GenericHTMLNode.js +2 -5
  11. package/dist/plugins/core/NestedLexicalEditor.js +58 -38
  12. package/dist/plugins/core/index.js +26 -30
  13. package/dist/plugins/core/lexicalExtensions.js +143 -0
  14. package/dist/plugins/diff-source/SourceEditor.js +1 -1
  15. package/dist/plugins/directives/DirectiveNode.js +1 -4
  16. package/dist/plugins/frontmatter/FrontmatterNode.js +1 -4
  17. package/dist/plugins/frontmatter/index.js +1 -1
  18. package/dist/plugins/headings/index.js +2 -1
  19. package/dist/plugins/image/ImageDialog.js +1 -2
  20. package/dist/plugins/image/ImageEditor.js +1 -2
  21. package/dist/plugins/image/ImageNode.js +1 -4
  22. package/dist/plugins/image/index.js +4 -6
  23. package/dist/plugins/jsx/LexicalJsxNode.js +1 -4
  24. package/dist/plugins/jsx/LexicalMdxExpressionNode.js +1 -4
  25. package/dist/plugins/link-dialog/LinkDialog.js +3 -3
  26. package/dist/plugins/link-dialog/index.js +16 -4
  27. package/dist/plugins/lists/index.js +3 -3
  28. package/dist/plugins/markdown-shortcut/index.js +1 -1
  29. package/dist/plugins/search/index.js +259 -179
  30. package/dist/plugins/table/TableEditor.js +38 -24
  31. package/dist/plugins/table/TableNode.js +1 -4
  32. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +2 -2
  33. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +1 -1
  34. package/dist/plugins/toolbar/primitives/toolbar.js +1 -1
  35. package/dist/realmSession.js +38 -0
  36. package/dist/style.css +1511 -1525
  37. package/dist/utils/lexicalHelpers.js +53 -74
  38. package/package.json +23 -12
  39. package/dist/plugins/core/SharedHistoryPlugin.js +0 -10
  40. package/dist/styles/globals.css.js +0 -1
@@ -1,7 +1,5 @@
1
- import { $getSelection, $getRoot, $isRangeSelection, $isElementNode, $isTextNode } from "lexical";
2
- import { $isLinkNode } from "@lexical/link";
3
- import { $isHeadingNode } from "@lexical/rich-text";
4
- import { $isListItemNode, $isListNode } from "@lexical/list";
1
+ import { $getSelection, $isRangeSelection, createEditor, $getRoot, $createParagraphNode } from "lexical";
2
+ import { $generateJSONFromSelectedNodes, $generateNodesFromSerializedNodes } from "@lexical/clipboard";
5
3
  import { $isAtNodeEnd } from "@lexical/selection";
6
4
  import { tap } from "./fp.js";
7
5
  import { exportMarkdownFromLexical } from "../exportMarkdownFromLexical.js";
@@ -101,80 +99,61 @@ function getStateAsMarkdown(editor, exportParams) {
101
99
  });
102
100
  }).markdown;
103
101
  }
104
- function getSelectionAsMarkdown(editor, _exportParams) {
102
+ function getSelectionAsMarkdown(editor, exportParams) {
103
+ let temporaryEditor = null;
104
+ let selectedNodes = [];
105
105
  let markdown = "";
106
- editor.getEditorState().read(() => {
107
- const selection = $getSelection();
108
- if (!selection || !$isRangeSelection(selection) || selection.isCollapsed()) {
109
- return;
110
- }
111
- const nodes = selection.getNodes();
112
- if (nodes.length === 0) {
113
- return;
114
- }
115
- const parentNodes = /* @__PURE__ */ new Set();
116
- nodes.forEach((node) => {
117
- let current = node;
118
- while (current) {
119
- if ($isHeadingNode(current) || $isListItemNode(current) || current.getType() === "paragraph" || current.getType() === "quote") {
120
- if ($isElementNode(current)) {
121
- parentNodes.add(current);
122
- }
123
- break;
124
- }
125
- current = current.getParent();
106
+ editor.getEditorState().read(
107
+ () => {
108
+ const selection = $getSelection();
109
+ if (!selection || $isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
110
+ return;
126
111
  }
127
- });
128
- const nodesToProcess = parentNodes.size > 0 ? Array.from(parentNodes) : nodes;
129
- function nodeToMarkdown(node) {
130
- if ($isHeadingNode(node)) {
131
- const level = parseInt(node.getTag().replace("h", ""));
132
- const children = node.getChildren();
133
- const headingText = children.map((child) => nodeToMarkdown(child)).join("");
134
- return "#".repeat(level) + " " + headingText + "\n\n";
135
- } else if ($isListItemNode(node)) {
136
- const parent = node.getParent();
137
- const prefix = parent && $isListNode(parent) && parent.getListType() === "number" ? "1. " : "- ";
138
- const children = node.getChildren();
139
- const itemText = children.map((child) => nodeToMarkdown(child)).join("");
140
- return prefix + itemText + "\n";
141
- } else if ($isListNode(node)) {
142
- const children = node.getChildren();
143
- return children.map((child) => nodeToMarkdown(child)).join("") + "\n";
144
- } else if ($isTextNode(node)) {
145
- let text = node.getTextContent();
146
- const format = node.getFormat();
147
- if (format & 16) {
148
- return `\`${text}\``;
149
- }
150
- if (format & 1) {
151
- text = `**${text}**`;
152
- }
153
- if (format & 2) {
154
- text = `*${text}*`;
155
- }
156
- if (format & 4) {
157
- text = `~~${text}~~`;
158
- }
159
- return text;
160
- } else if ($isLinkNode(node)) {
161
- const url = node.getURL();
162
- const title = node.getTitle();
163
- const children = node.getChildren();
164
- const linkText = children.map((child) => nodeToMarkdown(child)).join("");
165
- if (title) {
166
- return `[${linkText}](${url} "${title}")`;
112
+ selectedNodes = $generateJSONFromSelectedNodes(editor, selection).nodes;
113
+ if (selectedNodes.length > 0) {
114
+ temporaryEditor = createEditor();
115
+ }
116
+ },
117
+ { editor }
118
+ );
119
+ const selectedTreeEditor = temporaryEditor;
120
+ if (!selectedTreeEditor || selectedNodes.length === 0) {
121
+ return "";
122
+ }
123
+ const exportResult = { error: void 0, failed: false };
124
+ selectedTreeEditor.update(
125
+ () => {
126
+ try {
127
+ const root = $getRoot();
128
+ const nodes = $generateNodesFromSerializedNodes(selectedNodes);
129
+ let inlineContainer = $createParagraphNode();
130
+ const appendInlineContainer = () => {
131
+ if (!inlineContainer.isEmpty()) {
132
+ root.append(inlineContainer);
133
+ inlineContainer = $createParagraphNode();
134
+ }
135
+ };
136
+ for (const node of nodes) {
137
+ if (node.isInline()) {
138
+ inlineContainer.append(node);
139
+ } else {
140
+ appendInlineContainer();
141
+ root.append(node);
142
+ }
167
143
  }
168
- return `[${linkText}](${url})`;
169
- } else if ($isElementNode(node)) {
170
- const children = node.getChildren();
171
- return children.map((child) => nodeToMarkdown(child)).join("");
144
+ appendInlineContainer();
145
+ markdown = exportMarkdownFromLexical({ root, ...exportParams });
146
+ } catch (error) {
147
+ exportResult.failed = true;
148
+ exportResult.error = error;
172
149
  }
173
- return node.getTextContent();
174
- }
175
- markdown = nodesToProcess.map((node) => nodeToMarkdown(node)).join("");
176
- });
177
- return markdown.trim();
150
+ },
151
+ { discrete: true, skipTransforms: true }
152
+ );
153
+ if (exportResult.failed) {
154
+ throw exportResult.error;
155
+ }
156
+ return markdown.replace(/\n+$/u, "");
178
157
  }
179
158
  export {
180
159
  fromWithinEditorRead,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "4.0.4",
14
+ "version": "4.1.1",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",
@@ -22,6 +22,14 @@
22
22
  "lint": "eslint src --ext .ts,.tsx",
23
23
  "test": "vitest",
24
24
  "test:once": "vitest --run",
25
+ "test:compat:unit": "vitest --run src/test/compatibility.test.tsx",
26
+ "test:browser:serve": "ladle dev --host 127.0.0.1 --port 61000 --noWatch",
27
+ "test:browser": "playwright test",
28
+ "test:browser:chromium": "playwright test --project=chromium",
29
+ "test:compat": "npm run test:compat:unit && npm run test:browser",
30
+ "test:lexical-versions": "node scripts/assert-lexical-versions.mjs",
31
+ "test:package": "node scripts/verify-package-consumer.mjs",
32
+ "test:cross-version": "node scripts/verify-cross-version-markdown.mjs",
25
33
  "semantic-release": "semantic-release",
26
34
  "image-upload-backend": "node ./src/examples/file-backend.js",
27
35
  "export-icons": "node ./scripts/export-figma-icons.mjs"
@@ -44,15 +52,17 @@
44
52
  "@codemirror/merge": "^6.4.0",
45
53
  "@codemirror/state": "^6.4.0",
46
54
  "@codemirror/view": "^6.23.0",
47
- "@lexical/clipboard": "^0.35.0",
48
- "@lexical/link": "^0.35.0",
49
- "@lexical/list": "^0.35.0",
50
- "@lexical/markdown": "^0.35.0",
51
- "@lexical/plain-text": "^0.35.0",
52
- "@lexical/react": "^0.35.0",
53
- "@lexical/rich-text": "^0.35.0",
54
- "@lexical/selection": "^0.35.0",
55
- "@lexical/utils": "^0.35.0",
55
+ "@lexical/clipboard": "^0.48.0",
56
+ "@lexical/extension": "^0.48.0",
57
+ "@lexical/history": "^0.48.0",
58
+ "@lexical/link": "^0.48.0",
59
+ "@lexical/list": "^0.48.0",
60
+ "@lexical/markdown": "^0.48.0",
61
+ "@lexical/plain-text": "^0.48.0",
62
+ "@lexical/react": "^0.48.0",
63
+ "@lexical/rich-text": "^0.48.0",
64
+ "@lexical/selection": "^0.48.0",
65
+ "@lexical/utils": "^0.48.0",
56
66
  "@mdxeditor/gurx": "^1.2.4",
57
67
  "@radix-ui/colors": "^3.0.0",
58
68
  "@radix-ui/react-dialog": "^1.1.11",
@@ -67,8 +77,8 @@
67
77
  "cm6-theme-basic-light": "^0.2.0",
68
78
  "codemirror": "^6.0.1",
69
79
  "downshift": "^7.6.0",
70
- "js-yaml": "4.2.0",
71
- "lexical": "^0.35.0",
80
+ "js-yaml": "4.3.0",
81
+ "lexical": "^0.48.0",
72
82
  "mdast-util-directive": "^3.0.0",
73
83
  "mdast-util-from-markdown": "^2.0.0",
74
84
  "mdast-util-frontmatter": "^2.0.1",
@@ -106,6 +116,7 @@
106
116
  "@babel/preset-typescript": "^7.23.3",
107
117
  "@ladle/react": "^5.1.1",
108
118
  "@ngneat/falso": "^6.4.0",
119
+ "@playwright/test": "1.61.1",
109
120
  "@testing-library/dom": "^10.4.1",
110
121
  "@testing-library/jest-dom": "^6.1.6",
111
122
  "@testing-library/react": "^16.3.0",
@@ -1,10 +0,0 @@
1
- import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
2
- import React__default from "react";
3
- import { historyState$ } from "./index.js";
4
- import { useCellValue } from "@mdxeditor/gurx";
5
- const SharedHistoryPlugin = () => {
6
- return /* @__PURE__ */ React__default.createElement(HistoryPlugin, { externalHistoryState: useCellValue(historyState$) });
7
- };
8
- export {
9
- SharedHistoryPlugin
10
- };
@@ -1 +0,0 @@
1
-