@webstudio-is/react-sdk 0.135.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
@@ -773,6 +773,31 @@ var validateExpression = (code, options) => {
773
773
  transformIdentifier
774
774
  });
775
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
+ };
776
801
  var dataSourceVariablePrefix = "$ws$dataSource$";
777
802
  var encodeDataSourceVariable = (id) => {
778
803
  const encoded = id.replaceAll("-", "__DASH__");
@@ -1192,8 +1217,7 @@ var componentCategories = [
1192
1217
  "media",
1193
1218
  "forms",
1194
1219
  "radix",
1195
- "hidden",
1196
- "utilities"
1220
+ "hidden"
1197
1221
  ];
1198
1222
  var stateCategories = ["states", "component-states"];
1199
1223
  var ComponentState = z3.object({
@@ -1818,6 +1842,12 @@ var generatePageMeta = ({
1818
1842
  usedDataSources,
1819
1843
  scope: localScope
1820
1844
  });
1845
+ const languageExpression = generateExpression({
1846
+ expression: page.meta.language ?? "undefined",
1847
+ dataSources,
1848
+ usedDataSources,
1849
+ scope: localScope
1850
+ });
1821
1851
  const socialImageAssetIdExpression = JSON.stringify(
1822
1852
  page.meta.socialImageAssetId
1823
1853
  );
@@ -1912,6 +1942,8 @@ var generatePageMeta = ({
1912
1942
  generated += ` description: ${descriptionExpression},
1913
1943
  `;
1914
1944
  generated += ` excludePageFromSearch: ${excludePageFromSearchExpression},
1945
+ `;
1946
+ generated += ` language: ${languageExpression},
1915
1947
  `;
1916
1948
  generated += ` socialImageAssetId: ${socialImageAssetIdExpression},
1917
1949
  `;
@@ -1954,6 +1986,7 @@ export {
1954
1986
  executeExpression,
1955
1987
  generateCss,
1956
1988
  generateDataFromEmbedTemplate,
1989
+ generateExpression,
1957
1990
  generateJsxChildren,
1958
1991
  generateJsxElement,
1959
1992
  generatePageMeta,
@@ -1970,6 +2003,7 @@ export {
1970
2003
  getStyleRules,
1971
2004
  idAttribute,
1972
2005
  indexAttribute,
2006
+ isLiteralExpression,
1973
2007
  namespaceMeta,
1974
2008
  normalizeProps,
1975
2009
  portalComponent,
@@ -688,7 +688,7 @@ declare const WsComponentPropsMeta: z.ZodObject<{
688
688
  initialProps?: string[] | undefined;
689
689
  }>;
690
690
  export type WsComponentPropsMeta = z.infer<typeof WsComponentPropsMeta>;
691
- export declare const componentCategories: readonly ["general", "text", "data", "media", "forms", "radix", "hidden", "utilities"];
691
+ export declare const componentCategories: readonly ["general", "text", "data", "media", "forms", "radix", "hidden"];
692
692
  export declare const stateCategories: readonly ["states", "component-states"];
693
693
  export declare const ComponentState: z.ZodObject<{
694
694
  category: z.ZodOptional<z.ZodEnum<["states", "component-states"]>>;
@@ -706,7 +706,7 @@ export declare const ComponentState: z.ZodObject<{
706
706
  export type ComponentState = z.infer<typeof ComponentState>;
707
707
  export declare const defaultStates: ComponentState[];
708
708
  export declare const WsComponentMeta: z.ZodObject<{
709
- category: z.ZodOptional<z.ZodEnum<["general", "text", "data", "media", "forms", "radix", "hidden", "utilities"]>>;
709
+ category: z.ZodOptional<z.ZodEnum<["general", "text", "data", "media", "forms", "radix", "hidden"]>>;
710
710
  type: z.ZodEnum<["container", "control", "embed", "rich-text-child"]>;
711
711
  requiredAncestors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
712
712
  invalidAncestors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -2035,7 +2035,7 @@ export declare const WsComponentMeta: z.ZodObject<{
2035
2035
  }, "strip", z.ZodTypeAny, {
2036
2036
  type: "embed" | "control" | "container" | "rich-text-child";
2037
2037
  icon: string;
2038
- category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | "utilities" | undefined;
2038
+ category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2039
2039
  requiredAncestors?: string[] | undefined;
2040
2040
  invalidAncestors?: string[] | undefined;
2041
2041
  indexWithinAncestor?: string | undefined;
@@ -2488,7 +2488,7 @@ export declare const WsComponentMeta: z.ZodObject<{
2488
2488
  }, {
2489
2489
  type: "embed" | "control" | "container" | "rich-text-child";
2490
2490
  icon: string;
2491
- category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | "utilities" | undefined;
2491
+ category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2492
2492
  requiredAncestors?: string[] | undefined;
2493
2493
  invalidAncestors?: string[] | undefined;
2494
2494
  indexWithinAncestor?: string | undefined;
@@ -2250,7 +2250,7 @@ export declare const namespaceMeta: (meta: WsComponentMeta, namespace: string, c
2250
2250
  value: string;
2251
2251
  type: "expression";
2252
2252
  } | EmbedTemplateInstance)[] | undefined;
2253
- category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | "utilities" | undefined;
2253
+ category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2254
2254
  requiredAncestors?: string[] | undefined;
2255
2255
  invalidAncestors?: string[] | undefined;
2256
2256
  indexWithinAncestor?: string | undefined;
@@ -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, }: {
@@ -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 { validateExpression, encodeDataSourceVariable, decodeDataSourceVariable, executeExpression, } from "./expression";
12
+ export * from "./expression";
13
13
  export { getIndexesWithinAncestors } from "./instance-utils";
14
14
  export * from "./hook";
15
15
  export { generateUtilsExport } from "./generator";
@@ -3,6 +3,7 @@ export type PageMeta = {
3
3
  title: string;
4
4
  description?: string;
5
5
  excludePageFromSearch?: boolean;
6
+ language?: string;
6
7
  socialImageAssetId?: Asset["id"];
7
8
  socialImageUrl?: string;
8
9
  status?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.135.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/tsconfig": "1.0.7",
20
- "@webstudio-is/jest-config": "1.0.7"
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/fonts": "0.135.0",
37
- "@webstudio-is/css-engine": "0.135.0",
38
- "@webstudio-is/icons": "^0.135.0",
39
- "@webstudio-is/image": "0.135.0",
40
- "@webstudio-is/sdk": "0.135.0"
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
  ".": {