@builder.io/mitosis 0.0.56-28 → 0.0.56-30
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__/data/advanced-ref.raw.d.ts +4 -0
- package/dist/src/__tests__/data/advanced-ref.raw.jsx +39 -0
- package/dist/src/__tests__/hash-code.test.js +3 -0
- package/dist/src/__tests__/shared.js +26 -0
- package/dist/src/generators/angular.d.ts +1 -0
- package/dist/src/generators/angular.js +17 -7
- 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/babel-transform.js +1 -0
- package/dist/src/helpers/map-refs.js +6 -0
- package/dist/src/helpers/render-imports.js +4 -1
- package/dist/src/helpers/render-imports.test.js +14 -0
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +1 -0
- package/dist/src/helpers/strip-state-and-props-refs.js +9 -1
- package/dist/src/parsers/builder.js +41 -21
- package/dist/src/symbols/symbol-processor.js +2 -1
- package/dist/test/qwik/Accordion/low.jsx +16 -7
- package/dist/test/qwik/For/low.jsx +16 -7
- package/dist/test/qwik/Image/med.js +12 -8
- package/dist/test/qwik/Image.slow/med.js +12 -8
- package/dist/test/qwik/bindings/low.cjs +10 -6
- package/dist/test/qwik/button/low.js +17 -8
- package/dist/test/qwik/button/med.js +1 -1
- package/dist/test/qwik/component/bindings/low.jsx +49 -41
- package/dist/test/qwik/component/component/inputs/med.cjsx +12 -8
- package/dist/test/qwik/for-loop.bindings/low.cjs +10 -6
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +16 -7
- package/dist/test/qwik/mount/low.cjs +12 -10
- package/dist/test/qwik/page-with-symbol/low.js +16 -7
- package/dist/test/qwik/show-hide/med.jsx +12 -8
- package/dist/test/qwik/svg/low.js +16 -7
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +15 -11
- package/dist/test/qwik/todo/Todo.js/med.js +15 -12
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +15 -12
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +11 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function MyBasicRefComponent(props) {
|
|
5
|
+
var inputRef = (0, mitosis_1.useRef)(null);
|
|
6
|
+
var inputNoArgRef = (0, mitosis_1.useRef)(null);
|
|
7
|
+
var state = (0, mitosis_1.useStore)({
|
|
8
|
+
name: 'PatrickJS',
|
|
9
|
+
});
|
|
10
|
+
function onBlur() {
|
|
11
|
+
// Maintain focus
|
|
12
|
+
inputRef.focus();
|
|
13
|
+
}
|
|
14
|
+
function lowerCaseName() {
|
|
15
|
+
return state.name.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
(0, mitosis_1.onUpdate)(function () {
|
|
18
|
+
console.log('Received an update');
|
|
19
|
+
}, [inputRef, inputNoArgRef]);
|
|
20
|
+
return (<div>
|
|
21
|
+
{props.showInput && (<>
|
|
22
|
+
<input ref={inputRef} css={{
|
|
23
|
+
color: 'red',
|
|
24
|
+
}} value={state.name} onBlur={function (event) { return onBlur(); }} onChange={function (event) { return (state.name = event.target.value); }}/>
|
|
25
|
+
|
|
26
|
+
<label ref={inputNoArgRef} for="cars">
|
|
27
|
+
Choose a car:
|
|
28
|
+
</label>
|
|
29
|
+
|
|
30
|
+
<select name="cars" id="cars">
|
|
31
|
+
<option value="supra">GR Supra</option>
|
|
32
|
+
<option value="86">GR 86</option>
|
|
33
|
+
</select>
|
|
34
|
+
</>)}
|
|
35
|
+
Hello
|
|
36
|
+
{lowerCaseName()}! I can run in React, Qwik, Vue, Solid, or Web Component!
|
|
37
|
+
</div>);
|
|
38
|
+
}
|
|
39
|
+
exports.default = MyBasicRefComponent;
|
|
@@ -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
|
});
|
|
@@ -128,6 +128,12 @@ var SHOW_TESTS = {
|
|
|
128
128
|
nestedShow: require('./data/show/nested-show.raw'),
|
|
129
129
|
showWithFor: require('./data/show/show-with-for.raw'),
|
|
130
130
|
};
|
|
131
|
+
var ADVANCED_REF = {
|
|
132
|
+
AdvancedRef: require('./data/advanced-ref.raw'),
|
|
133
|
+
};
|
|
134
|
+
var ON_UPDATE_RETURN = {
|
|
135
|
+
basicOnUpdateReturn: require('./data/basic-onUpdate-return.raw'),
|
|
136
|
+
};
|
|
131
137
|
var TESTS_FOR_TARGET = {
|
|
132
138
|
react: [
|
|
133
139
|
BASIC_TESTS,
|
|
@@ -136,6 +142,8 @@ var TESTS_FOR_TARGET = {
|
|
|
136
142
|
FORWARD_REF_TESTS,
|
|
137
143
|
MULTI_ON_UPDATE_TESTS,
|
|
138
144
|
FORM_BLOCK_TESTS,
|
|
145
|
+
ADVANCED_REF,
|
|
146
|
+
ON_UPDATE_RETURN,
|
|
139
147
|
// FOR_SHOW_TESTS,
|
|
140
148
|
],
|
|
141
149
|
angular: [
|
|
@@ -146,6 +154,8 @@ var TESTS_FOR_TARGET = {
|
|
|
146
154
|
MULTI_ON_UPDATE_TESTS,
|
|
147
155
|
FORM_BLOCK_TESTS,
|
|
148
156
|
FOR_SHOW_TESTS,
|
|
157
|
+
ADVANCED_REF,
|
|
158
|
+
ON_UPDATE_RETURN,
|
|
149
159
|
],
|
|
150
160
|
webcomponent: [
|
|
151
161
|
BASIC_TESTS,
|
|
@@ -154,6 +164,8 @@ var TESTS_FOR_TARGET = {
|
|
|
154
164
|
FORWARD_REF_TESTS,
|
|
155
165
|
MULTI_ON_UPDATE_TESTS,
|
|
156
166
|
FOR_SHOW_TESTS,
|
|
167
|
+
ADVANCED_REF,
|
|
168
|
+
ON_UPDATE_RETURN,
|
|
157
169
|
// FORM_BLOCK_TESTS
|
|
158
170
|
],
|
|
159
171
|
vue: [
|
|
@@ -164,6 +176,8 @@ var TESTS_FOR_TARGET = {
|
|
|
164
176
|
MULTI_ON_UPDATE_TESTS,
|
|
165
177
|
FORM_BLOCK_TESTS,
|
|
166
178
|
FOR_SHOW_TESTS,
|
|
179
|
+
ADVANCED_REF,
|
|
180
|
+
ON_UPDATE_RETURN,
|
|
167
181
|
],
|
|
168
182
|
svelte: [
|
|
169
183
|
BASIC_TESTS,
|
|
@@ -172,6 +186,8 @@ var TESTS_FOR_TARGET = {
|
|
|
172
186
|
MULTI_ON_UPDATE_TESTS,
|
|
173
187
|
FORM_BLOCK_TESTS,
|
|
174
188
|
FOR_SHOW_TESTS,
|
|
189
|
+
ADVANCED_REF,
|
|
190
|
+
ON_UPDATE_RETURN,
|
|
175
191
|
],
|
|
176
192
|
html: [
|
|
177
193
|
BASIC_TESTS,
|
|
@@ -180,6 +196,8 @@ var TESTS_FOR_TARGET = {
|
|
|
180
196
|
FORWARD_REF_TESTS,
|
|
181
197
|
MULTI_ON_UPDATE_TESTS,
|
|
182
198
|
FOR_SHOW_TESTS,
|
|
199
|
+
ADVANCED_REF,
|
|
200
|
+
ON_UPDATE_RETURN,
|
|
183
201
|
// FORM_BLOCK_TESTS
|
|
184
202
|
],
|
|
185
203
|
stencil: [
|
|
@@ -189,6 +207,8 @@ var TESTS_FOR_TARGET = {
|
|
|
189
207
|
FORWARD_REF_TESTS,
|
|
190
208
|
// MULTI_ON_UPDATE_TESTS,
|
|
191
209
|
FORM_BLOCK_TESTS,
|
|
210
|
+
ADVANCED_REF,
|
|
211
|
+
ON_UPDATE_RETURN,
|
|
192
212
|
// FOR_SHOW_TESTS
|
|
193
213
|
],
|
|
194
214
|
solid: [
|
|
@@ -199,6 +219,8 @@ var TESTS_FOR_TARGET = {
|
|
|
199
219
|
MULTI_ON_UPDATE_TESTS,
|
|
200
220
|
FORM_BLOCK_TESTS,
|
|
201
221
|
FOR_SHOW_TESTS,
|
|
222
|
+
ADVANCED_REF,
|
|
223
|
+
ON_UPDATE_RETURN,
|
|
202
224
|
],
|
|
203
225
|
reactNative: [
|
|
204
226
|
BASIC_TESTS,
|
|
@@ -207,6 +229,8 @@ var TESTS_FOR_TARGET = {
|
|
|
207
229
|
FORWARD_REF_TESTS,
|
|
208
230
|
MULTI_ON_UPDATE_TESTS,
|
|
209
231
|
FORM_BLOCK_TESTS,
|
|
232
|
+
ADVANCED_REF,
|
|
233
|
+
ON_UPDATE_RETURN,
|
|
210
234
|
// FOR_SHOW_TESTS,
|
|
211
235
|
],
|
|
212
236
|
liquid: [
|
|
@@ -216,6 +240,8 @@ var TESTS_FOR_TARGET = {
|
|
|
216
240
|
FORWARD_REF_TESTS,
|
|
217
241
|
MULTI_ON_UPDATE_TESTS,
|
|
218
242
|
FORM_BLOCK_TESTS,
|
|
243
|
+
ADVANCED_REF,
|
|
244
|
+
ON_UPDATE_RETURN,
|
|
219
245
|
],
|
|
220
246
|
qwik: [
|
|
221
247
|
BASIC_TESTS,
|
|
@@ -6,6 +6,7 @@ interface AngularBlockOptions {
|
|
|
6
6
|
contextVars?: string[];
|
|
7
7
|
outputVars?: string[];
|
|
8
8
|
childComponents?: string[];
|
|
9
|
+
domRefs?: string[];
|
|
9
10
|
}
|
|
10
11
|
export declare const blockToAngular: (json: MitosisNode, options?: ToAngularOptions, blockOptions?: AngularBlockOptions) => string;
|
|
11
12
|
export declare const componentToAngular: (options?: ToAngularOptions) => Transpiler;
|
|
@@ -68,6 +68,7 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
68
68
|
var contextVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.contextVars) || [];
|
|
69
69
|
var outputVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.outputVars) || [];
|
|
70
70
|
var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
71
|
+
var domRefs = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.domRefs) || [];
|
|
71
72
|
if (mappers[json.name]) {
|
|
72
73
|
return mappers[json.name](json, options, blockOptions);
|
|
73
74
|
}
|
|
@@ -86,6 +87,7 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
86
87
|
// the context is the class
|
|
87
88
|
contextVars: [],
|
|
88
89
|
outputVars: outputVars,
|
|
90
|
+
domRefs: domRefs,
|
|
89
91
|
}), "}}");
|
|
90
92
|
}
|
|
91
93
|
var str = '';
|
|
@@ -94,6 +96,7 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
94
96
|
str += "<ng-container *ngFor=\"let ".concat(json.properties._forName, " of ").concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_e = json.bindings.each) === null || _e === void 0 ? void 0 : _e.code, {
|
|
95
97
|
contextVars: contextVars,
|
|
96
98
|
outputVars: outputVars,
|
|
99
|
+
domRefs: domRefs,
|
|
97
100
|
}), "\">");
|
|
98
101
|
str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
|
|
99
102
|
str += "</ng-container>";
|
|
@@ -102,6 +105,7 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
102
105
|
str += "<ng-container *ngIf=\"".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((_f = json.bindings.when) === null || _f === void 0 ? void 0 : _f.code, {
|
|
103
106
|
contextVars: contextVars,
|
|
104
107
|
outputVars: outputVars,
|
|
108
|
+
domRefs: domRefs,
|
|
105
109
|
}), "\">");
|
|
106
110
|
str += json.children.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); }).join('\n');
|
|
107
111
|
str += "</ng-container>";
|
|
@@ -136,6 +140,7 @@ var blockToAngular = function (json, options, blockOptions) {
|
|
|
136
140
|
var useValue = (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
137
141
|
contextVars: contextVars,
|
|
138
142
|
outputVars: outputVars,
|
|
143
|
+
domRefs: domRefs,
|
|
139
144
|
});
|
|
140
145
|
if (key.startsWith('on')) {
|
|
141
146
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
@@ -252,14 +257,14 @@ var componentToAngular = function (options) {
|
|
|
252
257
|
if (options.prettier !== false) {
|
|
253
258
|
css = tryFormat(css, 'css');
|
|
254
259
|
}
|
|
260
|
+
var blockOptions = {
|
|
261
|
+
contextVars: contextVars,
|
|
262
|
+
outputVars: outputVars,
|
|
263
|
+
domRefs: [],
|
|
264
|
+
childComponents: childComponents,
|
|
265
|
+
};
|
|
255
266
|
var template = json.children
|
|
256
|
-
.map(function (item) {
|
|
257
|
-
return (0, exports.blockToAngular)(item, options, {
|
|
258
|
-
contextVars: contextVars,
|
|
259
|
-
outputVars: outputVars,
|
|
260
|
-
childComponents: childComponents,
|
|
261
|
-
});
|
|
262
|
-
})
|
|
267
|
+
.map(function (item) { return (0, exports.blockToAngular)(item, options, blockOptions); })
|
|
263
268
|
.join('\n');
|
|
264
269
|
if (options.prettier !== false) {
|
|
265
270
|
template = tryFormat(template, 'html');
|
|
@@ -272,6 +277,7 @@ var componentToAngular = function (options) {
|
|
|
272
277
|
replaceWith: 'this.',
|
|
273
278
|
contextVars: contextVars,
|
|
274
279
|
outputVars: outputVars,
|
|
280
|
+
domRefs: Array.from(domRefs),
|
|
275
281
|
});
|
|
276
282
|
},
|
|
277
283
|
});
|
|
@@ -294,6 +300,7 @@ var componentToAngular = function (options) {
|
|
|
294
300
|
replaceWith: 'this.',
|
|
295
301
|
contextVars: contextVars,
|
|
296
302
|
outputVars: outputVars,
|
|
303
|
+
domRefs: Array.from(domRefs),
|
|
297
304
|
}))
|
|
298
305
|
: '', ";");
|
|
299
306
|
})
|
|
@@ -313,6 +320,7 @@ var componentToAngular = function (options) {
|
|
|
313
320
|
replaceWith: 'this.',
|
|
314
321
|
contextVars: contextVars,
|
|
315
322
|
outputVars: outputVars,
|
|
323
|
+
domRefs: Array.from(domRefs),
|
|
316
324
|
}), "\n "), "\n }"), !((_o = component.hooks.onUpdate) === null || _o === void 0 ? void 0 : _o.length)
|
|
317
325
|
? ''
|
|
318
326
|
: "ngAfterContentChecked() {\n ".concat(component.hooks.onUpdate.reduce(function (code, hook) {
|
|
@@ -320,6 +328,7 @@ var componentToAngular = function (options) {
|
|
|
320
328
|
replaceWith: 'this.',
|
|
321
329
|
contextVars: contextVars,
|
|
322
330
|
outputVars: outputVars,
|
|
331
|
+
domRefs: Array.from(domRefs),
|
|
323
332
|
});
|
|
324
333
|
return code + '\n';
|
|
325
334
|
}, ''), "\n }"), !component.hooks.onUnMount
|
|
@@ -328,6 +337,7 @@ var componentToAngular = function (options) {
|
|
|
328
337
|
replaceWith: 'this.',
|
|
329
338
|
contextVars: contextVars,
|
|
330
339
|
outputVars: outputVars,
|
|
340
|
+
domRefs: Array.from(domRefs),
|
|
331
341
|
}), "\n }"));
|
|
332
342
|
if (options.plugins) {
|
|
333
343
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
@@ -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
|
}
|
|
@@ -44,6 +44,7 @@ var babelTransform = function (code, visitor) {
|
|
|
44
44
|
configFile: false,
|
|
45
45
|
babelrc: false,
|
|
46
46
|
presets: [[tsPreset, { isTSX: true, allExtensions: true }]],
|
|
47
|
+
parserOpts: { allowReturnOutsideFunction: true },
|
|
47
48
|
plugins: __spreadArray([[decorators, { legacy: true }], jsxPlugin], (visitor ? [function () { return ({ visitor: visitor }); }] : []), true),
|
|
48
49
|
});
|
|
49
50
|
};
|
|
@@ -101,6 +101,9 @@ var mapRefs = function (component, mapper) {
|
|
|
101
101
|
if (hook.code) {
|
|
102
102
|
hook.code = replaceRefsInString(hook.code, refs, mapper);
|
|
103
103
|
}
|
|
104
|
+
if (hook.deps) {
|
|
105
|
+
hook.deps = replaceRefsInString(hook.deps, refs, mapper);
|
|
106
|
+
}
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
else {
|
|
@@ -108,6 +111,9 @@ var mapRefs = function (component, mapper) {
|
|
|
108
111
|
if (hookCode) {
|
|
109
112
|
hooks.code = replaceRefsInString(hookCode, refs, mapper);
|
|
110
113
|
}
|
|
114
|
+
if (hooks === null || hooks === void 0 ? void 0 : hooks.deps) {
|
|
115
|
+
hooks.deps = replaceRefsInString(hooks === null || hooks === void 0 ? void 0 : hooks.deps, refs, mapper);
|
|
116
|
+
}
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
};
|
|
@@ -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
|
});
|
|
@@ -16,10 +16,11 @@ var stripStateAndPropsRefs = function (code, options) {
|
|
|
16
16
|
var contextVars = (options === null || options === void 0 ? void 0 : options.contextVars) || [];
|
|
17
17
|
var outputVars = (options === null || options === void 0 ? void 0 : options.outputVars) || [];
|
|
18
18
|
var context = (options === null || options === void 0 ? void 0 : options.context) || 'this.';
|
|
19
|
+
var domRefs = (options === null || options === void 0 ? void 0 : options.domRefs) || [];
|
|
19
20
|
if (contextVars.length) {
|
|
20
21
|
contextVars.forEach(function (_var) {
|
|
21
22
|
newCode = newCode.replace(
|
|
22
|
-
// determine expression edge cases
|
|
23
|
+
// determine expression edge cases - https://regex101.com/r/iNcTSM/1
|
|
23
24
|
new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + _var + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g'), '$1' + context + _var + '$2');
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -51,6 +52,13 @@ var stripStateAndPropsRefs = function (code, options) {
|
|
|
51
52
|
newCode = newCode.replace(/state\.([\$a-z0-9_]+)/gi, function (memo, name) { return replacer(name); });
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
if (domRefs.length) {
|
|
56
|
+
domRefs.forEach(function (_var) {
|
|
57
|
+
newCode = newCode.replace(
|
|
58
|
+
// determine expression edge cases - https://regex101.com/r/iNcTSM/1
|
|
59
|
+
new RegExp('(^|\\n|\\r| |;|\\(|\\[|!)' + _var + '(\\?\\.|\\.|\\(| |;|\\)|$)', 'g'), '$1' + 'this.' + _var + '$2');
|
|
60
|
+
});
|
|
61
|
+
}
|
|
54
62
|
return newCode;
|
|
55
63
|
};
|
|
56
64
|
exports.stripStateAndPropsRefs = stripStateAndPropsRefs;
|
|
@@ -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
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Fragment,
|
|
3
|
+
h,
|
|
4
|
+
qrl,
|
|
5
|
+
useStore,
|
|
6
|
+
withScopedStylesQrl,
|
|
7
|
+
} from "@builder.io/qwik";
|
|
2
8
|
export const MyComponent_styles = `.csw5022{display:flex;flex-direction:column;position:relative;flex-shrink:0;box-sizing:border-box;margin-top:20px;align-items:stretch}.csanagh{margin-top:10px;position:relative;display:flex;align-items:stretch;flex-direction:column;padding-bottom:10px}.c4qyc1p{position:relative;display:flex;align-items:stretch;flex-direction:column;margin-top:10px;padding-bottom:10px}.crwdrpw{text-align:left;display:flex;flex-direction:column}.ctcw2m4{padding-top:50px;text-align:left;display:flex;flex-direction:column;padding-bottom:50px}`;
|
|
3
|
-
export const MyComponent_onMount = (
|
|
4
|
-
|
|
5
|
-
state
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
export const MyComponent_onMount = (props) => {
|
|
10
|
+
const state = useStore(() => {
|
|
11
|
+
const state = Object.assign(
|
|
12
|
+
{},
|
|
13
|
+
props,
|
|
14
|
+
typeof __STATE__ === "object" ? __STATE__[props.serverStateId] : undefined
|
|
15
|
+
);
|
|
16
|
+
return state;
|
|
17
|
+
});
|
|
9
18
|
withScopedStylesQrl(qrl("./low.js", "MyComponent_styles", []));
|
|
10
19
|
return (
|
|
11
20
|
<div
|