@builder.io/mitosis 0.0.56-1 → 0.0.56-101
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 +5 -13
- package/dist/src/__tests__/builder.test.js +3 -3
- package/dist/src/__tests__/data/advanced-ref.raw.d.ts +4 -0
- package/dist/src/__tests__/data/advanced-ref.raw.jsx +39 -0
- package/dist/src/__tests__/data/basic-child-component.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-child-component.raw.jsx +21 -0
- 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.d.ts +1 -0
- package/dist/src/__tests__/data/basic-for-show.raw.jsx +20 -0
- package/dist/src/__tests__/data/basic-for.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-for.raw.jsx +23 -0
- 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.d.ts +5 -0
- package/dist/src/__tests__/data/basic-onMount-update.raw.jsx +17 -0
- 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.d.ts +1 -0
- package/dist/src/__tests__/data/basic-outputs-meta.raw.jsx +17 -0
- package/dist/src/__tests__/data/basic-outputs.raw.d.ts +1 -0
- package/dist/src/__tests__/data/basic-outputs.raw.jsx +14 -0
- 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 +13 -4
- package/dist/src/__tests__/data/blocks/button-with-metadata.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/button.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/classname-jsx.raw.d.ts +7 -0
- package/dist/src/__tests__/data/blocks/classname-jsx.raw.jsx +15 -0
- package/dist/src/__tests__/data/blocks/columns.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/columns.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/content-slot-html.raw.d.ts +7 -0
- package/dist/src/__tests__/data/blocks/content-slot-html.raw.jsx +15 -0
- package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.d.ts +6 -0
- package/dist/src/__tests__/data/blocks/content-slot-jsx.raw.jsx +12 -0
- package/dist/src/__tests__/data/blocks/custom-code.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/custom-code.raw.jsx +3 -7
- package/dist/src/__tests__/data/blocks/embed.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/embed.raw.jsx +3 -7
- package/dist/src/__tests__/data/blocks/form.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/form.raw.jsx +8 -8
- package/dist/src/__tests__/data/blocks/image.raw.d.ts +2 -2
- package/dist/src/__tests__/data/blocks/image.raw.jsx +9 -10
- package/dist/src/__tests__/data/blocks/img-state.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/img-state.raw.jsx +17 -0
- package/dist/src/__tests__/data/blocks/img.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/input.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/input.raw.jsx +1 -3
- package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +7 -1
- package/dist/src/__tests__/data/blocks/onInit-onMount.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/onInit-onMount.raw.jsx +13 -0
- package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +8 -0
- package/dist/src/__tests__/data/blocks/onInit.raw.jsx +20 -0
- package/dist/src/__tests__/data/blocks/onMount.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/onUpdate.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +1 -1
- package/dist/src/__tests__/data/blocks/raw-text.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/rootShow.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/section-state.raw.d.ts +6 -0
- package/dist/src/__tests__/data/blocks/section-state.raw.jsx +17 -0
- package/dist/src/__tests__/data/blocks/section.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/select.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/select.raw.jsx +1 -3
- package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/self-referencing-component.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +2 -4
- package/dist/src/__tests__/data/blocks/slot-html.raw.d.ts +5 -0
- package/dist/src/__tests__/data/blocks/slot-html.raw.jsx +15 -0
- package/dist/src/__tests__/data/blocks/slot-jsx.raw.d.ts +5 -0
- package/dist/src/__tests__/data/blocks/slot-jsx.raw.jsx +12 -0
- package/dist/src/__tests__/data/blocks/stamped-io.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +4 -5
- package/dist/src/__tests__/data/blocks/submit-button.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/text.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/text.raw.jsx +3 -1
- package/dist/src/__tests__/data/blocks/textarea.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/video.raw.d.ts +1 -1
- package/dist/src/__tests__/data/blocks/video.raw.jsx +1 -1
- package/dist/src/__tests__/data/context/component-with-context.lite.d.ts +3 -1
- package/dist/src/__tests__/data/context/component-with-context.lite.jsx +7 -2
- package/dist/src/__tests__/data/default-props/default-props.raw.d.ts +7 -0
- package/dist/src/__tests__/data/default-props/default-props.raw.jsx +23 -0
- package/dist/src/__tests__/data/jsx-json.spec.d.ts +2 -0
- package/dist/src/__tests__/data/jsx-json.spec.js +10226 -0
- package/dist/src/__tests__/data/nested-styles.lite.d.ts +1 -0
- package/dist/src/__tests__/data/nested-styles.lite.jsx +20 -0
- package/dist/src/__tests__/data/show/nested-show.raw.d.ts +6 -0
- package/dist/src/__tests__/data/show/nested-show.raw.jsx +11 -0
- package/dist/src/__tests__/data/show/show-with-for.raw.d.ts +6 -0
- package/dist/src/__tests__/data/show/show-with-for.raw.jsx +9 -0
- package/dist/src/__tests__/data/styles/class-and-className.raw.d.ts +1 -0
- package/dist/src/__tests__/data/styles/class-and-className.raw.jsx +10 -0
- package/dist/src/__tests__/data/styles/class.raw.d.ts +1 -0
- package/dist/src/__tests__/data/styles/class.raw.jsx +10 -0
- package/dist/src/__tests__/data/styles/className.raw.d.ts +1 -0
- package/dist/src/__tests__/data/styles/className.raw.jsx +10 -0
- package/dist/src/__tests__/data/styles/classState.raw.d.ts +1 -0
- package/dist/src/__tests__/data/styles/classState.raw.jsx +13 -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/component-with-default-values-types.raw.d.ts +5 -0
- package/dist/src/__tests__/data/types/component-with-default-values-types.raw.jsx +9 -0
- package/dist/src/__tests__/data/types/foo-type.d.ts +1 -0
- package/dist/src/{jsx-types.js → __tests__/data/types/foo-type.js} +0 -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__/data/types/type-dependency.raw.d.ts +7 -0
- package/dist/src/__tests__/data/types/type-dependency.raw.jsx +6 -0
- package/dist/src/__tests__/data/types/type-export.lite.d.ts +3 -0
- package/dist/src/__tests__/data/types/type-export.lite.jsx +6 -0
- package/dist/src/__tests__/hash-code.test.d.ts +1 -0
- package/dist/src/__tests__/hash-code.test.js +11 -0
- package/dist/src/__tests__/html.test.js +2 -13
- package/dist/src/__tests__/liquid.test.js +2 -103
- package/dist/src/__tests__/lit.test.d.ts +1 -0
- package/dist/src/__tests__/lit.test.js +7 -0
- package/dist/src/__tests__/marko.test.d.ts +1 -0
- package/dist/src/__tests__/marko.test.js +14 -0
- package/dist/src/__tests__/parse-jsx.test.js +28 -0
- package/dist/src/__tests__/qwik/convert-method-to-function.test.d.ts +1 -0
- package/dist/src/__tests__/qwik/convert-method-to-function.test.js +37 -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.directive.test.js +1 -0
- package/dist/src/__tests__/qwik.test.js +54 -23
- package/dist/src/__tests__/react-native.test.js +3 -136
- package/dist/src/__tests__/react.test.js +9 -136
- package/dist/src/__tests__/shared.d.ts +3 -0
- package/dist/src/__tests__/shared.js +308 -0
- package/dist/src/__tests__/solid.test.js +5 -97
- package/dist/src/__tests__/stencil.test.js +3 -98
- package/dist/src/__tests__/styles.test.d.ts +1 -0
- package/dist/src/__tests__/styles.test.js +23 -0
- package/dist/src/__tests__/svelte.test.js +2 -31
- package/dist/src/__tests__/vue.test.js +2 -134
- package/dist/src/__tests__/webcomponent.test.js +8 -5
- package/dist/src/constants/hooks.d.ts +7 -0
- package/dist/src/constants/hooks.js +10 -0
- package/dist/src/flow.d.ts +6 -0
- package/dist/src/flow.js +6 -2
- package/dist/src/generators/angular.d.ts +10 -2
- package/dist/src/generators/angular.js +245 -47
- package/dist/src/generators/builder.d.ts +2 -2
- package/dist/src/generators/builder.js +26 -29
- 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/react.js +1 -1
- package/dist/src/generators/context/solid.js +1 -1
- package/dist/src/generators/context/svelte.d.ts +1 -1
- package/dist/src/generators/context/svelte.js +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 +365 -108
- package/dist/src/generators/liquid.d.ts +1 -1
- package/dist/src/generators/liquid.js +18 -25
- package/dist/src/generators/lit/collect-class-string.d.ts +2 -0
- package/dist/src/generators/lit/collect-class-string.js +43 -0
- package/dist/src/generators/lit/generate.d.ts +5 -0
- package/dist/src/generators/lit/generate.js +223 -0
- package/dist/src/generators/lit/index.d.ts +1 -0
- package/dist/src/generators/lit/index.js +17 -0
- package/dist/src/generators/marko/generate.d.ts +21 -0
- package/dist/src/generators/marko/generate.js +289 -0
- package/dist/src/generators/marko/index.d.ts +1 -0
- package/dist/src/generators/marko/index.js +17 -0
- package/dist/src/generators/mitosis.d.ts +1 -1
- package/dist/src/generators/mitosis.js +39 -34
- package/dist/src/generators/qwik/add-prevent-default.d.ts +7 -0
- package/dist/src/generators/qwik/add-prevent-default.js +32 -0
- package/dist/src/generators/qwik/component-generator.d.ts +4 -0
- package/dist/src/generators/qwik/component-generator.js +311 -0
- package/dist/src/generators/qwik/component.d.ts +1 -0
- package/dist/src/generators/qwik/component.js +68 -36
- package/dist/src/generators/qwik/convert-method-to-function.d.ts +1 -0
- package/dist/src/generators/qwik/convert-method-to-function.js +162 -0
- package/dist/src/generators/qwik/directives.js +43 -23
- package/dist/src/generators/qwik/handlers.js +6 -22
- 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.d.ts +12 -0
- package/dist/src/generators/qwik/jsx.js +81 -24
- package/dist/src/generators/qwik/src-generator.d.ts +21 -8
- package/dist/src/generators/qwik/src-generator.js +177 -43
- package/dist/src/generators/qwik/styles.js +3 -3
- package/dist/src/generators/react/generator.d.ts +6 -0
- package/dist/src/generators/react/generator.js +447 -0
- package/dist/src/generators/react/helpers.d.ts +2 -0
- package/dist/src/generators/react/helpers.js +14 -0
- package/dist/src/generators/react/index.d.ts +2 -0
- package/dist/src/generators/react/index.js +18 -0
- package/dist/src/generators/react/state.d.ts +9 -0
- package/dist/src/generators/react/state.js +109 -0
- package/dist/src/generators/react/types.d.ts +10 -0
- package/dist/src/generators/react/types.js +2 -0
- package/dist/src/generators/react-native.d.ts +2 -2
- package/dist/src/generators/react-native.js +8 -10
- package/dist/src/generators/react.d.ts +7 -3
- package/dist/src/generators/react.js +190 -92
- package/dist/src/generators/solid/index.d.ts +3 -0
- package/dist/src/generators/solid/index.js +345 -0
- package/dist/src/generators/solid/state.d.ts +19 -0
- package/dist/src/generators/solid/state.js +144 -0
- package/dist/src/generators/solid/types.d.ts +6 -0
- package/dist/src/generators/solid/types.js +2 -0
- package/dist/src/generators/solid.d.ts +3 -2
- package/dist/src/generators/solid.js +86 -50
- package/dist/src/generators/stencil/collect-class-string.d.ts +1 -1
- package/dist/src/generators/stencil/collect-class-string.js +10 -11
- package/dist/src/generators/stencil/generate.d.ts +1 -1
- package/dist/src/generators/stencil/generate.js +16 -31
- package/dist/src/generators/svelte.d.ts +2 -2
- package/dist/src/generators/svelte.js +160 -88
- package/dist/src/generators/swift-ui.d.ts +1 -1
- package/dist/src/generators/swift-ui.js +19 -20
- package/dist/src/generators/template.d.ts +1 -1
- package/dist/src/generators/template.js +11 -18
- package/dist/src/generators/vue.d.ts +17 -9
- package/dist/src/generators/vue.js +227 -106
- package/dist/src/helpers/babel-transform.js +8 -14
- 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/create-mitosis-node.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-custom-imports.d.ts +15 -0
- package/dist/src/helpers/get-custom-imports.js +40 -0
- package/dist/src/helpers/get-prop-functions.d.ts +5 -0
- package/dist/src/helpers/get-prop-functions.js +29 -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/get-refs.js +3 -2
- package/dist/src/helpers/get-state-object-string.d.ts +6 -4
- package/dist/src/helpers/get-state-object-string.js +37 -27
- package/dist/src/helpers/get-styles.js +4 -3
- package/dist/src/helpers/getters-to-functions.d.ts +1 -1
- package/dist/src/helpers/getters-to-functions.js +3 -2
- package/dist/src/helpers/handle-missing-state.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/has.d.ts +9 -0
- package/dist/src/helpers/has.js +27 -0
- package/dist/src/helpers/is-children.js +3 -1
- package/dist/src/helpers/is-component.js +1 -3
- package/dist/src/helpers/is-html-attribute.d.ts +4 -0
- package/dist/src/helpers/is-html-attribute.js +380 -0
- package/dist/src/helpers/json.d.ts +3 -1
- package/dist/src/helpers/map-refs.js +39 -14
- package/dist/src/helpers/nullable.d.ts +3 -0
- package/dist/src/helpers/nullable.js +7 -0
- package/dist/src/helpers/parsers.js +1 -2
- package/dist/src/helpers/process-http-requests.js +1 -1
- package/dist/src/helpers/render-imports.d.ts +20 -2
- package/dist/src/helpers/render-imports.js +115 -54
- package/dist/src/helpers/render-imports.test.d.ts +1 -0
- package/dist/src/helpers/render-imports.test.js +33 -0
- package/dist/src/helpers/replace-idenifiers.js +5 -7
- package/dist/src/helpers/slots.d.ts +2 -0
- package/dist/src/helpers/slots.js +8 -0
- package/dist/src/helpers/state.d.ts +11 -0
- package/dist/src/helpers/state.js +43 -0
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +6 -1
- package/dist/src/helpers/strip-state-and-props-refs.js +70 -15
- 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 +31 -0
- package/dist/src/helpers/styles/helpers.js +80 -0
- package/dist/src/helpers/typescript.d.ts +5 -0
- package/dist/src/helpers/typescript.js +2 -0
- package/dist/src/index.d.ts +12 -4
- package/dist/src/index.js +28 -8
- package/dist/src/modules/plugins.d.ts +1 -1
- package/dist/src/parsers/angular.js +22 -34
- package/dist/src/parsers/builder.d.ts +32 -29
- package/dist/src/parsers/builder.js +99 -85
- package/dist/src/parsers/jsx/ast.d.ts +3 -0
- package/dist/src/parsers/jsx/ast.js +74 -0
- package/dist/src/parsers/jsx/component-types.d.ts +6 -0
- package/dist/src/parsers/jsx/component-types.js +88 -0
- package/dist/src/parsers/jsx/context.d.ts +6 -0
- package/dist/src/parsers/jsx/context.js +68 -0
- package/dist/src/parsers/jsx/helpers.d.ts +3 -0
- package/dist/src/parsers/jsx/helpers.js +36 -0
- package/dist/src/parsers/jsx/index.d.ts +4 -0
- package/dist/src/parsers/jsx/index.js +25 -0
- package/dist/src/parsers/jsx/jsx.d.ts +10 -0
- package/dist/src/parsers/{jsx.js → jsx/jsx.js} +258 -330
- package/dist/src/parsers/jsx/metadata.d.ts +12 -0
- package/dist/src/parsers/jsx/metadata.js +70 -0
- package/dist/src/parsers/jsx/props.d.ts +2 -0
- package/dist/src/parsers/jsx/props.js +72 -0
- package/dist/src/parsers/jsx/state.d.ts +13 -0
- package/dist/src/parsers/jsx/state.js +161 -0
- package/dist/src/parsers/jsx/types.d.ts +11 -0
- package/dist/src/parsers/jsx/types.js +2 -0
- package/dist/src/parsers/liquid.js +51 -149
- package/dist/src/plugins/compile-away-builder-components.js +161 -116
- package/dist/src/symbols/symbol-processor.d.ts +2 -0
- package/dist/src/symbols/symbol-processor.js +58 -20
- package/dist/src/targets.d.ts +11 -6
- package/dist/src/targets.js +13 -1
- package/dist/src/types/config.d.ts +42 -13
- package/dist/src/types/json.d.ts +5 -2
- package/dist/src/types/mitosis-component.d.ts +40 -12
- package/dist/src/types/mitosis-node.d.ts +15 -9
- package/dist/src/types/transpiler.d.ts +14 -0
- package/dist/src/types/transpiler.js +2 -0
- package/dist/test/qwik/Accordion/low.jsx +45 -12
- package/dist/test/qwik/Accordion/med.jsx +2 -8
- package/dist/test/qwik/For/low.jsx +46 -27
- package/dist/test/qwik/For/med.jsx +2 -8
- package/dist/test/qwik/Image/high.js +1 -1
- package/dist/test/qwik/Image/med.js +24 -18
- package/dist/test/qwik/Image.slow/high.js +1 -1
- package/dist/test/qwik/Image.slow/med.js +24 -18
- package/dist/test/qwik/bindings/low.cjs +16 -4
- package/dist/test/qwik/bindings/med.cjs +1 -10
- package/dist/test/qwik/button/high.js +1 -1
- package/dist/test/qwik/button/low.js +18 -4
- package/dist/test/qwik/button/med.js +4 -10
- package/dist/test/qwik/component/bindings/low.jsx +72 -11
- package/dist/test/qwik/component/bindings/med.jsx +3 -49
- package/dist/test/qwik/component/component/inputs/high.cjsx +1 -1
- package/dist/test/qwik/component/component/inputs/med.cjsx +18 -15
- package/dist/test/qwik/for-loop.bindings/high.cjs +0 -0
- package/dist/test/qwik/for-loop.bindings/low.cjs +56 -0
- package/dist/test/qwik/for-loop.bindings/med.cjs +5 -0
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +17 -3
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +2 -8
- package/dist/test/qwik/mount/high.cjs +0 -0
- package/dist/test/qwik/mount/low.cjs +47 -0
- package/dist/test/qwik/mount/med.cjs +3 -0
- package/dist/test/qwik/page-with-symbol/low.js +17 -3
- package/dist/test/qwik/page-with-symbol/med.js +2 -8
- package/dist/test/qwik/show-hide/high.jsx +1 -1
- package/dist/test/qwik/show-hide/med.jsx +28 -21
- package/dist/test/qwik/svg/low.js +22 -5
- package/dist/test/qwik/svg/med.js +2 -8
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +6 -10
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +18 -15
- package/dist/test/qwik/todo/Todo.js/high.js +7 -10
- package/dist/test/qwik/todo/Todo.js/med.js +17 -15
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +7 -10
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +17 -15
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +1 -1
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +18 -13
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +1 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jsx-runtime.d.ts +2133 -0
- package/package.json +20 -8
- package/README.md +0 -239
- 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 -35
- package/dist/src/helpers/collect-styles.js +0 -178
- package/dist/src/jsx-types.d.ts +0 -1171
- package/dist/src/parsers/jsx.d.ts +0 -20
|
@@ -10,6 +10,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
13
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
24
|
};
|
|
@@ -17,18 +26,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
26
|
exports.componentToCustomElement = exports.componentToHtml = void 0;
|
|
18
27
|
var core_1 = require("@babel/core");
|
|
19
28
|
var lodash_1 = require("lodash");
|
|
29
|
+
var lodash_2 = require("lodash");
|
|
20
30
|
var standalone_1 = require("prettier/standalone");
|
|
21
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");
|
|
22
35
|
var traverse_1 = __importDefault(require("traverse"));
|
|
23
36
|
var babel_transform_1 = require("../helpers/babel-transform");
|
|
24
|
-
var
|
|
37
|
+
var collect_css_1 = require("../helpers/styles/collect-css");
|
|
25
38
|
var dash_case_1 = require("../helpers/dash-case");
|
|
26
39
|
var fast_clone_1 = require("../helpers/fast-clone");
|
|
27
40
|
var get_state_object_string_1 = require("../helpers/get-state-object-string");
|
|
28
41
|
var has_component_1 = require("../helpers/has-component");
|
|
42
|
+
var has_bindings_text_1 = require("../helpers/has-bindings-text");
|
|
29
43
|
var is_component_1 = require("../helpers/is-component");
|
|
30
44
|
var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
|
|
31
|
-
var
|
|
45
|
+
var is_html_attribute_1 = require("../helpers/is-html-attribute");
|
|
46
|
+
var get_props_1 = require("../helpers/get-props");
|
|
47
|
+
var get_props_ref_1 = require("../helpers/get-props-ref");
|
|
48
|
+
var get_prop_functions_1 = require("../helpers/get-prop-functions");
|
|
32
49
|
var jsx_1 = require("../parsers/jsx");
|
|
33
50
|
var strip_state_and_props_refs_1 = require("../helpers/strip-state-and-props-refs");
|
|
34
51
|
var plugins_1 = require("../modules/plugins");
|
|
@@ -36,67 +53,89 @@ var is_children_1 = __importDefault(require("../helpers/is-children"));
|
|
|
36
53
|
var strip_meta_properties_1 = require("../helpers/strip-meta-properties");
|
|
37
54
|
var remove_surrounding_block_1 = require("../helpers/remove-surrounding-block");
|
|
38
55
|
var render_imports_1 = require("../helpers/render-imports");
|
|
56
|
+
var isAttribute = function (key) {
|
|
57
|
+
return /-/.test(key);
|
|
58
|
+
};
|
|
39
59
|
var ATTRIBUTE_KEY_EXCEPTIONS_MAP = {
|
|
40
60
|
class: 'className',
|
|
61
|
+
innerHtml: 'innerHTML',
|
|
41
62
|
};
|
|
42
63
|
var updateKeyIfException = function (key) {
|
|
43
64
|
var _a;
|
|
44
65
|
return (_a = ATTRIBUTE_KEY_EXCEPTIONS_MAP[key]) !== null && _a !== void 0 ? _a : key;
|
|
45
66
|
};
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
var generateSetElementAttributeCode = function (key, tagName, useValue, options, meta) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if (meta === void 0) { meta = {}; }
|
|
70
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.props) {
|
|
71
|
+
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.props(key, useValue, options);
|
|
72
|
+
}
|
|
73
|
+
var isKey = key === 'key';
|
|
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);
|
|
78
|
+
var isHtmlAttr = (0, is_html_attribute_1.isHtmlAttribute)(key, tagName);
|
|
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');
|
|
53
93
|
};
|
|
54
94
|
var addUpdateAfterSet = function (json, options) {
|
|
55
95
|
(0, traverse_1.default)(json).forEach(function (item) {
|
|
96
|
+
var _a;
|
|
56
97
|
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
57
98
|
for (var key in item.bindings) {
|
|
58
|
-
var value = item.bindings[key];
|
|
99
|
+
var value = (_a = item.bindings[key]) === null || _a === void 0 ? void 0 : _a.code;
|
|
59
100
|
var newValue = addUpdateAfterSetInCode(value, options);
|
|
60
101
|
if (newValue !== value) {
|
|
61
|
-
item.bindings[key] = newValue;
|
|
102
|
+
item.bindings[key].code = newValue;
|
|
62
103
|
}
|
|
63
104
|
}
|
|
64
105
|
}
|
|
65
106
|
});
|
|
66
107
|
};
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
108
|
+
var getChildComponents = function (json, options) {
|
|
109
|
+
var childComponents = [];
|
|
110
|
+
json.imports.forEach(function (_a) {
|
|
111
|
+
var imports = _a.imports;
|
|
112
|
+
Object.keys(imports).forEach(function (key) {
|
|
113
|
+
if (imports[key] === 'default') {
|
|
114
|
+
childComponents.push(key);
|
|
73
115
|
}
|
|
74
|
-
}
|
|
116
|
+
});
|
|
75
117
|
});
|
|
76
|
-
return
|
|
118
|
+
return childComponents;
|
|
77
119
|
};
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
83
|
-
for (var key in item.bindings) {
|
|
84
|
-
if (key === 'css' || key === '_forName') {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
var value = item.bindings[key];
|
|
88
|
-
if (typeof value === 'string') {
|
|
89
|
-
item.bindings[key] = (0, replace_idenifiers_1.replaceIdentifiers)(value, forNames, function (name) {
|
|
90
|
-
return "".concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(name, "\")");
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
120
|
+
var getScopeVars = function (parentScopeVars, value) {
|
|
121
|
+
return parentScopeVars.filter(function (scopeVar) {
|
|
122
|
+
if (typeof value === 'boolean') {
|
|
123
|
+
return value;
|
|
94
124
|
}
|
|
125
|
+
var checkVar = new RegExp('(\\.\\.\\.|,| |;|\\(|^|!)' + scopeVar + '(\\.|,| |;|\\)|$)', 'g');
|
|
126
|
+
return checkVar.test(value);
|
|
95
127
|
});
|
|
96
128
|
};
|
|
129
|
+
var addScopeVars = function (parentScopeVars, value, fn) {
|
|
130
|
+
return "".concat(getScopeVars(parentScopeVars, value)
|
|
131
|
+
.map(function (scopeVar) {
|
|
132
|
+
return fn(scopeVar);
|
|
133
|
+
})
|
|
134
|
+
.join('\n'));
|
|
135
|
+
};
|
|
97
136
|
var mappers = {
|
|
98
|
-
Fragment: function (json, options) {
|
|
99
|
-
return json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
|
|
137
|
+
Fragment: function (json, options, blockOptions) {
|
|
138
|
+
return json.children.map(function (item) { return blockToHtml(item, options, blockOptions); }).join('\n');
|
|
100
139
|
},
|
|
101
140
|
};
|
|
102
141
|
var getId = function (json, options) {
|
|
@@ -109,17 +148,35 @@ var getId = function (json, options) {
|
|
|
109
148
|
options.namesMap[name] = newNameNum;
|
|
110
149
|
return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '').concat(name !== json.name && newNameNum === 1 ? '' : "-".concat(newNameNum));
|
|
111
150
|
};
|
|
112
|
-
var
|
|
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
|
+
};
|
|
156
|
+
// TODO: overloaded function
|
|
157
|
+
var updateReferencesInCode = function (code, options, blockOptions) {
|
|
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.';
|
|
162
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.updateReferencesInCode) {
|
|
163
|
+
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.updateReferencesInCode(code, options, {
|
|
164
|
+
stripStateAndPropsRefs: strip_state_and_props_refs_1.stripStateAndPropsRefs,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
113
167
|
if (options.format === 'class') {
|
|
114
168
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
115
169
|
includeProps: false,
|
|
116
170
|
includeState: true,
|
|
117
|
-
replaceWith: '
|
|
171
|
+
replaceWith: context + 'state.',
|
|
172
|
+
context: context,
|
|
118
173
|
}), {
|
|
119
174
|
// TODO: replace with `this.` and add setters that call this.update()
|
|
120
175
|
includeProps: true,
|
|
121
176
|
includeState: false,
|
|
122
|
-
replaceWith: '
|
|
177
|
+
replaceWith: context + 'props.',
|
|
178
|
+
contextVars: contextVars,
|
|
179
|
+
context: context,
|
|
123
180
|
});
|
|
124
181
|
}
|
|
125
182
|
return code;
|
|
@@ -131,15 +188,24 @@ var addOnChangeJs = function (id, options, code) {
|
|
|
131
188
|
options.onChangeJsById[id] += code;
|
|
132
189
|
};
|
|
133
190
|
// TODO: spread support
|
|
134
|
-
var blockToHtml = function (json, options) {
|
|
191
|
+
var blockToHtml = function (json, options, blockOptions) {
|
|
192
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
193
|
+
if (blockOptions === void 0) { blockOptions = {}; }
|
|
194
|
+
var ComponentName = blockOptions.ComponentName;
|
|
195
|
+
var scopeVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.scopeVars) || [];
|
|
196
|
+
var childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
135
197
|
var hasData = Object.keys(json.bindings).length;
|
|
198
|
+
var hasDomState = /input|textarea|select/.test(json.name);
|
|
136
199
|
var elId = '';
|
|
137
200
|
if (hasData) {
|
|
138
201
|
elId = getId(json, options);
|
|
139
|
-
json.properties['data-
|
|
202
|
+
json.properties['data-el'] = elId;
|
|
203
|
+
}
|
|
204
|
+
if (hasDomState) {
|
|
205
|
+
json.properties['data-dom-state'] = createGlobalId((ComponentName ? ComponentName + '-' : '') + json.name, options);
|
|
140
206
|
}
|
|
141
207
|
if (mappers[json.name]) {
|
|
142
|
-
return mappers[json.name](json, options);
|
|
208
|
+
return mappers[json.name](json, options, blockOptions);
|
|
143
209
|
}
|
|
144
210
|
if ((0, is_children_1.default)(json)) {
|
|
145
211
|
return "<slot></slot>";
|
|
@@ -147,35 +213,48 @@ var blockToHtml = function (json, options) {
|
|
|
147
213
|
if (json.properties._text) {
|
|
148
214
|
return json.properties._text;
|
|
149
215
|
}
|
|
150
|
-
if (json.bindings._text) {
|
|
216
|
+
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
151
217
|
// TO-DO: textContent might be better performance-wise
|
|
152
|
-
addOnChangeJs(elId, options, "
|
|
153
|
-
|
|
218
|
+
addOnChangeJs(elId, options, "\n ".concat(addScopeVars(scopeVars, json.bindings._text.code, function (scopeVar) {
|
|
219
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
220
|
+
}), "\n ").concat(options.format === 'class' ? 'this.' : '', "renderTextNode(el, ").concat(json.bindings._text.code, ");"));
|
|
221
|
+
return "<template data-el=\"".concat(elId, "\"><!-- ").concat((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code, " --></template>");
|
|
154
222
|
}
|
|
155
223
|
var str = '';
|
|
156
224
|
if (json.name === 'For') {
|
|
157
|
-
var
|
|
225
|
+
var forArguments = ((_c = json === null || json === void 0 ? void 0 : json.scope) === null || _c === void 0 ? void 0 : _c.For) || [];
|
|
226
|
+
var localScopeVars_1 = __spreadArray(__spreadArray([], scopeVars, true), forArguments, true);
|
|
227
|
+
var argsStr = forArguments.map(function (arg) { return "\"".concat(arg, "\""); }).join(',');
|
|
158
228
|
addOnChangeJs(elId, options,
|
|
159
229
|
// TODO: be smarter about rendering, deleting old items and adding new ones by
|
|
160
230
|
// querying dom potentially
|
|
161
|
-
"\n let array = ".concat(json.bindings.each
|
|
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 "));
|
|
162
232
|
// TODO: decide on how to handle this...
|
|
163
|
-
str += "\n <
|
|
233
|
+
str += "\n <template data-el=\"".concat(elId, "\">");
|
|
164
234
|
if (json.children) {
|
|
165
|
-
str += json.children
|
|
235
|
+
str += json.children
|
|
236
|
+
.map(function (item) {
|
|
237
|
+
return blockToHtml(item, options, __assign(__assign({}, blockOptions), { scopeVars: localScopeVars_1 }));
|
|
238
|
+
})
|
|
239
|
+
.join('\n');
|
|
166
240
|
}
|
|
167
241
|
str += '</template>';
|
|
168
242
|
}
|
|
169
243
|
else if (json.name === 'Show') {
|
|
170
|
-
|
|
171
|
-
|
|
244
|
+
var whenCondition = ((_e = json.bindings.when) === null || _e === void 0 ? void 0 : _e.code).replace(/;$/, '');
|
|
245
|
+
addOnChangeJs(elId, options, "\n ".concat(addScopeVars(scopeVars, whenCondition, function (scopeVar) {
|
|
246
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
247
|
+
}), "\n const whenCondition = ").concat(whenCondition, ";\n if (whenCondition) {\n ").concat(options.format === 'class' ? 'this.' : '', "showContent(el)\n }\n "));
|
|
248
|
+
str += "<template data-el=\"".concat(elId, "\">");
|
|
172
249
|
if (json.children) {
|
|
173
|
-
str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
|
|
250
|
+
str += json.children.map(function (item) { return blockToHtml(item, options, blockOptions); }).join('\n');
|
|
174
251
|
}
|
|
175
252
|
str += '</template>';
|
|
176
253
|
}
|
|
177
254
|
else {
|
|
178
|
-
|
|
255
|
+
var component = childComponents.find(function (impName) { return impName === json.name; });
|
|
256
|
+
var elSelector = component ? (0, lodash_2.kebabCase)(json.name) : json.name;
|
|
257
|
+
str += "<".concat(elSelector, " ");
|
|
179
258
|
// For now, spread is not supported
|
|
180
259
|
// if (json.bindings._spread === '_spread') {
|
|
181
260
|
// str += `
|
|
@@ -191,16 +270,19 @@ var blockToHtml = function (json, options) {
|
|
|
191
270
|
if (key.startsWith('$')) {
|
|
192
271
|
continue;
|
|
193
272
|
}
|
|
194
|
-
var value = (json.properties[key] || '')
|
|
195
|
-
.replace(/"/g, '"')
|
|
196
|
-
.replace(/\n/g, '\\n');
|
|
273
|
+
var value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
197
274
|
str += " ".concat(key, "=\"").concat(value, "\" ");
|
|
198
275
|
}
|
|
276
|
+
// batch all local vars within the bindings
|
|
277
|
+
var batchScopeVars_1 = {};
|
|
278
|
+
var injectOnce = false;
|
|
279
|
+
var startInjectVar = '%%START_VARS%%';
|
|
199
280
|
for (var key in json.bindings) {
|
|
200
|
-
if (key === '_spread' || key === '
|
|
281
|
+
if (key === '_spread' || key === 'css') {
|
|
201
282
|
continue;
|
|
202
283
|
}
|
|
203
|
-
var value = json.bindings[key];
|
|
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'];
|
|
204
286
|
// TODO: proper babel transform to replace. Util for this
|
|
205
287
|
var useValue = value;
|
|
206
288
|
if (key.startsWith('on')) {
|
|
@@ -209,33 +291,60 @@ var blockToHtml = function (json, options) {
|
|
|
209
291
|
event_1 = 'input';
|
|
210
292
|
}
|
|
211
293
|
var fnName = (0, lodash_1.camelCase)("on-".concat(elId, "-").concat(event_1));
|
|
294
|
+
var codeContent = (0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options, blockOptions));
|
|
212
295
|
options.js += "\n // Event handler for '".concat(event_1, "' event on ").concat(elId, "\n ").concat(options.format === 'class'
|
|
213
|
-
? "this.".concat(fnName, " = (
|
|
214
|
-
: "function ".concat(fnName, " (
|
|
296
|
+
? "this.".concat(fnName, " = (").concat(cusArg.join(','), ") => {")
|
|
297
|
+
: "function ".concat(fnName, " (").concat(cusArg.join(','), ") {"), "\n ").concat(addScopeVars(scopeVars, codeContent, function (scopeVar) {
|
|
298
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(event.currentTarget, \"").concat(scopeVar, "\");");
|
|
299
|
+
}), "\n ").concat(codeContent, "\n }\n ");
|
|
215
300
|
var fnIdentifier = "".concat(options.format === 'class' ? 'this.' : '').concat(fnName);
|
|
216
301
|
addOnChangeJs(elId, options, "\n ;el.removeEventListener('".concat(event_1, "', ").concat(fnIdentifier, ");\n ;el.addEventListener('").concat(event_1, "', ").concat(fnIdentifier, ");\n "));
|
|
217
302
|
}
|
|
303
|
+
else if (key === 'ref') {
|
|
304
|
+
str += " data-ref=\"".concat(ComponentName, "-").concat(useValue, "\" ");
|
|
305
|
+
}
|
|
218
306
|
else {
|
|
219
307
|
if (key === 'style') {
|
|
220
|
-
addOnChangeJs(elId, options, "
|
|
308
|
+
addOnChangeJs(elId, options, "\n ".concat(addScopeVars(scopeVars, useValue, function (scopeVar) {
|
|
309
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
310
|
+
}), "\n ;Object.assign(el.style, ").concat(useValue, ");"));
|
|
221
311
|
}
|
|
222
312
|
else {
|
|
223
|
-
|
|
313
|
+
// gather all local vars to inject later
|
|
314
|
+
getScopeVars(scopeVars, useValue).forEach(function (key) {
|
|
315
|
+
// unique keys
|
|
316
|
+
batchScopeVars_1[key] = true;
|
|
317
|
+
});
|
|
318
|
+
addOnChangeJs(elId, options, "\n ".concat(injectOnce ? '' : startInjectVar, "\n ").concat(generateSetElementAttributeCode(key, elSelector, useValue, options, {
|
|
319
|
+
component: component,
|
|
320
|
+
}), "\n "));
|
|
321
|
+
if (!injectOnce) {
|
|
322
|
+
injectOnce = true;
|
|
323
|
+
}
|
|
224
324
|
}
|
|
225
325
|
}
|
|
226
326
|
}
|
|
327
|
+
// batch inject local vars in the beginning of the function block
|
|
328
|
+
var codeBlock = options.onChangeJsById[elId];
|
|
329
|
+
var testInjectVar = new RegExp(startInjectVar);
|
|
330
|
+
if (codeBlock && testInjectVar.test(codeBlock)) {
|
|
331
|
+
var localScopeVars = Object.keys(batchScopeVars_1);
|
|
332
|
+
options.onChangeJsById[elId] = codeBlock.replace(startInjectVar, "\n ".concat(addScopeVars(localScopeVars, true, function (scopeVar) {
|
|
333
|
+
return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getScope(el, \"").concat(scopeVar, "\");");
|
|
334
|
+
}), "\n "));
|
|
335
|
+
}
|
|
227
336
|
if (jsx_1.selfClosingTags.has(json.name)) {
|
|
228
337
|
return str + ' />';
|
|
229
338
|
}
|
|
230
339
|
str += '>';
|
|
231
340
|
if (json.children) {
|
|
232
|
-
str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
|
|
341
|
+
str += json.children.map(function (item) { return blockToHtml(item, options, blockOptions); }).join('\n');
|
|
233
342
|
}
|
|
234
343
|
if (json.properties.innerHTML) {
|
|
235
344
|
// Maybe put some kind of safety here for broken HTML such as no close tag
|
|
236
345
|
str += htmlDecode(json.properties.innerHTML);
|
|
237
346
|
}
|
|
238
|
-
str += "</".concat(
|
|
347
|
+
str += "</".concat(elSelector, ">");
|
|
239
348
|
}
|
|
240
349
|
return str;
|
|
241
350
|
};
|
|
@@ -244,6 +353,7 @@ function addUpdateAfterSetInCode(code, options, useString) {
|
|
|
244
353
|
var updates = 0;
|
|
245
354
|
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
246
355
|
AssignmentExpression: function (path) {
|
|
356
|
+
var _a, _b;
|
|
247
357
|
var node = path.node;
|
|
248
358
|
if (core_1.types.isMemberExpression(node.left)) {
|
|
249
359
|
if (core_1.types.isIdentifier(node.left.object)) {
|
|
@@ -267,6 +377,13 @@ function addUpdateAfterSetInCode(code, options, useString) {
|
|
|
267
377
|
// console.error('Infinite assignment detected');
|
|
268
378
|
// return;
|
|
269
379
|
// }
|
|
380
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.addUpdateAfterSetInCode) {
|
|
381
|
+
useString = (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.addUpdateAfterSetInCode(useString, options, {
|
|
382
|
+
node: node,
|
|
383
|
+
code: code,
|
|
384
|
+
types: core_1.types,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
270
387
|
path.insertAfter(core_1.types.callExpression(core_1.types.identifier(useString), []));
|
|
271
388
|
}
|
|
272
389
|
}
|
|
@@ -279,60 +396,63 @@ var htmlDecode = function (html) { return html.replace(/"/gi, '"'); };
|
|
|
279
396
|
var componentToHtml = function (options) {
|
|
280
397
|
if (options === void 0) { options = {}; }
|
|
281
398
|
return function (_a) {
|
|
282
|
-
var _b, _c, _d;
|
|
399
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
283
400
|
var component = _a.component;
|
|
284
401
|
var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'script' });
|
|
285
402
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
286
403
|
if (options.plugins) {
|
|
287
404
|
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
288
405
|
}
|
|
289
|
-
replaceForNameIdentifiers(json, useOptions);
|
|
290
406
|
addUpdateAfterSet(json, useOptions);
|
|
291
407
|
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
292
408
|
var hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
409
|
+
var hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
410
|
+
var hasTextBinding = (0, has_bindings_text_1.hasBindingsText)(json);
|
|
293
411
|
if (options.plugins) {
|
|
294
412
|
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
295
413
|
}
|
|
296
|
-
var css = (0,
|
|
414
|
+
var css = (0, collect_css_1.collectCss)(json, {
|
|
297
415
|
prefix: options.prefix,
|
|
298
416
|
});
|
|
299
|
-
var str = json.children
|
|
300
|
-
.map(function (item) { return blockToHtml(item, useOptions); })
|
|
301
|
-
.join('\n');
|
|
417
|
+
var str = json.children.map(function (item) { return blockToHtml(item, useOptions); }).join('\n');
|
|
302
418
|
if (css.trim().length) {
|
|
303
419
|
str += "<style>".concat(css, "</style>");
|
|
304
420
|
}
|
|
305
421
|
var hasChangeListeners = Boolean(Object.keys(useOptions.onChangeJsById).length);
|
|
306
422
|
var hasGeneratedJs = Boolean(useOptions.js.trim().length);
|
|
307
|
-
if (hasChangeListeners ||
|
|
308
|
-
hasGeneratedJs ||
|
|
309
|
-
((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) ||
|
|
310
|
-
hasLoop) {
|
|
423
|
+
if (hasChangeListeners || hasGeneratedJs || ((_b = json.hooks.onMount) === null || _b === void 0 ? void 0 : _b.code) || hasLoop) {
|
|
311
424
|
// TODO: collectJs helper for here and liquid
|
|
312
425
|
str += "\n <script>\n (() => {\n const state = ".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
313
426
|
valueMapper: function (value) {
|
|
314
427
|
return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
|
|
315
428
|
},
|
|
316
|
-
}), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\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
|
|
317
430
|
? ''
|
|
318
|
-
: "\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)
|
|
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)
|
|
319
432
|
.map(function (key) {
|
|
320
433
|
var value = useOptions.onChangeJsById[key];
|
|
321
434
|
if (!value) {
|
|
322
435
|
return '';
|
|
323
436
|
}
|
|
324
|
-
return "\n document.querySelectorAll(\"[data-
|
|
437
|
+
return "\n document.querySelectorAll(\"[data-el='".concat(key, "']\").forEach((el) => {\n ").concat(value, "\n });\n ");
|
|
325
438
|
})
|
|
326
|
-
.join('\n\n'), "\n\n
|
|
439
|
+
.join('\n\n'), "\n\n destroyAnyNodes();\n\n ").concat(!((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
|
|
327
440
|
? ''
|
|
328
|
-
: "\n
|
|
329
|
-
|
|
330
|
-
|
|
441
|
+
: "\n ".concat(json.hooks.onUpdate.reduce(function (code, hook) {
|
|
442
|
+
code += addUpdateAfterSetInCode(updateReferencesInCode(hook.code, useOptions), useOptions);
|
|
443
|
+
return code + '\n';
|
|
444
|
+
}, ''), " \n "), "\n\n pendingUpdate = false;\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!((_g = (_f = json.hooks) === null || _f === void 0 ? void 0 : _f.onInit) === null || _g === void 0 ? void 0 : _g.code)
|
|
445
|
+
? ''
|
|
446
|
+
: "\n if (!onInitOnce) {\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode((_j = (_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit) === null || _j === void 0 ? void 0 : _j.code, useOptions), useOptions), "\n onInitOnce = true;\n }\n "), "\n\n ").concat(!((_k = json.hooks.onMount) === null || _k === void 0 ? void 0 : _k.code)
|
|
331
447
|
? ''
|
|
332
448
|
: // TODO: make prettier by grabbing only the function body
|
|
333
|
-
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), " \n "), "\n\n ").concat(!
|
|
449
|
+
"\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), " \n "), "\n\n ").concat(!hasShow
|
|
450
|
+
? ''
|
|
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
|
|
334
454
|
? ''
|
|
335
|
-
: "\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 ");
|
|
336
456
|
}
|
|
337
457
|
if (options.plugins) {
|
|
338
458
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
@@ -365,28 +485,83 @@ exports.componentToHtml = componentToHtml;
|
|
|
365
485
|
var componentToCustomElement = function (options) {
|
|
366
486
|
if (options === void 0) { options = {}; }
|
|
367
487
|
return function (_a) {
|
|
368
|
-
var _b, _c, _d, _e;
|
|
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;
|
|
369
489
|
var component = _a.component;
|
|
370
|
-
var
|
|
490
|
+
var ComponentName = component.name;
|
|
491
|
+
var kebabName = (0, lodash_2.kebabCase)(ComponentName);
|
|
492
|
+
var useOptions = __assign(__assign({ prefix: kebabName }, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
|
|
371
493
|
var json = (0, fast_clone_1.fastClone)(component);
|
|
372
494
|
if (options.plugins) {
|
|
373
495
|
json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
|
|
374
496
|
}
|
|
497
|
+
var _15 = (0, get_props_ref_1.getPropsRef)(json, true), forwardProp = _15[0], hasPropRef = _15[1];
|
|
498
|
+
var contextVars = Object.keys(((_b = json === null || json === void 0 ? void 0 : json.context) === null || _b === void 0 ? void 0 : _b.get) || {});
|
|
499
|
+
var childComponents = getChildComponents(json, useOptions);
|
|
375
500
|
var componentHasProps = (0, has_props_1.hasProps)(json);
|
|
376
|
-
|
|
501
|
+
var componentHasStatefulDom = (0, has_stateful_dom_1.hasStatefulDom)(json);
|
|
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
|
+
}
|
|
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 _16 = json.context.set[key], name_1 = _16.name, value = _16.value, ref = _16.ref;
|
|
522
|
+
setContext.push({ name: name_1, value: value, ref: ref });
|
|
523
|
+
}
|
|
377
524
|
addUpdateAfterSet(json, useOptions);
|
|
525
|
+
var hasContext = context.length;
|
|
378
526
|
var hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
527
|
+
var hasScope = hasLoop;
|
|
528
|
+
var hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
379
529
|
if (options.plugins) {
|
|
380
530
|
json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
|
|
381
531
|
}
|
|
382
|
-
var css =
|
|
383
|
-
|
|
384
|
-
|
|
532
|
+
var css = '';
|
|
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,
|
|
536
|
+
prefix: options.prefix,
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
css = (0, collect_css_1.collectCss)(json, {
|
|
541
|
+
prefix: options.prefix,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
385
544
|
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
386
545
|
var html = json.children
|
|
387
|
-
.map(function (item) {
|
|
546
|
+
.map(function (item) {
|
|
547
|
+
return blockToHtml(item, useOptions, {
|
|
548
|
+
childComponents: childComponents,
|
|
549
|
+
props: props,
|
|
550
|
+
outputs: outputs,
|
|
551
|
+
ComponentName: ComponentName,
|
|
552
|
+
contextVars: contextVars,
|
|
553
|
+
});
|
|
554
|
+
})
|
|
388
555
|
.join('\n');
|
|
389
|
-
|
|
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);
|
|
558
|
+
}
|
|
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);
|
|
561
|
+
}
|
|
562
|
+
else if (css.length) {
|
|
563
|
+
html += "<style>".concat(css, "</style>");
|
|
564
|
+
}
|
|
390
565
|
if (options.prettier !== false) {
|
|
391
566
|
try {
|
|
392
567
|
html = (0, standalone_1.format)(html, {
|
|
@@ -406,10 +581,17 @@ var componentToCustomElement = function (options) {
|
|
|
406
581
|
console.warn('Could not prettify', { string: html }, err);
|
|
407
582
|
}
|
|
408
583
|
}
|
|
409
|
-
var
|
|
410
|
-
.
|
|
411
|
-
.
|
|
412
|
-
|
|
584
|
+
var str = "\n ".concat(json.types ? json.types.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(((_j = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _j === void 0 ? void 0 : _j.classExtends)
|
|
585
|
+
? (_k = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _k === void 0 ? void 0 : _k.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 && ((_l = setContext === null || setContext === void 0 ? void 0 : setContext[0]) === null || _l === void 0 ? void 0 : _l.ref)
|
|
593
|
+
? "this.context = ".concat(setContext[0].ref)
|
|
594
|
+
: '', "\n\n ").concat(!((_o = (_m = json.hooks) === null || _m === void 0 ? void 0 : _m.onInit) === null || _o === void 0 ? void 0 : _o.code) ? '' : 'this.onInitOnce = false;', "\n\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
413
595
|
valueMapper: function (value) {
|
|
414
596
|
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
|
|
415
597
|
includeProps: false,
|
|
@@ -421,32 +603,107 @@ var componentToCustomElement = function (options) {
|
|
|
421
603
|
includeProps: true,
|
|
422
604
|
includeState: false,
|
|
423
605
|
replaceWith: 'self.props.',
|
|
606
|
+
contextVars: contextVars,
|
|
607
|
+
// correctly ref the class not state object
|
|
608
|
+
context: 'self.',
|
|
424
609
|
});
|
|
425
610
|
},
|
|
426
|
-
}), ";\n ").concat(componentHasProps
|
|
427
|
-
?
|
|
428
|
-
:
|
|
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(!((_p = json.hooks.onUpdate) === null || _p === void 0 ? void 0 : _p.length)
|
|
616
|
+
? ''
|
|
617
|
+
: "\n this.updateDeps = [".concat((_q = json.hooks.onUpdate) === null || _q === void 0 ? void 0 : _q.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(((_r = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _r === void 0 ? void 0 : _r.componentConstructor)
|
|
618
|
+
? (_s = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _s === void 0 ? void 0 : _s.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((_t = json.meta.useMetadata) === null || _t === void 0 ? void 0 : _t.isAttachedToShadowDom, ") {\n this.attachShadow({ mode: 'open' })\n }\n }\n\n\n ").concat(!((_u = json.hooks.onUnMount) === null || _u === void 0 ? void 0 : _u.code)
|
|
429
627
|
? ''
|
|
430
|
-
: "\n
|
|
628
|
+
: "\n disconnectedCallback() {\n ".concat(((_v = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _v === void 0 ? void 0 : _v.disconnectedCallback)
|
|
629
|
+
? (_w = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _w === void 0 ? void 0 : _w.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(!((_y = (_x = json.hooks) === null || _x === void 0 ? void 0 : _x.onInit) === null || _y === void 0 ? void 0 : _y.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
|
|
431
633
|
? ''
|
|
432
|
-
: "\n
|
|
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(((_z = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _z === void 0 ? void 0 : _z.connectedCallbackUpdate)
|
|
635
|
+
? (_0 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _0 === void 0 ? void 0 : _0.connectedCallbackUpdate(json, html, useOptions)
|
|
636
|
+
: "\n this._root.innerHTML = `\n ".concat(html, "`;\n this.pendingUpdate = true;\n ").concat(!((_2 = (_1 = json.hooks) === null || _1 === void 0 ? void 0 : _1.onInit) === null || _2 === void 0 ? void 0 : _2.code) ? '' : 'this.onInit();', "\n this.render();\n this.onMount();\n this.pendingUpdate = false;\n this.update();\n "), "\n }\n ").concat(!((_4 = (_3 = json.hooks) === null || _3 === void 0 ? void 0 : _3.onInit) === null || _4 === void 0 ? void 0 : _4.code)
|
|
637
|
+
? ''
|
|
638
|
+
: "\n onInit() {\n ".concat(!((_6 = (_5 = json.hooks) === null || _5 === void 0 ? void 0 : _5.onInit) === null || _6 === void 0 ? void 0 : _6.code)
|
|
639
|
+
? ''
|
|
640
|
+
: "\n if (!this.onInitOnce) {\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode((_8 = (_7 = json.hooks) === null || _7 === void 0 ? void 0 : _7.onInit) === null || _8 === void 0 ? void 0 : _8.code, useOptions), useOptions, {
|
|
641
|
+
contextVars: contextVars,
|
|
642
|
+
}), "\n this.onInitOnce = true;\n }"), "\n }\n "), "\n\n ").concat(!hasShow
|
|
643
|
+
? ''
|
|
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(!((_9 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _9 === void 0 ? void 0 : _9.attributeChangedCallback)
|
|
645
|
+
? ''
|
|
646
|
+
: "\n attributeChangedCallback(name, oldValue, newValue) {\n ".concat((_10 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _10 === void 0 ? void 0 : _10.attributeChangedCallback(['name', 'oldValue', 'newValue'], json, useOptions), "\n }\n "), "\n\n onMount() {\n ").concat(!((_11 = json.hooks.onMount) === null || _11 === void 0 ? void 0 : _11.code)
|
|
433
647
|
? ''
|
|
434
648
|
: // TODO: make prettier by grabbing only the function body
|
|
435
|
-
"\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(!((_12 = json.hooks.onUpdate) === null || _12 === void 0 ? void 0 : _12.length)
|
|
652
|
+
? ''
|
|
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
|
+
}
|
|
670
|
+
return code + '\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
|
|
436
672
|
? ''
|
|
437
|
-
: "\n
|
|
438
|
-
|
|
439
|
-
|
|
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
|
|
674
|
+
? ''
|
|
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
|
|
676
|
+
? ''
|
|
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)
|
|
440
678
|
.map(function (key) {
|
|
679
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
441
680
|
var value = useOptions.onChangeJsById[key];
|
|
442
681
|
if (!value) {
|
|
443
682
|
return '';
|
|
444
683
|
}
|
|
445
|
-
|
|
684
|
+
var code = '';
|
|
685
|
+
if ((_a = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _a === void 0 ? void 0 : _a.updateBindings) {
|
|
686
|
+
key = (_c = (_b = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _b === void 0 ? void 0 : _b.updateBindings) === null || _c === void 0 ? void 0 : _c.key(key, value, useOptions);
|
|
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);
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
code = updateReferencesInCode(value, useOptions, {
|
|
691
|
+
contextVars: contextVars,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
return "\n ".concat(((_f = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _f === void 0 ? void 0 : _f.generateQuerySelectorAll)
|
|
695
|
+
? "\n ".concat((_g = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _g === void 0 ? void 0 : _g.generateQuerySelectorAll(key, code), "\n ")
|
|
696
|
+
: " \n this._root.querySelectorAll(\"[data-el='".concat(key, "']\").forEach((el) => {\n ").concat(code, "\n })\n "), "\n ");
|
|
446
697
|
})
|
|
447
|
-
.join('\n\n'), "\n }\n\n ").concat(!
|
|
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
|
|
448
703
|
? ''
|
|
449
|
-
: "\n\n // Helper to render loops\n renderLoop(
|
|
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(((_13 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _13 === void 0 ? void 0 : _13.customElementsDefine)
|
|
705
|
+
? (_14 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _14 === void 0 ? void 0 : _14.customElementsDefine(kebabName, component, useOptions)
|
|
706
|
+
: "customElements.define('".concat(kebabName, "', ").concat(ComponentName, ");"), "\n ");
|
|
450
707
|
if (options.plugins) {
|
|
451
708
|
str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
|
|
452
709
|
}
|