@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,399 @@
|
|
|
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.componentToReact = exports.componentToPreact = exports.contextPropDrillingKey = void 0;
|
|
7
|
+
const default_props_1 = require("../../generators/react/helpers/default-props");
|
|
8
|
+
const hooks_1 = require("../../generators/react/helpers/hooks");
|
|
9
|
+
const bindings_1 = require("../../helpers/bindings");
|
|
10
|
+
const create_mitosis_node_1 = require("../../helpers/create-mitosis-node");
|
|
11
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
12
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
13
|
+
const get_props_ref_1 = require("../../helpers/get-props-ref");
|
|
14
|
+
const get_refs_1 = require("../../helpers/get-refs");
|
|
15
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
16
|
+
const getters_to_functions_1 = require("../../helpers/getters-to-functions");
|
|
17
|
+
const handle_missing_state_1 = require("../../helpers/handle-missing-state");
|
|
18
|
+
const is_root_text_node_1 = require("../../helpers/is-root-text-node");
|
|
19
|
+
const map_refs_1 = require("../../helpers/map-refs");
|
|
20
|
+
const merge_options_1 = require("../../helpers/merge-options");
|
|
21
|
+
const nullable_1 = require("../../helpers/nullable");
|
|
22
|
+
const on_event_1 = require("../../helpers/on-event");
|
|
23
|
+
const process_code_1 = require("../../helpers/plugins/process-code");
|
|
24
|
+
const process_http_requests_1 = require("../../helpers/process-http-requests");
|
|
25
|
+
const render_imports_1 = require("../../helpers/render-imports");
|
|
26
|
+
const replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
27
|
+
const replace_new_lines_in_strings_1 = require("../../helpers/replace-new-lines-in-strings");
|
|
28
|
+
const state_1 = require("../../helpers/state");
|
|
29
|
+
const strip_meta_properties_1 = require("../../helpers/strip-meta-properties");
|
|
30
|
+
const collect_css_1 = require("../../helpers/styles/collect-css");
|
|
31
|
+
const collect_styled_components_1 = require("../../helpers/styles/collect-styled-components");
|
|
32
|
+
const helpers_1 = require("../../helpers/styles/helpers");
|
|
33
|
+
const plugins_1 = require("../../modules/plugins");
|
|
34
|
+
const core_1 = require("@babel/core");
|
|
35
|
+
const hash_sum_1 = __importDefault(require("hash-sum"));
|
|
36
|
+
const json5_1 = __importDefault(require("json5"));
|
|
37
|
+
const standalone_1 = require("prettier/standalone");
|
|
38
|
+
const context_1 = require("../helpers/context");
|
|
39
|
+
const rsc_1 = require("../helpers/rsc");
|
|
40
|
+
const react_native_1 = require("../react-native");
|
|
41
|
+
const blocks_1 = require("./blocks");
|
|
42
|
+
const helpers_2 = require("./helpers");
|
|
43
|
+
const state_2 = require("./helpers/state");
|
|
44
|
+
exports.contextPropDrillingKey = '_context';
|
|
45
|
+
/**
|
|
46
|
+
* If the root Mitosis component only has 1 child, and it is a `Show`/`For` node, then we need to wrap it in a fragment.
|
|
47
|
+
* Otherwise, we end up with invalid React render code.
|
|
48
|
+
*/
|
|
49
|
+
const isRootSpecialNode = (json) => json.children.length === 1 && ['Show', 'For'].includes(json.children[0].name);
|
|
50
|
+
const getRefsString = (json, refs, options) => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
let hasStateArgument = false;
|
|
53
|
+
let code = '';
|
|
54
|
+
const domRefs = (0, get_refs_1.getRefs)(json);
|
|
55
|
+
for (const ref of refs) {
|
|
56
|
+
const typeParameter = ((_a = json['refs'][ref]) === null || _a === void 0 ? void 0 : _a.typeParameter) || '';
|
|
57
|
+
// domRefs must have null argument
|
|
58
|
+
const argument = ((_b = json['refs'][ref]) === null || _b === void 0 ? void 0 : _b.argument) || (domRefs.has(ref) ? 'null' : '');
|
|
59
|
+
hasStateArgument = /state\./.test(argument);
|
|
60
|
+
code += `\nconst ${ref} = useRef${typeParameter && options.typescript ? `<${typeParameter}>` : ''}(${(0, state_2.processHookCode)({
|
|
61
|
+
str: argument,
|
|
62
|
+
options,
|
|
63
|
+
})});`;
|
|
64
|
+
}
|
|
65
|
+
return [hasStateArgument, code];
|
|
66
|
+
};
|
|
67
|
+
function provideContext(json, options) {
|
|
68
|
+
if (options.contextType === 'prop-drill') {
|
|
69
|
+
let str = '';
|
|
70
|
+
for (const key in json.context.set) {
|
|
71
|
+
const { name, ref, value } = json.context.set[key];
|
|
72
|
+
if (value) {
|
|
73
|
+
str += `
|
|
74
|
+
${exports.contextPropDrillingKey}.${name} = ${(0, get_state_object_string_1.stringifyContextValue)(value)};
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
// TODO: support refs. I'm not sure what those are so unclear how to support them
|
|
78
|
+
}
|
|
79
|
+
return str;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
for (const key in json.context.set) {
|
|
83
|
+
const { name, ref, value } = json.context.set[key];
|
|
84
|
+
if (value) {
|
|
85
|
+
json.children = [
|
|
86
|
+
(0, create_mitosis_node_1.createMitosisNode)({
|
|
87
|
+
name: `${name}.Provider`,
|
|
88
|
+
children: json.children,
|
|
89
|
+
...(value && {
|
|
90
|
+
bindings: {
|
|
91
|
+
value: (0, bindings_1.createSingleBinding)({
|
|
92
|
+
code: (0, get_state_object_string_1.stringifyContextValue)(value),
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
}),
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
else if (ref) {
|
|
100
|
+
json.children = [
|
|
101
|
+
(0, create_mitosis_node_1.createMitosisNode)({
|
|
102
|
+
name: `${name}.Provider`,
|
|
103
|
+
children: json.children,
|
|
104
|
+
...(ref && {
|
|
105
|
+
bindings: {
|
|
106
|
+
value: (0, bindings_1.createSingleBinding)({ code: ref }),
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
}),
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function getContextString(component, options) {
|
|
116
|
+
let str = '';
|
|
117
|
+
for (const key in component.context.get) {
|
|
118
|
+
if (options.contextType === 'prop-drill') {
|
|
119
|
+
str += `
|
|
120
|
+
const ${key} = ${exports.contextPropDrillingKey}['${component.context.get[key].name}'];
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
str += `
|
|
125
|
+
const ${key} = useContext(${component.context.get[key].name});
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return str;
|
|
130
|
+
}
|
|
131
|
+
const componentToPreact = (reactOptions = {}) => (0, exports.componentToReact)({
|
|
132
|
+
...reactOptions,
|
|
133
|
+
preact: true,
|
|
134
|
+
});
|
|
135
|
+
exports.componentToPreact = componentToPreact;
|
|
136
|
+
const componentToReact = (reactOptions = {}) => ({ component, path }) => {
|
|
137
|
+
let json = (0, fast_clone_1.fastClone)(component);
|
|
138
|
+
const target = reactOptions.preact
|
|
139
|
+
? 'preact'
|
|
140
|
+
: reactOptions.type === 'native'
|
|
141
|
+
? 'reactNative'
|
|
142
|
+
: reactOptions.type === 'taro'
|
|
143
|
+
? 'taro'
|
|
144
|
+
: reactOptions.rsc
|
|
145
|
+
? 'rsc'
|
|
146
|
+
: 'react';
|
|
147
|
+
const stateType = reactOptions.stateType || 'useState';
|
|
148
|
+
const DEFAULT_OPTIONS = {
|
|
149
|
+
addUseClientDirectiveIfNeeded: true,
|
|
150
|
+
stateType,
|
|
151
|
+
stylesType: 'styled-jsx',
|
|
152
|
+
styleTagsPlacement: 'bottom',
|
|
153
|
+
type: 'dom',
|
|
154
|
+
plugins: [
|
|
155
|
+
(0, on_event_1.processOnEventHooksPlugin)({ setBindings: false }),
|
|
156
|
+
...(stateType === 'variables'
|
|
157
|
+
? [
|
|
158
|
+
(0, process_code_1.CODE_PROCESSOR_PLUGIN)((codeType, json) => (code, hookType) => {
|
|
159
|
+
if (codeType === 'types')
|
|
160
|
+
return code;
|
|
161
|
+
code = (0, replace_identifiers_1.replaceNodes)({
|
|
162
|
+
code,
|
|
163
|
+
nodeMaps: Object.entries(json.state)
|
|
164
|
+
.filter(([key, value]) => (value === null || value === void 0 ? void 0 : value.type) === 'getter')
|
|
165
|
+
.map(([key, value]) => {
|
|
166
|
+
const expr = core_1.types.memberExpression(core_1.types.identifier('state'), core_1.types.identifier(key));
|
|
167
|
+
return {
|
|
168
|
+
from: expr,
|
|
169
|
+
// condition: (path) => !types.isObjectMethod(path.parent),
|
|
170
|
+
to: core_1.types.callExpression(expr, []),
|
|
171
|
+
};
|
|
172
|
+
}),
|
|
173
|
+
});
|
|
174
|
+
code = (0, replace_identifiers_1.replaceStateIdentifier)(null)(code);
|
|
175
|
+
return code;
|
|
176
|
+
}),
|
|
177
|
+
]
|
|
178
|
+
: []),
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
const options = (0, merge_options_1.initializeOptions)({
|
|
182
|
+
target,
|
|
183
|
+
component,
|
|
184
|
+
defaults: DEFAULT_OPTIONS,
|
|
185
|
+
userOptions: reactOptions,
|
|
186
|
+
});
|
|
187
|
+
if (options.plugins) {
|
|
188
|
+
json = (0, plugins_1.runPreJsonPlugins)({ json, plugins: options.plugins });
|
|
189
|
+
}
|
|
190
|
+
let str = _componentToReact(json, options);
|
|
191
|
+
str +=
|
|
192
|
+
'\n\n\n' +
|
|
193
|
+
json.subComponents.map((item) => _componentToReact(item, options, true)).join('\n\n\n');
|
|
194
|
+
if (options.plugins) {
|
|
195
|
+
str = (0, plugins_1.runPreCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
196
|
+
}
|
|
197
|
+
if (options.prettier !== false) {
|
|
198
|
+
try {
|
|
199
|
+
str = (0, standalone_1.format)(str, {
|
|
200
|
+
parser: 'typescript',
|
|
201
|
+
plugins: [
|
|
202
|
+
require('prettier/parser-typescript'), // To support running in browsers
|
|
203
|
+
require('prettier/parser-postcss'),
|
|
204
|
+
],
|
|
205
|
+
})
|
|
206
|
+
// Remove spaces between imports
|
|
207
|
+
.replace(/;\n\nimport\s/g, ';\nimport ');
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
211
|
+
console.error('Format error for file:', str);
|
|
212
|
+
}
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (options.plugins) {
|
|
217
|
+
str = (0, plugins_1.runPostCodePlugins)({ json, code: str, plugins: options.plugins });
|
|
218
|
+
}
|
|
219
|
+
return str;
|
|
220
|
+
};
|
|
221
|
+
exports.componentToReact = componentToReact;
|
|
222
|
+
const isRSC = (json, options) => {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
// When using RSC generator, we check `componentType` field in metadata to determine if it's a server component
|
|
225
|
+
const componentType = (_b = (_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.rsc) === null || _b === void 0 ? void 0 : _b.componentType;
|
|
226
|
+
if (options.rsc && (0, nullable_1.checkIsDefined)(componentType)) {
|
|
227
|
+
return componentType === 'server';
|
|
228
|
+
}
|
|
229
|
+
return !(0, rsc_1.checkIfIsClientComponent)(json);
|
|
230
|
+
};
|
|
231
|
+
const checkShouldAddUseClientDirective = (json, options) => {
|
|
232
|
+
if (!options.addUseClientDirectiveIfNeeded)
|
|
233
|
+
return false;
|
|
234
|
+
if (options.type === 'native')
|
|
235
|
+
return false;
|
|
236
|
+
if (options.preact)
|
|
237
|
+
return false;
|
|
238
|
+
return !isRSC(json, options);
|
|
239
|
+
};
|
|
240
|
+
const generateStyleTags = (placement, json, options, componentHasStyles, css, shouldInjectCustomStyles) => {
|
|
241
|
+
if (placement !== options.styleTagsPlacement)
|
|
242
|
+
return '';
|
|
243
|
+
return (0, dedent_1.dedent) `
|
|
244
|
+
${componentHasStyles && options.stylesType === 'styled-jsx'
|
|
245
|
+
? `<style jsx>{\`${css}\`}</style>`
|
|
246
|
+
: ''}
|
|
247
|
+
${componentHasStyles && options.stylesType === 'style-tag' ? `<style>{\`${css}\`}</style>` : ''}
|
|
248
|
+
${shouldInjectCustomStyles ? `<style>{\`${json.style}\`}</style>` : ''}
|
|
249
|
+
`;
|
|
250
|
+
};
|
|
251
|
+
const _componentToReact = (json, options, isSubComponent = false) => {
|
|
252
|
+
var _a, _b, _c, _d, _e, _f;
|
|
253
|
+
(0, process_http_requests_1.processHttpRequests)(json);
|
|
254
|
+
(0, handle_missing_state_1.handleMissingState)(json);
|
|
255
|
+
(0, helpers_2.processTagReferences)(json, options);
|
|
256
|
+
const contextStr = provideContext(json, options);
|
|
257
|
+
const componentHasStyles = (0, helpers_1.hasCss)(json);
|
|
258
|
+
if (options.stateType === 'useState') {
|
|
259
|
+
(0, getters_to_functions_1.gettersToFunctions)(json);
|
|
260
|
+
(0, state_2.updateStateSetters)(json, options);
|
|
261
|
+
}
|
|
262
|
+
if (!json.name) {
|
|
263
|
+
json.name = 'MyComponent';
|
|
264
|
+
}
|
|
265
|
+
// const domRefs = getRefs(json);
|
|
266
|
+
const allRefs = Object.keys(json.refs);
|
|
267
|
+
(0, map_refs_1.mapRefs)(json, (refName) => `${refName}.current`);
|
|
268
|
+
// Always use state if we are generate Builder react code
|
|
269
|
+
const hasState = options.stateType === 'builder' || (0, state_1.checkHasState)(json);
|
|
270
|
+
const [forwardRef, hasPropRef] = (0, get_props_ref_1.getPropsRef)(json);
|
|
271
|
+
const isForwardRef = !options.preact && Boolean((0, helpers_2.isReactForwardRef)(json) || hasPropRef);
|
|
272
|
+
if (isForwardRef) {
|
|
273
|
+
const meta = (0, helpers_2.isReactForwardRef)(json);
|
|
274
|
+
options.forwardRef = meta || forwardRef;
|
|
275
|
+
}
|
|
276
|
+
const forwardRefType = options.typescript && json.propsTypeRef && forwardRef && json.propsTypeRef !== 'any'
|
|
277
|
+
? `<${json.propsTypeRef}["${forwardRef}"]>`
|
|
278
|
+
: '';
|
|
279
|
+
const useStateCode = options.stateType === 'useState' ? (0, state_2.getUseStateCode)(json, options) : '';
|
|
280
|
+
if (options.plugins) {
|
|
281
|
+
json = (0, plugins_1.runPostJsonPlugins)({ json, plugins: options.plugins });
|
|
282
|
+
}
|
|
283
|
+
const css = options.stylesType === 'styled-jsx'
|
|
284
|
+
? (0, collect_css_1.collectCss)(json)
|
|
285
|
+
: options.stylesType === 'style-tag'
|
|
286
|
+
? (0, collect_css_1.collectCss)(json, {
|
|
287
|
+
prefix: (0, hash_sum_1.default)(json),
|
|
288
|
+
})
|
|
289
|
+
: null;
|
|
290
|
+
const styledComponentsCode = (options.stylesType === 'styled-components' &&
|
|
291
|
+
componentHasStyles &&
|
|
292
|
+
(0, collect_styled_components_1.collectStyledComponents)(json)) ||
|
|
293
|
+
'';
|
|
294
|
+
if (options.format !== 'lite') {
|
|
295
|
+
(0, strip_meta_properties_1.stripMetaProperties)(json);
|
|
296
|
+
}
|
|
297
|
+
const reactLibImports = new Set();
|
|
298
|
+
if (useStateCode.includes('useState')) {
|
|
299
|
+
reactLibImports.add('useState');
|
|
300
|
+
}
|
|
301
|
+
if ((0, context_1.hasContext)(json) && options.contextType !== 'prop-drill') {
|
|
302
|
+
reactLibImports.add('useContext');
|
|
303
|
+
}
|
|
304
|
+
const shouldAddUseClientDirective = checkShouldAddUseClientDirective(json, options);
|
|
305
|
+
const shouldInlineOnInitHook = !shouldAddUseClientDirective && options.rsc && isRSC(json, options);
|
|
306
|
+
if (allRefs.length || (((_a = json.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code) && !shouldInlineOnInitHook)) {
|
|
307
|
+
reactLibImports.add('useRef');
|
|
308
|
+
}
|
|
309
|
+
if (!options.preact && hasPropRef) {
|
|
310
|
+
reactLibImports.add('forwardRef');
|
|
311
|
+
}
|
|
312
|
+
if (json.hooks.onMount.length || ((_b = json.hooks.onUnMount) === null || _b === void 0 ? void 0 : _b.code) || ((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
313
|
+
reactLibImports.add('useEffect');
|
|
314
|
+
}
|
|
315
|
+
const hasCustomStyles = !!((_d = json.style) === null || _d === void 0 ? void 0 : _d.length);
|
|
316
|
+
const shouldInjectCustomStyles = hasCustomStyles &&
|
|
317
|
+
(options.stylesType === 'styled-components' || options.stylesType === 'emotion');
|
|
318
|
+
const wrap = (0, helpers_2.wrapInFragment)(json) ||
|
|
319
|
+
(0, is_root_text_node_1.isRootTextNode)(json) ||
|
|
320
|
+
(componentHasStyles &&
|
|
321
|
+
(options.stylesType === 'styled-jsx' || options.stylesType === 'style-tag')) ||
|
|
322
|
+
shouldInjectCustomStyles ||
|
|
323
|
+
isRootSpecialNode(json);
|
|
324
|
+
const [hasStateArgument, refsString] = getRefsString(json, allRefs, options);
|
|
325
|
+
// NOTE: `collectReactNativeStyles` must run before style generation in the component generation body, as it has
|
|
326
|
+
// side effects that delete styles bindings from the JSON.
|
|
327
|
+
const reactNativeStyles = options.stylesType === 'react-native' && componentHasStyles
|
|
328
|
+
? (0, react_native_1.collectReactNativeStyles)(json, options)
|
|
329
|
+
: undefined;
|
|
330
|
+
const propType = json.propsTypeRef || 'any';
|
|
331
|
+
const componentArgs = [`props${options.typescript ? `:${propType}` : ''}`, options.forwardRef]
|
|
332
|
+
.filter(Boolean)
|
|
333
|
+
.join(',');
|
|
334
|
+
const componentBody = (0, dedent_1.dedent) `
|
|
335
|
+
${options.contextType === 'prop-drill'
|
|
336
|
+
? `const ${exports.contextPropDrillingKey} = { ...props['${exports.contextPropDrillingKey}'] };`
|
|
337
|
+
: ''}
|
|
338
|
+
${hasStateArgument ? '' : refsString}
|
|
339
|
+
${(0, state_2.getReactVariantStateString)({ hasState, useStateCode, json, options })}
|
|
340
|
+
${hasStateArgument ? refsString : ''}
|
|
341
|
+
${getContextString(json, options)}
|
|
342
|
+
${((_e = json.hooks.init) === null || _e === void 0 ? void 0 : _e.code) ? (0, state_2.processHookCode)({ str: (_f = json.hooks.init) === null || _f === void 0 ? void 0 : _f.code, options }) : ''}
|
|
343
|
+
${contextStr || ''}
|
|
344
|
+
|
|
345
|
+
${(0, hooks_1.getOnInitHookComponentBody)({ shouldInlineOnInitHook, json, options })}
|
|
346
|
+
${(0, hooks_1.getOnEventHookComponentBody)(json)}
|
|
347
|
+
${(0, hooks_1.getOnMountComponentBody)({ json, options })}
|
|
348
|
+
${(0, hooks_1.getOnUpdateComponentBody)({ json, options })}
|
|
349
|
+
${(0, hooks_1.getOnUnMountComponentBody)({ json, options })}
|
|
350
|
+
|
|
351
|
+
return (
|
|
352
|
+
${wrap ? (0, helpers_2.openFrag)(options) : ''}
|
|
353
|
+
${generateStyleTags('top', json, options, componentHasStyles, css, shouldInjectCustomStyles)}
|
|
354
|
+
${json.children.map((item) => (0, blocks_1.blockToReact)(item, options, json, wrap, [])).join('\n')}
|
|
355
|
+
${generateStyleTags('bottom', json, options, componentHasStyles, css, shouldInjectCustomStyles)}
|
|
356
|
+
${wrap ? (0, helpers_2.closeFrag)(options) : ''}
|
|
357
|
+
);
|
|
358
|
+
`;
|
|
359
|
+
const str = (0, dedent_1.dedent) `
|
|
360
|
+
${shouldAddUseClientDirective ? `'use client';` : ''}
|
|
361
|
+
${(0, state_2.getDefaultImport)(options, json)}
|
|
362
|
+
${styledComponentsCode ? `import styled from 'styled-components';\n` : ''}
|
|
363
|
+
${reactLibImports.size
|
|
364
|
+
? `import { ${Array.from(reactLibImports).join(', ')} } from '${options.preact ? 'preact/hooks' : 'react'}'`
|
|
365
|
+
: ''}
|
|
366
|
+
${options.stylesType === 'twrnc' ? `import tw from 'twrnc';\n` : ''}
|
|
367
|
+
${componentHasStyles && options.stylesType === 'emotion' && options.format !== 'lite'
|
|
368
|
+
? `/** @jsx jsx */
|
|
369
|
+
import { jsx } from '@emotion/react'`.trim()
|
|
370
|
+
: ''}
|
|
371
|
+
${(0, state_2.getReactVariantStateImportString)(hasState, options)}
|
|
372
|
+
${json.types && options.typescript ? json.types.join('\n') : ''}
|
|
373
|
+
${(0, render_imports_1.renderPreComponent)({
|
|
374
|
+
explicitImportFileExtension: options.explicitImportFileExtension,
|
|
375
|
+
component: json,
|
|
376
|
+
target: options.type === 'native' ? 'reactNative' : 'react',
|
|
377
|
+
})}
|
|
378
|
+
${isForwardRef ? `const ${json.name} = forwardRef${forwardRefType}(` : ''}function ${json.name}(${componentArgs}) {
|
|
379
|
+
${(0, default_props_1.getDefaultProps)(json)}
|
|
380
|
+
${componentBody}
|
|
381
|
+
}${isForwardRef ? ')' : ''}
|
|
382
|
+
|
|
383
|
+
${reactNativeStyles && Object.keys(reactNativeStyles).length > 0
|
|
384
|
+
? `const styles = StyleSheet.create(${json5_1.default.stringify(reactNativeStyles)});`
|
|
385
|
+
: ''}
|
|
386
|
+
|
|
387
|
+
${styledComponentsCode !== null && styledComponentsCode !== void 0 ? styledComponentsCode : ''}
|
|
388
|
+
${isSubComponent
|
|
389
|
+
? ''
|
|
390
|
+
: options.stateType === 'mobx'
|
|
391
|
+
? `
|
|
392
|
+
const observed${json.name} = observer(${json.name});
|
|
393
|
+
export default observed${json.name};
|
|
394
|
+
`
|
|
395
|
+
: `export default ${json.name};`}
|
|
396
|
+
|
|
397
|
+
`;
|
|
398
|
+
return (0, replace_new_lines_in_strings_1.stripNewlinesInStrings)(str);
|
|
399
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultProps = void 0;
|
|
4
|
+
const getDefaultProps = (json) => {
|
|
5
|
+
if (!json.defaultProps)
|
|
6
|
+
return '';
|
|
7
|
+
const defaultPropsString = Object.keys(json.defaultProps)
|
|
8
|
+
.map((prop) => {
|
|
9
|
+
var _a;
|
|
10
|
+
const value = json.defaultProps.hasOwnProperty(prop)
|
|
11
|
+
? (_a = json.defaultProps[prop]) === null || _a === void 0 ? void 0 : _a.code
|
|
12
|
+
: 'undefined';
|
|
13
|
+
return `${prop}: ${value}`;
|
|
14
|
+
})
|
|
15
|
+
.join(',');
|
|
16
|
+
if (defaultPropsString) {
|
|
17
|
+
return `props = {${defaultPropsString}, ...props}`;
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
};
|
|
21
|
+
exports.getDefaultProps = getDefaultProps;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ToReactOptions } from '../../../generators/react';
|
|
2
|
+
import { MitosisComponent } from '../../../types/mitosis-component';
|
|
3
|
+
export declare const getOnInitHookComponentBody: ({ shouldInlineOnInitHook, options, json, }: {
|
|
4
|
+
json: MitosisComponent;
|
|
5
|
+
options: ToReactOptions;
|
|
6
|
+
shouldInlineOnInitHook?: boolean | undefined;
|
|
7
|
+
}) => string;
|
|
8
|
+
export declare const getOnEventHookComponentBody: (json: MitosisComponent) => string;
|
|
9
|
+
export declare const getOnMountComponentBody: ({ options, json, }: {
|
|
10
|
+
json: MitosisComponent;
|
|
11
|
+
options: ToReactOptions;
|
|
12
|
+
}) => string;
|
|
13
|
+
export declare const getOnUpdateComponentBody: ({ options, json, }: {
|
|
14
|
+
json: MitosisComponent;
|
|
15
|
+
options: ToReactOptions;
|
|
16
|
+
}) => string;
|
|
17
|
+
export declare const getOnUnMountComponentBody: ({ options, json, }: {
|
|
18
|
+
json: MitosisComponent;
|
|
19
|
+
options: ToReactOptions;
|
|
20
|
+
}) => string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOnUnMountComponentBody = exports.getOnUpdateComponentBody = exports.getOnMountComponentBody = exports.getOnEventHookComponentBody = exports.getOnInitHookComponentBody = void 0;
|
|
4
|
+
const state_1 = require("../../../generators/react/helpers/state");
|
|
5
|
+
const on_event_1 = require("../../../helpers/on-event");
|
|
6
|
+
const getOnInitHookComponentBody = ({ shouldInlineOnInitHook, options, json, }) => {
|
|
7
|
+
var _a;
|
|
8
|
+
return ((_a = json.hooks.onInit) === null || _a === void 0 ? void 0 : _a.code)
|
|
9
|
+
? shouldInlineOnInitHook
|
|
10
|
+
? (0, state_1.processHookCode)({ str: json.hooks.onInit.code, options })
|
|
11
|
+
: `
|
|
12
|
+
const hasInitialized = useRef(false);
|
|
13
|
+
if (!hasInitialized.current) {
|
|
14
|
+
${(0, state_1.processHookCode)({
|
|
15
|
+
str: json.hooks.onInit.code,
|
|
16
|
+
options,
|
|
17
|
+
})}
|
|
18
|
+
hasInitialized.current = true;
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
|
+
: '';
|
|
22
|
+
};
|
|
23
|
+
exports.getOnInitHookComponentBody = getOnInitHookComponentBody;
|
|
24
|
+
const getOnEventHookComponentBody = (json) => json.hooks.onEvent
|
|
25
|
+
.map((hook) => {
|
|
26
|
+
const eventName = `"${hook.eventName}"`;
|
|
27
|
+
const handlerName = (0, on_event_1.getOnEventHandlerName)(hook);
|
|
28
|
+
return `
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
${hook.refName}.current?.addEventListener(${eventName}, ${handlerName});
|
|
31
|
+
return () => ${hook.refName}.current?.removeEventListener(${eventName}, ${handlerName});
|
|
32
|
+
}, []);
|
|
33
|
+
`;
|
|
34
|
+
})
|
|
35
|
+
.join('\n');
|
|
36
|
+
exports.getOnEventHookComponentBody = getOnEventHookComponentBody;
|
|
37
|
+
const getOnMountComponentBody = ({ options, json, }) => json.hooks.onMount
|
|
38
|
+
.map((hook) => `useEffect(() => {
|
|
39
|
+
${(0, state_1.processHookCode)({
|
|
40
|
+
str: hook.code,
|
|
41
|
+
options,
|
|
42
|
+
})}
|
|
43
|
+
}, [])`)
|
|
44
|
+
.join('\n');
|
|
45
|
+
exports.getOnMountComponentBody = getOnMountComponentBody;
|
|
46
|
+
const getOnUpdateComponentBody = ({ options, json, }) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return (_b = (_a = json.hooks.onUpdate) === null || _a === void 0 ? void 0 : _a.map((hook) => `useEffect(() => {
|
|
49
|
+
${(0, state_1.processHookCode)({ str: hook.code, options })}
|
|
50
|
+
},
|
|
51
|
+
${hook.deps ? (0, state_1.processHookCode)({ str: hook.deps, options }) : ''})`).join(';')) !== null && _b !== void 0 ? _b : '';
|
|
52
|
+
};
|
|
53
|
+
exports.getOnUpdateComponentBody = getOnUpdateComponentBody;
|
|
54
|
+
const getOnUnMountComponentBody = ({ options, json, }) => {
|
|
55
|
+
var _a;
|
|
56
|
+
return ((_a = json.hooks.onUnMount) === null || _a === void 0 ? void 0 : _a.code)
|
|
57
|
+
? `useEffect(() => {
|
|
58
|
+
return () => {
|
|
59
|
+
${(0, state_1.processHookCode)({
|
|
60
|
+
str: json.hooks.onUnMount.code,
|
|
61
|
+
options,
|
|
62
|
+
})}
|
|
63
|
+
}
|
|
64
|
+
}, [])`
|
|
65
|
+
: '';
|
|
66
|
+
};
|
|
67
|
+
exports.getOnUnMountComponentBody = getOnUnMountComponentBody;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MitosisComponent } from '../../../types/mitosis-component';
|
|
2
|
+
import { MitosisNode } from '../../../types/mitosis-node';
|
|
3
|
+
import { ToReactOptions } from '../types';
|
|
4
|
+
export declare const processBinding: (str: string, options: ToReactOptions) => string;
|
|
5
|
+
export declare const openFrag: (options: ToReactOptions) => string;
|
|
6
|
+
export declare const closeFrag: (options: ToReactOptions) => string;
|
|
7
|
+
export declare const isFragmentWithKey: (node?: MitosisNode) => boolean;
|
|
8
|
+
export declare function getFragment(type: 'open' | 'close', options: ToReactOptions, node?: MitosisNode): string;
|
|
9
|
+
export declare const wrapInFragment: (json: MitosisComponent | MitosisNode) => boolean;
|
|
10
|
+
export declare function processTagReferences(json: MitosisComponent, options: ToReactOptions): void;
|
|
11
|
+
export declare const isReactForwardRef: (json: MitosisComponent) => string | undefined;
|
|
@@ -0,0 +1,97 @@
|
|
|
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.isReactForwardRef = exports.processTagReferences = exports.wrapInFragment = exports.getFragment = exports.isFragmentWithKey = exports.closeFrag = exports.openFrag = exports.processBinding = void 0;
|
|
7
|
+
const is_mitosis_node_1 = require("../../../helpers/is-mitosis-node");
|
|
8
|
+
const strip_state_and_props_refs_1 = require("../../../helpers/strip-state-and-props-refs");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
11
|
+
const processBinding = (str, options) => {
|
|
12
|
+
// fix web-component tag transform issue with dashes by not transforming it
|
|
13
|
+
if (options.stateType !== 'useState') {
|
|
14
|
+
return str;
|
|
15
|
+
}
|
|
16
|
+
return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(str, {
|
|
17
|
+
includeState: true,
|
|
18
|
+
includeProps: false,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.processBinding = processBinding;
|
|
22
|
+
const openFrag = (options) => getFragment('open', options);
|
|
23
|
+
exports.openFrag = openFrag;
|
|
24
|
+
const closeFrag = (options) => getFragment('close', options);
|
|
25
|
+
exports.closeFrag = closeFrag;
|
|
26
|
+
const isFragmentWithKey = (node) => (node === null || node === void 0 ? void 0 : node.name) === 'Fragment' && !!(node === null || node === void 0 ? void 0 : node.bindings['key']);
|
|
27
|
+
exports.isFragmentWithKey = isFragmentWithKey;
|
|
28
|
+
function getFragment(type, options, node) {
|
|
29
|
+
var _a;
|
|
30
|
+
let tag = '';
|
|
31
|
+
if (node && node.bindings && (0, exports.isFragmentWithKey)(node)) {
|
|
32
|
+
tag = options.preact ? 'Fragment' : 'React.Fragment';
|
|
33
|
+
const keyCode = (_a = node.bindings['key']) === null || _a === void 0 ? void 0 : _a.code;
|
|
34
|
+
if (type === 'open' && keyCode) {
|
|
35
|
+
tag += ` key={${(0, exports.processBinding)(keyCode, options)}}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (options.preact) {
|
|
39
|
+
tag = 'Fragment';
|
|
40
|
+
}
|
|
41
|
+
return type === 'open' ? `<${tag}>` : `</${tag}>`;
|
|
42
|
+
}
|
|
43
|
+
exports.getFragment = getFragment;
|
|
44
|
+
const wrapInFragment = (json) => json.children.length !== 1;
|
|
45
|
+
exports.wrapInFragment = wrapInFragment;
|
|
46
|
+
function getRefName(path) {
|
|
47
|
+
return (0, lodash_1.upperFirst)(path) + 'Ref';
|
|
48
|
+
}
|
|
49
|
+
function processTagReferences(json, options) {
|
|
50
|
+
const namesFound = new Set();
|
|
51
|
+
(0, legacy_1.default)(json).forEach((el) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (!(0, is_mitosis_node_1.isMitosisNode)(el)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const processedRefName = el.name.includes('-') ? el.name : (0, exports.processBinding)(el.name, options);
|
|
57
|
+
if (el.name.includes('state.')) {
|
|
58
|
+
switch ((_a = json.state[processedRefName]) === null || _a === void 0 ? void 0 : _a.type) {
|
|
59
|
+
case 'getter':
|
|
60
|
+
const refName = getRefName(processedRefName);
|
|
61
|
+
if (!namesFound.has(el.name)) {
|
|
62
|
+
namesFound.add(el.name);
|
|
63
|
+
json.hooks.init = {
|
|
64
|
+
...json.hooks.init,
|
|
65
|
+
code: `
|
|
66
|
+
${((_b = json.hooks.init) === null || _b === void 0 ? void 0 : _b.code) || ''}
|
|
67
|
+
const ${refName} = ${el.name};
|
|
68
|
+
`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
el.name = refName;
|
|
72
|
+
break;
|
|
73
|
+
// NOTE: technically, it should be impossible for the tag to be a method or a function in Mitosis JSX syntax,
|
|
74
|
+
// as that will fail JSX parsing.
|
|
75
|
+
case 'method':
|
|
76
|
+
case 'function':
|
|
77
|
+
case 'property':
|
|
78
|
+
const capitalizedName = (0, lodash_1.upperFirst)(processedRefName);
|
|
79
|
+
if (capitalizedName !== processedRefName) {
|
|
80
|
+
el.name = capitalizedName;
|
|
81
|
+
json.state[capitalizedName] = { ...json.state[processedRefName] };
|
|
82
|
+
delete json.state[processedRefName];
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
el.name = processedRefName;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
el.name = processedRefName;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
exports.processTagReferences = processTagReferences;
|
|
96
|
+
const isReactForwardRef = (json) => { var _a, _b, _c; return ((_a = json.meta.useMetadata) === null || _a === void 0 ? void 0 : _a.forwardRef) || ((_c = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.react) === null || _c === void 0 ? void 0 : _c.forwardRef); };
|
|
97
|
+
exports.isReactForwardRef = isReactForwardRef;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MitosisComponent } from '../../../types/mitosis-component';
|
|
2
|
+
import { ToReactOptions } from '../types';
|
|
3
|
+
export declare const processHookCode: ({ str, options }: {
|
|
4
|
+
str: string;
|
|
5
|
+
options: ToReactOptions;
|
|
6
|
+
}) => string;
|
|
7
|
+
export declare const getUseStateCode: (json: MitosisComponent, options: ToReactOptions) => string;
|
|
8
|
+
export declare const updateStateSetters: (json: MitosisComponent, options: ToReactOptions) => void;
|
|
9
|
+
export declare const updateStateSettersInCode: (value: string, options: ToReactOptions) => string;
|
|
10
|
+
export declare const getReactVariantStateImportString: (hasState: boolean, options: ToReactOptions) => "" | "import { useLocalProxy } from 'valtio/utils';" | "import { useMutable } from 'react-solid-state';" | "import { useLocalObservable, observer } from 'mobx-react-lite';";
|
|
11
|
+
export declare const getReactVariantStateString: ({ hasState, options, json, useStateCode, }: {
|
|
12
|
+
useStateCode: string;
|
|
13
|
+
hasState: boolean;
|
|
14
|
+
json: MitosisComponent;
|
|
15
|
+
options: ToReactOptions;
|
|
16
|
+
}) => string;
|
|
17
|
+
export declare const getDefaultImport: (options: ToReactOptions, json: MitosisComponent) => string;
|