app.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. 'use strict'
  2. /* global siteConfig */
  3. import CONSTANTS from './constants'
  4. import Vue from 'vue'
  5. import VueClipboards from 'vue-clipboards'
  6. import VeeValidate from 'vee-validate'
  7. import { ApolloClient } from 'apollo-client'
  8. import { ApolloLink } from 'apollo-link'
  9. import { createApolloFetch } from 'apollo-fetch'
  10. import { BatchHttpLink } from 'apollo-link-batch-http'
  11. import { InMemoryCache } from 'apollo-cache-inmemory'
  12. import { Vuetify, VApp, VBtn, VIcon, VList, VMenu, VSpeedDial, VTooltip } from 'vuetify'
  13. import Hammer from 'hammerjs'
  14. import store from './store'
  15. // ====================================
  16. // Load Modules
  17. // ====================================
  18. import boot from './modules/boot'
  19. import localization from './modules/localization'
  20. // ====================================
  21. // Load Helpers
  22. // ====================================
  23. import helpers from './helpers'
  24. // ====================================
  25. // Initialize Global Vars
  26. // ====================================
  27. window.wiki = null
  28. window.boot = boot
  29. window.CONSTANTS = CONSTANTS
  30. window.Hammer = Hammer
  31. // ====================================
  32. // Initialize Apollo Client (GraphQL)
  33. // ====================================
  34. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + siteConfig.path + 'graphql'
  35. const apolloFetch = createApolloFetch({
  36. uri: graphQLEndpoint,
  37. constructOptions: (requestOrRequests, options) => ({
  38. ...options,
  39. method: 'POST',
  40. body: JSON.stringify(requestOrRequests),
  41. credentials: 'include'
  42. })
  43. })
  44. window.graphQL = new ApolloClient({
  45. link: ApolloLink.from([
  46. new ApolloLink((operation, forward) => {
  47. operation.setContext({
  48. headers: {
  49. 'Content-Type': 'application/json'
  50. }
  51. })
  52. return forward(operation)
  53. }),
  54. new BatchHttpLink({
  55. fetch: apolloFetch
  56. })
  57. ]),
  58. cache: new InMemoryCache(),
  59. connectToDevTools: (process.env.node_env === 'development')
  60. })
  61. // ====================================
  62. // Initialize Vue Modules
  63. // ====================================
  64. Vue.use(VueClipboards)
  65. Vue.use(localization.VueI18Next)
  66. Vue.use(helpers)
  67. Vue.use(VeeValidate, {
  68. enableAutoClasses: true,
  69. classNames: {
  70. touched: 'is-touched', // the control has been blurred
  71. untouched: 'is-untouched', // the control hasn't been blurred
  72. valid: 'is-valid', // model is valid
  73. invalid: 'is-invalid', // model is invalid
  74. pristine: 'is-pristine', // control has not been interacted with
  75. dirty: 'is-dirty' // control has been interacted with
  76. }
  77. })
  78. Vue.use(Vuetify, {
  79. components: {
  80. VApp,
  81. VBtn,
  82. VIcon,
  83. VList,
  84. VMenu,
  85. VSpeedDial,
  86. VTooltip
  87. }
  88. })
  89. // ====================================
  90. // Register Vue Components
  91. // ====================================
  92. Vue.component('editor', () => import(/* webpackChunkName: "editor" */ './components/editor.vue'))
  93. Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
  94. Vue.component('navigator', () => import(/* webpackMode: "eager" */ './components/navigator.vue'))
  95. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  96. Vue.component('toggle', () => import(/* webpackMode: "eager" */ './components/toggle.vue'))
  97. let bootstrap = () => {
  98. // ====================================
  99. // Notifications
  100. // ====================================
  101. window.addEventListener('beforeunload', () => {
  102. store.dispatch('startLoading')
  103. })
  104. // ====================================
  105. // Bootstrap Vue
  106. // ====================================
  107. const i18n = localization.init()
  108. window.wiki = new Vue({
  109. el: '#app',
  110. components: {},
  111. mixins: [helpers],
  112. store,
  113. i18n
  114. })
  115. // ----------------------------------
  116. // Dispatch boot ready
  117. // ----------------------------------
  118. window.boot.notify('vue')
  119. // ====================================
  120. // Load Icons
  121. // ====================================
  122. import(/* webpackChunkName: "icons" */ '../svg/icons.svg').then(icons => {
  123. document.body.insertAdjacentHTML('beforeend', icons)
  124. })
  125. }
  126. window.boot.onDOMReady(bootstrap)