@weekwise/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +227 -2
- package/dist/Calendar.d.ts +6 -0
- package/dist/Calendar.types.d.ts +118 -0
- package/dist/components/calendar-toolbar/CalendarToolbar.d.ts +3 -0
- package/dist/components/calendar-toolbar/index.d.ts +2 -0
- package/dist/components/date-navigator/DateNavigator.d.ts +7 -0
- package/dist/components/date-navigator/index.d.ts +2 -0
- package/dist/components/day-week-drawer/DayWeekDrawer.d.ts +9 -0
- package/dist/components/day-week-drawer/index.d.ts +2 -0
- package/dist/components/day-week-event/DayWeekEvent.d.ts +7 -0
- package/dist/components/day-week-event/DayWeekEventPreview.d.ts +11 -0
- package/dist/components/day-week-event/index.d.ts +3 -0
- package/dist/components/day-week-view/DayWeekView.d.ts +39 -0
- package/dist/components/day-week-view/HiddenEvents.d.ts +14 -0
- package/dist/components/day-week-view/index.d.ts +2 -0
- package/dist/components/day-week-view/useTimeColumnWidth.d.ts +9 -0
- package/dist/components/drag-overlay/DragOverlay.d.ts +9 -0
- package/dist/components/drag-overlay/index.d.ts +2 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/month-view/MonthView.d.ts +7 -0
- package/dist/components/month-view/MonthView.utils.d.ts +12 -0
- package/dist/components/month-view/MonthViewDay.d.ts +12 -0
- package/dist/components/month-view/MonthViewEvent.d.ts +30 -0
- package/dist/components/month-view/MonthViewEventPreview.d.ts +9 -0
- package/dist/components/month-view/MonthViewWeek.d.ts +20 -0
- package/dist/components/month-view/index.d.ts +2 -0
- package/dist/components/month-view/useMonthLanes.d.ts +7 -0
- package/dist/components/month-view/useMonthResize.d.ts +32 -0
- package/dist/components/nav-btn/NavBtn.d.ts +5 -0
- package/dist/components/nav-btn/index.d.ts +2 -0
- package/dist/components/pointer-popover/PointerPopover.d.ts +6 -0
- package/dist/components/pointer-popover/index.d.ts +2 -0
- package/dist/components/view-select/ViewSelect.d.ts +8 -0
- package/dist/components/view-select/index.d.ts +2 -0
- package/dist/contexts/CalendarContext.d.ts +7 -0
- package/dist/contexts/CalendarViewportContext.d.ts +11 -0
- package/dist/contexts/DayWeekViewContext.d.ts +7 -0
- package/dist/contexts/ThemeSourceContext.d.ts +4 -0
- package/dist/date-localization/DateLocalizationContext.d.ts +6 -0
- package/dist/date-localization/DateLocalizationProvider.d.ts +17 -0
- package/dist/date-localization/MessagesContext.d.ts +4 -0
- package/dist/date-localization/index.d.ts +6 -0
- package/dist/date-localization/useDateUtils.d.ts +8 -0
- package/dist/date-localization/useMessages.d.ts +2 -0
- package/dist/hooks/index.d.ts +15 -0
- package/dist/hooks/useAbsEventRect.d.ts +3 -0
- package/dist/hooks/useAutoScroller.d.ts +33 -0
- package/dist/hooks/useCalendarSize.d.ts +7 -0
- package/dist/hooks/useCalendarValue.d.ts +7 -0
- package/dist/hooks/useCanResizeEvent.d.ts +3 -0
- package/dist/hooks/useComputed.d.ts +2 -0
- package/dist/hooks/useControlled.d.ts +36 -0
- package/dist/hooks/useControlled.types.d.ts +16 -0
- package/dist/hooks/useControlled.utils.d.ts +7 -0
- package/dist/hooks/useCurrentRef.d.ts +3 -0
- package/dist/hooks/useEventCallback.d.ts +1 -0
- package/dist/hooks/useEventCallback.types.d.ts +8 -0
- package/dist/hooks/useEventCallback.utils.d.ts +2 -0
- package/dist/hooks/useEventResize.d.ts +46 -0
- package/dist/hooks/useGlobalListeners.d.ts +9 -0
- package/dist/hooks/useInterval.d.ts +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +7 -0
- package/dist/hooks/useMergedRefs.d.ts +3 -0
- package/dist/hooks/useMove.d.ts +5 -0
- package/dist/hooks/useMove.types.d.ts +56 -0
- package/dist/hooks/useMoveTransform.d.ts +72 -0
- package/dist/hooks/useMutationObserver.d.ts +5 -0
- package/dist/hooks/useNavigation.d.ts +6 -0
- package/dist/hooks/usePrevious.d.ts +2 -0
- package/dist/hooks/useRect.d.ts +2 -0
- package/dist/hooks/useRefWithInit.d.ts +13 -0
- package/dist/hooks/useResizeObserver.d.ts +5 -0
- package/dist/hooks/useScrollBarSize.d.ts +2 -0
- package/dist/hooks/useScrollBarSize.types.d.ts +6 -0
- package/dist/hooks/useScrollIntent.d.ts +14 -0
- package/dist/hooks/useScrollOffsets.d.ts +2 -0
- package/dist/hooks/useScrollOffsetsDelta.d.ts +3 -0
- package/dist/hooks/useScrollableAncestors.d.ts +1 -0
- package/dist/hooks/useScrollableAncestorsRects.d.ts +3 -0
- package/dist/hooks/useStateRef.d.ts +8 -0
- package/dist/hooks/useTimeInterval.d.ts +1 -0
- package/dist/hooks/useTimeOffset.d.ts +1 -0
- package/dist/hooks/useToday.d.ts +6 -0
- package/dist/icons/chevron.d.ts +2 -0
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2633 -0
- package/dist/index.js.map +1 -0
- package/dist/portal/Portal.d.ts +16 -0
- package/dist/portal/index.d.ts +2 -0
- package/dist/style.css +2 -0
- package/dist/utils/css.d.ts +3 -0
- package/dist/utils/mergeRefs.d.ts +2 -0
- package/package.json +89 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CalendarDate } from "@weekwise/core";
|
|
2
|
+
import type { RefObject } from "react";
|
|
3
|
+
import { type DateAdapter, type EventChangeInfo, type EventKey, type EventMap } from "@weekwise/core";
|
|
4
|
+
export type MonthResizeEdge = "start" | "end";
|
|
5
|
+
/** Driven by the `useMove` listeners of a bar's edge. */
|
|
6
|
+
export interface MonthResizeActions {
|
|
7
|
+
start: (key: EventKey, edge: MonthResizeEdge) => void;
|
|
8
|
+
move: (x: number, y: number) => void;
|
|
9
|
+
/** Applies the change; `false` drops it. */
|
|
10
|
+
end: (commit?: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
interface UseMonthResizeParams<TValue> {
|
|
13
|
+
/** Days of the month grid, in the order of the cells' `data-day-index`. */
|
|
14
|
+
days: CalendarDate[];
|
|
15
|
+
viewportRef: RefObject<HTMLElement | null>;
|
|
16
|
+
dateUtils: DateAdapter<CalendarDate>;
|
|
17
|
+
eventMap: EventMap<TValue, CalendarDate>;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
getIsDayDisabled?: (date: CalendarDate) => boolean;
|
|
20
|
+
onEventChange: (key: EventKey, date: CalendarDate, info: EventChangeInfo) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Stretches an event into other days by the left or right edge of its month-view bar.
|
|
24
|
+
* `eventMap` is the map to draw while it changes, with the event's new range.
|
|
25
|
+
*/
|
|
26
|
+
export default function useMonthResize<TValue>(params: UseMonthResizeParams<TValue>): {
|
|
27
|
+
/** Key of the event being resized, if any. */
|
|
28
|
+
resizingKey: EventKey | undefined;
|
|
29
|
+
actions: MonthResizeActions;
|
|
30
|
+
eventMap: EventMap<TValue, CalendarDate>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes } from "react";
|
|
2
|
+
export type NavBtnProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
3
|
+
direction?: "forward" | "backward";
|
|
4
|
+
};
|
|
5
|
+
export default function NavBtn({ direction, type, onClick, className, children, ...props }: NavBtnProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
import type { Coordinates } from "@weekwise/core";
|
|
3
|
+
export type PointerPopoverProps = HTMLAttributes<HTMLSpanElement> & {
|
|
4
|
+
coordinates?: Coordinates;
|
|
5
|
+
};
|
|
6
|
+
export default function PointerPopover({ coordinates, className, style, ...props }: PointerPopoverProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ViewSelectProps = {
|
|
2
|
+
className?: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* The view (day, week, month) as one button with a list: the view tabs of a calendar too
|
|
6
|
+
* narrow for them.
|
|
7
|
+
*/
|
|
8
|
+
export default function ViewSelect({ className }: ViewSelectProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CalendarContextValue } from "../Calendar.types";
|
|
2
|
+
/**
|
|
3
|
+
* DatePicker context.
|
|
4
|
+
*/
|
|
5
|
+
declare const CalendarContext: import("react").Context<CalendarContextValue | undefined>;
|
|
6
|
+
export default CalendarContext;
|
|
7
|
+
export declare function useCalendarContext(): CalendarContextValue;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Provides the calendar viewport element used to portal
|
|
4
|
+
* drag overlays and position absolute transforms relative to.
|
|
5
|
+
*/
|
|
6
|
+
export type CalendarViewportContextValue = {
|
|
7
|
+
viewportRef: RefObject<HTMLDivElement | null>;
|
|
8
|
+
};
|
|
9
|
+
declare const CalendarViewportContext: import("react").Context<CalendarViewportContextValue | undefined>;
|
|
10
|
+
export default CalendarViewportContext;
|
|
11
|
+
export declare function useCalendarViewportContext(): CalendarViewportContextValue;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DayWeekViewContextValue } from "../Calendar.types";
|
|
2
|
+
/**
|
|
3
|
+
* DropTarget context.
|
|
4
|
+
*/
|
|
5
|
+
declare const DayWeekViewContext: import("react").Context<DayWeekViewContextValue | undefined>;
|
|
6
|
+
export default DayWeekViewContext;
|
|
7
|
+
export declare function useDayWeekViewContext(): DayWeekViewContextValue;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CalendarDate, DateAdapter } from "@weekwise/core";
|
|
2
|
+
/**
|
|
3
|
+
* DateLocalization context: the adapter, whatever its date type (read it with `useDateUtils<TDate>()`).
|
|
4
|
+
*/
|
|
5
|
+
declare const DateLocalizationContext: import("react").Context<DateAdapter<CalendarDate> | undefined>;
|
|
6
|
+
export default DateLocalizationContext;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PropsWithChildren } from "react";
|
|
2
|
+
import type { CalendarMessages, DateAdapter } from "@weekwise/core";
|
|
3
|
+
export type DateLocalizationProviderProps<TDate = Date> = PropsWithChildren<{
|
|
4
|
+
/**
|
|
5
|
+
* Date adapter: an instance (`new DateFnsAdapter({ locale: ru })`) or a class
|
|
6
|
+
* with a no-argument constructor (`DateFnsAdapter`). Its `locale` also selects
|
|
7
|
+
* the interface language, so switching the adapter switches the whole calendar.
|
|
8
|
+
* Its date type (`Date`, `Temporal.ZonedDateTime`…) is the one the calendar takes and gives.
|
|
9
|
+
*/
|
|
10
|
+
adapter: DateAdapter<TDate> | (new () => DateAdapter<TDate>);
|
|
11
|
+
/**
|
|
12
|
+
* Interface strings on top of the built-in translation for the adapter's locale:
|
|
13
|
+
* a few words to change, or every string for a language without a translation.
|
|
14
|
+
*/
|
|
15
|
+
messages?: Partial<CalendarMessages>;
|
|
16
|
+
}>;
|
|
17
|
+
export default function DateLocalizationProvider<TDate = Date>(props: DateLocalizationProviderProps<TDate>): import("react").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CalendarMessages } from "@weekwise/core";
|
|
2
|
+
/** Interface strings, resolved by {@link DateLocalizationProvider} from the adapter's locale. */
|
|
3
|
+
declare const MessagesContext: import("react").Context<CalendarMessages | undefined>;
|
|
4
|
+
export default MessagesContext;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as DateLocalizationContext } from "./DateLocalizationContext";
|
|
2
|
+
export { default as useDateUtils, useCalendarDateUtils } from "./useDateUtils";
|
|
3
|
+
export { default as DateLocalizationProvider } from "./DateLocalizationProvider";
|
|
4
|
+
export { default as MessagesContext } from "./MessagesContext";
|
|
5
|
+
export { default as useMessages } from "./useMessages";
|
|
6
|
+
export type { DateLocalizationProviderProps } from "./DateLocalizationProvider";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CalendarDate, DateAdapter } from "@weekwise/core";
|
|
2
|
+
/**
|
|
3
|
+
* The adapter given to `DateLocalizationProvider`. `TDate` is its date type: `Date` unless
|
|
4
|
+
* the adapter works with another one, e.g. `useDateUtils<Temporal.ZonedDateTime>()`.
|
|
5
|
+
*/
|
|
6
|
+
export default function useDateUtils<TDate = Date>(): DateAdapter<TDate>;
|
|
7
|
+
/** The adapter for the calendar's own components, which never look inside a date. */
|
|
8
|
+
export declare function useCalendarDateUtils(): DateAdapter<CalendarDate>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { default as useCalendarSize } from "./useCalendarSize";
|
|
2
|
+
export { default as useComputed } from "./useComputed";
|
|
3
|
+
export { default as useControlled } from "./useControlled";
|
|
4
|
+
export { default as useCurrentRef } from "./useCurrentRef";
|
|
5
|
+
export { default as useEventCallback } from "./useEventCallback";
|
|
6
|
+
export { default as useGlobalListeners } from "./useGlobalListeners";
|
|
7
|
+
export { default as useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
|
|
8
|
+
export { default as useMergedRefs } from "./useMergedRefs";
|
|
9
|
+
export { default as useMove } from "./useMove";
|
|
10
|
+
export { default as usePrevious } from "./usePrevious";
|
|
11
|
+
export { default as useResizeObserver } from "./useResizeObserver";
|
|
12
|
+
export { useScrollBarSize } from "./useScrollBarSize";
|
|
13
|
+
export { default as useStateRef } from "./useStateRef";
|
|
14
|
+
export { default as useTimeInterval } from "./useTimeInterval";
|
|
15
|
+
export { default as useToday } from "./useToday";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { MeasuredEventData } from "../components/day-week-view";
|
|
3
|
+
export default function useAbsEventRect(rootRef: RefObject<HTMLDivElement | null>, relativeRect: MeasuredEventData["rect"]): import("@weekwise/core").LayoutRect | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ClientRect, Coordinates } from "@weekwise/core";
|
|
2
|
+
declare enum AutoScrollActivator {
|
|
3
|
+
Pointer = 0,
|
|
4
|
+
DraggableRect = 1
|
|
5
|
+
}
|
|
6
|
+
declare enum TraversalOrder {
|
|
7
|
+
TreeOrder = 0,
|
|
8
|
+
ReversedTreeOrder = 1
|
|
9
|
+
}
|
|
10
|
+
export declare function useAutoScroller(args: UseAutoScrollerParams): void;
|
|
11
|
+
interface UseAutoScrollerParams {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
pointerCoordinates: Coordinates | null;
|
|
14
|
+
delta: Coordinates;
|
|
15
|
+
acceleration?: number;
|
|
16
|
+
activator?: AutoScrollActivator;
|
|
17
|
+
canScroll?: CanScroll;
|
|
18
|
+
interval?: number;
|
|
19
|
+
activeNodeRect: ClientRect | null;
|
|
20
|
+
scrollableAncestors: Element[];
|
|
21
|
+
scrollableAncestorsRects: ClientRect[];
|
|
22
|
+
layoutShiftCompensation?: boolean | {
|
|
23
|
+
x: boolean;
|
|
24
|
+
y: boolean;
|
|
25
|
+
};
|
|
26
|
+
order?: TraversalOrder;
|
|
27
|
+
threshold?: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
type CanScroll = (element: Element) => boolean;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type CalendarSize } from "@weekwise/core";
|
|
3
|
+
/**
|
|
4
|
+
* Layout for the width of `ref`'s element, kept up to date as it is resized. `regular` on
|
|
5
|
+
* the server and until the element is measured.
|
|
6
|
+
*/
|
|
7
|
+
export default function useCalendarSize(ref: RefObject<HTMLElement | null>): CalendarSize;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CalendarView, UseCalendarValueParams } from "../Calendar.types";
|
|
2
|
+
export default function useCalendarValue<TDate>(params: UseCalendarValueParams<TDate>): {
|
|
3
|
+
view: CalendarView;
|
|
4
|
+
viewValue: TDate;
|
|
5
|
+
changeViewValue: (newValue: TDate, view: CalendarView) => void;
|
|
6
|
+
changeView: (view: CalendarView) => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from "react";
|
|
2
|
+
import type { UseControlledParams, UseControlledWithInitialParams } from "./useControlled.types";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a controlled state with an uncontrolled fallback.
|
|
5
|
+
*
|
|
6
|
+
* If `controlled` is defined, `useControlled` will return the controlled value and an
|
|
7
|
+
* identity function as the update function. If `controlled` is `undefined`, `useControlled`
|
|
8
|
+
* will return the `defaultValue` and a state update function.
|
|
9
|
+
*
|
|
10
|
+
* This hook is useful when you want to make a component that can be either controlled or
|
|
11
|
+
* uncontrolled, depending on whether the user provides a `value` or `defaultValue` prop.
|
|
12
|
+
*
|
|
13
|
+
* @param params - The parameters of the hook.
|
|
14
|
+
* @param params.controlled - The controlled value.
|
|
15
|
+
* @param params.default - The default value.
|
|
16
|
+
* @returns A tuple of the value and the update function.
|
|
17
|
+
*/
|
|
18
|
+
export default function useControlled<T>(params: UseControlledParams<T>): [T | undefined, Dispatch<SetStateAction<T | undefined>>, boolean];
|
|
19
|
+
/**
|
|
20
|
+
* Creates a controlled state with an uncontrolled fallback and an `initialState`.
|
|
21
|
+
*
|
|
22
|
+
* This hook is useful when you want to make a component that can be either controlled or
|
|
23
|
+
* uncontrolled, depending on whether the user provides a `value` or `defaultValue` prop. The
|
|
24
|
+
* `initialState` is used as the initial value of the state, if the component is uncontrolled.
|
|
25
|
+
*
|
|
26
|
+
* The third element of the returned tuple is a boolean indicating whether the component is
|
|
27
|
+
* controlled or uncontrolled.
|
|
28
|
+
*
|
|
29
|
+
* @param params - The parameters of the hook.
|
|
30
|
+
* @param params.controlled - The controlled value.
|
|
31
|
+
* @param params.default - The default value.
|
|
32
|
+
* @param params.initialState - The initial state.
|
|
33
|
+
* @returns A tuple of the value, the update function and a boolean indicating whether the
|
|
34
|
+
* component is controlled or uncontrolled.
|
|
35
|
+
*/
|
|
36
|
+
export default function useControlled<T>(params: UseControlledWithInitialParams<T>): [T, Dispatch<SetStateAction<T>>, boolean];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type UseControlledParams<T = unknown> = {
|
|
2
|
+
/**
|
|
3
|
+
* The controlled value.
|
|
4
|
+
*/
|
|
5
|
+
controlled?: T | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The default value when uncontrolled.
|
|
8
|
+
*/
|
|
9
|
+
default?: T | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type UseControlledWithInitialParams<T = unknown> = UseControlledParams<T> & {
|
|
12
|
+
/**
|
|
13
|
+
* The initial value when uncontrolled.
|
|
14
|
+
*/
|
|
15
|
+
initialState: T;
|
|
16
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper hook to handle previous comparison of controlled/uncontrolled
|
|
3
|
+
* Prints an error when isControlled value switches between subsequent renders
|
|
4
|
+
* @returns - whether the value is controlled
|
|
5
|
+
*/
|
|
6
|
+
export declare function useIsControlled<T>(controlledValue: T | undefined): controlledValue is T;
|
|
7
|
+
export declare function useAssert<T>(isControlled: boolean, controlledValue: T | undefined, defaultValue: T | undefined, defaultValueProp: T | undefined): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useEventCallback<T extends (...args: any[]) => any>(callback: T | undefined): T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Stable<T extends (...args: any[]) => any> = {
|
|
2
|
+
/** The next value for callback */
|
|
3
|
+
next: T | undefined;
|
|
4
|
+
/** The function to be called by trampoline. This must fail during the initial render phase. */
|
|
5
|
+
callback: T | undefined;
|
|
6
|
+
trampoline: T;
|
|
7
|
+
effect: () => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CalendarDate } from "@weekwise/core";
|
|
2
|
+
import type { RefObject } from "react";
|
|
3
|
+
import { type DateAdapter, type EventChangeInfo, type EventKey, type EventMap, type TimeBounds } from "@weekwise/core";
|
|
4
|
+
export type ResizeEdge = "top" | "bottom";
|
|
5
|
+
/** An event being resized: its range in wall-clock minutes from the first visible day. */
|
|
6
|
+
export interface ResizeState {
|
|
7
|
+
key: EventKey;
|
|
8
|
+
range: [number, number];
|
|
9
|
+
/** Pointer position, for the time preview. */
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
/** The pointer is where the edge cannot go; the last valid range stays. */
|
|
13
|
+
blocked: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface EventResizeActions {
|
|
16
|
+
start: (key: EventKey, edge: ResizeEdge, x: number, y: number) => void;
|
|
17
|
+
move: (x: number, y: number) => void;
|
|
18
|
+
end: () => void;
|
|
19
|
+
}
|
|
20
|
+
interface UseEventResizeParams {
|
|
21
|
+
days: CalendarDate[];
|
|
22
|
+
viewportRef: RefObject<HTMLElement | null>;
|
|
23
|
+
dateUtils: DateAdapter<CalendarDate>;
|
|
24
|
+
bounds: TimeBounds;
|
|
25
|
+
timeStep: number;
|
|
26
|
+
preventOutBoundsChanges: boolean;
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
getIsDayDisabled?: (date: CalendarDate) => boolean;
|
|
29
|
+
eventMap: EventMap<unknown, CalendarDate>;
|
|
30
|
+
onEventChange: (key: EventKey, date: CalendarDate, info: EventChangeInfo) => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resizes an event by its top or bottom edge, into other days too (like macOS Calendar):
|
|
34
|
+
* dragging the bottom edge into a later day ends the event there, the first day filling
|
|
35
|
+
* to midnight. The view draws the event from {@link ResizeState} while it changes.
|
|
36
|
+
*/
|
|
37
|
+
export default function useEventResize(params: UseEventResizeParams): {
|
|
38
|
+
state: ResizeState | null;
|
|
39
|
+
actions: EventResizeActions;
|
|
40
|
+
previewOf: (range: [number, number]) => {
|
|
41
|
+
date: CalendarDate;
|
|
42
|
+
top: number;
|
|
43
|
+
duration: number;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function useGlobalListeners(): GlobalListeners;
|
|
2
|
+
interface GlobalListeners {
|
|
3
|
+
addGlobalListener<K extends keyof DocumentEventMap>(el: EventTarget, type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
4
|
+
addGlobalListener(el: EventTarget, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
|
|
5
|
+
removeGlobalListener<K extends keyof DocumentEventMap>(el: EventTarget, type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
6
|
+
removeGlobalListener(el: EventTarget, type: string, listener: EventListener, options?: boolean | EventListenerOptions): void;
|
|
7
|
+
removeAllGlobalListeners(): void;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useInterval(): readonly [(listener: (...args: any[]) => any, duration: number) => void, () => void];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* `useLayoutEffect` that falls back to `useEffect` during server-side
|
|
4
|
+
* rendering to avoid the React SSR warning.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
7
|
+
export default useIsomorphicLayoutEffect;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type PointerType = "mouse" | "pen" | "touch" | "keyboard" | "virtual";
|
|
2
|
+
export interface EventBase {
|
|
3
|
+
/** Whether the shift keyboard modifier was held during the move event. */
|
|
4
|
+
shiftKey: boolean;
|
|
5
|
+
/** Whether the ctrl keyboard modifier was held during the move event. */
|
|
6
|
+
ctrlKey: boolean;
|
|
7
|
+
/** Whether the meta keyboard modifier was held during the move event. */
|
|
8
|
+
metaKey: boolean;
|
|
9
|
+
/** Whether the alt keyboard modifier was held during the move event. */
|
|
10
|
+
altKey: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PointerCoordinates {
|
|
13
|
+
clientX: number;
|
|
14
|
+
clientY: number;
|
|
15
|
+
}
|
|
16
|
+
export interface MoveData extends PointerCoordinates {
|
|
17
|
+
activePointId: number | null;
|
|
18
|
+
initialClientX: number;
|
|
19
|
+
initialClientY: number;
|
|
20
|
+
isDistanceReached: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface UseMoveParams {
|
|
23
|
+
/** The minimum distance in pixels that a move event should be considered. */
|
|
24
|
+
distance?: number;
|
|
25
|
+
/** Handler that is called when a move interaction starts. */
|
|
26
|
+
onMoveStart: (e: MoveStartEvent) => boolean | void;
|
|
27
|
+
/** Handler that is called when the element is moved. */
|
|
28
|
+
onMove: (e: MoveEvent) => void;
|
|
29
|
+
/** Handler that is called when a move interaction ends. */
|
|
30
|
+
onMoveEnd: (e: MoveEndEvent) => void;
|
|
31
|
+
}
|
|
32
|
+
interface BaseMoveEvent extends EventBase {
|
|
33
|
+
/** The pointer type that triggered the move event. */
|
|
34
|
+
pointerType: PointerType;
|
|
35
|
+
}
|
|
36
|
+
interface MoveStartEvent extends BaseMoveEvent, PointerCoordinates {
|
|
37
|
+
/** The type of move event being fired. */
|
|
38
|
+
type: "movestart";
|
|
39
|
+
}
|
|
40
|
+
interface MoveEvent extends BaseMoveEvent, PointerCoordinates {
|
|
41
|
+
/** The type of move event being fired. */
|
|
42
|
+
type: "move";
|
|
43
|
+
/** The amount moved in the X direction since the last event. */
|
|
44
|
+
deltaX: number;
|
|
45
|
+
/** The amount moved in the Y direction since the last event. */
|
|
46
|
+
deltaY: number;
|
|
47
|
+
/** The amount moved in the X direction since the initial event. */
|
|
48
|
+
initialDeltaX: number;
|
|
49
|
+
/** The amount moved in the Y direction since the initial event. */
|
|
50
|
+
initialDeltaY: number;
|
|
51
|
+
}
|
|
52
|
+
export interface MoveEndEvent extends BaseMoveEvent, PointerCoordinates {
|
|
53
|
+
/** The type of move event being fired. */
|
|
54
|
+
type: "moveend";
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type ClientRect, type Coordinates, type MoveTransform, type MoveTransformModifier } from "@weekwise/core";
|
|
2
|
+
export type { MoveTransform, MoveTransformModifier };
|
|
3
|
+
export default function useMoveTransform<Context = unknown>({ autoScrollEnabled, modifiers, activeNode, containerNode, }: UseMoveTranformParams<Context>): [
|
|
4
|
+
UseMoveTransformResult<Context>,
|
|
5
|
+
MoveActions<Context>,
|
|
6
|
+
{
|
|
7
|
+
pointerCoordinates: Coordinates;
|
|
8
|
+
scrollAdjustmentActiveNodeRect: ClientRect | null;
|
|
9
|
+
scrollAdjustmentContainerNodeRect: ClientRect | null;
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
interface UseMoveTranformParams<Context> {
|
|
13
|
+
modifiers?: MoveTransformModifier<Context>[];
|
|
14
|
+
activeNode?: ((context: Context | null) => HTMLElement | null) | HTMLElement | null;
|
|
15
|
+
containerNode?: ((context: Context | null) => HTMLElement | null) | HTMLElement | null;
|
|
16
|
+
autoScrollEnabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface MoveActions<Context = unknown> {
|
|
19
|
+
/**
|
|
20
|
+
* Starts the move transform
|
|
21
|
+
* @param newCoordinates The new coordinates
|
|
22
|
+
* @param context The context of execution
|
|
23
|
+
* @returns void
|
|
24
|
+
*/
|
|
25
|
+
start: (newCoordinates: Coordinates, context?: Context) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Moves the move transform
|
|
28
|
+
* @param newCoordinates The new coordinates
|
|
29
|
+
* @returns void
|
|
30
|
+
*/
|
|
31
|
+
move: (newCoordinates: Coordinates) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Stops the move transform
|
|
34
|
+
* @param newCoordinates The new coordinates
|
|
35
|
+
* @returns void
|
|
36
|
+
*/
|
|
37
|
+
stop: (newCoordinates: Coordinates) => void;
|
|
38
|
+
}
|
|
39
|
+
interface UseMoveTransformResult<Context = unknown> {
|
|
40
|
+
/**
|
|
41
|
+
* Whether the move transform is active
|
|
42
|
+
*/
|
|
43
|
+
isActive: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The current move transform
|
|
46
|
+
*/
|
|
47
|
+
transform: MoveTransform;
|
|
48
|
+
/**
|
|
49
|
+
* The context of the current move transform
|
|
50
|
+
*/
|
|
51
|
+
context: Context;
|
|
52
|
+
/**
|
|
53
|
+
* The current translate coordinates
|
|
54
|
+
*/
|
|
55
|
+
translate: Coordinates;
|
|
56
|
+
/**
|
|
57
|
+
* The initial translate coordinates
|
|
58
|
+
*/
|
|
59
|
+
initialTranslate: Coordinates;
|
|
60
|
+
/**
|
|
61
|
+
* The delta between previous translate coordinates
|
|
62
|
+
*/
|
|
63
|
+
delta: Coordinates;
|
|
64
|
+
/**
|
|
65
|
+
* The actions of the move transform
|
|
66
|
+
*/
|
|
67
|
+
activeNodeRect: ClientRect | null;
|
|
68
|
+
/**
|
|
69
|
+
* The actions of the move transform
|
|
70
|
+
*/
|
|
71
|
+
containerNodeRect: ClientRect | null;
|
|
72
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React.useRef() that is initialized with a function. Note that it accepts an optional
|
|
3
|
+
* initialization argument, so the initialization function doesn't need to be an inline closure.
|
|
4
|
+
*
|
|
5
|
+
* @usage
|
|
6
|
+
* const ref = useRefWithInit(sortColumns, columns)
|
|
7
|
+
*/
|
|
8
|
+
export default function useRefWithInit<T>(init: () => T): {
|
|
9
|
+
readonly current: T;
|
|
10
|
+
};
|
|
11
|
+
export default function useRefWithInit<T, U>(init: (arg: U) => T, initArg: U): {
|
|
12
|
+
readonly current: T;
|
|
13
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new ResizeObserver instance bound to the `onResize` callback.
|
|
3
|
+
* If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
|
|
4
|
+
*/
|
|
5
|
+
export default function useResizeObserver(cb: ResizeObserverCallback, disabled?: boolean): ResizeObserver | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Coordinates } from "@weekwise/core";
|
|
2
|
+
export declare enum ScrollDirection {
|
|
3
|
+
Forward = 1,
|
|
4
|
+
Backward = -1
|
|
5
|
+
}
|
|
6
|
+
interface ScrollIntent {
|
|
7
|
+
x: Record<ScrollDirection, boolean>;
|
|
8
|
+
y: Record<ScrollDirection, boolean>;
|
|
9
|
+
}
|
|
10
|
+
export default function useScrollIntent({ delta, disabled, }: {
|
|
11
|
+
delta: Coordinates;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
}): ScrollIntent;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScrollableAncestors(node: HTMLElement | null, limit?: number): Element[];
|