@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
|
@@ -11,12 +11,7 @@ import { registerRichText } from '@lexical/rich-text';
|
|
|
11
11
|
import { TableCellNode, TableExtension, TableNode, TableRowNode } from '@lexical/table';
|
|
12
12
|
import { configExtension, defineExtension } from 'lexical';
|
|
13
13
|
import { EDITOR_THEME, NODE_MAP, TRANSFORMER_MAP } from './constants.js';
|
|
14
|
-
import {
|
|
15
|
-
editorComponents,
|
|
16
|
-
HTML_CODE_IMPORT_MAP,
|
|
17
|
-
HTML_EXPORT_MAP,
|
|
18
|
-
HTML_IMPORT_MAP,
|
|
19
|
-
} from './conversion/html.js';
|
|
14
|
+
import { editorComponents, getHtmlConfig } from './conversion/html/index.js';
|
|
20
15
|
import { registerCodeHighlighting, shikiTokenizer } from './shiki/highlighter.js';
|
|
21
16
|
import { getCodeTheme, observeCodeTheme } from './shiki/theme.js';
|
|
22
17
|
import { CODE } from './conversion/transformers/code.js';
|
|
@@ -24,51 +19,42 @@ import { HR } from './conversion/transformers/hr.js';
|
|
|
24
19
|
import { RAW_HTML, RAW_SYNTAX } from './conversion/transformers/raw-syntax.js';
|
|
25
20
|
import { $ensureParagraphAfterTable, $normalizeTableHeaders } from './editing/table.js';
|
|
26
21
|
import { createTableTransformer } from './conversion/transformers/table.js';
|
|
27
|
-
import {
|
|
22
|
+
import { registerSingleLine } from './editing/single-line.js';
|
|
23
|
+
import { getEditorSetup, normalizeConfig } from './config.js';
|
|
28
24
|
import { removePlaceholdersFromMatch } from './conversion/editor-components.js';
|
|
29
25
|
import {
|
|
30
26
|
registerCodeEditorCommands,
|
|
31
27
|
registerListCommands,
|
|
32
28
|
registerTabIndentation,
|
|
33
29
|
} from './editing/commands.js';
|
|
30
|
+
import { registerGuards } from './editing/guards.js';
|
|
34
31
|
import { mergeUnregisters } from './utils.js';
|
|
35
32
|
import { registerLinkCommands } from './editing/link.js';
|
|
36
|
-
import {
|
|
33
|
+
import { registerValueExport } from './conversion/update.js';
|
|
37
34
|
import { registerPasteAsMarkdown } from './conversion/paste.js';
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
37
|
* @import { LexicalEditor } from 'lexical';
|
|
41
38
|
* @import { TextMatchTransformer, Transformer } from '@lexical/markdown';
|
|
42
|
-
* @import {
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* TextEditorNodeType,
|
|
46
|
-
* TextEditorValueFormat,
|
|
47
|
-
* } from '../../typedefs.js';
|
|
39
|
+
* @import { TextEditorConfig, TextEditorNodeType } from '../../typedefs.js';
|
|
40
|
+
* @import { EditorSetup } from './config.js';
|
|
41
|
+
* @import { ExportDetail } from './conversion/update.js';
|
|
48
42
|
*/
|
|
49
43
|
|
|
50
44
|
/**
|
|
51
45
|
* @typedef {object} InitEditorResult
|
|
52
46
|
* @property {LexicalEditor} editor Editor instance.
|
|
53
47
|
* @property {Transformer[]} enabledTransformers List of enabled Markdown transformers.
|
|
48
|
+
* @property {() => void} flush Export the content scheduled to be exported right away, instead
|
|
49
|
+
* of after the delay, so the value reflects what was just typed. Does nothing if nothing is
|
|
50
|
+
* scheduled.
|
|
54
51
|
* @property {() => void} dispose Remove all registered Lexical listeners.
|
|
55
52
|
*/
|
|
56
53
|
|
|
57
54
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
*
|
|
61
|
-
* @property {TextEditorComponent[]} components Editor components.
|
|
62
|
-
* @property {boolean | undefined} useMarkdownShortcuts Whether to enable Markdown shortcuts.
|
|
63
|
-
* @property {boolean} isCodeEditor Whether the editor is a code editor.
|
|
64
|
-
* @property {string} defaultLanguage Default code block language.
|
|
65
|
-
* @property {TextEditorValueFormat} format Value format.
|
|
66
|
-
* @property {boolean} multiline Whether the editor accepts multiple lines.
|
|
67
|
-
* @property {boolean} hasCodeBlock Whether to support code blocks.
|
|
68
|
-
* @property {boolean} hasTable Whether to support table editing.
|
|
69
|
-
* @property {boolean} hasHorizontalRule Whether to support selecting a horizontal rule.
|
|
70
|
-
* @property {boolean} hasBlockSyntax Whether to support horizontal rules and tables in Markdown,
|
|
71
|
-
* even without their buttons.
|
|
55
|
+
* @typedef {object} InitEditorOptions
|
|
56
|
+
* @property {(detail: ExportDetail) => void} [onExport] Function to call with the Markdown or HTML
|
|
57
|
+
* value and the selection state, a moment after the editor content or selection has changed.
|
|
72
58
|
*/
|
|
73
59
|
|
|
74
60
|
/**
|
|
@@ -76,37 +62,6 @@ import { registerPasteAsMarkdown } from './conversion/paste.js';
|
|
|
76
62
|
*/
|
|
77
63
|
const HISTORY_MAX_DEPTH = 200;
|
|
78
64
|
|
|
79
|
-
/**
|
|
80
|
-
* Apply the defaults to the editor configuration, and derive the features from it.
|
|
81
|
-
* @param {TextEditorConfig} config Editor configuration.
|
|
82
|
-
* @returns {EditorSetup} Editor setup.
|
|
83
|
-
*/
|
|
84
|
-
const getEditorSetup = (config) => {
|
|
85
|
-
const {
|
|
86
|
-
enabledButtons = [],
|
|
87
|
-
components = [],
|
|
88
|
-
useMarkdownShortcuts,
|
|
89
|
-
isCodeEditor = false,
|
|
90
|
-
defaultLanguage = 'plain',
|
|
91
|
-
format = 'markdown',
|
|
92
|
-
multiline = true,
|
|
93
|
-
} = limitToSingleLine(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
|
-
hasBlockSyntax: !isCodeEditor && multiline,
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
65
|
/**
|
|
111
66
|
* Get the unique items of a map keyed by button type, for the enabled buttons.
|
|
112
67
|
* @template T
|
|
@@ -136,6 +91,7 @@ const createEditorExtension = ({
|
|
|
136
91
|
hasCodeBlock,
|
|
137
92
|
hasTable,
|
|
138
93
|
hasHorizontalRule,
|
|
94
|
+
hasTaskList,
|
|
139
95
|
hasBlockSyntax,
|
|
140
96
|
}) =>
|
|
141
97
|
defineExtension({
|
|
@@ -174,15 +130,7 @@ const createEditorExtension = ({
|
|
|
174
130
|
...(hasBlockSyntax ? [HorizontalRuleNode, TableNode, TableCellNode, TableRowNode] : []),
|
|
175
131
|
],
|
|
176
132
|
theme: EDITOR_THEME,
|
|
177
|
-
|
|
178
|
-
// code blocks with their language. The export map also applies to copying
|
|
179
|
-
html:
|
|
180
|
-
format === 'html'
|
|
181
|
-
? {
|
|
182
|
-
export: HTML_EXPORT_MAP,
|
|
183
|
-
import: { ...HTML_IMPORT_MAP, ...(hasCodeBlock ? HTML_CODE_IMPORT_MAP : {}) },
|
|
184
|
-
}
|
|
185
|
-
: undefined,
|
|
133
|
+
html: format === 'html' ? getHtmlConfig({ hasCodeBlock, hasTaskList }) : undefined,
|
|
186
134
|
/**
|
|
187
135
|
* Log an error like `createEditor` does by default, instead of throwing it.
|
|
188
136
|
* @param {Error} error Error.
|
|
@@ -233,7 +181,9 @@ const getEnabledTransformers = ({ enabledButtons, components, isCodeEditor, hasB
|
|
|
233
181
|
* @param {LexicalEditor} editor Editor instance.
|
|
234
182
|
* @param {EditorSetup} setup Editor setup.
|
|
235
183
|
* @param {Transformer[]} enabledTransformers Enabled Markdown transformers.
|
|
236
|
-
* @
|
|
184
|
+
* @param {(detail: ExportDetail) => void} onExport Function to call with the exported value.
|
|
185
|
+
* @returns {{ flush: () => void, unregister: () => void }} Function to export the value right
|
|
186
|
+
* away, and function to unregister them all.
|
|
237
187
|
*/
|
|
238
188
|
const registerEditorListeners = (
|
|
239
189
|
editor,
|
|
@@ -246,11 +196,13 @@ const registerEditorListeners = (
|
|
|
246
196
|
multiline,
|
|
247
197
|
hasCodeBlock,
|
|
248
198
|
hasTable,
|
|
199
|
+
hasLink,
|
|
249
200
|
},
|
|
250
201
|
enabledTransformers,
|
|
251
|
-
|
|
202
|
+
onExport,
|
|
203
|
+
) => {
|
|
252
204
|
// The order matters, as listeners with the same priority are called in the registration order
|
|
253
|
-
mergeUnregisters(
|
|
205
|
+
const unregisterFeatures = mergeUnregisters(
|
|
254
206
|
registerRichText(editor),
|
|
255
207
|
registerDragonSupport(editor),
|
|
256
208
|
// Cap the undo stack, as each entry holds a snapshot of the whole document
|
|
@@ -273,7 +225,7 @@ const registerEditorListeners = (
|
|
|
273
225
|
})
|
|
274
226
|
: undefined,
|
|
275
227
|
hasCodeBlock ? observeCodeTheme(editor) : undefined,
|
|
276
|
-
|
|
228
|
+
hasLink ? registerLinkCommands(editor) : undefined,
|
|
277
229
|
hasTable
|
|
278
230
|
? editor.registerNodeTransform(TableNode, (table) => {
|
|
279
231
|
$ensureParagraphAfterTable(table);
|
|
@@ -286,29 +238,47 @@ const registerEditorListeners = (
|
|
|
286
238
|
})
|
|
287
239
|
: undefined,
|
|
288
240
|
registerListCommands(editor, enabledButtons),
|
|
289
|
-
|
|
241
|
+
isCodeEditor ? undefined : registerGuards(editor, { format, enabledButtons }),
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const valueExport = registerValueExport(editor, enabledTransformers, format, onExport);
|
|
245
|
+
|
|
246
|
+
const unregisterInput = mergeUnregisters(
|
|
290
247
|
registerTabIndentation(editor),
|
|
291
248
|
isCodeEditor ? undefined : registerPasteAsMarkdown(editor, enabledTransformers),
|
|
292
249
|
);
|
|
293
250
|
|
|
251
|
+
return {
|
|
252
|
+
flush: valueExport.flush,
|
|
253
|
+
unregister: mergeUnregisters(unregisterFeatures, valueExport.unregister, unregisterInput),
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
294
257
|
/**
|
|
295
258
|
* Initialize the Lexical editor.
|
|
296
|
-
* @param {TextEditorConfig} config Editor configuration.
|
|
259
|
+
* @param {Partial<TextEditorConfig>} config Editor configuration.
|
|
260
|
+
* @param {InitEditorOptions} [options] Options.
|
|
297
261
|
* @returns {InitEditorResult} Editor instance and cleanup.
|
|
298
262
|
*/
|
|
299
|
-
export const initEditor = (config) => {
|
|
300
|
-
const setup = getEditorSetup(config);
|
|
263
|
+
export const initEditor = (config, { onExport = () => {} } = {}) => {
|
|
264
|
+
const setup = getEditorSetup(normalizeConfig(config));
|
|
301
265
|
const enabledTransformers = getEnabledTransformers(setup);
|
|
302
266
|
const editor = buildEditorFromExtensions(createEditorExtension(setup));
|
|
303
267
|
|
|
304
268
|
// Let the HTML import tell the elements the components import
|
|
305
269
|
editorComponents.set(editor, setup.components);
|
|
306
270
|
|
|
307
|
-
const unregister = registerEditorListeners(
|
|
271
|
+
const { flush, unregister } = registerEditorListeners(
|
|
272
|
+
editor,
|
|
273
|
+
setup,
|
|
274
|
+
enabledTransformers,
|
|
275
|
+
onExport,
|
|
276
|
+
);
|
|
308
277
|
|
|
309
278
|
return {
|
|
310
279
|
editor,
|
|
311
280
|
enabledTransformers,
|
|
281
|
+
flush,
|
|
312
282
|
/**
|
|
313
283
|
* Remove all registered Lexical listeners.
|
|
314
284
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Commands of the code editor, lists and indentation
|
|
3
|
-
* handlers of the registered listeners.
|
|
2
|
+
* Commands of the code editor, lists and indentation.
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
import {
|
|
@@ -10,10 +9,9 @@ import {
|
|
|
10
9
|
} from '@lexical/code-core';
|
|
11
10
|
import {
|
|
12
11
|
$handleListInsertParagraph as handleListInsertParagraph,
|
|
13
|
-
INSERT_ORDERED_LIST_COMMAND,
|
|
14
|
-
INSERT_UNORDERED_LIST_COMMAND,
|
|
15
12
|
$insertList as insertList,
|
|
16
13
|
$isListItemNode as isListItemNode,
|
|
14
|
+
registerCheckList,
|
|
17
15
|
} from '@lexical/list';
|
|
18
16
|
import { $getNearestNodeOfType as getNearestNodeOfType } from '@lexical/utils';
|
|
19
17
|
import {
|
|
@@ -30,12 +28,12 @@ import {
|
|
|
30
28
|
RootNode,
|
|
31
29
|
} from 'lexical';
|
|
32
30
|
import { getNearestElementNode } from './selection.js';
|
|
31
|
+
import { LIST_TYPES } from '../constants.js';
|
|
33
32
|
import { mergeUnregisters } from '../utils.js';
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* @import { LexicalEditor } from 'lexical';
|
|
37
|
-
* @import {
|
|
38
|
-
* @import { TextEditorBlockType, TextEditorConfig } from '../../../typedefs.js';
|
|
36
|
+
* @import { TextEditorConfig } from '../../../typedefs.js';
|
|
39
37
|
*/
|
|
40
38
|
|
|
41
39
|
/**
|
|
@@ -116,25 +114,17 @@ export const registerCodeEditorCommands = (editor, defaultLanguage) =>
|
|
|
116
114
|
);
|
|
117
115
|
|
|
118
116
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*/
|
|
122
|
-
const LIST_COMMANDS = [
|
|
123
|
-
['bulleted-list', INSERT_UNORDERED_LIST_COMMAND, 'bullet'],
|
|
124
|
-
['numbered-list', INSERT_ORDERED_LIST_COMMAND, 'number'],
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Register the commands for the enabled list buttons.
|
|
117
|
+
* Register the commands for the enabled list buttons. With the task list button, a check box can be
|
|
118
|
+
* toggled with a click or the Space key.
|
|
129
119
|
* @param {LexicalEditor} editor Editor instance.
|
|
130
120
|
* @param {TextEditorConfig['enabledButtons']} enabledButtons Enabled buttons.
|
|
131
121
|
* @returns {() => void} Cleanup handler.
|
|
132
122
|
*/
|
|
133
123
|
export const registerListCommands = (editor, enabledButtons = []) => {
|
|
134
|
-
const enabledLists =
|
|
124
|
+
const enabledLists = LIST_TYPES.filter(({ type }) => enabledButtons.includes(type));
|
|
135
125
|
|
|
136
126
|
return mergeUnregisters(
|
|
137
|
-
...enabledLists.map((
|
|
127
|
+
...enabledLists.map(({ command, listType }) =>
|
|
138
128
|
editor.registerCommand(
|
|
139
129
|
command,
|
|
140
130
|
() => {
|
|
@@ -153,6 +143,7 @@ export const registerListCommands = (editor, enabledButtons = []) => {
|
|
|
153
143
|
COMMAND_PRIORITY_NORMAL,
|
|
154
144
|
)
|
|
155
145
|
: undefined,
|
|
146
|
+
enabledButtons.includes('task-list') ? registerCheckList(editor) : undefined,
|
|
156
147
|
);
|
|
157
148
|
};
|
|
158
149
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function registerGuards(editor: LexicalEditor, { format, enabledButtons }: {
|
|
2
|
+
format: TextEditorValueFormat;
|
|
3
|
+
enabledButtons: TextEditorConfig["enabledButtons"];
|
|
4
|
+
}): () => void;
|
|
5
|
+
import type { LexicalEditor } from 'lexical';
|
|
6
|
+
import type { TextEditorValueFormat } from '../../../typedefs.js';
|
|
7
|
+
import type { TextEditorConfig } from '../../../typedefs.js';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards that keep the formats and blocks a field can’t hold out of the editor, as they could come
|
|
3
|
+
* in anyway with a keyboard shortcut Lexical handles on its own, pasted HTML or a stored value.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ListNode } from '@lexical/list';
|
|
7
|
+
import {
|
|
8
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
9
|
+
FORMAT_TEXT_COMMAND,
|
|
10
|
+
$getSelection as getSelection,
|
|
11
|
+
$isRangeSelection as isRangeSelection,
|
|
12
|
+
$isTextNode as isTextNode,
|
|
13
|
+
TextNode,
|
|
14
|
+
} from 'lexical';
|
|
15
|
+
import { HTML_ONLY_FORMAT_TYPES, isHtmlOnlyButton, LIST_TYPES } from '../constants.js';
|
|
16
|
+
import { mergeUnregisters } from '../utils.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @import { LexicalEditor, TextFormatType } from 'lexical';
|
|
20
|
+
* @import { TextEditorConfig, TextEditorValueFormat } from '../../../typedefs.js';
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Remove the given format from all the text in the selection, including the text partly selected,
|
|
25
|
+
* or from the text to be typed at the caret. Unlike Lexical’s own toggle, which follows the text at
|
|
26
|
+
* the start of the selection, it never applies the format.
|
|
27
|
+
* @param {TextFormatType} type Format type.
|
|
28
|
+
*/
|
|
29
|
+
const $removeFormat = (type) => {
|
|
30
|
+
const selection = getSelection();
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
!isRangeSelection(selection) ||
|
|
34
|
+
!(
|
|
35
|
+
selection.hasFormat(type) ||
|
|
36
|
+
selection.getNodes().some((node) => isTextNode(node) && node.hasFormat(type))
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Align every node with a format that doesn’t have it
|
|
43
|
+
selection.formatText(type, 0);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Keep the HTML-only text formats, like underline, out of the editor unless their buttons are
|
|
48
|
+
* enabled for HTML. Lexical applies underline with the Ctrl/Cmd+U shortcut on its own, and pasted
|
|
49
|
+
* HTML can bring it in as well. For Markdown, which has no syntax for them and would drop them when
|
|
50
|
+
* saved, the formats are removed from any text that gets them, and the shortcut does nothing. For
|
|
51
|
+
* HTML without the button, the shortcut can only remove an existing format, like one in the stored
|
|
52
|
+
* value or in pasted text, which would otherwise have no button to undo it.
|
|
53
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
54
|
+
* @param {object} args Arguments.
|
|
55
|
+
* @param {TextEditorValueFormat} args.format Value format.
|
|
56
|
+
* @param {TextEditorConfig['enabledButtons']} args.enabledButtons Enabled buttons.
|
|
57
|
+
* @returns {() => void} Cleanup handler.
|
|
58
|
+
*/
|
|
59
|
+
const registerFormatGuard = (editor, { format, enabledButtons = [] }) => {
|
|
60
|
+
if (format !== 'html') {
|
|
61
|
+
return mergeUnregisters(
|
|
62
|
+
editor.registerNodeTransform(TextNode, (node) => {
|
|
63
|
+
HTML_ONLY_FORMAT_TYPES.forEach((type) => {
|
|
64
|
+
if (node.hasFormat(type)) {
|
|
65
|
+
node.toggleFormat(type);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}),
|
|
69
|
+
editor.registerCommand(FORMAT_TEXT_COMMAND, isHtmlOnlyButton, COMMAND_PRIORITY_CRITICAL),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return editor.registerCommand(
|
|
74
|
+
FORMAT_TEXT_COMMAND,
|
|
75
|
+
(type) => {
|
|
76
|
+
if (!isHtmlOnlyButton(type) || enabledButtons.includes(type)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
$removeFormat(type);
|
|
81
|
+
|
|
82
|
+
return true;
|
|
83
|
+
},
|
|
84
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Turn a task list into a bulleted list without the task list button, as its items couldn’t be
|
|
90
|
+
* toggled. One can come in with pasted HTML, for example. `ListNode` is only registered with a list
|
|
91
|
+
* button, so nothing is registered without any.
|
|
92
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
93
|
+
* @param {TextEditorConfig['enabledButtons']} enabledButtons Enabled buttons.
|
|
94
|
+
* @returns {(() => void) | undefined} Cleanup handler, if anything is registered.
|
|
95
|
+
*/
|
|
96
|
+
const registerTaskListGuard = (editor, enabledButtons = []) => {
|
|
97
|
+
if (
|
|
98
|
+
enabledButtons.includes('task-list') ||
|
|
99
|
+
!LIST_TYPES.some(({ type }) => enabledButtons.includes(type))
|
|
100
|
+
) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return editor.registerNodeTransform(ListNode, (list) => {
|
|
105
|
+
if (list.getListType() === 'check') {
|
|
106
|
+
list.setListType('bullet');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Register all the guards.
|
|
113
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
114
|
+
* @param {object} args Arguments.
|
|
115
|
+
* @param {TextEditorValueFormat} args.format Value format.
|
|
116
|
+
* @param {TextEditorConfig['enabledButtons']} args.enabledButtons Enabled buttons.
|
|
117
|
+
* @returns {() => void} Cleanup handler.
|
|
118
|
+
*/
|
|
119
|
+
export const registerGuards = (editor, { format, enabledButtons = [] }) =>
|
|
120
|
+
mergeUnregisters(
|
|
121
|
+
registerFormatGuard(editor, { format, enabledButtons }),
|
|
122
|
+
registerTaskListGuard(editor, enabledButtons),
|
|
123
|
+
);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export function getBlockType(state: RawTextState
|
|
2
|
-
|
|
1
|
+
export function getBlockType(state: RawTextState, { hasTaskList }?: {
|
|
2
|
+
hasTaskList?: boolean | undefined;
|
|
3
|
+
}): TextEditorBlockType;
|
|
4
|
+
export function toggleInlineFormat({ value, start, end }: RawTextState, type: Exclude<TextEditorFormatType, "underline">): RawTextEdit;
|
|
3
5
|
export function setBlockType(state: RawTextState, type: TextEditorBlockType): RawTextEdit;
|
|
4
6
|
export function insertLink({ value, start, end }: RawTextState, { url, text }: {
|
|
5
7
|
url: string;
|
|
@@ -23,6 +25,9 @@ export function joinLines({ value, caret }: {
|
|
|
23
25
|
caret: number;
|
|
24
26
|
};
|
|
25
27
|
export function registerRawTextSingleLine(textArea: HTMLTextAreaElement): () => void;
|
|
28
|
+
export function registerRawTextSelection(textArea: HTMLTextAreaElement, onChange: (blockType: TextEditorBlockType) => void, { hasTaskList }?: {
|
|
29
|
+
hasTaskList?: (() => boolean) | undefined;
|
|
30
|
+
}): () => void;
|
|
26
31
|
/**
|
|
27
32
|
* Current value and selection of the `<textarea>`.
|
|
28
33
|
*/
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Markdown editing helpers for the plain text mode of the text editor, where the toolbar buttons
|
|
3
3
|
* edit the Markdown source in the `<textarea>` instead of Lexical nodes. Apart from
|
|
4
4
|
* {@link getRawTextState}, {@link applyRawTextEdit}, {@link editRawText},
|
|
5
|
-
* {@link registerRawTextShortcut}
|
|
6
|
-
* takes the current value and selection, and returns
|
|
5
|
+
* {@link registerRawTextShortcut}, {@link insertComponent} and the other functions that register
|
|
6
|
+
* listeners, everything here is pure: a function takes the current value and selection, and returns
|
|
7
|
+
* the edit to apply.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { isMac, matchesShortcuts } from '@sveltia/utils/events';
|
|
10
11
|
import { getComponentMarkdown } from '../conversion/editor-components.js';
|
|
12
|
+
import { TASK_LIST_ITEM_REGEX } from '../conversion/transformers/task-list.js';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* @import {
|
|
@@ -37,8 +39,8 @@ import { getComponentMarkdown } from '../conversion/editor-components.js';
|
|
|
37
39
|
*/
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
|
-
* Markdown markers for the inline formats.
|
|
41
|
-
* @type {Record<TextEditorFormatType, string>}
|
|
42
|
+
* Markdown markers for the inline formats. Markdown has no syntax for underline.
|
|
43
|
+
* @type {Record<Exclude<TextEditorFormatType, 'underline'>, string>}
|
|
42
44
|
*/
|
|
43
45
|
const INLINE_MARKERS = {
|
|
44
46
|
bold: '**',
|
|
@@ -48,9 +50,12 @@ const INLINE_MARKERS = {
|
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
* Prefix of a heading, list item or blockquote line
|
|
53
|
+
* Prefix of a heading, list item or blockquote line, including the check box of a task list item,
|
|
54
|
+
* which can only be one or two spaces after the marker; see `TASK_LIST_ITEM_REGEX`.
|
|
52
55
|
*/
|
|
53
|
-
const BLOCK_PREFIX_REGEX =
|
|
56
|
+
const BLOCK_PREFIX_REGEX =
|
|
57
|
+
/^(?:#{1,6}[ \t]+|>[ \t]?|[-*+](?:[ \t]{1,2}\[[ xX]\][ \t]+|[ \t]+)|\d+[.)][ \t]+)/;
|
|
58
|
+
|
|
54
59
|
const CODE_FENCE_REGEX = /^[ \t]*(?:```|~~~)/;
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -111,9 +116,13 @@ const findCodeBlock = (lines, lineIndex) => {
|
|
|
111
116
|
/**
|
|
112
117
|
* Get the type of the block where the selection starts.
|
|
113
118
|
* @param {RawTextState} state Current state.
|
|
119
|
+
* @param {object} [options] Options.
|
|
120
|
+
* @param {boolean} [options.hasTaskList] Whether the task list button is enabled, which it isn’t
|
|
121
|
+
* by default. Without it, a task list item is a bulleted list item, as the rich text editor imports
|
|
122
|
+
* it.
|
|
114
123
|
* @returns {TextEditorBlockType} Block type.
|
|
115
124
|
*/
|
|
116
|
-
export const getBlockType = (state) => {
|
|
125
|
+
export const getBlockType = (state, { hasTaskList = false } = {}) => {
|
|
117
126
|
const lines = state.value.split('\n');
|
|
118
127
|
const lineIndex = getStartLineIndex(state);
|
|
119
128
|
const line = lines[lineIndex];
|
|
@@ -128,6 +137,10 @@ export const getBlockType = (state) => {
|
|
|
128
137
|
return /** @type {TextEditorBlockType} */ (`heading-${hashes.length}`);
|
|
129
138
|
}
|
|
130
139
|
|
|
140
|
+
if (hasTaskList && TASK_LIST_ITEM_REGEX.test(line)) {
|
|
141
|
+
return 'task-list';
|
|
142
|
+
}
|
|
143
|
+
|
|
131
144
|
if (/^[-*+][ \t]/.test(line)) {
|
|
132
145
|
return 'bulleted-list';
|
|
133
146
|
}
|
|
@@ -147,7 +160,7 @@ export const getBlockType = (state) => {
|
|
|
147
160
|
* Wrap the selection with the Markdown markers of the given inline format, or unwrap it if it’s
|
|
148
161
|
* already formatted. Without a selection, the markers are inserted with the caret in between.
|
|
149
162
|
* @param {RawTextState} state Current state.
|
|
150
|
-
* @param {TextEditorFormatType} type Format type.
|
|
163
|
+
* @param {Exclude<TextEditorFormatType, 'underline'>} type Format type.
|
|
151
164
|
* @returns {RawTextEdit} Edit.
|
|
152
165
|
*/
|
|
153
166
|
export const toggleInlineFormat = ({ value, start, end }, type) => {
|
|
@@ -273,6 +286,10 @@ export const setBlockType = (state, type) => {
|
|
|
273
286
|
return line.trim() ? '- ' : '';
|
|
274
287
|
}
|
|
275
288
|
|
|
289
|
+
if (type === 'task-list') {
|
|
290
|
+
return line.trim() ? '- [ ] ' : '';
|
|
291
|
+
}
|
|
292
|
+
|
|
276
293
|
if (type === 'numbered-list') {
|
|
277
294
|
if (!line.trim()) {
|
|
278
295
|
return '';
|
|
@@ -638,3 +655,46 @@ export const registerRawTextSingleLine = (textArea) => {
|
|
|
638
655
|
textArea.removeEventListener('input', onInput, { capture: true });
|
|
639
656
|
};
|
|
640
657
|
};
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Events after which the selection of the `<textarea>` may have changed.
|
|
661
|
+
*/
|
|
662
|
+
const SELECTION_EVENT_TYPES = ['selectionchange', 'select', 'input', 'keyup', 'mouseup', 'focus'];
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Keep track of the type of the block where the selection of the `<textarea>` starts, so the
|
|
666
|
+
* toolbar can reflect it like in the rich text mode. Until the `<textarea>` gets the focus, its
|
|
667
|
+
* caret is at the end of the value rather than where the user would expect, so the block type is
|
|
668
|
+
* not detected yet, and is reported as a paragraph.
|
|
669
|
+
* @param {HTMLTextAreaElement} textArea `<textarea>` element.
|
|
670
|
+
* @param {(blockType: TextEditorBlockType) => void} onChange Function to call with the block type,
|
|
671
|
+
* right away and whenever the selection may have changed.
|
|
672
|
+
* @param {object} [options] Options.
|
|
673
|
+
* @param {() => boolean} [options.hasTaskList] Function that tells whether the task list button is
|
|
674
|
+
* enabled; see {@link getBlockType}. It’s called on every change, so it can follow the editor
|
|
675
|
+
* configuration.
|
|
676
|
+
* @returns {() => void} Function to stop tracking the selection.
|
|
677
|
+
*/
|
|
678
|
+
export const registerRawTextSelection = (
|
|
679
|
+
textArea,
|
|
680
|
+
onChange,
|
|
681
|
+
{ hasTaskList = () => false } = {},
|
|
682
|
+
) => {
|
|
683
|
+
/**
|
|
684
|
+
* Report the block type.
|
|
685
|
+
*/
|
|
686
|
+
const update = () => {
|
|
687
|
+
onChange(
|
|
688
|
+
document.activeElement === textArea
|
|
689
|
+
? getBlockType(getRawTextState(textArea), { hasTaskList: hasTaskList() })
|
|
690
|
+
: 'paragraph',
|
|
691
|
+
);
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
update();
|
|
695
|
+
SELECTION_EVENT_TYPES.forEach((type) => textArea.addEventListener(type, update));
|
|
696
|
+
|
|
697
|
+
return () => {
|
|
698
|
+
SELECTION_EVENT_TYPES.forEach((type) => textArea.removeEventListener(type, update));
|
|
699
|
+
};
|
|
700
|
+
};
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
$getSelection as getSelection,
|
|
20
20
|
$isRangeSelection as isRangeSelection,
|
|
21
21
|
} from 'lexical';
|
|
22
|
-
import { BLOCK_BUTTON_TYPES, TEXT_FORMAT_BUTTON_TYPES } from '../constants.js';
|
|
22
|
+
import { BLOCK_BUTTON_TYPES, LIST_TYPES, TEXT_FORMAT_BUTTON_TYPES } from '../constants.js';
|
|
23
23
|
import { $getSelectedAlignment } from './alignment.js';
|
|
24
24
|
import { $getSelectedTableCellKey } from './table.js';
|
|
25
25
|
|
|
@@ -91,7 +91,11 @@ export const getSelectionTypes = () => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
if (isListNode(parent)) {
|
|
94
|
-
|
|
94
|
+
const listType = parent.getListType();
|
|
95
|
+
|
|
96
|
+
return /** @type {TextEditorBlockType} */ (
|
|
97
|
+
LIST_TYPES.find((list) => list.listType === listType)?.type
|
|
98
|
+
);
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
if (isQuoteNode(parent)) {
|