@webstudio-is/react-sdk 0.91.0 → 0.92.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/app/index.js +1 -0
- package/lib/app/root.js +2 -4
- package/lib/component-renderer.js +3 -5
- package/lib/components/component-meta.js +6 -11
- package/lib/components/components-utils.js +1 -0
- package/lib/context.js +2 -4
- package/lib/css/css.js +4 -9
- package/lib/css/global-rules.js +3 -5
- package/lib/css/index.js +1 -0
- package/lib/css/normalize-type-check.js +1 -0
- package/lib/css/normalize.js +48 -96
- package/lib/css/presets.js +3 -6
- package/lib/css/style-rules.js +3 -6
- package/{src/css/style-rules.test.ts → lib/css/style-rules.test.js} +23 -28
- package/lib/embed-template.js +7 -22
- package/{src/embed-template.test.ts → lib/embed-template.test.js} +165 -176
- package/lib/expression.js +11 -22
- package/{src/expression.test.ts → lib/expression.test.js} +55 -83
- package/lib/generator.js +2 -4
- package/{src/generator.test.ts → lib/generator.test.js} +28 -31
- package/lib/hook.js +2 -4
- package/{src/hook.test.ts → lib/hook.test.js} +4 -4
- package/lib/index.js +9 -31
- package/lib/instance-utils.js +2 -4
- package/{src/instance-utils.test.ts → lib/instance-utils.test.js} +19 -43
- package/lib/prop-meta.js +150 -0
- package/lib/props.js +8 -16
- package/{src/props.test.ts → lib/props.test.js} +39 -68
- package/lib/pubsub/create.js +2 -4
- package/lib/pubsub/index.js +1 -0
- package/lib/pubsub/raf-queue.js +2 -4
- package/lib/tree/create-elements-tree.js +2 -4
- package/lib/tree/index.js +1 -0
- package/lib/tree/root.js +2 -5
- package/lib/tree/webstudio-component.js +10 -20
- package/lib/types/component-renderer.d.ts +1 -1
- package/lib/types/components/component-meta.d.ts +526 -526
- package/lib/types/context.d.ts +1 -2
- package/lib/types/css/css.d.ts +22 -23
- package/lib/types/css/global-rules.d.ts +19 -19
- package/lib/types/css/normalize.d.ts +2444 -2444
- package/lib/types/css/style-rules.d.ts +2 -2
- package/lib/types/embed-template.d.ts +648 -648
- package/lib/types/generator.d.ts +1 -1
- package/lib/types/hook.d.ts +3 -3
- package/lib/types/index.d.ts +1 -0
- package/lib/types/instance-utils.d.ts +3 -3
- package/lib/types/prop-meta.d.ts +396 -0
- package/lib/types/props.d.ts +52 -53
- package/lib/types/tree/create-elements-tree.d.ts +3 -4
- package/lib/types/tree/root.d.ts +8 -8
- package/lib/types/tree/webstudio-component.d.ts +1 -1
- package/package.json +14 -22
- package/lib/cjs/app/index.js +0 -18
- package/lib/cjs/app/root.js +0 -40
- package/lib/cjs/component-renderer.js +0 -143
- package/lib/cjs/components/component-meta.js +0 -87
- package/lib/cjs/components/components-utils.js +0 -17
- package/lib/cjs/context.js +0 -43
- package/lib/cjs/css/css.js +0 -84
- package/lib/cjs/css/global-rules.js +0 -37
- package/lib/cjs/css/index.js +0 -20
- package/lib/cjs/css/normalize-type-check.js +0 -26
- package/lib/cjs/css/normalize.js +0 -349
- package/lib/cjs/css/presets.js +0 -48
- package/lib/cjs/css/style-rules.js +0 -86
- package/lib/cjs/embed-template.js +0 -368
- package/lib/cjs/expression.js +0 -371
- package/lib/cjs/generator.js +0 -128
- package/lib/cjs/hook.js +0 -34
- package/lib/cjs/index.js +0 -59
- package/lib/cjs/instance-utils.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/props.js +0 -204
- package/lib/cjs/pubsub/create.js +0 -78
- package/lib/cjs/pubsub/index.js +0 -18
- package/lib/cjs/pubsub/raf-queue.js +0 -42
- package/lib/cjs/tree/create-elements-tree.js +0 -152
- package/lib/cjs/tree/index.js +0 -20
- package/lib/cjs/tree/root.js +0 -100
- package/lib/cjs/tree/webstudio-component.js +0 -91
- package/src/app/index.ts +0 -1
- package/src/app/root.tsx +0 -25
- package/src/component-renderer.tsx +0 -146
- package/src/components/component-meta.ts +0 -86
- package/src/components/components-utils.ts +0 -13
- package/src/context.tsx +0 -73
- package/src/css/css.ts +0 -88
- package/src/css/global-rules.ts +0 -26
- package/src/css/index.ts +0 -3
- package/src/css/normalize-type-check.ts +0 -13
- package/src/css/normalize.ts +0 -507
- package/src/css/presets.ts +0 -27
- package/src/css/style-rules.ts +0 -101
- package/src/embed-template.ts +0 -438
- package/src/expression.ts +0 -401
- package/src/generator.ts +0 -147
- package/src/hook.ts +0 -52
- package/src/index.ts +0 -39
- package/src/instance-utils.ts +0 -65
- package/src/props.ts +0 -231
- package/src/pubsub/create.ts +0 -77
- package/src/pubsub/index.ts +0 -1
- package/src/pubsub/raf-queue.ts +0 -25
- package/src/tree/create-elements-tree.tsx +0 -186
- package/src/tree/index.ts +0 -3
- package/src/tree/root.ts +0 -131
- package/src/tree/webstudio-component.tsx +0 -97
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var webstudio_component_exports = {};
|
|
20
|
-
__export(webstudio_component_exports, {
|
|
21
|
-
WebstudioComponent: () => WebstudioComponent,
|
|
22
|
-
collapsedAttribute: () => collapsedAttribute,
|
|
23
|
-
componentAttribute: () => componentAttribute,
|
|
24
|
-
idAttribute: () => idAttribute,
|
|
25
|
-
indexAttribute: () => indexAttribute,
|
|
26
|
-
renderWebstudioComponentChildren: () => renderWebstudioComponentChildren,
|
|
27
|
-
selectorIdAttribute: () => selectorIdAttribute,
|
|
28
|
-
showAttribute: () => showAttribute,
|
|
29
|
-
splitPropsWithWebstudioAttributes: () => splitPropsWithWebstudioAttributes
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(webstudio_component_exports);
|
|
32
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
var import_react = require("react");
|
|
34
|
-
var import_props = require("../props");
|
|
35
|
-
const renderText = (text) => {
|
|
36
|
-
const lines = text.split("\n");
|
|
37
|
-
return lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
|
|
38
|
-
line,
|
|
39
|
-
index < lines.length - 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}) : null
|
|
40
|
-
] }, index));
|
|
41
|
-
};
|
|
42
|
-
const renderWebstudioComponentChildren = (children) => {
|
|
43
|
-
if (children === void 0 || children.length === 0) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
return children.map((child) => {
|
|
47
|
-
return typeof child === "string" ? renderText(child) : child;
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const WebstudioComponent = (0, import_react.forwardRef)(({ instance, instanceSelector, children, components, ...rest }, ref) => {
|
|
51
|
-
const { [showAttribute]: show = true, ...instanceProps } = (0, import_props.useInstanceProps)(
|
|
52
|
-
instance.id
|
|
53
|
-
);
|
|
54
|
-
const props = {
|
|
55
|
-
...instanceProps,
|
|
56
|
-
...rest,
|
|
57
|
-
[idAttribute]: instance.id,
|
|
58
|
-
[componentAttribute]: instance.component
|
|
59
|
-
};
|
|
60
|
-
if (show === false) {
|
|
61
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
62
|
-
}
|
|
63
|
-
const Component = components.get(instance.component);
|
|
64
|
-
if (Component === void 0) {
|
|
65
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
66
|
-
}
|
|
67
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props, ref, children: renderWebstudioComponentChildren(children) });
|
|
68
|
-
});
|
|
69
|
-
const idAttribute = "data-ws-id";
|
|
70
|
-
const selectorIdAttribute = "data-ws-selector";
|
|
71
|
-
const componentAttribute = "data-ws-component";
|
|
72
|
-
const showAttribute = "data-ws-show";
|
|
73
|
-
const indexAttribute = "data-ws-index";
|
|
74
|
-
const collapsedAttribute = "data-ws-collapsed";
|
|
75
|
-
const splitPropsWithWebstudioAttributes = ({
|
|
76
|
-
[idAttribute]: idAttributeValue,
|
|
77
|
-
[componentAttribute]: componentAttributeValue,
|
|
78
|
-
[showAttribute]: showAttributeValue,
|
|
79
|
-
[collapsedAttribute]: collapsedAttributeValue,
|
|
80
|
-
[selectorIdAttribute]: parentIdAttributeValue,
|
|
81
|
-
...props
|
|
82
|
-
}) => [
|
|
83
|
-
{
|
|
84
|
-
[idAttribute]: idAttributeValue,
|
|
85
|
-
[componentAttribute]: componentAttributeValue,
|
|
86
|
-
[showAttribute]: showAttributeValue,
|
|
87
|
-
[collapsedAttribute]: collapsedAttributeValue,
|
|
88
|
-
[selectorIdAttribute]: parentIdAttributeValue
|
|
89
|
-
},
|
|
90
|
-
props
|
|
91
|
-
];
|
package/src/app/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./root";
|
package/src/app/root.tsx
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Links, Meta, Outlet as DefaultOutlet } from "@remix-run/react";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* We are using Outlet prop from index layout when user renders site from a subdomain.
|
|
5
|
-
*/
|
|
6
|
-
export const Root = ({
|
|
7
|
-
Outlet = DefaultOutlet,
|
|
8
|
-
}: {
|
|
9
|
-
Outlet: typeof DefaultOutlet;
|
|
10
|
-
}) => {
|
|
11
|
-
return (
|
|
12
|
-
<html lang="en">
|
|
13
|
-
<head>
|
|
14
|
-
<meta charSet="utf-8" />
|
|
15
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
16
|
-
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
|
17
|
-
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
|
|
18
|
-
<Meta />
|
|
19
|
-
<Links />
|
|
20
|
-
</head>
|
|
21
|
-
|
|
22
|
-
<Outlet />
|
|
23
|
-
</html>
|
|
24
|
-
);
|
|
25
|
-
};
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { ExoticComponent } from "react";
|
|
2
|
-
import type { Instance } from "@webstudio-is/project-build";
|
|
3
|
-
import { getStyleDeclKey } from "@webstudio-is/project-build";
|
|
4
|
-
import type { WsComponentMeta } from "./components/component-meta";
|
|
5
|
-
import {
|
|
6
|
-
WsEmbedTemplate,
|
|
7
|
-
generateDataFromEmbedTemplate,
|
|
8
|
-
} from "./embed-template";
|
|
9
|
-
import { generateCssText } from "./css";
|
|
10
|
-
import { InstanceRoot, WebstudioComponent } from "./tree";
|
|
11
|
-
import {
|
|
12
|
-
decodeVariablesMap,
|
|
13
|
-
encodeDataSourceVariable,
|
|
14
|
-
encodeVariablesMap,
|
|
15
|
-
executeComputingExpressions,
|
|
16
|
-
executeEffectfulExpression,
|
|
17
|
-
} from "./expression";
|
|
18
|
-
import { getIndexesWithinAncestors } from "./instance-utils";
|
|
19
|
-
|
|
20
|
-
export const renderComponentTemplate = ({
|
|
21
|
-
name,
|
|
22
|
-
metas: metasRecord,
|
|
23
|
-
components,
|
|
24
|
-
props,
|
|
25
|
-
}: {
|
|
26
|
-
name: Instance["component"];
|
|
27
|
-
metas: Record<string, WsComponentMeta>;
|
|
28
|
-
props?: Record<string, unknown>;
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
components: Record<string, ExoticComponent<any>>;
|
|
31
|
-
}) => {
|
|
32
|
-
const metas = new Map(Object.entries(metasRecord));
|
|
33
|
-
|
|
34
|
-
const template: WsEmbedTemplate = metas.get(name)?.template ?? [
|
|
35
|
-
{
|
|
36
|
-
type: "instance",
|
|
37
|
-
component: name,
|
|
38
|
-
children: [],
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
if (template[0].type === "instance" && props !== undefined) {
|
|
43
|
-
template[0].props = Object.entries(props).map(([prop, value]) => {
|
|
44
|
-
if (typeof value === "string") {
|
|
45
|
-
return { type: "string", name: prop, value: value };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (typeof value === "number") {
|
|
49
|
-
return { type: "number", name: prop, value: value };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (typeof value === "boolean") {
|
|
53
|
-
return { type: "boolean", name: prop, value: value };
|
|
54
|
-
}
|
|
55
|
-
throw new Error(`Unsupported prop ${props} with value ${value}`);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const data = generateDataFromEmbedTemplate(template, metas, "base");
|
|
60
|
-
|
|
61
|
-
const instances: [Instance["id"], Instance][] = [
|
|
62
|
-
[
|
|
63
|
-
"root",
|
|
64
|
-
{
|
|
65
|
-
type: "instance",
|
|
66
|
-
id: "root",
|
|
67
|
-
component: "Box",
|
|
68
|
-
children: data.children,
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
...data.instances.map(
|
|
72
|
-
(instance) => [instance.id, instance] satisfies [Instance["id"], Instance]
|
|
73
|
-
),
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<>
|
|
78
|
-
<style>
|
|
79
|
-
{generateCssText(
|
|
80
|
-
{
|
|
81
|
-
assets: [],
|
|
82
|
-
breakpoints: [["base", { id: "base", label: "base" }]],
|
|
83
|
-
styles: data.styles.map((item) => [getStyleDeclKey(item), item]),
|
|
84
|
-
styleSourceSelections: data.styleSourceSelections.map((item) => [
|
|
85
|
-
item.instanceId,
|
|
86
|
-
item,
|
|
87
|
-
]),
|
|
88
|
-
componentMetas: metas,
|
|
89
|
-
},
|
|
90
|
-
{ assetBaseUrl: "/" }
|
|
91
|
-
)}
|
|
92
|
-
</style>
|
|
93
|
-
<InstanceRoot
|
|
94
|
-
data={{
|
|
95
|
-
page: {
|
|
96
|
-
path: "",
|
|
97
|
-
id: "",
|
|
98
|
-
name: "",
|
|
99
|
-
title: "",
|
|
100
|
-
meta: {},
|
|
101
|
-
rootInstanceId: "root",
|
|
102
|
-
},
|
|
103
|
-
pages: [],
|
|
104
|
-
assets: [],
|
|
105
|
-
build: {
|
|
106
|
-
instances,
|
|
107
|
-
props: data.props.map((prop) => [prop.id, prop]),
|
|
108
|
-
dataSources: data.dataSources.map((dataSource) => [
|
|
109
|
-
dataSource.id,
|
|
110
|
-
dataSource,
|
|
111
|
-
]),
|
|
112
|
-
},
|
|
113
|
-
}}
|
|
114
|
-
utils={{
|
|
115
|
-
indexesWithinAncestors: getIndexesWithinAncestors(
|
|
116
|
-
metas,
|
|
117
|
-
new Map(instances),
|
|
118
|
-
["root"]
|
|
119
|
-
),
|
|
120
|
-
executeComputingExpressions: (values) => {
|
|
121
|
-
const expressions = new Map<string, string>();
|
|
122
|
-
for (const dataSource of data.dataSources) {
|
|
123
|
-
const name = encodeDataSourceVariable(dataSource.id);
|
|
124
|
-
if (dataSource.type === "expression") {
|
|
125
|
-
expressions.set(name, dataSource.code);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return decodeVariablesMap(
|
|
129
|
-
executeComputingExpressions(
|
|
130
|
-
expressions,
|
|
131
|
-
encodeVariablesMap(values)
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
},
|
|
135
|
-
executeEffectfulExpression: (code, args, values) => {
|
|
136
|
-
return decodeVariablesMap(
|
|
137
|
-
executeEffectfulExpression(code, args, encodeVariablesMap(values))
|
|
138
|
-
);
|
|
139
|
-
},
|
|
140
|
-
}}
|
|
141
|
-
Component={WebstudioComponent}
|
|
142
|
-
components={new Map(Object.entries(components))}
|
|
143
|
-
/>
|
|
144
|
-
</>
|
|
145
|
-
);
|
|
146
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
3
|
-
import type { htmlTags as HtmlTags } from "html-tags";
|
|
4
|
-
import { EmbedTemplateStyleDecl, WsEmbedTemplate } from "../embed-template";
|
|
5
|
-
|
|
6
|
-
export type PresetStyle<Tag extends HtmlTags = HtmlTags> = Partial<
|
|
7
|
-
Record<Tag, EmbedTemplateStyleDecl[]>
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
// props are separated from the rest of the meta
|
|
11
|
-
// so they can be exported separately and potentially tree-shaken
|
|
12
|
-
const WsComponentPropsMeta = z.object({
|
|
13
|
-
props: z.record(PropMeta),
|
|
14
|
-
// Props that will be always visible in properties panel.
|
|
15
|
-
initialProps: z.array(z.string()).optional(),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export type WsComponentPropsMeta = z.infer<typeof WsComponentPropsMeta>;
|
|
19
|
-
|
|
20
|
-
export const componentCategories = [
|
|
21
|
-
"general",
|
|
22
|
-
"text",
|
|
23
|
-
"media",
|
|
24
|
-
"forms",
|
|
25
|
-
"radix",
|
|
26
|
-
"hidden",
|
|
27
|
-
] as const;
|
|
28
|
-
|
|
29
|
-
export const stateCategories = ["states", "component-states"] as const;
|
|
30
|
-
|
|
31
|
-
export const ComponentState = z.object({
|
|
32
|
-
category: z.enum(stateCategories).optional(),
|
|
33
|
-
selector: z.string(),
|
|
34
|
-
label: z.string(),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export type ComponentState = z.infer<typeof ComponentState>;
|
|
38
|
-
|
|
39
|
-
const ComponentToken = z.object({
|
|
40
|
-
variant: z.optional(z.string()),
|
|
41
|
-
styles: z.array(EmbedTemplateStyleDecl),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
export const defaultStates: ComponentState[] = [
|
|
45
|
-
{ selector: ":hover", label: "Hover" },
|
|
46
|
-
{ selector: ":active", label: "Active" },
|
|
47
|
-
{ selector: ":focus", label: "Focus" },
|
|
48
|
-
{ selector: ":focus-visible", label: "Focus Visible" },
|
|
49
|
-
{ selector: ":focus-within", label: "Focus Within" },
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
const WsComponentMeta = z.object({
|
|
53
|
-
category: z.enum(componentCategories).optional(),
|
|
54
|
-
// container - can accept other components with dnd or be edited as text
|
|
55
|
-
// control - usually form controls like inputs, without children
|
|
56
|
-
// embed - images, videos or other embeddable components, without children
|
|
57
|
-
// rich-text-child - formatted text fragment, not listed in components list
|
|
58
|
-
type: z.enum(["container", "control", "embed", "rich-text-child"]),
|
|
59
|
-
requiredAncestors: z.optional(z.array(z.string())),
|
|
60
|
-
invalidAncestors: z.optional(z.array(z.string())),
|
|
61
|
-
// when this field is specified component receives
|
|
62
|
-
// prop with index of same components withiin specified ancestor
|
|
63
|
-
// important to automatically enumerate collections without
|
|
64
|
-
// naming every item manually
|
|
65
|
-
indexWithinAncestor: z.optional(z.string()),
|
|
66
|
-
stylable: z.optional(z.boolean()),
|
|
67
|
-
// specifies whether the instance can be deleted,
|
|
68
|
-
// copied or dragged out of its parent instance
|
|
69
|
-
// true by default
|
|
70
|
-
detachable: z.optional(z.boolean()),
|
|
71
|
-
label: z.optional(z.string()),
|
|
72
|
-
description: z.string().optional(),
|
|
73
|
-
icon: z.string(),
|
|
74
|
-
presetStyle: z.optional(z.record(z.string(), EmbedTemplateStyleDecl)),
|
|
75
|
-
presetTokens: z.optional(z.record(z.string(), ComponentToken)),
|
|
76
|
-
states: z.optional(z.array(ComponentState)),
|
|
77
|
-
template: z.optional(WsEmbedTemplate),
|
|
78
|
-
order: z.number().optional(),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
export type WsComponentMeta = Omit<
|
|
82
|
-
z.infer<typeof WsComponentMeta>,
|
|
83
|
-
"presetStyle"
|
|
84
|
-
> & {
|
|
85
|
-
presetStyle?: PresetStyle;
|
|
86
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { componentAttribute, idAttribute } from "../tree";
|
|
2
|
-
|
|
3
|
-
export type AnyComponent = React.ForwardRefExoticComponent<
|
|
4
|
-
Omit<
|
|
5
|
-
React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>,
|
|
6
|
-
"ref"
|
|
7
|
-
> & {
|
|
8
|
-
[componentAttribute]: string;
|
|
9
|
-
[idAttribute]: string;
|
|
10
|
-
} & React.RefAttributes<HTMLElement>
|
|
11
|
-
>;
|
|
12
|
-
|
|
13
|
-
export type Components = Map<string, AnyComponent>;
|
package/src/context.tsx
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { type ReadableAtom, atom } from "nanostores";
|
|
2
|
-
import { createContext } from "react";
|
|
3
|
-
import type { Assets } from "@webstudio-is/asset-uploader";
|
|
4
|
-
import type { DataSource, Instance, Prop } from "@webstudio-is/project-build";
|
|
5
|
-
import type { Pages, PropsByInstanceId } from "./props";
|
|
6
|
-
import type { IndexesWithinAncestors } from "./instance-utils";
|
|
7
|
-
|
|
8
|
-
export type Params = {
|
|
9
|
-
renderer?: "canvas" | "preview";
|
|
10
|
-
/**
|
|
11
|
-
* Base url ir base path for images with ending slash.
|
|
12
|
-
* Used for configuring image with different sizes.
|
|
13
|
-
* Concatinated with "name?width=&quality=&format=".
|
|
14
|
-
*
|
|
15
|
-
* For example
|
|
16
|
-
* /asset/image/ used by default in builder
|
|
17
|
-
* https://image-transform.wstd.io/cdn-cgi/image/
|
|
18
|
-
* https://webstudio.is/cdn-cgi/image/
|
|
19
|
-
*/
|
|
20
|
-
imageBaseUrl: string;
|
|
21
|
-
/**
|
|
22
|
-
* Base url or base path for any asset with ending slash.
|
|
23
|
-
* Used to load assets like fonts or images in styles
|
|
24
|
-
* Concatinated with "name".
|
|
25
|
-
*
|
|
26
|
-
* For example
|
|
27
|
-
* /s/uploads/
|
|
28
|
-
* /asset/file/
|
|
29
|
-
* https://assets-dev.webstudio.is/
|
|
30
|
-
* https://assets.webstudio.is/
|
|
31
|
-
*/
|
|
32
|
-
assetBaseUrl: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type DataSourceValues = Map<DataSource["id"], unknown>;
|
|
36
|
-
|
|
37
|
-
export const ReactSdkContext = createContext<
|
|
38
|
-
Params & {
|
|
39
|
-
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
40
|
-
assetsStore: ReadableAtom<Assets>;
|
|
41
|
-
pagesStore: ReadableAtom<Pages>;
|
|
42
|
-
dataSourceValuesStore: ReadableAtom<DataSourceValues>;
|
|
43
|
-
executeEffectfulExpression: (
|
|
44
|
-
expression: string,
|
|
45
|
-
args: DataSourceValues,
|
|
46
|
-
values: DataSourceValues
|
|
47
|
-
) => DataSourceValues;
|
|
48
|
-
setDataSourceValues: (newValues: DataSourceValues) => void;
|
|
49
|
-
setBoundDataSourceValue: (
|
|
50
|
-
instanceId: Instance["id"],
|
|
51
|
-
prop: Prop["name"],
|
|
52
|
-
value: unknown
|
|
53
|
-
) => void;
|
|
54
|
-
indexesWithinAncestors: IndexesWithinAncestors;
|
|
55
|
-
}
|
|
56
|
-
>({
|
|
57
|
-
imageBaseUrl: "/",
|
|
58
|
-
assetBaseUrl: "/",
|
|
59
|
-
propsByInstanceIdStore: atom(new Map()),
|
|
60
|
-
assetsStore: atom(new Map()),
|
|
61
|
-
pagesStore: atom(new Map()),
|
|
62
|
-
dataSourceValuesStore: atom(new Map()),
|
|
63
|
-
executeEffectfulExpression: () => {
|
|
64
|
-
throw Error("React SDK executeEffectfulExpression is not implemented");
|
|
65
|
-
},
|
|
66
|
-
setDataSourceValues: () => {
|
|
67
|
-
throw Error("React SDK setBoundDataSourceValue is not implemented");
|
|
68
|
-
},
|
|
69
|
-
setBoundDataSourceValue: () => {
|
|
70
|
-
throw Error("React SDK setBoundDataSourceValue is not implemented");
|
|
71
|
-
},
|
|
72
|
-
indexesWithinAncestors: new Map(),
|
|
73
|
-
});
|
package/src/css/css.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { createCssEngine, type TransformValue } from "@webstudio-is/css-engine";
|
|
2
|
-
import type { Asset, Assets } from "@webstudio-is/asset-uploader";
|
|
3
|
-
import type { Build } from "@webstudio-is/project-build";
|
|
4
|
-
import type { WsComponentMeta } from "../components/component-meta";
|
|
5
|
-
import { idAttribute } from "../tree";
|
|
6
|
-
import { addGlobalRules } from "./global-rules";
|
|
7
|
-
import { getPresetStyleRules, getStyleRules } from "./style-rules";
|
|
8
|
-
|
|
9
|
-
type Data = {
|
|
10
|
-
assets: Asset[];
|
|
11
|
-
breakpoints?: Build["breakpoints"];
|
|
12
|
-
styles?: Build["styles"];
|
|
13
|
-
styleSourceSelections?: Build["styleSourceSelections"];
|
|
14
|
-
componentMetas: Map<string, WsComponentMeta>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type CssOptions = {
|
|
18
|
-
assetBaseUrl: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const createImageValueTransformer =
|
|
22
|
-
(assets: Assets, options: CssOptions): TransformValue =>
|
|
23
|
-
(styleValue) => {
|
|
24
|
-
if (styleValue.type === "image" && styleValue.value.type === "asset") {
|
|
25
|
-
const asset = assets.get(styleValue.value.value);
|
|
26
|
-
if (asset === undefined) {
|
|
27
|
-
return { type: "keyword", value: "none" };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// @todo reuse image loaders and generate image-set
|
|
31
|
-
const { assetBaseUrl } = options;
|
|
32
|
-
const url = `${assetBaseUrl}${asset.name}`;
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
type: "image",
|
|
36
|
-
value: {
|
|
37
|
-
type: "url",
|
|
38
|
-
url,
|
|
39
|
-
},
|
|
40
|
-
hidden: styleValue.hidden,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const generateCssText = (data: Data, options: CssOptions) => {
|
|
46
|
-
const assets = new Map<Asset["id"], Asset>(
|
|
47
|
-
data.assets.map((asset) => [asset.id, asset])
|
|
48
|
-
);
|
|
49
|
-
const breakpoints = new Map(data.breakpoints);
|
|
50
|
-
const styles = new Map(data.styles);
|
|
51
|
-
const styleSourceSelections = new Map(data.styleSourceSelections);
|
|
52
|
-
|
|
53
|
-
const engine = createCssEngine({ name: "ssr" });
|
|
54
|
-
|
|
55
|
-
addGlobalRules(engine, {
|
|
56
|
-
assets,
|
|
57
|
-
assetBaseUrl: options.assetBaseUrl,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
for (const breakpoint of breakpoints.values()) {
|
|
61
|
-
engine.addMediaRule(breakpoint.id, breakpoint);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (const [component, meta] of data.componentMetas) {
|
|
65
|
-
const presetStyle = meta.presetStyle;
|
|
66
|
-
if (presetStyle === undefined) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const rules = getPresetStyleRules(component, presetStyle);
|
|
70
|
-
for (const [selector, style] of rules) {
|
|
71
|
-
engine.addStyleRule(selector, { style });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const styleRules = getStyleRules(styles, styleSourceSelections);
|
|
76
|
-
for (const { breakpointId, instanceId, state, style } of styleRules) {
|
|
77
|
-
engine.addStyleRule(
|
|
78
|
-
`[${idAttribute}="${instanceId}"]${state ?? ""}`,
|
|
79
|
-
{
|
|
80
|
-
breakpoint: breakpointId,
|
|
81
|
-
style,
|
|
82
|
-
},
|
|
83
|
-
createImageValueTransformer(assets, options)
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return engine.cssText;
|
|
88
|
-
};
|
package/src/css/global-rules.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { CssEngine } from "@webstudio-is/css-engine";
|
|
2
|
-
import type { Assets, FontAsset } from "@webstudio-is/asset-uploader";
|
|
3
|
-
import { getFontFaces } from "@webstudio-is/fonts";
|
|
4
|
-
|
|
5
|
-
export const addGlobalRules = (
|
|
6
|
-
engine: CssEngine,
|
|
7
|
-
{ assets, assetBaseUrl }: { assets: Assets; assetBaseUrl: string }
|
|
8
|
-
) => {
|
|
9
|
-
// @todo we need to figure out all global resets while keeping
|
|
10
|
-
// the engine aware of all of them.
|
|
11
|
-
// Ideally, the user is somehow aware and in control of the reset
|
|
12
|
-
// Layout source https://twitter.com/ChallengesCss/status/1471128244720181258
|
|
13
|
-
engine.addPlaintextRule("html {margin: 0; display: grid; min-height: 100%}");
|
|
14
|
-
|
|
15
|
-
const fontAssets: FontAsset[] = [];
|
|
16
|
-
for (const asset of assets.values()) {
|
|
17
|
-
if (asset?.type === "font") {
|
|
18
|
-
fontAssets.push(asset);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
|
|
23
|
-
for (const fontFace of fontFaces) {
|
|
24
|
-
engine.addFontFaceRule(fontFace);
|
|
25
|
-
}
|
|
26
|
-
};
|
package/src/css/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as normalize from "./normalize";
|
|
2
|
-
import type { htmlTags as HtmlTags } from "html-tags";
|
|
3
|
-
import type { Style } from "@webstudio-is/css-data";
|
|
4
|
-
|
|
5
|
-
// no way I found to check exports https://github.com/microsoft/TypeScript/issues/38511
|
|
6
|
-
// we can check here that all exports represents a valid html tag
|
|
7
|
-
const normalizeWithKeyof = { ...normalize };
|
|
8
|
-
|
|
9
|
-
type ExportedTags = keyof typeof normalizeWithKeyof;
|
|
10
|
-
|
|
11
|
-
type ValidTags = ExportedTags extends HtmlTags ? ExportedTags : false;
|
|
12
|
-
|
|
13
|
-
normalizeWithKeyof satisfies Record<ValidTags, Style>;
|