@uniformdev/canvas 19.38.2 → 19.38.3-alpha.78

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.mjs CHANGED
@@ -679,11 +679,84 @@ var unstable_CompositionRelationshipClient = class extends ApiClient3 {
679
679
  }
680
680
  };
681
681
 
682
- // src/DataSourceClient.ts
682
+ // src/ContentClient.ts
683
683
  import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
684
+ var _contentTypesUrl, _entriesUrl;
685
+ var _ContentClient = class _ContentClient extends ApiClient4 {
686
+ constructor(options) {
687
+ var _a;
688
+ super(options);
689
+ this.edgeApiHost = (_a = options.edgeApiHost) != null ? _a : "https://uniform.global";
690
+ }
691
+ getContentTypes(options) {
692
+ const { projectId } = this.options;
693
+ const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl), { ...options, projectId });
694
+ return this.apiClient(fetchUri);
695
+ }
696
+ getEntries(options) {
697
+ const { projectId } = this.options;
698
+ const { skipDataResolution, ...params } = options;
699
+ const fetchUri = skipDataResolution ? this.createUrl(__privateGet(_ContentClient, _entriesUrl), { ...params, projectId }) : this.createUrl(__privateGet(_ContentClient, _entriesUrl), this.getEdgeOptions(params), this.edgeApiHost);
700
+ return this.apiClient(fetchUri);
701
+ }
702
+ async upsertContentType(body) {
703
+ const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl));
704
+ await this.apiClient(fetchUri, {
705
+ method: "PUT",
706
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
707
+ expectNoContent: true
708
+ });
709
+ }
710
+ async upsertEntry(body) {
711
+ const fetchUri = this.createUrl(__privateGet(_ContentClient, _entriesUrl));
712
+ await this.apiClient(fetchUri, {
713
+ method: "PUT",
714
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
715
+ expectNoContent: true
716
+ });
717
+ }
718
+ async deleteContentType(body) {
719
+ const fetchUri = this.createUrl(__privateGet(_ContentClient, _contentTypesUrl));
720
+ await this.apiClient(fetchUri, {
721
+ method: "DELETE",
722
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
723
+ expectNoContent: true
724
+ });
725
+ }
726
+ async deleteEntry(body) {
727
+ const fetchUri = this.createUrl(__privateGet(_ContentClient, _entriesUrl));
728
+ await this.apiClient(fetchUri, {
729
+ method: "DELETE",
730
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
731
+ expectNoContent: true
732
+ });
733
+ }
734
+ getEdgeOptions(options) {
735
+ const { projectId } = this.options;
736
+ const { skipDataResolution, ...params } = options;
737
+ return {
738
+ projectId,
739
+ ...params,
740
+ diagnostics: (options == null ? void 0 : options.diagnostics) ? "true" : void 0
741
+ };
742
+ }
743
+ };
744
+ _contentTypesUrl = new WeakMap();
745
+ _entriesUrl = new WeakMap();
746
+ __privateAdd(_ContentClient, _contentTypesUrl, "/api/v1/content-types");
747
+ __privateAdd(_ContentClient, _entriesUrl, "/api/v1/entries");
748
+ var ContentClient = _ContentClient;
749
+ var UncachedContentClient = class extends ContentClient {
750
+ constructor(options) {
751
+ super({ ...options, bypassCache: true });
752
+ }
753
+ };
754
+
755
+ // src/DataSourceClient.ts
756
+ import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
684
757
  var dataSourceUrl = "/api/v1/data-source";
685
758
  var dataSourcesUrl = "/api/v1/data-sources";
686
- var DataSourceClient = class extends ApiClient4 {
759
+ var DataSourceClient = class extends ApiClient5 {
687
760
  constructor(options) {
688
761
  super(options);
689
762
  }
@@ -720,9 +793,9 @@ var DataSourceClient = class extends ApiClient4 {
720
793
  };
721
794
 
722
795
  // src/DataTypeClient.ts
723
- import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
796
+ import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
724
797
  var _url;
725
- var _DataTypeClient = class _DataTypeClient extends ApiClient5 {
798
+ var _DataTypeClient = class _DataTypeClient extends ApiClient6 {
726
799
  constructor(options) {
727
800
  super(options);
728
801
  }
@@ -1245,10 +1318,13 @@ var CANVAS_TEST_SLOT = "test";
1245
1318
  var CANVAS_LOCALIZATION_SLOT = "localized";
1246
1319
  var CANVAS_DRAFT_STATE = 0;
1247
1320
  var CANVAS_PUBLISHED_STATE = 64;
1321
+ var CANVAS_EDITOR_STATE = 63;
1248
1322
  var CANVAS_PERSONALIZATION_PARAM = "$pzCrit";
1249
1323
  var CANVAS_TEST_VARIANT_PARAM = "$tstVrnt";
1250
1324
  var CANVAS_ENRICHMENT_TAG_PARAM = "$enr";
1251
1325
  var IN_CONTEXT_EDITOR_QUERY_STRING_PARAM = "is_incontext_editing_mode";
1326
+ var IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM = "is_incontext_editing_playground";
1327
+ var IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM = "is_config_check";
1252
1328
  var IN_CONTEXT_EDITOR_COMPONENT_START_ROLE = "uniform-component-start";
1253
1329
  var IN_CONTEXT_EDITOR_COMPONENT_END_ROLE = "uniform-component-end";
1254
1330
  var IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID = "uniform-canvas-preview-script";
@@ -1515,6 +1591,12 @@ var createCanvasChannel = ({
1515
1591
  };
1516
1592
  postMessage(message);
1517
1593
  };
1594
+ const editorStateUpdated = () => {
1595
+ const message = {
1596
+ type: "editor-state-updated"
1597
+ };
1598
+ postMessage(message);
1599
+ };
1518
1600
  const messageEventListener = (event) => {
1519
1601
  if (typeof event.data !== "string") {
1520
1602
  return;
@@ -1556,7 +1638,8 @@ var createCanvasChannel = ({
1556
1638
  updatePreviewSettings,
1557
1639
  updateContextualEditingStateInternal,
1558
1640
  selectParameter,
1559
- reportRenderedCompositions
1641
+ reportRenderedCompositions,
1642
+ editorStateUpdated
1560
1643
  };
1561
1644
  };
1562
1645
 
@@ -1639,9 +1722,9 @@ function subscribeToComposition({
1639
1722
  }
1640
1723
 
1641
1724
  // src/RouteClient.ts
1642
- import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
1725
+ import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
1643
1726
  var ROUTE_URL = "/api/v1/route";
1644
- var RouteClient = class extends ApiClient6 {
1727
+ var RouteClient = class extends ApiClient7 {
1645
1728
  constructor(options) {
1646
1729
  var _a;
1647
1730
  if (!options.limitPolicy) {
@@ -1658,80 +1741,6 @@ var RouteClient = class extends ApiClient6 {
1658
1741
  }
1659
1742
  };
1660
1743
 
1661
- // src/utils/bindVariables.ts
1662
- function bindVariables({
1663
- variables,
1664
- value,
1665
- errorPrefix = "Variable",
1666
- handleBinding
1667
- }) {
1668
- let boundCount = 0;
1669
- const errors = [];
1670
- const defaultHandleBinding = (variableName, variables2, errors2) => {
1671
- const variableValue = variables2[variableName];
1672
- if (variableValue === void 0) {
1673
- errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1674
- return "";
1675
- }
1676
- return variableValue;
1677
- };
1678
- const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
1679
- const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
1680
- boundCount++;
1681
- return variableValue;
1682
- });
1683
- return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
1684
- }
1685
-
1686
- // src/utils/bindVariablesToObject.ts
1687
- import { produce } from "immer";
1688
- function bindVariablesToObject(options) {
1689
- return bindVariablesToObjectRecursive(options);
1690
- }
1691
- function bindVariablesToObjectRecursive({
1692
- value,
1693
- recursivePath,
1694
- ...bindVariablesOptions
1695
- }) {
1696
- let boundCount = 0;
1697
- const errors = [];
1698
- if (typeof value === "string") {
1699
- return bindVariables({ ...bindVariablesOptions, value });
1700
- }
1701
- if (typeof value !== "object" || value === null) {
1702
- return { boundCount: 0, result: value };
1703
- }
1704
- const result = produce(value, (draft) => {
1705
- Object.entries(draft).forEach(([property, oldValue]) => {
1706
- const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1707
- if (typeof oldValue === "string") {
1708
- const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1709
- if (oldValue !== bindResult.result || bindResult.errors) {
1710
- boundCount += bindResult.boundCount;
1711
- draft[property] = bindResult.result;
1712
- if (bindResult.errors) {
1713
- errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1714
- }
1715
- }
1716
- return;
1717
- }
1718
- const childBind = bindVariablesToObjectRecursive({
1719
- ...bindVariablesOptions,
1720
- value: oldValue,
1721
- recursivePath: currentObjectPath
1722
- });
1723
- if (childBind.boundCount || childBind.errors) {
1724
- boundCount += childBind.boundCount;
1725
- draft[property] = childBind.result;
1726
- if (childBind.errors) {
1727
- errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
1728
- }
1729
- }
1730
- });
1731
- });
1732
- return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1733
- }
1734
-
1735
1744
  // src/utils/createApiEnhancer.ts
1736
1745
  var createUniformApiEnhancer = ({ apiUrl }) => {
1737
1746
  return async (message) => {
@@ -1821,6 +1830,180 @@ function mapSlotToTestVariations(slot) {
1821
1830
  });
1822
1831
  }
1823
1832
 
1833
+ // src/utils/variables/parseVariableExpression.ts
1834
+ var escapeCharacter = "\\";
1835
+ var variablePrefix = "${";
1836
+ var variableSuffix = "}";
1837
+ function parseVariableExpression(serialized, onToken) {
1838
+ let bufferStartIndex = 0;
1839
+ let bufferEndIndex = 0;
1840
+ let tokenCount = 0;
1841
+ const handleToken = (token, type) => {
1842
+ tokenCount++;
1843
+ return onToken == null ? void 0 : onToken(token, type);
1844
+ };
1845
+ let state = "text";
1846
+ for (let index = 0; index < serialized.length; index++) {
1847
+ const char = serialized[index];
1848
+ if (bufferStartIndex > bufferEndIndex) {
1849
+ bufferEndIndex = bufferStartIndex;
1850
+ }
1851
+ if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
1852
+ if (serialized[index - 1] === escapeCharacter) {
1853
+ bufferEndIndex -= escapeCharacter.length;
1854
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1855
+ return tokenCount;
1856
+ }
1857
+ bufferStartIndex = index;
1858
+ bufferEndIndex = index + 1;
1859
+ continue;
1860
+ }
1861
+ state = "variable";
1862
+ if (bufferEndIndex > bufferStartIndex) {
1863
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1864
+ return tokenCount;
1865
+ }
1866
+ bufferStartIndex = bufferEndIndex;
1867
+ }
1868
+ index += variablePrefix.length - 1;
1869
+ bufferStartIndex += variablePrefix.length;
1870
+ continue;
1871
+ }
1872
+ if (char === variableSuffix && state === "variable") {
1873
+ state = "text";
1874
+ if (bufferEndIndex > bufferStartIndex) {
1875
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
1876
+ return tokenCount;
1877
+ }
1878
+ bufferStartIndex = bufferEndIndex + variableSuffix.length;
1879
+ }
1880
+ continue;
1881
+ }
1882
+ bufferEndIndex++;
1883
+ }
1884
+ if (bufferEndIndex > bufferStartIndex) {
1885
+ if (state === "variable") {
1886
+ state = "text";
1887
+ bufferStartIndex -= variablePrefix.length;
1888
+ }
1889
+ handleToken(serialized.substring(bufferStartIndex), state);
1890
+ }
1891
+ return tokenCount;
1892
+ }
1893
+
1894
+ // src/utils/variables/bindVariables.ts
1895
+ function bindVariables({
1896
+ variables,
1897
+ value,
1898
+ errorPrefix = "Variable",
1899
+ handleBinding
1900
+ }) {
1901
+ let boundCount = 0;
1902
+ let tokenCount = 0;
1903
+ const errors = [];
1904
+ const defaultHandleBinding = (variableName, variables2, errors2) => {
1905
+ const variableValue = variables2[variableName];
1906
+ if (variableValue === void 0) {
1907
+ errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1908
+ return "";
1909
+ }
1910
+ return variableValue;
1911
+ };
1912
+ const result = [];
1913
+ parseVariableExpression(value, (token, tokenType) => {
1914
+ tokenCount++;
1915
+ if (tokenType === "text") {
1916
+ result.push(token);
1917
+ return;
1918
+ }
1919
+ const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(token, variables, errors);
1920
+ boundCount++;
1921
+ result.push(variableValue);
1922
+ });
1923
+ return {
1924
+ result: tokenCount === 1 ? result[0] : result.join(""),
1925
+ boundCount,
1926
+ errors: errors.length > 0 ? errors : void 0
1927
+ };
1928
+ }
1929
+
1930
+ // src/utils/variables/bindVariablesToObject.ts
1931
+ import { produce } from "immer";
1932
+
1933
+ // src/utils/variables/createVariableReference.ts
1934
+ function createVariableReference(variableName) {
1935
+ return `\${${variableName}}`;
1936
+ }
1937
+
1938
+ // src/utils/variables/bindVariablesToObject.ts
1939
+ function bindVariablesToObject(options) {
1940
+ return bindVariablesToObjectRecursive(options);
1941
+ }
1942
+ function bindVariablesToObjectRecursive({
1943
+ value,
1944
+ recursivePath,
1945
+ ...bindVariablesOptions
1946
+ }) {
1947
+ let boundCount = 0;
1948
+ const errors = [];
1949
+ if (typeof value === "string") {
1950
+ return bindVariables({ ...bindVariablesOptions, value });
1951
+ }
1952
+ if (typeof value !== "object" || value === null) {
1953
+ return { boundCount: 0, result: value };
1954
+ }
1955
+ const richTextNodeResult = handleRichTextNodeBinding(value, bindVariablesOptions);
1956
+ if (richTextNodeResult !== void 0) {
1957
+ return richTextNodeResult;
1958
+ }
1959
+ const result = produce(value, (draft) => {
1960
+ Object.entries(draft).forEach(([property, oldValue]) => {
1961
+ const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1962
+ if (typeof oldValue === "string") {
1963
+ const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1964
+ if (oldValue !== bindResult.result || bindResult.errors) {
1965
+ boundCount += bindResult.boundCount;
1966
+ draft[property] = bindResult.result;
1967
+ if (bindResult.errors) {
1968
+ errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1969
+ }
1970
+ }
1971
+ return;
1972
+ }
1973
+ const childBind = bindVariablesToObjectRecursive({
1974
+ ...bindVariablesOptions,
1975
+ value: oldValue,
1976
+ recursivePath: currentObjectPath
1977
+ });
1978
+ if (childBind.boundCount || childBind.errors) {
1979
+ boundCount += childBind.boundCount;
1980
+ draft[property] = childBind.result;
1981
+ if (childBind.errors) {
1982
+ errors.push(...childBind.errors);
1983
+ }
1984
+ }
1985
+ });
1986
+ });
1987
+ return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1988
+ }
1989
+ function handleRichTextNodeBinding(object, options) {
1990
+ if ("type" in object && object.type === "variable" && "reference" in object && typeof object.reference === "string" && "version" in object && object.version === 1) {
1991
+ const value = createVariableReference(object.reference);
1992
+ const bindResult = bindVariables({ ...options, value });
1993
+ const bindResultAsTextNode = {
1994
+ detail: 0,
1995
+ format: 0,
1996
+ mode: "normal",
1997
+ style: "",
1998
+ text: bindResult.result,
1999
+ type: "text",
2000
+ version: 1
2001
+ };
2002
+ return { ...bindResult, result: bindResultAsTextNode };
2003
+ }
2004
+ return void 0;
2005
+ }
2006
+
1824
2007
  // src/index.ts
1825
2008
  import { ApiClientError as ApiClientError2 } from "@uniformdev/context/api";
1826
2009
  var CanvasClientError = ApiClientError2;
@@ -1834,6 +2017,7 @@ export {
1834
2017
  ApiClientError2 as ApiClientError,
1835
2018
  BatchEntry,
1836
2019
  CANVAS_DRAFT_STATE,
2020
+ CANVAS_EDITOR_STATE,
1837
2021
  CANVAS_ENRICHMENT_TAG_PARAM,
1838
2022
  CANVAS_INTENT_TAG_PARAM,
1839
2023
  CANVAS_LOCALE_TAG_PARAM,
@@ -1850,6 +2034,7 @@ export {
1850
2034
  CanvasClientError,
1851
2035
  CategoryClient,
1852
2036
  ChildEnhancerBuilder,
2037
+ ContentClient,
1853
2038
  DataSourceClient,
1854
2039
  DataTypeClient,
1855
2040
  EDGE_CACHE_DISABLED,
@@ -1863,13 +2048,16 @@ export {
1863
2048
  EnhancerBuilder,
1864
2049
  IN_CONTEXT_EDITOR_COMPONENT_END_ROLE,
1865
2050
  IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
2051
+ IN_CONTEXT_EDITOR_CONFIG_CHECK_QUERY_STRING_PARAM,
1866
2052
  IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
2053
+ IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
1867
2054
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
1868
2055
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
1869
2056
  PLACEHOLDER_ID,
1870
2057
  RouteClient,
1871
2058
  UncachedCanvasClient,
1872
2059
  UncachedCategoryClient,
2060
+ UncachedContentClient,
1873
2061
  UniqueBatchEntries,
1874
2062
  bindVariables,
1875
2063
  bindVariablesToObject,
@@ -1879,6 +2067,7 @@ export {
1879
2067
  createEventBus,
1880
2068
  createLimitPolicy,
1881
2069
  createUniformApiEnhancer,
2070
+ createVariableReference,
1882
2071
  enhance,
1883
2072
  extractLocales,
1884
2073
  generateHash,
@@ -1904,6 +2093,7 @@ export {
1904
2093
  mapSlotToPersonalizedVariations,
1905
2094
  mapSlotToTestVariations,
1906
2095
  nullLimitPolicy,
2096
+ parseVariableExpression,
1907
2097
  subscribeToComposition,
1908
2098
  unstable_CompositionRelationshipClient,
1909
2099
  walkComponentTree
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "19.38.2",
3
+ "version": "19.38.3-alpha.78+5c9892bf1",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -32,13 +32,13 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/retry": "0.12.1",
35
- "lexical": "^0.11.1",
35
+ "lexical": "^0.12.0",
36
36
  "p-retry": "5.1.2",
37
37
  "p-throttle": "5.0.0",
38
38
  "pusher-js": "8.2.0"
39
39
  },
40
40
  "dependencies": {
41
- "@uniformdev/context": "19.38.2",
41
+ "@uniformdev/context": "19.38.3-alpha.78+5c9892bf1",
42
42
  "immer": "9.0.21"
43
43
  },
44
44
  "files": [
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "b97fd17fd44e0f5bd3806e942b516cb2bd218096"
50
+ "gitHead": "5c9892bf101584d351d06b65e1658a1237594cfb"
51
51
  }