You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.0 KiB

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