@uniformdev/canvas 19.35.2 → 19.35.3-alpha.82

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
@@ -557,10 +557,53 @@ var UncachedCanvasClient = class extends CanvasClient {
557
557
  }
558
558
  };
559
559
 
560
- // src/CompositionRelationshipClient.ts
560
+ // src/CategoryClient.ts
561
561
  import { ApiClient as ApiClient2 } from "@uniformdev/context/api";
562
+ var CATEGORIES_URL = "/api/v1/categories";
563
+ var CategoryClient = class extends ApiClient2 {
564
+ constructor(options) {
565
+ if (!options.limitPolicy) {
566
+ options.limitPolicy = createLimitPolicy({});
567
+ }
568
+ super(options);
569
+ }
570
+ /** Fetches all categories created in given project */
571
+ async getCategories(options) {
572
+ const { projectId } = this.options;
573
+ const fetchUri = this.createUrl("/api/v1/categories", { ...options, projectId });
574
+ return await this.apiClient(fetchUri);
575
+ }
576
+ /** Updates or creates a category, also used to re-order them */
577
+ async upsertCategories(categories) {
578
+ const { projectId } = this.options;
579
+ const fetchUri = this.createUrl(CATEGORIES_URL);
580
+ return await this.apiClient(fetchUri, {
581
+ method: "PUT",
582
+ body: JSON.stringify({ categories, projectId }),
583
+ expectNoContent: true
584
+ });
585
+ }
586
+ /** Deletes a category */
587
+ async removeCategory(options) {
588
+ const { projectId } = this.options;
589
+ const fetchUri = this.createUrl(CATEGORIES_URL);
590
+ return await this.apiClient(fetchUri, {
591
+ method: "DELETE",
592
+ body: JSON.stringify({ projectId, categoryId: options.categoryId }),
593
+ expectNoContent: true
594
+ });
595
+ }
596
+ };
597
+ var UncachedCategoryClient = class extends CategoryClient {
598
+ constructor(options) {
599
+ super({ ...options, bypassCache: true });
600
+ }
601
+ };
602
+
603
+ // src/CompositionRelationshipClient.ts
604
+ import { ApiClient as ApiClient3 } from "@uniformdev/context/api";
562
605
  var COMPOSITION_RELATIONSHIP_URL = "/api/v1/composition-relationships";
563
- var unstable_CompositionRelationshipClient = class extends ApiClient2 {
606
+ var unstable_CompositionRelationshipClient = class extends ApiClient3 {
564
607
  constructor(options) {
565
608
  super(options);
566
609
  this.getDefinitionsRelationships = async ({
@@ -621,10 +664,10 @@ var unstable_CompositionRelationshipClient = class extends ApiClient2 {
621
664
  };
622
665
 
623
666
  // src/DataSourceClient.ts
624
- import { ApiClient as ApiClient3 } from "@uniformdev/context/api";
667
+ import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
625
668
  var dataSourceUrl = "/api/v1/data-source";
626
669
  var dataSourcesUrl = "/api/v1/data-sources";
627
- var DataSourceClient = class extends ApiClient3 {
670
+ var DataSourceClient = class extends ApiClient4 {
628
671
  constructor(options) {
629
672
  super(options);
630
673
  }
@@ -661,9 +704,9 @@ var DataSourceClient = class extends ApiClient3 {
661
704
  };
662
705
 
663
706
  // src/DataTypeClient.ts
664
- import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
707
+ import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
665
708
  var _url;
666
- var _DataTypeClient = class _DataTypeClient extends ApiClient4 {
709
+ var _DataTypeClient = class _DataTypeClient extends ApiClient5 {
667
710
  constructor(options) {
668
711
  super(options);
669
712
  }
@@ -1580,9 +1623,9 @@ function subscribeToComposition({
1580
1623
  }
1581
1624
 
1582
1625
  // src/RouteClient.ts
1583
- import { ApiClient as ApiClient5 } from "@uniformdev/context/api";
1626
+ import { ApiClient as ApiClient6 } from "@uniformdev/context/api";
1584
1627
  var ROUTE_URL = "/api/v1/route";
1585
- var RouteClient = class extends ApiClient5 {
1628
+ var RouteClient = class extends ApiClient6 {
1586
1629
  constructor(options) {
1587
1630
  var _a;
1588
1631
  if (!options.limitPolicy) {
@@ -1599,80 +1642,6 @@ var RouteClient = class extends ApiClient5 {
1599
1642
  }
1600
1643
  };
1601
1644
 
1602
- // src/utils/bindVariables.ts
1603
- function bindVariables({
1604
- variables,
1605
- value,
1606
- errorPrefix = "Variable",
1607
- handleBinding
1608
- }) {
1609
- let boundCount = 0;
1610
- const errors = [];
1611
- const defaultHandleBinding = (variableName, variables2, errors2) => {
1612
- const variableValue = variables2[variableName];
1613
- if (variableValue === void 0) {
1614
- errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1615
- return "";
1616
- }
1617
- return variableValue;
1618
- };
1619
- const result = value.replace(/(?<!\\)\${([^}]+)}/g, (_match, variableName) => {
1620
- const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(variableName, variables, errors);
1621
- boundCount++;
1622
- return variableValue;
1623
- });
1624
- return { result, boundCount, errors: errors.length > 0 ? errors : void 0 };
1625
- }
1626
-
1627
- // src/utils/bindVariablesToObject.ts
1628
- import { produce } from "immer";
1629
- function bindVariablesToObject(options) {
1630
- return bindVariablesToObjectRecursive(options);
1631
- }
1632
- function bindVariablesToObjectRecursive({
1633
- value,
1634
- recursivePath,
1635
- ...bindVariablesOptions
1636
- }) {
1637
- let boundCount = 0;
1638
- const errors = [];
1639
- if (typeof value === "string") {
1640
- return bindVariables({ ...bindVariablesOptions, value });
1641
- }
1642
- if (typeof value !== "object" || value === null) {
1643
- return { boundCount: 0, result: value };
1644
- }
1645
- const result = produce(value, (draft) => {
1646
- Object.entries(draft).forEach(([property, oldValue]) => {
1647
- const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1648
- if (typeof oldValue === "string") {
1649
- const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1650
- if (oldValue !== bindResult.result || bindResult.errors) {
1651
- boundCount += bindResult.boundCount;
1652
- draft[property] = bindResult.result;
1653
- if (bindResult.errors) {
1654
- errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1655
- }
1656
- }
1657
- return;
1658
- }
1659
- const childBind = bindVariablesToObjectRecursive({
1660
- ...bindVariablesOptions,
1661
- value: oldValue,
1662
- recursivePath: currentObjectPath
1663
- });
1664
- if (childBind.boundCount || childBind.errors) {
1665
- boundCount += childBind.boundCount;
1666
- draft[property] = childBind.result;
1667
- if (childBind.errors) {
1668
- errors.push(...childBind.errors.map((e) => `${currentObjectPath}: ${e}`));
1669
- }
1670
- }
1671
- });
1672
- });
1673
- return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1674
- }
1675
-
1676
1645
  // src/utils/createApiEnhancer.ts
1677
1646
  var createUniformApiEnhancer = ({ apiUrl }) => {
1678
1647
  return async (message) => {
@@ -1720,8 +1689,8 @@ var getParameterAttributes = ({
1720
1689
  [ATTRIBUTE_PARAMETER_VALUE]: String(value != null ? value : ""),
1721
1690
  [ATTRIBUTE_PARAMETER_TYPE]: type,
1722
1691
  [ATTRIBUTE_PLACEHOLDER]: placeholder,
1723
- [ATTRIBUTE_MULTILINE]: isMultiline,
1724
- contentEditable: isEditable
1692
+ [ATTRIBUTE_MULTILINE]: type === "text" ? isMultiline : void 0,
1693
+ contentEditable: type === "text" ? isEditable : void 0
1725
1694
  };
1726
1695
  };
1727
1696
 
@@ -1762,6 +1731,180 @@ function mapSlotToTestVariations(slot) {
1762
1731
  });
1763
1732
  }
1764
1733
 
1734
+ // src/utils/variables/parseVariableExpression.ts
1735
+ var escapeCharacter = "\\";
1736
+ var variablePrefix = "${";
1737
+ var variableSuffix = "}";
1738
+ function parseVariableExpression(serialized, onToken) {
1739
+ let bufferStartIndex = 0;
1740
+ let bufferEndIndex = 0;
1741
+ let tokenCount = 0;
1742
+ const handleToken = (token, type) => {
1743
+ tokenCount++;
1744
+ return onToken == null ? void 0 : onToken(token, type);
1745
+ };
1746
+ let state = "text";
1747
+ for (let index = 0; index < serialized.length; index++) {
1748
+ const char = serialized[index];
1749
+ if (bufferStartIndex > bufferEndIndex) {
1750
+ bufferEndIndex = bufferStartIndex;
1751
+ }
1752
+ if (char === variablePrefix[0] && serialized[index + 1] === variablePrefix[1]) {
1753
+ if (serialized[index - 1] === escapeCharacter) {
1754
+ bufferEndIndex -= escapeCharacter.length;
1755
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1756
+ return tokenCount;
1757
+ }
1758
+ bufferStartIndex = index;
1759
+ bufferEndIndex = index + 1;
1760
+ continue;
1761
+ }
1762
+ state = "variable";
1763
+ if (bufferEndIndex > bufferStartIndex) {
1764
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "text") === false) {
1765
+ return tokenCount;
1766
+ }
1767
+ bufferStartIndex = bufferEndIndex;
1768
+ }
1769
+ index += variablePrefix.length - 1;
1770
+ bufferStartIndex += variablePrefix.length;
1771
+ continue;
1772
+ }
1773
+ if (char === variableSuffix && state === "variable") {
1774
+ state = "text";
1775
+ if (bufferEndIndex > bufferStartIndex) {
1776
+ if (handleToken(serialized.substring(bufferStartIndex, bufferEndIndex), "variable") === false) {
1777
+ return tokenCount;
1778
+ }
1779
+ bufferStartIndex = bufferEndIndex + variableSuffix.length;
1780
+ }
1781
+ continue;
1782
+ }
1783
+ bufferEndIndex++;
1784
+ }
1785
+ if (bufferEndIndex > bufferStartIndex) {
1786
+ if (state === "variable") {
1787
+ state = "text";
1788
+ bufferStartIndex -= variablePrefix.length;
1789
+ }
1790
+ handleToken(serialized.substring(bufferStartIndex), state);
1791
+ }
1792
+ return tokenCount;
1793
+ }
1794
+
1795
+ // src/utils/variables/bindVariables.ts
1796
+ function bindVariables({
1797
+ variables,
1798
+ value,
1799
+ errorPrefix = "Variable",
1800
+ handleBinding
1801
+ }) {
1802
+ let boundCount = 0;
1803
+ let tokenCount = 0;
1804
+ const errors = [];
1805
+ const defaultHandleBinding = (variableName, variables2, errors2) => {
1806
+ const variableValue = variables2[variableName];
1807
+ if (variableValue === void 0) {
1808
+ errors2.push(`${errorPrefix} "${variableName}" is not defined`);
1809
+ return "";
1810
+ }
1811
+ return variableValue;
1812
+ };
1813
+ const result = [];
1814
+ parseVariableExpression(value, (token, tokenType) => {
1815
+ tokenCount++;
1816
+ if (tokenType === "text") {
1817
+ result.push(token);
1818
+ return;
1819
+ }
1820
+ const variableValue = (handleBinding != null ? handleBinding : defaultHandleBinding)(token, variables, errors);
1821
+ boundCount++;
1822
+ result.push(variableValue);
1823
+ });
1824
+ return {
1825
+ result: tokenCount === 1 ? result[0] : result.join(""),
1826
+ boundCount,
1827
+ errors: errors.length > 0 ? errors : void 0
1828
+ };
1829
+ }
1830
+
1831
+ // src/utils/variables/bindVariablesToObject.ts
1832
+ import { produce } from "immer";
1833
+
1834
+ // src/utils/variables/createVariableReference.ts
1835
+ function createVariableReference(variableName) {
1836
+ return `\${${variableName}}`;
1837
+ }
1838
+
1839
+ // src/utils/variables/bindVariablesToObject.ts
1840
+ function bindVariablesToObject(options) {
1841
+ return bindVariablesToObjectRecursive(options);
1842
+ }
1843
+ function bindVariablesToObjectRecursive({
1844
+ value,
1845
+ recursivePath,
1846
+ ...bindVariablesOptions
1847
+ }) {
1848
+ let boundCount = 0;
1849
+ const errors = [];
1850
+ if (typeof value === "string") {
1851
+ return bindVariables({ ...bindVariablesOptions, value });
1852
+ }
1853
+ if (typeof value !== "object" || value === null) {
1854
+ return { boundCount: 0, result: value };
1855
+ }
1856
+ const richTextNodeResult = handleRichTextNodeBinding(value, bindVariablesOptions);
1857
+ if (richTextNodeResult !== void 0) {
1858
+ return richTextNodeResult;
1859
+ }
1860
+ const result = produce(value, (draft) => {
1861
+ Object.entries(draft).forEach(([property, oldValue]) => {
1862
+ const currentObjectPath = recursivePath ? `${recursivePath}.${property}` : property;
1863
+ if (typeof oldValue === "string") {
1864
+ const bindResult = bindVariables({ ...bindVariablesOptions, value: oldValue });
1865
+ if (oldValue !== bindResult.result || bindResult.errors) {
1866
+ boundCount += bindResult.boundCount;
1867
+ draft[property] = bindResult.result;
1868
+ if (bindResult.errors) {
1869
+ errors.push(...bindResult.errors.map((e) => `${currentObjectPath}: ${e}`));
1870
+ }
1871
+ }
1872
+ return;
1873
+ }
1874
+ const childBind = bindVariablesToObjectRecursive({
1875
+ ...bindVariablesOptions,
1876
+ value: oldValue,
1877
+ recursivePath: currentObjectPath
1878
+ });
1879
+ if (childBind.boundCount || childBind.errors) {
1880
+ boundCount += childBind.boundCount;
1881
+ draft[property] = childBind.result;
1882
+ if (childBind.errors) {
1883
+ errors.push(...childBind.errors);
1884
+ }
1885
+ }
1886
+ });
1887
+ });
1888
+ return { boundCount, result, errors: errors.length > 0 ? errors : void 0 };
1889
+ }
1890
+ function handleRichTextNodeBinding(object, options) {
1891
+ if ("type" in object && object.type === "variable" && "reference" in object && typeof object.reference === "string" && "version" in object && object.version === 1) {
1892
+ const value = createVariableReference(object.reference);
1893
+ const bindResult = bindVariables({ ...options, value });
1894
+ const bindResultAsTextNode = {
1895
+ detail: 0,
1896
+ format: 0,
1897
+ mode: "normal",
1898
+ style: "",
1899
+ text: bindResult.result,
1900
+ type: "text",
1901
+ version: 1
1902
+ };
1903
+ return { ...bindResult, result: bindResultAsTextNode };
1904
+ }
1905
+ return void 0;
1906
+ }
1907
+
1765
1908
  // src/index.ts
1766
1909
  import { ApiClientError } from "@uniformdev/context/api";
1767
1910
  var CanvasClientError = ApiClientError;
@@ -1789,6 +1932,7 @@ export {
1789
1932
  CANVAS_TEST_VARIANT_PARAM,
1790
1933
  CanvasClient,
1791
1934
  CanvasClientError,
1935
+ CategoryClient,
1792
1936
  ChildEnhancerBuilder,
1793
1937
  DataSourceClient,
1794
1938
  DataTypeClient,
@@ -1809,6 +1953,7 @@ export {
1809
1953
  PLACEHOLDER_ID,
1810
1954
  RouteClient,
1811
1955
  UncachedCanvasClient,
1956
+ UncachedCategoryClient,
1812
1957
  UniqueBatchEntries,
1813
1958
  bindVariables,
1814
1959
  bindVariablesToObject,
@@ -1818,6 +1963,7 @@ export {
1818
1963
  createEventBus,
1819
1964
  createLimitPolicy,
1820
1965
  createUniformApiEnhancer,
1966
+ createVariableReference,
1821
1967
  enhance,
1822
1968
  extractLocales,
1823
1969
  generateHash,
@@ -1843,6 +1989,7 @@ export {
1843
1989
  mapSlotToPersonalizedVariations,
1844
1990
  mapSlotToTestVariations,
1845
1991
  nullLimitPolicy,
1992
+ parseVariableExpression,
1846
1993
  subscribeToComposition,
1847
1994
  unstable_CompositionRelationshipClient,
1848
1995
  walkComponentTree
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "19.35.2",
3
+ "version": "19.35.3-alpha.82+4bc341093",
4
4
  "description": "Common functionality and types for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "pusher-js": "8.2.0"
39
39
  },
40
40
  "dependencies": {
41
- "@uniformdev/context": "19.35.2",
41
+ "@uniformdev/context": "19.35.3-alpha.82+4bc341093",
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": "64d3270175087c87cfaa29a283aa4a7b0a98fd2c"
50
+ "gitHead": "4bc341093bc946900df2646fe53eca4bcddc693c"
51
51
  }