@webstudio-is/react-sdk 0.17.0 → 0.18.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 (39) hide show
  1. package/lib/cjs/components/body.ws.cjs +2 -2
  2. package/lib/cjs/components/box.ws.cjs +2 -2
  3. package/lib/cjs/components/component-type.cjs +1 -1
  4. package/lib/cjs/components/form.ws.cjs +2 -2
  5. package/lib/cjs/components/image.ws.cjs +2 -2
  6. package/lib/cjs/components/italic.ws.cjs +2 -2
  7. package/lib/cjs/components/link.ws.cjs +2 -2
  8. package/lib/cjs/components/text-block.ws.cjs +2 -2
  9. package/lib/cjs/css/breakpoints.cjs +1 -1
  10. package/lib/cjs/db/instance.cjs +9 -1
  11. package/lib/cjs/pubsub/create.cjs +12 -0
  12. package/lib/cjs/tree/create-elements-tree.cjs +2 -2
  13. package/lib/components/body.ws.js +2 -2
  14. package/lib/components/box.ws.js +2 -2
  15. package/lib/components/component-type.js +1 -1
  16. package/lib/components/form.ws.js +2 -2
  17. package/lib/components/image.ws.js +2 -2
  18. package/lib/components/italic.ws.js +2 -2
  19. package/lib/components/link.ws.js +2 -2
  20. package/lib/components/text-block.ws.js +2 -2
  21. package/lib/css/breakpoints.js +1 -1
  22. package/lib/db/instance.js +9 -1
  23. package/lib/pubsub/create.js +12 -0
  24. package/lib/tree/create-elements-tree.js +2 -2
  25. package/package.json +9 -9
  26. package/src/components/body.ws.tsx +2 -2
  27. package/src/components/box.ws.ts +2 -2
  28. package/src/components/component-type.ts +2 -2
  29. package/src/components/form.ws.tsx +2 -2
  30. package/src/components/image.ws.tsx +2 -2
  31. package/src/components/index.test.ts +1 -0
  32. package/src/components/italic.ws.tsx +2 -2
  33. package/src/components/link.ws.tsx +2 -2
  34. package/src/components/text-block.ws.tsx +2 -2
  35. package/src/css/breakpoints.ts +1 -1
  36. package/src/db/instance.ts +16 -2
  37. package/src/pubsub/create.ts +22 -0
  38. package/src/tree/create-elements-tree.tsx +7 -3
  39. package/src/user-props/types.ts +1 -2
@@ -29,7 +29,7 @@ __export(body_ws_exports, {
29
29
  module.exports = __toCommonJS(body_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_body_props = __toESM(require("./__generated__/body.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  marginTop: {
34
34
  type: "unit",
35
35
  unit: "px",
@@ -83,6 +83,6 @@ const meta = {
83
83
  label: "Body",
84
84
  Icon: import_icons.BodyIcon,
85
85
  props: import_body_props.default,
86
- defaultStyle
86
+ presetStyle
87
87
  };
88
88
  var body_ws_default = meta;
@@ -29,7 +29,7 @@ __export(box_ws_exports, {
29
29
  module.exports = __toCommonJS(box_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_box_props = __toESM(require("./__generated__/box.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  boxSizing: {
34
34
  type: "keyword",
35
35
  value: "border-box"
@@ -39,7 +39,7 @@ const meta = {
39
39
  type: "container",
40
40
  label: "Box",
41
41
  Icon: import_icons.SquareIcon,
42
- defaultStyle,
42
+ presetStyle,
43
43
  props: import_box_props.default
44
44
  };
45
45
  var box_ws_default = meta;
@@ -71,7 +71,7 @@ const WsComponentMeta = import_zod.z.lazy(
71
71
  ]),
72
72
  label: import_zod.z.string(),
73
73
  Icon: import_zod.z.any(),
74
- defaultStyle: import_zod.z.optional(import_zod.z.any()),
74
+ presetStyle: import_zod.z.optional(import_zod.z.any()),
75
75
  children: import_zod.z.optional(import_zod.z.array(import_zod.z.string())),
76
76
  props: Props,
77
77
  initialProps: import_zod.z.optional(import_zod.z.array(import_zod.z.string()))
@@ -29,7 +29,7 @@ __export(form_ws_exports, {
29
29
  module.exports = __toCommonJS(form_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_form_props = __toESM(require("./__generated__/form.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  minHeight: {
34
34
  type: "unit",
35
35
  unit: "px",
@@ -44,7 +44,7 @@ const meta = {
44
44
  type: "container",
45
45
  label: "Form",
46
46
  Icon: import_icons.FormIcon,
47
- defaultStyle,
47
+ presetStyle,
48
48
  props: import_form_props.default
49
49
  };
50
50
  var form_ws_default = meta;
@@ -29,7 +29,7 @@ __export(image_ws_exports, {
29
29
  module.exports = __toCommonJS(image_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_image_props = __toESM(require("./__generated__/image.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  maxWidth: {
34
34
  type: "unit",
35
35
  unit: "%",
@@ -44,7 +44,7 @@ const meta = {
44
44
  type: "embed",
45
45
  label: "Image",
46
46
  Icon: import_icons.ImageIcon,
47
- defaultStyle,
47
+ presetStyle,
48
48
  props: import_image_props.default,
49
49
  initialProps: ["src", "width", "height", "alt", "loading"]
50
50
  };
@@ -29,7 +29,7 @@ __export(italic_ws_exports, {
29
29
  module.exports = __toCommonJS(italic_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_italic_props = __toESM(require("./__generated__/italic.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  fontStyle: {
34
34
  type: "keyword",
35
35
  value: "italic"
@@ -39,7 +39,7 @@ const meta = {
39
39
  type: "rich-text-child",
40
40
  label: "Italic Text",
41
41
  Icon: import_icons.FontItalicIcon,
42
- defaultStyle,
42
+ presetStyle,
43
43
  props: import_italic_props.default
44
44
  };
45
45
  var italic_ws_default = meta;
@@ -29,7 +29,7 @@ __export(link_ws_exports, {
29
29
  module.exports = __toCommonJS(link_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_link_props = __toESM(require("./__generated__/link.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  minHeight: {
34
34
  type: "unit",
35
35
  unit: "em",
@@ -44,7 +44,7 @@ const meta = {
44
44
  type: "rich-text",
45
45
  label: "Link",
46
46
  Icon: import_icons.Link2Icon,
47
- defaultStyle,
47
+ presetStyle,
48
48
  children: ["Link text you can edit"],
49
49
  props: import_link_props.default
50
50
  };
@@ -29,7 +29,7 @@ __export(text_block_ws_exports, {
29
29
  module.exports = __toCommonJS(text_block_ws_exports);
30
30
  var import_icons = require("@webstudio-is/icons");
31
31
  var import_text_block_props = __toESM(require("./__generated__/text-block.props.json"), 1);
32
- const defaultStyle = {
32
+ const presetStyle = {
33
33
  minHeight: {
34
34
  type: "unit",
35
35
  unit: "em",
@@ -40,7 +40,7 @@ const meta = {
40
40
  type: "rich-text",
41
41
  label: "Text Block",
42
42
  Icon: import_icons.TextIcon,
43
- defaultStyle,
43
+ presetStyle,
44
44
  children: ["Block of text you can edit"],
45
45
  props: import_text_block_props.default
46
46
  };
@@ -22,7 +22,7 @@ __export(breakpoints_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(breakpoints_exports);
24
24
  const initialBreakpoints = [
25
- { label: "Mobile", minWidth: 360 },
25
+ { label: "Mobile", minWidth: 0 },
26
26
  { label: "Tablet", minWidth: 768 },
27
27
  { label: "Laptop", minWidth: 1024 },
28
28
  { label: "Desktop", minWidth: 1280 }
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var instance_exports = {};
20
20
  __export(instance_exports, {
21
21
  Instance: () => Instance,
22
+ Text: () => Text,
22
23
  toBaseInstance: () => toBaseInstance
23
24
  });
24
25
  module.exports = __toCommonJS(instance_exports);
@@ -31,11 +32,18 @@ const toBaseInstance = (instance) => {
31
32
  cssRules: instance.cssRules
32
33
  };
33
34
  };
35
+ const Text = import_zod.z.lazy(
36
+ () => import_zod.z.object({
37
+ type: import_zod.z.literal("text"),
38
+ value: import_zod.z.string()
39
+ })
40
+ );
34
41
  const Instance = import_zod.z.lazy(
35
42
  () => import_zod.z.object({
43
+ type: import_zod.z.literal("instance"),
36
44
  id: import_zod.z.string(),
37
45
  component: import_zod.z.string(),
38
- children: import_zod.z.array(import_zod.z.union([Instance, import_zod.z.string()])),
46
+ children: import_zod.z.array(import_zod.z.union([Instance, Text])),
39
47
  cssRules: import_zod.z.array(import_css_data.CssRule)
40
48
  })
41
49
  );
@@ -77,6 +77,18 @@ const createPubsub = () => {
77
77
  emitter.off("*", onAction);
78
78
  };
79
79
  }, [onAction]);
80
+ },
81
+ subscribe(type, onAction) {
82
+ emitter.on(type, onAction);
83
+ return () => {
84
+ emitter.off(type, onAction);
85
+ };
86
+ },
87
+ subscribeAll(onAction) {
88
+ emitter.on("*", onAction);
89
+ return () => {
90
+ emitter.off("*", onAction);
91
+ };
80
92
  }
81
93
  };
82
94
  };
@@ -59,8 +59,8 @@ const createInstanceChildrenElements = ({
59
59
  }) => {
60
60
  const elements = [];
61
61
  for (const child of children) {
62
- if (typeof child === "string") {
63
- elements.push(child);
62
+ if (child.type === "text") {
63
+ elements.push(child.value);
64
64
  continue;
65
65
  }
66
66
  const children2 = createInstanceChildrenElements({
@@ -1,6 +1,6 @@
1
1
  import { BodyIcon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/body.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  marginTop: {
5
5
  type: "unit",
6
6
  unit: "px",
@@ -54,7 +54,7 @@ const meta = {
54
54
  label: "Body",
55
55
  Icon: BodyIcon,
56
56
  props,
57
- defaultStyle
57
+ presetStyle
58
58
  };
59
59
  var body_ws_default = meta;
60
60
  export {
@@ -1,6 +1,6 @@
1
1
  import { SquareIcon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/box.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  boxSizing: {
5
5
  type: "keyword",
6
6
  value: "border-box"
@@ -10,7 +10,7 @@ const meta = {
10
10
  type: "container",
11
11
  label: "Box",
12
12
  Icon: SquareIcon,
13
- defaultStyle,
13
+ presetStyle,
14
14
  props
15
15
  };
16
16
  var box_ws_default = meta;
@@ -48,7 +48,7 @@ const WsComponentMeta = z.lazy(
48
48
  ]),
49
49
  label: z.string(),
50
50
  Icon: z.any(),
51
- defaultStyle: z.optional(z.any()),
51
+ presetStyle: z.optional(z.any()),
52
52
  children: z.optional(z.array(z.string())),
53
53
  props: Props,
54
54
  initialProps: z.optional(z.array(z.string()))
@@ -1,6 +1,6 @@
1
1
  import { FormIcon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/form.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  minHeight: {
5
5
  type: "unit",
6
6
  unit: "px",
@@ -15,7 +15,7 @@ const meta = {
15
15
  type: "container",
16
16
  label: "Form",
17
17
  Icon: FormIcon,
18
- defaultStyle,
18
+ presetStyle,
19
19
  props
20
20
  };
21
21
  var form_ws_default = meta;
@@ -1,6 +1,6 @@
1
1
  import { ImageIcon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/image.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  maxWidth: {
5
5
  type: "unit",
6
6
  unit: "%",
@@ -15,7 +15,7 @@ const meta = {
15
15
  type: "embed",
16
16
  label: "Image",
17
17
  Icon: ImageIcon,
18
- defaultStyle,
18
+ presetStyle,
19
19
  props,
20
20
  initialProps: ["src", "width", "height", "alt", "loading"]
21
21
  };
@@ -1,6 +1,6 @@
1
1
  import { FontItalicIcon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/italic.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  fontStyle: {
5
5
  type: "keyword",
6
6
  value: "italic"
@@ -10,7 +10,7 @@ const meta = {
10
10
  type: "rich-text-child",
11
11
  label: "Italic Text",
12
12
  Icon: FontItalicIcon,
13
- defaultStyle,
13
+ presetStyle,
14
14
  props
15
15
  };
16
16
  var italic_ws_default = meta;
@@ -1,6 +1,6 @@
1
1
  import { Link2Icon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/link.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  minHeight: {
5
5
  type: "unit",
6
6
  unit: "em",
@@ -15,7 +15,7 @@ const meta = {
15
15
  type: "rich-text",
16
16
  label: "Link",
17
17
  Icon: Link2Icon,
18
- defaultStyle,
18
+ presetStyle,
19
19
  children: ["Link text you can edit"],
20
20
  props
21
21
  };
@@ -1,6 +1,6 @@
1
1
  import { TextIcon } from "@webstudio-is/icons";
2
2
  import props from "./__generated__/text-block.props.json";
3
- const defaultStyle = {
3
+ const presetStyle = {
4
4
  minHeight: {
5
5
  type: "unit",
6
6
  unit: "em",
@@ -11,7 +11,7 @@ const meta = {
11
11
  type: "rich-text",
12
12
  label: "Text Block",
13
13
  Icon: TextIcon,
14
- defaultStyle,
14
+ presetStyle,
15
15
  children: ["Block of text you can edit"],
16
16
  props
17
17
  };
@@ -1,5 +1,5 @@
1
1
  const initialBreakpoints = [
2
- { label: "Mobile", minWidth: 360 },
2
+ { label: "Mobile", minWidth: 0 },
3
3
  { label: "Tablet", minWidth: 768 },
4
4
  { label: "Laptop", minWidth: 1024 },
5
5
  { label: "Desktop", minWidth: 1280 }
@@ -7,15 +7,23 @@ const toBaseInstance = (instance) => {
7
7
  cssRules: instance.cssRules
8
8
  };
9
9
  };
10
+ const Text = z.lazy(
11
+ () => z.object({
12
+ type: z.literal("text"),
13
+ value: z.string()
14
+ })
15
+ );
10
16
  const Instance = z.lazy(
11
17
  () => z.object({
18
+ type: z.literal("instance"),
12
19
  id: z.string(),
13
20
  component: z.string(),
14
- children: z.array(z.union([Instance, z.string()])),
21
+ children: z.array(z.union([Instance, Text])),
15
22
  cssRules: z.array(CssRule)
16
23
  })
17
24
  );
18
25
  export {
19
26
  Instance,
27
+ Text,
20
28
  toBaseInstance
21
29
  };
@@ -48,6 +48,18 @@ const createPubsub = () => {
48
48
  emitter.off("*", onAction);
49
49
  };
50
50
  }, [onAction]);
51
+ },
52
+ subscribe(type, onAction) {
53
+ emitter.on(type, onAction);
54
+ return () => {
55
+ emitter.off(type, onAction);
56
+ };
57
+ },
58
+ subscribeAll(onAction) {
59
+ emitter.on("*", onAction);
60
+ return () => {
61
+ emitter.off("*", onAction);
62
+ };
51
63
  }
52
64
  };
53
65
  };
@@ -36,8 +36,8 @@ const createInstanceChildrenElements = ({
36
36
  }) => {
37
37
  const elements = [];
38
38
  for (const child of children) {
39
- if (typeof child === "string") {
40
- elements.push(child);
39
+ if (child.type === "text") {
40
+ elements.push(child.value);
41
41
  continue;
42
42
  }
43
43
  const children2 = createInstanceChildrenElements({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -21,23 +21,24 @@
21
21
  "devDependencies": {
22
22
  "@babel/core": "^7.20.2",
23
23
  "@esbuild-kit/esm-loader": "^2.4.2",
24
+ "@jest/globals": "^29.3.1",
25
+ "@remix-run/node": "^1.6.4",
24
26
  "@remix-run/react": "^1.2.3",
25
27
  "@remix-run/server-runtime": "^1.2.3",
26
- "@storybook/addon-actions": "^6.5.6",
27
- "@storybook/addon-essentials": "^6.5.6",
28
- "@storybook/addon-interactions": "^6.5.6",
29
- "@storybook/addon-links": "^6.5.6",
30
- "@storybook/builder-webpack4": "^6.5.6",
31
- "@storybook/manager-webpack4": "^6.5.6",
32
- "@storybook/react": "^6.5.6",
28
+ "@storybook/react": "^6.5.14",
33
29
  "@storybook/testing-library": "^0.0.11",
34
30
  "@types/node": "^17.0.21",
31
+ "@types/react": "^17.0.24",
32
+ "@types/react-dom": "^17.0.9",
35
33
  "@webstudio-is/generate-arg-types": "*",
36
34
  "@webstudio-is/jest-config": "*",
37
35
  "@webstudio-is/scripts": "*",
36
+ "@webstudio-is/storybook-config": "*",
37
+ "@webstudio-is/tsconfig": "*",
38
38
  "babel-loader": "^8.2.5",
39
39
  "esbuild": "^0.14.25",
40
40
  "esbuild-node-externals": "^1.4.1",
41
+ "jest": "^29.3.1",
41
42
  "react": "^17.0.2",
42
43
  "react-dom": "^17.0.2",
43
44
  "remix-utils": "^4.1.0",
@@ -48,7 +49,6 @@
48
49
  "peerDependencies": {
49
50
  "@remix-run/react": "^1.2.3",
50
51
  "@remix-run/server-runtime": "^1.2.3",
51
- "@storybook/react": "^6.5.6",
52
52
  "react": "^17.0.2",
53
53
  "react-dom": "^17.0.2",
54
54
  "remix-utils": "^4.1.0",
@@ -2,7 +2,7 @@ import { BodyIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/body.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  marginTop: {
7
7
  type: "unit",
8
8
  unit: "px",
@@ -57,7 +57,7 @@ const meta: WsComponentMeta = {
57
57
  label: "Body",
58
58
  Icon: BodyIcon,
59
59
  props: props as MetaProps,
60
- defaultStyle,
60
+ presetStyle,
61
61
  };
62
62
 
63
63
  export default meta;
@@ -2,7 +2,7 @@ import { SquareIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/box.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  boxSizing: {
7
7
  type: "keyword",
8
8
  value: "border-box",
@@ -13,7 +13,7 @@ const meta: WsComponentMeta = {
13
13
  type: "container",
14
14
  label: "Box",
15
15
  Icon: SquareIcon,
16
- defaultStyle,
16
+ presetStyle,
17
17
  props: props as MetaProps,
18
18
  };
19
19
 
@@ -23,7 +23,7 @@ export type WsComponentMeta = {
23
23
  | "rich-text-child";
24
24
  label: string;
25
25
  Icon: FunctionComponent<IconProps>;
26
- defaultStyle?: Style;
26
+ presetStyle?: Style;
27
27
  children?: Array<string>;
28
28
  props: MetaProps;
29
29
  initialProps?: Array<string>;
@@ -83,7 +83,7 @@ export const WsComponentMeta = z.lazy(() =>
83
83
  ]),
84
84
  label: z.string(),
85
85
  Icon: z.any(),
86
- defaultStyle: z.optional(z.any()),
86
+ presetStyle: z.optional(z.any()),
87
87
  children: z.optional(z.array(z.string())),
88
88
  props: Props,
89
89
  initialProps: z.optional(z.array(z.string())),
@@ -2,7 +2,7 @@ import { FormIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/form.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  minHeight: {
7
7
  type: "unit",
8
8
  unit: "px",
@@ -18,7 +18,7 @@ const meta: WsComponentMeta = {
18
18
  type: "container",
19
19
  label: "Form",
20
20
  Icon: FormIcon,
21
- defaultStyle,
21
+ presetStyle,
22
22
  props: props as MetaProps,
23
23
  };
24
24
 
@@ -2,7 +2,7 @@ import { ImageIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/image.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  // Otherwise on new image insert onto canvas it can overfit screen size multiple times
7
7
  maxWidth: {
8
8
  type: "unit",
@@ -21,7 +21,7 @@ const meta: WsComponentMeta = {
21
21
  type: "embed",
22
22
  label: "Image",
23
23
  Icon: ImageIcon,
24
- defaultStyle,
24
+ presetStyle,
25
25
  props: props as MetaProps,
26
26
  initialProps: ["src", "width", "height", "alt", "loading"],
27
27
  };
@@ -1,3 +1,4 @@
1
+ import { test, expect } from "@jest/globals";
1
2
  import {
2
3
  getComponentNames,
3
4
  getComponentMeta,
@@ -2,7 +2,7 @@ import { FontItalicIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/italic.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  fontStyle: {
7
7
  type: "keyword",
8
8
  value: "italic",
@@ -13,7 +13,7 @@ const meta: WsComponentMeta = {
13
13
  type: "rich-text-child",
14
14
  label: "Italic Text",
15
15
  Icon: FontItalicIcon,
16
- defaultStyle,
16
+ presetStyle,
17
17
  props: props as MetaProps,
18
18
  };
19
19
 
@@ -2,7 +2,7 @@ import { Link2Icon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/link.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  minHeight: {
7
7
  type: "unit",
8
8
  unit: "em",
@@ -18,7 +18,7 @@ const meta: WsComponentMeta = {
18
18
  type: "rich-text",
19
19
  label: "Link",
20
20
  Icon: Link2Icon,
21
- defaultStyle,
21
+ presetStyle,
22
22
  children: ["Link text you can edit"],
23
23
  props: props as MetaProps,
24
24
  };
@@ -2,7 +2,7 @@ import { TextIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, MetaProps } from "./component-type";
3
3
  import props from "./__generated__/text-block.props.json";
4
4
 
5
- const defaultStyle = {
5
+ const presetStyle = {
6
6
  minHeight: {
7
7
  type: "unit",
8
8
  unit: "em",
@@ -14,7 +14,7 @@ const meta: WsComponentMeta = {
14
14
  type: "rich-text",
15
15
  label: "Text Block",
16
16
  Icon: TextIcon,
17
- defaultStyle,
17
+ presetStyle,
18
18
  children: ["Block of text you can edit"],
19
19
  props: props as MetaProps,
20
20
  };
@@ -3,7 +3,7 @@ import type { Breakpoint } from "@webstudio-is/css-data";
3
3
  export type BaseBreakpoint = Pick<Breakpoint, "label" | "minWidth">;
4
4
 
5
5
  export const initialBreakpoints: Array<BaseBreakpoint> = [
6
- { label: "Mobile", minWidth: 360 },
6
+ { label: "Mobile", minWidth: 0 },
7
7
  { label: "Tablet", minWidth: 768 },
8
8
  { label: "Laptop", minWidth: 1024 },
9
9
  { label: "Desktop", minWidth: 1280 },
@@ -10,8 +10,14 @@ export type BaseInstance = {
10
10
  cssRules: Array<CssRule>;
11
11
  };
12
12
 
13
+ export type Text = {
14
+ type: "text";
15
+ value: string;
16
+ };
17
+
13
18
  export type Instance = BaseInstance & {
14
- children: Array<Instance | string>;
19
+ type: "instance";
20
+ children: Array<Instance | Text>;
15
21
  };
16
22
 
17
23
  export const toBaseInstance = (instance: Instance): BaseInstance => {
@@ -22,12 +28,20 @@ export const toBaseInstance = (instance: Instance): BaseInstance => {
22
28
  };
23
29
  };
24
30
 
31
+ export const Text = z.lazy(() =>
32
+ z.object({
33
+ type: z.literal("text"),
34
+ value: z.string(),
35
+ })
36
+ );
37
+
25
38
  export const Instance = z.lazy(
26
39
  () =>
27
40
  z.object({
41
+ type: z.literal("instance"),
28
42
  id: z.string(),
29
43
  component: z.string(),
30
- children: z.array(z.union([Instance, z.string()])),
44
+ children: z.array(z.union([Instance, Text])),
31
45
  cssRules: z.array(CssRule),
32
46
  })
33
47
  // @todo can't figure out how to make component to be z.enum(Object.keys(components))
@@ -82,5 +82,27 @@ export const createPubsub = <PublishMap>() => {
82
82
  };
83
83
  }, [onAction]);
84
84
  },
85
+
86
+ subscribe<Type extends keyof PublishMap>(
87
+ type: Type,
88
+ onAction: (payload: PublishMap[Type]) => void
89
+ ) {
90
+ emitter.on(type, onAction);
91
+ return () => {
92
+ emitter.off(type, onAction);
93
+ };
94
+ },
95
+
96
+ subscribeAll(
97
+ onAction: <Type extends keyof PublishMap>(
98
+ type: Type,
99
+ payload: PublishMap[Type]
100
+ ) => void
101
+ ) {
102
+ emitter.on("*", onAction);
103
+ return () => {
104
+ emitter.off("*", onAction);
105
+ };
106
+ },
85
107
  };
86
108
  };
@@ -5,8 +5,12 @@ import { Scripts, ScrollRestoration } from "@remix-run/react";
5
5
  import { SessionStoragePolyfill } from "./session-storage-polyfill";
6
6
 
7
7
  export type ChildrenUpdates = Array<
8
- | string
9
8
  | {
9
+ type: "text";
10
+ value: string;
11
+ }
12
+ | {
13
+ type: "instance";
10
14
  id: undefined | Instance["id"];
11
15
  component: Instance["component"];
12
16
  children: ChildrenUpdates;
@@ -60,8 +64,8 @@ const createInstanceChildrenElements = ({
60
64
  }) => {
61
65
  const elements = [];
62
66
  for (const child of children) {
63
- if (typeof child === "string") {
64
- elements.push(child);
67
+ if (child.type === "text") {
68
+ elements.push(child.value);
65
69
  continue;
66
70
  }
67
71
  const children = createInstanceChildrenElements({
@@ -2,9 +2,8 @@ import type { InstanceProps, Instance } from "../db";
2
2
  import { UserProp } from "./schema";
3
3
 
4
4
  export type UserPropsUpdates = {
5
- treeId: InstanceProps["treeId"];
6
- propsId: InstanceProps["id"];
7
5
  instanceId: Instance["id"];
6
+ propsId?: InstanceProps["id"];
8
7
  updates: Array<UserProp>;
9
8
  };
10
9