@sveltia/ui 0.88.0 → 0.88.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/listbox/option.svelte +7 -4
- package/dist/components/resizable-pane/resizable-handle.svelte +15 -7
- package/dist/components/resizable-pane/resizable-pane-group.svelte +204 -20
- package/dist/components/resizable-pane/resizable-pane.svelte +25 -6
- package/dist/components/scroll/infinite-scroll.svelte +36 -7
- package/dist/components/slider/slider.svelte +10 -1
- package/dist/components/text-editor/core.js +30 -7
- package/dist/components/text-editor/markdown.d.ts +1 -1
- package/dist/components/text-editor/markdown.js +137 -59
- 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/transformers/block-escape.d.ts +4 -0
- package/dist/components/text-editor/transformers/block-escape.js +53 -2
- package/dist/components/text-editor/transformers/raw-syntax.js +70 -8
- package/dist/components/text-editor/transformers/table.js +43 -3
- package/dist/components/text-field/masked-input.svelte +1 -13
- package/dist/components/text-field/text-input.svelte +1 -1
- package/dist/components/toast/toast.svelte +19 -8
- package/dist/components/tree/tree-item.svelte +7 -4
- package/dist/components/util/popup.svelte +1 -1
- package/dist/services/group.svelte.js +32 -1
- package/dist/services/popup-position.js +20 -10
- package/dist/services/popup.svelte.d.ts +10 -1
- package/dist/services/popup.svelte.js +18 -5
- package/dist/services/tree.svelte.js +23 -7
- package/dist/typedefs.d.ts +9 -4
- package/dist/typedefs.js +6 -3
- package/package.json +20 -20
|
@@ -125,6 +125,10 @@ const SETEXT_UNDERLINE_REGEX = /^ {0,3}(=+|-+)[ \t]*$/;
|
|
|
125
125
|
* Regular expression to match an ATX heading, like `## Heading`.
|
|
126
126
|
*/
|
|
127
127
|
const ATX_HEADING_REGEX = /^ {0,3}#{1,6}(?:[ \t]|$)/;
|
|
128
|
+
/**
|
|
129
|
+
* Regular expression to match a thematic break, like `***` or `- - -`.
|
|
130
|
+
*/
|
|
131
|
+
const THEMATIC_BREAK_REGEX = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/;
|
|
128
132
|
|
|
129
133
|
/**
|
|
130
134
|
* Names of the HTML elements that start an HTML block that can interrupt a paragraph, as opposed to
|
|
@@ -252,12 +256,21 @@ const NON_PARAGRAPH_LINE_REGEX = new RegExp(
|
|
|
252
256
|
/^ {0,3}(?:>|[-+*](?:[ \t]|$)|\d{1,9}[.)](?:[ \t]|$)|`{3,}|~{3,}|\|)/.source,
|
|
253
257
|
`^ {0,3}${HTML_BLOCK_START_REGEX.source}`,
|
|
254
258
|
/^(?: {4}|\t)/.source,
|
|
255
|
-
|
|
259
|
+
THEMATIC_BREAK_REGEX.source,
|
|
256
260
|
SETEXT_UNDERLINE_REGEX.source,
|
|
257
261
|
].join('|'),
|
|
258
262
|
'i',
|
|
259
263
|
);
|
|
260
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Regular expression to match a line that is a block on its own, so the line after it isn’t in a
|
|
267
|
+
* paragraph: an ATX heading or a thematic break. A setext heading underline is one as well, but
|
|
268
|
+
* only after a paragraph line.
|
|
269
|
+
*/
|
|
270
|
+
const SINGLE_LINE_BLOCK_REGEX = new RegExp(
|
|
271
|
+
[ATX_HEADING_REGEX.source, THEMATIC_BREAK_REGEX.source].join('|'),
|
|
272
|
+
);
|
|
273
|
+
|
|
261
274
|
/**
|
|
262
275
|
* Regular expression to match a line that ends the paragraph before it: a line that doesn’t
|
|
263
276
|
* continue a paragraph, other than an indented line, which does.
|
|
@@ -375,6 +388,110 @@ const splitFormattedLines = (text) =>
|
|
|
375
388
|
const hasMultilineFormatting = (text) =>
|
|
376
389
|
MULTILINE_FORMATTING_REGEXES.some(([, regex]) => text.search(regex) !== -1);
|
|
377
390
|
|
|
391
|
+
/**
|
|
392
|
+
* @typedef {object} CodeSpan
|
|
393
|
+
* @property {number} start Index of the opening backticks.
|
|
394
|
+
* @property {number} end Index after the closing backticks.
|
|
395
|
+
* @property {number} fenceLength Number of backticks on either side.
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Find the code spans in a line like Lexical does: a run of backticks that isn’t escaped opens a
|
|
400
|
+
* code span, which is closed by the next run of as many backticks.
|
|
401
|
+
* @param {string} line Line.
|
|
402
|
+
* @returns {CodeSpan[]} Code spans.
|
|
403
|
+
* @see https://spec.commonmark.org/0.31.2/#code-spans
|
|
404
|
+
*/
|
|
405
|
+
export const findCodeSpans = (line) => {
|
|
406
|
+
const runs = [...line.matchAll(/`+/g)].map(({ 0: { length }, index }) => {
|
|
407
|
+
let backslashes = 0;
|
|
408
|
+
|
|
409
|
+
while (line[index - backslashes - 1] === '\\') {
|
|
410
|
+
backslashes += 1;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return { index, length, escaped: backslashes % 2 === 1 };
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
/** @type {CodeSpan[]} */
|
|
417
|
+
const spans = [];
|
|
418
|
+
|
|
419
|
+
for (let open = 0; open < runs.length; open += 1) {
|
|
420
|
+
let close = open + 1;
|
|
421
|
+
|
|
422
|
+
while (close < runs.length && runs[close].length !== runs[open].length) {
|
|
423
|
+
close += 1;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (!runs[open].escaped && close < runs.length) {
|
|
427
|
+
const { index, length } = runs[close];
|
|
428
|
+
|
|
429
|
+
spans.push({ start: runs[open].index, end: index + length, fenceLength: length });
|
|
430
|
+
open = close;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return spans;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Regular expression to match a link whose text spans a line break, like `[foo\nbar](url)`, but not
|
|
439
|
+
* an image. The text before the line break can’t end with the backslash of a hard line break.
|
|
440
|
+
*/
|
|
441
|
+
const MULTILINE_LINK_REGEX = new RegExp(
|
|
442
|
+
String.raw`(?<!(?:^|[^\\])(?:\\\\)*[\\!])\[([^[\]\n]*[^[\]\s\\])([ \t]*\n[ \t]*)([^[\]\n]+)\]` +
|
|
443
|
+
String.raw`\(([^()\s]*(?:[ \t]+"[^"\n]*")?)\)`,
|
|
444
|
+
'g',
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Split a code span whose code spans a line break into one per line, like `` `foo\nbar` `` into
|
|
449
|
+
* `` `foo`\n`bar` ``, so the formatting around it can be split into separate lines as well.
|
|
450
|
+
* Backslashes and spaces are literal in a code span.
|
|
451
|
+
* @param {string} part Part of a Markdown string outside fenced code blocks.
|
|
452
|
+
* @returns {string} Processed part.
|
|
453
|
+
*/
|
|
454
|
+
const splitMultilineCodeSpans = (part) =>
|
|
455
|
+
part.replace(
|
|
456
|
+
/(?<=^|[\s\p{P}\p{S}])(?<![`\\])`([^`\n]+?)\n([^`\n]+?)`(?=[\s\p{P}\p{S}]|$)(?!`)/gu,
|
|
457
|
+
'`$1`\n`$2`',
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Split a link whose text spans a line break in the text of formatting into one per line, like
|
|
462
|
+
* `[foo\nbar](url)` into `[foo](url)\n[bar](url)`, so the formatting can be split into separate
|
|
463
|
+
* lines. Only the formatting needs it, so links elsewhere, including those in raw HTML, are left as
|
|
464
|
+
* they are. An image is left as is, as it would be duplicated, and so is anything in a code span.
|
|
465
|
+
* @param {string} text Text matched by one of {@link MULTILINE_FORMATTING_REGEXES}.
|
|
466
|
+
* @returns {string} Processed text.
|
|
467
|
+
*/
|
|
468
|
+
const splitMultilineLinks = (text) => {
|
|
469
|
+
if (!text.includes('[')) {
|
|
470
|
+
return text;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const codeSpans = findCodeSpans(text);
|
|
474
|
+
|
|
475
|
+
return text.replace(MULTILINE_LINK_REGEX, (match, first, lineBreak, second, target, offset) =>
|
|
476
|
+
codeSpans.some(({ start, end }) => offset >= start && offset < end)
|
|
477
|
+
? match
|
|
478
|
+
: `[${first}](${target})${lineBreak}[${second}](${target})`,
|
|
479
|
+
);
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Check if the text of formatting that spans line breaks has a line break within a code span or a
|
|
484
|
+
* link text, which {@link splitMultilineCodeSpans} and {@link splitMultilineLinks} couldn’t split.
|
|
485
|
+
* @param {string} text Text matched by one of {@link MULTILINE_FORMATTING_REGEXES}.
|
|
486
|
+
* @returns {boolean} Result.
|
|
487
|
+
*/
|
|
488
|
+
const hasLineBreakInSpan = (text) =>
|
|
489
|
+
findCodeSpans(text).some(({ start, end }) => text.slice(start, end).includes('\n')) ||
|
|
490
|
+
// An inline link or a full reference link. The first run can’t have a line break, so a `[`
|
|
491
|
+
// followed by many lines isn’t matched in quadratic time. A bracket after an escaped backslash,
|
|
492
|
+
// like `\\[`, isn’t escaped
|
|
493
|
+
/(?<!(?:^|[^\\])(?:\\\\)*\\)\[[^[\]\n]*\n[^[\]]*\](?=[([])/.test(text);
|
|
494
|
+
|
|
378
495
|
/**
|
|
379
496
|
* Split multiline formatting into separate lines to prevent Markdown parsing issues. Fenced code
|
|
380
497
|
* blocks are left untouched, as the formatting syntax is not parsed there. Formatting is left as is
|
|
@@ -386,7 +503,7 @@ const hasMultilineFormatting = (text) =>
|
|
|
386
503
|
*/
|
|
387
504
|
export const splitMultilineFormatting = (value) =>
|
|
388
505
|
mapOutsideCodeBlocks(value, (part) => {
|
|
389
|
-
let result = part;
|
|
506
|
+
let result = splitMultilineCodeSpans(part);
|
|
390
507
|
let previous;
|
|
391
508
|
|
|
392
509
|
// Split the inner formatting first, so `**_foo\nbar_**` becomes `**_foo_**\n**_bar_**`, not
|
|
@@ -396,8 +513,16 @@ export const splitMultilineFormatting = (value) =>
|
|
|
396
513
|
previous = result;
|
|
397
514
|
result = MULTILINE_FORMATTING_REGEXES.reduce(
|
|
398
515
|
(current, [marker, regex]) =>
|
|
399
|
-
current.replace(regex, (match,
|
|
400
|
-
if (hasMultilineFormatting(
|
|
516
|
+
current.replace(regex, (match, formattedText) => {
|
|
517
|
+
if (hasMultilineFormatting(formattedText)) {
|
|
518
|
+
return match;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const text = splitMultilineLinks(formattedText);
|
|
522
|
+
|
|
523
|
+
// A line break left within a code span or a link text can’t be split there, as the
|
|
524
|
+
// markers would become part of the code or the link
|
|
525
|
+
if (hasLineBreakInSpan(text)) {
|
|
401
526
|
return match;
|
|
402
527
|
}
|
|
403
528
|
|
|
@@ -428,14 +553,7 @@ export const splitMultilineFormatting = (value) =>
|
|
|
428
553
|
);
|
|
429
554
|
}
|
|
430
555
|
|
|
431
|
-
return
|
|
432
|
-
result
|
|
433
|
-
// Backslashes and spaces are literal in a code span
|
|
434
|
-
.replace(
|
|
435
|
-
/(?<=^|[\s\p{P}\p{S}])(?<![`\\])`([^`\n]+?)\n([^`\n]+?)`(?=[\s\p{P}\p{S}]|$)(?!`)/gu,
|
|
436
|
-
'`$1`\n`$2`',
|
|
437
|
-
)
|
|
438
|
-
);
|
|
556
|
+
return result;
|
|
439
557
|
});
|
|
440
558
|
|
|
441
559
|
/**
|
|
@@ -457,52 +575,6 @@ const CODE_TAB_PLACEHOLDER = '\uE005';
|
|
|
457
575
|
*/
|
|
458
576
|
const CODE_SPACE_PLACEHOLDER = '\uE006';
|
|
459
577
|
|
|
460
|
-
/**
|
|
461
|
-
* @typedef {object} CodeSpan
|
|
462
|
-
* @property {number} start Index of the opening backticks.
|
|
463
|
-
* @property {number} end Index after the closing backticks.
|
|
464
|
-
* @property {number} fenceLength Number of backticks on either side.
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Find the code spans in a line like Lexical does: a run of backticks that isn’t escaped opens a
|
|
469
|
-
* code span, which is closed by the next run of as many backticks.
|
|
470
|
-
* @param {string} line Line.
|
|
471
|
-
* @returns {CodeSpan[]} Code spans.
|
|
472
|
-
* @see https://spec.commonmark.org/0.31.2/#code-spans
|
|
473
|
-
*/
|
|
474
|
-
export const findCodeSpans = (line) => {
|
|
475
|
-
const runs = [...line.matchAll(/`+/g)].map(({ 0: { length }, index }) => {
|
|
476
|
-
let backslashes = 0;
|
|
477
|
-
|
|
478
|
-
while (line[index - backslashes - 1] === '\\') {
|
|
479
|
-
backslashes += 1;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
return { index, length, escaped: backslashes % 2 === 1 };
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
/** @type {CodeSpan[]} */
|
|
486
|
-
const spans = [];
|
|
487
|
-
|
|
488
|
-
for (let open = 0; open < runs.length; open += 1) {
|
|
489
|
-
let close = open + 1;
|
|
490
|
-
|
|
491
|
-
while (close < runs.length && runs[close].length !== runs[open].length) {
|
|
492
|
-
close += 1;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
if (!runs[open].escaped && close < runs.length) {
|
|
496
|
-
const { index, length } = runs[close];
|
|
497
|
-
|
|
498
|
-
spans.push({ start: runs[open].index, end: index + length, fenceLength: length });
|
|
499
|
-
open = close;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return spans;
|
|
504
|
-
};
|
|
505
|
-
|
|
506
578
|
/**
|
|
507
579
|
* Add placeholders around the backslashes at the end of a line, so Lexical reads them as CommonMark
|
|
508
580
|
* does. Lexical looks for a hard line break, a backslash at the end of a line, after it has removed
|
|
@@ -681,7 +753,13 @@ const markHtml = (part) => {
|
|
|
681
753
|
} else if (!isInParagraph && STANDALONE_HTML_TAG_REGEX.test(line)) {
|
|
682
754
|
end = null;
|
|
683
755
|
} else {
|
|
684
|
-
|
|
756
|
+
// A heading or a thematic break doesn’t leave a paragraph open, so a standalone tag
|
|
757
|
+
// after it starts an HTML block. A line like `===` is a heading underline only after a
|
|
758
|
+
// paragraph line, and paragraph text otherwise
|
|
759
|
+
isInParagraph =
|
|
760
|
+
!isBlankLine &&
|
|
761
|
+
!SINGLE_LINE_BLOCK_REGEX.test(line) &&
|
|
762
|
+
!(isInParagraph && SETEXT_UNDERLINE_REGEX.test(line));
|
|
685
763
|
|
|
686
764
|
return line.includes('\t')
|
|
687
765
|
? line.replace(GLOBAL_INLINE_HTML_REGEX, (tag) =>
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export function escapeBlockSyntax(text: string): string;
|
|
2
2
|
export function unescapeText(markdown: string): string;
|
|
3
|
+
export function unescapeCharacterReferences(markdown: string, { isInLink, isAtLineEnd }: {
|
|
4
|
+
isInLink: boolean;
|
|
5
|
+
isAtLineEnd: boolean;
|
|
6
|
+
}): string;
|
|
3
7
|
/**
|
|
4
8
|
* Export-only transformer that tidies up the Markdown of a text node that isn’t inline code, which
|
|
5
9
|
* Lexical exports verbatim. It removes the unnecessary escapes Lexical adds; see `unescapeText()`.
|
|
@@ -64,6 +64,53 @@ export const unescapeText = (markdown) =>
|
|
|
64
64
|
return match;
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Characters for the numeric character references Lexical exports in place of literal text.
|
|
69
|
+
* @type {Record<string, string>}
|
|
70
|
+
*/
|
|
71
|
+
const REFERENCED_CHARS = { 38: '&', 60: '<', 91: '[', 93: ']' };
|
|
72
|
+
/**
|
|
73
|
+
* Regular expression to match the start of an email autolink after its `<`, which can start with a
|
|
74
|
+
* digit or a symbol, like `<1@example.com>`.
|
|
75
|
+
* @see https://spec.commonmark.org/0.31.2/#email-autolink
|
|
76
|
+
*/
|
|
77
|
+
const EMAIL_AUTOLINK_START_REGEX = /^[\w.!#$%&'*+/=?^`{|}~-]{1,64}@[A-Za-z\d]/;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Replace the numeric character references Lexical exports for `<`, `&`, `[` and `]` in text, so
|
|
81
|
+
* HTML, a character reference or a link isn’t read from it, with the characters themselves where
|
|
82
|
+
* they can’t start one, so `a <= b`, `see [1]` and the `[ ]` of a task list item stay readable.
|
|
83
|
+
* The others are escaped with a backslash instead, as the Markdown would be written by hand: a `<`
|
|
84
|
+
* that could start a tag, a comment or an autolink, a `&` that could start a numeric reference, a
|
|
85
|
+
* `[` that could start a footnote and a `]` that could end a link text or a link label. One at the
|
|
86
|
+
* end of the node stays escaped, as the next node may complete the syntax, unless nothing but a
|
|
87
|
+
* line break follows, which none of them can be followed by. A bracket in a link text stays escaped
|
|
88
|
+
* too, as unbalanced brackets would end the link text early. Every replacement is punctuation,
|
|
89
|
+
* like the reference, so the escapes left by `unescapeText()` stay valid.
|
|
90
|
+
* @param {string} markdown Markdown exported from a text node with its format.
|
|
91
|
+
* @param {object} context Where the text node is.
|
|
92
|
+
* @param {boolean} context.isInLink Whether the text node is in a link.
|
|
93
|
+
* @param {boolean} context.isAtLineEnd Whether the text node is at the end of a line.
|
|
94
|
+
* @returns {string} Tidied Markdown.
|
|
95
|
+
* @see https://github.com/facebook/lexical/pull/9481
|
|
96
|
+
*/
|
|
97
|
+
export const unescapeCharacterReferences = (markdown, { isInLink, isAtLineEnd }) =>
|
|
98
|
+
markdown.replace(/&#(38|60|91|93);/g, (match, code, offset, string) => {
|
|
99
|
+
const char = REFERENCED_CHARS[code];
|
|
100
|
+
// Enough for the local part of an email address, the longest the checks below need, without
|
|
101
|
+
// copying the rest of a long text each time
|
|
102
|
+
const next = string.slice(offset + match.length, offset + match.length + 70);
|
|
103
|
+
|
|
104
|
+
const isNeeded =
|
|
105
|
+
(!next && !isAtLineEnd) ||
|
|
106
|
+
(char === '<' && (/^[A-Za-z/!?]/.test(next) || EMAIL_AUTOLINK_START_REGEX.test(next))) ||
|
|
107
|
+
(char === '&' && /^#(?:\d{1,7}|[xX][\dA-Fa-f]{1,6});/.test(next)) ||
|
|
108
|
+
(char === '[' && (isInLink || next.startsWith('^'))) ||
|
|
109
|
+
(char === ']' && (isInLink || /^[(:[]/.test(next)));
|
|
110
|
+
|
|
111
|
+
return isNeeded ? `\\${char}` : char;
|
|
112
|
+
});
|
|
113
|
+
|
|
67
114
|
/**
|
|
68
115
|
* Check if the given text node is italic and the italic text it’s part of is next to a word
|
|
69
116
|
* character, like `b` in `a*b*c`. The italic text then needs the `*` delimiter instead of `_`,
|
|
@@ -161,10 +208,14 @@ export const BLOCK_SYNTAX_ESCAPE = {
|
|
|
161
208
|
return markdown.replace(RAW_TEXT, () => rawSyntax);
|
|
162
209
|
}
|
|
163
210
|
|
|
164
|
-
markdown = unescapeText(markdown);
|
|
165
|
-
|
|
166
211
|
const parent = node.getParent();
|
|
167
212
|
const previous = node.getPreviousSibling();
|
|
213
|
+
const next = node.getNextSibling();
|
|
214
|
+
|
|
215
|
+
markdown = unescapeCharacterReferences(unescapeText(markdown), {
|
|
216
|
+
isInLink: !!parent?.isInline(),
|
|
217
|
+
isAtLineEnd: !next || isLineBreakNode(next),
|
|
218
|
+
});
|
|
168
219
|
|
|
169
220
|
// Text in a link or other inline element, in a code block, which is exported verbatim, or in a
|
|
170
221
|
// heading, whose content is only parsed for inline syntax, or text after the start of a line
|
|
@@ -24,6 +24,12 @@ export const HTML_TAG_SOURCE =
|
|
|
24
24
|
`(?:${TAG_SPACE}*=${TAG_SPACE}*(?:[^\\s"'=<>\`\\uE005]+|'[^'\\n]*'|"[^"\\n]*"))?)*` +
|
|
25
25
|
`${TAG_SPACE}*/?>|</[A-Za-z][A-Za-z0-9-]*${TAG_SPACE}*>`;
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Regular expression source to match the place before a `<` that isn’t escaped. The lookahead comes
|
|
29
|
+
* first, so the lookbehind is only tried before a `<`.
|
|
30
|
+
*/
|
|
31
|
+
const UNESCAPED_LT_SOURCE = String.raw`(?=<)(?<!(?:^|[^\\])(?:\\\\)*\\)`;
|
|
32
|
+
|
|
27
33
|
/**
|
|
28
34
|
* Regular expression to match inline raw HTML on a line: an open tag, a closing tag, a comment, a
|
|
29
35
|
* processing instruction, a declaration or a CDATA section, which isn’t escaped.
|
|
@@ -31,8 +37,8 @@ export const HTML_TAG_SOURCE =
|
|
|
31
37
|
*/
|
|
32
38
|
export const INLINE_HTML_REGEX = new RegExp(
|
|
33
39
|
[
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
UNESCAPED_LT_SOURCE,
|
|
41
|
+
'(?:',
|
|
36
42
|
[
|
|
37
43
|
HTML_TAG_SOURCE,
|
|
38
44
|
// Comment
|
|
@@ -48,6 +54,42 @@ export const INLINE_HTML_REGEX = new RegExp(
|
|
|
48
54
|
].join(''),
|
|
49
55
|
);
|
|
50
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Regular expression source to match a URI scheme that runs a script or embeds content, in any
|
|
59
|
+
* case, as a scheme is case-insensitive.
|
|
60
|
+
*/
|
|
61
|
+
const UNSAFE_SCHEME_SOURCE = `(?:${['javascript', 'vbscript', 'data']
|
|
62
|
+
.map((scheme) => scheme.replace(/[a-z]/g, (char) => `[${char}${char.toUpperCase()}]`))
|
|
63
|
+
.join('|')})`;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Regular expression to match an autolink, like `<https://example.com>` or `<foo@example.com>`,
|
|
67
|
+
* which isn’t escaped.
|
|
68
|
+
* @see https://spec.commonmark.org/0.31.2/#autolinks
|
|
69
|
+
*/
|
|
70
|
+
const AUTOLINK_REGEX = new RegExp(
|
|
71
|
+
[
|
|
72
|
+
UNESCAPED_LT_SOURCE,
|
|
73
|
+
'(?:',
|
|
74
|
+
[
|
|
75
|
+
// URI, other than one with a scheme that runs a script or embeds content, which is left to
|
|
76
|
+
// be escaped as text
|
|
77
|
+
String.raw`<(?!${UNSAFE_SCHEME_SOURCE}:)[A-Za-z][A-Za-z0-9+.-]{1,31}:[^\s<>]*>`,
|
|
78
|
+
// Email address
|
|
79
|
+
String.raw`<[\w.!#$%&'*+/=?^\x60{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?` +
|
|
80
|
+
String.raw`(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*>`,
|
|
81
|
+
].join('|'),
|
|
82
|
+
')',
|
|
83
|
+
].join(''),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Regular expression to match a footnote reference, like `[^1]`, which isn’t escaped. Footnotes
|
|
88
|
+
* aren’t supported, but they’re read by GitHub and many other renderers.
|
|
89
|
+
* @see https://github.github.com/gfm/
|
|
90
|
+
*/
|
|
91
|
+
const FOOTNOTE_REFERENCE_REGEX = /(?<!(?:^|[^\\])(?:\\\\)*\\)\[\^[^\s[\]]+\]/;
|
|
92
|
+
|
|
51
93
|
/**
|
|
52
94
|
* Block syntax at the start of a line, after up to 3 spaces.
|
|
53
95
|
*/
|
|
@@ -64,12 +106,20 @@ const BLOCK_SYNTAX = [
|
|
|
64
106
|
.map(({ source }) => source)
|
|
65
107
|
.join('|');
|
|
66
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Label of a link reference definition or a footnote definition, like `[foo]:` in
|
|
111
|
+
* `[foo]: https://example.com` or `[^1]:` in `[^1]: Note`, which isn’t supported. The rest of the
|
|
112
|
+
* line is left to the other transformers, so a paragraph that only starts like one keeps its
|
|
113
|
+
* formatting.
|
|
114
|
+
* @see https://spec.commonmark.org/0.31.2/#link-reference-definitions
|
|
115
|
+
*/
|
|
116
|
+
const DEFINITION_SYNTAX = String.raw`\[(?:[^\\[\]]|\\.)+\]:`;
|
|
67
117
|
/**
|
|
68
118
|
* Regular expression to match the Markdown syntax that the editor imports as text, but that has to
|
|
69
119
|
* be exported as is: the block syntax at the start of a line, which can’t be nested in a blockquote
|
|
70
|
-
* or a list item, or isn’t supported, like the `)` ordered list delimiter.
|
|
120
|
+
* or a list item, or isn’t supported, like the `)` ordered list delimiter or a definition.
|
|
71
121
|
*/
|
|
72
|
-
const RAW_SYNTAX_REGEX = new RegExp(`^ {0,3}(?:${BLOCK_SYNTAX})`);
|
|
122
|
+
const RAW_SYNTAX_REGEX = new RegExp(`^ {0,3}(?:${BLOCK_SYNTAX}|${DEFINITION_SYNTAX})`);
|
|
73
123
|
|
|
74
124
|
/**
|
|
75
125
|
* State of a text node imported from the {@link RAW_SYNTAX_REGEX raw syntax}, holding the Markdown
|
|
@@ -139,11 +189,23 @@ export const RAW_SYNTAX = {
|
|
|
139
189
|
|
|
140
190
|
/**
|
|
141
191
|
* Regular expression to match raw HTML: a line of an HTML block after the placeholder that marks
|
|
142
|
-
* it,
|
|
143
|
-
* that
|
|
144
|
-
*
|
|
192
|
+
* it, inline HTML, like a tag, an autolink or a footnote reference, which would otherwise be
|
|
193
|
+
* escaped on export as text that only looks like one. The placeholder is left out of the match, so
|
|
194
|
+
* an editor component that matches the line after it, which comes first, still takes precedence;
|
|
195
|
+
* see `removePlaceholdersFromMatch()` in `core.js`. It’s included if the line starts with a
|
|
196
|
+
* formatting marker, though: Lexical prefers formatting to a text match that covers the same text,
|
|
197
|
+
* so a line like `*foo*` would otherwise be imported as italic. A component pattern doesn’t start
|
|
198
|
+
* with one.
|
|
145
199
|
*/
|
|
146
|
-
const RAW_HTML_REGEX = new RegExp(
|
|
200
|
+
const RAW_HTML_REGEX = new RegExp(
|
|
201
|
+
[
|
|
202
|
+
`^${HTML_BLOCK_PLACEHOLDER}(?=[*_~=]).+`,
|
|
203
|
+
`(?<=^${HTML_BLOCK_PLACEHOLDER}).+`,
|
|
204
|
+
INLINE_HTML_REGEX.source,
|
|
205
|
+
AUTOLINK_REGEX.source,
|
|
206
|
+
FOOTNOTE_REFERENCE_REGEX.source,
|
|
207
|
+
].join('|'),
|
|
208
|
+
);
|
|
147
209
|
|
|
148
210
|
/**
|
|
149
211
|
* Import-only transformer that marks raw HTML, so it’s exported as is. Neither the Markdown syntax
|
|
@@ -31,6 +31,7 @@ import { RAW_HTML, RAW_SYNTAX } from './raw-syntax.js';
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @import { ElementTransformer, TextMatchTransformer, Transformer } from '@lexical/markdown';
|
|
34
|
+
* @import { ElementFormatType } from 'lexical';
|
|
34
35
|
*/
|
|
35
36
|
|
|
36
37
|
const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;
|
|
@@ -40,6 +41,24 @@ const TABLE_ROW_REG_EXP = /^(?:\|)(.+)(?:\|)\s?$/;
|
|
|
40
41
|
* @see https://github.github.com/gfm/#delimiter-row
|
|
41
42
|
*/
|
|
42
43
|
const TABLE_ROW_DIVIDER_REG_EXP = /^(?:\|[ \t]*:?-+:?[ \t]*)+\|\s?$/;
|
|
44
|
+
/**
|
|
45
|
+
* Delimiter row cell for each column alignment, which is kept as the format of the column’s cells.
|
|
46
|
+
* @type {Record<string, string>}
|
|
47
|
+
*/
|
|
48
|
+
const ALIGNMENT_DELIMITERS = { left: ':---', center: ':---:', right: '---:' };
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the alignment of a column from its delimiter row cell, like `:-:`.
|
|
52
|
+
* @param {string} delimiter Delimiter row cell.
|
|
53
|
+
* @returns {ElementFormatType} Alignment, or an empty string for the default.
|
|
54
|
+
*/
|
|
55
|
+
const getColumnAlignment = (delimiter) => {
|
|
56
|
+
const text = delimiter.trim();
|
|
57
|
+
const left = text.startsWith(':');
|
|
58
|
+
const right = text.endsWith(':');
|
|
59
|
+
|
|
60
|
+
return left && right ? 'center' : left ? 'left' : right ? 'right' : '';
|
|
61
|
+
};
|
|
43
62
|
|
|
44
63
|
/**
|
|
45
64
|
* Returns the number of columns in the table.
|
|
@@ -123,6 +142,8 @@ export const createTableTransformer = (cellTransformers = []) => {
|
|
|
123
142
|
node.getChildren().forEach((row) => {
|
|
124
143
|
/** @type {string[]} */
|
|
125
144
|
const rowOutput = [];
|
|
145
|
+
/** @type {TableCellNode[]} */
|
|
146
|
+
const cells = [];
|
|
126
147
|
|
|
127
148
|
if (!isTableRowNode(row)) {
|
|
128
149
|
return;
|
|
@@ -140,6 +161,7 @@ export const createTableTransformer = (cellTransformers = []) => {
|
|
|
140
161
|
.replace(/\n/g, '\\n')
|
|
141
162
|
.trim(),
|
|
142
163
|
);
|
|
164
|
+
cells.push(cell);
|
|
143
165
|
|
|
144
166
|
if (cell.__headerState === TableCellHeaderStates.ROW) {
|
|
145
167
|
isHeaderRow = true;
|
|
@@ -150,7 +172,9 @@ export const createTableTransformer = (cellTransformers = []) => {
|
|
|
150
172
|
output.push(`| ${rowOutput.join(' | ')} |`);
|
|
151
173
|
|
|
152
174
|
if (isHeaderRow) {
|
|
153
|
-
output.push(
|
|
175
|
+
output.push(
|
|
176
|
+
`| ${cells.map((cell) => ALIGNMENT_DELIMITERS[cell.getFormatType()] ?? '---').join(' | ')} |`,
|
|
177
|
+
);
|
|
154
178
|
}
|
|
155
179
|
});
|
|
156
180
|
|
|
@@ -173,13 +197,17 @@ export const createTableTransformer = (cellTransformers = []) => {
|
|
|
173
197
|
return;
|
|
174
198
|
}
|
|
175
199
|
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
const alignments = textContent.trim().slice(1, -1).split('|').map(getColumnAlignment);
|
|
201
|
+
|
|
202
|
+
// Add header state to row cells, and the column alignment, which the rows that follow take
|
|
203
|
+
// from the header row
|
|
204
|
+
lastRow.getChildren().forEach((cell, index) => {
|
|
178
205
|
if (!isTableCellNode(cell)) {
|
|
179
206
|
return;
|
|
180
207
|
}
|
|
181
208
|
|
|
182
209
|
cell.setHeaderStyles(TableCellHeaderStates.ROW, TableCellHeaderStates.ROW);
|
|
210
|
+
cell.setFormat(alignments[index] ?? '');
|
|
183
211
|
});
|
|
184
212
|
|
|
185
213
|
// Remove line
|
|
@@ -243,6 +271,18 @@ export const createTableTransformer = (cellTransformers = []) => {
|
|
|
243
271
|
const previousSibling = parentNode.getPreviousSibling();
|
|
244
272
|
|
|
245
273
|
if (isTableNode(previousSibling) && getTableColumnsSize(previousSibling) === maxCells) {
|
|
274
|
+
const headerCells = /** @type {TableRowNode} */ (
|
|
275
|
+
previousSibling.getFirstChild()
|
|
276
|
+
).getChildren();
|
|
277
|
+
|
|
278
|
+
table.getChildren().forEach((row) => {
|
|
279
|
+
/** @type {TableRowNode} */ (row).getChildren().forEach((cell, index) => {
|
|
280
|
+
/** @type {TableCellNode} */ (cell).setFormat(
|
|
281
|
+
/** @type {TableCellNode} */ (headerCells[index]).getFormatType(),
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
246
286
|
previousSibling.append(...table.getChildren());
|
|
247
287
|
parentNode.remove();
|
|
248
288
|
} else {
|
|
@@ -46,11 +46,6 @@
|
|
|
46
46
|
|
|
47
47
|
const id = $props.id();
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Reference to the `<input>` element.
|
|
51
|
-
* @type {HTMLInputElement | undefined}
|
|
52
|
-
*/
|
|
53
|
-
let inputElement = $state();
|
|
54
49
|
let show = $state(false);
|
|
55
50
|
|
|
56
51
|
const labels = $derived(
|
|
@@ -64,12 +59,6 @@
|
|
|
64
59
|
hide: '_sui.secret_input.hide_secret',
|
|
65
60
|
},
|
|
66
61
|
);
|
|
67
|
-
|
|
68
|
-
$effect(() => {
|
|
69
|
-
if (mask === 'type') {
|
|
70
|
-
inputElement?.setAttribute('type', show ? 'text' : 'password');
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
62
|
</script>
|
|
74
63
|
|
|
75
64
|
<div
|
|
@@ -86,12 +75,11 @@
|
|
|
86
75
|
words -->
|
|
87
76
|
<TextInput
|
|
88
77
|
dir="ltr"
|
|
89
|
-
bind:element={inputElement}
|
|
90
78
|
{...mask === 'css' ? { autocomplete: 'off', autocapitalize: 'off', autocorrect: 'off' } : {}}
|
|
91
79
|
{...restProps}
|
|
92
80
|
{id}
|
|
93
81
|
bind:value
|
|
94
|
-
{...mask === 'type' ? { type: 'password' } : {}}
|
|
82
|
+
{...mask === 'type' ? { type: show ? 'text' : 'password' } : {}}
|
|
95
83
|
spellcheck="false"
|
|
96
84
|
{flex}
|
|
97
85
|
{monospace}
|
|
@@ -244,13 +244,23 @@
|
|
|
244
244
|
* @type {HTMLElement | undefined}
|
|
245
245
|
*/
|
|
246
246
|
let toast = $state();
|
|
247
|
+
/**
|
|
248
|
+
* Whether the pointer is over the toast.
|
|
249
|
+
* @type {boolean}
|
|
250
|
+
*/
|
|
251
|
+
let hovered = $state(false);
|
|
252
|
+
/**
|
|
253
|
+
* Whether the focus is inside the toast.
|
|
254
|
+
* @type {boolean}
|
|
255
|
+
*/
|
|
256
|
+
let focused = $state(false);
|
|
247
257
|
/**
|
|
248
258
|
* Whether the pointer is over the toast or the focus is inside it. The auto-hide countdown is
|
|
249
259
|
* held while it is, so a toast with a control in it can’t vanish from under the user (WCAG
|
|
250
|
-
* 2.2.1).
|
|
251
|
-
*
|
|
260
|
+
* 2.2.1). Both are tracked apart, so the pointer leaving doesn’t release the hold of the focus,
|
|
261
|
+
* or the other way around.
|
|
252
262
|
*/
|
|
253
|
-
|
|
263
|
+
const held = $derived(hovered || focused);
|
|
254
264
|
/**
|
|
255
265
|
* Whether the content is in the DOM tree. It lags behind {@link show} on the way out, so the
|
|
256
266
|
* toast can fade before the content goes. On the way in, the content is inserted rather than
|
|
@@ -304,7 +314,8 @@
|
|
|
304
314
|
toast.remove();
|
|
305
315
|
// A detached element gets no `pointerleave` or `focusout`, so release the hold here, or the
|
|
306
316
|
// countdown would never start the next time the toast is shown
|
|
307
|
-
|
|
317
|
+
hovered = false;
|
|
318
|
+
focused = false;
|
|
308
319
|
|
|
309
320
|
// Close the base once the last toast is gone
|
|
310
321
|
if (!popover.querySelector('.toast') && popover.matches(':popover-open')) {
|
|
@@ -374,16 +385,16 @@
|
|
|
374
385
|
class={['sui', 'toast', position]}
|
|
375
386
|
aria-hidden={!show}
|
|
376
387
|
onpointerenter={() => {
|
|
377
|
-
|
|
388
|
+
hovered = true;
|
|
378
389
|
}}
|
|
379
390
|
onpointerleave={() => {
|
|
380
|
-
|
|
391
|
+
hovered = false;
|
|
381
392
|
}}
|
|
382
393
|
onfocusin={() => {
|
|
383
|
-
|
|
394
|
+
focused = true;
|
|
384
395
|
}}
|
|
385
396
|
onfocusout={(event) => {
|
|
386
|
-
|
|
397
|
+
focused = !!event.relatedTarget && !!toast?.contains(/** @type {Node} */ (event.relatedTarget));
|
|
387
398
|
}}
|
|
388
399
|
>
|
|
389
400
|
{#if rendered}
|