diff --git a/resources/js/bootstrap.js b/resources/js/bootstrap.js index 24b959fde8..9621dcf5fd 100644 --- a/resources/js/bootstrap.js +++ b/resources/js/bootstrap.js @@ -19,6 +19,7 @@ import MonacoEditor from "vue-monaco"; import Vue from "vue"; import * as vue from "vue"; import VueCookies from "vue-cookies"; +import GlobalStore from "./globalStore"; import Pagination from "./components/common/Pagination"; import ScreenSelect from "./processes/modeler/components/inspector/ScreenSelect.vue"; import translator from "./modules/lang.js"; @@ -75,6 +76,7 @@ window.bootstrap = bootstrap; window.Vue.use(BootstrapVue); window.Vue.use(BootstrapVueIcons); window.Vue.use(ScreenBuilder); +window.Vue.use(GlobalStore); window.Vue.use(VueDeepSet); window.Vue.use(VueCookies); if (!document.head.querySelector("meta[name=\"is-horizon\"]")) { diff --git a/resources/js/globalStore/index.js b/resources/js/globalStore/index.js new file mode 100644 index 0000000000..ec9a7c0bbf --- /dev/null +++ b/resources/js/globalStore/index.js @@ -0,0 +1,33 @@ +import Vuex from "vuex"; + +export default { + install(Vue) { + const globalStore = new Vuex.Store({ + modules: { }, + }); + + Vue.globalStore = globalStore; + + Vue.mixin({ + beforeCreate() { + const options = this.$options; + + if (options.globalStore) { + this.$globalStore = typeof options.globalStore === "function" + ? options.globalStore() + : options.globalStore; + + return; + } + + if (options?.parent?.$globalStore) { + this.$globalStore = options.parent.$globalStore; + + return; + } + + this.$globalStore = globalStore; + }, + }); + }, +};