@webstudio-is/react-sdk 0.114.0 → 0.116.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
@@ -460,97 +460,61 @@ import { StyleValue } from "@webstudio-is/css-engine";
460
460
  // src/expression.ts
461
461
  import jsep from "jsep";
462
462
  import jsepAssignment from "@jsep-plugin/assignment";
463
+ import jsepObject from "@jsep-plugin/object";
463
464
  jsep.plugins.register(jsepAssignment);
464
- var generateCode = (node, failOnForbidden, effectful, transformIdentifier) => {
465
+ jsep.plugins.register(jsepObject);
466
+ var generateCode = (node, failOnForbidden, options) => {
465
467
  if (node.type === "Identifier") {
466
- return transformIdentifier(node.name, false);
468
+ return options.transformIdentifier(node.name, false);
467
469
  }
468
470
  if (node.type === "MemberExpression") {
469
- if (failOnForbidden) {
470
- const object2 = generateCode(
471
- node.object,
472
- false,
473
- effectful,
474
- transformIdentifier
475
- );
476
- const property2 = generateCode(
477
- node.property,
478
- false,
479
- effectful,
480
- transformIdentifier
481
- );
482
- throw Error(`Cannot access "${property2}" of "${object2}"`);
471
+ const object = generateCode(node.object, failOnForbidden, options);
472
+ const property = node.property;
473
+ let propertyString;
474
+ if (property.type === "Identifier" && node.computed === false) {
475
+ propertyString = property.name;
476
+ } else {
477
+ propertyString = generateCode(property, failOnForbidden, options);
478
+ }
479
+ if (node.computed) {
480
+ if (options.optional) {
481
+ return `${object}?.[${propertyString}]`;
482
+ } else {
483
+ return `${object}[${propertyString}]`;
484
+ }
485
+ }
486
+ if (options.optional) {
487
+ return `${object}?.${propertyString}`;
488
+ } else {
489
+ return `${object}.${propertyString}`;
483
490
  }
484
- const object = generateCode(
485
- node.object,
486
- failOnForbidden,
487
- effectful,
488
- transformIdentifier
489
- );
490
- const property = generateCode(
491
- node.property,
492
- failOnForbidden,
493
- effectful,
494
- transformIdentifier
495
- );
496
- return `${object}.${property}`;
497
491
  }
498
492
  if (node.type === "Literal") {
499
493
  return node.raw;
500
494
  }
501
495
  if (node.type === "UnaryExpression") {
502
- const arg = generateCode(
503
- node.argument,
504
- failOnForbidden,
505
- effectful,
506
- transformIdentifier
507
- );
496
+ const arg = generateCode(node.argument, failOnForbidden, options);
508
497
  return `${node.operator}${arg}`;
509
498
  }
510
499
  if (node.type === "BinaryExpression") {
511
- const left = generateCode(
512
- node.left,
513
- failOnForbidden,
514
- effectful,
515
- transformIdentifier
516
- );
517
- const right = generateCode(
518
- node.right,
519
- failOnForbidden,
520
- effectful,
521
- transformIdentifier
522
- );
500
+ const left = generateCode(node.left, failOnForbidden, options);
501
+ const right = generateCode(node.right, failOnForbidden, options);
523
502
  return `${left} ${node.operator} ${right}`;
524
503
  }
525
504
  if (node.type === "ArrayExpression") {
526
505
  const elements = node.elements.map(
527
- (element) => generateCode(
528
- element,
529
- failOnForbidden,
530
- effectful,
531
- transformIdentifier
532
- )
506
+ (element) => generateCode(element, failOnForbidden, options)
533
507
  );
534
508
  return `[${elements.join(", ")}]`;
535
509
  }
536
510
  if (node.type === "CallExpression") {
537
511
  if (failOnForbidden) {
538
- const callee2 = generateCode(
539
- node.callee,
540
- false,
541
- effectful,
542
- transformIdentifier
543
- );
512
+ const callee2 = generateCode(node.callee, false, options);
544
513
  throw Error(`Cannot call "${callee2}"`);
545
514
  }
546
- const callee = generateCode(
547
- node.callee,
548
- failOnForbidden,
549
- effectful,
550
- transformIdentifier
551
- );
515
+ const callee = generateCode(node.callee, failOnForbidden, options);
552
516
  const args = node.arguments.map(
553
- (arg) => generateCode(arg, failOnForbidden, effectful, transformIdentifier)
517
+ (arg) => generateCode(arg, failOnForbidden, options)
554
518
  );
555
519
  return `${callee}(${args.join(", ")})`;
556
520
  }
@@ -570,82 +534,55 @@ var generateCode = (node, failOnForbidden, effectful, transformIdentifier) => {
570
534
  if (node.operator !== "=") {
571
535
  throw Error(`Only "=" assignment operator is supported`);
572
536
  }
573
- if (effectful === false) {
537
+ if (options.effectful === false) {
574
538
  throw Error(`Cannot use assignment in this expression`);
575
539
  }
576
- const left = generateCode(
577
- node.left,
578
- failOnForbidden,
579
- effectful,
540
+ const left = generateCode(node.left, failOnForbidden, {
541
+ ...options,
580
542
  // override and mark all identifiers inside of left expression as assignee
581
- (id) => transformIdentifier(id, true)
582
- );
583
- const right = generateCode(
584
- node.right,
585
- failOnForbidden,
586
- effectful,
587
- transformIdentifier
588
- );
543
+ transformIdentifier: (id) => options.transformIdentifier(id, true)
544
+ });
545
+ const right = generateCode(node.right, failOnForbidden, options);
589
546
  return `${left} ${node.operator} ${right}`;
590
547
  }
591
548
  if (node.type === "UpdateExpression") {
592
549
  throw Error(`"${node.operator}" operator is not supported`);
593
550
  }
551
+ if (node.type === "ObjectExpression") {
552
+ const properties = node.properties.map(
553
+ (property) => generateCode(property, failOnForbidden, options)
554
+ );
555
+ return `{${properties.join(", ")}}`;
556
+ }
557
+ if (node.type === "Property") {
558
+ const key = node.key;
559
+ let keyString;
560
+ if (key.type === "Identifier" && node.computed === false) {
561
+ keyString = key.name;
562
+ } else {
563
+ keyString = generateCode(key, failOnForbidden, options);
564
+ }
565
+ const value = generateCode(node.value, failOnForbidden, options);
566
+ if (node.computed) {
567
+ return `[${keyString}]: ${value}`;
568
+ }
569
+ return `${keyString}: ${value}`;
570
+ }
594
571
  node;
595
572
  return "";
596
573
  };
597
574
  var validateExpression = (code, options) => {
598
- const { effectful = false, transformIdentifier = (id) => id } = options ?? {};
575
+ const {
576
+ effectful = false,
577
+ optional = false,
578
+ transformIdentifier = (id) => id
579
+ } = options ?? {};
599
580
  const expression = jsep(code);
600
- return generateCode(expression, true, effectful, transformIdentifier);
601
- };
602
- var sortTopologically = (list, depsById, explored = /* @__PURE__ */ new Set(), sorted = []) => {
603
- for (const id of list) {
604
- if (explored.has(id)) {
605
- continue;
606
- }
607
- explored.add(id);
608
- const deps = depsById.get(id);
609
- if (deps) {
610
- sortTopologically(deps, depsById, explored, sorted);
611
- }
612
- sorted.push(id);
613
- }
614
- return sorted;
615
- };
616
- var computeExpressionDependencies = (expressions, expressionId, dependencies) => {
617
- const depsById = dependencies.get(expressionId);
618
- if (depsById) {
619
- return depsById;
620
- }
621
- const parentDeps = /* @__PURE__ */ new Set();
622
- const code = expressions.get(expressionId);
623
- if (code === void 0) {
624
- return parentDeps;
625
- }
626
- dependencies.set(expressionId, parentDeps);
627
- validateExpression(code, {
628
- transformIdentifier: (id) => {
629
- parentDeps.add(id);
630
- const childDeps = computeExpressionDependencies(
631
- expressions,
632
- id,
633
- dependencies
634
- );
635
- for (const depId of childDeps) {
636
- parentDeps.add(depId);
637
- }
638
- return id;
639
- }
581
+ return generateCode(expression, true, {
582
+ effectful,
583
+ optional,
584
+ transformIdentifier
640
585
  });
641
- return parentDeps;
642
- };
643
- var computeExpressionsDependencies = (expressions) => {
644
- const dependencies = /* @__PURE__ */ new Map();
645
- for (const id of expressions.keys()) {
646
- computeExpressionDependencies(expressions, id, dependencies);
647
- }
648
- return dependencies;
649
586
  };
650
587
  var dataSourceVariablePrefix = "$ws$dataSource$";
651
588
  var encodeDataSourceVariable = (id) => {
@@ -668,102 +605,108 @@ var generateDataSources = ({
668
605
  const variables = /* @__PURE__ */ new Map();
669
606
  let body = "";
670
607
  const output = /* @__PURE__ */ new Map();
671
- const depsById = /* @__PURE__ */ new Map();
672
- const codeById = /* @__PURE__ */ new Map();
673
608
  for (const dataSource of dataSources.values()) {
674
- if (dataSource.type === "expression") {
675
- const deps = /* @__PURE__ */ new Set();
676
- const newCode = validateExpression(dataSource.code, {
609
+ if (dataSource.type === "variable") {
610
+ const valueName = scope.getName(dataSource.id, dataSource.name);
611
+ const setterName = scope.getName(
612
+ `set$${dataSource.id}`,
613
+ `set$${dataSource.name}`
614
+ );
615
+ const initialValue = dataSource.value.value;
616
+ output.set(dataSource.id, valueName);
617
+ variables.set(dataSource.id, { valueName, setterName, initialValue });
618
+ }
619
+ }
620
+ for (const prop of props.values()) {
621
+ if (prop.type === "dataSource") {
622
+ const dataSource = dataSources.get(prop.value);
623
+ if (dataSource?.type !== "expression") {
624
+ continue;
625
+ }
626
+ const name = scope.getName(prop.id, prop.name);
627
+ output.set(prop.id, name);
628
+ const code = validateExpression(dataSource.code, {
629
+ optional: true,
677
630
  transformIdentifier: (identifier) => {
678
631
  const depId = decodeDataSourceVariable(identifier);
679
632
  const dep = depId ? dataSources.get(depId) : void 0;
680
633
  if (dep) {
681
- deps.add(dep.id);
682
634
  return scope.getName(dep.id, dep.name);
683
635
  }
684
636
  console.error(`Unknown dependency "${identifier}"`);
685
637
  return identifier;
686
638
  }
687
639
  });
688
- depsById.set(dataSource.id, deps);
689
- codeById.set(dataSource.id, newCode);
690
- }
691
- }
692
- const sortedDataSources = sortTopologically(
693
- new Set(dataSources.keys()),
694
- depsById
695
- );
696
- for (const dataSourceId of sortedDataSources) {
697
- const dataSource = dataSources.get(dataSourceId);
698
- if (dataSource?.type === "variable") {
699
- const valueName = scope.getName(dataSource.id, dataSource.name);
700
- const setterName = scope.getName(
701
- `set$${dataSource.id}`,
702
- `set$${dataSource.name}`
703
- );
704
- const initialValue = dataSource.value.value;
705
- output.set(dataSource.id, valueName);
706
- variables.set(dataSource.id, { valueName, setterName, initialValue });
707
- }
708
- if (dataSource?.type === "expression") {
709
- const name = scope.getName(dataSource.id, dataSource.name);
710
- const code = codeById.get(dataSourceId);
711
- output.set(dataSource.id, name);
712
640
  body += `let ${name} = (${code});
713
641
  `;
714
642
  }
715
- }
716
- for (const prop of props.values()) {
717
- if (prop.type !== "action") {
718
- continue;
719
- }
720
- const name = scope.getName(prop.id, prop.name);
721
- output.set(prop.id, name);
722
- const setters = /* @__PURE__ */ new Set();
723
- let args = void 0;
724
- let newCode = "";
725
- for (const value of prop.value) {
726
- args = value.args;
727
- newCode += validateExpression(value.code, {
728
- effectful: true,
729
- transformIdentifier: (identifier, assignee) => {
730
- if (args?.includes(identifier)) {
731
- return identifier;
732
- }
643
+ if (prop.type === "expression") {
644
+ const name = scope.getName(prop.id, prop.name);
645
+ output.set(prop.id, name);
646
+ const code = validateExpression(prop.value, {
647
+ transformIdentifier: (identifier) => {
733
648
  const depId = decodeDataSourceVariable(identifier);
734
649
  const dep = depId ? dataSources.get(depId) : void 0;
735
650
  if (dep) {
736
- const name2 = scope.getName(dep.id, dep.name);
737
- if (assignee) {
738
- setters.add(dep.id);
739
- }
740
- return name2;
651
+ return scope.getName(dep.id, dep.name);
741
652
  }
742
653
  console.error(`Unknown dependency "${identifier}"`);
743
654
  return identifier;
744
655
  }
745
656
  });
746
- newCode += `
657
+ body += `let ${name} = (${code});
747
658
  `;
748
659
  }
749
- if (args === void 0) {
750
- continue;
751
- }
752
- if (typed) {
753
- args = args.map((arg) => `${arg}: any`);
754
- }
755
- body += `let ${name} = (${args.join(", ")}) => {
660
+ if (prop.type === "action") {
661
+ const name = scope.getName(prop.id, prop.name);
662
+ output.set(prop.id, name);
663
+ const setters = /* @__PURE__ */ new Set();
664
+ let args = void 0;
665
+ let newCode = "";
666
+ for (const value of prop.value) {
667
+ args = value.args;
668
+ newCode += validateExpression(value.code, {
669
+ optional: true,
670
+ effectful: true,
671
+ transformIdentifier: (identifier, assignee) => {
672
+ if (args?.includes(identifier)) {
673
+ return identifier;
674
+ }
675
+ const depId = decodeDataSourceVariable(identifier);
676
+ const dep = depId ? dataSources.get(depId) : void 0;
677
+ if (dep) {
678
+ const name2 = scope.getName(dep.id, dep.name);
679
+ if (assignee) {
680
+ setters.add(dep.id);
681
+ }
682
+ return name2;
683
+ }
684
+ console.error(`Unknown dependency "${identifier}"`);
685
+ return identifier;
686
+ }
687
+ });
688
+ newCode += `
756
689
  `;
757
- body += newCode;
758
- for (const dataSourceId of setters.values()) {
759
- const variable = variables.get(dataSourceId);
760
- if (variable) {
761
- body += `${variable.setterName}(${variable.valueName})
690
+ }
691
+ if (args === void 0) {
692
+ continue;
693
+ }
694
+ if (typed) {
695
+ args = args.map((arg) => `${arg}: any`);
696
+ }
697
+ body += `let ${name} = (${args.join(", ")}) => {
762
698
  `;
699
+ body += newCode;
700
+ for (const dataSourceId of setters.values()) {
701
+ const variable = variables.get(dataSourceId);
702
+ if (variable) {
703
+ body += `${variable.setterName}(${variable.valueName})
704
+ `;
705
+ }
763
706
  }
764
- }
765
- body += `}
707
+ body += `}
766
708
  `;
709
+ }
767
710
  }
768
711
  return {
769
712
  variables,
@@ -884,26 +827,18 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
884
827
  for (const prop of item.props) {
885
828
  const propId = generateId();
886
829
  if (prop.type === "expression") {
887
- const dataSource = {
830
+ props.push({
831
+ id: propId,
832
+ instanceId,
833
+ name: prop.name,
888
834
  type: "expression",
889
- id: generateId(),
890
- scopeInstanceId: instanceId,
891
- name: "expression",
892
835
  // replace all references with variable names
893
- code: validateExpression(prop.code, {
836
+ value: validateExpression(prop.code, {
894
837
  transformIdentifier: (ref) => {
895
838
  const id = dataSourceByRef.get(ref)?.id ?? ref;
896
839
  return encodeDataSourceVariable(id);
897
840
  }
898
841
  })
899
- };
900
- dataSourceByRef.set(propId, dataSource);
901
- props.push({
902
- id: propId,
903
- instanceId,
904
- type: "dataSource",
905
- name: prop.name,
906
- value: dataSource.id
907
842
  });
908
843
  continue;
909
844
  }
@@ -1365,11 +1300,19 @@ ${indexAttribute}="${index}"`;
1365
1300
  if (dataSource === void 0) {
1366
1301
  continue;
1367
1302
  }
1368
- conditionVariableName = scope.getName(dataSource.id, dataSource.name);
1303
+ if (dataSource.type === "variable") {
1304
+ conditionVariableName = scope.getName(dataSource.id, dataSource.name);
1305
+ }
1306
+ if (dataSource.type === "expression") {
1307
+ conditionVariableName = scope.getName(prop.id, prop.name);
1308
+ }
1309
+ }
1310
+ if (prop.type === "expression") {
1311
+ conditionVariableName = scope.getName(prop.id, prop.name);
1369
1312
  }
1370
1313
  continue;
1371
1314
  }
1372
- if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]") {
1315
+ if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
1373
1316
  generatedProps += `
1374
1317
  ${prop.name}={${JSON.stringify(prop.value)}}`;
1375
1318
  continue;
@@ -1383,9 +1326,25 @@ ${prop.name}={${JSON.stringify(prop.value)}}`;
1383
1326
  if (dataSource === void 0) {
1384
1327
  continue;
1385
1328
  }
1386
- const dataSourceVariable = scope.getName(dataSource.id, dataSource.name);
1387
- generatedProps += `
1329
+ if (dataSource.type === "variable") {
1330
+ const dataSourceVariable = scope.getName(
1331
+ dataSource.id,
1332
+ dataSource.name
1333
+ );
1334
+ generatedProps += `
1335
+ ${prop.name}={${dataSourceVariable}}`;
1336
+ }
1337
+ if (dataSource.type === "expression") {
1338
+ const dataSourceVariable = scope.getName(prop.id, prop.name);
1339
+ generatedProps += `
1388
1340
  ${prop.name}={${dataSourceVariable}}`;
1341
+ }
1342
+ continue;
1343
+ }
1344
+ if (prop.type === "expression") {
1345
+ const propVariable = scope.getName(prop.id, prop.name);
1346
+ generatedProps += `
1347
+ ${prop.name}={${propVariable}}`;
1389
1348
  continue;
1390
1349
  }
1391
1350
  if (prop.type === "action") {
@@ -1524,7 +1483,6 @@ export {
1524
1483
  collapsedAttribute,
1525
1484
  componentAttribute,
1526
1485
  componentCategories,
1527
- computeExpressionsDependencies,
1528
1486
  createElementsTree,
1529
1487
  createImageValueTransformer,
1530
1488
  decodeDataSourceVariable,
@@ -24,6 +24,13 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
24
24
  id: string;
25
25
  instanceId: string;
26
26
  required?: boolean | undefined;
27
+ } | {
28
+ type: "json";
29
+ name: string;
30
+ id: string;
31
+ instanceId: string;
32
+ value?: unknown;
33
+ required?: boolean | undefined;
27
34
  } | {
28
35
  value: string;
29
36
  type: "asset";
@@ -58,6 +65,13 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
58
65
  id: string;
59
66
  instanceId: string;
60
67
  required?: boolean | undefined;
68
+ } | {
69
+ value: string;
70
+ type: "expression";
71
+ name: string;
72
+ id: string;
73
+ instanceId: string;
74
+ required?: boolean | undefined;
61
75
  } | {
62
76
  value: {
63
77
  code: string;
@@ -83,6 +97,9 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
83
97
  } | {
84
98
  value: string[];
85
99
  type: "string[]";
100
+ } | {
101
+ type: "json";
102
+ value?: unknown;
86
103
  };
87
104
  type: "variable";
88
105
  name: string;
@@ -139,6 +156,13 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
139
156
  id: string;
140
157
  instanceId: string;
141
158
  required?: boolean | undefined;
159
+ } | {
160
+ type: "json";
161
+ name: string;
162
+ id: string;
163
+ instanceId: string;
164
+ value?: unknown;
165
+ required?: boolean | undefined;
142
166
  } | {
143
167
  value: string;
144
168
  type: "asset";
@@ -173,6 +197,13 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
173
197
  id: string;
174
198
  instanceId: string;
175
199
  required?: boolean | undefined;
200
+ } | {
201
+ value: string;
202
+ type: "expression";
203
+ name: string;
204
+ id: string;
205
+ instanceId: string;
206
+ required?: boolean | undefined;
176
207
  } | {
177
208
  value: {
178
209
  code: string;
@@ -198,6 +229,9 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
198
229
  } | {
199
230
  value: string[];
200
231
  type: "string[]";
232
+ } | {
233
+ type: "json";
234
+ value?: unknown;
201
235
  };
202
236
  type: "variable";
203
237
  name: string;
@@ -249,6 +283,13 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
249
283
  id: string;
250
284
  instanceId: string;
251
285
  required?: boolean | undefined;
286
+ } | {
287
+ type: "json";
288
+ name: string;
289
+ id: string;
290
+ instanceId: string;
291
+ value?: unknown;
292
+ required?: boolean | undefined;
252
293
  } | {
253
294
  value: string;
254
295
  type: "asset";
@@ -283,6 +324,13 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
283
324
  id: string;
284
325
  instanceId: string;
285
326
  required?: boolean | undefined;
327
+ } | {
328
+ value: string;
329
+ type: "expression";
330
+ name: string;
331
+ id: string;
332
+ instanceId: string;
333
+ required?: boolean | undefined;
286
334
  } | {
287
335
  value: {
288
336
  code: string;
@@ -308,6 +356,9 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
308
356
  } | {
309
357
  value: string[];
310
358
  type: "string[]";
359
+ } | {
360
+ type: "json";
361
+ value?: unknown;
311
362
  };
312
363
  type: "variable";
313
364
  name: string;
@@ -2226,6 +2226,13 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2226
2226
  id: string;
2227
2227
  instanceId: string;
2228
2228
  required?: boolean | undefined;
2229
+ } | {
2230
+ type: "json";
2231
+ name: string;
2232
+ id: string;
2233
+ instanceId: string;
2234
+ value?: unknown;
2235
+ required?: boolean | undefined;
2229
2236
  } | {
2230
2237
  value: string;
2231
2238
  type: "asset";
@@ -2260,6 +2267,13 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2260
2267
  id: string;
2261
2268
  instanceId: string;
2262
2269
  required?: boolean | undefined;
2270
+ } | {
2271
+ value: string;
2272
+ type: "expression";
2273
+ name: string;
2274
+ id: string;
2275
+ instanceId: string;
2276
+ required?: boolean | undefined;
2263
2277
  } | {
2264
2278
  value: {
2265
2279
  code: string;
@@ -2285,6 +2299,9 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2285
2299
  } | {
2286
2300
  value: string[];
2287
2301
  type: "string[]";
2302
+ } | {
2303
+ type: "json";
2304
+ value?: unknown;
2288
2305
  };
2289
2306
  type: "variable";
2290
2307
  name: string;
@@ -1,10 +1,17 @@
1
1
  import type { DataSources, Props, Scope } from "@webstudio-is/sdk";
2
2
  type TransformIdentifier = (id: string, assignee: boolean) => string;
3
3
  export declare const validateExpression: (code: string, options?: {
4
+ /**
5
+ * Enable assignment operator for actions
6
+ */
4
7
  effectful?: boolean;
8
+ /**
9
+ * Add optional chaining to access nested properties safely
10
+ * and without checks even when not exist
11
+ */
12
+ optional?: boolean;
5
13
  transformIdentifier?: TransformIdentifier;
6
14
  }) => string;
7
- export declare const computeExpressionsDependencies: (expressions: Map<string, string>) => Map<string, Set<string>>;
8
15
  export declare const encodeDataSourceVariable: (id: string) => string;
9
16
  export declare const decodeDataSourceVariable: (name: string) => string | undefined;
10
17
  type VariableName = string;
@@ -24,6 +31,9 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
24
31
  } | {
25
32
  value: string[];
26
33
  type: "string[]";
34
+ } | {
35
+ type: "json";
36
+ value?: unknown;
27
37
  };
28
38
  type: "variable";
29
39
  name: string;
@@ -57,6 +67,13 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
57
67
  id: string;
58
68
  instanceId: string;
59
69
  required?: boolean | undefined;
70
+ } | {
71
+ type: "json";
72
+ name: string;
73
+ id: string;
74
+ instanceId: string;
75
+ value?: unknown;
76
+ required?: boolean | undefined;
60
77
  } | {
61
78
  value: string;
62
79
  type: "asset";
@@ -91,6 +108,13 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
91
108
  id: string;
92
109
  instanceId: string;
93
110
  required?: boolean | undefined;
111
+ } | {
112
+ value: string;
113
+ type: "expression";
114
+ name: string;
115
+ id: string;
116
+ instanceId: string;
117
+ required?: boolean | undefined;
94
118
  } | {
95
119
  value: {
96
120
  code: string;
@@ -7,7 +7,7 @@ export { type WsComponentPropsMeta, type ComponentState, type PresetStyle, WsCom
7
7
  export * from "./embed-template";
8
8
  export { normalizeProps, getPropsByInstanceId, getInstanceIdFromComponentProps, getIndexWithinAncestorFromComponentProps, } from "./props";
9
9
  export { type Params, ReactSdkContext } from "./context";
10
- export { validateExpression, computeExpressionsDependencies, encodeDataSourceVariable, decodeDataSourceVariable, generateDataSources, } from "./expression";
10
+ export { validateExpression, encodeDataSourceVariable, decodeDataSourceVariable, generateDataSources, } from "./expression";
11
11
  export { getIndexesWithinAncestors } from "./instance-utils";
12
12
  export * from "./hook";
13
13
  export { generateUtilsExport } from "./generator";
@@ -74,6 +74,13 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
74
74
  id: string;
75
75
  instanceId: string;
76
76
  required?: boolean | undefined;
77
+ } | {
78
+ type: "json";
79
+ name: string;
80
+ id: string;
81
+ instanceId: string;
82
+ value?: unknown;
83
+ required?: boolean | undefined;
77
84
  } | {
78
85
  value: string;
79
86
  type: "asset";
@@ -108,6 +115,13 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
108
115
  id: string;
109
116
  instanceId: string;
110
117
  required?: boolean | undefined;
118
+ } | {
119
+ value: string;
120
+ type: "expression";
121
+ name: string;
122
+ id: string;
123
+ instanceId: string;
124
+ required?: boolean | undefined;
111
125
  } | {
112
126
  value: {
113
127
  code: string;
@@ -141,6 +155,13 @@ export declare const getPropsByInstanceId: (props: Map<string, {
141
155
  id: string;
142
156
  instanceId: string;
143
157
  required?: boolean | undefined;
158
+ } | {
159
+ type: "json";
160
+ name: string;
161
+ id: string;
162
+ instanceId: string;
163
+ value?: unknown;
164
+ required?: boolean | undefined;
144
165
  } | {
145
166
  value: string;
146
167
  type: "asset";
@@ -175,6 +196,13 @@ export declare const getPropsByInstanceId: (props: Map<string, {
175
196
  id: string;
176
197
  instanceId: string;
177
198
  required?: boolean | undefined;
199
+ } | {
200
+ value: string;
201
+ type: "expression";
202
+ name: string;
203
+ id: string;
204
+ instanceId: string;
205
+ required?: boolean | undefined;
178
206
  } | {
179
207
  value: {
180
208
  code: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.114.0",
3
+ "version": "0.116.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -27,15 +27,16 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@jsep-plugin/assignment": "^1.2.1",
30
+ "@jsep-plugin/object": "^1.2.1",
30
31
  "change-case": "^5.0.2",
31
32
  "html-tags": "^3.3.1",
32
33
  "jsep": "^1.3.8",
33
34
  "nanoid": "^5.0.1",
34
35
  "title-case": "^4.1.0",
35
- "@webstudio-is/css-engine": "0.114.0",
36
- "@webstudio-is/fonts": "0.114.0",
37
- "@webstudio-is/image": "0.114.0",
38
- "@webstudio-is/sdk": "0.114.0"
36
+ "@webstudio-is/css-engine": "0.116.0",
37
+ "@webstudio-is/fonts": "0.116.0",
38
+ "@webstudio-is/image": "0.116.0",
39
+ "@webstudio-is/sdk": "0.116.0"
39
40
  },
40
41
  "exports": {
41
42
  ".": {