@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.
- package/dist/src/__tests__/builder.test.js +71 -68
- package/dist/src/__tests__/context.test.js +13 -10
- package/dist/src/__tests__/data/basic.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/button-with-metadata.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/columns.raw.jsx +2 -2
- package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -3
- package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -3
- package/dist/src/__tests__/data/blocks/form.raw.jsx +5 -5
- package/dist/src/__tests__/data/blocks/image.raw.jsx +4 -4
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -4
- package/dist/src/__tests__/data/context/component-with-context.lite.jsx +2 -2
- package/dist/src/__tests__/data/context/simple.context.lite.js +1 -1
- package/dist/src/__tests__/html.test.js +2 -2
- package/dist/src/__tests__/liquid.test.js +34 -34
- package/dist/src/__tests__/parse-jsx.test.js +1 -1
- package/dist/src/__tests__/qwik.test.js +36 -36
- package/dist/src/__tests__/react-native.test.js +35 -35
- package/dist/src/__tests__/react.test.js +35 -35
- package/dist/src/__tests__/solid.test.js +32 -32
- package/dist/src/__tests__/vue.test.js +35 -34
- package/dist/src/generators/angular.d.ts +4 -7
- package/dist/src/generators/angular.js +77 -81
- package/dist/src/generators/builder.d.ts +4 -4
- package/dist/src/generators/builder.js +57 -57
- package/dist/src/generators/context/react.d.ts +3 -1
- package/dist/src/generators/context/react.js +20 -17
- package/dist/src/generators/html.d.ts +5 -9
- package/dist/src/generators/html.js +205 -199
- package/dist/src/generators/liquid.d.ts +5 -9
- package/dist/src/generators/liquid.js +62 -59
- package/dist/src/generators/mitosis.d.ts +6 -7
- package/dist/src/generators/mitosis.js +61 -63
- package/dist/src/generators/qwik/component.js +13 -13
- package/dist/src/generators/qwik/handlers.js +12 -8
- package/dist/src/generators/qwik/jsx.js +13 -9
- package/dist/src/generators/qwik/styles.js +11 -7
- package/dist/src/generators/react-native.d.ts +4 -7
- package/dist/src/generators/react-native.js +25 -22
- package/dist/src/generators/react.d.ts +4 -8
- package/dist/src/generators/react.js +103 -112
- package/dist/src/generators/solid.d.ts +4 -8
- package/dist/src/generators/solid.js +55 -54
- package/dist/src/generators/svelte.d.ts +4 -7
- package/dist/src/generators/svelte.js +120 -123
- package/dist/src/generators/swift-ui.d.ts +2 -2
- package/dist/src/generators/swift-ui.js +62 -62
- package/dist/src/generators/template.d.ts +4 -8
- package/dist/src/generators/template.js +48 -45
- package/dist/src/generators/vue.d.ts +9 -9
- package/dist/src/generators/vue.js +169 -169
- package/dist/src/helpers/babel-transform.js +9 -9
- package/dist/src/helpers/collect-styles.js +39 -39
- package/dist/src/helpers/dash-case.js +1 -1
- package/dist/src/helpers/generic-format.test.js +2 -2
- package/dist/src/helpers/get-components-used.js +2 -2
- package/dist/src/helpers/get-components.js +3 -3
- package/dist/src/helpers/get-props.js +1 -1
- package/dist/src/helpers/get-refs.js +2 -2
- package/dist/src/helpers/get-state-object-string.js +5 -5
- package/dist/src/helpers/get-state-used.js +1 -1
- package/dist/src/helpers/get-styles.js +1 -1
- package/dist/src/helpers/getters-to-functions.js +4 -4
- package/dist/src/helpers/handle-missing-state.js +1 -1
- package/dist/src/helpers/has-component.js +2 -2
- package/dist/src/helpers/has-props.js +1 -1
- package/dist/src/helpers/is-children.js +1 -1
- package/dist/src/helpers/json.d.ts +1 -0
- package/dist/src/helpers/json.js +17 -0
- package/dist/src/helpers/map-refs.js +4 -4
- package/dist/src/helpers/map-to-attributes.js +4 -4
- package/dist/src/helpers/map-to-css.js +2 -2
- package/dist/src/helpers/parse-node.js +2 -2
- package/dist/src/helpers/parse-reactive-script.js +4 -4
- package/dist/src/helpers/process-http-requests.js +1 -1
- package/dist/src/helpers/process-tag-references.js +4 -4
- package/dist/src/helpers/remove-surrounding-block.test.js +1 -1
- package/dist/src/helpers/render-imports.js +7 -7
- package/dist/src/helpers/replace-idenifiers.js +1 -1
- package/dist/src/helpers/strip-meta-properties.js +2 -2
- package/dist/src/helpers/trace-reference-to-module-path.js +1 -1
- package/dist/src/helpers/traverse-nodes.js +2 -2
- package/dist/src/helpers/try-prettier-format.js +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/modules/plugins.d.ts +2 -10
- package/dist/src/parsers/angular.js +13 -13
- package/dist/src/parsers/builder.js +54 -58
- package/dist/src/parsers/context.js +2 -2
- package/dist/src/parsers/jsx.js +59 -87
- package/dist/src/parsers/liquid.js +191 -194
- package/dist/src/plugins/compile-away-builder-components.js +49 -45
- package/dist/src/plugins/compile-away-components.js +3 -3
- package/dist/src/plugins/map-styles.js +3 -3
- package/dist/src/targets.d.ts +24 -0
- package/dist/src/targets.js +30 -0
- package/dist/src/types/config.d.ts +31 -0
- package/dist/src/types/{jsx-lite-component.js → config.js} +0 -0
- package/dist/{test/qwik/Todo/Todo.js/low.js → src/types/generators.d.ts} +0 -0
- package/dist/src/types/generators.js +1 -0
- package/dist/src/types/plugins.d.ts +11 -0
- package/dist/src/types/{jsx-lite-context.js → plugins.js} +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.cjs/high.cjs +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.cjs/low.cjs +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.cjs/med.cjs +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.js/high.js +0 -0
- package/dist/test/qwik/{qwik/todo → todo}/Todo.js/low.js +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.js/med.js +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.tsx/high.tsx +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/{Todo → todo}/Todo.tsx/med.tsx +0 -0
- package/dist/test/qwik/{Todos → todos}/Todo.tsx/high.tsx +0 -0
- package/dist/test/qwik/{Todos → todos}/Todo.tsx/low.tsx +0 -0
- package/dist/test/qwik/{Todos → todos}/Todo.tsx/med.tsx +0 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/__tests__/data/blocks/tabs.raw.d.ts +0 -11
- package/dist/src/__tests__/data/blocks/tabs.raw.jsx +0 -24
- package/dist/src/__tests__/qoot.test.d.ts +0 -1
- package/dist/src/__tests__/qoot.test.js +0 -115
- package/dist/src/generators/jsx-lite.d.ts +0 -10
- package/dist/src/generators/jsx-lite.js +0 -176
- package/dist/src/generators/qoot.d.ts +0 -21
- package/dist/src/generators/qoot.js +0 -442
- package/dist/src/generators/qwik.d.ts +0 -21
- package/dist/src/generators/qwik.js +0 -458
- package/dist/src/helpers/create-jsx-lite-component.d.ts +0 -2
- package/dist/src/helpers/create-jsx-lite-component.js +0 -16
- package/dist/src/helpers/create-jsx-lite-context.d.ts +0 -4
- package/dist/src/helpers/create-jsx-lite-context.js +0 -18
- package/dist/src/helpers/create-jsx-lite-node.d.ts +0 -2
- package/dist/src/helpers/create-jsx-lite-node.js +0 -16
- package/dist/src/helpers/is-jsx-lite-node.d.ts +0 -2
- package/dist/src/helpers/is-jsx-lite-node.js +0 -7
- package/dist/src/types/jsx-lite-component.d.ts +0 -63
- package/dist/src/types/jsx-lite-context.d.ts +0 -6
- package/dist/src/types/jsx-lite-node.d.ts +0 -13
- package/dist/src/types/jsx-lite-node.js +0 -2
- package/dist/src/types/jsx-lite-styles.d.ts +0 -1
- package/dist/src/types/jsx-lite-styles.js +0 -2
- package/dist/test/qoot/Todo/bundle.js +0 -88
- package/dist/test/qoot/Todo/component.ts +0 -17
- package/dist/test/qoot/Todo/onButtonClick.ts +0 -13
- package/dist/test/qoot/Todo/onInput2Blur.ts +0 -11
- package/dist/test/qoot/Todo/onInput2KeyUp.ts +0 -10
- package/dist/test/qoot/Todo/onInputClick.ts +0 -10
- package/dist/test/qoot/Todo/onLabelDblClick.ts +0 -11
- package/dist/test/qoot/Todo/public.ts +0 -4
- package/dist/test/qoot/Todo/template.tsx +0 -46
- package/dist/test/qoot/Todos/component.ts +0 -9
- package/dist/test/qoot/Todos/onInputClick.ts +0 -14
- package/dist/test/qoot/Todos/public.ts +0 -3
- package/dist/test/qoot/Todos/template.tsx +0 -30
- package/dist/test/qwik/Todo/bundle.js +0 -46
- package/dist/test/qwik/Todo/component.ts +0 -17
- package/dist/test/qwik/Todo/onButtonClick.ts +0 -10
- package/dist/test/qwik/Todo/onInput2Blur.ts +0 -14
- package/dist/test/qwik/Todo/onInput2KeyUp.ts +0 -10
- package/dist/test/qwik/Todo/onInputClick.ts +0 -13
- package/dist/test/qwik/Todo/onLabelDblClick.ts +0 -11
- package/dist/test/qwik/Todo/public.ts +0 -3
- package/dist/test/qwik/Todo/template.tsx +0 -46
- package/dist/test/qwik/Todo.ts +0 -4
- package/dist/test/qwik/Todo_component.ts +0 -17
- package/dist/test/qwik/Todo_onButtonClick.ts +0 -13
- package/dist/test/qwik/Todo_onInput2Blur.ts +0 -14
- package/dist/test/qwik/Todo_onInput2KeyUp.ts +0 -10
- package/dist/test/qwik/Todo_onInputClick.ts +0 -13
- package/dist/test/qwik/Todo_onLabelDblClick.ts +0 -14
- package/dist/test/qwik/Todo_template.tsx +0 -46
- package/dist/test/qwik/Todos/component.ts +0 -9
- package/dist/test/qwik/Todos/onInputClick.ts +0 -14
- package/dist/test/qwik/Todos/public.ts +0 -3
- package/dist/test/qwik/Todos/template.tsx +0 -30
- package/dist/test/qwik/Todos.ts +0 -3
- package/dist/test/qwik/Todos_component.ts +0 -9
- package/dist/test/qwik/Todos_onInputClick.ts +0 -14
- package/dist/test/qwik/Todos_template.tsx +0 -30
- package/dist/test/qwik/qwik/Image/high.js +0 -1
- package/dist/test/qwik/qwik/Image/low.js +0 -75
- package/dist/test/qwik/qwik/Image/med.js +0 -9
- package/dist/test/qwik/qwik/Image.slow/high.js +0 -1
- package/dist/test/qwik/qwik/Image.slow/low.js +0 -75
- package/dist/test/qwik/qwik/Image.slow/med.js +0 -9
- package/dist/test/qwik/qwik/button/high.js +0 -8
- package/dist/test/qwik/qwik/button/low.js +0 -34
- package/dist/test/qwik/qwik/button/med.js +0 -9
- package/dist/test/qwik/qwik/hello_world/stylesheet/high.jsx +0 -1
- package/dist/test/qwik/qwik/hello_world/stylesheet/low.jsx +0 -24
- package/dist/test/qwik/qwik/hello_world/stylesheet/med.jsx +0 -9
- package/dist/test/qwik/qwik/page-with-symbol/high.js +0 -1
- package/dist/test/qwik/qwik/page-with-symbol/low.js +0 -49
- package/dist/test/qwik/qwik/page-with-symbol/med.js +0 -9
- package/dist/test/qwik/qwik/svg/high.js +0 -1
- package/dist/test/qwik/qwik/svg/low.js +0 -30
- package/dist/test/qwik/qwik/svg/med.js +0 -9
- package/dist/test/qwik/qwik/todo/Todo.cjs/high.cjs +0 -31
- package/dist/test/qwik/qwik/todo/Todo.cjs/low.cjs +0 -1
- package/dist/test/qwik/qwik/todo/Todo.cjs/med.cjs +0 -59
- package/dist/test/qwik/qwik/todo/Todo.js/high.js +0 -5
- package/dist/test/qwik/qwik/todo/Todo.js/med.js +0 -1
- package/dist/test/qwik/qwik/todo/Todo.tsx/high.tsx +0 -30
- package/dist/test/qwik/qwik/todo/Todo.tsx/low.tsx +0 -1
- package/dist/test/qwik/qwik/todo/Todo.tsx/med.tsx +0 -34
- package/dist/test/qwik/qwik/todos/Todo.tsx/high.tsx +0 -12
- package/dist/test/qwik/qwik/todos/Todo.tsx/low.tsx +0 -24
- package/dist/test/qwik/qwik/todos/Todo.tsx/med.tsx +0 -8
|
@@ -3,23 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.contextToReact = void 0;
|
|
4
4
|
var standalone_1 = require("prettier/standalone");
|
|
5
5
|
var get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
6
|
-
function
|
|
6
|
+
var contextToReact = function (options) {
|
|
7
7
|
if (options === void 0) { options = {}; }
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
}
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return str;
|
|
24
|
-
}
|
|
25
|
+
return str;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
25
28
|
exports.contextToReact = contextToReact;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare type ToHtmlOptions = {
|
|
4
|
-
prettier?: boolean;
|
|
1
|
+
import { BaseTranspilerOptions, Transpiler } from '../types/config';
|
|
2
|
+
export interface ToHtmlOptions extends BaseTranspilerOptions {
|
|
5
3
|
format?: 'class' | 'script';
|
|
6
|
-
plugins?: Plugin[];
|
|
7
4
|
prefix?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const componentToHtml: (
|
|
10
|
-
export declare const componentToCustomElement: (
|
|
11
|
-
export {};
|
|
5
|
+
}
|
|
6
|
+
export declare const componentToHtml: (options?: ToHtmlOptions) => Transpiler;
|
|
7
|
+
export declare const componentToCustomElement: (options?: ToHtmlOptions) => Transpiler;
|
|
@@ -36,8 +36,8 @@ 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
38
|
var addUpdateAfterSet = function (json, options) {
|
|
39
|
-
traverse_1.default(json).forEach(function (item) {
|
|
40
|
-
if (is_mitosis_node_1.isMitosisNode(item)) {
|
|
39
|
+
(0, traverse_1.default)(json).forEach(function (item) {
|
|
40
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
41
41
|
for (var key in item.bindings) {
|
|
42
42
|
var value = item.bindings[key];
|
|
43
43
|
var newValue = addUpdateAfterSetInCode(value, options);
|
|
@@ -50,8 +50,8 @@ var addUpdateAfterSet = function (json, options) {
|
|
|
50
50
|
};
|
|
51
51
|
var getForNames = function (json) {
|
|
52
52
|
var names = [];
|
|
53
|
-
traverse_1.default(json).forEach(function (item) {
|
|
54
|
-
if (is_mitosis_node_1.isMitosisNode(item)) {
|
|
53
|
+
(0, traverse_1.default)(json).forEach(function (item) {
|
|
54
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
55
55
|
if (item.name === 'For') {
|
|
56
56
|
names.push(item.properties._forName);
|
|
57
57
|
}
|
|
@@ -62,16 +62,16 @@ var getForNames = function (json) {
|
|
|
62
62
|
var replaceForNameIdentifiers = function (json, options) {
|
|
63
63
|
// TODO: cache this. by reference? lru?
|
|
64
64
|
var forNames = getForNames(json);
|
|
65
|
-
traverse_1.default(json).forEach(function (item) {
|
|
66
|
-
if (is_mitosis_node_1.isMitosisNode(item)) {
|
|
65
|
+
(0, traverse_1.default)(json).forEach(function (item) {
|
|
66
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
67
67
|
for (var key in item.bindings) {
|
|
68
68
|
if (key === 'css' || key === '_forName') {
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
71
71
|
var value = item.bindings[key];
|
|
72
72
|
if (typeof value === 'string') {
|
|
73
|
-
item.bindings[key] = replace_idenifiers_1.replaceIdentifiers(value, forNames, function (name) {
|
|
74
|
-
return (options.format === 'class' ? 'this.' : ''
|
|
73
|
+
item.bindings[key] = (0, replace_idenifiers_1.replaceIdentifiers)(value, forNames, function (name) {
|
|
74
|
+
return "".concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(name, "\")");
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -85,17 +85,17 @@ var mappers = {
|
|
|
85
85
|
};
|
|
86
86
|
var getId = function (json, options) {
|
|
87
87
|
var name = json.properties.$name
|
|
88
|
-
? dash_case_1.dashCase(json.properties.$name)
|
|
88
|
+
? (0, dash_case_1.dashCase)(json.properties.$name)
|
|
89
89
|
: /^h\d$/.test(json.name || '') // don't dashcase h1 into h-1
|
|
90
90
|
? json.name
|
|
91
|
-
: dash_case_1.dashCase(json.name || 'div');
|
|
91
|
+
: (0, dash_case_1.dashCase)(json.name || 'div');
|
|
92
92
|
var newNameNum = (options.namesMap[name] || 0) + 1;
|
|
93
93
|
options.namesMap[name] = newNameNum;
|
|
94
|
-
return ""
|
|
94
|
+
return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '').concat(name !== json.name && newNameNum === 1 ? '' : "-".concat(newNameNum));
|
|
95
95
|
};
|
|
96
96
|
var updateReferencesInCode = function (code, options) {
|
|
97
97
|
if (options.format === 'class') {
|
|
98
|
-
return strip_state_and_props_refs_1.stripStateAndPropsRefs(strip_state_and_props_refs_1.stripStateAndPropsRefs(code, {
|
|
98
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
99
99
|
includeProps: false,
|
|
100
100
|
includeState: true,
|
|
101
101
|
replaceWith: 'this.state.',
|
|
@@ -125,16 +125,16 @@ var blockToHtml = function (json, options) {
|
|
|
125
125
|
if (mappers[json.name]) {
|
|
126
126
|
return mappers[json.name](json, options);
|
|
127
127
|
}
|
|
128
|
-
if (is_children_1.default(json)) {
|
|
128
|
+
if ((0, is_children_1.default)(json)) {
|
|
129
129
|
return "<slot></slot>";
|
|
130
130
|
}
|
|
131
131
|
if (json.properties._text) {
|
|
132
132
|
return json.properties._text;
|
|
133
133
|
}
|
|
134
134
|
if (json.bindings._text) {
|
|
135
|
-
addOnChangeJs(elId, options, "el.innerText = "
|
|
136
|
-
return "<span data-name=\""
|
|
137
|
-
._text.replace(/getContext\(el, "([^"]+)"\)/g, '$1')
|
|
135
|
+
addOnChangeJs(elId, options, "el.innerText = ".concat(json.bindings._text, ";"));
|
|
136
|
+
return "<span data-name=\"".concat(elId, "\"><!-- ").concat(json.bindings
|
|
137
|
+
._text.replace(/getContext\(el, "([^"]+)"\)/g, '$1'), " --></span>");
|
|
138
138
|
}
|
|
139
139
|
var str = '';
|
|
140
140
|
if (json.name === 'For') {
|
|
@@ -142,24 +142,24 @@ var blockToHtml = function (json, options) {
|
|
|
142
142
|
addOnChangeJs(elId, options,
|
|
143
143
|
// TODO: be smarter about rendering, deleting old items and adding new ones by
|
|
144
144
|
// querying dom potentially
|
|
145
|
-
"\n let array = "
|
|
145
|
+
"\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 "));
|
|
146
146
|
// TODO: decide on how to handle this...
|
|
147
|
-
str += "\n <span data-name=\""
|
|
147
|
+
str += "\n <span data-name=\"".concat(elId, "\"></span>\n <template data-template-for=\"").concat(elId, "\">");
|
|
148
148
|
if (json.children) {
|
|
149
149
|
str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
|
|
150
150
|
}
|
|
151
151
|
str += '</template>';
|
|
152
152
|
}
|
|
153
153
|
else if (json.name === 'Show') {
|
|
154
|
-
addOnChangeJs(elId, options, "el.style.display = "
|
|
155
|
-
str += "<span data-name=\""
|
|
154
|
+
addOnChangeJs(elId, options, "el.style.display = ".concat(json.bindings.when.replace(/;$/, ''), " ? 'inline' : 'none'"));
|
|
155
|
+
str += "<span data-name=\"".concat(elId, "\">");
|
|
156
156
|
if (json.children) {
|
|
157
157
|
str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
|
|
158
158
|
}
|
|
159
159
|
str += '</span>';
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
|
-
str += "<"
|
|
162
|
+
str += "<".concat(json.name, " ");
|
|
163
163
|
// For now, spread is not supported
|
|
164
164
|
// if (json.bindings._spread === '_spread') {
|
|
165
165
|
// str += `
|
|
@@ -178,7 +178,7 @@ var blockToHtml = function (json, options) {
|
|
|
178
178
|
var value = (json.properties[key] || '')
|
|
179
179
|
.replace(/"/g, '"')
|
|
180
180
|
.replace(/\n/g, '\\n');
|
|
181
|
-
str += " "
|
|
181
|
+
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
182
182
|
}
|
|
183
183
|
for (var key in json.bindings) {
|
|
184
184
|
if (key === '_spread' || key === 'ref' || key === 'css') {
|
|
@@ -189,25 +189,25 @@ var blockToHtml = function (json, options) {
|
|
|
189
189
|
var useValue = value;
|
|
190
190
|
if (key.startsWith('on')) {
|
|
191
191
|
var event_1 = key.replace('on', '').toLowerCase();
|
|
192
|
-
if (!is_component_1.isComponent(json) && event_1 === 'change') {
|
|
192
|
+
if (!(0, is_component_1.isComponent)(json) && event_1 === 'change') {
|
|
193
193
|
event_1 = 'input';
|
|
194
194
|
}
|
|
195
|
-
var fnName = lodash_1.camelCase("on-"
|
|
196
|
-
options.js += "\n // Event handler for '"
|
|
197
|
-
? "this."
|
|
198
|
-
: "function "
|
|
199
|
-
var fnIdentifier = ""
|
|
200
|
-
addOnChangeJs(elId, options, "\n ;el.removeEventListener('"
|
|
195
|
+
var fnName = (0, lodash_1.camelCase)("on-".concat(elId, "-").concat(event_1));
|
|
196
|
+
options.js += "\n // Event handler for '".concat(event_1, "' event on ").concat(elId, "\n ").concat(options.format === 'class'
|
|
197
|
+
? "this.".concat(fnName, " = (event) => {")
|
|
198
|
+
: "function ".concat(fnName, " (event) {"), "\n ").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options)), "\n }\n ");
|
|
199
|
+
var fnIdentifier = "".concat(options.format === 'class' ? 'this.' : '').concat(fnName);
|
|
200
|
+
addOnChangeJs(elId, options, "\n ;el.removeEventListener('".concat(event_1, "', ").concat(fnIdentifier, ");\n ;el.addEventListener('").concat(event_1, "', ").concat(fnIdentifier, ");\n "));
|
|
201
201
|
}
|
|
202
202
|
else {
|
|
203
203
|
if (key === 'style') {
|
|
204
|
-
addOnChangeJs(elId, options, ";Object.assign(el.style, "
|
|
204
|
+
addOnChangeJs(elId, options, ";Object.assign(el.style, ".concat(useValue, ");"));
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
207
207
|
var useAttribute = key.includes('-');
|
|
208
208
|
addOnChangeJs(elId, options, useAttribute
|
|
209
|
-
? ";el.setAttribute("
|
|
210
|
-
: ";el."
|
|
209
|
+
? ";el.setAttribute(".concat(key, ", ").concat(useValue, ");")
|
|
210
|
+
: ";el.".concat(key, " = ").concat(useValue));
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -222,14 +222,14 @@ var blockToHtml = function (json, options) {
|
|
|
222
222
|
// Maybe put some kind of safety here for broken HTML such as no close tag
|
|
223
223
|
str += htmlDecode(json.properties.innerHTML);
|
|
224
224
|
}
|
|
225
|
-
str += "</"
|
|
225
|
+
str += "</".concat(json.name, ">");
|
|
226
226
|
}
|
|
227
227
|
return str;
|
|
228
228
|
};
|
|
229
229
|
function addUpdateAfterSetInCode(code, options, useString) {
|
|
230
230
|
if (useString === void 0) { useString = options.format === 'class' ? 'this.update' : 'update'; }
|
|
231
231
|
var updates = 0;
|
|
232
|
-
return babel_transform_1.babelTransformExpression(code, {
|
|
232
|
+
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
233
233
|
AssignmentExpression: function (path) {
|
|
234
234
|
var node = path.node;
|
|
235
235
|
if (core_1.types.isMemberExpression(node.left)) {
|
|
@@ -263,182 +263,188 @@ function addUpdateAfterSetInCode(code, options, useString) {
|
|
|
263
263
|
}
|
|
264
264
|
var htmlDecode = function (html) { return html.replace(/"/gi, '"'); };
|
|
265
265
|
// TODO: props support via custom elements
|
|
266
|
-
var componentToHtml = function (
|
|
266
|
+
var componentToHtml = function (options) {
|
|
267
267
|
if (options === void 0) { options = {}; }
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
json =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
addUpdateAfterSet(json, useOptions);
|
|
275
|
-
var componentHasProps = has_props_1.hasProps(json);
|
|
276
|
-
var hasLoop = has_component_1.hasComponent('For', json);
|
|
277
|
-
if (options.plugins) {
|
|
278
|
-
json = plugins_1.runPostJsonPlugins(json, options.plugins);
|
|
279
|
-
}
|
|
280
|
-
var css = collect_styles_1.collectCss(json, {
|
|
281
|
-
prefix: options.prefix,
|
|
282
|
-
});
|
|
283
|
-
var str = json.children
|
|
284
|
-
.map(function (item) { return blockToHtml(item, useOptions); })
|
|
285
|
-
.join('\n');
|
|
286
|
-
if (css.trim().length) {
|
|
287
|
-
str += "<style>" + css + "</style>";
|
|
288
|
-
}
|
|
289
|
-
var hasChangeListeners = Boolean(Object.keys(useOptions.onChangeJsById).length);
|
|
290
|
-
var hasGeneratedJs = Boolean(useOptions.js.trim().length);
|
|
291
|
-
if (hasChangeListeners || hasGeneratedJs || json.hooks.onMount || hasLoop) {
|
|
292
|
-
// TODO: collectJs helper for here and liquid
|
|
293
|
-
str += "\n <script>\n (() => {\n const state = " + get_state_object_string_1.getStateObjectStringFromComponent(json, {
|
|
294
|
-
valueMapper: function (value) {
|
|
295
|
-
return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
|
|
296
|
-
},
|
|
297
|
-
}) + ";\n " + (componentHasProps ? "let props = {};" : '') + "\n\n " + (!hasChangeListeners
|
|
298
|
-
? ''
|
|
299
|
-
: "\n \n // Function to update data bindings and loops\n // call update() when you mutate state and need the updates to reflect\n // in the dom\n function update() {\n " + Object.keys(useOptions.onChangeJsById)
|
|
300
|
-
.map(function (key) {
|
|
301
|
-
var value = useOptions.onChangeJsById[key];
|
|
302
|
-
if (!value) {
|
|
303
|
-
return '';
|
|
304
|
-
}
|
|
305
|
-
return "\n document.querySelectorAll(\"[data-name='" + key + "']\").forEach((el) => {\n " + value + "\n })\n ";
|
|
306
|
-
})
|
|
307
|
-
.join('\n\n') + "\n }\n\n " + useOptions.js + "\n\n // Update with initial state on first load\n update();\n ") + "\n\n " + (!json.hooks.onMount
|
|
308
|
-
? ''
|
|
309
|
-
: // TODO: make prettier by grabbing only the function body
|
|
310
|
-
"\n // onMount\n " + updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions) + " \n ") + "\n\n " + (!hasLoop
|
|
311
|
-
? ''
|
|
312
|
-
: "\n\n // Helper to render loops\n function 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(function (child) {\n contextMap.set(child, {\n ...contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n // Helper to pass context down for loops\n let contextMap = new WeakMap();\n function getContext(el, name) {\n let parent = el;\n do {\n let context = contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ") + "\n })()\n </script>\n ";
|
|
313
|
-
}
|
|
314
|
-
if (options.plugins) {
|
|
315
|
-
str = plugins_1.runPreCodePlugins(str, options.plugins);
|
|
316
|
-
}
|
|
317
|
-
if (options.prettier !== false) {
|
|
318
|
-
try {
|
|
319
|
-
str = standalone_1.format(str, {
|
|
320
|
-
parser: 'html',
|
|
321
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
322
|
-
plugins: [
|
|
323
|
-
// To support running in browsers
|
|
324
|
-
require('prettier/parser-html'),
|
|
325
|
-
require('prettier/parser-postcss'),
|
|
326
|
-
require('prettier/parser-babel'),
|
|
327
|
-
],
|
|
328
|
-
});
|
|
268
|
+
return function (_a) {
|
|
269
|
+
var component = _a.component;
|
|
270
|
+
var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'script' });
|
|
271
|
+
var json = (0, fast_clone_1.fastClone)(component);
|
|
272
|
+
if (options.plugins) {
|
|
273
|
+
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
329
274
|
}
|
|
330
|
-
|
|
331
|
-
|
|
275
|
+
replaceForNameIdentifiers(json, useOptions);
|
|
276
|
+
addUpdateAfterSet(json, useOptions);
|
|
277
|
+
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
278
|
+
var hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
279
|
+
if (options.plugins) {
|
|
280
|
+
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
332
281
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
282
|
+
var css = (0, collect_styles_1.collectCss)(json, {
|
|
283
|
+
prefix: options.prefix,
|
|
284
|
+
});
|
|
285
|
+
var str = json.children
|
|
286
|
+
.map(function (item) { return blockToHtml(item, useOptions); })
|
|
287
|
+
.join('\n');
|
|
288
|
+
if (css.trim().length) {
|
|
289
|
+
str += "<style>".concat(css, "</style>");
|
|
290
|
+
}
|
|
291
|
+
var hasChangeListeners = Boolean(Object.keys(useOptions.onChangeJsById).length);
|
|
292
|
+
var hasGeneratedJs = Boolean(useOptions.js.trim().length);
|
|
293
|
+
if (hasChangeListeners || hasGeneratedJs || json.hooks.onMount || hasLoop) {
|
|
294
|
+
// TODO: collectJs helper for here and liquid
|
|
295
|
+
str += "\n <script>\n (() => {\n const state = ".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
296
|
+
valueMapper: function (value) {
|
|
297
|
+
return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
|
|
298
|
+
},
|
|
299
|
+
}), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\n\n ").concat(!hasChangeListeners
|
|
300
|
+
? ''
|
|
301
|
+
: "\n \n // Function to update data bindings and loops\n // call update() when you mutate state and need the updates to reflect\n // in the dom\n function update() {\n ".concat(Object.keys(useOptions.onChangeJsById)
|
|
302
|
+
.map(function (key) {
|
|
303
|
+
var value = useOptions.onChangeJsById[key];
|
|
304
|
+
if (!value) {
|
|
305
|
+
return '';
|
|
306
|
+
}
|
|
307
|
+
return "\n document.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(value, "\n })\n ");
|
|
308
|
+
})
|
|
309
|
+
.join('\n\n'), "\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!json.hooks.onMount
|
|
310
|
+
? ''
|
|
311
|
+
: // TODO: make prettier by grabbing only the function body
|
|
312
|
+
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions), " \n "), "\n\n ").concat(!hasLoop
|
|
313
|
+
? ''
|
|
314
|
+
: "\n\n // Helper to render loops\n function 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(function (child) {\n contextMap.set(child, {\n ...contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n // Helper to pass context down for loops\n let contextMap = new WeakMap();\n function getContext(el, name) {\n let parent = el;\n do {\n let context = contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ", "\n })()\n </script>\n ");
|
|
315
|
+
}
|
|
316
|
+
if (options.plugins) {
|
|
317
|
+
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
318
|
+
}
|
|
319
|
+
if (options.prettier !== false) {
|
|
320
|
+
try {
|
|
321
|
+
str = (0, standalone_1.format)(str, {
|
|
322
|
+
parser: 'html',
|
|
323
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
324
|
+
plugins: [
|
|
325
|
+
// To support running in browsers
|
|
326
|
+
require('prettier/parser-html'),
|
|
327
|
+
require('prettier/parser-postcss'),
|
|
328
|
+
require('prettier/parser-babel'),
|
|
329
|
+
],
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (options.plugins) {
|
|
337
|
+
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
338
|
+
}
|
|
339
|
+
return str;
|
|
340
|
+
};
|
|
338
341
|
};
|
|
339
342
|
exports.componentToHtml = componentToHtml;
|
|
340
343
|
// TODO: props support via custom elements
|
|
341
|
-
var componentToCustomElement = function (
|
|
344
|
+
var componentToCustomElement = function (options) {
|
|
342
345
|
if (options === void 0) { options = {}; }
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
json =
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
replaceForNameIdentifiers(json, useOptions);
|
|
350
|
-
addUpdateAfterSet(json, useOptions);
|
|
351
|
-
var hasLoop = has_component_1.hasComponent('For', json);
|
|
352
|
-
if (options.plugins) {
|
|
353
|
-
json = plugins_1.runPostJsonPlugins(json, options.plugins);
|
|
354
|
-
}
|
|
355
|
-
var css = collect_styles_1.collectCss(json, {
|
|
356
|
-
prefix: options.prefix,
|
|
357
|
-
});
|
|
358
|
-
strip_meta_properties_1.stripMetaProperties(json);
|
|
359
|
-
var html = json.children
|
|
360
|
-
.map(function (item) { return blockToHtml(item, useOptions); })
|
|
361
|
-
.join('\n');
|
|
362
|
-
html += "<style>" + css + "</style>";
|
|
363
|
-
if (options.prettier !== false) {
|
|
364
|
-
try {
|
|
365
|
-
html = standalone_1.format(html, {
|
|
366
|
-
parser: 'html',
|
|
367
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
368
|
-
plugins: [
|
|
369
|
-
// To support running in browsers
|
|
370
|
-
require('prettier/parser-html'),
|
|
371
|
-
require('prettier/parser-postcss'),
|
|
372
|
-
require('prettier/parser-babel'),
|
|
373
|
-
require('prettier/parser-typescript'),
|
|
374
|
-
],
|
|
375
|
-
});
|
|
376
|
-
html = html.trim().replace(/\n/g, '\n ');
|
|
346
|
+
return function (_a) {
|
|
347
|
+
var component = _a.component;
|
|
348
|
+
var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
|
|
349
|
+
var json = (0, fast_clone_1.fastClone)(component);
|
|
350
|
+
if (options.plugins) {
|
|
351
|
+
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
377
352
|
}
|
|
378
|
-
|
|
379
|
-
|
|
353
|
+
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
354
|
+
replaceForNameIdentifiers(json, useOptions);
|
|
355
|
+
addUpdateAfterSet(json, useOptions);
|
|
356
|
+
var hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
357
|
+
if (options.plugins) {
|
|
358
|
+
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
380
359
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
: // TODO: make prettier by grabbing only the function body
|
|
408
|
-
"\n // onMount\n " + updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions) + "\n ") + "\n }\n\n update() {\n " + Object.keys(useOptions.onChangeJsById)
|
|
409
|
-
.map(function (key) {
|
|
410
|
-
var value = useOptions.onChangeJsById[key];
|
|
411
|
-
if (!value) {
|
|
412
|
-
return '';
|
|
360
|
+
var css = (0, collect_styles_1.collectCss)(json, {
|
|
361
|
+
prefix: options.prefix,
|
|
362
|
+
});
|
|
363
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
364
|
+
var html = json.children
|
|
365
|
+
.map(function (item) { return blockToHtml(item, useOptions); })
|
|
366
|
+
.join('\n');
|
|
367
|
+
html += "<style>".concat(css, "</style>");
|
|
368
|
+
if (options.prettier !== false) {
|
|
369
|
+
try {
|
|
370
|
+
html = (0, standalone_1.format)(html, {
|
|
371
|
+
parser: 'html',
|
|
372
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
373
|
+
plugins: [
|
|
374
|
+
// To support running in browsers
|
|
375
|
+
require('prettier/parser-html'),
|
|
376
|
+
require('prettier/parser-postcss'),
|
|
377
|
+
require('prettier/parser-babel'),
|
|
378
|
+
require('prettier/parser-typescript'),
|
|
379
|
+
],
|
|
380
|
+
});
|
|
381
|
+
html = html.trim().replace(/\n/g, '\n ');
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
console.warn('Could not prettify', { string: html }, err);
|
|
385
|
+
}
|
|
413
386
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
387
|
+
var kebabName = component.name
|
|
388
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
389
|
+
.toLowerCase();
|
|
390
|
+
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, {
|
|
391
|
+
valueMapper: function (value) {
|
|
392
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
|
|
393
|
+
includeProps: false,
|
|
394
|
+
includeState: true,
|
|
395
|
+
// TODO: if it's an arrow function it's this.state.
|
|
396
|
+
replaceWith: 'self.state.',
|
|
397
|
+
}), {
|
|
398
|
+
// TODO: replace with `this.` and add setters that call this.update()
|
|
399
|
+
includeProps: true,
|
|
400
|
+
includeState: false,
|
|
401
|
+
replaceWith: 'self.props.',
|
|
402
|
+
});
|
|
403
|
+
},
|
|
404
|
+
}), ";\n ").concat(componentHasProps /* TODO: accept these as attributes/properties on the custom element */
|
|
405
|
+
? "this.props = {};"
|
|
406
|
+
: '', "\n\n ").concat(!hasLoop
|
|
407
|
+
? ''
|
|
408
|
+
: "\n // Helper to pass context down for loops\n this.contextMap = new WeakMap();\n ", "\n\n ").concat(useOptions.js, "\n }\n\n ").concat(!json.hooks.onUnMount
|
|
409
|
+
? ''
|
|
410
|
+
: "\n disconnectedCallback() {\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount, useOptions), useOptions), "\n }\n "), "\n\n connectedCallback() {\n this.innerHTML = `\n ").concat(html, "`;\n this.update();\n\n ").concat(!json.hooks.onMount
|
|
411
|
+
? ''
|
|
412
|
+
: // TODO: make prettier by grabbing only the function body
|
|
413
|
+
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount, useOptions), useOptions), "\n "), "\n }\n\n update() {\n ").concat(Object.keys(useOptions.onChangeJsById)
|
|
414
|
+
.map(function (key) {
|
|
415
|
+
var value = useOptions.onChangeJsById[key];
|
|
416
|
+
if (!value) {
|
|
417
|
+
return '';
|
|
418
|
+
}
|
|
419
|
+
return "\n this.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(updateReferencesInCode(value, useOptions), "\n })\n ");
|
|
420
|
+
})
|
|
421
|
+
.join('\n\n'), "\n }\n\n ").concat(!hasLoop
|
|
422
|
+
? ''
|
|
423
|
+
: "\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 ");
|
|
424
|
+
if (options.plugins) {
|
|
425
|
+
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
426
|
+
}
|
|
427
|
+
if (options.prettier !== false) {
|
|
428
|
+
try {
|
|
429
|
+
str = (0, standalone_1.format)(str, {
|
|
430
|
+
parser: 'typescript',
|
|
431
|
+
plugins: [
|
|
432
|
+
// To support running in browsers
|
|
433
|
+
require('prettier/parser-html'),
|
|
434
|
+
require('prettier/parser-postcss'),
|
|
435
|
+
require('prettier/parser-babel'),
|
|
436
|
+
require('prettier/parser-typescript'),
|
|
437
|
+
],
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
catch (err) {
|
|
441
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
442
|
+
}
|
|
434
443
|
}
|
|
435
|
-
|
|
436
|
-
|
|
444
|
+
if (options.plugins) {
|
|
445
|
+
str = (0, plugins_1.runPostCodePlugins)(str, options.plugins);
|
|
437
446
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
str = plugins_1.runPostCodePlugins(str, options.plugins);
|
|
441
|
-
}
|
|
442
|
-
return str;
|
|
447
|
+
return str;
|
|
448
|
+
};
|
|
443
449
|
};
|
|
444
450
|
exports.componentToCustomElement = componentToCustomElement;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BaseTranspilerOptions, Transpiler } from '../types/config';
|
|
2
|
+
export interface ToLiquidOptions extends BaseTranspilerOptions {
|
|
3
|
+
reactive?: boolean;
|
|
4
|
+
}
|
|
3
5
|
/**
|
|
4
6
|
* Test if the binding expression would be likely to generate
|
|
5
7
|
* valid or invalid liquid. If we generate invalid liquid tags
|
|
6
8
|
* Shopify will reject our PUT to update the template
|
|
7
9
|
*/
|
|
8
10
|
export declare const isValidLiquidBinding: (str?: string) => boolean;
|
|
9
|
-
declare
|
|
10
|
-
prettier?: boolean;
|
|
11
|
-
plugins?: Plugin[];
|
|
12
|
-
reactive?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare const componentToLiquid: (componentJson: MitosisComponent, options?: ToLiquidOptions) => string;
|
|
15
|
-
export {};
|
|
11
|
+
export declare const componentToLiquid: (options?: ToLiquidOptions) => Transpiler;
|