@@ -289,28 +289,20 @@ function attachFlatpickr(node, opts, plugins = opts.noCalendar ? [] : [yearDropd
289
289
return fp ;
290
290
}
291
291
292
- /** @type {import('svelte/action').Action<HTMLInputElement,FlatpickrOptions,EventKey> } */
293
- const datePicker = ( node , options ) => {
294
- options = { ...defaultOptions , ...options } ;
295
- const opts = modifyHooks ( options ) ;
296
- const instance = attachFlatpickr ( node , opts ) ;
297
-
298
- $effect ( ( ) => {
299
- if ( opts . defaultDate ) {
300
- const event = new Event ( 'input' ) ;
301
- node . dispatchEvent ( event ) ;
292
+ /** @type {import('svelte/action').Action } */
293
+ export default function ( node , options = defaultOptions ) {
294
+ if ( options . isMonthPicker ) {
295
+ options = {
296
+ ...defaultMonthOptions , ...options
302
297
}
303
- return ( ) => {
304
- instance . destroy ( ) ;
305
- instance . _input ?. form ?. removeEventListener ( 'reset' , ( ev ) => resetFlatpickr ( ev , instance , opts ) ) ;
306
- } ;
307
- } ) ;
308
- }
298
+ } else {
299
+ options = {
300
+ ...defaultOptions , ...options
301
+ }
302
+ }
309
303
310
- /** @type {import('svelte/action').Action<HTMLInputElement,FlatpickrOptions,EventKey> } */
311
- const monthPicker = ( node , options ) => {
312
- options = { ...defaultOptions , ...options } ;
313
304
const opts = modifyHooks ( options ) ;
305
+
314
306
const monthPlugins =
315
307
[
316
308
monthSelectPlugin ( {
@@ -320,31 +312,17 @@ const monthPicker = (node, options) => {
320
312
} ) ,
321
313
yearDropdownPlugin ( ) ,
322
314
]
323
- const instance = attachFlatpickr ( node , opts , monthPlugins ) ;
315
+
316
+ const instance = attachFlatpickr ( node , opts , options . isMonthPicker ? monthPlugins : [ ] ) ;
317
+
324
318
$effect ( ( ) => {
325
319
if ( opts . defaultDate ) {
326
320
const event = new Event ( 'input' ) ;
327
321
node . dispatchEvent ( event ) ;
328
322
}
329
-
330
323
return ( ) => {
331
324
instance . destroy ( ) ;
332
325
instance . _input ?. form ?. removeEventListener ( 'reset' , ( ev ) => resetFlatpickr ( ev , instance , opts ) ) ;
333
326
} ;
334
327
} ) ;
335
- }
336
-
337
- /** @type {import('svelte/action').Action<HTMLInputElement,FlatpickrOptions,EventKey> } */
338
- export default function ( node , options = defaultOptions ) {
339
- if ( options . isMonthPicker ) {
340
- options = {
341
- ...defaultMonthOptions , ...options
342
- }
343
- monthPicker ( node , options ) ;
344
- } else {
345
- options = {
346
- ...defaultOptions , ...options
347
- }
348
- datePicker ( node , options ) ;
349
- }
350
328
}
0 commit comments