@fragmentsx/render-react 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/layer/index.d.ts +0 -1
- package/dist/hooks/layer/index.d.ts.map +1 -1
- package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
- package/dist/hooks/layer/useLayersValue.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerBackground.d.ts.map +1 -1
- package/dist/hooks/layer-styles/useLayerStyles/useLayerBorder.d.ts.map +1 -1
- package/dist/hooks/suspense/index.d.ts +3 -0
- package/dist/hooks/suspense/index.d.ts.map +1 -0
- package/dist/hooks/suspense/useSuspenseLoadArea.d.ts +6 -0
- package/dist/hooks/suspense/useSuspenseLoadArea.d.ts.map +1 -0
- package/dist/hooks/suspense/useSuspenseLoadFragment.d.ts +3 -0
- package/dist/hooks/suspense/useSuspenseLoadFragment.d.ts.map +1 -0
- package/dist/hooks/utils/useExpandedObjectProps.d.ts +12 -0
- package/dist/hooks/utils/useExpandedObjectProps.d.ts.map +1 -0
- package/dist/index.cjs.js +286 -138
- package/dist/index.es.js +287 -139
- package/dist/nodes/Area/Area.d.ts +8 -0
- package/dist/nodes/Area/Area.d.ts.map +1 -1
- package/dist/nodes/Area/hooks/useArea.d.ts +7 -2
- package/dist/nodes/Area/hooks/useArea.d.ts.map +1 -1
- package/dist/nodes/Area/index.d.ts +1 -0
- package/dist/nodes/Area/index.d.ts.map +1 -1
- package/dist/nodes/Collection/Collection.d.ts.map +1 -1
- package/dist/nodes/CollectionItem/CollectionItem.d.ts.map +1 -1
- package/dist/nodes/CollectionItem/hooks/useCollection.d.ts.map +1 -1
- package/dist/nodes/Instance/Instance.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstance.d.ts +0 -1
- package/dist/nodes/Instance/hooks/useInstance.d.ts.map +1 -1
- package/dist/nodes/Instance/hooks/useInstanceProps.d.ts +0 -1
- package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
- package/dist/nodes/Instance/test/dual-instance.browser.test.d.ts +2 -0
- package/dist/nodes/Instance/test/dual-instance.browser.test.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/layer/duplicateLayer.d.ts.map +1 -1
- package/dist/utils/suspense/createSuspenseResource.d.ts +5 -0
- package/dist/utils/suspense/createSuspenseResource.d.ts.map +1 -0
- package/dist/utils/suspense/createSuspenseResource.test.d.ts +2 -0
- package/dist/utils/suspense/createSuspenseResource.test.d.ts.map +1 -0
- package/dist/utils/suspense/index.d.ts +4 -0
- package/dist/utils/suspense/index.d.ts.map +1 -0
- package/dist/utils/suspense/suspenseCache.d.ts +4 -0
- package/dist/utils/suspense/suspenseCache.d.ts.map +1 -0
- package/dist/utils/suspense/suspenseCache.test.d.ts +2 -0
- package/dist/utils/suspense/suspenseCache.test.d.ts.map +1 -0
- package/dist/utils/variables/expandObjectProps.d.ts +9 -0
- package/dist/utils/variables/expandObjectProps.d.ts.map +1 -0
- package/dist/utils/variables/expandObjectProps.test.d.ts +2 -0
- package/dist/utils/variables/expandObjectProps.test.d.ts.map +1 -0
- package/dist/utils/variables/index.d.ts +2 -1
- package/dist/utils/variables/index.d.ts.map +1 -1
- package/dist/utils/variables/toCssCustomProperties.d.ts +7 -0
- package/dist/utils/variables/toCssCustomProperties.d.ts.map +1 -0
- package/package.json +4 -3
- package/dist/hooks/layer/useExtractProps.d.ts +0 -9
- package/dist/hooks/layer/useExtractProps.d.ts.map +0 -1
- package/dist/hooks/layer/useLayerCssVariable.d.ts +0 -8
- package/dist/hooks/layer/useLayerCssVariable.d.ts.map +0 -1
- package/dist/utils/variables/getCssVariables.d.ts +0 -3
- package/dist/utils/variables/getCssVariables.d.ts.map +0 -1
package/dist/index.cjs.js
CHANGED
|
@@ -781,23 +781,21 @@ const calcLinearGradient = (angle, values) => {
|
|
|
781
781
|
}
|
|
782
782
|
return `linear-gradient(${angle}deg, ${parts.join(", ")})`;
|
|
783
783
|
};
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
var _a, _b;
|
|
790
|
-
return value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
|
|
784
|
+
const getOverriderByLayers = (layerKey, layers) => {
|
|
785
|
+
return layers.find((l) => {
|
|
786
|
+
var _a;
|
|
787
|
+
return (_a = l == null ? void 0 : l.overrides) == null ? void 0 : _a.includes(layerKey);
|
|
788
|
+
});
|
|
791
789
|
};
|
|
792
|
-
const
|
|
793
|
-
return Object.entries(
|
|
790
|
+
const toCssCustomProperties = (props) => {
|
|
791
|
+
return Object.entries(props).reduce(
|
|
794
792
|
(acc, [key, value]) => {
|
|
795
793
|
var _a, _b;
|
|
796
|
-
if (isVariableLink(value)) {
|
|
794
|
+
if (definition.isVariableLink(value)) {
|
|
797
795
|
const nestedVariableId = (_a = core.entityOfKey(value)) == null ? void 0 : _a._id;
|
|
798
796
|
value = `var(--${nestedVariableId})`;
|
|
799
797
|
}
|
|
800
|
-
if (
|
|
798
|
+
if (typeof value === "string" && ((_b = value.startsWith) == null ? void 0 : _b.call(value, "http"))) {
|
|
801
799
|
value = `url("${value}")`;
|
|
802
800
|
}
|
|
803
801
|
acc[`--${key}`] = value;
|
|
@@ -806,11 +804,101 @@ const getCssVariables = (props) => {
|
|
|
806
804
|
{}
|
|
807
805
|
);
|
|
808
806
|
};
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
807
|
+
const resolveFieldVar = (field, manager) => {
|
|
808
|
+
if (utils.isObject(field) && (field == null ? void 0 : field._id)) {
|
|
809
|
+
return field;
|
|
810
|
+
}
|
|
811
|
+
if (definition.isVariableLink(field) && manager) {
|
|
812
|
+
return manager.resolve(field);
|
|
813
|
+
}
|
|
814
|
+
return void 0;
|
|
815
|
+
};
|
|
816
|
+
const toVariableLink = (field) => {
|
|
817
|
+
if (definition.isVariableLink(field)) {
|
|
818
|
+
return field;
|
|
819
|
+
}
|
|
820
|
+
if (utils.isObject(field) && (field == null ? void 0 : field._type) && (field == null ? void 0 : field._id)) {
|
|
821
|
+
return core.keyOfEntity(field);
|
|
822
|
+
}
|
|
823
|
+
return void 0;
|
|
824
|
+
};
|
|
825
|
+
const expandConcreteValue = (objectVar, valueObj, childManager, result) => {
|
|
826
|
+
const fields = utils.cleanGraph(objectVar.fields);
|
|
827
|
+
for (const [fieldName, childField] of Object.entries(fields)) {
|
|
828
|
+
if (!(fieldName in valueObj)) continue;
|
|
829
|
+
const childFieldVar = resolveFieldVar(childField, childManager);
|
|
830
|
+
if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
|
|
831
|
+
const fieldValue = valueObj[fieldName];
|
|
832
|
+
if (childFieldVar.type === definition.definition.variableType.Object && childFieldVar.fields && utils.isObject(fieldValue)) {
|
|
833
|
+
expandConcreteValue(
|
|
834
|
+
childFieldVar,
|
|
835
|
+
fieldValue,
|
|
836
|
+
childManager,
|
|
837
|
+
result
|
|
838
|
+
);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
result[childFieldVar._id] = fieldValue;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const expandVariableValue = (childObjectVar, parentObjectVar, childManager, resolveManager, result) => {
|
|
845
|
+
const childFields = utils.cleanGraph(childObjectVar.fields);
|
|
846
|
+
const parentFields = utils.cleanGraph(parentObjectVar.fields);
|
|
847
|
+
for (const [fieldName, childField] of Object.entries(childFields)) {
|
|
848
|
+
const parentField = parentFields[fieldName];
|
|
849
|
+
if (!parentField) continue;
|
|
850
|
+
const childFieldVar = resolveFieldVar(childField, childManager);
|
|
851
|
+
if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
|
|
852
|
+
const parentFieldVar = resolveFieldVar(parentField, resolveManager);
|
|
853
|
+
if (childFieldVar.type === definition.definition.variableType.Object && childFieldVar.fields && (parentFieldVar == null ? void 0 : parentFieldVar.type) === definition.definition.variableType.Object && (parentFieldVar == null ? void 0 : parentFieldVar.fields)) {
|
|
854
|
+
expandVariableValue(
|
|
855
|
+
childFieldVar,
|
|
856
|
+
parentFieldVar,
|
|
857
|
+
childManager,
|
|
858
|
+
resolveManager,
|
|
859
|
+
result
|
|
860
|
+
);
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
const parentFieldLink = toVariableLink(parentField);
|
|
864
|
+
if (parentFieldLink) {
|
|
865
|
+
result[childFieldVar._id] = parentFieldLink;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
const expandObjectProps = (props, childManager, parentManager) => {
|
|
870
|
+
if (!childManager) return props;
|
|
871
|
+
const resolveManager = parentManager ?? childManager;
|
|
872
|
+
const result = {};
|
|
873
|
+
for (const [propKey, propValue] of Object.entries(props)) {
|
|
874
|
+
const childVarKey = `Variable:${propKey}`;
|
|
875
|
+
const childVar = childManager.resolve(childVarKey);
|
|
876
|
+
if ((childVar == null ? void 0 : childVar.type) === definition.definition.variableType.Object && (childVar == null ? void 0 : childVar.fields)) {
|
|
877
|
+
if (definition.isVariableLink(propValue)) {
|
|
878
|
+
const parentVar = resolveManager.resolve(propValue);
|
|
879
|
+
if ((parentVar == null ? void 0 : parentVar.type) === definition.definition.variableType.Object && (parentVar == null ? void 0 : parentVar.fields)) {
|
|
880
|
+
expandVariableValue(
|
|
881
|
+
childVar,
|
|
882
|
+
parentVar,
|
|
883
|
+
childManager,
|
|
884
|
+
resolveManager,
|
|
885
|
+
result
|
|
886
|
+
);
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
} else if (utils.isObject(propValue)) {
|
|
890
|
+
expandConcreteValue(
|
|
891
|
+
childVar,
|
|
892
|
+
propValue,
|
|
893
|
+
childManager,
|
|
894
|
+
result
|
|
895
|
+
);
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
result[propKey] = propValue;
|
|
900
|
+
}
|
|
901
|
+
return result;
|
|
814
902
|
};
|
|
815
903
|
const declareFragmentProperty = (manager, property, fragmentLink = manager.$fragment.root) => {
|
|
816
904
|
const propertyLayer = createLayer(property);
|
|
@@ -879,6 +967,49 @@ const loadFragmentManager = async (globalManager, fragmentId) => {
|
|
|
879
967
|
}
|
|
880
968
|
return null;
|
|
881
969
|
};
|
|
970
|
+
const createSuspenseResource = (key, valueOrPromise, cache) => {
|
|
971
|
+
if (cache.has(key)) return cache.get(key);
|
|
972
|
+
if (!(valueOrPromise instanceof Promise)) {
|
|
973
|
+
const resource2 = {
|
|
974
|
+
read() {
|
|
975
|
+
return valueOrPromise;
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
cache.set(key, resource2);
|
|
979
|
+
return resource2;
|
|
980
|
+
}
|
|
981
|
+
let status = "pending";
|
|
982
|
+
let result;
|
|
983
|
+
let error;
|
|
984
|
+
const suspender = valueOrPromise.then(
|
|
985
|
+
(r) => {
|
|
986
|
+
status = "success";
|
|
987
|
+
result = r;
|
|
988
|
+
},
|
|
989
|
+
(e) => {
|
|
990
|
+
status = "error";
|
|
991
|
+
error = e;
|
|
992
|
+
}
|
|
993
|
+
);
|
|
994
|
+
const resource = {
|
|
995
|
+
read() {
|
|
996
|
+
if (status === "pending") throw suspender;
|
|
997
|
+
if (status === "error") throw error;
|
|
998
|
+
return result;
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
cache.set(key, resource);
|
|
1002
|
+
return resource;
|
|
1003
|
+
};
|
|
1004
|
+
const globalCache = /* @__PURE__ */ new WeakMap();
|
|
1005
|
+
const getSuspenseCache = (manager) => {
|
|
1006
|
+
let cache = globalCache.get(manager);
|
|
1007
|
+
if (!cache) {
|
|
1008
|
+
cache = /* @__PURE__ */ new Map();
|
|
1009
|
+
globalCache.set(manager, cache);
|
|
1010
|
+
}
|
|
1011
|
+
return cache;
|
|
1012
|
+
};
|
|
882
1013
|
const duplicateLayer = (manager, layer) => {
|
|
883
1014
|
var _a;
|
|
884
1015
|
const layerGraph = manager.resolve(layer, { deep: true });
|
|
@@ -886,6 +1017,9 @@ const duplicateLayer = (manager, layer) => {
|
|
|
886
1017
|
const linkedMap = {};
|
|
887
1018
|
const nextLayer = nodeWalker(layerGraph, (key, value, history) => {
|
|
888
1019
|
const nextId = utils.generateId();
|
|
1020
|
+
if ((value == null ? void 0 : value._type) === definition.definition.nodes.Instance && key === "props") {
|
|
1021
|
+
return utils.cleanGraph(value);
|
|
1022
|
+
}
|
|
889
1023
|
if (!!value && n(value)) {
|
|
890
1024
|
linkedMap[core.keyOfEntity(value)] = core.keyOfEntity({ ...value, _id: nextId });
|
|
891
1025
|
const linkedParent = linkedMap == null ? void 0 : linkedMap[utils.getKey(value.parent)];
|
|
@@ -952,6 +1086,14 @@ const wrapTextInParagraphWithAttributes = (text, attributes) => {
|
|
|
952
1086
|
).map(([key, value]) => `${utils.toKebabCase(key)}: ${value}`).join("; ");
|
|
953
1087
|
return `<p style="${style}">${text}</p>`;
|
|
954
1088
|
};
|
|
1089
|
+
const isVariableLink = (value) => {
|
|
1090
|
+
var _a;
|
|
1091
|
+
return isLink(value) && ((_a = value == null ? void 0 : value.split(":")) == null ? void 0 : _a.at(0)) === definition.definition.nodes.Variable;
|
|
1092
|
+
};
|
|
1093
|
+
const isLink = (value) => {
|
|
1094
|
+
var _a, _b;
|
|
1095
|
+
return value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
|
|
1096
|
+
};
|
|
955
1097
|
const layerFieldSetter = (manager, layerKey, fieldKey, currentValue) => (value, options) => {
|
|
956
1098
|
var _a;
|
|
957
1099
|
const { success, output } = definition.parseLayerField(
|
|
@@ -980,26 +1122,8 @@ const layerFieldSetter = (manager, layerKey, fieldKey, currentValue) => (value,
|
|
|
980
1122
|
);
|
|
981
1123
|
}
|
|
982
1124
|
};
|
|
983
|
-
const getLayerCssVariable = (manager, inputValue) => {
|
|
984
|
-
var _a;
|
|
985
|
-
const isVariable = definition.isVariableLink(inputValue);
|
|
986
|
-
const variableValue = manager.resolve(manager, inputValue);
|
|
987
|
-
const id = (_a = core.entityOfKey(inputValue)) == null ? void 0 : _a._id;
|
|
988
|
-
return {
|
|
989
|
-
value: isVariable ? `var(--${id}, ${variableValue == null ? void 0 : variableValue.defaultValue})` : null
|
|
990
|
-
};
|
|
991
|
-
};
|
|
992
|
-
const useLayerCssVariable = (inputValue) => {
|
|
993
|
-
var _a;
|
|
994
|
-
const { manager } = react.useContext(FragmentContext);
|
|
995
|
-
const isVariable = definition.isVariableLink(inputValue);
|
|
996
|
-
const { layer } = useNormalizeLayer(inputValue, isVariable ? manager : null);
|
|
997
|
-
const variableId = (layer == null ? void 0 : layer._id) ?? ((_a = core.entityOfKey(inputValue)) == null ? void 0 : _a._id);
|
|
998
|
-
return {
|
|
999
|
-
value: isVariable ? `var(--${variableId}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
|
|
1000
|
-
};
|
|
1001
|
-
};
|
|
1002
1125
|
const useLayerValue = (layerKey, fieldKey, options) => {
|
|
1126
|
+
var _a;
|
|
1003
1127
|
const { manager: fragmentManager } = react.useContext(FragmentContext);
|
|
1004
1128
|
const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
|
|
1005
1129
|
if (!resultManager) {
|
|
@@ -1029,8 +1153,8 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1029
1153
|
}, [updateLayerData]);
|
|
1030
1154
|
const restore = react.useCallback(
|
|
1031
1155
|
(fallbackValue) => {
|
|
1032
|
-
var
|
|
1033
|
-
const tempValue = ((_c = (_b = resultManager.resolve((
|
|
1156
|
+
var _a2, _b, _c;
|
|
1157
|
+
const tempValue = ((_c = (_b = resultManager.resolve((_a2 = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a2.temp)) == null ? void 0 : _b[key]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
|
|
1034
1158
|
updateLayerData({ [fieldKey]: tempValue });
|
|
1035
1159
|
return tempValue;
|
|
1036
1160
|
},
|
|
@@ -1042,15 +1166,16 @@ const useLayerValue = (layerKey, fieldKey, options) => {
|
|
|
1042
1166
|
},
|
|
1043
1167
|
[setter]
|
|
1044
1168
|
);
|
|
1045
|
-
const
|
|
1169
|
+
const isVariable = definition.isVariableLink(rawValue ?? layerValue);
|
|
1170
|
+
const variableId = isVariable ? (_a = core.entityOfKey(layerValue)) == null ? void 0 : _a._id : null;
|
|
1046
1171
|
return [
|
|
1047
1172
|
currentValue,
|
|
1048
1173
|
updateValue,
|
|
1049
1174
|
{
|
|
1050
1175
|
isOverride,
|
|
1051
1176
|
resetOverride,
|
|
1052
|
-
isVariable
|
|
1053
|
-
cssVariableValue:
|
|
1177
|
+
isVariable,
|
|
1178
|
+
cssVariableValue: isVariable ? `var(--${variableId}, ${transformCssValue(currentValue)})` : transformCssValue(currentValue),
|
|
1054
1179
|
rawValue,
|
|
1055
1180
|
restore,
|
|
1056
1181
|
...resultManager.entityOfKey(key)
|
|
@@ -1281,18 +1406,16 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
|
|
|
1281
1406
|
const updateValue = (value, options2) => {
|
|
1282
1407
|
setter(value, options2);
|
|
1283
1408
|
};
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1286
|
-
rawValue ?? layerValue
|
|
1287
|
-
)) == null ? void 0 : _b.value;
|
|
1409
|
+
const isVariable = definition.isVariableLink(rawValue ?? layerValue);
|
|
1410
|
+
const variableId = isVariable ? (_b = core.entityOfKey(layerValue)) == null ? void 0 : _b._id : null;
|
|
1288
1411
|
return [
|
|
1289
1412
|
currentValue,
|
|
1290
1413
|
updateValue,
|
|
1291
1414
|
{
|
|
1292
1415
|
isOverride,
|
|
1293
1416
|
resetOverride,
|
|
1294
|
-
isVariable
|
|
1295
|
-
cssVariableValue:
|
|
1417
|
+
isVariable,
|
|
1418
|
+
cssVariableValue: isVariable ? `var(--${variableId}, ${transformCssValue(currentValue)})` : transformCssValue(currentValue),
|
|
1296
1419
|
rawValue,
|
|
1297
1420
|
restore,
|
|
1298
1421
|
...resultManager.entityOfKey(normalizedLayer.layerKey)
|
|
@@ -1431,7 +1554,8 @@ const useLayerBackground = (layerKey) => {
|
|
|
1431
1554
|
cssImageFillOptions.cssVariableValue,
|
|
1432
1555
|
cssSolidFill,
|
|
1433
1556
|
cssImageSize,
|
|
1434
|
-
image
|
|
1557
|
+
image,
|
|
1558
|
+
linearGradient
|
|
1435
1559
|
]);
|
|
1436
1560
|
};
|
|
1437
1561
|
const useLayerDisplay = (layerKey) => {
|
|
@@ -1459,17 +1583,18 @@ const useLayerPaint = (paintLinkKey) => {
|
|
|
1459
1583
|
};
|
|
1460
1584
|
};
|
|
1461
1585
|
const useLayerBorder = (layerKey) => {
|
|
1586
|
+
var _a, _b;
|
|
1462
1587
|
const [borderLinkKey] = useLayerValue(layerKey, "border");
|
|
1463
1588
|
const [type] = useLayerValue(borderLinkKey, "type");
|
|
1464
1589
|
const [width] = useLayerValue(borderLinkKey, "width");
|
|
1465
1590
|
const [borderPaintLink] = useLayerValue(borderLinkKey, "paint");
|
|
1466
1591
|
const borderPaint = useLayerPaint(borderPaintLink);
|
|
1467
|
-
const borderLinearGradient = useLayerLinearGradient(
|
|
1592
|
+
const borderLinearGradient = (_a = useLayerLinearGradient(
|
|
1468
1593
|
borderPaint.linearGradientLink
|
|
1469
|
-
);
|
|
1594
|
+
)) == null ? void 0 : _a["background-image"];
|
|
1470
1595
|
const [paintLinkKey] = useLayerValue(layerKey, "paint");
|
|
1471
1596
|
const paint = useLayerPaint(paintLinkKey);
|
|
1472
|
-
const linearGradient = useLayerLinearGradient(paint.linearGradientLink);
|
|
1597
|
+
const linearGradient = (_b = useLayerLinearGradient(paint.linearGradientLink)) == null ? void 0 : _b["background-image"];
|
|
1473
1598
|
if (type === definition.definition.borderType.None) {
|
|
1474
1599
|
return {
|
|
1475
1600
|
border: null
|
|
@@ -1478,7 +1603,7 @@ const useLayerBorder = (layerKey) => {
|
|
|
1478
1603
|
if (borderPaint.type === definition.definition.paintMode.LinearGradient) {
|
|
1479
1604
|
let background = `linear-gradient(${paint.solid}, ${paint.solid}) padding-box, ${borderLinearGradient} border-box`;
|
|
1480
1605
|
if (paint.type === definition.definition.paintMode.LinearGradient) {
|
|
1481
|
-
background = `${linearGradient
|
|
1606
|
+
background = `${linearGradient} padding-box, ${borderLinearGradient} border-box`;
|
|
1482
1607
|
}
|
|
1483
1608
|
if (paint.type === definition.definition.paintMode.None) {
|
|
1484
1609
|
background = `linear-gradient(transparent, transparent) padding-box, ${borderLinearGradient} border-box`;
|
|
@@ -1950,40 +2075,52 @@ const useCollection = (layerKey, options) => {
|
|
|
1950
2075
|
...frame
|
|
1951
2076
|
};
|
|
1952
2077
|
};
|
|
1953
|
-
const
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2078
|
+
const collectLeafFieldKeys = (objectVar, manager, keys) => {
|
|
2079
|
+
if (!(objectVar == null ? void 0 : objectVar.fields)) return;
|
|
2080
|
+
const fields = utils.cleanGraph(objectVar.fields);
|
|
2081
|
+
for (const fieldValue of Object.values(fields)) {
|
|
2082
|
+
let fieldVar;
|
|
2083
|
+
let fieldKey;
|
|
2084
|
+
if (definition.isVariableLink(fieldValue)) {
|
|
2085
|
+
fieldKey = fieldValue;
|
|
2086
|
+
fieldVar = manager.resolve(fieldKey);
|
|
2087
|
+
} else if (utils.isObject(fieldValue) && (fieldValue == null ? void 0 : fieldValue._type) && (fieldValue == null ? void 0 : fieldValue._id)) {
|
|
2088
|
+
fieldKey = core.keyOfEntity(fieldValue);
|
|
2089
|
+
fieldVar = fieldValue;
|
|
2090
|
+
}
|
|
2091
|
+
if (!fieldVar || !fieldKey) continue;
|
|
2092
|
+
if (fieldVar.type === definition.definition.variableType.Object && fieldVar.fields) {
|
|
2093
|
+
collectLeafFieldKeys(fieldVar, manager, keys);
|
|
2094
|
+
} else {
|
|
2095
|
+
keys.push(fieldKey);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
};
|
|
2099
|
+
const useExpandedObjectProps = (props, manager, parentManager, definitions) => {
|
|
2100
|
+
const objectFieldKeys = react.useMemo(() => {
|
|
2101
|
+
if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
|
|
2102
|
+
const keys = [];
|
|
2103
|
+
for (const defKey of definitions) {
|
|
2104
|
+
const defVar = manager.resolve(defKey);
|
|
2105
|
+
if ((defVar == null ? void 0 : defVar.type) === definition.definition.variableType.Object && (defVar == null ? void 0 : defVar.fields)) {
|
|
2106
|
+
collectLeafFieldKeys(defVar, manager, keys);
|
|
1969
2107
|
}
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
() => definitionsData.reduce((acc, definition2) => {
|
|
1977
|
-
const defId = definition2._id;
|
|
1978
|
-
acc[defId] = (inputProps == null ? void 0 : inputProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
|
|
1979
|
-
return acc;
|
|
1980
|
-
}, {}),
|
|
1981
|
-
[inputProps]
|
|
2108
|
+
}
|
|
2109
|
+
return keys;
|
|
2110
|
+
}, [definitions, manager]);
|
|
2111
|
+
const fieldVarLayers = react$1.useGraphStack(
|
|
2112
|
+
objectFieldKeys.length ? manager : null,
|
|
2113
|
+
objectFieldKeys
|
|
1982
2114
|
);
|
|
1983
|
-
return
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2115
|
+
return react.useMemo(() => {
|
|
2116
|
+
const base = {};
|
|
2117
|
+
for (const layer of fieldVarLayers) {
|
|
2118
|
+
if ((layer == null ? void 0 : layer._id) && (layer == null ? void 0 : layer.defaultValue) != null) {
|
|
2119
|
+
base[layer._id] = layer.defaultValue;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
return { ...base, ...expandObjectProps(props, manager, parentManager) };
|
|
2123
|
+
}, [fieldVarLayers, props, manager, parentManager]);
|
|
1987
2124
|
};
|
|
1988
2125
|
const CollectionItem = ({
|
|
1989
2126
|
layer,
|
|
@@ -1994,20 +2131,24 @@ const CollectionItem = ({
|
|
|
1994
2131
|
...restProps
|
|
1995
2132
|
}) => {
|
|
1996
2133
|
var _a;
|
|
1997
|
-
|
|
2134
|
+
core.keyOfEntity(layer);
|
|
1998
2135
|
const definitionId = ((_a = core.entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
|
|
1999
2136
|
const value = layer.value ?? layer;
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2137
|
+
const inputProps = utils.isObject(value) ? {
|
|
2138
|
+
...value
|
|
2139
|
+
} : {
|
|
2140
|
+
[definitionId]: value
|
|
2141
|
+
};
|
|
2142
|
+
const props = utils.cleanGraph(inputProps);
|
|
2143
|
+
const definitions = react.useMemo(
|
|
2144
|
+
() => sourceDefinition ? [sourceDefinition] : [],
|
|
2145
|
+
[sourceDefinition]
|
|
2146
|
+
);
|
|
2147
|
+
const expandedProps = useExpandedObjectProps(props, manager, void 0, definitions);
|
|
2148
|
+
const cssVars = react.useMemo(
|
|
2149
|
+
() => toCssCustomProperties(expandedProps),
|
|
2150
|
+
[expandedProps]
|
|
2151
|
+
);
|
|
2011
2152
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2012
2153
|
Scope,
|
|
2013
2154
|
{
|
|
@@ -2017,7 +2158,7 @@ const CollectionItem = ({
|
|
|
2017
2158
|
type: definition.definition.scopeTypes.CollectionItemScope,
|
|
2018
2159
|
...restProps,
|
|
2019
2160
|
sourceDefinition,
|
|
2020
|
-
value:
|
|
2161
|
+
value: expandedProps,
|
|
2021
2162
|
manager
|
|
2022
2163
|
},
|
|
2023
2164
|
children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2025,7 +2166,7 @@ const CollectionItem = ({
|
|
|
2025
2166
|
{
|
|
2026
2167
|
style: {
|
|
2027
2168
|
display: "contents",
|
|
2028
|
-
...
|
|
2169
|
+
...cssVars
|
|
2029
2170
|
},
|
|
2030
2171
|
children: /* @__PURE__ */ jsxRuntime.jsx(FrameElement, { ...restProps, layerKey: child })
|
|
2031
2172
|
},
|
|
@@ -2348,8 +2489,6 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2348
2489
|
isTopInstance ? instanceProps == null ? void 0 : instanceProps.fragmentId : null
|
|
2349
2490
|
);
|
|
2350
2491
|
const { manager: fragmentContextManager } = react.useContext(FragmentContext);
|
|
2351
|
-
const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
|
|
2352
|
-
const { readVariable } = useReadVariable();
|
|
2353
2492
|
const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
|
|
2354
2493
|
const [instanceLayer] = react$1.useGraph(fragmentManager, instanceProps.layerKey);
|
|
2355
2494
|
const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
|
|
@@ -2361,11 +2500,7 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2361
2500
|
...localProps
|
|
2362
2501
|
};
|
|
2363
2502
|
}
|
|
2364
|
-
const extractProps =
|
|
2365
|
-
definitions,
|
|
2366
|
-
manager: fragmentManager,
|
|
2367
|
-
inputProps
|
|
2368
|
-
});
|
|
2503
|
+
const extractProps = utils.cleanGraph(inputProps);
|
|
2369
2504
|
react.useEffect(() => {
|
|
2370
2505
|
if (utils.isValue(instanceProps == null ? void 0 : instanceProps.props)) {
|
|
2371
2506
|
setLocalProps(instanceProps.props);
|
|
@@ -2373,7 +2508,6 @@ const useInstanceProps = (instanceProps) => {
|
|
|
2373
2508
|
}, [instanceProps == null ? void 0 : instanceProps.props]);
|
|
2374
2509
|
return {
|
|
2375
2510
|
props: extractProps,
|
|
2376
|
-
cssProps: getCssVariables(extractProps),
|
|
2377
2511
|
onChangeProps: (variableId, value) => {
|
|
2378
2512
|
var _a;
|
|
2379
2513
|
setLocalProps((prev) => ({ ...prev, [variableId]: value }));
|
|
@@ -2391,7 +2525,7 @@ const useInstance = (instanceProps) => {
|
|
|
2391
2525
|
);
|
|
2392
2526
|
const resultFragmentId = (instanceProps == null ? void 0 : instanceProps.fragmentId) ?? (instanceLayer == null ? void 0 : instanceLayer.fragment);
|
|
2393
2527
|
const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(resultFragmentId);
|
|
2394
|
-
const { props,
|
|
2528
|
+
const { props, onChangeProps } = useInstanceProps(instanceProps);
|
|
2395
2529
|
const classnames = useClassnames(
|
|
2396
2530
|
instanceProps.layerKey,
|
|
2397
2531
|
innerFragmentManager
|
|
@@ -2402,7 +2536,6 @@ const useInstance = (instanceProps) => {
|
|
|
2402
2536
|
events,
|
|
2403
2537
|
definitions,
|
|
2404
2538
|
props,
|
|
2405
|
-
cssProps,
|
|
2406
2539
|
parentManager,
|
|
2407
2540
|
innerManager: innerFragmentManager,
|
|
2408
2541
|
fragmentId: resultFragmentId,
|
|
@@ -2410,6 +2543,22 @@ const useInstance = (instanceProps) => {
|
|
|
2410
2543
|
onChangeProps
|
|
2411
2544
|
};
|
|
2412
2545
|
};
|
|
2546
|
+
const useSuspenseLoadFragment = (globalManager, fragmentId, skip) => {
|
|
2547
|
+
var _a, _b;
|
|
2548
|
+
if (skip || !globalManager || !fragmentId) return;
|
|
2549
|
+
const cache = getSuspenseCache(globalManager);
|
|
2550
|
+
const valueOrPromise = (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadFragment) == null ? void 0 : _b.call(_a, fragmentId);
|
|
2551
|
+
if (valueOrPromise == null) return;
|
|
2552
|
+
createSuspenseResource(`fragment:${fragmentId}`, valueOrPromise, cache).read();
|
|
2553
|
+
};
|
|
2554
|
+
const useSuspenseLoadArea = (globalManager, areaCode, skip) => {
|
|
2555
|
+
var _a, _b;
|
|
2556
|
+
if (skip || !globalManager || !areaCode) return null;
|
|
2557
|
+
const cache = getSuspenseCache(globalManager);
|
|
2558
|
+
const valueOrPromise = (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadArea) == null ? void 0 : _b.call(_a, areaCode);
|
|
2559
|
+
if (valueOrPromise == null) return null;
|
|
2560
|
+
return createSuspenseResource(`area:${areaCode}`, valueOrPromise, cache).read();
|
|
2561
|
+
};
|
|
2413
2562
|
const InstanceInitial = ({
|
|
2414
2563
|
Tag: inputTag,
|
|
2415
2564
|
style = {},
|
|
@@ -2417,13 +2566,12 @@ const InstanceInitial = ({
|
|
|
2417
2566
|
FrameElement,
|
|
2418
2567
|
...instanceProps
|
|
2419
2568
|
}) => {
|
|
2420
|
-
var _a
|
|
2569
|
+
var _a;
|
|
2421
2570
|
const ssr = ((_a = instanceProps == null ? void 0 : instanceProps.options) == null ? void 0 : _a.ssr) ?? true;
|
|
2422
2571
|
const link = useLayerLink(instanceProps.layerKey);
|
|
2423
2572
|
const Tag = (link == null ? void 0 : link.isLink) ? inputTag ?? "a" : inputTag ?? "div";
|
|
2424
2573
|
const {
|
|
2425
2574
|
fragmentId,
|
|
2426
|
-
cssProps,
|
|
2427
2575
|
parentManager,
|
|
2428
2576
|
events,
|
|
2429
2577
|
props,
|
|
@@ -2436,9 +2584,17 @@ const InstanceInitial = ({
|
|
|
2436
2584
|
...instanceProps,
|
|
2437
2585
|
pauseInteractions
|
|
2438
2586
|
});
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2587
|
+
const expandedProps = useExpandedObjectProps(
|
|
2588
|
+
props,
|
|
2589
|
+
innerManager,
|
|
2590
|
+
parentManager,
|
|
2591
|
+
definitions
|
|
2592
|
+
);
|
|
2593
|
+
const cssVars = react.useMemo(
|
|
2594
|
+
() => toCssCustomProperties(expandedProps),
|
|
2595
|
+
[expandedProps]
|
|
2596
|
+
);
|
|
2597
|
+
useSuspenseLoadFragment(globalManager, fragmentId, !ssr);
|
|
2442
2598
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2443
2599
|
Scope,
|
|
2444
2600
|
{
|
|
@@ -2446,7 +2602,7 @@ const InstanceInitial = ({
|
|
|
2446
2602
|
layerKey: instanceProps.layerKey,
|
|
2447
2603
|
value: {
|
|
2448
2604
|
type: definition.definition.scopeTypes.InstanceScope,
|
|
2449
|
-
props,
|
|
2605
|
+
props: expandedProps,
|
|
2450
2606
|
definitions,
|
|
2451
2607
|
fragmentId,
|
|
2452
2608
|
documentManager: innerManager,
|
|
@@ -2461,14 +2617,14 @@ const InstanceInitial = ({
|
|
|
2461
2617
|
definitions,
|
|
2462
2618
|
innerManager,
|
|
2463
2619
|
parentManager,
|
|
2464
|
-
props
|
|
2620
|
+
props: expandedProps
|
|
2465
2621
|
},
|
|
2466
2622
|
children: parentManager ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2467
2623
|
Tag,
|
|
2468
2624
|
{
|
|
2469
2625
|
className: classnames,
|
|
2470
2626
|
"data-key": instanceProps.layerKey,
|
|
2471
|
-
style: { ...style, ...
|
|
2627
|
+
style: { ...style, ...cssVars },
|
|
2472
2628
|
...link.linkProps,
|
|
2473
2629
|
...events,
|
|
2474
2630
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2481,7 +2637,7 @@ const InstanceInitial = ({
|
|
|
2481
2637
|
}
|
|
2482
2638
|
)
|
|
2483
2639
|
}
|
|
2484
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(Tag, { style: { ...style, ...
|
|
2640
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2485
2641
|
Fragment,
|
|
2486
2642
|
{
|
|
2487
2643
|
fragmentId,
|
|
@@ -2511,26 +2667,24 @@ const Instance = (props) => {
|
|
|
2511
2667
|
) });
|
|
2512
2668
|
};
|
|
2513
2669
|
const useArea = (options) => {
|
|
2514
|
-
|
|
2670
|
+
var _a;
|
|
2671
|
+
const { manager: resultGlobalManager } = useGlobalManager(
|
|
2515
2672
|
options == null ? void 0 : options.globalManager
|
|
2516
2673
|
);
|
|
2517
|
-
const
|
|
2674
|
+
const ssr = ((_a = options == null ? void 0 : options.options) == null ? void 0 : _a.ssr) ?? true;
|
|
2675
|
+
const areaData = useSuspenseLoadArea(
|
|
2676
|
+
resultGlobalManager,
|
|
2677
|
+
options.areaCode,
|
|
2678
|
+
!(isBrowser || ssr)
|
|
2679
|
+
);
|
|
2518
2680
|
const { manager: fragmentManager } = useFragmentManager(
|
|
2519
|
-
areaData.fragmentId,
|
|
2681
|
+
areaData == null ? void 0 : areaData.fragmentId,
|
|
2520
2682
|
resultGlobalManager
|
|
2521
2683
|
);
|
|
2522
2684
|
const resultProps = react.useMemo(
|
|
2523
|
-
() => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(options == null ? void 0 : options.props) ??
|
|
2685
|
+
() => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(options == null ? void 0 : options.props) ?? {} }),
|
|
2524
2686
|
[areaData, options]
|
|
2525
2687
|
);
|
|
2526
|
-
react.useEffect(() => {
|
|
2527
|
-
(async () => {
|
|
2528
|
-
const response = await queryArea(options.areaCode);
|
|
2529
|
-
if (response) {
|
|
2530
|
-
setAreaData(response);
|
|
2531
|
-
}
|
|
2532
|
-
})();
|
|
2533
|
-
}, []);
|
|
2534
2688
|
return {
|
|
2535
2689
|
...areaData,
|
|
2536
2690
|
fragmentManager,
|
|
@@ -2539,14 +2693,6 @@ const useArea = (options) => {
|
|
|
2539
2693
|
};
|
|
2540
2694
|
};
|
|
2541
2695
|
const AreaInitial = (areaProps) => {
|
|
2542
|
-
var _a, _b, _c;
|
|
2543
|
-
const { manager: globalManager } = useGlobalManager(areaProps == null ? void 0 : areaProps.globalManager);
|
|
2544
|
-
const ssr = ((_a = areaProps == null ? void 0 : areaProps.options) == null ? void 0 : _a.ssr) ?? true;
|
|
2545
|
-
if (isBrowser || ssr) {
|
|
2546
|
-
(_c = (_b = globalManager == null ? void 0 : globalManager.$load) == null ? void 0 : _b.loadArea) == null ? void 0 : _c.call(_b, areaProps.areaCode, {
|
|
2547
|
-
suspense: true
|
|
2548
|
-
});
|
|
2549
|
-
}
|
|
2550
2696
|
const areaData = useArea(areaProps);
|
|
2551
2697
|
if (!areaData) return null;
|
|
2552
2698
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2612,12 +2758,13 @@ exports.calcSize = calcSize;
|
|
|
2612
2758
|
exports.cloneLayer = cloneLayer;
|
|
2613
2759
|
exports.copyLayer = copyLayer;
|
|
2614
2760
|
exports.createLayer = createLayer;
|
|
2761
|
+
exports.createSuspenseResource = createSuspenseResource;
|
|
2615
2762
|
exports.declareFragmentProperty = declareFragmentProperty;
|
|
2616
2763
|
exports.defaultCustomRender = defaultCustomRender;
|
|
2617
2764
|
exports.duplicateLayer = duplicateLayer;
|
|
2765
|
+
exports.expandObjectProps = expandObjectProps;
|
|
2618
2766
|
exports.findBreakpoint = findBreakpoint;
|
|
2619
2767
|
exports.getAllParents = getAllParents;
|
|
2620
|
-
exports.getCssVariables = getCssVariables;
|
|
2621
2768
|
exports.getHydratedData = getHydratedData;
|
|
2622
2769
|
exports.getKey = getKey;
|
|
2623
2770
|
exports.getNormalizeLayer = getNormalizeLayer;
|
|
@@ -2625,6 +2772,7 @@ exports.getOverrider = getOverrider;
|
|
|
2625
2772
|
exports.getOverriderByLayers = getOverriderByLayers;
|
|
2626
2773
|
exports.getParent = getParent;
|
|
2627
2774
|
exports.getStylesheetKey = getStylesheetKey;
|
|
2775
|
+
exports.getSuspenseCache = getSuspenseCache;
|
|
2628
2776
|
exports.hashGenerator = hashGenerator;
|
|
2629
2777
|
exports.insertChildren = insertChildren;
|
|
2630
2778
|
exports.isBrowser = isBrowser;
|
|
@@ -2645,6 +2793,7 @@ exports.removeChildren = removeChildren;
|
|
|
2645
2793
|
exports.serializeData = serializeData;
|
|
2646
2794
|
exports.setKey = setKey;
|
|
2647
2795
|
exports.spliceChildren = spliceChildren;
|
|
2796
|
+
exports.toCssCustomProperties = toCssCustomProperties;
|
|
2648
2797
|
exports.transformCssValue = transformCssValue;
|
|
2649
2798
|
exports.useArea = useArea;
|
|
2650
2799
|
exports.useCollection = useCollection;
|
|
@@ -2662,7 +2811,6 @@ exports.useLayerBackground = useLayerBackground;
|
|
|
2662
2811
|
exports.useLayerBorder = useLayerBorder;
|
|
2663
2812
|
exports.useLayerChildren = useLayerChildren;
|
|
2664
2813
|
exports.useLayerCssOverride = useLayerCssOverride;
|
|
2665
|
-
exports.useLayerCssVariable = useLayerCssVariable;
|
|
2666
2814
|
exports.useLayerDisplay = useLayerDisplay;
|
|
2667
2815
|
exports.useLayerFlex = useLayerFlex;
|
|
2668
2816
|
exports.useLayerLayout = useLayerLayout;
|