@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/dist/index.cjs.js CHANGED
@@ -126,7 +126,7 @@ function assertAllowedPropertyName(name) {
126
126
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
127
127
  }
128
128
 
129
- var version = "2.2.7";
129
+ var version = "2.2.8";
130
130
 
131
131
  var Subscription = /** @class */ (function () {
132
132
  function Subscription(listeners, listener) {
@@ -1347,36 +1347,25 @@ var Builder = /** @class */ (function () {
1347
1347
  enumerable: false,
1348
1348
  configurable: true
1349
1349
  });
1350
+ Builder.serializeComponentInfo = function (info) {
1351
+ var serializeFn = function (fnValue) {
1352
+ var fnStr = fnValue.toString().trim();
1353
+ // we need to account for a few different fn syntaxes:
1354
+ // 1. `function name(args) => {code}`
1355
+ // 2. `name(args) => {code}`
1356
+ // 3. `(args) => {}`
1357
+ var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
1358
+ return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
1359
+ };
1360
+ return JSON.parse(JSON.stringify(info, function (key, value) {
1361
+ if (typeof value === 'function') {
1362
+ return serializeFn(value);
1363
+ }
1364
+ return value;
1365
+ }));
1366
+ };
1350
1367
  Builder.prepareComponentSpecToSend = function (spec) {
1351
- return tslib.__assign(tslib.__assign(tslib.__assign({}, spec), (spec.inputs && {
1352
- inputs: spec.inputs.map(function (input) {
1353
- var _a;
1354
- // TODO: do for nexted fields too
1355
- // TODO: probably just convert all functions, not just
1356
- // TODO: put this in input hooks: { onChange: ..., showIf: ... }
1357
- var keysToConvertFnToString = ['onChange', 'showIf'];
1358
- for (var _i = 0, keysToConvertFnToString_1 = keysToConvertFnToString; _i < keysToConvertFnToString_1.length; _i++) {
1359
- var key = keysToConvertFnToString_1[_i];
1360
- if (input[key] && typeof input[key] === 'function') {
1361
- var fn = input[key];
1362
- input = tslib.__assign(tslib.__assign({}, input), (_a = {}, _a[key] = "return (".concat(fn.toString(), ").apply(this, arguments)"), _a));
1363
- }
1364
- }
1365
- return input;
1366
- }),
1367
- })), { hooks: Object.keys(spec.hooks || {}).reduce(function (memo, key) {
1368
- var value = spec.hooks && spec.hooks[key];
1369
- if (!value) {
1370
- return memo;
1371
- }
1372
- if (typeof value === 'string') {
1373
- memo[key] = value;
1374
- }
1375
- else {
1376
- memo[key] = "return (".concat(value.toString(), ").apply(this, arguments)");
1377
- }
1378
- return memo;
1379
- }, {}), class: undefined });
1368
+ return tslib.__assign(tslib.__assign({}, this.serializeComponentInfo(spec)), { class: undefined });
1380
1369
  };
1381
1370
  Builder.registerBlock = function (component, options) {
1382
1371
  this.registerComponent(component, options);