setupHistoire.ts 2.3 KB

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