@webstudio-is/react-sdk 0.57.0 → 0.59.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/shared/remix-link.js +5 -1
- package/lib/cjs/app/custom-components/shared/remix-link.js +5 -1
- package/lib/cjs/components/component-meta.js +6 -0
- package/lib/cjs/components/link-block.ws.js +1 -0
- package/lib/cjs/components/link.js +4 -1
- package/lib/cjs/components/link.ws.js +1 -0
- package/lib/cjs/props.js +19 -5
- package/lib/components/component-meta.js +6 -0
- package/lib/components/link-block.ws.js +2 -1
- package/lib/components/link.js +4 -1
- package/lib/components/link.ws.js +1 -0
- package/lib/props.js +19 -5
- package/lib/types/app/custom-components/image.d.ts +6 -0
- package/lib/types/app/custom-components/index.d.ts +26 -0
- package/lib/types/app/custom-components/link-block.d.ts +6 -0
- package/lib/types/app/custom-components/link.d.ts +6 -0
- package/lib/types/app/custom-components/rich-text-link.d.ts +6 -0
- package/lib/types/app/custom-components/shared/remix-link.d.ts +10 -0
- package/lib/types/app/handle-request.server.d.ts +2 -0
- package/lib/types/app/index.d.ts +3 -0
- package/lib/types/app/params.d.ts +6 -0
- package/lib/types/app/root.d.ts +8 -0
- package/lib/types/components/__generated__/blockquote.props.d.ts +2 -0
- package/lib/types/components/__generated__/body.props.d.ts +2 -0
- package/lib/types/components/__generated__/bold.props.d.ts +2 -0
- package/lib/types/components/__generated__/box.props.d.ts +2 -0
- package/lib/types/components/__generated__/button.props.d.ts +2 -0
- package/lib/types/components/__generated__/code.props.d.ts +2 -0
- package/lib/types/components/__generated__/form.props.d.ts +2 -0
- package/lib/types/components/__generated__/fragment.props.d.ts +2 -0
- package/lib/types/components/__generated__/heading.props.d.ts +2 -0
- package/lib/types/components/__generated__/image.props.d.ts +2 -0
- package/lib/types/components/__generated__/input.props.d.ts +2 -0
- package/lib/types/components/__generated__/italic.props.d.ts +2 -0
- package/lib/types/components/__generated__/link-block.props.d.ts +2 -0
- package/lib/types/components/__generated__/link.props.d.ts +2 -0
- package/lib/types/components/__generated__/list-item.props.d.ts +2 -0
- package/lib/types/components/__generated__/list.props.d.ts +2 -0
- package/lib/types/components/__generated__/paragraph.props.d.ts +2 -0
- package/lib/types/components/__generated__/rich-text-link.props.d.ts +2 -0
- package/lib/types/components/__generated__/separator.props.d.ts +2 -0
- package/lib/types/components/__generated__/slot.props.d.ts +2 -0
- package/lib/types/components/__generated__/span.props.d.ts +2 -0
- package/lib/types/components/__generated__/subscript.props.d.ts +2 -0
- package/lib/types/components/__generated__/superscript.props.d.ts +2 -0
- package/lib/types/components/__generated__/text-block.props.d.ts +2 -0
- package/lib/types/components/blockquote.d.ts +3 -0
- package/lib/types/components/blockquote.stories.d.ts +5 -0
- package/lib/types/components/blockquote.ws.d.ts +3 -0
- package/lib/types/components/body.d.ts +3 -0
- package/lib/types/components/body.stories.d.ts +6 -0
- package/lib/types/components/body.ws.d.ts +3 -0
- package/lib/types/components/bold.d.ts +3 -0
- package/lib/types/components/bold.stories.d.ts +5 -0
- package/lib/types/components/bold.ws.d.ts +3 -0
- package/lib/types/components/box.d.ts +7 -0
- package/lib/types/components/box.stories.d.ts +9 -0
- package/lib/types/components/box.ws.d.ts +3 -0
- package/lib/types/components/button.d.ts +7 -0
- package/lib/types/components/button.stories.d.ts +9 -0
- package/lib/types/components/button.ws.d.ts +3 -0
- package/lib/types/components/code.d.ts +9 -0
- package/lib/types/components/code.stories.d.ts +11 -0
- package/lib/types/components/code.ws.d.ts +3 -0
- package/lib/types/components/component-meta.d.ts +639 -0
- package/lib/types/components/components-utils.d.ts +34 -0
- package/lib/types/components/components.d.ts +31 -0
- package/lib/types/components/form.d.ts +3 -0
- package/lib/types/components/form.stories.d.ts +5 -0
- package/lib/types/components/form.ws.d.ts +3 -0
- package/lib/types/components/fragment.d.ts +6 -0
- package/lib/types/components/fragment.ws.d.ts +3 -0
- package/lib/types/components/heading.d.ts +7 -0
- package/lib/types/components/heading.stories.d.ts +9 -0
- package/lib/types/components/heading.ws.d.ts +3 -0
- package/lib/types/components/image.d.ts +3 -0
- package/lib/types/components/image.stories.d.ts +5 -0
- package/lib/types/components/image.ws.d.ts +3 -0
- package/lib/types/components/index.d.ts +17 -0
- package/lib/types/components/input.d.ts +3 -0
- package/lib/types/components/input.stories.d.ts +5 -0
- package/lib/types/components/input.ws.d.ts +3 -0
- package/lib/types/components/italic.d.ts +3 -0
- package/lib/types/components/italic.stories.d.ts +5 -0
- package/lib/types/components/italic.ws.d.ts +3 -0
- package/lib/types/components/link-block.d.ts +3 -0
- package/lib/types/components/link-block.stories.d.ts +13 -0
- package/lib/types/components/link-block.ws.d.ts +3 -0
- package/lib/types/components/link.d.ts +9 -0
- package/lib/types/components/link.stories.d.ts +13 -0
- package/lib/types/components/link.ws.d.ts +3 -0
- package/lib/types/components/list-item.d.ts +3 -0
- package/lib/types/components/list-item.stories.d.ts +5 -0
- package/lib/types/components/list-item.ws.d.ts +3 -0
- package/lib/types/components/list.d.ts +9 -0
- package/lib/types/components/list.stories.d.ts +9 -0
- package/lib/types/components/list.ws.d.ts +3 -0
- package/lib/types/components/paragraph.d.ts +3 -0
- package/lib/types/components/paragraph.stories.d.ts +5 -0
- package/lib/types/components/paragraph.ws.d.ts +3 -0
- package/lib/types/components/rich-text-link.d.ts +2 -0
- package/lib/types/components/rich-text-link.stories.d.ts +13 -0
- package/lib/types/components/rich-text-link.ws.d.ts +3 -0
- package/lib/types/components/separator.d.ts +3 -0
- package/lib/types/components/separator.stories.d.ts +5 -0
- package/lib/types/components/separator.ws.d.ts +3 -0
- package/lib/types/components/slot.d.ts +6 -0
- package/lib/types/components/slot.stories.d.ts +9 -0
- package/lib/types/components/slot.ws.d.ts +3 -0
- package/lib/types/components/span.d.ts +3 -0
- package/lib/types/components/span.stories.d.ts +5 -0
- package/lib/types/components/span.ws.d.ts +3 -0
- package/lib/types/components/subscript.d.ts +3 -0
- package/lib/types/components/subscript.stories.d.ts +5 -0
- package/lib/types/components/subscript.ws.d.ts +3 -0
- package/lib/types/components/superscript.d.ts +3 -0
- package/lib/types/components/superscript.stories.d.ts +5 -0
- package/lib/types/components/superscript.ws.d.ts +3 -0
- package/lib/types/components/text-block.d.ts +3 -0
- package/lib/types/components/text-block.stories.d.ts +5 -0
- package/lib/types/components/text-block.ws.d.ts +3 -0
- package/lib/types/context.d.ts +9 -0
- package/lib/types/css/css.d.ts +52 -0
- package/lib/types/css/get-browser-style.d.ts +2 -0
- package/lib/types/css/global-rules.d.ts +43 -0
- package/lib/types/css/index.d.ts +4 -0
- package/lib/types/css/normalize-type-check.d.ts +1 -0
- package/lib/types/css/normalize.d.ts +2429 -0
- package/lib/types/css/presets.d.ts +38 -0
- package/lib/types/css/style-rules.d.ts +202 -0
- package/lib/types/css/style-rules.test.d.ts +1 -0
- package/lib/types/index.d.ts +9 -0
- package/lib/types/props.d.ts +158 -0
- package/lib/types/props.test.d.ts +1 -0
- package/lib/types/pubsub/create.d.ts +28 -0
- package/lib/types/pubsub/index.d.ts +1 -0
- package/lib/types/pubsub/raf-queue.d.ts +1 -0
- package/lib/types/tree/create-elements-tree.d.ts +29 -0
- package/lib/types/tree/index.d.ts +3 -0
- package/lib/types/tree/root.d.ts +25 -0
- package/lib/types/tree/session-storage-polyfill.d.ts +2 -0
- package/lib/types/tree/webstudio-component.d.ts +15 -0
- package/package.json +14 -14
- package/src/app/custom-components/shared/remix-link.tsx +5 -1
- package/src/components/component-meta.ts +8 -0
- package/src/components/link-block.ws.tsx +2 -1
- package/src/components/link.tsx +5 -1
- package/src/components/link.ws.tsx +1 -0
- package/src/index.ts +1 -0
- package/src/props.test.ts +36 -1
- package/src/props.ts +33 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BoxLinkIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
|
|
3
3
|
import { props } from "./__generated__/link-block.props";
|
|
4
|
-
import { propsMeta as linkPropsMeta } from "./link.ws";
|
|
4
|
+
import { meta as linkMeta, propsMeta as linkPropsMeta } from "./link.ws";
|
|
5
5
|
import type { defaultTag } from "./link-block";
|
|
6
6
|
import type { Style } from "@webstudio-is/css-data";
|
|
7
7
|
import { a } from "../css/normalize";
|
|
@@ -21,6 +21,7 @@ export const meta: WsComponentMeta = {
|
|
|
21
21
|
type: "container",
|
|
22
22
|
label: "Link Block",
|
|
23
23
|
Icon: BoxLinkIcon,
|
|
24
|
+
states: linkMeta.states,
|
|
24
25
|
presetStyle,
|
|
25
26
|
};
|
|
26
27
|
|
package/src/components/link.tsx
CHANGED
|
@@ -19,10 +19,14 @@ export const Link = forwardRef<HTMLAnchorElement, Props>((props, ref) => {
|
|
|
19
19
|
|
|
20
20
|
const { assetBaseUrl } = getParams();
|
|
21
21
|
|
|
22
|
-
let url
|
|
22
|
+
let url = "#";
|
|
23
|
+
|
|
23
24
|
switch (href?.type) {
|
|
24
25
|
case "page":
|
|
25
26
|
url = href.page.path;
|
|
27
|
+
if (href.hash !== undefined) {
|
|
28
|
+
url += `#${href.hash}`;
|
|
29
|
+
}
|
|
26
30
|
break;
|
|
27
31
|
case "asset":
|
|
28
32
|
url = `${assetBaseUrl}${href.asset.name}`;
|
package/src/index.ts
CHANGED
package/src/props.test.ts
CHANGED
|
@@ -56,6 +56,22 @@ describe("resolveUrlProp", () => {
|
|
|
56
56
|
value: page1.id,
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
const instnaceIdProp: Prop = {
|
|
60
|
+
type: "string",
|
|
61
|
+
id: unique(),
|
|
62
|
+
instanceId: unique(),
|
|
63
|
+
name: "id",
|
|
64
|
+
value: unique(),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const pageSectionProp: Prop = {
|
|
68
|
+
type: "page",
|
|
69
|
+
id: unique(),
|
|
70
|
+
instanceId,
|
|
71
|
+
name: unique(),
|
|
72
|
+
value: { pageId: page1.id, instanceId: instnaceIdProp.instanceId },
|
|
73
|
+
};
|
|
74
|
+
|
|
59
75
|
const pageByPathProp: Prop = {
|
|
60
76
|
type: "string",
|
|
61
77
|
id: unique(),
|
|
@@ -73,7 +89,17 @@ describe("resolveUrlProp", () => {
|
|
|
73
89
|
};
|
|
74
90
|
|
|
75
91
|
const props: PropsByInstanceId = new Map([
|
|
76
|
-
[
|
|
92
|
+
[
|
|
93
|
+
instanceId,
|
|
94
|
+
[
|
|
95
|
+
pageByIdProp,
|
|
96
|
+
pageByPathProp,
|
|
97
|
+
arbitraryUrlProp,
|
|
98
|
+
assetProp,
|
|
99
|
+
pageSectionProp,
|
|
100
|
+
],
|
|
101
|
+
],
|
|
102
|
+
[instnaceIdProp.instanceId, [instnaceIdProp]],
|
|
77
103
|
]);
|
|
78
104
|
|
|
79
105
|
const pages: Pages = new Map([
|
|
@@ -116,6 +142,15 @@ describe("resolveUrlProp", () => {
|
|
|
116
142
|
});
|
|
117
143
|
});
|
|
118
144
|
|
|
145
|
+
test("section on a page", () => {
|
|
146
|
+
expect(resolveUrlProp(instanceId, pageSectionProp.name, stores)).toEqual({
|
|
147
|
+
type: "page",
|
|
148
|
+
page: page1,
|
|
149
|
+
instanceId: instnaceIdProp.instanceId,
|
|
150
|
+
hash: instnaceIdProp.value,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
119
154
|
test("arbitrary url", () => {
|
|
120
155
|
expect(resolveUrlProp(instanceId, arbitraryUrlProp.name, stores)).toEqual({
|
|
121
156
|
type: "string",
|
package/src/props.ts
CHANGED
|
@@ -32,7 +32,7 @@ export const useInstanceProps = (instanceId: Instance["id"]) => {
|
|
|
32
32
|
const instancePropsObject: Record<Prop["name"], Prop["value"]> = {};
|
|
33
33
|
if (instanceProps) {
|
|
34
34
|
for (const prop of instanceProps) {
|
|
35
|
-
if (prop.type !== "asset") {
|
|
35
|
+
if (prop.type !== "asset" && prop.type !== "page") {
|
|
36
36
|
instancePropsObject[prop.name] = prop.value;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -74,7 +74,12 @@ export const resolveUrlProp = (
|
|
|
74
74
|
assets,
|
|
75
75
|
}: { props: PropsByInstanceId; pages: Pages; assets: Assets }
|
|
76
76
|
):
|
|
77
|
-
| {
|
|
77
|
+
| {
|
|
78
|
+
type: "page";
|
|
79
|
+
page: Page;
|
|
80
|
+
instanceId?: Instance["id"];
|
|
81
|
+
hash?: string;
|
|
82
|
+
}
|
|
78
83
|
| { type: "asset"; asset: Asset }
|
|
79
84
|
| { type: "string"; url: string }
|
|
80
85
|
| undefined => {
|
|
@@ -88,8 +93,30 @@ export const resolveUrlProp = (
|
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
if (prop.type === "page") {
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
if (typeof prop.value === "string") {
|
|
97
|
+
const page = pages.get(prop.value);
|
|
98
|
+
return page && { type: "page", page };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const { instanceId, pageId } = prop.value;
|
|
102
|
+
|
|
103
|
+
const page = pages.get(pageId);
|
|
104
|
+
|
|
105
|
+
if (page === undefined) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const idProp = props.get(instanceId)?.find((prop) => prop.name === "id");
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
type: "page",
|
|
113
|
+
page,
|
|
114
|
+
instanceId,
|
|
115
|
+
hash:
|
|
116
|
+
idProp === undefined || idProp.type !== "string"
|
|
117
|
+
? undefined
|
|
118
|
+
: idProp.value,
|
|
119
|
+
};
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
if (prop.type === "string") {
|
|
@@ -115,7 +142,7 @@ export const resolveUrlProp = (
|
|
|
115
142
|
export const usePropUrl = (instanceId: Instance["id"], name: string) => {
|
|
116
143
|
const { propsByInstanceIdStore, pagesStore, assetsStore } =
|
|
117
144
|
useContext(ReactSdkContext);
|
|
118
|
-
const
|
|
145
|
+
const store = useMemo(
|
|
119
146
|
() =>
|
|
120
147
|
computed(
|
|
121
148
|
[propsByInstanceIdStore, pagesStore, assetsStore],
|
|
@@ -124,7 +151,7 @@ export const usePropUrl = (instanceId: Instance["id"], name: string) => {
|
|
|
124
151
|
),
|
|
125
152
|
[propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
|
|
126
153
|
);
|
|
127
|
-
return useStore(
|
|
154
|
+
return useStore(store);
|
|
128
155
|
};
|
|
129
156
|
|
|
130
157
|
export const getInstanceIdFromComponentProps = (
|