@webstudio-is/react-sdk 0.134.0 → 0.136.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
CHANGED
|
@@ -649,6 +649,7 @@ import { StyleValue } from "@webstudio-is/css-engine";
|
|
|
649
649
|
import jsep from "jsep";
|
|
650
650
|
import jsepAssignment from "@jsep-plugin/assignment";
|
|
651
651
|
import jsepObject from "@jsep-plugin/object";
|
|
652
|
+
jsep.literals["undefined"] = "undefined";
|
|
652
653
|
jsep.plugins.register(jsepAssignment);
|
|
653
654
|
jsep.plugins.register(jsepObject);
|
|
654
655
|
var generateCode = (node, failOnForbidden, options) => {
|
|
@@ -772,6 +773,31 @@ var validateExpression = (code, options) => {
|
|
|
772
773
|
transformIdentifier
|
|
773
774
|
});
|
|
774
775
|
};
|
|
776
|
+
var isLiteralNode = (node) => {
|
|
777
|
+
if (node.type === "Literal") {
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
if (node.type === "ArrayExpression") {
|
|
781
|
+
return node.elements.every(isLiteralNode);
|
|
782
|
+
}
|
|
783
|
+
if (node.type === "ObjectExpression") {
|
|
784
|
+
return node.properties.every((property) => {
|
|
785
|
+
const key = property.key;
|
|
786
|
+
const isIdentifierKey = key.type === "Identifier" && property.computed === false;
|
|
787
|
+
const isLiteralKey = key.type === "Literal";
|
|
788
|
+
return (isLiteralKey || isIdentifierKey) && isLiteralNode(property.value);
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
return false;
|
|
792
|
+
};
|
|
793
|
+
var isLiteralExpression = (expression) => {
|
|
794
|
+
try {
|
|
795
|
+
const node = jsep(expression);
|
|
796
|
+
return isLiteralNode(node);
|
|
797
|
+
} catch {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
775
801
|
var dataSourceVariablePrefix = "$ws$dataSource$";
|
|
776
802
|
var encodeDataSourceVariable = (id) => {
|
|
777
803
|
const encoded = id.replaceAll("-", "__DASH__");
|
|
@@ -1816,6 +1842,12 @@ var generatePageMeta = ({
|
|
|
1816
1842
|
usedDataSources,
|
|
1817
1843
|
scope: localScope
|
|
1818
1844
|
});
|
|
1845
|
+
const languageExpression = generateExpression({
|
|
1846
|
+
expression: page.meta.language ?? "undefined",
|
|
1847
|
+
dataSources,
|
|
1848
|
+
usedDataSources,
|
|
1849
|
+
scope: localScope
|
|
1850
|
+
});
|
|
1819
1851
|
const socialImageAssetIdExpression = JSON.stringify(
|
|
1820
1852
|
page.meta.socialImageAssetId
|
|
1821
1853
|
);
|
|
@@ -1910,6 +1942,8 @@ var generatePageMeta = ({
|
|
|
1910
1942
|
generated += ` description: ${descriptionExpression},
|
|
1911
1943
|
`;
|
|
1912
1944
|
generated += ` excludePageFromSearch: ${excludePageFromSearchExpression},
|
|
1945
|
+
`;
|
|
1946
|
+
generated += ` language: ${languageExpression},
|
|
1913
1947
|
`;
|
|
1914
1948
|
generated += ` socialImageAssetId: ${socialImageAssetIdExpression},
|
|
1915
1949
|
`;
|
|
@@ -1952,6 +1986,7 @@ export {
|
|
|
1952
1986
|
executeExpression,
|
|
1953
1987
|
generateCss,
|
|
1954
1988
|
generateDataFromEmbedTemplate,
|
|
1989
|
+
generateExpression,
|
|
1955
1990
|
generateJsxChildren,
|
|
1956
1991
|
generateJsxElement,
|
|
1957
1992
|
generatePageMeta,
|
|
@@ -1968,6 +2003,7 @@ export {
|
|
|
1968
2003
|
getStyleRules,
|
|
1969
2004
|
idAttribute,
|
|
1970
2005
|
indexAttribute,
|
|
2006
|
+
isLiteralExpression,
|
|
1971
2007
|
namespaceMeta,
|
|
1972
2008
|
normalizeProps,
|
|
1973
2009
|
portalComponent,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { componentAttribute, idAttribute } from "../props";
|
|
3
|
-
export type AnyComponent = React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> &
|
|
3
|
+
export type AnyComponent = React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & WebstudioComponentSystemProps & React.RefAttributes<HTMLElement>>;
|
|
4
|
+
export type Components = Map<string, AnyComponent>;
|
|
5
|
+
export type WebstudioComponentSystemProps = {
|
|
4
6
|
[componentAttribute]: string;
|
|
5
7
|
[idAttribute]: string;
|
|
6
|
-
}
|
|
7
|
-
export type Components = Map<string, AnyComponent>;
|
|
8
|
+
};
|
|
@@ -12,6 +12,12 @@ export declare const validateExpression: (code: string, options?: {
|
|
|
12
12
|
optional?: boolean;
|
|
13
13
|
transformIdentifier?: TransformIdentifier;
|
|
14
14
|
}) => string;
|
|
15
|
+
/**
|
|
16
|
+
* check whether provided expression is a literal value
|
|
17
|
+
* like "", 0 or { param: "value" }
|
|
18
|
+
* which does not depends on any variable
|
|
19
|
+
*/
|
|
20
|
+
export declare const isLiteralExpression: (expression: string) => boolean;
|
|
15
21
|
export declare const encodeDataSourceVariable: (id: string) => string;
|
|
16
22
|
export declare const decodeDataSourceVariable: (name: string) => string | undefined;
|
|
17
23
|
export declare const generateExpression: ({ expression, dataSources, usedDataSources, scope, }: {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { type WsComponentPropsMeta, type ComponentState, type PresetStyle, WsCom
|
|
|
9
9
|
export * from "./embed-template";
|
|
10
10
|
export * from "./props";
|
|
11
11
|
export * from "./context";
|
|
12
|
-
export
|
|
12
|
+
export * from "./expression";
|
|
13
13
|
export { getIndexesWithinAncestors } from "./instance-utils";
|
|
14
14
|
export * from "./hook";
|
|
15
15
|
export { generateUtilsExport } from "./generator";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.136.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"type-fest": "^4.3.1",
|
|
17
17
|
"typescript": "5.2.2",
|
|
18
18
|
"zod": "^3.21.4",
|
|
19
|
-
"@webstudio-is/
|
|
20
|
-
"@webstudio-is/
|
|
19
|
+
"@webstudio-is/jest-config": "1.0.7",
|
|
20
|
+
"@webstudio-is/tsconfig": "1.0.7"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@remix-run/react": "^1.19.1",
|
|
@@ -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/
|
|
38
|
-
"@webstudio-is/
|
|
39
|
-
"@webstudio-is/
|
|
40
|
-
"@webstudio-is/
|
|
36
|
+
"@webstudio-is/image": "0.136.0",
|
|
37
|
+
"@webstudio-is/icons": "^0.136.0",
|
|
38
|
+
"@webstudio-is/fonts": "0.136.0",
|
|
39
|
+
"@webstudio-is/sdk": "0.136.0",
|
|
40
|
+
"@webstudio-is/css-engine": "0.136.0"
|
|
41
41
|
},
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|