@super-calendar/solid 2.17.0 → 2.18.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 +42 -5
- package/dist/client/index.d.ts +56 -14
- package/dist/client/index.js +570 -296
- package/dist/server/index.d.ts +56 -14
- package/dist/server/index.js +1173 -831
- package/package.json +2 -2
- package/src/Agenda.tsx +17 -1
- package/src/Calendar.tsx +106 -29
- package/src/MonthView.tsx +160 -18
- package/src/TimeGrid.tsx +350 -155
- package/src/YearView.tsx +17 -1
package/src/MonthView.tsx
CHANGED
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
bandRounding,
|
|
4
4
|
buildMonthGrid,
|
|
5
5
|
buildMultiWeekGrid,
|
|
6
|
+
nowInTimeZone,
|
|
6
7
|
type CalendarEvent,
|
|
8
|
+
type CreateGhostArgs,
|
|
7
9
|
type CalendarLabels,
|
|
8
10
|
compareDayEvents,
|
|
9
11
|
type DateRange,
|
|
@@ -63,6 +65,7 @@ export type MonthViewSlot =
|
|
|
63
65
|
| "dayBadge"
|
|
64
66
|
| "rangeBand"
|
|
65
67
|
| "events"
|
|
68
|
+
| "createGhost"
|
|
66
69
|
| "chipButton"
|
|
67
70
|
| "chip"
|
|
68
71
|
| "more"
|
|
@@ -81,6 +84,10 @@ const CHIP_GAP = 2;
|
|
|
81
84
|
const CELL_PAD = 4;
|
|
82
85
|
// Opacity of an event chip while it is being dragged to another day.
|
|
83
86
|
const DRAGGED_CHIP_OPACITY = 0.4;
|
|
87
|
+
// How far a press travels before it becomes a drag. Until then the chips stay
|
|
88
|
+
// hit-testable, so a click still reaches the chip it pressed.
|
|
89
|
+
const DRAG_SLOP_PX = 4;
|
|
90
|
+
const TOUCH_DRAG_SLOP_PX = 8;
|
|
84
91
|
|
|
85
92
|
/** Props passed to a custom month event chip renderer. */
|
|
86
93
|
export interface SolidMonthEventArgs<T = unknown> {
|
|
@@ -115,6 +122,10 @@ type MonthDrag<T> = (
|
|
|
115
122
|
) & {
|
|
116
123
|
// The rows the drag began in, so a drag never commits into a different window.
|
|
117
124
|
windowKey: string;
|
|
125
|
+
// Set once the pointer travels past the drag slop (or a touch hold fires).
|
|
126
|
+
// Chips stop taking pointer input only then, so a plain click is not
|
|
127
|
+
// retargeted to the day cell beneath.
|
|
128
|
+
armed: boolean;
|
|
118
129
|
};
|
|
119
130
|
|
|
120
131
|
// A day as the shared rows render it. Month days carry `isCurrentMonth`;
|
|
@@ -188,6 +199,13 @@ export interface MonthViewProps<T = unknown>
|
|
|
188
199
|
showWeekdays?: boolean;
|
|
189
200
|
/** date-fns locale for the title and weekday labels. */
|
|
190
201
|
locale?: Locale;
|
|
202
|
+
/**
|
|
203
|
+
* The instant whose calendar day is highlighted as today. Defaults to the
|
|
204
|
+
* device clock, and is read in `timeZone` when one is set.
|
|
205
|
+
*/
|
|
206
|
+
now?: Date;
|
|
207
|
+
/** Highlight today as it is in this IANA time zone (default: the device's). */
|
|
208
|
+
timeZone?: string;
|
|
191
209
|
/** Theme overrides; falls back to the default light theme. */
|
|
192
210
|
theme?: Partial<SolidCalendarTheme>;
|
|
193
211
|
/** Fired when a selectable day is clicked. */
|
|
@@ -205,6 +223,12 @@ export interface MonthViewProps<T = unknown>
|
|
|
205
223
|
* carry `data-creating` for styling.
|
|
206
224
|
*/
|
|
207
225
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
226
|
+
/**
|
|
227
|
+
* Custom content for a drag-to-create preview, once per covered week row.
|
|
228
|
+
* Receives the full all-day range with an exclusive end. Requires onCreateEvent.
|
|
229
|
+
* Content is clipped, noninteractive, and hidden from assistive technology.
|
|
230
|
+
*/
|
|
231
|
+
renderCreateGhost?: Component<CreateGhostArgs>;
|
|
208
232
|
/**
|
|
209
233
|
* Reports the day span of a create sweep **as it happens**, as the ordered
|
|
210
234
|
* inclusive `[start, end]` days (both at midnight), so a selection highlight can
|
|
@@ -612,7 +636,12 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
612
636
|
// Calendar layout (date in the corner + event chips) is on whenever `events`
|
|
613
637
|
// is provided; otherwise the compact picker badge layout is used. Multi-week
|
|
614
638
|
// rows always use the calendar layout.
|
|
615
|
-
const
|
|
639
|
+
const createContentEnabled = createMemo(
|
|
640
|
+
() => props.onCreateEvent != null && props.renderCreateGhost != null,
|
|
641
|
+
);
|
|
642
|
+
const eventsMode = createMemo(
|
|
643
|
+
() => props.events !== undefined || multiWeek() || createContentEnabled(),
|
|
644
|
+
);
|
|
616
645
|
// The day cells form a roving tab stop (arrow keys + Enter) in the picker
|
|
617
646
|
// always, and in events mode only when the consumer opts in. Otherwise events
|
|
618
647
|
// mode tabs through the event chips alone.
|
|
@@ -704,6 +733,8 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
704
733
|
maxDate: props.maxDate,
|
|
705
734
|
isDateDisabled: props.isDateDisabled,
|
|
706
735
|
locale: props.locale,
|
|
736
|
+
// Read here, not memoized apart, so each rebuild sees the current day.
|
|
737
|
+
today: nowInTimeZone(props.now, props.timeZone),
|
|
707
738
|
};
|
|
708
739
|
const weeks = numberOfWeeks();
|
|
709
740
|
if (weeks === undefined) {
|
|
@@ -852,6 +883,15 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
852
883
|
// all-day span, or press an event chip and drop it on another day. Both are
|
|
853
884
|
// released on a window pointerup, so letting go anywhere still commits.
|
|
854
885
|
const [drag, setDrag] = createSignal<MonthDrag<T> | null>(null);
|
|
886
|
+
const createRange = createMemo(
|
|
887
|
+
() => {
|
|
888
|
+
const current = drag();
|
|
889
|
+
return createContentEnabled() && current?.kind === "create"
|
|
890
|
+
? monthCreateRange(new Date(current.anchor), new Date(current.hover))
|
|
891
|
+
: null;
|
|
892
|
+
},
|
|
893
|
+
{ equals: (a, b) => a === b || (!!a && !!b && +a.start === +b.start && +a.end === +b.end) },
|
|
894
|
+
);
|
|
855
895
|
const dragRef: ElementRef<MonthDrag<T> | null> = { current: null };
|
|
856
896
|
const applyDrag = (value: MonthDrag<T> | null) => {
|
|
857
897
|
dragRef.current = value;
|
|
@@ -868,8 +908,9 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
868
908
|
const suppressClickRef = {
|
|
869
909
|
current: false,
|
|
870
910
|
};
|
|
871
|
-
|
|
872
|
-
|
|
911
|
+
// Keyboard and assistive-technology clicks have detail 0 and never trail a drag.
|
|
912
|
+
const consumeSuppressedClick = (detail: number) => {
|
|
913
|
+
if (detail === 0 || !suppressClickRef.current) return false;
|
|
873
914
|
suppressClickRef.current = false;
|
|
874
915
|
return true;
|
|
875
916
|
};
|
|
@@ -880,15 +921,22 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
880
921
|
!event.disabled &&
|
|
881
922
|
event.draggable !== false &&
|
|
882
923
|
(event.startEditable ?? props.eventStartEditable);
|
|
924
|
+
// Where the current press began and how far it may travel before it drags.
|
|
925
|
+
let pressOrigin = { x: 0, y: 0, slop: DRAG_SLOP_PX };
|
|
883
926
|
// A fresh press starts a new interaction, so any guard left over from the
|
|
884
927
|
// previous one is stale.
|
|
885
928
|
const beginPress = (e: PointerEvent) => {
|
|
886
929
|
if (dragRef.current || e.isPrimary === false) return false;
|
|
887
930
|
suppressClickRef.current = false;
|
|
888
931
|
movedRef.current = false;
|
|
932
|
+
pressOrigin = {
|
|
933
|
+
x: e.clientX,
|
|
934
|
+
y: e.clientY,
|
|
935
|
+
slop: e.pointerType === "touch" ? TOUCH_DRAG_SLOP_PX : DRAG_SLOP_PX,
|
|
936
|
+
};
|
|
889
937
|
return true;
|
|
890
938
|
};
|
|
891
|
-
const beginCreate = (day: Date, pointerId: number) => {
|
|
939
|
+
const beginCreate = (day: Date, pointerId: number, armed: boolean) => {
|
|
892
940
|
if (!props.onCreateEvent && !props.onSelectDrag) return;
|
|
893
941
|
const t = startOfDay(day).getTime();
|
|
894
942
|
applyDrag({
|
|
@@ -897,9 +945,10 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
897
945
|
anchor: t,
|
|
898
946
|
hover: t,
|
|
899
947
|
windowKey: windowKey(),
|
|
948
|
+
armed,
|
|
900
949
|
});
|
|
901
950
|
};
|
|
902
|
-
const beginMove = (event: CalendarEvent<T>, day: Date, pointerId: number) => {
|
|
951
|
+
const beginMove = (event: CalendarEvent<T>, day: Date, pointerId: number, armed: boolean) => {
|
|
903
952
|
if (!canMove(event)) return;
|
|
904
953
|
const t = startOfDay(day).getTime();
|
|
905
954
|
applyDrag({
|
|
@@ -909,6 +958,7 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
909
958
|
from: t,
|
|
910
959
|
to: t,
|
|
911
960
|
windowKey: windowKey(),
|
|
961
|
+
armed,
|
|
912
962
|
});
|
|
913
963
|
props.onDragStart?.(event);
|
|
914
964
|
};
|
|
@@ -923,10 +973,12 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
923
973
|
? {
|
|
924
974
|
...current,
|
|
925
975
|
hover: t,
|
|
976
|
+
armed: true,
|
|
926
977
|
}
|
|
927
978
|
: {
|
|
928
979
|
...current,
|
|
929
980
|
to: t,
|
|
981
|
+
armed: true,
|
|
930
982
|
},
|
|
931
983
|
);
|
|
932
984
|
// A sweep reports its span live, so a selection can track the drag; a move
|
|
@@ -952,12 +1004,12 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
952
1004
|
moving?: CalendarEvent<T>,
|
|
953
1005
|
) => {
|
|
954
1006
|
if (event.button !== 0 || heldTouch || !beginPress(event)) return;
|
|
955
|
-
const start = () => {
|
|
956
|
-
if (moving) beginMove(moving, day, event.pointerId);
|
|
957
|
-
else beginCreate(day, event.pointerId);
|
|
1007
|
+
const start = (armed: boolean) => {
|
|
1008
|
+
if (moving) beginMove(moving, day, event.pointerId, armed);
|
|
1009
|
+
else beginCreate(day, event.pointerId, armed);
|
|
958
1010
|
};
|
|
959
1011
|
if (!multiWeek() || !event.pointerType || event.pointerType === "mouse") {
|
|
960
|
-
start();
|
|
1012
|
+
start(false);
|
|
961
1013
|
return;
|
|
962
1014
|
}
|
|
963
1015
|
heldOrigin = { day, event: moving };
|
|
@@ -969,7 +1021,8 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
969
1021
|
clientX: event.clientX,
|
|
970
1022
|
clientY: event.clientY,
|
|
971
1023
|
},
|
|
972
|
-
|
|
1024
|
+
// The hold itself is the deliberate gesture, so a held drag starts armed.
|
|
1025
|
+
() => start(true),
|
|
973
1026
|
(x, y) => {
|
|
974
1027
|
const element = gridRef.current?.ownerDocument
|
|
975
1028
|
.elementFromPoint(x, y)
|
|
@@ -1029,6 +1082,7 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1029
1082
|
},
|
|
1030
1083
|
);
|
|
1031
1084
|
const isDragging = createMemo(() => drag() !== null);
|
|
1085
|
+
const dragArmed = createMemo(() => drag()?.armed === true);
|
|
1032
1086
|
// Whether any month drag is wired up at all, so the cells only take over touch
|
|
1033
1087
|
// scrolling and pointer tracking when one of the handlers can actually fire.
|
|
1034
1088
|
const dragWired = createMemo(
|
|
@@ -1043,7 +1097,13 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1043
1097
|
const current = dragRef.current;
|
|
1044
1098
|
if (!current || current.pointerId !== e.pointerId) return;
|
|
1045
1099
|
applyDrag(null);
|
|
1046
|
-
if (!movedRef.current)
|
|
1100
|
+
if (!movedRef.current) {
|
|
1101
|
+
// An armed move that returns to its day is released over the day cell,
|
|
1102
|
+
// because the chip ignored pointer input mid drag. The click that
|
|
1103
|
+
// follows belongs to the abandoned drag, not to the day.
|
|
1104
|
+
if (current.kind === "move" && current.armed) suppressClickRef.current = true;
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1047
1107
|
suppressClickRef.current = true;
|
|
1048
1108
|
// Multi-week rows drop a drag whose window was replaced before release.
|
|
1049
1109
|
if (multiWeek() && current.windowKey !== windowKey()) return;
|
|
@@ -1064,17 +1124,36 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1064
1124
|
}
|
|
1065
1125
|
props.onDragEvent?.(current.event, next.start, next.end);
|
|
1066
1126
|
};
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1127
|
+
const clear = () => {
|
|
1128
|
+
heldTouch?.();
|
|
1069
1129
|
applyDrag(null);
|
|
1070
1130
|
movedRef.current = false;
|
|
1071
1131
|
suppressClickRef.current = true;
|
|
1072
1132
|
};
|
|
1133
|
+
const cancel = (event: PointerEvent) => {
|
|
1134
|
+
if (dragRef.current?.pointerId === event.pointerId) clear();
|
|
1135
|
+
};
|
|
1136
|
+
const arm = (event: PointerEvent) => {
|
|
1137
|
+
const current = dragRef.current;
|
|
1138
|
+
if (!current || current.armed || current.pointerId !== event.pointerId) return;
|
|
1139
|
+
const distance = Math.hypot(event.clientX - pressOrigin.x, event.clientY - pressOrigin.y);
|
|
1140
|
+
if (distance <= pressOrigin.slop) return;
|
|
1141
|
+
applyDrag({ ...current, armed: true });
|
|
1142
|
+
};
|
|
1143
|
+
const keyDown = (event: KeyboardEvent) => {
|
|
1144
|
+
if (event.key !== "Escape") return;
|
|
1145
|
+
event.preventDefault();
|
|
1146
|
+
clear();
|
|
1147
|
+
};
|
|
1148
|
+
window.addEventListener("pointermove", arm);
|
|
1073
1149
|
window.addEventListener("pointerup", finish);
|
|
1074
1150
|
window.addEventListener("pointercancel", cancel);
|
|
1151
|
+
window.addEventListener("keydown", keyDown);
|
|
1075
1152
|
return () => {
|
|
1153
|
+
window.removeEventListener("pointermove", arm);
|
|
1076
1154
|
window.removeEventListener("pointerup", finish);
|
|
1077
1155
|
window.removeEventListener("pointercancel", cancel);
|
|
1156
|
+
window.removeEventListener("keydown", keyDown);
|
|
1078
1157
|
};
|
|
1079
1158
|
}),
|
|
1080
1159
|
);
|
|
@@ -1249,6 +1328,29 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1249
1328
|
last,
|
|
1250
1329
|
};
|
|
1251
1330
|
});
|
|
1331
|
+
const draftColumns = createMemo(() => {
|
|
1332
|
+
const range = createRange();
|
|
1333
|
+
return range
|
|
1334
|
+
? week().days.flatMap((day, index) =>
|
|
1335
|
+
(!showAdjacentMonths() && isOutsidePeriod(day)) ||
|
|
1336
|
+
day.date < range.start ||
|
|
1337
|
+
day.date >= range.end
|
|
1338
|
+
? []
|
|
1339
|
+
: [index],
|
|
1340
|
+
)
|
|
1341
|
+
: [];
|
|
1342
|
+
});
|
|
1343
|
+
const draftTop = createMemo(
|
|
1344
|
+
() =>
|
|
1345
|
+
CELL_PAD +
|
|
1346
|
+
DATE_ROW +
|
|
1347
|
+
props.chipGap +
|
|
1348
|
+
Math.min(visibleLanes(), Math.max(0, props.maxVisibleEventCount - 1)) *
|
|
1349
|
+
(props.chipHeight + props.chipGap),
|
|
1350
|
+
);
|
|
1351
|
+
const draftHeight = createMemo(() =>
|
|
1352
|
+
Math.min(props.chipHeight, Math.max(0, eventRowHeight() - draftTop())),
|
|
1353
|
+
);
|
|
1252
1354
|
return (
|
|
1253
1355
|
<>
|
|
1254
1356
|
{(() => {
|
|
@@ -1494,8 +1596,8 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1494
1596
|
onClick={
|
|
1495
1597
|
day().isDisabled
|
|
1496
1598
|
? undefined
|
|
1497
|
-
: () => {
|
|
1498
|
-
if (consumeSuppressedClick()) return;
|
|
1599
|
+
: (e) => {
|
|
1600
|
+
if (consumeSuppressedClick(e.detail)) return;
|
|
1499
1601
|
props.onPressDay?.(day().date);
|
|
1500
1602
|
props.onPressCell?.(startOfDay(day().date));
|
|
1501
1603
|
}
|
|
@@ -1540,6 +1642,45 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1540
1642
|
start day's gridcell and reads with that day. Made
|
|
1541
1643
|
non-interactive mid drag so a sweep (or a move) reaches the
|
|
1542
1644
|
cells beneath. */}
|
|
1645
|
+
<Show
|
|
1646
|
+
when={
|
|
1647
|
+
props.renderCreateGhost &&
|
|
1648
|
+
createRange() &&
|
|
1649
|
+
draftColumns()[0] === dayCol &&
|
|
1650
|
+
draftHeight() > 0
|
|
1651
|
+
}
|
|
1652
|
+
>
|
|
1653
|
+
<div
|
|
1654
|
+
{...slot("createGhost", {
|
|
1655
|
+
base: {
|
|
1656
|
+
position: "absolute",
|
|
1657
|
+
left: 2,
|
|
1658
|
+
width: `calc(${(draftColumns().at(-1)! - dayCol + 1) * 100}% - 4px)`,
|
|
1659
|
+
top: draftTop(),
|
|
1660
|
+
height: draftHeight(),
|
|
1661
|
+
boxSizing: "border-box",
|
|
1662
|
+
pointerEvents: "none",
|
|
1663
|
+
overflow: "hidden",
|
|
1664
|
+
zIndex: 3,
|
|
1665
|
+
},
|
|
1666
|
+
themed: {
|
|
1667
|
+
background: theme().rangeBackground,
|
|
1668
|
+
border: `1px solid ${theme().selectedBackground}`,
|
|
1669
|
+
borderRadius: 4,
|
|
1670
|
+
fontSize: 12,
|
|
1671
|
+
color: theme().text,
|
|
1672
|
+
},
|
|
1673
|
+
})}
|
|
1674
|
+
inert
|
|
1675
|
+
aria-hidden="true"
|
|
1676
|
+
>
|
|
1677
|
+
<Dynamic
|
|
1678
|
+
component={props.renderCreateGhost!}
|
|
1679
|
+
start={createRange()!.start}
|
|
1680
|
+
end={createRange()!.end}
|
|
1681
|
+
/>
|
|
1682
|
+
</div>
|
|
1683
|
+
</Show>
|
|
1543
1684
|
{
|
|
1544
1685
|
<For
|
|
1545
1686
|
each={barSegs().filter((b) => b.startCol === dayCol)}
|
|
@@ -1552,7 +1693,8 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1552
1693
|
const isDragged = createMemo(() => {
|
|
1553
1694
|
const currentDrag = drag();
|
|
1554
1695
|
return (
|
|
1555
|
-
currentDrag?.
|
|
1696
|
+
currentDrag?.armed === true &&
|
|
1697
|
+
currentDrag.kind === "move" &&
|
|
1556
1698
|
currentDrag.event === b().seg.event
|
|
1557
1699
|
);
|
|
1558
1700
|
});
|
|
@@ -1571,7 +1713,7 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1571
1713
|
}
|
|
1572
1714
|
onClick={(e) => {
|
|
1573
1715
|
e.stopPropagation();
|
|
1574
|
-
if (consumeSuppressedClick()) return;
|
|
1716
|
+
if (consumeSuppressedClick(e.detail)) return;
|
|
1575
1717
|
props.onPressEvent?.(b().seg.event);
|
|
1576
1718
|
}}
|
|
1577
1719
|
{...barChipButton()}
|
|
@@ -1602,7 +1744,7 @@ export function DateRows<T = unknown>(incoming: DateRowsProps<T>): JSX.Element {
|
|
|
1602
1744
|
b().seg.lane *
|
|
1603
1745
|
(props.chipHeight + props.chipGap),
|
|
1604
1746
|
height: props.chipHeight,
|
|
1605
|
-
pointerEvents:
|
|
1747
|
+
pointerEvents: dragArmed() ? "none" : "auto",
|
|
1606
1748
|
// Fade the bar being carried, so the tinted drop
|
|
1607
1749
|
// target reads as where it is going.
|
|
1608
1750
|
opacity: isDragged()
|