ngxsmk-datepicker 1.4.16 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -2,73 +2,302 @@ import * as i0 from '@angular/core';
2
2
  import { OnInit, OnChanges, OnDestroy, EventEmitter, SimpleChanges } from '@angular/core';
3
3
  import { ControlValueAccessor } from '@angular/forms';
4
4
 
5
+ /**
6
+ * Type-safe definitions for ngxsmk-datepicker
7
+ * Provides strict typing and generic safety for all datepicker configurations
8
+ */
9
+ /**
10
+ * Supported datepicker selection modes
11
+ */
12
+ type DatepickerMode = 'single' | 'range' | 'multiple';
13
+ /**
14
+ * Generic date input that supports multiple formats
15
+ * - Native Date object
16
+ * - ISO 8601 string
17
+ * - Unix timestamp (number)
18
+ * - Moment.js objects
19
+ * - Day.js objects
20
+ * - date-fns objects
21
+ */
22
+ type DateInput = Date | string | number | {
23
+ toDate: () => Date;
24
+ _isAMomentObject?: boolean;
25
+ } | {
26
+ $d: Date;
27
+ } | {
28
+ toISOString: () => string;
29
+ };
30
+ /**
31
+ * Date range tuple with start and end dates
32
+ */
33
+ type DateRangeTuple = readonly [DateInput, DateInput];
34
+ /**
35
+ * Object representation of a date range
36
+ */
37
+ interface DateRangeObject {
38
+ readonly start: Date;
39
+ readonly end: Date;
40
+ }
41
+ /**
42
+ * Named date ranges for quick selection
43
+ */
44
+ type DateRanges = Readonly<Record<string, DateRangeTuple>>;
45
+ /**
46
+ * Mode-specific datepicker values with strict typing
47
+ */
48
+ type DatepickerValueByMode<T extends DatepickerMode> = T extends 'single' ? Date | null : T extends 'range' ? DateRangeObject | null : T extends 'multiple' ? readonly Date[] | null : never;
49
+ /**
50
+ * Generic datepicker value (when mode is not known at compile time)
51
+ */
52
+ type DatepickerValue = Date | DateRangeObject | Date[] | null;
53
+ /**
54
+ * Holiday provider interface for custom holiday definitions
55
+ */
56
+ interface HolidayProvider {
57
+ /**
58
+ * Check if a given date is a holiday
59
+ * @param date - Date to check (normalized to start of day)
60
+ * @returns true if date is a holiday
61
+ */
62
+ isHoliday(date: Date): boolean;
63
+ /**
64
+ * Get holiday label/name for a given date
65
+ * @param date - Date to check
66
+ * @returns Holiday label or null if not a holiday
67
+ */
68
+ getHolidayLabel?(date: Date): string | null;
69
+ /**
70
+ * Get all holidays for a given year
71
+ * @param year - Year to get holidays for
72
+ * @returns Array of holiday dates
73
+ */
74
+ getHolidays?(year: number): readonly Date[];
75
+ }
76
+ /**
77
+ * Highlighted date configuration
78
+ */
79
+ interface HighlightedDate {
80
+ readonly date: Date;
81
+ readonly color: string;
82
+ readonly label?: string;
83
+ readonly tooltip?: string;
84
+ }
85
+ /**
86
+ * Time preset for quick time selection
87
+ */
88
+ interface TimePreset {
89
+ readonly label: string;
90
+ readonly hour: number;
91
+ readonly minute: number;
92
+ }
93
+ /**
94
+ * Quick selection button configuration
95
+ */
96
+ interface QuickButton<T extends DatepickerMode = 'single'> {
97
+ readonly label: string;
98
+ getValue(): DatepickerValueByMode<T>;
99
+ }
100
+ /**
101
+ * Date filter function for custom validation
102
+ */
103
+ type DateFilter = (date: Date) => boolean;
104
+ /**
105
+ * Datepicker action event types
106
+ */
107
+ type DatepickerActionType = 'select' | 'clear' | 'cancel' | 'apply' | 'open' | 'close' | 'monthChange' | 'yearChange';
108
+ /**
109
+ * Datepicker action event payload
110
+ */
111
+ interface DatepickerAction<T extends DatepickerMode = DatepickerMode> {
112
+ readonly type: DatepickerActionType;
113
+ readonly value?: DatepickerValueByMode<T>;
114
+ readonly metadata?: Readonly<Record<string, unknown>>;
115
+ }
116
+ /**
117
+ * Min/Max time configuration
118
+ */
119
+ interface TimeConstraints {
120
+ readonly hour: number;
121
+ readonly minute: number;
122
+ }
123
+ /**
124
+ * Custom error messages configuration
125
+ */
126
+ interface DatepickerErrorMessages {
127
+ readonly required?: string;
128
+ readonly minDate?: string;
129
+ readonly maxDate?: string;
130
+ readonly invalidDate?: string;
131
+ readonly minDays?: string;
132
+ readonly maxDays?: string;
133
+ readonly disabledDate?: string;
134
+ }
135
+ /**
136
+ * Datepicker theme type
137
+ */
138
+ type DatepickerTheme = 'light' | 'dark' | 'auto';
139
+ /**
140
+ * Select option for dropdowns
141
+ */
142
+ interface SelectOption<T = number | string> {
143
+ readonly label: string;
144
+ readonly value: T;
145
+ readonly disabled?: boolean;
146
+ }
147
+ /**
148
+ * Calendar day cell data
149
+ */
150
+ interface CalendarDay {
151
+ readonly date: Date;
152
+ readonly isCurrentMonth: boolean;
153
+ readonly isToday: boolean;
154
+ readonly isWeekend: boolean;
155
+ readonly isDisabled: boolean;
156
+ readonly isSelected: boolean;
157
+ readonly isInRange: boolean;
158
+ readonly isHoliday: boolean;
159
+ readonly holidayLabel?: string;
160
+ readonly highlightColor?: string;
161
+ readonly highlightLabel?: string;
162
+ }
163
+ /**
164
+ * Type guard to check if value is a single date
165
+ */
166
+ declare function isSingleDate(value: DatepickerValue): value is Date;
167
+ /**
168
+ * Type guard to check if value is a date range
169
+ */
170
+ declare function isDateRange(value: DatepickerValue): value is DateRangeObject;
171
+ /**
172
+ * Type guard to check if value is multiple dates
173
+ */
174
+ declare function isMultipleDates(value: DatepickerValue): value is Date[];
175
+ /**
176
+ * Type guard to check if date input is a Date object
177
+ */
178
+ declare function isNativeDate(input: DateInput): input is Date;
179
+ /**
180
+ * Type guard to check if date input is a string
181
+ */
182
+ declare function isDateString(input: DateInput): input is string;
183
+ /**
184
+ * Type guard to check if date input is a number (timestamp)
185
+ */
186
+ declare function isTimestamp(input: DateInput): input is number;
187
+ /**
188
+ * Datepicker configuration options (for future use)
189
+ */
190
+ interface DatepickerConfig<T extends DatepickerMode = 'single'> {
191
+ readonly mode: T;
192
+ readonly locale?: string;
193
+ readonly theme?: DatepickerTheme;
194
+ readonly inline?: boolean;
195
+ readonly showTime?: boolean;
196
+ readonly minDate?: DateInput | null;
197
+ readonly maxDate?: DateInput | null;
198
+ readonly disabledDates?: readonly DateInput[];
199
+ readonly isInvalidDate?: DateFilter;
200
+ readonly holidayProvider?: HolidayProvider;
201
+ readonly highlightedDates?: readonly HighlightedDate[];
202
+ readonly ranges?: DateRanges;
203
+ readonly placeholder?: string;
204
+ readonly disabled?: boolean;
205
+ }
206
+ /**
207
+ * Validation result type
208
+ */
209
+ interface ValidationResult {
210
+ readonly valid: boolean;
211
+ readonly error?: string;
212
+ readonly errorCode?: string;
213
+ }
214
+ /**
215
+ * Validation result
216
+ */
217
+ interface ValidationResult {
218
+ readonly valid: boolean;
219
+ readonly error?: string;
220
+ readonly errorCode?: string;
221
+ }
222
+ /**
223
+ * Export type for datepicker data
224
+ */
225
+ type ExportFormat = 'json' | 'csv' | 'ical';
226
+ /**
227
+ * Export data structure
228
+ */
229
+ interface ExportData {
230
+ readonly format: ExportFormat;
231
+ readonly data: string;
232
+ readonly timestamp: number;
233
+ }
234
+
5
235
  /**
6
236
  * Date utility functions for ngxsmk-datepicker
7
237
  * Extracted to improve tree-shaking and reduce bundle size
8
238
  */
239
+
240
+ /**
241
+ * Get start of day (00:00:00.000)
242
+ */
9
243
  declare function getStartOfDay(d: Date): Date;
244
+ /**
245
+ * Get end of day (23:59:59.999)
246
+ */
10
247
  declare function getEndOfDay(d: Date): Date;
248
+ /**
249
+ * Add months to a date
250
+ */
11
251
  declare function addMonths(d: Date, months: number): Date;
252
+ /**
253
+ * Subtract days from a date
254
+ */
12
255
  declare function subtractDays(d: Date, days: number): Date;
256
+ /**
257
+ * Get start of month
258
+ */
13
259
  declare function getStartOfMonth(d: Date): Date;
260
+ /**
261
+ * Get end of month
262
+ */
14
263
  declare function getEndOfMonth(d: Date): Date;
264
+ /**
265
+ * Check if two dates are on the same day
266
+ */
15
267
  declare function isSameDay(d1: Date | null, d2: Date | null): boolean;
16
- declare function normalizeDate(date: DateInput | null): Date | null;
17
- type DateInput = Date | string | {
18
- toDate: () => Date;
19
- _isAMomentObject?: boolean;
20
- $d?: Date;
21
- };
268
+ /**
269
+ * Normalize various date input formats to Date object
270
+ * Supports:
271
+ * - Date objects
272
+ * - ISO strings
273
+ * - Unix timestamps
274
+ * - Moment.js objects
275
+ * - Day.js objects
276
+ */
277
+ declare function normalizeDate(date: DateInput | null | undefined): Date | null;
22
278
 
23
279
  /**
24
280
  * Calendar utility functions for ngxsmk-datepicker
25
281
  * Optimized for performance and tree-shaking
26
282
  */
27
283
 
28
- interface HolidayProvider {
29
- /**
30
- * Returns true if the given date is a holiday.
31
- * The date passed will be at the start of the day (00:00:00).
32
- */
33
- isHoliday(date: Date): boolean;
34
- /**
35
- * Optional: Returns a label or reason for the holiday.
36
- */
37
- getHolidayLabel?(date: Date): string | null;
38
- }
39
284
  interface DateRange {
40
285
  [key: string]: [DateInput, DateInput];
41
286
  }
42
- type DatepickerValue = Date | {
43
- start: Date;
44
- end: Date;
45
- } | Date[] | null;
46
287
  /**
47
288
  * Generate month options for dropdown
48
289
  */
49
- declare function generateMonthOptions(locale: string, year: number): {
50
- label: string;
51
- value: number;
52
- }[];
290
+ declare function generateMonthOptions(locale: string, year: number): SelectOption<number>[];
53
291
  /**
54
292
  * Generate year options for dropdown
55
293
  */
56
- declare function generateYearOptions(currentYear: number, range?: number): {
57
- label: string;
58
- value: number;
59
- }[];
294
+ declare function generateYearOptions(currentYear: number, range?: number): SelectOption<number>[];
60
295
  /**
61
296
  * Generate time options for hour/minute dropdowns
62
297
  */
63
298
  declare function generateTimeOptions(minuteInterval?: number): {
64
- hourOptions: {
65
- label: string;
66
- value: number;
67
- }[];
68
- minuteOptions: {
69
- label: string;
70
- value: number;
71
- }[];
299
+ hourOptions: SelectOption<number>[];
300
+ minuteOptions: SelectOption<number>[];
72
301
  };
73
302
  /**
74
303
  * Generate week days for calendar header
@@ -252,5 +481,185 @@ declare class CustomSelectComponent {
252
481
  static ɵcmp: i0.ɵɵComponentDeclaration<CustomSelectComponent, "ngxsmk-custom-select", never, { "options": { "alias": "options"; "required": false; }; "value": { "alias": "value"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; }, { "valueChange": "valueChange"; }, never, never, true, never>;
253
482
  }
254
483
 
255
- export { CustomSelectComponent, NgxsmkDatepickerComponent, addMonths, generateMonthOptions, generateTimeOptions, generateWeekDays, generateYearOptions, get24Hour, getEndOfDay, getEndOfMonth, getFirstDayOfWeek, getStartOfDay, getStartOfMonth, isSameDay, normalizeDate, processDateRanges, subtractDays, update12HourState };
256
- export type { DateInput, DateRange, DatepickerValue, HolidayProvider };
484
+ /**
485
+ * Performance utilities for ngxsmk-datepicker
486
+ * Optimized for minimal bundle size and tree-shaking
487
+ */
488
+ declare const createDateComparator: () => (d1: Date | null, d2: Date | null) => boolean;
489
+
490
+ /**
491
+ * Week utilities for ngxsmk-datepicker
492
+ * Lazy-loaded to reduce initial bundle size
493
+ */
494
+ /**
495
+ * Get ISO week number
496
+ */
497
+ declare function getISOWeek(date: Date): number;
498
+ /**
499
+ * Get week of month
500
+ */
501
+ declare function getWeekOfMonth(date: Date): number;
502
+ /**
503
+ * Get date range for a week
504
+ */
505
+ declare function getWeekRange(date: Date, firstDayOfWeek?: number): {
506
+ start: Date;
507
+ end: Date;
508
+ };
509
+
510
+ /**
511
+ * Format utilities for ngxsmk-datepicker
512
+ * Lazy-loaded to reduce initial bundle size
513
+ */
514
+ /**
515
+ * Format date with custom format string
516
+ */
517
+ declare function formatDate(date: Date, format: string, locale?: string): string;
518
+ /**
519
+ * Parse date from string with format
520
+ */
521
+ declare function parseDate(dateStr: string, _format?: string): Date | null;
522
+
523
+ /**
524
+ * Validation utilities for ngxsmk-datepicker
525
+ * Lazy-loaded to reduce initial bundle size
526
+ */
527
+
528
+ /**
529
+ * Validate date range
530
+ */
531
+ declare function validateDateRange(start: Date | null, end: Date | null, minDate?: Date | null, maxDate?: Date | null): ValidationResult;
532
+ /**
533
+ * Validate min/max days in range
534
+ */
535
+ declare function validateMinMaxDays(start: Date | null, end: Date | null, minDays?: number, maxDays?: number): ValidationResult;
536
+ /**
537
+ * Validate working days
538
+ */
539
+ declare function validateWorkingDays(date: Date, workingDays?: number[]): ValidationResult;
540
+
541
+ /**
542
+ * Timezone utilities for ngxsmk-datepicker
543
+ * Lazy-loaded to reduce initial bundle size
544
+ */
545
+ /**
546
+ * Convert date to specific timezone
547
+ */
548
+ declare function convertToTimezone(date: Date, timezone: string): Date;
549
+ /**
550
+ * Get timezone offset in minutes
551
+ */
552
+ declare function getTimezoneOffset(timezone: string): number;
553
+
554
+ /**
555
+ * Export/Import utilities for ngxsmk-datepicker
556
+ * Lazy-loaded to reduce initial bundle size
557
+ */
558
+
559
+ /**
560
+ * Export dates to JSON format
561
+ */
562
+ declare function exportToJSON(value: DatepickerValue): string;
563
+ /**
564
+ * Export dates to CSV format
565
+ */
566
+ declare function exportToCSV(value: DatepickerValue): string;
567
+ /**
568
+ * Export dates to iCal format
569
+ */
570
+ declare function exportToICal(value: DatepickerValue, title?: string): string;
571
+ /**
572
+ * Import dates from JSON format
573
+ */
574
+ declare function importFromJSON(json: string): DatepickerValue;
575
+ /**
576
+ * Import dates from CSV format
577
+ */
578
+ declare function importFromCSV(csv: string): Date[] | null;
579
+
580
+ /**
581
+ * Lazy-loaded features for ngxsmk-datepicker
582
+ * These features are loaded on-demand to reduce initial bundle size
583
+ */
584
+ /**
585
+ * Export/Import Feature
586
+ * Dynamically loaded when export functionality is used
587
+ */
588
+ declare function loadExportFeature(): Promise<{
589
+ exportToJSON: typeof exportToJSON;
590
+ exportToCSV: typeof exportToCSV;
591
+ exportToICal: typeof exportToICal;
592
+ importFromJSON: typeof importFromJSON;
593
+ importFromCSV: typeof importFromCSV;
594
+ }>;
595
+ /**
596
+ * Timezone Feature
597
+ * Dynamically loaded when timezone conversion is needed
598
+ */
599
+ declare function loadTimezoneFeature(): Promise<{
600
+ convertToTimezone: typeof convertToTimezone;
601
+ getTimezoneOffset: typeof getTimezoneOffset;
602
+ }>;
603
+ /**
604
+ * Validation Feature
605
+ * Dynamically loaded when advanced validation is needed
606
+ */
607
+ declare function loadValidationFeature(): Promise<{
608
+ validateDateRange: typeof validateDateRange;
609
+ validateMinMaxDays: typeof validateMinMaxDays;
610
+ validateWorkingDays: typeof validateWorkingDays;
611
+ }>;
612
+ /**
613
+ * Format Feature
614
+ * Dynamically loaded when custom formatting is needed
615
+ */
616
+ declare function loadFormatFeature(): Promise<{
617
+ formatDate: typeof formatDate;
618
+ parseDate: typeof parseDate;
619
+ }>;
620
+ /**
621
+ * Week Utilities Feature
622
+ * Dynamically loaded when week-related calculations are needed
623
+ */
624
+ declare function loadWeekFeature(): Promise<{
625
+ getISOWeek: typeof getISOWeek;
626
+ getWeekOfMonth: typeof getWeekOfMonth;
627
+ getWeekRange: typeof getWeekRange;
628
+ }>;
629
+ /**
630
+ * Locale Data Loader
631
+ * Dynamically loads locale-specific data
632
+ */
633
+ declare function loadLocaleData(locale: string): Promise<{
634
+ locale: string;
635
+ loaded: boolean;
636
+ weekStart: number;
637
+ }>;
638
+ /**
639
+ * Feature flags for lazy loading
640
+ */
641
+ declare const LAZY_FEATURES: {
642
+ readonly EXPORT: "export";
643
+ readonly TIMEZONE: "timezone";
644
+ readonly VALIDATION: "validation";
645
+ readonly FORMAT: "format";
646
+ readonly WEEK: "week";
647
+ readonly LOCALE: "locale";
648
+ };
649
+ type LazyFeature = typeof LAZY_FEATURES[keyof typeof LAZY_FEATURES];
650
+ declare function loadFeature(feature: LazyFeature): Promise<any>;
651
+ /**
652
+ * Preload specific features
653
+ */
654
+ declare function preloadFeatures(features: LazyFeature[]): Promise<any[]>;
655
+ /**
656
+ * Check if feature is loaded
657
+ */
658
+ declare function isFeatureLoaded(feature: LazyFeature): boolean;
659
+ /**
660
+ * Clear feature cache (useful for testing or memory management)
661
+ */
662
+ declare function clearFeatureCache(): void;
663
+
664
+ export { CustomSelectComponent, LAZY_FEATURES, NgxsmkDatepickerComponent, addMonths, clearFeatureCache, createDateComparator, generateMonthOptions, generateTimeOptions, generateWeekDays, generateYearOptions, get24Hour, getEndOfDay, getEndOfMonth, getFirstDayOfWeek, getStartOfDay, getStartOfMonth, isDateRange, isDateString, isFeatureLoaded, isMultipleDates, isNativeDate, isSameDay, isSingleDate, isTimestamp, loadExportFeature, loadFeature, loadFormatFeature, loadLocaleData, loadTimezoneFeature, loadValidationFeature, loadWeekFeature, normalizeDate, preloadFeatures, processDateRanges, subtractDays, update12HourState };
665
+ export type { CalendarDay, DateFilter, DateInput, DateRange, DateRangeObject, DateRangeTuple, DateRanges, DatepickerAction, DatepickerActionType, DatepickerConfig, DatepickerErrorMessages, DatepickerMode, DatepickerTheme, DatepickerValue, DatepickerValueByMode, ExportData, ExportFormat, HighlightedDate, HolidayProvider, LazyFeature, QuickButton, SelectOption, TimeConstraints, TimePreset, ValidationResult };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "ngxsmk-datepicker",
3
- "version": "1.4.16",
3
+ "version": "1.6.0",
4
4
  "author": {
5
5
  "name": "Sachin Dilshan",
6
6
  "url": "https://www.linkedin.com/in/sachindilshan/"
7
7
  },
8
8
  "peerDependencies": {
9
- "@angular/common": ">=17.0.0",
10
- "@angular/core": ">=17.0.0",
11
- "@angular/forms": ">=17.0.0"
9
+ "@angular/common": ">=17.0.0 <22.0.0",
10
+ "@angular/core": ">=17.0.0 <22.0.0",
11
+ "@angular/forms": ">=17.0.0 <22.0.0"
12
12
  },
13
13
  "dependencies": {
14
14
  "tslib": "^2.3.0"
@@ -18,7 +18,7 @@
18
18
  "es2022": "fesm2022/ngxsmk-datepicker.mjs",
19
19
  "esm2022": "fesm2022/ngxsmk-datepicker.mjs",
20
20
  "types": "index.d.ts",
21
- "typings": "index.d.ts",
21
+ "typings": "types/ngxsmk-datepicker.d.ts",
22
22
  "homepage": "https://github.com/toozuuu/ngxsmk-datepicker#readme",
23
23
  "repository": {
24
24
  "type": "git",
@@ -43,7 +43,11 @@
43
43
  "date-range-picker",
44
44
  "calendar",
45
45
  "standalone-component",
46
+ "angular-17",
47
+ "angular-18",
48
+ "angular-19",
46
49
  "angular-20",
50
+ "angular-21",
47
51
  "typescript",
48
52
  "date-selection",
49
53
  "i18n",
@@ -53,7 +57,7 @@
53
57
  ".": {
54
58
  "import": "./fesm2022/ngxsmk-datepicker.mjs",
55
59
  "require": "./fesm2022/ngxsmk-datepicker.mjs",
56
- "types": "./index.d.ts",
60
+ "types": "./types/ngxsmk-datepicker.d.ts",
57
61
  "default": "./fesm2022/ngxsmk-datepicker.mjs"
58
62
  },
59
63
  "./package.json": {