@builder.io/mitosis 0.0.45 → 0.0.46

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.
Files changed (206) hide show
  1. package/dist/src/__tests__/builder.test.js +71 -68
  2. package/dist/src/__tests__/context.test.js +13 -10
  3. package/dist/src/__tests__/data/basic.raw.jsx +1 -1
  4. package/dist/src/__tests__/data/blocks/button-with-metadata.raw.jsx +1 -1
  5. package/dist/src/__tests__/data/blocks/columns.raw.jsx +2 -2
  6. package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -3
  7. package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -3
  8. package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
  9. package/dist/src/__tests__/data/blocks/image.raw.jsx +4 -4
  10. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -4
  11. package/dist/src/__tests__/data/context/component-with-context.lite.jsx +2 -2
  12. package/dist/src/__tests__/data/context/simple.context.lite.js +1 -1
  13. package/dist/src/__tests__/html.test.js +2 -2
  14. package/dist/src/__tests__/liquid.test.js +34 -34
  15. package/dist/src/__tests__/parse-jsx.test.js +1 -1
  16. package/dist/src/__tests__/qwik.test.js +36 -36
  17. package/dist/src/__tests__/react-native.test.js +35 -35
  18. package/dist/src/__tests__/react.test.js +35 -35
  19. package/dist/src/__tests__/solid.test.js +32 -32
  20. package/dist/src/__tests__/vue.test.js +35 -34
  21. package/dist/src/generators/angular.d.ts +4 -7
  22. package/dist/src/generators/angular.js +77 -81
  23. package/dist/src/generators/builder.d.ts +4 -4
  24. package/dist/src/generators/builder.js +57 -57
  25. package/dist/src/generators/context/react.d.ts +3 -1
  26. package/dist/src/generators/context/react.js +20 -17
  27. package/dist/src/generators/html.d.ts +5 -9
  28. package/dist/src/generators/html.js +205 -199
  29. package/dist/src/generators/liquid.d.ts +5 -9
  30. package/dist/src/generators/liquid.js +62 -59
  31. package/dist/src/generators/mitosis.d.ts +6 -7
  32. package/dist/src/generators/mitosis.js +61 -63
  33. package/dist/src/generators/qwik/component.js +13 -13
  34. package/dist/src/generators/qwik/handlers.js +12 -8
  35. package/dist/src/generators/qwik/jsx.js +13 -9
  36. package/dist/src/generators/qwik/styles.js +11 -7
  37. package/dist/src/generators/react-native.d.ts +4 -7
  38. package/dist/src/generators/react-native.js +25 -22
  39. package/dist/src/generators/react.d.ts +4 -8
  40. package/dist/src/generators/react.js +103 -112
  41. package/dist/src/generators/solid.d.ts +4 -8
  42. package/dist/src/generators/solid.js +55 -54
  43. package/dist/src/generators/svelte.d.ts +4 -7
  44. package/dist/src/generators/svelte.js +120 -123
  45. package/dist/src/generators/swift-ui.d.ts +2 -2
  46. package/dist/src/generators/swift-ui.js +62 -62
  47. package/dist/src/generators/template.d.ts +4 -8
  48. package/dist/src/generators/template.js +48 -45
  49. package/dist/src/generators/vue.d.ts +9 -9
  50. package/dist/src/generators/vue.js +169 -169
  51. package/dist/src/helpers/babel-transform.js +9 -9
  52. package/dist/src/helpers/collect-styles.js +39 -39
  53. package/dist/src/helpers/dash-case.js +1 -1
  54. package/dist/src/helpers/generic-format.test.js +2 -2
  55. package/dist/src/helpers/get-components-used.js +2 -2
  56. package/dist/src/helpers/get-components.js +3 -3
  57. package/dist/src/helpers/get-props.js +1 -1
  58. package/dist/src/helpers/get-refs.js +2 -2
  59. package/dist/src/helpers/get-state-object-string.js +5 -5
  60. package/dist/src/helpers/get-state-used.js +1 -1
  61. package/dist/src/helpers/get-styles.js +1 -1
  62. package/dist/src/helpers/getters-to-functions.js +4 -4
  63. package/dist/src/helpers/handle-missing-state.js +1 -1
  64. package/dist/src/helpers/has-component.js +2 -2
  65. package/dist/src/helpers/has-props.js +1 -1
  66. package/dist/src/helpers/is-children.js +1 -1
  67. package/dist/src/helpers/json.d.ts +1 -0
  68. package/dist/src/helpers/json.js +17 -0
  69. package/dist/src/helpers/map-refs.js +4 -4
  70. package/dist/src/helpers/map-to-attributes.js +4 -4
  71. package/dist/src/helpers/map-to-css.js +2 -2
  72. package/dist/src/helpers/parse-node.js +2 -2
  73. package/dist/src/helpers/parse-reactive-script.js +4 -4
  74. package/dist/src/helpers/process-http-requests.js +1 -1
  75. package/dist/src/helpers/process-tag-references.js +4 -4
  76. package/dist/src/helpers/remove-surrounding-block.test.js +1 -1
  77. package/dist/src/helpers/render-imports.js +7 -7
  78. package/dist/src/helpers/replace-idenifiers.js +1 -1
  79. package/dist/src/helpers/strip-meta-properties.js +2 -2
  80. package/dist/src/helpers/trace-reference-to-module-path.js +1 -1
  81. package/dist/src/helpers/traverse-nodes.js +2 -2
  82. package/dist/src/helpers/try-prettier-format.js +1 -1
  83. package/dist/src/index.d.ts +2 -0
  84. package/dist/src/index.js +2 -0
  85. package/dist/src/modules/plugins.d.ts +2 -10
  86. package/dist/src/parsers/angular.js +13 -13
  87. package/dist/src/parsers/builder.js +54 -58
  88. package/dist/src/parsers/context.js +2 -2
  89. package/dist/src/parsers/jsx.js +59 -87
  90. package/dist/src/parsers/liquid.js +191 -194
  91. package/dist/src/plugins/compile-away-builder-components.js +49 -45
  92. package/dist/src/plugins/compile-away-components.js +3 -3
  93. package/dist/src/plugins/map-styles.js +3 -3
  94. package/dist/src/targets.d.ts +24 -0
  95. package/dist/src/targets.js +30 -0
  96. package/dist/src/types/config.d.ts +31 -0
  97. package/dist/src/types/{jsx-lite-component.js → config.js} +0 -0
  98. package/dist/{test/qwik/Todo/Todo.js/low.js → src/types/generators.d.ts} +0 -0
  99. package/dist/src/types/generators.js +1 -0
  100. package/dist/src/types/plugins.d.ts +11 -0
  101. package/dist/src/types/{jsx-lite-context.js → plugins.js} +0 -0
  102. package/dist/test/qwik/{Todo → todo}/Todo.cjs/high.cjs +0 -0
  103. package/dist/test/qwik/{Todo → todo}/Todo.cjs/low.cjs +0 -0
  104. package/dist/test/qwik/{Todo → todo}/Todo.cjs/med.cjs +0 -0
  105. package/dist/test/qwik/{Todo → todo}/Todo.js/high.js +0 -0
  106. package/dist/test/qwik/{qwik/todo → todo}/Todo.js/low.js +0 -0
  107. package/dist/test/qwik/{Todo → todo}/Todo.js/med.js +0 -0
  108. package/dist/test/qwik/{Todo → todo}/Todo.tsx/high.tsx +0 -0
  109. package/dist/test/qwik/{Todo → todo}/Todo.tsx/low.tsx +0 -0
  110. package/dist/test/qwik/{Todo → todo}/Todo.tsx/med.tsx +0 -0
  111. package/dist/test/qwik/{Todos → todos}/Todo.tsx/high.tsx +0 -0
  112. package/dist/test/qwik/{Todos → todos}/Todo.tsx/low.tsx +0 -0
  113. package/dist/test/qwik/{Todos → todos}/Todo.tsx/med.tsx +0 -0
  114. package/dist/tsconfig.tsbuildinfo +1 -1
  115. package/package.json +2 -2
  116. package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +0 -11
  117. package/dist/src/__tests__/data/blocks/tabs.raw.jsx +0 -24
  118. package/dist/src/__tests__/qoot.test.d.ts +0 -1
  119. package/dist/src/__tests__/qoot.test.js +0 -115
  120. package/dist/src/generators/jsx-lite.d.ts +0 -10
  121. package/dist/src/generators/jsx-lite.js +0 -176
  122. package/dist/src/generators/qoot.d.ts +0 -21
  123. package/dist/src/generators/qoot.js +0 -442
  124. package/dist/src/generators/qwik.d.ts +0 -21
  125. package/dist/src/generators/qwik.js +0 -458
  126. package/dist/src/helpers/create-jsx-lite-component.d.ts +0 -2
  127. package/dist/src/helpers/create-jsx-lite-component.js +0 -16
  128. package/dist/src/helpers/create-jsx-lite-context.d.ts +0 -4
  129. package/dist/src/helpers/create-jsx-lite-context.js +0 -18
  130. package/dist/src/helpers/create-jsx-lite-node.d.ts +0 -2
  131. package/dist/src/helpers/create-jsx-lite-node.js +0 -16
  132. package/dist/src/helpers/is-jsx-lite-node.d.ts +0 -2
  133. package/dist/src/helpers/is-jsx-lite-node.js +0 -7
  134. package/dist/src/types/jsx-lite-component.d.ts +0 -63
  135. package/dist/src/types/jsx-lite-context.d.ts +0 -6
  136. package/dist/src/types/jsx-lite-node.d.ts +0 -13
  137. package/dist/src/types/jsx-lite-node.js +0 -2
  138. package/dist/src/types/jsx-lite-styles.d.ts +0 -1
  139. package/dist/src/types/jsx-lite-styles.js +0 -2
  140. package/dist/test/qoot/Todo/bundle.js +0 -88
  141. package/dist/test/qoot/Todo/component.ts +0 -17
  142. package/dist/test/qoot/Todo/onButtonClick.ts +0 -13
  143. package/dist/test/qoot/Todo/onInput2Blur.ts +0 -11
  144. package/dist/test/qoot/Todo/onInput2KeyUp.ts +0 -10
  145. package/dist/test/qoot/Todo/onInputClick.ts +0 -10
  146. package/dist/test/qoot/Todo/onLabelDblClick.ts +0 -11
  147. package/dist/test/qoot/Todo/public.ts +0 -4
  148. package/dist/test/qoot/Todo/template.tsx +0 -46
  149. package/dist/test/qoot/Todos/component.ts +0 -9
  150. package/dist/test/qoot/Todos/onInputClick.ts +0 -14
  151. package/dist/test/qoot/Todos/public.ts +0 -3
  152. package/dist/test/qoot/Todos/template.tsx +0 -30
  153. package/dist/test/qwik/Todo/bundle.js +0 -46
  154. package/dist/test/qwik/Todo/component.ts +0 -17
  155. package/dist/test/qwik/Todo/onButtonClick.ts +0 -10
  156. package/dist/test/qwik/Todo/onInput2Blur.ts +0 -14
  157. package/dist/test/qwik/Todo/onInput2KeyUp.ts +0 -10
  158. package/dist/test/qwik/Todo/onInputClick.ts +0 -13
  159. package/dist/test/qwik/Todo/onLabelDblClick.ts +0 -11
  160. package/dist/test/qwik/Todo/public.ts +0 -3
  161. package/dist/test/qwik/Todo/template.tsx +0 -46
  162. package/dist/test/qwik/Todo.ts +0 -4
  163. package/dist/test/qwik/Todo_component.ts +0 -17
  164. package/dist/test/qwik/Todo_onButtonClick.ts +0 -13
  165. package/dist/test/qwik/Todo_onInput2Blur.ts +0 -14
  166. package/dist/test/qwik/Todo_onInput2KeyUp.ts +0 -10
  167. package/dist/test/qwik/Todo_onInputClick.ts +0 -13
  168. package/dist/test/qwik/Todo_onLabelDblClick.ts +0 -14
  169. package/dist/test/qwik/Todo_template.tsx +0 -46
  170. package/dist/test/qwik/Todos/component.ts +0 -9
  171. package/dist/test/qwik/Todos/onInputClick.ts +0 -14
  172. package/dist/test/qwik/Todos/public.ts +0 -3
  173. package/dist/test/qwik/Todos/template.tsx +0 -30
  174. package/dist/test/qwik/Todos.ts +0 -3
  175. package/dist/test/qwik/Todos_component.ts +0 -9
  176. package/dist/test/qwik/Todos_onInputClick.ts +0 -14
  177. package/dist/test/qwik/Todos_template.tsx +0 -30
  178. package/dist/test/qwik/qwik/Image/high.js +0 -1
  179. package/dist/test/qwik/qwik/Image/low.js +0 -75
  180. package/dist/test/qwik/qwik/Image/med.js +0 -9
  181. package/dist/test/qwik/qwik/Image.slow/high.js +0 -1
  182. package/dist/test/qwik/qwik/Image.slow/low.js +0 -75
  183. package/dist/test/qwik/qwik/Image.slow/med.js +0 -9
  184. package/dist/test/qwik/qwik/button/high.js +0 -8
  185. package/dist/test/qwik/qwik/button/low.js +0 -34
  186. package/dist/test/qwik/qwik/button/med.js +0 -9
  187. package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +0 -1
  188. package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +0 -24
  189. package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +0 -9
  190. package/dist/test/qwik/qwik/page-with-symbol/high.js +0 -1
  191. package/dist/test/qwik/qwik/page-with-symbol/low.js +0 -49
  192. package/dist/test/qwik/qwik/page-with-symbol/med.js +0 -9
  193. package/dist/test/qwik/qwik/svg/high.js +0 -1
  194. package/dist/test/qwik/qwik/svg/low.js +0 -30
  195. package/dist/test/qwik/qwik/svg/med.js +0 -9
  196. package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +0 -31
  197. package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +0 -1
  198. package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +0 -59
  199. package/dist/test/qwik/qwik/todo/Todo.js/high.js +0 -5
  200. package/dist/test/qwik/qwik/todo/Todo.js/med.js +0 -1
  201. package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +0 -30
  202. package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +0 -1
  203. package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +0 -34
  204. package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +0 -12
  205. package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +0 -24
  206. package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +0 -8
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var fs_extra_promise_1 = require("fs-extra-promise");
40
- var qoot_1 = require("../generators/qoot");
41
- var jsx_1 = require("../parsers/jsx");
42
- var todo = require('../../../../examples/todo/src/components/todo.lite');
43
- var todos = require('../../../../examples/todo/src/components/todos.lite');
44
- var debugFiles = true;
45
- var debugOutput = function (output) { return __awaiter(void 0, void 0, void 0, function () {
46
- var _i, _a, file;
47
- return __generator(this, function (_b) {
48
- switch (_b.label) {
49
- case 0:
50
- if (!debugFiles) return [3 /*break*/, 4];
51
- _i = 0, _a = output.files;
52
- _b.label = 1;
53
- case 1:
54
- if (!(_i < _a.length)) return [3 /*break*/, 4];
55
- file = _a[_i];
56
- return [4 /*yield*/, fs_extra_promise_1.outputFileAsync('dist/test/qoot/' + file.path, file.contents)];
57
- case 2:
58
- _b.sent();
59
- _b.label = 3;
60
- case 3:
61
- _i++;
62
- return [3 /*break*/, 1];
63
- case 4: return [2 /*return*/];
64
- }
65
- });
66
- }); };
67
- describe('Qoot', function () {
68
- test('Todo', function () { return __awaiter(void 0, void 0, void 0, function () {
69
- var json, output;
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
72
- case 0:
73
- json = jsx_1.parseJsx(todo);
74
- return [4 /*yield*/, qoot_1.componentToQoot(json)];
75
- case 1:
76
- output = _a.sent();
77
- expect(output).toMatchSnapshot();
78
- debugOutput(output);
79
- return [2 /*return*/];
80
- }
81
- });
82
- }); });
83
- test('Todo bundle', function () { return __awaiter(void 0, void 0, void 0, function () {
84
- var json, output;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
87
- case 0:
88
- json = jsx_1.parseJsx(todo);
89
- return [4 /*yield*/, qoot_1.componentToQoot(json, {
90
- bundle: true,
91
- })];
92
- case 1:
93
- output = _a.sent();
94
- expect(output).toMatchSnapshot();
95
- debugOutput(output);
96
- return [2 /*return*/];
97
- }
98
- });
99
- }); });
100
- test('Todos', function () { return __awaiter(void 0, void 0, void 0, function () {
101
- var json, output;
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0:
105
- json = jsx_1.parseJsx(todos);
106
- return [4 /*yield*/, qoot_1.componentToQoot(json)];
107
- case 1:
108
- output = _a.sent();
109
- expect(output).toMatchSnapshot();
110
- debugOutput(output);
111
- return [2 /*return*/];
112
- }
113
- });
114
- }); });
115
- });
@@ -1,10 +0,0 @@
1
- import { JSXLiteComponent } from '../types/jsx-lite-component';
2
- import { JSXLiteNode } from '../types/jsx-lite-node';
3
- export declare const DEFAULT_FORMAT = "legacy";
4
- export declare type JsxLiteFormat = 'react' | 'legacy';
5
- export declare type ToJsxLiteOptions = {
6
- prettier?: boolean;
7
- format: JsxLiteFormat;
8
- };
9
- export declare const blockToJsxLite: (json: JSXLiteNode, toJsxLiteOptions?: Partial<ToJsxLiteOptions>) => string;
10
- export declare const componentToJsxLite: (componentJson: JSXLiteComponent, toJsxLiteOptions?: Partial<ToJsxLiteOptions>) => string;
@@ -1,176 +0,0 @@
1
- "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
- var __assign = (this && this.__assign) || function () {
7
- __assign = Object.assign || function(t) {
8
- for (var s, i = 1, n = arguments.length; i < n; i++) {
9
- s = arguments[i];
10
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
- t[p] = s[p];
12
- }
13
- return t;
14
- };
15
- return __assign.apply(this, arguments);
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.componentToJsxLite = exports.blockToJsxLite = exports.DEFAULT_FORMAT = void 0;
22
- var dedent_1 = __importDefault(require("dedent"));
23
- var json5_1 = __importDefault(require("json5"));
24
- var standalone_1 = require("prettier/standalone");
25
- var fast_clone_1 = require("../helpers/fast-clone");
26
- var get_components_1 = require("../helpers/get-components");
27
- var get_refs_1 = require("../helpers/get-refs");
28
- var get_state_object_string_1 = require("../helpers/get-state-object-string");
29
- var map_refs_1 = require("../helpers/map-refs");
30
- var render_imports_1 = require("../helpers/render-imports");
31
- var jsx_1 = require("../parsers/jsx");
32
- var react_1 = require("./react");
33
- exports.DEFAULT_FORMAT = 'legacy';
34
- // Special isValidAttributeName for JSX Lite so we can allow for $ in names
35
- var isValidAttributeName = function (str) {
36
- return Boolean(str && /^[$a-z0-9\-_:]+$/i.test(str));
37
- };
38
- var blockToJsxLite = function (json, toJsxLiteOptions) {
39
- if (toJsxLiteOptions === void 0) { toJsxLiteOptions = {}; }
40
- var options = __assign({ format: exports.DEFAULT_FORMAT }, toJsxLiteOptions);
41
- if (options.format === 'react') {
42
- return react_1.blockToReact(json, {
43
- format: 'lite',
44
- stateType: 'useState',
45
- stylesType: 'emotion',
46
- prettier: options.prettier,
47
- });
48
- }
49
- if (json.name === 'For') {
50
- var needsWrapper = json.children.length !== 1;
51
- return "<For each={" + json.bindings.each + "}>\n {(" + json.properties._forName + ", index) =>\n " + (needsWrapper ? '<>' : '') + "\n " + json.children.map(function (child) { return exports.blockToJsxLite(child, options); }) + "}\n " + (needsWrapper ? '</>' : '') + "\n </For>";
52
- }
53
- if (json.properties._text) {
54
- return json.properties._text;
55
- }
56
- if (json.bindings._text) {
57
- return "{" + json.bindings._text + "}";
58
- }
59
- var str = '';
60
- str += "<" + json.name + " ";
61
- if (json.bindings._spread) {
62
- str += " {...(" + json.bindings._spread + ")} ";
63
- }
64
- for (var key in json.properties) {
65
- var value = (json.properties[key] || '')
66
- .replace(/"/g, '&quot;')
67
- .replace(/\n/g, '\\n');
68
- if (!isValidAttributeName(key)) {
69
- console.warn('Skipping invalid attribute name:', key);
70
- }
71
- else {
72
- str += " " + key + "=\"" + value + "\" ";
73
- }
74
- }
75
- for (var key in json.bindings) {
76
- var value = json.bindings[key];
77
- if (key === '_spread') {
78
- continue;
79
- }
80
- if (key.startsWith('on')) {
81
- str += " " + key + "={event => " + value.replace(/\s*;$/, '') + "} ";
82
- }
83
- else {
84
- if (!isValidAttributeName(key)) {
85
- console.warn('Skipping invalid attribute name:', key);
86
- }
87
- else {
88
- str += " " + key + "={" + value + "} ";
89
- }
90
- }
91
- }
92
- if (jsx_1.selfClosingTags.has(json.name)) {
93
- return str + ' />';
94
- }
95
- // Self close by default if no children
96
- if (!json.children.length) {
97
- str += ' />';
98
- return str;
99
- }
100
- str += '>';
101
- if (json.children) {
102
- str += json.children
103
- .map(function (item) { return exports.blockToJsxLite(item, options); })
104
- .join('\n');
105
- }
106
- str += "</" + json.name + ">";
107
- return str;
108
- };
109
- exports.blockToJsxLite = blockToJsxLite;
110
- var getRefsString = function (json, refs) {
111
- if (refs === void 0) { refs = get_refs_1.getRefs(json); }
112
- var str = '';
113
- for (var _i = 0, _a = Array.from(refs); _i < _a.length; _i++) {
114
- var ref = _a[_i];
115
- str += "\nconst " + ref + " = useRef();";
116
- }
117
- return str;
118
- };
119
- var jsxLiteCoreComponents = ['Show', 'For'];
120
- var componentToJsxLite = function (componentJson, toJsxLiteOptions) {
121
- if (toJsxLiteOptions === void 0) { toJsxLiteOptions = {}; }
122
- var options = __assign({ format: exports.DEFAULT_FORMAT }, toJsxLiteOptions);
123
- if (options.format === 'react') {
124
- return react_1.componentToReact(componentJson, {
125
- format: 'lite',
126
- stateType: 'useState',
127
- stylesType: 'emotion',
128
- prettier: options.prettier,
129
- });
130
- }
131
- var json = fast_clone_1.fastClone(componentJson);
132
- var refs = get_refs_1.getRefs(json);
133
- map_refs_1.mapRefs(json, function (refName) { return refName + ".current"; });
134
- var addWrapper = json.children.length !== 1;
135
- var components = Array.from(get_components_1.getComponents(json));
136
- var jsxLiteComponents = components.filter(function (item) {
137
- return jsxLiteCoreComponents.includes(item);
138
- });
139
- var otherComponents = components.filter(function (item) { return !jsxLiteCoreComponents.includes(item); });
140
- var hasState = Boolean(Object.keys(componentJson.state).length);
141
- var needsJsxLiteCoreImport = Boolean(hasState || refs.size || jsxLiteComponents.length);
142
- // TODO: smart only pull in imports as needed
143
- var str = dedent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n\n ", "\n\n export default function ", "(props) {\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "], ["\n ",
144
- "\n ",
145
- "\n ", "\n\n ",
146
- "\n\n export default function ", "(props) {\n ",
147
- "\n ", "\n\n ", "\n\n ",
148
- "\n\n return (", "\n ", "\n ", ")\n }\n\n "])), !needsJsxLiteCoreImport
149
- ? ''
150
- : "import { " + (!hasState ? '' : 'useState, ') + " " + (!refs.size ? '' : 'useRef, ') + " " + jsxLiteComponents.join(', ') + " } from '@jsx-lite/core';", !otherComponents.length
151
- ? ''
152
- : "import { " + otherComponents.join(',') + " } from '@components';", render_imports_1.renderPreComponent(json), !componentJson.meta.metadataHook
153
- ? ''
154
- : jsx_1.METADATA_HOOK_NAME + "(" + json5_1.default.stringify(componentJson.meta.metadataHook) + ")", componentJson.name, !hasState
155
- ? ''
156
- : "const state = useState(" + get_state_object_string_1.getStateObjectStringFromComponent(json) + ");", getRefsString(json), !json.hooks.onMount ? '' : "onMount(() => { " + json.hooks.onMount + " })", !json.hooks.onUnMount
157
- ? ''
158
- : "onUnMount(() => { " + json.hooks.onUnMount + " })", addWrapper ? '<>' : '', json.children.map(function (item) { return exports.blockToJsxLite(item, options); }).join('\n'), addWrapper ? '</>' : '');
159
- if (options.prettier !== false) {
160
- try {
161
- str = standalone_1.format(str, {
162
- parser: 'typescript',
163
- plugins: [
164
- require('prettier/parser-typescript'), // To support running in browsers
165
- ],
166
- });
167
- }
168
- catch (err) {
169
- console.error('Format error for file:', str, JSON.stringify(json, null, 2));
170
- throw err;
171
- }
172
- }
173
- return str;
174
- };
175
- exports.componentToJsxLite = componentToJsxLite;
176
- var templateObject_1;
@@ -1,21 +0,0 @@
1
- import { Plugin } from '../modules/plugins';
2
- import { JSXLiteComponent } from '../types/jsx-lite-component';
3
- declare type ToQootOptions = {
4
- prettier?: boolean;
5
- plugins?: Plugin[];
6
- qootLib?: string;
7
- qrlPrefix?: string;
8
- cssNamespace?: string;
9
- minifyStyles?: boolean;
10
- qrlSuffix?: string;
11
- bundle?: boolean;
12
- format?: 'builder' | 'default';
13
- };
14
- export declare type File = {
15
- path: string;
16
- contents: string;
17
- };
18
- export declare const componentToQoot: (componentJson: JSXLiteComponent, toQootOptions?: ToQootOptions) => Promise<{
19
- files: File[];
20
- }>;
21
- export {};