@webstudio-is/sdk 0.191.4 → 0.192.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.
Files changed (40) hide show
  1. package/lib/__generated__/normalize.css.js +505 -0
  2. package/lib/index.js +1300 -0
  3. package/lib/runtime.js +101 -0
  4. package/lib/types/__generated__/normalize.css.d.ts +57 -0
  5. package/lib/types/expression.d.ts +53 -0
  6. package/lib/types/expression.test.d.ts +1 -0
  7. package/lib/types/form-fields.d.ts +8 -0
  8. package/lib/types/index.d.ts +19 -0
  9. package/lib/types/instances-utils.d.ts +5 -0
  10. package/lib/types/instances-utils.test.d.ts +1 -0
  11. package/lib/types/jsx.d.ts +151 -0
  12. package/lib/types/jsx.test.d.ts +1 -0
  13. package/lib/types/page-meta-generator.d.ts +24 -0
  14. package/lib/types/page-meta-generator.test.d.ts +1 -0
  15. package/lib/types/page-utils.d.ts +24 -0
  16. package/lib/types/page-utils.test.d.ts +1 -0
  17. package/lib/types/resource-loader.d.ts +30 -0
  18. package/lib/types/resource-loader.test.d.ts +1 -0
  19. package/lib/types/resources-generator.d.ts +22 -0
  20. package/lib/types/resources-generator.test.d.ts +1 -0
  21. package/lib/types/runtime.d.ts +3 -0
  22. package/lib/types/schema/assets.d.ts +527 -0
  23. package/lib/types/schema/breakpoints.d.ts +56 -0
  24. package/lib/types/schema/data-sources.d.ts +303 -0
  25. package/lib/types/schema/deployment.d.ts +41 -0
  26. package/lib/types/schema/instances.d.ts +417 -0
  27. package/lib/types/schema/pages.d.ts +675 -0
  28. package/lib/types/schema/props.d.ts +549 -0
  29. package/lib/types/schema/resources.d.ts +121 -0
  30. package/lib/types/schema/style-source-selections.d.ts +23 -0
  31. package/lib/types/schema/style-sources.d.ts +62 -0
  32. package/lib/types/schema/styles.d.ts +2629 -0
  33. package/lib/types/schema/webstudio.d.ts +2374 -0
  34. package/lib/types/scope.d.ts +16 -0
  35. package/lib/types/scope.test.d.ts +1 -0
  36. package/lib/types/testing.d.ts +1 -0
  37. package/lib/types/to-string.d.ts +2 -0
  38. package/lib/types/url-pattern.d.ts +2 -0
  39. package/lib/types/url-pattern.test.d.ts +1 -0
  40. package/package.json +5 -5
package/lib/runtime.js ADDED
@@ -0,0 +1,101 @@
1
+ // src/resource-loader.ts
2
+ var LOCAL_RESOURCE_PREFIX = "$resources";
3
+ var isLocalResource = (pathname, resourceName) => {
4
+ const segments = pathname.split("/").filter(Boolean);
5
+ if (resourceName === void 0) {
6
+ return segments[0] === LOCAL_RESOURCE_PREFIX;
7
+ }
8
+ return segments.join("/") === `${LOCAL_RESOURCE_PREFIX}/${resourceName}`;
9
+ };
10
+ var sitemapResourceUrl = `/${LOCAL_RESOURCE_PREFIX}/sitemap.xml`;
11
+ var loadResource = async (customFetch, resourceRequest) => {
12
+ const { url, method, headers, body } = resourceRequest;
13
+ const requestHeaders = new Headers(
14
+ headers.map(({ name, value }) => [name, value])
15
+ );
16
+ const requestInit = {
17
+ method,
18
+ headers: requestHeaders
19
+ };
20
+ if (method !== "get" && body !== void 0) {
21
+ if (typeof body === "string") {
22
+ requestInit.body = body;
23
+ }
24
+ if (typeof body === "object") {
25
+ requestInit.body = JSON.stringify(body);
26
+ }
27
+ }
28
+ try {
29
+ const response = await customFetch(url.trim(), requestInit);
30
+ let data = await response.text();
31
+ try {
32
+ data = JSON.parse(data);
33
+ } catch {
34
+ }
35
+ if (!response.ok) {
36
+ console.error(
37
+ `Failed to load resource: ${url} - ${response.status}: ${JSON.stringify(data).slice(0, 300)}`
38
+ );
39
+ }
40
+ return {
41
+ ok: response.ok,
42
+ data,
43
+ status: response.status,
44
+ statusText: response.statusText
45
+ };
46
+ } catch (error) {
47
+ console.error(error);
48
+ const message = error.message;
49
+ return {
50
+ ok: false,
51
+ data: void 0,
52
+ status: 500,
53
+ statusText: message
54
+ };
55
+ }
56
+ };
57
+ var loadResources = async (customFetch, requests) => {
58
+ return Object.fromEntries(
59
+ await Promise.all(
60
+ Array.from(
61
+ requests,
62
+ async ([name, request]) => [name, await loadResource(customFetch, request)]
63
+ )
64
+ )
65
+ );
66
+ };
67
+
68
+ // src/to-string.ts
69
+ var createJsonStringifyProxy = (target) => {
70
+ return new Proxy(target, {
71
+ get(target2, prop, receiver) {
72
+ if (prop === "toString") {
73
+ return function() {
74
+ return JSON.stringify(target2);
75
+ };
76
+ }
77
+ const value = Reflect.get(target2, prop, receiver);
78
+ if (typeof value === "object" && value !== null) {
79
+ return createJsonStringifyProxy(value);
80
+ }
81
+ return value;
82
+ }
83
+ });
84
+ };
85
+ var isPlainObject = (value) => {
86
+ return Object.prototype.toString.call(value) === "[object Object]" && (Object.getPrototypeOf(value) === null || Object.getPrototypeOf(value) === Object.prototype);
87
+ };
88
+
89
+ // src/form-fields.ts
90
+ var formIdFieldName = `ws--form-id`;
91
+ var formBotFieldName = `ws--form-bot`;
92
+ export {
93
+ createJsonStringifyProxy,
94
+ formBotFieldName,
95
+ formIdFieldName,
96
+ isLocalResource,
97
+ isPlainObject,
98
+ loadResource,
99
+ loadResources,
100
+ sitemapResourceUrl
101
+ };
@@ -0,0 +1,57 @@
1
+ import type { StyleProperty, StyleValue } from "@webstudio-is/css-engine";
2
+ type StyleDecl = {
3
+ state?: string;
4
+ property: StyleProperty;
5
+ value: StyleValue;
6
+ };
7
+ export declare const div: StyleDecl[];
8
+ export declare const address: StyleDecl[];
9
+ export declare const article: StyleDecl[];
10
+ export declare const aside: StyleDecl[];
11
+ export declare const figure: StyleDecl[];
12
+ export declare const footer: StyleDecl[];
13
+ export declare const header: StyleDecl[];
14
+ export declare const main: StyleDecl[];
15
+ export declare const nav: StyleDecl[];
16
+ export declare const section: StyleDecl[];
17
+ export declare const form: StyleDecl[];
18
+ export declare const label: StyleDecl[];
19
+ export declare const time: StyleDecl[];
20
+ export declare const h1: StyleDecl[];
21
+ export declare const h2: StyleDecl[];
22
+ export declare const h3: StyleDecl[];
23
+ export declare const h4: StyleDecl[];
24
+ export declare const h5: StyleDecl[];
25
+ export declare const h6: StyleDecl[];
26
+ export declare const i: StyleDecl[];
27
+ export declare const img: StyleDecl[];
28
+ export declare const a: StyleDecl[];
29
+ export declare const li: StyleDecl[];
30
+ export declare const ul: StyleDecl[];
31
+ export declare const ol: StyleDecl[];
32
+ export declare const p: StyleDecl[];
33
+ export declare const span: StyleDecl[];
34
+ export declare const html: StyleDecl[];
35
+ export declare const body: StyleDecl[];
36
+ export declare const hr: StyleDecl[];
37
+ export declare const b: StyleDecl[];
38
+ export declare const strong: StyleDecl[];
39
+ export declare const code: StyleDecl[];
40
+ export declare const kbd: StyleDecl[];
41
+ export declare const samp: StyleDecl[];
42
+ export declare const pre: StyleDecl[];
43
+ export declare const small: StyleDecl[];
44
+ export declare const sub: StyleDecl[];
45
+ export declare const sup: StyleDecl[];
46
+ export declare const table: StyleDecl[];
47
+ export declare const input: StyleDecl[];
48
+ export declare const textarea: StyleDecl[];
49
+ export declare const optgroup: StyleDecl[];
50
+ export declare const radio: StyleDecl[];
51
+ export declare const checkbox: StyleDecl[];
52
+ export declare const button: StyleDecl[];
53
+ export declare const select: StyleDecl[];
54
+ export declare const legend: StyleDecl[];
55
+ export declare const progress: StyleDecl[];
56
+ export declare const summary: StyleDecl[];
57
+ export {};
@@ -0,0 +1,53 @@
1
+ import { type Identifier } from "acorn";
2
+ import type { DataSources } from "./schema/data-sources";
3
+ import type { Scope } from "./scope";
4
+ export type Diagnostic = {
5
+ from: number;
6
+ to: number;
7
+ severity: "error" | "hint" | "info" | "warning";
8
+ message: string;
9
+ };
10
+ export declare const lintExpression: ({ expression, availableVariables, allowAssignment, }: {
11
+ expression: string;
12
+ availableVariables?: Set<Identifier["name"]>;
13
+ allowAssignment?: boolean;
14
+ }) => Diagnostic[];
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;
21
+ export declare const getExpressionIdentifiers: (expression: string) => Set<string>;
22
+ /**
23
+ * transpile expression into executable one
24
+ *
25
+ * add optional chaining operator to every member expression
26
+ * to access any field without runtime errors
27
+ *
28
+ * replace variable names if necessary
29
+ */
30
+ export declare const transpileExpression: ({ expression, executable, replaceVariable, }: {
31
+ expression: string;
32
+ executable?: boolean;
33
+ replaceVariable?: (identifier: string, assignee: boolean) => string | undefined | void;
34
+ }) => string;
35
+ /**
36
+ * parse object expression into key value map
37
+ * where each value is expression
38
+ */
39
+ export declare const parseObjectExpression: (expression: string) => Map<string, string>;
40
+ /**
41
+ * generate key value map into object expression
42
+ * after updating individual value expressions
43
+ */
44
+ export declare const generateObjectExpression: (map: Map<string, string>) => string;
45
+ export declare const encodeDataSourceVariable: (id: string) => string;
46
+ export declare const decodeDataSourceVariable: (name: string) => string | undefined;
47
+ export declare const generateExpression: ({ expression, dataSources, usedDataSources, scope, }: {
48
+ expression: string;
49
+ dataSources: DataSources;
50
+ usedDataSources: DataSources;
51
+ scope: Scope;
52
+ }) => string;
53
+ export declare const executeExpression: (expression: undefined | string) => any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Used to identify form inside server handler
3
+ */
4
+ export declare const formIdFieldName = "ws--form-id";
5
+ /**
6
+ * Used for simlpe protection against non js bots
7
+ */
8
+ export declare const formBotFieldName = "ws--form-bot";
@@ -0,0 +1,19 @@
1
+ export * from "./schema/assets";
2
+ export * from "./schema/pages";
3
+ export * from "./schema/instances";
4
+ export * from "./schema/data-sources";
5
+ export * from "./schema/resources";
6
+ export * from "./schema/props";
7
+ export * from "./schema/breakpoints";
8
+ export * from "./schema/style-sources";
9
+ export * from "./schema/style-source-selections";
10
+ export * from "./schema/styles";
11
+ export * from "./schema/deployment";
12
+ export * from "./schema/webstudio";
13
+ export * from "./instances-utils";
14
+ export * from "./page-utils";
15
+ export * from "./scope";
16
+ export * from "./expression";
17
+ export * from "./resources-generator";
18
+ export * from "./page-meta-generator";
19
+ export * from "./url-pattern";
@@ -0,0 +1,5 @@
1
+ import type { Instance, Instances } from "./schema/instances";
2
+ export declare const ROOT_INSTANCE_ID = ":root";
3
+ export declare const findTreeInstanceIds: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
4
+ export declare const findTreeInstanceIdsExcludingSlotDescendants: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
5
+ export declare const parseComponentName: (componentName: string) => readonly [string | undefined, string];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,151 @@
1
+ import type { ReactNode } from "react";
2
+ export declare class ExpressionValue {
3
+ value: string;
4
+ constructor(expression: string);
5
+ }
6
+ export declare class ParameterValue {
7
+ value: string;
8
+ constructor(dataSourceID: string);
9
+ }
10
+ export declare class ResourceValue {
11
+ value: string;
12
+ constructor(resourceId: string);
13
+ }
14
+ export declare class ActionValue {
15
+ value: {
16
+ type: "execute";
17
+ args: string[];
18
+ code: string;
19
+ };
20
+ constructor(args: string[], code: string);
21
+ }
22
+ export declare class AssetValue {
23
+ value: string;
24
+ constructor(assetId: string);
25
+ }
26
+ export declare class PageValue {
27
+ value: string | {
28
+ pageId: string;
29
+ instanceId: string;
30
+ };
31
+ constructor(pageId: string, instanceId?: string);
32
+ }
33
+ export declare const renderJsx: (root: JSX.Element) => {
34
+ instances: Map<string, {
35
+ type: "instance";
36
+ id: string;
37
+ children: ({
38
+ value: string;
39
+ type: "text";
40
+ placeholder?: boolean | undefined;
41
+ } | {
42
+ value: string;
43
+ type: "id";
44
+ } | {
45
+ value: string;
46
+ type: "expression";
47
+ })[];
48
+ component: string;
49
+ label?: string | undefined;
50
+ }>;
51
+ props: Map<string, {
52
+ value: number;
53
+ type: "number";
54
+ id: string;
55
+ name: string;
56
+ instanceId: string;
57
+ required?: boolean | undefined;
58
+ } | {
59
+ value: string;
60
+ type: "string";
61
+ id: string;
62
+ name: string;
63
+ instanceId: string;
64
+ required?: boolean | undefined;
65
+ } | {
66
+ value: boolean;
67
+ type: "boolean";
68
+ id: string;
69
+ name: string;
70
+ instanceId: string;
71
+ required?: boolean | undefined;
72
+ } | {
73
+ type: "json";
74
+ id: string;
75
+ name: string;
76
+ instanceId: string;
77
+ value?: unknown;
78
+ required?: boolean | undefined;
79
+ } | {
80
+ value: string;
81
+ type: "asset";
82
+ id: string;
83
+ name: string;
84
+ instanceId: string;
85
+ required?: boolean | undefined;
86
+ } | {
87
+ value: (string | {
88
+ instanceId: string;
89
+ pageId: string;
90
+ }) & (string | {
91
+ instanceId: string;
92
+ pageId: string;
93
+ } | undefined);
94
+ type: "page";
95
+ id: string;
96
+ name: string;
97
+ instanceId: string;
98
+ required?: boolean | undefined;
99
+ } | {
100
+ value: string[];
101
+ type: "string[]";
102
+ id: string;
103
+ name: string;
104
+ instanceId: string;
105
+ required?: boolean | undefined;
106
+ } | {
107
+ value: string;
108
+ type: "parameter";
109
+ id: string;
110
+ name: string;
111
+ instanceId: string;
112
+ required?: boolean | undefined;
113
+ } | {
114
+ value: string;
115
+ type: "resource";
116
+ id: string;
117
+ name: string;
118
+ instanceId: string;
119
+ required?: boolean | undefined;
120
+ } | {
121
+ value: string;
122
+ type: "expression";
123
+ id: string;
124
+ name: string;
125
+ instanceId: string;
126
+ required?: boolean | undefined;
127
+ } | {
128
+ value: {
129
+ code: string;
130
+ type: "execute";
131
+ args: string[];
132
+ }[];
133
+ type: "action";
134
+ id: string;
135
+ name: string;
136
+ instanceId: string;
137
+ required?: boolean | undefined;
138
+ }>;
139
+ };
140
+ type ComponentProps = Record<string, unknown> & Record<`${string}:expression`, string> & {
141
+ "ws:id"?: string;
142
+ "ws:label"?: string;
143
+ children?: ReactNode | ExpressionValue;
144
+ };
145
+ type Component = {
146
+ displayName: string;
147
+ } & ((props: ComponentProps) => ReactNode);
148
+ export declare const createProxy: (prefix: string) => Record<string, Component>;
149
+ export declare const $: Record<string, Component>;
150
+ export declare const ws: Record<string, Component>;
151
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { Asset, Assets } from "./schema/assets";
2
+ import type { DataSources } from "./schema/data-sources";
3
+ import type { Page } from "./schema/pages";
4
+ import { type Scope } from "./scope";
5
+ export type PageMeta = {
6
+ title: string;
7
+ description?: string;
8
+ excludePageFromSearch?: boolean;
9
+ language?: string;
10
+ socialImageAssetName?: Asset["name"];
11
+ socialImageUrl?: string;
12
+ status?: number;
13
+ redirect?: string;
14
+ custom: Array<{
15
+ property: string;
16
+ content: string;
17
+ }>;
18
+ };
19
+ export declare const generatePageMeta: ({ globalScope, page, dataSources, assets, }: {
20
+ globalScope: Scope;
21
+ page: Page;
22
+ dataSources: DataSources;
23
+ assets: Assets;
24
+ }) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { Folder, Page, Pages } from "./schema/pages";
2
+ export declare const ROOT_FOLDER_ID = "root";
3
+ /**
4
+ * Returns true if folder is the root folder.
5
+ */
6
+ export declare const isRootFolder: ({ id }: {
7
+ id: Folder["id"];
8
+ }) => boolean;
9
+ /**
10
+ * Find a page by id or path.
11
+ */
12
+ export declare const findPageByIdOrPath: (idOrPath: string, pages: Pages) => Page | undefined;
13
+ /**
14
+ * Find a folder that has has that id in the children.
15
+ */
16
+ export declare const findParentFolderByChildId: (id: Folder["id"] | Page["id"], folders: Array<Folder>) => Folder | undefined;
17
+ /**
18
+ * Get a path from all folder slugs from root to the current folder or page.
19
+ */
20
+ export declare const getPagePath: (id: Folder["id"] | Page["id"], pages: Pages) => string;
21
+ export declare const getStaticSiteMapXml: (pages: Pages, updatedAt: string) => {
22
+ path: string;
23
+ lastModified: string;
24
+ }[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { ResourceRequest } from "./schema/resources";
2
+ /**
3
+ * Prevents fetch cycles by prefixing local resources.
4
+ */
5
+ export declare const isLocalResource: (pathname: string, resourceName?: string) => boolean;
6
+ export declare const sitemapResourceUrl = "/$resources/sitemap.xml";
7
+ export declare const loadResource: (customFetch: typeof fetch, resourceRequest: ResourceRequest) => Promise<{
8
+ ok: boolean;
9
+ data: string;
10
+ status: number;
11
+ statusText: string;
12
+ } | {
13
+ ok: boolean;
14
+ data: undefined;
15
+ status: number;
16
+ statusText: string;
17
+ }>;
18
+ export declare const loadResources: (customFetch: typeof fetch, requests: Map<string, ResourceRequest>) => Promise<{
19
+ [k: string]: {
20
+ ok: boolean;
21
+ data: string;
22
+ status: number;
23
+ statusText: string;
24
+ } | {
25
+ ok: boolean;
26
+ data: undefined;
27
+ status: number;
28
+ statusText: string;
29
+ };
30
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { DataSources } from "./schema/data-sources";
2
+ import type { Page } from "./schema/pages";
3
+ import type { Resources } from "./schema/resources";
4
+ import type { Props } from "./schema/props";
5
+ import type { Instances } from "./schema/instances";
6
+ import type { Scope } from "./scope";
7
+ export declare const generateResources: ({ scope, page, dataSources, props, resources, }: {
8
+ scope: Scope;
9
+ page: Page;
10
+ dataSources: DataSources;
11
+ props: Props;
12
+ resources: Resources;
13
+ }) => string;
14
+ /**
15
+ * migrate webhook forms to resource action
16
+ * @todo move to client migrations eventually
17
+ */
18
+ export declare const replaceFormActionsWithResources: ({ props, instances, resources, }: {
19
+ props: Props;
20
+ instances: Instances;
21
+ resources: Resources;
22
+ }) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from "./resource-loader";
2
+ export * from "./to-string";
3
+ export * from "./form-fields";