@webstudio-is/react-sdk 0.55.0 → 0.57.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/custom-components/image.js +6 -6
- package/lib/app/custom-components/shared/remix-link.js +3 -3
- package/lib/app/params.js +4 -2
- package/lib/cjs/app/custom-components/image.js +6 -6
- package/lib/cjs/app/custom-components/shared/remix-link.js +3 -3
- package/lib/cjs/app/params.js +4 -2
- package/lib/cjs/components/link.js +14 -8
- package/lib/cjs/css/css.js +8 -5
- package/lib/cjs/css/global-rules.js +3 -3
- package/lib/cjs/css/style-rules.js +10 -3
- package/lib/cjs/props.js +18 -9
- package/lib/cjs/pubsub/raf-queue.js +3 -6
- package/lib/cjs/tree/root.js +1 -1
- package/lib/components/link.js +14 -8
- package/lib/css/css.js +8 -5
- package/lib/css/global-rules.js +4 -7
- package/lib/css/style-rules.js +10 -3
- package/lib/props.js +18 -9
- package/lib/pubsub/raf-queue.js +3 -6
- package/lib/tree/root.js +1 -1
- package/package.json +21 -21
- package/src/app/custom-components/image.tsx +6 -7
- package/src/app/custom-components/shared/remix-link.tsx +3 -3
- package/src/app/params.ts +6 -4
- package/src/components/link.tsx +17 -7
- package/src/css/css.ts +9 -7
- package/src/css/global-rules.ts +6 -10
- package/src/css/style-rules.test.ts +22 -0
- package/src/css/style-rules.ts +15 -4
- package/src/props.test.ts +50 -20
- package/src/props.ts +27 -12
- package/src/pubsub/raf-queue.ts +3 -9
- package/src/tree/create-elements-tree.tsx +3 -7
- package/src/tree/root.ts +1 -1
- package/src/tree/webstudio-component.tsx +2 -2
- package/lib/types/app/custom-components/image.d.ts +0 -6
- package/lib/types/app/custom-components/index.d.ts +0 -26
- package/lib/types/app/custom-components/link-block.d.ts +0 -6
- package/lib/types/app/custom-components/link.d.ts +0 -6
- package/lib/types/app/custom-components/rich-text-link.d.ts +0 -6
- package/lib/types/app/custom-components/shared/remix-link.d.ts +0 -10
- package/lib/types/app/handle-request.server.d.ts +0 -2
- package/lib/types/app/index.d.ts +0 -3
- package/lib/types/app/params.d.ts +0 -6
- package/lib/types/app/root.d.ts +0 -8
- package/lib/types/components/__generated__/blockquote.props.d.ts +0 -2
- package/lib/types/components/__generated__/body.props.d.ts +0 -2
- package/lib/types/components/__generated__/bold.props.d.ts +0 -2
- package/lib/types/components/__generated__/box.props.d.ts +0 -2
- package/lib/types/components/__generated__/button.props.d.ts +0 -2
- package/lib/types/components/__generated__/code.props.d.ts +0 -2
- package/lib/types/components/__generated__/form.props.d.ts +0 -2
- package/lib/types/components/__generated__/fragment.props.d.ts +0 -2
- package/lib/types/components/__generated__/heading.props.d.ts +0 -2
- package/lib/types/components/__generated__/image.props.d.ts +0 -2
- package/lib/types/components/__generated__/input.props.d.ts +0 -2
- package/lib/types/components/__generated__/italic.props.d.ts +0 -2
- package/lib/types/components/__generated__/link-block.props.d.ts +0 -2
- package/lib/types/components/__generated__/link.props.d.ts +0 -2
- package/lib/types/components/__generated__/list-item.props.d.ts +0 -2
- package/lib/types/components/__generated__/list.props.d.ts +0 -2
- package/lib/types/components/__generated__/paragraph.props.d.ts +0 -2
- package/lib/types/components/__generated__/rich-text-link.props.d.ts +0 -2
- package/lib/types/components/__generated__/separator.props.d.ts +0 -2
- package/lib/types/components/__generated__/slot.props.d.ts +0 -2
- package/lib/types/components/__generated__/span.props.d.ts +0 -2
- package/lib/types/components/__generated__/subscript.props.d.ts +0 -2
- package/lib/types/components/__generated__/superscript.props.d.ts +0 -2
- package/lib/types/components/__generated__/text-block.props.d.ts +0 -2
- package/lib/types/components/blockquote.d.ts +0 -3
- package/lib/types/components/blockquote.stories.d.ts +0 -5
- package/lib/types/components/blockquote.ws.d.ts +0 -3
- package/lib/types/components/body.d.ts +0 -3
- package/lib/types/components/body.stories.d.ts +0 -6
- package/lib/types/components/body.ws.d.ts +0 -3
- package/lib/types/components/bold.d.ts +0 -3
- package/lib/types/components/bold.stories.d.ts +0 -5
- package/lib/types/components/bold.ws.d.ts +0 -3
- package/lib/types/components/box.d.ts +0 -7
- package/lib/types/components/box.stories.d.ts +0 -9
- package/lib/types/components/box.ws.d.ts +0 -3
- package/lib/types/components/button.d.ts +0 -7
- package/lib/types/components/button.stories.d.ts +0 -9
- package/lib/types/components/button.ws.d.ts +0 -3
- package/lib/types/components/code.d.ts +0 -9
- package/lib/types/components/code.stories.d.ts +0 -11
- package/lib/types/components/code.ws.d.ts +0 -3
- package/lib/types/components/component-meta.d.ts +0 -610
- package/lib/types/components/components-utils.d.ts +0 -34
- package/lib/types/components/components.d.ts +0 -31
- package/lib/types/components/form.d.ts +0 -3
- package/lib/types/components/form.stories.d.ts +0 -5
- package/lib/types/components/form.ws.d.ts +0 -3
- package/lib/types/components/fragment.d.ts +0 -6
- package/lib/types/components/fragment.ws.d.ts +0 -3
- package/lib/types/components/heading.d.ts +0 -7
- package/lib/types/components/heading.stories.d.ts +0 -9
- package/lib/types/components/heading.ws.d.ts +0 -3
- package/lib/types/components/image.d.ts +0 -3
- package/lib/types/components/image.stories.d.ts +0 -5
- package/lib/types/components/image.ws.d.ts +0 -3
- package/lib/types/components/index.d.ts +0 -17
- package/lib/types/components/input.d.ts +0 -3
- package/lib/types/components/input.stories.d.ts +0 -5
- package/lib/types/components/input.ws.d.ts +0 -3
- package/lib/types/components/italic.d.ts +0 -3
- package/lib/types/components/italic.stories.d.ts +0 -5
- package/lib/types/components/italic.ws.d.ts +0 -3
- package/lib/types/components/link-block.d.ts +0 -3
- package/lib/types/components/link-block.stories.d.ts +0 -13
- package/lib/types/components/link-block.ws.d.ts +0 -3
- package/lib/types/components/link.d.ts +0 -9
- package/lib/types/components/link.stories.d.ts +0 -13
- package/lib/types/components/link.ws.d.ts +0 -3
- package/lib/types/components/list-item.d.ts +0 -3
- package/lib/types/components/list-item.stories.d.ts +0 -5
- package/lib/types/components/list-item.ws.d.ts +0 -3
- package/lib/types/components/list.d.ts +0 -9
- package/lib/types/components/list.stories.d.ts +0 -9
- package/lib/types/components/list.ws.d.ts +0 -3
- package/lib/types/components/paragraph.d.ts +0 -3
- package/lib/types/components/paragraph.stories.d.ts +0 -5
- package/lib/types/components/paragraph.ws.d.ts +0 -3
- package/lib/types/components/rich-text-link.d.ts +0 -2
- package/lib/types/components/rich-text-link.stories.d.ts +0 -13
- package/lib/types/components/rich-text-link.ws.d.ts +0 -3
- package/lib/types/components/separator.d.ts +0 -3
- package/lib/types/components/separator.stories.d.ts +0 -5
- package/lib/types/components/separator.ws.d.ts +0 -3
- package/lib/types/components/slot.d.ts +0 -6
- package/lib/types/components/slot.stories.d.ts +0 -9
- package/lib/types/components/slot.ws.d.ts +0 -3
- package/lib/types/components/span.d.ts +0 -3
- package/lib/types/components/span.stories.d.ts +0 -5
- package/lib/types/components/span.ws.d.ts +0 -3
- package/lib/types/components/subscript.d.ts +0 -3
- package/lib/types/components/subscript.stories.d.ts +0 -5
- package/lib/types/components/subscript.ws.d.ts +0 -3
- package/lib/types/components/superscript.d.ts +0 -3
- package/lib/types/components/superscript.stories.d.ts +0 -5
- package/lib/types/components/superscript.ws.d.ts +0 -3
- package/lib/types/components/text-block.d.ts +0 -3
- package/lib/types/components/text-block.stories.d.ts +0 -5
- package/lib/types/components/text-block.ws.d.ts +0 -3
- package/lib/types/context.d.ts +0 -9
- package/lib/types/css/css.d.ts +0 -54
- package/lib/types/css/get-browser-style.d.ts +0 -2
- package/lib/types/css/global-rules.d.ts +0 -44
- package/lib/types/css/index.d.ts +0 -4
- package/lib/types/css/normalize-type-check.d.ts +0 -1
- package/lib/types/css/normalize.d.ts +0 -2429
- package/lib/types/css/presets.d.ts +0 -38
- package/lib/types/css/style-rules.d.ts +0 -201
- package/lib/types/css/style-rules.test.d.ts +0 -1
- package/lib/types/index.d.ts +0 -9
- package/lib/types/props.d.ts +0 -97
- package/lib/types/props.test.d.ts +0 -1
- package/lib/types/pubsub/create.d.ts +0 -28
- package/lib/types/pubsub/index.d.ts +0 -1
- package/lib/types/pubsub/raf-queue.d.ts +0 -1
- package/lib/types/tree/create-elements-tree.d.ts +0 -29
- package/lib/types/tree/index.d.ts +0 -3
- package/lib/types/tree/root.d.ts +0 -25
- package/lib/types/tree/session-storage-polyfill.d.ts +0 -2
- package/lib/types/tree/webstudio-component.d.ts +0 -15
|
@@ -17,14 +17,14 @@ const Image = forwardRef(
|
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
if (asset.location === "REMOTE") {
|
|
20
|
-
return loaders.cloudflareImageLoader(
|
|
20
|
+
return loaders.cloudflareImageLoader({
|
|
21
|
+
resizeOrigin: params.resizeOrigin,
|
|
22
|
+
cdnUrl: params.assetBaseUrl
|
|
23
|
+
});
|
|
21
24
|
}
|
|
22
|
-
return loaders.localImageLoader(params);
|
|
25
|
+
return loaders.localImageLoader({ publicPath: params.assetBaseUrl });
|
|
23
26
|
}, [asset, params]);
|
|
24
|
-
|
|
25
|
-
if (asset != null) {
|
|
26
|
-
src = asset.path;
|
|
27
|
-
}
|
|
27
|
+
const src = asset?.name ?? props.src;
|
|
28
28
|
if (asset == null || loader == null) {
|
|
29
29
|
return /* @__PURE__ */ jsx(SdkImage, { ...props, src, ref }, src);
|
|
30
30
|
}
|
|
@@ -5,10 +5,10 @@ import { usePropUrl, getInstanceIdFromComponentProps } from "../../../props";
|
|
|
5
5
|
const wrapLinkComponent = (BaseLink) => {
|
|
6
6
|
const Component = forwardRef((props, ref) => {
|
|
7
7
|
const href = usePropUrl(getInstanceIdFromComponentProps(props), "href");
|
|
8
|
-
if (
|
|
9
|
-
return /* @__PURE__ */ jsx(
|
|
8
|
+
if (href?.type === "page") {
|
|
9
|
+
return /* @__PURE__ */ jsx(RemixLink, { ...props, to: href.page.path, ref });
|
|
10
10
|
}
|
|
11
|
-
return /* @__PURE__ */ jsx(
|
|
11
|
+
return /* @__PURE__ */ jsx(BaseLink, { ...props, ref });
|
|
12
12
|
});
|
|
13
13
|
Component.displayName = BaseLink.displayName;
|
|
14
14
|
return Component;
|
package/lib/app/params.js
CHANGED
|
@@ -37,14 +37,14 @@ const Image = (0, import_react.forwardRef)(
|
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
39
|
if (asset.location === "REMOTE") {
|
|
40
|
-
return import_image.loaders.cloudflareImageLoader(
|
|
40
|
+
return import_image.loaders.cloudflareImageLoader({
|
|
41
|
+
resizeOrigin: params.resizeOrigin,
|
|
42
|
+
cdnUrl: params.assetBaseUrl
|
|
43
|
+
});
|
|
41
44
|
}
|
|
42
|
-
return import_image.loaders.localImageLoader(params);
|
|
45
|
+
return import_image.loaders.localImageLoader({ publicPath: params.assetBaseUrl });
|
|
43
46
|
}, [asset, params]);
|
|
44
|
-
|
|
45
|
-
if (asset != null) {
|
|
46
|
-
src = asset.path;
|
|
47
|
-
}
|
|
47
|
+
const src = asset?.name ?? props.src;
|
|
48
48
|
if (asset == null || loader == null) {
|
|
49
49
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image2.Image, { ...props, src, ref }, src);
|
|
50
50
|
}
|
|
@@ -28,10 +28,10 @@ var import_props = require("../../../props");
|
|
|
28
28
|
const wrapLinkComponent = (BaseLink) => {
|
|
29
29
|
const Component = (0, import_react2.forwardRef)((props, ref) => {
|
|
30
30
|
const href = (0, import_props.usePropUrl)((0, import_props.getInstanceIdFromComponentProps)(props), "href");
|
|
31
|
-
if (
|
|
32
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
31
|
+
if (href?.type === "page") {
|
|
32
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Link, { ...props, to: href.page.path, ref });
|
|
33
33
|
}
|
|
34
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BaseLink, { ...props, ref });
|
|
35
35
|
});
|
|
36
36
|
Component.displayName = BaseLink.displayName;
|
|
37
37
|
return Component;
|
package/lib/cjs/app/params.js
CHANGED
|
@@ -22,8 +22,10 @@ __export(params_exports, {
|
|
|
22
22
|
setParams: () => setParams
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(params_exports);
|
|
25
|
-
let params
|
|
26
|
-
const emptyParams = {
|
|
25
|
+
let params;
|
|
26
|
+
const emptyParams = {
|
|
27
|
+
assetBaseUrl: "/"
|
|
28
|
+
};
|
|
27
29
|
const getParams = () => params ?? emptyParams;
|
|
28
30
|
const setParams = (newParams) => {
|
|
29
31
|
params = newParams;
|
|
@@ -25,16 +25,22 @@ module.exports = __toCommonJS(link_exports);
|
|
|
25
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
var import_props = require("../props");
|
|
28
|
+
var import_params = require("../app/params");
|
|
28
29
|
const defaultTag = "a";
|
|
29
30
|
const Link = (0, import_react.forwardRef)((props, ref) => {
|
|
30
31
|
const href = (0, import_props.usePropUrl)((0, import_props.getInstanceIdFromComponentProps)(props), "href");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const { assetBaseUrl } = (0, import_params.getParams)();
|
|
33
|
+
let url;
|
|
34
|
+
switch (href?.type) {
|
|
35
|
+
case "page":
|
|
36
|
+
url = href.page.path;
|
|
37
|
+
break;
|
|
38
|
+
case "asset":
|
|
39
|
+
url = `${assetBaseUrl}${href.asset.name}`;
|
|
40
|
+
break;
|
|
41
|
+
case "string":
|
|
42
|
+
url = href.url;
|
|
43
|
+
}
|
|
44
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props, href: url, ref });
|
|
39
45
|
});
|
|
40
46
|
Link.displayName = "Link";
|
package/lib/cjs/css/css.js
CHANGED
|
@@ -34,8 +34,8 @@ const createImageValueTransformer = (assets, options) => (styleValue) => {
|
|
|
34
34
|
if (asset === void 0) {
|
|
35
35
|
return { type: "keyword", value: "none" };
|
|
36
36
|
}
|
|
37
|
-
const {
|
|
38
|
-
const url =
|
|
37
|
+
const { assetBaseUrl } = options;
|
|
38
|
+
const url = `${assetBaseUrl}${asset.name}`;
|
|
39
39
|
return {
|
|
40
40
|
type: "image",
|
|
41
41
|
value: {
|
|
@@ -54,7 +54,10 @@ const generateCssText = (data, options) => {
|
|
|
54
54
|
const styles = new Map(data.styles);
|
|
55
55
|
const styleSourceSelections = new Map(data.styleSourceSelections);
|
|
56
56
|
const engine = (0, import_css_engine.createCssEngine)({ name: "ssr" });
|
|
57
|
-
(0, import_global_rules.addGlobalRules)(engine, {
|
|
57
|
+
(0, import_global_rules.addGlobalRules)(engine, {
|
|
58
|
+
assets,
|
|
59
|
+
assetBaseUrl: options.assetBaseUrl
|
|
60
|
+
});
|
|
58
61
|
for (const breakpoint of breakpoints.values()) {
|
|
59
62
|
engine.addMediaRule(breakpoint.id, breakpoint);
|
|
60
63
|
}
|
|
@@ -73,9 +76,9 @@ const generateCssText = (data, options) => {
|
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
const styleRules = (0, import_style_rules.getStyleRules)(styles, styleSourceSelections);
|
|
76
|
-
for (const { breakpointId, instanceId, style } of styleRules) {
|
|
79
|
+
for (const { breakpointId, instanceId, state, style } of styleRules) {
|
|
77
80
|
engine.addStyleRule(
|
|
78
|
-
`[${import_tree.idAttribute}="${instanceId}"]`,
|
|
81
|
+
`[${import_tree.idAttribute}="${instanceId}"]${state ?? ""}`,
|
|
79
82
|
{
|
|
80
83
|
breakpoint: breakpointId,
|
|
81
84
|
style
|
|
@@ -22,15 +22,15 @@ __export(global_rules_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(global_rules_exports);
|
|
24
24
|
var import_fonts = require("@webstudio-is/fonts");
|
|
25
|
-
const addGlobalRules = (engine, { assets }) => {
|
|
25
|
+
const addGlobalRules = (engine, { assets, assetBaseUrl }) => {
|
|
26
26
|
engine.addPlaintextRule("html {margin: 0; height: 100%}");
|
|
27
27
|
const fontAssets = [];
|
|
28
28
|
for (const asset of assets.values()) {
|
|
29
|
-
if (asset
|
|
29
|
+
if (asset?.type === "font") {
|
|
30
30
|
fontAssets.push(asset);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
const fontFaces = (0, import_fonts.getFontFaces)(fontAssets);
|
|
33
|
+
const fontFaces = (0, import_fonts.getFontFaces)(fontAssets, { assetBaseUrl });
|
|
34
34
|
for (const fontFace of fontFaces) {
|
|
35
35
|
engine.addFontFaceRule(fontFace);
|
|
36
36
|
}
|
|
@@ -43,15 +43,22 @@ const getStyleRules = (styles, styleSourceSelections) => {
|
|
|
43
43
|
if (styleSourceStyles === void 0) {
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
|
-
for (const {
|
|
47
|
-
|
|
46
|
+
for (const {
|
|
47
|
+
breakpointId,
|
|
48
|
+
state,
|
|
49
|
+
property,
|
|
50
|
+
value
|
|
51
|
+
} of styleSourceStyles) {
|
|
52
|
+
const key = `${breakpointId}:${state ?? ""}`;
|
|
53
|
+
let styleRule = styleRuleByBreakpointId.get(key);
|
|
48
54
|
if (styleRule === void 0) {
|
|
49
55
|
styleRule = {
|
|
50
56
|
instanceId,
|
|
51
57
|
breakpointId,
|
|
58
|
+
state,
|
|
52
59
|
style: {}
|
|
53
60
|
};
|
|
54
|
-
styleRuleByBreakpointId.set(
|
|
61
|
+
styleRuleByBreakpointId.set(key, styleRule);
|
|
55
62
|
}
|
|
56
63
|
styleRule.style[property] = value;
|
|
57
64
|
}
|
package/lib/cjs/props.js
CHANGED
|
@@ -79,8 +79,12 @@ const usePropAsset = (instanceId, name) => {
|
|
|
79
79
|
const asset = (0, import_react2.useStore)(assetStore);
|
|
80
80
|
return asset;
|
|
81
81
|
};
|
|
82
|
-
const resolveUrlProp = (instanceId, name,
|
|
83
|
-
|
|
82
|
+
const resolveUrlProp = (instanceId, name, {
|
|
83
|
+
props,
|
|
84
|
+
pages,
|
|
85
|
+
assets
|
|
86
|
+
}) => {
|
|
87
|
+
const instanceProps = props.get(instanceId);
|
|
84
88
|
if (instanceProps === void 0) {
|
|
85
89
|
return;
|
|
86
90
|
}
|
|
@@ -89,27 +93,32 @@ const resolveUrlProp = (instanceId, name, propsByInstanceId, pages) => {
|
|
|
89
93
|
continue;
|
|
90
94
|
}
|
|
91
95
|
if (prop.type === "page") {
|
|
92
|
-
|
|
96
|
+
const page = pages.get(prop.value);
|
|
97
|
+
return page && { type: "page", page };
|
|
93
98
|
}
|
|
94
99
|
if (prop.type === "string") {
|
|
95
100
|
for (const page of pages.values()) {
|
|
96
101
|
if (page.path === prop.value) {
|
|
97
|
-
return page;
|
|
102
|
+
return { type: "page", page };
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
|
-
return prop.value;
|
|
105
|
+
return { type: "string", url: prop.value };
|
|
106
|
+
}
|
|
107
|
+
if (prop.type === "asset") {
|
|
108
|
+
const asset = assets.get(prop.value);
|
|
109
|
+
return asset && { type: "asset", asset };
|
|
101
110
|
}
|
|
102
111
|
return;
|
|
103
112
|
}
|
|
104
113
|
};
|
|
105
114
|
const usePropUrl = (instanceId, name) => {
|
|
106
|
-
const { propsByInstanceIdStore, pagesStore } = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
115
|
+
const { propsByInstanceIdStore, pagesStore, assetsStore } = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
107
116
|
const pageStore = (0, import_react.useMemo)(
|
|
108
117
|
() => (0, import_nanostores.computed)(
|
|
109
|
-
[propsByInstanceIdStore, pagesStore],
|
|
110
|
-
(
|
|
118
|
+
[propsByInstanceIdStore, pagesStore, assetsStore],
|
|
119
|
+
(props, pages, assets) => resolveUrlProp(instanceId, name, { props, pages, assets })
|
|
111
120
|
),
|
|
112
|
-
[propsByInstanceIdStore, pagesStore, instanceId, name]
|
|
121
|
+
[propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
|
|
113
122
|
);
|
|
114
123
|
return (0, import_react2.useStore)(pageStore);
|
|
115
124
|
};
|
|
@@ -21,15 +21,12 @@ __export(raf_queue_exports, {
|
|
|
21
21
|
batchUpdate: () => batchUpdate
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(raf_queue_exports);
|
|
24
|
-
var import_react_dom = require("react-dom");
|
|
25
24
|
let handle;
|
|
26
25
|
let updateQueue = [];
|
|
27
26
|
const processUpdates = (updates) => {
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
});
|
|
27
|
+
for (const update of updates) {
|
|
28
|
+
update();
|
|
29
|
+
}
|
|
33
30
|
};
|
|
34
31
|
const batchUpdate = (update) => {
|
|
35
32
|
updateQueue.push(update);
|
package/lib/cjs/tree/root.js
CHANGED
|
@@ -34,7 +34,7 @@ const InstanceRoot = ({
|
|
|
34
34
|
customComponents = import_custom_components.customComponents,
|
|
35
35
|
getComponent
|
|
36
36
|
}) => {
|
|
37
|
-
(0, import_params.setParams)(data.params
|
|
37
|
+
(0, import_params.setParams)(data.params);
|
|
38
38
|
(0, import_components.registerComponents)(customComponents);
|
|
39
39
|
return (0, import_create_elements_tree.createElementsTree)({
|
|
40
40
|
instances: new Map(data.build.instances),
|
package/lib/components/link.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { usePropUrl, getInstanceIdFromComponentProps } from "../props";
|
|
4
|
+
import { getParams } from "../app/params";
|
|
4
5
|
const defaultTag = "a";
|
|
5
6
|
const Link = forwardRef((props, ref) => {
|
|
6
7
|
const href = usePropUrl(getInstanceIdFromComponentProps(props), "href");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const { assetBaseUrl } = getParams();
|
|
9
|
+
let url;
|
|
10
|
+
switch (href?.type) {
|
|
11
|
+
case "page":
|
|
12
|
+
url = href.page.path;
|
|
13
|
+
break;
|
|
14
|
+
case "asset":
|
|
15
|
+
url = `${assetBaseUrl}${href.asset.name}`;
|
|
16
|
+
break;
|
|
17
|
+
case "string":
|
|
18
|
+
url = href.url;
|
|
19
|
+
}
|
|
20
|
+
return /* @__PURE__ */ jsx("a", { ...props, href: url, ref });
|
|
15
21
|
});
|
|
16
22
|
Link.displayName = "Link";
|
|
17
23
|
export {
|
package/lib/css/css.js
CHANGED
|
@@ -10,8 +10,8 @@ const createImageValueTransformer = (assets, options) => (styleValue) => {
|
|
|
10
10
|
if (asset === void 0) {
|
|
11
11
|
return { type: "keyword", value: "none" };
|
|
12
12
|
}
|
|
13
|
-
const {
|
|
14
|
-
const url =
|
|
13
|
+
const { assetBaseUrl } = options;
|
|
14
|
+
const url = `${assetBaseUrl}${asset.name}`;
|
|
15
15
|
return {
|
|
16
16
|
type: "image",
|
|
17
17
|
value: {
|
|
@@ -30,7 +30,10 @@ const generateCssText = (data, options) => {
|
|
|
30
30
|
const styles = new Map(data.styles);
|
|
31
31
|
const styleSourceSelections = new Map(data.styleSourceSelections);
|
|
32
32
|
const engine = createCssEngine({ name: "ssr" });
|
|
33
|
-
addGlobalRules(engine, {
|
|
33
|
+
addGlobalRules(engine, {
|
|
34
|
+
assets,
|
|
35
|
+
assetBaseUrl: options.assetBaseUrl
|
|
36
|
+
});
|
|
34
37
|
for (const breakpoint of breakpoints.values()) {
|
|
35
38
|
engine.addMediaRule(breakpoint.id, breakpoint);
|
|
36
39
|
}
|
|
@@ -49,9 +52,9 @@ const generateCssText = (data, options) => {
|
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
const styleRules = getStyleRules(styles, styleSourceSelections);
|
|
52
|
-
for (const { breakpointId, instanceId, style } of styleRules) {
|
|
55
|
+
for (const { breakpointId, instanceId, state, style } of styleRules) {
|
|
53
56
|
engine.addStyleRule(
|
|
54
|
-
`[${idAttribute}="${instanceId}"]`,
|
|
57
|
+
`[${idAttribute}="${instanceId}"]${state ?? ""}`,
|
|
55
58
|
{
|
|
56
59
|
breakpoint: breakpointId,
|
|
57
60
|
style
|
package/lib/css/global-rules.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
getFontFaces
|
|
4
|
-
} from "@webstudio-is/fonts";
|
|
5
|
-
const addGlobalRules = (engine, { assets }) => {
|
|
1
|
+
import { getFontFaces } from "@webstudio-is/fonts";
|
|
2
|
+
const addGlobalRules = (engine, { assets, assetBaseUrl }) => {
|
|
6
3
|
engine.addPlaintextRule("html {margin: 0; height: 100%}");
|
|
7
4
|
const fontAssets = [];
|
|
8
5
|
for (const asset of assets.values()) {
|
|
9
|
-
if (asset
|
|
6
|
+
if (asset?.type === "font") {
|
|
10
7
|
fontAssets.push(asset);
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
const fontFaces = getFontFaces(fontAssets);
|
|
10
|
+
const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
|
|
14
11
|
for (const fontFace of fontFaces) {
|
|
15
12
|
engine.addFontFaceRule(fontFace);
|
|
16
13
|
}
|
package/lib/css/style-rules.js
CHANGED
|
@@ -20,15 +20,22 @@ const getStyleRules = (styles, styleSourceSelections) => {
|
|
|
20
20
|
if (styleSourceStyles === void 0) {
|
|
21
21
|
continue;
|
|
22
22
|
}
|
|
23
|
-
for (const {
|
|
24
|
-
|
|
23
|
+
for (const {
|
|
24
|
+
breakpointId,
|
|
25
|
+
state,
|
|
26
|
+
property,
|
|
27
|
+
value
|
|
28
|
+
} of styleSourceStyles) {
|
|
29
|
+
const key = `${breakpointId}:${state ?? ""}`;
|
|
30
|
+
let styleRule = styleRuleByBreakpointId.get(key);
|
|
25
31
|
if (styleRule === void 0) {
|
|
26
32
|
styleRule = {
|
|
27
33
|
instanceId,
|
|
28
34
|
breakpointId,
|
|
35
|
+
state,
|
|
29
36
|
style: {}
|
|
30
37
|
};
|
|
31
|
-
styleRuleByBreakpointId.set(
|
|
38
|
+
styleRuleByBreakpointId.set(key, styleRule);
|
|
32
39
|
}
|
|
33
40
|
styleRule.style[property] = value;
|
|
34
41
|
}
|
package/lib/props.js
CHANGED
|
@@ -51,8 +51,12 @@ const usePropAsset = (instanceId, name) => {
|
|
|
51
51
|
const asset = useStore(assetStore);
|
|
52
52
|
return asset;
|
|
53
53
|
};
|
|
54
|
-
const resolveUrlProp = (instanceId, name,
|
|
55
|
-
|
|
54
|
+
const resolveUrlProp = (instanceId, name, {
|
|
55
|
+
props,
|
|
56
|
+
pages,
|
|
57
|
+
assets
|
|
58
|
+
}) => {
|
|
59
|
+
const instanceProps = props.get(instanceId);
|
|
56
60
|
if (instanceProps === void 0) {
|
|
57
61
|
return;
|
|
58
62
|
}
|
|
@@ -61,27 +65,32 @@ const resolveUrlProp = (instanceId, name, propsByInstanceId, pages) => {
|
|
|
61
65
|
continue;
|
|
62
66
|
}
|
|
63
67
|
if (prop.type === "page") {
|
|
64
|
-
|
|
68
|
+
const page = pages.get(prop.value);
|
|
69
|
+
return page && { type: "page", page };
|
|
65
70
|
}
|
|
66
71
|
if (prop.type === "string") {
|
|
67
72
|
for (const page of pages.values()) {
|
|
68
73
|
if (page.path === prop.value) {
|
|
69
|
-
return page;
|
|
74
|
+
return { type: "page", page };
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
|
-
return prop.value;
|
|
77
|
+
return { type: "string", url: prop.value };
|
|
78
|
+
}
|
|
79
|
+
if (prop.type === "asset") {
|
|
80
|
+
const asset = assets.get(prop.value);
|
|
81
|
+
return asset && { type: "asset", asset };
|
|
73
82
|
}
|
|
74
83
|
return;
|
|
75
84
|
}
|
|
76
85
|
};
|
|
77
86
|
const usePropUrl = (instanceId, name) => {
|
|
78
|
-
const { propsByInstanceIdStore, pagesStore } = useContext(ReactSdkContext);
|
|
87
|
+
const { propsByInstanceIdStore, pagesStore, assetsStore } = useContext(ReactSdkContext);
|
|
79
88
|
const pageStore = useMemo(
|
|
80
89
|
() => computed(
|
|
81
|
-
[propsByInstanceIdStore, pagesStore],
|
|
82
|
-
(
|
|
90
|
+
[propsByInstanceIdStore, pagesStore, assetsStore],
|
|
91
|
+
(props, pages, assets) => resolveUrlProp(instanceId, name, { props, pages, assets })
|
|
83
92
|
),
|
|
84
|
-
[propsByInstanceIdStore, pagesStore, instanceId, name]
|
|
93
|
+
[propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
|
|
85
94
|
);
|
|
86
95
|
return useStore(pageStore);
|
|
87
96
|
};
|
package/lib/pubsub/raf-queue.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { unstable_batchedUpdates as batchedUpdates } from "react-dom";
|
|
2
1
|
let handle;
|
|
3
2
|
let updateQueue = [];
|
|
4
3
|
const processUpdates = (updates) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
});
|
|
4
|
+
for (const update of updates) {
|
|
5
|
+
update();
|
|
6
|
+
}
|
|
10
7
|
};
|
|
11
8
|
const batchUpdate = (update) => {
|
|
12
9
|
updateQueue.push(update);
|
package/lib/tree/root.js
CHANGED
|
@@ -11,7 +11,7 @@ const InstanceRoot = ({
|
|
|
11
11
|
customComponents = defaultCustomComponents,
|
|
12
12
|
getComponent
|
|
13
13
|
}) => {
|
|
14
|
-
setParams(data.params
|
|
14
|
+
setParams(data.params);
|
|
15
15
|
registerComponents(customComponents);
|
|
16
16
|
return createElementsTree({
|
|
17
17
|
instances: new Map(data.build.instances),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -13,23 +13,23 @@
|
|
|
13
13
|
"@remix-run/server-runtime": "1.15.0",
|
|
14
14
|
"@storybook/react": "^6.5.16",
|
|
15
15
|
"@types/node": "^18.11.18",
|
|
16
|
-
"@types/react": "^
|
|
17
|
-
"@types/react-dom": "^
|
|
16
|
+
"@types/react": "^18.0.35",
|
|
17
|
+
"@types/react-dom": "^18.0.11",
|
|
18
18
|
"jest": "^29.3.1",
|
|
19
|
-
"react": "^
|
|
20
|
-
"react-dom": "^
|
|
19
|
+
"react": "^18.2.0",
|
|
20
|
+
"react-dom": "^18.2.0",
|
|
21
21
|
"typescript": "5.0.3",
|
|
22
22
|
"zod": "^3.19.1",
|
|
23
|
-
"@webstudio-is/jest-config": "^1.0.
|
|
23
|
+
"@webstudio-is/jest-config": "^1.0.4",
|
|
24
24
|
"@webstudio-is/scripts": "^0.0.0",
|
|
25
25
|
"@webstudio-is/storybook-config": "^0.0.0",
|
|
26
|
-
"@webstudio-is/tsconfig": "^1.0.
|
|
26
|
+
"@webstudio-is/tsconfig": "^1.0.4"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@remix-run/react": "1.9.0",
|
|
30
30
|
"@remix-run/server-runtime": "1.9.0",
|
|
31
|
-
"react": "^
|
|
32
|
-
"react-dom": "^
|
|
31
|
+
"react": "^18.2.0",
|
|
32
|
+
"react-dom": "^18.2.0",
|
|
33
33
|
"zod": "^3.19.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"html-tags": "^3.2.0",
|
|
39
39
|
"nanoevents": "^7.0.1",
|
|
40
40
|
"nanostores": "^0.7.1",
|
|
41
|
-
"@webstudio-is/asset-uploader": "^0.
|
|
42
|
-
"@webstudio-is/css-data": "^0.
|
|
43
|
-
"@webstudio-is/css-engine": "^0.
|
|
44
|
-
"@webstudio-is/css-vars": "^0.
|
|
45
|
-
"@webstudio-is/fonts": "^0.
|
|
46
|
-
"@webstudio-is/generate-arg-types": "^0.
|
|
47
|
-
"@webstudio-is/icons": "^0.
|
|
48
|
-
"@webstudio-is/prisma-client": "^0.
|
|
49
|
-
"@webstudio-is/
|
|
50
|
-
"@webstudio-is/
|
|
41
|
+
"@webstudio-is/asset-uploader": "^0.57.0",
|
|
42
|
+
"@webstudio-is/css-data": "^0.57.0",
|
|
43
|
+
"@webstudio-is/css-engine": "^0.57.0",
|
|
44
|
+
"@webstudio-is/css-vars": "^0.57.0",
|
|
45
|
+
"@webstudio-is/fonts": "^0.57.0",
|
|
46
|
+
"@webstudio-is/generate-arg-types": "^0.57.0",
|
|
47
|
+
"@webstudio-is/icons": "^0.57.0",
|
|
48
|
+
"@webstudio-is/prisma-client": "^0.57.0",
|
|
49
|
+
"@webstudio-is/image": "^0.57.0",
|
|
50
|
+
"@webstudio-is/project-build": "^0.57.0"
|
|
51
51
|
},
|
|
52
52
|
"exports": {
|
|
53
53
|
".": {
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"dev": "build-package --watch",
|
|
70
70
|
"build": "build-package",
|
|
71
71
|
"build:args": "generate-arg-types './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.ts\"",
|
|
72
|
-
"dts": "tsc
|
|
73
|
-
"typecheck": "tsc --noEmit",
|
|
72
|
+
"dts": "tsc",
|
|
73
|
+
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
|
|
74
74
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
|
|
75
75
|
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
|
|
76
76
|
"checks": "pnpm typecheck && pnpm lint && pnpm test",
|
|
@@ -23,16 +23,15 @@ export const Image = forwardRef<ElementRef<typeof defaultTag>, Props>(
|
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
25
|
if (asset.location === "REMOTE") {
|
|
26
|
-
return loaders.cloudflareImageLoader(
|
|
26
|
+
return loaders.cloudflareImageLoader({
|
|
27
|
+
resizeOrigin: params.resizeOrigin,
|
|
28
|
+
cdnUrl: params.assetBaseUrl,
|
|
29
|
+
});
|
|
27
30
|
}
|
|
28
|
-
return loaders.localImageLoader(params);
|
|
31
|
+
return loaders.localImageLoader({ publicPath: params.assetBaseUrl });
|
|
29
32
|
}, [asset, params]);
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (asset != null) {
|
|
34
|
-
src = asset.path;
|
|
35
|
-
}
|
|
34
|
+
const src = asset?.name ?? props.src;
|
|
36
35
|
|
|
37
36
|
if (asset == null || loader == null) {
|
|
38
37
|
return <SdkImage key={src} {...props} src={src} ref={ref} />;
|
|
@@ -11,11 +11,11 @@ export const wrapLinkComponent = (BaseLink: LinkComponent) => {
|
|
|
11
11
|
const Component: LinkComponent = forwardRef((props: LinkProps, ref) => {
|
|
12
12
|
const href = usePropUrl(getInstanceIdFromComponentProps(props), "href");
|
|
13
13
|
|
|
14
|
-
if (
|
|
15
|
-
return <
|
|
14
|
+
if (href?.type === "page") {
|
|
15
|
+
return <RemixLink {...props} to={href.page.path} ref={ref} />;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return <
|
|
18
|
+
return <BaseLink {...props} ref={ref} />;
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
Component.displayName = BaseLink.displayName;
|
package/src/app/params.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export type Params = {
|
|
2
2
|
resizeOrigin?: string;
|
|
3
|
-
|
|
3
|
+
assetBaseUrl: string;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
-
let params:
|
|
6
|
+
let params: undefined | Params;
|
|
7
7
|
|
|
8
|
-
const emptyParams: Params = {
|
|
8
|
+
const emptyParams: Params = {
|
|
9
|
+
assetBaseUrl: "/",
|
|
10
|
+
};
|
|
9
11
|
|
|
10
12
|
export const getParams = (): Params => params ?? emptyParams;
|
|
11
13
|
|
|
12
|
-
export const setParams = (newParams:
|
|
14
|
+
export const setParams = (newParams: undefined | Params) => {
|
|
13
15
|
params = newParams;
|
|
14
16
|
};
|