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 | 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 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 6x 6x 6x 21x 21x 21x 21x 21x 21x 21x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 21x 21x 21x 21x 21x 21x 21x 14x 14x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | <!--
WikiLambda Vue component for setting the name of a ZFunction in the Function editor.
@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
@license MIT
-->
<template>
<wl-function-editor-field class="ext-wikilambda-app-function-editor-name">
<template #label>
<label :for="nameFieldId">
<!-- TODO (T335583): Replace i18n message with key label -->
{{ i18n( 'wikilambda-function-definition-name-label' ).text() }}
<span>{{ i18n( 'parentheses', [ i18n( 'wikilambda-optional' ).text() ] ).text() }}</span>
</label>
</template>
<template #body>
<cdx-text-input
:id="nameFieldId"
:lang="name ? langLabelData.langCode : undefined"
:dir="name ? langLabelData.langDir : undefined"
:model-value="name ? name.value : ''"
class="ext-wikilambda-app-function-editor-name__input"
:aria-label="i18n( 'wikilambda-function-definition-name-label' ).text()"
:placeholder="i18n( 'wikilambda-function-definition-name-placeholder' ).text()"
:maxlength="maxLabelChars"
@input="updateRemainingChars"
@change="persistName"
></cdx-text-input>
<div class="ext-wikilambda-app-function-editor-name__counter">
{{ remainingChars }}
</div>
</template>
</wl-function-editor-field>
</template>
<script>
const { computed, defineComponent, inject, onBeforeUnmount, onMounted, ref } = require( 'vue' );
const Constants = require( '../../../Constants.js' );
const useMainStore = require( '../../../store/index.js' );
const LabelData = require( '../../../store/classes/LabelData.js' );
const usePageTitle = require( '../../../composables/usePageTitle.js' );
// Function editor components
const FunctionEditorField = require( './FunctionEditorField.vue' );
// Codex components
const { CdxTextInput } = require( '../../../../codex.js' );
module.exports = exports = defineComponent( {
name: 'wl-function-editor-name',
components: {
'wl-function-editor-field': FunctionEditorField,
'cdx-text-input': CdxTextInput
},
props: {
/**
* zID of item label language
*
* @example Z1014
*/
zLanguage: {
type: String,
required: true
},
/**
* Label data for the language
*/
langLabelData: {
type: LabelData,
default: null
}
},
emits: [ 'name-updated' ],
setup( props, { emit } ) {
const i18n = inject( 'i18n' );
const store = useMainStore();
const { updateZObjectPageTitle } = usePageTitle();
// Constants
const maxLabelChars = Constants.LABEL_CHARS_MAX;
// State
const ignoreChangeEvent = ref( false );
const remainingChars = ref( Constants.LABEL_CHARS_MAX );
// Name data
/**
* Finds the Name (Z2K3) for the given language and returns
* its keyPath and value if found. Else, returns undefined.
*
* @return {Object|undefined}
*/
const name = computed( () => props.zLanguage ? store.getZPersistentName( props.zLanguage ) : undefined );
/**
* Returns the id for the input field
*
* @return {string}
*/
const nameFieldId = computed( () => `ext-wikilambda-app-function-editor-name__input-${ props.zLanguage }` );
// Actions
/**
* Updates the remainingChars data property as the user types into the Z2K5 field
*
* @param {Event} event - the event object that is automatically passed in on input
*/
function updateRemainingChars( event ) {
const { length } = event.target.value;
remainingChars.value = maxLabelChars - length;
}
/**
* Persist the new name value in the globally stored object
*
* @param {Object} event
*/
function persistName( event ) {
if ( ignoreChangeEvent.value ) {
return;
}
store.setZMonolingualString( {
parentKeyPath: [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_LABEL,
Constants.Z_MULTILINGUALSTRING_VALUE
],
itemKeyPath: name.value ? name.value.keyPath : undefined,
value: event.target.value,
lang: props.zLanguage
} );
// After persisting in the state, update the page title
updateZObjectPageTitle();
emit( 'name-updated' );
}
// Lifecycle
onMounted( () => {
remainingChars.value = maxLabelChars - ( name.value ? name.value.value.length : 0 );
} );
onBeforeUnmount( () => {
// When the component is unmounted, we want to ignore any change events and not persist the data
ignoreChangeEvent.value = true;
} );
// Return all properties and methods for the template
return {
i18n,
maxLabelChars,
name,
nameFieldId,
persistName,
remainingChars,
updateRemainingChars
};
}
} );
</script>
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
.ext-wikilambda-app-function-editor-name {
.ext-wikilambda-app-function-editor-name__counter {
color: @color-subtle;
margin-left: @spacing-50;
display: flex;
justify-content: flex-end;
}
}
</style>
|