@sveltia/ui 0.85.1 → 0.86.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.
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { $getRoot as getRoot, HISTORY_MERGE_TAG } from 'lexical';
3
- import { getContext, onMount } from 'svelte';
3
+ import { getContext, onMount, untrack } from 'svelte';
4
4
  import { IMPORT_UPDATE_TAG } from './constants.js';
5
5
  import { handleEditorMouseDown, initEditor } from './core.js';
6
6
 
@@ -133,6 +133,58 @@
133
133
  }
134
134
  };
135
135
 
136
+ // The state is updated within `untrack()` or a microtask below, because the browser fires these
137
+ // events synchronously while it removes a focused element from the DOM, e.g. a nested editor in a
138
+ // component being removed, in the middle of Svelte rendering, where a plain assignment would be
139
+ // reported as an unsafe mutation. See also `<FloatingLinkEditor>`.
140
+
141
+ /**
142
+ * Check if the given element is a dialog other than the one the editor is in, if any, like a menu
143
+ * opened from the toolbar of a nested editor, which is rendered outside the editor.
144
+ * @param {Element | null} dialog Dialog element.
145
+ * @returns {boolean} Result.
146
+ */
147
+ const isOtherDialog = (dialog) => !!dialog && !dialog.contains(lexicalRoot ?? null);
148
+
149
+ /**
150
+ * Track the focus, to tell whether it’s in an editor component, like a nested editor or a field
151
+ * of the component, rather than on the editor itself. The focus moving to another dialog doesn’t
152
+ * change anything.
153
+ * @param {FocusEvent} event `focusin` event.
154
+ */
155
+ const onFocusIn = ({ target }) => {
156
+ const node = /** @type {Node} */ (target);
157
+
158
+ if (lexicalRoot?.contains(node)) {
159
+ untrack(() => {
160
+ editorStore.componentHasFocus = node !== lexicalRoot;
161
+ });
162
+ } else if (!(node instanceof Element && isOtherDialog(node.closest('dialog')))) {
163
+ untrack(() => {
164
+ editorStore.componentHasFocus = false;
165
+ });
166
+ }
167
+ };
168
+
169
+ /**
170
+ * Track the focus leaving a removed element, which doesn’t fire `focusin`. The event also comes
171
+ * without a related target when a dialog opens, which only moves the focus into itself a moment
172
+ * later, so the state is kept while another modal dialog is open.
173
+ * @param {FocusEvent} event `focusout` event.
174
+ */
175
+ const onFocusOut = ({ relatedTarget }) => {
176
+ if (!relatedTarget) {
177
+ queueMicrotask(() => {
178
+ if (
179
+ document.activeElement === document.body &&
180
+ ![...document.querySelectorAll(':modal')].some(isOtherDialog)
181
+ ) {
182
+ editorStore.componentHasFocus = false;
183
+ }
184
+ });
185
+ }
186
+ };
187
+
136
188
  onMount(() => {
137
189
  const { editor, enabledTransformers, dispose } = initEditor(editorStore.config);
138
190
 
@@ -142,6 +194,8 @@
142
194
  lexicalRoot?.addEventListener('Update', onUpdate);
143
195
  lexicalRoot?.addEventListener('click', onClick);
144
196
  lexicalRoot?.addEventListener('mousedown', onMouseDown);
197
+ document.addEventListener('focusin', onFocusIn);
198
+ document.addEventListener('focusout', onFocusOut);
145
199
 
146
200
  // A change made by the user is converted to Markdown a moment later, so report it as pending
147
201
  // until then. An import, or an update that only changes how the content looks, e.g. the code
@@ -163,6 +217,8 @@
163
217
  lexicalRoot?.removeEventListener('Update', onUpdate);
164
218
  lexicalRoot?.removeEventListener('click', onClick);
165
219
  lexicalRoot?.removeEventListener('mousedown', onMouseDown);
220
+ document.removeEventListener('focusin', onFocusIn);
221
+ document.removeEventListener('focusout', onFocusOut);
166
222
  dispose();
167
223
  editor.setRootElement(null);
168
224
  editorStore.initialized = false;
@@ -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.85.1";
4
+ export const UI_VERSION: "0.86.0";
@@ -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.85.1';
6
+ export const UI_VERSION = '0.86.0';
@@ -42,6 +42,8 @@ export const createEditorStore = () => {
42
42
  /** @type {number} */
43
43
  let toolbarHeight = $state(0);
44
44
  /** @type {boolean} */
45
+ let componentHasFocus = $state(false);
46
+ /** @type {boolean} */
45
47
  let hasConverterError = $state(false);
46
48
  /** @type {boolean} */
47
49
  let showConverterError = $state(false);
@@ -188,6 +190,12 @@ export const createEditorStore = () => {
188
190
  set toolbarHeight(newValue) {
189
191
  toolbarHeight = newValue;
190
192
  },
193
+ get componentHasFocus() {
194
+ return componentHasFocus;
195
+ },
196
+ set componentHasFocus(newValue) {
197
+ componentHasFocus = newValue;
198
+ },
191
199
  get useRichText() {
192
200
  return useRichText;
193
201
  },
@@ -128,7 +128,11 @@
128
128
  );
129
129
  </script>
130
130
 
131
- <ToolbarWrapper disabled={disabled || readonly} ariaLabel={_('_sui.text_editor.text_editor')}>
131
+ <!-- Disabled while an editor component has focus, as the buttons only apply to this editor -->
132
+ <ToolbarWrapper
133
+ disabled={disabled || readonly || editorStore.componentHasFocus}
134
+ ariaLabel={_('_sui.text_editor.text_editor')}
135
+ >
132
136
  {#if canChangeBlock && blockLevelButtons.length > 1}
133
137
  <MenuButton
134
138
  aria-label={_('_sui.text_editor.show_text_style_options')}
@@ -76,6 +76,9 @@
76
76
  min-height: 40px;
77
77
  background-color: var(--sui-tertiary-background-color);
78
78
  }
79
+ .wrapper :global([role=toolbar][aria-disabled=true]) {
80
+ filter: none;
81
+ }
79
82
  .wrapper :global(.sui.menu-button) {
80
83
  padding: 0 4px;
81
84
  }
@@ -7,12 +7,16 @@
7
7
 
8
8
  /**
9
9
  * @typedef {object} Props
10
+ * @property {boolean} [eager] Whether to render the content right away rather than once it comes
11
+ * into view, such as an item just added to a list, which is then scrolled into view and focused.
12
+ * Only the value at mount is used, as the content stays rendered anyway.
10
13
  * @property {Snippet} children Slot content.
11
14
  */
12
15
 
13
16
  /** @type {Props} */
14
17
  let {
15
18
  /* eslint-disable prefer-const */
19
+ eager = false,
16
20
  children,
17
21
  /* eslint-enable prefer-const */
18
22
  } = $props();
@@ -20,7 +24,8 @@
20
24
  /** @type {HTMLElement | null} */
21
25
  let placeholder = $state(null);
22
26
  /** @type {boolean} */
23
- let visible = $state(false);
27
+ // svelte-ignore state_referenced_locally
28
+ let visible = $state(eager);
24
29
 
25
30
  $effect(() => {
26
31
  if (placeholder) {
@@ -4,12 +4,24 @@ type VisibilityObserver = {
4
4
  $set?(props: Partial<Props>): void;
5
5
  };
6
6
  declare const VisibilityObserver: import("svelte").Component<{
7
+ /**
8
+ * Whether to render the content right away rather than once it comes
9
+ * into view, such as an item just added to a list, which is then scrolled into view and focused.
10
+ * Only the value at mount is used, as the content stays rendered anyway.
11
+ */
12
+ eager?: boolean | undefined;
7
13
  /**
8
14
  * Slot content.
9
15
  */
10
16
  children: Snippet;
11
17
  }, {}, "">;
12
18
  type Props = {
19
+ /**
20
+ * Whether to render the content right away rather than once it comes
21
+ * into view, such as an item just added to a list, which is then scrolled into view and focused.
22
+ * Only the value at mount is used, as the content stays rendered anyway.
23
+ */
24
+ eager?: boolean | undefined;
13
25
  /**
14
26
  * Slot content.
15
27
  */
@@ -0,0 +1,174 @@
1
+ # Dialog action button labels
2
+ ok: OK
3
+ cancel: Cancel
4
+ close: Close
5
+
6
+ # Button to clear content, e.g. search input or calendar date
7
+ clear: Clear
8
+
9
+ # Text editor dialog buttons for link/image insertion
10
+ insert: Insert
11
+ update: Update
12
+ remove: Remove
13
+
14
+ # Combobox dropdown toggle button aria-labels
15
+ collapse: Collapse
16
+ expand: Expand
17
+
18
+ # Infobar/toast dismiss button label
19
+ dismiss: Dismiss
20
+
21
+ # Alert & infobar status, read out by screen readers before the message (visually hidden)
22
+ alert:
23
+ error: Error
24
+ warning: Warning
25
+ info: Information
26
+ success: Success
27
+
28
+ # Role descriptions, read out by screen readers in place of the generic “group” role
29
+ role_descriptions:
30
+ disclosure: disclosure
31
+ option_group: option group
32
+ menu_item_group: menu item group
33
+ checkbox_group: checkbox group
34
+ table_head: table head
35
+ table_body: table body
36
+ table_foot: table foot
37
+ grid_head: grid head
38
+ grid_body: grid body
39
+ grid_foot: grid foot
40
+
41
+ # Emoji suggestion listbox aria-label, shared by the text fields and the text editor
42
+ emoji_suggestions: Emoji Suggestions
43
+
44
+ # Calendar component
45
+ calendar:
46
+ # View switcher group aria-labels and navigation button aria-labels
47
+ year: Year
48
+ previous_decade: Previous Decade
49
+ next_decade: Next Decade
50
+ month: Month
51
+ previous_month: Previous Month
52
+ next_month: Next Month
53
+ # “Today” button label in footer
54
+ today: Today
55
+
56
+ # Split button component
57
+ split_button:
58
+ # Wrapper aria-label, e.g. “Save Options” when primary button is “Save”
59
+ x_options: '{$name} Options'
60
+ # Dropdown toggle aria-label
61
+ more_options: More Options
62
+
63
+ # Combobox component
64
+ combobox:
65
+ # Placeholder when no option is selected
66
+ select_an_option: Select an option…
67
+ # Filter input aria-label
68
+ filter_options: Filter Options
69
+ # Empty state message when filter has no matches
70
+ no_matching_options: No matching options found
71
+
72
+ # Number input component
73
+ number_input:
74
+ # Spin button aria-labels for incrementing/decrementing the number value
75
+ increase: Increase
76
+ decrease: Decrease
77
+ # Description of the allowed range when the number can’t be stepped, e.g. “From 1 to 10”
78
+ range: From {$min} to {$max}
79
+ # Description of the minimum value when the number can’t be stepped
80
+ min: Minimum {$min}
81
+ # Description of the maximum value when the number can’t be stepped
82
+ max: Maximum {$max}
83
+
84
+ # Password input component
85
+ password_input:
86
+ # Visibility toggle button aria-labels
87
+ show_password: Show Password
88
+ hide_password: Hide Password
89
+
90
+ # Secret input component (API keys, tokens, etc.)
91
+ secret_input:
92
+ # Visibility toggle button aria-labels
93
+ show_secret: Show Secret
94
+ hide_secret: Hide Secret
95
+
96
+ # Select tags component (multi-select)
97
+ select_tags:
98
+ # Listbox aria-label
99
+ selected_options: Selected Options
100
+ # Remove button aria-label, e.g. “Remove Option 1”
101
+ remove_x: Remove {$name}
102
+
103
+ # Text editor component
104
+ text_editor:
105
+ # Toolbar aria-labels
106
+ text_editor: Text Editor
107
+ code_editor: Code Editor
108
+ # Block style menu button and menu aria-labels
109
+ text_style_options: Text Style Options
110
+ show_text_style_options: Show Text Style Options
111
+ # Block style menu items
112
+ paragraph: Paragraph
113
+ heading_1: Heading 1
114
+ heading_2: Heading 2
115
+ heading_3: Heading 3
116
+ heading_4: Heading 4
117
+ heading_5: Heading 5
118
+ heading_6: Heading 6
119
+ bulleted_list: Bulleted List
120
+ numbered_list: Numbered List
121
+ blockquote: Block Quote
122
+ code_block: Code Block
123
+ # Inline style button aria-labels
124
+ bold: Bold
125
+ italic: Italic
126
+ strikethrough: Strikethrough
127
+ code: Code
128
+ link: Link
129
+ # Link dialog title
130
+ insert_link: Insert Link
131
+ # Floating link editor button aria-labels
132
+ edit_link: Edit Link
133
+ remove_link: Remove Link
134
+ # Link dialog input field labels
135
+ text: Text
136
+ url: URL
137
+ # Link dialog checkbox label and floating link editor button aria-label
138
+ open_in_new_tab: Open in New Tab
139
+ # Table dialog title
140
+ insert_table: Insert Table
141
+ # Table dialog input field labels
142
+ rows: Rows
143
+ columns: Columns
144
+ # Table menu button and menu aria-labels
145
+ table_options: Table Options
146
+ show_table_options: Show Table Options
147
+ # Table menu items
148
+ insert_row_above: Insert Row Above
149
+ insert_row_below: Insert Row Below
150
+ insert_column_left: Insert Column Left
151
+ insert_column_right: Insert Column Right
152
+ delete_row: Delete Row
153
+ delete_column: Delete Column
154
+ delete_table: Delete Table
155
+ # Horizontal rule button aria-label
156
+ insert_horizontal_rule: Insert Horizontal Rule
157
+ # Alignment menu button and menu aria-labels
158
+ alignment_options: Alignment Options
159
+ show_alignment_options: Show Alignment Options
160
+ # Alignment menu items
161
+ align_left: Left Align
162
+ align_center: Centre Align
163
+ align_right: Right Align
164
+ align_justify: Justify Align
165
+ # Markdown mode toggle button aria-label
166
+ edit_in_markdown: Edit in Markdown
167
+ # HTML mode toggle button aria-label
168
+ edit_in_html: Edit in HTML
169
+ # Error message when rich text conversion fails
170
+ converter_error: Unable to enable rich text mode. Please use the plain text editor instead.
171
+ # Language selector aria-label
172
+ language: Language
173
+ # Plain text mode option in language selector
174
+ plain_text: Plain Text
@@ -1053,6 +1053,12 @@ export type TextEditorStore = {
1053
1053
  * nested editors are placed below. `0` while the toolbar isn’t rendered.
1054
1054
  */
1055
1055
  toolbarHeight: number;
1056
+ /**
1057
+ * Whether the focus is in an editor component within the
1058
+ * content, like a nested editor or a field of the component, rather than on the editor itself. The
1059
+ * toolbar is disabled meanwhile, as it would only apply to the editor itself.
1060
+ */
1061
+ componentHasFocus: boolean;
1056
1062
  /**
1057
1063
  * ID of the editable element currently shown: the Lexical root in the
1058
1064
  * rich text mode, or the `<textarea>` in the plain text mode.
package/dist/typedefs.js CHANGED
@@ -457,6 +457,9 @@
457
457
  * mode.
458
458
  * @property {number} toolbarHeight Height of the sticky toolbar in pixels, which the toolbars of
459
459
  * nested editors are placed below. `0` while the toolbar isn’t rendered.
460
+ * @property {boolean} componentHasFocus Whether the focus is in an editor component within the
461
+ * content, like a nested editor or a field of the component, rather than on the editor itself. The
462
+ * toolbar is disabled meanwhile, as it would only apply to the editor itself.
460
463
  * @property {string} controlId ID of the editable element currently shown: the Lexical root in the
461
464
  * rich text mode, or the `<textarea>` in the plain text mode.
462
465
  * @property {boolean} hasConverterError Whether there was an error while converting Markdown or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.85.1",
3
+ "version": "0.86.0",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,13 +81,13 @@
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.2",
84
+ "eslint-plugin-jsdoc": "^65.3.4",
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.1",
89
89
  "oxlint": "^1.88.0",
90
- "playwright": "^1.64.0",
90
+ "playwright": "^1.64.1",
91
91
  "postcss": "^8.5.30",
92
92
  "postcss-html": "^2.0.0",
93
93
  "prettier": "^3.9.10",