@fragmentsx/render-react 1.3.0 → 1.5.0
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/useFragment.d.ts.map +1 -1
- package/dist/hooks/fragment/useFragmentManager.d.ts +1 -1
- package/dist/hooks/fragment/useFragmentManager.d.ts.map +1 -1
- package/dist/hooks/layer/index.d.ts +2 -0
- package/dist/hooks/layer/index.d.ts.map +1 -1
- package/dist/hooks/layer/useReadVariable.d.ts +1 -0
- package/dist/hooks/layer/useReadVariable.d.ts.map +1 -1
- package/dist/hooks/layer/useResolvedLayer.d.ts +14 -0
- package/dist/hooks/layer/useResolvedLayer.d.ts.map +1 -0
- package/dist/hooks/layer/useResolvedLayerVariables.d.ts +7 -0
- package/dist/hooks/layer/useResolvedLayerVariables.d.ts.map +1 -0
- package/dist/hooks/layer-styles/useLayerPaint.d.ts +8 -0
- package/dist/hooks/layer-styles/useLayerPaint.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/index.d.ts +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/index.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useImagePaint.d.ts +6 -0
- package/dist/hooks/layer-styles/useLayerStyles/useImagePaint.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerBackground.d.ts +4 -2
- package/dist/hooks/layer-styles/useLayerStyles/useLayerBackground.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerBorder.d.ts +16 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerBorder.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerDisplay.d.ts +2 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerDisplay.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerFlex.d.ts +4 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerFlex.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerLayout.d.ts +10 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerLayout.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerPosition.d.ts +36 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerPosition.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerSize.d.ts +7 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerSize.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerSizeValue.d.ts +9 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerSizeValue.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerTextStyles.d.ts +4 -0
- package/dist/hooks/layer-styles/useLayerStyles/useLayerTextStyles.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useOptionalSize.d.ts +2 -0
- package/dist/hooks/layer-styles/useLayerStyles/useOptionalSize.d.ts.map +1 -1
- package/dist/hooks/utils/useExtractProps.d.ts +16 -0
- package/dist/hooks/utils/useExtractProps.d.ts.map +1 -0
- package/dist/hooks/utils/useLayerInteractions.d.ts.map +1 -1
- package/dist/index.cjs.js +1457 -706
- package/dist/index.es.js +1460 -709
- package/dist/nodes/Area/Area.d.ts.map +1 -1
- package/dist/nodes/Area/hooks/useArea.d.ts +2 -7
- package/dist/nodes/Area/hooks/useArea.d.ts.map +1 -1
- package/dist/nodes/Area/hooks/useArea.test.d.ts +2 -0
- package/dist/nodes/Area/hooks/useArea.test.d.ts.map +1 -0
- package/dist/nodes/Area/hooks/useArea.types.d.ts +22 -0
- package/dist/nodes/Area/hooks/useArea.types.d.ts.map +1 -0
- package/dist/nodes/Area/hooks/useAsyncLoadArea.d.ts +15 -0
- package/dist/nodes/Area/hooks/useAsyncLoadArea.d.ts.map +1 -0
- package/dist/nodes/Area/hooks/useAsyncLoadArea.test.d.ts +2 -0
- package/dist/nodes/Area/hooks/useAsyncLoadArea.test.d.ts.map +1 -0
- package/dist/nodes/Area/index.d.ts +1 -0
- package/dist/nodes/Area/index.d.ts.map +1 -1
- package/dist/nodes/Collection/hooks/useCollection.d.ts +1 -1
- package/dist/nodes/Collection/hooks/useCollection.d.ts.map +1 -1
- package/dist/nodes/CollectionItem/CollectionItem.d.ts.map +1 -1
- package/dist/nodes/CollectionItem/hooks/useCollection.d.ts +1 -1
- package/dist/nodes/CssChunk/hooks/useCssChunk.d.ts.map +1 -1
- package/dist/nodes/Fragment/Fragment.d.ts.map +1 -1
- package/dist/nodes/Frame/hooks/useFrame.d.ts +1 -1
- package/dist/nodes/Instance/Instance.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstance.d.ts +1 -1
- package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
- package/dist/nodes/Instance/test/array-linking.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/array-linking.browser.test.d.ts.map +1 -0
- package/dist/nodes/Instance/test/cardDocuments.d.ts +39 -0
- package/dist/nodes/Instance/test/cardDocuments.d.ts.map +1 -0
- package/dist/nodes/Instance/test/collection-props.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/collection-props.browser.test.d.ts.map +1 -0
- package/dist/nodes/Instance/test/collection-schema.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/collection-schema.browser.test.d.ts.map +1 -0
- package/dist/nodes/Instance/test/props-basic.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/props-basic.browser.test.d.ts.map +1 -0
- package/dist/nodes/Instance/test/props-drilling.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/props-drilling.browser.test.d.ts.map +1 -0
- package/dist/nodes/Instance/test/props-dynamic.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/props-dynamic.browser.test.d.ts.map +1 -0
- package/dist/nodes/Text/hooks/useTextAttributes.d.ts +1 -1
- package/dist/providers/AreaManager.d.ts +3 -0
- package/dist/providers/AreaManager.d.ts.map +1 -0
- package/dist/providers/Scope/index.d.ts.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/utils/common/index.d.ts +0 -1
- package/dist/utils/common/index.d.ts.map +1 -1
- package/dist/utils/css/buildCssBlock.d.ts +6 -0
- package/dist/utils/css/buildCssBlock.d.ts.map +1 -0
- package/dist/utils/css/buildCssBlock.test.d.ts +2 -0
- package/dist/utils/css/buildCssBlock.test.d.ts.map +1 -0
- package/dist/utils/css/compareRules.d.ts +3 -0
- package/dist/utils/css/compareRules.d.ts.map +1 -0
- package/dist/utils/css/compareRules.test.d.ts +2 -0
- package/dist/utils/css/compareRules.test.d.ts.map +1 -0
- package/dist/utils/css/extractStyleSheet.d.ts +6 -0
- package/dist/utils/css/extractStyleSheet.d.ts.map +1 -0
- package/dist/utils/css/findGroups.d.ts +11 -0
- package/dist/utils/css/findGroups.d.ts.map +1 -0
- package/dist/utils/css/getAllChildren.d.ts +4 -0
- package/dist/utils/css/getAllChildren.d.ts.map +1 -0
- package/dist/utils/css/getAllChildren.test.d.ts +2 -0
- package/dist/utils/css/getAllChildren.test.d.ts.map +1 -0
- package/dist/utils/css/index.d.ts +12 -0
- package/dist/utils/css/index.d.ts.map +1 -0
- package/dist/utils/css/makeCss.d.ts +5 -0
- package/dist/utils/css/makeCss.d.ts.map +1 -0
- package/dist/utils/css/toCSS.d.ts +3 -0
- package/dist/utils/css/toCSS.d.ts.map +1 -0
- package/dist/utils/css/toCSS.test.d.ts +2 -0
- package/dist/utils/css/toCSS.test.d.ts.map +1 -0
- package/dist/utils/css/types.d.ts +5 -0
- package/dist/utils/css/types.d.ts.map +1 -0
- package/dist/utils/layer/cloneLayer.d.ts.map +1 -1
- package/dist/utils/variables/index.d.ts +0 -1
- package/dist/utils/variables/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/hooks/utils/useExpandedObjectProps.d.ts +0 -12
- package/dist/hooks/utils/useExpandedObjectProps.d.ts.map +0 -1
- package/dist/utils/common/loadFragmentManager.d.ts +0 -3
- package/dist/utils/common/loadFragmentManager.d.ts.map +0 -1
- package/dist/utils/variables/expandObjectProps.d.ts +0 -9
- package/dist/utils/variables/expandObjectProps.d.ts.map +0 -1
- package/dist/utils/variables/expandObjectProps.test.d.ts +0 -2
- package/dist/utils/variables/expandObjectProps.test.d.ts.map +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { createContext, useContext, useReducer, useRef, useEffect, useCallback,
|
|
2
|
-
import { definition, getNormalizeLayer as getNormalizeLayer$1, isVariableLink as isVariableLink$1, parseLayerField } from "@fragmentsx/definition";
|
|
1
|
+
import { createContext, useContext, useMemo, useReducer, useRef, useEffect, useCallback, useState, memo, Suspense } from "react";
|
|
2
|
+
import { definition, getNormalizeLayer as getNormalizeLayer$1, isVariableLink as isVariableLink$1, parseLayerField, isLink as isLink$1 } from "@fragmentsx/definition";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { cleanGraph, generateId, getKey as getKey$1, isValue, isObject, pick, toPx, setKey as setKey$1, toKebabCase, set, isPrimitive, get, omit, noop, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
|
|
5
|
+
import { keyOfEntity, isPartialKey, entityOfKey, isLinkKey } from "@graph-state/core";
|
|
4
6
|
import { useGraph, useGraphStack } from "@graph-state/react";
|
|
5
|
-
import {
|
|
6
|
-
import { entityOfKey, keyOfEntity, isPartialKey, isLinkKey } from "@graph-state/core";
|
|
7
|
+
import { createAreaManager } from "@fragmentsx/client-core";
|
|
7
8
|
const GlobalManagerContext = createContext(null);
|
|
8
9
|
const GlobalManagerProvider = GlobalManagerContext.Provider;
|
|
9
10
|
const FragmentContext = createContext({
|
|
@@ -22,35 +23,9 @@ const RenderTargetContext = createContext(
|
|
|
22
23
|
definition.renderTarget.document
|
|
23
24
|
);
|
|
24
25
|
const RenderTargetProvider = RenderTargetContext.Provider;
|
|
26
|
+
const AreaManagerContext = createContext(null);
|
|
27
|
+
const AreaManagerProvider = AreaManagerContext.Provider;
|
|
25
28
|
const ScopeContext = createContext([]);
|
|
26
|
-
const useGlobalManager = (globalManager) => {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
const currentGlobalManager = useContext(GlobalManagerContext);
|
|
29
|
-
const resultManager = globalManager ?? currentGlobalManager;
|
|
30
|
-
const [fragmentsGraph] = useGraph(
|
|
31
|
-
resultManager,
|
|
32
|
-
(_a = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _a.key
|
|
33
|
-
);
|
|
34
|
-
const queryFragmentManager = (id) => {
|
|
35
|
-
var _a2, _b2;
|
|
36
|
-
return (_b2 = (_a2 = resultManager == null ? void 0 : resultManager.$load) == null ? void 0 : _a2.loadFragment) == null ? void 0 : _b2.call(_a2, id);
|
|
37
|
-
};
|
|
38
|
-
const queryArea = (id) => {
|
|
39
|
-
var _a2, _b2;
|
|
40
|
-
return (_b2 = (_a2 = resultManager == null ? void 0 : resultManager.$load) == null ? void 0 : _a2.loadArea) == null ? void 0 : _b2.call(_a2, id);
|
|
41
|
-
};
|
|
42
|
-
const setRenderTarget = (value) => {
|
|
43
|
-
resultManager == null ? void 0 : resultManager.setRenderTarget(value);
|
|
44
|
-
};
|
|
45
|
-
return {
|
|
46
|
-
fragmentsGraph,
|
|
47
|
-
manager: resultManager,
|
|
48
|
-
queryFragmentManager,
|
|
49
|
-
queryArea,
|
|
50
|
-
getFragmentManager: ((_b = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _b.getManager) ?? noop,
|
|
51
|
-
setRenderTarget
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
29
|
const Scope = ({
|
|
55
30
|
value,
|
|
56
31
|
children,
|
|
@@ -58,9 +33,11 @@ const Scope = ({
|
|
|
58
33
|
layerKey
|
|
59
34
|
}) => {
|
|
60
35
|
var _a, _b;
|
|
61
|
-
const { manager: globalManager } = useGlobalManager();
|
|
62
36
|
const currentScope = useContext(ScopeContext) ?? [];
|
|
63
|
-
const nextScope =
|
|
37
|
+
const nextScope = useMemo(
|
|
38
|
+
() => [...currentScope, value],
|
|
39
|
+
[currentScope, value]
|
|
40
|
+
);
|
|
64
41
|
(_b = (_a = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a.registerScope) == null ? void 0 : _b.call(_a, layerKey, value);
|
|
65
42
|
return /* @__PURE__ */ jsx(ScopeContext.Provider, { value: nextScope, children });
|
|
66
43
|
};
|
|
@@ -71,191 +48,6 @@ const getOverrider = (manager, layerEntity) => {
|
|
|
71
48
|
const layer = manager.resolve(layerEntity);
|
|
72
49
|
return manager.resolve(getKey(layer == null ? void 0 : layer.overrideFrom) ?? layerEntity);
|
|
73
50
|
};
|
|
74
|
-
const getLayer = (manager, layer, options) => {
|
|
75
|
-
if (!manager || !layer) return null;
|
|
76
|
-
const layerKey = manager.keyOfEntity(layer);
|
|
77
|
-
const layerData = manager.resolve(layerKey);
|
|
78
|
-
const overrider = getOverrider(manager, layerKey);
|
|
79
|
-
return getNormalizeLayer$1(layerData, overrider, options == null ? void 0 : options.withFallback);
|
|
80
|
-
};
|
|
81
|
-
const getNormalizeLayer = (layerKey, manager, options) => {
|
|
82
|
-
const layer = manager == null ? void 0 : manager.resolve(layerKey);
|
|
83
|
-
const parsedLayer = getLayer(manager, layerKey, options);
|
|
84
|
-
return {
|
|
85
|
-
layerKey,
|
|
86
|
-
rawLayer: layer,
|
|
87
|
-
layer: parsedLayer
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
const useNormalizeLayer = (layerKey, manager, options) => {
|
|
91
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
92
|
-
const resultManager = manager ?? fragmentManager;
|
|
93
|
-
if (!resultManager) {
|
|
94
|
-
return {
|
|
95
|
-
layerKey,
|
|
96
|
-
rawLayer: null,
|
|
97
|
-
layer: null
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return getNormalizeLayer(layerKey, resultManager, options);
|
|
101
|
-
};
|
|
102
|
-
const useNormalizeLayers = (layerKeys, manager, options) => {
|
|
103
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
104
|
-
const resultManager = manager ?? fragmentManager;
|
|
105
|
-
return layerKeys.map(
|
|
106
|
-
(layerKey) => getNormalizeLayer(layerKey, resultManager, options)
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
function useForceUpdate() {
|
|
110
|
-
return useReducer(() => ({}), {});
|
|
111
|
-
}
|
|
112
|
-
const extractVariableValue = (input, variableId) => {
|
|
113
|
-
if (isObject(input)) {
|
|
114
|
-
if (variableId in input) {
|
|
115
|
-
return input[variableId];
|
|
116
|
-
}
|
|
117
|
-
for (let key in input) {
|
|
118
|
-
if (input.hasOwnProperty(key)) {
|
|
119
|
-
const result = extractVariableValue(input[key], variableId);
|
|
120
|
-
if (result !== void 0) {
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return void 0;
|
|
127
|
-
};
|
|
128
|
-
function deepMerge(a, b) {
|
|
129
|
-
if (!isObject(a) || !isObject(b)) return a;
|
|
130
|
-
const result = { ...b };
|
|
131
|
-
for (const [key, value] of Object.entries(a)) {
|
|
132
|
-
if (key in result && typeof result[key] === "object" && typeof value === "object") {
|
|
133
|
-
result[key] = deepMerge(value, result[key]);
|
|
134
|
-
} else {
|
|
135
|
-
result[key] = value;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
const useReadVariable = (variableKey, customScopes) => {
|
|
141
|
-
const contextScopes = useContext(ScopeContext);
|
|
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
|
-
);
|
|
152
|
-
const extractVariableDefaultValue = (manager, variableEntity) => {
|
|
153
|
-
const variableLayer = manager.resolve(variableEntity);
|
|
154
|
-
if ((variableLayer == null ? void 0 : variableLayer.type) !== definition.variableType.Object)
|
|
155
|
-
return variableLayer == null ? void 0 : variableLayer.defaultValue;
|
|
156
|
-
return Object.values((variableLayer == null ? void 0 : variableLayer.fields) ?? {}).reduce(
|
|
157
|
-
(acc, fieldLink) => {
|
|
158
|
-
var _a;
|
|
159
|
-
if (!!fieldLink && isVariableLink$1(fieldLink)) {
|
|
160
|
-
const _id = (_a = entityOfKey(fieldLink)) == null ? void 0 : _a._id;
|
|
161
|
-
if (_id) {
|
|
162
|
-
acc[_id] = extractVariableDefaultValue(manager, fieldLink);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return acc;
|
|
166
|
-
},
|
|
167
|
-
{}
|
|
168
|
-
);
|
|
169
|
-
};
|
|
170
|
-
const resolveVariableLayer = (manager, variableLink, customProps) => {
|
|
171
|
-
var _a, _b;
|
|
172
|
-
const variableLayer = (_a = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a.layer;
|
|
173
|
-
if (!variableLayer) return null;
|
|
174
|
-
if ((variableLayer == null ? void 0 : variableLayer.type) === definition.variableType.Array) {
|
|
175
|
-
const definitionLayer = manager.resolve(variableLayer == null ? void 0 : variableLayer.definition);
|
|
176
|
-
if (!((_b = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _b.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
|
|
177
|
-
return variableLayer;
|
|
178
|
-
const definitionDefaultValue = extractVariableDefaultValue(
|
|
179
|
-
manager,
|
|
180
|
-
definitionLayer
|
|
181
|
-
);
|
|
182
|
-
const customValue = customProps == null ? void 0 : customProps[variableLayer == null ? void 0 : variableLayer._id];
|
|
183
|
-
return {
|
|
184
|
-
...variableLayer,
|
|
185
|
-
defaultValue: (variableLayer == null ? void 0 : variableLayer.defaultValue).map((item, index) => {
|
|
186
|
-
const customItemValue = Array.isArray(customValue) ? customValue.at(index) : null;
|
|
187
|
-
return deepMerge(
|
|
188
|
-
customItemValue ? { ...item, ...customItemValue } : item,
|
|
189
|
-
definitionDefaultValue
|
|
190
|
-
);
|
|
191
|
-
})
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return variableLayer;
|
|
195
|
-
};
|
|
196
|
-
const readVariable = (variableKey2) => {
|
|
197
|
-
var _a, _b, _c, _d, _e;
|
|
198
|
-
const variableId = (_a = entityOfKey(variableKey2)) == null ? void 0 : _a._id;
|
|
199
|
-
if (!isVariableLink$1(variableKey2)) {
|
|
200
|
-
return {
|
|
201
|
-
value: null,
|
|
202
|
-
layer: null
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
let instanceScope = scopes.findLast(
|
|
206
|
-
(scope) => {
|
|
207
|
-
var _a2;
|
|
208
|
-
return (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope && !!((_a2 = scope.documentManager) == null ? void 0 : _a2.resolve(variableKey2));
|
|
209
|
-
}
|
|
210
|
-
);
|
|
211
|
-
if (!instanceScope) {
|
|
212
|
-
instanceScope = scopes.find(
|
|
213
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
const variableLayer = resolveVariableLayer(
|
|
217
|
-
instanceScope == null ? void 0 : instanceScope.documentManager,
|
|
218
|
-
variableKey2
|
|
219
|
-
);
|
|
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];
|
|
224
|
-
if (Array.isArray(instanceProp)) {
|
|
225
|
-
instanceProp = instanceProp.map(
|
|
226
|
-
(rawProp, index) => {
|
|
227
|
-
var _a2;
|
|
228
|
-
return deepMerge(rawProp, (_a2 = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a2.at(index));
|
|
229
|
-
}
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
const lastCollectionItem = scopes.findLast(
|
|
233
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
|
|
234
|
-
);
|
|
235
|
-
resolveVariableLayer(
|
|
236
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.manager,
|
|
237
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
|
|
238
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.value
|
|
239
|
-
);
|
|
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);
|
|
241
|
-
const currentValue = variableKey2 === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
|
|
242
|
-
const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
|
|
243
|
-
const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
|
|
244
|
-
const resultValue = required ? currentValue : currentValue ?? collectionItemProp ?? defaultValue;
|
|
245
|
-
if (isVariableLink$1(resultValue)) {
|
|
246
|
-
return readVariable(resultValue);
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
value: resultValue,
|
|
250
|
-
layer: variableLayer
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
const result = readVariable(variableKey);
|
|
254
|
-
return {
|
|
255
|
-
...result,
|
|
256
|
-
readVariable
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
51
|
const getParent = (manager, layerKey) => {
|
|
260
52
|
const layer = manager.resolve(layerKey);
|
|
261
53
|
return manager.resolve(getKey(layer == null ? void 0 : layer.parent) ?? null);
|
|
@@ -431,6 +223,9 @@ const cloneLayer = (manager, layer, externalProps = {}) => {
|
|
|
431
223
|
layerGraph,
|
|
432
224
|
(key, value, history) => {
|
|
433
225
|
const isRoot = history.length <= 2;
|
|
226
|
+
if ((value == null ? void 0 : value._type) === definition.nodes.Instance && key === "props") {
|
|
227
|
+
return cleanGraph(value);
|
|
228
|
+
}
|
|
434
229
|
if (!!value && n(value) && !IGNORE_TYPES.includes(value._type)) {
|
|
435
230
|
const nextId = generateId();
|
|
436
231
|
const parentFromValue = getKey$1(value.parent);
|
|
@@ -667,6 +462,41 @@ const moveChildren = (manager, targetKey, to, index) => {
|
|
|
667
462
|
spliceChildren(manager, targetParent, targetKey);
|
|
668
463
|
}
|
|
669
464
|
};
|
|
465
|
+
const getLayer = (manager, layer, options) => {
|
|
466
|
+
if (!manager || !layer) return null;
|
|
467
|
+
const layerKey = manager.keyOfEntity(layer);
|
|
468
|
+
const layerData = manager.resolve(layerKey);
|
|
469
|
+
const overrider = getOverrider(manager, layerKey);
|
|
470
|
+
return getNormalizeLayer$1(layerData, overrider, options == null ? void 0 : options.withFallback);
|
|
471
|
+
};
|
|
472
|
+
const getNormalizeLayer = (layerKey, manager, options) => {
|
|
473
|
+
const layer = manager == null ? void 0 : manager.resolve(layerKey);
|
|
474
|
+
const parsedLayer = getLayer(manager, layerKey, options);
|
|
475
|
+
return {
|
|
476
|
+
layerKey,
|
|
477
|
+
rawLayer: layer,
|
|
478
|
+
layer: parsedLayer
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
const useNormalizeLayer = (layerKey, manager, options) => {
|
|
482
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
483
|
+
const resultManager = manager ?? fragmentManager;
|
|
484
|
+
if (!resultManager) {
|
|
485
|
+
return {
|
|
486
|
+
layerKey,
|
|
487
|
+
rawLayer: null,
|
|
488
|
+
layer: null
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
return getNormalizeLayer(layerKey, resultManager, options);
|
|
492
|
+
};
|
|
493
|
+
const useNormalizeLayers = (layerKeys, manager, options) => {
|
|
494
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
495
|
+
const resultManager = manager ?? fragmentManager;
|
|
496
|
+
return layerKeys.map(
|
|
497
|
+
(layerKey) => getNormalizeLayer(layerKey, resultManager, options)
|
|
498
|
+
);
|
|
499
|
+
};
|
|
670
500
|
const calcBackground = (manager, layerKey) => {
|
|
671
501
|
manager.resolve(layerKey);
|
|
672
502
|
const { layer } = getNormalizeLayer(layerKey, manager);
|
|
@@ -802,111 +632,15 @@ const toCssCustomProperties = (props) => {
|
|
|
802
632
|
{}
|
|
803
633
|
);
|
|
804
634
|
};
|
|
805
|
-
const
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
635
|
+
const declareFragmentProperty = (manager, property, fragmentLink = manager.$fragment.root) => {
|
|
636
|
+
const propertyLayer = createLayer(property);
|
|
637
|
+
if (propertyLayer && "type" in propertyLayer) {
|
|
638
|
+
manager.mutate(manager.keyOfEntity(fragmentLink), {
|
|
639
|
+
properties: [propertyLayer]
|
|
640
|
+
});
|
|
641
|
+
return manager.keyOfEntity(propertyLayer);
|
|
811
642
|
}
|
|
812
|
-
return
|
|
813
|
-
};
|
|
814
|
-
const toVariableLink = (field) => {
|
|
815
|
-
if (isVariableLink$1(field)) {
|
|
816
|
-
return field;
|
|
817
|
-
}
|
|
818
|
-
if (isObject(field) && (field == null ? void 0 : field._type) && (field == null ? void 0 : field._id)) {
|
|
819
|
-
return keyOfEntity(field);
|
|
820
|
-
}
|
|
821
|
-
return void 0;
|
|
822
|
-
};
|
|
823
|
-
const expandConcreteValue = (objectVar, valueObj, childManager, result) => {
|
|
824
|
-
const fields = cleanGraph(objectVar.fields);
|
|
825
|
-
for (const [fieldName, childField] of Object.entries(fields)) {
|
|
826
|
-
if (!(fieldName in valueObj)) continue;
|
|
827
|
-
const childFieldVar = resolveFieldVar(childField, childManager);
|
|
828
|
-
if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
|
|
829
|
-
const fieldValue = valueObj[fieldName];
|
|
830
|
-
if (childFieldVar.type === definition.variableType.Object && childFieldVar.fields && isObject(fieldValue)) {
|
|
831
|
-
expandConcreteValue(
|
|
832
|
-
childFieldVar,
|
|
833
|
-
fieldValue,
|
|
834
|
-
childManager,
|
|
835
|
-
result
|
|
836
|
-
);
|
|
837
|
-
continue;
|
|
838
|
-
}
|
|
839
|
-
result[childFieldVar._id] = fieldValue;
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
const expandVariableValue = (childObjectVar, parentObjectVar, childManager, resolveManager, result) => {
|
|
843
|
-
const childFields = cleanGraph(childObjectVar.fields);
|
|
844
|
-
const parentFields = cleanGraph(parentObjectVar.fields);
|
|
845
|
-
for (const [fieldName, childField] of Object.entries(childFields)) {
|
|
846
|
-
const parentField = parentFields[fieldName];
|
|
847
|
-
if (!parentField) continue;
|
|
848
|
-
const childFieldVar = resolveFieldVar(childField, childManager);
|
|
849
|
-
if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
|
|
850
|
-
const parentFieldVar = resolveFieldVar(parentField, resolveManager);
|
|
851
|
-
if (childFieldVar.type === definition.variableType.Object && childFieldVar.fields && (parentFieldVar == null ? void 0 : parentFieldVar.type) === definition.variableType.Object && (parentFieldVar == null ? void 0 : parentFieldVar.fields)) {
|
|
852
|
-
expandVariableValue(
|
|
853
|
-
childFieldVar,
|
|
854
|
-
parentFieldVar,
|
|
855
|
-
childManager,
|
|
856
|
-
resolveManager,
|
|
857
|
-
result
|
|
858
|
-
);
|
|
859
|
-
continue;
|
|
860
|
-
}
|
|
861
|
-
const parentFieldLink = toVariableLink(parentField);
|
|
862
|
-
if (parentFieldLink) {
|
|
863
|
-
result[childFieldVar._id] = parentFieldLink;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
const expandObjectProps = (props, childManager, parentManager) => {
|
|
868
|
-
if (!childManager) return props;
|
|
869
|
-
const resolveManager = parentManager ?? childManager;
|
|
870
|
-
const result = {};
|
|
871
|
-
for (const [propKey, propValue] of Object.entries(props)) {
|
|
872
|
-
const childVarKey = `Variable:${propKey}`;
|
|
873
|
-
const childVar = childManager.resolve(childVarKey);
|
|
874
|
-
if ((childVar == null ? void 0 : childVar.type) === definition.variableType.Object && (childVar == null ? void 0 : childVar.fields)) {
|
|
875
|
-
if (isVariableLink$1(propValue)) {
|
|
876
|
-
const parentVar = resolveManager.resolve(propValue);
|
|
877
|
-
if ((parentVar == null ? void 0 : parentVar.type) === definition.variableType.Object && (parentVar == null ? void 0 : parentVar.fields)) {
|
|
878
|
-
expandVariableValue(
|
|
879
|
-
childVar,
|
|
880
|
-
parentVar,
|
|
881
|
-
childManager,
|
|
882
|
-
resolveManager,
|
|
883
|
-
result
|
|
884
|
-
);
|
|
885
|
-
continue;
|
|
886
|
-
}
|
|
887
|
-
} else if (isObject(propValue)) {
|
|
888
|
-
expandConcreteValue(
|
|
889
|
-
childVar,
|
|
890
|
-
propValue,
|
|
891
|
-
childManager,
|
|
892
|
-
result
|
|
893
|
-
);
|
|
894
|
-
continue;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
result[propKey] = propValue;
|
|
898
|
-
}
|
|
899
|
-
return result;
|
|
900
|
-
};
|
|
901
|
-
const declareFragmentProperty = (manager, property, fragmentLink = manager.$fragment.root) => {
|
|
902
|
-
const propertyLayer = createLayer(property);
|
|
903
|
-
if (propertyLayer && "type" in propertyLayer) {
|
|
904
|
-
manager.mutate(manager.keyOfEntity(fragmentLink), {
|
|
905
|
-
properties: [propertyLayer]
|
|
906
|
-
});
|
|
907
|
-
return manager.keyOfEntity(propertyLayer);
|
|
908
|
-
}
|
|
909
|
-
return null;
|
|
643
|
+
return null;
|
|
910
644
|
};
|
|
911
645
|
const getStylesheetKey = (fragmentKey) => {
|
|
912
646
|
const isLink2 = isLinkKey(fragmentKey);
|
|
@@ -949,22 +683,6 @@ function getHydratedData(id) {
|
|
|
949
683
|
return null;
|
|
950
684
|
}
|
|
951
685
|
}
|
|
952
|
-
const loadFragmentManager = async (globalManager, fragmentId) => {
|
|
953
|
-
var _a, _b;
|
|
954
|
-
const { document: document2, linkedFragments } = await ((_b = (_a = globalManager == null ? void 0 : globalManager.$fetch) == null ? void 0 : _a.queryFragment) == null ? void 0 : _b.call(_a, fragmentId));
|
|
955
|
-
if (fragmentId && document2) {
|
|
956
|
-
if (linkedFragments) {
|
|
957
|
-
linkedFragments.forEach(({ id, document: document22 }) => {
|
|
958
|
-
globalManager == null ? void 0 : globalManager.$fragments.createFragmentManager(id, document22);
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
return globalManager == null ? void 0 : globalManager.$fragments.createFragmentManager(
|
|
962
|
-
fragmentId,
|
|
963
|
-
document2
|
|
964
|
-
);
|
|
965
|
-
}
|
|
966
|
-
return null;
|
|
967
|
-
};
|
|
968
686
|
const createSuspenseResource = (key, valueOrPromise, cache) => {
|
|
969
687
|
if (cache.has(key)) return cache.get(key);
|
|
970
688
|
if (!(valueOrPromise instanceof Promise)) {
|
|
@@ -1120,6 +838,472 @@ const layerFieldSetter = (manager, layerKey, fieldKey, currentValue) => (value,
|
|
|
1120
838
|
);
|
|
1121
839
|
}
|
|
1122
840
|
};
|
|
841
|
+
const EMPTY_RESOLVED$1 = {
|
|
842
|
+
layerKey: null,
|
|
843
|
+
rawLayer: null,
|
|
844
|
+
layer: null,
|
|
845
|
+
isOverride: false
|
|
846
|
+
};
|
|
847
|
+
const useResolvedLayer = (layerKey, options) => {
|
|
848
|
+
const { manager } = useContext(FragmentContext);
|
|
849
|
+
const resultManager = (options == null ? void 0 : options.manager) ?? manager;
|
|
850
|
+
const key = keyOfEntity(layerKey);
|
|
851
|
+
useGraph(resultManager, key);
|
|
852
|
+
if (!resultManager || !key) {
|
|
853
|
+
return EMPTY_RESOLVED$1;
|
|
854
|
+
}
|
|
855
|
+
const rawLayer = resultManager.resolve(key);
|
|
856
|
+
const overrider = getOverrider(resultManager, key);
|
|
857
|
+
const layer = getNormalizeLayer$1(rawLayer, overrider, options == null ? void 0 : options.withFallback);
|
|
858
|
+
let isOverride = false;
|
|
859
|
+
if (!(options == null ? void 0 : options.skipOverrideCheck)) {
|
|
860
|
+
isOverride = !isPartOfPrimary(resultManager, key);
|
|
861
|
+
}
|
|
862
|
+
return { layerKey: key, rawLayer, layer, isOverride };
|
|
863
|
+
};
|
|
864
|
+
function useForceUpdate() {
|
|
865
|
+
return useReducer(() => ({}), {});
|
|
866
|
+
}
|
|
867
|
+
const EMPTY_RESOLVED = {
|
|
868
|
+
values: {},
|
|
869
|
+
cssVariableValues: {},
|
|
870
|
+
rawValues: {}
|
|
871
|
+
};
|
|
872
|
+
const extractVariableValue$1 = (input, variableId) => {
|
|
873
|
+
if (isObject(input)) {
|
|
874
|
+
if (variableId in input) return input[variableId];
|
|
875
|
+
for (const key in input) {
|
|
876
|
+
if (input.hasOwnProperty(key)) {
|
|
877
|
+
const result = extractVariableValue$1(input[key], variableId);
|
|
878
|
+
if (result !== void 0) return result;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return void 0;
|
|
883
|
+
};
|
|
884
|
+
function deepMerge$1(a, b) {
|
|
885
|
+
if (!isObject(a) || !isObject(b)) return a;
|
|
886
|
+
const result = { ...b };
|
|
887
|
+
for (const [key, value] of Object.entries(a)) {
|
|
888
|
+
if (key in result && typeof result[key] === "object" && typeof value === "object") {
|
|
889
|
+
result[key] = deepMerge$1(value, result[key]);
|
|
890
|
+
} else {
|
|
891
|
+
result[key] = value;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return result;
|
|
895
|
+
}
|
|
896
|
+
const useResolvedLayerVariables = (layer, rawLayer, customScopes) => {
|
|
897
|
+
var _a;
|
|
898
|
+
const contextScopes = useContext(ScopeContext);
|
|
899
|
+
const scopes = customScopes ?? contextScopes;
|
|
900
|
+
const subscriptions = useRef([]);
|
|
901
|
+
const [dep, forceUpdate] = useForceUpdate();
|
|
902
|
+
useEffect(() => {
|
|
903
|
+
const controller = new AbortController();
|
|
904
|
+
let ready = false;
|
|
905
|
+
const update = () => {
|
|
906
|
+
if (!ready) return;
|
|
907
|
+
forceUpdate();
|
|
908
|
+
};
|
|
909
|
+
for (const { manager, key } of subscriptions.current) {
|
|
910
|
+
manager.subscribe(key, update, { signal: controller.signal });
|
|
911
|
+
}
|
|
912
|
+
ready = true;
|
|
913
|
+
return () => controller.abort();
|
|
914
|
+
});
|
|
915
|
+
if (!layer) {
|
|
916
|
+
subscriptions.current = [];
|
|
917
|
+
return EMPTY_RESOLVED;
|
|
918
|
+
}
|
|
919
|
+
const values = {};
|
|
920
|
+
const cssVariableValues = {};
|
|
921
|
+
const rawValues = {};
|
|
922
|
+
const readVariable = (variableKey) => {
|
|
923
|
+
var _a2, _b, _c;
|
|
924
|
+
const variableId = (_a2 = entityOfKey(variableKey)) == null ? void 0 : _a2._id;
|
|
925
|
+
if (!isVariableLink$1(variableKey)) {
|
|
926
|
+
return { value: null, layer: null };
|
|
927
|
+
}
|
|
928
|
+
let instanceScope = scopes.findLast(
|
|
929
|
+
(scope) => {
|
|
930
|
+
var _a3;
|
|
931
|
+
return (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope && !!((_a3 = scope.documentManager) == null ? void 0 : _a3.resolve(variableKey));
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
if (!instanceScope) {
|
|
935
|
+
instanceScope = scopes.find(
|
|
936
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
const resolveVariableLayer = (manager, variableLink, customProps) => {
|
|
940
|
+
var _a3, _b2;
|
|
941
|
+
const variableLayer2 = (_a3 = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a3.layer;
|
|
942
|
+
if (!variableLayer2) return null;
|
|
943
|
+
if ((variableLayer2 == null ? void 0 : variableLayer2.type) === definition.variableType.Array) {
|
|
944
|
+
const definitionLayer = manager.resolve(variableLayer2 == null ? void 0 : variableLayer2.definition);
|
|
945
|
+
if (!((_b2 = variableLayer2 == null ? void 0 : variableLayer2.defaultValue) == null ? void 0 : _b2.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
|
|
946
|
+
return variableLayer2;
|
|
947
|
+
const extractVariableDefaultValue = (mgr, varEntity) => {
|
|
948
|
+
const varLayer = mgr.resolve(varEntity);
|
|
949
|
+
if ((varLayer == null ? void 0 : varLayer.type) !== definition.variableType.Object)
|
|
950
|
+
return varLayer == null ? void 0 : varLayer.defaultValue;
|
|
951
|
+
return Object.values((varLayer == null ? void 0 : varLayer.fields) ?? {}).reduce(
|
|
952
|
+
(acc, fieldLink) => {
|
|
953
|
+
var _a4;
|
|
954
|
+
if (!!fieldLink && isVariableLink$1(fieldLink)) {
|
|
955
|
+
const _id = (_a4 = entityOfKey(fieldLink)) == null ? void 0 : _a4._id;
|
|
956
|
+
if (_id) acc[_id] = extractVariableDefaultValue(mgr, fieldLink);
|
|
957
|
+
}
|
|
958
|
+
return acc;
|
|
959
|
+
},
|
|
960
|
+
{}
|
|
961
|
+
);
|
|
962
|
+
};
|
|
963
|
+
const definitionDefaultValue = extractVariableDefaultValue(
|
|
964
|
+
manager,
|
|
965
|
+
definitionLayer
|
|
966
|
+
);
|
|
967
|
+
const customValue = customProps == null ? void 0 : customProps[variableLayer2 == null ? void 0 : variableLayer2._id];
|
|
968
|
+
return {
|
|
969
|
+
...variableLayer2,
|
|
970
|
+
defaultValue: variableLayer2.defaultValue.map(
|
|
971
|
+
(item, index) => {
|
|
972
|
+
const customItemValue = Array.isArray(customValue) ? customValue.at(index) : null;
|
|
973
|
+
return deepMerge$1(
|
|
974
|
+
customItemValue ? { ...item, ...customItemValue } : item,
|
|
975
|
+
definitionDefaultValue
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
)
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
return variableLayer2;
|
|
982
|
+
};
|
|
983
|
+
const variableLayer = resolveVariableLayer(
|
|
984
|
+
instanceScope == null ? void 0 : instanceScope.documentManager,
|
|
985
|
+
variableKey
|
|
986
|
+
);
|
|
987
|
+
if ((instanceScope == null ? void 0 : instanceScope.documentManager) && variableKey) {
|
|
988
|
+
subscriptions.current.push({
|
|
989
|
+
manager: instanceScope.documentManager,
|
|
990
|
+
key: variableKey
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
let instanceProp = variableId ? (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId] : void 0;
|
|
994
|
+
if (Array.isArray(instanceProp)) {
|
|
995
|
+
instanceProp = instanceProp.map(
|
|
996
|
+
(rawProp, index) => {
|
|
997
|
+
var _a3;
|
|
998
|
+
return deepMerge$1(rawProp, (_a3 = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a3.at(index));
|
|
999
|
+
}
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
const lastCollectionItem = scopes.findLast(
|
|
1003
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
|
|
1004
|
+
);
|
|
1005
|
+
resolveVariableLayer(
|
|
1006
|
+
lastCollectionItem == null ? void 0 : lastCollectionItem.manager,
|
|
1007
|
+
lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
|
|
1008
|
+
lastCollectionItem == null ? void 0 : lastCollectionItem.value
|
|
1009
|
+
);
|
|
1010
|
+
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$1(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
|
|
1011
|
+
const currentValue = variableKey === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
|
|
1012
|
+
const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
|
|
1013
|
+
const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
|
|
1014
|
+
const resultValue = required ? currentValue : currentValue ?? collectionItemProp ?? defaultValue;
|
|
1015
|
+
if (isVariableLink$1(resultValue)) {
|
|
1016
|
+
return readVariable(resultValue);
|
|
1017
|
+
}
|
|
1018
|
+
return { value: resultValue, layer: variableLayer };
|
|
1019
|
+
};
|
|
1020
|
+
const resolveField = (fieldPath, value, raw) => {
|
|
1021
|
+
var _a2;
|
|
1022
|
+
rawValues[fieldPath] = raw;
|
|
1023
|
+
if (isVariableLink$1(value)) {
|
|
1024
|
+
const resolved = readVariable(value);
|
|
1025
|
+
values[fieldPath] = resolved.value ?? value;
|
|
1026
|
+
const variableId = (_a2 = entityOfKey(value)) == null ? void 0 : _a2._id;
|
|
1027
|
+
cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
|
|
1028
|
+
resolved.value ?? value
|
|
1029
|
+
)})`;
|
|
1030
|
+
} else {
|
|
1031
|
+
values[fieldPath] = value;
|
|
1032
|
+
cssVariableValues[fieldPath] = transformCssValue(value);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
subscriptions.current = [];
|
|
1036
|
+
for (const [field, value] of Object.entries(layer)) {
|
|
1037
|
+
resolveField(field, value, rawLayer == null ? void 0 : rawLayer[field]);
|
|
1038
|
+
if (isObject(value) && !isVariableLink$1(value)) {
|
|
1039
|
+
for (const [nestedField, nestedValue] of Object.entries(
|
|
1040
|
+
value
|
|
1041
|
+
)) {
|
|
1042
|
+
resolveField(
|
|
1043
|
+
`${field}.${nestedField}`,
|
|
1044
|
+
nestedValue,
|
|
1045
|
+
(_a = rawLayer == null ? void 0 : rawLayer[field]) == null ? void 0 : _a[nestedField]
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
return { values, cssVariableValues, rawValues };
|
|
1051
|
+
};
|
|
1052
|
+
const useRenderTarget = () => {
|
|
1053
|
+
const renderTarget = useContext(RenderTargetContext);
|
|
1054
|
+
return {
|
|
1055
|
+
renderTarget,
|
|
1056
|
+
isCanvas: renderTarget === definition.renderTarget.canvas,
|
|
1057
|
+
isDocument: renderTarget === definition.renderTarget.document
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
const useReadVariables = (variableKeys) => {
|
|
1061
|
+
const filterKeys = variableKeys.filter(isVariableLink$1);
|
|
1062
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1063
|
+
const { props, innerManager, layerKey } = useContext(InstanceContext);
|
|
1064
|
+
const resultManager = innerManager ?? fragmentManager;
|
|
1065
|
+
const variableLayers = useGraphStack(
|
|
1066
|
+
!!filterKeys.length ? resultManager : null,
|
|
1067
|
+
filterKeys,
|
|
1068
|
+
{
|
|
1069
|
+
selector: (graph) => graph ? pick(graph, "defaultValue", "required") : graph
|
|
1070
|
+
}
|
|
1071
|
+
);
|
|
1072
|
+
return variableLayers.map((layer) => {
|
|
1073
|
+
const { _id: propertyId } = layer ?? {};
|
|
1074
|
+
const currentValue = (props == null ? void 0 : props[propertyId]) ?? null;
|
|
1075
|
+
const required = (layer == null ? void 0 : layer.required) ?? false;
|
|
1076
|
+
const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
|
|
1077
|
+
const resultValue = required ? currentValue : currentValue ?? defaultValue;
|
|
1078
|
+
return {
|
|
1079
|
+
value: resultValue,
|
|
1080
|
+
layer
|
|
1081
|
+
};
|
|
1082
|
+
});
|
|
1083
|
+
};
|
|
1084
|
+
const extractVariableValue = (input, variableId) => {
|
|
1085
|
+
if (isObject(input)) {
|
|
1086
|
+
if (variableId in input) {
|
|
1087
|
+
return input[variableId];
|
|
1088
|
+
}
|
|
1089
|
+
for (let key in input) {
|
|
1090
|
+
if (input.hasOwnProperty(key)) {
|
|
1091
|
+
const result = extractVariableValue(input[key], variableId);
|
|
1092
|
+
if (result !== void 0) {
|
|
1093
|
+
return result;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
return void 0;
|
|
1099
|
+
};
|
|
1100
|
+
function deepMerge(a, b) {
|
|
1101
|
+
if (!isObject(a) || !isObject(b)) return a;
|
|
1102
|
+
const result = { ...b };
|
|
1103
|
+
for (const [key, value] of Object.entries(a)) {
|
|
1104
|
+
if (key in result && typeof result[key] === "object" && typeof value === "object") {
|
|
1105
|
+
result[key] = deepMerge(value, result[key]);
|
|
1106
|
+
} else {
|
|
1107
|
+
result[key] = value;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return result;
|
|
1111
|
+
}
|
|
1112
|
+
const useReadVariable = (variableKey, customScopes) => {
|
|
1113
|
+
const contextScopes = useContext(ScopeContext);
|
|
1114
|
+
const scopes = customScopes ?? contextScopes;
|
|
1115
|
+
const subscriptions = useRef([]);
|
|
1116
|
+
const [dep, forceUpdate] = useForceUpdate();
|
|
1117
|
+
useEffect(() => {
|
|
1118
|
+
const controller = new AbortController();
|
|
1119
|
+
let ready = false;
|
|
1120
|
+
const update = () => {
|
|
1121
|
+
if (!ready) return;
|
|
1122
|
+
forceUpdate();
|
|
1123
|
+
};
|
|
1124
|
+
for (const { manager, key } of subscriptions.current) {
|
|
1125
|
+
manager.subscribe(key, update, { signal: controller.signal });
|
|
1126
|
+
}
|
|
1127
|
+
ready = true;
|
|
1128
|
+
return () => controller.abort();
|
|
1129
|
+
});
|
|
1130
|
+
const extractVariableDefaultValue = (manager, variableEntity) => {
|
|
1131
|
+
const variableLayer = manager.resolve(variableEntity);
|
|
1132
|
+
if ((variableLayer == null ? void 0 : variableLayer.type) !== definition.variableType.Object)
|
|
1133
|
+
return variableLayer == null ? void 0 : variableLayer.defaultValue;
|
|
1134
|
+
return Object.values((variableLayer == null ? void 0 : variableLayer.fields) ?? {}).reduce(
|
|
1135
|
+
(acc, fieldLink) => {
|
|
1136
|
+
var _a;
|
|
1137
|
+
if (!!fieldLink && isVariableLink$1(fieldLink)) {
|
|
1138
|
+
const _id = (_a = entityOfKey(fieldLink)) == null ? void 0 : _a._id;
|
|
1139
|
+
if (_id) {
|
|
1140
|
+
acc[_id] = extractVariableDefaultValue(manager, fieldLink);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return acc;
|
|
1144
|
+
},
|
|
1145
|
+
{}
|
|
1146
|
+
);
|
|
1147
|
+
};
|
|
1148
|
+
const resolveVariableLayer = (manager, variableLink, customProps) => {
|
|
1149
|
+
var _a, _b;
|
|
1150
|
+
const variableLayer = (_a = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a.layer;
|
|
1151
|
+
if (!variableLayer) return null;
|
|
1152
|
+
if ((variableLayer == null ? void 0 : variableLayer.type) === definition.variableType.Array) {
|
|
1153
|
+
const definitionLayer = manager.resolve(variableLayer == null ? void 0 : variableLayer.definition);
|
|
1154
|
+
if (!((_b = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _b.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
|
|
1155
|
+
return variableLayer;
|
|
1156
|
+
const definitionDefaultValue = extractVariableDefaultValue(
|
|
1157
|
+
manager,
|
|
1158
|
+
definitionLayer
|
|
1159
|
+
);
|
|
1160
|
+
const customValue = customProps == null ? void 0 : customProps[variableLayer == null ? void 0 : variableLayer._id];
|
|
1161
|
+
return {
|
|
1162
|
+
...variableLayer,
|
|
1163
|
+
defaultValue: (variableLayer == null ? void 0 : variableLayer.defaultValue).map((item, index) => {
|
|
1164
|
+
const customItemValue = Array.isArray(customValue) ? customValue.at(index) : null;
|
|
1165
|
+
return deepMerge(
|
|
1166
|
+
customItemValue ? { ...item, ...customItemValue } : item,
|
|
1167
|
+
definitionDefaultValue
|
|
1168
|
+
);
|
|
1169
|
+
})
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
return variableLayer;
|
|
1173
|
+
};
|
|
1174
|
+
const readVariable = (variableKey2) => {
|
|
1175
|
+
var _a, _b, _c;
|
|
1176
|
+
const variableId = (_a = entityOfKey(variableKey2)) == null ? void 0 : _a._id;
|
|
1177
|
+
if (!isVariableLink$1(variableKey2)) {
|
|
1178
|
+
return {
|
|
1179
|
+
value: null,
|
|
1180
|
+
layer: null
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
let instanceScope = scopes.findLast(
|
|
1184
|
+
(scope) => {
|
|
1185
|
+
var _a2;
|
|
1186
|
+
return (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope && !!((_a2 = scope.documentManager) == null ? void 0 : _a2.resolve(variableKey2));
|
|
1187
|
+
}
|
|
1188
|
+
);
|
|
1189
|
+
if (!instanceScope) {
|
|
1190
|
+
instanceScope = scopes.find(
|
|
1191
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
const variableLayer = resolveVariableLayer(
|
|
1195
|
+
instanceScope == null ? void 0 : instanceScope.documentManager,
|
|
1196
|
+
variableKey2
|
|
1197
|
+
);
|
|
1198
|
+
if ((instanceScope == null ? void 0 : instanceScope.documentManager) && variableKey2) {
|
|
1199
|
+
subscriptions.current.push({
|
|
1200
|
+
manager: instanceScope.documentManager,
|
|
1201
|
+
key: variableKey2
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
let instanceProp = (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId];
|
|
1205
|
+
if (Array.isArray(instanceProp)) {
|
|
1206
|
+
instanceProp = instanceProp.map(
|
|
1207
|
+
(rawProp, index) => {
|
|
1208
|
+
var _a2;
|
|
1209
|
+
return deepMerge(rawProp, (_a2 = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a2.at(index));
|
|
1210
|
+
}
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
const lastCollectionItem = scopes.findLast(
|
|
1214
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
|
|
1215
|
+
);
|
|
1216
|
+
resolveVariableLayer(
|
|
1217
|
+
lastCollectionItem == null ? void 0 : lastCollectionItem.manager,
|
|
1218
|
+
lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
|
|
1219
|
+
lastCollectionItem == null ? void 0 : lastCollectionItem.value
|
|
1220
|
+
);
|
|
1221
|
+
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);
|
|
1222
|
+
const currentValue = variableKey2 === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
|
|
1223
|
+
const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
|
|
1224
|
+
const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
|
|
1225
|
+
const resultValue = required ? currentValue : currentValue ?? collectionItemProp ?? defaultValue;
|
|
1226
|
+
if (isVariableLink$1(resultValue)) {
|
|
1227
|
+
return readVariable(resultValue);
|
|
1228
|
+
}
|
|
1229
|
+
return {
|
|
1230
|
+
value: resultValue,
|
|
1231
|
+
layer: variableLayer
|
|
1232
|
+
};
|
|
1233
|
+
};
|
|
1234
|
+
subscriptions.current = [];
|
|
1235
|
+
const result = readVariable(variableKey);
|
|
1236
|
+
return {
|
|
1237
|
+
...result,
|
|
1238
|
+
readVariable,
|
|
1239
|
+
_dep: dep
|
|
1240
|
+
};
|
|
1241
|
+
};
|
|
1242
|
+
const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
1243
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1244
|
+
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
1245
|
+
if (!resultManager) {
|
|
1246
|
+
return [];
|
|
1247
|
+
}
|
|
1248
|
+
const keys = (layerKeys == null ? void 0 : layerKeys.map(keyOfEntity)) ?? [];
|
|
1249
|
+
useGraphStack(resultManager, keys, {
|
|
1250
|
+
// selector: (data) => (data ? pick(data, fieldKey) : data),
|
|
1251
|
+
});
|
|
1252
|
+
const normalizeLayers = useNormalizeLayers(keys, resultManager, options);
|
|
1253
|
+
const { readVariable } = useReadVariable(null, options == null ? void 0 : options.scopes);
|
|
1254
|
+
return normalizeLayers.map((normalizedLayer) => {
|
|
1255
|
+
var _a, _b;
|
|
1256
|
+
const rawValue = get(normalizedLayer.rawLayer, fieldKey);
|
|
1257
|
+
const layerValue = get(normalizedLayer.layer, fieldKey);
|
|
1258
|
+
const variableValue = (_a = readVariable(layerValue)) == null ? void 0 : _a.value;
|
|
1259
|
+
const currentValue = variableValue ?? layerValue;
|
|
1260
|
+
const isInherit = isInheritField(
|
|
1261
|
+
resultManager,
|
|
1262
|
+
normalizedLayer.layerKey,
|
|
1263
|
+
fieldKey
|
|
1264
|
+
);
|
|
1265
|
+
const isOverride = !isInherit && !isPartOfPrimary(resultManager, normalizedLayer.layerKey);
|
|
1266
|
+
const setter = layerFieldSetter(
|
|
1267
|
+
resultManager,
|
|
1268
|
+
normalizedLayer.layerKey,
|
|
1269
|
+
fieldKey,
|
|
1270
|
+
currentValue
|
|
1271
|
+
);
|
|
1272
|
+
const resetOverride = () => {
|
|
1273
|
+
resultManager.mutate(
|
|
1274
|
+
normalizedLayer.layerKey,
|
|
1275
|
+
(prev) => {
|
|
1276
|
+
const r = omit(prev, fieldKey);
|
|
1277
|
+
return r;
|
|
1278
|
+
},
|
|
1279
|
+
{ replace: true }
|
|
1280
|
+
);
|
|
1281
|
+
};
|
|
1282
|
+
const restore = (fallbackValue) => {
|
|
1283
|
+
var _a2, _b2, _c;
|
|
1284
|
+
const tempValue = ((_c = (_b2 = resultManager.resolve((_a2 = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a2.temp)) == null ? void 0 : _b2[normalizedLayer.layerKey]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
|
|
1285
|
+
return tempValue;
|
|
1286
|
+
};
|
|
1287
|
+
const updateValue = (value, options2) => {
|
|
1288
|
+
setter(value, options2);
|
|
1289
|
+
};
|
|
1290
|
+
const isVariable = isVariableLink$1(rawValue ?? layerValue);
|
|
1291
|
+
const variableId = isVariable ? (_b = entityOfKey(layerValue)) == null ? void 0 : _b._id : null;
|
|
1292
|
+
return [
|
|
1293
|
+
currentValue,
|
|
1294
|
+
updateValue,
|
|
1295
|
+
{
|
|
1296
|
+
isOverride,
|
|
1297
|
+
resetOverride,
|
|
1298
|
+
isVariable,
|
|
1299
|
+
cssVariableValue: isVariable ? `var(--${variableId}, ${transformCssValue(currentValue)})` : transformCssValue(currentValue),
|
|
1300
|
+
rawValue,
|
|
1301
|
+
restore,
|
|
1302
|
+
...resultManager.entityOfKey(normalizedLayer.layerKey)
|
|
1303
|
+
}
|
|
1304
|
+
];
|
|
1305
|
+
});
|
|
1306
|
+
};
|
|
1123
1307
|
const useLayerValue = (layerKey, fieldKey, options) => {
|
|
1124
1308
|
var _a;
|
|
1125
1309
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
@@ -1180,12 +1364,107 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1180
1364
|
}
|
|
1181
1365
|
];
|
|
1182
1366
|
};
|
|
1367
|
+
const useLayerChildren = (layerKey, customManager) => {
|
|
1368
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1369
|
+
const [layerData] = useGraph(customManager ?? fragmentManager, layerKey, {
|
|
1370
|
+
selector: (data) => pick(data, "children")
|
|
1371
|
+
});
|
|
1372
|
+
return (layerData == null ? void 0 : layerData.children) ?? [];
|
|
1373
|
+
};
|
|
1374
|
+
const useLayerScopes = (fragmentManager, layerKey) => {
|
|
1375
|
+
var _a, _b, _c, _d;
|
|
1376
|
+
if (!fragmentManager || !layerKey) return [];
|
|
1377
|
+
const layerParents = getAllParents(fragmentManager, layerKey);
|
|
1378
|
+
const resultScopes = [(_b = (_a = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a.scopes) == null ? void 0 : _b.get(void 0)];
|
|
1379
|
+
layerParents.forEach((parent) => {
|
|
1380
|
+
var _a2, _b2, _c2, _d2;
|
|
1381
|
+
const parentLink = keyOfEntity(parent);
|
|
1382
|
+
if ((_b2 = (_a2 = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a2.scopes) == null ? void 0 : _b2.has(parentLink)) {
|
|
1383
|
+
resultScopes.push((_d2 = (_c2 = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _c2.scopes) == null ? void 0 : _d2.get(parentLink));
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
const areaScope = (_d = (_c = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _c.scopes) == null ? void 0 : _d.get("Area");
|
|
1387
|
+
if (areaScope) {
|
|
1388
|
+
resultScopes.push(areaScope);
|
|
1389
|
+
}
|
|
1390
|
+
return resultScopes;
|
|
1391
|
+
};
|
|
1392
|
+
const useLayerLink = (layerKey) => {
|
|
1393
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1394
|
+
const [link] = useLayerValue(layerKey, "link", fragmentManager);
|
|
1395
|
+
const [href] = useLayerValue(link, "href", fragmentManager);
|
|
1396
|
+
const [isNewTab] = useLayerValue(link, "isNewTab", fragmentManager);
|
|
1397
|
+
const isLink2 = isValue(href) && typeof href === "string" && !!(href == null ? void 0 : href.length);
|
|
1398
|
+
const linkTarget = isNewTab ? "_blank" : "";
|
|
1399
|
+
const linkProps = useMemo(() => {
|
|
1400
|
+
if (isLink2) {
|
|
1401
|
+
return {
|
|
1402
|
+
target: linkTarget,
|
|
1403
|
+
href
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
return {};
|
|
1407
|
+
}, [linkTarget, href, isLink2]);
|
|
1408
|
+
return {
|
|
1409
|
+
isLink: isLink2,
|
|
1410
|
+
linkHref: href,
|
|
1411
|
+
linkTarget,
|
|
1412
|
+
linkProps
|
|
1413
|
+
};
|
|
1414
|
+
};
|
|
1415
|
+
const useLayerVariableValue = (layerKey, fieldKey, manager) => {
|
|
1416
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1417
|
+
const resultManager = manager ?? fragmentManager;
|
|
1418
|
+
const [layerValue, updateValue, layerInfo] = useLayerValue(
|
|
1419
|
+
layerKey,
|
|
1420
|
+
fieldKey,
|
|
1421
|
+
resultManager
|
|
1422
|
+
);
|
|
1423
|
+
const { value: instanceValue } = useReadVariable(
|
|
1424
|
+
(layerInfo == null ? void 0 : layerInfo.isVariable) ? layerValue : null
|
|
1425
|
+
);
|
|
1426
|
+
return [
|
|
1427
|
+
(layerInfo == null ? void 0 : layerInfo.isVariable) ? instanceValue : layerValue,
|
|
1428
|
+
updateValue,
|
|
1429
|
+
{
|
|
1430
|
+
...layerInfo,
|
|
1431
|
+
rawValue: layerValue
|
|
1432
|
+
}
|
|
1433
|
+
];
|
|
1434
|
+
};
|
|
1435
|
+
const useLayerLinearGradient = (linearGradientLink) => {
|
|
1436
|
+
const [stops] = useLayerValue(linearGradientLink, "stops");
|
|
1437
|
+
const [angle] = useLayerValue(linearGradientLink, "angle");
|
|
1438
|
+
const stopsValue = useLayersValue(stops, "value");
|
|
1439
|
+
const stopsPosition = useLayersValue(stops, "position");
|
|
1440
|
+
const stopValues = useMemo(
|
|
1441
|
+
() => (stops == null ? void 0 : stops.flatMap((stop, index) => {
|
|
1442
|
+
var _a, _b, _c;
|
|
1443
|
+
return [
|
|
1444
|
+
(_b = (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(2)) == null ? void 0 : _b.cssVariableValue,
|
|
1445
|
+
(_c = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _c.at(0)
|
|
1446
|
+
];
|
|
1447
|
+
})) ?? [],
|
|
1448
|
+
[stops, stopsValue, stopsPosition]
|
|
1449
|
+
);
|
|
1450
|
+
return useMemo(
|
|
1451
|
+
() => ({
|
|
1452
|
+
"background-image": calcLinearGradient(angle, stopValues)
|
|
1453
|
+
}),
|
|
1454
|
+
[angle, stopValues]
|
|
1455
|
+
);
|
|
1456
|
+
};
|
|
1183
1457
|
const processOptionalSize = (value, type) => {
|
|
1184
1458
|
if (value === -1) return "";
|
|
1185
1459
|
if (type === definition.sizing.Fixed) return toPx(value);
|
|
1186
1460
|
if (type === definition.sizing.Relative) return `${value}%`;
|
|
1187
1461
|
return "";
|
|
1188
1462
|
};
|
|
1463
|
+
const calcOptionalSize = (type, vars) => {
|
|
1464
|
+
const value = vars.values[type];
|
|
1465
|
+
const valueType = vars.values[`${type}Type`];
|
|
1466
|
+
return processOptionalSize(value, valueType);
|
|
1467
|
+
};
|
|
1189
1468
|
const useOptionalSize = (type, layerKey) => {
|
|
1190
1469
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1191
1470
|
const [value] = useLayerValue(layerKey, type, fragmentManager);
|
|
@@ -1195,6 +1474,14 @@ const useOptionalSize = (type, layerKey) => {
|
|
|
1195
1474
|
[valueType, value]
|
|
1196
1475
|
);
|
|
1197
1476
|
};
|
|
1477
|
+
const calcLayerSize = (vars) => {
|
|
1478
|
+
return {
|
|
1479
|
+
minWidth: calcOptionalSize("minWidth", vars),
|
|
1480
|
+
minHeight: calcOptionalSize("minHeight", vars),
|
|
1481
|
+
maxWidth: calcOptionalSize("maxWidth", vars),
|
|
1482
|
+
maxHeight: calcOptionalSize("maxHeight", vars)
|
|
1483
|
+
};
|
|
1484
|
+
};
|
|
1198
1485
|
const useLayerSize = (layerKey) => {
|
|
1199
1486
|
const { manager } = useContext(FragmentContext);
|
|
1200
1487
|
const minWidth = useOptionalSize("minWidth", layerKey);
|
|
@@ -1206,19 +1493,34 @@ const useLayerSize = (layerKey) => {
|
|
|
1206
1493
|
// height: heightCalc(heightValue),
|
|
1207
1494
|
minWidth,
|
|
1208
1495
|
minHeight,
|
|
1209
|
-
maxWidth,
|
|
1210
|
-
maxHeight
|
|
1211
|
-
};
|
|
1212
|
-
};
|
|
1213
|
-
const useRenderTarget = () => {
|
|
1214
|
-
const renderTarget = useContext(RenderTargetContext);
|
|
1215
|
-
return {
|
|
1216
|
-
renderTarget,
|
|
1217
|
-
isCanvas: renderTarget === definition.renderTarget.canvas,
|
|
1218
|
-
isDocument: renderTarget === definition.renderTarget.document
|
|
1496
|
+
maxWidth,
|
|
1497
|
+
maxHeight
|
|
1219
1498
|
};
|
|
1220
1499
|
};
|
|
1221
1500
|
const autoSizes = [definition.sizing.Hug];
|
|
1501
|
+
const calcLayerSizeValue = (resolved, vars, sizeType, parentResolved, instanceVars, context) => {
|
|
1502
|
+
const { isDocument, isTopLevel: isTop, instanceLayerKey } = context;
|
|
1503
|
+
const isPartOfInstance = !!instanceLayerKey;
|
|
1504
|
+
const layerNode = resolved.rawLayer;
|
|
1505
|
+
const instanceType = instanceVars.values[`${sizeType}Type`];
|
|
1506
|
+
const valueType = vars.values[`${sizeType}Type`];
|
|
1507
|
+
const growType = sizeType === "width" ? "horizontalGrow" : "verticalGrow";
|
|
1508
|
+
return (value) => {
|
|
1509
|
+
var _a;
|
|
1510
|
+
if (isTop && isDocument && ((_a = parentResolved.layer) == null ? void 0 : _a[growType]) === definition.fragmentGrowingMode.fill) {
|
|
1511
|
+
return "100%";
|
|
1512
|
+
}
|
|
1513
|
+
if (isTop && isPartOfInstance && !autoSizes.includes(instanceType)) {
|
|
1514
|
+
return "100%";
|
|
1515
|
+
}
|
|
1516
|
+
if (autoSizes.includes(valueType)) {
|
|
1517
|
+
return (layerNode == null ? void 0 : layerNode._type) === definition.nodes.Instance ? "auto" : "fit-content";
|
|
1518
|
+
}
|
|
1519
|
+
if (valueType === definition.sizing.Relative) return `${value}%`;
|
|
1520
|
+
if (valueType === definition.sizing.Fill) return `100%`;
|
|
1521
|
+
return toPx(value);
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1222
1524
|
const useLayerSizeValue = (layerKey, sizeType) => {
|
|
1223
1525
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1224
1526
|
const { layerKey: instanceLayerKey } = useContext(InstanceContext$1);
|
|
@@ -1273,6 +1575,65 @@ const useLayerSizeValue = (layerKey, sizeType) => {
|
|
|
1273
1575
|
]
|
|
1274
1576
|
);
|
|
1275
1577
|
};
|
|
1578
|
+
const calcLayerPosition = (resolved, vars, parentResolved, instanceResolved, instanceVars, context) => {
|
|
1579
|
+
const { isDocument, isTopLevel: isTop, instanceLayerKey } = context;
|
|
1580
|
+
const width = vars.values.width;
|
|
1581
|
+
const height = vars.values.height;
|
|
1582
|
+
const widthCalc = calcLayerSizeValue(
|
|
1583
|
+
resolved,
|
|
1584
|
+
vars,
|
|
1585
|
+
"width",
|
|
1586
|
+
parentResolved,
|
|
1587
|
+
instanceVars,
|
|
1588
|
+
context
|
|
1589
|
+
);
|
|
1590
|
+
const heightCalc = calcLayerSizeValue(
|
|
1591
|
+
resolved,
|
|
1592
|
+
vars,
|
|
1593
|
+
"height",
|
|
1594
|
+
parentResolved,
|
|
1595
|
+
instanceVars,
|
|
1596
|
+
context
|
|
1597
|
+
);
|
|
1598
|
+
const position = vars.values.position;
|
|
1599
|
+
const centerAnchorX = vars.values.centerAnchorX;
|
|
1600
|
+
const centerAnchorY = vars.values.centerAnchorY;
|
|
1601
|
+
const top = vars.values.top;
|
|
1602
|
+
const left = vars.values.left;
|
|
1603
|
+
const right = vars.values.right;
|
|
1604
|
+
const bottom = vars.values.bottom;
|
|
1605
|
+
const skipPosition = isTop && isDocument || !!instanceLayerKey && isTop;
|
|
1606
|
+
if (isTop && !skipPosition) {
|
|
1607
|
+
return {
|
|
1608
|
+
position: definition.positionType.absolute,
|
|
1609
|
+
top: toPx(top),
|
|
1610
|
+
left: toPx(left),
|
|
1611
|
+
width,
|
|
1612
|
+
height
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
if (position === definition.positionType.relative || skipPosition) {
|
|
1616
|
+
return {
|
|
1617
|
+
position: definition.positionType.relative,
|
|
1618
|
+
width: widthCalc(width),
|
|
1619
|
+
height: heightCalc(height)
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
const hasConstrainX = isFiniteNumber(left) && isFiniteNumber(right);
|
|
1623
|
+
const hasConstrainY = isFiniteNumber(top) && isFiniteNumber(bottom);
|
|
1624
|
+
const hasAnyConstrainX = isFiniteNumber(left) || isFiniteNumber(right);
|
|
1625
|
+
const hasAnyConstrainY = isFiniteNumber(top) || isFiniteNumber(bottom);
|
|
1626
|
+
return {
|
|
1627
|
+
position,
|
|
1628
|
+
left: isFiniteNumber(left) ? toPx(left) : !isFiniteNumber(right) ? `${centerAnchorX * 100}%` : null,
|
|
1629
|
+
top: isFiniteNumber(top) ? toPx(top) : !isFiniteNumber(bottom) ? `${centerAnchorY * 100}%` : null,
|
|
1630
|
+
right: isFiniteNumber(right) ? toPx(right) : null,
|
|
1631
|
+
bottom: isFiniteNumber(bottom) ? toPx(bottom) : null,
|
|
1632
|
+
width: hasConstrainX ? null : widthCalc(width),
|
|
1633
|
+
height: hasConstrainY ? null : heightCalc(height),
|
|
1634
|
+
transform: !hasAnyConstrainX || !hasAnyConstrainY ? `translate3d(${!hasAnyConstrainX ? "-50%" : 0}, ${!hasAnyConstrainY ? "-50%" : 0}, 0px)` : null
|
|
1635
|
+
};
|
|
1636
|
+
};
|
|
1276
1637
|
const useLayerPosition = (layerKey) => {
|
|
1277
1638
|
const { layerKey: instanceLayerKey } = useContext(InstanceContext$1);
|
|
1278
1639
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
@@ -1321,6 +1682,14 @@ const useLayerPosition = (layerKey) => {
|
|
|
1321
1682
|
transform: !hasAnyConstrainX || !hasAnyConstrainY ? `translate3d(${!hasAnyConstrainX ? "-50%" : 0}, ${!hasAnyConstrainY ? "-50%" : 0}, 0px)` : null
|
|
1322
1683
|
};
|
|
1323
1684
|
};
|
|
1685
|
+
const calcImagePaint = (imageVars) => {
|
|
1686
|
+
var _a, _b;
|
|
1687
|
+
return {
|
|
1688
|
+
background: imageVars.cssVariableValues.src,
|
|
1689
|
+
backgroundRepeat: "no-repeat",
|
|
1690
|
+
backgroundSize: (_b = (_a = imageVars.values.scale) == null ? void 0 : _a.toLowerCase) == null ? void 0 : _b.call(_a)
|
|
1691
|
+
};
|
|
1692
|
+
};
|
|
1324
1693
|
const useImagePaint = (imageLinkKey) => {
|
|
1325
1694
|
var _a;
|
|
1326
1695
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
@@ -1332,184 +1701,24 @@ const useImagePaint = (imageLinkKey) => {
|
|
|
1332
1701
|
backgroundSize: (_a = scale == null ? void 0 : scale.toLowerCase) == null ? void 0 : _a.call(scale)
|
|
1333
1702
|
};
|
|
1334
1703
|
};
|
|
1335
|
-
const
|
|
1336
|
-
const
|
|
1337
|
-
const
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
selector: (graph) => graph ? pick(graph, "defaultValue", "required") : graph
|
|
1345
|
-
}
|
|
1346
|
-
);
|
|
1347
|
-
return variableLayers.map((layer) => {
|
|
1348
|
-
const { _id: propertyId } = layer ?? {};
|
|
1349
|
-
const currentValue = (props == null ? void 0 : props[propertyId]) ?? null;
|
|
1350
|
-
const required = (layer == null ? void 0 : layer.required) ?? false;
|
|
1351
|
-
const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
|
|
1352
|
-
const resultValue = required ? currentValue : currentValue ?? defaultValue;
|
|
1704
|
+
const calcLayerBackground = (paintVars, imageVars, imageSizeVars, linearGradient) => {
|
|
1705
|
+
const fillType = paintVars.values.type;
|
|
1706
|
+
const cssSolidFill = paintVars.cssVariableValues.solid;
|
|
1707
|
+
const cssImageSize = imageSizeVars.cssVariableValues.imageSize;
|
|
1708
|
+
if (fillType === definition.paintMode.Solid) {
|
|
1709
|
+
return { background: cssSolidFill };
|
|
1710
|
+
}
|
|
1711
|
+
if (fillType === definition.paintMode.Image) {
|
|
1712
|
+
const image = calcImagePaint(imageVars);
|
|
1353
1713
|
return {
|
|
1354
|
-
|
|
1355
|
-
|
|
1714
|
+
...image,
|
|
1715
|
+
backgroundSize: cssImageSize ?? image.backgroundSize
|
|
1356
1716
|
};
|
|
1357
|
-
});
|
|
1358
|
-
};
|
|
1359
|
-
const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
1360
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1361
|
-
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
1362
|
-
if (!resultManager) {
|
|
1363
|
-
return [];
|
|
1364
1717
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
// selector: (data) => (data ? pick(data, fieldKey) : data),
|
|
1368
|
-
});
|
|
1369
|
-
const normalizeLayers = useNormalizeLayers(keys, resultManager, options);
|
|
1370
|
-
const { readVariable } = useReadVariable(null, options == null ? void 0 : options.scopes);
|
|
1371
|
-
return normalizeLayers.map((normalizedLayer) => {
|
|
1372
|
-
var _a, _b;
|
|
1373
|
-
const rawValue = get(normalizedLayer.rawLayer, fieldKey);
|
|
1374
|
-
const layerValue = get(normalizedLayer.layer, fieldKey);
|
|
1375
|
-
const variableValue = (_a = readVariable(layerValue)) == null ? void 0 : _a.value;
|
|
1376
|
-
const currentValue = variableValue ?? layerValue;
|
|
1377
|
-
const isInherit = isInheritField(
|
|
1378
|
-
resultManager,
|
|
1379
|
-
normalizedLayer.layerKey,
|
|
1380
|
-
fieldKey
|
|
1381
|
-
);
|
|
1382
|
-
const isOverride = !isInherit && !isPartOfPrimary(resultManager, normalizedLayer.layerKey);
|
|
1383
|
-
const setter = layerFieldSetter(
|
|
1384
|
-
resultManager,
|
|
1385
|
-
normalizedLayer.layerKey,
|
|
1386
|
-
fieldKey,
|
|
1387
|
-
currentValue
|
|
1388
|
-
);
|
|
1389
|
-
const resetOverride = () => {
|
|
1390
|
-
resultManager.mutate(
|
|
1391
|
-
normalizedLayer.layerKey,
|
|
1392
|
-
(prev) => {
|
|
1393
|
-
const r = omit(prev, fieldKey);
|
|
1394
|
-
return r;
|
|
1395
|
-
},
|
|
1396
|
-
{ replace: true }
|
|
1397
|
-
);
|
|
1398
|
-
};
|
|
1399
|
-
const restore = (fallbackValue) => {
|
|
1400
|
-
var _a2, _b2, _c;
|
|
1401
|
-
const tempValue = ((_c = (_b2 = resultManager.resolve((_a2 = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a2.temp)) == null ? void 0 : _b2[normalizedLayer.layerKey]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
|
|
1402
|
-
return tempValue;
|
|
1403
|
-
};
|
|
1404
|
-
const updateValue = (value, options2) => {
|
|
1405
|
-
setter(value, options2);
|
|
1406
|
-
};
|
|
1407
|
-
const isVariable = isVariableLink$1(rawValue ?? layerValue);
|
|
1408
|
-
const variableId = isVariable ? (_b = entityOfKey(layerValue)) == null ? void 0 : _b._id : null;
|
|
1409
|
-
return [
|
|
1410
|
-
currentValue,
|
|
1411
|
-
updateValue,
|
|
1412
|
-
{
|
|
1413
|
-
isOverride,
|
|
1414
|
-
resetOverride,
|
|
1415
|
-
isVariable,
|
|
1416
|
-
cssVariableValue: isVariable ? `var(--${variableId}, ${transformCssValue(currentValue)})` : transformCssValue(currentValue),
|
|
1417
|
-
rawValue,
|
|
1418
|
-
restore,
|
|
1419
|
-
...resultManager.entityOfKey(normalizedLayer.layerKey)
|
|
1420
|
-
}
|
|
1421
|
-
];
|
|
1422
|
-
});
|
|
1423
|
-
};
|
|
1424
|
-
const useLayerChildren = (layerKey, customManager) => {
|
|
1425
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1426
|
-
const [layerData] = useGraph(customManager ?? fragmentManager, layerKey, {
|
|
1427
|
-
selector: (data) => pick(data, "children")
|
|
1428
|
-
});
|
|
1429
|
-
return (layerData == null ? void 0 : layerData.children) ?? [];
|
|
1430
|
-
};
|
|
1431
|
-
const useLayerScopes = (fragmentManager, layerKey) => {
|
|
1432
|
-
var _a, _b, _c, _d;
|
|
1433
|
-
if (!fragmentManager || !layerKey) return [];
|
|
1434
|
-
const layerParents = getAllParents(fragmentManager, layerKey);
|
|
1435
|
-
const resultScopes = [(_b = (_a = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a.scopes) == null ? void 0 : _b.get(void 0)];
|
|
1436
|
-
layerParents.forEach((parent) => {
|
|
1437
|
-
var _a2, _b2, _c2, _d2;
|
|
1438
|
-
const parentLink = keyOfEntity(parent);
|
|
1439
|
-
if ((_b2 = (_a2 = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _a2.scopes) == null ? void 0 : _b2.has(parentLink)) {
|
|
1440
|
-
resultScopes.push((_d2 = (_c2 = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _c2.scopes) == null ? void 0 : _d2.get(parentLink));
|
|
1441
|
-
}
|
|
1442
|
-
});
|
|
1443
|
-
const areaScope = (_d = (_c = fragmentManager == null ? void 0 : fragmentManager.$scopes) == null ? void 0 : _c.scopes) == null ? void 0 : _d.get("Area");
|
|
1444
|
-
if (areaScope) {
|
|
1445
|
-
resultScopes.push(areaScope);
|
|
1718
|
+
if (fillType === definition.paintMode.LinearGradient) {
|
|
1719
|
+
return linearGradient;
|
|
1446
1720
|
}
|
|
1447
|
-
return
|
|
1448
|
-
};
|
|
1449
|
-
const useLayerLink = (layerKey) => {
|
|
1450
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1451
|
-
const [link] = useLayerValue(layerKey, "link", fragmentManager);
|
|
1452
|
-
const [href] = useLayerValue(link, "href", fragmentManager);
|
|
1453
|
-
const [isNewTab] = useLayerValue(link, "isNewTab", fragmentManager);
|
|
1454
|
-
const isLink2 = isValue(href) && typeof href === "string" && !!(href == null ? void 0 : href.length);
|
|
1455
|
-
const linkTarget = isNewTab ? "_blank" : "";
|
|
1456
|
-
const linkProps = useMemo(() => {
|
|
1457
|
-
if (isLink2) {
|
|
1458
|
-
return {
|
|
1459
|
-
target: linkTarget,
|
|
1460
|
-
href
|
|
1461
|
-
};
|
|
1462
|
-
}
|
|
1463
|
-
return {};
|
|
1464
|
-
}, [linkTarget, href, isLink2]);
|
|
1465
|
-
return {
|
|
1466
|
-
isLink: isLink2,
|
|
1467
|
-
linkHref: href,
|
|
1468
|
-
linkTarget,
|
|
1469
|
-
linkProps
|
|
1470
|
-
};
|
|
1471
|
-
};
|
|
1472
|
-
const useLayerVariableValue = (layerKey, fieldKey, manager) => {
|
|
1473
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1474
|
-
const resultManager = manager ?? fragmentManager;
|
|
1475
|
-
const [layerValue, updateValue, layerInfo] = useLayerValue(
|
|
1476
|
-
layerKey,
|
|
1477
|
-
fieldKey,
|
|
1478
|
-
resultManager
|
|
1479
|
-
);
|
|
1480
|
-
const { value: instanceValue } = useReadVariable(
|
|
1481
|
-
(layerInfo == null ? void 0 : layerInfo.isVariable) ? layerValue : null
|
|
1482
|
-
);
|
|
1483
|
-
return [
|
|
1484
|
-
(layerInfo == null ? void 0 : layerInfo.isVariable) ? instanceValue : layerValue,
|
|
1485
|
-
updateValue,
|
|
1486
|
-
{
|
|
1487
|
-
...layerInfo,
|
|
1488
|
-
rawValue: layerValue
|
|
1489
|
-
}
|
|
1490
|
-
];
|
|
1491
|
-
};
|
|
1492
|
-
const useLayerLinearGradient = (linearGradientLink) => {
|
|
1493
|
-
const [stops] = useLayerValue(linearGradientLink, "stops");
|
|
1494
|
-
const [angle] = useLayerValue(linearGradientLink, "angle");
|
|
1495
|
-
const stopsValue = useLayersValue(stops, "value");
|
|
1496
|
-
const stopsPosition = useLayersValue(stops, "position");
|
|
1497
|
-
const stopValues = useMemo(
|
|
1498
|
-
() => (stops == null ? void 0 : stops.flatMap((stop, index) => {
|
|
1499
|
-
var _a, _b, _c;
|
|
1500
|
-
return [
|
|
1501
|
-
(_b = (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(2)) == null ? void 0 : _b.cssVariableValue,
|
|
1502
|
-
(_c = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _c.at(0)
|
|
1503
|
-
];
|
|
1504
|
-
})) ?? [],
|
|
1505
|
-
[stops, stopsValue, stopsPosition]
|
|
1506
|
-
);
|
|
1507
|
-
return useMemo(
|
|
1508
|
-
() => ({
|
|
1509
|
-
"background-image": calcLinearGradient(angle, stopValues)
|
|
1510
|
-
}),
|
|
1511
|
-
[angle, stopValues]
|
|
1512
|
-
);
|
|
1721
|
+
return { background: null };
|
|
1513
1722
|
};
|
|
1514
1723
|
const useLayerBackground = (layerKey) => {
|
|
1515
1724
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
@@ -1556,6 +1765,12 @@ const useLayerBackground = (layerKey) => {
|
|
|
1556
1765
|
linearGradient
|
|
1557
1766
|
]);
|
|
1558
1767
|
};
|
|
1768
|
+
const calcLayerDisplay = (vars) => {
|
|
1769
|
+
const layerModeValue = vars.values.layerMode;
|
|
1770
|
+
const visible = vars.values.visible;
|
|
1771
|
+
if (!visible) return "none";
|
|
1772
|
+
return layerModeValue === definition.layerMode.flex ? "flex" : null;
|
|
1773
|
+
};
|
|
1559
1774
|
const useLayerDisplay = (layerKey) => {
|
|
1560
1775
|
const { manager } = useContext(FragmentContext);
|
|
1561
1776
|
const [layerModeValue] = useLayerValue(layerKey, "layerMode", manager);
|
|
@@ -1567,6 +1782,15 @@ const useLayerDisplay = (layerKey) => {
|
|
|
1567
1782
|
return layerModeValue === definition.layerMode.flex ? "flex" : null;
|
|
1568
1783
|
}, [layerModeValue, visible]);
|
|
1569
1784
|
};
|
|
1785
|
+
const calcLayerPaint = (paintVars) => {
|
|
1786
|
+
return {
|
|
1787
|
+
type: paintVars.values.type,
|
|
1788
|
+
solid: paintVars.values.solid,
|
|
1789
|
+
solidCssValue: paintVars.cssVariableValues.solid,
|
|
1790
|
+
image: paintVars.values.image,
|
|
1791
|
+
linearGradientLink: paintVars.values.linearGradient
|
|
1792
|
+
};
|
|
1793
|
+
};
|
|
1570
1794
|
const useLayerPaint = (paintLinkKey) => {
|
|
1571
1795
|
const [type] = useLayerValue(paintLinkKey, "type");
|
|
1572
1796
|
const [solid, , solidInfo] = useLayerValue(paintLinkKey, "solid");
|
|
@@ -1580,6 +1804,36 @@ const useLayerPaint = (paintLinkKey) => {
|
|
|
1580
1804
|
linearGradientLink
|
|
1581
1805
|
};
|
|
1582
1806
|
};
|
|
1807
|
+
const calcLayerBorder = (borderVars, borderPaintVars, borderLinearGradient, paintVars, linearGradient) => {
|
|
1808
|
+
const type = borderVars.values.type;
|
|
1809
|
+
const width = borderVars.values.width;
|
|
1810
|
+
const borderPaint = calcLayerPaint(borderPaintVars);
|
|
1811
|
+
const paint = calcLayerPaint(paintVars);
|
|
1812
|
+
if (type === definition.borderType.None) {
|
|
1813
|
+
return { border: null };
|
|
1814
|
+
}
|
|
1815
|
+
if (borderPaint.type === definition.paintMode.LinearGradient) {
|
|
1816
|
+
let background = `linear-gradient(${paint.solid}, ${paint.solid}) padding-box, ${borderLinearGradient == null ? void 0 : borderLinearGradient["background-image"]} border-box`;
|
|
1817
|
+
if (paint.type === definition.paintMode.LinearGradient) {
|
|
1818
|
+
background = `${linearGradient == null ? void 0 : linearGradient["background-image"]} padding-box, ${borderLinearGradient == null ? void 0 : borderLinearGradient["background-image"]} border-box`;
|
|
1819
|
+
}
|
|
1820
|
+
if (paint.type === definition.paintMode.None) {
|
|
1821
|
+
background = `linear-gradient(transparent, transparent) padding-box, ${borderLinearGradient == null ? void 0 : borderLinearGradient["background-image"]} border-box`;
|
|
1822
|
+
}
|
|
1823
|
+
return {
|
|
1824
|
+
...calcBorderSides(
|
|
1825
|
+
type,
|
|
1826
|
+
width,
|
|
1827
|
+
borderPaint.type === definition.paintMode.Solid ? borderPaint.solid : "transparent"
|
|
1828
|
+
),
|
|
1829
|
+
background
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
if (borderPaint.type === definition.paintMode.Solid) {
|
|
1833
|
+
return calcBorderSides(type, width, borderPaint.solidCssValue);
|
|
1834
|
+
}
|
|
1835
|
+
return { border: null };
|
|
1836
|
+
};
|
|
1583
1837
|
const useLayerBorder = (layerKey) => {
|
|
1584
1838
|
var _a, _b;
|
|
1585
1839
|
const [borderLinkKey] = useLayerValue(layerKey, "border");
|
|
@@ -1620,6 +1874,28 @@ const useLayerBorder = (layerKey) => {
|
|
|
1620
1874
|
}
|
|
1621
1875
|
return { border: null };
|
|
1622
1876
|
};
|
|
1877
|
+
const calcLayerLayout = (vars) => {
|
|
1878
|
+
const layerModeValue = vars.values.layerMode;
|
|
1879
|
+
const layerWrap = vars.values.layerWrap;
|
|
1880
|
+
const layerDistribute = vars.values.layerDistribute;
|
|
1881
|
+
const layerDirectionValue = vars.values.layerDirection;
|
|
1882
|
+
const layerAlign = vars.values.layerAlign;
|
|
1883
|
+
const padding = vars.values.padding;
|
|
1884
|
+
const gap = vars.values.layerGap;
|
|
1885
|
+
const isFlex = layerModeValue === definition.layerMode.flex;
|
|
1886
|
+
const baseFlow = layerDirectionValue === definition.layerDirection.vertical ? "column" : "row";
|
|
1887
|
+
const wrap = isFlex ? layerWrap ? "wrap" : null : null;
|
|
1888
|
+
const flexFlow = [baseFlow, wrap].filter(Boolean).join(" ");
|
|
1889
|
+
return {
|
|
1890
|
+
display: isFlex ? "flex" : null,
|
|
1891
|
+
gap: toPx(gap),
|
|
1892
|
+
flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
|
|
1893
|
+
justifyContent: isFlex ? layerDistribute : null,
|
|
1894
|
+
flexFlow,
|
|
1895
|
+
alignItems: isFlex ? layerAlign : null,
|
|
1896
|
+
padding: isFlex ? padding : null
|
|
1897
|
+
};
|
|
1898
|
+
};
|
|
1623
1899
|
const useLayerLayout = (layerKey) => {
|
|
1624
1900
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1625
1901
|
const [layerModeValue] = useLayerValue(
|
|
@@ -1655,6 +1931,15 @@ const useLayerLayout = (layerKey) => {
|
|
|
1655
1931
|
padding: isFlex ? padding : null
|
|
1656
1932
|
};
|
|
1657
1933
|
};
|
|
1934
|
+
const calcLayerTextStyles = (vars) => {
|
|
1935
|
+
const attributes = vars.values.attributes;
|
|
1936
|
+
const color = vars.values["attributes.color"];
|
|
1937
|
+
const cleanAttributes = omit(attributes, "_id", "_type");
|
|
1938
|
+
return {
|
|
1939
|
+
...cleanAttributes,
|
|
1940
|
+
color
|
|
1941
|
+
};
|
|
1942
|
+
};
|
|
1658
1943
|
const useLayerTextStyles = (layerKey) => {
|
|
1659
1944
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1660
1945
|
const [attributes] = useLayerValue(layerKey, "attributes", fragmentManager);
|
|
@@ -1665,6 +1950,15 @@ const useLayerTextStyles = (layerKey) => {
|
|
|
1665
1950
|
color
|
|
1666
1951
|
};
|
|
1667
1952
|
};
|
|
1953
|
+
const calcLayerFlex = (vars, parentVars) => {
|
|
1954
|
+
const widthType = vars.values.widthType;
|
|
1955
|
+
const heightType = vars.values.heightType;
|
|
1956
|
+
const layerDirectionValue = parentVars.values.layerDirection;
|
|
1957
|
+
const type = layerDirectionValue === definition.layerDirection.horizontal ? widthType : heightType;
|
|
1958
|
+
return {
|
|
1959
|
+
flex: type === definition.sizing.Fill ? "1 0 0" : "0 0 auto"
|
|
1960
|
+
};
|
|
1961
|
+
};
|
|
1668
1962
|
const useLayerFlex = (layerKey) => {
|
|
1669
1963
|
const { manager } = useContext(FragmentContext);
|
|
1670
1964
|
const [widthType] = useLayerValue(layerKey, "widthType", manager);
|
|
@@ -1680,48 +1974,121 @@ const useLayerFlex = (layerKey) => {
|
|
|
1680
1974
|
flex: type === definition.sizing.Fill ? "1 0 0" : "0 0 auto"
|
|
1681
1975
|
};
|
|
1682
1976
|
};
|
|
1977
|
+
const SKIP_OVERRIDE = { skipOverrideCheck: true };
|
|
1683
1978
|
const useLayerStyles = (layerKey) => {
|
|
1684
1979
|
try {
|
|
1685
|
-
if (!layerKey)
|
|
1686
|
-
throw new Error("Empty layer key");
|
|
1687
|
-
}
|
|
1980
|
+
if (!layerKey) throw new Error("Empty layer key");
|
|
1688
1981
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1689
|
-
const
|
|
1690
|
-
const
|
|
1691
|
-
const
|
|
1692
|
-
const
|
|
1693
|
-
const
|
|
1694
|
-
const
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
const
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1982
|
+
const { layerKey: instanceLayerKey } = useContext(InstanceContext$1);
|
|
1983
|
+
const { isDocument } = useRenderTarget();
|
|
1984
|
+
const resolved = useResolvedLayer(layerKey);
|
|
1985
|
+
const vars = useResolvedLayerVariables(resolved.layer, resolved.rawLayer);
|
|
1986
|
+
const paintResolved = useResolvedLayer(vars.values.paint, SKIP_OVERRIDE);
|
|
1987
|
+
const paintVars = useResolvedLayerVariables(
|
|
1988
|
+
paintResolved.layer,
|
|
1989
|
+
paintResolved.rawLayer
|
|
1990
|
+
);
|
|
1991
|
+
const borderResolved = useResolvedLayer(vars.values.border, SKIP_OVERRIDE);
|
|
1992
|
+
const borderVars = useResolvedLayerVariables(
|
|
1993
|
+
borderResolved.layer,
|
|
1994
|
+
borderResolved.rawLayer
|
|
1995
|
+
);
|
|
1996
|
+
const borderPaintResolved = useResolvedLayer(
|
|
1997
|
+
borderVars.values.paint,
|
|
1998
|
+
SKIP_OVERRIDE
|
|
1999
|
+
);
|
|
2000
|
+
const borderPaintVars = useResolvedLayerVariables(
|
|
2001
|
+
borderPaintResolved.layer,
|
|
2002
|
+
borderPaintResolved.rawLayer
|
|
2003
|
+
);
|
|
2004
|
+
const imageResolved = useResolvedLayer(
|
|
2005
|
+
paintVars.values.image,
|
|
2006
|
+
SKIP_OVERRIDE
|
|
2007
|
+
);
|
|
2008
|
+
const imageVars = useResolvedLayerVariables(
|
|
2009
|
+
imageResolved.layer,
|
|
2010
|
+
imageResolved.rawLayer
|
|
2011
|
+
);
|
|
2012
|
+
const imageSizeLayerKey = isVariableLink$1(paintVars.rawValues.image) ? paintVars.rawValues.image : layerKey;
|
|
2013
|
+
const imageSizeResolved = useResolvedLayer(
|
|
2014
|
+
imageSizeLayerKey,
|
|
2015
|
+
SKIP_OVERRIDE
|
|
2016
|
+
);
|
|
2017
|
+
const imageSizeVars = useResolvedLayerVariables(
|
|
2018
|
+
imageSizeResolved.layer,
|
|
2019
|
+
imageSizeResolved.rawLayer
|
|
2020
|
+
);
|
|
2021
|
+
const parentLayerKey = keyOfEntity(
|
|
2022
|
+
getParent(fragmentManager, layerKey)
|
|
2023
|
+
);
|
|
2024
|
+
const parentResolved = useResolvedLayer(
|
|
2025
|
+
parentLayerKey,
|
|
2026
|
+
SKIP_OVERRIDE
|
|
2027
|
+
);
|
|
2028
|
+
const parentVars = useResolvedLayerVariables(
|
|
2029
|
+
parentResolved.layer,
|
|
2030
|
+
parentResolved.rawLayer
|
|
2031
|
+
);
|
|
2032
|
+
const instanceResolved = useResolvedLayer(
|
|
2033
|
+
instanceLayerKey,
|
|
2034
|
+
SKIP_OVERRIDE
|
|
2035
|
+
);
|
|
2036
|
+
const instanceVars = useResolvedLayerVariables(
|
|
2037
|
+
instanceResolved.layer,
|
|
2038
|
+
instanceResolved.rawLayer
|
|
2039
|
+
);
|
|
2040
|
+
const paint = calcLayerPaint(paintVars);
|
|
2041
|
+
const borderPaint = calcLayerPaint(borderPaintVars);
|
|
2042
|
+
const linearGradient = useLayerLinearGradient(paint.linearGradientLink);
|
|
2043
|
+
const borderLinearGradient = useLayerLinearGradient(
|
|
2044
|
+
borderPaint.linearGradientLink
|
|
2045
|
+
);
|
|
2046
|
+
const context = {
|
|
2047
|
+
isDocument,
|
|
2048
|
+
isTopLevel: isTopLevel(fragmentManager, layerKey),
|
|
2049
|
+
instanceLayerKey
|
|
2050
|
+
};
|
|
2051
|
+
const layerSize = calcLayerSize(vars);
|
|
2052
|
+
const position = calcLayerPosition(
|
|
2053
|
+
resolved,
|
|
2054
|
+
vars,
|
|
2055
|
+
parentResolved,
|
|
2056
|
+
instanceResolved,
|
|
2057
|
+
instanceVars,
|
|
2058
|
+
context
|
|
2059
|
+
);
|
|
2060
|
+
const background = calcLayerBackground(
|
|
2061
|
+
paintVars,
|
|
2062
|
+
imageVars,
|
|
2063
|
+
imageSizeVars,
|
|
2064
|
+
linearGradient
|
|
2065
|
+
);
|
|
2066
|
+
const display = calcLayerDisplay(vars);
|
|
2067
|
+
const border = calcLayerBorder(
|
|
2068
|
+
borderVars,
|
|
2069
|
+
borderPaintVars,
|
|
2070
|
+
borderLinearGradient,
|
|
2071
|
+
paintVars,
|
|
2072
|
+
linearGradient
|
|
1703
2073
|
);
|
|
1704
|
-
const
|
|
1705
|
-
const textStyles =
|
|
1706
|
-
const
|
|
2074
|
+
const layout = calcLayerLayout(vars);
|
|
2075
|
+
const textStyles = calcLayerTextStyles(vars);
|
|
2076
|
+
const layerFlex = calcLayerFlex(vars, parentVars);
|
|
1707
2077
|
return {
|
|
1708
|
-
// ...(props ?? {}),
|
|
1709
2078
|
...background,
|
|
1710
2079
|
...border,
|
|
1711
2080
|
...position,
|
|
1712
|
-
opacity,
|
|
1713
|
-
overflow,
|
|
1714
|
-
rotate: isValue(rotate) ? `${rotate}deg` : null,
|
|
1715
|
-
"border-radius": isValue(
|
|
1716
|
-
"white-space": whiteSpace,
|
|
1717
|
-
"z-index": zIndex !== -1 ? zIndex : null,
|
|
2081
|
+
opacity: vars.values.opacity,
|
|
2082
|
+
overflow: vars.values.overflow,
|
|
2083
|
+
rotate: isValue(vars.values.rotate) ? `${vars.values.rotate}deg` : null,
|
|
2084
|
+
"border-radius": isValue(vars.rawValues.borderRadius) ? vars.values.borderRadius : null,
|
|
2085
|
+
"white-space": vars.values.whiteSpace,
|
|
2086
|
+
"z-index": vars.values.zIndex !== -1 ? vars.values.zIndex : null,
|
|
1718
2087
|
...layout,
|
|
1719
2088
|
...layerSize,
|
|
1720
2089
|
...textStyles,
|
|
1721
2090
|
...layerFlex,
|
|
1722
2091
|
display
|
|
1723
|
-
// "user-select": "none",
|
|
1724
|
-
// ...cssOverride,
|
|
1725
2092
|
};
|
|
1726
2093
|
} catch (e) {
|
|
1727
2094
|
return {};
|
|
@@ -1826,6 +2193,34 @@ const useStyleSheet = (manager) => {
|
|
|
1826
2193
|
unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? noop
|
|
1827
2194
|
};
|
|
1828
2195
|
};
|
|
2196
|
+
const useGlobalManager = (globalManager) => {
|
|
2197
|
+
var _a, _b;
|
|
2198
|
+
const currentGlobalManager = useContext(GlobalManagerContext);
|
|
2199
|
+
const resultManager = globalManager ?? currentGlobalManager;
|
|
2200
|
+
const [fragmentsGraph] = useGraph(
|
|
2201
|
+
resultManager,
|
|
2202
|
+
(_a = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _a.key
|
|
2203
|
+
);
|
|
2204
|
+
const queryFragmentManager = (id) => {
|
|
2205
|
+
var _a2, _b2;
|
|
2206
|
+
return (_b2 = (_a2 = resultManager == null ? void 0 : resultManager.$load) == null ? void 0 : _a2.loadFragment) == null ? void 0 : _b2.call(_a2, id);
|
|
2207
|
+
};
|
|
2208
|
+
const queryArea = (id) => {
|
|
2209
|
+
var _a2, _b2;
|
|
2210
|
+
return (_b2 = (_a2 = resultManager == null ? void 0 : resultManager.$load) == null ? void 0 : _a2.loadArea) == null ? void 0 : _b2.call(_a2, id);
|
|
2211
|
+
};
|
|
2212
|
+
const setRenderTarget = (value) => {
|
|
2213
|
+
resultManager == null ? void 0 : resultManager.setRenderTarget(value);
|
|
2214
|
+
};
|
|
2215
|
+
return {
|
|
2216
|
+
fragmentsGraph,
|
|
2217
|
+
manager: resultManager,
|
|
2218
|
+
queryFragmentManager,
|
|
2219
|
+
queryArea,
|
|
2220
|
+
getFragmentManager: ((_b = resultManager == null ? void 0 : resultManager.$fragments) == null ? void 0 : _b.getManager) ?? noop,
|
|
2221
|
+
setRenderTarget
|
|
2222
|
+
};
|
|
2223
|
+
};
|
|
1829
2224
|
const useLayerInteractions = (layerKey, options) => {
|
|
1830
2225
|
const pause = (options == null ? void 0 : options.pauseInteractions) ?? false;
|
|
1831
2226
|
const { manager: globalManager } = useGlobalManager();
|
|
@@ -1850,12 +2245,14 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
1850
2245
|
});
|
|
1851
2246
|
const fireEvent = useCallback(
|
|
1852
2247
|
(eventLink) => {
|
|
1853
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2248
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1854
2249
|
const eventType = (_a = entityOfKey(eventLink)) == null ? void 0 : _a._type;
|
|
1855
2250
|
const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
|
|
2251
|
+
console.log(scopes, eventLink, eventType, eventValue);
|
|
1856
2252
|
if (eventType === definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
|
|
1857
2253
|
if (!areaScope) return null;
|
|
1858
|
-
(
|
|
2254
|
+
console.log((_c = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _c.reachGoal);
|
|
2255
|
+
(_e = (_d = globalManager == null ? void 0 : globalManager.$metrics) == null ? void 0 : _d.reachGoal) == null ? void 0 : _e.call(_d, {
|
|
1859
2256
|
goalId: eventValue == null ? void 0 : eventValue.goalId,
|
|
1860
2257
|
...pick(areaScope, "variantId", "campaignId", "areaId")
|
|
1861
2258
|
});
|
|
@@ -1863,10 +2260,10 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
1863
2260
|
if (eventType === definition.nodes.MutateEvent) {
|
|
1864
2261
|
const target = eventValue == null ? void 0 : eventValue.target;
|
|
1865
2262
|
const targetLayer = getNormalizeLayer(target, fragmentManager);
|
|
1866
|
-
const value = (eventValue == null ? void 0 : eventValue.value) ?? ((
|
|
2263
|
+
const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_f = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _f.defaultValue);
|
|
1867
2264
|
if (isVariableLink$1(target) && isValue(value)) {
|
|
1868
|
-
const targetId = (
|
|
1869
|
-
(
|
|
2265
|
+
const targetId = (_g = entityOfKey(target)) == null ? void 0 : _g._id;
|
|
2266
|
+
(_h = instanceScope == null ? void 0 : instanceScope.onChangeProps) == null ? void 0 : _h.call(instanceScope, targetId, value);
|
|
1870
2267
|
}
|
|
1871
2268
|
}
|
|
1872
2269
|
},
|
|
@@ -2073,52 +2470,249 @@ const useCollection = (layerKey, options) => {
|
|
|
2073
2470
|
...frame
|
|
2074
2471
|
};
|
|
2075
2472
|
};
|
|
2076
|
-
const
|
|
2077
|
-
if (
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2473
|
+
const resolveFieldRef = (field, manager) => {
|
|
2474
|
+
if (isVariableLink$1(field)) {
|
|
2475
|
+
return manager.resolve(field);
|
|
2476
|
+
}
|
|
2477
|
+
if (isObject(field) && (field == null ? void 0 : field._id)) {
|
|
2478
|
+
return field;
|
|
2479
|
+
}
|
|
2480
|
+
return void 0;
|
|
2481
|
+
};
|
|
2482
|
+
const fieldRefToKey = (field) => {
|
|
2483
|
+
if (isVariableLink$1(field)) {
|
|
2484
|
+
return field;
|
|
2485
|
+
}
|
|
2486
|
+
if (isObject(field) && (field == null ? void 0 : field._type) && (field == null ? void 0 : field._id)) {
|
|
2487
|
+
return keyOfEntity(field);
|
|
2488
|
+
}
|
|
2489
|
+
return void 0;
|
|
2490
|
+
};
|
|
2491
|
+
const collectLeafKeys = (defVar, manager, keys) => {
|
|
2492
|
+
if (!(defVar == null ? void 0 : defVar.fields)) return;
|
|
2493
|
+
const fields = cleanGraph(defVar.fields);
|
|
2494
|
+
for (const fieldRef of Object.values(fields)) {
|
|
2495
|
+
const fieldVar = resolveFieldRef(fieldRef, manager);
|
|
2496
|
+
const fieldKey = fieldRefToKey(fieldRef);
|
|
2089
2497
|
if (!fieldVar || !fieldKey) continue;
|
|
2090
2498
|
if (fieldVar.type === definition.variableType.Object && fieldVar.fields) {
|
|
2091
|
-
|
|
2499
|
+
collectLeafKeys(fieldVar, manager, keys);
|
|
2092
2500
|
} else {
|
|
2093
2501
|
keys.push(fieldKey);
|
|
2094
2502
|
}
|
|
2095
2503
|
}
|
|
2096
2504
|
};
|
|
2097
|
-
const
|
|
2098
|
-
|
|
2505
|
+
const flattenObjectFields = (defVar, valueObj, manager, result) => {
|
|
2506
|
+
if (!(defVar == null ? void 0 : defVar.fields)) return;
|
|
2507
|
+
const fields = cleanGraph(defVar.fields);
|
|
2508
|
+
for (const [fieldName, fieldRef] of Object.entries(fields)) {
|
|
2509
|
+
const fieldVar = resolveFieldRef(fieldRef, manager);
|
|
2510
|
+
if (!(fieldVar == null ? void 0 : fieldVar._id)) continue;
|
|
2511
|
+
const fieldValue = valueObj[fieldName] ?? valueObj[fieldVar._id];
|
|
2512
|
+
if (fieldValue === void 0) continue;
|
|
2513
|
+
if (fieldVar.type === definition.variableType.Object && fieldVar.fields && isObject(fieldValue)) {
|
|
2514
|
+
flattenObjectFields(
|
|
2515
|
+
fieldVar,
|
|
2516
|
+
fieldValue,
|
|
2517
|
+
manager,
|
|
2518
|
+
result
|
|
2519
|
+
);
|
|
2520
|
+
} else {
|
|
2521
|
+
result[fieldVar._id] = fieldValue;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
const buildFieldIdMapping = (childDef, parentDef, childManager, parentManager) => {
|
|
2526
|
+
const mapping = {};
|
|
2527
|
+
if (!(childDef == null ? void 0 : childDef.fields) || !(parentDef == null ? void 0 : parentDef.fields)) return mapping;
|
|
2528
|
+
const childFields = cleanGraph(childDef.fields);
|
|
2529
|
+
const parentFields = cleanGraph(parentDef.fields);
|
|
2530
|
+
for (const [fieldName, childFieldRef] of Object.entries(childFields)) {
|
|
2531
|
+
const parentFieldRef = parentFields[fieldName];
|
|
2532
|
+
if (!parentFieldRef) continue;
|
|
2533
|
+
const childFieldVar = resolveFieldRef(childFieldRef, childManager);
|
|
2534
|
+
if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
|
|
2535
|
+
const parentFieldVar = resolveFieldRef(parentFieldRef, parentManager);
|
|
2536
|
+
if (!(parentFieldVar == null ? void 0 : parentFieldVar._id)) continue;
|
|
2537
|
+
if (childFieldVar.type === definition.variableType.Object && childFieldVar.fields && (parentFieldVar == null ? void 0 : parentFieldVar.type) === definition.variableType.Object && (parentFieldVar == null ? void 0 : parentFieldVar.fields)) {
|
|
2538
|
+
Object.assign(
|
|
2539
|
+
mapping,
|
|
2540
|
+
buildFieldIdMapping(
|
|
2541
|
+
childFieldVar,
|
|
2542
|
+
parentFieldVar,
|
|
2543
|
+
childManager,
|
|
2544
|
+
parentManager
|
|
2545
|
+
)
|
|
2546
|
+
);
|
|
2547
|
+
continue;
|
|
2548
|
+
}
|
|
2549
|
+
mapping[parentFieldVar._id] = childFieldVar._id;
|
|
2550
|
+
}
|
|
2551
|
+
return mapping;
|
|
2552
|
+
};
|
|
2553
|
+
const resolveArrayItems = (items, manager) => {
|
|
2554
|
+
const result = [];
|
|
2555
|
+
for (const item of items) {
|
|
2556
|
+
if (isLink$1(item)) {
|
|
2557
|
+
const resolved = manager.resolve(item);
|
|
2558
|
+
if (!resolved) continue;
|
|
2559
|
+
const payload = isObject(resolved.value) ? resolved.value : resolved;
|
|
2560
|
+
if (isObject(payload)) {
|
|
2561
|
+
result.push(cleanGraph(payload));
|
|
2562
|
+
}
|
|
2563
|
+
} else if (isObject(item)) {
|
|
2564
|
+
const payload = isObject(item.value) ? item.value : item;
|
|
2565
|
+
result.push(cleanGraph(payload));
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
return result;
|
|
2569
|
+
};
|
|
2570
|
+
const remapArrayItems = (items, mapping) => {
|
|
2571
|
+
return items.map((item) => {
|
|
2572
|
+
const remapped = {};
|
|
2573
|
+
for (const [key, value] of Object.entries(item)) {
|
|
2574
|
+
const newKey = mapping[key] ?? key;
|
|
2575
|
+
remapped[newKey] = value;
|
|
2576
|
+
}
|
|
2577
|
+
return remapped;
|
|
2578
|
+
});
|
|
2579
|
+
};
|
|
2580
|
+
const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
2581
|
+
const { readVariable, _dep } = useReadVariable();
|
|
2582
|
+
const leafKeys = useMemo(() => {
|
|
2099
2583
|
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2100
2584
|
const keys = [];
|
|
2101
2585
|
for (const defKey of definitions) {
|
|
2102
2586
|
const defVar = manager.resolve(defKey);
|
|
2103
|
-
if (
|
|
2104
|
-
|
|
2587
|
+
if (!defVar) continue;
|
|
2588
|
+
if (defVar.type === definition.variableType.Object && defVar.fields) {
|
|
2589
|
+
collectLeafKeys(defVar, manager, keys);
|
|
2590
|
+
} else if (defVar.type === definition.variableType.Array && defVar.definition) {
|
|
2591
|
+
const arrDef = resolveFieldRef(defVar.definition, manager);
|
|
2592
|
+
if ((arrDef == null ? void 0 : arrDef.type) === definition.variableType.Object && (arrDef == null ? void 0 : arrDef.fields)) {
|
|
2593
|
+
collectLeafKeys(arrDef, manager, keys);
|
|
2594
|
+
}
|
|
2105
2595
|
}
|
|
2106
2596
|
}
|
|
2107
2597
|
return keys;
|
|
2108
2598
|
}, [definitions, manager]);
|
|
2109
|
-
const
|
|
2110
|
-
|
|
2111
|
-
|
|
2599
|
+
const leafLayers = useGraphStack(leafKeys.length ? manager : null, leafKeys);
|
|
2600
|
+
const arrayItemKeys = useMemo(() => {
|
|
2601
|
+
var _a;
|
|
2602
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2603
|
+
const resolveManager = parentManager ?? manager;
|
|
2604
|
+
if (!resolveManager) return [];
|
|
2605
|
+
const keys = [];
|
|
2606
|
+
for (const defKey of definitions) {
|
|
2607
|
+
const defVar = manager.resolve(defKey);
|
|
2608
|
+
if (!(defVar == null ? void 0 : defVar._id)) continue;
|
|
2609
|
+
if (defVar.type !== definition.variableType.Array || !defVar.definition)
|
|
2610
|
+
continue;
|
|
2611
|
+
const propValue = props[defVar._id];
|
|
2612
|
+
if (!isVariableLink$1(propValue)) continue;
|
|
2613
|
+
const parentVar = resolveManager.resolve(propValue);
|
|
2614
|
+
if ((parentVar == null ? void 0 : parentVar.type) !== definition.variableType.Array) continue;
|
|
2615
|
+
const items = parentVar.defaultValue;
|
|
2616
|
+
if (!Array.isArray(items)) continue;
|
|
2617
|
+
for (const item of items) {
|
|
2618
|
+
if (isLink$1(item)) {
|
|
2619
|
+
keys.push(item);
|
|
2620
|
+
const resolved = resolveManager.resolve(item);
|
|
2621
|
+
if ((resolved == null ? void 0 : resolved.value) && isObject(resolved.value) && ((_a = resolved.value) == null ? void 0 : _a._type)) {
|
|
2622
|
+
const valueKey = keyOfEntity(resolved.value);
|
|
2623
|
+
if (valueKey) keys.push(valueKey);
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
return keys;
|
|
2629
|
+
}, [definitions, manager, parentManager, props, _dep]);
|
|
2630
|
+
const arrayItemLayers = useGraphStack(
|
|
2631
|
+
arrayItemKeys.length ? parentManager ?? manager : null,
|
|
2632
|
+
arrayItemKeys
|
|
2112
2633
|
);
|
|
2113
2634
|
return useMemo(() => {
|
|
2635
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length)) return props;
|
|
2636
|
+
const resolveManager = parentManager ?? manager;
|
|
2114
2637
|
const base = {};
|
|
2115
|
-
for (const layer of
|
|
2638
|
+
for (const layer of leafLayers) {
|
|
2116
2639
|
if ((layer == null ? void 0 : layer._id) && (layer == null ? void 0 : layer.defaultValue) != null) {
|
|
2117
2640
|
base[layer._id] = layer.defaultValue;
|
|
2118
2641
|
}
|
|
2119
2642
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2643
|
+
const expanded = {};
|
|
2644
|
+
const handledPropKeys = /* @__PURE__ */ new Set();
|
|
2645
|
+
for (const defKey of definitions) {
|
|
2646
|
+
const defVar = manager.resolve(defKey);
|
|
2647
|
+
if (!(defVar == null ? void 0 : defVar._id)) continue;
|
|
2648
|
+
const propValue = props[defVar._id];
|
|
2649
|
+
handledPropKeys.add(defVar._id);
|
|
2650
|
+
if (propValue === void 0) continue;
|
|
2651
|
+
if (defVar.type === definition.variableType.Object && defVar.fields) {
|
|
2652
|
+
if (isObject(propValue)) {
|
|
2653
|
+
flattenObjectFields(
|
|
2654
|
+
defVar,
|
|
2655
|
+
propValue,
|
|
2656
|
+
manager,
|
|
2657
|
+
expanded
|
|
2658
|
+
);
|
|
2659
|
+
continue;
|
|
2660
|
+
}
|
|
2661
|
+
expanded[defVar._id] = propValue;
|
|
2662
|
+
continue;
|
|
2663
|
+
}
|
|
2664
|
+
if (defVar.type === definition.variableType.Array && defVar.definition) {
|
|
2665
|
+
if (isVariableLink$1(propValue) && resolveManager) {
|
|
2666
|
+
const parentVar = resolveManager.resolve(propValue);
|
|
2667
|
+
if ((parentVar == null ? void 0 : parentVar.type) === definition.variableType.Array && (parentVar == null ? void 0 : parentVar.definition)) {
|
|
2668
|
+
const { value: resolvedArray } = readVariable(propValue);
|
|
2669
|
+
if (Array.isArray(resolvedArray)) {
|
|
2670
|
+
const concreteItems = resolveArrayItems(
|
|
2671
|
+
resolvedArray,
|
|
2672
|
+
resolveManager
|
|
2673
|
+
);
|
|
2674
|
+
const childDef = resolveFieldRef(defVar.definition, manager);
|
|
2675
|
+
const parentDef = resolveFieldRef(
|
|
2676
|
+
parentVar.definition,
|
|
2677
|
+
resolveManager
|
|
2678
|
+
);
|
|
2679
|
+
if ((childDef == null ? void 0 : childDef.type) === definition.variableType.Object && (childDef == null ? void 0 : childDef.fields) && (parentDef == null ? void 0 : parentDef.type) === definition.variableType.Object && (parentDef == null ? void 0 : parentDef.fields)) {
|
|
2680
|
+
const mapping = buildFieldIdMapping(
|
|
2681
|
+
childDef,
|
|
2682
|
+
parentDef,
|
|
2683
|
+
manager,
|
|
2684
|
+
resolveManager
|
|
2685
|
+
);
|
|
2686
|
+
expanded[defVar._id] = remapArrayItems(concreteItems, mapping);
|
|
2687
|
+
} else {
|
|
2688
|
+
expanded[defVar._id] = concreteItems;
|
|
2689
|
+
}
|
|
2690
|
+
continue;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
expanded[defVar._id] = propValue;
|
|
2694
|
+
continue;
|
|
2695
|
+
}
|
|
2696
|
+
expanded[defVar._id] = propValue;
|
|
2697
|
+
continue;
|
|
2698
|
+
}
|
|
2699
|
+
expanded[defVar._id] = propValue;
|
|
2700
|
+
}
|
|
2701
|
+
for (const [key, value] of Object.entries(props)) {
|
|
2702
|
+
if (!handledPropKeys.has(key) && !(key in expanded)) {
|
|
2703
|
+
expanded[key] = value;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
return { ...base, ...expanded };
|
|
2707
|
+
}, [
|
|
2708
|
+
leafLayers,
|
|
2709
|
+
arrayItemLayers,
|
|
2710
|
+
props,
|
|
2711
|
+
manager,
|
|
2712
|
+
parentManager,
|
|
2713
|
+
definitions,
|
|
2714
|
+
_dep
|
|
2715
|
+
]);
|
|
2122
2716
|
};
|
|
2123
2717
|
const CollectionItem = ({
|
|
2124
2718
|
layer,
|
|
@@ -2132,9 +2726,7 @@ const CollectionItem = ({
|
|
|
2132
2726
|
keyOfEntity(layer);
|
|
2133
2727
|
const definitionId = ((_a = entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
|
|
2134
2728
|
const value = layer.value ?? layer;
|
|
2135
|
-
const inputProps =
|
|
2136
|
-
...value
|
|
2137
|
-
} : {
|
|
2729
|
+
const inputProps = {
|
|
2138
2730
|
[definitionId]: value
|
|
2139
2731
|
};
|
|
2140
2732
|
const props = cleanGraph(inputProps);
|
|
@@ -2142,7 +2734,7 @@ const CollectionItem = ({
|
|
|
2142
2734
|
() => sourceDefinition ? [sourceDefinition] : [],
|
|
2143
2735
|
[sourceDefinition]
|
|
2144
2736
|
);
|
|
2145
|
-
const expandedProps =
|
|
2737
|
+
const expandedProps = useExtractProps(props, manager, void 0, definitions);
|
|
2146
2738
|
const cssVars = useMemo(
|
|
2147
2739
|
() => toCssCustomProperties(expandedProps),
|
|
2148
2740
|
[expandedProps]
|
|
@@ -2280,24 +2872,18 @@ const Frame = ({
|
|
|
2280
2872
|
}
|
|
2281
2873
|
);
|
|
2282
2874
|
};
|
|
2283
|
-
const useIsomorphicEffect = (callback, deps) => {
|
|
2284
|
-
useEffect(callback, deps);
|
|
2285
|
-
if (!isBrowser$1) {
|
|
2286
|
-
callback();
|
|
2287
|
-
}
|
|
2288
|
-
};
|
|
2289
2875
|
const useCssChunk = (linkKey) => {
|
|
2290
2876
|
const { manager } = useContext(FragmentContext);
|
|
2291
2877
|
const [chunkId] = useLayerValue(linkKey, "chunkId", { manager });
|
|
2292
2878
|
const [enabled] = useLayerValue(linkKey, "enabled", { manager });
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
}, [enabled]);
|
|
2879
|
+
const { addCssChunk } = useStyleSheet(manager);
|
|
2880
|
+
useEffect(() => {
|
|
2881
|
+
if (!enabled || !chunkId) return;
|
|
2882
|
+
const cleanup = addCssChunk(chunkId);
|
|
2883
|
+
return () => {
|
|
2884
|
+
cleanup();
|
|
2885
|
+
};
|
|
2886
|
+
}, [enabled, chunkId, addCssChunk]);
|
|
2301
2887
|
};
|
|
2302
2888
|
const CssChunk = ({ linkKey }) => {
|
|
2303
2889
|
useCssChunk(linkKey);
|
|
@@ -2311,23 +2897,18 @@ const useFragmentManager = (fragmentId, inputGlobalManager) => {
|
|
|
2311
2897
|
getFragmentManager,
|
|
2312
2898
|
queryFragmentManager
|
|
2313
2899
|
} = useGlobalManager(inputGlobalManager);
|
|
2314
|
-
const [loading, setLoading] = useState(false);
|
|
2315
2900
|
const manager = getFragmentManager(fragmentId);
|
|
2901
|
+
const loading = !!fragmentId && !manager;
|
|
2316
2902
|
useEffect(() => {
|
|
2317
|
-
(
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
await queryFragmentManager(fragmentId);
|
|
2321
|
-
setLoading(false);
|
|
2322
|
-
}
|
|
2323
|
-
})();
|
|
2903
|
+
if (fragmentsGraph && !getFragmentManager(fragmentId) && !!fragmentId) {
|
|
2904
|
+
queryFragmentManager(fragmentId);
|
|
2905
|
+
}
|
|
2324
2906
|
}, [fragmentId, fragmentsGraph]);
|
|
2325
2907
|
return {
|
|
2326
2908
|
loading,
|
|
2327
2909
|
manager,
|
|
2328
2910
|
fragmentLayerKey: (_a = manager == null ? void 0 : manager.$fragment) == null ? void 0 : _a.root,
|
|
2329
2911
|
queryFragmentManager
|
|
2330
|
-
// loadFragmentManager,
|
|
2331
2912
|
};
|
|
2332
2913
|
};
|
|
2333
2914
|
const useFragmentChildren = (fragmentId) => {
|
|
@@ -2385,7 +2966,7 @@ const useFragment = (fragmentId, globalManager) => {
|
|
|
2385
2966
|
const { properties: definitions } = useFragmentProperties(fragmentId);
|
|
2386
2967
|
const scopes = useContext(ScopeContext);
|
|
2387
2968
|
!(scopes == null ? void 0 : scopes.length);
|
|
2388
|
-
const { addLayerStyle,
|
|
2969
|
+
const { addLayerStyle, mount, unmount } = useStyleSheet(
|
|
2389
2970
|
fragmentContext.manager
|
|
2390
2971
|
);
|
|
2391
2972
|
if (fragmentContext.manager) {
|
|
@@ -2420,35 +3001,26 @@ const useFragment = (fragmentId, globalManager) => {
|
|
|
2420
3001
|
definitions
|
|
2421
3002
|
};
|
|
2422
3003
|
};
|
|
2423
|
-
const FragmentInternal = (
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
// fragmentManager={fragmentContext.manager}
|
|
2444
|
-
// layerKey={layerKey}
|
|
2445
|
-
// value={{
|
|
2446
|
-
// type: definition.scopeTypes.FragmentScope,
|
|
2447
|
-
// manager: fragmentContext.manager,
|
|
2448
|
-
// definitions,
|
|
2449
|
-
// }}
|
|
2450
|
-
// >
|
|
2451
|
-
/* @__PURE__ */ jsxs("div", { "data-key": layerKey, className: hash, children: [
|
|
3004
|
+
const FragmentInternal = memo(
|
|
3005
|
+
({
|
|
3006
|
+
fragmentId,
|
|
3007
|
+
globalManager,
|
|
3008
|
+
pauseInteractions,
|
|
3009
|
+
collectStyle,
|
|
3010
|
+
FrameElement = Frame
|
|
3011
|
+
}) => {
|
|
3012
|
+
const {
|
|
3013
|
+
children,
|
|
3014
|
+
fragmentContext,
|
|
3015
|
+
hash,
|
|
3016
|
+
chunkLinks,
|
|
3017
|
+
isResize,
|
|
3018
|
+
isTopFragment,
|
|
3019
|
+
definitions,
|
|
3020
|
+
layerKey
|
|
3021
|
+
} = useFragment(fragmentId);
|
|
3022
|
+
if (!fragmentContext.manager) return null;
|
|
3023
|
+
return /* @__PURE__ */ jsxs("div", { "data-key": layerKey, className: hash, children: [
|
|
2452
3024
|
chunkLinks.map((linkKey) => /* @__PURE__ */ jsx(CssChunk, { linkKey })),
|
|
2453
3025
|
children.map((childLink) => {
|
|
2454
3026
|
var _a;
|
|
@@ -2466,21 +3038,51 @@ const FragmentInternal = ({
|
|
|
2466
3038
|
childLink
|
|
2467
3039
|
);
|
|
2468
3040
|
})
|
|
2469
|
-
] })
|
|
2470
|
-
|
|
2471
|
-
|
|
3041
|
+
] });
|
|
3042
|
+
}
|
|
3043
|
+
);
|
|
2472
3044
|
const Fragment = (props) => {
|
|
2473
3045
|
const currentGlobalManager = useContext(GlobalManagerContext);
|
|
2474
3046
|
const { manager: resultGlobalManager } = useGlobalManager(
|
|
2475
3047
|
props.globalManager
|
|
2476
3048
|
);
|
|
2477
3049
|
const { manager } = useFragmentManager(props.fragmentId, resultGlobalManager);
|
|
2478
|
-
const
|
|
3050
|
+
const fragmentContextValue = useMemo(() => ({ manager }), [manager]);
|
|
3051
|
+
const Base = /* @__PURE__ */ jsx(FragmentContext.Provider, { value: fragmentContextValue, children: /* @__PURE__ */ jsx(FragmentInternal, { ...props }) });
|
|
2479
3052
|
if (!currentGlobalManager) {
|
|
2480
3053
|
return /* @__PURE__ */ jsx(GlobalManagerProvider, { value: resultGlobalManager, children: Base });
|
|
2481
3054
|
}
|
|
2482
3055
|
return Base;
|
|
2483
3056
|
};
|
|
3057
|
+
const resolveObjectToConcreteValue = (objectVar, manager, readVariable) => {
|
|
3058
|
+
const fields = cleanGraph(objectVar.fields);
|
|
3059
|
+
const result = {};
|
|
3060
|
+
for (const [fieldName, fieldRef] of Object.entries(fields)) {
|
|
3061
|
+
let fieldVar;
|
|
3062
|
+
let fieldKey;
|
|
3063
|
+
if (isVariableLink$1(fieldRef)) {
|
|
3064
|
+
fieldKey = fieldRef;
|
|
3065
|
+
fieldVar = manager == null ? void 0 : manager.resolve(fieldKey);
|
|
3066
|
+
} else if (isObject(fieldRef) && (fieldRef == null ? void 0 : fieldRef._id)) {
|
|
3067
|
+
fieldKey = keyOfEntity(fieldRef);
|
|
3068
|
+
fieldVar = fieldRef;
|
|
3069
|
+
}
|
|
3070
|
+
if (!fieldVar || !fieldKey) continue;
|
|
3071
|
+
if (fieldVar.type === definition.variableType.Object && fieldVar.fields) {
|
|
3072
|
+
result[fieldName] = resolveObjectToConcreteValue(
|
|
3073
|
+
fieldVar,
|
|
3074
|
+
manager,
|
|
3075
|
+
readVariable
|
|
3076
|
+
);
|
|
3077
|
+
} else {
|
|
3078
|
+
const { value } = readVariable(fieldKey);
|
|
3079
|
+
if (value != null) {
|
|
3080
|
+
result[fieldName] = value;
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
return result;
|
|
3085
|
+
};
|
|
2484
3086
|
const useInstanceProps = (instanceProps) => {
|
|
2485
3087
|
const isTopInstance = !(instanceProps == null ? void 0 : instanceProps.layerKey);
|
|
2486
3088
|
const { manager: loadedManager } = useFragmentManager(
|
|
@@ -2499,13 +3101,39 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2499
3101
|
};
|
|
2500
3102
|
}
|
|
2501
3103
|
const extractProps = cleanGraph(inputProps);
|
|
3104
|
+
const { readVariable } = useReadVariable();
|
|
3105
|
+
let resolvedProps = extractProps;
|
|
3106
|
+
if (!isTopInstance) {
|
|
3107
|
+
resolvedProps = {};
|
|
3108
|
+
for (const [key, value] of Object.entries(extractProps)) {
|
|
3109
|
+
if (!isVariableLink$1(value)) {
|
|
3110
|
+
resolvedProps[key] = value;
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
const varLayer = fragmentManager == null ? void 0 : fragmentManager.resolve(value);
|
|
3114
|
+
if ((varLayer == null ? void 0 : varLayer.type) === definition.variableType.Array) {
|
|
3115
|
+
resolvedProps[key] = value;
|
|
3116
|
+
continue;
|
|
3117
|
+
}
|
|
3118
|
+
if ((varLayer == null ? void 0 : varLayer.type) === definition.variableType.Object && (varLayer == null ? void 0 : varLayer.fields)) {
|
|
3119
|
+
resolvedProps[key] = resolveObjectToConcreteValue(
|
|
3120
|
+
varLayer,
|
|
3121
|
+
fragmentManager,
|
|
3122
|
+
readVariable
|
|
3123
|
+
);
|
|
3124
|
+
continue;
|
|
3125
|
+
}
|
|
3126
|
+
const { value: resolved } = readVariable(value);
|
|
3127
|
+
resolvedProps[key] = resolved;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
2502
3130
|
useEffect(() => {
|
|
2503
3131
|
if (isValue(instanceProps == null ? void 0 : instanceProps.props)) {
|
|
2504
3132
|
setLocalProps(instanceProps.props);
|
|
2505
3133
|
}
|
|
2506
3134
|
}, [instanceProps == null ? void 0 : instanceProps.props]);
|
|
2507
3135
|
return {
|
|
2508
|
-
props:
|
|
3136
|
+
props: resolvedProps,
|
|
2509
3137
|
onChangeProps: (variableId, value) => {
|
|
2510
3138
|
var _a;
|
|
2511
3139
|
setLocalProps((prev) => ({ ...prev, [variableId]: value }));
|
|
@@ -2582,7 +3210,7 @@ const InstanceInitial = ({
|
|
|
2582
3210
|
...instanceProps,
|
|
2583
3211
|
pauseInteractions
|
|
2584
3212
|
});
|
|
2585
|
-
const expandedProps =
|
|
3213
|
+
const expandedProps = useExtractProps(
|
|
2586
3214
|
props,
|
|
2587
3215
|
innerManager,
|
|
2588
3216
|
parentManager,
|
|
@@ -2593,49 +3221,56 @@ const InstanceInitial = ({
|
|
|
2593
3221
|
[expandedProps]
|
|
2594
3222
|
);
|
|
2595
3223
|
useSuspenseLoadFragment(globalManager, fragmentId, !ssr);
|
|
3224
|
+
const scopeValue = useMemo(
|
|
3225
|
+
() => ({
|
|
3226
|
+
type: definition.scopeTypes.InstanceScope,
|
|
3227
|
+
props: expandedProps,
|
|
3228
|
+
definitions,
|
|
3229
|
+
fragmentId,
|
|
3230
|
+
documentManager: innerManager,
|
|
3231
|
+
layerKey: instanceProps.layerKey,
|
|
3232
|
+
onChangeProps
|
|
3233
|
+
}),
|
|
3234
|
+
[
|
|
3235
|
+
expandedProps,
|
|
3236
|
+
definitions,
|
|
3237
|
+
fragmentId,
|
|
3238
|
+
innerManager,
|
|
3239
|
+
instanceProps.layerKey,
|
|
3240
|
+
onChangeProps
|
|
3241
|
+
]
|
|
3242
|
+
);
|
|
3243
|
+
const instanceContextValue = useMemo(
|
|
3244
|
+
() => ({
|
|
3245
|
+
layerKey: instanceProps.layerKey,
|
|
3246
|
+
definitions,
|
|
3247
|
+
innerManager,
|
|
3248
|
+
parentManager,
|
|
3249
|
+
props: expandedProps
|
|
3250
|
+
}),
|
|
3251
|
+
[
|
|
3252
|
+
instanceProps.layerKey,
|
|
3253
|
+
definitions,
|
|
3254
|
+
innerManager,
|
|
3255
|
+
parentManager,
|
|
3256
|
+
expandedProps
|
|
3257
|
+
]
|
|
3258
|
+
);
|
|
2596
3259
|
return /* @__PURE__ */ jsx(
|
|
2597
3260
|
Scope,
|
|
2598
3261
|
{
|
|
2599
3262
|
fragmentManager: innerManager,
|
|
2600
3263
|
layerKey: instanceProps.layerKey,
|
|
2601
|
-
value:
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
definitions,
|
|
2605
|
-
fragmentId,
|
|
2606
|
-
documentManager: innerManager,
|
|
2607
|
-
layerKey: instanceProps.layerKey,
|
|
2608
|
-
onChangeProps
|
|
2609
|
-
},
|
|
2610
|
-
children: /* @__PURE__ */ jsx(
|
|
2611
|
-
InstanceContext$1.Provider,
|
|
3264
|
+
value: scopeValue,
|
|
3265
|
+
children: /* @__PURE__ */ jsx(InstanceContext$1.Provider, { value: instanceContextValue, children: parentManager ? /* @__PURE__ */ jsx(
|
|
3266
|
+
Tag,
|
|
2612
3267
|
{
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
},
|
|
2620
|
-
children: parentManager ? /* @__PURE__ */ jsx(
|
|
2621
|
-
Tag,
|
|
2622
|
-
{
|
|
2623
|
-
className: classnames,
|
|
2624
|
-
"data-key": instanceProps.layerKey,
|
|
2625
|
-
style: { ...style, ...cssVars },
|
|
2626
|
-
...link.linkProps,
|
|
2627
|
-
...events,
|
|
2628
|
-
children: /* @__PURE__ */ jsx(
|
|
2629
|
-
Fragment,
|
|
2630
|
-
{
|
|
2631
|
-
fragmentId,
|
|
2632
|
-
globalManager,
|
|
2633
|
-
FrameElement,
|
|
2634
|
-
pauseInteractions
|
|
2635
|
-
}
|
|
2636
|
-
)
|
|
2637
|
-
}
|
|
2638
|
-
) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsx(
|
|
3268
|
+
className: classnames,
|
|
3269
|
+
"data-key": instanceProps.layerKey,
|
|
3270
|
+
style: { ...style, ...cssVars },
|
|
3271
|
+
...link.linkProps,
|
|
3272
|
+
...events,
|
|
3273
|
+
children: /* @__PURE__ */ jsx(
|
|
2639
3274
|
Fragment,
|
|
2640
3275
|
{
|
|
2641
3276
|
fragmentId,
|
|
@@ -2643,9 +3278,17 @@ const InstanceInitial = ({
|
|
|
2643
3278
|
FrameElement,
|
|
2644
3279
|
pauseInteractions
|
|
2645
3280
|
}
|
|
2646
|
-
)
|
|
3281
|
+
)
|
|
2647
3282
|
}
|
|
2648
|
-
)
|
|
3283
|
+
) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsx(
|
|
3284
|
+
Fragment,
|
|
3285
|
+
{
|
|
3286
|
+
fragmentId,
|
|
3287
|
+
globalManager,
|
|
3288
|
+
FrameElement,
|
|
3289
|
+
pauseInteractions
|
|
3290
|
+
}
|
|
3291
|
+
) }) })
|
|
2649
3292
|
}
|
|
2650
3293
|
);
|
|
2651
3294
|
};
|
|
@@ -2664,47 +3307,153 @@ const Instance = (props) => {
|
|
|
2664
3307
|
}
|
|
2665
3308
|
) });
|
|
2666
3309
|
};
|
|
2667
|
-
const
|
|
2668
|
-
|
|
2669
|
-
|
|
3310
|
+
const IDLE_STATE = {
|
|
3311
|
+
data: null,
|
|
3312
|
+
fetching: false,
|
|
3313
|
+
error: null
|
|
3314
|
+
};
|
|
3315
|
+
const useAsyncLoadArea = (globalManager, areaCode, skip) => {
|
|
3316
|
+
const [state, setState] = useState(IDLE_STATE);
|
|
3317
|
+
const areaCodeRef = useRef(areaCode);
|
|
3318
|
+
if (areaCodeRef.current !== areaCode) {
|
|
3319
|
+
areaCodeRef.current = areaCode;
|
|
3320
|
+
setState(IDLE_STATE);
|
|
3321
|
+
}
|
|
3322
|
+
useEffect(() => {
|
|
3323
|
+
var _a, _b;
|
|
3324
|
+
if (skip || !globalManager || !areaCode) return;
|
|
3325
|
+
const cache = getSuspenseCache(globalManager);
|
|
3326
|
+
const cacheKey = `area:${areaCode}`;
|
|
3327
|
+
if (cache.has(cacheKey)) {
|
|
3328
|
+
try {
|
|
3329
|
+
const cached = cache.get(cacheKey).read();
|
|
3330
|
+
setState({ data: cached, fetching: false, error: null });
|
|
3331
|
+
return;
|
|
3332
|
+
} catch (e) {
|
|
3333
|
+
if (!(e instanceof Promise)) {
|
|
3334
|
+
setState({ data: null, fetching: false, error: e });
|
|
3335
|
+
return;
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
const valueOrPromise = cache.has(cacheKey) ? void 0 : (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadArea) == null ? void 0 : _b.call(_a, areaCode);
|
|
3340
|
+
if (valueOrPromise != null && !(valueOrPromise instanceof Promise)) {
|
|
3341
|
+
createSuspenseResource(cacheKey, valueOrPromise, cache);
|
|
3342
|
+
setState({ data: valueOrPromise, fetching: false, error: null });
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3345
|
+
if (valueOrPromise instanceof Promise) {
|
|
3346
|
+
createSuspenseResource(cacheKey, valueOrPromise, cache);
|
|
3347
|
+
}
|
|
3348
|
+
setState({ data: null, fetching: true, error: null });
|
|
3349
|
+
let cancelled = false;
|
|
3350
|
+
const resource = cache.get(cacheKey);
|
|
3351
|
+
if (!resource) return;
|
|
3352
|
+
try {
|
|
3353
|
+
const data = resource.read();
|
|
3354
|
+
if (!cancelled) {
|
|
3355
|
+
setState({ data, fetching: false, error: null });
|
|
3356
|
+
}
|
|
3357
|
+
} catch (e) {
|
|
3358
|
+
if (e instanceof Promise) {
|
|
3359
|
+
e.then(() => {
|
|
3360
|
+
if (cancelled) return;
|
|
3361
|
+
try {
|
|
3362
|
+
const data = resource.read();
|
|
3363
|
+
setState({ data, fetching: false, error: null });
|
|
3364
|
+
} catch (err) {
|
|
3365
|
+
if (!cancelled) {
|
|
3366
|
+
setState({ data: null, fetching: false, error: err });
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
});
|
|
3370
|
+
} else if (!cancelled) {
|
|
3371
|
+
setState({ data: null, fetching: false, error: e });
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
return () => {
|
|
3375
|
+
cancelled = true;
|
|
3376
|
+
};
|
|
3377
|
+
}, [skip, globalManager, areaCode]);
|
|
3378
|
+
if (skip) return IDLE_STATE;
|
|
3379
|
+
return state;
|
|
3380
|
+
};
|
|
3381
|
+
const resolveSuspense = (options) => {
|
|
3382
|
+
if ((options == null ? void 0 : options.suspense) !== void 0) return options.suspense;
|
|
3383
|
+
if ((options == null ? void 0 : options.ssr) !== void 0) return options.ssr;
|
|
3384
|
+
return false;
|
|
3385
|
+
};
|
|
3386
|
+
const useArea = (areaCode, options) => {
|
|
3387
|
+
const { manager: globalManager } = useGlobalManager(
|
|
2670
3388
|
options == null ? void 0 : options.globalManager
|
|
2671
3389
|
);
|
|
2672
|
-
const
|
|
2673
|
-
const
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
3390
|
+
const suspense = resolveSuspense(options);
|
|
3391
|
+
const skip = !globalManager || !(isBrowser || suspense);
|
|
3392
|
+
const suspenseData = useSuspenseLoadArea(
|
|
3393
|
+
globalManager,
|
|
3394
|
+
areaCode,
|
|
3395
|
+
!suspense || skip
|
|
3396
|
+
);
|
|
3397
|
+
const asyncState = useAsyncLoadArea(
|
|
3398
|
+
globalManager,
|
|
3399
|
+
areaCode,
|
|
3400
|
+
suspense || skip
|
|
3401
|
+
);
|
|
3402
|
+
if (skip) {
|
|
3403
|
+
return { data: null, fetching: false, error: null };
|
|
3404
|
+
}
|
|
3405
|
+
if (suspense) {
|
|
3406
|
+
return {
|
|
3407
|
+
data: suspenseData ?? null,
|
|
3408
|
+
fetching: false,
|
|
3409
|
+
error: null
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
const throwOnError = (options == null ? void 0 : options.throwOnError) ?? true;
|
|
3413
|
+
if (throwOnError && asyncState.error) {
|
|
3414
|
+
throw asyncState.error;
|
|
3415
|
+
}
|
|
3416
|
+
return asyncState;
|
|
3417
|
+
};
|
|
3418
|
+
const AreaInitial = (areaProps) => {
|
|
3419
|
+
const { data: areaData } = useArea(areaProps.areaCode, {
|
|
3420
|
+
suspense: true,
|
|
3421
|
+
globalManager: areaProps.globalManager
|
|
3422
|
+
});
|
|
3423
|
+
const { manager: globalManager } = useGlobalManager(
|
|
3424
|
+
areaProps.globalManager
|
|
2677
3425
|
);
|
|
2678
3426
|
const { manager: fragmentManager } = useFragmentManager(
|
|
2679
3427
|
areaData == null ? void 0 : areaData.fragmentId,
|
|
2680
|
-
|
|
3428
|
+
globalManager
|
|
2681
3429
|
);
|
|
2682
3430
|
const resultProps = useMemo(
|
|
2683
|
-
() => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(
|
|
2684
|
-
[areaData,
|
|
3431
|
+
() => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(areaProps == null ? void 0 : areaProps.props) ?? {} }),
|
|
3432
|
+
[areaData, areaProps]
|
|
2685
3433
|
);
|
|
2686
|
-
return {
|
|
2687
|
-
...areaData,
|
|
2688
|
-
fragmentManager,
|
|
2689
|
-
props: resultProps,
|
|
2690
|
-
globalManager: resultGlobalManager
|
|
2691
|
-
};
|
|
2692
|
-
};
|
|
2693
|
-
const AreaInitial = (areaProps) => {
|
|
2694
|
-
const areaData = useArea(areaProps);
|
|
2695
3434
|
if (!areaData) return null;
|
|
2696
|
-
|
|
3435
|
+
const areaManager = useMemo(
|
|
3436
|
+
() => createAreaManager({
|
|
3437
|
+
areaId: areaData.areaId,
|
|
3438
|
+
campaignId: areaData.campaignId,
|
|
3439
|
+
variantId: areaData.variantId,
|
|
3440
|
+
areaProperties: areaData.areaProperties
|
|
3441
|
+
}),
|
|
3442
|
+
[areaData.areaId]
|
|
3443
|
+
);
|
|
3444
|
+
return /* @__PURE__ */ jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsx(
|
|
2697
3445
|
Scope,
|
|
2698
3446
|
{
|
|
2699
|
-
fragmentManager
|
|
3447
|
+
fragmentManager,
|
|
2700
3448
|
layerKey: "Area",
|
|
2701
3449
|
value: {
|
|
2702
3450
|
type: definition.scopeTypes.AreaScope,
|
|
3451
|
+
areaManager,
|
|
2703
3452
|
...areaData ?? {}
|
|
2704
3453
|
},
|
|
2705
|
-
children: /* @__PURE__ */ jsx(Instance, { fragmentId: areaData.fragmentId, props:
|
|
3454
|
+
children: /* @__PURE__ */ jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
|
|
2706
3455
|
}
|
|
2707
|
-
);
|
|
3456
|
+
) });
|
|
2708
3457
|
};
|
|
2709
3458
|
const Area = (props) => {
|
|
2710
3459
|
return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) }) : /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) });
|
|
@@ -2731,6 +3480,8 @@ const useLayerCssOverride = (layerKey) => {
|
|
|
2731
3480
|
};
|
|
2732
3481
|
export {
|
|
2733
3482
|
Area,
|
|
3483
|
+
AreaManagerContext,
|
|
3484
|
+
AreaManagerProvider,
|
|
2734
3485
|
Collection,
|
|
2735
3486
|
CssChunk,
|
|
2736
3487
|
CustomRender,
|
|
@@ -2761,7 +3512,6 @@ export {
|
|
|
2761
3512
|
declareFragmentProperty,
|
|
2762
3513
|
defaultCustomRender,
|
|
2763
3514
|
duplicateLayer,
|
|
2764
|
-
expandObjectProps,
|
|
2765
3515
|
findBreakpoint,
|
|
2766
3516
|
getAllParents,
|
|
2767
3517
|
getHydratedData,
|
|
@@ -2783,7 +3533,6 @@ export {
|
|
|
2783
3533
|
isTopLevel,
|
|
2784
3534
|
isVariableLink,
|
|
2785
3535
|
layerFieldSetter,
|
|
2786
|
-
loadFragmentManager,
|
|
2787
3536
|
makeSnapshot,
|
|
2788
3537
|
moveChildren,
|
|
2789
3538
|
nodeWalker,
|
|
@@ -2827,6 +3576,8 @@ export {
|
|
|
2827
3576
|
useReadVariable,
|
|
2828
3577
|
useReadVariables,
|
|
2829
3578
|
useRenderTarget,
|
|
3579
|
+
useResolvedLayer,
|
|
3580
|
+
useResolvedLayerVariables,
|
|
2830
3581
|
useTextAttributes,
|
|
2831
3582
|
useTextContent,
|
|
2832
3583
|
useTextHighlight,
|