1- import { BindingEventService } from '@slickgrid-universal/binding' ;
21import { classNameToList , createDomElement , isObject , isPrimitiveValue , setDeepValue , toKebabCase } from '@slickgrid-universal/utils' ;
32import autocompleter from 'autocompleter' ;
43import type { AutocompleteItem , AutocompleteResult , AutocompleteSettings } from 'autocompleter' ;
54import { addAutocompleteLoadingByOverridingFetch } from '../commonEditorFilter/commonEditorFilterUtils.js' ;
6- import { applyHtmlToElement , SlickEventData , type SlickGrid } from '../core/index.js' ;
5+ import { applyHtmlToElement } from '../core/index.js' ;
76import { textValidator } from '../editorValidators/textValidator.js' ;
87import type {
98 AutocompleterOption ,
109 AutocompleteSearchItem ,
1110 CollectionCustomStructure ,
1211 CollectionOverrideArgs ,
13- Column ,
14- ColumnEditor ,
1512 CompositeEditorOption ,
1613 Editor ,
1714 EditorArguments ,
1815 EditorValidationResult ,
19- EditorValidator ,
20- GridOption ,
2116 Locale ,
2217 ValidateOption ,
2318} from '../interfaces/index.js' ;
2419import type { TranslaterService } from '../services/translater.service.js' ;
2520import { findOrDefault , getDescendantProperty } from '../services/utilities.js' ;
2621import { Constants } from './../constants.js' ;
22+ import { BaseEditorClass } from './baseEditorClass.js' ;
2723
2824// minimum length of chars to type before starting to start querying
2925const MIN_LENGTH = 3 ;
@@ -32,9 +28,8 @@ const MIN_LENGTH = 3;
3228 * An example of a 'detached' editor.
3329 * KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter.
3430 */
35- export class AutocompleterEditor < T extends AutocompleteItem = any > implements Editor {
31+ export class AutocompleterEditor < T extends AutocompleteItem = any > extends BaseEditorClass implements Editor {
3632 protected _autocompleterOptions ! : Partial < AutocompleterOption < T > > ;
37- protected _bindEventService : BindingEventService ;
3833 protected _currentValue : any ;
3934 protected _defaultTextValue ! : string ;
4035 protected _originalValue : any ;
@@ -56,12 +51,6 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
5651 /** The translate library */
5752 protected _translater ?: TranslaterService ;
5853
59- /** is the Editor disabled? */
60- disabled = false ;
61-
62- /** SlickGrid Grid object */
63- grid : SlickGrid ;
64-
6554 /** The property name for labels in the collection */
6655 labelName ! : string ;
6756
@@ -80,15 +69,13 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
8069 finalCollection : T [ ] = [ ] ;
8170
8271 constructor ( protected readonly args : EditorArguments ) {
83- this . grid = args . grid ;
84- this . _bindEventService = new BindingEventService ( ) ;
72+ super ( args ) ;
8573 if ( this . gridOptions ?. translater ) {
8674 this . _translater = this . gridOptions . translater ;
8775 }
8876
8977 // get locales provided by user in forRoot or else use default English locales via the Constants
9078 this . _locales = this . gridOptions ?. locales || Constants . locales ;
91-
9279 this . init ( ) ;
9380 }
9481
@@ -112,16 +99,6 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
11299 return this . _elementCollection ;
113100 }
114101
115- /** Get Column Definition object */
116- get columnDef ( ) : Column {
117- return this . args . column ;
118- }
119-
120- /** Get Column Editor object */
121- get columnEditor ( ) : ColumnEditor {
122- return this . columnDef ?. editor || ( { } as ColumnEditor ) ;
123- }
124-
125102 /** Getter for the Custom Structure if exist */
126103 get customStructure ( ) : CollectionCustomStructure | undefined {
127104 let customStructure = this . columnEditor ?. customStructure ;
@@ -144,25 +121,11 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
144121 return { ...this . gridOptions . defaultEditorOptions ?. autocompleter , ...this . columnEditor ?. options } ;
145122 }
146123
147- /** Getter for the Grid Options pulled through the Grid Object */
148- get gridOptions ( ) : GridOption {
149- return this . grid ?. getOptions ( ) ?? { } ;
150- }
151-
152124 /** Kraaden AutoComplete instance */
153125 get instance ( ) : AutocompleteResult | undefined {
154126 return this . _instance ;
155127 }
156128
157- get hasAutoCommitEdit ( ) : boolean {
158- return this . gridOptions . autoCommitEdit ?? false ;
159- }
160-
161- /** Get the Validator function, can be passed in Editor property or Column Definition */
162- get validator ( ) : EditorValidator | undefined {
163- return this . columnEditor ?. validator ?? this . columnDef ?. validator ;
164- }
165-
166129 init ( ) : void {
167130 this . labelName = this . customStructure ?. label ?? 'label' ;
168131 this . valueName = this . customStructure ?. value ?? 'value' ;
@@ -441,17 +404,7 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
441404
442405 /** when it's a Composite Editor, we'll check if the Editor is editable (by checking onBeforeEditCell) and if not Editable we'll disable the Editor */
443406 protected applyInputUsabilityState ( ) : void {
444- const activeCell = this . grid . getActiveCell ( ) ;
445- const isCellEditable = this . grid . onBeforeEditCell
446- . notify ( {
447- ...activeCell ,
448- item : this . dataContext ,
449- column : this . args . column ,
450- grid : this . grid ,
451- target : 'composite' ,
452- compositeEditorOptions : this . args . compositeEditorOptions ,
453- } )
454- . getReturnValue ( ) ;
407+ const isCellEditable = super . checkInputUsabilityState ( ) ;
455408 this . disable ( isCellEditable === false ) ;
456409 }
457410
@@ -461,11 +414,6 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
461414 triggeredBy : 'user' | 'system' = 'user' ,
462415 isCalledByClearValue = false
463416 ) : void {
464- const activeCell = this . grid . getActiveCell ( ) ;
465- const column = this . args . column ;
466- const columnId = this . columnDef ?. id ?? '' ;
467- const item = this . dataContext ;
468- const grid = this . grid ;
469417 const newValue = this . serializeValue ( ) ;
470418
471419 // when valid, we'll also apply the new value to the dataContext item object
@@ -474,25 +422,7 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
474422 }
475423 this . applyValue ( compositeEditorOptions . formValues , newValue ) ;
476424
477- const isExcludeDisabledFieldFormValues = this . gridOptions ?. compositeEditorOptions ?. excludeDisabledFieldFormValues ?? false ;
478- if (
479- isCalledByClearValue ||
480- ( this . disabled && isExcludeDisabledFieldFormValues && compositeEditorOptions . formValues . hasOwnProperty ( columnId ) )
481- ) {
482- delete compositeEditorOptions . formValues [ columnId ] ; // when the input is disabled we won't include it in the form result object
483- }
484- grid . onCompositeEditorChange . notify (
485- {
486- ...activeCell ,
487- item,
488- grid,
489- column,
490- formValues : compositeEditorOptions . formValues ,
491- editors : compositeEditorOptions . editors ,
492- triggeredBy,
493- } ,
494- new SlickEventData ( event )
495- ) ;
425+ super . handleChangeOnCompositeEditor ( event , compositeEditorOptions , triggeredBy , isCalledByClearValue ) ;
496426 }
497427
498428 // this function should be protected but for unit tests purposes we'll make it public until a better solution is found
0 commit comments