@c9up/nebula 0.2.4 → 0.2.6

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 (53) hide show
  1. package/README.md +4 -4
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/NativeSelect.d.ts +16 -0
  5. package/dist/atoms/NativeSelect.js +4 -1
  6. package/dist/atoms/Progress.d.ts +9 -1
  7. package/dist/atoms/Progress.js +21 -5
  8. package/dist/atoms/Switch.d.ts +7 -1
  9. package/dist/atoms/Switch.js +7 -1
  10. package/dist/cli/diff.d.ts +46 -0
  11. package/dist/cli/diff.js +73 -2
  12. package/dist/console/DiffCommand.js +6 -11
  13. package/dist/molecules/Accordion.js +1 -2
  14. package/dist/molecules/Collapsible.js +1 -2
  15. package/dist/molecules/Resizable.d.ts +6 -0
  16. package/dist/molecules/Resizable.js +8 -2
  17. package/dist/organisms/Agenda.d.ts +200 -0
  18. package/dist/organisms/Agenda.js +762 -0
  19. package/dist/organisms/AlertDialog.js +4 -5
  20. package/dist/organisms/Chart.d.ts +103 -15
  21. package/dist/organisms/Chart.js +518 -99
  22. package/dist/organisms/Dialog.js +7 -7
  23. package/dist/organisms/Sidebar.d.ts +5 -7
  24. package/dist/organisms/Sidebar.js +23 -6
  25. package/dist/organisms/Sonner.js +11 -4
  26. package/dist/organisms/index.d.ts +2 -1
  27. package/dist/organisms/index.js +2 -1
  28. package/dist/primitives/floatingSurface.js +60 -36
  29. package/dist/primitives/menuParts.js +3 -3
  30. package/dist/primitives/portal.d.ts +15 -0
  31. package/dist/primitives/portal.js +18 -1
  32. package/nebula.css +1 -1
  33. package/package.json +1 -1
  34. package/registry.json +13 -0
  35. package/src/atoms/AspectRatio.ts +21 -6
  36. package/src/atoms/NativeSelect.ts +20 -1
  37. package/src/atoms/Progress.ts +21 -5
  38. package/src/atoms/Switch.ts +7 -1
  39. package/src/cli/diff.ts +123 -2
  40. package/src/console/DiffCommand.ts +12 -15
  41. package/src/molecules/Accordion.ts +1 -2
  42. package/src/molecules/Collapsible.ts +1 -3
  43. package/src/molecules/Resizable.ts +8 -2
  44. package/src/organisms/Agenda.ts +1061 -0
  45. package/src/organisms/AlertDialog.ts +3 -5
  46. package/src/organisms/Chart.ts +633 -125
  47. package/src/organisms/Dialog.ts +6 -7
  48. package/src/organisms/Sidebar.ts +28 -6
  49. package/src/organisms/Sonner.ts +11 -4
  50. package/src/organisms/index.ts +26 -0
  51. package/src/primitives/floatingSurface.ts +74 -40
  52. package/src/primitives/menuParts.ts +3 -3
  53. package/src/primitives/portal.ts +27 -1
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Agenda — a time grid of columns, with ranges behind and events on top.
3
+ *
4
+ * shadcn has no agenda; the usual React ones (FullCalendar, react-big-calendar)
5
+ * are whole libraries. This one keeps to what a booking screen needs: a day,
6
+ * a week, or several people side by side, with events that move and stretch
7
+ * by pointer and by keyboard alike.
8
+ *
9
+ * **Columns are the caller's.** A column is a key and a label: a day of the
10
+ * week, a practitioner on one day, a room. The agenda does not know whether it
11
+ * shows a week or a team, so the same component is the week of one person,
12
+ * the day of five, or five days of two. A column that carries a `date` gets
13
+ * the today mark and the now line.
14
+ *
15
+ * **Times are wall-clock text.** `"08:30"`, never a `Date`: a slot at half past
16
+ * eight is half past eight wherever the page is rendered, and a server in UTC
17
+ * hydrating for a browser in Zurich must draw the same grid. Dates, when a
18
+ * column has one, are `YYYY-MM-DD`.
19
+ *
20
+ * **Controlled.** Moving or stretching an event calls `onMove` or `onResize`
21
+ * with where it was dropped; the agenda never moves it itself. The caller
22
+ * updates `events` (at once, or once the server agrees) or does not, and the
23
+ * event goes back. A refused move therefore needs no undo.
24
+ *
25
+ * **Geometry.** The hour rows are real elements of a fixed height class, so the
26
+ * grid has its size in the server's markup. Ranges and events are placed in
27
+ * percentages of the grid through the CSSOM (`.style`), which a strict
28
+ * Content-Security-Policy does not govern; the server cannot write them, so
29
+ * they stay hidden until the agenda is mounted rather than drawn in the wrong
30
+ * place.
31
+ *
32
+ * **Keyboard.** One event is tabbable. The arrows walk the events — up and
33
+ * down within a column, left and right to the nearest one in the next column
34
+ * — Enter activates one, Space picks it up. Picked up, the arrows move it by
35
+ * the snap and across columns, Shift with Up or Down changes its end, Enter or
36
+ * Space drops it, Escape puts it back. Every step is announced.
37
+ */
38
+ import { type ReadSignal } from "@c9up/aurora";
39
+ import type { Child } from "../lib/children.js";
40
+ import { type Reactive } from "../lib/props.js";
41
+ /** A column of the grid: a day, a person on a day, a room. */
42
+ export interface AgendaColumn {
43
+ key: string;
44
+ label: string;
45
+ /** A second line under the label: who is away, how full the day is. */
46
+ hint?: string;
47
+ /** The calendar day it shows, `YYYY-MM-DD`: marks today and draws the now line. */
48
+ date?: string;
49
+ /** A public holiday: the header is marked. */
50
+ holiday?: boolean;
51
+ }
52
+ /**
53
+ * What a colour says. One meaning each, never decoration: an app maps its own
54
+ * states (free, booked, arrived, cancelled) onto these.
55
+ */
56
+ export type AgendaTone = "default" | "primary" | "success" | "warning" | "danger" | "muted";
57
+ /** A span drawn behind the events: a consultation block, an absence. */
58
+ export interface AgendaRange {
59
+ key: string;
60
+ column: string;
61
+ /** `HH:mm`. */
62
+ start: string;
63
+ /** `HH:mm`, after `start`. */
64
+ end: string;
65
+ label?: string;
66
+ tone?: AgendaTone;
67
+ /** Hatched: time that is not available (an absence, a closed block). */
68
+ hatched?: boolean;
69
+ }
70
+ /** An event: an appointment, a free slot offered for booking. */
71
+ export interface AgendaEvent {
72
+ key: string;
73
+ column: string;
74
+ /** `HH:mm`. */
75
+ start: string;
76
+ /** `HH:mm`, after `start`. */
77
+ end: string;
78
+ title: string;
79
+ detail?: string;
80
+ tone?: AgendaTone;
81
+ /** Any CSS colour for the left edge: a category's own colour. */
82
+ accent?: string;
83
+ /** Drawn struck through: cancelled. */
84
+ struck?: boolean;
85
+ /** May be dragged to another time or column. */
86
+ movable?: boolean;
87
+ /** May have its end dragged. */
88
+ resizable?: boolean;
89
+ }
90
+ /** Where an event was dropped. */
91
+ export interface AgendaChange {
92
+ event: AgendaEvent;
93
+ column: string;
94
+ start: string;
95
+ end: string;
96
+ }
97
+ /** A free point of the grid, clicked. */
98
+ export interface AgendaSlot {
99
+ column: string;
100
+ start: string;
101
+ }
102
+ /**
103
+ * The words the agenda writes itself. `{title}`, `{column}`, `{start}` and
104
+ * `{end}` are replaced where they appear.
105
+ */
106
+ export interface AgendaLabels {
107
+ /** How a screen reader is told to use an event. */
108
+ keyboardHint: string;
109
+ /** Announced when an event is picked up. */
110
+ grabbed: string;
111
+ /** Announced at each step while it is held, and when it is dropped. */
112
+ moved: string;
113
+ /** Announced when Escape puts it back. */
114
+ cancelled: string;
115
+ /** The now line. */
116
+ now: string;
117
+ /** The handle that stretches an event. */
118
+ resize: string;
119
+ }
120
+ export interface AgendaProps {
121
+ /** The grid's accessible name. */
122
+ label: string;
123
+ columns: Reactive<readonly AgendaColumn[]>;
124
+ events: Reactive<readonly AgendaEvent[]>;
125
+ ranges?: Reactive<readonly AgendaRange[]>;
126
+ /** First and last hour shown, `[7, 20]` by default: 07:00 to 20:00. */
127
+ hours?: readonly [number, number];
128
+ /** Minutes between two grid lines. Default `15`. */
129
+ step?: number;
130
+ /** Minutes an event moves by. Default: `step`. */
131
+ snap?: number;
132
+ /** Height of an hour. Default `"md"`. */
133
+ size?: "sm" | "md" | "lg";
134
+ /** BCP 47 locale for the hours. Default: the runtime's own. */
135
+ locale?: string;
136
+ labels?: Partial<AgendaLabels>;
137
+ /** The time it is: a clock for the now line, injectable for tests. */
138
+ now?: () => Date;
139
+ /** `HH:mm` scrolled to when mounted. Default: the first range or event. */
140
+ scrollTo?: string;
141
+ class?: Reactive<string>;
142
+ /**
143
+ * Classes of the body: its height. Default `"max-h-[40rem]"`, a body that
144
+ * scrolls on its own. Give `""` to let the agenda take its full height in a
145
+ * page that scrolls already: one scrollbar, the column headers staying in
146
+ * view (they are sticky, and the root clips without scrolling).
147
+ */
148
+ bodyClass?: string;
149
+ /** An event chosen: clicked, or Enter. */
150
+ onActivate?: (event: AgendaEvent) => void;
151
+ /** A range's label chosen. Without it, ranges are not interactive. */
152
+ onRangeActivate?: (range: AgendaRange) => void;
153
+ /** An empty point of the grid clicked. */
154
+ onSlotActivate?: (slot: AgendaSlot) => void;
155
+ /** An event dropped at another time or in another column (its end follows). */
156
+ onMove?: (change: AgendaChange) => void;
157
+ /** An event's end dragged, its start and column unchanged. */
158
+ onResize?: (change: AgendaChange) => void;
159
+ /** The content of an event, instead of its times, title and detail. */
160
+ renderEvent?: (event: ReadSignal<AgendaEvent>) => Child;
161
+ }
162
+ /** Minutes since midnight of `HH:mm`, or `null` when it is not one. */
163
+ export declare function minutesOf(clock: string): number | null;
164
+ /** `HH:mm` of minutes since midnight. */
165
+ export declare function clockOf(minutes: number): string;
166
+ /** `YYYY-MM-DD` of a date, on its own wall clock. */
167
+ export declare function isoDay(date: Date): string;
168
+ /** An event's place among those it overlaps: its lane, of how many. */
169
+ export interface Lane {
170
+ lane: number;
171
+ lanes: number;
172
+ }
173
+ /**
174
+ * Side-by-side lanes for the events of one column.
175
+ *
176
+ * Events that overlap, directly or through a chain, form a cluster; each takes
177
+ * the first lane free at its start, and every event of the cluster is drawn
178
+ * at the width of the cluster's lane count. Touching is not overlapping: an
179
+ * event ending at 09:00 and one starting at 09:00 share a lane.
180
+ */
181
+ export declare function lanesOf(events: readonly {
182
+ key: string;
183
+ start: number;
184
+ end: number;
185
+ }[]): Map<string, Lane>;
186
+ /** `value` down to a multiple of `snap`. */
187
+ export declare function snapDown(value: number, snap: number): number;
188
+ /** `value` to the nearest multiple of `snap`. */
189
+ export declare function snapNearest(value: number, snap: number): number;
190
+ /**
191
+ * A move kept within the grid: the start between the first hour and the
192
+ * last minus the duration, the duration unchanged.
193
+ */
194
+ export declare function clampMove(start: number, duration: number, from: number, to: number): {
195
+ start: number;
196
+ end: number;
197
+ };
198
+ /** A new end kept after the start by one snap at least, and within the grid. */
199
+ export declare function clampEnd(start: number, end: number, snap: number, to: number): number;
200
+ export declare const Agenda: (props?: AgendaProps | undefined) => import("@c9up/aurora").TemplateResult;