@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.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@ 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");
|
|
6
7
|
const utils = require("@fragmentsx/utils");
|
|
7
8
|
const core = require("@graph-state/core");
|
|
8
|
-
const react$1 = require("@graph-state/react");
|
|
9
9
|
const clientCore = require("@fragmentsx/client-core");
|
|
10
10
|
const GlobalManagerContext = react.createContext(null);
|
|
11
11
|
const GlobalManagerProvider = GlobalManagerContext.Provider;
|
|
@@ -14,12 +14,13 @@ const FragmentContext = react.createContext({
|
|
|
14
14
|
});
|
|
15
15
|
const defaultCustomRender = (layerKey, node) => node;
|
|
16
16
|
const CustomRender = react.createContext(defaultCustomRender);
|
|
17
|
-
const InstanceContext
|
|
17
|
+
const InstanceContext = react.createContext({
|
|
18
18
|
layerKey: null,
|
|
19
19
|
parentManager: null,
|
|
20
20
|
innerManager: null,
|
|
21
21
|
props: {},
|
|
22
|
-
definitions: []
|
|
22
|
+
definitions: [],
|
|
23
|
+
onChangeProps: null
|
|
23
24
|
});
|
|
24
25
|
const RenderTargetContext = react.createContext(
|
|
25
26
|
definition.definition.renderTarget.document
|
|
@@ -662,8 +663,8 @@ function hashGenerator(layerKey) {
|
|
|
662
663
|
return /^[0-9]/.test(raw) ? `h${raw}` : raw;
|
|
663
664
|
}
|
|
664
665
|
const transformCssValue = (value) => {
|
|
665
|
-
var _a;
|
|
666
|
-
if ((_a = value == null ? void 0 : value.startsWith) == null ? void 0 : _a.call(value, "http")) {
|
|
666
|
+
var _a, _b;
|
|
667
|
+
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:"))) {
|
|
667
668
|
value = `url("${value}")`;
|
|
668
669
|
}
|
|
669
670
|
return value;
|
|
@@ -863,178 +864,139 @@ const useResolvedLayer = (layerKey, options) => {
|
|
|
863
864
|
}
|
|
864
865
|
return { layerKey: key, rawLayer, layer, isOverride };
|
|
865
866
|
};
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
const EMPTY_RESOLVED = {
|
|
870
|
-
values: {},
|
|
871
|
-
cssVariableValues: {},
|
|
872
|
-
rawValues: {}
|
|
873
|
-
};
|
|
874
|
-
const extractVariableValue$1 = (input, variableId) => {
|
|
875
|
-
if (utils.isObject(input)) {
|
|
867
|
+
const extractVariableValue = (input, variableId) => {
|
|
868
|
+
if (input && typeof input === "object") {
|
|
876
869
|
if (variableId in input) return input[variableId];
|
|
877
870
|
for (const key in input) {
|
|
878
871
|
if (input.hasOwnProperty(key)) {
|
|
879
|
-
const result = extractVariableValue
|
|
872
|
+
const result = extractVariableValue(input[key], variableId);
|
|
880
873
|
if (result !== void 0) return result;
|
|
881
874
|
}
|
|
882
875
|
}
|
|
883
876
|
}
|
|
884
877
|
return void 0;
|
|
885
878
|
};
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
const
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
879
|
+
const useReadVariables = (variableKeys, customManager) => {
|
|
880
|
+
var _a, _b, _c, _d;
|
|
881
|
+
const filterKeys = variableKeys.filter(definition.isVariableLink);
|
|
882
|
+
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
883
|
+
const { props: instanceProps } = react.useContext(InstanceContext);
|
|
884
|
+
const globalManager = react.useContext(GlobalManagerContext);
|
|
885
|
+
const areaManager = react.useContext(AreaManagerContext);
|
|
886
|
+
const scopes = react.useContext(ScopeContext);
|
|
887
|
+
const resultManager = customManager ?? ((_a = react.useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
|
|
888
|
+
const safeFilterKeys = resultManager ? filterKeys : [];
|
|
889
|
+
const variableLayers = react$1.useGraphStack(
|
|
890
|
+
safeFilterKeys.length ? resultManager : null,
|
|
891
|
+
safeFilterKeys,
|
|
892
|
+
{
|
|
893
|
+
selector: (graph) => graph ? utils.pick(graph, "_id", "defaultValue", "required") : graph
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
react$1.useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
|
|
897
|
+
react$1.useGraph(areaManager, (_c = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _c.key);
|
|
898
|
+
const globalPropertyKeys = react.useMemo(() => {
|
|
899
|
+
if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
|
|
900
|
+
return filterKeys.filter((key) => globalManager.resolve(key));
|
|
901
|
+
}, [filterKeys, globalManager]);
|
|
902
|
+
const areaPropertyKeys = react.useMemo(() => {
|
|
903
|
+
if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
|
|
904
|
+
return filterKeys.filter((key) => areaManager.resolve(key));
|
|
905
|
+
}, [filterKeys, areaManager]);
|
|
906
|
+
react$1.useGraphStack(
|
|
907
|
+
globalPropertyKeys.length ? globalManager : null,
|
|
908
|
+
globalPropertyKeys
|
|
909
|
+
);
|
|
910
|
+
react$1.useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
|
|
911
|
+
const lastCollectionItem = (_d = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _d.call(
|
|
912
|
+
scopes,
|
|
913
|
+
(scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.CollectionItemScope
|
|
914
|
+
);
|
|
915
|
+
return filterKeys.map((variableKey, index) => {
|
|
916
|
+
var _a2;
|
|
917
|
+
const layer = variableLayers[index] ?? null;
|
|
918
|
+
const { _id: propertyId } = layer ?? {};
|
|
919
|
+
let collectionItemProp = void 0;
|
|
920
|
+
if (lastCollectionItem && propertyId) {
|
|
921
|
+
collectionItemProp = utils.isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_a2 = core.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);
|
|
922
|
+
}
|
|
923
|
+
const instanceProp = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? null;
|
|
924
|
+
const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
|
|
925
|
+
const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
|
|
926
|
+
const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
|
|
927
|
+
const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
|
|
928
|
+
const required = (layer == null ? void 0 : layer.required) ?? false;
|
|
929
|
+
const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
|
|
930
|
+
const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
|
|
931
|
+
const resultValue = required ? currentValue : currentValue ?? defaultValue;
|
|
932
|
+
if (definition.isVariableLink(resultValue)) {
|
|
933
|
+
const refKey = resultValue;
|
|
934
|
+
const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
|
|
935
|
+
const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
|
|
936
|
+
const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
|
|
937
|
+
const refValue = (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
|
|
938
|
+
return {
|
|
939
|
+
value: refValue,
|
|
940
|
+
layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
|
|
941
|
+
};
|
|
894
942
|
}
|
|
895
|
-
|
|
896
|
-
|
|
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();
|
|
943
|
+
return {
|
|
944
|
+
value: resultValue,
|
|
945
|
+
layer: layer ?? areaLayer ?? globalLayer ?? null
|
|
910
946
|
};
|
|
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
947
|
});
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
948
|
+
};
|
|
949
|
+
const EMPTY_RESOLVED = {
|
|
950
|
+
values: {},
|
|
951
|
+
cssVariableValues: {},
|
|
952
|
+
rawValues: {}
|
|
953
|
+
};
|
|
954
|
+
const collectVariableKeys = (layer) => {
|
|
955
|
+
const keys = [];
|
|
956
|
+
if (!layer) return keys;
|
|
957
|
+
for (const [, value] of Object.entries(layer)) {
|
|
958
|
+
if (definition.isVariableLink(value)) {
|
|
959
|
+
keys.push(value);
|
|
960
|
+
} else if (utils.isObject(value) && !definition.isVariableLink(value)) {
|
|
961
|
+
for (const [, nestedValue] of Object.entries(
|
|
962
|
+
value
|
|
963
|
+
)) {
|
|
964
|
+
if (definition.isVariableLink(nestedValue)) {
|
|
965
|
+
keys.push(nestedValue);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
920
969
|
}
|
|
970
|
+
return keys;
|
|
971
|
+
};
|
|
972
|
+
const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
|
|
973
|
+
var _a;
|
|
974
|
+
const variableKeys = collectVariableKeys(layer);
|
|
975
|
+
const resolved = useReadVariables(variableKeys);
|
|
976
|
+
if (!layer) return EMPTY_RESOLVED;
|
|
977
|
+
const resolvedByKey = {};
|
|
978
|
+
variableKeys.forEach((key, i) => {
|
|
979
|
+
var _a2;
|
|
980
|
+
resolvedByKey[key] = ((_a2 = resolved[i]) == null ? void 0 : _a2.value) ?? null;
|
|
981
|
+
});
|
|
921
982
|
const values = {};
|
|
922
983
|
const cssVariableValues = {};
|
|
923
984
|
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
985
|
const resolveField = (fieldPath, value, raw) => {
|
|
1023
986
|
var _a2;
|
|
1024
987
|
rawValues[fieldPath] = raw;
|
|
1025
988
|
if (definition.isVariableLink(value)) {
|
|
1026
|
-
const
|
|
1027
|
-
values[fieldPath] =
|
|
989
|
+
const resolvedValue = resolvedByKey[value] ?? value;
|
|
990
|
+
values[fieldPath] = resolvedValue;
|
|
1028
991
|
const variableId = (_a2 = core.entityOfKey(value)) == null ? void 0 : _a2._id;
|
|
1029
992
|
cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
|
|
1030
|
-
|
|
993
|
+
resolvedValue
|
|
1031
994
|
)})`;
|
|
1032
995
|
} else {
|
|
1033
996
|
values[fieldPath] = value;
|
|
1034
997
|
cssVariableValues[fieldPath] = transformCssValue(value);
|
|
1035
998
|
}
|
|
1036
999
|
};
|
|
1037
|
-
subscriptions.current = [];
|
|
1038
1000
|
for (const [field, value] of Object.entries(layer)) {
|
|
1039
1001
|
resolveField(field, value, rawLayer == null ? void 0 : rawLayer[field]);
|
|
1040
1002
|
if (utils.isObject(value) && !definition.isVariableLink(value)) {
|
|
@@ -1059,188 +1021,6 @@ const useRenderTarget = () => {
|
|
|
1059
1021
|
isDocument: renderTarget === definition.definition.renderTarget.document
|
|
1060
1022
|
};
|
|
1061
1023
|
};
|
|
1062
|
-
const useReadVariables = (variableKeys) => {
|
|
1063
|
-
const filterKeys = variableKeys.filter(definition.isVariableLink);
|
|
1064
|
-
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
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
|
-
}
|
|
1073
|
-
);
|
|
1074
|
-
return variableLayers.map((layer) => {
|
|
1075
|
-
const { _id: propertyId } = layer ?? {};
|
|
1076
|
-
const currentValue = (props == null ? void 0 : props[propertyId]) ?? null;
|
|
1077
|
-
const required = (layer == null ? void 0 : layer.required) ?? false;
|
|
1078
|
-
const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
|
|
1079
|
-
const resultValue = required ? currentValue : currentValue ?? defaultValue;
|
|
1080
|
-
return {
|
|
1081
|
-
value: resultValue,
|
|
1082
|
-
layer
|
|
1083
|
-
};
|
|
1084
|
-
});
|
|
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
|
-
};
|
|
1244
1024
|
const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
1245
1025
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1246
1026
|
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
@@ -1252,12 +1032,21 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1252
1032
|
// selector: (data) => (data ? pick(data, fieldKey) : data),
|
|
1253
1033
|
});
|
|
1254
1034
|
const normalizeLayers = useNormalizeLayers(keys, resultManager, options);
|
|
1255
|
-
const
|
|
1035
|
+
const variableKeysFromLayers = normalizeLayers.map((nl) => utils.get(nl.layer, fieldKey)).filter(definition.isVariableLink);
|
|
1036
|
+
const resolvedVariables = useReadVariables(
|
|
1037
|
+
variableKeysFromLayers,
|
|
1038
|
+
resultManager
|
|
1039
|
+
);
|
|
1040
|
+
const resolvedByKey = {};
|
|
1041
|
+
variableKeysFromLayers.forEach((key, i) => {
|
|
1042
|
+
var _a;
|
|
1043
|
+
resolvedByKey[key] = ((_a = resolvedVariables[i]) == null ? void 0 : _a.value) ?? null;
|
|
1044
|
+
});
|
|
1256
1045
|
return normalizeLayers.map((normalizedLayer) => {
|
|
1257
|
-
var _a
|
|
1046
|
+
var _a;
|
|
1258
1047
|
const rawValue = utils.get(normalizedLayer.rawLayer, fieldKey);
|
|
1259
1048
|
const layerValue = utils.get(normalizedLayer.layer, fieldKey);
|
|
1260
|
-
const variableValue = (
|
|
1049
|
+
const variableValue = definition.isVariableLink(layerValue) ? resolvedByKey[layerValue] ?? null : null;
|
|
1261
1050
|
const currentValue = variableValue ?? layerValue;
|
|
1262
1051
|
const isInherit = isInheritField(
|
|
1263
1052
|
resultManager,
|
|
@@ -1282,15 +1071,15 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1282
1071
|
);
|
|
1283
1072
|
};
|
|
1284
1073
|
const restore = (fallbackValue) => {
|
|
1285
|
-
var _a2,
|
|
1286
|
-
const tempValue = ((_c = (
|
|
1074
|
+
var _a2, _b, _c;
|
|
1075
|
+
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;
|
|
1287
1076
|
return tempValue;
|
|
1288
1077
|
};
|
|
1289
1078
|
const updateValue = (value, options2) => {
|
|
1290
1079
|
setter(value, options2);
|
|
1291
1080
|
};
|
|
1292
1081
|
const isVariable = definition.isVariableLink(rawValue ?? layerValue);
|
|
1293
|
-
const variableId = isVariable ? (
|
|
1082
|
+
const variableId = isVariable ? (_a = core.entityOfKey(layerValue)) == null ? void 0 : _a._id : null;
|
|
1294
1083
|
return [
|
|
1295
1084
|
currentValue,
|
|
1296
1085
|
updateValue,
|
|
@@ -1307,7 +1096,7 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1307
1096
|
});
|
|
1308
1097
|
};
|
|
1309
1098
|
const useLayerValue = (layerKey, fieldKey, options) => {
|
|
1310
|
-
var _a;
|
|
1099
|
+
var _a, _b;
|
|
1311
1100
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1312
1101
|
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
1313
1102
|
if (!resultManager) {
|
|
@@ -1320,7 +1109,11 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1320
1109
|
const { layer, rawLayer } = useNormalizeLayer(key, resultManager, options);
|
|
1321
1110
|
const rawValue = utils.get(rawLayer, fieldKey);
|
|
1322
1111
|
const layerValue = utils.get(layer, fieldKey);
|
|
1323
|
-
const
|
|
1112
|
+
const variableResults = useReadVariables(
|
|
1113
|
+
definition.isVariableLink(layerValue) ? [layerValue] : [],
|
|
1114
|
+
resultManager
|
|
1115
|
+
);
|
|
1116
|
+
const variableValue = ((_a = variableResults[0]) == null ? void 0 : _a.value) ?? null;
|
|
1324
1117
|
const currentValue = variableValue ?? layerValue;
|
|
1325
1118
|
const isInherit = isInheritField(resultManager, key, fieldKey);
|
|
1326
1119
|
const isOverride = !isInherit && !isPartOfPrimary(resultManager, key);
|
|
@@ -1337,8 +1130,8 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1337
1130
|
}, [updateLayerData]);
|
|
1338
1131
|
const restore = react.useCallback(
|
|
1339
1132
|
(fallbackValue) => {
|
|
1340
|
-
var _a2,
|
|
1341
|
-
const tempValue = ((_c = (
|
|
1133
|
+
var _a2, _b2, _c;
|
|
1134
|
+
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;
|
|
1342
1135
|
updateLayerData({ [fieldKey]: tempValue });
|
|
1343
1136
|
return tempValue;
|
|
1344
1137
|
},
|
|
@@ -1351,7 +1144,7 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1351
1144
|
[setter]
|
|
1352
1145
|
);
|
|
1353
1146
|
const isVariable = definition.isVariableLink(rawValue ?? layerValue);
|
|
1354
|
-
const variableId = isVariable ? (
|
|
1147
|
+
const variableId = isVariable ? (_b = core.entityOfKey(layerValue)) == null ? void 0 : _b._id : null;
|
|
1355
1148
|
return [
|
|
1356
1149
|
currentValue,
|
|
1357
1150
|
updateValue,
|
|
@@ -1366,6 +1159,20 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1366
1159
|
}
|
|
1367
1160
|
];
|
|
1368
1161
|
};
|
|
1162
|
+
const useReadVariable = (variableKey, _customScopes) => {
|
|
1163
|
+
const keys = variableKey && definition.isVariableLink(variableKey) ? [variableKey] : [];
|
|
1164
|
+
const results = useReadVariables(keys);
|
|
1165
|
+
const result = results[0] ?? { value: null, layer: null };
|
|
1166
|
+
return {
|
|
1167
|
+
...result,
|
|
1168
|
+
readVariable: () => {
|
|
1169
|
+
throw new Error(
|
|
1170
|
+
"readVariable() removed — используй useReadVariables"
|
|
1171
|
+
);
|
|
1172
|
+
},
|
|
1173
|
+
_dep: 0
|
|
1174
|
+
};
|
|
1175
|
+
};
|
|
1369
1176
|
const useLayerChildren = (layerKey, customManager) => {
|
|
1370
1177
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1371
1178
|
const [layerData] = react$1.useGraph(customManager ?? fragmentManager, layerKey, {
|
|
@@ -1415,6 +1222,7 @@ const useLayerLink = (layerKey) => {
|
|
|
1415
1222
|
};
|
|
1416
1223
|
};
|
|
1417
1224
|
const useLayerVariableValue = (layerKey, fieldKey, manager) => {
|
|
1225
|
+
var _a;
|
|
1418
1226
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1419
1227
|
const resultManager = manager ?? fragmentManager;
|
|
1420
1228
|
const [layerValue, updateValue, layerInfo] = useLayerValue(
|
|
@@ -1422,9 +1230,11 @@ const useLayerVariableValue = (layerKey, fieldKey, manager) => {
|
|
|
1422
1230
|
fieldKey,
|
|
1423
1231
|
resultManager
|
|
1424
1232
|
);
|
|
1425
|
-
const
|
|
1426
|
-
(layerInfo == null ? void 0 : layerInfo.isVariable) ? layerValue :
|
|
1233
|
+
const variableResults = useReadVariables(
|
|
1234
|
+
(layerInfo == null ? void 0 : layerInfo.isVariable) && definition.isVariableLink(layerValue) ? [layerValue] : [],
|
|
1235
|
+
resultManager
|
|
1427
1236
|
);
|
|
1237
|
+
const instanceValue = ((_a = variableResults[0]) == null ? void 0 : _a.value) ?? null;
|
|
1428
1238
|
return [
|
|
1429
1239
|
(layerInfo == null ? void 0 : layerInfo.isVariable) ? instanceValue : layerValue,
|
|
1430
1240
|
updateValue,
|
|
@@ -1525,7 +1335,7 @@ const calcLayerSizeValue = (resolved, vars, sizeType, parentResolved, instanceVa
|
|
|
1525
1335
|
};
|
|
1526
1336
|
const useLayerSizeValue = (layerKey, sizeType) => {
|
|
1527
1337
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1528
|
-
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext
|
|
1338
|
+
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext);
|
|
1529
1339
|
const { isDocument } = useRenderTarget();
|
|
1530
1340
|
const isTop = isTopLevel(fragmentManager, layerKey);
|
|
1531
1341
|
const isPartOfInstance = !!instanceLayerKey;
|
|
@@ -1637,7 +1447,7 @@ const calcLayerPosition = (resolved, vars, parentResolved, instanceResolved, ins
|
|
|
1637
1447
|
};
|
|
1638
1448
|
};
|
|
1639
1449
|
const useLayerPosition = (layerKey) => {
|
|
1640
|
-
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext
|
|
1450
|
+
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext);
|
|
1641
1451
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1642
1452
|
const isTop = isTopLevel(fragmentManager, layerKey);
|
|
1643
1453
|
const { isDocument } = useRenderTarget();
|
|
@@ -1981,7 +1791,7 @@ const useLayerStyles = (layerKey) => {
|
|
|
1981
1791
|
try {
|
|
1982
1792
|
if (!layerKey) throw new Error("Empty layer key");
|
|
1983
1793
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1984
|
-
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext
|
|
1794
|
+
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext);
|
|
1985
1795
|
const { isDocument } = useRenderTarget();
|
|
1986
1796
|
const resolved = useResolvedLayer(layerKey);
|
|
1987
1797
|
const vars = useResolvedLayerVariables(resolved.layer, resolved.rawLayer);
|
|
@@ -2122,16 +1932,14 @@ const useTextContent = (layerKey, manager) => {
|
|
|
2122
1932
|
fragmentManager
|
|
2123
1933
|
);
|
|
2124
1934
|
const variables = extractVariablesFromHtml(content);
|
|
2125
|
-
const
|
|
2126
|
-
|
|
2127
|
-
fragmentManager,
|
|
2128
|
-
variables.map((variable) => variable.variableKey)
|
|
2129
|
-
);
|
|
1935
|
+
const variableKeys = variables.map((variable) => variable.variableKey);
|
|
1936
|
+
const resolvedVariables = useReadVariables(variableKeys);
|
|
2130
1937
|
let nextContent = content;
|
|
2131
|
-
variables.forEach((variable) => {
|
|
1938
|
+
variables.forEach((variable, index) => {
|
|
1939
|
+
var _a;
|
|
2132
1940
|
nextContent = nextContent.replace(
|
|
2133
1941
|
variable.fullMatch,
|
|
2134
|
-
|
|
1942
|
+
((_a = resolvedVariables[index]) == null ? void 0 : _a.value) ?? ""
|
|
2135
1943
|
);
|
|
2136
1944
|
});
|
|
2137
1945
|
if (typeof nextContent === "string") {
|
|
@@ -2219,31 +2027,31 @@ const useGlobalManager = (globalManager) => {
|
|
|
2219
2027
|
};
|
|
2220
2028
|
};
|
|
2221
2029
|
const useLayerInteractions = (layerKey, options) => {
|
|
2030
|
+
var _a;
|
|
2222
2031
|
const pause = (options == null ? void 0 : options.pauseInteractions) ?? false;
|
|
2223
2032
|
const { manager: globalManager } = useGlobalManager();
|
|
2224
2033
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
2225
2034
|
const scopes = react.useContext(ScopeContext);
|
|
2226
|
-
const areaScope = scopes.find(
|
|
2035
|
+
const areaScope = (_a = scopes == null ? void 0 : scopes.find) == null ? void 0 : _a.call(
|
|
2036
|
+
scopes,
|
|
2227
2037
|
(scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.AreaScope
|
|
2228
2038
|
);
|
|
2229
|
-
const
|
|
2230
|
-
(scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.InstanceScope
|
|
2231
|
-
);
|
|
2039
|
+
const { onChangeProps } = react.useContext(InstanceContext);
|
|
2232
2040
|
const [interactionLinks] = useLayerValue(layerKey, "interactions");
|
|
2233
2041
|
const interactionOns = useLayersValue(interactionLinks, "on");
|
|
2234
2042
|
const interactionEvents = useLayersValue(interactionLinks, "event");
|
|
2235
2043
|
const interactions = (interactionLinks ?? []).map((linkKey, index) => {
|
|
2236
|
-
var
|
|
2044
|
+
var _a2, _b;
|
|
2237
2045
|
return {
|
|
2238
2046
|
linkKey,
|
|
2239
|
-
on: (
|
|
2047
|
+
on: (_a2 = interactionOns == null ? void 0 : interactionOns.at(index)) == null ? void 0 : _a2.at(0),
|
|
2240
2048
|
event: (_b = interactionEvents == null ? void 0 : interactionEvents.at(index)) == null ? void 0 : _b.at(0)
|
|
2241
2049
|
};
|
|
2242
2050
|
});
|
|
2243
2051
|
const fireEvent = react.useCallback(
|
|
2244
2052
|
(eventLink) => {
|
|
2245
|
-
var
|
|
2246
|
-
const eventType = (
|
|
2053
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2054
|
+
const eventType = (_a2 = core.entityOfKey(eventLink)) == null ? void 0 : _a2._type;
|
|
2247
2055
|
const eventValue = (_b = getNormalizeLayer(eventLink, fragmentManager)) == null ? void 0 : _b.layer;
|
|
2248
2056
|
console.log(scopes, eventLink, eventType, eventValue);
|
|
2249
2057
|
if (eventType === definition.definition.nodes.GoalEvent && (eventValue == null ? void 0 : eventValue.goalId)) {
|
|
@@ -2260,7 +2068,7 @@ const useLayerInteractions = (layerKey, options) => {
|
|
|
2260
2068
|
const value = (eventValue == null ? void 0 : eventValue.value) ?? ((_f = targetLayer == null ? void 0 : targetLayer.layer) == null ? void 0 : _f.defaultValue);
|
|
2261
2069
|
if (definition.isVariableLink(target) && utils.isValue(value)) {
|
|
2262
2070
|
const targetId = (_g = core.entityOfKey(target)) == null ? void 0 : _g._id;
|
|
2263
|
-
|
|
2071
|
+
onChangeProps == null ? void 0 : onChangeProps(targetId, value);
|
|
2264
2072
|
}
|
|
2265
2073
|
}
|
|
2266
2074
|
},
|
|
@@ -2544,6 +2352,7 @@ const buildFieldIdMapping = (childDef, parentDef, childManager, parentManager) =
|
|
|
2544
2352
|
continue;
|
|
2545
2353
|
}
|
|
2546
2354
|
mapping[parentFieldVar._id] = childFieldVar._id;
|
|
2355
|
+
mapping[fieldName] = childFieldVar._id;
|
|
2547
2356
|
}
|
|
2548
2357
|
return mapping;
|
|
2549
2358
|
};
|
|
@@ -2575,7 +2384,30 @@ const remapArrayItems = (items, mapping) => {
|
|
|
2575
2384
|
});
|
|
2576
2385
|
};
|
|
2577
2386
|
const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
2578
|
-
const
|
|
2387
|
+
const areaManager = react.useContext(AreaManagerContext);
|
|
2388
|
+
const globalManager = react.useContext(GlobalManagerContext);
|
|
2389
|
+
const arrayVariableKeys = react.useMemo(() => {
|
|
2390
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2391
|
+
const keys = [];
|
|
2392
|
+
for (const defKey of definitions) {
|
|
2393
|
+
const defVar = manager.resolve(defKey);
|
|
2394
|
+
if (!(defVar == null ? void 0 : defVar._id)) continue;
|
|
2395
|
+
if (defVar.type !== definition.definition.variableType.Array || !defVar.definition)
|
|
2396
|
+
continue;
|
|
2397
|
+
const propValue = props[defVar._id];
|
|
2398
|
+
if (definition.isVariableLink(propValue)) {
|
|
2399
|
+
keys.push(propValue);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
return keys;
|
|
2403
|
+
}, [definitions, manager, props]);
|
|
2404
|
+
const arrayResolvedResults = useReadVariables(arrayVariableKeys);
|
|
2405
|
+
const arrayResolvedByKey = {};
|
|
2406
|
+
arrayVariableKeys.forEach((key, i) => {
|
|
2407
|
+
var _a, _b;
|
|
2408
|
+
arrayResolvedByKey[key] = ((_a = arrayResolvedResults[i]) == null ? void 0 : _a.value) ?? null;
|
|
2409
|
+
((_b = arrayResolvedResults[i]) == null ? void 0 : _b.layer) ?? null;
|
|
2410
|
+
});
|
|
2579
2411
|
const leafKeys = react.useMemo(() => {
|
|
2580
2412
|
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2581
2413
|
const keys = [];
|
|
@@ -2594,12 +2426,12 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2594
2426
|
return keys;
|
|
2595
2427
|
}, [definitions, manager]);
|
|
2596
2428
|
const leafLayers = react$1.useGraphStack(leafKeys.length ? manager : null, leafKeys);
|
|
2597
|
-
const arrayItemKeys = react.useMemo(() => {
|
|
2429
|
+
const { arrayItemKeys, arrayItemManager } = react.useMemo(() => {
|
|
2598
2430
|
var _a;
|
|
2599
|
-
if (!manager || !(definitions == null ? void 0 : definitions.length))
|
|
2600
|
-
|
|
2601
|
-
if (!resolveManager) return [];
|
|
2431
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length))
|
|
2432
|
+
return { arrayItemKeys: [], arrayItemManager: null };
|
|
2602
2433
|
const keys = [];
|
|
2434
|
+
let itemManager = null;
|
|
2603
2435
|
for (const defKey of definitions) {
|
|
2604
2436
|
const defVar = manager.resolve(defKey);
|
|
2605
2437
|
if (!(defVar == null ? void 0 : defVar._id)) continue;
|
|
@@ -2607,14 +2439,17 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2607
2439
|
continue;
|
|
2608
2440
|
const propValue = props[defVar._id];
|
|
2609
2441
|
if (!definition.isVariableLink(propValue)) continue;
|
|
2610
|
-
const
|
|
2442
|
+
const resolveManager = parentManager ?? manager;
|
|
2443
|
+
const parentVar = (resolveManager == null ? void 0 : resolveManager.resolve(propValue)) ?? (areaManager == null ? void 0 : areaManager.resolve(propValue)) ?? (globalManager == null ? void 0 : globalManager.resolve(propValue));
|
|
2444
|
+
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;
|
|
2611
2445
|
if ((parentVar == null ? void 0 : parentVar.type) !== definition.definition.variableType.Array) continue;
|
|
2612
2446
|
const items = parentVar.defaultValue;
|
|
2613
2447
|
if (!Array.isArray(items)) continue;
|
|
2448
|
+
if (ownerManager) itemManager = ownerManager;
|
|
2614
2449
|
for (const item of items) {
|
|
2615
2450
|
if (definition.isLink(item)) {
|
|
2616
2451
|
keys.push(item);
|
|
2617
|
-
const resolved =
|
|
2452
|
+
const resolved = ownerManager == null ? void 0 : ownerManager.resolve(item);
|
|
2618
2453
|
if ((resolved == null ? void 0 : resolved.value) && utils.isObject(resolved.value) && ((_a = resolved.value) == null ? void 0 : _a._type)) {
|
|
2619
2454
|
const valueKey = core.keyOfEntity(resolved.value);
|
|
2620
2455
|
if (valueKey) keys.push(valueKey);
|
|
@@ -2622,13 +2457,14 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2622
2457
|
}
|
|
2623
2458
|
}
|
|
2624
2459
|
}
|
|
2625
|
-
return keys;
|
|
2626
|
-
}, [definitions, manager, parentManager,
|
|
2460
|
+
return { arrayItemKeys: keys, arrayItemManager: itemManager };
|
|
2461
|
+
}, [definitions, manager, parentManager, areaManager, globalManager, props]);
|
|
2627
2462
|
const arrayItemLayers = react$1.useGraphStack(
|
|
2628
|
-
arrayItemKeys.length ? parentManager ?? manager : null,
|
|
2463
|
+
arrayItemKeys.length ? arrayItemManager ?? parentManager ?? manager : null,
|
|
2629
2464
|
arrayItemKeys
|
|
2630
2465
|
);
|
|
2631
2466
|
return react.useMemo(() => {
|
|
2467
|
+
var _a;
|
|
2632
2468
|
if (!manager || !(definitions == null ? void 0 : definitions.length)) return props;
|
|
2633
2469
|
const resolveManager = parentManager ?? manager;
|
|
2634
2470
|
const base = {};
|
|
@@ -2659,26 +2495,22 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2659
2495
|
continue;
|
|
2660
2496
|
}
|
|
2661
2497
|
if (defVar.type === definition.definition.variableType.Array && defVar.definition) {
|
|
2662
|
-
if (definition.isVariableLink(propValue)
|
|
2663
|
-
const parentVar = resolveManager.resolve(propValue);
|
|
2498
|
+
if (definition.isVariableLink(propValue)) {
|
|
2499
|
+
const parentVar = (resolveManager == null ? void 0 : resolveManager.resolve(propValue)) ?? (areaManager == null ? void 0 : areaManager.resolve(propValue)) ?? (globalManager == null ? void 0 : globalManager.resolve(propValue));
|
|
2500
|
+
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;
|
|
2664
2501
|
if ((parentVar == null ? void 0 : parentVar.type) === definition.definition.variableType.Array && (parentVar == null ? void 0 : parentVar.definition)) {
|
|
2665
|
-
const
|
|
2502
|
+
const resolvedArray = arrayResolvedByKey[propValue];
|
|
2666
2503
|
if (Array.isArray(resolvedArray)) {
|
|
2667
|
-
const
|
|
2668
|
-
|
|
2669
|
-
resolveManager
|
|
2670
|
-
);
|
|
2504
|
+
const itemResolver = parentVarManager ?? resolveManager;
|
|
2505
|
+
const concreteItems = itemResolver ? resolveArrayItems(resolvedArray, itemResolver) : [];
|
|
2671
2506
|
const childDef = resolveFieldRef(defVar.definition, manager);
|
|
2672
|
-
const parentDef = resolveFieldRef(
|
|
2673
|
-
parentVar.definition,
|
|
2674
|
-
resolveManager
|
|
2675
|
-
);
|
|
2507
|
+
const parentDef = parentVarManager ? resolveFieldRef(parentVar.definition, parentVarManager) : utils.isObject(parentVar.definition) && ((_a = parentVar.definition) == null ? void 0 : _a._id) ? parentVar.definition : null;
|
|
2676
2508
|
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)) {
|
|
2677
2509
|
const mapping = buildFieldIdMapping(
|
|
2678
2510
|
childDef,
|
|
2679
2511
|
parentDef,
|
|
2680
2512
|
manager,
|
|
2681
|
-
resolveManager
|
|
2513
|
+
parentVarManager ?? resolveManager
|
|
2682
2514
|
);
|
|
2683
2515
|
expanded[defVar._id] = remapArrayItems(concreteItems, mapping);
|
|
2684
2516
|
} else {
|
|
@@ -2704,11 +2536,13 @@ const useExtractProps = (props, manager, parentManager, definitions) => {
|
|
|
2704
2536
|
}, [
|
|
2705
2537
|
leafLayers,
|
|
2706
2538
|
arrayItemLayers,
|
|
2539
|
+
arrayResolvedResults,
|
|
2707
2540
|
props,
|
|
2708
2541
|
manager,
|
|
2709
2542
|
parentManager,
|
|
2710
|
-
|
|
2711
|
-
|
|
2543
|
+
areaManager,
|
|
2544
|
+
globalManager,
|
|
2545
|
+
definitions
|
|
2712
2546
|
]);
|
|
2713
2547
|
};
|
|
2714
2548
|
const CollectionItem = ({
|
|
@@ -2895,8 +2729,10 @@ const useFragmentManager = (fragmentId, inputGlobalManager) => {
|
|
|
2895
2729
|
} = useGlobalManager(inputGlobalManager);
|
|
2896
2730
|
react$1.useGraph(globalManager, (_a = globalManager == null ? void 0 : globalManager.$fragments) == null ? void 0 : _a.key, {
|
|
2897
2731
|
selector: (state) => {
|
|
2898
|
-
|
|
2899
|
-
|
|
2732
|
+
return {
|
|
2733
|
+
...state,
|
|
2734
|
+
managers: fragmentId ? utils.pick(state.managers, fragmentId) : state.managers
|
|
2735
|
+
};
|
|
2900
2736
|
}
|
|
2901
2737
|
});
|
|
2902
2738
|
const manager = getFragmentManager(fragmentId);
|
|
@@ -2914,7 +2750,7 @@ const useFragmentManager = (fragmentId, inputGlobalManager) => {
|
|
|
2914
2750
|
};
|
|
2915
2751
|
};
|
|
2916
2752
|
const useFragmentChildren = (fragmentId) => {
|
|
2917
|
-
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext
|
|
2753
|
+
const { layerKey: instanceLayerKey } = react.useContext(InstanceContext);
|
|
2918
2754
|
const { manager, fragmentLayerKey } = useFragmentManager(fragmentId);
|
|
2919
2755
|
const children = useLayerChildren(fragmentLayerKey, manager);
|
|
2920
2756
|
const [resizeChildren, setResizeChildren] = react.useState(null);
|
|
@@ -2957,7 +2793,7 @@ const useFragmentCssChunks = (fragmentId) => {
|
|
|
2957
2793
|
};
|
|
2958
2794
|
const useFragment = (fragmentId, globalManager) => {
|
|
2959
2795
|
var _a, _b;
|
|
2960
|
-
const instanceContext = react.useContext(InstanceContext
|
|
2796
|
+
const instanceContext = react.useContext(InstanceContext);
|
|
2961
2797
|
const fragmentContext = useFragmentManager(fragmentId);
|
|
2962
2798
|
const { setRef, children, isResize, primary } = useFragmentChildren(fragmentId);
|
|
2963
2799
|
const chunkLinks = useFragmentCssChunks(fragmentId);
|
|
@@ -3056,7 +2892,64 @@ const Fragment = (props) => {
|
|
|
3056
2892
|
}
|
|
3057
2893
|
return Base;
|
|
3058
2894
|
};
|
|
3059
|
-
const
|
|
2895
|
+
const resolveFromManagers = (key, ...managers) => {
|
|
2896
|
+
for (const mgr of managers) {
|
|
2897
|
+
if (!mgr) continue;
|
|
2898
|
+
const layer = mgr.resolve(key, { deep: true });
|
|
2899
|
+
if (layer == null ? void 0 : layer.type) return { layer, manager: mgr };
|
|
2900
|
+
}
|
|
2901
|
+
return { layer: null, manager: null };
|
|
2902
|
+
};
|
|
2903
|
+
const collectAllVariableKeys = (extractProps, fragmentManager, globalManager, areaManager) => {
|
|
2904
|
+
const keys = [];
|
|
2905
|
+
const collectFromObject = (obj) => {
|
|
2906
|
+
for (const value of Object.values(obj)) {
|
|
2907
|
+
if (definition.isVariableLink(value)) {
|
|
2908
|
+
keys.push(value);
|
|
2909
|
+
} else if (utils.isObject(value)) {
|
|
2910
|
+
collectFromObject(value);
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
};
|
|
2914
|
+
const collectObjectFields = (objectVar, manager) => {
|
|
2915
|
+
const fields = utils.cleanGraph(objectVar.fields);
|
|
2916
|
+
for (const fieldRef of Object.values(fields)) {
|
|
2917
|
+
let fieldKey;
|
|
2918
|
+
let fieldVar;
|
|
2919
|
+
if (definition.isVariableLink(fieldRef)) {
|
|
2920
|
+
fieldKey = fieldRef;
|
|
2921
|
+
fieldVar = manager == null ? void 0 : manager.resolve(fieldKey);
|
|
2922
|
+
} else if (utils.isObject(fieldRef) && (fieldRef == null ? void 0 : fieldRef._id)) {
|
|
2923
|
+
fieldKey = core.keyOfEntity(fieldRef);
|
|
2924
|
+
fieldVar = fieldRef;
|
|
2925
|
+
}
|
|
2926
|
+
if (!fieldVar || !fieldKey) continue;
|
|
2927
|
+
if (fieldVar.type === definition.definition.variableType.Object && fieldVar.fields) {
|
|
2928
|
+
collectObjectFields(fieldVar, manager);
|
|
2929
|
+
} else {
|
|
2930
|
+
keys.push(fieldKey);
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
};
|
|
2934
|
+
for (const value of Object.values(extractProps)) {
|
|
2935
|
+
if (definition.isVariableLink(value)) {
|
|
2936
|
+
keys.push(value);
|
|
2937
|
+
const { layer: varLayer, manager: varManager } = resolveFromManagers(
|
|
2938
|
+
value,
|
|
2939
|
+
fragmentManager,
|
|
2940
|
+
globalManager,
|
|
2941
|
+
areaManager
|
|
2942
|
+
);
|
|
2943
|
+
if ((varLayer == null ? void 0 : varLayer.type) === definition.definition.variableType.Object && (varLayer == null ? void 0 : varLayer.fields)) {
|
|
2944
|
+
collectObjectFields(varLayer, varManager);
|
|
2945
|
+
}
|
|
2946
|
+
} else if (utils.isObject(value)) {
|
|
2947
|
+
collectFromObject(value);
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
return keys;
|
|
2951
|
+
};
|
|
2952
|
+
const resolveObjectToConcreteValueFromMap = (objectVar, manager, resolvedByKey) => {
|
|
3060
2953
|
const fields = utils.cleanGraph(objectVar.fields);
|
|
3061
2954
|
const result = {};
|
|
3062
2955
|
for (const [fieldName, fieldRef] of Object.entries(fields)) {
|
|
@@ -3071,13 +2964,13 @@ const resolveObjectToConcreteValue = (objectVar, manager, readVariable) => {
|
|
|
3071
2964
|
}
|
|
3072
2965
|
if (!fieldVar || !fieldKey) continue;
|
|
3073
2966
|
if (fieldVar.type === definition.definition.variableType.Object && fieldVar.fields) {
|
|
3074
|
-
result[fieldName] =
|
|
2967
|
+
result[fieldName] = resolveObjectToConcreteValueFromMap(
|
|
3075
2968
|
fieldVar,
|
|
3076
2969
|
manager,
|
|
3077
|
-
|
|
2970
|
+
resolvedByKey
|
|
3078
2971
|
);
|
|
3079
2972
|
} else {
|
|
3080
|
-
const
|
|
2973
|
+
const value = resolvedByKey[fieldKey];
|
|
3081
2974
|
if (value != null) {
|
|
3082
2975
|
result[fieldName] = value;
|
|
3083
2976
|
}
|
|
@@ -3085,12 +2978,30 @@ const resolveObjectToConcreteValue = (objectVar, manager, readVariable) => {
|
|
|
3085
2978
|
}
|
|
3086
2979
|
return result;
|
|
3087
2980
|
};
|
|
2981
|
+
const deepResolveObjectValuesFromMap = (obj, resolvedByKey) => {
|
|
2982
|
+
const result = {};
|
|
2983
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2984
|
+
if (definition.isVariableLink(value)) {
|
|
2985
|
+
result[key] = resolvedByKey[value];
|
|
2986
|
+
} else if (utils.isObject(value)) {
|
|
2987
|
+
result[key] = deepResolveObjectValuesFromMap(
|
|
2988
|
+
value,
|
|
2989
|
+
resolvedByKey
|
|
2990
|
+
);
|
|
2991
|
+
} else {
|
|
2992
|
+
result[key] = value;
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
return result;
|
|
2996
|
+
};
|
|
3088
2997
|
const useInstanceProps = (instanceProps) => {
|
|
3089
2998
|
const isTopInstance = !(instanceProps == null ? void 0 : instanceProps.layerKey);
|
|
3090
2999
|
const { manager: loadedManager } = useFragmentManager(
|
|
3091
3000
|
isTopInstance ? instanceProps == null ? void 0 : instanceProps.fragmentId : null
|
|
3092
3001
|
);
|
|
3093
3002
|
const { manager: fragmentContextManager } = react.useContext(FragmentContext);
|
|
3003
|
+
const globalManager = react.useContext(GlobalManagerContext);
|
|
3004
|
+
const areaManager = react.useContext(AreaManagerContext);
|
|
3094
3005
|
const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
|
|
3095
3006
|
const [instanceLayer] = react$1.useGraph(fragmentManager, instanceProps.layerKey);
|
|
3096
3007
|
const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
|
|
@@ -3103,30 +3014,52 @@ const useInstanceProps = (instanceProps) => {
|
|
|
3103
3014
|
};
|
|
3104
3015
|
}
|
|
3105
3016
|
const extractProps = utils.cleanGraph(inputProps);
|
|
3106
|
-
const
|
|
3017
|
+
const variableKeys = !isTopInstance ? collectAllVariableKeys(
|
|
3018
|
+
extractProps,
|
|
3019
|
+
fragmentManager,
|
|
3020
|
+
globalManager,
|
|
3021
|
+
areaManager
|
|
3022
|
+
) : [];
|
|
3023
|
+
const resolvedVariableResults = useReadVariables(variableKeys);
|
|
3024
|
+
const resolvedByKey = {};
|
|
3025
|
+
variableKeys.forEach((key, i) => {
|
|
3026
|
+
var _a;
|
|
3027
|
+
resolvedByKey[key] = ((_a = resolvedVariableResults[i]) == null ? void 0 : _a.value) ?? null;
|
|
3028
|
+
});
|
|
3107
3029
|
let resolvedProps = extractProps;
|
|
3108
3030
|
if (!isTopInstance) {
|
|
3109
3031
|
resolvedProps = {};
|
|
3110
3032
|
for (const [key, value] of Object.entries(extractProps)) {
|
|
3111
3033
|
if (!definition.isVariableLink(value)) {
|
|
3112
|
-
|
|
3034
|
+
if (utils.isObject(value)) {
|
|
3035
|
+
resolvedProps[key] = deepResolveObjectValuesFromMap(
|
|
3036
|
+
value,
|
|
3037
|
+
resolvedByKey
|
|
3038
|
+
);
|
|
3039
|
+
} else {
|
|
3040
|
+
resolvedProps[key] = value;
|
|
3041
|
+
}
|
|
3113
3042
|
continue;
|
|
3114
3043
|
}
|
|
3115
|
-
const
|
|
3044
|
+
const { layer: varLayer, manager: varManager } = resolveFromManagers(
|
|
3045
|
+
value,
|
|
3046
|
+
fragmentManager,
|
|
3047
|
+
globalManager,
|
|
3048
|
+
areaManager
|
|
3049
|
+
);
|
|
3116
3050
|
if ((varLayer == null ? void 0 : varLayer.type) === definition.definition.variableType.Array) {
|
|
3117
3051
|
resolvedProps[key] = value;
|
|
3118
3052
|
continue;
|
|
3119
3053
|
}
|
|
3120
3054
|
if ((varLayer == null ? void 0 : varLayer.type) === definition.definition.variableType.Object && (varLayer == null ? void 0 : varLayer.fields)) {
|
|
3121
|
-
resolvedProps[key] =
|
|
3055
|
+
resolvedProps[key] = resolveObjectToConcreteValueFromMap(
|
|
3122
3056
|
varLayer,
|
|
3123
|
-
|
|
3124
|
-
|
|
3057
|
+
varManager,
|
|
3058
|
+
resolvedByKey
|
|
3125
3059
|
);
|
|
3126
3060
|
continue;
|
|
3127
3061
|
}
|
|
3128
|
-
|
|
3129
|
-
resolvedProps[key] = resolved;
|
|
3062
|
+
resolvedProps[key] = resolvedByKey[value] ?? value;
|
|
3130
3063
|
}
|
|
3131
3064
|
}
|
|
3132
3065
|
react.useEffect(() => {
|
|
@@ -3187,6 +3120,45 @@ const useSuspenseLoadArea = (globalManager, areaCode, skip) => {
|
|
|
3187
3120
|
if (valueOrPromise == null) return null;
|
|
3188
3121
|
return createSuspenseResource(`area:${areaCode}`, valueOrPromise, cache).read();
|
|
3189
3122
|
};
|
|
3123
|
+
const collectPropertyCssVars = (manager, result) => {
|
|
3124
|
+
if (!(manager == null ? void 0 : manager.$properties)) return;
|
|
3125
|
+
const keys = manager.$properties.getPropertyKeys() ?? [];
|
|
3126
|
+
const processField = (fieldLayer) => {
|
|
3127
|
+
if (!(fieldLayer == null ? void 0 : fieldLayer._id)) return;
|
|
3128
|
+
if (fieldLayer.type === definition.definition.variableType.Object && fieldLayer.fields) {
|
|
3129
|
+
for (const [key, ref] of Object.entries(fieldLayer.fields)) {
|
|
3130
|
+
if (key === "_type" || key === "_id") continue;
|
|
3131
|
+
const child = utils.isObject(ref) ? ref : manager.resolve(ref);
|
|
3132
|
+
if (child) processField(child);
|
|
3133
|
+
}
|
|
3134
|
+
return;
|
|
3135
|
+
}
|
|
3136
|
+
if (fieldLayer.defaultValue != null) {
|
|
3137
|
+
result[`--${fieldLayer._id}`] = String(fieldLayer.defaultValue);
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
for (const key of keys) {
|
|
3141
|
+
const layer = manager.resolve(key, { deep: true });
|
|
3142
|
+
if (layer) processField(layer);
|
|
3143
|
+
}
|
|
3144
|
+
};
|
|
3145
|
+
const useManagerCssProperties = () => {
|
|
3146
|
+
var _a, _b, _c, _d;
|
|
3147
|
+
const globalManager = react.useContext(GlobalManagerContext);
|
|
3148
|
+
const areaManager = react.useContext(AreaManagerContext);
|
|
3149
|
+
react$1.useGraph(globalManager, (_a = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _a.key);
|
|
3150
|
+
react$1.useGraph(areaManager, (_b = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _b.key);
|
|
3151
|
+
const globalKeys = ((_c = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _c.getPropertyKeys()) ?? [];
|
|
3152
|
+
const areaKeys = ((_d = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _d.getPropertyKeys()) ?? [];
|
|
3153
|
+
react$1.useGraphStack(globalKeys.length ? globalManager : null, globalKeys);
|
|
3154
|
+
react$1.useGraphStack(areaKeys.length ? areaManager : null, areaKeys);
|
|
3155
|
+
return react.useMemo(() => {
|
|
3156
|
+
const vars = {};
|
|
3157
|
+
collectPropertyCssVars(globalManager, vars);
|
|
3158
|
+
collectPropertyCssVars(areaManager, vars);
|
|
3159
|
+
return vars;
|
|
3160
|
+
}, [globalManager, areaManager, globalKeys.length, areaKeys.length]);
|
|
3161
|
+
};
|
|
3190
3162
|
const InstanceInitial = ({
|
|
3191
3163
|
Tag: inputTag,
|
|
3192
3164
|
style = {},
|
|
@@ -3218,71 +3190,43 @@ const InstanceInitial = ({
|
|
|
3218
3190
|
parentManager,
|
|
3219
3191
|
definitions
|
|
3220
3192
|
);
|
|
3221
|
-
const
|
|
3193
|
+
const propsCssVars = react.useMemo(
|
|
3222
3194
|
() => toCssCustomProperties(expandedProps),
|
|
3223
3195
|
[expandedProps]
|
|
3224
3196
|
);
|
|
3225
|
-
|
|
3226
|
-
const
|
|
3227
|
-
() => ({
|
|
3228
|
-
|
|
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
|
-
]
|
|
3197
|
+
const managerCssVars = useManagerCssProperties();
|
|
3198
|
+
const cssVars = react.useMemo(
|
|
3199
|
+
() => ({ ...managerCssVars, ...propsCssVars }),
|
|
3200
|
+
[managerCssVars, propsCssVars]
|
|
3244
3201
|
);
|
|
3202
|
+
useSuspenseLoadFragment(globalManager, fragmentId, !ssr);
|
|
3245
3203
|
const instanceContextValue = react.useMemo(
|
|
3246
3204
|
() => ({
|
|
3247
3205
|
layerKey: instanceProps.layerKey,
|
|
3248
3206
|
definitions,
|
|
3249
3207
|
innerManager,
|
|
3250
3208
|
parentManager,
|
|
3251
|
-
props: expandedProps
|
|
3209
|
+
props: expandedProps,
|
|
3210
|
+
onChangeProps
|
|
3252
3211
|
}),
|
|
3253
3212
|
[
|
|
3254
3213
|
instanceProps.layerKey,
|
|
3255
3214
|
definitions,
|
|
3256
3215
|
innerManager,
|
|
3257
3216
|
parentManager,
|
|
3258
|
-
expandedProps
|
|
3217
|
+
expandedProps,
|
|
3218
|
+
onChangeProps
|
|
3259
3219
|
]
|
|
3260
3220
|
);
|
|
3261
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3262
|
-
|
|
3221
|
+
return /* @__PURE__ */ jsxRuntime.jsx(InstanceContext.Provider, { value: instanceContextValue, children: parentManager ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3222
|
+
Tag,
|
|
3263
3223
|
{
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
className: classnames,
|
|
3271
|
-
"data-key": instanceProps.layerKey,
|
|
3272
|
-
style: { ...style, ...cssVars },
|
|
3273
|
-
...link.linkProps,
|
|
3274
|
-
...events,
|
|
3275
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3276
|
-
Fragment,
|
|
3277
|
-
{
|
|
3278
|
-
fragmentId,
|
|
3279
|
-
globalManager,
|
|
3280
|
-
FrameElement,
|
|
3281
|
-
pauseInteractions
|
|
3282
|
-
}
|
|
3283
|
-
)
|
|
3284
|
-
}
|
|
3285
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3224
|
+
className: classnames,
|
|
3225
|
+
"data-key": instanceProps.layerKey,
|
|
3226
|
+
style: { ...style, ...cssVars },
|
|
3227
|
+
...link.linkProps,
|
|
3228
|
+
...events,
|
|
3229
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3286
3230
|
Fragment,
|
|
3287
3231
|
{
|
|
3288
3232
|
fragmentId,
|
|
@@ -3290,18 +3234,26 @@ const InstanceInitial = ({
|
|
|
3290
3234
|
FrameElement,
|
|
3291
3235
|
pauseInteractions
|
|
3292
3236
|
}
|
|
3293
|
-
)
|
|
3237
|
+
)
|
|
3294
3238
|
}
|
|
3295
|
-
)
|
|
3239
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3240
|
+
Fragment,
|
|
3241
|
+
{
|
|
3242
|
+
fragmentId,
|
|
3243
|
+
globalManager,
|
|
3244
|
+
FrameElement,
|
|
3245
|
+
pauseInteractions
|
|
3246
|
+
}
|
|
3247
|
+
) }) });
|
|
3296
3248
|
};
|
|
3297
3249
|
const Instance = (props) => {
|
|
3298
|
-
return "globalManager" in props ? /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, {
|
|
3250
|
+
return "globalManager" in props ? /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { children: /* @__PURE__ */ jsxRuntime.jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3299
3251
|
RenderTargetProvider,
|
|
3300
3252
|
{
|
|
3301
3253
|
value: props.renderTarget ?? definition.definition.renderTarget.document,
|
|
3302
3254
|
children: /* @__PURE__ */ jsxRuntime.jsx(InstanceInitial, { ...props })
|
|
3303
3255
|
}
|
|
3304
|
-
) }) }) : /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, {
|
|
3256
|
+
) }) }) : /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3305
3257
|
RenderTargetProvider,
|
|
3306
3258
|
{
|
|
3307
3259
|
value: props.renderTarget ?? definition.definition.renderTarget.document,
|
|
@@ -3453,16 +3405,16 @@ const AreaInitial = (areaProps) => {
|
|
|
3453
3405
|
() => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(areaProps == null ? void 0 : areaProps.props) ?? {} }),
|
|
3454
3406
|
[areaData, areaProps]
|
|
3455
3407
|
);
|
|
3456
|
-
if (!areaData) return null;
|
|
3457
3408
|
const areaManager = react.useMemo(
|
|
3458
3409
|
() => clientCore.createAreaManager({
|
|
3459
|
-
areaId: areaData.areaId,
|
|
3460
|
-
campaignId: areaData.campaignId,
|
|
3461
|
-
variantId: areaData.variantId,
|
|
3462
|
-
areaProperties: areaData.areaProperties
|
|
3410
|
+
areaId: areaData == null ? void 0 : areaData.areaId,
|
|
3411
|
+
campaignId: areaData == null ? void 0 : areaData.campaignId,
|
|
3412
|
+
variantId: areaData == null ? void 0 : areaData.variantId,
|
|
3413
|
+
areaProperties: areaData == null ? void 0 : areaData.areaProperties
|
|
3463
3414
|
}),
|
|
3464
|
-
[areaData.areaId]
|
|
3415
|
+
[areaData == null ? void 0 : areaData.areaId]
|
|
3465
3416
|
);
|
|
3417
|
+
if (!areaData) return null;
|
|
3466
3418
|
return /* @__PURE__ */ jsxRuntime.jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3467
3419
|
Scope,
|
|
3468
3420
|
{
|
|
@@ -3512,7 +3464,7 @@ exports.Frame = Frame;
|
|
|
3512
3464
|
exports.GlobalManagerContext = GlobalManagerContext;
|
|
3513
3465
|
exports.GlobalManagerProvider = GlobalManagerProvider;
|
|
3514
3466
|
exports.Instance = Instance;
|
|
3515
|
-
exports.InstanceContext = InstanceContext
|
|
3467
|
+
exports.InstanceContext = InstanceContext;
|
|
3516
3468
|
exports.RenderTargetContext = RenderTargetContext;
|
|
3517
3469
|
exports.RenderTargetProvider = RenderTargetProvider;
|
|
3518
3470
|
exports.Scope = Scope;
|