@builder.io/mitosis 0.0.56-13 → 0.0.56-16
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__/angular.test.js +2 -104
- package/dist/src/__tests__/builder.test.js +3 -3
- package/dist/src/__tests__/data/basic-child-component.raw.jsx +1 -2
- package/dist/src/__tests__/data/basic-context.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-context.raw.jsx +29 -0
- package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-custom-mitosis-package.raw.jsx +10 -0
- package/dist/src/__tests__/data/basic-for-show.raw.jsx +2 -3
- package/dist/src/__tests__/data/basic-for.raw.jsx +2 -3
- package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.d.ts +5 -0
- package/dist/src/__tests__/data/basic-forwardRef-metadata.raw.jsx +17 -0
- package/dist/src/__tests__/data/basic-forwardRef.raw.d.ts +5 -0
- package/dist/src/__tests__/data/basic-forwardRef.raw.jsx +14 -0
- package/dist/src/__tests__/data/basic-onChange.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-onChange.raw.jsx +17 -0
- package/dist/src/__tests__/data/basic-onMount-update.raw.jsx +1 -1
- package/dist/src/__tests__/data/basic-onUpdate-return.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-onUpdate-return.raw.jsx +24 -0
- package/dist/src/__tests__/data/basic-outputs-meta.raw.jsx +1 -1
- package/dist/src/__tests__/data/basic-outputs.raw.jsx +1 -1
- package/dist/src/__tests__/data/basic-preserve-export-or-local-statement.raw.d.ts +6 -0
- package/dist/src/__tests__/data/basic-preserve-export-or-local-statement.raw.jsx +14 -0
- package/dist/src/__tests__/data/basic-props-destructure.raw.d.ts +6 -0
- package/dist/src/__tests__/data/basic-props-destructure.raw.jsx +14 -0
- package/dist/src/__tests__/data/basic-props.raw.d.ts +6 -0
- package/dist/src/__tests__/data/basic-props.raw.jsx +13 -0
- package/dist/src/__tests__/data/basic-ref-assignment.raw.d.ts +4 -0
- package/dist/src/__tests__/data/basic-ref-assignment.raw.jsx +15 -0
- package/dist/src/__tests__/data/basic-ref-usePrevious.raw.d.ts +5 -0
- package/dist/src/__tests__/data/basic-ref-usePrevious.raw.jsx +35 -0
- package/dist/src/__tests__/data/basic-ref.raw.d.ts +4 -0
- package/dist/src/__tests__/data/basic-ref.raw.jsx +36 -0
- package/dist/src/__tests__/data/basic.raw.d.ts +6 -1
- package/dist/src/__tests__/data/basic.raw.jsx +10 -3
- package/dist/src/__tests__/data/blocks/classname-jsx.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/columns.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -7
- package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -7
- package/dist/src/__tests__/data/blocks/form.raw.jsx +3 -3
- package/dist/src/__tests__/data/blocks/image.raw.jsx +8 -9
- package/dist/src/__tests__/data/blocks/img-state.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/input.raw.jsx +1 -3
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +7 -1
- package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +8 -1
- package/dist/src/__tests__/data/blocks/onInit.raw.jsx +13 -3
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/section-state.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/select.raw.jsx +1 -3
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +2 -4
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +2 -4
- package/dist/src/__tests__/data/blocks/text.raw.jsx +2 -5
- package/dist/src/__tests__/data/styles/class-and-className.raw.jsx +1 -3
- package/dist/src/__tests__/data/styles/className.raw.jsx +1 -3
- package/dist/src/__tests__/data/styles/classState.raw.d.ts +1 -0
- package/dist/src/__tests__/data/styles/classState.raw.jsx +12 -0
- package/dist/src/__tests__/data/types/component-props-interface.raw.d.ts +6 -0
- package/dist/src/__tests__/data/types/component-props-interface.raw.jsx +6 -0
- package/dist/src/__tests__/data/types/component-props-type.raw.d.ts +6 -0
- package/dist/src/__tests__/data/types/component-props-type.raw.jsx +6 -0
- package/dist/src/__tests__/data/types/preserve-typing.raw.d.ts +8 -0
- package/dist/src/__tests__/data/types/preserve-typing.raw.jsx +6 -0
- package/dist/src/__tests__/html.test.js +2 -145
- package/dist/src/__tests__/liquid.test.js +2 -109
- package/dist/src/__tests__/parse-jsx.test.js +22 -0
- package/dist/src/__tests__/qwik/convertMethodToFunction.test.d.ts +1 -0
- package/dist/src/__tests__/qwik/convertMethodToFunction.test.js +34 -0
- package/dist/src/__tests__/qwik/src-generator.test.d.ts +1 -0
- package/dist/src/__tests__/qwik/src-generator.test.js +65 -0
- package/dist/src/__tests__/qwik.test.js +44 -21
- package/dist/src/__tests__/react-native.test.js +2 -135
- package/dist/src/__tests__/react.test.js +5 -177
- package/dist/src/__tests__/shared.d.ts +3 -0
- package/dist/src/__tests__/shared.js +224 -0
- package/dist/src/__tests__/solid.test.js +2 -103
- package/dist/src/__tests__/stencil.test.js +3 -98
- package/dist/src/__tests__/styles.test.js +9 -1
- package/dist/src/__tests__/svelte.test.js +6 -0
- package/dist/src/__tests__/vue.test.js +2 -134
- package/dist/src/__tests__/webcomponent.test.js +6 -165
- package/dist/src/constants/hooks.d.ts +6 -0
- package/dist/src/constants/hooks.js +9 -0
- package/dist/src/generators/angular.d.ts +1 -1
- package/dist/src/generators/angular.js +66 -34
- package/dist/src/generators/builder.d.ts +1 -1
- package/dist/src/generators/builder.js +6 -12
- package/dist/src/generators/context/{react copy.d.ts → qwik.d.ts} +2 -2
- package/dist/src/generators/context/{react copy.js → qwik.js} +4 -5
- package/dist/src/generators/context/svelte.d.ts +1 -1
- package/dist/src/generators/helpers/context.js +1 -2
- package/dist/src/generators/html.d.ts +1 -1
- package/dist/src/generators/html.js +206 -120
- package/dist/src/generators/liquid.d.ts +1 -1
- package/dist/src/generators/liquid.js +6 -14
- package/dist/src/generators/mitosis.d.ts +1 -1
- package/dist/src/generators/mitosis.js +30 -29
- package/dist/src/generators/qwik/component-generator.d.ts +4 -0
- package/dist/src/generators/qwik/component-generator.js +271 -0
- package/dist/src/generators/qwik/component.js +4 -5
- package/dist/src/generators/qwik/convertMethodToFunction.d.ts +1 -0
- package/dist/src/generators/qwik/convertMethodToFunction.js +161 -0
- package/dist/src/generators/qwik/directives.js +20 -18
- package/dist/src/generators/qwik/index.d.ts +3 -1
- package/dist/src/generators/qwik/index.js +3 -1
- package/dist/src/generators/qwik/jsx.js +10 -6
- package/dist/src/generators/qwik/src-generator.d.ts +19 -7
- package/dist/src/generators/qwik/src-generator.js +149 -31
- package/dist/src/generators/qwik/styles.js +1 -2
- package/dist/src/generators/react-native.d.ts +2 -2
- package/dist/src/generators/react-native.js +3 -6
- package/dist/src/generators/react.d.ts +4 -2
- package/dist/src/generators/react.js +88 -68
- package/dist/src/generators/solid.d.ts +1 -1
- package/dist/src/generators/solid.js +9 -12
- package/dist/src/generators/stencil/generate.d.ts +1 -1
- package/dist/src/generators/stencil/generate.js +5 -11
- package/dist/src/generators/svelte.d.ts +1 -1
- package/dist/src/generators/svelte.js +19 -26
- package/dist/src/generators/swift-ui.d.ts +1 -1
- package/dist/src/generators/swift-ui.js +6 -12
- package/dist/src/generators/template.d.ts +1 -1
- package/dist/src/generators/template.js +6 -14
- package/dist/src/generators/vue.d.ts +12 -6
- package/dist/src/generators/vue.js +62 -31
- package/dist/src/helpers/babel-transform.js +3 -8
- package/dist/src/helpers/create-mitosis-component.d.ts +1 -1
- package/dist/src/helpers/create-mitosis-component.js +1 -1
- package/dist/src/helpers/fast-clone.js +1 -3
- package/dist/src/helpers/filter-empty-text-nodes.js +1 -2
- package/dist/src/helpers/get-bindings.d.ts +2 -0
- package/dist/src/helpers/get-bindings.js +18 -0
- package/dist/src/helpers/get-props-ref.d.ts +2 -0
- package/dist/src/helpers/get-props-ref.js +32 -0
- package/dist/src/helpers/getters-to-functions.d.ts +1 -1
- package/dist/src/helpers/getters-to-functions.js +1 -1
- package/dist/src/helpers/has-bindings-text.d.ts +2 -0
- package/dist/src/helpers/has-bindings-text.js +21 -0
- package/dist/src/helpers/has-stateful-dom.d.ts +2 -0
- package/dist/src/helpers/has-stateful-dom.js +21 -0
- package/dist/src/helpers/is-children.js +1 -2
- package/dist/src/helpers/is-component.js +1 -3
- package/dist/src/helpers/is-html-attribute.d.ts +1 -1
- package/dist/src/helpers/is-html-attribute.js +4 -19
- package/dist/src/helpers/map-refs.js +4 -1
- package/dist/src/helpers/parsers.js +1 -2
- package/dist/src/helpers/render-imports.d.ts +18 -2
- package/dist/src/helpers/render-imports.js +86 -45
- package/dist/src/helpers/render-imports.test.d.ts +1 -0
- package/dist/src/helpers/render-imports.test.js +19 -0
- package/dist/src/helpers/replace-idenifiers.js +2 -5
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +2 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +5 -8
- package/dist/src/helpers/styles/collect-css.d.ts +6 -0
- package/dist/src/helpers/styles/collect-css.js +87 -0
- package/dist/src/helpers/styles/collect-css.test.d.ts +1 -0
- package/dist/src/helpers/styles/collect-css.test.js +18 -0
- package/dist/src/helpers/styles/collect-styled-components.d.ts +2 -0
- package/dist/src/helpers/styles/collect-styled-components.js +61 -0
- package/dist/src/helpers/styles/helpers.d.ts +30 -0
- package/dist/src/helpers/styles/helpers.js +61 -0
- package/dist/src/helpers/typescript.d.ts +2 -0
- package/dist/src/helpers/typescript.js +2 -0
- package/dist/src/index.d.ts +7 -4
- package/dist/src/index.js +24 -8
- package/dist/src/jsx-types.d.ts +1 -0
- package/dist/src/modules/plugins.d.ts +1 -1
- package/dist/src/parsers/angular.js +10 -28
- package/dist/src/parsers/builder.d.ts +23 -23
- package/dist/src/parsers/builder.js +15 -33
- package/dist/src/parsers/jsx.d.ts +2 -1
- package/dist/src/parsers/jsx.js +214 -64
- package/dist/src/parsers/liquid.js +51 -149
- package/dist/src/plugins/compile-away-builder-components.js +4 -10
- package/dist/src/symbols/symbol-processor.js +4 -6
- package/dist/src/targets.d.ts +5 -3
- package/dist/src/targets.js +7 -1
- package/dist/src/types/config.d.ts +37 -17
- package/dist/src/types/mitosis-component.d.ts +30 -10
- package/dist/src/types/transpiler.d.ts +14 -0
- package/dist/src/types/transpiler.js +2 -0
- package/dist/test/qwik/Accordion/low.jsx +1 -0
- package/dist/test/qwik/For/low.jsx +1 -0
- package/dist/test/qwik/Image/med.js +2 -1
- package/dist/test/qwik/Image.slow/med.js +2 -1
- package/dist/test/qwik/bindings/low.cjs +3 -2
- package/dist/test/qwik/button/low.js +1 -0
- package/dist/test/qwik/component/bindings/low.jsx +2 -1
- package/dist/test/qwik/component/component/inputs/med.cjsx +2 -1
- package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
- package/dist/test/qwik/for-loop.bindings/low.cjs +47 -0
- package/dist/test/qwik/for-loop.bindings/med.cjs +5 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +1 -0
- package/dist/test/qwik/mount/high.cjs +0 -0
- package/dist/test/qwik/mount/low.cjs +44 -0
- package/dist/test/qwik/mount/med.cjs +3 -0
- package/dist/test/qwik/page-with-symbol/low.js +1 -0
- package/dist/test/qwik/show-hide/med.jsx +2 -1
- package/dist/test/qwik/svg/low.js +1 -0
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +1 -0
- package/dist/test/qwik/todo/Todo.js/med.js +1 -0
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +1 -0
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/README.md +0 -239
- package/dist/src/__tests__/data/blocks/content-slot.raw.d.ts +0 -6
- package/dist/src/__tests__/data/blocks/content-slot.raw.jsx +0 -13
- package/dist/src/__tests__/data/blocks/onUpdate.raw copy.d.ts +0 -1
- package/dist/src/__tests__/data/blocks/onUpdate.raw copy.jsx +0 -10
- package/dist/src/__tests__/data/blocks/slot.raw.d.ts +0 -5
- package/dist/src/__tests__/data/blocks/slot.raw.jsx +0 -6
- package/dist/src/__tests__/data/blocks/styles.raw.d.ts +0 -1
- package/dist/src/__tests__/data/blocks/styles.raw.jsx +0 -10
- package/dist/src/helpers/babel-transform copy.d.ts +0 -8
- package/dist/src/helpers/babel-transform copy.js +0 -138
- package/dist/src/helpers/collect-styles.d.ts +0 -29
- package/dist/src/helpers/collect-styles.js +0 -176
|
@@ -29,18 +29,22 @@ var lodash_1 = require("lodash");
|
|
|
29
29
|
var lodash_2 = require("lodash");
|
|
30
30
|
var standalone_1 = require("prettier/standalone");
|
|
31
31
|
var has_props_1 = require("../helpers/has-props");
|
|
32
|
+
var has_stateful_dom_1 = require("../helpers/has-stateful-dom");
|
|
33
|
+
var get_refs_1 = require("../helpers/get-refs");
|
|
34
|
+
var map_refs_1 = require("../helpers/map-refs");
|
|
32
35
|
var traverse_1 = __importDefault(require("traverse"));
|
|
33
36
|
var babel_transform_1 = require("../helpers/babel-transform");
|
|
34
|
-
var
|
|
37
|
+
var collect_css_1 = require("../helpers/styles/collect-css");
|
|
35
38
|
var dash_case_1 = require("../helpers/dash-case");
|
|
36
39
|
var fast_clone_1 = require("../helpers/fast-clone");
|
|
37
40
|
var get_state_object_string_1 = require("../helpers/get-state-object-string");
|
|
38
41
|
var has_component_1 = require("../helpers/has-component");
|
|
42
|
+
var has_bindings_text_1 = require("../helpers/has-bindings-text");
|
|
39
43
|
var is_component_1 = require("../helpers/is-component");
|
|
40
44
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
41
45
|
var is_html_attribute_1 = require("../helpers/is-html-attribute");
|
|
42
|
-
var is_valid_attribute_name_1 = require("../helpers/is-valid-attribute-name");
|
|
43
46
|
var get_props_1 = require("../helpers/get-props");
|
|
47
|
+
var get_props_ref_1 = require("../helpers/get-props-ref");
|
|
44
48
|
var get_prop_functions_1 = require("../helpers/get-prop-functions");
|
|
45
49
|
var jsx_1 = require("../parsers/jsx");
|
|
46
50
|
var strip_state_and_props_refs_1 = require("../helpers/strip-state-and-props-refs");
|
|
@@ -54,6 +58,7 @@ var isAttribute = function (key) {
|
|
|
54
58
|
};
|
|
55
59
|
var ATTRIBUTE_KEY_EXCEPTIONS_MAP = {
|
|
56
60
|
class: 'className',
|
|
61
|
+
innerHtml: 'innerHTML',
|
|
57
62
|
};
|
|
58
63
|
var updateKeyIfException = function (key) {
|
|
59
64
|
var _a;
|
|
@@ -66,16 +71,25 @@ var generateSetElementAttributeCode = function (key, tagName, useValue, options,
|
|
|
66
71
|
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.props(key, useValue, options);
|
|
67
72
|
}
|
|
68
73
|
var isKey = key === 'key';
|
|
69
|
-
var
|
|
74
|
+
var ignoreKey = /^(innerHTML|key|class|value)$/.test(key);
|
|
75
|
+
var isTextarea = key === 'value' && tagName === 'textarea';
|
|
76
|
+
var isDataSet = /^data-/.test(key);
|
|
77
|
+
var isComponent = Boolean(meta === null || meta === void 0 ? void 0 : meta.component);
|
|
70
78
|
var isHtmlAttr = (0, is_html_attribute_1.isHtmlAttribute)(key, tagName);
|
|
71
|
-
var setAttr = !
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
?
|
|
78
|
-
:
|
|
79
|
+
var setAttr = !ignoreKey && (isHtmlAttr || !isTextarea || isAttribute(key));
|
|
80
|
+
return [
|
|
81
|
+
// is html attribute or dash-case
|
|
82
|
+
setAttr ? ";el.setAttribute(\"".concat(key, "\", ").concat(useValue, ");") : '',
|
|
83
|
+
// not attr or dataset or html attr
|
|
84
|
+
!setAttr || !(isHtmlAttr || isDataSet || !isComponent || isKey)
|
|
85
|
+
? "el.".concat(updateKeyIfException((0, lodash_1.camelCase)(key)), " = ").concat(useValue, ";")
|
|
86
|
+
: '',
|
|
87
|
+
// is component but not html attribute
|
|
88
|
+
isComponent && !isHtmlAttr
|
|
89
|
+
? // custom-element is created but we're in the middle of the update loop
|
|
90
|
+
"\n if (el.props) {\n ;el.props.".concat((0, lodash_1.camelCase)(key), " = ").concat(useValue, ";\n if (el.update) {\n ;el.update();\n }\n } else {\n ;el.props = {};\n ;el.props.").concat((0, lodash_1.camelCase)(key), " = ").concat(useValue, ";\n }\n ")
|
|
91
|
+
: '',
|
|
92
|
+
].join('\n');
|
|
79
93
|
};
|
|
80
94
|
var addUpdateAfterSet = function (json, options) {
|
|
81
95
|
(0, traverse_1.default)(json).forEach(function (item) {
|
|
@@ -121,9 +135,7 @@ var addScopeVars = function (parentScopeVars, value, fn) {
|
|
|
121
135
|
};
|
|
122
136
|
var mappers = {
|
|
123
137
|
Fragment: function (json, options, blockOptions) {
|
|
124
|
-
return json.children
|
|
125
|
-
.map(function (item) { return blockToHtml(item, options, blockOptions); })
|
|
126
|
-
.join('\n');
|
|
138
|
+
return json.children.map(function (item) { return blockToHtml(item, options, blockOptions); }).join('\n');
|
|
127
139
|
},
|
|
128
140
|
};
|
|
129
141
|
var getId = function (json, options) {
|
|
@@ -136,9 +148,17 @@ var getId = function (json, options) {
|
|
|
136
148
|
options.namesMap[name] = newNameNum;
|
|
137
149
|
return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '').concat(name !== json.name && newNameNum === 1 ? '' : "-".concat(newNameNum));
|
|
138
150
|
};
|
|
151
|
+
var createGlobalId = function (name, options) {
|
|
152
|
+
var newNameNum = (options.namesMap[name] || 0) + 1;
|
|
153
|
+
options.namesMap[name] = newNameNum;
|
|
154
|
+
return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '', "-").concat(newNameNum);
|
|
155
|
+
};
|
|
139
156
|
// TODO: overloaded function
|
|
140
|
-
var updateReferencesInCode = function (code, options) {
|
|
157
|
+
var updateReferencesInCode = function (code, options, blockOptions) {
|
|
141
158
|
var _a, _b;
|
|
159
|
+
if (blockOptions === void 0) { blockOptions = {}; }
|
|
160
|
+
var contextVars = blockOptions.contextVars || [];
|
|
161
|
+
var context = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.context) || 'this.';
|
|
142
162
|
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.updateReferencesInCode) {
|
|
143
163
|
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.updateReferencesInCode(code, options, {
|
|
144
164
|
stripStateAndPropsRefs: strip_state_and_props_refs_1.stripStateAndPropsRefs,
|
|
@@ -148,12 +168,15 @@ var updateReferencesInCode = function (code, options) {
|
|
|
148
168
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
149
169
|
includeProps: false,
|
|
150
170
|
includeState: true,
|
|
151
|
-
replaceWith: '
|
|
171
|
+
replaceWith: context + 'state.',
|
|
172
|
+
context: context,
|
|
152
173
|
}), {
|
|
153
174
|
// TODO: replace with `this.` and add setters that call this.update()
|
|
154
175
|
includeProps: true,
|
|
155
176
|
includeState: false,
|
|
156
|
-
replaceWith: '
|
|
177
|
+
replaceWith: context + 'props.',
|
|
178
|
+
contextVars: contextVars,
|
|
179
|
+
context: context,
|
|
157
180
|
});
|
|
158
181
|
}
|
|
159
182
|
return code;
|
|
@@ -166,31 +189,23 @@ var addOnChangeJs = function (id, options, code) {
|
|
|
166
189
|
};
|
|
167
190
|
// TODO: spread support
|
|
168
191
|
var blockToHtml = function (json, options, blockOptions) {
|
|
169
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
192
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
170
193
|
if (blockOptions === void 0) { blockOptions = {}; }
|
|
194
|
+
var ComponentName = blockOptions.ComponentName;
|
|
171
195
|
var scopeVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.scopeVars) || [];
|
|
172
196
|
var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
173
197
|
var hasData = Object.keys(json.bindings).length;
|
|
198
|
+
var hasDomState = /input|textarea|select/.test(json.name);
|
|
174
199
|
var elId = '';
|
|
175
200
|
if (hasData) {
|
|
176
201
|
elId = getId(json, options);
|
|
177
|
-
json.properties['data-
|
|
178
|
-
}
|
|
179
|
-
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.getId) {
|
|
180
|
-
elId = (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.getId(elId, json, options, {
|
|
181
|
-
hasData: hasData,
|
|
182
|
-
getId: getId,
|
|
183
|
-
});
|
|
184
|
-
json.properties['data-name'] = (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.dataName(elId, json, options, {
|
|
185
|
-
hasData: hasData,
|
|
186
|
-
getId: getId,
|
|
187
|
-
});
|
|
202
|
+
json.properties['data-el'] = elId;
|
|
188
203
|
}
|
|
189
|
-
if (
|
|
190
|
-
|
|
204
|
+
if (hasDomState) {
|
|
205
|
+
json.properties['data-dom-state'] = createGlobalId((ComponentName ? ComponentName + '-' : '') + json.name, options);
|
|
191
206
|
}
|
|
192
207
|
if (mappers[json.name]) {
|
|
193
|
-
return mappers[json.name](json, options,
|
|
208
|
+
return mappers[json.name](json, options, blockOptions);
|
|
194
209
|
}
|
|
195
210
|
if ((0, is_children_1.default)(json)) {
|
|
196
211
|
return "<slot></slot>";
|
|
@@ -198,48 +213,41 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
198
213
|
if (json.properties._text) {
|
|
199
214
|
return json.properties._text;
|
|
200
215
|
}
|
|
201
|
-
if ((
|
|
216
|
+
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
202
217
|
// TO-DO: textContent might be better performance-wise
|
|
203
218
|
addOnChangeJs(elId, options, "\n ".concat(addScopeVars(scopeVars, json.bindings._text.code, function (scopeVar) {
|
|
204
|
-
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "
|
|
219
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
205
220
|
}), "\n ").concat(options.format === 'class' ? 'this.' : '', "renderTextNode(el, ").concat(json.bindings._text.code, ");"));
|
|
206
|
-
return "<template data-
|
|
221
|
+
return "<template data-el=\"".concat(elId, "\"><!-- ").concat((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code, " --></template>");
|
|
207
222
|
}
|
|
208
223
|
var str = '';
|
|
209
224
|
if (json.name === 'For') {
|
|
210
|
-
var forArguments = ((
|
|
225
|
+
var forArguments = ((_c = json === null || json === void 0 ? void 0 : json.scope) === null || _c === void 0 ? void 0 : _c.For) || [];
|
|
211
226
|
var localScopeVars_1 = __spreadArray(__spreadArray([], scopeVars, true), forArguments, true);
|
|
212
227
|
var argsStr = forArguments.map(function (arg) { return "\"".concat(arg, "\""); }).join(',');
|
|
213
228
|
addOnChangeJs(elId, options,
|
|
214
229
|
// TODO: be smarter about rendering, deleting old items and adding new ones by
|
|
215
230
|
// querying dom potentially
|
|
216
|
-
"\n let array = ".concat((
|
|
231
|
+
"\n let array = ".concat((_d = json.bindings.each) === null || _d === void 0 ? void 0 : _d.code, ";\n ").concat(options.format === 'class' ? 'this.' : '', "renderLoop(el, array, ").concat(argsStr, ");\n "));
|
|
217
232
|
// TODO: decide on how to handle this...
|
|
218
|
-
str += "\n <template data-
|
|
233
|
+
str += "\n <template data-el=\"".concat(elId, "\">");
|
|
219
234
|
if (json.children) {
|
|
220
235
|
str += json.children
|
|
221
236
|
.map(function (item) {
|
|
222
|
-
return blockToHtml(item, options, {
|
|
223
|
-
scopeVars: localScopeVars_1,
|
|
224
|
-
childComponents: childComponents,
|
|
225
|
-
});
|
|
237
|
+
return blockToHtml(item, options, __assign(__assign({}, blockOptions), { scopeVars: localScopeVars_1 }));
|
|
226
238
|
})
|
|
227
239
|
.join('\n');
|
|
228
240
|
}
|
|
229
241
|
str += '</template>';
|
|
230
242
|
}
|
|
231
243
|
else if (json.name === 'Show') {
|
|
232
|
-
var whenCondition = ((
|
|
244
|
+
var whenCondition = ((_e = json.bindings.when) === null || _e === void 0 ? void 0 : _e.code).replace(/;$/, '');
|
|
233
245
|
addOnChangeJs(elId, options, "\n ".concat(addScopeVars(scopeVars, whenCondition, function (scopeVar) {
|
|
234
|
-
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "
|
|
246
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
235
247
|
}), "\n const whenCondition = ").concat(whenCondition, ";\n if (whenCondition) {\n ").concat(options.format === 'class' ? 'this.' : '', "showContent(el)\n }\n "));
|
|
236
|
-
str += "<template data-
|
|
248
|
+
str += "<template data-el=\"".concat(elId, "\">");
|
|
237
249
|
if (json.children) {
|
|
238
|
-
str += json.children
|
|
239
|
-
.map(function (item) {
|
|
240
|
-
return blockToHtml(item, options, { scopeVars: scopeVars, childComponents: childComponents });
|
|
241
|
-
})
|
|
242
|
-
.join('\n');
|
|
250
|
+
str += json.children.map(function (item) { return blockToHtml(item, options, blockOptions); }).join('\n');
|
|
243
251
|
}
|
|
244
252
|
str += '</template>';
|
|
245
253
|
}
|
|
@@ -262,9 +270,7 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
262
270
|
if (key.startsWith('$')) {
|
|
263
271
|
continue;
|
|
264
272
|
}
|
|
265
|
-
var value = (json.properties[key] || '')
|
|
266
|
-
.replace(/"/g, '"')
|
|
267
|
-
.replace(/\n/g, '\\n');
|
|
273
|
+
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
268
274
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
269
275
|
}
|
|
270
276
|
// batch all local vars within the bindings
|
|
@@ -272,11 +278,11 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
272
278
|
var injectOnce = false;
|
|
273
279
|
var startInjectVar = '%%START_VARS%%';
|
|
274
280
|
for (var key in json.bindings) {
|
|
275
|
-
if (key === '_spread' || key === '
|
|
281
|
+
if (key === '_spread' || key === 'css') {
|
|
276
282
|
continue;
|
|
277
283
|
}
|
|
278
|
-
var value = (
|
|
279
|
-
var cusArg = ((
|
|
284
|
+
var value = (_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code;
|
|
285
|
+
var cusArg = ((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.arguments) || ['event'];
|
|
280
286
|
// TODO: proper babel transform to replace. Util for this
|
|
281
287
|
var useValue = value;
|
|
282
288
|
if (key.startsWith('on')) {
|
|
@@ -285,19 +291,22 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
285
291
|
event_1 = 'input';
|
|
286
292
|
}
|
|
287
293
|
var fnName = (0, lodash_1.camelCase)("on-".concat(elId, "-").concat(event_1));
|
|
288
|
-
var codeContent = (0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options));
|
|
294
|
+
var codeContent = (0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options, blockOptions));
|
|
289
295
|
options.js += "\n // Event handler for '".concat(event_1, "' event on ").concat(elId, "\n ").concat(options.format === 'class'
|
|
290
296
|
? "this.".concat(fnName, " = (").concat(cusArg.join(','), ") => {")
|
|
291
297
|
: "function ".concat(fnName, " (").concat(cusArg.join(','), ") {"), "\n ").concat(addScopeVars(scopeVars, codeContent, function (scopeVar) {
|
|
292
|
-
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "
|
|
298
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(event.currentTarget, \"").concat(scopeVar, "\");");
|
|
293
299
|
}), "\n ").concat(codeContent, "\n }\n ");
|
|
294
300
|
var fnIdentifier = "".concat(options.format === 'class' ? 'this.' : '').concat(fnName);
|
|
295
301
|
addOnChangeJs(elId, options, "\n ;el.removeEventListener('".concat(event_1, "', ").concat(fnIdentifier, ");\n ;el.addEventListener('").concat(event_1, "', ").concat(fnIdentifier, ");\n "));
|
|
296
302
|
}
|
|
303
|
+
else if (key === 'ref') {
|
|
304
|
+
str += " data-ref=\"".concat(ComponentName, "-").concat(useValue, "\" ");
|
|
305
|
+
}
|
|
297
306
|
else {
|
|
298
307
|
if (key === 'style') {
|
|
299
308
|
addOnChangeJs(elId, options, "\n ".concat(addScopeVars(scopeVars, useValue, function (scopeVar) {
|
|
300
|
-
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "
|
|
309
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
301
310
|
}), "\n ;Object.assign(el.style, ").concat(useValue, ");"));
|
|
302
311
|
}
|
|
303
312
|
else {
|
|
@@ -321,7 +330,7 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
321
330
|
if (codeBlock && testInjectVar.test(codeBlock)) {
|
|
322
331
|
var localScopeVars = Object.keys(batchScopeVars_1);
|
|
323
332
|
options.onChangeJsById[elId] = codeBlock.replace(startInjectVar, "\n ".concat(addScopeVars(localScopeVars, true, function (scopeVar) {
|
|
324
|
-
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "
|
|
333
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
325
334
|
}), "\n "));
|
|
326
335
|
}
|
|
327
336
|
if (jsx_1.selfClosingTags.has(json.name)) {
|
|
@@ -329,11 +338,7 @@ var blockToHtml = function (json, options, blockOptions) {
|
|
|
329
338
|
}
|
|
330
339
|
str += '>';
|
|
331
340
|
if (json.children) {
|
|
332
|
-
str += json.children
|
|
333
|
-
.map(function (item) {
|
|
334
|
-
return blockToHtml(item, options, { scopeVars: scopeVars, childComponents: childComponents });
|
|
335
|
-
})
|
|
336
|
-
.join('\n');
|
|
341
|
+
str += json.children.map(function (item) { return blockToHtml(item, options, blockOptions); }).join('\n');
|
|
337
342
|
}
|
|
338
343
|
if (json.properties.innerHTML) {
|
|
339
344
|
// Maybe put some kind of safety here for broken HTML such as no close tag
|
|
@@ -402,30 +407,26 @@ var componentToHtml = function (options) {
|
|
|
402
407
|
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
403
408
|
var hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
404
409
|
var hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
410
|
+
var hasTextBinding = (0, has_bindings_text_1.hasBindingsText)(json);
|
|
405
411
|
if (options.plugins) {
|
|
406
412
|
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
407
413
|
}
|
|
408
|
-
var css = (0,
|
|
414
|
+
var css = (0, collect_css_1.collectCss)(json, {
|
|
409
415
|
prefix: options.prefix,
|
|
410
416
|
});
|
|
411
|
-
var str = json.children
|
|
412
|
-
.map(function (item) { return blockToHtml(item, useOptions); })
|
|
413
|
-
.join('\n');
|
|
417
|
+
var str = json.children.map(function (item) { return blockToHtml(item, useOptions); }).join('\n');
|
|
414
418
|
if (css.trim().length) {
|
|
415
419
|
str += "<style>".concat(css, "</style>");
|
|
416
420
|
}
|
|
417
421
|
var hasChangeListeners = Boolean(Object.keys(useOptions.onChangeJsById).length);
|
|
418
422
|
var hasGeneratedJs = Boolean(useOptions.js.trim().length);
|
|
419
|
-
if (hasChangeListeners ||
|
|
420
|
-
hasGeneratedJs ||
|
|
421
|
-
((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ||
|
|
422
|
-
hasLoop) {
|
|
423
|
+
if (hasChangeListeners || hasGeneratedJs || ((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) || hasLoop) {
|
|
423
424
|
// TODO: collectJs helper for here and liquid
|
|
424
425
|
str += "\n <script>\n (() => {\n const state = ".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
425
426
|
valueMapper: function (value) {
|
|
426
427
|
return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
|
|
427
428
|
},
|
|
428
|
-
}), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\n let nodesToDestroy = [];\n let pendingUpdate = false;\n ").concat(!((_d = (_c = json.hooks) === null || _c === void 0 ? void 0 : _c.onInit) === null || _d === void 0 ? void 0 : _d.code) ? '' : 'let onInitOnce = false;', "\n\n function destroyAnyNodes() {\n // destroy current view template refs before rendering again\n nodesToDestroy.forEach(el => el.remove());\n nodesToDestroy = [];\n }\n ").concat(!hasChangeListeners
|
|
429
|
+
}), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\n let context = null;\n let nodesToDestroy = [];\n let pendingUpdate = false;\n ").concat(!((_d = (_c = json.hooks) === null || _c === void 0 ? void 0 : _c.onInit) === null || _d === void 0 ? void 0 : _d.code) ? '' : 'let onInitOnce = false;', "\n\n function destroyAnyNodes() {\n // destroy current view template refs before rendering again\n nodesToDestroy.forEach(el => el.remove());\n nodesToDestroy = [];\n }\n ").concat(!hasChangeListeners
|
|
429
430
|
? ''
|
|
430
431
|
: "\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 if (pendingUpdate === true) {\n return;\n }\n pendingUpdate = true;\n ".concat(Object.keys(useOptions.onChangeJsById)
|
|
431
432
|
.map(function (key) {
|
|
@@ -433,7 +434,7 @@ var componentToHtml = function (options) {
|
|
|
433
434
|
if (!value) {
|
|
434
435
|
return '';
|
|
435
436
|
}
|
|
436
|
-
return "\n document.querySelectorAll(\"[data-
|
|
437
|
+
return "\n document.querySelectorAll(\"[data-el='".concat(key, "']\").forEach((el) => {\n ").concat(value, "\n });\n ");
|
|
437
438
|
})
|
|
438
439
|
.join('\n\n'), "\n\n destroyAnyNodes();\n\n ").concat(!((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
|
|
439
440
|
? ''
|
|
@@ -447,9 +448,11 @@ var componentToHtml = function (options) {
|
|
|
447
448
|
: // TODO: make prettier by grabbing only the function body
|
|
448
449
|
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), " \n "), "\n\n ").concat(!hasShow
|
|
449
450
|
? ''
|
|
450
|
-
: "\n function showContent(el) {\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content\n // grabs the content of a node that is between <template> tags\n // iterates through child nodes to register all content including text elements\n // attaches the content after the template\n \n \n const elementFragment = el.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n children.forEach(child => {\n if (el?.scope) {\n child.scope = el.scope;\n }\n nodesToDestroy.push(child);\n });\n el.after(elementFragment);\n }\n \n ", "\n
|
|
451
|
+
: "\n function showContent(el) {\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content\n // grabs the content of a node that is between <template> tags\n // iterates through child nodes to register all content including text elements\n // attaches the content after the template\n \n \n const elementFragment = el.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n children.forEach(child => {\n if (el?.scope) {\n child.scope = el.scope;\n }\n if (el?.context) {\n child.context = el.context;\n }\n nodesToDestroy.push(child);\n });\n el.after(elementFragment);\n }\n \n ", "\n ").concat(!hasTextBinding
|
|
452
|
+
? ''
|
|
453
|
+
: "\n // Helper text DOM nodes\n function renderTextNode(el, text) {\n const textNode = document.createTextNode(text);\n if (el?.scope) {\n textNode.scope = el.scope\n }\n if (el?.context) {\n child.context = el.context;\n }\n el.after(textNode);\n nodesToDestroy.push(el.nextSibling);\n }\n ", "\n ").concat(!hasLoop
|
|
451
454
|
? ''
|
|
452
|
-
: "\n // Helper to render loops\n function renderLoop(template, array, itemName, itemIndex, collectionName) {\n for (let [index, value] of array.entries()) {\n const elementFragment = template.content.cloneNode(true);\n const localScope = {};\n let scope = localScope;\n if (template?.scope) {\n const getParent = {\n get(target, prop, receiver) {\n if (prop in target) {\n return target[prop];\n }\n if (prop in template.scope) {\n return template.scope[prop];\n }\n return target[prop];\n }\n };\n scope = new Proxy(localScope, getParent);\n }\n
|
|
455
|
+
: "\n // Helper to render loops\n function renderLoop(template, array, itemName, itemIndex, collectionName) {\n const collection = [];\n for (let [index, value] of array.entries()) {\n const elementFragment = template.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n const localScope = {};\n let scope = localScope;\n if (template?.scope) {\n const getParent = {\n get(target, prop, receiver) {\n if (prop in target) {\n return target[prop];\n }\n if (prop in template.scope) {\n return template.scope[prop];\n }\n return target[prop];\n }\n };\n scope = new Proxy(localScope, getParent);\n }\n children.forEach((child) => {\n if (itemName !== undefined) {\n scope[itemName] = value;\n }\n if (itemIndex !== undefined) {\n scope[itemIndex] = index;\n }\n if (collectionName !== undefined) {\n scope[collectionName] = array;\n }\n child.scope = scope;\n if (template.context) {\n child.context = template.context;\n }\n this.nodesToDestroy.push(child);\n collection.unshift(child);\n });\n collection.forEach(child => template.after(child));\n }\n }\n\n function getScope(el, name) {\n do {\n let value = el?.scope?.[name]\n if (value !== undefined) {\n return value\n }\n } while ((el = el.parentNode));\n }\n ", "\n })()\n </script>\n ");
|
|
453
456
|
}
|
|
454
457
|
if (options.plugins) {
|
|
455
458
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
@@ -482,49 +485,81 @@ exports.componentToHtml = componentToHtml;
|
|
|
482
485
|
var componentToCustomElement = function (options) {
|
|
483
486
|
if (options === void 0) { options = {}; }
|
|
484
487
|
return function (_a) {
|
|
485
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15
|
|
488
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
|
|
486
489
|
var component = _a.component;
|
|
487
|
-
var
|
|
490
|
+
var ComponentName = component.name;
|
|
491
|
+
var kebabName = (0, lodash_2.kebabCase)(ComponentName);
|
|
488
492
|
var useOptions = __assign(__assign({ prefix: kebabName }, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
|
|
489
493
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
490
494
|
if (options.plugins) {
|
|
491
495
|
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
492
496
|
}
|
|
497
|
+
var _16 = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _16[0], hasPropRef = _16[1];
|
|
498
|
+
var contextVars = Object.keys(((_b = json === null || json === void 0 ? void 0 : json.context) === null || _b === void 0 ? void 0 : _b.get) || {});
|
|
493
499
|
var childComponents = getChildComponents(json, useOptions);
|
|
494
500
|
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
501
|
+
var componentHasStatefulDom = (0, has_stateful_dom_1.hasStatefulDom)(json);
|
|
495
502
|
var props = (0, get_props_1.getProps)(json);
|
|
503
|
+
// prevent jsx props from showing up as @Input
|
|
504
|
+
if (hasPropRef) {
|
|
505
|
+
props.delete(forwardProp);
|
|
506
|
+
}
|
|
496
507
|
var outputs = (0, get_prop_functions_1.getPropFunctions)(json);
|
|
508
|
+
var domRefs = (0, get_refs_1.getRefs)(json);
|
|
509
|
+
var jsRefs = Object.keys(json.refs).filter(function (ref) { return !domRefs.has(ref); });
|
|
510
|
+
(0, map_refs_1.mapRefs)(json, function (refName) { return "self._".concat(refName); });
|
|
511
|
+
var context = contextVars.map(function (variableName) {
|
|
512
|
+
var _a, _b, _c;
|
|
513
|
+
var token = (_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get[variableName].name;
|
|
514
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.htmlContext) {
|
|
515
|
+
return (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.htmlContext(variableName, token);
|
|
516
|
+
}
|
|
517
|
+
return "this.".concat(variableName, " = this.getContext(this._root, ").concat(token, ")");
|
|
518
|
+
});
|
|
519
|
+
var setContext = [];
|
|
520
|
+
for (var key in json.context.set) {
|
|
521
|
+
var _17 = json.context.set[key], name_1 = _17.name, value = _17.value, ref = _17.ref;
|
|
522
|
+
setContext.push({ name: name_1, value: value, ref: ref });
|
|
523
|
+
}
|
|
497
524
|
addUpdateAfterSet(json, useOptions);
|
|
525
|
+
var hasContext = context.length;
|
|
498
526
|
var hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
527
|
+
var hasScope = hasLoop;
|
|
499
528
|
var hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
500
529
|
if (options.plugins) {
|
|
501
530
|
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
502
531
|
}
|
|
503
532
|
var css = '';
|
|
504
|
-
if ((
|
|
505
|
-
css = (
|
|
506
|
-
collectCss:
|
|
533
|
+
if ((_c = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _c === void 0 ? void 0 : _c.css) {
|
|
534
|
+
css = (_d = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _d === void 0 ? void 0 : _d.css(json, useOptions, {
|
|
535
|
+
collectCss: collect_css_1.collectCss,
|
|
507
536
|
prefix: options.prefix,
|
|
508
537
|
});
|
|
509
538
|
}
|
|
510
539
|
else {
|
|
511
|
-
css = (0,
|
|
540
|
+
css = (0, collect_css_1.collectCss)(json, {
|
|
512
541
|
prefix: options.prefix,
|
|
513
542
|
});
|
|
514
543
|
}
|
|
515
544
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
516
545
|
var html = json.children
|
|
517
546
|
.map(function (item) {
|
|
518
|
-
return blockToHtml(item, useOptions, {
|
|
547
|
+
return blockToHtml(item, useOptions, {
|
|
548
|
+
childComponents: childComponents,
|
|
549
|
+
props: props,
|
|
550
|
+
outputs: outputs,
|
|
551
|
+
ComponentName: ComponentName,
|
|
552
|
+
contextVars: contextVars,
|
|
553
|
+
});
|
|
519
554
|
})
|
|
520
555
|
.join('\n');
|
|
521
|
-
if ((
|
|
522
|
-
html = (
|
|
556
|
+
if ((_e = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _e === void 0 ? void 0 : _e.childrenHtml) {
|
|
557
|
+
html = (_f = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _f === void 0 ? void 0 : _f.childrenHtml(html, kebabName, json, useOptions);
|
|
523
558
|
}
|
|
524
|
-
if ((
|
|
525
|
-
html += (
|
|
559
|
+
if ((_g = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _g === void 0 ? void 0 : _g.cssHtml) {
|
|
560
|
+
html += (_h = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _h === void 0 ? void 0 : _h.cssHtml(css);
|
|
526
561
|
}
|
|
527
|
-
else {
|
|
562
|
+
else if (css.length) {
|
|
528
563
|
html += "<style>".concat(css, "</style>");
|
|
529
564
|
}
|
|
530
565
|
if (options.prettier !== false) {
|
|
@@ -546,9 +581,17 @@ var componentToCustomElement = function (options) {
|
|
|
546
581
|
console.warn('Could not prettify', { string: html }, err);
|
|
547
582
|
}
|
|
548
583
|
}
|
|
549
|
-
var str = "\n ".concat((0, render_imports_1.renderPreComponent)(json), "\n /**\n * Usage:\n * \n * <").concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(
|
|
550
|
-
? (
|
|
551
|
-
: 'HTMLElement', " {\n
|
|
584
|
+
var str = "\n ".concat(json.types ? json.types.join('\n') : '', "\n ").concat(json.interfaces ? (_j = json.interfaces) === null || _j === void 0 ? void 0 : _j.join('\n') : '', "\n ").concat((0, render_imports_1.renderPreComponent)({ component: json, target: 'customElement' }), "\n /**\n * Usage:\n * \n * <").concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(ComponentName, " extends ").concat(((_k = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _k === void 0 ? void 0 : _k.classExtends)
|
|
585
|
+
? (_l = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _l === void 0 ? void 0 : _l.classExtends(json, useOptions)
|
|
586
|
+
: 'HTMLElement', " {\n ").concat(Array.from(domRefs)
|
|
587
|
+
.map(function (ref) {
|
|
588
|
+
return "\n get _".concat(ref, "() {\n return this._root.querySelector(\"[data-ref='").concat(ComponentName, "-").concat(ref, "']\")\n }\n ");
|
|
589
|
+
})
|
|
590
|
+
.join('\n'), "\n\n get _root() {\n return this.shadowRoot || this;\n }\n\n constructor() {\n super();\n const self = this;\n ").concat(
|
|
591
|
+
// TODO: more than one context not injector
|
|
592
|
+
setContext.length === 1 && ((_m = setContext === null || setContext === void 0 ? void 0 : setContext[0]) === null || _m === void 0 ? void 0 : _m.ref)
|
|
593
|
+
? "this.context = ".concat(setContext[0].ref)
|
|
594
|
+
: '', "\n\n ").concat(!((_p = (_o = json.hooks) === null || _o === void 0 ? void 0 : _o.onInit) === null || _p === void 0 ? void 0 : _p.code) ? '' : 'this.onInitOnce = false;', "\n\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
552
595
|
valueMapper: function (value) {
|
|
553
596
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
|
|
554
597
|
includeProps: false,
|
|
@@ -560,41 +603,78 @@ var componentToCustomElement = function (options) {
|
|
|
560
603
|
includeProps: true,
|
|
561
604
|
includeState: false,
|
|
562
605
|
replaceWith: 'self.props.',
|
|
606
|
+
contextVars: contextVars,
|
|
607
|
+
// correctly ref the class not state object
|
|
608
|
+
context: 'self.',
|
|
563
609
|
});
|
|
564
610
|
},
|
|
565
|
-
}), ";\n ").concat(componentHasProps
|
|
566
|
-
?
|
|
567
|
-
:
|
|
568
|
-
|
|
569
|
-
|
|
611
|
+
}), ";\n if (!this.props) {\n this.props = {};\n }\n ").concat(!componentHasProps
|
|
612
|
+
? ''
|
|
613
|
+
: "\n this.componentProps = [".concat(Array.from(props)
|
|
614
|
+
.map(function (prop) { return "\"".concat(prop, "\""); })
|
|
615
|
+
.join(','), "];\n "), "\n\n ").concat(!((_q = json.hooks.onUpdate) === null || _q === void 0 ? void 0 : _q.length)
|
|
570
616
|
? ''
|
|
571
|
-
: "\n
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
617
|
+
: "\n this.updateDeps = [".concat((_r = json.hooks.onUpdate) === null || _r === void 0 ? void 0 : _r.map(function (hook) { return updateReferencesInCode((hook === null || hook === void 0 ? void 0 : hook.deps) || '[]', useOptions); }).join(','), "];\n "), "\n\n // used to keep track of all nodes created by show/for\n this.nodesToDestroy = [];\n // batch updates\n this.pendingUpdate = false;\n ").concat(((_s = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _s === void 0 ? void 0 : _s.componentConstructor)
|
|
618
|
+
? (_t = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _t === void 0 ? void 0 : _t.componentConstructor(json, useOptions)
|
|
619
|
+
: '', "\n\n ").concat(useOptions.js, "\n\n ").concat(jsRefs
|
|
620
|
+
.map(function (ref) {
|
|
621
|
+
var _a;
|
|
622
|
+
// const typeParameter = json['refs'][ref]?.typeParameter || '';
|
|
623
|
+
var argument = ((_a = json['refs'][ref]) === null || _a === void 0 ? void 0 : _a.argument) || 'null';
|
|
624
|
+
return "this._".concat(ref, " = ").concat(argument);
|
|
625
|
+
})
|
|
626
|
+
.join('\n'), "\n\n if (").concat((_u = json.meta.useMetadata) === null || _u === void 0 ? void 0 : _u.isAttachedToShadowDom, ") {\n this.attachShadow({ mode: 'open' })\n }\n }\n\n\n ").concat(!((_v = json.hooks.onUnMount) === null || _v === void 0 ? void 0 : _v.code)
|
|
627
|
+
? ''
|
|
628
|
+
: "\n disconnectedCallback() {\n ".concat(((_w = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _w === void 0 ? void 0 : _w.disconnectedCallback)
|
|
629
|
+
? (_x = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _x === void 0 ? void 0 : _x.disconnectedCallback(json, useOptions)
|
|
630
|
+
: "\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount.code, useOptions), useOptions, {
|
|
631
|
+
contextVars: contextVars,
|
|
632
|
+
}), "\n this.destroyAnyNodes(); // clean up nodes when component is destroyed\n ").concat(!((_z = (_y = json.hooks) === null || _y === void 0 ? void 0 : _y.onInit) === null || _z === void 0 ? void 0 : _z.code) ? '' : 'this.onInitOnce = false;', "\n "), "\n }\n "), "\n\n destroyAnyNodes() {\n // destroy current view template refs before rendering again\n this.nodesToDestroy.forEach(el => el.remove());\n this.nodesToDestroy = [];\n }\n\n connectedCallback() {\n ").concat(context.join('\n'), "\n ").concat(!componentHasProps
|
|
633
|
+
? ''
|
|
634
|
+
: "\n this.getAttributeNames().forEach((attr) => {\n const jsVar = attr.replace(/-/g, '');\n const regexp = new RegExp(jsVar, 'i');\n this.componentProps.forEach(prop => {\n if (regexp.test(prop)) {\n const attrValue = this.getAttribute(attr);\n if (this.props[prop] !== attrValue) {\n this.props[prop] = attrValue;\n }\n }\n });\n });\n ", "\n ").concat(((_0 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _0 === void 0 ? void 0 : _0.connectedCallbackUpdate)
|
|
635
|
+
? (_1 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _1 === void 0 ? void 0 : _1.connectedCallbackUpdate(json, html, useOptions)
|
|
636
|
+
: "\n this._root.innerHTML = `\n ".concat(html, "`;\n this.pendingUpdate = true;\n ").concat(!((_3 = (_2 = json.hooks) === null || _2 === void 0 ? void 0 : _2.onInit) === null || _3 === void 0 ? void 0 : _3.code) ? '' : 'this.onInit();', "\n this.render();\n this.onMount();\n this.pendingUpdate = false;\n this.update();\n "), "\n }\n ").concat(!((_5 = (_4 = json.hooks) === null || _4 === void 0 ? void 0 : _4.onInit) === null || _5 === void 0 ? void 0 : _5.code)
|
|
576
637
|
? ''
|
|
577
|
-
: "\n onInit() {\n ".concat(!((
|
|
638
|
+
: "\n onInit() {\n ".concat(!((_7 = (_6 = json.hooks) === null || _6 === void 0 ? void 0 : _6.onInit) === null || _7 === void 0 ? void 0 : _7.code)
|
|
578
639
|
? ''
|
|
579
|
-
: "\n if (!this.onInitOnce) {\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode((
|
|
640
|
+
: "\n if (!this.onInitOnce) {\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode((_9 = (_8 = json.hooks) === null || _8 === void 0 ? void 0 : _8.onInit) === null || _9 === void 0 ? void 0 : _9.code, useOptions), useOptions, {
|
|
641
|
+
contextVars: contextVars,
|
|
642
|
+
}), "\n this.onInitOnce = true;\n }"), "\n }\n "), "\n\n ").concat(!hasShow
|
|
580
643
|
? ''
|
|
581
|
-
: "\n showContent(el) {\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content\n // grabs the content of a node that is between <template> tags\n // iterates through child nodes to register all content including text elements\n // attaches the content after the template\n \n \n const elementFragment = el.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n children.forEach(child => {\n if (el?.scope) {\n child.scope = el.scope;\n }\n this.nodesToDestroy.push(child);\n });\n el.after(elementFragment);\n }", "\n ").concat(!((
|
|
644
|
+
: "\n showContent(el) {\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content\n // grabs the content of a node that is between <template> tags\n // iterates through child nodes to register all content including text elements\n // attaches the content after the template\n \n \n const elementFragment = el.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n children.forEach(child => {\n if (el?.scope) {\n child.scope = el.scope;\n }\n if (el?.context) {\n child.context = el.context;\n }\n this.nodesToDestroy.push(child);\n });\n el.after(elementFragment);\n }", "\n ").concat(!((_10 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _10 === void 0 ? void 0 : _10.attributeChangedCallback)
|
|
582
645
|
? ''
|
|
583
|
-
: "\n attributeChangedCallback(name, oldValue, newValue) {\n ".concat((
|
|
646
|
+
: "\n attributeChangedCallback(name, oldValue, newValue) {\n ".concat((_11 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _11 === void 0 ? void 0 : _11.attributeChangedCallback(['name', 'oldValue', 'newValue'], json, useOptions), "\n }\n "), "\n\n onMount() {\n ").concat(!((_12 = json.hooks.onMount) === null || _12 === void 0 ? void 0 : _12.code)
|
|
584
647
|
? ''
|
|
585
648
|
: // TODO: make prettier by grabbing only the function body
|
|
586
|
-
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions
|
|
649
|
+
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions, {
|
|
650
|
+
contextVars: contextVars,
|
|
651
|
+
}), "\n "), "\n }\n\n onUpdate() {\n ").concat(!((_13 = json.hooks.onUpdate) === null || _13 === void 0 ? void 0 : _13.length)
|
|
587
652
|
? ''
|
|
588
|
-
: "\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
|
|
589
|
-
|
|
653
|
+
: "\n const self = this;\n ".concat(json.hooks.onUpdate.reduce(function (code, hook, index) {
|
|
654
|
+
// create check update
|
|
655
|
+
if (hook === null || hook === void 0 ? void 0 : hook.deps) {
|
|
656
|
+
code += "\n ;(function (__prev, __next) {\n const __hasChange = __prev.find((val, index) => val !== __next[index]);\n if (__hasChange !== undefined) {\n ".concat(updateReferencesInCode(hook.code, useOptions, {
|
|
657
|
+
contextVars: contextVars,
|
|
658
|
+
context: 'self.',
|
|
659
|
+
}), "\n self.updateDeps[").concat(index, "] = __next;\n }\n }(self.updateDeps[").concat(index, "], ").concat(updateReferencesInCode((hook === null || hook === void 0 ? void 0 : hook.deps) || '[]', useOptions, {
|
|
660
|
+
contextVars: contextVars,
|
|
661
|
+
context: 'self.',
|
|
662
|
+
}), "));\n ");
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
code += "\n ".concat(updateReferencesInCode(hook.code, useOptions, {
|
|
666
|
+
contextVars: contextVars,
|
|
667
|
+
context: 'self.',
|
|
668
|
+
}), "\n ");
|
|
669
|
+
}
|
|
590
670
|
return code + '\n';
|
|
591
|
-
}, ''), " \n "), "\n }\n\n update() {\n if (this.pendingUpdate === true) {\n return;\n }\n this.pendingUpdate = true;\n
|
|
671
|
+
}, ''), " \n "), "\n }\n\n update() {\n if (this.pendingUpdate === true) {\n return;\n }\n this.pendingUpdate = true;\n this.render();\n this.onUpdate();\n this.pendingUpdate = false;\n }\n\n render() {\n ").concat(!componentHasStatefulDom
|
|
672
|
+
? ''
|
|
673
|
+
: "\n // grab previous input state\n const preStateful = this.getStateful(this._root);\n const preValues = this.prepareHydrate(preStateful);\n ", "\n\n // re-rendering needs to ensure that all nodes generated by for/show are refreshed\n this.destroyAnyNodes();\n this.updateBindings();\n\n ").concat(!componentHasStatefulDom
|
|
592
674
|
? ''
|
|
593
|
-
: "\n
|
|
675
|
+
: "\n // hydrate input state\n if (preValues.length) {\n const nextStateful = this.getStateful(this._root);\n this.hydrateDom(preValues, nextStateful);\n }\n ", "\n }\n ").concat(!componentHasStatefulDom
|
|
594
676
|
? ''
|
|
595
|
-
: "\n
|
|
596
|
-
? (_14 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _14 === void 0 ? void 0 : _14.updateBindings(json, useOptions)
|
|
597
|
-
: 'this.updateBindings();', "\n }\n\n updateBindings() {\n ").concat(Object.keys(useOptions.onChangeJsById)
|
|
677
|
+
: "\n getStateful(el) {\n const stateful = el.querySelectorAll('[data-dom-state]');\n return stateful ? Array.from(stateful) : [];\n }\n prepareHydrate(stateful) {\n return stateful.map(el => {\n return {\n id: el.dataset.domState,\n value: el.value,\n active: document.activeElement === el,\n selectionStart: el.selectionStart\n };\n });\n }\n hydrateDom(preValues, stateful) {\n return stateful.map((el, index) => {\n const prev = preValues.find((prev) => el.dataset.domState === prev.id);\n if (prev) {\n el.value = prev.value;\n if (prev.active) {\n el.focus();\n el.selectionStart = prev.selectionStart;\n }\n }\n });\n }\n ", "\n\n updateBindings() {\n ").concat(Object.keys(useOptions.onChangeJsById)
|
|
598
678
|
.map(function (key) {
|
|
599
679
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
600
680
|
var value = useOptions.onChangeJsById[key];
|
|
@@ -607,17 +687,23 @@ var componentToCustomElement = function (options) {
|
|
|
607
687
|
code = (_e = (_d = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _d === void 0 ? void 0 : _d.updateBindings) === null || _e === void 0 ? void 0 : _e.code(key, value, useOptions);
|
|
608
688
|
}
|
|
609
689
|
else {
|
|
610
|
-
code = updateReferencesInCode(value, useOptions
|
|
690
|
+
code = updateReferencesInCode(value, useOptions, {
|
|
691
|
+
contextVars: contextVars,
|
|
692
|
+
});
|
|
611
693
|
}
|
|
612
694
|
return "\n ".concat(((_f = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _f === void 0 ? void 0 : _f.generateQuerySelectorAll)
|
|
613
695
|
? "\n ".concat((_g = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _g === void 0 ? void 0 : _g.generateQuerySelectorAll(key, code), "\n ")
|
|
614
|
-
: " \n this._root.querySelectorAll(\"[data-
|
|
696
|
+
: " \n this._root.querySelectorAll(\"[data-el='".concat(key, "']\").forEach((el) => {\n ").concat(code, "\n })\n "), "\n ");
|
|
615
697
|
})
|
|
616
|
-
.join('\n\n'), "\n }\n\n // Helper to render content\n renderTextNode(el, text) {\n const textNode = document.createTextNode(text);\n if (el?.scope) {\n textNode.scope = el.scope;\n }\n el.after(textNode);\n this.nodesToDestroy.push(el.nextSibling);\n }\n
|
|
698
|
+
.join('\n\n'), "\n }\n\n // Helper to render content\n renderTextNode(el, text) {\n const textNode = document.createTextNode(text);\n if (el?.scope) {\n textNode.scope = el.scope;\n }\n if (el?.context) {\n textNode.context = el.context;\n }\n el.after(textNode);\n this.nodesToDestroy.push(el.nextSibling);\n }\n ").concat(!hasContext
|
|
699
|
+
? ''
|
|
700
|
+
: "\n // get Context Helper\n getContext(el, token) {\n do {\n let value;\n if (el?.context?.get) {\n value = el.context.get(token);\n } else if (el?.context?.[token]) {\n value = el.context[token];\n }\n if (value !== undefined) {\n return value;\n }\n } while ((el = el.parentNode));\n }\n ", "\n ").concat(!hasScope
|
|
701
|
+
? ''
|
|
702
|
+
: "\n // scope helper\n getScope(el, name) {\n do {\n let value = el?.scope?.[name]\n if (value !== undefined) {\n return value\n }\n } while ((el = el.parentNode));\n }\n ", "\n\n ").concat(!hasLoop
|
|
617
703
|
? ''
|
|
618
|
-
: "\n\n // Helper to render loops\n renderLoop(template, array, itemName, itemIndex, collectionName) {\n const collection = [];\n for (let [index, value] of array.entries()) {\n const elementFragment = template.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n const localScope = {};\n let scope = localScope;\n if (template?.scope) {\n const getParent = {\n get(target, prop, receiver) {\n if (prop in target) {\n return target[prop];\n }\n if (prop in template.scope) {\n return template.scope[prop];\n }\n return target[prop];\n }\n };\n scope = new Proxy(localScope, getParent);\n }\n children.forEach((child) => {\n if (itemName !== undefined) {\n scope[itemName] = value;\n }\n if (itemIndex !== undefined) {\n scope[itemIndex] = index;\n }\n if (collectionName !== undefined) {\n scope[collectionName] = array;\n }\n child.scope = scope;\n this.nodesToDestroy.push(child);\n collection.
|
|
619
|
-
? (
|
|
620
|
-
: "customElements.define('".concat(kebabName, "', ").concat(
|
|
704
|
+
: "\n\n // Helper to render loops\n renderLoop(template, array, itemName, itemIndex, collectionName) {\n const collection = [];\n for (let [index, value] of array.entries()) {\n const elementFragment = template.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n const localScope = {};\n let scope = localScope;\n if (template?.scope) {\n const getParent = {\n get(target, prop, receiver) {\n if (prop in target) {\n return target[prop];\n }\n if (prop in template.scope) {\n return template.scope[prop];\n }\n return target[prop];\n }\n };\n scope = new Proxy(localScope, getParent);\n }\n children.forEach((child) => {\n if (itemName !== undefined) {\n scope[itemName] = value;\n }\n if (itemIndex !== undefined) {\n scope[itemIndex] = index;\n }\n if (collectionName !== undefined) {\n scope[collectionName] = array;\n }\n child.scope = scope;\n if (template.context) {\n child.context = context;\n }\n this.nodesToDestroy.push(child);\n collection.unshift(child)\n });\n }\n collection.forEach(child => template.after(child));\n }\n ", "\n }\n\n ").concat(((_14 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _14 === void 0 ? void 0 : _14.customElementsDefine)
|
|
705
|
+
? (_15 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _15 === void 0 ? void 0 : _15.customElementsDefine(kebabName, component, useOptions)
|
|
706
|
+
: "customElements.define('".concat(kebabName, "', ").concat(ComponentName, ");"), "\n ");
|
|
621
707
|
if (options.plugins) {
|
|
622
708
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
623
709
|
}
|