@jsb188/calendar 1.1.11 → 1.1.13

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jsb188
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@jsb188/calendar",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "Calendar and scheduling surface for web.",
5
- "license": "ISC",
5
+ "license": "MIT",
6
6
  "author": "jsb188",
7
7
  "type": "module",
8
8
  "exports": {
@@ -17,30 +17,35 @@
17
17
  "./modules/MiniCalendar": "./src/modules/MiniCalendar.tsx",
18
18
  "./types/calendar.d.ts": "./src/types/calendar.d.ts",
19
19
  "./ui/CalendarAgendaUI": "./src/ui/CalendarAgendaUI.tsx",
20
- "./ui/CalendarCoverageUI": "./src/ui/CalendarCoverageUI.tsx",
21
- "./ui/CalendarEventDetailUI": "./src/ui/CalendarEventDetailUI.tsx",
22
- "./ui/CalendarEventFormUI": "./src/ui/CalendarEventFormUI.tsx",
23
20
  "./ui/CalendarMonthUI": "./src/ui/CalendarMonthUI.tsx",
24
- "./ui/CalendarRailUI": "./src/ui/CalendarRailUI.tsx",
25
- "./ui/CalendarRequestUI": "./src/ui/CalendarRequestUI.tsx",
26
21
  "./ui/CalendarToolbarUI": "./src/ui/CalendarToolbarUI.tsx",
27
22
  "./ui/CalendarUI": "./src/ui/CalendarUI.tsx",
28
- "./ui/CalendarViolationUI": "./src/ui/CalendarViolationUI.tsx",
29
- "./ui/CalendarYearUI": "./src/ui/CalendarYearUI.tsx"
23
+ "./ui/CalendarYearUI": "./src/ui/CalendarYearUI.tsx",
24
+ "./libs/roster-layout": "./src/libs/roster-layout.ts",
25
+ "./ui/RosterUI": "./src/ui/RosterUI.tsx"
30
26
  },
31
27
  "peerDependencies": {
32
- "@jsb188/app": "1.1.11",
33
- "@jsb188/graphql": "1.1.11",
34
- "@jsb188/mday": "1.1.11",
35
- "@jsb188/react": "1.1.11",
36
- "@jsb188/react-web": "1.1.11",
28
+ "@jsb188/app": "1.1.13",
29
+ "@jsb188/graphql": "1.1.13",
30
+ "@jsb188/mday": "1.1.13",
31
+ "@jsb188/react": "1.1.13",
32
+ "@jsb188/react-web": "1.1.13",
37
33
  "jotai": "^2.20.2",
38
34
  "luxon": "^3.7.2",
39
- "react": "^19.2.8",
40
- "react-router": "^8.3.0"
35
+ "react": "^19.3.0",
36
+ "react-router": "^8.4.0",
37
+ "@jsb188/form": "1.1.13"
41
38
  },
42
39
  "scripts": {
43
40
  "test": "vitest run --config ./vitest.config.ts --passWithNoTests",
44
41
  "build": "tsc"
45
- }
42
+ },
43
+ "files": [
44
+ "src/**/*.{ts,tsx,css,svg}",
45
+ "!**/*.test.*",
46
+ "!**/*.spec.*",
47
+ "!**/tests/**",
48
+ "!**/*.md",
49
+ "!**/.DS_Store"
50
+ ]
46
51
  }
@@ -13,6 +13,7 @@
13
13
  */
14
14
 
15
15
  export const CALENDAR_VIEW_ENUMS = [
16
+ 'ROSTER',
16
17
  'DAY',
17
18
  'FOUR_DAYS',
18
19
  'WEEK',
@@ -28,6 +29,7 @@ export type CalendarViewEnum = (typeof CALENDAR_VIEW_ENUMS)[number];
28
29
  export const CALENDAR_VIEW_DAY_COUNTS: Partial<
29
30
  Record<CalendarViewEnum, number>
30
31
  > = {
32
+ ROSTER: 7,
31
33
  DAY: 1,
32
34
  FOUR_DAYS: 4,
33
35
  WEEK: 7,
@@ -106,10 +108,11 @@ export const CALENDAR_MONTH_CELL_MAX_EVENTS = 3;
106
108
 
107
109
  export const CALENDAR_SEARCH_PARAMS = {
108
110
  view: 'v',
111
+ calendar: 'cal',
112
+ room: 'room',
113
+ groupByRoom: 'rooms',
109
114
  date: 'd',
110
115
  mine: 'me',
111
- // The calendars the viewer has HIDDEN; absent means show everything
112
- hiddenCalendars: 'hide',
113
116
  } as const;
114
117
 
115
118
  /**
@@ -118,6 +121,7 @@ export const CALENDAR_SEARCH_PARAMS = {
118
121
  */
119
122
 
120
123
  export const CALENDAR_VIEW_SLUGS: Record<CalendarViewEnum, string> = {
124
+ ROSTER: 'roster',
121
125
  DAY: 'day',
122
126
  FOUR_DAYS: '4day',
123
127
  WEEK: 'week',
@@ -133,14 +137,13 @@ export const CALENDAR_DEFAULT_VIEW: CalendarViewEnum = 'WEEK';
133
137
  export const CALENDAR_DATE_PARAM_FORMAT = 'yyyy-MM-dd';
134
138
 
135
139
  /**
136
- * Occurrence status → surface treatment. DRAFT is drawn with the shared
137
- * stripe pattern so an unpublished shift reads as provisional at a glance,
138
- * and CANCELED is struck through rather than hidden — somebody looking for a
140
+ * Seat status → surface treatment. DRAFT is drawn with the shared stripe
141
+ * pattern so an unpublished shift reads as provisional at a glance, and
142
+ * CANCELED is struck through rather than hidden — somebody looking for a
139
143
  * shift that was cancelled needs to find it, not wonder where it went.
140
144
  */
141
145
 
142
146
  // The stripe pattern is a MASK on a :before pseudo-element, so it needs both a
143
147
  // fill colour class ("*_bf") and a positioned parent ("rel", or any absolutely
144
- // positioned element) or it renders as nothing at all. This is the same
145
- // combination DataTable-InboundContact and VerticalDataTableDesigner use.
148
+ // positioned element) or it renders as nothing at all.
146
149
  export const CALENDAR_DRAFT_PATTERN_CLASS_NAME = 'pattern_stripes medium_bf';
@@ -368,10 +368,8 @@ export function getCalendarAllDayLayout(
368
368
  continue;
369
369
  }
370
370
 
371
- // An entry belongs in the band when it is flagged all-day, or when it
372
- // simply spans more than one of the days on screen — a three-day
373
- // closure is not usefully drawn as three tall columns
374
- if (!event.allDay && span.startDayIndex === span.endDayIndex) {
371
+ // Timed overnight events remain in the timed grid only.
372
+ if (!event.allDay) {
375
373
  continue;
376
374
  }
377
375
 
@@ -179,9 +179,8 @@ function buildMonthDays(
179
179
  *
180
180
  * The year view is a NAVIGATION surface, not a display one: twelve mini month
181
181
  * grids you click to jump into. It deliberately does not draw events, so this
182
- * only has to produce the days — which is also why the page skips the
183
- * occurrence query entirely for this view rather than asking for a year of
184
- * shifts and silently truncating them at the window limit.
182
+ * only has to produce the days; a caller should not fetch events for this
183
+ * view (a year of them would be truncated at any read limit).
185
184
  */
186
185
 
187
186
  function buildYearDays(anchor: DateTime, todayKey: string): CalendarDayObj[] {
@@ -243,6 +242,7 @@ function getCalendarViewDays(p: {
243
242
  const { view, anchor, weekStartsOn, todayKey } = p;
244
243
 
245
244
  switch (view) {
245
+ case 'ROSTER':
246
246
  case 'WEEK':
247
247
  return buildConsecutiveDays(
248
248
  getWeekStart(anchor, weekStartsOn),
@@ -286,6 +286,7 @@ export function getCalendarStepAnchor(p: {
286
286
  }).startOf('day');
287
287
 
288
288
  switch (view) {
289
+ case 'ROSTER':
289
290
  case 'WEEK':
290
291
  return anchor.plus({ weeks: direction }).toJSDate();
291
292
  case 'MONTH':
@@ -1,168 +1,26 @@
1
- import { atom } from 'jotai';
2
- import type {
3
- CalendarEventObj,
4
- CalendarSelectionObj,
5
- } from '../types/calendar.d.ts';
6
-
7
- /**
8
- * Calendar app state.
9
- *
10
- * Three rules from the grid packages are followed here deliberately:
11
- *
12
- * - **Atoms are created per mounted calendar by a factory**, never at module
13
- * scope. There is one Jotai store in the whole app, so isolation comes from
14
- * atom object identity: two calendars on one page get two bags and cannot
15
- * see each other's selection.
16
- *
17
- * - **View and anchor date are NOT here.** They live in the URL, because the
18
- * app shell remounts a route on every pathname change but not on a search
19
- * change — so a week in the URL survives navigation, is linkable, and does
20
- * not tear the calendar down when the user pages through months.
21
- *
22
- * - **Nothing that changes every animation frame is an atom.** A drag in
23
- * progress is a ref inside the grid; only its committed result reaches this
24
- * module. An atom written on pointermove would re-render every event in the
25
- * week sixty times a second.
26
- */
27
-
28
- /**
29
- * What the user is currently doing with the pointer, once it has committed to
30
- * being something. The in-flight pixel positions stay in the grid's refs.
31
- */
32
-
33
- export interface CalendarDraftObj {
34
- kind: 'CREATE' | 'MOVE' | 'RESIZE';
35
- // The event being moved or resized; null while creating a new one
36
- eventId: string | null;
37
- startAt: Date;
38
- endAt: Date;
39
- allDay: boolean;
40
- calendarId: string | null;
41
- }
42
-
43
- /**
44
- * The event detail popover's anchor and target.
45
- */
46
-
47
- export interface CalendarPopoverStateObj {
48
- eventId: string;
49
- // Viewport coordinates of the element that opened it
50
- anchorRect: { top: number; left: number; width: number; height: number };
51
- }
52
-
53
- /*
54
- * Return the empty visible-calendar map. Absent means "not yet decided", which
55
- * the page fills from the URL or from the calendar list; an explicit false is
56
- * what a user actually unticking a calendar writes.
57
- */
58
-
59
- export function getInitialVisibleCalendarIds(): Record<string, boolean> {
60
- return {};
1
+ import { atom, type PrimitiveAtom } from 'jotai';
2
+
3
+ export interface CalendarStateAtoms {
4
+ selectedEventIdAtom: PrimitiveAtom<string | null>;
5
+ draftRangeAtom: PrimitiveAtom<{
6
+ startAt: Date;
7
+ endAt: Date;
8
+ roomId: string | null;
9
+ } | null>;
10
+ pendingIdsAtom: PrimitiveAtom<ReadonlySet<string>>;
11
+ hoverPersonIdAtom: PrimitiveAtom<string | null>;
61
12
  }
62
13
 
63
- /**
64
- * Create the atom group for one mounted calendar.
65
- */
66
-
67
- export function createCalendarStateAtoms(scopeKey = '') {
14
+ /* Create isolated committed interaction state; pointer movement stays in refs and authority stays in server rows. */
15
+ export function createCalendarStateAtoms(): CalendarStateAtoms {
68
16
  return {
69
- scopeKey,
70
-
71
- // The event whose detail popover is open, with where to anchor it
72
- popoverStateAtom: atom<CalendarPopoverStateObj | null>(null),
73
-
74
- // The committed result of a drag: a new block being drawn, or an
75
- // existing event moved or resized but not yet saved
76
- draftAtom: atom<CalendarDraftObj | null>(null),
77
-
78
- // A time range the user has selected without creating anything yet
79
- selectionAtom: atom<CalendarSelectionObj | null>(null),
80
-
81
- // Which overlaid calendars are drawn; absent means visible
82
- visibleCalendarIdsAtom: atom<Record<string, boolean>>(
83
- getInitialVisibleCalendarIds(),
84
- ),
85
-
86
- // Optimistic edits applied over server data while a mutation is in
87
- // flight, keyed by event id. Cleared when authority arrives, so a
88
- // failed save snaps back rather than leaving a phantom shift behind.
89
- optimisticEventsAtom: atom<Map<string, CalendarEventObj>>(new Map()),
90
-
91
- // Events the user has just deleted or cancelled, hidden until the
92
- // server confirms; same reasoning as above in the other direction
93
- optimisticallyRemovedEventIdsAtom: atom<Set<string>>(new Set<string>()),
94
-
95
- // The coverage board's currently inspected violation, if any
96
- inspectedViolationKeyAtom: atom<string | null>(null),
97
-
98
- // Whether the left rail (calendar list, mini month) is expanded
99
- railOpenAtom: atom(true),
17
+ selectedEventIdAtom: atom<string | null>(null),
18
+ draftRangeAtom: atom<{
19
+ startAt: Date;
20
+ endAt: Date;
21
+ roomId: string | null;
22
+ } | null>(null),
23
+ pendingIdsAtom: atom<ReadonlySet<string>>(new Set<string>()),
24
+ hoverPersonIdAtom: atom<string | null>(null),
100
25
  };
101
26
  }
102
-
103
- export type CalendarStateAtoms = ReturnType<typeof createCalendarStateAtoms>;
104
-
105
- /**
106
- * Return the stable scope key for one mounted calendar.
107
- */
108
-
109
- export function getCalendarStateScopeKey(
110
- organizationId?: string | null,
111
- ): string {
112
- return ['calendar', organizationId || 'pending'].join(':');
113
- }
114
-
115
- /**
116
- * Apply the optimistic overlays to a list of server events.
117
- *
118
- * Kept as a plain function rather than a derived atom so the caller decides
119
- * when it runs: it is a full pass over the week, and it should happen once per
120
- * data change inside a memo, not once per subscriber.
121
- */
122
-
123
- export function applyCalendarOptimisticOverlays(
124
- events: CalendarEventObj[],
125
- optimisticEvents: Map<string, CalendarEventObj>,
126
- removedEventIds: Set<string>,
127
- ): CalendarEventObj[] {
128
- if (!optimisticEvents.size && !removedEventIds.size) {
129
- // Returning the SAME array reference on a no-op matters: this feeds a
130
- // memoized layout pass, and a fresh array would recompute the whole week
131
- return events;
132
- }
133
-
134
- const merged: CalendarEventObj[] = [];
135
- const seen = new Set<string>();
136
-
137
- for (const event of events) {
138
- if (removedEventIds.has(event.id)) {
139
- continue;
140
- }
141
-
142
- seen.add(event.id);
143
- merged.push(optimisticEvents.get(event.id) || event);
144
- }
145
-
146
- // An optimistic event with no server counterpart is one being created
147
- for (const [eventId, event] of optimisticEvents) {
148
- if (!seen.has(eventId) && !removedEventIds.has(eventId)) {
149
- merged.push(event);
150
- }
151
- }
152
-
153
- return merged;
154
- }
155
-
156
- /**
157
- * Return whether one calendar is drawn, treating "absent" as visible.
158
- *
159
- * A calendar the viewer has just been granted access to should appear without
160
- * them having to find and tick it; only an explicit untick hides one.
161
- */
162
-
163
- export function isCalendarVisible(
164
- visibleCalendarIds: Record<string, boolean>,
165
- calendarId: string,
166
- ): boolean {
167
- return visibleCalendarIds[calendarId] !== false;
168
- }
@@ -13,12 +13,12 @@ import {
13
13
  * The calendar's URL state.
14
14
  *
15
15
  * The URL is the calendar's state store for anything a person might want to
16
- * link to or come back to: which view, which date, whose shifts, which
17
- * calendars. It is kept deliberately terse and readable — one- and two-letter
18
- * keys, lowercase view slugs, and every default omitted — so that
16
+ * link to or come back to: which calendar, which view, which date, whose
17
+ * shifts, which room. It is kept deliberately terse and readable — one- and
18
+ * two-letter keys, lowercase view slugs, and every default omitted — so that
19
19
  *
20
20
  * /app/calendar
21
- * /app/calendar?v=month&d=2026-07-25
21
+ * /app/calendar?cal=<id>&v=roster&d=2026-07-25
22
22
  * /app/calendar?me=1
23
23
  *
24
24
  * are what somebody actually sees in the address bar, rather than a query
@@ -30,14 +30,12 @@ import {
30
30
  */
31
31
 
32
32
  export interface CalendarUrlState {
33
+ calendarId: string | null;
34
+ roomId: string | null;
35
+ groupByRoom: boolean;
33
36
  view: CalendarViewEnum;
34
37
  anchorDate: Date;
35
38
  mineOnly: boolean;
36
- // Calendars the viewer has explicitly HIDDEN — a blocklist, not a
37
- // whitelist. Empty therefore means "show everything", which is what makes
38
- // a calendar the viewer was just granted access to appear on its own
39
- // instead of staying invisible until they find and tick it.
40
- hiddenCalendarIds: string[];
41
39
  }
42
40
 
43
41
  const VIEW_BY_SLUG: Record<string, CalendarViewEnum> = Object.fromEntries(
@@ -90,9 +88,10 @@ export function readCalendarUrlState(
90
88
  now: Date,
91
89
  timeZone?: string | null,
92
90
  ): CalendarUrlState {
93
- const calendars = searchParams.get(CALENDAR_SEARCH_PARAMS.hiddenCalendars);
94
-
95
91
  return {
92
+ calendarId: searchParams.get(CALENDAR_SEARCH_PARAMS.calendar) || null,
93
+ roomId: searchParams.get(CALENDAR_SEARCH_PARAMS.room) || null,
94
+ groupByRoom: searchParams.get(CALENDAR_SEARCH_PARAMS.groupByRoom) === '1',
96
95
  view: parseCalendarViewSlug(searchParams.get(CALENDAR_SEARCH_PARAMS.view)),
97
96
  anchorDate: parseCalendarDateParam(
98
97
  searchParams.get(CALENDAR_SEARCH_PARAMS.date),
@@ -100,12 +99,6 @@ export function readCalendarUrlState(
100
99
  timeZone,
101
100
  ),
102
101
  mineOnly: searchParams.get(CALENDAR_SEARCH_PARAMS.mine) === '1',
103
- hiddenCalendarIds: calendars
104
- ? calendars
105
- .split(',')
106
- .map((id) => id.trim())
107
- .filter(Boolean)
108
- : [],
109
102
  };
110
103
  }
111
104
 
@@ -156,10 +149,18 @@ export function writeCalendarUrlState(
156
149
  setOrDelete(CALENDAR_SEARCH_PARAMS.mine, next.mineOnly ? '1' : null);
157
150
  }
158
151
 
159
- if (next.hiddenCalendarIds !== undefined) {
152
+ if (next.calendarId !== undefined) {
153
+ setOrDelete(CALENDAR_SEARCH_PARAMS.calendar, next.calendarId || null);
154
+ }
155
+
156
+ if (next.roomId !== undefined) {
157
+ setOrDelete(CALENDAR_SEARCH_PARAMS.room, next.roomId || null);
158
+ }
159
+
160
+ if (next.groupByRoom !== undefined) {
160
161
  setOrDelete(
161
- CALENDAR_SEARCH_PARAMS.hiddenCalendars,
162
- next.hiddenCalendarIds.length ? next.hiddenCalendarIds.join(',') : null,
162
+ CALENDAR_SEARCH_PARAMS.groupByRoom,
163
+ next.groupByRoom ? '1' : null,
163
164
  );
164
165
  }
165
166