@@ -289,28 +289,20 @@ function attachFlatpickr(node, opts, plugins = opts.noCalendar ? [] : [yearDropd
289289 return fp ;
290290}
291291
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
302297 }
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+ }
309303
310- /** @type {import('svelte/action').Action<HTMLInputElement,FlatpickrOptions,EventKey> } */
311- const monthPicker = ( node , options ) => {
312- options = { ...defaultOptions , ...options } ;
313304 const opts = modifyHooks ( options ) ;
305+
314306 const monthPlugins =
315307 [
316308 monthSelectPlugin ( {
@@ -320,31 +312,17 @@ const monthPicker = (node, options) => {
320312 } ) ,
321313 yearDropdownPlugin ( ) ,
322314 ]
323- const instance = attachFlatpickr ( node , opts , monthPlugins ) ;
315+
316+ const instance = attachFlatpickr ( node , opts , options . isMonthPicker ? monthPlugins : [ ] ) ;
317+
324318 $effect ( ( ) => {
325319 if ( opts . defaultDate ) {
326320 const event = new Event ( 'input' ) ;
327321 node . dispatchEvent ( event ) ;
328322 }
329-
330323 return ( ) => {
331324 instance . destroy ( ) ;
332325 instance . _input ?. form ?. removeEventListener ( 'reset' , ( ev ) => resetFlatpickr ( ev , instance , opts ) ) ;
333326 } ;
334327 } ) ;
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- }
350328}
0 commit comments