@xmachines/json-render-solid 0.21.0-xm.4 → 0.21.0-xm.6

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/dist/index.js CHANGED
@@ -30,7 +30,7 @@ __export(index_exports, {
30
30
  VisibilityProvider: () => VisibilityProvider,
31
31
  buildSpecFromParts: () => buildSpecFromParts,
32
32
  createRenderer: () => createRenderer,
33
- createStateStore: () => import_core8.createStateStore,
33
+ createStateStore: () => import_core9.createStateStore,
34
34
  defineRegistry: () => defineRegistry,
35
35
  elementTreeSchema: () => elementTreeSchema,
36
36
  flatToTree: () => flatToTree,
@@ -56,6 +56,13 @@ module.exports = __toCommonJS(index_exports);
56
56
 
57
57
  // src/contexts/state.tsx
58
58
  var import_web = require("solid-js/web");
59
+
60
+ // src/contexts/bindings.ts
61
+ function pathAccessor(path) {
62
+ return typeof path === "function" ? path : () => path;
63
+ }
64
+
65
+ // src/contexts/state.tsx
59
66
  var import_solid_js = require("solid-js");
60
67
  var import_core = require("@xmachines/json-render-core");
61
68
  var import_store_utils = require("@xmachines/json-render-core/store-utils");
@@ -120,9 +127,15 @@ function StateProvider(props) {
120
127
  };
121
128
  (0, import_solid_js.createEffect)(() => {
122
129
  const s = store();
123
- setState(s.getSnapshot());
130
+ let shown = s.getSnapshot();
131
+ setState(shown);
124
132
  const unsubscribe = s.subscribe(() => {
125
- setState(s.getSnapshot());
133
+ for (; ; ) {
134
+ const next = s.getSnapshot();
135
+ if (next === shown) return;
136
+ shown = next;
137
+ setState(next);
138
+ }
126
139
  });
127
140
  (0, import_solid_js.onCleanup)(unsubscribe);
128
141
  });
@@ -190,12 +203,23 @@ function useStateStore() {
190
203
  }
191
204
  function useStateValue(path) {
192
205
  const store = useStateStore();
193
- return (0, import_solid_js.createMemo)(() => (0, import_core.getByPath)(store.state, path));
206
+ const live = pathAccessor(path);
207
+ return (0, import_solid_js.createMemo)(() => {
208
+ const now = live();
209
+ return now === void 0 ? void 0 : (0, import_core.getByPath)(store.state, now);
210
+ });
194
211
  }
195
212
  function useStateBinding(path) {
196
213
  const store = useStateStore();
197
- const value = (0, import_solid_js.createMemo)(() => (0, import_core.getByPath)(store.state, path));
198
- const setValue = (newValue) => store.set(path, newValue);
214
+ const live = pathAccessor(path);
215
+ const value = (0, import_solid_js.createMemo)(() => {
216
+ const now = live();
217
+ return now === void 0 ? void 0 : (0, import_core.getByPath)(store.state, now);
218
+ });
219
+ const setValue = (newValue) => {
220
+ const now = live();
221
+ if (now !== void 0) store.set(now, newValue);
222
+ };
199
223
  return [value, setValue];
200
224
  }
201
225
 
@@ -245,14 +269,118 @@ var import_web8 = require("solid-js/web");
245
269
  var import_web9 = require("solid-js/web");
246
270
  var import_web10 = require("solid-js/web");
247
271
  var import_web11 = require("solid-js/web");
248
- var import_solid_js4 = require("solid-js");
272
+ var import_solid_js6 = require("solid-js");
249
273
  var import_core4 = require("@xmachines/json-render-core");
250
274
 
275
+ // src/xm/write-together.ts
276
+ var import_solid_js3 = require("solid-js");
277
+ function writeTogether(set, updates) {
278
+ (0, import_solid_js3.batch)(() => {
279
+ for (const [path, value] of Object.entries(updates)) set(path, value);
280
+ });
281
+ }
282
+
283
+ // src/xm/field-registration.ts
284
+ var import_solid_js4 = require("solid-js");
285
+ function inRenderEffect() {
286
+ const owner = (0, import_solid_js4.getOwner)();
287
+ return owner?.pure === false && owner.user !== true;
288
+ }
289
+ var queues = /* @__PURE__ */ new WeakMap();
290
+ function createFieldRegistrationRules() {
291
+ const jobs = [];
292
+ const [pending, setPending] = (0, import_solid_js4.createSignal)(0);
293
+ const flush = () => {
294
+ if (jobs.length === 0) return;
295
+ const now = jobs.splice(0);
296
+ (0, import_solid_js4.untrack)(() => {
297
+ for (const job of now) job.register();
298
+ });
299
+ };
300
+ (0, import_solid_js4.createEffect)(() => {
301
+ pending();
302
+ flush();
303
+ });
304
+ const queue = {
305
+ enqueue: (job) => {
306
+ jobs.push(job);
307
+ setPending((count) => count + 1);
308
+ }
309
+ };
310
+ const releasedNow = /* @__PURE__ */ new Set();
311
+ return {
312
+ settle: () => (0, import_solid_js4.untrack)(flush),
313
+ registered: (path) => {
314
+ releasedNow.delete(path);
315
+ },
316
+ released: (path) => {
317
+ if (releasedNow.size === 0) queueMicrotask(() => releasedNow.clear());
318
+ releasedNow.add(path);
319
+ },
320
+ dropsWrite: (path) => releasedNow.has(path) && inRenderEffect(),
321
+ bind: (validation) => {
322
+ queues.set(validation, queue);
323
+ }
324
+ };
325
+ }
326
+ function useFieldRegistration(validation, path, config) {
327
+ const configKey = (0, import_solid_js4.createMemo)(() => {
328
+ const current = config();
329
+ return current === void 0 ? void 0 : JSON.stringify(current);
330
+ });
331
+ const queue = queues.get(validation);
332
+ let held;
333
+ let queued = false;
334
+ let disposed = false;
335
+ const release = () => {
336
+ if (held === void 0) return;
337
+ const { path: releasedPath } = held;
338
+ held = void 0;
339
+ validation.unregisterField(releasedPath);
340
+ };
341
+ const register = () => {
342
+ queued = false;
343
+ if (disposed || held !== void 0) return;
344
+ const current = (0, import_solid_js4.untrack)(path);
345
+ const currentConfig = (0, import_solid_js4.untrack)(config);
346
+ if (!current || !currentConfig) return;
347
+ validation.registerField(current, currentConfig);
348
+ held = { path: current, key: (0, import_solid_js4.untrack)(configKey) };
349
+ };
350
+ (0, import_solid_js4.createComputed)(() => {
351
+ const current = path();
352
+ const key = configKey();
353
+ if (held !== void 0 && (held.path !== current || held.key !== key)) {
354
+ release();
355
+ }
356
+ if (held !== void 0 || queued || !current || key === void 0) return;
357
+ if (queue === void 0) return;
358
+ queued = true;
359
+ queue.enqueue({ register });
360
+ });
361
+ (0, import_solid_js4.onCleanup)(() => {
362
+ disposed = true;
363
+ release();
364
+ });
365
+ }
366
+ function validateFieldsTogether(validateAll, fieldStates) {
367
+ return (0, import_solid_js4.batch)(() => {
368
+ const valid = validateAll();
369
+ const errors = {};
370
+ for (const [path, fs] of Object.entries(fieldStates())) {
371
+ if (fs.result && !fs.result.valid) {
372
+ errors[path] = fs.result.errors;
373
+ }
374
+ }
375
+ return { valid, errors };
376
+ });
377
+ }
378
+
251
379
  // src/contexts/validation.tsx
252
380
  var import_web3 = require("solid-js/web");
253
- var import_solid_js3 = require("solid-js");
381
+ var import_solid_js5 = require("solid-js");
254
382
  var import_core3 = require("@xmachines/json-render-core");
255
- var ValidationContext = (0, import_solid_js3.createContext)(null);
383
+ var ValidationContext = (0, import_solid_js5.createContext)(null);
256
384
  function dynamicArgsEqual(a, b) {
257
385
  if (a === b) return true;
258
386
  if (!a || !b) return false;
@@ -288,16 +416,18 @@ function validationConfigEqual(a, b) {
288
416
  return true;
289
417
  }
290
418
  function ValidationProvider(props) {
419
+ const rules = createFieldRegistrationRules();
291
420
  const {
292
421
  getSnapshot
293
422
  } = useStateStore();
294
423
  const customFunctions = () => props.customFunctions ?? {};
295
- const [fieldStates, setFieldStates] = (0, import_solid_js3.createSignal)({});
424
+ const [fieldStates, setFieldStates] = (0, import_solid_js5.createSignal)({});
296
425
  let fieldStatesRef = {};
297
- const [fieldConfigs, setFieldConfigs] = (0, import_solid_js3.createSignal)({});
426
+ const [fieldConfigs, setFieldConfigs] = (0, import_solid_js5.createSignal)({});
298
427
  const registrationCounts = {};
299
428
  const registerField = (path, config) => {
300
429
  registrationCounts[path] = (registrationCounts[path] ?? 0) + 1;
430
+ rules.registered(path);
301
431
  setFieldConfigs((prev) => {
302
432
  const existing = prev[path];
303
433
  if (existing && validationConfigEqual(existing, config)) {
@@ -316,7 +446,15 @@ function ValidationProvider(props) {
316
446
  return;
317
447
  }
318
448
  delete registrationCounts[path];
319
- delete fieldStatesRef[path];
449
+ rules.released(path);
450
+ if (path in fieldStatesRef) {
451
+ const {
452
+ [path]: _dropped,
453
+ ...rest
454
+ } = fieldStatesRef;
455
+ fieldStatesRef = rest;
456
+ setFieldStates(rest);
457
+ }
320
458
  setFieldConfigs((prev) => {
321
459
  if (!(path in prev)) return prev;
322
460
  const {
@@ -327,6 +465,7 @@ function ValidationProvider(props) {
327
465
  });
328
466
  };
329
467
  const validate = (path, config) => {
468
+ rules.settle();
330
469
  const currentState = getSnapshot();
331
470
  const segments = path.split("/").filter(Boolean);
332
471
  let value2 = currentState;
@@ -343,6 +482,7 @@ function ValidationProvider(props) {
343
482
  stateModel: currentState,
344
483
  customFunctions: customFunctions()
345
484
  });
485
+ if (rules.dropsWrite(path)) return result;
346
486
  const newFieldState = {
347
487
  touched: fieldStatesRef[path]?.touched ?? true,
348
488
  validated: true,
@@ -356,6 +496,8 @@ function ValidationProvider(props) {
356
496
  return result;
357
497
  };
358
498
  const touch = (path) => {
499
+ rules.settle();
500
+ if (rules.dropsWrite(path)) return;
359
501
  fieldStatesRef = {
360
502
  ...fieldStatesRef,
361
503
  [path]: {
@@ -368,6 +510,7 @@ function ValidationProvider(props) {
368
510
  setFieldStates(fieldStatesRef);
369
511
  };
370
512
  const clear = (path) => {
513
+ rules.settle();
371
514
  const {
372
515
  [path]: _,
373
516
  ...rest
@@ -376,6 +519,7 @@ function ValidationProvider(props) {
376
519
  setFieldStates(rest);
377
520
  };
378
521
  const validateAll = () => {
522
+ rules.settle();
379
523
  let allValid = true;
380
524
  for (const [path, config] of Object.entries(fieldConfigs())) {
381
525
  const result = validate(path, config);
@@ -400,6 +544,7 @@ function ValidationProvider(props) {
400
544
  registerField,
401
545
  unregisterField
402
546
  };
547
+ rules.bind(value);
403
548
  return (0, import_web3.createComponent)(ValidationContext.Provider, {
404
549
  value,
405
550
  get children() {
@@ -408,38 +553,36 @@ function ValidationProvider(props) {
408
553
  });
409
554
  }
410
555
  function useValidation() {
411
- const ctx = (0, import_solid_js3.useContext)(ValidationContext);
556
+ const ctx = (0, import_solid_js5.useContext)(ValidationContext);
412
557
  if (!ctx) {
413
558
  throw new Error("useValidation must be used within a ValidationProvider");
414
559
  }
415
560
  return ctx;
416
561
  }
417
562
  function useOptionalValidation() {
418
- return (0, import_solid_js3.useContext)(ValidationContext);
563
+ return (0, import_solid_js5.useContext)(ValidationContext);
419
564
  }
420
565
  function useFieldValidation(path, config) {
421
566
  const validation = useValidation();
422
- (0, import_solid_js3.createEffect)(() => {
423
- if (path && config) {
424
- validation.registerField(path, config);
425
- (0, import_solid_js3.onCleanup)(() => validation.unregisterField(path));
426
- }
427
- });
428
- const state = (0, import_solid_js3.createMemo)(() => {
429
- const current = validation.fieldStates[path];
567
+ const live = pathAccessor(path);
568
+ const now = () => live() ?? "";
569
+ const configNow = typeof config === "function" ? config : () => config;
570
+ useFieldRegistration(validation, now, configNow);
571
+ const state = (0, import_solid_js5.createMemo)(() => {
572
+ const current = validation.fieldStates[now()];
430
573
  return current ?? {
431
574
  touched: false,
432
575
  validated: false,
433
576
  result: null
434
577
  };
435
578
  });
436
- const validate = () => validation.validate(path, config ?? {
579
+ const validate = () => validation.validate(now(), configNow() ?? {
437
580
  checks: []
438
581
  });
439
- const touch = () => validation.touch(path);
440
- const clear = () => validation.clear(path);
441
- const errors = (0, import_solid_js3.createMemo)(() => state().result?.errors ?? []);
442
- const isValid = (0, import_solid_js3.createMemo)(() => state().result?.valid ?? true);
582
+ const touch = () => validation.touch(now());
583
+ const clear = () => validation.clear(now());
584
+ const errors = (0, import_solid_js5.createMemo)(() => state().result?.errors ?? []);
585
+ const isValid = (0, import_solid_js5.createMemo)(() => state().result?.valid ?? true);
443
586
  return {
444
587
  state,
445
588
  validate,
@@ -484,23 +627,18 @@ function deepResolveValue(value, get) {
484
627
  }
485
628
  return value;
486
629
  }
487
- var ActionContext = (0, import_solid_js4.createContext)(null);
630
+ var ActionContext = (0, import_solid_js6.createContext)(null);
488
631
  function ActionProvider(props) {
489
632
  const {
490
633
  get,
491
634
  set,
492
635
  getSnapshot
493
636
  } = useStateStore();
494
- const writeTogether = (updates) => {
495
- (0, import_solid_js4.batch)(() => {
496
- for (const [path, value] of Object.entries(updates)) set(path, value);
497
- });
498
- };
499
637
  const validation = useOptionalValidation();
500
- const [registered, setRegistered] = (0, import_solid_js4.createSignal)({});
501
- const handlers = (0, import_solid_js4.createMemo)(() => (0, import_core4.mergeActionHandlers)(props.handlers ?? {}, registered()));
502
- const [loadingActions, setLoadingActions] = (0, import_solid_js4.createSignal)(/* @__PURE__ */ new Set());
503
- const [pendingConfirmation, setPendingConfirmation] = (0, import_solid_js4.createSignal)(null);
638
+ const [registered, setRegistered] = (0, import_solid_js6.createSignal)({});
639
+ const handlers = (0, import_solid_js6.createMemo)(() => (0, import_core4.mergeActionHandlers)(props.handlers ?? {}, registered()));
640
+ const [loadingActions, setLoadingActions] = (0, import_solid_js6.createSignal)(/* @__PURE__ */ new Set());
641
+ const [pendingConfirmation, setPendingConfirmation] = (0, import_solid_js6.createSignal)(null);
504
642
  const registerHandler = (name, handler) => {
505
643
  setRegistered((prev) => ({
506
644
  ...prev,
@@ -567,7 +705,7 @@ function ActionProvider(props) {
567
705
  const arr = get(statePath) ?? [];
568
706
  const clearStatePath = resolved.params.clearStatePath;
569
707
  if (clearStatePath) {
570
- writeTogether({
708
+ writeTogether(set, {
571
709
  [statePath]: [...arr, resolvedValue],
572
710
  [clearStatePath]: ""
573
711
  });
@@ -591,7 +729,7 @@ function ActionProvider(props) {
591
729
  if (screen) {
592
730
  const currentScreen = get("/currentScreen");
593
731
  const navStack = get("/navStack") ?? [];
594
- writeTogether({
732
+ writeTogether(set, {
595
733
  "/navStack": [...navStack, currentScreen ? currentScreen : ""],
596
734
  "/currentScreen": screen
597
735
  });
@@ -602,7 +740,7 @@ function ActionProvider(props) {
602
740
  const navStack = get("/navStack") ?? [];
603
741
  if (navStack.length > 0) {
604
742
  const previousScreen = navStack[navStack.length - 1];
605
- writeTogether({
743
+ writeTogether(set, {
606
744
  "/navStack": navStack.slice(0, -1),
607
745
  "/currentScreen": previousScreen ? previousScreen : void 0
608
746
  });
@@ -615,13 +753,10 @@ function ActionProvider(props) {
615
753
  console.warn("validateForm action was dispatched but no ValidationProvider is connected. Ensure ValidationProvider is rendered inside the provider tree.");
616
754
  return;
617
755
  }
618
- const valid = validateAll();
619
- const errors = {};
620
- for (const [path, fs] of Object.entries(validation.fieldStates)) {
621
- if (fs.result && !fs.result.valid) {
622
- errors[path] = fs.result.errors;
623
- }
624
- }
756
+ const {
757
+ valid,
758
+ errors
759
+ } = validateFieldsTogether(validateAll, () => validation.fieldStates);
625
760
  const statePath = resolved.params?.statePath || "/formValidation";
626
761
  set(statePath, {
627
762
  valid,
@@ -636,7 +771,7 @@ function ActionProvider(props) {
636
771
  action: resolved,
637
772
  handler,
638
773
  setState: set,
639
- updateState: writeTogether,
774
+ updateState: (updates) => writeTogether(set, updates),
640
775
  navigate: props.navigate,
641
776
  executeAction: async (binding2) => {
642
777
  await execute(binding2);
@@ -696,7 +831,7 @@ function ActionProvider(props) {
696
831
  });
697
832
  }
698
833
  function useActions() {
699
- const ctx = (0, import_solid_js4.useContext)(ActionContext);
834
+ const ctx = (0, import_solid_js6.useContext)(ActionContext);
700
835
  if (!ctx) {
701
836
  throw new Error("useActions must be used within an ActionProvider");
702
837
  }
@@ -731,14 +866,12 @@ function ConfirmDialog(props) {
731
866
 
732
867
  // src/contexts/repeat-scope.tsx
733
868
  var import_web12 = require("solid-js/web");
734
- var import_solid_js5 = require("solid-js");
735
- var RepeatScopeContext = (0, import_solid_js5.createContext)(null);
869
+ var import_solid_js7 = require("solid-js");
870
+ var RepeatScopeContext = (0, import_solid_js7.createContext)(null);
736
871
  function RepeatScopeProvider(props) {
737
872
  return (0, import_web12.createComponent)(RepeatScopeContext.Provider, {
738
873
  value: {
739
- // Getters, and not copies: a row that stays on the screen shows the
740
- // item and the index of now, so a consumer that reads the scope in a
741
- // tracked computation follows them.
874
+ // Getters: a row that stays shows the item and the index of now.
742
875
  get item() {
743
876
  return props.item;
744
877
  },
@@ -755,7 +888,7 @@ function RepeatScopeProvider(props) {
755
888
  });
756
889
  }
757
890
  function useRepeatScope() {
758
- return (0, import_solid_js5.useContext)(RepeatScopeContext);
891
+ return (0, import_solid_js7.useContext)(RepeatScopeContext);
759
892
  }
760
893
 
761
894
  // src/schema.ts
@@ -806,24 +939,7 @@ var schema = (0, import_core5.defineSchema)(
806
939
  })
807
940
  }),
808
941
  {
809
- builtInActions: [
810
- {
811
- name: "setState",
812
- description: "Update a value in the state model at the given statePath. Params: { statePath: string, value: any }"
813
- },
814
- {
815
- name: "pushState",
816
- description: 'Append an item to an array in state. Params: { statePath: string, value: any, clearStatePath?: string }. Value can contain {"$state":"/path"} refs and "$id" for auto IDs.'
817
- },
818
- {
819
- name: "removeState",
820
- description: "Remove an item from an array in state by index. Params: { statePath: string, index: number }"
821
- },
822
- {
823
- name: "validateForm",
824
- description: "Validate all registered form fields and write the result to state. Params: { statePath?: string }. Defaults to /formValidation. Result: { valid: boolean, errors: Record<string, string[]> }."
825
- }
826
- ],
942
+ builtInActions: [...import_core5.builtInActionDefinitions],
827
943
  defaultRules: [
828
944
  // Element integrity
829
945
  "CRITICAL INTEGRITY CHECK: Before outputting ANY element that references children, you MUST have already output (or will output) each child as its own element. If an element has children: ['a', 'b'], then elements 'a' and 'b' MUST exist. A missing child element causes that entire branch of the UI to be invisible.",
@@ -846,7 +962,7 @@ var schema = (0, import_core5.defineSchema)(
846
962
  var elementTreeSchema = schema;
847
963
 
848
964
  // src/index.ts
849
- var import_core8 = require("@xmachines/json-render-core");
965
+ var import_core9 = require("@xmachines/json-render-core");
850
966
 
851
967
  // src/renderer.tsx
852
968
  var import_web13 = require("solid-js/web");
@@ -855,33 +971,111 @@ var import_web15 = require("solid-js/web");
855
971
  var import_web16 = require("solid-js/web");
856
972
  var import_web17 = require("solid-js/web");
857
973
  var import_web18 = require("solid-js/web");
858
- var import_solid_js6 = require("solid-js");
974
+ var import_solid_js9 = require("solid-js");
975
+ var import_core7 = require("@xmachines/json-render-core");
976
+
977
+ // src/xm/errors.ts
859
978
  var import_core6 = require("@xmachines/json-render-core");
860
- var _tmpl$2 = /* @__PURE__ */ (0, import_web13.template)(`<span style=display:contents>`);
861
- function reportRenderError(registry, elementType, error) {
862
- const onRenderError = (0, import_core6.getRenderErrorHandler)(registry);
863
- if (onRenderError !== void 0) {
864
- onRenderError(error, elementType);
865
- return;
866
- }
867
- (0, import_core6.warnUnusedRenderErrorHandler)(registry);
868
- console.error(`[json-render] Rendering error in <${elementType}>:`, error);
979
+ var import_solid_js8 = require("solid-js");
980
+ var tags = /* @__PURE__ */ new WeakMap();
981
+ function infoOf(kind, key, type) {
982
+ return {
983
+ kind,
984
+ ...key !== void 0 ? { key } : {},
985
+ ...type !== void 0 ? { type } : {}
986
+ };
987
+ }
988
+ function taggable(error) {
989
+ return typeof error === "object" && error !== null || typeof error === "function";
990
+ }
991
+ function takeTag(error) {
992
+ if (!taggable(error)) return void 0;
993
+ const info = tags.get(error);
994
+ tags.delete(error);
995
+ return info;
996
+ }
997
+ function createExpressionGuard(kind, key, type) {
998
+ let failure;
999
+ return (run) => {
1000
+ try {
1001
+ const value = run();
1002
+ failure = void 0;
1003
+ return value;
1004
+ } catch (error) {
1005
+ if (failure === void 0) {
1006
+ const first = { error };
1007
+ failure = first;
1008
+ queueMicrotask(() => {
1009
+ if (failure === first) failure = void 0;
1010
+ });
1011
+ }
1012
+ if (taggable(failure.error)) {
1013
+ tags.set(failure.error, infoOf(kind, key(), type()));
1014
+ }
1015
+ throw failure.error;
1016
+ }
1017
+ };
1018
+ }
1019
+ function reportBoundaryFailure(registry, error, type, key, root = false) {
1020
+ const handler = (0, import_core6.getRenderErrorHandler)(registry);
1021
+ const tag = takeTag(error);
1022
+ const own = root && (tag === void 0 || tag.key === key);
1023
+ if (handler === void 0) (0, import_core6.warnUnusedRenderErrorHandler)(registry);
1024
+ (0, import_core6.reportRenderError)(
1025
+ handler,
1026
+ error,
1027
+ type,
1028
+ own ? infoOf("root", key, type) : tag ?? infoOf("element", key, type)
1029
+ );
1030
+ }
1031
+ function reportChainFailure(registry, error, kind, action, key, type) {
1032
+ (0, import_core6.reportRenderError)((0, import_core6.getRenderErrorHandler)(registry), error, action, {
1033
+ ...infoOf(kind, key, type),
1034
+ action
1035
+ });
869
1036
  }
1037
+ function useMissingRootWarning(rootKey, rootElement, loading) {
1038
+ const missing = (0, import_solid_js8.createMemo)(() => {
1039
+ const key = rootKey();
1040
+ if (!key || loading() || rootElement() !== void 0) return void 0;
1041
+ return key;
1042
+ });
1043
+ (0, import_solid_js8.createRenderEffect)(() => {
1044
+ const key = missing();
1045
+ if (key !== void 0) (0, import_core6.warnMissingRoot)(key);
1046
+ });
1047
+ }
1048
+
1049
+ // src/renderer.tsx
1050
+ var _tmpl$2 = /* @__PURE__ */ (0, import_web13.template)(`<span style=display:contents>`);
870
1051
  var EMPTY_FUNCTIONS = {};
871
- var FunctionsContext = (0, import_solid_js6.createContext)(EMPTY_FUNCTIONS);
1052
+ var FunctionsContext = (0, import_solid_js9.createContext)(EMPTY_FUNCTIONS);
872
1053
  function useFunctions() {
873
- return (0, import_solid_js6.useContext)(FunctionsContext) ?? EMPTY_FUNCTIONS;
1054
+ return (0, import_solid_js9.useContext)(FunctionsContext) ?? EMPTY_FUNCTIONS;
874
1055
  }
875
- var DirectivesContext = (0, import_solid_js6.createContext)(void 0);
1056
+ var DirectivesContext = (0, import_solid_js9.createContext)(void 0);
876
1057
  function useDirectives() {
877
- return (0, import_solid_js6.useContext)(DirectivesContext);
1058
+ return (0, import_solid_js9.useContext)(DirectivesContext);
878
1059
  }
879
1060
  function useDevtoolsActive() {
880
- const [active, setActive] = (0, import_solid_js6.createSignal)((0, import_core6.isDevtoolsActive)());
881
- const unsub = (0, import_core6.subscribeDevtoolsActive)(() => setActive((0, import_core6.isDevtoolsActive)()));
882
- (0, import_solid_js6.onCleanup)(unsub);
1061
+ const [active, setActive] = (0, import_solid_js9.createSignal)((0, import_core7.isDevtoolsActive)());
1062
+ const unsub = (0, import_core7.subscribeDevtoolsActive)(() => setActive((0, import_core7.isDevtoolsActive)()));
1063
+ (0, import_solid_js9.onCleanup)(unsub);
883
1064
  return active;
884
1065
  }
1066
+ function lastElementOf(read, first) {
1067
+ let last = first;
1068
+ let gone = false;
1069
+ (0, import_solid_js9.onCleanup)(() => {
1070
+ gone = true;
1071
+ });
1072
+ return () => {
1073
+ if (gone) return last;
1074
+ const now = read();
1075
+ if (now !== void 0) last = now;
1076
+ return last;
1077
+ };
1078
+ }
885
1079
  function ElementRenderer(props) {
886
1080
  const repeatScope = useRepeatScope();
887
1081
  const {
@@ -894,7 +1088,7 @@ function ElementRenderer(props) {
894
1088
  const getSnapshot = () => stateStore.getSnapshot();
895
1089
  const functions = useFunctions();
896
1090
  const directives = useDirectives();
897
- const fullCtx = (0, import_solid_js6.createMemo)(() => {
1091
+ const fullCtx = (0, import_solid_js9.createMemo)(() => {
898
1092
  const repeatItem = repeatScope?.item;
899
1093
  const repeatIndex = repeatScope?.index;
900
1094
  const repeatBasePath = repeatScope?.basePath;
@@ -915,30 +1109,32 @@ function ElementRenderer(props) {
915
1109
  directives
916
1110
  };
917
1111
  });
918
- const repeatVisibility = (0, import_solid_js6.createMemo)(() => props.element.repeat !== void 0 && !repeatScope ? (0, import_core6.splitRepeatVisibility)(props.element.visible) : {
1112
+ const visibleGuard = createExpressionGuard("visible", () => props.elementKey, () => props.element.type);
1113
+ const repeatVisibility = (0, import_solid_js9.createMemo)(() => props.element.repeat !== void 0 && !repeatScope ? (0, import_core7.splitRepeatVisibility)(props.element.visible) : {
919
1114
  container: props.element.visible,
920
1115
  itemFilter: void 0
921
1116
  });
922
- const isVisible = (0, import_solid_js6.createMemo)(() => {
1117
+ const isVisible = (0, import_solid_js9.createMemo)(() => {
923
1118
  const container = repeatVisibility().container;
924
- return container === void 0 ? true : (0, import_core6.evaluateVisibility)(container, fullCtx());
1119
+ return container === void 0 ? true : visibleGuard(() => (0, import_core7.evaluateVisibility)(container, fullCtx()));
925
1120
  });
926
1121
  const emit = async (eventName) => {
927
1122
  const onBindings = props.element.on;
928
1123
  const binding = onBindings?.[eventName];
929
1124
  if (!binding) return;
930
1125
  const actionBindings = Array.isArray(binding) ? binding : [binding];
1126
+ const scope = (0, import_solid_js9.untrack)(fullCtx);
931
1127
  let action = "";
932
1128
  try {
933
1129
  for (const b of actionBindings) {
934
1130
  action = b.action;
935
- await execute((0, import_core6.resolveBindingParams)(b, {
936
- ...fullCtx(),
1131
+ await execute((0, import_core7.resolveBindingParams)(b, {
1132
+ ...scope,
937
1133
  stateModel: getSnapshot()
938
1134
  }));
939
1135
  }
940
1136
  } catch (err) {
941
- (0, import_core6.reportActionError)((0, import_core6.getRenderErrorHandler)(props.registry), err, action, "event");
1137
+ reportChainFailure(props.registry, err, "action", action, props.elementKey, props.element.type);
942
1138
  }
943
1139
  };
944
1140
  const on = (eventName) => {
@@ -961,63 +1157,68 @@ function ElementRenderer(props) {
961
1157
  };
962
1158
  };
963
1159
  let stableWatched;
964
- const watchedValues = (0, import_solid_js6.createMemo)(() => {
1160
+ const watchedValues = (0, import_solid_js9.createMemo)(() => {
965
1161
  const cfg = props.element.watch;
966
- stableWatched = cfg ? (0, import_core6.readWatchedValues)(cfg, stateStore.state, stableWatched) : void 0;
1162
+ stableWatched = cfg ? (0, import_core7.readWatchedValues)(cfg, stateStore.state, stableWatched) : void 0;
967
1163
  return stableWatched;
968
1164
  });
969
- let previousWatched = (0, import_solid_js6.untrack)(watchedValues);
970
- (0, import_solid_js6.createEffect)(() => {
1165
+ let previousWatched = (0, import_solid_js9.untrack)(watchedValues);
1166
+ (0, import_solid_js9.createEffect)(() => {
971
1167
  const current = watchedValues();
972
1168
  const prev = previousWatched;
973
1169
  previousWatched = current;
974
- const paths = (0, import_core6.changedWatchPaths)(current, prev);
975
- const watchConfig = (0, import_solid_js6.untrack)(() => props.element.watch);
1170
+ const paths = (0, import_core7.changedWatchPaths)(current, prev);
1171
+ const watchConfig = (0, import_solid_js9.untrack)(() => props.element.watch);
976
1172
  if (!watchConfig || paths.length === 0) return;
977
1173
  let cancelled = false;
978
- (0, import_solid_js6.onCleanup)(() => {
1174
+ (0, import_solid_js9.onCleanup)(() => {
979
1175
  cancelled = true;
980
1176
  });
981
- (0, import_solid_js6.untrack)(() => {
1177
+ (0, import_solid_js9.untrack)(() => {
982
1178
  let action = "";
983
- void (0, import_core6.runWatchBindings)(watchConfig, paths, async (b) => {
1179
+ void (0, import_core7.runWatchBindings)(watchConfig, paths, async (b) => {
984
1180
  action = b.action;
985
- await execute((0, import_core6.resolveBindingParams)(b, {
1181
+ await execute((0, import_core7.resolveBindingParams)(b, {
986
1182
  ...fullCtx(),
987
1183
  stateModel: getSnapshot()
988
1184
  }));
989
1185
  }, () => cancelled).catch((err) => {
990
- (0, import_core6.reportActionError)((0, import_core6.getRenderErrorHandler)(props.registry), err, action, "watch");
1186
+ reportChainFailure(props.registry, err, "watch", action, props.elementKey, props.element.type);
991
1187
  });
992
1188
  });
993
1189
  });
994
- const elementBindings = (0, import_solid_js6.createMemo)(() => {
1190
+ const elementBindings = (0, import_solid_js9.createMemo)(() => {
995
1191
  const rawProps = props.element.props;
996
- return (0, import_core6.resolveBindings)(rawProps, fullCtx());
1192
+ return (0, import_core7.resolveBindings)(rawProps, fullCtx());
997
1193
  });
998
- const resolvedElement = (0, import_solid_js6.createMemo)(() => {
1194
+ const propsGuard = createExpressionGuard("props", () => props.elementKey, () => props.element.type);
1195
+ const resolvedElement = (0, import_solid_js9.createMemo)(() => {
999
1196
  const rawProps = props.element.props;
1000
- const resolvedProps = (0, import_core6.resolveElementProps)(rawProps, fullCtx());
1197
+ const resolvedProps = propsGuard(() => (0, import_core7.resolveElementProps)(rawProps, fullCtx()));
1001
1198
  return resolvedProps !== props.element.props ? {
1002
1199
  ...props.element,
1003
1200
  props: resolvedProps
1004
1201
  } : props.element;
1005
1202
  });
1006
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1203
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1007
1204
  get when() {
1008
1205
  return isVisible();
1009
1206
  },
1010
1207
  get children() {
1011
- return (0, import_web18.createComponent)(import_solid_js6.ErrorBoundary, {
1012
- fallback: (err, reset) => {
1013
- reportRenderError(props.registry, props.element.type, err);
1014
- const subtree = () => (0, import_core6.elementSubtreeJson)(props.spec, props.elementKey, props.element);
1015
- const failed = (0, import_solid_js6.untrack)(subtree);
1016
- (0, import_solid_js6.createEffect)(() => {
1017
- if (subtree() !== failed) reset();
1018
- });
1019
- return null;
1208
+ return (0, import_web18.createComponent)(ElementBoundary, {
1209
+ get registry() {
1210
+ return props.registry;
1211
+ },
1212
+ get type() {
1213
+ return props.element.type;
1020
1214
  },
1215
+ get elementKey() {
1216
+ return props.elementKey;
1217
+ },
1218
+ get root() {
1219
+ return props.root;
1220
+ },
1221
+ subtree: () => (0, import_core7.elementSubtreeJson)(props.spec, props.elementKey, props.element),
1021
1222
  get children() {
1022
1223
  return (0, import_web18.createComponent)(ElementRendererContent, {
1023
1224
  get resolvedElement() {
@@ -1052,73 +1253,99 @@ function ElementRenderer(props) {
1052
1253
  }
1053
1254
  });
1054
1255
  }
1256
+ function ElementBoundary(props) {
1257
+ let failing = false;
1258
+ return (0, import_web18.createComponent)(import_solid_js9.ErrorBoundary, {
1259
+ fallback: (err, reset) => {
1260
+ if (!failing) {
1261
+ failing = true;
1262
+ reportBoundaryFailure(props.registry, err, props.type, props.elementKey, props.root);
1263
+ }
1264
+ const failed = (0, import_solid_js9.untrack)(props.subtree);
1265
+ (0, import_solid_js9.createEffect)(() => {
1266
+ if (props.subtree() === failed) return;
1267
+ failing = false;
1268
+ reset();
1269
+ });
1270
+ return null;
1271
+ },
1272
+ get children() {
1273
+ return props.children;
1274
+ }
1275
+ });
1276
+ }
1055
1277
  function ElementRendererContent(props) {
1056
1278
  const devtoolsActive = useDevtoolsActive();
1057
- const Comp = () => (0, import_core6.getRegistryComponent)(props.registry, props.resolvedElement.type) ?? props.fallback;
1058
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1279
+ const Comp = () => (0, import_core7.getRegistryComponent)(props.registry, props.resolvedElement.type) ?? props.fallback;
1280
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1059
1281
  get when() {
1060
1282
  return Comp();
1061
1283
  },
1062
1284
  keyed: true,
1063
1285
  get fallback() {
1064
- console.warn(`No renderer for component type: ${props.resolvedElement.type}`);
1286
+ (0, import_solid_js9.untrack)(() => (0, import_core7.warnUnknownType)(props.resolvedElement.type, props.elementKey));
1065
1287
  return null;
1066
1288
  },
1067
1289
  children: (Component) => {
1068
- const elementSlots = (0, import_solid_js6.createMemo)(() => props.resolvedElement.slots);
1069
- (0, import_solid_js6.createRenderEffect)(() => {
1290
+ const elementSlots = (0, import_solid_js9.createMemo)(() => props.resolvedElement.slots);
1291
+ (0, import_solid_js9.createRenderEffect)(() => {
1070
1292
  const slotEntries = elementSlots();
1071
- (0, import_solid_js6.untrack)(() => (0, import_core6.warnElementSlots)(props.registry, props.resolvedElement.type, slotEntries));
1293
+ (0, import_solid_js9.untrack)(() => (0, import_core7.warnElementSlots)(props.registry, props.resolvedElement.type, slotEntries));
1072
1294
  });
1073
- const renderChildKeys = (childKeys, slotName) => (0, import_web18.createComponent)(import_solid_js6.For, {
1074
- get each() {
1075
- return childKeys();
1076
- },
1077
- children: (childKey) => {
1078
- const childElement = () => props.spec.elements[childKey];
1079
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1080
- get when() {
1081
- return childElement();
1082
- },
1083
- get fallback() {
1084
- if (!props.loading) {
1085
- const type = (0, import_solid_js6.untrack)(() => props.resolvedElement.type);
1086
- const location = slotName ? `in slot "${slotName}" of "${type}"` : `as child of "${type}"`;
1087
- console.warn(`[json-render] Missing element "${childKey}" referenced ${location}. This element will not render.`);
1088
- }
1089
- return null;
1090
- },
1091
- children: (el) => (0, import_web18.createComponent)(ElementRenderer, {
1092
- get element() {
1093
- return el();
1094
- },
1095
- elementKey: childKey,
1096
- get spec() {
1097
- return props.spec;
1098
- },
1099
- get registry() {
1100
- return props.registry;
1101
- },
1102
- get loading() {
1103
- return props.loading;
1295
+ const renderChildKeys = (childKeys, slotName) => {
1296
+ return (0, import_web18.createComponent)(import_solid_js9.For, {
1297
+ get each() {
1298
+ return childKeys();
1299
+ },
1300
+ children: (childKey) => {
1301
+ const childElement = () => props.spec.elements[childKey];
1302
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1303
+ get when() {
1304
+ return childElement();
1104
1305
  },
1105
1306
  get fallback() {
1106
- return props.fallback;
1307
+ if (!props.loading) {
1308
+ const type = (0, import_solid_js9.untrack)(() => props.resolvedElement.type);
1309
+ const location = slotName ? `in slot "${slotName}" of "${type}"` : `as child of "${type}"`;
1310
+ console.warn(`[json-render] Missing element "${childKey}" referenced ${location}. This element will not render.`);
1311
+ }
1312
+ return null;
1313
+ },
1314
+ children: (el) => {
1315
+ const element = lastElementOf(childElement, el());
1316
+ return (0, import_web18.createComponent)(ElementRenderer, {
1317
+ get element() {
1318
+ return element();
1319
+ },
1320
+ elementKey: childKey,
1321
+ get spec() {
1322
+ return props.spec;
1323
+ },
1324
+ get registry() {
1325
+ return props.registry;
1326
+ },
1327
+ get loading() {
1328
+ return props.loading;
1329
+ },
1330
+ get fallback() {
1331
+ return props.fallback;
1332
+ }
1333
+ });
1107
1334
  }
1108
- })
1109
- });
1110
- }
1111
- });
1112
- const owner = (0, import_solid_js6.getOwner)();
1335
+ });
1336
+ }
1337
+ });
1338
+ };
1339
+ const owner = (0, import_solid_js9.getOwner)();
1113
1340
  const once = (make) => {
1114
1341
  const contents = /* @__PURE__ */ new Map();
1115
1342
  return () => {
1116
- const reader = (0, import_solid_js6.getOwner)();
1343
+ const reader = (0, import_solid_js9.getOwner)();
1117
1344
  let content = contents.get(reader);
1118
1345
  if (content === void 0) {
1119
1346
  let dispose = () => {
1120
1347
  };
1121
- const value = (0, import_solid_js6.createRoot)((disposeRoot) => {
1348
+ const value = (0, import_solid_js9.createRoot)((disposeRoot) => {
1122
1349
  dispose = disposeRoot;
1123
1350
  return make();
1124
1351
  }, reader ?? owner);
@@ -1128,7 +1355,7 @@ function ElementRendererContent(props) {
1128
1355
  leaving: false
1129
1356
  };
1130
1357
  contents.set(reader, made);
1131
- (0, import_solid_js6.runWithOwner)(owner, () => (0, import_solid_js6.onCleanup)(() => {
1358
+ (0, import_solid_js9.runWithOwner)(owner, () => (0, import_solid_js9.onCleanup)(() => {
1132
1359
  contents.delete(reader);
1133
1360
  made.dispose();
1134
1361
  }));
@@ -1137,7 +1364,7 @@ function ElementRendererContent(props) {
1137
1364
  content.leaving = false;
1138
1365
  if (reader !== null && reader !== owner) {
1139
1366
  const read = content;
1140
- (0, import_solid_js6.onCleanup)(() => {
1367
+ (0, import_solid_js9.onCleanup)(() => {
1141
1368
  read.leaving = true;
1142
1369
  queueMicrotask(() => {
1143
1370
  if (!read.leaving || contents.get(reader) !== read) return;
@@ -1149,7 +1376,7 @@ function ElementRendererContent(props) {
1149
1376
  return content.value;
1150
1377
  };
1151
1378
  };
1152
- const children = once(() => (0, import_web18.createComponent)(import_solid_js6.Show, {
1379
+ const children = once(() => (0, import_web18.createComponent)(import_solid_js9.Show, {
1153
1380
  get when() {
1154
1381
  return props.resolvedElement.repeat;
1155
1382
  },
@@ -1225,7 +1452,7 @@ function ElementRendererContent(props) {
1225
1452
  return children();
1226
1453
  }
1227
1454
  });
1228
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1455
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1229
1456
  get when() {
1230
1457
  return (0, import_web17.memo)(() => !!devtoolsActive())() && props.elementKey;
1231
1458
  },
@@ -1245,27 +1472,31 @@ function RepeatChildren(props) {
1245
1472
  const repeat = () => props.element.repeat;
1246
1473
  const parentScope = useRepeatScope();
1247
1474
  const statePath = () => {
1248
- const resolved = (0, import_core6.resolveRepeatStatePath)(repeat().statePath, parentScope?.basePath);
1475
+ const resolved = (0, import_core7.resolveRepeatStatePath)(repeat().statePath, parentScope?.basePath);
1249
1476
  if (resolved === void 0) {
1250
1477
  console.warn("[json-render/solid] $item in repeat.statePath used outside of a repeat scope");
1251
1478
  }
1252
1479
  return resolved;
1253
1480
  };
1254
- const items = () => statePath() === void 0 ? [] : (0, import_core6.getByPath)(stateStore.state, statePath()) ?? [];
1481
+ const items = () => {
1482
+ const path = statePath();
1483
+ if (path === void 0) return [];
1484
+ const value = (0, import_core7.getByPath)(stateStore.state, path);
1485
+ return Array.isArray(value) ? value : [];
1486
+ };
1255
1487
  const entries = () => items().map((itemValue, index) => ({
1256
1488
  itemValue,
1257
1489
  index
1258
1490
  })).filter(({
1259
1491
  itemValue,
1260
1492
  index
1261
- }) => props.itemFilter === void 0 || (0, import_core6.evaluateVisibility)(props.itemFilter, {
1493
+ }) => props.itemFilter === void 0 || (0, import_core7.evaluateVisibility)(props.itemFilter, {
1262
1494
  stateModel: stateStore.state,
1263
1495
  repeatItem: itemValue,
1264
1496
  repeatIndex: index
1265
1497
  }));
1266
- const keyed = (0, import_solid_js6.createMemo)(() => {
1498
+ const keyed = (0, import_solid_js9.createMemo)(() => {
1267
1499
  const r = repeat();
1268
- const path = statePath();
1269
1500
  const byKey = /* @__PURE__ */ new Map();
1270
1501
  const keys = [];
1271
1502
  for (const entry of entries()) {
@@ -1273,8 +1504,9 @@ function RepeatChildren(props) {
1273
1504
  itemValue,
1274
1505
  index
1275
1506
  } = entry;
1276
- const itemKey = r.key && typeof itemValue === "object" && itemValue !== null ? String(itemValue[r.key] ?? "") : "";
1277
- const key = JSON.stringify([path, index, itemKey]);
1507
+ const itemKey = r.key && typeof itemValue === "object" && itemValue !== null ? itemValue[r.key] : void 0;
1508
+ let key = itemKey === void 0 || itemKey === null ? JSON.stringify(["index", index]) : JSON.stringify(["key", String(itemKey)]);
1509
+ if (byKey.has(key)) key = JSON.stringify(["index", index]);
1278
1510
  byKey.set(key, entry);
1279
1511
  keys.push(key);
1280
1512
  }
@@ -1283,13 +1515,14 @@ function RepeatChildren(props) {
1283
1515
  byKey
1284
1516
  };
1285
1517
  });
1286
- return (0, import_web18.createComponent)(import_solid_js6.For, {
1518
+ const childKeys = () => props.element.children ?? [];
1519
+ return (0, import_web18.createComponent)(import_solid_js9.For, {
1287
1520
  get each() {
1288
1521
  return keyed().keys;
1289
1522
  },
1290
1523
  children: (key) => {
1291
- const entry = (0, import_solid_js6.createMemo)(() => keyed().byKey.get(key), void 0, {
1292
- equals: (a, b) => a?.itemValue === b?.itemValue
1524
+ const entry = (0, import_solid_js9.createMemo)(() => keyed().byKey.get(key) ?? void 0, void 0, {
1525
+ equals: (a, b) => a?.itemValue === b?.itemValue && a?.index === b?.index
1293
1526
  });
1294
1527
  const index = () => entry()?.index ?? 0;
1295
1528
  return (0, import_web18.createComponent)(RepeatScopeProvider, {
@@ -1300,16 +1533,16 @@ function RepeatChildren(props) {
1300
1533
  return index();
1301
1534
  },
1302
1535
  get basePath() {
1303
- return (0, import_core6.resolveRepeatItemStatePath)(statePath(), index());
1536
+ return (0, import_core7.resolveRepeatItemStatePath)(statePath(), index());
1304
1537
  },
1305
1538
  get children() {
1306
- return (0, import_web18.createComponent)(import_solid_js6.For, {
1539
+ return (0, import_web18.createComponent)(import_solid_js9.For, {
1307
1540
  get each() {
1308
- return props.element.children ?? [];
1541
+ return childKeys();
1309
1542
  },
1310
1543
  children: (childKey) => {
1311
1544
  const childElement = () => props.spec.elements[childKey];
1312
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1545
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1313
1546
  get when() {
1314
1547
  return childElement();
1315
1548
  },
@@ -1319,24 +1552,27 @@ function RepeatChildren(props) {
1319
1552
  }
1320
1553
  return null;
1321
1554
  },
1322
- children: (el) => (0, import_web18.createComponent)(ElementRenderer, {
1323
- get element() {
1324
- return el();
1325
- },
1326
- elementKey: childKey,
1327
- get spec() {
1328
- return props.spec;
1329
- },
1330
- get registry() {
1331
- return props.registry;
1332
- },
1333
- get loading() {
1334
- return props.loading;
1335
- },
1336
- get fallback() {
1337
- return props.fallback;
1338
- }
1339
- })
1555
+ children: (el) => {
1556
+ const element = lastElementOf(childElement, el());
1557
+ return (0, import_web18.createComponent)(ElementRenderer, {
1558
+ get element() {
1559
+ return element();
1560
+ },
1561
+ elementKey: childKey,
1562
+ get spec() {
1563
+ return props.spec;
1564
+ },
1565
+ get registry() {
1566
+ return props.registry;
1567
+ },
1568
+ get loading() {
1569
+ return props.loading;
1570
+ },
1571
+ get fallback() {
1572
+ return props.fallback;
1573
+ }
1574
+ });
1575
+ }
1340
1576
  });
1341
1577
  }
1342
1578
  });
@@ -1346,40 +1582,60 @@ function RepeatChildren(props) {
1346
1582
  });
1347
1583
  }
1348
1584
  function Renderer(props) {
1349
- const rootElement = (0, import_solid_js6.createMemo)(() => {
1585
+ const rootElement = (0, import_solid_js9.createMemo)(() => {
1350
1586
  const spec = props.spec;
1351
1587
  if (!spec || !spec.root) return void 0;
1352
1588
  return spec.elements[spec.root];
1353
1589
  });
1354
- const rendererRegistry = (0, import_solid_js6.createMemo)(() => props.onRenderError ? (0, import_core6.withRenderErrorHandler)(props.registry, props.onRenderError) : props.registry);
1355
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1590
+ const rendererRegistry = (0, import_solid_js9.createMemo)(() => props.onRenderError ? (0, import_core7.withRenderErrorHandler)(props.registry, props.onRenderError) : props.registry);
1591
+ useMissingRootWarning(() => props.spec?.root, rootElement, () => props.loading);
1592
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1356
1593
  get when() {
1357
1594
  return rootElement();
1358
1595
  },
1359
- children: (el) => (0, import_web18.createComponent)(ElementRenderer, {
1360
- get element() {
1361
- return el();
1362
- },
1363
- get elementKey() {
1364
- return props.spec.root;
1365
- },
1366
- get spec() {
1367
- return props.spec;
1368
- },
1369
- get registry() {
1370
- return rendererRegistry();
1371
- },
1372
- get loading() {
1373
- return props.loading;
1374
- },
1375
- get fallback() {
1376
- return props.fallback;
1377
- }
1378
- })
1596
+ children: (el) => {
1597
+ const element = lastElementOf(rootElement, el());
1598
+ return (0, import_web18.createComponent)(ElementBoundary, {
1599
+ root: true,
1600
+ get registry() {
1601
+ return rendererRegistry();
1602
+ },
1603
+ get type() {
1604
+ return element().type;
1605
+ },
1606
+ get elementKey() {
1607
+ return props.spec?.root;
1608
+ },
1609
+ subtree: () => (0, import_core7.elementSubtreeJson)(props.spec, props.spec?.root, element()),
1610
+ get children() {
1611
+ return (0, import_web18.createComponent)(ElementRenderer, {
1612
+ get element() {
1613
+ return element();
1614
+ },
1615
+ get elementKey() {
1616
+ return props.spec.root;
1617
+ },
1618
+ root: true,
1619
+ get spec() {
1620
+ return props.spec;
1621
+ },
1622
+ get registry() {
1623
+ return rendererRegistry();
1624
+ },
1625
+ get loading() {
1626
+ return props.loading;
1627
+ },
1628
+ get fallback() {
1629
+ return props.fallback;
1630
+ }
1631
+ });
1632
+ }
1633
+ });
1634
+ }
1379
1635
  });
1380
1636
  }
1381
1637
  function JSONUIProvider(props) {
1382
- const directiveRegistry = (0, import_solid_js6.createMemo)(() => props.directives ? (0, import_core6.createDirectiveRegistry)(props.directives) : void 0);
1638
+ const directiveRegistry = (0, import_solid_js9.createMemo)(() => props.directives ? (0, import_core7.createDirectiveRegistry)(props.directives) : void 0);
1383
1639
  return (0, import_web18.createComponent)(StateProvider, {
1384
1640
  get store() {
1385
1641
  return props.store;
@@ -1432,7 +1688,7 @@ function JSONUIProvider(props) {
1432
1688
  }
1433
1689
  function ConfirmationDialogManager() {
1434
1690
  const actions = useActions();
1435
- return (0, import_web18.createComponent)(import_solid_js6.Show, {
1691
+ return (0, import_web18.createComponent)(import_solid_js9.Show, {
1436
1692
  get when() {
1437
1693
  return actions.pendingConfirmation?.action.confirm;
1438
1694
  },
@@ -1450,7 +1706,7 @@ function ConfirmationDialogManager() {
1450
1706
  });
1451
1707
  }
1452
1708
  function defineRegistry(catalog, options) {
1453
- const registry = (0, import_core6.createComponentRegistry)(options.components);
1709
+ const registry = (0, import_core7.createComponentRegistry)(options.components);
1454
1710
  if (options.components) {
1455
1711
  for (const [name, componentFn] of Object.entries(options.components)) {
1456
1712
  registry[name] = (renderProps) => {
@@ -1476,7 +1732,7 @@ function defineRegistry(catalog, options) {
1476
1732
  };
1477
1733
  }
1478
1734
  }
1479
- (0, import_core6.setCatalogSlotMetadata)(registry, catalog);
1735
+ (0, import_core7.setCatalogSlotMetadata)(registry, catalog);
1480
1736
  const actionMap = options.actions ? Object.entries(options.actions) : [];
1481
1737
  const handlers = (getSetState, getState) => {
1482
1738
  const result = {};
@@ -1500,7 +1756,7 @@ function defineRegistry(catalog, options) {
1500
1756
  }
1501
1757
  };
1502
1758
  if (options.onRenderError) {
1503
- (0, import_core6.setRenderErrorHandler)(registry, options.onRenderError);
1759
+ (0, import_core7.setRenderErrorHandler)(registry, options.onRenderError);
1504
1760
  }
1505
1761
  return {
1506
1762
  registry,
@@ -1510,10 +1766,10 @@ function defineRegistry(catalog, options) {
1510
1766
  }
1511
1767
  function createRenderer(catalog, components) {
1512
1768
  const registry = components;
1513
- (0, import_core6.setCatalogSlotMetadata)(registry, catalog);
1769
+ (0, import_core7.setCatalogSlotMetadata)(registry, catalog);
1514
1770
  return function CatalogRenderer(props) {
1515
- const directiveRegistry = (0, import_solid_js6.createMemo)(() => props.directives ? (0, import_core6.createDirectiveRegistry)(props.directives) : void 0);
1516
- const rendererRegistry = (0, import_solid_js6.createMemo)(() => props.onRenderError ? (0, import_core6.withRenderErrorHandler)(registry, props.onRenderError) : registry);
1771
+ const directiveRegistry = (0, import_solid_js9.createMemo)(() => props.directives ? (0, import_core7.createDirectiveRegistry)(props.directives) : void 0);
1772
+ const rendererRegistry = (0, import_solid_js9.createMemo)(() => props.onRenderError ? (0, import_core7.withRenderErrorHandler)(registry, props.onRenderError) : registry);
1517
1773
  const actionHandlers = () => props.onAction ? new Proxy({}, {
1518
1774
  get: (_target, prop) => {
1519
1775
  return (params) => props.onAction(prop, params);
@@ -1580,8 +1836,8 @@ function createRenderer(catalog, components) {
1580
1836
  }
1581
1837
 
1582
1838
  // src/hooks.ts
1583
- var import_solid_js7 = require("solid-js");
1584
- var import_core7 = require("@xmachines/json-render-core");
1839
+ var import_solid_js10 = require("solid-js");
1840
+ var import_core8 = require("@xmachines/json-render-core");
1585
1841
  function parseLine(line) {
1586
1842
  try {
1587
1843
  const trimmed = line.trim();
@@ -1616,7 +1872,7 @@ function setSpecValue(newSpec, path, value) {
1616
1872
  if (path.startsWith("/state/")) {
1617
1873
  if (!newSpec.state) newSpec.state = {};
1618
1874
  const statePath = path.slice("/state".length);
1619
- (0, import_core7.setByPath)(newSpec.state, statePath, value);
1875
+ (0, import_core8.setByPath)(newSpec.state, statePath, value);
1620
1876
  return;
1621
1877
  }
1622
1878
  if (path.startsWith("/elements/")) {
@@ -1630,7 +1886,7 @@ function setSpecValue(newSpec, path, value) {
1630
1886
  if (element) {
1631
1887
  const propPath = "/" + pathParts.slice(1).join("/");
1632
1888
  const newElement = { ...element };
1633
- (0, import_core7.setByPath)(
1889
+ (0, import_core8.setByPath)(
1634
1890
  newElement,
1635
1891
  propPath,
1636
1892
  value
@@ -1647,7 +1903,7 @@ function removeSpecValue(newSpec, path) {
1647
1903
  }
1648
1904
  if (path.startsWith("/state/") && newSpec.state) {
1649
1905
  const statePath = path.slice("/state".length);
1650
- (0, import_core7.removeByPath)(newSpec.state, statePath);
1906
+ (0, import_core8.removeByPath)(newSpec.state, statePath);
1651
1907
  return;
1652
1908
  }
1653
1909
  if (path.startsWith("/elements/")) {
@@ -1662,7 +1918,7 @@ function removeSpecValue(newSpec, path) {
1662
1918
  if (element) {
1663
1919
  const propPath = "/" + pathParts.slice(1).join("/");
1664
1920
  const newElement = { ...element };
1665
- (0, import_core7.removeByPath)(
1921
+ (0, import_core8.removeByPath)(
1666
1922
  newElement,
1667
1923
  propPath
1668
1924
  );
@@ -1676,9 +1932,9 @@ function getSpecValue(spec, path) {
1676
1932
  if (path === "/state") return spec.state;
1677
1933
  if (path.startsWith("/state/") && spec.state) {
1678
1934
  const statePath = path.slice("/state".length);
1679
- return (0, import_core7.getByPath)(spec.state, statePath);
1935
+ return (0, import_core8.getByPath)(spec.state, statePath);
1680
1936
  }
1681
- return (0, import_core7.getByPath)(spec, path);
1937
+ return (0, import_core8.getByPath)(spec, path);
1682
1938
  }
1683
1939
  function applyPatch(spec, patch) {
1684
1940
  const newSpec = {
@@ -1716,11 +1972,11 @@ function applyPatch(spec, patch) {
1716
1972
  return newSpec;
1717
1973
  }
1718
1974
  function useUIStream(options) {
1719
- const [spec, setSpec] = (0, import_solid_js7.createSignal)(null);
1720
- const [isStreaming, setIsStreaming] = (0, import_solid_js7.createSignal)(false);
1721
- const [error, setError] = (0, import_solid_js7.createSignal)(null);
1722
- const [usage, setUsage] = (0, import_solid_js7.createSignal)(null);
1723
- const [rawLines, setRawLines] = (0, import_solid_js7.createSignal)([]);
1975
+ const [spec, setSpec] = (0, import_solid_js10.createSignal)(null);
1976
+ const [isStreaming, setIsStreaming] = (0, import_solid_js10.createSignal)(false);
1977
+ const [error, setError] = (0, import_solid_js10.createSignal)(null);
1978
+ const [usage, setUsage] = (0, import_solid_js10.createSignal)(null);
1979
+ const [rawLines, setRawLines] = (0, import_solid_js10.createSignal)([]);
1724
1980
  let abortController = null;
1725
1981
  const clear = () => {
1726
1982
  setSpec(null);
@@ -1811,7 +2067,7 @@ function useUIStream(options) {
1811
2067
  setIsStreaming(false);
1812
2068
  }
1813
2069
  };
1814
- (0, import_solid_js7.onCleanup)(() => {
2070
+ (0, import_solid_js10.onCleanup)(() => {
1815
2071
  abortController?.abort();
1816
2072
  });
1817
2073
  return {
@@ -1862,8 +2118,10 @@ function flatToTree(elements) {
1862
2118
  }
1863
2119
  function useBoundProp(propValue, bindingPath) {
1864
2120
  const { set } = useStateStore();
2121
+ const path = pathAccessor(bindingPath);
1865
2122
  const setValue = (value) => {
1866
- if (bindingPath) set(bindingPath, value);
2123
+ const now = path();
2124
+ if (now) set(now, value);
1867
2125
  };
1868
2126
  return [propValue, setValue];
1869
2127
  }
@@ -1884,18 +2142,18 @@ function buildSpecFromParts(parts) {
1884
2142
  const spec = { root: "", elements: {} };
1885
2143
  let hasSpec = false;
1886
2144
  for (const part of parts) {
1887
- if (part.type === import_core7.SPEC_DATA_PART_TYPE) {
2145
+ if (part.type === import_core8.SPEC_DATA_PART_TYPE) {
1888
2146
  if (!isSpecDataPart(part.data)) continue;
1889
2147
  const payload = part.data;
1890
2148
  if (payload.type === "patch") {
1891
2149
  hasSpec = true;
1892
- (0, import_core7.applySpecPatch)(spec, payload.patch);
2150
+ (0, import_core8.applySpecPatch)(spec, payload.patch);
1893
2151
  } else if (payload.type === "flat") {
1894
2152
  hasSpec = true;
1895
2153
  Object.assign(spec, payload.spec);
1896
2154
  } else if (payload.type === "nested") {
1897
2155
  hasSpec = true;
1898
- const flat = (0, import_core7.nestedToFlat)(payload.spec);
2156
+ const flat = (0, import_core8.nestedToFlat)(payload.spec);
1899
2157
  Object.assign(spec, flat);
1900
2158
  }
1901
2159
  }
@@ -1908,7 +2166,7 @@ function getTextFromParts(parts) {
1908
2166
  ).map((p) => p.text.trim()).filter(Boolean).join("\n\n");
1909
2167
  }
1910
2168
  function useJsonRenderMessage(getParts) {
1911
- const result = (0, import_solid_js7.createMemo)(() => {
2169
+ const result = (0, import_solid_js10.createMemo)(() => {
1912
2170
  const parts = getParts();
1913
2171
  return {
1914
2172
  spec: buildSpecFromParts(parts),
@@ -1937,9 +2195,9 @@ function generateChatId() {
1937
2195
  return `msg-${Date.now()}-${chatMessageIdCounter}`;
1938
2196
  }
1939
2197
  function useChatUI(options) {
1940
- const [messages, setMessages] = (0, import_solid_js7.createSignal)([]);
1941
- const [isStreaming, setIsStreaming] = (0, import_solid_js7.createSignal)(false);
1942
- const [error, setError] = (0, import_solid_js7.createSignal)(null);
2198
+ const [messages, setMessages] = (0, import_solid_js10.createSignal)([]);
2199
+ const [isStreaming, setIsStreaming] = (0, import_solid_js10.createSignal)(false);
2200
+ const [error, setError] = (0, import_solid_js10.createSignal)(null);
1943
2201
  let abortController = null;
1944
2202
  const clear = () => {
1945
2203
  setMessages([]);
@@ -2000,10 +2258,10 @@ function useChatUI(options) {
2000
2258
  throw new Error("No response body");
2001
2259
  }
2002
2260
  const decoder = new TextDecoder();
2003
- const parser = (0, import_core7.createMixedStreamParser)({
2261
+ const parser = (0, import_core8.createMixedStreamParser)({
2004
2262
  onPatch(patch) {
2005
2263
  hasSpec = true;
2006
- (0, import_core7.applySpecPatch)(currentSpec, patch);
2264
+ (0, import_core8.applySpecPatch)(currentSpec, patch);
2007
2265
  setMessages(
2008
2266
  (prev) => prev.map(
2009
2267
  (m) => m.id === assistantId ? {
@@ -2057,7 +2315,7 @@ function useChatUI(options) {
2057
2315
  setIsStreaming(false);
2058
2316
  }
2059
2317
  };
2060
- (0, import_solid_js7.onCleanup)(() => {
2318
+ (0, import_solid_js10.onCleanup)(() => {
2061
2319
  abortController?.abort();
2062
2320
  });
2063
2321
  return {