app.js 4.0 KB

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