Path: blob/main/frontend/vue/wc-wrapper/platypusWrapper.ts
3367 views
import { createApp, h, Component, CreateAppFunction, App } from 'vue'12import { Step, StepComponent } from '@mathigon/studio'3import { HTMLBaseView } from '@mathigon/boost'4import * as i18nPlugin from '../../plugins/i18nStrings'5import * as segmentPlugin from '../../plugins/segmentAnalytics'6import wrapper from './index'78declare module '@vue/runtime-core' {9interface ComponentCustomProperties {10$step: Step;11$trackClickEvent: (cta: string, location: string) => void;12$trackPage: (title: string) => void;13$translate: (str: string, args?: string[]) => string14}15}1617interface ICustomElement extends HTMLElement {18_wrapper: App;19}2021const createAppWithPlugins: CreateAppFunction<Element> = (rootComponent: Component, rootProps?: Record<string, unknown> | null) => {22return createApp(rootComponent, rootProps)23.use(segmentPlugin)24.use(i18nPlugin)25}2627class VueWidgetView extends HTMLBaseView<ICustomElement> implements StepComponent {28setup ($step: Step /*, goal: string, initialData?: UserData | undefined */) {29const app = this._el._wrapper30app.config.globalProperties.$step = $step31}32}3334function connectedCallback (): void {35// @ts-ignore "this" is the CustomElement from wrapper function.36const self: ICustomElement = this3738// eslint-disable-next-line no-new39new VueWidgetView(self)40}4142export default function wrap (component: Component) {43return wrapper(component, createAppWithPlugins, h, { connectedCallback })44}454647