@sveltia/ui 0.34.0 → 0.35.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.
@@ -260,7 +260,8 @@ button.pill {
260
260
  border-radius: 80px;
261
261
  padding: var(--sui-button-medium-pill-padding, 0 12px);
262
262
  }
263
- button.flex {
263
+ button.flex:not([hidden]) {
264
+ display: inline-flex;
264
265
  flex: auto;
265
266
  width: -moz-available;
266
267
  width: -webkit-fill-available;
@@ -23,7 +23,8 @@
23
23
 
24
24
  <div {...restProps} role="none" class="sui spacer {className}" class:flex></div>
25
25
 
26
- <style>.spacer.flex {
26
+ <style>.spacer.flex:not([hidden]) {
27
+ display: block;
27
28
  flex: auto;
28
29
  }
29
30
  .spacer:not(.flex) {
@@ -115,4 +115,7 @@
115
115
  <style>.code-editor {
116
116
  margin: var(--sui-focus-ring-width);
117
117
  width: calc(100% - var(--sui-focus-ring-width) * 2);
118
+ }
119
+ .code-editor.flex:not([hidden]) {
120
+ display: block;
118
121
  }</style>
@@ -128,6 +128,9 @@
128
128
  margin: var(--sui-focus-ring-width);
129
129
  width: calc(100% - var(--sui-focus-ring-width) * 2);
130
130
  }
131
+ .text-editor.flex:not([hidden]) {
132
+ display: block;
133
+ }
131
134
  .text-editor :global(.sui.text-area) {
132
135
  margin: 0 !important;
133
136
  width: 100% !important;
@@ -204,7 +204,8 @@
204
204
  margin: var(--sui-focus-ring-width);
205
205
  min-width: var(--sui-textbox-singleline-min-width);
206
206
  }
207
- .number-input.flex {
207
+ .number-input.flex:not([hidden]) {
208
+ display: inline-flex;
208
209
  width: -moz-available;
209
210
  width: -webkit-fill-available;
210
211
  width: stretch;
@@ -107,7 +107,8 @@
107
107
  margin: var(--sui-focus-ring-width);
108
108
  min-width: var(--sui-textbox-singleline-min-width);
109
109
  }
110
- .password-input.flex {
110
+ .password-input.flex:not([hidden]) {
111
+ display: inline-flex;
111
112
  width: -moz-available;
112
113
  width: -webkit-fill-available;
113
114
  width: stretch;
@@ -121,7 +121,8 @@
121
121
  margin: var(--sui-focus-ring-width);
122
122
  min-width: var(--sui-textbox-singleline-min-width);
123
123
  }
124
- .search-bar.flex {
124
+ .search-bar.flex:not([hidden]) {
125
+ display: inline-flex;
125
126
  width: -moz-available;
126
127
  width: -webkit-fill-available;
127
128
  width: stretch;
@@ -101,7 +101,8 @@
101
101
  margin: var(--sui-focus-ring-width);
102
102
  min-width: var(--sui-textbox-singleline-min-width);
103
103
  }
104
- .secret-input.flex {
104
+ .secret-input.flex:not([hidden]) {
105
+ display: inline-flex;
105
106
  width: -moz-available;
106
107
  width: -webkit-fill-available;
107
108
  width: stretch;
@@ -87,7 +87,8 @@
87
87
  .text-area[hidden] {
88
88
  display: none;
89
89
  }
90
- .text-area.flex {
90
+ .text-area.flex:not([hidden]) {
91
+ display: inline-grid;
91
92
  width: -moz-available;
92
93
  width: -webkit-fill-available;
93
94
  width: stretch;
@@ -31,6 +31,7 @@
31
31
  inputmode = 'text',
32
32
  flex = false,
33
33
  monospace = false,
34
+ debounce = false,
34
35
  class: className,
35
36
  hidden = false,
36
37
  disabled = false,
@@ -39,11 +40,43 @@
39
40
  invalid = false,
40
41
  'aria-label': ariaLabel,
41
42
  children,
43
+ oninput,
42
44
  ...restProps
43
45
  /* eslint-enable prefer-const */
44
46
  } = $props();
45
47
 
46
48
  const id = $props.id();
49
+ const timeout = $derived(typeof debounce === 'number' ? debounce : 300);
50
+
51
+ let debounceTimer = 0;
52
+
53
+ $effect(() => () => {
54
+ clearTimeout(debounceTimer);
55
+ });
56
+
57
+ /**
58
+ * Update the `value` and call the `oninput` callback.
59
+ * @param {InputEvent} event The `input` event object.
60
+ */
61
+ const fireInput = (event) => {
62
+ value = /** @type {HTMLInputElement} */ (event.target).value;
63
+ oninput?.(event);
64
+ };
65
+
66
+ /**
67
+ * Handle the `input` event. If `debounce` is `true`, the event will be debounced by 300ms.
68
+ * @param {InputEvent} event The `input` event object.
69
+ */
70
+ const handleInput = (event) => {
71
+ if (debounce) {
72
+ clearTimeout(debounceTimer);
73
+ debounceTimer = setTimeout(() => {
74
+ fireInput(event);
75
+ }, timeout);
76
+ } else {
77
+ fireInput(event);
78
+ }
79
+ };
47
80
  </script>
48
81
 
49
82
  <div
@@ -58,7 +91,7 @@
58
91
  <input
59
92
  bind:this={element}
60
93
  {...restProps}
61
- bind:value
94
+ {value}
62
95
  type="text"
63
96
  {role}
64
97
  dir="auto"
@@ -73,6 +106,7 @@
73
106
  aria-readonly={readonly}
74
107
  aria-required={required}
75
108
  aria-invalid={invalid}
109
+ oninput={handleInput}
76
110
  use:activateKeyShortcuts={keyShortcuts}
77
111
  />
78
112
  {#if ariaLabel && showInlineLabel}
@@ -91,7 +125,8 @@
91
125
  margin: var(--sui-focus-ring-width);
92
126
  min-width: var(--sui-textbox-singleline-min-width);
93
127
  }
94
- .text-input.flex {
128
+ .text-input.flex:not([hidden]) {
129
+ display: inline-flex;
95
130
  width: -moz-available;
96
131
  width: -webkit-fill-available;
97
132
  width: stretch;
@@ -448,6 +448,13 @@ export type TextInputProps = {
448
448
  * Whether to use a monospace font for the input text.
449
449
  */
450
450
  monospace?: boolean | undefined;
451
+ /**
452
+ * Whether to debounce the `input` event. If `true`, the
453
+ * `input` event will be debounced by 300ms. If a number is provided, it will be used as the
454
+ * debounce delay in milliseconds. This is useful for performance optimization when the input event
455
+ * triggers expensive operations like API calls. Default: `false`.
456
+ */
457
+ debounce?: number | boolean | undefined;
451
458
  /**
452
459
  * The `class` attribute on the wrapper element.
453
460
  */
package/dist/typedefs.js CHANGED
@@ -159,6 +159,10 @@
159
159
  * `inputmode` attribute on the `<input>`.
160
160
  * @property {boolean} [flex] Make the text input container flexible.
161
161
  * @property {boolean} [monospace] Whether to use a monospace font for the input text.
162
+ * @property {boolean | number} [debounce] Whether to debounce the `input` event. If `true`, the
163
+ * `input` event will be debounced by 300ms. If a number is provided, it will be used as the
164
+ * debounce delay in milliseconds. This is useful for performance optimization when the input event
165
+ * triggers expensive operations like API calls. Default: `false`.
162
166
  * @property {string} [class] The `class` attribute on the wrapper element.
163
167
  * @property {boolean} [hidden] Whether to hide the widget.
164
168
  * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@sveltejs/adapter-auto": "^7.0.1",
32
- "@sveltejs/kit": "^2.53.4",
32
+ "@sveltejs/kit": "^2.54.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",
@@ -40,17 +40,17 @@
40
40
  "eslint-plugin-import": "^2.32.0",
41
41
  "eslint-plugin-jsdoc": "^62.7.1",
42
42
  "eslint-plugin-svelte": "^2.46.1",
43
- "oxlint": "^1.51.0",
43
+ "oxlint": "^1.53.0",
44
44
  "postcss": "^8.5.8",
45
45
  "postcss-html": "^1.8.1",
46
46
  "prettier": "^3.8.1",
47
47
  "prettier-plugin-svelte": "^3.5.1",
48
- "sass": "^1.97.3",
48
+ "sass": "^1.98.0",
49
49
  "stylelint": "^17.4.0",
50
50
  "stylelint-config-recommended-scss": "^17.0.0",
51
51
  "stylelint-scss": "^7.0.0",
52
- "svelte": "^5.53.7",
53
- "svelte-check": "^4.4.4",
52
+ "svelte": "^5.53.11",
53
+ "svelte-check": "^4.4.5",
54
54
  "svelte-preprocess": "^6.0.3",
55
55
  "tslib": "^2.8.1",
56
56
  "vite": "^7.3.1",