11import type { ObjectTypeDefinition , ObjectGroup , LabelObjectBase } from '../types/ObjectType' ;
22import { useT } from '../lib/useT' ;
33import { inputCls , labelCls } from '../components/Properties/styles' ;
4- import { fieldPos } from './zplHelpers' ;
4+ import { fieldPos , fdField } from './zplHelpers' ;
55import { commitHeightTransform } from './transformHelpers' ;
6+ import { filterContent , type ContentSpec } from './contentSpec' ;
67
78export interface Barcode1DProps {
89 content : string ;
@@ -16,7 +17,6 @@ interface Barcode1DConfig {
1617 label : string ;
1718 icon : string ;
1819 defaultContent : string ;
19- contentMaxLength ?: number ;
2020 hasCheckDigit : boolean ;
2121 /** Build the ZPL barcode command (e.g. `^BUN,100,Y,N,N`). */
2222 zplCommand : ( p : Barcode1DProps ) => string ;
@@ -34,6 +34,8 @@ interface Barcode1DConfig {
3434 heightLocked ?: boolean ;
3535 /** See {@link ObjectTypeDefinition.interpretationLocked}. */
3636 interpretationLocked ?: boolean ;
37+ /** Restrict allowed input characters; see {@link ContentSpec}. */
38+ contentSpec ?: ContentSpec ;
3739}
3840
3941interface BarcodeLocale {
@@ -77,7 +79,7 @@ export function createBarcode1D(config: Barcode1DConfig): ObjectTypeDefinition<B
7779 byCmd ,
7880 fieldPos ( obj ) ,
7981 config . zplCommand ( p ) ,
80- `^FD ${ p . content } ^FS` ,
82+ fdField ( p . content ) ,
8183 ] . filter ( Boolean ) . join ( '' ) ;
8284 } ,
8385
@@ -92,9 +94,9 @@ export function createBarcode1D(config: Barcode1DConfig): ObjectTypeDefinition<B
9294 < input
9395 className = { inputCls }
9496 value = { p . content }
95- maxLength = { config . contentMaxLength }
97+ maxLength = { config . contentSpec ?. maxLength }
9698 placeholder = { loc . placeholder }
97- onChange = { ( e ) => onChange ( { content : e . target . value } ) }
99+ onChange = { ( e ) => onChange ( { content : filterContent ( e . target . value , config . contentSpec ) } ) }
98100 />
99101 </ div >
100102
0 commit comments