@webstudio-is/react-sdk 0.35.0 → 0.36.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 +1 -1
- package/lib/app/custom-components/index.js +1 -6
- package/lib/cjs/app/custom-components/image.cjs +2 -2
- package/lib/cjs/app/custom-components/index.cjs +1 -6
- package/lib/cjs/components/__generated__/blockquote.props.cjs +414 -0
- package/lib/cjs/components/__generated__/body.props.cjs +413 -0
- package/lib/cjs/components/__generated__/bold.props.cjs +413 -0
- package/lib/cjs/components/__generated__/box.props.cjs +431 -0
- package/lib/cjs/components/__generated__/button.props.cjs +430 -0
- package/lib/cjs/components/__generated__/code.props.cjs +420 -0
- package/lib/cjs/components/__generated__/form.props.cjs +421 -0
- package/lib/cjs/components/__generated__/heading.props.cjs +420 -0
- package/lib/cjs/components/__generated__/image.props.cjs +454 -0
- package/lib/cjs/components/__generated__/input.props.cjs +451 -0
- package/lib/cjs/components/__generated__/italic.props.cjs +413 -0
- package/lib/cjs/components/__generated__/link.props.cjs +437 -0
- package/lib/cjs/components/__generated__/list-item.props.cjs +414 -0
- package/lib/cjs/components/__generated__/list.props.cjs +427 -0
- package/lib/cjs/components/__generated__/paragraph.props.cjs +413 -0
- package/lib/cjs/components/__generated__/rich-text-link.props.cjs +437 -0
- package/lib/cjs/components/__generated__/separator.props.cjs +413 -0
- package/lib/cjs/components/__generated__/span.props.cjs +413 -0
- package/lib/cjs/components/__generated__/subscript.props.cjs +413 -0
- package/lib/cjs/components/__generated__/superscript.props.cjs +413 -0
- package/lib/cjs/components/__generated__/text-block.props.cjs +413 -0
- package/lib/cjs/components/blockquote.cjs +31 -0
- package/lib/cjs/components/blockquote.ws.cjs +75 -0
- package/lib/cjs/components/body.ws.cjs +2 -8
- package/lib/cjs/components/bold.ws.cjs +2 -8
- package/lib/cjs/components/box.ws.cjs +2 -8
- package/lib/cjs/components/button.ws.cjs +2 -8
- package/lib/cjs/components/code.cjs +38 -0
- package/lib/cjs/components/code.ws.cjs +66 -0
- package/lib/cjs/components/components-utils.cjs +71 -0
- package/lib/cjs/components/components.cjs +64 -0
- package/lib/cjs/components/form.ws.cjs +2 -8
- package/lib/cjs/components/heading.ws.cjs +2 -8
- package/lib/cjs/components/image.ws.cjs +8 -9
- package/lib/cjs/components/index.cjs +28 -53
- package/lib/cjs/components/input.ws.cjs +2 -8
- package/lib/cjs/components/italic.ws.cjs +2 -8
- package/lib/cjs/components/link.ws.cjs +2 -8
- package/lib/cjs/components/list-item.cjs +31 -0
- package/lib/cjs/components/list-item.ws.cjs +35 -0
- package/lib/cjs/components/list.cjs +31 -0
- package/lib/cjs/components/list.ws.cjs +51 -0
- package/lib/cjs/components/paragraph.ws.cjs +2 -8
- package/lib/cjs/components/rich-text-link.ws.cjs +2 -8
- package/lib/cjs/components/separator.cjs +31 -0
- package/lib/cjs/components/separator.ws.cjs +51 -0
- package/lib/cjs/components/span.ws.cjs +2 -8
- package/lib/cjs/components/subscript.ws.cjs +2 -8
- package/lib/cjs/components/superscript.ws.cjs +2 -8
- package/lib/cjs/components/text-block.ws.cjs +2 -8
- package/lib/cjs/css/get-browser-style.cjs +13 -5
- package/lib/cjs/index.cjs +2 -0
- package/lib/cjs/tree/create-elements-tree.cjs +16 -8
- package/lib/cjs/tree/index.cjs +1 -1
- package/lib/cjs/tree/root.cjs +28 -4
- package/lib/cjs/tree/{wrapper-component.cjs → webstudio-component.cjs} +10 -10
- package/lib/components/__generated__/blockquote.props.js +394 -0
- package/lib/components/__generated__/body.props.js +393 -0
- package/lib/components/__generated__/bold.props.js +393 -0
- package/lib/components/__generated__/box.props.js +411 -0
- package/lib/components/__generated__/button.props.js +410 -0
- package/lib/components/__generated__/code.props.js +400 -0
- package/lib/components/__generated__/form.props.js +401 -0
- package/lib/components/__generated__/heading.props.js +400 -0
- package/lib/components/__generated__/image.props.js +434 -0
- package/lib/components/__generated__/input.props.js +431 -0
- package/lib/components/__generated__/italic.props.js +393 -0
- package/lib/components/__generated__/link.props.js +417 -0
- package/lib/components/__generated__/list-item.props.js +394 -0
- package/lib/components/__generated__/list.props.js +407 -0
- package/lib/components/__generated__/paragraph.props.js +393 -0
- package/lib/components/__generated__/rich-text-link.props.js +417 -0
- package/lib/components/__generated__/separator.props.js +393 -0
- package/lib/components/__generated__/span.props.js +393 -0
- package/lib/components/__generated__/subscript.props.js +393 -0
- package/lib/components/__generated__/superscript.props.js +393 -0
- package/lib/components/__generated__/text-block.props.js +393 -0
- package/lib/components/blockquote.js +14 -0
- package/lib/components/blockquote.ws.js +55 -0
- package/lib/components/body.ws.js +1 -1
- package/lib/components/bold.ws.js +1 -1
- package/lib/components/box.ws.js +1 -1
- package/lib/components/button.ws.js +1 -1
- package/lib/components/code.js +21 -0
- package/lib/components/code.ws.js +46 -0
- package/lib/components/components-utils.js +45 -0
- package/lib/components/components.js +44 -0
- package/lib/components/form.ws.js +1 -1
- package/lib/components/heading.ws.js +1 -1
- package/lib/components/image.ws.js +7 -2
- package/lib/components/index.js +28 -53
- package/lib/components/input.ws.js +1 -1
- package/lib/components/italic.ws.js +1 -1
- package/lib/components/link.ws.js +1 -1
- package/lib/components/list-item.js +14 -0
- package/lib/components/list-item.ws.js +15 -0
- package/lib/components/list.js +14 -0
- package/lib/components/list.ws.js +31 -0
- package/lib/components/paragraph.ws.js +1 -1
- package/lib/components/rich-text-link.ws.js +1 -1
- package/lib/components/separator.js +14 -0
- package/lib/components/separator.ws.js +31 -0
- package/lib/components/span.ws.js +1 -1
- package/lib/components/subscript.ws.js +1 -1
- package/lib/components/superscript.ws.js +1 -1
- package/lib/components/text-block.ws.js +1 -1
- package/lib/css/get-browser-style.js +9 -1
- package/lib/index.js +2 -0
- package/lib/tree/create-elements-tree.js +16 -8
- package/lib/tree/index.js +1 -1
- package/lib/tree/root.js +28 -4
- package/lib/tree/{wrapper-component.js → webstudio-component.js} +6 -6
- package/package.json +14 -11
- package/src/app/custom-components/image.tsx +1 -1
- package/src/app/custom-components/index.ts +2 -7
- package/src/components/__generated__/blockquote.props.ts +439 -0
- package/src/components/__generated__/body.props.ts +438 -0
- package/src/components/__generated__/bold.props.ts +438 -0
- package/src/components/__generated__/box.props.ts +456 -0
- package/src/components/__generated__/button.props.ts +455 -0
- package/src/components/__generated__/code.props.ts +445 -0
- package/src/components/__generated__/form.props.ts +446 -0
- package/src/components/__generated__/heading.props.ts +445 -0
- package/src/components/__generated__/image.props.ts +479 -0
- package/src/components/__generated__/input.props.ts +476 -0
- package/src/components/__generated__/italic.props.ts +438 -0
- package/src/components/__generated__/link.props.ts +462 -0
- package/src/components/__generated__/list-item.props.ts +439 -0
- package/src/components/__generated__/list.props.ts +452 -0
- package/src/components/__generated__/paragraph.props.ts +438 -0
- package/src/components/__generated__/rich-text-link.props.ts +462 -0
- package/src/components/__generated__/separator.props.ts +438 -0
- package/src/components/__generated__/span.props.ts +438 -0
- package/src/components/__generated__/subscript.props.ts +438 -0
- package/src/components/__generated__/superscript.props.ts +438 -0
- package/src/components/__generated__/text-block.props.ts +438 -0
- package/src/components/blockquote.stories.tsx +16 -0
- package/src/components/blockquote.tsx +18 -0
- package/src/components/blockquote.ws.tsx +55 -0
- package/src/components/body.ws.tsx +3 -3
- package/src/components/bold.ws.tsx +3 -3
- package/src/components/box.ws.ts +3 -3
- package/src/components/button.ws.tsx +3 -3
- package/src/components/code.stories.tsx +16 -0
- package/src/components/code.tsx +31 -0
- package/src/components/code.ws.tsx +46 -0
- package/src/components/components-utils.ts +75 -0
- package/src/components/components.ts +28 -0
- package/src/components/form.ws.tsx +3 -3
- package/src/components/heading.ws.tsx +3 -3
- package/src/components/image.ws.tsx +9 -4
- package/src/components/index.ts +28 -63
- package/src/components/input.ws.tsx +3 -3
- package/src/components/italic.ws.tsx +3 -3
- package/src/components/link.ws.tsx +3 -3
- package/src/components/list-item.stories.tsx +16 -0
- package/src/components/list-item.tsx +18 -0
- package/src/components/list-item.ws.tsx +14 -0
- package/src/components/list.stories.tsx +17 -0
- package/src/components/list.tsx +24 -0
- package/src/components/list.ws.tsx +31 -0
- package/src/components/paragraph.ws.tsx +3 -3
- package/src/components/rich-text-link.ws.tsx +3 -3
- package/src/components/separator.stories.tsx +14 -0
- package/src/components/separator.tsx +18 -0
- package/src/components/separator.ws.tsx +31 -0
- package/src/components/span.ws.tsx +3 -3
- package/src/components/subscript.ws.tsx +3 -3
- package/src/components/superscript.ws.tsx +3 -3
- package/src/components/text-block.ws.tsx +3 -3
- package/src/css/get-browser-style.ts +14 -3
- package/src/index.ts +2 -0
- package/src/props.ts +1 -1
- package/src/tree/create-elements-tree.tsx +16 -4
- package/src/tree/index.ts +1 -1
- package/src/tree/root.ts +37 -5
- package/src/tree/{wrapper-component.tsx → webstudio-component.tsx} +10 -6
- package/lib/cjs/components/__generated__/body.props.json +0 -743
- package/lib/cjs/components/__generated__/bold.props.json +0 -743
- package/lib/cjs/components/__generated__/box.props.json +0 -765
- package/lib/cjs/components/__generated__/button.props.json +0 -824
- package/lib/cjs/components/__generated__/form.props.json +0 -799
- package/lib/cjs/components/__generated__/heading.props.json +0 -754
- package/lib/cjs/components/__generated__/image.props.json +0 -846
- package/lib/cjs/components/__generated__/input.props.json +0 -977
- package/lib/cjs/components/__generated__/italic.props.json +0 -743
- package/lib/cjs/components/__generated__/link.props.json +0 -820
- package/lib/cjs/components/__generated__/paragraph.props.json +0 -743
- package/lib/cjs/components/__generated__/rich-text-link.props.json +0 -820
- package/lib/cjs/components/__generated__/span.props.json +0 -743
- package/lib/cjs/components/__generated__/subscript.props.json +0 -743
- package/lib/cjs/components/__generated__/superscript.props.json +0 -743
- package/lib/cjs/components/__generated__/text-block.props.json +0 -743
- package/lib/components/__generated__/body.props.json +0 -743
- package/lib/components/__generated__/bold.props.json +0 -743
- package/lib/components/__generated__/box.props.json +0 -765
- package/lib/components/__generated__/button.props.json +0 -824
- package/lib/components/__generated__/form.props.json +0 -799
- package/lib/components/__generated__/heading.props.json +0 -754
- package/lib/components/__generated__/image.props.json +0 -846
- package/lib/components/__generated__/input.props.json +0 -977
- package/lib/components/__generated__/italic.props.json +0 -743
- package/lib/components/__generated__/link.props.json +0 -820
- package/lib/components/__generated__/paragraph.props.json +0 -743
- package/lib/components/__generated__/rich-text-link.props.json +0 -820
- package/lib/components/__generated__/span.props.json +0 -743
- package/lib/components/__generated__/subscript.props.json +0 -743
- package/lib/components/__generated__/superscript.props.json +0 -743
- package/lib/components/__generated__/text-block.props.json +0 -743
- package/src/components/__generated__/body.props.json +0 -743
- package/src/components/__generated__/bold.props.json +0 -743
- package/src/components/__generated__/box.props.json +0 -765
- package/src/components/__generated__/button.props.json +0 -824
- package/src/components/__generated__/form.props.json +0 -799
- package/src/components/__generated__/heading.props.json +0 -754
- package/src/components/__generated__/image.props.json +0 -846
- package/src/components/__generated__/input.props.json +0 -977
- package/src/components/__generated__/italic.props.json +0 -743
- package/src/components/__generated__/link.props.json +0 -820
- package/src/components/__generated__/paragraph.props.json +0 -743
- package/src/components/__generated__/rich-text-link.props.json +0 -820
- package/src/components/__generated__/span.props.json +0 -743
- package/src/components/__generated__/subscript.props.json +0 -743
- package/src/components/__generated__/superscript.props.json +0 -743
- package/src/components/__generated__/text-block.props.json +0 -743
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CodeIcon } from "@webstudio-is/icons";
|
|
2
|
+
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
+
import { displayVarNamespace } from "./code";
|
|
4
|
+
import { props } from "./__generated__/code.props";
|
|
5
|
+
|
|
6
|
+
const presetStyle: WsComponentMeta["presetStyle"] = {
|
|
7
|
+
display: {
|
|
8
|
+
type: "var",
|
|
9
|
+
value: displayVarNamespace,
|
|
10
|
+
fallbacks: [
|
|
11
|
+
{
|
|
12
|
+
type: "keyword",
|
|
13
|
+
value: "inline-block",
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
paddingLeft: {
|
|
18
|
+
type: "keyword",
|
|
19
|
+
value: "0.2em",
|
|
20
|
+
},
|
|
21
|
+
paddingRight: {
|
|
22
|
+
type: "keyword",
|
|
23
|
+
value: "0.2em",
|
|
24
|
+
},
|
|
25
|
+
backgroundColor: {
|
|
26
|
+
type: "keyword",
|
|
27
|
+
value: "#eee",
|
|
28
|
+
},
|
|
29
|
+
fontFamily: {
|
|
30
|
+
type: "keyword",
|
|
31
|
+
value: "monospace",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const meta: WsComponentMeta = {
|
|
36
|
+
type: "rich-text",
|
|
37
|
+
label: "Code",
|
|
38
|
+
Icon: CodeIcon,
|
|
39
|
+
presetStyle,
|
|
40
|
+
children: ["Code you can edit"],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
44
|
+
props,
|
|
45
|
+
initialProps: ["inline", "lang", "meta"],
|
|
46
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as components from "./components";
|
|
2
|
+
import { registeredComponents } from "./index";
|
|
3
|
+
|
|
4
|
+
export type ComponentName = keyof typeof components;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* We need to define component names manually here, instead of using Object.keys(components)
|
|
8
|
+
* Otherwise every component would be included in the bundle, even if it is not used
|
|
9
|
+
*/
|
|
10
|
+
const componentNames = Object.keys({
|
|
11
|
+
Box: 1,
|
|
12
|
+
Body: 1,
|
|
13
|
+
TextBlock: 1,
|
|
14
|
+
Heading: 1,
|
|
15
|
+
Paragraph: 1,
|
|
16
|
+
Link: 1,
|
|
17
|
+
RichTextLink: 1,
|
|
18
|
+
Span: 1,
|
|
19
|
+
Bold: 1,
|
|
20
|
+
Italic: 1,
|
|
21
|
+
Superscript: 1,
|
|
22
|
+
Subscript: 1,
|
|
23
|
+
Button: 1,
|
|
24
|
+
Input: 1,
|
|
25
|
+
Form: 1,
|
|
26
|
+
Image: 1,
|
|
27
|
+
Blockquote: 1,
|
|
28
|
+
List: 1,
|
|
29
|
+
ListItem: 1,
|
|
30
|
+
Separator: 1,
|
|
31
|
+
Code: 1,
|
|
32
|
+
} satisfies { [K in keyof typeof components]: 1 }) as Array<
|
|
33
|
+
keyof typeof components
|
|
34
|
+
>;
|
|
35
|
+
|
|
36
|
+
export const getComponentNames = (): ComponentName[] => {
|
|
37
|
+
const uniqueNames = new Set([
|
|
38
|
+
...componentNames,
|
|
39
|
+
...Object.keys(registeredComponents || {}),
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
return Array.from(uniqueNames) as ComponentName[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Now used only in builder app
|
|
47
|
+
* @todo Consider using the same approach in the builder app as in the published apps . A dynamic import is needed
|
|
48
|
+
*/
|
|
49
|
+
export const getComponent = (
|
|
50
|
+
name: string
|
|
51
|
+
): undefined | (typeof components)[ComponentName] => {
|
|
52
|
+
return registeredComponents != null && name in registeredComponents
|
|
53
|
+
? (registeredComponents[
|
|
54
|
+
name as ComponentName
|
|
55
|
+
] as (typeof components)[ComponentName])
|
|
56
|
+
: components[name as ComponentName];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The application imports only the components it uses, then pass them to createGetComponent i.e.
|
|
61
|
+
* getComponent = createGetComponent({ Box, BlaBla })
|
|
62
|
+
* <RootInstance data={data} getComponent={getComponent} />
|
|
63
|
+
* see example /packages/sdk-size-test/app/routes/$.tsx
|
|
64
|
+
**/
|
|
65
|
+
export const createGetComponent = (comps: Partial<typeof components>) => {
|
|
66
|
+
return (name: string) => {
|
|
67
|
+
return registeredComponents != null && name in registeredComponents
|
|
68
|
+
? (registeredComponents[
|
|
69
|
+
name as ComponentName
|
|
70
|
+
] as (typeof components)[ComponentName])
|
|
71
|
+
: comps[name as ComponentName];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type GetComponent = typeof getComponent;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file should contain all the components that we use in the builder/production app
|
|
3
|
+
*
|
|
4
|
+
* The application imports only the components it uses and uses
|
|
5
|
+
* getComponent = createGetComponent({ Box, BlaBla })to pass them to RootInstance
|
|
6
|
+
* see example /packages/sdk-size-test/app/routes/$.tsx
|
|
7
|
+
*/
|
|
8
|
+
export { Body } from "./body";
|
|
9
|
+
export { Box } from "./box";
|
|
10
|
+
export { TextBlock } from "./text-block";
|
|
11
|
+
export { Heading } from "./heading";
|
|
12
|
+
export { Paragraph } from "./paragraph";
|
|
13
|
+
export { Link } from "./link";
|
|
14
|
+
export { RichTextLink } from "./rich-text-link";
|
|
15
|
+
export { Span } from "./span";
|
|
16
|
+
export { Bold } from "./bold";
|
|
17
|
+
export { Italic } from "./italic";
|
|
18
|
+
export { Superscript } from "./superscript";
|
|
19
|
+
export { Subscript } from "./subscript";
|
|
20
|
+
export { Button } from "./button";
|
|
21
|
+
export { Input } from "./input";
|
|
22
|
+
export { Form } from "./form";
|
|
23
|
+
export { Image } from "./image";
|
|
24
|
+
export { Blockquote } from "./blockquote";
|
|
25
|
+
export { List } from "./list";
|
|
26
|
+
export { ListItem } from "./list-item";
|
|
27
|
+
export { Separator } from "./separator";
|
|
28
|
+
export { Code } from "./code";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/form.props
|
|
3
|
+
import { props } from "./__generated__/form.props";
|
|
4
4
|
|
|
5
5
|
const presetStyle = {
|
|
6
6
|
minHeight: {
|
|
@@ -21,6 +21,6 @@ export const meta: WsComponentMeta = {
|
|
|
21
21
|
presetStyle,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export const propsMeta = {
|
|
24
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
25
25
|
props,
|
|
26
|
-
}
|
|
26
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HeadingIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/heading.props
|
|
3
|
+
import { props } from "./__generated__/heading.props";
|
|
4
4
|
|
|
5
5
|
export const meta: WsComponentMeta = {
|
|
6
6
|
type: "rich-text",
|
|
@@ -9,7 +9,7 @@ export const meta: WsComponentMeta = {
|
|
|
9
9
|
children: ["Heading you can edit"],
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const propsMeta = {
|
|
12
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
13
13
|
props,
|
|
14
14
|
initialProps: ["tag"],
|
|
15
|
-
}
|
|
15
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ImageIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/image.props
|
|
3
|
+
import { props } from "./__generated__/image.props";
|
|
4
4
|
|
|
5
5
|
const presetStyle = {
|
|
6
6
|
// Otherwise on new image insert onto canvas it can overfit screen size multiple times
|
|
@@ -24,10 +24,15 @@ export const meta: WsComponentMeta = {
|
|
|
24
24
|
presetStyle,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export const propsMeta = {
|
|
27
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
28
28
|
props: {
|
|
29
29
|
...props,
|
|
30
|
-
src: {
|
|
30
|
+
src: {
|
|
31
|
+
type: "string",
|
|
32
|
+
control: "file-image",
|
|
33
|
+
label: "Source",
|
|
34
|
+
required: false,
|
|
35
|
+
},
|
|
31
36
|
},
|
|
32
37
|
initialProps: ["src", "width", "height", "alt", "loading"],
|
|
33
|
-
}
|
|
38
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
|
|
3
|
+
import type { ComponentName } from "./components-utils";
|
|
4
4
|
import { meta as BodyMeta } from "./body.ws";
|
|
5
5
|
import { meta as BoxMeta } from "./box.ws";
|
|
6
6
|
import { meta as TextBlockMeta } from "./text-block.ws";
|
|
@@ -17,6 +17,11 @@ import { meta as ButtonMeta } from "./button.ws";
|
|
|
17
17
|
import { meta as InputMeta } from "./input.ws";
|
|
18
18
|
import { meta as FormMeta } from "./form.ws";
|
|
19
19
|
import { meta as ImageMeta } from "./image.ws";
|
|
20
|
+
import { meta as BlockquoteMeta } from "./blockquote.ws";
|
|
21
|
+
import { meta as ListMeta } from "./list.ws";
|
|
22
|
+
import { meta as ListItemMeta } from "./list-item.ws";
|
|
23
|
+
import { meta as SeparatorMeta } from "./separator.ws";
|
|
24
|
+
import { meta as CodeMeta } from "./code.ws";
|
|
20
25
|
|
|
21
26
|
// these are huge JSON objects that we want to be tree-shaken when not used!
|
|
22
27
|
import { propsMeta as BodyMetaPropsMeta } from "./body.ws";
|
|
@@ -35,23 +40,11 @@ import { propsMeta as ButtonMetaPropsMeta } from "./button.ws";
|
|
|
35
40
|
import { propsMeta as InputMetaPropsMeta } from "./input.ws";
|
|
36
41
|
import { propsMeta as FormMetaPropsMeta } from "./form.ws";
|
|
37
42
|
import { propsMeta as ImageMetaPropsMeta } from "./image.ws";
|
|
38
|
-
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import { Paragraph } from "./paragraph";
|
|
44
|
-
import { Link } from "./link";
|
|
45
|
-
import { RichTextLink } from "./rich-text-link";
|
|
46
|
-
import { Span } from "./span";
|
|
47
|
-
import { Bold } from "./bold";
|
|
48
|
-
import { Italic } from "./italic";
|
|
49
|
-
import { Superscript } from "./superscript";
|
|
50
|
-
import { Subscript } from "./subscript";
|
|
51
|
-
import { Button } from "./button";
|
|
52
|
-
import { Input } from "./input";
|
|
53
|
-
import { Form } from "./form";
|
|
54
|
-
import { Image } from "./image";
|
|
43
|
+
import { propsMeta as BlockquotePropsMeta } from "./blockquote.ws";
|
|
44
|
+
import { propsMeta as ListPropsMeta } from "./list.ws";
|
|
45
|
+
import { propsMeta as ListItemPropsMeta } from "./list-item.ws";
|
|
46
|
+
import { propsMeta as SeparatorPropsMeta } from "./separator.ws";
|
|
47
|
+
import { propsMeta as CodePropsMeta } from "./code.ws";
|
|
55
48
|
|
|
56
49
|
const defaultMetas: Record<string, WsComponentMeta> = {
|
|
57
50
|
Box: BoxMeta,
|
|
@@ -70,6 +63,11 @@ const defaultMetas: Record<string, WsComponentMeta> = {
|
|
|
70
63
|
Input: InputMeta,
|
|
71
64
|
Form: FormMeta,
|
|
72
65
|
Image: ImageMeta,
|
|
66
|
+
Blockquote: BlockquoteMeta,
|
|
67
|
+
List: ListMeta,
|
|
68
|
+
ListItem: ListItemMeta,
|
|
69
|
+
Separator: SeparatorMeta,
|
|
70
|
+
Code: CodeMeta,
|
|
73
71
|
};
|
|
74
72
|
|
|
75
73
|
let currentMetas = defaultMetas;
|
|
@@ -88,7 +86,7 @@ export const registerComponentMetas = (
|
|
|
88
86
|
currentMetas = result;
|
|
89
87
|
};
|
|
90
88
|
|
|
91
|
-
const
|
|
89
|
+
const defaultPropsMetasRaw = {
|
|
92
90
|
Box: BoxMetaPropsMeta,
|
|
93
91
|
Body: BodyMetaPropsMeta,
|
|
94
92
|
TextBlock: TextBlockMetaPropsMeta,
|
|
@@ -105,7 +103,15 @@ const defaultPropsMetas: Record<string, WsComponentPropsMeta> = {
|
|
|
105
103
|
Input: InputMetaPropsMeta,
|
|
106
104
|
Form: FormMetaPropsMeta,
|
|
107
105
|
Image: ImageMetaPropsMeta,
|
|
108
|
-
|
|
106
|
+
Blockquote: BlockquotePropsMeta,
|
|
107
|
+
List: ListPropsMeta,
|
|
108
|
+
ListItem: ListItemPropsMeta,
|
|
109
|
+
Separator: SeparatorPropsMeta,
|
|
110
|
+
Code: CodePropsMeta,
|
|
111
|
+
} as const;
|
|
112
|
+
|
|
113
|
+
const defaultPropsMetas: Record<string, WsComponentPropsMeta> =
|
|
114
|
+
defaultPropsMetasRaw;
|
|
109
115
|
|
|
110
116
|
let registeredPropsMetas: Record<string, Partial<WsComponentPropsMeta>> = {};
|
|
111
117
|
|
|
@@ -142,53 +148,12 @@ export const registerComponentPropsMetas = (
|
|
|
142
148
|
currentPropsMetas = undefined;
|
|
143
149
|
};
|
|
144
150
|
|
|
145
|
-
const defaultComponents = {
|
|
146
|
-
Box,
|
|
147
|
-
Body,
|
|
148
|
-
TextBlock,
|
|
149
|
-
Heading,
|
|
150
|
-
Paragraph,
|
|
151
|
-
Link,
|
|
152
|
-
RichTextLink,
|
|
153
|
-
Span,
|
|
154
|
-
Bold,
|
|
155
|
-
Italic,
|
|
156
|
-
Superscript,
|
|
157
|
-
Subscript,
|
|
158
|
-
Button,
|
|
159
|
-
Input,
|
|
160
|
-
Form,
|
|
161
|
-
Image,
|
|
162
|
-
} as const;
|
|
163
|
-
|
|
164
|
-
export type ComponentName = keyof typeof defaultComponents;
|
|
165
151
|
type RegisteredComponents = Partial<{
|
|
166
152
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
167
153
|
[name in ComponentName]: {};
|
|
168
154
|
}>;
|
|
169
155
|
|
|
170
|
-
let registeredComponents: RegisteredComponents |
|
|
171
|
-
|
|
172
|
-
const componentNames = Object.keys(defaultComponents) as ComponentName[];
|
|
173
|
-
|
|
174
|
-
export const getComponentNames = (): ComponentName[] => {
|
|
175
|
-
const uniqueNames = new Set([
|
|
176
|
-
...componentNames,
|
|
177
|
-
...Object.keys(registeredComponents || {}),
|
|
178
|
-
]);
|
|
179
|
-
|
|
180
|
-
return [...uniqueNames.values()] as ComponentName[];
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export const getComponent = (
|
|
184
|
-
name: string
|
|
185
|
-
): undefined | typeof defaultComponents[ComponentName] => {
|
|
186
|
-
return registeredComponents != null && name in registeredComponents
|
|
187
|
-
? (registeredComponents[
|
|
188
|
-
name as ComponentName
|
|
189
|
-
] as typeof defaultComponents[ComponentName])
|
|
190
|
-
: defaultComponents[name as ComponentName];
|
|
191
|
-
};
|
|
156
|
+
export let registeredComponents: RegisteredComponents | undefined;
|
|
192
157
|
|
|
193
158
|
/**
|
|
194
159
|
* @todo: Allow register any component.
|
|
@@ -232,7 +197,7 @@ const computeInitialProps = (
|
|
|
232
197
|
? Object.entries(props)
|
|
233
198
|
.filter(
|
|
234
199
|
([name, value]) =>
|
|
235
|
-
value?.
|
|
200
|
+
value?.required && initialProps.includes(name) === false
|
|
236
201
|
)
|
|
237
202
|
.map(([name]) => name)
|
|
238
203
|
: [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InputIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/input.props
|
|
3
|
+
import { props } from "./__generated__/input.props";
|
|
4
4
|
|
|
5
5
|
export const meta: WsComponentMeta = {
|
|
6
6
|
type: "control",
|
|
@@ -8,6 +8,6 @@ export const meta: WsComponentMeta = {
|
|
|
8
8
|
Icon: InputIcon,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const propsMeta = {
|
|
11
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
12
12
|
props,
|
|
13
|
-
}
|
|
13
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FontItalicIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/italic.props
|
|
3
|
+
import { props } from "./__generated__/italic.props";
|
|
4
4
|
|
|
5
5
|
const presetStyle = {
|
|
6
6
|
fontStyle: {
|
|
@@ -16,6 +16,6 @@ export const meta: WsComponentMeta = {
|
|
|
16
16
|
presetStyle,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const propsMeta = {
|
|
19
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
20
20
|
props,
|
|
21
|
-
}
|
|
21
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Link2Icon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/link.props
|
|
3
|
+
import { props } from "./__generated__/link.props";
|
|
4
4
|
|
|
5
5
|
const presetStyle = {
|
|
6
6
|
minHeight: {
|
|
@@ -22,7 +22,7 @@ export const meta: WsComponentMeta = {
|
|
|
22
22
|
children: ["Link text you can edit"],
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export const propsMeta = {
|
|
25
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
26
26
|
props,
|
|
27
27
|
initialProps: ["href"],
|
|
28
|
-
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
2
|
+
import { ListItem as ListItemPrimitive } from "./list-item";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "Components/List Item",
|
|
6
|
+
component: ListItemPrimitive,
|
|
7
|
+
} as ComponentMeta<typeof ListItemPrimitive>;
|
|
8
|
+
|
|
9
|
+
const Template: ComponentStory<typeof ListItemPrimitive> = (args) => (
|
|
10
|
+
<ListItemPrimitive {...args} />
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const ListItem = Template.bind({});
|
|
14
|
+
ListItem.args = {
|
|
15
|
+
children: "ListItem",
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
createElement,
|
|
4
|
+
type ElementRef,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
} from "react";
|
|
7
|
+
|
|
8
|
+
const defaultTag = "li";
|
|
9
|
+
|
|
10
|
+
type Props = ComponentProps<typeof defaultTag>;
|
|
11
|
+
|
|
12
|
+
export const ListItem = forwardRef<ElementRef<typeof defaultTag>, Props>(
|
|
13
|
+
(props, ref) => {
|
|
14
|
+
return createElement(defaultTag, { ...props, ref });
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
ListItem.displayName = "ListItem";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ListItemIcon } from "@webstudio-is/icons";
|
|
2
|
+
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
+
import { props } from "./__generated__/list-item.props";
|
|
4
|
+
|
|
5
|
+
export const meta: WsComponentMeta = {
|
|
6
|
+
type: "rich-text",
|
|
7
|
+
label: "List Item",
|
|
8
|
+
Icon: ListItemIcon,
|
|
9
|
+
children: ["List Item you can edit"],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
13
|
+
props,
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
2
|
+
import { List as ListPrimitive } from "./list";
|
|
3
|
+
import { ListItem } from "./list-item";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: "Components/List",
|
|
7
|
+
component: ListPrimitive,
|
|
8
|
+
} as ComponentMeta<typeof ListPrimitive>;
|
|
9
|
+
|
|
10
|
+
const Template: ComponentStory<typeof ListPrimitive> = (args) => (
|
|
11
|
+
<ListPrimitive {...args} />
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const List = Template.bind({});
|
|
15
|
+
List.args = {
|
|
16
|
+
children: <ListItem />,
|
|
17
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
createElement,
|
|
4
|
+
type ElementRef,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
} from "react";
|
|
7
|
+
|
|
8
|
+
const unorderedTag = "ul";
|
|
9
|
+
const orderedTag = "ol";
|
|
10
|
+
|
|
11
|
+
type Props = ComponentProps<typeof unorderedTag> &
|
|
12
|
+
ComponentProps<typeof orderedTag> & {
|
|
13
|
+
ordered?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const List = forwardRef<
|
|
17
|
+
ElementRef<typeof unorderedTag | typeof orderedTag>,
|
|
18
|
+
Props
|
|
19
|
+
>(({ ordered = false, ...props }, ref) => {
|
|
20
|
+
const tag = ordered ? orderedTag : unorderedTag;
|
|
21
|
+
return createElement(tag, { ...props, ref });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
List.displayName = "List";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ListIcon } from "@webstudio-is/icons";
|
|
2
|
+
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
+
import { props } from "./__generated__/list.props";
|
|
4
|
+
|
|
5
|
+
const presetStyle = {
|
|
6
|
+
marginTop: {
|
|
7
|
+
type: "keyword",
|
|
8
|
+
value: "0",
|
|
9
|
+
},
|
|
10
|
+
marginBottom: {
|
|
11
|
+
type: "keyword",
|
|
12
|
+
value: "10px",
|
|
13
|
+
},
|
|
14
|
+
paddingLeft: {
|
|
15
|
+
type: "keyword",
|
|
16
|
+
value: "40px",
|
|
17
|
+
},
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export const meta: WsComponentMeta = {
|
|
21
|
+
type: "container",
|
|
22
|
+
label: "List",
|
|
23
|
+
Icon: ListIcon,
|
|
24
|
+
presetStyle,
|
|
25
|
+
children: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
29
|
+
props,
|
|
30
|
+
initialProps: ["ordered", "type", "starts", "reversed"],
|
|
31
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TextAlignLeftIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/paragraph.props
|
|
3
|
+
import { props } from "./__generated__/paragraph.props";
|
|
4
4
|
|
|
5
5
|
export const meta: WsComponentMeta = {
|
|
6
6
|
type: "rich-text",
|
|
@@ -9,6 +9,6 @@ export const meta: WsComponentMeta = {
|
|
|
9
9
|
children: ["Pragraph you can edit"],
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const propsMeta = {
|
|
12
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
13
13
|
props,
|
|
14
|
-
}
|
|
14
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Link2Icon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/rich-text-link.props
|
|
3
|
+
import { props } from "./__generated__/rich-text-link.props";
|
|
4
4
|
|
|
5
5
|
export const meta: WsComponentMeta = {
|
|
6
6
|
type: "rich-text-child",
|
|
@@ -8,6 +8,6 @@ export const meta: WsComponentMeta = {
|
|
|
8
8
|
Icon: Link2Icon,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const propsMeta = {
|
|
11
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
12
12
|
props,
|
|
13
|
-
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
2
|
+
import { Separator as SeparatorPrimitive } from "./separator";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "Components/Separator",
|
|
6
|
+
component: SeparatorPrimitive,
|
|
7
|
+
} as ComponentMeta<typeof SeparatorPrimitive>;
|
|
8
|
+
|
|
9
|
+
const Template: ComponentStory<typeof SeparatorPrimitive> = (args) => (
|
|
10
|
+
<SeparatorPrimitive {...args} />
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const Separator = Template.bind({});
|
|
14
|
+
Separator.args = {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
createElement,
|
|
4
|
+
type ElementRef,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
} from "react";
|
|
7
|
+
|
|
8
|
+
const defaultTag = "hr";
|
|
9
|
+
|
|
10
|
+
type Props = ComponentProps<typeof defaultTag>;
|
|
11
|
+
|
|
12
|
+
export const Separator = forwardRef<ElementRef<typeof defaultTag>, Props>(
|
|
13
|
+
(props, ref) => {
|
|
14
|
+
return createElement(defaultTag, { ...props, ref });
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
Separator.displayName = "Separator";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DashIcon } from "@webstudio-is/icons";
|
|
2
|
+
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
+
import { props } from "./__generated__/separator.props";
|
|
4
|
+
|
|
5
|
+
const presetStyle = {
|
|
6
|
+
height: {
|
|
7
|
+
type: "keyword",
|
|
8
|
+
value: "1px",
|
|
9
|
+
},
|
|
10
|
+
backgroundColor: {
|
|
11
|
+
type: "keyword",
|
|
12
|
+
value: "gray",
|
|
13
|
+
},
|
|
14
|
+
border: {
|
|
15
|
+
type: "keyword",
|
|
16
|
+
value: "none",
|
|
17
|
+
},
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export const meta: WsComponentMeta = {
|
|
21
|
+
type: "embed",
|
|
22
|
+
label: "Separator",
|
|
23
|
+
Icon: DashIcon,
|
|
24
|
+
presetStyle,
|
|
25
|
+
children: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
29
|
+
props,
|
|
30
|
+
initialProps: [],
|
|
31
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BrushIcon } from "@webstudio-is/icons";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
|
|
3
|
-
import props from "./__generated__/span.props
|
|
3
|
+
import { props } from "./__generated__/span.props";
|
|
4
4
|
|
|
5
5
|
export const meta: WsComponentMeta = {
|
|
6
6
|
type: "rich-text-child",
|
|
@@ -8,6 +8,6 @@ export const meta: WsComponentMeta = {
|
|
|
8
8
|
Icon: BrushIcon,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const propsMeta = {
|
|
11
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
12
12
|
props,
|
|
13
|
-
}
|
|
13
|
+
};
|