@builder.io/mitosis 0.0.0-dev-20260605060721
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/constants/hooks.d.ts +16 -0
- package/dist/src/constants/hooks.js +19 -0
- package/dist/src/constants/html_tags.d.ts +2 -0
- package/dist/src/constants/html_tags.js +198 -0
- package/dist/src/constants/media-sizes.d.ts +22 -0
- package/dist/src/constants/media-sizes.js +34 -0
- package/dist/src/constants/method-literal-prefix.d.ts +1 -0
- package/dist/src/constants/method-literal-prefix.js +2 -0
- package/dist/src/flow.d.ts +26 -0
- package/dist/src/flow.js +27 -0
- package/dist/src/generators/alpine/generate.d.ts +11 -0
- package/dist/src/generators/alpine/generate.js +201 -0
- package/dist/src/generators/alpine/index.d.ts +2 -0
- package/dist/src/generators/alpine/index.js +18 -0
- package/dist/src/generators/alpine/render-mount-hook.d.ts +2 -0
- package/dist/src/generators/alpine/render-mount-hook.js +17 -0
- package/dist/src/generators/alpine/render-update-hooks.d.ts +5 -0
- package/dist/src/generators/alpine/render-update-hooks.js +44 -0
- package/dist/src/generators/alpine/types.d.ts +12 -0
- package/dist/src/generators/alpine/types.js +2 -0
- package/dist/src/generators/angular/classic/blocks.d.ts +10 -0
- package/dist/src/generators/angular/classic/blocks.js +409 -0
- package/dist/src/generators/angular/classic/component.d.ts +3 -0
- package/dist/src/generators/angular/classic/component.js +356 -0
- package/dist/src/generators/angular/classic/plugins/get-class-properties-plugin.d.ts +2 -0
- package/dist/src/generators/angular/classic/plugins/get-class-properties-plugin.js +138 -0
- package/dist/src/generators/angular/classic/plugins/get-code-processor-plugins.d.ts +8 -0
- package/dist/src/generators/angular/classic/plugins/get-code-processor-plugins.js +60 -0
- package/dist/src/generators/angular/component.d.ts +3 -0
- package/dist/src/generators/angular/component.js +27 -0
- package/dist/src/generators/angular/helpers/format.d.ts +1 -0
- package/dist/src/generators/angular/helpers/format.js +24 -0
- package/dist/src/generators/angular/helpers/get-inputs.d.ts +7 -0
- package/dist/src/generators/angular/helpers/get-inputs.js +18 -0
- package/dist/src/generators/angular/helpers/get-outputs.d.ts +7 -0
- package/dist/src/generators/angular/helpers/get-outputs.js +23 -0
- package/dist/src/generators/angular/helpers/get-refs.d.ts +8 -0
- package/dist/src/generators/angular/helpers/get-refs.js +40 -0
- package/dist/src/generators/angular/helpers/get-styles.d.ts +6 -0
- package/dist/src/generators/angular/helpers/get-styles.js +17 -0
- package/dist/src/generators/angular/helpers/hooks.d.ts +25 -0
- package/dist/src/generators/angular/helpers/hooks.js +59 -0
- package/dist/src/generators/angular/helpers/index.d.ts +33 -0
- package/dist/src/generators/angular/helpers/index.js +221 -0
- package/dist/src/generators/angular/helpers/parse-selector.d.ts +5 -0
- package/dist/src/generators/angular/helpers/parse-selector.js +19 -0
- package/dist/src/generators/angular/index.d.ts +2 -0
- package/dist/src/generators/angular/index.js +18 -0
- package/dist/src/generators/angular/signals/blocks.d.ts +10 -0
- package/dist/src/generators/angular/signals/blocks.js +379 -0
- package/dist/src/generators/angular/signals/component.d.ts +3 -0
- package/dist/src/generators/angular/signals/component.js +377 -0
- package/dist/src/generators/angular/signals/helpers/get-computed.d.ts +6 -0
- package/dist/src/generators/angular/signals/helpers/get-computed.js +79 -0
- package/dist/src/generators/angular/signals/helpers/get-dynamic-template-refs.d.ts +2 -0
- package/dist/src/generators/angular/signals/helpers/get-dynamic-template-refs.js +25 -0
- package/dist/src/generators/angular/signals/helpers/get-inputs.d.ts +7 -0
- package/dist/src/generators/angular/signals/helpers/get-inputs.js +15 -0
- package/dist/src/generators/angular/signals/helpers/index.d.ts +16 -0
- package/dist/src/generators/angular/signals/helpers/index.js +30 -0
- package/dist/src/generators/angular/signals/plugins/get-code-processor-plugins.d.ts +4 -0
- package/dist/src/generators/angular/signals/plugins/get-code-processor-plugins.js +547 -0
- package/dist/src/generators/angular/types.d.ts +72 -0
- package/dist/src/generators/angular/types.js +12 -0
- package/dist/src/generators/builder/generator.d.ts +12 -0
- package/dist/src/generators/builder/generator.js +876 -0
- package/dist/src/generators/builder/index.d.ts +2 -0
- package/dist/src/generators/builder/index.js +18 -0
- package/dist/src/generators/builder/types.d.ts +6 -0
- package/dist/src/generators/builder/types.js +2 -0
- package/dist/src/generators/context/angular.d.ts +9 -0
- package/dist/src/generators/context/angular.js +40 -0
- package/dist/src/generators/context/helpers/context-with-symbol-key.d.ts +5 -0
- package/dist/src/generators/context/helpers/context-with-symbol-key.js +33 -0
- package/dist/src/generators/context/qwik.d.ts +8 -0
- package/dist/src/generators/context/qwik.js +29 -0
- package/dist/src/generators/context/react.d.ts +10 -0
- package/dist/src/generators/context/react.js +30 -0
- package/dist/src/generators/context/rsc.d.ts +12 -0
- package/dist/src/generators/context/rsc.js +32 -0
- package/dist/src/generators/context/solid.d.ts +8 -0
- package/dist/src/generators/context/solid.js +30 -0
- package/dist/src/generators/context/svelte.d.ts +11 -0
- package/dist/src/generators/context/svelte.js +44 -0
- package/dist/src/generators/context/vue.d.ts +3 -0
- package/dist/src/generators/context/vue.js +5 -0
- package/dist/src/generators/helpers/context.d.ts +8 -0
- package/dist/src/generators/helpers/context.js +15 -0
- package/dist/src/generators/helpers/functions.d.ts +2 -0
- package/dist/src/generators/helpers/functions.js +31 -0
- package/dist/src/generators/helpers/minify.d.ts +1 -0
- package/dist/src/generators/helpers/minify.js +20 -0
- package/dist/src/generators/helpers/on-mount.d.ts +5 -0
- package/dist/src/generators/helpers/on-mount.js +25 -0
- package/dist/src/generators/helpers/rsc.d.ts +2 -0
- package/dist/src/generators/helpers/rsc.js +38 -0
- package/dist/src/generators/html/generator.d.ts +4 -0
- package/dist/src/generators/html/generator.js +1232 -0
- package/dist/src/generators/html/index.d.ts +2 -0
- package/dist/src/generators/html/index.js +18 -0
- package/dist/src/generators/html/types.d.ts +6 -0
- package/dist/src/generators/html/types.js +2 -0
- package/dist/src/generators/liquid/generator.d.ts +9 -0
- package/dist/src/generators/liquid/generator.js +161 -0
- package/dist/src/generators/liquid/index.d.ts +2 -0
- package/dist/src/generators/liquid/index.js +18 -0
- package/dist/src/generators/liquid/types.d.ts +5 -0
- package/dist/src/generators/liquid/types.js +2 -0
- package/dist/src/generators/lit/collect-class-string.d.ts +2 -0
- package/dist/src/generators/lit/collect-class-string.js +41 -0
- package/dist/src/generators/lit/generate.d.ts +3 -0
- package/dist/src/generators/lit/generate.js +271 -0
- package/dist/src/generators/lit/index.d.ts +2 -0
- package/dist/src/generators/lit/index.js +18 -0
- package/dist/src/generators/lit/types.d.ts +8 -0
- package/dist/src/generators/lit/types.js +2 -0
- package/dist/src/generators/marko/generate.d.ts +20 -0
- package/dist/src/generators/marko/generate.js +316 -0
- package/dist/src/generators/marko/index.d.ts +2 -0
- package/dist/src/generators/marko/index.js +18 -0
- package/dist/src/generators/marko/types.d.ts +4 -0
- package/dist/src/generators/marko/types.js +2 -0
- package/dist/src/generators/mitosis/generator.d.ts +7 -0
- package/dist/src/generators/mitosis/generator.js +367 -0
- package/dist/src/generators/mitosis/index.d.ts +2 -0
- package/dist/src/generators/mitosis/index.js +18 -0
- package/dist/src/generators/mitosis/types.d.ts +8 -0
- package/dist/src/generators/mitosis/types.js +2 -0
- package/dist/src/generators/qwik/component-generator.d.ts +3 -0
- package/dist/src/generators/qwik/component-generator.js +337 -0
- package/dist/src/generators/qwik/component.d.ts +21 -0
- package/dist/src/generators/qwik/component.js +170 -0
- package/dist/src/generators/qwik/directives.d.ts +24 -0
- package/dist/src/generators/qwik/directives.js +152 -0
- package/dist/src/generators/qwik/helpers/add-prevent-default.d.ts +7 -0
- package/dist/src/generators/qwik/helpers/add-prevent-default.js +33 -0
- package/dist/src/generators/qwik/helpers/convert-method-to-function.d.ts +2 -0
- package/dist/src/generators/qwik/helpers/convert-method-to-function.js +161 -0
- package/dist/src/generators/qwik/helpers/handlers.d.ts +3 -0
- package/dist/src/generators/qwik/helpers/handlers.js +60 -0
- package/dist/src/generators/qwik/helpers/stable-inject.d.ts +5 -0
- package/dist/src/generators/qwik/helpers/stable-inject.js +49 -0
- package/dist/src/generators/qwik/helpers/stable-serialize.d.ts +6 -0
- package/dist/src/generators/qwik/helpers/stable-serialize.js +50 -0
- package/dist/src/generators/qwik/helpers/state.d.ts +32 -0
- package/dist/src/generators/qwik/helpers/state.js +111 -0
- package/dist/src/generators/qwik/helpers/styles.d.ts +7 -0
- package/dist/src/generators/qwik/helpers/styles.js +70 -0
- package/dist/src/generators/qwik/index.d.ts +5 -0
- package/dist/src/generators/qwik/index.js +26 -0
- package/dist/src/generators/qwik/jsx.d.ts +17 -0
- package/dist/src/generators/qwik/jsx.js +223 -0
- package/dist/src/generators/qwik/src-generator.d.ts +83 -0
- package/dist/src/generators/qwik/src-generator.js +575 -0
- package/dist/src/generators/qwik/types.d.ts +14 -0
- package/dist/src/generators/qwik/types.js +2 -0
- package/dist/src/generators/react/blocks.d.ts +4 -0
- package/dist/src/generators/react/blocks.js +332 -0
- package/dist/src/generators/react/generator.d.ts +5 -0
- package/dist/src/generators/react/generator.js +399 -0
- package/dist/src/generators/react/helpers/default-props.d.ts +2 -0
- package/dist/src/generators/react/helpers/default-props.js +21 -0
- package/dist/src/generators/react/helpers/hooks.d.ts +20 -0
- package/dist/src/generators/react/helpers/hooks.js +67 -0
- package/dist/src/generators/react/helpers/index.d.ts +11 -0
- package/dist/src/generators/react/helpers/index.js +97 -0
- package/dist/src/generators/react/helpers/state.d.ts +17 -0
- package/dist/src/generators/react/helpers/state.js +198 -0
- package/dist/src/generators/react/index.d.ts +3 -0
- package/dist/src/generators/react/index.js +21 -0
- package/dist/src/generators/react/types.d.ts +22 -0
- package/dist/src/generators/react/types.js +2 -0
- package/dist/src/generators/react-native/extract-css-var-default-value.d.ts +1 -0
- package/dist/src/generators/react-native/extract-css-var-default-value.js +15 -0
- package/dist/src/generators/react-native/helpers.d.ts +3 -0
- package/dist/src/generators/react-native/helpers.js +133 -0
- package/dist/src/generators/react-native/index.d.ts +8 -0
- package/dist/src/generators/react-native/index.js +286 -0
- package/dist/src/generators/react-native/sanitize-react-native-block-styles.d.ts +4 -0
- package/dist/src/generators/react-native/sanitize-react-native-block-styles.js +57 -0
- package/dist/src/generators/react-native/types.d.ts +9 -0
- package/dist/src/generators/react-native/types.js +2 -0
- package/dist/src/generators/rsc/generator.d.ts +3 -0
- package/dist/src/generators/rsc/generator.js +77 -0
- package/dist/src/generators/rsc/index.d.ts +2 -0
- package/dist/src/generators/rsc/index.js +18 -0
- package/dist/src/generators/rsc/types.d.ts +5 -0
- package/dist/src/generators/rsc/types.js +2 -0
- package/dist/src/generators/solid/blocks.d.ts +4 -0
- package/dist/src/generators/solid/blocks.js +138 -0
- package/dist/src/generators/solid/helpers/styles.d.ts +3 -0
- package/dist/src/generators/solid/helpers/styles.js +47 -0
- package/dist/src/generators/solid/index.d.ts +4 -0
- package/dist/src/generators/solid/index.js +264 -0
- package/dist/src/generators/solid/state/helpers.d.ts +13 -0
- package/dist/src/generators/solid/state/helpers.js +88 -0
- package/dist/src/generators/solid/state/index.d.ts +1 -0
- package/dist/src/generators/solid/state/index.js +5 -0
- package/dist/src/generators/solid/state/signals.d.ts +7 -0
- package/dist/src/generators/solid/state/signals.js +53 -0
- package/dist/src/generators/solid/state/state.d.ts +14 -0
- package/dist/src/generators/solid/state/state.js +55 -0
- package/dist/src/generators/solid/state/store.d.ts +7 -0
- package/dist/src/generators/solid/state/store.js +76 -0
- package/dist/src/generators/solid/types.d.ts +10 -0
- package/dist/src/generators/solid/types.js +2 -0
- package/dist/src/generators/stencil/blocks.d.ts +9 -0
- package/dist/src/generators/stencil/blocks.js +122 -0
- package/dist/src/generators/stencil/component.d.ts +3 -0
- package/dist/src/generators/stencil/component.js +199 -0
- package/dist/src/generators/stencil/helpers/collect-class-string.d.ts +2 -0
- package/dist/src/generators/stencil/helpers/collect-class-string.js +43 -0
- package/dist/src/generators/stencil/helpers/index.d.ts +37 -0
- package/dist/src/generators/stencil/helpers/index.js +129 -0
- package/dist/src/generators/stencil/index.d.ts +2 -0
- package/dist/src/generators/stencil/index.js +18 -0
- package/dist/src/generators/stencil/plugins/get-code-processor-plugins.d.ts +4 -0
- package/dist/src/generators/stencil/plugins/get-code-processor-plugins.js +25 -0
- package/dist/src/generators/stencil/types.d.ts +37 -0
- package/dist/src/generators/stencil/types.js +2 -0
- package/dist/src/generators/svelte/blocks.d.ts +10 -0
- package/dist/src/generators/svelte/blocks.js +280 -0
- package/dist/src/generators/svelte/helpers.d.ts +6 -0
- package/dist/src/generators/svelte/helpers.js +14 -0
- package/dist/src/generators/svelte/index.d.ts +2 -0
- package/dist/src/generators/svelte/index.js +20 -0
- package/dist/src/generators/svelte/svelte.d.ts +3 -0
- package/dist/src/generators/svelte/svelte.js +412 -0
- package/dist/src/generators/svelte/types.d.ts +5 -0
- package/dist/src/generators/svelte/types.js +2 -0
- package/dist/src/generators/swift/blocks.d.ts +8 -0
- package/dist/src/generators/swift/blocks.js +304 -0
- package/dist/src/generators/swift/generator.d.ts +3 -0
- package/dist/src/generators/swift/generator.js +287 -0
- package/dist/src/generators/swift/helpers.d.ts +42 -0
- package/dist/src/generators/swift/helpers.js +412 -0
- package/dist/src/generators/swift/index.d.ts +2 -0
- package/dist/src/generators/swift/index.js +18 -0
- package/dist/src/generators/swift/types.d.ts +29 -0
- package/dist/src/generators/swift/types.js +2 -0
- package/dist/src/generators/taro/generator.d.ts +8 -0
- package/dist/src/generators/taro/generator.js +168 -0
- package/dist/src/generators/taro/index.d.ts +2 -0
- package/dist/src/generators/taro/index.js +18 -0
- package/dist/src/generators/taro/types.d.ts +3 -0
- package/dist/src/generators/taro/types.js +2 -0
- package/dist/src/generators/template/generator.d.ts +3 -0
- package/dist/src/generators/template/generator.js +131 -0
- package/dist/src/generators/template/index.d.ts +2 -0
- package/dist/src/generators/template/index.js +18 -0
- package/dist/src/generators/template/types.d.ts +4 -0
- package/dist/src/generators/template/types.js +2 -0
- package/dist/src/generators/vue/blocks.d.ts +8 -0
- package/dist/src/generators/vue/blocks.js +217 -0
- package/dist/src/generators/vue/compositionApi.d.ts +3 -0
- package/dist/src/generators/vue/compositionApi.js +128 -0
- package/dist/src/generators/vue/helpers.d.ts +25 -0
- package/dist/src/generators/vue/helpers.js +179 -0
- package/dist/src/generators/vue/index.d.ts +2 -0
- package/dist/src/generators/vue/index.js +18 -0
- package/dist/src/generators/vue/optionsApi.d.ts +3 -0
- package/dist/src/generators/vue/optionsApi.js +210 -0
- package/dist/src/generators/vue/types.d.ts +33 -0
- package/dist/src/generators/vue/types.js +2 -0
- package/dist/src/generators/vue/vue.d.ts +3 -0
- package/dist/src/generators/vue/vue.js +272 -0
- package/dist/src/helpers/apply-meta-tagname.d.ts +2 -0
- package/dist/src/helpers/apply-meta-tagname.js +20 -0
- package/dist/src/helpers/babel-transform.d.ts +7 -0
- package/dist/src/helpers/babel-transform.js +130 -0
- package/dist/src/helpers/bindings.d.ts +6 -0
- package/dist/src/helpers/bindings.js +9 -0
- package/dist/src/helpers/camel-case.d.ts +8 -0
- package/dist/src/helpers/camel-case.js +17 -0
- package/dist/src/helpers/capitalize.d.ts +1 -0
- package/dist/src/helpers/capitalize.js +10 -0
- package/dist/src/helpers/class-components.d.ts +13 -0
- package/dist/src/helpers/class-components.js +51 -0
- package/dist/src/helpers/component-file-extensions.d.ts +50 -0
- package/dist/src/helpers/component-file-extensions.js +141 -0
- package/dist/src/helpers/create-mitosis-component.d.ts +7 -0
- package/dist/src/helpers/create-mitosis-component.js +27 -0
- package/dist/src/helpers/create-mitosis-context.d.ts +4 -0
- package/dist/src/helpers/create-mitosis-context.js +11 -0
- package/dist/src/helpers/create-mitosis-node.d.ts +2 -0
- package/dist/src/helpers/create-mitosis-node.js +14 -0
- package/dist/src/helpers/dash-case.d.ts +1 -0
- package/dist/src/helpers/dash-case.js +6 -0
- package/dist/src/helpers/dedent.d.ts +1 -0
- package/dist/src/helpers/dedent.js +83 -0
- package/dist/src/helpers/event-handlers.d.ts +3 -0
- package/dist/src/helpers/event-handlers.js +115 -0
- package/dist/src/helpers/fast-clone.d.ts +1 -0
- package/dist/src/helpers/fast-clone.js +5 -0
- package/dist/src/helpers/filter-empty-text-nodes.d.ts +3 -0
- package/dist/src/helpers/filter-empty-text-nodes.js +9 -0
- package/dist/src/helpers/generic-format.d.ts +6 -0
- package/dist/src/helpers/generic-format.js +35 -0
- package/dist/src/helpers/get-bindings.d.ts +2 -0
- package/dist/src/helpers/get-bindings.js +16 -0
- package/dist/src/helpers/get-child-components.d.ts +2 -0
- package/dist/src/helpers/get-child-components.js +26 -0
- package/dist/src/helpers/get-components-used.d.ts +2 -0
- package/dist/src/helpers/get-components-used.js +18 -0
- package/dist/src/helpers/get-components.d.ts +2 -0
- package/dist/src/helpers/get-components.js +21 -0
- package/dist/src/helpers/get-custom-imports.d.ts +15 -0
- package/dist/src/helpers/get-custom-imports.js +38 -0
- package/dist/src/helpers/get-function-string.d.ts +1 -0
- package/dist/src/helpers/get-function-string.js +5 -0
- package/dist/src/helpers/get-prop-functions.d.ts +5 -0
- package/dist/src/helpers/get-prop-functions.js +28 -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-props.d.ts +5 -0
- package/dist/src/helpers/get-props.js +41 -0
- package/dist/src/helpers/get-refs.d.ts +2 -0
- package/dist/src/helpers/get-refs.js +21 -0
- package/dist/src/helpers/get-state-object-string.d.ts +20 -0
- package/dist/src/helpers/get-state-object-string.js +86 -0
- package/dist/src/helpers/get-state-used.d.ts +5 -0
- package/dist/src/helpers/get-state-used.js +28 -0
- package/dist/src/helpers/get-styles.d.ts +4 -0
- package/dist/src/helpers/get-styles.js +34 -0
- package/dist/src/helpers/get-tag-name.d.ts +2 -0
- package/dist/src/helpers/get-tag-name.js +7 -0
- package/dist/src/helpers/get-typed-function.d.ts +4 -0
- package/dist/src/helpers/get-typed-function.js +20 -0
- package/dist/src/helpers/getters-to-functions.d.ts +5 -0
- package/dist/src/helpers/getters-to-functions.js +36 -0
- package/dist/src/helpers/handle-missing-state.d.ts +2 -0
- package/dist/src/helpers/handle-missing-state.js +13 -0
- 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-component.d.ts +2 -0
- package/dist/src/helpers/has-component.js +21 -0
- package/dist/src/helpers/has-props.d.ts +2 -0
- package/dist/src/helpers/has-props.js +19 -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/html-escape.d.ts +1 -0
- package/dist/src/helpers/html-escape.js +7 -0
- package/dist/src/helpers/indent.d.ts +1 -0
- package/dist/src/helpers/indent.js +7 -0
- package/dist/src/helpers/is-children.d.ts +6 -0
- package/dist/src/helpers/is-children.js +14 -0
- package/dist/src/helpers/is-component.d.ts +5 -0
- package/dist/src/helpers/is-component.js +8 -0
- package/dist/src/helpers/is-hook-empty.d.ts +2 -0
- package/dist/src/helpers/is-hook-empty.js +14 -0
- package/dist/src/helpers/is-html-attribute.d.ts +4 -0
- package/dist/src/helpers/is-html-attribute.js +371 -0
- package/dist/src/helpers/is-mitosis-node.d.ts +2 -0
- package/dist/src/helpers/is-mitosis-node.js +7 -0
- package/dist/src/helpers/is-root-text-node.d.ts +4 -0
- package/dist/src/helpers/is-root-text-node.js +12 -0
- package/dist/src/helpers/is-upper-case.d.ts +1 -0
- package/dist/src/helpers/is-upper-case.js +5 -0
- package/dist/src/helpers/is-valid-attribute-name.d.ts +1 -0
- package/dist/src/helpers/is-valid-attribute-name.js +7 -0
- package/dist/src/helpers/json.d.ts +3 -0
- package/dist/src/helpers/json.js +17 -0
- package/dist/src/helpers/map-refs.d.ts +9 -0
- package/dist/src/helpers/map-refs.js +91 -0
- package/dist/src/helpers/merge-options.d.ts +19 -0
- package/dist/src/helpers/merge-options.js +35 -0
- package/dist/src/helpers/mitosis-imports.d.ts +5 -0
- package/dist/src/helpers/mitosis-imports.js +48 -0
- package/dist/src/helpers/nodes/for.d.ts +4 -0
- package/dist/src/helpers/nodes/for.js +12 -0
- package/dist/src/helpers/nullable.d.ts +2 -0
- package/dist/src/helpers/nullable.js +5 -0
- package/dist/src/helpers/on-event.d.ts +14 -0
- package/dist/src/helpers/on-event.js +52 -0
- package/dist/src/helpers/output.d.ts +5 -0
- package/dist/src/helpers/output.js +10 -0
- package/dist/src/helpers/parse-node.d.ts +2 -0
- package/dist/src/helpers/parse-node.js +20 -0
- package/dist/src/helpers/parsers.d.ts +9 -0
- package/dist/src/helpers/parsers.js +66 -0
- package/dist/src/helpers/patterns.d.ts +8 -0
- package/dist/src/helpers/patterns.js +17 -0
- package/dist/src/helpers/plugins/process-code/index.d.ts +12 -0
- package/dist/src/helpers/plugins/process-code/index.js +169 -0
- package/dist/src/helpers/plugins/process-code/types.d.ts +7 -0
- package/dist/src/helpers/plugins/process-code/types.js +2 -0
- package/dist/src/helpers/plugins/process-signals.d.ts +22 -0
- package/dist/src/helpers/plugins/process-signals.js +179 -0
- package/dist/src/helpers/plugins/process-target-blocks.d.ts +6 -0
- package/dist/src/helpers/plugins/process-target-blocks.js +59 -0
- package/dist/src/helpers/process-http-requests.d.ts +2 -0
- package/dist/src/helpers/process-http-requests.js +25 -0
- package/dist/src/helpers/remove-surrounding-block.d.ts +6 -0
- package/dist/src/helpers/remove-surrounding-block.js +25 -0
- package/dist/src/helpers/render-imports.d.ts +42 -0
- package/dist/src/helpers/render-imports.js +169 -0
- package/dist/src/helpers/replace-identifiers.d.ts +27 -0
- package/dist/src/helpers/replace-identifiers.js +187 -0
- package/dist/src/helpers/replace-new-lines-in-strings.d.ts +1 -0
- package/dist/src/helpers/replace-new-lines-in-strings.js +26 -0
- package/dist/src/helpers/set.d.ts +7 -0
- package/dist/src/helpers/set.js +24 -0
- package/dist/src/helpers/signals/index.d.ts +1 -0
- package/dist/src/helpers/signals/index.js +17 -0
- package/dist/src/helpers/signals/signals.d.ts +22 -0
- package/dist/src/helpers/signals/signals.js +109 -0
- package/dist/src/helpers/slots.d.ts +5 -0
- package/dist/src/helpers/slots.js +26 -0
- package/dist/src/helpers/state.d.ts +2 -0
- package/dist/src/helpers/state.js +5 -0
- package/dist/src/helpers/strip-meta-properties.d.ts +2 -0
- package/dist/src/helpers/strip-meta-properties.js +26 -0
- package/dist/src/helpers/strip-state-and-props-refs.d.ts +38 -0
- package/dist/src/helpers/strip-state-and-props-refs.js +86 -0
- package/dist/src/helpers/styles/collect-css.d.ts +7 -0
- package/dist/src/helpers/styles/collect-css.js +113 -0
- package/dist/src/helpers/styles/collect-styled-components.d.ts +2 -0
- package/dist/src/helpers/styles/collect-styled-components.js +64 -0
- package/dist/src/helpers/styles/helpers.d.ts +31 -0
- package/dist/src/helpers/styles/helpers.js +90 -0
- package/dist/src/helpers/trace-reference-to-module-path.d.ts +2 -0
- package/dist/src/helpers/trace-reference-to-module-path.js +13 -0
- package/dist/src/helpers/transform-state-setters.d.ts +14 -0
- package/dist/src/helpers/transform-state-setters.js +24 -0
- package/dist/src/helpers/transform-to-jsx.d.ts +4 -0
- package/dist/src/helpers/transform-to-jsx.js +13 -0
- package/dist/src/helpers/traverse-nodes.d.ts +4 -0
- package/dist/src/helpers/traverse-nodes.js +16 -0
- package/dist/src/helpers/try-prettier-format.d.ts +1 -0
- package/dist/src/helpers/try-prettier-format.js +24 -0
- package/dist/src/helpers/typescript-project.d.ts +7 -0
- package/dist/src/helpers/typescript-project.js +63 -0
- package/dist/src/helpers/typescript.d.ts +9 -0
- package/dist/src/helpers/typescript.js +5 -0
- package/dist/src/helpers/web-components/attribute-passing.d.ts +6 -0
- package/dist/src/helpers/web-components/attribute-passing.js +47 -0
- package/dist/src/index.d.ts +96 -0
- package/dist/src/index.js +74 -0
- package/dist/src/modules/plugins.d.ts +25 -0
- package/dist/src/modules/plugins.js +51 -0
- package/dist/src/parsers/angular.d.ts +5 -0
- package/dist/src/parsers/angular.js +154 -0
- package/dist/src/parsers/builder/builder.d.ts +55 -0
- package/dist/src/parsers/builder/builder.js +1198 -0
- package/dist/src/parsers/builder/helpers.d.ts +3 -0
- package/dist/src/parsers/builder/helpers.js +26 -0
- package/dist/src/parsers/builder/index.d.ts +1 -0
- package/dist/src/parsers/builder/index.js +17 -0
- package/dist/src/parsers/context.d.ts +6 -0
- package/dist/src/parsers/context.js +82 -0
- package/dist/src/parsers/jsx/ast.d.ts +5 -0
- package/dist/src/parsers/jsx/ast.js +74 -0
- package/dist/src/parsers/jsx/component-types.d.ts +8 -0
- package/dist/src/parsers/jsx/component-types.js +82 -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/element-parser.d.ts +9 -0
- package/dist/src/parsers/jsx/element-parser.js +418 -0
- package/dist/src/parsers/jsx/exports.d.ts +5 -0
- package/dist/src/parsers/jsx/exports.js +76 -0
- package/dist/src/parsers/jsx/function-parser.d.ts +9 -0
- package/dist/src/parsers/jsx/function-parser.js +360 -0
- package/dist/src/parsers/jsx/helpers.d.ts +17 -0
- package/dist/src/parsers/jsx/helpers.js +85 -0
- package/dist/src/parsers/jsx/hooks/helpers.d.ts +5 -0
- package/dist/src/parsers/jsx/hooks/helpers.js +54 -0
- package/dist/src/parsers/jsx/hooks/index.d.ts +16 -0
- package/dist/src/parsers/jsx/hooks/index.js +96 -0
- package/dist/src/parsers/jsx/hooks/use-metadata.d.ts +9 -0
- package/dist/src/parsers/jsx/hooks/use-metadata.js +184 -0
- package/dist/src/parsers/jsx/hooks/use-target.d.ts +13 -0
- package/dist/src/parsers/jsx/hooks/use-target.js +135 -0
- package/dist/src/parsers/jsx/imports.d.ts +7 -0
- package/dist/src/parsers/jsx/imports.js +23 -0
- package/dist/src/parsers/jsx/index.d.ts +2 -0
- package/dist/src/parsers/jsx/index.js +5 -0
- package/dist/src/parsers/jsx/jsx.d.ts +10 -0
- package/dist/src/parsers/jsx/jsx.js +227 -0
- package/dist/src/parsers/jsx/props-types.d.ts +5 -0
- package/dist/src/parsers/jsx/props-types.js +22 -0
- package/dist/src/parsers/jsx/props.d.ts +2 -0
- package/dist/src/parsers/jsx/props.js +64 -0
- package/dist/src/parsers/jsx/signals.d.ts +9 -0
- package/dist/src/parsers/jsx/signals.js +99 -0
- package/dist/src/parsers/jsx/state.d.ts +17 -0
- package/dist/src/parsers/jsx/state.js +274 -0
- package/dist/src/parsers/jsx/types.d.ts +29 -0
- package/dist/src/parsers/jsx/types.js +2 -0
- package/dist/src/parsers/svelte/css/index.d.ts +3 -0
- package/dist/src/parsers/svelte/css/index.js +8 -0
- package/dist/src/parsers/svelte/helpers/bindings.d.ts +3 -0
- package/dist/src/parsers/svelte/helpers/bindings.js +75 -0
- package/dist/src/parsers/svelte/helpers/children.d.ts +5 -0
- package/dist/src/parsers/svelte/helpers/children.js +22 -0
- package/dist/src/parsers/svelte/helpers/expressions.d.ts +3 -0
- package/dist/src/parsers/svelte/helpers/expressions.js +20 -0
- package/dist/src/parsers/svelte/helpers/hooks.d.ts +2 -0
- package/dist/src/parsers/svelte/helpers/hooks.js +15 -0
- package/dist/src/parsers/svelte/helpers/mitosis-node.d.ts +2 -0
- package/dist/src/parsers/svelte/helpers/mitosis-node.js +16 -0
- package/dist/src/parsers/svelte/helpers/post-process.d.ts +15 -0
- package/dist/src/parsers/svelte/helpers/post-process.js +174 -0
- package/dist/src/parsers/svelte/helpers/string.d.ts +3 -0
- package/dist/src/parsers/svelte/helpers/string.js +26 -0
- package/dist/src/parsers/svelte/html/actions.d.ts +3 -0
- package/dist/src/parsers/svelte/html/actions.js +46 -0
- package/dist/src/parsers/svelte/html/each.d.ts +4 -0
- package/dist/src/parsers/svelte/html/each.js +20 -0
- package/dist/src/parsers/svelte/html/element.d.ts +3 -0
- package/dist/src/parsers/svelte/html/element.js +224 -0
- package/dist/src/parsers/svelte/html/fragment.d.ts +3 -0
- package/dist/src/parsers/svelte/html/fragment.js +16 -0
- package/dist/src/parsers/svelte/html/if-else.d.ts +3 -0
- package/dist/src/parsers/svelte/html/if-else.js +31 -0
- package/dist/src/parsers/svelte/html/index.d.ts +5 -0
- package/dist/src/parsers/svelte/html/index.js +80 -0
- package/dist/src/parsers/svelte/html/mustache-tag.d.ts +3 -0
- package/dist/src/parsers/svelte/html/mustache-tag.js +24 -0
- package/dist/src/parsers/svelte/html/slot.d.ts +3 -0
- package/dist/src/parsers/svelte/html/slot.js +20 -0
- package/dist/src/parsers/svelte/html/text.d.ts +66 -0
- package/dist/src/parsers/svelte/html/text.js +14 -0
- package/dist/src/parsers/svelte/index.d.ts +2 -0
- package/dist/src/parsers/svelte/index.js +59 -0
- package/dist/src/parsers/svelte/instance/context.d.ts +5 -0
- package/dist/src/parsers/svelte/instance/context.js +59 -0
- package/dist/src/parsers/svelte/instance/expressions.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/expressions.js +11 -0
- package/dist/src/parsers/svelte/instance/functions.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/functions.js +66 -0
- package/dist/src/parsers/svelte/instance/hooks.d.ts +5 -0
- package/dist/src/parsers/svelte/instance/hooks.js +32 -0
- package/dist/src/parsers/svelte/instance/imports.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/imports.js +32 -0
- package/dist/src/parsers/svelte/instance/index.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/index.js +123 -0
- package/dist/src/parsers/svelte/instance/properties.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/properties.js +22 -0
- package/dist/src/parsers/svelte/instance/reactive.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/reactive.js +33 -0
- package/dist/src/parsers/svelte/instance/references.d.ts +4 -0
- package/dist/src/parsers/svelte/instance/references.js +68 -0
- package/dist/src/parsers/svelte/instance/statements.d.ts +3 -0
- package/dist/src/parsers/svelte/instance/statements.js +10 -0
- package/dist/src/parsers/svelte/module/index.d.ts +3 -0
- package/dist/src/parsers/svelte/module/index.js +34 -0
- package/dist/src/parsers/svelte/types/index.d.ts +4 -0
- package/dist/src/parsers/svelte/types/index.js +2 -0
- package/dist/src/parsers/svelte/typescript/index.d.ts +7 -0
- package/dist/src/parsers/svelte/typescript/index.js +121 -0
- package/dist/src/plugins/compile-away-builder-components.d.ts +15 -0
- package/dist/src/plugins/compile-away-builder-components.js +609 -0
- package/dist/src/plugins/compile-away-components.d.ts +33 -0
- package/dist/src/plugins/compile-away-components.js +50 -0
- package/dist/src/plugins/map-styles.d.ts +12 -0
- package/dist/src/plugins/map-styles.js +16 -0
- package/dist/src/symbols/symbol-processor.d.ts +20 -0
- package/dist/src/symbols/symbol-processor.js +202 -0
- package/dist/src/targets.d.ts +25 -0
- package/dist/src/targets.js +46 -0
- package/dist/src/types/config.d.ts +103 -0
- package/dist/src/types/config.js +2 -0
- package/dist/src/types/json.d.ts +13 -0
- package/dist/src/types/json.js +2 -0
- package/dist/src/types/metadata.d.ts +55 -0
- package/dist/src/types/metadata.js +2 -0
- package/dist/src/types/mitosis-component.d.ts +162 -0
- package/dist/src/types/mitosis-component.js +2 -0
- package/dist/src/types/mitosis-context.d.ts +6 -0
- package/dist/src/types/mitosis-context.js +2 -0
- package/dist/src/types/mitosis-node.d.ts +117 -0
- package/dist/src/types/mitosis-node.js +12 -0
- package/dist/src/types/mitosis-styles.d.ts +1 -0
- package/dist/src/types/mitosis-styles.js +2 -0
- package/dist/src/types/plugins.d.ts +19 -0
- package/dist/src/types/plugins.js +2 -0
- package/dist/src/types/transpiler.d.ts +48 -0
- package/dist/src/types/transpiler.js +2 -0
- package/jsx-runtime.d.ts +2143 -0
- package/package.json +106 -0
|
@@ -0,0 +1,1232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.componentToCustomElement = exports.componentToHtml = void 0;
|
|
7
|
+
const html_tags_1 = require("../../constants/html_tags");
|
|
8
|
+
const babel_transform_1 = require("../../helpers/babel-transform");
|
|
9
|
+
const dash_case_1 = require("../../helpers/dash-case");
|
|
10
|
+
const event_handlers_1 = require("../../helpers/event-handlers");
|
|
11
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
12
|
+
const get_prop_functions_1 = require("../../helpers/get-prop-functions");
|
|
13
|
+
const get_props_1 = require("../../helpers/get-props");
|
|
14
|
+
const get_props_ref_1 = require("../../helpers/get-props-ref");
|
|
15
|
+
const get_refs_1 = require("../../helpers/get-refs");
|
|
16
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
17
|
+
const has_bindings_text_1 = require("../../helpers/has-bindings-text");
|
|
18
|
+
const has_component_1 = require("../../helpers/has-component");
|
|
19
|
+
const has_props_1 = require("../../helpers/has-props");
|
|
20
|
+
const has_stateful_dom_1 = require("../../helpers/has-stateful-dom");
|
|
21
|
+
const is_html_attribute_1 = require("../../helpers/is-html-attribute");
|
|
22
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
23
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
24
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
25
|
+
const for_1 = require("../../helpers/nodes/for");
|
|
26
|
+
const remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
|
|
27
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
28
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
29
|
+
const strip_state_and_props_refs_1 = require("../../helpers/strip-state-and-props-refs");
|
|
30
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
31
|
+
const plugins_1 = require("../../modules/plugins");
|
|
32
|
+
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
33
|
+
const core_1 = require("@babel/core");
|
|
34
|
+
const function_1 = require("fp-ts/lib/function");
|
|
35
|
+
const lodash_1 = require("lodash");
|
|
36
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
37
|
+
const is_children_1 = __importDefault(require("../../helpers/is-children"));
|
|
38
|
+
const standalone_1 = require("prettier/standalone");
|
|
39
|
+
const on_mount_1 = require("../helpers/on-mount");
|
|
40
|
+
const isAttribute = (key) => {
|
|
41
|
+
return /-/.test(key);
|
|
42
|
+
};
|
|
43
|
+
const ATTRIBUTE_KEY_EXCEPTIONS_MAP = {
|
|
44
|
+
class: 'className',
|
|
45
|
+
innerHtml: 'innerHTML',
|
|
46
|
+
};
|
|
47
|
+
const updateKeyIfException = (key) => {
|
|
48
|
+
var _a;
|
|
49
|
+
return (_a = ATTRIBUTE_KEY_EXCEPTIONS_MAP[key]) !== null && _a !== void 0 ? _a : key;
|
|
50
|
+
};
|
|
51
|
+
const generateSetElementAttributeCode = (key, tagName, useValue, options, meta = {}) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.props) {
|
|
54
|
+
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.props(key, useValue, options);
|
|
55
|
+
}
|
|
56
|
+
const isKey = key === 'key';
|
|
57
|
+
const ignoreKey = /^(innerHTML|key|class|value)$/.test(key);
|
|
58
|
+
const isTextarea = key === 'value' && tagName === 'textarea';
|
|
59
|
+
const isDataSet = /^data-/.test(key);
|
|
60
|
+
const isComponent = Boolean(meta === null || meta === void 0 ? void 0 : meta.component);
|
|
61
|
+
const isHtmlAttr = (0, is_html_attribute_1.isHtmlAttribute)(key, tagName);
|
|
62
|
+
const setAttr = !ignoreKey && (isHtmlAttr || !isTextarea || isAttribute(key));
|
|
63
|
+
return [
|
|
64
|
+
// is html attribute or dash-case
|
|
65
|
+
setAttr ? `;el.setAttribute("${key}", ${useValue});` : '',
|
|
66
|
+
// not attr or dataset or html attr
|
|
67
|
+
!setAttr || !(isHtmlAttr || isDataSet || !isComponent || isKey)
|
|
68
|
+
? `el.${updateKeyIfException((0, lodash_1.camelCase)(key))} = ${useValue};`
|
|
69
|
+
: '',
|
|
70
|
+
// is component but not html attribute
|
|
71
|
+
isComponent && !isHtmlAttr
|
|
72
|
+
? // custom-element is created but we're in the middle of the update loop
|
|
73
|
+
`
|
|
74
|
+
if (el.props) {
|
|
75
|
+
;el.props.${(0, lodash_1.camelCase)(key)} = ${useValue};
|
|
76
|
+
if (el.update) {
|
|
77
|
+
;el.update();
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
;el.props = {};
|
|
81
|
+
;el.props.${(0, lodash_1.camelCase)(key)} = ${useValue};
|
|
82
|
+
}
|
|
83
|
+
`
|
|
84
|
+
: '',
|
|
85
|
+
].join('\n');
|
|
86
|
+
};
|
|
87
|
+
const addUpdateAfterSet = (json, options) => {
|
|
88
|
+
(0, legacy_1.default)(json).forEach(function (item) {
|
|
89
|
+
var _a;
|
|
90
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
|
|
91
|
+
for (const key in item.bindings) {
|
|
92
|
+
const value = (_a = item.bindings[key]) === null || _a === void 0 ? void 0 : _a.code;
|
|
93
|
+
if (value) {
|
|
94
|
+
const newValue = addUpdateAfterSetInCode(value, options);
|
|
95
|
+
if (newValue !== value) {
|
|
96
|
+
item.bindings[key].code = newValue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const getChildComponents = (json, options) => {
|
|
104
|
+
const childComponents = [];
|
|
105
|
+
json.imports.forEach(({ imports }) => {
|
|
106
|
+
Object.keys(imports).forEach((key) => {
|
|
107
|
+
if (imports[key] === 'default') {
|
|
108
|
+
childComponents.push(key);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
return childComponents;
|
|
113
|
+
};
|
|
114
|
+
const getScopeVars = (parentScopeVars, value) => {
|
|
115
|
+
return parentScopeVars.filter((scopeVar) => {
|
|
116
|
+
if (typeof value === 'boolean') {
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
const checkVar = new RegExp('(\\.\\.\\.|,| |;|\\(|^|!)' + scopeVar + '(\\.|,| |;|\\)|$)', 'g');
|
|
120
|
+
return checkVar.test(value);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const addScopeVars = (parentScopeVars, value, fn) => {
|
|
124
|
+
return `${getScopeVars(parentScopeVars, value)
|
|
125
|
+
.map((scopeVar) => {
|
|
126
|
+
return fn(scopeVar);
|
|
127
|
+
})
|
|
128
|
+
.join('\n')}`;
|
|
129
|
+
};
|
|
130
|
+
const mappers = {
|
|
131
|
+
Fragment: (json, options, blockOptions) => {
|
|
132
|
+
return json.children.map((item) => blockToHtml(item, options, blockOptions)).join('\n');
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
const getId = (json, options) => {
|
|
136
|
+
const name = json.properties.$name
|
|
137
|
+
? (0, dash_case_1.dashCase)(json.properties.$name)
|
|
138
|
+
: /^h\d$/.test(json.name || '') // don't dashcase h1 into h-1
|
|
139
|
+
? json.name
|
|
140
|
+
: (0, dash_case_1.dashCase)(json.name || 'div');
|
|
141
|
+
const newNameNum = (options.namesMap[name] || 0) + 1;
|
|
142
|
+
options.namesMap[name] = newNameNum;
|
|
143
|
+
return `${name}${options.prefix ? `-${options.prefix}` : ''}${name !== json.name && newNameNum === 1 ? '' : `-${newNameNum}`}`;
|
|
144
|
+
};
|
|
145
|
+
const createGlobalId = (name, options) => {
|
|
146
|
+
const newNameNum = (options.namesMap[name] || 0) + 1;
|
|
147
|
+
options.namesMap[name] = newNameNum;
|
|
148
|
+
return `${name}${options.prefix ? `-${options.prefix}` : ''}-${newNameNum}`;
|
|
149
|
+
};
|
|
150
|
+
const deprecatedStripStateAndPropsRefs = (code, { context, contextVars, domRefs, includeProps, includeState, outputVars, replaceWith, stateVars, }) => {
|
|
151
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
152
|
+
includeProps,
|
|
153
|
+
includeState,
|
|
154
|
+
replaceWith,
|
|
155
|
+
}), (newCode) => (0, strip_state_and_props_refs_1.DO_NOT_USE_VARS_TRANSFORMS)(newCode, {
|
|
156
|
+
context,
|
|
157
|
+
contextVars,
|
|
158
|
+
domRefs,
|
|
159
|
+
outputVars,
|
|
160
|
+
stateVars,
|
|
161
|
+
}));
|
|
162
|
+
};
|
|
163
|
+
// TODO: overloaded function
|
|
164
|
+
const updateReferencesInCode = (code, options, blockOptions = {}) => {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
const contextVars = blockOptions.contextVars || [];
|
|
167
|
+
const context = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.context) || 'this.';
|
|
168
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.updateReferencesInCode) {
|
|
169
|
+
return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.updateReferencesInCode(code, options, {
|
|
170
|
+
stripStateAndPropsRefs: deprecatedStripStateAndPropsRefs,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (options.format === 'class') {
|
|
174
|
+
return (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
|
|
175
|
+
includeProps: false,
|
|
176
|
+
includeState: true,
|
|
177
|
+
replaceWith: context + 'state.',
|
|
178
|
+
}), (newCode) => (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, {
|
|
179
|
+
// TODO: replace with `this.` and add setters that call this.update()
|
|
180
|
+
includeProps: true,
|
|
181
|
+
includeState: false,
|
|
182
|
+
replaceWith: context + 'props.',
|
|
183
|
+
}), (newCode) => (0, strip_state_and_props_refs_1.DO_NOT_USE_CONTEXT_VARS_TRANSFORMS)({ code: newCode, context, contextVars }));
|
|
184
|
+
}
|
|
185
|
+
return code;
|
|
186
|
+
};
|
|
187
|
+
const addOnChangeJs = (id, options, code) => {
|
|
188
|
+
if (!options.onChangeJsById[id]) {
|
|
189
|
+
options.onChangeJsById[id] = '';
|
|
190
|
+
}
|
|
191
|
+
options.onChangeJsById[id] += code;
|
|
192
|
+
};
|
|
193
|
+
// TODO: spread support
|
|
194
|
+
const blockToHtml = (json, options, blockOptions = {}) => {
|
|
195
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
196
|
+
const ComponentName = blockOptions.ComponentName;
|
|
197
|
+
const scopeVars = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.scopeVars) || [];
|
|
198
|
+
const childComponents = (blockOptions === null || blockOptions === void 0 ? void 0 : blockOptions.childComponents) || [];
|
|
199
|
+
const hasData = Object.keys(json.bindings).length;
|
|
200
|
+
const hasDomState = /input|textarea|select/.test(json.name);
|
|
201
|
+
let elId = '';
|
|
202
|
+
if (hasData) {
|
|
203
|
+
elId = getId(json, options);
|
|
204
|
+
json.properties['data-el'] = elId;
|
|
205
|
+
}
|
|
206
|
+
if (hasDomState) {
|
|
207
|
+
json.properties['data-dom-state'] = createGlobalId((ComponentName ? ComponentName + '-' : '') + json.name, options);
|
|
208
|
+
}
|
|
209
|
+
if (mappers[json.name]) {
|
|
210
|
+
return mappers[json.name](json, options, blockOptions);
|
|
211
|
+
}
|
|
212
|
+
if ((0, is_children_1.default)({ node: json })) {
|
|
213
|
+
return `<slot></slot>`;
|
|
214
|
+
}
|
|
215
|
+
if (json.properties._text) {
|
|
216
|
+
return json.properties._text;
|
|
217
|
+
}
|
|
218
|
+
if ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code) {
|
|
219
|
+
// TO-DO: textContent might be better performance-wise
|
|
220
|
+
addOnChangeJs(elId, options, `
|
|
221
|
+
${addScopeVars(scopeVars, json.bindings._text.code, (scopeVar) => `const ${scopeVar} = ${options.format === 'class' ? 'this.' : ''}getScope(el, "${scopeVar}");`)}
|
|
222
|
+
${options.format === 'class' ? 'this.' : ''}renderTextNode(el, ${json.bindings._text.code});`);
|
|
223
|
+
return `<template data-el="${elId}"><!-- ${(_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code} --></template>`;
|
|
224
|
+
}
|
|
225
|
+
let str = '';
|
|
226
|
+
if ((0, mitosis_node_1.checkIsForNode)(json)) {
|
|
227
|
+
const forArguments = (0, for_1.getForArguments)(json);
|
|
228
|
+
const localScopeVars = [...scopeVars, ...forArguments];
|
|
229
|
+
const argsStr = forArguments.map((arg) => `"${arg}"`).join(',');
|
|
230
|
+
addOnChangeJs(elId, options,
|
|
231
|
+
// TODO: be smarter about rendering, deleting old items and adding new ones by
|
|
232
|
+
// querying dom potentially
|
|
233
|
+
`
|
|
234
|
+
let array = ${(_c = json.bindings.each) === null || _c === void 0 ? void 0 : _c.code};
|
|
235
|
+
${options.format === 'class' ? 'this.' : ''}renderLoop(el, array, ${argsStr});
|
|
236
|
+
`);
|
|
237
|
+
// TODO: decide on how to handle this...
|
|
238
|
+
str += `
|
|
239
|
+
<template data-el="${elId}">`;
|
|
240
|
+
if (json.children) {
|
|
241
|
+
str += json.children
|
|
242
|
+
.map((item) => blockToHtml(item, options, {
|
|
243
|
+
...blockOptions,
|
|
244
|
+
scopeVars: localScopeVars,
|
|
245
|
+
}))
|
|
246
|
+
.join('\n');
|
|
247
|
+
}
|
|
248
|
+
str += '</template>';
|
|
249
|
+
}
|
|
250
|
+
else if (json.name === 'Show') {
|
|
251
|
+
const whenCondition = ((_d = json.bindings.when) === null || _d === void 0 ? void 0 : _d.code).replace(/;$/, '');
|
|
252
|
+
addOnChangeJs(elId, options, `
|
|
253
|
+
${addScopeVars(scopeVars, whenCondition, (scopeVar) => `const ${scopeVar} = ${options.format === 'class' ? 'this.' : ''}getScope(el, "${scopeVar}");`)}
|
|
254
|
+
const whenCondition = ${whenCondition};
|
|
255
|
+
if (whenCondition) {
|
|
256
|
+
${options.format === 'class' ? 'this.' : ''}showContent(el)
|
|
257
|
+
}
|
|
258
|
+
`);
|
|
259
|
+
str += `<template data-el="${elId}">`;
|
|
260
|
+
if (json.children) {
|
|
261
|
+
str += json.children.map((item) => blockToHtml(item, options, blockOptions)).join('\n');
|
|
262
|
+
}
|
|
263
|
+
str += '</template>';
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const component = childComponents.find((impName) => impName === json.name);
|
|
267
|
+
const elSelector = component ? (0, lodash_1.kebabCase)(json.name) : json.name;
|
|
268
|
+
str += `<${elSelector} `;
|
|
269
|
+
// For now, spread is not supported
|
|
270
|
+
// if (json.bindings._spread === '_spread') {
|
|
271
|
+
// str += `
|
|
272
|
+
// {% for _attr in ${json.bindings._spread} %}
|
|
273
|
+
// {{ _attr[0] }}="{{ _attr[1] }}"
|
|
274
|
+
// {% endfor %}
|
|
275
|
+
// `;
|
|
276
|
+
// }
|
|
277
|
+
for (const key in json.properties) {
|
|
278
|
+
if (key === 'innerHTML') {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (key.startsWith('$')) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const value = (json.properties[key] || '').replace(/"/g, '"').replace(/\n/g, '\\n');
|
|
285
|
+
str += ` ${key}="${value}" `;
|
|
286
|
+
}
|
|
287
|
+
// batch all local vars within the bindings
|
|
288
|
+
let batchScopeVars = {};
|
|
289
|
+
let injectOnce = false;
|
|
290
|
+
let startInjectVar = '%%START_VARS%%';
|
|
291
|
+
for (const key in json.bindings) {
|
|
292
|
+
if (((_e = json.bindings[key]) === null || _e === void 0 ? void 0 : _e.type) === 'spread' || key === 'css') {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const value = (_f = json.bindings[key]) === null || _f === void 0 ? void 0 : _f.code;
|
|
296
|
+
const cusArg = ((_g = json.bindings[key]) === null || _g === void 0 ? void 0 : _g.arguments) || ['event'];
|
|
297
|
+
// TODO: proper babel transform to replace. Util for this
|
|
298
|
+
const useValue = value;
|
|
299
|
+
if ((0, event_handlers_1.checkIsEvent)(key)) {
|
|
300
|
+
let event = key.replace('on', '').toLowerCase();
|
|
301
|
+
const fnName = (0, lodash_1.camelCase)(`on-${elId}-${event}`);
|
|
302
|
+
const codeContent = (0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options, blockOptions));
|
|
303
|
+
const asyncKeyword = ((_h = json.bindings[key]) === null || _h === void 0 ? void 0 : _h.async) ? 'async ' : '';
|
|
304
|
+
options.js += `
|
|
305
|
+
// Event handler for '${event}' event on ${elId}
|
|
306
|
+
${options.format === 'class'
|
|
307
|
+
? `this.${fnName} = ${asyncKeyword}(${cusArg.join(',')}) => {`
|
|
308
|
+
: `${asyncKeyword}function ${fnName} (${cusArg.join(',')}) {`}
|
|
309
|
+
${addScopeVars(scopeVars, codeContent, (scopeVar) => `const ${scopeVar} = ${options.format === 'class' ? 'this.' : ''}getScope(event.currentTarget, "${scopeVar}");`)}
|
|
310
|
+
${codeContent}
|
|
311
|
+
}
|
|
312
|
+
`;
|
|
313
|
+
const fnIdentifier = `${options.format === 'class' ? 'this.' : ''}${fnName}`;
|
|
314
|
+
addOnChangeJs(elId, options, `
|
|
315
|
+
;el.removeEventListener('${event}', ${fnIdentifier});
|
|
316
|
+
;el.addEventListener('${event}', ${fnIdentifier});
|
|
317
|
+
`);
|
|
318
|
+
}
|
|
319
|
+
else if (key === 'ref') {
|
|
320
|
+
str += ` data-ref="${ComponentName}-${useValue}" `;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
if (key === 'style') {
|
|
324
|
+
addOnChangeJs(elId, options, `
|
|
325
|
+
${addScopeVars(scopeVars, useValue, (scopeVar) => `const ${scopeVar} = ${options.format === 'class' ? 'this.' : ''}getScope(el, "${scopeVar}");`)}
|
|
326
|
+
;Object.assign(el.style, ${useValue});`);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
// gather all local vars to inject later
|
|
330
|
+
getScopeVars(scopeVars, useValue).forEach((key) => {
|
|
331
|
+
// unique keys
|
|
332
|
+
batchScopeVars[key] = true;
|
|
333
|
+
});
|
|
334
|
+
addOnChangeJs(elId, options, `
|
|
335
|
+
${injectOnce ? '' : startInjectVar}
|
|
336
|
+
${generateSetElementAttributeCode(key, elSelector, useValue, options, {
|
|
337
|
+
component,
|
|
338
|
+
})}
|
|
339
|
+
`);
|
|
340
|
+
if (!injectOnce) {
|
|
341
|
+
injectOnce = true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// batch inject local vars in the beginning of the function block
|
|
347
|
+
const codeBlock = options.onChangeJsById[elId];
|
|
348
|
+
const testInjectVar = new RegExp(startInjectVar);
|
|
349
|
+
if (codeBlock && testInjectVar.test(codeBlock)) {
|
|
350
|
+
const localScopeVars = Object.keys(batchScopeVars);
|
|
351
|
+
options.onChangeJsById[elId] = codeBlock.replace(startInjectVar, `
|
|
352
|
+
${addScopeVars(localScopeVars, true, (scopeVar) => `const ${scopeVar} = ${options.format === 'class' ? 'this.' : ''}getScope(el, "${scopeVar}");`)}
|
|
353
|
+
`);
|
|
354
|
+
}
|
|
355
|
+
if (html_tags_1.SELF_CLOSING_HTML_TAGS.has(json.name)) {
|
|
356
|
+
return str + ' />';
|
|
357
|
+
}
|
|
358
|
+
str += '>';
|
|
359
|
+
if (json.children) {
|
|
360
|
+
str += json.children.map((item) => blockToHtml(item, options, blockOptions)).join('\n');
|
|
361
|
+
}
|
|
362
|
+
if (json.properties.innerHTML) {
|
|
363
|
+
// Maybe put some kind of safety here for broken HTML such as no close tag
|
|
364
|
+
str += htmlDecode(json.properties.innerHTML);
|
|
365
|
+
}
|
|
366
|
+
str += `</${elSelector}>`;
|
|
367
|
+
}
|
|
368
|
+
return str;
|
|
369
|
+
};
|
|
370
|
+
function addUpdateAfterSetInCode(code = '', options, useString = options.format === 'class' ? 'this.update' : 'update') {
|
|
371
|
+
let updates = 0;
|
|
372
|
+
return (0, babel_transform_1.babelTransformExpression)(code, {
|
|
373
|
+
AssignmentExpression(path) {
|
|
374
|
+
var _a, _b;
|
|
375
|
+
const { node } = path;
|
|
376
|
+
if (core_1.types.isMemberExpression(node.left)) {
|
|
377
|
+
if (core_1.types.isIdentifier(node.left.object)) {
|
|
378
|
+
// TODO: utillity to properly trace this reference to the beginning
|
|
379
|
+
if (node.left.object.name === 'state') {
|
|
380
|
+
// TODO: ultimately do updates by property, e.g. updateName()
|
|
381
|
+
// that updates any attributes dependent on name, etcç
|
|
382
|
+
let parent = path;
|
|
383
|
+
// `_temp = ` assignments are created sometimes when we insertAfter
|
|
384
|
+
// for simple expressions. this causes us to re-process the same expression
|
|
385
|
+
// in an infinite loop
|
|
386
|
+
while ((parent = parent.parentPath)) {
|
|
387
|
+
if (core_1.types.isAssignmentExpression(parent.node) &&
|
|
388
|
+
core_1.types.isIdentifier(parent.node.left) &&
|
|
389
|
+
parent.node.left.name.startsWith('_temp')) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Uncomment to debug infinite loops:
|
|
394
|
+
// if (updates++ > 1000) {
|
|
395
|
+
// console.error('Infinite assignment detected');
|
|
396
|
+
// return;
|
|
397
|
+
// }
|
|
398
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.addUpdateAfterSetInCode) {
|
|
399
|
+
useString = (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.addUpdateAfterSetInCode(useString, options, {
|
|
400
|
+
node,
|
|
401
|
+
code,
|
|
402
|
+
types: core_1.types,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
path.insertAfter(core_1.types.callExpression(core_1.types.identifier(useString), []));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
const htmlDecode = (html) => html.replace(/"/gi, '"');
|
|
413
|
+
// TODO: props support via custom elements
|
|
414
|
+
const componentToHtml = (_options = {}) => ({ component }) => {
|
|
415
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
416
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
417
|
+
target: 'html',
|
|
418
|
+
component,
|
|
419
|
+
defaults: {
|
|
420
|
+
..._options,
|
|
421
|
+
onChangeJsById: {},
|
|
422
|
+
js: '',
|
|
423
|
+
namesMap: {},
|
|
424
|
+
format: 'script',
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
428
|
+
if (options.plugins) {
|
|
429
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
430
|
+
}
|
|
431
|
+
addUpdateAfterSet(json, options);
|
|
432
|
+
const componentHasProps = (0, has_props_1.hasProps)(json);
|
|
433
|
+
const hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
434
|
+
const hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
435
|
+
const hasTextBinding = (0, has_bindings_text_1.hasBindingsText)(json);
|
|
436
|
+
if (options.plugins) {
|
|
437
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
438
|
+
}
|
|
439
|
+
const css = (0, collect_css_1.collectCss)(json, {
|
|
440
|
+
prefix: options.prefix,
|
|
441
|
+
});
|
|
442
|
+
let str = json.children.map((item) => blockToHtml(item, options)).join('\n');
|
|
443
|
+
if (css.trim().length) {
|
|
444
|
+
str += `<style>${css}</style>`;
|
|
445
|
+
}
|
|
446
|
+
const hasChangeListeners = Boolean(Object.keys(options.onChangeJsById).length);
|
|
447
|
+
const hasGeneratedJs = Boolean(options.js.trim().length);
|
|
448
|
+
if (hasChangeListeners || hasGeneratedJs || json.hooks.onMount.length || hasLoop) {
|
|
449
|
+
// TODO: collectJs helper for here and liquid
|
|
450
|
+
str += `
|
|
451
|
+
<script>
|
|
452
|
+
(() => {
|
|
453
|
+
const state = ${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
454
|
+
valueMapper: (value) => addUpdateAfterSetInCode(updateReferencesInCode(value, options), options),
|
|
455
|
+
})};
|
|
456
|
+
${componentHasProps ? `let props = {};` : ''}
|
|
457
|
+
let context = null;
|
|
458
|
+
let nodesToDestroy = [];
|
|
459
|
+
let pendingUpdate = false;
|
|
460
|
+
${!((_b = (_a = json.hooks) === null || _a === void 0 ? void 0 : _a.onInit) === null || _b === void 0 ? void 0 : _b.code) ? '' : 'let onInitOnce = false;'}
|
|
461
|
+
|
|
462
|
+
function destroyAnyNodes() {
|
|
463
|
+
// destroy current view template refs before rendering again
|
|
464
|
+
nodesToDestroy.forEach(el => el.remove());
|
|
465
|
+
nodesToDestroy = [];
|
|
466
|
+
}
|
|
467
|
+
${!hasChangeListeners
|
|
468
|
+
? ''
|
|
469
|
+
: `
|
|
470
|
+
|
|
471
|
+
// Function to update data bindings and loops
|
|
472
|
+
// call update() when you mutate state and need the updates to reflect
|
|
473
|
+
// in the dom
|
|
474
|
+
function update() {
|
|
475
|
+
if (pendingUpdate === true) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
pendingUpdate = true;
|
|
479
|
+
${Object.keys(options.onChangeJsById)
|
|
480
|
+
.map((key) => {
|
|
481
|
+
const value = options.onChangeJsById[key];
|
|
482
|
+
if (!value) {
|
|
483
|
+
return '';
|
|
484
|
+
}
|
|
485
|
+
return `
|
|
486
|
+
document.querySelectorAll("[data-el='${key}']").forEach((el) => {
|
|
487
|
+
${value}
|
|
488
|
+
});
|
|
489
|
+
`;
|
|
490
|
+
})
|
|
491
|
+
.join('\n\n')}
|
|
492
|
+
|
|
493
|
+
destroyAnyNodes();
|
|
494
|
+
|
|
495
|
+
${!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)
|
|
496
|
+
? ''
|
|
497
|
+
: `
|
|
498
|
+
${json.hooks.onUpdate.reduce((code, hook) => {
|
|
499
|
+
code += addUpdateAfterSetInCode(updateReferencesInCode(hook.code, options), options);
|
|
500
|
+
return code + '\n';
|
|
501
|
+
}, '')}
|
|
502
|
+
`}
|
|
503
|
+
|
|
504
|
+
pendingUpdate = false;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
${options.js}
|
|
508
|
+
|
|
509
|
+
// Update with initial state on first load
|
|
510
|
+
update();
|
|
511
|
+
`}
|
|
512
|
+
|
|
513
|
+
${!((_e = (_d = json.hooks) === null || _d === void 0 ? void 0 : _d.onInit) === null || _e === void 0 ? void 0 : _e.code)
|
|
514
|
+
? ''
|
|
515
|
+
: `
|
|
516
|
+
if (!onInitOnce) {
|
|
517
|
+
${updateReferencesInCode(addUpdateAfterSetInCode((_g = (_f = json.hooks) === null || _f === void 0 ? void 0 : _f.onInit) === null || _g === void 0 ? void 0 : _g.code, options), options)}
|
|
518
|
+
onInitOnce = true;
|
|
519
|
+
}
|
|
520
|
+
`}
|
|
521
|
+
|
|
522
|
+
${!json.hooks.onMount.length
|
|
523
|
+
? ''
|
|
524
|
+
: // TODO: make prettier by grabbing only the function body
|
|
525
|
+
`
|
|
526
|
+
// onMount
|
|
527
|
+
${updateReferencesInCode(addUpdateAfterSetInCode((0, on_mount_1.stringifySingleScopeOnMount)(json), options), options)}
|
|
528
|
+
`}
|
|
529
|
+
|
|
530
|
+
${!hasShow
|
|
531
|
+
? ''
|
|
532
|
+
: `
|
|
533
|
+
function showContent(el) {
|
|
534
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content
|
|
535
|
+
// grabs the content of a node that is between <template> tags
|
|
536
|
+
// iterates through child nodes to register all content including text elements
|
|
537
|
+
// attaches the content after the template
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
const elementFragment = el.content.cloneNode(true);
|
|
541
|
+
const children = Array.from(elementFragment.childNodes)
|
|
542
|
+
children.forEach(child => {
|
|
543
|
+
if (el?.scope) {
|
|
544
|
+
child.scope = el.scope;
|
|
545
|
+
}
|
|
546
|
+
if (el?.context) {
|
|
547
|
+
child.context = el.context;
|
|
548
|
+
}
|
|
549
|
+
nodesToDestroy.push(child);
|
|
550
|
+
});
|
|
551
|
+
el.after(elementFragment);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
`}
|
|
555
|
+
${!hasTextBinding
|
|
556
|
+
? ''
|
|
557
|
+
: `
|
|
558
|
+
// Helper text DOM nodes
|
|
559
|
+
function renderTextNode(el, text) {
|
|
560
|
+
const textNode = document.createTextNode(text);
|
|
561
|
+
if (el?.scope) {
|
|
562
|
+
textNode.scope = el.scope
|
|
563
|
+
}
|
|
564
|
+
if (el?.context) {
|
|
565
|
+
child.context = el.context;
|
|
566
|
+
}
|
|
567
|
+
el.after(textNode);
|
|
568
|
+
nodesToDestroy.push(el.nextSibling);
|
|
569
|
+
}
|
|
570
|
+
`}
|
|
571
|
+
${!hasLoop
|
|
572
|
+
? ''
|
|
573
|
+
: `
|
|
574
|
+
// Helper to render loops
|
|
575
|
+
function renderLoop(template, array, itemName, itemIndex, collectionName) {
|
|
576
|
+
const collection = [];
|
|
577
|
+
for (let [index, value] of array.entries()) {
|
|
578
|
+
const elementFragment = template.content.cloneNode(true);
|
|
579
|
+
const children = Array.from(elementFragment.childNodes)
|
|
580
|
+
const localScope = {};
|
|
581
|
+
let scope = localScope;
|
|
582
|
+
if (template?.scope) {
|
|
583
|
+
const getParent = {
|
|
584
|
+
get(target, prop, receiver) {
|
|
585
|
+
if (prop in target) {
|
|
586
|
+
return target[prop];
|
|
587
|
+
}
|
|
588
|
+
if (prop in template.scope) {
|
|
589
|
+
return template.scope[prop];
|
|
590
|
+
}
|
|
591
|
+
return target[prop];
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
scope = new Proxy(localScope, getParent);
|
|
595
|
+
}
|
|
596
|
+
children.forEach((child) => {
|
|
597
|
+
if (itemName !== undefined) {
|
|
598
|
+
scope[itemName] = value;
|
|
599
|
+
}
|
|
600
|
+
if (itemIndex !== undefined) {
|
|
601
|
+
scope[itemIndex] = index;
|
|
602
|
+
}
|
|
603
|
+
if (collectionName !== undefined) {
|
|
604
|
+
scope[collectionName] = array;
|
|
605
|
+
}
|
|
606
|
+
child.scope = scope;
|
|
607
|
+
if (template.context) {
|
|
608
|
+
child.context = template.context;
|
|
609
|
+
}
|
|
610
|
+
this.nodesToDestroy.push(child);
|
|
611
|
+
collection.unshift(child);
|
|
612
|
+
});
|
|
613
|
+
collection.forEach(child => template.after(child));
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function getScope(el, name) {
|
|
618
|
+
do {
|
|
619
|
+
let value = el?.scope?.[name]
|
|
620
|
+
if (value !== undefined) {
|
|
621
|
+
return value
|
|
622
|
+
}
|
|
623
|
+
} while ((el = el.parentNode));
|
|
624
|
+
}
|
|
625
|
+
`}
|
|
626
|
+
})()
|
|
627
|
+
</script>
|
|
628
|
+
`;
|
|
629
|
+
}
|
|
630
|
+
if (options.plugins) {
|
|
631
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
632
|
+
}
|
|
633
|
+
if (options.prettier !== false) {
|
|
634
|
+
try {
|
|
635
|
+
str = (0, standalone_1.format)(str, {
|
|
636
|
+
parser: 'html',
|
|
637
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
638
|
+
plugins: [
|
|
639
|
+
// To support running in browsers
|
|
640
|
+
require('prettier/parser-html'),
|
|
641
|
+
require('prettier/parser-postcss'),
|
|
642
|
+
require('prettier/parser-babel'),
|
|
643
|
+
],
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
catch (err) {
|
|
647
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (options.plugins) {
|
|
651
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
652
|
+
}
|
|
653
|
+
return str;
|
|
654
|
+
};
|
|
655
|
+
exports.componentToHtml = componentToHtml;
|
|
656
|
+
// TODO: props support via custom elements
|
|
657
|
+
const componentToCustomElement = (_options = {}) => ({ component }) => {
|
|
658
|
+
var _a, _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;
|
|
659
|
+
const ComponentName = component.name;
|
|
660
|
+
const kebabName = (0, lodash_1.kebabCase)(ComponentName);
|
|
661
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
662
|
+
target: 'customElement',
|
|
663
|
+
component,
|
|
664
|
+
defaults: {
|
|
665
|
+
prefix: kebabName,
|
|
666
|
+
..._options,
|
|
667
|
+
onChangeJsById: {},
|
|
668
|
+
js: '',
|
|
669
|
+
namesMap: {},
|
|
670
|
+
format: 'class',
|
|
671
|
+
},
|
|
672
|
+
});
|
|
673
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
674
|
+
if (options.plugins) {
|
|
675
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
676
|
+
}
|
|
677
|
+
const [forwardProp, hasPropRef] = (0, get_props_ref_1.getPropsRef)(json, true);
|
|
678
|
+
const contextVars = Object.keys(((_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get) || {});
|
|
679
|
+
const childComponents = getChildComponents(json, options);
|
|
680
|
+
const componentHasProps = (0, has_props_1.hasProps)(json);
|
|
681
|
+
const componentHasStatefulDom = (0, has_stateful_dom_1.hasStatefulDom)(json);
|
|
682
|
+
const props = (0, get_props_1.getProps)(json);
|
|
683
|
+
// prevent jsx props from showing up as @Input
|
|
684
|
+
if (hasPropRef) {
|
|
685
|
+
props.delete(forwardProp);
|
|
686
|
+
}
|
|
687
|
+
const outputs = (0, get_prop_functions_1.getPropFunctions)(json);
|
|
688
|
+
const domRefs = (0, get_refs_1.getRefs)(json);
|
|
689
|
+
const jsRefs = Object.keys(json.refs).filter((ref) => !domRefs.has(ref));
|
|
690
|
+
(0, map_refs_1.mapRefs)(json, (refName) => `self._${refName}`);
|
|
691
|
+
const context = contextVars.map((variableName) => {
|
|
692
|
+
var _a, _b, _c;
|
|
693
|
+
const token = (_a = json === null || json === void 0 ? void 0 : json.context) === null || _a === void 0 ? void 0 : _a.get[variableName].name;
|
|
694
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.htmlContext) {
|
|
695
|
+
return (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.htmlContext(variableName, token);
|
|
696
|
+
}
|
|
697
|
+
return `this.${variableName} = this.getContext(this._root, ${token})`;
|
|
698
|
+
});
|
|
699
|
+
const setContext = [];
|
|
700
|
+
for (const key in json.context.set) {
|
|
701
|
+
const { name, value, ref } = json.context.set[key];
|
|
702
|
+
setContext.push({ name, value, ref });
|
|
703
|
+
}
|
|
704
|
+
addUpdateAfterSet(json, options);
|
|
705
|
+
const hasContext = context.length;
|
|
706
|
+
const hasLoop = (0, has_component_1.hasComponent)('For', json);
|
|
707
|
+
const hasScope = hasLoop;
|
|
708
|
+
const hasShow = (0, has_component_1.hasComponent)('Show', json);
|
|
709
|
+
if (options.plugins) {
|
|
710
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
711
|
+
}
|
|
712
|
+
let css = '';
|
|
713
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.css) {
|
|
714
|
+
css = (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.css(json, options, {
|
|
715
|
+
collectCss: collect_css_1.collectCss,
|
|
716
|
+
prefix: options.prefix,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
css = (0, collect_css_1.collectCss)(json, {
|
|
721
|
+
prefix: options.prefix,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
725
|
+
let html = json.children
|
|
726
|
+
.map((item) => blockToHtml(item, options, {
|
|
727
|
+
childComponents,
|
|
728
|
+
props,
|
|
729
|
+
outputs,
|
|
730
|
+
ComponentName,
|
|
731
|
+
contextVars,
|
|
732
|
+
}))
|
|
733
|
+
.join('\n');
|
|
734
|
+
if ((_d = options === null || options === void 0 ? void 0 : options.experimental) === null || _d === void 0 ? void 0 : _d.childrenHtml) {
|
|
735
|
+
html = (_e = options === null || options === void 0 ? void 0 : options.experimental) === null || _e === void 0 ? void 0 : _e.childrenHtml(html, kebabName, json, options);
|
|
736
|
+
}
|
|
737
|
+
if ((_f = options === null || options === void 0 ? void 0 : options.experimental) === null || _f === void 0 ? void 0 : _f.cssHtml) {
|
|
738
|
+
html += (_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.cssHtml(css);
|
|
739
|
+
}
|
|
740
|
+
else if (css.length) {
|
|
741
|
+
html += `<style>${css}</style>`;
|
|
742
|
+
}
|
|
743
|
+
if (options.prettier !== false) {
|
|
744
|
+
try {
|
|
745
|
+
html = (0, standalone_1.format)(html, {
|
|
746
|
+
parser: 'html',
|
|
747
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
748
|
+
plugins: [
|
|
749
|
+
// To support running in browsers
|
|
750
|
+
require('prettier/parser-html'),
|
|
751
|
+
require('prettier/parser-postcss'),
|
|
752
|
+
require('prettier/parser-babel'),
|
|
753
|
+
require('prettier/parser-typescript'),
|
|
754
|
+
],
|
|
755
|
+
});
|
|
756
|
+
html = html.trim().replace(/\n/g, '\n ');
|
|
757
|
+
}
|
|
758
|
+
catch (err) {
|
|
759
|
+
console.warn('Could not prettify', { string: html }, err);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
let str = `
|
|
763
|
+
${json.types ? json.types.join('\n') : ''}
|
|
764
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
765
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
766
|
+
component: json,
|
|
767
|
+
target: 'customElement',
|
|
768
|
+
})}
|
|
769
|
+
/**
|
|
770
|
+
* Usage:
|
|
771
|
+
*
|
|
772
|
+
* <${kebabName}></${kebabName}>
|
|
773
|
+
*
|
|
774
|
+
*/
|
|
775
|
+
class ${ComponentName} extends ${((_h = options === null || options === void 0 ? void 0 : options.experimental) === null || _h === void 0 ? void 0 : _h.classExtends)
|
|
776
|
+
? (_j = options === null || options === void 0 ? void 0 : options.experimental) === null || _j === void 0 ? void 0 : _j.classExtends(json, options)
|
|
777
|
+
: 'HTMLElement'} {
|
|
778
|
+
${Array.from(domRefs)
|
|
779
|
+
.map((ref) => {
|
|
780
|
+
return `
|
|
781
|
+
get _${ref}() {
|
|
782
|
+
return this._root.querySelector("[data-ref='${ComponentName}-${ref}']")
|
|
783
|
+
}
|
|
784
|
+
`;
|
|
785
|
+
})
|
|
786
|
+
.join('\n')}
|
|
787
|
+
|
|
788
|
+
get _root() {
|
|
789
|
+
return this.shadowRoot || this;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
constructor() {
|
|
793
|
+
super();
|
|
794
|
+
const self = this;
|
|
795
|
+
${
|
|
796
|
+
// TODO: more than one context not injector
|
|
797
|
+
setContext.length === 1 && ((_k = setContext === null || setContext === void 0 ? void 0 : setContext[0]) === null || _k === void 0 ? void 0 : _k.ref)
|
|
798
|
+
? `this.context = ${setContext[0].ref}`
|
|
799
|
+
: ''}
|
|
800
|
+
|
|
801
|
+
${!((_m = (_l = json.hooks) === null || _l === void 0 ? void 0 : _l.onInit) === null || _m === void 0 ? void 0 : _m.code) ? '' : 'this.onInitOnce = false;'}
|
|
802
|
+
|
|
803
|
+
this.state = ${(0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
|
|
804
|
+
valueMapper: (value) => (0, function_1.pipe)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, options, 'self.update'), {
|
|
805
|
+
includeProps: false,
|
|
806
|
+
includeState: true,
|
|
807
|
+
// TODO: if it's an arrow function it's this.state.
|
|
808
|
+
replaceWith: 'self.state.',
|
|
809
|
+
}), (newCode) => (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(newCode, {
|
|
810
|
+
// TODO: replace with `this.` and add setters that call this.update()
|
|
811
|
+
includeProps: true,
|
|
812
|
+
includeState: false,
|
|
813
|
+
replaceWith: 'self.props.',
|
|
814
|
+
}), (code) => (0, strip_state_and_props_refs_1.DO_NOT_USE_CONTEXT_VARS_TRANSFORMS)({
|
|
815
|
+
code,
|
|
816
|
+
contextVars,
|
|
817
|
+
// correctly ref the class not state object
|
|
818
|
+
context: 'self.',
|
|
819
|
+
})),
|
|
820
|
+
})};
|
|
821
|
+
if (!this.props) {
|
|
822
|
+
this.props = {};
|
|
823
|
+
}
|
|
824
|
+
${!componentHasProps
|
|
825
|
+
? ''
|
|
826
|
+
: `
|
|
827
|
+
this.componentProps = [${Array.from(props)
|
|
828
|
+
.map((prop) => `"${prop}"`)
|
|
829
|
+
.join(',')}];
|
|
830
|
+
`}
|
|
831
|
+
|
|
832
|
+
${!((_o = json.hooks.onUpdate) === null || _o === void 0 ? void 0 : _o.length)
|
|
833
|
+
? ''
|
|
834
|
+
: `
|
|
835
|
+
this.updateDeps = [${(_p = json.hooks.onUpdate) === null || _p === void 0 ? void 0 : _p.map((hook) => updateReferencesInCode((hook === null || hook === void 0 ? void 0 : hook.deps) || '[]', options)).join(',')}];
|
|
836
|
+
`}
|
|
837
|
+
|
|
838
|
+
// used to keep track of all nodes created by show/for
|
|
839
|
+
this.nodesToDestroy = [];
|
|
840
|
+
// batch updates
|
|
841
|
+
this.pendingUpdate = false;
|
|
842
|
+
${((_q = options === null || options === void 0 ? void 0 : options.experimental) === null || _q === void 0 ? void 0 : _q.componentConstructor)
|
|
843
|
+
? (_r = options === null || options === void 0 ? void 0 : options.experimental) === null || _r === void 0 ? void 0 : _r.componentConstructor(json, options)
|
|
844
|
+
: ''}
|
|
845
|
+
|
|
846
|
+
${options.js}
|
|
847
|
+
|
|
848
|
+
${jsRefs
|
|
849
|
+
.map((ref) => {
|
|
850
|
+
var _a;
|
|
851
|
+
// const typeParameter = json['refs'][ref]?.typeParameter || '';
|
|
852
|
+
const argument = ((_a = json['refs'][ref]) === null || _a === void 0 ? void 0 : _a.argument) || 'null';
|
|
853
|
+
return `this._${ref} = ${argument}`;
|
|
854
|
+
})
|
|
855
|
+
.join('\n')}
|
|
856
|
+
|
|
857
|
+
if (${(_s = json.meta.useMetadata) === null || _s === void 0 ? void 0 : _s.isAttachedToShadowDom}) {
|
|
858
|
+
this.attachShadow({ mode: 'open' })
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
${!((_t = json.hooks.onUnMount) === null || _t === void 0 ? void 0 : _t.code)
|
|
864
|
+
? ''
|
|
865
|
+
: `
|
|
866
|
+
disconnectedCallback() {
|
|
867
|
+
${((_u = options === null || options === void 0 ? void 0 : options.experimental) === null || _u === void 0 ? void 0 : _u.disconnectedCallback)
|
|
868
|
+
? (_v = options === null || options === void 0 ? void 0 : options.experimental) === null || _v === void 0 ? void 0 : _v.disconnectedCallback(json, options)
|
|
869
|
+
: `
|
|
870
|
+
// onUnMount
|
|
871
|
+
${updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount.code, options), options, {
|
|
872
|
+
contextVars,
|
|
873
|
+
})}
|
|
874
|
+
this.destroyAnyNodes(); // clean up nodes when component is destroyed
|
|
875
|
+
${!((_x = (_w = json.hooks) === null || _w === void 0 ? void 0 : _w.onInit) === null || _x === void 0 ? void 0 : _x.code) ? '' : 'this.onInitOnce = false;'}
|
|
876
|
+
`}
|
|
877
|
+
}
|
|
878
|
+
`}
|
|
879
|
+
|
|
880
|
+
destroyAnyNodes() {
|
|
881
|
+
// destroy current view template refs before rendering again
|
|
882
|
+
this.nodesToDestroy.forEach(el => el.remove());
|
|
883
|
+
this.nodesToDestroy = [];
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
connectedCallback() {
|
|
887
|
+
${context.join('\n')}
|
|
888
|
+
${!componentHasProps
|
|
889
|
+
? ''
|
|
890
|
+
: `
|
|
891
|
+
this.getAttributeNames().forEach((attr) => {
|
|
892
|
+
const jsVar = attr.replace(/-/g, '');
|
|
893
|
+
const regexp = new RegExp(jsVar, 'i');
|
|
894
|
+
this.componentProps.forEach(prop => {
|
|
895
|
+
if (regexp.test(prop)) {
|
|
896
|
+
const attrValue = this.getAttribute(attr);
|
|
897
|
+
if (this.props[prop] !== attrValue) {
|
|
898
|
+
this.props[prop] = attrValue;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
`}
|
|
904
|
+
${((_y = options === null || options === void 0 ? void 0 : options.experimental) === null || _y === void 0 ? void 0 : _y.connectedCallbackUpdate)
|
|
905
|
+
? (_z = options === null || options === void 0 ? void 0 : options.experimental) === null || _z === void 0 ? void 0 : _z.connectedCallbackUpdate(json, html, options)
|
|
906
|
+
: `
|
|
907
|
+
this._root.innerHTML = \`
|
|
908
|
+
${html}\`;
|
|
909
|
+
this.pendingUpdate = true;
|
|
910
|
+
${!((_1 = (_0 = json.hooks) === null || _0 === void 0 ? void 0 : _0.onInit) === null || _1 === void 0 ? void 0 : _1.code) ? '' : 'this.onInit();'}
|
|
911
|
+
this.render();
|
|
912
|
+
this.onMount();
|
|
913
|
+
this.pendingUpdate = false;
|
|
914
|
+
this.update();
|
|
915
|
+
`}
|
|
916
|
+
}
|
|
917
|
+
${!((_3 = (_2 = json.hooks) === null || _2 === void 0 ? void 0 : _2.onInit) === null || _3 === void 0 ? void 0 : _3.code)
|
|
918
|
+
? ''
|
|
919
|
+
: `
|
|
920
|
+
onInit() {
|
|
921
|
+
${!((_5 = (_4 = json.hooks) === null || _4 === void 0 ? void 0 : _4.onInit) === null || _5 === void 0 ? void 0 : _5.code)
|
|
922
|
+
? ''
|
|
923
|
+
: `
|
|
924
|
+
if (!this.onInitOnce) {
|
|
925
|
+
${updateReferencesInCode(addUpdateAfterSetInCode((_7 = (_6 = json.hooks) === null || _6 === void 0 ? void 0 : _6.onInit) === null || _7 === void 0 ? void 0 : _7.code, options), options, {
|
|
926
|
+
contextVars,
|
|
927
|
+
})}
|
|
928
|
+
this.onInitOnce = true;
|
|
929
|
+
}`}
|
|
930
|
+
}
|
|
931
|
+
`}
|
|
932
|
+
|
|
933
|
+
${!hasShow
|
|
934
|
+
? ''
|
|
935
|
+
: `
|
|
936
|
+
showContent(el) {
|
|
937
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content
|
|
938
|
+
// grabs the content of a node that is between <template> tags
|
|
939
|
+
// iterates through child nodes to register all content including text elements
|
|
940
|
+
// attaches the content after the template
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
const elementFragment = el.content.cloneNode(true);
|
|
944
|
+
const children = Array.from(elementFragment.childNodes)
|
|
945
|
+
children.forEach(child => {
|
|
946
|
+
if (el?.scope) {
|
|
947
|
+
child.scope = el.scope;
|
|
948
|
+
}
|
|
949
|
+
if (el?.context) {
|
|
950
|
+
child.context = el.context;
|
|
951
|
+
}
|
|
952
|
+
this.nodesToDestroy.push(child);
|
|
953
|
+
});
|
|
954
|
+
el.after(elementFragment);
|
|
955
|
+
}`}
|
|
956
|
+
${!((_8 = options === null || options === void 0 ? void 0 : options.experimental) === null || _8 === void 0 ? void 0 : _8.attributeChangedCallback)
|
|
957
|
+
? ''
|
|
958
|
+
: `
|
|
959
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
960
|
+
${(_9 = options === null || options === void 0 ? void 0 : options.experimental) === null || _9 === void 0 ? void 0 : _9.attributeChangedCallback(['name', 'oldValue', 'newValue'], json, options)}
|
|
961
|
+
}
|
|
962
|
+
`}
|
|
963
|
+
|
|
964
|
+
onMount() {
|
|
965
|
+
${!json.hooks.onMount.length
|
|
966
|
+
? ''
|
|
967
|
+
: // TODO: make prettier by grabbing only the function body
|
|
968
|
+
`
|
|
969
|
+
// onMount
|
|
970
|
+
${updateReferencesInCode(addUpdateAfterSetInCode((0, on_mount_1.stringifySingleScopeOnMount)(json), options), options, {
|
|
971
|
+
contextVars,
|
|
972
|
+
})}
|
|
973
|
+
`}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
onUpdate() {
|
|
977
|
+
${!((_10 = json.hooks.onUpdate) === null || _10 === void 0 ? void 0 : _10.length)
|
|
978
|
+
? ''
|
|
979
|
+
: `
|
|
980
|
+
const self = this;
|
|
981
|
+
${json.hooks.onUpdate.reduce((code, hook, index) => {
|
|
982
|
+
// create check update
|
|
983
|
+
if (hook === null || hook === void 0 ? void 0 : hook.deps) {
|
|
984
|
+
code += `
|
|
985
|
+
;(function (__prev, __next) {
|
|
986
|
+
const __hasChange = __prev.find((val, index) => val !== __next[index]);
|
|
987
|
+
if (__hasChange !== undefined) {
|
|
988
|
+
${updateReferencesInCode(hook.code, options, {
|
|
989
|
+
contextVars,
|
|
990
|
+
context: 'self.',
|
|
991
|
+
})}
|
|
992
|
+
self.updateDeps[${index}] = __next;
|
|
993
|
+
}
|
|
994
|
+
}(self.updateDeps[${index}], ${updateReferencesInCode((hook === null || hook === void 0 ? void 0 : hook.deps) || '[]', options, {
|
|
995
|
+
contextVars,
|
|
996
|
+
context: 'self.',
|
|
997
|
+
})}));
|
|
998
|
+
`;
|
|
999
|
+
}
|
|
1000
|
+
else {
|
|
1001
|
+
code += `
|
|
1002
|
+
${updateReferencesInCode(hook.code, options, {
|
|
1003
|
+
contextVars,
|
|
1004
|
+
context: 'self.',
|
|
1005
|
+
})}
|
|
1006
|
+
`;
|
|
1007
|
+
}
|
|
1008
|
+
return code + '\n';
|
|
1009
|
+
}, '')}
|
|
1010
|
+
`}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
update() {
|
|
1014
|
+
if (this.pendingUpdate === true) {
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
this.pendingUpdate = true;
|
|
1018
|
+
this.render();
|
|
1019
|
+
this.onUpdate();
|
|
1020
|
+
this.pendingUpdate = false;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
render() {
|
|
1024
|
+
${!componentHasStatefulDom
|
|
1025
|
+
? ''
|
|
1026
|
+
: `
|
|
1027
|
+
// grab previous input state
|
|
1028
|
+
const preStateful = this.getStateful(this._root);
|
|
1029
|
+
const preValues = this.prepareHydrate(preStateful);
|
|
1030
|
+
`}
|
|
1031
|
+
|
|
1032
|
+
// re-rendering needs to ensure that all nodes generated by for/show are refreshed
|
|
1033
|
+
this.destroyAnyNodes();
|
|
1034
|
+
this.updateBindings();
|
|
1035
|
+
|
|
1036
|
+
${!componentHasStatefulDom
|
|
1037
|
+
? ''
|
|
1038
|
+
: `
|
|
1039
|
+
// hydrate input state
|
|
1040
|
+
if (preValues.length) {
|
|
1041
|
+
const nextStateful = this.getStateful(this._root);
|
|
1042
|
+
this.hydrateDom(preValues, nextStateful);
|
|
1043
|
+
}
|
|
1044
|
+
`}
|
|
1045
|
+
}
|
|
1046
|
+
${!componentHasStatefulDom
|
|
1047
|
+
? ''
|
|
1048
|
+
: `
|
|
1049
|
+
getStateful(el) {
|
|
1050
|
+
const stateful = el.querySelectorAll('[data-dom-state]');
|
|
1051
|
+
return stateful ? Array.from(stateful) : [];
|
|
1052
|
+
}
|
|
1053
|
+
prepareHydrate(stateful) {
|
|
1054
|
+
return stateful.map(el => {
|
|
1055
|
+
return {
|
|
1056
|
+
id: el.dataset.domState,
|
|
1057
|
+
value: el.value,
|
|
1058
|
+
active: document.activeElement === el,
|
|
1059
|
+
selectionStart: el.selectionStart
|
|
1060
|
+
};
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
hydrateDom(preValues, stateful) {
|
|
1064
|
+
return stateful.map((el, index) => {
|
|
1065
|
+
const prev = preValues.find((prev) => el.dataset.domState === prev.id);
|
|
1066
|
+
if (prev) {
|
|
1067
|
+
el.value = prev.value;
|
|
1068
|
+
if (prev.active) {
|
|
1069
|
+
el.focus();
|
|
1070
|
+
el.selectionStart = prev.selectionStart;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
`}
|
|
1076
|
+
|
|
1077
|
+
updateBindings() {
|
|
1078
|
+
${Object.keys(options.onChangeJsById)
|
|
1079
|
+
.map((key) => {
|
|
1080
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1081
|
+
const value = options.onChangeJsById[key];
|
|
1082
|
+
if (!value) {
|
|
1083
|
+
return '';
|
|
1084
|
+
}
|
|
1085
|
+
let code = '';
|
|
1086
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.updateBindings) {
|
|
1087
|
+
key = (_c = (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.updateBindings) === null || _c === void 0 ? void 0 : _c.key(key, value, options);
|
|
1088
|
+
code = (_e = (_d = options === null || options === void 0 ? void 0 : options.experimental) === null || _d === void 0 ? void 0 : _d.updateBindings) === null || _e === void 0 ? void 0 : _e.code(key, value, options);
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
code = updateReferencesInCode(value, options, {
|
|
1092
|
+
contextVars,
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
return `
|
|
1096
|
+
${((_f = options === null || options === void 0 ? void 0 : options.experimental) === null || _f === void 0 ? void 0 : _f.generateQuerySelectorAll)
|
|
1097
|
+
? `
|
|
1098
|
+
${(_g = options === null || options === void 0 ? void 0 : options.experimental) === null || _g === void 0 ? void 0 : _g.generateQuerySelectorAll(key, code)}
|
|
1099
|
+
`
|
|
1100
|
+
: `
|
|
1101
|
+
this._root.querySelectorAll("[data-el='${key}']").forEach((el) => {
|
|
1102
|
+
${code}
|
|
1103
|
+
})
|
|
1104
|
+
`}
|
|
1105
|
+
`;
|
|
1106
|
+
})
|
|
1107
|
+
.join('\n\n')}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Helper to render content
|
|
1111
|
+
renderTextNode(el, text) {
|
|
1112
|
+
const textNode = document.createTextNode(text);
|
|
1113
|
+
if (el?.scope) {
|
|
1114
|
+
textNode.scope = el.scope;
|
|
1115
|
+
}
|
|
1116
|
+
if (el?.context) {
|
|
1117
|
+
textNode.context = el.context;
|
|
1118
|
+
}
|
|
1119
|
+
el.after(textNode);
|
|
1120
|
+
this.nodesToDestroy.push(el.nextSibling);
|
|
1121
|
+
}
|
|
1122
|
+
${!hasContext
|
|
1123
|
+
? ''
|
|
1124
|
+
: `
|
|
1125
|
+
// get Context Helper
|
|
1126
|
+
getContext(el, token) {
|
|
1127
|
+
do {
|
|
1128
|
+
let value;
|
|
1129
|
+
if (el?.context?.get) {
|
|
1130
|
+
value = el.context.get(token);
|
|
1131
|
+
} else if (el?.context?.[token]) {
|
|
1132
|
+
value = el.context[token];
|
|
1133
|
+
}
|
|
1134
|
+
if (value !== undefined) {
|
|
1135
|
+
return value;
|
|
1136
|
+
}
|
|
1137
|
+
} while ((el = el.parentNode));
|
|
1138
|
+
}
|
|
1139
|
+
`}
|
|
1140
|
+
${!hasScope
|
|
1141
|
+
? ''
|
|
1142
|
+
: `
|
|
1143
|
+
// scope helper
|
|
1144
|
+
getScope(el, name) {
|
|
1145
|
+
do {
|
|
1146
|
+
let value = el?.scope?.[name]
|
|
1147
|
+
if (value !== undefined) {
|
|
1148
|
+
return value
|
|
1149
|
+
}
|
|
1150
|
+
} while ((el = el.parentNode));
|
|
1151
|
+
}
|
|
1152
|
+
`}
|
|
1153
|
+
|
|
1154
|
+
${!hasLoop
|
|
1155
|
+
? ''
|
|
1156
|
+
: `
|
|
1157
|
+
|
|
1158
|
+
// Helper to render loops
|
|
1159
|
+
renderLoop(template, array, itemName, itemIndex, collectionName) {
|
|
1160
|
+
const collection = [];
|
|
1161
|
+
for (let [index, value] of array.entries()) {
|
|
1162
|
+
const elementFragment = template.content.cloneNode(true);
|
|
1163
|
+
const children = Array.from(elementFragment.childNodes)
|
|
1164
|
+
const localScope = {};
|
|
1165
|
+
let scope = localScope;
|
|
1166
|
+
if (template?.scope) {
|
|
1167
|
+
const getParent = {
|
|
1168
|
+
get(target, prop, receiver) {
|
|
1169
|
+
if (prop in target) {
|
|
1170
|
+
return target[prop];
|
|
1171
|
+
}
|
|
1172
|
+
if (prop in template.scope) {
|
|
1173
|
+
return template.scope[prop];
|
|
1174
|
+
}
|
|
1175
|
+
return target[prop];
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
scope = new Proxy(localScope, getParent);
|
|
1179
|
+
}
|
|
1180
|
+
children.forEach((child) => {
|
|
1181
|
+
if (itemName !== undefined) {
|
|
1182
|
+
scope[itemName] = value;
|
|
1183
|
+
}
|
|
1184
|
+
if (itemIndex !== undefined) {
|
|
1185
|
+
scope[itemIndex] = index;
|
|
1186
|
+
}
|
|
1187
|
+
if (collectionName !== undefined) {
|
|
1188
|
+
scope[collectionName] = array;
|
|
1189
|
+
}
|
|
1190
|
+
child.scope = scope;
|
|
1191
|
+
if (template.context) {
|
|
1192
|
+
child.context = context;
|
|
1193
|
+
}
|
|
1194
|
+
this.nodesToDestroy.push(child);
|
|
1195
|
+
collection.unshift(child)
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
collection.forEach(child => template.after(child));
|
|
1199
|
+
}
|
|
1200
|
+
`}
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
${((_11 = options === null || options === void 0 ? void 0 : options.experimental) === null || _11 === void 0 ? void 0 : _11.customElementsDefine)
|
|
1204
|
+
? (_12 = options === null || options === void 0 ? void 0 : options.experimental) === null || _12 === void 0 ? void 0 : _12.customElementsDefine(kebabName, component, options)
|
|
1205
|
+
: `customElements.define('${kebabName}', ${ComponentName});`}
|
|
1206
|
+
`;
|
|
1207
|
+
if (options.plugins) {
|
|
1208
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
1209
|
+
}
|
|
1210
|
+
if (options.prettier !== false) {
|
|
1211
|
+
try {
|
|
1212
|
+
str = (0, standalone_1.format)(str, {
|
|
1213
|
+
parser: 'typescript',
|
|
1214
|
+
plugins: [
|
|
1215
|
+
// To support running in browsers
|
|
1216
|
+
require('prettier/parser-html'),
|
|
1217
|
+
require('prettier/parser-postcss'),
|
|
1218
|
+
require('prettier/parser-babel'),
|
|
1219
|
+
require('prettier/parser-typescript'),
|
|
1220
|
+
],
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
catch (err) {
|
|
1224
|
+
console.warn('Could not prettify', { string: str }, err);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
if (options.plugins) {
|
|
1228
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
1229
|
+
}
|
|
1230
|
+
return str;
|
|
1231
|
+
};
|
|
1232
|
+
exports.componentToCustomElement = componentToCustomElement;
|