@mdxeditor/editor 3.55.0 → 4.0.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.
@@ -141,13 +141,6 @@ const defaultSvgIcons = {
141
141
  fill: "currentColor"
142
142
  }
143
143
  )),
144
- sandpack: /* @__PURE__ */ React__default.createElement("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React__default.createElement(
145
- "path",
146
- {
147
- d: "M12.9999 22.5C12.4947 22.5 12.0671 22.325 11.7171 21.975C11.3671 21.625 11.1921 21.1974 11.1921 20.6922V7.30775C11.1921 6.80258 11.3671 6.375 11.7171 6.025C12.0671 5.675 12.4947 5.5 12.9999 5.5H16.3844C16.8895 5.5 17.3171 5.675 17.6671 6.025C18.0171 6.375 18.1921 6.80258 18.1921 7.30775V20.6922C18.1921 21.1974 18.0171 21.625 17.6671 21.975C17.3171 22.325 16.8895 22.5 16.3844 22.5H12.9999ZM12.6921 7.30775V20.6922C12.6921 20.7692 12.7242 20.8398 12.7884 20.9038C12.8524 20.9679 12.9229 21 12.9999 21H16.3844C16.4614 21 16.5319 20.9679 16.5959 20.9038C16.66 20.8398 16.6921 20.7692 16.6921 20.6922V7.30775C16.6921 7.23075 16.66 7.16025 16.5959 7.09625C16.5319 7.03208 16.4614 7 16.3844 7H12.9999C12.9229 7 12.8524 7.03208 12.7884 7.09625C12.7242 7.16025 12.6921 7.23075 12.6921 7.30775ZM6.61537 18.5C6.1102 18.5 5.68262 18.325 5.33262 17.975C4.98262 17.625 4.80762 17.1974 4.80762 16.6923V3.30775C4.80762 2.80258 4.98262 2.375 5.33262 2.025C5.68262 1.675 6.1102 1.5 6.61537 1.5H9.99987C10.505 1.5 10.9326 1.675 11.2826 2.025C11.6326 2.375 11.8076 2.80258 11.8076 3.30775V16.6923C11.8076 17.1974 11.6326 17.625 11.2826 17.975C10.9326 18.325 10.505 18.5 9.99987 18.5H6.61537ZM6.30762 3.30775V16.6923C6.30762 16.7692 6.3397 16.8398 6.40387 16.9038C6.46787 16.9679 6.53837 17 6.61537 17H9.99987C10.0769 17 10.1474 16.9679 10.2114 16.9038C10.2755 16.8398 10.3076 16.7692 10.3076 16.6923V3.30775C10.3076 3.23075 10.2755 3.16025 10.2114 3.09625C10.1474 3.03208 10.0769 3 9.99987 3H6.61537C6.53837 3 6.46787 3.03208 6.40387 3.09625C6.3397 3.16025 6.30762 3.23075 6.30762 3.30775Z",
148
- fill: "currentColor"
149
- }
150
- )),
151
144
  rich_text: /* @__PURE__ */ React__default.createElement("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React__default.createElement(
152
145
  "path",
153
146
  {
package/dist/index.d.ts CHANGED
@@ -44,7 +44,6 @@ import { RangeSelection } from 'lexical';
44
44
  import { ReactNode } from 'react';
45
45
  import { Realm } from '@mdxeditor/gurx';
46
46
  import { RootNode } from 'lexical';
47
- import { SandpackProvider } from '@codesandbox/sandpack-react';
48
47
  import { SerializedElementNode } from 'lexical';
49
48
  import { SerializedLexicalNode } from 'lexical';
50
49
  import { Spread } from 'lexical';
@@ -669,7 +668,6 @@ export declare function compose<I, A, R>(a: (arg: A) => R, b: (arg: I) => A): (a
669
668
  * <ConditionalContents
670
669
  * options={[
671
670
  * { when: (editor) => editor?.editorType === 'codeblock', contents: () => <ChangeCodeMirrorLanguage /> },
672
- * { when: (editor) => editor?.editorType === 'sandpack', contents: () => <ShowSandpackInfo /> },
673
671
  * {
674
672
  * fallback: () => (
675
673
  * <>
@@ -875,7 +873,6 @@ export declare const defaultSvgIcons: {
875
873
  frame_source: JSX_2.Element;
876
874
  arrow_drop_down: JSX_2.Element;
877
875
  admonition: JSX_2.Element;
878
- sandpack: JSX_2.Element;
879
876
  rich_text: JSX_2.Element;
880
877
  difference: JSX_2.Element;
881
878
  markdown: JSX_2.Element;
@@ -1436,7 +1433,7 @@ export declare const htmlTags: string[];
1436
1433
  */
1437
1434
  export declare const iconComponentFor$: NodeRef<(name: IconKey) => default_2.ReactNode>;
1438
1435
 
1439
- export declare type IconKey = 'undo' | 'redo' | 'format_bold' | 'format_italic' | 'format_underlined' | 'code' | 'strikeThrough' | 'superscript' | 'subscript' | 'format_list_bulleted' | 'format_list_numbered' | 'format_list_checked' | 'format_highlight' | 'link' | 'add_photo' | 'table' | 'horizontal_rule' | 'frontmatter' | 'frame_source' | 'arrow_drop_down' | 'admonition' | 'sandpack' | 'rich_text' | 'difference' | 'markdown' | 'open_in_new' | 'link_off' | 'edit' | 'content_copy' | 'more_horiz' | 'more_vert' | 'close' | 'settings' | 'delete_big' | 'delete_small' | 'format_align_center' | 'format_align_left' | 'format_align_right' | 'add_row' | 'add_column' | 'insert_col_left' | 'insert_row_above' | 'insert_row_below' | 'insert_col_right' | 'check';
1436
+ export declare type IconKey = 'undo' | 'redo' | 'format_bold' | 'format_italic' | 'format_underlined' | 'code' | 'strikeThrough' | 'superscript' | 'subscript' | 'format_list_bulleted' | 'format_list_numbered' | 'format_list_checked' | 'format_highlight' | 'link' | 'add_photo' | 'table' | 'horizontal_rule' | 'frontmatter' | 'frame_source' | 'arrow_drop_down' | 'admonition' | 'rich_text' | 'difference' | 'markdown' | 'open_in_new' | 'link_off' | 'edit' | 'content_copy' | 'more_horiz' | 'more_vert' | 'close' | 'settings' | 'delete_big' | 'delete_small' | 'format_align_center' | 'format_align_left' | 'format_align_right' | 'add_row' | 'add_column' | 'insert_col_left' | 'insert_row_above' | 'insert_row_below' | 'insert_col_right' | 'check';
1440
1437
 
1441
1438
  /**
1442
1439
  * Holds the autocomplete suggestions for image sources.
@@ -1689,20 +1686,6 @@ export declare const insertJsx$: NodeRef<{
1689
1686
  */
1690
1687
  export declare const insertMarkdown$: NodeRef<string>;
1691
1688
 
1692
- /**
1693
- * A signal that inserts a new sandpack code block with the specified name from the {@link SandpackConfig}.
1694
- * If no name is specified, the default preset will be used.
1695
- * @group Sandpack
1696
- */
1697
- export declare const insertSandpack$: NodeRef<string>;
1698
-
1699
- /**
1700
- * A dropdown button that allows the user to insert a live code block into the editor. The dropdown offers a list of presets that are defined in the sandpack plugin config.
1701
- * For this to work, you need to have the `sandpackPlugin` installed.
1702
- * @group Toolbar Components
1703
- */
1704
- export declare const InsertSandpack: () => JSX_2.Element;
1705
-
1706
1689
  /**
1707
1690
  * A signal that will insert a table with the published amount of rows and columns into the active editor.
1708
1691
  * @example
@@ -2739,91 +2722,6 @@ export declare const rootEditor$: NodeRef<LexicalEditor | null>;
2739
2722
 
2740
2723
  /* Excluded from this release type: rootEditorSubscriptions$ */
2741
2724
 
2742
- /**
2743
- * Holds the current sandpack configuration.
2744
- * @group Sandpack
2745
- */
2746
- export declare const sandpackConfig$: NodeRef<SandpackConfig>;
2747
-
2748
- /**
2749
- * The configuration for the available sandpack presets.
2750
- * @group Sandpack
2751
- */
2752
- export declare interface SandpackConfig {
2753
- /**
2754
- * The name of the default preset that will be used if no meta (other than live) is set.
2755
- */
2756
- defaultPreset: string;
2757
- /**
2758
- * The list of sandpack presets that can be used.
2759
- */
2760
- presets: SandpackPreset[];
2761
- }
2762
-
2763
- export declare const SandpackEditor: ({ nodeKey, code, focusEmitter, preset }: SandpackEditorProps) => JSX_2.Element;
2764
-
2765
- export declare interface SandpackEditorProps extends CodeBlockEditorProps {
2766
- preset: SandpackPreset;
2767
- }
2768
-
2769
- /**
2770
- * A plugin that adds support for sandpack code blocks in the editor.
2771
- * @group Sandpack
2772
- */
2773
- export declare const sandpackPlugin: (params?: {
2774
- sandpackConfig: SandpackConfig;
2775
- } | undefined) => RealmPlugin;
2776
-
2777
- /**
2778
- * Defines a single preset that can be used to create a Sandpack sandbox.
2779
- * @group Sandpack
2780
- */
2781
- export declare interface SandpackPreset {
2782
- /**
2783
- * The name of the preset - use this to reference the preset from the defaultPreset field.
2784
- */
2785
- name: string;
2786
- /**
2787
- * The label of the preset, displayed in the sandpack button dropdown.
2788
- */
2789
- label: string | JSX.Element;
2790
- /**
2791
- * The meta string that will be used to identify the preset from the fenced code block. e.g. "live react"
2792
- */
2793
- meta: string;
2794
- /**
2795
- * The sandpack template that will be used to create the sandbox. e.g. "react", "react-ts", "vanilla".
2796
- */
2797
- sandpackTemplate: SandpackProviderProps['template'];
2798
- /**
2799
- * The sandpack theme that will be used to create the sandbox. e.g. "light", "dark".
2800
- */
2801
- sandpackTheme: SandpackProviderProps['theme'];
2802
- /**
2803
- * The name of the file that will be created in the sandbox. e.g. "/App.js".
2804
- */
2805
- snippetFileName: string;
2806
- /**
2807
- * The dependencies that will be added to the sandbox, just like in package.json.
2808
- */
2809
- dependencies?: Record<string, string>;
2810
- /**
2811
- * The files that will be added to the sandbox (read-only).
2812
- * The key is the name of the file, and the value is the contents of the file.
2813
- */
2814
- files?: Record<string, string>;
2815
- /**
2816
- * The language used in the editable snippet. e.g. "jsx", "tsx", etc.
2817
- */
2818
- snippetLanguage?: string;
2819
- /**
2820
- * The initial content of the editable snippet.
2821
- */
2822
- initialSnippetContent?: string;
2823
- }
2824
-
2825
- declare type SandpackProviderProps = default_2.ComponentProps<typeof SandpackProvider>;
2826
-
2827
2725
  /**
2828
2726
  * Saves the data from the image dialog
2829
2727
  * @group Image
@@ -2943,14 +2841,6 @@ export declare const setMarkdown$: NodeRef<string>;
2943
2841
 
2944
2842
  export declare const showLinkTitleField$: NodeRef<boolean>;
2945
2843
 
2946
- /**
2947
- * A component that displays the focused live code block's name.
2948
- * For this component to work, you must enable the `sandpackPlugin` for the editor.
2949
- * See {@link ConditionalContents} for an example on how to display the dropdown only when a sandpack editor is in focus.
2950
- * @group Toolbar Components
2951
- */
2952
- export declare const ShowSandpackInfo: () => JSX_2.Element | null;
2953
-
2954
2844
  /**
2955
2845
  * A toolbar primitive that allows you to build an UI with multiple exclusive toggle groups, like the list type toggle.
2956
2846
  * @group Toolbar Primitives
package/dist/index.js CHANGED
@@ -16,8 +16,6 @@ import { quotePlugin } from "./plugins/quote/index.js";
16
16
  import { maxLengthPlugin } from "./plugins/maxlength/index.js";
17
17
  import { insertJsx$, isMdastJsxNode, jsxPlugin } from "./plugins/jsx/index.js";
18
18
  import { GenericJsxEditor } from "./jsx-editors/GenericJsxEditor.js";
19
- import { insertSandpack$, sandpackConfig$, sandpackPlugin } from "./plugins/sandpack/index.js";
20
- import { SandpackEditor } from "./plugins/sandpack/SandpackEditor.js";
21
19
  import { EMPTY_VALUE, codeBlockLanguages$, codeMirrorAutoLoadLanguageSupport$, codeMirrorExtensions$, codeMirrorPlugin, getCodeBlockLanguageSelectData, insertCodeMirror$, normalizeCodeBlockLanguages } from "./plugins/codemirror/index.js";
22
20
  import { COMMON_STATE_CONFIG_EXTENSIONS, CodeMirrorEditor } from "./plugins/codemirror/CodeMirrorEditor.js";
23
21
  import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$ } from "./plugins/codeblock/index.js";
@@ -41,11 +39,9 @@ import { InsertAdmonition } from "./plugins/toolbar/components/InsertAdmonition.
41
39
  import { InsertCodeBlock } from "./plugins/toolbar/components/InsertCodeBlock.js";
42
40
  import { InsertFrontmatter } from "./plugins/toolbar/components/InsertFrontmatter.js";
43
41
  import { InsertImage } from "./plugins/toolbar/components/InsertImage.js";
44
- import { InsertSandpack } from "./plugins/toolbar/components/InsertSandpack.js";
45
42
  import { InsertTable } from "./plugins/toolbar/components/InsertTable.js";
46
43
  import { InsertThematicBreak } from "./plugins/toolbar/components/InsertThematicBreak.js";
47
44
  import { ListsToggle } from "./plugins/toolbar/components/ListsToggle.js";
48
- import { ShowSandpackInfo } from "./plugins/toolbar/components/ShowSandpackInfo.js";
49
45
  import { UndoRedo } from "./plugins/toolbar/components/UndoRedo.js";
50
46
  import { KitchenSinkToolbar } from "./plugins/toolbar/components/KitchenSinkToolbar.js";
51
47
  import { Button, ButtonOrDropdownButton, ButtonWithTooltip, ConditionalContents, MultipleChoiceToggleGroup, Root, Separator, SingleChoiceToggleGroup, SingleToggleGroup, ToggleSingleGroupWithItem, ToolbarToggleItem } from "./plugins/toolbar/primitives/toolbar.js";
@@ -132,7 +128,6 @@ export {
132
128
  InsertCodeBlock,
133
129
  InsertFrontmatter,
134
130
  InsertImage,
135
- InsertSandpack,
136
131
  InsertTable,
137
132
  InsertThematicBreak,
138
133
  KitchenSinkToolbar,
@@ -149,14 +144,12 @@ export {
149
144
  RealmWithPlugins,
150
145
  RemoteMDXEditorRealmProvider,
151
146
  Root,
152
- SandpackEditor,
153
147
  Select,
154
148
  SelectButtonTrigger,
155
149
  SelectContent,
156
150
  SelectItem,
157
151
  SelectTrigger,
158
152
  Separator,
159
- ShowSandpackInfo,
160
153
  SingleChoiceToggleGroup,
161
154
  SingleToggleGroup,
162
155
  StrikeThroughSupSubToggles,
@@ -278,7 +271,6 @@ export {
278
271
  insertImage$,
279
272
  insertJsx$,
280
273
  insertMarkdown$,
281
- insertSandpack$,
282
274
  insertTable$,
283
275
  insertThematicBreak$,
284
276
  isMdastHTMLNode,
@@ -328,8 +320,6 @@ export {
328
320
  removeLink$,
329
321
  rootEditor$,
330
322
  rootEditorSubscriptions$,
331
- sandpackConfig$,
332
- sandpackPlugin,
333
323
  saveImage$,
334
324
  searchOpen$,
335
325
  searchPlugin,
@@ -11,7 +11,7 @@ import { basicLight } from "cm6-theme-basic-light";
11
11
  import { basicSetup } from "codemirror";
12
12
  import { $setSelection } from "lexical";
13
13
  import { codeMirrorExtensions$, codeMirrorAutoLoadLanguageSupport$, codeBlockLanguages$, getCodeBlockLanguageSelectData, EMPTY_VALUE } from "./index.js";
14
- import { useCodeMirrorRef } from "../sandpack/useCodeMirrorRef.js";
14
+ import { useCodeMirrorRef } from "./useCodeMirrorRef.js";
15
15
  import { Select } from "../toolbar/primitives/select.js";
16
16
  const COMMON_STATE_CONFIG_EXTENSIONS = [];
17
17
  const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
@@ -24,7 +24,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
24
24
  iconComponentFor$,
25
25
  codeBlockLanguages$
26
26
  );
27
- const codeMirrorRef = useCodeMirrorRef(nodeKey, "codeblock", language, focusEmitter);
27
+ const codeMirrorRef = useCodeMirrorRef(nodeKey, language, focusEmitter);
28
28
  const { setCode } = useCodeBlockEditorContext();
29
29
  const editorViewRef = React__default.useRef(null);
30
30
  const elRef = React__default.useRef(null);
@@ -90,15 +90,15 @@ const codeMirrorPlugin = realmPlugin({
90
90
  r.pubIn({
91
91
  [codeBlockLanguages$]: normalized,
92
92
  [codeMirrorExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) ?? [],
93
- [appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor(),
93
+ [appendCodeBlockEditorDescriptor$]: buildCodeBlockDescriptor(normalized),
94
94
  [codeMirrorAutoLoadLanguageSupport$]: (params == null ? void 0 : params.autoLoadLanguageSupport) ?? true
95
95
  });
96
96
  }
97
97
  });
98
- function buildCodeBlockDescriptor(_normalized) {
98
+ function buildCodeBlockDescriptor(normalized) {
99
99
  return {
100
- match(_language, meta) {
101
- return !meta;
100
+ match(language, meta) {
101
+ return !meta || Object.hasOwn(normalized.keyMap, language ?? "");
102
102
  },
103
103
  priority: 1,
104
104
  Editor: CodeMirrorEditor
@@ -3,7 +3,7 @@ import React__default from "react";
3
3
  import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
4
4
  import { activeEditor$, editorInFocus$ } from "../core/index.js";
5
5
  import { useCellValue, usePublisher } from "@mdxeditor/gurx";
6
- function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
6
+ function useCodeMirrorRef(nodeKey, language, focusEmitter) {
7
7
  const activeEditor = useCellValue(activeEditor$);
8
8
  const setEditorInFocus = usePublisher(editorInFocus$);
9
9
  const codeMirrorRef = React__default.useRef(null);
@@ -12,11 +12,11 @@ function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
12
12
  const atTop = React__default.useRef(false);
13
13
  const onFocusHandler = React__default.useCallback(() => {
14
14
  setEditorInFocus({
15
- editorType,
15
+ editorType: "codeblock",
16
16
  rootNode: lexicalNode,
17
17
  editorRef: codeMirrorRef.current
18
18
  });
19
- }, [editorType, lexicalNode, setEditorInFocus]);
19
+ }, [lexicalNode, setEditorInFocus]);
20
20
  const onKeyDownHandler = React__default.useCallback(
21
21
  (e) => {
22
22
  var _a, _b, _c, _d, _e, _f;
@@ -10,11 +10,9 @@ import { InsertAdmonition } from "./InsertAdmonition.js";
10
10
  import { InsertCodeBlock } from "./InsertCodeBlock.js";
11
11
  import { InsertFrontmatter } from "./InsertFrontmatter.js";
12
12
  import { InsertImage } from "./InsertImage.js";
13
- import { InsertSandpack } from "./InsertSandpack.js";
14
13
  import { InsertTable } from "./InsertTable.js";
15
14
  import { InsertThematicBreak } from "./InsertThematicBreak.js";
16
15
  import { ListsToggle } from "./ListsToggle.js";
17
- import { ShowSandpackInfo } from "./ShowSandpackInfo.js";
18
16
  import { UndoRedo } from "./UndoRedo.js";
19
17
  import { CreateLink } from "./CreateLink.js";
20
18
  import { HighlightToggle } from "./HighlightToggle.js";
@@ -31,14 +29,13 @@ const KitchenSinkToolbar = () => {
31
29
  {
32
30
  options: [
33
31
  { when: (editor) => (editor == null ? void 0 : editor.editorType) === "codeblock", contents: () => /* @__PURE__ */ React__default.createElement(ChangeCodeMirrorLanguage, null) },
34
- { when: (editor) => (editor == null ? void 0 : editor.editorType) === "sandpack", contents: () => /* @__PURE__ */ React__default.createElement(ShowSandpackInfo, null) },
35
32
  {
36
33
  fallback: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(UndoRedo, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(BoldItalicUnderlineToggles, null), /* @__PURE__ */ React__default.createElement(CodeToggle, null), /* @__PURE__ */ React__default.createElement(HighlightToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(StrikeThroughSupSubToggles, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(ListsToggle, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(
37
34
  ConditionalContents,
38
35
  {
39
36
  options: [{ when: whenInAdmonition, contents: () => /* @__PURE__ */ React__default.createElement(ChangeAdmonitionType, null) }, { fallback: () => /* @__PURE__ */ React__default.createElement(BlockTypeSelect, null) }]
40
37
  }
41
- ), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(CreateLink, null), /* @__PURE__ */ React__default.createElement(InsertImage, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(InsertTable, null), /* @__PURE__ */ React__default.createElement(InsertThematicBreak, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(InsertCodeBlock, null), /* @__PURE__ */ React__default.createElement(InsertSandpack, null), /* @__PURE__ */ React__default.createElement(
38
+ ), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(CreateLink, null), /* @__PURE__ */ React__default.createElement(InsertImage, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(InsertTable, null), /* @__PURE__ */ React__default.createElement(InsertThematicBreak, null), /* @__PURE__ */ React__default.createElement(Separator, null), /* @__PURE__ */ React__default.createElement(InsertCodeBlock, null), /* @__PURE__ */ React__default.createElement(
42
39
  ConditionalContents,
43
40
  {
44
41
  options: [