@super-calendar/dom 2.14.2 → 2.16.0
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/README.md +48 -0
- package/dist/index.d.mts +47 -26
- package/dist/index.d.ts +47 -26
- package/dist/index.js +1264 -452
- package/dist/index.mjs +1265 -453
- package/package.json +2 -2
- package/src/Calendar.tsx +13 -0
- package/src/DateRangePicker.tsx +60 -6
- package/src/EventActions.tsx +470 -0
- package/src/InertDiv.ts +7 -0
- package/src/MonthList.tsx +64 -38
- package/src/MonthView.tsx +14 -2
- package/src/ResourceTimeline.tsx +438 -98
- package/src/TimeGrid.tsx +305 -35
- package/src/index.ts +1 -0
package/src/InertDiv.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createElement, type HTMLAttributes } from "react";
|
|
2
|
+
|
|
3
|
+
export function InertDiv(props: HTMLAttributes<HTMLDivElement>) {
|
|
4
|
+
// React 18 needs a string; React 19 needs a nonempty value. The canonical
|
|
5
|
+
// attribute value works in both and applies before children can take focus.
|
|
6
|
+
return createElement("div", { ...props, inert: props.inert ? "inert" : undefined });
|
|
7
|
+
}
|
package/src/MonthList.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LegendList } from "@legendapp/list/react";
|
|
2
2
|
import { addMonths, type Locale, startOfMonth } from "date-fns";
|
|
3
|
-
import { type CSSProperties, type ReactElement, useMemo } from "react";
|
|
3
|
+
import { type CSSProperties, type ReactElement, useCallback, useMemo } from "react";
|
|
4
4
|
import {
|
|
5
5
|
buildMonthGrid,
|
|
6
6
|
type CalendarEvent,
|
|
@@ -154,10 +154,66 @@ export function MonthList<T = unknown>({
|
|
|
154
154
|
return map;
|
|
155
155
|
}, [events]);
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
const renderMonth = useCallback(
|
|
158
|
+
({ item }: { item: Date }) => (
|
|
159
|
+
<MonthView<T>
|
|
160
|
+
date={item}
|
|
161
|
+
weekStartsOn={weekStartsOn}
|
|
162
|
+
highlightWeekends={highlightWeekends}
|
|
163
|
+
events={events}
|
|
164
|
+
eventsByDay={eventsByDay}
|
|
165
|
+
renderEvent={renderEvent}
|
|
166
|
+
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
167
|
+
maxVisibleEventCount={maxVisibleEventCount}
|
|
168
|
+
chipHeight={chipHeight}
|
|
169
|
+
chipGap={chipGap}
|
|
170
|
+
moreLabel={moreLabel}
|
|
171
|
+
labels={labels}
|
|
172
|
+
onPressEvent={onPressEvent}
|
|
173
|
+
onPressMore={onPressMore}
|
|
174
|
+
selectedRange={selectedRange}
|
|
175
|
+
selectedDates={selectedDates}
|
|
176
|
+
fillCellOnSelection={fillCellOnSelection}
|
|
177
|
+
showAdjacentMonths={false}
|
|
178
|
+
showWeekdays={false}
|
|
179
|
+
locale={locale}
|
|
180
|
+
theme={themeOverrides}
|
|
181
|
+
minDate={minDate}
|
|
182
|
+
maxDate={maxDate}
|
|
183
|
+
isDateDisabled={isDateDisabled}
|
|
184
|
+
keyboardDayNavigation={keyboardDayNavigation}
|
|
185
|
+
onPressDay={onPressDay}
|
|
186
|
+
classNames={classNames}
|
|
187
|
+
styles={styles}
|
|
188
|
+
/>
|
|
189
|
+
),
|
|
190
|
+
[
|
|
191
|
+
weekStartsOn,
|
|
192
|
+
highlightWeekends,
|
|
193
|
+
events,
|
|
194
|
+
eventsByDay,
|
|
195
|
+
renderEvent,
|
|
196
|
+
eventAccessibilityLabel,
|
|
197
|
+
maxVisibleEventCount,
|
|
198
|
+
chipHeight,
|
|
199
|
+
chipGap,
|
|
200
|
+
moreLabel,
|
|
201
|
+
labels,
|
|
202
|
+
onPressEvent,
|
|
203
|
+
onPressMore,
|
|
204
|
+
selectedRange,
|
|
205
|
+
selectedDates,
|
|
206
|
+
fillCellOnSelection,
|
|
207
|
+
locale,
|
|
208
|
+
themeOverrides,
|
|
209
|
+
minDate,
|
|
210
|
+
maxDate,
|
|
211
|
+
isDateDisabled,
|
|
212
|
+
keyboardDayNavigation,
|
|
213
|
+
onPressDay,
|
|
214
|
+
classNames,
|
|
215
|
+
styles,
|
|
216
|
+
],
|
|
161
217
|
);
|
|
162
218
|
|
|
163
219
|
return (
|
|
@@ -189,7 +245,8 @@ export function MonthList<T = unknown>({
|
|
|
189
245
|
</div>
|
|
190
246
|
<LegendList
|
|
191
247
|
data={months}
|
|
192
|
-
|
|
248
|
+
// Legend List caches rows independently of renderItem's identity.
|
|
249
|
+
extraData={renderMonth}
|
|
193
250
|
keyExtractor={(m: Date) => m.toISOString()}
|
|
194
251
|
recycleItems={false}
|
|
195
252
|
estimatedItemSize={theme.cellHeight * 7 + 40}
|
|
@@ -197,38 +254,7 @@ export function MonthList<T = unknown>({
|
|
|
197
254
|
// `months` starts `pastMonths` before the anchor, so it sits at that index.
|
|
198
255
|
initialScrollIndex={pastMonths}
|
|
199
256
|
style={{ height, overflowY: "auto" }}
|
|
200
|
-
renderItem={
|
|
201
|
-
<MonthView<T>
|
|
202
|
-
date={item}
|
|
203
|
-
weekStartsOn={weekStartsOn}
|
|
204
|
-
highlightWeekends={highlightWeekends}
|
|
205
|
-
events={events}
|
|
206
|
-
eventsByDay={eventsByDay}
|
|
207
|
-
renderEvent={renderEvent}
|
|
208
|
-
eventAccessibilityLabel={eventAccessibilityLabel}
|
|
209
|
-
maxVisibleEventCount={maxVisibleEventCount}
|
|
210
|
-
chipHeight={chipHeight}
|
|
211
|
-
chipGap={chipGap}
|
|
212
|
-
moreLabel={moreLabel}
|
|
213
|
-
labels={labels}
|
|
214
|
-
onPressEvent={onPressEvent}
|
|
215
|
-
onPressMore={onPressMore}
|
|
216
|
-
selectedRange={selectedRange}
|
|
217
|
-
selectedDates={selectedDates}
|
|
218
|
-
fillCellOnSelection={fillCellOnSelection}
|
|
219
|
-
showAdjacentMonths={false}
|
|
220
|
-
showWeekdays={false}
|
|
221
|
-
locale={locale}
|
|
222
|
-
theme={themeOverrides}
|
|
223
|
-
minDate={minDate}
|
|
224
|
-
maxDate={maxDate}
|
|
225
|
-
isDateDisabled={isDateDisabled}
|
|
226
|
-
keyboardDayNavigation={keyboardDayNavigation}
|
|
227
|
-
onPressDay={onPressDay}
|
|
228
|
-
classNames={classNames}
|
|
229
|
-
styles={styles}
|
|
230
|
-
/>
|
|
231
|
-
)}
|
|
257
|
+
renderItem={renderMonth}
|
|
232
258
|
/>
|
|
233
259
|
</div>
|
|
234
260
|
);
|
package/src/MonthView.tsx
CHANGED
|
@@ -643,7 +643,13 @@ export function MonthView<T = unknown>({
|
|
|
643
643
|
const initialFocusRef = useRef(initialFocus);
|
|
644
644
|
initialFocusRef.current = initialFocus;
|
|
645
645
|
const monthKey = format(date, "yyyy-MM");
|
|
646
|
-
|
|
646
|
+
const focusedMonth = useRef(monthKey);
|
|
647
|
+
useEffect(() => {
|
|
648
|
+
// A parent can focus a day before the initial passive effect runs.
|
|
649
|
+
if (monthKey === focusedMonth.current) return;
|
|
650
|
+
focusedMonth.current = monthKey;
|
|
651
|
+
setFocusedDate(initialFocusRef.current);
|
|
652
|
+
}, [monthKey]);
|
|
647
653
|
|
|
648
654
|
const [hoveredKey, setHoveredKey] = useState<string | null>(null);
|
|
649
655
|
const gridRef = useRef<HTMLDivElement>(null);
|
|
@@ -917,6 +923,9 @@ export function MonthView<T = unknown>({
|
|
|
917
923
|
key={day.id}
|
|
918
924
|
role="gridcell"
|
|
919
925
|
data-day={day.id}
|
|
926
|
+
onFocus={(event) => {
|
|
927
|
+
if (event.target === event.currentTarget) setFocusedDate(day.date);
|
|
928
|
+
}}
|
|
920
929
|
{...dayData}
|
|
921
930
|
tabIndex={keyboardDayNavigation ? (day.id === focusKey ? 0 : -1) : undefined}
|
|
922
931
|
aria-disabled={day.isDisabled || undefined}
|
|
@@ -1187,11 +1196,14 @@ export function MonthView<T = unknown>({
|
|
|
1187
1196
|
type="button"
|
|
1188
1197
|
role="gridcell"
|
|
1189
1198
|
data-day={day.id}
|
|
1199
|
+
onFocus={(event) => {
|
|
1200
|
+
if (event.target === event.currentTarget) setFocusedDate(day.date);
|
|
1201
|
+
}}
|
|
1190
1202
|
{...dayData}
|
|
1191
1203
|
tabIndex={day.id === focusKey ? 0 : -1}
|
|
1192
1204
|
aria-disabled={day.isDisabled || undefined}
|
|
1193
1205
|
aria-label={label}
|
|
1194
|
-
aria-
|
|
1206
|
+
aria-selected={day.isSelected || day.isInRange}
|
|
1195
1207
|
{...slot("day", dayCellDefault(day, theme, highlightWeekends))}
|
|
1196
1208
|
onClick={
|
|
1197
1209
|
day.isDisabled
|