@builder.io/sdk 2.2.7 → 2.2.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @builder.io/sdk
2
2
 
3
+ ## 2.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 11e118c: Fix: serialize all functions within registered component info.
8
+
3
9
  ## 2.2.7
4
10
 
5
11
  ### Patch Changes
@@ -152,7 +152,7 @@
152
152
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
153
153
  }
154
154
 
155
- var version = "2.2.7";
155
+ var version = "2.2.8";
156
156
 
157
157
  var Subscription = /** @class */ (function () {
158
158
  function Subscription(listeners, listener) {
@@ -1441,36 +1441,25 @@
1441
1441
  enumerable: false,
1442
1442
  configurable: true
1443
1443
  });
1444
+ Builder.serializeComponentInfo = function (info) {
1445
+ var serializeFn = function (fnValue) {
1446
+ var fnStr = fnValue.toString().trim();
1447
+ // we need to account for a few different fn syntaxes:
1448
+ // 1. `function name(args) => {code}`
1449
+ // 2. `name(args) => {code}`
1450
+ // 3. `(args) => {}`
1451
+ var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
1452
+ return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1453
+ };
1454
+ return JSON.parse(JSON.stringify(info, function (key, value) {
1455
+ if (typeof value === 'function') {
1456
+ return serializeFn(value);
1457
+ }
1458
+ return value;
1459
+ }));
1460
+ };
1444
1461
  Builder.prepareComponentSpecToSend = function (spec) {
1445
- return __assign(__assign(__assign({}, spec), (spec.inputs && {
1446
- inputs: spec.inputs.map(function (input) {
1447
- var _a;
1448
- // TODO: do for nexted fields too
1449
- // TODO: probably just convert all functions, not just
1450
- // TODO: put this in input hooks: { onChange: ..., showIf: ... }
1451
- var keysToConvertFnToString = ['onChange', 'showIf'];
1452
- for (var _i = 0, keysToConvertFnToString_1 = keysToConvertFnToString; _i < keysToConvertFnToString_1.length; _i++) {
1453
- var key = keysToConvertFnToString_1[_i];
1454
- if (input[key] && typeof input[key] === 'function') {
1455
- var fn = input[key];
1456
- input = __assign(__assign({}, input), (_a = {}, _a[key] = "return (".concat(fn.toString(), ").apply(this, arguments)"), _a));
1457
- }
1458
- }
1459
- return input;
1460
- }),
1461
- })), { hooks: Object.keys(spec.hooks || {}).reduce(function (memo, key) {
1462
- var value = spec.hooks && spec.hooks[key];
1463
- if (!value) {
1464
- return memo;
1465
- }
1466
- if (typeof value === 'string') {
1467
- memo[key] = value;
1468
- }
1469
- else {
1470
- memo[key] = "return (".concat(value.toString(), ").apply(this, arguments)");
1471
- }
1472
- return memo;
1473
- }, {}), class: undefined });
1462
+ return __assign(__assign({}, this.serializeComponentInfo(spec)), { class: undefined });
1474
1463
  };
1475
1464
  Builder.registerBlock = function (component, options) {
1476
1465
  this.registerComponent(component, options);