@webstudio-is/react-sdk 0.59.0 → 0.61.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 (163) hide show
  1. package/lib/app/custom-components/shared/remix-link.js +2 -2
  2. package/lib/app/index.js +0 -1
  3. package/lib/cjs/app/custom-components/shared/remix-link.js +2 -2
  4. package/lib/cjs/app/index.js +0 -1
  5. package/lib/cjs/components/__generated__/blockquote.props.js +5 -0
  6. package/lib/cjs/components/__generated__/body.props.js +5 -0
  7. package/lib/cjs/components/__generated__/bold.props.js +5 -0
  8. package/lib/cjs/components/__generated__/box.props.js +5 -0
  9. package/lib/cjs/components/__generated__/button.props.js +5 -1
  10. package/lib/cjs/components/__generated__/code.props.js +5 -0
  11. package/lib/cjs/components/__generated__/form.props.js +5 -0
  12. package/lib/cjs/components/__generated__/heading.props.js +5 -0
  13. package/lib/cjs/components/__generated__/image.props.js +5 -0
  14. package/lib/cjs/components/__generated__/input.props.js +11 -2
  15. package/lib/cjs/components/__generated__/italic.props.js +5 -0
  16. package/lib/cjs/components/__generated__/link-block.props.js +5 -1
  17. package/lib/cjs/components/__generated__/link.props.js +5 -1
  18. package/lib/cjs/components/__generated__/list-item.props.js +5 -0
  19. package/lib/cjs/components/__generated__/list.props.js +5 -0
  20. package/lib/cjs/components/__generated__/paragraph.props.js +5 -0
  21. package/lib/cjs/components/__generated__/rich-text-link.props.js +5 -1
  22. package/lib/cjs/components/__generated__/separator.props.js +5 -0
  23. package/lib/cjs/components/__generated__/span.props.js +5 -0
  24. package/lib/cjs/components/__generated__/subscript.props.js +5 -0
  25. package/lib/cjs/components/__generated__/superscript.props.js +5 -0
  26. package/lib/cjs/components/__generated__/text-block.props.js +5 -0
  27. package/lib/cjs/components/blockquote.ws.js +36 -48
  28. package/lib/cjs/components/body.ws.js +19 -24
  29. package/lib/cjs/components/button.ws.js +1 -1
  30. package/lib/cjs/components/code.ws.js +20 -28
  31. package/lib/cjs/components/component-meta.js +2 -1
  32. package/lib/cjs/components/form.ws.js +14 -7
  33. package/lib/cjs/components/heading.ws.js +1 -1
  34. package/lib/cjs/components/image.ws.js +8 -9
  35. package/lib/cjs/components/italic.ws.js +5 -5
  36. package/lib/cjs/components/link-block.ws.js +5 -5
  37. package/lib/cjs/components/link.js +1 -1
  38. package/lib/cjs/components/link.ws.js +9 -10
  39. package/lib/cjs/components/list-item.ws.js +1 -1
  40. package/lib/cjs/components/list.ws.js +22 -22
  41. package/lib/cjs/components/paragraph.ws.js +1 -1
  42. package/lib/cjs/components/separator.ws.js +20 -20
  43. package/lib/cjs/components/text-block.ws.js +6 -7
  44. package/lib/cjs/css/css.js +6 -9
  45. package/lib/cjs/css/normalize.js +166 -185
  46. package/lib/cjs/css/presets.js +14 -34
  47. package/lib/cjs/css/style-rules.js +17 -0
  48. package/lib/cjs/embed-template.js +160 -0
  49. package/lib/cjs/index.js +1 -0
  50. package/lib/components/__generated__/blockquote.props.js +5 -0
  51. package/lib/components/__generated__/body.props.js +5 -0
  52. package/lib/components/__generated__/bold.props.js +5 -0
  53. package/lib/components/__generated__/box.props.js +5 -0
  54. package/lib/components/__generated__/button.props.js +5 -1
  55. package/lib/components/__generated__/code.props.js +5 -0
  56. package/lib/components/__generated__/form.props.js +5 -0
  57. package/lib/components/__generated__/heading.props.js +5 -0
  58. package/lib/components/__generated__/image.props.js +5 -0
  59. package/lib/components/__generated__/input.props.js +11 -2
  60. package/lib/components/__generated__/italic.props.js +5 -0
  61. package/lib/components/__generated__/link-block.props.js +5 -1
  62. package/lib/components/__generated__/link.props.js +5 -1
  63. package/lib/components/__generated__/list-item.props.js +5 -0
  64. package/lib/components/__generated__/list.props.js +5 -0
  65. package/lib/components/__generated__/paragraph.props.js +5 -0
  66. package/lib/components/__generated__/rich-text-link.props.js +5 -1
  67. package/lib/components/__generated__/separator.props.js +5 -0
  68. package/lib/components/__generated__/span.props.js +5 -0
  69. package/lib/components/__generated__/subscript.props.js +5 -0
  70. package/lib/components/__generated__/superscript.props.js +5 -0
  71. package/lib/components/__generated__/text-block.props.js +5 -0
  72. package/lib/components/blockquote.ws.js +36 -48
  73. package/lib/components/body.ws.js +19 -24
  74. package/lib/components/button.ws.js +1 -1
  75. package/lib/components/code.ws.js +20 -28
  76. package/lib/components/component-meta.js +2 -1
  77. package/lib/components/form.ws.js +14 -7
  78. package/lib/components/heading.ws.js +1 -1
  79. package/lib/components/image.ws.js +8 -9
  80. package/lib/components/italic.ws.js +5 -5
  81. package/lib/components/link-block.ws.js +5 -5
  82. package/lib/components/link.js +1 -1
  83. package/lib/components/link.ws.js +9 -10
  84. package/lib/components/list-item.ws.js +1 -1
  85. package/lib/components/list.ws.js +22 -22
  86. package/lib/components/paragraph.ws.js +1 -1
  87. package/lib/components/separator.ws.js +20 -20
  88. package/lib/components/text-block.ws.js +6 -7
  89. package/lib/css/css.js +8 -11
  90. package/lib/css/normalize.js +166 -185
  91. package/lib/css/presets.js +14 -34
  92. package/lib/css/style-rules.js +17 -0
  93. package/lib/embed-template.js +140 -0
  94. package/lib/index.js +1 -0
  95. package/lib/types/app/index.d.ts +0 -1
  96. package/lib/types/components/box.stories.d.ts +2 -2
  97. package/lib/types/components/component-meta.d.ts +20 -5
  98. package/lib/types/components/components-utils.d.ts +1 -1
  99. package/lib/types/css/normalize.d.ts +8786 -2286
  100. package/lib/types/css/presets.d.ts +2 -38
  101. package/lib/types/css/style-rules.d.ts +11 -9
  102. package/lib/types/embed-template.d.ts +1725 -0
  103. package/lib/types/embed-template.test.d.ts +1 -0
  104. package/lib/types/index.d.ts +1 -0
  105. package/package.json +16 -19
  106. package/src/app/custom-components/shared/remix-link.tsx +2 -2
  107. package/src/app/index.ts +0 -1
  108. package/src/components/__generated__/blockquote.props.ts +5 -0
  109. package/src/components/__generated__/body.props.ts +5 -0
  110. package/src/components/__generated__/bold.props.ts +5 -0
  111. package/src/components/__generated__/box.props.ts +5 -0
  112. package/src/components/__generated__/button.props.ts +5 -1
  113. package/src/components/__generated__/code.props.ts +5 -0
  114. package/src/components/__generated__/form.props.ts +5 -0
  115. package/src/components/__generated__/heading.props.ts +5 -0
  116. package/src/components/__generated__/image.props.ts +5 -0
  117. package/src/components/__generated__/input.props.ts +11 -2
  118. package/src/components/__generated__/italic.props.ts +5 -0
  119. package/src/components/__generated__/link-block.props.ts +5 -1
  120. package/src/components/__generated__/link.props.ts +5 -1
  121. package/src/components/__generated__/list-item.props.ts +5 -0
  122. package/src/components/__generated__/list.props.ts +5 -0
  123. package/src/components/__generated__/paragraph.props.ts +5 -0
  124. package/src/components/__generated__/rich-text-link.props.ts +5 -1
  125. package/src/components/__generated__/separator.props.ts +5 -0
  126. package/src/components/__generated__/span.props.ts +5 -0
  127. package/src/components/__generated__/subscript.props.ts +5 -0
  128. package/src/components/__generated__/superscript.props.ts +5 -0
  129. package/src/components/__generated__/text-block.props.ts +5 -0
  130. package/src/components/blockquote.ws.tsx +42 -52
  131. package/src/components/body.ws.tsx +25 -32
  132. package/src/components/bold.ws.tsx +6 -3
  133. package/src/components/box.ws.ts +6 -3
  134. package/src/components/button.ws.tsx +7 -4
  135. package/src/components/code.ws.tsx +26 -32
  136. package/src/components/component-meta.ts +5 -3
  137. package/src/components/form.ws.tsx +19 -9
  138. package/src/components/heading.ws.tsx +7 -4
  139. package/src/components/image.ws.tsx +14 -12
  140. package/src/components/input.ws.tsx +6 -3
  141. package/src/components/italic.ws.tsx +11 -8
  142. package/src/components/link-block.ws.tsx +11 -8
  143. package/src/components/link.tsx +1 -1
  144. package/src/components/link.ws.tsx +15 -13
  145. package/src/components/list-item.ws.tsx +7 -4
  146. package/src/components/list.ws.tsx +28 -25
  147. package/src/components/paragraph.ws.tsx +7 -4
  148. package/src/components/separator.ws.tsx +26 -25
  149. package/src/components/span.ws.tsx +6 -3
  150. package/src/components/subscript.ws.tsx +6 -3
  151. package/src/components/superscript.ws.tsx +6 -3
  152. package/src/components/text-block.ws.tsx +12 -11
  153. package/src/css/css.ts +8 -11
  154. package/src/css/normalize.ts +165 -188
  155. package/src/css/presets.ts +15 -37
  156. package/src/css/style-rules.ts +24 -0
  157. package/src/embed-template.test.ts +210 -0
  158. package/src/embed-template.ts +187 -0
  159. package/src/index.ts +1 -0
  160. package/lib/app/handle-request.server.js +0 -16
  161. package/lib/cjs/app/handle-request.server.js +0 -36
  162. package/lib/types/app/handle-request.server.d.ts +0 -2
  163. package/src/app/handle-request.server.tsx +0 -21
@@ -1,41 +1,21 @@
1
- const borders = {
2
- borderTopColor: {
3
- type: "keyword",
4
- value: "currentColor"
1
+ const borders = [
2
+ {
3
+ property: "borderTopWidth",
4
+ value: { type: "unit", value: 1, unit: "px" }
5
5
  },
6
- borderRightColor: {
7
- type: "keyword",
8
- value: "currentColor"
6
+ {
7
+ property: "borderRightWidth",
8
+ value: { type: "unit", value: 1, unit: "px" }
9
9
  },
10
- borderBottomColor: {
11
- type: "keyword",
12
- value: "currentColor"
10
+ {
11
+ property: "borderBottomWidth",
12
+ value: { type: "unit", value: 1, unit: "px" }
13
13
  },
14
- borderLeftColor: {
15
- type: "keyword",
16
- value: "currentColor"
17
- },
18
- borderTopWidth: {
19
- type: "unit",
20
- value: 1,
21
- unit: "px"
22
- },
23
- borderRightWidth: {
24
- type: "unit",
25
- value: 1,
26
- unit: "px"
27
- },
28
- borderBottomWidth: {
29
- type: "unit",
30
- value: 1,
31
- unit: "px"
32
- },
33
- borderLeftWidth: {
34
- type: "unit",
35
- value: 1,
36
- unit: "px"
14
+ {
15
+ property: "borderLeftWidth",
16
+ value: { type: "unit", value: 1, unit: "px" }
37
17
  }
38
- };
18
+ ];
39
19
  export {
40
20
  borders
41
21
  };
@@ -1,3 +1,4 @@
1
+ import { componentAttribute } from "../tree";
1
2
  const getStyleRules = (styles, styleSourceSelections) => {
2
3
  if (styles === void 0 || styleSourceSelections === void 0) {
3
4
  return [];
@@ -44,6 +45,22 @@ const getStyleRules = (styles, styleSourceSelections) => {
44
45
  }
45
46
  return styleRules;
46
47
  };
48
+ const getPresetStyleRules = (component, presetStyle) => {
49
+ const presetStyleRules = /* @__PURE__ */ new Map();
50
+ for (const [tag, styles] of Object.entries(presetStyle)) {
51
+ for (const styleDecl of styles) {
52
+ const selector = `${tag}:where([${componentAttribute}=${component}])${styleDecl.state ?? ""}`;
53
+ let rule = presetStyleRules.get(selector);
54
+ if (rule === void 0) {
55
+ rule = {};
56
+ presetStyleRules.set(selector, rule);
57
+ }
58
+ rule[styleDecl.property] = styleDecl.value;
59
+ }
60
+ }
61
+ return presetStyleRules;
62
+ };
47
63
  export {
64
+ getPresetStyleRules,
48
65
  getStyleRules
49
66
  };
@@ -0,0 +1,140 @@
1
+ import { z } from "zod";
2
+ import { nanoid } from "nanoid";
3
+ import { StyleValue } from "@webstudio-is/css-data";
4
+ const EmbedTemplateText = z.object({
5
+ type: z.literal("text"),
6
+ value: z.string()
7
+ });
8
+ const EmbedTemplateProp = z.union([
9
+ z.object({
10
+ type: z.literal("number"),
11
+ name: z.string(),
12
+ value: z.number()
13
+ }),
14
+ z.object({
15
+ type: z.literal("string"),
16
+ name: z.string(),
17
+ value: z.string()
18
+ }),
19
+ z.object({
20
+ type: z.literal("boolean"),
21
+ name: z.string(),
22
+ value: z.boolean()
23
+ }),
24
+ z.object({
25
+ type: z.literal("string[]"),
26
+ name: z.string(),
27
+ value: z.array(z.string())
28
+ })
29
+ ]);
30
+ const EmbedTemplateStyleDecl = z.object({
31
+ state: z.optional(z.string()),
32
+ property: z.string(),
33
+ value: StyleValue
34
+ });
35
+ const EmbedTemplateInstance = z.lazy(
36
+ () => z.object({
37
+ type: z.literal("instance"),
38
+ component: z.string(),
39
+ props: z.optional(z.array(EmbedTemplateProp)),
40
+ styles: z.optional(z.array(EmbedTemplateStyleDecl)),
41
+ children: WsEmbedTemplate
42
+ })
43
+ );
44
+ const WsEmbedTemplate = z.lazy(
45
+ () => z.array(z.union([EmbedTemplateInstance, EmbedTemplateText]))
46
+ );
47
+ const createInstancesFromTemplate = (treeTemplate, instances, props, styleSourceSelections, styleSources, styles, defaultBreakpointId) => {
48
+ const parentChildren = [];
49
+ for (const item of treeTemplate) {
50
+ if (item.type === "instance") {
51
+ const instanceId = nanoid();
52
+ if (item.props) {
53
+ for (const prop of item.props) {
54
+ props.push({
55
+ id: nanoid(),
56
+ instanceId,
57
+ ...prop
58
+ });
59
+ }
60
+ }
61
+ if (item.styles) {
62
+ const styleSourceId = nanoid();
63
+ styleSources.push({
64
+ type: "local",
65
+ id: styleSourceId
66
+ });
67
+ styleSourceSelections.push({
68
+ instanceId,
69
+ values: [styleSourceId]
70
+ });
71
+ for (const styleDecl of item.styles) {
72
+ styles.push({
73
+ breakpointId: defaultBreakpointId,
74
+ styleSourceId,
75
+ state: styleDecl.state,
76
+ property: styleDecl.property,
77
+ value: styleDecl.value
78
+ });
79
+ }
80
+ }
81
+ const instance = {
82
+ type: "instance",
83
+ id: instanceId,
84
+ component: item.component,
85
+ children: []
86
+ };
87
+ instances.push(instance);
88
+ instance.children = createInstancesFromTemplate(
89
+ item.children,
90
+ instances,
91
+ props,
92
+ styleSourceSelections,
93
+ styleSources,
94
+ styles,
95
+ defaultBreakpointId
96
+ );
97
+ parentChildren.push({
98
+ type: "id",
99
+ value: instanceId
100
+ });
101
+ }
102
+ if (item.type === "text") {
103
+ parentChildren.push({
104
+ type: "text",
105
+ value: item.value
106
+ });
107
+ }
108
+ }
109
+ return parentChildren;
110
+ };
111
+ const generateDataFromEmbedTemplate = (treeTemplate, defaultBreakpointId) => {
112
+ const instances = [];
113
+ const props = [];
114
+ const styleSourceSelections = [];
115
+ const styleSources = [];
116
+ const styles = [];
117
+ const children = createInstancesFromTemplate(
118
+ treeTemplate,
119
+ instances,
120
+ props,
121
+ styleSourceSelections,
122
+ styleSources,
123
+ styles,
124
+ defaultBreakpointId
125
+ );
126
+ return {
127
+ children,
128
+ instances,
129
+ props,
130
+ styleSourceSelections,
131
+ styleSources,
132
+ styles
133
+ };
134
+ };
135
+ export {
136
+ EmbedTemplateInstance,
137
+ EmbedTemplateStyleDecl,
138
+ WsEmbedTemplate,
139
+ generateDataFromEmbedTemplate
140
+ };
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  import {
14
14
  componentCategories
15
15
  } from "./components/component-meta";
16
+ export * from "./embed-template";
16
17
  export {
17
18
  componentCategories,
18
19
  customComponentMetas,
@@ -1,3 +1,2 @@
1
1
  export * from "./root";
2
- export * from "./handle-request.server";
3
2
  export * from "./params";
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import type { ComponentStory, ComponentMeta } from "@storybook/react";
3
3
  declare const _default: ComponentMeta<import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
4
- tag?: "div" | "address" | "article" | "aside" | "figure" | "footer" | "header" | "main" | "nav" | "section" | undefined;
4
+ tag?: "address" | "article" | "aside" | "div" | "figure" | "footer" | "header" | "main" | "nav" | "section" | undefined;
5
5
  }, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
6
6
  export default _default;
7
7
  export declare const Box: ComponentStory<import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
8
- tag?: "div" | "address" | "article" | "aside" | "figure" | "footer" | "header" | "main" | "nav" | "section" | undefined;
8
+ tag?: "address" | "article" | "aside" | "div" | "figure" | "footer" | "header" | "main" | "nav" | "section" | undefined;
9
9
  }, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
@@ -1,9 +1,9 @@
1
1
  import { z } from "zod";
2
2
  import type { FunctionComponent } from "react";
3
3
  import type { IconProps } from "@webstudio-is/icons";
4
- import type { Style } from "@webstudio-is/css-data";
5
4
  import type { htmlTags as HtmlTags } from "html-tags";
6
- type PresetStyle = Partial<Record<HtmlTags, Style>>;
5
+ import { EmbedTemplateStyleDecl } from "../embed-template";
6
+ export type PresetStyle<Tag extends HtmlTags = HtmlTags> = Partial<Record<Tag, EmbedTemplateStyleDecl[]>>;
7
7
  declare const WsComponentPropsMeta: z.ZodObject<{
8
8
  props: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
9
9
  control: z.ZodLiteral<"number">;
@@ -608,9 +608,21 @@ declare const WsComponentMeta: z.ZodObject<{
608
608
  label: string;
609
609
  selector: string;
610
610
  }>, "many">>;
611
- children: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
611
+ children: z.ZodOptional<z.ZodLazy<z.ZodArray<z.ZodUnion<[z.ZodType<import("../embed-template").EmbedTemplateInstance, z.ZodTypeDef, import("../embed-template").EmbedTemplateInstance>, z.ZodObject<{
612
+ type: z.ZodLiteral<"text">;
613
+ value: z.ZodString;
614
+ }, "strip", z.ZodTypeAny, {
615
+ type: "text";
616
+ value: string;
617
+ }, {
618
+ type: "text";
619
+ value: string;
620
+ }>]>, "many">>>;
612
621
  }, "strip", z.ZodTypeAny, {
613
- children?: string[] | undefined;
622
+ children?: ({
623
+ type: "text";
624
+ value: string;
625
+ } | import("../embed-template").EmbedTemplateInstance)[] | undefined;
614
626
  category?: "media" | "general" | "typography" | "forms" | undefined;
615
627
  presetStyle?: any;
616
628
  states?: {
@@ -621,7 +633,10 @@ declare const WsComponentMeta: z.ZodObject<{
621
633
  label: string;
622
634
  Icon: (...args: unknown[]) => unknown;
623
635
  }, {
624
- children?: string[] | undefined;
636
+ children?: ({
637
+ type: "text";
638
+ value: string;
639
+ } | import("../embed-template").EmbedTemplateInstance)[] | undefined;
625
640
  category?: "media" | "general" | "typography" | "forms" | undefined;
626
641
  presetStyle?: any;
627
642
  states?: {
@@ -16,7 +16,7 @@ export declare const getComponent: (name: string) => undefined | (typeof compone
16
16
  export declare const createGetComponent: (comps: Partial<typeof components>) => (name: string) => import("react").ForwardRefExoticComponent<{
17
17
  children?: import("react").ReactNode;
18
18
  } & import("react").RefAttributes<HTMLDivElement>> | import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>, "ref"> & import("react").RefAttributes<HTMLBodyElement>> | import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
19
- tag?: "div" | "address" | "article" | "aside" | "figure" | "footer" | "header" | "main" | "nav" | "section" | undefined;
19
+ tag?: "address" | "article" | "aside" | "div" | "figure" | "footer" | "header" | "main" | "nav" | "section" | undefined;
20
20
  }, "ref"> & import("react").RefAttributes<HTMLDivElement>> | import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>> | import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLHeadingElement> & import("react").HTMLAttributes<HTMLHeadingElement> & {
21
21
  tag?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | undefined;
22
22
  }, "ref"> & import("react").RefAttributes<HTMLHeadingElement>> | import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "href" | "target"> & {