@json-render/solid 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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";
@@ -547,11 +547,8 @@ function ActionProvider(props) {
547
547
  handler,
548
548
  setState: set,
549
549
  navigate: props.navigate,
550
- executeAction: async (name) => {
551
- const subBinding = {
552
- action: name
553
- };
554
- await execute(subBinding);
550
+ executeAction: async (binding2) => {
551
+ await execute(binding2);
555
552
  }
556
553
  });
557
554
  } finally {
@@ -570,11 +567,8 @@ function ActionProvider(props) {
570
567
  handler,
571
568
  setState: set,
572
569
  navigate: props.navigate,
573
- executeAction: async (name) => {
574
- const subBinding = {
575
- action: name
576
- };
577
- await execute(subBinding);
570
+ executeAction: async (binding2) => {
571
+ await execute(binding2);
578
572
  }
579
573
  });
580
574
  } finally {
@@ -695,13 +689,17 @@ import { insert as _$insert2 } from "solid-js/web";
695
689
  import { memo as _$memo2 } from "solid-js/web";
696
690
  import { createComponent as _$createComponent6 } from "solid-js/web";
697
691
  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 } from "@json-render/core";
692
+ import { resolveElementProps, resolveBindings, resolveActionParam, resolveRepeatItemStatePath, resolveRepeatStatePath, evaluateVisibility as evaluateVisibility2, getByPath as getByPath2, isDevtoolsActive, subscribeDevtoolsActive, createDirectiveRegistry } from "@json-render/core";
699
693
  var _tmpl$2 = /* @__PURE__ */ _$template2(`<span style=display:contents>`);
700
694
  var EMPTY_FUNCTIONS = {};
701
695
  var FunctionsContext = createContext6(EMPTY_FUNCTIONS);
702
696
  function useFunctions() {
703
697
  return useContext6(FunctionsContext) ?? EMPTY_FUNCTIONS;
704
698
  }
699
+ var DirectivesContext = createContext6(void 0);
700
+ function useDirectives() {
701
+ return useContext6(DirectivesContext);
702
+ }
705
703
  function useDevtoolsActive() {
706
704
  const [active, setActive] = createSignal4(isDevtoolsActive());
707
705
  const unsub = subscribeDevtoolsActive(() => setActive(isDevtoolsActive()));
@@ -719,6 +717,7 @@ function ElementRenderer(props) {
719
717
  const stateStore = useStateStore();
720
718
  const getSnapshot = () => stateStore.getSnapshot();
721
719
  const functions = useFunctions();
720
+ const directives = useDirectives();
722
721
  const fullCtx = createMemo3(() => {
723
722
  const repeatItem = repeatScope?.item;
724
723
  const repeatIndex = repeatScope?.index;
@@ -736,7 +735,8 @@ function ElementRenderer(props) {
736
735
  ...repeatBasePath !== void 0 ? {
737
736
  repeatBasePath
738
737
  } : {},
739
- functions
738
+ functions,
739
+ directives
740
740
  };
741
741
  });
742
742
  const isVisible = createMemo3(() => props.element.visible === void 0 ? true : evaluateVisibility2(props.element.visible, fullCtx()));
@@ -978,8 +978,15 @@ function ElementRendererContent(props) {
978
978
  function RepeatChildren(props) {
979
979
  const stateStore = useStateStore();
980
980
  const repeat = () => props.element.repeat;
981
- const statePath = () => repeat().statePath;
982
- const items = () => getByPath2(stateStore.state, statePath()) ?? [];
981
+ const parentScope = useRepeatScope();
982
+ const statePath = () => {
983
+ const resolved = resolveRepeatStatePath(repeat().statePath, parentScope?.basePath);
984
+ if (resolved === void 0) {
985
+ console.warn("[json-render/solid] $item in repeat.statePath used outside of a repeat scope");
986
+ }
987
+ return resolved;
988
+ };
989
+ const items = () => statePath() === void 0 ? [] : getByPath2(stateStore.state, statePath()) ?? [];
983
990
  return _$createComponent6(For, {
984
991
  get each() {
985
992
  return items();
@@ -995,7 +1002,7 @@ function RepeatChildren(props) {
995
1002
  return index();
996
1003
  },
997
1004
  get basePath() {
998
- return `${statePath()}/${index()}`;
1005
+ return resolveRepeatItemStatePath(statePath(), index());
999
1006
  },
1000
1007
  get children() {
1001
1008
  return _$createComponent6(For, {
@@ -1072,6 +1079,7 @@ function Renderer(props) {
1072
1079
  });
1073
1080
  }
1074
1081
  function JSONUIProvider(props) {
1082
+ const directiveRegistry = createMemo3(() => props.directives ? createDirectiveRegistry(props.directives) : void 0);
1075
1083
  return _$createComponent6(StateProvider, {
1076
1084
  get store() {
1077
1085
  return props.store;
@@ -1103,7 +1111,14 @@ function JSONUIProvider(props) {
1103
1111
  return props.functions ?? EMPTY_FUNCTIONS;
1104
1112
  },
1105
1113
  get children() {
1106
- return [_$memo2(() => props.children), _$createComponent6(ConfirmationDialogManager, {})];
1114
+ return _$createComponent6(DirectivesContext.Provider, {
1115
+ get value() {
1116
+ return directiveRegistry();
1117
+ },
1118
+ get children() {
1119
+ return [_$memo2(() => props.children), _$createComponent6(ConfirmationDialogManager, {})];
1120
+ }
1121
+ });
1107
1122
  }
1108
1123
  });
1109
1124
  }
@@ -1189,6 +1204,7 @@ function defineRegistry(_catalog, options) {
1189
1204
  function createRenderer(catalog, components) {
1190
1205
  const registry = components;
1191
1206
  return function CatalogRenderer(props) {
1207
+ const directiveRegistry = createMemo3(() => props.directives ? createDirectiveRegistry(props.directives) : void 0);
1192
1208
  const actionHandlers = () => props.onAction ? new Proxy({}, {
1193
1209
  get: (_target, prop) => {
1194
1210
  return (params) => props.onAction(prop, params);
@@ -1220,18 +1236,25 @@ function createRenderer(catalog, components) {
1220
1236
  return props.functions ?? EMPTY_FUNCTIONS;
1221
1237
  },
1222
1238
  get children() {
1223
- return [_$createComponent6(Renderer, {
1224
- get spec() {
1225
- return props.spec;
1226
- },
1227
- registry,
1228
- get loading() {
1229
- return props.loading;
1239
+ return _$createComponent6(DirectivesContext.Provider, {
1240
+ get value() {
1241
+ return directiveRegistry();
1230
1242
  },
1231
- get fallback() {
1232
- return props.fallback;
1243
+ get children() {
1244
+ return [_$createComponent6(Renderer, {
1245
+ get spec() {
1246
+ return props.spec;
1247
+ },
1248
+ registry,
1249
+ get loading() {
1250
+ return props.loading;
1251
+ },
1252
+ get fallback() {
1253
+ return props.fallback;
1254
+ }
1255
+ }), _$createComponent6(ConfirmationDialogManager, {})];
1233
1256
  }
1234
- }), _$createComponent6(ConfirmationDialogManager, {})];
1257
+ });
1235
1258
  }
1236
1259
  });
1237
1260
  }