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 | 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 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x | <!--
WikiLambda Vue component for setting the aliases 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-aliases">
<template #label>
<label :for="aliasFieldId">
<!-- TODO (T335583): Replace i18n message with key label -->
{{ i18n( 'wikilambda-function-definition-alias-label' ).text() }}
<span>{{ i18n( 'parentheses', [ i18n( 'wikilambda-optional' ).text() ] ).text() }}</span>
</label>
</template>
<template #description>
{{ i18n( 'wikilambda-function-definition-alias-description' ).text() }}
</template>
<template #body>
<cdx-chip-input
:id="aliasFieldId"
:aria-label="i18n( 'wikilambda-function-definition-alias-label-new' ).text()"
:input-chips="aliases ? aliases.value.map( ( a ) => ( { value: a } ) ) : []"
:placeholder="hasAliases ? '' : i18n( 'wikilambda-function-definition-alias-placeholder' ).text()"
@update:input-chips="persistAlias"
></cdx-chip-input>
</template>
</wl-function-editor-field>
</template>
<script>
const { computed, defineComponent, inject } = require( 'vue' );
const Constants = require( '../../../Constants.js' );
const useMainStore = require( '../../../store/index.js' );
// Function editor components
const FunctionEditorField = require( './FunctionEditorField.vue' );
// Codex components
const { CdxChipInput } = require( '../../../../codex.js' );
module.exports = exports = defineComponent( {
name: 'wl-function-editor-aliases',
components: {
'wl-function-editor-field': FunctionEditorField,
'cdx-chip-input': CdxChipInput
},
props: {
/**
* zID of item label language
*
* @example Z1014
*/
zLanguage: {
type: String,
required: true
}
},
emits: [ 'alias-updated' ],
setup( props, { emit } ) {
const i18n = inject( 'i18n' );
const store = useMainStore();
// Aliases data
/**
* Finds the Alias set (Z2K4) for the given language
*
* @return {Object|undefined}
*/
const aliases = computed( () => props.zLanguage ? store.getZPersistentAlias( props.zLanguage ) : undefined );
/**
* Returns whether there are any aliases for the selected language
*
* @return {boolean}
*/
const hasAliases = computed( () => aliases.value && aliases.value.value.length > 0 );
/**
* Returns the id for the alias field
*
* @return {string}
*/
const aliasFieldId = computed( () => `ext-wikilambda-app-function-editor-aliases__input${ props.zLanguage }` );
// Actions
/**
* Persists the aliases in the data store.
*
* @param {Array} aliasesArray list of ChipInputItem objects
*/
function persistAlias( aliasesArray ) {
store.setZMonolingualStringset( {
parentKeyPath: [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_ALIASES,
Constants.Z_MULTILINGUALSTRINGSET_VALUE
],
itemKeyPath: aliases.value ? aliases.value.keyPath : undefined,
value: aliasesArray.map( ( alias ) => alias.value ),
lang: props.zLanguage
} );
emit( 'alias-updated' );
}
return {
aliasFieldId,
aliases,
hasAliases,
i18n,
persistAlias
};
}
} );
</script>
|