setupHistoire.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. /* eslint-disable no-underscore-dangle */
  3. import initializeApp from '@mobile/initialize'
  4. import DynamicInitializer from '@shared/components/DynamicInitializer/DynamicInitializer.vue'
  5. import { defineSetupVue3 } from '@histoire/plugin-vue'
  6. import { createRouter, createWebHistory } from 'vue-router'
  7. import { h, createApp, type App } from 'vue'
  8. const root = typeof window !== 'undefined' && window.document.documentElement
  9. const initializeRouter = (app: App) => {
  10. // to avoid warning message
  11. delete app._context.components.RouterView
  12. delete app._context.components.RouterLink
  13. const router = createRouter({
  14. history: createWebHistory('/'),
  15. routes: [
  16. {
  17. path: '/:pathMatch(.*)*',
  18. component: {
  19. render() {
  20. return h('div')
  21. },
  22. },
  23. },
  24. ],
  25. })
  26. app.use(router)
  27. }
  28. const renderDynamics = () => {
  29. const dynamic = createApp({
  30. components: { DynamicInitializer },
  31. render() {
  32. return h(DynamicInitializer, {
  33. name: 'dialog',
  34. transition: {
  35. enterActiveClass: 'duration-300 ease-out',
  36. enterFromClass: 'opacity-0 translate-y-3/4',
  37. enterToClass: 'opacity-100 translate-y-0',
  38. leaveActiveClass: 'duration-200 ease-in',
  39. leaveFromClass: 'opacity-100 translate-y-0',
  40. leaveToClass: 'opacity-0 translate-y-3/4',
  41. },
  42. })
  43. },
  44. })
  45. initializeApp(dynamic)
  46. initializeRouter(dynamic)
  47. dynamic.mount('#dynamic')
  48. }
  49. if (root) {
  50. const getSandbox = () =>
  51. typeof document !== 'undefined' &&
  52. document.querySelector('#app > .__histoire-sandbox')
  53. const interval = setInterval(() => {
  54. const sandbox = getSandbox()
  55. if (sandbox) {
  56. clearInterval(interval)
  57. sandbox.classList.add('text-white')
  58. sandbox.classList.add('p-2')
  59. sandbox.classList.add('h-full')
  60. const dynamics = document.createElement('div')
  61. dynamics.setAttribute('id', 'dynamic')
  62. sandbox.appendChild(dynamics)
  63. renderDynamics()
  64. }
  65. if (typeof document === 'undefined') {
  66. clearInterval(interval)
  67. }
  68. }, 60)
  69. root.setAttribute('dir', 'ltr')
  70. }
  71. // let initialized = false
  72. export const setupVue3 = defineSetupVue3(({ app }) => {
  73. // if (initialized) return
  74. // initialized = true
  75. initializeApp(app)
  76. initializeRouter(app)
  77. })