@builder.io/mitosis 0.0.45-2 → 0.0.45
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 +6 -1
- package/dist/src/__tests__/qwik.test.js +166 -50
- package/dist/src/generators/qwik/component.d.ts +20 -0
- package/dist/src/generators/qwik/component.js +117 -0
- package/dist/src/generators/qwik/directives.d.ts +2 -0
- package/dist/src/generators/qwik/directives.js +24 -0
- package/dist/src/generators/qwik/handlers.d.ts +4 -0
- package/dist/src/generators/qwik/handlers.js +76 -0
- package/dist/src/generators/qwik/index.d.ts +2 -0
- package/dist/src/generators/qwik/index.js +9 -0
- package/dist/src/generators/qwik/jsx.d.ts +4 -0
- package/dist/src/generators/qwik/jsx.js +120 -0
- package/dist/src/generators/qwik/src-generator.d.ts +68 -0
- package/dist/src/generators/qwik/src-generator.js +385 -0
- package/dist/src/generators/qwik/styles.d.ts +7 -0
- package/dist/src/generators/qwik/styles.js +90 -0
- package/dist/src/generators/react.js +5 -3
- package/dist/src/helpers/camel-case.d.ts +8 -0
- package/dist/src/helpers/camel-case.js +18 -0
- package/dist/src/helpers/collect-styles.js +5 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/parsers/builder.d.ts +1 -1
- package/dist/src/parsers/builder.js +4 -3
- package/dist/src/parsers/liquid.js +2 -1
- package/dist/src/plugins/compile-away-builder-components.d.ts +1 -1
- package/dist/src/plugins/compile-away-builder-components.js +317 -76
- package/dist/test/qwik/Accordion/high.jsx +1 -0
- package/dist/test/qwik/Accordion/low.jsx +92 -0
- package/dist/test/qwik/Accordion/med.jsx +9 -0
- package/dist/test/qwik/Image/high.js +1 -0
- package/dist/test/qwik/Image/low.js +68 -0
- package/dist/test/qwik/Image/med.js +9 -0
- package/dist/test/qwik/Image.slow/high.js +1 -0
- package/dist/test/qwik/Image.slow/low.js +68 -0
- package/dist/test/qwik/Image.slow/med.js +9 -0
- package/dist/test/qwik/Todo/Todo.cjs/high.cjs +31 -0
- package/dist/test/qwik/Todo/Todo.cjs/low.cjs +1 -0
- package/dist/test/qwik/Todo/Todo.cjs/med.cjs +59 -0
- package/dist/test/qwik/Todo/Todo.js/high.js +5 -0
- package/dist/test/qwik/Todo/Todo.js/low.js +0 -0
- package/dist/test/qwik/Todo/Todo.js/med.js +1 -0
- package/dist/test/qwik/Todo/Todo.tsx/high.tsx +30 -0
- package/dist/test/qwik/Todo/Todo.tsx/low.tsx +1 -0
- package/dist/test/qwik/Todo/Todo.tsx/med.tsx +34 -0
- package/dist/test/qwik/Todo.ts +2 -1
- package/dist/test/qwik/Todo_component.ts +4 -1
- package/dist/test/qwik/Todo_onButtonClick.ts +4 -1
- package/dist/test/qwik/Todo_onInput2Blur.ts +3 -0
- package/dist/test/qwik/Todo_onInput2KeyUp.ts +1 -4
- package/dist/test/qwik/Todo_onInputClick.ts +4 -1
- package/dist/test/qwik/Todo_onLabelDblClick.ts +4 -1
- package/dist/test/qwik/Todos/Todo.tsx/high.tsx +12 -0
- package/dist/test/qwik/Todos/Todo.tsx/low.tsx +24 -0
- package/dist/test/qwik/Todos/Todo.tsx/med.tsx +8 -0
- package/dist/test/qwik/button/high.js +8 -0
- package/dist/test/qwik/button/low.js +34 -0
- package/dist/test/qwik/button/med.js +9 -0
- package/dist/test/qwik/hello_world/stylesheet/high.jsx +1 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +24 -0
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +9 -0
- package/dist/test/qwik/page-with-symbol/high.js +1 -0
- package/dist/test/qwik/page-with-symbol/low.js +49 -0
- package/dist/test/qwik/page-with-symbol/med.js +9 -0
- package/dist/test/qwik/qwik/Image/high.js +1 -0
- package/dist/test/qwik/qwik/Image/low.js +75 -0
- package/dist/test/qwik/qwik/Image/med.js +9 -0
- package/dist/test/qwik/qwik/Image.slow/high.js +1 -0
- package/dist/test/qwik/qwik/Image.slow/low.js +75 -0
- package/dist/test/qwik/qwik/Image.slow/med.js +9 -0
- package/dist/test/qwik/qwik/button/high.js +8 -0
- package/dist/test/qwik/qwik/button/low.js +34 -0
- package/dist/test/qwik/qwik/button/med.js +9 -0
- package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +1 -0
- package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +24 -0
- package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +9 -0
- package/dist/test/qwik/qwik/page-with-symbol/high.js +1 -0
- package/dist/test/qwik/qwik/page-with-symbol/low.js +49 -0
- package/dist/test/qwik/qwik/page-with-symbol/med.js +9 -0
- package/dist/test/qwik/qwik/svg/high.js +1 -0
- package/dist/test/qwik/qwik/svg/low.js +30 -0
- package/dist/test/qwik/qwik/svg/med.js +9 -0
- package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +31 -0
- package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +1 -0
- package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +59 -0
- package/dist/test/qwik/qwik/todo/Todo.js/high.js +5 -0
- package/dist/test/qwik/qwik/todo/Todo.js/low.js +0 -0
- package/dist/test/qwik/qwik/todo/Todo.js/med.js +1 -0
- package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +30 -0
- package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +1 -0
- package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +34 -0
- package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +12 -0
- package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +24 -0
- package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +8 -0
- package/dist/test/qwik/svg/high.js +1 -0
- package/dist/test/qwik/svg/low.js +30 -0
- package/dist/test/qwik/svg/med.js +9 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
|
@@ -70,6 +70,7 @@ var html_1 = require("../generators/html");
|
|
|
70
70
|
var builder_2 = require("../parsers/builder");
|
|
71
71
|
var jsx_1 = require("../parsers/jsx");
|
|
72
72
|
var compile_away_builder_components_1 = require("../plugins/compile-away-builder-components");
|
|
73
|
+
var __1 = require("..");
|
|
73
74
|
/**
|
|
74
75
|
* Load a file using nodejs resolution as a string.
|
|
75
76
|
*/
|
|
@@ -152,7 +153,7 @@ describe('Builder', function () {
|
|
|
152
153
|
});
|
|
153
154
|
}); });
|
|
154
155
|
test('Regenerate Image', function () {
|
|
155
|
-
var code = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { useState } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"
|
|
156
|
+
var code = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { useState } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"https://cdn.builder.io/api/v1/image/foobar\"\n sizes=\"100vw\"\n backgroundSize=\"contain\"\n css={{\n marignTop: \"50px\",\n display: \"block\",\n }}\n />\n </div>\n );\n }\n "], ["\n import { useState } from \"@builder.io/mitosis\";\n import { Image } from \"@components\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <Image\n image=\"https://cdn.builder.io/api/v1/image/foobar\"\n sizes=\"100vw\"\n backgroundSize=\"contain\"\n css={{\n marignTop: \"50px\",\n display: \"block\",\n }}\n />\n </div>\n );\n }\n "])));
|
|
156
157
|
var json = jsx_1.parseJsx(code);
|
|
157
158
|
var builderJson = builder_1.componentToBuilder(json);
|
|
158
159
|
var backToMitosis = builder_2.builderContentToMitosisComponent(builderJson);
|
|
@@ -160,6 +161,10 @@ describe('Builder', function () {
|
|
|
160
161
|
format: 'legacy',
|
|
161
162
|
});
|
|
162
163
|
expect(mitosis.trim()).toEqual(code.trim());
|
|
164
|
+
var react = __1.componentToReact(json, {
|
|
165
|
+
plugins: [compile_away_builder_components_1.compileAwayBuilderComponents()],
|
|
166
|
+
});
|
|
167
|
+
expect(react).toMatchSnapshot();
|
|
163
168
|
});
|
|
164
169
|
test('Regenerate Text', function () {
|
|
165
170
|
var code = dedent_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n import { useState } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <h2\n css={{\n marginBottom: \"20px\",\n }}\n >\n Hello!\n </h2>\n </div>\n );\n }\n "], ["\n import { useState } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useState({ people: [\"Steve\", \"Sewell\"] });\n\n return (\n <div\n css={{\n padding: \"20px\",\n }}\n >\n <h2\n css={{\n marginBottom: \"20px\",\n }}\n >\n Hello!\n </h2>\n </div>\n );\n }\n "])));
|
|
@@ -37,26 +37,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var fs_extra_promise_1 = require("fs-extra-promise");
|
|
40
|
-
var
|
|
40
|
+
var __1 = require("..");
|
|
41
|
+
var index_1 = require("../generators/qwik/index");
|
|
41
42
|
var jsx_1 = require("../parsers/jsx");
|
|
43
|
+
var compile_away_builder_components_1 = require("../plugins/compile-away-builder-components");
|
|
42
44
|
var todo = require('../../../../examples/todo/src/components/todo.lite');
|
|
43
45
|
var todos = require('../../../../examples/todo/src/components/todos.lite');
|
|
44
46
|
var debugFiles = true;
|
|
45
|
-
var debugOutput = function (
|
|
46
|
-
var
|
|
47
|
-
return __generator(this, function (
|
|
48
|
-
switch (
|
|
47
|
+
var debugOutput = function (fileSet) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
+
var testName, base, _a, _b, _i, key, file;
|
|
49
|
+
return __generator(this, function (_c) {
|
|
50
|
+
switch (_c.label) {
|
|
49
51
|
case 0:
|
|
52
|
+
testName = expect.getState().currentTestName;
|
|
53
|
+
base = 'dist/test/' + testName.split(' ').join('/') + '/';
|
|
50
54
|
if (!debugFiles) return [3 /*break*/, 4];
|
|
51
|
-
|
|
52
|
-
_b
|
|
55
|
+
_a = [];
|
|
56
|
+
for (_b in fileSet)
|
|
57
|
+
_a.push(_b);
|
|
58
|
+
_i = 0;
|
|
59
|
+
_c.label = 1;
|
|
53
60
|
case 1:
|
|
54
61
|
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
key = _a[_i];
|
|
63
|
+
file = fileSet[key];
|
|
64
|
+
return [4 /*yield*/, fs_extra_promise_1.outputFileAsync(base + file.path, file.contents)];
|
|
57
65
|
case 2:
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
_c.sent();
|
|
67
|
+
_c.label = 3;
|
|
60
68
|
case 3:
|
|
61
69
|
_i++;
|
|
62
70
|
return [3 /*break*/, 1];
|
|
@@ -64,52 +72,160 @@ var debugOutput = function (output) { return __awaiter(void 0, void 0, void 0, f
|
|
|
64
72
|
}
|
|
65
73
|
});
|
|
66
74
|
}); };
|
|
67
|
-
describe('
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
describe('qwik', function () {
|
|
76
|
+
describe('todo', function () {
|
|
77
|
+
test('Todo.tsx', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
+
var json, fileSet;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
json = jsx_1.parseJsx(todo);
|
|
81
|
+
fileSet = index_1.createFileSet({ output: 'ts' });
|
|
82
|
+
index_1.addComponent(fileSet, json);
|
|
83
|
+
debugOutput(fileSet);
|
|
84
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
85
|
+
return [2 /*return*/];
|
|
86
|
+
});
|
|
87
|
+
}); });
|
|
88
|
+
test('Todo.cjs', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
89
|
+
var json, fileSet;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
json = jsx_1.parseJsx(todo);
|
|
92
|
+
fileSet = index_1.createFileSet({ output: 'cjs', jsx: false });
|
|
93
|
+
index_1.addComponent(fileSet, json);
|
|
94
|
+
debugOutput(fileSet);
|
|
95
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
});
|
|
98
|
+
}); });
|
|
99
|
+
test('Todo.js', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var json, fileSet;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
json = jsx_1.parseJsx(todo);
|
|
103
|
+
fileSet = index_1.createFileSet({
|
|
104
|
+
output: 'mjs',
|
|
105
|
+
minify: true,
|
|
106
|
+
jsx: false,
|
|
107
|
+
});
|
|
108
|
+
index_1.addComponent(fileSet, json);
|
|
109
|
+
debugOutput(fileSet);
|
|
110
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
});
|
|
113
|
+
}); });
|
|
114
|
+
});
|
|
115
|
+
describe('todos', function () {
|
|
116
|
+
test('Todo.tsx', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var json, fileSet;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
json = jsx_1.parseJsx(todos);
|
|
120
|
+
fileSet = index_1.createFileSet({ output: 'ts' });
|
|
121
|
+
index_1.addComponent(fileSet, json);
|
|
122
|
+
debugOutput(fileSet);
|
|
123
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
124
|
+
return [2 /*return*/];
|
|
125
|
+
});
|
|
126
|
+
}); });
|
|
127
|
+
});
|
|
128
|
+
describe('hello_world', function () {
|
|
129
|
+
test('stylesheet', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
130
|
+
var component, fileSet;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.hello_world.json'));
|
|
133
|
+
fileSet = index_1.createFileSet({ output: 'mjs' });
|
|
134
|
+
index_1.addComponent(fileSet, component);
|
|
135
|
+
debugOutput(fileSet);
|
|
136
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
137
|
+
return [2 /*return*/];
|
|
138
|
+
});
|
|
139
|
+
}); });
|
|
140
|
+
});
|
|
141
|
+
test('page-with-symbol', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
142
|
+
var component, fileSet;
|
|
70
143
|
return __generator(this, function (_a) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expect(output).toMatchSnapshot();
|
|
78
|
-
debugOutput(output);
|
|
79
|
-
return [2 /*return*/];
|
|
80
|
-
}
|
|
144
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.page-with-symbol.json'));
|
|
145
|
+
fileSet = index_1.createFileSet({ output: 'mjs', jsx: false });
|
|
146
|
+
index_1.addComponent(fileSet, component);
|
|
147
|
+
debugOutput(fileSet);
|
|
148
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
149
|
+
return [2 /*return*/];
|
|
81
150
|
});
|
|
82
151
|
}); });
|
|
83
|
-
test('
|
|
84
|
-
var
|
|
152
|
+
test('button', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
+
var component, fileSet;
|
|
85
154
|
return __generator(this, function (_a) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
case 1:
|
|
93
|
-
output = _a.sent();
|
|
94
|
-
expect(output).toMatchSnapshot();
|
|
95
|
-
debugOutput(output);
|
|
96
|
-
return [2 /*return*/];
|
|
97
|
-
}
|
|
155
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.button.json'));
|
|
156
|
+
fileSet = index_1.createFileSet({ output: 'mjs', jsx: false });
|
|
157
|
+
index_1.addComponent(fileSet, component);
|
|
158
|
+
debugOutput(fileSet);
|
|
159
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
160
|
+
return [2 /*return*/];
|
|
98
161
|
});
|
|
99
162
|
}); });
|
|
100
|
-
test('
|
|
101
|
-
var
|
|
163
|
+
test('svg', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
|
+
var component, fileSet;
|
|
102
165
|
return __generator(this, function (_a) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
166
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.svg.json'), {
|
|
167
|
+
includeBuilderExtras: true,
|
|
168
|
+
preserveTextBlocks: true,
|
|
169
|
+
});
|
|
170
|
+
fileSet = index_1.createFileSet({ output: 'mjs', jsx: false });
|
|
171
|
+
index_1.addComponent(fileSet, component);
|
|
172
|
+
debugOutput(fileSet);
|
|
173
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
174
|
+
return [2 /*return*/];
|
|
175
|
+
});
|
|
176
|
+
}); });
|
|
177
|
+
test('Image', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
178
|
+
var component, fileSet;
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.image.json'), {
|
|
181
|
+
includeBuilderExtras: true,
|
|
182
|
+
preserveTextBlocks: true,
|
|
183
|
+
});
|
|
184
|
+
fileSet = index_1.createFileSet({ output: 'mjs', jsx: false });
|
|
185
|
+
index_1.addComponent(fileSet, component);
|
|
186
|
+
debugOutput(fileSet);
|
|
187
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
188
|
+
return [2 /*return*/];
|
|
189
|
+
});
|
|
190
|
+
}); });
|
|
191
|
+
test('Image.slow', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
192
|
+
var component, fileSet;
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.image.json'), {
|
|
195
|
+
includeBuilderExtras: true,
|
|
196
|
+
preserveTextBlocks: true,
|
|
197
|
+
});
|
|
198
|
+
compile_away_builder_components_1.compileAwayBuilderComponentsFromTree(component, compile_away_builder_components_1.components);
|
|
199
|
+
fileSet = index_1.createFileSet({ output: 'mjs', jsx: false });
|
|
200
|
+
index_1.addComponent(fileSet, component);
|
|
201
|
+
debugOutput(fileSet);
|
|
202
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
203
|
+
return [2 /*return*/];
|
|
204
|
+
});
|
|
205
|
+
}); });
|
|
206
|
+
test('Accordion', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
207
|
+
var component, fileSet;
|
|
208
|
+
return __generator(this, function (_a) {
|
|
209
|
+
component = __1.builderContentToMitosisComponent(require('./qwik.test.accordion.json'), {
|
|
210
|
+
includeBuilderExtras: true,
|
|
211
|
+
preserveTextBlocks: true,
|
|
212
|
+
});
|
|
213
|
+
compile_away_builder_components_1.compileAwayBuilderComponentsFromTree(component, compile_away_builder_components_1.components);
|
|
214
|
+
fileSet = index_1.createFileSet({ output: 'mjs', jsx: true });
|
|
215
|
+
index_1.addComponent(fileSet, component);
|
|
216
|
+
debugOutput(fileSet);
|
|
217
|
+
expect(toObj(fileSet)).toMatchSnapshot();
|
|
218
|
+
return [2 /*return*/];
|
|
113
219
|
});
|
|
114
220
|
}); });
|
|
115
221
|
});
|
|
222
|
+
function toObj(fileSet) {
|
|
223
|
+
var obj = {};
|
|
224
|
+
for (var key in fileSet) {
|
|
225
|
+
if (Object.prototype.hasOwnProperty.call(fileSet, key)) {
|
|
226
|
+
var file = fileSet[key];
|
|
227
|
+
obj[file.path] = file.contents;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return obj;
|
|
231
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
|
+
import { File } from './src-generator';
|
|
3
|
+
export declare type QwikOptions = {
|
|
4
|
+
qwikLib?: string;
|
|
5
|
+
qrlPrefix?: string;
|
|
6
|
+
output?: 'ts' | 'cjs' | 'mjs';
|
|
7
|
+
jsx?: boolean;
|
|
8
|
+
minify?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export interface FileSet {
|
|
11
|
+
high: File;
|
|
12
|
+
med: File;
|
|
13
|
+
low: File;
|
|
14
|
+
}
|
|
15
|
+
export declare function createFileSet(options?: QwikOptions): FileSet;
|
|
16
|
+
export declare function addComponent(fileSet: FileSet, component: MitosisComponent, opts?: {
|
|
17
|
+
isRoot?: boolean;
|
|
18
|
+
shareStyles?: boolean;
|
|
19
|
+
}): void;
|
|
20
|
+
export declare function addCommonStyles(fileSet: FileSet): void;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.addCommonStyles = exports.addComponent = exports.createFileSet = void 0;
|
|
15
|
+
var compile_away_builder_components_1 = require("../../plugins/compile-away-builder-components");
|
|
16
|
+
var handlers_1 = require("./handlers");
|
|
17
|
+
var jsx_1 = require("./jsx");
|
|
18
|
+
var src_generator_1 = require("./src-generator");
|
|
19
|
+
var styles_1 = require("./styles");
|
|
20
|
+
function createFileSet(options) {
|
|
21
|
+
if (options === void 0) { options = {}; }
|
|
22
|
+
var opts = __assign({ qwikLib: '@builder.io/qwik', qrlPrefix: './', output: 'ts', minify: false, jsx: true }, options);
|
|
23
|
+
var extension = (opts.output == 'mjs' ? 'js' : opts.output) + (opts.jsx ? 'x' : '');
|
|
24
|
+
var srcOptions = {
|
|
25
|
+
isPretty: !opts.minify,
|
|
26
|
+
isModule: opts.output != 'cjs',
|
|
27
|
+
isTypeScript: opts.output == 'ts',
|
|
28
|
+
isJSX: opts.jsx,
|
|
29
|
+
};
|
|
30
|
+
var fileSet = {
|
|
31
|
+
high: new src_generator_1.File('high.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
32
|
+
med: new src_generator_1.File('med.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
33
|
+
low: new src_generator_1.File('low.' + extension, srcOptions, opts.qwikLib, opts.qrlPrefix),
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(fileSet, '_commonStyles', {
|
|
36
|
+
enumerable: false,
|
|
37
|
+
value: { styles: new Map(), symbolName: null },
|
|
38
|
+
});
|
|
39
|
+
return fileSet;
|
|
40
|
+
}
|
|
41
|
+
exports.createFileSet = createFileSet;
|
|
42
|
+
function getCommonStyles(fileSet) {
|
|
43
|
+
return fileSet['_commonStyles'];
|
|
44
|
+
}
|
|
45
|
+
function addComponent(fileSet, component, opts) {
|
|
46
|
+
if (opts === void 0) { opts = {}; }
|
|
47
|
+
var _opts = __assign({ isRoot: false, shareStyles: false }, opts);
|
|
48
|
+
compile_away_builder_components_1.compileAwayBuilderComponentsFromTree(component, compile_away_builder_components_1.components);
|
|
49
|
+
var componentName = component.name;
|
|
50
|
+
var handlers = handlers_1.renderHandlers(fileSet.high, componentName, component.children);
|
|
51
|
+
// If the component has no handlers, than it is probably static
|
|
52
|
+
// and so it is unlikely to be re-rendered on the client, therefore
|
|
53
|
+
// put it in a low priority bucket.
|
|
54
|
+
var isStatic = Array.from(handlers.keys()).reduce(function (p, v) { return p && v.indexOf('state') == -1; }, true);
|
|
55
|
+
var onRenderFile = isStatic ? fileSet.low : fileSet.med;
|
|
56
|
+
var componentFile = fileSet.med;
|
|
57
|
+
if (!componentFile.exports.get('onMountCreateEmptyState')) {
|
|
58
|
+
componentFile.exportConst('onMountCreateEmptyState', function () {
|
|
59
|
+
this.emit(src_generator_1.invoke(componentFile.import(componentFile.qwikModule, 'qHook'), [src_generator_1.arrowFnValue([], ['({})'])], ['any', 'any']));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (component.hooks.onMount) {
|
|
63
|
+
addComponentOnMount(componentFile, componentName, component);
|
|
64
|
+
}
|
|
65
|
+
var styles = _opts.shareStyles
|
|
66
|
+
? getCommonStyles(fileSet).styles
|
|
67
|
+
: new Map();
|
|
68
|
+
styles_1.collectStyles(component.children, styles);
|
|
69
|
+
var qComponentOptions = {
|
|
70
|
+
// tagName: string(componentName.toLowerCase()),
|
|
71
|
+
onMount: src_generator_1.invoke(componentFile.import(componentFile.qwikModule, 'qHook'), [
|
|
72
|
+
componentFile.toQrl(component.hooks.onMount
|
|
73
|
+
? componentName + '_onMount'
|
|
74
|
+
: 'onMountCreateEmptyState'),
|
|
75
|
+
]),
|
|
76
|
+
onRender: src_generator_1.invoke(componentFile.import(componentFile.qwikModule, 'qHook'), [
|
|
77
|
+
onRenderFile.toQrl(componentName + '_onRender'),
|
|
78
|
+
]),
|
|
79
|
+
};
|
|
80
|
+
if (_opts.shareStyles) {
|
|
81
|
+
if (_opts.isRoot) {
|
|
82
|
+
var symbolName = componentName + '_styles';
|
|
83
|
+
getCommonStyles(fileSet).symbolName = symbolName;
|
|
84
|
+
qComponentOptions.unscopedStyles = onRenderFile.toQrl(symbolName);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (styles.size) {
|
|
89
|
+
qComponentOptions.styles = onRenderFile.toQrl(componentName + '_styles');
|
|
90
|
+
onRenderFile.exportConst(componentName + '_styles', styles_1.renderStyles(styles));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
componentFile.exportConst(componentName, src_generator_1.invoke(componentFile.import(componentFile.qwikModule, 'qComponent'), [qComponentOptions], ['any', 'any']));
|
|
94
|
+
onRenderFile.src.emit(src_generator_1.NL);
|
|
95
|
+
onRenderFile.exportConst(componentName + '_onRender', src_generator_1.invoke(onRenderFile.import(onRenderFile.qwikModule, 'qHook'), [
|
|
96
|
+
src_generator_1.arrowFnValue(['props', 'state'], jsx_1.renderJSXNodes(onRenderFile, handlers, component.children, styles)),
|
|
97
|
+
]));
|
|
98
|
+
}
|
|
99
|
+
exports.addComponent = addComponent;
|
|
100
|
+
function addCommonStyles(fileSet) {
|
|
101
|
+
var _a = getCommonStyles(fileSet), styles = _a.styles, symbolName = _a.symbolName;
|
|
102
|
+
var onRenderFile = fileSet.low;
|
|
103
|
+
if (symbolName) {
|
|
104
|
+
onRenderFile.exportConst(symbolName, styles_1.renderStyles(styles));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.addCommonStyles = addCommonStyles;
|
|
108
|
+
function addComponentOnMount(componentFile, componentName, component) {
|
|
109
|
+
componentFile.exportConst(componentName + '_onMount', function () {
|
|
110
|
+
var _this = this;
|
|
111
|
+
this.emit(src_generator_1.invoke(componentFile.import(componentFile.qwikModule, 'qHook'), [
|
|
112
|
+
src_generator_1.arrowFnValue([], function () {
|
|
113
|
+
return _this.emit('{', src_generator_1.NL, src_generator_1.INDENT, 'const state = {};', src_generator_1.NL, component.hooks.onMount, src_generator_1.NL, 'return state;', src_generator_1.UNINDENT, src_generator_1.NL, '}');
|
|
114
|
+
}),
|
|
115
|
+
], ['any', 'any']));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIRECTIVES = void 0;
|
|
4
|
+
var src_generator_1 = require("./src-generator");
|
|
5
|
+
exports.DIRECTIVES = {
|
|
6
|
+
Show: function (node, blockFn) {
|
|
7
|
+
return function () {
|
|
8
|
+
var expr = node.bindings.when;
|
|
9
|
+
if (this.isJSX) {
|
|
10
|
+
this.emit('{', src_generator_1.WS, src_generator_1.INDENT, expr, src_generator_1.WS, '?', src_generator_1.NL);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.emit(expr, src_generator_1.WS, '?', src_generator_1.INDENT, src_generator_1.NL);
|
|
14
|
+
}
|
|
15
|
+
blockFn();
|
|
16
|
+
if (this.isJSX) {
|
|
17
|
+
this.emit(':', src_generator_1.WS, 'null', src_generator_1.UNINDENT, src_generator_1.NL, '}', src_generator_1.NL);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.emit(':', src_generator_1.WS, 'null', src_generator_1.UNINDENT, src_generator_1.NL);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
|
+
import { File } from './src-generator';
|
|
3
|
+
export declare function extractJSBlock(binding: any): string | null;
|
|
4
|
+
export declare function renderHandlers(file: File, componentName: string, children: MitosisNode[]): Map<string, string>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
3
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
4
|
+
to[j] = from[i];
|
|
5
|
+
return to;
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.renderHandlers = exports.extractJSBlock = void 0;
|
|
9
|
+
var src_generator_1 = require("./src-generator");
|
|
10
|
+
var IIF_START = '(() => {';
|
|
11
|
+
var IIF_END = '})()';
|
|
12
|
+
function extractJSBlock(binding) {
|
|
13
|
+
if (typeof binding == 'string') {
|
|
14
|
+
if (binding.startsWith('{') &&
|
|
15
|
+
binding.endsWith('}') &&
|
|
16
|
+
!binding.startsWith('{"') &&
|
|
17
|
+
!binding.endsWith('"}')) {
|
|
18
|
+
return binding.substring(1, binding.length - 2);
|
|
19
|
+
}
|
|
20
|
+
else if (binding.startsWith(IIF_START) && binding.endsWith(IIF_END)) {
|
|
21
|
+
return binding.substring(IIF_START.length, binding.length - IIF_END.length - 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
exports.extractJSBlock = extractJSBlock;
|
|
27
|
+
function renderHandlers(file, componentName, children) {
|
|
28
|
+
var id = 0;
|
|
29
|
+
var map = new Map();
|
|
30
|
+
var nodes = __spreadArray([], children);
|
|
31
|
+
while (nodes.length) {
|
|
32
|
+
var node = nodes.shift();
|
|
33
|
+
var bindings = node.bindings;
|
|
34
|
+
for (var key in bindings) {
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(bindings, key)) {
|
|
36
|
+
var binding = bindings[key];
|
|
37
|
+
if (binding != null) {
|
|
38
|
+
if (key.startsWith('on')) {
|
|
39
|
+
var block = extractJSBlock(binding) || binding;
|
|
40
|
+
var symbol = componentName + "_" + key + "_" + id++;
|
|
41
|
+
map.set(binding, symbol);
|
|
42
|
+
renderHandler(file, symbol, block);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
nodes.push.apply(nodes, node.children);
|
|
48
|
+
}
|
|
49
|
+
return map;
|
|
50
|
+
}
|
|
51
|
+
exports.renderHandlers = renderHandlers;
|
|
52
|
+
function renderHandler(file, symbol, code) {
|
|
53
|
+
file.exportConst(symbol, function () {
|
|
54
|
+
this.emit(src_generator_1.invoke(file.import(file.qwikModule, 'qHook'), [src_generator_1.arrowFnBlock(['props', 'state'], [wrapWithUse(file, code)])], ['any', 'any']));
|
|
55
|
+
});
|
|
56
|
+
file.src.emit(src_generator_1.NL);
|
|
57
|
+
}
|
|
58
|
+
function wrapWithUse(file, code) {
|
|
59
|
+
var needsEvent = !!code.match(/\bevent\b/);
|
|
60
|
+
if (needsEvent) {
|
|
61
|
+
return function () {
|
|
62
|
+
this.emit('{', src_generator_1.NL, src_generator_1.INDENT);
|
|
63
|
+
needsEvent &&
|
|
64
|
+
this.emit('const event', src_generator_1.WS, '=', src_generator_1.WS, src_generator_1.invoke(file.import(file.qwikModule, 'useEvent'), []), ';', src_generator_1.NL);
|
|
65
|
+
var blockContent = stripBlock(code);
|
|
66
|
+
this.emit(blockContent);
|
|
67
|
+
this.emit(src_generator_1.UNINDENT, src_generator_1.NL, '}');
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return code;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function stripBlock(block) {
|
|
75
|
+
return block.substring(1, block.length - 1).trim();
|
|
76
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.File = exports.createFileSet = exports.addComponent = exports.addCommonStyles = void 0;
|
|
4
|
+
var component_1 = require("./component");
|
|
5
|
+
Object.defineProperty(exports, "addCommonStyles", { enumerable: true, get: function () { return component_1.addCommonStyles; } });
|
|
6
|
+
Object.defineProperty(exports, "addComponent", { enumerable: true, get: function () { return component_1.addComponent; } });
|
|
7
|
+
Object.defineProperty(exports, "createFileSet", { enumerable: true, get: function () { return component_1.createFileSet; } });
|
|
8
|
+
var src_generator_1 = require("./src-generator");
|
|
9
|
+
Object.defineProperty(exports, "File", { enumerable: true, get: function () { return src_generator_1.File; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
|
+
import { File } from './src-generator';
|
|
3
|
+
import { CssStyles } from './styles';
|
|
4
|
+
export declare function renderJSXNodes(file: File, handlers: Map<string, string>, children: MitosisNode[], styles: Map<string, CssStyles>, root?: boolean): any;
|