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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | 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 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 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 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 23x 42x 42x 42x 42x 42x 42x 42x 42x 42x 7x 7x 7x 42x 42x 42x 42x 42x 1x 1x 42x 42x 42x 42x 42x 42x 42x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 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 1x 1x 1x 1x 1x 1x | <!--
WikiLambda Vue component for an individual input to be set for a ZFunction in the Function editor.
@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
@license MIT
-->
<template>
<div class="ext-wikilambda-app-function-editor-inputs-item" data-testid="input-list-item">
<!-- Per-input label -->
<div class="ext-wikilambda-app-function-editor-inputs-item__header">
<span class="ext-wikilambda-app-function-editor-inputs-item__label">
{{ inputFieldLabel }}
</span>
<cdx-button
v-if="canEditType"
weight="quiet"
class="ext-wikilambda-app-function-editor-inputs-item__action-delete"
:aria-label="i18n( 'wikilambda-function-definition-inputs-item-remove' ).text()"
data-testid="remove-input"
@click="removeInput"
>
<cdx-icon
:icon="iconTrash"
class="ext-wikilambda-app-function-editor-inputs-item__icon-trash"></cdx-icon>
</cdx-button>
</div>
<!-- Input fields -->
<div class="ext-wikilambda-app-function-editor-inputs-item__body">
<!-- Label field: always active -->
<cdx-field
class="ext-wikilambda-app-function-editor-inputs-item__field"
data-testid="function-editor-input-item-label"
>
<template #label>
{{ i18n( 'wikilambda-function-definition-input-item-label' ).text() }}
</template>
<cdx-text-input
:lang="input ? langLabelData.langCode : undefined"
:dir="input ? langLabelData.langDir : undefined"
:model-value="input ? input.value : ''"
:placeholder="i18n( 'wikilambda-function-definition-inputs-item-input-placeholder' ).text()"
:aria-label="i18n( 'wikilambda-function-definition-inputs-item-input-placeholder' ).text()"
:maxlength="maxInputLabelChars"
@input="updateRemainingChars"
@change="persistInputLabel"
></cdx-text-input>
<div class="ext-wikilambda-app-function-editor-inputs-item__counter">
{{ remainingChars }}
</div>
</cdx-field>
<!-- Type field: only first block -->
<wl-type-selector
v-if="isMainLanguageBlock && input"
class="ext-wikilambda-app-function-editor-inputs-item__field"
data-testid="function-editor-input-item-type"
:key-path="input.typeKeyPath"
:object-value="input.type"
:label-data="inputTypeLabel"
:disabled="!canEditType"
:placeholder="i18n( 'wikilambda-function-definition-inputs-item-selector-placeholder' ).text()"
></wl-type-selector>
</div>
</div>
</template>
<script>
const { computed, defineComponent, inject, onMounted, ref } = require( 'vue' );
const Constants = require( '../../../Constants.js' );
const icons = require( './../../../../lib/icons.json' );
const LabelData = require( '../../../store/classes/LabelData.js' );
const useMainStore = require( '../../../store/index.js' );
// Base components
const TypeSelector = require( '../../base/TypeSelector.vue' );
// Codex components
const { CdxButton, CdxField, CdxIcon, CdxTextInput } = require( '../../../../codex.js' );
module.exports = exports = defineComponent( {
name: 'wl-function-editor-inputs-item',
components: {
'wl-type-selector': TypeSelector,
'cdx-button': CdxButton,
'cdx-field': CdxField,
'cdx-icon': CdxIcon,
'cdx-text-input': CdxTextInput
},
props: {
/**
* Input data with key, type and label for the given language
*/
input: {
type: Object,
required: true
},
/**
* Index for this input in the list of inputs (zero-lead, excluding benjamin item)
*/
index: {
type: Number,
required: true
},
/**
* If this input is in the main language block
*/
isMainLanguageBlock: {
type: Boolean,
required: true
},
/**
* if user has permissions to edit the input type
*/
canEditType: {
type: Boolean,
required: true
},
/**
* zID of item label language
*
* @example Z1014
*/
zLanguage: {
type: String,
required: true
},
/**
* Label data for the language
*/
langLabelData: {
type: LabelData,
default: null
}
},
emits: [ 'argument-label-updated', 'remove' ],
setup( props, { emit } ) {
const i18n = inject( 'i18n' );
const store = useMainStore();
// Constants
const iconTrash = icons.cdxIconTrash;
const maxInputLabelChars = Constants.INPUT_CHARS_MAX;
// State
const remainingChars = ref( Constants.INPUT_CHARS_MAX );
// Input display
/**
* Returns the label and index for the current input.
* If not active, returns label, index and selected type.
*
* @return {string}
*/
const inputFieldLabel = computed( () => {
const inputNumber = props.index + 1;
return i18n( 'wikilambda-function-viewer-details-input-number', inputNumber ).text();
} );
/**
* Returns the title for the input type field
*
* @return {string}
*/
const inputTypeLabel = computed( () => LabelData.fromString(
i18n( 'wikilambda-function-definition-input-item-type' ).text()
) );
// Actions
/**
* Updates the remainingChars data property as the user types into the Z2K2 field
*
* @param {Event} event - the event object that is automatically passed in on input
*/
function updateRemainingChars( event ) {
const { length } = event.target.value;
remainingChars.value = maxInputLabelChars - length;
}
/**
* Removes the input given by its index (zero-lead, excluding benjamin item)
*/
function removeInput() {
emit( 'remove', props.index );
}
/**
* Persist the new input label in the globally stored object
*
* @param {Object} event
*/
function persistInputLabel( event ) {
store.setZMonolingualString( {
parentKeyPath: [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_VALUE,
Constants.Z_FUNCTION_ARGUMENTS,
String( props.index + 1 ),
Constants.Z_ARGUMENT_LABEL,
Constants.Z_MULTILINGUALSTRING_VALUE
],
itemKeyPath: props.input ? props.input.keyPath : undefined,
value: event.target.value,
lang: props.zLanguage
} );
emit( 'argument-label-updated' );
}
// Lifecycle
onMounted( () => {
remainingChars.value = maxInputLabelChars - ( props.input ? props.input.value.length : 0 );
} );
return {
iconTrash,
inputFieldLabel,
inputTypeLabel,
maxInputLabelChars,
persistInputLabel,
remainingChars,
removeInput,
updateRemainingChars,
i18n
};
}
} );
</script>
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
.ext-wikilambda-app-function-editor-inputs-item {
border-radius: @border-radius-base;
border: @border-subtle;
padding: @spacing-35 @spacing-75 @spacing-75;
margin-bottom: @spacing-100;
.ext-wikilambda-app-function-editor-inputs-item__counter {
color: @color-subtle;
margin-left: @spacing-50;
display: flex;
justify-content: flex-end;
}
.ext-wikilambda-app-function-editor-inputs-item__header {
display: flex;
flex-direction: row;
margin-bottom: @spacing-100;
margin-right: -@spacing-35;
align-items: center;
}
.ext-wikilambda-app-function-editor-inputs-item__label {
flex-grow: 1;
font-weight: @font-weight-bold;
display: inline-block;
}
.ext-wikilambda-app-function-editor-inputs-item__action-delete {
flex-grow: 0;
}
.ext-wikilambda-app-function-editor-inputs-item__body {
width: 100%;
box-sizing: border-box;
padding: 0;
}
.ext-wikilambda-app-function-editor-inputs-item__field {
margin-bottom: @spacing-100;
&:last-child {
margin-bottom: 0;
}
.cdx-label__label__text {
font-weight: @font-weight-normal;
}
}
}
</style>
|