sh3-core 0.13.1 → 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 (119) 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 +4 -2
  38. package/dist/primitives/widgets/Field.svelte.d.ts +2 -2
  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 +2 -2
  42. package/dist/primitives/widgets/FilePicker.svelte.d.ts +2 -2
  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 +4 -4
  46. package/dist/primitives/widgets/IconToggleGroup.svelte.d.ts +3 -3
  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 +19 -9
  50. package/dist/primitives/widgets/NumberInput.svelte.d.ts +2 -2
  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 +11 -4
  62. package/dist/primitives/widgets/RangeSlider.svelte.d.ts +2 -2
  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 +4 -4
  66. package/dist/primitives/widgets/Segmented.svelte.d.ts +3 -3
  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 +4 -4
  70. package/dist/primitives/widgets/Select.svelte.d.ts +3 -3
  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 +4 -2
  74. package/dist/primitives/widgets/Slider.svelte.d.ts +2 -2
  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 +4 -2
  78. package/dist/primitives/widgets/SliderGroup.svelte.d.ts +2 -2
  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 +5 -2
  82. package/dist/primitives/widgets/Textarea.svelte.d.ts +2 -2
  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/version.d.ts +1 -1
  117. package/dist/version.js +1 -1
  118. package/package.json +1 -1
  119. /package/dist/{shards/activate-tenantid.test.d.ts → apps/workspace-rekey.test.d.ts} +0 -0
@@ -1,4 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { CommitOnlyEvents } from './_contract';
2
3
  type Option = {
3
4
  value: string;
4
5
  icon: Snippet;
@@ -6,12 +7,11 @@ type Option = {
6
7
  };
7
8
  type $$ComponentProps = {
8
9
  options: Option[];
9
- value: string | string[];
10
10
  multiple?: boolean;
11
+ value?: string | string[];
11
12
  disabled?: boolean;
12
13
  size?: 'sm' | 'md';
13
- onchange?: (next: string | string[]) => void;
14
- };
14
+ } & CommitOnlyEvents<string | string[]>;
15
15
  declare const IconToggleGroup: import("svelte").Component<$$ComponentProps, {}, "value">;
16
16
  type IconToggleGroup = ReturnType<typeof IconToggleGroup>;
17
17
  export default IconToggleGroup;
@@ -0,0 +1,40 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import { createRawSnippet } from 'svelte';
4
+ import IconToggleGroup from './IconToggleGroup.svelte';
5
+ const blank = createRawSnippet(() => ({ render: () => '<span/>' }));
6
+ const options = [
7
+ { value: 'b', icon: blank, tooltip: 'Bold' },
8
+ { value: 'i', icon: blank, tooltip: 'Italic' },
9
+ { value: 'u', icon: blank, tooltip: 'Under' },
10
+ ];
11
+ describe('IconToggleGroup event contract', () => {
12
+ it('fires onchange on click in single mode', async () => {
13
+ const onchange = vi.fn();
14
+ const { getByLabelText } = render(IconToggleGroup, {
15
+ props: { options, value: 'b', onchange },
16
+ });
17
+ await fireEvent.click(getByLabelText('Italic'));
18
+ expect(onchange).toHaveBeenCalledTimes(1);
19
+ expect(onchange).toHaveBeenCalledWith('i');
20
+ });
21
+ it('defaults to first option in single mode', () => {
22
+ const { getByLabelText } = render(IconToggleGroup, { props: { options } });
23
+ const bold = getByLabelText('Bold');
24
+ expect(bold.getAttribute('aria-pressed')).toBe('true');
25
+ });
26
+ it('defaults to empty array in multi mode', () => {
27
+ const { getByLabelText } = render(IconToggleGroup, { props: { options, multiple: true } });
28
+ expect(getByLabelText('Bold').getAttribute('aria-pressed')).toBe('false');
29
+ expect(getByLabelText('Italic').getAttribute('aria-pressed')).toBe('false');
30
+ });
31
+ it('toggles individual items in multi mode', async () => {
32
+ const onchange = vi.fn();
33
+ const { getByLabelText } = render(IconToggleGroup, {
34
+ props: { options, multiple: true, onchange },
35
+ });
36
+ await fireEvent.click(getByLabelText('Bold'));
37
+ await fireEvent.click(getByLabelText('Italic'));
38
+ expect(onchange).toHaveBeenLastCalledWith(['b', 'i']);
39
+ });
40
+ });
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
- import { clamp, applyStep, formatNumber } from './NumberInput';
3
+ import type { LiveInputEvents } from './_contract';
4
+ import { clamp, applyStep } from './NumberInput';
4
5
 
5
6
  let {
6
7
  value = $bindable(0),
@@ -14,6 +15,7 @@
14
15
  disabled = false,
15
16
  invalid = false,
16
17
  size = 'md',
18
+ oninput,
17
19
  onchange,
18
20
  }: {
19
21
  value?: number;
@@ -27,18 +29,18 @@
27
29
  disabled?: boolean;
28
30
  invalid?: boolean;
29
31
  size?: 'sm' | 'md';
30
- onchange?: (next: number) => void;
31
- } = $props();
32
-
33
- const display = $derived(formatNumber(value, precision));
32
+ } & LiveInputEvents<number> = $props();
34
33
 
35
34
  function commit(next: number) {
36
35
  if (Number.isNaN(next)) return;
37
- value = clamp(applyStep(next, { min, step }), min, max);
36
+ let v = clamp(applyStep(next, { min, step }), min, max);
37
+ if (precision !== undefined) v = Number(v.toFixed(precision));
38
+ value = v;
38
39
  }
39
40
 
40
41
  function bump(direction: 1 | -1) {
41
42
  commit(value + direction * step);
43
+ oninput?.(value);
42
44
  }
43
45
 
44
46
  let holdTimer: ReturnType<typeof setTimeout> | null = null;
@@ -82,9 +84,17 @@
82
84
  {step}
83
85
  {disabled}
84
86
  aria-invalid={invalid || undefined}
85
- value={display}
86
- oninput={(e) => commit(parseFloat((e.currentTarget as HTMLInputElement).value))}
87
- onblur={() => onchange?.(value)}
87
+ value={value}
88
+ oninput={(e) => {
89
+ const raw = (e.currentTarget as HTMLInputElement).valueAsNumber;
90
+ if (Number.isNaN(raw)) return;
91
+ value = raw;
92
+ oninput?.(raw);
93
+ }}
94
+ onblur={() => {
95
+ commit(value);
96
+ onchange?.(value);
97
+ }}
88
98
  />
89
99
  {#if suffix}<span class="sh3-num__affix">{@render suffix()}</span>{/if}
90
100
  <span class="sh3-num__steppers">
@@ -1,4 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { LiveInputEvents } from './_contract';
2
3
  type $$ComponentProps = {
3
4
  value?: number;
4
5
  min?: number;
@@ -11,8 +12,7 @@ type $$ComponentProps = {
11
12
  disabled?: boolean;
12
13
  invalid?: boolean;
13
14
  size?: 'sm' | 'md';
14
- onchange?: (next: number) => void;
15
- };
15
+ } & LiveInputEvents<number>;
16
16
  declare const NumberInput: import("svelte").Component<$$ComponentProps, {}, "value">;
17
17
  type NumberInput = ReturnType<typeof NumberInput>;
18
18
  export default NumberInput;
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import NumberInput from './NumberInput.svelte';
4
+ describe('NumberInput event contract', () => {
5
+ it('does not snap mid-typing when step=1', async () => {
6
+ const oninput = vi.fn();
7
+ const { container } = render(NumberInput, { props: { value: 0, step: 1, oninput } });
8
+ const input = container.querySelector('input');
9
+ await fireEvent.input(input, { target: { value: '5' } });
10
+ await fireEvent.input(input, { target: { value: '5.5' } });
11
+ expect(oninput).toHaveBeenCalledTimes(2);
12
+ expect(oninput).toHaveBeenNthCalledWith(1, 5);
13
+ expect(oninput).toHaveBeenNthCalledWith(2, 5.5);
14
+ });
15
+ it('swallows partial parses (NaN does not call oninput)', async () => {
16
+ const oninput = vi.fn();
17
+ const { container } = render(NumberInput, { props: { value: 1, oninput } });
18
+ const input = container.querySelector('input');
19
+ await fireEvent.input(input, { target: { value: '' } });
20
+ expect(oninput).not.toHaveBeenCalled();
21
+ });
22
+ it('commits applyStep on blur and fires onchange once', async () => {
23
+ const onchange = vi.fn();
24
+ const { container } = render(NumberInput, { props: { value: 0, step: 1, onchange } });
25
+ const input = container.querySelector('input');
26
+ await fireEvent.input(input, { target: { value: '5.5' } });
27
+ await fireEvent.blur(input);
28
+ expect(onchange).toHaveBeenCalledTimes(1);
29
+ expect(onchange).toHaveBeenCalledWith(6);
30
+ });
31
+ it('clamps to max on blur', async () => {
32
+ const onchange = vi.fn();
33
+ const { container } = render(NumberInput, { props: { value: 0, max: 10, onchange } });
34
+ const input = container.querySelector('input');
35
+ await fireEvent.input(input, { target: { value: '999' } });
36
+ await fireEvent.blur(input);
37
+ expect(onchange).toHaveBeenCalledWith(10);
38
+ });
39
+ it('rounds to precision on blur', async () => {
40
+ const onchange = vi.fn();
41
+ const { container } = render(NumberInput, { props: { value: 0, step: 0.01, precision: 2, onchange } });
42
+ const input = container.querySelector('input');
43
+ await fireEvent.input(input, { target: { value: '1.23456' } });
44
+ await fireEvent.blur(input);
45
+ expect(onchange).toHaveBeenCalledTimes(1);
46
+ expect(onchange.mock.calls[0][0]).toBeCloseTo(1.23, 5);
47
+ });
48
+ });
@@ -0,0 +1,24 @@
1
+ export interface PickerItem {
2
+ id: string;
3
+ label: string;
4
+ /** Optional secondary line shown beneath the label in muted style. */
5
+ sublabel?: string;
6
+ }
7
+ export interface PickerListProps {
8
+ items: PickerItem[];
9
+ value: string[];
10
+ onchange?: (next: string[]) => void;
11
+ loading?: boolean;
12
+ error?: string | null;
13
+ onRetry?: () => void;
14
+ /** Empty-state message when items.length === 0 and not loading/error. */
15
+ emptyText?: string;
16
+ /** Search input is rendered when items.length >= this value. Default: 8. */
17
+ searchThreshold?: number;
18
+ disabled?: boolean;
19
+ size?: 'sm' | 'md';
20
+ }
21
+ /** Case-insensitive substring match over label, id, and sublabel. */
22
+ export declare function filterItems(items: PickerItem[], query: string): PickerItem[];
23
+ /** Toggle the given id in or out of value, returning a NEW array. */
24
+ export declare function toggle(value: string[], id: string): string[];
@@ -0,0 +1,21 @@
1
+ /** Case-insensitive substring match over label, id, and sublabel. */
2
+ export function filterItems(items, query) {
3
+ if (!query)
4
+ return items;
5
+ const q = query.toLowerCase();
6
+ return items.filter((it) => {
7
+ if (it.label.toLowerCase().includes(q))
8
+ return true;
9
+ if (it.id.toLowerCase().includes(q))
10
+ return true;
11
+ if (it.sublabel && it.sublabel.toLowerCase().includes(q))
12
+ return true;
13
+ return false;
14
+ });
15
+ }
16
+ /** Toggle the given id in or out of value, returning a NEW array. */
17
+ export function toggle(value, id) {
18
+ if (value.includes(id))
19
+ return value.filter((v) => v !== id);
20
+ return [...value, id];
21
+ }
@@ -0,0 +1,150 @@
1
+ <script lang="ts">
2
+ import type { CommitOnlyEvents } from './_contract';
3
+ import { filterItems, toggle, type PickerItem } from './PickerList';
4
+
5
+ let {
6
+ items,
7
+ value = $bindable<string[]>([]),
8
+ loading = false,
9
+ error = null,
10
+ onRetry,
11
+ emptyText = 'No items.',
12
+ searchThreshold = 8,
13
+ disabled = false,
14
+ size = 'md',
15
+ onchange,
16
+ }: {
17
+ items: PickerItem[];
18
+ value?: string[];
19
+ loading?: boolean;
20
+ error?: string | null;
21
+ onRetry?: () => void;
22
+ emptyText?: string;
23
+ searchThreshold?: number;
24
+ disabled?: boolean;
25
+ size?: 'sm' | 'md';
26
+ } & CommitOnlyEvents<string[]> = $props();
27
+
28
+ let query = $state('');
29
+ const showSearch = $derived(items.length >= searchThreshold);
30
+ const filtered = $derived(filterItems(items, query));
31
+ const totalCount = $derived(items.length);
32
+ const selectedCount = $derived(value.length);
33
+
34
+ function toggleId(id: string) {
35
+ if (disabled) return;
36
+ const next = toggle(value, id);
37
+ value = next;
38
+ onchange?.(next);
39
+ }
40
+ </script>
41
+
42
+ <div class="sh3-picker" class:sh3-picker--sm={size === 'sm'} class:sh3-picker--disabled={disabled}>
43
+ {#if showSearch}
44
+ <input
45
+ type="search"
46
+ class="sh3-picker__search"
47
+ placeholder="Filter…"
48
+ bind:value={query}
49
+ {disabled}
50
+ />
51
+ {/if}
52
+
53
+ <div class="sh3-picker__list">
54
+ {#if loading}
55
+ <p class="sh3-picker__status">Loading…</p>
56
+ {:else if error}
57
+ <p class="sh3-picker__status sh3-picker__status--error">{error}</p>
58
+ {#if onRetry}
59
+ <button type="button" class="sh3-picker__retry" onclick={() => onRetry?.()}>Retry</button>
60
+ {/if}
61
+ {:else if items.length === 0}
62
+ <p class="sh3-picker__status">{emptyText}</p>
63
+ {:else}
64
+ {#each filtered as item (item.id)}
65
+ <label class="sh3-picker__row">
66
+ <input
67
+ type="checkbox"
68
+ checked={value.includes(item.id)}
69
+ {disabled}
70
+ onchange={() => toggleId(item.id)}
71
+ />
72
+ <span class="sh3-picker__row-text">
73
+ <span class="sh3-picker__row-label">{item.label}</span>
74
+ {#if item.sublabel}
75
+ <span class="sh3-picker__row-sub">{item.sublabel}</span>
76
+ {/if}
77
+ </span>
78
+ </label>
79
+ {/each}
80
+ {/if}
81
+ </div>
82
+
83
+ <p class="sh3-picker__footer">{selectedCount} of {totalCount} selected</p>
84
+ </div>
85
+
86
+ <style>
87
+ .sh3-picker {
88
+ display: flex;
89
+ flex-direction: column;
90
+ gap: 6px;
91
+ border: 1px solid var(--shell-border);
92
+ border-radius: var(--shell-radius-sm, 3px);
93
+ padding: 6px;
94
+ background: var(--shell-bg-elevated);
95
+ }
96
+ .sh3-picker__search {
97
+ width: 100%;
98
+ padding: 4px 6px;
99
+ border: 1px solid var(--shell-border);
100
+ border-radius: var(--shell-radius-sm, 3px);
101
+ background: var(--shell-bg);
102
+ color: var(--shell-fg);
103
+ font: inherit;
104
+ font-size: 12px;
105
+ }
106
+ .sh3-picker__list {
107
+ display: flex;
108
+ flex-direction: column;
109
+ max-height: 200px;
110
+ overflow-y: auto;
111
+ }
112
+ .sh3-picker__row {
113
+ display: flex;
114
+ align-items: center;
115
+ gap: 8px;
116
+ padding: 4px 6px;
117
+ cursor: pointer;
118
+ border-radius: var(--shell-radius-sm, 3px);
119
+ }
120
+ .sh3-picker__row:hover { background: var(--shell-bg); }
121
+ .sh3-picker__row-text { display: flex; flex-direction: column; gap: 0; }
122
+ .sh3-picker__row-label { font-size: 13px; }
123
+ .sh3-picker__row-sub { font-size: 11px; color: var(--shell-fg-muted); }
124
+ .sh3-picker__status {
125
+ margin: 0;
126
+ padding: 8px 6px;
127
+ color: var(--shell-fg-muted);
128
+ font-size: 12px;
129
+ }
130
+ .sh3-picker__status--error { color: var(--shell-error, #c33); }
131
+ .sh3-picker__retry {
132
+ align-self: flex-start;
133
+ margin: 0 6px 8px;
134
+ background: var(--shell-bg);
135
+ color: var(--shell-fg);
136
+ border: 1px solid var(--shell-border);
137
+ border-radius: var(--shell-radius-sm, 3px);
138
+ padding: 2px 8px;
139
+ font: inherit;
140
+ font-size: 12px;
141
+ cursor: pointer;
142
+ }
143
+ .sh3-picker__footer {
144
+ margin: 0;
145
+ font-size: 11px;
146
+ color: var(--shell-fg-muted);
147
+ text-align: right;
148
+ }
149
+ .sh3-picker--disabled .sh3-picker__row { cursor: not-allowed; opacity: 0.6; }
150
+ </style>
@@ -0,0 +1,16 @@
1
+ import type { CommitOnlyEvents } from './_contract';
2
+ import { type PickerItem } from './PickerList';
3
+ type $$ComponentProps = {
4
+ items: PickerItem[];
5
+ value?: string[];
6
+ loading?: boolean;
7
+ error?: string | null;
8
+ onRetry?: () => void;
9
+ emptyText?: string;
10
+ searchThreshold?: number;
11
+ disabled?: boolean;
12
+ size?: 'sm' | 'md';
13
+ } & CommitOnlyEvents<string[]>;
14
+ declare const PickerList: import("svelte").Component<$$ComponentProps, {}, "value">;
15
+ type PickerList = ReturnType<typeof PickerList>;
16
+ export default PickerList;
@@ -0,0 +1,31 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/svelte';
3
+ import PickerList from './PickerList.svelte';
4
+ const items = [
5
+ { id: '1', label: 'One' },
6
+ { id: '2', label: 'Two' },
7
+ { id: '3', label: 'Three' },
8
+ ];
9
+ describe('PickerList event contract', () => {
10
+ it('fires onchange with updated array when row toggled', async () => {
11
+ const onchange = vi.fn();
12
+ const { container } = render(PickerList, { props: { items, value: [], onchange } });
13
+ const checkboxes = container.querySelectorAll('input[type=checkbox]');
14
+ await fireEvent.click(checkboxes[1]);
15
+ expect(onchange).toHaveBeenCalledTimes(1);
16
+ expect(onchange).toHaveBeenCalledWith(['2']);
17
+ });
18
+ it('renders loading state', () => {
19
+ const { getByText } = render(PickerList, { props: { items: [], loading: true } });
20
+ expect(getByText('Loading…')).toBeInTheDocument();
21
+ });
22
+ it('renders error state with retry button when provided', async () => {
23
+ const onRetry = vi.fn();
24
+ const { getByText } = render(PickerList, {
25
+ props: { items: [], error: 'Boom', onRetry },
26
+ });
27
+ expect(getByText('Boom')).toBeInTheDocument();
28
+ await fireEvent.click(getByText('Retry'));
29
+ expect(onRetry).toHaveBeenCalled();
30
+ });
31
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ });