@selvajs/ui 4.3.0 → 4.5.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.
Files changed (80) hide show
  1. package/dist/components/compute/AppLayout.svelte +3 -3
  2. package/dist/components/compute/AppLayout.svelte.d.ts +2 -2
  3. package/dist/components/compute/ComputeApp.svelte +47 -140
  4. package/dist/components/compute/ComputeApp.svelte.d.ts +0 -16
  5. package/dist/components/compute/ComputeMessagesDialog.svelte +125 -0
  6. package/dist/components/compute/ComputeMessagesDialog.svelte.d.ts +10 -0
  7. package/dist/components/compute/ParameterPresetManager.svelte +25 -33
  8. package/dist/components/layout/PageFooter.svelte +22 -144
  9. package/dist/components/preview/Group.svelte +6 -3
  10. package/dist/components/preview/ImageOutput.svelte +1 -13
  11. package/dist/components/preview/OutputDisplay.svelte +6 -6
  12. package/dist/components/preview/TabLayout.svelte +6 -5
  13. package/dist/components/preview/inputs/FileInput.svelte +10 -19
  14. package/dist/composables/useFooterItem.svelte.d.ts +10 -12
  15. package/dist/composables/useFooterItem.svelte.js +9 -16
  16. package/dist/compute/computeThrottle.svelte.js +5 -2
  17. package/dist/compute/createSolveSession.svelte.d.ts +56 -0
  18. package/dist/compute/createSolveSession.svelte.js +122 -0
  19. package/dist/compute/solve-session-core.d.ts +45 -0
  20. package/dist/compute/solve-session-core.js +69 -0
  21. package/dist/constants.d.ts +0 -2
  22. package/dist/constants.js +0 -2
  23. package/dist/contexts/footerContext.svelte.d.ts +17 -5
  24. package/dist/contexts/footerContext.svelte.js +10 -2
  25. package/dist/external/storage.js +7 -23
  26. package/dist/index.d.ts +3 -1
  27. package/dist/index.js +5 -0
  28. package/dist/schema/param-exporter.d.ts +25 -1
  29. package/dist/schema/param-exporter.js +30 -27
  30. package/dist/schema/traversal.d.ts +1 -0
  31. package/dist/schema/traversal.js +5 -0
  32. package/dist/schema/visibility-rules.d.ts +12 -0
  33. package/dist/schema/visibility-rules.js +20 -0
  34. package/dist/types/solveFn.d.ts +1 -2
  35. package/dist/utils/file-download.d.ts +5 -17
  36. package/dist/utils/file-download.js +12 -19
  37. package/dist/utils/randomId.js +3 -19
  38. package/package.json +10 -26
  39. package/src/lib/components/compute/AppLayout.svelte +3 -3
  40. package/src/lib/components/compute/ComputeApp.svelte +47 -140
  41. package/src/lib/components/compute/ComputeMessagesDialog.svelte +125 -0
  42. package/src/lib/components/compute/ParameterPresetManager.svelte +25 -33
  43. package/src/lib/components/layout/PageFooter.svelte +22 -144
  44. package/src/lib/components/preview/Group.svelte +6 -3
  45. package/src/lib/components/preview/ImageOutput.svelte +1 -13
  46. package/src/lib/components/preview/OutputDisplay.svelte +6 -6
  47. package/src/lib/components/preview/TabLayout.svelte +6 -5
  48. package/src/lib/components/preview/inputs/FileInput.svelte +10 -19
  49. package/src/lib/composables/useFooterItem.svelte.ts +25 -25
  50. package/src/lib/compute/computeThrottle.svelte.ts +5 -2
  51. package/src/lib/compute/computeThrottle.test.ts +106 -0
  52. package/src/lib/compute/createSolveSession.svelte.ts +188 -0
  53. package/src/lib/compute/solve-session-core.test.ts +153 -0
  54. package/src/lib/compute/solve-session-core.ts +102 -0
  55. package/src/lib/constants.ts +0 -2
  56. package/src/lib/contexts/footerContext.svelte.ts +29 -14
  57. package/src/lib/external/storage.test.ts +99 -0
  58. package/src/lib/external/storage.ts +6 -22
  59. package/src/lib/index.ts +14 -1
  60. package/src/lib/schema/param-exporter.test.ts +136 -0
  61. package/src/lib/schema/param-exporter.ts +44 -30
  62. package/src/lib/schema/traversal.test.ts +92 -0
  63. package/src/lib/schema/traversal.ts +5 -0
  64. package/src/lib/schema/visibility-rules.test.ts +173 -0
  65. package/src/lib/schema/visibility-rules.ts +25 -0
  66. package/src/lib/types/solveFn.ts +1 -1
  67. package/src/lib/utils/file-download.ts +13 -20
  68. package/src/lib/utils/randomId.ts +3 -19
  69. package/dist/components/compute/ComputeMessages.svelte +0 -169
  70. package/dist/components/compute/ComputeMessages.svelte.d.ts +0 -7
  71. package/dist/components/compute/index.d.ts +0 -5
  72. package/dist/components/compute/index.js +0 -5
  73. package/dist/components/preview/index.d.ts +0 -3
  74. package/dist/components/preview/index.js +0 -4
  75. package/dist/components/viewer/index.d.ts +0 -3
  76. package/dist/components/viewer/index.js +0 -3
  77. package/src/lib/components/compute/ComputeMessages.svelte +0 -169
  78. package/src/lib/components/compute/index.ts +0 -5
  79. package/src/lib/components/preview/index.ts +0 -4
  80. package/src/lib/components/viewer/index.ts +0 -3
@@ -3,8 +3,8 @@
3
3
  import type { UISchema, ParameterPreset } from '@selvajs/schemas';
4
4
  import {
5
5
  createSavedState,
6
- validateSavedState,
7
- extractLoadableValues,
6
+ loadPreset,
7
+ type PresetLoadResult,
8
8
  exportStateAsJson,
9
9
  importStateFromJson
10
10
  } from '../../schema/param-exporter';
@@ -52,8 +52,8 @@
52
52
  // Import/validation state
53
53
  let showValidationDialog = $state(false);
54
54
  let showLoadDialog = $state(false);
55
- let importedState = $state<ParameterPreset | null>(null);
56
- let validationResult = $state<ReturnType<typeof validateSavedState> | null>(null);
55
+ let loadResult = $state<PresetLoadResult | null>(null);
56
+ let loadingPresetName = $state('');
57
57
  let fileInputRef = $state<HTMLInputElement | null>(null);
58
58
 
59
59
  // Listed states (when onListStates is provided)
@@ -90,15 +90,15 @@
90
90
  showExportDialog = false;
91
91
  }
92
92
 
93
- // Validate a preset, then either load it directly (no issues) or open the
93
+ // Load a preset in one pass, then either apply it directly (no issues) or open the
94
94
  // validation dialog (any errors or warnings). Shared by every load path.
95
95
  function tryLoad(preset: ParameterPreset) {
96
- const validation = validateSavedState(preset, schema);
97
- if (validation.isValid) {
98
- onLoadValues(extractLoadableValues(preset, schema, validation));
96
+ const result = loadPreset(preset, schema);
97
+ if (result.isValid) {
98
+ onLoadValues(result.values);
99
99
  } else {
100
- importedState = preset;
101
- validationResult = validation;
100
+ loadResult = result;
101
+ loadingPresetName = preset.name;
102
102
  showValidationDialog = true;
103
103
  }
104
104
  }
@@ -119,21 +119,16 @@
119
119
  }
120
120
 
121
121
  function confirmLoad() {
122
- if (!importedState || !validationResult) return;
123
-
124
- if (validationResult.canLoad) {
125
- const values = extractLoadableValues(importedState, schema, validationResult);
126
- onLoadValues(values);
127
- showValidationDialog = false;
128
- importedState = null;
129
- validationResult = null;
130
- }
122
+ if (!loadResult || !loadResult.canLoad) return;
123
+
124
+ onLoadValues(loadResult.values);
125
+ showValidationDialog = false;
126
+ loadResult = null;
131
127
  }
132
128
 
133
129
  function cancelImport() {
134
130
  showValidationDialog = false;
135
- importedState = null;
136
- validationResult = null;
131
+ loadResult = null;
137
132
  }
138
133
 
139
134
  async function openLoadDialog() {
@@ -288,16 +283,16 @@
288
283
  <Dialog.Header>
289
284
  <Dialog.Title>{t.validationTitle}</Dialog.Title>
290
285
  <Dialog.Description>
291
- {#if importedState}
292
- {t.validationValidatingPrefix}{importedState.name}
286
+ {#if loadingPresetName}
287
+ {t.validationValidatingPrefix}{loadingPresetName}
293
288
  {/if}
294
289
  </Dialog.Description>
295
290
  </Dialog.Header>
296
291
 
297
- {#if validationResult}
292
+ {#if loadResult}
298
293
  <div class="gap-4 py-4 grid">
299
294
  <!-- Summary Alert -->
300
- {#if validationResult.isValid}
295
+ {#if loadResult.isValid}
301
296
  <Card.Root class="p-4 border-success/30 bg-success/5">
302
297
  <div class="gap-3 flex items-start">
303
298
  <CheckCircle class="h-5 w-5 text-success" />
@@ -311,7 +306,7 @@
311
306
  </div>
312
307
  </div>
313
308
  </Card.Root>
314
- {:else if validationResult.canLoad}
309
+ {:else if loadResult.canLoad}
315
310
  <Card.Root class="p-4 border-warning/30 bg-warning/5">
316
311
  <div class="gap-3 flex items-start">
317
312
  <AlertTriangle class="h-5 w-5 text-warning" />
@@ -320,10 +315,7 @@
320
315
  {t.validationWarningsTitle}
321
316
  </h4>
322
317
  <p class="text-sm mt-1 text-warning-foreground/80">
323
- {t.validationWarningsBody.replace(
324
- '{count}',
325
- String(validationResult.issues.length)
326
- )}
318
+ {t.validationWarningsBody.replace('{count}', String(loadResult.issues.length))}
327
319
  </p>
328
320
  </div>
329
321
  </div>
@@ -343,10 +335,10 @@
343
335
  {/if}
344
336
 
345
337
  <!-- Issues List -->
346
- {#if !validationResult.isValid}
338
+ {#if !loadResult.isValid}
347
339
  <div class="space-y-2">
348
340
  <h4 class="text-sm font-medium">{t.validationIssuesHeading}</h4>
349
- {#each validationResult.issues as issue (issue.message)}
341
+ {#each loadResult.issues as issue (issue.message)}
350
342
  <div
351
343
  class="p-3 rounded-lg border {issue.severity === 'error'
352
344
  ? 'border-destructive/30 bg-destructive/5'
@@ -378,7 +370,7 @@
378
370
 
379
371
  <Dialog.Footer>
380
372
  <Button variant="outline" onclick={cancelImport}>{t.cancelButton}</Button>
381
- {#if validationResult?.canLoad}
373
+ {#if loadResult?.canLoad}
382
374
  <Button onclick={confirmLoad}>{t.loadAnywayButton}</Button>
383
375
  {/if}
384
376
  </Dialog.Footer>
@@ -1,10 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
- import * as Dialog from '$lib/components/primitives/dialog';
4
- import * as Collapsible from '$lib/components/primitives/collapsible';
5
- import { CircleAlert, TriangleAlert, ChevronDown, ChevronRight } from '@lucide/svelte';
6
- import { SvelteMap } from 'svelte/reactivity';
3
+ import { CircleAlert, TriangleAlert } from '@lucide/svelte';
7
4
  import { useFooter } from '$lib/contexts/footerContext.svelte';
5
+ import ComputeMessagesDialog from '../compute/ComputeMessagesDialog.svelte';
8
6
  import FooterItemRenderer from './FooterItemRenderer.svelte';
9
7
 
10
8
  interface Props {
@@ -48,31 +46,10 @@
48
46
  );
49
47
 
50
48
  let _currentYear = new Date().getFullYear();
51
- let dialogOpen = $state(false);
52
- let showErrors = $state(true);
53
- let showWarnings = $state(false);
54
49
 
55
50
  const hasMessages = $derived(errors.length > 0 || warnings.length > 0);
56
51
  const totalCount = $derived(errors.length + warnings.length);
57
52
 
58
- function groupMessages(messages: string[]): Array<{ message: string; count: number }> {
59
- const grouped = new SvelteMap<string, number>();
60
-
61
- for (const msg of messages) {
62
- // Extract the base message without the component GUID
63
- const baseMsg = msg.replace(/\([a-f0-9-]{36}\)$/i, '(...)').trim();
64
- const currentCount = grouped.get(baseMsg) || 0;
65
- grouped.set(baseMsg, currentCount + 1);
66
- }
67
-
68
- return Array.from(grouped.entries())
69
- .map(([message, count]) => ({ message, count }))
70
- .sort((a, b) => b.count - a.count);
71
- }
72
-
73
- const groupedErrors = $derived(groupMessages(errors));
74
- const groupedWarnings = $derived(groupMessages(warnings));
75
-
76
53
  const copyrightLine = $derived(
77
54
  footerText
78
55
  ? footerText.replace('{name}', copyrightName).replace('{year}', String(_currentYear))
@@ -91,131 +68,32 @@
91
68
  {/each}
92
69
 
93
70
  {#if hasMessages}
94
- <Dialog.Root bind:open={dialogOpen}>
95
- <Dialog.Trigger
96
- class="gap-1.5 px-2 py-1 rounded flex cursor-pointer items-center transition-colors hover:bg-muted {errors.length >
97
- 0
98
- ? 'text-destructive hover:bg-destructive/10'
99
- : 'text-warning hover:bg-warning/10'}"
100
- title={`${totalCount} ${totalCount === 1 ? 'issue' : 'issues'}`}
101
- >
102
- {#if errors.length > 0}
103
- <CircleAlert class="h-3.5 w-3.5" />
104
- <span class="font-medium">{errors.length} Error{errors.length !== 1 ? 's' : ''}</span>
105
- {/if}
106
-
107
- {#if warnings.length > 0}
71
+ <ComputeMessagesDialog {errors} {warnings}>
72
+ {#snippet trigger()}
73
+ <div
74
+ class="gap-1.5 px-2 py-1 rounded flex cursor-pointer items-center transition-colors hover:bg-muted {errors.length >
75
+ 0
76
+ ? 'text-destructive hover:bg-destructive/10'
77
+ : 'text-warning hover:bg-warning/10'}"
78
+ title={`${totalCount} ${totalCount === 1 ? 'issue' : 'issues'}`}
79
+ >
108
80
  {#if errors.length > 0}
109
- <span class="text-border">•</span>
81
+ <CircleAlert class="h-3.5 w-3.5" />
82
+ <span class="font-medium">{errors.length} Error{errors.length !== 1 ? 's' : ''}</span>
110
83
  {/if}
111
- <TriangleAlert class="h-3.5 w-3.5" />
112
- <span class="font-medium"
113
- >{warnings.length} Warning{warnings.length !== 1 ? 's' : ''}</span
114
- >
115
- {/if}
116
- </Dialog.Trigger>
117
84
 
118
- <Dialog.Content class="max-w-2xl max-h-[80vh]">
119
- <Dialog.Header>
120
- <Dialog.Title class="gap-2 flex items-center">
121
- <CircleAlert class="h-5 w-5" />
122
- Compute Messages
123
- </Dialog.Title>
124
- <Dialog.Description>
125
- {totalCount}
126
- {totalCount === 1 ? 'issue' : 'issues'} detected during solve
127
- </Dialog.Description>
128
- </Dialog.Header>
129
-
130
- <div class="space-y-3 pr-2 overflow-y-auto" style="max-height: calc(80vh - 180px);">
131
- <!-- Errors Section -->
132
- {#if errors.length > 0}
133
- <Collapsible.Root bind:open={showErrors}>
134
- <div class="overflow-hidden rounded-lg border border-destructive bg-card">
135
- <div class="px-4 py-3 flex items-center">
136
- <Collapsible.Trigger
137
- class="-mx-4 -my-3 gap-3 px-4 py-3 flex flex-1 items-center text-left transition-colors hover:bg-destructive/5"
138
- >
139
- {#if showErrors}
140
- <ChevronDown class="h-4 w-4 shrink-0 text-destructive" />
141
- {:else}
142
- <ChevronRight class="h-4 w-4 shrink-0 text-destructive" />
143
- {/if}
144
- <CircleAlert class="h-4 w-4 shrink-0 text-destructive" />
145
- <span class="text-sm font-medium text-destructive">
146
- {errors.length === 1 ? '1 Error' : `${errors.length} Errors`}
147
- </span>
148
- </Collapsible.Trigger>
149
- </div>
150
-
151
- <Collapsible.Content class="space-y-0">
152
- <div
153
- class="max-h-60 px-4 py-3 overflow-y-auto border-t border-destructive bg-card"
154
- >
155
- <ul class="space-y-2">
156
- {#each groupedErrors as { message, count } (message)}
157
- <li class="gap-2 text-sm flex text-destructive/90">
158
- <span class="shrink-0">•</span>
159
- <span class="flex-1">
160
- {message}
161
- {#if count > 1}
162
- <span class="ml-1 font-medium text-destructive/70">×{count} </span>
163
- {/if}
164
- </span>
165
- </li>
166
- {/each}
167
- </ul>
168
- </div>
169
- </Collapsible.Content>
170
- </div>
171
- </Collapsible.Root>
172
- {/if}
173
-
174
- <!-- Warnings Section -->
175
85
  {#if warnings.length > 0}
176
- <Collapsible.Root bind:open={showWarnings}>
177
- <div class="overflow-hidden rounded-lg border border-warning/50 bg-card">
178
- <div class="px-4 py-3 flex items-center">
179
- <Collapsible.Trigger
180
- class="-mx-4 -my-3 gap-3 px-4 py-3 flex flex-1 items-center text-left transition-colors hover:bg-warning/5"
181
- >
182
- {#if showWarnings}
183
- <ChevronDown class="h-4 w-4 shrink-0 text-warning" />
184
- {:else}
185
- <ChevronRight class="h-4 w-4 shrink-0 text-warning" />
186
- {/if}
187
- <TriangleAlert class="h-4 w-4 shrink-0 text-warning" />
188
- <span class="text-sm font-medium text-warning">
189
- {warnings.length === 1 ? '1 Warning' : `${warnings.length} Warnings`}
190
- </span>
191
- </Collapsible.Trigger>
192
- </div>
193
-
194
- <Collapsible.Content class="space-y-0">
195
- <div
196
- class="max-h-60 px-4 py-3 overflow-y-auto border-t border-warning/50 bg-card"
197
- >
198
- <ul class="space-y-2">
199
- {#each groupedWarnings as { message, count } (message)}
200
- <li class="gap-2 text-sm flex text-muted-foreground">
201
- <span class="shrink-0">•</span>
202
- <span class="flex-1">
203
- {message}
204
- {#if count > 1}
205
- <span class="ml-1 font-medium text-warning/70">×{count}</span>
206
- {/if}
207
- </span>
208
- </li>
209
- {/each}
210
- </ul>
211
- </div>
212
- </Collapsible.Content>
213
- </div>
214
- </Collapsible.Root>
86
+ {#if errors.length > 0}
87
+ <span class="text-border">•</span>
88
+ {/if}
89
+ <TriangleAlert class="h-3.5 w-3.5" />
90
+ <span class="font-medium"
91
+ >{warnings.length} Warning{warnings.length !== 1 ? 's' : ''}</span
92
+ >
215
93
  {/if}
216
94
  </div>
217
- </Dialog.Content>
218
- </Dialog.Root>
95
+ {/snippet}
96
+ </ComputeMessagesDialog>
219
97
  {/if}
220
98
 
221
99
  {#if children}
@@ -3,7 +3,7 @@
3
3
  import type { Snippet } from 'svelte';
4
4
  import * as Card from '$lib/components/primitives/card';
5
5
  import { ChevronDown } from '@lucide/svelte';
6
- import { evaluateVisibility } from '$lib/schema/visibility-rules';
6
+ import { buildVisibilityMap, itemKey } from '$lib/schema/visibility-rules';
7
7
 
8
8
  interface Props {
9
9
  label: string;
@@ -44,6 +44,9 @@
44
44
  }
45
45
  }
46
46
 
47
+ // One visibility evaluation per item per render; columnStarts and gridItem both read it.
48
+ const visibilityMap = $derived(buildVisibilityMap(items, values));
49
+
47
50
  /**
48
51
  * Compute the column position (0-indexed) where each item starts, accounting
49
52
  * for spans and linebreak resets. Items hidden by visibility don't consume
@@ -58,7 +61,7 @@
58
61
  col = 0;
59
62
  continue;
60
63
  }
61
- const visibility = evaluateVisibility(item, values);
64
+ const visibility = visibilityMap[itemKey(item)];
62
65
  if (!visibility.visible) {
63
66
  positions.push(0);
64
67
  continue;
@@ -120,7 +123,7 @@
120
123
  {#if layoutItem.type === 'linebreak'}
121
124
  <div style="grid-column: 1 / -1" class="h-px bg-border" aria-hidden="true"></div>
122
125
  {:else}
123
- {@const visibility = evaluateVisibility(layoutItem, values)}
126
+ {@const visibility = visibilityMap[itemKey(layoutItem)]}
124
127
  {@const span = Math.min(Math.max(1, layoutItem.span ?? 1), cols)}
125
128
  {#if visibility.visible}
126
129
  {#if layoutItem.type === 'input'}
@@ -2,7 +2,7 @@
2
2
  import type { OutputImageLayoutItem } from '@selvajs/schemas';
3
3
  import type { FileData } from '@selvajs/compute';
4
4
  import { Download, Maximize, Minimize } from '@lucide/svelte';
5
- import { downloadFiles } from '$lib/utils/file-download';
5
+ import { downloadFiles, isFileData, MIME_BY_EXT } from '$lib/utils/file-download';
6
6
 
7
7
  interface Props {
8
8
  item: OutputImageLayoutItem;
@@ -12,18 +12,6 @@
12
12
  let { item, value }: Props = $props();
13
13
 
14
14
  const SUPPORTED_EXTS = new Set(['.png', '.jpg', '.jpeg', '.webp', '.gif', '.svg']);
15
- const MIME_BY_EXT: Record<string, string> = {
16
- '.png': 'image/png',
17
- '.jpg': 'image/jpeg',
18
- '.jpeg': 'image/jpeg',
19
- '.webp': 'image/webp',
20
- '.gif': 'image/gif',
21
- '.svg': 'image/svg+xml'
22
- };
23
-
24
- function isFileData(x: unknown): x is FileData {
25
- return !!x && typeof x === 'object' && 'fileName' in x && 'data' in x && 'fileType' in x;
26
- }
27
15
 
28
16
  const file = $derived.by<FileData | null>(() => {
29
17
  if (Array.isArray(value)) return value.find(isFileData) ?? null;
@@ -3,7 +3,12 @@
3
3
  import type { FileData } from '@selvajs/compute';
4
4
  import ChartOutput from './ChartOutput.svelte';
5
5
  import ImageOutput from './ImageOutput.svelte';
6
- import { downloadFiles, formatFileSize, getBase64FileSize } from '$lib/utils/file-download';
6
+ import {
7
+ downloadFiles,
8
+ formatFileSize,
9
+ getBase64FileSize,
10
+ isFileData
11
+ } from '$lib/utils/file-download';
7
12
  import { Button } from '../primitives';
8
13
  import * as Dialog from '$lib/components/primitives/dialog';
9
14
  import { Info, Folder, FolderOpen, FileIcon, ChevronRight } from '@lucide/svelte';
@@ -46,10 +51,6 @@
46
51
  let downloading = $state(false);
47
52
  let downloadError = $state<string | null>(null);
48
53
 
49
- function isFileData(data: any): data is FileData {
50
- return data && typeof data === 'object' && 'fileName' in data && 'data' in data;
51
- }
52
-
53
54
  const filesArray = $derived(
54
55
  !value ? [] : Array.isArray(value) ? value.filter(isFileData) : isFileData(value) ? [value] : []
55
56
  );
@@ -114,7 +115,6 @@
114
115
  });
115
116
  const hasDuplicates = $derived(duplicatePaths.length > 0);
116
117
 
117
- // All folders expanded by default
118
118
  let expandedFolders = new SvelteSet<string>();
119
119
 
120
120
  $effect(() => {
@@ -4,7 +4,7 @@
4
4
  import * as Tabs from '$lib/components/primitives/tabs';
5
5
  import TabBar from './TabBar.svelte';
6
6
  import TabContent from './TabContent.svelte';
7
- import { evaluateVisibility } from '$lib/schema/visibility-rules';
7
+ import { buildVisibilityMap, itemKey } from '$lib/schema/visibility-rules';
8
8
 
9
9
  interface Props {
10
10
  schema: UISchema;
@@ -64,17 +64,18 @@
64
64
  if (schema.layout.type !== 'tabbed') return;
65
65
  const updates: Record<string, unknown> = {};
66
66
  visibleTabs.forEach((tab) =>
67
- tab.groups.forEach((group) =>
67
+ tab.groups.forEach((group) => {
68
+ const visibilityMap = buildVisibilityMap(group.items, values);
68
69
  group.items.forEach((layoutItem) => {
69
70
  if (layoutItem.type === 'linebreak') return;
70
- const { visible, disabled, defaultValue } = evaluateVisibility(layoutItem, values);
71
+ const { visible, disabled, defaultValue } = visibilityMap[itemKey(layoutItem)];
71
72
  const input = schema.inputs.find((i) => i.id === layoutItem.paramId);
72
73
  if (!input || defaultValue === undefined) return;
73
74
  if ((!visible || disabled) && values[input.id] !== defaultValue) {
74
75
  updates[input.id] = defaultValue;
75
76
  }
76
- })
77
- )
77
+ });
78
+ })
78
79
  );
79
80
  if (Object.keys(updates).length > 0) Object.assign(values, updates);
80
81
  });
@@ -41,7 +41,7 @@
41
41
  let urlInput = $state('');
42
42
  let isDragging = $state(false);
43
43
  let isLoading = $state(false);
44
- let urlError = $state<{ message: string; isCors: boolean } | null>(null);
44
+ let urlError = $state<{ message: string; isCors: boolean; hint?: string } | null>(null);
45
45
  let urlSuccess = $state('');
46
46
 
47
47
  // Parse existing value if it's JSON
@@ -88,26 +88,22 @@
88
88
  async function handleUrlChange() {
89
89
  if (!urlInput.trim()) return;
90
90
 
91
- // Reset all state before starting a new fetch
92
91
  isLoading = true;
93
92
  urlError = null;
94
93
  urlSuccess = '';
95
94
  uploadedFileName = '';
96
95
 
97
96
  try {
98
- // Validate URL format first
99
97
  let parsedUrl: URL;
100
98
  try {
101
99
  parsedUrl = new URL(urlInput);
102
100
  } catch {
103
101
  urlError = { message: 'Invalid URL — make sure it starts with https://', isCors: false };
104
- isLoading = false;
105
102
  return;
106
103
  }
107
104
 
108
105
  if (parsedUrl.protocol !== 'https:' && parsedUrl.protocol !== 'http:') {
109
106
  urlError = { message: 'Only http:// and https:// URLs are supported.', isCors: false };
110
- isLoading = false;
111
107
  return;
112
108
  }
113
109
 
@@ -117,7 +113,6 @@
117
113
  message: `Server returned ${response.status} ${response.statusText}. Check the URL is correct and publicly accessible.`,
118
114
  isCors: false
119
115
  };
120
- isLoading = false;
121
116
  return;
122
117
  }
123
118
 
@@ -129,7 +124,6 @@
129
124
  message: `File format "${fileEnding}" is not accepted. Allowed: ${acceptedFormats.join(', ')}`,
130
125
  isCors: false
131
126
  };
132
- isLoading = false;
133
127
  return;
134
128
  }
135
129
 
@@ -139,24 +133,22 @@
139
133
  message: `File too large: ${(blob.size / 1024 / 1024).toFixed(2)}MB (max ${APP_DEFAULTS.FILE_UPLOAD.MAX_SIZE_MB}MB). Download it and use Upload instead.`,
140
134
  isCors: false
141
135
  };
142
- isLoading = false;
143
136
  return;
144
137
  }
145
138
 
146
- await new Promise<void>((resolve, reject) => {
139
+ const base64Data = await new Promise<string>((resolve, reject) => {
147
140
  const reader = new FileReader();
148
141
  reader.onload = (e) => {
149
- const base64 = e.target?.result as string;
150
- const base64Data = base64.includes(',') ? base64.split(',')[1] : base64;
151
- const data = JSON.stringify({ file: base64Data, type: 'base64', fileEnding });
152
- value = data;
153
- urlSuccess = `Loaded ${fileEnding} (${(blob.size / 1024).toFixed(0)} KB)`;
154
- onChange(data);
155
- resolve();
142
+ const result = e.target?.result as string;
143
+ resolve(result.includes(',') ? result.split(',')[1] : result);
156
144
  };
157
145
  reader.onerror = () => reject(new Error('Failed to read the downloaded file.'));
158
146
  reader.readAsDataURL(blob);
159
147
  });
148
+ const data = JSON.stringify({ file: base64Data, type: 'base64', fileEnding });
149
+ value = data;
150
+ urlSuccess = `Loaded ${fileEnding} (${(blob.size / 1024).toFixed(0)} KB)`;
151
+ onChange(data);
160
152
  } catch (error) {
161
153
  if (isCorsError(error)) {
162
154
  const host = (() => {
@@ -184,7 +176,6 @@
184
176
  urlError = {
185
177
  message: `Could not reach "${host}" — the file may not exist, or the server does not allow browser access.`,
186
178
  isCors: true,
187
- // @ts-expect-error hint is properly typed at runtime
188
179
  hint
189
180
  };
190
181
  } else {
@@ -328,8 +319,8 @@
328
319
  <CircleAlert size={13} class="mt-0.5 shrink-0 text-destructive" />
329
320
  <p class="text-xs leading-snug text-destructive">{urlError.message}</p>
330
321
  </div>
331
- {#if urlError.isCors && (urlError as any).hint}
332
- <p class="text-xs leading-snug pl-5 text-muted-foreground">{(urlError as any).hint}</p>
322
+ {#if urlError.isCors && urlError.hint}
323
+ <p class="text-xs leading-snug pl-5 text-muted-foreground">{urlError.hint}</p>
333
324
  {/if}
334
325
  </div>
335
326
  {/if}
@@ -1,40 +1,40 @@
1
- import { getContext, onMount, onDestroy } from 'svelte';
2
- import { type FooterStore, FOOTER_CONTEXT_KEY } from '$lib/contexts/footerContext.svelte';
1
+ import { getContext, onMount, onDestroy, type Component } from 'svelte';
2
+ import {
3
+ type FooterStore,
4
+ type FooterItem,
5
+ FOOTER_CONTEXT_KEY
6
+ } from '$lib/contexts/footerContext.svelte';
7
+
8
+ /** Config for a footer-item registration; generic over the component's props. */
9
+ export type FooterItemConfig<P extends Record<string, unknown> = Record<string, unknown>> = Omit<
10
+ FooterItem<P>,
11
+ 'position' | 'priority'
12
+ > &
13
+ Partial<Pick<FooterItem<P>, 'position' | 'priority'>>;
3
14
 
4
15
  /**
5
- * Register a footer item component that reactively updates its props.
6
- * The `getProps` function is called on every render, so returning reactive state
7
- * (e.g. `() => ({ status: myState.status })`) will keep the footer in sync.
8
- *
9
- * Registration is deferred to onMount (client-side only) to avoid SSR context errors.
16
+ * Register a footer item for the lifetime of the calling component.
10
17
  *
11
- * @param id - Unique identifier for this footer item
12
- * @param component - Svelte component to render
13
- * @param getProps - Function returning current props (called reactively)
14
- * @param position - Where to display ('left' or 'right'), defaults to 'left'
15
- * @param priority - Higher values render first within their position
16
- * @param onClick - Optional click handler (e.g. open a popup/dialog)
18
+ * Registration is deferred to onMount (client-side only) to avoid SSR context errors;
19
+ * it's unregistered on destroy. A no-op when no footer context is present (e.g. a
20
+ * component rendered outside the root layout) or no component is supplied.
17
21
  */
18
- export function useFooterItem(
19
- id: string,
20
- component: any,
21
- getProps: () => Record<string, any>,
22
- position: 'left' | 'right' = 'left',
23
- priority: number = 0,
24
- onClick?: () => void
25
- ) {
22
+ export function useFooterItem<P extends Record<string, unknown>>(config: FooterItemConfig<P>) {
26
23
  onMount(() => {
27
24
  const store = getContext<FooterStore | undefined>(FOOTER_CONTEXT_KEY);
28
- if (!store || !component) return;
29
- store.register(id, component, getProps, position, priority, onClick);
25
+ if (!store || !config.component) return;
26
+ store.register(config);
30
27
  });
31
28
 
32
29
  onDestroy(() => {
33
30
  try {
34
31
  const store = getContext<FooterStore | undefined>(FOOTER_CONTEXT_KEY);
35
- store?.unregister(id);
32
+ store?.unregister(config.id);
36
33
  } catch {
37
- // Context may not exist during SSR cleanup — safe to ignore
34
+ // Context may not exist during SSR cleanup — safe to ignore.
38
35
  }
39
36
  });
40
37
  }
38
+
39
+ // Re-export for callers that type their component prop explicitly.
40
+ export type { Component };
@@ -55,8 +55,11 @@ export function createComputeThrottle<T>(
55
55
  try {
56
56
  await computeFn(values, signal);
57
57
  } catch (err) {
58
- if (!(err instanceof Error && err.name === 'AbortError')) {
59
- throw err;
58
+ // AbortError is expected (timeout or cancel). Non-abort errors must be
59
+ // handled inside computeFn — re-throwing here would produce an unhandled
60
+ // rejection because executeCompute is always called fire-and-forget.
61
+ if (!(err instanceof Error) || (err.name !== 'AbortError' && err.name !== 'TimeoutError')) {
62
+ console.error('[computeThrottle] unhandled error in computeFn:', err);
60
63
  }
61
64
  } finally {
62
65
  clearTimeout(timeoutId);