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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 1x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 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 20x 20x 20x 20x 20x 20x 217x 217x 217x 217x 217x 217x 217x 217x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 33x 33x 1x 1x 1x 1x 1x 1x 32x 32x 32x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 the AboutLanguages Dialog.
@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
@license MIT
-->
<template>
<div>
<cdx-dialog
:open="open"
data-testid="languages-dialog"
class="ext-wikilambda-app-about-languages-dialog"
:title="i18n( 'wikilambda-about-widget-view-languages-accessible-title' ).text()"
:use-close-button="true"
@update:open="closeDialog"
>
<!-- Dialog Header -->
<template #header>
<wl-custom-dialog-header @close-dialog="closeDialog">
{{ i18n( 'wikilambda-about-widget-view-languages-title' ).text() }}
</wl-custom-dialog-header>
<!-- Language Search block -->
<div class="ext-wikilambda-app-about-languages-dialog__search">
<cdx-search-input
:model-value="searchTerm"
data-testid="search-language"
class="ext-wikilambda-app-about-languages-dialog__search-input"
:placeholder="i18n( 'wikilambda-about-widget-search-language-placeholder' ).text()"
@update:model-value="updateSearchTerm"
@focus="showSearchCancel = true"
></cdx-search-input>
<cdx-button
v-if="showSearchCancel"
action="default"
weight="quiet"
class="ext-wikilambda-app-about-languages-dialog__search-cancel"
@click="clearSearch"
>
{{ i18n( 'wikilambda-cancel' ).text() }}
</cdx-button>
</div>
</template>
<!-- Dialog Body: Language Items block -->
<div class="ext-wikilambda-app-about-languages-dialog__items">
<section
v-for="group in itemGroups"
:key="group.id"
class="ext-wikilambda-app-about-languages-dialog__group"
>
<h3
v-if="group.title"
class="ext-wikilambda-app-about-languages-dialog__group-title"
>
{{ group.title }}
</h3>
<ul class="ext-wikilambda-app-list-reset ext-wikilambda-app-about-languages-dialog__list">
<li
v-for="( item, index ) in group.items"
:key="`dialog-lang-${group.id}-${index}`"
class="ext-wikilambda-app-about-languages-dialog__item"
>
<button
type="button"
class="ext-wikilambda-app-button-reset
ext-wikilambda-app-about-languages-dialog__item-button"
@click="editLanguage( item.langZid )"
>
<div
class="ext-wikilambda-app-about-languages-dialog__item-title"
:lang="item.langLabelData.langCode"
:dir="item.langLabelData.langDir"
>
{{ item.langLabelData.label }}
</div>
<div class="ext-wikilambda-app-about-languages-dialog__item-field">
<span
v-if="item.hasMultilingualData"
:class="{
'ext-wikilambda-app-about-languages-dialog__item-untitled': !item.hasName
}"
>{{ item.name }}</span>
<span v-else class="ext-wikilambda-app-about-languages-dialog__item-add-language">
{{ i18n( 'wikilambda-about-widget-add-language' ).text() }}
</span>
</div>
</button>
</li>
</ul>
</section>
</div>
</cdx-dialog>
</div>
</template>
<script>
const { computed, defineComponent, inject, ref } = require( 'vue' );
const { CdxButton, CdxDialog, CdxSearchInput } = require( '../../../../codex.js' );
const Constants = require( '../../../Constants.js' );
const CustomDialogHeader = require( '../../base/CustomDialogHeader.vue' );
const LabelData = require( '../../../store/classes/LabelData.js' );
const useMainStore = require( '../../../store/index.js' );
const { createLabelComparator } = require( '../../../utils/sortUtils.js' );
module.exports = exports = defineComponent( {
name: 'wl-about-languages-dialog',
components: {
'cdx-button': CdxButton,
'cdx-dialog': CdxDialog,
'cdx-search-input': CdxSearchInput,
'wl-custom-dialog-header': CustomDialogHeader
},
props: {
open: {
type: Boolean,
required: true,
default: false
}
},
emits: [ 'add-language', 'close-dialog' ],
setup( _, { emit } ) {
const i18n = inject( 'i18n' );
const store = useMainStore();
// Search functionality
const searchTerm = ref( '' );
const showSearchCancel = ref( false );
// Lookup results
const lookupResults = ref( [] );
let lookupAbortController = null;
// Dialog state
/**
* Close the dialog and make sure that the selected language
* and unsaved changes are cleared.
*/
function closeDialog() {
searchTerm.value = '';
lookupResults.value = [];
showSearchCancel.value = false;
emit( 'close-dialog' );
}
/**
* Emits the add-language event so that we can edit or
* create multilingual data in a given language by adding a new
* block in the About widget accordion.
*
* @param {string} lang
*/
function editLanguage( lang ) {
emit( 'add-language', lang );
closeDialog();
}
// Language data
/**
* Returns a list of all the fallback language Zids.
*
* @return {Array}
*/
const suggestedLangs = computed( () => store.getFallbackLanguageZids );
/**
* Returns a list of all the language Zids that are present
* in the metadata collection (must have at least a name, a
* description or a set of aliases). The list excludes all
* the suggested (fallback) language zids.
*
* @return {Array}
*/
const allLangs = computed( () => store.getMultilingualDataLanguages.all
.filter( ( lang ) => !suggestedLangs.value.includes( lang ) ) );
/**
* Returns grouped language items for local languages.
* Groups are: "Suggested" and "Other".
* Returns whether the given language Zid has any metadata
* in the current object (either name, description or aliases)
*
* @param {string} langZid
* @return {boolean}
*/
const hasMultilingualData = ( langZid ) => allLangs.value.includes( langZid );
/**
* Builds a language item object for a given language Zid.
*
* @param {string} langZid
* @return {Object}
*/
const buildLangItem = ( langZid ) => {
const name = store.getZPersistentName( langZid );
return {
langZid,
langLabelData: store.getLabelData( langZid ),
hasMultilingualData: true,
hasName: !!name,
name: name ? name.value : i18n( 'wikilambda-editor-default-name' ).text()
};
};
/**
* Builds the list of items that correspond to the available
* languages in the object. Each item contains the language Zid
* and label, the Name/Label in that language, and the flags
* hasMultilingualData and hasName that will condition the style.
*
* @return {Array}
*/
const localItems = computed( () => {
const sortByLabel = createLabelComparator(
store.getUserLangCode,
( item ) => item.langLabelData.label
);
const suggestedLangsList = store.getFallbackLanguageZids.map( ( zid ) => buildLangItem( zid ) );
const otherLangs = allLangs.value.map( ( zid ) => buildLangItem( zid ) ).sort( sortByLabel );
const groups = [];
if ( suggestedLangsList.length > 0 ) {
groups.push( {
id: 'suggested',
title: i18n( 'wikilambda-about-widget-view-languages-suggested' ).text(),
items: suggestedLangsList
} );
}
if ( otherLangs.length > 0 ) {
groups.push( {
id: 'other',
title: i18n( 'wikilambda-about-widget-view-languages-other' ).text(),
items: otherLangs
} );
}
return groups;
} );
// Search functionality
/**
* Clear the search field and results
*/
function clearSearch() {
searchTerm.value = '';
updateSearchTerm( '' );
showSearchCancel.value = false;
}
/**
* Update the lookupResults when there's a new search
* term in the language search box.
*
* @param {string} value
*/
function updateSearchTerm( value ) {
searchTerm.value = value;
if ( !value ) {
lookupResults.value = [];
return;
}
getLookupResults( value );
}
// Lookup results
/**
* Abort any in-flight lookup request, create a new controller, and return its signal.
*
* @return {AbortSignal}
*/
function resetAbortController() {
if ( lookupAbortController ) {
lookupAbortController.abort();
}
lookupAbortController = new AbortController();
return lookupAbortController.signal;
}
/**
* Processes lookup response data and updates the results list.
*
* @param {Object} data
* @param {string} substring
*/
function handleLookupResponse( data, substring ) {
// Discard responses from superseded searches.
if ( substring !== searchTerm.value ) {
return;
}
const allZids = [];
const { labels } = data;
// Compile information for every search result
lookupResults.value = labels
.map( ( result ) => {
const name = store.getZPersistentName( result.page_title );
allZids.push( result.page_title );
const labelData = new LabelData(
result.page_title,
result.label,
result.match_lang,
store.getLanguageIsoCodeOfZLang( result.match_lang )
);
return {
langZid: result.page_title,
langLabelData: labelData,
hasMultilingualData: hasMultilingualData( result.page_title ),
hasName: !!name,
name: name ? name.value : i18n( 'wikilambda-editor-default-name' ).text()
};
} )
.sort( ( a, b ) => {
// Sorts the results so that the items with an available name
// come first, then the items with any available metadata,
// and finally the items that don't have any metadata yet.
if ( a.hasName ) {
return -2;
}
if ( b.hasName ) {
return 2;
}
if ( a.hasMultilingualData ) {
return -1;
}
if ( b.hasMultilingualData ) {
return 1;
}
return 0;
} );
// Fetch the result zid information (labels)
store.fetchZids( { zids: allZids } );
}
/**
* Handle lookup error.
*
* @param {Error} error
*/
function handleLookupError( error ) {
if ( error.code === 'abort' ) {
return;
}
}
/**
* Triggers a lookup API to search for matches for the given substring.
*
* @param {string} substring
*/
function getLookupResults( substring ) {
const signal = resetAbortController();
store.lookupZObjectLabels( {
input: substring,
types: [ Constants.Z_NATURAL_LANGUAGE ],
signal
} )
.then( ( data ) => handleLookupResponse( data, substring ) )
.catch( ( error ) => handleLookupError( error ) );
}
// Display items
/**
* Returns grouped language items for both local languages and search results.
* For local languages, groups are: "Suggested" and "Other".
* For search results, returns a single group without a title.
*
* @return {Array}
*/
const itemGroups = computed( () => {
// If we have search results, return them as a single group without a title
if ( lookupResults.value.length > 0 ) {
return [ {
id: 'search-results',
title: '',
items: lookupResults.value
} ];
}
// Otherwise, return grouped local languages
return localItems.value;
} );
return {
clearSearch,
closeDialog,
editLanguage,
itemGroups,
i18n,
searchTerm,
showSearchCancel,
updateSearchTerm
};
}
} );
</script>
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
.ext-wikilambda-app-about-languages-dialog {
.cdx-dialog__body {
padding: @spacing-50 0;
}
.ext-wikilambda-app-about-languages-dialog__search {
padding: @spacing-100 0 0;
display: flex;
gap: @spacing-150;
}
.ext-wikilambda-app-about-languages-dialog__search-input {
flex-grow: 1;
}
.ext-wikilambda-app-about-languages-dialog__search-cancel {
flex-grow: 0;
}
.ext-wikilambda-app-about-languages-dialog__group-title {
padding: @spacing-50 @spacing-150;
margin: 0;
font-weight: @font-weight-bold;
color: @color-subtle;
font-size: inherit;
}
.ext-wikilambda-app-about-languages-dialog__item {
margin: 0;
padding: 0;
}
.ext-wikilambda-app-about-languages-dialog__item-button {
width: 100%;
padding: @spacing-50 @spacing-150;
text-align: left;
&:hover {
background-color: @background-color-interactive;
}
}
.ext-wikilambda-app-about-languages-dialog__item-title {
margin: 0;
}
.ext-wikilambda-app-about-languages-dialog__item-field {
margin: 0;
color: @color-subtle;
}
.ext-wikilambda-app-about-languages-dialog__item-untitled {
color: @color-placeholder;
font-style: italic;
}
.ext-wikilambda-app-about-languages-dialog__item-add-language {
.cdx-mixin-link();
}
}
</style>
|