@sveltia/ui 0.87.0 → 0.87.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.
@@ -106,11 +106,6 @@
106
106
  font-size: var(--sui-control-font-size);
107
107
  line-height: var(--sui-control-line-height);
108
108
  }
109
- @media (pointer: coarse) {
110
- [role=listbox] {
111
- gap: 8px 0;
112
- }
113
- }
114
109
  [role=listbox] :global([role=separator]) {
115
110
  margin: 4px 0;
116
111
  background-color: var(--sui-control-border-color);
@@ -123,7 +123,11 @@
123
123
  if (hasItems) {
124
124
  event.preventDefault();
125
125
  event.stopPropagation();
126
- isPopupOpen = !isPopupOpen;
126
+ window.clearTimeout(hoverTimer);
127
+ // A pointer click opens rather than toggles, as the hover may have opened the submenu
128
+ // already; on a touch screen, the emulated `mouseenter` comes right before the `click`. A
129
+ // scripted click still toggles it, which is how the keyboard navigation closes it.
130
+ isPopupOpen = event.detail ? true : !isPopupOpen;
127
131
  }
128
132
 
129
133
  onclick?.(event);
@@ -65,11 +65,6 @@
65
65
  border-radius: var(--sui-menu-border-radius, 4px);
66
66
  padding: var(--sui-menu-padding, 4px);
67
67
  }
68
- @media (pointer: coarse) {
69
- .menu {
70
- gap: 8px 0;
71
- }
72
- }
73
68
  .menu :global([role=separator]) {
74
69
  margin: var(--sui-menu-divider-margin, 4px);
75
70
  width: auto;
@@ -20,6 +20,8 @@ import {
20
20
  import { HeadingNode, QuoteNode } from '@lexical/rich-text';
21
21
  import { createCommand } from 'lexical';
22
22
 
23
+ import { LEADING_INLINE_CODE } from './transformers/inline-code.js';
24
+
23
25
  /**
24
26
  * @import { EditorThemeClasses, LexicalCommand } from 'lexical';
25
27
  * @import { Transformer } from '@lexical/markdown';
@@ -219,7 +221,8 @@ export const TRANSFORMER_MAP = {
219
221
  // MULTILINE_ELEMENT_TRANSFORMERS
220
222
  'code-block': [CODE],
221
223
  // TEXT_FORMAT_TRANSFORMERS
222
- code: [INLINE_CODE],
224
+ // The second one keeps the backslashes in inline code at the start of a node
225
+ code: [INLINE_CODE, LEADING_INLINE_CODE],
223
226
  bold: [
224
227
  BOLD_STAR,
225
228
  // Disabled for Markdown output in `DISABLED_MARKDOWN_TAGS` below
@@ -96,7 +96,6 @@ import {
96
96
  import {
97
97
  convertSetextHeadings,
98
98
  convertTildeFences,
99
- increaseListIndentation,
100
99
  padBlankBlockquoteLines,
101
100
  splitMultilineFormatting,
102
101
  trimBlankBlockquoteLines,
@@ -1191,10 +1190,9 @@ export const convertMarkdownToLexical = async (editor, value, enabledTransformer
1191
1190
  */
1192
1191
  $import: () => {
1193
1192
  convertFromMarkdownString(
1194
- // Split multiline formatting into separate lines to prevent Markdown parsing issues, then
1195
- // increase list indentation levels to prevent Markdown parsing issues, and pad blank
1196
- // blockquote lines so they are not imported as literal `>` text
1197
- padBlankBlockquoteLines(increaseListIndentation(splitMultilineFormatting(normalizedValue))),
1193
+ // Split multiline formatting into separate lines to prevent Markdown parsing issues, and
1194
+ // pad blank blockquote lines so they are not imported as literal `>` text
1195
+ padBlankBlockquoteLines(splitMultilineFormatting(normalizedValue)),
1198
1196
  enabledTransformers,
1199
1197
  );
1200
1198
  },
@@ -1,7 +1,6 @@
1
1
  export function splitMultilineFormatting(value: string): string;
2
2
  export function convertTildeFences(value: string): string;
3
3
  export function convertSetextHeadings(value: string): string;
4
- export function increaseListIndentation(value: string): string;
5
4
  export function padBlankBlockquoteLines(value: string): string;
6
5
  export function trimBlankBlockquoteLines(value: string): string;
7
6
  export type CodeBlock = {
@@ -327,24 +327,6 @@ export const convertSetextHeadings = (value) => {
327
327
  });
328
328
  };
329
329
 
330
- /**
331
- * Increase list indentation levels to prevent Markdown parsing issues.
332
- * Slate uses 2 spaces per indentation level, whereas Lexical uses 4 spaces.
333
- * This function doubles the indentation to match Lexical's expectations.
334
- * @param {string} value Markdown string to process.
335
- * @returns {string} Processed Markdown string.
336
- * @see https://github.com/sveltia/sveltia-cms/issues/549
337
- */
338
- export const increaseListIndentation = (value) => {
339
- if (!value.match(/^\s{2}(?:-|\+|\*|\d+\.)\s/m)) {
340
- return value;
341
- }
342
-
343
- return mapLinesOutsideCodeBlocks(value, (line) =>
344
- line.replace(/^(\s+)(-|\+|\*|\d+\.)/, (_match, p1, p2) => `${' '.repeat(p1.length * 2)}${p2}`),
345
- );
346
- };
347
-
348
330
  /**
349
331
  * Add a trailing space to a blank blockquote line (`>`) so Lexical treats it as a blank line within
350
332
  * the blockquote. Without the space, the line does not match Lexical's `/^>\s/` quote pattern and
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
3
3
  */
4
- export const UI_VERSION: "0.87.0";
4
+ export const UI_VERSION: "0.87.2";
@@ -3,4 +3,4 @@
3
3
  /**
4
4
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
5
5
  */
6
- export const UI_VERSION = '0.87.0';
6
+ export const UI_VERSION = '0.87.2';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @import { TextMatchTransformer } from '@lexical/markdown';
3
+ * @import { TextNode } from 'lexical';
4
+ */
5
+ /**
6
+ * Import-only transformer for a code span at the start of a node, such as a table cell, a
7
+ * paragraph or bold text starting with inline code. Lexical’s `INLINE_CODE` transformer then reuses
8
+ * the node for the code, and removes the backslash escapes from the node once the inline syntax has
9
+ * been imported, so `` `C:\$MFT` `` would become `C:$MFT`, though backslashes are literal in a code
10
+ * span. Backslashes in a code span split from the text before it are kept. A text match wrapping a
11
+ * code span takes priority over it, and this one replaces the node with a new one, leaving the old
12
+ * node, which is no longer in the document, to be unescaped.
13
+ * @type {TextMatchTransformer}
14
+ * @see https://github.com/sveltia/sveltia-cms/issues/1100
15
+ */
16
+ export const LEADING_INLINE_CODE: TextMatchTransformer;
17
+ import type { TextMatchTransformer } from '@lexical/markdown';
@@ -0,0 +1,52 @@
1
+ import { $createTextNode as createTextNode } from 'lexical';
2
+
3
+ /**
4
+ * @import { TextMatchTransformer } from '@lexical/markdown';
5
+ * @import { TextNode } from 'lexical';
6
+ */
7
+
8
+ /**
9
+ * Import-only transformer for a code span at the start of a node, such as a table cell, a
10
+ * paragraph or bold text starting with inline code. Lexical’s `INLINE_CODE` transformer then reuses
11
+ * the node for the code, and removes the backslash escapes from the node once the inline syntax has
12
+ * been imported, so `` `C:\$MFT` `` would become `C:$MFT`, though backslashes are literal in a code
13
+ * span. Backslashes in a code span split from the text before it are kept. A text match wrapping a
14
+ * code span takes priority over it, and this one replaces the node with a new one, leaving the old
15
+ * node, which is no longer in the document, to be unescaped.
16
+ * @type {TextMatchTransformer}
17
+ * @see https://github.com/sveltia/sveltia-cms/issues/1100
18
+ */
19
+ export const LEADING_INLINE_CODE = {
20
+ dependencies: [],
21
+ /**
22
+ * Never export Markdown; Lexical’s `INLINE_CODE` transformer exports the code.
23
+ * @returns {null} Nothing.
24
+ */
25
+ export: () => null,
26
+ // A code span as Lexical’s `INLINE_CODE` transformer reads it: from a backtick run to the next
27
+ // run of the same length
28
+ // @see https://spec.commonmark.org/0.31.2/#code-spans
29
+ importRegExp: /^(`+)(?!`)([^]*?[^`])\1(?!`)/,
30
+ regExp: /(?!)/,
31
+ /**
32
+ * Replace the given text node, which has been split at the end of the code span, with a new code
33
+ * node, keeping its formats and style.
34
+ * @param {TextNode} node Text node.
35
+ * @param {RegExpMatchArray} match Match of the code span.
36
+ * @returns {TextNode} New node.
37
+ */
38
+ replace: (node, [, , content]) => {
39
+ // One space is stripped from both ends of the content if it’s padded on both sides and has a
40
+ // non-space character
41
+ const codeNode = createTextNode(/^ .*[^ ].* $/s.test(content) ? content.slice(1, -1) : content)
42
+ .setFormat(node.getFormat())
43
+ .setStyle(node.getStyle())
44
+ // Lexical doesn’t import the inline syntax in a node that is already code
45
+ .toggleFormat('code');
46
+
47
+ node.replace(codeNode);
48
+
49
+ return codeNode;
50
+ },
51
+ type: 'text-match',
52
+ };
@@ -24,6 +24,7 @@ import {
24
24
  import { $isParagraphNode as isParagraphNode, $isTextNode as isTextNode } from 'lexical';
25
25
 
26
26
  import { BLOCK_SYNTAX_ESCAPE } from './block-escape.js';
27
+ import { LEADING_INLINE_CODE } from './inline-code.js';
27
28
 
28
29
  /**
29
30
  * @import { ElementTransformer, TextMatchTransformer, Transformer } from '@lexical/markdown';
@@ -90,7 +91,7 @@ export const mapToTableCells = (textContent, transformers) => {
90
91
  */
91
92
  export const createTableTransformer = (cellTransformers = []) => {
92
93
  /** @type {Transformer[]} */
93
- const transformers = [...cellTransformers, ...TRANSFORMERS];
94
+ const transformers = [...cellTransformers, ...TRANSFORMERS, LEADING_INLINE_CODE];
94
95
  /** @type {Transformer[]} */
95
96
  const exportTransformers = [...transformers, BLOCK_SYNTAX_ESCAPE];
96
97
 
@@ -198,6 +198,7 @@
198
198
  --sui-heading-font-weight: var(--sui-font-weight-bold);
199
199
  --sui-heading-line-height: var(--sui-line-height-default);
200
200
  --sui-paragraph-margin: 1.75em;
201
+ --sui-menuitem-font-size: 14px;
201
202
  --sui-control-small-border-width: 1px;
202
203
  --sui-control-small-border-radius: calc(var(--sui-control-small-height) / 8);
203
204
  --sui-control-small-padding: 0 calc((var(--sui-control-small-height) / 5));
@@ -275,6 +276,7 @@
275
276
  @media (pointer: coarse) {
276
277
  :global(:root),
277
278
  :global(:host) {
279
+ --sui-menuitem-height: 40px;
278
280
  --sui-control-small-height: 32px;
279
281
  --sui-control-medium-height: 40px;
280
282
  --sui-control-large-height: 48px;
@@ -189,6 +189,7 @@
189
189
  role="none"
190
190
  class="content {className} {contentType}"
191
191
  class:touch
192
+ class:nested={!!parentDialogElement}
192
193
  style:inset={popupInstance?.style.inset}
193
194
  style:z-index={popupInstance?.style.zIndex}
194
195
  style:min-width={popupInstance?.style.minWidth}
@@ -338,4 +339,10 @@
338
339
  transition-duration: 300ms;
339
340
  opacity: 0;
340
341
  transform: translateY(-8px);
342
+ }
343
+ .content.nested.menu {
344
+ margin-block: calc(-1 * (var(--sui-menu-border-width, 1px) + var(--sui-menu-padding, 4px)));
345
+ }
346
+ :global(dialog.open) .content.nested.menu {
347
+ transform: none;
341
348
  }</style>
@@ -118,9 +118,13 @@ class Popup {
118
118
 
119
119
  this.anchorElement.setAttribute('aria-expanded', 'false');
120
120
 
121
- const removeClickListener = on(anchorElement, 'click', () => {
121
+ const removeClickListener = on(anchorElement, 'click', (event) => {
122
122
  if (!this.isDisabled && !this.isReadOnly) {
123
- this.open = !this.open;
123
+ // A menu item’s submenu may already have been opened by hovering, which also happens right
124
+ // before a tap on a touch screen, so a pointer click only opens it rather than toggling it
125
+ // closed. A scripted click, which has no `detail`, still toggles it: that’s how the
126
+ // keyboard navigation closes a submenu.
127
+ this.open = event.detail && anchorElement.matches('[role="menuitem"]') ? true : !this.open;
124
128
  }
125
129
  });
126
130
 
@@ -281,6 +281,8 @@
281
281
  --sui-heading-font-weight: var(--sui-font-weight-bold);
282
282
  --sui-heading-line-height: var(--sui-line-height-default);
283
283
  --sui-paragraph-margin: 1.75em;
284
+ // Menu
285
+ --sui-menuitem-font-size: 14px;
284
286
  // Controls
285
287
  --sui-control-small-border-width: 1px;
286
288
  --sui-control-small-border-radius: calc(var(--sui-control-small-height) / 8);
@@ -369,6 +371,7 @@
369
371
 
370
372
  // Make controls larger on touch devices, e.g. mobile & tablet
371
373
  @media (pointer: coarse) {
374
+ --sui-menuitem-height: 40px;
372
375
  --sui-control-small-height: 32px;
373
376
  --sui-control-medium-height: 40px;
374
377
  --sui-control-large-height: 48px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.87.0",
3
+ "version": "0.87.2",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,14 +81,14 @@
81
81
  "eslint-config-airbnb-extended": "^3.3.0",
82
82
  "eslint-config-prettier": "^10.1.8",
83
83
  "eslint-plugin-import": "^2.32.0",
84
- "eslint-plugin-jsdoc": "^65.3.8",
84
+ "eslint-plugin-jsdoc": "^65.3.15",
85
85
  "eslint-plugin-package-json": "^1.10.1",
86
86
  "eslint-plugin-svelte": "^3.23.1",
87
87
  "globals": "^17.13.0",
88
88
  "happy-dom": "^21.0.3",
89
89
  "oxlint": "^1.88.0",
90
90
  "playwright": "^1.64.1",
91
- "postcss": "^8.5.30",
91
+ "postcss": "^8.5.31",
92
92
  "postcss-html": "^2.0.0",
93
93
  "prettier": "^3.9.10",
94
94
  "prettier-plugin-svelte": "^4.1.1",