@uniformdev/canvas 20.1.1-alpha.2 → 20.3.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -805,6 +805,9 @@ var _ContentClient = class _ContentClient extends ApiClient3 {
805
805
  }
806
806
  async upsertContentType(body, opts = {}) {
807
807
  const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl));
808
+ if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
809
+ delete body.contentType.slugSettings;
810
+ }
808
811
  await this.apiClient(fetchUri, {
809
812
  method: "PUT",
810
813
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -1855,6 +1858,101 @@ function findParameterInNodeTree(data, predicate) {
1855
1858
  return results;
1856
1859
  }
1857
1860
 
1861
+ // src/utils/variables/convertToBindExpression.ts
1862
+ var bindExpressionPrefix = "#";
1863
+ var bindExpressionEscapeChars = /* @__PURE__ */ new Set(["#", "\\", "[", "]", ":"]);
1864
+ function convertToBindExpression(binding) {
1865
+ if (binding.syntax === "jptr") {
1866
+ const expressionComponents = [
1867
+ `${bindExpressionPrefix}${binding.syntax}:${escapeNestedVariableExpressions(
1868
+ escapeBindExpressionReservedChars(binding.pointer)
1869
+ )}`
1870
+ ];
1871
+ if (binding.failureAction && binding.failureAction !== "t") {
1872
+ expressionComponents.push(`fa=${binding.failureAction}`);
1873
+ }
1874
+ if (binding.failureLogLevel && binding.failureLogLevel !== "w") {
1875
+ expressionComponents.push(`fl=${binding.failureLogLevel}`);
1876
+ }
1877
+ if (binding.failureDefault) {
1878
+ expressionComponents.push(`fd=${escapeBindExpressionDefaultValue(binding.failureDefault)}`);
1879
+ }
1880
+ return expressionComponents.join(":");
1881
+ }
1882
+ throw new Error(`Unsupported dynamic token binding syntax '${binding.syntax}'`);
1883
+ }
1884
+ function escapeNestedVariableExpressions(pointer) {
1885
+ return pointer.replace(/\$\{([^}]+)\}/g, "$[$1]");
1886
+ }
1887
+ function escapeBindExpressionReservedChars(pointer) {
1888
+ return pointer.split("").map((c) => bindExpressionEscapeChars.has(c) ? `\\${c === ":" ? ";" : c}` : c).join("");
1889
+ }
1890
+ function escapeBindExpressionDefaultValue(defaultValue) {
1891
+ return escapeBindExpressionReservedChars(defaultValue).replace("=", "\\+");
1892
+ }
1893
+
1894
+ // src/utils/variables/createVariableReference.ts
1895
+ function createVariableReference(variableName) {
1896
+ return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
1897
+ }
1898
+
1899
+ // src/enhancement/getEffectivePropertyValue.ts
1900
+ function getEffectivePropertyValue({
1901
+ property,
1902
+ conditionIndex,
1903
+ locale,
1904
+ strict,
1905
+ greedyLocaleMatching
1906
+ }) {
1907
+ var _a, _b, _c, _d;
1908
+ if (!property) {
1909
+ return void 0;
1910
+ }
1911
+ let effectiveValue = property.value;
1912
+ if (conditionIndex >= 0) {
1913
+ const conditionalValue = (_b = (_a = property.conditions) == null ? void 0 : _a[conditionIndex]) == null ? void 0 : _b.value;
1914
+ if (conditionalValue === null) {
1915
+ return void 0;
1916
+ }
1917
+ if (conditionalValue !== void 0 || strict) {
1918
+ effectiveValue = conditionalValue;
1919
+ }
1920
+ }
1921
+ if (locale) {
1922
+ const localeValue = getLocaleMatch(property.locales, locale, greedyLocaleMatching);
1923
+ if (localeValue !== void 0 || strict) {
1924
+ effectiveValue = localeValue;
1925
+ }
1926
+ if (conditionIndex >= 0) {
1927
+ const localeConditionalValue = (_d = (_c = getLocaleMatch(
1928
+ property.localesConditions,
1929
+ locale,
1930
+ greedyLocaleMatching
1931
+ )) == null ? void 0 : _c[conditionIndex]) == null ? void 0 : _d.value;
1932
+ if (localeConditionalValue === null) {
1933
+ return void 0;
1934
+ }
1935
+ if (localeConditionalValue !== void 0 || strict) {
1936
+ effectiveValue = localeConditionalValue;
1937
+ }
1938
+ }
1939
+ }
1940
+ if (property.connectedData) {
1941
+ effectiveValue = createVariableReference(convertToBindExpression(property.connectedData));
1942
+ }
1943
+ return effectiveValue;
1944
+ }
1945
+ function getLocaleMatch(index, locale, greedy) {
1946
+ if (!index) {
1947
+ return void 0;
1948
+ }
1949
+ const match = index[locale];
1950
+ if (match === void 0 && greedy) {
1951
+ return Object.values(index)[0];
1952
+ }
1953
+ return match;
1954
+ }
1955
+
1858
1956
  // src/enhancement/visibility/evaluateVisibilityCriteriaGroup.ts
1859
1957
  function evaluateVisibilityCriteriaGroup(options) {
1860
1958
  const { criteriaGroup, simplifyCriteria } = options;
@@ -2356,6 +2454,33 @@ var UniqueBatchEntries = class {
2356
2454
  }
2357
2455
  };
2358
2456
 
2457
+ // src/enhancement/walkPropertyValues.ts
2458
+ function walkPropertyValues(property, visitor) {
2459
+ var _a, _b;
2460
+ const definedLocales = /* @__PURE__ */ new Set([
2461
+ ...Object.keys((_a = property.locales) != null ? _a : {}),
2462
+ ...Object.keys((_b = property.localesConditions) != null ? _b : {})
2463
+ ]);
2464
+ const propertyLocales = [void 0, ...definedLocales];
2465
+ propertyLocales.forEach((locale) => {
2466
+ var _a2, _b2;
2467
+ const conditionalValues = (_b2 = locale === void 0 ? property.conditions : (_a2 = property.localesConditions) == null ? void 0 : _a2[locale]) != null ? _b2 : [];
2468
+ for (let conditionIndex = conditionalValues.length - 1; conditionIndex >= -1; conditionIndex--) {
2469
+ const value = getEffectivePropertyValue({
2470
+ property,
2471
+ locale,
2472
+ conditionIndex,
2473
+ strict: true
2474
+ });
2475
+ visitor({
2476
+ locale,
2477
+ conditionIndex,
2478
+ value
2479
+ });
2480
+ }
2481
+ });
2482
+ }
2483
+
2359
2484
  // src/EntityReleasesClient.ts
2360
2485
  import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
2361
2486
  var releaseContentsUrl = "/api/v1/entity-releases";
@@ -2601,6 +2726,20 @@ var createCanvasChannel = ({
2601
2726
  };
2602
2727
  postMessage(message);
2603
2728
  };
2729
+ const requestPageHtml = (options) => {
2730
+ const message = {
2731
+ ...options,
2732
+ type: "request-page-html"
2733
+ };
2734
+ postMessage(message);
2735
+ };
2736
+ const sendPageHtml = (options) => {
2737
+ const message = {
2738
+ ...options,
2739
+ type: "send-page-html"
2740
+ };
2741
+ postMessage(message);
2742
+ };
2604
2743
  const updateContextualEditingStateInternal = (options) => {
2605
2744
  const message = {
2606
2745
  ...options,
@@ -2720,6 +2859,8 @@ var createCanvasChannel = ({
2720
2859
  updateComponentReferences,
2721
2860
  requestComponentSuggestion,
2722
2861
  suggestComponent,
2862
+ requestPageHtml,
2863
+ sendPageHtml,
2723
2864
  contextStorageUpdated
2724
2865
  };
2725
2866
  };
@@ -3139,13 +3280,6 @@ function bindVariables({
3139
3280
 
3140
3281
  // src/utils/variables/bindVariablesToObject.ts
3141
3282
  import { isDraft, produce } from "immer";
3142
-
3143
- // src/utils/variables/createVariableReference.ts
3144
- function createVariableReference(variableName) {
3145
- return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
3146
- }
3147
-
3148
- // src/utils/variables/bindVariablesToObject.ts
3149
3283
  function bindVariablesToObject(options) {
3150
3284
  return bindVariablesToObjectRecursive(options);
3151
3285
  }
@@ -3337,10 +3471,13 @@ export {
3337
3471
  UncachedContentClient,
3338
3472
  UniqueBatchEntries,
3339
3473
  WorkflowClient,
3474
+ bindExpressionEscapeChars,
3475
+ bindExpressionPrefix,
3340
3476
  bindVariables,
3341
3477
  bindVariablesToObject,
3342
3478
  compose,
3343
3479
  convertEntryToPutEntry,
3480
+ convertToBindExpression,
3344
3481
  createBatchEnhancer,
3345
3482
  createCanvasChannel,
3346
3483
  createDynamicInputVisibilityRule,
@@ -3351,6 +3488,7 @@ export {
3351
3488
  createUniformApiEnhancer,
3352
3489
  createVariableReference,
3353
3490
  enhance,
3491
+ escapeBindExpressionDefaultValue,
3354
3492
  evaluateNodeVisibilityParameter,
3355
3493
  evaluatePropertyCriteria,
3356
3494
  evaluateVisibilityCriteriaGroup,
@@ -3365,6 +3503,7 @@ export {
3365
3503
  getComponentJsonPointer,
3366
3504
  getComponentPath,
3367
3505
  getDataSourceVariantFromRouteGetParams,
3506
+ getEffectivePropertyValue,
3368
3507
  getLocalizedPropertyValues,
3369
3508
  getNounForLocation,
3370
3509
  getNounForNode,
@@ -3406,5 +3545,6 @@ export {
3406
3545
  nullLimitPolicy,
3407
3546
  parseComponentPlaceholderId,
3408
3547
  parseVariableExpression,
3409
- walkNodeTree
3548
+ walkNodeTree,
3549
+ walkPropertyValues
3410
3550
  };
package/dist/index.js CHANGED
@@ -460,10 +460,13 @@ __export(src_exports, {
460
460
  UncachedContentClient: () => UncachedContentClient,
461
461
  UniqueBatchEntries: () => UniqueBatchEntries,
462
462
  WorkflowClient: () => WorkflowClient,
463
+ bindExpressionEscapeChars: () => bindExpressionEscapeChars,
464
+ bindExpressionPrefix: () => bindExpressionPrefix,
463
465
  bindVariables: () => bindVariables,
464
466
  bindVariablesToObject: () => bindVariablesToObject,
465
467
  compose: () => compose,
466
468
  convertEntryToPutEntry: () => convertEntryToPutEntry,
469
+ convertToBindExpression: () => convertToBindExpression,
467
470
  createBatchEnhancer: () => createBatchEnhancer,
468
471
  createCanvasChannel: () => createCanvasChannel,
469
472
  createDynamicInputVisibilityRule: () => createDynamicInputVisibilityRule,
@@ -474,6 +477,7 @@ __export(src_exports, {
474
477
  createUniformApiEnhancer: () => createUniformApiEnhancer,
475
478
  createVariableReference: () => createVariableReference,
476
479
  enhance: () => enhance,
480
+ escapeBindExpressionDefaultValue: () => escapeBindExpressionDefaultValue,
477
481
  evaluateNodeVisibilityParameter: () => evaluateNodeVisibilityParameter,
478
482
  evaluatePropertyCriteria: () => evaluatePropertyCriteria,
479
483
  evaluateVisibilityCriteriaGroup: () => evaluateVisibilityCriteriaGroup,
@@ -488,6 +492,7 @@ __export(src_exports, {
488
492
  getComponentJsonPointer: () => getComponentJsonPointer,
489
493
  getComponentPath: () => getComponentPath,
490
494
  getDataSourceVariantFromRouteGetParams: () => getDataSourceVariantFromRouteGetParams,
495
+ getEffectivePropertyValue: () => getEffectivePropertyValue,
491
496
  getLocalizedPropertyValues: () => getLocalizedPropertyValues,
492
497
  getNounForLocation: () => getNounForLocation,
493
498
  getNounForNode: () => getNounForNode,
@@ -529,7 +534,8 @@ __export(src_exports, {
529
534
  nullLimitPolicy: () => nullLimitPolicy,
530
535
  parseComponentPlaceholderId: () => parseComponentPlaceholderId,
531
536
  parseVariableExpression: () => parseVariableExpression,
532
- walkNodeTree: () => walkNodeTree
537
+ walkNodeTree: () => walkNodeTree,
538
+ walkPropertyValues: () => walkPropertyValues
533
539
  });
534
540
  module.exports = __toCommonJS(src_exports);
535
541
 
@@ -959,6 +965,9 @@ var _ContentClient = class _ContentClient extends import_api4.ApiClient {
959
965
  }
960
966
  async upsertContentType(body, opts = {}) {
961
967
  const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl));
968
+ if (typeof body.contentType.slugSettings === "object" && body.contentType.slugSettings !== null && Object.keys(body.contentType.slugSettings).length === 0) {
969
+ delete body.contentType.slugSettings;
970
+ }
962
971
  await this.apiClient(fetchUri, {
963
972
  method: "PUT",
964
973
  body: JSON.stringify({ ...body, projectId: this.options.projectId }),
@@ -2009,6 +2018,101 @@ function findParameterInNodeTree(data, predicate) {
2009
2018
  return results;
2010
2019
  }
2011
2020
 
2021
+ // src/utils/variables/convertToBindExpression.ts
2022
+ var bindExpressionPrefix = "#";
2023
+ var bindExpressionEscapeChars = /* @__PURE__ */ new Set(["#", "\\", "[", "]", ":"]);
2024
+ function convertToBindExpression(binding) {
2025
+ if (binding.syntax === "jptr") {
2026
+ const expressionComponents = [
2027
+ `${bindExpressionPrefix}${binding.syntax}:${escapeNestedVariableExpressions(
2028
+ escapeBindExpressionReservedChars(binding.pointer)
2029
+ )}`
2030
+ ];
2031
+ if (binding.failureAction && binding.failureAction !== "t") {
2032
+ expressionComponents.push(`fa=${binding.failureAction}`);
2033
+ }
2034
+ if (binding.failureLogLevel && binding.failureLogLevel !== "w") {
2035
+ expressionComponents.push(`fl=${binding.failureLogLevel}`);
2036
+ }
2037
+ if (binding.failureDefault) {
2038
+ expressionComponents.push(`fd=${escapeBindExpressionDefaultValue(binding.failureDefault)}`);
2039
+ }
2040
+ return expressionComponents.join(":");
2041
+ }
2042
+ throw new Error(`Unsupported dynamic token binding syntax '${binding.syntax}'`);
2043
+ }
2044
+ function escapeNestedVariableExpressions(pointer) {
2045
+ return pointer.replace(/\$\{([^}]+)\}/g, "$[$1]");
2046
+ }
2047
+ function escapeBindExpressionReservedChars(pointer) {
2048
+ return pointer.split("").map((c) => bindExpressionEscapeChars.has(c) ? `\\${c === ":" ? ";" : c}` : c).join("");
2049
+ }
2050
+ function escapeBindExpressionDefaultValue(defaultValue) {
2051
+ return escapeBindExpressionReservedChars(defaultValue).replace("=", "\\+");
2052
+ }
2053
+
2054
+ // src/utils/variables/createVariableReference.ts
2055
+ function createVariableReference(variableName) {
2056
+ return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
2057
+ }
2058
+
2059
+ // src/enhancement/getEffectivePropertyValue.ts
2060
+ function getEffectivePropertyValue({
2061
+ property,
2062
+ conditionIndex,
2063
+ locale,
2064
+ strict,
2065
+ greedyLocaleMatching
2066
+ }) {
2067
+ var _a, _b, _c, _d;
2068
+ if (!property) {
2069
+ return void 0;
2070
+ }
2071
+ let effectiveValue = property.value;
2072
+ if (conditionIndex >= 0) {
2073
+ const conditionalValue = (_b = (_a = property.conditions) == null ? void 0 : _a[conditionIndex]) == null ? void 0 : _b.value;
2074
+ if (conditionalValue === null) {
2075
+ return void 0;
2076
+ }
2077
+ if (conditionalValue !== void 0 || strict) {
2078
+ effectiveValue = conditionalValue;
2079
+ }
2080
+ }
2081
+ if (locale) {
2082
+ const localeValue = getLocaleMatch(property.locales, locale, greedyLocaleMatching);
2083
+ if (localeValue !== void 0 || strict) {
2084
+ effectiveValue = localeValue;
2085
+ }
2086
+ if (conditionIndex >= 0) {
2087
+ const localeConditionalValue = (_d = (_c = getLocaleMatch(
2088
+ property.localesConditions,
2089
+ locale,
2090
+ greedyLocaleMatching
2091
+ )) == null ? void 0 : _c[conditionIndex]) == null ? void 0 : _d.value;
2092
+ if (localeConditionalValue === null) {
2093
+ return void 0;
2094
+ }
2095
+ if (localeConditionalValue !== void 0 || strict) {
2096
+ effectiveValue = localeConditionalValue;
2097
+ }
2098
+ }
2099
+ }
2100
+ if (property.connectedData) {
2101
+ effectiveValue = createVariableReference(convertToBindExpression(property.connectedData));
2102
+ }
2103
+ return effectiveValue;
2104
+ }
2105
+ function getLocaleMatch(index, locale, greedy) {
2106
+ if (!index) {
2107
+ return void 0;
2108
+ }
2109
+ const match = index[locale];
2110
+ if (match === void 0 && greedy) {
2111
+ return Object.values(index)[0];
2112
+ }
2113
+ return match;
2114
+ }
2115
+
2012
2116
  // src/enhancement/visibility/evaluateVisibilityCriteriaGroup.ts
2013
2117
  function evaluateVisibilityCriteriaGroup(options) {
2014
2118
  const { criteriaGroup, simplifyCriteria } = options;
@@ -2510,6 +2614,33 @@ var UniqueBatchEntries = class {
2510
2614
  }
2511
2615
  };
2512
2616
 
2617
+ // src/enhancement/walkPropertyValues.ts
2618
+ function walkPropertyValues(property, visitor) {
2619
+ var _a, _b;
2620
+ const definedLocales = /* @__PURE__ */ new Set([
2621
+ ...Object.keys((_a = property.locales) != null ? _a : {}),
2622
+ ...Object.keys((_b = property.localesConditions) != null ? _b : {})
2623
+ ]);
2624
+ const propertyLocales = [void 0, ...definedLocales];
2625
+ propertyLocales.forEach((locale) => {
2626
+ var _a2, _b2;
2627
+ const conditionalValues = (_b2 = locale === void 0 ? property.conditions : (_a2 = property.localesConditions) == null ? void 0 : _a2[locale]) != null ? _b2 : [];
2628
+ for (let conditionIndex = conditionalValues.length - 1; conditionIndex >= -1; conditionIndex--) {
2629
+ const value = getEffectivePropertyValue({
2630
+ property,
2631
+ locale,
2632
+ conditionIndex,
2633
+ strict: true
2634
+ });
2635
+ visitor({
2636
+ locale,
2637
+ conditionIndex,
2638
+ value
2639
+ });
2640
+ }
2641
+ });
2642
+ }
2643
+
2513
2644
  // src/EntityReleasesClient.ts
2514
2645
  var import_api7 = require("@uniformdev/context/api");
2515
2646
  var releaseContentsUrl = "/api/v1/entity-releases";
@@ -2755,6 +2886,20 @@ var createCanvasChannel = ({
2755
2886
  };
2756
2887
  postMessage(message);
2757
2888
  };
2889
+ const requestPageHtml = (options) => {
2890
+ const message = {
2891
+ ...options,
2892
+ type: "request-page-html"
2893
+ };
2894
+ postMessage(message);
2895
+ };
2896
+ const sendPageHtml = (options) => {
2897
+ const message = {
2898
+ ...options,
2899
+ type: "send-page-html"
2900
+ };
2901
+ postMessage(message);
2902
+ };
2758
2903
  const updateContextualEditingStateInternal = (options) => {
2759
2904
  const message = {
2760
2905
  ...options,
@@ -2874,6 +3019,8 @@ var createCanvasChannel = ({
2874
3019
  updateComponentReferences,
2875
3020
  requestComponentSuggestion,
2876
3021
  suggestComponent,
3022
+ requestPageHtml,
3023
+ sendPageHtml,
2877
3024
  contextStorageUpdated
2878
3025
  };
2879
3026
  };
@@ -3293,13 +3440,6 @@ function bindVariables({
3293
3440
 
3294
3441
  // src/utils/variables/bindVariablesToObject.ts
3295
3442
  var import_immer = require("immer");
3296
-
3297
- // src/utils/variables/createVariableReference.ts
3298
- function createVariableReference(variableName) {
3299
- return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
3300
- }
3301
-
3302
- // src/utils/variables/bindVariablesToObject.ts
3303
3443
  function bindVariablesToObject(options) {
3304
3444
  return bindVariablesToObjectRecursive(options);
3305
3445
  }
@@ -3492,10 +3632,13 @@ var CanvasClientError = import_api16.ApiClientError;
3492
3632
  UncachedContentClient,
3493
3633
  UniqueBatchEntries,
3494
3634
  WorkflowClient,
3635
+ bindExpressionEscapeChars,
3636
+ bindExpressionPrefix,
3495
3637
  bindVariables,
3496
3638
  bindVariablesToObject,
3497
3639
  compose,
3498
3640
  convertEntryToPutEntry,
3641
+ convertToBindExpression,
3499
3642
  createBatchEnhancer,
3500
3643
  createCanvasChannel,
3501
3644
  createDynamicInputVisibilityRule,
@@ -3506,6 +3649,7 @@ var CanvasClientError = import_api16.ApiClientError;
3506
3649
  createUniformApiEnhancer,
3507
3650
  createVariableReference,
3508
3651
  enhance,
3652
+ escapeBindExpressionDefaultValue,
3509
3653
  evaluateNodeVisibilityParameter,
3510
3654
  evaluatePropertyCriteria,
3511
3655
  evaluateVisibilityCriteriaGroup,
@@ -3520,6 +3664,7 @@ var CanvasClientError = import_api16.ApiClientError;
3520
3664
  getComponentJsonPointer,
3521
3665
  getComponentPath,
3522
3666
  getDataSourceVariantFromRouteGetParams,
3667
+ getEffectivePropertyValue,
3523
3668
  getLocalizedPropertyValues,
3524
3669
  getNounForLocation,
3525
3670
  getNounForNode,
@@ -3561,5 +3706,6 @@ var CanvasClientError = import_api16.ApiClientError;
3561
3706
  nullLimitPolicy,
3562
3707
  parseComponentPlaceholderId,
3563
3708
  parseVariableExpression,
3564
- walkNodeTree
3709
+ walkNodeTree,
3710
+ walkPropertyValues
3565
3711
  });