@@ -30,7 +30,7 @@ import React, {
3030 useState ,
3131 useContext ,
3232} from "react" ;
33- import { arrayStringExposingStateControl } from "comps/controls/codeStateControl" ;
33+ import { arrayStringExposingStateControl , stringExposingStateControl } from "comps/controls/codeStateControl" ;
3434import { BoolControl } from "comps/controls/boolControl" ;
3535import { RefControl } from "comps/controls/refControl" ;
3636import { EditorContext } from "comps/editorState" ;
@@ -120,6 +120,7 @@ const BarcodeScannerComponent = React.lazy(
120120const ScannerTmpComp = ( function ( ) {
121121 const childrenMap = {
122122 data : arrayStringExposingStateControl ( "data" ) ,
123+ value : stringExposingStateControl ( "value" ) ,
123124 text : withDefault ( StringControl , trans ( "scanner.text" ) ) ,
124125 continuous : BoolControl ,
125126 uniqueData : withDefault ( BoolControl , true ) ,
@@ -150,17 +151,27 @@ const ScannerTmpComp = (function () {
150151 } , [ success , showModal ] ) ;
151152
152153 const continuousValue = useRef < string [ ] > ( [ ] ) ;
154+ const seenSetRef = useRef < Set < string > > ( new Set ( ) ) ;
153155
154156 const handleUpdate = ( err : any , result : any ) => {
155157 if ( result ) {
156158 if ( props . continuous ) {
157- continuousValue . current = [ ...continuousValue . current , result . text ] ;
159+ const scannedText : string = result . text ;
160+ if ( props . uniqueData && seenSetRef . current . has ( scannedText ) ) {
161+ return ;
162+ }
163+ continuousValue . current = [ ...continuousValue . current , scannedText ] ;
164+ if ( props . uniqueData ) {
165+ seenSetRef . current . add ( scannedText ) ;
166+ }
158167 const val = props . uniqueData
159168 ? [ ...new Set ( continuousValue . current ) ]
160169 : continuousValue . current ;
170+ props . value . onChange ( scannedText ) ;
161171 props . data . onChange ( val ) ;
162172 props . onEvent ( "success" ) ;
163173 } else {
174+ props . value . onChange ( result . text ) ;
164175 props . data . onChange ( [ result . text ] ) ;
165176 setShowModal ( false ) ;
166177 setSuccess ( true ) ;
@@ -205,6 +216,7 @@ const ScannerTmpComp = (function () {
205216 props . onEvent ( "click" ) ;
206217 setShowModal ( true ) ;
207218 continuousValue . current = [ ] ;
219+ seenSetRef . current = new Set ( ) ;
208220 } }
209221 >
210222 < span > { props . text } </ span >
@@ -317,6 +329,7 @@ const ScannerTmpComp = (function () {
317329
318330export const ScannerComp = withExposingConfigs ( ScannerTmpComp , [
319331 new NameConfig ( "data" , trans ( "data" ) ) ,
332+ new NameConfig ( "value" , trans ( "value" ) ) ,
320333 new NameConfig ( "text" , trans ( "button.textDesc" ) ) ,
321334 ...CommonNameConfig ,
322335] ) ;
0 commit comments