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 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 28x 28x 28x 28x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 1x 1x 1x 1x 1x 1x 1x 26x 26x 11x 11x 15x 26x 10x 1x 1x 1x 1x 1x 1x 10x 14x 14x 1x 1x 1x 1x 1x 1x 1x 26x 26x 8x 8x 18x 26x 10x 1x 1x 1x 1x 1x 1x 10x 17x 17x 1x 1x 1x 1x 1x 1x 1x 26x 26x 8x 8x 18x 26x 11x 1x 1x 1x 1x 1x 1x 11x 17x 17x 1x 1x 1x 1x 1x 1x 1x 10x 13x 13x 9x 9x 4x 13x 5x 2x 2x 2x 2x 2x 2x 5x 2x 2x 10x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 21x 1x 1x 1x 1x 1x 1x 1x 1x 18x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 18x 1x 1x 1x 1x 1x 1x 1x 1x 18x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 10x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 - About Widget Language Block @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt @license MIT --> <template> <div class="ext-wikilambda-app-about-language-block" data-testid="about-language-block"> <!-- Read mode --> <div v-if="!edit" class="ext-wikilambda-app-about-language-block__read"> <div class="ext-wikilambda-app-about-language-block__fields"> <!-- No descriptions or aliases message --> <div v-if="!hasDescription && !hasAliases" class="ext-wikilambda-app-about-language-block__unavailable"> {{ $i18n( 'wikilambda-about-widget-no-descriptions-or-aliases' ).text() }} </div> <template v-else> <!-- Description block --> <div class="ext-wikilambda-app-about-language-block__description" data-testid="about-description"> <span v-if="hasDescription" class="ext-wikilambda-app-about-language-block__value"> {{ viewData.description.value }} </span> <span v-else class="ext-wikilambda-app-about-language-block__unavailable"> {{ $i18n( 'wikilambda-about-widget-no-descriptions' ).text() }} </span> </div> <!-- Aliases block --> <div class="ext-wikilambda-app-about-language-block__aliases" data-testid="about-aliases"> <template v-if="hasAliases"> <span v-for="( alias, index ) in visibleAliases" :key="'alias-' + index" class="ext-wikilambda-app-about-language-block__alias" data-testid="about-alias" >{{ alias.value }}</span> <a v-if="viewData.aliases.value.length > 3 && !seeAllAliases" class="ext-wikilambda-app-about-language-block__aliases-more" @click="seeAllAliases = true" >+{{ viewData.aliases.value.length - 3 }}</a> </template> <span v-else class="ext-wikilambda-app-about-language-block__unavailable"> {{ $i18n( 'wikilambda-about-widget-no-aliases' ).text() }} </span> </div> </template> </div> <!-- Function specific fields --> <div v-if="isFunction" class="ext-wikilambda-app-about-language-block__function-fields"> <div class="ext-wikilambda-app-about-language-block__inputs"> <!-- Inputs --> <div class="ext-wikilambda-app-about-language-block__field-title"> {{ $i18n( 'wikilambda-function-definition-inputs-label' ).text() }} </div> <template v-if="viewData.inputs.length > 0"> <div v-for="input in viewData.inputs" :key="input.key" class="ext-wikilambda-app-about-language-block__field-value ext-wikilambda-app-about-language-block__input"> <span v-if="input.value" class="ext-wikilambda-app-about-language-block__input-label" >{{ input.value }}<span>:</span></span> <span v-else class="ext-wikilambda-app-about-language-block__input-label ext-wikilambda-app-about-language-block__unavailable" >{{ $i18n( 'wikilambda-editor-default-name' ).text() }}<span>:</span> </span> <wl-z-object-to-string :row-id="input.typeRowId"></wl-z-object-to-string> </div> </template> <div v-else class="ext-wikilambda-app-about-language-block__field-value"> <span class="ext-wikilambda-app-about-language-block__unavailable"> {{ $i18n( 'wikilambda-about-widget-no-inputs' ).text() }} </span> </div> </div> <!-- Output --> <div class="ext-wikilambda-app-about-language-block__output"> <div class="ext-wikilambda-app-about-language-block__field-title"> {{ $i18n( 'wikilambda-function-definition-output-label' ).text() }} </div> <div class="ext-wikilambda-app-about-language-block__field-value"> <wl-z-object-to-string :row-id="outputTypeRowId"></wl-z-object-to-string> </div> </div> </div> </div> <!-- Edit mode --> <div v-else class="ext-wikilambda-app-about-language-block__edit"> <!-- Name field --> <cdx-field class="ext-wikilambda-app-about-language-block__edit-field" data-testid="about-name-field" > <cdx-text-input :model-value="editData.name.value" :placeholder="$i18n( 'wikilambda-about-widget-name-placeholder' ).text()" :maxlength="maxNameChars" data-testid="text-input" @update:model-value="updateEditValue( editData.name, $event )" @change="changeEditValue" ></cdx-text-input> <template #label> <span :lang="nameLabelData.langCode" :dir="nameLabelData.langDir" >{{ nameLabelData.label }}</span> </template> <template #help-text> <div class="ext-wikilambda-app-about-language-block__edit-field-caption"> <template v-if="fallbackName"> <span :lang="fallbackName.lang.langCode" :dir="fallbackName.lang.langDir" >{{ fallbackName.lang.label }}</span>: {{ fallbackName.value }} </template> </div> <div class="ext-wikilambda-app-about-language-block__edit-field-counter"> {{ nameCharsLeft }} </div> </template> </cdx-field> <!-- Description field --> <cdx-field class="ext-wikilambda-app-about-language-block__edit-field" data-testid="about-description-field" > <cdx-text-area :model-value="editData.description.value" :placeholder="$i18n( 'wikilambda-about-widget-description-placeholder' ).text()" :maxlength="maxDescriptionChars" data-testid="text-area" @update:model-value="updateEditValue( editData.description, $event )" @change="changeEditValue" ></cdx-text-area> <template #label> <span :lang="descriptionLabelData.langCode" :dir="descriptionLabelData.langDir" >{{ descriptionLabelData.label }}</span> </template> <template #help-text> <div class="ext-wikilambda-app-about-language-block__edit-field-caption"> <template v-if="fallbackDescription"> <span :lang="fallbackDescription.lang.langCode" :dir="fallbackDescription.lang.langDir" >{{ fallbackDescription.lang.label }}</span>: {{ fallbackDescription.value }} </template> </div> <div class="ext-wikilambda-app-about-language-block__edit-field-counter"> {{ descriptionCharsLeft }} </div> </template> </cdx-field> <!-- Aliases field --> <cdx-field class="ext-wikilambda-app-about-language-block__edit-field" data-testid="about-aliases-field" > <cdx-chip-input :input-chips="editData.aliases.value" @update:input-chips="updateEditValue( editData.aliases, $event ); changeEditValue();" ></cdx-chip-input> <template #label> <span :lang="aliasesLabelData.langCode" :dir="aliasesLabelData.langDir" >{{ aliasesLabelData.label }}</span> </template> <template #help-text> <div v-if="fallbackAliases" class="ext-wikilambda-app-about-language-block__edit-field-caption" > <span :lang="fallbackAliases.lang.langCode" :dir="fallbackAliases.lang.langDir" >{{ fallbackAliases.lang.label }}</span>: {{ fallbackAliases.value.join( ', ' ) }} </div> </template> </cdx-field> <!-- Function input fields --> <template v-if="isFunction"> <cdx-field v-for="( input, index ) in editData.inputs" :key="'input-' + index" class="ext-wikilambda-app-about-language-block__edit-field ext-wikilambda-app-about-language-block__edit-input" data-testid="about-input-field" > <cdx-text-input :model-value="input.value" :placeholder="$i18n( 'wikilambda-function-definition-inputs-item-input-placeholder' ).text()" :maxlength="maxInputChars" data-testid="text-input" @update:model-value="updateEditValue( input, $event )" @change="changeEditValue" ></cdx-text-input> <template #label> {{ $i18n( 'wikilambda-about-widget-input-label', index + 1 ).text() }} </template> <template #help-text> <div class="ext-wikilambda-app-about-language-block__edit-field-caption"> <template v-if="fallbackInputs[ index ]"> <span :lang="fallbackInputs[ index ].lang.langCode" :dir="fallbackInputs[ index ].lang.langDir" >{{ fallbackInputs[ index ].lang.label }}</span>: {{ fallbackInputs[ index ].value }} </template> </div> <div class="ext-wikilambda-app-about-language-block__edit-field-counter"> {{ inputCharsLeft[ index ] }} </div> </template> </cdx-field> </template> </div> </div> </template> <script> const { CdxChipInput, CdxField, CdxTextArea, CdxTextInput } = require( '@wikimedia/codex' ); const { defineComponent } = require( 'vue' ); const Constants = require( '../../../Constants.js' ), ZObjectToString = require( '../../default-view-types/ZObjectToString.vue' ), { mapGetters } = require( 'vuex' ); module.exports = exports = defineComponent( { name: 'wl-about-language-block', components: { 'cdx-chip-input': CdxChipInput, 'cdx-field': CdxField, 'cdx-text-area': CdxTextArea, 'cdx-text-input': CdxTextInput, 'wl-z-object-to-string': ZObjectToString }, props: { edit: { type: Boolean, required: true }, language: { type: String, required: true }, isFunction: { type: Boolean, required: true }, viewData: { type: Object, required: true }, editData: { type: Object, required: false, default: undefined }, fieldLangs: { type: Object, required: true } }, data: function () { return { maxNameChars: Constants.LABEL_CHARS_MAX, maxInputChars: Constants.INPUT_CHARS_MAX, maxDescriptionChars: Constants.DESCRIPTION_CHARS_MAX, seeAllAliases: false }; }, computed: Object.assign( mapGetters( [ 'getFallbackLanguageZids', 'getLabelData', 'getZArgumentLabelForLanguage', 'getZFunctionOutput', 'getZMonolingualTextValue', 'getZMonolingualStringsetValues', 'getZPersistentName', 'getZPersistentAlias', 'getZPersistentDescription' ] ), { /** * Returns the list of fallback languages in their Zid * representation, excluding the language of the current block * * @return {Array} */ fallbackLanguageZids: function () { return this.getFallbackLanguageZids.filter( ( zid ) => zid !== this.language ); }, /** * Returns the name for the closest available fallback language * * @return {Object|undefined} */ fallbackName: function () { // Don't search for fallback if the field has value if ( this.viewData.name.value ) { return undefined; } // Return the value in the first available fallback for ( const lang of this.fallbackLanguageZids ) { if ( this.fieldLangs.name.includes( lang ) ) { const row = this.getZPersistentName( lang ); return { value: this.getZMonolingualTextValue( row.id ), lang: this.getLabelData( lang ) }; } } // Or return undefined if no value was found return undefined; }, /** * Returns the description for the closest available fallback language * * @return {Object|undefined} */ fallbackDescription: function () { // Don't search for fallback if the field has value if ( this.viewData.description.value ) { return undefined; } // Return the value in the first available fallback for ( const lang of this.fallbackLanguageZids ) { if ( this.fieldLangs.description.includes( lang ) ) { const row = this.getZPersistentDescription( lang ); return { value: this.getZMonolingualTextValue( row.id ), lang: this.getLabelData( lang ) }; } } // Or return undefined if no value was found return undefined; }, /** * Returns the alias for the closest available fallback language * * @return {Object|undefined} */ fallbackAliases: function () { // Don't search for fallback if the field has value if ( this.viewData.aliases.value.length > 0 ) { return undefined; } // Return the value in the first available fallback for ( const lang of this.fallbackLanguageZids ) { if ( this.fieldLangs.aliases.includes( lang ) ) { const row = this.getZPersistentAlias( lang ); return { value: this.getZMonolingualStringsetValues( row.id ).map( ( item ) => item.value ), lang: this.getLabelData( lang ) }; } } // Or return undefined if no value was found return undefined; }, /** * Returns the function inputs for the fallback language * * @return {Array} */ fallbackInputs: function () { return this.viewData.inputs.map( ( input, index ) => { // Don't search for fallback if the field has value if ( input.value ) { return undefined; } // Return the value in the first available fallback for ( const lang of this.fallbackLanguageZids ) { if ( this.fieldLangs.inputs[ index ].includes( lang ) ) { const row = this.getZArgumentLabelForLanguage( input.inputRowId, lang ); return { value: this.getZMonolingualTextValue( row.id ), lang: this.getLabelData( lang ) }; } } // Or return undefined if no value was found return undefined; } ); }, /** * Returns the label for the name input field (Z2K3) * * @return {LabelData} */ nameLabelData: function () { return this.getLabelData( Constants.Z_PERSISTENTOBJECT_LABEL ); }, /** * Returns the number of characters left to reach the * label field maximum allowed. * * @return {number} */ nameCharsLeft: function () { return this.maxNameChars - this.editData.name.value.length; }, /** * Returns whether the object has any available description * (in any language) * * @return {boolean} */ hasDescription: function () { return !!this.viewData.description.value; }, /** * Returns the label for the description input field (Z2K5) * * @return {LabelData} */ descriptionLabelData: function () { return this.getLabelData( Constants.Z_PERSISTENTOBJECT_DESCRIPTION ); }, /** * Returns the number of characters left to reach the * description field maximum allowed. * * @return {number} */ descriptionCharsLeft: function () { return this.maxDescriptionChars - this.editData.description.value.length; }, /** * Returns whether the object has any available aliases * (in any language) * * @return {boolean} */ hasAliases: function () { return this.viewData.aliases.value.length > 0; }, /** * Returns the label for the aliases input field (Z2K4) * * @return {LabelData} */ aliasesLabelData: function () { return this.getLabelData( Constants.Z_PERSISTENTOBJECT_ALIASES ); }, /** * Returns the visible aliases depending on * the seeAllAliases flag. * * @return {Array} */ visibleAliases: function () { return this.seeAllAliases ? this.viewData.aliases.value : this.viewData.aliases.value.slice( 0, 3 ); }, /** * Returns the number of characters left to reach each * input field maximum allowed. * * @return {Array} */ inputCharsLeft: function () { return this.editData.inputs.map( ( input ) => this.maxInputChars - input.value.length ); }, /** * Returns the rowId of the output type * * @return {number|undefined} */ outputTypeRowId: function () { if ( !this.isFunction ) { return undefined; } const outputTypeRow = this.getZFunctionOutput(); return outputTypeRow ? outputTypeRow.id : undefined; } } ), methods: { /** * Emits an 'update-edit-value' event with the changes done to * the fields, so that the parent component can update the editData * object passed as property. * * @param {Object} data * @param {Array|string} value */ updateEditValue: function ( data, value ) { this.$emit( 'update-edit-value', { data, value } ); }, /** * Emits a 'change-value' event every time that a field * changes its value, to trigger the parent to persist the new * value into the state in case we are in an edit page. * We use the 'change' events to limit state persistance to * whole field updates (on blur, or on chip input), so that we * don't run persistance methods for every input character. */ changeEditValue: function () { this.$emit( 'change-value' ); } } } ); </script> <style lang="less"> @import '../../../ext.wikilambda.app.variables.less'; .ext-wikilambda-app-about-language-block { .ext-wikilambda-app-about-language-block__unavailable { color: @color-placeholder; & > span { color: @color-base; } } .ext-wikilambda-app-about-language-block__description, .ext-wikilambda-app-about-language-block__aliases { overflow-wrap: break-word; margin-top: @spacing-50; } .ext-wikilambda-app-about-language-block__aliases { padding-bottom: @spacing-25; display: flex; flex-wrap: wrap; gap: 8px; } .ext-wikilambda-app-about-language-block__alias { display: inline-block; border-radius: @border-radius-pill; border: 1px solid @border-color-subtle; color: @color-subtle; padding: 0 @spacing-50; } .ext-wikilambda-app-about-language-block__aliases-more { color: @color-progressive; } .ext-wikilambda-app-about-language-block__function-fields { margin-top: @spacing-100; & > div { margin-top: @spacing-100; } } .ext-wikilambda-app-about-language-block__field-title { font-weight: @font-weight-bold; } .ext-wikilambda-app-about-language-block__field-value { margin-top: @spacing-25; } .ext-wikilambda-app-about-language-block__edit-field { margin: 0 0 @spacing-100; .cdx-field__help-text { display: flex; justify-content: space-between; align-items: baseline; flex-direction: row; } .cdx-text-input { max-width: initial; } .cdx-chip-input__chips { min-width: auto; } .cdx-chip-input__input { max-width: 100%; } } .ext-wikilambda-app-about-language-block__edit-field-caption { display: block; color: @color-subtle; flex-grow: 1; } .ext-wikilambda-app-about-language-block__edit-field-counter { flex-grow: 0; } } </style> |