@fragmentsx/render-react 1.2.2 → 1.2.4

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 (43) hide show
  1. package/dist/hooks/fragment/useFragmentCssChunks.d.ts.map +1 -1
  2. package/dist/hooks/layer/index.d.ts +1 -1
  3. package/dist/hooks/layer/index.d.ts.map +1 -1
  4. package/dist/hooks/layer/useLayerCssVariable.d.ts.map +1 -1
  5. package/dist/hooks/layer/useLayerValue.d.ts +2 -3
  6. package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
  7. package/dist/hooks/layer/useNormalizeLayer/index.d.ts.map +1 -1
  8. package/dist/hooks/layer/useReadVariable.d.ts +6 -2
  9. package/dist/hooks/layer/useReadVariable.d.ts.map +1 -1
  10. package/dist/hooks/layer-styles/useLayerPaint.d.ts +1 -0
  11. package/dist/hooks/layer-styles/useLayerPaint.d.ts.map +1 -1
  12. package/dist/hooks/render/index.d.ts +2 -0
  13. package/dist/hooks/render/index.d.ts.map +1 -0
  14. package/dist/hooks/utils/useLayerInteractions.d.ts.map +1 -1
  15. package/dist/index.cjs.js +263 -95
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.es.js +264 -96
  19. package/dist/nodes/Collection/Collection.d.ts.map +1 -1
  20. package/dist/nodes/Instance/Instance.d.ts +1 -0
  21. package/dist/nodes/Instance/Instance.d.ts.map +1 -1
  22. package/dist/nodes/Instance/hooks/useInstance.d.ts +1 -0
  23. package/dist/nodes/Instance/hooks/useInstance.d.ts.map +1 -1
  24. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts +2 -1
  25. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
  26. package/dist/nodes/Text/Text.d.ts.map +1 -1
  27. package/dist/nodes/Text/hooks/useTextAttributes.d.ts +9 -0
  28. package/dist/nodes/Text/hooks/useTextAttributes.d.ts.map +1 -1
  29. package/dist/nodes/Text/hooks/useTextContent.d.ts.map +1 -1
  30. package/dist/nodes/Text/hooks/useTextHighlight.d.ts +6 -0
  31. package/dist/nodes/Text/hooks/useTextHighlight.d.ts.map +1 -0
  32. package/dist/nodes/Text/index.d.ts +1 -0
  33. package/dist/nodes/Text/index.d.ts.map +1 -1
  34. package/dist/test/__examples__/Fragment.test.d.ts +6 -0
  35. package/dist/test/__examples__/Fragment.test.d.ts.map +1 -0
  36. package/dist/test/__examples__/useReadVariable.test.d.ts +6 -0
  37. package/dist/test/__examples__/useReadVariable.test.d.ts.map +1 -0
  38. package/dist/test/setupTests.d.ts +2 -0
  39. package/dist/test/setupTests.d.ts.map +1 -0
  40. package/dist/test/testUtils.d.ts +17 -0
  41. package/dist/test/testUtils.d.ts.map +1 -0
  42. package/dist/utils/layer/makeSnapshot.d.ts.map +1 -1
  43. package/package.json +2 -2
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createContext, useContext, useCallback, useMemo, useEffect, useState, useRef, Suspense } from "react";
2
2
  import { definition, getNormalizeLayer as getNormalizeLayer$1, isVariableLink as isVariableLink$1, parseLayerField } from "@fragmentsx/definition";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
- import { useGraph, useGraphStack } from "@graph-state/react";
4
+ import { useGraph, useGraphStack, GraphValue } from "@graph-state/react";
5
5
  import { noop, isPrimitive, isObject, generateId, getKey as getKey$1, isValue, pick, toPx, cleanGraph, flattenObject, setKey as setKey$1, toKebabCase, set, get, omit, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
6
6
  import { entityOfKey, keyOfEntity, isPartialKey, isLinkKey } from "@graph-state/core";
7
7
  const GlobalManagerContext = createContext(null);
@@ -90,6 +90,13 @@ const getNormalizeLayer = (layerKey, manager, options) => {
90
90
  const useNormalizeLayer = (layerKey, manager, options) => {
91
91
  const { manager: fragmentManager } = useContext(FragmentContext);
92
92
  const resultManager = manager ?? fragmentManager;
93
+ if (!resultManager) {
94
+ return {
95
+ layerKey,
96
+ rawLayer: null,
97
+ layer: null
98
+ };
99
+ }
93
100
  return getNormalizeLayer(layerKey, resultManager, options);
94
101
  };
95
102
  const useNormalizeLayers = (layerKeys, manager, options) => {
@@ -149,12 +156,12 @@ const useReadVariable = (variableKey, customScopes) => {
149
156
  );
150
157
  };
151
158
  const resolveVariableLayer = (manager, variableLink, customProps) => {
152
- var _a;
153
- const variableLayer = manager == null ? void 0 : manager.resolve(variableLink);
159
+ var _a, _b;
160
+ const variableLayer = (_a = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a.layer;
154
161
  if (!variableLayer) return null;
155
162
  if ((variableLayer == null ? void 0 : variableLayer.type) === definition.variableType.Array) {
156
163
  const definitionLayer = manager.resolve(variableLayer == null ? void 0 : variableLayer.definition);
157
- if (!((_a = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
164
+ if (!((_b = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _b.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
158
165
  return variableLayer;
159
166
  const definitionDefaultValue = extractVariableDefaultValue(
160
167
  manager,
@@ -462,14 +469,12 @@ function makeSnapshot(globalManager, targetFragmentId) {
462
469
  ).filter(Boolean);
463
470
  const linkedGoals = Array.from(
464
471
  new Set(
465
- targetFragment.inspectFields(definition.nodes.Variable).map(targetFragment == null ? void 0 : targetFragment.resolve).filter((graph) => {
466
- return (graph == null ? void 0 : graph.type) === definition.variableType.Event && (graph == null ? void 0 : graph.mode) === definition.eventMode.goal;
467
- }).map((graph) => {
472
+ targetFragment.inspectFields(definition.nodes.GoalEvent).map((link) => {
468
473
  var _a2;
469
- return (_a2 = graph == null ? void 0 : graph.defaultValue) == null ? void 0 : _a2.goalId;
470
- }).filter(Boolean).values()
474
+ return (_a2 = targetFragment == null ? void 0 : targetFragment.resolve(link)) == null ? void 0 : _a2.goalId;
475
+ }).values()
471
476
  )
472
- );
477
+ ).filter(Boolean);
473
478
  const fonts = Array.from(
474
479
  new Set(
475
480
  targetFragment.inspectFields(definition.nodes.Text).map((linkKey) => {
@@ -497,7 +502,8 @@ function makeSnapshot(globalManager, targetFragmentId) {
497
502
  };
498
503
  }
499
504
  const isInheritField = (manager, layerEntity, field) => {
500
- const layer = manager.resolve(layerEntity);
505
+ var _a;
506
+ const layer = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerEntity);
501
507
  if (layer) {
502
508
  const overrider = getOverrider(manager, layer);
503
509
  if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
@@ -969,13 +975,9 @@ const getLayerCssVariable = (manager, inputValue) => {
969
975
  const useLayerCssVariable = (inputValue) => {
970
976
  const { manager } = useContext(FragmentContext);
971
977
  const isVariable = isVariableLink$1(inputValue);
972
- const [variableValue] = useGraph(isVariable ? manager : null, inputValue, {
973
- selector: (graph) => pick(graph, "defaultValue", "_id")
974
- });
978
+ const { layer } = useNormalizeLayer(inputValue, isVariable ? manager : null);
975
979
  return {
976
- value: isVariable ? `var(--${variableValue == null ? void 0 : variableValue._id}, ${transformCssValue(
977
- variableValue == null ? void 0 : variableValue.defaultValue
978
- )})` : null
980
+ value: isVariable ? `var(--${layer == null ? void 0 : layer._id}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
979
981
  };
980
982
  };
981
983
  const useLayerValue = (layerKey, fieldKey, options) => {
@@ -1426,12 +1428,13 @@ const useLayerDisplay = (layerKey) => {
1426
1428
  };
1427
1429
  const useLayerPaint = (paintLinkKey) => {
1428
1430
  const [type] = useLayerValue(paintLinkKey, "type");
1429
- const [solid] = useLayerValue(paintLinkKey, "solid");
1431
+ const [solid, , solidInfo] = useLayerValue(paintLinkKey, "solid");
1430
1432
  const [image] = useLayerValue(paintLinkKey, "image");
1431
1433
  const [linearGradientLink] = useLayerValue(paintLinkKey, "linearGradient");
1432
1434
  return {
1433
1435
  type,
1434
1436
  solid,
1437
+ solidCssValue: solidInfo.cssVariableValue,
1435
1438
  image,
1436
1439
  linearGradientLink
1437
1440
  };
@@ -1471,7 +1474,7 @@ const useLayerBorder = (layerKey) => {
1471
1474
  };
1472
1475
  }
1473
1476
  if (borderPaint.type === definition.paintMode.Solid) {
1474
- return calcBorderSides(type, width, borderPaint.solid);
1477
+ return calcBorderSides(type, width, borderPaint.solidCssValue);
1475
1478
  }
1476
1479
  return { border: null };
1477
1480
  };
@@ -1627,6 +1630,10 @@ const useTextContent = (layerKey, manager) => {
1627
1630
  readVariable(variable.variableKey).value ?? ""
1628
1631
  );
1629
1632
  });
1633
+ nextContent = nextContent.replace(
1634
+ /\{\{(.*?)}}/,
1635
+ `<mark class="highlight">$1</mark>`
1636
+ );
1630
1637
  return nextContent;
1631
1638
  };
1632
1639
  const useHash = (layerKey, manager) => {
@@ -1682,36 +1689,6 @@ const useStyleSheet = (manager) => {
1682
1689
  unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? noop
1683
1690
  };
1684
1691
  };
1685
- const useTextAttributes = (layerKey, options) => {
1686
- const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1687
- const { manager: fragmentManager } = useContext(FragmentContext);
1688
- const styles = useLayerStyles(layerKey);
1689
- const content = useTextContent(layerKey);
1690
- const classnames = useClassnames(layerKey, fragmentManager);
1691
- const { addLayerStyle } = useStyleSheet(fragmentManager);
1692
- if (collectStyle) {
1693
- addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
1694
- }
1695
- return {
1696
- styles,
1697
- classnames,
1698
- content
1699
- };
1700
- };
1701
- const Text = ({
1702
- layerKey,
1703
- Tag = "div",
1704
- collectStyle,
1705
- ...restProps
1706
- }) => {
1707
- const { classnames, content } = useTextAttributes(layerKey, { collectStyle });
1708
- return /* @__PURE__ */ jsx(Tag, { className: classnames, "data-key": layerKey, ...restProps, children: /* @__PURE__ */ jsx(
1709
- "div",
1710
- {
1711
- dangerouslySetInnerHTML: { __html: content }
1712
- }
1713
- ) });
1714
- };
1715
1692
  const useLayerInteractions = (layerKey, options) => {
1716
1693
  const pause = (options == null ? void 0 : options.pauseInteractions) ?? false;
1717
1694
  const { manager: globalManager } = useGlobalManager();
@@ -1720,29 +1697,40 @@ const useLayerInteractions = (layerKey, options) => {
1720
1697
  const areaScope = scopes.find(
1721
1698
  (scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.AreaScope
1722
1699
  );
1723
- const [interactions] = useLayerValue(
1724
- layerKey,
1725
- "interactions",
1726
- fragmentManager
1700
+ const instanceScope = scopes.find(
1701
+ (scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
1727
1702
  );
1728
- const { readVariable } = useReadVariable();
1703
+ const [interactionLinks] = useLayerValue(layerKey, "interactions");
1704
+ const interactionOns = useLayersValue(interactionLinks, "on");
1705
+ const interactionEvents = useLayersValue(interactionLinks, "event");
1706
+ const interactions = (interactionLinks ?? []).map((linkKey, index) => {
1707
+ var _a, _b;
1708
+ return {
1709
+ linkKey,
1710
+ on: (_a = interactionOns == null ? void 0 : interactionOns.at(index)) == null ? void 0 : _a.at(0),
1711
+ event: (_b = interactionEvents == null ? void 0 : interactionEvents.at(index)) == null ? void 0 : _b.at(0)
1712
+ };
1713
+ });
1729
1714
  const fireEvent = useCallback(
1730
1715
  (eventLink) => {
1731
- var _a, _b, _c, _d;
1732
- if (!areaScope) return null;
1733
- const event = fragmentManager.resolve(eventLink);
1734
- const { value: eventValue } = readVariable(eventLink);
1735
- if ((event == null ? void 0 : event.mode) === definition.eventMode.goal && (eventValue == null ? void 0 : eventValue.goalId)) {
1736
- (_b = (_a = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _a.reachGoal) == null ? void 0 : _b.call(_a, {
1716
+ var _a, _b, _c, _d, _e, _f, _g;
1717
+ const eventType = (_a = entityOfKey(eventLink)) == null ? void 0 : _a._type;
1718
+ const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
1719
+ if (eventType === definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
1720
+ if (!areaScope) return null;
1721
+ (_d = (_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.reachGoal) == null ? void 0 : _d.call(_c, {
1737
1722
  goalId: eventValue == null ? void 0 : eventValue.goalId,
1738
1723
  ...pick(areaScope, "variantId", "campaignId", "areaId")
1739
1724
  });
1740
1725
  }
1741
- if ((event == null ? void 0 : event.mode) === definition.eventMode.tracker && eventValue) {
1742
- (_d = (_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.trackAdPixel) == null ? void 0 : _d.call(_c, eventValue);
1743
- }
1744
- if ((event == null ? void 0 : event.mode) === definition.eventMode.callback && typeof eventValue === "function") {
1745
- eventValue();
1726
+ if (eventType === definition.nodes.MutateEvent) {
1727
+ const target = eventValue == null ? void 0 : eventValue.target;
1728
+ const targetLayer = getNormalizeLayer(target, fragmentManager);
1729
+ const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_e = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _e.defaultValue);
1730
+ if (isVariableLink$1(target) && isValue(value)) {
1731
+ const targetId = (_f = entityOfKey(target)) == null ? void 0 : _f._id;
1732
+ (_g = instanceScope == null ? void 0 : instanceScope.onChangeProps) == null ? void 0 : _g.call(instanceScope, targetId, value);
1733
+ }
1746
1734
  }
1747
1735
  },
1748
1736
  [globalManager, fragmentManager, areaScope]
@@ -1763,6 +1751,142 @@ const useLayerInteractions = (layerKey, options) => {
1763
1751
  };
1764
1752
  }, [interactions, fireEvent, pause]);
1765
1753
  };
1754
+ const useTextHighlight = (layerKey, options) => {
1755
+ const [highlightLayerKey] = useLayerValue(layerKey, "highlight", options);
1756
+ const [, , { cssVariableValue: fontSize }] = useLayerValue(
1757
+ highlightLayerKey,
1758
+ "fontSize",
1759
+ options
1760
+ );
1761
+ const [, , { cssVariableValue: color }] = useLayerValue(
1762
+ highlightLayerKey,
1763
+ "color",
1764
+ options
1765
+ );
1766
+ const [, , { cssVariableValue: fontWeight }] = useLayerValue(
1767
+ highlightLayerKey,
1768
+ "fontWeight",
1769
+ options
1770
+ );
1771
+ const [, , { cssVariableValue: textAlign }] = useLayerValue(
1772
+ highlightLayerKey,
1773
+ "textAlign",
1774
+ options
1775
+ );
1776
+ const [, , { cssVariableValue: textDecoration }] = useLayerValue(
1777
+ highlightLayerKey,
1778
+ "textDecoration",
1779
+ options
1780
+ );
1781
+ const [, , { cssVariableValue: textTransform }] = useLayerValue(
1782
+ highlightLayerKey,
1783
+ "textTransform",
1784
+ options
1785
+ );
1786
+ const [, , { cssVariableValue: lineHeight }] = useLayerValue(
1787
+ highlightLayerKey,
1788
+ "lineHeight",
1789
+ options
1790
+ );
1791
+ const [, , { cssVariableValue: letterSpacing }] = useLayerValue(
1792
+ highlightLayerKey,
1793
+ "letterSpacing",
1794
+ options
1795
+ );
1796
+ const [, , { cssVariableValue: fontFamily }] = useLayerValue(
1797
+ highlightLayerKey,
1798
+ "fontFamily",
1799
+ options
1800
+ );
1801
+ const styles = {
1802
+ background: "inherit",
1803
+ color: "inherit"
1804
+ };
1805
+ if (!!fontSize) {
1806
+ styles["font-size"] = toPx(fontSize);
1807
+ }
1808
+ if (!!color) {
1809
+ styles["color"] = color;
1810
+ }
1811
+ if (!!fontWeight) {
1812
+ styles["font-weight"] = fontWeight;
1813
+ }
1814
+ if (!!textAlign) {
1815
+ styles["text-align"] = textAlign;
1816
+ }
1817
+ if (!!textDecoration) {
1818
+ styles["text-decoration"] = textDecoration;
1819
+ }
1820
+ if (!!textTransform) {
1821
+ styles["text-transform"] = textTransform;
1822
+ }
1823
+ if (!!lineHeight) {
1824
+ styles["line-height"] = lineHeight;
1825
+ }
1826
+ if (!!letterSpacing) {
1827
+ styles["letter-spacing"] = toPx(letterSpacing);
1828
+ }
1829
+ if (!!fontFamily) {
1830
+ styles["font-family"] = fontFamily;
1831
+ }
1832
+ return {
1833
+ stylesString: Object.entries(styles).reduce(
1834
+ (acc, [key, value]) => acc += `${key}: ${value};`,
1835
+ ""
1836
+ )
1837
+ };
1838
+ };
1839
+ const useTextAttributes = (layerKey, options) => {
1840
+ const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1841
+ const { manager: fragmentManager } = useContext(FragmentContext);
1842
+ const styles = useLayerStyles(layerKey);
1843
+ const highlight = useTextHighlight(layerKey);
1844
+ const content = useTextContent(layerKey);
1845
+ const classnames = useClassnames(layerKey, fragmentManager);
1846
+ const hash = useHash(layerKey, fragmentManager);
1847
+ const { addLayerStyle } = useStyleSheet(fragmentManager);
1848
+ const events = useLayerInteractions(layerKey, options);
1849
+ if (collectStyle) {
1850
+ addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
1851
+ }
1852
+ return {
1853
+ hash,
1854
+ events,
1855
+ styles,
1856
+ classnames,
1857
+ content,
1858
+ highlight
1859
+ };
1860
+ };
1861
+ const Text = ({
1862
+ layerKey,
1863
+ Tag = "div",
1864
+ collectStyle,
1865
+ ...restProps
1866
+ }) => {
1867
+ const { classnames, content, events, hash, highlight } = useTextAttributes(
1868
+ layerKey,
1869
+ {
1870
+ collectStyle
1871
+ }
1872
+ );
1873
+ return /* @__PURE__ */ jsxs(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: [
1874
+ /* @__PURE__ */ jsx(
1875
+ "style",
1876
+ {
1877
+ dangerouslySetInnerHTML: {
1878
+ __html: `.${hash} .highlight {${highlight.stylesString}}`
1879
+ }
1880
+ }
1881
+ ),
1882
+ /* @__PURE__ */ jsx(
1883
+ "div",
1884
+ {
1885
+ dangerouslySetInnerHTML: { __html: content }
1886
+ }
1887
+ )
1888
+ ] });
1889
+ };
1766
1890
  const useFrame = (layerKey, options) => {
1767
1891
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1768
1892
  const { manager: fragmentManager } = useContext(FragmentContext);
@@ -1842,29 +1966,36 @@ const Collection = ({
1842
1966
  "data-key": layerKey,
1843
1967
  style: resultStyles,
1844
1968
  ...restProps,
1845
- children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItem, index) => /* @__PURE__ */ jsx(
1846
- Scope,
1969
+ children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItemLinkKey) => /* @__PURE__ */ jsx(
1970
+ GraphValue,
1847
1971
  {
1848
- fragmentManager,
1849
- layerKey: `${layerKey}.${index}`,
1850
- value: {
1851
- type: definition.scopeTypes.CollectionItemScope,
1852
- source,
1853
- sourceDefinition,
1854
- value: collectionItem,
1855
- manager: fragmentManager
1856
- },
1857
- children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
1858
- "div",
1972
+ graphState: fragmentManager,
1973
+ field: collectionItemLinkKey,
1974
+ children: (value) => /* @__PURE__ */ jsx(
1975
+ Scope,
1859
1976
  {
1860
- style: {
1861
- display: "contents",
1862
- ...getCssVariables(collectionItem ?? {})
1977
+ fragmentManager,
1978
+ layerKey: collectionItemLinkKey,
1979
+ value: {
1980
+ type: definition.scopeTypes.CollectionItemScope,
1981
+ source,
1982
+ sourceDefinition,
1983
+ value,
1984
+ manager: fragmentManager
1863
1985
  },
1864
- children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
1865
- },
1866
- child
1867
- ))
1986
+ children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
1987
+ "div",
1988
+ {
1989
+ style: {
1990
+ display: "contents",
1991
+ ...getCssVariables(value ?? {})
1992
+ },
1993
+ children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
1994
+ },
1995
+ child
1996
+ ))
1997
+ }
1998
+ )
1868
1999
  }
1869
2000
  ))
1870
2001
  }
@@ -2135,30 +2266,61 @@ const useInstanceProps = (instanceProps) => {
2135
2266
  );
2136
2267
  const { manager: fragmentContextManager } = useContext(FragmentContext);
2137
2268
  const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
2138
- const definitionsData = useGraphStack(innerFragmentManager, definitions);
2269
+ const { readVariable } = useReadVariable();
2139
2270
  const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
2271
+ const flatDefinition = useMemo(() => {
2272
+ const acc = [];
2273
+ const run = (defLink) => {
2274
+ const resolvedDefinition = fragmentManager.resolve(defLink);
2275
+ if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.variableType.Object) {
2276
+ Object.values(resolvedDefinition.fields).forEach(run);
2277
+ } else if (isVariableLink$1(defLink)) {
2278
+ acc.push(defLink);
2279
+ }
2280
+ };
2281
+ definitions.forEach(run);
2282
+ return acc;
2283
+ }, [definitions]);
2284
+ const definitionsData = useGraphStack(innerFragmentManager, flatDefinition);
2140
2285
  const [instanceLayer] = useGraph(fragmentManager, instanceProps.layerKey);
2141
2286
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
2287
+ const [localProps, setLocalProps] = useState(instanceProps.props ?? {});
2142
2288
  const mergedProps = useMemo(() => {
2143
2289
  let base = instanceLayerProps;
2144
- if (isTopInstance && isObject(base) && isObject(instanceProps == null ? void 0 : instanceProps.props)) {
2290
+ if (isTopInstance && isObject(base) && isObject(localProps)) {
2145
2291
  base = {
2146
2292
  ...base,
2147
- ...instanceProps == null ? void 0 : instanceProps.props
2293
+ ...localProps
2148
2294
  };
2149
2295
  }
2150
2296
  if (isTopInstance && fragmentManager) {
2151
2297
  definitionsData.forEach((definition2) => {
2152
- var _a;
2153
2298
  const defId = definition2._id;
2154
- base[defId] = ((_a = instanceProps == null ? void 0 : instanceProps.props) == null ? void 0 : _a[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
2299
+ base[defId] = (localProps == null ? void 0 : localProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
2155
2300
  });
2156
2301
  }
2157
2302
  return omit(base, "_type", "_id");
2158
- }, [isTopInstance, fragmentManager, instanceLayerProps, definitionsData]);
2303
+ }, [
2304
+ isTopInstance,
2305
+ fragmentManager,
2306
+ instanceLayerProps,
2307
+ definitionsData,
2308
+ localProps,
2309
+ readVariable
2310
+ ]);
2311
+ useEffect(() => {
2312
+ if (isValue(instanceProps == null ? void 0 : instanceProps.props)) {
2313
+ setLocalProps(instanceProps.props);
2314
+ }
2315
+ }, [instanceProps == null ? void 0 : instanceProps.props]);
2159
2316
  return {
2160
2317
  props: mergedProps,
2161
- cssProps: getCssVariables(mergedProps)
2318
+ cssProps: getCssVariables(mergedProps),
2319
+ onChangeProps: (variableId, value) => {
2320
+ var _a;
2321
+ setLocalProps((prev) => ({ ...prev, [variableId]: value }));
2322
+ (_a = instanceProps == null ? void 0 : instanceProps.onChangeProps) == null ? void 0 : _a.call(instanceProps, variableId, value);
2323
+ }
2162
2324
  };
2163
2325
  };
2164
2326
  const useInstance = (instanceProps) => {
@@ -2171,7 +2333,7 @@ const useInstance = (instanceProps) => {
2171
2333
  );
2172
2334
  const resultFragmentId = (instanceProps == null ? void 0 : instanceProps.fragmentId) ?? (instanceLayer == null ? void 0 : instanceLayer.fragment);
2173
2335
  const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(resultFragmentId);
2174
- const { props, cssProps } = useInstanceProps(instanceProps);
2336
+ const { props, cssProps, onChangeProps } = useInstanceProps(instanceProps);
2175
2337
  const classnames = useClassnames(
2176
2338
  instanceProps.layerKey,
2177
2339
  innerFragmentManager
@@ -2186,7 +2348,8 @@ const useInstance = (instanceProps) => {
2186
2348
  parentManager,
2187
2349
  innerManager: innerFragmentManager,
2188
2350
  fragmentId: resultFragmentId,
2189
- globalManager: resultGlobalManager
2351
+ globalManager: resultGlobalManager,
2352
+ onChangeProps
2190
2353
  };
2191
2354
  };
2192
2355
  const InstanceInitial = ({
@@ -2209,7 +2372,8 @@ const InstanceInitial = ({
2209
2372
  classnames,
2210
2373
  innerManager,
2211
2374
  definitions,
2212
- globalManager
2375
+ globalManager,
2376
+ onChangeProps
2213
2377
  } = useInstance({
2214
2378
  ...instanceProps,
2215
2379
  pauseInteractions
@@ -2228,7 +2392,8 @@ const InstanceInitial = ({
2228
2392
  definitions,
2229
2393
  fragmentId,
2230
2394
  documentManager: innerManager,
2231
- layerKey: instanceProps.layerKey
2395
+ layerKey: instanceProps.layerKey,
2396
+ onChangeProps
2232
2397
  },
2233
2398
  children: /* @__PURE__ */ jsx(
2234
2399
  InstanceContext$1.Provider,
@@ -2398,6 +2563,7 @@ export {
2398
2563
  getCssVariables,
2399
2564
  getHydratedData,
2400
2565
  getKey,
2566
+ getNormalizeLayer,
2401
2567
  getOverrider,
2402
2568
  getOverriderByLayers,
2403
2569
  getParent,
@@ -2456,7 +2622,9 @@ export {
2456
2622
  useOptionalSize,
2457
2623
  useReadVariable,
2458
2624
  useReadVariables,
2625
+ useRenderTarget,
2459
2626
  useTextAttributes,
2460
2627
  useTextContent,
2628
+ useTextHighlight,
2461
2629
  wrapTextInParagraphWithAttributes
2462
2630
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../src/nodes/Collection/Collection.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAS,UAAU,EAAE,MAAM,eAAe,CAAC;AAIlD,UAAU,eAAgB,SAAQ,UAAU;CAAG;AAE/C,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CA+D1C,CAAC"}
1
+ {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../src/nodes/Collection/Collection.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAS,UAAU,EAAE,MAAM,eAAe,CAAC;AAKlD,UAAU,eAAgB,SAAQ,UAAU;CAAG;AAE/C,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAwE1C,CAAC"}
@@ -14,6 +14,7 @@ export interface InstanceProps extends ComponentPropsWithoutRef<"div"> {
14
14
  options?: InstanceOptions;
15
15
  globalManager?: unknown;
16
16
  Tag?: string | ElementType;
17
+ onChangeProps?: (variableId: string, value: unknown) => void;
17
18
  }
18
19
  export declare const Instance: (props: any) => import("react/jsx-runtime").JSX.Element;
19
20
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Instance.d.ts","sourceRoot":"","sources":["../../../src/nodes/Instance/Instance.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAgB,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAS5C,UAAU,eAAe;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,aAAc,SAAQ,wBAAwB,CAAC,KAAK,CAAC;IACpE,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,OAAO,UAAU,CAAC,YAAY,CAAC;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAC5B;AAoFD,eAAO,MAAM,QAAQ,yDAoBpB,CAAC"}
1
+ {"version":3,"file":"Instance.d.ts","sourceRoot":"","sources":["../../../src/nodes/Instance/Instance.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,WAAW,EAKZ,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAS5C,UAAU,eAAe;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,aAAc,SAAQ,wBAAwB,CAAC,KAAK,CAAC;IACpE,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,OAAO,UAAU,CAAC,YAAY,CAAC;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9D;AAsFD,eAAO,MAAM,QAAQ,yDAoBpB,CAAC"}
@@ -15,6 +15,7 @@ export declare const useInstance: (instanceProps: UseInstanceOptions) => {
15
15
  innerManager: any;
16
16
  fragmentId: any;
17
17
  globalManager: import('@graph-state/core').GraphState<import('@graph-state/core').SystemFields, string> | null;
18
+ onChangeProps: (variableId: string, value: unknown) => void;
18
19
  };
19
20
  export {};
20
21
  //# sourceMappingURL=useInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInstance.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstance.ts"],"names":[],"mappings":"AAUA,UAAU,kBAAmB,SAAQ,2BAA2B;CAAG;AAEnE,eAAO,MAAM,WAAW,kBAAmB,kBAAkB;;;;;;;;;;;;;;;CAyC5D,CAAC"}
1
+ {"version":3,"file":"useInstance.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstance.ts"],"names":[],"mappings":"AAUA,UAAU,kBAAmB,SAAQ,2BAA2B;CAAG;AAEnE,eAAO,MAAM,WAAW,kBAAmB,kBAAkB;;;;;;;;;;;;;;;;CA0C5D,CAAC"}
@@ -1,6 +1,7 @@
1
- import { InstanceProps } from '../index';
1
+ import { InstanceProps } from '../Instance';
2
2
  export declare const useInstanceProps: (instanceProps: InstanceProps) => {
3
3
  props: Omit<any, "_type" | "_id">;
4
4
  cssProps: {};
5
+ onChangeProps: (variableId: string, value: unknown) => void;
5
6
  };
6
7
  //# sourceMappingURL=useInstanceProps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInstanceProps.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstanceProps.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAiBzC,eAAO,MAAM,gBAAgB,kBAAmB,aAAa;;;CAsE5D,CAAC"}
1
+ {"version":3,"file":"useInstanceProps.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstanceProps.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAgB1D,eAAO,MAAM,gBAAgB,kBAAmB,aAAa;;;gCA4E7B,MAAM,SAAS,OAAO;CAKrD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../src/nodes/Text/Text.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAIlE,UAAU,SAAU,SAAQ,wBAAwB,CAAC,KAAK,CAAC,EAAE,iBAAiB;IAC5E,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAgB9B,CAAC"}
1
+ {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../src/nodes/Text/Text.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAIlE,UAAU,SAAU,SAAQ,wBAAwB,CAAC,KAAK,CAAC,EAAE,iBAAiB;IAC5E,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CA0B9B,CAAC"}
@@ -3,8 +3,17 @@ export interface UseTextAttributes {
3
3
  collectStyle?: boolean;
4
4
  }
5
5
  export declare const useTextAttributes: (layerKey: LinkKey, options?: UseTextAttributes) => {
6
+ hash: string | null;
7
+ events: {
8
+ onClick?: undefined;
9
+ } | {
10
+ onClick: () => void;
11
+ };
6
12
  styles: {};
7
13
  classnames: string | null;
8
14
  content: any;
15
+ highlight: {
16
+ stylesString: string;
17
+ };
9
18
  };
10
19
  //# sourceMappingURL=useTextAttributes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTextAttributes.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Text/hooks/useTextAttributes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,iBAAiB,aAClB,OAAO,YACP,iBAAiB;;;;CAmB5B,CAAC"}
1
+ {"version":3,"file":"useTextAttributes.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Text/hooks/useTextAttributes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAU5C,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,iBAAiB,aAClB,OAAO,YACP,iBAAiB;;;;;;;;;;;;;CAyB5B,CAAC"}
@@ -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;AAiCrE,eAAO,MAAM,cAAc,aAAc,OAAO,WAAW,UAAU,QAwCpE,CAAC"}
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;AAiCrE,eAAO,MAAM,cAAc,aAAc,OAAO,WAAW,UAAU,QA6CpE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { LinkKey } from '@graph-state/core';
2
+ import { UseLayerValueOptions } from '../../../hooks/layer/useLayerValue';
3
+ export declare const useTextHighlight: (layerKey: LinkKey, options?: UseLayerValueOptions) => {
4
+ stylesString: string;
5
+ };
6
+ //# sourceMappingURL=useTextHighlight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTextHighlight.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Text/hooks/useTextHighlight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,eAAO,MAAM,gBAAgB,aACjB,OAAO,YACP,oBAAoB;;CAwF/B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export { Text } from './Text';
2
2
  export { useTextAttributes } from './hooks/useTextAttributes';
3
3
  export { useTextContent } from './hooks/useTextContent';
4
+ export { useTextHighlight } from './hooks/useTextHighlight';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nodes/Text/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nodes/Text/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Пример теста для компонента Fragment
3
+ * Этот файл можно удалить после создания реальных тестов
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=Fragment.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Fragment.test.d.ts","sourceRoot":"","sources":["../../../src/test/__examples__/Fragment.test.tsx"],"names":[],"mappings":"AAAA;;;GAGG"}