@fragmentsx/render-react 1.5.3 → 1.6.1
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/useFragmentManager.d.ts.map +1 -1
- package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
- package/dist/hooks/layer/useLayerVariableValue.d.ts.map +1 -1
- package/dist/hooks/layer/useLayersValue.d.ts.map +1 -1
- package/dist/hooks/layer/useReadVariable.d.ts +8 -11
- package/dist/hooks/layer/useReadVariable.d.ts.map +1 -1
- package/dist/hooks/layer/useReadVariables.d.ts +3 -3
- package/dist/hooks/layer/useReadVariables.d.ts.map +1 -1
- package/dist/hooks/layer/useResolvedLayerVariables.d.ts +1 -1
- package/dist/hooks/layer/useResolvedLayerVariables.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/calcImagePaint.test.d.ts +2 -0
- package/dist/hooks/layer-styles/useLayerStyles/calcImagePaint.test.d.ts.map +1 -0
- package/dist/hooks/utils/useExtractProps.d.ts.map +1 -1
- package/dist/hooks/utils/useLayerInteractions.d.ts.map +1 -1
- package/dist/index.cjs.js +412 -460
- package/dist/index.es.js +413 -461
- package/dist/nodes/Instance/Instance.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
- package/dist/nodes/Instance/test/project-props.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/project-props.browser.test.d.ts.map +1 -0
- package/dist/nodes/Text/hooks/useTextContent.d.ts.map +1 -1
- package/dist/providers/InstanceContext.d.ts +1 -0
- package/dist/providers/InstanceContext.d.ts.map +1 -1
- package/dist/utils/common/transformCssValue.test.d.ts +2 -0
- package/dist/utils/common/transformCssValue.test.d.ts.map +1 -0
- package/package.json +5 -3
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createContext, useContext, useMemo,
|
|
1
|
+
import { createContext, useContext, useMemo, useCallback, useEffect, useState, useRef, memo, Suspense } from "react";
|
|
2
2
|
import { definition, getNormalizeLayer as getNormalizeLayer$1, isVariableLink as isVariableLink$1, parseLayerField, isLink as isLink$1 } from "@fragmentsx/definition";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useGraph, useGraphStack } from "@graph-state/react";
|
|
4
5
|
import { cleanGraph, generateId, getKey as getKey$1, isValue, isObject, pick, toPx, setKey as setKey$1, toKebabCase, set, isPrimitive, get, omit, noop, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
|
|
5
6
|
import { keyOfEntity, isPartialKey, entityOfKey, isLinkKey } from "@graph-state/core";
|
|
6
|
-
import { useGraph, useGraphStack } from "@graph-state/react";
|
|
7
7
|
import { createAreaManager } from "@fragmentsx/client-core";
|
|
8
8
|
const GlobalManagerContext = createContext(null);
|
|
9
9
|
const GlobalManagerProvider = GlobalManagerContext.Provider;
|
|
@@ -12,12 +12,13 @@ const FragmentContext = createContext({
|
|
|
12
12
|
});
|
|
13
13
|
const defaultCustomRender = (layerKey, node) => node;
|
|
14
14
|
const CustomRender = createContext(defaultCustomRender);
|
|
15
|
-
const InstanceContext
|
|
15
|
+
const InstanceContext = createContext({
|
|
16
16
|
layerKey: null,
|
|
17
17
|
parentManager: null,
|
|
18
18
|
innerManager: null,
|
|
19
19
|
props: {},
|
|
20
|
-
definitions: []
|
|
20
|
+
definitions: [],
|
|
21
|
+
onChangeProps: null
|
|
21
22
|
});
|
|
22
23
|
const RenderTargetContext = createContext(
|
|
23
24
|
definition.renderTarget.document
|
|
@@ -660,8 +661,8 @@ function hashGenerator(layerKey) {
|
|
|
660
661
|
return /^[0-9]/.test(raw) ? `h${raw}` : raw;
|
|
661
662
|
}
|
|
662
663
|
const transformCssValue = (value) => {
|
|
663
|
-
var _a;
|
|
664
|
-
if ((_a = value == null ? void 0 : value.startsWith) == null ? void 0 : _a.call(value, "http")) {
|
|
664
|
+
var _a, _b;
|
|
665
|
+
if (((_a = value == null ? void 0 : value.startsWith) == null ? void 0 : _a.call(value, "http")) || ((_b = value == null ? void 0 : value.startsWith) == null ? void 0 : _b.call(value, "data:"))) {
|
|
665
666
|
value = `url("${value}")`;
|
|
666
667
|
}
|
|
667
668
|
return value;
|
|
@@ -861,178 +862,139 @@ const useResolvedLayer = (layerKey, options) => {
|
|
|
861
862
|
}
|
|
862
863
|
return { layerKey: key, rawLayer, layer, isOverride };
|
|
863
864
|
};
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
}
|
|
867
|
-
const EMPTY_RESOLVED = {
|
|
868
|
-
values: {},
|
|
869
|
-
cssVariableValues: {},
|
|
870
|
-
rawValues: {}
|
|
871
|
-
};
|
|
872
|
-
const extractVariableValue$1 = (input, variableId) => {
|
|
873
|
-
if (isObject(input)) {
|
|
865
|
+
const extractVariableValue = (input, variableId) => {
|
|
866
|
+
if (input && typeof input === "object") {
|
|
874
867
|
if (variableId in input) return input[variableId];
|
|
875
868
|
for (const key in input) {
|
|
876
869
|
if (input.hasOwnProperty(key)) {
|
|
877
|
-
const result = extractVariableValue
|
|
870
|
+
const result = extractVariableValue(input[key], variableId);
|
|
878
871
|
if (result !== void 0) return result;
|
|
879
872
|
}
|
|
880
873
|
}
|
|
881
874
|
}
|
|
882
875
|
return void 0;
|
|
883
876
|
};
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
877
|
+
const useReadVariables = (variableKeys, customManager) => {
|
|
878
|
+
var _a, _b, _c, _d;
|
|
879
|
+
const filterKeys = variableKeys.filter(isVariableLink$1);
|
|
880
|
+
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
881
|
+
const { props: instanceProps } = useContext(InstanceContext);
|
|
882
|
+
const globalManager = useContext(GlobalManagerContext);
|
|
883
|
+
const areaManager = useContext(AreaManagerContext);
|
|
884
|
+
const scopes = useContext(ScopeContext);
|
|
885
|
+
const resultManager = customManager ?? ((_a = useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
|
|
886
|
+
const safeFilterKeys = resultManager ? filterKeys : [];
|
|
887
|
+
const variableLayers = useGraphStack(
|
|
888
|
+
safeFilterKeys.length ? resultManager : null,
|
|
889
|
+
safeFilterKeys,
|
|
890
|
+
{
|
|
891
|
+
selector: (graph) => graph ? pick(graph, "_id", "defaultValue", "required") : graph
|
|
892
|
+
}
|
|
893
|
+
);
|
|
894
|
+
useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
|
|
895
|
+
useGraph(areaManager, (_c = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _c.key);
|
|
896
|
+
const globalPropertyKeys = useMemo(() => {
|
|
897
|
+
if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
|
|
898
|
+
return filterKeys.filter((key) => globalManager.resolve(key));
|
|
899
|
+
}, [filterKeys, globalManager]);
|
|
900
|
+
const areaPropertyKeys = useMemo(() => {
|
|
901
|
+
if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
|
|
902
|
+
return filterKeys.filter((key) => areaManager.resolve(key));
|
|
903
|
+
}, [filterKeys, areaManager]);
|
|
904
|
+
useGraphStack(
|
|
905
|
+
globalPropertyKeys.length ? globalManager : null,
|
|
906
|
+
globalPropertyKeys
|
|
907
|
+
);
|
|
908
|
+
useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
|
|
909
|
+
const lastCollectionItem = (_d = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _d.call(
|
|
910
|
+
scopes,
|
|
911
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
|
|
912
|
+
);
|
|
913
|
+
return filterKeys.map((variableKey, index) => {
|
|
914
|
+
var _a2;
|
|
915
|
+
const layer = variableLayers[index] ?? null;
|
|
916
|
+
const { _id: propertyId } = layer ?? {};
|
|
917
|
+
let collectionItemProp = void 0;
|
|
918
|
+
if (lastCollectionItem && propertyId) {
|
|
919
|
+
collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_a2 = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _a2._id) === propertyId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, propertyId);
|
|
920
|
+
}
|
|
921
|
+
const instanceProp = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? null;
|
|
922
|
+
const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
|
|
923
|
+
const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
|
|
924
|
+
const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
|
|
925
|
+
const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
|
|
926
|
+
const required = (layer == null ? void 0 : layer.required) ?? false;
|
|
927
|
+
const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
|
|
928
|
+
const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
|
|
929
|
+
const resultValue = required ? currentValue : currentValue ?? defaultValue;
|
|
930
|
+
if (isVariableLink$1(resultValue)) {
|
|
931
|
+
const refKey = resultValue;
|
|
932
|
+
const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
|
|
933
|
+
const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
|
|
934
|
+
const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
|
|
935
|
+
const refValue = (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
|
|
936
|
+
return {
|
|
937
|
+
value: refValue,
|
|
938
|
+
layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
|
|
939
|
+
};
|
|
892
940
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
const useResolvedLayerVariables = (layer, rawLayer, customScopes) => {
|
|
897
|
-
var _a;
|
|
898
|
-
const contextScopes = useContext(ScopeContext);
|
|
899
|
-
const scopes = customScopes ?? contextScopes;
|
|
900
|
-
const subscriptions = useRef([]);
|
|
901
|
-
const [dep, forceUpdate] = useForceUpdate();
|
|
902
|
-
useEffect(() => {
|
|
903
|
-
const controller = new AbortController();
|
|
904
|
-
let ready = false;
|
|
905
|
-
const update = () => {
|
|
906
|
-
if (!ready) return;
|
|
907
|
-
forceUpdate();
|
|
941
|
+
return {
|
|
942
|
+
value: resultValue,
|
|
943
|
+
layer: layer ?? areaLayer ?? globalLayer ?? null
|
|
908
944
|
};
|
|
909
|
-
for (const { manager, key } of subscriptions.current) {
|
|
910
|
-
manager.subscribe(key, update, { signal: controller.signal });
|
|
911
|
-
}
|
|
912
|
-
ready = true;
|
|
913
|
-
return () => controller.abort();
|
|
914
945
|
});
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
946
|
+
};
|
|
947
|
+
const EMPTY_RESOLVED = {
|
|
948
|
+
values: {},
|
|
949
|
+
cssVariableValues: {},
|
|
950
|
+
rawValues: {}
|
|
951
|
+
};
|
|
952
|
+
const collectVariableKeys = (layer) => {
|
|
953
|
+
const keys = [];
|
|
954
|
+
if (!layer) return keys;
|
|
955
|
+
for (const [, value] of Object.entries(layer)) {
|
|
956
|
+
if (isVariableLink$1(value)) {
|
|
957
|
+
keys.push(value);
|
|
958
|
+
} else if (isObject(value) && !isVariableLink$1(value)) {
|
|
959
|
+
for (const [, nestedValue] of Object.entries(
|
|
960
|
+
value
|
|
961
|
+
)) {
|
|
962
|
+
if (isVariableLink$1(nestedValue)) {
|
|
963
|
+
keys.push(nestedValue);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
918
967
|
}
|
|
968
|
+
return keys;
|
|
969
|
+
};
|
|
970
|
+
const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
|
|
971
|
+
var _a;
|
|
972
|
+
const variableKeys = collectVariableKeys(layer);
|
|
973
|
+
const resolved = useReadVariables(variableKeys);
|
|
974
|
+
if (!layer) return EMPTY_RESOLVED;
|
|
975
|
+
const resolvedByKey = {};
|
|
976
|
+
variableKeys.forEach((key, i) => {
|
|
977
|
+
var _a2;
|
|
978
|
+
resolvedByKey[key] = ((_a2 = resolved[i]) == null ? void 0 : _a2.value) ?? null;
|
|
979
|
+
});
|
|
919
980
|
const values = {};
|
|
920
981
|
const cssVariableValues = {};
|
|
921
982
|
const rawValues = {};
|
|
922
|
-
const readVariable = (variableKey) => {
|
|
923
|
-
var _a2, _b, _c;
|
|
924
|
-
const variableId = (_a2 = entityOfKey(variableKey)) == null ? void 0 : _a2._id;
|
|
925
|
-
if (!isVariableLink$1(variableKey)) {
|
|
926
|
-
return { value: null, layer: null };
|
|
927
|
-
}
|
|
928
|
-
let instanceScope = scopes.findLast(
|
|
929
|
-
(scope) => {
|
|
930
|
-
var _a3;
|
|
931
|
-
return (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope && !!((_a3 = scope.documentManager) == null ? void 0 : _a3.resolve(variableKey));
|
|
932
|
-
}
|
|
933
|
-
);
|
|
934
|
-
if (!instanceScope) {
|
|
935
|
-
instanceScope = scopes.find(
|
|
936
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
|
|
937
|
-
);
|
|
938
|
-
}
|
|
939
|
-
const resolveVariableLayer = (manager, variableLink, customProps) => {
|
|
940
|
-
var _a3, _b2;
|
|
941
|
-
const variableLayer2 = (_a3 = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a3.layer;
|
|
942
|
-
if (!variableLayer2) return null;
|
|
943
|
-
if ((variableLayer2 == null ? void 0 : variableLayer2.type) === definition.variableType.Array) {
|
|
944
|
-
const definitionLayer = manager.resolve(variableLayer2 == null ? void 0 : variableLayer2.definition);
|
|
945
|
-
if (!((_b2 = variableLayer2 == null ? void 0 : variableLayer2.defaultValue) == null ? void 0 : _b2.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
|
|
946
|
-
return variableLayer2;
|
|
947
|
-
const extractVariableDefaultValue = (mgr, varEntity) => {
|
|
948
|
-
const varLayer = mgr.resolve(varEntity);
|
|
949
|
-
if ((varLayer == null ? void 0 : varLayer.type) !== definition.variableType.Object)
|
|
950
|
-
return varLayer == null ? void 0 : varLayer.defaultValue;
|
|
951
|
-
return Object.values((varLayer == null ? void 0 : varLayer.fields) ?? {}).reduce(
|
|
952
|
-
(acc, fieldLink) => {
|
|
953
|
-
var _a4;
|
|
954
|
-
if (!!fieldLink && isVariableLink$1(fieldLink)) {
|
|
955
|
-
const _id = (_a4 = entityOfKey(fieldLink)) == null ? void 0 : _a4._id;
|
|
956
|
-
if (_id) acc[_id] = extractVariableDefaultValue(mgr, fieldLink);
|
|
957
|
-
}
|
|
958
|
-
return acc;
|
|
959
|
-
},
|
|
960
|
-
{}
|
|
961
|
-
);
|
|
962
|
-
};
|
|
963
|
-
const definitionDefaultValue = extractVariableDefaultValue(
|
|
964
|
-
manager,
|
|
965
|
-
definitionLayer
|
|
966
|
-
);
|
|
967
|
-
const customValue = customProps == null ? void 0 : customProps[variableLayer2 == null ? void 0 : variableLayer2._id];
|
|
968
|
-
return {
|
|
969
|
-
...variableLayer2,
|
|
970
|
-
defaultValue: variableLayer2.defaultValue.map(
|
|
971
|
-
(item, index) => {
|
|
972
|
-
const customItemValue = Array.isArray(customValue) ? customValue.at(index) : null;
|
|
973
|
-
return deepMerge$1(
|
|
974
|
-
customItemValue ? { ...item, ...customItemValue } : item,
|
|
975
|
-
definitionDefaultValue
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
)
|
|
979
|
-
};
|
|
980
|
-
}
|
|
981
|
-
return variableLayer2;
|
|
982
|
-
};
|
|
983
|
-
const variableLayer = resolveVariableLayer(
|
|
984
|
-
instanceScope == null ? void 0 : instanceScope.documentManager,
|
|
985
|
-
variableKey
|
|
986
|
-
);
|
|
987
|
-
if ((instanceScope == null ? void 0 : instanceScope.documentManager) && variableKey) {
|
|
988
|
-
subscriptions.current.push({
|
|
989
|
-
manager: instanceScope.documentManager,
|
|
990
|
-
key: variableKey
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
let instanceProp = variableId ? (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId] : void 0;
|
|
994
|
-
if (Array.isArray(instanceProp)) {
|
|
995
|
-
instanceProp = instanceProp.map(
|
|
996
|
-
(rawProp, index) => {
|
|
997
|
-
var _a3;
|
|
998
|
-
return deepMerge$1(rawProp, (_a3 = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a3.at(index));
|
|
999
|
-
}
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
const lastCollectionItem = scopes.findLast(
|
|
1003
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
|
|
1004
|
-
);
|
|
1005
|
-
resolveVariableLayer(
|
|
1006
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.manager,
|
|
1007
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
|
|
1008
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.value
|
|
1009
|
-
);
|
|
1010
|
-
const collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_c = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _c._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue$1(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
|
|
1011
|
-
const currentValue = variableKey === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
|
|
1012
|
-
const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
|
|
1013
|
-
const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
|
|
1014
|
-
const resultValue = required ? currentValue : currentValue ?? collectionItemProp ?? defaultValue;
|
|
1015
|
-
if (isVariableLink$1(resultValue)) {
|
|
1016
|
-
return readVariable(resultValue);
|
|
1017
|
-
}
|
|
1018
|
-
return { value: resultValue, layer: variableLayer };
|
|
1019
|
-
};
|
|
1020
983
|
const resolveField = (fieldPath, value, raw) => {
|
|
1021
984
|
var _a2;
|
|
1022
985
|
rawValues[fieldPath] = raw;
|
|
1023
986
|
if (isVariableLink$1(value)) {
|
|
1024
|
-
const
|
|
1025
|
-
values[fieldPath] =
|
|
987
|
+
const resolvedValue = resolvedByKey[value] ?? value;
|
|
988
|
+
values[fieldPath] = resolvedValue;
|
|
1026
989
|
const variableId = (_a2 = entityOfKey(value)) == null ? void 0 : _a2._id;
|
|
1027
990
|
cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
|
|
1028
|
-
|
|
991
|
+
resolvedValue
|
|
1029
992
|
)})`;
|
|
1030
993
|
} else {
|
|
1031
994
|
values[fieldPath] = value;
|
|
1032
995
|
cssVariableValues[fieldPath] = transformCssValue(value);
|
|
1033
996
|
}
|
|
1034
997
|
};
|
|
1035
|
-
subscriptions.current = [];
|
|
1036
998
|
for (const [field, value] of Object.entries(layer)) {
|
|
1037
999
|
resolveField(field, value, rawLayer == null ? void 0 : rawLayer[field]);
|
|
1038
1000
|
if (isObject(value) && !isVariableLink$1(value)) {
|
|
@@ -1057,188 +1019,6 @@ const useRenderTarget = () => {
|
|
|
1057
1019
|
isDocument: renderTarget === definition.renderTarget.document
|
|
1058
1020
|
};
|
|
1059
1021
|
};
|
|
1060
|
-
const useReadVariables = (variableKeys) => {
|
|
1061
|
-
const filterKeys = variableKeys.filter(isVariableLink$1);
|
|
1062
|
-
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1063
|
-
const { props, innerManager, layerKey } = useContext(InstanceContext);
|
|
1064
|
-
const resultManager = innerManager ?? fragmentManager;
|
|
1065
|
-
const variableLayers = useGraphStack(
|
|
1066
|
-
!!filterKeys.length ? resultManager : null,
|
|
1067
|
-
filterKeys,
|
|
1068
|
-
{
|
|
1069
|
-
selector: (graph) => graph ? pick(graph, "defaultValue", "required") : graph
|
|
1070
|
-
}
|
|
1071
|
-
);
|
|
1072
|
-
return variableLayers.map((layer) => {
|
|
1073
|
-
const { _id: propertyId } = layer ?? {};
|
|
1074
|
-
const currentValue = (props == null ? void 0 : props[propertyId]) ?? null;
|
|
1075
|
-
const required = (layer == null ? void 0 : layer.required) ?? false;
|
|
1076
|
-
const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
|
|
1077
|
-
const resultValue = required ? currentValue : currentValue ?? defaultValue;
|
|
1078
|
-
return {
|
|
1079
|
-
value: resultValue,
|
|
1080
|
-
layer
|
|
1081
|
-
};
|
|
1082
|
-
});
|
|
1083
|
-
};
|
|
1084
|
-
const extractVariableValue = (input, variableId) => {
|
|
1085
|
-
if (isObject(input)) {
|
|
1086
|
-
if (variableId in input) {
|
|
1087
|
-
return input[variableId];
|
|
1088
|
-
}
|
|
1089
|
-
for (let key in input) {
|
|
1090
|
-
if (input.hasOwnProperty(key)) {
|
|
1091
|
-
const result = extractVariableValue(input[key], variableId);
|
|
1092
|
-
if (result !== void 0) {
|
|
1093
|
-
return result;
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
return void 0;
|
|
1099
|
-
};
|
|
1100
|
-
function deepMerge(a, b) {
|
|
1101
|
-
if (!isObject(a) || !isObject(b)) return a;
|
|
1102
|
-
const result = { ...b };
|
|
1103
|
-
for (const [key, value] of Object.entries(a)) {
|
|
1104
|
-
if (key in result && typeof result[key] === "object" && typeof value === "object") {
|
|
1105
|
-
result[key] = deepMerge(value, result[key]);
|
|
1106
|
-
} else {
|
|
1107
|
-
result[key] = value;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
return result;
|
|
1111
|
-
}
|
|
1112
|
-
const useReadVariable = (variableKey, customScopes) => {
|
|
1113
|
-
const contextScopes = useContext(ScopeContext);
|
|
1114
|
-
const scopes = customScopes ?? contextScopes;
|
|
1115
|
-
const subscriptions = useRef([]);
|
|
1116
|
-
const [dep, forceUpdate] = useForceUpdate();
|
|
1117
|
-
useEffect(() => {
|
|
1118
|
-
const controller = new AbortController();
|
|
1119
|
-
let ready = false;
|
|
1120
|
-
const update = () => {
|
|
1121
|
-
if (!ready) return;
|
|
1122
|
-
forceUpdate();
|
|
1123
|
-
};
|
|
1124
|
-
for (const { manager, key } of subscriptions.current) {
|
|
1125
|
-
manager.subscribe(key, update, { signal: controller.signal });
|
|
1126
|
-
}
|
|
1127
|
-
ready = true;
|
|
1128
|
-
return () => controller.abort();
|
|
1129
|
-
});
|
|
1130
|
-
const extractVariableDefaultValue = (manager, variableEntity) => {
|
|
1131
|
-
const variableLayer = manager.resolve(variableEntity);
|
|
1132
|
-
if ((variableLayer == null ? void 0 : variableLayer.type) !== definition.variableType.Object)
|
|
1133
|
-
return variableLayer == null ? void 0 : variableLayer.defaultValue;
|
|
1134
|
-
return Object.values((variableLayer == null ? void 0 : variableLayer.fields) ?? {}).reduce(
|
|
1135
|
-
(acc, fieldLink) => {
|
|
1136
|
-
var _a;
|
|
1137
|
-
if (!!fieldLink && isVariableLink$1(fieldLink)) {
|
|
1138
|
-
const _id = (_a = entityOfKey(fieldLink)) == null ? void 0 : _a._id;
|
|
1139
|
-
if (_id) {
|
|
1140
|
-
acc[_id] = extractVariableDefaultValue(manager, fieldLink);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
return acc;
|
|
1144
|
-
},
|
|
1145
|
-
{}
|
|
1146
|
-
);
|
|
1147
|
-
};
|
|
1148
|
-
const resolveVariableLayer = (manager, variableLink, customProps) => {
|
|
1149
|
-
var _a, _b;
|
|
1150
|
-
const variableLayer = (_a = getNormalizeLayer(variableLink, manager)) == null ? void 0 : _a.layer;
|
|
1151
|
-
if (!variableLayer) return null;
|
|
1152
|
-
if ((variableLayer == null ? void 0 : variableLayer.type) === definition.variableType.Array) {
|
|
1153
|
-
const definitionLayer = manager.resolve(variableLayer == null ? void 0 : variableLayer.definition);
|
|
1154
|
-
if (!((_b = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _b.length) || (definitionLayer == null ? void 0 : definitionLayer.type) !== definition.variableType.Object)
|
|
1155
|
-
return variableLayer;
|
|
1156
|
-
const definitionDefaultValue = extractVariableDefaultValue(
|
|
1157
|
-
manager,
|
|
1158
|
-
definitionLayer
|
|
1159
|
-
);
|
|
1160
|
-
const customValue = customProps == null ? void 0 : customProps[variableLayer == null ? void 0 : variableLayer._id];
|
|
1161
|
-
return {
|
|
1162
|
-
...variableLayer,
|
|
1163
|
-
defaultValue: (variableLayer == null ? void 0 : variableLayer.defaultValue).map((item, index) => {
|
|
1164
|
-
const customItemValue = Array.isArray(customValue) ? customValue.at(index) : null;
|
|
1165
|
-
return deepMerge(
|
|
1166
|
-
customItemValue ? { ...item, ...customItemValue } : item,
|
|
1167
|
-
definitionDefaultValue
|
|
1168
|
-
);
|
|
1169
|
-
})
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
return variableLayer;
|
|
1173
|
-
};
|
|
1174
|
-
const readVariable = (variableKey2) => {
|
|
1175
|
-
var _a, _b, _c;
|
|
1176
|
-
const variableId = (_a = entityOfKey(variableKey2)) == null ? void 0 : _a._id;
|
|
1177
|
-
if (!isVariableLink$1(variableKey2)) {
|
|
1178
|
-
return {
|
|
1179
|
-
value: null,
|
|
1180
|
-
layer: null
|
|
1181
|
-
};
|
|
1182
|
-
}
|
|
1183
|
-
let instanceScope = scopes.findLast(
|
|
1184
|
-
(scope) => {
|
|
1185
|
-
var _a2;
|
|
1186
|
-
return (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope && !!((_a2 = scope.documentManager) == null ? void 0 : _a2.resolve(variableKey2));
|
|
1187
|
-
}
|
|
1188
|
-
);
|
|
1189
|
-
if (!instanceScope) {
|
|
1190
|
-
instanceScope = scopes.find(
|
|
1191
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
const variableLayer = resolveVariableLayer(
|
|
1195
|
-
instanceScope == null ? void 0 : instanceScope.documentManager,
|
|
1196
|
-
variableKey2
|
|
1197
|
-
);
|
|
1198
|
-
if ((instanceScope == null ? void 0 : instanceScope.documentManager) && variableKey2) {
|
|
1199
|
-
subscriptions.current.push({
|
|
1200
|
-
manager: instanceScope.documentManager,
|
|
1201
|
-
key: variableKey2
|
|
1202
|
-
});
|
|
1203
|
-
}
|
|
1204
|
-
let instanceProp = (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId];
|
|
1205
|
-
if (Array.isArray(instanceProp)) {
|
|
1206
|
-
instanceProp = instanceProp.map(
|
|
1207
|
-
(rawProp, index) => {
|
|
1208
|
-
var _a2;
|
|
1209
|
-
return deepMerge(rawProp, (_a2 = variableLayer == null ? void 0 : variableLayer.defaultValue) == null ? void 0 : _a2.at(index));
|
|
1210
|
-
}
|
|
1211
|
-
);
|
|
1212
|
-
}
|
|
1213
|
-
const lastCollectionItem = scopes.findLast(
|
|
1214
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
|
|
1215
|
-
);
|
|
1216
|
-
resolveVariableLayer(
|
|
1217
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.manager,
|
|
1218
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
|
|
1219
|
-
lastCollectionItem == null ? void 0 : lastCollectionItem.value
|
|
1220
|
-
);
|
|
1221
|
-
const collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_c = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _c._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
|
|
1222
|
-
const currentValue = variableKey2 === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
|
|
1223
|
-
const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
|
|
1224
|
-
const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
|
|
1225
|
-
const resultValue = required ? currentValue : currentValue ?? collectionItemProp ?? defaultValue;
|
|
1226
|
-
if (isVariableLink$1(resultValue)) {
|
|
1227
|
-
return readVariable(resultValue);
|
|
1228
|
-
}
|
|
1229
|
-
return {
|
|
1230
|
-
value: resultValue,
|
|
1231
|
-
layer: variableLayer
|
|
1232
|
-
};
|
|
1233
|
-
};
|
|
1234
|
-
subscriptions.current = [];
|
|
1235
|
-
const result = readVariable(variableKey);
|
|
1236
|
-
return {
|
|
1237
|
-
...result,
|
|
1238
|
-
readVariable,
|
|
1239
|
-
_dep: dep
|
|
1240
|
-
};
|
|
1241
|
-
};
|
|
1242
1022
|
const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
1243
1023
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1244
1024
|
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
@@ -1250,12 +1030,21 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1250
1030
|
// selector: (data) => (data ? pick(data, fieldKey) : data),
|
|
1251
1031
|
});
|
|
1252
1032
|
const normalizeLayers = useNormalizeLayers(keys, resultManager, options);
|
|
1253
|
-
const
|
|
1033
|
+
const variableKeysFromLayers = normalizeLayers.map((nl) => get(nl.layer, fieldKey)).filter(isVariableLink$1);
|
|
1034
|
+
const resolvedVariables = useReadVariables(
|
|
1035
|
+
variableKeysFromLayers,
|
|
1036
|
+
resultManager
|
|
1037
|
+
);
|
|
1038
|
+
const resolvedByKey = {};
|
|
1039
|
+
variableKeysFromLayers.forEach((key, i) => {
|
|
1040
|
+
var _a;
|
|
1041
|
+
resolvedByKey[key] = ((_a = resolvedVariables[i]) == null ? void 0 : _a.value) ?? null;
|
|
1042
|
+
});
|
|
1254
1043
|
return normalizeLayers.map((normalizedLayer) => {
|
|
1255
|
-
var _a
|
|
1044
|
+
var _a;
|
|
1256
1045
|
const rawValue = get(normalizedLayer.rawLayer, fieldKey);
|
|
1257
1046
|
const layerValue = get(normalizedLayer.layer, fieldKey);
|
|
1258
|
-
const variableValue = (
|
|
1047
|
+
const variableValue = isVariableLink$1(layerValue) ? resolvedByKey[layerValue] ?? null : null;
|
|
1259
1048
|
const currentValue = variableValue ?? layerValue;
|
|
1260
1049
|
const isInherit = isInheritField(
|
|
1261
1050
|
resultManager,
|
|
@@ -1280,15 +1069,15 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1280
1069
|
);
|
|
1281
1070
|
};
|
|
1282
1071
|
const restore = (fallbackValue) => {
|
|
1283
|
-
var _a2,
|
|
1284
|
-
const tempValue = ((_c = (
|
|
1072
|
+
var _a2, _b, _c;
|
|
1073
|
+
const tempValue = ((_c = (_b = resultManager.resolve((_a2 = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a2.temp)) == null ? void 0 : _b[normalizedLayer.layerKey]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
|
|
1285
1074
|
return tempValue;
|
|
1286
1075
|
};
|
|
1287
1076
|
const updateValue = (value, options2) => {
|
|
1288
1077
|
setter(value, options2);
|
|
1289
1078
|
};
|
|
1290
1079
|
const isVariable = isVariableLink$1(rawValue ?? layerValue);
|
|
1291
|
-
const variableId = isVariable ? (
|
|
1080
|
+
const variableId = isVariable ? (_a = entityOfKey(layerValue)) == null ? void 0 : _a._id : null;
|
|
1292
1081
|
return [
|
|
1293
1082
|
currentValue,
|
|
1294
1083
|
updateValue,
|
|
@@ -1305,7 +1094,7 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1305
1094
|
});
|
|
1306
1095
|
};
|
|
1307
1096
|
const useLayerValue = (layerKey, fieldKey, options) => {
|
|
1308
|
-
var _a;
|
|
1097
|
+
var _a, _b;
|
|
1309
1098
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1310
1099
|
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
1311
1100
|
if (!resultManager) {
|
|
@@ -1318,7 +1107,11 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1318
1107
|
const { layer, rawLayer } = useNormalizeLayer(key, resultManager, options);
|
|
1319
1108
|
const rawValue = get(rawLayer, fieldKey);
|
|
1320
1109
|
const layerValue = get(layer, fieldKey);
|
|
1321
|
-
const
|
|
1110
|
+
const variableResults = useReadVariables(
|
|
1111
|
+
isVariableLink$1(layerValue) ? [layerValue] : [],
|
|
1112
|
+
resultManager
|
|
1113
|
+
);
|
|
1114
|
+
const variableValue = ((_a = variableResults[0]) == null ? void 0 : _a.value) ?? null;
|
|
1322
1115
|
const currentValue = variableValue ?? layerValue;
|
|
1323
1116
|
const isInherit = isInheritField(resultManager, key, fieldKey);
|
|
1324
1117
|
const isOverride = !isInherit && !isPartOfPrimary(resultManager, key);
|
|
@@ -1335,8 +1128,8 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1335
1128
|
}, [updateLayerData]);
|
|
1336
1129
|
const restore = useCallback(
|
|
1337
1130
|
(fallbackValue) => {
|
|
1338
|
-
var _a2,
|
|
1339
|
-
const tempValue = ((_c = (
|
|
1131
|
+
var _a2, _b2, _c;
|
|
1132
|
+
const tempValue = ((_c = (_b2 = resultManager.resolve((_a2 = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a2.temp)) == null ? void 0 : _b2[key]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
|
|
1340
1133
|
updateLayerData({ [fieldKey]: tempValue });
|
|
1341
1134
|
return tempValue;
|
|
1342
1135
|
},
|
|
@@ -1349,7 +1142,7 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1349
1142
|
[setter]
|
|
1350
1143
|
);
|
|
1351
1144
|
const isVariable = isVariableLink$1(rawValue ?? layerValue);
|
|
1352
|
-
const variableId = isVariable ? (
|
|
1145
|
+
const variableId = isVariable ? (_b = entityOfKey(layerValue)) == null ? void 0 : _b._id : null;
|
|
1353
1146
|
return [
|
|
1354
1147
|
currentValue,
|
|
1355
1148
|
updateValue,
|
|
@@ -1364,6 +1157,20 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1364
1157
|
}
|
|
1365
1158
|
];
|
|
1366
1159
|
};
|
|
1160
|
+
const useReadVariable = (variableKey, _customScopes) => {
|
|
1161
|
+
const keys = variableKey && isVariableLink$1(variableKey) ? [variableKey] : [];
|
|
1162
|
+
const results = useReadVariables(keys);
|
|
1163
|
+
const result = results[0] ?? { value: null, layer: null };
|
|
1164
|
+
return {
|
|
1165
|
+
...result,
|
|
1166
|
+
readVariable: () => {
|
|
1167
|
+
throw new Error(
|
|
1168
|
+
"readVariable() removed — используй useReadVariables"
|
|
1169
|
+
);
|
|
1170
|
+
},
|
|
1171
|
+
_dep: 0
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1367
1174
|
const useLayerChildren = (layerKey, customManager) => {
|
|
1368
1175
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1369
1176
|
const [layerData] = useGraph(customManager ?? fragmentManager, layerKey, {
|
|
@@ -1413,6 +1220,7 @@ const useLayerLink = (layerKey) => {
|
|
|
1413
1220
|
};
|
|
1414
1221
|
};
|
|
1415
1222
|
const useLayerVariableValue = (layerKey, fieldKey, manager) => {
|
|
1223
|
+
var _a;
|
|
1416
1224
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1417
1225
|
const resultManager = manager ?? fragmentManager;
|
|
1418
1226
|
const [layerValue, updateValue, layerInfo] = useLayerValue(
|
|
@@ -1420,9 +1228,11 @@ const useLayerVariableValue = (layerKey, fieldKey, manager) => {
|
|
|
1420
1228
|
fieldKey,
|
|
1421
1229
|
resultManager
|
|
1422
1230
|
);
|
|
1423
|
-
const
|
|
1424
|
-
(layerInfo == null ? void 0 : layerInfo.isVariable) ? layerValue :
|
|
1231
|
+
const variableResults = useReadVariables(
|
|
1232
|
+
(layerInfo == null ? void 0 : layerInfo.isVariable) && isVariableLink$1(layerValue) ? [layerValue] : [],
|
|
1233
|
+
resultManager
|
|
1425
1234
|
);
|
|
1235
|
+
const instanceValue = ((_a = variableResults[0]) == null ? void 0 : _a.value) ?? null;
|
|
1426
1236
|
return [
|
|
1427
1237
|
(layerInfo == null ? void 0 : layerInfo.isVariable) ? instanceValue : layerValue,
|
|
1428
1238
|
updateValue,
|
|
@@ -1523,7 +1333,7 @@ const calcLayerSizeValue = (resolved, vars, sizeType, parentResolved, instanceVa
|
|
|
1523
1333
|
};
|
|
1524
1334
|
const useLayerSizeValue = (layerKey, sizeType) => {
|
|
1525
1335
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1526
|
-
const { layerKey: instanceLayerKey } = useContext(InstanceContext
|
|
1336
|
+
const { layerKey: instanceLayerKey } = useContext(InstanceContext);
|
|
1527
1337
|
const { isDocument } = useRenderTarget();
|
|
1528
1338
|
const isTop = isTopLevel(fragmentManager, layerKey);
|
|
1529
1339
|
const isPartOfInstance = !!instanceLayerKey;
|
|
@@ -1635,7 +1445,7 @@ const calcLayerPosition = (resolved, vars, parentResolved, instanceResolved, ins
|
|
|
1635
1445
|
};
|
|
1636
1446
|
};
|
|
1637
1447
|
const useLayerPosition = (layerKey) => {
|
|
1638
|
-
const { layerKey: instanceLayerKey } = useContext(InstanceContext
|
|
1448
|
+
const { layerKey: instanceLayerKey } = useContext(InstanceContext);
|
|
1639
1449
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1640
1450
|
const isTop = isTopLevel(fragmentManager, layerKey);
|
|
1641
1451
|
const { isDocument } = useRenderTarget();
|
|
@@ -1979,7 +1789,7 @@ const useLayerStyles = (layerKey) => {
|
|
|
1979
1789
|
try {
|
|
1980
1790
|
if (!layerKey) throw new Error("Empty layer key");
|
|
1981
1791
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
1982
|
-
const { layerKey: instanceLayerKey } = useContext(InstanceContext
|
|
1792
|
+
const { layerKey: instanceLayerKey } = useContext(InstanceContext);
|
|
1983
1793
|
const { isDocument } = useRenderTarget();
|
|
1984
1794
|
const resolved = useResolvedLayer(layerKey);
|
|
1985
1795
|
const vars = useResolvedLayerVariables(resolved.layer, resolved.rawLayer);
|
|
@@ -2120,16 +1930,14 @@ const useTextContent = (layerKey, manager) => {
|
|
|
2120
1930
|
fragmentManager
|
|
2121
1931
|
);
|
|
2122
1932
|
const variables = extractVariablesFromHtml(content);
|
|
2123
|
-
const
|
|
2124
|
-
|
|
2125
|
-
fragmentManager,
|
|
2126
|
-
variables.map((variable) => variable.variableKey)
|
|
2127
|
-
);
|
|
1933
|
+
const variableKeys = variables.map((variable) => variable.variableKey);
|
|
1934
|
+
const resolvedVariables = useReadVariables(variableKeys);
|
|
2128
1935
|
let nextContent = content;
|
|
2129
|
-
variables.forEach((variable) => {
|
|
1936
|
+
variables.forEach((variable, index) => {
|
|
1937
|
+
var _a;
|
|
2130
1938
|
nextContent = nextContent.replace(
|
|
2131
1939
|
variable.fullMatch,
|
|
2132
|
-
|
|
1940
|
+
((_a = resolvedVariables[index]) == null ? void 0 : _a.value) ?? ""
|
|
2133
1941
|
);
|
|
2134
1942
|
});
|
|
2135
1943
|
if (typeof nextContent === "string") {
|
|
@@ -2217,31 +2025,31 @@ const useGlobalManager = (globalManager) => {
|
|
|
2217
2025
|
};
|
|
2218
2026
|
};
|
|
2219
2027
|
const useLayerInteractions = (layerKey, options) => {
|
|
2028
|
+
var _a;
|
|
2220
2029
|
const pause = (options == null ? void 0 : options.pauseInteractions) ?? false;
|
|
2221
2030
|
const { manager: globalManager } = useGlobalManager();
|
|
2222
2031
|
const { manager: fragmentManager } = useContext(FragmentContext);
|
|
2223
2032
|
const scopes = useContext(ScopeContext);
|
|
2224
|
-
const areaScope = scopes.find(
|
|
2033
|
+
const areaScope = (_a = scopes == null ? void 0 : scopes.find) == null ? void 0 : _a.call(
|
|
2034
|
+
scopes,
|
|
2225
2035
|
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.AreaScope
|
|
2226
2036
|
);
|
|
2227
|
-
const
|
|
2228
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.InstanceScope
|
|
2229
|
-
);
|
|
2037
|
+
const { onChangeProps } = useContext(InstanceContext);
|
|
2230
2038
|
const [interactionLinks] = useLayerValue(layerKey, "interactions");
|
|
2231
2039
|
const interactionOns = useLayersValue(interactionLinks, "on");
|
|
2232
2040
|
const interactionEvents = useLayersValue(interactionLinks, "event");
|
|
2233
2041
|
const interactions = (interactionLinks ?? []).map((linkKey, index) => {
|
|
2234
|
-
var
|
|
2042
|
+
var _a2, _b;
|
|
2235
2043
|
return {
|
|
2236
2044
|
linkKey,
|
|
2237
|
-
on: (
|
|
2045
|
+
on: (_a2 = interactionOns == null ? void 0 : interactionOns.at(index)) == null ? void 0 : _a2.at(0),
|
|
2238
2046
|
event: (_b = interactionEvents == null ? void 0 : interactionEvents.at(index)) == null ? void 0 : _b.at(0)
|
|
2239
2047
|
};
|
|
2240
2048
|
});
|
|
2241
2049
|
const fireEvent = useCallback(
|
|
2242
2050
|
(eventLink) => {
|
|
2243
|
-
var
|
|
2244
|
-
const eventType = (
|
|
2051
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2052
|
+
const eventType = (_a2 = entityOfKey(eventLink)) == null ? void 0 : _a2._type;
|
|
2245
2053
|
const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
|
|
2246
2054
|
console.log(scopes, eventLink, eventType, eventValue);
|
|
2247
2055
|
if (eventType === definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
|
|
@@ -2258,7 +2066,7 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
2258
2066
|
const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_f = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _f.defaultValue);
|
|
2259
2067
|
if (isVariableLink$1(target) && isValue(value)) {
|
|
2260
2068
|
const targetId = (_g = entityOfKey(target)) == null ? void 0 : _g._id;
|
|
2261
|
-
|
|
2069
|
+
onChangeProps == null ? void 0 : onChangeProps(targetId, value);
|
|
2262
2070
|
}
|
|
2263
2071
|
}
|
|
2264
2072
|
},
|
|
@@ -2542,6 +2350,7 @@ const buildFieldIdMapping = (childDef, parentDef, childManager, parentManager) =
|
|
|
2542
2350
|
continue;
|
|
2543
2351
|
}
|
|
2544
2352
|
mapping[parentFieldVar._id] = childFieldVar._id;
|
|
2353
|
+
mapping[fieldName] = childFieldVar._id;
|
|
2545
2354
|
}
|
|
2546
2355
|
return mapping;
|
|
2547
2356
|
};
|
|
@@ -2573,7 +2382,30 @@ const remapArrayItems = (items, mapping) => {
|
|
|
2573
2382
|
});
|
|
2574
2383
|
};
|
|
2575
2384
|
const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
2576
|
-
const
|
|
2385
|
+
const areaManager = useContext(AreaManagerContext);
|
|
2386
|
+
const globalManager = useContext(GlobalManagerContext);
|
|
2387
|
+
const arrayVariableKeys = useMemo(() => {
|
|
2388
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2389
|
+
const keys = [];
|
|
2390
|
+
for (const defKey of definitions) {
|
|
2391
|
+
const defVar = manager.resolve(defKey);
|
|
2392
|
+
if (!(defVar == null ? void 0 : defVar._id)) continue;
|
|
2393
|
+
if (defVar.type !== definition.variableType.Array || !defVar.definition)
|
|
2394
|
+
continue;
|
|
2395
|
+
const propValue = props[defVar._id];
|
|
2396
|
+
if (isVariableLink$1(propValue)) {
|
|
2397
|
+
keys.push(propValue);
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
return keys;
|
|
2401
|
+
}, [definitions, manager, props]);
|
|
2402
|
+
const arrayResolvedResults = useReadVariables(arrayVariableKeys);
|
|
2403
|
+
const arrayResolvedByKey = {};
|
|
2404
|
+
arrayVariableKeys.forEach((key, i) => {
|
|
2405
|
+
var _a, _b;
|
|
2406
|
+
arrayResolvedByKey[key] = ((_a = arrayResolvedResults[i]) == null ? void 0 : _a.value) ?? null;
|
|
2407
|
+
((_b = arrayResolvedResults[i]) == null ? void 0 : _b.layer) ?? null;
|
|
2408
|
+
});
|
|
2577
2409
|
const leafKeys = useMemo(() => {
|
|
2578
2410
|
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2579
2411
|
const keys = [];
|
|
@@ -2592,12 +2424,12 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2592
2424
|
return keys;
|
|
2593
2425
|
}, [definitions, manager]);
|
|
2594
2426
|
const leafLayers = useGraphStack(leafKeys.length ? manager : null, leafKeys);
|
|
2595
|
-
const arrayItemKeys = useMemo(() => {
|
|
2427
|
+
const { arrayItemKeys, arrayItemManager } = useMemo(() => {
|
|
2596
2428
|
var _a;
|
|
2597
|
-
if (!manager || !(definitions == null ? void 0 : definitions.length))
|
|
2598
|
-
|
|
2599
|
-
if (!resolveManager) return [];
|
|
2429
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length))
|
|
2430
|
+
return { arrayItemKeys: [], arrayItemManager: null };
|
|
2600
2431
|
const keys = [];
|
|
2432
|
+
let itemManager = null;
|
|
2601
2433
|
for (const defKey of definitions) {
|
|
2602
2434
|
const defVar = manager.resolve(defKey);
|
|
2603
2435
|
if (!(defVar == null ? void 0 : defVar._id)) continue;
|
|
@@ -2605,14 +2437,17 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2605
2437
|
continue;
|
|
2606
2438
|
const propValue = props[defVar._id];
|
|
2607
2439
|
if (!isVariableLink$1(propValue)) continue;
|
|
2608
|
-
const
|
|
2440
|
+
const resolveManager = parentManager ?? manager;
|
|
2441
|
+
const parentVar = (resolveManager == null ? void 0 : resolveManager.resolve(propValue)) ?? (areaManager == null ? void 0 : areaManager.resolve(propValue)) ?? (globalManager == null ? void 0 : globalManager.resolve(propValue));
|
|
2442
|
+
const ownerManager = (resolveManager == null ? void 0 : resolveManager.resolve(propValue)) ? resolveManager : (areaManager == null ? void 0 : areaManager.resolve(propValue)) ? areaManager : (globalManager == null ? void 0 : globalManager.resolve(propValue)) ? globalManager : null;
|
|
2609
2443
|
if ((parentVar == null ? void 0 : parentVar.type) !== definition.variableType.Array) continue;
|
|
2610
2444
|
const items = parentVar.defaultValue;
|
|
2611
2445
|
if (!Array.isArray(items)) continue;
|
|
2446
|
+
if (ownerManager) itemManager = ownerManager;
|
|
2612
2447
|
for (const item of items) {
|
|
2613
2448
|
if (isLink$1(item)) {
|
|
2614
2449
|
keys.push(item);
|
|
2615
|
-
const resolved =
|
|
2450
|
+
const resolved = ownerManager == null ? void 0 : ownerManager.resolve(item);
|
|
2616
2451
|
if ((resolved == null ? void 0 : resolved.value) && isObject(resolved.value) && ((_a = resolved.value) == null ? void 0 : _a._type)) {
|
|
2617
2452
|
const valueKey = keyOfEntity(resolved.value);
|
|
2618
2453
|
if (valueKey) keys.push(valueKey);
|
|
@@ -2620,13 +2455,14 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2620
2455
|
}
|
|
2621
2456
|
}
|
|
2622
2457
|
}
|
|
2623
|
-
return keys;
|
|
2624
|
-
}, [definitions, manager, parentManager,
|
|
2458
|
+
return { arrayItemKeys: keys, arrayItemManager: itemManager };
|
|
2459
|
+
}, [definitions, manager, parentManager, areaManager, globalManager, props]);
|
|
2625
2460
|
const arrayItemLayers = useGraphStack(
|
|
2626
|
-
arrayItemKeys.length ? parentManager ?? manager : null,
|
|
2461
|
+
arrayItemKeys.length ? arrayItemManager ?? parentManager ?? manager : null,
|
|
2627
2462
|
arrayItemKeys
|
|
2628
2463
|
);
|
|
2629
2464
|
return useMemo(() => {
|
|
2465
|
+
var _a;
|
|
2630
2466
|
if (!manager || !(definitions == null ? void 0 : definitions.length)) return props;
|
|
2631
2467
|
const resolveManager = parentManager ?? manager;
|
|
2632
2468
|
const base = {};
|
|
@@ -2657,26 +2493,22 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2657
2493
|
continue;
|
|
2658
2494
|
}
|
|
2659
2495
|
if (defVar.type === definition.variableType.Array && defVar.definition) {
|
|
2660
|
-
if (isVariableLink$1(propValue)
|
|
2661
|
-
const parentVar = resolveManager.resolve(propValue);
|
|
2496
|
+
if (isVariableLink$1(propValue)) {
|
|
2497
|
+
const parentVar = (resolveManager == null ? void 0 : resolveManager.resolve(propValue)) ?? (areaManager == null ? void 0 : areaManager.resolve(propValue)) ?? (globalManager == null ? void 0 : globalManager.resolve(propValue));
|
|
2498
|
+
const parentVarManager = (resolveManager == null ? void 0 : resolveManager.resolve(propValue)) ? resolveManager : (areaManager == null ? void 0 : areaManager.resolve(propValue)) ? areaManager : (globalManager == null ? void 0 : globalManager.resolve(propValue)) ? globalManager : resolveManager;
|
|
2662
2499
|
if ((parentVar == null ? void 0 : parentVar.type) === definition.variableType.Array && (parentVar == null ? void 0 : parentVar.definition)) {
|
|
2663
|
-
const
|
|
2500
|
+
const resolvedArray = arrayResolvedByKey[propValue];
|
|
2664
2501
|
if (Array.isArray(resolvedArray)) {
|
|
2665
|
-
const
|
|
2666
|
-
|
|
2667
|
-
resolveManager
|
|
2668
|
-
);
|
|
2502
|
+
const itemResolver = parentVarManager ?? resolveManager;
|
|
2503
|
+
const concreteItems = itemResolver ? resolveArrayItems(resolvedArray, itemResolver) : [];
|
|
2669
2504
|
const childDef = resolveFieldRef(defVar.definition, manager);
|
|
2670
|
-
const parentDef = resolveFieldRef(
|
|
2671
|
-
parentVar.definition,
|
|
2672
|
-
resolveManager
|
|
2673
|
-
);
|
|
2505
|
+
const parentDef = parentVarManager ? resolveFieldRef(parentVar.definition, parentVarManager) : isObject(parentVar.definition) && ((_a = parentVar.definition) == null ? void 0 : _a._id) ? parentVar.definition : null;
|
|
2674
2506
|
if ((childDef == null ? void 0 : childDef.type) === definition.variableType.Object && (childDef == null ? void 0 : childDef.fields) && (parentDef == null ? void 0 : parentDef.type) === definition.variableType.Object && (parentDef == null ? void 0 : parentDef.fields)) {
|
|
2675
2507
|
const mapping = buildFieldIdMapping(
|
|
2676
2508
|
childDef,
|
|
2677
2509
|
parentDef,
|
|
2678
2510
|
manager,
|
|
2679
|
-
resolveManager
|
|
2511
|
+
parentVarManager ?? resolveManager
|
|
2680
2512
|
);
|
|
2681
2513
|
expanded[defVar._id] = remapArrayItems(concreteItems, mapping);
|
|
2682
2514
|
} else {
|
|
@@ -2702,11 +2534,13 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2702
2534
|
}, [
|
|
2703
2535
|
leafLayers,
|
|
2704
2536
|
arrayItemLayers,
|
|
2537
|
+
arrayResolvedResults,
|
|
2705
2538
|
props,
|
|
2706
2539
|
manager,
|
|
2707
2540
|
parentManager,
|
|
2708
|
-
|
|
2709
|
-
|
|
2541
|
+
areaManager,
|
|
2542
|
+
globalManager,
|
|
2543
|
+
definitions
|
|
2710
2544
|
]);
|
|
2711
2545
|
};
|
|
2712
2546
|
const CollectionItem = ({
|
|
@@ -2893,8 +2727,10 @@ const useFragmentManager = (fragmentId, inputGlobalManager) => {
|
|
|
2893
2727
|
} = useGlobalManager(inputGlobalManager);
|
|
2894
2728
|
useGraph(globalManager, (_a = globalManager == null ? void 0 : globalManager.$fragments) == null ? void 0 : _a.key, {
|
|
2895
2729
|
selector: (state) => {
|
|
2896
|
-
|
|
2897
|
-
|
|
2730
|
+
return {
|
|
2731
|
+
...state,
|
|
2732
|
+
managers: fragmentId ? pick(state.managers, fragmentId) : state.managers
|
|
2733
|
+
};
|
|
2898
2734
|
}
|
|
2899
2735
|
});
|
|
2900
2736
|
const manager = getFragmentManager(fragmentId);
|
|
@@ -2912,7 +2748,7 @@ const useFragmentManager = (fragmentId, inputGlobalManager) => {
|
|
|
2912
2748
|
};
|
|
2913
2749
|
};
|
|
2914
2750
|
const useFragmentChildren = (fragmentId) => {
|
|
2915
|
-
const { layerKey: instanceLayerKey } = useContext(InstanceContext
|
|
2751
|
+
const { layerKey: instanceLayerKey } = useContext(InstanceContext);
|
|
2916
2752
|
const { manager, fragmentLayerKey } = useFragmentManager(fragmentId);
|
|
2917
2753
|
const children = useLayerChildren(fragmentLayerKey, manager);
|
|
2918
2754
|
const [resizeChildren, setResizeChildren] = useState(null);
|
|
@@ -2955,7 +2791,7 @@ const useFragmentCssChunks = (fragmentId) => {
|
|
|
2955
2791
|
};
|
|
2956
2792
|
const useFragment = (fragmentId, globalManager) => {
|
|
2957
2793
|
var _a, _b;
|
|
2958
|
-
const instanceContext = useContext(InstanceContext
|
|
2794
|
+
const instanceContext = useContext(InstanceContext);
|
|
2959
2795
|
const fragmentContext = useFragmentManager(fragmentId);
|
|
2960
2796
|
const { setRef, children, isResize, primary } = useFragmentChildren(fragmentId);
|
|
2961
2797
|
const chunkLinks = useFragmentCssChunks(fragmentId);
|
|
@@ -3054,7 +2890,64 @@ const Fragment = (props) => {
|
|
|
3054
2890
|
}
|
|
3055
2891
|
return Base;
|
|
3056
2892
|
};
|
|
3057
|
-
const
|
|
2893
|
+
const resolveFromManagers = (key, ...managers) => {
|
|
2894
|
+
for (const mgr of managers) {
|
|
2895
|
+
if (!mgr) continue;
|
|
2896
|
+
const layer = mgr.resolve(key, { deep: true });
|
|
2897
|
+
if (layer == null ? void 0 : layer.type) return { layer, manager: mgr };
|
|
2898
|
+
}
|
|
2899
|
+
return { layer: null, manager: null };
|
|
2900
|
+
};
|
|
2901
|
+
const collectAllVariableKeys = (extractProps, fragmentManager, globalManager, areaManager) => {
|
|
2902
|
+
const keys = [];
|
|
2903
|
+
const collectFromObject = (obj) => {
|
|
2904
|
+
for (const value of Object.values(obj)) {
|
|
2905
|
+
if (isVariableLink$1(value)) {
|
|
2906
|
+
keys.push(value);
|
|
2907
|
+
} else if (isObject(value)) {
|
|
2908
|
+
collectFromObject(value);
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
};
|
|
2912
|
+
const collectObjectFields = (objectVar, manager) => {
|
|
2913
|
+
const fields = cleanGraph(objectVar.fields);
|
|
2914
|
+
for (const fieldRef of Object.values(fields)) {
|
|
2915
|
+
let fieldKey;
|
|
2916
|
+
let fieldVar;
|
|
2917
|
+
if (isVariableLink$1(fieldRef)) {
|
|
2918
|
+
fieldKey = fieldRef;
|
|
2919
|
+
fieldVar = manager == null ? void 0 : manager.resolve(fieldKey);
|
|
2920
|
+
} else if (isObject(fieldRef) && (fieldRef == null ? void 0 : fieldRef._id)) {
|
|
2921
|
+
fieldKey = keyOfEntity(fieldRef);
|
|
2922
|
+
fieldVar = fieldRef;
|
|
2923
|
+
}
|
|
2924
|
+
if (!fieldVar || !fieldKey) continue;
|
|
2925
|
+
if (fieldVar.type === definition.variableType.Object && fieldVar.fields) {
|
|
2926
|
+
collectObjectFields(fieldVar, manager);
|
|
2927
|
+
} else {
|
|
2928
|
+
keys.push(fieldKey);
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
};
|
|
2932
|
+
for (const value of Object.values(extractProps)) {
|
|
2933
|
+
if (isVariableLink$1(value)) {
|
|
2934
|
+
keys.push(value);
|
|
2935
|
+
const { layer: varLayer, manager: varManager } = resolveFromManagers(
|
|
2936
|
+
value,
|
|
2937
|
+
fragmentManager,
|
|
2938
|
+
globalManager,
|
|
2939
|
+
areaManager
|
|
2940
|
+
);
|
|
2941
|
+
if ((varLayer == null ? void 0 : varLayer.type) === definition.variableType.Object && (varLayer == null ? void 0 : varLayer.fields)) {
|
|
2942
|
+
collectObjectFields(varLayer, varManager);
|
|
2943
|
+
}
|
|
2944
|
+
} else if (isObject(value)) {
|
|
2945
|
+
collectFromObject(value);
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
return keys;
|
|
2949
|
+
};
|
|
2950
|
+
const resolveObjectToConcreteValueFromMap = (objectVar, manager, resolvedByKey) => {
|
|
3058
2951
|
const fields = cleanGraph(objectVar.fields);
|
|
3059
2952
|
const result = {};
|
|
3060
2953
|
for (const [fieldName, fieldRef] of Object.entries(fields)) {
|
|
@@ -3069,13 +2962,13 @@ const resolveObjectToConcreteValue = (objectVar, manager, readVariable) => {
|
|
|
3069
2962
|
}
|
|
3070
2963
|
if (!fieldVar || !fieldKey) continue;
|
|
3071
2964
|
if (fieldVar.type === definition.variableType.Object && fieldVar.fields) {
|
|
3072
|
-
result[fieldName] =
|
|
2965
|
+
result[fieldName] = resolveObjectToConcreteValueFromMap(
|
|
3073
2966
|
fieldVar,
|
|
3074
2967
|
manager,
|
|
3075
|
-
|
|
2968
|
+
resolvedByKey
|
|
3076
2969
|
);
|
|
3077
2970
|
} else {
|
|
3078
|
-
const
|
|
2971
|
+
const value = resolvedByKey[fieldKey];
|
|
3079
2972
|
if (value != null) {
|
|
3080
2973
|
result[fieldName] = value;
|
|
3081
2974
|
}
|
|
@@ -3083,12 +2976,30 @@ const resolveObjectToConcreteValue = (objectVar, manager, readVariable) => {
|
|
|
3083
2976
|
}
|
|
3084
2977
|
return result;
|
|
3085
2978
|
};
|
|
2979
|
+
const deepResolveObjectValuesFromMap = (obj, resolvedByKey) => {
|
|
2980
|
+
const result = {};
|
|
2981
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2982
|
+
if (isVariableLink$1(value)) {
|
|
2983
|
+
result[key] = resolvedByKey[value];
|
|
2984
|
+
} else if (isObject(value)) {
|
|
2985
|
+
result[key] = deepResolveObjectValuesFromMap(
|
|
2986
|
+
value,
|
|
2987
|
+
resolvedByKey
|
|
2988
|
+
);
|
|
2989
|
+
} else {
|
|
2990
|
+
result[key] = value;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
return result;
|
|
2994
|
+
};
|
|
3086
2995
|
const useInstanceProps = (instanceProps) => {
|
|
3087
2996
|
const isTopInstance = !(instanceProps == null ? void 0 : instanceProps.layerKey);
|
|
3088
2997
|
const { manager: loadedManager } = useFragmentManager(
|
|
3089
2998
|
isTopInstance ? instanceProps == null ? void 0 : instanceProps.fragmentId : null
|
|
3090
2999
|
);
|
|
3091
3000
|
const { manager: fragmentContextManager } = useContext(FragmentContext);
|
|
3001
|
+
const globalManager = useContext(GlobalManagerContext);
|
|
3002
|
+
const areaManager = useContext(AreaManagerContext);
|
|
3092
3003
|
const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
|
|
3093
3004
|
const [instanceLayer] = useGraph(fragmentManager, instanceProps.layerKey);
|
|
3094
3005
|
const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
|
|
@@ -3101,30 +3012,52 @@ const useInstanceProps = (instanceProps) => {
|
|
|
3101
3012
|
};
|
|
3102
3013
|
}
|
|
3103
3014
|
const extractProps = cleanGraph(inputProps);
|
|
3104
|
-
const
|
|
3015
|
+
const variableKeys = !isTopInstance ? collectAllVariableKeys(
|
|
3016
|
+
extractProps,
|
|
3017
|
+
fragmentManager,
|
|
3018
|
+
globalManager,
|
|
3019
|
+
areaManager
|
|
3020
|
+
) : [];
|
|
3021
|
+
const resolvedVariableResults = useReadVariables(variableKeys);
|
|
3022
|
+
const resolvedByKey = {};
|
|
3023
|
+
variableKeys.forEach((key, i) => {
|
|
3024
|
+
var _a;
|
|
3025
|
+
resolvedByKey[key] = ((_a = resolvedVariableResults[i]) == null ? void 0 : _a.value) ?? null;
|
|
3026
|
+
});
|
|
3105
3027
|
let resolvedProps = extractProps;
|
|
3106
3028
|
if (!isTopInstance) {
|
|
3107
3029
|
resolvedProps = {};
|
|
3108
3030
|
for (const [key, value] of Object.entries(extractProps)) {
|
|
3109
3031
|
if (!isVariableLink$1(value)) {
|
|
3110
|
-
|
|
3032
|
+
if (isObject(value)) {
|
|
3033
|
+
resolvedProps[key] = deepResolveObjectValuesFromMap(
|
|
3034
|
+
value,
|
|
3035
|
+
resolvedByKey
|
|
3036
|
+
);
|
|
3037
|
+
} else {
|
|
3038
|
+
resolvedProps[key] = value;
|
|
3039
|
+
}
|
|
3111
3040
|
continue;
|
|
3112
3041
|
}
|
|
3113
|
-
const
|
|
3042
|
+
const { layer: varLayer, manager: varManager } = resolveFromManagers(
|
|
3043
|
+
value,
|
|
3044
|
+
fragmentManager,
|
|
3045
|
+
globalManager,
|
|
3046
|
+
areaManager
|
|
3047
|
+
);
|
|
3114
3048
|
if ((varLayer == null ? void 0 : varLayer.type) === definition.variableType.Array) {
|
|
3115
3049
|
resolvedProps[key] = value;
|
|
3116
3050
|
continue;
|
|
3117
3051
|
}
|
|
3118
3052
|
if ((varLayer == null ? void 0 : varLayer.type) === definition.variableType.Object && (varLayer == null ? void 0 : varLayer.fields)) {
|
|
3119
|
-
resolvedProps[key] =
|
|
3053
|
+
resolvedProps[key] = resolveObjectToConcreteValueFromMap(
|
|
3120
3054
|
varLayer,
|
|
3121
|
-
|
|
3122
|
-
|
|
3055
|
+
varManager,
|
|
3056
|
+
resolvedByKey
|
|
3123
3057
|
);
|
|
3124
3058
|
continue;
|
|
3125
3059
|
}
|
|
3126
|
-
|
|
3127
|
-
resolvedProps[key] = resolved;
|
|
3060
|
+
resolvedProps[key] = resolvedByKey[value] ?? value;
|
|
3128
3061
|
}
|
|
3129
3062
|
}
|
|
3130
3063
|
useEffect(() => {
|
|
@@ -3185,6 +3118,45 @@ const useSuspenseLoadArea = (globalManager, areaCode, skip) => {
|
|
|
3185
3118
|
if (valueOrPromise == null) return null;
|
|
3186
3119
|
return createSuspenseResource(`area:${areaCode}`, valueOrPromise, cache).read();
|
|
3187
3120
|
};
|
|
3121
|
+
const collectPropertyCssVars = (manager, result) => {
|
|
3122
|
+
if (!(manager == null ? void 0 : manager.$properties)) return;
|
|
3123
|
+
const keys = manager.$properties.getPropertyKeys() ?? [];
|
|
3124
|
+
const processField = (fieldLayer) => {
|
|
3125
|
+
if (!(fieldLayer == null ? void 0 : fieldLayer._id)) return;
|
|
3126
|
+
if (fieldLayer.type === definition.variableType.Object && fieldLayer.fields) {
|
|
3127
|
+
for (const [key, ref] of Object.entries(fieldLayer.fields)) {
|
|
3128
|
+
if (key === "_type" || key === "_id") continue;
|
|
3129
|
+
const child = isObject(ref) ? ref : manager.resolve(ref);
|
|
3130
|
+
if (child) processField(child);
|
|
3131
|
+
}
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
if (fieldLayer.defaultValue != null) {
|
|
3135
|
+
result[`--${fieldLayer._id}`] = String(fieldLayer.defaultValue);
|
|
3136
|
+
}
|
|
3137
|
+
};
|
|
3138
|
+
for (const key of keys) {
|
|
3139
|
+
const layer = manager.resolve(key, { deep: true });
|
|
3140
|
+
if (layer) processField(layer);
|
|
3141
|
+
}
|
|
3142
|
+
};
|
|
3143
|
+
const useManagerCssProperties = () => {
|
|
3144
|
+
var _a, _b, _c, _d;
|
|
3145
|
+
const globalManager = useContext(GlobalManagerContext);
|
|
3146
|
+
const areaManager = useContext(AreaManagerContext);
|
|
3147
|
+
useGraph(globalManager, (_a = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _a.key);
|
|
3148
|
+
useGraph(areaManager, (_b = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _b.key);
|
|
3149
|
+
const globalKeys = ((_c = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _c.getPropertyKeys()) ?? [];
|
|
3150
|
+
const areaKeys = ((_d = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _d.getPropertyKeys()) ?? [];
|
|
3151
|
+
useGraphStack(globalKeys.length ? globalManager : null, globalKeys);
|
|
3152
|
+
useGraphStack(areaKeys.length ? areaManager : null, areaKeys);
|
|
3153
|
+
return useMemo(() => {
|
|
3154
|
+
const vars = {};
|
|
3155
|
+
collectPropertyCssVars(globalManager, vars);
|
|
3156
|
+
collectPropertyCssVars(areaManager, vars);
|
|
3157
|
+
return vars;
|
|
3158
|
+
}, [globalManager, areaManager, globalKeys.length, areaKeys.length]);
|
|
3159
|
+
};
|
|
3188
3160
|
const InstanceInitial = ({
|
|
3189
3161
|
Tag: inputTag,
|
|
3190
3162
|
style = {},
|
|
@@ -3216,71 +3188,43 @@ const InstanceInitial = ({
|
|
|
3216
3188
|
parentManager,
|
|
3217
3189
|
definitions
|
|
3218
3190
|
);
|
|
3219
|
-
const
|
|
3191
|
+
const propsCssVars = useMemo(
|
|
3220
3192
|
() => toCssCustomProperties(expandedProps),
|
|
3221
3193
|
[expandedProps]
|
|
3222
3194
|
);
|
|
3223
|
-
|
|
3224
|
-
const
|
|
3225
|
-
() => ({
|
|
3226
|
-
|
|
3227
|
-
props: expandedProps,
|
|
3228
|
-
definitions,
|
|
3229
|
-
fragmentId,
|
|
3230
|
-
documentManager: innerManager,
|
|
3231
|
-
layerKey: instanceProps.layerKey,
|
|
3232
|
-
onChangeProps
|
|
3233
|
-
}),
|
|
3234
|
-
[
|
|
3235
|
-
expandedProps,
|
|
3236
|
-
definitions,
|
|
3237
|
-
fragmentId,
|
|
3238
|
-
innerManager,
|
|
3239
|
-
instanceProps.layerKey,
|
|
3240
|
-
onChangeProps
|
|
3241
|
-
]
|
|
3195
|
+
const managerCssVars = useManagerCssProperties();
|
|
3196
|
+
const cssVars = useMemo(
|
|
3197
|
+
() => ({ ...managerCssVars, ...propsCssVars }),
|
|
3198
|
+
[managerCssVars, propsCssVars]
|
|
3242
3199
|
);
|
|
3200
|
+
useSuspenseLoadFragment(globalManager, fragmentId, !ssr);
|
|
3243
3201
|
const instanceContextValue = useMemo(
|
|
3244
3202
|
() => ({
|
|
3245
3203
|
layerKey: instanceProps.layerKey,
|
|
3246
3204
|
definitions,
|
|
3247
3205
|
innerManager,
|
|
3248
3206
|
parentManager,
|
|
3249
|
-
props: expandedProps
|
|
3207
|
+
props: expandedProps,
|
|
3208
|
+
onChangeProps
|
|
3250
3209
|
}),
|
|
3251
3210
|
[
|
|
3252
3211
|
instanceProps.layerKey,
|
|
3253
3212
|
definitions,
|
|
3254
3213
|
innerManager,
|
|
3255
3214
|
parentManager,
|
|
3256
|
-
expandedProps
|
|
3215
|
+
expandedProps,
|
|
3216
|
+
onChangeProps
|
|
3257
3217
|
]
|
|
3258
3218
|
);
|
|
3259
|
-
return /* @__PURE__ */ jsx(
|
|
3260
|
-
|
|
3219
|
+
return /* @__PURE__ */ jsx(InstanceContext.Provider, { value: instanceContextValue, children: parentManager ? /* @__PURE__ */ jsx(
|
|
3220
|
+
Tag,
|
|
3261
3221
|
{
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
className: classnames,
|
|
3269
|
-
"data-key": instanceProps.layerKey,
|
|
3270
|
-
style: { ...style, ...cssVars },
|
|
3271
|
-
...link.linkProps,
|
|
3272
|
-
...events,
|
|
3273
|
-
children: /* @__PURE__ */ jsx(
|
|
3274
|
-
Fragment,
|
|
3275
|
-
{
|
|
3276
|
-
fragmentId,
|
|
3277
|
-
globalManager,
|
|
3278
|
-
FrameElement,
|
|
3279
|
-
pauseInteractions
|
|
3280
|
-
}
|
|
3281
|
-
)
|
|
3282
|
-
}
|
|
3283
|
-
) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsx(
|
|
3222
|
+
className: classnames,
|
|
3223
|
+
"data-key": instanceProps.layerKey,
|
|
3224
|
+
style: { ...style, ...cssVars },
|
|
3225
|
+
...link.linkProps,
|
|
3226
|
+
...events,
|
|
3227
|
+
children: /* @__PURE__ */ jsx(
|
|
3284
3228
|
Fragment,
|
|
3285
3229
|
{
|
|
3286
3230
|
fragmentId,
|
|
@@ -3288,18 +3232,26 @@ const InstanceInitial = ({
|
|
|
3288
3232
|
FrameElement,
|
|
3289
3233
|
pauseInteractions
|
|
3290
3234
|
}
|
|
3291
|
-
)
|
|
3235
|
+
)
|
|
3292
3236
|
}
|
|
3293
|
-
)
|
|
3237
|
+
) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsx(
|
|
3238
|
+
Fragment,
|
|
3239
|
+
{
|
|
3240
|
+
fragmentId,
|
|
3241
|
+
globalManager,
|
|
3242
|
+
FrameElement,
|
|
3243
|
+
pauseInteractions
|
|
3244
|
+
}
|
|
3245
|
+
) }) });
|
|
3294
3246
|
};
|
|
3295
3247
|
const Instance = (props) => {
|
|
3296
|
-
return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, {
|
|
3248
|
+
return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsx(
|
|
3297
3249
|
RenderTargetProvider,
|
|
3298
3250
|
{
|
|
3299
3251
|
value: props.renderTarget ?? definition.renderTarget.document,
|
|
3300
3252
|
children: /* @__PURE__ */ jsx(InstanceInitial, { ...props })
|
|
3301
3253
|
}
|
|
3302
|
-
) }) }) : /* @__PURE__ */ jsx(Suspense, {
|
|
3254
|
+
) }) }) : /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(
|
|
3303
3255
|
RenderTargetProvider,
|
|
3304
3256
|
{
|
|
3305
3257
|
value: props.renderTarget ?? definition.renderTarget.document,
|
|
@@ -3451,16 +3403,16 @@ const AreaInitial = (areaProps) => {
|
|
|
3451
3403
|
() => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(areaProps == null ? void 0 : areaProps.props) ?? {} }),
|
|
3452
3404
|
[areaData, areaProps]
|
|
3453
3405
|
);
|
|
3454
|
-
if (!areaData) return null;
|
|
3455
3406
|
const areaManager = useMemo(
|
|
3456
3407
|
() => createAreaManager({
|
|
3457
|
-
areaId: areaData.areaId,
|
|
3458
|
-
campaignId: areaData.campaignId,
|
|
3459
|
-
variantId: areaData.variantId,
|
|
3460
|
-
areaProperties: areaData.areaProperties
|
|
3408
|
+
areaId: areaData == null ? void 0 : areaData.areaId,
|
|
3409
|
+
campaignId: areaData == null ? void 0 : areaData.campaignId,
|
|
3410
|
+
variantId: areaData == null ? void 0 : areaData.variantId,
|
|
3411
|
+
areaProperties: areaData == null ? void 0 : areaData.areaProperties
|
|
3461
3412
|
}),
|
|
3462
|
-
[areaData.areaId]
|
|
3413
|
+
[areaData == null ? void 0 : areaData.areaId]
|
|
3463
3414
|
);
|
|
3415
|
+
if (!areaData) return null;
|
|
3464
3416
|
return /* @__PURE__ */ jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsx(
|
|
3465
3417
|
Scope,
|
|
3466
3418
|
{
|
|
@@ -3511,7 +3463,7 @@ export {
|
|
|
3511
3463
|
GlobalManagerContext,
|
|
3512
3464
|
GlobalManagerProvider,
|
|
3513
3465
|
Instance,
|
|
3514
|
-
InstanceContext
|
|
3466
|
+
InstanceContext,
|
|
3515
3467
|
RenderTargetContext,
|
|
3516
3468
|
RenderTargetProvider,
|
|
3517
3469
|
Scope,
|