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