@fragmentsx/render-react 1.2.3 → 1.2.5

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 (77) hide show
  1. package/dist/hooks/layer/useExtractProps.d.ts +9 -0
  2. package/dist/hooks/layer/useExtractProps.d.ts.map +1 -0
  3. package/dist/hooks/layer/useLayerCssVariable.d.ts.map +1 -1
  4. package/dist/hooks/layer/useLayerValue.d.ts +2 -3
  5. package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
  6. package/dist/hooks/layer/useReadVariable.d.ts.map +1 -1
  7. package/dist/hooks/layer-styles/useLayerStyles/index.d.ts.map +1 -1
  8. package/dist/hooks/layer-styles/useLayerStyles/useLayerLayout.d.ts +1 -1
  9. package/dist/hooks/layer-styles/useLayerStyles/useLayerLayout.d.ts.map +1 -1
  10. package/dist/hooks/utils/useForceUpdate.d.ts +2 -0
  11. package/dist/hooks/utils/useForceUpdate.d.ts.map +1 -0
  12. package/dist/index.cjs.js +277 -91
  13. package/dist/index.es.js +278 -92
  14. package/dist/nodes/Area/test/area-project-props.browser.test.d.ts +2 -0
  15. package/dist/nodes/Area/test/area-project-props.browser.test.d.ts.map +1 -0
  16. package/dist/nodes/Collection/Collection.d.ts.map +1 -1
  17. package/dist/nodes/Collection/hooks/useCollection.d.ts.map +1 -1
  18. package/dist/nodes/CollectionItem/CollectionItem.d.ts +7 -0
  19. package/dist/nodes/CollectionItem/CollectionItem.d.ts.map +1 -0
  20. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts +26 -0
  21. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts.map +1 -0
  22. package/dist/nodes/CollectionItem/index.d.ts +3 -0
  23. package/dist/nodes/CollectionItem/index.d.ts.map +1 -0
  24. package/dist/nodes/Frame/Frame.d.ts +1 -0
  25. package/dist/nodes/Frame/Frame.d.ts.map +1 -1
  26. package/dist/nodes/Frame/hooks/useFrame.d.ts +1 -0
  27. package/dist/nodes/Frame/hooks/useFrame.d.ts.map +1 -1
  28. package/dist/nodes/Instance/hooks/useInstance.d.ts +1 -1
  29. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts +1 -1
  30. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
  31. package/dist/nodes/Instance/test/basic.test.d.ts +2 -0
  32. package/dist/nodes/Instance/test/basic.test.d.ts.map +1 -0
  33. package/dist/nodes/Instance/test/collection.browser.test.d.ts +2 -0
  34. package/dist/nodes/Instance/test/collection.browser.test.d.ts.map +1 -0
  35. package/dist/nodes/Instance/test/constraints.browser.test.d.ts +2 -0
  36. package/dist/nodes/Instance/test/constraints.browser.test.d.ts.map +1 -0
  37. package/dist/nodes/Instance/test/css-chunks.browser.test.d.ts +2 -0
  38. package/dist/nodes/Instance/test/css-chunks.browser.test.d.ts.map +1 -0
  39. package/dist/nodes/Instance/test/fragmentDocuments.d.ts +19 -0
  40. package/dist/nodes/Instance/test/fragmentDocuments.d.ts.map +1 -0
  41. package/dist/nodes/Instance/test/layout.browser.test.d.ts +2 -0
  42. package/dist/nodes/Instance/test/layout.browser.test.d.ts.map +1 -0
  43. package/dist/nodes/Instance/test/modified.browser.test.d.ts +2 -0
  44. package/dist/nodes/Instance/test/modified.browser.test.d.ts.map +1 -0
  45. package/dist/nodes/Instance/test/modified.test.d.ts +2 -0
  46. package/dist/nodes/Instance/test/modified.test.d.ts.map +1 -0
  47. package/dist/nodes/Instance/test/nested-instance.browser.test.d.ts +2 -0
  48. package/dist/nodes/Instance/test/nested-instance.browser.test.d.ts.map +1 -0
  49. package/dist/nodes/Instance/test/nested-instance.test.d.ts +2 -0
  50. package/dist/nodes/Instance/test/nested-instance.test.d.ts.map +1 -0
  51. package/dist/nodes/Instance/test/paint.browser.test.d.ts +2 -0
  52. package/dist/nodes/Instance/test/paint.browser.test.d.ts.map +1 -0
  53. package/dist/nodes/Instance/test/resize.browser.test.d.ts +2 -0
  54. package/dist/nodes/Instance/test/resize.browser.test.d.ts.map +1 -0
  55. package/dist/nodes/Instance/test/sizing.browser.test.d.ts +2 -0
  56. package/dist/nodes/Instance/test/sizing.browser.test.d.ts.map +1 -0
  57. package/dist/nodes/Instance/test/standalone-props.browser.test.d.ts +2 -0
  58. package/dist/nodes/Instance/test/standalone-props.browser.test.d.ts.map +1 -0
  59. package/dist/nodes/Instance/test/structure.test.d.ts +2 -0
  60. package/dist/nodes/Instance/test/structure.test.d.ts.map +1 -0
  61. package/dist/nodes/Instance/test/styles.browser.test.d.ts +2 -0
  62. package/dist/nodes/Instance/test/styles.browser.test.d.ts.map +1 -0
  63. package/dist/nodes/Instance/test/text.browser.test.d.ts +2 -0
  64. package/dist/nodes/Instance/test/text.browser.test.d.ts.map +1 -0
  65. package/dist/nodes/Instance/test/text.test.d.ts +2 -0
  66. package/dist/nodes/Instance/test/text.test.d.ts.map +1 -0
  67. package/dist/nodes/Text/Text.d.ts.map +1 -1
  68. package/dist/nodes/Text/hooks/useTextAttributes.d.ts +4 -0
  69. package/dist/nodes/Text/hooks/useTextAttributes.d.ts.map +1 -1
  70. package/dist/nodes/Text/hooks/useTextContent.d.ts.map +1 -1
  71. package/dist/nodes/Text/hooks/useTextHighlight.d.ts +6 -0
  72. package/dist/nodes/Text/hooks/useTextHighlight.d.ts.map +1 -0
  73. package/dist/nodes/Text/index.d.ts +1 -0
  74. package/dist/nodes/Text/index.d.ts.map +1 -1
  75. package/dist/test/setupTests.d.ts +1 -0
  76. package/dist/test/setupTests.d.ts.map +1 -0
  77. package/package.json +20 -8
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useCallback, useMemo, useEffect, useState, useRef, Suspense } from "react";
1
+ import { createContext, useContext, useReducer, useRef, useEffect, useCallback, useMemo, useState, 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
4
  import { useGraph, useGraphStack } from "@graph-state/react";
@@ -106,6 +106,9 @@ const useNormalizeLayers = (layerKeys, manager, options) => {
106
106
  (layerKey) => getNormalizeLayer(layerKey, resultManager, options)
107
107
  );
108
108
  };
109
+ function useForceUpdate() {
110
+ return useReducer(() => ({}), {});
111
+ }
109
112
  const extractVariableValue = (input, variableId) => {
110
113
  if (isObject(input)) {
111
114
  if (variableId in input) {
@@ -137,6 +140,15 @@ function deepMerge(a, b) {
137
140
  const useReadVariable = (variableKey, customScopes) => {
138
141
  const contextScopes = useContext(ScopeContext);
139
142
  const scopes = customScopes ?? contextScopes;
143
+ const unmountAbortController = useRef(new AbortController());
144
+ const [dep, forceUpdate] = useForceUpdate();
145
+ useEffect(
146
+ () => () => {
147
+ var _a;
148
+ (_a = unmountAbortController.current) == null ? void 0 : _a.abort("unmount");
149
+ },
150
+ []
151
+ );
140
152
  const extractVariableDefaultValue = (manager, variableEntity) => {
141
153
  const variableLayer = manager.resolve(variableEntity);
142
154
  if ((variableLayer == null ? void 0 : variableLayer.type) !== definition.variableType.Object)
@@ -182,7 +194,7 @@ const useReadVariable = (variableKey, customScopes) => {
182
194
  return variableLayer;
183
195
  };
184
196
  const readVariable = (variableKey2) => {
185
- var _a, _b, _c;
197
+ var _a, _b, _c, _d, _e;
186
198
  const variableId = (_a = entityOfKey(variableKey2)) == null ? void 0 : _a._id;
187
199
  if (!isVariableLink$1(variableKey2)) {
188
200
  return {
@@ -205,7 +217,10 @@ const useReadVariable = (variableKey, customScopes) => {
205
217
  instanceScope == null ? void 0 : instanceScope.documentManager,
206
218
  variableKey2
207
219
  );
208
- let instanceProp = (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId];
220
+ (_c = instanceScope == null ? void 0 : instanceScope.documentManager) == null ? void 0 : _c.subscribe(variableKey2, forceUpdate, {
221
+ signal: (_b = unmountAbortController.current) == null ? void 0 : _b.signal
222
+ });
223
+ let instanceProp = (_d = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _d[variableId];
209
224
  if (Array.isArray(instanceProp)) {
210
225
  instanceProp = instanceProp.map(
211
226
  (rawProp, index) => {
@@ -222,7 +237,7 @@ const useReadVariable = (variableKey, customScopes) => {
222
237
  lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
223
238
  lastCollectionItem == null ? void 0 : lastCollectionItem.value
224
239
  );
225
- const collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_c = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _c._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
240
+ const collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_e = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _e._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
226
241
  const currentValue = variableKey2 === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
227
242
  const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
228
243
  const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
@@ -502,7 +517,8 @@ function makeSnapshot(globalManager, targetFragmentId) {
502
517
  };
503
518
  }
504
519
  const isInheritField = (manager, layerEntity, field) => {
505
- const layer = manager.resolve(layerEntity);
520
+ var _a;
521
+ const layer = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerEntity);
506
522
  if (layer) {
507
523
  const overrider = getOverrider(manager, layer);
508
524
  if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
@@ -972,11 +988,13 @@ const getLayerCssVariable = (manager, inputValue) => {
972
988
  };
973
989
  };
974
990
  const useLayerCssVariable = (inputValue) => {
991
+ var _a;
975
992
  const { manager } = useContext(FragmentContext);
976
993
  const isVariable = isVariableLink$1(inputValue);
977
994
  const { layer } = useNormalizeLayer(inputValue, isVariable ? manager : null);
995
+ const variableId = (layer == null ? void 0 : layer._id) ?? ((_a = entityOfKey(inputValue)) == null ? void 0 : _a._id);
978
996
  return {
979
- value: isVariable ? `var(--${layer == null ? void 0 : layer._id}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
997
+ value: isVariable ? `var(--${variableId}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
980
998
  };
981
999
  };
982
1000
  const useLayerValue = (layerKey, fieldKey, options) => {
@@ -1355,10 +1373,10 @@ const useLayerLinearGradient = (linearGradientLink) => {
1355
1373
  const stopsPosition = useLayersValue(stops, "position");
1356
1374
  const stopValues = useMemo(
1357
1375
  () => (stops == null ? void 0 : stops.flatMap((stop, index) => {
1358
- var _a, _b;
1376
+ var _a, _b, _c;
1359
1377
  return [
1360
- (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(0),
1361
- (_b = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _b.at(0)
1378
+ (_b = (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(2)) == null ? void 0 : _b.cssVariableValue,
1379
+ (_c = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _c.at(0)
1362
1380
  ];
1363
1381
  })) ?? [],
1364
1382
  [stops, stopsValue, stopsPosition]
@@ -1458,7 +1476,7 @@ const useLayerBorder = (layerKey) => {
1458
1476
  if (borderPaint.type === definition.paintMode.LinearGradient) {
1459
1477
  let background = `linear-gradient(${paint.solid}, ${paint.solid}) padding-box, ${borderLinearGradient} border-box`;
1460
1478
  if (paint.type === definition.paintMode.LinearGradient) {
1461
- background = `${linearGradient} padding-box, ${borderLinearGradient} border-box`;
1479
+ background = `${linearGradient["background-image"]} padding-box, ${borderLinearGradient["background-image"]} border-box`;
1462
1480
  }
1463
1481
  if (paint.type === definition.paintMode.None) {
1464
1482
  background = `linear-gradient(transparent, transparent) padding-box, ${borderLinearGradient} border-box`;
@@ -1499,25 +1517,18 @@ const useLayerLayout = (layerKey) => {
1499
1517
  const [padding] = useLayerValue(layerKey, "padding", fragmentManager);
1500
1518
  const [gap] = useLayerValue(layerKey, "layerGap", fragmentManager);
1501
1519
  const isFlex = layerModeValue === definition.layerMode.flex;
1502
- return useMemo(
1503
- () => ({
1504
- display: isFlex ? "flex" : null,
1505
- gap: toPx(gap),
1506
- flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
1507
- justifyContent: isFlex ? layerDistribute : null,
1508
- flexFlow: isFlex ? layerDirectionValue === definition.layerDirection.vertical ? "column" : "row" : null,
1509
- alignItems: isFlex ? layerAlign : null,
1510
- padding: isFlex ? padding : null
1511
- }),
1512
- [
1513
- isFlex,
1514
- layerWrap,
1515
- layerDistribute,
1516
- layerDirectionValue,
1517
- layerAlign,
1518
- padding
1519
- ]
1520
- );
1520
+ const baseFlow = layerDirectionValue === definition.layerDirection.vertical ? "column" : "row";
1521
+ const wrap = isFlex ? layerWrap ? "wrap" : null : null;
1522
+ const flexFlow = [baseFlow, wrap].filter(Boolean).join(" ");
1523
+ return {
1524
+ display: isFlex ? "flex" : null,
1525
+ gap: toPx(gap),
1526
+ flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
1527
+ justifyContent: isFlex ? layerDistribute : null,
1528
+ flexFlow,
1529
+ alignItems: isFlex ? layerAlign : null,
1530
+ padding: isFlex ? padding : null
1531
+ };
1521
1532
  };
1522
1533
  const useLayerTextStyles = (layerKey) => {
1523
1534
  const { manager: fragmentManager } = useContext(FragmentContext);
@@ -1560,7 +1571,7 @@ const useLayerStyles = (layerKey) => {
1560
1571
  const layout = useLayerLayout(layerKey);
1561
1572
  const [zIndex] = useLayerValue(layerKey, "zIndex", fragmentManager);
1562
1573
  const [rotate] = useLayerValue(layerKey, "rotate", fragmentManager);
1563
- const [borderRadius] = useLayerValue(
1574
+ const [borderRadius, , { rawValue: rawBorderRadius }] = useLayerValue(
1564
1575
  layerKey,
1565
1576
  "borderRadius",
1566
1577
  fragmentManager
@@ -1570,13 +1581,13 @@ const useLayerStyles = (layerKey) => {
1570
1581
  const [overflow] = useLayerValue(layerKey, "overflow", fragmentManager);
1571
1582
  return {
1572
1583
  // ...(props ?? {}),
1573
- ...border,
1574
1584
  ...background,
1585
+ ...border,
1575
1586
  ...position,
1576
1587
  opacity,
1577
1588
  overflow,
1578
1589
  rotate: isValue(rotate) ? `${rotate}deg` : null,
1579
- "border-radius": borderRadius,
1590
+ "border-radius": isValue(rawBorderRadius) ? borderRadius : null,
1580
1591
  "white-space": whiteSpace,
1581
1592
  "z-index": zIndex !== -1 ? zIndex : null,
1582
1593
  ...layout,
@@ -1629,6 +1640,12 @@ const useTextContent = (layerKey, manager) => {
1629
1640
  readVariable(variable.variableKey).value ?? ""
1630
1641
  );
1631
1642
  });
1643
+ if (typeof nextContent === "string") {
1644
+ nextContent = nextContent.replace(
1645
+ /\{\{(.*?)}}/,
1646
+ `<mark class="highlight">$1</mark>`
1647
+ );
1648
+ }
1632
1649
  return nextContent;
1633
1650
  };
1634
1651
  const useHash = (layerKey, manager) => {
@@ -1746,22 +1763,111 @@ const useLayerInteractions = (layerKey, options) => {
1746
1763
  };
1747
1764
  }, [interactions, fireEvent, pause]);
1748
1765
  };
1766
+ const useTextHighlight = (layerKey, options) => {
1767
+ const [highlightLayerKey] = useLayerValue(layerKey, "highlight", options);
1768
+ const [, , { cssVariableValue: fontSize }] = useLayerValue(
1769
+ highlightLayerKey,
1770
+ "fontSize",
1771
+ options
1772
+ );
1773
+ const [, , { cssVariableValue: color }] = useLayerValue(
1774
+ highlightLayerKey,
1775
+ "color",
1776
+ options
1777
+ );
1778
+ const [, , { cssVariableValue: fontWeight }] = useLayerValue(
1779
+ highlightLayerKey,
1780
+ "fontWeight",
1781
+ options
1782
+ );
1783
+ const [, , { cssVariableValue: textAlign }] = useLayerValue(
1784
+ highlightLayerKey,
1785
+ "textAlign",
1786
+ options
1787
+ );
1788
+ const [, , { cssVariableValue: textDecoration }] = useLayerValue(
1789
+ highlightLayerKey,
1790
+ "textDecoration",
1791
+ options
1792
+ );
1793
+ const [, , { cssVariableValue: textTransform }] = useLayerValue(
1794
+ highlightLayerKey,
1795
+ "textTransform",
1796
+ options
1797
+ );
1798
+ const [, , { cssVariableValue: lineHeight }] = useLayerValue(
1799
+ highlightLayerKey,
1800
+ "lineHeight",
1801
+ options
1802
+ );
1803
+ const [, , { cssVariableValue: letterSpacing }] = useLayerValue(
1804
+ highlightLayerKey,
1805
+ "letterSpacing",
1806
+ options
1807
+ );
1808
+ const [, , { cssVariableValue: fontFamily }] = useLayerValue(
1809
+ highlightLayerKey,
1810
+ "fontFamily",
1811
+ options
1812
+ );
1813
+ const styles = {
1814
+ background: "inherit",
1815
+ color: "inherit"
1816
+ };
1817
+ if (!!fontSize) {
1818
+ styles["font-size"] = toPx(fontSize);
1819
+ }
1820
+ if (!!color) {
1821
+ styles["color"] = color;
1822
+ }
1823
+ if (!!fontWeight) {
1824
+ styles["font-weight"] = fontWeight;
1825
+ }
1826
+ if (!!textAlign) {
1827
+ styles["text-align"] = textAlign;
1828
+ }
1829
+ if (!!textDecoration) {
1830
+ styles["text-decoration"] = textDecoration;
1831
+ }
1832
+ if (!!textTransform) {
1833
+ styles["text-transform"] = textTransform;
1834
+ }
1835
+ if (!!lineHeight) {
1836
+ styles["line-height"] = lineHeight;
1837
+ }
1838
+ if (!!letterSpacing) {
1839
+ styles["letter-spacing"] = toPx(letterSpacing);
1840
+ }
1841
+ if (!!fontFamily) {
1842
+ styles["font-family"] = `${fontFamily} !important`;
1843
+ }
1844
+ return {
1845
+ stylesString: Object.entries(styles).reduce(
1846
+ (acc, [key, value]) => acc += `${key}: ${value};`,
1847
+ ""
1848
+ )
1849
+ };
1850
+ };
1749
1851
  const useTextAttributes = (layerKey, options) => {
1750
1852
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1751
1853
  const { manager: fragmentManager } = useContext(FragmentContext);
1752
1854
  const styles = useLayerStyles(layerKey);
1855
+ const highlight = useTextHighlight(layerKey);
1753
1856
  const content = useTextContent(layerKey);
1754
1857
  const classnames = useClassnames(layerKey, fragmentManager);
1858
+ const hash = useHash(layerKey, fragmentManager);
1755
1859
  const { addLayerStyle } = useStyleSheet(fragmentManager);
1756
1860
  const events = useLayerInteractions(layerKey, options);
1757
1861
  if (collectStyle) {
1758
1862
  addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
1759
1863
  }
1760
1864
  return {
1865
+ hash,
1761
1866
  events,
1762
1867
  styles,
1763
1868
  classnames,
1764
- content
1869
+ content,
1870
+ highlight
1765
1871
  };
1766
1872
  };
1767
1873
  const Text = ({
@@ -1770,15 +1876,28 @@ const Text = ({
1770
1876
  collectStyle,
1771
1877
  ...restProps
1772
1878
  }) => {
1773
- const { classnames, content, events } = useTextAttributes(layerKey, {
1774
- collectStyle
1775
- });
1776
- return /* @__PURE__ */ jsx(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: /* @__PURE__ */ jsx(
1777
- "div",
1879
+ const { classnames, content, events, hash, highlight } = useTextAttributes(
1880
+ layerKey,
1778
1881
  {
1779
- dangerouslySetInnerHTML: { __html: content }
1882
+ collectStyle
1780
1883
  }
1781
- ) });
1884
+ );
1885
+ return /* @__PURE__ */ jsxs(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: [
1886
+ /* @__PURE__ */ jsx(
1887
+ "style",
1888
+ {
1889
+ dangerouslySetInnerHTML: {
1890
+ __html: `.${hash} .highlight {${highlight.stylesString}}`
1891
+ }
1892
+ }
1893
+ ),
1894
+ /* @__PURE__ */ jsx(
1895
+ "div",
1896
+ {
1897
+ dangerouslySetInnerHTML: { __html: content }
1898
+ }
1899
+ )
1900
+ ] });
1782
1901
  };
1783
1902
  const useFrame = (layerKey, options) => {
1784
1903
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
@@ -1797,8 +1916,7 @@ const useFrame = (layerKey, options) => {
1797
1916
  Tag: (link == null ? void 0 : link.isLink) ? (options == null ? void 0 : options.FrameTag) ?? "a" : (options == null ? void 0 : options.FrameTag) ?? "div",
1798
1917
  type: layer == null ? void 0 : layer._type,
1799
1918
  classnames,
1800
- styles: {},
1801
- //isBrowser ? pick(styles, "background") : {},
1919
+ styles,
1802
1920
  children,
1803
1921
  events,
1804
1922
  linkProps: link.linkProps
@@ -1814,16 +1932,106 @@ const useCollection = (layerKey, options) => {
1814
1932
  });
1815
1933
  const source = collectionLayer == null ? void 0 : collectionLayer.source;
1816
1934
  const sourceDefinition = (_a = fragmentManager == null ? void 0 : fragmentManager.resolve(source)) == null ? void 0 : _a.definition;
1817
- const [sourceValue] = useLayerValue(layerKey, "source", fragmentManager);
1935
+ const [sourceValue] = useLayerValue(layerKey, "source", {
1936
+ manager: fragmentManager
1937
+ });
1938
+ const sourceValues = useGraphStack(fragmentManager, sourceValue ?? []);
1939
+ const resultValues = (sourceValue ?? []).map(
1940
+ (initValue, index) => (sourceValues == null ? void 0 : sourceValues[index]) ?? initValue
1941
+ );
1818
1942
  return {
1819
1943
  source,
1820
1944
  sourceDefinition,
1821
- sourceValue: sourceValue ?? [],
1945
+ sourceValue: resultValues ?? [],
1822
1946
  fragmentManager,
1823
1947
  children,
1824
1948
  ...frame
1825
1949
  };
1826
1950
  };
1951
+ const useExtractProps = ({
1952
+ layerKey,
1953
+ definitions,
1954
+ manager,
1955
+ inputProps
1956
+ }) => {
1957
+ const flatDefinition = useMemo(() => {
1958
+ const acc = [];
1959
+ const run = (defLink) => {
1960
+ var _a;
1961
+ const resolvedDefinition = (_a = getNormalizeLayer(defLink, manager)) == null ? void 0 : _a.layer;
1962
+ if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.variableType.Array) return;
1963
+ if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.variableType.Object) {
1964
+ Object.values(cleanGraph(resolvedDefinition == null ? void 0 : resolvedDefinition.fields)).forEach(run);
1965
+ } else if (isVariableLink$1(defLink)) {
1966
+ acc.push(defLink);
1967
+ }
1968
+ };
1969
+ definitions.forEach(run);
1970
+ return acc;
1971
+ }, [definitions]);
1972
+ const definitionsData = useGraphStack(manager, flatDefinition);
1973
+ const definitionProps = useMemo(
1974
+ () => definitionsData.reduce((acc, definition2) => {
1975
+ const defId = definition2._id;
1976
+ acc[defId] = (inputProps == null ? void 0 : inputProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
1977
+ return acc;
1978
+ }, {}),
1979
+ [inputProps]
1980
+ );
1981
+ return cleanGraph({
1982
+ ...inputProps,
1983
+ ...definitionProps
1984
+ });
1985
+ };
1986
+ const CollectionItem = ({
1987
+ layer,
1988
+ manager,
1989
+ FrameElement,
1990
+ children,
1991
+ sourceDefinition,
1992
+ ...restProps
1993
+ }) => {
1994
+ var _a;
1995
+ const layerKey = keyOfEntity(layer);
1996
+ const definitionId = ((_a = entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
1997
+ const value = layer.value ?? layer;
1998
+ const props = useExtractProps({
1999
+ layerKey,
2000
+ definitions: [sourceDefinition],
2001
+ inputProps: isObject(value) ? {
2002
+ // [definitionId]: layer.value,
2003
+ ...value
2004
+ } : {
2005
+ [definitionId]: value
2006
+ },
2007
+ manager
2008
+ });
2009
+ return /* @__PURE__ */ jsx(
2010
+ Scope,
2011
+ {
2012
+ fragmentManager: manager,
2013
+ layerKey: keyOfEntity(layer),
2014
+ value: {
2015
+ type: definition.scopeTypes.CollectionItemScope,
2016
+ ...restProps,
2017
+ sourceDefinition,
2018
+ value: props,
2019
+ manager
2020
+ },
2021
+ children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
2022
+ "div",
2023
+ {
2024
+ style: {
2025
+ display: "contents",
2026
+ ...getCssVariables(props ?? {})
2027
+ },
2028
+ children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
2029
+ },
2030
+ child
2031
+ ))
2032
+ }
2033
+ );
2034
+ };
1827
2035
  const Collection = ({
1828
2036
  layerKey,
1829
2037
  styles: inputStyles,
@@ -1859,30 +2067,17 @@ const Collection = ({
1859
2067
  "data-key": layerKey,
1860
2068
  style: resultStyles,
1861
2069
  ...restProps,
1862
- children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItem, index) => /* @__PURE__ */ jsx(
1863
- Scope,
2070
+ children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (itemValue, index) => /* @__PURE__ */ jsx(
2071
+ CollectionItem,
1864
2072
  {
1865
- fragmentManager,
1866
- layerKey: `${layerKey}.${index}`,
1867
- value: {
1868
- type: definition.scopeTypes.CollectionItemScope,
1869
- source,
1870
- sourceDefinition,
1871
- value: collectionItem,
1872
- manager: fragmentManager
1873
- },
1874
- children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
1875
- "div",
1876
- {
1877
- style: {
1878
- display: "contents",
1879
- ...getCssVariables(collectionItem ?? {})
1880
- },
1881
- children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
1882
- },
1883
- child
1884
- ))
1885
- }
2073
+ layer: itemValue,
2074
+ manager: fragmentManager,
2075
+ source,
2076
+ children,
2077
+ sourceDefinition,
2078
+ FrameElement
2079
+ },
2080
+ index
1886
2081
  ))
1887
2082
  }
1888
2083
  )
@@ -2152,41 +2347,31 @@ const useInstanceProps = (instanceProps) => {
2152
2347
  );
2153
2348
  const { manager: fragmentContextManager } = useContext(FragmentContext);
2154
2349
  const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
2155
- const definitionsData = useGraphStack(innerFragmentManager, definitions);
2350
+ const { readVariable } = useReadVariable();
2156
2351
  const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
2157
2352
  const [instanceLayer] = useGraph(fragmentManager, instanceProps.layerKey);
2158
2353
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
2159
2354
  const [localProps, setLocalProps] = useState(instanceProps.props ?? {});
2160
- const mergedProps = useMemo(() => {
2161
- let base = instanceLayerProps;
2162
- if (isTopInstance && isObject(base) && isObject(localProps)) {
2163
- base = {
2164
- ...base,
2165
- ...localProps
2166
- };
2167
- }
2168
- if (isTopInstance && fragmentManager) {
2169
- definitionsData.forEach((definition2) => {
2170
- const defId = definition2._id;
2171
- base[defId] = (localProps == null ? void 0 : localProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
2172
- });
2173
- }
2174
- return omit(base, "_type", "_id");
2175
- }, [
2176
- isTopInstance,
2177
- fragmentManager,
2178
- instanceLayerProps,
2179
- definitionsData,
2180
- localProps
2181
- ]);
2355
+ let inputProps = instanceLayerProps;
2356
+ if (isTopInstance && isObject(inputProps) && isObject(localProps)) {
2357
+ inputProps = {
2358
+ ...inputProps,
2359
+ ...localProps
2360
+ };
2361
+ }
2362
+ const extractProps = useExtractProps({
2363
+ definitions,
2364
+ manager: fragmentManager,
2365
+ inputProps
2366
+ });
2182
2367
  useEffect(() => {
2183
2368
  if (isValue(instanceProps == null ? void 0 : instanceProps.props)) {
2184
2369
  setLocalProps(instanceProps.props);
2185
2370
  }
2186
2371
  }, [instanceProps == null ? void 0 : instanceProps.props]);
2187
2372
  return {
2188
- props: mergedProps,
2189
- cssProps: getCssVariables(mergedProps),
2373
+ props: extractProps,
2374
+ cssProps: getCssVariables(extractProps),
2190
2375
  onChangeProps: (variableId, value) => {
2191
2376
  var _a;
2192
2377
  setLocalProps((prev) => ({ ...prev, [variableId]: value }));
@@ -2496,5 +2681,6 @@ export {
2496
2681
  useRenderTarget,
2497
2682
  useTextAttributes,
2498
2683
  useTextContent,
2684
+ useTextHighlight,
2499
2685
  wrapTextInParagraphWithAttributes
2500
2686
  };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=area-project-props.browser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"area-project-props.browser.test.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Area/test/area-project-props.browser.test.tsx"],"names":[],"mappings":""}
@@ -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;AAOlD,UAAU,eAAgB,SAAQ,UAAU;CAAG;AAE/C,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,CAiD1C,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;;;;;;;;;;;;;;;;;;;;;;CAqBzE,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;;;;;;;;;;;;;;;;;;;;;;CA4BzE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { FC } from 'react';
2
+ import { FrameProps } from '../Frame';
3
+ interface CollectionProps extends FrameProps {
4
+ }
5
+ export declare const CollectionItem: FC<CollectionProps>;
6
+ export {};
7
+ //# sourceMappingURL=CollectionItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CollectionItem.d.ts","sourceRoot":"","sources":["../../../src/nodes/CollectionItem/CollectionItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAS,UAAU,EAAE,MAAM,eAAe,CAAC;AASlD,UAAU,eAAgB,SAAQ,UAAU;CAAG;AAE/C,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,eAAe,CAmD9C,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { LinkKey } from '@graph-state/core';
2
+ import { UseFrameOptions } from '../../Frame/hooks/useFrame';
3
+ export declare const useCollection: (layerKey: LinkKey, options?: UseFrameOptions) => {
4
+ Tag: string | import('react').ComponentClass<any, any> | import('react').FunctionComponent<any>;
5
+ type: any;
6
+ classnames: string | null;
7
+ styles: {};
8
+ children: any;
9
+ events: {
10
+ onClick?: undefined;
11
+ } | {
12
+ onClick: () => void;
13
+ };
14
+ linkProps: {
15
+ target: string;
16
+ href: string;
17
+ } | {
18
+ target?: undefined;
19
+ href?: undefined;
20
+ };
21
+ source: any;
22
+ sourceDefinition: any;
23
+ sourceValue: any;
24
+ fragmentManager: null;
25
+ };
26
+ //# sourceMappingURL=useCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCollection.d.ts","sourceRoot":"","sources":["../../../../src/nodes/CollectionItem/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"}
@@ -0,0 +1,3 @@
1
+ export { CollectionItem } from './CollectionItem';
2
+ export { useCollection } from './hooks/useCollection';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nodes/CollectionItem/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { ElementType, FC } from 'react';
2
2
  import { LinkKey } from '@graph-state/core';
3
+ import { UseFrameOptions } from './hooks/useFrame';
3
4
  export interface FrameProps extends UseFrameOptions {
4
5
  TextElement?: ElementType;
5
6
  InstanceElement?: ElementType;
@@ -1 +1 @@
1
- {"version":3,"file":"Frame.d.ts","sourceRoot":"","sources":["../../../src/nodes/Frame/Frame.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,EAAE,EAAyB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQ5C,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,iBAAiB,CAAC,EAAE,WAAW,CAAC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,UAAU,CAsDhC,CAAC"}
1
+ {"version":3,"file":"Frame.d.ts","sourceRoot":"","sources":["../../../src/nodes/Frame/Frame.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,EAAE,EAAyB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAM5C,OAAO,EAAY,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,iBAAiB,CAAC,EAAE,WAAW,CAAC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,UAAU,CAsDhC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { LinkKey } from '@graph-state/core';
2
2
  import { ElementType } from 'react';
3
+ import { UseLayerInteractionsOptions } from '../../../hooks/utils/useLayerInteractions';
3
4
  export interface UseFrameOptions extends UseLayerInteractionsOptions {
4
5
  collectStyle?: boolean;
5
6
  FrameTag?: string | ElementType;
@@ -1 +1 @@
1
- {"version":3,"file":"useFrame.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Frame/hooks/useFrame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAc,MAAM,OAAO,CAAC;AAQhD,MAAM,WAAW,eAAgB,SAAQ,2BAA2B;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CACjC;AAED,eAAO,MAAM,QAAQ,aAAc,OAAO,YAAY,eAAe;;;;;;;;;;;;;;;;;;CAwBpE,CAAC"}
1
+ {"version":3,"file":"useFrame.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Frame/hooks/useFrame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAc,MAAM,OAAO,CAAC;AAKhD,OAAO,EAEL,2BAA2B,EAC5B,MAAM,oCAAoC,CAAC;AAG5C,MAAM,WAAW,eAAgB,SAAQ,2BAA2B;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CACjC;AAED,eAAO,MAAM,QAAQ,aAAc,OAAO,YAAY,eAAe;;;;;;;;;;;;;;;;;;CAwBpE,CAAC"}
@@ -9,7 +9,7 @@ export declare const useInstance: (instanceProps: UseInstanceOptions) => {
9
9
  onClick: () => void;
10
10
  };
11
11
  definitions: any;
12
- props: Omit<any, "_type" | "_id">;
12
+ props: unknown;
13
13
  cssProps: {};
14
14
  parentManager: null;
15
15
  innerManager: any;
@@ -1,6 +1,6 @@
1
1
  import { InstanceProps } from '../Instance';
2
2
  export declare const useInstanceProps: (instanceProps: InstanceProps) => {
3
- props: Omit<any, "_type" | "_id">;
3
+ props: unknown;
4
4
  cssProps: {};
5
5
  onChangeProps: (variableId: string, value: unknown) => void;
6
6
  };