@builder.io/mitosis 0.0.44-21 → 0.0.45-2
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__/builder.test.js +55 -0
- package/dist/src/__tests__/context.test.js +7 -0
- package/dist/src/__tests__/data/blocks/columns.raw.jsx +0 -2
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +1 -1
- package/dist/src/__tests__/react-native.test.d.ts +1 -0
- package/dist/src/__tests__/react-native.test.js +110 -0
- package/dist/src/flow.d.ts +3 -3
- package/dist/src/generators/builder.d.ts +1 -0
- package/dist/src/generators/builder.js +4 -2
- package/dist/src/generators/context/vue.d.ts +6 -0
- package/dist/src/generators/context/vue.js +9 -0
- package/dist/src/generators/qwik.js +23 -10
- package/dist/src/generators/react-native.d.ts +1 -1
- package/dist/src/generators/react-native.js +17 -0
- package/dist/src/generators/react.js +30 -19
- package/dist/src/generators/template.js +1 -1
- package/dist/src/generators/vue.d.ts +4 -0
- package/dist/src/generators/vue.js +139 -28
- package/dist/src/helpers/babel-transform.js +31 -18
- package/dist/src/helpers/collect-styles.js +1 -1
- package/dist/src/helpers/get-state-used.d.ts +5 -0
- package/dist/src/helpers/get-state-used.js +29 -0
- package/dist/src/helpers/handle-missing-state.d.ts +2 -0
- package/dist/src/helpers/handle-missing-state.js +13 -0
- package/dist/src/helpers/parse-node.js +2 -2
- package/dist/src/helpers/process-http-requests.d.ts +2 -0
- package/dist/src/helpers/process-http-requests.js +22 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/jsx-types.d.ts +1 -0
- package/dist/src/parsers/builder.js +16 -12
- package/dist/src/parsers/context.js +2 -0
- package/dist/src/parsers/jsx.js +51 -7
- package/dist/src/plugins/compile-away-builder-components.js +2 -2
- package/dist/test/qwik/Todo/bundle.js +8 -8
- package/dist/test/qwik/Todo_onButtonClick.ts +1 -4
- package/dist/test/qwik/Todo_onInput2Blur.ts +1 -1
- package/dist/test/qwik/Todo_onLabelDblClick.ts +1 -4
- package/dist/test/qwik/Todo_template.tsx +2 -2
- package/dist/test/qwik/Todos_template.tsx +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
package/dist/src/parsers/jsx.js
CHANGED
|
@@ -300,6 +300,9 @@ var jsxElementToJson = function (node) {
|
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
302
|
if (types.isJSXExpressionContainer(node)) {
|
|
303
|
+
if (types.isJSXEmptyExpression(node.expression)) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
303
306
|
// foo.map -> <For each={foo}>...</For>
|
|
304
307
|
if (types.isCallExpression(node.expression) ||
|
|
305
308
|
types.isOptionalCallExpression(node.expression)) {
|
|
@@ -337,6 +340,19 @@ var jsxElementToJson = function (node) {
|
|
|
337
340
|
// TODO: good warning system for unsupported operators
|
|
338
341
|
}
|
|
339
342
|
}
|
|
343
|
+
// {foo ? <div /> : <span />} -> <Show when={foo} else={<span />}>...</Show>
|
|
344
|
+
if (types.isConditionalExpression(node.expression)) {
|
|
345
|
+
return create_mitosis_node_1.createMitosisNode({
|
|
346
|
+
name: 'Show',
|
|
347
|
+
meta: {
|
|
348
|
+
else: jsxElementToJson(node.expression.alternate),
|
|
349
|
+
},
|
|
350
|
+
bindings: {
|
|
351
|
+
when: generator_1.default(node.expression.test).code,
|
|
352
|
+
},
|
|
353
|
+
children: [jsxElementToJson(node.expression.consequent)],
|
|
354
|
+
});
|
|
355
|
+
}
|
|
340
356
|
// TODO: support {foo ? bar : baz}
|
|
341
357
|
return create_mitosis_node_1.createMitosisNode({
|
|
342
358
|
bindings: {
|
|
@@ -347,25 +363,32 @@ var jsxElementToJson = function (node) {
|
|
|
347
363
|
if (types.isJSXFragment(node)) {
|
|
348
364
|
return create_mitosis_node_1.createMitosisNode({
|
|
349
365
|
name: 'Fragment',
|
|
350
|
-
children: node.children
|
|
351
|
-
return jsxElementToJson(item);
|
|
352
|
-
|
|
366
|
+
children: node.children
|
|
367
|
+
.map(function (item) { return jsxElementToJson(item); })
|
|
368
|
+
.filter(Boolean),
|
|
353
369
|
});
|
|
354
370
|
}
|
|
355
371
|
var nodeName = generator_1.default(node.openingElement.name).code;
|
|
356
372
|
if (nodeName === 'Show') {
|
|
357
373
|
var whenAttr = node.openingElement.attributes.find(function (item) { return types.isJSXAttribute(item) && item.name.name === 'when'; });
|
|
374
|
+
var elseAttr = node.openingElement.attributes.find(function (item) { return types.isJSXAttribute(item) && item.name.name === 'else'; });
|
|
358
375
|
var whenValue = whenAttr &&
|
|
359
376
|
types.isJSXExpressionContainer(whenAttr.value) &&
|
|
360
377
|
generator_1.default(whenAttr.value.expression).code;
|
|
378
|
+
var elseValue = elseAttr &&
|
|
379
|
+
types.isJSXExpressionContainer(elseAttr.value) &&
|
|
380
|
+
jsxElementToJson(elseAttr.value.expression);
|
|
361
381
|
return create_mitosis_node_1.createMitosisNode({
|
|
362
382
|
name: 'Show',
|
|
383
|
+
meta: {
|
|
384
|
+
else: elseValue || undefined,
|
|
385
|
+
},
|
|
363
386
|
bindings: {
|
|
364
387
|
when: whenValue || undefined,
|
|
365
388
|
},
|
|
366
|
-
children: node.children
|
|
367
|
-
return jsxElementToJson(item);
|
|
368
|
-
|
|
389
|
+
children: node.children
|
|
390
|
+
.map(function (item) { return jsxElementToJson(item); })
|
|
391
|
+
.filter(Boolean),
|
|
369
392
|
});
|
|
370
393
|
}
|
|
371
394
|
// <For ...> control flow component
|
|
@@ -428,7 +451,9 @@ var jsxElementToJson = function (node) {
|
|
|
428
451
|
}
|
|
429
452
|
return memo;
|
|
430
453
|
}, {}),
|
|
431
|
-
children: node.children
|
|
454
|
+
children: node.children
|
|
455
|
+
.map(function (item) { return jsxElementToJson(item); })
|
|
456
|
+
.filter(Boolean),
|
|
432
457
|
});
|
|
433
458
|
};
|
|
434
459
|
var getHook = function (node) {
|
|
@@ -512,6 +537,18 @@ function mapReactIdentifiers(json) {
|
|
|
512
537
|
if (value) {
|
|
513
538
|
item.bindings[key] = mapReactIdentifiersInExpression(value, stateProperties);
|
|
514
539
|
}
|
|
540
|
+
if (key === 'className') {
|
|
541
|
+
var currentValue = item.bindings[key];
|
|
542
|
+
delete item.bindings[key];
|
|
543
|
+
item.bindings.class = currentValue;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
for (var key in item.properties) {
|
|
547
|
+
if (key === 'class') {
|
|
548
|
+
var currentValue = item.properties[key];
|
|
549
|
+
delete item.properties[key];
|
|
550
|
+
item.properties.class = currentValue;
|
|
551
|
+
}
|
|
515
552
|
}
|
|
516
553
|
}
|
|
517
554
|
});
|
|
@@ -553,11 +590,18 @@ function parseJsx(jsx, options) {
|
|
|
553
590
|
var useOptions = __assign({ format: 'react' }, options);
|
|
554
591
|
var subComponentFunctions = [];
|
|
555
592
|
var output = babel.transform(jsx, {
|
|
593
|
+
configFile: false,
|
|
594
|
+
babelrc: false,
|
|
556
595
|
presets: [[tsPreset, { isTSX: true, allExtensions: true }]],
|
|
557
596
|
plugins: [
|
|
558
597
|
jsxPlugin,
|
|
559
598
|
function () { return ({
|
|
560
599
|
visitor: {
|
|
600
|
+
JSXExpressionContainer: function (path, context) {
|
|
601
|
+
if (types.isJSXEmptyExpression(path.node.expression)) {
|
|
602
|
+
path.remove();
|
|
603
|
+
}
|
|
604
|
+
},
|
|
561
605
|
Program: function (path, context) {
|
|
562
606
|
if (context.builder) {
|
|
563
607
|
return;
|
|
@@ -113,7 +113,7 @@ exports.components = {
|
|
|
113
113
|
}), components);
|
|
114
114
|
},
|
|
115
115
|
CoreSection: function (node, context, components) {
|
|
116
|
-
return wrapOutput(node, parse_node_1.parseNode("<
|
|
116
|
+
return wrapOutput(node, parse_node_1.parseNode("<section\n $name=\"section\"\n " + (node.bindings.lazyLoad === 'true' ? 'lazyload="true"' : '') + "\n css={{\n width: '100%',\n alignSelf: 'stretch',\n flexGrow: '1',\n boxSizing: 'border-box',\n maxWidth: '" + ((node.bindings.maxWidth &&
|
|
117
117
|
Number(node.bindings.maxWidth)) ||
|
|
118
118
|
1200) + "px',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'stretch',\n marginLeft: 'auto',\n marginRight: 'auto',\n }}\n >\n " + node.children
|
|
119
119
|
.map(function (block) {
|
|
@@ -121,7 +121,7 @@ exports.components = {
|
|
|
121
121
|
prettier: false,
|
|
122
122
|
});
|
|
123
123
|
})
|
|
124
|
-
.join('\n') + "\n </
|
|
124
|
+
.join('\n') + "\n </section>"), components);
|
|
125
125
|
},
|
|
126
126
|
Columns: function (node, context, components) {
|
|
127
127
|
var columns = node.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes).map(function (item) { return ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, injectMethod,
|
|
1
|
+
import { Component, injectMethod, h, QRL } from '@builder.io/qwik';
|
|
2
2
|
|
|
3
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
4
|
class TodoComponent extends Component {
|
|
@@ -21,21 +21,21 @@ class TodoComponent extends Component {
|
|
|
21
21
|
_defineProperty(TodoComponent, "$templateQRL", "ui:/Todo/bundle.template");
|
|
22
22
|
|
|
23
23
|
const template = injectMethod(TodoComponent, function () {
|
|
24
|
-
return
|
|
24
|
+
return h("li", {
|
|
25
25
|
class: `${this.todo.completed ? "completed" : ""} ${this.editing ? "editing" : ""}`
|
|
26
|
-
},
|
|
26
|
+
}, h("div", {
|
|
27
27
|
class: "view"
|
|
28
|
-
},
|
|
29
|
-
class: "toggle",
|
|
28
|
+
}, h("input", {
|
|
30
29
|
type: "checkbox",
|
|
30
|
+
class: "toggle",
|
|
31
31
|
checked: this.todo.completed,
|
|
32
32
|
"on:click": QRL`ui:/Todo/bundle.onInputClick`
|
|
33
|
-
}),
|
|
33
|
+
}), h("label", {
|
|
34
34
|
"on:dblclick": QRL`ui:/Todo/bundle.onLabelDblClick`
|
|
35
|
-
}, this.todo.text),
|
|
35
|
+
}, this.todo.text), h("button", {
|
|
36
36
|
class: "destroy",
|
|
37
37
|
"on:click": QRL`ui:/Todo/bundle.onButtonClick`
|
|
38
|
-
})), this.editing ?
|
|
38
|
+
})), this.editing ? h(null, null, h("input", {
|
|
39
39
|
class: "edit",
|
|
40
40
|
value: this.todo.text,
|
|
41
41
|
"on:blur": QRL`ui:/Todo/bundle.onInput2Blur`,
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { injectEventHandler, provideEvent, markDirty } from "@builder.io/qwik";
|
|
2
2
|
import { TodoComponent } from "./Todo_component.js";
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export const onButtonClick = injectEventHandler(
|
|
5
5
|
TodoComponent,
|
|
6
6
|
provideEvent(),
|
|
7
7
|
async function (this: TodoComponent, event: Event) {
|
|
8
8
|
todosState.todos.splice(todosState.todos.indexOf(this.todo));
|
|
9
9
|
}
|
|
10
10
|
);
|
|
11
|
-
odo));
|
|
12
|
-
}
|
|
13
|
-
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { injectEventHandler, provideEvent, markDirty } from "@builder.io/qwik";
|
|
2
2
|
import { TodoComponent } from "./Todo_component.js";
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export default injectEventHandler(
|
|
5
5
|
TodoComponent,
|
|
6
6
|
provideEvent(),
|
|
7
7
|
async function (this: TodoComponent, event: Event) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { injectEventHandler, provideEvent, markDirty } from "@builder.io/qwik";
|
|
2
2
|
import { TodoComponent } from "./Todo_component.js";
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export const onLabelDblClick = injectEventHandler(
|
|
5
5
|
TodoComponent,
|
|
6
6
|
provideEvent(),
|
|
7
7
|
async function (this: TodoComponent, event: Event) {
|
|
@@ -9,6 +9,3 @@ export default injectEventHandler(
|
|
|
9
9
|
markDirty(this);
|
|
10
10
|
}
|
|
11
11
|
);
|
|
12
|
-
y(this);
|
|
13
|
-
}
|
|
14
|
-
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { injectMethod, QRL,
|
|
1
|
+
import { injectMethod, QRL, h } from "@builder.io/qwik";
|
|
2
2
|
import { TodoComponent } from "./Todo_component.js";
|
|
3
3
|
|
|
4
4
|
import { TodosState as todosState } from "../TodosState/public.js";
|
|
@@ -14,8 +14,8 @@ export const template = injectMethod(
|
|
|
14
14
|
>
|
|
15
15
|
<div class="view">
|
|
16
16
|
<input
|
|
17
|
-
class="toggle"
|
|
18
17
|
type="checkbox"
|
|
18
|
+
class="toggle"
|
|
19
19
|
checked={this.todo.completed}
|
|
20
20
|
on:click={QRL`ui:/Todo/bundle.onInputClick`}
|
|
21
21
|
/>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { injectMethod, QRL,
|
|
1
|
+
import { injectMethod, QRL, h } from "@builder.io/qwik";
|
|
2
2
|
import { TodosComponent } from "./Todos_component.js";
|
|
3
3
|
|
|
4
4
|
import { TodosState as todosState } from "../TodosState/public.js";
|
|
@@ -10,8 +10,8 @@ export default injectMethod(TodosComponent, function (this: TodosComponent) {
|
|
|
10
10
|
{todosState.todos.length ? (
|
|
11
11
|
<>
|
|
12
12
|
<input
|
|
13
|
-
class="toggle-all"
|
|
14
13
|
type="checkbox"
|
|
14
|
+
class="toggle-all"
|
|
15
15
|
checked={todosState.allCompleted}
|
|
16
16
|
on:click={QRL`ui:/Todos_onInputClick`}
|
|
17
17
|
/>
|
|
@@ -19,7 +19,7 @@ export default injectMethod(TodosComponent, function (this: TodosComponent) {
|
|
|
19
19
|
) : undefined}
|
|
20
20
|
|
|
21
21
|
<ul class="todo-list">
|
|
22
|
-
{todosState.todos
|
|
22
|
+
{todosState.todos?.map((todo) => (
|
|
23
23
|
<>
|
|
24
24
|
<Todo todo={todo}></Todo>
|
|
25
25
|
</>
|