All files / ext.wikilambda.edit/components ZKeyModeSelector.vue

83.33% Statements 10/12
57.14% Branches 4/7
80% Functions 4/5
83.33% Lines 10/12

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                                                24x     24x                                                                     30x 1x   29x       29x         29x           3x   3x     250x                                        
<template>
	<!--
		WikiLambda Vue interface module for Key mode selection.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<select
		class="ext-wikilambda-zkey-modeselector"
		:value="mode"
		@change="updateMode"
	>
		<option
			v-for="modeItem in modes"
			:key="modeItem.key"
			:value="modeItem.key"
			:title="translate( modeItem.label )"
		>
			{{ translate( modeItem.value ) }}
		</option>
	</select>
</template>
 
<script>
var mapGetters = require( 'vuex' ).mapGetters;
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-key-mode-selector',
	inject: {
		allowArgRefMode: { default: false }
	},
	props: {
		mode: {
			type: String,
			required: true,
			validator: this.modeIsValid
		},
		parentType: {
			type: String,
			required: true
		},
		literalType: {
			type: String,
			required: false,
			default: ''
		},
		availableModes: {
			type: Array,
			default: null
		}
	},
	emits: [ 'change' ],
	computed: $.extend( {},
		mapGetters( {
			getAllModes: 'getAllModes',
			modeIsValid: 'getModeIsValid',
			getZarguments: 'getZarguments',
			isExpertMode: 'isExpertMode'
		} ),
		{
			modes: function () {
				if ( this.availableModes ) {
					return this.availableModes;
				} else {
					return this.availableModesWithCurrentType;
				}
			},
			availableModesWithCurrentType: function () {
				var payload = {
					parentType: this.parentType,
					literalType: this.literalType,
					allowZArgumentRefMode: this.allowArgRefMode && !!Object.keys( this.getZarguments ).length
				};
				return this.getAllModes( payload );
			}
		}
	),
	methods: {
		updateMode: function ( event ) {
			var modeValue = event.target.value;
 
			this.$emit( 'change', modeValue );
		},
		translate: function ( value ) {
			return this.$i18n( value ).text();
		}
	},
	watch: {
		isExpertMode: function () {
			Iif ( !this.isExpertMode && this.mode === 'json' ) {
				this.$emit( 'change', 'literal' );
			}
		}
	}
};
</script>
 
<style lang="less">
.ext-wikilambda-zkey-modeselector {
	height: 22px;
	vertical-align: top;
	margin-top: 5px;
}
</style>