All files / ext.wikilambda.app/components App.vue

100% Statements 114/114
100% Branches 10/10
100% Functions 2/2
100% Lines 114/114

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 1151x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 2x 2x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue interface module for generic ZObject manipulation.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div id="ext-wikilambda-app" class="ext-wikilambda-app">
		<wl-clipboard-manager
			:class-names="[
				'ext-wikilambda-viewpage-header__zid',
				'ext-wikilambda-editpage-header__zid'
			]">
		</wl-clipboard-manager>
		<template v-if="isInitialized && isAppSetup">
			<!-- Append wl- prefix to the router current view, to help reference component correctly -->
			<component
				:is="`wl-${getCurrentView}`"
			></component>
		</template>
		<span v-else>
			{{ $i18n( 'wikilambda-loading' ).text() }}
		</span>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const { mapActions, mapGetters } = require( 'vuex' ),
	ClipboardManager = require( './base/ClipboardManager.vue' ),
	eventLogUtils = require( '../mixins/eventLogUtils.js' ),
	urlUtils = require( '../mixins/urlUtils.js' ),
	FunctionEvaluatorView = require( '../views/FunctionEvaluator.vue' ),
	FunctionEditorView = require( '../views/FunctionEditor.vue' ),
	FunctionViewerView = require( '../views/FunctionViewer.vue' ),
	DefaultView = require( '../views/Default.vue' );
 
module.exports = exports = defineComponent( {
	name: 'app',
	components: {
		'wl-function-evaluator-view': FunctionEvaluatorView,
		'wl-function-editor-view': FunctionEditorView,
		'wl-function-viewer-view': FunctionViewerView,
		'wl-default-view': DefaultView,
		'wl-clipboard-manager': ClipboardManager
	},
	mixins: [ eventLogUtils, urlUtils ],
	inject: {
		viewmode: { default: false }
	},
	data: function () {
		return {
			isAppSetup: false
		};
	},
	computed: Object.assign(
		mapGetters( [
			'isInitialized',
			'isCreateNewPage',
			'getCurrentView'
		] )
	),
	methods: Object.assign(
		mapActions( [
			'initializeView',
			'prefetchZids',
			'fetchUserRights',
			'evaluateUri'
		] )
	),
	created: function () {
		// Set zobject
		this.fetchUserRights();
		this.prefetchZids().then( () => {
			this.initializeView().then( () => {
				this.evaluateUri();
				this.isAppSetup = true;
			} );
		} );
 
		window.onpopstate = function ( event ) {
			/**
			 * Prevent reinitializing the view when there is a hash in the URL,
			 * this is most likely when using a a11y SkipLink.
			 */
			if ( window.location.hash && event.state === null ) {
				event.preventDefault();
				// Remove hash from url so it does not persist after navigation
				this.removeHashFromURL();
				return false;
			}
 
			// Reinitialize zObject if current page/zObject is new and user changes route
			if ( this.isCreateNewPage ) {
				this.initializeView().then(
					() => {
						this.evaluateUri();
					}
				);
				return;
			}
 
			this.evaluateUri();
		}.bind( this );
	}
} );
</script>
 
<style lang="less">
.ext-wikilambda-view-nojsfallback,
.ext-wikilambda-editor-nojswarning {
	display: none;
}
</style>