setupHistoire.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import './setupGlobals.ts'
  3. import initializeApp from '#mobile/initialize.ts'
  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-render-story')
  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. sandbox.classList.add('font-sans')
  61. sandbox.classList.add('text-sm')
  62. const dynamics = document.createElement('div')
  63. dynamics.setAttribute('id', 'dynamic')
  64. sandbox.appendChild(dynamics)
  65. renderDynamics()
  66. }
  67. if (typeof document === 'undefined') {
  68. clearInterval(interval)
  69. }
  70. }, 60)
  71. root.setAttribute('dir', 'ltr')
  72. }
  73. // let initialized = false
  74. export const setupVue3 = defineSetupVue3(({ app }) => {
  75. // if (initialized) return
  76. // initialized = true
  77. initializeApp(app)
  78. initializeRouter(app)
  79. })