cally 0.9.1 → 0.10.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.
Files changed (3) hide show
  1. package/dist/cally.d.ts +504 -9
  2. package/dist/cally.js +621 -561
  3. package/package.json +5 -2
package/dist/cally.d.ts CHANGED
@@ -1,6 +1,26 @@
1
- import { Atomico } from 'atomico/types/dom';
2
- import { DaysOfWeek } from '../utils/date.js';
3
- import { Pagination } from '../calendar-base/useCalendarBase.js';
1
+ declare interface Atomico<Props, PropsForInstance, Base>
2
+ extends AtomicoStatic<Props> {
3
+ new (
4
+ props?: JSXProxy<
5
+ DOMTag<DOMThis<Base>, Props>,
6
+ AtomicoThis<PropsForInstance, Base>
7
+ >
8
+ ): AtomicoThis<PropsForInstance, Base>;
9
+ }
10
+
11
+ declare interface AtomicoStatic<Props> extends HTMLElement {
12
+ styles: Sheets[];
13
+ props: SchemaInfer<Props>;
14
+ /**
15
+ * Meta property, allows associating the component's
16
+ * props in typescript to external environments.
17
+ */
18
+ readonly "##props": Props;
19
+ /**
20
+ * Allows to identify a constructor created with Atomico
21
+ */
22
+ readonly "##atomico": true;
23
+ }
4
24
 
5
25
  declare type AtomicoThis<Props = {}, Base = HTMLElement> = Props &
6
26
  DOMThis<Base> & {
@@ -13,8 +33,8 @@ DOMThis<Base> & {
13
33
 
14
34
  export declare const CalendarDate: Atomico< {
15
35
  months: number;
16
- value: string;
17
36
  focus: (options?: CalendarFocusOptions) => void;
37
+ value: string;
18
38
  firstDayOfWeek: DaysOfWeek;
19
39
  isDateDisallowed: (date: Date) => boolean;
20
40
  min: string;
@@ -29,10 +49,11 @@ showOutsideDays: boolean;
29
49
  showWeekNumbers: boolean;
30
50
  pageBy: Pagination;
31
51
  onChange: (event: Event) => any;
52
+ onPageChange: (event: CustomEvent<PageChangeDetail>) => any;
32
53
  } & {}, {
33
54
  months: number;
34
- value: string;
35
55
  focus: (options?: CalendarFocusOptions) => void;
56
+ value: string;
36
57
  firstDayOfWeek: DaysOfWeek;
37
58
  isDateDisallowed: (date: Date) => boolean;
38
59
  min: string;
@@ -47,6 +68,7 @@ showOutsideDays: boolean;
47
68
  showWeekNumbers: boolean;
48
69
  pageBy: Pagination;
49
70
  onChange: (event: Event) => any;
71
+ onPageChange: (event: CustomEvent<PageChangeDetail>) => any;
50
72
  } & {}, {
51
73
  new (): HTMLElement;
52
74
  prototype: HTMLElement;
@@ -58,6 +80,19 @@ declare interface CalendarFocusOptions extends FocusOptions {
58
80
  target?: "day" | "next" | "previous";
59
81
  }
60
82
 
83
+ export declare const CalendarHeading: Atomico< {
84
+ year: "numeric" | "2-digit" | undefined;
85
+ month: "long" | "short" | "narrow" | "numeric" | "2-digit" | undefined;
86
+ } & {}, {
87
+ year: "numeric" | "2-digit" | undefined;
88
+ month: "long" | "short" | "narrow" | "numeric" | "2-digit" | undefined;
89
+ } & {}, {
90
+ new (): HTMLElement;
91
+ prototype: HTMLElement;
92
+ }>;
93
+
94
+ export declare type CalendarHeadingProps = ComponentProps<typeof CalendarHeading>;
95
+
61
96
  export declare const CalendarMonth: Atomico< {
62
97
  offset: number;
63
98
  onSelectDay: (event: CustomEvent<string>) => any;
@@ -77,8 +112,8 @@ export declare type CalendarMonthProps = ComponentProps<typeof CalendarMonth>;
77
112
 
78
113
  export declare const CalendarMulti: Atomico< {
79
114
  months: number;
80
- value: string;
81
115
  focus: (options?: CalendarFocusOptions) => void;
116
+ value: string;
82
117
  firstDayOfWeek: DaysOfWeek;
83
118
  isDateDisallowed: (date: Date) => boolean;
84
119
  min: string;
@@ -93,10 +128,11 @@ showOutsideDays: boolean;
93
128
  showWeekNumbers: boolean;
94
129
  pageBy: Pagination;
95
130
  onChange: (event: Event) => any;
131
+ onPageChange: (event: CustomEvent<PageChangeDetail>) => any;
96
132
  } & {}, {
97
133
  months: number;
98
- value: string;
99
134
  focus: (options?: CalendarFocusOptions) => void;
135
+ value: string;
100
136
  firstDayOfWeek: DaysOfWeek;
101
137
  isDateDisallowed: (date: Date) => boolean;
102
138
  min: string;
@@ -111,6 +147,7 @@ showOutsideDays: boolean;
111
147
  showWeekNumbers: boolean;
112
148
  pageBy: Pagination;
113
149
  onChange: (event: Event) => any;
150
+ onPageChange: (event: CustomEvent<PageChangeDetail>) => any;
114
151
  } & {}, {
115
152
  new (): HTMLElement;
116
153
  prototype: HTMLElement;
@@ -120,8 +157,8 @@ export declare type CalendarMultiProps = ComponentProps<typeof CalendarMulti>;
120
157
 
121
158
  export declare const CalendarRange: Atomico< {
122
159
  months: number;
123
- value: string;
124
160
  focus: (options?: CalendarFocusOptions) => void;
161
+ value: string;
125
162
  firstDayOfWeek: DaysOfWeek;
126
163
  isDateDisallowed: (date: Date) => boolean;
127
164
  min: string;
@@ -136,13 +173,14 @@ showOutsideDays: boolean;
136
173
  showWeekNumbers: boolean;
137
174
  pageBy: Pagination;
138
175
  onChange: (event: Event) => any;
176
+ onPageChange: (event: CustomEvent<PageChangeDetail>) => any;
139
177
  tentative: string;
140
178
  onRangeStart: (event: CustomEvent<Date>) => any;
141
179
  onRangeEnd: (event: CustomEvent<Date>) => any;
142
180
  } & {}, {
143
181
  months: number;
144
- value: string;
145
182
  focus: (options?: CalendarFocusOptions) => void;
183
+ value: string;
146
184
  firstDayOfWeek: DaysOfWeek;
147
185
  isDateDisallowed: (date: Date) => boolean;
148
186
  min: string;
@@ -157,6 +195,7 @@ showOutsideDays: boolean;
157
195
  showWeekNumbers: boolean;
158
196
  pageBy: Pagination;
159
197
  onChange: (event: Event) => any;
198
+ onPageChange: (event: CustomEvent<PageChangeDetail>) => any;
160
199
  tentative: string;
161
200
  onRangeStart: (event: CustomEvent<Date>) => any;
162
201
  onRangeEnd: (event: CustomEvent<Date>) => any;
@@ -189,18 +228,470 @@ prototype: HTMLElement;
189
228
 
190
229
  export declare type CalendarSelectYearProps = ComponentProps<typeof CalendarSelectYear>;
191
230
 
231
+ declare type CheckEvent<CurrentEvent, True> = CurrentEvent extends Event ? True : never;
232
+
192
233
  declare type ComponentProps<T extends abstract new (...args: any) => any> = Simplify<Partial<Omit<InstanceType<T>, keyof HTMLElement | keyof AtomicoThis>>>;
193
234
 
235
+ /**
236
+ * ISO day of week, Monday is 1 and Sunday is 7.
237
+ * `0` for Sunday is deprecated and will be removed in v1.
238
+ */
239
+ declare type DaysOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
240
+
241
+ declare interface DOM$Attrs {
242
+ [prop: `\$${string}`]: Nullable<string>;
243
+ }
244
+
245
+ declare type DOMCleanKeys =
246
+ | keyof DOMGenericProperties
247
+ | `add${string}`
248
+ | `get${string}`
249
+ | `set${string}`
250
+ | `has${string}`
251
+ | `matches${string}`
252
+ | `remove${string}`
253
+ | `replace${string}`
254
+ | `querySelector${string}`
255
+ | `offset${string}`
256
+ | `append${string}`
257
+ | `request${string}`
258
+ | `scroll${string}`
259
+ | `is${string}`
260
+ | `toggle${string}`
261
+ | `webkit${string}`
262
+ | `insert${string}`
263
+ | `client${string}`
264
+ | `child${string}`
265
+ | `${string}_${string}`
266
+ | `${string}HTML`
267
+ | `${string}Child`
268
+ | `${string}Validity`
269
+ | `${string}Capture`
270
+ | `${string}ElementSibling`
271
+ | "classList"
272
+ | "attributes"
273
+ | "normalize"
274
+ | "closest"
275
+ | "localName"
276
+ | "contains"
277
+ | "animate"
278
+ | "attachShadow"
279
+ | "outerText"
280
+ | "attachInternals"
281
+ | "click"
282
+ | "tagName"
283
+ | "focus"
284
+ | "submit"
285
+ | "accessKeyLabel"
286
+ | "elements"
287
+ | "isContentEditable"
288
+ | "innerText"
289
+ | "prepend"
290
+ | "namespaceURI"
291
+ | "blur"
292
+ | "dataset"
293
+ | "shadowRoot"
294
+ | keyof Omit<ChildNode, "textContent">;
295
+
296
+ declare type DOMCustomTarget<Target> = { customTarget: Target };
297
+
298
+ declare type DOMEvent<
299
+ Target = HTMLElement,
300
+ CurrentEvent = Event
301
+ > = Target extends string
302
+ ? CurrentEvent extends AtomicoStatic<any>
303
+ ? DOMGetEvent<Target, CurrentEvent>
304
+ : DOMEventType<Target, CurrentEvent>
305
+ : DOMTarget<DOMThis<Target>, CurrentEvent>;
306
+
307
+ declare type DOMEventHandler<Target, Handler> = Handler extends (
308
+ ev: infer CurrentEvent
309
+ ) => any
310
+ ? CurrentEvent extends Event
311
+ ? (ev: DOMEvent<Target, CurrentEvent>) => any
312
+ : Handler
313
+ : Handler;
314
+
315
+ /**
316
+ * @todo Rename Handler to Listener
317
+ */
318
+
319
+ declare type DOMEventHandlerKeys<P> = {
320
+ [I in keyof P]-?: NonNullable<P[I]> extends DOMEventHandlerValue<infer E>
321
+ ? CheckEvent<E, I>
322
+ : P[I] extends { value: DOMEventHandlerValue<infer E> }
323
+ ? CheckEvent<E, I>
324
+ : never;
325
+ }[keyof P];
326
+
327
+ declare interface DOMEventHandlerType extends FunctionConstructor {}
328
+
329
+ declare interface DOMEventHandlerValue<CurrentEvent> {
330
+ (event: CurrentEvent): any;
331
+ }
332
+
333
+ declare type DOMEvents<Target> = {
334
+ [Prop in keyof Target]?: Prop extends `on${string}`
335
+ ? DOMEventHandler<Target, Target[Prop]>
336
+ : Target[Prop];
337
+ };
338
+
339
+ declare type DOMEventTarget<CurrentEvent, CurrentTarget, Target> = {
340
+ [I in keyof CurrentEvent]: I extends "currentTarget"
341
+ ? CurrentTarget
342
+ : I extends "target"
343
+ ? Target
344
+ : CurrentEvent[I];
345
+ };
346
+
347
+ declare type DOMEventType<Type extends string, CurrentEvent> = {
348
+ [I in keyof "0" as `on${Type}`]: {
349
+ type: DOMEventHandlerType;
350
+ value: DOMEventHandlerValue<CurrentEvent>;
351
+ };
352
+ };
353
+
354
+ declare interface DOMGenericProperties {
355
+ style?: string | Partial<CSSStyleDeclaration> | object;
356
+ class?: string;
357
+ id?: string;
358
+ slot?: string;
359
+ part?: string;
360
+ is?: string;
361
+ tabindex?: string | number;
362
+ role?: string;
363
+ shadowDom?: boolean | Partial<ShadowRootInit>;
364
+ staticNode?: boolean;
365
+ cloneNode?: boolean;
366
+ width?: string | number;
367
+ height?: string | number;
368
+ key?: any;
369
+ children?: any;
370
+ }
371
+
372
+ declare type DOMGetEvent<
373
+ Type extends string,
374
+ Element extends AtomicoStatic<any>
375
+ > = Element extends {
376
+ "##props": infer Props;
377
+ }
378
+ ? `on${Type}` extends keyof Props
379
+ ? DOMGetEventBefore<NonNullable<Props[`on${Type}`]>, DOMThis<Element>>
380
+ : Event
381
+ : Event;
382
+
383
+ declare type DOMGetEventBefore<Value, Target> = Value extends DOMEventHandlerValue<
384
+ infer Event
385
+ >
386
+ ? DOMEvent<HTMLElement, Event & DOMCustomTarget<Target>>
387
+ : null;
388
+
389
+ declare type DOMRef<Target> = {
390
+ ref?: DOMRefValue<Target>;
391
+ };
392
+
393
+ declare type DOMRefValue<Target> = FillObject | ((target: Target) => any);
394
+
395
+ declare type DOMTag<Element, Props = null> = Props extends null
396
+ ? PropsNullable<
397
+ Omit<DOMEvents<Element>, DOMCleanKeys> &
398
+ DOMGenericProperties &
399
+ DOMRef<Element>
400
+ > &
401
+ DOM$Attrs &
402
+ DOMUnknown
403
+ : PropsNullable<
404
+ Props &
405
+ Omit<DOMEvents<Element & Props>, keyof Props | DOMCleanKeys> &
406
+ DOMGenericProperties &
407
+ DOMRef<Element & Props>
408
+ > &
409
+ DOM$Attrs &
410
+ DOMUnknown;
411
+
412
+ declare type DOMTarget<
413
+ Target,
414
+ CurrentEvent,
415
+ Targets = Element | Node
416
+ > = CurrentEvent extends {
417
+ customTarget: infer EventTarget;
418
+ }
419
+ ? DOMTarget<Target, Omit<CurrentEvent, "customTarget">, EventTarget>
420
+ : DOMEventTarget<CurrentEvent, Target, Targets>;
421
+
194
422
  declare type DOMThis<Element> = Element extends new (
195
423
  ...args: any[]
196
424
  ) => infer This
197
425
  ? This
198
426
  : Element;
199
427
 
428
+ declare interface DOMUnknown {
429
+ [prop: string]: any;
430
+ }
431
+
432
+ declare type EventInit_2 = CustomEventInit<any> & {
433
+ type: string;
434
+ base?: typeof CustomEvent | typeof Event;
435
+ };
436
+
437
+ declare type FillArray = any[];
438
+
439
+ declare type FillConstructor = abstract new (...args: any) => any;
440
+
441
+ declare type FillFunction = (...args: any[]) => any;
442
+
443
+ /**
444
+ * Interface to fill in unknown properties like any | null | undefined
445
+ */
446
+ declare interface FillObject {
447
+ [index: string]: any;
448
+ }
449
+
450
+ declare type FillPromise = Promise<any>;
451
+
452
+ declare type GetTypeSelf<value extends TypesSelfValues> = {
453
+ [I in keyof SelfConstructors]-?: value extends InstanceType<
454
+ SelfConstructors[I]
455
+ >
456
+ ? keyof value extends keyof InstanceType<SelfConstructors[I]>
457
+ ? SelfConstructors[I]
458
+ : never
459
+ : never;
460
+ }[keyof SelfConstructors];
461
+
462
+ declare type JSXProxy<Props, This> = {
463
+ [I in keyof Props]?: I extends `on${string}`
464
+ ? NonNullable<Props[I]> extends DOMEventHandlerValue<infer CurrentEvent>
465
+ ? Nullable<
466
+ (
467
+ ev: DOMEventTarget<CurrentEvent, This, Element | Node>
468
+ ) => any
469
+ >
470
+ : Props[I]
471
+ : I extends "ref"
472
+ ? DOMRefValue<This>
473
+ : Props[I];
474
+ };
475
+
476
+ declare type Nullable<T> = NonNullable<T> | undefined | null;
477
+
478
+ declare interface PageChangeDetail {
479
+ start: Date;
480
+ end: Date;
481
+ }
482
+
483
+ declare type Pagination = "single" | "months";
484
+
485
+ declare type PropsNullable<Data> = {
486
+ [I in keyof Data]?: Nullable<Data[I]>;
487
+ };
488
+
489
+ declare type SafeGlobal =
490
+ | "Event"
491
+ | "URL"
492
+ | "Range"
493
+ | "Image"
494
+ | "Crypto"
495
+ | "File"
496
+ | "Date"
497
+ | "Set"
498
+ | "Map"
499
+ | "RegExp"
500
+ | "Animation"
501
+ | `${string}Event`
502
+ | `Event${string}`
503
+ | `Clipboard${string}`
504
+ | `Animation${string}`
505
+ | `Form${string}`
506
+ | `Font${string}`
507
+ | `DOM${string}`
508
+ | `Touch${string}`
509
+ | `Mutation${string}`
510
+ | `Intersection${string}`
511
+ | `Message${string}`
512
+ | `HTML${string}`
513
+ | `SVG${string}`
514
+ | `Audio${string}`
515
+ | `Document${string}`
516
+ | `Weak${string}`
517
+ | `CSS${string}`
518
+ | `File${string}`;
519
+
520
+ declare type SchemaAny<Type> =
521
+ | SchemaReflect<{
522
+ value: Type;
523
+ }>
524
+ | SchemaReflect<{
525
+ value: () => Type;
526
+ }>
527
+ | SchemaReflect<{}>;
528
+
529
+ declare type SchemaBase = SchemaEvent & {
530
+ attr?: string;
531
+ };
532
+
533
+ declare type SchemaEvent = {
534
+ event?: EventInit_2;
535
+ };
536
+
537
+ declare type SchemaInfer<Props> = Required<
538
+ Omit<
539
+ {
540
+ [I in keyof Props]: Type<Props[I]>;
541
+ },
542
+ DOMEventHandlerKeys<Props>
543
+ >
544
+ >;
545
+
546
+ declare type SchemaOnlyPropWrapper<Constructor, Type> =
547
+ | SchemaProp<{
548
+ type: Constructor;
549
+ }>
550
+ | SchemaProp<{
551
+ type: Constructor;
552
+ value: Type;
553
+ }>
554
+ | SchemaProp<{
555
+ type: Constructor;
556
+ value: () => Type;
557
+ }>;
558
+
559
+ declare type SchemaProp<type> = SchemaEvent & type;
560
+
561
+ declare type SchemaReflect<type> = SchemaBase & {
562
+ reflect?: boolean;
563
+ } & type;
564
+
565
+ declare type SchemaReflectWrapper<Constructor, Type> =
566
+ | SchemaReflect<{
567
+ type: Constructor;
568
+ }>
569
+ | SchemaReflect<{
570
+ type: Constructor;
571
+ value: Type;
572
+ }>
573
+ | SchemaReflect<{
574
+ type: Constructor;
575
+ value: () => Type;
576
+ }>;
577
+
578
+ declare type SchemaTypeCustom =
579
+ | TypeCustom<FillFunction>
580
+ | SchemaReflectWrapper<TypeCustom<FillFunction>, any>;
581
+
582
+ declare type Self = typeof window;
583
+
584
+ declare type SelfConstructors = Pick<
585
+ Self,
586
+ {
587
+ [I in keyof Self]-?: I extends string
588
+ ? I extends Capitalize<I>
589
+ ? Self[I] extends FillConstructor
590
+ ? Self[I] extends SelfIgnore
591
+ ? never
592
+ : I extends SafeGlobal
593
+ ? I
594
+ : never
595
+ : never
596
+ : never
597
+ : never;
598
+ }[keyof Self]
599
+ >;
600
+
601
+ declare type SelfIgnore =
602
+ | StringConstructor
603
+ | NumberConstructor
604
+ | BooleanConstructor
605
+ | FunctionConstructor
606
+ | ObjectConstructor
607
+ | PromiseConstructor
608
+ | SymbolConstructor
609
+ | ArrayConstructor;
610
+
611
+ declare type Sheet = CSSStyleSheet | HTMLStyleElement;
612
+
613
+ declare type Sheets = Sheet | Sheet[] | Sheets[];
614
+
200
615
  declare type Simplify<T> = {
201
616
  [K in keyof T]: T[K];
202
617
  } & {};
203
618
 
619
+ declare type Type<type> = type extends string
620
+ ? TypeString<type>
621
+ : type extends number
622
+ ? TypeNumber<type>
623
+ : type extends boolean
624
+ ? TypeBoolean
625
+ : type extends TypeCustom<FillFunction>
626
+ ? SchemaTypeCustom
627
+ : type extends FillPromise
628
+ ? TypePromise<type>
629
+ : type extends symbol
630
+ ? TypeSymbol<type>
631
+ : type extends FillArray
632
+ ? TypeArray<type>
633
+ : type extends DOMStringMap
634
+ ? TypeObject<type>
635
+ : type extends TypesSelfValues
636
+ ? GetTypeSelf<type> extends never
637
+ ? TypesDiscard<type>
638
+ : TypeConstructor<GetTypeSelf<type>>
639
+ : TypesDiscard<type>;
640
+
641
+ declare type TypeAny<type = any> = null | SchemaAny<type>;
642
+
643
+ declare type TypeArray<type extends FillArray> =
644
+ | ArrayConstructor
645
+ | SchemaReflectWrapper<ArrayConstructor, type>;
646
+
647
+ declare type TypeBoolean =
648
+ | BooleanConstructor
649
+ | SchemaReflectWrapper<BooleanConstructor, true | false>;
650
+
651
+ declare type TypeConstructor<type extends FillConstructor> =
652
+ | type
653
+ | SchemaOnlyPropWrapper<type, InstanceType<type>>;
654
+
655
+ declare type TypeCustom<Map extends FillFunction> = {
656
+ name: "Custom";
657
+ map: Map;
658
+ serialize?: (value: ReturnType<Map>) => string;
659
+ };
660
+
661
+ declare type TypeFunction<type extends FillFunction> =
662
+ | FunctionConstructor
663
+ | SchemaOnlyPropWrapper<FunctionConstructor, type>;
664
+
665
+ declare type TypeNumber<type extends number> =
666
+ | NumberConstructor
667
+ | SchemaReflectWrapper<NumberConstructor, type>;
668
+
669
+ declare type TypeObject<type extends FillObject> =
670
+ | ObjectConstructor
671
+ | SchemaReflectWrapper<ObjectConstructor, type>;
672
+
673
+ declare type TypePromise<type extends FillPromise> =
674
+ | PromiseConstructor
675
+ | SchemaOnlyPropWrapper<PromiseConstructor, type>;
676
+
677
+ declare type TypesDiscard<type> = type extends FillFunction
678
+ ? TypeFunction<type>
679
+ : type extends FillObject
680
+ ? TypeObject<type>
681
+ : TypeAny<type>;
682
+
683
+ declare type TypesSelfValues = {
684
+ [I in keyof SelfConstructors]-?: InstanceType<SelfConstructors[I]>;
685
+ }[keyof SelfConstructors];
686
+
687
+ declare type TypeString<type extends string> =
688
+ | StringConstructor
689
+ | SchemaReflectWrapper<StringConstructor, type>;
690
+
691
+ declare type TypeSymbol<type extends symbol> =
692
+ | SymbolConstructor
693
+ | SchemaOnlyPropWrapper<SymbolConstructor, type>;
694
+
204
695
  export { }
205
696
  // this is just a hacky workaround to ensure the global declarations make it into the dts rollup
206
697
  // they get appended to the end of the file on vite build
@@ -209,5 +700,9 @@ declare global {
209
700
  "calendar-month": InstanceType<typeof CalendarMonth>;
210
701
  "calendar-date": InstanceType<typeof CalendarDate>;
211
702
  "calendar-range": InstanceType<typeof CalendarRange>;
703
+ "calendar-multi": InstanceType<typeof CalendarMulti>;
704
+ "calendar-select-month": InstanceType<typeof CalendarSelectMonth>;
705
+ "calendar-select-year": InstanceType<typeof CalendarSelectYear>;
706
+ "calendar-heading": InstanceType<typeof CalendarHeading>;
212
707
  }
213
708
  }