@webstudio-is/react-sdk 0.131.0 → 0.133.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/lib/index.js +89 -28
- package/lib/types/expression.d.ts +34 -1
- package/lib/types/page-meta-generator.d.ts +5 -3
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -787,6 +787,7 @@ var decodeDataSourceVariable = (name) => {
|
|
|
787
787
|
var generateExpression = ({
|
|
788
788
|
expression,
|
|
789
789
|
dataSources,
|
|
790
|
+
usedDataSources,
|
|
790
791
|
scope
|
|
791
792
|
}) => {
|
|
792
793
|
return validateExpression(expression, {
|
|
@@ -798,6 +799,7 @@ var generateExpression = ({
|
|
|
798
799
|
const depId = decodeDataSourceVariable(identifier);
|
|
799
800
|
const dep = depId ? dataSources.get(depId) : void 0;
|
|
800
801
|
if (dep) {
|
|
802
|
+
usedDataSources?.set(dep.id, dep);
|
|
801
803
|
return scope.getName(dep.id, dep.name);
|
|
802
804
|
}
|
|
803
805
|
return identifier;
|
|
@@ -1763,25 +1765,33 @@ var generateResourcesLoader = ({
|
|
|
1763
1765
|
};
|
|
1764
1766
|
|
|
1765
1767
|
// src/page-meta-generator.ts
|
|
1768
|
+
import {
|
|
1769
|
+
createScope
|
|
1770
|
+
} from "@webstudio-is/sdk";
|
|
1766
1771
|
var generatePageMeta = ({
|
|
1767
|
-
|
|
1772
|
+
globalScope,
|
|
1768
1773
|
page,
|
|
1769
1774
|
dataSources
|
|
1770
1775
|
}) => {
|
|
1776
|
+
const localScope = createScope(["params", "resources"]);
|
|
1777
|
+
const usedDataSources = /* @__PURE__ */ new Map();
|
|
1771
1778
|
const titleExpression = generateExpression({
|
|
1772
1779
|
expression: page.title,
|
|
1773
1780
|
dataSources,
|
|
1774
|
-
|
|
1781
|
+
usedDataSources,
|
|
1782
|
+
scope: localScope
|
|
1775
1783
|
});
|
|
1776
1784
|
const descriptionExpression = generateExpression({
|
|
1777
1785
|
expression: page.meta.description ?? "undefined",
|
|
1778
1786
|
dataSources,
|
|
1779
|
-
|
|
1787
|
+
usedDataSources,
|
|
1788
|
+
scope: localScope
|
|
1780
1789
|
});
|
|
1781
1790
|
const excludePageFromSearchExpression = generateExpression({
|
|
1782
1791
|
expression: page.meta.excludePageFromSearch ?? "undefined",
|
|
1783
1792
|
dataSources,
|
|
1784
|
-
|
|
1793
|
+
usedDataSources,
|
|
1794
|
+
scope: localScope
|
|
1785
1795
|
});
|
|
1786
1796
|
const socialImageAssetIdExpression = JSON.stringify(
|
|
1787
1797
|
page.meta.socialImageAssetId
|
|
@@ -1789,10 +1799,53 @@ var generatePageMeta = ({
|
|
|
1789
1799
|
const socialImageUrlExpression = generateExpression({
|
|
1790
1800
|
expression: page.meta.socialImageUrl ?? "undefined",
|
|
1791
1801
|
dataSources,
|
|
1792
|
-
|
|
1802
|
+
usedDataSources,
|
|
1803
|
+
scope: localScope
|
|
1804
|
+
});
|
|
1805
|
+
const statusExpression = generateExpression({
|
|
1806
|
+
expression: page.meta.status ?? "undefined",
|
|
1807
|
+
dataSources,
|
|
1808
|
+
usedDataSources,
|
|
1809
|
+
scope: localScope
|
|
1810
|
+
});
|
|
1811
|
+
const redirectExpression = generateExpression({
|
|
1812
|
+
expression: page.meta.redirect ?? "undefined",
|
|
1813
|
+
dataSources,
|
|
1814
|
+
usedDataSources,
|
|
1815
|
+
scope: localScope
|
|
1793
1816
|
});
|
|
1817
|
+
let customExpression = "";
|
|
1818
|
+
customExpression += `[
|
|
1819
|
+
`;
|
|
1820
|
+
for (const customMeta of page.meta.custom ?? []) {
|
|
1821
|
+
if (customMeta.property.trim().length === 0) {
|
|
1822
|
+
continue;
|
|
1823
|
+
}
|
|
1824
|
+
const propertyExpression = JSON.stringify(customMeta.property);
|
|
1825
|
+
const contentExpression = generateExpression({
|
|
1826
|
+
expression: customMeta.content,
|
|
1827
|
+
dataSources,
|
|
1828
|
+
usedDataSources,
|
|
1829
|
+
scope: localScope
|
|
1830
|
+
});
|
|
1831
|
+
customExpression += ` {
|
|
1832
|
+
`;
|
|
1833
|
+
customExpression += ` property: ${propertyExpression},
|
|
1834
|
+
`;
|
|
1835
|
+
customExpression += ` content: ${contentExpression},
|
|
1836
|
+
`;
|
|
1837
|
+
customExpression += ` },
|
|
1838
|
+
`;
|
|
1839
|
+
}
|
|
1840
|
+
customExpression += ` ]`;
|
|
1794
1841
|
let generated = "";
|
|
1795
|
-
generated += `export const getPageMeta = ({
|
|
1842
|
+
generated += `export const getPageMeta = ({
|
|
1843
|
+
`;
|
|
1844
|
+
generated += ` params,
|
|
1845
|
+
`;
|
|
1846
|
+
generated += ` resources,
|
|
1847
|
+
`;
|
|
1848
|
+
generated += `}: {
|
|
1796
1849
|
`;
|
|
1797
1850
|
generated += ` params: Record<string, undefined | string>;
|
|
1798
1851
|
`;
|
|
@@ -1800,6 +1853,33 @@ var generatePageMeta = ({
|
|
|
1800
1853
|
`;
|
|
1801
1854
|
generated += `}): PageMeta => {
|
|
1802
1855
|
`;
|
|
1856
|
+
for (const dataSource of usedDataSources.values()) {
|
|
1857
|
+
if (dataSource.type === "variable") {
|
|
1858
|
+
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1859
|
+
const initialValueString = JSON.stringify(dataSource.value.value);
|
|
1860
|
+
generated += ` let ${valueName} = ${initialValueString}
|
|
1861
|
+
`;
|
|
1862
|
+
continue;
|
|
1863
|
+
}
|
|
1864
|
+
if (dataSource.type === "parameter") {
|
|
1865
|
+
if (dataSource.id === page.pathVariableId) {
|
|
1866
|
+
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1867
|
+
generated += ` let ${valueName} = params
|
|
1868
|
+
`;
|
|
1869
|
+
}
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
if (dataSource.type === "resource") {
|
|
1873
|
+
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1874
|
+
const resourceName = globalScope.getName(
|
|
1875
|
+
dataSource.resourceId,
|
|
1876
|
+
dataSource.name
|
|
1877
|
+
);
|
|
1878
|
+
generated += ` let ${valueName} = resources.${resourceName}
|
|
1879
|
+
`;
|
|
1880
|
+
continue;
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1803
1883
|
generated += ` return {
|
|
1804
1884
|
`;
|
|
1805
1885
|
generated += ` title: ${titleExpression},
|
|
@@ -1812,30 +1892,11 @@ var generatePageMeta = ({
|
|
|
1812
1892
|
`;
|
|
1813
1893
|
generated += ` socialImageUrl: ${socialImageUrlExpression},
|
|
1814
1894
|
`;
|
|
1815
|
-
generated += `
|
|
1895
|
+
generated += ` status: ${statusExpression},
|
|
1816
1896
|
`;
|
|
1817
|
-
|
|
1818
|
-
for (const customMeta of page.meta.custom) {
|
|
1819
|
-
if (customMeta.property.trim().length === 0) {
|
|
1820
|
-
continue;
|
|
1821
|
-
}
|
|
1822
|
-
const propertyExpression = JSON.stringify(customMeta.property);
|
|
1823
|
-
const contentExpression = generateExpression({
|
|
1824
|
-
scope,
|
|
1825
|
-
dataSources,
|
|
1826
|
-
expression: customMeta.content
|
|
1827
|
-
});
|
|
1828
|
-
generated += ` {
|
|
1897
|
+
generated += ` redirect: ${redirectExpression},
|
|
1829
1898
|
`;
|
|
1830
|
-
|
|
1831
|
-
`;
|
|
1832
|
-
generated += ` content: ${contentExpression},
|
|
1833
|
-
`;
|
|
1834
|
-
generated += ` },
|
|
1835
|
-
`;
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
generated += ` ],
|
|
1899
|
+
generated += ` custom: ${customExpression},
|
|
1839
1900
|
`;
|
|
1840
1901
|
generated += ` };
|
|
1841
1902
|
`;
|
|
@@ -14,7 +14,7 @@ export declare const validateExpression: (code: string, options?: {
|
|
|
14
14
|
}) => string;
|
|
15
15
|
export declare const encodeDataSourceVariable: (id: string) => string;
|
|
16
16
|
export declare const decodeDataSourceVariable: (name: string) => string | undefined;
|
|
17
|
-
export declare const generateExpression: ({ expression, dataSources, scope, }: {
|
|
17
|
+
export declare const generateExpression: ({ expression, dataSources, usedDataSources, scope, }: {
|
|
18
18
|
expression: string;
|
|
19
19
|
dataSources: Map<string, {
|
|
20
20
|
value: {
|
|
@@ -49,6 +49,39 @@ export declare const generateExpression: ({ expression, dataSources, scope, }: {
|
|
|
49
49
|
resourceId: string;
|
|
50
50
|
scopeInstanceId?: string | undefined;
|
|
51
51
|
}>;
|
|
52
|
+
usedDataSources?: Map<string, {
|
|
53
|
+
value: {
|
|
54
|
+
value: number;
|
|
55
|
+
type: "number";
|
|
56
|
+
} | {
|
|
57
|
+
value: string;
|
|
58
|
+
type: "string";
|
|
59
|
+
} | {
|
|
60
|
+
value: boolean;
|
|
61
|
+
type: "boolean";
|
|
62
|
+
} | {
|
|
63
|
+
value: string[];
|
|
64
|
+
type: "string[]";
|
|
65
|
+
} | {
|
|
66
|
+
type: "json";
|
|
67
|
+
value?: unknown;
|
|
68
|
+
};
|
|
69
|
+
type: "variable";
|
|
70
|
+
name: string;
|
|
71
|
+
id: string;
|
|
72
|
+
scopeInstanceId?: string | undefined;
|
|
73
|
+
} | {
|
|
74
|
+
type: "parameter";
|
|
75
|
+
name: string;
|
|
76
|
+
id: string;
|
|
77
|
+
scopeInstanceId?: string | undefined;
|
|
78
|
+
} | {
|
|
79
|
+
type: "resource";
|
|
80
|
+
name: string;
|
|
81
|
+
id: string;
|
|
82
|
+
resourceId: string;
|
|
83
|
+
scopeInstanceId?: string | undefined;
|
|
84
|
+
}> | undefined;
|
|
52
85
|
scope: Scope;
|
|
53
86
|
}) => string;
|
|
54
87
|
export declare const executeExpression: (expression: undefined | string) => any;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Asset, type DataSources, type Page, type Scope } from "@webstudio-is/sdk";
|
|
2
2
|
export type PageMeta = {
|
|
3
3
|
title: string;
|
|
4
4
|
description?: string;
|
|
5
5
|
excludePageFromSearch?: boolean;
|
|
6
6
|
socialImageAssetId?: Asset["id"];
|
|
7
7
|
socialImageUrl?: string;
|
|
8
|
+
status?: number;
|
|
9
|
+
redirect?: string;
|
|
8
10
|
custom: Array<{
|
|
9
11
|
property: string;
|
|
10
12
|
content: string;
|
|
11
13
|
}>;
|
|
12
14
|
};
|
|
13
|
-
export declare const generatePageMeta: ({
|
|
14
|
-
|
|
15
|
+
export declare const generatePageMeta: ({ globalScope, page, dataSources, }: {
|
|
16
|
+
globalScope: Scope;
|
|
15
17
|
page: Page;
|
|
16
18
|
dataSources: Map<string, {
|
|
17
19
|
value: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.133.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"jsep": "^1.3.8",
|
|
34
34
|
"nanoid": "^5.0.1",
|
|
35
35
|
"title-case": "^4.1.0",
|
|
36
|
-
"@webstudio-is/
|
|
37
|
-
"@webstudio-is/fonts": "0.
|
|
38
|
-
"@webstudio-is/
|
|
39
|
-
"@webstudio-is/image": "0.
|
|
40
|
-
"@webstudio-is/
|
|
36
|
+
"@webstudio-is/css-engine": "0.133.0",
|
|
37
|
+
"@webstudio-is/fonts": "0.133.0",
|
|
38
|
+
"@webstudio-is/icons": "^0.133.0",
|
|
39
|
+
"@webstudio-is/image": "0.133.0",
|
|
40
|
+
"@webstudio-is/sdk": "0.133.0"
|
|
41
41
|
},
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|