@uniformdev/canvas 19.79.0 → 19.79.1-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3277 -1187
- package/dist/index.d.ts +3277 -1187
- package/dist/index.esm.js +287 -107
- package/dist/index.js +314 -120
- package/dist/index.mjs +287 -107
- package/package.json +6 -6
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"(
|
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"(
|
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
|
-
|
188
|
-
var timeouts =
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
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"(
|
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: () =>
|
289
|
+
ApiClientError: () => import_api11.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,15 @@ __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,
|
325
332
|
RouteClient: () => RouteClient,
|
326
333
|
SECRET_QUERY_STRING_PARAM: () => SECRET_QUERY_STRING_PARAM,
|
327
334
|
UncachedCanvasClient: () => UncachedCanvasClient,
|
@@ -340,21 +347,29 @@ __export(src_exports, {
|
|
340
347
|
createVariableReference: () => createVariableReference,
|
341
348
|
enhance: () => enhance,
|
342
349
|
extractLocales: () => extractLocales,
|
350
|
+
findParameterInNodeTree: () => findParameterInNodeTree,
|
351
|
+
flattenValues: () => flattenValues,
|
343
352
|
generateComponentPlaceholderId: () => generateComponentPlaceholderId,
|
344
353
|
generateHash: () => generateHash,
|
345
354
|
getBlockValue: () => getBlockValue,
|
346
355
|
getChannelName: () => getChannelName,
|
347
356
|
getComponentJsonPointer: () => getComponentJsonPointer,
|
348
357
|
getComponentPath: () => getComponentPath,
|
358
|
+
getNounForLocation: () => getNounForLocation,
|
359
|
+
getNounForNode: () => getNounForNode,
|
349
360
|
getParameterAttributes: () => getParameterAttributes,
|
350
361
|
getPropertiesValue: () => getPropertiesValue,
|
362
|
+
getPropertyValue: () => getPropertyValue,
|
351
363
|
isAddComponentMessage: () => isAddComponentMessage,
|
352
364
|
isAllowedReferrer: () => isAllowedReferrer,
|
365
|
+
isAssetParamValue: () => isAssetParamValue,
|
366
|
+
isAssetParamValueItem: () => isAssetParamValueItem,
|
353
367
|
isComponentActionMessage: () => isComponentActionMessage,
|
354
368
|
isComponentPlaceholderId: () => isComponentPlaceholderId,
|
355
369
|
isDismissPlaceholderMessage: () => isDismissPlaceholderMessage,
|
356
370
|
isEntryData: () => isEntryData,
|
357
371
|
isMovingComponentMessage: () => isMovingComponentMessage,
|
372
|
+
isNestedNodeType: () => isNestedNodeType,
|
358
373
|
isOpenParameterEditorMessage: () => isOpenParameterEditorMessage,
|
359
374
|
isReadyMessage: () => isReadyMessage,
|
360
375
|
isReportRenderedCompositionsMessage: () => isReportRenderedCompositionsMessage,
|
@@ -376,7 +391,6 @@ __export(src_exports, {
|
|
376
391
|
nullLimitPolicy: () => nullLimitPolicy,
|
377
392
|
parseVariableExpression: () => parseVariableExpression,
|
378
393
|
subscribeToComposition: () => subscribeToComposition,
|
379
|
-
unstable_CompositionRelationshipClient: () => unstable_CompositionRelationshipClient,
|
380
394
|
walkComponentTree: () => walkComponentTree,
|
381
395
|
walkNodeTree: () => walkNodeTree
|
382
396
|
});
|
@@ -590,6 +604,7 @@ var CanvasClient = class extends import_api2.ApiClient {
|
|
590
604
|
}
|
591
605
|
super(options);
|
592
606
|
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
607
|
+
this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
|
593
608
|
}
|
594
609
|
/** Fetches lists of Canvas compositions, optionally by type */
|
595
610
|
async getCompositionList(params = {}) {
|
@@ -605,7 +620,7 @@ var CanvasClient = class extends import_api2.ApiClient {
|
|
605
620
|
...params.diagnostics ? { diagnostics: "true" } : {}
|
606
621
|
};
|
607
622
|
const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
|
608
|
-
return this.apiClient(edgeUrl);
|
623
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
609
624
|
}
|
610
625
|
getCompositionByNodePath(options) {
|
611
626
|
return this.getOneComposition(options);
|
@@ -645,7 +660,7 @@ var CanvasClient = class extends import_api2.ApiClient {
|
|
645
660
|
...diagnostics ? { diagnostics: "true" } : {}
|
646
661
|
};
|
647
662
|
const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
|
648
|
-
return this.apiClient(edgeUrl);
|
663
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
649
664
|
}
|
650
665
|
/** Updates or creates a Canvas component definition */
|
651
666
|
async updateComposition(body) {
|
@@ -740,73 +755,10 @@ var UncachedCategoryClient = class extends CategoryClient {
|
|
740
755
|
}
|
741
756
|
};
|
742
757
|
|
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
758
|
// src/ContentClient.ts
|
807
|
-
var
|
759
|
+
var import_api4 = require("@uniformdev/context/api");
|
808
760
|
var _contentTypesUrl, _entriesUrl;
|
809
|
-
var _ContentClient = class _ContentClient extends
|
761
|
+
var _ContentClient = class _ContentClient extends import_api4.ApiClient {
|
810
762
|
constructor(options) {
|
811
763
|
var _a;
|
812
764
|
super(options);
|
@@ -820,8 +772,15 @@ var _ContentClient = class _ContentClient extends import_api5.ApiClient {
|
|
820
772
|
getEntries(options) {
|
821
773
|
const { projectId } = this.options;
|
822
774
|
const { skipDataResolution, ...params } = options;
|
823
|
-
|
824
|
-
|
775
|
+
if (skipDataResolution) {
|
776
|
+
const url = this.createUrl(__privateGet(_ContentClient, _entriesUrl), { ...params, projectId });
|
777
|
+
return this.apiClient(url);
|
778
|
+
}
|
779
|
+
const edgeUrl = this.createUrl(__privateGet(_ContentClient, _entriesUrl), this.getEdgeOptions(params), this.edgeApiHost);
|
780
|
+
return this.apiClient(
|
781
|
+
edgeUrl,
|
782
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
783
|
+
);
|
825
784
|
}
|
826
785
|
/** Fetches historical versions of an entry */
|
827
786
|
async getEntryHistory(options) {
|
@@ -886,10 +845,10 @@ var UncachedContentClient = class extends ContentClient {
|
|
886
845
|
};
|
887
846
|
|
888
847
|
// src/DataSourceClient.ts
|
889
|
-
var
|
848
|
+
var import_api5 = require("@uniformdev/context/api");
|
890
849
|
var dataSourceUrl = "/api/v1/data-source";
|
891
850
|
var dataSourcesUrl = "/api/v1/data-sources";
|
892
|
-
var DataSourceClient = class extends
|
851
|
+
var DataSourceClient = class extends import_api5.ApiClient {
|
893
852
|
constructor(options) {
|
894
853
|
super(options);
|
895
854
|
}
|
@@ -926,9 +885,9 @@ var DataSourceClient = class extends import_api6.ApiClient {
|
|
926
885
|
};
|
927
886
|
|
928
887
|
// src/DataTypeClient.ts
|
929
|
-
var
|
888
|
+
var import_api6 = require("@uniformdev/context/api");
|
930
889
|
var _url;
|
931
|
-
var _DataTypeClient = class _DataTypeClient extends
|
890
|
+
var _DataTypeClient = class _DataTypeClient extends import_api6.ApiClient {
|
932
891
|
constructor(options) {
|
933
892
|
super(options);
|
934
893
|
}
|
@@ -1099,6 +1058,7 @@ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
|
|
1099
1058
|
var SECRET_QUERY_STRING_PARAM = "secret";
|
1100
1059
|
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
1101
1060
|
var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
|
1061
|
+
var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
|
1102
1062
|
var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
|
1103
1063
|
var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
|
1104
1064
|
var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
|
@@ -1114,25 +1074,9 @@ var EDGE_MIN_CACHE_TTL = 10;
|
|
1114
1074
|
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
1115
1075
|
var EDGE_DEFAULT_CACHE_TTL = 30;
|
1116
1076
|
var EDGE_CACHE_DISABLED = -1;
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
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
|
-
}
|
1077
|
+
var ASSET_PARAMETER_TYPE = "asset";
|
1078
|
+
var ASSETS_SOURCE_UNIFORM = "uniform-assets";
|
1079
|
+
var ASSETS_SOURCE_CUSTOM_URL = "custom-url";
|
1136
1080
|
|
1137
1081
|
// src/utils/guards.ts
|
1138
1082
|
function isRootEntryReference(root) {
|
@@ -1141,6 +1085,49 @@ function isRootEntryReference(root) {
|
|
1141
1085
|
function isEntryData(entryData) {
|
1142
1086
|
return Boolean(entryData && typeof entryData === "object" && "fields" in entryData);
|
1143
1087
|
}
|
1088
|
+
function isAssetParamValue(value) {
|
1089
|
+
return Array.isArray(value) && (value.length > 0 ? isAssetParamValueItem(value[0]) : true);
|
1090
|
+
}
|
1091
|
+
function isAssetParamValueItem(item) {
|
1092
|
+
return Boolean(
|
1093
|
+
item instanceof Object && "_source" in item && "fields" in item && item.fields instanceof Object && "url" in item.fields && item.fields.url instanceof Object
|
1094
|
+
);
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
// src/utils/properties.ts
|
1098
|
+
function getPropertiesValue(entity) {
|
1099
|
+
return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
|
1100
|
+
}
|
1101
|
+
function getPropertyValue(parameter) {
|
1102
|
+
return parameter ? parameter.value : parameter;
|
1103
|
+
}
|
1104
|
+
function flattenValues(data, options = {}) {
|
1105
|
+
if (!data) {
|
1106
|
+
return data;
|
1107
|
+
} else if (Array.isArray(data) && options.toSingle) {
|
1108
|
+
return data.length > 0 ? flattenSingleNodeValues(data[0]) : void 0;
|
1109
|
+
} else if (Array.isArray(data)) {
|
1110
|
+
return data.map((node) => flattenSingleNodeValues(node, options));
|
1111
|
+
} else {
|
1112
|
+
return flattenSingleNodeValues(data, options);
|
1113
|
+
}
|
1114
|
+
}
|
1115
|
+
function flattenSingleNodeValues(data, options = {}) {
|
1116
|
+
const { levels = 1 } = options;
|
1117
|
+
const properties = getPropertiesValue(data);
|
1118
|
+
return properties ? Object.fromEntries(
|
1119
|
+
Object.entries(properties).map(([id, parameter]) => {
|
1120
|
+
const value = getPropertyValue(parameter);
|
1121
|
+
if (levels > 0 && Array.isArray(value) && // In the future ASSET_PARAMETER_TYPE will be a nested data type
|
1122
|
+
(isNestedNodeType(parameter.type) || parameter.type === ASSET_PARAMETER_TYPE)) {
|
1123
|
+
const nestedOptions = { ...options, levels: levels - 1 };
|
1124
|
+
return [id, value.map((item) => flattenValues(item, nestedOptions))];
|
1125
|
+
} else {
|
1126
|
+
return [id, value];
|
1127
|
+
}
|
1128
|
+
})
|
1129
|
+
) : properties;
|
1130
|
+
}
|
1144
1131
|
|
1145
1132
|
// src/enhancement/walkNodeTree.ts
|
1146
1133
|
function walkNodeTree(node, visitor, options) {
|
@@ -1364,7 +1351,7 @@ function walkNodeTree(node, visitor, options) {
|
|
1364
1351
|
const propertyEntries = Object.entries(properties);
|
1365
1352
|
for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
|
1366
1353
|
const [propKey, propObject] = propertyEntries[propIndex];
|
1367
|
-
if (propObject.type
|
1354
|
+
if (!isNestedNodeType(propObject.type))
|
1368
1355
|
continue;
|
1369
1356
|
const blocks = (_b = propObject.value) != null ? _b : [];
|
1370
1357
|
for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
|
@@ -1390,6 +1377,9 @@ function walkNodeTree(node, visitor, options) {
|
|
1390
1377
|
}
|
1391
1378
|
} while (componentQueue.length > 0);
|
1392
1379
|
}
|
1380
|
+
function isNestedNodeType(type) {
|
1381
|
+
return type === CANVAS_BLOCK_PARAM_TYPE;
|
1382
|
+
}
|
1393
1383
|
function getBlockValue(component, parameterName) {
|
1394
1384
|
var _a;
|
1395
1385
|
const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
|
@@ -1681,6 +1671,31 @@ function getNounForLocation(parentLocation) {
|
|
1681
1671
|
}
|
1682
1672
|
return noun;
|
1683
1673
|
}
|
1674
|
+
function getNounForNode(node) {
|
1675
|
+
let noun = "parameters";
|
1676
|
+
if (isEntryData(node)) {
|
1677
|
+
noun = "fields";
|
1678
|
+
}
|
1679
|
+
return noun;
|
1680
|
+
}
|
1681
|
+
|
1682
|
+
// src/enhancement/findInNodeTree.ts
|
1683
|
+
function findParameterInNodeTree(data, predicate) {
|
1684
|
+
const results = [];
|
1685
|
+
walkNodeTree(data, ({ node, ancestorsAndSelf }) => {
|
1686
|
+
const parameters = getPropertiesValue(node);
|
1687
|
+
if (parameters) {
|
1688
|
+
Object.entries(parameters).filter(([key, field]) => predicate(field, key, node)).forEach(([key, field]) => {
|
1689
|
+
results.push({
|
1690
|
+
key,
|
1691
|
+
pointer: (ancestorsAndSelf.length === 1 ? "" : getComponentJsonPointer(ancestorsAndSelf)) + `/${getNounForNode(node)}/${key}`,
|
1692
|
+
parameter: field
|
1693
|
+
});
|
1694
|
+
});
|
1695
|
+
}
|
1696
|
+
});
|
1697
|
+
return results;
|
1698
|
+
}
|
1684
1699
|
|
1685
1700
|
// src/enhancement/localize.ts
|
1686
1701
|
function extractLocales({ component }) {
|
@@ -1697,23 +1712,31 @@ function extractLocales({ component }) {
|
|
1697
1712
|
});
|
1698
1713
|
return variations;
|
1699
1714
|
}
|
1700
|
-
function localize({
|
1701
|
-
composition
|
1702
|
-
locale
|
1703
|
-
}) {
|
1704
|
-
walkNodeTree(composition, ({ type, node, actions }) => {
|
1715
|
+
function localize(options) {
|
1716
|
+
const nodes = "nodes" in options ? options.nodes : options.composition;
|
1717
|
+
const locale = options.locale;
|
1718
|
+
walkNodeTree(nodes, ({ type, node, actions }) => {
|
1705
1719
|
if (type !== "component") {
|
1706
|
-
|
1720
|
+
if (typeof locale === "string") {
|
1721
|
+
localizeProperties(node.fields, locale);
|
1722
|
+
}
|
1707
1723
|
return;
|
1708
1724
|
}
|
1725
|
+
const shouldRunPropertyLocalization = typeof locale === "string";
|
1709
1726
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1710
1727
|
const locales = extractLocales({ component: node });
|
1711
|
-
const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
|
1728
|
+
const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
|
1712
1729
|
let replaceComponent;
|
1713
1730
|
if (resolvedLocale) {
|
1714
1731
|
replaceComponent = locales[resolvedLocale];
|
1715
1732
|
}
|
1716
1733
|
if (replaceComponent == null ? void 0 : replaceComponent.length) {
|
1734
|
+
replaceComponent.forEach((component) => {
|
1735
|
+
removeLocaleProperty(component);
|
1736
|
+
if (shouldRunPropertyLocalization) {
|
1737
|
+
localizeProperties(getPropertiesValue(component), locale);
|
1738
|
+
}
|
1739
|
+
});
|
1717
1740
|
const [first, ...rest] = replaceComponent;
|
1718
1741
|
actions.replace(first);
|
1719
1742
|
if (rest.length) {
|
@@ -1722,6 +1745,42 @@ function localize({
|
|
1722
1745
|
} else {
|
1723
1746
|
actions.remove();
|
1724
1747
|
}
|
1748
|
+
} else if (shouldRunPropertyLocalization) {
|
1749
|
+
localizeProperties(getPropertiesValue(node), locale);
|
1750
|
+
}
|
1751
|
+
});
|
1752
|
+
}
|
1753
|
+
function removeLocaleProperty(component) {
|
1754
|
+
const properties = getPropertiesValue(component);
|
1755
|
+
const localeTagProperty = properties == null ? void 0 : properties[CANVAS_LOCALE_TAG_PARAM];
|
1756
|
+
if (localeTagProperty) {
|
1757
|
+
delete properties[CANVAS_LOCALE_TAG_PARAM];
|
1758
|
+
}
|
1759
|
+
if (properties && Object.keys(properties).length === 0) {
|
1760
|
+
if ("fields" in component) {
|
1761
|
+
delete component.fields;
|
1762
|
+
}
|
1763
|
+
if ("parameters" in component) {
|
1764
|
+
delete component.parameters;
|
1765
|
+
}
|
1766
|
+
}
|
1767
|
+
}
|
1768
|
+
function localizeProperties(properties, locale) {
|
1769
|
+
if (!properties) {
|
1770
|
+
return void 0;
|
1771
|
+
}
|
1772
|
+
Object.entries(properties).forEach(([key, property]) => {
|
1773
|
+
var _a;
|
1774
|
+
if (!locale) {
|
1775
|
+
delete property.locales;
|
1776
|
+
}
|
1777
|
+
const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
|
1778
|
+
if (currentLocaleValue !== void 0) {
|
1779
|
+
property.value = currentLocaleValue;
|
1780
|
+
}
|
1781
|
+
delete property.locales;
|
1782
|
+
if (property.value === void 0) {
|
1783
|
+
delete properties[key];
|
1725
1784
|
}
|
1726
1785
|
});
|
1727
1786
|
}
|
@@ -1871,6 +1930,39 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1871
1930
|
} while (componentQueue.length > 0);
|
1872
1931
|
}
|
1873
1932
|
|
1933
|
+
// src/LocaleClient.ts
|
1934
|
+
var import_api7 = require("@uniformdev/context/api");
|
1935
|
+
var localesUrl = "/api/v1/locales";
|
1936
|
+
var LocaleClient = class extends import_api7.ApiClient {
|
1937
|
+
constructor(options) {
|
1938
|
+
super(options);
|
1939
|
+
}
|
1940
|
+
/** Fetches all locales for a project */
|
1941
|
+
async get(options) {
|
1942
|
+
const { projectId } = this.options;
|
1943
|
+
const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
|
1944
|
+
return await this.apiClient(fetchUri);
|
1945
|
+
}
|
1946
|
+
/** Updates or creates (based on id) a locale */
|
1947
|
+
async upsert(body) {
|
1948
|
+
const fetchUri = this.createUrl(localesUrl);
|
1949
|
+
await this.apiClient(fetchUri, {
|
1950
|
+
method: "PUT",
|
1951
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
1952
|
+
expectNoContent: true
|
1953
|
+
});
|
1954
|
+
}
|
1955
|
+
/** Deletes a locale */
|
1956
|
+
async remove(body) {
|
1957
|
+
const fetchUri = this.createUrl(localesUrl);
|
1958
|
+
await this.apiClient(fetchUri, {
|
1959
|
+
method: "DELETE",
|
1960
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
1961
|
+
expectNoContent: true
|
1962
|
+
});
|
1963
|
+
}
|
1964
|
+
};
|
1965
|
+
|
1874
1966
|
// src/utils/hash.ts
|
1875
1967
|
var generateHash = ({
|
1876
1968
|
composition,
|
@@ -1949,7 +2041,7 @@ var createCanvasChannel = ({
|
|
1949
2041
|
const handlers = {};
|
1950
2042
|
const broadcastToItems = [...broadcastTo];
|
1951
2043
|
const postMessage = (message) => {
|
1952
|
-
broadcastToItems.forEach((item) => item.postMessage(JSON.stringify(message), "*"));
|
2044
|
+
broadcastToItems.forEach((item) => item == null ? void 0 : item.postMessage(JSON.stringify(message), "*"));
|
1953
2045
|
};
|
1954
2046
|
const selectComponent = (id) => {
|
1955
2047
|
const message = {
|
@@ -2260,10 +2352,67 @@ var PromptClient = class extends import_api8.ApiClient {
|
|
2260
2352
|
}
|
2261
2353
|
};
|
2262
2354
|
|
2263
|
-
// src/
|
2355
|
+
// src/RelationshipClient.ts
|
2264
2356
|
var import_api9 = require("@uniformdev/context/api");
|
2357
|
+
var RELATIONSHIPS_URL = "/api/v1/relationships";
|
2358
|
+
var RelationshipClient = class extends import_api9.ApiClient {
|
2359
|
+
constructor(options) {
|
2360
|
+
super(options);
|
2361
|
+
this.get = async (options) => {
|
2362
|
+
const { projectId } = this.options;
|
2363
|
+
const url = this.createUrl(RELATIONSHIPS_URL, { ...options, projectId });
|
2364
|
+
return this.apiClient(url);
|
2365
|
+
};
|
2366
|
+
this.clearProjectRelationships = async () => {
|
2367
|
+
const { projectId } = this.options;
|
2368
|
+
const url = this.createUrl(RELATIONSHIPS_URL);
|
2369
|
+
return this.apiClient(url, {
|
2370
|
+
method: "POST",
|
2371
|
+
body: JSON.stringify({
|
2372
|
+
action: "clear",
|
2373
|
+
projectId
|
2374
|
+
})
|
2375
|
+
});
|
2376
|
+
};
|
2377
|
+
this.indexRelationships = async ({ state, id, type }) => {
|
2378
|
+
const { projectId } = this.options;
|
2379
|
+
const url = this.createUrl(RELATIONSHIPS_URL);
|
2380
|
+
return this.apiClient(url, {
|
2381
|
+
method: "POST",
|
2382
|
+
body: JSON.stringify({
|
2383
|
+
action: "index",
|
2384
|
+
type,
|
2385
|
+
projectId,
|
2386
|
+
state,
|
2387
|
+
id
|
2388
|
+
})
|
2389
|
+
});
|
2390
|
+
};
|
2391
|
+
this.getVersion = async () => {
|
2392
|
+
const { projectId } = this.options;
|
2393
|
+
const url = this.createUrl("/api/v1/usage-tracking", {
|
2394
|
+
projectId
|
2395
|
+
});
|
2396
|
+
return this.apiClient(url).then((response) => response.version);
|
2397
|
+
};
|
2398
|
+
this.setVersion = async (version) => {
|
2399
|
+
const { projectId } = this.options;
|
2400
|
+
const url = this.createUrl("/api/v1/usage-tracking");
|
2401
|
+
return this.apiClient(url, {
|
2402
|
+
method: "POST",
|
2403
|
+
body: JSON.stringify({
|
2404
|
+
projectId,
|
2405
|
+
version
|
2406
|
+
})
|
2407
|
+
});
|
2408
|
+
};
|
2409
|
+
}
|
2410
|
+
};
|
2411
|
+
|
2412
|
+
// src/RouteClient.ts
|
2413
|
+
var import_api10 = require("@uniformdev/context/api");
|
2265
2414
|
var ROUTE_URL = "/api/v1/route";
|
2266
|
-
var RouteClient = class extends
|
2415
|
+
var RouteClient = class extends import_api10.ApiClient {
|
2267
2416
|
constructor(options) {
|
2268
2417
|
var _a;
|
2269
2418
|
if (!options.limitPolicy) {
|
@@ -2276,10 +2425,16 @@ var RouteClient = class extends import_api9.ApiClient {
|
|
2276
2425
|
async getRoute(options) {
|
2277
2426
|
const { projectId } = this.options;
|
2278
2427
|
const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
|
2279
|
-
return await this.apiClient(
|
2428
|
+
return await this.apiClient(
|
2429
|
+
fetchUri,
|
2430
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
2431
|
+
);
|
2280
2432
|
}
|
2281
2433
|
};
|
2282
2434
|
|
2435
|
+
// src/types/locales.ts
|
2436
|
+
var LOCALE_DYNAMIC_INPUT_NAME = "locale";
|
2437
|
+
|
2283
2438
|
// src/utils/createApiEnhancer.ts
|
2284
2439
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
2285
2440
|
return async (message) => {
|
@@ -2302,6 +2457,26 @@ var createUniformApiEnhancer = ({ apiUrl }) => {
|
|
2302
2457
|
};
|
2303
2458
|
};
|
2304
2459
|
|
2460
|
+
// src/utils/entryConverter.ts
|
2461
|
+
function convertEntryToPutEntry(entry) {
|
2462
|
+
return {
|
2463
|
+
entry: {
|
2464
|
+
type: entry.entry.type,
|
2465
|
+
_dataResources: entry.entry._dataResources,
|
2466
|
+
_id: entry.entry._id,
|
2467
|
+
_name: entry.entry._name,
|
2468
|
+
_slug: entry.entry._slug,
|
2469
|
+
_pattern: entry.entry._pattern,
|
2470
|
+
_overridability: entry.entry._overridability,
|
2471
|
+
_overrides: entry.entry._overrides,
|
2472
|
+
fields: entry.entry.fields,
|
2473
|
+
_locales: entry.entry._locales
|
2474
|
+
},
|
2475
|
+
state: entry.state,
|
2476
|
+
projectId: entry.projectId
|
2477
|
+
};
|
2478
|
+
}
|
2479
|
+
|
2305
2480
|
// src/utils/getParameterAttributes.ts
|
2306
2481
|
var ATTRIBUTE_COMPONENT_ID = "data-uniform-component-id";
|
2307
2482
|
var ATTRIBUTE_PARAMETER_ID = "data-uniform-parameter-id";
|
@@ -2431,9 +2606,14 @@ function parseVariableExpression(serialized, onToken) {
|
|
2431
2606
|
continue;
|
2432
2607
|
}
|
2433
2608
|
if (char === variableSuffix && state === "variable") {
|
2609
|
+
if (serialized[index - 1] === escapeCharacter) {
|
2610
|
+
bufferEndIndex++;
|
2611
|
+
continue;
|
2612
|
+
}
|
2434
2613
|
state = "text";
|
2435
2614
|
if (bufferEndIndex > bufferStartIndex) {
|
2436
|
-
|
2615
|
+
const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
|
2616
|
+
if (handleToken(unescapedVariableName, "variable") === false) {
|
2437
2617
|
return tokenCount;
|
2438
2618
|
}
|
2439
2619
|
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
@@ -2493,7 +2673,7 @@ var import_immer = require("immer");
|
|
2493
2673
|
|
2494
2674
|
// src/utils/variables/createVariableReference.ts
|
2495
2675
|
function createVariableReference(variableName) {
|
2496
|
-
return `\${${variableName}}`;
|
2676
|
+
return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
|
2497
2677
|
}
|
2498
2678
|
|
2499
2679
|
// src/utils/variables/bindVariablesToObject.ts
|
@@ -2574,10 +2754,13 @@ function handleRichTextNodeBinding(object, options) {
|
|
2574
2754
|
}
|
2575
2755
|
|
2576
2756
|
// src/index.ts
|
2577
|
-
var
|
2578
|
-
var CanvasClientError =
|
2757
|
+
var import_api11 = require("@uniformdev/context/api");
|
2758
|
+
var CanvasClientError = import_api11.ApiClientError;
|
2579
2759
|
// Annotate the CommonJS export names for ESM import in node:
|
2580
2760
|
0 && (module.exports = {
|
2761
|
+
ASSETS_SOURCE_CUSTOM_URL,
|
2762
|
+
ASSETS_SOURCE_UNIFORM,
|
2763
|
+
ASSET_PARAMETER_TYPE,
|
2581
2764
|
ATTRIBUTE_COMPONENT_ID,
|
2582
2765
|
ATTRIBUTE_MULTILINE,
|
2583
2766
|
ATTRIBUTE_PARAMETER_ID,
|
@@ -2618,11 +2801,15 @@ var CanvasClientError = import_api10.ApiClientError;
|
|
2618
2801
|
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
2619
2802
|
IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM,
|
2620
2803
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
2804
|
+
IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM,
|
2621
2805
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
2622
2806
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
2623
2807
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
2808
|
+
LOCALE_DYNAMIC_INPUT_NAME,
|
2809
|
+
LocaleClient,
|
2624
2810
|
PLACEHOLDER_ID,
|
2625
2811
|
PromptClient,
|
2812
|
+
RelationshipClient,
|
2626
2813
|
RouteClient,
|
2627
2814
|
SECRET_QUERY_STRING_PARAM,
|
2628
2815
|
UncachedCanvasClient,
|
@@ -2641,21 +2828,29 @@ var CanvasClientError = import_api10.ApiClientError;
|
|
2641
2828
|
createVariableReference,
|
2642
2829
|
enhance,
|
2643
2830
|
extractLocales,
|
2831
|
+
findParameterInNodeTree,
|
2832
|
+
flattenValues,
|
2644
2833
|
generateComponentPlaceholderId,
|
2645
2834
|
generateHash,
|
2646
2835
|
getBlockValue,
|
2647
2836
|
getChannelName,
|
2648
2837
|
getComponentJsonPointer,
|
2649
2838
|
getComponentPath,
|
2839
|
+
getNounForLocation,
|
2840
|
+
getNounForNode,
|
2650
2841
|
getParameterAttributes,
|
2651
2842
|
getPropertiesValue,
|
2843
|
+
getPropertyValue,
|
2652
2844
|
isAddComponentMessage,
|
2653
2845
|
isAllowedReferrer,
|
2846
|
+
isAssetParamValue,
|
2847
|
+
isAssetParamValueItem,
|
2654
2848
|
isComponentActionMessage,
|
2655
2849
|
isComponentPlaceholderId,
|
2656
2850
|
isDismissPlaceholderMessage,
|
2657
2851
|
isEntryData,
|
2658
2852
|
isMovingComponentMessage,
|
2853
|
+
isNestedNodeType,
|
2659
2854
|
isOpenParameterEditorMessage,
|
2660
2855
|
isReadyMessage,
|
2661
2856
|
isReportRenderedCompositionsMessage,
|
@@ -2677,7 +2872,6 @@ var CanvasClientError = import_api10.ApiClientError;
|
|
2677
2872
|
nullLimitPolicy,
|
2678
2873
|
parseVariableExpression,
|
2679
2874
|
subscribeToComposition,
|
2680
|
-
unstable_CompositionRelationshipClient,
|
2681
2875
|
walkComponentTree,
|
2682
2876
|
walkNodeTree
|
2683
2877
|
});
|