@uniformdev/canvas 19.49.1 → 19.49.4-alpha.67

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.esm.js CHANGED
@@ -922,13 +922,93 @@ function isPromise(obj) {
922
922
  return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
923
923
  }
924
924
 
925
- // src/enhancement/walkComponentTree.ts
926
- function walkComponentTree(component, visitor, initialContext) {
927
- var _a;
925
+ // src/enhancement/getComponentPath.ts
926
+ function getComponentPath(ancestorsAndSelf) {
927
+ const path = [];
928
+ for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
929
+ const currentLocation = ancestorsAndSelf[i];
930
+ const parentLocation = ancestorsAndSelf[i + 1];
931
+ if ("type" in currentLocation && currentLocation.type !== "slot") {
932
+ if (currentLocation.type === "block") {
933
+ const { fieldName, blockIndex } = currentLocation;
934
+ if (fieldName && blockIndex !== void 0) {
935
+ const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
936
+ path.push(`${noun}.${fieldName}.value[${blockIndex}]`);
937
+ }
938
+ } else {
939
+ }
940
+ continue;
941
+ }
942
+ const { parentSlot, parentSlotIndex } = currentLocation;
943
+ if (parentSlot && parentSlotIndex !== void 0) {
944
+ path.push(`${parentSlot}[${parentSlotIndex}]`);
945
+ }
946
+ }
947
+ return `.${path.join(".")}`;
948
+ }
949
+
950
+ // src/utils/constants.ts
951
+ var CANVAS_PERSONALIZE_TYPE = "$personalization";
952
+ var CANVAS_TEST_TYPE = "$test";
953
+ var CANVAS_LOCALIZATION_TYPE = "$localization";
954
+ var CANVAS_INTENT_TAG_PARAM = "intentTag";
955
+ var CANVAS_LOCALE_TAG_PARAM = "locale";
956
+ var CANVAS_BLOCK_PARAM_TYPE = "$block";
957
+ var CANVAS_PERSONALIZE_SLOT = "pz";
958
+ var CANVAS_TEST_SLOT = "test";
959
+ var CANVAS_LOCALIZATION_SLOT = "localized";
960
+ var CANVAS_DRAFT_STATE = 0;
961
+ var CANVAS_PUBLISHED_STATE = 64;
962
+ var CANVAS_EDITOR_STATE = 63;
963
+ var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
964
+ var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
965
+ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
966
+ var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
967
+ var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
968
+ var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
969
+ var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
970
+ var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
971
+ var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
972
+ var IS_RENDERED_BY_UNIFORM_ATTRIBUTE = "data-is-rendered-by-uniform";
973
+ var PLACEHOLDER_ID = "placeholder";
974
+ var EMPTY_COMPOSITION = {
975
+ _id: "_empty_composition_id",
976
+ _name: "An empty composition used for contextual editing",
977
+ type: "_empty_composition_type"
978
+ };
979
+ var EDGE_MIN_CACHE_TTL = 15;
980
+ var EDGE_MAX_CACHE_TTL = 600;
981
+ var EDGE_DEFAULT_CACHE_TTL = 30;
982
+ var EDGE_CACHE_DISABLED = -1;
983
+ var EDGE_MIN_L2_CACHE_TTL_IN_HOURS = 1;
984
+ var EDGE_MAX_L2_CACHE_TTL_IN_HOURS = 4 * 7 * 24;
985
+ var EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
986
+
987
+ // src/utils/entryConverter.ts
988
+ function convertEntryToPutEntry(entry) {
989
+ return {
990
+ entry: {
991
+ type: entry.entry.type,
992
+ _dataResources: entry.entry._dataResources,
993
+ _id: entry.entry._id,
994
+ _slug: entry.entry._slug,
995
+ fields: entry.entry.fields
996
+ },
997
+ state: entry.state,
998
+ projectId: entry.projectId
999
+ };
1000
+ }
1001
+ function getPropertiesValue(entity) {
1002
+ return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
1003
+ }
1004
+
1005
+ // src/enhancement/walkNodeTree.ts
1006
+ function walkNodeTree(node, visitor, options) {
1007
+ var _a, _b;
928
1008
  const componentQueue = [
929
1009
  {
930
- ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
931
- context: initialContext
1010
+ ancestorsAndSelf: Array.isArray(node) ? node : [{ node, type: "root" }],
1011
+ context: options == null ? void 0 : options.initialContext
932
1012
  }
933
1013
  ];
934
1014
  const childContexts = /* @__PURE__ */ new Map();
@@ -938,81 +1018,182 @@ function walkComponentTree(component, visitor, initialContext) {
938
1018
  continue;
939
1019
  const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
940
1020
  let visitDescendants = true;
941
- let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
942
- visitor(
943
- currentComponent.component,
944
- currentQueueEntry.ancestorsAndSelf,
945
- {
946
- replaceComponent: (replacementComponent) => {
947
- Object.assign(currentComponent.component, replacementComponent);
948
- const propertiesToCheck = [
949
- "parameters",
950
- "variant",
951
- "slots",
952
- "data",
953
- "_pattern",
954
- "_patternError"
955
- ];
956
- propertiesToCheck.forEach((property) => {
957
- if (!replacementComponent[property]) {
958
- delete currentComponent.component[property];
1021
+ let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
1022
+ let visitorInfo;
1023
+ if (currentComponent.type === "root" || currentComponent.type === "slot") {
1024
+ visitorInfo = {
1025
+ type: "component",
1026
+ node: currentComponent.node,
1027
+ ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
1028
+ actions: {
1029
+ replace: (replacementComponent) => {
1030
+ Object.assign(currentComponent.node, replacementComponent);
1031
+ const propertiesToCheck = [
1032
+ "parameters",
1033
+ "variant",
1034
+ "slots",
1035
+ "data",
1036
+ "_pattern",
1037
+ "_patternError",
1038
+ "_dataResources",
1039
+ "_overridability",
1040
+ "_overrides",
1041
+ "_patternDataResources"
1042
+ ];
1043
+ propertiesToCheck.forEach((property) => {
1044
+ if (!replacementComponent[property]) {
1045
+ delete currentComponent.node[property];
1046
+ }
1047
+ });
1048
+ },
1049
+ remove: () => {
1050
+ const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
1051
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1052
+ if (currentComponentLocation.type === "root") {
1053
+ throw new Error("Unable to delete root node.");
959
1054
  }
960
- });
961
- },
962
- removeComponent: () => {
963
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
964
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
965
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
966
- parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
967
- } else {
968
- throw new Error("Unable to delete composition.");
1055
+ if (currentComponentLocation.type === "slot") {
1056
+ const { parentSlot, parentSlotIndex } = currentComponentLocation;
1057
+ parentComponent.node.slots[parentSlot].splice(parentSlotIndex, 1);
1058
+ } else {
1059
+ throw new Error("Unknown node type");
1060
+ }
1061
+ },
1062
+ insertAfter: (nodes) => {
1063
+ const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
1064
+ const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
1065
+ if (currentNodeInfo.type === "root") {
1066
+ throw new Error("Unable to insert after root node.");
1067
+ }
1068
+ if (currentNodeInfo.type === "slot") {
1069
+ const { parentSlot, parentSlotIndex } = currentNodeInfo;
1070
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1071
+ if (parentSlot && typeof parentSlotIndex !== "undefined") {
1072
+ parentComponent.node.slots[parentSlot].splice(
1073
+ parentSlotIndex + 1,
1074
+ 0,
1075
+ ...nodesToInsert
1076
+ );
1077
+ componentQueue.unshift(
1078
+ ...nodesToInsert.map((enqueueingComponent) => ({
1079
+ type: "slot",
1080
+ ancestorsAndSelf: [
1081
+ {
1082
+ type: "slot",
1083
+ node: enqueueingComponent,
1084
+ parentSlot,
1085
+ get parentSlotIndex() {
1086
+ return parentComponent.node.slots[parentSlot].findIndex(
1087
+ (x) => x === enqueueingComponent
1088
+ );
1089
+ }
1090
+ },
1091
+ // slice removes 'self' since we are inserting a peer of self
1092
+ ...currentQueueEntry.ancestorsAndSelf.slice(1)
1093
+ ],
1094
+ context: descendantContext
1095
+ }))
1096
+ );
1097
+ }
1098
+ } else {
1099
+ throw new Error("Unknown type");
1100
+ }
1101
+ },
1102
+ stopProcessingDescendants() {
1103
+ visitDescendants = false;
1104
+ },
1105
+ setDescendantsContext(context) {
1106
+ descendantContext = context;
1107
+ },
1108
+ setChildContext(child, context) {
1109
+ childContexts.set(child, context);
969
1110
  }
970
1111
  },
971
- insertAfter: (components) => {
972
- const componentsToInsert = Array.isArray(components) ? components : [components];
973
- const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
974
- const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
975
- if (parentSlot && typeof parentSlotIndex !== "undefined") {
976
- parentComponent.component.slots[parentSlot].splice(
977
- parentSlotIndex + 1,
978
- 0,
979
- ...componentsToInsert
980
- );
981
- componentQueue.unshift(
982
- ...componentsToInsert.map((enqueueingComponent) => ({
983
- ancestorsAndSelf: [
984
- {
985
- component: enqueueingComponent,
986
- parentSlot,
987
- get parentSlotIndex() {
988
- return parentComponent.component.slots[parentSlot].findIndex(
989
- (x) => x === enqueueingComponent
990
- );
991
- }
992
- },
993
- ...currentQueueEntry.ancestorsAndSelf
994
- ],
995
- context: descendantContext
996
- }))
997
- );
998
- } else {
999
- throw new Error("Unable to insert after a component not in a slot.");
1112
+ context: descendantContext
1113
+ };
1114
+ } else {
1115
+ visitorInfo = {
1116
+ type: "entry",
1117
+ node: currentComponent.node,
1118
+ ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
1119
+ actions: {
1120
+ replace: (replacementNode) => {
1121
+ Object.assign(currentComponent.node, replacementNode);
1122
+ const propertiesToCheck = ["fields", "_dataResources", "_author"];
1123
+ propertiesToCheck.forEach((property) => {
1124
+ if (!replacementNode[property]) {
1125
+ delete currentComponent.node[property];
1126
+ }
1127
+ });
1128
+ },
1129
+ remove: () => {
1130
+ const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
1131
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1132
+ if (currentComponentLocation.type === "block") {
1133
+ const { fieldName, blockIndex } = currentComponentLocation;
1134
+ const blockValue = getBlockValue(parentComponent.node, fieldName);
1135
+ blockValue.splice(blockIndex, 1);
1136
+ if (blockValue.length === 0) {
1137
+ const properties2 = getPropertiesValue(parentComponent.node);
1138
+ delete properties2[fieldName];
1139
+ }
1140
+ } else {
1141
+ throw new Error("Unknown node type");
1142
+ }
1143
+ },
1144
+ insertAfter: (nodes) => {
1145
+ const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
1146
+ if (currentNodeInfo.type !== "block") {
1147
+ throw new Error("Unknown type");
1148
+ }
1149
+ const { fieldName, blockIndex } = currentNodeInfo;
1150
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1151
+ const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
1152
+ if (fieldName && typeof blockIndex !== "undefined") {
1153
+ getPropertiesValue(parentComponent.node)[fieldName].value.splice(
1154
+ blockIndex + 1,
1155
+ 0,
1156
+ ...nodesToInsert
1157
+ );
1158
+ componentQueue.unshift(
1159
+ ...nodesToInsert.map((enqueueingComponent) => ({
1160
+ ancestorsAndSelf: [
1161
+ {
1162
+ type: "block",
1163
+ node: enqueueingComponent,
1164
+ fieldName,
1165
+ get blockIndex() {
1166
+ const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
1167
+ return parentArray.findIndex((x) => x === enqueueingComponent);
1168
+ }
1169
+ },
1170
+ // slice removes 'self' since we are inserting a peer of self
1171
+ ...currentQueueEntry.ancestorsAndSelf.slice(1)
1172
+ ],
1173
+ context: descendantContext
1174
+ }))
1175
+ );
1176
+ }
1177
+ },
1178
+ stopProcessingDescendants() {
1179
+ visitDescendants = false;
1180
+ },
1181
+ setDescendantsContext(context) {
1182
+ descendantContext = context;
1183
+ },
1184
+ setChildContext(child, context) {
1185
+ childContexts.set(child, context);
1000
1186
  }
1001
1187
  },
1002
- stopProcessingDescendants() {
1003
- visitDescendants = false;
1004
- },
1005
- setDescendantsContext(context) {
1006
- descendantContext = context;
1007
- },
1008
- setChildContext(child, context) {
1009
- childContexts.set(child, context);
1010
- }
1011
- },
1012
- descendantContext
1013
- );
1014
- const slots = currentComponent.component.slots;
1015
- if (visitDescendants && slots) {
1188
+ context: descendantContext
1189
+ };
1190
+ }
1191
+ visitor(visitorInfo);
1192
+ if (!visitDescendants) {
1193
+ continue;
1194
+ }
1195
+ const slots = "slots" in currentComponent.node && currentComponent.node.slots;
1196
+ if (slots) {
1016
1197
  const slotKeys = Object.keys(slots);
1017
1198
  for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1018
1199
  const slotKey = slotKeys[slotIndex];
@@ -1022,10 +1203,11 @@ function walkComponentTree(component, visitor, initialContext) {
1022
1203
  componentQueue.push({
1023
1204
  ancestorsAndSelf: [
1024
1205
  {
1025
- component: enqueueingComponent,
1206
+ type: "slot",
1207
+ node: enqueueingComponent,
1026
1208
  parentSlot: slotKey,
1027
1209
  get parentSlotIndex() {
1028
- return currentComponent.component.slots[slotKey].findIndex(
1210
+ return currentComponent.node.slots[slotKey].findIndex(
1029
1211
  (x) => x === enqueueingComponent
1030
1212
  );
1031
1213
  }
@@ -1037,27 +1219,44 @@ function walkComponentTree(component, visitor, initialContext) {
1037
1219
  }
1038
1220
  }
1039
1221
  }
1040
- } while (componentQueue.length > 0);
1041
- }
1042
- function getComponentPath(ancestorsAndSelf) {
1043
- const path = [];
1044
- for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1045
- const { parentSlot, parentSlotIndex } = ancestorsAndSelf[i];
1046
- if (parentSlot && parentSlotIndex !== void 0) {
1047
- path.push(`${parentSlot}[${parentSlotIndex}]`);
1222
+ const properties = getPropertiesValue(currentComponent.node);
1223
+ if (properties) {
1224
+ const propertyEntries = Object.entries(properties);
1225
+ for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1226
+ const [propKey, propObject] = propertyEntries[propIndex];
1227
+ if (propObject.type !== CANVAS_BLOCK_PARAM_TYPE)
1228
+ continue;
1229
+ const blocks = (_b = propObject.value) != null ? _b : [];
1230
+ for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
1231
+ const enqueueingBlock = blocks[blockIndex];
1232
+ componentQueue.push({
1233
+ ancestorsAndSelf: [
1234
+ {
1235
+ type: "block",
1236
+ node: enqueueingBlock,
1237
+ fieldName: propKey,
1238
+ get blockIndex() {
1239
+ return getBlockValue(currentComponent.node, propKey).findIndex(
1240
+ (x) => x === enqueueingBlock
1241
+ );
1242
+ }
1243
+ },
1244
+ ...currentQueueEntry.ancestorsAndSelf
1245
+ ],
1246
+ context: descendantContext
1247
+ });
1248
+ }
1249
+ }
1048
1250
  }
1049
- }
1050
- return `.${path.join(".")}`;
1251
+ } while (componentQueue.length > 0);
1051
1252
  }
1052
- function getComponentJsonPointer(ancestorsAndSelf, { withSlots = false } = {}) {
1053
- const path = [];
1054
- for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1055
- const { parentSlot, parentSlotIndex } = ancestorsAndSelf[i];
1056
- if (parentSlot && parentSlotIndex !== void 0) {
1057
- path.push(`${parentSlot}/${parentSlotIndex}`);
1058
- }
1253
+ function getBlockValue(component, parameterName) {
1254
+ var _a;
1255
+ const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
1256
+ if ((parameter == null ? void 0 : parameter.value) && parameter.type === CANVAS_BLOCK_PARAM_TYPE && Array.isArray(parameter.value)) {
1257
+ return parameter.value;
1059
1258
  }
1060
- return withSlots ? `/slots/${path.join("/slots/")}` : `/${path.join("/")}`;
1259
+ return [];
1061
1260
  }
1062
1261
 
1063
1262
  // src/enhancement/enhance.ts
@@ -1077,19 +1276,21 @@ async function enhance({
1077
1276
  const promises = [];
1078
1277
  const usedComponentEnhancers = /* @__PURE__ */ new Set();
1079
1278
  const usedParameterEnhancers = /* @__PURE__ */ new Set();
1080
- walkComponentTree(composition, (currentComponent, componentContext) => {
1279
+ walkNodeTree(composition, ({ type, node, ancestorsAndSelf, actions }) => {
1081
1280
  var _a;
1082
- Object.entries((_a = currentComponent.parameters) != null ? _a : {}).forEach(([paramName, paramValue]) => {
1083
- const enhancer = enhancers.resolveParameterEnhancer(currentComponent, paramName, paramValue);
1281
+ if (type !== "component") {
1282
+ actions.stopProcessingDescendants();
1283
+ return;
1284
+ }
1285
+ Object.entries((_a = node.parameters) != null ? _a : {}).forEach(([paramName, paramValue]) => {
1286
+ const enhancer = enhancers.resolveParameterEnhancer(node, paramName, paramValue);
1084
1287
  if (enhancer) {
1085
1288
  usedParameterEnhancers.add(enhancer);
1086
- promises.push(
1087
- enhanceParameter(currentComponent, componentContext, paramName, paramValue, enhancer, context)
1088
- );
1289
+ promises.push(enhanceParameter(node, ancestorsAndSelf, paramName, paramValue, enhancer, context));
1089
1290
  }
1090
1291
  });
1091
- const componentEnhancers = enhancers.resolveComponentEnhancers(currentComponent);
1092
- promises.push(enhanceComponent(currentComponent, componentContext, componentEnhancers, context));
1292
+ const componentEnhancers = enhancers.resolveComponentEnhancers(node);
1293
+ promises.push(enhanceComponent(node, ancestorsAndSelf, componentEnhancers, context));
1093
1294
  usedComponentEnhancers.add(componentEnhancers);
1094
1295
  });
1095
1296
  promises.push(
@@ -1307,41 +1508,30 @@ var EnhancerBuilder = class {
1307
1508
  }
1308
1509
  };
1309
1510
 
1310
- // src/utils/constants.ts
1311
- var CANVAS_PERSONALIZE_TYPE = "$personalization";
1312
- var CANVAS_TEST_TYPE = "$test";
1313
- var CANVAS_LOCALIZATION_TYPE = "$localization";
1314
- var CANVAS_INTENT_TAG_PARAM = "intentTag";
1315
- var CANVAS_LOCALE_TAG_PARAM = "locale";
1316
- var CANVAS_PERSONALIZE_SLOT = "pz";
1317
- var CANVAS_TEST_SLOT = "test";
1318
- var CANVAS_LOCALIZATION_SLOT = "localized";
1319
- var CANVAS_DRAFT_STATE = 0;
1320
- var CANVAS_PUBLISHED_STATE = 64;
1321
- var CANVAS_EDITOR_STATE = 63;
1322
- var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1323
- var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1324
- var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1325
- var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1326
- var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1327
- var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
1328
- var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1329
- var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
1330
- var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
1331
- var IS_RENDERED_BY_UNIFORM_ATTRIBUTE = "data-is-rendered-by-uniform";
1332
- var PLACEHOLDER_ID = "placeholder";
1333
- var EMPTY_COMPOSITION = {
1334
- _id: "_empty_composition_id",
1335
- _name: "An empty composition used for contextual editing",
1336
- type: "_empty_composition_type"
1337
- };
1338
- var EDGE_MIN_CACHE_TTL = 15;
1339
- var EDGE_MAX_CACHE_TTL = 600;
1340
- var EDGE_DEFAULT_CACHE_TTL = 30;
1341
- var EDGE_CACHE_DISABLED = -1;
1342
- var EDGE_MIN_L2_CACHE_TTL_IN_HOURS = 1;
1343
- var EDGE_MAX_L2_CACHE_TTL_IN_HOURS = 4 * 7 * 24;
1344
- var EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS = 24;
1511
+ // src/enhancement/getComponentJsonPointer.ts
1512
+ function getComponentJsonPointer(ancestorsAndSelf) {
1513
+ const path = [];
1514
+ for (let i = ancestorsAndSelf.length - 1; i >= 0; i--) {
1515
+ const currentLocation = ancestorsAndSelf[i];
1516
+ const parentLocation = ancestorsAndSelf[i + 1];
1517
+ if ("type" in currentLocation && currentLocation.type !== "slot") {
1518
+ if (currentLocation.type === "block") {
1519
+ const { fieldName: parameterName, blockIndex } = currentLocation;
1520
+ if (parameterName && blockIndex !== void 0) {
1521
+ const noun = parentLocation && "type" in parentLocation && parentLocation.type === "block" ? "fields" : "parameters";
1522
+ path.push(`${noun}/${parameterName}/value/${blockIndex}`);
1523
+ }
1524
+ } else {
1525
+ }
1526
+ continue;
1527
+ }
1528
+ const { parentSlot, parentSlotIndex } = currentLocation;
1529
+ if (parentSlot && parentSlotIndex !== void 0) {
1530
+ path.push(`slots/${parentSlot}/${parentSlotIndex}`);
1531
+ }
1532
+ }
1533
+ return `/${path.join("/")}`;
1534
+ }
1345
1535
 
1346
1536
  // src/enhancement/localize.ts
1347
1537
  function extractLocales({ component }) {
@@ -1362,22 +1552,26 @@ function localize({
1362
1552
  composition,
1363
1553
  locale
1364
1554
  }) {
1365
- walkComponentTree(composition, (currentComponent, _componentContext, actions) => {
1366
- if (currentComponent.type === CANVAS_LOCALIZATION_TYPE) {
1367
- const locales = extractLocales({ component: currentComponent });
1368
- const resolvedLocale = typeof locale === "string" ? locale : locale({ component: currentComponent, locales });
1555
+ walkNodeTree(composition, ({ type, node, actions }) => {
1556
+ if (type !== "component") {
1557
+ actions.stopProcessingDescendants();
1558
+ return;
1559
+ }
1560
+ if (node.type === CANVAS_LOCALIZATION_TYPE) {
1561
+ const locales = extractLocales({ component: node });
1562
+ const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
1369
1563
  let replaceComponent;
1370
1564
  if (resolvedLocale) {
1371
1565
  replaceComponent = locales[resolvedLocale];
1372
1566
  }
1373
1567
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1374
1568
  const [first, ...rest] = replaceComponent;
1375
- actions.replaceComponent(first);
1569
+ actions.replace(first);
1376
1570
  if (rest.length) {
1377
1571
  actions.insertAfter(rest);
1378
1572
  }
1379
1573
  } else {
1380
- actions.removeComponent();
1574
+ actions.remove();
1381
1575
  }
1382
1576
  }
1383
1577
  });
@@ -1410,6 +1604,124 @@ var UniqueBatchEntries = class {
1410
1604
  }
1411
1605
  };
1412
1606
 
1607
+ // src/enhancement/walkComponentTree.ts
1608
+ function walkComponentTree(component, visitor, initialContext) {
1609
+ var _a;
1610
+ const componentQueue = [
1611
+ {
1612
+ ancestorsAndSelf: [{ component, parentSlot: void 0, parentSlotIndex: void 0 }],
1613
+ context: initialContext
1614
+ }
1615
+ ];
1616
+ const childContexts = /* @__PURE__ */ new Map();
1617
+ do {
1618
+ const currentQueueEntry = componentQueue.pop();
1619
+ if (!currentQueueEntry)
1620
+ continue;
1621
+ const currentComponent = currentQueueEntry.ancestorsAndSelf[0];
1622
+ let visitDescendants = true;
1623
+ let descendantContext = (_a = childContexts.get(currentComponent.component)) != null ? _a : currentQueueEntry.context;
1624
+ visitor(
1625
+ currentComponent.component,
1626
+ currentQueueEntry.ancestorsAndSelf,
1627
+ {
1628
+ replaceComponent: (replacementComponent) => {
1629
+ Object.assign(currentComponent.component, replacementComponent);
1630
+ const propertiesToCheck = [
1631
+ "parameters",
1632
+ "variant",
1633
+ "slots",
1634
+ "data",
1635
+ "_pattern",
1636
+ "_patternError"
1637
+ ];
1638
+ propertiesToCheck.forEach((property) => {
1639
+ if (!replacementComponent[property]) {
1640
+ delete currentComponent.component[property];
1641
+ }
1642
+ });
1643
+ },
1644
+ removeComponent: () => {
1645
+ const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
1646
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1647
+ if (parentSlot && typeof parentSlotIndex !== "undefined") {
1648
+ parentComponent.component.slots[parentSlot].splice(parentSlotIndex, 1);
1649
+ } else {
1650
+ throw new Error("Unable to delete composition.");
1651
+ }
1652
+ },
1653
+ insertAfter: (components) => {
1654
+ const componentsToInsert = Array.isArray(components) ? components : [components];
1655
+ const { parentSlot, parentSlotIndex } = currentQueueEntry.ancestorsAndSelf[0];
1656
+ const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
1657
+ if (parentSlot && typeof parentSlotIndex !== "undefined") {
1658
+ parentComponent.component.slots[parentSlot].splice(
1659
+ parentSlotIndex + 1,
1660
+ 0,
1661
+ ...componentsToInsert
1662
+ );
1663
+ componentQueue.unshift(
1664
+ ...componentsToInsert.map((enqueueingComponent) => ({
1665
+ ancestorsAndSelf: [
1666
+ {
1667
+ component: enqueueingComponent,
1668
+ parentSlot,
1669
+ get parentSlotIndex() {
1670
+ return parentComponent.component.slots[parentSlot].findIndex(
1671
+ (x) => x === enqueueingComponent
1672
+ );
1673
+ }
1674
+ },
1675
+ ...currentQueueEntry.ancestorsAndSelf
1676
+ ],
1677
+ context: descendantContext
1678
+ }))
1679
+ );
1680
+ } else {
1681
+ throw new Error("Unable to insert after a component not in a slot.");
1682
+ }
1683
+ },
1684
+ stopProcessingDescendants() {
1685
+ visitDescendants = false;
1686
+ },
1687
+ setDescendantsContext(context) {
1688
+ descendantContext = context;
1689
+ },
1690
+ setChildContext(child, context) {
1691
+ childContexts.set(child, context);
1692
+ }
1693
+ },
1694
+ descendantContext
1695
+ );
1696
+ const slots = currentComponent.component.slots;
1697
+ if (visitDescendants && slots) {
1698
+ const slotKeys = Object.keys(slots);
1699
+ for (let slotIndex = slotKeys.length - 1; slotIndex >= 0; slotIndex--) {
1700
+ const slotKey = slotKeys[slotIndex];
1701
+ const components = slots[slotKey];
1702
+ for (let componentIndex = components.length - 1; componentIndex >= 0; componentIndex--) {
1703
+ const enqueueingComponent = components[componentIndex];
1704
+ componentQueue.push({
1705
+ ancestorsAndSelf: [
1706
+ {
1707
+ component: enqueueingComponent,
1708
+ parentSlot: slotKey,
1709
+ get parentSlotIndex() {
1710
+ return currentComponent.component.slots[slotKey].findIndex(
1711
+ (x) => x === enqueueingComponent
1712
+ );
1713
+ }
1714
+ },
1715
+ ...currentQueueEntry.ancestorsAndSelf
1716
+ ],
1717
+ context: descendantContext
1718
+ });
1719
+ }
1720
+ }
1721
+ }
1722
+ } while (componentQueue.length > 0);
1723
+ }
1724
+
1413
1725
  // src/utils/hash.ts
1414
1726
  var generateHash = ({
1415
1727
  composition,
@@ -1435,6 +1747,9 @@ var isSelectComponentMessage = (message) => {
1435
1747
  var isReadyMessage = (message) => {
1436
1748
  return message.type === "ready";
1437
1749
  };
1750
+ var isComponentActionMessage = (message) => {
1751
+ return message.type === "trigger-component-action";
1752
+ };
1438
1753
  var isUpdateCompositionMessage = (message) => {
1439
1754
  return message.type === "update-composition";
1440
1755
  };
@@ -1468,6 +1783,12 @@ var isReportRenderedCompositionsMessage = (message) => {
1468
1783
  var isSelectParameterMessage = (message) => {
1469
1784
  return message.type === "select-parameter";
1470
1785
  };
1786
+ var isOpenParameterEditorMessage = (message) => {
1787
+ return message.type === "open-parameter-editor";
1788
+ };
1789
+ var isUpdateComponentReferencesMessage = (message) => {
1790
+ return message.type === "update-component-references";
1791
+ };
1471
1792
  var createCanvasChannel = ({
1472
1793
  listenTo,
1473
1794
  broadcastTo
@@ -1528,6 +1849,13 @@ var createCanvasChannel = ({
1528
1849
  };
1529
1850
  postMessage(message);
1530
1851
  };
1852
+ const triggerComponentAction = (options) => {
1853
+ const message = {
1854
+ ...options,
1855
+ type: "trigger-component-action"
1856
+ };
1857
+ postMessage(message);
1858
+ };
1531
1859
  const addComponent = (options) => {
1532
1860
  const message = {
1533
1861
  ...options,
@@ -1570,12 +1898,7 @@ var createCanvasChannel = ({
1570
1898
  };
1571
1899
  postMessage(message);
1572
1900
  };
1573
- const updateContextualEditingStateInternal = (options) => {
1574
- const message = {
1575
- ...options,
1576
- type: "update-contextual-editing-state-internal"
1577
- };
1578
- postMessage(message);
1901
+ const updateContextualEditingStateInternal = () => {
1579
1902
  };
1580
1903
  const reportRenderedCompositions = (options) => {
1581
1904
  const message = {
@@ -1591,12 +1914,26 @@ var createCanvasChannel = ({
1591
1914
  };
1592
1915
  postMessage(message);
1593
1916
  };
1917
+ const openParameterEditor = (options) => {
1918
+ const message = {
1919
+ ...options,
1920
+ type: "open-parameter-editor"
1921
+ };
1922
+ postMessage(message);
1923
+ };
1594
1924
  const editorStateUpdated = () => {
1595
1925
  const message = {
1596
1926
  type: "editor-state-updated"
1597
1927
  };
1598
1928
  postMessage(message);
1599
1929
  };
1930
+ const updateComponentReferences = (options) => {
1931
+ const message = {
1932
+ ...options,
1933
+ type: "update-component-references"
1934
+ };
1935
+ postMessage(message);
1936
+ };
1600
1937
  const messageEventListener = (event) => {
1601
1938
  if (typeof event.data !== "string") {
1602
1939
  return;
@@ -1626,6 +1963,7 @@ var createCanvasChannel = ({
1626
1963
  return {
1627
1964
  ready,
1628
1965
  destroy,
1966
+ triggerComponentAction,
1629
1967
  selectComponent,
1630
1968
  updateComposition,
1631
1969
  updateCompositionInternal,
@@ -1638,8 +1976,10 @@ var createCanvasChannel = ({
1638
1976
  updatePreviewSettings,
1639
1977
  updateContextualEditingStateInternal,
1640
1978
  selectParameter,
1979
+ openParameterEditor,
1641
1980
  reportRenderedCompositions,
1642
- editorStateUpdated
1981
+ editorStateUpdated,
1982
+ updateComponentReferences
1643
1983
  };
1644
1984
  };
1645
1985
 
@@ -1830,6 +2170,17 @@ function mapSlotToTestVariations(slot) {
1830
2170
  });
1831
2171
  }
1832
2172
 
2173
+ // src/utils/placeholder.ts
2174
+ var isComponentPlaceholderId = (id) => {
2175
+ if (id === PLACEHOLDER_ID) {
2176
+ return true;
2177
+ }
2178
+ return id == null ? void 0 : id.startsWith(PLACEHOLDER_ID);
2179
+ };
2180
+ var generateComponentPlaceholderId = (randomId) => {
2181
+ return `${PLACEHOLDER_ID}_${randomId}`;
2182
+ };
2183
+
1833
2184
  // src/utils/variables/parseVariableExpression.ts
1834
2185
  var escapeCharacter = "\\";
1835
2186
  var variablePrefix = "${";
@@ -1965,7 +2316,15 @@ function bindVariablesToObjectRecursive({
1965
2316
  boundCount += bindResult.boundCount;
1966
2317
  draft[property] = bindResult.result;
1967
2318
  if (bindResult.errors) {
1968
- errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
2319
+ errors.push(
2320
+ ...bindResult.errors.map((e) => {
2321
+ if (typeof e === "string") {
2322
+ return `${currentObjectPath}: ${e}`;
2323
+ }
2324
+ e.message = `${currentObjectPath}: ${e.message}`;
2325
+ return e;
2326
+ })
2327
+ );
1969
2328
  }
1970
2329
  }
1971
2330
  return;
@@ -2016,6 +2375,7 @@ export {
2016
2375
  ATTRIBUTE_PLACEHOLDER,
2017
2376
  ApiClientError2 as ApiClientError,
2018
2377
  BatchEntry,
2378
+ CANVAS_BLOCK_PARAM_TYPE,
2019
2379
  CANVAS_DRAFT_STATE,
2020
2380
  CANVAS_EDITOR_STATE,
2021
2381
  CANVAS_ENRICHMENT_TAG_PARAM,
@@ -2062,6 +2422,7 @@ export {
2062
2422
  bindVariables,
2063
2423
  bindVariablesToObject,
2064
2424
  compose,
2425
+ convertEntryToPutEntry,
2065
2426
  createBatchEnhancer,
2066
2427
  createCanvasChannel,
2067
2428
  createEventBus,
@@ -2070,14 +2431,20 @@ export {
2070
2431
  createVariableReference,
2071
2432
  enhance,
2072
2433
  extractLocales,
2434
+ generateComponentPlaceholderId,
2073
2435
  generateHash,
2436
+ getBlockValue,
2074
2437
  getChannelName,
2075
2438
  getComponentJsonPointer,
2076
2439
  getComponentPath,
2077
2440
  getParameterAttributes,
2441
+ getPropertiesValue,
2078
2442
  isAddComponentMessage,
2443
+ isComponentActionMessage,
2444
+ isComponentPlaceholderId,
2079
2445
  isDismissPlaceholderMessage,
2080
2446
  isMovingComponentMessage,
2447
+ isOpenParameterEditorMessage,
2081
2448
  isReadyMessage,
2082
2449
  isReportRenderedCompositionsMessage,
2083
2450
  isSelectComponentMessage,
@@ -2085,6 +2452,7 @@ export {
2085
2452
  isSystemComponentDefinition,
2086
2453
  isTriggerCompositionActionMessage,
2087
2454
  isUpdateComponentParameterMessage,
2455
+ isUpdateComponentReferencesMessage,
2088
2456
  isUpdateCompositionInternalMessage,
2089
2457
  isUpdateCompositionMessage,
2090
2458
  isUpdateContextualEditingStateInternalMessage,
@@ -2096,5 +2464,6 @@ export {
2096
2464
  parseVariableExpression,
2097
2465
  subscribeToComposition,
2098
2466
  unstable_CompositionRelationshipClient,
2099
- walkComponentTree
2467
+ walkComponentTree,
2468
+ walkNodeTree
2100
2469
  };