@uniformdev/canvas 19.79.1-alpha.11 → 19.79.1-alpha.18

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
@@ -45,7 +45,7 @@ var __privateAdd = (obj, member, value) => {
45
45
 
46
46
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
47
47
  var require_retry_operation = __commonJS({
48
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module2) {
48
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports2, module2) {
49
49
  "use strict";
50
50
  function RetryOperation(timeouts, options) {
51
51
  if (typeof options === "boolean") {
@@ -181,18 +181,18 @@ var require_retry_operation = __commonJS({
181
181
 
182
182
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
183
183
  var require_retry = __commonJS({
184
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
184
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports2) {
185
185
  "use strict";
186
186
  var RetryOperation = require_retry_operation();
187
- exports.operation = function(options) {
188
- var timeouts = exports.timeouts(options);
187
+ exports2.operation = function(options) {
188
+ var timeouts = exports2.timeouts(options);
189
189
  return new RetryOperation(timeouts, {
190
190
  forever: options && (options.forever || options.retries === Infinity),
191
191
  unref: options && options.unref,
192
192
  maxRetryTime: options && options.maxRetryTime
193
193
  });
194
194
  };
195
- exports.timeouts = function(options) {
195
+ exports2.timeouts = function(options) {
196
196
  if (options instanceof Array) {
197
197
  return [].concat(options);
198
198
  }
@@ -221,13 +221,13 @@ var require_retry = __commonJS({
221
221
  });
222
222
  return timeouts;
223
223
  };
224
- exports.createTimeout = function(attempt, opts) {
224
+ exports2.createTimeout = function(attempt, opts) {
225
225
  var random = opts.randomize ? Math.random() + 1 : 1;
226
226
  var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
227
227
  timeout = Math.min(timeout, opts.maxTimeout);
228
228
  return timeout;
229
229
  };
230
- exports.wrap = function(obj, options, methods) {
230
+ exports2.wrap = function(obj, options, methods) {
231
231
  if (options instanceof Array) {
232
232
  methods = options;
233
233
  options = null;
@@ -244,7 +244,7 @@ var require_retry = __commonJS({
244
244
  var method = methods[i];
245
245
  var original = obj[method];
246
246
  obj[method] = function retryWrapper(original2) {
247
- var op = exports.operation(options);
247
+ var op = exports2.operation(options);
248
248
  var args = Array.prototype.slice.call(arguments, 1);
249
249
  var callback = args.pop();
250
250
  args.push(function(err) {
@@ -268,7 +268,7 @@ var require_retry = __commonJS({
268
268
 
269
269
  // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
270
270
  var require_retry2 = __commonJS({
271
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module2) {
271
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports2, module2) {
272
272
  "use strict";
273
273
  module2.exports = require_retry();
274
274
  }
@@ -277,13 +277,16 @@ var require_retry2 = __commonJS({
277
277
  // src/index.ts
278
278
  var src_exports = {};
279
279
  __export(src_exports, {
280
+ ASSETS_SOURCE_CUSTOM_URL: () => ASSETS_SOURCE_CUSTOM_URL,
281
+ ASSETS_SOURCE_UNIFORM: () => ASSETS_SOURCE_UNIFORM,
282
+ ASSET_PARAMETER_TYPE: () => ASSET_PARAMETER_TYPE,
280
283
  ATTRIBUTE_COMPONENT_ID: () => ATTRIBUTE_COMPONENT_ID,
281
284
  ATTRIBUTE_MULTILINE: () => ATTRIBUTE_MULTILINE,
282
285
  ATTRIBUTE_PARAMETER_ID: () => ATTRIBUTE_PARAMETER_ID,
283
286
  ATTRIBUTE_PARAMETER_TYPE: () => ATTRIBUTE_PARAMETER_TYPE,
284
287
  ATTRIBUTE_PARAMETER_VALUE: () => ATTRIBUTE_PARAMETER_VALUE,
285
288
  ATTRIBUTE_PLACEHOLDER: () => ATTRIBUTE_PLACEHOLDER,
286
- ApiClientError: () => import_api10.ApiClientError,
289
+ ApiClientError: () => import_api13.ApiClientError,
287
290
  BatchEntry: () => BatchEntry,
288
291
  CANVAS_BLOCK_PARAM_TYPE: () => CANVAS_BLOCK_PARAM_TYPE,
289
292
  CANVAS_DRAFT_STATE: () => CANVAS_DRAFT_STATE,
@@ -317,11 +320,17 @@ __export(src_exports, {
317
320
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE: () => IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
318
321
  IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM,
319
322
  IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID: () => IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
323
+ IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM,
320
324
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
321
325
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
322
326
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE: () => IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
327
+ LOCALE_DYNAMIC_INPUT_NAME: () => LOCALE_DYNAMIC_INPUT_NAME,
328
+ LocaleClient: () => LocaleClient,
323
329
  PLACEHOLDER_ID: () => PLACEHOLDER_ID,
324
330
  PromptClient: () => PromptClient,
331
+ RelationshipClient: () => RelationshipClient,
332
+ ReleaseClient: () => ReleaseClient,
333
+ ReleaseContentsClient: () => ReleaseContentsClient,
325
334
  RouteClient: () => RouteClient,
326
335
  SECRET_QUERY_STRING_PARAM: () => SECRET_QUERY_STRING_PARAM,
327
336
  UncachedCanvasClient: () => UncachedCanvasClient,
@@ -340,21 +349,29 @@ __export(src_exports, {
340
349
  createVariableReference: () => createVariableReference,
341
350
  enhance: () => enhance,
342
351
  extractLocales: () => extractLocales,
352
+ findParameterInNodeTree: () => findParameterInNodeTree,
353
+ flattenValues: () => flattenValues,
343
354
  generateComponentPlaceholderId: () => generateComponentPlaceholderId,
344
355
  generateHash: () => generateHash,
345
356
  getBlockValue: () => getBlockValue,
346
357
  getChannelName: () => getChannelName,
347
358
  getComponentJsonPointer: () => getComponentJsonPointer,
348
359
  getComponentPath: () => getComponentPath,
360
+ getNounForLocation: () => getNounForLocation,
361
+ getNounForNode: () => getNounForNode,
349
362
  getParameterAttributes: () => getParameterAttributes,
350
363
  getPropertiesValue: () => getPropertiesValue,
364
+ getPropertyValue: () => getPropertyValue,
351
365
  isAddComponentMessage: () => isAddComponentMessage,
352
366
  isAllowedReferrer: () => isAllowedReferrer,
367
+ isAssetParamValue: () => isAssetParamValue,
368
+ isAssetParamValueItem: () => isAssetParamValueItem,
353
369
  isComponentActionMessage: () => isComponentActionMessage,
354
370
  isComponentPlaceholderId: () => isComponentPlaceholderId,
355
371
  isDismissPlaceholderMessage: () => isDismissPlaceholderMessage,
356
372
  isEntryData: () => isEntryData,
357
373
  isMovingComponentMessage: () => isMovingComponentMessage,
374
+ isNestedNodeType: () => isNestedNodeType,
358
375
  isOpenParameterEditorMessage: () => isOpenParameterEditorMessage,
359
376
  isReadyMessage: () => isReadyMessage,
360
377
  isReportRenderedCompositionsMessage: () => isReportRenderedCompositionsMessage,
@@ -376,7 +393,6 @@ __export(src_exports, {
376
393
  nullLimitPolicy: () => nullLimitPolicy,
377
394
  parseVariableExpression: () => parseVariableExpression,
378
395
  subscribeToComposition: () => subscribeToComposition,
379
- unstable_CompositionRelationshipClient: () => unstable_CompositionRelationshipClient,
380
396
  walkComponentTree: () => walkComponentTree,
381
397
  walkNodeTree: () => walkNodeTree
382
398
  });
@@ -590,6 +606,7 @@ var CanvasClient = class extends import_api2.ApiClient {
590
606
  }
591
607
  super(options);
592
608
  this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
609
+ this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
593
610
  }
594
611
  /** Fetches lists of Canvas compositions, optionally by type */
595
612
  async getCompositionList(params = {}) {
@@ -605,7 +622,7 @@ var CanvasClient = class extends import_api2.ApiClient {
605
622
  ...params.diagnostics ? { diagnostics: "true" } : {}
606
623
  };
607
624
  const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
608
- return this.apiClient(edgeUrl);
625
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
609
626
  }
610
627
  getCompositionByNodePath(options) {
611
628
  return this.getOneComposition(options);
@@ -645,7 +662,7 @@ var CanvasClient = class extends import_api2.ApiClient {
645
662
  ...diagnostics ? { diagnostics: "true" } : {}
646
663
  };
647
664
  const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
648
- return this.apiClient(edgeUrl);
665
+ return this.apiClient(edgeUrl, this.edgeApiRequestInit);
649
666
  }
650
667
  /** Updates or creates a Canvas component definition */
651
668
  async updateComposition(body) {
@@ -740,73 +757,10 @@ var UncachedCategoryClient = class extends CategoryClient {
740
757
  }
741
758
  };
742
759
 
743
- // src/CompositionRelationshipClient.ts
744
- var import_api4 = require("@uniformdev/context/api");
745
- var COMPOSITION_RELATIONSHIP_URL = "/api/v1/composition-relationships";
746
- var unstable_CompositionRelationshipClient = class extends import_api4.ApiClient {
747
- constructor(options) {
748
- super(options);
749
- this.getDefinitionsRelationships = async ({
750
- definitionIds,
751
- withCompositions
752
- }) => {
753
- const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL, {
754
- type: "definition",
755
- projectId: this._options.projectId,
756
- definitionIds: definitionIds.join(","),
757
- withCompositions
758
- });
759
- return this.apiClient(url);
760
- };
761
- this.clearAllRelationships = async () => {
762
- const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL);
763
- return this.apiClient(url, {
764
- method: "POST",
765
- body: JSON.stringify({
766
- type: "clear",
767
- projectId: this._options.projectId
768
- })
769
- });
770
- };
771
- this.indexCompositionRelationships = async ({
772
- state,
773
- compositionId
774
- }) => {
775
- const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL);
776
- return this.apiClient(url, {
777
- method: "POST",
778
- body: JSON.stringify({
779
- type: "index",
780
- projectId: this._options.projectId,
781
- state,
782
- compositionId
783
- })
784
- });
785
- };
786
- this.getVersion = async () => {
787
- const url = this.createUrl("/api/v1/usage-tracking", {
788
- projectId: this._options.projectId
789
- });
790
- return this.apiClient(url).then((response) => response.version);
791
- };
792
- this.setVersion = async (version) => {
793
- const url = this.createUrl("/api/v1/usage-tracking");
794
- return this.apiClient(url, {
795
- method: "POST",
796
- body: JSON.stringify({
797
- projectId: this._options.projectId,
798
- version
799
- })
800
- });
801
- };
802
- this._options = options;
803
- }
804
- };
805
-
806
760
  // src/ContentClient.ts
807
- var import_api5 = require("@uniformdev/context/api");
761
+ var import_api4 = require("@uniformdev/context/api");
808
762
  var _contentTypesUrl, _entriesUrl;
809
- var _ContentClient = class _ContentClient extends import_api5.ApiClient {
763
+ var _ContentClient = class _ContentClient extends import_api4.ApiClient {
810
764
  constructor(options) {
811
765
  var _a;
812
766
  super(options);
@@ -819,9 +773,26 @@ var _ContentClient = class _ContentClient extends import_api5.ApiClient {
819
773
  }
820
774
  getEntries(options) {
821
775
  const { projectId } = this.options;
822
- const { skipDataResolution, ...params } = options;
823
- const fetchUri = skipDataResolution ? this.createUrl(__privateGet(_ContentClient, _entriesUrl), { ...params, projectId }) : this.createUrl(__privateGet(_ContentClient, _entriesUrl), this.getEdgeOptions(params), this.edgeApiHost);
824
- return this.apiClient(fetchUri);
776
+ const { skipDataResolution, filters, ...params } = options;
777
+ const rewrittenFilters = Object.entries(filters != null ? filters : {}).reduce((acc, [key, value]) => {
778
+ const lhs = `filters.${key}` + (typeof value === "object" ? `[${Object.keys(value)[0]}]` : "");
779
+ let rhs = typeof value === "object" ? Object.values(value)[0] : value;
780
+ rhs = Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim();
781
+ return { ...acc, [lhs]: rhs };
782
+ }, {});
783
+ if (skipDataResolution) {
784
+ const url = this.createUrl(__privateGet(_ContentClient, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
785
+ return this.apiClient(url);
786
+ }
787
+ const edgeUrl = this.createUrl(
788
+ __privateGet(_ContentClient, _entriesUrl),
789
+ { ...this.getEdgeOptions(params), ...rewrittenFilters },
790
+ this.edgeApiHost
791
+ );
792
+ return this.apiClient(
793
+ edgeUrl,
794
+ this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
795
+ );
825
796
  }
826
797
  /** Fetches historical versions of an entry */
827
798
  async getEntryHistory(options) {
@@ -886,10 +857,10 @@ var UncachedContentClient = class extends ContentClient {
886
857
  };
887
858
 
888
859
  // src/DataSourceClient.ts
889
- var import_api6 = require("@uniformdev/context/api");
860
+ var import_api5 = require("@uniformdev/context/api");
890
861
  var dataSourceUrl = "/api/v1/data-source";
891
862
  var dataSourcesUrl = "/api/v1/data-sources";
892
- var DataSourceClient = class extends import_api6.ApiClient {
863
+ var DataSourceClient = class extends import_api5.ApiClient {
893
864
  constructor(options) {
894
865
  super(options);
895
866
  }
@@ -926,9 +897,9 @@ var DataSourceClient = class extends import_api6.ApiClient {
926
897
  };
927
898
 
928
899
  // src/DataTypeClient.ts
929
- var import_api7 = require("@uniformdev/context/api");
900
+ var import_api6 = require("@uniformdev/context/api");
930
901
  var _url;
931
- var _DataTypeClient = class _DataTypeClient extends import_api7.ApiClient {
902
+ var _DataTypeClient = class _DataTypeClient extends import_api6.ApiClient {
932
903
  constructor(options) {
933
904
  super(options);
934
905
  }
@@ -1099,6 +1070,7 @@ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1099
1070
  var SECRET_QUERY_STRING_PARAM = "secret";
1100
1071
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1101
1072
  var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1073
+ var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
1102
1074
  var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
1103
1075
  var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1104
1076
  var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
@@ -1114,25 +1086,9 @@ var EDGE_MIN_CACHE_TTL = 10;
1114
1086
  var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
1115
1087
  var EDGE_DEFAULT_CACHE_TTL = 30;
1116
1088
  var EDGE_CACHE_DISABLED = -1;
1117
-
1118
- // src/utils/entryConverter.ts
1119
- function convertEntryToPutEntry(entry) {
1120
- return {
1121
- entry: {
1122
- type: entry.entry.type,
1123
- _dataResources: entry.entry._dataResources,
1124
- _id: entry.entry._id,
1125
- _name: entry.entry._name,
1126
- _slug: entry.entry._slug,
1127
- fields: entry.entry.fields
1128
- },
1129
- state: entry.state,
1130
- projectId: entry.projectId
1131
- };
1132
- }
1133
- function getPropertiesValue(entity) {
1134
- return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
1135
- }
1089
+ var ASSET_PARAMETER_TYPE = "asset";
1090
+ var ASSETS_SOURCE_UNIFORM = "uniform-assets";
1091
+ var ASSETS_SOURCE_CUSTOM_URL = "custom-url";
1136
1092
 
1137
1093
  // src/utils/guards.ts
1138
1094
  function isRootEntryReference(root) {
@@ -1141,6 +1097,49 @@ function isRootEntryReference(root) {
1141
1097
  function isEntryData(entryData) {
1142
1098
  return Boolean(entryData && typeof entryData === "object" && "fields" in entryData);
1143
1099
  }
1100
+ function isAssetParamValue(value) {
1101
+ return Array.isArray(value) && (value.length > 0 ? isAssetParamValueItem(value[0]) : true);
1102
+ }
1103
+ function isAssetParamValueItem(item) {
1104
+ return Boolean(
1105
+ item instanceof Object && "_source" in item && "fields" in item && item.fields instanceof Object && "url" in item.fields && item.fields.url instanceof Object
1106
+ );
1107
+ }
1108
+
1109
+ // src/utils/properties.ts
1110
+ function getPropertiesValue(entity) {
1111
+ return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
1112
+ }
1113
+ function getPropertyValue(parameter) {
1114
+ return parameter ? parameter.value : parameter;
1115
+ }
1116
+ function flattenValues(data, options = {}) {
1117
+ if (!data) {
1118
+ return data;
1119
+ } else if (Array.isArray(data) && options.toSingle) {
1120
+ return data.length > 0 ? flattenSingleNodeValues(data[0]) : void 0;
1121
+ } else if (Array.isArray(data)) {
1122
+ return data.map((node) => flattenSingleNodeValues(node, options));
1123
+ } else {
1124
+ return flattenSingleNodeValues(data, options);
1125
+ }
1126
+ }
1127
+ function flattenSingleNodeValues(data, options = {}) {
1128
+ const { levels = 1 } = options;
1129
+ const properties = getPropertiesValue(data);
1130
+ return properties ? Object.fromEntries(
1131
+ Object.entries(properties).map(([id, parameter]) => {
1132
+ const value = getPropertyValue(parameter);
1133
+ if (levels > 0 && Array.isArray(value) && // In the future ASSET_PARAMETER_TYPE will be a nested data type
1134
+ (isNestedNodeType(parameter.type) || parameter.type === ASSET_PARAMETER_TYPE)) {
1135
+ const nestedOptions = { ...options, levels: levels - 1 };
1136
+ return [id, value.map((item) => flattenValues(item, nestedOptions))];
1137
+ } else {
1138
+ return [id, value];
1139
+ }
1140
+ })
1141
+ ) : properties;
1142
+ }
1144
1143
 
1145
1144
  // src/enhancement/walkNodeTree.ts
1146
1145
  function walkNodeTree(node, visitor, options) {
@@ -1364,7 +1363,7 @@ function walkNodeTree(node, visitor, options) {
1364
1363
  const propertyEntries = Object.entries(properties);
1365
1364
  for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
1366
1365
  const [propKey, propObject] = propertyEntries[propIndex];
1367
- if (propObject.type !== CANVAS_BLOCK_PARAM_TYPE)
1366
+ if (!isNestedNodeType(propObject.type))
1368
1367
  continue;
1369
1368
  const blocks = (_b = propObject.value) != null ? _b : [];
1370
1369
  for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
@@ -1390,6 +1389,9 @@ function walkNodeTree(node, visitor, options) {
1390
1389
  }
1391
1390
  } while (componentQueue.length > 0);
1392
1391
  }
1392
+ function isNestedNodeType(type) {
1393
+ return type === CANVAS_BLOCK_PARAM_TYPE;
1394
+ }
1393
1395
  function getBlockValue(component, parameterName) {
1394
1396
  var _a;
1395
1397
  const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
@@ -1681,6 +1683,31 @@ function getNounForLocation(parentLocation) {
1681
1683
  }
1682
1684
  return noun;
1683
1685
  }
1686
+ function getNounForNode(node) {
1687
+ let noun = "parameters";
1688
+ if (isEntryData(node)) {
1689
+ noun = "fields";
1690
+ }
1691
+ return noun;
1692
+ }
1693
+
1694
+ // src/enhancement/findInNodeTree.ts
1695
+ function findParameterInNodeTree(data, predicate) {
1696
+ const results = [];
1697
+ walkNodeTree(data, ({ node, ancestorsAndSelf }) => {
1698
+ const parameters = getPropertiesValue(node);
1699
+ if (parameters) {
1700
+ Object.entries(parameters).filter(([key, field]) => predicate(field, key, node)).forEach(([key, field]) => {
1701
+ results.push({
1702
+ key,
1703
+ pointer: (ancestorsAndSelf.length === 1 ? "" : getComponentJsonPointer(ancestorsAndSelf)) + `/${getNounForNode(node)}/${key}`,
1704
+ parameter: field
1705
+ });
1706
+ });
1707
+ }
1708
+ });
1709
+ return results;
1710
+ }
1684
1711
 
1685
1712
  // src/enhancement/localize.ts
1686
1713
  function extractLocales({ component }) {
@@ -1697,23 +1724,31 @@ function extractLocales({ component }) {
1697
1724
  });
1698
1725
  return variations;
1699
1726
  }
1700
- function localize({
1701
- composition,
1702
- locale
1703
- }) {
1704
- walkNodeTree(composition, ({ type, node, actions }) => {
1727
+ function localize(options) {
1728
+ const nodes = "nodes" in options ? options.nodes : options.composition;
1729
+ const locale = options.locale;
1730
+ walkNodeTree(nodes, ({ type, node, actions }) => {
1705
1731
  if (type !== "component") {
1706
- actions.stopProcessingDescendants();
1732
+ if (typeof locale === "string") {
1733
+ localizeProperties(node.fields, locale);
1734
+ }
1707
1735
  return;
1708
1736
  }
1737
+ const shouldRunPropertyLocalization = typeof locale === "string";
1709
1738
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
1710
1739
  const locales = extractLocales({ component: node });
1711
- const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
1740
+ const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
1712
1741
  let replaceComponent;
1713
1742
  if (resolvedLocale) {
1714
1743
  replaceComponent = locales[resolvedLocale];
1715
1744
  }
1716
1745
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1746
+ replaceComponent.forEach((component) => {
1747
+ removeLocaleProperty(component);
1748
+ if (shouldRunPropertyLocalization) {
1749
+ localizeProperties(getPropertiesValue(component), locale);
1750
+ }
1751
+ });
1717
1752
  const [first, ...rest] = replaceComponent;
1718
1753
  actions.replace(first);
1719
1754
  if (rest.length) {
@@ -1722,6 +1757,42 @@ function localize({
1722
1757
  } else {
1723
1758
  actions.remove();
1724
1759
  }
1760
+ } else if (shouldRunPropertyLocalization) {
1761
+ localizeProperties(getPropertiesValue(node), locale);
1762
+ }
1763
+ });
1764
+ }
1765
+ function removeLocaleProperty(component) {
1766
+ const properties = getPropertiesValue(component);
1767
+ const localeTagProperty = properties == null ? void 0 : properties[CANVAS_LOCALE_TAG_PARAM];
1768
+ if (localeTagProperty) {
1769
+ delete properties[CANVAS_LOCALE_TAG_PARAM];
1770
+ }
1771
+ if (properties && Object.keys(properties).length === 0) {
1772
+ if ("fields" in component) {
1773
+ delete component.fields;
1774
+ }
1775
+ if ("parameters" in component) {
1776
+ delete component.parameters;
1777
+ }
1778
+ }
1779
+ }
1780
+ function localizeProperties(properties, locale) {
1781
+ if (!properties) {
1782
+ return void 0;
1783
+ }
1784
+ Object.entries(properties).forEach(([key, property]) => {
1785
+ var _a;
1786
+ if (!locale) {
1787
+ delete property.locales;
1788
+ }
1789
+ const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
1790
+ if (currentLocaleValue !== void 0) {
1791
+ property.value = currentLocaleValue;
1792
+ }
1793
+ delete property.locales;
1794
+ if (property.value === void 0) {
1795
+ delete properties[key];
1725
1796
  }
1726
1797
  });
1727
1798
  }
@@ -1871,6 +1942,39 @@ function walkComponentTree(component, visitor, initialContext) {
1871
1942
  } while (componentQueue.length > 0);
1872
1943
  }
1873
1944
 
1945
+ // src/LocaleClient.ts
1946
+ var import_api7 = require("@uniformdev/context/api");
1947
+ var localesUrl = "/api/v1/locales";
1948
+ var LocaleClient = class extends import_api7.ApiClient {
1949
+ constructor(options) {
1950
+ super(options);
1951
+ }
1952
+ /** Fetches all locales for a project */
1953
+ async get(options) {
1954
+ const { projectId } = this.options;
1955
+ const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
1956
+ return await this.apiClient(fetchUri);
1957
+ }
1958
+ /** Updates or creates (based on id) a locale */
1959
+ async upsert(body) {
1960
+ const fetchUri = this.createUrl(localesUrl);
1961
+ await this.apiClient(fetchUri, {
1962
+ method: "PUT",
1963
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1964
+ expectNoContent: true
1965
+ });
1966
+ }
1967
+ /** Deletes a locale */
1968
+ async remove(body) {
1969
+ const fetchUri = this.createUrl(localesUrl);
1970
+ await this.apiClient(fetchUri, {
1971
+ method: "DELETE",
1972
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1973
+ expectNoContent: true
1974
+ });
1975
+ }
1976
+ };
1977
+
1874
1978
  // src/utils/hash.ts
1875
1979
  var generateHash = ({
1876
1980
  composition,
@@ -1949,7 +2053,7 @@ var createCanvasChannel = ({
1949
2053
  const handlers = {};
1950
2054
  const broadcastToItems = [...broadcastTo];
1951
2055
  const postMessage = (message) => {
1952
- broadcastToItems.forEach((item) => item.postMessage(JSON.stringify(message), "*"));
2056
+ broadcastToItems.forEach((item) => item == null ? void 0 : item.postMessage(JSON.stringify(message), "*"));
1953
2057
  };
1954
2058
  const selectComponent = (id) => {
1955
2059
  const message = {
@@ -2260,10 +2364,133 @@ var PromptClient = class extends import_api8.ApiClient {
2260
2364
  }
2261
2365
  };
2262
2366
 
2263
- // src/RouteClient.ts
2367
+ // src/RelationshipClient.ts
2264
2368
  var import_api9 = require("@uniformdev/context/api");
2369
+ var RELATIONSHIPS_URL = "/api/v1/relationships";
2370
+ var RelationshipClient = class extends import_api9.ApiClient {
2371
+ constructor(options) {
2372
+ super(options);
2373
+ this.get = async (options) => {
2374
+ const { projectId } = this.options;
2375
+ const url = this.createUrl(RELATIONSHIPS_URL, { ...options, projectId });
2376
+ return this.apiClient(url);
2377
+ };
2378
+ this.clearProjectRelationships = async () => {
2379
+ const { projectId } = this.options;
2380
+ const url = this.createUrl(RELATIONSHIPS_URL);
2381
+ return this.apiClient(url, {
2382
+ method: "POST",
2383
+ body: JSON.stringify({
2384
+ action: "clear",
2385
+ projectId
2386
+ })
2387
+ });
2388
+ };
2389
+ this.indexRelationships = async ({ state, id, type }) => {
2390
+ const { projectId } = this.options;
2391
+ const url = this.createUrl(RELATIONSHIPS_URL);
2392
+ return this.apiClient(url, {
2393
+ method: "POST",
2394
+ body: JSON.stringify({
2395
+ action: "index",
2396
+ type,
2397
+ projectId,
2398
+ state,
2399
+ id
2400
+ })
2401
+ });
2402
+ };
2403
+ this.getVersion = async () => {
2404
+ const { projectId } = this.options;
2405
+ const url = this.createUrl("/api/v1/usage-tracking", {
2406
+ projectId
2407
+ });
2408
+ return this.apiClient(url).then((response) => response.version);
2409
+ };
2410
+ this.setVersion = async (version) => {
2411
+ const { projectId } = this.options;
2412
+ const url = this.createUrl("/api/v1/usage-tracking");
2413
+ return this.apiClient(url, {
2414
+ method: "POST",
2415
+ body: JSON.stringify({
2416
+ projectId,
2417
+ version
2418
+ })
2419
+ });
2420
+ };
2421
+ }
2422
+ };
2423
+
2424
+ // src/ReleaseClient.ts
2425
+ var import_api10 = require("@uniformdev/context/api");
2426
+ var releasesUrl = "/api/v1/releases";
2427
+ var ReleaseClient = class extends import_api10.ApiClient {
2428
+ constructor(options) {
2429
+ super(options);
2430
+ }
2431
+ /** Fetches all releases for a project */
2432
+ async get(options) {
2433
+ const { projectId } = this.options;
2434
+ const fetchUri = this.createUrl(releasesUrl, { ...options, projectId });
2435
+ return await this.apiClient(fetchUri);
2436
+ }
2437
+ /** Updates or creates (based on id) a release */
2438
+ async upsert(body) {
2439
+ const fetchUri = this.createUrl(releasesUrl);
2440
+ await this.apiClient(fetchUri, {
2441
+ method: "PUT",
2442
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
2443
+ expectNoContent: true
2444
+ });
2445
+ }
2446
+ /** Deletes a release */
2447
+ async remove(body) {
2448
+ const fetchUri = this.createUrl(releasesUrl);
2449
+ await this.apiClient(fetchUri, {
2450
+ method: "DELETE",
2451
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
2452
+ expectNoContent: true
2453
+ });
2454
+ }
2455
+ /** Readies or unreadies a release for merging */
2456
+ async ready(body) {
2457
+ const fetchUri = this.createUrl(releasesUrl);
2458
+ await this.apiClient(fetchUri, {
2459
+ method: "PATCH",
2460
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
2461
+ expectNoContent: true
2462
+ });
2463
+ }
2464
+ };
2465
+
2466
+ // src/ReleaseContentsClient.ts
2467
+ var import_api11 = require("@uniformdev/context/api");
2468
+ var releaseContentsUrl = "/api/v1/release-contents";
2469
+ var ReleaseContentsClient = class extends import_api11.ApiClient {
2470
+ constructor(options) {
2471
+ super(options);
2472
+ }
2473
+ /** Fetches all entities added to a release */
2474
+ async get(options) {
2475
+ const { projectId } = this.options;
2476
+ const fetchUri = this.createUrl(releaseContentsUrl, { ...options, projectId });
2477
+ return await this.apiClient(fetchUri);
2478
+ }
2479
+ /** Removes a release content from a release */
2480
+ async remove(body) {
2481
+ const fetchUri = this.createUrl(releaseContentsUrl);
2482
+ await this.apiClient(fetchUri, {
2483
+ method: "DELETE",
2484
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
2485
+ expectNoContent: true
2486
+ });
2487
+ }
2488
+ };
2489
+
2490
+ // src/RouteClient.ts
2491
+ var import_api12 = require("@uniformdev/context/api");
2265
2492
  var ROUTE_URL = "/api/v1/route";
2266
- var RouteClient = class extends import_api9.ApiClient {
2493
+ var RouteClient = class extends import_api12.ApiClient {
2267
2494
  constructor(options) {
2268
2495
  var _a;
2269
2496
  if (!options.limitPolicy) {
@@ -2276,10 +2503,16 @@ var RouteClient = class extends import_api9.ApiClient {
2276
2503
  async getRoute(options) {
2277
2504
  const { projectId } = this.options;
2278
2505
  const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
2279
- return await this.apiClient(fetchUri);
2506
+ return await this.apiClient(
2507
+ fetchUri,
2508
+ this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
2509
+ );
2280
2510
  }
2281
2511
  };
2282
2512
 
2513
+ // src/types/locales.ts
2514
+ var LOCALE_DYNAMIC_INPUT_NAME = "locale";
2515
+
2283
2516
  // src/utils/createApiEnhancer.ts
2284
2517
  var createUniformApiEnhancer = ({ apiUrl }) => {
2285
2518
  return async (message) => {
@@ -2302,6 +2535,28 @@ var createUniformApiEnhancer = ({ apiUrl }) => {
2302
2535
  };
2303
2536
  };
2304
2537
 
2538
+ // src/utils/entryConverter.ts
2539
+ function convertEntryToPutEntry(entry) {
2540
+ return {
2541
+ entry: {
2542
+ type: entry.entry.type,
2543
+ _dataResources: entry.entry._dataResources,
2544
+ _id: entry.entry._id,
2545
+ _name: entry.entry._name,
2546
+ _slug: entry.entry._slug,
2547
+ _pattern: entry.entry._pattern,
2548
+ _overridability: entry.entry._overridability,
2549
+ _overrides: entry.entry._overrides,
2550
+ fields: entry.entry.fields,
2551
+ _locales: entry.entry._locales
2552
+ },
2553
+ pattern: entry.pattern,
2554
+ state: entry.state,
2555
+ projectId: entry.projectId,
2556
+ releaseId: entry.releaseId
2557
+ };
2558
+ }
2559
+
2305
2560
  // src/utils/getParameterAttributes.ts
2306
2561
  var ATTRIBUTE_COMPONENT_ID = "data-uniform-component-id";
2307
2562
  var ATTRIBUTE_PARAMETER_ID = "data-uniform-parameter-id";
@@ -2431,9 +2686,14 @@ function parseVariableExpression(serialized, onToken) {
2431
2686
  continue;
2432
2687
  }
2433
2688
  if (char === variableSuffix && state === "variable") {
2689
+ if (serialized[index - 1] === escapeCharacter) {
2690
+ bufferEndIndex++;
2691
+ continue;
2692
+ }
2434
2693
  state = "text";
2435
2694
  if (bufferEndIndex > bufferStartIndex) {
2436
- if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
2695
+ const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
2696
+ if (handleToken(unescapedVariableName, "variable") === false) {
2437
2697
  return tokenCount;
2438
2698
  }
2439
2699
  bufferStartIndex = bufferEndIndex + variableSuffix.length;
@@ -2493,7 +2753,7 @@ var import_immer = require("immer");
2493
2753
 
2494
2754
  // src/utils/variables/createVariableReference.ts
2495
2755
  function createVariableReference(variableName) {
2496
- return `\${${variableName}}`;
2756
+ return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
2497
2757
  }
2498
2758
 
2499
2759
  // src/utils/variables/bindVariablesToObject.ts
@@ -2574,10 +2834,13 @@ function handleRichTextNodeBinding(object, options) {
2574
2834
  }
2575
2835
 
2576
2836
  // src/index.ts
2577
- var import_api10 = require("@uniformdev/context/api");
2578
- var CanvasClientError = import_api10.ApiClientError;
2837
+ var import_api13 = require("@uniformdev/context/api");
2838
+ var CanvasClientError = import_api13.ApiClientError;
2579
2839
  // Annotate the CommonJS export names for ESM import in node:
2580
2840
  0 && (module.exports = {
2841
+ ASSETS_SOURCE_CUSTOM_URL,
2842
+ ASSETS_SOURCE_UNIFORM,
2843
+ ASSET_PARAMETER_TYPE,
2581
2844
  ATTRIBUTE_COMPONENT_ID,
2582
2845
  ATTRIBUTE_MULTILINE,
2583
2846
  ATTRIBUTE_PARAMETER_ID,
@@ -2618,11 +2881,17 @@ var CanvasClientError = import_api10.ApiClientError;
2618
2881
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
2619
2882
  IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM,
2620
2883
  IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
2884
+ IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM,
2621
2885
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
2622
2886
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
2623
2887
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
2888
+ LOCALE_DYNAMIC_INPUT_NAME,
2889
+ LocaleClient,
2624
2890
  PLACEHOLDER_ID,
2625
2891
  PromptClient,
2892
+ RelationshipClient,
2893
+ ReleaseClient,
2894
+ ReleaseContentsClient,
2626
2895
  RouteClient,
2627
2896
  SECRET_QUERY_STRING_PARAM,
2628
2897
  UncachedCanvasClient,
@@ -2641,21 +2910,29 @@ var CanvasClientError = import_api10.ApiClientError;
2641
2910
  createVariableReference,
2642
2911
  enhance,
2643
2912
  extractLocales,
2913
+ findParameterInNodeTree,
2914
+ flattenValues,
2644
2915
  generateComponentPlaceholderId,
2645
2916
  generateHash,
2646
2917
  getBlockValue,
2647
2918
  getChannelName,
2648
2919
  getComponentJsonPointer,
2649
2920
  getComponentPath,
2921
+ getNounForLocation,
2922
+ getNounForNode,
2650
2923
  getParameterAttributes,
2651
2924
  getPropertiesValue,
2925
+ getPropertyValue,
2652
2926
  isAddComponentMessage,
2653
2927
  isAllowedReferrer,
2928
+ isAssetParamValue,
2929
+ isAssetParamValueItem,
2654
2930
  isComponentActionMessage,
2655
2931
  isComponentPlaceholderId,
2656
2932
  isDismissPlaceholderMessage,
2657
2933
  isEntryData,
2658
2934
  isMovingComponentMessage,
2935
+ isNestedNodeType,
2659
2936
  isOpenParameterEditorMessage,
2660
2937
  isReadyMessage,
2661
2938
  isReportRenderedCompositionsMessage,
@@ -2677,7 +2954,6 @@ var CanvasClientError = import_api10.ApiClientError;
2677
2954
  nullLimitPolicy,
2678
2955
  parseVariableExpression,
2679
2956
  subscribeToComposition,
2680
- unstable_CompositionRelationshipClient,
2681
2957
  walkComponentTree,
2682
2958
  walkNodeTree
2683
2959
  });