@webstudio-is/react-sdk 0.65.0 → 0.67.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/form.ws.js +2 -2
- package/lib/app/custom-components/image.js +7 -13
- package/lib/app/custom-components/index.js +4 -1
- package/lib/app/params.js +1 -0
- package/lib/cjs/app/custom-components/form.ws.js +2 -2
- package/lib/cjs/app/custom-components/image.js +3 -12
- package/lib/cjs/app/custom-components/index.js +4 -1
- package/lib/cjs/app/params.js +1 -0
- package/lib/cjs/components/__generated__/{code.props.js → code-text.props.js} +3 -3
- package/lib/cjs/components/__generated__/html-embed.props.js +31 -0
- package/lib/cjs/components/blockquote.ws.js +2 -2
- package/lib/cjs/components/body.ws.js +2 -2
- package/lib/cjs/components/bold.ws.js +2 -2
- package/lib/cjs/components/box.ws.js +2 -2
- package/lib/cjs/components/button.ws.js +2 -2
- package/lib/cjs/components/checkbox-field.ws.js +2 -2
- package/lib/cjs/components/checkbox.ws.js +2 -2
- package/lib/cjs/components/{code.js → code-text.js} +6 -6
- package/lib/cjs/components/{code.ws.js → code-text.ws.js} +10 -10
- package/lib/cjs/components/component-meta.js +2 -2
- package/lib/cjs/components/components-utils.js +1 -43
- package/lib/cjs/components/components.js +4 -2
- package/lib/cjs/components/error-message.ws.js +2 -2
- package/lib/cjs/components/form.ws.js +2 -2
- package/lib/cjs/components/fragment.ws.js +1 -1
- package/lib/cjs/components/heading.ws.js +2 -2
- package/lib/cjs/components/html-embed.js +80 -0
- package/lib/cjs/components/html-embed.ws.js +43 -0
- package/lib/cjs/components/image.ws.js +2 -2
- package/lib/cjs/components/index.js +11 -57
- package/lib/cjs/components/input.ws.js +2 -2
- package/lib/cjs/components/italic.ws.js +2 -2
- package/lib/cjs/components/label.ws.js +2 -2
- package/lib/cjs/components/link-block.ws.js +2 -2
- package/lib/cjs/components/link.ws.js +2 -2
- package/lib/cjs/components/list-item.ws.js +2 -2
- package/lib/cjs/components/list.ws.js +2 -2
- package/lib/cjs/components/paragraph.ws.js +2 -2
- package/lib/cjs/components/radio-button-field.ws.js +2 -2
- package/lib/cjs/components/radio-button.ws.js +2 -2
- package/lib/cjs/components/separator.ws.js +2 -2
- package/lib/cjs/components/slot.ws.js +2 -2
- package/lib/cjs/components/span.ws.js +2 -2
- package/lib/cjs/components/subscript.ws.js +2 -2
- package/lib/cjs/components/success-message.ws.js +2 -2
- package/lib/cjs/components/superscript.ws.js +2 -2
- package/lib/cjs/components/text-block.ws.js +2 -2
- package/lib/cjs/components/textarea.ws.js +2 -2
- package/lib/cjs/css/css.js +2 -5
- package/lib/cjs/css/normalize.js +1 -1
- package/lib/cjs/css/presets.js +8 -1
- package/lib/cjs/tree/create-elements-tree.js +2 -4
- package/lib/components/__generated__/html-embed.props.js +11 -0
- package/lib/components/blockquote.ws.js +2 -2
- package/lib/components/body.ws.js +2 -2
- package/lib/components/bold.ws.js +2 -2
- package/lib/components/box.ws.js +2 -2
- package/lib/components/button.ws.js +2 -2
- package/lib/components/checkbox-field.ws.js +2 -2
- package/lib/components/checkbox.ws.js +2 -2
- package/lib/components/{code.js → code-text.js} +3 -3
- package/lib/components/{code.ws.js → code-text.ws.js} +5 -5
- package/lib/components/component-meta.js +3 -3
- package/lib/components/components-utils.js +1 -43
- package/lib/components/components.js +4 -2
- package/lib/components/error-message.ws.js +2 -2
- package/lib/components/form.ws.js +2 -2
- package/lib/components/fragment.ws.js +1 -1
- package/lib/components/heading.ws.js +2 -2
- package/lib/components/html-embed.js +65 -0
- package/lib/components/html-embed.ws.js +23 -0
- package/lib/components/image.ws.js +2 -2
- package/lib/components/index.js +11 -57
- package/lib/components/input.ws.js +2 -2
- package/lib/components/italic.ws.js +2 -2
- package/lib/components/label.ws.js +2 -2
- package/lib/components/link-block.ws.js +2 -2
- package/lib/components/link.ws.js +2 -2
- package/lib/components/list-item.ws.js +2 -2
- package/lib/components/list.ws.js +2 -2
- package/lib/components/paragraph.ws.js +2 -2
- package/lib/components/radio-button-field.ws.js +2 -2
- package/lib/components/radio-button.ws.js +2 -2
- package/lib/components/separator.ws.js +2 -2
- package/lib/components/slot.ws.js +2 -2
- package/lib/components/span.ws.js +2 -2
- package/lib/components/subscript.ws.js +2 -2
- package/lib/components/success-message.ws.js +2 -2
- package/lib/components/superscript.ws.js +2 -2
- package/lib/components/text-block.ws.js +2 -2
- package/lib/components/textarea.ws.js +2 -2
- package/lib/css/css.js +2 -5
- package/lib/css/normalize.js +2 -2
- package/lib/css/presets.js +8 -1
- package/lib/tree/create-elements-tree.js +2 -4
- package/lib/types/app/params.d.ts +22 -1
- package/lib/types/components/__generated__/html-embed.props.d.ts +2 -0
- package/lib/types/components/{code.d.ts → code-text.d.ts} +1 -1
- package/lib/types/components/{code.stories.d.ts → code-text.stories.d.ts} +1 -1
- package/lib/types/components/component-meta.d.ts +1785 -10
- package/lib/types/components/components-utils.d.ts +6 -3
- package/lib/types/components/components.d.ts +2 -1
- package/lib/types/components/html-embed.d.ts +7 -0
- package/lib/types/components/html-embed.stories.d.ts +11 -0
- package/lib/types/components/html-embed.ws.d.ts +3 -0
- package/lib/types/components/index.d.ts +2 -2
- package/lib/types/context.d.ts +1 -0
- package/lib/types/css/css.d.ts +2 -0
- package/lib/types/css/presets.d.ts +1 -0
- package/lib/types/css/style-rules.d.ts +1 -1
- package/lib/types/embed-template.d.ts +1 -1
- package/lib/types/tree/create-elements-tree.d.ts +2 -2
- package/package.json +14 -13
- package/src/app/custom-components/form.ws.tsx +2 -2
- package/src/app/custom-components/image.tsx +7 -13
- package/src/app/custom-components/index.ts +4 -1
- package/src/app/params.ts +23 -1
- package/src/components/__generated__/html-embed.props.ts +10 -0
- package/src/components/blockquote.ws.tsx +2 -2
- package/src/components/body.ws.tsx +2 -2
- package/src/components/bold.ws.tsx +2 -2
- package/src/components/box.ws.ts +2 -2
- package/src/components/button.ws.tsx +2 -2
- package/src/components/checkbox-field.ws.tsx +2 -2
- package/src/components/checkbox.ws.tsx +2 -2
- package/src/components/code-text.stories.tsx +16 -0
- package/src/components/{code.tsx → code-text.tsx} +2 -2
- package/src/components/{code.ws.tsx → code-text.ws.tsx} +5 -5
- package/src/components/component-meta.ts +3 -6
- package/src/components/components-utils.ts +14 -58
- package/src/components/components.ts +2 -1
- package/src/components/error-message.ws.tsx +2 -2
- package/src/components/form.ws.tsx +2 -2
- package/src/components/fragment.ws.ts +1 -1
- package/src/components/heading.ws.tsx +2 -2
- package/src/components/html-embed.stories.tsx +16 -0
- package/src/components/html-embed.tsx +96 -0
- package/src/components/html-embed.ws.ts +22 -0
- package/src/components/image.ws.tsx +2 -2
- package/src/components/index.ts +10 -87
- package/src/components/input.ws.tsx +2 -2
- package/src/components/italic.ws.tsx +2 -2
- package/src/components/label.ws.tsx +2 -2
- package/src/components/link-block.ws.tsx +2 -2
- package/src/components/link.ws.tsx +2 -2
- package/src/components/list-item.ws.tsx +2 -2
- package/src/components/list.ws.tsx +2 -2
- package/src/components/paragraph.ws.tsx +2 -2
- package/src/components/radio-button-field.ws.tsx +2 -2
- package/src/components/radio-button.ws.tsx +2 -2
- package/src/components/separator.ws.tsx +2 -2
- package/src/components/slot.ws.ts +2 -2
- package/src/components/span.ws.tsx +2 -2
- package/src/components/subscript.ws.tsx +2 -2
- package/src/components/success-message.ws.tsx +2 -2
- package/src/components/superscript.ws.tsx +2 -2
- package/src/components/text-block.ws.tsx +2 -2
- package/src/components/textarea.ws.tsx +2 -2
- package/src/context.tsx +1 -0
- package/src/css/css.ts +4 -5
- package/src/css/normalize.ts +2 -2
- package/src/css/presets.ts +7 -0
- package/src/tree/create-elements-tree.tsx +3 -5
- package/lib/cjs/tree/session-storage-polyfill.js +0 -65
- package/lib/tree/session-storage-polyfill.js +0 -45
- package/lib/types/tree/session-storage-polyfill.d.ts +0 -2
- package/src/components/code.stories.tsx +0 -16
- package/src/tree/session-storage-polyfill.tsx +0 -50
- /package/lib/components/__generated__/{code.props.js → code-text.props.js} +0 -0
- /package/lib/types/components/__generated__/{code.props.d.ts → code-text.props.d.ts} +0 -0
- /package/lib/types/components/{code.ws.d.ts → code-text.ws.d.ts} +0 -0
- /package/src/components/__generated__/{code.props.ts → code-text.props.ts} +0 -0
|
@@ -1,63 +1,19 @@
|
|
|
1
|
-
import type { forwardRef } from "react";
|
|
2
1
|
import * as components from "./components";
|
|
3
2
|
import { registeredComponents } from "./index";
|
|
3
|
+
import { componentAttribute, idAttribute } from "../tree";
|
|
4
4
|
|
|
5
5
|
export type ComponentName = keyof typeof components;
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* We need to define component names manually here, instead of using Object.keys(components)
|
|
9
|
-
* Otherwise every component would be included in the bundle, even if it is not used
|
|
10
|
-
*
|
|
11
|
-
* @todo this list should not be hardcoded!
|
|
12
|
-
*/
|
|
13
|
-
const componentNames = Object.keys({
|
|
14
|
-
Slot: 1,
|
|
15
|
-
Fragment: 1,
|
|
16
|
-
Box: 1,
|
|
17
|
-
Body: 1,
|
|
18
|
-
TextBlock: 1,
|
|
19
|
-
Heading: 1,
|
|
20
|
-
Paragraph: 1,
|
|
21
|
-
Link: 1,
|
|
22
|
-
LinkBlock: 1,
|
|
23
|
-
RichTextLink: 1,
|
|
24
|
-
Span: 1,
|
|
25
|
-
Bold: 1,
|
|
26
|
-
Italic: 1,
|
|
27
|
-
Superscript: 1,
|
|
28
|
-
Subscript: 1,
|
|
29
|
-
Button: 1,
|
|
30
|
-
Input: 1,
|
|
31
|
-
Form: 1,
|
|
32
|
-
Image: 1,
|
|
33
|
-
Blockquote: 1,
|
|
34
|
-
List: 1,
|
|
35
|
-
ListItem: 1,
|
|
36
|
-
Separator: 1,
|
|
37
|
-
Code: 1,
|
|
38
|
-
Label: 1,
|
|
39
|
-
SuccessMessage: 1,
|
|
40
|
-
ErrorMessage: 1,
|
|
41
|
-
Textarea: 1,
|
|
42
|
-
RadioButtonField: 1,
|
|
43
|
-
RadioButton: 1,
|
|
44
|
-
CheckboxField: 1,
|
|
45
|
-
Checkbox: 1,
|
|
46
|
-
} satisfies { [K in keyof typeof components]: 1 }) as Array<
|
|
47
|
-
keyof typeof components
|
|
48
|
-
>;
|
|
49
|
-
|
|
50
|
-
export const getComponentNames = (): ComponentName[] => {
|
|
51
|
-
const uniqueNames = new Set([
|
|
52
|
-
...componentNames,
|
|
53
|
-
...Object.keys(registeredComponents || {}),
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
return Array.from(uniqueNames) as ComponentName[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
type AnyComponent =
|
|
8
|
+
type AnyComponent = React.ForwardRefExoticComponent<
|
|
9
|
+
Omit<
|
|
10
|
+
React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>,
|
|
11
|
+
"ref"
|
|
12
|
+
> & {
|
|
13
|
+
[componentAttribute]: string;
|
|
14
|
+
[idAttribute]: string;
|
|
15
|
+
} & React.RefAttributes<HTMLElement>
|
|
16
|
+
>;
|
|
61
17
|
|
|
62
18
|
/**
|
|
63
19
|
* Now used only in builder app
|
|
@@ -65,8 +21,8 @@ type AnyComponent = ReturnType<typeof forwardRef<any, any>>;
|
|
|
65
21
|
*/
|
|
66
22
|
export const getComponent = (name: string): undefined | AnyComponent => {
|
|
67
23
|
return registeredComponents != null && name in registeredComponents
|
|
68
|
-
? (registeredComponents[name as ComponentName] as
|
|
69
|
-
: components[name as ComponentName];
|
|
24
|
+
? (registeredComponents[name as ComponentName] as never)
|
|
25
|
+
: (components[name as ComponentName] as never);
|
|
70
26
|
};
|
|
71
27
|
|
|
72
28
|
/**
|
|
@@ -78,8 +34,8 @@ export const getComponent = (name: string): undefined | AnyComponent => {
|
|
|
78
34
|
export const createGetComponent = (comps: Partial<typeof components>) => {
|
|
79
35
|
return (name: string): undefined | AnyComponent => {
|
|
80
36
|
return registeredComponents != null && name in registeredComponents
|
|
81
|
-
? (registeredComponents[name as ComponentName] as
|
|
82
|
-
: comps[name as ComponentName];
|
|
37
|
+
? (registeredComponents[name as ComponentName] as never)
|
|
38
|
+
: (comps[name as ComponentName] as never);
|
|
83
39
|
};
|
|
84
40
|
};
|
|
85
41
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { Slot } from "./slot";
|
|
9
9
|
export { Fragment } from "./fragment";
|
|
10
|
+
export { HtmlEmbed } from "./html-embed";
|
|
10
11
|
export { Body } from "./body";
|
|
11
12
|
export { Box } from "./box";
|
|
12
13
|
export { TextBlock } from "./text-block";
|
|
@@ -28,7 +29,7 @@ export { Blockquote } from "./blockquote";
|
|
|
28
29
|
export { List } from "./list";
|
|
29
30
|
export { ListItem } from "./list-item";
|
|
30
31
|
export { Separator } from "./separator";
|
|
31
|
-
export {
|
|
32
|
+
export { CodeText } from "./code-text";
|
|
32
33
|
export { Label } from "./label";
|
|
33
34
|
export { SuccessMessage } from "./success-message";
|
|
34
35
|
export { ErrorMessage } from "./error-message";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoxIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { BoxIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import type {
|
|
3
3
|
WsComponentMeta,
|
|
4
4
|
WsComponentPropsMeta,
|
|
@@ -14,7 +14,7 @@ const presetStyle = {
|
|
|
14
14
|
export const meta: WsComponentMeta = {
|
|
15
15
|
type: "container",
|
|
16
16
|
label: "Error Message",
|
|
17
|
-
|
|
17
|
+
icon: BoxIcon,
|
|
18
18
|
presetStyle,
|
|
19
19
|
};
|
|
20
20
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { FormIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { form } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -20,7 +20,7 @@ export const meta: WsComponentMeta = {
|
|
|
20
20
|
category: "forms",
|
|
21
21
|
type: "container",
|
|
22
22
|
label: "Form",
|
|
23
|
-
|
|
23
|
+
icon: FormIcon,
|
|
24
24
|
states: defaultStates,
|
|
25
25
|
presetStyle,
|
|
26
26
|
children: [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HeadingIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { HeadingIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import type { ComponentProps } from "react";
|
|
3
3
|
import { h1, h2, h3, h4, h5, h6 } from "../css/normalize";
|
|
4
4
|
import {
|
|
@@ -25,7 +25,7 @@ export const meta: WsComponentMeta = {
|
|
|
25
25
|
category: "typography",
|
|
26
26
|
type: "rich-text",
|
|
27
27
|
label: "Heading",
|
|
28
|
-
|
|
28
|
+
icon: HeadingIcon,
|
|
29
29
|
children: [{ type: "text", value: "Heading you can edit" }],
|
|
30
30
|
states: defaultStates,
|
|
31
31
|
presetStyle,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
2
|
+
import { HtmlEmbed as HtmlEmbedPrimitive } from "./html-embed";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "Components/HtmlEmbed",
|
|
6
|
+
component: HtmlEmbedPrimitive,
|
|
7
|
+
} as ComponentMeta<typeof HtmlEmbedPrimitive>;
|
|
8
|
+
|
|
9
|
+
const Template: ComponentStory<typeof HtmlEmbedPrimitive> = (args) => (
|
|
10
|
+
<HtmlEmbedPrimitive {...args} />
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const HtmlEmbed = Template.bind({});
|
|
14
|
+
HtmlEmbed.args = {
|
|
15
|
+
code: "<strong>custom code</strong>",
|
|
16
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
type ForwardedRef,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { mergeRefs } from "@react-aria/utils";
|
|
9
|
+
import { ReactSdkContext } from "../context";
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
code: string;
|
|
13
|
+
executeScriptOnCanvas: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ChildProps = {
|
|
17
|
+
innerRef: ForwardedRef<HTMLDivElement>;
|
|
18
|
+
// code can be actually undefined when prop is not provided
|
|
19
|
+
code?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Scripts are executed when rendered client side.
|
|
24
|
+
* Necessary on canvas which does not have server rendering.
|
|
25
|
+
*/
|
|
26
|
+
const ExecutableHtml = (props: ChildProps) => {
|
|
27
|
+
const { code, innerRef, ...rest } = props;
|
|
28
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const container = containerRef.current;
|
|
32
|
+
if (container === null || code === undefined) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// the trick to execute inserted scripts
|
|
36
|
+
// https://ghinda.net/article/script-tags
|
|
37
|
+
const range = document.createRange();
|
|
38
|
+
range.setStart(container, 0);
|
|
39
|
+
const fragment = range.createContextualFragment(code);
|
|
40
|
+
while (container.firstChild) {
|
|
41
|
+
container.removeChild(container.firstChild);
|
|
42
|
+
}
|
|
43
|
+
container.append(fragment);
|
|
44
|
+
}, [code]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
{...rest}
|
|
49
|
+
ref={mergeRefs(innerRef, containerRef)}
|
|
50
|
+
style={{ display: "contents" }}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Scripts are executed when rendered server side
|
|
57
|
+
*/
|
|
58
|
+
const InnerHtml = (props: ChildProps) => {
|
|
59
|
+
const { code, innerRef, ...rest } = props;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
{...rest}
|
|
64
|
+
ref={innerRef}
|
|
65
|
+
style={{ display: "contents" }}
|
|
66
|
+
dangerouslySetInnerHTML={{ __html: props.code ?? "" }}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const Placeholder = (props: ChildProps) => {
|
|
72
|
+
const { code, innerRef, ...rest } = props;
|
|
73
|
+
return (
|
|
74
|
+
<div ref={innerRef} {...rest} style={{ padding: "20px" }}>
|
|
75
|
+
{'Open "Properties" panel to insert HTML code'}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const HtmlEmbed = forwardRef<HTMLDivElement, Props>((props, ref) => {
|
|
81
|
+
const { renderer } = useContext(ReactSdkContext);
|
|
82
|
+
const { code, executeScriptOnCanvas, ...rest } = props;
|
|
83
|
+
|
|
84
|
+
// code can be actually undefined when prop is not provided
|
|
85
|
+
if (code === undefined || code.trim().length === 0) {
|
|
86
|
+
return <Placeholder innerRef={ref} {...rest} />;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (renderer === "canvas" && executeScriptOnCanvas === true) {
|
|
90
|
+
return <ExecutableHtml innerRef={ref} code={code} {...rest} />;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return <InnerHtml innerRef={ref} code={code} {...rest} />;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
HtmlEmbed.displayName = "HtmlEmbed";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EmbedIcon } from "@webstudio-is/icons/svg";
|
|
2
|
+
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
|
|
3
|
+
import { props } from "./__generated__/html-embed.props";
|
|
4
|
+
|
|
5
|
+
export const meta: WsComponentMeta = {
|
|
6
|
+
category: "general",
|
|
7
|
+
type: "embed",
|
|
8
|
+
label: "HTML Embed",
|
|
9
|
+
icon: EmbedIcon,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const propsMeta: WsComponentPropsMeta = {
|
|
13
|
+
props: {
|
|
14
|
+
...props,
|
|
15
|
+
code: {
|
|
16
|
+
required: true,
|
|
17
|
+
control: "code",
|
|
18
|
+
type: "string",
|
|
19
|
+
rows: 10,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { ImageIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { img } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -31,7 +31,7 @@ export const meta: WsComponentMeta = {
|
|
|
31
31
|
category: "media",
|
|
32
32
|
type: "embed",
|
|
33
33
|
label: "Image",
|
|
34
|
-
|
|
34
|
+
icon: ImageIcon,
|
|
35
35
|
states: defaultStates,
|
|
36
36
|
presetStyle,
|
|
37
37
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
2
1
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
|
|
3
2
|
import type { ComponentName } from "./components-utils";
|
|
4
3
|
import { meta as SlotMeta } from "./slot.ws";
|
|
5
4
|
import { meta as FragmentMeta } from "./fragment.ws";
|
|
5
|
+
import { meta as HtmlEmbedMeta } from "./html-embed.ws";
|
|
6
6
|
import { meta as BodyMeta } from "./body.ws";
|
|
7
7
|
import { meta as BoxMeta } from "./box.ws";
|
|
8
8
|
import { meta as TextBlockMeta } from "./text-block.ws";
|
|
@@ -24,7 +24,7 @@ import { meta as BlockquoteMeta } from "./blockquote.ws";
|
|
|
24
24
|
import { meta as ListMeta } from "./list.ws";
|
|
25
25
|
import { meta as ListItemMeta } from "./list-item.ws";
|
|
26
26
|
import { meta as SeparatorMeta } from "./separator.ws";
|
|
27
|
-
import { meta as
|
|
27
|
+
import { meta as CodeTextMeta } from "./code-text.ws";
|
|
28
28
|
import { meta as LabelMeta } from "./label.ws";
|
|
29
29
|
import { meta as SuccessMessageMeta } from "./success-message.ws";
|
|
30
30
|
import { meta as ErrorMessageMeta } from "./error-message.ws";
|
|
@@ -37,6 +37,7 @@ import { meta as CheckboxMeta } from "./checkbox.ws";
|
|
|
37
37
|
// these are huge JSON objects that we want to be tree-shaken when not used!
|
|
38
38
|
import { propsMeta as SlotMetaPropsMeta } from "./slot.ws";
|
|
39
39
|
import { propsMeta as FragmentMetaPropsMeta } from "./fragment.ws";
|
|
40
|
+
import { propsMeta as HtmlEmbedMetaPropsMeta } from "./html-embed.ws";
|
|
40
41
|
import { propsMeta as BodyMetaPropsMeta } from "./body.ws";
|
|
41
42
|
import { propsMeta as BoxMetaPropsMeta } from "./box.ws";
|
|
42
43
|
import { propsMeta as TextBlockMetaPropsMeta } from "./text-block.ws";
|
|
@@ -58,7 +59,7 @@ import { propsMeta as BlockquotePropsMeta } from "./blockquote.ws";
|
|
|
58
59
|
import { propsMeta as ListPropsMeta } from "./list.ws";
|
|
59
60
|
import { propsMeta as ListItemPropsMeta } from "./list-item.ws";
|
|
60
61
|
import { propsMeta as SeparatorPropsMeta } from "./separator.ws";
|
|
61
|
-
import { propsMeta as
|
|
62
|
+
import { propsMeta as CodeTextPropsMeta } from "./code-text.ws";
|
|
62
63
|
import { propsMeta as LabelPropsMeta } from "./label.ws";
|
|
63
64
|
import { propsMeta as SuccessMessagePropsMeta } from "./success-message.ws";
|
|
64
65
|
import { propsMeta as ErrorMessagePropsMeta } from "./error-message.ws";
|
|
@@ -69,9 +70,10 @@ import { propsMeta as CheckboxFieldPropsMeta } from "./checkbox-field.ws";
|
|
|
69
70
|
import { propsMeta as CheckboxPropsMeta } from "./checkbox.ws";
|
|
70
71
|
|
|
71
72
|
// @todo this list should not be hardcoded!
|
|
72
|
-
const defaultMetas: Record<string, WsComponentMeta> = {
|
|
73
|
+
export const defaultMetas: Record<string, WsComponentMeta> = {
|
|
73
74
|
Slot: SlotMeta,
|
|
74
75
|
Fragment: FragmentMeta,
|
|
76
|
+
HtmlEmbed: HtmlEmbedMeta,
|
|
75
77
|
Box: BoxMeta,
|
|
76
78
|
Body: BodyMeta,
|
|
77
79
|
TextBlock: TextBlockMeta,
|
|
@@ -93,7 +95,7 @@ const defaultMetas: Record<string, WsComponentMeta> = {
|
|
|
93
95
|
List: ListMeta,
|
|
94
96
|
ListItem: ListItemMeta,
|
|
95
97
|
Separator: SeparatorMeta,
|
|
96
|
-
|
|
98
|
+
CodeText: CodeTextMeta,
|
|
97
99
|
Label: LabelMeta,
|
|
98
100
|
SuccessMessage: SuccessMessageMeta,
|
|
99
101
|
ErrorMessage: ErrorMessageMeta,
|
|
@@ -121,9 +123,10 @@ export const registerComponentMetas = (
|
|
|
121
123
|
};
|
|
122
124
|
|
|
123
125
|
// @todo this list should not be hardcoded!
|
|
124
|
-
const
|
|
126
|
+
export const defaultPropsMetas: Record<string, WsComponentPropsMeta> = {
|
|
125
127
|
Slot: SlotMetaPropsMeta,
|
|
126
128
|
Fragment: FragmentMetaPropsMeta,
|
|
129
|
+
HtmlEmbed: HtmlEmbedMetaPropsMeta,
|
|
127
130
|
Box: BoxMetaPropsMeta,
|
|
128
131
|
Body: BodyMetaPropsMeta,
|
|
129
132
|
TextBlock: TextBlockMetaPropsMeta,
|
|
@@ -145,7 +148,7 @@ const defaultPropsMetasRaw = {
|
|
|
145
148
|
List: ListPropsMeta,
|
|
146
149
|
ListItem: ListItemPropsMeta,
|
|
147
150
|
Separator: SeparatorPropsMeta,
|
|
148
|
-
|
|
151
|
+
CodeText: CodeTextPropsMeta,
|
|
149
152
|
Label: LabelPropsMeta,
|
|
150
153
|
SuccessMessage: SuccessMessagePropsMeta,
|
|
151
154
|
ErrorMessage: ErrorMessagePropsMeta,
|
|
@@ -154,44 +157,6 @@ const defaultPropsMetasRaw = {
|
|
|
154
157
|
RadioButton: RadioButtonPropsMeta,
|
|
155
158
|
CheckboxField: CheckboxFieldPropsMeta,
|
|
156
159
|
Checkbox: CheckboxPropsMeta,
|
|
157
|
-
} as const;
|
|
158
|
-
|
|
159
|
-
const defaultPropsMetas: Record<string, WsComponentPropsMeta> =
|
|
160
|
-
defaultPropsMetasRaw;
|
|
161
|
-
|
|
162
|
-
let registeredPropsMetas: Record<string, Partial<WsComponentPropsMeta>> = {};
|
|
163
|
-
|
|
164
|
-
// we start as `undefined` because pre-computing will likely kill tree-shaking
|
|
165
|
-
let currentPropsMetas: Record<string, WsComponentPropsMeta> | undefined =
|
|
166
|
-
undefined;
|
|
167
|
-
|
|
168
|
-
export const getComponentPropsMeta = (
|
|
169
|
-
name: string
|
|
170
|
-
): WsComponentPropsMeta | undefined => {
|
|
171
|
-
if (currentPropsMetas === undefined) {
|
|
172
|
-
currentPropsMetas = {};
|
|
173
|
-
for (const name of Object.keys(defaultPropsMetas)) {
|
|
174
|
-
const props = computeProps(
|
|
175
|
-
defaultPropsMetas[name],
|
|
176
|
-
registeredPropsMetas[name] ?? {}
|
|
177
|
-
);
|
|
178
|
-
const initialProps = computeInitialProps(
|
|
179
|
-
props,
|
|
180
|
-
defaultPropsMetas[name],
|
|
181
|
-
registeredPropsMetas[name] ?? {}
|
|
182
|
-
);
|
|
183
|
-
currentPropsMetas[name] = { props, initialProps };
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return currentPropsMetas[name];
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export const registerComponentPropsMetas = (
|
|
191
|
-
metas: Record<string, WsComponentPropsMeta>
|
|
192
|
-
) => {
|
|
193
|
-
registeredPropsMetas = metas;
|
|
194
|
-
currentPropsMetas = undefined;
|
|
195
160
|
};
|
|
196
161
|
|
|
197
162
|
type RegisteredComponents = Partial<{
|
|
@@ -210,48 +175,6 @@ export const registerComponents = (components: RegisteredComponents) => {
|
|
|
210
175
|
registeredComponents = components;
|
|
211
176
|
};
|
|
212
177
|
|
|
213
|
-
const computeProps = (
|
|
214
|
-
defaults: WsComponentPropsMeta,
|
|
215
|
-
overrides: Partial<WsComponentPropsMeta>
|
|
216
|
-
) => {
|
|
217
|
-
if (overrides) {
|
|
218
|
-
const allNames = new Set([
|
|
219
|
-
...Object.keys(defaults.props ?? {}),
|
|
220
|
-
...Object.keys(overrides?.props ?? {}),
|
|
221
|
-
]).values();
|
|
222
|
-
|
|
223
|
-
const result: WsComponentPropsMeta["props"] = {};
|
|
224
|
-
for (const name of allNames) {
|
|
225
|
-
result[name] = PropMeta.parse({
|
|
226
|
-
...defaults.props[name],
|
|
227
|
-
...overrides?.props?.[name],
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return result;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return defaults.props;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const computeInitialProps = (
|
|
237
|
-
props: WsComponentPropsMeta["props"],
|
|
238
|
-
defaults: WsComponentPropsMeta,
|
|
239
|
-
overrides: Partial<WsComponentPropsMeta>
|
|
240
|
-
): Array<string> => {
|
|
241
|
-
const initialProps = overrides?.initialProps ?? defaults?.initialProps ?? [];
|
|
242
|
-
const requiredProps = props
|
|
243
|
-
? Object.entries(props)
|
|
244
|
-
.filter(
|
|
245
|
-
([name, value]) =>
|
|
246
|
-
value?.required && initialProps.includes(name) === false
|
|
247
|
-
)
|
|
248
|
-
.map(([name]) => name)
|
|
249
|
-
: [];
|
|
250
|
-
|
|
251
|
-
// order of initialProps must be preserved
|
|
252
|
-
return [...initialProps, ...requiredProps];
|
|
253
|
-
};
|
|
254
|
-
|
|
255
178
|
export const canAcceptComponent = (
|
|
256
179
|
parentComponent: string,
|
|
257
180
|
childComponent: string
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormTextFieldIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { FormTextFieldIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { input } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -17,7 +17,7 @@ export const meta: WsComponentMeta = {
|
|
|
17
17
|
category: "forms",
|
|
18
18
|
type: "control",
|
|
19
19
|
label: "Text Input",
|
|
20
|
-
|
|
20
|
+
icon: FormTextFieldIcon,
|
|
21
21
|
presetStyle,
|
|
22
22
|
states: [
|
|
23
23
|
...defaultStates,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextItalicIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { TextItalicIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import type { defaultTag } from "./italic";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -22,7 +22,7 @@ const presetStyle = {
|
|
|
22
22
|
export const meta: WsComponentMeta = {
|
|
23
23
|
type: "rich-text-child",
|
|
24
24
|
label: "Italic Text",
|
|
25
|
-
|
|
25
|
+
icon: TextItalicIcon,
|
|
26
26
|
states: defaultStates,
|
|
27
27
|
presetStyle,
|
|
28
28
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextBlockIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { TextBlockIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
type WsComponentMeta,
|
|
4
4
|
type WsComponentPropsMeta,
|
|
@@ -20,7 +20,7 @@ export const meta: WsComponentMeta = {
|
|
|
20
20
|
category: "forms",
|
|
21
21
|
type: "rich-text",
|
|
22
22
|
label: "Input Label",
|
|
23
|
-
|
|
23
|
+
icon: TextBlockIcon,
|
|
24
24
|
states: defaultStates,
|
|
25
25
|
presetStyle,
|
|
26
26
|
children: [{ type: "text", value: "Form Label" }],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LinkBlockIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { LinkBlockIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import type {
|
|
3
3
|
PresetStyle,
|
|
4
4
|
WsComponentMeta,
|
|
@@ -23,7 +23,7 @@ export const meta: WsComponentMeta = {
|
|
|
23
23
|
category: "general",
|
|
24
24
|
type: "container",
|
|
25
25
|
label: "Link Block",
|
|
26
|
-
|
|
26
|
+
icon: LinkBlockIcon,
|
|
27
27
|
states: linkMeta.states,
|
|
28
28
|
presetStyle,
|
|
29
29
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LinkIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { LinkIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { a } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -27,7 +27,7 @@ export const meta: WsComponentMeta = {
|
|
|
27
27
|
category: "general",
|
|
28
28
|
type: "rich-text",
|
|
29
29
|
label: "Link Text",
|
|
30
|
-
|
|
30
|
+
icon: LinkIcon,
|
|
31
31
|
presetStyle,
|
|
32
32
|
states: [
|
|
33
33
|
...defaultStates,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ListItemIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { ListItemIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { li } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -18,7 +18,7 @@ export const meta: WsComponentMeta = {
|
|
|
18
18
|
type: "rich-text",
|
|
19
19
|
acceptedParents: ["List"],
|
|
20
20
|
label: "List Item",
|
|
21
|
-
|
|
21
|
+
icon: ListItemIcon,
|
|
22
22
|
children: [{ type: "text", value: "List Item you can edit" }],
|
|
23
23
|
states: defaultStates,
|
|
24
24
|
presetStyle,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ListIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { ListIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
defaultStates,
|
|
4
4
|
type PresetStyle,
|
|
@@ -46,7 +46,7 @@ export const meta: WsComponentMeta = {
|
|
|
46
46
|
category: "typography",
|
|
47
47
|
type: "container",
|
|
48
48
|
label: "List",
|
|
49
|
-
|
|
49
|
+
icon: ListIcon,
|
|
50
50
|
states: defaultStates,
|
|
51
51
|
presetStyle,
|
|
52
52
|
children: [],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextAlignLeftIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { TextAlignLeftIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { p } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -17,7 +17,7 @@ export const meta: WsComponentMeta = {
|
|
|
17
17
|
category: "typography",
|
|
18
18
|
type: "rich-text",
|
|
19
19
|
label: "Paragraph",
|
|
20
|
-
|
|
20
|
+
icon: TextAlignLeftIcon,
|
|
21
21
|
children: [{ type: "text", value: "Pragraph you can edit" }],
|
|
22
22
|
states: defaultStates,
|
|
23
23
|
presetStyle,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RadioCheckedIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { RadioCheckedIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
type WsComponentMeta,
|
|
4
4
|
type WsComponentPropsMeta,
|
|
@@ -20,7 +20,7 @@ export const meta: WsComponentMeta = {
|
|
|
20
20
|
category: "forms",
|
|
21
21
|
type: "container",
|
|
22
22
|
label: "Radio",
|
|
23
|
-
|
|
23
|
+
icon: RadioCheckedIcon,
|
|
24
24
|
states: defaultStates,
|
|
25
25
|
presetStyle,
|
|
26
26
|
children: [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RadioCheckedIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { RadioCheckedIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
type WsComponentMeta,
|
|
4
4
|
type WsComponentPropsMeta,
|
|
@@ -22,7 +22,7 @@ const presetStyle = {
|
|
|
22
22
|
export const meta: WsComponentMeta = {
|
|
23
23
|
type: "control",
|
|
24
24
|
label: "Radio Input",
|
|
25
|
-
|
|
25
|
+
icon: RadioCheckedIcon,
|
|
26
26
|
presetStyle,
|
|
27
27
|
states: [
|
|
28
28
|
...defaultStates,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DashIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { DashIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
defaultStates,
|
|
4
4
|
type PresetStyle,
|
|
@@ -44,7 +44,7 @@ export const meta: WsComponentMeta = {
|
|
|
44
44
|
category: "general",
|
|
45
45
|
type: "embed",
|
|
46
46
|
label: "Separator",
|
|
47
|
-
|
|
47
|
+
icon: DashIcon,
|
|
48
48
|
states: defaultStates,
|
|
49
49
|
presetStyle,
|
|
50
50
|
children: [],
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { SlotComponentIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { SlotComponentIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
|
|
3
3
|
|
|
4
4
|
export const meta: WsComponentMeta = {
|
|
5
5
|
category: "general",
|
|
6
6
|
type: "container",
|
|
7
7
|
label: "Slot",
|
|
8
|
-
|
|
8
|
+
icon: SlotComponentIcon,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const propsMeta: WsComponentPropsMeta = {
|