22
33export function init ( id ) {
44 const el = document . getElementById ( id ) ;
5- const input = el . querySelector ( '.bb-opt-input-val' ) ;
65 const skipKeys = [ 'Enter' , 'Tab' , 'Shift' , 'Control' , 'Alt' ] ;
76 EventHandler . on ( el , 'input' , '.bb-opt-item' , e => {
87 const isNumber = e . target . getAttribute ( 'type' ) === 'number' ;
@@ -11,7 +10,7 @@ export function init(id) {
1110 e . target . value = e . target . value . slice ( 1 , 2 ) ;
1211 }
1312 }
14- input . value = [ ... el . querySelectorAll ( '.bb-opt-item' ) ] . map ( input => input . value ) . join ( '' ) ;
13+ setValue ( el ) ;
1514 } ) ;
1615 EventHandler . on ( el , 'keydown' , '.bb-opt-item' , e => {
1716 if ( e . ctrlKey ) {
@@ -48,6 +47,29 @@ export function init(id) {
4847 e . target . select ( ) ;
4948 }
5049 } ) ;
50+
51+ EventHandler . on ( el , 'paste' , e => {
52+ if ( e . clipboardData && e . clipboardData . getData ) {
53+ const pastedText = e . clipboardData . getData ( 'text/plain' ) ;
54+ const inputs = [ ...el . querySelectorAll ( '.bb-opt-item' ) ] ;
55+ for ( const index in inputs ) {
56+ const input = inputs [ index ] ;
57+ if ( index < pastedText . length ) {
58+ input . value = pastedText [ index ] ;
59+ }
60+ else {
61+ input . value = '' ;
62+ }
63+ }
64+ }
65+ e . target . blur ( ) ;
66+ setValue ( el ) ;
67+ } ) ;
68+ }
69+
70+ const setValue = el => {
71+ const input = el . querySelector ( '.bb-opt-input-val' ) ;
72+ input . value = [ ...el . querySelectorAll ( '.bb-opt-item' ) ] . map ( input => input . value ) . join ( '' ) ;
5173}
5274
5375const setPrevFocus = ( el , target ) => {
0 commit comments