@builder.io/mitosis 0.0.50-6 → 0.0.50

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 (138) hide show
  1. package/dist/src/__tests__/angular.test.js +6 -0
  2. package/dist/src/__tests__/builder.test.js +5 -1
  3. package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.d.ts +1 -0
  4. package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.jsx +13 -0
  5. package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.d.ts +1 -0
  6. package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +19 -0
  7. package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +6 -3
  8. package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.d.ts +1 -0
  9. package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.jsx +15 -0
  10. package/dist/src/__tests__/data/blocks/self-referencing-component.raw.d.ts +1 -0
  11. package/dist/src/__tests__/data/blocks/self-referencing-component.raw.jsx +12 -0
  12. package/dist/src/__tests__/data/blocks/shadow-dom.raw.d.ts +6 -0
  13. package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +54 -0
  14. package/dist/src/__tests__/data/blocks/slot.raw.d.ts +5 -0
  15. package/dist/src/__tests__/data/blocks/slot.raw.jsx +6 -0
  16. package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +8 -0
  17. package/dist/src/__tests__/data/blocks/styles.raw.d.ts +1 -0
  18. package/dist/src/__tests__/data/blocks/styles.raw.jsx +10 -0
  19. package/dist/src/__tests__/data/context/simple.context.lite.d.ts +8 -1
  20. package/dist/src/__tests__/html.test.js +6 -0
  21. package/dist/src/__tests__/qwik.directive.test.d.ts +1 -0
  22. package/dist/src/__tests__/qwik.directive.test.js +107 -0
  23. package/dist/src/__tests__/qwik.test.js +256 -128
  24. package/dist/src/__tests__/react-native.test.js +12 -0
  25. package/dist/src/__tests__/react.test.js +12 -0
  26. package/dist/src/__tests__/svelte.test.js +24 -0
  27. package/dist/src/__tests__/vue.test.js +12 -0
  28. package/dist/src/__tests__/webcomponent.test.d.ts +1 -0
  29. package/dist/src/__tests__/webcomponent.test.js +12 -0
  30. package/dist/src/constants/html_tags.d.ts +1 -0
  31. package/dist/src/constants/html_tags.js +119 -0
  32. package/dist/src/generators/angular.js +7 -4
  33. package/dist/src/generators/context/react copy.d.ts +8 -0
  34. package/dist/src/generators/context/react copy.js +28 -0
  35. package/dist/src/generators/context/solid.d.ts +8 -0
  36. package/dist/src/generators/context/solid.js +28 -0
  37. package/dist/src/generators/context/svelte.d.ts +8 -0
  38. package/dist/src/generators/context/svelte.js +28 -0
  39. package/dist/src/generators/helpers/context.d.ts +2 -0
  40. package/dist/src/generators/helpers/context.js +8 -0
  41. package/dist/src/generators/html.js +20 -14
  42. package/dist/src/generators/mitosis.js +4 -3
  43. package/dist/src/generators/qwik/component.js +26 -5
  44. package/dist/src/generators/qwik/directives.d.ts +14 -5
  45. package/dist/src/generators/qwik/directives.js +32 -25
  46. package/dist/src/generators/qwik/handlers.js +3 -4
  47. package/dist/src/generators/qwik/jsx.js +17 -5
  48. package/dist/src/generators/qwik/src-generator.d.ts +0 -9
  49. package/dist/src/generators/qwik/src-generator.js +93 -101
  50. package/dist/src/generators/qwik/styles.js +8 -11
  51. package/dist/src/generators/react.js +9 -8
  52. package/dist/src/generators/solid.js +82 -8
  53. package/dist/src/generators/stencil/generate.js +5 -3
  54. package/dist/src/generators/stencil/index.js +5 -1
  55. package/dist/src/generators/svelte.d.ts +9 -1
  56. package/dist/src/generators/svelte.js +175 -76
  57. package/dist/src/generators/vue.d.ts +1 -1
  58. package/dist/src/generators/vue.js +86 -10
  59. package/dist/src/helpers/babel-transform copy.d.ts +8 -0
  60. package/dist/src/helpers/babel-transform copy.js +138 -0
  61. package/dist/src/helpers/babel-transform.d.ts +4 -7
  62. package/dist/src/helpers/babel-transform.js +18 -2
  63. package/dist/src/helpers/babel-transform.test.d.ts +1 -0
  64. package/dist/src/helpers/babel-transform.test.js +7 -0
  65. package/dist/src/helpers/create-mitosis-component.js +1 -1
  66. package/dist/src/helpers/get-state-object-string.js +2 -1
  67. package/dist/src/helpers/map-refs.js +22 -9
  68. package/dist/src/helpers/parsers.d.ts +8 -0
  69. package/dist/src/helpers/parsers.js +66 -0
  70. package/dist/src/helpers/render-imports.d.ts +2 -4
  71. package/dist/src/helpers/render-imports.js +32 -14
  72. package/dist/src/index.d.ts +10 -5
  73. package/dist/src/index.js +11 -5
  74. package/dist/src/parsers/builder.d.ts +16 -50
  75. package/dist/src/parsers/builder.js +22 -40
  76. package/dist/src/parsers/context.js +5 -1
  77. package/dist/src/parsers/jsx.d.ts +7 -0
  78. package/dist/src/parsers/jsx.js +27 -5
  79. package/dist/src/parsers/liquid.js +5 -1
  80. package/dist/src/plugins/compile-away-builder-components.js +5 -1
  81. package/dist/src/symbols/symbol-processor.js +3 -3
  82. package/dist/src/targets.d.ts +1 -1
  83. package/dist/src/types/mitosis-component.d.ts +8 -3
  84. package/dist/test/qwik/Accordion/high.jsx +0 -1
  85. package/dist/test/qwik/Accordion/low.jsx +171 -65
  86. package/dist/test/qwik/Accordion/med.jsx +9 -10
  87. package/dist/test/qwik/For/high.jsx +0 -1
  88. package/dist/test/qwik/For/low.jsx +25 -58
  89. package/dist/test/qwik/For/med.jsx +9 -10
  90. package/dist/test/qwik/Image/high.js +9 -1
  91. package/dist/test/qwik/Image/low.js +0 -42
  92. package/dist/test/qwik/Image/med.js +149 -12
  93. package/dist/test/qwik/Image.slow/high.js +9 -1
  94. package/dist/test/qwik/Image.slow/low.js +0 -42
  95. package/dist/test/qwik/Image.slow/med.js +149 -12
  96. package/dist/{src/types/generators.d.ts → test/qwik/bindings/high.cjs} +0 -0
  97. package/dist/test/qwik/bindings/low.cjs +33 -0
  98. package/dist/test/qwik/bindings/med.cjs +12 -0
  99. package/dist/test/qwik/button/high.js +1 -13
  100. package/dist/test/qwik/button/low.js +8 -40
  101. package/dist/test/qwik/button/med.js +36 -11
  102. package/dist/test/qwik/component/bindings/high.jsx +0 -1
  103. package/dist/test/qwik/component/bindings/low.jsx +26 -71
  104. package/dist/test/qwik/component/bindings/med.jsx +48 -39
  105. package/dist/test/qwik/component/component/inputs/high.cjsx +9 -0
  106. package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
  107. package/dist/test/qwik/component/component/inputs/med.cjsx +65 -0
  108. package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -1
  109. package/dist/test/qwik/hello_world/stylesheet/low.jsx +6 -27
  110. package/dist/test/qwik/hello_world/stylesheet/med.jsx +9 -10
  111. package/dist/test/qwik/page-with-symbol/high.js +0 -1
  112. package/dist/test/qwik/page-with-symbol/low.js +15 -52
  113. package/dist/test/qwik/page-with-symbol/med.js +9 -10
  114. package/dist/test/qwik/show-hide/high.jsx +9 -0
  115. package/dist/test/qwik/show-hide/low.jsx +0 -0
  116. package/dist/test/qwik/show-hide/med.jsx +174 -0
  117. package/dist/test/qwik/svg/high.js +0 -1
  118. package/dist/test/qwik/svg/low.js +9 -35
  119. package/dist/test/qwik/svg/med.js +9 -10
  120. package/dist/test/qwik/todo/Todo.cjs/high.cjs +4 -39
  121. package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -1
  122. package/dist/test/qwik/todo/Todo.cjs/med.cjs +38 -61
  123. package/dist/test/qwik/todo/Todo.js/high.js +22 -5
  124. package/dist/test/qwik/todo/Todo.js/med.js +45 -1
  125. package/dist/test/qwik/todo/Todo.tsx/high.tsx +4 -39
  126. package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -1
  127. package/dist/test/qwik/todo/Todo.tsx/med.tsx +31 -34
  128. package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -12
  129. package/dist/test/qwik/todos/Todo.tsx/low.tsx +18 -25
  130. package/dist/test/qwik/todos/Todo.tsx/med.tsx +8 -10
  131. package/dist/tsconfig.build.tsbuildinfo +1 -0
  132. package/dist/tsconfig.tsbuildinfo +1 -1
  133. package/package.json +22 -22
  134. package/dist/src/__tests__/data/blocks/onMount-onUnMount.d.ts +0 -1
  135. package/dist/src/__tests__/data/blocks/onMount-onUnMount.jsx +0 -13
  136. package/dist/src/__tests__/data/blocks/onMount.d.ts +0 -1
  137. package/dist/src/__tests__/data/blocks/onMount.jsx +0 -13
  138. package/dist/src/types/generators.js +0 -1
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VALID_HTML_TAGS = void 0;
4
+ exports.VALID_HTML_TAGS = [
5
+ 'html',
6
+ 'base',
7
+ 'head',
8
+ 'link',
9
+ 'meta',
10
+ 'style',
11
+ 'title',
12
+ 'body',
13
+ 'address',
14
+ 'article',
15
+ 'aside',
16
+ 'footer',
17
+ 'header',
18
+ 'h1',
19
+ 'h2',
20
+ 'h3',
21
+ 'h4',
22
+ 'h5',
23
+ 'h6',
24
+ 'main',
25
+ 'nav',
26
+ 'section',
27
+ 'blockquote',
28
+ 'dd',
29
+ 'div',
30
+ 'dl',
31
+ 'dt',
32
+ 'figcaption',
33
+ 'figure',
34
+ 'hr',
35
+ 'li',
36
+ 'menu',
37
+ 'ol',
38
+ 'p',
39
+ 'pre',
40
+ 'ul',
41
+ 'a',
42
+ 'abbr',
43
+ 'b',
44
+ 'bdi',
45
+ 'bdo',
46
+ 'br',
47
+ 'cite',
48
+ 'code',
49
+ 'data',
50
+ 'dfn',
51
+ 'em',
52
+ 'i',
53
+ 'kbd',
54
+ 'mark',
55
+ 'q',
56
+ 'rp',
57
+ 'rt',
58
+ 'ruby',
59
+ 's',
60
+ 'samp',
61
+ 'small',
62
+ 'span',
63
+ 'strong',
64
+ 'sub',
65
+ 'sup',
66
+ 'time',
67
+ 'u',
68
+ 'var',
69
+ 'wbr',
70
+ 'area',
71
+ 'audio',
72
+ 'img',
73
+ 'map',
74
+ 'track',
75
+ 'video',
76
+ 'embed',
77
+ 'iframe',
78
+ 'object',
79
+ 'param',
80
+ 'picture',
81
+ 'portal',
82
+ 'source',
83
+ 'svg',
84
+ 'math',
85
+ 'canvas',
86
+ 'noscript',
87
+ 'script',
88
+ 'del',
89
+ 'ins',
90
+ 'caption',
91
+ 'col',
92
+ 'colgroup',
93
+ 'table',
94
+ 'tbody',
95
+ 'td',
96
+ 'tfoot',
97
+ 'th',
98
+ 'thead',
99
+ 'tr',
100
+ 'button',
101
+ 'datalist',
102
+ 'fieldset',
103
+ 'form',
104
+ 'input',
105
+ 'label',
106
+ 'legend',
107
+ 'meter',
108
+ 'optgroup',
109
+ 'option',
110
+ 'output',
111
+ 'progress',
112
+ 'select',
113
+ 'textarea',
114
+ 'details',
115
+ 'dialog',
116
+ 'summary',
117
+ 'slot',
118
+ 'template',
119
+ ];
@@ -38,7 +38,7 @@ var blockToAngular = function (json, options) {
38
38
  return mappers[json.name](json, options);
39
39
  }
40
40
  if ((0, is_children_1.default)(json)) {
41
- return "<ng-slot></ng-slot>";
41
+ return "<ng-content></ng-content>";
42
42
  }
43
43
  if (json.properties._text) {
44
44
  return json.properties._text;
@@ -120,6 +120,7 @@ exports.blockToAngular = blockToAngular;
120
120
  var componentToAngular = function (options) {
121
121
  if (options === void 0) { options = {}; }
122
122
  return function (_a) {
123
+ var _b;
123
124
  var component = _a.component;
124
125
  // Make a copy we can safely mutate, similar to babel's toolchain
125
126
  var json = (0, fast_clone_1.fastClone)(component);
@@ -157,10 +158,12 @@ var componentToAngular = function (options) {
157
158
  ? ''
158
159
  : "ngOnInit() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(component.hooks.onMount.code, {
159
160
  replaceWith: 'this.',
160
- }), "\n }"), !component.hooks.onUpdate
161
+ }), "\n }"), !((_b = component.hooks.onUpdate) === null || _b === void 0 ? void 0 : _b.length)
161
162
  ? ''
162
- : "ngAfterContentChecked() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(component.hooks.onUpdate.code, {
163
- replaceWith: 'this.',
163
+ : "ngAfterContentChecked() {\n ".concat(component.hooks.onUpdate.map(function (hook) {
164
+ return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(hook.code, {
165
+ replaceWith: 'this.',
166
+ });
164
167
  }), "\n }"), !component.hooks.onUnMount
165
168
  ? ''
166
169
  : "ngOnDestroy() {\n ".concat((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(component.hooks.onUnMount.code, {
@@ -0,0 +1,8 @@
1
+ import { MitosisContext } from '../../types/mitosis-context';
2
+ declare type ContextToReactOptions = {
3
+ format?: boolean;
4
+ };
5
+ export declare const contextToReact: (options?: ContextToReactOptions) => ({ context }: {
6
+ context: MitosisContext;
7
+ }) => string;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contextToReact = void 0;
4
+ var standalone_1 = require("prettier/standalone");
5
+ var get_state_object_string_1 = require("../../helpers/get-state-object-string");
6
+ var contextToReact = function (options) {
7
+ if (options === void 0) { options = {}; }
8
+ return function (_a) {
9
+ var context = _a.context;
10
+ var str = "\n import { createContext } from 'react';\n\n export default createContext(".concat((0, get_state_object_string_1.getMemberObjectString)(context.value), ")\n ");
11
+ if (options.format !== false) {
12
+ try {
13
+ str = (0, standalone_1.format)(str, {
14
+ parser: 'typescript',
15
+ plugins: [
16
+ require('prettier/parser-typescript'), // To support running in browsers
17
+ ],
18
+ });
19
+ }
20
+ catch (err) {
21
+ console.error('Format error for file:', str);
22
+ throw err;
23
+ }
24
+ }
25
+ return str;
26
+ };
27
+ };
28
+ exports.contextToReact = contextToReact;
@@ -0,0 +1,8 @@
1
+ import { MitosisContext } from '../../types/mitosis-context';
2
+ declare type ContextToSolidOptions = {
3
+ format?: boolean;
4
+ };
5
+ export declare const contextToSolid: (options?: ContextToSolidOptions) => ({ context }: {
6
+ context: MitosisContext;
7
+ }) => string;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contextToSolid = void 0;
4
+ var standalone_1 = require("prettier/standalone");
5
+ var get_state_object_string_1 = require("../../helpers/get-state-object-string");
6
+ var contextToSolid = function (options) {
7
+ if (options === void 0) { options = {}; }
8
+ return function (_a) {
9
+ var context = _a.context;
10
+ var str = "\n import { createContext } from 'solid-js';\n\n export default createContext(".concat((0, get_state_object_string_1.getMemberObjectString)(context.value), ")\n ");
11
+ if (options.format !== false) {
12
+ try {
13
+ str = (0, standalone_1.format)(str, {
14
+ parser: 'typescript',
15
+ plugins: [
16
+ require('prettier/parser-typescript'), // To support running in browsers
17
+ ],
18
+ });
19
+ }
20
+ catch (err) {
21
+ console.error('Format error for file:', str);
22
+ throw err;
23
+ }
24
+ }
25
+ return str;
26
+ };
27
+ };
28
+ exports.contextToSolid = contextToSolid;
@@ -0,0 +1,8 @@
1
+ import { MitosisContext } from '../../types/mitosis-context';
2
+ import { BaseTranspilerOptions } from '../../types/config';
3
+ interface ContextToSvelteOptions extends Pick<BaseTranspilerOptions, 'prettier'> {
4
+ }
5
+ export declare const contextToSvelte: (options?: ContextToSvelteOptions) => ({ context }: {
6
+ context: MitosisContext;
7
+ }) => string;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contextToSvelte = void 0;
4
+ var standalone_1 = require("prettier/standalone");
5
+ var get_state_object_string_1 = require("../../helpers/get-state-object-string");
6
+ var contextToSvelte = function (options) {
7
+ if (options === void 0) { options = {}; }
8
+ return function (_a) {
9
+ var context = _a.context;
10
+ var str = "\n const key = Symbol(); \n\n export default {\n ".concat(context.name, ": ").concat((0, get_state_object_string_1.getMemberObjectString)(context.value), ", \n key \n }\n ");
11
+ if (options.prettier !== false) {
12
+ try {
13
+ str = (0, standalone_1.format)(str, {
14
+ parser: 'typescript',
15
+ plugins: [
16
+ require('prettier/parser-typescript'), // To support running in browsers
17
+ ],
18
+ });
19
+ }
20
+ catch (err) {
21
+ console.error('Format error for file:', str);
22
+ throw err;
23
+ }
24
+ }
25
+ return str;
26
+ };
27
+ };
28
+ exports.contextToSvelte = contextToSvelte;
@@ -0,0 +1,2 @@
1
+ import { MitosisComponent } from '../../types/mitosis-component';
2
+ export declare const hasContext: (component: MitosisComponent) => boolean;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasContext = void 0;
4
+ var hasContext = function (component) {
5
+ return Boolean(Object.keys(component.context.get).length ||
6
+ Object.keys(component.context.set).length);
7
+ };
8
+ exports.hasContext = hasContext;
@@ -35,6 +35,7 @@ var plugins_1 = require("../modules/plugins");
35
35
  var is_children_1 = __importDefault(require("../helpers/is-children"));
36
36
  var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
37
37
  var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
38
+ var render_imports_1 = require("../helpers/render-imports");
38
39
  var ATTRIBUTE_KEY_EXCEPTIONS_MAP = {
39
40
  class: 'className',
40
41
  };
@@ -147,6 +148,7 @@ var blockToHtml = function (json, options) {
147
148
  return json.properties._text;
148
149
  }
149
150
  if (json.bindings._text) {
151
+ // TO-DO: textContent might be better performance-wise
150
152
  addOnChangeJs(elId, options, "el.innerText = ".concat(json.bindings._text, ";"));
151
153
  return "<span data-name=\"".concat(elId, "\"><!-- ").concat(json.bindings._text.replace(/getContext\(el, "([^"]+)"\)/g, '$1'), " --></span>");
152
154
  }
@@ -156,7 +158,7 @@ var blockToHtml = function (json, options) {
156
158
  addOnChangeJs(elId, options,
157
159
  // TODO: be smarter about rendering, deleting old items and adding new ones by
158
160
  // querying dom potentially
159
- "\n let array = ".concat(json.bindings.each, ";\n let template = ").concat(options.format === 'class' ? 'this' : 'document', ".querySelector('[data-template-for=\"").concat(elId, "\"]');\n ").concat(options.format === 'class' ? 'this.' : '', "renderLoop(el, array, template, \"").concat(itemName, "\");\n "));
161
+ "\n let array = ".concat(json.bindings.each, ";\n let template = ").concat(options.format === 'class' ? 'this._root' : 'document', ".querySelector('[data-template-for=\"").concat(elId, "\"]');\n ").concat(options.format === 'class' ? 'this.' : '', "renderLoop(el, array, template, \"").concat(itemName, "\");\n "));
160
162
  // TODO: decide on how to handle this...
161
163
  str += "\n <span data-name=\"".concat(elId, "\"></span>\n <template data-template-for=\"").concat(elId, "\">");
162
164
  if (json.children) {
@@ -319,11 +321,13 @@ var componentToHtml = function (options) {
319
321
  if (!value) {
320
322
  return '';
321
323
  }
322
- return "\n document.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(value, "\n })\n ");
324
+ return "\n document.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el, index) => {\n ").concat(value, "\n })\n ");
323
325
  })
324
- .join('\n\n'), "\n\n ").concat(!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.code)
326
+ .join('\n\n'), "\n\n ").concat(!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)
325
327
  ? ''
326
- : "\n ".concat(updateReferencesInCode(json.hooks.onUpdate.code, useOptions), " \n "), "\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
328
+ : "\n ".concat(json.hooks.onUpdate.map(function (hook) {
329
+ return updateReferencesInCode(hook.code, useOptions);
330
+ }), " \n "), "\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
327
331
  ? ''
328
332
  : // TODO: make prettier by grabbing only the function body
329
333
  "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), " \n "), "\n\n ").concat(!hasLoop
@@ -361,7 +365,7 @@ exports.componentToHtml = componentToHtml;
361
365
  var componentToCustomElement = function (options) {
362
366
  if (options === void 0) { options = {}; }
363
367
  return function (_a) {
364
- var _b, _c, _d;
368
+ var _b, _c, _d, _e;
365
369
  var component = _a.component;
366
370
  var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
367
371
  var json = (0, fast_clone_1.fastClone)(component);
@@ -405,7 +409,7 @@ var componentToCustomElement = function (options) {
405
409
  var kebabName = component.name
406
410
  .replace(/([a-z])([A-Z])/g, '$1-$2')
407
411
  .toLowerCase();
408
- var str = "\n /**\n * Usage:\n * \n * <".concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(component.name, " extends HTMLElement {\n constructor() {\n super();\n\n const self = this;\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
412
+ var str = "\n ".concat((0, render_imports_1.renderPreComponent)(json), "\n /**\n * Usage:\n * \n * <").concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(component.name, " extends HTMLElement {\n constructor() {\n super();\n\n const self = this;\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
409
413
  valueMapper: function (value) {
410
414
  return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
411
415
  includeProps: false,
@@ -423,24 +427,26 @@ var componentToCustomElement = function (options) {
423
427
  ? "this.props = {};"
424
428
  : '', "\n\n ").concat(!hasLoop
425
429
  ? ''
426
- : "\n // Helper to pass context down for loops\n this.contextMap = new WeakMap();\n ", "\n\n ").concat(useOptions.js, "\n }\n\n ").concat(!((_b = json.hooks.onUnMount) === null || _b === void 0 ? void 0 : _b.code)
430
+ : "\n // Helper to pass context down for loops\n this.contextMap = new WeakMap();\n ", "\n\n ").concat(useOptions.js, "\n\n if (").concat((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.isAttachedToShadowDom, ") {\n this.attachShadow({ mode: 'open' })\n }\n }\n\n\n ").concat(!((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code)
427
431
  ? ''
428
- : "\n disconnectedCallback() {\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount.code, useOptions), useOptions), "\n }\n "), "\n\n connectedCallback() {\n this.innerHTML = `\n ").concat(html, "`;\n this.update();\n\n ").concat(!((_c = json.hooks.onMount) === null || _c === void 0 ? void 0 : _c.code)
432
+ : "\n disconnectedCallback() {\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount.code, useOptions), useOptions), "\n }\n "), "\n\n get _root() {\n return this.shadowRoot || this;\n }\n\n connectedCallback() {\n this._root.innerHTML = `\n ").concat(html, "`;\n this.onMount();\n this.update();\n }\n\n onMount() {\n ").concat(!((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
429
433
  ? ''
430
434
  : // TODO: make prettier by grabbing only the function body
431
- "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), "\n "), "\n }\n\n update() {\n ").concat(Object.keys(useOptions.onChangeJsById)
435
+ "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), "\n "), "\n }\n\n onUpdate() {\n ").concat(!((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
436
+ ? ''
437
+ : "\n ".concat(json.hooks.onUpdate.map(function (hook) {
438
+ return updateReferencesInCode(hook.code, useOptions);
439
+ }), " \n "), " \n }\n\n update() {\n this.onUpdate();\n this.updateBindings();\n }\n\n updateBindings() {\n ").concat(Object.keys(useOptions.onChangeJsById)
432
440
  .map(function (key) {
433
441
  var value = useOptions.onChangeJsById[key];
434
442
  if (!value) {
435
443
  return '';
436
444
  }
437
- return "\n this.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(updateReferencesInCode(value, useOptions), "\n })\n ");
445
+ return "\n this._root.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el, index) => {\n ").concat(updateReferencesInCode(value, useOptions), "\n })\n ");
438
446
  })
439
- .join('\n\n'), "\n\n ").concat(!((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.code)
440
- ? ''
441
- : "\n ".concat(updateReferencesInCode(json.hooks.onUpdate.code, useOptions), " \n "), " \n }\n\n ").concat(!hasLoop
447
+ .join('\n\n'), "\n }\n\n ").concat(!hasLoop
442
448
  ? ''
443
- : "\n\n // Helper to render loops\n renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n this.contextMap.set(child, {\n ...this.contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n getContext(el, name) {\n let parent = el;\n do {\n let context = this.contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ", "\n }\n\n customElements.define('").concat(kebabName, "', ").concat(component.name, ");\n ");
449
+ : "\n\n // Helper to render loops\n renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n this.contextMap.set(child, {\n ...this.contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n getContext(el, name) {\n let parent = el;\n do {\n let context = this.contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode || parent.host)\n }\n ", "\n }\n\n customElements.define('").concat(kebabName, "', ").concat(component.name, ");\n ");
444
450
  if (options.plugins) {
445
451
  str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
446
452
  }
@@ -142,14 +142,15 @@ var componentToMitosis = function (toMitosisOptions) {
142
142
  var otherComponents = components.filter(function (item) { return !mitosisCoreComponents.includes(item); });
143
143
  var hasState = Boolean(Object.keys(component.state).length);
144
144
  var needsMitosisCoreImport = Boolean(hasState || refs.size || mitosisComponents.length);
145
+ var stringifiedUseMetadata = json5_1.default.stringify(component.meta.useMetadata);
145
146
  // TODO: smart only pull in imports as needed
146
147
  var str = (0, 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 ", "\n ", "\n ", "\n\n ", "\n\n export default function ", "(props) {\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (", "\n ", "\n ", ")\n }\n\n "])), !needsMitosisCoreImport
147
148
  ? ''
148
149
  : "import { ".concat(!hasState ? '' : 'useState, ', " ").concat(!refs.size ? '' : 'useRef, ', " ").concat(mitosisComponents.join(', '), " } from '@builder.io/mitosis';"), !otherComponents.length
149
150
  ? ''
150
- : "import { ".concat(otherComponents.join(','), " } from '@components';"), (0, render_imports_1.renderPreComponent)(json), !component.meta.metadataHook
151
- ? ''
152
- : "".concat(jsx_1.METADATA_HOOK_NAME, "(").concat(json5_1.default.stringify(component.meta.metadataHook), ")"), component.name, !hasState
151
+ : "import { ".concat(otherComponents.join(','), " } from '@components';"), (0, render_imports_1.renderPreComponent)(json), stringifiedUseMetadata !== '{}'
152
+ ? "".concat(jsx_1.METADATA_HOOK_NAME, "(").concat(stringifiedUseMetadata, ")")
153
+ : '', component.name, !hasState
153
154
  ? ''
154
155
  : "const state = useState(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");"), getRefsString(json), !((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code)
155
156
  ? ''
@@ -10,6 +10,15 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
13
22
  Object.defineProperty(exports, "__esModule", { value: true });
14
23
  exports.addCommonStyles = exports.renderUseLexicalScope = exports.addComponent = exports.createFileSet = void 0;
15
24
  var compile_away_builder_components_1 = require("../../plugins/compile-away-builder-components");
@@ -74,8 +83,7 @@ function addComponent(fileSet, component, opts) {
74
83
  }
75
84
  }
76
85
  addComponentOnMount(componentFile, onRenderFile, componentName, component, useStyles);
77
- componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentFromQrl'), [generateQrl(componentFile, componentName + '_onMount')], ['any', 'any']));
78
- onRenderFile.src.emit(src_generator_1.NL);
86
+ componentFile.exportConst(componentName, (0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, 'componentQrl'), [generateQrl(componentFile, componentName + '_onMount')], ['any', 'any']));
79
87
  var directives = new Map();
80
88
  onRenderFile.exportConst(componentName + '_onRender', (0, src_generator_1.arrowFnBlock)([], [
81
89
  renderUseLexicalScope(onRenderFile),
@@ -91,12 +99,12 @@ function addComponent(fileSet, component, opts) {
91
99
  exports.addComponent = addComponent;
92
100
  function generateStyles(componentFile, styleFile, symbol, scoped) {
93
101
  return function () {
94
- this.emit((0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, scoped ? 'withScopedStylesFromQrl' : 'useStylesFromQrl'), [generateQrl(styleFile, symbol)]));
102
+ this.emit((0, src_generator_1.invoke)(componentFile.import(componentFile.qwikModule, scoped ? 'withScopedStylesQrl' : 'useStylesQrl'), [generateQrl(styleFile, symbol)]), ';');
95
103
  };
96
104
  }
97
105
  function renderUseLexicalScope(file) {
98
106
  return function () {
99
- return this.emit('const state', src_generator_1.WS, '=', src_generator_1.WS, file.import(file.qwikModule, 'useLexicalScope').name, '()[0]');
107
+ return this.emit('const state=', file.import(file.qwikModule, 'useLexicalScope').name, '()[0]');
100
108
  };
101
109
  }
102
110
  exports.renderUseLexicalScope = renderUseLexicalScope;
@@ -109,11 +117,24 @@ function addCommonStyles(fileSet) {
109
117
  }
110
118
  exports.addCommonStyles = addCommonStyles;
111
119
  function addComponentOnMount(componentFile, onRenderFile, componentName, component, useStyles) {
120
+ var inputInitializer = [];
121
+ if (component.inputs) {
122
+ component.inputs.forEach(function (input) {
123
+ input.defaultValue !== undefined &&
124
+ inputInitializer.push('if(state.', input.name, '===undefined)state.', input.name, '=', JSON.stringify(input.defaultValue), ';');
125
+ });
126
+ }
112
127
  componentFile.exportConst(componentName + '_onMount', function () {
113
128
  var _this = this;
114
129
  this.emit((0, src_generator_1.arrowFnValue)(['state'], function () {
115
130
  var _a;
116
- return _this.emit('{', (0, src_generator_1.iif)((_a = component.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code), ';', useStyles, src_generator_1.NL, 'return ', generateQrl(onRenderFile, componentName + '_onRender', ['state']), ';', src_generator_1.UNINDENT, src_generator_1.NL, '}');
131
+ return _this.emit.apply(_this, __spreadArray(__spreadArray(['{'], inputInitializer, false), ['typeof __STATE__==="object"&&Object.assign(state,__STATE__[state.serverStateId]);',
132
+ (0, src_generator_1.iif)((_a = component.hooks.onMount) === null || _a === void 0 ? void 0 : _a.code),
133
+ ';',
134
+ useStyles,
135
+ 'return ',
136
+ generateQrl(onRenderFile, componentName + '_onRender', ['state']),
137
+ ';}'], false));
117
138
  }));
118
139
  });
119
140
  }
@@ -1,18 +1,26 @@
1
1
  import { MitosisNode } from '../../types/mitosis-node';
2
2
  export declare const DIRECTIVES: Record<string, string | ((node: MitosisNode, blockFn: () => void) => void)>;
3
- export declare function Image(props: {
4
- href?: string;
3
+ interface ImageProps {
4
+ altText?: string;
5
5
  image?: string;
6
+ href?: string;
7
+ height?: number;
8
+ width?: number;
9
+ builderBlock?: any;
10
+ attributes?: any;
11
+ sizes?: string;
12
+ srcsetSizes?: string;
13
+ srcset?: string;
6
14
  backgroundSize?: string;
7
15
  backgroundPosition?: string;
8
- sizes?: string;
9
- altText?: string;
10
16
  fitContent?: boolean;
11
17
  aspectRatio?: number;
12
18
  lazy?: boolean;
13
19
  class?: string;
14
20
  children?: any[];
15
- }): any;
21
+ }
22
+ export declare function Image(props: ImageProps): any;
23
+ export declare function __passThroughProps__(dstProps: Record<string, any>, srcProps: Record<string, any>): Record<string, any>;
16
24
  export declare function CoreButton(props: {
17
25
  text?: string;
18
26
  link?: string;
@@ -20,3 +28,4 @@ export declare function CoreButton(props: {
20
28
  openInNewTab?: string;
21
29
  tagName$: string;
22
30
  }): any;
31
+ export {};
@@ -4,42 +4,43 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
4
4
  return cooked;
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.CoreButton = exports.Image = exports.DIRECTIVES = void 0;
7
+ exports.CoreButton = exports.__passThroughProps__ = exports.Image = exports.DIRECTIVES = void 0;
8
8
  var minify_1 = require("../minify");
9
9
  var src_generator_1 = require("./src-generator");
10
10
  exports.DIRECTIVES = {
11
11
  Show: function (node, blockFn) {
12
12
  return function () {
13
13
  var expr = node.bindings.when;
14
- this.isJSX && this.emit('{', src_generator_1.WS);
15
- this.emit(expr, src_generator_1.WS, '?', src_generator_1.INDENT, src_generator_1.NL);
14
+ this.isJSX && this.emit('{');
15
+ this.emit(expr, '?');
16
16
  blockFn();
17
- this.emit(':', src_generator_1.WS, 'null', src_generator_1.UNINDENT, src_generator_1.NL);
18
- this.isJSX && this.emit('}', src_generator_1.NL);
17
+ this.emit(':null');
18
+ this.isJSX && this.emit('}');
19
19
  };
20
20
  },
21
21
  For: function (node, blockFn) {
22
22
  return function () {
23
23
  var expr = node.bindings.each;
24
- this.isJSX && this.emit('{', src_generator_1.WS);
25
- this.emit('(', expr, src_generator_1.WS, '||', src_generator_1.WS, '[])');
26
- this.emit('.map(', '(function(__value__)', src_generator_1.WS, '{', src_generator_1.INDENT, src_generator_1.NL);
27
- this.emit('var state', src_generator_1.WS, '=', src_generator_1.WS, 'Object.assign({},', src_generator_1.WS, 'this,', src_generator_1.WS, '{', (0, src_generator_1.iteratorProperty)(expr), ':', src_generator_1.WS, '__value__', src_generator_1.WS, '==', src_generator_1.WS, 'null', src_generator_1.WS, '?', src_generator_1.WS, '{}', src_generator_1.WS, ':', src_generator_1.WS, '__value__', '});', src_generator_1.NL);
28
- this.emit('return', src_generator_1.WS, '(');
24
+ this.isJSX && this.emit('{');
25
+ this.emit('(', expr, '||[]).map(', '(function(__value__){');
26
+ this.emit('var state=Object.assign({},this,{', (0, src_generator_1.iteratorProperty)(expr), ':__value__==null?{}:__value__});');
27
+ this.emit('return(');
29
28
  blockFn();
30
- this.emit(')', ';', src_generator_1.UNINDENT, src_generator_1.NL);
31
- this.emit('}', ').bind(state))', src_generator_1.NL);
32
- this.isJSX && this.emit('}', src_generator_1.NL);
29
+ this.emit(');}).bind(state))');
30
+ this.isJSX && this.emit('}');
33
31
  };
34
32
  },
35
33
  Image: (0, minify_1.minify)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), Image),
36
34
  CoreButton: (0, minify_1.minify)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["", ""], ["", ""])), CoreButton),
35
+ __passThroughProps__: (0, minify_1.minify)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["", ""], ["", ""])), __passThroughProps__),
37
36
  };
38
37
  function Image(props) {
38
+ var _a;
39
39
  var jsx = props.children || [];
40
40
  var image = props.image;
41
41
  if (image) {
42
- var isBuilderIoImage = !!(image || '').match(/builder\.io/);
42
+ var isBuilderIoImage = !!(image || '').match(/\.builder\.io/);
43
+ var isPixel = (_a = props.builderBlock) === null || _a === void 0 ? void 0 : _a.id.startsWith('builder-pixel-');
43
44
  var imgProps = {
44
45
  src: props.image,
45
46
  style: "object-fit:".concat(props.backgroundSize || 'cover', ";object-position:").concat(props.backgroundPosition || 'center', ";") +
@@ -48,15 +49,17 @@ function Image(props) {
48
49
  : ''),
49
50
  sizes: props.sizes,
50
51
  alt: props.altText,
51
- loading: props.lazy ? 'lazy' : undefined,
52
+ role: !props.altText ? 'presentation' : undefined,
53
+ loading: isPixel ? 'eager' : 'lazy',
52
54
  srcset: undefined,
53
55
  };
54
56
  if (isBuilderIoImage) {
57
+ image = updateQueryParam(image, 'format', 'webp');
55
58
  var srcset = ['100', '200', '400', '800', '1200', '1600', '2000']
59
+ .concat(props.srcsetSizes ? String(props.srcsetSizes).split(' ') : [])
56
60
  .map(function (size) {
57
61
  return updateQueryParam(image, 'width', size) + ' ' + size + 'w';
58
62
  })
59
- .concat([image])
60
63
  .join(', ');
61
64
  imgProps.srcset = srcset;
62
65
  jsx = jsx = [
@@ -79,7 +82,7 @@ function Image(props) {
79
82
  }
80
83
  }
81
84
  var children = props.children ? [jsx].concat(props.children) : [jsx];
82
- return h(props.href ? 'a' : 'div', { href: props.href, class: props.class }, children);
85
+ return h(props.href ? 'a' : 'div', __passThroughProps__({ href: props.href, class: props.class }, props), children);
83
86
  function updateQueryParam(uri, key, value) {
84
87
  if (uri === void 0) { uri = ''; }
85
88
  var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
@@ -91,6 +94,16 @@ function Image(props) {
91
94
  }
92
95
  }
93
96
  exports.Image = Image;
97
+ function __passThroughProps__(dstProps, srcProps) {
98
+ for (var key in srcProps) {
99
+ if (Object.prototype.hasOwnProperty.call(srcProps, key) &&
100
+ ((key.startsWith('on') && key.endsWith('Qrl')) || key == 'style')) {
101
+ dstProps[key] = srcProps[key];
102
+ }
103
+ }
104
+ return dstProps;
105
+ }
106
+ exports.__passThroughProps__ = __passThroughProps__;
94
107
  function CoreButton(props) {
95
108
  var hasLink = !!props.link;
96
109
  var hProps = {
@@ -99,13 +112,7 @@ function CoreButton(props) {
99
112
  target: props.openInNewTab ? '_blank' : '_self',
100
113
  class: props.class,
101
114
  };
102
- for (var key in props) {
103
- if (Object.prototype.hasOwnProperty.call(props, key) &&
104
- key.startsWith('on:')) {
105
- hProps[key] = props[key];
106
- }
107
- }
108
- return h(hasLink ? 'a' : props.tagName$ || 'span', hProps);
115
+ return h(hasLink ? 'a' : props.tagName$ || 'span', __passThroughProps__(hProps, props));
109
116
  }
110
117
  exports.CoreButton = CoreButton;
111
- var templateObject_1, templateObject_2;
118
+ var templateObject_1, templateObject_2, templateObject_3;