@mdxeditor/editor 3.54.1 → 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.
- package/dist/defaultSvgIcons.js +0 -7
- package/dist/index.d.ts +13 -111
- package/dist/index.js +2 -11
- package/dist/plugins/codeblock/MdastCodeVisitor.js +2 -2
- package/dist/plugins/codemirror/CodeMirrorEditor.js +9 -5
- package/dist/plugins/codemirror/index.js +15 -3
- package/dist/plugins/{sandpack → codemirror}/useCodeMirrorRef.js +3 -3
- package/dist/plugins/core/MdastHTMLNode.js +1 -1
- package/dist/plugins/jsx/LexicalJsxVisitor.js +2 -2
- package/dist/plugins/jsx/jsxTagName.js +7 -0
- package/dist/plugins/table/TableEditor.js +1 -1
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +4 -7
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +1 -4
- package/dist/style.css +313 -307
- package/dist/styles/lexical-theme.module.css.js +21 -18
- package/dist/styles/lexicalTheme.js +1 -0
- package/dist/styles/ui.module.css.js +94 -97
- package/package.json +6 -7
- package/dist/plugins/sandpack/SandpackEditor.js +0 -56
- package/dist/plugins/sandpack/index.js +0 -83
- package/dist/plugins/toolbar/components/InsertSandpack.js +0 -15
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +0 -41
package/dist/defaultSvgIcons.js
CHANGED
|
@@ -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;
|
|
@@ -1353,6 +1350,18 @@ export declare interface GenericJsxEditorProps extends JsxEditorProps {
|
|
|
1353
1350
|
PropertyEditor?: PropertyEditorType;
|
|
1354
1351
|
}
|
|
1355
1352
|
|
|
1353
|
+
/**
|
|
1354
|
+
* Resolves the current language to the select value and items used by CodeMirror language pickers.
|
|
1355
|
+
* Unknown languages are added as a temporary item so the picker remains in sync with the code block value.
|
|
1356
|
+
*/
|
|
1357
|
+
export declare function getCodeBlockLanguageSelectData(normalized: NormalizedCodeBlockLanguages, language: string): {
|
|
1358
|
+
value: string;
|
|
1359
|
+
items: {
|
|
1360
|
+
value: string;
|
|
1361
|
+
label: string;
|
|
1362
|
+
}[];
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1356
1365
|
/**
|
|
1357
1366
|
* Gets the selected node from the Lexical editor.
|
|
1358
1367
|
* @group Utils
|
|
@@ -1424,7 +1433,7 @@ export declare const htmlTags: string[];
|
|
|
1424
1433
|
*/
|
|
1425
1434
|
export declare const iconComponentFor$: NodeRef<(name: IconKey) => default_2.ReactNode>;
|
|
1426
1435
|
|
|
1427
|
-
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' | '
|
|
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';
|
|
1428
1437
|
|
|
1429
1438
|
/**
|
|
1430
1439
|
* Holds the autocomplete suggestions for image sources.
|
|
@@ -1677,20 +1686,6 @@ export declare const insertJsx$: NodeRef<{
|
|
|
1677
1686
|
*/
|
|
1678
1687
|
export declare const insertMarkdown$: NodeRef<string>;
|
|
1679
1688
|
|
|
1680
|
-
/**
|
|
1681
|
-
* A signal that inserts a new sandpack code block with the specified name from the {@link SandpackConfig}.
|
|
1682
|
-
* If no name is specified, the default preset will be used.
|
|
1683
|
-
* @group Sandpack
|
|
1684
|
-
*/
|
|
1685
|
-
export declare const insertSandpack$: NodeRef<string>;
|
|
1686
|
-
|
|
1687
|
-
/**
|
|
1688
|
-
* 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.
|
|
1689
|
-
* For this to work, you need to have the `sandpackPlugin` installed.
|
|
1690
|
-
* @group Toolbar Components
|
|
1691
|
-
*/
|
|
1692
|
-
export declare const InsertSandpack: () => JSX_2.Element;
|
|
1693
|
-
|
|
1694
1689
|
/**
|
|
1695
1690
|
* A signal that will insert a table with the published amount of rows and columns into the active editor.
|
|
1696
1691
|
* @example
|
|
@@ -2727,91 +2722,6 @@ export declare const rootEditor$: NodeRef<LexicalEditor | null>;
|
|
|
2727
2722
|
|
|
2728
2723
|
/* Excluded from this release type: rootEditorSubscriptions$ */
|
|
2729
2724
|
|
|
2730
|
-
/**
|
|
2731
|
-
* Holds the current sandpack configuration.
|
|
2732
|
-
* @group Sandpack
|
|
2733
|
-
*/
|
|
2734
|
-
export declare const sandpackConfig$: NodeRef<SandpackConfig>;
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* The configuration for the available sandpack presets.
|
|
2738
|
-
* @group Sandpack
|
|
2739
|
-
*/
|
|
2740
|
-
export declare interface SandpackConfig {
|
|
2741
|
-
/**
|
|
2742
|
-
* The name of the default preset that will be used if no meta (other than live) is set.
|
|
2743
|
-
*/
|
|
2744
|
-
defaultPreset: string;
|
|
2745
|
-
/**
|
|
2746
|
-
* The list of sandpack presets that can be used.
|
|
2747
|
-
*/
|
|
2748
|
-
presets: SandpackPreset[];
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
export declare const SandpackEditor: ({ nodeKey, code, focusEmitter, preset }: SandpackEditorProps) => JSX_2.Element;
|
|
2752
|
-
|
|
2753
|
-
export declare interface SandpackEditorProps extends CodeBlockEditorProps {
|
|
2754
|
-
preset: SandpackPreset;
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2757
|
-
/**
|
|
2758
|
-
* A plugin that adds support for sandpack code blocks in the editor.
|
|
2759
|
-
* @group Sandpack
|
|
2760
|
-
*/
|
|
2761
|
-
export declare const sandpackPlugin: (params?: {
|
|
2762
|
-
sandpackConfig: SandpackConfig;
|
|
2763
|
-
} | undefined) => RealmPlugin;
|
|
2764
|
-
|
|
2765
|
-
/**
|
|
2766
|
-
* Defines a single preset that can be used to create a Sandpack sandbox.
|
|
2767
|
-
* @group Sandpack
|
|
2768
|
-
*/
|
|
2769
|
-
export declare interface SandpackPreset {
|
|
2770
|
-
/**
|
|
2771
|
-
* The name of the preset - use this to reference the preset from the defaultPreset field.
|
|
2772
|
-
*/
|
|
2773
|
-
name: string;
|
|
2774
|
-
/**
|
|
2775
|
-
* The label of the preset, displayed in the sandpack button dropdown.
|
|
2776
|
-
*/
|
|
2777
|
-
label: string | JSX.Element;
|
|
2778
|
-
/**
|
|
2779
|
-
* The meta string that will be used to identify the preset from the fenced code block. e.g. "live react"
|
|
2780
|
-
*/
|
|
2781
|
-
meta: string;
|
|
2782
|
-
/**
|
|
2783
|
-
* The sandpack template that will be used to create the sandbox. e.g. "react", "react-ts", "vanilla".
|
|
2784
|
-
*/
|
|
2785
|
-
sandpackTemplate: SandpackProviderProps['template'];
|
|
2786
|
-
/**
|
|
2787
|
-
* The sandpack theme that will be used to create the sandbox. e.g. "light", "dark".
|
|
2788
|
-
*/
|
|
2789
|
-
sandpackTheme: SandpackProviderProps['theme'];
|
|
2790
|
-
/**
|
|
2791
|
-
* The name of the file that will be created in the sandbox. e.g. "/App.js".
|
|
2792
|
-
*/
|
|
2793
|
-
snippetFileName: string;
|
|
2794
|
-
/**
|
|
2795
|
-
* The dependencies that will be added to the sandbox, just like in package.json.
|
|
2796
|
-
*/
|
|
2797
|
-
dependencies?: Record<string, string>;
|
|
2798
|
-
/**
|
|
2799
|
-
* The files that will be added to the sandbox (read-only).
|
|
2800
|
-
* The key is the name of the file, and the value is the contents of the file.
|
|
2801
|
-
*/
|
|
2802
|
-
files?: Record<string, string>;
|
|
2803
|
-
/**
|
|
2804
|
-
* The language used in the editable snippet. e.g. "jsx", "tsx", etc.
|
|
2805
|
-
*/
|
|
2806
|
-
snippetLanguage?: string;
|
|
2807
|
-
/**
|
|
2808
|
-
* The initial content of the editable snippet.
|
|
2809
|
-
*/
|
|
2810
|
-
initialSnippetContent?: string;
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
declare type SandpackProviderProps = default_2.ComponentProps<typeof SandpackProvider>;
|
|
2814
|
-
|
|
2815
2725
|
/**
|
|
2816
2726
|
* Saves the data from the image dialog
|
|
2817
2727
|
* @group Image
|
|
@@ -2931,14 +2841,6 @@ export declare const setMarkdown$: NodeRef<string>;
|
|
|
2931
2841
|
|
|
2932
2842
|
export declare const showLinkTitleField$: NodeRef<boolean>;
|
|
2933
2843
|
|
|
2934
|
-
/**
|
|
2935
|
-
* A component that displays the focused live code block's name.
|
|
2936
|
-
* For this component to work, you must enable the `sandpackPlugin` for the editor.
|
|
2937
|
-
* See {@link ConditionalContents} for an example on how to display the dropdown only when a sandpack editor is in focus.
|
|
2938
|
-
* @group Toolbar Components
|
|
2939
|
-
*/
|
|
2940
|
-
export declare const ShowSandpackInfo: () => JSX_2.Element | null;
|
|
2941
|
-
|
|
2942
2844
|
/**
|
|
2943
2845
|
* A toolbar primitive that allows you to build an UI with multiple exclusive toggle groups, like the list type toggle.
|
|
2944
2846
|
* @group Toolbar Primitives
|
package/dist/index.js
CHANGED
|
@@ -16,9 +16,7 @@ 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 {
|
|
20
|
-
import { SandpackEditor } from "./plugins/sandpack/SandpackEditor.js";
|
|
21
|
-
import { EMPTY_VALUE, codeBlockLanguages$, codeMirrorAutoLoadLanguageSupport$, codeMirrorExtensions$, codeMirrorPlugin, insertCodeMirror$, normalizeCodeBlockLanguages } from "./plugins/codemirror/index.js";
|
|
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";
|
|
24
22
|
import { directivesPlugin, insertDirective$ } from "./plugins/directives/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,
|
|
@@ -248,6 +241,7 @@ export {
|
|
|
248
241
|
fromWithinEditorRead,
|
|
249
242
|
frontmatterDialogOpen$,
|
|
250
243
|
frontmatterPlugin,
|
|
244
|
+
getCodeBlockLanguageSelectData,
|
|
251
245
|
getSelectedNode,
|
|
252
246
|
getSelectionAsMarkdown,
|
|
253
247
|
getSelectionRectangle,
|
|
@@ -277,7 +271,6 @@ export {
|
|
|
277
271
|
insertImage$,
|
|
278
272
|
insertJsx$,
|
|
279
273
|
insertMarkdown$,
|
|
280
|
-
insertSandpack$,
|
|
281
274
|
insertTable$,
|
|
282
275
|
insertThematicBreak$,
|
|
283
276
|
isMdastHTMLNode,
|
|
@@ -327,8 +320,6 @@ export {
|
|
|
327
320
|
removeLink$,
|
|
328
321
|
rootEditor$,
|
|
329
322
|
rootEditorSubscriptions$,
|
|
330
|
-
sandpackConfig$,
|
|
331
|
-
sandpackPlugin,
|
|
332
323
|
saveImage$,
|
|
333
324
|
searchOpen$,
|
|
334
325
|
searchPlugin,
|
|
@@ -10,8 +10,8 @@ import { indentWithTab } from "@codemirror/commands";
|
|
|
10
10
|
import { basicLight } from "cm6-theme-basic-light";
|
|
11
11
|
import { basicSetup } from "codemirror";
|
|
12
12
|
import { $setSelection } from "lexical";
|
|
13
|
-
import { codeMirrorExtensions$, codeMirrorAutoLoadLanguageSupport$, codeBlockLanguages$, EMPTY_VALUE } from "./index.js";
|
|
14
|
-
import { useCodeMirrorRef } from "
|
|
13
|
+
import { codeMirrorExtensions$, codeMirrorAutoLoadLanguageSupport$, codeBlockLanguages$, getCodeBlockLanguageSelectData, EMPTY_VALUE } from "./index.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,10 +24,14 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
24
24
|
iconComponentFor$,
|
|
25
25
|
codeBlockLanguages$
|
|
26
26
|
);
|
|
27
|
-
const codeMirrorRef = useCodeMirrorRef(nodeKey,
|
|
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);
|
|
31
|
+
const { value: selectValue, items: selectItems } = React__default.useMemo(
|
|
32
|
+
() => getCodeBlockLanguageSelectData(codeBlockLanguages, language),
|
|
33
|
+
[codeBlockLanguages, language]
|
|
34
|
+
);
|
|
31
35
|
const setCodeRef = React__default.useRef(setCode);
|
|
32
36
|
setCodeRef.current = setCode;
|
|
33
37
|
codeMirrorRef.current = {
|
|
@@ -94,7 +98,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
94
98
|
Select,
|
|
95
99
|
{
|
|
96
100
|
disabled: readOnly,
|
|
97
|
-
value:
|
|
101
|
+
value: selectValue,
|
|
98
102
|
onChange: (language2) => {
|
|
99
103
|
parentEditor.update(() => {
|
|
100
104
|
lexicalNode.setLanguage(language2 === EMPTY_VALUE ? "" : language2);
|
|
@@ -107,7 +111,7 @@ const CodeMirrorEditor = ({ language, nodeKey, code, focusEmitter }) => {
|
|
|
107
111
|
},
|
|
108
112
|
triggerTitle: t("codeBlock.selectLanguage", "Select code block language"),
|
|
109
113
|
placeholder: t("codeBlock.inlineLanguage", "Language"),
|
|
110
|
-
items:
|
|
114
|
+
items: selectItems
|
|
111
115
|
}
|
|
112
116
|
), /* @__PURE__ */ React__default.createElement(
|
|
113
117
|
"button",
|
|
@@ -10,9 +10,10 @@ function normalizeCodeBlockLanguages(input) {
|
|
|
10
10
|
const supportMap = {};
|
|
11
11
|
if (Array.isArray(input)) {
|
|
12
12
|
for (const lang of input) {
|
|
13
|
-
const
|
|
13
|
+
const rawCanonical = ((_a = lang.alias) == null ? void 0 : _a[0]) ?? lang.name.toLowerCase();
|
|
14
|
+
const canonical = rawCanonical || EMPTY_VALUE;
|
|
14
15
|
items.push({ value: canonical, label: lang.name });
|
|
15
|
-
keyMap[
|
|
16
|
+
keyMap[rawCanonical] = canonical;
|
|
16
17
|
if (lang.alias) {
|
|
17
18
|
for (const alias of lang.alias) {
|
|
18
19
|
keyMap[alias] = canonical;
|
|
@@ -40,6 +41,16 @@ function normalizeCodeBlockLanguages(input) {
|
|
|
40
41
|
}
|
|
41
42
|
return { items, keyMap, supportMap };
|
|
42
43
|
}
|
|
44
|
+
function getCodeBlockLanguageSelectData(normalized, language) {
|
|
45
|
+
const value = normalized.keyMap[language] ?? language;
|
|
46
|
+
if (!value || normalized.items.some((item) => item.value === value)) {
|
|
47
|
+
return { value, items: normalized.items };
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
value,
|
|
51
|
+
items: [...normalized.items, { value, label: language }]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
43
54
|
const codeBlockLanguages$ = Cell(
|
|
44
55
|
normalizeCodeBlockLanguages({
|
|
45
56
|
js: "JavaScript",
|
|
@@ -87,7 +98,7 @@ const codeMirrorPlugin = realmPlugin({
|
|
|
87
98
|
function buildCodeBlockDescriptor(normalized) {
|
|
88
99
|
return {
|
|
89
100
|
match(language, meta) {
|
|
90
|
-
return Object.hasOwn(normalized.keyMap, language ?? "")
|
|
101
|
+
return !meta || Object.hasOwn(normalized.keyMap, language ?? "");
|
|
91
102
|
},
|
|
92
103
|
priority: 1,
|
|
93
104
|
Editor: CodeMirrorEditor
|
|
@@ -99,6 +110,7 @@ export {
|
|
|
99
110
|
codeMirrorAutoLoadLanguageSupport$,
|
|
100
111
|
codeMirrorExtensions$,
|
|
101
112
|
codeMirrorPlugin,
|
|
113
|
+
getCodeBlockLanguageSelectData,
|
|
102
114
|
insertCodeMirror$,
|
|
103
115
|
normalizeCodeBlockLanguages
|
|
104
116
|
};
|
|
@@ -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,
|
|
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
|
-
}, [
|
|
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
|
const MDX_NODE_TYPES = ["mdxJsxTextElement", "mdxJsxFlowElement"];
|
|
2
2
|
function isMdastHTMLNode(node) {
|
|
3
|
-
return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(node.name
|
|
3
|
+
return MDX_NODE_TYPES.includes(node.type) && htmlTags.includes(node.name);
|
|
4
4
|
}
|
|
5
5
|
const htmlTags = [
|
|
6
6
|
"a",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { $isLexicalJsxNode } from "./LexicalJsxNode.js";
|
|
2
2
|
import { isMdastJsxNode } from "./index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isHtmlTagName } from "./jsxTagName.js";
|
|
4
4
|
const LexicalJsxVisitor = {
|
|
5
5
|
testLexicalNode: $isLexicalJsxNode,
|
|
6
6
|
visitLexicalNode({ actions, mdastParent, lexicalNode }) {
|
|
7
7
|
function traverseNestedJsxNodes(node) {
|
|
8
8
|
if ("children" in node && node.children instanceof Array) {
|
|
9
9
|
node.children.forEach((child) => {
|
|
10
|
-
if (isMdastJsxNode(child) && !
|
|
10
|
+
if (isMdastJsxNode(child) && !isHtmlTagName(child.name)) {
|
|
11
11
|
actions.registerReferredComponent(child.name);
|
|
12
12
|
}
|
|
13
13
|
traverseNestedJsxNodes(child);
|
|
@@ -187,7 +187,7 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
187
187
|
);
|
|
188
188
|
}), readOnly || rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, iconComponentFor("add_column"))));
|
|
189
189
|
})),
|
|
190
|
-
readOnly || /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, iconComponentFor("add_row"))), /* @__PURE__ */ React__default.createElement("th", null)))
|
|
190
|
+
readOnly || /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, iconComponentFor("add_row"))), /* @__PURE__ */ React__default.createElement("th", null)))
|
|
191
191
|
);
|
|
192
192
|
};
|
|
193
193
|
const Cell = ({ align, ...props }) => {
|
|
@@ -2,7 +2,7 @@ import { useCellValues } from "@mdxeditor/gurx";
|
|
|
2
2
|
import React__default from "react";
|
|
3
3
|
import styles from "../../../styles/ui.module.css.js";
|
|
4
4
|
import { $isCodeBlockNode } from "../../codeblock/CodeBlockNode.js";
|
|
5
|
-
import { codeBlockLanguages$, EMPTY_VALUE } from "../../codemirror/index.js";
|
|
5
|
+
import { codeBlockLanguages$, getCodeBlockLanguageSelectData, EMPTY_VALUE } from "../../codemirror/index.js";
|
|
6
6
|
import { editorInFocus$, activeEditor$, useTranslation } from "../../core/index.js";
|
|
7
7
|
import { Select } from "../primitives/select.js";
|
|
8
8
|
const ChangeCodeMirrorLanguage = () => {
|
|
@@ -13,14 +13,11 @@ const ChangeCodeMirrorLanguage = () => {
|
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
15
|
const rawLanguage = codeBlockNode.getLanguage();
|
|
16
|
-
|
|
17
|
-
if (currentLanguage === "") {
|
|
18
|
-
currentLanguage = EMPTY_VALUE;
|
|
19
|
-
}
|
|
16
|
+
const { value: currentLanguage, items } = getCodeBlockLanguageSelectData(codeBlockLanguages, rawLanguage);
|
|
20
17
|
return /* @__PURE__ */ React__default.createElement("div", { className: styles.selectWithLabel }, /* @__PURE__ */ React__default.createElement("label", null, t("codeBlock.language", "Code block language")), /* @__PURE__ */ React__default.createElement(
|
|
21
18
|
Select,
|
|
22
19
|
{
|
|
23
|
-
value: currentLanguage,
|
|
20
|
+
value: currentLanguage || EMPTY_VALUE,
|
|
24
21
|
onChange: (language) => {
|
|
25
22
|
theEditor == null ? void 0 : theEditor.update(() => {
|
|
26
23
|
codeBlockNode.setLanguage(language === EMPTY_VALUE ? "" : language);
|
|
@@ -33,7 +30,7 @@ const ChangeCodeMirrorLanguage = () => {
|
|
|
33
30
|
},
|
|
34
31
|
triggerTitle: t("codeBlock.selectLanguage", "Select code block language"),
|
|
35
32
|
placeholder: t("codeBlock.language", "Code block language"),
|
|
36
|
-
items
|
|
33
|
+
items
|
|
37
34
|
}
|
|
38
35
|
));
|
|
39
36
|
};
|
|
@@ -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(
|
|
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: [
|