@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,4 +1,5 @@
1
- const getIndexesWithinAncestors = (metas, instances, rootIds) => {
1
+ "use strict";
2
+ export const getIndexesWithinAncestors = (metas, instances, rootIds) => {
2
3
  const ancestors = /* @__PURE__ */ new Set();
3
4
  for (const meta of metas.values()) {
4
5
  if (meta.indexWithinAncestor !== void 0) {
@@ -40,6 +41,3 @@ const getIndexesWithinAncestors = (metas, instances, rootIds) => {
40
41
  }
41
42
  return indexes;
42
43
  };
43
- export {
44
- getIndexesWithinAncestors
45
- };
@@ -1,81 +1,57 @@
1
+ "use strict";
1
2
  import { test, expect } from "@jest/globals";
2
- import type { Instance, Instances } from "@webstudio-is/project-build";
3
3
  import { getIndexesWithinAncestors } from "./instance-utils";
4
- import type { WsComponentMeta } from ".";
5
-
6
- const getIdValuePair = <T extends { id: string }>(item: T) =>
7
- [item.id, item] as const;
8
-
9
- const toMap = <T extends { id: string }>(list: T[]) =>
10
- new Map(list.map(getIdValuePair));
11
-
12
- const createInstance = (
13
- id: Instance["id"],
14
- component: string,
15
- children: Instance["children"]
16
- ): Instance => {
4
+ const getIdValuePair = (item) => [item.id, item];
5
+ const toMap = (list) => new Map(list.map(getIdValuePair));
6
+ const createInstance = (id, component, children) => {
17
7
  return { type: "instance", id, component, children };
18
8
  };
19
-
20
- const createMeta = (meta?: Partial<WsComponentMeta>) => {
21
- return { type: "container", label: "", icon: "", ...meta } as const;
9
+ const createMeta = (meta) => {
10
+ return { type: "container", label: "", icon: "", ...meta };
22
11
  };
23
-
24
12
  test("get indexes within ancestors", () => {
25
- // body0
26
- // tabs1
27
- // tabs1list
28
- // tabs1box
29
- // tabs1trigger1
30
- // tabs1trigger2
31
- // tabs1content1
32
- // tabs2
33
- // tabs2list
34
- // tabs2trigger1
35
- // tabs2content1
36
- // tabs1content2
37
- const instances: Instances = toMap([
13
+ const instances = toMap([
38
14
  createInstance("body0", "Body", [{ type: "id", value: "tabs1" }]),
39
15
  // tabs1
40
16
  createInstance("tabs1", "Tabs", [
41
17
  { type: "id", value: "tabs1list" },
42
18
  { type: "id", value: "tabs1content1" },
43
- { type: "id", value: "tabs1content2" },
19
+ { type: "id", value: "tabs1content2" }
44
20
  ]),
45
21
  createInstance("tabs1list", "TabsList", [
46
- { type: "id", value: "tabs1box" },
22
+ { type: "id", value: "tabs1box" }
47
23
  ]),
48
24
  createInstance("tabs1box", "Box", [
49
25
  { type: "id", value: "tabs1trigger1" },
50
- { type: "id", value: "tabs1trigger2" },
26
+ { type: "id", value: "tabs1trigger2" }
51
27
  ]),
52
28
  createInstance("tabs1trigger1", "TabsTrigger", []),
53
29
  createInstance("tabs1trigger2", "TabsTrigger", []),
54
30
  createInstance("tabs1content1", "TabsContent", [
55
- { type: "id", value: "tabs2" },
31
+ { type: "id", value: "tabs2" }
56
32
  ]),
57
33
  createInstance("tabs1content2", "TabsContent", []),
58
34
  // tabs2
59
35
  createInstance("tabs2", "Tabs", [
60
36
  { type: "id", value: "tabs2list" },
61
- { type: "id", value: "tabs2content1" },
37
+ { type: "id", value: "tabs2content1" }
62
38
  ]),
63
39
  createInstance("tabs2list", "TabsList", [
64
- { type: "id", value: "tabs2trigger1" },
40
+ { type: "id", value: "tabs2trigger1" }
65
41
  ]),
66
42
  createInstance("tabs2trigger1", "TabsTrigger", []),
67
- createInstance("tabs2content1", "TabsContent", []),
68
- ] satisfies Instance[]);
69
- const metas = new Map<Instance["component"], WsComponentMeta>([
43
+ createInstance("tabs2content1", "TabsContent", [])
44
+ ]);
45
+ const metas = /* @__PURE__ */ new Map([
70
46
  ["Body", createMeta()],
71
47
  ["Box", createMeta()],
72
48
  ["Tabs", createMeta()],
73
49
  ["TabsList", createMeta({ indexWithinAncestor: "Tabs" })],
74
50
  ["TabsTrigger", createMeta({ indexWithinAncestor: "TabsList" })],
75
- ["TabsContent", createMeta({ indexWithinAncestor: "Tabs" })],
51
+ ["TabsContent", createMeta({ indexWithinAncestor: "Tabs" })]
76
52
  ]);
77
53
  expect(getIndexesWithinAncestors(metas, instances, ["body0"])).toEqual(
78
- new Map([
54
+ /* @__PURE__ */ new Map([
79
55
  ["tabs1list", 0],
80
56
  ["tabs1trigger1", 0],
81
57
  ["tabs1trigger2", 1],
@@ -83,7 +59,7 @@ test("get indexes within ancestors", () => {
83
59
  ["tabs1content2", 1],
84
60
  ["tabs2list", 0],
85
61
  ["tabs2trigger1", 0],
86
- ["tabs2content1", 0],
62
+ ["tabs2content1", 0]
87
63
  ])
88
64
  );
89
65
  });
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ import { z } from "zod";
3
+ const common = {
4
+ label: z.string().optional(),
5
+ description: z.string().optional(),
6
+ required: z.boolean()
7
+ };
8
+ const Number = z.object({
9
+ ...common,
10
+ control: z.literal("number"),
11
+ type: z.literal("number"),
12
+ defaultValue: z.number().optional()
13
+ });
14
+ const Range = z.object({
15
+ ...common,
16
+ control: z.literal("range"),
17
+ type: z.literal("number"),
18
+ defaultValue: z.number().optional()
19
+ });
20
+ const Text = z.object({
21
+ ...common,
22
+ control: z.literal("text"),
23
+ type: z.literal("string"),
24
+ defaultValue: z.string().optional(),
25
+ /**
26
+ * The number of rows in <textarea>. If set to 0 an <input> will be used instead.
27
+ * In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
28
+ */
29
+ rows: z.number().optional()
30
+ });
31
+ const Code = z.object({
32
+ ...common,
33
+ control: z.literal("code"),
34
+ type: z.literal("string"),
35
+ defaultValue: z.string().optional(),
36
+ /**
37
+ * The number of rows in <textarea>. If set to 0 an <input> will be used instead.
38
+ * In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
39
+ */
40
+ rows: z.number().optional()
41
+ });
42
+ const Color = z.object({
43
+ ...common,
44
+ control: z.literal("color"),
45
+ type: z.literal("string"),
46
+ defaultValue: z.string().optional()
47
+ });
48
+ const Boolean = z.object({
49
+ ...common,
50
+ control: z.literal("boolean"),
51
+ type: z.literal("boolean"),
52
+ defaultValue: z.boolean().optional()
53
+ });
54
+ const Radio = z.object({
55
+ ...common,
56
+ control: z.literal("radio"),
57
+ type: z.literal("string"),
58
+ defaultValue: z.string().optional(),
59
+ options: z.array(z.string())
60
+ });
61
+ const InlineRadio = z.object({
62
+ ...common,
63
+ control: z.literal("inline-radio"),
64
+ type: z.literal("string"),
65
+ defaultValue: z.string().optional(),
66
+ options: z.array(z.string())
67
+ });
68
+ const Select = z.object({
69
+ ...common,
70
+ control: z.literal("select"),
71
+ type: z.literal("string"),
72
+ defaultValue: z.string().optional(),
73
+ options: z.array(z.string())
74
+ });
75
+ const Check = z.object({
76
+ ...common,
77
+ control: z.literal("check"),
78
+ type: z.literal("string[]"),
79
+ defaultValue: z.array(z.string()).optional(),
80
+ options: z.array(z.string())
81
+ });
82
+ const InlineCheck = z.object({
83
+ ...common,
84
+ control: z.literal("inline-check"),
85
+ type: z.literal("string[]"),
86
+ defaultValue: z.array(z.string()).optional(),
87
+ options: z.array(z.string())
88
+ });
89
+ const MultiSelect = z.object({
90
+ ...common,
91
+ control: z.literal("multi-select"),
92
+ type: z.literal("string[]"),
93
+ defaultValue: z.array(z.string()).optional(),
94
+ options: z.array(z.string())
95
+ });
96
+ const File = z.object({
97
+ ...common,
98
+ control: z.literal("file"),
99
+ type: z.literal("string"),
100
+ defaultValue: z.string().optional(),
101
+ /** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
102
+ accept: z.string().optional()
103
+ });
104
+ const Url = z.object({
105
+ ...common,
106
+ control: z.literal("url"),
107
+ type: z.literal("string"),
108
+ defaultValue: z.string().optional()
109
+ });
110
+ const ObjectType = z.object({
111
+ ...common,
112
+ control: z.literal("object"),
113
+ // @todo not sure what type should be here
114
+ // (we don't support Object yet, added for completeness)
115
+ type: z.literal("Record<string, string>"),
116
+ defaultValue: z.record(z.string()).optional()
117
+ });
118
+ const Date = z.object({
119
+ ...common,
120
+ control: z.literal("date"),
121
+ // @todo not sure what type should be here
122
+ // (we don't support Date yet, added for completeness)
123
+ type: z.literal("string"),
124
+ defaultValue: z.string().optional()
125
+ });
126
+ const Action = z.object({
127
+ ...common,
128
+ control: z.literal("action"),
129
+ type: z.literal("action"),
130
+ defaultValue: z.undefined().optional()
131
+ });
132
+ export const PropMeta = z.union([
133
+ Number,
134
+ Range,
135
+ Text,
136
+ Code,
137
+ Color,
138
+ Boolean,
139
+ Radio,
140
+ InlineRadio,
141
+ Select,
142
+ MultiSelect,
143
+ Check,
144
+ InlineCheck,
145
+ File,
146
+ Url,
147
+ ObjectType,
148
+ Date,
149
+ Action
150
+ ]);
package/lib/props.js CHANGED
@@ -1,9 +1,10 @@
1
+ "use strict";
1
2
  import { useContext, useMemo } from "react";
2
3
  import { computed } from "nanostores";
3
4
  import { useStore } from "@nanostores/react";
4
5
  import { ReactSdkContext } from "./context";
5
6
  import { idAttribute, indexAttribute } from "./tree/webstudio-component";
6
- const getPropsByInstanceId = (props) => {
7
+ export const getPropsByInstanceId = (props) => {
7
8
  const propsByInstanceId = /* @__PURE__ */ new Map();
8
9
  for (const prop of props.values()) {
9
10
  let instanceProps = propsByInstanceId.get(prop.instanceId);
@@ -15,7 +16,7 @@ const getPropsByInstanceId = (props) => {
15
16
  }
16
17
  return propsByInstanceId;
17
18
  };
18
- const useInstanceProps = (instanceId) => {
19
+ export const useInstanceProps = (instanceId) => {
19
20
  const {
20
21
  propsByInstanceIdStore,
21
22
  dataSourceValuesStore,
@@ -83,7 +84,7 @@ const useInstanceProps = (instanceId) => {
83
84
  const instancePropsObject = useStore(instancePropsObjectStore);
84
85
  return instancePropsObject;
85
86
  };
86
- const usePropAsset = (instanceId, name) => {
87
+ export const usePropAsset = (instanceId, name) => {
87
88
  const { propsByInstanceIdStore, assetsStore } = useContext(ReactSdkContext);
88
89
  const assetStore = useMemo(() => {
89
90
  return computed(
@@ -105,7 +106,7 @@ const usePropAsset = (instanceId, name) => {
105
106
  const asset = useStore(assetStore);
106
107
  return asset;
107
108
  };
108
- const resolveUrlProp = (instanceId, name, {
109
+ export const resolveUrlProp = (instanceId, name, {
109
110
  props,
110
111
  pages,
111
112
  assets
@@ -156,7 +157,7 @@ const resolveUrlProp = (instanceId, name, {
156
157
  }
157
158
  return;
158
159
  };
159
- const usePropUrl = (instanceId, name) => {
160
+ export const usePropUrl = (instanceId, name) => {
160
161
  const { propsByInstanceIdStore, pagesStore, assetsStore } = useContext(ReactSdkContext);
161
162
  const store = useMemo(
162
163
  () => computed(
@@ -167,18 +168,9 @@ const usePropUrl = (instanceId, name) => {
167
168
  );
168
169
  return useStore(store);
169
170
  };
170
- const getInstanceIdFromComponentProps = (props) => {
171
+ export const getInstanceIdFromComponentProps = (props) => {
171
172
  return props[idAttribute];
172
173
  };
173
- const getIndexWithinAncestorFromComponentProps = (props) => {
174
+ export const getIndexWithinAncestorFromComponentProps = (props) => {
174
175
  return props[indexAttribute];
175
176
  };
176
- export {
177
- getIndexWithinAncestorFromComponentProps,
178
- getInstanceIdFromComponentProps,
179
- getPropsByInstanceId,
180
- resolveUrlProp,
181
- useInstanceProps,
182
- usePropAsset,
183
- usePropUrl
184
- };
@@ -1,111 +1,95 @@
1
+ "use strict";
1
2
  import { describe, test, expect } from "@jest/globals";
2
- import { resolveUrlProp, type Pages, type PropsByInstanceId } from "./props";
3
- import type { Page, Prop } from "@webstudio-is/project-build";
4
- import type { Asset, Assets } from "@webstudio-is/asset-uploader";
5
-
3
+ import { resolveUrlProp } from "./props";
6
4
  const unique = () => Math.random().toString();
7
-
8
5
  describe("resolveUrlProp", () => {
9
6
  const instanceId = unique();
10
7
  const projectId = unique();
11
-
12
- const page1: Page = {
8
+ const page1 = {
13
9
  id: unique(),
14
10
  path: `/${unique()}`,
15
11
  name: "",
16
12
  title: "",
17
13
  meta: {},
18
- rootInstanceId: "0",
14
+ rootInstanceId: "0"
19
15
  };
20
-
21
- const page2: Page = {
16
+ const page2 = {
22
17
  id: unique(),
23
18
  path: `/${unique()}`,
24
19
  name: "",
25
20
  title: "",
26
21
  meta: {},
27
- rootInstanceId: "0",
22
+ rootInstanceId: "0"
28
23
  };
29
-
30
- const asset1: Asset = {
24
+ const asset1 = {
31
25
  id: unique(),
32
26
  name: unique(),
33
27
  type: "image",
34
28
  projectId,
35
29
  format: "png",
36
- size: 100000,
37
- createdAt: new Date().toISOString(),
30
+ size: 1e5,
31
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
38
32
  description: null,
39
- meta: { width: 128, height: 180 },
33
+ meta: { width: 128, height: 180 }
40
34
  };
41
-
42
- const assetProp: Prop = {
35
+ const assetProp = {
43
36
  type: "asset",
44
37
  id: unique(),
45
38
  instanceId,
46
39
  name: unique(),
47
- value: asset1.id,
40
+ value: asset1.id
48
41
  };
49
-
50
- const pageByIdProp: Prop = {
42
+ const pageByIdProp = {
51
43
  type: "page",
52
44
  id: unique(),
53
45
  instanceId,
54
46
  name: unique(),
55
- value: page1.id,
47
+ value: page1.id
56
48
  };
57
-
58
- const instnaceIdProp: Prop = {
49
+ const instnaceIdProp = {
59
50
  type: "string",
60
51
  id: unique(),
61
52
  instanceId: unique(),
62
53
  name: "id",
63
- value: unique(),
54
+ value: unique()
64
55
  };
65
-
66
- const pageSectionProp: Prop = {
56
+ const pageSectionProp = {
67
57
  type: "page",
68
58
  id: unique(),
69
59
  instanceId,
70
60
  name: unique(),
71
- value: { pageId: page1.id, instanceId: instnaceIdProp.instanceId },
61
+ value: { pageId: page1.id, instanceId: instnaceIdProp.instanceId }
72
62
  };
73
-
74
- const pageByPathProp: Prop = {
63
+ const pageByPathProp = {
75
64
  type: "string",
76
65
  id: unique(),
77
66
  instanceId,
78
67
  name: unique(),
79
- value: page2.path,
68
+ value: page2.path
80
69
  };
81
-
82
- const arbitraryUrlProp: Prop = {
70
+ const arbitraryUrlProp = {
83
71
  type: "string",
84
72
  id: unique(),
85
73
  instanceId,
86
74
  name: unique(),
87
- value: unique(),
75
+ value: unique()
88
76
  };
89
-
90
77
  const duplicatePropName = unique();
91
-
92
- const duplicateUrlPropFirst: Prop = {
78
+ const duplicateUrlPropFirst = {
93
79
  type: "string",
94
80
  id: unique(),
95
81
  instanceId,
96
82
  name: duplicatePropName,
97
- value: unique(),
83
+ value: unique()
98
84
  };
99
-
100
- const duplicateUrlPropSecond: Prop = {
85
+ const duplicateUrlPropSecond = {
101
86
  type: "string",
102
87
  id: unique(),
103
88
  instanceId,
104
89
  name: duplicatePropName,
105
- value: unique(),
90
+ value: unique()
106
91
  };
107
-
108
- const props: PropsByInstanceId = new Map([
92
+ const props = /* @__PURE__ */ new Map([
109
93
  [
110
94
  instanceId,
111
95
  [
@@ -115,74 +99,61 @@ describe("resolveUrlProp", () => {
115
99
  assetProp,
116
100
  pageSectionProp,
117
101
  duplicateUrlPropFirst,
118
- duplicateUrlPropSecond,
119
- ],
102
+ duplicateUrlPropSecond
103
+ ]
120
104
  ],
121
- [instnaceIdProp.instanceId, [instnaceIdProp]],
105
+ [instnaceIdProp.instanceId, [instnaceIdProp]]
122
106
  ]);
123
-
124
- const pages: Pages = new Map([
107
+ const pages = /* @__PURE__ */ new Map([
125
108
  [page1.id, page1],
126
- [page2.id, page2],
109
+ [page2.id, page2]
127
110
  ]);
128
-
129
- const assets: Assets = new Map([[asset1.id, asset1]]);
130
-
111
+ const assets = /* @__PURE__ */ new Map([[asset1.id, asset1]]);
131
112
  const stores = { props, pages, assets };
132
-
133
113
  test("if instanceId is unknown returns undefined", () => {
134
114
  expect(
135
115
  resolveUrlProp("unknown", pageByIdProp.name, stores)
136
116
  ).toBeUndefined();
137
117
  });
138
-
139
118
  test("if prop name is unknown returns undefined", () => {
140
119
  expect(resolveUrlProp(instanceId, "unknown", stores)).toBeUndefined();
141
120
  });
142
-
143
121
  test("asset by id", () => {
144
122
  expect(resolveUrlProp(instanceId, assetProp.name, stores)).toEqual({
145
123
  type: "asset",
146
- asset: asset1,
124
+ asset: asset1
147
125
  });
148
126
  });
149
-
150
127
  test("page by id", () => {
151
128
  expect(resolveUrlProp(instanceId, pageByIdProp.name, stores)).toEqual({
152
129
  type: "page",
153
- page: page1,
130
+ page: page1
154
131
  });
155
132
  });
156
-
157
133
  test("page by path", () => {
158
134
  expect(resolveUrlProp(instanceId, pageByPathProp.name, stores)).toEqual({
159
135
  type: "page",
160
- page: page2,
136
+ page: page2
161
137
  });
162
138
  });
163
-
164
139
  test("section on a page", () => {
165
140
  expect(resolveUrlProp(instanceId, pageSectionProp.name, stores)).toEqual({
166
141
  type: "page",
167
142
  page: page1,
168
143
  instanceId: instnaceIdProp.instanceId,
169
- hash: instnaceIdProp.value,
144
+ hash: instnaceIdProp.value
170
145
  });
171
146
  });
172
-
173
147
  test("arbitrary url", () => {
174
148
  expect(resolveUrlProp(instanceId, arbitraryUrlProp.name, stores)).toEqual({
175
149
  type: "string",
176
- url: arbitraryUrlProp.value,
150
+ url: arbitraryUrlProp.value
177
151
  });
178
152
  });
179
-
180
- // We had a bug that some props were duplicated https://github.com/webstudio-is/webstudio-builder/pull/2170
181
- // Use the latest prop to ensure consistency with the builder settings panel.
182
153
  test("duplicate prop name", () => {
183
154
  expect(resolveUrlProp(instanceId, duplicatePropName, stores)).toEqual({
184
155
  type: "string",
185
- url: duplicateUrlPropSecond.value,
156
+ url: duplicateUrlPropSecond.value
186
157
  });
187
158
  });
188
159
  });
@@ -1,7 +1,8 @@
1
+ "use strict";
1
2
  import { createNanoEvents } from "nanoevents";
2
3
  import { useCallback, useEffect, useRef } from "react";
3
4
  import { batchUpdate } from "./raf-queue";
4
- const createPubsub = () => {
5
+ export const createPubsub = () => {
5
6
  const emitter = createNanoEvents();
6
7
  if (typeof window === "object") {
7
8
  window.addEventListener(
@@ -53,6 +54,3 @@ const createPubsub = () => {
53
54
  }
54
55
  };
55
56
  };
56
- export {
57
- createPubsub
58
- };
@@ -1 +1,2 @@
1
+ "use strict";
1
2
  export * from "./create";
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  let handle;
2
3
  let updateQueue = [];
3
4
  const processUpdates = (updates) => {
@@ -5,7 +6,7 @@ const processUpdates = (updates) => {
5
6
  update();
6
7
  }
7
8
  };
8
- const batchUpdate = (update) => {
9
+ export const batchUpdate = (update) => {
9
10
  updateQueue.push(update);
10
11
  if (handle !== void 0) {
11
12
  return;
@@ -17,6 +18,3 @@ const batchUpdate = (update) => {
17
18
  processUpdates(updates);
18
19
  });
19
20
  };
20
- export {
21
- batchUpdate
22
- };
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  import { jsx, jsxs } from "react/jsx-runtime";
2
3
  import {
3
4
  Fragment
@@ -5,7 +6,7 @@ import {
5
6
  import {
6
7
  ReactSdkContext
7
8
  } from "../context";
8
- const createElementsTree = ({
9
+ export const createElementsTree = ({
9
10
  renderer,
10
11
  imageBaseUrl,
11
12
  assetBaseUrl,
@@ -131,6 +132,3 @@ const createInstanceElement = ({
131
132
  instance.id
132
133
  );
133
134
  };
134
- export {
135
- createElementsTree
136
- };
package/lib/tree/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  export * from "./create-elements-tree";
2
3
  export * from "./root";
3
4
  export * from "./webstudio-component";
package/lib/tree/root.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  import {
2
3
  useRef,
3
4
  useCallback
@@ -6,13 +7,12 @@ import {
6
7
  atom,
7
8
  computed
8
9
  } from "nanostores";
9
- import {} from "@webstudio-is/project-build";
10
10
  import { createElementsTree } from "./create-elements-tree";
11
11
  import {
12
12
  WebstudioComponent
13
13
  } from "./webstudio-component";
14
14
  import { getPropsByInstanceId } from "../props";
15
- const InstanceRoot = ({
15
+ export const InstanceRoot = ({
16
16
  data,
17
17
  utils,
18
18
  Component,
@@ -83,6 +83,3 @@ const InstanceRoot = ({
83
83
  scripts
84
84
  });
85
85
  };
86
- export {
87
- InstanceRoot
88
- };