@webstudio-is/react-sdk 0.118.0 → 0.119.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
@@ -14,143 +14,79 @@ var addGlobalRules = (engine, { assets, assetBaseUrl }) => {
14
14
  }
15
15
  };
16
16
 
17
- // src/tree/create-elements-tree.tsx
18
- import {
19
- Fragment
20
- } from "react";
21
-
22
- // src/context.tsx
23
- import { createContext } from "react";
24
- var ReactSdkContext = createContext({
25
- assetBaseUrl: "/",
26
- imageBaseUrl: "/",
27
- imageLoader: ({ src }) => src,
28
- pagesPaths: /* @__PURE__ */ new Set()
29
- });
30
-
31
- // src/tree/create-elements-tree.tsx
32
- import { jsx, jsxs } from "react/jsx-runtime";
33
- var createElementsTree = ({
34
- renderer,
17
+ // src/props.ts
18
+ var normalizeProps = ({
19
+ props,
35
20
  assetBaseUrl,
36
- imageBaseUrl,
37
- imageLoader,
38
- instances,
39
- rootInstanceId,
40
- Component,
41
- components,
42
- scripts
43
- }) => {
44
- const rootInstance = instances.get(rootInstanceId);
45
- if (rootInstance === void 0) {
46
- return null;
47
- }
48
- const rootInstanceSelector = [rootInstanceId];
49
- const children = createInstanceChildrenElements({
50
- instances,
51
- instanceSelector: rootInstanceSelector,
52
- Component,
53
- children: rootInstance.children,
54
- components
55
- });
56
- const root = createInstanceElement({
57
- Component,
58
- instance: rootInstance,
59
- instanceSelector: rootInstanceSelector,
60
- children: [
61
- /* @__PURE__ */ jsxs(Fragment, { children: [
62
- children,
63
- scripts
64
- ] }, "children")
65
- ],
66
- components
67
- });
68
- return /* @__PURE__ */ jsx(
69
- ReactSdkContext.Provider,
70
- {
71
- value: {
72
- renderer,
73
- imageLoader,
74
- pagesPaths: /* @__PURE__ */ new Set(),
75
- assetBaseUrl,
76
- imageBaseUrl
77
- },
78
- children: root
79
- }
80
- );
81
- };
82
- var createInstanceChildrenElements = ({
83
- instances,
84
- instanceSelector,
85
- children,
86
- Component,
87
- components
21
+ assets,
22
+ pages
88
23
  }) => {
89
- const elements = [];
90
- for (const child of children) {
91
- if (child.type === "text") {
92
- elements.push(child.value);
24
+ const newProps = [];
25
+ for (const prop of props) {
26
+ if (prop.type === "asset") {
27
+ const assetId = prop.value;
28
+ const asset = assets.get(assetId);
29
+ if (asset === void 0) {
30
+ continue;
31
+ }
32
+ newProps.push({
33
+ id: prop.id,
34
+ name: prop.name,
35
+ required: prop.required,
36
+ instanceId: prop.instanceId,
37
+ type: "string",
38
+ value: `${assetBaseUrl}${asset.name}`
39
+ });
93
40
  continue;
94
41
  }
95
- const childInstance = instances.get(child.value);
96
- if (childInstance === void 0) {
42
+ if (prop.type === "page") {
43
+ let page;
44
+ let idProp;
45
+ if (typeof prop.value === "string") {
46
+ const pageId = prop.value;
47
+ page = pages.get(pageId);
48
+ } else {
49
+ const { pageId, instanceId } = prop.value;
50
+ page = pages.get(pageId);
51
+ idProp = props.find(
52
+ (prop2) => prop2.instanceId === instanceId && prop2.name === "id"
53
+ );
54
+ }
55
+ if (page === void 0) {
56
+ continue;
57
+ }
58
+ const url = new URL(page.path, "https://any-valid.url");
59
+ let value = url.pathname;
60
+ if (idProp?.type === "string") {
61
+ const hash = idProp.value;
62
+ url.hash = encodeURIComponent(hash);
63
+ value = `${url.pathname}${url.hash}`;
64
+ }
65
+ newProps.push({
66
+ id: prop.id,
67
+ name: prop.name,
68
+ required: prop.required,
69
+ instanceId: prop.instanceId,
70
+ type: "string",
71
+ value
72
+ });
97
73
  continue;
98
74
  }
99
- const childInstanceSelector = [child.value, ...instanceSelector];
100
- const children2 = createInstanceChildrenElements({
101
- instances,
102
- instanceSelector: childInstanceSelector,
103
- children: childInstance.children,
104
- Component,
105
- components
106
- });
107
- const element = createInstanceElement({
108
- instance: childInstance,
109
- instanceSelector: childInstanceSelector,
110
- Component,
111
- children: children2,
112
- components
113
- });
114
- elements.push(element);
75
+ newProps.push(prop);
115
76
  }
116
- return elements;
117
- };
118
- var createInstanceElement = ({
119
- Component,
120
- instance,
121
- instanceSelector,
122
- children = [],
123
- components
124
- }) => {
125
- return /* @__PURE__ */ jsx(
126
- Component,
127
- {
128
- instance,
129
- instanceSelector,
130
- components,
131
- children
132
- },
133
- instance.id
134
- );
135
- };
136
-
137
- // src/tree/webstudio-component.tsx
138
- import { Fragment as Fragment2 } from "react";
139
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
140
- var renderText = (text) => {
141
- const lines = text.split("\n");
142
- return lines.map((line, index) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
143
- line,
144
- index < lines.length - 1 ? /* @__PURE__ */ jsx2("br", {}) : null
145
- ] }, index));
77
+ return newProps;
146
78
  };
147
- var renderWebstudioComponentChildren = (children) => {
148
- if (children === void 0 || children.length === 0) {
149
- return;
79
+ var getPropsByInstanceId = (props) => {
80
+ const propsByInstanceId = /* @__PURE__ */ new Map();
81
+ for (const prop of props.values()) {
82
+ let instanceProps = propsByInstanceId.get(prop.instanceId);
83
+ if (instanceProps === void 0) {
84
+ instanceProps = [];
85
+ propsByInstanceId.set(prop.instanceId, instanceProps);
86
+ }
87
+ instanceProps.push(prop);
150
88
  }
151
- return children.map((child) => {
152
- return typeof child === "string" ? renderText(child) : child;
153
- });
89
+ return propsByInstanceId;
154
90
  };
155
91
  var idAttribute = "data-ws-id";
156
92
  var selectorIdAttribute = "data-ws-selector";
@@ -158,6 +94,12 @@ var componentAttribute = "data-ws-component";
158
94
  var showAttribute = "data-ws-show";
159
95
  var indexAttribute = "data-ws-index";
160
96
  var collapsedAttribute = "data-ws-collapsed";
97
+ var getInstanceIdFromComponentProps = (props) => {
98
+ return props[idAttribute];
99
+ };
100
+ var getIndexWithinAncestorFromComponentProps = (props) => {
101
+ return props[indexAttribute];
102
+ };
161
103
 
162
104
  // src/css/style-rules.ts
163
105
  var getStyleRules = (styles, styleSourceSelections) => {
@@ -279,23 +221,150 @@ var generateCssText = (data, options) => {
279
221
  return engine.cssText;
280
222
  };
281
223
 
224
+ // src/tree/create-elements-tree.tsx
225
+ import {
226
+ Fragment
227
+ } from "react";
228
+
229
+ // src/context.tsx
230
+ import { createContext } from "react";
231
+ var ReactSdkContext = createContext({
232
+ assetBaseUrl: "/",
233
+ imageBaseUrl: "/",
234
+ imageLoader: ({ src }) => src,
235
+ pagesPaths: /* @__PURE__ */ new Set()
236
+ });
237
+
238
+ // src/tree/create-elements-tree.tsx
239
+ import { jsx, jsxs } from "react/jsx-runtime";
240
+ var createElementsTree = ({
241
+ renderer,
242
+ assetBaseUrl,
243
+ imageBaseUrl,
244
+ imageLoader,
245
+ instances,
246
+ rootInstanceId,
247
+ Component,
248
+ components
249
+ }) => {
250
+ const rootInstance = instances.get(rootInstanceId);
251
+ if (rootInstance === void 0) {
252
+ return null;
253
+ }
254
+ const rootInstanceSelector = [rootInstanceId];
255
+ const children = createInstanceChildrenElements({
256
+ instances,
257
+ instanceSelector: rootInstanceSelector,
258
+ Component,
259
+ children: rootInstance.children,
260
+ components
261
+ });
262
+ const root = createInstanceElement({
263
+ Component,
264
+ instance: rootInstance,
265
+ instanceSelector: rootInstanceSelector,
266
+ children,
267
+ components
268
+ });
269
+ return /* @__PURE__ */ jsx(
270
+ ReactSdkContext.Provider,
271
+ {
272
+ value: {
273
+ renderer,
274
+ imageLoader,
275
+ pagesPaths: /* @__PURE__ */ new Set(),
276
+ assetBaseUrl,
277
+ imageBaseUrl
278
+ },
279
+ children: root
280
+ }
281
+ );
282
+ };
283
+ var renderText = (text) => {
284
+ const lines = text.split("\n");
285
+ return lines.map((line, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
286
+ line,
287
+ index < lines.length - 1 && /* @__PURE__ */ jsx("br", {})
288
+ ] }, index));
289
+ };
290
+ var createInstanceChildrenElements = ({
291
+ instances,
292
+ instanceSelector,
293
+ children,
294
+ Component,
295
+ components
296
+ }) => {
297
+ const elements = [];
298
+ for (const child of children) {
299
+ if (child.type === "text") {
300
+ elements.push(renderText(child.value));
301
+ continue;
302
+ }
303
+ const childInstance = instances.get(child.value);
304
+ if (childInstance === void 0) {
305
+ continue;
306
+ }
307
+ const childInstanceSelector = [child.value, ...instanceSelector];
308
+ const children2 = createInstanceChildrenElements({
309
+ instances,
310
+ instanceSelector: childInstanceSelector,
311
+ children: childInstance.children,
312
+ Component,
313
+ components
314
+ });
315
+ const element = createInstanceElement({
316
+ instance: childInstance,
317
+ instanceSelector: childInstanceSelector,
318
+ Component,
319
+ children: children2,
320
+ components
321
+ });
322
+ elements.push(element);
323
+ }
324
+ if (elements.length === 0) {
325
+ return;
326
+ }
327
+ return elements;
328
+ };
329
+ var createInstanceElement = ({
330
+ Component,
331
+ instance,
332
+ instanceSelector,
333
+ children,
334
+ components
335
+ }) => {
336
+ return /* @__PURE__ */ jsx(
337
+ Component,
338
+ {
339
+ instance,
340
+ instanceSelector,
341
+ components,
342
+ children
343
+ },
344
+ instance.id
345
+ );
346
+ };
347
+
282
348
  // src/app/root.tsx
283
349
  import { Links, Meta, Outlet as DefaultOutlet } from "@remix-run/react";
284
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
350
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
285
351
  var Root = ({
286
352
  Outlet = DefaultOutlet
287
353
  }) => {
288
- return /* @__PURE__ */ jsxs3("html", { lang: "en", children: [
289
- /* @__PURE__ */ jsxs3("head", { children: [
290
- /* @__PURE__ */ jsx3("meta", { charSet: "utf-8" }),
291
- /* @__PURE__ */ jsx3("meta", { name: "viewport", content: "width=device-width,initial-scale=1" }),
292
- /* @__PURE__ */ jsx3(Meta, {}),
293
- /* @__PURE__ */ jsx3(Links, {})
354
+ return /* @__PURE__ */ jsxs2("html", { lang: "en", children: [
355
+ /* @__PURE__ */ jsxs2("head", { children: [
356
+ /* @__PURE__ */ jsx2("meta", { charSet: "utf-8" }),
357
+ /* @__PURE__ */ jsx2("meta", { name: "viewport", content: "width=device-width,initial-scale=1" }),
358
+ /* @__PURE__ */ jsx2(Meta, {}),
359
+ /* @__PURE__ */ jsx2(Links, {})
294
360
  ] }),
295
- /* @__PURE__ */ jsx3(Outlet, {})
361
+ /* @__PURE__ */ jsx2(Outlet, {})
296
362
  ] });
297
363
  };
298
364
 
365
+ // src/core-components.ts
366
+ var collectionComponent = "ws:component";
367
+
299
368
  // src/prop-meta.ts
300
369
  import { z } from "zod";
301
370
  var common = {
@@ -405,13 +474,11 @@ var Url = z.object({
405
474
  type: z.literal("string"),
406
475
  defaultValue: z.string().optional()
407
476
  });
408
- var ObjectType = z.object({
477
+ var Json = z.object({
409
478
  ...common,
410
- control: z.literal("object"),
411
- // @todo not sure what type should be here
412
- // (we don't support Object yet, added for completeness)
413
- type: z.literal("Record<string, string>"),
414
- defaultValue: z.record(z.string()).optional()
479
+ control: z.literal("json"),
480
+ type: z.literal("json"),
481
+ defaultValue: z.unknown().optional()
415
482
  });
416
483
  var Date = z.object({
417
484
  ...common,
@@ -442,7 +509,7 @@ var PropMeta = z.union([
442
509
  InlineCheck,
443
510
  File,
444
511
  Url,
445
- ObjectType,
512
+ Json,
446
513
  Date,
447
514
  Action
448
515
  ]);
@@ -618,11 +685,15 @@ var generateDataSources = ({
618
685
  }
619
686
  }
620
687
  for (const prop of props.values()) {
688
+ if (prop.type === "parameter") {
689
+ output.delete(prop.value);
690
+ variables.delete(prop.value);
691
+ }
621
692
  if (prop.type === "action") {
622
693
  const name = scope.getName(prop.id, prop.name);
623
694
  output.set(prop.id, name);
624
695
  const setters = /* @__PURE__ */ new Set();
625
- let args = void 0;
696
+ let args = [];
626
697
  let newCode = "";
627
698
  for (const value of prop.value) {
628
699
  args = value.args;
@@ -649,9 +720,6 @@ var generateDataSources = ({
649
720
  newCode += `
650
721
  `;
651
722
  }
652
- if (args === void 0) {
653
- continue;
654
- }
655
723
  if (typed) {
656
724
  args = args.map((arg) => `${arg}: any`);
657
725
  }
@@ -1054,87 +1122,6 @@ var WsComponentMeta = z3.object({
1054
1122
  order: z3.number().optional()
1055
1123
  });
1056
1124
 
1057
- // src/props.ts
1058
- var normalizeProps = ({
1059
- props,
1060
- assetBaseUrl,
1061
- assets,
1062
- pages
1063
- }) => {
1064
- const newProps = [];
1065
- for (const prop of props) {
1066
- if (prop.type === "asset") {
1067
- const assetId = prop.value;
1068
- const asset = assets.get(assetId);
1069
- if (asset === void 0) {
1070
- continue;
1071
- }
1072
- newProps.push({
1073
- id: prop.id,
1074
- name: prop.name,
1075
- required: prop.required,
1076
- instanceId: prop.instanceId,
1077
- type: "string",
1078
- value: `${assetBaseUrl}${asset.name}`
1079
- });
1080
- continue;
1081
- }
1082
- if (prop.type === "page") {
1083
- let page;
1084
- let idProp;
1085
- if (typeof prop.value === "string") {
1086
- const pageId = prop.value;
1087
- page = pages.get(pageId);
1088
- } else {
1089
- const { pageId, instanceId } = prop.value;
1090
- page = pages.get(pageId);
1091
- idProp = props.find(
1092
- (prop2) => prop2.instanceId === instanceId && prop2.name === "id"
1093
- );
1094
- }
1095
- if (page === void 0) {
1096
- continue;
1097
- }
1098
- const url = new URL(page.path, "https://any-valid.url");
1099
- let value = url.pathname;
1100
- if (idProp?.type === "string") {
1101
- const hash = idProp.value;
1102
- url.hash = encodeURIComponent(hash);
1103
- value = `${url.pathname}${url.hash}`;
1104
- }
1105
- newProps.push({
1106
- id: prop.id,
1107
- name: prop.name,
1108
- required: prop.required,
1109
- instanceId: prop.instanceId,
1110
- type: "string",
1111
- value
1112
- });
1113
- continue;
1114
- }
1115
- newProps.push(prop);
1116
- }
1117
- return newProps;
1118
- };
1119
- var getPropsByInstanceId = (props) => {
1120
- const propsByInstanceId = /* @__PURE__ */ new Map();
1121
- for (const prop of props.values()) {
1122
- let instanceProps = propsByInstanceId.get(prop.instanceId);
1123
- if (instanceProps === void 0) {
1124
- instanceProps = [];
1125
- propsByInstanceId.set(prop.instanceId, instanceProps);
1126
- }
1127
- instanceProps.push(prop);
1128
- }
1129
- return propsByInstanceId;
1130
- };
1131
- var getInstanceIdFromComponentProps = (props) => {
1132
- return props[idAttribute];
1133
- };
1134
- var getIndexWithinAncestorFromComponentProps = (props) => {
1135
- return props[indexAttribute];
1136
- };
1137
-
1138
1125
  // src/instance-utils.ts
1139
1126
  var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1140
1127
  const ancestors = /* @__PURE__ */ new Set();
@@ -1237,6 +1224,13 @@ var generatePropValue = ({
1237
1224
  if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
1238
1225
  return JSON.stringify(prop.value);
1239
1226
  }
1227
+ if (prop.type === "parameter") {
1228
+ const dataSource = dataSources.get(prop.value);
1229
+ if (dataSource === void 0) {
1230
+ return;
1231
+ }
1232
+ return scope.getName(dataSource.id, dataSource.name);
1233
+ }
1240
1234
  if (prop.type === "expression") {
1241
1235
  return validateExpression(prop.value, {
1242
1236
  // transpile to safely executable member expressions
@@ -1264,7 +1258,6 @@ var generateJsxElement = ({
1264
1258
  indexesWithinAncestors,
1265
1259
  children
1266
1260
  }) => {
1267
- let conditionValue;
1268
1261
  let generatedProps = "";
1269
1262
  generatedProps += `
1270
1263
  ${idAttribute}=${JSON.stringify(instance.id)}`;
@@ -1277,6 +1270,9 @@ ${componentAttribute}=${JSON.stringify(
1277
1270
  generatedProps += `
1278
1271
  ${indexAttribute}="${index}"`;
1279
1272
  }
1273
+ let conditionValue;
1274
+ let collectionDataValue;
1275
+ let collectionItemValue;
1280
1276
  for (const prop of props.values()) {
1281
1277
  if (prop.instanceId !== instance.id) {
1282
1278
  continue;
@@ -1292,6 +1288,15 @@ ${indexAttribute}="${index}"`;
1292
1288
  conditionValue = propValue;
1293
1289
  continue;
1294
1290
  }
1291
+ if (instance.component === collectionComponent) {
1292
+ if (prop.name === "data") {
1293
+ collectionDataValue = propValue;
1294
+ }
1295
+ if (prop.name === "item") {
1296
+ collectionItemValue = propValue;
1297
+ }
1298
+ continue;
1299
+ }
1295
1300
  if (propValue !== void 0) {
1296
1301
  generatedProps += `
1297
1302
  ${prop.name}={${propValue}}`;
@@ -1302,17 +1307,33 @@ ${prop.name}={${propValue}}`;
1302
1307
  generatedElement += `{(${conditionValue}) &&
1303
1308
  `;
1304
1309
  }
1305
- const [_namespace, shortName] = parseComponentName(instance.component);
1306
- const componentVariable = scope.getName(instance.component, shortName);
1307
- if (instance.children.length === 0) {
1308
- generatedElement += `<${componentVariable}${generatedProps} />
1310
+ if (instance.component === collectionComponent) {
1311
+ if (collectionDataValue === void 0 || collectionItemValue === void 0) {
1312
+ return "";
1313
+ }
1314
+ const indexVariable = scope.getName(`${instance.id}-index`, "index");
1315
+ generatedElement += `{${collectionDataValue}.map((${collectionItemValue}, ${indexVariable}) =>
1309
1316
  `;
1310
- } else {
1311
- generatedElement += `<${componentVariable}${generatedProps}>
1317
+ generatedElement += `<Fragment key={${indexVariable}}>
1312
1318
  `;
1313
1319
  generatedElement += children;
1314
- generatedElement += `</${componentVariable}>
1320
+ generatedElement += `</Fragment>
1321
+ `;
1322
+ generatedElement += `)}
1315
1323
  `;
1324
+ } else {
1325
+ const [_namespace, shortName] = parseComponentName(instance.component);
1326
+ const componentVariable = scope.getName(instance.component, shortName);
1327
+ if (instance.children.length === 0) {
1328
+ generatedElement += `<${componentVariable}${generatedProps} />
1329
+ `;
1330
+ } else {
1331
+ generatedElement += `<${componentVariable}${generatedProps}>
1332
+ `;
1333
+ generatedElement += children;
1334
+ generatedElement += `</${componentVariable}>
1335
+ `;
1336
+ }
1316
1337
  }
1317
1338
  if (conditionValue) {
1318
1339
  generatedElement += `}
@@ -1401,10 +1422,10 @@ var generatePageComponent = ({
1401
1422
  props,
1402
1423
  dataSources,
1403
1424
  indexesWithinAncestors
1404
- }) + "{props.scripts}\n"
1425
+ })
1405
1426
  });
1406
1427
  let generatedComponent = "";
1407
- generatedComponent += `const Page = (props: { scripts?: ReactNode }) => {
1428
+ generatedComponent += `const Page = () => {
1408
1429
  `;
1409
1430
  generatedComponent += `${generatedDataSources}`;
1410
1431
  generatedComponent += `return ${generatedJsx}`;
@@ -1423,6 +1444,7 @@ export {
1423
1444
  WsEmbedTemplate,
1424
1445
  addGlobalRules,
1425
1446
  collapsedAttribute,
1447
+ collectionComponent,
1426
1448
  componentAttribute,
1427
1449
  componentCategories,
1428
1450
  createElementsTree,
@@ -1448,7 +1470,6 @@ export {
1448
1470
  indexAttribute,
1449
1471
  namespaceMeta,
1450
1472
  normalizeProps,
1451
- renderWebstudioComponentChildren,
1452
1473
  selectorIdAttribute,
1453
1474
  showAttribute,
1454
1475
  stateCategories,
@@ -58,6 +58,13 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
58
58
  id: string;
59
59
  instanceId: string;
60
60
  required?: boolean | undefined;
61
+ } | {
62
+ value: string;
63
+ type: "parameter";
64
+ name: string;
65
+ id: string;
66
+ instanceId: string;
67
+ required?: boolean | undefined;
61
68
  } | {
62
69
  value: string;
63
70
  type: "expression";
@@ -102,10 +109,6 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
102
109
  indexesWithinAncestors: IndexesWithinAncestors;
103
110
  children: string;
104
111
  }) => string;
105
- /**
106
- * Jsx element and children are generated separately to be able
107
- * to inject some scripts into Body if necessary
108
- */
109
112
  export declare const generateJsxChildren: ({ scope, children, instances, props, dataSources, indexesWithinAncestors, }: {
110
113
  scope: Scope;
111
114
  children: Instance["children"];
@@ -177,6 +180,13 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
177
180
  id: string;
178
181
  instanceId: string;
179
182
  required?: boolean | undefined;
183
+ } | {
184
+ value: string;
185
+ type: "parameter";
186
+ name: string;
187
+ id: string;
188
+ instanceId: string;
189
+ required?: boolean | undefined;
180
190
  } | {
181
191
  value: string;
182
192
  type: "expression";
@@ -291,6 +301,13 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
291
301
  id: string;
292
302
  instanceId: string;
293
303
  required?: boolean | undefined;
304
+ } | {
305
+ value: string;
306
+ type: "parameter";
307
+ name: string;
308
+ id: string;
309
+ instanceId: string;
310
+ required?: boolean | undefined;
294
311
  } | {
295
312
  value: string;
296
313
  type: "expression";
@@ -325,24 +325,24 @@ declare const WsComponentPropsMeta: z.ZodObject<{
325
325
  label?: string | undefined;
326
326
  description?: string | undefined;
327
327
  }>, z.ZodObject<{
328
- control: z.ZodLiteral<"object">;
329
- type: z.ZodLiteral<"Record<string, string>">;
330
- defaultValue: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
328
+ control: z.ZodLiteral<"json">;
329
+ type: z.ZodLiteral<"json">;
330
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
331
331
  label: z.ZodOptional<z.ZodString>;
332
332
  description: z.ZodOptional<z.ZodString>;
333
333
  required: z.ZodBoolean;
334
334
  }, "strip", z.ZodTypeAny, {
335
- type: "Record<string, string>";
335
+ type: "json";
336
336
  required: boolean;
337
- control: "object";
338
- defaultValue?: Record<string, string> | undefined;
337
+ control: "json";
338
+ defaultValue?: unknown;
339
339
  label?: string | undefined;
340
340
  description?: string | undefined;
341
341
  }, {
342
- type: "Record<string, string>";
342
+ type: "json";
343
343
  required: boolean;
344
- control: "object";
345
- defaultValue?: Record<string, string> | undefined;
344
+ control: "json";
345
+ defaultValue?: unknown;
346
346
  label?: string | undefined;
347
347
  description?: string | undefined;
348
348
  }>, z.ZodObject<{
@@ -498,10 +498,10 @@ declare const WsComponentPropsMeta: z.ZodObject<{
498
498
  label?: string | undefined;
499
499
  description?: string | undefined;
500
500
  } | {
501
- type: "Record<string, string>";
501
+ type: "json";
502
502
  required: boolean;
503
- control: "object";
504
- defaultValue?: Record<string, string> | undefined;
503
+ control: "json";
504
+ defaultValue?: unknown;
505
505
  label?: string | undefined;
506
506
  description?: string | undefined;
507
507
  } | {
@@ -629,10 +629,10 @@ declare const WsComponentPropsMeta: z.ZodObject<{
629
629
  label?: string | undefined;
630
630
  description?: string | undefined;
631
631
  } | {
632
- type: "Record<string, string>";
632
+ type: "json";
633
633
  required: boolean;
634
- control: "object";
635
- defaultValue?: Record<string, string> | undefined;
634
+ control: "json";
635
+ defaultValue?: unknown;
636
636
  label?: string | undefined;
637
637
  description?: string | undefined;
638
638
  } | {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { componentAttribute, idAttribute } from "../tree";
2
+ import { componentAttribute, idAttribute } from "../props";
3
3
  export type AnyComponent = React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
4
4
  [componentAttribute]: string;
5
5
  [idAttribute]: string;
@@ -0,0 +1 @@
1
+ export declare const collectionComponent = "ws:component";
@@ -2260,6 +2260,13 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2260
2260
  id: string;
2261
2261
  instanceId: string;
2262
2262
  required?: boolean | undefined;
2263
+ } | {
2264
+ value: string;
2265
+ type: "parameter";
2266
+ name: string;
2267
+ id: string;
2268
+ instanceId: string;
2269
+ required?: boolean | undefined;
2263
2270
  } | {
2264
2271
  value: string;
2265
2272
  type: "expression";
@@ -95,6 +95,13 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
95
95
  id: string;
96
96
  instanceId: string;
97
97
  required?: boolean | undefined;
98
+ } | {
99
+ value: string;
100
+ type: "parameter";
101
+ name: string;
102
+ id: string;
103
+ instanceId: string;
104
+ required?: boolean | undefined;
98
105
  } | {
99
106
  value: string;
100
107
  type: "expression";
@@ -1,11 +1,12 @@
1
1
  export * from "./css/index";
2
2
  export * from "./tree/index";
3
3
  export * from "./app/index";
4
+ export * from "./core-components";
4
5
  export * from "./components/components-utils";
5
6
  export { PropMeta } from "./prop-meta";
6
7
  export { type WsComponentPropsMeta, type ComponentState, type PresetStyle, WsComponentMeta, componentCategories, stateCategories, defaultStates, } from "./components/component-meta";
7
8
  export * from "./embed-template";
8
- export { normalizeProps, getPropsByInstanceId, getInstanceIdFromComponentProps, getIndexWithinAncestorFromComponentProps, } from "./props";
9
+ export * from "./props";
9
10
  export { type Params, ReactSdkContext } from "./context";
10
11
  export { validateExpression, encodeDataSourceVariable, decodeDataSourceVariable, generateDataSources, } from "./expression";
11
12
  export { getIndexesWithinAncestors } from "./instance-utils";
@@ -330,24 +330,24 @@ export declare const PropMeta: z.ZodUnion<[z.ZodObject<{
330
330
  label?: string | undefined;
331
331
  description?: string | undefined;
332
332
  }>, z.ZodObject<{
333
- control: z.ZodLiteral<"object">;
334
- type: z.ZodLiteral<"Record<string, string>">;
335
- defaultValue: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
333
+ control: z.ZodLiteral<"json">;
334
+ type: z.ZodLiteral<"json">;
335
+ defaultValue: z.ZodOptional<z.ZodUnknown>;
336
336
  label: z.ZodOptional<z.ZodString>;
337
337
  description: z.ZodOptional<z.ZodString>;
338
338
  required: z.ZodBoolean;
339
339
  }, "strip", z.ZodTypeAny, {
340
- type: "Record<string, string>";
340
+ type: "json";
341
341
  required: boolean;
342
- control: "object";
343
- defaultValue?: Record<string, string> | undefined;
342
+ control: "json";
343
+ defaultValue?: unknown;
344
344
  label?: string | undefined;
345
345
  description?: string | undefined;
346
346
  }, {
347
- type: "Record<string, string>";
347
+ type: "json";
348
348
  required: boolean;
349
- control: "object";
350
- defaultValue?: Record<string, string> | undefined;
349
+ control: "json";
350
+ defaultValue?: unknown;
351
351
  label?: string | undefined;
352
352
  description?: string | undefined;
353
353
  }>, z.ZodObject<{
@@ -108,6 +108,13 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
108
108
  id: string;
109
109
  instanceId: string;
110
110
  required?: boolean | undefined;
111
+ } | {
112
+ value: string;
113
+ type: "parameter";
114
+ name: string;
115
+ id: string;
116
+ instanceId: string;
117
+ required?: boolean | undefined;
111
118
  } | {
112
119
  value: string;
113
120
  type: "expression";
@@ -182,6 +189,13 @@ export declare const getPropsByInstanceId: (props: Map<string, {
182
189
  id: string;
183
190
  instanceId: string;
184
191
  required?: boolean | undefined;
192
+ } | {
193
+ value: string;
194
+ type: "parameter";
195
+ name: string;
196
+ id: string;
197
+ instanceId: string;
198
+ required?: boolean | undefined;
185
199
  } | {
186
200
  value: string;
187
201
  type: "expression";
@@ -201,5 +215,11 @@ export declare const getPropsByInstanceId: (props: Map<string, {
201
215
  instanceId: string;
202
216
  required?: boolean | undefined;
203
217
  }>) => PropsByInstanceId;
218
+ export declare const idAttribute: "data-ws-id";
219
+ export declare const selectorIdAttribute: "data-ws-selector";
220
+ export declare const componentAttribute: "data-ws-component";
221
+ export declare const showAttribute: "data-ws-show";
222
+ export declare const indexAttribute: "data-ws-index";
223
+ export declare const collapsedAttribute: "data-ws-collapsed";
204
224
  export declare const getInstanceIdFromComponentProps: (props: Record<string, unknown>) => string;
205
225
  export declare const getIndexWithinAncestorFromComponentProps: (props: Record<string, unknown>) => string | undefined;
@@ -1,10 +1,15 @@
1
- import { type ForwardRefExoticComponent, type RefAttributes, type ReactNode } from "react";
1
+ import { type ForwardRefExoticComponent, type ReactNode, type RefAttributes } from "react";
2
2
  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
- import type { WebstudioComponentProps } from "./webstudio-component";
6
5
  import type { ImageLoader } from "@webstudio-is/image";
7
- export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl, imageLoader, instances, rootInstanceId, Component, components, scripts, }: Params & {
6
+ export type WebstudioComponentProps = {
7
+ instance: Instance;
8
+ instanceSelector: Instance["id"][];
9
+ children: ReactNode;
10
+ components: Components;
11
+ };
12
+ export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl, imageLoader, instances, rootInstanceId, Component, components, }: Params & {
8
13
  instances: Map<string, {
9
14
  type: "instance";
10
15
  id: string;
@@ -22,5 +27,4 @@ export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl
22
27
  rootInstanceId: Instance["id"];
23
28
  Component: ForwardRefExoticComponent<WebstudioComponentProps & RefAttributes<HTMLElement>>;
24
29
  components: Components;
25
- scripts?: ReactNode;
26
30
  }) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,2 +1 @@
1
1
  export * from "./create-elements-tree";
2
- export * from "./webstudio-component";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.118.0",
3
+ "version": "0.119.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -16,8 +16,8 @@
16
16
  "type-fest": "^4.3.1",
17
17
  "typescript": "5.2.2",
18
18
  "zod": "^3.21.4",
19
- "@webstudio-is/tsconfig": "1.0.7",
20
- "@webstudio-is/jest-config": "1.0.7"
19
+ "@webstudio-is/jest-config": "1.0.7",
20
+ "@webstudio-is/tsconfig": "1.0.7"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@remix-run/react": "^1.19.1",
@@ -33,10 +33,10 @@
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.118.0",
37
- "@webstudio-is/fonts": "0.118.0",
38
- "@webstudio-is/image": "0.118.0",
39
- "@webstudio-is/sdk": "0.118.0"
36
+ "@webstudio-is/css-engine": "0.119.0",
37
+ "@webstudio-is/image": "0.119.0",
38
+ "@webstudio-is/fonts": "0.119.0",
39
+ "@webstudio-is/sdk": "0.119.0"
40
40
  },
41
41
  "exports": {
42
42
  ".": {
@@ -1,16 +0,0 @@
1
- /// <reference types="react" />
2
- import type { Instance } from "@webstudio-is/sdk";
3
- import type { Components } from "../components/components-utils";
4
- export declare const renderWebstudioComponentChildren: (children: Array<JSX.Element | string> | undefined) => Array<JSX.Element | string | Array<JSX.Element | string>> | undefined;
5
- export type WebstudioComponentProps = {
6
- instance: Instance;
7
- instanceSelector: Instance["id"][];
8
- children: Array<JSX.Element | string>;
9
- components: Components;
10
- };
11
- export declare const idAttribute: "data-ws-id";
12
- export declare const selectorIdAttribute: "data-ws-selector";
13
- export declare const componentAttribute: "data-ws-component";
14
- export declare const showAttribute: "data-ws-show";
15
- export declare const indexAttribute: "data-ws-index";
16
- export declare const collapsedAttribute: "data-ws-collapsed";