mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
fix: support npm major upgrades
Signed-off-by: hazre <[email protected]>
This commit is contained in:
1 parent
5a68c68ecd
commit
fcf98d45f3
37 files changed
+314
-101
No files matched your search
@@ -25,4 +25,5 @@ Fixes #
|
||||
|
||||
- [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
|
||||
- [ ] Fully AI generated (explain what all the generated code does in moderate detail).
|
||||
|
||||
<!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
|
||||
@@ -7,8 +7,8 @@ type ConfirmPasswordMatchProps = {
|
||||
children: (
|
||||
match: boolean,
|
||||
doMatch: () => void,
|
||||
passRef: RefObject<HTMLInputElement>,
|
||||
confPassRef: RefObject<HTMLInputElement>
|
||||
passRef: RefObject<HTMLInputElement | null>,
|
||||
confPassRef: RefObject<HTMLInputElement | null>
|
||||
) => ReactNode;
|
||||
};
|
||||
export function ConfirmPasswordMatch({ initialValue, children }: ConfirmPasswordMatchProps) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ComponentProps, CSSProperties, RefObject } from 'react';
|
||||
import type { ComponentProps, CSSProperties, RefObject } from "react";
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
@@ -6,17 +6,17 @@ import React, {
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Box } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import * as css from '$features/room/message/styles.css';
|
||||
import { useDismissOnBack } from '$utils/androidBack';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { getMobileSheetTiming, useMobileSheetAnimation } from './mobileSheetAnimation';
|
||||
import { MOBILE_SHEET_DURATION_MS, MOBILE_SHEET_EASING } from './mobileSheetAnimationConstants';
|
||||
import * as animationCss from './mobileSheetAnimation.css';
|
||||
} from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Box } from "folds";
|
||||
import FocusTrap from "focus-trap-react";
|
||||
import { useDrag } from "@use-gesture/react";
|
||||
import * as css from "$features/room/message/styles.css";
|
||||
import { useDismissOnBack } from "$utils/androidBack";
|
||||
import { stopPropagation } from "$utils/keyboard";
|
||||
import { getMobileSheetTiming, useMobileSheetAnimation } from "./mobileSheetAnimation";
|
||||
import { MOBILE_SHEET_DURATION_MS, MOBILE_SHEET_EASING } from "./mobileSheetAnimationConstants";
|
||||
import * as animationCss from "./mobileSheetAnimation.css";
|
||||
|
||||
interface MobileSwipeDownModalProps {
|
||||
children: () => React.ReactNode;
|
||||
@@ -30,7 +30,7 @@ interface MobileSwipeDownModalProps {
|
||||
keyboardAware?: boolean;
|
||||
}
|
||||
|
||||
type FocusTrapOptions = ComponentProps<typeof FocusTrap>['focusTrapOptions'];
|
||||
type FocusTrapOptions = ComponentProps<typeof FocusTrap>["focusTrapOptions"];
|
||||
|
||||
const MobileSheetCloseContext = createContext<(() => void) | null>(null);
|
||||
|
||||
@@ -42,8 +42,8 @@ const DISMISS_VELOCITY = 0.5;
|
||||
/** Keeps a fling that lands at the top of a list from turning into a sheet drag. */
|
||||
const DRAG_BLOCKED_COOLDOWN_MS = 200;
|
||||
|
||||
const HANDLE_ATTRIBUTE = 'data-mobile-sheet-handle';
|
||||
const NO_DRAG_ATTRIBUTE = 'data-mobile-sheet-no-drag';
|
||||
const HANDLE_ATTRIBUTE = "data-mobile-sheet-handle";
|
||||
const NO_DRAG_ATTRIBUTE = "data-mobile-sheet-no-drag";
|
||||
|
||||
function getKeyboardOverlap(): number {
|
||||
const viewport = window.visualViewport;
|
||||
@@ -57,7 +57,7 @@ function findScroller(from: HTMLElement | null, boundary: HTMLElement): HTMLElem
|
||||
while (element && element !== boundary) {
|
||||
const { overflowY } = window.getComputedStyle(element);
|
||||
if (
|
||||
(overflowY === 'auto' || overflowY === 'scroll') &&
|
||||
(overflowY === "auto" || overflowY === "scroll") &&
|
||||
element.scrollHeight > element.clientHeight
|
||||
) {
|
||||
return element;
|
||||
@@ -123,15 +123,15 @@ export function MobileSwipeDownModal({
|
||||
sheet.style.transition =
|
||||
animate && !shouldReduceMotion
|
||||
? `transform ${MOBILE_SHEET_DURATION_MS}ms ${MOBILE_SHEET_EASING}`
|
||||
: '';
|
||||
sheet.style.transform = y === 0 ? '' : `translate3d(0, ${y}px, 0)`;
|
||||
: "";
|
||||
sheet.style.transform = y === 0 ? "" : `translate3d(0, ${y}px, 0)`;
|
||||
// Once lifted above the keyboard the bottom inset is no longer a safe area.
|
||||
sheet.style.setProperty(
|
||||
'--mobile-sheet-safe-bottom',
|
||||
keyboardOffset.current > 0 ? '0px' : ''
|
||||
"--mobile-sheet-safe-bottom",
|
||||
keyboardOffset.current > 0 ? "0px" : "",
|
||||
);
|
||||
},
|
||||
[shouldReduceMotion]
|
||||
[shouldReduceMotion],
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
@@ -144,7 +144,7 @@ export function MobileSwipeDownModal({
|
||||
const next = Math.max(stableViewportHeight, window.innerHeight);
|
||||
if (next === stableViewportHeight) return;
|
||||
stableViewportHeight = next;
|
||||
sheetRef.current?.style.setProperty('--mobile-sheet-viewport', `${next}px`);
|
||||
sheetRef.current?.style.setProperty("--mobile-sheet-viewport", `${next}px`);
|
||||
};
|
||||
|
||||
// The two viewports shrink in separate stages. Mid-way the visual one alone
|
||||
@@ -157,7 +157,7 @@ export function MobileSwipeDownModal({
|
||||
if (closingRef.current) return;
|
||||
publishViewportHeight();
|
||||
const visible = window.visualViewport?.height ?? window.innerHeight;
|
||||
sheetRef.current?.style.setProperty('--mobile-sheet-visible', `${visible}px`);
|
||||
sheetRef.current?.style.setProperty("--mobile-sheet-visible", `${visible}px`);
|
||||
|
||||
const next = getKeyboardOverlap();
|
||||
if (next === keyboardOffset.current) return;
|
||||
@@ -181,19 +181,19 @@ export function MobileSwipeDownModal({
|
||||
const viewport = window.visualViewport;
|
||||
|
||||
applySettled();
|
||||
window.addEventListener('resize', handleViewportChange);
|
||||
window.addEventListener('scroll', handleViewportChange);
|
||||
window.addEventListener('orientationchange', handleOrientationChange);
|
||||
viewport?.addEventListener('resize', handleViewportChange);
|
||||
viewport?.addEventListener('scroll', handleViewportChange);
|
||||
window.addEventListener("resize", handleViewportChange);
|
||||
window.addEventListener("scroll", handleViewportChange);
|
||||
window.addEventListener("orientationchange", handleOrientationChange);
|
||||
viewport?.addEventListener("resize", handleViewportChange);
|
||||
viewport?.addEventListener("scroll", handleViewportChange);
|
||||
|
||||
return () => {
|
||||
window.clearTimeout(settleTimer);
|
||||
window.removeEventListener('resize', handleViewportChange);
|
||||
window.removeEventListener('scroll', handleViewportChange);
|
||||
window.removeEventListener('orientationchange', handleOrientationChange);
|
||||
viewport?.removeEventListener('resize', handleViewportChange);
|
||||
viewport?.removeEventListener('scroll', handleViewportChange);
|
||||
window.removeEventListener("resize", handleViewportChange);
|
||||
window.removeEventListener("scroll", handleViewportChange);
|
||||
window.removeEventListener("orientationchange", handleOrientationChange);
|
||||
viewport?.removeEventListener("resize", handleViewportChange);
|
||||
viewport?.removeEventListener("scroll", handleViewportChange);
|
||||
};
|
||||
}, [keyboardAware, applySheetOffset]);
|
||||
|
||||
@@ -209,16 +209,16 @@ export function MobileSwipeDownModal({
|
||||
}
|
||||
|
||||
container.getAnimations().forEach((animation) => animation.cancel());
|
||||
container.style.transition = '';
|
||||
container.style.transition = "";
|
||||
const startY = touchYDiff.current - keyboardOffset.current;
|
||||
const animation = container.animate(
|
||||
[{ transform: `translate3d(0, ${startY}px, 0)` }, { transform: 'translate3d(0, 100%, 0)' }],
|
||||
[{ transform: `translate3d(0, ${startY}px, 0)` }, { transform: "translate3d(0, 100%, 0)" }],
|
||||
{
|
||||
...getMobileSheetTiming(shouldReduceMotion),
|
||||
duration: shouldReduceMotion ? 0 : 140,
|
||||
}
|
||||
},
|
||||
);
|
||||
animation.addEventListener('finish', requestClose, { once: true });
|
||||
animation.addEventListener("finish", requestClose, { once: true });
|
||||
}, [requestClose, shouldReduceMotion]);
|
||||
|
||||
// Android back closes the overlay instead of navigating away.
|
||||
@@ -285,10 +285,10 @@ export function MobileSwipeDownModal({
|
||||
target: sheetRef,
|
||||
eventOptions: { passive: false },
|
||||
pointer: { capture: false, touch: true },
|
||||
axis: 'y',
|
||||
axis: "y",
|
||||
// MobileMenuItem owns tap activation for marked actions; the sheet owns drag arbitration.
|
||||
filterTaps: false,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// A sheet opened by a long press mounts under the finger, and releasing it
|
||||
@@ -296,7 +296,7 @@ export function MobileSwipeDownModal({
|
||||
// backdrop is a dismiss.
|
||||
const handleBackdropClick = (e: React.MouseEvent) => {
|
||||
const fromTouch =
|
||||
e.nativeEvent instanceof PointerEvent && e.nativeEvent.pointerType === 'touch';
|
||||
e.nativeEvent instanceof PointerEvent && e.nativeEvent.pointerType === "touch";
|
||||
if (fromTouch && !backdropTouchRef.current) return;
|
||||
closeWithAnimation();
|
||||
};
|
||||
@@ -306,7 +306,7 @@ export function MobileSwipeDownModal({
|
||||
className={css.MessageMobileDragHandle}
|
||||
data-gestures="ignore"
|
||||
data-testid="mobile-sheet-drag-handle"
|
||||
{...{ [HANDLE_ATTRIBUTE]: '' }}
|
||||
{...{ [HANDLE_ATTRIBUTE]: "" }}
|
||||
>
|
||||
<div className={css.MessageMobileDragIndicator} />
|
||||
</div>
|
||||
@@ -356,10 +356,10 @@ export function MobileSwipeDownModal({
|
||||
return createPortal(
|
||||
<Box
|
||||
className={`${css.MessageMobileOptionsWrapped} ${
|
||||
portalRef ? css.MessageMobileOptionsWrappedContained : ''
|
||||
portalRef ? css.MessageMobileOptionsWrappedContained : ""
|
||||
}`}
|
||||
data-gestures="ignore"
|
||||
style={closing ? { opacity: 0, transition: 'opacity 100ms ease-out' } : undefined}
|
||||
style={closing ? { opacity: 0, transition: "opacity 100ms ease-out" } : undefined}
|
||||
onClick={handleBackdropClick}
|
||||
// Touch events deliberately propagate: the drag binds them on `document`, and
|
||||
// stopping them here would starve it. `data-gestures="ignore"` is what keeps the
|
||||
@@ -373,10 +373,10 @@ export function MobileSwipeDownModal({
|
||||
>
|
||||
<Box
|
||||
ref={sheetRef}
|
||||
className={`${css.MessageMobileOptionsContainer} ${sheetClassName ?? ''} ${
|
||||
portalRef ? css.MessageMobileOptionsContainerContained : ''
|
||||
className={`${css.MessageMobileOptionsContainer} ${sheetClassName ?? ""} ${
|
||||
portalRef ? css.MessageMobileOptionsContainerContained : ""
|
||||
} ${animationCss.SheetEntrance}`}
|
||||
style={{ ...(shouldReduceMotion ? { animation: 'none' } : undefined), ...sheetStyle }}
|
||||
style={{ ...(shouldReduceMotion ? { animation: "none" } : undefined), ...sheetStyle }}
|
||||
onPointerDown={(e: React.PointerEvent) => e.stopPropagation()}
|
||||
onPointerMove={(e: React.PointerEvent) => e.stopPropagation()}
|
||||
onPointerUp={(e: React.PointerEvent) => e.stopPropagation()}
|
||||
@@ -386,6 +386,6 @@ export function MobileSwipeDownModal({
|
||||
<div className={css.MessageMobileSheetFill}>{dialog}</div>
|
||||
</Box>
|
||||
</Box>,
|
||||
target
|
||||
target,
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CSSProperties } from 'react';
|
||||
import type { CSSProperties, JSX } from 'react';
|
||||
import { memo, useMemo, useCallback } from 'react';
|
||||
import type { IPreviewUrlResponse, MatrixClient, MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ComponentType, ReactNode } from 'react';
|
||||
import type { ComponentType, JSX, ReactNode } from 'react';
|
||||
import type { IconProps } from '@phosphor-icons/react';
|
||||
import { Box, config, IconButton, MenuItem, Text } from 'folds';
|
||||
import { PageNav, PageNavContent, PageNavHeader, PageRoot } from '$components/page';
|
||||
|
||||
@@ -34,13 +34,13 @@ function rgbToArgb(color: string): number | undefined {
|
||||
|
||||
// Color of the surface adjacent to a strip; on Android also tints the native system bar.
|
||||
function useBarColor(
|
||||
probeRef: RefObject<HTMLDivElement>,
|
||||
probeRef: RefObject<HTMLDivElement | null>,
|
||||
edge: 'top' | 'bottom',
|
||||
android: boolean,
|
||||
enabled: boolean
|
||||
): string | undefined {
|
||||
const [color, setColor] = useState<string>();
|
||||
const lastRef = useRef<string>();
|
||||
const lastRef = useRef<string | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return undefined;
|
||||
@@ -106,7 +106,7 @@ type SystemBarStripProps = {
|
||||
edge: 'top' | 'bottom';
|
||||
size: string;
|
||||
background: string;
|
||||
stripRef?: RefObject<HTMLDivElement>;
|
||||
stripRef?: RefObject<HTMLDivElement | null>;
|
||||
transition?: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
|
||||
]);
|
||||
const rootRef = useRef<HTMLDivElement | null>(null);
|
||||
const editableRef = useRef<HTMLDivElement>(null);
|
||||
const focusScrollTimerRef = useRef<number>();
|
||||
const focusScrollTimerRef = useRef<number | undefined>(undefined);
|
||||
const rowRef = useRef<HTMLDivElement>(null);
|
||||
const beforeRef = useRef<HTMLDivElement>(null);
|
||||
const afterRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
@@ -372,7 +372,7 @@ function StickerSidebar({
|
||||
}
|
||||
|
||||
type EmojiGroupHolderProps = {
|
||||
contentScrollRef: RefObject<HTMLDivElement>;
|
||||
contentScrollRef: RefObject<HTMLDivElement | null>;
|
||||
previewAtom: PrimitiveAtom<PreviewData | undefined>;
|
||||
children?: ReactNode;
|
||||
onGroupItemClick: MouseEventHandler;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { KeyboardEventHandler, MouseEventHandler } from 'react';
|
||||
import type { JSX, KeyboardEventHandler, MouseEventHandler } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import parse from 'html-react-parser';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Box, Chip, Text, as, color, toRem } from 'folds';
|
||||
import type { EventTimelineSet, IMentions, Room } from '$types/matrix-sdk';
|
||||
import { EventType, MsgType } from '$types/matrix-sdk';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import type { JSX, MouseEventHandler, ReactNode } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import classNames from 'classnames';
|
||||
|
||||
@@ -94,11 +94,11 @@ export function MobileNavDrawer({ nav, rail, bottomNav, children }: MobileNavDra
|
||||
const positionRef = useRef(0);
|
||||
|
||||
const [panelIntent, setPanelIntent] = useState(contentOpen ? 1 : 0);
|
||||
const gestureRef = useRef<ActiveTouchGesture>();
|
||||
const gestureRef = useRef<ActiveTouchGesture | undefined>(undefined);
|
||||
const messageTargetsRef = useRef(new WeakMap<HTMLElement, MobileSwipeTarget>());
|
||||
const chatTargetsRef = useRef(new WeakMap<HTMLElement, MobileSwipeTarget>());
|
||||
const settleAnimationRef = useRef<number>();
|
||||
const programmaticTargetRef = useRef<number>();
|
||||
const settleAnimationRef = useRef<number | undefined>(undefined);
|
||||
const programmaticTargetRef = useRef<number | undefined>(undefined);
|
||||
|
||||
const setTrackPosition = useCallback((position: number) => {
|
||||
positionRef.current = position;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { JSX } from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
@@ -142,7 +142,7 @@ function CallPrescreen() {
|
||||
}
|
||||
|
||||
type CallJoinedProps = {
|
||||
containerRef: RefObject<HTMLDivElement>;
|
||||
containerRef: RefObject<HTMLDivElement | null>;
|
||||
};
|
||||
|
||||
function CallJoined({ containerRef }: CallJoinedProps) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { sizedIcon, MagnifyingGlass, X } from '$components/icons/phosphor';
|
||||
type SearchProps = {
|
||||
active?: boolean;
|
||||
loading?: boolean;
|
||||
searchInputRef: RefObject<HTMLInputElement>;
|
||||
searchInputRef: RefObject<HTMLInputElement | null>;
|
||||
onSearch: (term: string) => void;
|
||||
onReset: () => void;
|
||||
};
|
||||
|
||||
@@ -282,7 +282,7 @@ const createUploadItemKey = () =>
|
||||
|
||||
interface RoomInputProps {
|
||||
editor: Editor;
|
||||
fileDropContainerRef: RefObject<HTMLElement>;
|
||||
fileDropContainerRef: RefObject<HTMLElement | null>;
|
||||
roomId: string;
|
||||
room: Room;
|
||||
threadRootId?: string;
|
||||
@@ -376,7 +376,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
roomUploadAtomFamily,
|
||||
selectedFiles.map((f) => f.file)
|
||||
);
|
||||
const uploadBoardHandlers = useRef<UploadBoardImperativeHandlers>();
|
||||
const uploadBoardHandlers = useRef<UploadBoardImperativeHandlers | undefined>(undefined);
|
||||
const longPressTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const isLongPress = useRef(false);
|
||||
const suppressBlurRefocusRef = useRef(false);
|
||||
@@ -603,8 +603,8 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
[room]
|
||||
);
|
||||
|
||||
const prevEditingEventId = useRef<string>();
|
||||
const preEditDraftRef = useRef<Editor['children']>();
|
||||
const prevEditingEventId = useRef<string | undefined>(undefined);
|
||||
const preEditDraftRef = useRef<Editor['children'] | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
if (!isMobileOrTablet()) {
|
||||
prevEditingEventId.current = undefined;
|
||||
@@ -2317,7 +2317,10 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
align="End"
|
||||
anchor={(() => {
|
||||
if (emojiBoardTab === undefined) return undefined;
|
||||
const buttonRefs: Record<EditorButtonId, RefObject<HTMLButtonElement>> = {
|
||||
const buttonRefs: Record<
|
||||
EditorButtonId,
|
||||
RefObject<HTMLButtonElement | null>
|
||||
> = {
|
||||
gif: gifBtnRef,
|
||||
sticker: stickerBtnRef,
|
||||
emoji: emojiBtnRef,
|
||||
|
||||
@@ -75,7 +75,7 @@ const shouldFocusMessageField = (evt: KeyboardEvent): boolean => {
|
||||
export function RoomView({ eventId }: { eventId?: string }) {
|
||||
const roomInputRef = useRef<HTMLDivElement>(null);
|
||||
const roomViewRef = useRef<HTMLDivElement>(null);
|
||||
const editLastMessageRef = useRef<(() => void) | undefined>();
|
||||
const editLastMessageRef = useRef<(() => void) | undefined>(undefined);
|
||||
|
||||
const [hideReads] = useSetting(settingsAtom, 'hideReads');
|
||||
const screenSize = useScreenSizeContext();
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import { createRef } from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { Message } from './Message';
|
||||
|
||||
/* oxlint-disable typescript/no-explicit-any */
|
||||
|
||||
vi.mock('$hooks/useMatrixClient', () => ({
|
||||
useMatrixClient: () =>
|
||||
({
|
||||
getUserId: () => '@me:example.com',
|
||||
mxcUrlToHttp: () => null,
|
||||
}) as any,
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useMediaAuthentication', () => ({
|
||||
useMediaAuthentication: () => false,
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useUserProfile', () => ({
|
||||
useUserProfile: () => ({}),
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useSableCosmetics', () => ({
|
||||
useSableCosmetics: () => ({ color: undefined, font: undefined }),
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useRoomMemberHydration', () => ({
|
||||
useRoomMemberHydration: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useRenderableMediaUrl', () => ({
|
||||
useRenderableMediaUrl: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useMentionClickHandler', () => ({
|
||||
useMentionClickHandler: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('$state/hooks/settings', () => ({
|
||||
useSetting: () => [false, vi.fn<() => void>()],
|
||||
}));
|
||||
|
||||
const createRoom = () =>
|
||||
({
|
||||
roomId: '!room:example.com',
|
||||
emit: () => {},
|
||||
getTimelineForEvent: () => undefined,
|
||||
getMember: () => undefined,
|
||||
}) as any;
|
||||
|
||||
const createMessageEvent = () =>
|
||||
({
|
||||
getContent: () => ({ msgtype: 'm.text', body: 'hello world' }),
|
||||
getClearContent: () => ({ msgtype: 'm.text', body: 'hello world' }),
|
||||
getId: () => '$evt:example.com',
|
||||
getTs: () => 1700000000000,
|
||||
getSender: () => '@alice:example.com',
|
||||
getType: () => 'm.room.message',
|
||||
sender: null,
|
||||
on: () => {},
|
||||
off: () => {},
|
||||
}) as any;
|
||||
|
||||
describe('Message forwarded ref', () => {
|
||||
it('exposes the inner message HTMLDivElement on mount and clears on unmount', () => {
|
||||
const ref = createRef<HTMLDivElement>();
|
||||
|
||||
const { container, unmount } = render(
|
||||
<Message
|
||||
ref={ref}
|
||||
room={createRoom()}
|
||||
mEvent={createMessageEvent()}
|
||||
collapse={false}
|
||||
highlight={false}
|
||||
messageSpacing="400"
|
||||
onUserClick={() => {}}
|
||||
onUsernameClick={() => {}}
|
||||
onReplyClick={() => {}}
|
||||
onReactionToggle={() => {}}
|
||||
hour24Clock
|
||||
dateFormatString="dd MMM yyyy"
|
||||
senderId="@alice:example.com"
|
||||
senderDisplayName="Alice"
|
||||
>
|
||||
hello world
|
||||
</Message>
|
||||
);
|
||||
|
||||
const messageDiv = container.querySelector('[tabindex="0"]');
|
||||
expect(messageDiv).not.toBeNull();
|
||||
expect(ref.current).toBeInstanceOf(HTMLDivElement);
|
||||
expect(ref.current).toBe(messageDiv);
|
||||
expect(ref.current).toHaveTextContent('hello world');
|
||||
|
||||
unmount();
|
||||
|
||||
expect(ref.current).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
config,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import type { KeyboardEventHandler, MouseEventHandler, MouseEvent, ReactNode } from 'react';
|
||||
import type { JSX, KeyboardEventHandler, MouseEventHandler, MouseEvent, ReactNode } from 'react';
|
||||
import {
|
||||
memo,
|
||||
useCallback,
|
||||
@@ -358,11 +358,7 @@ function MessageInternal(
|
||||
msc2723ForwardedMessageProps,
|
||||
...props
|
||||
}: MessageProps & { className?: string; children?: ReactNode },
|
||||
ref:
|
||||
| ((instance: HTMLDivElement | null) => void)
|
||||
| React.RefObject<HTMLDivElement>
|
||||
| null
|
||||
| undefined
|
||||
ref: React.Ref<HTMLDivElement> | undefined
|
||||
) {
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import type { ComponentType, ReactNode } from 'react';
|
||||
import type { ComponentType, JSX, ReactNode } from 'react';
|
||||
import { DesktopIcon, type IconProps } from '@phosphor-icons/react';
|
||||
import { Avatar, Box, Button, config, Text } from 'folds';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
|
||||
@@ -61,7 +61,7 @@ export function NotificationTransportRuntimeFeature() {
|
||||
const [useRichPushPayloads] = useSetting(settingsAtom, 'useRichPushPayloads');
|
||||
const [pushNotifyUrlOverride] = useSetting(settingsAtom, 'pushNotifyUrlOverride');
|
||||
|
||||
const runtimeRef = useRef<NotificationTransportRuntime>();
|
||||
const runtimeRef = useRef<NotificationTransportRuntime | undefined>(undefined);
|
||||
if (!runtimeRef.current) runtimeRef.current = new NotificationTransportRuntime();
|
||||
|
||||
// Read fresh by the listener for each incoming push, so toggling display
|
||||
|
||||
@@ -576,7 +576,7 @@ export function useProcessedTimeline({
|
||||
hiddenEventReactionRedactionTimeline,
|
||||
hiddenEventOther,
|
||||
} = hiddenEvents;
|
||||
const cacheRef = useRef<ProcessingCache>();
|
||||
const cacheRef = useRef<ProcessingCache | undefined>(undefined);
|
||||
|
||||
return useMemo(() => {
|
||||
const timelineEvents = flattenTimelineEvents(linkedTimelines);
|
||||
|
||||
@@ -28,9 +28,9 @@ export const useCallEmbed = (): CallEmbed | undefined => {
|
||||
return callEmbed;
|
||||
};
|
||||
|
||||
const CallEmbedRefContext = createContext<RefObject<HTMLDivElement> | undefined>(undefined);
|
||||
const CallEmbedRefContext = createContext<RefObject<HTMLDivElement | null> | undefined>(undefined);
|
||||
export const CallEmbedRefContextProvider = CallEmbedRefContext.Provider;
|
||||
const useCallEmbedRef = (): RefObject<HTMLDivElement> => {
|
||||
const useCallEmbedRef = (): RefObject<HTMLDivElement | null> => {
|
||||
const ref = useContext(CallEmbedRefContext);
|
||||
if (!ref) {
|
||||
throw new Error('CallEmbedRef is not provided!');
|
||||
@@ -152,7 +152,9 @@ export const useCallThemeSync = (embed: CallEmbed) => {
|
||||
}, [theme.kind, embed]);
|
||||
};
|
||||
|
||||
export const useCallEmbedPlacementSync = (containerViewRef: RefObject<HTMLDivElement>): void => {
|
||||
export const useCallEmbedPlacementSync = (
|
||||
containerViewRef: RefObject<HTMLDivElement | null>
|
||||
): void => {
|
||||
const callEmbedRef = useCallEmbedRef();
|
||||
|
||||
const syncCallEmbedPlacement = useCallback(() => {
|
||||
|
||||
@@ -10,7 +10,7 @@ export function useDebounce<T extends unknown[]>(
|
||||
callback: DebounceCallback<T>,
|
||||
options?: DebounceOptions
|
||||
): DebounceCallback<T> {
|
||||
const timeoutIdRef = useRef<number>();
|
||||
const timeoutIdRef = useRef<number | undefined>(undefined);
|
||||
const { wait, immediate } = options ?? {};
|
||||
|
||||
const debounceCallback = useCallback(
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { renderHook, act } from '@testing-library/react';
|
||||
import type { RefObject } from 'react';
|
||||
import { useFileDropZone } from './useFileDrop';
|
||||
|
||||
// jsdom has no DragEvent/DataTransfer constructors, so drag events are faked
|
||||
// with a plain Event carrying a minimal `dataTransfer` stand-in.
|
||||
type FakeDataTransfer = { types: string[] } | { files: File[] };
|
||||
|
||||
const fireDragEvent = (target: HTMLElement, type: string, dataTransfer?: FakeDataTransfer) => {
|
||||
const evt = new Event(type, { bubbles: true, cancelable: true });
|
||||
Object.defineProperty(evt, 'dataTransfer', { value: dataTransfer, configurable: true });
|
||||
act(() => {
|
||||
target.dispatchEvent(evt);
|
||||
});
|
||||
};
|
||||
|
||||
const setupZone = () => {
|
||||
const target = document.createElement('div');
|
||||
const zoneRef: RefObject<HTMLElement> = { current: target };
|
||||
return { target, zoneRef };
|
||||
};
|
||||
|
||||
describe('useFileDropZone', () => {
|
||||
it('ignores drags that do not contain files', () => {
|
||||
const { target, zoneRef } = setupZone();
|
||||
const onDrop = vi.fn<(files: File[]) => void>();
|
||||
const { result } = renderHook(() => useFileDropZone(zoneRef, onDrop));
|
||||
|
||||
fireDragEvent(target, 'dragenter', { types: ['text/plain', 'text/uri-list'] });
|
||||
fireDragEvent(target, 'dragover');
|
||||
fireDragEvent(target, 'dragleave');
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
expect(onDrop).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('activates on dragenter with files and only deactivates on dragleave after dragover', () => {
|
||||
const { target, zoneRef } = setupZone();
|
||||
const { result } = renderHook(() => useFileDropZone(zoneRef, vi.fn()));
|
||||
|
||||
fireDragEvent(target, 'dragenter', { types: ['Files'] });
|
||||
expect(result.current).toBe(true);
|
||||
|
||||
// start -> leave is not enough; a dragover must happen first.
|
||||
fireDragEvent(target, 'dragleave');
|
||||
expect(result.current).toBe(true);
|
||||
|
||||
fireDragEvent(target, 'dragover');
|
||||
expect(result.current).toBe(true);
|
||||
|
||||
fireDragEvent(target, 'dragleave');
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
it('invokes onDrop with the dropped files and deactivates the zone', () => {
|
||||
const { target, zoneRef } = setupZone();
|
||||
const onDrop = vi.fn<(files: File[]) => void>();
|
||||
const { result } = renderHook(() => useFileDropZone(zoneRef, onDrop));
|
||||
|
||||
fireDragEvent(target, 'dragenter', { types: ['Files'] });
|
||||
expect(result.current).toBe(true);
|
||||
|
||||
const fileA = new File(['a'], 'a.txt', { type: 'text/plain' });
|
||||
const fileB = new File(['b'], 'b.txt', { type: 'text/plain' });
|
||||
fireDragEvent(target, 'drop', { files: [fileA, fileB] });
|
||||
|
||||
expect(onDrop).toHaveBeenCalledTimes(1);
|
||||
expect(onDrop).toHaveBeenCalledWith([fileA, fileB]);
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
it('removes all drop-zone event listeners on unmount', () => {
|
||||
const { target, zoneRef } = setupZone();
|
||||
const addSpy = vi.spyOn(target, 'addEventListener');
|
||||
const removeSpy = vi.spyOn(target, 'removeEventListener');
|
||||
|
||||
const { unmount } = renderHook(() => useFileDropZone(zoneRef, vi.fn()));
|
||||
|
||||
const registered = new Map(addSpy.mock.calls.map(([type, listener]) => [type, listener]));
|
||||
expect([...registered.keys()].toSorted()).toEqual([
|
||||
'dragenter',
|
||||
'dragleave',
|
||||
'dragover',
|
||||
'drop',
|
||||
]);
|
||||
|
||||
unmount();
|
||||
|
||||
registered.forEach((listener, type) => {
|
||||
expect(removeSpy).toHaveBeenCalledWith(type, listener);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -3,10 +3,10 @@ import { useState, useEffect, useRef } from 'react';
|
||||
import { getDataTransferFiles } from '$utils/dom';
|
||||
|
||||
export const useFileDropZone = (
|
||||
zoneRef: RefObject<HTMLElement>,
|
||||
zoneRef: RefObject<HTMLElement | null>,
|
||||
onDrop: (file: File[]) => void
|
||||
): boolean => {
|
||||
const dragStateRef = useRef<'start' | 'leave' | 'over'>();
|
||||
const dragStateRef = useRef<'start' | 'leave' | 'over' | undefined>(undefined);
|
||||
const [active, setActive] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -104,7 +104,7 @@ export function useSettingsSyncEffect(): void {
|
||||
useAccountDataCallback(mx, onAccountData);
|
||||
|
||||
// Debounced upload whenever settings change
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout>>();
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
clearTimeout(timerRef.current);
|
||||
const generation = ++uploadGenerationRef.current;
|
||||
|
||||
@@ -11,8 +11,8 @@ export function useThrottle<T extends unknown[]>(
|
||||
callback: ThrottleCallback<T>,
|
||||
options?: ThrottleOptions
|
||||
): ThrottleCallback<T> {
|
||||
const timeoutIdRef = useRef<number>();
|
||||
const argsRef = useRef<T>();
|
||||
const timeoutIdRef = useRef<number | undefined>(undefined);
|
||||
const argsRef = useRef<T | undefined>(undefined);
|
||||
const { wait, immediate } = options ?? {};
|
||||
|
||||
const debounceCallback = useCallback(
|
||||
|
||||
@@ -11,7 +11,7 @@ export const useScrollActivity = (
|
||||
): { isScrolling: boolean; notifyScroll: () => void } => {
|
||||
const [isScrolling, setIsScrolling] = useState(false);
|
||||
const isScrollingRef = useRef(false);
|
||||
const idleTimerRef = useRef<ReturnType<typeof globalThis.setTimeout>>();
|
||||
const idleTimerRef = useRef<ReturnType<typeof globalThis.setTimeout> | undefined>(undefined);
|
||||
|
||||
const notifyScroll = useCallback(() => {
|
||||
if (!isScrollingRef.current) {
|
||||
|
||||
@@ -72,7 +72,7 @@ function renderSentryErrorFallback({ error, eventId }: { error: unknown; eventId
|
||||
function App() {
|
||||
const screenSize = useScreenSize();
|
||||
useCompositionEndTracking();
|
||||
const jotaiStoreRef = useRef<ReturnType<typeof createStore>>();
|
||||
const jotaiStoreRef = useRef<ReturnType<typeof createStore> | undefined>(undefined);
|
||||
if (!jotaiStoreRef.current) {
|
||||
jotaiStoreRef.current = createStore();
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ const FALLBACK_ROOMS_LIMIT = 24;
|
||||
type SearchProps = {
|
||||
active?: boolean;
|
||||
loading?: boolean;
|
||||
searchInputRef: RefObject<HTMLInputElement>;
|
||||
searchInputRef: RefObject<HTMLInputElement | null>;
|
||||
onSearch: (term: string) => void;
|
||||
onReset: () => void;
|
||||
};
|
||||
|
||||
@@ -392,7 +392,7 @@ function BookmarkResultGroup({
|
||||
type BookmarkFilterInputProps = {
|
||||
active?: boolean;
|
||||
loading?: boolean;
|
||||
searchInputRef: React.RefObject<HTMLInputElement>;
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>;
|
||||
onChange: ChangeEventHandler<HTMLInputElement>;
|
||||
};
|
||||
function BookmarkFilterInput({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { JSX } from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import parse from 'html-react-parser';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -95,7 +96,7 @@ describe('getReactCustomHtmlParser code blocks', () => {
|
||||
language: 'rust',
|
||||
allowDetect: false,
|
||||
}),
|
||||
expect.anything()
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
/* oxlint-disable jsx-a11y/alt-text */
|
||||
import type { CSSProperties, ComponentPropsWithoutRef, ReactEventHandler, ReactNode } from 'react';
|
||||
import type {
|
||||
CSSProperties,
|
||||
ComponentPropsWithoutRef,
|
||||
JSX,
|
||||
ReactEventHandler,
|
||||
ReactNode,
|
||||
} from 'react';
|
||||
import { Fragment, useEffect, useMemo, useState } from 'react';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { attributesToProps, domToReact, Element, Text as DOMText } from 'html-react-parser';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { renderHook, act } from '@testing-library/react';
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
import { createStore, Provider } from 'jotai';
|
||||
import { createElement, type ReactNode } from 'react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -76,12 +76,11 @@ describe('useDesktopSetting', () => {
|
||||
wrapper: makeWrapper(store),
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(store.get(desktopSettingsReadyAtom)).toBe(true);
|
||||
expect(result.current[0]).toBe(false);
|
||||
});
|
||||
|
||||
expect(result.current[0]).toBe(false);
|
||||
|
||||
await act(async () => {
|
||||
await result.current[1](true);
|
||||
});
|
||||
@@ -113,7 +112,7 @@ describe('useDesktopSetting', () => {
|
||||
wrapper: makeWrapper(store),
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
await waitFor(() => {
|
||||
expect(store.get(desktopSettingsReadyAtom)).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ export const orderKeys = (
|
||||
): Array<string> | undefined => {
|
||||
const newKeys: string[] = [];
|
||||
|
||||
for (let i = 0; i < keys.length; ) {
|
||||
for (let i = 0; i < keys.length;) {
|
||||
const key = keys[i];
|
||||
const collectedKeys: string[] = [];
|
||||
const [nextKeyIndex, nextKey] = findNextFilledKey(i + 1, keys);
|
||||
|
||||
@@ -7,3 +7,13 @@ class ResizeObserverPolyfill {
|
||||
}
|
||||
|
||||
globalThis.ResizeObserver = globalThis.ResizeObserver ?? ResizeObserverPolyfill;
|
||||
|
||||
class IntersectionObserverPolyfill {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
globalThis.IntersectionObserver =
|
||||
globalThis.IntersectionObserver ??
|
||||
(IntersectionObserverPolyfill as unknown as typeof IntersectionObserver);
|
||||
+2
-2
@@ -82,8 +82,8 @@ const copyFiles = {
|
||||
},
|
||||
{
|
||||
src: 'node_modules/pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
dest: '',
|
||||
rename: 'pdf.worker.min.js',
|
||||
dest: '.',
|
||||
rename: { name: 'pdf.worker.min.js', stripBase: true as const },
|
||||
},
|
||||
{
|
||||
src: 'config.json',
|
||||
|
||||
Reference in new issue
Block a user