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