File tree Expand file tree Collapse file tree
src/BootstrapBlazor/Components/IpAddress Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import Data from "../../modules/data.js"
1+ import Data from "../../modules/data.js"
22import EventHandler from "../../modules/event-handler.js"
33
44const selectCell = ( el , index ) => {
@@ -73,7 +73,7 @@ export function init(id) {
7373 e . preventDefault ( )
7474 selectCell ( el , index - 1 )
7575 }
76- else if ( e . key === 'Delete' || e . key === 'Tab' || e . key === 'ArrowLeft' || e . key === 'ArrowRight' ) {
76+ else if ( e . composed || e . key === 'Delete' || e . key === 'Tab' || e . key === 'ArrowLeft' || e . key === 'ArrowRight' ) {
7777
7878 }
7979 else {
@@ -89,6 +89,26 @@ export function init(id) {
8989 }
9090 }
9191 } )
92+
93+ EventHandler . on ( c , 'paste' , e => {
94+ e . preventDefault ( ) ;
95+ const raw = ( e . clipboardData || window . clipboardData ) ?. getData ( 'text' ) ?? '' ;
96+ if ( ! raw ) {
97+ return ;
98+ }
99+ const parts = raw . replace ( / [ ^ \d . ] / g, '' ) . split ( '.' ) . filter ( p => p . length ) ;
100+ const cells = el . querySelectorAll ( ".ipv4-cell" ) ;
101+ let pos = 0 ;
102+ parts . forEach ( p => {
103+ if ( pos > 3 ) {
104+ return ;
105+ }
106+ const num = Math . max ( 0 , Math . min ( 255 , parseInt ( p , 10 ) || 0 ) ) ;
107+ cells [ pos ] . value = num . toString ( ) ;
108+ ip . prevValues [ pos ] = cells [ pos ] . value ;
109+ pos ++ ;
110+ } ) ;
111+ } ) ;
92112 } )
93113}
94114
You can’t perform that action at this time.
0 commit comments