@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.
@@ -1,266 +0,0 @@
1
- import { cn } from '@jsb188/app/utils/string.ts';
2
- import { Input, Textarea } from '@jsb188/react-web/modules/Form';
3
- import { Button } from '@jsb188/react-web/ui/Button';
4
- import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
5
- import { memo } from 'react';
6
-
7
- /**
8
- * The create / edit form for one occurrence.
9
- *
10
- * Fully controlled: every keystroke leaves through onChangeValue and comes
11
- * back as a prop. The form owns no draft of its own, because the same draft
12
- * has to survive the bubble closing, a drag on the grid moving the block, and
13
- * the modal being reopened — none of which this component can see.
14
- *
15
- * Dates and times are kept as the browser's own wire formats ("yyyy-MM-dd" and
16
- * "HH:mm") rather than as Date objects. There is no datetime picker in the UI
17
- * kit, so these are native date/time inputs, and native inputs speak those two
18
- * strings; keeping the props in the same shape means nothing here has to parse
19
- * or re-serialize, and the zone stays the caller's problem — which is correct,
20
- * since only the caller knows the calendar's display zone.
21
- */
22
-
23
- export interface CalendarEventFormValuesObj {
24
- title: string;
25
- allDay: boolean;
26
- // "yyyy-MM-dd", the value an <input type='date'> reads and writes
27
- startDate: string;
28
- // "HH:mm" in 24-hour time, the value an <input type='time'> reads and writes
29
- startTime: string;
30
- endDate: string;
31
- endTime: string;
32
- location: string;
33
- note: string;
34
- }
35
-
36
- export type CalendarEventFormFieldEnum = keyof CalendarEventFormValuesObj;
37
-
38
- export interface CalendarEventFormUIProps {
39
- className?: string;
40
- values: CalendarEventFormValuesObj;
41
- headingText: string;
42
- titleLabel: string;
43
- titlePlaceholder: string;
44
- allDayText: string;
45
- startLabel: string;
46
- endLabel: string;
47
- locationLabel: string;
48
- locationPlaceholder: string;
49
- noteLabel: string;
50
- notePlaceholder: string;
51
- saveText: string;
52
- // Swapped in for saveText while a save is in flight, if the caller has one
53
- savingText?: string;
54
- cancelText: string;
55
- // Validation or mutation failure, already worded by the caller
56
- errorText?: string | null;
57
- saving?: boolean;
58
- // Lets the caller veto a save the form cannot see is wrong — an end before
59
- // its start, a slot that violates a rule
60
- disableSave?: boolean;
61
- onChangeValue: (
62
- field: CalendarEventFormFieldEnum,
63
- value: string | boolean,
64
- ) => void;
65
- onSubmit: () => void;
66
- onCancel: () => void;
67
- }
68
-
69
- export const CalendarEventFormUI = memo((p: CalendarEventFormUIProps) => {
70
- const {
71
- className,
72
- values,
73
- headingText,
74
- titleLabel,
75
- titlePlaceholder,
76
- allDayText,
77
- startLabel,
78
- endLabel,
79
- locationLabel,
80
- locationPlaceholder,
81
- noteLabel,
82
- notePlaceholder,
83
- saveText,
84
- savingText,
85
- cancelText,
86
- errorText,
87
- saving,
88
- disableSave,
89
- onChangeValue,
90
- onSubmit,
91
- onCancel,
92
- } = p;
93
-
94
- // An untitled occurrence is unreadable on the grid, so it is the one rule
95
- // the form enforces by itself; everything else is the caller's to judge
96
- const saveDisabled = !!saving || !!disableSave || !values.title.trim();
97
-
98
- return (
99
- <div className={cn('v_stretch of', className)}>
100
- <div
101
- className="no_shrink ft_md ft_bold bd_b_1 bd_b_bd"
102
- style={{
103
- paddingLeft: 12,
104
- paddingRight: 12,
105
- paddingTop: 8,
106
- paddingBottom: 8,
107
- }}
108
- >
109
- {headingText}
110
- </div>
111
-
112
- <div
113
- className="f h_0 app_scr auto_y"
114
- style={{
115
- paddingLeft: 12,
116
- paddingRight: 12,
117
- paddingTop: 8,
118
- paddingBottom: 8,
119
- }}
120
- >
121
- <Input
122
- fullWidth
123
- autoFocus
124
- preset="fill"
125
- name="title"
126
- label={titleLabel}
127
- placeholder={titlePlaceholder}
128
- disabled={saving}
129
- value={values.title}
130
- onChange={(e) => onChangeValue('title', e.currentTarget.value)}
131
- />
132
-
133
- <label
134
- className="h_item gap_sm pointer unsel"
135
- style={{ paddingTop: 10, paddingBottom: 6 }}
136
- >
137
- <ToggleSwitch
138
- size="sm"
139
- disabled={saving}
140
- checked={values.allDay}
141
- onChange={(e) => onChangeValue('allDay', e.currentTarget.checked)}
142
- />
143
- <span className="ft_sm">{allDayText}</span>
144
- </label>
145
-
146
- {/* The kit has no datetime control, so a row is a native date input
147
- plus a native time input; the time half disappears for an all-day
148
- entry rather than being disabled, because there is no time to edit */}
149
- <div
150
- className="h_item gap_sm"
151
- style={{ paddingTop: 4, paddingBottom: 4 }}
152
- >
153
- <Input
154
- fullWidth
155
- className="f"
156
- preset="fill"
157
- type="date"
158
- name="startDate"
159
- label={startLabel}
160
- disabled={saving}
161
- value={values.startDate}
162
- onChange={(e) => onChangeValue('startDate', e.currentTarget.value)}
163
- />
164
-
165
- {values.allDay ? null : (
166
- <Input
167
- className="no_shrink"
168
- preset="fill"
169
- type="time"
170
- name="startTime"
171
- disabled={saving}
172
- value={values.startTime}
173
- onChange={(e) =>
174
- onChangeValue('startTime', e.currentTarget.value)
175
- }
176
- />
177
- )}
178
- </div>
179
-
180
- <div
181
- className="h_item gap_sm"
182
- style={{ paddingTop: 4, paddingBottom: 4 }}
183
- >
184
- <Input
185
- fullWidth
186
- className="f"
187
- preset="fill"
188
- type="date"
189
- name="endDate"
190
- label={endLabel}
191
- disabled={saving}
192
- value={values.endDate}
193
- onChange={(e) => onChangeValue('endDate', e.currentTarget.value)}
194
- />
195
-
196
- {values.allDay ? null : (
197
- <Input
198
- className="no_shrink"
199
- preset="fill"
200
- type="time"
201
- name="endTime"
202
- disabled={saving}
203
- value={values.endTime}
204
- onChange={(e) => onChangeValue('endTime', e.currentTarget.value)}
205
- />
206
- )}
207
- </div>
208
-
209
- <Input
210
- fullWidth
211
- className="mt_xs"
212
- preset="fill"
213
- name="location"
214
- label={locationLabel}
215
- placeholder={locationPlaceholder}
216
- disabled={saving}
217
- value={values.location}
218
- onChange={(e) => onChangeValue('location', e.currentTarget.value)}
219
- />
220
-
221
- <Textarea
222
- fullWidth
223
- className="mt_xs"
224
- preset="fill"
225
- name="note"
226
- label={noteLabel}
227
- placeholder={notePlaceholder}
228
- minHeight={80}
229
- disabled={saving}
230
- value={values.note}
231
- onChange={(e) => onChangeValue('note', e.currentTarget.value)}
232
- />
233
-
234
- {errorText ? (
235
- <div className="ft_xs cl_err mt_xs">{errorText}</div>
236
- ) : null}
237
- </div>
238
-
239
- <div
240
- className="no_shrink h_right gap_sm bd_t_1 bd_t_bd"
241
- style={{
242
- paddingLeft: 12,
243
- paddingRight: 12,
244
- paddingTop: 8,
245
- paddingBottom: 8,
246
- }}
247
- >
248
- <Button
249
- preset="bg"
250
- size="sm"
251
- disabled={saving}
252
- text={cancelText}
253
- onClick={onCancel}
254
- />
255
-
256
- <Button
257
- preset="bg_secondary"
258
- size="sm"
259
- disabled={saveDisabled}
260
- text={saving && savingText ? savingText : saveText}
261
- onClick={onSubmit}
262
- />
263
- </div>
264
- </div>
265
- );
266
- });
@@ -1,342 +0,0 @@
1
- import { cn } from '@jsb188/app/utils/string.ts';
2
- import { Icon } from '@jsb188/react-web/svgs/Icon';
3
- import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
4
- import { memo } from 'react';
5
- import type { CalendarDayObj, CalendarSourceObj } from '../types/calendar.d.ts';
6
-
7
- /**
8
- * The calendar's left rail: which calendars are drawn, and a mini month for
9
- * jumping somewhere else.
10
- *
11
- * Stateless like the rest of /ui/. It holds no visibility map of its own — a
12
- * calendar's toggle reflects the `visible` flag it arrives with, so the
13
- * "absent means visible" rule stays in one place (isCalendarVisible in
14
- * calendar-state) instead of being re-decided here. That is what makes a
15
- * newly granted calendar show up without the viewer hunting for it: only an
16
- * explicit untick ever hides one.
17
- *
18
- * The mini month deliberately draws no events. It is a jump target, and a
19
- * month of dots at this size is noise that would also force the rail to load
20
- * a range nobody is looking at.
21
- */
22
-
23
- /**
24
- * One month for the rail's navigator, shaped exactly like the year view's
25
- * mini grids so the two read as the same control.
26
- */
27
-
28
- export interface CalendarRailMiniMonthObj {
29
- // Localized month and year, e.g. "July 2026"
30
- label: string;
31
- // Leading blanks before the 1st, so it lands under its own weekday
32
- leadingBlankCount: number;
33
- days: CalendarDayObj[];
34
- dayNumberLabels: string[];
35
- }
36
-
37
- export interface CalendarRailUIProps {
38
- open: boolean;
39
- // Every calendar the viewer can see, in display order
40
- calendars: CalendarSourceObj[];
41
- miniMonth?: CalendarRailMiniMonthObj | null;
42
- // Single-letter weekday initials for the mini grid's header
43
- weekdayInitials: string[];
44
- // The day the calendar is anchored on, marked in the mini grid
45
- selectedDateKey?: string | null;
46
- // Display strings. This package holds no copy of its own: the app owns
47
- // i18n, so every user-visible word is passed in.
48
- calendarsText: string;
49
- emptyText: string;
50
- expandText: string;
51
- collapseText: string;
52
- previousMonthText: string;
53
- nextMonthText: string;
54
- // Rendered at the bottom: subscribe, new calendar, whatever the page owns
55
- FooterComponent?: React.ReactNode;
56
- onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
57
- onSelectDay: (dateKey: string) => void;
58
- onStepMonth: (direction: 1 | -1) => void;
59
- // Omitted when the page collapses the rail from somewhere else, in which
60
- // case a closed rail takes no width at all
61
- onToggleOpen?: (nextOpen: boolean) => void;
62
- }
63
-
64
- /**
65
- * The rail's mini month grid.
66
- */
67
-
68
- const CalendarRailMiniMonthUI = memo(
69
- (p: {
70
- miniMonth: CalendarRailMiniMonthObj;
71
- weekdayInitials: string[];
72
- selectedDateKey?: string | null;
73
- previousMonthText: string;
74
- nextMonthText: string;
75
- onSelectDay: (dateKey: string) => void;
76
- onStepMonth: (direction: 1 | -1) => void;
77
- }) => {
78
- const {
79
- miniMonth,
80
- weekdayInitials,
81
- selectedDateKey,
82
- previousMonthText,
83
- nextMonthText,
84
- onSelectDay,
85
- onStepMonth,
86
- } = p;
87
-
88
- return (
89
- <div
90
- className="no_shrink"
91
- style={{
92
- paddingLeft: 12,
93
- paddingRight: 12,
94
- paddingTop: 8,
95
- paddingBottom: 8,
96
- }}
97
- >
98
- <div className="h_item gap_sm">
99
- <span className="f ellip ft_sm ft_bold cl_md">{miniMonth.label}</span>
100
-
101
- {/* No IconButton exists in the kit, so these are the documented raw
102
- pattern: a bare button wrapping an Icon */}
103
- <button
104
- type="button"
105
- className="no_shrink av_sm h_center"
106
- aria-label={previousMonthText}
107
- title={previousMonthText}
108
- onClick={() => onStepMonth(-1)}
109
- >
110
- <Icon name="arrow-left" />
111
- </button>
112
-
113
- <button
114
- type="button"
115
- className="no_shrink av_sm h_center"
116
- aria-label={nextMonthText}
117
- title={nextMonthText}
118
- onClick={() => onStepMonth(1)}
119
- >
120
- <Icon name="arrow-right" />
121
- </button>
122
- </div>
123
-
124
- <div
125
- style={{
126
- display: 'grid',
127
- gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
128
- }}
129
- >
130
- {weekdayInitials.map((initial, index) => (
131
- <div key={index} className="a_c ft_tn cl_lt">
132
- {initial}
133
- </div>
134
- ))}
135
-
136
- {Array.from(
137
- { length: miniMonth.leadingBlankCount },
138
- (_unused, index) => (
139
- <div key={`blank${index}`} />
140
- ),
141
- )}
142
-
143
- {miniMonth.days.map((day, index) => (
144
- <button
145
- key={day.dateKey}
146
- type="button"
147
- className={cn(
148
- 'a_c ft_tn r_xs',
149
- // Today is bold and the anchored day is filled, so the two
150
- // stay tellable apart when they are not the same day; a
151
- // day borrowed from the next month recedes rather than
152
- // disappearing
153
- day.isToday
154
- ? 'ft_bold'
155
- : day.isInPrimaryRange
156
- ? 'cl_md'
157
- : 'cl_lt',
158
- day.dateKey === selectedDateKey ? 'bg_active' : '',
159
- )}
160
- style={{ paddingTop: 2, paddingBottom: 2 }}
161
- onClick={() => onSelectDay(day.dateKey)}
162
- aria-current={
163
- day.dateKey === selectedDateKey ? 'date' : undefined
164
- }
165
- >
166
- {miniMonth.dayNumberLabels[index]}
167
- </button>
168
- ))}
169
- </div>
170
- </div>
171
- );
172
- },
173
- );
174
-
175
- /**
176
- * One calendar's row: its colour, its name, and whether it is drawn.
177
- */
178
-
179
- const CalendarRailSourceUI = memo(
180
- (p: {
181
- calendar: CalendarSourceObj;
182
- onToggleCalendar: (calendarId: string, nextVisible: boolean) => void;
183
- }) => {
184
- const { calendar, onToggleCalendar } = p;
185
-
186
- return (
187
- <label
188
- className="h_item gap_sm pointer unsel"
189
- style={{
190
- paddingLeft: 12,
191
- paddingRight: 12,
192
- paddingTop: 4,
193
- paddingBottom: 4,
194
- }}
195
- >
196
- {/* The swatch is DATA — it is the calendar's own colour — so it is an
197
- inline background rather than a class. A calendar with no colour
198
- set gets the neutral chip instead of a black dot. */}
199
- <span
200
- className={cn(
201
- 'no_shrink r_xs bd_1 bd_bd',
202
- calendar.color ? '' : 'bg_alt',
203
- )}
204
- style={{
205
- width: 10,
206
- height: 10,
207
- backgroundColor: calendar.color || undefined,
208
- }}
209
- />
210
-
211
- <span className="f ellip ft_sm" title={calendar.name}>
212
- {calendar.name}
213
- </span>
214
-
215
- {/* Visibility is a viewer's own concern, so even a calendar they
216
- cannot edit can be hidden */}
217
- <ToggleSwitch
218
- size="sm"
219
- className="no_shrink"
220
- checked={calendar.visible}
221
- onChange={(event) =>
222
- onToggleCalendar(calendar.id, event.currentTarget.checked)
223
- }
224
- />
225
- </label>
226
- );
227
- },
228
- );
229
-
230
- export const CalendarRailUI = memo((p: CalendarRailUIProps) => {
231
- const {
232
- open,
233
- calendars,
234
- miniMonth,
235
- weekdayInitials,
236
- selectedDateKey,
237
- calendarsText,
238
- emptyText,
239
- expandText,
240
- collapseText,
241
- previousMonthText,
242
- nextMonthText,
243
- FooterComponent,
244
- onToggleCalendar,
245
- onSelectDay,
246
- onStepMonth,
247
- onToggleOpen,
248
- } = p;
249
-
250
- if (!open) {
251
- // With no way to reopen it from here, a closed rail is simply gone; the
252
- // page's own control is what brings it back
253
- if (!onToggleOpen) {
254
- return null;
255
- }
256
-
257
- return (
258
- <div
259
- className="no_shrink v_stretch h_f bd_r_1 bd_r_bd bg"
260
- style={{ width: 36, paddingTop: 6 }}
261
- >
262
- <button
263
- type="button"
264
- className="av_sm h_center"
265
- aria-label={expandText}
266
- title={expandText}
267
- onClick={() => onToggleOpen(true)}
268
- >
269
- <Icon name="sidebar-expand" />
270
- </button>
271
- </div>
272
- );
273
- }
274
-
275
- return (
276
- <div
277
- className="no_shrink v_stretch h_f bd_r_1 bd_r_bd bg"
278
- style={{ width: 232 }}
279
- >
280
- {miniMonth ? (
281
- <CalendarRailMiniMonthUI
282
- miniMonth={miniMonth}
283
- weekdayInitials={weekdayInitials}
284
- selectedDateKey={selectedDateKey}
285
- previousMonthText={previousMonthText}
286
- nextMonthText={nextMonthText}
287
- onSelectDay={onSelectDay}
288
- onStepMonth={onStepMonth}
289
- />
290
- ) : null}
291
-
292
- <div
293
- className="no_shrink h_item gap_sm bd_t_1 bd_t_bd"
294
- style={{
295
- paddingLeft: 12,
296
- paddingRight: 6,
297
- paddingTop: 6,
298
- paddingBottom: 2,
299
- }}
300
- >
301
- <span className="f ellip ft_tn cl_lt">{calendarsText}</span>
302
-
303
- {onToggleOpen ? (
304
- <button
305
- type="button"
306
- className="no_shrink av_sm h_center"
307
- aria-label={collapseText}
308
- title={collapseText}
309
- onClick={() => onToggleOpen(false)}
310
- >
311
- <Icon name="sidebar-close" />
312
- </button>
313
- ) : null}
314
- </div>
315
-
316
- <div className="f h_0 app_scr auto_y">
317
- {calendars.length ? (
318
- calendars.map((calendar) => (
319
- <CalendarRailSourceUI
320
- key={calendar.id}
321
- calendar={calendar}
322
- onToggleCalendar={onToggleCalendar}
323
- />
324
- ))
325
- ) : (
326
- <div
327
- className="ft_tn cl_lt"
328
- style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 4 }}
329
- >
330
- {emptyText}
331
- </div>
332
- )}
333
- </div>
334
-
335
- {FooterComponent ? (
336
- <div className="no_shrink bd_t_1 bd_t_bd" style={{ padding: 8 }}>
337
- {FooterComponent}
338
- </div>
339
- ) : null}
340
- </div>
341
- );
342
- });