@sveltia/ui 0.90.0 → 0.92.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/components/bottom-navigation/bottom-navigation.svelte +3 -9
- package/dist/components/bottom-navigation/bottom-navigation.svelte.d.ts +4 -39
- package/dist/components/button/button-group.svelte +2 -4
- package/dist/components/button/button-group.svelte.d.ts +3 -19
- package/dist/components/button/select-button-group.svelte +2 -13
- package/dist/components/button/select-button-group.svelte.d.ts +5 -67
- package/dist/components/calendar/calendar.d.ts +9 -0
- package/dist/components/calendar/calendar.js +43 -0
- package/dist/components/calendar/calendar.svelte +26 -27
- package/dist/components/checkbox/checkbox-group.svelte +2 -8
- package/dist/components/checkbox/checkbox-group.svelte.d.ts +4 -39
- package/dist/components/dialog/alert-dialog.svelte.d.ts +2 -3
- package/dist/components/dialog/confirmation-dialog.svelte.d.ts +2 -3
- package/dist/components/dialog/dialog.svelte +6 -7
- package/dist/components/dialog/dialog.svelte.d.ts +2 -3
- package/dist/components/dialog/prompt-dialog.svelte +2 -2
- package/dist/components/dialog/prompt-dialog.svelte.d.ts +2 -3
- package/dist/components/disclosure/disclosure.svelte +14 -16
- package/dist/components/disclosure/disclosure.svelte.d.ts +4 -38
- package/dist/components/drawer/drawer.svelte +22 -39
- package/dist/components/drawer/drawer.svelte.d.ts +3 -24
- package/dist/components/grid/grid-body.svelte +2 -3
- package/dist/components/grid/grid-body.svelte.d.ts +3 -18
- package/dist/components/grid/grid-cell.svelte +2 -8
- package/dist/components/grid/grid-cell.svelte.d.ts +3 -22
- package/dist/components/grid/grid-col-header.svelte +2 -4
- package/dist/components/grid/grid-col-header.svelte.d.ts +3 -19
- package/dist/components/grid/grid-foot.svelte +4 -9
- package/dist/components/grid/grid-foot.svelte.d.ts +3 -22
- package/dist/components/grid/grid-head.svelte +4 -9
- package/dist/components/grid/grid-head.svelte.d.ts +3 -22
- package/dist/components/grid/grid-row-header.svelte +2 -8
- package/dist/components/grid/grid-row-header.svelte.d.ts +3 -22
- package/dist/components/grid/grid-row.svelte +4 -5
- package/dist/components/grid/grid-row.svelte.d.ts +3 -19
- package/dist/components/grid/grid.d.ts +10 -0
- package/dist/components/grid/grid.js +11 -0
- package/dist/components/grid/grid.svelte +6 -7
- package/dist/components/grid/grid.svelte.d.ts +5 -21
- package/dist/components/listbox/listbox.svelte +34 -15
- package/dist/components/listbox/listbox.svelte.d.ts +5 -69
- package/dist/components/listbox/option-group.svelte +2 -8
- package/dist/components/listbox/option-group.svelte.d.ts +4 -39
- package/dist/components/listbox/option.svelte +2 -1
- package/dist/components/menu/menu-item-group.svelte +2 -6
- package/dist/components/menu/menu-item-group.svelte.d.ts +3 -22
- package/dist/components/menu/menu-item.svelte +5 -1
- package/dist/components/menu/menu.svelte +2 -8
- package/dist/components/menu/menu.svelte.d.ts +4 -39
- package/dist/components/radio/radio-group.svelte +2 -17
- package/dist/components/radio/radio-group.svelte.d.ts +5 -67
- package/dist/components/radio/radio.svelte +19 -22
- package/dist/components/radio/radio.svelte.d.ts +10 -40
- package/dist/components/resizable-pane/resizable-handle.svelte +42 -49
- package/dist/components/resizable-pane/resizable-pane-group.svelte +44 -58
- package/dist/components/resizable-pane/resizable-pane-group.svelte.d.ts +3 -19
- package/dist/components/resizable-pane/resizable-pane.svelte +2 -5
- package/dist/components/resizable-pane/resizable-pane.svelte.d.ts +3 -19
- package/dist/components/resizable-pane/sizing.d.ts +24 -0
- package/dist/components/resizable-pane/sizing.js +83 -0
- package/dist/components/select/combobox.svelte +35 -39
- package/dist/components/select/select-tags.svelte +3 -13
- package/dist/components/select/select-tags.svelte.d.ts +5 -67
- package/dist/components/slider/slider.d.ts +5 -4
- package/dist/components/slider/slider.js +28 -23
- package/dist/components/slider/slider.svelte +64 -62
- package/dist/components/slider/slider.svelte.d.ts +4 -37
- package/dist/components/switch/switch.svelte +2 -13
- package/dist/components/switch/switch.svelte.d.ts +5 -67
- package/dist/components/table/table-body.svelte +2 -4
- package/dist/components/table/table-body.svelte.d.ts +3 -19
- package/dist/components/table/table-cell.svelte +2 -8
- package/dist/components/table/table-cell.svelte.d.ts +3 -22
- package/dist/components/table/table-col-header.svelte +2 -8
- package/dist/components/table/table-col-header.svelte.d.ts +3 -22
- package/dist/components/table/table-foot.svelte +2 -8
- package/dist/components/table/table-foot.svelte.d.ts +3 -22
- package/dist/components/table/table-head.svelte +2 -8
- package/dist/components/table/table-head.svelte.d.ts +3 -22
- package/dist/components/table/table-part.svelte +2 -4
- package/dist/components/table/table-part.svelte.d.ts +3 -19
- package/dist/components/table/table-row-header.svelte +2 -8
- package/dist/components/table/table-row-header.svelte.d.ts +3 -22
- package/dist/components/table/table-row.svelte +2 -8
- package/dist/components/table/table-row.svelte.d.ts +3 -22
- package/dist/components/table/table.svelte +2 -4
- package/dist/components/table/table.svelte.d.ts +3 -19
- package/dist/components/tabs/tab-box.svelte +2 -4
- package/dist/components/tabs/tab-box.svelte.d.ts +3 -19
- package/dist/components/tabs/tab-list.svelte +2 -7
- package/dist/components/tabs/tab-list.svelte.d.ts +4 -37
- package/dist/components/tabs/tab-panel.svelte +2 -8
- package/dist/components/tabs/tab-panel.svelte.d.ts +3 -22
- package/dist/components/tabs/tab-panels.svelte +2 -8
- package/dist/components/tabs/tab-panels.svelte.d.ts +3 -22
- package/dist/components/text-editor/code-editor.js +14 -7
- package/dist/components/text-editor/code-editor.svelte +14 -22
- package/dist/components/text-editor/code-editor.svelte.d.ts +5 -103
- package/dist/components/text-editor/config.d.ts +73 -0
- package/dist/components/text-editor/config.js +110 -0
- package/dist/components/text-editor/constants.d.ts +40 -6
- package/dist/components/text-editor/constants.js +81 -7
- package/dist/components/text-editor/conversion/editor-components.js +4 -4
- package/dist/components/text-editor/conversion/html/components.d.ts +16 -0
- package/dist/components/text-editor/conversion/html/components.js +87 -0
- package/dist/components/text-editor/conversion/html/export.d.ts +10 -0
- package/dist/components/text-editor/conversion/html/export.js +360 -0
- package/dist/components/text-editor/conversion/html/import-rules.d.ts +12 -0
- package/dist/components/text-editor/conversion/html/import-rules.js +234 -0
- package/dist/components/text-editor/conversion/html/index.d.ts +10 -0
- package/dist/components/text-editor/conversion/html/index.js +33 -0
- package/dist/components/text-editor/conversion/html/paragraph.d.ts +1 -0
- package/dist/components/text-editor/conversion/html/paragraph.js +123 -0
- package/dist/components/text-editor/conversion/html/task-list.d.ts +13 -0
- package/dist/components/text-editor/conversion/html/task-list.js +82 -0
- package/dist/components/text-editor/conversion/html/unsupported.d.ts +2 -0
- package/dist/components/text-editor/conversion/html/unsupported.js +122 -0
- package/dist/components/text-editor/conversion/html/utils.d.ts +6 -0
- package/dist/components/text-editor/conversion/html/utils.js +34 -0
- package/dist/components/text-editor/conversion/import.js +33 -27
- package/dist/components/text-editor/conversion/markdown/block-conversion.d.ts +4 -0
- package/dist/components/text-editor/conversion/markdown/block-conversion.js +154 -0
- package/dist/components/text-editor/conversion/markdown/block-structure.d.ts +16 -0
- package/dist/components/text-editor/conversion/markdown/block-structure.js +254 -0
- package/dist/components/text-editor/conversion/markdown/code-blocks.d.ts +57 -0
- package/dist/components/text-editor/conversion/markdown/code-blocks.js +279 -0
- package/dist/components/text-editor/conversion/markdown/code-spans.d.ts +19 -0
- package/dist/components/text-editor/conversion/markdown/code-spans.js +71 -0
- package/dist/components/text-editor/conversion/markdown/formatting.d.ts +22 -0
- package/dist/components/text-editor/conversion/markdown/formatting.js +451 -0
- package/dist/components/text-editor/conversion/markdown/index.d.ts +10 -0
- package/dist/components/text-editor/conversion/markdown/index.js +55 -0
- package/dist/components/text-editor/conversion/markdown/placeholders.d.ts +2 -0
- package/dist/components/text-editor/conversion/markdown/placeholders.js +229 -0
- package/dist/components/text-editor/conversion/markdown/syntax.d.ts +99 -0
- package/dist/components/text-editor/conversion/markdown/syntax.js +206 -0
- package/dist/components/text-editor/conversion/placeholder-chars.d.ts +43 -0
- package/dist/components/text-editor/conversion/placeholder-chars.js +51 -0
- package/dist/components/text-editor/conversion/transformers/block-escape.d.ts +1 -0
- package/dist/components/text-editor/conversion/transformers/block-escape.js +53 -26
- package/dist/components/text-editor/conversion/transformers/code.d.ts +3 -14
- package/dist/components/text-editor/conversion/transformers/code.js +78 -16
- package/dist/components/text-editor/conversion/transformers/formatted-code.js +3 -18
- package/dist/components/text-editor/conversion/transformers/inline-code.js +3 -1
- package/dist/components/text-editor/conversion/transformers/link.js +3 -1
- package/dist/components/text-editor/conversion/transformers/raw-syntax.d.ts +0 -19
- package/dist/components/text-editor/conversion/transformers/raw-syntax.js +22 -93
- package/dist/components/text-editor/conversion/transformers/table.js +57 -16
- package/dist/components/text-editor/conversion/transformers/task-list.d.ts +24 -0
- package/dist/components/text-editor/conversion/transformers/task-list.js +53 -0
- package/dist/components/text-editor/conversion/update.d.ts +19 -2
- package/dist/components/text-editor/conversion/update.js +64 -40
- package/dist/components/text-editor/core.d.ts +12 -51
- package/dist/components/text-editor/core.js +47 -77
- package/dist/components/text-editor/editing/commands.js +9 -18
- package/dist/components/text-editor/editing/guards.d.ts +7 -0
- package/dist/components/text-editor/editing/guards.js +123 -0
- package/dist/components/text-editor/editing/raw-markdown.d.ts +7 -2
- package/dist/components/text-editor/editing/raw-markdown.js +68 -8
- package/dist/components/text-editor/editing/selection.js +6 -2
- package/dist/components/text-editor/lexical-root.svelte +89 -47
- package/dist/components/text-editor/lexical-root.svelte.d.ts +4 -67
- package/dist/components/text-editor/shiki/{facade.d.ts → engine.d.ts} +8 -8
- package/dist/components/text-editor/shiki/{facade.js → engine.js} +53 -156
- package/dist/components/text-editor/shiki/highlighter.js +5 -5
- package/dist/components/text-editor/shiki/lexical.d.ts +6 -0
- package/dist/components/text-editor/shiki/lexical.js +165 -0
- package/dist/components/text-editor/shiki/preload.js +1 -1
- package/dist/components/text-editor/shiki/source-highlight.svelte.d.ts +15 -0
- package/dist/components/text-editor/shiki/source-highlight.svelte.js +120 -0
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/components/text-editor/store.svelte.js +65 -16
- package/dist/components/text-editor/text-editor.svelte +57 -146
- package/dist/components/text-editor/text-editor.svelte.d.ts +9 -105
- package/dist/components/text-editor/toolbar/actions.d.ts +25 -0
- package/dist/components/text-editor/toolbar/actions.js +107 -0
- package/dist/components/text-editor/toolbar/align-menu-button.svelte +16 -14
- package/dist/components/text-editor/toolbar/format-text-button.svelte +27 -19
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +23 -23
- package/dist/components/text-editor/toolbar/insert-item-button.svelte +1 -1
- package/dist/components/text-editor/toolbar/insert-link-button.svelte +47 -51
- package/dist/components/text-editor/toolbar/insert-menu-button.svelte +1 -1
- package/dist/components/text-editor/toolbar/insert-table-button.svelte +35 -52
- package/dist/components/text-editor/toolbar/table-action-menu.svelte +19 -17
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +34 -11
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +0 -8
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +35 -41
- package/dist/components/text-editor/widgets/emoji-autocomplete.svelte +7 -6
- package/dist/components/text-editor/widgets/floating-link-editor.svelte +19 -32
- package/dist/components/text-editor/widgets/table-cell-menu-button.svelte +28 -32
- package/dist/components/text-field/date-time-input.svelte +7 -8
- package/dist/components/text-field/date-time-input.svelte.d.ts +3 -32
- package/dist/components/text-field/number-input.d.ts +0 -2
- package/dist/components/text-field/number-input.js +25 -25
- package/dist/components/text-field/number-input.svelte +18 -9
- package/dist/components/text-field/number-input.svelte.d.ts +1 -1
- package/dist/components/text-field/text-area.d.ts +2 -0
- package/dist/components/text-field/text-area.js +31 -0
- package/dist/components/text-field/text-area.svelte +12 -25
- package/dist/components/text-field/text-area.svelte.d.ts +5 -67
- package/dist/components/toast/toast.svelte +31 -8
- package/dist/components/toast/toast.svelte.d.ts +6 -6
- package/dist/components/toolbar/toolbar.svelte +2 -7
- package/dist/components/toolbar/toolbar.svelte.d.ts +4 -37
- package/dist/components/tree/tree-item.svelte +2 -6
- package/dist/components/tree/tree-item.svelte.d.ts +3 -22
- package/dist/components/tree/tree.svelte +3 -10
- package/dist/components/tree/tree.svelte.d.ts +4 -39
- package/dist/components/util/group.svelte +2 -7
- package/dist/components/util/group.svelte.d.ts +4 -37
- package/dist/components/util/modal.d.ts +9 -0
- package/dist/components/util/modal.js +30 -0
- package/dist/components/util/modal.svelte +16 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/locales/ar.yaml +2 -0
- package/dist/locales/bg.yaml +2 -0
- package/dist/locales/ca.yaml +2 -0
- package/dist/locales/cs.yaml +2 -0
- package/dist/locales/da.yaml +2 -0
- package/dist/locales/de.yaml +2 -0
- package/dist/locales/el.yaml +2 -0
- package/dist/locales/en-CA.yaml +2 -0
- package/dist/locales/en-GB.yaml +2 -0
- package/dist/locales/en-US.yaml +2 -0
- package/dist/locales/en-ZA.yaml +2 -0
- package/dist/locales/es-CO.yaml +2 -0
- package/dist/locales/es-ES.yaml +2 -0
- package/dist/locales/fa.yaml +2 -0
- package/dist/locales/fi.yaml +2 -0
- package/dist/locales/fr.yaml +2 -0
- package/dist/locales/he.yaml +2 -0
- package/dist/locales/hr.yaml +2 -0
- package/dist/locales/hu.yaml +176 -0
- package/dist/locales/it.yaml +2 -0
- package/dist/locales/ja.yaml +2 -0
- package/dist/locales/ko.yaml +2 -0
- package/dist/locales/nl.yaml +2 -0
- package/dist/locales/pl.yaml +2 -0
- package/dist/locales/pt-BR.yaml +2 -0
- package/dist/locales/pt-PT.yaml +2 -0
- package/dist/locales/ru.yaml +2 -0
- package/dist/locales/sk.yaml +2 -0
- package/dist/locales/sv.yaml +2 -0
- package/dist/locales/tr.yaml +2 -0
- package/dist/locales/uk.yaml +2 -0
- package/dist/locales/vi.yaml +2 -0
- package/dist/locales/zh-CN.yaml +2 -0
- package/dist/locales/zh-TW.yaml +2 -0
- package/dist/services/composite-widget.svelte.d.ts +76 -0
- package/dist/services/composite-widget.svelte.js +157 -0
- package/dist/services/focus.d.ts +2 -0
- package/dist/services/focus.js +68 -0
- package/dist/services/group.svelte.d.ts +17 -69
- package/dist/services/group.svelte.js +128 -391
- package/dist/services/label.d.ts +9 -0
- package/dist/services/label.js +22 -0
- package/dist/services/menu.d.ts +8 -0
- package/dist/services/menu.js +237 -0
- package/dist/services/navigation.d.ts +9 -0
- package/dist/services/navigation.js +13 -0
- package/dist/services/number.d.ts +2 -0
- package/dist/services/number.js +27 -0
- package/dist/services/pointer-drag.d.ts +14 -0
- package/dist/services/pointer-drag.js +89 -0
- package/dist/services/popup.svelte.js +123 -103
- package/dist/services/text.d.ts +3 -0
- package/dist/services/text.js +17 -0
- package/dist/services/tree.svelte.d.ts +29 -43
- package/dist/services/tree.svelte.js +58 -105
- package/dist/services/type-ahead.d.ts +10 -1
- package/dist/services/type-ahead.js +56 -34
- package/dist/typedefs.d.ts +108 -6
- package/dist/typedefs.js +63 -6
- package/package.json +5 -5
- package/dist/components/text-editor/conversion/html.d.ts +0 -30
- package/dist/components/text-editor/conversion/html.js +0 -857
- package/dist/components/text-editor/conversion/markdown.d.ts +0 -56
- package/dist/components/text-editor/conversion/markdown.js +0 -949
- package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +0 -28
- package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +0 -37
- package/dist/components/text-editor/toolbar/insert-component.d.ts +0 -3
- package/dist/components/text-editor/toolbar/insert-component.js +0 -37
|
@@ -3,26 +3,33 @@
|
|
|
3
3
|
* block the underlying editor works with.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const BACKTICKS = '```';
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
|
-
* Wrap code in a Markdown fenced code block.
|
|
7
|
+
* Wrap code in a Markdown fenced code block. Like Lexical, the fence is made longer than any
|
|
8
|
+
* backtick run in the code, so a fence line within the code, like a fenced code block in Markdown,
|
|
9
|
+
* doesn’t close the block.
|
|
10
10
|
* @param {string} lang Language identifier, placed after the opening fence.
|
|
11
11
|
* @param {string} code Code. If empty, the block has no content line at all.
|
|
12
12
|
* @returns {string} Fenced code block.
|
|
13
13
|
*/
|
|
14
|
-
export const toCodeBlock = (lang, code) =>
|
|
15
|
-
|
|
14
|
+
export const toCodeBlock = (lang, code) => {
|
|
15
|
+
// Not `Math.max(...runs)`, which would exceed the maximum number of arguments with many runs
|
|
16
|
+
const longestRun = (code.match(/`+/g) ?? []).reduce((max, run) => Math.max(max, run.length), 2);
|
|
17
|
+
const fence = '`'.repeat(longestRun + 1);
|
|
18
|
+
|
|
19
|
+
return code ? `${fence}${lang}\n${code}\n${fence}` : `${fence}${lang}\n${fence}`;
|
|
20
|
+
};
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
|
-
* Take a Markdown fenced code block apart.
|
|
23
|
+
* Take a Markdown fenced code block apart. The fence can be longer than three backticks, as Lexical
|
|
24
|
+
* makes it when the code contains a fence line, and the closing fence has to be as long.
|
|
19
25
|
* @param {string} markdown Fenced code block, as produced by {@link toCodeBlock}.
|
|
20
26
|
* @returns {{ lang: string, code: string }} Language identifier, `plain` if the fence has none,
|
|
21
27
|
* and the code, empty if the block has no content or `markdown` is not a code block at all.
|
|
22
28
|
*/
|
|
23
29
|
export const parseCodeBlock = (markdown) => {
|
|
24
30
|
const { lang = 'plain', code = '' } =
|
|
25
|
-
markdown.match(
|
|
31
|
+
markdown.match(/^(?<fence>`{3,})(?<lang>[^\s`]+)?\n(?:(?<code>.*)\n)?\k<fence>(?!`)/s)
|
|
32
|
+
?.groups ?? {};
|
|
26
33
|
|
|
27
34
|
return { lang, code };
|
|
28
35
|
};
|
|
@@ -10,10 +10,15 @@
|
|
|
10
10
|
import { parseCodeBlock, toCodeBlock } from './code-editor.js';
|
|
11
11
|
import LexicalRoot from './lexical-root.svelte';
|
|
12
12
|
import { createEditorStore, syncEditorProps } from './store.svelte.js';
|
|
13
|
-
import
|
|
13
|
+
import CodeLanguageSwitcher from './toolbar/code-language-switcher.svelte';
|
|
14
|
+
import ToolbarWrapper from './toolbar/toolbar-wrapper.svelte';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* @import {
|
|
17
|
+
* @import {
|
|
18
|
+
* EditorCommonProps,
|
|
19
|
+
* FormFieldStateProps,
|
|
20
|
+
* WidgetStateProps,
|
|
21
|
+
* } from '../../typedefs.js';
|
|
17
22
|
*/
|
|
18
23
|
|
|
19
24
|
/**
|
|
@@ -24,27 +29,11 @@
|
|
|
24
29
|
* update {@link code}, which it does a moment later. Bind it to wait for the change before
|
|
25
30
|
* reading the code, for example to save it. Read-only.
|
|
26
31
|
* @property {boolean} [showLanguageSwitcher] Whether to show the language selector.
|
|
27
|
-
* @property {boolean} [flex] Make the text input container flexible.
|
|
28
|
-
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
29
|
-
* @property {boolean} [hidden] Whether to hide the widget.
|
|
30
|
-
* @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
|
|
31
|
-
* attribute.
|
|
32
|
-
* @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
|
|
33
|
-
* `aria-readonly` attribute.
|
|
34
|
-
* @property {boolean} [required] Whether to mark the widget required. An alias of the
|
|
35
|
-
* `aria-required` attribute.
|
|
36
|
-
* @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
|
|
37
|
-
* `aria-invalid` attribute.
|
|
38
|
-
* @property {string} [ariaLabel] The `aria-label` attribute on the editable text box. Either
|
|
39
|
-
* this or `ariaLabelledby` is required for the editor to have an accessible name.
|
|
40
|
-
* @property {string} [ariaLabelledby] The `aria-labelledby` attribute on the editable text box.
|
|
41
|
-
* @property {string} [ariaDescribedby] The `aria-describedby` attribute on the editable text
|
|
42
|
-
* box.
|
|
43
|
-
* @property {Snippet} [children] Primary slot content.
|
|
44
32
|
*/
|
|
45
33
|
|
|
46
34
|
/**
|
|
47
|
-
* @type {
|
|
35
|
+
* @type {EditorCommonProps & WidgetStateProps & FormFieldStateProps & Props &
|
|
36
|
+
* Record<string, any>}
|
|
48
37
|
*/
|
|
49
38
|
let {
|
|
50
39
|
/* eslint-disable prefer-const */
|
|
@@ -64,7 +53,8 @@
|
|
|
64
53
|
'aria-label': ariaLabelAttr = undefined,
|
|
65
54
|
'aria-labelledby': ariaLabelledbyAttr = undefined,
|
|
66
55
|
'aria-describedby': ariaDescribedbyAttr = undefined,
|
|
67
|
-
|
|
56
|
+
// Not rendered, but kept out of `restProps`, which go on the wrapper element
|
|
57
|
+
children: _children,
|
|
68
58
|
...restProps
|
|
69
59
|
/* eslint-enable prefer-const */
|
|
70
60
|
} = $props();
|
|
@@ -130,7 +120,9 @@
|
|
|
130
120
|
style:--sui-text-editor-toolbar-height="{editorStore.toolbarHeight}px"
|
|
131
121
|
>
|
|
132
122
|
{#if showLanguageSwitcher}
|
|
133
|
-
<
|
|
123
|
+
<ToolbarWrapper disabled={disabled || readonly} ariaLabel={_('_sui.text_editor.code_editor')}>
|
|
124
|
+
<CodeLanguageSwitcher disabled={disabled || readonly} />
|
|
125
|
+
</ToolbarWrapper>
|
|
134
126
|
{/if}
|
|
135
127
|
<LexicalRoot {...labelAttrs} {hidden} {disabled} {readonly} {required} {invalid} />
|
|
136
128
|
</div>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export default CodeEditor;
|
|
2
2
|
type CodeEditor = {
|
|
3
3
|
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
-
$set?(props: Partial<Props & Record<string, any>>): void;
|
|
4
|
+
$set?(props: Partial<EditorCommonProps & WidgetStateProps & FormFieldStateProps & Props & Record<string, any>>): void;
|
|
5
5
|
};
|
|
6
6
|
/** A code editor based on Lexical. */
|
|
7
|
-
declare const CodeEditor: import("svelte").Component<{
|
|
7
|
+
declare const CodeEditor: import("svelte").Component<EditorCommonProps & WidgetStateProps & FormFieldStateProps & {
|
|
8
8
|
/**
|
|
9
9
|
* Input value.
|
|
10
10
|
*/
|
|
@@ -23,56 +23,6 @@ declare const CodeEditor: import("svelte").Component<{
|
|
|
23
23
|
* Whether to show the language selector.
|
|
24
24
|
*/
|
|
25
25
|
showLanguageSwitcher?: boolean | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Make the text input container flexible.
|
|
28
|
-
*/
|
|
29
|
-
flex?: boolean | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* The `class` attribute on the wrapper element.
|
|
32
|
-
*/
|
|
33
|
-
class?: string | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Whether to hide the widget.
|
|
36
|
-
*/
|
|
37
|
-
hidden?: boolean | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
40
|
-
* attribute.
|
|
41
|
-
*/
|
|
42
|
-
disabled?: boolean | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Whether to make the widget read-only. An alias of the
|
|
45
|
-
* `aria-readonly` attribute.
|
|
46
|
-
*/
|
|
47
|
-
readonly?: boolean | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Whether to mark the widget required. An alias of the
|
|
50
|
-
* `aria-required` attribute.
|
|
51
|
-
*/
|
|
52
|
-
required?: boolean | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Whether to mark the widget invalid. An alias of the
|
|
55
|
-
* `aria-invalid` attribute.
|
|
56
|
-
*/
|
|
57
|
-
invalid?: boolean | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* The `aria-label` attribute on the editable text box. Either
|
|
60
|
-
* this or `ariaLabelledby` is required for the editor to have an accessible name.
|
|
61
|
-
*/
|
|
62
|
-
ariaLabel?: string | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* The `aria-labelledby` attribute on the editable text box.
|
|
65
|
-
*/
|
|
66
|
-
ariaLabelledby?: string | undefined;
|
|
67
|
-
/**
|
|
68
|
-
* The `aria-describedby` attribute on the editable text
|
|
69
|
-
* box.
|
|
70
|
-
*/
|
|
71
|
-
ariaDescribedby?: string | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Primary slot content.
|
|
74
|
-
*/
|
|
75
|
-
children?: Snippet<[]> | undefined;
|
|
76
26
|
} & Record<string, any>, {}, "code" | "lang" | "pending">;
|
|
77
27
|
type Props = {
|
|
78
28
|
/**
|
|
@@ -93,55 +43,7 @@ type Props = {
|
|
|
93
43
|
* Whether to show the language selector.
|
|
94
44
|
*/
|
|
95
45
|
showLanguageSwitcher?: boolean | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Make the text input container flexible.
|
|
98
|
-
*/
|
|
99
|
-
flex?: boolean | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* The `class` attribute on the wrapper element.
|
|
102
|
-
*/
|
|
103
|
-
class?: string | undefined;
|
|
104
|
-
/**
|
|
105
|
-
* Whether to hide the widget.
|
|
106
|
-
*/
|
|
107
|
-
hidden?: boolean | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
110
|
-
* attribute.
|
|
111
|
-
*/
|
|
112
|
-
disabled?: boolean | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* Whether to make the widget read-only. An alias of the
|
|
115
|
-
* `aria-readonly` attribute.
|
|
116
|
-
*/
|
|
117
|
-
readonly?: boolean | undefined;
|
|
118
|
-
/**
|
|
119
|
-
* Whether to mark the widget required. An alias of the
|
|
120
|
-
* `aria-required` attribute.
|
|
121
|
-
*/
|
|
122
|
-
required?: boolean | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* Whether to mark the widget invalid. An alias of the
|
|
125
|
-
* `aria-invalid` attribute.
|
|
126
|
-
*/
|
|
127
|
-
invalid?: boolean | undefined;
|
|
128
|
-
/**
|
|
129
|
-
* The `aria-label` attribute on the editable text box. Either
|
|
130
|
-
* this or `ariaLabelledby` is required for the editor to have an accessible name.
|
|
131
|
-
*/
|
|
132
|
-
ariaLabel?: string | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* The `aria-labelledby` attribute on the editable text box.
|
|
135
|
-
*/
|
|
136
|
-
ariaLabelledby?: string | undefined;
|
|
137
|
-
/**
|
|
138
|
-
* The `aria-describedby` attribute on the editable text
|
|
139
|
-
* box.
|
|
140
|
-
*/
|
|
141
|
-
ariaDescribedby?: string | undefined;
|
|
142
|
-
/**
|
|
143
|
-
* Primary slot content.
|
|
144
|
-
*/
|
|
145
|
-
children?: Snippet<[]> | undefined;
|
|
146
46
|
};
|
|
147
|
-
import type {
|
|
47
|
+
import type { EditorCommonProps } from '../../typedefs.js';
|
|
48
|
+
import type { WidgetStateProps } from '../../typedefs.js';
|
|
49
|
+
import type { FormFieldStateProps } from '../../typedefs.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export function normalizeConfig({ modes, enabledButtons, components, isCodeEditor, useEmojiAutocomplete, defaultLanguage, format, multiline, ...rest }: Partial<TextEditorConfig>): NormalizedEditorConfig;
|
|
2
|
+
export function getEditorSetup(config: NormalizedEditorConfig): EditorSetup;
|
|
3
|
+
/**
|
|
4
|
+
* Editor configuration with the defaults applied.
|
|
5
|
+
*/
|
|
6
|
+
export type NormalizedEditorConfig = TextEditorConfig & {
|
|
7
|
+
useEmojiAutocomplete: boolean;
|
|
8
|
+
defaultLanguage: string;
|
|
9
|
+
format: TextEditorValueFormat;
|
|
10
|
+
multiline: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Editor configuration with the defaults applied, and the features derived from it.
|
|
14
|
+
*/
|
|
15
|
+
export type EditorSetup = {
|
|
16
|
+
/**
|
|
17
|
+
* Enabled buttons.
|
|
18
|
+
*/
|
|
19
|
+
enabledButtons: TextEditorNodeType[];
|
|
20
|
+
/**
|
|
21
|
+
* Editor components.
|
|
22
|
+
*/
|
|
23
|
+
components: TextEditorComponent[];
|
|
24
|
+
/**
|
|
25
|
+
* Whether to enable Markdown shortcuts.
|
|
26
|
+
*/
|
|
27
|
+
useMarkdownShortcuts: boolean | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the editor is a code editor.
|
|
30
|
+
*/
|
|
31
|
+
isCodeEditor: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Default code block language.
|
|
34
|
+
*/
|
|
35
|
+
defaultLanguage: string;
|
|
36
|
+
/**
|
|
37
|
+
* Value format.
|
|
38
|
+
*/
|
|
39
|
+
format: TextEditorValueFormat;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the editor accepts multiple lines.
|
|
42
|
+
*/
|
|
43
|
+
multiline: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to support code blocks.
|
|
46
|
+
*/
|
|
47
|
+
hasCodeBlock: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Whether to support table editing.
|
|
50
|
+
*/
|
|
51
|
+
hasTable: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether to support selecting a horizontal rule.
|
|
54
|
+
*/
|
|
55
|
+
hasHorizontalRule: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Whether to support links.
|
|
58
|
+
*/
|
|
59
|
+
hasLink: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to support task lists.
|
|
62
|
+
*/
|
|
63
|
+
hasTaskList: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to support horizontal rules and tables in Markdown,
|
|
66
|
+
* even without their buttons.
|
|
67
|
+
*/
|
|
68
|
+
hasBlockSyntax: boolean;
|
|
69
|
+
};
|
|
70
|
+
import type { TextEditorConfig } from '../../typedefs.js';
|
|
71
|
+
import type { TextEditorValueFormat } from '../../typedefs.js';
|
|
72
|
+
import type { TextEditorNodeType } from '../../typedefs.js';
|
|
73
|
+
import type { TextEditorComponent } from '../../typedefs.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor configuration: its defaults, and the features derived from it.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { limitToSingleLine } from './editing/single-line.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import {
|
|
9
|
+
* TextEditorComponent,
|
|
10
|
+
* TextEditorConfig,
|
|
11
|
+
* TextEditorNodeType,
|
|
12
|
+
* TextEditorValueFormat,
|
|
13
|
+
* } from '../../typedefs.js';
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Editor configuration with the defaults applied.
|
|
18
|
+
* @typedef {TextEditorConfig & {
|
|
19
|
+
* useEmojiAutocomplete: boolean,
|
|
20
|
+
* defaultLanguage: string,
|
|
21
|
+
* format: TextEditorValueFormat,
|
|
22
|
+
* multiline: boolean,
|
|
23
|
+
* }} NormalizedEditorConfig
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Editor configuration with the defaults applied, and the features derived from it.
|
|
28
|
+
* @typedef {object} EditorSetup
|
|
29
|
+
* @property {TextEditorNodeType[]} enabledButtons Enabled buttons.
|
|
30
|
+
* @property {TextEditorComponent[]} components Editor components.
|
|
31
|
+
* @property {boolean | undefined} useMarkdownShortcuts Whether to enable Markdown shortcuts.
|
|
32
|
+
* @property {boolean} isCodeEditor Whether the editor is a code editor.
|
|
33
|
+
* @property {string} defaultLanguage Default code block language.
|
|
34
|
+
* @property {TextEditorValueFormat} format Value format.
|
|
35
|
+
* @property {boolean} multiline Whether the editor accepts multiple lines.
|
|
36
|
+
* @property {boolean} hasCodeBlock Whether to support code blocks.
|
|
37
|
+
* @property {boolean} hasTable Whether to support table editing.
|
|
38
|
+
* @property {boolean} hasHorizontalRule Whether to support selecting a horizontal rule.
|
|
39
|
+
* @property {boolean} hasLink Whether to support links.
|
|
40
|
+
* @property {boolean} hasTaskList Whether to support task lists.
|
|
41
|
+
* @property {boolean} hasBlockSyntax Whether to support horizontal rules and tables in Markdown,
|
|
42
|
+
* even without their buttons.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Apply the defaults to the editor configuration, and limit it to the inline features if the editor
|
|
47
|
+
* is limited to a single line. Normalizing a configuration again gives an equal one.
|
|
48
|
+
* @param {Partial<TextEditorConfig>} config Editor configuration.
|
|
49
|
+
* @returns {NormalizedEditorConfig} Normalized configuration.
|
|
50
|
+
*/
|
|
51
|
+
export const normalizeConfig = ({
|
|
52
|
+
modes = [],
|
|
53
|
+
enabledButtons = [],
|
|
54
|
+
components = [],
|
|
55
|
+
isCodeEditor = false,
|
|
56
|
+
useEmojiAutocomplete = false,
|
|
57
|
+
defaultLanguage = 'plain',
|
|
58
|
+
format = 'markdown',
|
|
59
|
+
multiline = true,
|
|
60
|
+
...rest
|
|
61
|
+
}) =>
|
|
62
|
+
/** @type {NormalizedEditorConfig} */ (
|
|
63
|
+
limitToSingleLine({
|
|
64
|
+
...rest,
|
|
65
|
+
// The store always gives one; a configuration without one has no Markdown shortcuts
|
|
66
|
+
useMarkdownShortcuts: /** @type {boolean} */ (rest.useMarkdownShortcuts),
|
|
67
|
+
modes,
|
|
68
|
+
enabledButtons,
|
|
69
|
+
components,
|
|
70
|
+
isCodeEditor,
|
|
71
|
+
useEmojiAutocomplete,
|
|
72
|
+
defaultLanguage,
|
|
73
|
+
format,
|
|
74
|
+
multiline,
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Derive the features from the editor configuration.
|
|
80
|
+
* @param {NormalizedEditorConfig} config Editor configuration normalized with
|
|
81
|
+
* {@link normalizeConfig}, like the one the editor store holds.
|
|
82
|
+
* @returns {EditorSetup} Editor setup.
|
|
83
|
+
*/
|
|
84
|
+
export const getEditorSetup = (config) => {
|
|
85
|
+
const {
|
|
86
|
+
enabledButtons,
|
|
87
|
+
components,
|
|
88
|
+
useMarkdownShortcuts,
|
|
89
|
+
isCodeEditor,
|
|
90
|
+
defaultLanguage,
|
|
91
|
+
format,
|
|
92
|
+
multiline,
|
|
93
|
+
} = config;
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
enabledButtons,
|
|
97
|
+
components,
|
|
98
|
+
useMarkdownShortcuts,
|
|
99
|
+
isCodeEditor,
|
|
100
|
+
defaultLanguage,
|
|
101
|
+
format,
|
|
102
|
+
multiline,
|
|
103
|
+
hasCodeBlock: enabledButtons.includes('code-block') || isCodeEditor,
|
|
104
|
+
hasTable: enabledButtons.includes('table') && !isCodeEditor,
|
|
105
|
+
hasHorizontalRule: enabledButtons.includes('horizontal-rule') && !isCodeEditor,
|
|
106
|
+
hasLink: enabledButtons.includes('link'),
|
|
107
|
+
hasTaskList: enabledButtons.includes('task-list'),
|
|
108
|
+
hasBlockSyntax: !isCodeEditor && multiline,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { EditorThemeClasses, LexicalCommand } from 'lexical';
|
|
3
|
+
* @import { ListType } from '@lexical/list';
|
|
3
4
|
* @import { Transformer } from '@lexical/markdown';
|
|
4
5
|
* @import {
|
|
5
6
|
* TextEditorBlockType,
|
|
@@ -35,6 +36,38 @@ export const INLINE_BUTTON_TYPES: TextEditorInlineType[];
|
|
|
35
36
|
* @type {TextEditorBlockType[]}
|
|
36
37
|
*/
|
|
37
38
|
export const BLOCK_BUTTON_TYPES: TextEditorBlockType[];
|
|
39
|
+
/**
|
|
40
|
+
* Buttons only available for HTML, as Markdown has no syntax for them: the underline format and the
|
|
41
|
+
* alignment menu. They’re hidden for Markdown and in the plain text mode, which shows the HTML
|
|
42
|
+
* source, and they’re not enabled by default.
|
|
43
|
+
* @type {('underline' | 'align')[]}
|
|
44
|
+
*/
|
|
45
|
+
export const HTML_ONLY_BUTTON_TYPES: ("underline" | "align")[];
|
|
46
|
+
export function isHtmlOnlyButton(type: string): type is "underline" | "align";
|
|
47
|
+
/**
|
|
48
|
+
* Text formats only available for HTML, like underline. See {@link HTML_ONLY_BUTTON_TYPES}.
|
|
49
|
+
*/
|
|
50
|
+
export const HTML_ONLY_FORMAT_TYPES: TextEditorFormatType[];
|
|
51
|
+
/**
|
|
52
|
+
* Buttons not enabled by default: the HTML-only ones and the task list, a GitHub Flavored Markdown
|
|
53
|
+
* extension that not every Markdown renderer supports.
|
|
54
|
+
* @type {TextEditorNodeType[]}
|
|
55
|
+
*/
|
|
56
|
+
export const OPTIONAL_BUTTON_TYPES: TextEditorNodeType[];
|
|
57
|
+
/**
|
|
58
|
+
* Buttons enabled by default: all the inline and block level buttons but the optional ones.
|
|
59
|
+
* @type {TextEditorNodeType[]}
|
|
60
|
+
*/
|
|
61
|
+
export const DEFAULT_BUTTON_TYPES: TextEditorNodeType[];
|
|
62
|
+
/**
|
|
63
|
+
* List block types, with their Lexical list type and the command to insert the list.
|
|
64
|
+
* @type {{ type: TextEditorBlockType, listType: ListType, command: LexicalCommand<void> }[]}
|
|
65
|
+
*/
|
|
66
|
+
export const LIST_TYPES: {
|
|
67
|
+
type: TextEditorBlockType;
|
|
68
|
+
listType: ListType;
|
|
69
|
+
command: LexicalCommand<void>;
|
|
70
|
+
}[];
|
|
38
71
|
/**
|
|
39
72
|
* Map of Lexical nodes for each block type. The `paragraph` block type is excluded because it is
|
|
40
73
|
* the default block type.
|
|
@@ -42,12 +75,12 @@ export const BLOCK_BUTTON_TYPES: TextEditorBlockType[];
|
|
|
42
75
|
*/
|
|
43
76
|
export const NODE_MAP: Record<Exclude<TextEditorBlockType | "link", "paragraph">, any[]>;
|
|
44
77
|
/**
|
|
45
|
-
* Map of Lexical transformers for each
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Transformer[]
|
|
78
|
+
* Map of Lexical transformers for each button type. The `paragraph` block type has none because it
|
|
79
|
+
* is the default block type, and neither have the HTML-only buttons. Horizontal rules and tables
|
|
80
|
+
* are always supported in Markdown, so their transformers are added in `core.js`.
|
|
81
|
+
* @type {Partial<Record<TextEditorNodeType, Transformer[]>>}
|
|
49
82
|
*/
|
|
50
|
-
export const TRANSFORMER_MAP: Record<
|
|
83
|
+
export const TRANSFORMER_MAP: Partial<Record<TextEditorNodeType, Transformer[]>>;
|
|
51
84
|
/**
|
|
52
85
|
* List of Markdown tags that should be disabled in the editor when converting Lexical nodes to
|
|
53
86
|
* Markdown (but not when converting Markdown to Lexical nodes because we don’t want to lose any
|
|
@@ -94,5 +127,6 @@ import type { TextEditorFormatType } from '../../typedefs.js';
|
|
|
94
127
|
import type { TextEditorInlineType } from '../../typedefs.js';
|
|
95
128
|
import type { TextEditorBlockType } from '../../typedefs.js';
|
|
96
129
|
import type { TextEditorNodeType } from '../../typedefs.js';
|
|
97
|
-
import type {
|
|
130
|
+
import type { ListType } from '@lexical/list';
|
|
98
131
|
import type { LexicalCommand } from 'lexical';
|
|
132
|
+
import type { Transformer } from '@lexical/markdown';
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { CodeHighlightNode, CodeNode } from '@lexical/code-core';
|
|
2
2
|
import { LinkNode } from '@lexical/link';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
INSERT_CHECK_LIST_COMMAND,
|
|
5
|
+
INSERT_ORDERED_LIST_COMMAND,
|
|
6
|
+
INSERT_UNORDERED_LIST_COMMAND,
|
|
7
|
+
ListItemNode,
|
|
8
|
+
ListNode,
|
|
9
|
+
} from '@lexical/list';
|
|
4
10
|
import {
|
|
5
11
|
BOLD_ITALIC_STAR,
|
|
6
12
|
BOLD_ITALIC_UNDERSCORE,
|
|
@@ -21,9 +27,11 @@ import { createCommand } from 'lexical';
|
|
|
21
27
|
import { CODE } from './conversion/transformers/code.js';
|
|
22
28
|
import { LEADING_INLINE_CODE } from './conversion/transformers/inline-code.js';
|
|
23
29
|
import { LINK } from './conversion/transformers/link.js';
|
|
30
|
+
import { TASK_LIST } from './conversion/transformers/task-list.js';
|
|
24
31
|
|
|
25
32
|
/**
|
|
26
33
|
* @import { EditorThemeClasses, LexicalCommand } from 'lexical';
|
|
34
|
+
* @import { ListType } from '@lexical/list';
|
|
27
35
|
* @import { Transformer } from '@lexical/markdown';
|
|
28
36
|
* @import {
|
|
29
37
|
* TextEditorBlockType,
|
|
@@ -39,16 +47,22 @@ import { LINK } from './conversion/transformers/link.js';
|
|
|
39
47
|
export const EDITOR_THEME = {
|
|
40
48
|
text: {
|
|
41
49
|
/**
|
|
42
|
-
* Enable bold+italic and strikethrough styling.
|
|
50
|
+
* Enable bold+italic, underline and strikethrough styling. Lexical only uses the combined
|
|
51
|
+
* class for text that is both underlined and struck through.
|
|
43
52
|
* @see https://github.com/facebook/lexical/discussions/4381
|
|
44
53
|
*/
|
|
45
54
|
italic: 'italic',
|
|
55
|
+
underline: 'underline',
|
|
46
56
|
strikethrough: 'strikethrough',
|
|
57
|
+
underlineStrikethrough: 'underline strikethrough',
|
|
47
58
|
},
|
|
48
59
|
list: {
|
|
49
60
|
nested: {
|
|
50
61
|
listitem: 'nested',
|
|
51
62
|
},
|
|
63
|
+
// Task list items, drawn with a check box; see `lexical-root.svelte`
|
|
64
|
+
listitemChecked: 'task-list-item checked',
|
|
65
|
+
listitemUnchecked: 'task-list-item',
|
|
52
66
|
},
|
|
53
67
|
code: 'code-block',
|
|
54
68
|
// Lexical wraps a table with an element to scroll it horizontally when the table button is
|
|
@@ -73,6 +87,11 @@ export const AVAILABLE_BUTTONS = {
|
|
|
73
87
|
icon: 'format_italic',
|
|
74
88
|
inline: true,
|
|
75
89
|
},
|
|
90
|
+
underline: {
|
|
91
|
+
labelKey: 'underline',
|
|
92
|
+
icon: 'format_underlined',
|
|
93
|
+
inline: true,
|
|
94
|
+
},
|
|
76
95
|
strikethrough: {
|
|
77
96
|
labelKey: 'strikethrough',
|
|
78
97
|
icon: 'strikethrough_s',
|
|
@@ -133,6 +152,11 @@ export const AVAILABLE_BUTTONS = {
|
|
|
133
152
|
icon: 'format_list_numbered',
|
|
134
153
|
inline: false,
|
|
135
154
|
},
|
|
155
|
+
'task-list': {
|
|
156
|
+
labelKey: 'task_list',
|
|
157
|
+
icon: 'checklist',
|
|
158
|
+
inline: false,
|
|
159
|
+
},
|
|
136
160
|
blockquote: {
|
|
137
161
|
labelKey: 'blockquote',
|
|
138
162
|
icon: 'format_quote',
|
|
@@ -158,7 +182,7 @@ export const AVAILABLE_BUTTONS = {
|
|
|
158
182
|
/**
|
|
159
183
|
* @type {TextEditorFormatType[]}
|
|
160
184
|
*/
|
|
161
|
-
export const TEXT_FORMAT_BUTTON_TYPES = ['bold', 'italic', 'strikethrough', 'code'];
|
|
185
|
+
export const TEXT_FORMAT_BUTTON_TYPES = ['bold', 'italic', 'underline', 'strikethrough', 'code'];
|
|
162
186
|
|
|
163
187
|
/**
|
|
164
188
|
* @type {TextEditorInlineType[]}
|
|
@@ -178,10 +202,57 @@ export const BLOCK_BUTTON_TYPES = [
|
|
|
178
202
|
'heading-6',
|
|
179
203
|
'bulleted-list',
|
|
180
204
|
'numbered-list',
|
|
205
|
+
'task-list',
|
|
181
206
|
'blockquote',
|
|
182
207
|
'code-block',
|
|
183
208
|
];
|
|
184
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Buttons only available for HTML, as Markdown has no syntax for them: the underline format and the
|
|
212
|
+
* alignment menu. They’re hidden for Markdown and in the plain text mode, which shows the HTML
|
|
213
|
+
* source, and they’re not enabled by default.
|
|
214
|
+
* @type {('underline' | 'align')[]}
|
|
215
|
+
*/
|
|
216
|
+
export const HTML_ONLY_BUTTON_TYPES = ['underline', 'align'];
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Check whether the given button is only available for HTML. See {@link HTML_ONLY_BUTTON_TYPES}.
|
|
220
|
+
* @param {string} type Button type.
|
|
221
|
+
* @returns {type is 'underline' | 'align'} Result.
|
|
222
|
+
*/
|
|
223
|
+
export const isHtmlOnlyButton = (type) =>
|
|
224
|
+
/** @type {string[]} */ (HTML_ONLY_BUTTON_TYPES).includes(type);
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Text formats only available for HTML, like underline. See {@link HTML_ONLY_BUTTON_TYPES}.
|
|
228
|
+
*/
|
|
229
|
+
export const HTML_ONLY_FORMAT_TYPES = TEXT_FORMAT_BUTTON_TYPES.filter(isHtmlOnlyButton);
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Buttons not enabled by default: the HTML-only ones and the task list, a GitHub Flavored Markdown
|
|
233
|
+
* extension that not every Markdown renderer supports.
|
|
234
|
+
* @type {TextEditorNodeType[]}
|
|
235
|
+
*/
|
|
236
|
+
export const OPTIONAL_BUTTON_TYPES = [...HTML_ONLY_BUTTON_TYPES, 'task-list'];
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Buttons enabled by default: all the inline and block level buttons but the optional ones.
|
|
240
|
+
* @type {TextEditorNodeType[]}
|
|
241
|
+
*/
|
|
242
|
+
export const DEFAULT_BUTTON_TYPES = [...INLINE_BUTTON_TYPES, ...BLOCK_BUTTON_TYPES].filter(
|
|
243
|
+
(type) => !OPTIONAL_BUTTON_TYPES.includes(type),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* List block types, with their Lexical list type and the command to insert the list.
|
|
248
|
+
* @type {{ type: TextEditorBlockType, listType: ListType, command: LexicalCommand<void> }[]}
|
|
249
|
+
*/
|
|
250
|
+
export const LIST_TYPES = [
|
|
251
|
+
{ type: 'bulleted-list', listType: 'bullet', command: INSERT_UNORDERED_LIST_COMMAND },
|
|
252
|
+
{ type: 'numbered-list', listType: 'number', command: INSERT_ORDERED_LIST_COMMAND },
|
|
253
|
+
{ type: 'task-list', listType: 'check', command: INSERT_CHECK_LIST_COMMAND },
|
|
254
|
+
];
|
|
255
|
+
|
|
185
256
|
/**
|
|
186
257
|
* Map of Lexical nodes for each block type. The `paragraph` block type is excluded because it is
|
|
187
258
|
* the default block type.
|
|
@@ -196,16 +267,17 @@ export const NODE_MAP = {
|
|
|
196
267
|
'heading-6': [HeadingNode],
|
|
197
268
|
'bulleted-list': [ListNode, ListItemNode],
|
|
198
269
|
'numbered-list': [ListNode, ListItemNode],
|
|
270
|
+
'task-list': [ListNode, ListItemNode],
|
|
199
271
|
blockquote: [QuoteNode],
|
|
200
272
|
'code-block': [CodeNode, CodeHighlightNode],
|
|
201
273
|
link: [LinkNode],
|
|
202
274
|
};
|
|
203
275
|
|
|
204
276
|
/**
|
|
205
|
-
* Map of Lexical transformers for each
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* Transformer[]
|
|
277
|
+
* Map of Lexical transformers for each button type. The `paragraph` block type has none because it
|
|
278
|
+
* is the default block type, and neither have the HTML-only buttons. Horizontal rules and tables
|
|
279
|
+
* are always supported in Markdown, so their transformers are added in `core.js`.
|
|
280
|
+
* @type {Partial<Record<TextEditorNodeType, Transformer[]>>}
|
|
209
281
|
*/
|
|
210
282
|
export const TRANSFORMER_MAP = {
|
|
211
283
|
// ELEMENT_TRANSFORMERS
|
|
@@ -215,6 +287,8 @@ export const TRANSFORMER_MAP = {
|
|
|
215
287
|
'heading-4': [HEADING],
|
|
216
288
|
'heading-5': [HEADING],
|
|
217
289
|
'heading-6': [HEADING],
|
|
290
|
+
// Before the bulleted list, as `- [ ] item` matches both
|
|
291
|
+
'task-list': [TASK_LIST],
|
|
218
292
|
'bulleted-list': [UNORDERED_LIST],
|
|
219
293
|
'numbered-list': [ORDERED_LIST],
|
|
220
294
|
blockquote: [QUOTE],
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
$createParagraphNode as createParagraphNode,
|
|
8
8
|
$getRoot as getRoot,
|
|
9
9
|
} from 'lexical';
|
|
10
|
-
import { removeImportPlaceholders } from './markdown.js';
|
|
11
|
-
import { HTML_BLOCK_PLACEHOLDER } from './
|
|
12
|
-
import {
|
|
10
|
+
import { removeImportPlaceholders } from './markdown/index.js';
|
|
11
|
+
import { HTML_BLOCK_PLACEHOLDER } from './placeholder-chars.js';
|
|
12
|
+
import { exportValue } from './update.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @import { Transformer } from '@lexical/markdown';
|
|
@@ -53,7 +53,7 @@ export const getComponentMarkdown = ({ node, createNode, transformer, createMark
|
|
|
53
53
|
// An inline node needs a paragraph to live in
|
|
54
54
|
getRoot().append(newNode.isInline() ? createParagraphNode().append(newNode) : newNode);
|
|
55
55
|
|
|
56
|
-
markdown =
|
|
56
|
+
markdown = exportValue(editor, [transformer]);
|
|
57
57
|
},
|
|
58
58
|
{ discrete: true },
|
|
59
59
|
);
|