sh3-core 0.13.0 → 0.13.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.
Files changed (120) hide show
  1. package/dist/BrandSlot.svelte +62 -13
  2. package/dist/__test__/setup-dom.js +5 -0
  3. package/dist/api.d.ts +3 -0
  4. package/dist/api.js +3 -0
  5. package/dist/apps/lifecycle.js +10 -2
  6. package/dist/apps/types.d.ts +11 -4
  7. package/dist/apps/workspace-rekey.d.ts +1 -0
  8. package/dist/apps/workspace-rekey.js +35 -0
  9. package/dist/apps/workspace-rekey.test.js +23 -0
  10. package/dist/auth/admin-users.svelte.d.ts +9 -0
  11. package/dist/auth/admin-users.svelte.js +42 -0
  12. package/dist/auth/admin-users.test.d.ts +1 -0
  13. package/dist/auth/admin-users.test.js +52 -0
  14. package/dist/createShell.js +5 -5
  15. package/dist/documents/config.d.ts +5 -1
  16. package/dist/documents/config.js +16 -8
  17. package/dist/documents/index.d.ts +1 -1
  18. package/dist/documents/index.js +1 -1
  19. package/dist/host-entry.d.ts +1 -1
  20. package/dist/host-entry.js +1 -1
  21. package/dist/host.d.ts +1 -1
  22. package/dist/host.js +8 -2
  23. package/dist/primitives/Button.svelte +50 -4
  24. package/dist/primitives/Button.svelte.d.ts +3 -1
  25. package/dist/primitives/Collapsible.svelte +110 -0
  26. package/dist/primitives/Collapsible.svelte.d.ts +14 -0
  27. package/dist/primitives/widgets/AppPicker.svelte +41 -0
  28. package/dist/primitives/widgets/AppPicker.svelte.d.ts +9 -0
  29. package/dist/primitives/widgets/AppPicker.svelte.test.d.ts +1 -0
  30. package/dist/primitives/widgets/AppPicker.svelte.test.js +26 -0
  31. package/dist/primitives/widgets/AppPicker.test.d.ts +1 -0
  32. package/dist/primitives/widgets/AppPicker.test.js +74 -0
  33. package/dist/primitives/widgets/ColorSwatch.svelte +7 -2
  34. package/dist/primitives/widgets/ColorSwatch.svelte.d.ts +2 -1
  35. package/dist/primitives/widgets/ColorSwatch.svelte.test.d.ts +1 -0
  36. package/dist/primitives/widgets/ColorSwatch.svelte.test.js +31 -0
  37. package/dist/primitives/widgets/Field.svelte +6 -1
  38. package/dist/primitives/widgets/Field.svelte.d.ts +2 -1
  39. package/dist/primitives/widgets/Field.svelte.test.d.ts +1 -0
  40. package/dist/primitives/widgets/Field.svelte.test.js +33 -0
  41. package/dist/primitives/widgets/FilePicker.svelte +6 -3
  42. package/dist/primitives/widgets/FilePicker.svelte.d.ts +2 -1
  43. package/dist/primitives/widgets/FilePicker.svelte.test.d.ts +1 -0
  44. package/dist/primitives/widgets/FilePicker.svelte.test.js +31 -0
  45. package/dist/primitives/widgets/IconToggleGroup.svelte +6 -3
  46. package/dist/primitives/widgets/IconToggleGroup.svelte.d.ts +3 -2
  47. package/dist/primitives/widgets/IconToggleGroup.svelte.test.d.ts +1 -0
  48. package/dist/primitives/widgets/IconToggleGroup.svelte.test.js +40 -0
  49. package/dist/primitives/widgets/NumberInput.svelte +26 -7
  50. package/dist/primitives/widgets/NumberInput.svelte.d.ts +2 -1
  51. package/dist/primitives/widgets/NumberInput.svelte.test.d.ts +1 -0
  52. package/dist/primitives/widgets/NumberInput.svelte.test.js +48 -0
  53. package/dist/primitives/widgets/PickerList.d.ts +24 -0
  54. package/dist/primitives/widgets/PickerList.js +21 -0
  55. package/dist/primitives/widgets/PickerList.svelte +150 -0
  56. package/dist/primitives/widgets/PickerList.svelte.d.ts +16 -0
  57. package/dist/primitives/widgets/PickerList.svelte.test.d.ts +1 -0
  58. package/dist/primitives/widgets/PickerList.svelte.test.js +31 -0
  59. package/dist/primitives/widgets/PickerList.test.d.ts +1 -0
  60. package/dist/primitives/widgets/PickerList.test.js +218 -0
  61. package/dist/primitives/widgets/RangeSlider.svelte +16 -5
  62. package/dist/primitives/widgets/RangeSlider.svelte.d.ts +2 -1
  63. package/dist/primitives/widgets/RangeSlider.svelte.test.d.ts +1 -0
  64. package/dist/primitives/widgets/RangeSlider.svelte.test.js +38 -0
  65. package/dist/primitives/widgets/Segmented.svelte +12 -5
  66. package/dist/primitives/widgets/Segmented.svelte.d.ts +3 -2
  67. package/dist/primitives/widgets/Segmented.svelte.test.d.ts +1 -0
  68. package/dist/primitives/widgets/Segmented.svelte.test.js +25 -0
  69. package/dist/primitives/widgets/Select.svelte +7 -3
  70. package/dist/primitives/widgets/Select.svelte.d.ts +3 -2
  71. package/dist/primitives/widgets/Select.svelte.test.d.ts +1 -0
  72. package/dist/primitives/widgets/Select.svelte.test.js +37 -0
  73. package/dist/primitives/widgets/Slider.svelte +6 -1
  74. package/dist/primitives/widgets/Slider.svelte.d.ts +2 -1
  75. package/dist/primitives/widgets/Slider.svelte.test.d.ts +1 -0
  76. package/dist/primitives/widgets/Slider.svelte.test.js +22 -0
  77. package/dist/primitives/widgets/SliderGroup.svelte +6 -1
  78. package/dist/primitives/widgets/SliderGroup.svelte.d.ts +2 -1
  79. package/dist/primitives/widgets/SliderGroup.svelte.test.d.ts +1 -0
  80. package/dist/primitives/widgets/SliderGroup.svelte.test.js +34 -0
  81. package/dist/primitives/widgets/Textarea.svelte +7 -1
  82. package/dist/primitives/widgets/Textarea.svelte.d.ts +2 -1
  83. package/dist/primitives/widgets/Textarea.svelte.test.d.ts +1 -0
  84. package/dist/primitives/widgets/Textarea.svelte.test.js +29 -0
  85. package/dist/primitives/widgets/UserPicker.svelte +53 -0
  86. package/dist/primitives/widgets/UserPicker.svelte.d.ts +9 -0
  87. package/dist/primitives/widgets/UserPicker.svelte.test.d.ts +1 -0
  88. package/dist/primitives/widgets/UserPicker.svelte.test.js +30 -0
  89. package/dist/primitives/widgets/UserPicker.test.d.ts +1 -0
  90. package/dist/primitives/widgets/UserPicker.test.js +115 -0
  91. package/dist/primitives/widgets/_contract.d.ts +27 -0
  92. package/dist/primitives/widgets/_contract.js +10 -0
  93. package/dist/projects/session-state.svelte.d.ts +17 -0
  94. package/dist/projects/session-state.svelte.js +39 -0
  95. package/dist/projects/session-state.test.d.ts +1 -0
  96. package/dist/projects/session-state.test.js +55 -0
  97. package/dist/projects-shard/DeleteProjectDialog.svelte +150 -0
  98. package/dist/projects-shard/DeleteProjectDialog.svelte.d.ts +12 -0
  99. package/dist/projects-shard/DeleteProjectDialog.test.d.ts +1 -0
  100. package/dist/projects-shard/DeleteProjectDialog.test.js +120 -0
  101. package/dist/projects-shard/ProjectManage.svelte +209 -0
  102. package/dist/projects-shard/ProjectManage.svelte.d.ts +8 -0
  103. package/dist/projects-shard/ProjectsSection.svelte +120 -0
  104. package/dist/projects-shard/ProjectsSection.svelte.d.ts +3 -0
  105. package/dist/projects-shard/index.d.ts +4 -0
  106. package/dist/projects-shard/index.js +4 -0
  107. package/dist/projects-shard/projectsApi.d.ts +20 -0
  108. package/dist/projects-shard/projectsApi.js +44 -0
  109. package/dist/projects-shard/projectsApi.test.d.ts +1 -0
  110. package/dist/projects-shard/projectsApi.test.js +71 -0
  111. package/dist/projects-shard/projectsShard.svelte.d.ts +10 -0
  112. package/dist/projects-shard/projectsShard.svelte.js +148 -0
  113. package/dist/sh3core-shard/ShellHome.svelte +19 -1
  114. package/dist/shards/activate-scopeid.test.d.ts +1 -0
  115. package/dist/shards/{activate-tenantid.test.js → activate-scopeid.test.js} +6 -6
  116. package/dist/tokens.css +4 -2
  117. package/dist/version.d.ts +1 -1
  118. package/dist/version.js +1 -1
  119. package/package.json +1 -1
  120. /package/dist/{shards/activate-tenantid.test.d.ts → apps/workspace-rekey.test.d.ts} +0 -0
@@ -0,0 +1,218 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { mount, unmount, tick } from 'svelte';
3
+ import PickerList from './PickerList.svelte';
4
+ import { filterItems, toggle } from './PickerList';
5
+ let host;
6
+ let cmp = null;
7
+ beforeEach(() => {
8
+ host = document.createElement('div');
9
+ document.body.appendChild(host);
10
+ });
11
+ afterEach(() => {
12
+ if (cmp) {
13
+ unmount(cmp);
14
+ cmp = null;
15
+ }
16
+ host.remove();
17
+ });
18
+ describe('filterItems', () => {
19
+ const items = [
20
+ { id: 'notes', label: 'Notes', sublabel: 'note-taking' },
21
+ { id: 'files', label: 'Files' },
22
+ { id: 'tasks', label: 'Task Manager' },
23
+ ];
24
+ it('returns everything when query is empty', () => {
25
+ expect(filterItems(items, '')).toEqual(items);
26
+ });
27
+ it('matches by label case-insensitively', () => {
28
+ expect(filterItems(items, 'note').map((i) => i.id)).toEqual(['notes']);
29
+ expect(filterItems(items, 'TASK').map((i) => i.id)).toEqual(['tasks']);
30
+ });
31
+ it('matches by id', () => {
32
+ expect(filterItems(items, 'fil').map((i) => i.id)).toEqual(['files']);
33
+ });
34
+ it('matches by sublabel', () => {
35
+ expect(filterItems(items, 'taking').map((i) => i.id)).toEqual(['notes']);
36
+ });
37
+ it('returns empty when nothing matches', () => {
38
+ expect(filterItems(items, 'zzz')).toEqual([]);
39
+ });
40
+ });
41
+ describe('toggle', () => {
42
+ it('adds an id when missing', () => {
43
+ expect(toggle(['a'], 'b')).toEqual(['a', 'b']);
44
+ });
45
+ it('removes an id when present', () => {
46
+ expect(toggle(['a', 'b'], 'a')).toEqual(['b']);
47
+ });
48
+ it('returns a new array (does not mutate)', () => {
49
+ const v = ['a'];
50
+ const next = toggle(v, 'b');
51
+ expect(v).toEqual(['a']);
52
+ expect(next).not.toBe(v);
53
+ });
54
+ });
55
+ describe('PickerList — rendering', () => {
56
+ function makeItems(n) {
57
+ return Array.from({ length: n }, (_, i) => ({ id: `id-${i}`, label: `Item ${i}` }));
58
+ }
59
+ it('renders one checkbox row per item', async () => {
60
+ cmp = mount(PickerList, {
61
+ target: host,
62
+ props: { items: makeItems(3), value: [] },
63
+ });
64
+ await tick();
65
+ const rows = host.querySelectorAll('.sh3-picker__row');
66
+ expect(rows.length).toBe(3);
67
+ const checks = host.querySelectorAll('input[type="checkbox"]');
68
+ expect(checks.length).toBe(3);
69
+ expect(Array.from(checks).every((c) => !c.checked)).toBe(true);
70
+ });
71
+ it('reflects value as checked rows', async () => {
72
+ cmp = mount(PickerList, {
73
+ target: host,
74
+ props: { items: makeItems(3), value: ['id-1'] },
75
+ });
76
+ await tick();
77
+ const checks = host.querySelectorAll('input[type="checkbox"]');
78
+ expect(checks[0].checked).toBe(false);
79
+ expect(checks[1].checked).toBe(true);
80
+ expect(checks[2].checked).toBe(false);
81
+ });
82
+ it('hides the search input when items.length < threshold (default 8)', async () => {
83
+ cmp = mount(PickerList, {
84
+ target: host,
85
+ props: { items: makeItems(7), value: [] },
86
+ });
87
+ await tick();
88
+ expect(host.querySelector('.sh3-picker__search')).toBeNull();
89
+ });
90
+ it('shows the search input when items.length >= threshold', async () => {
91
+ cmp = mount(PickerList, {
92
+ target: host,
93
+ props: { items: makeItems(8), value: [] },
94
+ });
95
+ await tick();
96
+ expect(host.querySelector('.sh3-picker__search')).not.toBeNull();
97
+ });
98
+ it('shows "Loading…" and hides the list when loading=true', async () => {
99
+ cmp = mount(PickerList, {
100
+ target: host,
101
+ props: { items: makeItems(2), value: [], loading: true },
102
+ });
103
+ await tick();
104
+ expect(host.textContent).toContain('Loading');
105
+ expect(host.querySelectorAll('.sh3-picker__row').length).toBe(0);
106
+ });
107
+ it('shows the error message and a Retry button when error is set', async () => {
108
+ let retried = false;
109
+ cmp = mount(PickerList, {
110
+ target: host,
111
+ props: {
112
+ items: [],
113
+ value: [],
114
+ error: 'boom',
115
+ onRetry: () => { retried = true; },
116
+ },
117
+ });
118
+ await tick();
119
+ expect(host.textContent).toContain('boom');
120
+ const retryBtn = host.querySelector('.sh3-picker__retry');
121
+ expect(retryBtn).not.toBeNull();
122
+ retryBtn.click();
123
+ expect(retried).toBe(true);
124
+ });
125
+ it('shows emptyText when items is empty and not loading/erroring', async () => {
126
+ cmp = mount(PickerList, {
127
+ target: host,
128
+ props: { items: [], value: [], emptyText: 'No widgets.' },
129
+ });
130
+ await tick();
131
+ expect(host.textContent).toContain('No widgets.');
132
+ });
133
+ it('shows the selected count in the footer', async () => {
134
+ cmp = mount(PickerList, {
135
+ target: host,
136
+ props: { items: makeItems(4), value: ['id-0', 'id-2'] },
137
+ });
138
+ await tick();
139
+ expect(host.textContent).toMatch(/2 of 4 selected/);
140
+ });
141
+ });
142
+ describe('PickerList — interaction', () => {
143
+ function makeItems(n) {
144
+ return Array.from({ length: n }, (_, i) => ({ id: `id-${i}`, label: `Item ${i}` }));
145
+ }
146
+ it('clicking a row fires onchange with the new array', async () => {
147
+ let received = null;
148
+ cmp = mount(PickerList, {
149
+ target: host,
150
+ props: {
151
+ items: makeItems(3),
152
+ value: [],
153
+ onchange: (next) => { received = next; },
154
+ },
155
+ });
156
+ await tick();
157
+ const checks = host.querySelectorAll('input[type="checkbox"]');
158
+ checks[1].click();
159
+ await tick();
160
+ expect(received).toEqual(['id-1']);
161
+ });
162
+ it('toggling an already-selected row removes it', async () => {
163
+ let received = null;
164
+ cmp = mount(PickerList, {
165
+ target: host,
166
+ props: {
167
+ items: makeItems(3),
168
+ value: ['id-1'],
169
+ onchange: (next) => { received = next; },
170
+ },
171
+ });
172
+ await tick();
173
+ const checks = host.querySelectorAll('input[type="checkbox"]');
174
+ checks[1].click();
175
+ await tick();
176
+ expect(received).toEqual([]);
177
+ });
178
+ it('disabled blocks input', async () => {
179
+ cmp = mount(PickerList, {
180
+ target: host,
181
+ props: {
182
+ items: makeItems(2),
183
+ value: [],
184
+ disabled: true,
185
+ },
186
+ });
187
+ await tick();
188
+ const checks = host.querySelectorAll('input[type="checkbox"]');
189
+ expect(checks[0].disabled).toBe(true);
190
+ });
191
+ it('typing in the search input filters the rendered rows but keeps value', async () => {
192
+ cmp = mount(PickerList, {
193
+ target: host,
194
+ props: {
195
+ items: [
196
+ { id: 'notes', label: 'Notes' },
197
+ { id: 'files', label: 'Files' },
198
+ { id: 'tasks', label: 'Tasks' },
199
+ { id: 'photos', label: 'Photos' },
200
+ { id: 'mail', label: 'Mail' },
201
+ { id: 'maps', label: 'Maps' },
202
+ { id: 'calc', label: 'Calculator' },
203
+ { id: 'paint', label: 'Paint' },
204
+ ],
205
+ value: ['mail'],
206
+ },
207
+ });
208
+ await tick();
209
+ const search = host.querySelector('.sh3-picker__search');
210
+ expect(search).not.toBeNull();
211
+ search.value = 'note';
212
+ search.dispatchEvent(new Event('input', { bubbles: true }));
213
+ await tick();
214
+ const rows = host.querySelectorAll('.sh3-picker__row');
215
+ expect(rows.length).toBe(1);
216
+ expect(rows[0].textContent).toContain('Notes');
217
+ });
218
+ });
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import type { LiveInputEvents } from './_contract';
2
3
  import { valueToPercent } from './Slider';
3
4
  import { constrainPair, type Pair } from './RangeSlider';
4
5
 
@@ -10,6 +11,8 @@
10
11
  disabled = false,
11
12
  invalid = false,
12
13
  size = 'md',
14
+ oninput,
15
+ onchange,
13
16
  }: {
14
17
  value?: Pair;
15
18
  min?: number;
@@ -18,13 +21,19 @@
18
21
  disabled?: boolean;
19
22
  invalid?: boolean;
20
23
  size?: 'sm' | 'md';
21
- } = $props();
24
+ } & LiveInputEvents<Pair> = $props();
22
25
 
23
26
  const lowPct = $derived(valueToPercent(value[0], min, max));
24
27
  const highPct = $derived(valueToPercent(value[1], min, max));
25
28
 
26
- function setLow(n: number) { value = constrainPair(value, 'low', n); }
27
- function setHigh(n: number) { value = constrainPair(value, 'high', n); }
29
+ function setLow(n: number) {
30
+ value = constrainPair(value, 'low', n);
31
+ oninput?.(value);
32
+ }
33
+ function setHigh(n: number) {
34
+ value = constrainPair(value, 'high', n);
35
+ oninput?.(value);
36
+ }
28
37
  </script>
29
38
 
30
39
  <div class="sh3-range" class:sh3-range--sm={size === 'sm'} class:sh3-range--invalid={invalid}>
@@ -36,11 +45,13 @@
36
45
  <input type="range" class="sh3-range__native sh3-range__native--low"
37
46
  {min} {max} {step} {disabled}
38
47
  value={value[0]}
39
- oninput={(e) => setLow(parseFloat((e.currentTarget as HTMLInputElement).value))} />
48
+ oninput={(e) => setLow(parseFloat((e.currentTarget as HTMLInputElement).value))}
49
+ onchange={() => onchange?.(value)} />
40
50
  <input type="range" class="sh3-range__native sh3-range__native--high"
41
51
  {min} {max} {step} {disabled}
42
52
  value={value[1]}
43
- oninput={(e) => setHigh(parseFloat((e.currentTarget as HTMLInputElement).value))} />
53
+ oninput={(e) => setHigh(parseFloat((e.currentTarget as HTMLInputElement).value))}
54
+ onchange={() => onchange?.(value)} />
44
55
  </div>
45
56
 
46
57
  <style>
@@ -1,3 +1,4 @@
1
+ import type { LiveInputEvents } from './_contract';
1
2
  import { type Pair } from './RangeSlider';
2
3
  type $$ComponentProps = {
3
4
  value?: Pair;
@@ -7,7 +8,7 @@ type $$ComponentProps = {
7
8
  disabled?: boolean;
8
9
  invalid?: boolean;
9
10
  size?: 'sm' | 'md';
10
- };
11
+ } & LiveInputEvents<Pair>;
11
12
  declare const RangeSlider: import("svelte").Component<$$ComponentProps, {}, "value">;
12
13
  type RangeSlider = ReturnType<typeof RangeSlider>;
13
14
  export default RangeSlider;
@@ -0,0 +1,38 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import RangeSlider from './RangeSlider.svelte';
4
+ describe('RangeSlider event contract', () => {
5
+ it('fires oninput per thumb with constrained pair', async () => {
6
+ const oninput = vi.fn();
7
+ const { container } = render(RangeSlider, {
8
+ props: { value: [10, 90], min: 0, max: 100, oninput },
9
+ });
10
+ const lows = container.querySelectorAll('input[type=range]');
11
+ const low = lows[0];
12
+ await fireEvent.input(low, { target: { value: '20' } });
13
+ expect(oninput).toHaveBeenCalledTimes(1);
14
+ const lastCall = oninput.mock.calls[oninput.mock.calls.length - 1][0];
15
+ expect(lastCall).toEqual([20, 90]);
16
+ });
17
+ it('fires onchange per thumb on change event', async () => {
18
+ const onchange = vi.fn();
19
+ const { container } = render(RangeSlider, {
20
+ props: { value: [10, 90], min: 0, max: 100, onchange },
21
+ });
22
+ const high = container.querySelectorAll('input[type=range]')[1];
23
+ await fireEvent.input(high, { target: { value: '80' } });
24
+ await fireEvent.change(high, { target: { value: '80' } });
25
+ expect(onchange).toHaveBeenCalledTimes(1);
26
+ expect(onchange.mock.calls[0][0]).toEqual([10, 80]);
27
+ });
28
+ it('thumbs cannot cross', async () => {
29
+ const oninput = vi.fn();
30
+ const { container } = render(RangeSlider, {
31
+ props: { value: [10, 90], min: 0, max: 100, oninput },
32
+ });
33
+ const low = container.querySelectorAll('input[type=range]')[0];
34
+ await fireEvent.input(low, { target: { value: '99' } });
35
+ const lastCall = oninput.mock.calls[oninput.mock.calls.length - 1][0];
36
+ expect(lastCall[0]).toBeLessThanOrEqual(lastCall[1]);
37
+ });
38
+ });
@@ -1,17 +1,24 @@
1
1
  <script lang="ts">
2
+ import type { CommitOnlyEvents } from './_contract';
2
3
  import { type SegmentedOption, nextValue, prevValue, firstValue, lastValue } from './Segmented';
3
4
 
4
5
  let {
5
6
  options,
6
- value = $bindable(),
7
+ value = $bindable(options[0]?.value ?? ''),
7
8
  size = 'md',
8
9
  disabled = false,
10
+ onchange,
9
11
  }: {
10
12
  options: SegmentedOption[];
11
- value: string;
13
+ value?: string;
12
14
  size?: 'sm' | 'md';
13
15
  disabled?: boolean;
14
- } = $props();
16
+ } & CommitOnlyEvents<string> = $props();
17
+
18
+ function commit(next: string) {
19
+ value = next;
20
+ onchange?.(next);
21
+ }
15
22
 
16
23
  function onKey(e: KeyboardEvent) {
17
24
  if (disabled) return;
@@ -24,7 +31,7 @@
24
31
  default: return;
25
32
  }
26
33
  e.preventDefault();
27
- if (next !== undefined) value = next;
34
+ if (next !== undefined) commit(next);
28
35
  }
29
36
  </script>
30
37
 
@@ -37,7 +44,7 @@
37
44
  tabindex={value === opt.value ? 0 : -1}
38
45
  disabled={disabled || opt.disabled}
39
46
  class:sh3-seg__btn--active={value === opt.value}
40
- onclick={() => { if (!opt.disabled && !disabled) value = opt.value; }}
47
+ onclick={() => { if (!opt.disabled && !disabled) commit(opt.value); }}
41
48
  >{opt.label}</button>
42
49
  {/each}
43
50
  </div>
@@ -1,10 +1,11 @@
1
+ import type { CommitOnlyEvents } from './_contract';
1
2
  import { type SegmentedOption } from './Segmented';
2
3
  type $$ComponentProps = {
3
4
  options: SegmentedOption[];
4
- value: string;
5
+ value?: string;
5
6
  size?: 'sm' | 'md';
6
7
  disabled?: boolean;
7
- };
8
+ } & CommitOnlyEvents<string>;
8
9
  declare const Segmented: import("svelte").Component<$$ComponentProps, {}, "value">;
9
10
  type Segmented = ReturnType<typeof Segmented>;
10
11
  export default Segmented;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import Segmented from './Segmented.svelte';
4
+ describe('Segmented event contract', () => {
5
+ const options = [
6
+ { value: 'a', label: 'A' },
7
+ { value: 'b', label: 'B' },
8
+ { value: 'c', label: 'C' },
9
+ ];
10
+ it('fires onchange once on click', async () => {
11
+ const onchange = vi.fn();
12
+ const { getByText } = render(Segmented, { props: { options, value: 'a', onchange } });
13
+ await fireEvent.click(getByText('B'));
14
+ expect(onchange).toHaveBeenCalledTimes(1);
15
+ expect(onchange).toHaveBeenCalledWith('b');
16
+ });
17
+ it('defaults value to first option when not passed', () => {
18
+ const { container } = render(Segmented, { props: { options } });
19
+ const active = container.querySelector('.sh3-seg__btn--active');
20
+ expect(active === null || active === void 0 ? void 0 : active.textContent).toBe('A');
21
+ });
22
+ it('does not throw props_invalid_value when bound to an undefined source', () => {
23
+ expect(() => render(Segmented, { props: { options, value: undefined } })).not.toThrow();
24
+ });
25
+ });
@@ -1,28 +1,30 @@
1
1
  <script lang="ts">
2
2
  import { tick } from 'svelte';
3
+ import type { CommitOnlyEvents } from './_contract';
3
4
  import { shell } from '../../shellRuntime.svelte';
4
5
  import Listbox from './_select-listbox.svelte';
5
6
  import { type SelectOption, resolveValueLabel, toggleMulti } from './Select';
6
7
 
7
8
  let {
8
9
  options,
9
- value = $bindable<string | string[]>(''),
10
10
  multiple = false,
11
+ value = $bindable<string | string[]>(multiple ? [] : ''),
11
12
  placeholder = 'Select…',
12
13
  label,
13
14
  disabled = false,
14
15
  invalid = false,
15
16
  size = 'md',
17
+ onchange,
16
18
  }: {
17
19
  options: SelectOption[];
18
- value?: string | string[];
19
20
  multiple?: boolean;
21
+ value?: string | string[];
20
22
  placeholder?: string;
21
23
  label?: string;
22
24
  disabled?: boolean;
23
25
  invalid?: boolean;
24
26
  size?: 'sm' | 'md';
25
- } = $props();
27
+ } & CommitOnlyEvents<string | string[]> = $props();
26
28
 
27
29
  let trigger = $state<HTMLButtonElement | undefined>(undefined);
28
30
  let nativeRef = $state<HTMLSelectElement | undefined>(undefined);
@@ -54,6 +56,7 @@
54
56
  } else {
55
57
  value = v;
56
58
  }
59
+ onchange?.(value);
57
60
  },
58
61
  // Listbox calls this on its own close paths (selection in
59
62
  // single mode, Escape inside the listbox). Outside-click and
@@ -90,6 +93,7 @@
90
93
  } else {
91
94
  value = nativeRef.value;
92
95
  }
96
+ onchange?.(value);
93
97
  }
94
98
  </script>
95
99
 
@@ -1,14 +1,15 @@
1
+ import type { CommitOnlyEvents } from './_contract';
1
2
  import { type SelectOption } from './Select';
2
3
  type $$ComponentProps = {
3
4
  options: SelectOption[];
4
- value?: string | string[];
5
5
  multiple?: boolean;
6
+ value?: string | string[];
6
7
  placeholder?: string;
7
8
  label?: string;
8
9
  disabled?: boolean;
9
10
  invalid?: boolean;
10
11
  size?: 'sm' | 'md';
11
- };
12
+ } & CommitOnlyEvents<string | string[]>;
12
13
  declare const Select: import("svelte").Component<$$ComponentProps, {}, "value">;
13
14
  type Select = ReturnType<typeof Select>;
14
15
  export default Select;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import Select from './Select.svelte';
4
+ vi.mock('../../shellRuntime.svelte', () => ({
5
+ shell: { popup: { show: () => ({ close: () => { } }) } },
6
+ }));
7
+ describe('Select event contract', () => {
8
+ const options = [
9
+ { value: 'a', label: 'Apple' },
10
+ { value: 'b', label: 'Banana' },
11
+ { value: 'c', label: 'Cherry' },
12
+ ];
13
+ it('fires onchange via native select in single mode', async () => {
14
+ const onchange = vi.fn();
15
+ const { container } = render(Select, { props: { options, value: 'a', onchange } });
16
+ const native = container.querySelector('select');
17
+ native.value = 'c';
18
+ await fireEvent.change(native);
19
+ expect(onchange).toHaveBeenCalledTimes(1);
20
+ expect(onchange).toHaveBeenCalledWith('c');
21
+ });
22
+ it('defaults to empty array in multi mode', () => {
23
+ const { container } = render(Select, { props: { options, multiple: true } });
24
+ const native = container.querySelector('select');
25
+ // No <option> should carry a `selected` attribute when value defaults to [].
26
+ // (happy-dom may surface a selectedOptions item for the first option in a
27
+ // multi-select that has no explicit selection — assert the attribute the
28
+ // template controls instead.)
29
+ const optionsEls = Array.from(native.querySelectorAll('option'));
30
+ expect(optionsEls.every((o) => !o.hasAttribute('selected'))).toBe(true);
31
+ });
32
+ it('defaults to empty string in single mode', () => {
33
+ const { container } = render(Select, { props: { options } });
34
+ const trigger = container.querySelector('.sh3-select__display');
35
+ expect(trigger === null || trigger === void 0 ? void 0 : trigger.classList.contains('sh3-select__display--placeholder')).toBe(true);
36
+ });
37
+ });
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import type { LiveInputEvents } from './_contract';
2
3
  import { valueToPercent } from './Slider';
3
4
 
4
5
  let {
@@ -12,6 +13,8 @@
12
13
  invalid = false,
13
14
  size = 'md',
14
15
  orientation = 'horizontal',
16
+ oninput,
17
+ onchange,
15
18
  }: {
16
19
  value?: number;
17
20
  min?: number;
@@ -23,7 +26,7 @@
23
26
  invalid?: boolean;
24
27
  size?: 'sm' | 'md';
25
28
  orientation?: 'horizontal' | 'vertical';
26
- } = $props();
29
+ } & LiveInputEvents<number> = $props();
27
30
 
28
31
  const pct = $derived(valueToPercent(value, min, max));
29
32
  </script>
@@ -48,6 +51,8 @@
48
51
  {disabled}
49
52
  aria-invalid={invalid || undefined}
50
53
  bind:value
54
+ oninput={() => oninput?.(value)}
55
+ onchange={() => onchange?.(value)}
51
56
  />
52
57
  {#if showValue}
53
58
  <output class="sh3-slider__value" style:--pct="{pct}%">{value}</output>
@@ -1,3 +1,4 @@
1
+ import type { LiveInputEvents } from './_contract';
1
2
  type $$ComponentProps = {
2
3
  value?: number;
3
4
  min?: number;
@@ -9,7 +10,7 @@ type $$ComponentProps = {
9
10
  invalid?: boolean;
10
11
  size?: 'sm' | 'md';
11
12
  orientation?: 'horizontal' | 'vertical';
12
- };
13
+ } & LiveInputEvents<number>;
13
14
  declare const Slider: import("svelte").Component<$$ComponentProps, {}, "value">;
14
15
  type Slider = ReturnType<typeof Slider>;
15
16
  export default Slider;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import Slider from './Slider.svelte';
4
+ describe('Slider event contract', () => {
5
+ it('fires oninput on native input event', async () => {
6
+ const oninput = vi.fn();
7
+ const { container } = render(Slider, { props: { value: 0, min: 0, max: 100, oninput } });
8
+ const range = container.querySelector('input[type=range]');
9
+ await fireEvent.input(range, { target: { value: '42' } });
10
+ expect(oninput).toHaveBeenCalledTimes(1);
11
+ expect(oninput).toHaveBeenCalledWith(42);
12
+ });
13
+ it('fires onchange on native change event', async () => {
14
+ const onchange = vi.fn();
15
+ const { container } = render(Slider, { props: { value: 0, min: 0, max: 100, onchange } });
16
+ const range = container.querySelector('input[type=range]');
17
+ await fireEvent.input(range, { target: { value: '70' } });
18
+ await fireEvent.change(range, { target: { value: '70' } });
19
+ expect(onchange).toHaveBeenCalledTimes(1);
20
+ expect(onchange).toHaveBeenCalledWith(70);
21
+ });
22
+ });
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import type { LiveInputEvents } from './_contract';
2
3
  import Slider from './Slider.svelte';
3
4
 
4
5
  type Channel = { id: string; label: string; min?: number; max?: number; step?: number };
@@ -10,6 +11,8 @@
10
11
  showValues = false,
11
12
  disabled = false,
12
13
  size = 'md',
14
+ oninput,
15
+ onchange,
13
16
  }: {
14
17
  orientation?: 'horizontal' | 'vertical';
15
18
  channels: Channel[];
@@ -17,7 +20,7 @@
17
20
  showValues?: boolean;
18
21
  disabled?: boolean;
19
22
  size?: 'sm' | 'md';
20
- } = $props();
23
+ } & LiveInputEvents<Record<string, number>> = $props();
21
24
  </script>
22
25
 
23
26
  <div class="sh3-sg sh3-sg--{orientation}">
@@ -36,6 +39,8 @@
36
39
  () => values[ch.id] ?? 0,
37
40
  (n: number) => values = { ...values, [ch.id]: n }
38
41
  }
42
+ oninput={() => oninput?.(values)}
43
+ onchange={() => onchange?.(values)}
39
44
  />
40
45
  </div>
41
46
  {/each}
@@ -1,3 +1,4 @@
1
+ import type { LiveInputEvents } from './_contract';
1
2
  type Channel = {
2
3
  id: string;
3
4
  label: string;
@@ -12,7 +13,7 @@ type $$ComponentProps = {
12
13
  showValues?: boolean;
13
14
  disabled?: boolean;
14
15
  size?: 'sm' | 'md';
15
- };
16
+ } & LiveInputEvents<Record<string, number>>;
16
17
  declare const SliderGroup: import("svelte").Component<$$ComponentProps, {}, "values">;
17
18
  type SliderGroup = ReturnType<typeof SliderGroup>;
18
19
  export default SliderGroup;