@sveltia/ui 0.90.0 → 0.91.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/text-editor/constants.d.ts +40 -6
- package/dist/components/text-editor/constants.js +81 -7
- package/dist/components/text-editor/conversion/html/components.d.ts +16 -0
- package/dist/components/text-editor/conversion/html/components.js +87 -0
- package/dist/components/text-editor/conversion/html/export.d.ts +10 -0
- package/dist/components/text-editor/conversion/html/export.js +360 -0
- package/dist/components/text-editor/conversion/html/import-rules.d.ts +12 -0
- package/dist/components/text-editor/conversion/html/import-rules.js +234 -0
- package/dist/components/text-editor/conversion/html/index.d.ts +10 -0
- package/dist/components/text-editor/conversion/html/index.js +33 -0
- package/dist/components/text-editor/conversion/html/paragraph.d.ts +1 -0
- package/dist/components/text-editor/conversion/html/paragraph.js +123 -0
- package/dist/components/text-editor/conversion/html/task-list.d.ts +13 -0
- package/dist/components/text-editor/conversion/html/task-list.js +82 -0
- package/dist/components/text-editor/conversion/html/unsupported.d.ts +2 -0
- package/dist/components/text-editor/conversion/html/unsupported.js +122 -0
- package/dist/components/text-editor/conversion/html/utils.d.ts +6 -0
- package/dist/components/text-editor/conversion/html/utils.js +34 -0
- package/dist/components/text-editor/conversion/import.js +1 -1
- package/dist/components/text-editor/conversion/transformers/task-list.d.ts +24 -0
- package/dist/components/text-editor/conversion/transformers/task-list.js +53 -0
- package/dist/components/text-editor/conversion/update.js +1 -1
- package/dist/components/text-editor/core.js +4 -12
- package/dist/components/text-editor/editing/commands.js +9 -18
- package/dist/components/text-editor/editing/guards.d.ts +7 -0
- package/dist/components/text-editor/editing/guards.js +123 -0
- package/dist/components/text-editor/editing/raw-markdown.d.ts +4 -2
- package/dist/components/text-editor/editing/raw-markdown.js +22 -6
- package/dist/components/text-editor/editing/selection.js +6 -2
- package/dist/components/text-editor/lexical-root.svelte +40 -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/text-editor.svelte +7 -4
- package/dist/components/text-editor/text-editor.svelte.d.ts +4 -2
- package/dist/components/text-editor/toolbar/format-text-button.svelte +7 -1
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +19 -8
- package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +7 -14
- package/dist/locales/ar.yaml +2 -0
- package/dist/locales/bg.yaml +2 -0
- package/dist/locales/ca.yaml +2 -0
- package/dist/locales/cs.yaml +2 -0
- package/dist/locales/da.yaml +2 -0
- package/dist/locales/de.yaml +2 -0
- package/dist/locales/el.yaml +2 -0
- package/dist/locales/en-CA.yaml +2 -0
- package/dist/locales/en-GB.yaml +2 -0
- package/dist/locales/en-US.yaml +2 -0
- package/dist/locales/en-ZA.yaml +2 -0
- package/dist/locales/es-CO.yaml +2 -0
- package/dist/locales/es-ES.yaml +2 -0
- package/dist/locales/fa.yaml +2 -0
- package/dist/locales/fi.yaml +2 -0
- package/dist/locales/fr.yaml +2 -0
- package/dist/locales/he.yaml +2 -0
- package/dist/locales/hr.yaml +2 -0
- package/dist/locales/it.yaml +2 -0
- package/dist/locales/ja.yaml +2 -0
- package/dist/locales/ko.yaml +2 -0
- package/dist/locales/nl.yaml +2 -0
- package/dist/locales/pl.yaml +2 -0
- package/dist/locales/pt-BR.yaml +2 -0
- package/dist/locales/pt-PT.yaml +2 -0
- package/dist/locales/ru.yaml +2 -0
- package/dist/locales/sk.yaml +2 -0
- package/dist/locales/sv.yaml +2 -0
- package/dist/locales/tr.yaml +2 -0
- package/dist/locales/uk.yaml +2 -0
- package/dist/locales/vi.yaml +2 -0
- package/dist/locales/zh-CN.yaml +2 -0
- package/dist/locales/zh-TW.yaml +2 -0
- package/dist/typedefs.d.ts +5 -2
- package/dist/typedefs.js +3 -2
- package/package.json +5 -5
- package/dist/components/text-editor/conversion/html.d.ts +0 -30
- package/dist/components/text-editor/conversion/html.js +0 -857
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards that keep the formats and blocks a field can’t hold out of the editor, as they could come
|
|
3
|
+
* in anyway with a keyboard shortcut Lexical handles on its own, pasted HTML or a stored value.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ListNode } from '@lexical/list';
|
|
7
|
+
import {
|
|
8
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
9
|
+
FORMAT_TEXT_COMMAND,
|
|
10
|
+
$getSelection as getSelection,
|
|
11
|
+
$isRangeSelection as isRangeSelection,
|
|
12
|
+
$isTextNode as isTextNode,
|
|
13
|
+
TextNode,
|
|
14
|
+
} from 'lexical';
|
|
15
|
+
import { HTML_ONLY_FORMAT_TYPES, isHtmlOnlyButton, LIST_TYPES } from '../constants.js';
|
|
16
|
+
import { mergeUnregisters } from '../utils.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @import { LexicalEditor, TextFormatType } from 'lexical';
|
|
20
|
+
* @import { TextEditorConfig, TextEditorValueFormat } from '../../../typedefs.js';
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Remove the given format from all the text in the selection, including the text partly selected,
|
|
25
|
+
* or from the text to be typed at the caret. Unlike Lexical’s own toggle, which follows the text at
|
|
26
|
+
* the start of the selection, it never applies the format.
|
|
27
|
+
* @param {TextFormatType} type Format type.
|
|
28
|
+
*/
|
|
29
|
+
const $removeFormat = (type) => {
|
|
30
|
+
const selection = getSelection();
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
!isRangeSelection(selection) ||
|
|
34
|
+
!(
|
|
35
|
+
selection.hasFormat(type) ||
|
|
36
|
+
selection.getNodes().some((node) => isTextNode(node) && node.hasFormat(type))
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Align every node with a format that doesn’t have it
|
|
43
|
+
selection.formatText(type, 0);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Keep the HTML-only text formats, like underline, out of the editor unless their buttons are
|
|
48
|
+
* enabled for HTML. Lexical applies underline with the Ctrl/Cmd+U shortcut on its own, and pasted
|
|
49
|
+
* HTML can bring it in as well. For Markdown, which has no syntax for them and would drop them when
|
|
50
|
+
* saved, the formats are removed from any text that gets them, and the shortcut does nothing. For
|
|
51
|
+
* HTML without the button, the shortcut can only remove an existing format, like one in the stored
|
|
52
|
+
* value or in pasted text, which would otherwise have no button to undo it.
|
|
53
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
54
|
+
* @param {object} args Arguments.
|
|
55
|
+
* @param {TextEditorValueFormat} args.format Value format.
|
|
56
|
+
* @param {TextEditorConfig['enabledButtons']} args.enabledButtons Enabled buttons.
|
|
57
|
+
* @returns {() => void} Cleanup handler.
|
|
58
|
+
*/
|
|
59
|
+
const registerFormatGuard = (editor, { format, enabledButtons = [] }) => {
|
|
60
|
+
if (format !== 'html') {
|
|
61
|
+
return mergeUnregisters(
|
|
62
|
+
editor.registerNodeTransform(TextNode, (node) => {
|
|
63
|
+
HTML_ONLY_FORMAT_TYPES.forEach((type) => {
|
|
64
|
+
if (node.hasFormat(type)) {
|
|
65
|
+
node.toggleFormat(type);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}),
|
|
69
|
+
editor.registerCommand(FORMAT_TEXT_COMMAND, isHtmlOnlyButton, COMMAND_PRIORITY_CRITICAL),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return editor.registerCommand(
|
|
74
|
+
FORMAT_TEXT_COMMAND,
|
|
75
|
+
(type) => {
|
|
76
|
+
if (!isHtmlOnlyButton(type) || enabledButtons.includes(type)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
$removeFormat(type);
|
|
81
|
+
|
|
82
|
+
return true;
|
|
83
|
+
},
|
|
84
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Turn a task list into a bulleted list without the task list button, as its items couldn’t be
|
|
90
|
+
* toggled. One can come in with pasted HTML, for example. `ListNode` is only registered with a list
|
|
91
|
+
* button, so nothing is registered without any.
|
|
92
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
93
|
+
* @param {TextEditorConfig['enabledButtons']} enabledButtons Enabled buttons.
|
|
94
|
+
* @returns {(() => void) | undefined} Cleanup handler, if anything is registered.
|
|
95
|
+
*/
|
|
96
|
+
const registerTaskListGuard = (editor, enabledButtons = []) => {
|
|
97
|
+
if (
|
|
98
|
+
enabledButtons.includes('task-list') ||
|
|
99
|
+
!LIST_TYPES.some(({ type }) => enabledButtons.includes(type))
|
|
100
|
+
) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return editor.registerNodeTransform(ListNode, (list) => {
|
|
105
|
+
if (list.getListType() === 'check') {
|
|
106
|
+
list.setListType('bullet');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Register all the guards.
|
|
113
|
+
* @param {LexicalEditor} editor Editor instance.
|
|
114
|
+
* @param {object} args Arguments.
|
|
115
|
+
* @param {TextEditorValueFormat} args.format Value format.
|
|
116
|
+
* @param {TextEditorConfig['enabledButtons']} args.enabledButtons Enabled buttons.
|
|
117
|
+
* @returns {() => void} Cleanup handler.
|
|
118
|
+
*/
|
|
119
|
+
export const registerGuards = (editor, { format, enabledButtons = [] }) =>
|
|
120
|
+
mergeUnregisters(
|
|
121
|
+
registerFormatGuard(editor, { format, enabledButtons }),
|
|
122
|
+
registerTaskListGuard(editor, enabledButtons),
|
|
123
|
+
);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export function getBlockType(state: RawTextState
|
|
2
|
-
|
|
1
|
+
export function getBlockType(state: RawTextState, { hasTaskList }?: {
|
|
2
|
+
hasTaskList?: boolean | undefined;
|
|
3
|
+
}): TextEditorBlockType;
|
|
4
|
+
export function toggleInlineFormat({ value, start, end }: RawTextState, type: Exclude<TextEditorFormatType, "underline">): RawTextEdit;
|
|
3
5
|
export function setBlockType(state: RawTextState, type: TextEditorBlockType): RawTextEdit;
|
|
4
6
|
export function insertLink({ value, start, end }: RawTextState, { url, text }: {
|
|
5
7
|
url: string;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { isMac, matchesShortcuts } from '@sveltia/utils/events';
|
|
10
10
|
import { getComponentMarkdown } from '../conversion/editor-components.js';
|
|
11
|
+
import { TASK_LIST_ITEM_REGEX } from '../conversion/transformers/task-list.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @import {
|
|
@@ -37,8 +38,8 @@ import { getComponentMarkdown } from '../conversion/editor-components.js';
|
|
|
37
38
|
*/
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
|
-
* Markdown markers for the inline formats.
|
|
41
|
-
* @type {Record<TextEditorFormatType, string>}
|
|
41
|
+
* Markdown markers for the inline formats. Markdown has no syntax for underline.
|
|
42
|
+
* @type {Record<Exclude<TextEditorFormatType, 'underline'>, string>}
|
|
42
43
|
*/
|
|
43
44
|
const INLINE_MARKERS = {
|
|
44
45
|
bold: '**',
|
|
@@ -48,9 +49,12 @@ const INLINE_MARKERS = {
|
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
|
-
* Prefix of a heading, list item or blockquote line
|
|
52
|
+
* Prefix of a heading, list item or blockquote line, including the check box of a task list item,
|
|
53
|
+
* which can only be one or two spaces after the marker; see `TASK_LIST_ITEM_REGEX`.
|
|
52
54
|
*/
|
|
53
|
-
const BLOCK_PREFIX_REGEX =
|
|
55
|
+
const BLOCK_PREFIX_REGEX =
|
|
56
|
+
/^(?:#{1,6}[ \t]+|>[ \t]?|[-*+](?:[ \t]{1,2}\[[ xX]\][ \t]+|[ \t]+)|\d+[.)][ \t]+)/;
|
|
57
|
+
|
|
54
58
|
const CODE_FENCE_REGEX = /^[ \t]*(?:```|~~~)/;
|
|
55
59
|
|
|
56
60
|
/**
|
|
@@ -111,9 +115,13 @@ const findCodeBlock = (lines, lineIndex) => {
|
|
|
111
115
|
/**
|
|
112
116
|
* Get the type of the block where the selection starts.
|
|
113
117
|
* @param {RawTextState} state Current state.
|
|
118
|
+
* @param {object} [options] Options.
|
|
119
|
+
* @param {boolean} [options.hasTaskList] Whether the task list button is enabled, which it isn’t
|
|
120
|
+
* by default. Without it, a task list item is a bulleted list item, as the rich text editor imports
|
|
121
|
+
* it.
|
|
114
122
|
* @returns {TextEditorBlockType} Block type.
|
|
115
123
|
*/
|
|
116
|
-
export const getBlockType = (state) => {
|
|
124
|
+
export const getBlockType = (state, { hasTaskList = false } = {}) => {
|
|
117
125
|
const lines = state.value.split('\n');
|
|
118
126
|
const lineIndex = getStartLineIndex(state);
|
|
119
127
|
const line = lines[lineIndex];
|
|
@@ -128,6 +136,10 @@ export const getBlockType = (state) => {
|
|
|
128
136
|
return /** @type {TextEditorBlockType} */ (`heading-${hashes.length}`);
|
|
129
137
|
}
|
|
130
138
|
|
|
139
|
+
if (hasTaskList && TASK_LIST_ITEM_REGEX.test(line)) {
|
|
140
|
+
return 'task-list';
|
|
141
|
+
}
|
|
142
|
+
|
|
131
143
|
if (/^[-*+][ \t]/.test(line)) {
|
|
132
144
|
return 'bulleted-list';
|
|
133
145
|
}
|
|
@@ -147,7 +159,7 @@ export const getBlockType = (state) => {
|
|
|
147
159
|
* Wrap the selection with the Markdown markers of the given inline format, or unwrap it if it’s
|
|
148
160
|
* already formatted. Without a selection, the markers are inserted with the caret in between.
|
|
149
161
|
* @param {RawTextState} state Current state.
|
|
150
|
-
* @param {TextEditorFormatType} type Format type.
|
|
162
|
+
* @param {Exclude<TextEditorFormatType, 'underline'>} type Format type.
|
|
151
163
|
* @returns {RawTextEdit} Edit.
|
|
152
164
|
*/
|
|
153
165
|
export const toggleInlineFormat = ({ value, start, end }, type) => {
|
|
@@ -273,6 +285,10 @@ export const setBlockType = (state, type) => {
|
|
|
273
285
|
return line.trim() ? '- ' : '';
|
|
274
286
|
}
|
|
275
287
|
|
|
288
|
+
if (type === 'task-list') {
|
|
289
|
+
return line.trim() ? '- [ ] ' : '';
|
|
290
|
+
}
|
|
291
|
+
|
|
276
292
|
if (type === 'numbered-list') {
|
|
277
293
|
if (!line.trim()) {
|
|
278
294
|
return '';
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
$getSelection as getSelection,
|
|
20
20
|
$isRangeSelection as isRangeSelection,
|
|
21
21
|
} from 'lexical';
|
|
22
|
-
import { BLOCK_BUTTON_TYPES, TEXT_FORMAT_BUTTON_TYPES } from '../constants.js';
|
|
22
|
+
import { BLOCK_BUTTON_TYPES, LIST_TYPES, TEXT_FORMAT_BUTTON_TYPES } from '../constants.js';
|
|
23
23
|
import { $getSelectedAlignment } from './alignment.js';
|
|
24
24
|
import { $getSelectedTableCellKey } from './table.js';
|
|
25
25
|
|
|
@@ -91,7 +91,11 @@ export const getSelectionTypes = () => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
if (isListNode(parent)) {
|
|
94
|
-
|
|
94
|
+
const listType = parent.getListType();
|
|
95
|
+
|
|
96
|
+
return /** @type {TextEditorBlockType} */ (
|
|
97
|
+
LIST_TYPES.find((list) => list.listType === listType)?.type
|
|
98
|
+
);
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
if (isQuoteNode(parent)) {
|
|
@@ -346,12 +346,52 @@
|
|
|
346
346
|
.lexical-root :global(strong.italic) {
|
|
347
347
|
font-style: italic;
|
|
348
348
|
}
|
|
349
|
+
.lexical-root :global(.underline) {
|
|
350
|
+
text-decoration: underline;
|
|
351
|
+
}
|
|
349
352
|
.lexical-root :global(.strikethrough) {
|
|
350
353
|
text-decoration: line-through;
|
|
351
354
|
}
|
|
355
|
+
.lexical-root :global(.underline.strikethrough) {
|
|
356
|
+
text-decoration: underline line-through;
|
|
357
|
+
}
|
|
352
358
|
.lexical-root :global(li.nested) {
|
|
353
359
|
list-style-type: none;
|
|
354
360
|
}
|
|
361
|
+
.lexical-root :global(li.task-list-item:not(.nested)) {
|
|
362
|
+
position: relative;
|
|
363
|
+
padding-inline-start: 1.5em;
|
|
364
|
+
list-style-type: none;
|
|
365
|
+
}
|
|
366
|
+
.lexical-root :global(li.task-list-item:not(.nested)::before) {
|
|
367
|
+
position: absolute;
|
|
368
|
+
inset-block-start: calc((1lh - 1em) / 2);
|
|
369
|
+
inset-inline-start: 0;
|
|
370
|
+
border: var(--sui-checkbox-border-width, 1.5px) solid var(--sui-checkbox-border-color);
|
|
371
|
+
border-radius: var(--sui-checkbox-border-radius);
|
|
372
|
+
width: 1em;
|
|
373
|
+
height: 1em;
|
|
374
|
+
background-color: var(--sui-checkbox-background-color);
|
|
375
|
+
content: "";
|
|
376
|
+
cursor: pointer;
|
|
377
|
+
}
|
|
378
|
+
.lexical-root :global(li.task-list-item:not(.nested).checked::before) {
|
|
379
|
+
border-color: var(--sui-checkbox-border-color-checked, var(--sui-primary-accent-color));
|
|
380
|
+
background-color: var(--sui-checkbox-background-color-checked, var(--sui-primary-accent-color));
|
|
381
|
+
}
|
|
382
|
+
.lexical-root :global(li.task-list-item:not(.nested).checked::after) {
|
|
383
|
+
position: absolute;
|
|
384
|
+
inset-block-start: calc((1lh - 1em) / 2 + 0.15em);
|
|
385
|
+
inset-inline-start: 0.35em;
|
|
386
|
+
border-width: 0 2px 2px 0;
|
|
387
|
+
border-style: solid;
|
|
388
|
+
border-color: var(--sui-checkbox-foreground-color-checked, var(--sui-primary-accent-color-inverted));
|
|
389
|
+
width: 0.3em;
|
|
390
|
+
height: 0.55em;
|
|
391
|
+
content: "";
|
|
392
|
+
transform: rotate(45deg);
|
|
393
|
+
pointer-events: none;
|
|
394
|
+
}
|
|
355
395
|
.lexical-root :global(.code-block) {
|
|
356
396
|
position: relative;
|
|
357
397
|
display: block;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import Alert from '../alert/alert.svelte';
|
|
9
9
|
import TextArea from '../text-field/text-area.svelte';
|
|
10
10
|
import Toast from '../toast/toast.svelte';
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_BUTTON_TYPES } from './constants.js';
|
|
12
12
|
import { loadCodeHighlighter } from './shiki/preload.js';
|
|
13
13
|
import EmojiAutocomplete from './widgets/emoji-autocomplete.svelte';
|
|
14
14
|
import FloatingLinkEditor from './widgets/floating-link-editor.svelte';
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
* @property {'ltr' | 'rtl' | 'auto'} [dir] The `dir` attribute on the editable text box, both
|
|
53
53
|
* the rich text editor and the `<textarea>` element of the plain text mode.
|
|
54
54
|
* @property {TextEditorMode[]} [modes] Enabled modes.
|
|
55
|
-
* @property {TextEditorNodeType[]} [buttons] Enabled buttons.
|
|
55
|
+
* @property {TextEditorNodeType[]} [buttons] Enabled buttons. All the inline and block level
|
|
56
|
+
* buttons by default, except the HTML-only `underline`.
|
|
56
57
|
* @property {TextEditorComponent[]} [components] Editor components.
|
|
57
58
|
* @property {boolean} [multiline] Whether the content can span multiple paragraphs and lines.
|
|
58
59
|
* With `false`, the content is kept in a single paragraph: the Enter key does nothing, and the
|
|
@@ -95,7 +96,7 @@
|
|
|
95
96
|
flex = false,
|
|
96
97
|
dir = undefined,
|
|
97
98
|
modes = ['rich-text', 'plain-text'],
|
|
98
|
-
buttons = [...
|
|
99
|
+
buttons = [...DEFAULT_BUTTON_TYPES],
|
|
99
100
|
components = [],
|
|
100
101
|
multiline = true,
|
|
101
102
|
minimal = false,
|
|
@@ -262,7 +263,9 @@
|
|
|
262
263
|
blockNodeKey: null,
|
|
263
264
|
blockType:
|
|
264
265
|
document.activeElement === textArea
|
|
265
|
-
? getBlockType(getRawTextState(textArea)
|
|
266
|
+
? getBlockType(getRawTextState(textArea), {
|
|
267
|
+
hasTaskList: editorStore.config.enabledButtons.includes('task-list'),
|
|
268
|
+
})
|
|
266
269
|
: 'paragraph',
|
|
267
270
|
inlineTypes: [],
|
|
268
271
|
};
|
|
@@ -39,7 +39,8 @@ declare const TextEditor: import("svelte").Component<{
|
|
|
39
39
|
*/
|
|
40
40
|
modes?: TextEditorMode[] | undefined;
|
|
41
41
|
/**
|
|
42
|
-
* Enabled buttons.
|
|
42
|
+
* Enabled buttons. All the inline and block level
|
|
43
|
+
* buttons by default, except the HTML-only `underline`.
|
|
43
44
|
*/
|
|
44
45
|
buttons?: TextEditorNodeType[] | undefined;
|
|
45
46
|
/**
|
|
@@ -152,7 +153,8 @@ type Props = {
|
|
|
152
153
|
*/
|
|
153
154
|
modes?: TextEditorMode[] | undefined;
|
|
154
155
|
/**
|
|
155
|
-
* Enabled buttons.
|
|
156
|
+
* Enabled buttons. All the inline and block level
|
|
157
|
+
* buttons by default, except the HTML-only `underline`.
|
|
156
158
|
*/
|
|
157
159
|
buttons?: TextEditorNodeType[] | undefined;
|
|
158
160
|
/**
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { getContext } from 'svelte';
|
|
5
5
|
import Button from '../../button/button.svelte';
|
|
6
6
|
import Icon from '../../icon/icon.svelte';
|
|
7
|
-
import { AVAILABLE_BUTTONS } from '../constants.js';
|
|
7
|
+
import { AVAILABLE_BUTTONS, isHtmlOnlyButton } from '../constants.js';
|
|
8
8
|
import { focusEditor } from '../editing/caret.js';
|
|
9
9
|
import {
|
|
10
10
|
editRawText,
|
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
const { editor, textArea, useRichText } = editorStore;
|
|
48
48
|
|
|
49
49
|
if (!useRichText) {
|
|
50
|
+
// The `<textarea>` is only there for Markdown, which hides the HTML-only formats
|
|
51
|
+
/* v8 ignore next 3 */
|
|
52
|
+
if (isHtmlOnlyButton(type)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
50
56
|
// The button is only enabled while the `<textarea>` is there
|
|
51
57
|
editRawText(textArea, (state) => toggleInlineFormat(state, type));
|
|
52
58
|
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
import Icon from '../../icon/icon.svelte';
|
|
10
10
|
import MenuButton from '../../menu/menu-button.svelte';
|
|
11
11
|
import Menu from '../../menu/menu.svelte';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
AVAILABLE_BUTTONS,
|
|
14
|
+
BLOCK_BUTTON_TYPES,
|
|
15
|
+
INLINE_BUTTON_TYPES,
|
|
16
|
+
isHtmlOnlyButton,
|
|
17
|
+
} from '../constants.js';
|
|
13
18
|
import { isInlineComponent } from '../conversion/editor-components.js';
|
|
14
19
|
import CodeLanguageSwitcher from './code-language-switcher.svelte';
|
|
15
20
|
import AlignMenuButton from './align-menu-button.svelte';
|
|
@@ -69,13 +74,16 @@
|
|
|
69
74
|
*/
|
|
70
75
|
const canFormat = $derived(editorStore.useRichText || !isHtml);
|
|
71
76
|
|
|
72
|
-
const hasTable = $derived(editorStore.config.enabledButtons.includes('table'));
|
|
73
77
|
/**
|
|
74
|
-
* Whether the
|
|
75
|
-
* available for HTML, and only in the rich text mode, as
|
|
78
|
+
* Whether the HTML-only buttons, like underline and the alignment menu, are available. Markdown
|
|
79
|
+
* has no syntax for them, so they’re only available for HTML, and only in the rich text mode, as
|
|
80
|
+
* the plain text mode shows the source.
|
|
76
81
|
*/
|
|
82
|
+
const canUseHtmlOnlyButtons = $derived(isHtml && editorStore.useRichText);
|
|
83
|
+
|
|
84
|
+
const hasTable = $derived(editorStore.config.enabledButtons.includes('table'));
|
|
77
85
|
const canAlign = $derived(
|
|
78
|
-
|
|
86
|
+
canUseHtmlOnlyButtons && editorStore.config.enabledButtons.includes('align'),
|
|
79
87
|
);
|
|
80
88
|
const hasHorizontalRule = $derived(editorStore.config.enabledButtons.includes('horizontal-rule'));
|
|
81
89
|
/**
|
|
@@ -116,13 +124,16 @@
|
|
|
116
124
|
const canChangeBlock = $derived(canFormat && !inMarkdownTable);
|
|
117
125
|
|
|
118
126
|
/**
|
|
119
|
-
* Enabled inline level buttons
|
|
127
|
+
* Enabled inline level buttons, leaving out the HTML-only ones, like underline, when they’re not
|
|
128
|
+
* available.
|
|
120
129
|
* @type {TextEditorInlineType[]}
|
|
121
130
|
*/
|
|
122
131
|
const inlineLevelButtons = $derived(
|
|
123
132
|
unique(
|
|
124
|
-
editorStore.config.enabledButtons.filter(
|
|
125
|
-
|
|
133
|
+
editorStore.config.enabledButtons.filter(
|
|
134
|
+
(type) =>
|
|
135
|
+
INLINE_BUTTON_TYPES.includes(/** @type {any} */ (type)) &&
|
|
136
|
+
(canUseHtmlOnlyButtons || !isHtmlOnlyButton(type)),
|
|
126
137
|
),
|
|
127
138
|
),
|
|
128
139
|
);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { $createCodeNode as createCodeNode } from '@lexical/code-core';
|
|
3
|
-
import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
|
|
4
3
|
import {
|
|
5
4
|
$createHeadingNode as createHeadingNode,
|
|
6
5
|
$createQuoteNode as createQuoteNode,
|
|
@@ -14,14 +13,14 @@
|
|
|
14
13
|
import { getContext } from 'svelte';
|
|
15
14
|
import Icon from '../../icon/icon.svelte';
|
|
16
15
|
import MenuItemCheckbox from '../../menu/menu-item-checkbox.svelte';
|
|
17
|
-
import { AVAILABLE_BUTTONS } from '../constants.js';
|
|
16
|
+
import { AVAILABLE_BUTTONS, LIST_TYPES } from '../constants.js';
|
|
18
17
|
import { focusEditor } from '../editing/caret.js';
|
|
19
18
|
import { editRawText, setBlockType } from '../editing/raw-markdown.js';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @import { TextEditorBlockType, TextEditorStore } from '../../../typedefs.js';
|
|
23
22
|
* @import { HeadingTagType } from '@lexical/rich-text';
|
|
24
|
-
* @import { ElementNode
|
|
23
|
+
* @import { ElementNode } from 'lexical';
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
26
|
/**
|
|
@@ -35,15 +34,6 @@
|
|
|
35
34
|
'code-block': createCodeNode,
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
/**
|
|
39
|
-
* Commands for the list block types, which are toggled by the list plugin instead.
|
|
40
|
-
* @type {Record<string, LexicalCommand<void>>}
|
|
41
|
-
*/
|
|
42
|
-
const LIST_COMMANDS = {
|
|
43
|
-
'bulleted-list': INSERT_UNORDERED_LIST_COMMAND,
|
|
44
|
-
'numbered-list': INSERT_ORDERED_LIST_COMMAND,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
37
|
/**
|
|
48
38
|
* @typedef {object} Props
|
|
49
39
|
* @property {TextEditorBlockType} type Button type.
|
|
@@ -93,8 +83,11 @@
|
|
|
93
83
|
});
|
|
94
84
|
}
|
|
95
85
|
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
// A list is toggled by its command instead
|
|
87
|
+
const list = LIST_TYPES.find((item) => item.type === type);
|
|
88
|
+
|
|
89
|
+
if (list) {
|
|
90
|
+
editorStore.editor.dispatchCommand(list.command, undefined);
|
|
98
91
|
}
|
|
99
92
|
};
|
|
100
93
|
</script>
|
package/dist/locales/ar.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: عنوان 6
|
|
119
119
|
bulleted_list: قائمة نقطية
|
|
120
120
|
numbered_list: قائمة مرقمة
|
|
121
|
+
task_list: قائمة مهام
|
|
121
122
|
blockquote: اقتباس
|
|
122
123
|
code_block: كتلة برمجية
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: عريض
|
|
125
126
|
italic: مائل
|
|
127
|
+
underline: تسطير
|
|
126
128
|
strikethrough: يتوسطه خط
|
|
127
129
|
code: كود
|
|
128
130
|
link: رابط
|
package/dist/locales/bg.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Заглавие 6
|
|
119
119
|
bulleted_list: Неномериран списък
|
|
120
120
|
numbered_list: Номериран списък
|
|
121
|
+
task_list: Списък със задачи
|
|
121
122
|
blockquote: Цитат
|
|
122
123
|
code_block: Блок с код
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Получер
|
|
125
126
|
italic: Курсив
|
|
127
|
+
underline: Подчертан
|
|
126
128
|
strikethrough: Зачертан
|
|
127
129
|
code: Код
|
|
128
130
|
link: Връзка
|
package/dist/locales/ca.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Encapçalament 6
|
|
119
119
|
bulleted_list: Llista amb pics
|
|
120
120
|
numbered_list: Llista numerada
|
|
121
|
+
task_list: Llista de tasques
|
|
121
122
|
blockquote: Bloc de cita
|
|
122
123
|
code_block: Bloc de codi
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Negreta
|
|
125
126
|
italic: Cursiva
|
|
127
|
+
underline: Subratllat
|
|
126
128
|
strikethrough: Barrat
|
|
127
129
|
code: Codi
|
|
128
130
|
link: Enllaç
|
package/dist/locales/cs.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Nadpis 6
|
|
119
119
|
bulleted_list: Seznam s odrážkami
|
|
120
120
|
numbered_list: Číslovaný seznam
|
|
121
|
+
task_list: Seznam úkolů
|
|
121
122
|
blockquote: Citace
|
|
122
123
|
code_block: Blok kódu
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Tučné
|
|
125
126
|
italic: Kurzíva
|
|
127
|
+
underline: Podtržené
|
|
126
128
|
strikethrough: Přeškrtnuté
|
|
127
129
|
code: Kód
|
|
128
130
|
link: Odkaz
|
package/dist/locales/da.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Overskrift 6
|
|
119
119
|
bulleted_list: Punktopstilling
|
|
120
120
|
numbered_list: Nummereret liste
|
|
121
|
+
task_list: Opgaveliste
|
|
121
122
|
blockquote: Citat
|
|
122
123
|
code_block: Kodeblok
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Fed
|
|
125
126
|
italic: Kursiv
|
|
127
|
+
underline: Understreget
|
|
126
128
|
strikethrough: Gennemstreget
|
|
127
129
|
code: Kode
|
|
128
130
|
link: Link
|
package/dist/locales/de.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Überschrift 6
|
|
119
119
|
bulleted_list: Aufzählungsliste
|
|
120
120
|
numbered_list: Nummerierte Liste
|
|
121
|
+
task_list: Aufgabenliste
|
|
121
122
|
blockquote: Zitat
|
|
122
123
|
code_block: Code-Block
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Fett
|
|
125
126
|
italic: Kursiv
|
|
127
|
+
underline: Unterstrichen
|
|
126
128
|
strikethrough: Durchgestrichen
|
|
127
129
|
code: Code
|
|
128
130
|
link: Link
|
package/dist/locales/el.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Επικεφαλίδα 6
|
|
119
119
|
bulleted_list: Λίστα με κουκίδες
|
|
120
120
|
numbered_list: Αριθμημένη λίστα
|
|
121
|
+
task_list: Λίστα εργασιών
|
|
121
122
|
blockquote: Παράθεση
|
|
122
123
|
code_block: Μπλόκ κώδικα
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Έντονα
|
|
125
126
|
italic: Πλάγια
|
|
127
|
+
underline: Υπογράμμιση
|
|
126
128
|
strikethrough: Διακριτή διαγραφή
|
|
127
129
|
code: Κώδικας
|
|
128
130
|
link: Σύνδεσμος
|
package/dist/locales/en-CA.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Heading 6
|
|
119
119
|
bulleted_list: Bulleted List
|
|
120
120
|
numbered_list: Numbered List
|
|
121
|
+
task_list: Task List
|
|
121
122
|
blockquote: Block Quote
|
|
122
123
|
code_block: Code Block
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Bold
|
|
125
126
|
italic: Italic
|
|
127
|
+
underline: Underline
|
|
126
128
|
strikethrough: Strikethrough
|
|
127
129
|
code: Code
|
|
128
130
|
link: Link
|
package/dist/locales/en-GB.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Heading 6
|
|
119
119
|
bulleted_list: Bulleted List
|
|
120
120
|
numbered_list: Numbered List
|
|
121
|
+
task_list: Task List
|
|
121
122
|
blockquote: Block Quote
|
|
122
123
|
code_block: Code Block
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Bold
|
|
125
126
|
italic: Italic
|
|
127
|
+
underline: Underline
|
|
126
128
|
strikethrough: Strikethrough
|
|
127
129
|
code: Code
|
|
128
130
|
link: Link
|
package/dist/locales/en-US.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Heading 6
|
|
119
119
|
bulleted_list: Bulleted List
|
|
120
120
|
numbered_list: Numbered List
|
|
121
|
+
task_list: Task List
|
|
121
122
|
blockquote: Block Quote
|
|
122
123
|
code_block: Code Block
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Bold
|
|
125
126
|
italic: Italic
|
|
127
|
+
underline: Underline
|
|
126
128
|
strikethrough: Strikethrough
|
|
127
129
|
code: Code
|
|
128
130
|
link: Link
|
package/dist/locales/en-ZA.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Heading 6
|
|
119
119
|
bulleted_list: Bulleted List
|
|
120
120
|
numbered_list: Numbered List
|
|
121
|
+
task_list: Task List
|
|
121
122
|
blockquote: Block Quote
|
|
122
123
|
code_block: Code Block
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Bold
|
|
125
126
|
italic: Italic
|
|
127
|
+
underline: Underline
|
|
126
128
|
strikethrough: Strikethrough
|
|
127
129
|
code: Code
|
|
128
130
|
link: Link
|
package/dist/locales/es-CO.yaml
CHANGED
|
@@ -118,11 +118,13 @@ text_editor:
|
|
|
118
118
|
heading_6: Encabezado 6
|
|
119
119
|
bulleted_list: Lista con viñetas
|
|
120
120
|
numbered_list: Lista numerada
|
|
121
|
+
task_list: Lista de tareas
|
|
121
122
|
blockquote: Cita
|
|
122
123
|
code_block: Bloque de código
|
|
123
124
|
# Inline style button aria-labels
|
|
124
125
|
bold: Negrita
|
|
125
126
|
italic: Cursiva
|
|
127
|
+
underline: Subrayado
|
|
126
128
|
strikethrough: Tachado
|
|
127
129
|
code: Código
|
|
128
130
|
link: Enlace
|