@webstudio-is/react-sdk 0.118.0 → 0.120.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,67 @@ 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);
115
- }
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));
146
- };
147
- var renderWebstudioComponentChildren = (children) => {
148
- if (children === void 0 || children.length === 0) {
149
- return;
75
+ newProps.push(prop);
150
76
  }
151
- return children.map((child) => {
152
- return typeof child === "string" ? renderText(child) : child;
153
- });
77
+ return newProps;
154
78
  };
155
79
  var idAttribute = "data-ws-id";
156
80
  var selectorIdAttribute = "data-ws-selector";
@@ -158,6 +82,12 @@ var componentAttribute = "data-ws-component";
158
82
  var showAttribute = "data-ws-show";
159
83
  var indexAttribute = "data-ws-index";
160
84
  var collapsedAttribute = "data-ws-collapsed";
85
+ var getInstanceIdFromComponentProps = (props) => {
86
+ return props[idAttribute];
87
+ };
88
+ var getIndexWithinAncestorFromComponentProps = (props) => {
89
+ return props[indexAttribute];
90
+ };
161
91
 
162
92
  // src/css/style-rules.ts
163
93
  var getStyleRules = (styles, styleSourceSelections) => {
@@ -279,23 +209,150 @@ var generateCssText = (data, options) => {
279
209
  return engine.cssText;
280
210
  };
281
211
 
212
+ // src/tree/create-elements-tree.tsx
213
+ import {
214
+ Fragment
215
+ } from "react";
216
+
217
+ // src/context.tsx
218
+ import { createContext } from "react";
219
+ var ReactSdkContext = createContext({
220
+ assetBaseUrl: "/",
221
+ imageBaseUrl: "/",
222
+ imageLoader: ({ src }) => src,
223
+ pagesPaths: /* @__PURE__ */ new Set()
224
+ });
225
+
226
+ // src/tree/create-elements-tree.tsx
227
+ import { jsx, jsxs } from "react/jsx-runtime";
228
+ var createElementsTree = ({
229
+ renderer,
230
+ assetBaseUrl,
231
+ imageBaseUrl,
232
+ imageLoader,
233
+ instances,
234
+ rootInstanceId,
235
+ Component,
236
+ components
237
+ }) => {
238
+ const rootInstance = instances.get(rootInstanceId);
239
+ if (rootInstance === void 0) {
240
+ return null;
241
+ }
242
+ const rootInstanceSelector = [rootInstanceId];
243
+ const children = createInstanceChildrenElements({
244
+ instances,
245
+ instanceSelector: rootInstanceSelector,
246
+ Component,
247
+ children: rootInstance.children,
248
+ components
249
+ });
250
+ const root = createInstanceElement({
251
+ Component,
252
+ instance: rootInstance,
253
+ instanceSelector: rootInstanceSelector,
254
+ children,
255
+ components
256
+ });
257
+ return /* @__PURE__ */ jsx(
258
+ ReactSdkContext.Provider,
259
+ {
260
+ value: {
261
+ renderer,
262
+ imageLoader,
263
+ pagesPaths: /* @__PURE__ */ new Set(),
264
+ assetBaseUrl,
265
+ imageBaseUrl
266
+ },
267
+ children: root
268
+ }
269
+ );
270
+ };
271
+ var renderText = (text) => {
272
+ const lines = text.split("\n");
273
+ return lines.map((line, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
274
+ line,
275
+ index < lines.length - 1 && /* @__PURE__ */ jsx("br", {})
276
+ ] }, index));
277
+ };
278
+ var createInstanceChildrenElements = ({
279
+ instances,
280
+ instanceSelector,
281
+ children,
282
+ Component,
283
+ components
284
+ }) => {
285
+ const elements = [];
286
+ for (const child of children) {
287
+ if (child.type === "text") {
288
+ elements.push(renderText(child.value));
289
+ continue;
290
+ }
291
+ const childInstance = instances.get(child.value);
292
+ if (childInstance === void 0) {
293
+ continue;
294
+ }
295
+ const childInstanceSelector = [child.value, ...instanceSelector];
296
+ const children2 = createInstanceChildrenElements({
297
+ instances,
298
+ instanceSelector: childInstanceSelector,
299
+ children: childInstance.children,
300
+ Component,
301
+ components
302
+ });
303
+ const element = createInstanceElement({
304
+ instance: childInstance,
305
+ instanceSelector: childInstanceSelector,
306
+ Component,
307
+ children: children2,
308
+ components
309
+ });
310
+ elements.push(element);
311
+ }
312
+ if (elements.length === 0) {
313
+ return;
314
+ }
315
+ return elements;
316
+ };
317
+ var createInstanceElement = ({
318
+ Component,
319
+ instance,
320
+ instanceSelector,
321
+ children,
322
+ components
323
+ }) => {
324
+ return /* @__PURE__ */ jsx(
325
+ Component,
326
+ {
327
+ instance,
328
+ instanceSelector,
329
+ components,
330
+ children
331
+ },
332
+ instance.id
333
+ );
334
+ };
335
+
282
336
  // src/app/root.tsx
283
337
  import { Links, Meta, Outlet as DefaultOutlet } from "@remix-run/react";
284
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
338
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
285
339
  var Root = ({
286
340
  Outlet = DefaultOutlet
287
341
  }) => {
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, {})
342
+ return /* @__PURE__ */ jsxs2("html", { lang: "en", children: [
343
+ /* @__PURE__ */ jsxs2("head", { children: [
344
+ /* @__PURE__ */ jsx2("meta", { charSet: "utf-8" }),
345
+ /* @__PURE__ */ jsx2("meta", { name: "viewport", content: "width=device-width,initial-scale=1" }),
346
+ /* @__PURE__ */ jsx2(Meta, {}),
347
+ /* @__PURE__ */ jsx2(Links, {})
294
348
  ] }),
295
- /* @__PURE__ */ jsx3(Outlet, {})
349
+ /* @__PURE__ */ jsx2(Outlet, {})
296
350
  ] });
297
351
  };
298
352
 
353
+ // src/core-components.ts
354
+ var collectionComponent = "ws:component";
355
+
299
356
  // src/prop-meta.ts
300
357
  import { z } from "zod";
301
358
  var common = {
@@ -405,13 +462,11 @@ var Url = z.object({
405
462
  type: z.literal("string"),
406
463
  defaultValue: z.string().optional()
407
464
  });
408
- var ObjectType = z.object({
465
+ var Json = z.object({
409
466
  ...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()
467
+ control: z.literal("json"),
468
+ type: z.literal("json"),
469
+ defaultValue: z.unknown().optional()
415
470
  });
416
471
  var Date = z.object({
417
472
  ...common,
@@ -442,7 +497,7 @@ var PropMeta = z.union([
442
497
  InlineCheck,
443
498
  File,
444
499
  Url,
445
- ObjectType,
500
+ Json,
446
501
  Date,
447
502
  Action
448
503
  ]);
@@ -618,11 +673,15 @@ var generateDataSources = ({
618
673
  }
619
674
  }
620
675
  for (const prop of props.values()) {
676
+ if (prop.type === "parameter") {
677
+ output.delete(prop.value);
678
+ variables.delete(prop.value);
679
+ }
621
680
  if (prop.type === "action") {
622
681
  const name = scope.getName(prop.id, prop.name);
623
682
  output.set(prop.id, name);
624
683
  const setters = /* @__PURE__ */ new Set();
625
- let args = void 0;
684
+ let args = [];
626
685
  let newCode = "";
627
686
  for (const value of prop.value) {
628
687
  args = value.args;
@@ -649,9 +708,6 @@ var generateDataSources = ({
649
708
  newCode += `
650
709
  `;
651
710
  }
652
- if (args === void 0) {
653
- continue;
654
- }
655
711
  if (typed) {
656
712
  args = args.map((arg) => `${arg}: any`);
657
713
  }
@@ -1054,87 +1110,6 @@ var WsComponentMeta = z3.object({
1054
1110
  order: z3.number().optional()
1055
1111
  });
1056
1112
 
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
1113
  // src/instance-utils.ts
1139
1114
  var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1140
1115
  const ancestors = /* @__PURE__ */ new Set();
@@ -1237,6 +1212,13 @@ var generatePropValue = ({
1237
1212
  if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
1238
1213
  return JSON.stringify(prop.value);
1239
1214
  }
1215
+ if (prop.type === "parameter") {
1216
+ const dataSource = dataSources.get(prop.value);
1217
+ if (dataSource === void 0) {
1218
+ return;
1219
+ }
1220
+ return scope.getName(dataSource.id, dataSource.name);
1221
+ }
1240
1222
  if (prop.type === "expression") {
1241
1223
  return validateExpression(prop.value, {
1242
1224
  // transpile to safely executable member expressions
@@ -1264,7 +1246,6 @@ var generateJsxElement = ({
1264
1246
  indexesWithinAncestors,
1265
1247
  children
1266
1248
  }) => {
1267
- let conditionValue;
1268
1249
  let generatedProps = "";
1269
1250
  generatedProps += `
1270
1251
  ${idAttribute}=${JSON.stringify(instance.id)}`;
@@ -1277,6 +1258,9 @@ ${componentAttribute}=${JSON.stringify(
1277
1258
  generatedProps += `
1278
1259
  ${indexAttribute}="${index}"`;
1279
1260
  }
1261
+ let conditionValue;
1262
+ let collectionDataValue;
1263
+ let collectionItemValue;
1280
1264
  for (const prop of props.values()) {
1281
1265
  if (prop.instanceId !== instance.id) {
1282
1266
  continue;
@@ -1292,6 +1276,15 @@ ${indexAttribute}="${index}"`;
1292
1276
  conditionValue = propValue;
1293
1277
  continue;
1294
1278
  }
1279
+ if (instance.component === collectionComponent) {
1280
+ if (prop.name === "data") {
1281
+ collectionDataValue = propValue;
1282
+ }
1283
+ if (prop.name === "item") {
1284
+ collectionItemValue = propValue;
1285
+ }
1286
+ continue;
1287
+ }
1295
1288
  if (propValue !== void 0) {
1296
1289
  generatedProps += `
1297
1290
  ${prop.name}={${propValue}}`;
@@ -1302,17 +1295,33 @@ ${prop.name}={${propValue}}`;
1302
1295
  generatedElement += `{(${conditionValue}) &&
1303
1296
  `;
1304
1297
  }
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} />
1298
+ if (instance.component === collectionComponent) {
1299
+ if (collectionDataValue === void 0 || collectionItemValue === void 0) {
1300
+ return "";
1301
+ }
1302
+ const indexVariable = scope.getName(`${instance.id}-index`, "index");
1303
+ generatedElement += `{${collectionDataValue}.map((${collectionItemValue}, ${indexVariable}) =>
1309
1304
  `;
1310
- } else {
1311
- generatedElement += `<${componentVariable}${generatedProps}>
1305
+ generatedElement += `<Fragment key={${indexVariable}}>
1312
1306
  `;
1313
1307
  generatedElement += children;
1314
- generatedElement += `</${componentVariable}>
1308
+ generatedElement += `</Fragment>
1309
+ `;
1310
+ generatedElement += `)}
1315
1311
  `;
1312
+ } else {
1313
+ const [_namespace, shortName] = parseComponentName(instance.component);
1314
+ const componentVariable = scope.getName(instance.component, shortName);
1315
+ if (instance.children.length === 0) {
1316
+ generatedElement += `<${componentVariable}${generatedProps} />
1317
+ `;
1318
+ } else {
1319
+ generatedElement += `<${componentVariable}${generatedProps}>
1320
+ `;
1321
+ generatedElement += children;
1322
+ generatedElement += `</${componentVariable}>
1323
+ `;
1324
+ }
1316
1325
  }
1317
1326
  if (conditionValue) {
1318
1327
  generatedElement += `}
@@ -1401,10 +1410,10 @@ var generatePageComponent = ({
1401
1410
  props,
1402
1411
  dataSources,
1403
1412
  indexesWithinAncestors
1404
- }) + "{props.scripts}\n"
1413
+ })
1405
1414
  });
1406
1415
  let generatedComponent = "";
1407
- generatedComponent += `const Page = (props: { scripts?: ReactNode }) => {
1416
+ generatedComponent += `const Page = () => {
1408
1417
  `;
1409
1418
  generatedComponent += `${generatedDataSources}`;
1410
1419
  generatedComponent += `return ${generatedJsx}`;
@@ -1423,6 +1432,7 @@ export {
1423
1432
  WsEmbedTemplate,
1424
1433
  addGlobalRules,
1425
1434
  collapsedAttribute,
1435
+ collectionComponent,
1426
1436
  componentAttribute,
1427
1437
  componentCategories,
1428
1438
  createElementsTree,
@@ -1442,13 +1452,11 @@ export {
1442
1452
  getIndexesWithinAncestors,
1443
1453
  getInstanceIdFromComponentProps,
1444
1454
  getPresetStyleRules,
1445
- getPropsByInstanceId,
1446
1455
  getStyleRules,
1447
1456
  idAttribute,
1448
1457
  indexAttribute,
1449
1458
  namespaceMeta,
1450
1459
  normalizeProps,
1451
- renderWebstudioComponentChildren,
1452
1460
  selectorIdAttribute,
1453
1461
  showAttribute,
1454
1462
  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<{
@@ -1,5 +1,4 @@
1
- import type { Instance, Page, Prop, Assets } from "@webstudio-is/sdk";
2
- export type PropsByInstanceId = Map<Instance["id"], Prop[]>;
1
+ import type { Page, Prop, Assets } from "@webstudio-is/sdk";
3
2
  export type Pages = Map<Page["id"], Page>;
4
3
  export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
5
4
  props: Prop[];
@@ -110,74 +109,7 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
110
109
  required?: boolean | undefined;
111
110
  } | {
112
111
  value: string;
113
- type: "expression";
114
- name: string;
115
- id: string;
116
- instanceId: string;
117
- required?: boolean | undefined;
118
- } | {
119
- value: {
120
- code: string;
121
- type: "execute";
122
- args: string[];
123
- }[];
124
- type: "action";
125
- name: string;
126
- id: string;
127
- instanceId: string;
128
- required?: boolean | undefined;
129
- })[];
130
- export declare const getPropsByInstanceId: (props: Map<string, {
131
- value: number;
132
- type: "number";
133
- name: string;
134
- id: string;
135
- instanceId: string;
136
- required?: boolean | undefined;
137
- } | {
138
- value: string;
139
- type: "string";
140
- name: string;
141
- id: string;
142
- instanceId: string;
143
- required?: boolean | undefined;
144
- } | {
145
- value: boolean;
146
- type: "boolean";
147
- name: string;
148
- id: string;
149
- instanceId: string;
150
- required?: boolean | undefined;
151
- } | {
152
- type: "json";
153
- name: string;
154
- id: string;
155
- instanceId: string;
156
- value?: unknown;
157
- required?: boolean | undefined;
158
- } | {
159
- value: string;
160
- type: "asset";
161
- name: string;
162
- id: string;
163
- instanceId: string;
164
- required?: boolean | undefined;
165
- } | {
166
- value: (string | {
167
- instanceId: string;
168
- pageId: string;
169
- }) & (string | {
170
- instanceId: string;
171
- pageId: string;
172
- } | undefined);
173
- type: "page";
174
- name: string;
175
- id: string;
176
- instanceId: string;
177
- required?: boolean | undefined;
178
- } | {
179
- value: string[];
180
- type: "string[]";
112
+ type: "parameter";
181
113
  name: string;
182
114
  id: string;
183
115
  instanceId: string;
@@ -200,6 +132,12 @@ export declare const getPropsByInstanceId: (props: Map<string, {
200
132
  id: string;
201
133
  instanceId: string;
202
134
  required?: boolean | undefined;
203
- }>) => PropsByInstanceId;
135
+ })[];
136
+ export declare const idAttribute: "data-ws-id";
137
+ export declare const selectorIdAttribute: "data-ws-selector";
138
+ export declare const componentAttribute: "data-ws-component";
139
+ export declare const showAttribute: "data-ws-show";
140
+ export declare const indexAttribute: "data-ws-index";
141
+ export declare const collapsedAttribute: "data-ws-collapsed";
204
142
  export declare const getInstanceIdFromComponentProps: (props: Record<string, unknown>) => string;
205
143
  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.120.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.120.0",
37
+ "@webstudio-is/fonts": "0.120.0",
38
+ "@webstudio-is/image": "0.120.0",
39
+ "@webstudio-is/sdk": "0.120.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";