@builder.io/mitosis 0.0.56-28 → 0.0.56-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.
- package/dist/src/__tests__/hash-code.test.js +3 -0
- package/dist/src/generators/builder.js +2 -1
- package/dist/src/generators/qwik/component.js +24 -6
- package/dist/src/generators/qwik/directives.js +1 -1
- package/dist/src/generators/qwik/handlers.js +4 -1
- package/dist/src/generators/qwik/jsx.js +11 -7
- package/dist/src/helpers/render-imports.js +4 -1
- package/dist/src/helpers/render-imports.test.js +14 -0
- package/dist/src/parsers/builder.js +41 -21
- package/dist/src/symbols/symbol-processor.js +2 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -5,4 +5,7 @@ describe('hashCode', function () {
|
|
|
5
5
|
test('should compute object', function () {
|
|
6
6
|
expect((0, __1.hashCodeAsString)({ foo: 'bar' })).toEqual('1jo4fm');
|
|
7
7
|
});
|
|
8
|
+
test('order of properties should not matter', function () {
|
|
9
|
+
expect((0, __1.hashCodeAsString)({ a: 'first', b: 'second' })).toEqual((0, __1.hashCodeAsString)({ b: 'second', a: 'first' }));
|
|
10
|
+
});
|
|
8
11
|
});
|
|
@@ -33,6 +33,7 @@ var lodash_1 = require("lodash");
|
|
|
33
33
|
var builder_1 = require("../parsers/builder");
|
|
34
34
|
var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
|
|
35
35
|
var traverse_1 = __importDefault(require("traverse"));
|
|
36
|
+
var symbol_processor_1 = require("../symbols/symbol-processor");
|
|
36
37
|
var omitMetaProperties = function (obj) {
|
|
37
38
|
return (0, lodash_1.omitBy)(obj, function (_value, key) { return key.startsWith('$'); });
|
|
38
39
|
};
|
|
@@ -109,7 +110,7 @@ var componentMappers = __assign(__assign({}, (!builder_1.symbolBlocksAsChildren
|
|
|
109
110
|
}, options);
|
|
110
111
|
} });
|
|
111
112
|
var el = function (options, toBuilderOptions) { return (__assign(__assign({ '@type': '@builder.io/sdk:Element' }, (toBuilderOptions.includeIds && {
|
|
112
|
-
id: 'builder-' +
|
|
113
|
+
id: 'builder-' + (0, symbol_processor_1.hashCodeAsString)(options),
|
|
113
114
|
})), options)); };
|
|
114
115
|
function tryFormat(code) {
|
|
115
116
|
var str = code;
|
|
@@ -56,7 +56,9 @@ function getCommonStyles(fileSet) {
|
|
|
56
56
|
function addComponent(fileSet, component, opts) {
|
|
57
57
|
if (opts === void 0) { opts = {}; }
|
|
58
58
|
var _opts = __assign({ isRoot: false, shareStyles: false, hostProps: null }, opts);
|
|
59
|
-
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, __assign(__assign({}, compile_away_builder_components_1.components), {
|
|
59
|
+
(0, compile_away_builder_components_1.compileAwayBuilderComponentsFromTree)(component, __assign(__assign({}, compile_away_builder_components_1.components), {
|
|
60
|
+
// A set of components that should not be compiled away because they are implemented as runtime components.
|
|
61
|
+
Image: undefined, CoreButton: undefined }));
|
|
60
62
|
addBuilderBlockClass(component.children);
|
|
61
63
|
var componentName = component.name;
|
|
62
64
|
var handlers = (0, handlers_1.renderHandlers)(fileSet.high, componentName, component.children);
|
|
@@ -141,17 +143,33 @@ function addComponentOnMount(componentFile, onRenderEmit, componentName, compone
|
|
|
141
143
|
}
|
|
142
144
|
componentFile.exportConst(componentName + '_onMount', function () {
|
|
143
145
|
var _this = this;
|
|
144
|
-
this.emit((0, src_generator_1.arrowFnValue)(['
|
|
145
|
-
var _a
|
|
146
|
-
return _this.emit.apply(_this, __spreadArray(__spreadArray(
|
|
147
|
-
'
|
|
148
|
-
|
|
146
|
+
this.emit((0, src_generator_1.arrowFnValue)(['props'], function () {
|
|
147
|
+
var _a;
|
|
148
|
+
return _this.emit.apply(_this, __spreadArray(__spreadArray(['{',
|
|
149
|
+
'const state=',
|
|
150
|
+
componentFile.import(componentFile.qwikModule, 'useStore').localName,
|
|
151
|
+
'(()=>{',
|
|
152
|
+
'const state = Object.assign({},props,typeof __STATE__==="object"?__STATE__[props.serverStateId]:undefined);'], inputInitializer, false), [inlineCode((_a = component.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code),
|
|
153
|
+
'return state;',
|
|
154
|
+
'});',
|
|
149
155
|
useStyles,
|
|
150
156
|
onRenderEmit,
|
|
151
157
|
';}'], false));
|
|
152
158
|
}));
|
|
153
159
|
});
|
|
154
160
|
}
|
|
161
|
+
function inlineCode(code) {
|
|
162
|
+
return function () {
|
|
163
|
+
if (code) {
|
|
164
|
+
// HACK: remove the return value as it is not the state we are creating.
|
|
165
|
+
code = code
|
|
166
|
+
.trim()
|
|
167
|
+
.replace(/return main\(\);?$/, '')
|
|
168
|
+
.trim();
|
|
169
|
+
this.emit(code, ';');
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
155
173
|
function generateQrl(fromFile, dstFile, componentName, capture) {
|
|
156
174
|
if (capture === void 0) { capture = []; }
|
|
157
175
|
return (0, src_generator_1.invoke)(fromFile.import(fromFile.qwikModule, 'qrl'), [
|
|
@@ -110,7 +110,7 @@ exports.Image = Image;
|
|
|
110
110
|
function __passThroughProps__(dstProps, srcProps) {
|
|
111
111
|
for (var key in srcProps) {
|
|
112
112
|
if (Object.prototype.hasOwnProperty.call(srcProps, key) &&
|
|
113
|
-
((key.startsWith('on') && key.endsWith('
|
|
113
|
+
((key.startsWith('on') && key.endsWith('$')) || key == 'style')) {
|
|
114
114
|
dstProps[key] = srcProps[key];
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -40,7 +40,7 @@ function renderHandlers(file, componentName, children) {
|
|
|
40
40
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
41
41
|
var binding = bindings[key].code;
|
|
42
42
|
if (binding != null) {
|
|
43
|
-
if (key
|
|
43
|
+
if (isEventName(key)) {
|
|
44
44
|
var block = extractJSBlock(binding) || binding;
|
|
45
45
|
var symbol = "".concat(componentName, "_").concat(key, "_").concat(id++);
|
|
46
46
|
map.set(binding, symbol);
|
|
@@ -67,3 +67,6 @@ function renderHandler(file, symbol, code) {
|
|
|
67
67
|
function stripBlock(block) {
|
|
68
68
|
return block.substring(1, block.length - 1).trim();
|
|
69
69
|
}
|
|
70
|
+
function isEventName(name) {
|
|
71
|
+
return name.startsWith('on') && name.charAt(2).toUpperCase() == name.charAt(2);
|
|
72
|
+
}
|
|
@@ -162,27 +162,31 @@ function isTextNode(child) {
|
|
|
162
162
|
* @returns
|
|
163
163
|
*/
|
|
164
164
|
function rewriteHandlers(file, handlers, bindings, symbolBindings) {
|
|
165
|
+
var _a;
|
|
165
166
|
var outBindings = {};
|
|
166
167
|
for (var key in bindings) {
|
|
167
168
|
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
168
|
-
var
|
|
169
|
+
var bindingExpr = (_a = bindings === null || bindings === void 0 ? void 0 : bindings[key]) === null || _a === void 0 ? void 0 : _a.code;
|
|
169
170
|
var handlerBlock = void 0;
|
|
170
|
-
if (
|
|
171
|
+
if (bindingExpr != null) {
|
|
171
172
|
if (key == 'css') {
|
|
172
173
|
continue;
|
|
173
174
|
}
|
|
174
|
-
else if ((handlerBlock = handlers.get(
|
|
175
|
-
key = "".concat(key, "
|
|
176
|
-
|
|
175
|
+
else if ((handlerBlock = handlers.get(bindingExpr))) {
|
|
176
|
+
key = "".concat(key, "$");
|
|
177
|
+
bindingExpr = (0, src_generator_1.invoke)(file.import(file.qwikModule, 'qrl'), [
|
|
177
178
|
(0, src_generator_1.quote)(file.qrlPrefix + 'high.js'),
|
|
178
179
|
(0, src_generator_1.quote)(handlerBlock),
|
|
179
180
|
'[state]',
|
|
180
181
|
]);
|
|
181
182
|
}
|
|
182
183
|
else if (symbolBindings && key.startsWith('symbol.data.')) {
|
|
183
|
-
symbolBindings[(0, src_generator_1.lastProperty)(key)] =
|
|
184
|
+
symbolBindings[(0, src_generator_1.lastProperty)(key)] = bindingExpr;
|
|
185
|
+
}
|
|
186
|
+
else if (key.startsWith('component.options.')) {
|
|
187
|
+
key = (0, src_generator_1.lastProperty)(key);
|
|
184
188
|
}
|
|
185
|
-
outBindings[key] = { code:
|
|
189
|
+
outBindings[key] = { code: bindingExpr };
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
}
|
|
@@ -102,7 +102,7 @@ var renderImport = function (_a) {
|
|
|
102
102
|
return "const ".concat(importValue, " = () => import('").concat(path, "')");
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
return "import ".concat(importValue, " from '").concat(path, "';");
|
|
105
|
+
return importValue ? "import ".concat(importValue, " from '").concat(path, "';") : "import '".concat(path, "';");
|
|
106
106
|
};
|
|
107
107
|
exports.renderImport = renderImport;
|
|
108
108
|
var renderImports = function (_a) {
|
|
@@ -116,6 +116,9 @@ var renderImports = function (_a) {
|
|
|
116
116
|
theImport.path.startsWith('@builder.io/mitosis')) {
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
|
+
else if (target === 'angular' && theImport.path.includes('.lite')) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
119
122
|
else {
|
|
120
123
|
return true;
|
|
121
124
|
}
|
|
@@ -16,4 +16,18 @@ describe('renderImport', function () {
|
|
|
16
16
|
});
|
|
17
17
|
expect(output).toMatchSnapshot();
|
|
18
18
|
});
|
|
19
|
+
test('Adds correctly a side-effect import', function () {
|
|
20
|
+
var data = [
|
|
21
|
+
{
|
|
22
|
+
imports: {},
|
|
23
|
+
path: '../render-blocks.scss',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
var output = (0, render_imports_1.renderImport)({
|
|
27
|
+
theImport: data[0],
|
|
28
|
+
target: 'react',
|
|
29
|
+
asyncComponentImports: false,
|
|
30
|
+
});
|
|
31
|
+
expect(output).toEqual("import '../render-blocks.scss';");
|
|
32
|
+
});
|
|
19
33
|
});
|
|
@@ -203,7 +203,7 @@ var getBlockNonActionBindings = function (block, options) {
|
|
|
203
203
|
}
|
|
204
204
|
return obj;
|
|
205
205
|
};
|
|
206
|
-
|
|
206
|
+
function wrapBinding(value) {
|
|
207
207
|
if (!value) {
|
|
208
208
|
return value;
|
|
209
209
|
}
|
|
@@ -211,7 +211,7 @@ var wrapBinding = function (value) {
|
|
|
211
211
|
return value;
|
|
212
212
|
}
|
|
213
213
|
return "(() => {\n try { ".concat((0, parsers_1.isExpression)(value) ? 'return ' : '').concat(value, " }\n catch (err) {\n console.warn('Builder code error', err);\n }\n })()");
|
|
214
|
-
}
|
|
214
|
+
}
|
|
215
215
|
var getBlockBindings = function (block, options) {
|
|
216
216
|
var obj = __assign(__assign({}, getBlockNonActionBindings(block, options)), getBlockActionsAsBindings(block, options));
|
|
217
217
|
return obj;
|
|
@@ -281,15 +281,16 @@ var componentMappers = __assign(__assign({ Symbol: function (block, options) {
|
|
|
281
281
|
});
|
|
282
282
|
delete node.bindings.columns;
|
|
283
283
|
delete node.properties.columns;
|
|
284
|
-
node.children =
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
284
|
+
node.children =
|
|
285
|
+
((_b = (_a = block.component) === null || _a === void 0 ? void 0 : _a.options.columns) === null || _b === void 0 ? void 0 : _b.map(function (col, index) {
|
|
286
|
+
return (0, create_mitosis_node_1.createMitosisNode)(__assign(__assign({ name: 'Column', bindings: {
|
|
287
|
+
width: { code: col.width },
|
|
288
|
+
} }, (col.link && {
|
|
289
|
+
properties: {
|
|
290
|
+
link: col.link,
|
|
291
|
+
},
|
|
292
|
+
})), { children: col.blocks.map(function (col) { return (0, exports.builderElementToMitosisNode)(col, options); }) }));
|
|
293
|
+
})) || [];
|
|
293
294
|
return node;
|
|
294
295
|
}, 'Shopify:For': function (block, options) {
|
|
295
296
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
@@ -303,12 +304,12 @@ var componentMappers = __assign(__assign({ Symbol: function (block, options) {
|
|
|
303
304
|
children: (block.children || []).map(function (child) { return (0, exports.builderElementToMitosisNode)(child, options); }),
|
|
304
305
|
});
|
|
305
306
|
}, Text: function (block, options) {
|
|
306
|
-
var _a
|
|
307
|
-
var
|
|
307
|
+
var _a;
|
|
308
|
+
var _b;
|
|
308
309
|
var css = getCssFromBlock(block);
|
|
309
310
|
var styleString = getStyleStringFromBlock(block, options);
|
|
310
311
|
var actionBindings = getActionBindingsFromBlock(block, options);
|
|
311
|
-
var blockBindings = __assign(__assign({}, (
|
|
312
|
+
var blockBindings = __assign(__assign({}, mapBuilderBindingsToMitosisBindingWithCode((_b = block.code) === null || _b === void 0 ? void 0 : _b.bindings)), mapBuilderBindingsToMitosisBindingWithCode(block.bindings));
|
|
312
313
|
var bindings = __assign(__assign(__assign(__assign({}, (0, lodash_1.omitBy)(blockBindings, function (value, key) {
|
|
313
314
|
if (key === 'component.options.text') {
|
|
314
315
|
return true;
|
|
@@ -326,14 +327,16 @@ var componentMappers = __assign(__assign({ Symbol: function (block, options) {
|
|
|
326
327
|
if (block.layerName) {
|
|
327
328
|
properties.$name = block.layerName;
|
|
328
329
|
}
|
|
329
|
-
var innerBindings =
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
var innerBindings = {};
|
|
331
|
+
var componentOptionsText = blockBindings['component.options.text'];
|
|
332
|
+
if (componentOptionsText) {
|
|
333
|
+
innerBindings[options.preserveTextBlocks ? 'innerHTML' : '_text'] = {
|
|
334
|
+
code: wrapBindingIfNeeded(componentOptionsText.code, options),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
var innerProperties = (_a = {},
|
|
338
|
+
_a[options.preserveTextBlocks ? 'innerHTML' : '_text'] = block.component.options.text,
|
|
333
339
|
_a);
|
|
334
|
-
var innerProperties = (_b = {},
|
|
335
|
-
_b[options.preserveTextBlocks ? 'innerHTML' : '_text'] = block.component.options.text,
|
|
336
|
-
_b);
|
|
337
340
|
if (options.preserveTextBlocks) {
|
|
338
341
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
339
342
|
name: block.tagName || 'div',
|
|
@@ -712,3 +715,20 @@ var builderContentToMitosisComponent = function (builderContent, options) {
|
|
|
712
715
|
return componentJson;
|
|
713
716
|
};
|
|
714
717
|
exports.builderContentToMitosisComponent = builderContentToMitosisComponent;
|
|
718
|
+
function mapBuilderBindingsToMitosisBindingWithCode(bindings) {
|
|
719
|
+
var result = {};
|
|
720
|
+
bindings &&
|
|
721
|
+
Object.keys(bindings).forEach(function (key) {
|
|
722
|
+
var value = bindings[key];
|
|
723
|
+
if (typeof value === 'string') {
|
|
724
|
+
result[key] = { code: value };
|
|
725
|
+
}
|
|
726
|
+
else if (value && typeof value === 'object' && value.code) {
|
|
727
|
+
result[key] = { code: value.code };
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
throw new Error('Unexpected binding value: ' + JSON.stringify(value));
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
return result;
|
|
734
|
+
}
|
|
@@ -189,7 +189,8 @@ function hashCode(obj, hash) {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
|
-
for (var
|
|
192
|
+
for (var _i = 0, _a = Object.keys(obj).sort(); _i < _a.length; _i++) {
|
|
193
|
+
var key = _a[_i];
|
|
193
194
|
if (obj.hasOwnProperty(key)) {
|
|
194
195
|
hash = hashCode(obj[key], hash);
|
|
195
196
|
}
|