@mdxeditor/editor 3.0.7 → 3.1.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.
Files changed (61) hide show
  1. package/dist/FormatConstants.js +6 -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 +133 -142
  10. package/dist/index.js +2 -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 +56 -10
  21. package/dist/plugins/core/MdastFormattingVisitor.js +66 -30
  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 +36 -39
  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 +9 -8
  61. package/dist/plugins/core/MdastInlineCodeVisitor.js +0 -27
@@ -5,7 +5,8 @@ import { $setBlocksType } from "@lexical/selection";
5
5
  import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
6
6
  import { Cell, withLatestFrom, Signal, filter, map, useCellValue, scan } from "@mdxeditor/gurx";
7
7
  import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, $getSelection, $insertNodes, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, DecoratorNode, $createParagraphNode, FOCUS_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, BLUR_COMMAND, $isRangeSelection, ParagraphNode, TextNode, createEditor } from "lexical";
8
- import { mdxJsxFromMarkdown, mdxJsxToMarkdown } from "mdast-util-mdx-jsx";
8
+ import { gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown } from "mdast-util-gfm-strikethrough";
9
+ import { mdxJsxToMarkdown, mdxJsxFromMarkdown } from "mdast-util-mdx-jsx";
9
10
  import { mdxJsx } from "micromark-extension-mdx-jsx";
10
11
  import { mdxMd } from "micromark-extension-mdx-md";
11
12
  import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
@@ -20,15 +21,15 @@ import { LexicalParagraphVisitor } from "./LexicalParagraphVisitor.js";
20
21
  import { LexicalRootVisitor } from "./LexicalRootVisitor.js";
21
22
  import { LexicalTextVisitor } from "./LexicalTextVisitor.js";
22
23
  import { MdastBreakVisitor } from "./MdastBreakVisitor.js";
23
- import { MdastFormattingVisitor } from "./MdastFormattingVisitor.js";
24
+ import { formattingVisitors } from "./MdastFormattingVisitor.js";
24
25
  import { MdastHTMLVisitor } from "./MdastHTMLVisitor.js";
25
- import { MdastInlineCodeVisitor } from "./MdastInlineCodeVisitor.js";
26
26
  import { MdastParagraphVisitor } from "./MdastParagraphVisitor.js";
27
27
  import { MdastRootVisitor } from "./MdastRootVisitor.js";
28
28
  import { MdastTextVisitor } from "./MdastTextVisitor.js";
29
29
  import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
30
30
  import { commentFromMarkdown, comment } from "../../mdastUtilHtmlComment.js";
31
31
  import { lexicalTheme } from "../../styles/lexicalTheme.js";
32
+ import { gfmStrikethrough } from "../../node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js";
32
33
  const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
33
34
  const rootEditor$ = Cell(null);
34
35
  const activeEditor$ = Cell(null);
@@ -136,7 +137,9 @@ const setMarkdown$ = Signal((r) => {
136
137
  }
137
138
  },
138
139
  {
139
- onUpdate: () => r.pub(muteChange$, false)
140
+ onUpdate: () => {
141
+ r.pub(muteChange$, false);
142
+ }
140
143
  }
141
144
  );
142
145
  }
@@ -153,7 +156,7 @@ const insertMarkdown$ = Signal((r) => {
153
156
  this.children.push(node);
154
157
  },
155
158
  getType() {
156
- return selection == null ? void 0 : selection.getNodes()[0].getType();
159
+ return selection.getNodes()[0].getType();
157
160
  }
158
161
  };
159
162
  tryImportingMarkdown(r, importPoint, markdownToInsert);
@@ -403,28 +406,25 @@ const insertDecoratorNode$ = Signal((r) => {
403
406
  theEditor.getEditorState().read(() => {
404
407
  const selection = $getSelection();
405
408
  if ($isRangeSelection(selection)) {
406
- const focusNode = selection.focus.getNode();
407
- if (focusNode !== null) {
408
- theEditor.update(() => {
409
- const node = nodeFactory();
410
- if (node.isInline()) {
411
- $insertNodes([node]);
412
- if ($isRootOrShadowRoot(node.getParentOrThrow())) {
413
- $wrapNodeInElement(node, $createParagraphNode).selectEnd();
414
- }
415
- } else {
416
- $insertNodeToNearestRoot(node);
409
+ theEditor.update(() => {
410
+ const node = nodeFactory();
411
+ if (node.isInline()) {
412
+ $insertNodes([node]);
413
+ if ($isRootOrShadowRoot(node.getParentOrThrow())) {
414
+ $wrapNodeInElement(node, $createParagraphNode).selectEnd();
417
415
  }
418
- setTimeout(() => {
419
- if ("select" in node && typeof node.select === "function") {
420
- node.select();
421
- }
422
- });
423
- });
416
+ } else {
417
+ $insertNodeToNearestRoot(node);
418
+ }
424
419
  setTimeout(() => {
425
- theEditor.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, void 0);
420
+ if ("select" in node && typeof node.select === "function") {
421
+ node.select();
422
+ }
426
423
  });
427
- }
424
+ });
425
+ setTimeout(() => {
426
+ theEditor.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, void 0);
427
+ });
428
428
  }
429
429
  });
430
430
  },
@@ -478,14 +478,7 @@ const corePlugin = realmPlugin({
478
478
  r.pubIn({
479
479
  [initialMarkdown$]: params == null ? void 0 : params.initialMarkdown.trim(),
480
480
  [iconComponentFor$]: params == null ? void 0 : params.iconComponentFor,
481
- [addImportVisitor$]: [
482
- MdastRootVisitor,
483
- MdastParagraphVisitor,
484
- MdastTextVisitor,
485
- MdastFormattingVisitor,
486
- MdastInlineCodeVisitor,
487
- MdastBreakVisitor
488
- ],
481
+ [addImportVisitor$]: [MdastRootVisitor, MdastParagraphVisitor, MdastTextVisitor, MdastBreakVisitor, ...formattingVisitors],
489
482
  [addLexicalNode$]: [ParagraphNode, TextNode, GenericHTMLNode],
490
483
  [addExportVisitor$]: [
491
484
  LexicalRootVisitor,
@@ -500,13 +493,15 @@ const corePlugin = realmPlugin({
500
493
  [autoFocus$]: params == null ? void 0 : params.autoFocus,
501
494
  [placeholder$]: params == null ? void 0 : params.placeholder,
502
495
  [readOnly$]: params == null ? void 0 : params.readOnly,
503
- [translation$]: params == null ? void 0 : params.translation
496
+ [translation$]: params == null ? void 0 : params.translation,
497
+ [addMdastExtension$]: gfmStrikethroughFromMarkdown(),
498
+ [addSyntaxExtension$]: gfmStrikethrough(),
499
+ [addToMarkdownExtension$]: [mdxJsxToMarkdown(), gfmStrikethroughToMarkdown()]
504
500
  });
505
501
  if (!(params == null ? void 0 : params.suppressHtmlProcessing)) {
506
502
  r.pubIn({
507
503
  [addMdastExtension$]: [mdxJsxFromMarkdown(), commentFromMarkdown({ ast: false })],
508
504
  [addSyntaxExtension$]: [mdxJsx(), mdxMd(), comment],
509
- [addToMarkdownExtension$]: mdxJsxToMarkdown(),
510
505
  [addImportVisitor$]: MdastHTMLVisitor
511
506
  });
512
507
  }
@@ -527,14 +522,16 @@ const corePlugin = realmPlugin({
527
522
  const autoFocusValue = params == null ? void 0 : params.autoFocus;
528
523
  if (autoFocusValue) {
529
524
  if (autoFocusValue === true) {
530
- setTimeout(() => newEditor.focus(noop, { defaultSelection: "rootStart" }));
525
+ setTimeout(() => {
526
+ newEditor.focus(noop, { defaultSelection: "rootStart" });
527
+ });
531
528
  return;
532
529
  }
533
- setTimeout(
534
- () => newEditor.focus(noop, {
530
+ setTimeout(() => {
531
+ newEditor.focus(noop, {
535
532
  defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
536
- })
537
- );
533
+ });
534
+ });
538
535
  }
539
536
  });
540
537
  r.pub(rootEditor$, newEditor);
@@ -28,7 +28,7 @@ const DownshiftAutoCompleteWithSuggestions = ({
28
28
  initialInputValue,
29
29
  onInputValueChange({ inputValue = "" }) {
30
30
  setValue(inputName, inputValue);
31
- inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
31
+ inputValue = inputValue.toLowerCase() || "";
32
32
  const matchingItems = [];
33
33
  for (const suggestion of suggestions) {
34
34
  if (suggestion.toLowerCase().includes(inputValue)) {
@@ -20,11 +20,11 @@ const insertDirective$ = Signal((r) => {
20
20
  });
21
21
  const directivesPlugin = realmPlugin({
22
22
  update: (realm, params) => {
23
- realm.pub(directiveDescriptors$, (params == null ? void 0 : params.directiveDescriptors) || []);
23
+ realm.pub(directiveDescriptors$, (params == null ? void 0 : params.directiveDescriptors) ?? []);
24
24
  },
25
25
  init: (realm, params) => {
26
26
  realm.pubIn({
27
- [directiveDescriptors$]: (params == null ? void 0 : params.directiveDescriptors) || [],
27
+ [directiveDescriptors$]: (params == null ? void 0 : params.directiveDescriptors) ?? [],
28
28
  // import
29
29
  [addMdastExtension$]: directiveFromMarkdown(),
30
30
  [addSyntaxExtension$]: directive(),
@@ -39,48 +39,65 @@ const FrontmatterEditor = ({ yaml, onChange }) => {
39
39
  setFrontmatterDialogOpen(false);
40
40
  return;
41
41
  }
42
- const yaml2 = yamlConfig2.reduce(
43
- (acc, { key, value }) => {
44
- if (key && value) {
45
- acc[key] = value;
46
- }
47
- return acc;
48
- },
49
- {}
50
- );
42
+ const yaml2 = yamlConfig2.reduce((acc, { key, value }) => {
43
+ if (key && value) {
44
+ acc[key] = value;
45
+ }
46
+ return acc;
47
+ }, {});
51
48
  onChange(YamlParser.dump(yaml2).trim());
52
49
  setFrontmatterDialogOpen(false);
53
50
  },
54
51
  [onChange, setFrontmatterDialogOpen, removeFrontmatter]
55
52
  );
56
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Dialog.Root, { open: frontmatterDialogOpen, onOpenChange: (open) => setFrontmatterDialogOpen(open) }, /* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.largeDialogContent, "data-editor-type": "frontmatter" }, /* @__PURE__ */ React__default.createElement(Dialog.Title, { className: styles.dialogTitle }, t("frontmatterEditor.title", "Edit document frontmatter")), /* @__PURE__ */ React__default.createElement(
57
- "form",
53
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
54
+ Dialog.Root,
58
55
  {
59
- onSubmit: (e) => {
60
- void handleSubmit(onSubmit)(e);
61
- e.stopPropagation();
62
- },
63
- onReset: (e) => {
64
- e.stopPropagation();
65
- setFrontmatterDialogOpen(false);
56
+ open: frontmatterDialogOpen,
57
+ onOpenChange: (open) => {
58
+ setFrontmatterDialogOpen(open);
66
59
  }
67
60
  },
68
- /* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null, t("frontmatterEditor.key", "Key")), /* @__PURE__ */ React__default.createElement("th", null, t("frontmatterEditor.value", "Value")), /* @__PURE__ */ React__default.createElement("th", null))), /* @__PURE__ */ React__default.createElement("tbody", null, fields.map((item, index) => {
69
- return /* @__PURE__ */ React__default.createElement("tr", { key: item.id }, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.key`, { required: true }), autofocusIfEmpty: true, readOnly })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.value`, { required: true }), readOnly })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("button", { type: "button", onClick: () => remove(index), className: styles.iconButton, disabled: readOnly }, iconComponentFor("delete_big"))));
70
- })), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
71
- "button",
61
+ /* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.largeDialogContent, "data-editor-type": "frontmatter" }, /* @__PURE__ */ React__default.createElement(Dialog.Title, { className: styles.dialogTitle }, t("frontmatterEditor.title", "Edit document frontmatter")), /* @__PURE__ */ React__default.createElement(
62
+ "form",
72
63
  {
73
- disabled: readOnly,
74
- className: classNames(styles.primaryButton, styles.smallButton),
75
- type: "button",
76
- onClick: () => {
77
- append({ key: "", value: "" });
64
+ onSubmit: (e) => {
65
+ void handleSubmit(onSubmit)(e);
66
+ e.stopPropagation();
67
+ },
68
+ onReset: (e) => {
69
+ e.stopPropagation();
70
+ setFrontmatterDialogOpen(false);
78
71
  }
79
72
  },
80
- t("frontmatterEditor.addEntry", "Add entry")
81
- ))))),
82
- /* @__PURE__ */ React__default.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "var(--spacing-2)" } }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, t("dialogControls.save", "Save")), /* @__PURE__ */ React__default.createElement("button", { type: "reset", className: styles.secondaryButton }, t("dialogControls.cancel", "Cancel")))
83
- ), /* @__PURE__ */ React__default.createElement(Dialog.Close, { asChild: true }, /* @__PURE__ */ React__default.createElement("button", { className: styles.dialogCloseButton, "aria-label": t("dialogControls.cancel", "Cancel") }, iconComponentFor("close")))))));
73
+ /* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null, t("frontmatterEditor.key", "Key")), /* @__PURE__ */ React__default.createElement("th", null, t("frontmatterEditor.value", "Value")), /* @__PURE__ */ React__default.createElement("th", null))), /* @__PURE__ */ React__default.createElement("tbody", null, fields.map((item, index) => {
74
+ return /* @__PURE__ */ React__default.createElement("tr", { key: item.id }, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.key`, { required: true }), autofocusIfEmpty: true, readOnly })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(TableInput, { ...register(`yamlConfig.${index}.value`, { required: true }), readOnly })), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
75
+ "button",
76
+ {
77
+ type: "button",
78
+ onClick: () => {
79
+ remove(index);
80
+ },
81
+ className: styles.iconButton,
82
+ disabled: readOnly
83
+ },
84
+ iconComponentFor("delete_big")
85
+ )));
86
+ })), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement(
87
+ "button",
88
+ {
89
+ disabled: readOnly,
90
+ className: classNames(styles.primaryButton, styles.smallButton),
91
+ type: "button",
92
+ onClick: () => {
93
+ append({ key: "", value: "" });
94
+ }
95
+ },
96
+ t("frontmatterEditor.addEntry", "Add entry")
97
+ ))))),
98
+ /* @__PURE__ */ React__default.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "var(--spacing-2)" } }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, t("dialogControls.save", "Save")), /* @__PURE__ */ React__default.createElement("button", { type: "reset", className: styles.secondaryButton }, t("dialogControls.cancel", "Cancel")))
99
+ ), /* @__PURE__ */ React__default.createElement(Dialog.Close, { asChild: true }, /* @__PURE__ */ React__default.createElement("button", { className: styles.dialogCloseButton, "aria-label": t("dialogControls.cancel", "Cancel") }, iconComponentFor("close")))))
100
+ ));
84
101
  };
85
102
  const TableInput = React__default.forwardRef(({ className, autofocusIfEmpty: _, ...props }, ref) => {
86
103
  return /* @__PURE__ */ React__default.createElement("input", { className: classNames(styles.propertyEditorInput, className), ...props, ref });
@@ -51,9 +51,11 @@ class FrontmatterNode extends DecoratorNode {
51
51
  FrontmatterEditor,
52
52
  {
53
53
  yaml: this.getYaml(),
54
- onChange: (yaml) => editor == null ? void 0 : editor.update(() => {
55
- this.setYaml(yaml);
56
- })
54
+ onChange: (yaml) => {
55
+ editor.update(() => {
56
+ this.setYaml(yaml);
57
+ });
58
+ }
57
59
  }
58
60
  );
59
61
  }
@@ -55,7 +55,7 @@ const ImageDialog = () => {
55
55
  DownshiftAutoComplete,
56
56
  {
57
57
  register,
58
- initialInputValue: state.type === "editing" ? state.initialValues.src || "" : "",
58
+ initialInputValue: state.type === "editing" ? state.initialValues.src ?? "" : "",
59
59
  inputName: "src",
60
60
  suggestions: imageAutocompleteSuggestions,
61
61
  setValue,
@@ -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);