@xmachines/json-render-solid 0.19.0-xm.3 → 0.20.0-xm.2

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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  elementTreeSchema,
3
3
  schema
4
- } from "./chunk-XTSB6FIM.mjs";
4
+ } from "./chunk-ZTWTJIEL.mjs";
5
5
 
6
6
  // src/contexts/state.tsx
7
7
  import { createComponent as _$createComponent } from "solid-js/web";
@@ -199,7 +199,7 @@ import { resolveAction, executeAction, nextActionDispatchId, notifyActionDispatc
199
199
 
200
200
  // src/contexts/validation.tsx
201
201
  import { createComponent as _$createComponent3 } from "solid-js/web";
202
- import { createContext as createContext3, useContext as useContext3, createSignal as createSignal2, createEffect as createEffect2, createMemo as createMemo2 } from "solid-js";
202
+ import { createContext as createContext3, useContext as useContext3, createSignal as createSignal2, createEffect as createEffect2, createMemo as createMemo2, onCleanup as onCleanup2 } from "solid-js";
203
203
  import { runValidation } from "@xmachines/json-render-core";
204
204
  var ValidationContext = createContext3(null);
205
205
  function dynamicArgsEqual(a, b) {
@@ -244,7 +244,9 @@ function ValidationProvider(props) {
244
244
  const [fieldStates, setFieldStates] = createSignal2({});
245
245
  let fieldStatesRef = {};
246
246
  const [fieldConfigs, setFieldConfigs] = createSignal2({});
247
+ const registrationCounts = {};
247
248
  const registerField = (path, config) => {
249
+ registrationCounts[path] = (registrationCounts[path] ?? 0) + 1;
248
250
  setFieldConfigs((prev) => {
249
251
  const existing = prev[path];
250
252
  if (existing && validationConfigEqual(existing, config)) {
@@ -256,6 +258,23 @@ function ValidationProvider(props) {
256
258
  };
257
259
  });
258
260
  };
261
+ const unregisterField = (path) => {
262
+ const next = (registrationCounts[path] ?? 0) - 1;
263
+ if (next > 0) {
264
+ registrationCounts[path] = next;
265
+ return;
266
+ }
267
+ delete registrationCounts[path];
268
+ delete fieldStatesRef[path];
269
+ setFieldConfigs((prev) => {
270
+ if (!(path in prev)) return prev;
271
+ const {
272
+ [path]: _removed,
273
+ ...rest
274
+ } = prev;
275
+ return rest;
276
+ });
277
+ };
259
278
  const validate = (path, config) => {
260
279
  const currentState = getSnapshot();
261
280
  const segments = path.split("/").filter(Boolean);
@@ -327,7 +346,8 @@ function ValidationProvider(props) {
327
346
  touch,
328
347
  clear,
329
348
  validateAll,
330
- registerField
349
+ registerField,
350
+ unregisterField
331
351
  };
332
352
  return _$createComponent3(ValidationContext.Provider, {
333
353
  value,
@@ -351,6 +371,7 @@ function useFieldValidation(path, config) {
351
371
  createEffect2(() => {
352
372
  if (path && config) {
353
373
  validation.registerField(path, config);
374
+ onCleanup2(() => validation.unregisterField(path));
354
375
  }
355
376
  });
356
377
  const state = createMemo2(() => {
@@ -547,11 +568,8 @@ function ActionProvider(props) {
547
568
  handler,
548
569
  setState: set,
549
570
  navigate: props.navigate,
550
- executeAction: async (name) => {
551
- const subBinding = {
552
- action: name
553
- };
554
- await execute(subBinding);
571
+ executeAction: async (binding2) => {
572
+ await execute(binding2);
555
573
  }
556
574
  });
557
575
  } finally {
@@ -570,11 +588,8 @@ function ActionProvider(props) {
570
588
  handler,
571
589
  setState: set,
572
590
  navigate: props.navigate,
573
- executeAction: async (name) => {
574
- const subBinding = {
575
- action: name
576
- };
577
- await execute(subBinding);
591
+ executeAction: async (binding2) => {
592
+ await execute(binding2);
578
593
  }
579
594
  });
580
595
  } finally {
@@ -694,8 +709,8 @@ import { effect as _$effect2 } from "solid-js/web";
694
709
  import { insert as _$insert2 } from "solid-js/web";
695
710
  import { memo as _$memo2 } from "solid-js/web";
696
711
  import { createComponent as _$createComponent6 } from "solid-js/web";
697
- import { createContext as createContext6, useContext as useContext6, createMemo as createMemo3, createEffect as createEffect3, createSignal as createSignal4, onCleanup as onCleanup2, ErrorBoundary, Show, For } from "solid-js";
698
- import { resolveElementProps, resolveBindings, resolveActionParam, evaluateVisibility as evaluateVisibility2, getByPath as getByPath2, isDevtoolsActive, subscribeDevtoolsActive, createDirectiveRegistry } from "@xmachines/json-render-core";
712
+ import { createContext as createContext6, useContext as useContext6, createMemo as createMemo3, createEffect as createEffect3, createSignal as createSignal4, onCleanup as onCleanup3, ErrorBoundary, Show, For } from "solid-js";
713
+ import { resolveElementProps, resolveBindings, resolveActionParam, resolveRepeatItemStatePath, resolveRepeatStatePath, evaluateVisibility as evaluateVisibility2, getByPath as getByPath2, isDevtoolsActive, subscribeDevtoolsActive, createDirectiveRegistry, splitRepeatVisibility } from "@xmachines/json-render-core";
699
714
  var _tmpl$2 = /* @__PURE__ */ _$template2(`<span style=display:contents>`);
700
715
  function reportRenderError(registry, elementType, error) {
701
716
  const onRenderError = registry?.onRenderError;
@@ -717,7 +732,7 @@ function useDirectives() {
717
732
  function useDevtoolsActive() {
718
733
  const [active, setActive] = createSignal4(isDevtoolsActive());
719
734
  const unsub = subscribeDevtoolsActive(() => setActive(isDevtoolsActive()));
720
- onCleanup2(unsub);
735
+ onCleanup3(unsub);
721
736
  return active;
722
737
  }
723
738
  function ElementRenderer(props) {
@@ -753,7 +768,14 @@ function ElementRenderer(props) {
753
768
  directives
754
769
  };
755
770
  });
756
- const isVisible = createMemo3(() => props.element.visible === void 0 ? true : evaluateVisibility2(props.element.visible, fullCtx()));
771
+ const repeatVisibility = createMemo3(() => props.element.repeat !== void 0 && !repeatScope ? splitRepeatVisibility(props.element.visible) : {
772
+ container: props.element.visible,
773
+ itemFilter: void 0
774
+ });
775
+ const isVisible = createMemo3(() => {
776
+ const container = repeatVisibility().container;
777
+ return container === void 0 ? true : evaluateVisibility2(container, fullCtx());
778
+ });
757
779
  const emit = async (eventName) => {
758
780
  const onBindings = props.element.on;
759
781
  const binding = onBindings?.[eventName];
@@ -831,7 +853,7 @@ function ElementRenderer(props) {
831
853
  }
832
854
  })().catch(console.error);
833
855
  });
834
- onCleanup2(() => {
856
+ onCleanup3(() => {
835
857
  unsubscribe();
836
858
  });
837
859
  });
@@ -862,6 +884,9 @@ function ElementRenderer(props) {
862
884
  get resolvedElement() {
863
885
  return resolvedElement();
864
886
  },
887
+ get itemFilter() {
888
+ return repeatVisibility().itemFilter;
889
+ },
865
890
  get elementKey() {
866
891
  return props.elementKey;
867
892
  },
@@ -916,6 +941,9 @@ function ElementRendererContent(props) {
916
941
  },
917
942
  get fallback() {
918
943
  return props.fallback;
944
+ },
945
+ get itemFilter() {
946
+ return props.itemFilter;
919
947
  }
920
948
  }) : _$createComponent6(For, {
921
949
  get each() {
@@ -992,24 +1020,43 @@ function ElementRendererContent(props) {
992
1020
  function RepeatChildren(props) {
993
1021
  const stateStore = useStateStore();
994
1022
  const repeat = () => props.element.repeat;
995
- const statePath = () => repeat().statePath;
996
- const items = () => getByPath2(stateStore.state, statePath()) ?? [];
1023
+ const parentScope = useRepeatScope();
1024
+ const statePath = () => {
1025
+ const resolved = resolveRepeatStatePath(repeat().statePath, parentScope?.basePath);
1026
+ if (resolved === void 0) {
1027
+ console.warn("[json-render/solid] $item in repeat.statePath used outside of a repeat scope");
1028
+ }
1029
+ return resolved;
1030
+ };
1031
+ const items = () => statePath() === void 0 ? [] : getByPath2(stateStore.state, statePath()) ?? [];
1032
+ const entries = () => items().map((itemValue, index) => ({
1033
+ itemValue,
1034
+ index
1035
+ })).filter(({
1036
+ itemValue,
1037
+ index
1038
+ }) => props.itemFilter === void 0 || evaluateVisibility2(props.itemFilter, {
1039
+ stateModel: stateStore.state,
1040
+ repeatItem: itemValue,
1041
+ repeatIndex: index
1042
+ }));
997
1043
  return _$createComponent6(For, {
998
1044
  get each() {
999
- return items();
1045
+ return entries();
1000
1046
  },
1001
- children: (itemValue, index) => {
1047
+ children: ({
1048
+ itemValue,
1049
+ index
1050
+ }) => {
1002
1051
  const key = () => {
1003
1052
  const r = repeat();
1004
- return r.key && typeof itemValue === "object" && itemValue !== null ? String(itemValue[r.key] ?? index()) : String(index());
1053
+ return r.key && typeof itemValue === "object" && itemValue !== null ? String(itemValue[r.key] ?? index) : String(index);
1005
1054
  };
1006
1055
  return _$createComponent6(RepeatScopeProvider, {
1007
1056
  item: itemValue,
1008
- get index() {
1009
- return index();
1010
- },
1057
+ index,
1011
1058
  get basePath() {
1012
- return `${statePath()}/${index()}`;
1059
+ return resolveRepeatItemStatePath(statePath(), index);
1013
1060
  },
1014
1061
  get children() {
1015
1062
  return _$createComponent6(For, {
@@ -1150,21 +1197,21 @@ function JSONUIProvider(props) {
1150
1197
  });
1151
1198
  }
1152
1199
  function ConfirmationDialogManager() {
1153
- const {
1154
- pendingConfirmation,
1155
- confirm,
1156
- cancel
1157
- } = useActions();
1200
+ const actions = useActions();
1158
1201
  return _$createComponent6(Show, {
1159
1202
  get when() {
1160
- return pendingConfirmation?.action.confirm;
1203
+ return actions.pendingConfirmation?.action.confirm;
1161
1204
  },
1162
1205
  children: (confirmConfig) => _$createComponent6(ConfirmDialog, {
1163
1206
  get confirm() {
1164
1207
  return confirmConfig();
1165
1208
  },
1166
- onConfirm: confirm,
1167
- onCancel: cancel
1209
+ get onConfirm() {
1210
+ return actions.confirm;
1211
+ },
1212
+ get onCancel() {
1213
+ return actions.cancel;
1214
+ }
1168
1215
  })
1169
1216
  });
1170
1217
  }
@@ -1309,7 +1356,7 @@ function createRenderer(catalog, components) {
1309
1356
  }
1310
1357
 
1311
1358
  // src/hooks.ts
1312
- import { createSignal as createSignal5, onCleanup as onCleanup3, createMemo as createMemo4 } from "solid-js";
1359
+ import { createSignal as createSignal5, onCleanup as onCleanup4, createMemo as createMemo4 } from "solid-js";
1313
1360
  import {
1314
1361
  setByPath,
1315
1362
  getByPath as getByPath3,
@@ -1548,7 +1595,7 @@ function useUIStream(options) {
1548
1595
  setIsStreaming(false);
1549
1596
  }
1550
1597
  };
1551
- onCleanup3(() => {
1598
+ onCleanup4(() => {
1552
1599
  abortController?.abort();
1553
1600
  });
1554
1601
  return {
@@ -1794,7 +1841,7 @@ function useChatUI(options) {
1794
1841
  setIsStreaming(false);
1795
1842
  }
1796
1843
  };
1797
- onCleanup3(() => {
1844
+ onCleanup4(() => {
1798
1845
  abortController?.abort();
1799
1846
  });
1800
1847
  return {