@webstudio-is/react-sdk 0.56.0 → 0.58.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 +7 -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 +7 -3
- package/lib/cjs/app/params.js +4 -2
- package/lib/cjs/components/link.js +17 -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 +35 -12
- package/lib/cjs/pubsub/raf-queue.js +3 -6
- package/lib/cjs/tree/root.js +1 -1
- package/lib/components/link.js +17 -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 +35 -12
- package/lib/pubsub/raf-queue.js +3 -6
- package/lib/tree/root.js +1 -1
- package/lib/types/app/custom-components/image.d.ts +2 -2
- package/lib/types/app/custom-components/index.d.ts +8 -8
- package/lib/types/app/custom-components/link-block.d.ts +2 -2
- package/lib/types/app/custom-components/link.d.ts +2 -2
- package/lib/types/app/custom-components/rich-text-link.d.ts +2 -2
- package/lib/types/app/custom-components/shared/remix-link.d.ts +3 -3
- package/lib/types/app/params.d.ts +2 -2
- package/lib/types/components/blockquote.d.ts +1 -1
- package/lib/types/components/blockquote.stories.d.ts +2 -2
- package/lib/types/components/body.d.ts +1 -1
- package/lib/types/components/body.stories.d.ts +1 -1
- package/lib/types/components/bold.d.ts +1 -1
- package/lib/types/components/bold.stories.d.ts +2 -2
- package/lib/types/components/box.d.ts +1 -1
- package/lib/types/components/box.stories.d.ts +4 -4
- package/lib/types/components/button.d.ts +1 -1
- package/lib/types/components/button.stories.d.ts +4 -4
- package/lib/types/components/code.d.ts +1 -1
- package/lib/types/components/code.stories.d.ts +4 -4
- package/lib/types/components/components-utils.d.ts +7 -7
- package/lib/types/components/form.d.ts +1 -1
- package/lib/types/components/form.stories.d.ts +2 -2
- package/lib/types/components/heading.d.ts +1 -1
- package/lib/types/components/heading.stories.d.ts +4 -4
- package/lib/types/components/image.d.ts +1 -1
- package/lib/types/components/image.stories.d.ts +2 -2
- package/lib/types/components/input.d.ts +1 -1
- package/lib/types/components/input.stories.d.ts +2 -2
- package/lib/types/components/italic.d.ts +1 -1
- package/lib/types/components/italic.stories.d.ts +2 -2
- package/lib/types/components/link-block.stories.d.ts +4 -4
- package/lib/types/components/link.d.ts +1 -1
- package/lib/types/components/link.stories.d.ts +4 -4
- package/lib/types/components/list-item.d.ts +1 -1
- package/lib/types/components/list-item.stories.d.ts +2 -2
- package/lib/types/components/list.d.ts +1 -1
- package/lib/types/components/list.stories.d.ts +4 -4
- package/lib/types/components/paragraph.d.ts +1 -1
- package/lib/types/components/paragraph.stories.d.ts +2 -2
- package/lib/types/components/rich-text-link.stories.d.ts +4 -4
- package/lib/types/components/separator.d.ts +1 -1
- package/lib/types/components/separator.stories.d.ts +2 -2
- package/lib/types/components/span.d.ts +1 -1
- package/lib/types/components/span.stories.d.ts +2 -2
- package/lib/types/components/subscript.d.ts +1 -1
- package/lib/types/components/subscript.stories.d.ts +2 -2
- package/lib/types/components/superscript.d.ts +1 -1
- package/lib/types/components/superscript.stories.d.ts +2 -2
- package/lib/types/components/text-block.d.ts +1 -1
- package/lib/types/components/text-block.stories.d.ts +2 -2
- package/lib/types/css/css.d.ts +1 -3
- package/lib/types/css/global-rules.d.ts +2 -3
- package/lib/types/css/style-rules.d.ts +1 -0
- package/lib/types/props.d.ts +73 -12
- package/lib/types/tree/webstudio-component.d.ts +2 -2
- package/package.json +21 -21
- package/src/app/custom-components/image.tsx +6 -7
- package/src/app/custom-components/shared/remix-link.tsx +7 -3
- package/src/app/params.ts +6 -4
- package/src/components/link.tsx +21 -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 +85 -20
- package/src/props.ts +57 -15
- 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
|
@@ -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,14 @@ 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
|
-
|
|
8
|
+
if (href?.type === "page") {
|
|
9
|
+
let to = href.page.path;
|
|
10
|
+
if (href.hash !== void 0) {
|
|
11
|
+
to += `#${href.hash}`;
|
|
12
|
+
}
|
|
13
|
+
return /* @__PURE__ */ jsx(RemixLink, { ...props, to, ref });
|
|
10
14
|
}
|
|
11
|
-
return /* @__PURE__ */ jsx(
|
|
15
|
+
return /* @__PURE__ */ jsx(BaseLink, { ...props, ref });
|
|
12
16
|
});
|
|
13
17
|
Component.displayName = BaseLink.displayName;
|
|
14
18
|
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,14 @@ 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
|
-
|
|
31
|
+
if (href?.type === "page") {
|
|
32
|
+
let to = href.page.path;
|
|
33
|
+
if (href.hash !== void 0) {
|
|
34
|
+
to += `#${href.hash}`;
|
|
35
|
+
}
|
|
36
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Link, { ...props, to, ref });
|
|
33
37
|
}
|
|
34
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
38
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BaseLink, { ...props, ref });
|
|
35
39
|
});
|
|
36
40
|
Component.displayName = BaseLink.displayName;
|
|
37
41
|
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,25 @@ 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
|
+
if (href.hash !== void 0) {
|
|
38
|
+
url += `#${href.hash}`;
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case "asset":
|
|
42
|
+
url = `${assetBaseUrl}${href.asset.name}`;
|
|
43
|
+
break;
|
|
44
|
+
case "string":
|
|
45
|
+
url = href.url;
|
|
46
|
+
}
|
|
47
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props, href: url, ref });
|
|
39
48
|
});
|
|
40
49
|
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
|
@@ -50,7 +50,7 @@ const useInstanceProps = (instanceId) => {
|
|
|
50
50
|
const instancePropsObject = {};
|
|
51
51
|
if (instanceProps) {
|
|
52
52
|
for (const prop of instanceProps) {
|
|
53
|
-
if (prop.type !== "asset") {
|
|
53
|
+
if (prop.type !== "asset" && prop.type !== "page") {
|
|
54
54
|
instancePropsObject[prop.name] = prop.value;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -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,29 +93,48 @@ const resolveUrlProp = (instanceId, name, propsByInstanceId, pages) => {
|
|
|
89
93
|
continue;
|
|
90
94
|
}
|
|
91
95
|
if (prop.type === "page") {
|
|
92
|
-
|
|
96
|
+
if (typeof prop.value === "string") {
|
|
97
|
+
const page2 = pages.get(prop.value);
|
|
98
|
+
return page2 && { type: "page", page: page2 };
|
|
99
|
+
}
|
|
100
|
+
const { instanceId: instanceId2, pageId } = prop.value;
|
|
101
|
+
const page = pages.get(pageId);
|
|
102
|
+
if (page === void 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const idProp = props.get(instanceId2)?.find((prop2) => prop2.name === "id");
|
|
106
|
+
return {
|
|
107
|
+
type: "page",
|
|
108
|
+
page,
|
|
109
|
+
instanceId: instanceId2,
|
|
110
|
+
hash: idProp === void 0 || idProp.type !== "string" ? void 0 : idProp.value
|
|
111
|
+
};
|
|
93
112
|
}
|
|
94
113
|
if (prop.type === "string") {
|
|
95
114
|
for (const page of pages.values()) {
|
|
96
115
|
if (page.path === prop.value) {
|
|
97
|
-
return page;
|
|
116
|
+
return { type: "page", page };
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
|
-
return prop.value;
|
|
119
|
+
return { type: "string", url: prop.value };
|
|
120
|
+
}
|
|
121
|
+
if (prop.type === "asset") {
|
|
122
|
+
const asset = assets.get(prop.value);
|
|
123
|
+
return asset && { type: "asset", asset };
|
|
101
124
|
}
|
|
102
125
|
return;
|
|
103
126
|
}
|
|
104
127
|
};
|
|
105
128
|
const usePropUrl = (instanceId, name) => {
|
|
106
|
-
const { propsByInstanceIdStore, pagesStore } = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
107
|
-
const
|
|
129
|
+
const { propsByInstanceIdStore, pagesStore, assetsStore } = (0, import_react.useContext)(import_context.ReactSdkContext);
|
|
130
|
+
const store = (0, import_react.useMemo)(
|
|
108
131
|
() => (0, import_nanostores.computed)(
|
|
109
|
-
[propsByInstanceIdStore, pagesStore],
|
|
110
|
-
(
|
|
132
|
+
[propsByInstanceIdStore, pagesStore, assetsStore],
|
|
133
|
+
(props, pages, assets) => resolveUrlProp(instanceId, name, { props, pages, assets })
|
|
111
134
|
),
|
|
112
|
-
[propsByInstanceIdStore, pagesStore, instanceId, name]
|
|
135
|
+
[propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
|
|
113
136
|
);
|
|
114
|
-
return (0, import_react2.useStore)(
|
|
137
|
+
return (0, import_react2.useStore)(store);
|
|
115
138
|
};
|
|
116
139
|
const getInstanceIdFromComponentProps = (props) => {
|
|
117
140
|
return props[import_webstudio_component.idAttribute];
|
|
@@ -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,26 @@
|
|
|
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
|
+
if (href.hash !== void 0) {
|
|
14
|
+
url += `#${href.hash}`;
|
|
15
|
+
}
|
|
16
|
+
break;
|
|
17
|
+
case "asset":
|
|
18
|
+
url = `${assetBaseUrl}${href.asset.name}`;
|
|
19
|
+
break;
|
|
20
|
+
case "string":
|
|
21
|
+
url = href.url;
|
|
22
|
+
}
|
|
23
|
+
return /* @__PURE__ */ jsx("a", { ...props, href: url, ref });
|
|
15
24
|
});
|
|
16
25
|
Link.displayName = "Link";
|
|
17
26
|
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
|
@@ -22,7 +22,7 @@ const useInstanceProps = (instanceId) => {
|
|
|
22
22
|
const instancePropsObject = {};
|
|
23
23
|
if (instanceProps) {
|
|
24
24
|
for (const prop of instanceProps) {
|
|
25
|
-
if (prop.type !== "asset") {
|
|
25
|
+
if (prop.type !== "asset" && prop.type !== "page") {
|
|
26
26
|
instancePropsObject[prop.name] = prop.value;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -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,29 +65,48 @@ const resolveUrlProp = (instanceId, name, propsByInstanceId, pages) => {
|
|
|
61
65
|
continue;
|
|
62
66
|
}
|
|
63
67
|
if (prop.type === "page") {
|
|
64
|
-
|
|
68
|
+
if (typeof prop.value === "string") {
|
|
69
|
+
const page2 = pages.get(prop.value);
|
|
70
|
+
return page2 && { type: "page", page: page2 };
|
|
71
|
+
}
|
|
72
|
+
const { instanceId: instanceId2, pageId } = prop.value;
|
|
73
|
+
const page = pages.get(pageId);
|
|
74
|
+
if (page === void 0) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const idProp = props.get(instanceId2)?.find((prop2) => prop2.name === "id");
|
|
78
|
+
return {
|
|
79
|
+
type: "page",
|
|
80
|
+
page,
|
|
81
|
+
instanceId: instanceId2,
|
|
82
|
+
hash: idProp === void 0 || idProp.type !== "string" ? void 0 : idProp.value
|
|
83
|
+
};
|
|
65
84
|
}
|
|
66
85
|
if (prop.type === "string") {
|
|
67
86
|
for (const page of pages.values()) {
|
|
68
87
|
if (page.path === prop.value) {
|
|
69
|
-
return page;
|
|
88
|
+
return { type: "page", page };
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
|
-
return prop.value;
|
|
91
|
+
return { type: "string", url: prop.value };
|
|
92
|
+
}
|
|
93
|
+
if (prop.type === "asset") {
|
|
94
|
+
const asset = assets.get(prop.value);
|
|
95
|
+
return asset && { type: "asset", asset };
|
|
73
96
|
}
|
|
74
97
|
return;
|
|
75
98
|
}
|
|
76
99
|
};
|
|
77
100
|
const usePropUrl = (instanceId, name) => {
|
|
78
|
-
const { propsByInstanceIdStore, pagesStore } = useContext(ReactSdkContext);
|
|
79
|
-
const
|
|
101
|
+
const { propsByInstanceIdStore, pagesStore, assetsStore } = useContext(ReactSdkContext);
|
|
102
|
+
const store = useMemo(
|
|
80
103
|
() => computed(
|
|
81
|
-
[propsByInstanceIdStore, pagesStore],
|
|
82
|
-
(
|
|
104
|
+
[propsByInstanceIdStore, pagesStore, assetsStore],
|
|
105
|
+
(props, pages, assets) => resolveUrlProp(instanceId, name, { props, pages, assets })
|
|
83
106
|
),
|
|
84
|
-
[propsByInstanceIdStore, pagesStore, instanceId, name]
|
|
107
|
+
[propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
|
|
85
108
|
);
|
|
86
|
-
return useStore(
|
|
109
|
+
return useStore(store);
|
|
87
110
|
};
|
|
88
111
|
const getInstanceIdFromComponentProps = (props) => {
|
|
89
112
|
return props[idAttribute];
|
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),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare const Image: import("react").ForwardRefExoticComponent<
|
|
2
|
+
export declare const Image: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").ClassAttributes<HTMLImageElement> & import("react").ImgHTMLAttributes<HTMLImageElement> & {
|
|
3
3
|
quality?: number | undefined;
|
|
4
4
|
optimize?: boolean | undefined;
|
|
5
5
|
loader: import("@webstudio-is/image").ImageLoader;
|
|
6
|
-
}, "
|
|
6
|
+
}, "ref"> & import("react").RefAttributes<HTMLImageElement>, "ref"> & import("react").RefAttributes<HTMLImageElement>>;
|