@tasknotes/calendar 0.1.3 → 0.1.4

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/dist/esm/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  TIMELINE_UNIT_DAYS,
8
8
  defaultOptions,
9
9
  localeFirstDay
10
- } from "./chunk-XHPZ7K4W.js";
10
+ } from "./chunk-26DEUGQH.js";
11
11
  import {
12
12
  DAY_MS,
13
13
  ItemStore,
package/dist/esm/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Calendar
3
- } from "./chunk-XHPZ7K4W.js";
3
+ } from "./chunk-26DEUGQH.js";
4
4
  import "./chunk-DVMZ5OXN.js";
5
5
 
6
6
  // src/react/index.tsx
@@ -6,6 +6,7 @@ import { type TimeZone } from "../core/zone.cjs";
6
6
  import { type ElMeta, type ViewContext } from "./context.cjs";
7
7
  import { Formatter } from "./format.cjs";
8
8
  import { type CalendarOptions, type CalendarText, type DayArg, type ExternalDragSource, type Hit, type TimelineAnchor, type ViewInfo, type ViewType } from "./options.cjs";
9
+ import { DateStrip } from "./views/strip.cjs";
9
10
  /**
10
11
  * A calendar bound to one element. Works in any document, including Obsidian
11
12
  * popout windows: all listeners, timers and observers use the element's window.
@@ -40,6 +41,9 @@ export declare class Calendar<D = unknown> implements ViewContext<D> {
40
41
  id: string;
41
42
  rowId: string;
42
43
  } | null;
44
+ strip: DateStrip<D> | null;
45
+ private stripSize;
46
+ private rebuilding;
43
47
  private readonly toolbarEl;
44
48
  private readonly viewHost;
45
49
  private current;
@@ -149,8 +153,17 @@ export declare class Calendar<D = unknown> implements ViewContext<D> {
149
153
  private computeRange;
150
154
  private computeTitle;
151
155
  private rebuild;
152
- /** Sets the visible days and view info from the anchor; true when the range moved. */
156
+ /** Sets the visible days and view info from the anchor. */
153
157
  private applyRange;
158
+ /** The range, run on to the end of the strip's days so their dots are right. */
159
+ private dataRangeFor;
160
+ /** Adds, updates or removes the date strip for the current view. */
161
+ private syncStrip;
162
+ private pickStripDay;
163
+ /** The strip moved to other days: load theirs too. */
164
+ private stripShown;
165
+ /** What is under a point, the date strip included. */
166
+ private hitAt;
154
167
  private agendaList;
155
168
  extendList(endDay: Day): void;
156
169
  showListDay(day: Day): void;
@@ -6,6 +6,7 @@ import { type TimeZone } from "../core/zone.js";
6
6
  import { type ElMeta, type ViewContext } from "./context.js";
7
7
  import { Formatter } from "./format.js";
8
8
  import { type CalendarOptions, type CalendarText, type DayArg, type ExternalDragSource, type Hit, type TimelineAnchor, type ViewInfo, type ViewType } from "./options.js";
9
+ import { DateStrip } from "./views/strip.js";
9
10
  /**
10
11
  * A calendar bound to one element. Works in any document, including Obsidian
11
12
  * popout windows: all listeners, timers and observers use the element's window.
@@ -40,6 +41,9 @@ export declare class Calendar<D = unknown> implements ViewContext<D> {
40
41
  id: string;
41
42
  rowId: string;
42
43
  } | null;
44
+ strip: DateStrip<D> | null;
45
+ private stripSize;
46
+ private rebuilding;
43
47
  private readonly toolbarEl;
44
48
  private readonly viewHost;
45
49
  private current;
@@ -149,8 +153,17 @@ export declare class Calendar<D = unknown> implements ViewContext<D> {
149
153
  private computeRange;
150
154
  private computeTitle;
151
155
  private rebuild;
152
- /** Sets the visible days and view info from the anchor; true when the range moved. */
156
+ /** Sets the visible days and view info from the anchor. */
153
157
  private applyRange;
158
+ /** The range, run on to the end of the strip's days so their dots are right. */
159
+ private dataRangeFor;
160
+ /** Adds, updates or removes the date strip for the current view. */
161
+ private syncStrip;
162
+ private pickStripDay;
163
+ /** The strip moved to other days: load theirs too. */
164
+ private stripShown;
165
+ /** What is under a point, the date strip included. */
166
+ private hitAt;
154
167
  private agendaList;
155
168
  extendList(endDay: Day): void;
156
169
  showListDay(day: Day): void;
@@ -5,6 +5,7 @@ import type { NormalizedItem } from "../core/types.cjs";
5
5
  import type { TimeZone } from "../core/zone.cjs";
6
6
  import type { Formatter } from "./format.cjs";
7
7
  import type { CalendarOptions, CalendarText, DayArg, Hit, ItemVariant, ViewInfo } from "./options.cjs";
8
+ import type { DateStrip } from "./views/strip.cjs";
8
9
  export type Variant = ItemVariant;
9
10
  export interface ElMeta<D = unknown> {
10
11
  n: NormalizedItem<D>;
@@ -70,8 +71,10 @@ export interface ViewContext<D = unknown> {
70
71
  id: string;
71
72
  rowId: string;
72
73
  } | null;
73
- /** Reports a day picked outside the grid (year days, the agenda strip) through `onDateClick`. */
74
+ /** Reports a day picked outside the grid (year days) through `onDateClick`. */
74
75
  dateClick(day: Day, jsEvent: MouseEvent | KeyboardEvent): void;
76
+ /** The date strip, when the view has one. */
77
+ readonly strip: DateStrip<D> | null;
75
78
  /** Agenda lists: grows the range to end at `endDay`. */
76
79
  extendList(endDay: Day): void;
77
80
  /** Agenda lists: brings `day` to the top, moving the range to reach it. */
@@ -97,8 +100,6 @@ export interface View {
97
100
  scrollToTime?(minute: number): void;
98
101
  /** Item elements currently shown for an id. */
99
102
  elementsFor(id: string): HTMLElement[];
100
- /** A drag ended, dropped or not. */
101
- dragEnded?(): void;
102
103
  destroy(): void;
103
104
  }
104
105
  export declare class ItemPool<D> {
@@ -5,6 +5,7 @@ import type { NormalizedItem } from "../core/types.js";
5
5
  import type { TimeZone } from "../core/zone.js";
6
6
  import type { Formatter } from "./format.js";
7
7
  import type { CalendarOptions, CalendarText, DayArg, Hit, ItemVariant, ViewInfo } from "./options.js";
8
+ import type { DateStrip } from "./views/strip.js";
8
9
  export type Variant = ItemVariant;
9
10
  export interface ElMeta<D = unknown> {
10
11
  n: NormalizedItem<D>;
@@ -70,8 +71,10 @@ export interface ViewContext<D = unknown> {
70
71
  id: string;
71
72
  rowId: string;
72
73
  } | null;
73
- /** Reports a day picked outside the grid (year days, the agenda strip) through `onDateClick`. */
74
+ /** Reports a day picked outside the grid (year days) through `onDateClick`. */
74
75
  dateClick(day: Day, jsEvent: MouseEvent | KeyboardEvent): void;
76
+ /** The date strip, when the view has one. */
77
+ readonly strip: DateStrip<D> | null;
75
78
  /** Agenda lists: grows the range to end at `endDay`. */
76
79
  extendList(endDay: Day): void;
77
80
  /** Agenda lists: brings `day` to the top, moving the range to reach it. */
@@ -97,8 +100,6 @@ export interface View {
97
100
  scrollToTime?(minute: number): void;
98
101
  /** Item elements currently shown for an id. */
99
102
  elementsFor(id: string): HTMLElement[];
100
- /** A drag ended, dropped or not. */
101
- dragEnded?(): void;
102
103
  destroy(): void;
103
104
  }
104
105
  export declare class ItemPool<D> {
@@ -14,6 +14,12 @@ export interface ViewInfo {
14
14
  /** Anchor date the view was built around. */
15
15
  anchor: Day;
16
16
  title: string;
17
+ /**
18
+ * The days whose items the calendar can show: `range`, extended to the
19
+ * end of the days a date strip is showing so their dots are right. Load
20
+ * items for this range; `onRangeChange` fires when it changes too.
21
+ */
22
+ dataRange: DateRange;
17
23
  }
18
24
  /** Where a pointer is over the calendar. */
19
25
  export type Hit = {
@@ -291,6 +297,31 @@ export interface CalendarOptions<D = unknown> {
291
297
  * dragged onto a strip day or another day's section move there.
292
298
  */
293
299
  listAgenda: boolean;
300
+ /**
301
+ * Puts the agenda's date strip above the "day", "days" and "week" views
302
+ * too. Picking a strip day moves the grid to it, and items dragged onto a
303
+ * strip day move there at the same time.
304
+ */
305
+ dateStrip: boolean;
306
+ /**
307
+ * Agenda lists: a section above the first day, titled with this text, for
308
+ * items `listLeadIncludes` picks out (overdue work, say). Those items show
309
+ * there instead of under their day. Null for none.
310
+ */
311
+ listLeadTitle: string | null;
312
+ listLeadIncludes?: (item: CalendarItem<D>) => boolean;
313
+ /** The lead section's header has an empty slot for host controls (a "Reschedule" button, say). */
314
+ listLeadDidMount?: (arg: {
315
+ el: HTMLElement;
316
+ }) => void;
317
+ listLeadWillUnmount?: (arg: {
318
+ el: HTMLElement;
319
+ }) => void;
320
+ /** Agenda lists: an add row with this label under every day, reported through `onListAdd`. Null for none. */
321
+ listAddText: string | null;
322
+ onListAdd?: (arg: DayArg & {
323
+ jsEvent: MouseEvent | KeyboardEvent;
324
+ }) => void;
294
325
  /**
295
326
  * Month cells: "full" draws bars and titled entries; "dots" draws every
296
327
  * item as a small dot that wraps across the cell, with a "+N" count when
@@ -402,13 +433,13 @@ export interface CalendarOptions<D = unknown> {
402
433
  dayHeaderContent?: (arg: DayArg) => Node | string | null | undefined;
403
434
  dayHeaderDidMount?: (arg: DayHeaderArg) => void;
404
435
  /**
405
- * The agenda strip's header has an empty slot after its arrows. Mount host
436
+ * The date strip's header has an empty slot after its arrows. Mount host
406
437
  * controls (a layout menu, say) into `el`; the calendar leaves it alone.
407
438
  */
408
439
  stripSlotDidMount?: (arg: {
409
440
  el: HTMLElement;
410
441
  }) => void;
411
- /** The agenda strip's slot is about to be removed. */
442
+ /** The date strip's slot is about to be removed. */
412
443
  stripSlotWillUnmount?: (arg: {
413
444
  el: HTMLElement;
414
445
  }) => void;
@@ -14,6 +14,12 @@ export interface ViewInfo {
14
14
  /** Anchor date the view was built around. */
15
15
  anchor: Day;
16
16
  title: string;
17
+ /**
18
+ * The days whose items the calendar can show: `range`, extended to the
19
+ * end of the days a date strip is showing so their dots are right. Load
20
+ * items for this range; `onRangeChange` fires when it changes too.
21
+ */
22
+ dataRange: DateRange;
17
23
  }
18
24
  /** Where a pointer is over the calendar. */
19
25
  export type Hit = {
@@ -291,6 +297,31 @@ export interface CalendarOptions<D = unknown> {
291
297
  * dragged onto a strip day or another day's section move there.
292
298
  */
293
299
  listAgenda: boolean;
300
+ /**
301
+ * Puts the agenda's date strip above the "day", "days" and "week" views
302
+ * too. Picking a strip day moves the grid to it, and items dragged onto a
303
+ * strip day move there at the same time.
304
+ */
305
+ dateStrip: boolean;
306
+ /**
307
+ * Agenda lists: a section above the first day, titled with this text, for
308
+ * items `listLeadIncludes` picks out (overdue work, say). Those items show
309
+ * there instead of under their day. Null for none.
310
+ */
311
+ listLeadTitle: string | null;
312
+ listLeadIncludes?: (item: CalendarItem<D>) => boolean;
313
+ /** The lead section's header has an empty slot for host controls (a "Reschedule" button, say). */
314
+ listLeadDidMount?: (arg: {
315
+ el: HTMLElement;
316
+ }) => void;
317
+ listLeadWillUnmount?: (arg: {
318
+ el: HTMLElement;
319
+ }) => void;
320
+ /** Agenda lists: an add row with this label under every day, reported through `onListAdd`. Null for none. */
321
+ listAddText: string | null;
322
+ onListAdd?: (arg: DayArg & {
323
+ jsEvent: MouseEvent | KeyboardEvent;
324
+ }) => void;
294
325
  /**
295
326
  * Month cells: "full" draws bars and titled entries; "dots" draws every
296
327
  * item as a small dot that wraps across the cell, with a "+N" count when
@@ -402,13 +433,13 @@ export interface CalendarOptions<D = unknown> {
402
433
  dayHeaderContent?: (arg: DayArg) => Node | string | null | undefined;
403
434
  dayHeaderDidMount?: (arg: DayHeaderArg) => void;
404
435
  /**
405
- * The agenda strip's header has an empty slot after its arrows. Mount host
436
+ * The date strip's header has an empty slot after its arrows. Mount host
406
437
  * controls (a layout menu, say) into `el`; the calendar leaves it alone.
407
438
  */
408
439
  stripSlotDidMount?: (arg: {
409
440
  el: HTMLElement;
410
441
  }) => void;
411
- /** The agenda strip's slot is about to be removed. */
442
+ /** The date strip's slot is about to be removed. */
412
443
  stripSlotWillUnmount?: (arg: {
413
444
  el: HTMLElement;
414
445
  }) => void;
@@ -4,29 +4,32 @@ import { type Selection, type View, type ViewContext } from "../context.cjs";
4
4
  import type { Hit } from "../options.cjs";
5
5
  /**
6
6
  * N-day agenda: one section per day that has items. With `listAgenda`, every
7
- * day gets a section, a date strip follows the day at the top, and more days
8
- * load as the list nears its end.
7
+ * day gets a section, the calendar's date strip follows the day at the top,
8
+ * and more days load as the list nears its end. A lead section above the
9
+ * first day can collect items such as overdue work.
9
10
  */
10
11
  export declare class ListView<D> implements View {
11
12
  private readonly ctx;
12
13
  readonly el: HTMLElement;
13
14
  private readonly scroller;
14
15
  private readonly body;
16
+ private readonly agenda;
15
17
  private pools;
16
18
  private sections;
17
- private readonly strip;
19
+ private lead;
18
20
  private readonly sentinel;
19
21
  private readonly loader;
20
- private readonly stripSize;
21
22
  private frame;
22
23
  /** A picked day stays marked until the list is scrolled by hand. */
23
24
  private pinned;
24
25
  constructor(ctx: ViewContext<D>);
25
26
  private itemsOn;
26
27
  render(_change: StoreChange | null): void;
27
- /** A strip day: the host hears of it, and the list brings it to the top. */
28
- private pick;
29
- /** Brings a day's section to the top, under the strip. */
28
+ /** Places items in a pool, keeping DOM order equal to item order. */
29
+ private fill;
30
+ private renderLead;
31
+ private addRow;
32
+ /** Brings a day's section to the top, under the strip; the first day brings the lead section too. */
30
33
  scrollToDay(day: Day): void;
31
34
  private readonly fold;
32
35
  private readonly onScroll;
@@ -34,7 +37,6 @@ export declare class ListView<D> implements View {
34
37
  private followTop;
35
38
  showSelection(_sel: Selection | null): void;
36
39
  hit(x: number, y: number): Hit | null;
37
- dragEnded(): void;
38
40
  getScroll(): {
39
41
  top: number;
40
42
  left: number;
@@ -4,29 +4,32 @@ import { type Selection, type View, type ViewContext } from "../context.js";
4
4
  import type { Hit } from "../options.js";
5
5
  /**
6
6
  * N-day agenda: one section per day that has items. With `listAgenda`, every
7
- * day gets a section, a date strip follows the day at the top, and more days
8
- * load as the list nears its end.
7
+ * day gets a section, the calendar's date strip follows the day at the top,
8
+ * and more days load as the list nears its end. A lead section above the
9
+ * first day can collect items such as overdue work.
9
10
  */
10
11
  export declare class ListView<D> implements View {
11
12
  private readonly ctx;
12
13
  readonly el: HTMLElement;
13
14
  private readonly scroller;
14
15
  private readonly body;
16
+ private readonly agenda;
15
17
  private pools;
16
18
  private sections;
17
- private readonly strip;
19
+ private lead;
18
20
  private readonly sentinel;
19
21
  private readonly loader;
20
- private readonly stripSize;
21
22
  private frame;
22
23
  /** A picked day stays marked until the list is scrolled by hand. */
23
24
  private pinned;
24
25
  constructor(ctx: ViewContext<D>);
25
26
  private itemsOn;
26
27
  render(_change: StoreChange | null): void;
27
- /** A strip day: the host hears of it, and the list brings it to the top. */
28
- private pick;
29
- /** Brings a day's section to the top, under the strip. */
28
+ /** Places items in a pool, keeping DOM order equal to item order. */
29
+ private fill;
30
+ private renderLead;
31
+ private addRow;
32
+ /** Brings a day's section to the top, under the strip; the first day brings the lead section too. */
30
33
  scrollToDay(day: Day): void;
31
34
  private readonly fold;
32
35
  private readonly onScroll;
@@ -34,7 +37,6 @@ export declare class ListView<D> implements View {
34
37
  private followTop;
35
38
  showSelection(_sel: Selection | null): void;
36
39
  hit(x: number, y: number): Hit | null;
37
- dragEnded(): void;
38
40
  getScroll(): {
39
41
  top: number;
40
42
  left: number;
@@ -1,29 +1,49 @@
1
1
  import { type Day } from "../../core/date.cjs";
2
2
  import type { ViewContext } from "../context.cjs";
3
3
  /**
4
- * The agenda's date strip: one week, or the whole month when expanded. Days
5
- * with items carry a dot; the day at the top of the list is marked. Picking a
6
- * day hands it to the list, and swipes step a week (or a month).
4
+ * A date strip above the agenda or a time grid: one week, or the whole month
5
+ * when expanded. Days with items carry a dot; the focus day (the top of the
6
+ * list, or the grid's first day) is marked, and the rest of a grid's range is
7
+ * tinted. Picking a day hands it to the calendar, and swipes step a week (or
8
+ * a month).
7
9
  */
8
10
  export declare class DateStrip<D> {
9
11
  private readonly ctx;
10
12
  private readonly pick;
13
+ /** Called when the days on show change, so their items can be loaded. */
14
+ private readonly onShown;
11
15
  readonly el: HTMLElement;
12
16
  private readonly title;
13
17
  private readonly dows;
14
18
  private readonly grid;
15
19
  private readonly slot;
20
+ private readonly todayBtn;
16
21
  /** Day at the top of the list. */
17
22
  private focus;
18
23
  /** First day of the week shown, or the month shown when expanded. */
19
24
  private shown;
20
25
  private target;
26
+ /** Days tinted as on screen besides the focus (a time grid's range). */
27
+ private range;
28
+ private shownKey;
21
29
  private swipe;
22
30
  private swallowClick;
23
31
  expanded: boolean;
24
- constructor(ctx: ViewContext<D>, pick: (day: Day, ev: MouseEvent | KeyboardEvent) => void, focus: Day);
25
- /** The list scrolled: mark its top day and keep it in view. */
26
- setFocus(day: Day): void;
32
+ constructor(ctx: ViewContext<D>, pick: (day: Day, ev: MouseEvent | KeyboardEvent) => void, focus: Day,
33
+ /** Called when the days on show change, so their items can be loaded. */
34
+ onShown: () => void);
35
+ /** The list scrolled or the grid moved: mark the day and keep it in view. */
36
+ setFocus(day: Day, range?: {
37
+ start: Day;
38
+ end: Day;
39
+ } | null): void;
40
+ /** Publishes the strip's height as `--tnc-strip-h`, for what sticks below it. */
41
+ measure(): void;
42
+ /** First day and end (exclusive) of the days on show. */
43
+ window(): {
44
+ start: Day;
45
+ end: Day;
46
+ };
27
47
  setExpanded(on: boolean): void;
28
48
  /** Highlights the day a dragged item would land on. */
29
49
  markTarget(day: Day | null): void;
@@ -1,29 +1,49 @@
1
1
  import { type Day } from "../../core/date.js";
2
2
  import type { ViewContext } from "../context.js";
3
3
  /**
4
- * The agenda's date strip: one week, or the whole month when expanded. Days
5
- * with items carry a dot; the day at the top of the list is marked. Picking a
6
- * day hands it to the list, and swipes step a week (or a month).
4
+ * A date strip above the agenda or a time grid: one week, or the whole month
5
+ * when expanded. Days with items carry a dot; the focus day (the top of the
6
+ * list, or the grid's first day) is marked, and the rest of a grid's range is
7
+ * tinted. Picking a day hands it to the calendar, and swipes step a week (or
8
+ * a month).
7
9
  */
8
10
  export declare class DateStrip<D> {
9
11
  private readonly ctx;
10
12
  private readonly pick;
13
+ /** Called when the days on show change, so their items can be loaded. */
14
+ private readonly onShown;
11
15
  readonly el: HTMLElement;
12
16
  private readonly title;
13
17
  private readonly dows;
14
18
  private readonly grid;
15
19
  private readonly slot;
20
+ private readonly todayBtn;
16
21
  /** Day at the top of the list. */
17
22
  private focus;
18
23
  /** First day of the week shown, or the month shown when expanded. */
19
24
  private shown;
20
25
  private target;
26
+ /** Days tinted as on screen besides the focus (a time grid's range). */
27
+ private range;
28
+ private shownKey;
21
29
  private swipe;
22
30
  private swallowClick;
23
31
  expanded: boolean;
24
- constructor(ctx: ViewContext<D>, pick: (day: Day, ev: MouseEvent | KeyboardEvent) => void, focus: Day);
25
- /** The list scrolled: mark its top day and keep it in view. */
26
- setFocus(day: Day): void;
32
+ constructor(ctx: ViewContext<D>, pick: (day: Day, ev: MouseEvent | KeyboardEvent) => void, focus: Day,
33
+ /** Called when the days on show change, so their items can be loaded. */
34
+ onShown: () => void);
35
+ /** The list scrolled or the grid moved: mark the day and keep it in view. */
36
+ setFocus(day: Day, range?: {
37
+ start: Day;
38
+ end: Day;
39
+ } | null): void;
40
+ /** Publishes the strip's height as `--tnc-strip-h`, for what sticks below it. */
41
+ measure(): void;
42
+ /** First day and end (exclusive) of the days on show. */
43
+ window(): {
44
+ start: Day;
45
+ end: Day;
46
+ };
27
47
  setExpanded(on: boolean): void;
28
48
  /** Highlights the day a dragged item would land on. */
29
49
  markTarget(day: Day | null): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tasknotes/calendar",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Task-native calendar engine for TaskNotes: incremental layout, time grid, month, list, year and timeline views.",
5
5
  "license": "MIT",
6
6
  "type": "module",