@mdxeditor/editor 3.55.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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';
@@ -600,7 +599,8 @@ export declare const codeBlockPlugin: (params?: {
600
599
  */
601
600
  codeBlockEditorDescriptors?: CodeBlockEditorDescriptor[];
602
601
  /**
603
- * The default language to use when creating a new code block if no language is passed.
602
+ * The default code block language. Used when inserting a new code block, and as a fallback at import time for
603
+ * fences whose language has no matching descriptor.
604
604
  */
605
605
  defaultCodeBlockLanguage?: string;
606
606
  } | undefined) => RealmPlugin;
@@ -669,7 +669,6 @@ export declare function compose<I, A, R>(a: (arg: A) => R, b: (arg: I) => A): (a
669
669
  * <ConditionalContents
670
670
  * options={[
671
671
  * { when: (editor) => editor?.editorType === 'codeblock', contents: () => <ChangeCodeMirrorLanguage /> },
672
- * { when: (editor) => editor?.editorType === 'sandpack', contents: () => <ShowSandpackInfo /> },
673
672
  * {
674
673
  * fallback: () => (
675
674
  * <>
@@ -848,7 +847,8 @@ export declare const debouncedIndexer$: NodeRef<TextNodeIndex>;
848
847
  export declare const DEFAULT_FORMAT: 0;
849
848
 
850
849
  /**
851
- * Contains the default language to use when creating a new code block if no language is passed.
850
+ * The default code block language. Used both when inserting a new code block without an explicit language, and as a
851
+ * fallback at import time when a fence's own language doesn't match any registered descriptor.
852
852
  * @group Code Block
853
853
  */
854
854
  export declare const defaultCodeBlockLanguage$: NodeRef<string>;
@@ -875,7 +875,6 @@ export declare const defaultSvgIcons: {
875
875
  frame_source: JSX_2.Element;
876
876
  arrow_drop_down: JSX_2.Element;
877
877
  admonition: JSX_2.Element;
878
- sandpack: JSX_2.Element;
879
878
  rich_text: JSX_2.Element;
880
879
  difference: JSX_2.Element;
881
880
  markdown: JSX_2.Element;
@@ -902,12 +901,16 @@ export declare const defaultSvgIcons: {
902
901
  };
903
902
 
904
903
  /**
905
- * The registered descriptors for composite nodes (jsx, directives, code blocks).
904
+ * Per-plugin import context passed to {@link MdastImportVisitor} functions.
906
905
  */
907
906
  export declare interface Descriptors {
908
907
  jsxComponentDescriptors: JsxComponentDescriptor[];
909
908
  directiveDescriptors: DirectiveDescriptor[];
910
909
  codeBlockEditorDescriptors: CodeBlockEditorDescriptor[];
910
+ /**
911
+ * The fallback language used to select a code block editor when a fenced code block's own language has no matching descriptor.
912
+ */
913
+ defaultCodeBlockLanguage?: string;
911
914
  }
912
915
 
913
916
  /**
@@ -1436,7 +1439,7 @@ export declare const htmlTags: string[];
1436
1439
  */
1437
1440
  export declare const iconComponentFor$: NodeRef<(name: IconKey) => default_2.ReactNode>;
1438
1441
 
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';
1442
+ 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
1443
 
1441
1444
  /**
1442
1445
  * Holds the autocomplete suggestions for image sources.
@@ -1689,20 +1692,6 @@ export declare const insertJsx$: NodeRef<{
1689
1692
  */
1690
1693
  export declare const insertMarkdown$: NodeRef<string>;
1691
1694
 
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
1695
  /**
1707
1696
  * A signal that will insert a table with the published amount of rows and columns into the active editor.
1708
1697
  * @example
@@ -2163,7 +2152,7 @@ export declare interface MdastImportVisitor<UN extends Mdast.Nodes> {
2163
2152
  /**
2164
2153
  * The test function that determines if this visitor should be used for the given node.
2165
2154
  * As a convenience, you can also pass a string here, which will be compared to the node's type.
2166
- * @param descriptors - the registered descriptors for composite nodes (jsx, directives, code blocks).
2155
+ * @param descriptors - the registered descriptors and fallback values for composite nodes.
2167
2156
  */
2168
2157
  testNode: ((mdastNode: Mdast.Nodes, descriptors: Descriptors) => boolean) | string;
2169
2158
  visitNode(params: {
@@ -2739,91 +2728,6 @@ export declare const rootEditor$: NodeRef<LexicalEditor | null>;
2739
2728
 
2740
2729
  /* Excluded from this release type: rootEditorSubscriptions$ */
2741
2730
 
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
2731
  /**
2828
2732
  * Saves the data from the image dialog
2829
2733
  * @group Image
@@ -2943,14 +2847,6 @@ export declare const setMarkdown$: NodeRef<string>;
2943
2847
 
2944
2848
  export declare const showLinkTitleField$: NodeRef<boolean>;
2945
2849
 
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
2850
  /**
2955
2851
  * A toolbar primitive that allows you to build an UI with multiple exclusive toggle groups, like the list type toggle.
2956
2852
  * @group Toolbar Primitives
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { MDXEditor } from "./MDXEditor.js";
4
4
  import { defaultSvgIcons } from "./defaultSvgIcons.js";
5
5
  import { MarkdownParseError, UnrecognizedMarkdownConstructError, importMarkdownToLexical, importMdastTreeToLexical } from "./importMarkdownToLexical.js";
6
6
  import { exportLexicalTreeToMdast, exportMarkdownFromLexical } from "./exportMarkdownFromLexical.js";
7
- import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addBottomAreaChild$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addTableCellEditorChild$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, bottomAreaChildren$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, contentEditableRef$, contentEditableWrapperElement$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorInTable$, editorRootElementRef$, editorWrapperElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialMarkdownNormalize$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, syntaxExtensions$, tableCellEditorChildren$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
7
+ import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addBottomAreaChild$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addTableCellEditorChild$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, bottomAreaChildren$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, contentEditableRef$, contentEditableWrapperElement$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, defaultCodeBlockLanguage$, directiveDescriptors$, editorInFocus$, editorInTable$, editorRootElementRef$, editorWrapperElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialMarkdownNormalize$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, syntaxExtensions$, tableCellEditorChildren$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
8
8
  import { ALL_HEADING_LEVELS, allowedHeadingLevels$, headingsPlugin } from "./plugins/headings/index.js";
9
9
  import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-break/index.js";
10
10
  import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
@@ -16,11 +16,9 @@ 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
- import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, defaultCodeBlockLanguage$, insertCodeBlock$ } from "./plugins/codeblock/index.js";
21
+ import { appendCodeBlockEditorDescriptor$, codeBlockPlugin, insertCodeBlock$ } from "./plugins/codeblock/index.js";
24
22
  import { directivesPlugin, insertDirective$ } from "./plugins/directives/index.js";
25
23
  import { ADMONITION_TYPES, AdmonitionDirectiveDescriptor } from "./directive-editors/AdmonitionDirectiveDescriptor.js";
26
24
  import { GenericDirectiveEditor } from "./directive-editors/GenericDirectiveEditor.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,
@@ -7,9 +7,10 @@ var __publicField = (obj, key, value) => {
7
7
  import { useCellValue } from "@mdxeditor/gurx";
8
8
  import { DecoratorNode } from "lexical";
9
9
  import React__default from "react";
10
- import { defaultCodeBlockLanguage$ } from "./index.js";
10
+ import "./index.js";
11
11
  import { voidEmitter } from "../../utils/voidEmitter.js";
12
- import { codeBlockEditorDescriptors$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
12
+ import { codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
13
+ import { findCodeBlockDescriptor } from "./findCodeBlockDescriptor.js";
13
14
  class CodeBlockNode extends DecoratorNode {
14
15
  constructor(code, language, meta, key) {
15
16
  super(key);
@@ -151,8 +152,7 @@ function useCodeBlockEditorContext() {
151
152
  const CodeBlockEditorContainer = (props) => {
152
153
  const codeBlockEditorDescriptors = useCellValue(codeBlockEditorDescriptors$);
153
154
  const defaultCodeBlockLanguage = useCellValue(defaultCodeBlockLanguage$);
154
- let descriptor = codeBlockEditorDescriptors.sort((a, b) => b.priority - a.priority).find((descriptor2) => descriptor2.match(props.language || "", props.meta || ""));
155
- descriptor ?? (descriptor = codeBlockEditorDescriptors.find((descriptor2) => descriptor2.match(defaultCodeBlockLanguage || "", props.meta || "")));
155
+ const descriptor = findCodeBlockDescriptor(codeBlockEditorDescriptors, props.language, props.meta, defaultCodeBlockLanguage);
156
156
  if (!descriptor) {
157
157
  throw new Error(`No CodeBlockEditor registered for language=${props.language} meta=${props.meta}`);
158
158
  }
@@ -1,8 +1,9 @@
1
1
  import { $createCodeBlockNode } from "./CodeBlockNode.js";
2
+ import { findCodeBlockDescriptor } from "./findCodeBlockDescriptor.js";
2
3
  const MdastCodeVisitor = {
3
- testNode: (node, { codeBlockEditorDescriptors }) => {
4
+ testNode: (node, { codeBlockEditorDescriptors, defaultCodeBlockLanguage }) => {
4
5
  if (node.type === "code") {
5
- const descriptor = codeBlockEditorDescriptors.find((descriptor2) => descriptor2.match(node.lang, node.meta));
6
+ const descriptor = findCodeBlockDescriptor(codeBlockEditorDescriptors, node.lang, node.meta, defaultCodeBlockLanguage);
6
7
  return descriptor !== void 0;
7
8
  }
8
9
  return false;
@@ -0,0 +1,8 @@
1
+ function findCodeBlockDescriptor(descriptors, language, meta, defaultLanguage) {
2
+ const sortedDescriptors = [...descriptors].sort((a, b) => b.priority - a.priority);
3
+ const resolvedMeta = meta ?? "";
4
+ return sortedDescriptors.find((descriptor) => descriptor.match(language ?? "", resolvedMeta)) ?? sortedDescriptors.find((descriptor) => descriptor.match(defaultLanguage ?? "", resolvedMeta));
5
+ }
6
+ export {
7
+ findCodeBlockDescriptor
8
+ };
@@ -1,11 +1,10 @@
1
1
  import { CodeBlockVisitor } from "./CodeBlockVisitor.js";
2
2
  import { MdastCodeVisitor } from "./MdastCodeVisitor.js";
3
- import { Appender, insertDecoratorNode$, codeBlockEditorDescriptors$, addExportVisitor$, addLexicalNode$, addImportVisitor$, addActivePlugin$ } from "../core/index.js";
3
+ import { Appender, defaultCodeBlockLanguage$, insertDecoratorNode$, codeBlockEditorDescriptors$, addExportVisitor$, addLexicalNode$, addImportVisitor$, addActivePlugin$ } from "../core/index.js";
4
4
  import { $createCodeBlockNode, CodeBlockNode } from "./CodeBlockNode.js";
5
5
  import { $convertPreElement, $isCodeBlockNode, useCodeBlockEditorContext } from "./CodeBlockNode.js";
6
- import { Cell, Signal, withLatestFrom, map } from "@mdxeditor/gurx";
6
+ import { Signal, withLatestFrom, map } from "@mdxeditor/gurx";
7
7
  import { realmPlugin } from "../../RealmWithPlugins.js";
8
- const defaultCodeBlockLanguage$ = Cell("");
9
8
  const insertCodeBlock$ = Signal((r) => {
10
9
  r.link(
11
10
  r.pipe(
@@ -26,6 +25,7 @@ const codeBlockPlugin = realmPlugin({
26
25
  init(realm, params) {
27
26
  realm.pubIn({
28
27
  [addActivePlugin$]: "codeblock",
28
+ [defaultCodeBlockLanguage$]: (params == null ? void 0 : params.defaultCodeBlockLanguage) ?? "",
29
29
  [codeBlockEditorDescriptors$]: (params == null ? void 0 : params.codeBlockEditorDescriptors) ?? [],
30
30
  [addImportVisitor$]: MdastCodeVisitor,
31
31
  [addLexicalNode$]: CodeBlockNode,
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import { $addUpdateTag, $getNodeByKey, createEditor, $getRoot, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_CRITICAL } from "lexical";
2
2
  import React__default from "react";
3
- import { NESTED_EDITOR_UPDATED_COMMAND, rootEditor$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, jsxIsAvailable$, nestedEditorChildren$, lexicalTheme$, editorInFocus$ } from "./index.js";
3
+ import { NESTED_EDITOR_UPDATED_COMMAND, rootEditor$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, jsxIsAvailable$, nestedEditorChildren$, lexicalTheme$, editorInFocus$ } from "./index.js";
4
4
  import { ContentEditable } from "@lexical/react/LexicalContentEditable";
5
5
  import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
6
6
  import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
@@ -62,6 +62,7 @@ const NestedLexicalEditor = function(props) {
62
62
  jsxComponentDescriptors,
63
63
  directiveDescriptors,
64
64
  codeBlockEditorDescriptors,
65
+ defaultCodeBlockLanguage,
65
66
  jsxIsAvailable,
66
67
  nestedEditorChildren,
67
68
  lexicalTheme
@@ -73,6 +74,7 @@ const NestedLexicalEditor = function(props) {
73
74
  jsxComponentDescriptors$,
74
75
  directiveDescriptors$,
75
76
  codeBlockEditorDescriptors$,
77
+ defaultCodeBlockLanguage$,
76
78
  jsxIsAvailable$,
77
79
  nestedEditorChildren$,
78
80
  lexicalTheme$
@@ -111,6 +113,7 @@ const NestedLexicalEditor = function(props) {
111
113
  visitors: importVisitors,
112
114
  directiveDescriptors,
113
115
  codeBlockEditorDescriptors,
116
+ defaultCodeBlockLanguage,
114
117
  jsxComponentDescriptors
115
118
  });
116
119
  });
@@ -113,6 +113,7 @@ const jsxIsAvailable$ = Cell(false);
113
113
  const jsxComponentDescriptors$ = Cell([]);
114
114
  const directiveDescriptors$ = Cell([]);
115
115
  const codeBlockEditorDescriptors$ = Cell([]);
116
+ const defaultCodeBlockLanguage$ = Cell("");
116
117
  const editorRootElementRef$ = Cell(null);
117
118
  const editorWrapperElementRef$ = Cell(null);
118
119
  const contentEditableRef$ = Cell(null);
@@ -375,7 +376,8 @@ function tryImportingMarkdown(r, node, markdownValue) {
375
376
  syntaxExtensions: r.getValue(syntaxExtensions$),
376
377
  jsxComponentDescriptors: r.getValue(jsxComponentDescriptors$),
377
378
  directiveDescriptors: r.getValue(directiveDescriptors$),
378
- codeBlockEditorDescriptors: r.getValue(codeBlockEditorDescriptors$)
379
+ codeBlockEditorDescriptors: r.getValue(codeBlockEditorDescriptors$),
380
+ defaultCodeBlockLanguage: r.getValue(defaultCodeBlockLanguage$)
379
381
  });
380
382
  r.pub(markdownProcessingError$, null);
381
383
  } catch (e) {
@@ -647,6 +649,7 @@ export {
647
649
  currentBlockType$,
648
650
  currentFormat$,
649
651
  currentSelection$,
652
+ defaultCodeBlockLanguage$,
650
653
  directiveDescriptors$,
651
654
  editorInFocus$,
652
655
  editorInTable$,
@@ -15,7 +15,7 @@ import classNames from "classnames";
15
15
  import styles from "../../styles/ui.module.css.js";
16
16
  import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
17
17
  import { uuidv4 } from "../../utils/uuid4.js";
18
- import { iconComponentFor$, readOnly$, useTranslation, editorRootElementRef$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, jsxIsAvailable$, rootEditor$, tableCellEditorChildren$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
18
+ import { iconComponentFor$, readOnly$, useTranslation, editorRootElementRef$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, jsxIsAvailable$, rootEditor$, tableCellEditorChildren$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
19
19
  import { useCellValues } from "@mdxeditor/gurx";
20
20
  const getCellType = (rowIndex) => {
21
21
  if (rowIndex === 0) {
@@ -215,6 +215,7 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
215
215
  jsxComponentDescriptors,
216
216
  directiveDescriptors,
217
217
  codeBlockEditorDescriptors,
218
+ defaultCodeBlockLanguage,
218
219
  jsxIsAvailable,
219
220
  rootEditor,
220
221
  tableCellEditorChildren
@@ -225,6 +226,7 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
225
226
  jsxComponentDescriptors$,
226
227
  directiveDescriptors$,
227
228
  codeBlockEditorDescriptors$,
229
+ defaultCodeBlockLanguage$,
228
230
  jsxIsAvailable$,
229
231
  rootEditor$,
230
232
  tableCellEditorChildren$
@@ -242,7 +244,8 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
242
244
  visitors: importVisitors,
243
245
  jsxComponentDescriptors,
244
246
  directiveDescriptors,
245
- codeBlockEditorDescriptors
247
+ codeBlockEditorDescriptors,
248
+ defaultCodeBlockLanguage
246
249
  });
247
250
  });
248
251
  return editor2;
@@ -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: [