@fragmentsx/render-react 1.6.1 → 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.
Files changed (33) hide show
  1. package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
  2. package/dist/hooks/layer/useReadVariables.d.ts.map +1 -1
  3. package/dist/hooks/layer/useReadVariables.test.d.ts +2 -0
  4. package/dist/hooks/layer/useReadVariables.test.d.ts.map +1 -0
  5. package/dist/hooks/layer/useResolvedLayerVariables.d.ts.map +1 -1
  6. package/dist/hooks/utils/useExtractProps.d.ts.map +1 -1
  7. package/dist/hooks/utils/useLayerInteractions.d.ts.map +1 -1
  8. package/dist/index.cjs.js +186 -48
  9. package/dist/index.es.js +188 -50
  10. package/dist/nodes/Area/Area.d.ts +2 -1
  11. package/dist/nodes/Area/Area.d.ts.map +1 -1
  12. package/dist/nodes/Area/Area.test.d.ts +2 -0
  13. package/dist/nodes/Area/Area.test.d.ts.map +1 -0
  14. package/dist/nodes/Area/hooks/useArea.types.d.ts +1 -0
  15. package/dist/nodes/Area/hooks/useArea.types.d.ts.map +1 -1
  16. package/dist/nodes/Area/index.d.ts +1 -1
  17. package/dist/nodes/Area/index.d.ts.map +1 -1
  18. package/dist/nodes/Collection/hooks/useCollection.d.ts.map +1 -1
  19. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
  20. package/dist/nodes/Instance/test/collection-isolation.browser.test.d.ts +2 -0
  21. package/dist/nodes/Instance/test/collection-isolation.browser.test.d.ts.map +1 -0
  22. package/dist/nodes/Instance/test/mutate-event.test.d.ts +2 -0
  23. package/dist/nodes/Instance/test/mutate-event.test.d.ts.map +1 -0
  24. package/dist/nodes/Text/hooks/useTextAttributes.d.ts +1 -1
  25. package/dist/nodes/Text/hooks/useTextContent.d.ts +3 -1
  26. package/dist/nodes/Text/hooks/useTextContent.d.ts.map +1 -1
  27. package/dist/nodes/Text/hooks/useTextContent.test.d.ts +2 -0
  28. package/dist/nodes/Text/hooks/useTextContent.test.d.ts.map +1 -0
  29. package/dist/providers/CampaignManager.d.ts +3 -0
  30. package/dist/providers/CampaignManager.d.ts.map +1 -0
  31. package/dist/providers/index.d.ts +1 -0
  32. package/dist/providers/index.d.ts.map +1 -1
  33. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"useLayerValue.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,UAAU,EAGV,OAAO,EAER,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,aACd,OAAO,YACP,MAAM,YACN,oBAAoB,UAkF/B,CAAC"}
1
+ {"version":3,"file":"useLayerValue.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,UAAU,EAGV,OAAO,EAER,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,aACd,OAAO,YACP,MAAM,YACN,oBAAoB,UAmF/B,CAAC"}
@@ -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;AAuBrE,eAAO,MAAM,gBAAgB,iBACb,OAAO,EAAE,kBACP,UAAU,GAAG,IAAI;;;GAiHlC,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"useExtractProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useExtractProps.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAe,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAwMrE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,UACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACpB,UAAU,kBACJ,UAAU,gBACZ,OAAO,EAAE,KACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAkQxB,CAAC"}
1
+ {"version":3,"file":"useExtractProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useExtractProps.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAe,OAAO,EAAE,MAAM,mBAAmB,CAAC;AA0OrE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,UACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACpB,UAAU,kBACJ,UAAU,gBACZ,OAAO,EAAE,KACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAwQxB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLayerInteractions.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useLayerInteractions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,OAAO,EAAE,MAAM,mBAAmB,CAAC;AASzD,MAAM,WAAW,2BAA2B;IAC1C,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,oBAAoB,aACrB,OAAO,YACP,2BAA2B;;;;CAwFtC,CAAC"}
1
+ {"version":3,"file":"useLayerInteractions.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useLayerInteractions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,OAAO,EAAE,MAAM,mBAAmB,CAAC;AASzD,MAAM,WAAW,2BAA2B;IAC1C,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,oBAAoB,aACrB,OAAO,YACP,2BAA2B;;;;CAiGtC,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2
5
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
6
  const react = require("react");
4
7
  const definition = require("@fragmentsx/definition");
@@ -28,6 +31,8 @@ const RenderTargetContext = react.createContext(
28
31
  const RenderTargetProvider = RenderTargetContext.Provider;
29
32
  const AreaManagerContext = react.createContext(null);
30
33
  const AreaManagerProvider = AreaManagerContext.Provider;
34
+ const CampaignManagerContext = react.createContext(null);
35
+ const CampaignManagerProvider = CampaignManagerContext.Provider;
31
36
  const ScopeContext = react.createContext([]);
32
37
  const Scope = ({
33
38
  value,
@@ -877,12 +882,13 @@ const extractVariableValue = (input, variableId) => {
877
882
  return void 0;
878
883
  };
879
884
  const useReadVariables = (variableKeys, customManager) => {
880
- var _a, _b, _c, _d;
885
+ var _a, _b, _c, _d, _e;
881
886
  const filterKeys = variableKeys.filter(definition.isVariableLink);
882
887
  const { manager: fragmentManager } = react.useContext(FragmentContext);
883
888
  const { props: instanceProps } = react.useContext(InstanceContext);
884
889
  const globalManager = react.useContext(GlobalManagerContext);
885
890
  const areaManager = react.useContext(AreaManagerContext);
891
+ const campaignManager = react.useContext(CampaignManagerContext);
886
892
  const scopes = react.useContext(ScopeContext);
887
893
  const resultManager = customManager ?? ((_a = react.useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
888
894
  const safeFilterKeys = resultManager ? filterKeys : [];
@@ -895,6 +901,7 @@ const useReadVariables = (variableKeys, customManager) => {
895
901
  );
896
902
  react$1.useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
897
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);
898
905
  const globalPropertyKeys = react.useMemo(() => {
899
906
  if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
900
907
  return filterKeys.filter((key) => globalManager.resolve(key));
@@ -903,46 +910,58 @@ const useReadVariables = (variableKeys, customManager) => {
903
910
  if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
904
911
  return filterKeys.filter((key) => areaManager.resolve(key));
905
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]);
906
917
  react$1.useGraphStack(
907
918
  globalPropertyKeys.length ? globalManager : null,
908
919
  globalPropertyKeys
909
920
  );
910
921
  react$1.useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
911
- 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(
912
927
  scopes,
913
928
  (scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.CollectionItemScope
914
929
  );
915
930
  return filterKeys.map((variableKey, index) => {
916
- var _a2;
917
- const layer = variableLayers[index] ?? null;
931
+ var _a2, _b2;
932
+ variableLayers[index];
933
+ const layer = ((_a2 = getNormalizeLayer(variableKey, resultManager)) == null ? void 0 : _a2.layer) ?? null;
918
934
  const { _id: propertyId } = layer ?? {};
919
935
  let collectionItemProp = void 0;
920
936
  if (lastCollectionItem && propertyId) {
921
- collectionItemProp = utils.isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_a2 = core.entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _a2._id) === propertyId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, propertyId);
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);
922
938
  }
923
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;
924
942
  const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
925
943
  const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
926
944
  const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
927
945
  const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
928
946
  const required = (layer == null ? void 0 : layer.required) ?? false;
929
947
  const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
930
- const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
948
+ const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? campaignProp ?? areaProp ?? globalProp ?? null;
931
949
  const resultValue = required ? currentValue : currentValue ?? defaultValue;
932
950
  if (definition.isVariableLink(resultValue)) {
933
951
  const refKey = resultValue;
952
+ const refCampaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(refKey);
934
953
  const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
935
954
  const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
936
955
  const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
937
- 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;
938
957
  return {
939
958
  value: refValue,
940
- layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
959
+ layer: refCampaignLayer ?? refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
941
960
  };
942
961
  }
943
962
  return {
944
963
  value: resultValue,
945
- layer: layer ?? areaLayer ?? globalLayer ?? null
964
+ layer: layer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null
946
965
  };
947
966
  });
948
967
  };
@@ -975,9 +994,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
975
994
  const resolved = useReadVariables(variableKeys);
976
995
  if (!layer) return EMPTY_RESOLVED;
977
996
  const resolvedByKey = {};
997
+ const defaultByKey = {};
978
998
  variableKeys.forEach((key, i) => {
979
- var _a2;
999
+ var _a2, _b, _c;
980
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;
981
1002
  });
982
1003
  const values = {};
983
1004
  const cssVariableValues = {};
@@ -986,12 +1007,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
986
1007
  var _a2;
987
1008
  rawValues[fieldPath] = raw;
988
1009
  if (definition.isVariableLink(value)) {
989
- const resolvedValue = resolvedByKey[value] ?? value;
1010
+ const resolvedValue = value in resolvedByKey ? resolvedByKey[value] : value;
990
1011
  values[fieldPath] = resolvedValue;
991
1012
  const variableId = (_a2 = core.entityOfKey(value)) == null ? void 0 : _a2._id;
992
- cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
993
- resolvedValue
994
- )})`;
1013
+ const staticDefault = defaultByKey[value];
1014
+ cssVariableValues[fieldPath] = staticDefault != null ? `var(--${variableId}, ${transformCssValue(staticDefault)})` : `var(--${variableId})`;
995
1015
  } else {
996
1016
  values[fieldPath] = value;
997
1017
  cssVariableValues[fieldPath] = transformCssValue(value);
@@ -1906,6 +1926,7 @@ const useLayerStyles = (layerKey) => {
1906
1926
  return {};
1907
1927
  }
1908
1928
  };
1929
+ const MAX_NESTING_DEPTH = 5;
1909
1930
  function extractVariablesFromHtml(html) {
1910
1931
  if (!html) return [];
1911
1932
  const regex = /<span(?=\s)(?=(?:[^>]*?\s)?class="[^"]*variable[^"]*")(?=(?:[^>]*?\s)?data-type="mention")(?=(?:[^>]*?\s)?data-id="([^"]+)")[^>]*>.*?<\/span>/gi;
@@ -1924,24 +1945,75 @@ function extractVariablesFromHtml(html) {
1924
1945
  }
1925
1946
  return mentions;
1926
1947
  }
1948
+ function collectNestedVariableKeys(content, instanceProps, fragmentManager, maxDepth = MAX_NESTING_DEPTH) {
1949
+ var _a, _b;
1950
+ const allKeys = [];
1951
+ const visited = /* @__PURE__ */ new Set();
1952
+ let currentContents = [content];
1953
+ for (let depth = 0; depth < maxDepth; depth++) {
1954
+ const nextContents = [];
1955
+ for (const html of currentContents) {
1956
+ const variables = extractVariablesFromHtml(html);
1957
+ for (const variable of variables) {
1958
+ const keyStr = variable.variableKey;
1959
+ if (visited.has(keyStr)) continue;
1960
+ visited.add(keyStr);
1961
+ allKeys.push(variable.variableKey);
1962
+ const propertyId = (_a = core.entityOfKey(variable.variableKey)) == null ? void 0 : _a._id;
1963
+ const value = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? ((_b = fragmentManager == null ? void 0 : fragmentManager.resolve(variable.variableKey)) == null ? void 0 : _b.defaultValue) ?? null;
1964
+ if (typeof value === "string") {
1965
+ nextContents.push(value);
1966
+ }
1967
+ }
1968
+ }
1969
+ if (nextContents.length === 0) break;
1970
+ currentContents = nextContents;
1971
+ }
1972
+ return allKeys;
1973
+ }
1974
+ function resolveNestedContent(content, resolvedMap, maxDepth = MAX_NESTING_DEPTH) {
1975
+ let result = content;
1976
+ const visited = /* @__PURE__ */ new Set();
1977
+ for (let depth = 0; depth < maxDepth; depth++) {
1978
+ const variables = extractVariablesFromHtml(result);
1979
+ if (variables.length === 0) break;
1980
+ let hasCycle = false;
1981
+ const depthKeys = /* @__PURE__ */ new Set();
1982
+ for (const variable of variables) {
1983
+ const key = variable.variableKey;
1984
+ if (visited.has(key)) {
1985
+ console.warn(`Circular variable reference detected: ${key}`);
1986
+ hasCycle = true;
1987
+ continue;
1988
+ }
1989
+ depthKeys.add(key);
1990
+ result = result.replace(
1991
+ variable.fullMatch,
1992
+ String(resolvedMap.get(key) ?? "")
1993
+ );
1994
+ }
1995
+ for (const key of depthKeys) {
1996
+ visited.add(key);
1997
+ }
1998
+ if (hasCycle) break;
1999
+ }
2000
+ return result;
2001
+ }
1927
2002
  const useTextContent = (layerKey, manager) => {
1928
2003
  const { manager: fragmentManager } = react.useContext(FragmentContext);
1929
- const [content, , contentInfo] = useLayerValue(
1930
- layerKey,
1931
- "content",
1932
- fragmentManager
1933
- );
1934
- const variables = extractVariablesFromHtml(content);
1935
- const variableKeys = variables.map((variable) => variable.variableKey);
1936
- const resolvedVariables = useReadVariables(variableKeys);
1937
- let nextContent = content;
1938
- variables.forEach((variable, index) => {
2004
+ const { props: instanceProps } = react.useContext(InstanceContext);
2005
+ const [content] = useLayerValue(layerKey, "content", fragmentManager);
2006
+ const allVariableKeys = react.useMemo(
2007
+ () => collectNestedVariableKeys(content, instanceProps, fragmentManager),
2008
+ [content, instanceProps, fragmentManager]
2009
+ );
2010
+ const allResolved = useReadVariables(allVariableKeys);
2011
+ const resolvedMap = /* @__PURE__ */ new Map();
2012
+ allVariableKeys.forEach((key, index) => {
1939
2013
  var _a;
1940
- nextContent = nextContent.replace(
1941
- variable.fullMatch,
1942
- ((_a = resolvedVariables[index]) == null ? void 0 : _a.value) ?? ""
1943
- );
2014
+ resolvedMap.set(key, ((_a = allResolved[index]) == null ? void 0 : _a.value) ?? "");
1944
2015
  });
2016
+ let nextContent = resolveNestedContent(content, resolvedMap);
1945
2017
  if (typeof nextContent === "string") {
1946
2018
  nextContent = nextContent.replace(
1947
2019
  /\{\{(.*?)}}/,
@@ -2050,14 +2122,21 @@ const useLayerInteractions = (layerKey, options) => {
2050
2122
  });
2051
2123
  const fireEvent = react.useCallback(
2052
2124
  (eventLink) => {
2053
- var _a2, _b, _c, _d, _e, _f, _g;
2054
- const eventType = (_a2 = core.entityOfKey(eventLink)) == null ? void 0 : _a2._type;
2055
- const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
2056
- console.log(scopes, eventLink, eventType, eventValue);
2125
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2126
+ const isVariableGoal = typeof eventLink === "number";
2127
+ if (isVariableGoal) {
2128
+ if (!areaScope) return null;
2129
+ (_b = (_a2 = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _a2.reachGoal) == null ? void 0 : _b.call(_a2, {
2130
+ goalId: eventLink,
2131
+ ...utils.pick(areaScope, "variantId", "campaignId", "areaId")
2132
+ });
2133
+ return;
2134
+ }
2135
+ const eventType = (_c = core.entityOfKey(eventLink)) == null ? void 0 : _c._type;
2136
+ const eventValue = (_d = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _d.layer;
2057
2137
  if (eventType === definition.definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
2058
2138
  if (!areaScope) return null;
2059
- console.log((_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.reachGoal);
2060
- (_e = (_d = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _d.reachGoal) == null ? void 0 : _e.call(_d, {
2139
+ (_f = (_e = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _e.reachGoal) == null ? void 0 : _f.call(_e, {
2061
2140
  goalId: eventValue == null ? void 0 : eventValue.goalId,
2062
2141
  ...utils.pick(areaScope, "variantId", "campaignId", "areaId")
2063
2142
  });
@@ -2065,14 +2144,14 @@ const useLayerInteractions = (layerKey, options) => {
2065
2144
  if (eventType === definition.definition.nodes.MutateEvent) {
2066
2145
  const target = eventValue == null ? void 0 : eventValue.target;
2067
2146
  const targetLayer = getNormalizeLayer(target, fragmentManager);
2068
- const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_f = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _f.defaultValue);
2147
+ const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_g = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _g.defaultValue);
2069
2148
  if (definition.isVariableLink(target) && utils.isValue(value)) {
2070
- const targetId = (_g = core.entityOfKey(target)) == null ? void 0 : _g._id;
2149
+ const targetId = (_h = core.entityOfKey(target)) == null ? void 0 : _h._id;
2071
2150
  onChangeProps == null ? void 0 : onChangeProps(targetId, value);
2072
2151
  }
2073
2152
  }
2074
2153
  },
2075
- [globalManager, fragmentManager, areaScope]
2154
+ [globalManager, fragmentManager, areaScope, onChangeProps]
2076
2155
  );
2077
2156
  react.useEffect(() => {
2078
2157
  if (!pause && Array.isArray(interactions)) {
@@ -2264,7 +2343,12 @@ const useCollection = (layerKey, options) => {
2264
2343
  });
2265
2344
  const sourceValues = react$1.useGraphStack(fragmentManager, sourceValue ?? []);
2266
2345
  const resultValues = (sourceValue ?? []).map(
2267
- (initValue, index) => (sourceValues == null ? void 0 : sourceValues[index]) ?? initValue
2346
+ (initValue, index) => (
2347
+ // Если initValue — объект (пришёл из пропсов через useReadVariables),
2348
+ // он уже содержит актуальные значения и имеет приоритет.
2349
+ // Если initValue — ссылка (строка), используем graph-версию для реактивности.
2350
+ utils.isObject(initValue) ? initValue : (sourceValues == null ? void 0 : sourceValues[index]) ?? initValue
2351
+ )
2268
2352
  );
2269
2353
  return {
2270
2354
  source,
@@ -2383,6 +2467,25 @@ const remapArrayItems = (items, mapping) => {
2383
2467
  return remapped;
2384
2468
  });
2385
2469
  };
2470
+ const fillArrayItemDefaults = (items, parentDef, manager) => {
2471
+ if (!(parentDef == null ? void 0 : parentDef.fields)) return items;
2472
+ const fields = utils.cleanGraph(parentDef.fields);
2473
+ return items.map((item) => {
2474
+ const filled = { ...item };
2475
+ let changed = false;
2476
+ for (const [fieldName, fieldRef] of Object.entries(fields)) {
2477
+ const fieldVar = resolveFieldRef(fieldRef, manager);
2478
+ if (!fieldVar) continue;
2479
+ if (filled[fieldName] !== void 0) continue;
2480
+ if (fieldVar._id && filled[fieldVar._id] !== void 0) continue;
2481
+ if (fieldVar.defaultValue !== void 0) {
2482
+ filled[fieldName] = fieldVar.defaultValue;
2483
+ changed = true;
2484
+ }
2485
+ }
2486
+ return changed ? filled : item;
2487
+ });
2488
+ };
2386
2489
  const useExtractProps = (props, manager, parentManager, definitions) => {
2387
2490
  const areaManager = react.useContext(AreaManagerContext);
2388
2491
  const globalManager = react.useContext(GlobalManagerContext);
@@ -2506,13 +2609,18 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
2506
2609
  const childDef = resolveFieldRef(defVar.definition, manager);
2507
2610
  const parentDef = parentVarManager ? resolveFieldRef(parentVar.definition, parentVarManager) : utils.isObject(parentVar.definition) && ((_a = parentVar.definition) == null ? void 0 : _a._id) ? parentVar.definition : null;
2508
2611
  if ((childDef == null ? void 0 : childDef.type) === definition.definition.variableType.Object && (childDef == null ? void 0 : childDef.fields) && (parentDef == null ? void 0 : parentDef.type) === definition.definition.variableType.Object && (parentDef == null ? void 0 : parentDef.fields)) {
2612
+ const filledItems = fillArrayItemDefaults(
2613
+ concreteItems,
2614
+ parentDef,
2615
+ parentVarManager ?? resolveManager
2616
+ );
2509
2617
  const mapping = buildFieldIdMapping(
2510
2618
  childDef,
2511
2619
  parentDef,
2512
2620
  manager,
2513
2621
  parentVarManager ?? resolveManager
2514
2622
  );
2515
- expanded[defVar._id] = remapArrayItems(concreteItems, mapping);
2623
+ expanded[defVar._id] = remapArrayItems(filledItems, mapping);
2516
2624
  } else {
2517
2625
  expanded[defVar._id] = concreteItems;
2518
2626
  }
@@ -3007,7 +3115,7 @@ const useInstanceProps = (instanceProps) => {
3007
3115
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3008
3116
  const [localProps, setLocalProps] = react.useState(instanceProps.props ?? {});
3009
3117
  let inputProps = instanceLayerProps;
3010
- if (isTopInstance && utils.isObject(inputProps) && utils.isObject(localProps)) {
3118
+ if (utils.isObject(inputProps) && utils.isObject(localProps)) {
3011
3119
  inputProps = {
3012
3120
  ...inputProps,
3013
3121
  ...localProps
@@ -3059,7 +3167,7 @@ const useInstanceProps = (instanceProps) => {
3059
3167
  );
3060
3168
  continue;
3061
3169
  }
3062
- resolvedProps[key] = resolvedByKey[value] ?? value;
3170
+ resolvedProps[key] = value in resolvedByKey ? resolvedByKey[value] : value;
3063
3171
  }
3064
3172
  }
3065
3173
  react.useEffect(() => {
@@ -3387,6 +3495,24 @@ const useArea = (areaCode, options) => {
3387
3495
  }
3388
3496
  return asyncState;
3389
3497
  };
3498
+ class AreaErrorBoundary extends react.Component {
3499
+ constructor() {
3500
+ super(...arguments);
3501
+ __publicField(this, "state", { hasError: false });
3502
+ }
3503
+ static getDerivedStateFromError() {
3504
+ return { hasError: true };
3505
+ }
3506
+ componentDidCatch(error, info) {
3507
+ if (process.env.NODE_ENV !== "production") {
3508
+ console.error("[fragments] Area error:", error, info.componentStack);
3509
+ }
3510
+ }
3511
+ render() {
3512
+ if (this.state.hasError) return null;
3513
+ return this.props.children;
3514
+ }
3515
+ }
3390
3516
  const AreaInitial = (areaProps) => {
3391
3517
  var _a;
3392
3518
  const { data: areaData } = useArea(areaProps.areaCode, {
@@ -3401,10 +3527,13 @@ const AreaInitial = (areaProps) => {
3401
3527
  areaData == null ? void 0 : areaData.fragmentId,
3402
3528
  globalManager
3403
3529
  );
3404
- const resultProps = react.useMemo(
3405
- () => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(areaProps == null ? void 0 : areaProps.props) ?? {} }),
3406
- [areaData, areaProps]
3407
- );
3530
+ const resultProps = react.useMemo(() => {
3531
+ const baseProps = (areaData == null ? void 0 : areaData.props) ?? {};
3532
+ if (typeof (areaProps == null ? void 0 : areaProps.props) === "function") {
3533
+ return { ...baseProps, ...areaProps.props(baseProps) };
3534
+ }
3535
+ return { ...baseProps, ...(areaProps == null ? void 0 : areaProps.props) ?? {} };
3536
+ }, [areaData, areaProps]);
3408
3537
  const areaManager = react.useMemo(
3409
3538
  () => clientCore.createAreaManager({
3410
3539
  areaId: areaData == null ? void 0 : areaData.areaId,
@@ -3414,8 +3543,15 @@ const AreaInitial = (areaProps) => {
3414
3543
  }),
3415
3544
  [areaData == null ? void 0 : areaData.areaId]
3416
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
+ );
3417
3553
  if (!areaData) return null;
3418
- 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(
3419
3555
  Scope,
3420
3556
  {
3421
3557
  fragmentManager,
@@ -3427,10 +3563,10 @@ const AreaInitial = (areaProps) => {
3427
3563
  },
3428
3564
  children: /* @__PURE__ */ jsxRuntime.jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
3429
3565
  }
3430
- ) });
3566
+ ) }) });
3431
3567
  };
3432
3568
  const Area = (props) => {
3433
- return "globalManager" in props ? /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsxRuntime.jsx(AreaInitial, { ...props }) }) }) : /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(AreaInitial, { ...props }) });
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 }) }) });
3434
3570
  };
3435
3571
  function cssToJsStyle(cssKey) {
3436
3572
  return cssKey.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -3455,6 +3591,8 @@ const useLayerCssOverride = (layerKey) => {
3455
3591
  exports.Area = Area;
3456
3592
  exports.AreaManagerContext = AreaManagerContext;
3457
3593
  exports.AreaManagerProvider = AreaManagerProvider;
3594
+ exports.CampaignManagerContext = CampaignManagerContext;
3595
+ exports.CampaignManagerProvider = CampaignManagerProvider;
3458
3596
  exports.Collection = Collection;
3459
3597
  exports.CssChunk = CssChunk;
3460
3598
  exports.CustomRender = CustomRender;
package/dist/index.es.js CHANGED
@@ -1,10 +1,13 @@
1
- import { createContext, useContext, useMemo, useCallback, useEffect, useState, useRef, memo, Suspense } from "react";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { createContext, useContext, useMemo, useCallback, useEffect, useState, useRef, memo, Suspense, Component } from "react";
2
5
  import { definition, getNormalizeLayer as getNormalizeLayer$1, isVariableLink as isVariableLink$1, parseLayerField, isLink as isLink$1 } from "@fragmentsx/definition";
3
6
  import { jsx, jsxs } from "react/jsx-runtime";
4
7
  import { useGraph, useGraphStack } from "@graph-state/react";
5
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";
6
9
  import { keyOfEntity, isPartialKey, entityOfKey, isLinkKey } from "@graph-state/core";
7
- import { createAreaManager } from "@fragmentsx/client-core";
10
+ import { createAreaManager, createCampaignManager } from "@fragmentsx/client-core";
8
11
  const GlobalManagerContext = createContext(null);
9
12
  const GlobalManagerProvider = GlobalManagerContext.Provider;
10
13
  const FragmentContext = createContext({
@@ -26,6 +29,8 @@ const RenderTargetContext = createContext(
26
29
  const RenderTargetProvider = RenderTargetContext.Provider;
27
30
  const AreaManagerContext = createContext(null);
28
31
  const AreaManagerProvider = AreaManagerContext.Provider;
32
+ const CampaignManagerContext = createContext(null);
33
+ const CampaignManagerProvider = CampaignManagerContext.Provider;
29
34
  const ScopeContext = createContext([]);
30
35
  const Scope = ({
31
36
  value,
@@ -875,12 +880,13 @@ const extractVariableValue = (input, variableId) => {
875
880
  return void 0;
876
881
  };
877
882
  const useReadVariables = (variableKeys, customManager) => {
878
- var _a, _b, _c, _d;
883
+ var _a, _b, _c, _d, _e;
879
884
  const filterKeys = variableKeys.filter(isVariableLink$1);
880
885
  const { manager: fragmentManager } = useContext(FragmentContext);
881
886
  const { props: instanceProps } = useContext(InstanceContext);
882
887
  const globalManager = useContext(GlobalManagerContext);
883
888
  const areaManager = useContext(AreaManagerContext);
889
+ const campaignManager = useContext(CampaignManagerContext);
884
890
  const scopes = useContext(ScopeContext);
885
891
  const resultManager = customManager ?? ((_a = useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
886
892
  const safeFilterKeys = resultManager ? filterKeys : [];
@@ -893,6 +899,7 @@ const useReadVariables = (variableKeys, customManager) => {
893
899
  );
894
900
  useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
895
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);
896
903
  const globalPropertyKeys = useMemo(() => {
897
904
  if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
898
905
  return filterKeys.filter((key) => globalManager.resolve(key));
@@ -901,46 +908,58 @@ const useReadVariables = (variableKeys, customManager) => {
901
908
  if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
902
909
  return filterKeys.filter((key) => areaManager.resolve(key));
903
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]);
904
915
  useGraphStack(
905
916
  globalPropertyKeys.length ? globalManager : null,
906
917
  globalPropertyKeys
907
918
  );
908
919
  useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
909
- 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(
910
925
  scopes,
911
926
  (scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
912
927
  );
913
928
  return filterKeys.map((variableKey, index) => {
914
- var _a2;
915
- const layer = variableLayers[index] ?? null;
929
+ var _a2, _b2;
930
+ variableLayers[index];
931
+ const layer = ((_a2 = getNormalizeLayer(variableKey, resultManager)) == null ? void 0 : _a2.layer) ?? null;
916
932
  const { _id: propertyId } = layer ?? {};
917
933
  let collectionItemProp = void 0;
918
934
  if (lastCollectionItem && propertyId) {
919
- collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_a2 = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _a2._id) === propertyId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, propertyId);
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);
920
936
  }
921
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;
922
940
  const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
923
941
  const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
924
942
  const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
925
943
  const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
926
944
  const required = (layer == null ? void 0 : layer.required) ?? false;
927
945
  const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
928
- const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
946
+ const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? campaignProp ?? areaProp ?? globalProp ?? null;
929
947
  const resultValue = required ? currentValue : currentValue ?? defaultValue;
930
948
  if (isVariableLink$1(resultValue)) {
931
949
  const refKey = resultValue;
950
+ const refCampaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(refKey);
932
951
  const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
933
952
  const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
934
953
  const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
935
- 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;
936
955
  return {
937
956
  value: refValue,
938
- layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
957
+ layer: refCampaignLayer ?? refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
939
958
  };
940
959
  }
941
960
  return {
942
961
  value: resultValue,
943
- layer: layer ?? areaLayer ?? globalLayer ?? null
962
+ layer: layer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null
944
963
  };
945
964
  });
946
965
  };
@@ -973,9 +992,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
973
992
  const resolved = useReadVariables(variableKeys);
974
993
  if (!layer) return EMPTY_RESOLVED;
975
994
  const resolvedByKey = {};
995
+ const defaultByKey = {};
976
996
  variableKeys.forEach((key, i) => {
977
- var _a2;
997
+ var _a2, _b, _c;
978
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;
979
1000
  });
980
1001
  const values = {};
981
1002
  const cssVariableValues = {};
@@ -984,12 +1005,11 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
984
1005
  var _a2;
985
1006
  rawValues[fieldPath] = raw;
986
1007
  if (isVariableLink$1(value)) {
987
- const resolvedValue = resolvedByKey[value] ?? value;
1008
+ const resolvedValue = value in resolvedByKey ? resolvedByKey[value] : value;
988
1009
  values[fieldPath] = resolvedValue;
989
1010
  const variableId = (_a2 = entityOfKey(value)) == null ? void 0 : _a2._id;
990
- cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
991
- resolvedValue
992
- )})`;
1011
+ const staticDefault = defaultByKey[value];
1012
+ cssVariableValues[fieldPath] = staticDefault != null ? `var(--${variableId}, ${transformCssValue(staticDefault)})` : `var(--${variableId})`;
993
1013
  } else {
994
1014
  values[fieldPath] = value;
995
1015
  cssVariableValues[fieldPath] = transformCssValue(value);
@@ -1904,6 +1924,7 @@ const useLayerStyles = (layerKey) => {
1904
1924
  return {};
1905
1925
  }
1906
1926
  };
1927
+ const MAX_NESTING_DEPTH = 5;
1907
1928
  function extractVariablesFromHtml(html) {
1908
1929
  if (!html) return [];
1909
1930
  const regex = /<span(?=\s)(?=(?:[^>]*?\s)?class="[^"]*variable[^"]*")(?=(?:[^>]*?\s)?data-type="mention")(?=(?:[^>]*?\s)?data-id="([^"]+)")[^>]*>.*?<\/span>/gi;
@@ -1922,24 +1943,75 @@ function extractVariablesFromHtml(html) {
1922
1943
  }
1923
1944
  return mentions;
1924
1945
  }
1946
+ function collectNestedVariableKeys(content, instanceProps, fragmentManager, maxDepth = MAX_NESTING_DEPTH) {
1947
+ var _a, _b;
1948
+ const allKeys = [];
1949
+ const visited = /* @__PURE__ */ new Set();
1950
+ let currentContents = [content];
1951
+ for (let depth = 0; depth < maxDepth; depth++) {
1952
+ const nextContents = [];
1953
+ for (const html of currentContents) {
1954
+ const variables = extractVariablesFromHtml(html);
1955
+ for (const variable of variables) {
1956
+ const keyStr = variable.variableKey;
1957
+ if (visited.has(keyStr)) continue;
1958
+ visited.add(keyStr);
1959
+ allKeys.push(variable.variableKey);
1960
+ const propertyId = (_a = entityOfKey(variable.variableKey)) == null ? void 0 : _a._id;
1961
+ const value = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? ((_b = fragmentManager == null ? void 0 : fragmentManager.resolve(variable.variableKey)) == null ? void 0 : _b.defaultValue) ?? null;
1962
+ if (typeof value === "string") {
1963
+ nextContents.push(value);
1964
+ }
1965
+ }
1966
+ }
1967
+ if (nextContents.length === 0) break;
1968
+ currentContents = nextContents;
1969
+ }
1970
+ return allKeys;
1971
+ }
1972
+ function resolveNestedContent(content, resolvedMap, maxDepth = MAX_NESTING_DEPTH) {
1973
+ let result = content;
1974
+ const visited = /* @__PURE__ */ new Set();
1975
+ for (let depth = 0; depth < maxDepth; depth++) {
1976
+ const variables = extractVariablesFromHtml(result);
1977
+ if (variables.length === 0) break;
1978
+ let hasCycle = false;
1979
+ const depthKeys = /* @__PURE__ */ new Set();
1980
+ for (const variable of variables) {
1981
+ const key = variable.variableKey;
1982
+ if (visited.has(key)) {
1983
+ console.warn(`Circular variable reference detected: ${key}`);
1984
+ hasCycle = true;
1985
+ continue;
1986
+ }
1987
+ depthKeys.add(key);
1988
+ result = result.replace(
1989
+ variable.fullMatch,
1990
+ String(resolvedMap.get(key) ?? "")
1991
+ );
1992
+ }
1993
+ for (const key of depthKeys) {
1994
+ visited.add(key);
1995
+ }
1996
+ if (hasCycle) break;
1997
+ }
1998
+ return result;
1999
+ }
1925
2000
  const useTextContent = (layerKey, manager) => {
1926
2001
  const { manager: fragmentManager } = useContext(FragmentContext);
1927
- const [content, , contentInfo] = useLayerValue(
1928
- layerKey,
1929
- "content",
1930
- fragmentManager
1931
- );
1932
- const variables = extractVariablesFromHtml(content);
1933
- const variableKeys = variables.map((variable) => variable.variableKey);
1934
- const resolvedVariables = useReadVariables(variableKeys);
1935
- let nextContent = content;
1936
- variables.forEach((variable, index) => {
2002
+ const { props: instanceProps } = useContext(InstanceContext);
2003
+ const [content] = useLayerValue(layerKey, "content", fragmentManager);
2004
+ const allVariableKeys = useMemo(
2005
+ () => collectNestedVariableKeys(content, instanceProps, fragmentManager),
2006
+ [content, instanceProps, fragmentManager]
2007
+ );
2008
+ const allResolved = useReadVariables(allVariableKeys);
2009
+ const resolvedMap = /* @__PURE__ */ new Map();
2010
+ allVariableKeys.forEach((key, index) => {
1937
2011
  var _a;
1938
- nextContent = nextContent.replace(
1939
- variable.fullMatch,
1940
- ((_a = resolvedVariables[index]) == null ? void 0 : _a.value) ?? ""
1941
- );
2012
+ resolvedMap.set(key, ((_a = allResolved[index]) == null ? void 0 : _a.value) ?? "");
1942
2013
  });
2014
+ let nextContent = resolveNestedContent(content, resolvedMap);
1943
2015
  if (typeof nextContent === "string") {
1944
2016
  nextContent = nextContent.replace(
1945
2017
  /\{\{(.*?)}}/,
@@ -2048,14 +2120,21 @@ const useLayerInteractions = (layerKey, options) => {
2048
2120
  });
2049
2121
  const fireEvent = useCallback(
2050
2122
  (eventLink) => {
2051
- var _a2, _b, _c, _d, _e, _f, _g;
2052
- const eventType = (_a2 = entityOfKey(eventLink)) == null ? void 0 : _a2._type;
2053
- const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
2054
- console.log(scopes, eventLink, eventType, eventValue);
2123
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2124
+ const isVariableGoal = typeof eventLink === "number";
2125
+ if (isVariableGoal) {
2126
+ if (!areaScope) return null;
2127
+ (_b = (_a2 = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _a2.reachGoal) == null ? void 0 : _b.call(_a2, {
2128
+ goalId: eventLink,
2129
+ ...pick(areaScope, "variantId", "campaignId", "areaId")
2130
+ });
2131
+ return;
2132
+ }
2133
+ const eventType = (_c = entityOfKey(eventLink)) == null ? void 0 : _c._type;
2134
+ const eventValue = (_d = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _d.layer;
2055
2135
  if (eventType === definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
2056
2136
  if (!areaScope) return null;
2057
- console.log((_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.reachGoal);
2058
- (_e = (_d = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _d.reachGoal) == null ? void 0 : _e.call(_d, {
2137
+ (_f = (_e = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _e.reachGoal) == null ? void 0 : _f.call(_e, {
2059
2138
  goalId: eventValue == null ? void 0 : eventValue.goalId,
2060
2139
  ...pick(areaScope, "variantId", "campaignId", "areaId")
2061
2140
  });
@@ -2063,14 +2142,14 @@ const useLayerInteractions = (layerKey, options) => {
2063
2142
  if (eventType === definition.nodes.MutateEvent) {
2064
2143
  const target = eventValue == null ? void 0 : eventValue.target;
2065
2144
  const targetLayer = getNormalizeLayer(target, fragmentManager);
2066
- const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_f = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _f.defaultValue);
2145
+ const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_g = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _g.defaultValue);
2067
2146
  if (isVariableLink$1(target) && isValue(value)) {
2068
- const targetId = (_g = entityOfKey(target)) == null ? void 0 : _g._id;
2147
+ const targetId = (_h = entityOfKey(target)) == null ? void 0 : _h._id;
2069
2148
  onChangeProps == null ? void 0 : onChangeProps(targetId, value);
2070
2149
  }
2071
2150
  }
2072
2151
  },
2073
- [globalManager, fragmentManager, areaScope]
2152
+ [globalManager, fragmentManager, areaScope, onChangeProps]
2074
2153
  );
2075
2154
  useEffect(() => {
2076
2155
  if (!pause && Array.isArray(interactions)) {
@@ -2262,7 +2341,12 @@ const useCollection = (layerKey, options) => {
2262
2341
  });
2263
2342
  const sourceValues = useGraphStack(fragmentManager, sourceValue ?? []);
2264
2343
  const resultValues = (sourceValue ?? []).map(
2265
- (initValue, index) => (sourceValues == null ? void 0 : sourceValues[index]) ?? initValue
2344
+ (initValue, index) => (
2345
+ // Если initValue — объект (пришёл из пропсов через useReadVariables),
2346
+ // он уже содержит актуальные значения и имеет приоритет.
2347
+ // Если initValue — ссылка (строка), используем graph-версию для реактивности.
2348
+ isObject(initValue) ? initValue : (sourceValues == null ? void 0 : sourceValues[index]) ?? initValue
2349
+ )
2266
2350
  );
2267
2351
  return {
2268
2352
  source,
@@ -2381,6 +2465,25 @@ const remapArrayItems = (items, mapping) => {
2381
2465
  return remapped;
2382
2466
  });
2383
2467
  };
2468
+ const fillArrayItemDefaults = (items, parentDef, manager) => {
2469
+ if (!(parentDef == null ? void 0 : parentDef.fields)) return items;
2470
+ const fields = cleanGraph(parentDef.fields);
2471
+ return items.map((item) => {
2472
+ const filled = { ...item };
2473
+ let changed = false;
2474
+ for (const [fieldName, fieldRef] of Object.entries(fields)) {
2475
+ const fieldVar = resolveFieldRef(fieldRef, manager);
2476
+ if (!fieldVar) continue;
2477
+ if (filled[fieldName] !== void 0) continue;
2478
+ if (fieldVar._id && filled[fieldVar._id] !== void 0) continue;
2479
+ if (fieldVar.defaultValue !== void 0) {
2480
+ filled[fieldName] = fieldVar.defaultValue;
2481
+ changed = true;
2482
+ }
2483
+ }
2484
+ return changed ? filled : item;
2485
+ });
2486
+ };
2384
2487
  const useExtractProps = (props, manager, parentManager, definitions) => {
2385
2488
  const areaManager = useContext(AreaManagerContext);
2386
2489
  const globalManager = useContext(GlobalManagerContext);
@@ -2504,13 +2607,18 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
2504
2607
  const childDef = resolveFieldRef(defVar.definition, manager);
2505
2608
  const parentDef = parentVarManager ? resolveFieldRef(parentVar.definition, parentVarManager) : isObject(parentVar.definition) && ((_a = parentVar.definition) == null ? void 0 : _a._id) ? parentVar.definition : null;
2506
2609
  if ((childDef == null ? void 0 : childDef.type) === definition.variableType.Object && (childDef == null ? void 0 : childDef.fields) && (parentDef == null ? void 0 : parentDef.type) === definition.variableType.Object && (parentDef == null ? void 0 : parentDef.fields)) {
2610
+ const filledItems = fillArrayItemDefaults(
2611
+ concreteItems,
2612
+ parentDef,
2613
+ parentVarManager ?? resolveManager
2614
+ );
2507
2615
  const mapping = buildFieldIdMapping(
2508
2616
  childDef,
2509
2617
  parentDef,
2510
2618
  manager,
2511
2619
  parentVarManager ?? resolveManager
2512
2620
  );
2513
- expanded[defVar._id] = remapArrayItems(concreteItems, mapping);
2621
+ expanded[defVar._id] = remapArrayItems(filledItems, mapping);
2514
2622
  } else {
2515
2623
  expanded[defVar._id] = concreteItems;
2516
2624
  }
@@ -3005,7 +3113,7 @@ const useInstanceProps = (instanceProps) => {
3005
3113
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3006
3114
  const [localProps, setLocalProps] = useState(instanceProps.props ?? {});
3007
3115
  let inputProps = instanceLayerProps;
3008
- if (isTopInstance && isObject(inputProps) && isObject(localProps)) {
3116
+ if (isObject(inputProps) && isObject(localProps)) {
3009
3117
  inputProps = {
3010
3118
  ...inputProps,
3011
3119
  ...localProps
@@ -3057,7 +3165,7 @@ const useInstanceProps = (instanceProps) => {
3057
3165
  );
3058
3166
  continue;
3059
3167
  }
3060
- resolvedProps[key] = resolvedByKey[value] ?? value;
3168
+ resolvedProps[key] = value in resolvedByKey ? resolvedByKey[value] : value;
3061
3169
  }
3062
3170
  }
3063
3171
  useEffect(() => {
@@ -3385,6 +3493,24 @@ const useArea = (areaCode, options) => {
3385
3493
  }
3386
3494
  return asyncState;
3387
3495
  };
3496
+ class AreaErrorBoundary extends Component {
3497
+ constructor() {
3498
+ super(...arguments);
3499
+ __publicField(this, "state", { hasError: false });
3500
+ }
3501
+ static getDerivedStateFromError() {
3502
+ return { hasError: true };
3503
+ }
3504
+ componentDidCatch(error, info) {
3505
+ if (process.env.NODE_ENV !== "production") {
3506
+ console.error("[fragments] Area error:", error, info.componentStack);
3507
+ }
3508
+ }
3509
+ render() {
3510
+ if (this.state.hasError) return null;
3511
+ return this.props.children;
3512
+ }
3513
+ }
3388
3514
  const AreaInitial = (areaProps) => {
3389
3515
  var _a;
3390
3516
  const { data: areaData } = useArea(areaProps.areaCode, {
@@ -3399,10 +3525,13 @@ const AreaInitial = (areaProps) => {
3399
3525
  areaData == null ? void 0 : areaData.fragmentId,
3400
3526
  globalManager
3401
3527
  );
3402
- const resultProps = useMemo(
3403
- () => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(areaProps == null ? void 0 : areaProps.props) ?? {} }),
3404
- [areaData, areaProps]
3405
- );
3528
+ const resultProps = useMemo(() => {
3529
+ const baseProps = (areaData == null ? void 0 : areaData.props) ?? {};
3530
+ if (typeof (areaProps == null ? void 0 : areaProps.props) === "function") {
3531
+ return { ...baseProps, ...areaProps.props(baseProps) };
3532
+ }
3533
+ return { ...baseProps, ...(areaProps == null ? void 0 : areaProps.props) ?? {} };
3534
+ }, [areaData, areaProps]);
3406
3535
  const areaManager = useMemo(
3407
3536
  () => createAreaManager({
3408
3537
  areaId: areaData == null ? void 0 : areaData.areaId,
@@ -3412,8 +3541,15 @@ const AreaInitial = (areaProps) => {
3412
3541
  }),
3413
3542
  [areaData == null ? void 0 : areaData.areaId]
3414
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
+ );
3415
3551
  if (!areaData) return null;
3416
- 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(
3417
3553
  Scope,
3418
3554
  {
3419
3555
  fragmentManager,
@@ -3425,10 +3561,10 @@ const AreaInitial = (areaProps) => {
3425
3561
  },
3426
3562
  children: /* @__PURE__ */ jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
3427
3563
  }
3428
- ) });
3564
+ ) }) });
3429
3565
  };
3430
3566
  const Area = (props) => {
3431
- return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) }) : /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) });
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 }) }) });
3432
3568
  };
3433
3569
  function cssToJsStyle(cssKey) {
3434
3570
  return cssKey.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -3454,6 +3590,8 @@ export {
3454
3590
  Area,
3455
3591
  AreaManagerContext,
3456
3592
  AreaManagerProvider,
3593
+ CampaignManagerContext,
3594
+ CampaignManagerProvider,
3457
3595
  Collection,
3458
3596
  CssChunk,
3459
3597
  CustomRender,
@@ -1,7 +1,8 @@
1
+ export type AreaPropsFn = (variantProps: Record<string, unknown>) => Record<string, unknown>;
1
2
  export interface AreaProps {
2
3
  areaCode: string;
3
4
  globalManager?: unknown;
4
- props?: Record<string, unknown>;
5
+ props?: Record<string, unknown> | AreaPropsFn;
5
6
  options?: {
6
7
  ssr?: boolean;
7
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Area.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/Area.tsx"],"names":[],"mappings":"AAUA,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,CAAC;CACH;AAqDD,eAAO,MAAM,IAAI,UAAW,SAAS,4CAYpC,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Area.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Area.test.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/Area.test.tsx"],"names":[],"mappings":""}
@@ -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,5 +1,5 @@
1
1
  export { Area } from './Area';
2
- export type { AreaProps } from './Area';
2
+ export type { AreaProps, AreaPropsFn } from './Area';
3
3
  export { useArea } from './hooks/useArea';
4
4
  export type { UseAreaOptions, UseAreaResult, AreaData, } from './hooks/useArea.types';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EACV,cAAc,EACd,aAAa,EACb,QAAQ,GACT,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EACV,cAAc,EACd,aAAa,EACb,QAAQ,GACT,MAAM,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCollection.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Collection/hooks/useCollection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAY,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAKzE,eAAO,MAAM,aAAa,aAAc,OAAO,YAAY,eAAe;;;;;;;;;;;;;;;;;;;;;;CA2BzE,CAAC"}
1
+ {"version":3,"file":"useCollection.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Collection/hooks/useCollection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAY,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAKzE,eAAO,MAAM,aAAa,aAAc,OAAO,YAAY,eAAe;;;;;;;;;;;;;;;;;;;;;;CA8BzE,CAAC"}
@@ -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":""}
@@ -11,7 +11,7 @@ export declare const useTextAttributes: (layerKey: LinkKey, options?: UseTextAtt
11
11
  };
12
12
  styles: any;
13
13
  classnames: string | null;
14
- content: any;
14
+ content: string;
15
15
  highlight: {
16
16
  stylesString: string;
17
17
  };
@@ -1,3 +1,5 @@
1
1
  import { GraphState, LinkKey } from '@graph-state/core';
2
- export declare const useTextContent: (layerKey: LinkKey, manager: GraphState) => any;
2
+ export declare function collectNestedVariableKeys(content: string, instanceProps: Record<string, any>, fragmentManager: GraphState | null, maxDepth?: number): LinkKey[];
3
+ export declare function resolveNestedContent(content: string, resolvedMap: Map<string, any>, maxDepth?: number): string;
4
+ export declare const useTextContent: (layerKey: LinkKey, manager: GraphState) => string;
3
5
  //# sourceMappingURL=useTextContent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTextContent.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Text/hooks/useTextContent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAe,OAAO,EAAE,MAAM,mBAAmB,CAAC;AA+BrE,eAAO,MAAM,cAAc,aAAc,OAAO,WAAW,UAAU,QA4CpE,CAAC"}
1
+ {"version":3,"file":"useTextContent.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Text/hooks/useTextContent.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,UAAU,EAEV,OAAO,EACR,MAAM,mBAAmB,CAAC;AAgC3B,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClC,eAAe,EAAE,UAAU,GAAG,IAAI,EAClC,QAAQ,GAAE,MAA0B,GACnC,OAAO,EAAE,CAkCX;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,QAAQ,GAAE,MAA0B,GACnC,MAAM,CAmCR;AAED,eAAO,MAAM,cAAc,aAAc,OAAO,WAAW,UAAU,WA0BpE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useTextContent.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTextContent.test.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Text/hooks/useTextContent.test.ts"],"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.1",
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.3",
30
31
  "@fragmentsx/definition": "0.2.2",
31
- "@fragmentsx/utils": "0.2.0",
32
- "@fragmentsx/client-core": "0.4.2"
32
+ "@fragmentsx/utils": "0.2.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@testing-library/jest-dom": "^6.6.3",