@jsb188/calendar 1.1.11 → 1.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsb188/calendar",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "Calendar and scheduling surface for web.",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
@@ -17,27 +17,26 @@
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",
26
+ "./ui/ShiftFormUI": "./src/ui/ShiftFormUI.tsx",
27
+ "./types/shift-form.d.ts": "./src/types/shift-form.d.ts"
30
28
  },
31
29
  "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",
30
+ "@jsb188/app": "1.1.12",
31
+ "@jsb188/graphql": "1.1.12",
32
+ "@jsb188/mday": "1.1.12",
33
+ "@jsb188/react": "1.1.12",
34
+ "@jsb188/react-web": "1.1.12",
37
35
  "jotai": "^2.20.2",
38
36
  "luxon": "^3.7.2",
39
- "react": "^19.2.8",
40
- "react-router": "^8.3.0"
37
+ "react": "^19.3.0",
38
+ "react-router": "^8.4.0",
39
+ "@jsb188/form": "1.1.12"
41
40
  },
42
41
  "scripts": {
43
42
  "test": "vitest run --config ./vitest.config.ts --passWithNoTests",
@@ -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,6 +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',
114
+ panel: 'p',
115
+ open: 'o',
109
116
  date: 'd',
110
117
  mine: 'me',
111
118
  // The calendars the viewer has HIDDEN; absent means show everything
@@ -118,6 +125,7 @@ export const CALENDAR_SEARCH_PARAMS = {
118
125
  */
119
126
 
120
127
  export const CALENDAR_VIEW_SLUGS: Record<CalendarViewEnum, string> = {
128
+ ROSTER: 'roster',
121
129
  DAY: 'day',
122
130
  FOUR_DAYS: '4day',
123
131
  WEEK: 'week',
@@ -141,6 +149,5 @@ export const CALENDAR_DATE_PARAM_FORMAT = 'yyyy-MM-dd';
141
149
 
142
150
  // The stripe pattern is a MASK on a :before pseudo-element, so it needs both a
143
151
  // 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.
152
+ // positioned element) or it renders as nothing at all.
146
153
  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
 
@@ -243,6 +243,7 @@ function getCalendarViewDays(p: {
243
243
  const { view, anchor, weekStartsOn, todayKey } = p;
244
244
 
245
245
  switch (view) {
246
+ case 'ROSTER':
246
247
  case 'WEEK':
247
248
  return buildConsecutiveDays(
248
249
  getWeekStart(anchor, weekStartsOn),
@@ -286,6 +287,7 @@ export function getCalendarStepAnchor(p: {
286
287
  }).startOf('day');
287
288
 
288
289
  switch (view) {
290
+ case 'ROSTER':
289
291
  case 'WEEK':
290
292
  return anchor.plus({ weeks: direction }).toJSDate();
291
293
  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
- }
@@ -30,6 +30,11 @@ import {
30
30
  */
31
31
 
32
32
  export interface CalendarUrlState {
33
+ calendarId: string | null;
34
+ roomId: string | null;
35
+ groupByRoom: boolean;
36
+ panel: 'open' | 'requests' | 'timeoff' | 'publish' | 'settings' | null;
37
+ openId: string | null;
33
38
  view: CalendarViewEnum;
34
39
  anchorDate: Date;
35
40
  mineOnly: boolean;
@@ -93,6 +98,15 @@ export function readCalendarUrlState(
93
98
  const calendars = searchParams.get(CALENDAR_SEARCH_PARAMS.hiddenCalendars);
94
99
 
95
100
  return {
101
+ calendarId: searchParams.get('cal') || null,
102
+ roomId: searchParams.get('room') || null,
103
+ groupByRoom: searchParams.get('rooms') === '1',
104
+ panel: ['open', 'requests', 'timeoff', 'publish', 'settings'].includes(
105
+ searchParams.get('p') || '',
106
+ )
107
+ ? (searchParams.get('p') as CalendarUrlState['panel'])
108
+ : null,
109
+ openId: searchParams.get('o') || null,
96
110
  view: parseCalendarViewSlug(searchParams.get(CALENDAR_SEARCH_PARAMS.view)),
97
111
  anchorDate: parseCalendarDateParam(
98
112
  searchParams.get(CALENDAR_SEARCH_PARAMS.date),
@@ -163,5 +177,15 @@ export function writeCalendarUrlState(
163
177
  );
164
178
  }
165
179
 
180
+ for (const [field, key] of [
181
+ ['calendarId', 'cal'],
182
+ ['roomId', 'room'],
183
+ ['panel', 'p'],
184
+ ['openId', 'o'],
185
+ ] as const) {
186
+ if (next[field] !== undefined) setOrDelete(key, next[field] || null);
187
+ }
188
+ if (next.groupByRoom !== undefined)
189
+ setOrDelete('rooms', next.groupByRoom ? '1' : null);
166
190
  return params;
167
191
  }