| 1 | ( function () { |
| 2 | const Vue = require( '../../lib/vue/vue.js' ); |
| 3 | const errorLogger = require( './errorLogger.js' ); |
| 4 | const i18n = require( './i18n.js' ); |
| 5 | const teleportTarget = require( 'mediawiki.page.ready' ).teleportTarget; |
| 6 | |
| 7 | /** |
| 8 | * Additional functions and plugins added to the Vue object. |
| 9 | * |
| 10 | * For documentation on Vue's built-in functions, see |
| 11 | * {@link https://vuejs.org/api/ Vue's API reference}. |
| 12 | * |
| 13 | * @module vue |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Wrapper around {@link https://vuejs.org/api/application.html#createapp Vue.createApp} that |
| 18 | * adds the {@link module:vue#$i18n i18n plugin} and the error handler. These were added |
| 19 | * globally in Vue 2, but Vue 3 does not support global plugins. |
| 20 | * |
| 21 | * To ensure all Vue code has the i18n plugin and the error handler installed, use of |
| 22 | * `vue.createMwApp()` is recommended anywhere one would normally use `Vue.createApp()`. |
| 23 | * |
| 24 | * @method createMwApp |
| 25 | * @param {...any} args |
| 26 | * @return {Object} Vue app instance |
| 27 | * @memberof module:vue |
| 28 | */ |
| 29 | Vue.createMwApp = function ( ...args ) { |
| 30 | const app = Vue.createApp( ...args ); |
| 31 | app.use( errorLogger ); |
| 32 | app.use( i18n ); |
| 33 | app.provide( 'CdxTeleportTarget', teleportTarget ); |
| 34 | // Includes all messages with `cdx-` prefix in languages/i18n/codex. |
| 35 | app.provide( 'CdxI18nFunction', mw.msg ); |
| 36 | |
| 37 | return app; |
| 38 | }; |
| 39 | |
| 40 | // HACK: the global build of Vue that we're using assumes that Vue is globally available |
| 41 | // in eval()ed code, because it expects var Vue = ...; to run in the global scope |
| 42 | // Satisfy that assumption |
| 43 | window.Vue = Vue; |
| 44 | |
| 45 | module.exports = Vue; |
| 46 | }() ); |