@builder.io/mitosis 0.6.7 → 0.7.0
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/generators/builder/generator.js +1 -8
- package/dist/src/generators/stencil/blocks.js +3 -1
- package/dist/src/generators/stencil/component.js +178 -158
- package/dist/src/generators/stencil/helpers/index.d.ts +7 -2
- package/dist/src/generators/stencil/helpers/index.js +4 -3
- package/dist/src/generators/stencil/types.d.ts +25 -2
- package/dist/src/helpers/event-handlers.d.ts +1 -0
- package/dist/src/helpers/event-handlers.js +4 -1
- package/dist/src/helpers/transform-to-jsx.d.ts +4 -0
- package/dist/src/helpers/transform-to-jsx.js +13 -0
- package/dist/src/parsers/jsx/element-parser.js +4 -3
- package/package.json +1 -1
|
@@ -461,7 +461,7 @@ function isGlobalStyle(key) {
|
|
|
461
461
|
key.startsWith('@'));
|
|
462
462
|
}
|
|
463
463
|
const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
464
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m
|
|
464
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
465
465
|
const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
|
|
466
466
|
if (mapper) {
|
|
467
467
|
const element = mapper(json, options);
|
|
@@ -562,13 +562,6 @@ const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
|
562
562
|
}
|
|
563
563
|
delete json.bindings.css;
|
|
564
564
|
}
|
|
565
|
-
if (thisIsComponent) {
|
|
566
|
-
for (const key in json.bindings) {
|
|
567
|
-
if (!((_o = json.slots) === null || _o === void 0 ? void 0 : _o[key])) {
|
|
568
|
-
builderBindings[`component.options.${key}`] = json.bindings[key].code;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
565
|
const element = el({
|
|
573
566
|
tagName: thisIsComponent ? undefined : json.name,
|
|
574
567
|
...(hasCss && {
|
|
@@ -6,6 +6,7 @@ const helpers_1 = require("../../generators/stencil/helpers");
|
|
|
6
6
|
const collect_class_string_1 = require("../../generators/stencil/helpers/collect-class-string");
|
|
7
7
|
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
8
8
|
const for_1 = require("../../helpers/nodes/for");
|
|
9
|
+
const transform_to_jsx_1 = require("../../helpers/transform-to-jsx");
|
|
9
10
|
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
10
11
|
const blockToStencil = ({ json, options = {}, insideJsx, rootRef, childComponents, }) => {
|
|
11
12
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -78,7 +79,8 @@ const blockToStencil = ({ json, options = {}, insideJsx, rootRef, childComponent
|
|
|
78
79
|
}
|
|
79
80
|
for (const key in json.properties) {
|
|
80
81
|
const value = json.properties[key];
|
|
81
|
-
|
|
82
|
+
// Stencil uses ´htmlFor´ (JSX) instead of ´for´ (HTML)
|
|
83
|
+
str += ` ${(0, transform_to_jsx_1.transformAttributeToJSX)(key)}="${value}" `;
|
|
82
84
|
}
|
|
83
85
|
for (const key in json.bindings) {
|
|
84
86
|
const { code, arguments: cusArgs = [], type } = json.bindings[key];
|
|
@@ -7,6 +7,7 @@ const helpers_1 = require("../../generators/stencil/helpers");
|
|
|
7
7
|
const get_code_processor_plugins_1 = require("../../generators/stencil/plugins/get-code-processor-plugins");
|
|
8
8
|
const dash_case_1 = require("../../helpers/dash-case");
|
|
9
9
|
const dedent_1 = require("../../helpers/dedent");
|
|
10
|
+
const event_handlers_1 = require("../../helpers/event-handlers");
|
|
10
11
|
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
11
12
|
const get_child_components_1 = require("../../helpers/get-child-components");
|
|
12
13
|
const get_props_1 = require("../../helpers/get-props");
|
|
@@ -21,168 +22,187 @@ const plugins_1 = require("../../modules/plugins");
|
|
|
21
22
|
const standalone_1 = require("prettier/standalone");
|
|
22
23
|
const componentToStencil = (_options = {
|
|
23
24
|
typescript: true, // Stencil is uses .tsx always
|
|
24
|
-
}) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(0, map_refs_1.mapRefs)(json, (refName) => `this.${refName}`);
|
|
36
|
-
let css = (0, collect_css_1.collectCss)(json);
|
|
37
|
-
const props = Array.from((0, get_props_1.getProps)(json));
|
|
38
|
-
const events = props.filter((prop) => (0, helpers_1.isEvent)(prop));
|
|
39
|
-
const defaultProps = json.defaultProps;
|
|
40
|
-
const childComponents = (0, get_child_components_1.getChildComponents)(json);
|
|
41
|
-
const processBindingOptions = { events };
|
|
42
|
-
options.plugins = (0, get_code_processor_plugins_1.getCodeProcessorPlugins)(json, options, processBindingOptions);
|
|
43
|
-
if (options.plugins) {
|
|
44
|
-
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
45
|
-
}
|
|
46
|
-
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
47
|
-
const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
48
|
-
format: 'class',
|
|
49
|
-
data: true,
|
|
50
|
-
functions: false,
|
|
51
|
-
getters: false,
|
|
52
|
-
keyPrefix: '@State() ',
|
|
53
|
-
});
|
|
54
|
-
const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
55
|
-
format: 'class',
|
|
56
|
-
data: false,
|
|
57
|
-
functions: true,
|
|
58
|
-
getters: true,
|
|
59
|
-
});
|
|
60
|
-
let refs = json.refs
|
|
61
|
-
? Object.entries(json.refs)
|
|
62
|
-
.map(([key, value]) => { var _a; return `private ${key}!: ${(_a = value.typeParameter) !== null && _a !== void 0 ? _a : 'HTMLElement'};`; })
|
|
63
|
-
.join('\n')
|
|
64
|
-
: '';
|
|
65
|
-
const wrap = (0, helpers_1.needsWrap)(json.children);
|
|
66
|
-
const withAttributePassing = !wrap && (0, attribute_passing_1.shouldAddAttributePassing)(json, options);
|
|
67
|
-
const rootRef = (0, attribute_passing_1.getAddAttributePassingRef)(json, options);
|
|
68
|
-
if (withAttributePassing && !refs.includes(rootRef)) {
|
|
69
|
-
refs += `\nprivate ${rootRef}!: HTMLElement;`;
|
|
70
|
-
}
|
|
71
|
-
if (options.prettier !== false) {
|
|
72
|
-
try {
|
|
73
|
-
css = (0, standalone_1.format)(css, {
|
|
74
|
-
parser: 'css',
|
|
75
|
-
plugins: [require('prettier/parser-postcss')],
|
|
76
|
-
});
|
|
25
|
+
}) => {
|
|
26
|
+
return ({ component }) => {
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
28
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
29
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
30
|
+
target: 'stencil',
|
|
31
|
+
component,
|
|
32
|
+
defaults: _options,
|
|
33
|
+
});
|
|
34
|
+
if (options.plugins) {
|
|
35
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
77
36
|
}
|
|
78
|
-
|
|
79
|
-
|
|
37
|
+
(0, map_refs_1.mapRefs)(json, (refName) => `this.${refName}`);
|
|
38
|
+
let css = (0, collect_css_1.collectCss)(json);
|
|
39
|
+
let props = Array.from((0, get_props_1.getProps)(json));
|
|
40
|
+
const events = props.filter((prop) => (0, helpers_1.isEvent)(prop));
|
|
41
|
+
const defaultProps = json.defaultProps;
|
|
42
|
+
const childComponents = (0, get_child_components_1.getChildComponents)(json);
|
|
43
|
+
const processBindingOptions = { events };
|
|
44
|
+
props = props
|
|
45
|
+
.map((prop) => {
|
|
46
|
+
// Stencil adds "on" to every `@Event` so we need to remove "on" from event props
|
|
47
|
+
// https://stenciljs.com/docs/events#using-events-in-jsx
|
|
48
|
+
if ((0, helpers_1.isEvent)(prop)) {
|
|
49
|
+
return (0, event_handlers_1.getEventNameWithoutOn)(prop);
|
|
50
|
+
}
|
|
51
|
+
return prop;
|
|
52
|
+
})
|
|
53
|
+
.filter((prop) => {
|
|
54
|
+
// Stencil doesn't need children as a prop
|
|
55
|
+
return prop !== 'children';
|
|
56
|
+
});
|
|
57
|
+
options.plugins = (0, get_code_processor_plugins_1.getCodeProcessorPlugins)(json, options, processBindingOptions);
|
|
58
|
+
if (options.plugins) {
|
|
59
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
80
60
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
61
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
62
|
+
const dataString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
63
|
+
format: 'class',
|
|
64
|
+
data: true,
|
|
65
|
+
functions: false,
|
|
66
|
+
getters: false,
|
|
67
|
+
keyPrefix: '@State() ',
|
|
68
|
+
});
|
|
69
|
+
const methodsString = (0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
70
|
+
format: 'class',
|
|
71
|
+
data: false,
|
|
72
|
+
functions: true,
|
|
73
|
+
getters: true,
|
|
74
|
+
});
|
|
75
|
+
let refs = json.refs
|
|
76
|
+
? Object.entries(json.refs)
|
|
77
|
+
.map(([key, value]) => { var _a; return `private ${key}!: ${(_a = value.typeParameter) !== null && _a !== void 0 ? _a : 'HTMLElement'};`; })
|
|
78
|
+
.join('\n')
|
|
79
|
+
: '';
|
|
80
|
+
const wrap = (0, helpers_1.needsWrap)(json.children);
|
|
81
|
+
const withAttributePassing = !wrap && (0, attribute_passing_1.shouldAddAttributePassing)(json, options);
|
|
82
|
+
const rootRef = (0, attribute_passing_1.getAddAttributePassingRef)(json, options);
|
|
83
|
+
if (withAttributePassing && !refs.includes(rootRef)) {
|
|
84
|
+
refs += `\nprivate ${rootRef}!: HTMLElement;`;
|
|
85
|
+
}
|
|
86
|
+
if (options.prettier !== false) {
|
|
87
|
+
try {
|
|
88
|
+
css = (0, standalone_1.format)(css, {
|
|
89
|
+
parser: 'css',
|
|
90
|
+
plugins: [require('prettier/parser-postcss')],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
console.warn('Could not format css', err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let tagName = (0, helpers_1.getTagName)(json.name, options);
|
|
98
|
+
if ((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.tagName) {
|
|
99
|
+
// Deprecated option, we shouldn't use this, instead change the name of your Mitosis component
|
|
100
|
+
tagName = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName;
|
|
101
|
+
}
|
|
102
|
+
const noDependencyOnUpdateHooks = (_d = (_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.filter((hook) => !hook.deps)) !== null && _d !== void 0 ? _d : [];
|
|
103
|
+
/*
|
|
104
|
+
* We want to create a function for every onUpdate hook that has dependencies.
|
|
105
|
+
* We call the function once in "componentDidLoad"
|
|
106
|
+
* And we create "Watch" decorators for every dependency
|
|
107
|
+
*/
|
|
108
|
+
const dependencyOnUpdateHooks = (_f = (_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter((hook) => hook.deps)) !== null && _f !== void 0 ? _f : [];
|
|
109
|
+
const coreImports = (0, helpers_1.getStencilCoreImportsAsString)({
|
|
110
|
+
wrap,
|
|
111
|
+
events,
|
|
112
|
+
props,
|
|
113
|
+
dataString,
|
|
114
|
+
watch: Boolean(dependencyOnUpdateHooks === null || dependencyOnUpdateHooks === void 0 ? void 0 : dependencyOnUpdateHooks.length),
|
|
115
|
+
});
|
|
116
|
+
const propOptions = {
|
|
117
|
+
...options.propOptions,
|
|
118
|
+
...(_h = (_g = json.meta.useMetadata) === null || _g === void 0 ? void 0 : _g.stencil) === null || _h === void 0 ? void 0 : _h.propOptions,
|
|
119
|
+
};
|
|
120
|
+
let str = (0, dedent_1.dedent) `
|
|
121
|
+
${(0, helpers_1.getImports)(json, options, childComponents)}
|
|
122
|
+
|
|
123
|
+
import { ${coreImports} } from '@stencil/core';
|
|
124
|
+
|
|
125
|
+
@Component({
|
|
126
|
+
tag: '${tagName}',
|
|
127
|
+
${((_j = json.meta.useMetadata) === null || _j === void 0 ? void 0 : _j.isAttachedToShadowDom) ? 'shadow: true,' : ''}
|
|
128
|
+
${css.length
|
|
129
|
+
? `styles: \`
|
|
130
|
+
${(0, indent_1.indent)(css, 8)}\`,`
|
|
131
|
+
: ''}
|
|
132
|
+
})
|
|
133
|
+
export class ${json.name} {
|
|
134
|
+
${refs}
|
|
135
|
+
${(0, helpers_1.getPropsAsCode)({ props, json, defaultProps, propOptions })}
|
|
136
|
+
${dataString}
|
|
137
|
+
${methodsString}
|
|
138
|
+
${(0, helpers_1.getExportsAndLocal)(json)}
|
|
139
|
+
${withAttributePassing ? (0, attribute_passing_1.getAttributePassingString)(true) : ''}
|
|
128
140
|
|
|
129
|
-
${
|
|
130
|
-
.map((
|
|
141
|
+
${dependencyOnUpdateHooks
|
|
142
|
+
.map((hook, index) => {
|
|
143
|
+
return `
|
|
144
|
+
watch${index}Fn() {
|
|
145
|
+
${hook.code}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
${(0, helpers_1.getDepsAsArray)(hook.deps)
|
|
149
|
+
.map((dep) => `@Watch("${dep}")`)
|
|
150
|
+
.join('\n')}
|
|
151
|
+
watch${index}(){
|
|
152
|
+
this.watch${index}Fn();
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
})
|
|
131
156
|
.join('\n')}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
${
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
rootRef: withAttributePassing && rootRef === attribute_passing_1.ROOT_REF ? rootRef : undefined, // only pass rootRef if it's not the default
|
|
167
|
-
}))
|
|
168
|
-
.join('\n')}
|
|
169
|
-
|
|
170
|
-
${wrap ? '</Host>' : ''})
|
|
157
|
+
|
|
158
|
+
${`componentDidLoad() {
|
|
159
|
+
${withAttributePassing
|
|
160
|
+
? `this.enableAttributePassing(this.${rootRef}, "${(0, dash_case_1.dashCase)(json.name)}");`
|
|
161
|
+
: ''}
|
|
162
|
+
${json.hooks.onMount.length ? (0, on_mount_1.stringifySingleScopeOnMount)(json) : ''}
|
|
163
|
+
${dependencyOnUpdateHooks
|
|
164
|
+
.map((_, index) => `this.watch${index}Fn();`)
|
|
165
|
+
.join('\n')}
|
|
166
|
+
}`}
|
|
167
|
+
${!((_k = json.hooks.onUnMount) === null || _k === void 0 ? void 0 : _k.code)
|
|
168
|
+
? ''
|
|
169
|
+
: `disconnectedCallback() { ${json.hooks.onUnMount.code} }`}
|
|
170
|
+
${noDependencyOnUpdateHooks.length
|
|
171
|
+
? `componentDidUpdate() { ${noDependencyOnUpdateHooks
|
|
172
|
+
.map((hook) => hook.code)
|
|
173
|
+
.join('\n')} }`
|
|
174
|
+
: ''}
|
|
175
|
+
|
|
176
|
+
render() {
|
|
177
|
+
return (${wrap ? '<Host>' : ''}
|
|
178
|
+
|
|
179
|
+
${json.children
|
|
180
|
+
.map((item) => (0, blocks_1.blockToStencil)({
|
|
181
|
+
json: item,
|
|
182
|
+
options,
|
|
183
|
+
insideJsx: true,
|
|
184
|
+
childComponents,
|
|
185
|
+
rootRef: withAttributePassing && rootRef === attribute_passing_1.ROOT_REF ? rootRef : undefined, // only pass rootRef if it's not the default
|
|
186
|
+
}))
|
|
187
|
+
.join('\n')}
|
|
188
|
+
|
|
189
|
+
${wrap ? '</Host>' : ''})
|
|
190
|
+
}
|
|
171
191
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
`;
|
|
193
|
+
if (options.plugins) {
|
|
194
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
195
|
+
}
|
|
196
|
+
if (options.prettier !== false) {
|
|
197
|
+
str = (0, standalone_1.format)(str, {
|
|
198
|
+
parser: 'typescript',
|
|
199
|
+
plugins: [require('prettier/parser-typescript')],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (options.plugins) {
|
|
203
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
204
|
+
}
|
|
205
|
+
return str;
|
|
206
|
+
};
|
|
187
207
|
};
|
|
188
208
|
exports.componentToStencil = componentToStencil;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToStencilOptions } from '../../../generators/stencil/types';
|
|
1
|
+
import { StencilPropOption, ToStencilOptions } from '../../../generators/stencil/types';
|
|
2
2
|
import { MitosisComponent, MitosisState } from '../../../types/mitosis-component';
|
|
3
3
|
import { MitosisNode } from '../../../types/mitosis-node';
|
|
4
4
|
export declare const isEvent: (key: string) => boolean;
|
|
@@ -7,7 +7,12 @@ export type ProcessBindingOptions = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const processBinding: (json: MitosisComponent, code: string, { events }: ProcessBindingOptions) => string;
|
|
9
9
|
export declare const getTagName: (name: string, { prefix }: ToStencilOptions) => string;
|
|
10
|
-
export declare const getPropsAsCode: (props
|
|
10
|
+
export declare const getPropsAsCode: ({ props, propOptions, defaultProps, json, }: {
|
|
11
|
+
props: string[];
|
|
12
|
+
json: MitosisComponent;
|
|
13
|
+
defaultProps?: MitosisState | undefined;
|
|
14
|
+
propOptions: Record<string, StencilPropOption>;
|
|
15
|
+
}) => string;
|
|
11
16
|
/**
|
|
12
17
|
* Check for root element if it needs a wrapping <Host>
|
|
13
18
|
* @param children
|
|
@@ -14,7 +14,7 @@ const appendEmits = (str, events) => {
|
|
|
14
14
|
let code = str;
|
|
15
15
|
if (events.length) {
|
|
16
16
|
for (const event of events) {
|
|
17
|
-
code = code.replaceAll(`props.${event}(`, `props.${event}.emit(`);
|
|
17
|
+
code = code.replaceAll(`props.${event}(`, `props.${(0, event_handlers_1.getEventNameWithoutOn)(event)}.emit(`);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
return code;
|
|
@@ -43,7 +43,7 @@ const getTagName = (name, { prefix }) => {
|
|
|
43
43
|
return dashName;
|
|
44
44
|
};
|
|
45
45
|
exports.getTagName = getTagName;
|
|
46
|
-
const getPropsAsCode = (props, json,
|
|
46
|
+
const getPropsAsCode = ({ props, propOptions, defaultProps, json, }) => {
|
|
47
47
|
const propsTypeRef = json.propsTypeRef;
|
|
48
48
|
const internalTypes = json.types;
|
|
49
49
|
const isInternalType = propsTypeRef && internalTypes && internalTypes.find((iType) => iType.includes(propsTypeRef));
|
|
@@ -52,6 +52,7 @@ const getPropsAsCode = (props, json, defaultProps) => {
|
|
|
52
52
|
var _a;
|
|
53
53
|
const defaultProp = defaultProps ? (_a = defaultProps[item]) === null || _a === void 0 ? void 0 : _a.code : undefined;
|
|
54
54
|
const defaultPropString = defaultProp ? ` = ${defaultProp}` : '';
|
|
55
|
+
const propOption = propOptions[item];
|
|
55
56
|
if ((0, exports.isEvent)(item)) {
|
|
56
57
|
return `@Event() ${item}: any${defaultPropString}`;
|
|
57
58
|
}
|
|
@@ -62,7 +63,7 @@ const getPropsAsCode = (props, json, defaultProps) => {
|
|
|
62
63
|
!isInternalType
|
|
63
64
|
? `${propsTypeRef}["${item}"]`
|
|
64
65
|
: 'any';
|
|
65
|
-
return `@Prop() ${item}: ${type}${defaultPropString}`;
|
|
66
|
+
return `@Prop(${propOption ? JSON.stringify(propOption) : ''}) ${item}: ${type}${defaultPropString}`;
|
|
66
67
|
})
|
|
67
68
|
.join(';\n');
|
|
68
69
|
};
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
import { BaseTranspilerOptions } from '../../types/transpiler';
|
|
2
|
-
export interface
|
|
2
|
+
export interface StencilPropOption {
|
|
3
|
+
attribute?: string;
|
|
4
|
+
mutable?: boolean;
|
|
5
|
+
reflect?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface StencilPropOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Add additional options for Stencil properties: https://stenciljs.com/docs/properties#prop-options.
|
|
10
|
+
* You need to map your properties you provide to the component.
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```tsx
|
|
14
|
+
* propOptions: {
|
|
15
|
+
* className: {
|
|
16
|
+
* attribute: 'classname',
|
|
17
|
+
* mutable: false,
|
|
18
|
+
* reflect: false,
|
|
19
|
+
* },
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
propOptions?: Record<string, StencilPropOption>;
|
|
24
|
+
}
|
|
25
|
+
export interface ToStencilOptions extends BaseTranspilerOptions, StencilPropOptions {
|
|
3
26
|
/**
|
|
4
27
|
* Add a prefix for every component like `my`.
|
|
5
28
|
* A Stencil component needs a prefix with a dash.
|
|
@@ -11,4 +34,4 @@ export interface ToStencilOptions extends BaseTranspilerOptions {
|
|
|
11
34
|
*/
|
|
12
35
|
prefix?: string;
|
|
13
36
|
}
|
|
14
|
-
export type StencilMetadata = {};
|
|
37
|
+
export type StencilMetadata = {} & StencilPropOptions;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkIsBindingNativeEvent = exports.checkIsEvent = void 0;
|
|
3
|
+
exports.checkIsBindingNativeEvent = exports.getEventNameWithoutOn = exports.checkIsEvent = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
const checkIsEvent = (code) => code.startsWith('on');
|
|
5
6
|
exports.checkIsEvent = checkIsEvent;
|
|
7
|
+
const getEventNameWithoutOn = (code) => (0, lodash_1.camelCase)(code.replace('on', ''));
|
|
8
|
+
exports.getEventNameWithoutOn = getEventNameWithoutOn;
|
|
6
9
|
const nativeEvents = [
|
|
7
10
|
'abort',
|
|
8
11
|
'animationcancel',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformAttributeToJSX = exports.JSX_TO_HTML_ATTR = void 0;
|
|
4
|
+
const typescript_1 = require("../helpers/typescript");
|
|
5
|
+
exports.JSX_TO_HTML_ATTR = {
|
|
6
|
+
for: 'htmlFor',
|
|
7
|
+
};
|
|
8
|
+
const transformAttributeToJSX = (key) => {
|
|
9
|
+
if ((0, typescript_1.objectHasKey)(exports.JSX_TO_HTML_ATTR, key))
|
|
10
|
+
return exports.JSX_TO_HTML_ATTR[key];
|
|
11
|
+
return key;
|
|
12
|
+
};
|
|
13
|
+
exports.transformAttributeToJSX = transformAttributeToJSX;
|
|
@@ -103,7 +103,7 @@ const jsxElementToJson = (node) => {
|
|
|
103
103
|
}),
|
|
104
104
|
},
|
|
105
105
|
scope: forArguments,
|
|
106
|
-
children: [(0, exports.jsxElementToJson)(bodyExpression)],
|
|
106
|
+
children: [(0, exports.jsxElementToJson)(bodyExpression)].filter(nullable_1.checkIsDefined),
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -144,7 +144,7 @@ const jsxElementToJson = (node) => {
|
|
|
144
144
|
}).code,
|
|
145
145
|
}),
|
|
146
146
|
},
|
|
147
|
-
children: [(0, exports.jsxElementToJson)(node.right)],
|
|
147
|
+
children: [(0, exports.jsxElementToJson)(node.right)].filter(nullable_1.checkIsDefined),
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
@@ -154,10 +154,11 @@ const jsxElementToJson = (node) => {
|
|
|
154
154
|
else if (types.isConditionalExpression(node)) {
|
|
155
155
|
// {foo ? <div /> : <span />} -> <Show when={foo} else={<span />}>...</Show>
|
|
156
156
|
const child = (0, exports.jsxElementToJson)(node.consequent);
|
|
157
|
+
const elseCase = (0, exports.jsxElementToJson)(node.alternate);
|
|
157
158
|
return (0, create_mitosis_node_1.createMitosisNode)({
|
|
158
159
|
name: 'Show',
|
|
159
160
|
meta: {
|
|
160
|
-
|
|
161
|
+
...((0, nullable_1.checkIsDefined)(elseCase) ? { else: elseCase } : undefined),
|
|
161
162
|
},
|
|
162
163
|
bindings: {
|
|
163
164
|
when: (0, bindings_1.createSingleBinding)({ code: (0, generator_1.default)(node.test, { compact: true }).code }),
|