@sveltia/ui 0.91.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/conversion/editor-components.js +4 -4
- package/dist/components/text-editor/conversion/html/export.js +1 -1
- package/dist/components/text-editor/conversion/import.js +32 -26
- 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/update.d.ts +19 -2
- package/dist/components/text-editor/conversion/update.js +63 -39
- package/dist/components/text-editor/core.d.ts +12 -51
- package/dist/components/text-editor/core.js +44 -66
- package/dist/components/text-editor/editing/raw-markdown.d.ts +3 -0
- package/dist/components/text-editor/editing/raw-markdown.js +46 -2
- package/dist/components/text-editor/lexical-root.svelte +49 -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 +53 -145
- package/dist/components/text-editor/text-editor.svelte.d.ts +5 -103
- 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 +26 -24
- 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 +16 -4
- 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 +34 -33
- 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/hu.yaml +176 -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 +103 -4
- package/dist/typedefs.js +60 -4
- package/package.json +1 -1
- 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
|
@@ -2,8 +2,9 @@
|
|
|
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';
|
|
@@ -654,3 +655,46 @@ export const registerRawTextSingleLine = (textArea) => {
|
|
|
654
655
|
textArea.removeEventListener('input', onInput, { capture: true });
|
|
655
656
|
};
|
|
656
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
|
+
};
|
|
@@ -1,45 +1,34 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { $getRoot as getRoot, HISTORY_MERGE_TAG } from 'lexical';
|
|
3
3
|
import { getContext, onMount, untrack } from 'svelte';
|
|
4
|
+
import { on } from 'svelte/events';
|
|
4
5
|
import { IMPORT_UPDATE_TAG } from './constants.js';
|
|
5
6
|
import { handleEditorMouseDown, isStaticDecoratorContent } from './editing/caret.js';
|
|
6
7
|
import { initEditor } from './core.js';
|
|
8
|
+
import { mergeUnregisters } from './utils.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
* @import {
|
|
10
|
-
* @import { TextEditorStore } from '../../typedefs.js';
|
|
11
|
+
* @import { ExportDetail } from './conversion/update.js';
|
|
12
|
+
* @import { FormFieldStateProps, TextEditorStore, WidgetStateProps } from '../../typedefs.js';
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @typedef {object} Props
|
|
15
|
-
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
16
17
|
* @property {'ltr' | 'rtl' | 'auto'} [dir] Direction of the text. With `auto` or no value, each
|
|
17
18
|
* paragraph takes the direction of its own text.
|
|
18
|
-
* @property {boolean} [hidden] Whether to hide the widget.
|
|
19
|
-
* @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
|
|
20
|
-
* attribute.
|
|
21
|
-
* @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
|
|
22
|
-
* `aria-readonly` attribute.
|
|
23
|
-
* @property {boolean} [required] Whether to mark the widget required. An alias of the
|
|
24
|
-
* `aria-required` attribute.
|
|
25
|
-
* @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
|
|
26
|
-
* `aria-invalid` attribute.
|
|
27
|
-
* @property {Snippet} [children] Primary slot content.
|
|
28
19
|
*/
|
|
29
20
|
|
|
30
21
|
/**
|
|
31
|
-
* @type {Props & Record<string, any>}
|
|
22
|
+
* @type {WidgetStateProps & FormFieldStateProps & Props & Record<string, any>}
|
|
32
23
|
*/
|
|
33
24
|
let {
|
|
34
25
|
/* eslint-disable prefer-const */
|
|
35
|
-
class: className,
|
|
36
26
|
dir = undefined,
|
|
37
27
|
hidden = false,
|
|
38
28
|
disabled = false,
|
|
39
29
|
readonly = false,
|
|
40
30
|
required = false,
|
|
41
31
|
invalid = false,
|
|
42
|
-
children,
|
|
43
32
|
...restProps
|
|
44
33
|
/* eslint-enable prefer-const */
|
|
45
34
|
} = $props();
|
|
@@ -80,10 +69,10 @@
|
|
|
80
69
|
});
|
|
81
70
|
|
|
82
71
|
/**
|
|
83
|
-
* Update
|
|
84
|
-
* @param {
|
|
72
|
+
* Update the input value and the selection state whenever the editor exports its content.
|
|
73
|
+
* @param {ExportDetail} detail Exported value and selection state.
|
|
85
74
|
*/
|
|
86
|
-
const
|
|
75
|
+
const onExport = ({ value: exportedValue, selection }) => {
|
|
87
76
|
const { hasConverterError, useRichText, inputValue } = editorStore;
|
|
88
77
|
|
|
89
78
|
// The content has been converted, if it has changed at all
|
|
@@ -95,18 +84,13 @@
|
|
|
95
84
|
return;
|
|
96
85
|
}
|
|
97
86
|
|
|
98
|
-
const { value: exportedValue, selection } = /** @type {CustomEvent} */ (event).detail;
|
|
99
87
|
// Keep the value as given when the content is the one last imported, which the editor only
|
|
100
88
|
// writes in its own Markdown style, e.g. `_text_` for `*text*`: that’s not a change, whether
|
|
101
89
|
// the content is untouched or the user has undone their changes to it
|
|
102
90
|
const newValue = editorStore.getImportedValue(exportedValue) ?? exportedValue;
|
|
103
91
|
|
|
104
92
|
if (inputValue !== newValue) {
|
|
105
|
-
|
|
106
|
-
// Lexical nodes and selection, then restore the state
|
|
107
|
-
editorStore.useRichText = false;
|
|
108
|
-
editorStore.inputValue = newValue;
|
|
109
|
-
editorStore.useRichText = true;
|
|
93
|
+
editorStore.setExportedValue(newValue);
|
|
110
94
|
}
|
|
111
95
|
|
|
112
96
|
editorStore.selection = selection;
|
|
@@ -230,24 +214,45 @@
|
|
|
230
214
|
}
|
|
231
215
|
};
|
|
232
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Pass what was just typed on as soon as the focus leaves the editor, rather than after the
|
|
219
|
+
* delay, so the value is up to date by the time the user acts on it, like with a button. That
|
|
220
|
+
* includes a nested editor in a component, which passes the change on to this editor through the
|
|
221
|
+
* component.
|
|
222
|
+
* @param {FocusEvent} event `focusout` event.
|
|
223
|
+
*/
|
|
224
|
+
const onRootFocusOut = ({ relatedTarget }) => {
|
|
225
|
+
if (!lexicalRoot?.contains(/** @type {Node | null} */ (relatedTarget))) {
|
|
226
|
+
// The root may be being removed; see above
|
|
227
|
+
untrack(() => {
|
|
228
|
+
editorStore.flushExport();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
233
|
onMount(() => {
|
|
234
|
-
const { editor, enabledTransformers, dispose } = initEditor(editorStore.config
|
|
234
|
+
const { editor, enabledTransformers, flush, dispose } = initEditor(editorStore.config, {
|
|
235
|
+
onExport,
|
|
236
|
+
});
|
|
235
237
|
|
|
236
238
|
editorStore.editor = editor;
|
|
237
239
|
editorStore.enabledTransformers = enabledTransformers;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
lexicalRoot
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
240
|
+
editorStore.flushExport = flush;
|
|
241
|
+
|
|
242
|
+
// The root is bound before this runs
|
|
243
|
+
const root = /** @type {HTMLElement} */ (lexicalRoot);
|
|
244
|
+
|
|
245
|
+
const unregister = mergeUnregisters(
|
|
246
|
+
on(root, 'focusout', onRootFocusOut),
|
|
247
|
+
on(root, 'click', onClick),
|
|
248
|
+
on(root, 'mousedown', onMouseDown),
|
|
249
|
+
on(root, 'mousedown', onComponentMouseDown),
|
|
250
|
+
on(document, 'focusin', onFocusIn),
|
|
251
|
+
on(document, 'focusout', onFocusOut),
|
|
252
|
+
// A change made by the user is converted to Markdown a moment later, so report it as pending
|
|
253
|
+
// until then. An import, or an update that only changes how the content looks, e.g. the code
|
|
254
|
+
// highlighting, isn’t a change
|
|
255
|
+
editor.registerUpdateListener(({ dirtyElements, dirtyLeaves, tags }) => {
|
|
251
256
|
if (
|
|
252
257
|
(dirtyElements.size || dirtyLeaves.size) &&
|
|
253
258
|
!tags.has(IMPORT_UPDATE_TAG) &&
|
|
@@ -259,17 +264,14 @@
|
|
|
259
264
|
// An editor component with the focus may have been removed, which doesn’t fire `focusout`
|
|
260
265
|
// in Firefox and Safari
|
|
261
266
|
checkComponentFocus();
|
|
262
|
-
},
|
|
267
|
+
}),
|
|
263
268
|
);
|
|
264
269
|
|
|
265
270
|
return () => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
lexicalRoot?.removeEventListener('mousedown', onComponentMouseDown);
|
|
271
|
-
document.removeEventListener('focusin', onFocusIn);
|
|
272
|
-
document.removeEventListener('focusout', onFocusOut);
|
|
271
|
+
// Pass on what was just typed, as Firefox and Safari don’t fire `focusout` when the focused
|
|
272
|
+
// root is removed. This does nothing if the change has been passed on already
|
|
273
|
+
flush();
|
|
274
|
+
unregister();
|
|
273
275
|
dispose();
|
|
274
276
|
editor.setRootElement(null);
|
|
275
277
|
editorStore.initialized = false;
|
|
@@ -1,84 +1,21 @@
|
|
|
1
1
|
export default LexicalRoot;
|
|
2
2
|
type LexicalRoot = {
|
|
3
3
|
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
-
$set?(props: Partial<Props & Record<string, any>>): void;
|
|
4
|
+
$set?(props: Partial<WidgetStateProps & FormFieldStateProps & Props & Record<string, any>>): void;
|
|
5
5
|
};
|
|
6
|
-
declare const LexicalRoot: import("svelte").Component<{
|
|
7
|
-
/**
|
|
8
|
-
* The `class` attribute on the wrapper element.
|
|
9
|
-
*/
|
|
10
|
-
class?: string | undefined;
|
|
6
|
+
declare const LexicalRoot: import("svelte").Component<WidgetStateProps & FormFieldStateProps & {
|
|
11
7
|
/**
|
|
12
8
|
* Direction of the text. With `auto` or no value, each
|
|
13
9
|
* paragraph takes the direction of its own text.
|
|
14
10
|
*/
|
|
15
11
|
dir?: "ltr" | "rtl" | "auto" | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Whether to hide the widget.
|
|
18
|
-
*/
|
|
19
|
-
hidden?: boolean | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
22
|
-
* attribute.
|
|
23
|
-
*/
|
|
24
|
-
disabled?: boolean | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Whether to make the widget read-only. An alias of the
|
|
27
|
-
* `aria-readonly` attribute.
|
|
28
|
-
*/
|
|
29
|
-
readonly?: boolean | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* Whether to mark the widget required. An alias of the
|
|
32
|
-
* `aria-required` attribute.
|
|
33
|
-
*/
|
|
34
|
-
required?: boolean | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Whether to mark the widget invalid. An alias of the
|
|
37
|
-
* `aria-invalid` attribute.
|
|
38
|
-
*/
|
|
39
|
-
invalid?: boolean | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Primary slot content.
|
|
42
|
-
*/
|
|
43
|
-
children?: Snippet<[]> | undefined;
|
|
44
12
|
} & Record<string, any>, {}, "">;
|
|
45
13
|
type Props = {
|
|
46
|
-
/**
|
|
47
|
-
* The `class` attribute on the wrapper element.
|
|
48
|
-
*/
|
|
49
|
-
class?: string | undefined;
|
|
50
14
|
/**
|
|
51
15
|
* Direction of the text. With `auto` or no value, each
|
|
52
16
|
* paragraph takes the direction of its own text.
|
|
53
17
|
*/
|
|
54
18
|
dir?: "ltr" | "rtl" | "auto" | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Whether to hide the widget.
|
|
57
|
-
*/
|
|
58
|
-
hidden?: boolean | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Whether to disable the widget. An alias of the `aria-disabled`
|
|
61
|
-
* attribute.
|
|
62
|
-
*/
|
|
63
|
-
disabled?: boolean | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Whether to make the widget read-only. An alias of the
|
|
66
|
-
* `aria-readonly` attribute.
|
|
67
|
-
*/
|
|
68
|
-
readonly?: boolean | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Whether to mark the widget required. An alias of the
|
|
71
|
-
* `aria-required` attribute.
|
|
72
|
-
*/
|
|
73
|
-
required?: boolean | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* Whether to mark the widget invalid. An alias of the
|
|
76
|
-
* `aria-invalid` attribute.
|
|
77
|
-
*/
|
|
78
|
-
invalid?: boolean | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* Primary slot content.
|
|
81
|
-
*/
|
|
82
|
-
children?: Snippet<[]> | undefined;
|
|
83
19
|
};
|
|
84
|
-
import type {
|
|
20
|
+
import type { WidgetStateProps } from '../../typedefs.js';
|
|
21
|
+
import type { FormFieldStateProps } from '../../typedefs.js';
|
|
@@ -2,20 +2,20 @@ export function isPlainLanguage(language: string | null | undefined): boolean;
|
|
|
2
2
|
export function isEngineLoaded(): boolean;
|
|
3
3
|
export function isEngineUnavailable(): boolean;
|
|
4
4
|
export function isCodeLanguageLoaded(language: string): boolean;
|
|
5
|
-
export function loadEngine(
|
|
5
|
+
export function loadEngine(onLoaded?: () => void): Promise<void> | undefined;
|
|
6
6
|
export function normalizeCodeLanguage(language: string): string;
|
|
7
|
-
export function loadCodeLanguage(language: string,
|
|
7
|
+
export function loadCodeLanguage(language: string, onLoaded?: () => void): Promise<void> | undefined;
|
|
8
8
|
export function isCodeThemeLoaded(theme: string): boolean;
|
|
9
|
-
export function loadCodeTheme(theme: string,
|
|
10
|
-
export function
|
|
9
|
+
export function loadCodeTheme(theme: string, onLoaded?: () => void): Promise<void> | undefined;
|
|
10
|
+
export function tokenizeCode(code: string, language: string, theme?: string): {
|
|
11
|
+
tokens: any[][];
|
|
12
|
+
diff: boolean;
|
|
13
|
+
};
|
|
14
|
+
export function getTokenStyle(token: any): string;
|
|
11
15
|
export function highlightCodeToHTML(code: string, language: string, { theme }?: {
|
|
12
16
|
theme?: string | undefined;
|
|
13
17
|
}): string | undefined;
|
|
14
18
|
export function highlightCodeToTokens(code: string, language: string, { theme }?: {
|
|
15
19
|
theme?: string | undefined;
|
|
16
20
|
}): HighlightedToken[][] | undefined;
|
|
17
|
-
import type { LexicalEditor } from 'lexical';
|
|
18
|
-
import type { NodeKey } from 'lexical';
|
|
19
|
-
import type { CodeNode } from '@lexical/code-core';
|
|
20
|
-
import type { LexicalNode } from 'lexical';
|
|
21
21
|
import type { HighlightedToken } from '../../../typedefs.js';
|