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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 81x 81x 81x 1x 1x 1x 1x 1x 1x 1x 35x 1x 1x 1x 1x 1x 1x 1x 1x 50x 50x 50x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 1x 1x 1x 1x 1x 1x 1x 19x 1x 1x 1x 1x 1x 1x 1x 19x 1x 1x 1x 1x 1x 1x 1x 19x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 5x 5x 1x 1x 19x 19x 19x 1x 1x 14x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | <!-- WikiLambda Vue component for setting the description 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-description"> <template #label> <label :for="descriptionInputId"> {{ descriptionLabel }} <span>{{ descriptionOptional }}</span> </label> </template> <template #body> <cdx-text-area :id="descriptionInputId" :model-value="description" class="ext-wikilambda-app-function-editor-description__input" :aria-label="descriptionLabel" :placeholder="descriptionInputPlaceholder" :maxlength="maxDescriptionChars" @input="updateRemainingChars" @change="persistDescription" ></cdx-text-area> <div class="ext-wikilambda-app-function-editor-description__counter"> {{ remainingChars }} </div> </template> </wl-function-editor-field> </template> <script> const { CdxTextArea } = require( '@wikimedia/codex' ); const { defineComponent } = require( 'vue' ); const Constants = require( '../../../Constants.js' ), FunctionEditorField = require( './FunctionEditorField.vue' ), { mapActions, mapGetters } = require( 'vuex' ); module.exports = exports = defineComponent( { name: 'wl-function-editor-description', components: { 'wl-function-editor-field': FunctionEditorField, 'cdx-text-area': CdxTextArea }, props: { zLanguage: { type: String, required: true } }, data: function () { return { ignoreChangeEvent: false, maxDescriptionChars: Constants.DESCRIPTION_CHARS_MAX, remainingChars: Constants.DESCRIPTION_CHARS_MAX }; }, computed: Object.assign( mapGetters( [ 'getRowByKeyPath', 'getZMonolingualTextValue', 'getZPersistentDescription' ] ), { /** * Returns the Short Description (Z2K5) row for the * appropriate language * * @return {Object|undefined} */ descriptionRow: function () { return this.zLanguage ? this.getZPersistentDescription( this.zLanguage ) : undefined; }, /** * Returns true if the current zObject has a description object * * @return {boolean} */ hasDescription: function () { return this.descriptionRow !== undefined; }, /** * Returns the description value for the given language. * If value is not available, returns empty string * * @return {string} */ description: function () { return this.hasDescription ? this.getZMonolingualTextValue( this.descriptionRow.id ) : ''; }, /** * Returns the label for the description field * * @return {string} */ descriptionLabel: function () { // TODO (T335583): Replace i18n message with key label // return this.getLabelData( Constants.Z_PERSISTENTOBJECT_DESCRIPTION ); return this.$i18n( 'wikilambda-function-definition-description-label' ).text(); }, /** * Returns the i18n message for the description field placeholder * * @return {string} */ descriptionInputPlaceholder: function () { return this.$i18n( 'wikilambda-function-definition-description-placeholder' ).text(); }, /** * Returns the "optional" caption for the description field * * @return {string} */ descriptionOptional: function () { return this.$i18n( 'parentheses', [ this.$i18n( 'wikilambda-optional' ).text() ] ).text(); }, /** * Returns the id for the input field * * @return {string} */ descriptionInputId: function () { return `ext-wikilambda-app-function-editor-description__input${ this.zLanguage }`; } } ), methods: Object.assign( mapActions( [ 'changeType', 'removeItemFromTypedList', 'setValueByRowIdAndPath' ] ), { /** * 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 */ updateRemainingChars: function ( event ) { const { length } = event.target.value; this.remainingChars = this.maxDescriptionChars - length; }, /** * Persist the new name value in the globally stored object * * @param {Object} event */ persistDescription: function ( event ) { if ( this.ignoreChangeEvent ) { return; } const value = event.target.value; if ( this.hasDescription ) { if ( value === '' ) { this.removeItemFromTypedList( { rowId: this.descriptionRow.id } ); } else { this.setValueByRowIdAndPath( { rowId: this.descriptionRow.id, keyPath: [ Constants.Z_MONOLINGUALSTRING_VALUE, Constants.Z_STRING_VALUE ], value } ); } } else { // If this.descriptionRow is undefined, there's no monolingual string // for the given language, so we create a new monolingual string // with the new value and append to the parent list. const parentRow = this.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_DESCRIPTION, Constants.Z_MULTILINGUALSTRING_VALUE ] ); if ( !parentRow ) { // This should never happen because all Z2Kn's are initialized return; } this.changeType( { id: parentRow.id, type: Constants.Z_MONOLINGUALSTRING, lang: this.zLanguage, value, append: true } ); } this.$emit( 'updated-description' ); } } ), mounted: function () { this.$nextTick( function () { this.remainingChars = this.maxDescriptionChars - this.description.length; } ); }, beforeUnmount() { // When the component is unmounted, we want to ignore any change events and not persist the data this.ignoreChangeEvent = true; } } ); </script> <style lang="less"> @import '../../../ext.wikilambda.app.variables.less'; .ext-wikilambda-app-function-editor-description { .ext-wikilambda-app-function-editor-description__counter { color: @color-subtle; margin-left: @spacing-50; display: flex; justify-content: flex-end; } } </style> |