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