@uniformdev/canvas 19.88.0 → 19.89.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.d.mts +1338 -604
- package/dist/index.d.ts +1338 -604
- package/dist/index.esm.js +95 -12
- package/dist/index.js +100 -15
- package/dist/index.mjs +95 -12
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
@@ -1640,23 +1640,31 @@ function extractLocales({ component }) {
|
|
1640
1640
|
});
|
1641
1641
|
return variations;
|
1642
1642
|
}
|
1643
|
-
function localize({
|
1644
|
-
composition
|
1645
|
-
locale
|
1646
|
-
}) {
|
1647
|
-
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 }) => {
|
1648
1647
|
if (type !== "component") {
|
1649
|
-
|
1648
|
+
if (typeof locale === "string") {
|
1649
|
+
localizeProperties(node.fields, locale);
|
1650
|
+
}
|
1650
1651
|
return;
|
1651
1652
|
}
|
1653
|
+
const shouldRunPropertyLocalization = typeof locale === "string";
|
1652
1654
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1653
1655
|
const locales = extractLocales({ component: node });
|
1654
|
-
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 });
|
1655
1657
|
let replaceComponent;
|
1656
1658
|
if (resolvedLocale) {
|
1657
1659
|
replaceComponent = locales[resolvedLocale];
|
1658
1660
|
}
|
1659
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
|
+
});
|
1660
1668
|
const [first, ...rest] = replaceComponent;
|
1661
1669
|
actions.replace(first);
|
1662
1670
|
if (rest.length) {
|
@@ -1665,6 +1673,42 @@ function localize({
|
|
1665
1673
|
} else {
|
1666
1674
|
actions.remove();
|
1667
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];
|
1668
1712
|
}
|
1669
1713
|
});
|
1670
1714
|
}
|
@@ -1814,6 +1858,39 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1814
1858
|
} while (componentQueue.length > 0);
|
1815
1859
|
}
|
1816
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
|
+
|
1817
1894
|
// src/utils/hash.ts
|
1818
1895
|
var generateHash = ({
|
1819
1896
|
composition,
|
@@ -2171,9 +2248,9 @@ function subscribeToComposition({
|
|
2171
2248
|
}
|
2172
2249
|
|
2173
2250
|
// src/PromptClient.ts
|
2174
|
-
import { ApiClient as
|
2251
|
+
import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
|
2175
2252
|
var PromptsUrl = "/api/v1/prompts";
|
2176
|
-
var PromptClient = class extends
|
2253
|
+
var PromptClient = class extends ApiClient8 {
|
2177
2254
|
constructor(options) {
|
2178
2255
|
super(options);
|
2179
2256
|
}
|
@@ -2204,9 +2281,9 @@ var PromptClient = class extends ApiClient7 {
|
|
2204
2281
|
};
|
2205
2282
|
|
2206
2283
|
// src/RouteClient.ts
|
2207
|
-
import { ApiClient as
|
2284
|
+
import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
|
2208
2285
|
var ROUTE_URL = "/api/v1/route";
|
2209
|
-
var RouteClient = class extends
|
2286
|
+
var RouteClient = class extends ApiClient9 {
|
2210
2287
|
constructor(options) {
|
2211
2288
|
var _a;
|
2212
2289
|
if (!options.limitPolicy) {
|
@@ -2223,6 +2300,9 @@ var RouteClient = class extends ApiClient8 {
|
|
2223
2300
|
}
|
2224
2301
|
};
|
2225
2302
|
|
2303
|
+
// src/types/locales.ts
|
2304
|
+
var LOCALE_DYNAMIC_INPUT_NAME = "locale";
|
2305
|
+
|
2226
2306
|
// src/utils/createApiEnhancer.ts
|
2227
2307
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
2228
2308
|
return async (message) => {
|
@@ -2254,7 +2334,8 @@ function convertEntryToPutEntry(entry) {
|
|
2254
2334
|
_id: entry.entry._id,
|
2255
2335
|
_name: entry.entry._name,
|
2256
2336
|
_slug: entry.entry._slug,
|
2257
|
-
fields: entry.entry.fields
|
2337
|
+
fields: entry.entry.fields,
|
2338
|
+
_locales: entry.entry._locales
|
2258
2339
|
},
|
2259
2340
|
state: entry.state,
|
2260
2341
|
projectId: entry.projectId
|
@@ -2587,6 +2668,8 @@ export {
|
|
2587
2668
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
2588
2669
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
2589
2670
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
2671
|
+
LOCALE_DYNAMIC_INPUT_NAME,
|
2672
|
+
LocaleClient,
|
2590
2673
|
PLACEHOLDER_ID,
|
2591
2674
|
PromptClient,
|
2592
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: () =>
|
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,
|
@@ -1765,23 +1767,31 @@ function extractLocales({ component }) {
|
|
1765
1767
|
});
|
1766
1768
|
return variations;
|
1767
1769
|
}
|
1768
|
-
function localize({
|
1769
|
-
composition
|
1770
|
-
locale
|
1771
|
-
}) {
|
1772
|
-
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 }) => {
|
1773
1774
|
if (type !== "component") {
|
1774
|
-
|
1775
|
+
if (typeof locale === "string") {
|
1776
|
+
localizeProperties(node.fields, locale);
|
1777
|
+
}
|
1775
1778
|
return;
|
1776
1779
|
}
|
1780
|
+
const shouldRunPropertyLocalization = typeof locale === "string";
|
1777
1781
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1778
1782
|
const locales = extractLocales({ component: node });
|
1779
|
-
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 });
|
1780
1784
|
let replaceComponent;
|
1781
1785
|
if (resolvedLocale) {
|
1782
1786
|
replaceComponent = locales[resolvedLocale];
|
1783
1787
|
}
|
1784
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
|
+
});
|
1785
1795
|
const [first, ...rest] = replaceComponent;
|
1786
1796
|
actions.replace(first);
|
1787
1797
|
if (rest.length) {
|
@@ -1790,6 +1800,42 @@ function localize({
|
|
1790
1800
|
} else {
|
1791
1801
|
actions.remove();
|
1792
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];
|
1793
1839
|
}
|
1794
1840
|
});
|
1795
1841
|
}
|
@@ -1939,6 +1985,39 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1939
1985
|
} while (componentQueue.length > 0);
|
1940
1986
|
}
|
1941
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
|
+
|
1942
2021
|
// src/utils/hash.ts
|
1943
2022
|
var generateHash = ({
|
1944
2023
|
composition,
|
@@ -2296,9 +2375,9 @@ function subscribeToComposition({
|
|
2296
2375
|
}
|
2297
2376
|
|
2298
2377
|
// src/PromptClient.ts
|
2299
|
-
var
|
2378
|
+
var import_api9 = require("@uniformdev/context/api");
|
2300
2379
|
var PromptsUrl = "/api/v1/prompts";
|
2301
|
-
var PromptClient = class extends
|
2380
|
+
var PromptClient = class extends import_api9.ApiClient {
|
2302
2381
|
constructor(options) {
|
2303
2382
|
super(options);
|
2304
2383
|
}
|
@@ -2329,9 +2408,9 @@ var PromptClient = class extends import_api8.ApiClient {
|
|
2329
2408
|
};
|
2330
2409
|
|
2331
2410
|
// src/RouteClient.ts
|
2332
|
-
var
|
2411
|
+
var import_api10 = require("@uniformdev/context/api");
|
2333
2412
|
var ROUTE_URL = "/api/v1/route";
|
2334
|
-
var RouteClient = class extends
|
2413
|
+
var RouteClient = class extends import_api10.ApiClient {
|
2335
2414
|
constructor(options) {
|
2336
2415
|
var _a;
|
2337
2416
|
if (!options.limitPolicy) {
|
@@ -2348,6 +2427,9 @@ var RouteClient = class extends import_api9.ApiClient {
|
|
2348
2427
|
}
|
2349
2428
|
};
|
2350
2429
|
|
2430
|
+
// src/types/locales.ts
|
2431
|
+
var LOCALE_DYNAMIC_INPUT_NAME = "locale";
|
2432
|
+
|
2351
2433
|
// src/utils/createApiEnhancer.ts
|
2352
2434
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
2353
2435
|
return async (message) => {
|
@@ -2379,7 +2461,8 @@ function convertEntryToPutEntry(entry) {
|
|
2379
2461
|
_id: entry.entry._id,
|
2380
2462
|
_name: entry.entry._name,
|
2381
2463
|
_slug: entry.entry._slug,
|
2382
|
-
fields: entry.entry.fields
|
2464
|
+
fields: entry.entry.fields,
|
2465
|
+
_locales: entry.entry._locales
|
2383
2466
|
},
|
2384
2467
|
state: entry.state,
|
2385
2468
|
projectId: entry.projectId
|
@@ -2663,8 +2746,8 @@ function handleRichTextNodeBinding(object, options) {
|
|
2663
2746
|
}
|
2664
2747
|
|
2665
2748
|
// src/index.ts
|
2666
|
-
var
|
2667
|
-
var CanvasClientError =
|
2749
|
+
var import_api11 = require("@uniformdev/context/api");
|
2750
|
+
var CanvasClientError = import_api11.ApiClientError;
|
2668
2751
|
// Annotate the CommonJS export names for ESM import in node:
|
2669
2752
|
0 && (module.exports = {
|
2670
2753
|
ASSETS_SOURCE_CUSTOM_URL,
|
@@ -2713,6 +2796,8 @@ var CanvasClientError = import_api10.ApiClientError;
|
|
2713
2796
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
2714
2797
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
2715
2798
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
2799
|
+
LOCALE_DYNAMIC_INPUT_NAME,
|
2800
|
+
LocaleClient,
|
2716
2801
|
PLACEHOLDER_ID,
|
2717
2802
|
PromptClient,
|
2718
2803
|
RouteClient,
|
package/dist/index.mjs
CHANGED
@@ -1640,23 +1640,31 @@ function extractLocales({ component }) {
|
|
1640
1640
|
});
|
1641
1641
|
return variations;
|
1642
1642
|
}
|
1643
|
-
function localize({
|
1644
|
-
composition
|
1645
|
-
locale
|
1646
|
-
}) {
|
1647
|
-
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 }) => {
|
1648
1647
|
if (type !== "component") {
|
1649
|
-
|
1648
|
+
if (typeof locale === "string") {
|
1649
|
+
localizeProperties(node.fields, locale);
|
1650
|
+
}
|
1650
1651
|
return;
|
1651
1652
|
}
|
1653
|
+
const shouldRunPropertyLocalization = typeof locale === "string";
|
1652
1654
|
if (node.type === CANVAS_LOCALIZATION_TYPE) {
|
1653
1655
|
const locales = extractLocales({ component: node });
|
1654
|
-
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 });
|
1655
1657
|
let replaceComponent;
|
1656
1658
|
if (resolvedLocale) {
|
1657
1659
|
replaceComponent = locales[resolvedLocale];
|
1658
1660
|
}
|
1659
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
|
+
});
|
1660
1668
|
const [first, ...rest] = replaceComponent;
|
1661
1669
|
actions.replace(first);
|
1662
1670
|
if (rest.length) {
|
@@ -1665,6 +1673,42 @@ function localize({
|
|
1665
1673
|
} else {
|
1666
1674
|
actions.remove();
|
1667
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];
|
1668
1712
|
}
|
1669
1713
|
});
|
1670
1714
|
}
|
@@ -1814,6 +1858,39 @@ function walkComponentTree(component, visitor, initialContext) {
|
|
1814
1858
|
} while (componentQueue.length > 0);
|
1815
1859
|
}
|
1816
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
|
+
|
1817
1894
|
// src/utils/hash.ts
|
1818
1895
|
var generateHash = ({
|
1819
1896
|
composition,
|
@@ -2171,9 +2248,9 @@ function subscribeToComposition({
|
|
2171
2248
|
}
|
2172
2249
|
|
2173
2250
|
// src/PromptClient.ts
|
2174
|
-
import { ApiClient as
|
2251
|
+
import { ApiClient as ApiClient8 } from "@uniformdev/context/api";
|
2175
2252
|
var PromptsUrl = "/api/v1/prompts";
|
2176
|
-
var PromptClient = class extends
|
2253
|
+
var PromptClient = class extends ApiClient8 {
|
2177
2254
|
constructor(options) {
|
2178
2255
|
super(options);
|
2179
2256
|
}
|
@@ -2204,9 +2281,9 @@ var PromptClient = class extends ApiClient7 {
|
|
2204
2281
|
};
|
2205
2282
|
|
2206
2283
|
// src/RouteClient.ts
|
2207
|
-
import { ApiClient as
|
2284
|
+
import { ApiClient as ApiClient9 } from "@uniformdev/context/api";
|
2208
2285
|
var ROUTE_URL = "/api/v1/route";
|
2209
|
-
var RouteClient = class extends
|
2286
|
+
var RouteClient = class extends ApiClient9 {
|
2210
2287
|
constructor(options) {
|
2211
2288
|
var _a;
|
2212
2289
|
if (!options.limitPolicy) {
|
@@ -2223,6 +2300,9 @@ var RouteClient = class extends ApiClient8 {
|
|
2223
2300
|
}
|
2224
2301
|
};
|
2225
2302
|
|
2303
|
+
// src/types/locales.ts
|
2304
|
+
var LOCALE_DYNAMIC_INPUT_NAME = "locale";
|
2305
|
+
|
2226
2306
|
// src/utils/createApiEnhancer.ts
|
2227
2307
|
var createUniformApiEnhancer = ({ apiUrl }) => {
|
2228
2308
|
return async (message) => {
|
@@ -2254,7 +2334,8 @@ function convertEntryToPutEntry(entry) {
|
|
2254
2334
|
_id: entry.entry._id,
|
2255
2335
|
_name: entry.entry._name,
|
2256
2336
|
_slug: entry.entry._slug,
|
2257
|
-
fields: entry.entry.fields
|
2337
|
+
fields: entry.entry.fields,
|
2338
|
+
_locales: entry.entry._locales
|
2258
2339
|
},
|
2259
2340
|
state: entry.state,
|
2260
2341
|
projectId: entry.projectId
|
@@ -2587,6 +2668,8 @@ export {
|
|
2587
2668
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
2588
2669
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
2589
2670
|
IS_RENDERED_BY_UNIFORM_ATTRIBUTE,
|
2671
|
+
LOCALE_DYNAMIC_INPUT_NAME,
|
2672
|
+
LocaleClient,
|
2590
2673
|
PLACEHOLDER_ID,
|
2591
2674
|
PromptClient,
|
2592
2675
|
RouteClient,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/canvas",
|
3
|
-
"version": "19.
|
3
|
+
"version": "19.89.0",
|
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.
|
42
|
-
"@uniformdev/context": "19.
|
41
|
+
"@uniformdev/assets": "19.89.0",
|
42
|
+
"@uniformdev/context": "19.89.0",
|
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": "
|
51
|
+
"gitHead": "247189fb1039d0f81498949534646baaffb8bca7"
|
52
52
|
}
|