@sveltia/ui 0.91.0 → 0.92.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +33 -14
- 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 +2 -2
- 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
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
} from '@lexical/table';
|
|
25
25
|
import { $isParagraphNode as isParagraphNode, $isTextNode as isTextNode } from 'lexical';
|
|
26
26
|
|
|
27
|
+
import { mapCodeSpans } from '../markdown/code-spans.js';
|
|
28
|
+
import { UNESCAPED_LOOKBEHIND } from '../markdown/syntax.js';
|
|
27
29
|
import { BLOCK_SYNTAX_ESCAPE } from './block-escape.js';
|
|
28
30
|
import { LEADING_INLINE_CODE } from './inline-code.js';
|
|
29
31
|
import { LINK } from './link.js';
|
|
@@ -60,6 +62,17 @@ const getColumnAlignment = (delimiter) => {
|
|
|
60
62
|
return left && right ? 'center' : left ? 'left' : right ? 'right' : '';
|
|
61
63
|
};
|
|
62
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Regular expression to match `\n` in a cell, which stands for a line break unless its backslash is
|
|
67
|
+
* escaped, like `\\n`. The lookahead comes first, so the lookbehind is only tried before a `\n`.
|
|
68
|
+
*/
|
|
69
|
+
const CELL_LINE_BREAK_REG_EXP = new RegExp(String.raw`(?=\\n)${UNESCAPED_LOOKBEHIND}\\n`, 'g');
|
|
70
|
+
/**
|
|
71
|
+
* Regular expression to match a pipe that isn’t escaped, which separates the cells of a row. The
|
|
72
|
+
* lookahead comes first, so the lookbehind is only tried before a pipe.
|
|
73
|
+
*/
|
|
74
|
+
const UNESCAPED_PIPE_REG_EXP = new RegExp(String.raw`(?=\|)${UNESCAPED_LOOKBEHIND}\|`);
|
|
75
|
+
|
|
63
76
|
/**
|
|
64
77
|
* Returns the number of columns in the table.
|
|
65
78
|
* @internal
|
|
@@ -79,9 +92,12 @@ export const getTableColumnsSize = (table) => {
|
|
|
79
92
|
* @returns {TableCellNode}
|
|
80
93
|
*/
|
|
81
94
|
const createTableCell = (textContent, transformers) => {
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
95
|
+
// `\n` is a line break in the cell, except within inline code, where it’s literal, or after an
|
|
96
|
+
// escaped backslash. An escaped pipe is part of the cell, even within inline code, like GitHub
|
|
97
|
+
// Flavored Markdown. The spaces around the content only separate it from the pipes
|
|
98
|
+
textContent = mapCodeSpans(textContent.trim(), {
|
|
99
|
+
outside: (text) => text.replace(CELL_LINE_BREAK_REG_EXP, '\n'),
|
|
100
|
+
}).replace(/\\\|/g, '|');
|
|
85
101
|
|
|
86
102
|
const cell = createTableCellNode(TableCellHeaderStates.NO_STATUS);
|
|
87
103
|
|
|
@@ -105,8 +121,8 @@ export const mapToTableCells = (textContent, transformers) => {
|
|
|
105
121
|
}
|
|
106
122
|
|
|
107
123
|
// Split the row at the pipes that are not escaped, which are preceded by an even number of
|
|
108
|
-
// backslashes
|
|
109
|
-
return match.split(
|
|
124
|
+
// backslashes, if any
|
|
125
|
+
return match.split(UNESCAPED_PIPE_REG_EXP).map((text) => createTableCell(text, transformers));
|
|
110
126
|
};
|
|
111
127
|
|
|
112
128
|
/**
|
|
@@ -126,7 +142,12 @@ const exportTableRow = (row, transformers) => {
|
|
|
126
142
|
// It’s TableCellNode so it’s just to make flow happy
|
|
127
143
|
if (isTableCellNode(cell)) {
|
|
128
144
|
rowOutput.push(
|
|
129
|
-
|
|
145
|
+
// A backslash followed by `n` in text, like that in `C:\new`, is escaped, so it’s not read
|
|
146
|
+
// as a line break; it means the same in Markdown. Inline code is left as is, as `\n` is
|
|
147
|
+
// literal there
|
|
148
|
+
mapCodeSpans(convertToMarkdownString(transformers, cell), {
|
|
149
|
+
outside: (text) => text.replace(CELL_LINE_BREAK_REG_EXP, '\\\\n'),
|
|
150
|
+
})
|
|
130
151
|
// Escape a pipe, which would otherwise end the cell, even within inline code
|
|
131
152
|
.replace(/\|/g, '\\|')
|
|
132
153
|
.replace(/\n/g, '\\n')
|
|
@@ -235,10 +256,15 @@ const $takePrecedingRows = (parentNode, transformers) => {
|
|
|
235
256
|
* Create a table from the given rows, padding the shorter ones with empty cells.
|
|
236
257
|
* @param {TableCellNode[][]} rows Cells of each row.
|
|
237
258
|
* @param {Transformer[]} transformers Transformers to import the empty cell content with.
|
|
259
|
+
* @param {number} [columnsSize] Number of columns. The cells beyond it are dropped. The default is
|
|
260
|
+
* the number of cells in the longest row.
|
|
238
261
|
* @returns {TableNode} Table.
|
|
239
262
|
*/
|
|
240
|
-
const $createTable = (
|
|
241
|
-
|
|
263
|
+
const $createTable = (
|
|
264
|
+
rows,
|
|
265
|
+
transformers,
|
|
266
|
+
columnsSize = Math.max(...rows.map((cells) => cells.length)),
|
|
267
|
+
) => {
|
|
242
268
|
const table = createTableNode();
|
|
243
269
|
|
|
244
270
|
rows.forEach((cells) => {
|
|
@@ -246,7 +272,7 @@ const $createTable = (rows, transformers) => {
|
|
|
246
272
|
|
|
247
273
|
table.append(tableRow);
|
|
248
274
|
|
|
249
|
-
for (let i = 0; i <
|
|
275
|
+
for (let i = 0; i < columnsSize; i += 1) {
|
|
250
276
|
tableRow.append(i < cells.length ? cells[i] : createTableCell('', transformers));
|
|
251
277
|
}
|
|
252
278
|
});
|
|
@@ -255,19 +281,33 @@ const $createTable = (rows, transformers) => {
|
|
|
255
281
|
};
|
|
256
282
|
|
|
257
283
|
/**
|
|
258
|
-
* Put a new table in place of the given paragraph, or add
|
|
259
|
-
* that has the same number of columns.
|
|
284
|
+
* Put a new table with the given rows in place of the given paragraph, or add the rows to the table
|
|
285
|
+
* right before it if that has a header row or the same number of columns. Like GitHub Flavored
|
|
286
|
+
* Markdown, a row with fewer cells than the header row is padded with empty cells, and the cells
|
|
287
|
+
* beyond it are dropped. The rows then take the column alignment from the header.
|
|
260
288
|
* @param {ElementNode} parentNode Paragraph to replace.
|
|
261
|
-
* @param {
|
|
289
|
+
* @param {TableCellNode[][]} rows Cells of each row.
|
|
290
|
+
* @param {Transformer[]} transformers Transformers to import the empty cell content with.
|
|
291
|
+
* @see https://github.github.com/gfm/#tables-extension-
|
|
262
292
|
*/
|
|
263
|
-
const $insertImportedTable = (parentNode,
|
|
293
|
+
const $insertImportedTable = (parentNode, rows, transformers) => {
|
|
264
294
|
const previousSibling = parentNode.getPreviousSibling();
|
|
295
|
+
const headerRow = isTableNode(previousSibling) ? previousSibling.getFirstChild() : null;
|
|
296
|
+
const headerCells = isTableRowNode(headerRow) ? headerRow.getChildren() : [];
|
|
297
|
+
|
|
298
|
+
const hasHeaderRow = headerCells.some(
|
|
299
|
+
(cell) => isTableCellNode(cell) && cell.hasHeaderState(TableCellHeaderStates.ROW),
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
/** @type {TableNode} */
|
|
303
|
+
let table;
|
|
265
304
|
|
|
266
305
|
if (
|
|
267
306
|
isTableNode(previousSibling) &&
|
|
268
|
-
|
|
307
|
+
(hasHeaderRow ||
|
|
308
|
+
getTableColumnsSize(previousSibling) === Math.max(...rows.map((cells) => cells.length)))
|
|
269
309
|
) {
|
|
270
|
-
|
|
310
|
+
table = $createTable(rows, transformers, headerCells.length);
|
|
271
311
|
|
|
272
312
|
table.getChildren().forEach((row) => {
|
|
273
313
|
/** @type {TableRowNode} */ (row).getChildren().forEach((cell, index) => {
|
|
@@ -280,6 +320,7 @@ const $insertImportedTable = (parentNode, table) => {
|
|
|
280
320
|
previousSibling.append(...table.getChildren());
|
|
281
321
|
parentNode.remove();
|
|
282
322
|
} else {
|
|
323
|
+
table = $createTable(rows, transformers);
|
|
283
324
|
parentNode.replace(table);
|
|
284
325
|
}
|
|
285
326
|
|
|
@@ -335,7 +376,7 @@ export const createTableTransformer = (cellTransformers = []) => {
|
|
|
335
376
|
|
|
336
377
|
const rows = [...$takePrecedingRows(parentNode, transformers), matchCells];
|
|
337
378
|
|
|
338
|
-
$insertImportedTable(parentNode,
|
|
379
|
+
$insertImportedTable(parentNode, rows, transformers);
|
|
339
380
|
},
|
|
340
381
|
type: 'element',
|
|
341
382
|
};
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
export function exportMarkdown(enabledTransformers: Transformer[]): string;
|
|
2
|
-
export function
|
|
3
|
-
export function
|
|
2
|
+
export function exportValue(editor: LexicalEditor, enabledTransformers: Transformer[], format?: TextEditorValueFormat): string;
|
|
3
|
+
export function registerValueExport(editor: LexicalEditor, enabledTransformers: Transformer[], format: TextEditorValueFormat, onExport: (detail: ExportDetail) => void): {
|
|
4
|
+
flush: () => void;
|
|
5
|
+
unregister: () => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Value exported from the editor, and the selection state at the time.
|
|
9
|
+
*/
|
|
10
|
+
export type ExportDetail = {
|
|
11
|
+
/**
|
|
12
|
+
* Markdown or HTML value.
|
|
13
|
+
*/
|
|
14
|
+
value: string;
|
|
15
|
+
/**
|
|
16
|
+
* Selection state.
|
|
17
|
+
*/
|
|
18
|
+
selection: TextEditorSelectionState;
|
|
19
|
+
};
|
|
4
20
|
import type { Transformer } from '@lexical/markdown';
|
|
5
21
|
import type { LexicalEditor } from 'lexical';
|
|
6
22
|
import type { TextEditorValueFormat } from '../../../typedefs.js';
|
|
23
|
+
import type { TextEditorSelectionState } from '../../../typedefs.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Exporting the editor content, and
|
|
2
|
+
* Exporting the editor content, and passing it on as it changes.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { $convertToMarkdownString as convertToMarkdownString } from '@lexical/markdown';
|
|
6
6
|
import { sleep } from '@sveltia/utils/misc';
|
|
7
7
|
import { DISABLED_MARKDOWN_TAGS } from '../constants.js';
|
|
8
8
|
import { exportHtml } from './html/index.js';
|
|
9
|
-
import { trimBlankBlockquoteLines } from './markdown.js';
|
|
9
|
+
import { trimBlankBlockquoteLines } from './markdown/index.js';
|
|
10
10
|
import { BLOCK_SYNTAX_ESCAPE } from './transformers/block-escape.js';
|
|
11
11
|
import { getSelectionTypes } from '../editing/selection.js';
|
|
12
12
|
import { mergeUnregisters } from '../utils.js';
|
|
@@ -14,7 +14,14 @@ import { mergeUnregisters } from '../utils.js';
|
|
|
14
14
|
/**
|
|
15
15
|
* @import { LexicalEditor } from 'lexical';
|
|
16
16
|
* @import { Transformer } from '@lexical/markdown';
|
|
17
|
-
* @import { TextEditorValueFormat } from '../../../typedefs.js';
|
|
17
|
+
* @import { TextEditorSelectionState, TextEditorValueFormat } from '../../../typedefs.js';
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Value exported from the editor, and the selection state at the time.
|
|
22
|
+
* @typedef {object} ExportDetail
|
|
23
|
+
* @property {string} value Markdown or HTML value.
|
|
24
|
+
* @property {TextEditorSelectionState} selection Selection state.
|
|
18
25
|
*/
|
|
19
26
|
|
|
20
27
|
/**
|
|
@@ -42,49 +49,70 @@ export const exportMarkdown = (enabledTransformers) => {
|
|
|
42
49
|
};
|
|
43
50
|
|
|
44
51
|
/**
|
|
45
|
-
*
|
|
52
|
+
* Export the editor content as Markdown or HTML. Call this within an editor update or read.
|
|
46
53
|
* @internal
|
|
47
54
|
* @param {LexicalEditor} editor Editor instance.
|
|
48
55
|
* @param {Transformer[]} enabledTransformers Enabled Markdown transformers.
|
|
49
|
-
* @param {string} [cachedValue] Value from a previous call, to be reused instead of converting the
|
|
50
|
-
* whole document again when only the selection has changed.
|
|
51
56
|
* @param {TextEditorValueFormat} [format] Value format.
|
|
52
57
|
* @returns {string} Markdown or HTML value.
|
|
53
58
|
*/
|
|
54
|
-
export const
|
|
55
|
-
|
|
56
|
-
cachedValue ?? (format === 'html' ? exportHtml(editor) : exportMarkdown(enabledTransformers));
|
|
57
|
-
|
|
58
|
-
editor.getRootElement()?.dispatchEvent(
|
|
59
|
-
new CustomEvent('Update', {
|
|
60
|
-
detail: {
|
|
61
|
-
value,
|
|
62
|
-
selection: getSelectionTypes(),
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
return value;
|
|
68
|
-
};
|
|
59
|
+
export const exportValue = (editor, enabledTransformers, format = 'markdown') =>
|
|
60
|
+
format === 'html' ? exportHtml(editor) : exportMarkdown(enabledTransformers);
|
|
69
61
|
|
|
70
62
|
/**
|
|
71
|
-
* Register an update listener that
|
|
72
|
-
* debounced so only the latest update in a burst
|
|
63
|
+
* Register an update listener that exports the editor content as Markdown or HTML, and passes it
|
|
64
|
+
* on along with the selection state, debounced so only the latest update in a burst is exported.
|
|
73
65
|
* @param {LexicalEditor} editor Editor instance.
|
|
74
66
|
* @param {Transformer[]} enabledTransformers Enabled Markdown transformers.
|
|
75
67
|
* @param {TextEditorValueFormat} format Value format.
|
|
76
|
-
* @
|
|
68
|
+
* @param {(detail: ExportDetail) => void} onExport Function to call with the exported value. It’s
|
|
69
|
+
* called within an editor update.
|
|
70
|
+
* @returns {{ flush: () => void, unregister: () => void }} `flush` exports the content scheduled
|
|
71
|
+
* to be exported right away, instead of after the delay, so the value reflects what was just
|
|
72
|
+
* typed. Call it before acting on the value, like when the focus leaves the editor or before
|
|
73
|
+
* switching to the Markdown or HTML source. It does nothing if nothing is scheduled. `unregister`
|
|
74
|
+
* removes the listener.
|
|
77
75
|
*/
|
|
78
|
-
export const
|
|
79
|
-
/** Incremented on every update, so only the latest one in a burst
|
|
76
|
+
export const registerValueExport = (editor, enabledTransformers, format, onExport) => {
|
|
77
|
+
/** Incremented on every update, so only the latest one in a burst is exported. */
|
|
80
78
|
let updateCount = 0;
|
|
81
|
-
/** Whether the content has changed since
|
|
79
|
+
/** Whether the content has changed since it was last exported. */
|
|
82
80
|
let contentChanged = true;
|
|
83
81
|
/** @type {string | undefined} */
|
|
84
82
|
let lastValue = undefined;
|
|
85
83
|
let disposed = false;
|
|
84
|
+
/** Whether an export is scheduled, and hasn’t been made yet. */
|
|
85
|
+
let scheduled = false;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Export the current value, and pass it on.
|
|
89
|
+
*/
|
|
90
|
+
const triggerExport = () => {
|
|
91
|
+
scheduled = false;
|
|
92
|
+
|
|
93
|
+
editor.update(() => {
|
|
94
|
+
// Reuse the value when only the selection has changed, instead of converting the whole
|
|
95
|
+
// document again
|
|
96
|
+
const value =
|
|
97
|
+
(contentChanged ? undefined : lastValue) ??
|
|
98
|
+
exportValue(editor, enabledTransformers, format);
|
|
86
99
|
|
|
87
|
-
|
|
100
|
+
onExport({ value, selection: getSelectionTypes() });
|
|
101
|
+
lastValue = value;
|
|
102
|
+
contentChanged = false;
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Export the scheduled value right away.
|
|
108
|
+
*/
|
|
109
|
+
const flush = () => {
|
|
110
|
+
if (scheduled && !disposed && !editor.isComposing()) {
|
|
111
|
+
triggerExport();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const unregister = mergeUnregisters(
|
|
88
116
|
() => {
|
|
89
117
|
disposed = true;
|
|
90
118
|
},
|
|
@@ -99,27 +127,23 @@ export const registerUpdateEvent = (editor, enabledTransformers, format) => {
|
|
|
99
127
|
}
|
|
100
128
|
|
|
101
129
|
updateCount += 1;
|
|
130
|
+
scheduled = true;
|
|
102
131
|
|
|
103
132
|
const currentCount = updateCount;
|
|
104
133
|
|
|
105
134
|
(async () => {
|
|
106
135
|
await sleep(100);
|
|
107
136
|
|
|
108
|
-
// Skip if a newer update has been made in the meantime,
|
|
109
|
-
|
|
137
|
+
// Skip if a newer update has been made in the meantime, the value has been exported
|
|
138
|
+
// already with `flush()`, or the editor has been disposed
|
|
139
|
+
if (currentCount !== updateCount || !scheduled || disposed) {
|
|
110
140
|
return;
|
|
111
141
|
}
|
|
112
142
|
|
|
113
|
-
|
|
114
|
-
lastValue = onEditorUpdate(
|
|
115
|
-
editor,
|
|
116
|
-
enabledTransformers,
|
|
117
|
-
contentChanged ? undefined : lastValue,
|
|
118
|
-
format,
|
|
119
|
-
);
|
|
120
|
-
contentChanged = false;
|
|
121
|
-
});
|
|
143
|
+
triggerExport();
|
|
122
144
|
})();
|
|
123
145
|
}),
|
|
124
146
|
);
|
|
147
|
+
|
|
148
|
+
return { flush, unregister };
|
|
125
149
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function initEditor(config: TextEditorConfig): InitEditorResult;
|
|
1
|
+
export function initEditor(config: Partial<TextEditorConfig>, { onExport }?: InitEditorOptions): InitEditorResult;
|
|
2
2
|
export type InitEditorResult = {
|
|
3
3
|
/**
|
|
4
4
|
* Editor instance.
|
|
@@ -8,64 +8,25 @@ export type InitEditorResult = {
|
|
|
8
8
|
* List of enabled Markdown transformers.
|
|
9
9
|
*/
|
|
10
10
|
enabledTransformers: Transformer[];
|
|
11
|
+
/**
|
|
12
|
+
* Export the content scheduled to be exported right away, instead
|
|
13
|
+
* of after the delay, so the value reflects what was just typed. Does nothing if nothing is
|
|
14
|
+
* scheduled.
|
|
15
|
+
*/
|
|
16
|
+
flush: () => void;
|
|
11
17
|
/**
|
|
12
18
|
* Remove all registered Lexical listeners.
|
|
13
19
|
*/
|
|
14
20
|
dispose: () => void;
|
|
15
21
|
};
|
|
16
|
-
|
|
17
|
-
* Editor configuration with the defaults applied, and the features derived from it.
|
|
18
|
-
*/
|
|
19
|
-
export type EditorSetup = {
|
|
20
|
-
/**
|
|
21
|
-
* Enabled buttons.
|
|
22
|
-
*/
|
|
23
|
-
enabledButtons: TextEditorNodeType[];
|
|
24
|
-
/**
|
|
25
|
-
* Editor components.
|
|
26
|
-
*/
|
|
27
|
-
components: TextEditorComponent[];
|
|
28
|
-
/**
|
|
29
|
-
* Whether to enable Markdown shortcuts.
|
|
30
|
-
*/
|
|
31
|
-
useMarkdownShortcuts: boolean | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Whether the editor is a code editor.
|
|
34
|
-
*/
|
|
35
|
-
isCodeEditor: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Default code block language.
|
|
38
|
-
*/
|
|
39
|
-
defaultLanguage: string;
|
|
40
|
-
/**
|
|
41
|
-
* Value format.
|
|
42
|
-
*/
|
|
43
|
-
format: TextEditorValueFormat;
|
|
44
|
-
/**
|
|
45
|
-
* Whether the editor accepts multiple lines.
|
|
46
|
-
*/
|
|
47
|
-
multiline: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Whether to support code blocks.
|
|
50
|
-
*/
|
|
51
|
-
hasCodeBlock: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Whether to support table editing.
|
|
54
|
-
*/
|
|
55
|
-
hasTable: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Whether to support selecting a horizontal rule.
|
|
58
|
-
*/
|
|
59
|
-
hasHorizontalRule: boolean;
|
|
22
|
+
export type InitEditorOptions = {
|
|
60
23
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
24
|
+
* Function to call with the Markdown or HTML
|
|
25
|
+
* value and the selection state, a moment after the editor content or selection has changed.
|
|
63
26
|
*/
|
|
64
|
-
|
|
27
|
+
onExport?: ((detail: ExportDetail) => void) | undefined;
|
|
65
28
|
};
|
|
66
29
|
import type { TextEditorConfig } from '../../typedefs.js';
|
|
67
30
|
import type { LexicalEditor } from 'lexical';
|
|
68
31
|
import type { Transformer } from '@lexical/markdown';
|
|
69
|
-
import type {
|
|
70
|
-
import type { TextEditorComponent } from '../../typedefs.js';
|
|
71
|
-
import type { TextEditorValueFormat } from '../../typedefs.js';
|
|
32
|
+
import type { ExportDetail } from './conversion/update.js';
|
|
@@ -19,7 +19,8 @@ import { HR } from './conversion/transformers/hr.js';
|
|
|
19
19
|
import { RAW_HTML, RAW_SYNTAX } from './conversion/transformers/raw-syntax.js';
|
|
20
20
|
import { $ensureParagraphAfterTable, $normalizeTableHeaders } from './editing/table.js';
|
|
21
21
|
import { createTableTransformer } from './conversion/transformers/table.js';
|
|
22
|
-
import {
|
|
22
|
+
import { registerSingleLine } from './editing/single-line.js';
|
|
23
|
+
import { getEditorSetup, normalizeConfig } from './config.js';
|
|
23
24
|
import { removePlaceholdersFromMatch } from './conversion/editor-components.js';
|
|
24
25
|
import {
|
|
25
26
|
registerCodeEditorCommands,
|
|
@@ -29,42 +30,31 @@ import {
|
|
|
29
30
|
import { registerGuards } from './editing/guards.js';
|
|
30
31
|
import { mergeUnregisters } from './utils.js';
|
|
31
32
|
import { registerLinkCommands } from './editing/link.js';
|
|
32
|
-
import {
|
|
33
|
+
import { registerValueExport } from './conversion/update.js';
|
|
33
34
|
import { registerPasteAsMarkdown } from './conversion/paste.js';
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* @import { LexicalEditor } from 'lexical';
|
|
37
38
|
* @import { TextMatchTransformer, Transformer } from '@lexical/markdown';
|
|
38
|
-
* @import {
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* TextEditorNodeType,
|
|
42
|
-
* TextEditorValueFormat,
|
|
43
|
-
* } from '../../typedefs.js';
|
|
39
|
+
* @import { TextEditorConfig, TextEditorNodeType } from '../../typedefs.js';
|
|
40
|
+
* @import { EditorSetup } from './config.js';
|
|
41
|
+
* @import { ExportDetail } from './conversion/update.js';
|
|
44
42
|
*/
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* @typedef {object} InitEditorResult
|
|
48
46
|
* @property {LexicalEditor} editor Editor instance.
|
|
49
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.
|
|
50
51
|
* @property {() => void} dispose Remove all registered Lexical listeners.
|
|
51
52
|
*/
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
57
|
-
* @property {TextEditorComponent[]} components Editor components.
|
|
58
|
-
* @property {boolean | undefined} useMarkdownShortcuts Whether to enable Markdown shortcuts.
|
|
59
|
-
* @property {boolean} isCodeEditor Whether the editor is a code editor.
|
|
60
|
-
* @property {string} defaultLanguage Default code block language.
|
|
61
|
-
* @property {TextEditorValueFormat} format Value format.
|
|
62
|
-
* @property {boolean} multiline Whether the editor accepts multiple lines.
|
|
63
|
-
* @property {boolean} hasCodeBlock Whether to support code blocks.
|
|
64
|
-
* @property {boolean} hasTable Whether to support table editing.
|
|
65
|
-
* @property {boolean} hasHorizontalRule Whether to support selecting a horizontal rule.
|
|
66
|
-
* @property {boolean} hasBlockSyntax Whether to support horizontal rules and tables in Markdown,
|
|
67
|
-
* 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.
|
|
68
58
|
*/
|
|
69
59
|
|
|
70
60
|
/**
|
|
@@ -72,37 +62,6 @@ import { registerPasteAsMarkdown } from './conversion/paste.js';
|
|
|
72
62
|
*/
|
|
73
63
|
const HISTORY_MAX_DEPTH = 200;
|
|
74
64
|
|
|
75
|
-
/**
|
|
76
|
-
* Apply the defaults to the editor configuration, and derive the features from it.
|
|
77
|
-
* @param {TextEditorConfig} config Editor configuration.
|
|
78
|
-
* @returns {EditorSetup} Editor setup.
|
|
79
|
-
*/
|
|
80
|
-
const getEditorSetup = (config) => {
|
|
81
|
-
const {
|
|
82
|
-
enabledButtons = [],
|
|
83
|
-
components = [],
|
|
84
|
-
useMarkdownShortcuts,
|
|
85
|
-
isCodeEditor = false,
|
|
86
|
-
defaultLanguage = 'plain',
|
|
87
|
-
format = 'markdown',
|
|
88
|
-
multiline = true,
|
|
89
|
-
} = limitToSingleLine(config);
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
enabledButtons,
|
|
93
|
-
components,
|
|
94
|
-
useMarkdownShortcuts,
|
|
95
|
-
isCodeEditor,
|
|
96
|
-
defaultLanguage,
|
|
97
|
-
format,
|
|
98
|
-
multiline,
|
|
99
|
-
hasCodeBlock: enabledButtons.includes('code-block') || isCodeEditor,
|
|
100
|
-
hasTable: enabledButtons.includes('table') && !isCodeEditor,
|
|
101
|
-
hasHorizontalRule: enabledButtons.includes('horizontal-rule') && !isCodeEditor,
|
|
102
|
-
hasBlockSyntax: !isCodeEditor && multiline,
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
65
|
/**
|
|
107
66
|
* Get the unique items of a map keyed by button type, for the enabled buttons.
|
|
108
67
|
* @template T
|
|
@@ -132,6 +91,7 @@ const createEditorExtension = ({
|
|
|
132
91
|
hasCodeBlock,
|
|
133
92
|
hasTable,
|
|
134
93
|
hasHorizontalRule,
|
|
94
|
+
hasTaskList,
|
|
135
95
|
hasBlockSyntax,
|
|
136
96
|
}) =>
|
|
137
97
|
defineExtension({
|
|
@@ -170,10 +130,7 @@ const createEditorExtension = ({
|
|
|
170
130
|
...(hasBlockSyntax ? [HorizontalRuleNode, TableNode, TableCellNode, TableRowNode] : []),
|
|
171
131
|
],
|
|
172
132
|
theme: EDITOR_THEME,
|
|
173
|
-
html:
|
|
174
|
-
format === 'html'
|
|
175
|
-
? getHtmlConfig({ hasCodeBlock, hasTaskList: enabledButtons.includes('task-list') })
|
|
176
|
-
: undefined,
|
|
133
|
+
html: format === 'html' ? getHtmlConfig({ hasCodeBlock, hasTaskList }) : undefined,
|
|
177
134
|
/**
|
|
178
135
|
* Log an error like `createEditor` does by default, instead of throwing it.
|
|
179
136
|
* @param {Error} error Error.
|
|
@@ -224,7 +181,9 @@ const getEnabledTransformers = ({ enabledButtons, components, isCodeEditor, hasB
|
|
|
224
181
|
* @param {LexicalEditor} editor Editor instance.
|
|
225
182
|
* @param {EditorSetup} setup Editor setup.
|
|
226
183
|
* @param {Transformer[]} enabledTransformers Enabled Markdown transformers.
|
|
227
|
-
* @
|
|
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.
|
|
228
187
|
*/
|
|
229
188
|
const registerEditorListeners = (
|
|
230
189
|
editor,
|
|
@@ -237,11 +196,13 @@ const registerEditorListeners = (
|
|
|
237
196
|
multiline,
|
|
238
197
|
hasCodeBlock,
|
|
239
198
|
hasTable,
|
|
199
|
+
hasLink,
|
|
240
200
|
},
|
|
241
201
|
enabledTransformers,
|
|
242
|
-
|
|
202
|
+
onExport,
|
|
203
|
+
) => {
|
|
243
204
|
// The order matters, as listeners with the same priority are called in the registration order
|
|
244
|
-
mergeUnregisters(
|
|
205
|
+
const unregisterFeatures = mergeUnregisters(
|
|
245
206
|
registerRichText(editor),
|
|
246
207
|
registerDragonSupport(editor),
|
|
247
208
|
// Cap the undo stack, as each entry holds a snapshot of the whole document
|
|
@@ -264,7 +225,7 @@ const registerEditorListeners = (
|
|
|
264
225
|
})
|
|
265
226
|
: undefined,
|
|
266
227
|
hasCodeBlock ? observeCodeTheme(editor) : undefined,
|
|
267
|
-
|
|
228
|
+
hasLink ? registerLinkCommands(editor) : undefined,
|
|
268
229
|
hasTable
|
|
269
230
|
? editor.registerNodeTransform(TableNode, (table) => {
|
|
270
231
|
$ensureParagraphAfterTable(table);
|
|
@@ -278,29 +239,46 @@ const registerEditorListeners = (
|
|
|
278
239
|
: undefined,
|
|
279
240
|
registerListCommands(editor, enabledButtons),
|
|
280
241
|
isCodeEditor ? undefined : registerGuards(editor, { format, enabledButtons }),
|
|
281
|
-
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const valueExport = registerValueExport(editor, enabledTransformers, format, onExport);
|
|
245
|
+
|
|
246
|
+
const unregisterInput = mergeUnregisters(
|
|
282
247
|
registerTabIndentation(editor),
|
|
283
248
|
isCodeEditor ? undefined : registerPasteAsMarkdown(editor, enabledTransformers),
|
|
284
249
|
);
|
|
285
250
|
|
|
251
|
+
return {
|
|
252
|
+
flush: valueExport.flush,
|
|
253
|
+
unregister: mergeUnregisters(unregisterFeatures, valueExport.unregister, unregisterInput),
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
286
257
|
/**
|
|
287
258
|
* Initialize the Lexical editor.
|
|
288
|
-
* @param {TextEditorConfig} config Editor configuration.
|
|
259
|
+
* @param {Partial<TextEditorConfig>} config Editor configuration.
|
|
260
|
+
* @param {InitEditorOptions} [options] Options.
|
|
289
261
|
* @returns {InitEditorResult} Editor instance and cleanup.
|
|
290
262
|
*/
|
|
291
|
-
export const initEditor = (config) => {
|
|
292
|
-
const setup = getEditorSetup(config);
|
|
263
|
+
export const initEditor = (config, { onExport = () => {} } = {}) => {
|
|
264
|
+
const setup = getEditorSetup(normalizeConfig(config));
|
|
293
265
|
const enabledTransformers = getEnabledTransformers(setup);
|
|
294
266
|
const editor = buildEditorFromExtensions(createEditorExtension(setup));
|
|
295
267
|
|
|
296
268
|
// Let the HTML import tell the elements the components import
|
|
297
269
|
editorComponents.set(editor, setup.components);
|
|
298
270
|
|
|
299
|
-
const unregister = registerEditorListeners(
|
|
271
|
+
const { flush, unregister } = registerEditorListeners(
|
|
272
|
+
editor,
|
|
273
|
+
setup,
|
|
274
|
+
enabledTransformers,
|
|
275
|
+
onExport,
|
|
276
|
+
);
|
|
300
277
|
|
|
301
278
|
return {
|
|
302
279
|
editor,
|
|
303
280
|
enabledTransformers,
|
|
281
|
+
flush,
|
|
304
282
|
/**
|
|
305
283
|
* Remove all registered Lexical listeners.
|
|
306
284
|
*/
|
|
@@ -25,6 +25,9 @@ export function joinLines({ value, caret }: {
|
|
|
25
25
|
caret: number;
|
|
26
26
|
};
|
|
27
27
|
export function registerRawTextSingleLine(textArea: HTMLTextAreaElement): () => void;
|
|
28
|
+
export function registerRawTextSelection(textArea: HTMLTextAreaElement, onChange: (blockType: TextEditorBlockType) => void, { hasTaskList }?: {
|
|
29
|
+
hasTaskList?: (() => boolean) | undefined;
|
|
30
|
+
}): () => void;
|
|
28
31
|
/**
|
|
29
32
|
* Current value and selection of the `<textarea>`.
|
|
30
33
|
*/
|