@json-render/svelte 0.6.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.
Files changed (76) hide show
  1. package/LICENSE +201 -0
  2. package/dist/CatalogRenderer.svelte +55 -0
  3. package/dist/CatalogRenderer.svelte.d.ts +20 -0
  4. package/dist/CatalogRenderer.svelte.d.ts.map +1 -0
  5. package/dist/ConfirmDialog.svelte +98 -0
  6. package/dist/ConfirmDialog.svelte.d.ts +10 -0
  7. package/dist/ConfirmDialog.svelte.d.ts.map +1 -0
  8. package/dist/ConfirmDialogManager.svelte +15 -0
  9. package/dist/ConfirmDialogManager.svelte.d.ts +4 -0
  10. package/dist/ConfirmDialogManager.svelte.d.ts.map +1 -0
  11. package/dist/ElementRenderer.svelte +147 -0
  12. package/dist/ElementRenderer.svelte.d.ts +13 -0
  13. package/dist/ElementRenderer.svelte.d.ts.map +1 -0
  14. package/dist/JsonUIProvider.svelte +68 -0
  15. package/dist/JsonUIProvider.svelte.d.ts +37 -0
  16. package/dist/JsonUIProvider.svelte.d.ts.map +1 -0
  17. package/dist/Renderer.svelte +34 -0
  18. package/dist/Renderer.svelte.d.ts +19 -0
  19. package/dist/Renderer.svelte.d.ts.map +1 -0
  20. package/dist/RendererWithProvider.test.svelte +37 -0
  21. package/dist/RendererWithProvider.test.svelte.d.ts +14 -0
  22. package/dist/RendererWithProvider.test.svelte.d.ts.map +1 -0
  23. package/dist/RepeatChildren.svelte +50 -0
  24. package/dist/RepeatChildren.svelte.d.ts +13 -0
  25. package/dist/RepeatChildren.svelte.d.ts.map +1 -0
  26. package/dist/TestButton.svelte +11 -0
  27. package/dist/TestButton.svelte.d.ts +9 -0
  28. package/dist/TestButton.svelte.d.ts.map +1 -0
  29. package/dist/TestContainer.svelte +19 -0
  30. package/dist/TestContainer.svelte.d.ts +11 -0
  31. package/dist/TestContainer.svelte.d.ts.map +1 -0
  32. package/dist/TestText.svelte +9 -0
  33. package/dist/TestText.svelte.d.ts +9 -0
  34. package/dist/TestText.svelte.d.ts.map +1 -0
  35. package/dist/catalog-types.d.ts +63 -0
  36. package/dist/catalog-types.d.ts.map +1 -0
  37. package/dist/catalog-types.js +1 -0
  38. package/dist/contexts/ActionProvider.svelte +344 -0
  39. package/dist/contexts/ActionProvider.svelte.d.ts +62 -0
  40. package/dist/contexts/ActionProvider.svelte.d.ts.map +1 -0
  41. package/dist/contexts/FunctionsContextProvider.svelte +44 -0
  42. package/dist/contexts/FunctionsContextProvider.svelte.d.ts +21 -0
  43. package/dist/contexts/FunctionsContextProvider.svelte.d.ts.map +1 -0
  44. package/dist/contexts/RepeatScopeProvider.svelte +49 -0
  45. package/dist/contexts/RepeatScopeProvider.svelte.d.ts +26 -0
  46. package/dist/contexts/RepeatScopeProvider.svelte.d.ts.map +1 -0
  47. package/dist/contexts/StateProvider.svelte +182 -0
  48. package/dist/contexts/StateProvider.svelte.d.ts +47 -0
  49. package/dist/contexts/StateProvider.svelte.d.ts.map +1 -0
  50. package/dist/contexts/ValidationProvider.svelte +198 -0
  51. package/dist/contexts/ValidationProvider.svelte.d.ts +57 -0
  52. package/dist/contexts/ValidationProvider.svelte.d.ts.map +1 -0
  53. package/dist/contexts/VisibilityProvider.svelte +82 -0
  54. package/dist/contexts/VisibilityProvider.svelte.d.ts +29 -0
  55. package/dist/contexts/VisibilityProvider.svelte.d.ts.map +1 -0
  56. package/dist/contexts/actions.test.js +156 -0
  57. package/dist/contexts/state.test.js +118 -0
  58. package/dist/contexts/visibility.test.js +71 -0
  59. package/dist/index.d.ts +18 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +30 -0
  62. package/dist/renderer.d.ts +128 -0
  63. package/dist/renderer.d.ts.map +1 -0
  64. package/dist/renderer.js +124 -0
  65. package/dist/renderer.test.js +168 -0
  66. package/dist/schema.d.ts +57 -0
  67. package/dist/schema.d.ts.map +1 -0
  68. package/dist/schema.js +81 -0
  69. package/dist/streaming.svelte.d.ts +75 -0
  70. package/dist/streaming.svelte.d.ts.map +1 -0
  71. package/dist/streaming.svelte.js +404 -0
  72. package/dist/utils.svelte.d.ts +26 -0
  73. package/dist/utils.svelte.d.ts.map +1 -0
  74. package/dist/utils.svelte.js +92 -0
  75. package/dist/utils.test.js +307 -0
  76. package/package.json +70 -0
@@ -0,0 +1,344 @@
1
+ <script module lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type {
4
+ ActionBinding,
5
+ ActionConfirm,
6
+ ActionHandler,
7
+ ResolvedAction,
8
+ } from "@json-render/core";
9
+
10
+ const ACTION_KEY = Symbol.for("json-render-actions");
11
+
12
+ /**
13
+ * Pending confirmation state
14
+ */
15
+ export interface PendingConfirmation {
16
+ action: ResolvedAction;
17
+ handler: ActionHandler;
18
+ resolve: () => void;
19
+ reject: () => void;
20
+ }
21
+
22
+ export interface CurrentValue<T> {
23
+ readonly current: T;
24
+ }
25
+
26
+ /**
27
+ * Action context value
28
+ */
29
+ export interface ActionContext {
30
+ /** Registered action handlers */
31
+ handlers: Record<string, ActionHandler>;
32
+ /** Currently loading action names */
33
+ loadingActions: Set<string>;
34
+ /** Pending confirmation dialog */
35
+ pendingConfirmation: PendingConfirmation | null;
36
+ /** Execute an action binding */
37
+ execute: (binding: ActionBinding) => Promise<void>;
38
+ /** Confirm the pending action */
39
+ confirm: () => void;
40
+ /** Cancel the pending action */
41
+ cancel: () => void;
42
+ /** Register an action handler */
43
+ registerHandler: (name: string, handler: ActionHandler) => void;
44
+ }
45
+
46
+ /**
47
+ * Get the action context from component tree
48
+ */
49
+ export function getActionContext(): ActionContext {
50
+ const ctx = getContext<ActionContext>(ACTION_KEY);
51
+ if (!ctx) {
52
+ throw new Error(
53
+ "getActionContext must be called within an ActionProvider",
54
+ );
55
+ }
56
+ return ctx;
57
+ }
58
+
59
+ /**
60
+ * Convenience helper to get a registered action handler by name
61
+ */
62
+ export function getAction(
63
+ name: string,
64
+ ): CurrentValue<ActionHandler | undefined> {
65
+ const context = getActionContext();
66
+ return {
67
+ get current() {
68
+ return context.handlers[name];
69
+ },
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Props for ConfirmDialog component
75
+ */
76
+ export interface ConfirmDialogProps {
77
+ /** The confirmation config */
78
+ confirm: ActionConfirm;
79
+ /** Called when confirmed */
80
+ onConfirm: () => void;
81
+ /** Called when cancelled */
82
+ onCancel: () => void;
83
+ }
84
+
85
+ /**
86
+ * Generate a unique ID for use with the "$id" token.
87
+ */
88
+ let idCounter = 0;
89
+ function generateUniqueId(): string {
90
+ idCounter += 1;
91
+ return `${Date.now()}-${idCounter}`;
92
+ }
93
+
94
+ /**
95
+ * Deep-resolve dynamic value references within an object.
96
+ */
97
+ function deepResolveValue(
98
+ value: unknown,
99
+ get: (path: string) => unknown,
100
+ ): unknown {
101
+ if (value === null || value === undefined) return value;
102
+
103
+ if (value === "$id") {
104
+ return generateUniqueId();
105
+ }
106
+
107
+ if (typeof value === "object" && !Array.isArray(value)) {
108
+ const obj = value as Record<string, unknown>;
109
+ const keys = Object.keys(obj);
110
+
111
+ if (keys.length === 1 && typeof obj.$state === "string") {
112
+ return get(obj.$state as string);
113
+ }
114
+
115
+ if (keys.length === 1 && "$id" in obj) {
116
+ return generateUniqueId();
117
+ }
118
+ }
119
+
120
+ if (Array.isArray(value)) {
121
+ return value.map((item) => deepResolveValue(item, get));
122
+ }
123
+
124
+ if (typeof value === "object") {
125
+ const resolved: Record<string, unknown> = {};
126
+ for (const [key, val] of Object.entries(
127
+ value as Record<string, unknown>,
128
+ )) {
129
+ resolved[key] = deepResolveValue(val, get);
130
+ }
131
+ return resolved;
132
+ }
133
+
134
+ return value;
135
+ }
136
+ </script>
137
+
138
+ <script lang="ts">
139
+ import { setContext, type Snippet } from "svelte";
140
+ import {
141
+ resolveAction,
142
+ executeAction,
143
+ type ActionBinding as CoreActionBinding,
144
+ type ActionHandler as CoreActionHandler,
145
+ } from "@json-render/core";
146
+ import { getStateContext } from "./StateProvider.svelte";
147
+ import { getOptionalValidationContext } from "./ValidationProvider.svelte";
148
+ import { SvelteSet } from "svelte/reactivity";
149
+
150
+ interface Props {
151
+ handlers?: Record<string, CoreActionHandler>;
152
+ navigate?: (path: string) => void;
153
+ children?: Snippet;
154
+ }
155
+
156
+ let { handlers = {}, navigate, children }: Props = $props();
157
+
158
+ const stateCtx = getStateContext();
159
+ const validation = getOptionalValidationContext();
160
+
161
+ let registeredHandlers = $state.raw<Record<string, CoreActionHandler>>({});
162
+ let loadingActions = new SvelteSet<string>();
163
+ let pendingConfirmation = $state.raw<PendingConfirmation | null>(null);
164
+
165
+ const execute = async (binding: CoreActionBinding): Promise<void> => {
166
+ const resolved = resolveAction(binding, stateCtx.getSnapshot());
167
+
168
+ if (resolved.action === "setState" && resolved.params) {
169
+ const statePath = resolved.params.statePath as string;
170
+ const value = resolved.params.value;
171
+ if (statePath) {
172
+ stateCtx.set(statePath, value);
173
+ }
174
+ return;
175
+ }
176
+
177
+ if (resolved.action === "pushState" && resolved.params) {
178
+ const statePath = resolved.params.statePath as string;
179
+ const rawValue = resolved.params.value;
180
+ if (statePath) {
181
+ const resolvedValue = deepResolveValue(rawValue, stateCtx.get);
182
+ const arr = (stateCtx.get(statePath) as unknown[] | undefined) ?? [];
183
+ stateCtx.set(statePath, [...arr, resolvedValue]);
184
+ const clearStatePath = resolved.params.clearStatePath as
185
+ | string
186
+ | undefined;
187
+ if (clearStatePath) {
188
+ stateCtx.set(clearStatePath, "");
189
+ }
190
+ }
191
+ return;
192
+ }
193
+
194
+ if (resolved.action === "removeState" && resolved.params) {
195
+ const statePath = resolved.params.statePath as string;
196
+ const index = resolved.params.index as number;
197
+ if (statePath !== undefined && index !== undefined) {
198
+ const arr = (stateCtx.get(statePath) as unknown[] | undefined) ?? [];
199
+ stateCtx.set(
200
+ statePath,
201
+ arr.filter((_, i) => i !== index),
202
+ );
203
+ }
204
+ return;
205
+ }
206
+
207
+ if (resolved.action === "validateForm") {
208
+ if (!validation?.validateAll) {
209
+ console.warn(
210
+ "validateForm action was dispatched but no ValidationProvider is connected. " +
211
+ "Ensure ValidationProvider is rendered inside the provider tree.",
212
+ );
213
+ return;
214
+ }
215
+ const valid = validation.validateAll();
216
+ const errors: Record<string, string[]> = {};
217
+ for (const [path, fieldState] of Object.entries(validation.fieldStates)) {
218
+ if (fieldState.result && !fieldState.result.valid) {
219
+ errors[path] = fieldState.result.errors;
220
+ }
221
+ }
222
+ const statePath =
223
+ (resolved.params?.statePath as string) || "/formValidation";
224
+ stateCtx.set(statePath, { valid, errors });
225
+ return;
226
+ }
227
+
228
+ if (resolved.action === "push" && resolved.params) {
229
+ const screen = resolved.params.screen as string;
230
+ if (screen) {
231
+ const currentScreen = stateCtx.get("/currentScreen") as
232
+ | string
233
+ | undefined;
234
+ const navStack =
235
+ (stateCtx.get("/navStack") as string[] | undefined) ?? [];
236
+ if (currentScreen) {
237
+ stateCtx.set("/navStack", [...navStack, currentScreen]);
238
+ } else {
239
+ stateCtx.set("/navStack", [...navStack, ""]);
240
+ }
241
+ stateCtx.set("/currentScreen", screen);
242
+ }
243
+ return;
244
+ }
245
+
246
+ if (resolved.action === "pop") {
247
+ const navStack =
248
+ (stateCtx.get("/navStack") as string[] | undefined) ?? [];
249
+ if (navStack.length > 0) {
250
+ const previousScreen = navStack[navStack.length - 1];
251
+ stateCtx.set("/navStack", navStack.slice(0, -1));
252
+ if (previousScreen) {
253
+ stateCtx.set("/currentScreen", previousScreen);
254
+ } else {
255
+ stateCtx.set("/currentScreen", undefined);
256
+ }
257
+ }
258
+ return;
259
+ }
260
+
261
+ const handler =
262
+ registeredHandlers[resolved.action] ?? handlers[resolved.action];
263
+
264
+ if (!handler) {
265
+ console.warn(`No handler registered for action: ${resolved.action}`);
266
+ return;
267
+ }
268
+
269
+ if (resolved.confirm) {
270
+ return new Promise<void>((resolve, reject) => {
271
+ pendingConfirmation = {
272
+ action: resolved,
273
+ handler,
274
+ resolve: () => {
275
+ pendingConfirmation = null;
276
+ resolve();
277
+ },
278
+ reject: () => {
279
+ pendingConfirmation = null;
280
+ reject(new Error("Action cancelled"));
281
+ },
282
+ };
283
+ }).then(async () => {
284
+ loadingActions.add(resolved.action);
285
+ try {
286
+ await executeAction({
287
+ action: resolved,
288
+ handler,
289
+ setState: stateCtx.set,
290
+ navigate,
291
+ executeAction: async (name) => {
292
+ const subBinding: CoreActionBinding = { action: name };
293
+ await execute(subBinding);
294
+ },
295
+ });
296
+ } finally {
297
+ loadingActions.delete(resolved.action);
298
+ }
299
+ });
300
+ }
301
+
302
+ loadingActions.add(resolved.action);
303
+ try {
304
+ await executeAction({
305
+ action: resolved,
306
+ handler,
307
+ setState: stateCtx.set,
308
+ navigate,
309
+ executeAction: async (name) => {
310
+ const subBinding: CoreActionBinding = { action: name };
311
+ await execute(subBinding);
312
+ },
313
+ });
314
+ } finally {
315
+ loadingActions.delete(resolved.action);
316
+ }
317
+ };
318
+
319
+ const ctx: ActionContext = {
320
+ get handlers() {
321
+ return { ...handlers, ...registeredHandlers };
322
+ },
323
+ get loadingActions() {
324
+ return loadingActions;
325
+ },
326
+ get pendingConfirmation() {
327
+ return pendingConfirmation;
328
+ },
329
+ execute,
330
+ confirm: () => {
331
+ pendingConfirmation?.resolve();
332
+ },
333
+ cancel: () => {
334
+ pendingConfirmation?.reject();
335
+ },
336
+ registerHandler: (name: string, handler: CoreActionHandler) => {
337
+ registeredHandlers = { ...registeredHandlers, [name]: handler };
338
+ },
339
+ };
340
+
341
+ setContext(ACTION_KEY, ctx);
342
+ </script>
343
+
344
+ {@render children?.()}
@@ -0,0 +1,62 @@
1
+ import type { ActionBinding, ActionConfirm, ActionHandler, ResolvedAction } from "@json-render/core";
2
+ /**
3
+ * Pending confirmation state
4
+ */
5
+ export interface PendingConfirmation {
6
+ action: ResolvedAction;
7
+ handler: ActionHandler;
8
+ resolve: () => void;
9
+ reject: () => void;
10
+ }
11
+ export interface CurrentValue<T> {
12
+ readonly current: T;
13
+ }
14
+ /**
15
+ * Action context value
16
+ */
17
+ export interface ActionContext {
18
+ /** Registered action handlers */
19
+ handlers: Record<string, ActionHandler>;
20
+ /** Currently loading action names */
21
+ loadingActions: Set<string>;
22
+ /** Pending confirmation dialog */
23
+ pendingConfirmation: PendingConfirmation | null;
24
+ /** Execute an action binding */
25
+ execute: (binding: ActionBinding) => Promise<void>;
26
+ /** Confirm the pending action */
27
+ confirm: () => void;
28
+ /** Cancel the pending action */
29
+ cancel: () => void;
30
+ /** Register an action handler */
31
+ registerHandler: (name: string, handler: ActionHandler) => void;
32
+ }
33
+ /**
34
+ * Get the action context from component tree
35
+ */
36
+ export declare function getActionContext(): ActionContext;
37
+ /**
38
+ * Convenience helper to get a registered action handler by name
39
+ */
40
+ export declare function getAction(name: string): CurrentValue<ActionHandler | undefined>;
41
+ /**
42
+ * Props for ConfirmDialog component
43
+ */
44
+ export interface ConfirmDialogProps {
45
+ /** The confirmation config */
46
+ confirm: ActionConfirm;
47
+ /** Called when confirmed */
48
+ onConfirm: () => void;
49
+ /** Called when cancelled */
50
+ onCancel: () => void;
51
+ }
52
+ import { type Snippet } from "svelte";
53
+ import { type ActionHandler as CoreActionHandler } from "@json-render/core";
54
+ interface Props {
55
+ handlers?: Record<string, CoreActionHandler>;
56
+ navigate?: (path: string) => void;
57
+ children?: Snippet;
58
+ }
59
+ declare const ActionProvider: import("svelte").Component<Props, {}, "">;
60
+ type ActionProvider = ReturnType<typeof ActionProvider>;
61
+ export default ActionProvider;
62
+ //# sourceMappingURL=ActionProvider.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionProvider.svelte.d.ts","sourceRoot":"","sources":["../../src/contexts/ActionProvider.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,cAAc,EACf,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,qCAAqC;IACrC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,kCAAkC;IAClC,mBAAmB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAChD,gCAAgC;IAChC,OAAO,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,iCAAiC;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,gCAAgC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,iCAAiC;IACjC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;CACjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAQhD;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,GACX,YAAY,CAAC,aAAa,GAAG,SAAS,CAAC,CAOzC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,4BAA4B;IAC5B,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAuDH,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAIH,KAAK,aAAa,IAAI,iBAAiB,EACxC,MAAM,mBAAmB,CAAC;AAM3B,UAAU,KAAK;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA2MH,QAAA,MAAM,cAAc,2CAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
@@ -0,0 +1,44 @@
1
+ <script module lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { ComputedFunction } from "@json-render/core";
4
+
5
+ const FUNCTIONS_KEY = Symbol.for("json-render-functions");
6
+ const EMPTY_FUNCTIONS: Record<string, ComputedFunction> = {};
7
+
8
+ /**
9
+ * Functions context value
10
+ */
11
+ export interface FunctionsContext {
12
+ /** Named functions for `$computed` expressions */
13
+ functions: Record<string, ComputedFunction>;
14
+ }
15
+
16
+ /**
17
+ * Get the functions context from component tree
18
+ */
19
+ export function getFunctions(): Record<string, ComputedFunction> {
20
+ const ctx = getContext<FunctionsContext>(FUNCTIONS_KEY);
21
+ return ctx?.functions ?? EMPTY_FUNCTIONS;
22
+ }
23
+ </script>
24
+
25
+ <script lang="ts">
26
+ import { setContext, type Snippet } from "svelte";
27
+
28
+ interface Props {
29
+ functions?: Record<string, ComputedFunction>;
30
+ children?: Snippet;
31
+ }
32
+
33
+ let { functions, children }: Props = $props();
34
+
35
+ const ctx: FunctionsContext = {
36
+ get functions() {
37
+ return functions ?? EMPTY_FUNCTIONS;
38
+ },
39
+ };
40
+
41
+ setContext(FUNCTIONS_KEY, ctx);
42
+ </script>
43
+
44
+ {@render children?.()}
@@ -0,0 +1,21 @@
1
+ import type { ComputedFunction } from "@json-render/core";
2
+ /**
3
+ * Functions context value
4
+ */
5
+ export interface FunctionsContext {
6
+ /** Named functions for `$computed` expressions */
7
+ functions: Record<string, ComputedFunction>;
8
+ }
9
+ /**
10
+ * Get the functions context from component tree
11
+ */
12
+ export declare function getFunctions(): Record<string, ComputedFunction>;
13
+ import { type Snippet } from "svelte";
14
+ interface Props {
15
+ functions?: Record<string, ComputedFunction>;
16
+ children?: Snippet;
17
+ }
18
+ declare const FunctionsContextProvider: import("svelte").Component<Props, {}, "">;
19
+ type FunctionsContextProvider = ReturnType<typeof FunctionsContextProvider>;
20
+ export default FunctionsContextProvider;
21
+ //# sourceMappingURL=FunctionsContextProvider.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionsContextProvider.svelte.d.ts","sourceRoot":"","sources":["../../src/contexts/FunctionsContextProvider.svelte.ts"],"names":[],"mappings":"AAIE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAK1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAG/D;AAGH,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGhD,UAAU,KAAK;IACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAsBH,QAAA,MAAM,wBAAwB,2CAAwC,CAAC;AACvE,KAAK,wBAAwB,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC5E,eAAe,wBAAwB,CAAC"}
@@ -0,0 +1,49 @@
1
+ <script module lang="ts">
2
+ import { getContext, setContext, type Snippet } from "svelte";
3
+
4
+ const REPEAT_SCOPE_KEY = Symbol("json-render-repeat-scope");
5
+
6
+ /**
7
+ * Repeat scope value provided to child elements inside a repeated element.
8
+ */
9
+ export interface RepeatScopeValue {
10
+ /** The current array item object */
11
+ item: unknown;
12
+ /** Index of the current item in the array */
13
+ index: number;
14
+ /** Absolute state path to the current array item (e.g. "/todos/0") */
15
+ basePath: string;
16
+ }
17
+
18
+ /**
19
+ * Get the current repeat scope (or null if not inside a repeated element)
20
+ */
21
+ export function getRepeatScope(): RepeatScopeValue | null {
22
+ return getContext<RepeatScopeValue | null>(REPEAT_SCOPE_KEY) ?? null;
23
+ }
24
+ </script>
25
+
26
+ <script lang="ts">
27
+ interface Props {
28
+ item: unknown;
29
+ index: number;
30
+ basePath: string;
31
+ children: Snippet;
32
+ }
33
+
34
+ let { item, index, basePath, children }: Props = $props();
35
+
36
+ setContext(REPEAT_SCOPE_KEY, {
37
+ get item() {
38
+ return item;
39
+ },
40
+ get index() {
41
+ return index;
42
+ },
43
+ get basePath() {
44
+ return basePath;
45
+ },
46
+ });
47
+ </script>
48
+
49
+ {@render children()}
@@ -0,0 +1,26 @@
1
+ import { type Snippet } from "svelte";
2
+ /**
3
+ * Repeat scope value provided to child elements inside a repeated element.
4
+ */
5
+ export interface RepeatScopeValue {
6
+ /** The current array item object */
7
+ item: unknown;
8
+ /** Index of the current item in the array */
9
+ index: number;
10
+ /** Absolute state path to the current array item (e.g. "/todos/0") */
11
+ basePath: string;
12
+ }
13
+ /**
14
+ * Get the current repeat scope (or null if not inside a repeated element)
15
+ */
16
+ export declare function getRepeatScope(): RepeatScopeValue | null;
17
+ interface Props {
18
+ item: unknown;
19
+ index: number;
20
+ basePath: string;
21
+ children: Snippet;
22
+ }
23
+ declare const RepeatScopeProvider: import("svelte").Component<Props, {}, "">;
24
+ type RepeatScopeProvider = ReturnType<typeof RepeatScopeProvider>;
25
+ export default RepeatScopeProvider;
26
+ //# sourceMappingURL=RepeatScopeProvider.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RepeatScopeProvider.svelte.d.ts","sourceRoot":"","sources":["../../src/contexts/RepeatScopeProvider.svelte.ts"],"names":[],"mappings":"AAGE,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AAI9D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,GAAG,IAAI,CAExD;AAED,UAAU,KAAK;IACb,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAyBH,QAAA,MAAM,mBAAmB,2CAAwC,CAAC;AAClE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,eAAe,mBAAmB,CAAC"}