@builder.io/mitosis 0.0.56-46 → 0.0.56-49
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__/data/blocks/stamped-io.raw.jsx +2 -1
- package/dist/src/generators/marko/generate.js +6 -8
- package/dist/src/generators/qwik/add-prevent-default.d.ts +7 -0
- package/dist/src/generators/qwik/add-prevent-default.js +32 -0
- package/dist/src/generators/qwik/component-generator.js +2 -0
- package/dist/src/generators/stencil/collect-class-string.d.ts +1 -1
- package/dist/src/generators/stencil/collect-class-string.js +5 -3
- package/dist/src/helpers/get-custom-imports.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -31,7 +31,8 @@ function SmileReviews(props) {
|
|
|
31
31
|
<input css={{ display: 'block' }} placeholder="Title"/>
|
|
32
32
|
|
|
33
33
|
<textarea css={{ display: 'block' }} placeholder="How was your experience?"/>
|
|
34
|
-
<button css={{ display: 'block' }} onClick={function () {
|
|
34
|
+
<button css={{ display: 'block' }} onClick={function (event) {
|
|
35
|
+
event.preventDefault();
|
|
35
36
|
state.showReviewPrompt = false;
|
|
36
37
|
}}>
|
|
37
38
|
Submit
|
|
@@ -27,7 +27,6 @@ var jsx_1 = require("../../parsers/jsx");
|
|
|
27
27
|
var plugins_1 = require("../../modules/plugins");
|
|
28
28
|
var fast_clone_1 = require("../../helpers/fast-clone");
|
|
29
29
|
var strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
30
|
-
var collect_class_string_1 = require("../stencil/collect-class-string");
|
|
31
30
|
var strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
32
31
|
var filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
33
32
|
var collect_css_1 = require("../../helpers/styles/collect-css");
|
|
@@ -115,10 +114,6 @@ var blockToMarko = function (json, options) {
|
|
|
115
114
|
}
|
|
116
115
|
var str = '';
|
|
117
116
|
str += "<".concat(toTagName(json.name), " ");
|
|
118
|
-
var classString = (0, collect_class_string_1.collectClassString)(json);
|
|
119
|
-
if (classString) {
|
|
120
|
-
str += " class=".concat(classString, " ");
|
|
121
|
-
}
|
|
122
117
|
if ((_e = json.bindings._spread) === null || _e === void 0 ? void 0 : _e.code) {
|
|
123
118
|
str += " ...(".concat(json.bindings._spread.code, ") ");
|
|
124
119
|
}
|
|
@@ -246,8 +241,11 @@ var componentToMarko = function (userOptions) {
|
|
|
246
241
|
console.warn('Could not format js', err);
|
|
247
242
|
}
|
|
248
243
|
}
|
|
249
|
-
|
|
250
|
-
|
|
244
|
+
htmlString = htmlString
|
|
245
|
+
// Convert on-click=(...) -> on-click(...)
|
|
246
|
+
.replace(/(on-[a-z]+)=\(/g, function (_match, group) { return group + '('; })
|
|
247
|
+
// Fix a weird edge case where </if> becomes </if \n > which is invalid in marko
|
|
248
|
+
.replace(/<\/([a-z]+)\s+>/g, '</$1>');
|
|
251
249
|
var finalStr = "\n".concat(jsString, "\n").concat(cssString, "\n").concat(htmlString, "\n ")
|
|
252
250
|
.replace(/\n{3,}/g, '\n\n')
|
|
253
251
|
.trim();
|
|
@@ -297,7 +295,7 @@ exports.preprocessHtml = preprocessHtml;
|
|
|
297
295
|
function postprocessHtml(htmlString) {
|
|
298
296
|
return htmlString
|
|
299
297
|
.replace(/<for \|/g, '<for|')
|
|
300
|
-
.replace(/<if _="([\s\S]
|
|
298
|
+
.replace(/<if _="([\s\S]+?)"\s*>/g, function (_match, group) {
|
|
301
299
|
return "<if(".concat(decodeAttributeValue(group), ")>");
|
|
302
300
|
})
|
|
303
301
|
.replace(/="\(([\s\S]*?)\)"(\s*[a-z\/>])/g, function (_match, group, after) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MitosisComponent } from '../../types/mitosis-component';
|
|
2
|
+
/**
|
|
3
|
+
* Find event handlers that explicitly call .preventDefault() and
|
|
4
|
+
* add preventdefault:event
|
|
5
|
+
* https://qwik.builder.io/tutorial/events/preventdefault
|
|
6
|
+
*/
|
|
7
|
+
export declare function addPreventDefault(json: MitosisComponent): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addPreventDefault = void 0;
|
|
7
|
+
var traverse_1 = __importDefault(require("traverse"));
|
|
8
|
+
var is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
9
|
+
/**
|
|
10
|
+
* Find event handlers that explicitly call .preventDefault() and
|
|
11
|
+
* add preventdefault:event
|
|
12
|
+
* https://qwik.builder.io/tutorial/events/preventdefault
|
|
13
|
+
*/
|
|
14
|
+
function addPreventDefault(json) {
|
|
15
|
+
(0, traverse_1.default)(json).forEach(function (node) {
|
|
16
|
+
var _a;
|
|
17
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(node)) {
|
|
18
|
+
if (node.bindings) {
|
|
19
|
+
for (var _i = 0, _b = Object.keys(node.bindings); _i < _b.length; _i++) {
|
|
20
|
+
var key = _b[_i];
|
|
21
|
+
if (key.startsWith('on')) {
|
|
22
|
+
if ((_a = node.bindings[key]) === null || _a === void 0 ? void 0 : _a.code.includes('.preventDefault()')) {
|
|
23
|
+
var event_1 = key.slice(2).toLowerCase();
|
|
24
|
+
node.properties['preventdefault:' + event_1] = '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.addPreventDefault = addPreventDefault;
|
|
@@ -16,6 +16,7 @@ var jsx_1 = require("./jsx");
|
|
|
16
16
|
var src_generator_1 = require("./src-generator");
|
|
17
17
|
var babel_transform_1 = require("../../helpers/babel-transform");
|
|
18
18
|
var fast_clone_1 = require("../../helpers/fast-clone");
|
|
19
|
+
var add_prevent_default_1 = require("./add-prevent-default");
|
|
19
20
|
Error.stackTraceLimit = 9999;
|
|
20
21
|
// TODO(misko): styles are not processed.
|
|
21
22
|
var DEBUG = false;
|
|
@@ -25,6 +26,7 @@ var componentToQwik = function (userOptions) {
|
|
|
25
26
|
var _component = _a.component, path = _a.path;
|
|
26
27
|
// Make a copy we can safely mutate, similar to babel's toolchain
|
|
27
28
|
var component = (0, fast_clone_1.fastClone)(_component);
|
|
29
|
+
(0, add_prevent_default_1.addPreventDefault)(component);
|
|
28
30
|
var file = new src_generator_1.File(component.name + '.js', {
|
|
29
31
|
isPretty: true,
|
|
30
32
|
isJSX: true,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { MitosisNode } from '../../types/mitosis-node';
|
|
2
|
-
export declare function collectClassString(json: MitosisNode): string | null;
|
|
2
|
+
export declare function collectClassString(json: MitosisNode, bindingOpenChar?: string, bindingCloseChar?: string): string | null;
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.collectClassString = void 0;
|
|
4
4
|
// This should really be a preprocessor mapping the `class` attribute binding based on what other values have
|
|
5
5
|
// to make this more pluggable
|
|
6
|
-
function collectClassString(json) {
|
|
6
|
+
function collectClassString(json, bindingOpenChar, bindingCloseChar) {
|
|
7
7
|
var _a, _b;
|
|
8
|
+
if (bindingOpenChar === void 0) { bindingOpenChar = '{'; }
|
|
9
|
+
if (bindingCloseChar === void 0) { bindingCloseChar = '}'; }
|
|
8
10
|
var staticClasses = [];
|
|
9
11
|
var hasStaticClasses = Boolean(staticClasses.length);
|
|
10
12
|
if (json.properties.class) {
|
|
@@ -31,10 +33,10 @@ function collectClassString(json) {
|
|
|
31
33
|
return "\"".concat(staticClassesString, "\"");
|
|
32
34
|
}
|
|
33
35
|
if (hasDynamicClasses && !hasStaticClasses) {
|
|
34
|
-
return "
|
|
36
|
+
return "".concat(bindingOpenChar).concat(dynamicClassesString).concat(bindingCloseChar);
|
|
35
37
|
}
|
|
36
38
|
if (hasDynamicClasses && hasStaticClasses) {
|
|
37
|
-
return "
|
|
39
|
+
return "".concat(bindingOpenChar, "\"").concat(staticClassesString, " \" + ").concat(dynamicClassesString).concat(bindingCloseChar);
|
|
38
40
|
}
|
|
39
41
|
return null;
|
|
40
42
|
}
|
|
@@ -25,7 +25,7 @@ function getCustomImports(json) {
|
|
|
25
25
|
// This is imperfect. Basically, if the string of this import name
|
|
26
26
|
// doesn't occur at all, it's definitely not used. If it does, it might.
|
|
27
27
|
// So this simple check helps us ~90% of the time not over-add imports
|
|
28
|
-
// to templates. Arguably "good enough" for now, as there is generally no
|
|
28
|
+
// to templates. Arguably "good enough" for now, as there is generally no
|
|
29
29
|
// consequence to over adding here, and it would be a lot more performance expensive
|
|
30
30
|
// during compilation to do a complete AST parse and look for real references
|
|
31
31
|
.filter(function (item) { return blocksString.includes(item); });
|