@fragmentsx/render-react 1.2.3 → 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.
- package/dist/hooks/layer/useLayerValue.d.ts +2 -3
- package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
- package/dist/index.cjs.js +161 -31
- package/dist/index.es.js +162 -32
- package/dist/nodes/Collection/Collection.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
- package/dist/nodes/Text/Text.d.ts.map +1 -1
- package/dist/nodes/Text/hooks/useTextAttributes.d.ts +4 -0
- package/dist/nodes/Text/hooks/useTextAttributes.d.ts.map +1 -1
- package/dist/nodes/Text/hooks/useTextContent.d.ts.map +1 -1
- package/dist/nodes/Text/hooks/useTextHighlight.d.ts +6 -0
- package/dist/nodes/Text/hooks/useTextHighlight.d.ts.map +1 -0
- package/dist/nodes/Text/index.d.ts +1 -0
- package/dist/nodes/Text/index.d.ts.map +1 -1
- package/dist/test/__examples__/Fragment.test.d.ts +6 -0
- package/dist/test/__examples__/Fragment.test.d.ts.map +1 -0
- package/dist/test/__examples__/useReadVariable.test.d.ts +6 -0
- package/dist/test/__examples__/useReadVariable.test.d.ts.map +1 -0
- package/dist/test/setupTests.d.ts +2 -0
- package/dist/test/setupTests.d.ts.map +1 -0
- package/dist/test/testUtils.d.ts +17 -0
- package/dist/test/testUtils.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { GraphState, LinkKey } from '@graph-state/core';
|
|
2
2
|
import { GetLayerOptions } from './useNormalizeLayer/getLayer';
|
|
3
|
-
interface
|
|
3
|
+
export interface UseLayerValueOptions extends GetLayerOptions {
|
|
4
4
|
manager?: GraphState;
|
|
5
5
|
scopes?: unknown[];
|
|
6
6
|
}
|
|
7
|
-
export declare const useLayerValue: (layerKey: LinkKey, fieldKey: string, options?:
|
|
8
|
-
export {};
|
|
7
|
+
export declare const useLayerValue: (layerKey: LinkKey, fieldKey: string, options?: UseLayerValueOptions) => any[];
|
|
9
8
|
//# sourceMappingURL=useLayerValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLayerValue.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,UAAU,EAEV,OAAO,EAER,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,
|
|
1
|
+
{"version":3,"file":"useLayerValue.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,UAAU,EAEV,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,UA4E/B,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -504,7 +504,8 @@ function makeSnapshot(globalManager, targetFragmentId) {
|
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
const isInheritField = (manager, layerEntity, field) => {
|
|
507
|
-
|
|
507
|
+
var _a;
|
|
508
|
+
const layer = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerEntity);
|
|
508
509
|
if (layer) {
|
|
509
510
|
const overrider = getOverrider(manager, layer);
|
|
510
511
|
if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
|
|
@@ -1631,6 +1632,10 @@ const useTextContent = (layerKey, manager) => {
|
|
|
1631
1632
|
readVariable(variable.variableKey).value ?? ""
|
|
1632
1633
|
);
|
|
1633
1634
|
});
|
|
1635
|
+
nextContent = nextContent.replace(
|
|
1636
|
+
/\{\{(.*?)}}/,
|
|
1637
|
+
`<mark class="highlight">$1</mark>`
|
|
1638
|
+
);
|
|
1634
1639
|
return nextContent;
|
|
1635
1640
|
};
|
|
1636
1641
|
const useHash = (layerKey, manager) => {
|
|
@@ -1748,22 +1753,111 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
1748
1753
|
};
|
|
1749
1754
|
}, [interactions, fireEvent, pause]);
|
|
1750
1755
|
};
|
|
1756
|
+
const useTextHighlight = (layerKey, options) => {
|
|
1757
|
+
const [highlightLayerKey] = useLayerValue(layerKey, "highlight", options);
|
|
1758
|
+
const [, , { cssVariableValue: fontSize }] = useLayerValue(
|
|
1759
|
+
highlightLayerKey,
|
|
1760
|
+
"fontSize",
|
|
1761
|
+
options
|
|
1762
|
+
);
|
|
1763
|
+
const [, , { cssVariableValue: color }] = useLayerValue(
|
|
1764
|
+
highlightLayerKey,
|
|
1765
|
+
"color",
|
|
1766
|
+
options
|
|
1767
|
+
);
|
|
1768
|
+
const [, , { cssVariableValue: fontWeight }] = useLayerValue(
|
|
1769
|
+
highlightLayerKey,
|
|
1770
|
+
"fontWeight",
|
|
1771
|
+
options
|
|
1772
|
+
);
|
|
1773
|
+
const [, , { cssVariableValue: textAlign }] = useLayerValue(
|
|
1774
|
+
highlightLayerKey,
|
|
1775
|
+
"textAlign",
|
|
1776
|
+
options
|
|
1777
|
+
);
|
|
1778
|
+
const [, , { cssVariableValue: textDecoration }] = useLayerValue(
|
|
1779
|
+
highlightLayerKey,
|
|
1780
|
+
"textDecoration",
|
|
1781
|
+
options
|
|
1782
|
+
);
|
|
1783
|
+
const [, , { cssVariableValue: textTransform }] = useLayerValue(
|
|
1784
|
+
highlightLayerKey,
|
|
1785
|
+
"textTransform",
|
|
1786
|
+
options
|
|
1787
|
+
);
|
|
1788
|
+
const [, , { cssVariableValue: lineHeight }] = useLayerValue(
|
|
1789
|
+
highlightLayerKey,
|
|
1790
|
+
"lineHeight",
|
|
1791
|
+
options
|
|
1792
|
+
);
|
|
1793
|
+
const [, , { cssVariableValue: letterSpacing }] = useLayerValue(
|
|
1794
|
+
highlightLayerKey,
|
|
1795
|
+
"letterSpacing",
|
|
1796
|
+
options
|
|
1797
|
+
);
|
|
1798
|
+
const [, , { cssVariableValue: fontFamily }] = useLayerValue(
|
|
1799
|
+
highlightLayerKey,
|
|
1800
|
+
"fontFamily",
|
|
1801
|
+
options
|
|
1802
|
+
);
|
|
1803
|
+
const styles = {
|
|
1804
|
+
background: "inherit",
|
|
1805
|
+
color: "inherit"
|
|
1806
|
+
};
|
|
1807
|
+
if (!!fontSize) {
|
|
1808
|
+
styles["font-size"] = utils.toPx(fontSize);
|
|
1809
|
+
}
|
|
1810
|
+
if (!!color) {
|
|
1811
|
+
styles["color"] = color;
|
|
1812
|
+
}
|
|
1813
|
+
if (!!fontWeight) {
|
|
1814
|
+
styles["font-weight"] = fontWeight;
|
|
1815
|
+
}
|
|
1816
|
+
if (!!textAlign) {
|
|
1817
|
+
styles["text-align"] = textAlign;
|
|
1818
|
+
}
|
|
1819
|
+
if (!!textDecoration) {
|
|
1820
|
+
styles["text-decoration"] = textDecoration;
|
|
1821
|
+
}
|
|
1822
|
+
if (!!textTransform) {
|
|
1823
|
+
styles["text-transform"] = textTransform;
|
|
1824
|
+
}
|
|
1825
|
+
if (!!lineHeight) {
|
|
1826
|
+
styles["line-height"] = lineHeight;
|
|
1827
|
+
}
|
|
1828
|
+
if (!!letterSpacing) {
|
|
1829
|
+
styles["letter-spacing"] = utils.toPx(letterSpacing);
|
|
1830
|
+
}
|
|
1831
|
+
if (!!fontFamily) {
|
|
1832
|
+
styles["font-family"] = fontFamily;
|
|
1833
|
+
}
|
|
1834
|
+
return {
|
|
1835
|
+
stylesString: Object.entries(styles).reduce(
|
|
1836
|
+
(acc, [key, value]) => acc += `${key}: ${value};`,
|
|
1837
|
+
""
|
|
1838
|
+
)
|
|
1839
|
+
};
|
|
1840
|
+
};
|
|
1751
1841
|
const useTextAttributes = (layerKey, options) => {
|
|
1752
1842
|
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
1753
1843
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1754
1844
|
const styles = useLayerStyles(layerKey);
|
|
1845
|
+
const highlight = useTextHighlight(layerKey);
|
|
1755
1846
|
const content = useTextContent(layerKey);
|
|
1756
1847
|
const classnames = useClassnames(layerKey, fragmentManager);
|
|
1848
|
+
const hash = useHash(layerKey, fragmentManager);
|
|
1757
1849
|
const { addLayerStyle } = useStyleSheet(fragmentManager);
|
|
1758
1850
|
const events = useLayerInteractions(layerKey, options);
|
|
1759
1851
|
if (collectStyle) {
|
|
1760
1852
|
addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
|
|
1761
1853
|
}
|
|
1762
1854
|
return {
|
|
1855
|
+
hash,
|
|
1763
1856
|
events,
|
|
1764
1857
|
styles,
|
|
1765
1858
|
classnames,
|
|
1766
|
-
content
|
|
1859
|
+
content,
|
|
1860
|
+
highlight
|
|
1767
1861
|
};
|
|
1768
1862
|
};
|
|
1769
1863
|
const Text = ({
|
|
@@ -1772,15 +1866,28 @@ const Text = ({
|
|
|
1772
1866
|
collectStyle,
|
|
1773
1867
|
...restProps
|
|
1774
1868
|
}) => {
|
|
1775
|
-
const { classnames, content, events } = useTextAttributes(
|
|
1776
|
-
|
|
1777
|
-
});
|
|
1778
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1779
|
-
"div",
|
|
1869
|
+
const { classnames, content, events, hash, highlight } = useTextAttributes(
|
|
1870
|
+
layerKey,
|
|
1780
1871
|
{
|
|
1781
|
-
|
|
1872
|
+
collectStyle
|
|
1782
1873
|
}
|
|
1783
|
-
)
|
|
1874
|
+
);
|
|
1875
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: [
|
|
1876
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1877
|
+
"style",
|
|
1878
|
+
{
|
|
1879
|
+
dangerouslySetInnerHTML: {
|
|
1880
|
+
__html: `.${hash} .highlight {${highlight.stylesString}}`
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
),
|
|
1884
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1885
|
+
"div",
|
|
1886
|
+
{
|
|
1887
|
+
dangerouslySetInnerHTML: { __html: content }
|
|
1888
|
+
}
|
|
1889
|
+
)
|
|
1890
|
+
] });
|
|
1784
1891
|
};
|
|
1785
1892
|
const useFrame = (layerKey, options) => {
|
|
1786
1893
|
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
@@ -1861,29 +1968,36 @@ const Collection = ({
|
|
|
1861
1968
|
"data-key": layerKey,
|
|
1862
1969
|
style: resultStyles,
|
|
1863
1970
|
...restProps,
|
|
1864
|
-
children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (
|
|
1865
|
-
|
|
1971
|
+
children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItemLinkKey) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1972
|
+
react$1.GraphValue,
|
|
1866
1973
|
{
|
|
1867
|
-
fragmentManager,
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
source,
|
|
1872
|
-
sourceDefinition,
|
|
1873
|
-
value: collectionItem,
|
|
1874
|
-
manager: fragmentManager
|
|
1875
|
-
},
|
|
1876
|
-
children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1877
|
-
"div",
|
|
1974
|
+
graphState: fragmentManager,
|
|
1975
|
+
field: collectionItemLinkKey,
|
|
1976
|
+
children: (value) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1977
|
+
Scope,
|
|
1878
1978
|
{
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1979
|
+
fragmentManager,
|
|
1980
|
+
layerKey: collectionItemLinkKey,
|
|
1981
|
+
value: {
|
|
1982
|
+
type: definition.definition.scopeTypes.CollectionItemScope,
|
|
1983
|
+
source,
|
|
1984
|
+
sourceDefinition,
|
|
1985
|
+
value,
|
|
1986
|
+
manager: fragmentManager
|
|
1882
1987
|
},
|
|
1883
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1988
|
+
children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1989
|
+
"div",
|
|
1990
|
+
{
|
|
1991
|
+
style: {
|
|
1992
|
+
display: "contents",
|
|
1993
|
+
...getCssVariables(value ?? {})
|
|
1994
|
+
},
|
|
1995
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(FrameElement, { ...restProps, layerKey: child })
|
|
1996
|
+
},
|
|
1997
|
+
child
|
|
1998
|
+
))
|
|
1999
|
+
}
|
|
2000
|
+
)
|
|
1887
2001
|
}
|
|
1888
2002
|
))
|
|
1889
2003
|
}
|
|
@@ -2154,8 +2268,22 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2154
2268
|
);
|
|
2155
2269
|
const { manager: fragmentContextManager } = react.useContext(FragmentContext);
|
|
2156
2270
|
const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
|
|
2157
|
-
const
|
|
2271
|
+
const { readVariable } = useReadVariable();
|
|
2158
2272
|
const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
|
|
2273
|
+
const flatDefinition = react.useMemo(() => {
|
|
2274
|
+
const acc = [];
|
|
2275
|
+
const run = (defLink) => {
|
|
2276
|
+
const resolvedDefinition = fragmentManager.resolve(defLink);
|
|
2277
|
+
if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.definition.variableType.Object) {
|
|
2278
|
+
Object.values(resolvedDefinition.fields).forEach(run);
|
|
2279
|
+
} else if (definition.isVariableLink(defLink)) {
|
|
2280
|
+
acc.push(defLink);
|
|
2281
|
+
}
|
|
2282
|
+
};
|
|
2283
|
+
definitions.forEach(run);
|
|
2284
|
+
return acc;
|
|
2285
|
+
}, [definitions]);
|
|
2286
|
+
const definitionsData = react$1.useGraphStack(innerFragmentManager, flatDefinition);
|
|
2159
2287
|
const [instanceLayer] = react$1.useGraph(fragmentManager, instanceProps.layerKey);
|
|
2160
2288
|
const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
|
|
2161
2289
|
const [localProps, setLocalProps] = react.useState(instanceProps.props ?? {});
|
|
@@ -2179,7 +2307,8 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2179
2307
|
fragmentManager,
|
|
2180
2308
|
instanceLayerProps,
|
|
2181
2309
|
definitionsData,
|
|
2182
|
-
localProps
|
|
2310
|
+
localProps,
|
|
2311
|
+
readVariable
|
|
2183
2312
|
]);
|
|
2184
2313
|
react.useEffect(() => {
|
|
2185
2314
|
if (utils.isValue(instanceProps == null ? void 0 : instanceProps.props)) {
|
|
@@ -2497,4 +2626,5 @@ exports.useReadVariables = useReadVariables;
|
|
|
2497
2626
|
exports.useRenderTarget = useRenderTarget;
|
|
2498
2627
|
exports.useTextAttributes = useTextAttributes;
|
|
2499
2628
|
exports.useTextContent = useTextContent;
|
|
2629
|
+
exports.useTextHighlight = useTextHighlight;
|
|
2500
2630
|
exports.wrapTextInParagraphWithAttributes = wrapTextInParagraphWithAttributes;
|
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);
|
|
@@ -502,7 +502,8 @@ function makeSnapshot(globalManager, targetFragmentId) {
|
|
|
502
502
|
};
|
|
503
503
|
}
|
|
504
504
|
const isInheritField = (manager, layerEntity, field) => {
|
|
505
|
-
|
|
505
|
+
var _a;
|
|
506
|
+
const layer = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerEntity);
|
|
506
507
|
if (layer) {
|
|
507
508
|
const overrider = getOverrider(manager, layer);
|
|
508
509
|
if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
|
|
@@ -1629,6 +1630,10 @@ const useTextContent = (layerKey, manager) => {
|
|
|
1629
1630
|
readVariable(variable.variableKey).value ?? ""
|
|
1630
1631
|
);
|
|
1631
1632
|
});
|
|
1633
|
+
nextContent = nextContent.replace(
|
|
1634
|
+
/\{\{(.*?)}}/,
|
|
1635
|
+
`<mark class="highlight">$1</mark>`
|
|
1636
|
+
);
|
|
1632
1637
|
return nextContent;
|
|
1633
1638
|
};
|
|
1634
1639
|
const useHash = (layerKey, manager) => {
|
|
@@ -1746,22 +1751,111 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
1746
1751
|
};
|
|
1747
1752
|
}, [interactions, fireEvent, pause]);
|
|
1748
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
|
+
};
|
|
1749
1839
|
const useTextAttributes = (layerKey, options) => {
|
|
1750
1840
|
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
1751
1841
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1752
1842
|
const styles = useLayerStyles(layerKey);
|
|
1843
|
+
const highlight = useTextHighlight(layerKey);
|
|
1753
1844
|
const content = useTextContent(layerKey);
|
|
1754
1845
|
const classnames = useClassnames(layerKey, fragmentManager);
|
|
1846
|
+
const hash = useHash(layerKey, fragmentManager);
|
|
1755
1847
|
const { addLayerStyle } = useStyleSheet(fragmentManager);
|
|
1756
1848
|
const events = useLayerInteractions(layerKey, options);
|
|
1757
1849
|
if (collectStyle) {
|
|
1758
1850
|
addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
|
|
1759
1851
|
}
|
|
1760
1852
|
return {
|
|
1853
|
+
hash,
|
|
1761
1854
|
events,
|
|
1762
1855
|
styles,
|
|
1763
1856
|
classnames,
|
|
1764
|
-
content
|
|
1857
|
+
content,
|
|
1858
|
+
highlight
|
|
1765
1859
|
};
|
|
1766
1860
|
};
|
|
1767
1861
|
const Text = ({
|
|
@@ -1770,15 +1864,28 @@ const Text = ({
|
|
|
1770
1864
|
collectStyle,
|
|
1771
1865
|
...restProps
|
|
1772
1866
|
}) => {
|
|
1773
|
-
const { classnames, content, events } = useTextAttributes(
|
|
1774
|
-
|
|
1775
|
-
});
|
|
1776
|
-
return /* @__PURE__ */ jsx(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: /* @__PURE__ */ jsx(
|
|
1777
|
-
"div",
|
|
1867
|
+
const { classnames, content, events, hash, highlight } = useTextAttributes(
|
|
1868
|
+
layerKey,
|
|
1778
1869
|
{
|
|
1779
|
-
|
|
1870
|
+
collectStyle
|
|
1780
1871
|
}
|
|
1781
|
-
)
|
|
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
|
+
] });
|
|
1782
1889
|
};
|
|
1783
1890
|
const useFrame = (layerKey, options) => {
|
|
1784
1891
|
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
@@ -1859,29 +1966,36 @@ const Collection = ({
|
|
|
1859
1966
|
"data-key": layerKey,
|
|
1860
1967
|
style: resultStyles,
|
|
1861
1968
|
...restProps,
|
|
1862
|
-
children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (
|
|
1863
|
-
|
|
1969
|
+
children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItemLinkKey) => /* @__PURE__ */ jsx(
|
|
1970
|
+
GraphValue,
|
|
1864
1971
|
{
|
|
1865
|
-
fragmentManager,
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
source,
|
|
1870
|
-
sourceDefinition,
|
|
1871
|
-
value: collectionItem,
|
|
1872
|
-
manager: fragmentManager
|
|
1873
|
-
},
|
|
1874
|
-
children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
|
|
1875
|
-
"div",
|
|
1972
|
+
graphState: fragmentManager,
|
|
1973
|
+
field: collectionItemLinkKey,
|
|
1974
|
+
children: (value) => /* @__PURE__ */ jsx(
|
|
1975
|
+
Scope,
|
|
1876
1976
|
{
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1977
|
+
fragmentManager,
|
|
1978
|
+
layerKey: collectionItemLinkKey,
|
|
1979
|
+
value: {
|
|
1980
|
+
type: definition.scopeTypes.CollectionItemScope,
|
|
1981
|
+
source,
|
|
1982
|
+
sourceDefinition,
|
|
1983
|
+
value,
|
|
1984
|
+
manager: fragmentManager
|
|
1880
1985
|
},
|
|
1881
|
-
children:
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
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
|
+
)
|
|
1885
1999
|
}
|
|
1886
2000
|
))
|
|
1887
2001
|
}
|
|
@@ -2152,8 +2266,22 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2152
2266
|
);
|
|
2153
2267
|
const { manager: fragmentContextManager } = useContext(FragmentContext);
|
|
2154
2268
|
const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
|
|
2155
|
-
const
|
|
2269
|
+
const { readVariable } = useReadVariable();
|
|
2156
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);
|
|
2157
2285
|
const [instanceLayer] = useGraph(fragmentManager, instanceProps.layerKey);
|
|
2158
2286
|
const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
|
|
2159
2287
|
const [localProps, setLocalProps] = useState(instanceProps.props ?? {});
|
|
@@ -2177,7 +2305,8 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2177
2305
|
fragmentManager,
|
|
2178
2306
|
instanceLayerProps,
|
|
2179
2307
|
definitionsData,
|
|
2180
|
-
localProps
|
|
2308
|
+
localProps,
|
|
2309
|
+
readVariable
|
|
2181
2310
|
]);
|
|
2182
2311
|
useEffect(() => {
|
|
2183
2312
|
if (isValue(instanceProps == null ? void 0 : instanceProps.props)) {
|
|
@@ -2496,5 +2625,6 @@ export {
|
|
|
2496
2625
|
useRenderTarget,
|
|
2497
2626
|
useTextAttributes,
|
|
2498
2627
|
useTextContent,
|
|
2628
|
+
useTextHighlight,
|
|
2499
2629
|
wrapTextInParagraphWithAttributes
|
|
2500
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;
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInstanceProps.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Instance/hooks/useInstanceProps.ts"],"names":[],"mappings":"
|
|
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,
|
|
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,6 +3,7 @@ export interface UseTextAttributes {
|
|
|
3
3
|
collectStyle?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare const useTextAttributes: (layerKey: LinkKey, options?: UseTextAttributes) => {
|
|
6
|
+
hash: string | null;
|
|
6
7
|
events: {
|
|
7
8
|
onClick?: undefined;
|
|
8
9
|
} | {
|
|
@@ -11,5 +12,8 @@ export declare const useTextAttributes: (layerKey: LinkKey, options?: UseTextAtt
|
|
|
11
12
|
styles: {};
|
|
12
13
|
classnames: string | null;
|
|
13
14
|
content: any;
|
|
15
|
+
highlight: {
|
|
16
|
+
stylesString: string;
|
|
17
|
+
};
|
|
14
18
|
};
|
|
15
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;
|
|
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,
|
|
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 +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 @@
|
|
|
1
|
+
{"version":3,"file":"Fragment.test.d.ts","sourceRoot":"","sources":["../../../src/test/__examples__/Fragment.test.tsx"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReadVariable.test.d.ts","sourceRoot":"","sources":["../../../src/test/__examples__/useReadVariable.test.tsx"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupTests.d.ts","sourceRoot":"","sources":["../../src/test/setupTests.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { RenderOptions } from '@testing-library/react';
|
|
3
|
+
import { GraphState } from '@graph-state/core';
|
|
4
|
+
/**
|
|
5
|
+
* Создаёт тестовый GlobalManager для тестов
|
|
6
|
+
*/
|
|
7
|
+
export declare const createTestGlobalManager: (initialData?: unknown) => GraphState;
|
|
8
|
+
/**
|
|
9
|
+
* Кастомный render с провайдерами по умолчанию
|
|
10
|
+
*/
|
|
11
|
+
interface CustomRenderOptions extends Omit<RenderOptions, "wrapper"> {
|
|
12
|
+
globalManager?: GraphState;
|
|
13
|
+
}
|
|
14
|
+
export declare const renderWithProviders: (ui: ReactElement, { globalManager, ...renderOptions }?: CustomRenderOptions) => any;
|
|
15
|
+
export * from '@testing-library/react';
|
|
16
|
+
export { default as userEvent } from '@testing-library/user-event';
|
|
17
|
+
//# sourceMappingURL=testUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../../src/test/testUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAU,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C;;GAEG;AACH,eAAO,MAAM,uBAAuB,iBAAkB,OAAO,KAAG,UAE/D,CAAC;AAEF;;GAEG;AACH,UAAU,mBAAoB,SAAQ,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC;IAClE,aAAa,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,eAAO,MAAM,mBAAmB,OAC1B,YAAY,wCAIb,mBAAmB,QAWvB,CAAC;AAGF,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,6BAA6B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fragmentsx/render-react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@graph-state/core": "^0.13.2",
|
|
28
28
|
"@graph-state/react": "^0.8.2",
|
|
29
29
|
"react-use-measure": "^2.1.7",
|
|
30
|
-
"@fragmentsx/definition": "0.2.
|
|
30
|
+
"@fragmentsx/definition": "0.2.1",
|
|
31
31
|
"@fragmentsx/utils": "0.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|