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

95.08% Statements 58/61
92.85% Branches 26/28
87.5% Functions 7/8
95.08% Lines 58/61

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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224                                                              17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x     17x                                                                                                         57x             607x     19x     607x                 607x           598x   32x   78x   14x   13x   19x     19x     21x   20x   7x   3x   32x     8x 7x   1x     5x   36x   11x       24x   6x   16x   18x   10x   12x   213x                               57x                            
<template>
	<!--
		WikiLambda Vue interface module for generic ZObject manipulation.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<div :class="classZObject">
		<!-- Depending on the type, it will render a different component -->
		<wl-z-object-selector
			v-if="type === Constants.Z_OBJECT"
			:type="Constants.Z_TYPE"
			:return-type="Constants.Z_TYPE"
			:placeholder="$i18n( 'wikilambda-argument-typeselector-label' ).text()"
			@input="changeZObjectType"
		></wl-z-object-selector>
 
		<component
			:is="determineComponent"
			v-else-if="type !== undefined"
			:zobject-id="zobjectId"
			:type="type"
			:persistent="persistent"
			:readonly="readonly"
			:parent-type="parentType"
			:search-type="referenceType"
		></component>
	</div>
</template>
 
<script>
var Constants = require( '../Constants.js' ),
	typeUtils = require( '../mixins/typeUtils.js' ),
	ZObjectGeneric = require( './ZObjectGeneric.vue' ),
	ZTypedList = require( './main-types/ZTypedList.vue' ),
	ZMultilingualString = require( './main-types/ZMultilingualString.vue' ),
	ZReference = require( './main-types/ZReference.vue' ),
	ZString = require( './main-types/ZString.vue' ),
	ZCode = require( './main-types/ZCode.vue' ),
	ZArgument = require( './main-types/ZArgument.vue' ),
	ZFunctionCall = require( './main-types/ZFunctionCall.vue' ),
	ZObjectSelector = require( './ZObjectSelector.vue' ),
	ZFunction = require( './main-types/ZFunction.vue' ),
	ZBoolean = require( './main-types/ZBoolean.vue' ),
	ZImplementation = require( './main-types/ZImplementation.vue' ),
	ZArgumentReference = require( './main-types/ZArgumentReference.vue' ),
	ZTester = require( './main-types/ZTester.vue' ),
	ZPersistentObject = require( './main-types/ZPersistentObject.vue' ),
	ZCharacter = require( './main-types/ZCharacter.vue' ),
	ZResponseEnvelope = require( './main-types/ZResponseEnvelope.vue' ),
	ZType = require( './main-types/ZType.vue' ),
	ZTypedPair = require( './main-types/ZTypedPair.vue' ),
	ZTypedMap = require( './main-types/ZTypedMap.vue' ),
	ZFunctionCallToType = require( './main-types/ZFunctionCallToType.vue' ),
	ZKey = require( './main-types/ZKey.vue' ),
	mapActions = require( 'vuex' ).mapActions,
	mapGetters = require( 'vuex' ).mapGetters;
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-object',
	components: {
		'wl-z-multilingual-string': ZMultilingualString,
		'wl-z-reference': ZReference,
		'wl-z-string': ZString,
		'wl-z-object-generic': ZObjectGeneric,
		'wl-z-code': ZCode,
		'wl-z-argument': ZArgument,
		'wl-z-function-call': ZFunctionCall,
		'wl-z-object-selector': ZObjectSelector,
		'wl-z-function': ZFunction,
		'wl-z-boolean': ZBoolean,
		'wl-z-implementation': ZImplementation,
		'wl-z-argument-reference': ZArgumentReference,
		'wl-z-tester': ZTester,
		'wl-z-persistentobject': ZPersistentObject,
		'wl-z-character': ZCharacter,
		'wl-z-responseenvelope': ZResponseEnvelope,
		'wl-z-type': ZType,
		'wl-z-typed-list': ZTypedList,
		'wl-z-typed-pair': ZTypedPair,
		'wl-z-typed-map': ZTypedMap,
		'wl-z-function-call-to-type': ZFunctionCallToType,
		'wl-z-key': ZKey
	},
	mixins: [ typeUtils ],
	props: {
		zobjectId: {
			type: Number,
			required: false,
			default: 0
		},
		persistent: {
			type: Boolean,
			required: true
		},
		readonly: {
			type: Boolean,
			default: false
		},
		parentType: {
			type: String,
			required: false,
			default: ''
		},
		referenceType: {
			type: String,
			required: false,
			default: null
		}
	},
	data: function () {
		return {
			Constants: Constants
		};
	},
	computed: $.extend( mapGetters( [ 'getZObjectById', 'getZObjectTypeById' ] ),
		{
			type: function () {
				return this.getZObjectTypeById( this.zobjectId );
			},
			zObject: function () {
				return this.getZObjectById( this.zobjectId );
			},
			isInlineComponent: function () {
				return [
					Constants.Z_STRING,
					Constants.Z_REFERENCE,
					Constants.Z_BOOLEAN,
					Constants.Z_ARGUMENT_REFERENCE,
					Constants.Z_CHARACTER
				].indexOf( this.type ) !== -1;
			},
			classZObject: function () {
				return {
					'ext-wikilambda-zobject': true,
					'ext-wikilambda-zobject-inline': this.isInlineComponent
				};
			},
			determineComponent: function () {
				switch ( this.type ) {
					case Constants.Z_PERSISTENTOBJECT:
						return 'wl-z-persistentobject';
					case Constants.Z_STRING:
						return 'wl-z-string';
					case Constants.Z_REFERENCE:
						return 'wl-z-reference';
					case Constants.Z_MULTILINGUALSTRING:
						return 'wl-z-multilingual-string';
					case Constants.Z_TYPED_LIST:
						Iif ( this.zObject && this.zObject.value === 'array' ) {
							return 'wl-z-typed-list';
						} else {
							return 'wl-z-object-generic';
						}
					case Constants.Z_TYPED_PAIR:
						return 'wl-z-typed-pair';
					case Constants.Z_TYPED_MAP:
						return 'wl-z-typed-map';
					case Constants.Z_CODE:
						return 'wl-z-code';
					case Constants.Z_ARGUMENT:
						return 'wl-z-argument';
					case Constants.Z_FUNCTION_CALL:
						return 'wl-z-function-call';
					case Constants.Z_FUNCTION:
						// Prevent rendering the ZFunction component is not the root element
						if ( this.parentType === Constants.Z_PERSISTENTOBJECT ) {
							return 'wl-z-function';
						} else {
							return 'wl-z-object-generic';
						}
					case Constants.Z_BOOLEAN:
						return 'wl-z-boolean';
					case Constants.Z_IMPLEMENTATION:
						return 'wl-z-implementation';
					case Constants.Z_ARGUMENT_REFERENCE:
						return 'wl-z-argument-reference';
					case Constants.Z_NOTHING:
						return 'wl-z-nothing';
					case Constants.Z_TESTER:
						return 'wl-z-tester';
					case Constants.Z_CHARACTER:
						return 'wl-z-character';
					case Constants.Z_RESPONSEENVELOPE:
						return 'wl-z-responseenvelope';
					case Constants.Z_TYPE:
						return 'wl-z-type';
					case Constants.Z_FUNCTION_CALL_TO_TYPE:
						return 'wl-z-function-call-to-type';
					case Constants.Z_KEY:
						return 'wl-z-key';
					default:
						return 'wl-z-object-generic';
				}
			}
		} ),
	methods: $.extend( {},
		mapActions( [ 'fetchZKeys', 'changeType' ] ),
		{
			changeZObjectType: function ( zid ) {
				this.changeType( {
					id: this.zobjectId,
					type: zid
				} );
			}
		}
	),
	mounted: function () {
		this.fetchZKeys( { zids: [ this.type ] } );
	}
};
</script>
 
<style lang="less">
.ext-wikilambda-zobject {
	display: block;
 
	.ext-wikilambda-zobject-inline {
		display: inline-block;
	}
}
</style>