@uniformdev/canvas 19.68.1-alpha.27 → 19.71.1-alpha.103
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 +1102 -837
- package/dist/index.d.ts +1102 -837
- package/dist/index.esm.js +286 -120
- package/dist/index.js +304 -123
- package/dist/index.mjs +286 -120
- package/package.json +6 -6
package/dist/index.js
CHANGED
@@ -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,
|
@@ -320,6 +323,8 @@ __export(src_exports, {
|
|
320
323
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
321
324
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
322
325
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE: () => IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
326
|
+
LOCALE_DYNAMIC_INPUT_NAME: () => LOCALE_DYNAMIC_INPUT_NAME,
|
327
|
+
LocaleClient: () => LocaleClient,
|
323
328
|
PLACEHOLDER_ID: () => PLACEHOLDER_ID,
|
324
329
|
PromptClient: () => PromptClient,
|
325
330
|
RouteClient: () => RouteClient,
|
@@ -340,23 +345,33 @@ __export(src_exports, {
|
|
340
345
|
createVariableReference: () => createVariableReference,
|
341
346
|
enhance: () => enhance,
|
342
347
|
extractLocales: () => extractLocales,
|
348
|
+
findParameterInNodeTree: () => findParameterInNodeTree,
|
349
|
+
flattenValues: () => flattenValues,
|
343
350
|
generateComponentPlaceholderId: () => generateComponentPlaceholderId,
|
344
351
|
generateHash: () => generateHash,
|
345
352
|
getBlockValue: () => getBlockValue,
|
346
353
|
getChannelName: () => getChannelName,
|
347
354
|
getComponentJsonPointer: () => getComponentJsonPointer,
|
348
355
|
getComponentPath: () => getComponentPath,
|
356
|
+
getNounForLocation: () => getNounForLocation,
|
357
|
+
getNounForNode: () => getNounForNode,
|
349
358
|
getParameterAttributes: () => getParameterAttributes,
|
350
359
|
getPropertiesValue: () => getPropertiesValue,
|
360
|
+
getPropertyValue: () => getPropertyValue,
|
351
361
|
isAddComponentMessage: () => isAddComponentMessage,
|
352
362
|
isAllowedReferrer: () => isAllowedReferrer,
|
363
|
+
isAssetParamValue: () => isAssetParamValue,
|
364
|
+
isAssetParamValueItem: () => isAssetParamValueItem,
|
353
365
|
isComponentActionMessage: () => isComponentActionMessage,
|
354
366
|
isComponentPlaceholderId: () => isComponentPlaceholderId,
|
355
367
|
isDismissPlaceholderMessage: () => isDismissPlaceholderMessage,
|
368
|
+
isEntryData: () => isEntryData,
|
356
369
|
isMovingComponentMessage: () => isMovingComponentMessage,
|
370
|
+
isNestedNodeType: () => isNestedNodeType,
|
357
371
|
isOpenParameterEditorMessage: () => isOpenParameterEditorMessage,
|
358
372
|
isReadyMessage: () => isReadyMessage,
|
359
373
|
isReportRenderedCompositionsMessage: () => isReportRenderedCompositionsMessage,
|
374
|
+
isRootEntryReference: () => isRootEntryReference,
|
360
375
|
isSelectComponentMessage: () => isSelectComponentMessage,
|
361
376
|
isSelectParameterMessage: () => isSelectParameterMessage,
|
362
377
|
isSystemComponentDefinition: () => isSystemComponentDefinition,
|
@@ -829,12 +844,13 @@ var _ContentClient = class _ContentClient extends import_api5.ApiClient {
|
|
829
844
|
});
|
830
845
|
return this.apiClient(historyUrl);
|
831
846
|
}
|
832
|
-
async upsertContentType(body) {
|
847
|
+
async upsertContentType(body, opts = {}) {
|
833
848
|
const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl));
|
834
849
|
await this.apiClient(fetchUri, {
|
835
850
|
method: "PUT",
|
836
851
|
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
837
|
-
expectNoContent: true
|
852
|
+
expectNoContent: true,
|
853
|
+
headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
|
838
854
|
});
|
839
855
|
}
|
840
856
|
async upsertEntry(body) {
|
@@ -1111,25 +1127,60 @@ var EDGE_MIN_CACHE_TTL = 10;
|
|
1111
1127
|
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
1112
1128
|
var EDGE_DEFAULT_CACHE_TTL = 30;
|
1113
1129
|
var EDGE_CACHE_DISABLED = -1;
|
1130
|
+
var ASSET_PARAMETER_TYPE = "asset";
|
1131
|
+
var ASSETS_SOURCE_UNIFORM = "uniform-assets";
|
1132
|
+
var ASSETS_SOURCE_CUSTOM_URL = "custom-url";
|
1114
1133
|
|
1115
|
-
// src/utils/
|
1116
|
-
function
|
1117
|
-
return
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
fields: entry.entry.fields
|
1125
|
-
},
|
1126
|
-
state: entry.state,
|
1127
|
-
projectId: entry.projectId
|
1128
|
-
};
|
1134
|
+
// src/utils/guards.ts
|
1135
|
+
function isRootEntryReference(root) {
|
1136
|
+
return root.type === "root" && isEntryData(root.node);
|
1137
|
+
}
|
1138
|
+
function isEntryData(entryData) {
|
1139
|
+
return Boolean(entryData && typeof entryData === "object" && "fields" in entryData);
|
1140
|
+
}
|
1141
|
+
function isAssetParamValue(value) {
|
1142
|
+
return Array.isArray(value) && (value.length > 0 ? isAssetParamValueItem(value[0]) : true);
|
1129
1143
|
}
|
1144
|
+
function isAssetParamValueItem(item) {
|
1145
|
+
return Boolean(
|
1146
|
+
item instanceof Object && "_source" in item && "fields" in item && item.fields instanceof Object && "url" in item.fields && item.fields.url instanceof Object
|
1147
|
+
);
|
1148
|
+
}
|
1149
|
+
|
1150
|
+
// src/utils/properties.ts
|
1130
1151
|
function getPropertiesValue(entity) {
|
1131
1152
|
return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
|
1132
1153
|
}
|
1154
|
+
function getPropertyValue(parameter) {
|
1155
|
+
return parameter ? parameter.value : parameter;
|
1156
|
+
}
|
1157
|
+
function flattenValues(data, options = {}) {
|
1158
|
+
if (!data) {
|
1159
|
+
return data;
|
1160
|
+
} else if (Array.isArray(data) && options.toSingle) {
|
1161
|
+
return data.length > 0 ? flattenSingleNodeValues(data[0]) : void 0;
|
1162
|
+
} else if (Array.isArray(data)) {
|
1163
|
+
return data.map((node) => flattenSingleNodeValues(node, options));
|
1164
|
+
} else {
|
1165
|
+
return flattenSingleNodeValues(data, options);
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
function flattenSingleNodeValues(data, options = {}) {
|
1169
|
+
const { levels = 1 } = options;
|
1170
|
+
const properties = getPropertiesValue(data);
|
1171
|
+
return properties ? Object.fromEntries(
|
1172
|
+
Object.entries(properties).map(([id, parameter]) => {
|
1173
|
+
const value = getPropertyValue(parameter);
|
1174
|
+
if (levels > 0 && Array.isArray(value) && // In the future ASSET_PARAMETER_TYPE will be a nested data type
|
1175
|
+
(isNestedNodeType(parameter.type) || parameter.type === ASSET_PARAMETER_TYPE)) {
|
1176
|
+
const nestedOptions = { ...options, levels: levels - 1 };
|
1177
|
+
return [id, value.map((item) => flattenValues(item, nestedOptions))];
|
1178
|
+
} else {
|
1179
|
+
return [id, value];
|
1180
|
+
}
|
1181
|
+
})
|
1182
|
+
) : properties;
|
1183
|
+
}
|
1133
1184
|
|
1134
1185
|
// src/enhancement/walkNodeTree.ts
|
1135
1186
|
function walkNodeTree(node, visitor, options) {
|
@@ -1149,7 +1200,83 @@ function walkNodeTree(node, visitor, options) {
|
|
1149
1200
|
let visitDescendants = true;
|
1150
1201
|
let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
|
1151
1202
|
let visitorInfo;
|
1152
|
-
if (currentComponent.type === "root" || currentComponent.type === "
|
1203
|
+
if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
|
1204
|
+
visitorInfo = {
|
1205
|
+
type: "entry",
|
1206
|
+
node: currentComponent.node,
|
1207
|
+
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
1208
|
+
actions: {
|
1209
|
+
replace: (replacementNode) => {
|
1210
|
+
Object.assign(currentComponent.node, replacementNode);
|
1211
|
+
const propertiesToCheck = ["fields", "_dataResources", "_author"];
|
1212
|
+
propertiesToCheck.forEach((property) => {
|
1213
|
+
if (!replacementNode[property]) {
|
1214
|
+
delete currentComponent.node[property];
|
1215
|
+
}
|
1216
|
+
});
|
1217
|
+
},
|
1218
|
+
remove: () => {
|
1219
|
+
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
1220
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1221
|
+
if (currentComponentLocation.type === "block") {
|
1222
|
+
const { fieldName, blockIndex } = currentComponentLocation;
|
1223
|
+
const blockValue = getBlockValue(parentComponent.node, fieldName);
|
1224
|
+
blockValue.splice(blockIndex, 1);
|
1225
|
+
if (blockValue.length === 0) {
|
1226
|
+
const properties2 = getPropertiesValue(parentComponent.node);
|
1227
|
+
delete properties2[fieldName];
|
1228
|
+
}
|
1229
|
+
} else {
|
1230
|
+
throw new Error("Unknown node type");
|
1231
|
+
}
|
1232
|
+
},
|
1233
|
+
insertAfter: (nodes) => {
|
1234
|
+
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
1235
|
+
if (currentNodeInfo.type !== "block") {
|
1236
|
+
throw new Error("Unknown type");
|
1237
|
+
}
|
1238
|
+
const { fieldName, blockIndex } = currentNodeInfo;
|
1239
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1240
|
+
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
1241
|
+
if (fieldName && typeof blockIndex !== "undefined") {
|
1242
|
+
getPropertiesValue(parentComponent.node)[fieldName].value.splice(
|
1243
|
+
blockIndex + 1,
|
1244
|
+
0,
|
1245
|
+
...nodesToInsert
|
1246
|
+
);
|
1247
|
+
componentQueue.unshift(
|
1248
|
+
...nodesToInsert.map((enqueueingComponent) => ({
|
1249
|
+
ancestorsAndSelf: [
|
1250
|
+
{
|
1251
|
+
type: "block",
|
1252
|
+
node: enqueueingComponent,
|
1253
|
+
fieldName,
|
1254
|
+
get blockIndex() {
|
1255
|
+
const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
|
1256
|
+
return parentArray.findIndex((x) => x === enqueueingComponent);
|
1257
|
+
}
|
1258
|
+
},
|
1259
|
+
// slice removes 'self' since we are inserting a peer of self
|
1260
|
+
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
1261
|
+
],
|
1262
|
+
context: descendantContext
|
1263
|
+
}))
|
1264
|
+
);
|
1265
|
+
}
|
1266
|
+
},
|
1267
|
+
stopProcessingDescendants() {
|
1268
|
+
visitDescendants = false;
|
1269
|
+
},
|
1270
|
+
setDescendantsContext(context) {
|
1271
|
+
descendantContext = context;
|
1272
|
+
},
|
1273
|
+
setChildContext(child, context) {
|
1274
|
+
childContexts.set(child, context);
|
1275
|
+
}
|
1276
|
+
},
|
1277
|
+
context: descendantContext
|
1278
|
+
};
|
1279
|
+
} else {
|
1153
1280
|
visitorInfo = {
|
1154
1281
|
type: "component",
|
1155
1282
|
node: currentComponent.node,
|
@@ -1240,82 +1367,6 @@ function walkNodeTree(node, visitor, options) {
|
|
1240
1367
|
},
|
1241
1368
|
context: descendantContext
|
1242
1369
|
};
|
1243
|
-
} else {
|
1244
|
-
visitorInfo = {
|
1245
|
-
type: "entry",
|
1246
|
-
node: currentComponent.node,
|
1247
|
-
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
1248
|
-
actions: {
|
1249
|
-
replace: (replacementNode) => {
|
1250
|
-
Object.assign(currentComponent.node, replacementNode);
|
1251
|
-
const propertiesToCheck = ["fields", "_dataResources", "_author"];
|
1252
|
-
propertiesToCheck.forEach((property) => {
|
1253
|
-
if (!replacementNode[property]) {
|
1254
|
-
delete currentComponent.node[property];
|
1255
|
-
}
|
1256
|
-
});
|
1257
|
-
},
|
1258
|
-
remove: () => {
|
1259
|
-
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
1260
|
-
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1261
|
-
if (currentComponentLocation.type === "block") {
|
1262
|
-
const { fieldName, blockIndex } = currentComponentLocation;
|
1263
|
-
const blockValue = getBlockValue(parentComponent.node, fieldName);
|
1264
|
-
blockValue.splice(blockIndex, 1);
|
1265
|
-
if (blockValue.length === 0) {
|
1266
|
-
const properties2 = getPropertiesValue(parentComponent.node);
|
1267
|
-
delete properties2[fieldName];
|
1268
|
-
}
|
1269
|
-
} else {
|
1270
|
-
throw new Error("Unknown node type");
|
1271
|
-
}
|
1272
|
-
},
|
1273
|
-
insertAfter: (nodes) => {
|
1274
|
-
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
1275
|
-
if (currentNodeInfo.type !== "block") {
|
1276
|
-
throw new Error("Unknown type");
|
1277
|
-
}
|
1278
|
-
const { fieldName, blockIndex } = currentNodeInfo;
|
1279
|
-
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1280
|
-
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
1281
|
-
if (fieldName && typeof blockIndex !== "undefined") {
|
1282
|
-
getPropertiesValue(parentComponent.node)[fieldName].value.splice(
|
1283
|
-
blockIndex + 1,
|
1284
|
-
0,
|
1285
|
-
...nodesToInsert
|
1286
|
-
);
|
1287
|
-
componentQueue.unshift(
|
1288
|
-
...nodesToInsert.map((enqueueingComponent) => ({
|
1289
|
-
ancestorsAndSelf: [
|
1290
|
-
{
|
1291
|
-
type: "block",
|
1292
|
-
node: enqueueingComponent,
|
1293
|
-
fieldName,
|
1294
|
-
get blockIndex() {
|
1295
|
-
const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
|
1296
|
-
return parentArray.findIndex((x) => x === enqueueingComponent);
|
1297
|
-
}
|
1298
|
-
},
|
1299
|
-
// slice removes 'self' since we are inserting a peer of self
|
1300
|
-
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
1301
|
-
],
|
1302
|
-
context: descendantContext
|
1303
|
-
}))
|
1304
|
-
);
|
1305
|
-
}
|
1306
|
-
},
|
1307
|
-
stopProcessingDescendants() {
|
1308
|
-
visitDescendants = false;
|
1309
|
-
},
|
1310
|
-
setDescendantsContext(context) {
|
1311
|
-
descendantContext = context;
|
1312
|
-
},
|
1313
|
-
setChildContext(child, context) {
|
1314
|
-
childContexts.set(child, context);
|
1315
|
-
}
|
1316
|
-
},
|
1317
|
-
context: descendantContext
|
1318
|
-
};
|
1319
1370
|
}
|
1320
1371
|
visitor(visitorInfo);
|
1321
1372
|
if (!visitDescendants) {
|
@@ -1353,7 +1404,7 @@ function walkNodeTree(node, visitor, options) {
|
|
1353
1404
|
const propertyEntries = Object.entries(properties);
|
1354
1405
|
for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
|
1355
1406
|
const [propKey, propObject] = propertyEntries[propIndex];
|
1356
|
-
if (propObject.type
|
1407
|
+
if (!isNestedNodeType(propObject.type))
|
1357
1408
|
continue;
|
1358
1409
|
const blocks = (_b = propObject.value) != null ? _b : [];
|
1359
1410
|
for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
|
@@ -1379,6 +1430,9 @@ function walkNodeTree(node, visitor, options) {
|
|
1379
1430
|
}
|
1380
1431
|
} while (componentQueue.length > 0);
|
1381
1432
|
}
|
1433
|
+
function isNestedNodeType(type) {
|
1434
|
+
return type === CANVAS_BLOCK_PARAM_TYPE;
|
1435
|
+
}
|
1382
1436
|
function getBlockValue(component, parameterName) {
|
1383
1437
|
var _a;
|
1384
1438
|
const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
|
@@ -1647,7 +1701,7 @@ function getComponentJsonPointer(ancestorsAndSelf) {
|
|
1647
1701
|
if (currentLocation.type === "block") {
|
1648
1702
|
const { fieldName: parameterName, blockIndex } = currentLocation;
|
1649
1703
|
if (parameterName && blockIndex !== void 0) {
|
1650
|
-
const noun = parentLocation
|
1704
|
+
const noun = getNounForLocation(parentLocation);
|
1651
1705
|
path.push(`${noun}/${parameterName}/value/${blockIndex}`);
|
1652
1706
|
}
|
1653
1707
|
} else {
|
@@ -1661,6 +1715,40 @@ function getComponentJsonPointer(ancestorsAndSelf) {
|
|
1661
1715
|
}
|
1662
1716
|
return `/${path.join("/")}`;
|
1663
1717
|
}
|
1718
|
+
function getNounForLocation(parentLocation) {
|
1719
|
+
let noun = "parameters";
|
1720
|
+
if (parentLocation && "type" in parentLocation) {
|
1721
|
+
if (parentLocation.type === "block" || isRootEntryReference(parentLocation)) {
|
1722
|
+
noun = "fields";
|
1723
|
+
}
|
1724
|
+
}
|
1725
|
+
return noun;
|
1726
|
+
}
|
1727
|
+
function getNounForNode(node) {
|
1728
|
+
let noun = "parameters";
|
1729
|
+
if (isEntryData(node)) {
|
1730
|
+
noun = "fields";
|
1731
|
+
}
|
1732
|
+
return noun;
|
1733
|
+
}
|
1734
|
+
|
1735
|
+
// src/enhancement/findInNodeTree.ts
|
1736
|
+
function findParameterInNodeTree(data, predicate) {
|
1737
|
+
const results = [];
|
1738
|
+
walkNodeTree(data, ({ node, ancestorsAndSelf }) => {
|
1739
|
+
const parameters = getPropertiesValue(node);
|
1740
|
+
if (parameters) {
|
1741
|
+
Object.entries(parameters).filter(([key, field]) => predicate(field, key, node)).forEach(([key, field]) => {
|
1742
|
+
results.push({
|
1743
|
+
key,
|
1744
|
+
pointer: (ancestorsAndSelf.length === 1 ? "" : getComponentJsonPointer(ancestorsAndSelf)) + `/${getNounForNode(node)}/${key}`,
|
1745
|
+
parameter: field
|
1746
|
+
});
|
1747
|
+
});
|
1748
|
+
}
|
1749
|
+
});
|
1750
|
+
return results;
|
1751
|
+
}
|
1664
1752
|
|
1665
1753
|
// src/enhancement/localize.ts
|
1666
1754
|
function extractLocales({ component }) {
|
@@ -1677,18 +1765,22 @@ function extractLocales({ component }) {
|
|
1677
1765
|
});
|
1678
1766
|
return variations;
|
1679
1767
|
}
|
1680
|
-
function localize({
|
1681
|
-
composition
|
1682
|
-
locale
|
1683
|
-
}) {
|
1684
|
-
walkNodeTree(composition, ({ type, node, actions }) => {
|
1768
|
+
function localize(options) {
|
1769
|
+
const nodes = "nodes" in options ? options.nodes : options.composition;
|
1770
|
+
const locale = options.locale;
|
1771
|
+
walkNodeTree(nodes, ({ type, node, actions }) => {
|
1685
1772
|
if (type !== "component") {
|
1686
|
-
|
1773
|
+
if (typeof locale === "string") {
|
1774
|
+
localizeProperties(node.fields, locale);
|
1775
|
+
}
|
1687
1776
|
return;
|
1688
1777
|
}
|
1778
|
+
if (typeof locale === "string") {
|
1779
|
+
localizeProperties(getPropertiesValue(node), locale);
|
1780
|
+
}
|
1689
1781
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1690
1782
|
const locales = extractLocales({ component: node });
|
1691
|
-
const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
|
1783
|
+
const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
|
1692
1784
|
let replaceComponent;
|
1693
1785
|
if (resolvedLocale) {
|
1694
1786
|
replaceComponent = locales[resolvedLocale];
|
@@ -1705,6 +1797,25 @@ function localize({
|
|
1705
1797
|
}
|
1706
1798
|
});
|
1707
1799
|
}
|
1800
|
+
function localizeProperties(properties, locale) {
|
1801
|
+
if (!properties) {
|
1802
|
+
return void 0;
|
1803
|
+
}
|
1804
|
+
Object.entries(properties).forEach(([key, property]) => {
|
1805
|
+
var _a;
|
1806
|
+
if (!locale) {
|
1807
|
+
delete property.locales;
|
1808
|
+
}
|
1809
|
+
const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
|
1810
|
+
if (currentLocaleValue !== void 0) {
|
1811
|
+
property.value = currentLocaleValue;
|
1812
|
+
}
|
1813
|
+
delete property.locales;
|
1814
|
+
if (property.value === void 0) {
|
1815
|
+
delete properties[key];
|
1816
|
+
}
|
1817
|
+
});
|
1818
|
+
}
|
1708
1819
|
|
1709
1820
|
// src/enhancement/UniqueBatchEntries.ts
|
1710
1821
|
var UniqueBatchEntries = class {
|
@@ -1851,6 +1962,39 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1851
1962
|
} while (componentQueue.length > 0);
|
1852
1963
|
}
|
1853
1964
|
|
1965
|
+
// src/LocaleClient.ts
|
1966
|
+
var import_api8 = require("@uniformdev/context/api");
|
1967
|
+
var localesUrl = "/api/v1/locales";
|
1968
|
+
var LocaleClient = class extends import_api8.ApiClient {
|
1969
|
+
constructor(options) {
|
1970
|
+
super(options);
|
1971
|
+
}
|
1972
|
+
/** Fetches all locales for a project */
|
1973
|
+
async get(options) {
|
1974
|
+
const { projectId } = this.options;
|
1975
|
+
const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
|
1976
|
+
return await this.apiClient(fetchUri);
|
1977
|
+
}
|
1978
|
+
/** Updates or creates (based on id) a locale */
|
1979
|
+
async upsert(body) {
|
1980
|
+
const fetchUri = this.createUrl(localesUrl);
|
1981
|
+
await this.apiClient(fetchUri, {
|
1982
|
+
method: "PUT",
|
1983
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
1984
|
+
expectNoContent: true
|
1985
|
+
});
|
1986
|
+
}
|
1987
|
+
/** Deletes a locale */
|
1988
|
+
async remove(body) {
|
1989
|
+
const fetchUri = this.createUrl(localesUrl);
|
1990
|
+
await this.apiClient(fetchUri, {
|
1991
|
+
method: "DELETE",
|
1992
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
1993
|
+
expectNoContent: true
|
1994
|
+
});
|
1995
|
+
}
|
1996
|
+
};
|
1997
|
+
|
1854
1998
|
// src/utils/hash.ts
|
1855
1999
|
var generateHash = ({
|
1856
2000
|
composition,
|
@@ -1938,7 +2082,7 @@ var createCanvasChannel = ({
|
|
1938
2082
|
};
|
1939
2083
|
postMessage(message);
|
1940
2084
|
};
|
1941
|
-
const ready = () => {
|
2085
|
+
const ready = (options) => {
|
1942
2086
|
var _a, _b;
|
1943
2087
|
if (typeof window === "undefined") {
|
1944
2088
|
return;
|
@@ -1948,7 +2092,8 @@ var createCanvasChannel = ({
|
|
1948
2092
|
const message = {
|
1949
2093
|
type: "ready",
|
1950
2094
|
framework,
|
1951
|
-
version
|
2095
|
+
version,
|
2096
|
+
rsc: options == null ? void 0 : options.rsc
|
1952
2097
|
};
|
1953
2098
|
postMessage(message);
|
1954
2099
|
};
|
@@ -2207,28 +2352,21 @@ function subscribeToComposition({
|
|
2207
2352
|
}
|
2208
2353
|
|
2209
2354
|
// src/PromptClient.ts
|
2210
|
-
var
|
2211
|
-
var PromptUrl = "/api/v1/prompt";
|
2355
|
+
var import_api9 = require("@uniformdev/context/api");
|
2212
2356
|
var PromptsUrl = "/api/v1/prompts";
|
2213
|
-
var PromptClient = class extends
|
2357
|
+
var PromptClient = class extends import_api9.ApiClient {
|
2214
2358
|
constructor(options) {
|
2215
2359
|
super(options);
|
2216
2360
|
}
|
2217
|
-
/** Fetches
|
2361
|
+
/** Fetches Prompts for a project */
|
2218
2362
|
async get(options) {
|
2219
|
-
const { projectId } = this.options;
|
2220
|
-
const fetchUri = this.createUrl(PromptUrl, { ...options, projectId });
|
2221
|
-
return await this.apiClient(fetchUri);
|
2222
|
-
}
|
2223
|
-
/** Fetches all Prompts for a project */
|
2224
|
-
async getList(options) {
|
2225
2363
|
const { projectId } = this.options;
|
2226
2364
|
const fetchUri = this.createUrl(PromptsUrl, { ...options, projectId });
|
2227
2365
|
return await this.apiClient(fetchUri);
|
2228
2366
|
}
|
2229
2367
|
/** Updates or creates (based on id) a Prompt */
|
2230
2368
|
async upsert(body) {
|
2231
|
-
const fetchUri = this.createUrl(
|
2369
|
+
const fetchUri = this.createUrl(PromptsUrl);
|
2232
2370
|
await this.apiClient(fetchUri, {
|
2233
2371
|
method: "PUT",
|
2234
2372
|
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
@@ -2237,7 +2375,7 @@ var PromptClient = class extends import_api8.ApiClient {
|
|
2237
2375
|
}
|
2238
2376
|
/** Deletes a Prompt */
|
2239
2377
|
async remove(body) {
|
2240
|
-
const fetchUri = this.createUrl(
|
2378
|
+
const fetchUri = this.createUrl(PromptsUrl);
|
2241
2379
|
await this.apiClient(fetchUri, {
|
2242
2380
|
method: "DELETE",
|
2243
2381
|
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
@@ -2247,9 +2385,9 @@ var PromptClient = class extends import_api8.ApiClient {
|
|
2247
2385
|
};
|
2248
2386
|
|
2249
2387
|
// src/RouteClient.ts
|
2250
|
-
var
|
2388
|
+
var import_api10 = require("@uniformdev/context/api");
|
2251
2389
|
var ROUTE_URL = "/api/v1/route";
|
2252
|
-
var RouteClient = class extends
|
2390
|
+
var RouteClient = class extends import_api10.ApiClient {
|
2253
2391
|
constructor(options) {
|
2254
2392
|
var _a;
|
2255
2393
|
if (!options.limitPolicy) {
|
@@ -2266,6 +2404,9 @@ var RouteClient = class extends import_api9.ApiClient {
|
|
2266
2404
|
}
|
2267
2405
|
};
|
2268
2406
|
|
2407
|
+
// src/types/locales.ts
|
2408
|
+
var LOCALE_DYNAMIC_INPUT_NAME = "locale";
|
2409
|
+
|
2269
2410
|
// src/utils/createApiEnhancer.ts
|
2270
2411
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
2271
2412
|
return async (message) => {
|
@@ -2288,6 +2429,23 @@ var createUniformApiEnhancer = ({ apiUrl }) => {
|
|
2288
2429
|
};
|
2289
2430
|
};
|
2290
2431
|
|
2432
|
+
// src/utils/entryConverter.ts
|
2433
|
+
function convertEntryToPutEntry(entry) {
|
2434
|
+
return {
|
2435
|
+
entry: {
|
2436
|
+
type: entry.entry.type,
|
2437
|
+
_dataResources: entry.entry._dataResources,
|
2438
|
+
_id: entry.entry._id,
|
2439
|
+
_name: entry.entry._name,
|
2440
|
+
_slug: entry.entry._slug,
|
2441
|
+
fields: entry.entry.fields,
|
2442
|
+
_locales: entry.entry._locales
|
2443
|
+
},
|
2444
|
+
state: entry.state,
|
2445
|
+
projectId: entry.projectId
|
2446
|
+
};
|
2447
|
+
}
|
2448
|
+
|
2291
2449
|
// src/utils/getParameterAttributes.ts
|
2292
2450
|
var ATTRIBUTE_COMPONENT_ID = "data-uniform-component-id";
|
2293
2451
|
var ATTRIBUTE_PARAMETER_ID = "data-uniform-parameter-id";
|
@@ -2365,6 +2523,9 @@ var isComponentPlaceholderId = (id) => {
|
|
2365
2523
|
if (id === PLACEHOLDER_ID) {
|
2366
2524
|
return true;
|
2367
2525
|
}
|
2526
|
+
if (typeof id !== "string") {
|
2527
|
+
return false;
|
2528
|
+
}
|
2368
2529
|
return id == null ? void 0 : id.startsWith(PLACEHOLDER_ID);
|
2369
2530
|
};
|
2370
2531
|
var generateComponentPlaceholderId = (randomId, sdkVersion) => {
|
@@ -2414,9 +2575,14 @@ function parseVariableExpression(serialized, onToken) {
|
|
2414
2575
|
continue;
|
2415
2576
|
}
|
2416
2577
|
if (char === variableSuffix && state === "variable") {
|
2578
|
+
if (serialized[index - 1] === escapeCharacter) {
|
2579
|
+
bufferEndIndex++;
|
2580
|
+
continue;
|
2581
|
+
}
|
2417
2582
|
state = "text";
|
2418
2583
|
if (bufferEndIndex > bufferStartIndex) {
|
2419
|
-
|
2584
|
+
const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
|
2585
|
+
if (handleToken(unescapedVariableName, "variable") === false) {
|
2420
2586
|
return tokenCount;
|
2421
2587
|
}
|
2422
2588
|
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
@@ -2476,7 +2642,7 @@ var import_immer = require("immer");
|
|
2476
2642
|
|
2477
2643
|
// src/utils/variables/createVariableReference.ts
|
2478
2644
|
function createVariableReference(variableName) {
|
2479
|
-
return `\${${variableName}}`;
|
2645
|
+
return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
|
2480
2646
|
}
|
2481
2647
|
|
2482
2648
|
// src/utils/variables/bindVariablesToObject.ts
|
@@ -2557,10 +2723,13 @@ function handleRichTextNodeBinding(object, options) {
|
|
2557
2723
|
}
|
2558
2724
|
|
2559
2725
|
// src/index.ts
|
2560
|
-
var
|
2561
|
-
var CanvasClientError =
|
2726
|
+
var import_api11 = require("@uniformdev/context/api");
|
2727
|
+
var CanvasClientError = import_api11.ApiClientError;
|
2562
2728
|
// Annotate the CommonJS export names for ESM import in node:
|
2563
2729
|
0 && (module.exports = {
|
2730
|
+
ASSETS_SOURCE_CUSTOM_URL,
|
2731
|
+
ASSETS_SOURCE_UNIFORM,
|
2732
|
+
ASSET_PARAMETER_TYPE,
|
2564
2733
|
ATTRIBUTE_COMPONENT_ID,
|
2565
2734
|
ATTRIBUTE_MULTILINE,
|
2566
2735
|
ATTRIBUTE_PARAMETER_ID,
|
@@ -2604,6 +2773,8 @@ var CanvasClientError = import_api10.ApiClientError;
|
|
2604
2773
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
2605
2774
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
2606
2775
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
2776
|
+
LOCALE_DYNAMIC_INPUT_NAME,
|
2777
|
+
LocaleClient,
|
2607
2778
|
PLACEHOLDER_ID,
|
2608
2779
|
PromptClient,
|
2609
2780
|
RouteClient,
|
@@ -2624,23 +2795,33 @@ var CanvasClientError = import_api10.ApiClientError;
|
|
2624
2795
|
createVariableReference,
|
2625
2796
|
enhance,
|
2626
2797
|
extractLocales,
|
2798
|
+
findParameterInNodeTree,
|
2799
|
+
flattenValues,
|
2627
2800
|
generateComponentPlaceholderId,
|
2628
2801
|
generateHash,
|
2629
2802
|
getBlockValue,
|
2630
2803
|
getChannelName,
|
2631
2804
|
getComponentJsonPointer,
|
2632
2805
|
getComponentPath,
|
2806
|
+
getNounForLocation,
|
2807
|
+
getNounForNode,
|
2633
2808
|
getParameterAttributes,
|
2634
2809
|
getPropertiesValue,
|
2810
|
+
getPropertyValue,
|
2635
2811
|
isAddComponentMessage,
|
2636
2812
|
isAllowedReferrer,
|
2813
|
+
isAssetParamValue,
|
2814
|
+
isAssetParamValueItem,
|
2637
2815
|
isComponentActionMessage,
|
2638
2816
|
isComponentPlaceholderId,
|
2639
2817
|
isDismissPlaceholderMessage,
|
2818
|
+
isEntryData,
|
2640
2819
|
isMovingComponentMessage,
|
2820
|
+
isNestedNodeType,
|
2641
2821
|
isOpenParameterEditorMessage,
|
2642
2822
|
isReadyMessage,
|
2643
2823
|
isReportRenderedCompositionsMessage,
|
2824
|
+
isRootEntryReference,
|
2644
2825
|
isSelectComponentMessage,
|
2645
2826
|
isSelectParameterMessage,
|
2646
2827
|
isSystemComponentDefinition,
|