1
- import { Controller } from '@hotwired/stimulus' ;
2
- import Backend , { type BackendInterface } from './Backend/Backend' ;
3
- import Component , { proxifyComponent } from './Component' ;
4
- import { StimulusElementDriver } from './Component/ElementDriver' ;
1
+ import { Controller } from '@hotwired/stimulus' ;
2
+ import Backend , { type BackendInterface } from './Backend/Backend' ;
3
+ import Component , { proxifyComponent } from './Component' ;
4
+ import { StimulusElementDriver } from './Component/ElementDriver' ;
5
5
import ChildComponentPlugin from './Component/plugins/ChildComponentPlugin' ;
6
6
import LazyPlugin from './Component/plugins/LazyPlugin' ;
7
7
import LoadingPlugin from './Component/plugins/LoadingPlugin' ;
8
8
import PageUnloadingPlugin from './Component/plugins/PageUnloadingPlugin' ;
9
- import type { PluginInterface } from './Component/plugins/PluginInterface' ;
9
+ import type { PluginInterface } from './Component/plugins/PluginInterface' ;
10
10
import PollingPlugin from './Component/plugins/PollingPlugin' ;
11
11
import QueryStringPlugin from './Component/plugins/QueryStringPlugin' ;
12
12
import SetValueOntoModelFieldsPlugin from './Component/plugins/SetValueOntoModelFieldsPlugin' ;
13
13
import ValidatedFieldsPlugin from './Component/plugins/ValidatedFieldsPlugin' ;
14
- import { type DirectiveModifier , parseDirectives } from './Directive/directives_parser' ;
14
+ import { type DirectiveModifier , parseDirectives } from './Directive/directives_parser' ;
15
15
import getModelBinding from './Directive/get_model_binding' ;
16
- import { elementBelongsToThisComponent , getModelDirectiveFromElement , getValueFromElement } from './dom_utils' ;
16
+ import { elementBelongsToThisComponent , getModelDirectiveFromElement , getValueFromElement } from './dom_utils' ;
17
17
import getElementAsTagText from './Util/getElementAsTagText' ;
18
18
19
- export { Component } ;
20
- export { getComponent } from './ComponentRegistry' ;
19
+ export { Component } ;
20
+ export { getComponent } from './ComponentRegistry' ;
21
21
22
22
export interface LiveEvent extends CustomEvent {
23
23
detail : {
@@ -35,15 +35,15 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
35
35
static values = {
36
36
name : String ,
37
37
url : String ,
38
- props : { type : Object , default : { } } ,
39
- propsUpdatedFromParent : { type : Object , default : { } } ,
40
- listeners : { type : Array , default : [ ] } ,
41
- eventsToEmit : { type : Array , default : [ ] } ,
42
- eventsToDispatch : { type : Array , default : [ ] } ,
43
- debounce : { type : Number , default : 150 } ,
44
- fingerprint : { type : String , default : '' } ,
45
- requestMethod : { type : String , default : 'post' } ,
46
- queryMapping : { type : Object , default : { } } ,
38
+ props : { type : Object , default : { } } ,
39
+ propsUpdatedFromParent : { type : Object , default : { } } ,
40
+ listeners : { type : Array , default : [ ] } ,
41
+ eventsToEmit : { type : Array , default : [ ] } ,
42
+ eventsToDispatch : { type : Array , default : [ ] } ,
43
+ debounce : { type : Number , default : 150 } ,
44
+ fingerprint : { type : String , default : '' } ,
45
+ requestMethod : { type : String , default : 'post' } ,
46
+ queryMapping : { type : Object , default : { } } ,
47
47
} ;
48
48
49
49
declare readonly nameValue : string ;
@@ -72,8 +72,8 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
72
72
pendingActionTriggerModelElement : HTMLElement | null = null ;
73
73
74
74
private elementEventListeners : Array < { event : string ; callback : ( event : any ) => void } > = [
75
- { event : 'input' , callback : ( event ) => this . handleInputEvent ( event ) } ,
76
- { event : 'change' , callback : ( event ) => this . handleChangeEvent ( event ) } ,
75
+ { event : 'input' , callback : ( event ) => this . handleInputEvent ( event ) } ,
76
+ { event : 'change' , callback : ( event ) => this . handleChangeEvent ( event ) } ,
77
77
] ;
78
78
private pendingFiles : { [ key : string ] : HTMLInputElement } = { } ;
79
79
@@ -128,7 +128,7 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
128
128
}
129
129
const rawAction = params . action ;
130
130
// all other params are considered action arguments
131
- const actionArgs = { ...params } ;
131
+ const actionArgs = { ...params } ;
132
132
delete actionArgs . action ;
133
133
134
134
// data-live-action-param="debounce(1000)|save"
@@ -160,8 +160,7 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
160
160
directive . modifiers . forEach ( ( modifier ) => {
161
161
if ( validModifiers . has ( modifier . name ) ) {
162
162
// variable is entirely to make ts happy
163
- const callable = validModifiers . get ( modifier . name ) ?? ( ( ) => {
164
- } ) ;
163
+ const callable = validModifiers . get ( modifier . name ) ?? ( ( ) => { } ) ;
165
164
callable ( modifier ) ;
166
165
167
166
return ;
@@ -197,19 +196,19 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
197
196
}
198
197
199
198
emit ( event : any ) {
200
- this . getEmitDirectives ( event ) . forEach ( ( { name, data, nameMatch} ) => {
199
+ this . getEmitDirectives ( event ) . forEach ( ( { name, data, nameMatch } ) => {
201
200
this . component . emit ( name , data , nameMatch ) ;
202
201
} ) ;
203
202
}
204
203
205
204
emitUp ( event : any ) {
206
- this . getEmitDirectives ( event ) . forEach ( ( { name, data, nameMatch} ) => {
205
+ this . getEmitDirectives ( event ) . forEach ( ( { name, data, nameMatch } ) => {
207
206
this . component . emitUp ( name , data , nameMatch ) ;
208
207
} ) ;
209
208
}
210
209
211
210
emitSelf ( event : any ) {
212
- this . getEmitDirectives ( event ) . forEach ( ( { name, data} ) => {
211
+ this . getEmitDirectives ( event ) . forEach ( ( { name, data } ) => {
213
212
this . component . emitSelf ( name , data ) ;
214
213
} ) ;
215
214
}
@@ -245,7 +244,7 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
245
244
}
246
245
const eventInfo = params . event ;
247
246
// all other params are considered event arguments
248
- const eventArgs = { ...params } ;
247
+ const eventArgs = { ...params } ;
249
248
delete eventArgs . event ;
250
249
251
250
// data-event="name(product_list)|some_event"
@@ -317,7 +316,7 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
317
316
attributes : true ,
318
317
} ) ;
319
318
320
- this . elementEventListeners . forEach ( ( { event, callback} ) => {
319
+ this . elementEventListeners . forEach ( ( { event, callback } ) => {
321
320
this . component . element . addEventListener ( event , callback ) ;
322
321
} ) ;
323
322
@@ -326,7 +325,7 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
326
325
327
326
private disconnectComponent ( ) {
328
327
this . component . disconnect ( ) ;
329
- this . elementEventListeners . forEach ( ( { event, callback} ) => {
328
+ this . elementEventListeners . forEach ( ( { event, callback } ) => {
330
329
this . component . element . removeEventListener ( event , callback ) ;
331
330
} ) ;
332
331
this . dispatchEvent ( 'disconnect' ) ;
@@ -432,13 +431,22 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
432
431
const finalValue = getValueFromElement ( element , this . component . valueStore ) ;
433
432
434
433
if (
435
- ( element instanceof HTMLInputElement && [ 'text' , 'email' , 'password' , 'search' , 'tel' , 'url' ] . includes ( element . type ) ) ||
434
+ ( element instanceof HTMLInputElement &&
435
+ [ 'text' , 'email' , 'password' , 'search' , 'tel' , 'url' ] . includes ( element . type ) ) ||
436
436
element instanceof HTMLTextAreaElement
437
437
) {
438
- if ( modelBinding . minLength !== null && typeof finalValue === "string" && finalValue . length < modelBinding . minLength ) {
438
+ if (
439
+ modelBinding . minLength !== null &&
440
+ typeof finalValue === 'string' &&
441
+ finalValue . length < modelBinding . minLength
442
+ ) {
439
443
return ;
440
444
}
441
- if ( modelBinding . maxLength !== null && typeof finalValue === "string" && finalValue . length > modelBinding . maxLength ) {
445
+ if (
446
+ modelBinding . maxLength !== null &&
447
+ typeof finalValue === 'string' &&
448
+ finalValue . length > modelBinding . maxLength
449
+ ) {
442
450
return ;
443
451
}
444
452
}
@@ -459,7 +467,7 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
459
467
detail . controller = this ;
460
468
detail . component = this . proxiedComponent ;
461
469
462
- this . dispatch ( name , { detail, prefix : 'live' , cancelable, bubbles : canBubble } ) ;
470
+ this . dispatch ( name , { detail, prefix : 'live' , cancelable, bubbles : canBubble } ) ;
463
471
}
464
472
465
473
private onMutations ( mutations : MutationRecord [ ] ) : void {
0 commit comments