@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,876 @@
|
|
|
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.componentToBuilder = exports.blockToBuilder = exports.builderBlockPrefixes = void 0;
|
|
7
|
+
const media_sizes_1 = require("../../constants/media-sizes");
|
|
8
|
+
const dedent_1 = require("../../helpers/dedent");
|
|
9
|
+
const fast_clone_1 = require("../../helpers/fast-clone");
|
|
10
|
+
const filter_empty_text_nodes_1 = require("../../helpers/filter-empty-text-nodes");
|
|
11
|
+
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
|
|
12
|
+
const has_props_1 = require("../../helpers/has-props");
|
|
13
|
+
const is_component_1 = require("../../helpers/is-component");
|
|
14
|
+
const is_mitosis_node_1 = require("../../helpers/is-mitosis-node");
|
|
15
|
+
const is_upper_case_1 = require("../../helpers/is-upper-case");
|
|
16
|
+
const parsers_1 = require("../../helpers/parsers");
|
|
17
|
+
const remove_surrounding_block_1 = require("../../helpers/remove-surrounding-block");
|
|
18
|
+
const replace_identifiers_1 = require("../../helpers/replace-identifiers");
|
|
19
|
+
const state_1 = require("../../helpers/state");
|
|
20
|
+
const builder_1 = require("../../parsers/builder");
|
|
21
|
+
const symbol_processor_1 = require("../../symbols/symbol-processor");
|
|
22
|
+
const mitosis_node_1 = require("../../types/mitosis-node");
|
|
23
|
+
const core_1 = require("@babel/core");
|
|
24
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
25
|
+
const parser_1 = require("@babel/parser");
|
|
26
|
+
const json5_1 = __importDefault(require("json5"));
|
|
27
|
+
const lodash_1 = require("lodash");
|
|
28
|
+
const legacy_1 = __importDefault(require("neotraverse/legacy"));
|
|
29
|
+
const standalone_1 = require("prettier/standalone");
|
|
30
|
+
const on_mount_1 = require("../helpers/on-mount");
|
|
31
|
+
const isValidCollection = (code) => {
|
|
32
|
+
if (!code || typeof code !== 'string') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// Pattern: Array.from({ length: number })
|
|
36
|
+
// Examples: "Array.from({ length: 10 })", "Array.from({ length: 5 })"
|
|
37
|
+
const arrayFromPattern = /^Array\.from\(\{\s*length\s*:\s*\d+\s*\}\)$/;
|
|
38
|
+
if (arrayFromPattern.test(code)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// Pattern: alphanumeric strings separated by dots
|
|
42
|
+
// Examples: "abc.def", "state.list1", "data.items"
|
|
43
|
+
const dotPattern = /^[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*$/;
|
|
44
|
+
return dotPattern.test(code);
|
|
45
|
+
};
|
|
46
|
+
const replaceWithStateVariable = (code, stateMap) => {
|
|
47
|
+
if (!code) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
if (stateMap === null || stateMap === void 0 ? void 0 : stateMap.has(code)) {
|
|
51
|
+
return 'state.' + (stateMap.get(code) || '');
|
|
52
|
+
}
|
|
53
|
+
return code;
|
|
54
|
+
};
|
|
55
|
+
const generateUniqueKey = (state) => {
|
|
56
|
+
let newKeyPrefix = 'dataBuilderList';
|
|
57
|
+
let counter = 1;
|
|
58
|
+
while (state[newKeyPrefix + counter]) {
|
|
59
|
+
counter++;
|
|
60
|
+
}
|
|
61
|
+
return newKeyPrefix + counter;
|
|
62
|
+
};
|
|
63
|
+
const convertMitosisStateToBuilderState = (state) => {
|
|
64
|
+
return Object.entries(state).reduce((acc, [key, value]) => {
|
|
65
|
+
if ((value === null || value === void 0 ? void 0 : value.type) === 'property' && (value === null || value === void 0 ? void 0 : value.code)) {
|
|
66
|
+
if (value.code === 'true' || value.code === 'false') {
|
|
67
|
+
acc[key] = value.code === 'true';
|
|
68
|
+
}
|
|
69
|
+
else if (value.code === 'null') {
|
|
70
|
+
acc[key] = null;
|
|
71
|
+
}
|
|
72
|
+
else if (value.code === 'undefined') {
|
|
73
|
+
acc[key] = undefined;
|
|
74
|
+
}
|
|
75
|
+
else if (!Number.isNaN(Number(value.code))) {
|
|
76
|
+
acc[key] = Number(value.code);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
try {
|
|
80
|
+
acc[key] = JSON.parse(value.code);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
acc[key] = value.code;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return acc;
|
|
88
|
+
}, {});
|
|
89
|
+
};
|
|
90
|
+
const findStateWithinMitosisNode = (node, options, state, stateMap) => {
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
if ((0, mitosis_node_1.checkIsForNode)(node)) {
|
|
93
|
+
if (!isValidCollection((_a = node.bindings.each) === null || _a === void 0 ? void 0 : _a.code) &&
|
|
94
|
+
!stateMap.has((_b = node.bindings.each) === null || _b === void 0 ? void 0 : _b.code)) {
|
|
95
|
+
const newKey = generateUniqueKey(state);
|
|
96
|
+
const code = (_c = node.bindings.each) === null || _c === void 0 ? void 0 : _c.code;
|
|
97
|
+
try {
|
|
98
|
+
state[newKey] = JSON.parse(code);
|
|
99
|
+
stateMap.set(code, newKey);
|
|
100
|
+
}
|
|
101
|
+
catch (parseError) {
|
|
102
|
+
// The parsing error happens when `code` is a function or expression
|
|
103
|
+
// We would need `eval` to parse the code and then set the state. But because
|
|
104
|
+
// of security concerns we are not handling this case right now.
|
|
105
|
+
// Will revisit this if we need to support this.
|
|
106
|
+
console.log('Failed to parse:', code, parseError);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
node.children.forEach((child) => findStateWithinMitosisNode(child, options, state, stateMap));
|
|
111
|
+
};
|
|
112
|
+
const findStateWithinMitosisComponent = (component, options, state, stateMap) => {
|
|
113
|
+
component.children.forEach((child) => findStateWithinMitosisNode(child, options, state, stateMap));
|
|
114
|
+
return state;
|
|
115
|
+
};
|
|
116
|
+
const omitMetaProperties = (obj) => (0, lodash_1.omitBy)(obj, (_value, key) => key.startsWith('$'));
|
|
117
|
+
exports.builderBlockPrefixes = ['Amp', 'Core', 'Builder', 'Raw', 'Form'];
|
|
118
|
+
const mapComponentName = (name, properties) => {
|
|
119
|
+
if (properties === null || properties === void 0 ? void 0 : properties['data-builder-originalName']) {
|
|
120
|
+
return properties['data-builder-originalName'];
|
|
121
|
+
}
|
|
122
|
+
if (name === 'CustomCode') {
|
|
123
|
+
return 'Custom Code';
|
|
124
|
+
}
|
|
125
|
+
for (const prefix of exports.builderBlockPrefixes) {
|
|
126
|
+
if (name.startsWith(prefix)) {
|
|
127
|
+
const suffix = name.replace(prefix, '');
|
|
128
|
+
const restOfName = suffix[0];
|
|
129
|
+
if (restOfName && (0, is_upper_case_1.isUpperCase)(restOfName)) {
|
|
130
|
+
return `${prefix}:${name.replace(prefix, '')}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return name;
|
|
135
|
+
};
|
|
136
|
+
const componentMappers = {
|
|
137
|
+
// TODO: add back if this direction (blocks as children not prop) is desired
|
|
138
|
+
...(!builder_1.symbolBlocksAsChildren
|
|
139
|
+
? {}
|
|
140
|
+
: {
|
|
141
|
+
Symbol(node, options) {
|
|
142
|
+
const child = node.children[0];
|
|
143
|
+
const symbolOptions = (node.bindings.symbol && json5_1.default.parse(node.bindings.symbol.code)) || {};
|
|
144
|
+
if (child) {
|
|
145
|
+
(0, lodash_1.set)(symbolOptions, 'content.data.blocks', child.children.map((item) => (0, exports.blockToBuilder)(item, options)));
|
|
146
|
+
}
|
|
147
|
+
return el({
|
|
148
|
+
component: {
|
|
149
|
+
name: 'Symbol',
|
|
150
|
+
options: {
|
|
151
|
+
// TODO: forward other symbol options
|
|
152
|
+
symbol: symbolOptions,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
}, options);
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
Columns(node, options) {
|
|
159
|
+
const block = (0, exports.blockToBuilder)(node, options, { skipMapper: true });
|
|
160
|
+
const columns = block.children.map((item) => {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
return ({
|
|
163
|
+
blocks: item.children,
|
|
164
|
+
width: (_b = (_a = item.component) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.width,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
block.component.options.columns = columns;
|
|
168
|
+
block.children = [];
|
|
169
|
+
return block;
|
|
170
|
+
},
|
|
171
|
+
Fragment(node, options) {
|
|
172
|
+
const block = (0, exports.blockToBuilder)(node, options, { skipMapper: true });
|
|
173
|
+
block.component = { name: 'Core:Fragment' };
|
|
174
|
+
block.tagName = undefined;
|
|
175
|
+
return block;
|
|
176
|
+
},
|
|
177
|
+
PersonalizationContainer(node, options) {
|
|
178
|
+
const block = (0, exports.blockToBuilder)(node, options, { skipMapper: true });
|
|
179
|
+
const variants = [];
|
|
180
|
+
let defaultVariant = [];
|
|
181
|
+
const validFakeNodeNames = [
|
|
182
|
+
'Variant',
|
|
183
|
+
'PersonalizationOption',
|
|
184
|
+
'PersonalizationVariant',
|
|
185
|
+
'Personalization',
|
|
186
|
+
];
|
|
187
|
+
block.children.forEach((item) => {
|
|
188
|
+
var _a;
|
|
189
|
+
if (item.component && validFakeNodeNames.includes((_a = item.component) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
190
|
+
let query;
|
|
191
|
+
if (item.component.options.query) {
|
|
192
|
+
const optionsQuery = item.component.options.query;
|
|
193
|
+
if (Array.isArray(optionsQuery)) {
|
|
194
|
+
query = optionsQuery.map((q) => ({
|
|
195
|
+
'@type': '@builder.io/core:Query',
|
|
196
|
+
...q,
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
query = [
|
|
201
|
+
{
|
|
202
|
+
'@type': '@builder.io/core:Query',
|
|
203
|
+
...optionsQuery,
|
|
204
|
+
},
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
const newVariant = {
|
|
208
|
+
...item.component.options,
|
|
209
|
+
query,
|
|
210
|
+
blocks: item.children,
|
|
211
|
+
};
|
|
212
|
+
variants.push(newVariant);
|
|
213
|
+
}
|
|
214
|
+
else if (item.children) {
|
|
215
|
+
defaultVariant.push(...item.children);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
defaultVariant.push(item);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
delete block.properties;
|
|
223
|
+
delete block.bindings;
|
|
224
|
+
block.component.options.variants = variants;
|
|
225
|
+
block.children = defaultVariant;
|
|
226
|
+
return block;
|
|
227
|
+
},
|
|
228
|
+
For(_node, options) {
|
|
229
|
+
var _a, _b, _c;
|
|
230
|
+
const node = _node;
|
|
231
|
+
const stateMap = options.stateMap;
|
|
232
|
+
const replaceIndexNode = (str) => (0, replace_identifiers_1.replaceNodes)({
|
|
233
|
+
code: str,
|
|
234
|
+
nodeMaps: [
|
|
235
|
+
{
|
|
236
|
+
from: core_1.types.identifier(target),
|
|
237
|
+
to: core_1.types.memberExpression(core_1.types.identifier('state'), core_1.types.identifier('$index')),
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
});
|
|
241
|
+
// rename `index` var to `state.$index`
|
|
242
|
+
const target = node.scope.indexName || 'index';
|
|
243
|
+
const replaceIndex = (node) => {
|
|
244
|
+
(0, legacy_1.default)(node).forEach(function (thing) {
|
|
245
|
+
if (!(0, is_mitosis_node_1.isMitosisNode)(thing))
|
|
246
|
+
return;
|
|
247
|
+
for (const [key, value] of Object.entries(thing.bindings)) {
|
|
248
|
+
if (!value)
|
|
249
|
+
continue;
|
|
250
|
+
if (!value.code.includes(target))
|
|
251
|
+
continue;
|
|
252
|
+
if (value.type === 'single' && value.bindingType === 'function') {
|
|
253
|
+
try {
|
|
254
|
+
const code = value.code;
|
|
255
|
+
const programNode = (0, parsers_1.parseCodeToAst)(code);
|
|
256
|
+
if (!programNode)
|
|
257
|
+
continue;
|
|
258
|
+
(0, core_1.traverse)(programNode, {
|
|
259
|
+
Program(path) {
|
|
260
|
+
if (path.scope.hasBinding(target))
|
|
261
|
+
return;
|
|
262
|
+
const x = {
|
|
263
|
+
id: core_1.types.identifier(target),
|
|
264
|
+
init: core_1.types.identifier('PLACEHOLDER'),
|
|
265
|
+
};
|
|
266
|
+
path.scope.push(x);
|
|
267
|
+
path.scope.rename(target, 'state.$index');
|
|
268
|
+
path.traverse({
|
|
269
|
+
VariableDeclaration(p) {
|
|
270
|
+
if (p.node.declarations.length === 1 && p.node.declarations[0].id === x.id) {
|
|
271
|
+
p.remove();
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
thing.bindings[key].code = (0, generator_1.default)(programNode).code;
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
console.error('Error processing function binding. Falling back to simple replacement.', error);
|
|
281
|
+
thing.bindings[key].code = replaceIndexNode(value.code);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
thing.bindings[key].code = replaceIndexNode(value.code);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
return node;
|
|
290
|
+
};
|
|
291
|
+
return el({
|
|
292
|
+
component: {
|
|
293
|
+
name: 'Core:Fragment',
|
|
294
|
+
},
|
|
295
|
+
repeat: {
|
|
296
|
+
collection: isValidCollection((_a = node.bindings.each) === null || _a === void 0 ? void 0 : _a.code)
|
|
297
|
+
? ((_b = node.bindings.each) === null || _b === void 0 ? void 0 : _b.code) || ''
|
|
298
|
+
: replaceWithStateVariable((_c = node.bindings.each) === null || _c === void 0 ? void 0 : _c.code, stateMap),
|
|
299
|
+
itemName: node.scope.forName,
|
|
300
|
+
},
|
|
301
|
+
children: node.children
|
|
302
|
+
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
303
|
+
.map((node) => (0, exports.blockToBuilder)(replaceIndex(node), options)),
|
|
304
|
+
}, options);
|
|
305
|
+
},
|
|
306
|
+
Show(node, options) {
|
|
307
|
+
var _a, _b, _c;
|
|
308
|
+
const elseCase = node.meta.else;
|
|
309
|
+
const children = node.children.filter(filter_empty_text_nodes_1.filterEmptyTextNodes);
|
|
310
|
+
const showNode = children.length > 0
|
|
311
|
+
? el({
|
|
312
|
+
// TODO: the reverse mapping for this
|
|
313
|
+
component: {
|
|
314
|
+
name: 'Core:Fragment',
|
|
315
|
+
},
|
|
316
|
+
bindings: {
|
|
317
|
+
show: (_a = node.bindings.when) === null || _a === void 0 ? void 0 : _a.code,
|
|
318
|
+
},
|
|
319
|
+
children: children.map((node) => (0, exports.blockToBuilder)(node, options)),
|
|
320
|
+
}, options)
|
|
321
|
+
: undefined;
|
|
322
|
+
const elseNode = elseCase && (0, filter_empty_text_nodes_1.filterEmptyTextNodes)(elseCase)
|
|
323
|
+
? el({
|
|
324
|
+
// TODO: the reverse mapping for this
|
|
325
|
+
component: {
|
|
326
|
+
name: 'Core:Fragment',
|
|
327
|
+
},
|
|
328
|
+
bindings: {
|
|
329
|
+
hide: (_b = node.bindings.when) === null || _b === void 0 ? void 0 : _b.code,
|
|
330
|
+
},
|
|
331
|
+
children: [(0, exports.blockToBuilder)(elseCase, options)],
|
|
332
|
+
}, options)
|
|
333
|
+
: undefined;
|
|
334
|
+
if (elseNode && showNode) {
|
|
335
|
+
return el({
|
|
336
|
+
component: {
|
|
337
|
+
name: 'Core:Fragment',
|
|
338
|
+
},
|
|
339
|
+
children: [showNode, elseNode],
|
|
340
|
+
}, options);
|
|
341
|
+
}
|
|
342
|
+
else if (showNode) {
|
|
343
|
+
return showNode;
|
|
344
|
+
}
|
|
345
|
+
else if (elseNode) {
|
|
346
|
+
return elseNode;
|
|
347
|
+
}
|
|
348
|
+
return el({
|
|
349
|
+
// TODO: the reverse mapping for this
|
|
350
|
+
component: {
|
|
351
|
+
name: 'Core:Fragment',
|
|
352
|
+
},
|
|
353
|
+
bindings: {
|
|
354
|
+
show: (_c = node.bindings.when) === null || _c === void 0 ? void 0 : _c.code,
|
|
355
|
+
},
|
|
356
|
+
children: [],
|
|
357
|
+
}, options);
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
const el = (options, toBuilderOptions) => ({
|
|
361
|
+
'@type': '@builder.io/sdk:Element',
|
|
362
|
+
...(toBuilderOptions.includeIds && {
|
|
363
|
+
id: 'builder-' + (0, symbol_processor_1.hashCodeAsString)(options),
|
|
364
|
+
}),
|
|
365
|
+
...options,
|
|
366
|
+
});
|
|
367
|
+
function tryFormat(code) {
|
|
368
|
+
let str = code;
|
|
369
|
+
try {
|
|
370
|
+
str = (0, standalone_1.format)(str, {
|
|
371
|
+
parser: 'babel',
|
|
372
|
+
plugins: [
|
|
373
|
+
require('prettier/parser-babel'), // To support running in browsers
|
|
374
|
+
],
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
console.error('Format error for code:', str);
|
|
379
|
+
throw err;
|
|
380
|
+
}
|
|
381
|
+
return str;
|
|
382
|
+
}
|
|
383
|
+
const processLocalizedValues = (element, node) => {
|
|
384
|
+
if (node.localizedValues) {
|
|
385
|
+
for (const [path, value] of Object.entries(node.localizedValues)) {
|
|
386
|
+
(0, lodash_1.set)(element, path, value);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return element;
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Turns a stringified object into an object that can be looped over.
|
|
393
|
+
* Since values in the stringified object could be JS expressions, all
|
|
394
|
+
* values in the resulting object will remain strings.
|
|
395
|
+
* @param input - The stringified object
|
|
396
|
+
*/
|
|
397
|
+
const parseJSObject = (input) => {
|
|
398
|
+
var _a;
|
|
399
|
+
const unparsed = [];
|
|
400
|
+
let parsed = {};
|
|
401
|
+
try {
|
|
402
|
+
const ast = (0, parser_1.parseExpression)(`(${input})`, {
|
|
403
|
+
plugins: ['jsx', 'typescript'],
|
|
404
|
+
sourceType: 'module',
|
|
405
|
+
});
|
|
406
|
+
if (ast.type !== 'ObjectExpression') {
|
|
407
|
+
return { parsed, unparsed: input };
|
|
408
|
+
}
|
|
409
|
+
for (const prop of ast.properties) {
|
|
410
|
+
/**
|
|
411
|
+
* If the object includes spread or method, we stop. We can't really break the component into Key/Value
|
|
412
|
+
* and the whole expression is considered dynamic. We return `false` to signify that.
|
|
413
|
+
*/
|
|
414
|
+
if (prop.type === 'ObjectMethod' || prop.type === 'SpreadElement') {
|
|
415
|
+
if (!!prop.start && !!prop.end) {
|
|
416
|
+
if (typeof input === 'string') {
|
|
417
|
+
unparsed.push(input.slice(prop.start - 1, prop.end - 1));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Ignore shorthand objects when processing incomplete objects. Otherwise we may
|
|
424
|
+
* create identifiers unintentionally.
|
|
425
|
+
* Example: When accounting for shorthand objects, "{ color" would become
|
|
426
|
+
* { color: color } thus creating a "color" identifier that does not exist.
|
|
427
|
+
*/
|
|
428
|
+
if (prop.type === 'ObjectProperty') {
|
|
429
|
+
if ((_a = prop.extra) === null || _a === void 0 ? void 0 : _a.shorthand) {
|
|
430
|
+
if (typeof input === 'string') {
|
|
431
|
+
unparsed.push(input.slice(prop.start - 1, prop.end - 1));
|
|
432
|
+
}
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
let key = '';
|
|
436
|
+
if (prop.key.type === 'Identifier') {
|
|
437
|
+
key = prop.key.name;
|
|
438
|
+
}
|
|
439
|
+
else if (prop.key.type === 'StringLiteral') {
|
|
440
|
+
key = prop.key.value;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (typeof input === 'string') {
|
|
446
|
+
const [val, err] = extractValue(input, prop.value);
|
|
447
|
+
if (err === null) {
|
|
448
|
+
parsed[key] = val;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
parsed,
|
|
455
|
+
unparsed: unparsed.length > 0 ? `{${unparsed.join('\n')}}` : undefined,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
return {
|
|
460
|
+
parsed,
|
|
461
|
+
unparsed: unparsed.length > 0 ? `{${unparsed.join('\n')}}` : undefined,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const extractValue = (input, node) => {
|
|
466
|
+
var _a, _b;
|
|
467
|
+
const start = (_a = node === null || node === void 0 ? void 0 : node.loc) === null || _a === void 0 ? void 0 : _a.start;
|
|
468
|
+
const end = (_b = node === null || node === void 0 ? void 0 : node.loc) === null || _b === void 0 ? void 0 : _b.end;
|
|
469
|
+
const startIndex = start !== undefined && 'index' in start && typeof start['index'] === 'number'
|
|
470
|
+
? start['index']
|
|
471
|
+
: undefined;
|
|
472
|
+
const endIndex = end !== undefined && 'index' in end && typeof end['index'] === 'number'
|
|
473
|
+
? end['index']
|
|
474
|
+
: undefined;
|
|
475
|
+
if (startIndex === undefined || endIndex === undefined || node === null) {
|
|
476
|
+
const err = `bad value: ${node}`;
|
|
477
|
+
return [null, err];
|
|
478
|
+
}
|
|
479
|
+
const value = input.slice(startIndex - 1, endIndex - 1);
|
|
480
|
+
return [value, null];
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Maps and styles that are bound with dynamic values onto their respective
|
|
484
|
+
* binding keys for Builder elements. This function also maps media queries
|
|
485
|
+
* with dynamic values.
|
|
486
|
+
* @param - bindings - The bindings object that has your styles. This param
|
|
487
|
+
* will be modified in-place, and the old "style" key will be removed.
|
|
488
|
+
*/
|
|
489
|
+
const mapBoundStyles = (bindings) => {
|
|
490
|
+
const styles = bindings['style'];
|
|
491
|
+
if (!styles) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const { parsed, unparsed } = parseJSObject(styles.code);
|
|
495
|
+
for (const key in parsed) {
|
|
496
|
+
const mediaQueryMatch = key.match(media_sizes_1.mediaQueryRegex);
|
|
497
|
+
if (mediaQueryMatch) {
|
|
498
|
+
const { parsed: mParsed } = parseJSObject(parsed[key]);
|
|
499
|
+
const [_, pixelSize] = mediaQueryMatch;
|
|
500
|
+
const size = media_sizes_1.sizes.getSizeForWidth(Number(pixelSize));
|
|
501
|
+
for (const mKey in mParsed) {
|
|
502
|
+
bindings[`responsiveStyles.${size}.${mKey}`] = {
|
|
503
|
+
code: mParsed[mKey],
|
|
504
|
+
bindingType: 'expression',
|
|
505
|
+
type: 'single',
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
if (isGlobalStyle(key)) {
|
|
511
|
+
console.warn(`The following bound styles are not supported by Builder JSON and have been removed:
|
|
512
|
+
"${key}": ${parsed[key]}
|
|
513
|
+
`);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
bindings[`style.${key}`] = {
|
|
517
|
+
code: parsed[key],
|
|
518
|
+
bindingType: 'expression',
|
|
519
|
+
type: 'single',
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
delete bindings['style'];
|
|
525
|
+
// unparsed data could be something else such as a function call
|
|
526
|
+
if (unparsed) {
|
|
527
|
+
try {
|
|
528
|
+
const ast = (0, parser_1.parseExpression)(`(${unparsed})`, {
|
|
529
|
+
plugins: ['jsx', 'typescript'],
|
|
530
|
+
sourceType: 'module',
|
|
531
|
+
});
|
|
532
|
+
// style={state.getStyles()}
|
|
533
|
+
if (ast.type === 'CallExpression') {
|
|
534
|
+
bindings['style'] = {
|
|
535
|
+
code: unparsed,
|
|
536
|
+
bindingType: 'expression',
|
|
537
|
+
type: 'single',
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
throw 'unsupported style';
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
catch (_a) {
|
|
545
|
+
console.warn(`The following bound styles are invalid and have been removed: ${unparsed}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
function isGlobalStyle(key) {
|
|
550
|
+
// These are mapped to their respective responsiveStyle and support bindings
|
|
551
|
+
if (/max-width: (.*?)px/gm.exec(key)) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
return (
|
|
555
|
+
// pseudo class
|
|
556
|
+
key.startsWith('&:') ||
|
|
557
|
+
key.startsWith(':') ||
|
|
558
|
+
// @ rules
|
|
559
|
+
key.startsWith('@'));
|
|
560
|
+
}
|
|
561
|
+
const blockToBuilder = (json, options = {}, _internalOptions = {}) => {
|
|
562
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
563
|
+
const mapper = !_internalOptions.skipMapper && componentMappers[json.name];
|
|
564
|
+
if (mapper) {
|
|
565
|
+
const element = mapper(json, options);
|
|
566
|
+
return processLocalizedValues(element, json);
|
|
567
|
+
}
|
|
568
|
+
const symbolBinding = json.bindings.symbol;
|
|
569
|
+
if (symbolBinding === null || symbolBinding === void 0 ? void 0 : symbolBinding.code) {
|
|
570
|
+
const isExplicitUserSymbol = json.type === 'user-symbol';
|
|
571
|
+
let hasValidSymbolMetadata = false;
|
|
572
|
+
if (!isExplicitUserSymbol) {
|
|
573
|
+
const parsed = (0, lodash_1.attempt)(() => json5_1.default.parse(symbolBinding.code));
|
|
574
|
+
hasValidSymbolMetadata =
|
|
575
|
+
!(parsed instanceof Error) &&
|
|
576
|
+
parsed &&
|
|
577
|
+
typeof parsed === 'object' &&
|
|
578
|
+
(parsed.entry || parsed.model === 'symbol');
|
|
579
|
+
}
|
|
580
|
+
if (isExplicitUserSymbol || hasValidSymbolMetadata) {
|
|
581
|
+
const symbolOptions = (0, lodash_1.attempt)(() => json5_1.default.parse(symbolBinding.code));
|
|
582
|
+
if (!(symbolOptions instanceof Error)) {
|
|
583
|
+
if (!symbolOptions.name) {
|
|
584
|
+
const displayName = json.name
|
|
585
|
+
.replace(/^Symbol/, '')
|
|
586
|
+
.replace(/([A-Z])/g, ' $1')
|
|
587
|
+
.trim();
|
|
588
|
+
if (displayName) {
|
|
589
|
+
symbolOptions.name = displayName;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
const inputData = {};
|
|
593
|
+
for (const key of Object.keys(json.bindings)) {
|
|
594
|
+
if (key !== 'symbol' && key !== 'css' && key !== 'style') {
|
|
595
|
+
const value = (0, lodash_1.attempt)(() => json5_1.default.parse(json.bindings[key].code));
|
|
596
|
+
if (!(value instanceof Error)) {
|
|
597
|
+
inputData[key] = value;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
for (const key of Object.keys(json.properties)) {
|
|
602
|
+
if (!key.startsWith('$') && !key.startsWith('_') && !key.startsWith('data-')) {
|
|
603
|
+
inputData[key] = json.properties[key];
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (Object.keys(inputData).length > 0) {
|
|
607
|
+
symbolOptions.data = { ...symbolOptions.data, ...inputData };
|
|
608
|
+
}
|
|
609
|
+
const element = el({
|
|
610
|
+
component: {
|
|
611
|
+
name: 'Symbol',
|
|
612
|
+
options: {
|
|
613
|
+
symbol: symbolOptions,
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
}, options);
|
|
617
|
+
return processLocalizedValues(element, json);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (json.properties._text || ((_a = json.bindings._text) === null || _a === void 0 ? void 0 : _a.code)) {
|
|
622
|
+
const element = el({
|
|
623
|
+
tagName: 'span',
|
|
624
|
+
bindings: {
|
|
625
|
+
...(((_b = json.bindings._text) === null || _b === void 0 ? void 0 : _b.code)
|
|
626
|
+
? {
|
|
627
|
+
'component.options.text': json.bindings._text.code,
|
|
628
|
+
'json.bindings._text.code': undefined,
|
|
629
|
+
}
|
|
630
|
+
: {}),
|
|
631
|
+
},
|
|
632
|
+
component: {
|
|
633
|
+
name: 'Text',
|
|
634
|
+
options: {
|
|
635
|
+
// Mitosis uses {} for bindings, but Builder expects {{}} so we need to convert
|
|
636
|
+
text: (_c = json.properties._text) === null || _c === void 0 ? void 0 : _c.replace(/\{(.*?)\}/g, '{{$1}}'),
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
}, options);
|
|
640
|
+
return processLocalizedValues(element, json);
|
|
641
|
+
}
|
|
642
|
+
const thisIsComponent = (0, is_component_1.isComponent)(json);
|
|
643
|
+
let bindings = json.bindings;
|
|
644
|
+
const actions = {};
|
|
645
|
+
for (const key in bindings) {
|
|
646
|
+
const eventBindingKeyRegex = /^on([A-Z])/;
|
|
647
|
+
const firstCharMatchForEventBindingKey = (_d = key.match(eventBindingKeyRegex)) === null || _d === void 0 ? void 0 : _d[1];
|
|
648
|
+
if (firstCharMatchForEventBindingKey) {
|
|
649
|
+
let actionBody = ((_e = bindings[key]) === null || _e === void 0 ? void 0 : _e.async)
|
|
650
|
+
? `(async () => ${(_f = bindings[key]) === null || _f === void 0 ? void 0 : _f.code})()`
|
|
651
|
+
: (0, remove_surrounding_block_1.removeSurroundingBlock)((_g = bindings[key]) === null || _g === void 0 ? void 0 : _g.code);
|
|
652
|
+
const eventIdentifier = (_j = (_h = bindings[key]) === null || _h === void 0 ? void 0 : _h.arguments) === null || _j === void 0 ? void 0 : _j[0];
|
|
653
|
+
if (typeof eventIdentifier === 'string' && eventIdentifier !== 'event') {
|
|
654
|
+
actionBody = (0, replace_identifiers_1.replaceNodes)({
|
|
655
|
+
code: actionBody,
|
|
656
|
+
nodeMaps: [{ from: core_1.types.identifier(eventIdentifier), to: core_1.types.identifier('event') }],
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
actions[key.replace(eventBindingKeyRegex, firstCharMatchForEventBindingKey.toLowerCase())] =
|
|
660
|
+
actionBody;
|
|
661
|
+
delete bindings[key];
|
|
662
|
+
}
|
|
663
|
+
if (key === 'style') {
|
|
664
|
+
mapBoundStyles(bindings);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
const builderBindings = {};
|
|
668
|
+
const componentOptions = omitMetaProperties(json.properties);
|
|
669
|
+
if (thisIsComponent) {
|
|
670
|
+
for (const key in bindings) {
|
|
671
|
+
if (key === 'css') {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const value = bindings[key];
|
|
675
|
+
const parsed = (0, lodash_1.attempt)(() => json5_1.default.parse(value === null || value === void 0 ? void 0 : value.code));
|
|
676
|
+
if (!(parsed instanceof Error)) {
|
|
677
|
+
componentOptions[key] = parsed;
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
if (!((_k = json.slots) === null || _k === void 0 ? void 0 : _k[key])) {
|
|
681
|
+
builderBindings[`component.options.${key}`] = bindings[key].code;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
for (const key in json.slots) {
|
|
687
|
+
componentOptions[key] = json.slots[key].map((node) => (0, exports.blockToBuilder)(node, options));
|
|
688
|
+
}
|
|
689
|
+
for (const key in json.blocksSlots) {
|
|
690
|
+
const value = json.blocksSlots[key];
|
|
691
|
+
(0, legacy_1.default)(value).forEach(function (v) {
|
|
692
|
+
if ((0, is_mitosis_node_1.isMitosisNode)(v)) {
|
|
693
|
+
this.update((0, exports.blockToBuilder)(v, options, _internalOptions));
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
componentOptions[key] = value;
|
|
697
|
+
}
|
|
698
|
+
const hasCss = !!((_l = bindings.css) === null || _l === void 0 ? void 0 : _l.code);
|
|
699
|
+
let responsiveStyles = {
|
|
700
|
+
large: {},
|
|
701
|
+
};
|
|
702
|
+
if (hasCss) {
|
|
703
|
+
const cssRules = json5_1.default.parse((_m = bindings.css) === null || _m === void 0 ? void 0 : _m.code);
|
|
704
|
+
const cssRuleKeys = Object.keys(cssRules);
|
|
705
|
+
for (const ruleKey of cssRuleKeys) {
|
|
706
|
+
const mediaQueryMatch = ruleKey.match(media_sizes_1.mediaQueryRegex);
|
|
707
|
+
if (mediaQueryMatch) {
|
|
708
|
+
const [fullmatch, pixelSize] = mediaQueryMatch;
|
|
709
|
+
const sizeForWidth = media_sizes_1.sizes.getSizeForWidth(Number(pixelSize));
|
|
710
|
+
const currentSizeStyles = responsiveStyles[sizeForWidth] || {};
|
|
711
|
+
responsiveStyles[sizeForWidth] = {
|
|
712
|
+
...currentSizeStyles,
|
|
713
|
+
...cssRules[ruleKey],
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
responsiveStyles.large = {
|
|
718
|
+
...responsiveStyles.large,
|
|
719
|
+
[ruleKey]: cssRules[ruleKey],
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
delete json.bindings.css;
|
|
724
|
+
}
|
|
725
|
+
const element = el({
|
|
726
|
+
tagName: thisIsComponent ? undefined : json.name,
|
|
727
|
+
...(hasCss && {
|
|
728
|
+
responsiveStyles,
|
|
729
|
+
}),
|
|
730
|
+
layerName: json.properties.$name,
|
|
731
|
+
...(json.properties['data-builder-layerLocked'] !== undefined && {
|
|
732
|
+
layerLocked: json.properties['data-builder-layerLocked'] === 'true',
|
|
733
|
+
}),
|
|
734
|
+
...(json.properties['data-builder-groupLocked'] !== undefined && {
|
|
735
|
+
groupLocked: json.properties['data-builder-groupLocked'] === 'true',
|
|
736
|
+
}),
|
|
737
|
+
...(thisIsComponent && {
|
|
738
|
+
component: {
|
|
739
|
+
name: mapComponentName(json.name, json.properties),
|
|
740
|
+
options: (0, lodash_1.omit)(componentOptions, ['data-builder-originalName']),
|
|
741
|
+
},
|
|
742
|
+
}),
|
|
743
|
+
code: {
|
|
744
|
+
bindings: builderBindings,
|
|
745
|
+
actions,
|
|
746
|
+
},
|
|
747
|
+
properties: thisIsComponent ? undefined : omitMetaProperties(json.properties),
|
|
748
|
+
bindings: thisIsComponent
|
|
749
|
+
? builderBindings
|
|
750
|
+
: (0, lodash_1.omit)((0, lodash_1.mapValues)(bindings, (value) => value === null || value === void 0 ? void 0 : value.code), 'css'),
|
|
751
|
+
actions,
|
|
752
|
+
children: json.children
|
|
753
|
+
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
754
|
+
.map((child) => (0, exports.blockToBuilder)(child, options)),
|
|
755
|
+
}, options);
|
|
756
|
+
return processLocalizedValues(element, json);
|
|
757
|
+
};
|
|
758
|
+
exports.blockToBuilder = blockToBuilder;
|
|
759
|
+
const recursivelyCheckForChildrenWithSameComponent = (elementOrContent, componentName, path = '') => {
|
|
760
|
+
var _a, _b, _c, _d, _e;
|
|
761
|
+
if ((0, builder_1.isBuilderElement)(elementOrContent)) {
|
|
762
|
+
if (((_a = elementOrContent.component) === null || _a === void 0 ? void 0 : _a.name) === componentName) {
|
|
763
|
+
return path;
|
|
764
|
+
}
|
|
765
|
+
return (((_b = elementOrContent.children) === null || _b === void 0 ? void 0 : _b.map((child, index) => recursivelyCheckForChildrenWithSameComponent(child, componentName, `${path}.children[${index}]`)).find(Boolean)) || '');
|
|
766
|
+
}
|
|
767
|
+
if ((_c = elementOrContent.data) === null || _c === void 0 ? void 0 : _c.blocks) {
|
|
768
|
+
return (((_e = (_d = elementOrContent.data) === null || _d === void 0 ? void 0 : _d.blocks) === null || _e === void 0 ? void 0 : _e.map((block, index) => recursivelyCheckForChildrenWithSameComponent(block, componentName, `${path ? `${path}.` : ''}data.blocks[${index}]`)).find(Boolean)) || '');
|
|
769
|
+
}
|
|
770
|
+
return '';
|
|
771
|
+
};
|
|
772
|
+
function removeItem(obj, path, indexToRemove) {
|
|
773
|
+
return (0, lodash_1.set)((0, lodash_1.cloneDeep)(obj), // Clone to ensure immutability
|
|
774
|
+
path, (0, lodash_1.filter)((0, lodash_1.get)(obj, path), (item, index) => index !== indexToRemove));
|
|
775
|
+
}
|
|
776
|
+
const componentToBuilder = (options = {}) => ({ component }) => {
|
|
777
|
+
var _a, _b, _c;
|
|
778
|
+
const hasState = (0, state_1.checkHasState)(component);
|
|
779
|
+
if (!options.stateMap) {
|
|
780
|
+
options.stateMap = new Map();
|
|
781
|
+
}
|
|
782
|
+
const result = (0, fast_clone_1.fastClone)({
|
|
783
|
+
data: {
|
|
784
|
+
httpRequests: (_b = (_a = component === null || component === void 0 ? void 0 : component.meta) === null || _a === void 0 ? void 0 : _a.useMetadata) === null || _b === void 0 ? void 0 : _b.httpRequests,
|
|
785
|
+
jsCode: tryFormat((0, dedent_1.dedent) `
|
|
786
|
+
${!(0, has_props_1.hasProps)(component) ? '' : `var props = state;`}
|
|
787
|
+
|
|
788
|
+
${!hasState ? '' : `Object.assign(state, ${(0, get_state_object_string_1.getStateObjectStringFromComponent)(component)});`}
|
|
789
|
+
|
|
790
|
+
${(0, on_mount_1.stringifySingleScopeOnMount)(component)}
|
|
791
|
+
`),
|
|
792
|
+
tsCode: tryFormat((0, dedent_1.dedent) `
|
|
793
|
+
${!(0, has_props_1.hasProps)(component) ? '' : `var props = state;`}
|
|
794
|
+
|
|
795
|
+
${!hasState ? '' : `useStore(${(0, get_state_object_string_1.getStateObjectStringFromComponent)(component)});`}
|
|
796
|
+
|
|
797
|
+
${!component.hooks.onMount.length
|
|
798
|
+
? ''
|
|
799
|
+
: `onMount(() => {
|
|
800
|
+
${(0, on_mount_1.stringifySingleScopeOnMount)(component)}
|
|
801
|
+
})`}
|
|
802
|
+
`),
|
|
803
|
+
cssCode: component === null || component === void 0 ? void 0 : component.style,
|
|
804
|
+
...(() => {
|
|
805
|
+
const stateData = findStateWithinMitosisComponent(component, options, { ...convertMitosisStateToBuilderState(component.state) }, options.stateMap);
|
|
806
|
+
return { state: stateData };
|
|
807
|
+
})(),
|
|
808
|
+
blocks: component.children
|
|
809
|
+
.filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
|
|
810
|
+
.map((child) => (0, exports.blockToBuilder)(child, options)),
|
|
811
|
+
},
|
|
812
|
+
});
|
|
813
|
+
if (((_c = result.data) === null || _c === void 0 ? void 0 : _c.state) && Object.keys(result.data.state).length === 0) {
|
|
814
|
+
delete result.data.state;
|
|
815
|
+
}
|
|
816
|
+
const subComponentMap = {};
|
|
817
|
+
for (const subComponent of component.subComponents) {
|
|
818
|
+
const name = subComponent.name;
|
|
819
|
+
subComponentMap[name] = (0, exports.componentToBuilder)(options)({
|
|
820
|
+
component: subComponent,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
(0, legacy_1.default)([result, subComponentMap]).forEach(function (el) {
|
|
824
|
+
var _a, _b, _c, _d, _e;
|
|
825
|
+
if ((0, builder_1.isBuilderElement)(el) && !((_a = el.meta) === null || _a === void 0 ? void 0 : _a.preventRecursion)) {
|
|
826
|
+
const value = subComponentMap[(_b = el.component) === null || _b === void 0 ? void 0 : _b.name];
|
|
827
|
+
if (value) {
|
|
828
|
+
// Recursive Components are handled in the following steps :
|
|
829
|
+
// 1. Find out the path in which the component is self-referenced ( where that component reoccurs within it’s tree ).
|
|
830
|
+
// 2. We populate that component recursively for 4 times in a row.
|
|
831
|
+
// 3. Finally remove the recursive part from the last component which was populated.
|
|
832
|
+
// Also note that it doesn’t mean that component will render that many times, the rendering logic depends on the logic in it's parent. (Eg. show property binding)
|
|
833
|
+
const path = recursivelyCheckForChildrenWithSameComponent(value, (_c = el.component) === null || _c === void 0 ? void 0 : _c.name);
|
|
834
|
+
if (path) {
|
|
835
|
+
let tempElement = el;
|
|
836
|
+
for (let i = 0; i < 4; i++) {
|
|
837
|
+
const tempValue = (0, lodash_1.cloneDeep)(value);
|
|
838
|
+
(0, lodash_1.set)(tempElement, 'component.options.symbol.content', tempValue);
|
|
839
|
+
(0, lodash_1.set)(tempElement, 'meta.preventRecursion', true);
|
|
840
|
+
tempElement = (0, lodash_1.get)(tempValue, path);
|
|
841
|
+
}
|
|
842
|
+
// Finally remove the recursive part.
|
|
843
|
+
const arrayPath = path.replace(/\[\d+\]$/, '');
|
|
844
|
+
const newValue = removeItem(value, arrayPath, Number((_d = path.match(/\[(\d+)\]$/)) === null || _d === void 0 ? void 0 : _d[1]));
|
|
845
|
+
(0, lodash_1.set)(tempElement, 'component.options.symbol.content', newValue);
|
|
846
|
+
(0, lodash_1.set)(tempElement, 'meta.preventRecursion', true);
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
(0, lodash_1.set)(el, 'component.options.symbol.content', value);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
if (el.bindings) {
|
|
853
|
+
for (const [key, value] of Object.entries(el.bindings)) {
|
|
854
|
+
if (value.match(/\n|;/)) {
|
|
855
|
+
if (!el.code) {
|
|
856
|
+
el.code = {};
|
|
857
|
+
}
|
|
858
|
+
if (!el.code.bindings) {
|
|
859
|
+
el.code.bindings = {};
|
|
860
|
+
}
|
|
861
|
+
el.code.bindings[key] = value;
|
|
862
|
+
el.bindings[key] = ` return ${value}`;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if ((0, builder_1.isBuilderElement)(el) && ((_e = el.meta) === null || _e === void 0 ? void 0 : _e.preventRecursion)) {
|
|
868
|
+
delete el.meta.preventRecursion;
|
|
869
|
+
if (el.meta && Object.keys(el.meta).length === 0) {
|
|
870
|
+
delete el.meta;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
return result;
|
|
875
|
+
};
|
|
876
|
+
exports.componentToBuilder = componentToBuilder;
|