@warkypublic/svelix 0.1.46 → 0.2.1
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.
- package/README.md +93 -33
- package/dist/components/BetterMenu/BetterMenu.svelte +21 -37
- package/dist/components/BetterMenu/BetterMenuAsyncButton.svelte +21 -31
- package/dist/components/BetterMenu/BetterMenuPreview.svelte +27 -29
- package/dist/components/BetterMenu/MenuRenderer.svelte +40 -51
- package/dist/components/Boxer/Boxer.svelte +492 -602
- package/dist/components/Boxer/BoxerTarget.svelte +6 -46
- package/dist/components/Boxer/BoxerTarget.svelte.d.ts +1 -0
- package/dist/components/Boxer/types.d.ts +0 -1
- package/dist/components/Button.svelte +19 -43
- package/dist/components/ButtonPreview.svelte +2 -11
- package/dist/components/CardGrid/CardGrid.svelte +489 -614
- package/dist/components/CardGrid/CardGrid.svelte.d.ts +4 -0
- package/dist/components/CardGrid/CardGridFilterPanel.svelte +111 -90
- package/dist/components/CardGrid/DefaultCard.svelte +86 -97
- package/dist/components/CardGrid/DefaultCard.svelte.d.ts +1 -0
- package/dist/components/CardGrid/ImageCardStory.svelte +87 -36
- package/dist/components/CardGrid/cardGrid.d.ts +24 -0
- package/dist/components/CardGrid/cardGrid.js +20 -0
- package/dist/components/ContentEditor/CollaboraInsertTextDemo.svelte +5 -10
- package/dist/components/ContentEditor/ContentEditor.svelte +24 -50
- package/dist/components/ContentEditor/subcomponents/AudioPlayer.svelte +17 -17
- package/dist/components/ContentEditor/subcomponents/CollaboraEditor.svelte +244 -309
- package/dist/components/ContentEditor/subcomponents/EmailViewer.svelte +2 -3
- package/dist/components/ContentEditor/subcomponents/ImageViewer.svelte +14 -15
- package/dist/components/ContentEditor/subcomponents/MarkdownViewer.svelte +74 -90
- package/dist/components/ContentEditor/subcomponents/MonacoEditor.svelte +75 -103
- package/dist/components/ContentEditor/subcomponents/Office365Editor.svelte +234 -297
- package/dist/components/ContentEditor/subcomponents/PdfViewer.svelte +14 -20
- package/dist/components/ContentEditor/subcomponents/TextEditor.svelte +122 -150
- package/dist/components/ContentEditor/subcomponents/UnknownFile.svelte +105 -126
- package/dist/components/ContentEditor/subcomponents/VideoPlayer.svelte +17 -17
- package/dist/components/ContentEditor/subcomponents/ZipViewer.svelte +2 -3
- package/dist/components/ErrorBoundary/ErrorBoundary.svelte +41 -58
- package/dist/components/ErrorBoundary/ErrorBoundaryPreview.svelte +8 -16
- package/dist/components/Former/Former.svelte +306 -424
- package/dist/components/Former/FormerButtonArea.svelte +17 -68
- package/dist/components/Former/FormerDrawer.svelte +16 -80
- package/dist/components/Former/FormerDrawerPreview.svelte +99 -89
- package/dist/components/Former/FormerModal.svelte +16 -74
- package/dist/components/Former/FormerModalPreview.svelte +99 -89
- package/dist/components/Former/FormerPreview.svelte +76 -78
- package/dist/components/Former/FormerRestApiPreview.svelte +55 -48
- package/dist/components/Former/formerOverlayHelpers.svelte.d.ts +11 -0
- package/dist/components/Former/formerOverlayHelpers.svelte.js +38 -0
- package/dist/components/Former/index.d.ts +1 -0
- package/dist/components/Former/index.js +1 -0
- package/dist/components/FormerControllers/ButtonCtrl.svelte +13 -49
- package/dist/components/FormerControllers/CtrlFieldShell.svelte +15 -0
- package/dist/components/FormerControllers/CtrlFieldShell.svelte.d.ts +12 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.svelte +285 -457
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlCalendar.svelte +95 -136
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlPickerPanel.svelte +3 -62
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlTimeFields.svelte +143 -217
- package/dist/components/FormerControllers/IconButtonCtrl.svelte +13 -47
- package/dist/components/FormerControllers/InlineWrapper.svelte +12 -41
- package/dist/components/FormerControllers/InlineWrapperPreview.svelte +4 -26
- package/dist/components/FormerControllers/NativeSelectCtrl.svelte +7 -39
- package/dist/components/FormerControllers/NumberInputCtrl.svelte +21 -43
- package/dist/components/FormerControllers/PasswordInputCtrl.svelte +8 -33
- package/dist/components/FormerControllers/SwitchCtrl.svelte +4 -20
- package/dist/components/FormerControllers/TextAreaCtrl.svelte +7 -34
- package/dist/components/FormerControllers/TextInputCtrl.svelte +7 -34
- package/dist/components/FormerControllers/ctrlLoading.svelte.d.ts +8 -0
- package/dist/components/FormerControllers/ctrlLoading.svelte.js +43 -0
- package/dist/components/FormerControllers/index.d.ts +2 -0
- package/dist/components/FormerControllers/index.js +2 -0
- package/dist/components/FormerControllers/utils.d.ts +1 -0
- package/dist/components/FormerControllers/utils.js +3 -0
- package/dist/components/GlobalStateStore/GlobalStateStoreProvider.svelte +73 -120
- package/dist/components/Gridler/components/Gridler.svelte +344 -442
- package/dist/components/Gridler/components/GridlerCanvas.svelte +720 -1115
- package/dist/components/Gridler/components/GridlerEditor.svelte +2 -15
- package/dist/components/Gridler/components/GridlerFull.svelte +521 -841
- package/dist/components/Gridler/components/GridlerFull.svelte.d.ts +1 -1
- package/dist/components/Gridler/components/GridlerFullWithFormerPreview.svelte +194 -147
- package/dist/components/Gridler/components/GridlerSearch.svelte +7 -16
- package/dist/components/Gridler/components/GridlerSearchToggle.svelte +7 -19
- package/dist/components/Gridler/types.d.ts +1 -1
- package/dist/components/Gridler/utils/serverPaging.d.ts +1 -0
- package/dist/components/Gridler/utils/serverPaging.js +7 -0
- package/dist/components/Icons/IconAdd.svelte +1 -3
- package/dist/components/Icons/IconAlertCircle.svelte +1 -3
- package/dist/components/Icons/IconAlertTriangle.svelte +1 -3
- package/dist/components/Icons/IconCamera.svelte +1 -3
- package/dist/components/Icons/IconClose.svelte +1 -3
- package/dist/components/Icons/IconEdit.svelte +1 -3
- package/dist/components/Icons/IconFilter.svelte +1 -3
- package/dist/components/Icons/IconSearch.svelte +1 -3
- package/dist/components/Icons/IconSort.svelte +1 -3
- package/dist/components/Icons/IconTrash.svelte +1 -3
- package/dist/components/Portal/Portal.svelte +14 -38
- package/dist/components/Screenshot/Screenshot.svelte +7 -13
- package/dist/components/Svark/Svark.svelte +680 -852
- package/dist/components/Svark/SvarkContextMenu.svelte +44 -63
- package/dist/components/Svark/SvarkInfiniteLoader.svelte +2 -6
- package/dist/components/Svark/SvarkPager.svelte +2 -28
- package/dist/components/Svark/SvarkSelectionDemo.svelte +4 -8
- package/dist/components/Svark/SvarkTopBar.svelte +9 -74
- package/dist/components/SvarkGrid/SvarkGrid.svelte +877 -1123
- package/dist/components/SvarkGrid/components/SvarkColumnFilterForm.svelte +45 -58
- package/dist/components/SvarkGrid/components/SvarkContextMenu.svelte +44 -63
- package/dist/components/SvarkGrid/components/SvarkHeaderFilterCell.svelte +41 -75
- package/dist/components/SvarkGrid/components/SvarkInfiniteLoader.svelte +2 -6
- package/dist/components/SvarkGrid/components/SvarkPager.svelte +2 -28
- package/dist/components/SvarkGrid/components/SvarkSearchPopover.svelte +8 -16
- package/dist/components/SvarkGrid/components/SvarkTopBar.svelte +6 -62
- package/dist/components/SvarkGrid/internal/SvarkGridView.svelte +345 -507
- package/dist/components/VTree/VTree.svelte +454 -431
- package/dist/components/VTree/VTree.utils.d.ts +23 -0
- package/dist/components/VTree/VTree.utils.js +73 -0
- package/dist/components/VTree/VTreeContextMenu.svelte +21 -33
- package/dist/components/VTree/VTreeControlledSelectionDemo.svelte +20 -0
- package/dist/components/VTree/VTreeControlledSelectionDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeCustomizationDemo.svelte +23 -0
- package/dist/components/VTree/VTreeCustomizationDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeEventsDemo.svelte +48 -58
- package/dist/components/VTree/VTreeInteractionDemo.svelte +29 -0
- package/dist/components/VTree/VTreeInteractionDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeMultiSelectDemo.svelte +27 -0
- package/dist/components/VTree/VTreeMultiSelectDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeRow.svelte +77 -115
- package/dist/components/VTree/VTreeRow.svelte.d.ts +34 -18
- package/dist/components/VTree/VTreeSearch.svelte +6 -13
- package/dist/components/VTree/VTreeVirtualViewport.svelte +54 -143
- package/dist/components/VTree/VTreeVirtualViewport.svelte.d.ts +35 -18
- package/dist/components/VTree/types.d.ts +39 -1
- package/llm/COMPONENT_GUIDE.md +25 -0
- package/package.json +51 -50
|
@@ -1,427 +1,309 @@
|
|
|
1
|
-
<script lang="ts"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
values = data;
|
|
309
|
-
initialValues = JSON.parse(JSON.stringify(data));
|
|
310
|
-
dirty = false;
|
|
311
|
-
onChange?.(data, getAllState());
|
|
312
|
-
handleClose(data);
|
|
313
|
-
return data;
|
|
314
|
-
} catch (e) {
|
|
315
|
-
const msg = (e as Error)?.message ?? String(e);
|
|
316
|
-
error = msg;
|
|
317
|
-
onError?.(msg, getAllState());
|
|
318
|
-
} finally {
|
|
319
|
-
loading = false;
|
|
320
|
-
}
|
|
321
|
-
return undefined;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
async function reset(): Promise<void> {
|
|
325
|
-
if (request !== "insert") {
|
|
326
|
-
await load(true);
|
|
327
|
-
} else {
|
|
328
|
-
values = initialValues
|
|
329
|
-
? JSON.parse(JSON.stringify(initialValues))
|
|
330
|
-
: undefined;
|
|
331
|
-
dirty = false;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function handleClose(data?: any) {
|
|
336
|
-
if (dirty) {
|
|
337
|
-
if (
|
|
338
|
-
!confirm("You have unsaved changes. Are you sure you want to close?")
|
|
339
|
-
) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (onClose) {
|
|
344
|
-
onClose(data);
|
|
345
|
-
} else {
|
|
346
|
-
opened = false;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// Load data when opened changes (for non-insert modes).
|
|
351
|
-
// untrack() prevents reactive reads inside load() (values, onAPICall, etc.)
|
|
352
|
-
// from being tracked by this effect, which would cause a re-fetch every time
|
|
353
|
-
// load() writes back to values after a successful GET.
|
|
354
|
-
$effect(() => {
|
|
355
|
-
if (mounted && opened && request && request !== "insert") {
|
|
356
|
-
untrack(() => load(true));
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
const formerState: FormerState = {
|
|
361
|
-
get deleteConfirmed() {
|
|
362
|
-
return deleteConfirmed;
|
|
363
|
-
},
|
|
364
|
-
get dirty() {
|
|
365
|
-
return dirty;
|
|
366
|
-
},
|
|
367
|
-
get error() {
|
|
368
|
-
return error;
|
|
369
|
-
},
|
|
370
|
-
getAllState,
|
|
371
|
-
getState,
|
|
372
|
-
load,
|
|
373
|
-
get loading() {
|
|
374
|
-
return loading;
|
|
375
|
-
},
|
|
376
|
-
get opened() {
|
|
377
|
-
return opened;
|
|
378
|
-
},
|
|
379
|
-
get primeData() {
|
|
380
|
-
return primeData;
|
|
381
|
-
},
|
|
382
|
-
get request() {
|
|
383
|
-
return request;
|
|
384
|
-
},
|
|
385
|
-
reset,
|
|
386
|
-
save,
|
|
387
|
-
setRequest,
|
|
388
|
-
setState,
|
|
389
|
-
validate,
|
|
390
|
-
get values() {
|
|
391
|
-
return values;
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
// Exposed methods for bind:this
|
|
396
|
-
export async function show(): Promise<void> {
|
|
397
|
-
opened = true;
|
|
398
|
-
onOpen?.(values);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
export async function close(): Promise<void> {
|
|
402
|
-
handleClose(values);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
export async function saveForm(): Promise<any> {
|
|
406
|
-
return save();
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export async function validateForm(): Promise<boolean> {
|
|
410
|
-
return validate();
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
export function resetForm(): void {
|
|
414
|
-
reset();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export function getValue(): any {
|
|
418
|
-
return values;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export function setValue(val: any): void {
|
|
422
|
-
values = val;
|
|
423
|
-
onChange?.(val, getAllState());
|
|
424
|
-
}
|
|
1
|
+
<script lang="ts">/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { untrack } from "svelte";
|
|
3
|
+
import FormerButtonArea from "./FormerButtonArea.svelte";
|
|
4
|
+
import { getUUID } from "@warkypublic/artemis-kit/strings";
|
|
5
|
+
let { afterGet, afterSave, beforeGet, beforeSave, children, id = getUUID(), keepOpen = $bindable(false), layout, mounted = true, onAPICall, onChange, onClose, onConfirmDelete, onError, onOpen, opened = $bindable(false), primeData, request = $bindable("insert"), uniqueKeyField = "id", values = $bindable(undefined) } = $props();
|
|
6
|
+
// Internal state
|
|
7
|
+
let loading = $state(false);
|
|
8
|
+
let error = $state(undefined);
|
|
9
|
+
let dirty = $state(false);
|
|
10
|
+
let deleteConfirmed = $state(false);
|
|
11
|
+
// Track initial values for dirty detection
|
|
12
|
+
let initialValues = $state(undefined);
|
|
13
|
+
// Snapshot initial values once when the form opens.
|
|
14
|
+
// untrack() prevents values/primeData reads from being tracked — only the
|
|
15
|
+
// opened transition should trigger re-initialization.
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (!mounted) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (opened) {
|
|
21
|
+
untrack(() => {
|
|
22
|
+
if (initialValues === undefined) {
|
|
23
|
+
if (values !== undefined) {
|
|
24
|
+
initialValues = JSON.parse(JSON.stringify(values));
|
|
25
|
+
} else if (primeData !== undefined) {
|
|
26
|
+
initialValues = JSON.parse(JSON.stringify(primeData));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
// Reset when form closes so re-opens start fresh.
|
|
32
|
+
initialValues = undefined;
|
|
33
|
+
dirty = false;
|
|
34
|
+
deleteConfirmed = false;
|
|
35
|
+
error = undefined;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
// Track dirty state
|
|
39
|
+
$effect(() => {
|
|
40
|
+
if (!mounted) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (initialValues !== undefined && values !== undefined) {
|
|
44
|
+
dirty = JSON.stringify(values) !== JSON.stringify(initialValues);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
function getState(key) {
|
|
48
|
+
const state = getAllState();
|
|
49
|
+
return state[key];
|
|
50
|
+
}
|
|
51
|
+
function getAllState() {
|
|
52
|
+
return {
|
|
53
|
+
afterGet,
|
|
54
|
+
afterSave,
|
|
55
|
+
beforeGet,
|
|
56
|
+
beforeSave,
|
|
57
|
+
deleteConfirmed,
|
|
58
|
+
dirty,
|
|
59
|
+
error,
|
|
60
|
+
getAllState,
|
|
61
|
+
getState,
|
|
62
|
+
keepOpen,
|
|
63
|
+
layout,
|
|
64
|
+
load,
|
|
65
|
+
loading,
|
|
66
|
+
onAPICall,
|
|
67
|
+
onChange,
|
|
68
|
+
onClose: handleClose,
|
|
69
|
+
onConfirmDelete,
|
|
70
|
+
onError,
|
|
71
|
+
onOpen,
|
|
72
|
+
opened,
|
|
73
|
+
primeData,
|
|
74
|
+
request,
|
|
75
|
+
reset,
|
|
76
|
+
save,
|
|
77
|
+
setRequest,
|
|
78
|
+
setState,
|
|
79
|
+
uniqueKeyField,
|
|
80
|
+
validate,
|
|
81
|
+
values
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function setState(key, value) {
|
|
85
|
+
if (key === "opened") opened = value;
|
|
86
|
+
else if (key === "values") values = value;
|
|
87
|
+
else if (key === "request") request = value;
|
|
88
|
+
else if (key === "keepOpen") keepOpen = value;
|
|
89
|
+
else if (key === "loading") loading = value;
|
|
90
|
+
else if (key === "error") error = value;
|
|
91
|
+
else if (key === "dirty") dirty = value;
|
|
92
|
+
else if (key === "deleteConfirmed") deleteConfirmed = value;
|
|
93
|
+
}
|
|
94
|
+
function setRequest(r) {
|
|
95
|
+
request = r;
|
|
96
|
+
}
|
|
97
|
+
async function validate() {
|
|
98
|
+
if (!mounted) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
// With native HTML form validation, check validity
|
|
102
|
+
const form = document.getElementById(`former_f${id}`);
|
|
103
|
+
if (form) {
|
|
104
|
+
return form.reportValidity();
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
async function load(reset) {
|
|
109
|
+
if (!mounted) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
loading = true;
|
|
114
|
+
error = undefined;
|
|
115
|
+
// Base data for "load" comes from existing values or primeData.
|
|
116
|
+
// If `beforeGet` is provided, it can normalize/augment this data even
|
|
117
|
+
// when no API call is configured.
|
|
118
|
+
let inData = values !== undefined ? { ...values } : primeData !== undefined ? { ...primeData } : values;
|
|
119
|
+
if (beforeGet) {
|
|
120
|
+
const modified = await beforeGet(inData, getAllState());
|
|
121
|
+
if (modified !== undefined) inData = modified;
|
|
122
|
+
}
|
|
123
|
+
const keyValue = inData?.[uniqueKeyField] ?? primeData?.[uniqueKeyField];
|
|
124
|
+
if (onAPICall && keyValue !== undefined) {
|
|
125
|
+
let data = await onAPICall("read", request ?? "insert", inData, keyValue);
|
|
126
|
+
if (afterGet) {
|
|
127
|
+
const result = await afterGet(data, getAllState());
|
|
128
|
+
if (result !== undefined) data = result;
|
|
129
|
+
}
|
|
130
|
+
values = data;
|
|
131
|
+
onChange?.(data, getAllState());
|
|
132
|
+
} else if (beforeGet) {
|
|
133
|
+
// No API call: still apply `beforeGet` output to the form values.
|
|
134
|
+
values = inData;
|
|
135
|
+
onChange?.(inData, getAllState());
|
|
136
|
+
}
|
|
137
|
+
if (reset) {
|
|
138
|
+
initialValues = values ? JSON.parse(JSON.stringify(values)) : undefined;
|
|
139
|
+
dirty = false;
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
const msg = e?.message ?? String(e);
|
|
143
|
+
error = msg;
|
|
144
|
+
onError?.(msg, getAllState());
|
|
145
|
+
} finally {
|
|
146
|
+
loading = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function save() {
|
|
150
|
+
if (!mounted) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
loading = true;
|
|
155
|
+
error = undefined;
|
|
156
|
+
let data = values ? { ...values } : {};
|
|
157
|
+
if (beforeSave) {
|
|
158
|
+
const modified = await beforeSave(data, getAllState());
|
|
159
|
+
if (modified !== undefined) data = modified;
|
|
160
|
+
}
|
|
161
|
+
if (request === "delete" && !deleteConfirmed) {
|
|
162
|
+
const confirmed = onConfirmDelete ? await onConfirmDelete(data) : confirm("Are you sure you want to delete this item?");
|
|
163
|
+
if (!confirmed) {
|
|
164
|
+
loading = false;
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
deleteConfirmed = true;
|
|
168
|
+
}
|
|
169
|
+
if (onAPICall) {
|
|
170
|
+
const keyValue = values?.[uniqueKeyField] ?? primeData?.[uniqueKeyField];
|
|
171
|
+
const savedData = await onAPICall("mutate", request ?? "insert", data, keyValue);
|
|
172
|
+
const newData = {
|
|
173
|
+
...data,
|
|
174
|
+
...savedData
|
|
175
|
+
};
|
|
176
|
+
if (afterSave) {
|
|
177
|
+
await afterSave(newData, getAllState());
|
|
178
|
+
}
|
|
179
|
+
if (keepOpen) {
|
|
180
|
+
const clearedData = { ...newData };
|
|
181
|
+
delete clearedData[uniqueKeyField];
|
|
182
|
+
values = clearedData;
|
|
183
|
+
initialValues = JSON.parse(JSON.stringify(clearedData));
|
|
184
|
+
dirty = false;
|
|
185
|
+
deleteConfirmed = false;
|
|
186
|
+
onChange?.(clearedData, getAllState());
|
|
187
|
+
return newData;
|
|
188
|
+
}
|
|
189
|
+
values = newData;
|
|
190
|
+
initialValues = JSON.parse(JSON.stringify(newData));
|
|
191
|
+
dirty = false;
|
|
192
|
+
onChange?.(newData, getAllState());
|
|
193
|
+
handleClose(newData);
|
|
194
|
+
return newData;
|
|
195
|
+
}
|
|
196
|
+
if (keepOpen) {
|
|
197
|
+
const clearedData = { ...data };
|
|
198
|
+
delete clearedData[uniqueKeyField];
|
|
199
|
+
values = clearedData;
|
|
200
|
+
initialValues = JSON.parse(JSON.stringify(clearedData));
|
|
201
|
+
dirty = false;
|
|
202
|
+
onChange?.(clearedData, getAllState());
|
|
203
|
+
return data;
|
|
204
|
+
}
|
|
205
|
+
values = data;
|
|
206
|
+
initialValues = JSON.parse(JSON.stringify(data));
|
|
207
|
+
dirty = false;
|
|
208
|
+
onChange?.(data, getAllState());
|
|
209
|
+
handleClose(data);
|
|
210
|
+
return data;
|
|
211
|
+
} catch (e) {
|
|
212
|
+
const msg = e?.message ?? String(e);
|
|
213
|
+
error = msg;
|
|
214
|
+
onError?.(msg, getAllState());
|
|
215
|
+
} finally {
|
|
216
|
+
loading = false;
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
async function reset() {
|
|
221
|
+
if (request !== "insert") {
|
|
222
|
+
await load(true);
|
|
223
|
+
} else {
|
|
224
|
+
values = initialValues ? JSON.parse(JSON.stringify(initialValues)) : undefined;
|
|
225
|
+
dirty = false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function handleClose(data) {
|
|
229
|
+
if (dirty) {
|
|
230
|
+
if (!confirm("You have unsaved changes. Are you sure you want to close?")) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (onClose) {
|
|
235
|
+
onClose(data);
|
|
236
|
+
} else {
|
|
237
|
+
opened = false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Load data when opened changes (for non-insert modes).
|
|
241
|
+
// untrack() prevents reactive reads inside load() (values, onAPICall, etc.)
|
|
242
|
+
// from being tracked by this effect, which would cause a re-fetch every time
|
|
243
|
+
// load() writes back to values after a successful GET.
|
|
244
|
+
$effect(() => {
|
|
245
|
+
if (mounted && opened && request && request !== "insert") {
|
|
246
|
+
untrack(() => load(true));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
const formerState = {
|
|
250
|
+
get deleteConfirmed() {
|
|
251
|
+
return deleteConfirmed;
|
|
252
|
+
},
|
|
253
|
+
get dirty() {
|
|
254
|
+
return dirty;
|
|
255
|
+
},
|
|
256
|
+
get error() {
|
|
257
|
+
return error;
|
|
258
|
+
},
|
|
259
|
+
getAllState,
|
|
260
|
+
getState,
|
|
261
|
+
load,
|
|
262
|
+
get loading() {
|
|
263
|
+
return loading;
|
|
264
|
+
},
|
|
265
|
+
get opened() {
|
|
266
|
+
return opened;
|
|
267
|
+
},
|
|
268
|
+
get primeData() {
|
|
269
|
+
return primeData;
|
|
270
|
+
},
|
|
271
|
+
get request() {
|
|
272
|
+
return request;
|
|
273
|
+
},
|
|
274
|
+
reset,
|
|
275
|
+
save,
|
|
276
|
+
setRequest,
|
|
277
|
+
setState,
|
|
278
|
+
validate,
|
|
279
|
+
get values() {
|
|
280
|
+
return values;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
// Exposed methods for bind:this
|
|
284
|
+
export async function show() {
|
|
285
|
+
opened = true;
|
|
286
|
+
onOpen?.(values);
|
|
287
|
+
}
|
|
288
|
+
export async function close() {
|
|
289
|
+
handleClose(values);
|
|
290
|
+
}
|
|
291
|
+
export async function saveForm() {
|
|
292
|
+
return save();
|
|
293
|
+
}
|
|
294
|
+
export async function validateForm() {
|
|
295
|
+
return validate();
|
|
296
|
+
}
|
|
297
|
+
export function resetForm() {
|
|
298
|
+
reset();
|
|
299
|
+
}
|
|
300
|
+
export function getValue() {
|
|
301
|
+
return values;
|
|
302
|
+
}
|
|
303
|
+
export function setValue(val) {
|
|
304
|
+
values = val;
|
|
305
|
+
onChange?.(val, getAllState());
|
|
306
|
+
}
|
|
425
307
|
</script>
|
|
426
308
|
|
|
427
309
|
{#if mounted}
|