@mdxeditor/editor 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -229,7 +229,8 @@ class CodeBlockNode extends DecoratorNode {
229
229
  );
230
230
  }
231
231
  }
232
- function $createCodeBlockNode({ code: code2, language, meta }) {
232
+ function $createCodeBlockNode(options) {
233
+ const { code: code2, language, meta } = options;
233
234
  return new CodeBlockNode(code2, language, meta);
234
235
  }
235
236
  function $isCodeBlockNode(node) {
@@ -249,9 +250,7 @@ class FrontmatterNode extends DecoratorNode {
249
250
  }
250
251
  static importJSON(serializedNode) {
251
252
  const { yaml } = serializedNode;
252
- const node = $createFrontmatterNode({
253
- yaml
254
- });
253
+ const node = $createFrontmatterNode(yaml);
255
254
  return node;
256
255
  }
257
256
  exportJSON() {
@@ -292,7 +291,7 @@ class FrontmatterNode extends DecoratorNode {
292
291
  );
293
292
  }
294
293
  }
295
- function $createFrontmatterNode({ yaml }) {
294
+ function $createFrontmatterNode(yaml) {
296
295
  return new FrontmatterNode(yaml);
297
296
  }
298
297
  function $isFrontmatterNode(node) {
@@ -357,7 +356,6 @@ class ImageNode extends DecoratorNode {
357
356
  version: 1
358
357
  };
359
358
  }
360
- // View
361
359
  createDOM(config) {
362
360
  const span = document.createElement("span");
363
361
  const theme2 = config.theme;
@@ -386,7 +384,8 @@ class ImageNode extends DecoratorNode {
386
384
  return /* @__PURE__ */ React__default.createElement("img", { title: this.__title, src: this.__src, alt: this.__altText });
387
385
  }
388
386
  }
389
- function $createImageNode({ altText, title, src, key }) {
387
+ function $createImageNode(options) {
388
+ const { altText, title, src, key } = options;
390
389
  return new ImageNode(src, altText, title, key);
391
390
  }
392
391
  function $isImageNode(node) {
@@ -593,8 +592,8 @@ class JsxNode extends DecoratorNode {
593
592
  );
594
593
  }
595
594
  }
596
- function $createJsxNode(payload) {
597
- return new JsxNode(payload);
595
+ function $createJsxNode(options) {
596
+ return new JsxNode(options);
598
597
  }
599
598
  function $isJsxNode(node) {
600
599
  return node instanceof JsxNode;
@@ -695,7 +694,8 @@ class SandpackNode extends DecoratorNode {
695
694
  );
696
695
  }
697
696
  }
698
- function $createSandpackNode({ code: code2, language, meta }) {
697
+ function $createSandpackNode(options) {
698
+ const { code: code2, language, meta } = options;
699
699
  return new SandpackNode(code2, language, meta);
700
700
  }
701
701
  function $isSandpackNode(node) {
@@ -1391,11 +1391,7 @@ const MdastImageVisitor = {
1391
1391
  const MdastFrontmatterVisitor = {
1392
1392
  testNode: "yaml",
1393
1393
  visitNode({ mdastNode, actions }) {
1394
- actions.addAndStepInto(
1395
- $createFrontmatterNode({
1396
- yaml: mdastNode.value
1397
- })
1398
- );
1394
+ actions.addAndStepInto($createFrontmatterNode(mdastNode.value));
1399
1395
  }
1400
1396
  };
1401
1397
  const MdastMdxJsEsmVisitor = {
@@ -2264,7 +2260,7 @@ const [EditorSystem, EditorSystemType] = system((r) => {
2264
2260
  theEditor == null ? void 0 : theEditor.update(() => {
2265
2261
  const firstItem = $getRoot().getFirstChild();
2266
2262
  if (!$isFrontmatterNode(firstItem)) {
2267
- const fmNode = $createFrontmatterNode({ yaml: '"": ""' });
2263
+ const fmNode = $createFrontmatterNode('"": ""');
2268
2264
  if (firstItem) {
2269
2265
  firstItem.insertBefore(fmNode);
2270
2266
  } else {
@@ -2497,9 +2493,17 @@ const defaultSandpackConfig$1 = {
2497
2493
  }
2498
2494
  ]
2499
2495
  };
2496
+ const defaultCodeBlockLanguages = {
2497
+ js: "JavaScript",
2498
+ ts: "TypeScript",
2499
+ tsx: "TypeScript (React)",
2500
+ jsx: "JavaScript (React)",
2501
+ css: "CSS"
2502
+ };
2500
2503
  const [SandpackSystem] = system(
2501
2504
  (r, [{ activeEditor, activeEditorType, createEditorSubscription }]) => {
2502
2505
  const sandpackConfig = r.node(defaultSandpackConfig$1);
2506
+ const codeBlockLanguages = r.node(defaultCodeBlockLanguages);
2503
2507
  const insertSandpack = r.node();
2504
2508
  const insertCodeBlock = r.node();
2505
2509
  r.pub(createEditorSubscription, (editor) => {
@@ -2555,6 +2559,7 @@ const [SandpackSystem] = system(
2555
2559
  });
2556
2560
  });
2557
2561
  return {
2562
+ codeBlockLanguages,
2558
2563
  insertSandpack,
2559
2564
  insertCodeBlock,
2560
2565
  sandpackConfig
@@ -2875,7 +2880,8 @@ const {
2875
2880
  editorRootElementRef: "editorRootElementRef",
2876
2881
  viewMode: "viewMode",
2877
2882
  linkAutocompleteSuggestions: "linkAutocompleteSuggestions",
2878
- imageAutocompleteSuggestions: "imageAutocompleteSuggestions"
2883
+ imageAutocompleteSuggestions: "imageAutocompleteSuggestions",
2884
+ codeBlockLanguages: "codeBlockLanguages"
2879
2885
  },
2880
2886
  events: {
2881
2887
  onChange: "onChange"
@@ -2919,57 +2925,59 @@ const SvgArrowDropDown$1 = (props) => /* @__PURE__ */ React.createElement("svg",
2919
2925
  maskType: "alpha"
2920
2926
  } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m12 15-5-5h10l-5 5Z" })));
2921
2927
  const DropDownIcon = SvgArrowDropDown$1;
2922
- const editorRoot = "_editorRoot_1nlu3_43";
2923
- const editorWrapper = "_editorWrapper_1nlu3_121";
2924
- const nestedListItem = "_nestedListItem_1nlu3_125";
2925
- const toolbarRoot = "_toolbarRoot_1nlu3_129";
2926
- const toolbarModeSwitch = "_toolbarModeSwitch_1nlu3_150";
2927
- const toolbarToggleItem = "_toolbarToggleItem_1nlu3_159";
2928
- const toolbarGroupOfGroups = "_toolbarGroupOfGroups_1nlu3_169";
2929
- const toolbarToggleSingleGroup = "_toolbarToggleSingleGroup_1nlu3_173";
2930
- const toolbarButton = "_toolbarButton_1nlu3_187";
2931
- const toolbarNodeKindSelectContainer = "_toolbarNodeKindSelectContainer_1nlu3_216";
2932
- const toolbarButtonDropdownContainer = "_toolbarButtonDropdownContainer_1nlu3_217";
2933
- const toolbarNodeKindSelectTrigger = "_toolbarNodeKindSelectTrigger_1nlu3_230";
2934
- const toolbarButtonSelectTrigger = "_toolbarButtonSelectTrigger_1nlu3_231";
2935
- const toolbarNodeKindSelectItem = "_toolbarNodeKindSelectItem_1nlu3_264";
2936
- const toolbarNodeKindSelectDropdownArrow = "_toolbarNodeKindSelectDropdownArrow_1nlu3_287";
2937
- const contentEditable = "_contentEditable_1nlu3_291";
2938
- const sandpackWrapper = "_sandpackWrapper_1nlu3_299";
2939
- const frontmatterWrapper = "_frontmatterWrapper_1nlu3_303";
2940
- const frontmatterToggleButton = "_frontmatterToggleButton_1nlu3_313";
2941
- const frontmatterEditorTable = "_frontmatterEditorTable_1nlu3_321";
2942
- const iconButton = "_iconButton_1nlu3_339";
2943
- const frontmatterInput = "_frontmatterInput_1nlu3_345";
2944
- const primaryButton = "_primaryButton_1nlu3_360";
2945
- const linkDialogEditForm = "_linkDialogEditForm_1nlu3_370";
2946
- const linkDialogInputContainer = "_linkDialogInputContainer_1nlu3_376";
2947
- const linkDialogInputWrapper = "_linkDialogInputWrapper_1nlu3_382";
2948
- const linkDialogInput = "_linkDialogInput_1nlu3_376";
2949
- const linkDialogAutocompleteContainer = "_linkDialogAutocompleteContainer_1nlu3_412";
2950
- const linkDialogAnchor = "_linkDialogAnchor_1nlu3_457";
2951
- const linkDialogPopoverContent = "_linkDialogPopoverContent_1nlu3_471";
2952
- const tableColumnEditorPopoverContent = "_tableColumnEditorPopoverContent_1nlu3_471";
2953
- const dialogContent = "_dialogContent_1nlu3_471";
2954
- const linkDialogPreviewAnchor = "_linkDialogPreviewAnchor_1nlu3_485";
2955
- const tooltipContent = "_tooltipContent_1nlu3_507";
2956
- const actionButton = "_actionButton_1nlu3_519";
2957
- const primaryActionButton = "_primaryActionButton_1nlu3_525";
2958
- const tableEditor = "_tableEditor_1nlu3_534";
2959
- const toolCell = "_toolCell_1nlu3_545";
2960
- const tableColumnEditorTrigger = "_tableColumnEditorTrigger_1nlu3_562";
2961
- const tableRowEditorTrigger = "_tableRowEditorTrigger_1nlu3_562";
2962
- const addRowButton = "_addRowButton_1nlu3_562";
2963
- const addColumnButton = "_addColumnButton_1nlu3_562";
2964
- const tableColumnEditorToolbar = "_tableColumnEditorToolbar_1nlu3_596";
2965
- const toggleGroupRoot = "_toggleGroupRoot_1nlu3_608";
2966
- const tableToolsColumn = "_tableToolsColumn_1nlu3_625";
2967
- const leftAlignedCell = "_leftAlignedCell_1nlu3_633";
2968
- const rightAlignedCell = "_rightAlignedCell_1nlu3_637";
2969
- const centeredCell = "_centeredCell_1nlu3_641";
2970
- const dialogOverlay = "_dialogOverlay_1nlu3_669";
2971
- const overlayShow = "_overlayShow_1nlu3_1";
2972
- const contentShow = "_contentShow_1nlu3_1";
2928
+ const editorRoot = "_editorRoot_1bxeh_43";
2929
+ const editorWrapper = "_editorWrapper_1bxeh_121";
2930
+ const nestedListItem = "_nestedListItem_1bxeh_125";
2931
+ const toolbarRoot = "_toolbarRoot_1bxeh_129";
2932
+ const toolbarModeSwitch = "_toolbarModeSwitch_1bxeh_150";
2933
+ const toolbarToggleItem = "_toolbarToggleItem_1bxeh_159";
2934
+ const toolbarGroupOfGroups = "_toolbarGroupOfGroups_1bxeh_169";
2935
+ const toolbarToggleSingleGroup = "_toolbarToggleSingleGroup_1bxeh_173";
2936
+ const toolbarButton = "_toolbarButton_1bxeh_187";
2937
+ const toolbarNodeKindSelectContainer = "_toolbarNodeKindSelectContainer_1bxeh_216";
2938
+ const toolbarButtonDropdownContainer = "_toolbarButtonDropdownContainer_1bxeh_217";
2939
+ const toolbarCodeBlockLanguageSelectContent = "_toolbarCodeBlockLanguageSelectContent_1bxeh_218";
2940
+ const toolbarNodeKindSelectTrigger = "_toolbarNodeKindSelectTrigger_1bxeh_232";
2941
+ const toolbarButtonSelectTrigger = "_toolbarButtonSelectTrigger_1bxeh_233";
2942
+ const toolbarCodeBlockLanguageSelectTrigger = "_toolbarCodeBlockLanguageSelectTrigger_1bxeh_266";
2943
+ const toolbarNodeKindSelectItem = "_toolbarNodeKindSelectItem_1bxeh_272";
2944
+ const toolbarNodeKindSelectDropdownArrow = "_toolbarNodeKindSelectDropdownArrow_1bxeh_295";
2945
+ const contentEditable = "_contentEditable_1bxeh_299";
2946
+ const sandpackWrapper = "_sandpackWrapper_1bxeh_307";
2947
+ const frontmatterWrapper = "_frontmatterWrapper_1bxeh_311";
2948
+ const frontmatterToggleButton = "_frontmatterToggleButton_1bxeh_321";
2949
+ const frontmatterEditorTable = "_frontmatterEditorTable_1bxeh_329";
2950
+ const iconButton = "_iconButton_1bxeh_347";
2951
+ const frontmatterInput = "_frontmatterInput_1bxeh_353";
2952
+ const primaryButton = "_primaryButton_1bxeh_368";
2953
+ const linkDialogEditForm = "_linkDialogEditForm_1bxeh_378";
2954
+ const linkDialogInputContainer = "_linkDialogInputContainer_1bxeh_384";
2955
+ const linkDialogInputWrapper = "_linkDialogInputWrapper_1bxeh_390";
2956
+ const linkDialogInput = "_linkDialogInput_1bxeh_384";
2957
+ const linkDialogAutocompleteContainer = "_linkDialogAutocompleteContainer_1bxeh_420";
2958
+ const linkDialogAnchor = "_linkDialogAnchor_1bxeh_465";
2959
+ const linkDialogPopoverContent = "_linkDialogPopoverContent_1bxeh_479";
2960
+ const tableColumnEditorPopoverContent = "_tableColumnEditorPopoverContent_1bxeh_479";
2961
+ const dialogContent = "_dialogContent_1bxeh_479";
2962
+ const linkDialogPreviewAnchor = "_linkDialogPreviewAnchor_1bxeh_493";
2963
+ const tooltipContent = "_tooltipContent_1bxeh_515";
2964
+ const actionButton = "_actionButton_1bxeh_527";
2965
+ const primaryActionButton = "_primaryActionButton_1bxeh_533";
2966
+ const tableEditor = "_tableEditor_1bxeh_542";
2967
+ const toolCell = "_toolCell_1bxeh_553";
2968
+ const tableColumnEditorTrigger = "_tableColumnEditorTrigger_1bxeh_570";
2969
+ const tableRowEditorTrigger = "_tableRowEditorTrigger_1bxeh_570";
2970
+ const addRowButton = "_addRowButton_1bxeh_570";
2971
+ const addColumnButton = "_addColumnButton_1bxeh_570";
2972
+ const tableColumnEditorToolbar = "_tableColumnEditorToolbar_1bxeh_604";
2973
+ const toggleGroupRoot = "_toggleGroupRoot_1bxeh_616";
2974
+ const tableToolsColumn = "_tableToolsColumn_1bxeh_633";
2975
+ const leftAlignedCell = "_leftAlignedCell_1bxeh_641";
2976
+ const rightAlignedCell = "_rightAlignedCell_1bxeh_645";
2977
+ const centeredCell = "_centeredCell_1bxeh_649";
2978
+ const dialogOverlay = "_dialogOverlay_1bxeh_677";
2979
+ const overlayShow = "_overlayShow_1bxeh_1";
2980
+ const contentShow = "_contentShow_1bxeh_1";
2973
2981
  const styles = {
2974
2982
  editorRoot,
2975
2983
  editorWrapper,
@@ -2982,8 +2990,10 @@ const styles = {
2982
2990
  toolbarButton,
2983
2991
  toolbarNodeKindSelectContainer,
2984
2992
  toolbarButtonDropdownContainer,
2993
+ toolbarCodeBlockLanguageSelectContent,
2985
2994
  toolbarNodeKindSelectTrigger,
2986
2995
  toolbarButtonSelectTrigger,
2996
+ toolbarCodeBlockLanguageSelectTrigger,
2987
2997
  toolbarNodeKindSelectItem,
2988
2998
  toolbarNodeKindSelectDropdownArrow,
2989
2999
  contentEditable,
@@ -3940,8 +3950,8 @@ const SelectItem = React__default.forwardRef(
3940
3950
  return /* @__PURE__ */ React__default.createElement(Select.Item, { ...props, ref: forwardedRef, className: classNames(className, styles.toolbarNodeKindSelectItem) }, /* @__PURE__ */ React__default.createElement(Select.ItemText, null, children));
3941
3951
  }
3942
3952
  );
3943
- const SelectTrigger = ({ placeholder }) => {
3944
- return /* @__PURE__ */ React__default.createElement(Select.Trigger, { "aria-label": placeholder, className: styles.toolbarNodeKindSelectTrigger }, /* @__PURE__ */ React__default.createElement(Select.Value, { placeholder }), /* @__PURE__ */ React__default.createElement(Select.Icon, { className: styles.toolbarNodeKindSelectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null)));
3953
+ const SelectTrigger = ({ placeholder, className }) => {
3954
+ return /* @__PURE__ */ React__default.createElement(Select.Trigger, { "aria-label": placeholder, className: classNames(styles.toolbarNodeKindSelectTrigger, className) }, /* @__PURE__ */ React__default.createElement(Select.Value, { placeholder }), /* @__PURE__ */ React__default.createElement(Select.Icon, { className: styles.toolbarNodeKindSelectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null)));
3945
3955
  };
3946
3956
  const SelectContent = ({
3947
3957
  children,
@@ -3958,7 +3968,7 @@ const SelectButtonTrigger = ({
3958
3968
  return /* @__PURE__ */ React__default.createElement(Select.Trigger, { className: classNames(styles.toolbarButtonSelectTrigger, className), title }, children, /* @__PURE__ */ React__default.createElement(Select.Icon, { className: styles.toolbarNodeKindSelectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null)));
3959
3969
  };
3960
3970
  function CodeBlockLanguageSelect() {
3961
- const [activeEditorType, activeEditor] = useEmitterValues("activeEditorType", "activeEditor");
3971
+ const [activeEditorType, activeEditor, codeBlockLanguages] = useEmitterValues("activeEditorType", "activeEditor", "codeBlockLanguages");
3962
3972
  const nodeLanguage = React__default.useMemo(() => {
3963
3973
  let language;
3964
3974
  activeEditor.getEditorState().read(() => {
@@ -3981,8 +3991,8 @@ function CodeBlockLanguageSelect() {
3981
3991
  });
3982
3992
  }
3983
3993
  },
3984
- /* @__PURE__ */ React__default.createElement(SelectTrigger, { placeholder: "Language" }),
3985
- /* @__PURE__ */ React__default.createElement(SelectContent, null, /* @__PURE__ */ React__default.createElement(SelectItem, { value: "js" }, "JavaScript"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "ts" }, "TypeScript"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "css" }, "CSS"))
3994
+ /* @__PURE__ */ React__default.createElement(SelectTrigger, { placeholder: "Language", className: styles.toolbarCodeBlockLanguageSelectTrigger }),
3995
+ /* @__PURE__ */ React__default.createElement(SelectContent, { className: styles.toolbarCodeBlockLanguageSelectContent }, Object.entries(codeBlockLanguages).map(([value, label]) => /* @__PURE__ */ React__default.createElement(SelectItem, { key: value, value }, label)))
3986
3996
  );
3987
3997
  }
3988
3998
  const SvgDelete = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {