@sveltia/ui 0.32.0 → 0.32.2
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/core.js +41 -53
- package/dist/components/text-editor/markdown.d.ts +0 -1
- package/dist/components/text-editor/markdown.js +0 -14
- package/dist/components/text-editor/markdown.test.js +1 -95
- package/dist/components/text-editor/transformers/table.js +24 -24
- package/package.json +22 -22
|
@@ -1,64 +1,55 @@
|
|
|
1
1
|
import {
|
|
2
|
+
$createCodeNode,
|
|
3
|
+
$isCodeHighlightNode,
|
|
4
|
+
$isCodeNode,
|
|
2
5
|
CodeHighlightNode,
|
|
3
6
|
CodeNode,
|
|
4
7
|
PrismTokenizer,
|
|
5
|
-
$createCodeNode as createCodeNode,
|
|
6
|
-
$isCodeHighlightNode as isCodeHighlightNode,
|
|
7
|
-
$isCodeNode as isCodeNode,
|
|
8
8
|
registerCodeHighlighting,
|
|
9
9
|
} from '@lexical/code';
|
|
10
10
|
import { registerDragonSupport } from '@lexical/dragon';
|
|
11
11
|
import { HorizontalRuleNode } from '@lexical/extension';
|
|
12
12
|
import { createEmptyHistoryState, registerHistory } from '@lexical/history';
|
|
13
|
+
import { $isLinkNode, $toggleLink, LinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
|
|
13
14
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
$
|
|
17
|
-
$
|
|
18
|
-
} from '@lexical/link';
|
|
19
|
-
import {
|
|
15
|
+
$handleListInsertParagraph,
|
|
16
|
+
$insertList,
|
|
17
|
+
$isListItemNode,
|
|
18
|
+
$isListNode,
|
|
20
19
|
INSERT_ORDERED_LIST_COMMAND,
|
|
21
20
|
INSERT_UNORDERED_LIST_COMMAND,
|
|
22
21
|
ListItemNode,
|
|
23
22
|
ListNode,
|
|
24
|
-
$handleListInsertParagraph as handleListInsertParagraph,
|
|
25
|
-
$insertList as insertList,
|
|
26
|
-
$isListItemNode as isListItemNode,
|
|
27
|
-
$isListNode as isListNode,
|
|
28
23
|
} from '@lexical/list';
|
|
29
24
|
import {
|
|
25
|
+
$convertFromMarkdownString,
|
|
26
|
+
$convertToMarkdownString,
|
|
30
27
|
TRANSFORMERS,
|
|
31
|
-
$convertFromMarkdownString as convertFromMarkdownString,
|
|
32
|
-
$convertToMarkdownString as convertToMarkdownString,
|
|
33
28
|
} from '@lexical/markdown';
|
|
34
29
|
import {
|
|
30
|
+
$isHeadingNode,
|
|
31
|
+
$isQuoteNode,
|
|
35
32
|
HeadingNode,
|
|
36
33
|
QuoteNode,
|
|
37
|
-
$isHeadingNode as isHeadingNode,
|
|
38
|
-
$isQuoteNode as isQuoteNode,
|
|
39
34
|
registerRichText,
|
|
40
35
|
} from '@lexical/rich-text';
|
|
41
36
|
import { TableCellNode, TableNode, TableRowNode } from '@lexical/table';
|
|
42
|
-
import { $getNearestNodeOfType
|
|
37
|
+
import { $getNearestNodeOfType } from '@lexical/utils';
|
|
43
38
|
import { sleep } from '@sveltia/utils/misc';
|
|
44
39
|
import {
|
|
40
|
+
$getRoot,
|
|
41
|
+
$getSelection,
|
|
42
|
+
$isRangeSelection,
|
|
45
43
|
COMMAND_PRIORITY_NORMAL,
|
|
46
44
|
ElementNode,
|
|
47
45
|
INDENT_CONTENT_COMMAND,
|
|
48
46
|
INSERT_PARAGRAPH_COMMAND,
|
|
49
47
|
OUTDENT_CONTENT_COMMAND,
|
|
50
48
|
createEditor,
|
|
51
|
-
$getRoot as getRoot,
|
|
52
|
-
$getSelection as getSelection,
|
|
53
|
-
$isRangeSelection as isRangeSelection,
|
|
54
49
|
} from 'lexical';
|
|
55
50
|
import prismComponents from 'prismjs/components';
|
|
56
51
|
import { BLOCK_BUTTON_TYPES, TEXT_FORMAT_BUTTON_TYPES } from './constants.js';
|
|
57
|
-
import {
|
|
58
|
-
fixMarkdownFormatting,
|
|
59
|
-
increaseListIndentation,
|
|
60
|
-
splitMultilineFormatting,
|
|
61
|
-
} from './markdown.js';
|
|
52
|
+
import { increaseListIndentation, splitMultilineFormatting } from './markdown.js';
|
|
62
53
|
import { HR } from './transformers/hr.js';
|
|
63
54
|
import { TABLE } from './transformers/table.js';
|
|
64
55
|
|
|
@@ -150,9 +141,9 @@ const editorConfig = {
|
|
|
150
141
|
* @returns {TextEditorSelectionState} Current selection state.
|
|
151
142
|
*/
|
|
152
143
|
const getSelectionTypes = () => {
|
|
153
|
-
const selection = getSelection();
|
|
144
|
+
const selection = $getSelection();
|
|
154
145
|
|
|
155
|
-
if (
|
|
146
|
+
if (!$isRangeSelection(selection)) {
|
|
156
147
|
return {
|
|
157
148
|
blockNodeKey: null,
|
|
158
149
|
blockType: 'paragraph',
|
|
@@ -167,15 +158,15 @@ const getSelectionTypes = () => {
|
|
|
167
158
|
const inlineTypes = TEXT_FORMAT_BUTTON_TYPES.filter((type) => selection.hasFormat(type));
|
|
168
159
|
|
|
169
160
|
if (anchor.getType() !== 'root') {
|
|
170
|
-
parent = anchor instanceof ElementNode ? anchor : getNearestNodeOfType(anchor, ElementNode);
|
|
161
|
+
parent = anchor instanceof ElementNode ? anchor : $getNearestNodeOfType(anchor, ElementNode);
|
|
171
162
|
|
|
172
|
-
if (isLinkNode(parent)) {
|
|
163
|
+
if ($isLinkNode(parent)) {
|
|
173
164
|
inlineTypes.push('link');
|
|
174
|
-
parent = getNearestNodeOfType(parent, ElementNode);
|
|
165
|
+
parent = $getNearestNodeOfType(parent, ElementNode);
|
|
175
166
|
}
|
|
176
167
|
|
|
177
|
-
if (isListItemNode(parent)) {
|
|
178
|
-
parent = getNearestNodeOfType(parent, ListNode);
|
|
168
|
+
if ($isListItemNode(parent)) {
|
|
169
|
+
parent = $getNearestNodeOfType(parent, ListNode);
|
|
179
170
|
}
|
|
180
171
|
}
|
|
181
172
|
|
|
@@ -185,19 +176,19 @@ const getSelectionTypes = () => {
|
|
|
185
176
|
return 'paragraph';
|
|
186
177
|
}
|
|
187
178
|
|
|
188
|
-
if (isHeadingNode(parent)) {
|
|
179
|
+
if ($isHeadingNode(parent)) {
|
|
189
180
|
return `heading-${parent.getTag().match(/\d/)?.[0]}`;
|
|
190
181
|
}
|
|
191
182
|
|
|
192
|
-
if (isListNode(parent)) {
|
|
183
|
+
if ($isListNode(parent)) {
|
|
193
184
|
return parent.getListType() === 'bullet' ? 'bulleted-list' : 'numbered-list';
|
|
194
185
|
}
|
|
195
186
|
|
|
196
|
-
if (isQuoteNode(parent)) {
|
|
187
|
+
if ($isQuoteNode(parent)) {
|
|
197
188
|
return 'blockquote';
|
|
198
189
|
}
|
|
199
190
|
|
|
200
|
-
if (isCodeNode(parent) || isCodeHighlightNode(parent)) {
|
|
191
|
+
if ($isCodeNode(parent) || $isCodeHighlightNode(parent)) {
|
|
201
192
|
return 'code-block';
|
|
202
193
|
}
|
|
203
194
|
|
|
@@ -226,7 +217,7 @@ const onEditorUpdate = (editor) => {
|
|
|
226
217
|
editor.getRootElement()?.dispatchEvent(
|
|
227
218
|
new CustomEvent('Update', {
|
|
228
219
|
detail: {
|
|
229
|
-
value: convertToMarkdownString(
|
|
220
|
+
value: $convertToMarkdownString(
|
|
230
221
|
// Use underscores for italic text in Markdown instead of asterisks
|
|
231
222
|
allTransformers.filter((/** @type {any} */ { tag }) => tag !== '*'),
|
|
232
223
|
) // Remove unnecessary backslash for underscore and backslash characters
|
|
@@ -276,7 +267,7 @@ export const initEditor = ({
|
|
|
276
267
|
editor.registerCommand(
|
|
277
268
|
TOGGLE_LINK_COMMAND,
|
|
278
269
|
(payload) => {
|
|
279
|
-
toggleLink(typeof payload === 'string' ? payload : null);
|
|
270
|
+
$toggleLink(typeof payload === 'string' ? payload : null);
|
|
280
271
|
|
|
281
272
|
return true;
|
|
282
273
|
},
|
|
@@ -286,7 +277,7 @@ export const initEditor = ({
|
|
|
286
277
|
editor.registerCommand(
|
|
287
278
|
INSERT_UNORDERED_LIST_COMMAND,
|
|
288
279
|
() => {
|
|
289
|
-
insertList('bullet');
|
|
280
|
+
$insertList('bullet');
|
|
290
281
|
|
|
291
282
|
return true;
|
|
292
283
|
},
|
|
@@ -296,7 +287,7 @@ export const initEditor = ({
|
|
|
296
287
|
editor.registerCommand(
|
|
297
288
|
INSERT_ORDERED_LIST_COMMAND,
|
|
298
289
|
() => {
|
|
299
|
-
insertList('number');
|
|
290
|
+
$insertList('number');
|
|
300
291
|
|
|
301
292
|
return true;
|
|
302
293
|
},
|
|
@@ -306,7 +297,7 @@ export const initEditor = ({
|
|
|
306
297
|
// https://github.com/facebook/lexical/blob/main/packages/lexical-react/src/shared/useList.ts
|
|
307
298
|
editor.registerCommand(
|
|
308
299
|
INSERT_PARAGRAPH_COMMAND,
|
|
309
|
-
() => handleListInsertParagraph(),
|
|
300
|
+
() => $handleListInsertParagraph(),
|
|
310
301
|
COMMAND_PRIORITY_NORMAL,
|
|
311
302
|
);
|
|
312
303
|
|
|
@@ -320,15 +311,15 @@ export const initEditor = ({
|
|
|
320
311
|
editor.update(() => {
|
|
321
312
|
// Prevent CodeNode from being removed
|
|
322
313
|
if (isCodeEditor) {
|
|
323
|
-
const root = getRoot();
|
|
314
|
+
const root = $getRoot();
|
|
324
315
|
const children = root.getChildren();
|
|
325
316
|
|
|
326
|
-
if (children.length === 1 &&
|
|
317
|
+
if (children.length === 1 && !$isCodeNode(children[0])) {
|
|
327
318
|
children[0].remove();
|
|
328
319
|
}
|
|
329
320
|
|
|
330
321
|
if (children.length === 0) {
|
|
331
|
-
const node = createCodeNode();
|
|
322
|
+
const node = $createCodeNode();
|
|
332
323
|
|
|
333
324
|
node.setLanguage(defaultLanguage);
|
|
334
325
|
root.append(node);
|
|
@@ -346,18 +337,18 @@ export const initEditor = ({
|
|
|
346
337
|
root.addEventListener('keydown', (event) => {
|
|
347
338
|
editor.update(() => {
|
|
348
339
|
if (event.key === 'Tab') {
|
|
349
|
-
const selection = getSelection();
|
|
340
|
+
const selection = $getSelection();
|
|
350
341
|
|
|
351
|
-
if (
|
|
342
|
+
if (!$isRangeSelection(selection)) {
|
|
352
343
|
return;
|
|
353
344
|
}
|
|
354
345
|
|
|
355
346
|
const anchor = selection.anchor.getNode();
|
|
356
347
|
|
|
357
348
|
const parent =
|
|
358
|
-
anchor instanceof ElementNode ? anchor : getNearestNodeOfType(anchor, ElementNode);
|
|
349
|
+
anchor instanceof ElementNode ? anchor : $getNearestNodeOfType(anchor, ElementNode);
|
|
359
350
|
|
|
360
|
-
if (isListItemNode(parent) && parent.canIndent()) {
|
|
351
|
+
if ($isListItemNode(parent) && parent.canIndent()) {
|
|
361
352
|
if (!event.shiftKey) {
|
|
362
353
|
event.preventDefault();
|
|
363
354
|
editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
|
|
@@ -420,16 +411,13 @@ export const convertMarkdownToLexical = async (editor, value) => {
|
|
|
420
411
|
// Split multiline formatting into separate lines to prevent Markdown parsing issues
|
|
421
412
|
value = splitMultilineFormatting(value);
|
|
422
413
|
|
|
423
|
-
// Fix unclosed formatting markers (work around Lexical bug)
|
|
424
|
-
value = fixMarkdownFormatting(value);
|
|
425
|
-
|
|
426
414
|
// Increase list indentation levels to prevent Markdown parsing issues
|
|
427
415
|
value = increaseListIndentation(value);
|
|
428
416
|
|
|
429
417
|
return new Promise((resolve, reject) => {
|
|
430
418
|
editor.update(() => {
|
|
431
419
|
try {
|
|
432
|
-
convertFromMarkdownString(value, allTransformers);
|
|
420
|
+
$convertFromMarkdownString(value, allTransformers);
|
|
433
421
|
resolve(undefined);
|
|
434
422
|
} catch (ex) {
|
|
435
423
|
reject(new Error('Failed to convert Markdown', { cause: ex }));
|
|
@@ -11,20 +11,6 @@ export const splitMultilineFormatting = (value) =>
|
|
|
11
11
|
.replace(/(\s+)~~([^~\n]+?)\n([^~\n]+?)~~(\s+)/gm, '$1~~$2~~\n~~$3~~$4')
|
|
12
12
|
.replace(/(\s+)`([^`\n]+?)\n([^`\n]+?)`(\s+)/gm, '$1`$2`\n`$3`$4');
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Fix malformed Markdown formatting markers.
|
|
16
|
-
* Converts unclosed formatting markers like `**foo **bar` to `**foo** bar`.
|
|
17
|
-
* This works around a Lexical bug with certain formatting patterns.
|
|
18
|
-
* @param {string} value Markdown string to fix.
|
|
19
|
-
* @returns {string} Fixed Markdown string.
|
|
20
|
-
* @see https://github.com/sveltia/sveltia-cms/issues/599
|
|
21
|
-
*/
|
|
22
|
-
export const fixMarkdownFormatting = (value) =>
|
|
23
|
-
value
|
|
24
|
-
.replace(/\*\*(\S+?) \*\*/gm, '**$1** ')
|
|
25
|
-
.replace(/_(\S+?) _/gm, '_$1_ ')
|
|
26
|
-
.replace(/~~(\S+?) ~~/gm, '~~$1~~ ');
|
|
27
|
-
|
|
28
14
|
/**
|
|
29
15
|
* Increase list indentation levels to prevent Markdown parsing issues.
|
|
30
16
|
* Slate uses 2 spaces per indentation level, whereas Lexical uses 4 spaces.
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
fixMarkdownFormatting,
|
|
4
|
-
increaseListIndentation,
|
|
5
|
-
splitMultilineFormatting,
|
|
6
|
-
} from './markdown.js';
|
|
2
|
+
import { increaseListIndentation, splitMultilineFormatting } from './markdown.js';
|
|
7
3
|
|
|
8
4
|
describe('splitMultilineFormatting', () => {
|
|
9
5
|
it('should split italic formatting across lines', () => {
|
|
@@ -43,96 +39,6 @@ describe('splitMultilineFormatting', () => {
|
|
|
43
39
|
});
|
|
44
40
|
});
|
|
45
41
|
|
|
46
|
-
describe('fixMarkdownFormatting', () => {
|
|
47
|
-
it('should fix unclosed bold markers with space in between', () => {
|
|
48
|
-
expect(fixMarkdownFormatting('**foo **bar')).toBe('**foo** bar');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should fix unclosed italic markers with space in between', () => {
|
|
52
|
-
expect(fixMarkdownFormatting('_foo _bar')).toBe('_foo_ bar');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should fix multiple bold markers', () => {
|
|
56
|
-
expect(fixMarkdownFormatting('**foo **bar **baz **qux')).toBe('**foo** bar **baz** qux');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should fix multiple italic markers', () => {
|
|
60
|
-
expect(fixMarkdownFormatting('_foo _bar _baz _qux')).toBe('_foo_ bar _baz_ qux');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should fix mixed bold and italic markers', () => {
|
|
64
|
-
expect(fixMarkdownFormatting('**foo **bar _baz _qux')).toBe('**foo** bar _baz_ qux');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should not affect properly closed bold markers', () => {
|
|
68
|
-
expect(fixMarkdownFormatting('**foo** bar')).toBe('**foo** bar');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should not affect properly closed italic markers', () => {
|
|
72
|
-
expect(fixMarkdownFormatting('_foo_ bar')).toBe('_foo_ bar');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should preserve other formatting', () => {
|
|
76
|
-
expect(fixMarkdownFormatting('~~strikethrough~~ **bold** _italic_')).toBe(
|
|
77
|
-
'~~strikethrough~~ **bold** _italic_',
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should handle bold and italic in combination', () => {
|
|
82
|
-
expect(fixMarkdownFormatting('**foo **bar _baz _qux **test **end')).toBe(
|
|
83
|
-
'**foo** bar _baz_ qux **test** end',
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should handle markers at the start of a line', () => {
|
|
88
|
-
expect(fixMarkdownFormatting('**foo **bar\n_baz _qux')).toBe('**foo** bar\n_baz_ qux');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should handle markers at the end of a line', () => {
|
|
92
|
-
expect(fixMarkdownFormatting('line 1 **foo **bar\nline 2 _baz _qux')).toBe(
|
|
93
|
-
'line 1 **foo** bar\nline 2 _baz_ qux',
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should work with global flag for multiple occurrences', () => {
|
|
98
|
-
expect(fixMarkdownFormatting('**a **b **c **d _e _f')).toBe('**a** b **c** d _e_ f');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should not break when markers are not present', () => {
|
|
102
|
-
expect(fixMarkdownFormatting('regular text without formatting')).toBe(
|
|
103
|
-
'regular text without formatting',
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should handle edge case with only formatting markers', () => {
|
|
108
|
-
expect(fixMarkdownFormatting('**foo **')).toBe('**foo** ');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should handle underscores in words (not formatting)', () => {
|
|
112
|
-
expect(fixMarkdownFormatting('snake_case_variable **foo **bar')).toBe(
|
|
113
|
-
'snake_case_variable **foo** bar',
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should fix unclosed strikethrough markers with space in between', () => {
|
|
118
|
-
expect(fixMarkdownFormatting('~~foo ~~bar')).toBe('~~foo~~ bar');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should fix multiple strikethrough markers', () => {
|
|
122
|
-
expect(fixMarkdownFormatting('~~foo ~~bar ~~baz ~~qux')).toBe('~~foo~~ bar ~~baz~~ qux');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should fix mixed formatting with strikethrough', () => {
|
|
126
|
-
expect(fixMarkdownFormatting('**bold **text _italic _text ~~strike ~~text')).toBe(
|
|
127
|
-
'**bold** text _italic_ text ~~strike~~ text',
|
|
128
|
-
);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should not affect properly closed strikethrough markers', () => {
|
|
132
|
-
expect(fixMarkdownFormatting('~~foo~~ bar')).toBe('~~foo~~ bar');
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
42
|
describe('increaseListIndentation', () => {
|
|
137
43
|
it('should double indentation for bullet lists', () => {
|
|
138
44
|
expect(increaseListIndentation(' - item')).toBe(' - item');
|
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
/* eslint-disable jsdoc/require-param-description */
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
$convertFromMarkdownString,
|
|
9
|
+
$convertToMarkdownString,
|
|
8
10
|
TRANSFORMERS,
|
|
9
|
-
$convertFromMarkdownString as convertFromMarkdownString,
|
|
10
|
-
$convertToMarkdownString as convertToMarkdownString,
|
|
11
11
|
} from '@lexical/markdown';
|
|
12
12
|
import {
|
|
13
|
+
$createTableCellNode,
|
|
14
|
+
$createTableNode,
|
|
15
|
+
$createTableRowNode,
|
|
16
|
+
$isTableCellNode,
|
|
17
|
+
$isTableNode,
|
|
18
|
+
$isTableRowNode,
|
|
13
19
|
TableCellHeaderStates,
|
|
14
20
|
TableCellNode,
|
|
15
21
|
TableNode,
|
|
16
22
|
TableRowNode,
|
|
17
|
-
$createTableCellNode as createTableCellNode,
|
|
18
|
-
$createTableNode as createTableNode,
|
|
19
|
-
$createTableRowNode as createTableRowNode,
|
|
20
|
-
$isTableCellNode as isTableCellNode,
|
|
21
|
-
$isTableNode as isTableNode,
|
|
22
|
-
$isTableRowNode as isTableRowNode,
|
|
23
23
|
} from '@lexical/table';
|
|
24
|
-
import { $isParagraphNode
|
|
24
|
+
import { $isParagraphNode, $isTextNode } from 'lexical';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @import { ElementTransformer } from '@lexical/markdown';
|
|
@@ -38,7 +38,7 @@ const TABLE_ROW_DIVIDER_REG_EXP = /^(\| ?:?-*:? ?)+\|\s?$/;
|
|
|
38
38
|
function getTableColumnsSize(table) {
|
|
39
39
|
const row = table.getFirstChild();
|
|
40
40
|
|
|
41
|
-
return isTableRowNode(row) ? row.getChildrenSize() : 0;
|
|
41
|
+
return $isTableRowNode(row) ? row.getChildrenSize() : 0;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -49,9 +49,9 @@ function getTableColumnsSize(table) {
|
|
|
49
49
|
const createTableCell = (textContent) => {
|
|
50
50
|
textContent = textContent.replace(/\\n/g, '\n');
|
|
51
51
|
|
|
52
|
-
const cell = createTableCellNode(TableCellHeaderStates.NO_STATUS);
|
|
52
|
+
const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
|
|
53
53
|
|
|
54
|
-
convertFromMarkdownString(textContent, TRANSFORMERS, cell);
|
|
54
|
+
$convertFromMarkdownString(textContent, TRANSFORMERS, cell);
|
|
55
55
|
|
|
56
56
|
return cell;
|
|
57
57
|
};
|
|
@@ -77,7 +77,7 @@ const mapToTableCells = (textContent) => {
|
|
|
77
77
|
export const TABLE = {
|
|
78
78
|
dependencies: [TableNode, TableRowNode, TableCellNode],
|
|
79
79
|
export: (node) => {
|
|
80
|
-
if (
|
|
80
|
+
if (!$isTableNode(node)) {
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -88,7 +88,7 @@ export const TABLE = {
|
|
|
88
88
|
/** @type {string[]} */
|
|
89
89
|
const rowOutput = [];
|
|
90
90
|
|
|
91
|
-
if (
|
|
91
|
+
if (!$isTableRowNode(row)) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -96,8 +96,8 @@ export const TABLE = {
|
|
|
96
96
|
|
|
97
97
|
row.getChildren().forEach((cell) => {
|
|
98
98
|
// It’s TableCellNode so it’s just to make flow happy
|
|
99
|
-
if (isTableCellNode(cell)) {
|
|
100
|
-
rowOutput.push(convertToMarkdownString(TRANSFORMERS, cell).replace(/\n/g, '\\n').trim());
|
|
99
|
+
if ($isTableCellNode(cell)) {
|
|
100
|
+
rowOutput.push($convertToMarkdownString(TRANSFORMERS, cell).replace(/\n/g, '\\n').trim());
|
|
101
101
|
|
|
102
102
|
if (cell.__headerState === TableCellHeaderStates.ROW) {
|
|
103
103
|
isHeaderRow = true;
|
|
@@ -120,20 +120,20 @@ export const TABLE = {
|
|
|
120
120
|
if (TABLE_ROW_DIVIDER_REG_EXP.test(textContent)) {
|
|
121
121
|
const table = parentNode.getPreviousSibling();
|
|
122
122
|
|
|
123
|
-
if (!table ||
|
|
123
|
+
if (!table || !$isTableNode(table)) {
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
const rows = table.getChildren();
|
|
128
128
|
const lastRow = rows[rows.length - 1];
|
|
129
129
|
|
|
130
|
-
if (!lastRow ||
|
|
130
|
+
if (!lastRow || !$isTableRowNode(lastRow)) {
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// Add header state to row cells
|
|
135
135
|
lastRow.getChildren().forEach((cell) => {
|
|
136
|
-
if (
|
|
136
|
+
if (!$isTableCellNode(cell)) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -157,7 +157,7 @@ export const TABLE = {
|
|
|
157
157
|
let maxCells = matchCells.length;
|
|
158
158
|
|
|
159
159
|
while (sibling) {
|
|
160
|
-
if (
|
|
160
|
+
if (!$isParagraphNode(sibling)) {
|
|
161
161
|
break;
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -167,7 +167,7 @@ export const TABLE = {
|
|
|
167
167
|
|
|
168
168
|
const firstChild = sibling.getFirstChild();
|
|
169
169
|
|
|
170
|
-
if (
|
|
170
|
+
if (!$isTextNode(firstChild)) {
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -186,10 +186,10 @@ export const TABLE = {
|
|
|
186
186
|
sibling = previousSibling;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
const table = createTableNode();
|
|
189
|
+
const table = $createTableNode();
|
|
190
190
|
|
|
191
191
|
rows.forEach((cells) => {
|
|
192
|
-
const tableRow = createTableRowNode();
|
|
192
|
+
const tableRow = $createTableRowNode();
|
|
193
193
|
|
|
194
194
|
table.append(tableRow);
|
|
195
195
|
|
|
@@ -200,7 +200,7 @@ export const TABLE = {
|
|
|
200
200
|
|
|
201
201
|
const previousSibling = parentNode.getPreviousSibling();
|
|
202
202
|
|
|
203
|
-
if (isTableNode(previousSibling) && getTableColumnsSize(previousSibling) === maxCells) {
|
|
203
|
+
if ($isTableNode(previousSibling) && getTableColumnsSize(previousSibling) === maxCells) {
|
|
204
204
|
previousSibling.append(...table.getChildren());
|
|
205
205
|
parentNode.remove();
|
|
206
206
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
"url": "github:sveltia/sveltia-ui"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@lexical/code": "^0.
|
|
12
|
-
"@lexical/dragon": "^0.
|
|
13
|
-
"@lexical/extension": "^0.
|
|
14
|
-
"@lexical/history": "^0.
|
|
15
|
-
"@lexical/link": "^0.
|
|
16
|
-
"@lexical/list": "^0.
|
|
17
|
-
"@lexical/markdown": "^0.
|
|
18
|
-
"@lexical/rich-text": "^0.
|
|
19
|
-
"@lexical/selection": "^0.
|
|
20
|
-
"@lexical/table": "^0.
|
|
21
|
-
"@lexical/utils": "^0.
|
|
11
|
+
"@lexical/code": "^0.41.0",
|
|
12
|
+
"@lexical/dragon": "^0.41.0",
|
|
13
|
+
"@lexical/extension": "^0.41.0",
|
|
14
|
+
"@lexical/history": "^0.41.0",
|
|
15
|
+
"@lexical/link": "^0.41.0",
|
|
16
|
+
"@lexical/list": "^0.41.0",
|
|
17
|
+
"@lexical/markdown": "^0.41.0",
|
|
18
|
+
"@lexical/rich-text": "^0.41.0",
|
|
19
|
+
"@lexical/selection": "^0.41.0",
|
|
20
|
+
"@lexical/table": "^0.41.0",
|
|
21
|
+
"@lexical/utils": "^0.41.0",
|
|
22
22
|
"@sveltia/utils": "^0.8.6",
|
|
23
|
-
"lexical": "^0.
|
|
23
|
+
"lexical": "^0.41.0",
|
|
24
24
|
"prismjs": "^1.30.0",
|
|
25
25
|
"svelte-i18n": "^4.0.1"
|
|
26
26
|
},
|
|
@@ -28,29 +28,29 @@
|
|
|
28
28
|
"svelte": "^5.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@sveltejs/adapter-auto": "^7.0.
|
|
32
|
-
"@sveltejs/kit": "^2.
|
|
31
|
+
"@sveltejs/adapter-auto": "^7.0.1",
|
|
32
|
+
"@sveltejs/kit": "^2.53.0",
|
|
33
33
|
"@sveltejs/package": "^2.5.7",
|
|
34
34
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
35
35
|
"@vitest/coverage-v8": "^4.0.18",
|
|
36
|
-
"cspell": "^9.
|
|
36
|
+
"cspell": "^9.7.0",
|
|
37
37
|
"eslint": "^8.57.1",
|
|
38
38
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
39
39
|
"eslint-config-prettier": "^10.1.8",
|
|
40
40
|
"eslint-plugin-import": "^2.32.0",
|
|
41
|
-
"eslint-plugin-jsdoc": "^62.
|
|
41
|
+
"eslint-plugin-jsdoc": "^62.7.1",
|
|
42
42
|
"eslint-plugin-svelte": "^2.46.1",
|
|
43
|
-
"oxlint": "^1.
|
|
43
|
+
"oxlint": "^1.50.0",
|
|
44
44
|
"postcss": "^8.5.6",
|
|
45
45
|
"postcss-html": "^1.8.1",
|
|
46
46
|
"prettier": "^3.8.1",
|
|
47
|
-
"prettier-plugin-svelte": "^3.
|
|
47
|
+
"prettier-plugin-svelte": "^3.5.0",
|
|
48
48
|
"sass": "^1.97.3",
|
|
49
|
-
"stylelint": "^17.
|
|
49
|
+
"stylelint": "^17.3.0",
|
|
50
50
|
"stylelint-config-recommended-scss": "^17.0.0",
|
|
51
51
|
"stylelint-scss": "^7.0.0",
|
|
52
|
-
"svelte": "^5.
|
|
53
|
-
"svelte-check": "^4.3
|
|
52
|
+
"svelte": "^5.53.3",
|
|
53
|
+
"svelte-check": "^4.4.3",
|
|
54
54
|
"svelte-preprocess": "^6.0.3",
|
|
55
55
|
"tslib": "^2.8.1",
|
|
56
56
|
"vite": "^7.3.1",
|