@webstudio-is/react-sdk 0.120.0 → 0.122.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.
package/lib/index.js CHANGED
@@ -240,18 +240,10 @@ var createElementsTree = ({
240
240
  return null;
241
241
  }
242
242
  const rootInstanceSelector = [rootInstanceId];
243
- const children = createInstanceChildrenElements({
244
- instances,
245
- instanceSelector: rootInstanceSelector,
246
- Component,
247
- children: rootInstance.children,
248
- components
249
- });
250
243
  const root = createInstanceElement({
251
244
  Component,
252
245
  instance: rootInstance,
253
246
  instanceSelector: rootInstanceSelector,
254
- children,
255
247
  components
256
248
  });
257
249
  return /* @__PURE__ */ jsx(
@@ -293,18 +285,10 @@ var createInstanceChildrenElements = ({
293
285
  continue;
294
286
  }
295
287
  const childInstanceSelector = [child.value, ...instanceSelector];
296
- const children2 = createInstanceChildrenElements({
297
- instances,
298
- instanceSelector: childInstanceSelector,
299
- children: childInstance.children,
300
- Component,
301
- components
302
- });
303
288
  const element = createInstanceElement({
304
289
  instance: childInstance,
305
290
  instanceSelector: childInstanceSelector,
306
291
  Component,
307
- children: children2,
308
292
  components
309
293
  });
310
294
  elements.push(element);
@@ -318,7 +302,6 @@ var createInstanceElement = ({
318
302
  Component,
319
303
  instance,
320
304
  instanceSelector,
321
- children,
322
305
  components
323
306
  }) => {
324
307
  return /* @__PURE__ */ jsx(
@@ -326,8 +309,7 @@ var createInstanceElement = ({
326
309
  {
327
310
  instance,
328
311
  instanceSelector,
329
- components,
330
- children
312
+ components
331
313
  },
332
314
  instance.id
333
315
  );
@@ -351,7 +333,63 @@ var Root = ({
351
333
  };
352
334
 
353
335
  // src/core-components.ts
354
- var collectionComponent = "ws:component";
336
+ import { ListIcon } from "@webstudio-is/icons/svg";
337
+ var portalComponent = "Slot";
338
+ var collectionComponent = "ws:collection";
339
+ var collectionMeta = {
340
+ category: "general",
341
+ order: 7,
342
+ type: "container",
343
+ label: "Collection",
344
+ icon: ListIcon,
345
+ stylable: false,
346
+ template: [
347
+ {
348
+ type: "instance",
349
+ component: collectionComponent,
350
+ props: [
351
+ {
352
+ name: "data",
353
+ type: "json",
354
+ value: ["apple", "orange", "banana"]
355
+ },
356
+ { name: "item", type: "parameter", variableName: "collectionItem" }
357
+ ],
358
+ children: [
359
+ {
360
+ type: "instance",
361
+ component: "Box",
362
+ children: [
363
+ {
364
+ type: "instance",
365
+ component: "HtmlEmbed",
366
+ props: [
367
+ { name: "code", type: "expression", code: "collectionItem" }
368
+ ],
369
+ children: []
370
+ }
371
+ ]
372
+ }
373
+ ]
374
+ }
375
+ ]
376
+ };
377
+ var collectionPropsMeta = {
378
+ props: {
379
+ data: {
380
+ required: true,
381
+ control: "json",
382
+ type: "json"
383
+ }
384
+ },
385
+ initialProps: ["data"]
386
+ };
387
+ var coreMetas = {
388
+ [collectionComponent]: collectionMeta
389
+ };
390
+ var corePropsMetas = {
391
+ [collectionComponent]: collectionPropsMeta
392
+ };
355
393
 
356
394
  // src/prop-meta.ts
357
395
  import { z } from "zod";
@@ -673,10 +711,6 @@ var generateDataSources = ({
673
711
  }
674
712
  }
675
713
  for (const prop of props.values()) {
676
- if (prop.type === "parameter") {
677
- output.delete(prop.value);
678
- variables.delete(prop.value);
679
- }
680
714
  if (prop.type === "action") {
681
715
  const name = scope.getName(prop.id, prop.name);
682
716
  output.set(prop.id, name);
@@ -738,12 +772,7 @@ var EmbedTemplateText = z2.object({
738
772
  value: z2.string()
739
773
  });
740
774
  var EmbedTemplateVariable = z2.object({
741
- initialValue: z2.union([
742
- z2.string(),
743
- z2.number(),
744
- z2.boolean(),
745
- z2.array(z2.string())
746
- ])
775
+ initialValue: z2.unknown()
747
776
  });
748
777
  var EmbedTemplateProp = z2.union([
749
778
  z2.object({
@@ -766,11 +795,21 @@ var EmbedTemplateProp = z2.union([
766
795
  name: z2.string(),
767
796
  value: z2.array(z2.string())
768
797
  }),
798
+ z2.object({
799
+ type: z2.literal("json"),
800
+ name: z2.string(),
801
+ value: z2.unknown()
802
+ }),
769
803
  z2.object({
770
804
  type: z2.literal("expression"),
771
805
  name: z2.string(),
772
806
  code: z2.string()
773
807
  }),
808
+ z2.object({
809
+ type: z2.literal("parameter"),
810
+ name: z2.string(),
811
+ variableName: z2.string()
812
+ }),
774
813
  z2.object({
775
814
  type: z2.literal("action"),
776
815
  name: z2.string(),
@@ -818,8 +857,7 @@ var getVariablValue = (value) => {
818
857
  if (Array.isArray(value)) {
819
858
  return { type: "string[]", value };
820
859
  }
821
- value;
822
- throw Error("Impossible case");
860
+ return { type: "json", value };
823
861
  };
824
862
  var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByRef, styleSourceSelections, styleSources, styles, metas, defaultBreakpointId, generateId) => {
825
863
  const parentChildren = [];
@@ -886,6 +924,24 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
886
924
  });
887
925
  continue;
888
926
  }
927
+ if (prop.type === "parameter") {
928
+ const dataSourceId = generateId();
929
+ dataSourceByRef.set(prop.variableName, {
930
+ type: "parameter",
931
+ id: dataSourceId,
932
+ scopeInstanceId: instanceId,
933
+ name: prop.variableName
934
+ });
935
+ props.push({
936
+ id: propId,
937
+ instanceId,
938
+ name: prop.name,
939
+ type: "parameter",
940
+ // replace variable reference with variable id
941
+ value: dataSourceId
942
+ });
943
+ continue;
944
+ }
889
945
  props.push({ id: propId, instanceId, ...prop });
890
946
  }
891
947
  }
@@ -1435,8 +1491,11 @@ export {
1435
1491
  collectionComponent,
1436
1492
  componentAttribute,
1437
1493
  componentCategories,
1494
+ coreMetas,
1495
+ corePropsMetas,
1438
1496
  createElementsTree,
1439
1497
  createImageValueTransformer,
1498
+ createInstanceChildrenElements,
1440
1499
  decodeDataSourceVariable,
1441
1500
  defaultStates,
1442
1501
  encodeDataSourceVariable,
@@ -1457,6 +1516,7 @@ export {
1457
1516
  indexAttribute,
1458
1517
  namespaceMeta,
1459
1518
  normalizeProps,
1519
+ portalComponent,
1460
1520
  selectorIdAttribute,
1461
1521
  showAttribute,
1462
1522
  stateCategories,
@@ -105,6 +105,11 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
105
105
  name: string;
106
106
  id: string;
107
107
  scopeInstanceId?: string | undefined;
108
+ } | {
109
+ type: "parameter";
110
+ name: string;
111
+ id: string;
112
+ scopeInstanceId?: string | undefined;
108
113
  }>;
109
114
  indexesWithinAncestors: IndexesWithinAncestors;
110
115
  children: string;
@@ -227,6 +232,11 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
227
232
  name: string;
228
233
  id: string;
229
234
  scopeInstanceId?: string | undefined;
235
+ } | {
236
+ type: "parameter";
237
+ name: string;
238
+ id: string;
239
+ scopeInstanceId?: string | undefined;
230
240
  }>;
231
241
  indexesWithinAncestors: IndexesWithinAncestors;
232
242
  }) => string;
@@ -348,6 +358,11 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
348
358
  name: string;
349
359
  id: string;
350
360
  scopeInstanceId?: string | undefined;
361
+ } | {
362
+ type: "parameter";
363
+ name: string;
364
+ id: string;
365
+ scopeInstanceId?: string | undefined;
351
366
  }>;
352
367
  indexesWithinAncestors: IndexesWithinAncestors;
353
368
  }) => string;
@@ -1 +1,140 @@
1
- export declare const collectionComponent = "ws:component";
1
+ import type { WsComponentMeta } from "./components/component-meta";
2
+ export declare const portalComponent = "Slot";
3
+ export declare const collectionComponent = "ws:collection";
4
+ export declare const coreMetas: {
5
+ "ws:collection": WsComponentMeta;
6
+ };
7
+ export declare const corePropsMetas: {
8
+ "ws:collection": {
9
+ props: Record<string, {
10
+ type: "number";
11
+ required: boolean;
12
+ control: "number";
13
+ defaultValue?: number | undefined;
14
+ label?: string | undefined;
15
+ description?: string | undefined;
16
+ } | {
17
+ type: "number";
18
+ required: boolean;
19
+ control: "range";
20
+ defaultValue?: number | undefined;
21
+ label?: string | undefined;
22
+ description?: string | undefined;
23
+ } | {
24
+ type: "string";
25
+ required: boolean;
26
+ control: "text";
27
+ defaultValue?: string | undefined;
28
+ rows?: number | undefined;
29
+ label?: string | undefined;
30
+ description?: string | undefined;
31
+ } | {
32
+ type: "string";
33
+ required: boolean;
34
+ control: "code";
35
+ defaultValue?: string | undefined;
36
+ rows?: number | undefined;
37
+ label?: string | undefined;
38
+ description?: string | undefined;
39
+ } | {
40
+ type: "string";
41
+ required: boolean;
42
+ control: "color";
43
+ defaultValue?: string | undefined;
44
+ label?: string | undefined;
45
+ description?: string | undefined;
46
+ } | {
47
+ type: "boolean";
48
+ required: boolean;
49
+ control: "boolean";
50
+ defaultValue?: boolean | undefined;
51
+ label?: string | undefined;
52
+ description?: string | undefined;
53
+ } | {
54
+ options: string[];
55
+ type: "string";
56
+ required: boolean;
57
+ control: "radio";
58
+ defaultValue?: string | undefined;
59
+ label?: string | undefined;
60
+ description?: string | undefined;
61
+ } | {
62
+ options: string[];
63
+ type: "string";
64
+ required: boolean;
65
+ control: "inline-radio";
66
+ defaultValue?: string | undefined;
67
+ label?: string | undefined;
68
+ description?: string | undefined;
69
+ } | {
70
+ options: string[];
71
+ type: "string";
72
+ required: boolean;
73
+ control: "select";
74
+ defaultValue?: string | undefined;
75
+ label?: string | undefined;
76
+ description?: string | undefined;
77
+ } | {
78
+ options: string[];
79
+ type: "string[]";
80
+ required: boolean;
81
+ control: "check";
82
+ defaultValue?: string[] | undefined;
83
+ label?: string | undefined;
84
+ description?: string | undefined;
85
+ } | {
86
+ options: string[];
87
+ type: "string[]";
88
+ required: boolean;
89
+ control: "inline-check";
90
+ defaultValue?: string[] | undefined;
91
+ label?: string | undefined;
92
+ description?: string | undefined;
93
+ } | {
94
+ options: string[];
95
+ type: "string[]";
96
+ required: boolean;
97
+ control: "multi-select";
98
+ defaultValue?: string[] | undefined;
99
+ label?: string | undefined;
100
+ description?: string | undefined;
101
+ } | {
102
+ type: "string";
103
+ required: boolean;
104
+ control: "file";
105
+ defaultValue?: string | undefined;
106
+ accept?: string | undefined;
107
+ label?: string | undefined;
108
+ description?: string | undefined;
109
+ } | {
110
+ type: "string";
111
+ required: boolean;
112
+ control: "url";
113
+ defaultValue?: string | undefined;
114
+ label?: string | undefined;
115
+ description?: string | undefined;
116
+ } | {
117
+ type: "json";
118
+ required: boolean;
119
+ control: "json";
120
+ defaultValue?: unknown;
121
+ label?: string | undefined;
122
+ description?: string | undefined;
123
+ } | {
124
+ type: "string";
125
+ required: boolean;
126
+ control: "date";
127
+ defaultValue?: string | undefined;
128
+ label?: string | undefined;
129
+ description?: string | undefined;
130
+ } | {
131
+ type: "action";
132
+ required: boolean;
133
+ control: "action";
134
+ defaultValue?: undefined;
135
+ label?: string | undefined;
136
+ description?: string | undefined;
137
+ }>;
138
+ initialProps?: string[] | undefined;
139
+ };
140
+ };
@@ -15,11 +15,11 @@ declare const EmbedTemplateText: z.ZodObject<{
15
15
  }>;
16
16
  type EmbedTemplateText = z.infer<typeof EmbedTemplateText>;
17
17
  declare const EmbedTemplateVariable: z.ZodObject<{
18
- initialValue: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">]>;
18
+ initialValue: z.ZodUnknown;
19
19
  }, "strip", z.ZodTypeAny, {
20
- initialValue: (string | number | boolean | string[]) & (string | number | boolean | string[] | undefined);
20
+ initialValue?: unknown;
21
21
  }, {
22
- initialValue: (string | number | boolean | string[]) & (string | number | boolean | string[] | undefined);
22
+ initialValue?: unknown;
23
23
  }>;
24
24
  type EmbedTemplateVariable = z.infer<typeof EmbedTemplateVariable>;
25
25
  export declare const EmbedTemplateProp: z.ZodUnion<[z.ZodObject<{
@@ -70,6 +70,18 @@ export declare const EmbedTemplateProp: z.ZodUnion<[z.ZodObject<{
70
70
  value: string[];
71
71
  type: "string[]";
72
72
  name: string;
73
+ }>, z.ZodObject<{
74
+ type: z.ZodLiteral<"json">;
75
+ name: z.ZodString;
76
+ value: z.ZodUnknown;
77
+ }, "strip", z.ZodTypeAny, {
78
+ type: "json";
79
+ name: string;
80
+ value?: unknown;
81
+ }, {
82
+ type: "json";
83
+ name: string;
84
+ value?: unknown;
73
85
  }>, z.ZodObject<{
74
86
  type: z.ZodLiteral<"expression">;
75
87
  name: z.ZodString;
@@ -82,6 +94,18 @@ export declare const EmbedTemplateProp: z.ZodUnion<[z.ZodObject<{
82
94
  code: string;
83
95
  type: "expression";
84
96
  name: string;
97
+ }>, z.ZodObject<{
98
+ type: z.ZodLiteral<"parameter">;
99
+ name: z.ZodString;
100
+ variableName: z.ZodString;
101
+ }, "strip", z.ZodTypeAny, {
102
+ type: "parameter";
103
+ name: string;
104
+ variableName: string;
105
+ }, {
106
+ type: "parameter";
107
+ name: string;
108
+ variableName: string;
85
109
  }>, z.ZodObject<{
86
110
  type: z.ZodLiteral<"action">;
87
111
  name: z.ZodString;
@@ -2286,7 +2310,7 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2286
2310
  instanceId: string;
2287
2311
  required?: boolean | undefined;
2288
2312
  })[];
2289
- dataSources: {
2313
+ dataSources: ({
2290
2314
  value: {
2291
2315
  value: number;
2292
2316
  type: "number";
@@ -2307,7 +2331,12 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2307
2331
  name: string;
2308
2332
  id: string;
2309
2333
  scopeInstanceId?: string | undefined;
2310
- }[];
2334
+ } | {
2335
+ type: "parameter";
2336
+ name: string;
2337
+ id: string;
2338
+ scopeInstanceId?: string | undefined;
2339
+ })[];
2311
2340
  styleSourceSelections: {
2312
2341
  values: string[];
2313
2342
  instanceId: string;
@@ -39,6 +39,11 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
39
39
  name: string;
40
40
  id: string;
41
41
  scopeInstanceId?: string | undefined;
42
+ } | {
43
+ type: "parameter";
44
+ name: string;
45
+ id: string;
46
+ scopeInstanceId?: string | undefined;
42
47
  }>;
43
48
  props: Map<string, {
44
49
  value: number;
@@ -3,10 +3,10 @@ import type { Instance, Instances } from "@webstudio-is/sdk";
3
3
  import type { Components } from "../components/components-utils";
4
4
  import { type Params } from "../context";
5
5
  import type { ImageLoader } from "@webstudio-is/image";
6
+ type InstanceSelector = Instance["id"][];
6
7
  export type WebstudioComponentProps = {
7
8
  instance: Instance;
8
9
  instanceSelector: Instance["id"][];
9
- children: ReactNode;
10
10
  components: Components;
11
11
  };
12
12
  export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl, imageLoader, instances, rootInstanceId, Component, components, }: Params & {
@@ -28,3 +28,23 @@ export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl
28
28
  Component: ForwardRefExoticComponent<WebstudioComponentProps & RefAttributes<HTMLElement>>;
29
29
  components: Components;
30
30
  }) => import("react/jsx-runtime").JSX.Element | null;
31
+ export declare const createInstanceChildrenElements: ({ instances, instanceSelector, children, Component, components, }: {
32
+ instances: Map<string, {
33
+ type: "instance";
34
+ id: string;
35
+ component: string;
36
+ children: ({
37
+ value: string;
38
+ type: "text";
39
+ } | {
40
+ value: string;
41
+ type: "id";
42
+ })[];
43
+ label?: string | undefined;
44
+ }>;
45
+ instanceSelector: InstanceSelector;
46
+ children: Instance["children"];
47
+ Component: ForwardRefExoticComponent<WebstudioComponentProps & RefAttributes<HTMLElement>>;
48
+ components: Components;
49
+ }) => ReactNode[] | undefined;
50
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.120.0",
3
+ "version": "0.122.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -33,10 +33,11 @@
33
33
  "jsep": "^1.3.8",
34
34
  "nanoid": "^5.0.1",
35
35
  "title-case": "^4.1.0",
36
- "@webstudio-is/css-engine": "0.120.0",
37
- "@webstudio-is/fonts": "0.120.0",
38
- "@webstudio-is/image": "0.120.0",
39
- "@webstudio-is/sdk": "0.120.0"
36
+ "@webstudio-is/css-engine": "0.122.0",
37
+ "@webstudio-is/icons": "^0.122.0",
38
+ "@webstudio-is/image": "0.122.0",
39
+ "@webstudio-is/fonts": "0.122.0",
40
+ "@webstudio-is/sdk": "0.122.0"
40
41
  },
41
42
  "exports": {
42
43
  ".": {