@uniformdev/canvas 19.58.2-alpha.0 → 19.59.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/index.d.mts +328 -111
- package/dist/index.d.ts +328 -111
- package/dist/index.esm.js +514 -162
- package/dist/index.js +523 -163
- package/dist/index.mjs +514 -162
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -922,13 +922,93 @@ function isPromise(obj) {
|
|
922
922
|
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
923
923
|
}
|
924
924
|
|
925
|
-
// src/enhancement/
|
926
|
-
function
|
927
|
-
|
925
|
+
// src/enhancement/getComponentPath.ts
|
926
|
+
function getComponentPath(ancestorsAndSelf) {
|
927
|
+
const path = [];
|
928
|
+
for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
|
929
|
+
const currentLocation = ancestorsAndSelf[i];
|
930
|
+
const parentLocation = ancestorsAndSelf[i + 1];
|
931
|
+
if ("type" in currentLocation && currentLocation.type !== "slot") {
|
932
|
+
if (currentLocation.type === "block") {
|
933
|
+
const { fieldName, blockIndex } = currentLocation;
|
934
|
+
if (fieldName && blockIndex !== void 0) {
|
935
|
+
const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
|
936
|
+
path.push(`${noun}.${fieldName}.value[${blockIndex}]`);
|
937
|
+
}
|
938
|
+
} else {
|
939
|
+
}
|
940
|
+
continue;
|
941
|
+
}
|
942
|
+
const { parentSlot, parentSlotIndex } = currentLocation;
|
943
|
+
if (parentSlot && parentSlotIndex !== void 0) {
|
944
|
+
path.push(`${parentSlot}[${parentSlotIndex}]`);
|
945
|
+
}
|
946
|
+
}
|
947
|
+
return `.${path.join(".")}`;
|
948
|
+
}
|
949
|
+
|
950
|
+
// src/utils/constants.ts
|
951
|
+
var CANVAS_PERSONALIZE_TYPE = "$personalization";
|
952
|
+
var CANVAS_TEST_TYPE = "$test";
|
953
|
+
var CANVAS_LOCALIZATION_TYPE = "$localization";
|
954
|
+
var CANVAS_INTENT_TAG_PARAM = "intentTag";
|
955
|
+
var CANVAS_LOCALE_TAG_PARAM = "locale";
|
956
|
+
var CANVAS_BLOCK_PARAM_TYPE = "$block";
|
957
|
+
var CANVAS_PERSONALIZE_SLOT = "pz";
|
958
|
+
var CANVAS_TEST_SLOT = "test";
|
959
|
+
var CANVAS_LOCALIZATION_SLOT = "localized";
|
960
|
+
var CANVAS_DRAFT_STATE = 0;
|
961
|
+
var CANVAS_PUBLISHED_STATE = 64;
|
962
|
+
var CANVAS_EDITOR_STATE = 63;
|
963
|
+
var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
|
964
|
+
var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
|
965
|
+
var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
|
966
|
+
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
967
|
+
var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
|
968
|
+
var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
|
969
|
+
var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
|
970
|
+
var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
|
971
|
+
var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
|
972
|
+
var IS_RENDERED_BY_UNIFORM_ATTRIBUTE = "data-is-rendered-by-uniform";
|
973
|
+
var PLACEHOLDER_ID = "placeholder";
|
974
|
+
var EMPTY_COMPOSITION = {
|
975
|
+
_id: "_empty_composition_id",
|
976
|
+
_name: "An empty composition used for contextual editing",
|
977
|
+
type: "_empty_composition_type"
|
978
|
+
};
|
979
|
+
var EDGE_MIN_CACHE_TTL = 15;
|
980
|
+
var EDGE_MAX_CACHE_TTL = 600;
|
981
|
+
var EDGE_DEFAULT_CACHE_TTL = 30;
|
982
|
+
var EDGE_CACHE_DISABLED = -1;
|
983
|
+
var EDGE_MIN_L2_CACHE_TTL_IN_HOURS = 1;
|
984
|
+
var EDGE_MAX_L2_CACHE_TTL_IN_HOURS = 4 * 7 * 24;
|
985
|
+
var EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
|
986
|
+
|
987
|
+
// src/utils/entryConverter.ts
|
988
|
+
function convertEntryToPutEntry(entry) {
|
989
|
+
return {
|
990
|
+
entry: {
|
991
|
+
type: entry.entry.type,
|
992
|
+
_dataResources: entry.entry._dataResources,
|
993
|
+
_id: entry.entry._id,
|
994
|
+
_slug: entry.entry._slug,
|
995
|
+
fields: entry.entry.fields
|
996
|
+
},
|
997
|
+
state: entry.state,
|
998
|
+
projectId: entry.projectId
|
999
|
+
};
|
1000
|
+
}
|
1001
|
+
function getPropertiesValue(entity) {
|
1002
|
+
return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
// src/enhancement/walkNodeTree.ts
|
1006
|
+
function walkNodeTree(node, visitor, options) {
|
1007
|
+
var _a, _b;
|
928
1008
|
const componentQueue = [
|
929
1009
|
{
|
930
|
-
ancestorsAndSelf:
|
931
|
-
context: initialContext
|
1010
|
+
ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
|
1011
|
+
context: options == null ? void 0 : options.initialContext
|
932
1012
|
}
|
933
1013
|
];
|
934
1014
|
const childContexts = /* @__PURE__ */ new Map();
|
@@ -938,81 +1018,182 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
938
1018
|
continue;
|
939
1019
|
const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
|
940
1020
|
let visitDescendants = true;
|
941
|
-
let descendantContext = (_a = childContexts.get(currentComponent.
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
1021
|
+
let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
|
1022
|
+
let visitorInfo;
|
1023
|
+
if (currentComponent.type === "root" || currentComponent.type === "slot") {
|
1024
|
+
visitorInfo = {
|
1025
|
+
type: "component",
|
1026
|
+
node: currentComponent.node,
|
1027
|
+
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
1028
|
+
actions: {
|
1029
|
+
replace: (replacementComponent) => {
|
1030
|
+
Object.assign(currentComponent.node, replacementComponent);
|
1031
|
+
const propertiesToCheck = [
|
1032
|
+
"parameters",
|
1033
|
+
"variant",
|
1034
|
+
"slots",
|
1035
|
+
"data",
|
1036
|
+
"_pattern",
|
1037
|
+
"_patternError",
|
1038
|
+
"_dataResources",
|
1039
|
+
"_overridability",
|
1040
|
+
"_overrides",
|
1041
|
+
"_patternDataResources"
|
1042
|
+
];
|
1043
|
+
propertiesToCheck.forEach((property) => {
|
1044
|
+
if (!replacementComponent[property]) {
|
1045
|
+
delete currentComponent.node[property];
|
1046
|
+
}
|
1047
|
+
});
|
1048
|
+
},
|
1049
|
+
remove: () => {
|
1050
|
+
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
1051
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1052
|
+
if (currentComponentLocation.type === "root") {
|
1053
|
+
throw new Error("Unable to delete root node.");
|
959
1054
|
}
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
1055
|
+
if (currentComponentLocation.type === "slot") {
|
1056
|
+
const { parentSlot, parentSlotIndex } = currentComponentLocation;
|
1057
|
+
parentComponent.node.slots[parentSlot].splice(parentSlotIndex, 1);
|
1058
|
+
} else {
|
1059
|
+
throw new Error("Unknown node type");
|
1060
|
+
}
|
1061
|
+
},
|
1062
|
+
insertAfter: (nodes) => {
|
1063
|
+
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
1064
|
+
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
1065
|
+
if (currentNodeInfo.type === "root") {
|
1066
|
+
throw new Error("Unable to insert after root node.");
|
1067
|
+
}
|
1068
|
+
if (currentNodeInfo.type === "slot") {
|
1069
|
+
const { parentSlot, parentSlotIndex } = currentNodeInfo;
|
1070
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1071
|
+
if (parentSlot && typeof parentSlotIndex !== "undefined") {
|
1072
|
+
parentComponent.node.slots[parentSlot].splice(
|
1073
|
+
parentSlotIndex + 1,
|
1074
|
+
0,
|
1075
|
+
...nodesToInsert
|
1076
|
+
);
|
1077
|
+
componentQueue.unshift(
|
1078
|
+
...nodesToInsert.map((enqueueingComponent) => ({
|
1079
|
+
type: "slot",
|
1080
|
+
ancestorsAndSelf: [
|
1081
|
+
{
|
1082
|
+
type: "slot",
|
1083
|
+
node: enqueueingComponent,
|
1084
|
+
parentSlot,
|
1085
|
+
get parentSlotIndex() {
|
1086
|
+
return parentComponent.node.slots[parentSlot].findIndex(
|
1087
|
+
(x) => x === enqueueingComponent
|
1088
|
+
);
|
1089
|
+
}
|
1090
|
+
},
|
1091
|
+
// slice removes 'self' since we are inserting a peer of self
|
1092
|
+
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
1093
|
+
],
|
1094
|
+
context: descendantContext
|
1095
|
+
}))
|
1096
|
+
);
|
1097
|
+
}
|
1098
|
+
} else {
|
1099
|
+
throw new Error("Unknown type");
|
1100
|
+
}
|
1101
|
+
},
|
1102
|
+
stopProcessingDescendants() {
|
1103
|
+
visitDescendants = false;
|
1104
|
+
},
|
1105
|
+
setDescendantsContext(context) {
|
1106
|
+
descendantContext = context;
|
1107
|
+
},
|
1108
|
+
setChildContext(child, context) {
|
1109
|
+
childContexts.set(child, context);
|
969
1110
|
}
|
970
1111
|
},
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
);
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1112
|
+
context: descendantContext
|
1113
|
+
};
|
1114
|
+
} else {
|
1115
|
+
visitorInfo = {
|
1116
|
+
type: "entry",
|
1117
|
+
node: currentComponent.node,
|
1118
|
+
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
1119
|
+
actions: {
|
1120
|
+
replace: (replacementNode) => {
|
1121
|
+
Object.assign(currentComponent.node, replacementNode);
|
1122
|
+
const propertiesToCheck = ["fields", "_dataResources", "_author"];
|
1123
|
+
propertiesToCheck.forEach((property) => {
|
1124
|
+
if (!replacementNode[property]) {
|
1125
|
+
delete currentComponent.node[property];
|
1126
|
+
}
|
1127
|
+
});
|
1128
|
+
},
|
1129
|
+
remove: () => {
|
1130
|
+
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
1131
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1132
|
+
if (currentComponentLocation.type === "block") {
|
1133
|
+
const { fieldName, blockIndex } = currentComponentLocation;
|
1134
|
+
const blockValue = getBlockValue(parentComponent.node, fieldName);
|
1135
|
+
blockValue.splice(blockIndex, 1);
|
1136
|
+
if (blockValue.length === 0) {
|
1137
|
+
const properties2 = getPropertiesValue(parentComponent.node);
|
1138
|
+
delete properties2[fieldName];
|
1139
|
+
}
|
1140
|
+
} else {
|
1141
|
+
throw new Error("Unknown node type");
|
1142
|
+
}
|
1143
|
+
},
|
1144
|
+
insertAfter: (nodes) => {
|
1145
|
+
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
1146
|
+
if (currentNodeInfo.type !== "block") {
|
1147
|
+
throw new Error("Unknown type");
|
1148
|
+
}
|
1149
|
+
const { fieldName, blockIndex } = currentNodeInfo;
|
1150
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1151
|
+
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
1152
|
+
if (fieldName && typeof blockIndex !== "undefined") {
|
1153
|
+
getPropertiesValue(parentComponent.node)[fieldName].value.splice(
|
1154
|
+
blockIndex + 1,
|
1155
|
+
0,
|
1156
|
+
...nodesToInsert
|
1157
|
+
);
|
1158
|
+
componentQueue.unshift(
|
1159
|
+
...nodesToInsert.map((enqueueingComponent) => ({
|
1160
|
+
ancestorsAndSelf: [
|
1161
|
+
{
|
1162
|
+
type: "block",
|
1163
|
+
node: enqueueingComponent,
|
1164
|
+
fieldName,
|
1165
|
+
get blockIndex() {
|
1166
|
+
const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
|
1167
|
+
return parentArray.findIndex((x) => x === enqueueingComponent);
|
1168
|
+
}
|
1169
|
+
},
|
1170
|
+
// slice removes 'self' since we are inserting a peer of self
|
1171
|
+
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
1172
|
+
],
|
1173
|
+
context: descendantContext
|
1174
|
+
}))
|
1175
|
+
);
|
1176
|
+
}
|
1177
|
+
},
|
1178
|
+
stopProcessingDescendants() {
|
1179
|
+
visitDescendants = false;
|
1180
|
+
},
|
1181
|
+
setDescendantsContext(context) {
|
1182
|
+
descendantContext = context;
|
1183
|
+
},
|
1184
|
+
setChildContext(child, context) {
|
1185
|
+
childContexts.set(child, context);
|
1000
1186
|
}
|
1001
1187
|
},
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
},
|
1012
|
-
descendantContext
|
1013
|
-
);
|
1014
|
-
const slots = currentComponent.component.slots;
|
1015
|
-
if (visitDescendants && slots) {
|
1188
|
+
context: descendantContext
|
1189
|
+
};
|
1190
|
+
}
|
1191
|
+
visitor(visitorInfo);
|
1192
|
+
if (!visitDescendants) {
|
1193
|
+
continue;
|
1194
|
+
}
|
1195
|
+
const slots = "slots" in currentComponent.node && currentComponent.node.slots;
|
1196
|
+
if (slots) {
|
1016
1197
|
const slotKeys = Object.keys(slots);
|
1017
1198
|
for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
|
1018
1199
|
const slotKey = slotKeys[slotIndex];
|
@@ -1022,10 +1203,11 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1022
1203
|
componentQueue.push({
|
1023
1204
|
ancestorsAndSelf: [
|
1024
1205
|
{
|
1025
|
-
|
1206
|
+
type: "slot",
|
1207
|
+
node: enqueueingComponent,
|
1026
1208
|
parentSlot: slotKey,
|
1027
1209
|
get parentSlotIndex() {
|
1028
|
-
return currentComponent.
|
1210
|
+
return currentComponent.node.slots[slotKey].findIndex(
|
1029
1211
|
(x) => x === enqueueingComponent
|
1030
1212
|
);
|
1031
1213
|
}
|
@@ -1037,27 +1219,44 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1037
1219
|
}
|
1038
1220
|
}
|
1039
1221
|
}
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1222
|
+
const properties = getPropertiesValue(currentComponent.node);
|
1223
|
+
if (properties) {
|
1224
|
+
const propertyEntries = Object.entries(properties);
|
1225
|
+
for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
|
1226
|
+
const [propKey, propObject] = propertyEntries[propIndex];
|
1227
|
+
if (propObject.type !== CANVAS_BLOCK_PARAM_TYPE)
|
1228
|
+
continue;
|
1229
|
+
const blocks = (_b = propObject.value) != null ? _b : [];
|
1230
|
+
for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
|
1231
|
+
const enqueueingBlock = blocks[blockIndex];
|
1232
|
+
componentQueue.push({
|
1233
|
+
ancestorsAndSelf: [
|
1234
|
+
{
|
1235
|
+
type: "block",
|
1236
|
+
node: enqueueingBlock,
|
1237
|
+
fieldName: propKey,
|
1238
|
+
get blockIndex() {
|
1239
|
+
return getBlockValue(currentComponent.node, propKey).findIndex(
|
1240
|
+
(x) => x === enqueueingBlock
|
1241
|
+
);
|
1242
|
+
}
|
1243
|
+
},
|
1244
|
+
...currentQueueEntry.ancestorsAndSelf
|
1245
|
+
],
|
1246
|
+
context: descendantContext
|
1247
|
+
});
|
1248
|
+
}
|
1249
|
+
}
|
1048
1250
|
}
|
1049
|
-
}
|
1050
|
-
return `.${path.join(".")}`;
|
1251
|
+
} while (componentQueue.length > 0);
|
1051
1252
|
}
|
1052
|
-
function
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
path.push(`${parentSlot}/${parentSlotIndex}`);
|
1058
|
-
}
|
1253
|
+
function getBlockValue(component, parameterName) {
|
1254
|
+
var _a;
|
1255
|
+
const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
|
1256
|
+
if ((parameter == null ? void 0 : parameter.value) && parameter.type === CANVAS_BLOCK_PARAM_TYPE && Array.isArray(parameter.value)) {
|
1257
|
+
return parameter.value;
|
1059
1258
|
}
|
1060
|
-
return
|
1259
|
+
return [];
|
1061
1260
|
}
|
1062
1261
|
|
1063
1262
|
// src/enhancement/enhance.ts
|
@@ -1077,19 +1276,21 @@ async function enhance({
|
|
1077
1276
|
const promises = [];
|
1078
1277
|
const usedComponentEnhancers = /* @__PURE__ */ new Set();
|
1079
1278
|
const usedParameterEnhancers = /* @__PURE__ */ new Set();
|
1080
|
-
|
1279
|
+
walkNodeTree(composition, ({ type, node, ancestorsAndSelf, actions }) => {
|
1081
1280
|
var _a;
|
1082
|
-
|
1083
|
-
|
1281
|
+
if (type !== "component") {
|
1282
|
+
actions.stopProcessingDescendants();
|
1283
|
+
return;
|
1284
|
+
}
|
1285
|
+
Object.entries((_a = node.parameters) != null ? _a : {}).forEach(([paramName, paramValue]) => {
|
1286
|
+
const enhancer = enhancers.resolveParameterEnhancer(node, paramName, paramValue);
|
1084
1287
|
if (enhancer) {
|
1085
1288
|
usedParameterEnhancers.add(enhancer);
|
1086
|
-
promises.push(
|
1087
|
-
enhanceParameter(currentComponent, componentContext, paramName, paramValue, enhancer, context)
|
1088
|
-
);
|
1289
|
+
promises.push(enhanceParameter(node, ancestorsAndSelf, paramName, paramValue, enhancer, context));
|
1089
1290
|
}
|
1090
1291
|
});
|
1091
|
-
const componentEnhancers = enhancers.resolveComponentEnhancers(
|
1092
|
-
promises.push(enhanceComponent(
|
1292
|
+
const componentEnhancers = enhancers.resolveComponentEnhancers(node);
|
1293
|
+
promises.push(enhanceComponent(node, ancestorsAndSelf, componentEnhancers, context));
|
1093
1294
|
usedComponentEnhancers.add(componentEnhancers);
|
1094
1295
|
});
|
1095
1296
|
promises.push(
|
@@ -1307,41 +1508,30 @@ var EnhancerBuilder = class {
|
|
1307
1508
|
}
|
1308
1509
|
};
|
1309
1510
|
|
1310
|
-
// src/
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
_id: "_empty_composition_id",
|
1335
|
-
_name: "An empty composition used for contextual editing",
|
1336
|
-
type: "_empty_composition_type"
|
1337
|
-
};
|
1338
|
-
var EDGE_MIN_CACHE_TTL = 15;
|
1339
|
-
var EDGE_MAX_CACHE_TTL = 600;
|
1340
|
-
var EDGE_DEFAULT_CACHE_TTL = 30;
|
1341
|
-
var EDGE_CACHE_DISABLED = -1;
|
1342
|
-
var EDGE_MIN_L2_CACHE_TTL_IN_HOURS = 1;
|
1343
|
-
var EDGE_MAX_L2_CACHE_TTL_IN_HOURS = 4 * 7 * 24;
|
1344
|
-
var EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
|
1511
|
+
// src/enhancement/getComponentJsonPointer.ts
|
1512
|
+
function getComponentJsonPointer(ancestorsAndSelf) {
|
1513
|
+
const path = [];
|
1514
|
+
for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
|
1515
|
+
const currentLocation = ancestorsAndSelf[i];
|
1516
|
+
const parentLocation = ancestorsAndSelf[i + 1];
|
1517
|
+
if ("type" in currentLocation && currentLocation.type !== "slot") {
|
1518
|
+
if (currentLocation.type === "block") {
|
1519
|
+
const { fieldName: parameterName, blockIndex } = currentLocation;
|
1520
|
+
if (parameterName && blockIndex !== void 0) {
|
1521
|
+
const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
|
1522
|
+
path.push(`${noun}/${parameterName}/value/${blockIndex}`);
|
1523
|
+
}
|
1524
|
+
} else {
|
1525
|
+
}
|
1526
|
+
continue;
|
1527
|
+
}
|
1528
|
+
const { parentSlot, parentSlotIndex } = currentLocation;
|
1529
|
+
if (parentSlot && parentSlotIndex !== void 0) {
|
1530
|
+
path.push(`slots/${parentSlot}/${parentSlotIndex}`);
|
1531
|
+
}
|
1532
|
+
}
|
1533
|
+
return `/${path.join("/")}`;
|
1534
|
+
}
|
1345
1535
|
|
1346
1536
|
// src/enhancement/localize.ts
|
1347
1537
|
function extractLocales({ component }) {
|
@@ -1362,22 +1552,26 @@ function localize({
|
|
1362
1552
|
composition,
|
1363
1553
|
locale
|
1364
1554
|
}) {
|
1365
|
-
|
1366
|
-
if (
|
1367
|
-
|
1368
|
-
|
1555
|
+
walkNodeTree(composition, ({ type, node, actions }) => {
|
1556
|
+
if (type !== "component") {
|
1557
|
+
actions.stopProcessingDescendants();
|
1558
|
+
return;
|
1559
|
+
}
|
1560
|
+
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1561
|
+
const locales = extractLocales({ component: node });
|
1562
|
+
const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
|
1369
1563
|
let replaceComponent;
|
1370
1564
|
if (resolvedLocale) {
|
1371
1565
|
replaceComponent = locales[resolvedLocale];
|
1372
1566
|
}
|
1373
1567
|
if (replaceComponent == null ? void 0 : replaceComponent.length) {
|
1374
1568
|
const [first, ...rest] = replaceComponent;
|
1375
|
-
actions.
|
1569
|
+
actions.replace(first);
|
1376
1570
|
if (rest.length) {
|
1377
1571
|
actions.insertAfter(rest);
|
1378
1572
|
}
|
1379
1573
|
} else {
|
1380
|
-
actions.
|
1574
|
+
actions.remove();
|
1381
1575
|
}
|
1382
1576
|
}
|
1383
1577
|
});
|
@@ -1410,6 +1604,124 @@ var UniqueBatchEntries = class {
|
|
1410
1604
|
}
|
1411
1605
|
};
|
1412
1606
|
|
1607
|
+
// src/enhancement/walkComponentTree.ts
|
1608
|
+
function walkComponentTree(component, visitor, initialContext) {
|
1609
|
+
var _a;
|
1610
|
+
const componentQueue = [
|
1611
|
+
{
|
1612
|
+
ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
|
1613
|
+
context: initialContext
|
1614
|
+
}
|
1615
|
+
];
|
1616
|
+
const childContexts = /* @__PURE__ */ new Map();
|
1617
|
+
do {
|
1618
|
+
const currentQueueEntry = componentQueue.pop();
|
1619
|
+
if (!currentQueueEntry)
|
1620
|
+
continue;
|
1621
|
+
const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
|
1622
|
+
let visitDescendants = true;
|
1623
|
+
let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
|
1624
|
+
visitor(
|
1625
|
+
currentComponent.component,
|
1626
|
+
currentQueueEntry.ancestorsAndSelf,
|
1627
|
+
{
|
1628
|
+
replaceComponent: (replacementComponent) => {
|
1629
|
+
Object.assign(currentComponent.component, replacementComponent);
|
1630
|
+
const propertiesToCheck = [
|
1631
|
+
"parameters",
|
1632
|
+
"variant",
|
1633
|
+
"slots",
|
1634
|
+
"data",
|
1635
|
+
"_pattern",
|
1636
|
+
"_patternError"
|
1637
|
+
];
|
1638
|
+
propertiesToCheck.forEach((property) => {
|
1639
|
+
if (!replacementComponent[property]) {
|
1640
|
+
delete currentComponent.component[property];
|
1641
|
+
}
|
1642
|
+
});
|
1643
|
+
},
|
1644
|
+
removeComponent: () => {
|
1645
|
+
const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
|
1646
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1647
|
+
if (parentSlot && typeof parentSlotIndex !== "undefined") {
|
1648
|
+
parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
|
1649
|
+
} else {
|
1650
|
+
throw new Error("Unable to delete composition.");
|
1651
|
+
}
|
1652
|
+
},
|
1653
|
+
insertAfter: (components) => {
|
1654
|
+
const componentsToInsert = Array.isArray(components) ? components : [components];
|
1655
|
+
const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
|
1656
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1657
|
+
if (parentSlot && typeof parentSlotIndex !== "undefined") {
|
1658
|
+
parentComponent.component.slots[parentSlot].splice(
|
1659
|
+
parentSlotIndex + 1,
|
1660
|
+
0,
|
1661
|
+
...componentsToInsert
|
1662
|
+
);
|
1663
|
+
componentQueue.unshift(
|
1664
|
+
...componentsToInsert.map((enqueueingComponent) => ({
|
1665
|
+
ancestorsAndSelf: [
|
1666
|
+
{
|
1667
|
+
component: enqueueingComponent,
|
1668
|
+
parentSlot,
|
1669
|
+
get parentSlotIndex() {
|
1670
|
+
return parentComponent.component.slots[parentSlot].findIndex(
|
1671
|
+
(x) => x === enqueueingComponent
|
1672
|
+
);
|
1673
|
+
}
|
1674
|
+
},
|
1675
|
+
...currentQueueEntry.ancestorsAndSelf
|
1676
|
+
],
|
1677
|
+
context: descendantContext
|
1678
|
+
}))
|
1679
|
+
);
|
1680
|
+
} else {
|
1681
|
+
throw new Error("Unable to insert after a component not in a slot.");
|
1682
|
+
}
|
1683
|
+
},
|
1684
|
+
stopProcessingDescendants() {
|
1685
|
+
visitDescendants = false;
|
1686
|
+
},
|
1687
|
+
setDescendantsContext(context) {
|
1688
|
+
descendantContext = context;
|
1689
|
+
},
|
1690
|
+
setChildContext(child, context) {
|
1691
|
+
childContexts.set(child, context);
|
1692
|
+
}
|
1693
|
+
},
|
1694
|
+
descendantContext
|
1695
|
+
);
|
1696
|
+
const slots = currentComponent.component.slots;
|
1697
|
+
if (visitDescendants && slots) {
|
1698
|
+
const slotKeys = Object.keys(slots);
|
1699
|
+
for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
|
1700
|
+
const slotKey = slotKeys[slotIndex];
|
1701
|
+
const components = slots[slotKey];
|
1702
|
+
for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
|
1703
|
+
const enqueueingComponent = components[componentIndex];
|
1704
|
+
componentQueue.push({
|
1705
|
+
ancestorsAndSelf: [
|
1706
|
+
{
|
1707
|
+
component: enqueueingComponent,
|
1708
|
+
parentSlot: slotKey,
|
1709
|
+
get parentSlotIndex() {
|
1710
|
+
return currentComponent.component.slots[slotKey].findIndex(
|
1711
|
+
(x) => x === enqueueingComponent
|
1712
|
+
);
|
1713
|
+
}
|
1714
|
+
},
|
1715
|
+
...currentQueueEntry.ancestorsAndSelf
|
1716
|
+
],
|
1717
|
+
context: descendantContext
|
1718
|
+
});
|
1719
|
+
}
|
1720
|
+
}
|
1721
|
+
}
|
1722
|
+
} while (componentQueue.length > 0);
|
1723
|
+
}
|
1724
|
+
|
1413
1725
|
// src/utils/hash.ts
|
1414
1726
|
var generateHash = ({
|
1415
1727
|
composition,
|
@@ -1435,6 +1747,9 @@ var isSelectComponentMessage = (message) => {
|
|
1435
1747
|
var isReadyMessage = (message) => {
|
1436
1748
|
return message.type === "ready";
|
1437
1749
|
};
|
1750
|
+
var isComponentActionMessage = (message) => {
|
1751
|
+
return message.type === "trigger-component-action";
|
1752
|
+
};
|
1438
1753
|
var isUpdateCompositionMessage = (message) => {
|
1439
1754
|
return message.type === "update-composition";
|
1440
1755
|
};
|
@@ -1459,6 +1774,9 @@ var isTriggerCompositionActionMessage = (message) => {
|
|
1459
1774
|
var isUpdatePreviewSettingsMessage = (message) => {
|
1460
1775
|
return message.type === "update-preview-settings";
|
1461
1776
|
};
|
1777
|
+
var isUpdateFeatureFlagsMessage = (message) => {
|
1778
|
+
return message.type === "update-feature-flags";
|
1779
|
+
};
|
1462
1780
|
var isUpdateContextualEditingStateInternalMessage = (message) => {
|
1463
1781
|
return message.type === "update-contextual-editing-state-internal";
|
1464
1782
|
};
|
@@ -1468,6 +1786,12 @@ var isReportRenderedCompositionsMessage = (message) => {
|
|
1468
1786
|
var isSelectParameterMessage = (message) => {
|
1469
1787
|
return message.type === "select-parameter";
|
1470
1788
|
};
|
1789
|
+
var isOpenParameterEditorMessage = (message) => {
|
1790
|
+
return message.type === "open-parameter-editor";
|
1791
|
+
};
|
1792
|
+
var isUpdateComponentReferencesMessage = (message) => {
|
1793
|
+
return message.type === "update-component-references";
|
1794
|
+
};
|
1471
1795
|
var createCanvasChannel = ({
|
1472
1796
|
listenTo,
|
1473
1797
|
broadcastTo
|
@@ -1528,6 +1852,13 @@ var createCanvasChannel = ({
|
|
1528
1852
|
};
|
1529
1853
|
postMessage(message);
|
1530
1854
|
};
|
1855
|
+
const triggerComponentAction = (options) => {
|
1856
|
+
const message = {
|
1857
|
+
...options,
|
1858
|
+
type: "trigger-component-action"
|
1859
|
+
};
|
1860
|
+
postMessage(message);
|
1861
|
+
};
|
1531
1862
|
const addComponent = (options) => {
|
1532
1863
|
const message = {
|
1533
1864
|
...options,
|
@@ -1591,12 +1922,33 @@ var createCanvasChannel = ({
|
|
1591
1922
|
};
|
1592
1923
|
postMessage(message);
|
1593
1924
|
};
|
1925
|
+
const openParameterEditor = (options) => {
|
1926
|
+
const message = {
|
1927
|
+
...options,
|
1928
|
+
type: "open-parameter-editor"
|
1929
|
+
};
|
1930
|
+
postMessage(message);
|
1931
|
+
};
|
1594
1932
|
const editorStateUpdated = () => {
|
1595
1933
|
const message = {
|
1596
1934
|
type: "editor-state-updated"
|
1597
1935
|
};
|
1598
1936
|
postMessage(message);
|
1599
1937
|
};
|
1938
|
+
const updateComponentReferences = (options) => {
|
1939
|
+
const message = {
|
1940
|
+
...options,
|
1941
|
+
type: "update-component-references"
|
1942
|
+
};
|
1943
|
+
postMessage(message);
|
1944
|
+
};
|
1945
|
+
const updateFeatureFlags = (options) => {
|
1946
|
+
const message = {
|
1947
|
+
...options,
|
1948
|
+
type: "update-feature-flags"
|
1949
|
+
};
|
1950
|
+
postMessage(message);
|
1951
|
+
};
|
1600
1952
|
const messageEventListener = (event) => {
|
1601
1953
|
if (typeof event.data !== "string") {
|
1602
1954
|
return;
|
@@ -1626,6 +1978,7 @@ var createCanvasChannel = ({
|
|
1626
1978
|
return {
|
1627
1979
|
ready,
|
1628
1980
|
destroy,
|
1981
|
+
triggerComponentAction,
|
1629
1982
|
selectComponent,
|
1630
1983
|
updateComposition,
|
1631
1984
|
updateCompositionInternal,
|
@@ -1636,10 +1989,13 @@ var createCanvasChannel = ({
|
|
1636
1989
|
dismissPlaceholder,
|
1637
1990
|
triggerCompositionAction,
|
1638
1991
|
updatePreviewSettings,
|
1992
|
+
updateFeatureFlags,
|
1639
1993
|
updateContextualEditingStateInternal,
|
1640
1994
|
selectParameter,
|
1995
|
+
openParameterEditor,
|
1641
1996
|
reportRenderedCompositions,
|
1642
|
-
editorStateUpdated
|
1997
|
+
editorStateUpdated,
|
1998
|
+
updateComponentReferences
|
1643
1999
|
};
|
1644
2000
|
};
|
1645
2001
|
|
@@ -1763,21 +2119,6 @@ var createUniformApiEnhancer = ({ apiUrl }) => {
|
|
1763
2119
|
};
|
1764
2120
|
};
|
1765
2121
|
|
1766
|
-
// src/utils/entryConverter.ts
|
1767
|
-
function convertEntryToPutEntry(entry) {
|
1768
|
-
return {
|
1769
|
-
entry: {
|
1770
|
-
type: entry.entry.type,
|
1771
|
-
_dataResources: entry.entry._dataResources,
|
1772
|
-
_id: entry.entry._id,
|
1773
|
-
_slug: entry.entry._slug,
|
1774
|
-
fields: entry.entry.fields
|
1775
|
-
},
|
1776
|
-
state: entry.state,
|
1777
|
-
projectId: entry.projectId
|
1778
|
-
};
|
1779
|
-
}
|
1780
|
-
|
1781
2122
|
// src/utils/getParameterAttributes.ts
|
1782
2123
|
var ATTRIBUTE_COMPONENT_ID = "data-uniform-component-id";
|
1783
2124
|
var ATTRIBUTE_PARAMETER_ID = "data-uniform-parameter-id";
|
@@ -1857,7 +2198,10 @@ var isComponentPlaceholderId = (id) => {
|
|
1857
2198
|
}
|
1858
2199
|
return id == null ? void 0 : id.startsWith(PLACEHOLDER_ID);
|
1859
2200
|
};
|
1860
|
-
var generateComponentPlaceholderId = (randomId) => {
|
2201
|
+
var generateComponentPlaceholderId = (randomId, sdkVersion) => {
|
2202
|
+
if (typeof sdkVersion === "undefined" || sdkVersion === 1) {
|
2203
|
+
return PLACEHOLDER_ID;
|
2204
|
+
}
|
1861
2205
|
return `${PLACEHOLDER_ID}_${randomId}`;
|
1862
2206
|
};
|
1863
2207
|
|
@@ -2055,6 +2399,7 @@ export {
|
|
2055
2399
|
ATTRIBUTE_PLACEHOLDER,
|
2056
2400
|
ApiClientError2 as ApiClientError,
|
2057
2401
|
BatchEntry,
|
2402
|
+
CANVAS_BLOCK_PARAM_TYPE,
|
2058
2403
|
CANVAS_DRAFT_STATE,
|
2059
2404
|
CANVAS_EDITOR_STATE,
|
2060
2405
|
CANVAS_ENRICHMENT_TAG_PARAM,
|
@@ -2112,15 +2457,19 @@ export {
|
|
2112
2457
|
extractLocales,
|
2113
2458
|
generateComponentPlaceholderId,
|
2114
2459
|
generateHash,
|
2460
|
+
getBlockValue,
|
2115
2461
|
getChannelName,
|
2116
2462
|
getComponentJsonPointer,
|
2117
2463
|
getComponentPath,
|
2118
2464
|
getParameterAttributes,
|
2465
|
+
getPropertiesValue,
|
2119
2466
|
isAddComponentMessage,
|
2120
2467
|
isAllowedReferrer,
|
2468
|
+
isComponentActionMessage,
|
2121
2469
|
isComponentPlaceholderId,
|
2122
2470
|
isDismissPlaceholderMessage,
|
2123
2471
|
isMovingComponentMessage,
|
2472
|
+
isOpenParameterEditorMessage,
|
2124
2473
|
isReadyMessage,
|
2125
2474
|
isReportRenderedCompositionsMessage,
|
2126
2475
|
isSelectComponentMessage,
|
@@ -2128,9 +2477,11 @@ export {
|
|
2128
2477
|
isSystemComponentDefinition,
|
2129
2478
|
isTriggerCompositionActionMessage,
|
2130
2479
|
isUpdateComponentParameterMessage,
|
2480
|
+
isUpdateComponentReferencesMessage,
|
2131
2481
|
isUpdateCompositionInternalMessage,
|
2132
2482
|
isUpdateCompositionMessage,
|
2133
2483
|
isUpdateContextualEditingStateInternalMessage,
|
2484
|
+
isUpdateFeatureFlagsMessage,
|
2134
2485
|
isUpdatePreviewSettingsMessage,
|
2135
2486
|
localize,
|
2136
2487
|
mapSlotToPersonalizedVariations,
|
@@ -2139,5 +2490,6 @@ export {
|
|
2139
2490
|
parseVariableExpression,
|
2140
2491
|
subscribeToComposition,
|
2141
2492
|
unstable_CompositionRelationshipClient,
|
2142
|
-
walkComponentTree
|
2493
|
+
walkComponentTree,
|
2494
|
+
walkNodeTree
|
2143
2495
|
};
|