@fragmentsx/render-react 1.6.2 → 1.6.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"useReadVariables.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariables.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAwBrE,eAAO,MAAM,gBAAgB,iBACb,OAAO,EAAE,kBACP,UAAU,GAAG,IAAI;;;GAoHlC,CAAC"}
1
+ {"version":3,"file":"useReadVariables.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariables.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAyBrE,eAAO,MAAM,gBAAgB,iBACb,OAAO,EAAE,kBACP,UAAU,GAAG,IAAI;;;GA2IlC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useReadVariables.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReadVariables.test.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariables.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"useResolvedLayerVariables.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useResolvedLayerVariables.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AA8BD,eAAO,MAAM,yBAAyB,UAC7B,GAAG,YACA,GAAG,kBACG,OAAO,EAAE,KACxB,iBAiDF,CAAC"}
1
+ {"version":3,"file":"useResolvedLayerVariables.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useResolvedLayerVariables.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AA8BD,eAAO,MAAM,yBAAyB,UAC7B,GAAG,YACA,GAAG,kBACG,OAAO,EAAE,KACxB,iBA2DF,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -31,6 +31,8 @@ const RenderTargetContext = react.createContext(
31
31
  const RenderTargetProvider = RenderTargetContext.Provider;
32
32
  const AreaManagerContext = react.createContext(null);
33
33
  const AreaManagerProvider = AreaManagerContext.Provider;
34
+ const CampaignManagerContext = react.createContext(null);
35
+ const CampaignManagerProvider = CampaignManagerContext.Provider;
34
36
  const ScopeContext = react.createContext([]);
35
37
  const Scope = ({
36
38
  value,
@@ -880,12 +882,13 @@ const extractVariableValue = (input, variableId) => {
880
882
  return void 0;
881
883
  };
882
884
  const useReadVariables = (variableKeys, customManager) => {
883
- var _a, _b, _c, _d;
885
+ var _a, _b, _c, _d, _e;
884
886
  const filterKeys = variableKeys.filter(definition.isVariableLink);
885
887
  const { manager: fragmentManager } = react.useContext(FragmentContext);
886
888
  const { props: instanceProps } = react.useContext(InstanceContext);
887
889
  const globalManager = react.useContext(GlobalManagerContext);
888
890
  const areaManager = react.useContext(AreaManagerContext);
891
+ const campaignManager = react.useContext(CampaignManagerContext);
889
892
  const scopes = react.useContext(ScopeContext);
890
893
  const resultManager = customManager ?? ((_a = react.useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
891
894
  const safeFilterKeys = resultManager ? filterKeys : [];
@@ -898,6 +901,7 @@ const useReadVariables = (variableKeys, customManager) => {
898
901
  );
899
902
  react$1.useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
900
903
  react$1.useGraph(areaManager, (_c = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _c.key);
904
+ react$1.useGraph(campaignManager, (_d = campaignManager == null ? void 0 : campaignManager.$properties) == null ? void 0 : _d.key);
901
905
  const globalPropertyKeys = react.useMemo(() => {
902
906
  if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
903
907
  return filterKeys.filter((key) => globalManager.resolve(key));
@@ -906,12 +910,20 @@ const useReadVariables = (variableKeys, customManager) => {
906
910
  if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
907
911
  return filterKeys.filter((key) => areaManager.resolve(key));
908
912
  }, [filterKeys, areaManager]);
913
+ const campaignPropertyKeys = react.useMemo(() => {
914
+ if (!(campaignManager == null ? void 0 : campaignManager.$properties)) return [];
915
+ return filterKeys.filter((key) => campaignManager.resolve(key));
916
+ }, [filterKeys, campaignManager]);
909
917
  react$1.useGraphStack(
910
918
  globalPropertyKeys.length ? globalManager : null,
911
919
  globalPropertyKeys
912
920
  );
913
921
  react$1.useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
914
- const lastCollectionItem = (_d = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _d.call(
922
+ react$1.useGraphStack(
923
+ campaignPropertyKeys.length ? campaignManager : null,
924
+ campaignPropertyKeys
925
+ );
926
+ const lastCollectionItem = (_e = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _e.call(
915
927
  scopes,
916
928
  (scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.CollectionItemScope
917
929
  );
@@ -925,28 +937,31 @@ const useReadVariables = (variableKeys, customManager) => {
925
937
  collectionItemProp = utils.isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_b2 = core.entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _b2._id) === propertyId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, propertyId);
926
938
  }
927
939
  const instanceProp = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? null;
940
+ const campaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(variableKey);
941
+ const campaignProp = (campaignLayer == null ? void 0 : campaignLayer.defaultValue) ?? null;
928
942
  const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
929
943
  const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
930
944
  const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
931
945
  const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
932
946
  const required = (layer == null ? void 0 : layer.required) ?? false;
933
947
  const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
934
- const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
948
+ const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? campaignProp ?? areaProp ?? globalProp ?? null;
935
949
  const resultValue = required ? currentValue : currentValue ?? defaultValue;
936
950
  if (definition.isVariableLink(resultValue)) {
937
951
  const refKey = resultValue;
952
+ const refCampaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(refKey);
938
953
  const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
939
954
  const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
940
955
  const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
941
- const refValue = (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
956
+ const refValue = (refCampaignLayer == null ? void 0 : refCampaignLayer.defaultValue) ?? (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
942
957
  return {
943
958
  value: refValue,
944
- layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
959
+ layer: refCampaignLayer ?? refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
945
960
  };
946
961
  }
947
962
  return {
948
963
  value: resultValue,
949
- layer: layer ?? areaLayer ?? globalLayer ?? null
964
+ layer: layer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null
950
965
  };
951
966
  });
952
967
  };
@@ -979,9 +994,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
979
994
  const resolved = useReadVariables(variableKeys);
980
995
  if (!layer) return EMPTY_RESOLVED;
981
996
  const resolvedByKey = {};
997
+ const defaultByKey = {};
982
998
  variableKeys.forEach((key, i) => {
983
- var _a2;
999
+ var _a2, _b, _c;
984
1000
  resolvedByKey[key] = ((_a2 = resolved[i]) == null ? void 0 : _a2.value) ?? null;
1001
+ defaultByKey[key] = ((_c = (_b = resolved[i]) == null ? void 0 : _b.layer) == null ? void 0 : _c.defaultValue) ?? null;
985
1002
  });
986
1003
  const values = {};
987
1004
  const cssVariableValues = {};
@@ -990,12 +1007,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
990
1007
  var _a2;
991
1008
  rawValues[fieldPath] = raw;
992
1009
  if (definition.isVariableLink(value)) {
993
- const resolvedValue = resolvedByKey[value] ?? value;
1010
+ const resolvedValue = value in resolvedByKey ? resolvedByKey[value] : value;
994
1011
  values[fieldPath] = resolvedValue;
995
1012
  const variableId = (_a2 = core.entityOfKey(value)) == null ? void 0 : _a2._id;
996
- cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
997
- resolvedValue
998
- )})`;
1013
+ const staticDefault = defaultByKey[value];
1014
+ cssVariableValues[fieldPath] = staticDefault != null ? `var(--${variableId}, ${transformCssValue(staticDefault)})` : `var(--${variableId})`;
999
1015
  } else {
1000
1016
  values[fieldPath] = value;
1001
1017
  cssVariableValues[fieldPath] = transformCssValue(value);
@@ -2135,7 +2151,7 @@ const useLayerInteractions = (layerKey, options) => {
2135
2151
  }
2136
2152
  }
2137
2153
  },
2138
- [globalManager, fragmentManager, areaScope]
2154
+ [globalManager, fragmentManager, areaScope, onChangeProps]
2139
2155
  );
2140
2156
  react.useEffect(() => {
2141
2157
  if (!pause && Array.isArray(interactions)) {
@@ -3099,7 +3115,7 @@ const useInstanceProps = (instanceProps) => {
3099
3115
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3100
3116
  const [localProps, setLocalProps] = react.useState(instanceProps.props ?? {});
3101
3117
  let inputProps = instanceLayerProps;
3102
- if (isTopInstance && utils.isObject(inputProps) && utils.isObject(localProps)) {
3118
+ if (utils.isObject(inputProps) && utils.isObject(localProps)) {
3103
3119
  inputProps = {
3104
3120
  ...inputProps,
3105
3121
  ...localProps
@@ -3151,7 +3167,7 @@ const useInstanceProps = (instanceProps) => {
3151
3167
  );
3152
3168
  continue;
3153
3169
  }
3154
- resolvedProps[key] = resolvedByKey[value] ?? value;
3170
+ resolvedProps[key] = value in resolvedByKey ? resolvedByKey[value] : value;
3155
3171
  }
3156
3172
  }
3157
3173
  react.useEffect(() => {
@@ -3527,8 +3543,15 @@ const AreaInitial = (areaProps) => {
3527
3543
  }),
3528
3544
  [areaData == null ? void 0 : areaData.areaId]
3529
3545
  );
3546
+ const campaignManager = react.useMemo(
3547
+ () => (areaData == null ? void 0 : areaData.campaignId) ? clientCore.createCampaignManager({
3548
+ campaignId: areaData.campaignId,
3549
+ campaignProperties: areaData.campaignProperties ?? void 0
3550
+ }) : null,
3551
+ [areaData == null ? void 0 : areaData.campaignId]
3552
+ );
3530
3553
  if (!areaData) return null;
3531
- return /* @__PURE__ */ jsxRuntime.jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsxRuntime.jsx(
3554
+ return /* @__PURE__ */ jsxRuntime.jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsxRuntime.jsx(CampaignManagerProvider, { value: campaignManager, children: /* @__PURE__ */ jsxRuntime.jsx(
3532
3555
  Scope,
3533
3556
  {
3534
3557
  fragmentManager,
@@ -3540,7 +3563,7 @@ const AreaInitial = (areaProps) => {
3540
3563
  },
3541
3564
  children: /* @__PURE__ */ jsxRuntime.jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
3542
3565
  }
3543
- ) });
3566
+ ) }) });
3544
3567
  };
3545
3568
  const Area = (props) => {
3546
3569
  return "globalManager" in props ? /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsxRuntime.jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(AreaInitial, { ...props }) }) }) }) : /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(AreaInitial, { ...props }) }) });
@@ -3568,6 +3591,8 @@ const useLayerCssOverride = (layerKey) => {
3568
3591
  exports.Area = Area;
3569
3592
  exports.AreaManagerContext = AreaManagerContext;
3570
3593
  exports.AreaManagerProvider = AreaManagerProvider;
3594
+ exports.CampaignManagerContext = CampaignManagerContext;
3595
+ exports.CampaignManagerProvider = CampaignManagerProvider;
3571
3596
  exports.Collection = Collection;
3572
3597
  exports.CssChunk = CssChunk;
3573
3598
  exports.CustomRender = CustomRender;
package/dist/index.es.js CHANGED
@@ -7,7 +7,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
7
7
  import { useGraph, useGraphStack } from "@graph-state/react";
8
8
  import { cleanGraph, generateId, getKey as getKey$1, isValue, isObject, pick, toPx, setKey as setKey$1, toKebabCase, set, isPrimitive, get, omit, noop, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
9
9
  import { keyOfEntity, isPartialKey, entityOfKey, isLinkKey } from "@graph-state/core";
10
- import { createAreaManager } from "@fragmentsx/client-core";
10
+ import { createAreaManager, createCampaignManager } from "@fragmentsx/client-core";
11
11
  const GlobalManagerContext = createContext(null);
12
12
  const GlobalManagerProvider = GlobalManagerContext.Provider;
13
13
  const FragmentContext = createContext({
@@ -29,6 +29,8 @@ const RenderTargetContext = createContext(
29
29
  const RenderTargetProvider = RenderTargetContext.Provider;
30
30
  const AreaManagerContext = createContext(null);
31
31
  const AreaManagerProvider = AreaManagerContext.Provider;
32
+ const CampaignManagerContext = createContext(null);
33
+ const CampaignManagerProvider = CampaignManagerContext.Provider;
32
34
  const ScopeContext = createContext([]);
33
35
  const Scope = ({
34
36
  value,
@@ -878,12 +880,13 @@ const extractVariableValue = (input, variableId) => {
878
880
  return void 0;
879
881
  };
880
882
  const useReadVariables = (variableKeys, customManager) => {
881
- var _a, _b, _c, _d;
883
+ var _a, _b, _c, _d, _e;
882
884
  const filterKeys = variableKeys.filter(isVariableLink$1);
883
885
  const { manager: fragmentManager } = useContext(FragmentContext);
884
886
  const { props: instanceProps } = useContext(InstanceContext);
885
887
  const globalManager = useContext(GlobalManagerContext);
886
888
  const areaManager = useContext(AreaManagerContext);
889
+ const campaignManager = useContext(CampaignManagerContext);
887
890
  const scopes = useContext(ScopeContext);
888
891
  const resultManager = customManager ?? ((_a = useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
889
892
  const safeFilterKeys = resultManager ? filterKeys : [];
@@ -896,6 +899,7 @@ const useReadVariables = (variableKeys, customManager) => {
896
899
  );
897
900
  useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
898
901
  useGraph(areaManager, (_c = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _c.key);
902
+ useGraph(campaignManager, (_d = campaignManager == null ? void 0 : campaignManager.$properties) == null ? void 0 : _d.key);
899
903
  const globalPropertyKeys = useMemo(() => {
900
904
  if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
901
905
  return filterKeys.filter((key) => globalManager.resolve(key));
@@ -904,12 +908,20 @@ const useReadVariables = (variableKeys, customManager) => {
904
908
  if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
905
909
  return filterKeys.filter((key) => areaManager.resolve(key));
906
910
  }, [filterKeys, areaManager]);
911
+ const campaignPropertyKeys = useMemo(() => {
912
+ if (!(campaignManager == null ? void 0 : campaignManager.$properties)) return [];
913
+ return filterKeys.filter((key) => campaignManager.resolve(key));
914
+ }, [filterKeys, campaignManager]);
907
915
  useGraphStack(
908
916
  globalPropertyKeys.length ? globalManager : null,
909
917
  globalPropertyKeys
910
918
  );
911
919
  useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
912
- const lastCollectionItem = (_d = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _d.call(
920
+ useGraphStack(
921
+ campaignPropertyKeys.length ? campaignManager : null,
922
+ campaignPropertyKeys
923
+ );
924
+ const lastCollectionItem = (_e = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _e.call(
913
925
  scopes,
914
926
  (scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
915
927
  );
@@ -923,28 +935,31 @@ const useReadVariables = (variableKeys, customManager) => {
923
935
  collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_b2 = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _b2._id) === propertyId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, propertyId);
924
936
  }
925
937
  const instanceProp = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? null;
938
+ const campaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(variableKey);
939
+ const campaignProp = (campaignLayer == null ? void 0 : campaignLayer.defaultValue) ?? null;
926
940
  const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
927
941
  const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
928
942
  const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
929
943
  const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
930
944
  const required = (layer == null ? void 0 : layer.required) ?? false;
931
945
  const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
932
- const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
946
+ const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? campaignProp ?? areaProp ?? globalProp ?? null;
933
947
  const resultValue = required ? currentValue : currentValue ?? defaultValue;
934
948
  if (isVariableLink$1(resultValue)) {
935
949
  const refKey = resultValue;
950
+ const refCampaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(refKey);
936
951
  const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
937
952
  const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
938
953
  const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
939
- const refValue = (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
954
+ const refValue = (refCampaignLayer == null ? void 0 : refCampaignLayer.defaultValue) ?? (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
940
955
  return {
941
956
  value: refValue,
942
- layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
957
+ layer: refCampaignLayer ?? refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
943
958
  };
944
959
  }
945
960
  return {
946
961
  value: resultValue,
947
- layer: layer ?? areaLayer ?? globalLayer ?? null
962
+ layer: layer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null
948
963
  };
949
964
  });
950
965
  };
@@ -977,9 +992,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
977
992
  const resolved = useReadVariables(variableKeys);
978
993
  if (!layer) return EMPTY_RESOLVED;
979
994
  const resolvedByKey = {};
995
+ const defaultByKey = {};
980
996
  variableKeys.forEach((key, i) => {
981
- var _a2;
997
+ var _a2, _b, _c;
982
998
  resolvedByKey[key] = ((_a2 = resolved[i]) == null ? void 0 : _a2.value) ?? null;
999
+ defaultByKey[key] = ((_c = (_b = resolved[i]) == null ? void 0 : _b.layer) == null ? void 0 : _c.defaultValue) ?? null;
983
1000
  });
984
1001
  const values = {};
985
1002
  const cssVariableValues = {};
@@ -988,12 +1005,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
988
1005
  var _a2;
989
1006
  rawValues[fieldPath] = raw;
990
1007
  if (isVariableLink$1(value)) {
991
- const resolvedValue = resolvedByKey[value] ?? value;
1008
+ const resolvedValue = value in resolvedByKey ? resolvedByKey[value] : value;
992
1009
  values[fieldPath] = resolvedValue;
993
1010
  const variableId = (_a2 = entityOfKey(value)) == null ? void 0 : _a2._id;
994
- cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
995
- resolvedValue
996
- )})`;
1011
+ const staticDefault = defaultByKey[value];
1012
+ cssVariableValues[fieldPath] = staticDefault != null ? `var(--${variableId}, ${transformCssValue(staticDefault)})` : `var(--${variableId})`;
997
1013
  } else {
998
1014
  values[fieldPath] = value;
999
1015
  cssVariableValues[fieldPath] = transformCssValue(value);
@@ -2133,7 +2149,7 @@ const useLayerInteractions = (layerKey, options) => {
2133
2149
  }
2134
2150
  }
2135
2151
  },
2136
- [globalManager, fragmentManager, areaScope]
2152
+ [globalManager, fragmentManager, areaScope, onChangeProps]
2137
2153
  );
2138
2154
  useEffect(() => {
2139
2155
  if (!pause && Array.isArray(interactions)) {
@@ -3097,7 +3113,7 @@ const useInstanceProps = (instanceProps) => {
3097
3113
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3098
3114
  const [localProps, setLocalProps] = useState(instanceProps.props ?? {});
3099
3115
  let inputProps = instanceLayerProps;
3100
- if (isTopInstance && isObject(inputProps) && isObject(localProps)) {
3116
+ if (isObject(inputProps) && isObject(localProps)) {
3101
3117
  inputProps = {
3102
3118
  ...inputProps,
3103
3119
  ...localProps
@@ -3149,7 +3165,7 @@ const useInstanceProps = (instanceProps) => {
3149
3165
  );
3150
3166
  continue;
3151
3167
  }
3152
- resolvedProps[key] = resolvedByKey[value] ?? value;
3168
+ resolvedProps[key] = value in resolvedByKey ? resolvedByKey[value] : value;
3153
3169
  }
3154
3170
  }
3155
3171
  useEffect(() => {
@@ -3525,8 +3541,15 @@ const AreaInitial = (areaProps) => {
3525
3541
  }),
3526
3542
  [areaData == null ? void 0 : areaData.areaId]
3527
3543
  );
3544
+ const campaignManager = useMemo(
3545
+ () => (areaData == null ? void 0 : areaData.campaignId) ? createCampaignManager({
3546
+ campaignId: areaData.campaignId,
3547
+ campaignProperties: areaData.campaignProperties ?? void 0
3548
+ }) : null,
3549
+ [areaData == null ? void 0 : areaData.campaignId]
3550
+ );
3528
3551
  if (!areaData) return null;
3529
- return /* @__PURE__ */ jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsx(
3552
+ return /* @__PURE__ */ jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsx(CampaignManagerProvider, { value: campaignManager, children: /* @__PURE__ */ jsx(
3530
3553
  Scope,
3531
3554
  {
3532
3555
  fragmentManager,
@@ -3538,7 +3561,7 @@ const AreaInitial = (areaProps) => {
3538
3561
  },
3539
3562
  children: /* @__PURE__ */ jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
3540
3563
  }
3541
- ) });
3564
+ ) }) });
3542
3565
  };
3543
3566
  const Area = (props) => {
3544
3567
  return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) }) }) : /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) });
@@ -3567,6 +3590,8 @@ export {
3567
3590
  Area,
3568
3591
  AreaManagerContext,
3569
3592
  AreaManagerProvider,
3593
+ CampaignManagerContext,
3594
+ CampaignManagerProvider,
3570
3595
  Collection,
3571
3596
  CssChunk,
3572
3597
  CustomRender,
@@ -1 +1 @@
1
- {"version":3,"file":"Area.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/Area.tsx"],"names":[],"mappings":"AAuCA,MAAM,MAAM,WAAW,GAAG,CACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7B,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC;IAC9C,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,CAAC;CACH;AAwDD,eAAO,MAAM,IAAI,UAAW,SAAS,4CAgBpC,CAAC"}
1
+ {"version":3,"file":"Area.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/Area.tsx"],"names":[],"mappings":"AA8CA,MAAM,MAAM,WAAW,GAAG,CACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7B,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC;IAC9C,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,CAAC;CACH;AAqED,eAAO,MAAM,IAAI,UAAW,SAAS,4CAgBpC,CAAC"}
@@ -13,6 +13,7 @@ export interface AreaData {
13
13
  campaignId: string;
14
14
  variantId: string;
15
15
  areaProperties?: unknown;
16
+ campaignProperties?: any[] | null;
16
17
  }
17
18
  export interface UseAreaResult {
18
19
  data: AreaData | null;
@@ -1 +1 @@
1
- {"version":3,"file":"useArea.types.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Area/hooks/useArea.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8CAA8C;IAC9C,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;CAChB"}
1
+ {"version":3,"file":"useArea.types.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Area/hooks/useArea.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8CAA8C;IAC9C,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;CAChB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useInstanceProps.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstanceProps.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA+K1D,eAAO,MAAM,gBAAgB,kBAAmB,aAAa;;gCAwG7B,MAAM,SAAS,OAAO;CAKrD,CAAC"}
1
+ {"version":3,"file":"useInstanceProps.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstanceProps.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AA+K1D,eAAO,MAAM,gBAAgB,kBAAmB,aAAa;;gCA2G7B,MAAM,SAAS,OAAO;CAKrD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=collection-isolation.browser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-isolation.browser.test.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/test/collection-isolation.browser.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mutate-event.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutate-event.test.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/test/mutate-event.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare const CampaignManagerContext: import('react').Context<null>;
2
+ export declare const CampaignManagerProvider: import('react').Provider<null>;
3
+ //# sourceMappingURL=CampaignManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CampaignManager.d.ts","sourceRoot":"","sources":["../../src/providers/CampaignManager.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,+BAAsB,CAAC;AAC1D,eAAO,MAAM,uBAAuB,gCAAkC,CAAC"}
@@ -4,6 +4,7 @@ export * from './CustomRender';
4
4
  export * from './InstanceContext';
5
5
  export * from './RenderTarget';
6
6
  export * from './AreaManager';
7
+ export * from './CampaignManager';
7
8
  export { Scope } from './Scope';
8
9
  export { ScopeContext } from './Scope/ScopeContext';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fragmentsx/render-react",
3
3
  "private": false,
4
- "version": "1.6.2",
4
+ "version": "1.6.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -27,9 +27,9 @@
27
27
  "@graph-state/core": "^0.13.2",
28
28
  "@graph-state/react": "^0.8.3",
29
29
  "react-use-measure": "^2.1.7",
30
- "@fragmentsx/client-core": "0.4.2",
31
- "@fragmentsx/utils": "0.2.0",
32
- "@fragmentsx/definition": "0.2.2"
30
+ "@fragmentsx/client-core": "0.4.3",
31
+ "@fragmentsx/definition": "0.2.2",
32
+ "@fragmentsx/utils": "0.2.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@testing-library/jest-dom": "^6.6.3",