@builder.io/mitosis 0.4.5 → 0.4.6
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.
|
@@ -72,6 +72,59 @@ const componentMappers = {
|
|
|
72
72
|
block.children = [];
|
|
73
73
|
return block;
|
|
74
74
|
},
|
|
75
|
+
PersonalizationContainer(node, options) {
|
|
76
|
+
const block = (0, exports.blockToBuilder)(node, options, { skipMapper: true });
|
|
77
|
+
// console.log('block', node);
|
|
78
|
+
const variants = [];
|
|
79
|
+
let defaultVariant = [];
|
|
80
|
+
const validFakeNodeNames = [
|
|
81
|
+
'Variant',
|
|
82
|
+
'PersonalizationOption',
|
|
83
|
+
'PersonalizationVariant',
|
|
84
|
+
'Personalization',
|
|
85
|
+
];
|
|
86
|
+
block.children.forEach((item) => {
|
|
87
|
+
var _a;
|
|
88
|
+
console.log('item', item);
|
|
89
|
+
if (item.component && validFakeNodeNames.includes((_a = item.component) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
90
|
+
let query;
|
|
91
|
+
if (item.component.options.query) {
|
|
92
|
+
const optionsQuery = item.component.options.query;
|
|
93
|
+
if (Array.isArray(optionsQuery)) {
|
|
94
|
+
query = optionsQuery.map((q) => ({
|
|
95
|
+
'@type': '@builder.io/core:Query',
|
|
96
|
+
...q,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
query = [
|
|
101
|
+
{
|
|
102
|
+
'@type': '@builder.io/core:Query',
|
|
103
|
+
...optionsQuery,
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
const newVariant = {
|
|
108
|
+
...item.component.options,
|
|
109
|
+
query,
|
|
110
|
+
blocks: item.children,
|
|
111
|
+
};
|
|
112
|
+
variants.push(newVariant);
|
|
113
|
+
}
|
|
114
|
+
else if (item.children) {
|
|
115
|
+
defaultVariant.push(...item.children);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
defaultVariant.push(item);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
delete block.properties;
|
|
123
|
+
delete block.bindings;
|
|
124
|
+
block.component.options.variants = variants;
|
|
125
|
+
block.children = defaultVariant;
|
|
126
|
+
return block;
|
|
127
|
+
},
|
|
75
128
|
For(_node, options) {
|
|
76
129
|
var _a;
|
|
77
130
|
// rename `index` var to `state.$index`
|
|
@@ -272,7 +325,7 @@ const componentToBuilder = (options = {}) => ({ component }) => {
|
|
|
272
325
|
${!(0, has_props_1.hasProps)(component) ? '' : `var props = state;`}
|
|
273
326
|
|
|
274
327
|
${!hasState ? '' : `Object.assign(state, ${(0, get_state_object_string_1.getStateObjectStringFromComponent)(component)});`}
|
|
275
|
-
|
|
328
|
+
|
|
276
329
|
${(0, on_mount_1.stringifySingleScopeOnMount)(component)}
|
|
277
330
|
`),
|
|
278
331
|
tsCode: tryFormat((0, dedent_1.dedent) `
|
|
@@ -335,6 +335,50 @@ const componentMappers = {
|
|
|
335
335
|
})) || [];
|
|
336
336
|
return node;
|
|
337
337
|
},
|
|
338
|
+
PersonalizationContainer(block, options) {
|
|
339
|
+
var _a, _b;
|
|
340
|
+
const node = (0, exports.builderElementToMitosisNode)(block, options, {
|
|
341
|
+
skipMapper: true,
|
|
342
|
+
});
|
|
343
|
+
delete node.bindings.variants;
|
|
344
|
+
delete node.properties.variants;
|
|
345
|
+
const newChildren = ((_b = (_a = block.component) === null || _a === void 0 ? void 0 : _a.options.variants) === null || _b === void 0 ? void 0 : _b.map((variant) => {
|
|
346
|
+
const variantNode = (0, create_mitosis_node_1.createMitosisNode)({
|
|
347
|
+
name: 'Variant',
|
|
348
|
+
properties: {
|
|
349
|
+
name: variant.name,
|
|
350
|
+
startDate: variant.startDate,
|
|
351
|
+
endDate: variant.endDate,
|
|
352
|
+
},
|
|
353
|
+
meta: (0, exports.getMetaFromBlock)(block, options),
|
|
354
|
+
children: variant.blocks.map((col) => (0, exports.builderElementToMitosisNode)(col, options)),
|
|
355
|
+
});
|
|
356
|
+
const queryOptions = variant.query;
|
|
357
|
+
if (Array.isArray(queryOptions)) {
|
|
358
|
+
variantNode.bindings.query = {
|
|
359
|
+
type: 'single',
|
|
360
|
+
code: JSON.stringify(queryOptions.map((q) => (0, lodash_1.omit)(q, '@type'))),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
else if (queryOptions) {
|
|
364
|
+
variantNode.bindings.query = {
|
|
365
|
+
type: 'single',
|
|
366
|
+
code: JSON.stringify((0, lodash_1.omit)(queryOptions, '@type')),
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
return variantNode;
|
|
370
|
+
})) || [];
|
|
371
|
+
const defaultVariant = (0, create_mitosis_node_1.createMitosisNode)({
|
|
372
|
+
name: 'Variant',
|
|
373
|
+
properties: {
|
|
374
|
+
default: '',
|
|
375
|
+
},
|
|
376
|
+
children: node.children,
|
|
377
|
+
});
|
|
378
|
+
newChildren.push(defaultVariant);
|
|
379
|
+
node.children = newChildren;
|
|
380
|
+
return node;
|
|
381
|
+
},
|
|
338
382
|
'Shopify:For': (block, options) => {
|
|
339
383
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
340
384
|
name: 'For',
|
|
@@ -50,10 +50,12 @@ const getForArguments = (params) => {
|
|
|
50
50
|
* Parses a JSX element into a MitosisNode.
|
|
51
51
|
*/
|
|
52
52
|
const jsxElementToJson = (node) => {
|
|
53
|
+
var _a;
|
|
53
54
|
if (types.isJSXText(node)) {
|
|
55
|
+
const value = typeof ((_a = node.extra) === null || _a === void 0 ? void 0 : _a.raw) === 'string' ? node.extra.raw : node.value;
|
|
54
56
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
55
57
|
properties: {
|
|
56
|
-
_text:
|
|
58
|
+
_text: value,
|
|
57
59
|
},
|
|
58
60
|
});
|
|
59
61
|
}
|