@webstudio-is/react-sdk 0.64.0 → 0.66.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 +3 -3
- package/lib/app/custom-components/image.js +7 -13
- package/lib/app/params.js +1 -0
- package/lib/cjs/app/custom-components/form.ws.js +3 -3
- package/lib/cjs/app/custom-components/image.js +3 -12
- package/lib/cjs/app/params.js +1 -0
- package/lib/cjs/components/__generated__/html.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 +3 -3
- package/lib/cjs/components/checkbox-field.ws.js +4 -3
- package/lib/cjs/components/checkbox.ws.js +3 -3
- package/lib/cjs/components/code.ws.js +2 -2
- package/lib/cjs/components/component-meta.js +2 -2
- package/lib/cjs/components/components-utils.js +1 -43
- package/lib/cjs/components/components.js +2 -0
- package/lib/cjs/components/error-message.ws.js +2 -2
- package/lib/cjs/components/form.ws.js +3 -3
- package/lib/cjs/components/fragment.ws.js +1 -1
- package/lib/cjs/components/heading.ws.js +2 -2
- package/lib/cjs/components/html.js +80 -0
- package/lib/cjs/components/html.ws.js +43 -0
- package/lib/cjs/components/image.ws.js +2 -2
- package/lib/cjs/components/index.js +7 -53
- package/lib/cjs/components/input.ws.js +3 -3
- 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 +4 -3
- package/lib/cjs/components/radio-button.ws.js +3 -3
- 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/embed-template.js +2 -0
- package/lib/cjs/tree/create-elements-tree.js +2 -4
- package/lib/components/__generated__/html.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 +3 -3
- package/lib/components/checkbox-field.ws.js +4 -3
- package/lib/components/checkbox.ws.js +3 -3
- package/lib/components/code.ws.js +2 -2
- package/lib/components/component-meta.js +3 -3
- package/lib/components/components-utils.js +1 -43
- package/lib/components/components.js +2 -0
- package/lib/components/error-message.ws.js +2 -2
- package/lib/components/form.ws.js +3 -3
- package/lib/components/fragment.ws.js +1 -1
- package/lib/components/heading.ws.js +2 -2
- package/lib/components/html.js +65 -0
- package/lib/components/html.ws.js +23 -0
- package/lib/components/image.ws.js +2 -2
- package/lib/components/index.js +7 -53
- package/lib/components/input.ws.js +3 -3
- 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 +4 -3
- package/lib/components/radio-button.ws.js +3 -3
- 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/embed-template.js +2 -0
- package/lib/tree/create-elements-tree.js +2 -4
- package/lib/types/app/params.d.ts +22 -1
- package/lib/types/components/__generated__/html.props.d.ts +2 -0
- 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 +1 -0
- package/lib/types/components/html.d.ts +7 -0
- package/lib/types/components/html.stories.d.ts +11 -0
- package/lib/types/components/html.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/embed-template.d.ts +1 -0
- package/lib/types/tree/create-elements-tree.d.ts +2 -2
- package/package.json +13 -12
- package/src/app/custom-components/form.ws.tsx +3 -3
- package/src/app/custom-components/image.tsx +7 -13
- package/src/app/params.ts +23 -1
- package/src/components/__generated__/html.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 +3 -3
- package/src/components/checkbox-field.ws.tsx +4 -3
- package/src/components/checkbox.ws.tsx +3 -3
- package/src/components/code.ws.tsx +2 -2
- package/src/components/component-meta.ts +3 -6
- package/src/components/components-utils.ts +14 -58
- package/src/components/components.ts +1 -0
- package/src/components/error-message.ws.tsx +2 -2
- package/src/components/form.ws.tsx +3 -3
- package/src/components/fragment.ws.ts +1 -1
- package/src/components/heading.ws.tsx +2 -2
- package/src/components/html.stories.tsx +16 -0
- package/src/components/html.tsx +96 -0
- package/src/components/html.ws.ts +22 -0
- package/src/components/image.ws.tsx +2 -2
- package/src/components/index.ts +6 -83
- package/src/components/input.ws.tsx +3 -3
- 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 +4 -3
- package/src/components/radio-button.ws.tsx +3 -3
- 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/embed-template.ts +3 -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/tree/session-storage-polyfill.tsx +0 -50
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import * as components from "./components";
|
|
3
|
+
import { componentAttribute, idAttribute } from "../tree";
|
|
3
4
|
export type ComponentName = keyof typeof components;
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
type AnyComponent = React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
|
|
6
|
+
[componentAttribute]: string;
|
|
7
|
+
[idAttribute]: string;
|
|
8
|
+
} & React.RefAttributes<HTMLElement>>;
|
|
6
9
|
/**
|
|
7
10
|
* Now used only in builder app
|
|
8
11
|
* @todo Consider using the same approach in the builder app as in the published apps . A dynamic import is needed
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ComponentStory, ComponentMeta } from "@storybook/react";
|
|
3
|
+
declare const _default: ComponentMeta<import("react").ForwardRefExoticComponent<{
|
|
4
|
+
code: string;
|
|
5
|
+
executeScriptInCanvas: boolean;
|
|
6
|
+
} & import("react").RefAttributes<HTMLDivElement>>>;
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare const Html: ComponentStory<import("react").ForwardRefExoticComponent<{
|
|
9
|
+
code: string;
|
|
10
|
+
executeScriptInCanvas: boolean;
|
|
11
|
+
} & import("react").RefAttributes<HTMLDivElement>>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
|
|
2
2
|
import type { ComponentName } from "./components-utils";
|
|
3
|
+
export declare const defaultMetas: Record<string, WsComponentMeta>;
|
|
3
4
|
export declare const getComponentMeta: (name: string) => WsComponentMeta | undefined;
|
|
4
5
|
export declare const registerComponentMetas: (overrides: Record<string, Partial<WsComponentMeta>>) => void;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const registerComponentPropsMetas: (metas: Record<string, WsComponentPropsMeta>) => void;
|
|
6
|
+
export declare const defaultPropsMetas: Record<string, WsComponentPropsMeta>;
|
|
7
7
|
type RegisteredComponents = Partial<{
|
|
8
8
|
[name in ComponentName]: {};
|
|
9
9
|
}>;
|
package/lib/types/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ReadableAtom } from "nanostores";
|
|
|
3
3
|
import type { Assets } from "@webstudio-is/asset-uploader";
|
|
4
4
|
import type { Pages, PropsByInstanceId } from "./props";
|
|
5
5
|
export declare const ReactSdkContext: import("react").Context<{
|
|
6
|
+
renderer?: "canvas" | undefined;
|
|
6
7
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
7
8
|
assetsStore: ReadableAtom<Assets>;
|
|
8
9
|
pagesStore: ReadableAtom<Pages>;
|
package/lib/types/css/css.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type TransformValue } from "@webstudio-is/css-engine";
|
|
2
2
|
import type { Asset } from "@webstudio-is/asset-uploader";
|
|
3
3
|
import type { Build } from "@webstudio-is/project-build";
|
|
4
|
+
import type { WsComponentMeta } from "../components/component-meta";
|
|
4
5
|
type Data = {
|
|
5
6
|
assets: Asset[];
|
|
6
7
|
breakpoints?: Build["breakpoints"];
|
|
7
8
|
styles?: Build["styles"];
|
|
8
9
|
styleSourceSelections?: Build["styleSourceSelections"];
|
|
10
|
+
componentMetas: Map<string, WsComponentMeta>;
|
|
9
11
|
};
|
|
10
12
|
type CssOptions = {
|
|
11
13
|
assetBaseUrl: string;
|
|
@@ -1436,6 +1436,7 @@ export type EmbedTemplateStyleDecl = z.infer<typeof EmbedTemplateStyleDecl>;
|
|
|
1436
1436
|
export type EmbedTemplateInstance = {
|
|
1437
1437
|
type: "instance";
|
|
1438
1438
|
component: string;
|
|
1439
|
+
label?: string;
|
|
1439
1440
|
props?: EmbedTemplateProp[];
|
|
1440
1441
|
styles?: EmbedTemplateStyleDecl[];
|
|
1441
1442
|
children: Array<EmbedTemplateInstance | EmbedTemplateText>;
|
|
@@ -5,7 +5,8 @@ import type { Instance, Instances } from "@webstudio-is/project-build";
|
|
|
5
5
|
import type { GetComponent } from "../components/components-utils";
|
|
6
6
|
import type { Pages, PropsByInstanceId } from "../props";
|
|
7
7
|
import type { WebstudioComponent } from "./webstudio-component";
|
|
8
|
-
export declare const createElementsTree: ({ instances, rootInstanceId,
|
|
8
|
+
export declare const createElementsTree: ({ renderer, instances, rootInstanceId, propsByInstanceIdStore, assetsStore, pagesStore, Component, getComponent, }: {
|
|
9
|
+
renderer?: "canvas" | undefined;
|
|
9
10
|
instances: Map<string, {
|
|
10
11
|
label?: string | undefined;
|
|
11
12
|
type: "instance";
|
|
@@ -20,7 +21,6 @@ export declare const createElementsTree: ({ instances, rootInstanceId, sandbox,
|
|
|
20
21
|
})[];
|
|
21
22
|
}>;
|
|
22
23
|
rootInstanceId: Instance["id"];
|
|
23
|
-
sandbox?: boolean | undefined;
|
|
24
24
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
25
25
|
assetsStore: ReadableAtom<Assets>;
|
|
26
26
|
pagesStore: ReadableAtom<Pages>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.66.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -30,22 +30,23 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@nanostores/react": "^0.4.1",
|
|
33
|
+
"@react-aria/utils": "^3.13.3",
|
|
33
34
|
"detect-font": "^0.1.5",
|
|
34
35
|
"html-tags": "^3.2.0",
|
|
35
36
|
"nanoevents": "^7.0.1",
|
|
36
37
|
"nanoid": "^3.2.0",
|
|
37
38
|
"nanostores": "^0.7.1",
|
|
38
|
-
"@webstudio-is/asset-uploader": "^0.
|
|
39
|
-
"@webstudio-is/css-data": "^0.
|
|
40
|
-
"@webstudio-is/css-engine": "^0.
|
|
41
|
-
"@webstudio-is/css-vars": "^0.
|
|
42
|
-
"@webstudio-is/fonts": "^0.
|
|
43
|
-
"@webstudio-is/
|
|
44
|
-
"@webstudio-is/
|
|
45
|
-
"@webstudio-is/
|
|
46
|
-
"@webstudio-is/
|
|
47
|
-
"@webstudio-is/
|
|
48
|
-
"@webstudio-is/
|
|
39
|
+
"@webstudio-is/asset-uploader": "^0.66.0",
|
|
40
|
+
"@webstudio-is/css-data": "^0.66.0",
|
|
41
|
+
"@webstudio-is/css-engine": "^0.66.0",
|
|
42
|
+
"@webstudio-is/css-vars": "^0.66.0",
|
|
43
|
+
"@webstudio-is/fonts": "^0.66.0",
|
|
44
|
+
"@webstudio-is/form-handlers": "^0.66.0",
|
|
45
|
+
"@webstudio-is/generate-arg-types": "^0.66.0",
|
|
46
|
+
"@webstudio-is/icons": "^0.66.0",
|
|
47
|
+
"@webstudio-is/image": "^0.66.0",
|
|
48
|
+
"@webstudio-is/prisma-client": "^0.66.0",
|
|
49
|
+
"@webstudio-is/project-build": "^0.66.0"
|
|
49
50
|
},
|
|
50
51
|
"exports": {
|
|
51
52
|
".": {
|
|
@@ -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 type {
|
|
4
4
|
PresetStyle,
|
|
@@ -19,7 +19,7 @@ export const meta: WsComponentMeta = {
|
|
|
19
19
|
category: "forms",
|
|
20
20
|
type: "container",
|
|
21
21
|
label: "Form",
|
|
22
|
-
|
|
22
|
+
icon: FormIcon,
|
|
23
23
|
presetStyle,
|
|
24
24
|
states: [
|
|
25
25
|
{ selector: "[data-state=error]", label: "Error" },
|
|
@@ -45,7 +45,7 @@ export const meta: WsComponentMeta = {
|
|
|
45
45
|
{
|
|
46
46
|
type: "instance",
|
|
47
47
|
component: "Input",
|
|
48
|
-
props: [{ type: "string", name: "
|
|
48
|
+
props: [{ type: "string", name: "name", value: "email" }],
|
|
49
49
|
children: [],
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -4,7 +4,10 @@ import {
|
|
|
4
4
|
type ComponentPropsWithoutRef,
|
|
5
5
|
type ElementRef,
|
|
6
6
|
} from "react";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
Image as WebstudioImage,
|
|
9
|
+
createImageLoader,
|
|
10
|
+
} from "@webstudio-is/image";
|
|
8
11
|
import { Image as SdkImage } from "../../components/image";
|
|
9
12
|
import { usePropAsset, getInstanceIdFromComponentProps } from "../../props";
|
|
10
13
|
import { getParams } from "../params";
|
|
@@ -16,20 +19,11 @@ type Props = ComponentPropsWithoutRef<typeof WebstudioImage>;
|
|
|
16
19
|
export const Image = forwardRef<ElementRef<typeof defaultTag>, Props>(
|
|
17
20
|
(props, ref) => {
|
|
18
21
|
const asset = usePropAsset(getInstanceIdFromComponentProps(props), "src");
|
|
19
|
-
const params = getParams();
|
|
20
22
|
|
|
21
23
|
const loader = useMemo(() => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (asset.location === "REMOTE") {
|
|
26
|
-
return loaders.cloudflareImageLoader({
|
|
27
|
-
resizeOrigin: params.resizeOrigin,
|
|
28
|
-
cdnUrl: params.assetBaseUrl,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return loaders.localImageLoader({ publicPath: params.assetBaseUrl });
|
|
32
|
-
}, [asset, params]);
|
|
24
|
+
const params = getParams();
|
|
25
|
+
return createImageLoader({ imageBaseUrl: params.imageBaseUrl });
|
|
26
|
+
}, []);
|
|
33
27
|
|
|
34
28
|
const src = asset?.name ?? props.src;
|
|
35
29
|
|
package/src/app/params.ts
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
export type Params = {
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Base url ir base path for images with ending slash.
|
|
4
|
+
* Used for configuring image with different sizes.
|
|
5
|
+
* Concatinated with "name?width=&quality=&format=".
|
|
6
|
+
*
|
|
7
|
+
* For example
|
|
8
|
+
* /asset/image/ used by default in builder
|
|
9
|
+
* https://image-transform.wstd.io/cdn-cgi/image/
|
|
10
|
+
* https://webstudio.is/cdn-cgi/image/
|
|
11
|
+
*/
|
|
12
|
+
imageBaseUrl: string;
|
|
13
|
+
/**
|
|
14
|
+
* Base url or base path for any asset with ending slash.
|
|
15
|
+
* Used to load assets like fonts or images in styles
|
|
16
|
+
* Concatinated with "name".
|
|
17
|
+
*
|
|
18
|
+
* For example
|
|
19
|
+
* /s/uploads/
|
|
20
|
+
* /asset/file/
|
|
21
|
+
* https://assets-dev.webstudio.is/
|
|
22
|
+
* https://assets.webstudio.is/
|
|
23
|
+
*/
|
|
3
24
|
assetBaseUrl: string;
|
|
4
25
|
};
|
|
5
26
|
|
|
6
27
|
let params: undefined | Params;
|
|
7
28
|
|
|
8
29
|
const emptyParams: Params = {
|
|
30
|
+
imageBaseUrl: "/",
|
|
9
31
|
assetBaseUrl: "/",
|
|
10
32
|
};
|
|
11
33
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
2
|
+
|
|
3
|
+
export const props: Record<string, PropMeta> = {
|
|
4
|
+
code: { required: true, control: "text", type: "string" },
|
|
5
|
+
executeScriptInCanvas: {
|
|
6
|
+
required: true,
|
|
7
|
+
control: "boolean",
|
|
8
|
+
type: "boolean",
|
|
9
|
+
},
|
|
10
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockquoteIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { BlockquoteIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import type { defaultTag } from "./blockquote";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -63,7 +63,7 @@ export const meta: WsComponentMeta = {
|
|
|
63
63
|
category: "typography",
|
|
64
64
|
type: "rich-text",
|
|
65
65
|
label: "Blockquote",
|
|
66
|
-
|
|
66
|
+
icon: BlockquoteIcon,
|
|
67
67
|
states: defaultStates,
|
|
68
68
|
presetStyle,
|
|
69
69
|
children: [{ type: "text", value: "Blockquote you can edit" }],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BodyIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { BodyIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { body } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -41,7 +41,7 @@ const presetStyle = {
|
|
|
41
41
|
export const meta: WsComponentMeta = {
|
|
42
42
|
type: "container",
|
|
43
43
|
label: "Body",
|
|
44
|
-
|
|
44
|
+
icon: BodyIcon,
|
|
45
45
|
states: defaultStates,
|
|
46
46
|
presetStyle,
|
|
47
47
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoldIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { BoldIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
defaultStates,
|
|
4
4
|
type PresetStyle,
|
|
@@ -16,7 +16,7 @@ const presetStyle = {
|
|
|
16
16
|
export const meta: WsComponentMeta = {
|
|
17
17
|
type: "rich-text-child",
|
|
18
18
|
label: "Bold Text",
|
|
19
|
-
|
|
19
|
+
icon: BoldIcon,
|
|
20
20
|
states: defaultStates,
|
|
21
21
|
presetStyle,
|
|
22
22
|
};
|
package/src/components/box.ws.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoxIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { BoxIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
defaultStates,
|
|
4
4
|
type PresetStyle,
|
|
@@ -40,7 +40,7 @@ export const meta: WsComponentMeta = {
|
|
|
40
40
|
category: "general",
|
|
41
41
|
type: "container",
|
|
42
42
|
label: "Box",
|
|
43
|
-
|
|
43
|
+
icon: BoxIcon,
|
|
44
44
|
states: defaultStates,
|
|
45
45
|
presetStyle,
|
|
46
46
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ButtonElementIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { ButtonElementIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import { button } from "../css/normalize";
|
|
3
3
|
import {
|
|
4
4
|
defaultStates,
|
|
@@ -14,10 +14,10 @@ const presetStyle = {
|
|
|
14
14
|
} satisfies PresetStyle<typeof defaultTag>;
|
|
15
15
|
|
|
16
16
|
export const meta: WsComponentMeta = {
|
|
17
|
-
category: "
|
|
17
|
+
category: "forms",
|
|
18
18
|
type: "container",
|
|
19
19
|
label: "Button",
|
|
20
|
-
|
|
20
|
+
icon: ButtonElementIcon,
|
|
21
21
|
presetStyle,
|
|
22
22
|
states: [
|
|
23
23
|
...defaultStates,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CheckboxCheckedIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { CheckboxCheckedIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
type WsComponentMeta,
|
|
4
4
|
type WsComponentPropsMeta,
|
|
@@ -19,8 +19,8 @@ const presetStyle = {
|
|
|
19
19
|
export const meta: WsComponentMeta = {
|
|
20
20
|
category: "forms",
|
|
21
21
|
type: "container",
|
|
22
|
-
label: "Checkbox
|
|
23
|
-
|
|
22
|
+
label: "Checkbox",
|
|
23
|
+
icon: CheckboxCheckedIcon,
|
|
24
24
|
states: defaultStates,
|
|
25
25
|
presetStyle,
|
|
26
26
|
children: [
|
|
@@ -28,6 +28,7 @@ export const meta: WsComponentMeta = {
|
|
|
28
28
|
{
|
|
29
29
|
type: "instance",
|
|
30
30
|
component: "TextBlock",
|
|
31
|
+
label: "Checkbox Label",
|
|
31
32
|
props: [],
|
|
32
33
|
children: [{ type: "text", value: "Checkbox" }],
|
|
33
34
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CheckboxCheckedIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { CheckboxCheckedIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
type WsComponentMeta,
|
|
4
4
|
type WsComponentPropsMeta,
|
|
@@ -21,8 +21,8 @@ const presetStyle = {
|
|
|
21
21
|
|
|
22
22
|
export const meta: WsComponentMeta = {
|
|
23
23
|
type: "control",
|
|
24
|
-
label: "Checkbox",
|
|
25
|
-
|
|
24
|
+
label: "Checkbox Input",
|
|
25
|
+
icon: CheckboxCheckedIcon,
|
|
26
26
|
presetStyle,
|
|
27
27
|
states: [
|
|
28
28
|
...defaultStates,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CodeIcon } from "@webstudio-is/icons";
|
|
1
|
+
import { CodeIcon } from "@webstudio-is/icons/svg";
|
|
2
2
|
import {
|
|
3
3
|
defaultStates,
|
|
4
4
|
type PresetStyle,
|
|
@@ -39,7 +39,7 @@ export const meta: WsComponentMeta = {
|
|
|
39
39
|
category: "general",
|
|
40
40
|
type: "rich-text",
|
|
41
41
|
label: "Code",
|
|
42
|
-
|
|
42
|
+
icon: CodeIcon,
|
|
43
43
|
states: defaultStates,
|
|
44
44
|
presetStyle,
|
|
45
45
|
children: [{ type: "text", value: "Code you can edit" }],
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { FunctionComponent } from "react";
|
|
3
|
-
import type { IconProps } from "@webstudio-is/icons";
|
|
4
2
|
import { PropMeta } from "@webstudio-is/generate-arg-types";
|
|
5
3
|
import type { htmlTags as HtmlTags } from "html-tags";
|
|
6
4
|
import { EmbedTemplateStyleDecl, WsEmbedTemplate } from "../embed-template";
|
|
@@ -59,16 +57,15 @@ const WsComponentMeta = z.object({
|
|
|
59
57
|
]),
|
|
60
58
|
acceptedParents: z.optional(z.array(z.string())),
|
|
61
59
|
label: z.string(),
|
|
62
|
-
|
|
63
|
-
presetStyle: z.optional(z.
|
|
60
|
+
icon: z.string(),
|
|
61
|
+
presetStyle: z.optional(z.record(z.string(), EmbedTemplateStyleDecl)),
|
|
64
62
|
states: z.optional(z.array(ComponentState)),
|
|
65
63
|
children: z.optional(WsEmbedTemplate),
|
|
66
64
|
});
|
|
67
65
|
|
|
68
66
|
export type WsComponentMeta = Omit<
|
|
69
67
|
z.infer<typeof WsComponentMeta>,
|
|
70
|
-
"presetStyle"
|
|
68
|
+
"presetStyle"
|
|
71
69
|
> & {
|
|
72
70
|
presetStyle?: PresetStyle;
|
|
73
|
-
Icon: FunctionComponent<IconProps>;
|
|
74
71
|
};
|
|
@@ -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
|
|
|
@@ -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: [
|
|
@@ -43,7 +43,7 @@ export const meta: WsComponentMeta = {
|
|
|
43
43
|
{
|
|
44
44
|
type: "instance",
|
|
45
45
|
component: "Input",
|
|
46
|
-
props: [{ type: "string", name: "
|
|
46
|
+
props: [{ type: "string", name: "name", value: "email" }],
|
|
47
47
|
children: [],
|
|
48
48
|
},
|
|
49
49
|
{
|
|
@@ -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 { Html as HtmlPrimitive } from "./html";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "Components/Html",
|
|
6
|
+
component: HtmlPrimitive,
|
|
7
|
+
} as ComponentMeta<typeof HtmlPrimitive>;
|
|
8
|
+
|
|
9
|
+
const Template: ComponentStory<typeof HtmlPrimitive> = (args) => (
|
|
10
|
+
<HtmlPrimitive {...args} />
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const Html = Template.bind({});
|
|
14
|
+
Html.args = {
|
|
15
|
+
code: "<strong>custom code</strong>",
|
|
16
|
+
};
|