@uniformdev/canvas 19.80.1-alpha.149 → 19.80.1-alpha.192

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
@@ -634,13 +634,15 @@ var unstable_CompositionRelationshipClient = class extends ApiClient3 {
634
634
  super(options);
635
635
  this.getDefinitionsRelationships = async ({
636
636
  definitionIds,
637
- withCompositions
637
+ withCompositions,
638
+ entityType = "composition"
638
639
  }) => {
639
640
  const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL, {
640
641
  type: "definition",
641
642
  projectId: this._options.projectId,
642
643
  definitionIds: definitionIds.join(","),
643
- withCompositions
644
+ withCompositions,
645
+ entityType
644
646
  });
645
647
  return this.apiClient(url);
646
648
  };
@@ -1638,23 +1640,31 @@ function extractLocales({ component }) {
1638
1640
  });
1639
1641
  return variations;
1640
1642
  }
1641
- function localize({
1642
- composition,
1643
- locale
1644
- }) {
1645
- walkNodeTree(composition, ({ type, node, actions }) => {
1643
+ function localize(options) {
1644
+ const nodes = "nodes" in options ? options.nodes : options.composition;
1645
+ const locale = options.locale;
1646
+ walkNodeTree(nodes, ({ type, node, actions }) => {
1646
1647
  if (type !== "component") {
1647
- actions.stopProcessingDescendants();
1648
+ if (typeof locale === "string") {
1649
+ localizeProperties(node.fields, locale);
1650
+ }
1648
1651
  return;
1649
1652
  }
1653
+ const shouldRunPropertyLocalization = typeof locale === "string";
1650
1654
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
1651
1655
  const locales = extractLocales({ component: node });
1652
- const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
1656
+ const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
1653
1657
  let replaceComponent;
1654
1658
  if (resolvedLocale) {
1655
1659
  replaceComponent = locales[resolvedLocale];
1656
1660
  }
1657
1661
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1662
+ replaceComponent.forEach((component) => {
1663
+ removeLocaleProperty(component);
1664
+ if (shouldRunPropertyLocalization) {
1665
+ localizeProperties(getPropertiesValue(component), locale);
1666
+ }
1667
+ });
1658
1668
  const [first, ...rest] = replaceComponent;
1659
1669
  actions.replace(first);
1660
1670
  if (rest.length) {
@@ -1663,6 +1673,42 @@ function localize({
1663
1673
  } else {
1664
1674
  actions.remove();
1665
1675
  }
1676
+ } else if (shouldRunPropertyLocalization) {
1677
+ localizeProperties(getPropertiesValue(node), locale);
1678
+ }
1679
+ });
1680
+ }
1681
+ function removeLocaleProperty(component) {
1682
+ const properties = getPropertiesValue(component);
1683
+ const localeTagProperty = properties == null ? void 0 : properties[CANVAS_LOCALE_TAG_PARAM];
1684
+ if (localeTagProperty) {
1685
+ delete properties[CANVAS_LOCALE_TAG_PARAM];
1686
+ }
1687
+ if (properties && Object.keys(properties).length === 0) {
1688
+ if ("fields" in component) {
1689
+ delete component.fields;
1690
+ }
1691
+ if ("parameters" in component) {
1692
+ delete component.parameters;
1693
+ }
1694
+ }
1695
+ }
1696
+ function localizeProperties(properties, locale) {
1697
+ if (!properties) {
1698
+ return void 0;
1699
+ }
1700
+ Object.entries(properties).forEach(([key, property]) => {
1701
+ var _a;
1702
+ if (!locale) {
1703
+ delete property.locales;
1704
+ }
1705
+ const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
1706
+ if (currentLocaleValue !== void 0) {
1707
+ property.value = currentLocaleValue;
1708
+ }
1709
+ delete property.locales;
1710
+ if (property.value === void 0) {
1711
+ delete properties[key];
1666
1712
  }
1667
1713
  });
1668
1714
  }
@@ -1812,6 +1858,39 @@ function walkComponentTree(component, visitor, initialContext) {
1812
1858
  } while (componentQueue.length > 0);
1813
1859
  }
1814
1860
 
1861
+ // src/LocaleClient.ts
1862
+ import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
1863
+ var localesUrl = "/api/v1/locales";
1864
+ var LocaleClient = class extends ApiClient7 {
1865
+ constructor(options) {
1866
+ super(options);
1867
+ }
1868
+ /** Fetches all locales for a project */
1869
+ async get(options) {
1870
+ const { projectId } = this.options;
1871
+ const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
1872
+ return await this.apiClient(fetchUri);
1873
+ }
1874
+ /** Updates or creates (based on id) a locale */
1875
+ async upsert(body) {
1876
+ const fetchUri = this.createUrl(localesUrl);
1877
+ await this.apiClient(fetchUri, {
1878
+ method: "PUT",
1879
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1880
+ expectNoContent: true
1881
+ });
1882
+ }
1883
+ /** Deletes a locale */
1884
+ async remove(body) {
1885
+ const fetchUri = this.createUrl(localesUrl);
1886
+ await this.apiClient(fetchUri, {
1887
+ method: "DELETE",
1888
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1889
+ expectNoContent: true
1890
+ });
1891
+ }
1892
+ };
1893
+
1815
1894
  // src/utils/hash.ts
1816
1895
  var generateHash = ({
1817
1896
  composition,
@@ -2169,9 +2248,9 @@ function subscribeToComposition({
2169
2248
  }
2170
2249
 
2171
2250
  // src/PromptClient.ts
2172
- import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
2251
+ import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
2173
2252
  var PromptsUrl = "/api/v1/prompts";
2174
- var PromptClient = class extends ApiClient7 {
2253
+ var PromptClient = class extends ApiClient8 {
2175
2254
  constructor(options) {
2176
2255
  super(options);
2177
2256
  }
@@ -2202,9 +2281,9 @@ var PromptClient = class extends ApiClient7 {
2202
2281
  };
2203
2282
 
2204
2283
  // src/RouteClient.ts
2205
- import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
2284
+ import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
2206
2285
  var ROUTE_URL = "/api/v1/route";
2207
- var RouteClient = class extends ApiClient8 {
2286
+ var RouteClient = class extends ApiClient9 {
2208
2287
  constructor(options) {
2209
2288
  var _a;
2210
2289
  if (!options.limitPolicy) {
@@ -2221,6 +2300,9 @@ var RouteClient = class extends ApiClient8 {
2221
2300
  }
2222
2301
  };
2223
2302
 
2303
+ // src/types/locales.ts
2304
+ var LOCALE_DYNAMIC_INPUT_NAME = "locale";
2305
+
2224
2306
  // src/utils/createApiEnhancer.ts
2225
2307
  var createUniformApiEnhancer = ({ apiUrl }) => {
2226
2308
  return async (message) => {
@@ -2252,7 +2334,8 @@ function convertEntryToPutEntry(entry) {
2252
2334
  _id: entry.entry._id,
2253
2335
  _name: entry.entry._name,
2254
2336
  _slug: entry.entry._slug,
2255
- fields: entry.entry.fields
2337
+ fields: entry.entry.fields,
2338
+ _locales: entry.entry._locales
2256
2339
  },
2257
2340
  state: entry.state,
2258
2341
  projectId: entry.projectId
@@ -2585,6 +2668,8 @@ export {
2585
2668
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
2586
2669
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
2587
2670
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
2671
+ LOCALE_DYNAMIC_INPUT_NAME,
2672
+ LocaleClient,
2588
2673
  PLACEHOLDER_ID,
2589
2674
  PromptClient,
2590
2675
  RouteClient,
package/dist/index.js CHANGED
@@ -286,7 +286,7 @@ __export(src_exports, {
286
286
  ATTRIBUTE_PARAMETER_TYPE: () => ATTRIBUTE_PARAMETER_TYPE,
287
287
  ATTRIBUTE_PARAMETER_VALUE: () => ATTRIBUTE_PARAMETER_VALUE,
288
288
  ATTRIBUTE_PLACEHOLDER: () => ATTRIBUTE_PLACEHOLDER,
289
- ApiClientError: () => import_api10.ApiClientError,
289
+ ApiClientError: () => import_api11.ApiClientError,
290
290
  BatchEntry: () => BatchEntry,
291
291
  CANVAS_BLOCK_PARAM_TYPE: () => CANVAS_BLOCK_PARAM_TYPE,
292
292
  CANVAS_DRAFT_STATE: () => CANVAS_DRAFT_STATE,
@@ -323,6 +323,8 @@ __export(src_exports, {
323
323
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
324
324
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM: () => IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
325
325
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE: () => IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
326
+ LOCALE_DYNAMIC_INPUT_NAME: () => LOCALE_DYNAMIC_INPUT_NAME,
327
+ LocaleClient: () => LocaleClient,
326
328
  PLACEHOLDER_ID: () => PLACEHOLDER_ID,
327
329
  PromptClient: () => PromptClient,
328
330
  RouteClient: () => RouteClient,
@@ -759,13 +761,15 @@ var unstable_CompositionRelationshipClient = class extends import_api4.ApiClient
759
761
  super(options);
760
762
  this.getDefinitionsRelationships = async ({
761
763
  definitionIds,
762
- withCompositions
764
+ withCompositions,
765
+ entityType = "composition"
763
766
  }) => {
764
767
  const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL, {
765
768
  type: "definition",
766
769
  projectId: this._options.projectId,
767
770
  definitionIds: definitionIds.join(","),
768
- withCompositions
771
+ withCompositions,
772
+ entityType
769
773
  });
770
774
  return this.apiClient(url);
771
775
  };
@@ -1763,23 +1767,31 @@ function extractLocales({ component }) {
1763
1767
  });
1764
1768
  return variations;
1765
1769
  }
1766
- function localize({
1767
- composition,
1768
- locale
1769
- }) {
1770
- walkNodeTree(composition, ({ type, node, actions }) => {
1770
+ function localize(options) {
1771
+ const nodes = "nodes" in options ? options.nodes : options.composition;
1772
+ const locale = options.locale;
1773
+ walkNodeTree(nodes, ({ type, node, actions }) => {
1771
1774
  if (type !== "component") {
1772
- actions.stopProcessingDescendants();
1775
+ if (typeof locale === "string") {
1776
+ localizeProperties(node.fields, locale);
1777
+ }
1773
1778
  return;
1774
1779
  }
1780
+ const shouldRunPropertyLocalization = typeof locale === "string";
1775
1781
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
1776
1782
  const locales = extractLocales({ component: node });
1777
- const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
1783
+ const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
1778
1784
  let replaceComponent;
1779
1785
  if (resolvedLocale) {
1780
1786
  replaceComponent = locales[resolvedLocale];
1781
1787
  }
1782
1788
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1789
+ replaceComponent.forEach((component) => {
1790
+ removeLocaleProperty(component);
1791
+ if (shouldRunPropertyLocalization) {
1792
+ localizeProperties(getPropertiesValue(component), locale);
1793
+ }
1794
+ });
1783
1795
  const [first, ...rest] = replaceComponent;
1784
1796
  actions.replace(first);
1785
1797
  if (rest.length) {
@@ -1788,6 +1800,42 @@ function localize({
1788
1800
  } else {
1789
1801
  actions.remove();
1790
1802
  }
1803
+ } else if (shouldRunPropertyLocalization) {
1804
+ localizeProperties(getPropertiesValue(node), locale);
1805
+ }
1806
+ });
1807
+ }
1808
+ function removeLocaleProperty(component) {
1809
+ const properties = getPropertiesValue(component);
1810
+ const localeTagProperty = properties == null ? void 0 : properties[CANVAS_LOCALE_TAG_PARAM];
1811
+ if (localeTagProperty) {
1812
+ delete properties[CANVAS_LOCALE_TAG_PARAM];
1813
+ }
1814
+ if (properties && Object.keys(properties).length === 0) {
1815
+ if ("fields" in component) {
1816
+ delete component.fields;
1817
+ }
1818
+ if ("parameters" in component) {
1819
+ delete component.parameters;
1820
+ }
1821
+ }
1822
+ }
1823
+ function localizeProperties(properties, locale) {
1824
+ if (!properties) {
1825
+ return void 0;
1826
+ }
1827
+ Object.entries(properties).forEach(([key, property]) => {
1828
+ var _a;
1829
+ if (!locale) {
1830
+ delete property.locales;
1831
+ }
1832
+ const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
1833
+ if (currentLocaleValue !== void 0) {
1834
+ property.value = currentLocaleValue;
1835
+ }
1836
+ delete property.locales;
1837
+ if (property.value === void 0) {
1838
+ delete properties[key];
1791
1839
  }
1792
1840
  });
1793
1841
  }
@@ -1937,6 +1985,39 @@ function walkComponentTree(component, visitor, initialContext) {
1937
1985
  } while (componentQueue.length > 0);
1938
1986
  }
1939
1987
 
1988
+ // src/LocaleClient.ts
1989
+ var import_api8 = require("@uniformdev/context/api");
1990
+ var localesUrl = "/api/v1/locales";
1991
+ var LocaleClient = class extends import_api8.ApiClient {
1992
+ constructor(options) {
1993
+ super(options);
1994
+ }
1995
+ /** Fetches all locales for a project */
1996
+ async get(options) {
1997
+ const { projectId } = this.options;
1998
+ const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
1999
+ return await this.apiClient(fetchUri);
2000
+ }
2001
+ /** Updates or creates (based on id) a locale */
2002
+ async upsert(body) {
2003
+ const fetchUri = this.createUrl(localesUrl);
2004
+ await this.apiClient(fetchUri, {
2005
+ method: "PUT",
2006
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
2007
+ expectNoContent: true
2008
+ });
2009
+ }
2010
+ /** Deletes a locale */
2011
+ async remove(body) {
2012
+ const fetchUri = this.createUrl(localesUrl);
2013
+ await this.apiClient(fetchUri, {
2014
+ method: "DELETE",
2015
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
2016
+ expectNoContent: true
2017
+ });
2018
+ }
2019
+ };
2020
+
1940
2021
  // src/utils/hash.ts
1941
2022
  var generateHash = ({
1942
2023
  composition,
@@ -2294,9 +2375,9 @@ function subscribeToComposition({
2294
2375
  }
2295
2376
 
2296
2377
  // src/PromptClient.ts
2297
- var import_api8 = require("@uniformdev/context/api");
2378
+ var import_api9 = require("@uniformdev/context/api");
2298
2379
  var PromptsUrl = "/api/v1/prompts";
2299
- var PromptClient = class extends import_api8.ApiClient {
2380
+ var PromptClient = class extends import_api9.ApiClient {
2300
2381
  constructor(options) {
2301
2382
  super(options);
2302
2383
  }
@@ -2327,9 +2408,9 @@ var PromptClient = class extends import_api8.ApiClient {
2327
2408
  };
2328
2409
 
2329
2410
  // src/RouteClient.ts
2330
- var import_api9 = require("@uniformdev/context/api");
2411
+ var import_api10 = require("@uniformdev/context/api");
2331
2412
  var ROUTE_URL = "/api/v1/route";
2332
- var RouteClient = class extends import_api9.ApiClient {
2413
+ var RouteClient = class extends import_api10.ApiClient {
2333
2414
  constructor(options) {
2334
2415
  var _a;
2335
2416
  if (!options.limitPolicy) {
@@ -2346,6 +2427,9 @@ var RouteClient = class extends import_api9.ApiClient {
2346
2427
  }
2347
2428
  };
2348
2429
 
2430
+ // src/types/locales.ts
2431
+ var LOCALE_DYNAMIC_INPUT_NAME = "locale";
2432
+
2349
2433
  // src/utils/createApiEnhancer.ts
2350
2434
  var createUniformApiEnhancer = ({ apiUrl }) => {
2351
2435
  return async (message) => {
@@ -2377,7 +2461,8 @@ function convertEntryToPutEntry(entry) {
2377
2461
  _id: entry.entry._id,
2378
2462
  _name: entry.entry._name,
2379
2463
  _slug: entry.entry._slug,
2380
- fields: entry.entry.fields
2464
+ fields: entry.entry.fields,
2465
+ _locales: entry.entry._locales
2381
2466
  },
2382
2467
  state: entry.state,
2383
2468
  projectId: entry.projectId
@@ -2661,8 +2746,8 @@ function handleRichTextNodeBinding(object, options) {
2661
2746
  }
2662
2747
 
2663
2748
  // src/index.ts
2664
- var import_api10 = require("@uniformdev/context/api");
2665
- var CanvasClientError = import_api10.ApiClientError;
2749
+ var import_api11 = require("@uniformdev/context/api");
2750
+ var CanvasClientError = import_api11.ApiClientError;
2666
2751
  // Annotate the CommonJS export names for ESM import in node:
2667
2752
  0 && (module.exports = {
2668
2753
  ASSETS_SOURCE_CUSTOM_URL,
@@ -2711,6 +2796,8 @@ var CanvasClientError = import_api10.ApiClientError;
2711
2796
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
2712
2797
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
2713
2798
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
2799
+ LOCALE_DYNAMIC_INPUT_NAME,
2800
+ LocaleClient,
2714
2801
  PLACEHOLDER_ID,
2715
2802
  PromptClient,
2716
2803
  RouteClient,
package/dist/index.mjs CHANGED
@@ -634,13 +634,15 @@ var unstable_CompositionRelationshipClient = class extends ApiClient3 {
634
634
  super(options);
635
635
  this.getDefinitionsRelationships = async ({
636
636
  definitionIds,
637
- withCompositions
637
+ withCompositions,
638
+ entityType = "composition"
638
639
  }) => {
639
640
  const url = this.createUrl(COMPOSITION_RELATIONSHIP_URL, {
640
641
  type: "definition",
641
642
  projectId: this._options.projectId,
642
643
  definitionIds: definitionIds.join(","),
643
- withCompositions
644
+ withCompositions,
645
+ entityType
644
646
  });
645
647
  return this.apiClient(url);
646
648
  };
@@ -1638,23 +1640,31 @@ function extractLocales({ component }) {
1638
1640
  });
1639
1641
  return variations;
1640
1642
  }
1641
- function localize({
1642
- composition,
1643
- locale
1644
- }) {
1645
- walkNodeTree(composition, ({ type, node, actions }) => {
1643
+ function localize(options) {
1644
+ const nodes = "nodes" in options ? options.nodes : options.composition;
1645
+ const locale = options.locale;
1646
+ walkNodeTree(nodes, ({ type, node, actions }) => {
1646
1647
  if (type !== "component") {
1647
- actions.stopProcessingDescendants();
1648
+ if (typeof locale === "string") {
1649
+ localizeProperties(node.fields, locale);
1650
+ }
1648
1651
  return;
1649
1652
  }
1653
+ const shouldRunPropertyLocalization = typeof locale === "string";
1650
1654
  if (node.type === CANVAS_LOCALIZATION_TYPE) {
1651
1655
  const locales = extractLocales({ component: node });
1652
- const resolvedLocale = typeof locale === "string" ? locale : locale({ component: node, locales });
1656
+ const resolvedLocale = typeof locale === "string" ? locale : locale == null ? void 0 : locale({ component: node, locales });
1653
1657
  let replaceComponent;
1654
1658
  if (resolvedLocale) {
1655
1659
  replaceComponent = locales[resolvedLocale];
1656
1660
  }
1657
1661
  if (replaceComponent == null ? void 0 : replaceComponent.length) {
1662
+ replaceComponent.forEach((component) => {
1663
+ removeLocaleProperty(component);
1664
+ if (shouldRunPropertyLocalization) {
1665
+ localizeProperties(getPropertiesValue(component), locale);
1666
+ }
1667
+ });
1658
1668
  const [first, ...rest] = replaceComponent;
1659
1669
  actions.replace(first);
1660
1670
  if (rest.length) {
@@ -1663,6 +1673,42 @@ function localize({
1663
1673
  } else {
1664
1674
  actions.remove();
1665
1675
  }
1676
+ } else if (shouldRunPropertyLocalization) {
1677
+ localizeProperties(getPropertiesValue(node), locale);
1678
+ }
1679
+ });
1680
+ }
1681
+ function removeLocaleProperty(component) {
1682
+ const properties = getPropertiesValue(component);
1683
+ const localeTagProperty = properties == null ? void 0 : properties[CANVAS_LOCALE_TAG_PARAM];
1684
+ if (localeTagProperty) {
1685
+ delete properties[CANVAS_LOCALE_TAG_PARAM];
1686
+ }
1687
+ if (properties && Object.keys(properties).length === 0) {
1688
+ if ("fields" in component) {
1689
+ delete component.fields;
1690
+ }
1691
+ if ("parameters" in component) {
1692
+ delete component.parameters;
1693
+ }
1694
+ }
1695
+ }
1696
+ function localizeProperties(properties, locale) {
1697
+ if (!properties) {
1698
+ return void 0;
1699
+ }
1700
+ Object.entries(properties).forEach(([key, property]) => {
1701
+ var _a;
1702
+ if (!locale) {
1703
+ delete property.locales;
1704
+ }
1705
+ const currentLocaleValue = locale ? (_a = property.locales) == null ? void 0 : _a[locale] : void 0;
1706
+ if (currentLocaleValue !== void 0) {
1707
+ property.value = currentLocaleValue;
1708
+ }
1709
+ delete property.locales;
1710
+ if (property.value === void 0) {
1711
+ delete properties[key];
1666
1712
  }
1667
1713
  });
1668
1714
  }
@@ -1812,6 +1858,39 @@ function walkComponentTree(component, visitor, initialContext) {
1812
1858
  } while (componentQueue.length > 0);
1813
1859
  }
1814
1860
 
1861
+ // src/LocaleClient.ts
1862
+ import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
1863
+ var localesUrl = "/api/v1/locales";
1864
+ var LocaleClient = class extends ApiClient7 {
1865
+ constructor(options) {
1866
+ super(options);
1867
+ }
1868
+ /** Fetches all locales for a project */
1869
+ async get(options) {
1870
+ const { projectId } = this.options;
1871
+ const fetchUri = this.createUrl(localesUrl, { ...options, projectId });
1872
+ return await this.apiClient(fetchUri);
1873
+ }
1874
+ /** Updates or creates (based on id) a locale */
1875
+ async upsert(body) {
1876
+ const fetchUri = this.createUrl(localesUrl);
1877
+ await this.apiClient(fetchUri, {
1878
+ method: "PUT",
1879
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1880
+ expectNoContent: true
1881
+ });
1882
+ }
1883
+ /** Deletes a locale */
1884
+ async remove(body) {
1885
+ const fetchUri = this.createUrl(localesUrl);
1886
+ await this.apiClient(fetchUri, {
1887
+ method: "DELETE",
1888
+ body: JSON.stringify({ ...body, projectId: this.options.projectId }),
1889
+ expectNoContent: true
1890
+ });
1891
+ }
1892
+ };
1893
+
1815
1894
  // src/utils/hash.ts
1816
1895
  var generateHash = ({
1817
1896
  composition,
@@ -2169,9 +2248,9 @@ function subscribeToComposition({
2169
2248
  }
2170
2249
 
2171
2250
  // src/PromptClient.ts
2172
- import { ApiClient as ApiClient7 } from "@uniformdev/context/api";
2251
+ import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
2173
2252
  var PromptsUrl = "/api/v1/prompts";
2174
- var PromptClient = class extends ApiClient7 {
2253
+ var PromptClient = class extends ApiClient8 {
2175
2254
  constructor(options) {
2176
2255
  super(options);
2177
2256
  }
@@ -2202,9 +2281,9 @@ var PromptClient = class extends ApiClient7 {
2202
2281
  };
2203
2282
 
2204
2283
  // src/RouteClient.ts
2205
- import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
2284
+ import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
2206
2285
  var ROUTE_URL = "/api/v1/route";
2207
- var RouteClient = class extends ApiClient8 {
2286
+ var RouteClient = class extends ApiClient9 {
2208
2287
  constructor(options) {
2209
2288
  var _a;
2210
2289
  if (!options.limitPolicy) {
@@ -2221,6 +2300,9 @@ var RouteClient = class extends ApiClient8 {
2221
2300
  }
2222
2301
  };
2223
2302
 
2303
+ // src/types/locales.ts
2304
+ var LOCALE_DYNAMIC_INPUT_NAME = "locale";
2305
+
2224
2306
  // src/utils/createApiEnhancer.ts
2225
2307
  var createUniformApiEnhancer = ({ apiUrl }) => {
2226
2308
  return async (message) => {
@@ -2252,7 +2334,8 @@ function convertEntryToPutEntry(entry) {
2252
2334
  _id: entry.entry._id,
2253
2335
  _name: entry.entry._name,
2254
2336
  _slug: entry.entry._slug,
2255
- fields: entry.entry.fields
2337
+ fields: entry.entry.fields,
2338
+ _locales: entry.entry._locales
2256
2339
  },
2257
2340
  state: entry.state,
2258
2341
  projectId: entry.projectId
@@ -2585,6 +2668,8 @@ export {
2585
2668
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
2586
2669
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
2587
2670
  IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
2671
+ LOCALE_DYNAMIC_INPUT_NAME,
2672
+ LocaleClient,
2588
2673
  PLACEHOLDER_ID,
2589
2674
  PromptClient,
2590
2675
  RouteClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas",
3
- "version": "19.80.1-alpha.149+7f4e45fecc",
3
+ "version": "19.80.1-alpha.192+a267dfba25",
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,8 +38,8 @@
38
38
  "pusher-js": "8.2.0"
39
39
  },
40
40
  "dependencies": {
41
- "@uniformdev/assets": "19.80.1-alpha.149+7f4e45fecc",
42
- "@uniformdev/context": "19.80.1-alpha.149+7f4e45fecc",
41
+ "@uniformdev/assets": "19.80.1-alpha.192+a267dfba25",
42
+ "@uniformdev/context": "19.80.1-alpha.192+a267dfba25",
43
43
  "immer": "10.0.3"
44
44
  },
45
45
  "files": [
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "7f4e45fecc013dc224fbd0a2975f6d208382b05e"
51
+ "gitHead": "a267dfba252cb26b79bc51681d526f2fbb8d5af3"
52
52
  }