@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.
- package/dist/hooks/fragment/useFragmentCssChunks.d.ts.map +1 -1
- package/dist/hooks/layer/index.d.ts +1 -1
- package/dist/hooks/layer/index.d.ts.map +1 -1
- package/dist/hooks/layer/useLayerCssVariable.d.ts.map +1 -1
- package/dist/hooks/layer/useLayerValue.d.ts +2 -3
- package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
- package/dist/hooks/layer/useNormalizeLayer/index.d.ts.map +1 -1
- package/dist/hooks/layer/useReadVariable.d.ts +6 -2
- package/dist/hooks/layer/useReadVariable.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerPaint.d.ts +1 -0
- package/dist/hooks/layer-styles/useLayerPaint.d.ts.map +1 -1
- package/dist/hooks/render/index.d.ts +2 -0
- package/dist/hooks/render/index.d.ts.map +1 -0
- package/dist/hooks/utils/useLayerInteractions.d.ts.map +1 -1
- package/dist/index.cjs.js +263 -95
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +264 -96
- package/dist/nodes/Collection/Collection.d.ts.map +1 -1
- package/dist/nodes/Instance/Instance.d.ts +1 -0
- package/dist/nodes/Instance/Instance.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstance.d.ts +1 -0
- package/dist/nodes/Instance/hooks/useInstance.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstanceProps.d.ts +2 -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 +9 -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/dist/utils/layer/makeSnapshot.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragmentCssChunks.d.ts","sourceRoot":"","sources":["../../../src/hooks/fragment/useFragmentCssChunks.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,eAAgB,MAAM,
|
|
1
|
+
{"version":3,"file":"useFragmentCssChunks.d.ts","sourceRoot":"","sources":["../../../src/hooks/fragment/useFragmentCssChunks.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,eAAgB,MAAM,QAStD,CAAC"}
|
|
@@ -7,5 +7,5 @@ export { useLayerScopes } from './useLayerScopes';
|
|
|
7
7
|
export { useLayerLink } from './useLayerLink';
|
|
8
8
|
export { useLayerCssVariable } from './useLayerCssVariable';
|
|
9
9
|
export { useLayerVariableValue } from './useLayerVariableValue';
|
|
10
|
-
export { useNormalizeLayer } from './useNormalizeLayer';
|
|
10
|
+
export { useNormalizeLayer, getNormalizeLayer } from './useNormalizeLayer';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLayerCssVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerCssVariable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useLayerCssVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerCssVariable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,eAAO,MAAM,mBAAmB,YAAa,UAAU;;CAQtD,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAU/B,CAAC"}
|
|
@@ -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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/layer/useNormalizeLayer/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAY,eAAe,EAAE,MAAM,YAAY,CAAC;AAGvD,eAAO,MAAM,iBAAiB,aAClB,OAAO,WACR,OAAO,YACN,eAAe;;;;;;CAU1B,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAClB,OAAO,YACP,OAAO,YACP,eAAe;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/layer/useNormalizeLayer/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAY,eAAe,EAAE,MAAM,YAAY,CAAC;AAGvD,eAAO,MAAM,iBAAiB,aAClB,OAAO,WACR,OAAO,YACN,eAAe;;;;;;CAU1B,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAClB,OAAO,YACP,OAAO,YACP,eAAe;;;;;;CAc1B,CAAC;AAEF,eAAO,MAAM,kBAAkB,cAClB,OAAO,EAAE,YACV,OAAO,YACP,eAAe;;;;;;GAQ1B,CAAC"}
|
|
@@ -2,9 +2,13 @@ import { LinkKey } from '@graph-state/core';
|
|
|
2
2
|
export declare const useReadVariable: (variableKey?: LinkKey | null, customScopes?: unknown[]) => {
|
|
3
3
|
readVariable: (variableKey?: LinkKey) => {
|
|
4
4
|
value: any;
|
|
5
|
-
layer:
|
|
5
|
+
layer: {
|
|
6
|
+
[k: string]: any;
|
|
7
|
+
} | null;
|
|
6
8
|
};
|
|
7
9
|
value: any;
|
|
8
|
-
layer:
|
|
10
|
+
layer: {
|
|
11
|
+
[k: string]: any;
|
|
12
|
+
} | null;
|
|
9
13
|
};
|
|
10
14
|
//# sourceMappingURL=useReadVariable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReadVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariable.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useReadVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariable.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAiDrE,eAAO,MAAM,eAAe,iBACZ,OAAO,GAAG,IAAI,iBACb,OAAO,EAAE;iCAgFY,OAAO;;;;;;;;;;CAgI5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLayerPaint.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer-styles/useLayerPaint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,eAAO,MAAM,aAAa,iBAAkB,OAAO
|
|
1
|
+
{"version":3,"file":"useLayerPaint.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer-styles/useLayerPaint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,eAAO,MAAM,aAAa,iBAAkB,OAAO;;;;;;CAalD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLayerInteractions.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useLayerInteractions.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"useLayerInteractions.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useLayerInteractions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQzD,MAAM,WAAW,2BAA2B;IAC1C,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,oBAAoB,aACrB,OAAO,YACP,2BAA2B;;;;CAuFtC,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -92,6 +92,13 @@ const getNormalizeLayer = (layerKey, manager, options) => {
|
|
|
92
92
|
const useNormalizeLayer = (layerKey, manager, options) => {
|
|
93
93
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
94
94
|
const resultManager = manager ?? fragmentManager;
|
|
95
|
+
if (!resultManager) {
|
|
96
|
+
return {
|
|
97
|
+
layerKey,
|
|
98
|
+
rawLayer: null,
|
|
99
|
+
layer: null
|
|
100
|
+
};
|
|
101
|
+
}
|
|
95
102
|
return getNormalizeLayer(layerKey, resultManager, options);
|
|
96
103
|
};
|
|
97
104
|
const useNormalizeLayers = (layerKeys, manager, options) => {
|
|
@@ -151,12 +158,12 @@ const useReadVariable = (variableKey, customScopes) => {
|
|
|
151
158
|
);
|
|
152
159
|
};
|
|
153
160
|
const resolveVariableLayer = (manager, variableLink, customProps) => {
|
|
154
|
-
var _a;
|
|
155
|
-
const variableLayer = manager == null ? void 0 :
|
|
161
|
+
var _a, _b;
|
|
162
|
+
const variableLayer = (_a = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a.layer;
|
|
156
163
|
if (!variableLayer) return null;
|
|
157
164
|
if ((variableLayer == null ? void 0 : variableLayer.type) === definition.definition.variableType.Array) {
|
|
158
165
|
const definitionLayer = manager.resolve(variableLayer == null ? void 0 : variableLayer.definition);
|
|
159
|
-
if (!((
|
|
166
|
+
if (!((_b = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _b.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.definition.variableType.Object)
|
|
160
167
|
return variableLayer;
|
|
161
168
|
const definitionDefaultValue = extractVariableDefaultValue(
|
|
162
169
|
manager,
|
|
@@ -464,14 +471,12 @@ function makeSnapshot(globalManager, targetFragmentId) {
|
|
|
464
471
|
).filter(Boolean);
|
|
465
472
|
const linkedGoals = Array.from(
|
|
466
473
|
new Set(
|
|
467
|
-
targetFragment.inspectFields(definition.definition.nodes.
|
|
468
|
-
return (graph == null ? void 0 : graph.type) === definition.definition.variableType.Event && (graph == null ? void 0 : graph.mode) === definition.definition.eventMode.goal;
|
|
469
|
-
}).map((graph) => {
|
|
474
|
+
targetFragment.inspectFields(definition.definition.nodes.GoalEvent).map((link) => {
|
|
470
475
|
var _a2;
|
|
471
|
-
return (_a2 =
|
|
472
|
-
}).
|
|
476
|
+
return (_a2 = targetFragment == null ? void 0 : targetFragment.resolve(link)) == null ? void 0 : _a2.goalId;
|
|
477
|
+
}).values()
|
|
473
478
|
)
|
|
474
|
-
);
|
|
479
|
+
).filter(Boolean);
|
|
475
480
|
const fonts = Array.from(
|
|
476
481
|
new Set(
|
|
477
482
|
targetFragment.inspectFields(definition.definition.nodes.Text).map((linkKey) => {
|
|
@@ -499,7 +504,8 @@ function makeSnapshot(globalManager, targetFragmentId) {
|
|
|
499
504
|
};
|
|
500
505
|
}
|
|
501
506
|
const isInheritField = (manager, layerEntity, field) => {
|
|
502
|
-
|
|
507
|
+
var _a;
|
|
508
|
+
const layer = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerEntity);
|
|
503
509
|
if (layer) {
|
|
504
510
|
const overrider = getOverrider(manager, layer);
|
|
505
511
|
if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
|
|
@@ -971,13 +977,9 @@ const getLayerCssVariable = (manager, inputValue) => {
|
|
|
971
977
|
const useLayerCssVariable = (inputValue) => {
|
|
972
978
|
const { manager } = react.useContext(FragmentContext);
|
|
973
979
|
const isVariable = definition.isVariableLink(inputValue);
|
|
974
|
-
const
|
|
975
|
-
selector: (graph) => utils.pick(graph, "defaultValue", "_id")
|
|
976
|
-
});
|
|
980
|
+
const { layer } = useNormalizeLayer(inputValue, isVariable ? manager : null);
|
|
977
981
|
return {
|
|
978
|
-
value: isVariable ? `var(--${
|
|
979
|
-
variableValue == null ? void 0 : variableValue.defaultValue
|
|
980
|
-
)})` : null
|
|
982
|
+
value: isVariable ? `var(--${layer == null ? void 0 : layer._id}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
|
|
981
983
|
};
|
|
982
984
|
};
|
|
983
985
|
const useLayerValue = (layerKey, fieldKey, options) => {
|
|
@@ -1428,12 +1430,13 @@ const useLayerDisplay = (layerKey) => {
|
|
|
1428
1430
|
};
|
|
1429
1431
|
const useLayerPaint = (paintLinkKey) => {
|
|
1430
1432
|
const [type] = useLayerValue(paintLinkKey, "type");
|
|
1431
|
-
const [solid] = useLayerValue(paintLinkKey, "solid");
|
|
1433
|
+
const [solid, , solidInfo] = useLayerValue(paintLinkKey, "solid");
|
|
1432
1434
|
const [image] = useLayerValue(paintLinkKey, "image");
|
|
1433
1435
|
const [linearGradientLink] = useLayerValue(paintLinkKey, "linearGradient");
|
|
1434
1436
|
return {
|
|
1435
1437
|
type,
|
|
1436
1438
|
solid,
|
|
1439
|
+
solidCssValue: solidInfo.cssVariableValue,
|
|
1437
1440
|
image,
|
|
1438
1441
|
linearGradientLink
|
|
1439
1442
|
};
|
|
@@ -1473,7 +1476,7 @@ const useLayerBorder = (layerKey) => {
|
|
|
1473
1476
|
};
|
|
1474
1477
|
}
|
|
1475
1478
|
if (borderPaint.type === definition.definition.paintMode.Solid) {
|
|
1476
|
-
return calcBorderSides(type, width, borderPaint.
|
|
1479
|
+
return calcBorderSides(type, width, borderPaint.solidCssValue);
|
|
1477
1480
|
}
|
|
1478
1481
|
return { border: null };
|
|
1479
1482
|
};
|
|
@@ -1629,6 +1632,10 @@ const useTextContent = (layerKey, manager) => {
|
|
|
1629
1632
|
readVariable(variable.variableKey).value ?? ""
|
|
1630
1633
|
);
|
|
1631
1634
|
});
|
|
1635
|
+
nextContent = nextContent.replace(
|
|
1636
|
+
/\{\{(.*?)}}/,
|
|
1637
|
+
`<mark class="highlight">$1</mark>`
|
|
1638
|
+
);
|
|
1632
1639
|
return nextContent;
|
|
1633
1640
|
};
|
|
1634
1641
|
const useHash = (layerKey, manager) => {
|
|
@@ -1684,36 +1691,6 @@ const useStyleSheet = (manager) => {
|
|
|
1684
1691
|
unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? utils.noop
|
|
1685
1692
|
};
|
|
1686
1693
|
};
|
|
1687
|
-
const useTextAttributes = (layerKey, options) => {
|
|
1688
|
-
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
1689
|
-
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1690
|
-
const styles = useLayerStyles(layerKey);
|
|
1691
|
-
const content = useTextContent(layerKey);
|
|
1692
|
-
const classnames = useClassnames(layerKey, fragmentManager);
|
|
1693
|
-
const { addLayerStyle } = useStyleSheet(fragmentManager);
|
|
1694
|
-
if (collectStyle) {
|
|
1695
|
-
addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
|
|
1696
|
-
}
|
|
1697
|
-
return {
|
|
1698
|
-
styles,
|
|
1699
|
-
classnames,
|
|
1700
|
-
content
|
|
1701
|
-
};
|
|
1702
|
-
};
|
|
1703
|
-
const Text = ({
|
|
1704
|
-
layerKey,
|
|
1705
|
-
Tag = "div",
|
|
1706
|
-
collectStyle,
|
|
1707
|
-
...restProps
|
|
1708
|
-
}) => {
|
|
1709
|
-
const { classnames, content } = useTextAttributes(layerKey, { collectStyle });
|
|
1710
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { className: classnames, "data-key": layerKey, ...restProps, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1711
|
-
"div",
|
|
1712
|
-
{
|
|
1713
|
-
dangerouslySetInnerHTML: { __html: content }
|
|
1714
|
-
}
|
|
1715
|
-
) });
|
|
1716
|
-
};
|
|
1717
1694
|
const useLayerInteractions = (layerKey, options) => {
|
|
1718
1695
|
const pause = (options == null ? void 0 : options.pauseInteractions) ?? false;
|
|
1719
1696
|
const { manager: globalManager } = useGlobalManager();
|
|
@@ -1722,29 +1699,40 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
1722
1699
|
const areaScope = scopes.find(
|
|
1723
1700
|
(scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.AreaScope
|
|
1724
1701
|
);
|
|
1725
|
-
const
|
|
1726
|
-
|
|
1727
|
-
"interactions",
|
|
1728
|
-
fragmentManager
|
|
1702
|
+
const instanceScope = scopes.find(
|
|
1703
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.InstanceScope
|
|
1729
1704
|
);
|
|
1730
|
-
const
|
|
1705
|
+
const [interactionLinks] = useLayerValue(layerKey, "interactions");
|
|
1706
|
+
const interactionOns = useLayersValue(interactionLinks, "on");
|
|
1707
|
+
const interactionEvents = useLayersValue(interactionLinks, "event");
|
|
1708
|
+
const interactions = (interactionLinks ?? []).map((linkKey, index) => {
|
|
1709
|
+
var _a, _b;
|
|
1710
|
+
return {
|
|
1711
|
+
linkKey,
|
|
1712
|
+
on: (_a = interactionOns == null ? void 0 : interactionOns.at(index)) == null ? void 0 : _a.at(0),
|
|
1713
|
+
event: (_b = interactionEvents == null ? void 0 : interactionEvents.at(index)) == null ? void 0 : _b.at(0)
|
|
1714
|
+
};
|
|
1715
|
+
});
|
|
1731
1716
|
const fireEvent = react.useCallback(
|
|
1732
1717
|
(eventLink) => {
|
|
1733
|
-
var _a, _b, _c, _d;
|
|
1734
|
-
|
|
1735
|
-
const
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
(
|
|
1718
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1719
|
+
const eventType = (_a = core.entityOfKey(eventLink)) == null ? void 0 : _a._type;
|
|
1720
|
+
const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
|
|
1721
|
+
if (eventType === definition.definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
|
|
1722
|
+
if (!areaScope) return null;
|
|
1723
|
+
(_d = (_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.reachGoal) == null ? void 0 : _d.call(_c, {
|
|
1739
1724
|
goalId: eventValue == null ? void 0 : eventValue.goalId,
|
|
1740
1725
|
...utils.pick(areaScope, "variantId", "campaignId", "areaId")
|
|
1741
1726
|
});
|
|
1742
1727
|
}
|
|
1743
|
-
if (
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1728
|
+
if (eventType === definition.definition.nodes.MutateEvent) {
|
|
1729
|
+
const target = eventValue == null ? void 0 : eventValue.target;
|
|
1730
|
+
const targetLayer = getNormalizeLayer(target, fragmentManager);
|
|
1731
|
+
const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_e = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _e.defaultValue);
|
|
1732
|
+
if (definition.isVariableLink(target) && utils.isValue(value)) {
|
|
1733
|
+
const targetId = (_f = core.entityOfKey(target)) == null ? void 0 : _f._id;
|
|
1734
|
+
(_g = instanceScope == null ? void 0 : instanceScope.onChangeProps) == null ? void 0 : _g.call(instanceScope, targetId, value);
|
|
1735
|
+
}
|
|
1748
1736
|
}
|
|
1749
1737
|
},
|
|
1750
1738
|
[globalManager, fragmentManager, areaScope]
|
|
@@ -1765,6 +1753,142 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
1765
1753
|
};
|
|
1766
1754
|
}, [interactions, fireEvent, pause]);
|
|
1767
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
|
+
};
|
|
1841
|
+
const useTextAttributes = (layerKey, options) => {
|
|
1842
|
+
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
1843
|
+
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1844
|
+
const styles = useLayerStyles(layerKey);
|
|
1845
|
+
const highlight = useTextHighlight(layerKey);
|
|
1846
|
+
const content = useTextContent(layerKey);
|
|
1847
|
+
const classnames = useClassnames(layerKey, fragmentManager);
|
|
1848
|
+
const hash = useHash(layerKey, fragmentManager);
|
|
1849
|
+
const { addLayerStyle } = useStyleSheet(fragmentManager);
|
|
1850
|
+
const events = useLayerInteractions(layerKey, options);
|
|
1851
|
+
if (collectStyle) {
|
|
1852
|
+
addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
|
|
1853
|
+
}
|
|
1854
|
+
return {
|
|
1855
|
+
hash,
|
|
1856
|
+
events,
|
|
1857
|
+
styles,
|
|
1858
|
+
classnames,
|
|
1859
|
+
content,
|
|
1860
|
+
highlight
|
|
1861
|
+
};
|
|
1862
|
+
};
|
|
1863
|
+
const Text = ({
|
|
1864
|
+
layerKey,
|
|
1865
|
+
Tag = "div",
|
|
1866
|
+
collectStyle,
|
|
1867
|
+
...restProps
|
|
1868
|
+
}) => {
|
|
1869
|
+
const { classnames, content, events, hash, highlight } = useTextAttributes(
|
|
1870
|
+
layerKey,
|
|
1871
|
+
{
|
|
1872
|
+
collectStyle
|
|
1873
|
+
}
|
|
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
|
+
] });
|
|
1891
|
+
};
|
|
1768
1892
|
const useFrame = (layerKey, options) => {
|
|
1769
1893
|
const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
|
|
1770
1894
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
@@ -1844,29 +1968,36 @@ const Collection = ({
|
|
|
1844
1968
|
"data-key": layerKey,
|
|
1845
1969
|
style: resultStyles,
|
|
1846
1970
|
...restProps,
|
|
1847
|
-
children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (
|
|
1848
|
-
|
|
1971
|
+
children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItemLinkKey) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1972
|
+
react$1.GraphValue,
|
|
1849
1973
|
{
|
|
1850
|
-
fragmentManager,
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
source,
|
|
1855
|
-
sourceDefinition,
|
|
1856
|
-
value: collectionItem,
|
|
1857
|
-
manager: fragmentManager
|
|
1858
|
-
},
|
|
1859
|
-
children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1860
|
-
"div",
|
|
1974
|
+
graphState: fragmentManager,
|
|
1975
|
+
field: collectionItemLinkKey,
|
|
1976
|
+
children: (value) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1977
|
+
Scope,
|
|
1861
1978
|
{
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1979
|
+
fragmentManager,
|
|
1980
|
+
layerKey: collectionItemLinkKey,
|
|
1981
|
+
value: {
|
|
1982
|
+
type: definition.definition.scopeTypes.CollectionItemScope,
|
|
1983
|
+
source,
|
|
1984
|
+
sourceDefinition,
|
|
1985
|
+
value,
|
|
1986
|
+
manager: fragmentManager
|
|
1865
1987
|
},
|
|
1866
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
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
|
+
)
|
|
1870
2001
|
}
|
|
1871
2002
|
))
|
|
1872
2003
|
}
|
|
@@ -2137,30 +2268,61 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2137
2268
|
);
|
|
2138
2269
|
const { manager: fragmentContextManager } = react.useContext(FragmentContext);
|
|
2139
2270
|
const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
|
|
2140
|
-
const
|
|
2271
|
+
const { readVariable } = useReadVariable();
|
|
2141
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);
|
|
2142
2287
|
const [instanceLayer] = react$1.useGraph(fragmentManager, instanceProps.layerKey);
|
|
2143
2288
|
const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
|
|
2289
|
+
const [localProps, setLocalProps] = react.useState(instanceProps.props ?? {});
|
|
2144
2290
|
const mergedProps = react.useMemo(() => {
|
|
2145
2291
|
let base = instanceLayerProps;
|
|
2146
|
-
if (isTopInstance && utils.isObject(base) && utils.isObject(
|
|
2292
|
+
if (isTopInstance && utils.isObject(base) && utils.isObject(localProps)) {
|
|
2147
2293
|
base = {
|
|
2148
2294
|
...base,
|
|
2149
|
-
...
|
|
2295
|
+
...localProps
|
|
2150
2296
|
};
|
|
2151
2297
|
}
|
|
2152
2298
|
if (isTopInstance && fragmentManager) {
|
|
2153
2299
|
definitionsData.forEach((definition2) => {
|
|
2154
|
-
var _a;
|
|
2155
2300
|
const defId = definition2._id;
|
|
2156
|
-
base[defId] = (
|
|
2301
|
+
base[defId] = (localProps == null ? void 0 : localProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
|
|
2157
2302
|
});
|
|
2158
2303
|
}
|
|
2159
2304
|
return utils.omit(base, "_type", "_id");
|
|
2160
|
-
}, [
|
|
2305
|
+
}, [
|
|
2306
|
+
isTopInstance,
|
|
2307
|
+
fragmentManager,
|
|
2308
|
+
instanceLayerProps,
|
|
2309
|
+
definitionsData,
|
|
2310
|
+
localProps,
|
|
2311
|
+
readVariable
|
|
2312
|
+
]);
|
|
2313
|
+
react.useEffect(() => {
|
|
2314
|
+
if (utils.isValue(instanceProps == null ? void 0 : instanceProps.props)) {
|
|
2315
|
+
setLocalProps(instanceProps.props);
|
|
2316
|
+
}
|
|
2317
|
+
}, [instanceProps == null ? void 0 : instanceProps.props]);
|
|
2161
2318
|
return {
|
|
2162
2319
|
props: mergedProps,
|
|
2163
|
-
cssProps: getCssVariables(mergedProps)
|
|
2320
|
+
cssProps: getCssVariables(mergedProps),
|
|
2321
|
+
onChangeProps: (variableId, value) => {
|
|
2322
|
+
var _a;
|
|
2323
|
+
setLocalProps((prev) => ({ ...prev, [variableId]: value }));
|
|
2324
|
+
(_a = instanceProps == null ? void 0 : instanceProps.onChangeProps) == null ? void 0 : _a.call(instanceProps, variableId, value);
|
|
2325
|
+
}
|
|
2164
2326
|
};
|
|
2165
2327
|
};
|
|
2166
2328
|
const useInstance = (instanceProps) => {
|
|
@@ -2173,7 +2335,7 @@ const useInstance = (instanceProps) => {
|
|
|
2173
2335
|
);
|
|
2174
2336
|
const resultFragmentId = (instanceProps == null ? void 0 : instanceProps.fragmentId) ?? (instanceLayer == null ? void 0 : instanceLayer.fragment);
|
|
2175
2337
|
const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(resultFragmentId);
|
|
2176
|
-
const { props, cssProps } = useInstanceProps(instanceProps);
|
|
2338
|
+
const { props, cssProps, onChangeProps } = useInstanceProps(instanceProps);
|
|
2177
2339
|
const classnames = useClassnames(
|
|
2178
2340
|
instanceProps.layerKey,
|
|
2179
2341
|
innerFragmentManager
|
|
@@ -2188,7 +2350,8 @@ const useInstance = (instanceProps) => {
|
|
|
2188
2350
|
parentManager,
|
|
2189
2351
|
innerManager: innerFragmentManager,
|
|
2190
2352
|
fragmentId: resultFragmentId,
|
|
2191
|
-
globalManager: resultGlobalManager
|
|
2353
|
+
globalManager: resultGlobalManager,
|
|
2354
|
+
onChangeProps
|
|
2192
2355
|
};
|
|
2193
2356
|
};
|
|
2194
2357
|
const InstanceInitial = ({
|
|
@@ -2211,7 +2374,8 @@ const InstanceInitial = ({
|
|
|
2211
2374
|
classnames,
|
|
2212
2375
|
innerManager,
|
|
2213
2376
|
definitions,
|
|
2214
|
-
globalManager
|
|
2377
|
+
globalManager,
|
|
2378
|
+
onChangeProps
|
|
2215
2379
|
} = useInstance({
|
|
2216
2380
|
...instanceProps,
|
|
2217
2381
|
pauseInteractions
|
|
@@ -2230,7 +2394,8 @@ const InstanceInitial = ({
|
|
|
2230
2394
|
definitions,
|
|
2231
2395
|
fragmentId,
|
|
2232
2396
|
documentManager: innerManager,
|
|
2233
|
-
layerKey: instanceProps.layerKey
|
|
2397
|
+
layerKey: instanceProps.layerKey,
|
|
2398
|
+
onChangeProps
|
|
2234
2399
|
},
|
|
2235
2400
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2236
2401
|
InstanceContext$1.Provider,
|
|
@@ -2399,6 +2564,7 @@ exports.getAllParents = getAllParents;
|
|
|
2399
2564
|
exports.getCssVariables = getCssVariables;
|
|
2400
2565
|
exports.getHydratedData = getHydratedData;
|
|
2401
2566
|
exports.getKey = getKey;
|
|
2567
|
+
exports.getNormalizeLayer = getNormalizeLayer;
|
|
2402
2568
|
exports.getOverrider = getOverrider;
|
|
2403
2569
|
exports.getOverriderByLayers = getOverriderByLayers;
|
|
2404
2570
|
exports.getParent = getParent;
|
|
@@ -2457,6 +2623,8 @@ exports.useNormalizeLayer = useNormalizeLayer;
|
|
|
2457
2623
|
exports.useOptionalSize = useOptionalSize;
|
|
2458
2624
|
exports.useReadVariable = useReadVariable;
|
|
2459
2625
|
exports.useReadVariables = useReadVariables;
|
|
2626
|
+
exports.useRenderTarget = useRenderTarget;
|
|
2460
2627
|
exports.useTextAttributes = useTextAttributes;
|
|
2461
2628
|
exports.useTextContent = useTextContent;
|
|
2629
|
+
exports.useTextHighlight = useTextHighlight;
|
|
2462
2630
|
exports.wrapTextInParagraphWithAttributes = wrapTextInParagraphWithAttributes;
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|