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 | 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 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 38x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 82x 5x 5x 77x 77x 77x 82x 16x 16x 61x 61x 61x 82x 61x 61x 61x 82x 1x 1x 60x 60x 60x 82x 33x 45x 16x 16x 45x 17x 44x 44x 24x 24x 24x 24x 24x 24x 24x 24x 24x 4x 4x 24x 24x 24x 24x 24x 24x 24x 24x 24x 1x 1x | <!--
WikiLambda Vue component for the selection of a ZNaturalLanguage object inside the Function editor.
@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
@license MIT
-->
<template>
<wl-function-editor-field class="ext-wikilambda-app-function-editor-language">
<template #label>
<label id="ext-wikilambda-app-function-editor-language__label-id">
<!-- TODO (T335583): Replace i18n message with key label -->
{{ i18n( 'wikilambda-languagelabel' ).text() }}
</label>
</template>
<template #body>
<wl-z-object-selector
class="ext-wikilambda-app-function-editor-language__add-language"
aria-labelledby="ext-wikilambda-app-function-editor-language__label-id"
:disabled="hasContent"
:exclude-zids="excludedLanguages"
:selected-zid="zLanguage"
:type="naturalLanguageType"
@select-item="addNewLanguage"
></wl-z-object-selector>
</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' );
// Base components
const ZObjectSelector = require( '../../base/ZObjectSelector.vue' );
module.exports = exports = defineComponent( {
name: 'wl-function-editor-language',
components: {
'wl-function-editor-field': FunctionEditorField,
'wl-z-object-selector': ZObjectSelector
},
props: {
zLanguage: {
type: String,
default: ''
},
functionLanguages: {
type: Array,
default: () => []
},
index: {
type: Number,
default: 0
}
},
emits: [ 'language-changed' ],
setup( props, { emit } ) {
const i18n = inject( 'i18n' );
const store = useMainStore();
// Constants
const naturalLanguageType = Constants.Z_NATURAL_LANGUAGE;
// Language selector
/**
* Returns the list of languages that should be excluded from selection.
* Excludes languages already selected in other language blocks (excluding current block).
*
* @return {Array}
*/
const excludedLanguages = computed( () => props.functionLanguages
.filter( ( _, index ) => index !== props.index )
);
/**
* Whether the language selector should be disabled.
* Disabled when content has been entered in any field (name, description, aliases, or input labels).
* The selector is enabled when the language is not set or when the content is empty.
*
* @return {boolean}
*/
const hasContent = computed( () => {
if ( !props.zLanguage ) {
return false;
}
// Check if name has content
const name = store.getZPersistentName( props.zLanguage );
if ( name && name.value && name.value.trim() !== '' ) {
return true;
}
// Check if description has content
const description = store.getZPersistentDescription( props.zLanguage );
if ( description && description.value && description.value.trim() !== '' ) {
return true;
}
// Check if aliases have content
const aliases = store.getZPersistentAlias( props.zLanguage );
if ( aliases && aliases.value && aliases.value.length > 0 ) {
return true;
}
// Check if any input labels have content
const inputs = store.getZFunctionInputLabels( props.zLanguage );
if ( inputs && inputs.length > 0 ) {
for ( const input of inputs ) {
if ( input.value && input.value.trim() !== '' ) {
return true;
}
}
}
return false;
} );
// Actions
/**
* Emits a change event when the selector is set to a new language.
*
* @param {string} lang
*/
function addNewLanguage( lang ) {
emit( 'language-changed', lang );
}
return {
i18n,
addNewLanguage,
excludedLanguages,
hasContent,
naturalLanguageType
};
}
} );
</script>
|