runeforge 0.0.62 → 0.0.63

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 (66) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1410 -1407
  3. package/dist/components/Avatar.svelte +31 -31
  4. package/dist/components/IconRenderer.svelte +73 -73
  5. package/dist/components/Modal.svelte +75 -75
  6. package/dist/components/common/Header.svelte +40 -40
  7. package/dist/components/crud/EmbeddedField.svelte +203 -203
  8. package/dist/components/crud/Field.svelte +122 -122
  9. package/dist/components/crud/GenericCRUD.svelte +426 -426
  10. package/dist/components/crud/SearchInput.svelte +53 -53
  11. package/dist/components/crud/columns/Avatar.svelte +15 -15
  12. package/dist/components/crud/columns/Icon.svelte +8 -8
  13. package/dist/components/crud/fields/BooleanField.svelte +38 -38
  14. package/dist/components/crud/fields/DatetimeField.svelte +250 -250
  15. package/dist/components/crud/fields/DefaultField.svelte +67 -67
  16. package/dist/components/crud/fields/FileField.svelte +70 -70
  17. package/dist/components/crud/fields/MultiSelectField.svelte +70 -70
  18. package/dist/components/crud/fields/SelectField.svelte +67 -67
  19. package/dist/components/crud/fields/TextareaField.svelte +55 -55
  20. package/dist/components/crud/fields/TreeField.svelte +1 -0
  21. package/dist/components/crud/utils/resolution.js +1 -0
  22. package/dist/components/crud/utils/tree.d.ts +5 -0
  23. package/dist/components/crud/utils/tree.js +29 -0
  24. package/dist/components/crud/views/Create.svelte +239 -239
  25. package/dist/components/crud/views/Read.svelte +131 -131
  26. package/dist/components/crud/views/Update.svelte +215 -215
  27. package/dist/components/crud/views/list/List.svelte +291 -291
  28. package/dist/components/crud/views/list/Modals.svelte +56 -56
  29. package/dist/components/crud/views/list/Table.svelte +173 -173
  30. package/dist/components/crud/views/list/Toolbar.svelte +340 -340
  31. package/dist/components/form/Button.svelte +27 -27
  32. package/dist/components/form/Label.svelte +37 -37
  33. package/dist/components/form/MultiSelect.svelte +248 -248
  34. package/dist/components/form/PasswordInput.svelte +68 -68
  35. package/dist/components/form/Required.svelte +1 -1
  36. package/dist/components/form/Select.svelte +209 -209
  37. package/dist/components/form/Tree.svelte +43 -4
  38. package/dist/components/form/Tree.svelte.d.ts +1 -0
  39. package/dist/components/form/TreeNode.svelte +31 -2
  40. package/dist/components/form/TreeNode.svelte.d.ts +2 -0
  41. package/dist/components/navigation/Breadcrumbs.svelte +111 -111
  42. package/dist/components/table/ColumnFilter.svelte +168 -168
  43. package/dist/components/table/PaginatedTable.svelte +542 -542
  44. package/dist/components/table/Paginator.svelte +113 -113
  45. package/dist/components/table/SortHeader.svelte +43 -43
  46. package/dist/components/table/TableBody.svelte +150 -150
  47. package/dist/components/table/TableHeader.svelte +88 -88
  48. package/dist/icons/defaults/Clear.svelte +6 -6
  49. package/dist/icons/defaults/Create.svelte +6 -6
  50. package/dist/icons/defaults/Delete.svelte +6 -6
  51. package/dist/icons/defaults/Download.svelte +7 -7
  52. package/dist/icons/defaults/Edit.svelte +7 -7
  53. package/dist/icons/defaults/Filter.svelte +6 -6
  54. package/dist/icons/defaults/FilterActive.svelte +6 -6
  55. package/dist/icons/defaults/Folder.svelte +6 -6
  56. package/dist/icons/defaults/Grip.svelte +7 -7
  57. package/dist/icons/defaults/Home.svelte +6 -6
  58. package/dist/icons/defaults/PasswordHide.svelte +9 -9
  59. package/dist/icons/defaults/PasswordShow.svelte +7 -7
  60. package/dist/icons/defaults/SortAsc.svelte +6 -6
  61. package/dist/icons/defaults/SortDesc.svelte +6 -6
  62. package/dist/icons/defaults/SortNone.svelte +6 -6
  63. package/dist/icons/defaults/View.svelte +7 -7
  64. package/dist/types/attribute.d.ts +3 -0
  65. package/dist/types/crud/fields.d.ts +3 -0
  66. package/package.json +1 -1
@@ -1,68 +1,68 @@
1
- <script lang="ts">
2
- import type { FullAutoFill } from 'svelte/elements';
3
- import Label from './Label.svelte';
4
- import Button from './Button.svelte';
5
- import { getIconSet } from '../../icons/context.js';
6
- import { defaultIconSet } from '../../icons/sets/default.js';
7
-
8
- let {
9
- name,
10
- id,
11
- value = $bindable(''),
12
- autocomplete,
13
- required = true,
14
- placeholder = '',
15
- invalid = false,
16
- labelClass,
17
- inputClass,
18
- buttonClass,
19
- }: {
20
- name?: string;
21
- id?: string;
22
- value?: string;
23
- autocomplete?: FullAutoFill;
24
- required?: boolean;
25
- placeholder?: string;
26
- invalid?: boolean;
27
- labelClass?: string;
28
- inputClass?: string;
29
- buttonClass?: string;
30
- } = $props();
31
-
32
- const icons = $derived(getIconSet() ?? defaultIconSet);
33
- let visible = $state(false);
34
- </script>
35
-
36
- <Label
37
- class={[
38
- 'input input-bordered w-full',
39
- { 'input-error': invalid },
40
- labelClass
41
- ]}
42
- >
43
- <input
44
- {name}
45
- {id}
46
- {required}
47
- {placeholder}
48
- bind:value
49
- {autocomplete}
50
- type={visible ? 'text' : 'password'}
51
- class={['grow', inputClass]}
52
- />
53
- <Button
54
- btn={false}
55
- class={['cursor-pointer opacity-60 hover:opacity-100', buttonClass].filter(Boolean).join(' ')}
56
- aria-label={visible ? 'Ocultar contraseña' : 'Mostrar contraseña'}
57
- aria-pressed={visible}
58
- onclick={() => (visible = !visible)}
59
- >
60
- {#if visible}
61
- {@const HideIcon = icons.passwordHide}
62
- <HideIcon class="size-4" />
63
- {:else}
64
- {@const ShowIcon = icons.passwordShow}
65
- <ShowIcon class="size-4" />
66
- {/if}
67
- </Button>
68
- </Label>
1
+ <script lang="ts">
2
+ import type { FullAutoFill } from 'svelte/elements';
3
+ import Label from './Label.svelte';
4
+ import Button from './Button.svelte';
5
+ import { getIconSet } from '../../icons/context.js';
6
+ import { defaultIconSet } from '../../icons/sets/default.js';
7
+
8
+ let {
9
+ name,
10
+ id,
11
+ value = $bindable(''),
12
+ autocomplete,
13
+ required = true,
14
+ placeholder = '',
15
+ invalid = false,
16
+ labelClass,
17
+ inputClass,
18
+ buttonClass,
19
+ }: {
20
+ name?: string;
21
+ id?: string;
22
+ value?: string;
23
+ autocomplete?: FullAutoFill;
24
+ required?: boolean;
25
+ placeholder?: string;
26
+ invalid?: boolean;
27
+ labelClass?: string;
28
+ inputClass?: string;
29
+ buttonClass?: string;
30
+ } = $props();
31
+
32
+ const icons = $derived(getIconSet() ?? defaultIconSet);
33
+ let visible = $state(false);
34
+ </script>
35
+
36
+ <Label
37
+ class={[
38
+ 'input input-bordered w-full',
39
+ { 'input-error': invalid },
40
+ labelClass
41
+ ]}
42
+ >
43
+ <input
44
+ {name}
45
+ {id}
46
+ {required}
47
+ {placeholder}
48
+ bind:value
49
+ {autocomplete}
50
+ type={visible ? 'text' : 'password'}
51
+ class={['grow', inputClass]}
52
+ />
53
+ <Button
54
+ btn={false}
55
+ class={['cursor-pointer opacity-60 hover:opacity-100', buttonClass].filter(Boolean).join(' ')}
56
+ aria-label={visible ? 'Ocultar contraseña' : 'Mostrar contraseña'}
57
+ aria-pressed={visible}
58
+ onclick={() => (visible = !visible)}
59
+ >
60
+ {#if visible}
61
+ {@const HideIcon = icons.passwordHide}
62
+ <HideIcon class="size-4" />
63
+ {:else}
64
+ {@const ShowIcon = icons.passwordShow}
65
+ <ShowIcon class="size-4" />
66
+ {/if}
67
+ </Button>
68
+ </Label>
@@ -1 +1 @@
1
- <span class="text-error ml-0.5">*</span>
1
+ <span class="text-error ml-0.5">*</span>
@@ -1,209 +1,209 @@
1
- <script lang="ts">
2
- import { getStrings } from '../../i18n/context.js';
3
- import type { SearchResolver } from '../../types/attribute.js';
4
-
5
- const strings = getStrings();
6
-
7
- let {
8
- name,
9
- id,
10
- value = $bindable(''),
11
- options = [],
12
- search: searchFn,
13
- searchDebounceMs = 300,
14
- placeholder = strings.selectPlaceholder,
15
- error = '',
16
- disabled = false
17
- }: {
18
- name?: string;
19
- id?: string;
20
- value?: string;
21
- options?: { value: string; label: string }[];
22
- search?: SearchResolver;
23
- searchDebounceMs?: number;
24
- placeholder?: string;
25
- error?: string;
26
- disabled?: boolean;
27
- } = $props();
28
-
29
- const popId = $props.id();
30
- const anchorName = `--select-anchor-${popId}`;
31
-
32
- let query = $state('');
33
- let open = $state(false);
34
- let containerEl: HTMLElement | undefined = $state();
35
- let popoverEl: HTMLElement | undefined = $state();
36
- let inputEl: HTMLInputElement | undefined = $state();
37
-
38
- // Options resolved by `searchFn` for the current query; null while no
39
- // server search has run yet (e.g. box just opened, query still empty).
40
- let remoteResults = $state<{ value: string; label: string }[] | null>(null);
41
- let searching = $state(false);
42
- // Label of whatever was last picked from `remoteResults`, kept around so the
43
- // closed-state input can still show it even though it isn't in `options`.
44
- let pickedLabel = $state<string | null>(null);
45
-
46
- let searchToken = 0;
47
- $effect(() => {
48
- if (!searchFn) return;
49
- const q = query.trim();
50
- if (!q) {
51
- remoteResults = null;
52
- searching = false;
53
- return;
54
- }
55
- const token = ++searchToken;
56
- searching = true;
57
- const timer = setTimeout(() => {
58
- searchFn(q).then((results) => {
59
- if (token !== searchToken) return; // stale response, a newer query took over
60
- remoteResults = results;
61
- searching = false;
62
- });
63
- }, searchDebounceMs);
64
- return () => clearTimeout(timer);
65
- });
66
-
67
- const filtered = $derived(
68
- searchFn
69
- ? (remoteResults ?? options)
70
- : query.trim()
71
- ? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase()))
72
- : options
73
- );
74
-
75
- const selectedLabel = $derived(
76
- value === '' ? '' : (options.find((o) => o.value === value)?.label ?? pickedLabel ?? '')
77
- );
78
-
79
- function openPopover() {
80
- open = true;
81
- query = '';
82
- popoverEl?.showPopover();
83
- }
84
-
85
- function pick(option: { value: string; label: string }) {
86
- value = option.value;
87
- pickedLabel = option.label;
88
- query = '';
89
- popoverEl?.hidePopover();
90
- inputEl?.blur();
91
- }
92
-
93
- function clear() {
94
- value = '';
95
- pickedLabel = null;
96
- query = '';
97
- popoverEl?.hidePopover();
98
- inputEl?.blur();
99
- }
100
-
101
- // Catches dismissal paths that don't go through pick()/clear() (outside
102
- // click, Escape), so a stale search doesn't linger for next time it opens.
103
- function onToggle(e: Event) {
104
- if ((e as ToggleEvent).newState === 'closed') {
105
- open = false;
106
- query = '';
107
- }
108
- }
109
-
110
- // Escape can be pressed while an option button has focus (not just the
111
- // text input), so this is wired at the container level rather than on
112
- // the input alone — otherwise picking an option and then hitting Escape
113
- // would leave the popover open with nothing listening for the key.
114
- function onKeydown(e: KeyboardEvent) {
115
- if (e.key === 'Enter' && e.target === inputEl) {
116
- // The trigger used to be a plain button, so Enter never submitted the
117
- // surrounding form. Now that it's a text input, guard against that.
118
- e.preventDefault();
119
- } else if (e.key === 'Escape') {
120
- // Also suppress the browser's native "revert to last value" behavior
121
- // for text inputs on Escape, which would otherwise race our own
122
- // close-and-restore-label update and blank the field.
123
- e.preventDefault();
124
- popoverEl?.hidePopover();
125
- }
126
- }
127
-
128
- // The trigger is a text input now, not a button, so it can't rely on the
129
- // native `popovertarget` invoker exclusion to survive its own opening
130
- // click (that relationship only applies to button-like elements — for a
131
- // text input, the click that focuses it and opens the popover would
132
- // immediately light-dismiss it again). `popover="manual"` opts out of
133
- // that dismiss behavior entirely; this handler reimplements "close when
134
- // focus leaves the widget" instead.
135
- function onFocusOut(e: FocusEvent) {
136
- const next = e.relatedTarget as Node | null;
137
- if (!next || !containerEl?.contains(next)) {
138
- popoverEl?.hidePopover();
139
- }
140
- }
141
- </script>
142
-
143
- <!--
144
- The keydown/focusout handlers here are event delegation for the input and
145
- popover option buttons below, not interaction with this div itself — every
146
- actually-interactive element inside already has correct native semantics.
147
- -->
148
- <!-- svelte-ignore a11y_no_static_element_interactions -->
149
- <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
150
- <div class="relative w-full" bind:this={containerEl} onfocusout={onFocusOut} onkeydown={onKeydown}>
151
- {#if name}
152
- <input type="hidden" {name} {value} />
153
- {/if}
154
-
155
- <input
156
- bind:this={inputEl}
157
- {id}
158
- type="text"
159
- class="input input-bordered w-full font-normal"
160
- class:input-error={!!error}
161
- {disabled}
162
- {placeholder}
163
- value={open ? query : selectedLabel}
164
- oninput={(e) => (query = e.currentTarget.value)}
165
- onfocus={openPopover}
166
- style="anchor-name:{anchorName}"
167
- autocomplete="off"
168
- />
169
-
170
- <div
171
- popover="manual"
172
- id={popId}
173
- bind:this={popoverEl}
174
- style="position-anchor:{anchorName}; width:anchor-size(width); position-try-fallbacks:flip-block;"
175
- class="dropdown mt-1 rounded-box border border-base-content/10 bg-base-100 shadow-lg"
176
- ontoggle={onToggle}
177
- >
178
- <ul class="max-h-48 overflow-y-auto p-1">
179
- <li>
180
- <button
181
- type="button"
182
- class="w-full rounded-btn px-3 py-2 text-left text-sm text-base-content/40 hover:bg-base-200"
183
- onclick={clear}
184
- >
185
- {placeholder}
186
- </button>
187
- </li>
188
- {#if searching}
189
- <li class="px-3 py-2 text-sm text-base-content/40">{strings.selectSearching}</li>
190
- {/if}
191
- {#each filtered as option (option.value)}
192
- <li>
193
- <button
194
- type="button"
195
- class="w-full rounded-btn px-3 py-2 text-left text-sm hover:bg-base-200"
196
- class:bg-primary={value === option.value}
197
- class:text-primary-content={value === option.value}
198
- onclick={() => pick(option)}
199
- >
200
- {option.label}
201
- </button>
202
- </li>
203
- {/each}
204
- {#if !searching && filtered.length === 0}
205
- <li class="px-3 py-2 text-sm text-base-content/40">{strings.selectNoResults}</li>
206
- {/if}
207
- </ul>
208
- </div>
209
- </div>
1
+ <script lang="ts">
2
+ import { getStrings } from '../../i18n/context.js';
3
+ import type { SearchResolver } from '../../types/attribute.js';
4
+
5
+ const strings = getStrings();
6
+
7
+ let {
8
+ name,
9
+ id,
10
+ value = $bindable(''),
11
+ options = [],
12
+ search: searchFn,
13
+ searchDebounceMs = 300,
14
+ placeholder = strings.selectPlaceholder,
15
+ error = '',
16
+ disabled = false
17
+ }: {
18
+ name?: string;
19
+ id?: string;
20
+ value?: string;
21
+ options?: { value: string; label: string }[];
22
+ search?: SearchResolver;
23
+ searchDebounceMs?: number;
24
+ placeholder?: string;
25
+ error?: string;
26
+ disabled?: boolean;
27
+ } = $props();
28
+
29
+ const popId = $props.id();
30
+ const anchorName = `--select-anchor-${popId}`;
31
+
32
+ let query = $state('');
33
+ let open = $state(false);
34
+ let containerEl: HTMLElement | undefined = $state();
35
+ let popoverEl: HTMLElement | undefined = $state();
36
+ let inputEl: HTMLInputElement | undefined = $state();
37
+
38
+ // Options resolved by `searchFn` for the current query; null while no
39
+ // server search has run yet (e.g. box just opened, query still empty).
40
+ let remoteResults = $state<{ value: string; label: string }[] | null>(null);
41
+ let searching = $state(false);
42
+ // Label of whatever was last picked from `remoteResults`, kept around so the
43
+ // closed-state input can still show it even though it isn't in `options`.
44
+ let pickedLabel = $state<string | null>(null);
45
+
46
+ let searchToken = 0;
47
+ $effect(() => {
48
+ if (!searchFn) return;
49
+ const q = query.trim();
50
+ if (!q) {
51
+ remoteResults = null;
52
+ searching = false;
53
+ return;
54
+ }
55
+ const token = ++searchToken;
56
+ searching = true;
57
+ const timer = setTimeout(() => {
58
+ searchFn(q).then((results) => {
59
+ if (token !== searchToken) return; // stale response, a newer query took over
60
+ remoteResults = results;
61
+ searching = false;
62
+ });
63
+ }, searchDebounceMs);
64
+ return () => clearTimeout(timer);
65
+ });
66
+
67
+ const filtered = $derived(
68
+ searchFn
69
+ ? (remoteResults ?? options)
70
+ : query.trim()
71
+ ? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase()))
72
+ : options
73
+ );
74
+
75
+ const selectedLabel = $derived(
76
+ value === '' ? '' : (options.find((o) => o.value === value)?.label ?? pickedLabel ?? '')
77
+ );
78
+
79
+ function openPopover() {
80
+ open = true;
81
+ query = '';
82
+ popoverEl?.showPopover();
83
+ }
84
+
85
+ function pick(option: { value: string; label: string }) {
86
+ value = option.value;
87
+ pickedLabel = option.label;
88
+ query = '';
89
+ popoverEl?.hidePopover();
90
+ inputEl?.blur();
91
+ }
92
+
93
+ function clear() {
94
+ value = '';
95
+ pickedLabel = null;
96
+ query = '';
97
+ popoverEl?.hidePopover();
98
+ inputEl?.blur();
99
+ }
100
+
101
+ // Catches dismissal paths that don't go through pick()/clear() (outside
102
+ // click, Escape), so a stale search doesn't linger for next time it opens.
103
+ function onToggle(e: Event) {
104
+ if ((e as ToggleEvent).newState === 'closed') {
105
+ open = false;
106
+ query = '';
107
+ }
108
+ }
109
+
110
+ // Escape can be pressed while an option button has focus (not just the
111
+ // text input), so this is wired at the container level rather than on
112
+ // the input alone — otherwise picking an option and then hitting Escape
113
+ // would leave the popover open with nothing listening for the key.
114
+ function onKeydown(e: KeyboardEvent) {
115
+ if (e.key === 'Enter' && e.target === inputEl) {
116
+ // The trigger used to be a plain button, so Enter never submitted the
117
+ // surrounding form. Now that it's a text input, guard against that.
118
+ e.preventDefault();
119
+ } else if (e.key === 'Escape') {
120
+ // Also suppress the browser's native "revert to last value" behavior
121
+ // for text inputs on Escape, which would otherwise race our own
122
+ // close-and-restore-label update and blank the field.
123
+ e.preventDefault();
124
+ popoverEl?.hidePopover();
125
+ }
126
+ }
127
+
128
+ // The trigger is a text input now, not a button, so it can't rely on the
129
+ // native `popovertarget` invoker exclusion to survive its own opening
130
+ // click (that relationship only applies to button-like elements — for a
131
+ // text input, the click that focuses it and opens the popover would
132
+ // immediately light-dismiss it again). `popover="manual"` opts out of
133
+ // that dismiss behavior entirely; this handler reimplements "close when
134
+ // focus leaves the widget" instead.
135
+ function onFocusOut(e: FocusEvent) {
136
+ const next = e.relatedTarget as Node | null;
137
+ if (!next || !containerEl?.contains(next)) {
138
+ popoverEl?.hidePopover();
139
+ }
140
+ }
141
+ </script>
142
+
143
+ <!--
144
+ The keydown/focusout handlers here are event delegation for the input and
145
+ popover option buttons below, not interaction with this div itself — every
146
+ actually-interactive element inside already has correct native semantics.
147
+ -->
148
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
149
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
150
+ <div class="relative w-full" bind:this={containerEl} onfocusout={onFocusOut} onkeydown={onKeydown}>
151
+ {#if name}
152
+ <input type="hidden" {name} {value} />
153
+ {/if}
154
+
155
+ <input
156
+ bind:this={inputEl}
157
+ {id}
158
+ type="text"
159
+ class="input input-bordered w-full font-normal"
160
+ class:input-error={!!error}
161
+ {disabled}
162
+ {placeholder}
163
+ value={open ? query : selectedLabel}
164
+ oninput={(e) => (query = e.currentTarget.value)}
165
+ onfocus={openPopover}
166
+ style="anchor-name:{anchorName}"
167
+ autocomplete="off"
168
+ />
169
+
170
+ <div
171
+ popover="manual"
172
+ id={popId}
173
+ bind:this={popoverEl}
174
+ style="position-anchor:{anchorName}; width:anchor-size(width); position-try-fallbacks:flip-block;"
175
+ class="dropdown mt-1 rounded-box border border-base-content/10 bg-base-100 shadow-lg"
176
+ ontoggle={onToggle}
177
+ >
178
+ <ul class="max-h-48 overflow-y-auto p-1">
179
+ <li>
180
+ <button
181
+ type="button"
182
+ class="w-full rounded-btn px-3 py-2 text-left text-sm text-base-content/40 hover:bg-base-200"
183
+ onclick={clear}
184
+ >
185
+ {placeholder}
186
+ </button>
187
+ </li>
188
+ {#if searching}
189
+ <li class="px-3 py-2 text-sm text-base-content/40">{strings.selectSearching}</li>
190
+ {/if}
191
+ {#each filtered as option (option.value)}
192
+ <li>
193
+ <button
194
+ type="button"
195
+ class="w-full rounded-btn px-3 py-2 text-left text-sm hover:bg-base-200"
196
+ class:bg-primary={value === option.value}
197
+ class:text-primary-content={value === option.value}
198
+ onclick={() => pick(option)}
199
+ >
200
+ {option.label}
201
+ </button>
202
+ </li>
203
+ {/each}
204
+ {#if !searching && filtered.length === 0}
205
+ <li class="px-3 py-2 text-sm text-base-content/40">{strings.selectNoResults}</li>
206
+ {/if}
207
+ </ul>
208
+ </div>
209
+ </div>
@@ -1,8 +1,15 @@
1
1
  <script lang="ts">
2
2
  import type { SelectOption } from '../../types/attribute.js';
3
- import { buildChildrenByParent, collectDescendantIds } from '../crud/utils/tree.js';
3
+ import {
4
+ buildChildrenByParent,
5
+ buildTreeSearchState,
6
+ collectDescendantIds
7
+ } from '../crud/utils/tree.js';
8
+ import { getStrings } from '../../i18n/context.js';
4
9
  import TreeNode from './TreeNode.svelte';
5
10
 
11
+ const strings = getStrings();
12
+
6
13
  let {
7
14
  name,
8
15
  value = $bindable([]),
@@ -10,6 +17,7 @@
10
17
  disabled = false,
11
18
  columns = 1,
12
19
  defaultExpanded = true,
20
+ searchable = true
13
21
  }: {
14
22
  name?: string;
15
23
  value?: string[];
@@ -17,11 +25,18 @@
17
25
  disabled?: boolean;
18
26
  columns?: number;
19
27
  defaultExpanded?: boolean;
28
+ searchable?: boolean;
20
29
  } = $props();
21
30
 
31
+ let query = $state('');
32
+
22
33
  const childrenByParent = $derived(buildChildrenByParent(options));
23
34
  const selected = $derived(new Set(value));
24
- const roots = $derived(childrenByParent.get(null) ?? []);
35
+ const searchState = $derived(buildTreeSearchState(query, childrenByParent));
36
+ const allRoots = $derived(childrenByParent.get(null) ?? []);
37
+ const roots = $derived(
38
+ searchState ? allRoots.filter((root) => searchState.visible.has(root.value)) : allRoots
39
+ );
25
40
 
26
41
  function toggle(nodeValue: string, checked: boolean) {
27
42
  const affected = [nodeValue, ...collectDescendantIds(nodeValue, childrenByParent)];
@@ -34,6 +49,17 @@
34
49
  }
35
50
  </script>
36
51
 
52
+ {#if searchable && options.length > 0}
53
+ <input
54
+ type="search"
55
+ class="input input-bordered input-sm mb-2 w-full"
56
+ placeholder={strings.searchPlaceholder}
57
+ bind:value={query}
58
+ {disabled}
59
+ aria-label={strings.searchPlaceholder}
60
+ />
61
+ {/if}
62
+
37
63
  <div
38
64
  class="overflow-y-auto rounded-box border border-base-300 p-2"
39
65
  style="max-height: var(--runeforge-tree-max-height, 24rem)"
@@ -44,11 +70,24 @@
44
70
  <input type="hidden" {name} value={JSON.stringify(value)} />
45
71
  {/if}
46
72
  {#if roots.length === 0}
47
- <p class="px-1 py-2 text-sm text-base-content/40">—</p>
73
+ <p class="px-1 py-2 text-sm text-base-content/40">
74
+ {searchState ? strings.selectNoResults : '—'}
75
+ </p>
48
76
  {/if}
49
77
  <div class:leaf-columns={columns > 1} style={`--columns: ${columns}`}>
50
78
  {#each roots as root (root.value)}
51
- <TreeNode node={root} {childrenByParent} {selected} onToggle={toggle} {disabled} depth={0} {columns} {defaultExpanded} />
79
+ <TreeNode
80
+ node={root}
81
+ {childrenByParent}
82
+ {selected}
83
+ onToggle={toggle}
84
+ {disabled}
85
+ depth={0}
86
+ {columns}
87
+ {defaultExpanded}
88
+ visible={searchState?.visible ?? null}
89
+ forceExpanded={searchState?.forceExpanded ?? null}
90
+ />
52
91
  {/each}
53
92
  </div>
54
93
  </div>
@@ -6,6 +6,7 @@ type $$ComponentProps = {
6
6
  disabled?: boolean;
7
7
  columns?: number;
8
8
  defaultExpanded?: boolean;
9
+ searchable?: boolean;
9
10
  };
10
11
  declare const Tree: import("svelte").Component<$$ComponentProps, {}, "value">;
11
12
  type Tree = ReturnType<typeof Tree>;