mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 21:48:48 +08:00
0f5778ac89
fix #13663 #### PR Dependency Tree * **PR #14984** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Calendar view for database blocks (month layout, entry cards, external-source support) * Workspace calendar integration and new slash-menu "Calendar View" * **Improvements** * Create/manage database rows from calendar UI; preserve durations when moving/resizing ranges * Drag-and-drop, drop-preview, and hit-testing support for calendar and docs * Redesigned in-menu View settings with multi-page navigation * Context-menu input autofocus toggle and conditional back-navigation * **Tests** * New unit and E2E suites covering calendar layout, interactions, sources, and slash-menu integration <!-- end of auto-generated comment: release notes by coderabbit.ai -->
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
export const getCalendarDateFromPoint = (
|
|
root: HTMLElement,
|
|
clientX: number,
|
|
clientY: number
|
|
) => {
|
|
const doc = root.ownerDocument;
|
|
const hitStack = doc.elementsFromPoint(clientX, clientY);
|
|
|
|
for (const element of hitStack) {
|
|
const day = element.closest<HTMLElement>('.calendar-day[data-date]');
|
|
if (day && root.contains(day)) {
|
|
return Number(day.dataset['date']);
|
|
}
|
|
}
|
|
|
|
for (const element of hitStack) {
|
|
const week =
|
|
element.closest<HTMLElement>('.calendar-week') ??
|
|
element.closest<HTMLElement>('.calendar-segments')?.parentElement;
|
|
if (week && root.contains(week)) {
|
|
const days = week.querySelectorAll<HTMLElement>('.calendar-day');
|
|
for (const day of days) {
|
|
const rect = day.getBoundingClientRect();
|
|
if (
|
|
clientX >= rect.left &&
|
|
clientX < rect.right &&
|
|
clientY >= rect.top &&
|
|
clientY < rect.bottom &&
|
|
day.dataset['date']
|
|
) {
|
|
return Number(day.dataset['date']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
};
|