@builder.io/mitosis 0.5.28 → 0.5.29

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.
@@ -277,14 +277,23 @@ function tryFormat(code) {
277
277
  }
278
278
  return str;
279
279
  }
280
+ const processLocalizedValues = (element, node) => {
281
+ if (node.localizedValues) {
282
+ for (const [path, value] of Object.entries(node.localizedValues)) {
283
+ (0, lodash_1.set)(element, path, value);
284
+ }
285
+ }
286
+ return element;
287
+ };
280
288
  const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
281
289
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
282
290
  const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
283
291
  if (mapper) {
284
- return mapper(json, options);
292
+ const element = mapper(json, options);
293
+ return processLocalizedValues(element, json);
285
294
  }
286
295
  if (json.properties._text || ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code)) {
287
- return el({
296
+ const element = el({
288
297
  tagName: 'span',
289
298
  bindings: {
290
299
  ...(((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code)
@@ -302,6 +311,7 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
302
311
  },
303
312
  },
304
313
  }, options);
314
+ return processLocalizedValues(element, json);
305
315
  }
306
316
  const thisIsComponent = (0, is_component_1.isComponent)(json);
307
317
  let bindings = json.bindings;
@@ -381,7 +391,7 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
381
391
  }
382
392
  }
383
393
  }
384
- return el({
394
+ const element = el({
385
395
  tagName: thisIsComponent ? undefined : json.name,
386
396
  ...(hasCss && {
387
397
  responsiveStyles,
@@ -406,6 +416,7 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
406
416
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
407
417
  .map((child) => (0, exports.blockToBuilder)(child, options)),
408
418
  }, options);
419
+ return processLocalizedValues(element, json);
409
420
  };
410
421
  exports.blockToBuilder = blockToBuilder;
411
422
  const componentToBuilder = (options = {}) => ({ component }) => {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Minimal implementation of lodash's _.set
3
+ * https://lodash.com/docs/4.17.15#set
4
+ *
5
+ * See ./set.test.ts for usage examples
6
+ */
7
+ export declare const set: (obj: any, _path: string | string[], value: any) => any;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.set = void 0;
4
+ /**
5
+ * Minimal implementation of lodash's _.set
6
+ * https://lodash.com/docs/4.17.15#set
7
+ *
8
+ * See ./set.test.ts for usage examples
9
+ */
10
+ const set = (obj, _path, value) => {
11
+ if (Object(obj) !== obj) {
12
+ return obj;
13
+ }
14
+ const path = Array.isArray(_path)
15
+ ? _path
16
+ : _path.toString().match(/[^.[\]]+/g);
17
+ path
18
+ .slice(0, -1)
19
+ .reduce((a, c, i) => Object(a[c]) === a[c]
20
+ ? a[c]
21
+ : (a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}), obj)[path[path.length - 1]] = value;
22
+ return obj;
23
+ };
24
+ exports.set = set;
@@ -444,10 +444,11 @@ const componentMappers = {
444
444
  });
445
445
  },
446
446
  Text: (block, options) => {
447
- var _a;
447
+ var _a, _b, _c;
448
448
  let css = getCssFromBlock(block);
449
449
  const styleString = getStyleStringFromBlock(block, options);
450
450
  const actionBindings = getActionBindingsFromBlock(block, options);
451
+ const localizedValues = {};
451
452
  const blockBindings = {
452
453
  ...mapBuilderBindingsToMitosisBindingWithCode(block.bindings),
453
454
  ...mapBuilderBindingsToMitosisBindingWithCode((_a = block.code) === null || _a === void 0 ? void 0 : _a.bindings),
@@ -471,6 +472,15 @@ const componentMappers = {
471
472
  }),
472
473
  };
473
474
  const properties = { ...block.properties };
475
+ for (const key in properties) {
476
+ if (typeof properties[key] === 'object' &&
477
+ properties[key] !== null &&
478
+ properties[key]['@type'] === '@builder.io/core:LocalizedValue') {
479
+ const localizedValue = properties[key];
480
+ localizedValues[`properties.${key}`] = localizedValue;
481
+ properties[key] = localizedValue.Default;
482
+ }
483
+ }
474
484
  if (options.includeBuilderExtras && block.id)
475
485
  properties['builder-id'] = block.id;
476
486
  if (block.class)
@@ -485,7 +495,13 @@ const componentMappers = {
485
495
  code: wrapBindingIfNeeded(componentOptionsText.code, options),
486
496
  });
487
497
  }
488
- const text = block.component.options.text;
498
+ let text = ((_b = block.component.options) === null || _b === void 0 ? void 0 : _b.text) || '';
499
+ if (typeof text === 'object' &&
500
+ text !== null &&
501
+ text['@type'] === '@builder.io/core:LocalizedValue') {
502
+ localizedValues['component.options.text'] = (_c = block.component.options) === null || _c === void 0 ? void 0 : _c.text;
503
+ text = text.Default;
504
+ }
489
505
  // Builder uses {{}} for bindings, but Mitosis expects {} so we need to convert
490
506
  const innerProperties = innerBindings._text
491
507
  ? {}
@@ -498,6 +514,7 @@ const componentMappers = {
498
514
  bindings,
499
515
  properties,
500
516
  meta: (0, exports.getMetaFromBlock)(block, options),
517
+ ...(Object.keys(localizedValues).length && { localizedValues }),
501
518
  children: [
502
519
  (0, create_mitosis_node_1.createMitosisNode)({
503
520
  bindings: innerBindings,
@@ -505,6 +522,7 @@ const componentMappers = {
505
522
  ...innerProperties,
506
523
  class: 'builder-text',
507
524
  },
525
+ ...(Object.keys(localizedValues).length && { localizedValues }),
508
526
  }),
509
527
  ],
510
528
  });
@@ -534,6 +552,7 @@ const componentMappers = {
534
552
  (0, create_mitosis_node_1.createMitosisNode)({
535
553
  bindings: innerBindings,
536
554
  properties: innerProperties,
555
+ ...(Object.keys(localizedValues).length && { localizedValues }),
537
556
  }),
538
557
  ],
539
558
  });
@@ -550,12 +569,14 @@ const componentMappers = {
550
569
  ...innerBindings,
551
570
  },
552
571
  meta: (0, exports.getMetaFromBlock)(block, options),
572
+ ...(Object.keys(localizedValues).length && { localizedValues }),
553
573
  });
554
574
  },
555
575
  };
556
576
  const builderElementToMitosisNode = (block, options, _internalOptions = {}) => {
557
577
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
558
578
  const { includeSpecialBindings = true } = options;
579
+ const localizedValues = {};
559
580
  if (((_a = block.component) === null || _a === void 0 ? void 0 : _a.name) === 'Core:Fragment') {
560
581
  block.component.name = 'Fragment';
561
582
  }
@@ -671,11 +692,27 @@ const builderElementToMitosisNode = (block, options, _internalOptions = {}) => {
671
692
  }),
672
693
  ...(options.includeBuilderExtras && getBuilderPropsForSymbol(block)),
673
694
  };
695
+ for (const key in properties) {
696
+ if (typeof properties[key] === 'object' &&
697
+ properties[key] !== null &&
698
+ properties[key]['@type'] === '@builder.io/core:LocalizedValue') {
699
+ const localizedValue = properties[key];
700
+ localizedValues[`properties.${key}`] = localizedValue;
701
+ properties[key] = localizedValue.Default;
702
+ }
703
+ }
674
704
  if (block.layerName) {
675
705
  properties.$name = block.layerName;
676
706
  }
677
- if (block.linkUrl) {
678
- properties.href = block.linkUrl;
707
+ const linkUrl = block.linkUrl;
708
+ if (linkUrl) {
709
+ if (typeof linkUrl === 'object' && linkUrl['@type'] === '@builder.io/core:LocalizedValue') {
710
+ properties.href = linkUrl.Default;
711
+ localizedValues['linkUrl'] = linkUrl;
712
+ }
713
+ else {
714
+ properties.href = linkUrl;
715
+ }
679
716
  }
680
717
  if ((_o = block.component) === null || _o === void 0 ? void 0 : _o.options) {
681
718
  for (const key in block.component.options) {
@@ -694,6 +731,11 @@ const builderElementToMitosisNode = (block, options, _internalOptions = {}) => {
694
731
  else if (typeof value === 'string') {
695
732
  properties[key] = value;
696
733
  }
734
+ else if (typeof value === 'object' &&
735
+ value['@type'] === '@builder.io/core:LocalizedValue') {
736
+ properties[key] = value.Default;
737
+ localizedValues[`component.options.${key}`] = value;
738
+ }
697
739
  else if (valueIsArrayOfBuilderElements) {
698
740
  const childrenElements = value
699
741
  .filter((item) => {
@@ -748,6 +790,7 @@ const builderElementToMitosisNode = (block, options, _internalOptions = {}) => {
748
790
  ...slots,
749
791
  },
750
792
  meta: (0, exports.getMetaFromBlock)(block, options),
793
+ ...(Object.keys(localizedValues).length && { localizedValues }),
751
794
  });
752
795
  // Has single text node child
753
796
  const firstChild = (_r = block.children) === null || _r === void 0 ? void 0 : _r[0];
@@ -14,6 +14,9 @@ export declare function parseText(node: TemplateNode): {
14
14
  slots?: {
15
15
  [key: string]: import("../../..").MitosisNode[];
16
16
  } | undefined;
17
+ localizedValues?: {
18
+ [index: string]: import("../../..").BuilderLocalizedValue;
19
+ } | undefined;
17
20
  } | {
18
21
  name: string;
19
22
  properties: {
@@ -33,4 +36,7 @@ export declare function parseText(node: TemplateNode): {
33
36
  slots?: {
34
37
  [key: string]: import("../../..").MitosisNode[];
35
38
  } | undefined;
39
+ localizedValues?: {
40
+ [index: string]: import("../../..").BuilderLocalizedValue;
41
+ } | undefined;
36
42
  };
@@ -28,6 +28,11 @@ type BindingProperties = {
28
28
  export type Binding = {
29
29
  code: string;
30
30
  } & BindingProperties;
31
+ export type BuilderLocalizedValue = {
32
+ '@type': '@builder.io/core:LocalizedValue';
33
+ Default: string;
34
+ [index: string]: string;
35
+ };
31
36
  export type BaseNode = {
32
37
  '@type': '@builder.io/mitosis/node';
33
38
  meta: JSONObject;
@@ -68,6 +73,13 @@ export type BaseNode = {
68
73
  slots?: {
69
74
  [key: string]: MitosisNode[];
70
75
  };
76
+ /**
77
+ * Key-value store of localized values
78
+ * It is used when a Builder content block has localized values.
79
+ */
80
+ localizedValues?: {
81
+ [index: string]: BuilderLocalizedValue;
82
+ };
71
83
  };
72
84
  export type SpecialNodesNames = 'For' | 'Fragment' | 'Show' | 'Slot';
73
85
  export type ForNode = BaseNode & {
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.5.28",
25
+ "version": "0.5.29",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {