@uniformdev/canvas 19.61.1 → 19.62.1-alpha.127
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/LICENSE.txt +1 -1
- package/dist/index.d.mts +18936 -7195
- package/dist/index.d.ts +18936 -7195
- package/dist/index.esm.js +611 -201
- package/dist/index.js +649 -217
- package/dist/index.mjs +611 -201
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
@@ -476,12 +476,30 @@ var CanvasClient = class extends ApiClient {
|
|
476
476
|
}
|
477
477
|
super(options);
|
478
478
|
this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
|
479
|
+
this.edgeApiRequestInit = options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0;
|
479
480
|
}
|
480
481
|
/** Fetches lists of Canvas compositions, optionally by type */
|
481
|
-
async getCompositionList(
|
482
|
+
async getCompositionList(params = {}) {
|
482
483
|
const { projectId } = this.options;
|
483
|
-
const
|
484
|
-
|
484
|
+
const { resolveData, filters, ...originParams } = params;
|
485
|
+
const rewrittenFilters = Object.entries(filters != null ? filters : {}).reduce((acc, [key, value]) => {
|
486
|
+
const lhs = `filters.${key}` + (typeof value === "object" ? `[${Object.keys(value)[0]}]` : "");
|
487
|
+
let rhs = typeof value === "object" ? Object.values(value)[0] : value;
|
488
|
+
rhs = Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim();
|
489
|
+
return { ...acc, [lhs]: rhs };
|
490
|
+
}, {});
|
491
|
+
if (!resolveData) {
|
492
|
+
const fetchUri = this.createUrl(CANVAS_URL, { ...originParams, projectId, ...rewrittenFilters });
|
493
|
+
return this.apiClient(fetchUri);
|
494
|
+
}
|
495
|
+
const edgeParams = {
|
496
|
+
...originParams,
|
497
|
+
projectId,
|
498
|
+
...params.diagnostics ? { diagnostics: "true" } : {},
|
499
|
+
...rewrittenFilters
|
500
|
+
};
|
501
|
+
const edgeUrl = this.createUrl("/api/v1/compositions", edgeParams, this.edgeApiHost);
|
502
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
485
503
|
}
|
486
504
|
getCompositionByNodePath(options) {
|
487
505
|
return this.getOneComposition(options);
|
@@ -499,12 +517,12 @@ var CanvasClient = class extends ApiClient {
|
|
499
517
|
return this.getOneComposition(options);
|
500
518
|
}
|
501
519
|
/** Fetches historical versions of a composition or pattern */
|
502
|
-
async
|
503
|
-
const
|
520
|
+
async getCompositionHistory(options) {
|
521
|
+
const historyUrl = this.createUrl("/api/v1/canvas-history", {
|
504
522
|
...options,
|
505
523
|
projectId: this.options.projectId
|
506
524
|
});
|
507
|
-
return this.apiClient(
|
525
|
+
return this.apiClient(historyUrl);
|
508
526
|
}
|
509
527
|
getOneComposition({
|
510
528
|
skipDataResolution,
|
@@ -521,7 +539,7 @@ var CanvasClient = class extends ApiClient {
|
|
521
539
|
...diagnostics ? { diagnostics: "true" } : {}
|
522
540
|
};
|
523
541
|
const edgeUrl = this.createUrl("/api/v1/composition", edgeParams, this.edgeApiHost);
|
524
|
-
return this.apiClient(edgeUrl);
|
542
|
+
return this.apiClient(edgeUrl, this.edgeApiRequestInit);
|
525
543
|
}
|
526
544
|
/** Updates or creates a Canvas component definition */
|
527
545
|
async updateComposition(body) {
|
@@ -546,7 +564,7 @@ var CanvasClient = class extends ApiClient {
|
|
546
564
|
async getComponentDefinitions(options) {
|
547
565
|
const { projectId } = this.options;
|
548
566
|
const fetchUri = this.createUrl("/api/v1/canvas-definitions", { ...options, projectId });
|
549
|
-
return
|
567
|
+
return this.apiClient(fetchUri);
|
550
568
|
}
|
551
569
|
/** Updates or creates a Canvas component definition */
|
552
570
|
async updateComponentDefinition(body) {
|
@@ -616,73 +634,10 @@ var UncachedCategoryClient = class extends CategoryClient {
|
|
616
634
|
}
|
617
635
|
};
|
618
636
|
|
619
|
-
// src/CompositionRelationshipClient.ts
|
620
|
-
import { ApiClient as ApiClient3 } from "@uniformdev/context/api";
|
621
|
-
var COMPOSITION_RELATIONSHIP_URL = "/api/v1/composition-relationships";
|
622
|
-
var unstable_CompositionRelationshipClient = class extends ApiClient3 {
|
623
|
-
constructor(options) {
|
624
|
-
super(options);
|
625
|
-
this.getDefinitionsRelationships = async ({
|
626
|
-
definitionIds,
|
627
|
-
withCompositions
|
628
|
-
}) => {
|
629
|
-
const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL, {
|
630
|
-
type: "definition",
|
631
|
-
projectId: this._options.projectId,
|
632
|
-
definitionIds: definitionIds.join(","),
|
633
|
-
withCompositions
|
634
|
-
});
|
635
|
-
return this.apiClient(url);
|
636
|
-
};
|
637
|
-
this.clearAllRelationships = async () => {
|
638
|
-
const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL);
|
639
|
-
return this.apiClient(url, {
|
640
|
-
method: "POST",
|
641
|
-
body: JSON.stringify({
|
642
|
-
type: "clear",
|
643
|
-
projectId: this._options.projectId
|
644
|
-
})
|
645
|
-
});
|
646
|
-
};
|
647
|
-
this.indexCompositionRelationships = async ({
|
648
|
-
state,
|
649
|
-
compositionId
|
650
|
-
}) => {
|
651
|
-
const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL);
|
652
|
-
return this.apiClient(url, {
|
653
|
-
method: "POST",
|
654
|
-
body: JSON.stringify({
|
655
|
-
type: "index",
|
656
|
-
projectId: this._options.projectId,
|
657
|
-
state,
|
658
|
-
compositionId
|
659
|
-
})
|
660
|
-
});
|
661
|
-
};
|
662
|
-
this.getVersion = async () => {
|
663
|
-
const url = this.createUrl("/api/v1/usage-tracking", {
|
664
|
-
projectId: this._options.projectId
|
665
|
-
});
|
666
|
-
return this.apiClient(url).then((response) => response.version);
|
667
|
-
};
|
668
|
-
this.setVersion = async (version) => {
|
669
|
-
const url = this.createUrl("/api/v1/usage-tracking");
|
670
|
-
return this.apiClient(url, {
|
671
|
-
method: "POST",
|
672
|
-
body: JSON.stringify({
|
673
|
-
projectId: this._options.projectId,
|
674
|
-
version
|
675
|
-
})
|
676
|
-
});
|
677
|
-
};
|
678
|
-
this._options = options;
|
679
|
-
}
|
680
|
-
};
|
681
|
-
|
682
637
|
// src/ContentClient.ts
|
683
|
-
import { ApiClient as
|
638
|
+
import { ApiClient as ApiClient3 } from "@uniformdev/context/api";
|
684
639
|
var _contentTypesUrl, _entriesUrl;
|
685
|
-
var _ContentClient = class _ContentClient extends
|
640
|
+
var _ContentClient = class _ContentClient extends ApiClient3 {
|
686
641
|
constructor(options) {
|
687
642
|
var _a;
|
688
643
|
super(options);
|
@@ -695,16 +650,42 @@ var _ContentClient = class _ContentClient extends ApiClient4 {
|
|
695
650
|
}
|
696
651
|
getEntries(options) {
|
697
652
|
const { projectId } = this.options;
|
698
|
-
const { skipDataResolution, ...params } = options;
|
699
|
-
const
|
700
|
-
|
653
|
+
const { skipDataResolution, filters, ...params } = options;
|
654
|
+
const rewrittenFilters = Object.entries(filters != null ? filters : {}).reduce((acc, [key, value]) => {
|
655
|
+
const lhs = `filters.${key}` + (typeof value === "object" ? `[${Object.keys(value)[0]}]` : "");
|
656
|
+
let rhs = typeof value === "object" ? Object.values(value)[0] : value;
|
657
|
+
rhs = Array.isArray(rhs) ? rhs.map((v) => `${v}`.trim()).join(",") : `${rhs}`.trim();
|
658
|
+
return { ...acc, [lhs]: rhs };
|
659
|
+
}, {});
|
660
|
+
if (skipDataResolution) {
|
661
|
+
const url = this.createUrl(__privateGet(_ContentClient, _entriesUrl), { ...params, ...rewrittenFilters, projectId });
|
662
|
+
return this.apiClient(url);
|
663
|
+
}
|
664
|
+
const edgeUrl = this.createUrl(
|
665
|
+
__privateGet(_ContentClient, _entriesUrl),
|
666
|
+
{ ...this.getEdgeOptions(params), ...rewrittenFilters },
|
667
|
+
this.edgeApiHost
|
668
|
+
);
|
669
|
+
return this.apiClient(
|
670
|
+
edgeUrl,
|
671
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
672
|
+
);
|
701
673
|
}
|
702
|
-
|
674
|
+
/** Fetches historical versions of an entry */
|
675
|
+
async getEntryHistory(options) {
|
676
|
+
const historyUrl = this.createUrl("/api/v1/entries-history", {
|
677
|
+
...options,
|
678
|
+
projectId: this.options.projectId
|
679
|
+
});
|
680
|
+
return this.apiClient(historyUrl);
|
681
|
+
}
|
682
|
+
async upsertContentType(body, opts = {}) {
|
703
683
|
const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl));
|
704
684
|
await this.apiClient(fetchUri, {
|
705
685
|
method: "PUT",
|
706
686
|
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
707
|
-
expectNoContent: true
|
687
|
+
expectNoContent: true,
|
688
|
+
headers: opts.autogenerateDataTypes ? { "x-uniform-autogenerate-data-types": "true" } : {}
|
708
689
|
});
|
709
690
|
}
|
710
691
|
async upsertEntry(body) {
|
@@ -753,10 +734,10 @@ var UncachedContentClient = class extends ContentClient {
|
|
753
734
|
};
|
754
735
|
|
755
736
|
// src/DataSourceClient.ts
|
756
|
-
import { ApiClient as
|
737
|
+
import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
|
757
738
|
var dataSourceUrl = "/api/v1/data-source";
|
758
739
|
var dataSourcesUrl = "/api/v1/data-sources";
|
759
|
-
var DataSourceClient = class extends
|
740
|
+
var DataSourceClient = class extends ApiClient4 {
|
760
741
|
constructor(options) {
|
761
742
|
super(options);
|
762
743
|
}
|
@@ -793,9 +774,9 @@ var DataSourceClient = class extends ApiClient5 {
|
|
793
774
|
};
|
794
775
|
|
795
776
|
// src/DataTypeClient.ts
|
796
|
-
import { ApiClient as
|
777
|
+
import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
|
797
778
|
var _url;
|
798
|
-
var _DataTypeClient = class _DataTypeClient extends
|
779
|
+
var _DataTypeClient = class _DataTypeClient extends ApiClient5 {
|
799
780
|
constructor(options) {
|
800
781
|
super(options);
|
801
782
|
}
|
@@ -951,12 +932,14 @@ function getComponentPath(ancestorsAndSelf) {
|
|
951
932
|
var CANVAS_PERSONALIZE_TYPE = "$personalization";
|
952
933
|
var CANVAS_TEST_TYPE = "$test";
|
953
934
|
var CANVAS_LOCALIZATION_TYPE = "$localization";
|
935
|
+
var CANVAS_SLOT_SECTION_TYPE = "$slotSection";
|
954
936
|
var CANVAS_INTENT_TAG_PARAM = "intentTag";
|
955
937
|
var CANVAS_LOCALE_TAG_PARAM = "locale";
|
956
938
|
var CANVAS_BLOCK_PARAM_TYPE = "$block";
|
957
939
|
var CANVAS_PERSONALIZE_SLOT = "pz";
|
958
940
|
var CANVAS_TEST_SLOT = "test";
|
959
941
|
var CANVAS_LOCALIZATION_SLOT = "localized";
|
942
|
+
var CANVAS_SLOT_SECTION_SLOT = "$slotSectionItems";
|
960
943
|
var CANVAS_DRAFT_STATE = 0;
|
961
944
|
var CANVAS_PUBLISHED_STATE = 64;
|
962
945
|
var CANVAS_EDITOR_STATE = 63;
|
@@ -966,6 +949,7 @@ var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
|
|
966
949
|
var SECRET_QUERY_STRING_PARAM = "secret";
|
967
950
|
var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
|
968
951
|
var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
|
952
|
+
var IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM = "is_incontext_editing_forced_settings";
|
969
953
|
var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
|
970
954
|
var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
|
971
955
|
var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
|
@@ -977,31 +961,79 @@ var EMPTY_COMPOSITION = {
|
|
977
961
|
_name: "An empty composition used for contextual editing",
|
978
962
|
type: "_empty_composition_type"
|
979
963
|
};
|
980
|
-
var EDGE_MIN_CACHE_TTL =
|
981
|
-
var EDGE_MAX_CACHE_TTL =
|
964
|
+
var EDGE_MIN_CACHE_TTL = 10;
|
965
|
+
var EDGE_MAX_CACHE_TTL = 24 * 60 * 60;
|
982
966
|
var EDGE_DEFAULT_CACHE_TTL = 30;
|
983
967
|
var EDGE_CACHE_DISABLED = -1;
|
984
|
-
var
|
985
|
-
var
|
986
|
-
var
|
968
|
+
var ASSET_PARAMETER_TYPE = "asset";
|
969
|
+
var ASSETS_SOURCE_UNIFORM = "uniform-assets";
|
970
|
+
var ASSETS_SOURCE_CUSTOM_URL = "custom-url";
|
987
971
|
|
988
|
-
// src/utils/
|
989
|
-
function
|
990
|
-
return
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
972
|
+
// src/utils/guards.ts
|
973
|
+
function isRootEntryReference(root) {
|
974
|
+
return root.type === "root" && isEntryData(root.node);
|
975
|
+
}
|
976
|
+
function isEntryData(entryData) {
|
977
|
+
return Boolean(entryData && typeof entryData === "object" && "fields" in entryData);
|
978
|
+
}
|
979
|
+
function isAssetParamValue(value) {
|
980
|
+
return Array.isArray(value) && (value.length > 0 ? isAssetParamValueItem(value[0]) : true);
|
981
|
+
}
|
982
|
+
function isAssetParamValueItem(item) {
|
983
|
+
return Boolean(
|
984
|
+
item instanceof Object && "_source" in item && "fields" in item && item.fields instanceof Object && "url" in item.fields && item.fields.url instanceof Object
|
985
|
+
);
|
1001
986
|
}
|
987
|
+
|
988
|
+
// src/utils/properties.ts
|
1002
989
|
function getPropertiesValue(entity) {
|
1003
990
|
return "parameters" in entity && entity.parameters ? entity.parameters : "fields" in entity && entity.fields ? entity.fields : void 0;
|
1004
991
|
}
|
992
|
+
function getPropertyValue(parameter) {
|
993
|
+
return parameter ? parameter.value : parameter;
|
994
|
+
}
|
995
|
+
function getLocalizedPropertyValues(parameter) {
|
996
|
+
if (!parameter) {
|
997
|
+
return parameter;
|
998
|
+
}
|
999
|
+
const localizedValues = /* @__PURE__ */ new Map();
|
1000
|
+
if (typeof parameter.value !== "undefined") {
|
1001
|
+
localizedValues.set(void 0, parameter.value);
|
1002
|
+
}
|
1003
|
+
if (parameter.locales !== void 0) {
|
1004
|
+
for (const [locale, localeValue] of Object.entries(parameter.locales)) {
|
1005
|
+
localizedValues.set(locale, localeValue);
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
return localizedValues;
|
1009
|
+
}
|
1010
|
+
function flattenValues(data, options = {}) {
|
1011
|
+
if (!data) {
|
1012
|
+
return data;
|
1013
|
+
} else if (Array.isArray(data) && options.toSingle) {
|
1014
|
+
return data.length > 0 ? flattenSingleNodeValues(data[0]) : void 0;
|
1015
|
+
} else if (Array.isArray(data)) {
|
1016
|
+
return data.map((node) => flattenSingleNodeValues(node, options));
|
1017
|
+
} else {
|
1018
|
+
return flattenSingleNodeValues(data, options);
|
1019
|
+
}
|
1020
|
+
}
|
1021
|
+
function flattenSingleNodeValues(data, options = {}) {
|
1022
|
+
const { levels = 1 } = options;
|
1023
|
+
const properties = getPropertiesValue(data);
|
1024
|
+
return properties ? Object.fromEntries(
|
1025
|
+
Object.entries(properties).map(([id, parameter]) => {
|
1026
|
+
const value = getPropertyValue(parameter);
|
1027
|
+
if (levels > 0 && Array.isArray(value) && // In the future ASSET_PARAMETER_TYPE will be a nested data type
|
1028
|
+
(isNestedNodeType(parameter.type) || parameter.type === ASSET_PARAMETER_TYPE)) {
|
1029
|
+
const nestedOptions = { ...options, levels: levels - 1 };
|
1030
|
+
return [id, value.map((item) => flattenValues(item, nestedOptions))];
|
1031
|
+
} else {
|
1032
|
+
return [id, value];
|
1033
|
+
}
|
1034
|
+
})
|
1035
|
+
) : properties;
|
1036
|
+
}
|
1005
1037
|
|
1006
1038
|
// src/enhancement/walkNodeTree.ts
|
1007
1039
|
function walkNodeTree(node, visitor, options) {
|
@@ -1021,7 +1053,83 @@ function walkNodeTree(node, visitor, options) {
|
|
1021
1053
|
let visitDescendants = true;
|
1022
1054
|
let descendantContext = (_a = childContexts.get(currentComponent.node)) != null ? _a : currentQueueEntry.context;
|
1023
1055
|
let visitorInfo;
|
1024
|
-
if (currentComponent.type === "root" || currentComponent.type === "
|
1056
|
+
if (currentComponent.type === "root" && isRootEntryReference(currentComponent) || currentComponent.type === "block") {
|
1057
|
+
visitorInfo = {
|
1058
|
+
type: "entry",
|
1059
|
+
node: currentComponent.node,
|
1060
|
+
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
1061
|
+
actions: {
|
1062
|
+
replace: (replacementNode) => {
|
1063
|
+
Object.assign(currentComponent.node, replacementNode);
|
1064
|
+
const propertiesToCheck = ["fields", "_dataResources", "_author"];
|
1065
|
+
propertiesToCheck.forEach((property) => {
|
1066
|
+
if (!replacementNode[property]) {
|
1067
|
+
delete currentComponent.node[property];
|
1068
|
+
}
|
1069
|
+
});
|
1070
|
+
},
|
1071
|
+
remove: () => {
|
1072
|
+
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
1073
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1074
|
+
if (currentComponentLocation.type === "block") {
|
1075
|
+
const { fieldName, blockIndex } = currentComponentLocation;
|
1076
|
+
const blockValue = getBlockValue(parentComponent.node, fieldName);
|
1077
|
+
blockValue.splice(blockIndex, 1);
|
1078
|
+
if (blockValue.length === 0) {
|
1079
|
+
const properties2 = getPropertiesValue(parentComponent.node);
|
1080
|
+
delete properties2[fieldName];
|
1081
|
+
}
|
1082
|
+
} else {
|
1083
|
+
throw new Error("Unknown node type");
|
1084
|
+
}
|
1085
|
+
},
|
1086
|
+
insertAfter: (nodes) => {
|
1087
|
+
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
1088
|
+
if (currentNodeInfo.type !== "block") {
|
1089
|
+
throw new Error("Unknown type");
|
1090
|
+
}
|
1091
|
+
const { fieldName, blockIndex } = currentNodeInfo;
|
1092
|
+
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1093
|
+
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
1094
|
+
if (fieldName && typeof blockIndex !== "undefined") {
|
1095
|
+
getPropertiesValue(parentComponent.node)[fieldName].value.splice(
|
1096
|
+
blockIndex + 1,
|
1097
|
+
0,
|
1098
|
+
...nodesToInsert
|
1099
|
+
);
|
1100
|
+
componentQueue.unshift(
|
1101
|
+
...nodesToInsert.map((enqueueingComponent) => ({
|
1102
|
+
ancestorsAndSelf: [
|
1103
|
+
{
|
1104
|
+
type: "block",
|
1105
|
+
node: enqueueingComponent,
|
1106
|
+
fieldName,
|
1107
|
+
get blockIndex() {
|
1108
|
+
const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
|
1109
|
+
return parentArray.findIndex((x) => x === enqueueingComponent);
|
1110
|
+
}
|
1111
|
+
},
|
1112
|
+
// slice removes 'self' since we are inserting a peer of self
|
1113
|
+
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
1114
|
+
],
|
1115
|
+
context: descendantContext
|
1116
|
+
}))
|
1117
|
+
);
|
1118
|
+
}
|
1119
|
+
},
|
1120
|
+
stopProcessingDescendants() {
|
1121
|
+
visitDescendants = false;
|
1122
|
+
},
|
1123
|
+
setDescendantsContext(context) {
|
1124
|
+
descendantContext = context;
|
1125
|
+
},
|
1126
|
+
setChildContext(child, context) {
|
1127
|
+
childContexts.set(child, context);
|
1128
|
+
}
|
1129
|
+
},
|
1130
|
+
context: descendantContext
|
1131
|
+
};
|
1132
|
+
} else {
|
1025
1133
|
visitorInfo = {
|
1026
1134
|
type: "component",
|
1027
1135
|
node: currentComponent.node,
|
@@ -1112,82 +1220,6 @@ function walkNodeTree(node, visitor, options) {
|
|
1112
1220
|
},
|
1113
1221
|
context: descendantContext
|
1114
1222
|
};
|
1115
|
-
} else {
|
1116
|
-
visitorInfo = {
|
1117
|
-
type: "entry",
|
1118
|
-
node: currentComponent.node,
|
1119
|
-
ancestorsAndSelf: currentQueueEntry.ancestorsAndSelf,
|
1120
|
-
actions: {
|
1121
|
-
replace: (replacementNode) => {
|
1122
|
-
Object.assign(currentComponent.node, replacementNode);
|
1123
|
-
const propertiesToCheck = ["fields", "_dataResources", "_author"];
|
1124
|
-
propertiesToCheck.forEach((property) => {
|
1125
|
-
if (!replacementNode[property]) {
|
1126
|
-
delete currentComponent.node[property];
|
1127
|
-
}
|
1128
|
-
});
|
1129
|
-
},
|
1130
|
-
remove: () => {
|
1131
|
-
const currentComponentLocation = currentQueueEntry.ancestorsAndSelf[0];
|
1132
|
-
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1133
|
-
if (currentComponentLocation.type === "block") {
|
1134
|
-
const { fieldName, blockIndex } = currentComponentLocation;
|
1135
|
-
const blockValue = getBlockValue(parentComponent.node, fieldName);
|
1136
|
-
blockValue.splice(blockIndex, 1);
|
1137
|
-
if (blockValue.length === 0) {
|
1138
|
-
const properties2 = getPropertiesValue(parentComponent.node);
|
1139
|
-
delete properties2[fieldName];
|
1140
|
-
}
|
1141
|
-
} else {
|
1142
|
-
throw new Error("Unknown node type");
|
1143
|
-
}
|
1144
|
-
},
|
1145
|
-
insertAfter: (nodes) => {
|
1146
|
-
const currentNodeInfo = currentQueueEntry.ancestorsAndSelf[0];
|
1147
|
-
if (currentNodeInfo.type !== "block") {
|
1148
|
-
throw new Error("Unknown type");
|
1149
|
-
}
|
1150
|
-
const { fieldName, blockIndex } = currentNodeInfo;
|
1151
|
-
const parentComponent = currentQueueEntry.ancestorsAndSelf[1];
|
1152
|
-
const nodesToInsert = Array.isArray(nodes) ? nodes : [nodes];
|
1153
|
-
if (fieldName && typeof blockIndex !== "undefined") {
|
1154
|
-
getPropertiesValue(parentComponent.node)[fieldName].value.splice(
|
1155
|
-
blockIndex + 1,
|
1156
|
-
0,
|
1157
|
-
...nodesToInsert
|
1158
|
-
);
|
1159
|
-
componentQueue.unshift(
|
1160
|
-
...nodesToInsert.map((enqueueingComponent) => ({
|
1161
|
-
ancestorsAndSelf: [
|
1162
|
-
{
|
1163
|
-
type: "block",
|
1164
|
-
node: enqueueingComponent,
|
1165
|
-
fieldName,
|
1166
|
-
get blockIndex() {
|
1167
|
-
const parentArray = getPropertiesValue(parentComponent.node)[fieldName].value;
|
1168
|
-
return parentArray.findIndex((x) => x === enqueueingComponent);
|
1169
|
-
}
|
1170
|
-
},
|
1171
|
-
// slice removes 'self' since we are inserting a peer of self
|
1172
|
-
...currentQueueEntry.ancestorsAndSelf.slice(1)
|
1173
|
-
],
|
1174
|
-
context: descendantContext
|
1175
|
-
}))
|
1176
|
-
);
|
1177
|
-
}
|
1178
|
-
},
|
1179
|
-
stopProcessingDescendants() {
|
1180
|
-
visitDescendants = false;
|
1181
|
-
},
|
1182
|
-
setDescendantsContext(context) {
|
1183
|
-
descendantContext = context;
|
1184
|
-
},
|
1185
|
-
setChildContext(child, context) {
|
1186
|
-
childContexts.set(child, context);
|
1187
|
-
}
|
1188
|
-
},
|
1189
|
-
context: descendantContext
|
1190
|
-
};
|
1191
1223
|
}
|
1192
1224
|
visitor(visitorInfo);
|
1193
1225
|
if (!visitDescendants) {
|
@@ -1225,7 +1257,7 @@ function walkNodeTree(node, visitor, options) {
|
|
1225
1257
|
const propertyEntries = Object.entries(properties);
|
1226
1258
|
for (let propIndex = propertyEntries.length - 1; propIndex >= 0; propIndex--) {
|
1227
1259
|
const [propKey, propObject] = propertyEntries[propIndex];
|
1228
|
-
if (propObject.type
|
1260
|
+
if (!isNestedNodeType(propObject.type))
|
1229
1261
|
continue;
|
1230
1262
|
const blocks = (_b = propObject.value) != null ? _b : [];
|
1231
1263
|
for (let blockIndex = blocks.length - 1; blockIndex >= 0; blockIndex--) {
|
@@ -1251,6 +1283,9 @@ function walkNodeTree(node, visitor, options) {
|
|
1251
1283
|
}
|
1252
1284
|
} while (componentQueue.length > 0);
|
1253
1285
|
}
|
1286
|
+
function isNestedNodeType(type) {
|
1287
|
+
return type === CANVAS_BLOCK_PARAM_TYPE;
|
1288
|
+
}
|
1254
1289
|
function getBlockValue(component, parameterName) {
|
1255
1290
|
var _a;
|
1256
1291
|
const parameter = (_a = getPropertiesValue(component)) == null ? void 0 : _a[parameterName];
|
@@ -1519,7 +1554,7 @@ function getComponentJsonPointer(ancestorsAndSelf) {
|
|
1519
1554
|
if (currentLocation.type === "block") {
|
1520
1555
|
const { fieldName: parameterName, blockIndex } = currentLocation;
|
1521
1556
|
if (parameterName && blockIndex !== void 0) {
|
1522
|
-
const noun = parentLocation
|
1557
|
+
const noun = getNounForLocation(parentLocation);
|
1523
1558
|
path.push(`${noun}/${parameterName}/value/${blockIndex}`);
|
1524
1559
|
}
|
1525
1560
|
} else {
|
@@ -1533,6 +1568,40 @@ function getComponentJsonPointer(ancestorsAndSelf) {
|
|
1533
1568
|
}
|
1534
1569
|
return `/${path.join("/")}`;
|
1535
1570
|
}
|
1571
|
+
function getNounForLocation(parentLocation) {
|
1572
|
+
let noun = "parameters";
|
1573
|
+
if (parentLocation && "type" in parentLocation) {
|
1574
|
+
if (parentLocation.type === "block" || isRootEntryReference(parentLocation)) {
|
1575
|
+
noun = "fields";
|
1576
|
+
}
|
1577
|
+
}
|
1578
|
+
return noun;
|
1579
|
+
}
|
1580
|
+
function getNounForNode(node) {
|
1581
|
+
let noun = "parameters";
|
1582
|
+
if (isEntryData(node)) {
|
1583
|
+
noun = "fields";
|
1584
|
+
}
|
1585
|
+
return noun;
|
1586
|
+
}
|
1587
|
+
|
1588
|
+
// src/enhancement/findInNodeTree.ts
|
1589
|
+
function findParameterInNodeTree(data, predicate) {
|
1590
|
+
const results = [];
|
1591
|
+
walkNodeTree(data, ({ node, ancestorsAndSelf }) => {
|
1592
|
+
const parameters = getPropertiesValue(node);
|
1593
|
+
if (parameters) {
|
1594
|
+
Object.entries(parameters).filter(([key, field]) => predicate(field, key, node)).forEach(([key, field]) => {
|
1595
|
+
results.push({
|
1596
|
+
key,
|
1597
|
+
pointer: (ancestorsAndSelf.length === 1 ? "" : getComponentJsonPointer(ancestorsAndSelf)) + `/${getNounForNode(node)}/${key}`,
|
1598
|
+
parameter: field
|
1599
|
+
});
|
1600
|
+
});
|
1601
|
+
}
|
1602
|
+
});
|
1603
|
+
return results;
|
1604
|
+
}
|
1536
1605
|
|
1537
1606
|
// src/enhancement/localize.ts
|
1538
1607
|
function extractLocales({ component }) {
|
@@ -1549,23 +1618,31 @@ function extractLocales({ component }) {
|
|
1549
1618
|
});
|
1550
1619
|
return variations;
|
1551
1620
|
}
|
1552
|
-
function localize({
|
1553
|
-
composition
|
1554
|
-
locale
|
1555
|
-
}) {
|
1556
|
-
walkNodeTree(composition, ({ type, node, actions }) => {
|
1621
|
+
function localize(options) {
|
1622
|
+
const nodes = "nodes" in options ? options.nodes : options.composition;
|
1623
|
+
const locale = options.locale;
|
1624
|
+
walkNodeTree(nodes, ({ type, node, actions }) => {
|
1557
1625
|
if (type !== "component") {
|
1558
|
-
|
1626
|
+
if (typeof locale === "string") {
|
1627
|
+
localizeProperties(node.fields, locale);
|
1628
|
+
}
|
1559
1629
|
return;
|
1560
1630
|
}
|
1631
|
+
const shouldRunPropertyLocalization = typeof locale === "string";
|
1561
1632
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1562
1633
|
const locales = extractLocales({ component: node });
|
1563
|
-
const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
|
1634
|
+
const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
|
1564
1635
|
let replaceComponent;
|
1565
1636
|
if (resolvedLocale) {
|
1566
1637
|
replaceComponent = locales[resolvedLocale];
|
1567
1638
|
}
|
1568
1639
|
if (replaceComponent == null ? void 0 : replaceComponent.length) {
|
1640
|
+
replaceComponent.forEach((component) => {
|
1641
|
+
removeLocaleProperty(component);
|
1642
|
+
if (shouldRunPropertyLocalization) {
|
1643
|
+
localizeProperties(getPropertiesValue(component), locale);
|
1644
|
+
}
|
1645
|
+
});
|
1569
1646
|
const [first, ...rest] = replaceComponent;
|
1570
1647
|
actions.replace(first);
|
1571
1648
|
if (rest.length) {
|
@@ -1574,6 +1651,42 @@ function localize({
|
|
1574
1651
|
} else {
|
1575
1652
|
actions.remove();
|
1576
1653
|
}
|
1654
|
+
} else if (shouldRunPropertyLocalization) {
|
1655
|
+
localizeProperties(getPropertiesValue(node), locale);
|
1656
|
+
}
|
1657
|
+
});
|
1658
|
+
}
|
1659
|
+
function removeLocaleProperty(component) {
|
1660
|
+
const properties = getPropertiesValue(component);
|
1661
|
+
const localeTagProperty = properties == null ? void 0 : properties[CANVAS_LOCALE_TAG_PARAM];
|
1662
|
+
if (localeTagProperty) {
|
1663
|
+
delete properties[CANVAS_LOCALE_TAG_PARAM];
|
1664
|
+
}
|
1665
|
+
if (properties && Object.keys(properties).length === 0) {
|
1666
|
+
if ("fields" in component) {
|
1667
|
+
delete component.fields;
|
1668
|
+
}
|
1669
|
+
if ("parameters" in component) {
|
1670
|
+
delete component.parameters;
|
1671
|
+
}
|
1672
|
+
}
|
1673
|
+
}
|
1674
|
+
function localizeProperties(properties, locale) {
|
1675
|
+
if (!properties) {
|
1676
|
+
return void 0;
|
1677
|
+
}
|
1678
|
+
Object.entries(properties).forEach(([key, property]) => {
|
1679
|
+
var _a;
|
1680
|
+
if (!locale) {
|
1681
|
+
delete property.locales;
|
1682
|
+
}
|
1683
|
+
const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
|
1684
|
+
if (currentLocaleValue !== void 0) {
|
1685
|
+
property.value = currentLocaleValue;
|
1686
|
+
}
|
1687
|
+
delete property.locales;
|
1688
|
+
if (property.value === void 0) {
|
1689
|
+
delete properties[key];
|
1577
1690
|
}
|
1578
1691
|
});
|
1579
1692
|
}
|
@@ -1723,6 +1836,39 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1723
1836
|
} while (componentQueue.length > 0);
|
1724
1837
|
}
|
1725
1838
|
|
1839
|
+
// src/LocaleClient.ts
|
1840
|
+
import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
|
1841
|
+
var localesUrl = "/api/v1/locales";
|
1842
|
+
var LocaleClient = class extends ApiClient6 {
|
1843
|
+
constructor(options) {
|
1844
|
+
super(options);
|
1845
|
+
}
|
1846
|
+
/** Fetches all locales for a project */
|
1847
|
+
async get(options) {
|
1848
|
+
const { projectId } = this.options;
|
1849
|
+
const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
|
1850
|
+
return await this.apiClient(fetchUri);
|
1851
|
+
}
|
1852
|
+
/** Updates or creates (based on id) a locale */
|
1853
|
+
async upsert(body) {
|
1854
|
+
const fetchUri = this.createUrl(localesUrl);
|
1855
|
+
await this.apiClient(fetchUri, {
|
1856
|
+
method: "PUT",
|
1857
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
1858
|
+
expectNoContent: true
|
1859
|
+
});
|
1860
|
+
}
|
1861
|
+
/** Deletes a locale */
|
1862
|
+
async remove(body) {
|
1863
|
+
const fetchUri = this.createUrl(localesUrl);
|
1864
|
+
await this.apiClient(fetchUri, {
|
1865
|
+
method: "DELETE",
|
1866
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
1867
|
+
expectNoContent: true
|
1868
|
+
});
|
1869
|
+
}
|
1870
|
+
};
|
1871
|
+
|
1726
1872
|
// src/utils/hash.ts
|
1727
1873
|
var generateHash = ({
|
1728
1874
|
composition,
|
@@ -1793,6 +1939,12 @@ var isOpenParameterEditorMessage = (message) => {
|
|
1793
1939
|
var isUpdateComponentReferencesMessage = (message) => {
|
1794
1940
|
return message.type === "update-component-references";
|
1795
1941
|
};
|
1942
|
+
var isRequestComponentSuggestionMessage = (message) => {
|
1943
|
+
return message.type === "request-component-suggestion";
|
1944
|
+
};
|
1945
|
+
var isSuggestComponentMessage = (message) => {
|
1946
|
+
return message.type === "suggest-component";
|
1947
|
+
};
|
1796
1948
|
var createCanvasChannel = ({
|
1797
1949
|
listenTo,
|
1798
1950
|
broadcastTo
|
@@ -1801,7 +1953,13 @@ var createCanvasChannel = ({
|
|
1801
1953
|
const handlers = {};
|
1802
1954
|
const broadcastToItems = [...broadcastTo];
|
1803
1955
|
const postMessage = (message) => {
|
1804
|
-
broadcastToItems.forEach((item) => item.postMessage(JSON.stringify(message), "*"));
|
1956
|
+
broadcastToItems.forEach((item) => item == null ? void 0 : item.postMessage(JSON.stringify(message), "*"));
|
1957
|
+
for (const handlerId in handlers) {
|
1958
|
+
const handler = handlers[handlerId];
|
1959
|
+
if (handler.types.includes(message.type)) {
|
1960
|
+
handler.handler(message, new MessageEvent(message.type));
|
1961
|
+
}
|
1962
|
+
}
|
1805
1963
|
};
|
1806
1964
|
const selectComponent = (id) => {
|
1807
1965
|
const message = {
|
@@ -1810,7 +1968,7 @@ var createCanvasChannel = ({
|
|
1810
1968
|
};
|
1811
1969
|
postMessage(message);
|
1812
1970
|
};
|
1813
|
-
const ready = () => {
|
1971
|
+
const ready = (options) => {
|
1814
1972
|
var _a, _b;
|
1815
1973
|
if (typeof window === "undefined") {
|
1816
1974
|
return;
|
@@ -1820,7 +1978,8 @@ var createCanvasChannel = ({
|
|
1820
1978
|
const message = {
|
1821
1979
|
type: "ready",
|
1822
1980
|
framework,
|
1823
|
-
version
|
1981
|
+
version,
|
1982
|
+
rsc: options == null ? void 0 : options.rsc
|
1824
1983
|
};
|
1825
1984
|
postMessage(message);
|
1826
1985
|
};
|
@@ -1943,6 +2102,20 @@ var createCanvasChannel = ({
|
|
1943
2102
|
};
|
1944
2103
|
postMessage(message);
|
1945
2104
|
};
|
2105
|
+
const requestComponentSuggestion = (options) => {
|
2106
|
+
const message = {
|
2107
|
+
...options,
|
2108
|
+
type: "request-component-suggestion"
|
2109
|
+
};
|
2110
|
+
postMessage(message);
|
2111
|
+
};
|
2112
|
+
const suggestComponent = (options) => {
|
2113
|
+
const message = {
|
2114
|
+
...options,
|
2115
|
+
type: "suggest-component"
|
2116
|
+
};
|
2117
|
+
postMessage(message);
|
2118
|
+
};
|
1946
2119
|
const updateFeatureFlags = (options) => {
|
1947
2120
|
const message = {
|
1948
2121
|
...options,
|
@@ -1996,7 +2169,9 @@ var createCanvasChannel = ({
|
|
1996
2169
|
openParameterEditor,
|
1997
2170
|
reportRenderedCompositions,
|
1998
2171
|
editorStateUpdated,
|
1999
|
-
updateComponentReferences
|
2172
|
+
updateComponentReferences,
|
2173
|
+
requestComponentSuggestion,
|
2174
|
+
suggestComponent
|
2000
2175
|
};
|
2001
2176
|
};
|
2002
2177
|
|
@@ -2078,10 +2253,166 @@ function subscribeToComposition({
|
|
2078
2253
|
};
|
2079
2254
|
}
|
2080
2255
|
|
2081
|
-
// src/
|
2256
|
+
// src/PromptClient.ts
|
2082
2257
|
import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
|
2258
|
+
var PromptsUrl = "/api/v1/prompts";
|
2259
|
+
var PromptClient = class extends ApiClient7 {
|
2260
|
+
constructor(options) {
|
2261
|
+
super(options);
|
2262
|
+
}
|
2263
|
+
/** Fetches Prompts for a project */
|
2264
|
+
async get(options) {
|
2265
|
+
const { projectId } = this.options;
|
2266
|
+
const fetchUri = this.createUrl(PromptsUrl, { ...options, projectId });
|
2267
|
+
return await this.apiClient(fetchUri);
|
2268
|
+
}
|
2269
|
+
/** Updates or creates (based on id) a Prompt */
|
2270
|
+
async upsert(body) {
|
2271
|
+
const fetchUri = this.createUrl(PromptsUrl);
|
2272
|
+
await this.apiClient(fetchUri, {
|
2273
|
+
method: "PUT",
|
2274
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
2275
|
+
expectNoContent: true
|
2276
|
+
});
|
2277
|
+
}
|
2278
|
+
/** Deletes a Prompt */
|
2279
|
+
async remove(body) {
|
2280
|
+
const fetchUri = this.createUrl(PromptsUrl);
|
2281
|
+
await this.apiClient(fetchUri, {
|
2282
|
+
method: "DELETE",
|
2283
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
2284
|
+
expectNoContent: true
|
2285
|
+
});
|
2286
|
+
}
|
2287
|
+
};
|
2288
|
+
|
2289
|
+
// src/RelationshipClient.ts
|
2290
|
+
import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
|
2291
|
+
var RELATIONSHIPS_URL = "/api/v1/relationships";
|
2292
|
+
var RelationshipClient = class extends ApiClient8 {
|
2293
|
+
constructor(options) {
|
2294
|
+
super(options);
|
2295
|
+
this.get = async (options) => {
|
2296
|
+
const { projectId } = this.options;
|
2297
|
+
const url = this.createUrl(RELATIONSHIPS_URL, { ...options, projectId });
|
2298
|
+
return this.apiClient(url);
|
2299
|
+
};
|
2300
|
+
this.clearProjectRelationships = async () => {
|
2301
|
+
const { projectId } = this.options;
|
2302
|
+
const url = this.createUrl(RELATIONSHIPS_URL);
|
2303
|
+
return this.apiClient(url, {
|
2304
|
+
method: "POST",
|
2305
|
+
body: JSON.stringify({
|
2306
|
+
action: "clear",
|
2307
|
+
projectId
|
2308
|
+
})
|
2309
|
+
});
|
2310
|
+
};
|
2311
|
+
this.indexRelationships = async ({ state, id, type }) => {
|
2312
|
+
const { projectId } = this.options;
|
2313
|
+
const url = this.createUrl(RELATIONSHIPS_URL);
|
2314
|
+
return this.apiClient(url, {
|
2315
|
+
method: "POST",
|
2316
|
+
body: JSON.stringify({
|
2317
|
+
action: "index",
|
2318
|
+
type,
|
2319
|
+
projectId,
|
2320
|
+
state,
|
2321
|
+
id
|
2322
|
+
})
|
2323
|
+
});
|
2324
|
+
};
|
2325
|
+
this.getVersion = async () => {
|
2326
|
+
const { projectId } = this.options;
|
2327
|
+
const url = this.createUrl("/api/v1/usage-tracking", {
|
2328
|
+
projectId
|
2329
|
+
});
|
2330
|
+
return this.apiClient(url).then((response) => response.version);
|
2331
|
+
};
|
2332
|
+
this.setVersion = async (version) => {
|
2333
|
+
const { projectId } = this.options;
|
2334
|
+
const url = this.createUrl("/api/v1/usage-tracking");
|
2335
|
+
return this.apiClient(url, {
|
2336
|
+
method: "POST",
|
2337
|
+
body: JSON.stringify({
|
2338
|
+
projectId,
|
2339
|
+
version
|
2340
|
+
})
|
2341
|
+
});
|
2342
|
+
};
|
2343
|
+
}
|
2344
|
+
};
|
2345
|
+
|
2346
|
+
// src/ReleaseClient.ts
|
2347
|
+
import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
|
2348
|
+
var releasesUrl = "/api/v1/releases";
|
2349
|
+
var ReleaseClient = class extends ApiClient9 {
|
2350
|
+
constructor(options) {
|
2351
|
+
super(options);
|
2352
|
+
}
|
2353
|
+
/** Fetches all releases for a project */
|
2354
|
+
async get(options) {
|
2355
|
+
const { projectId } = this.options;
|
2356
|
+
const fetchUri = this.createUrl(releasesUrl, { ...options, projectId });
|
2357
|
+
return await this.apiClient(fetchUri);
|
2358
|
+
}
|
2359
|
+
/** Updates or creates (based on id) a release */
|
2360
|
+
async upsert(body) {
|
2361
|
+
const fetchUri = this.createUrl(releasesUrl);
|
2362
|
+
await this.apiClient(fetchUri, {
|
2363
|
+
method: "PUT",
|
2364
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
2365
|
+
expectNoContent: true
|
2366
|
+
});
|
2367
|
+
}
|
2368
|
+
/** Deletes a release */
|
2369
|
+
async remove(body) {
|
2370
|
+
const fetchUri = this.createUrl(releasesUrl);
|
2371
|
+
await this.apiClient(fetchUri, {
|
2372
|
+
method: "DELETE",
|
2373
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
2374
|
+
expectNoContent: true
|
2375
|
+
});
|
2376
|
+
}
|
2377
|
+
/** Readies or unreadies a release for merging */
|
2378
|
+
async ready(body) {
|
2379
|
+
const fetchUri = this.createUrl(releasesUrl);
|
2380
|
+
await this.apiClient(fetchUri, {
|
2381
|
+
method: "PATCH",
|
2382
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
2383
|
+
expectNoContent: true
|
2384
|
+
});
|
2385
|
+
}
|
2386
|
+
};
|
2387
|
+
|
2388
|
+
// src/ReleaseContentsClient.ts
|
2389
|
+
import { ApiClient as ApiClient10 } from "@uniformdev/context/api";
|
2390
|
+
var releaseContentsUrl = "/api/v1/release-contents";
|
2391
|
+
var ReleaseContentsClient = class extends ApiClient10 {
|
2392
|
+
constructor(options) {
|
2393
|
+
super(options);
|
2394
|
+
}
|
2395
|
+
/** Fetches all entities added to a release */
|
2396
|
+
async get(options) {
|
2397
|
+
const { projectId } = this.options;
|
2398
|
+
const fetchUri = this.createUrl(releaseContentsUrl, { ...options, projectId });
|
2399
|
+
return await this.apiClient(fetchUri);
|
2400
|
+
}
|
2401
|
+
/** Removes a release content from a release */
|
2402
|
+
async remove(body) {
|
2403
|
+
const fetchUri = this.createUrl(releaseContentsUrl);
|
2404
|
+
await this.apiClient(fetchUri, {
|
2405
|
+
method: "DELETE",
|
2406
|
+
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
2407
|
+
expectNoContent: true
|
2408
|
+
});
|
2409
|
+
}
|
2410
|
+
};
|
2411
|
+
|
2412
|
+
// src/RouteClient.ts
|
2413
|
+
import { ApiClient as ApiClient11 } from "@uniformdev/context/api";
|
2083
2414
|
var ROUTE_URL = "/api/v1/route";
|
2084
|
-
var RouteClient = class extends
|
2415
|
+
var RouteClient = class extends ApiClient11 {
|
2085
2416
|
constructor(options) {
|
2086
2417
|
var _a;
|
2087
2418
|
if (!options.limitPolicy) {
|
@@ -2094,10 +2425,16 @@ var RouteClient = class extends ApiClient7 {
|
|
2094
2425
|
async getRoute(options) {
|
2095
2426
|
const { projectId } = this.options;
|
2096
2427
|
const fetchUri = this.createUrl(ROUTE_URL, { ...options, projectId }, this.edgeApiHost);
|
2097
|
-
return await this.apiClient(
|
2428
|
+
return await this.apiClient(
|
2429
|
+
fetchUri,
|
2430
|
+
this.options.disableSWR ? { headers: { "x-disable-swr": "true" } } : void 0
|
2431
|
+
);
|
2098
2432
|
}
|
2099
2433
|
};
|
2100
2434
|
|
2435
|
+
// src/types/locales.ts
|
2436
|
+
var LOCALE_DYNAMIC_INPUT_NAME = "locale";
|
2437
|
+
|
2101
2438
|
// src/utils/createApiEnhancer.ts
|
2102
2439
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
2103
2440
|
return async (message) => {
|
@@ -2120,6 +2457,28 @@ var createUniformApiEnhancer = ({ apiUrl }) => {
|
|
2120
2457
|
};
|
2121
2458
|
};
|
2122
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
|
+
pattern: entry.pattern,
|
2476
|
+
state: entry.state,
|
2477
|
+
projectId: entry.projectId,
|
2478
|
+
releaseId: entry.releaseId
|
2479
|
+
};
|
2480
|
+
}
|
2481
|
+
|
2123
2482
|
// src/utils/getParameterAttributes.ts
|
2124
2483
|
var ATTRIBUTE_COMPONENT_ID = "data-uniform-component-id";
|
2125
2484
|
var ATTRIBUTE_PARAMETER_ID = "data-uniform-parameter-id";
|
@@ -2193,17 +2552,41 @@ function mapSlotToTestVariations(slot) {
|
|
2193
2552
|
}
|
2194
2553
|
|
2195
2554
|
// src/utils/placeholder.ts
|
2555
|
+
var SEPARATOR = "_";
|
2196
2556
|
var isComponentPlaceholderId = (id) => {
|
2197
2557
|
if (id === PLACEHOLDER_ID) {
|
2198
2558
|
return true;
|
2199
2559
|
}
|
2560
|
+
if (typeof id !== "string") {
|
2561
|
+
return false;
|
2562
|
+
}
|
2200
2563
|
return id == null ? void 0 : id.startsWith(PLACEHOLDER_ID);
|
2201
2564
|
};
|
2202
|
-
var generateComponentPlaceholderId = (randomId, sdkVersion) => {
|
2565
|
+
var generateComponentPlaceholderId = (randomId, sdkVersion, parent) => {
|
2203
2566
|
if (typeof sdkVersion === "undefined" || sdkVersion === 1) {
|
2204
2567
|
return PLACEHOLDER_ID;
|
2205
2568
|
}
|
2206
|
-
|
2569
|
+
let idParts = [PLACEHOLDER_ID, randomId];
|
2570
|
+
if (parent) {
|
2571
|
+
idParts = [...idParts, parent.nodeId, parent.slotId];
|
2572
|
+
}
|
2573
|
+
return idParts.join(SEPARATOR);
|
2574
|
+
};
|
2575
|
+
var parseComponentPlaceholderId = (id) => {
|
2576
|
+
if (!isComponentPlaceholderId(id)) {
|
2577
|
+
return;
|
2578
|
+
}
|
2579
|
+
const idParts = id.split(SEPARATOR);
|
2580
|
+
const result = {
|
2581
|
+
id: idParts[1]
|
2582
|
+
};
|
2583
|
+
if (idParts[2]) {
|
2584
|
+
result.parent = {
|
2585
|
+
nodeId: idParts[2],
|
2586
|
+
slotId: idParts[3]
|
2587
|
+
};
|
2588
|
+
}
|
2589
|
+
return result;
|
2207
2590
|
};
|
2208
2591
|
|
2209
2592
|
// src/utils/variables/parseVariableExpression.ts
|
@@ -2246,9 +2629,14 @@ function parseVariableExpression(serialized, onToken) {
|
|
2246
2629
|
continue;
|
2247
2630
|
}
|
2248
2631
|
if (char === variableSuffix && state === "variable") {
|
2632
|
+
if (serialized[index - 1] === escapeCharacter) {
|
2633
|
+
bufferEndIndex++;
|
2634
|
+
continue;
|
2635
|
+
}
|
2249
2636
|
state = "text";
|
2250
2637
|
if (bufferEndIndex > bufferStartIndex) {
|
2251
|
-
|
2638
|
+
const unescapedVariableName = serialized.substring(bufferStartIndex, bufferEndIndex).replace(/\\([${}])/g, "$1");
|
2639
|
+
if (handleToken(unescapedVariableName, "variable") === false) {
|
2252
2640
|
return tokenCount;
|
2253
2641
|
}
|
2254
2642
|
bufferStartIndex = bufferEndIndex + variableSuffix.length;
|
@@ -2308,7 +2696,7 @@ import { produce } from "immer";
|
|
2308
2696
|
|
2309
2697
|
// src/utils/variables/createVariableReference.ts
|
2310
2698
|
function createVariableReference(variableName) {
|
2311
|
-
return `\${${variableName}}`;
|
2699
|
+
return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
|
2312
2700
|
}
|
2313
2701
|
|
2314
2702
|
// src/utils/variables/bindVariablesToObject.ts
|
@@ -2392,6 +2780,9 @@ function handleRichTextNodeBinding(object, options) {
|
|
2392
2780
|
import { ApiClientError as ApiClientError2 } from "@uniformdev/context/api";
|
2393
2781
|
var CanvasClientError = ApiClientError2;
|
2394
2782
|
export {
|
2783
|
+
ASSETS_SOURCE_CUSTOM_URL,
|
2784
|
+
ASSETS_SOURCE_UNIFORM,
|
2785
|
+
ASSET_PARAMETER_TYPE,
|
2395
2786
|
ATTRIBUTE_COMPONENT_ID,
|
2396
2787
|
ATTRIBUTE_MULTILINE,
|
2397
2788
|
ATTRIBUTE_PARAMETER_ID,
|
@@ -2412,6 +2803,8 @@ export {
|
|
2412
2803
|
CANVAS_PERSONALIZE_SLOT,
|
2413
2804
|
CANVAS_PERSONALIZE_TYPE,
|
2414
2805
|
CANVAS_PUBLISHED_STATE,
|
2806
|
+
CANVAS_SLOT_SECTION_SLOT,
|
2807
|
+
CANVAS_SLOT_SECTION_TYPE,
|
2415
2808
|
CANVAS_TEST_SLOT,
|
2416
2809
|
CANVAS_TEST_TYPE,
|
2417
2810
|
CANVAS_TEST_VARIANT_PARAM,
|
@@ -2424,21 +2817,25 @@ export {
|
|
2424
2817
|
DataTypeClient,
|
2425
2818
|
EDGE_CACHE_DISABLED,
|
2426
2819
|
EDGE_DEFAULT_CACHE_TTL,
|
2427
|
-
EDGE_DEFAULT_L2_CACHE_TTL_IN_HOURS,
|
2428
2820
|
EDGE_MAX_CACHE_TTL,
|
2429
|
-
EDGE_MAX_L2_CACHE_TTL_IN_HOURS,
|
2430
2821
|
EDGE_MIN_CACHE_TTL,
|
2431
|
-
EDGE_MIN_L2_CACHE_TTL_IN_HOURS,
|
2432
2822
|
EMPTY_COMPOSITION,
|
2433
2823
|
EnhancerBuilder,
|
2434
2824
|
IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
|
2435
2825
|
IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
2436
2826
|
IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM,
|
2437
2827
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
2828
|
+
IN_CONTEXT_EDITOR_FORCED_SETTINGS_QUERY_STRING_PARAM,
|
2438
2829
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
2439
2830
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
2440
2831
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
2832
|
+
LOCALE_DYNAMIC_INPUT_NAME,
|
2833
|
+
LocaleClient,
|
2441
2834
|
PLACEHOLDER_ID,
|
2835
|
+
PromptClient,
|
2836
|
+
RelationshipClient,
|
2837
|
+
ReleaseClient,
|
2838
|
+
ReleaseContentsClient,
|
2442
2839
|
RouteClient,
|
2443
2840
|
SECRET_QUERY_STRING_PARAM,
|
2444
2841
|
UncachedCanvasClient,
|
@@ -2457,25 +2854,38 @@ export {
|
|
2457
2854
|
createVariableReference,
|
2458
2855
|
enhance,
|
2459
2856
|
extractLocales,
|
2857
|
+
findParameterInNodeTree,
|
2858
|
+
flattenValues,
|
2460
2859
|
generateComponentPlaceholderId,
|
2461
2860
|
generateHash,
|
2462
2861
|
getBlockValue,
|
2463
2862
|
getChannelName,
|
2464
2863
|
getComponentJsonPointer,
|
2465
2864
|
getComponentPath,
|
2865
|
+
getLocalizedPropertyValues,
|
2866
|
+
getNounForLocation,
|
2867
|
+
getNounForNode,
|
2466
2868
|
getParameterAttributes,
|
2467
2869
|
getPropertiesValue,
|
2870
|
+
getPropertyValue,
|
2468
2871
|
isAddComponentMessage,
|
2469
2872
|
isAllowedReferrer,
|
2873
|
+
isAssetParamValue,
|
2874
|
+
isAssetParamValueItem,
|
2470
2875
|
isComponentActionMessage,
|
2471
2876
|
isComponentPlaceholderId,
|
2472
2877
|
isDismissPlaceholderMessage,
|
2878
|
+
isEntryData,
|
2473
2879
|
isMovingComponentMessage,
|
2880
|
+
isNestedNodeType,
|
2474
2881
|
isOpenParameterEditorMessage,
|
2475
2882
|
isReadyMessage,
|
2476
2883
|
isReportRenderedCompositionsMessage,
|
2884
|
+
isRequestComponentSuggestionMessage,
|
2885
|
+
isRootEntryReference,
|
2477
2886
|
isSelectComponentMessage,
|
2478
2887
|
isSelectParameterMessage,
|
2888
|
+
isSuggestComponentMessage,
|
2479
2889
|
isSystemComponentDefinition,
|
2480
2890
|
isTriggerCompositionActionMessage,
|
2481
2891
|
isUpdateComponentParameterMessage,
|
@@ -2489,9 +2899,9 @@ export {
|
|
2489
2899
|
mapSlotToPersonalizedVariations,
|
2490
2900
|
mapSlotToTestVariations,
|
2491
2901
|
nullLimitPolicy,
|
2902
|
+
parseComponentPlaceholderId,
|
2492
2903
|
parseVariableExpression,
|
2493
2904
|
subscribeToComposition,
|
2494
|
-
unstable_CompositionRelationshipClient,
|
2495
2905
|
walkComponentTree,
|
2496
2906
|
walkNodeTree
|
2497
2907
|
};
|