@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.js CHANGED
@@ -285,6 +285,7 @@ __export(src_exports, {
285
285
  ATTRIBUTE_PLACEHOLDER: () => ATTRIBUTE_PLACEHOLDER,
286
286
  ApiClientError: () => import_api9.ApiClientError,
287
287
  BatchEntry: () => BatchEntry,
288
+ CANVAS_BLOCK_PARAM_TYPE: () => CANVAS_BLOCK_PARAM_TYPE,
288
289
  CANVAS_DRAFT_STATE: () => CANVAS_DRAFT_STATE,
289
290
  CANVAS_EDITOR_STATE: () => CANVAS_EDITOR_STATE,
290
291
  CANVAS_ENRICHMENT_TAG_PARAM: () => CANVAS_ENRICHMENT_TAG_PARAM,
@@ -324,6 +325,7 @@ __export(src_exports, {
324
325
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE: () => IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
325
326
  PLACEHOLDER_ID: () => PLACEHOLDER_ID,
326
327
  RouteClient: () => RouteClient,
328
+ SECRET_QUERY_STRING_PARAM: () => SECRET_QUERY_STRING_PARAM,
327
329
  UncachedCanvasClient: () => UncachedCanvasClient,
328
330
  UncachedCategoryClient: () => UncachedCategoryClient,
329
331
  UncachedContentClient: () => UncachedContentClient,
@@ -342,15 +344,19 @@ __export(src_exports, {
342
344
  extractLocales: () => extractLocales,
343
345
  generateComponentPlaceholderId: () => generateComponentPlaceholderId,
344
346
  generateHash: () => generateHash,
347
+ getBlockValue: () => getBlockValue,
345
348
  getChannelName: () => getChannelName,
346
349
  getComponentJsonPointer: () => getComponentJsonPointer,
347
350
  getComponentPath: () => getComponentPath,
348
351
  getParameterAttributes: () => getParameterAttributes,
352
+ getPropertiesValue: () => getPropertiesValue,
349
353
  isAddComponentMessage: () => isAddComponentMessage,
350
354
  isAllowedReferrer: () => isAllowedReferrer,
355
+ isComponentActionMessage: () => isComponentActionMessage,
351
356
  isComponentPlaceholderId: () => isComponentPlaceholderId,
352
357
  isDismissPlaceholderMessage: () => isDismissPlaceholderMessage,
353
358
  isMovingComponentMessage: () => isMovingComponentMessage,
359
+ isOpenParameterEditorMessage: () => isOpenParameterEditorMessage,
354
360
  isReadyMessage: () => isReadyMessage,
355
361
  isReportRenderedCompositionsMessage: () => isReportRenderedCompositionsMessage,
356
362
  isSelectComponentMessage: () => isSelectComponentMessage,
@@ -358,9 +364,11 @@ __export(src_exports, {
358
364
  isSystemComponentDefinition: () => isSystemComponentDefinition,
359
365
  isTriggerCompositionActionMessage: () => isTriggerCompositionActionMessage,
360
366
  isUpdateComponentParameterMessage: () => isUpdateComponentParameterMessage,
367
+ isUpdateComponentReferencesMessage: () => isUpdateComponentReferencesMessage,
361
368
  isUpdateCompositionInternalMessage: () => isUpdateCompositionInternalMessage,
362
369
  isUpdateCompositionMessage: () => isUpdateCompositionMessage,
363
370
  isUpdateContextualEditingStateInternalMessage: () => isUpdateContextualEditingStateInternalMessage,
371
+ isUpdateFeatureFlagsMessage: () => isUpdateFeatureFlagsMessage,
364
372
  isUpdatePreviewSettingsMessage: () => isUpdatePreviewSettingsMessage,
365
373
  localize: () => localize,
366
374
  mapSlotToPersonalizedVariations: () => mapSlotToPersonalizedVariations,
@@ -369,7 +377,8 @@ __export(src_exports, {
369
377
  parseVariableExpression: () => parseVariableExpression,
370
378
  subscribeToComposition: () => subscribeToComposition,
371
379
  unstable_CompositionRelationshipClient: () => unstable_CompositionRelationshipClient,
372
- walkComponentTree: () => walkComponentTree
380
+ walkComponentTree: () => walkComponentTree,
381
+ walkNodeTree: () => walkNodeTree
373
382
  });
374
383
  module.exports = __toCommonJS(src_exports);
375
384
 
@@ -1027,13 +1036,94 @@ function isPromise(obj) {
1027
1036
  return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
1028
1037
  }
1029
1038
 
1030
- // src/enhancement/walkComponentTree.ts
1031
- function walkComponentTree(component, visitor, initialContext) {
1032
- var _a;
1039
+ // src/enhancement/getComponentPath.ts
1040
+ function getComponentPath(ancestorsAndSelf) {
1041
+ const path = [];
1042
+ for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1043
+ const currentLocation = ancestorsAndSelf[i];
1044
+ const parentLocation = ancestorsAndSelf[i + 1];
1045
+ if ("type" in currentLocation && currentLocation.type !== "slot") {
1046
+ if (currentLocation.type === "block") {
1047
+ const { fieldName, blockIndex } = currentLocation;
1048
+ if (fieldName && blockIndex !== void 0) {
1049
+ const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
1050
+ path.push(`${noun}.${fieldName}.value[${blockIndex}]`);
1051
+ }
1052
+ } else {
1053
+ }
1054
+ continue;
1055
+ }
1056
+ const { parentSlot, parentSlotIndex } = currentLocation;
1057
+ if (parentSlot && parentSlotIndex !== void 0) {
1058
+ path.push(`${parentSlot}[${parentSlotIndex}]`);
1059
+ }
1060
+ }
1061
+ return `.${path.join(".")}`;
1062
+ }
1063
+
1064
+ // src/utils/constants.ts
1065
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
1066
+ var CANVAS_TEST_TYPE = "$test";
1067
+ var CANVAS_LOCALIZATION_TYPE = "$localization";
1068
+ var CANVAS_INTENT_TAG_PARAM = "intentTag";
1069
+ var CANVAS_LOCALE_TAG_PARAM = "locale";
1070
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
1071
+ var CANVAS_PERSONALIZE_SLOT = "pz";
1072
+ var CANVAS_TEST_SLOT = "test";
1073
+ var CANVAS_LOCALIZATION_SLOT = "localized";
1074
+ var CANVAS_DRAFT_STATE = 0;
1075
+ var CANVAS_PUBLISHED_STATE = 64;
1076
+ var CANVAS_EDITOR_STATE = 63;
1077
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1078
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1079
+ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1080
+ var SECRET_QUERY_STRING_PARAM = "secret";
1081
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1082
+ var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1083
+ var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
1084
+ var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1085
+ var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
1086
+ var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1087
+ var IS_RENDERED_BY_UNIFORM_ATTRIBUTE = "data-is-rendered-by-uniform";
1088
+ var PLACEHOLDER_ID = "placeholder";
1089
+ var EMPTY_COMPOSITION = {
1090
+ _id: "_empty_composition_id",
1091
+ _name: "An empty composition used for contextual editing",
1092
+ type: "_empty_composition_type"
1093
+ };
1094
+ var EDGE_MIN_CACHE_TTL = 15;
1095
+ var EDGE_MAX_CACHE_TTL = 600;
1096
+ var EDGE_DEFAULT_CACHE_TTL = 30;
1097
+ var EDGE_CACHE_DISABLED = -1;
1098
+ var EDGE_MIN_L2_CACHE_TTL_IN_HOURS = 1;
1099
+ var EDGE_MAX_L2_CACHE_TTL_IN_HOURS = 4 * 7 * 24;
1100
+ var EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
1101
+
1102
+ // src/utils/entryConverter.ts
1103
+ function convertEntryToPutEntry(entry) {
1104
+ return {
1105
+ entry: {
1106
+ type: entry.entry.type,
1107
+ _dataResources: entry.entry._dataResources,
1108
+ _id: entry.entry._id,
1109
+ _slug: entry.entry._slug,
1110
+ fields: entry.entry.fields
1111
+ },
1112
+ state: entry.state,
1113
+ projectId: entry.projectId
1114
+ };
1115
+ }
1116
+ function getPropertiesValue(entity) {
1117
+ return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
1118
+ }
1119
+
1120
+ // src/enhancement/walkNodeTree.ts
1121
+ function walkNodeTree(node, visitor, options) {
1122
+ var _a, _b;
1033
1123
  const componentQueue = [
1034
1124
  {
1035
- ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
1036
- context: initialContext
1125
+ ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
1126
+ context: options == null ? void 0 : options.initialContext
1037
1127
  }
1038
1128
  ];
1039
1129
  const childContexts = /* @__PURE__ */ new Map();
@@ -1043,81 +1133,182 @@ function walkComponentTree(component, visitor, initialContext) {
1043
1133
  continue;
1044
1134
  const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1045
1135
  let visitDescendants = true;
1046
- let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
1047
- visitor(
1048
- currentComponent.component,
1049
- currentQueueEntry.ancestorsAndSelf,
1050
- {
1051
- replaceComponent: (replacementComponent) => {
1052
- Object.assign(currentComponent.component, replacementComponent);
1053
- const propertiesToCheck = [
1054
- "parameters",
1055
- "variant",
1056
- "slots",
1057
- "data",
1058
- "_pattern",
1059
- "_patternError"
1060
- ];
1061
- propertiesToCheck.forEach((property) => {
1062
- if (!replacementComponent[property]) {
1063
- delete currentComponent.component[property];
1136
+ let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
1137
+ let visitorInfo;
1138
+ if (currentComponent.type === "root" || currentComponent.type === "slot") {
1139
+ visitorInfo = {
1140
+ type: "component",
1141
+ node: currentComponent.node,
1142
+ ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
1143
+ actions: {
1144
+ replace: (replacementComponent) => {
1145
+ Object.assign(currentComponent.node, replacementComponent);
1146
+ const propertiesToCheck = [
1147
+ "parameters",
1148
+ "variant",
1149
+ "slots",
1150
+ "data",
1151
+ "_pattern",
1152
+ "_patternError",
1153
+ "_dataResources",
1154
+ "_overridability",
1155
+ "_overrides",
1156
+ "_patternDataResources"
1157
+ ];
1158
+ propertiesToCheck.forEach((property) => {
1159
+ if (!replacementComponent[property]) {
1160
+ delete currentComponent.node[property];
1161
+ }
1162
+ });
1163
+ },
1164
+ remove: () => {
1165
+ const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
1166
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1167
+ if (currentComponentLocation.type === "root") {
1168
+ throw new Error("Unable to delete root node.");
1064
1169
  }
1065
- });
1066
- },
1067
- removeComponent: () => {
1068
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
1069
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1070
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
1071
- parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
1072
- } else {
1073
- throw new Error("Unable to delete composition.");
1170
+ if (currentComponentLocation.type === "slot") {
1171
+ const { parentSlot, parentSlotIndex } = currentComponentLocation;
1172
+ parentComponent.node.slots[parentSlot].splice(parentSlotIndex, 1);
1173
+ } else {
1174
+ throw new Error("Unknown node type");
1175
+ }
1176
+ },
1177
+ insertAfter: (nodes) => {
1178
+ const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
1179
+ const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
1180
+ if (currentNodeInfo.type === "root") {
1181
+ throw new Error("Unable to insert after root node.");
1182
+ }
1183
+ if (currentNodeInfo.type === "slot") {
1184
+ const { parentSlot, parentSlotIndex } = currentNodeInfo;
1185
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1186
+ if (parentSlot && typeof parentSlotIndex !== "undefined") {
1187
+ parentComponent.node.slots[parentSlot].splice(
1188
+ parentSlotIndex + 1,
1189
+ 0,
1190
+ ...nodesToInsert
1191
+ );
1192
+ componentQueue.unshift(
1193
+ ...nodesToInsert.map((enqueueingComponent) => ({
1194
+ type: "slot",
1195
+ ancestorsAndSelf: [
1196
+ {
1197
+ type: "slot",
1198
+ node: enqueueingComponent,
1199
+ parentSlot,
1200
+ get parentSlotIndex() {
1201
+ return parentComponent.node.slots[parentSlot].findIndex(
1202
+ (x) => x === enqueueingComponent
1203
+ );
1204
+ }
1205
+ },
1206
+ // slice removes 'self' since we are inserting a peer of self
1207
+ ...currentQueueEntry.ancestorsAndSelf.slice(1)
1208
+ ],
1209
+ context: descendantContext
1210
+ }))
1211
+ );
1212
+ }
1213
+ } else {
1214
+ throw new Error("Unknown type");
1215
+ }
1216
+ },
1217
+ stopProcessingDescendants() {
1218
+ visitDescendants = false;
1219
+ },
1220
+ setDescendantsContext(context) {
1221
+ descendantContext = context;
1222
+ },
1223
+ setChildContext(child, context) {
1224
+ childContexts.set(child, context);
1074
1225
  }
1075
1226
  },
1076
- insertAfter: (components) => {
1077
- const componentsToInsert = Array.isArray(components) ? components : [components];
1078
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
1079
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1080
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
1081
- parentComponent.component.slots[parentSlot].splice(
1082
- parentSlotIndex + 1,
1083
- 0,
1084
- ...componentsToInsert
1085
- );
1086
- componentQueue.unshift(
1087
- ...componentsToInsert.map((enqueueingComponent) => ({
1088
- ancestorsAndSelf: [
1089
- {
1090
- component: enqueueingComponent,
1091
- parentSlot,
1092
- get parentSlotIndex() {
1093
- return parentComponent.component.slots[parentSlot].findIndex(
1094
- (x) => x === enqueueingComponent
1095
- );
1096
- }
1097
- },
1098
- ...currentQueueEntry.ancestorsAndSelf
1099
- ],
1100
- context: descendantContext
1101
- }))
1102
- );
1103
- } else {
1104
- throw new Error("Unable to insert after a component not in a slot.");
1227
+ context: descendantContext
1228
+ };
1229
+ } else {
1230
+ visitorInfo = {
1231
+ type: "entry",
1232
+ node: currentComponent.node,
1233
+ ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
1234
+ actions: {
1235
+ replace: (replacementNode) => {
1236
+ Object.assign(currentComponent.node, replacementNode);
1237
+ const propertiesToCheck = ["fields", "_dataResources", "_author"];
1238
+ propertiesToCheck.forEach((property) => {
1239
+ if (!replacementNode[property]) {
1240
+ delete currentComponent.node[property];
1241
+ }
1242
+ });
1243
+ },
1244
+ remove: () => {
1245
+ const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
1246
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1247
+ if (currentComponentLocation.type === "block") {
1248
+ const { fieldName, blockIndex } = currentComponentLocation;
1249
+ const blockValue = getBlockValue(parentComponent.node, fieldName);
1250
+ blockValue.splice(blockIndex, 1);
1251
+ if (blockValue.length === 0) {
1252
+ const properties2 = getPropertiesValue(parentComponent.node);
1253
+ delete properties2[fieldName];
1254
+ }
1255
+ } else {
1256
+ throw new Error("Unknown node type");
1257
+ }
1258
+ },
1259
+ insertAfter: (nodes) => {
1260
+ const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
1261
+ if (currentNodeInfo.type !== "block") {
1262
+ throw new Error("Unknown type");
1263
+ }
1264
+ const { fieldName, blockIndex } = currentNodeInfo;
1265
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1266
+ const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
1267
+ if (fieldName && typeof blockIndex !== "undefined") {
1268
+ getPropertiesValue(parentComponent.node)[fieldName].value.splice(
1269
+ blockIndex + 1,
1270
+ 0,
1271
+ ...nodesToInsert
1272
+ );
1273
+ componentQueue.unshift(
1274
+ ...nodesToInsert.map((enqueueingComponent) => ({
1275
+ ancestorsAndSelf: [
1276
+ {
1277
+ type: "block",
1278
+ node: enqueueingComponent,
1279
+ fieldName,
1280
+ get blockIndex() {
1281
+ const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
1282
+ return parentArray.findIndex((x) => x === enqueueingComponent);
1283
+ }
1284
+ },
1285
+ // slice removes 'self' since we are inserting a peer of self
1286
+ ...currentQueueEntry.ancestorsAndSelf.slice(1)
1287
+ ],
1288
+ context: descendantContext
1289
+ }))
1290
+ );
1291
+ }
1292
+ },
1293
+ stopProcessingDescendants() {
1294
+ visitDescendants = false;
1295
+ },
1296
+ setDescendantsContext(context) {
1297
+ descendantContext = context;
1298
+ },
1299
+ setChildContext(child, context) {
1300
+ childContexts.set(child, context);
1105
1301
  }
1106
1302
  },
1107
- stopProcessingDescendants() {
1108
- visitDescendants = false;
1109
- },
1110
- setDescendantsContext(context) {
1111
- descendantContext = context;
1112
- },
1113
- setChildContext(child, context) {
1114
- childContexts.set(child, context);
1115
- }
1116
- },
1117
- descendantContext
1118
- );
1119
- const slots = currentComponent.component.slots;
1120
- if (visitDescendants && slots) {
1303
+ context: descendantContext
1304
+ };
1305
+ }
1306
+ visitor(visitorInfo);
1307
+ if (!visitDescendants) {
1308
+ continue;
1309
+ }
1310
+ const slots = "slots" in currentComponent.node && currentComponent.node.slots;
1311
+ if (slots) {
1121
1312
  const slotKeys = Object.keys(slots);
1122
1313
  for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1123
1314
  const slotKey = slotKeys[slotIndex];
@@ -1127,10 +1318,11 @@ function walkComponentTree(component, visitor, initialContext) {
1127
1318
  componentQueue.push({
1128
1319
  ancestorsAndSelf: [
1129
1320
  {
1130
- component: enqueueingComponent,
1321
+ type: "slot",
1322
+ node: enqueueingComponent,
1131
1323
  parentSlot: slotKey,
1132
1324
  get parentSlotIndex() {
1133
- return currentComponent.component.slots[slotKey].findIndex(
1325
+ return currentComponent.node.slots[slotKey].findIndex(
1134
1326
  (x) => x === enqueueingComponent
1135
1327
  );
1136
1328
  }
@@ -1142,27 +1334,44 @@ function walkComponentTree(component, visitor, initialContext) {
1142
1334
  }
1143
1335
  }
1144
1336
  }
1145
- } while (componentQueue.length > 0);
1146
- }
1147
- function getComponentPath(ancestorsAndSelf) {
1148
- const path = [];
1149
- for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1150
- const { parentSlot, parentSlotIndex } = ancestorsAndSelf[i];
1151
- if (parentSlot && parentSlotIndex !== void 0) {
1152
- path.push(`${parentSlot}[${parentSlotIndex}]`);
1337
+ const properties = getPropertiesValue(currentComponent.node);
1338
+ if (properties) {
1339
+ const propertyEntries = Object.entries(properties);
1340
+ for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1341
+ const [propKey, propObject] = propertyEntries[propIndex];
1342
+ if (propObject.type !== CANVAS_BLOCK_PARAM_TYPE)
1343
+ continue;
1344
+ const blocks = (_b = propObject.value) != null ? _b : [];
1345
+ for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
1346
+ const enqueueingBlock = blocks[blockIndex];
1347
+ componentQueue.push({
1348
+ ancestorsAndSelf: [
1349
+ {
1350
+ type: "block",
1351
+ node: enqueueingBlock,
1352
+ fieldName: propKey,
1353
+ get blockIndex() {
1354
+ return getBlockValue(currentComponent.node, propKey).findIndex(
1355
+ (x) => x === enqueueingBlock
1356
+ );
1357
+ }
1358
+ },
1359
+ ...currentQueueEntry.ancestorsAndSelf
1360
+ ],
1361
+ context: descendantContext
1362
+ });
1363
+ }
1364
+ }
1153
1365
  }
1154
- }
1155
- return `.${path.join(".")}`;
1366
+ } while (componentQueue.length > 0);
1156
1367
  }
1157
- function getComponentJsonPointer(ancestorsAndSelf, { withSlots = false } = {}) {
1158
- const path = [];
1159
- for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1160
- const { parentSlot, parentSlotIndex } = ancestorsAndSelf[i];
1161
- if (parentSlot && parentSlotIndex !== void 0) {
1162
- path.push(`${parentSlot}/${parentSlotIndex}`);
1163
- }
1368
+ function getBlockValue(component, parameterName) {
1369
+ var _a;
1370
+ const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
1371
+ if ((parameter == null ? void 0 : parameter.value) && parameter.type === CANVAS_BLOCK_PARAM_TYPE && Array.isArray(parameter.value)) {
1372
+ return parameter.value;
1164
1373
  }
1165
- return withSlots ? `/slots/${path.join("/slots/")}` : `/${path.join("/")}`;
1374
+ return [];
1166
1375
  }
1167
1376
 
1168
1377
  // src/enhancement/enhance.ts
@@ -1182,19 +1391,21 @@ async function enhance({
1182
1391
  const promises = [];
1183
1392
  const usedComponentEnhancers = /* @__PURE__ */ new Set();
1184
1393
  const usedParameterEnhancers = /* @__PURE__ */ new Set();
1185
- walkComponentTree(composition, (currentComponent, componentContext) => {
1394
+ walkNodeTree(composition, ({ type, node, ancestorsAndSelf, actions }) => {
1186
1395
  var _a;
1187
- Object.entries((_a = currentComponent.parameters) != null ? _a : {}).forEach(([paramName, paramValue]) => {
1188
- const enhancer = enhancers.resolveParameterEnhancer(currentComponent, paramName, paramValue);
1396
+ if (type !== "component") {
1397
+ actions.stopProcessingDescendants();
1398
+ return;
1399
+ }
1400
+ Object.entries((_a = node.parameters) != null ? _a : {}).forEach(([paramName, paramValue]) => {
1401
+ const enhancer = enhancers.resolveParameterEnhancer(node, paramName, paramValue);
1189
1402
  if (enhancer) {
1190
1403
  usedParameterEnhancers.add(enhancer);
1191
- promises.push(
1192
- enhanceParameter(currentComponent, componentContext, paramName, paramValue, enhancer, context)
1193
- );
1404
+ promises.push(enhanceParameter(node, ancestorsAndSelf, paramName, paramValue, enhancer, context));
1194
1405
  }
1195
1406
  });
1196
- const componentEnhancers = enhancers.resolveComponentEnhancers(currentComponent);
1197
- promises.push(enhanceComponent(currentComponent, componentContext, componentEnhancers, context));
1407
+ const componentEnhancers = enhancers.resolveComponentEnhancers(node);
1408
+ promises.push(enhanceComponent(node, ancestorsAndSelf, componentEnhancers, context));
1198
1409
  usedComponentEnhancers.add(componentEnhancers);
1199
1410
  });
1200
1411
  promises.push(
@@ -1412,41 +1623,30 @@ var EnhancerBuilder = class {
1412
1623
  }
1413
1624
  };
1414
1625
 
1415
- // src/utils/constants.ts
1416
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1417
- var CANVAS_TEST_TYPE = "$test";
1418
- var CANVAS_LOCALIZATION_TYPE = "$localization";
1419
- var CANVAS_INTENT_TAG_PARAM = "intentTag";
1420
- var CANVAS_LOCALE_TAG_PARAM = "locale";
1421
- var CANVAS_PERSONALIZE_SLOT = "pz";
1422
- var CANVAS_TEST_SLOT = "test";
1423
- var CANVAS_LOCALIZATION_SLOT = "localized";
1424
- var CANVAS_DRAFT_STATE = 0;
1425
- var CANVAS_PUBLISHED_STATE = 64;
1426
- var CANVAS_EDITOR_STATE = 63;
1427
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1428
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1429
- var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1430
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1431
- var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1432
- var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
1433
- var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1434
- var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
1435
- var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1436
- var IS_RENDERED_BY_UNIFORM_ATTRIBUTE = "data-is-rendered-by-uniform";
1437
- var PLACEHOLDER_ID = "placeholder";
1438
- var EMPTY_COMPOSITION = {
1439
- _id: "_empty_composition_id",
1440
- _name: "An empty composition used for contextual editing",
1441
- type: "_empty_composition_type"
1442
- };
1443
- var EDGE_MIN_CACHE_TTL = 15;
1444
- var EDGE_MAX_CACHE_TTL = 600;
1445
- var EDGE_DEFAULT_CACHE_TTL = 30;
1446
- var EDGE_CACHE_DISABLED = -1;
1447
- var EDGE_MIN_L2_CACHE_TTL_IN_HOURS = 1;
1448
- var EDGE_MAX_L2_CACHE_TTL_IN_HOURS = 4 * 7 * 24;
1449
- var EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
1626
+ // src/enhancement/getComponentJsonPointer.ts
1627
+ function getComponentJsonPointer(ancestorsAndSelf) {
1628
+ const path = [];
1629
+ for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1630
+ const currentLocation = ancestorsAndSelf[i];
1631
+ const parentLocation = ancestorsAndSelf[i + 1];
1632
+ if ("type" in currentLocation && currentLocation.type !== "slot") {
1633
+ if (currentLocation.type === "block") {
1634
+ const { fieldName: parameterName, blockIndex } = currentLocation;
1635
+ if (parameterName && blockIndex !== void 0) {
1636
+ const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
1637
+ path.push(`${noun}/${parameterName}/value/${blockIndex}`);
1638
+ }
1639
+ } else {
1640
+ }
1641
+ continue;
1642
+ }
1643
+ const { parentSlot, parentSlotIndex } = currentLocation;
1644
+ if (parentSlot && parentSlotIndex !== void 0) {
1645
+ path.push(`slots/${parentSlot}/${parentSlotIndex}`);
1646
+ }
1647
+ }
1648
+ return `/${path.join("/")}`;
1649
+ }
1450
1650
 
1451
1651
  // src/enhancement/localize.ts
1452
1652
  function extractLocales({ component }) {
@@ -1467,22 +1667,26 @@ function localize({
1467
1667
  composition,
1468
1668
  locale
1469
1669
  }) {
1470
- walkComponentTree(composition, (currentComponent, _componentContext, actions) => {
1471
- if (currentComponent.type === CANVAS_LOCALIZATION_TYPE) {
1472
- const locales = extractLocales({ component: currentComponent });
1473
- const resolvedLocale = typeof locale === "string" ? locale : locale({ component: currentComponent, locales });
1670
+ walkNodeTree(composition, ({ type, node, actions }) => {
1671
+ if (type !== "component") {
1672
+ actions.stopProcessingDescendants();
1673
+ return;
1674
+ }
1675
+ if (node.type === CANVAS_LOCALIZATION_TYPE) {
1676
+ const locales = extractLocales({ component: node });
1677
+ const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
1474
1678
  let replaceComponent;
1475
1679
  if (resolvedLocale) {
1476
1680
  replaceComponent = locales[resolvedLocale];
1477
1681
  }
1478
1682
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1479
1683
  const [first, ...rest] = replaceComponent;
1480
- actions.replaceComponent(first);
1684
+ actions.replace(first);
1481
1685
  if (rest.length) {
1482
1686
  actions.insertAfter(rest);
1483
1687
  }
1484
1688
  } else {
1485
- actions.removeComponent();
1689
+ actions.remove();
1486
1690
  }
1487
1691
  }
1488
1692
  });
@@ -1515,6 +1719,124 @@ var UniqueBatchEntries = class {
1515
1719
  }
1516
1720
  };
1517
1721
 
1722
+ // src/enhancement/walkComponentTree.ts
1723
+ function walkComponentTree(component, visitor, initialContext) {
1724
+ var _a;
1725
+ const componentQueue = [
1726
+ {
1727
+ ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
1728
+ context: initialContext
1729
+ }
1730
+ ];
1731
+ const childContexts = /* @__PURE__ */ new Map();
1732
+ do {
1733
+ const currentQueueEntry = componentQueue.pop();
1734
+ if (!currentQueueEntry)
1735
+ continue;
1736
+ const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1737
+ let visitDescendants = true;
1738
+ let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
1739
+ visitor(
1740
+ currentComponent.component,
1741
+ currentQueueEntry.ancestorsAndSelf,
1742
+ {
1743
+ replaceComponent: (replacementComponent) => {
1744
+ Object.assign(currentComponent.component, replacementComponent);
1745
+ const propertiesToCheck = [
1746
+ "parameters",
1747
+ "variant",
1748
+ "slots",
1749
+ "data",
1750
+ "_pattern",
1751
+ "_patternError"
1752
+ ];
1753
+ propertiesToCheck.forEach((property) => {
1754
+ if (!replacementComponent[property]) {
1755
+ delete currentComponent.component[property];
1756
+ }
1757
+ });
1758
+ },
1759
+ removeComponent: () => {
1760
+ const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
1761
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1762
+ if (parentSlot && typeof parentSlotIndex !== "undefined") {
1763
+ parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
1764
+ } else {
1765
+ throw new Error("Unable to delete composition.");
1766
+ }
1767
+ },
1768
+ insertAfter: (components) => {
1769
+ const componentsToInsert = Array.isArray(components) ? components : [components];
1770
+ const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
1771
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1772
+ if (parentSlot && typeof parentSlotIndex !== "undefined") {
1773
+ parentComponent.component.slots[parentSlot].splice(
1774
+ parentSlotIndex + 1,
1775
+ 0,
1776
+ ...componentsToInsert
1777
+ );
1778
+ componentQueue.unshift(
1779
+ ...componentsToInsert.map((enqueueingComponent) => ({
1780
+ ancestorsAndSelf: [
1781
+ {
1782
+ component: enqueueingComponent,
1783
+ parentSlot,
1784
+ get parentSlotIndex() {
1785
+ return parentComponent.component.slots[parentSlot].findIndex(
1786
+ (x) => x === enqueueingComponent
1787
+ );
1788
+ }
1789
+ },
1790
+ ...currentQueueEntry.ancestorsAndSelf
1791
+ ],
1792
+ context: descendantContext
1793
+ }))
1794
+ );
1795
+ } else {
1796
+ throw new Error("Unable to insert after a component not in a slot.");
1797
+ }
1798
+ },
1799
+ stopProcessingDescendants() {
1800
+ visitDescendants = false;
1801
+ },
1802
+ setDescendantsContext(context) {
1803
+ descendantContext = context;
1804
+ },
1805
+ setChildContext(child, context) {
1806
+ childContexts.set(child, context);
1807
+ }
1808
+ },
1809
+ descendantContext
1810
+ );
1811
+ const slots = currentComponent.component.slots;
1812
+ if (visitDescendants && slots) {
1813
+ const slotKeys = Object.keys(slots);
1814
+ for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1815
+ const slotKey = slotKeys[slotIndex];
1816
+ const components = slots[slotKey];
1817
+ for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
1818
+ const enqueueingComponent = components[componentIndex];
1819
+ componentQueue.push({
1820
+ ancestorsAndSelf: [
1821
+ {
1822
+ component: enqueueingComponent,
1823
+ parentSlot: slotKey,
1824
+ get parentSlotIndex() {
1825
+ return currentComponent.component.slots[slotKey].findIndex(
1826
+ (x) => x === enqueueingComponent
1827
+ );
1828
+ }
1829
+ },
1830
+ ...currentQueueEntry.ancestorsAndSelf
1831
+ ],
1832
+ context: descendantContext
1833
+ });
1834
+ }
1835
+ }
1836
+ }
1837
+ } while (componentQueue.length > 0);
1838
+ }
1839
+
1518
1840
  // src/utils/hash.ts
1519
1841
  var generateHash = ({
1520
1842
  composition,
@@ -1540,6 +1862,9 @@ var isSelectComponentMessage = (message) => {
1540
1862
  var isReadyMessage = (message) => {
1541
1863
  return message.type === "ready";
1542
1864
  };
1865
+ var isComponentActionMessage = (message) => {
1866
+ return message.type === "trigger-component-action";
1867
+ };
1543
1868
  var isUpdateCompositionMessage = (message) => {
1544
1869
  return message.type === "update-composition";
1545
1870
  };
@@ -1564,6 +1889,9 @@ var isTriggerCompositionActionMessage = (message) => {
1564
1889
  var isUpdatePreviewSettingsMessage = (message) => {
1565
1890
  return message.type === "update-preview-settings";
1566
1891
  };
1892
+ var isUpdateFeatureFlagsMessage = (message) => {
1893
+ return message.type === "update-feature-flags";
1894
+ };
1567
1895
  var isUpdateContextualEditingStateInternalMessage = (message) => {
1568
1896
  return message.type === "update-contextual-editing-state-internal";
1569
1897
  };
@@ -1573,6 +1901,12 @@ var isReportRenderedCompositionsMessage = (message) => {
1573
1901
  var isSelectParameterMessage = (message) => {
1574
1902
  return message.type === "select-parameter";
1575
1903
  };
1904
+ var isOpenParameterEditorMessage = (message) => {
1905
+ return message.type === "open-parameter-editor";
1906
+ };
1907
+ var isUpdateComponentReferencesMessage = (message) => {
1908
+ return message.type === "update-component-references";
1909
+ };
1576
1910
  var createCanvasChannel = ({
1577
1911
  listenTo,
1578
1912
  broadcastTo
@@ -1633,6 +1967,13 @@ var createCanvasChannel = ({
1633
1967
  };
1634
1968
  postMessage(message);
1635
1969
  };
1970
+ const triggerComponentAction = (options) => {
1971
+ const message = {
1972
+ ...options,
1973
+ type: "trigger-component-action"
1974
+ };
1975
+ postMessage(message);
1976
+ };
1636
1977
  const addComponent = (options) => {
1637
1978
  const message = {
1638
1979
  ...options,
@@ -1696,12 +2037,33 @@ var createCanvasChannel = ({
1696
2037
  };
1697
2038
  postMessage(message);
1698
2039
  };
2040
+ const openParameterEditor = (options) => {
2041
+ const message = {
2042
+ ...options,
2043
+ type: "open-parameter-editor"
2044
+ };
2045
+ postMessage(message);
2046
+ };
1699
2047
  const editorStateUpdated = () => {
1700
2048
  const message = {
1701
2049
  type: "editor-state-updated"
1702
2050
  };
1703
2051
  postMessage(message);
1704
2052
  };
2053
+ const updateComponentReferences = (options) => {
2054
+ const message = {
2055
+ ...options,
2056
+ type: "update-component-references"
2057
+ };
2058
+ postMessage(message);
2059
+ };
2060
+ const updateFeatureFlags = (options) => {
2061
+ const message = {
2062
+ ...options,
2063
+ type: "update-feature-flags"
2064
+ };
2065
+ postMessage(message);
2066
+ };
1705
2067
  const messageEventListener = (event) => {
1706
2068
  if (typeof event.data !== "string") {
1707
2069
  return;
@@ -1731,6 +2093,7 @@ var createCanvasChannel = ({
1731
2093
  return {
1732
2094
  ready,
1733
2095
  destroy,
2096
+ triggerComponentAction,
1734
2097
  selectComponent,
1735
2098
  updateComposition,
1736
2099
  updateCompositionInternal,
@@ -1741,10 +2104,13 @@ var createCanvasChannel = ({
1741
2104
  dismissPlaceholder,
1742
2105
  triggerCompositionAction,
1743
2106
  updatePreviewSettings,
2107
+ updateFeatureFlags,
1744
2108
  updateContextualEditingStateInternal,
1745
2109
  selectParameter,
2110
+ openParameterEditor,
1746
2111
  reportRenderedCompositions,
1747
- editorStateUpdated
2112
+ editorStateUpdated,
2113
+ updateComponentReferences
1748
2114
  };
1749
2115
  };
1750
2116
 
@@ -1868,21 +2234,6 @@ var createUniformApiEnhancer = ({ apiUrl }) => {
1868
2234
  };
1869
2235
  };
1870
2236
 
1871
- // src/utils/entryConverter.ts
1872
- function convertEntryToPutEntry(entry) {
1873
- return {
1874
- entry: {
1875
- type: entry.entry.type,
1876
- _dataResources: entry.entry._dataResources,
1877
- _id: entry.entry._id,
1878
- _slug: entry.entry._slug,
1879
- fields: entry.entry.fields
1880
- },
1881
- state: entry.state,
1882
- projectId: entry.projectId
1883
- };
1884
- }
1885
-
1886
2237
  // src/utils/getParameterAttributes.ts
1887
2238
  var ATTRIBUTE_COMPONENT_ID = "data-uniform-component-id";
1888
2239
  var ATTRIBUTE_PARAMETER_ID = "data-uniform-parameter-id";
@@ -1962,7 +2313,10 @@ var isComponentPlaceholderId = (id) => {
1962
2313
  }
1963
2314
  return id == null ? void 0 : id.startsWith(PLACEHOLDER_ID);
1964
2315
  };
1965
- var generateComponentPlaceholderId = (randomId) => {
2316
+ var generateComponentPlaceholderId = (randomId, sdkVersion) => {
2317
+ if (typeof sdkVersion === "undefined" || sdkVersion === 1) {
2318
+ return PLACEHOLDER_ID;
2319
+ }
1966
2320
  return `${PLACEHOLDER_ID}_${randomId}`;
1967
2321
  };
1968
2322
 
@@ -2161,6 +2515,7 @@ var CanvasClientError = import_api9.ApiClientError;
2161
2515
  ATTRIBUTE_PLACEHOLDER,
2162
2516
  ApiClientError,
2163
2517
  BatchEntry,
2518
+ CANVAS_BLOCK_PARAM_TYPE,
2164
2519
  CANVAS_DRAFT_STATE,
2165
2520
  CANVAS_EDITOR_STATE,
2166
2521
  CANVAS_ENRICHMENT_TAG_PARAM,
@@ -2200,6 +2555,7 @@ var CanvasClientError = import_api9.ApiClientError;
2200
2555
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
2201
2556
  PLACEHOLDER_ID,
2202
2557
  RouteClient,
2558
+ SECRET_QUERY_STRING_PARAM,
2203
2559
  UncachedCanvasClient,
2204
2560
  UncachedCategoryClient,
2205
2561
  UncachedContentClient,
@@ -2218,15 +2574,19 @@ var CanvasClientError = import_api9.ApiClientError;
2218
2574
  extractLocales,
2219
2575
  generateComponentPlaceholderId,
2220
2576
  generateHash,
2577
+ getBlockValue,
2221
2578
  getChannelName,
2222
2579
  getComponentJsonPointer,
2223
2580
  getComponentPath,
2224
2581
  getParameterAttributes,
2582
+ getPropertiesValue,
2225
2583
  isAddComponentMessage,
2226
2584
  isAllowedReferrer,
2585
+ isComponentActionMessage,
2227
2586
  isComponentPlaceholderId,
2228
2587
  isDismissPlaceholderMessage,
2229
2588
  isMovingComponentMessage,
2589
+ isOpenParameterEditorMessage,
2230
2590
  isReadyMessage,
2231
2591
  isReportRenderedCompositionsMessage,
2232
2592
  isSelectComponentMessage,
@@ -2234,9 +2594,11 @@ var CanvasClientError = import_api9.ApiClientError;
2234
2594
  isSystemComponentDefinition,
2235
2595
  isTriggerCompositionActionMessage,
2236
2596
  isUpdateComponentParameterMessage,
2597
+ isUpdateComponentReferencesMessage,
2237
2598
  isUpdateCompositionInternalMessage,
2238
2599
  isUpdateCompositionMessage,
2239
2600
  isUpdateContextualEditingStateInternalMessage,
2601
+ isUpdateFeatureFlagsMessage,
2240
2602
  isUpdatePreviewSettingsMessage,
2241
2603
  localize,
2242
2604
  mapSlotToPersonalizedVariations,
@@ -2245,5 +2607,6 @@ var CanvasClientError = import_api9.ApiClientError;
2245
2607
  parseVariableExpression,
2246
2608
  subscribeToComposition,
2247
2609
  unstable_CompositionRelationshipClient,
2248
- walkComponentTree
2610
+ walkComponentTree,
2611
+ walkNodeTree
2249
2612
  });