@mdxeditor/editor 3.0.8 → 3.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 (60) hide show
  1. package/dist/FormatConstants.js +10 -0
  2. package/dist/MDXEditor.js +1 -1
  3. package/dist/directive-editors/GenericDirectiveEditor.js +5 -7
  4. package/dist/exportMarkdownFromLexical.js +10 -7
  5. package/dist/icons/strikethrough_s.svg.js +5 -0
  6. package/dist/icons/subscript.svg.js +5 -0
  7. package/dist/icons/superscript.svg.js +5 -0
  8. package/dist/importMarkdownToLexical.js +3 -1
  9. package/dist/index.d.ts +62 -32
  10. package/dist/index.js +12 -1
  11. package/dist/jsx-editors/GenericJsxEditor.js +1 -1
  12. package/dist/mdastUtilHtmlComment.js +2 -2
  13. package/dist/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js +114 -0
  14. package/dist/node_modules/micromark-util-chunked/index.js +29 -0
  15. package/dist/node_modules/micromark-util-classify-character/index.js +12 -0
  16. package/dist/node_modules/micromark-util-resolve-all/index.js +15 -0
  17. package/dist/plugins/codeblock/index.js +2 -2
  18. package/dist/plugins/codemirror/index.js +4 -4
  19. package/dist/plugins/core/Icon.js +6 -0
  20. package/dist/plugins/core/LexicalTextVisitor.js +49 -4
  21. package/dist/plugins/core/MdastFormattingVisitor.js +35 -59
  22. package/dist/plugins/core/MdastHTMLNode.js +1 -2
  23. package/dist/plugins/core/NestedLexicalEditor.js +1 -1
  24. package/dist/plugins/core/PropertyPopover.js +28 -18
  25. package/dist/plugins/core/index.js +34 -29
  26. package/dist/plugins/core/ui/DownshiftAutoComplete.js +1 -1
  27. package/dist/plugins/directives/index.js +2 -2
  28. package/dist/plugins/frontmatter/FrontmatterEditor.js +48 -31
  29. package/dist/plugins/frontmatter/FrontmatterNode.js +5 -3
  30. package/dist/plugins/image/ImageDialog.js +1 -1
  31. package/dist/plugins/image/ImageEditor.js +8 -6
  32. package/dist/plugins/image/ImageNode.js +2 -2
  33. package/dist/plugins/image/MdastImageVisitor.js +3 -3
  34. package/dist/plugins/image/index.js +20 -20
  35. package/dist/plugins/jsx/index.js +1 -1
  36. package/dist/plugins/link-dialog/LinkDialog.js +13 -5
  37. package/dist/plugins/link-dialog/index.js +7 -8
  38. package/dist/plugins/lists/MdastListVisitor.js +1 -2
  39. package/dist/plugins/lists/index.js +1 -1
  40. package/dist/plugins/markdown-shortcut/index.js +4 -2
  41. package/dist/plugins/sandpack/SandpackEditor.js +1 -1
  42. package/dist/plugins/sandpack/index.js +2 -2
  43. package/dist/plugins/sandpack/useCodeMirrorRef.js +8 -8
  44. package/dist/plugins/table/TableEditor.js +67 -50
  45. package/dist/plugins/table/TableNode.js +2 -2
  46. package/dist/plugins/toolbar/components/BlockTypeSelect.js +3 -3
  47. package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +79 -24
  48. package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +1 -1
  49. package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +1 -1
  50. package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +3 -1
  51. package/dist/plugins/toolbar/components/InsertFrontmatter.js +3 -1
  52. package/dist/plugins/toolbar/components/InsertImage.js +12 -1
  53. package/dist/plugins/toolbar/components/InsertThematicBreak.js +10 -1
  54. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +2 -2
  55. package/dist/plugins/toolbar/primitives/DialogButton.js +1 -1
  56. package/dist/plugins/toolbar/primitives/select.js +3 -1
  57. package/dist/plugins/toolbar/primitives/toolbar.js +17 -3
  58. package/dist/utils/detectMac.js +1 -1
  59. package/dist/utils/isPartOftheEditorUI.js +1 -1
  60. package/package.json +3 -2
@@ -36,7 +36,7 @@ function LazyImage({
36
36
  return /* @__PURE__ */ React__default.createElement(
37
37
  "img",
38
38
  {
39
- className: className || void 0,
39
+ className: className ?? void 0,
40
40
  alt,
41
41
  src,
42
42
  title,
@@ -120,7 +120,9 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
120
120
  const updatedSrc = await imagePreviewHandler(src);
121
121
  setImageSource(updatedSrc);
122
122
  };
123
- callPreviewHandler().catch(console.error);
123
+ callPreviewHandler().catch((e) => {
124
+ console.error(e);
125
+ });
124
126
  } else {
125
127
  setImageSource(src);
126
128
  }
@@ -207,8 +209,8 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
207
209
  [styles.focusedImage]: isFocused
208
210
  }),
209
211
  src: imageSource,
210
- title: title || "",
211
- alt: alt || "",
212
+ title: title ?? "",
213
+ alt: alt ?? "",
212
214
  imageRef
213
215
  }
214
216
  )), draggable && isFocused && !disableImageResize && /* @__PURE__ */ React__default.createElement(ImageResizer, { editor, imageRef, onResizeStart, onResizeEnd }), !disableImageSettingsButton && /* @__PURE__ */ React__default.createElement(
@@ -223,8 +225,8 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
223
225
  nodeKey,
224
226
  initialValues: {
225
227
  src: !initialImagePath ? imageSource : initialImagePath,
226
- title: title || "",
227
- altText: alt || ""
228
+ title: title ?? "",
229
+ altText: alt ?? ""
228
230
  }
229
231
  });
230
232
  }
@@ -35,8 +35,8 @@ class ImageNode extends DecoratorNode {
35
35
  this.__src = src;
36
36
  this.__title = title;
37
37
  this.__altText = altText;
38
- this.__width = width || "inherit";
39
- this.__height = height || "inherit";
38
+ this.__width = width ?? "inherit";
39
+ this.__height = height ?? "inherit";
40
40
  }
41
41
  /** @internal */
42
42
  static getType() {
@@ -6,8 +6,8 @@ const MdastImageVisitor = {
6
6
  actions.addAndStepInto(
7
7
  $createImageNode({
8
8
  src: mdastNode.url,
9
- altText: mdastNode.alt || "",
10
- title: mdastNode.title || ""
9
+ altText: mdastNode.alt ?? "",
10
+ title: mdastNode.title ?? ""
11
11
  })
12
12
  );
13
13
  }
@@ -60,7 +60,7 @@ const MdastJsxImageVisitor = {
60
60
  if (!src) {
61
61
  return;
62
62
  }
63
- const altText = getAttributeValue(mdastNode, "alt") || "";
63
+ const altText = getAttributeValue(mdastNode, "alt") ?? "";
64
64
  const title = getAttributeValue(mdastNode, "title");
65
65
  const height = getAttributeValue(mdastNode, "height");
66
66
  const width = getAttributeValue(mdastNode, "width");
@@ -68,7 +68,7 @@ const imageDialogState$ = Cell(
68
68
  r.pub(createActiveEditorSubscription$, (editor) => {
69
69
  const theUploadHandler = r.getValue(imageUploadHandler$);
70
70
  return mergeRegister(
71
- editor == null ? void 0 : editor.registerCommand(
71
+ editor.registerCommand(
72
72
  INSERT_IMAGE_COMMAND,
73
73
  (payload) => {
74
74
  const imageNode = $createImageNode(payload);
@@ -80,21 +80,21 @@ const imageDialogState$ = Cell(
80
80
  },
81
81
  COMMAND_PRIORITY_EDITOR
82
82
  ),
83
- editor == null ? void 0 : editor.registerCommand(
83
+ editor.registerCommand(
84
84
  DRAGSTART_COMMAND,
85
85
  (event) => {
86
86
  return onDragStart(event);
87
87
  },
88
88
  COMMAND_PRIORITY_HIGH
89
89
  ),
90
- editor == null ? void 0 : editor.registerCommand(
90
+ editor.registerCommand(
91
91
  DRAGOVER_COMMAND,
92
92
  (event) => {
93
93
  return onDragover(event);
94
94
  },
95
95
  COMMAND_PRIORITY_LOW
96
96
  ),
97
- editor == null ? void 0 : editor.registerCommand(
97
+ editor.registerCommand(
98
98
  DROP_COMMAND,
99
99
  (event) => {
100
100
  return onDrop(event, editor, r.getValue(imageUploadHandler$));
@@ -102,12 +102,12 @@ const imageDialogState$ = Cell(
102
102
  COMMAND_PRIORITY_HIGH
103
103
  ),
104
104
  ...theUploadHandler !== null ? [
105
- editor == null ? void 0 : editor.registerCommand(
105
+ editor.registerCommand(
106
106
  PASTE_COMMAND,
107
107
  (event) => {
108
108
  var _a;
109
- let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
110
- cbPayload = cbPayload.filter((i) => /image/.test(i.type));
109
+ let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) ?? []);
110
+ cbPayload = cbPayload.filter((i) => i.type.includes("image"));
111
111
  if (!cbPayload.length || cbPayload.length === 0) {
112
112
  return false;
113
113
  }
@@ -154,24 +154,24 @@ const imagePlugin = realmPlugin({
154
154
  [addImportVisitor$]: [MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor],
155
155
  [addLexicalNode$]: ImageNode,
156
156
  [addExportVisitor$]: LexicalImageVisitor,
157
- [addComposerChild$]: (params == null ? void 0 : params.ImageDialog) || ImageDialog,
158
- [imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) || null,
159
- [imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) || [],
157
+ [addComposerChild$]: (params == null ? void 0 : params.ImageDialog) ?? ImageDialog,
158
+ [imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) ?? null,
159
+ [imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) ?? [],
160
160
  [disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
161
161
  [disableImageSettingsButton$]: Boolean(params == null ? void 0 : params.disableImageSettingsButton),
162
- [imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) || null
162
+ [imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null
163
163
  });
164
164
  },
165
165
  update(realm, params) {
166
166
  realm.pubIn({
167
- [imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) || null,
168
- [imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) || [],
167
+ [imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) ?? null,
168
+ [imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) ?? [],
169
169
  [disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
170
- [imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) || null
170
+ [imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null
171
171
  });
172
172
  }
173
173
  });
174
- const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
174
+ const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow ?? window).getSelection() : null;
175
175
  const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
176
176
  const TRANSPARENT_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
177
177
  function onDragStart(event) {
@@ -203,8 +203,8 @@ function onDragStart(event) {
203
203
  }
204
204
  function onDragover(event) {
205
205
  var _a;
206
- let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
207
- cbPayload = cbPayload.filter((i) => /image/.test(i.type));
206
+ let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) ?? []);
207
+ cbPayload = cbPayload.filter((i) => i.type.includes("image"));
208
208
  if (cbPayload.length > 0) {
209
209
  event.preventDefault();
210
210
  return true;
@@ -220,8 +220,8 @@ function onDragover(event) {
220
220
  }
221
221
  function onDrop(event, editor, imageUploadHandler) {
222
222
  var _a;
223
- let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
224
- cbPayload = cbPayload.filter((i) => /image/.test(i.type));
223
+ let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) ?? []);
224
+ cbPayload = cbPayload.filter((i) => i.type.includes("image"));
225
225
  if (cbPayload.length > 0) {
226
226
  if (imageUploadHandler !== null) {
227
227
  event.preventDefault();
@@ -292,7 +292,7 @@ function getDragSelection(event) {
292
292
  if (document.caretRangeFromPoint) {
293
293
  range = document.caretRangeFromPoint(event.clientX, event.clientY);
294
294
  } else if (event.rangeParent && domSelection !== null) {
295
- domSelection.collapse(event.rangeParent, event.rangeOffset || 0);
295
+ domSelection.collapse(event.rangeParent, event.rangeOffset ?? 0);
296
296
  range = domSelection.getRangeAt(0);
297
297
  } else {
298
298
  throw Error(`Cannot get the selection when dragging`);
@@ -15,7 +15,7 @@ function isMdastJsxNode(node) {
15
15
  return node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement";
16
16
  }
17
17
  const isExpressionValue = (value) => {
18
- if (typeof value === "object" && value !== null && "type" in value && value.type === "expression" && "value" in value && typeof value.value === "string") {
18
+ if (value !== null && typeof value === "object" && "type" in value && "value" in value && typeof value.value === "string") {
19
19
  return true;
20
20
  }
21
21
  return false;
@@ -102,7 +102,7 @@ const LinkDialog = () => {
102
102
  }, [activeEditor, publishWindowChange]);
103
103
  const [copyUrlTooltipOpen, setCopyUrlTooltipOpen] = React__default.useState(false);
104
104
  const t = useTranslation();
105
- const theRect = linkDialogState == null ? void 0 : linkDialogState.rectangle;
105
+ const theRect = linkDialogState.rectangle;
106
106
  const urlIsExternal = linkDialogState.type === "preview" && linkDialogState.url.startsWith("http");
107
107
  return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, { open: linkDialogState.type !== "inactive" }, /* @__PURE__ */ React__default.createElement(
108
108
  RadixPopover.Anchor,
@@ -121,7 +121,9 @@ const LinkDialog = () => {
121
121
  {
122
122
  className: classNames(styles.linkDialogPopoverContent),
123
123
  sideOffset: 5,
124
- onOpenAutoFocus: (e) => e.preventDefault(),
124
+ onOpenAutoFocus: (e) => {
125
+ e.preventDefault();
126
+ },
125
127
  key: linkDialogState.linkNodeKey
126
128
  },
127
129
  linkDialogState.type === "edit" && /* @__PURE__ */ React__default.createElement(
@@ -153,7 +155,9 @@ const LinkDialog = () => {
153
155
  ), /* @__PURE__ */ React__default.createElement(
154
156
  ActionButton,
155
157
  {
156
- onClick: () => switchFromPreviewToLinkEdit(),
158
+ onClick: () => {
159
+ switchFromPreviewToLinkEdit();
160
+ },
157
161
  title: t("linkPreview.edit", "Edit link URL"),
158
162
  "aria-label": t("linkPreview.edit", "Edit link URL")
159
163
  },
@@ -166,7 +170,9 @@ const LinkDialog = () => {
166
170
  onClick: () => {
167
171
  void window.navigator.clipboard.writeText(linkDialogState.url).then(() => {
168
172
  setCopyUrlTooltipOpen(true);
169
- setTimeout(() => setCopyUrlTooltipOpen(false), 1e3);
173
+ setTimeout(() => {
174
+ setCopyUrlTooltipOpen(false);
175
+ }, 1e3);
170
176
  });
171
177
  }
172
178
  },
@@ -176,7 +182,9 @@ const LinkDialog = () => {
176
182
  {
177
183
  title: t("linkPreview.remove", "Remove link"),
178
184
  "aria-label": t("linkPreview.remove", "Remove link"),
179
- onClick: () => removeLink()
185
+ onClick: () => {
186
+ removeLink();
187
+ }
180
188
  },
181
189
  iconComponentFor("link_off")
182
190
  )),
@@ -80,9 +80,8 @@ const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
80
80
  linkDialogState$
81
81
  );
82
82
  r.sub(r.pipe(updateLink$, withLatestFrom(activeEditor$, linkDialogState$, currentSelection$)), ([payload, editor, state, selection]) => {
83
- var _a, _b;
84
- const url = ((_a = payload.url) == null ? void 0 : _a.trim()) ?? "";
85
- const title = ((_b = payload.title) == null ? void 0 : _b.trim()) ?? "";
83
+ const url = payload.url.trim();
84
+ const title = payload.title.trim();
86
85
  if (url !== "") {
87
86
  if (selection == null ? void 0 : selection.isCollapsed()) {
88
87
  const linkContent = title || url;
@@ -186,16 +185,16 @@ const openLinkEditDialog$ = Action((r) => {
186
185
  ),
187
186
  ([, selection, editor]) => {
188
187
  editor == null ? void 0 : editor.focus(() => {
189
- editor == null ? void 0 : editor.getEditorState().read(() => {
188
+ editor.getEditorState().read(() => {
190
189
  const node = getLinkNodeInSelection(selection);
191
190
  const rectangle = getSelectionRectangle(editor);
192
191
  if (node) {
193
192
  r.pub(linkDialogState$, {
194
193
  type: "edit",
195
194
  initialUrl: node.getURL(),
196
- initialTitle: node.getTitle() || "",
195
+ initialTitle: node.getTitle() ?? "",
197
196
  url: node.getURL(),
198
- title: node.getTitle() || "",
197
+ title: node.getTitle() ?? "",
199
198
  linkNodeKey: node.getKey(),
200
199
  rectangle
201
200
  });
@@ -219,11 +218,11 @@ const linkAutocompleteSuggestions$ = Cell([]);
219
218
  const onClickLinkCallback$ = Cell(null);
220
219
  const linkDialogPlugin = realmPlugin({
221
220
  init(r, params) {
222
- r.pub(addComposerChild$, (params == null ? void 0 : params.LinkDialog) || LinkDialog);
221
+ r.pub(addComposerChild$, (params == null ? void 0 : params.LinkDialog) ?? LinkDialog);
223
222
  r.pub(onClickLinkCallback$, (params == null ? void 0 : params.onClickLinkCallback) ?? null);
224
223
  },
225
224
  update(r, params = {}) {
226
- r.pub(linkAutocompleteSuggestions$, params.linkAutocompleteSuggestions || []);
225
+ r.pub(linkAutocompleteSuggestions$, params.linkAutocompleteSuggestions ?? []);
227
226
  }
228
227
  });
229
228
  export {
@@ -2,8 +2,7 @@ import { $createListNode, $isListItemNode, $createListItemNode } from "@lexical/
2
2
  const MdastListVisitor = {
3
3
  testNode: "list",
4
4
  visitNode: function({ mdastNode, lexicalParent, actions }) {
5
- var _a;
6
- const listType = ((_a = mdastNode.children) == null ? void 0 : _a.some((e) => typeof e.checked === "boolean")) ? "check" : mdastNode.ordered ? "number" : "bullet";
5
+ const listType = mdastNode.children.some((e) => typeof e.checked === "boolean") ? "check" : mdastNode.ordered ? "number" : "bullet";
7
6
  const lexicalNode = $createListNode(listType);
8
7
  if ($isListItemNode(lexicalParent)) {
9
8
  const dedicatedParent = $createListItemNode();
@@ -87,7 +87,7 @@ function isIndentPermitted(maxDepth) {
87
87
  } else if ($isListItemNode(elementNode)) {
88
88
  const parent = elementNode.getParent();
89
89
  if ((parent == null ? void 0 : parent.getChildren().length) === 1) {
90
- const grandParentListItem = parent == null ? void 0 : parent.getParent();
90
+ const grandParentListItem = parent.getParent();
91
91
  if ($isListItemNode(grandParentListItem) && grandParentListItem.getChildren().length === 1) {
92
92
  return false;
93
93
  }
@@ -73,9 +73,11 @@ function pickTransformersForActivePlugins(pluginIds, allowedHeadingLevels) {
73
73
  ...CODE,
74
74
  dependencies: [CodeBlockNode],
75
75
  replace: (parentNode, _children, match) => {
76
- const codeBlockNode = $createCodeBlockNode({ code: "", language: match ? match[1] : "", meta: "" });
76
+ const codeBlockNode = $createCodeBlockNode({ code: "", language: match[1] ?? "", meta: "" });
77
77
  parentNode.replace(codeBlockNode);
78
- setTimeout(() => codeBlockNode.select(), 80);
78
+ setTimeout(() => {
79
+ codeBlockNode.select();
80
+ }, 80);
79
81
  }
80
82
  };
81
83
  transformers.push(codeTransformerCopy);
@@ -20,7 +20,7 @@ const SandpackEditor = ({ nodeKey, code, focusEmitter, preset }) => {
20
20
  theme: preset.sandpackTheme,
21
21
  files: {
22
22
  [preset.snippetFileName]: code,
23
- ...Object.entries(preset.files || {}).reduce(
23
+ ...Object.entries(preset.files ?? {}).reduce(
24
24
  (acc, [filePath, fileContents]) => ({ ...acc, ...{ [filePath]: { code: fileContents, readOnly: true } } }),
25
25
  {}
26
26
  )
@@ -40,8 +40,8 @@ const insertSandpack$ = Signal((r) => {
40
40
  throw new Error(`No sandpack preset found with name ${presetName}`);
41
41
  }
42
42
  return {
43
- code: preset.initialSnippetContent || "",
44
- language: preset.snippetLanguage || "jsx",
43
+ code: preset.initialSnippetContent ?? "",
44
+ language: preset.snippetLanguage ?? "jsx",
45
45
  meta: preset.meta
46
46
  };
47
47
  })
@@ -20,7 +20,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
20
20
  (e) => {
21
21
  var _a, _b, _c, _d;
22
22
  if (e.key === "ArrowDown") {
23
- const state = (_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.state;
23
+ const state = (_b = (_a = codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.state;
24
24
  if (state) {
25
25
  const docLength = state.doc.length;
26
26
  const selectionEnd = state.selection.ranges[0].to;
@@ -33,7 +33,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
33
33
  const node = $getNodeByKey(nodeKey);
34
34
  const nextSibling = node.getNextSibling();
35
35
  if (nextSibling) {
36
- (_b2 = (_a2 = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
36
+ (_b2 = (_a2 = codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
37
37
  node.selectNext();
38
38
  } else {
39
39
  node.insertAfter($createParagraphNode());
@@ -44,7 +44,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
44
44
  }
45
45
  }
46
46
  } else if (e.key === "ArrowUp") {
47
- const state = (_d = (_c = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _c.getCodemirror()) == null ? void 0 : _d.state;
47
+ const state = (_d = (_c = codeMirrorRef.current) == null ? void 0 : _c.getCodemirror()) == null ? void 0 : _d.state;
48
48
  if (state) {
49
49
  const selectionStart = state.selection.ranges[0].from;
50
50
  if (selectionStart === 0) {
@@ -56,7 +56,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
56
56
  const node = $getNodeByKey(nodeKey);
57
57
  const previousSibling = node.getPreviousSibling();
58
58
  if (previousSibling) {
59
- (_b2 = (_a2 = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
59
+ (_b2 = (_a2 = codeMirrorRef.current) == null ? void 0 : _a2.getCodemirror()) == null ? void 0 : _b2.contentDOM.blur();
60
60
  node.selectPrevious();
61
61
  }
62
62
  });
@@ -73,9 +73,9 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
73
73
  React__default.useEffect(() => {
74
74
  const codeMirror = codeMirrorRef.current;
75
75
  setTimeout(() => {
76
- var _a, _b, _c, _d;
77
- (_b = (_a = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _a.contentDOM) == null ? void 0 : _b.addEventListener("focus", onFocusHandler);
78
- (_d = (_c = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _c.contentDOM) == null ? void 0 : _d.addEventListener("keydown", onKeyDownHandler);
76
+ var _a, _b;
77
+ (_a = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _a.contentDOM.addEventListener("focus", onFocusHandler);
78
+ (_b = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _b.contentDOM.addEventListener("keydown", onKeyDownHandler);
79
79
  }, 300);
80
80
  return () => {
81
81
  var _a, _b;
@@ -86,7 +86,7 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
86
86
  React__default.useEffect(() => {
87
87
  focusEmitter.subscribe(() => {
88
88
  var _a, _b;
89
- (_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
89
+ (_b = (_a = codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
90
90
  onFocusHandler();
91
91
  });
92
92
  }, [focusEmitter, codeMirrorRef, nodeKey, onFocusHandler]);
@@ -122,67 +122,80 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
122
122
  setHighlightedCoordinates([colIndex, rowIndex]);
123
123
  }, []);
124
124
  const t = useTranslation();
125
- return /* @__PURE__ */ React__default.createElement("table", { className: styles.tableEditor, onMouseOver: onTableMouseOver, onMouseLeave: () => setHighlightedCoordinates([-1, -1]) }, /* @__PURE__ */ React__default.createElement("colgroup", null, readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
126
- const align = mdastNode.align || [];
127
- const currentColumnAlign = align[colIndex] || "left";
128
- const className = AlignToTailwindClassMap[currentColumnAlign];
129
- return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
130
- }), readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null)), readOnly || /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
131
- "button",
125
+ return /* @__PURE__ */ React__default.createElement(
126
+ "table",
132
127
  {
133
- className: styles.iconButton,
134
- type: "button",
135
- title: t("table.deleteTable", "Delete table"),
136
- onClick: (e) => {
137
- e.preventDefault();
138
- parentEditor.update(() => {
139
- lexicalTable.selectNext();
140
- lexicalTable.remove();
141
- });
128
+ className: styles.tableEditor,
129
+ onMouseOver: onTableMouseOver,
130
+ onMouseLeave: () => {
131
+ setHighlightedCoordinates([-1, -1]);
142
132
  }
143
133
  },
144
- iconComponentFor("delete_small")
145
- )), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
146
- return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
147
- ColumnEditor,
134
+ /* @__PURE__ */ React__default.createElement("colgroup", null, readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
135
+ const align = mdastNode.align ?? [];
136
+ const currentColumnAlign = align[colIndex] ?? "left";
137
+ const className = AlignToTailwindClassMap[currentColumnAlign];
138
+ return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
139
+ }), readOnly ? null : /* @__PURE__ */ React__default.createElement("col", null)),
140
+ readOnly || /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
141
+ "button",
148
142
  {
149
- ...{
150
- setActiveCellWithBoundaries,
151
- parentEditor,
152
- colIndex,
153
- highlightedCoordinates,
154
- lexicalTable,
155
- align: (mdastNode.align || [])[colIndex]
143
+ className: styles.iconButton,
144
+ type: "button",
145
+ title: t("table.deleteTable", "Delete table"),
146
+ onClick: (e) => {
147
+ e.preventDefault();
148
+ parentEditor.update(() => {
149
+ lexicalTable.selectNext();
150
+ lexicalTable.remove();
151
+ });
156
152
  }
157
- }
158
- ));
159
- }), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))), /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
160
- const CellElement = getCellType(rowIndex);
161
- return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, readOnly || /* @__PURE__ */ React__default.createElement(CellElement, { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
162
- var _a;
163
- return /* @__PURE__ */ React__default.createElement(
164
- Cell,
153
+ },
154
+ iconComponentFor("delete_small")
155
+ )), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
156
+ return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
157
+ ColumnEditor,
165
158
  {
166
- align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
167
- key: getCellKey(mdastCell),
168
- contents: mdastCell.children,
169
- setActiveCell: setActiveCellWithBoundaries,
170
159
  ...{
171
- rowIndex,
160
+ setActiveCellWithBoundaries,
161
+ parentEditor,
172
162
  colIndex,
163
+ highlightedCoordinates,
173
164
  lexicalTable,
174
- parentEditor,
175
- activeCell: readOnly ? [-1, -1] : activeCell
165
+ align: (mdastNode.align ?? [])[colIndex]
176
166
  }
177
167
  }
178
- );
179
- }), readOnly || rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, iconComponentFor("add_column"))));
180
- })), readOnly || /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, iconComponentFor("add_row"))), /* @__PURE__ */ React__default.createElement("th", null))));
168
+ ));
169
+ }), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))),
170
+ /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
171
+ const CellElement = getCellType(rowIndex);
172
+ return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, readOnly || /* @__PURE__ */ React__default.createElement(CellElement, { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
173
+ var _a;
174
+ return /* @__PURE__ */ React__default.createElement(
175
+ Cell,
176
+ {
177
+ align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
178
+ key: getCellKey(mdastCell),
179
+ contents: mdastCell.children,
180
+ setActiveCell: setActiveCellWithBoundaries,
181
+ ...{
182
+ rowIndex,
183
+ colIndex,
184
+ lexicalTable,
185
+ parentEditor,
186
+ activeCell: readOnly ? [-1, -1] : activeCell
187
+ }
188
+ }
189
+ );
190
+ }), readOnly || rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, iconComponentFor("add_column"))));
191
+ })),
192
+ readOnly || /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, iconComponentFor("add_row"))), /* @__PURE__ */ React__default.createElement("th", null)))
193
+ );
181
194
  };
182
195
  const Cell = ({ align, ...props }) => {
183
196
  const { activeCell, setActiveCell } = props;
184
197
  const isActive = Boolean(activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex);
185
- const className = AlignToTailwindClassMap[align || "left"];
198
+ const className = AlignToTailwindClassMap[align ?? "left"];
186
199
  const CellElement = getCellType(props.rowIndex);
187
200
  return /* @__PURE__ */ React__default.createElement(
188
201
  CellElement,
@@ -307,7 +320,7 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
307
320
  );
308
321
  }, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell]);
309
322
  React__default.useEffect(() => {
310
- focus && (editor == null ? void 0 : editor.focus());
323
+ focus && editor.focus();
311
324
  }, [focus, editor]);
312
325
  return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, null), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), /* @__PURE__ */ React__default.createElement(HistoryPlugin, null));
313
326
  };
@@ -358,7 +371,9 @@ const ColumnEditor = ({
358
371
  RadixPopover.PopoverContent,
359
372
  {
360
373
  className: classNames(styles.tableColumnEditorPopoverContent),
361
- onOpenAutoFocus: (e) => e.preventDefault(),
374
+ onOpenAutoFocus: (e) => {
375
+ e.preventDefault();
376
+ },
362
377
  sideOffset: 5,
363
378
  side: "top"
364
379
  },
@@ -369,7 +384,7 @@ const ColumnEditor = ({
369
384
  onValueChange: (value) => {
370
385
  setColumnAlign(colIndex, value);
371
386
  },
372
- value: align || "left",
387
+ value: align ?? "left",
373
388
  type: "single",
374
389
  "aria-label": t("table.textAlignment", "Text alignment")
375
390
  },
@@ -432,7 +447,9 @@ const RowEditor = ({
432
447
  RadixPopover.PopoverContent,
433
448
  {
434
449
  className: classNames(styles.tableColumnEditorPopoverContent),
435
- onOpenAutoFocus: (e) => e.preventDefault(),
450
+ onOpenAutoFocus: (e) => {
451
+ e.preventDefault();
452
+ },
436
453
  sideOffset: 5,
437
454
  side: "bottom"
438
455
  },
@@ -31,7 +31,7 @@ class TableNode extends DecoratorNode {
31
31
  __publicField(this, "__mdastNode");
32
32
  /** @internal */
33
33
  __publicField(this, "focusEmitter", coordinatesEmitter());
34
- this.__mdastNode = mdastNode || { type: "table", children: [] };
34
+ this.__mdastNode = mdastNode ?? { type: "table", children: [] };
35
35
  }
36
36
  /** @internal */
37
37
  static getType() {
@@ -160,7 +160,7 @@ class TableNode extends DecoratorNode {
160
160
  * Pass `undefined` to remove the focus.
161
161
  */
162
162
  select(coords) {
163
- this.focusEmitter.publish(coords || [0, 0]);
163
+ this.focusEmitter.publish(coords ?? [0, 0]);
164
164
  }
165
165
  /** @internal */
166
166
  isInline() {
@@ -41,10 +41,10 @@ const BlockTypeSelect = () => {
41
41
  case "paragraph":
42
42
  convertSelectionToNode(() => $createParagraphNode());
43
43
  break;
44
+ case "":
45
+ break;
44
46
  default:
45
- if (blockType == "")
46
- ;
47
- else if (blockType.startsWith("h")) {
47
+ if (blockType.startsWith("h")) {
48
48
  convertSelectionToNode(() => $createHeadingNode(blockType));
49
49
  } else {
50
50
  throw new Error(`Unknown block type: ${blockType}`);