@webstudio-is/react-sdk 0.91.0 → 0.93.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 (108) hide show
  1. package/lib/app/index.js +1 -0
  2. package/lib/app/root.js +2 -4
  3. package/lib/component-renderer.js +3 -5
  4. package/lib/components/component-meta.js +6 -11
  5. package/lib/components/components-utils.js +1 -0
  6. package/lib/context.js +2 -4
  7. package/lib/css/css.js +4 -9
  8. package/lib/css/global-rules.js +3 -5
  9. package/lib/css/index.js +1 -0
  10. package/lib/css/normalize-type-check.js +1 -0
  11. package/lib/css/normalize.js +48 -96
  12. package/lib/css/presets.js +3 -6
  13. package/lib/css/style-rules.js +3 -6
  14. package/{src/css/style-rules.test.ts → lib/css/style-rules.test.js} +23 -28
  15. package/lib/embed-template.js +7 -22
  16. package/{src/embed-template.test.ts → lib/embed-template.test.js} +165 -176
  17. package/lib/expression.js +11 -22
  18. package/{src/expression.test.ts → lib/expression.test.js} +55 -83
  19. package/lib/generator.js +2 -4
  20. package/{src/generator.test.ts → lib/generator.test.js} +28 -31
  21. package/lib/hook.js +2 -4
  22. package/{src/hook.test.ts → lib/hook.test.js} +4 -4
  23. package/lib/index.js +9 -31
  24. package/lib/instance-utils.js +2 -4
  25. package/{src/instance-utils.test.ts → lib/instance-utils.test.js} +19 -43
  26. package/lib/prop-meta.js +150 -0
  27. package/lib/props.js +8 -16
  28. package/{src/props.test.ts → lib/props.test.js} +39 -68
  29. package/lib/pubsub/create.js +2 -4
  30. package/lib/pubsub/index.js +1 -0
  31. package/lib/pubsub/raf-queue.js +2 -4
  32. package/lib/tree/create-elements-tree.js +2 -4
  33. package/lib/tree/index.js +1 -0
  34. package/lib/tree/root.js +2 -5
  35. package/lib/tree/webstudio-component.js +10 -20
  36. package/lib/types/component-renderer.d.ts +1 -1
  37. package/lib/types/components/component-meta.d.ts +526 -526
  38. package/lib/types/context.d.ts +1 -2
  39. package/lib/types/css/css.d.ts +22 -23
  40. package/lib/types/css/global-rules.d.ts +19 -19
  41. package/lib/types/css/normalize.d.ts +2444 -2444
  42. package/lib/types/css/style-rules.d.ts +2 -2
  43. package/lib/types/embed-template.d.ts +648 -648
  44. package/lib/types/generator.d.ts +1 -1
  45. package/lib/types/hook.d.ts +3 -3
  46. package/lib/types/index.d.ts +1 -0
  47. package/lib/types/instance-utils.d.ts +3 -3
  48. package/lib/types/prop-meta.d.ts +396 -0
  49. package/lib/types/props.d.ts +52 -53
  50. package/lib/types/tree/create-elements-tree.d.ts +3 -4
  51. package/lib/types/tree/root.d.ts +8 -8
  52. package/lib/types/tree/webstudio-component.d.ts +1 -1
  53. package/package.json +14 -22
  54. package/lib/cjs/app/index.js +0 -18
  55. package/lib/cjs/app/root.js +0 -40
  56. package/lib/cjs/component-renderer.js +0 -143
  57. package/lib/cjs/components/component-meta.js +0 -87
  58. package/lib/cjs/components/components-utils.js +0 -17
  59. package/lib/cjs/context.js +0 -43
  60. package/lib/cjs/css/css.js +0 -84
  61. package/lib/cjs/css/global-rules.js +0 -37
  62. package/lib/cjs/css/index.js +0 -20
  63. package/lib/cjs/css/normalize-type-check.js +0 -26
  64. package/lib/cjs/css/normalize.js +0 -349
  65. package/lib/cjs/css/presets.js +0 -48
  66. package/lib/cjs/css/style-rules.js +0 -86
  67. package/lib/cjs/embed-template.js +0 -368
  68. package/lib/cjs/expression.js +0 -371
  69. package/lib/cjs/generator.js +0 -128
  70. package/lib/cjs/hook.js +0 -34
  71. package/lib/cjs/index.js +0 -59
  72. package/lib/cjs/instance-utils.js +0 -65
  73. package/lib/cjs/package.json +0 -1
  74. package/lib/cjs/props.js +0 -204
  75. package/lib/cjs/pubsub/create.js +0 -78
  76. package/lib/cjs/pubsub/index.js +0 -18
  77. package/lib/cjs/pubsub/raf-queue.js +0 -42
  78. package/lib/cjs/tree/create-elements-tree.js +0 -152
  79. package/lib/cjs/tree/index.js +0 -20
  80. package/lib/cjs/tree/root.js +0 -100
  81. package/lib/cjs/tree/webstudio-component.js +0 -91
  82. package/src/app/index.ts +0 -1
  83. package/src/app/root.tsx +0 -25
  84. package/src/component-renderer.tsx +0 -146
  85. package/src/components/component-meta.ts +0 -86
  86. package/src/components/components-utils.ts +0 -13
  87. package/src/context.tsx +0 -73
  88. package/src/css/css.ts +0 -88
  89. package/src/css/global-rules.ts +0 -26
  90. package/src/css/index.ts +0 -3
  91. package/src/css/normalize-type-check.ts +0 -13
  92. package/src/css/normalize.ts +0 -507
  93. package/src/css/presets.ts +0 -27
  94. package/src/css/style-rules.ts +0 -101
  95. package/src/embed-template.ts +0 -438
  96. package/src/expression.ts +0 -401
  97. package/src/generator.ts +0 -147
  98. package/src/hook.ts +0 -52
  99. package/src/index.ts +0 -39
  100. package/src/instance-utils.ts +0 -65
  101. package/src/props.ts +0 -231
  102. package/src/pubsub/create.ts +0 -77
  103. package/src/pubsub/index.ts +0 -1
  104. package/src/pubsub/raf-queue.ts +0 -25
  105. package/src/tree/create-elements-tree.tsx +0 -186
  106. package/src/tree/index.ts +0 -3
  107. package/src/tree/root.ts +0 -131
  108. package/src/tree/webstudio-component.tsx +0 -97
@@ -1,97 +0,0 @@
1
- import { Fragment, forwardRef } from "react";
2
- import type { Instance } from "@webstudio-is/project-build";
3
- import type { Components } from "../components/components-utils";
4
- import { useInstanceProps } from "../props";
5
-
6
- const renderText = (text: string): Array<JSX.Element> => {
7
- const lines = text.split("\n");
8
- return lines.map((line, index) => (
9
- <Fragment key={index}>
10
- {line}
11
- {index < lines.length - 1 ? <br /> : null}
12
- </Fragment>
13
- ));
14
- };
15
-
16
- export const renderWebstudioComponentChildren = (
17
- children: Array<JSX.Element | string> | undefined
18
- ): Array<JSX.Element | string | Array<JSX.Element | string>> | undefined => {
19
- // Some elements like input can't have children
20
- // @todo needs to be made impossible to drag element into input
21
- if (children === undefined || children.length === 0) {
22
- return;
23
- }
24
- return children.map((child) => {
25
- return typeof child === "string" ? renderText(child) : child;
26
- });
27
- };
28
-
29
- export type WebstudioComponentProps = {
30
- instance: Instance;
31
- instanceSelector: Instance["id"][];
32
- children: Array<JSX.Element | string>;
33
- components: Components;
34
- };
35
-
36
- // eslint-disable-next-line react/display-name
37
- export const WebstudioComponent = forwardRef<
38
- HTMLElement,
39
- WebstudioComponentProps
40
- >(({ instance, instanceSelector, children, components, ...rest }, ref) => {
41
- const { [showAttribute]: show = true, ...instanceProps } = useInstanceProps(
42
- instance.id
43
- );
44
- const props = {
45
- ...instanceProps,
46
- ...rest,
47
- [idAttribute]: instance.id,
48
- [componentAttribute]: instance.component,
49
- };
50
- if (show === false) {
51
- return <></>;
52
- }
53
- const Component = components.get(instance.component);
54
- if (Component === undefined) {
55
- return <></>;
56
- }
57
- return (
58
- <Component {...props} ref={ref}>
59
- {renderWebstudioComponentChildren(children)}
60
- </Component>
61
- );
62
- });
63
-
64
- export const idAttribute = "data-ws-id" as const;
65
- export const selectorIdAttribute = "data-ws-selector" as const;
66
- export const componentAttribute = "data-ws-component" as const;
67
- export const showAttribute = "data-ws-show" as const;
68
- export const indexAttribute = "data-ws-index" as const;
69
- export const collapsedAttribute = "data-ws-collapsed" as const;
70
-
71
- export type WebstudioAttributes = {
72
- [idAttribute]?: string | undefined;
73
- [selectorIdAttribute]?: string | undefined;
74
- [componentAttribute]?: string | undefined;
75
- [showAttribute]?: string | undefined;
76
- [collapsedAttribute]?: string | undefined;
77
- };
78
-
79
- export const splitPropsWithWebstudioAttributes = <
80
- P extends WebstudioAttributes,
81
- >({
82
- [idAttribute]: idAttributeValue,
83
- [componentAttribute]: componentAttributeValue,
84
- [showAttribute]: showAttributeValue,
85
- [collapsedAttribute]: collapsedAttributeValue,
86
- [selectorIdAttribute]: parentIdAttributeValue,
87
- ...props
88
- }: P): [WebstudioAttributes, Omit<P, keyof WebstudioAttributes>] => [
89
- {
90
- [idAttribute]: idAttributeValue,
91
- [componentAttribute]: componentAttributeValue,
92
- [showAttribute]: showAttributeValue,
93
- [collapsedAttribute]: collapsedAttributeValue,
94
- [selectorIdAttribute]: parentIdAttributeValue,
95
- },
96
- props,
97
- ];