@mdxeditor/editor 0.7.2 → 0.9.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 (28) hide show
  1. package/README.md +2 -2
  2. package/dist/{CodeBlockEditor-6e6cadb7.js → CodeBlockEditor-ce4c85ed.js} +3 -2
  3. package/dist/{CodeBlockEditor-d6235774.cjs → CodeBlockEditor-ed222322.cjs} +1 -1
  4. package/dist/FrontmatterEditor-914aa241.cjs +1 -0
  5. package/dist/{FrontmatterEditor-bcb1a0fd.js → FrontmatterEditor-e2f25a6a.js} +2 -1
  6. package/dist/{ImageEditor-c0184e9a.js → ImageEditor-ad505654.js} +2 -1
  7. package/dist/ImageEditor-c4e65554.cjs +1 -0
  8. package/dist/{JsxEditor-4ff2f120.cjs → JsxEditor-6cff258d.cjs} +1 -1
  9. package/dist/{JsxEditor-6fd46aaa.js → JsxEditor-88d55ef8.js} +1 -1
  10. package/dist/LeafDirectiveEditor-0e1328e6.cjs +1 -0
  11. package/dist/LeafDirectiveEditor-34ead530.js +59 -0
  12. package/dist/{SandpackEditor-1f2bbe22.cjs → SandpackEditor-a999ca47.cjs} +1 -1
  13. package/dist/{SandpackEditor-cdcd7e95.js → SandpackEditor-b1e22784.js} +3 -2
  14. package/dist/{SourceEditor-80e3e5dd.cjs → SourceEditor-0c46ec47.cjs} +1 -1
  15. package/dist/{SourceEditor-0399298a.js → SourceEditor-e509d0a5.js} +2 -1
  16. package/dist/{TableEditor-533f6497.js → TableEditor-44bef804.js} +1 -1
  17. package/dist/{TableEditor-982bfce3.cjs → TableEditor-ced03ce4.cjs} +1 -1
  18. package/dist/index-21fcefae.cjs +1 -0
  19. package/dist/{index-911b7e3d.js → index-ce0832cc.js} +326 -60
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +134 -13
  22. package/dist/index.js +23 -17
  23. package/dist/{useCodeMirrorRef-dc6425df.js → useCodeMirrorRef-177e9901.js} +1 -1
  24. package/dist/{useCodeMirrorRef-17daf915.cjs → useCodeMirrorRef-6cb866bd.cjs} +1 -1
  25. package/package.json +5 -2
  26. package/dist/FrontmatterEditor-535e834d.cjs +0 -1
  27. package/dist/ImageEditor-b47dff60.cjs +0 -1
  28. package/dist/index-93ab76f9.cjs +0 -1
@@ -13,7 +13,7 @@ import { ListPlugin } from "@lexical/react/LexicalListPlugin";
13
13
  import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
14
14
  import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin";
15
15
  import classNames from "classnames";
16
- import { ElementNode, $createParagraphNode, $applyNodeReplacement, DecoratorNode, createEditor, $getRoot, $isRootNode, $isParagraphNode, $isLineBreakNode, $isTextNode, $isElementNode, ParagraphNode, $createTextNode, $getSelection, $isRangeSelection, DEPRECATED_$isGridSelection, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, COMMAND_PRIORITY_LOW, PASTE_COMMAND, FOCUS_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, COMMAND_PRIORITY_HIGH, createCommand, INDENT_CONTENT_COMMAND, $getNodeByKey, $insertNodes, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, DRAGOVER_COMMAND, DROP_COMMAND, $createRangeSelection, $setSelection, $isNodeSelection } from "lexical";
16
+ import { ElementNode, $createParagraphNode, $applyNodeReplacement, DecoratorNode, createEditor, $getRoot, $isRootNode, $isParagraphNode, $isLineBreakNode, $isTextNode, $isElementNode, ParagraphNode, $createTextNode, $getSelection, $isRangeSelection, DEPRECATED_$isGridSelection, FORMAT_TEXT_COMMAND, $insertNodes, $isRootOrShadowRoot, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, COMMAND_PRIORITY_LOW, PASTE_COMMAND, FOCUS_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, COMMAND_PRIORITY_HIGH, createCommand, INDENT_CONTENT_COMMAND, $getNodeByKey, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, DRAGOVER_COMMAND, DROP_COMMAND, $createRangeSelection, $setSelection, $isNodeSelection } from "lexical";
17
17
  import * as React from "react";
18
18
  import React__default, { createContext, forwardRef, useMemo, useImperativeHandle, createElement, useCallback, useContext, useState, useEffect } from "react";
19
19
  import { CodeNode } from "@lexical/code";
@@ -30,7 +30,7 @@ import { directive } from "micromark-extension-directive";
30
30
  import { frontmatter } from "micromark-extension-frontmatter";
31
31
  import { gfmTable } from "micromark-extension-gfm-table";
32
32
  import { mdxjs } from "micromark-extension-mdxjs";
33
- import { addClassNamesToElement, $insertNodeToNearestRoot, $findMatchingParent, $getNearestNodeOfType, mergeRegister, $wrapNodeInElement } from "@lexical/utils";
33
+ import { addClassNamesToElement, $wrapNodeInElement, $insertNodeToNearestRoot, $findMatchingParent, $getNearestNodeOfType, mergeRegister } from "@lexical/utils";
34
34
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
35
35
  import { $setBlocksType, $isAtNodeEnd } from "@lexical/selection";
36
36
  import { createEmptyHistoryState, HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
@@ -45,6 +45,7 @@ import { formatLines, diffLines } from "unidiff";
45
45
  import * as RadixToolbar from "@radix-ui/react-toolbar";
46
46
  import * as Select from "@radix-ui/react-select";
47
47
  import * as Dialog from "@radix-ui/react-dialog";
48
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
48
49
  class AdmonitionNode extends ElementNode {
49
50
  constructor(kind, key) {
50
51
  super(key);
@@ -833,6 +834,60 @@ function $isTableNode(node) {
833
834
  function $createTableNode(mdastNode) {
834
835
  return new TableNode(mdastNode);
835
836
  }
837
+ class LeafDirectiveNode extends DecoratorNode {
838
+ constructor(mdastNode, key) {
839
+ super(key);
840
+ __publicField(this, "__mdastNode");
841
+ this.__mdastNode = mdastNode;
842
+ }
843
+ static getType() {
844
+ return "leafDirective";
845
+ }
846
+ static clone(node) {
847
+ return new LeafDirectiveNode(structuredClone(node.__mdastNode));
848
+ }
849
+ static importJSON(serializedNode) {
850
+ return $createLeafDirectiveNode(serializedNode.mdastNode);
851
+ }
852
+ getMdastNode() {
853
+ return this.__mdastNode;
854
+ }
855
+ exportJSON() {
856
+ return {
857
+ mdastNode: this.getMdastNode(),
858
+ type: "leafDirective",
859
+ version: 1
860
+ };
861
+ }
862
+ createDOM() {
863
+ return document.createElement("div");
864
+ }
865
+ updateDOM() {
866
+ return false;
867
+ }
868
+ setMdastNode(mdastNode) {
869
+ this.getWritable().__mdastNode = mdastNode;
870
+ }
871
+ decorate(parentEditor, {
872
+ theme: {
873
+ nodeDecoratorComponents: { LeafDirectiveEditor }
874
+ }
875
+ }) {
876
+ return /* @__PURE__ */ React__default.createElement(LeafDirectiveEditor, { leafDirective: this, mdastNode: this.getMdastNode(), parentEditor });
877
+ }
878
+ isInline() {
879
+ return false;
880
+ }
881
+ isKeyboardSelectable() {
882
+ return true;
883
+ }
884
+ }
885
+ function $createLeafDirectiveNode(mdastNode) {
886
+ return new LeafDirectiveNode(mdastNode);
887
+ }
888
+ function $isLeafDirectiveNode(node) {
889
+ return node instanceof LeafDirectiveNode;
890
+ }
836
891
  const IS_BOLD = 1;
837
892
  const IS_ITALIC = 2;
838
893
  const IS_UNDERLINE = 8;
@@ -1045,6 +1100,12 @@ const LexicalTableVisitor = {
1045
1100
  actions.appendToParent(mdastParent, lexicalNode.getMdastNode());
1046
1101
  }
1047
1102
  };
1103
+ const LexicalLeafDirectiveVisitor = {
1104
+ testLexicalNode: $isLeafDirectiveNode,
1105
+ visitLexicalNode({ actions, mdastParent, lexicalNode }) {
1106
+ actions.appendToParent(mdastParent, lexicalNode.getMdastNode());
1107
+ }
1108
+ };
1048
1109
  const JsxVisitor = {
1049
1110
  testLexicalNode: $isJsxNode,
1050
1111
  visitLexicalNode({ mdastParent, lexicalNode, actions }) {
@@ -1079,7 +1140,8 @@ const defaultLexicalVisitors = {
1079
1140
  AdmonitionVisitor,
1080
1141
  LexicalImageVisitor,
1081
1142
  JsxVisitor,
1082
- LexicalTableVisitor
1143
+ LexicalTableVisitor,
1144
+ LexicalLeafDirectiveVisitor
1083
1145
  };
1084
1146
  function isParent$1(node) {
1085
1147
  return node.children instanceof Array;
@@ -1291,6 +1353,12 @@ const MdastAdmonitionVisitor = {
1291
1353
  actions.addAndStepInto($createAdmonitionNode(mdastNode.name));
1292
1354
  }
1293
1355
  };
1356
+ const MdastLeafDirectiveVisitor = {
1357
+ testNode: "leafDirective",
1358
+ visitNode({ lexicalParent, mdastNode }) {
1359
+ lexicalParent.append($createLeafDirectiveNode(mdastNode));
1360
+ }
1361
+ };
1294
1362
  const MdastHeadingVisitor = {
1295
1363
  testNode: "heading",
1296
1364
  visitNode: function({ mdastNode, actions }) {
@@ -1436,7 +1504,8 @@ const defaultMdastVisitors = {
1436
1504
  MdastAdmonitionVisitor,
1437
1505
  MdastMdxJsEsmVisitor,
1438
1506
  MdastMdxJsxElementVisitor,
1439
- MdastTableVisitor
1507
+ MdastTableVisitor,
1508
+ MdastLeafDirectiveVisitor
1440
1509
  };
1441
1510
  function isParent(node) {
1442
1511
  return node.children instanceof Array;
@@ -1479,7 +1548,8 @@ function importMdastTreeToLexical({ root, mdastRoot, visitors }) {
1479
1548
  return visitor2.testNode(mdastNode);
1480
1549
  });
1481
1550
  if (!visitor) {
1482
- throw new Error(`no unist visitor found for ${mdastNode.type}`, {
1551
+ debugger;
1552
+ throw new Error(`no MdastImportVisitor found for ${mdastNode.type}`, {
1483
1553
  cause: mdastNode
1484
1554
  });
1485
1555
  }
@@ -1522,7 +1592,8 @@ const defaultLexicalNodes = {
1522
1592
  JsxNode,
1523
1593
  CodeNode,
1524
1594
  // this one should not be used, but markdown shortcuts complain about it
1525
- TableNode
1595
+ TableNode,
1596
+ LeafDirectiveNode
1526
1597
  };
1527
1598
  function uuidv4() {
1528
1599
  const hex = [...Array(256).keys()].map((index2) => index2.toString(16).padStart(2, "0"));
@@ -2221,6 +2292,7 @@ const [EditorSystem, EditorSystemType] = system((r) => {
2221
2292
  const activeEditorType = r.node({ type: "lexical" });
2222
2293
  const editorRootElementRef = r.node(null);
2223
2294
  const markdownParseOptions = r.node(null);
2295
+ const customLeafDirectiveEditors = r.node([]);
2224
2296
  const lexicalConvertOptions = r.node(null);
2225
2297
  const lexicalNodes = r.node([]);
2226
2298
  const imageAutocompleteSuggestions = r.node([]);
@@ -2258,16 +2330,11 @@ const [EditorSystem, EditorSystemType] = system((r) => {
2258
2330
  theEditor == null ? void 0 : theEditor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, void 0);
2259
2331
  });
2260
2332
  r.sub(r.pipe(insertImage, r.o.withLatestFrom(activeEditor)), ([src, theEditor]) => {
2261
- theEditor == null ? void 0 : theEditor.getEditorState().read(() => {
2262
- const selection = $getSelection();
2263
- if ($isRangeSelection(selection)) {
2264
- const focusNode = selection.focus.getNode();
2265
- if (focusNode !== null) {
2266
- theEditor.update(() => {
2267
- const imageNode = $createImageNode({ altText: "", src, title: "" });
2268
- $insertNodeToNearestRoot(imageNode);
2269
- });
2270
- }
2333
+ theEditor == null ? void 0 : theEditor.update(() => {
2334
+ const imageNode = $createImageNode({ altText: "", src, title: "" });
2335
+ $insertNodes([imageNode]);
2336
+ if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
2337
+ $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
2271
2338
  }
2272
2339
  });
2273
2340
  });
@@ -2423,8 +2490,11 @@ const [EditorSystem, EditorSystemType] = system((r) => {
2423
2490
  return false;
2424
2491
  }
2425
2492
  const imageUploadHandlerValue = r.getValue(imageUploadHandler);
2426
- const theImage = cbPayload[0].getAsFile();
2427
- imageUploadHandlerValue(theImage).then((url) => r.pub(insertImage, url)).catch((e) => {
2493
+ Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
2494
+ urls.forEach((url) => {
2495
+ r.pub(insertImage, url);
2496
+ });
2497
+ }).catch((e) => {
2428
2498
  throw e;
2429
2499
  });
2430
2500
  return true;
@@ -2458,7 +2528,8 @@ const [EditorSystem, EditorSystemType] = system((r) => {
2458
2528
  imageAutocompleteSuggestions,
2459
2529
  markdownSource,
2460
2530
  setMarkdown,
2461
- imageUploadHandler
2531
+ imageUploadHandler,
2532
+ customLeafDirectiveEditors
2462
2533
  };
2463
2534
  }, []);
2464
2535
  const [JsxSystem, JsxSystemType] = system((r) => {
@@ -2600,6 +2671,8 @@ const [SandpackSystem] = system(
2600
2671
  },
2601
2672
  [EditorSystemType]
2602
2673
  );
2674
+ const CAN_USE_DOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
2675
+ const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
2603
2676
  function getSelectedNode(selection) {
2604
2677
  const anchor = selection.anchor;
2605
2678
  const focus = selection.focus;
@@ -2650,8 +2723,6 @@ function getStateAsMarkdown(editor, exportParams) {
2650
2723
  });
2651
2724
  }).markdown;
2652
2725
  }
2653
- const CAN_USE_DOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
2654
- const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
2655
2726
  function getLinkNodeInSelection(selection) {
2656
2727
  const node = getSelectedNode(selection);
2657
2728
  const parent = node.getParent();
@@ -2875,7 +2946,7 @@ const [OnChangeSystem, OnChangeSystemType] = system(
2875
2946
  r.pub(markdownSource, markdown);
2876
2947
  }
2877
2948
  updateMarkdown();
2878
- return activeEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, prevEditorState, tags }) => {
2949
+ return rootEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, prevEditorState, tags }) => {
2879
2950
  if (dirtyElements.size === 0 && dirtyLeaves.size === 0 || tags.has("history-merge") || prevEditorState.isEmpty()) {
2880
2951
  return;
2881
2952
  }
@@ -2917,7 +2988,8 @@ const {
2917
2988
  viewMode: "viewMode",
2918
2989
  linkAutocompleteSuggestions: "linkAutocompleteSuggestions",
2919
2990
  imageAutocompleteSuggestions: "imageAutocompleteSuggestions",
2920
- codeBlockLanguages: "codeBlockLanguages"
2991
+ codeBlockLanguages: "codeBlockLanguages",
2992
+ customLeafDirectiveEditors: "customLeafDirectiveEditors"
2921
2993
  },
2922
2994
  events: {
2923
2995
  onChange: "onChange"
@@ -3076,9 +3148,9 @@ const styles = {
3076
3148
  imageWrapper
3077
3149
  };
3078
3150
  createCommand();
3079
- const MAX_SUGGESTIONS$1 = 20;
3151
+ const MAX_SUGGESTIONS$2 = 20;
3080
3152
  function LinkEditForm({ initialUrl, onSubmit, onCancel, linkAutocompleteSuggestions }) {
3081
- const [items, setItems] = React__default.useState(linkAutocompleteSuggestions.slice(0, MAX_SUGGESTIONS$1));
3153
+ const [items, setItems] = React__default.useState(linkAutocompleteSuggestions.slice(0, MAX_SUGGESTIONS$2));
3082
3154
  const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
3083
3155
  initialInputValue: initialUrl,
3084
3156
  onInputValueChange({ inputValue }) {
@@ -3087,7 +3159,7 @@ function LinkEditForm({ initialUrl, onSubmit, onCancel, linkAutocompleteSuggesti
3087
3159
  for (const url of linkAutocompleteSuggestions) {
3088
3160
  if (url.toLowerCase().includes(inputValue)) {
3089
3161
  matchingItems.push(url);
3090
- if (matchingItems.length >= MAX_SUGGESTIONS$1) {
3162
+ if (matchingItems.length >= MAX_SUGGESTIONS$2) {
3091
3163
  break;
3092
3164
  }
3093
3165
  }
@@ -3286,7 +3358,7 @@ const SharedHistoryPlugin = () => {
3286
3358
  return /* @__PURE__ */ React__default.createElement(HistoryPlugin, { externalHistoryState: historyState });
3287
3359
  };
3288
3360
  const index = "";
3289
- const SourceEditor = React__default.lazy(() => import("./SourceEditor-0399298a.js").then((module) => ({ default: module.SourceEditor })));
3361
+ const SourceEditor = React__default.lazy(() => import("./SourceEditor-e509d0a5.js").then((module) => ({ default: module.SourceEditor })));
3290
3362
  function DiffViewer({ oldText, newText }) {
3291
3363
  const diffText = formatLines(diffLines(oldText, newText), { context: 3 });
3292
3364
  if (diffText.trim() === "")
@@ -3429,7 +3501,124 @@ const SvgAddPhoto = (props) => /* @__PURE__ */ React.createElement("svg", { widt
3429
3501
  maskType: "alpha"
3430
3502
  }, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 24, height: 24 }, /* @__PURE__ */ React.createElement("rect", { width: 24, height: 24, fill: "#D9D9D9" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#mask0_343_38)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 21V3H14V5H5V19H19V10H21V21H3ZM17 9V7H15V5H17V3H19V5H21V7H19V9H17ZM6 17H18L14.25 12L11.25 16L9 13L6 17Z", fill: "currentColor" })));
3431
3503
  const AddPhotoIcon = SvgAddPhoto;
3432
- const ImageButton = React__default.forwardRef((props, forwardedRef) => {
3504
+ const MAX_SUGGESTIONS$1 = 20;
3505
+ const DialogButton = React__default.forwardRef(
3506
+ ({ autocompleteSuggestions = [], submitButtonTitle, dialogInputPlaceholder, onSubmit, tooltipTitle, buttonContent }, forwardedRef) => {
3507
+ const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
3508
+ const [open, setOpen] = React__default.useState(false);
3509
+ const onSubmitCallback = React__default.useCallback(
3510
+ (value) => {
3511
+ onSubmit(value);
3512
+ setOpen(false);
3513
+ },
3514
+ [onSubmit]
3515
+ );
3516
+ return /* @__PURE__ */ React__default.createElement(Dialog.Root, { open, onOpenChange: setOpen }, /* @__PURE__ */ React__default.createElement(Dialog.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { className: styles.toolbarButton, ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(InstantTooltip, { title: tooltipTitle }, buttonContent))), /* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.dialogContent }, /* @__PURE__ */ React__default.createElement(
3517
+ DialogForm,
3518
+ {
3519
+ submitButtonTitle,
3520
+ autocompleteSuggestions,
3521
+ onSubmitCallback,
3522
+ dialogInputPlaceholder
3523
+ }
3524
+ ))));
3525
+ }
3526
+ );
3527
+ const DialogForm = ({ autocompleteSuggestions, onSubmitCallback, dialogInputPlaceholder, submitButtonTitle }) => {
3528
+ const [items, setItems] = React__default.useState(autocompleteSuggestions.slice(0, MAX_SUGGESTIONS$1));
3529
+ const enableAutoComplete = autocompleteSuggestions.length > 0;
3530
+ const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
3531
+ initialInputValue: "",
3532
+ onInputValueChange({ inputValue }) {
3533
+ inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
3534
+ const matchingItems = [];
3535
+ for (const suggestion of autocompleteSuggestions) {
3536
+ if (suggestion.toLowerCase().includes(inputValue)) {
3537
+ matchingItems.push(suggestion);
3538
+ if (matchingItems.length >= MAX_SUGGESTIONS$1) {
3539
+ break;
3540
+ }
3541
+ }
3542
+ }
3543
+ setItems(matchingItems);
3544
+ },
3545
+ items,
3546
+ itemToString(item) {
3547
+ return item ?? "";
3548
+ }
3549
+ });
3550
+ const onSubmitEH = (e) => {
3551
+ e.preventDefault();
3552
+ onSubmitCallback(selectedItem || "");
3553
+ };
3554
+ const onKeyDownEH = React__default.useCallback(
3555
+ (e) => {
3556
+ var _a;
3557
+ if (e.key === "Escape") {
3558
+ (_a = e.target.form) == null ? void 0 : _a.reset();
3559
+ } else if (e.key === "Enter" && (!isOpen || items.length === 0)) {
3560
+ e.preventDefault();
3561
+ onSubmitCallback(e.target.value);
3562
+ }
3563
+ },
3564
+ [isOpen, items, onSubmitCallback]
3565
+ );
3566
+ const downshiftInputProps = getInputProps();
3567
+ const inputProps = {
3568
+ ...downshiftInputProps,
3569
+ onKeyDown: (e) => {
3570
+ onKeyDownEH(e);
3571
+ downshiftInputProps.onKeyDown(e);
3572
+ }
3573
+ };
3574
+ const dropdownIsVisible = isOpen && items.length > 0;
3575
+ return /* @__PURE__ */ React__default.createElement("form", { onSubmit: onSubmitEH, className: classNames(styles.linkDialogEditForm) }, /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogInputContainer }, /* @__PURE__ */ React__default.createElement("div", { "data-visible-dropdown": dropdownIsVisible, className: styles.linkDialogInputWrapper }, /* @__PURE__ */ React__default.createElement(
3576
+ "input",
3577
+ {
3578
+ placeholder: dialogInputPlaceholder,
3579
+ className: styles.linkDialogInput,
3580
+ ...inputProps,
3581
+ autoFocus: true,
3582
+ size: 30,
3583
+ "data-editor-dialog": true
3584
+ }
3585
+ ), enableAutoComplete && /* @__PURE__ */ React__default.createElement("button", { "aria-label": "toggle menu", type: "button", ...getToggleButtonProps() }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))), /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogAutocompleteContainer }, /* @__PURE__ */ React__default.createElement("ul", { ...getMenuProps(), "data-visible": dropdownIsVisible }, items.map((item, index2) => /* @__PURE__ */ React__default.createElement(
3586
+ "li",
3587
+ {
3588
+ "data-selected": selectedItem === item,
3589
+ "data-highlighted": highlightedIndex === index2,
3590
+ key: `${item}${index2}`,
3591
+ ...getItemProps({ item, index: index2 })
3592
+ },
3593
+ item
3594
+ ))))), /* @__PURE__ */ React__default.createElement(
3595
+ "button",
3596
+ {
3597
+ type: "submit",
3598
+ title: submitButtonTitle,
3599
+ "aria-label": submitButtonTitle,
3600
+ className: classNames(styles.actionButton, styles.primaryActionButton)
3601
+ },
3602
+ /* @__PURE__ */ React__default.createElement(CheckIcon, null)
3603
+ ), /* @__PURE__ */ React__default.createElement(Dialog.Close, { className: styles.actionButton }, /* @__PURE__ */ React__default.createElement(CloseIcon, null)));
3604
+ };
3605
+ const ImageButton = React__default.forwardRef((_, forwardedRef) => {
3606
+ const [imageAutocompleteSuggestions] = useEmitterValues("imageAutocompleteSuggestions");
3607
+ const insertImage = usePublisher("insertImage");
3608
+ return /* @__PURE__ */ React__default.createElement(
3609
+ DialogButton,
3610
+ {
3611
+ ref: forwardedRef,
3612
+ submitButtonTitle: "Insert Image",
3613
+ dialogInputPlaceholder: "Paste or select image URL",
3614
+ tooltipTitle: "Insert image",
3615
+ onSubmit: insertImage,
3616
+ buttonContent: /* @__PURE__ */ React__default.createElement(AddPhotoIcon, null),
3617
+ autocompleteSuggestions: imageAutocompleteSuggestions
3618
+ }
3619
+ );
3620
+ });
3621
+ React__default.forwardRef((props, forwardedRef) => {
3433
3622
  const [editorRootElementRef, imageAutocompleteSuggestions] = useEmitterValues("editorRootElementRef", "imageAutocompleteSuggestions");
3434
3623
  const [open, setOpen] = React__default.useState(false);
3435
3624
  const insertImage = usePublisher("insertImage");
@@ -3442,7 +3631,6 @@ const ImageButton = React__default.forwardRef((props, forwardedRef) => {
3442
3631
  );
3443
3632
  return /* @__PURE__ */ React__default.createElement(Dialog.Root, { open, onOpenChange: setOpen }, /* @__PURE__ */ React__default.createElement(Dialog.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { className: styles.toolbarButton, ...props, ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(InstantTooltip, { title: "Insert image" }, /* @__PURE__ */ React__default.createElement(AddPhotoIcon, null)))), /* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.dialogContent }, /* @__PURE__ */ React__default.createElement(ImageForm, { initialUrl: "", onSubmit, imageAutocompleteSuggestions }))));
3444
3633
  });
3445
- createCommand();
3446
3634
  const MAX_SUGGESTIONS = 20;
3447
3635
  const ImageForm = ({ initialUrl, onSubmit, imageAutocompleteSuggestions }) => {
3448
3636
  const [items, setItems] = React__default.useState(imageAutocompleteSuggestions.slice(0, MAX_SUGGESTIONS));
@@ -3646,9 +3834,10 @@ const ToolbarComponents = {
3646
3834
  BlockTypeSelect,
3647
3835
  BoldItalicUnderlineButtons,
3648
3836
  CodeBlockButton,
3837
+ CodeFormattingButton,
3649
3838
  FrontmatterButton,
3650
3839
  GroupGroup,
3651
- HorizontalRuleIcon,
3840
+ HorizontalRuleButton,
3652
3841
  LinkButton,
3653
3842
  ListButtons,
3654
3843
  SandpackButton,
@@ -3658,7 +3847,8 @@ const ToolbarComponents = {
3658
3847
  ToggleSingleGroupWithItem,
3659
3848
  ToolbarButton,
3660
3849
  ToolbarSeparator,
3661
- ImageButton
3850
+ ImageButton,
3851
+ DialogButton
3662
3852
  };
3663
3853
  const ToolbarPlugin = () => {
3664
3854
  const [activeEditorType, viewMode] = useEmitterValues("activeEditorType", "viewMode");
@@ -3797,10 +3987,12 @@ function onDrop(event, editor, imageUploadHandler) {
3797
3987
  cbPayload = cbPayload.filter((i) => /image/.test(i.type));
3798
3988
  if (cbPayload.length > 0) {
3799
3989
  event.preventDefault();
3800
- imageUploadHandler(cbPayload[0].getAsFile()).then((url) => {
3801
- editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
3802
- src: url,
3803
- altText: ""
3990
+ Promise.all(cbPayload.map((image) => imageUploadHandler(image.getAsFile()))).then((urls) => {
3991
+ urls.forEach((url) => {
3992
+ editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
3993
+ src: url,
3994
+ altText: ""
3995
+ });
3804
3996
  });
3805
3997
  }).catch((e) => {
3806
3998
  throw e;
@@ -3869,24 +4061,28 @@ function getDragSelection(event) {
3869
4061
  return range;
3870
4062
  }
3871
4063
  const LazyFrontmatterEditor = React__default.lazy(
3872
- () => import("./FrontmatterEditor-bcb1a0fd.js").then((module) => ({ default: module.FrontmatterEditor }))
4064
+ () => import("./FrontmatterEditor-e2f25a6a.js").then((module) => ({ default: module.FrontmatterEditor }))
3873
4065
  );
3874
- const LazyJsxEditor = React__default.lazy(() => import("./JsxEditor-6fd46aaa.js").then((module) => ({ default: module.JsxEditor })));
4066
+ const LazyJsxEditor = React__default.lazy(() => import("./JsxEditor-88d55ef8.js").then((module) => ({ default: module.JsxEditor })));
3875
4067
  const LazySandpackEditor = React__default.lazy(
3876
- () => import("./SandpackEditor-cdcd7e95.js").then((module) => ({ default: module.SandpackEditor }))
4068
+ () => import("./SandpackEditor-b1e22784.js").then((module) => ({ default: module.SandpackEditor }))
3877
4069
  );
3878
4070
  const LazyCodeBlockEditor = React__default.lazy(
3879
- () => import("./CodeBlockEditor-6e6cadb7.js").then((module) => ({ default: module.CodeBlockEditor }))
4071
+ () => import("./CodeBlockEditor-ce4c85ed.js").then((module) => ({ default: module.CodeBlockEditor }))
4072
+ );
4073
+ const LazyTableEditor = React__default.lazy(() => import("./TableEditor-44bef804.js").then((module) => ({ default: module.TableEditor })));
4074
+ const LazyImageEditor = React__default.lazy(() => import("./ImageEditor-ad505654.js").then((module) => ({ default: module.ImageEditor })));
4075
+ const LazyLeafDirectiveEditor = React__default.lazy(
4076
+ () => import("./LeafDirectiveEditor-34ead530.js").then((module) => ({ default: module.LeafDirectiveEditor }))
3880
4077
  );
3881
- const LazyTableEditor = React__default.lazy(() => import("./TableEditor-533f6497.js").then((module) => ({ default: module.TableEditor })));
3882
- const LazyImageEditor = React__default.lazy(() => import("./ImageEditor-c0184e9a.js").then((module) => ({ default: module.ImageEditor })));
3883
4078
  const defaultNodeDecorators = {
3884
4079
  FrontmatterEditor: LazyFrontmatterEditor,
3885
4080
  JsxEditor: LazyJsxEditor,
3886
4081
  SandpackEditor: LazySandpackEditor,
3887
4082
  CodeBlockEditor: LazyCodeBlockEditor,
3888
4083
  TableEditor: LazyTableEditor,
3889
- ImageEditor: LazyImageEditor
4084
+ ImageEditor: LazyImageEditor,
4085
+ LeafDirectiveEditor: LazyLeafDirectiveEditor
3890
4086
  };
3891
4087
  const defaultToolbarComponents = [
3892
4088
  BoldItalicUnderlineButtons,
@@ -3967,7 +4163,8 @@ const MDXEditor = React__default.forwardRef(
3967
4163
  toMarkdownOptions = defaultToMarkdownOptions,
3968
4164
  visitors: exportVisitors = Object.values(defaultLexicalVisitors)
3969
4165
  } = {},
3970
- lexicalNodes = Object.values(defaultLexicalNodes)
4166
+ lexicalNodes = Object.values(defaultLexicalNodes),
4167
+ customLeafDirectiveEditors = []
3971
4168
  }, ref) => {
3972
4169
  const editorRootElementRef = React__default.useRef(null);
3973
4170
  return /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.editorRoot, styles.editorWrapper, className), ref: editorRootElementRef }, /* @__PURE__ */ React__default.createElement(
@@ -4018,7 +4215,8 @@ const MDXEditor = React__default.forwardRef(
4018
4215
  toMarkdownExtensions
4019
4216
  },
4020
4217
  lexicalNodes,
4021
- imageUploadHandler
4218
+ imageUploadHandler,
4219
+ customLeafDirectiveEditors
4022
4220
  },
4023
4221
  /* @__PURE__ */ React__default.createElement(ToolbarPlugin, null),
4024
4222
  /* @__PURE__ */ React__default.createElement(ViewModeToggler, null, /* @__PURE__ */ React__default.createElement(
@@ -4060,6 +4258,68 @@ const MDXMethods = ({ mdxRef }) => {
4060
4258
  );
4061
4259
  return null;
4062
4260
  };
4261
+ const NestedEditorsContext = React__default.createContext(void 0);
4262
+ const useNestedEditorContext = () => {
4263
+ const context = React__default.useContext(NestedEditorsContext);
4264
+ if (!context) {
4265
+ throw new Error("useNestedEditor must be used within a NestedEditorsProvider");
4266
+ }
4267
+ return context;
4268
+ };
4269
+ function useMdastNodeUpdater() {
4270
+ const { parentEditor, lexicalNode } = useNestedEditorContext();
4271
+ return function updateMdastNode(node) {
4272
+ parentEditor.update(() => {
4273
+ lexicalNode.setMdastNode(node);
4274
+ });
4275
+ };
4276
+ }
4277
+ const NestedEditor = function(props) {
4278
+ const { getContent, getUpdatedMdastNode, contentEditableProps } = props;
4279
+ const { mdastNode } = useNestedEditorContext();
4280
+ const updateMdastNode = useMdastNodeUpdater();
4281
+ const [markdownParseOptions, lexicalConvertOptions, jsxComponentDescriptors, lexicalNodes] = useEmitterValues(
4282
+ "markdownParseOptions",
4283
+ "lexicalConvertOptions",
4284
+ "jsxComponentDescriptors",
4285
+ "lexicalNodes"
4286
+ );
4287
+ const [editor] = React__default.useState(() => {
4288
+ const editor2 = createEditor({
4289
+ nodes: lexicalNodes,
4290
+ theme
4291
+ });
4292
+ editor2.update(() => {
4293
+ importMdastTreeToLexical({
4294
+ root: $getRoot(),
4295
+ mdastRoot: { type: "root", children: [{ type: "paragraph", children: getContent(mdastNode) }] },
4296
+ visitors: markdownParseOptions.visitors
4297
+ });
4298
+ });
4299
+ return editor2;
4300
+ });
4301
+ React__default.useEffect(() => {
4302
+ return editor.registerUpdateListener(({ editorState }) => {
4303
+ editorState.read(() => {
4304
+ const mdast = exportLexicalTreeToMdast({
4305
+ root: $getRoot(),
4306
+ jsxComponentDescriptors,
4307
+ ...lexicalConvertOptions
4308
+ });
4309
+ const rootParagraph = mdast.children[0];
4310
+ updateMdastNode(getUpdatedMdastNode(mdastNode, rootParagraph.children));
4311
+ });
4312
+ });
4313
+ }, [editor, getUpdatedMdastNode, jsxComponentDescriptors, lexicalConvertOptions, mdastNode, updateMdastNode]);
4314
+ return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(
4315
+ RichTextPlugin,
4316
+ {
4317
+ contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { ...contentEditableProps }),
4318
+ placeholder: /* @__PURE__ */ React__default.createElement("div", null),
4319
+ ErrorBoundary: LexicalErrorBoundary
4320
+ }
4321
+ ), /* @__PURE__ */ React__default.createElement(SharedHistoryPlugin, null));
4322
+ };
4063
4323
  export {
4064
4324
  $isImageNode as $,
4065
4325
  AdmonitionNode as A,
@@ -4067,29 +4327,35 @@ export {
4067
4327
  FrontmatterNode as F,
4068
4328
  ImageNode as I,
4069
4329
  JsxNode as J,
4330
+ LeafDirectiveNode as L,
4070
4331
  MDXEditor as M,
4332
+ NestedEditorsContext as N,
4071
4333
  SharedHistoryPlugin as S,
4072
4334
  ToolbarComponents as T,
4073
4335
  usePublisher as a,
4074
- $createAdmonitionNode as b,
4075
- $isAdmonitionNode as c,
4076
- $createCodeBlockNode as d,
4336
+ NestedEditor as b,
4337
+ useMdastNodeUpdater as c,
4338
+ $createAdmonitionNode as d,
4077
4339
  exportLexicalTreeToMdast as e,
4078
- $isCodeBlockNode as f,
4079
- $createFrontmatterNode as g,
4080
- $isFrontmatterNode as h,
4340
+ $isAdmonitionNode as f,
4341
+ $createCodeBlockNode as g,
4342
+ $isCodeBlockNode as h,
4081
4343
  importMdastTreeToLexical as i,
4082
- $createImageNode as j,
4083
- $createJsxNode as k,
4084
- $isJsxNode as l,
4085
- SandpackNode as m,
4086
- $createSandpackNode as n,
4087
- $isSandpackNode as o,
4088
- TableNode as p,
4089
- $isTableNode as q,
4090
- $createTableNode as r,
4344
+ $createFrontmatterNode as j,
4345
+ $isFrontmatterNode as k,
4346
+ $createImageNode as l,
4347
+ $createJsxNode as m,
4348
+ $isJsxNode as n,
4349
+ SandpackNode as o,
4350
+ $createSandpackNode as p,
4351
+ $isSandpackNode as q,
4352
+ TableNode as r,
4091
4353
  styles as s,
4092
4354
  theme as t,
4093
4355
  useEmitterValues as u,
4094
- defaultMdxOptionValues as v
4356
+ $isTableNode as v,
4357
+ $createTableNode as w,
4358
+ $createLeafDirectiveNode as x,
4359
+ $isLeafDirectiveNode as y,
4360
+ defaultMdxOptionValues as z
4095
4361
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-93ab76f9.cjs"),r=require("lexical");require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalContentEditable"),require("@lexical/react/LexicalErrorBoundary"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalRichTextPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("classnames"),require("react"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/react/LexicalComposerContext"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-popover"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-toolbar"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog"),exports.$createAdmonitionNode=e.$createAdmonitionNode,exports.$createCodeBlockNode=e.$createCodeBlockNode,exports.$createFrontmatterNode=e.$createFrontmatterNode,exports.$createImageNode=e.$createImageNode,exports.$createJsxNode=e.$createJsxNode,exports.$createSandpackNode=e.$createSandpackNode,exports.$createTableNode=e.$createTableNode,exports.$isAdmonitionNode=e.$isAdmonitionNode,exports.$isCodeBlockNode=e.$isCodeBlockNode,exports.$isFrontmatterNode=e.$isFrontmatterNode,exports.$isImageNode=e.$isImageNode,exports.$isJsxNode=e.$isJsxNode,exports.$isSandpackNode=e.$isSandpackNode,exports.$isTableNode=e.$isTableNode,exports.AdmonitionNode=e.AdmonitionNode,exports.CodeBlockNode=e.CodeBlockNode,exports.FrontmatterNode=e.FrontmatterNode,exports.ImageNode=e.ImageNode,exports.JsxNode=e.JsxNode,exports.MDXEditor=e.MDXEditor,exports.SandpackNode=e.SandpackNode,exports.TableNode=e.TableNode,exports.ToolbarComponents=e.ToolbarComponents,exports.defaultMdxOptionValues=e.defaultMdxOptionValues,Object.defineProperty(exports,"AdmonitionKind",{enumerable:!0,get:()=>r.AdmonitionKind});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-21fcefae.cjs"),r=require("lexical");require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalContentEditable"),require("@lexical/react/LexicalErrorBoundary"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalRichTextPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("classnames"),require("react"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/react/LexicalComposerContext"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-popover"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-toolbar"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog"),require("@lexical/react/LexicalNestedComposer"),exports.$createAdmonitionNode=e.$createAdmonitionNode,exports.$createCodeBlockNode=e.$createCodeBlockNode,exports.$createFrontmatterNode=e.$createFrontmatterNode,exports.$createImageNode=e.$createImageNode,exports.$createJsxNode=e.$createJsxNode,exports.$createLeafDirectiveNode=e.$createLeafDirectiveNode,exports.$createSandpackNode=e.$createSandpackNode,exports.$createTableNode=e.$createTableNode,exports.$isAdmonitionNode=e.$isAdmonitionNode,exports.$isCodeBlockNode=e.$isCodeBlockNode,exports.$isFrontmatterNode=e.$isFrontmatterNode,exports.$isImageNode=e.$isImageNode,exports.$isJsxNode=e.$isJsxNode,exports.$isLeafDirectiveNode=e.$isLeafDirectiveNode,exports.$isSandpackNode=e.$isSandpackNode,exports.$isTableNode=e.$isTableNode,exports.AdmonitionNode=e.AdmonitionNode,exports.CodeBlockNode=e.CodeBlockNode,exports.FrontmatterNode=e.FrontmatterNode,exports.ImageNode=e.ImageNode,exports.JsxNode=e.JsxNode,exports.LeafDirectiveNode=e.LeafDirectiveNode,exports.MDXEditor=e.MDXEditor,exports.NestedEditor=e.NestedEditor,exports.SandpackNode=e.SandpackNode,exports.TableNode=e.TableNode,exports.ToolbarComponents=e.ToolbarComponents,exports.defaultMdxOptionValues=e.defaultMdxOptionValues,exports.useMdastNodeUpdater=e.useMdastNodeUpdater,Object.defineProperty(exports,"AdmonitionKind",{enumerable:!0,get:()=>r.AdmonitionKind});