yunohost-admin/app/src/main.js

111 lines
3 KiB
JavaScript
Raw Normal View History

import { createApp, configureCompat } from 'vue'
2020-07-06 19:08:34 +02:00
import App from './App.vue'
2020-08-29 19:05:56 +02:00
import BootstrapVue from 'bootstrap-vue'
2024-03-04 15:12:40 +01:00
import { VueShowdownPlugin } from 'vue-showdown'
2020-08-29 19:05:56 +02:00
import store from './store'
import router from './router'
import i18n from './i18n'
import { registerGlobalErrorHandlers } from './api'
import { initDefaultLocales } from './i18n/helpers'
const app = createApp({
...App,
})
app.use(store)
app.use(router)
app.use(i18n)
configureCompat({
MODE: 2,
// warnings we can do something about should be fixed
// next warnings are suppressed because those come from bootstrap-vue (vue2)
INSTANCE_EVENT_EMITTER: 'suppress-warning',
COMPONENT_FUNCTIONAL: 'suppress-warning',
RENDER_FUNCTION: 'suppress-warning',
GLOBAL_EXTEND: 'suppress-warning',
GLOBAL_MOUNT: 'suppress-warning',
WATCH_ARRAY: 'suppress-warning',
GLOBAL_PROTOTYPE: 'suppress-warning',
INSTANCE_SCOPED_SLOTS: 'suppress-warning',
INSTANCE_LISTENERS: 'suppress-warning',
OPTIONS_DATA_MERGE: 'suppress-warning',
OPTIONS_BEFORE_DESTROY: 'suppress-warning',
INSTANCE_ATTRS_CLASS_STYLE: 'suppress-warning',
CUSTOM_DIR: 'suppress-warning',
// TODO
// ATTR_FALSE_VALUE: 'suppress-warning',
// ATTR_ENUMERATED_COERCION
// ATTR_FALSE_VALUE
// COMPONENT_V_MODEL: 'suppress-warning',
// COMPILER_V_BIND_SYNC
})
2020-07-06 19:08:34 +02:00
2020-08-29 19:05:56 +02:00
// Styles are imported in `src/App.vue` <style>
app.use(BootstrapVue, {
BSkeleton: { animation: 'none' },
BAlert: { show: true },
2024-02-24 18:25:12 +01:00
BBadge: { pill: true },
})
2020-08-29 19:05:56 +02:00
2024-03-04 15:12:40 +01:00
app.use(VueShowdownPlugin, {
flavor: 'github',
2021-08-14 14:37:19 +02:00
options: {
2024-02-24 18:25:12 +01:00
emoji: true,
},
2021-08-14 14:37:19 +02:00
})
// Ugly wrapper for `$bvModal.msgBoxConfirm` to set default i18n button titles
// FIXME find or wait for a better way
app.config.globalProperties.$askConfirmation = function (message, props) {
return this.$bvModal.msgBoxConfirm(message, {
2021-03-17 15:35:01 +01:00
okTitle: this.$i18n.t('ok'),
cancelTitle: this.$i18n.t('cancel'),
bodyBgVariant: 'warning',
centered: true,
2024-02-24 18:25:12 +01:00
bodyClass: [
'font-weight-bold',
'rounded-top',
store.state.theme ? 'text-white' : 'text-black',
],
...props,
})
}
app.config.globalProperties.$askMdConfirmation = function (
markdown,
props,
ok = false,
) {
2022-11-23 16:18:16 +01:00
const content = this.$createElement('vue-showdown', {
2024-02-24 18:25:12 +01:00
props: { markdown, flavor: 'github', options: { headerLevelStart: 4 } },
2022-11-23 16:18:16 +01:00
})
return this.$bvModal['msgBox' + (ok ? 'Ok' : 'Confirm')](content, {
okTitle: this.$i18n.t('yes'),
cancelTitle: this.$i18n.t('cancel'),
headerBgVariant: 'warning',
headerClass: store.state.theme ? 'text-white' : 'text-black',
centered: true,
2024-02-24 18:25:12 +01:00
...props,
2022-11-23 16:18:16 +01:00
})
}
// Register global components
2024-02-24 18:25:12 +01:00
const globalComponentsModules = import.meta.glob(
['@/components/globals/*.vue', '@/components/globals/*/*.vue'],
{ eager: true },
)
Object.values(globalComponentsModules).forEach((module) => {
const component = module.default
app.component(component.name, component)
})
registerGlobalErrorHandlers()
// Load default locales translations files and setup store data
initDefaultLocales().then(() => {
app.mount('#app')
})