@sveltia/ui 0.81.3 → 0.83.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/drawer/drawer.svelte.d.ts +2 -2
- package/dist/components/grid/grid-col-header.svelte +121 -2
- package/dist/components/grid/grid-col-header.svelte.d.ts +35 -1
- package/dist/components/grid/grid-foot.svelte +5 -0
- package/dist/components/grid/grid-head.svelte +4 -0
- package/dist/components/grid/grid-row.svelte +55 -2
- package/dist/components/grid/grid-row.svelte.d.ts +4 -2
- package/dist/components/grid/grid.svelte +5 -0
- package/dist/components/text-editor/alignment.d.ts +2 -0
- package/dist/components/text-editor/alignment.js +40 -0
- package/dist/components/text-editor/block.d.ts +4 -0
- package/dist/components/text-editor/block.js +65 -0
- package/dist/components/text-editor/constants.d.ts +22 -2
- package/dist/components/text-editor/constants.js +40 -1
- package/dist/components/text-editor/core.d.ts +7 -0
- package/dist/components/text-editor/core.js +61 -7
- package/dist/components/text-editor/floating-link-editor.svelte +58 -6
- package/dist/components/text-editor/html.js +21 -4
- package/dist/components/text-editor/lexical-root.svelte +27 -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/table-cell-menu-button.svelte +228 -0
- package/dist/components/text-editor/table-cell-menu-button.svelte.d.ts +12 -0
- package/dist/components/text-editor/table.d.ts +18 -0
- package/dist/components/text-editor/table.js +277 -0
- package/dist/components/text-editor/text-editor.svelte +5 -0
- package/dist/components/text-editor/toolbar/align-menu-button.svelte +84 -0
- package/dist/components/text-editor/toolbar/align-menu-button.svelte.d.ts +10 -0
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +65 -0
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte.d.ts +30 -0
- package/dist/components/text-editor/toolbar/insert-link-button.svelte +17 -1
- package/dist/components/text-editor/toolbar/insert-table-button.svelte +209 -0
- package/dist/components/text-editor/toolbar/insert-table-button.svelte.d.ts +24 -0
- package/dist/components/text-editor/toolbar/menu.d.ts +1 -0
- package/dist/components/text-editor/toolbar/menu.js +32 -0
- package/dist/components/text-editor/toolbar/table-action-menu.svelte +96 -0
- package/dist/components/text-editor/toolbar/table-action-menu.svelte.d.ts +21 -0
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +75 -7
- package/dist/components/text-editor/transformers/hr.d.ts +5 -0
- package/dist/components/text-editor/transformers/hr.js +7 -1
- package/dist/components/text-editor/transformers/table.js +3 -2
- package/dist/locales/ar.yaml +28 -0
- package/dist/locales/bg.yaml +28 -0
- package/dist/locales/ca.yaml +28 -0
- package/dist/locales/cs.yaml +28 -0
- package/dist/locales/da.yaml +28 -0
- package/dist/locales/de.yaml +28 -0
- package/dist/locales/el.yaml +28 -0
- package/dist/locales/en-CA.yaml +28 -0
- package/dist/locales/en-GB.yaml +28 -0
- package/dist/locales/en-US.yaml +28 -0
- package/dist/locales/es-CO.yaml +28 -0
- package/dist/locales/fa.yaml +28 -0
- package/dist/locales/fi.yaml +28 -0
- package/dist/locales/fr.yaml +28 -0
- package/dist/locales/he.yaml +28 -0
- package/dist/locales/hr.yaml +28 -0
- package/dist/locales/it.yaml +28 -0
- package/dist/locales/ja.yaml +28 -0
- package/dist/locales/ko.yaml +28 -0
- package/dist/locales/nl.yaml +28 -0
- package/dist/locales/pl.yaml +28 -0
- package/dist/locales/pt-BR.yaml +28 -0
- package/dist/locales/pt-PT.yaml +28 -0
- package/dist/locales/ru.yaml +28 -0
- package/dist/locales/sk.yaml +28 -0
- package/dist/locales/sv.yaml +28 -0
- package/dist/locales/tr.yaml +28 -0
- package/dist/locales/uk.yaml +28 -0
- package/dist/locales/vi.yaml +28 -0
- package/dist/locales/zh-CN.yaml +28 -0
- package/dist/locales/zh-TW.yaml +28 -0
- package/dist/services/group.svelte.js +6 -1
- package/dist/typedefs.d.ts +10 -1
- package/dist/typedefs.js +5 -1
- package/package.json +4 -4
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Toolbar button to insert a table. It opens a dialog to choose the number of rows and columns, then
|
|
4
|
+
inserts an empty table with a header row: a table node in the rich text mode, or its Markdown in
|
|
5
|
+
the plain text mode.
|
|
6
|
+
-->
|
|
7
|
+
<script>
|
|
8
|
+
import { _ } from '@sveltia/i18n';
|
|
9
|
+
import { matchesShortcuts } from '@sveltia/utils/events';
|
|
10
|
+
import { getContext } from 'svelte';
|
|
11
|
+
import Button from '../../button/button.svelte';
|
|
12
|
+
import Dialog from '../../dialog/dialog.svelte';
|
|
13
|
+
import Icon from '../../icon/icon.svelte';
|
|
14
|
+
import NumberInput from '../../text-field/number-input.svelte';
|
|
15
|
+
import { AVAILABLE_BUTTONS, DEFAULT_TABLE_SIZE, MAX_TABLE_SIZE } from '../constants.js';
|
|
16
|
+
import { focusEditor } from '../core.js';
|
|
17
|
+
import { editRawText, insertMarkdown } from '../raw-markdown.js';
|
|
18
|
+
import { $insertTable as insertTable, createTableMarkdown, parseTableSize } from '../table.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @import { TextEditorStore } from '../../../typedefs.js';
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Number of rows, including the header row, and columns of a new table.
|
|
26
|
+
* @typedef {{ rows: number, columns: number }} TableSize
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {object} Props
|
|
31
|
+
* @property {boolean} [disabled] Whether to disable the button, like when the caret is already in
|
|
32
|
+
* a table, as tables can’t be nested.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** @type {Props} */
|
|
36
|
+
let {
|
|
37
|
+
/* eslint-disable prefer-const */
|
|
38
|
+
disabled = false,
|
|
39
|
+
/* eslint-enable prefer-const */
|
|
40
|
+
} = $props();
|
|
41
|
+
|
|
42
|
+
const id = $props.id();
|
|
43
|
+
|
|
44
|
+
/** @type {TextEditorStore} */
|
|
45
|
+
const editorStore = getContext('editorStore');
|
|
46
|
+
|
|
47
|
+
let openDialog = $state(false);
|
|
48
|
+
/** @type {number | undefined} */
|
|
49
|
+
let rows = $state(DEFAULT_TABLE_SIZE);
|
|
50
|
+
/** @type {number | undefined} */
|
|
51
|
+
let columns = $state(DEFAULT_TABLE_SIZE);
|
|
52
|
+
|
|
53
|
+
const rowCount = $derived(parseTableSize(rows));
|
|
54
|
+
const columnCount = $derived(parseTableSize(columns));
|
|
55
|
+
const isValid = $derived(!!rowCount && !!columnCount);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Open the dialog. The size last chosen is kept, unless it was left invalid when the dialog was
|
|
59
|
+
* canceled.
|
|
60
|
+
*/
|
|
61
|
+
const onButtonClick = () => {
|
|
62
|
+
if (!rowCount) {
|
|
63
|
+
rows = DEFAULT_TABLE_SIZE;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!columnCount) {
|
|
67
|
+
columns = DEFAULT_TABLE_SIZE;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
openDialog = true;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Handle `keydown` event fired on the input fields on the dialog: insert the table with Enter.
|
|
75
|
+
* @param {KeyboardEvent} event `keydown` event.
|
|
76
|
+
*/
|
|
77
|
+
const onInputKeyDown = (event) => {
|
|
78
|
+
if (matchesShortcuts(event, 'Enter') && isValid) {
|
|
79
|
+
openDialog = false;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Insert the table into the rich text editor, then move the focus back to it, where the caret is
|
|
85
|
+
* in the first cell.
|
|
86
|
+
* @param {TableSize} size Table size.
|
|
87
|
+
*/
|
|
88
|
+
const insertRichText = async ({ rows: rowSize, columns: columnSize }) => {
|
|
89
|
+
const { editor } = editorStore;
|
|
90
|
+
|
|
91
|
+
// The button is only enabled while the editor is there
|
|
92
|
+
/* v8 ignore next 3 */
|
|
93
|
+
if (!editor) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
editor.update(() => {
|
|
98
|
+
insertTable(rowSize, columnSize);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await focusEditor(editor);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Insert the table’s Markdown into the `<textarea>`, with the caret in the first cell.
|
|
106
|
+
* @param {TableSize} size Table size.
|
|
107
|
+
*/
|
|
108
|
+
const insertPlainText = async ({ rows: rowSize, columns: columnSize }) => {
|
|
109
|
+
const markdown = createTableMarkdown(rowSize, columnSize);
|
|
110
|
+
|
|
111
|
+
await editRawText(editorStore.textArea, (state) => {
|
|
112
|
+
const edit = insertMarkdown(state, markdown, { block: true });
|
|
113
|
+
// Right after the leading pipe and space of the first cell
|
|
114
|
+
const caret = edit.start + edit.text.indexOf(markdown) + 2;
|
|
115
|
+
|
|
116
|
+
return { ...edit, selectionStart: caret, selectionEnd: caret };
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Handle `close` event fired on the dialog. Insert the table unless the dialog has been canceled.
|
|
122
|
+
* @param {CustomEvent} event `close` event.
|
|
123
|
+
*/
|
|
124
|
+
const onDialogClose = async (event) => {
|
|
125
|
+
const canceled = event.detail.returnValue === 'cancel';
|
|
126
|
+
|
|
127
|
+
if (!canceled && rowCount && columnCount) {
|
|
128
|
+
const size = { rows: rowCount, columns: columnCount };
|
|
129
|
+
|
|
130
|
+
if (editorStore.useRichText) {
|
|
131
|
+
await insertRichText(size);
|
|
132
|
+
} else {
|
|
133
|
+
await insertPlainText(size);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// The dialog leaves the focus alone (see `restoreFocus` below), so bring it back here
|
|
140
|
+
if (editorStore.useRichText) {
|
|
141
|
+
// The button is only enabled while the editor is there
|
|
142
|
+
/* v8 ignore else */
|
|
143
|
+
if (editorStore.editor) {
|
|
144
|
+
await focusEditor(editorStore.editor);
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
editorStore.textArea?.focus();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
</script>
|
|
151
|
+
|
|
152
|
+
<Button
|
|
153
|
+
iconic
|
|
154
|
+
{disabled}
|
|
155
|
+
aria-label={_(`_sui.text_editor.${AVAILABLE_BUTTONS.table.labelKey}`)}
|
|
156
|
+
aria-controls={editorStore.controlId}
|
|
157
|
+
onclick={() => {
|
|
158
|
+
onButtonClick();
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
{#snippet startIcon()}
|
|
162
|
+
<Icon name={AVAILABLE_BUTTONS.table.icon} />
|
|
163
|
+
{/snippet}
|
|
164
|
+
</Button>
|
|
165
|
+
|
|
166
|
+
<Dialog
|
|
167
|
+
title={_('_sui.text_editor.insert_table')}
|
|
168
|
+
bind:open={openDialog}
|
|
169
|
+
okDisabled={!isValid}
|
|
170
|
+
okLabel={_('_sui.insert')}
|
|
171
|
+
restoreFocus={false}
|
|
172
|
+
onClose={(event) => {
|
|
173
|
+
onDialogClose(event);
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
<div role="none" class="table-size">
|
|
177
|
+
<label for="{id}-rows">{_('_sui.text_editor.rows')}</label>
|
|
178
|
+
<NumberInput
|
|
179
|
+
id="{id}-rows"
|
|
180
|
+
bind:value={rows}
|
|
181
|
+
min={1}
|
|
182
|
+
max={MAX_TABLE_SIZE}
|
|
183
|
+
invalid={!rowCount}
|
|
184
|
+
aria-label={_('_sui.text_editor.rows')}
|
|
185
|
+
onkeydown={(event) => {
|
|
186
|
+
onInputKeyDown(event);
|
|
187
|
+
}}
|
|
188
|
+
/>
|
|
189
|
+
<label for="{id}-columns">{_('_sui.text_editor.columns')}</label>
|
|
190
|
+
<NumberInput
|
|
191
|
+
id="{id}-columns"
|
|
192
|
+
bind:value={columns}
|
|
193
|
+
min={1}
|
|
194
|
+
max={MAX_TABLE_SIZE}
|
|
195
|
+
invalid={!columnCount}
|
|
196
|
+
aria-label={_('_sui.text_editor.columns')}
|
|
197
|
+
onkeydown={(event) => {
|
|
198
|
+
onInputKeyDown(event);
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
</div>
|
|
202
|
+
</Dialog>
|
|
203
|
+
|
|
204
|
+
<style>.table-size {
|
|
205
|
+
display: grid;
|
|
206
|
+
grid-template-columns: auto 1fr;
|
|
207
|
+
align-items: center;
|
|
208
|
+
gap: 8px 16px;
|
|
209
|
+
}</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default InsertTableButton;
|
|
2
|
+
type InsertTableButton = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props>): void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Toolbar button to insert a table. It opens a dialog to choose the number of rows and columns, then
|
|
8
|
+
* inserts an empty table with a header row: a table node in the rich text mode, or its Markdown in
|
|
9
|
+
* the plain text mode.
|
|
10
|
+
*/
|
|
11
|
+
declare const InsertTableButton: import("svelte").Component<{
|
|
12
|
+
/**
|
|
13
|
+
* Whether to disable the button, like when the caret is already in
|
|
14
|
+
* a table, as tables can’t be nested.
|
|
15
|
+
*/
|
|
16
|
+
disabled?: boolean | undefined;
|
|
17
|
+
}, {}, "">;
|
|
18
|
+
type Props = {
|
|
19
|
+
/**
|
|
20
|
+
* Whether to disable the button, like when the caret is already in
|
|
21
|
+
* a table, as tables can’t be nested.
|
|
22
|
+
*/
|
|
23
|
+
disabled?: boolean | undefined;
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function waitForMenuToClose(item: HTMLElement, frames?: number): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for the menus on the text editor toolbar.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Maximum number of frames to wait for a menu to close.
|
|
7
|
+
*/
|
|
8
|
+
const MAX_CLOSE_FRAMES = 60;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wait for the menu the given item is in to close. A menu is a modal dialog, which makes the rest
|
|
12
|
+
* of the page inert while it’s open, so the editor can’t take the focus yet. Once closed, the
|
|
13
|
+
* dialog moves the focus back to the button that opened it on the next task, so wait for that as
|
|
14
|
+
* well.
|
|
15
|
+
* Call this before moving the focus back to the editor after an item is chosen.
|
|
16
|
+
* @param {HTMLElement} item Menu item chosen.
|
|
17
|
+
* @param {number} [frames] Number of frames waited so far.
|
|
18
|
+
* @returns {Promise<void>} Nothing.
|
|
19
|
+
*/
|
|
20
|
+
export const waitForMenuToClose = async (item, frames = 0) => {
|
|
21
|
+
if (item.closest('dialog')?.open && frames < MAX_CLOSE_FRAMES) {
|
|
22
|
+
await new Promise((resolve) => {
|
|
23
|
+
window.requestAnimationFrame(resolve);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return waitForMenuToClose(item, frames + 1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
window.setTimeout(resolve);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Menu of the operations on a table: inserting and deleting rows and columns, and deleting the whole
|
|
4
|
+
table. It’s opened from the toolbar or the button on the selected table cell.
|
|
5
|
+
-->
|
|
6
|
+
<script>
|
|
7
|
+
import { _ } from '@sveltia/i18n';
|
|
8
|
+
import { getContext } from 'svelte';
|
|
9
|
+
import Divider from '../../divider/divider.svelte';
|
|
10
|
+
import MenuItem from '../../menu/menu-item.svelte';
|
|
11
|
+
import Menu from '../../menu/menu.svelte';
|
|
12
|
+
import { focusEditor } from '../core.js';
|
|
13
|
+
import { isRightToLeftTable, $runTableAction as runTableAction } from '../table.js';
|
|
14
|
+
import { waitForMenuToClose } from './menu.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @import { TextEditorStore } from '../../../typedefs.js';
|
|
18
|
+
* @import { TableAction } from '../table.js';
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {object} Props
|
|
23
|
+
* @property {string} cellKey Key of the table cell to run the operations on.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** @type {Props} */
|
|
27
|
+
let {
|
|
28
|
+
/* eslint-disable prefer-const */
|
|
29
|
+
cellKey,
|
|
30
|
+
/* eslint-enable prefer-const */
|
|
31
|
+
} = $props();
|
|
32
|
+
|
|
33
|
+
/** @type {TextEditorStore} */
|
|
34
|
+
const editorStore = getContext('editorStore');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Menu items, grouped by what they do. Each item has the operation and the key of its label.
|
|
38
|
+
* @type {[TableAction, string][][]}
|
|
39
|
+
*/
|
|
40
|
+
const ITEM_GROUPS = [
|
|
41
|
+
[
|
|
42
|
+
['insert-row-above', 'insert_row_above'],
|
|
43
|
+
['insert-row-below', 'insert_row_below'],
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
['insert-column-left', 'insert_column_left'],
|
|
47
|
+
['insert-column-right', 'insert_column_right'],
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
['delete-row', 'delete_row'],
|
|
51
|
+
['delete-column', 'delete_column'],
|
|
52
|
+
['delete-table', 'delete_table'],
|
|
53
|
+
],
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Run the given operation on the cell, then move the focus back to the editor.
|
|
58
|
+
* @param {TableAction} action Operation.
|
|
59
|
+
* @param {HTMLElement} item Menu item chosen.
|
|
60
|
+
*/
|
|
61
|
+
const runAction = async (action, item) => {
|
|
62
|
+
const { editor } = editorStore;
|
|
63
|
+
|
|
64
|
+
// The menu is only shown for a cell in the editor
|
|
65
|
+
/* v8 ignore next 3 */
|
|
66
|
+
if (!editor) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const cell = editor.getElementByKey(cellKey);
|
|
71
|
+
const rtl = !!cell && isRightToLeftTable(cell);
|
|
72
|
+
|
|
73
|
+
editor.update(() => {
|
|
74
|
+
runTableAction(action, cellKey, { rtl });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await waitForMenuToClose(item);
|
|
78
|
+
await focusEditor(editor);
|
|
79
|
+
};
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<Menu ariaLabel={_('_sui.text_editor.table_options')}>
|
|
83
|
+
{#each ITEM_GROUPS as items, index (index)}
|
|
84
|
+
{#if index > 0}
|
|
85
|
+
<Divider />
|
|
86
|
+
{/if}
|
|
87
|
+
{#each items as [action, labelKey] (action)}
|
|
88
|
+
<MenuItem
|
|
89
|
+
label={_(`_sui.text_editor.${labelKey}`)}
|
|
90
|
+
onclick={(/** @type {MouseEvent} */ event) => {
|
|
91
|
+
runAction(action, /** @type {HTMLElement} */ (event.currentTarget));
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
{/each}
|
|
95
|
+
{/each}
|
|
96
|
+
</Menu>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default TableActionMenu;
|
|
2
|
+
type TableActionMenu = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props>): void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Menu of the operations on a table: inserting and deleting rows and columns, and deleting the whole
|
|
8
|
+
* table. It’s opened from the toolbar or the button on the selected table cell.
|
|
9
|
+
*/
|
|
10
|
+
declare const TableActionMenu: import("svelte").Component<{
|
|
11
|
+
/**
|
|
12
|
+
* Key of the table cell to run the operations on.
|
|
13
|
+
*/
|
|
14
|
+
cellKey: string;
|
|
15
|
+
}, {}, "">;
|
|
16
|
+
type Props = {
|
|
17
|
+
/**
|
|
18
|
+
* Key of the table cell to run the operations on.
|
|
19
|
+
*/
|
|
20
|
+
cellKey: string;
|
|
21
|
+
};
|
|
@@ -11,10 +11,14 @@
|
|
|
11
11
|
import Menu from '../../menu/menu.svelte';
|
|
12
12
|
import { AVAILABLE_BUTTONS, BLOCK_BUTTON_TYPES, INLINE_BUTTON_TYPES } from '../constants.js';
|
|
13
13
|
import CodeLanguageSwitcher from './code-language-switcher.svelte';
|
|
14
|
+
import AlignMenuButton from './align-menu-button.svelte';
|
|
14
15
|
import FormatTextButton from './format-text-button.svelte';
|
|
16
|
+
import InsertHorizontalRuleButton from './insert-horizontal-rule-button.svelte';
|
|
15
17
|
import InsertItemButton from './insert-item-button.svelte';
|
|
16
18
|
import InsertLinkButton from './insert-link-button.svelte';
|
|
17
19
|
import InsertMenuButton from './insert-menu-button.svelte';
|
|
20
|
+
import InsertTableButton from './insert-table-button.svelte';
|
|
21
|
+
import TableActionMenu from './table-action-menu.svelte';
|
|
18
22
|
import ToggleBlockMenuItem from './toggle-block-menu-item.svelte';
|
|
19
23
|
import ToolbarWrapper from './toolbar-wrapper.svelte';
|
|
20
24
|
|
|
@@ -71,6 +75,41 @@
|
|
|
71
75
|
*/
|
|
72
76
|
const canFormat = $derived(editorStore.useRichText || !isHtml);
|
|
73
77
|
|
|
78
|
+
const hasTable = $derived(editorStore.config.enabledButtons.includes('table'));
|
|
79
|
+
/**
|
|
80
|
+
* Whether the alignment menu is available. Markdown has no syntax for alignment, so it’s only
|
|
81
|
+
* available for HTML, and only in the rich text mode, as the plain text mode shows the source.
|
|
82
|
+
*/
|
|
83
|
+
const canAlign = $derived(
|
|
84
|
+
isHtml && editorStore.useRichText && editorStore.config.enabledButtons.includes('align'),
|
|
85
|
+
);
|
|
86
|
+
const hasHorizontalRule = $derived(editorStore.config.enabledButtons.includes('horizontal-rule'));
|
|
87
|
+
/**
|
|
88
|
+
* Key of the table cell the caret is in, if any. The table menu only works with the rich text
|
|
89
|
+
* editor.
|
|
90
|
+
*/
|
|
91
|
+
const tableCellKey = $derived(
|
|
92
|
+
editorStore.useRichText ? (editorStore.selection.tableCellKey ?? null) : null,
|
|
93
|
+
);
|
|
94
|
+
/**
|
|
95
|
+
* Whether the caret is in a Markdown table cell, which can only have inline content, so neither
|
|
96
|
+
* a horizontal rule nor an editor component can be inserted. A cell is also exported with the
|
|
97
|
+
* standard Markdown syntax only, so an editor component would be lost.
|
|
98
|
+
*/
|
|
99
|
+
const inMarkdownTable = $derived(!!tableCellKey && !isHtml);
|
|
100
|
+
/**
|
|
101
|
+
* Whether any of the buttons to insert a table, a horizontal rule or an editor component is
|
|
102
|
+
* shown.
|
|
103
|
+
*/
|
|
104
|
+
const hasInsertButtons = $derived(
|
|
105
|
+
hasTable ||
|
|
106
|
+
(!inMarkdownTable && (hasHorizontalRule || editorStore.config.components.length > 0)),
|
|
107
|
+
);
|
|
108
|
+
/**
|
|
109
|
+
* Whether the block level styles are available.
|
|
110
|
+
*/
|
|
111
|
+
const canChangeBlock = $derived(canFormat && !inMarkdownTable);
|
|
112
|
+
|
|
74
113
|
/**
|
|
75
114
|
* Enabled inline level buttons.
|
|
76
115
|
* @type {TextEditorInlineType[]}
|
|
@@ -85,7 +124,7 @@
|
|
|
85
124
|
</script>
|
|
86
125
|
|
|
87
126
|
<ToolbarWrapper disabled={disabled || readonly} ariaLabel={_('_sui.text_editor.text_editor')}>
|
|
88
|
-
{#if
|
|
127
|
+
{#if canChangeBlock && blockLevelButtons.length > 1}
|
|
89
128
|
<MenuButton
|
|
90
129
|
aria-label={_('_sui.text_editor.show_text_style_options')}
|
|
91
130
|
aria-controls={editorStore.controlId}
|
|
@@ -109,6 +148,22 @@
|
|
|
109
148
|
<Divider orientation="vertical" />
|
|
110
149
|
<CodeLanguageSwitcher />
|
|
111
150
|
{:else if canFormat}
|
|
151
|
+
{#if hasTable && tableCellKey}
|
|
152
|
+
{#if canChangeBlock && blockLevelButtons.length > 1}
|
|
153
|
+
<Divider orientation="vertical" />
|
|
154
|
+
{/if}
|
|
155
|
+
<MenuButton
|
|
156
|
+
aria-label={_('_sui.text_editor.show_table_options')}
|
|
157
|
+
aria-controls={editorStore.controlId}
|
|
158
|
+
>
|
|
159
|
+
{#snippet startIcon()}
|
|
160
|
+
<Icon name="table_edit" />
|
|
161
|
+
{/snippet}
|
|
162
|
+
{#snippet popup()}
|
|
163
|
+
<TableActionMenu cellKey={tableCellKey} />
|
|
164
|
+
{/snippet}
|
|
165
|
+
</MenuButton>
|
|
166
|
+
{/if}
|
|
112
167
|
{#if inlineLevelButtons.length}
|
|
113
168
|
<Divider orientation="vertical" />
|
|
114
169
|
<ButtonGroup>
|
|
@@ -121,13 +176,26 @@
|
|
|
121
176
|
{/each}
|
|
122
177
|
</ButtonGroup>
|
|
123
178
|
{/if}
|
|
124
|
-
{#if
|
|
179
|
+
{#if canAlign}
|
|
180
|
+
<Divider orientation="vertical" />
|
|
181
|
+
<AlignMenuButton />
|
|
182
|
+
{/if}
|
|
183
|
+
{#if hasInsertButtons}
|
|
125
184
|
<Divider orientation="vertical" />
|
|
126
|
-
{#
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
|
|
185
|
+
{#if hasTable}
|
|
186
|
+
<!-- Tables can’t be nested -->
|
|
187
|
+
<InsertTableButton disabled={!!tableCellKey} />
|
|
188
|
+
{/if}
|
|
189
|
+
{#if !inMarkdownTable}
|
|
190
|
+
{#if hasHorizontalRule}
|
|
191
|
+
<InsertHorizontalRuleButton />
|
|
192
|
+
{/if}
|
|
193
|
+
{#each buttons as button (button.id)}
|
|
194
|
+
<InsertItemButton component={button} />
|
|
195
|
+
{/each}
|
|
196
|
+
{#if menuitems.length}
|
|
197
|
+
<InsertMenuButton components={menuitems} />
|
|
198
|
+
{/if}
|
|
131
199
|
{/if}
|
|
132
200
|
{/if}
|
|
133
201
|
{/if}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { ElementTransformer } from '@lexical/markdown';
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* Markdown of a horizontal rule. Unlike `---`, it can’t be taken for the underline of a setext
|
|
6
|
+
* heading or the delimiter of front matter.
|
|
7
|
+
*/
|
|
8
|
+
export const HORIZONTAL_RULE_MARKDOWN: "***";
|
|
4
9
|
/**
|
|
5
10
|
* @type {ElementTransformer}
|
|
6
11
|
*/
|
|
@@ -12,12 +12,18 @@ import {
|
|
|
12
12
|
* @import { ElementTransformer } from '@lexical/markdown';
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Markdown of a horizontal rule. Unlike `---`, it can’t be taken for the underline of a setext
|
|
17
|
+
* heading or the delimiter of front matter.
|
|
18
|
+
*/
|
|
19
|
+
export const HORIZONTAL_RULE_MARKDOWN = '***';
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* @type {ElementTransformer}
|
|
17
23
|
*/
|
|
18
24
|
export const HR = {
|
|
19
25
|
dependencies: [HorizontalRuleNode],
|
|
20
|
-
export: (node) => (isHorizontalRuleNode(node) ?
|
|
26
|
+
export: (node) => (isHorizontalRuleNode(node) ? HORIZONTAL_RULE_MARKDOWN : null),
|
|
21
27
|
regExp: /^(---|\*\*\*|___)\s?$/,
|
|
22
28
|
replace: (parentNode, _1, _2, isImport) => {
|
|
23
29
|
const line = createHorizontalRuleNode();
|
|
@@ -50,8 +50,9 @@ export const getTableColumnsSize = (table) => {
|
|
|
50
50
|
* @returns {TableCellNode}
|
|
51
51
|
*/
|
|
52
52
|
const createTableCell = (textContent) => {
|
|
53
|
-
// An escaped pipe is part of the cell, even within inline code, like GitHub Flavored Markdown
|
|
54
|
-
|
|
53
|
+
// An escaped pipe is part of the cell, even within inline code, like GitHub Flavored Markdown.
|
|
54
|
+
// The spaces around the content only separate it from the pipes
|
|
55
|
+
textContent = textContent.trim().replace(/\\n/g, '\n').replace(/\\\|/g, '|');
|
|
55
56
|
|
|
56
57
|
const cell = createTableCellNode(TableCellHeaderStates.NO_STATUS);
|
|
57
58
|
|
package/dist/locales/ar.yaml
CHANGED
|
@@ -134,6 +134,34 @@ text_editor:
|
|
|
134
134
|
# Link dialog input field labels
|
|
135
135
|
text: نص
|
|
136
136
|
url: الرابط
|
|
137
|
+
# Link dialog checkbox label and floating link editor button aria-label
|
|
138
|
+
open_in_new_tab: فتح في علامة تبويب جديدة
|
|
139
|
+
# Table dialog title
|
|
140
|
+
insert_table: إدراج جدول
|
|
141
|
+
# Table dialog input field labels
|
|
142
|
+
rows: الصفوف
|
|
143
|
+
columns: الأعمدة
|
|
144
|
+
# Table menu button and menu aria-labels
|
|
145
|
+
table_options: خيارات الجدول
|
|
146
|
+
show_table_options: إظهار خيارات الجدول
|
|
147
|
+
# Table menu items
|
|
148
|
+
insert_row_above: إدراج صف أعلاه
|
|
149
|
+
insert_row_below: إدراج صف أسفله
|
|
150
|
+
insert_column_left: إدراج عمود إلى اليسار
|
|
151
|
+
insert_column_right: إدراج عمود إلى اليمين
|
|
152
|
+
delete_row: حذف الصف
|
|
153
|
+
delete_column: حذف العمود
|
|
154
|
+
delete_table: حذف الجدول
|
|
155
|
+
# Horizontal rule button aria-label
|
|
156
|
+
insert_horizontal_rule: إدراج خط أفقي
|
|
157
|
+
# Alignment menu button and menu aria-labels
|
|
158
|
+
alignment_options: خيارات المحاذاة
|
|
159
|
+
show_alignment_options: إظهار خيارات المحاذاة
|
|
160
|
+
# Alignment menu items
|
|
161
|
+
align_left: محاذاة لليسار
|
|
162
|
+
align_center: توسيط
|
|
163
|
+
align_right: محاذاة لليمين
|
|
164
|
+
align_justify: ضبط
|
|
137
165
|
# Markdown mode toggle button aria-label
|
|
138
166
|
edit_in_markdown: التحرير بلغة Markdown
|
|
139
167
|
# HTML mode toggle button aria-label
|
package/dist/locales/bg.yaml
CHANGED
|
@@ -134,6 +134,34 @@ text_editor:
|
|
|
134
134
|
# Link dialog input field labels
|
|
135
135
|
text: Текст
|
|
136
136
|
url: URL адрес
|
|
137
|
+
# Link dialog checkbox label and floating link editor button aria-label
|
|
138
|
+
open_in_new_tab: Отваряне в нов раздел
|
|
139
|
+
# Table dialog title
|
|
140
|
+
insert_table: Вмъкване на таблица
|
|
141
|
+
# Table dialog input field labels
|
|
142
|
+
rows: Редове
|
|
143
|
+
columns: Колони
|
|
144
|
+
# Table menu button and menu aria-labels
|
|
145
|
+
table_options: Опции за таблицата
|
|
146
|
+
show_table_options: Показване на опциите за таблицата
|
|
147
|
+
# Table menu items
|
|
148
|
+
insert_row_above: Вмъкване на ред отгоре
|
|
149
|
+
insert_row_below: Вмъкване на ред отдолу
|
|
150
|
+
insert_column_left: Вмъкване на колона отляво
|
|
151
|
+
insert_column_right: Вмъкване на колона отдясно
|
|
152
|
+
delete_row: Изтриване на реда
|
|
153
|
+
delete_column: Изтриване на колоната
|
|
154
|
+
delete_table: Изтриване на таблицата
|
|
155
|
+
# Horizontal rule button aria-label
|
|
156
|
+
insert_horizontal_rule: Вмъкване на хоризонтална линия
|
|
157
|
+
# Alignment menu button and menu aria-labels
|
|
158
|
+
alignment_options: Опции за подравняване
|
|
159
|
+
show_alignment_options: Показване на опциите за подравняване
|
|
160
|
+
# Alignment menu items
|
|
161
|
+
align_left: Подравняване вляво
|
|
162
|
+
align_center: Центриране
|
|
163
|
+
align_right: Подравняване вдясно
|
|
164
|
+
align_justify: Двустранно подравняване
|
|
137
165
|
# Markdown mode toggle button aria-label
|
|
138
166
|
edit_in_markdown: Редактиране в Markdown
|
|
139
167
|
# HTML mode toggle button aria-label
|
package/dist/locales/ca.yaml
CHANGED
|
@@ -134,6 +134,34 @@ text_editor:
|
|
|
134
134
|
# Link dialog input field labels
|
|
135
135
|
text: Text
|
|
136
136
|
url: URL
|
|
137
|
+
# Link dialog checkbox label and floating link editor button aria-label
|
|
138
|
+
open_in_new_tab: Obre en una pestanya nova
|
|
139
|
+
# Table dialog title
|
|
140
|
+
insert_table: Insereix una taula
|
|
141
|
+
# Table dialog input field labels
|
|
142
|
+
rows: Files
|
|
143
|
+
columns: Columnes
|
|
144
|
+
# Table menu button and menu aria-labels
|
|
145
|
+
table_options: Opcions de la taula
|
|
146
|
+
show_table_options: Mostra les opcions de la taula
|
|
147
|
+
# Table menu items
|
|
148
|
+
insert_row_above: Insereix una fila a sobre
|
|
149
|
+
insert_row_below: Insereix una fila a sota
|
|
150
|
+
insert_column_left: Insereix una columna a l’esquerra
|
|
151
|
+
insert_column_right: Insereix una columna a la dreta
|
|
152
|
+
delete_row: Elimina la fila
|
|
153
|
+
delete_column: Elimina la columna
|
|
154
|
+
delete_table: Elimina la taula
|
|
155
|
+
# Horizontal rule button aria-label
|
|
156
|
+
insert_horizontal_rule: Insereix una línia horitzontal
|
|
157
|
+
# Alignment menu button and menu aria-labels
|
|
158
|
+
alignment_options: Opcions d’alineació
|
|
159
|
+
show_alignment_options: Mostra les opcions d’alineació
|
|
160
|
+
# Alignment menu items
|
|
161
|
+
align_left: Alinea a l’esquerra
|
|
162
|
+
align_center: Centra
|
|
163
|
+
align_right: Alinea a la dreta
|
|
164
|
+
align_justify: Justifica
|
|
137
165
|
# Markdown mode toggle button aria-label
|
|
138
166
|
edit_in_markdown: Edita en Markdown
|
|
139
167
|
# HTML mode toggle button aria-label
|