4 {{ $i18n( 'ipb-namespaces-label' ).text() }}
6 <cdx-multiselect-lookup
7 v-model:input-chips="chips"
8 v-model:selected="selection"
9 class="mw-block-namespaces"
10 :menu-items="menuItems"
11 :menu-config="menuConfig"
12 :aria-label="$i18n( 'ipb-namespaces-label' ).text()"
13 :placeholder="$i18n( 'block-namespaces-placeholder' ).text()"
15 @update:input-chips="onUpdateChips"
16 ></cdx-multiselect-lookup>
21 const { defineComponent, ref } = require( 'vue' );
22 const { storeToRefs } = require( 'pinia' );
23 const { CdxField, ChipInputItem, CdxMultiselectLookup } = require( '@wikimedia/codex' );
24 const useBlockStore = require( '../stores/block.js' );
27 * Namespaces field component for use by Special:Block.
29 * @todo Abstract for general use in MediaWiki (T375220)
31 module.exports = exports = defineComponent( {
32 name: 'NamespacesField',
38 const { namespaces } = storeToRefs( useBlockStore() );
39 const selection = ref( namespaces.value );
40 const mwNamespaces = mw.config.get( 'wgFormattedNamespaces' );
41 mwNamespaces[ '0' ] = mw.msg( 'blanknamespace' );
42 const initialMenuItems = Object.keys( mwNamespaces )
43 // Exclude virtual namespaces
44 .filter( ( id ) => Number( id ) >= 0 )
47 label: mwNamespaces[ id ]
50 namespaces.value.map( ( nsId ) => ( { value: nsId, label: mwNamespaces[ nsId ] } ) )
52 const menuItems = ref( initialMenuItems );
53 const menuConfig = { visibleItemLimit: 10 };
56 * On input, filter the menu items.
58 * @param {string} value
60 function onInput( value ) {
62 // eslint-disable-next-line arrow-body-style
63 menuItems.value = initialMenuItems.filter( ( item ) => {
64 return item.label.toLowerCase().indexOf( value.toLowerCase() ) !== -1;
67 menuItems.value = initialMenuItems;
72 * Update the store with the new chip values.
74 * @param {ChipInputItem[]} newChips
76 function onUpdateChips( newChips ) {
77 namespaces.value = newChips.map( ( chip ) => chip.value );