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