@webstudio-is/react-sdk 0.65.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.
Files changed (155) hide show
  1. package/lib/app/custom-components/form.ws.js +2 -2
  2. package/lib/app/custom-components/image.js +7 -13
  3. package/lib/app/params.js +1 -0
  4. package/lib/cjs/app/custom-components/form.ws.js +2 -2
  5. package/lib/cjs/app/custom-components/image.js +3 -12
  6. package/lib/cjs/app/params.js +1 -0
  7. package/lib/cjs/components/__generated__/html.props.js +31 -0
  8. package/lib/cjs/components/blockquote.ws.js +2 -2
  9. package/lib/cjs/components/body.ws.js +2 -2
  10. package/lib/cjs/components/bold.ws.js +2 -2
  11. package/lib/cjs/components/box.ws.js +2 -2
  12. package/lib/cjs/components/button.ws.js +2 -2
  13. package/lib/cjs/components/checkbox-field.ws.js +2 -2
  14. package/lib/cjs/components/checkbox.ws.js +2 -2
  15. package/lib/cjs/components/code.ws.js +2 -2
  16. package/lib/cjs/components/component-meta.js +2 -2
  17. package/lib/cjs/components/components-utils.js +1 -43
  18. package/lib/cjs/components/components.js +2 -0
  19. package/lib/cjs/components/error-message.ws.js +2 -2
  20. package/lib/cjs/components/form.ws.js +2 -2
  21. package/lib/cjs/components/fragment.ws.js +1 -1
  22. package/lib/cjs/components/heading.ws.js +2 -2
  23. package/lib/cjs/components/html.js +80 -0
  24. package/lib/cjs/components/html.ws.js +43 -0
  25. package/lib/cjs/components/image.ws.js +2 -2
  26. package/lib/cjs/components/index.js +7 -53
  27. package/lib/cjs/components/input.ws.js +2 -2
  28. package/lib/cjs/components/italic.ws.js +2 -2
  29. package/lib/cjs/components/label.ws.js +2 -2
  30. package/lib/cjs/components/link-block.ws.js +2 -2
  31. package/lib/cjs/components/link.ws.js +2 -2
  32. package/lib/cjs/components/list-item.ws.js +2 -2
  33. package/lib/cjs/components/list.ws.js +2 -2
  34. package/lib/cjs/components/paragraph.ws.js +2 -2
  35. package/lib/cjs/components/radio-button-field.ws.js +2 -2
  36. package/lib/cjs/components/radio-button.ws.js +2 -2
  37. package/lib/cjs/components/separator.ws.js +2 -2
  38. package/lib/cjs/components/slot.ws.js +2 -2
  39. package/lib/cjs/components/span.ws.js +2 -2
  40. package/lib/cjs/components/subscript.ws.js +2 -2
  41. package/lib/cjs/components/success-message.ws.js +2 -2
  42. package/lib/cjs/components/superscript.ws.js +2 -2
  43. package/lib/cjs/components/text-block.ws.js +2 -2
  44. package/lib/cjs/components/textarea.ws.js +2 -2
  45. package/lib/cjs/css/css.js +2 -5
  46. package/lib/cjs/css/normalize.js +1 -1
  47. package/lib/cjs/css/presets.js +8 -1
  48. package/lib/cjs/tree/create-elements-tree.js +2 -4
  49. package/lib/components/__generated__/html.props.js +11 -0
  50. package/lib/components/blockquote.ws.js +2 -2
  51. package/lib/components/body.ws.js +2 -2
  52. package/lib/components/bold.ws.js +2 -2
  53. package/lib/components/box.ws.js +2 -2
  54. package/lib/components/button.ws.js +2 -2
  55. package/lib/components/checkbox-field.ws.js +2 -2
  56. package/lib/components/checkbox.ws.js +2 -2
  57. package/lib/components/code.ws.js +2 -2
  58. package/lib/components/component-meta.js +3 -3
  59. package/lib/components/components-utils.js +1 -43
  60. package/lib/components/components.js +2 -0
  61. package/lib/components/error-message.ws.js +2 -2
  62. package/lib/components/form.ws.js +2 -2
  63. package/lib/components/fragment.ws.js +1 -1
  64. package/lib/components/heading.ws.js +2 -2
  65. package/lib/components/html.js +65 -0
  66. package/lib/components/html.ws.js +23 -0
  67. package/lib/components/image.ws.js +2 -2
  68. package/lib/components/index.js +7 -53
  69. package/lib/components/input.ws.js +2 -2
  70. package/lib/components/italic.ws.js +2 -2
  71. package/lib/components/label.ws.js +2 -2
  72. package/lib/components/link-block.ws.js +2 -2
  73. package/lib/components/link.ws.js +2 -2
  74. package/lib/components/list-item.ws.js +2 -2
  75. package/lib/components/list.ws.js +2 -2
  76. package/lib/components/paragraph.ws.js +2 -2
  77. package/lib/components/radio-button-field.ws.js +2 -2
  78. package/lib/components/radio-button.ws.js +2 -2
  79. package/lib/components/separator.ws.js +2 -2
  80. package/lib/components/slot.ws.js +2 -2
  81. package/lib/components/span.ws.js +2 -2
  82. package/lib/components/subscript.ws.js +2 -2
  83. package/lib/components/success-message.ws.js +2 -2
  84. package/lib/components/superscript.ws.js +2 -2
  85. package/lib/components/text-block.ws.js +2 -2
  86. package/lib/components/textarea.ws.js +2 -2
  87. package/lib/css/css.js +2 -5
  88. package/lib/css/normalize.js +2 -2
  89. package/lib/css/presets.js +8 -1
  90. package/lib/tree/create-elements-tree.js +2 -4
  91. package/lib/types/app/params.d.ts +22 -1
  92. package/lib/types/components/__generated__/html.props.d.ts +2 -0
  93. package/lib/types/components/component-meta.d.ts +1785 -10
  94. package/lib/types/components/components-utils.d.ts +6 -3
  95. package/lib/types/components/components.d.ts +1 -0
  96. package/lib/types/components/html.d.ts +7 -0
  97. package/lib/types/components/html.stories.d.ts +11 -0
  98. package/lib/types/components/html.ws.d.ts +3 -0
  99. package/lib/types/components/index.d.ts +2 -2
  100. package/lib/types/context.d.ts +1 -0
  101. package/lib/types/css/css.d.ts +2 -0
  102. package/lib/types/css/presets.d.ts +1 -0
  103. package/lib/types/tree/create-elements-tree.d.ts +2 -2
  104. package/package.json +13 -12
  105. package/src/app/custom-components/form.ws.tsx +2 -2
  106. package/src/app/custom-components/image.tsx +7 -13
  107. package/src/app/params.ts +23 -1
  108. package/src/components/__generated__/html.props.ts +10 -0
  109. package/src/components/blockquote.ws.tsx +2 -2
  110. package/src/components/body.ws.tsx +2 -2
  111. package/src/components/bold.ws.tsx +2 -2
  112. package/src/components/box.ws.ts +2 -2
  113. package/src/components/button.ws.tsx +2 -2
  114. package/src/components/checkbox-field.ws.tsx +2 -2
  115. package/src/components/checkbox.ws.tsx +2 -2
  116. package/src/components/code.ws.tsx +2 -2
  117. package/src/components/component-meta.ts +3 -6
  118. package/src/components/components-utils.ts +14 -58
  119. package/src/components/components.ts +1 -0
  120. package/src/components/error-message.ws.tsx +2 -2
  121. package/src/components/form.ws.tsx +2 -2
  122. package/src/components/fragment.ws.ts +1 -1
  123. package/src/components/heading.ws.tsx +2 -2
  124. package/src/components/html.stories.tsx +16 -0
  125. package/src/components/html.tsx +96 -0
  126. package/src/components/html.ws.ts +22 -0
  127. package/src/components/image.ws.tsx +2 -2
  128. package/src/components/index.ts +6 -83
  129. package/src/components/input.ws.tsx +2 -2
  130. package/src/components/italic.ws.tsx +2 -2
  131. package/src/components/label.ws.tsx +2 -2
  132. package/src/components/link-block.ws.tsx +2 -2
  133. package/src/components/link.ws.tsx +2 -2
  134. package/src/components/list-item.ws.tsx +2 -2
  135. package/src/components/list.ws.tsx +2 -2
  136. package/src/components/paragraph.ws.tsx +2 -2
  137. package/src/components/radio-button-field.ws.tsx +2 -2
  138. package/src/components/radio-button.ws.tsx +2 -2
  139. package/src/components/separator.ws.tsx +2 -2
  140. package/src/components/slot.ws.ts +2 -2
  141. package/src/components/span.ws.tsx +2 -2
  142. package/src/components/subscript.ws.tsx +2 -2
  143. package/src/components/success-message.ws.tsx +2 -2
  144. package/src/components/superscript.ws.tsx +2 -2
  145. package/src/components/text-block.ws.tsx +2 -2
  146. package/src/components/textarea.ws.tsx +2 -2
  147. package/src/context.tsx +1 -0
  148. package/src/css/css.ts +4 -5
  149. package/src/css/normalize.ts +2 -2
  150. package/src/css/presets.ts +7 -0
  151. package/src/tree/create-elements-tree.tsx +3 -5
  152. package/lib/cjs/tree/session-storage-polyfill.js +0 -65
  153. package/lib/tree/session-storage-polyfill.js +0 -45
  154. package/lib/types/tree/session-storage-polyfill.d.ts +0 -2
  155. package/src/tree/session-storage-polyfill.tsx +0 -50
@@ -1,8 +1,11 @@
1
- import type { forwardRef } from "react";
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
- export declare const getComponentNames: () => ComponentName[];
5
- type AnyComponent = ReturnType<typeof forwardRef<any, any>>;
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
@@ -7,6 +7,7 @@
7
7
  */
8
8
  export { Slot } from "./slot";
9
9
  export { Fragment } from "./fragment";
10
+ export { Html } from "./html";
10
11
  export { Body } from "./body";
11
12
  export { Box } from "./box";
12
13
  export { TextBlock } from "./text-block";
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ code: string;
4
+ executeScriptInCanvas: boolean;
5
+ };
6
+ export declare const Html: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<HTMLDivElement>>;
7
+ export {};
@@ -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>>>;
@@ -0,0 +1,3 @@
1
+ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
2
+ export declare const meta: WsComponentMeta;
3
+ export declare const propsMeta: WsComponentPropsMeta;
@@ -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 getComponentPropsMeta: (name: string) => WsComponentPropsMeta | undefined;
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
  }>;
@@ -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>;
@@ -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;
@@ -1,2 +1,3 @@
1
1
  import type { Styles } from "./normalize";
2
2
  export declare const borders: Styles;
3
+ export declare const outline: Styles;
@@ -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, sandbox, propsByInstanceIdStore, assetsStore, pagesStore, Component, getComponent, }: {
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.65.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.65.0",
39
- "@webstudio-is/css-data": "^0.65.0",
40
- "@webstudio-is/css-engine": "^0.65.0",
41
- "@webstudio-is/css-vars": "^0.65.0",
42
- "@webstudio-is/fonts": "^0.65.0",
43
- "@webstudio-is/generate-arg-types": "^0.65.0",
44
- "@webstudio-is/icons": "^0.65.0",
45
- "@webstudio-is/image": "^0.65.0",
46
- "@webstudio-is/prisma-client": "^0.65.0",
47
- "@webstudio-is/project-build": "^0.65.0",
48
- "@webstudio-is/form-handlers": "^0.65.0"
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
- Icon: FormIcon,
22
+ icon: FormIcon,
23
23
  presetStyle,
24
24
  states: [
25
25
  { selector: "[data-state=error]", label: "Error" },
@@ -4,7 +4,10 @@ import {
4
4
  type ComponentPropsWithoutRef,
5
5
  type ElementRef,
6
6
  } from "react";
7
- import { Image as WebstudioImage, loaders } from "@webstudio-is/image";
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
- if (asset === undefined) {
23
- return null;
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
- resizeOrigin?: string;
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
- Icon: BlockquoteIcon,
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
- Icon: BodyIcon,
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
- Icon: BoldIcon,
19
+ icon: BoldIcon,
20
20
  states: defaultStates,
21
21
  presetStyle,
22
22
  };
@@ -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
- Icon: BoxIcon,
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,
@@ -17,7 +17,7 @@ export const meta: WsComponentMeta = {
17
17
  category: "forms",
18
18
  type: "container",
19
19
  label: "Button",
20
- Icon: ButtonElementIcon,
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,
@@ -20,7 +20,7 @@ export const meta: WsComponentMeta = {
20
20
  category: "forms",
21
21
  type: "container",
22
22
  label: "Checkbox",
23
- Icon: CheckboxCheckedIcon,
23
+ icon: CheckboxCheckedIcon,
24
24
  states: defaultStates,
25
25
  presetStyle,
26
26
  children: [
@@ -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,
@@ -22,7 +22,7 @@ const presetStyle = {
22
22
  export const meta: WsComponentMeta = {
23
23
  type: "control",
24
24
  label: "Checkbox Input",
25
- Icon: CheckboxCheckedIcon,
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
- Icon: CodeIcon,
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
- Icon: z.function(),
63
- presetStyle: z.optional(z.any()),
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" | "Icon"
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 = ReturnType<typeof forwardRef<any, any>>;
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 AnyComponent)
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 AnyComponent)
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 { Html } from "./html";
10
11
  export { Body } from "./body";
11
12
  export { Box } from "./box";
12
13
  export { TextBlock } from "./text-block";
@@ -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
- Icon: BoxIcon,
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
- Icon: FormIcon,
23
+ icon: FormIcon,
24
24
  states: defaultStates,
25
25
  presetStyle,
26
26
  children: [
@@ -3,7 +3,7 @@ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
3
  export const meta: WsComponentMeta = {
4
4
  type: "container",
5
5
  label: "Fragment",
6
- Icon: () => null,
6
+ icon: "",
7
7
  };
8
8
 
9
9
  export const propsMeta: WsComponentPropsMeta = {
@@ -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
- Icon: HeadingIcon,
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
+ };