etudes 7.0.3 → 7.2.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.
@@ -17,6 +17,7 @@ export type VideoProps = Omit<HTMLAttributes<HTMLVideoElement>, 'autoPlay' | 'co
17
17
  onPause?: () => void;
18
18
  onPlay?: () => void;
19
19
  onSizeChange?: (size?: Size) => void;
20
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
20
21
  };
21
22
  export declare const Video: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLVideoElement>, "onCanPlay" | "onEnded" | "onPause" | "onPlay" | "autoPlay" | "controls" | "loop" | "muted" | "playsInline" | "poster"> & {
22
23
  autoLoop?: boolean;
@@ -35,4 +36,5 @@ export declare const Video: import("react").ForwardRefExoticComponent<Omit<HTMLA
35
36
  onPause?: () => void;
36
37
  onPlay?: () => void;
37
38
  onSizeChange?: (size?: Size) => void;
39
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
38
40
  } & import("react").RefAttributes<HTMLVideoElement>>;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useEffect, useRef } from 'react';
3
3
  import { useVideoSize } from '../hooks/useVideoSize.js';
4
- export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls = false, isMuted = true, playsInline = true, posterSrc, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, ...props }, ref) => {
4
+ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls = false, isMuted = true, playsInline = true, posterSrc, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, onTimeUpdate, ...props }, ref) => {
5
5
  const localRef = useRef(null);
6
6
  const videoRef = ref ?? localRef;
7
7
  const size = useVideoSize({
@@ -36,7 +36,8 @@ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls
36
36
  onFullscreenChange?.(isFullscreen);
37
37
  };
38
38
  const canPlayHandler = event => {
39
- if (autoPlay && (videoRef.current?.paused ?? false)) {
39
+ const el = event.currentTarget;
40
+ if (autoPlay && el.paused) {
40
41
  play();
41
42
  }
42
43
  onCanPlay?.();
@@ -50,6 +51,10 @@ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls
50
51
  const endHandler = event => {
51
52
  onEnd?.();
52
53
  };
54
+ const timeUpdateHandler = event => {
55
+ const el = event.currentTarget;
56
+ onTimeUpdate?.(el.currentTime, el.duration);
57
+ };
53
58
  const play = () => {
54
59
  if (!videoRef.current)
55
60
  return;
@@ -60,6 +65,6 @@ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls
60
65
  return;
61
66
  videoRef.current.pause();
62
67
  };
63
- return (_jsx("video", { ...props, ref: ref, autoPlay: autoPlay, controls: hasControls, loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, children: _jsx("source", { src: src }) }));
68
+ return (_jsx("video", { ...props, ref: ref, autoPlay: autoPlay, controls: hasControls, loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, onTimeUpdate: timeUpdateHandler, children: _jsx("source", { src: src }) }));
64
69
  });
65
70
  Object.defineProperty(Video, 'displayName', { value: 'Video', writable: false });
@@ -1,2 +1,4 @@
1
1
  import { type DependencyList, type RefObject } from 'react';
2
- export declare function useClickOutsideEffect(targetRef: RefObject<HTMLElement> | RefObject<HTMLElement | undefined> | RefObject<HTMLElement | null>, handler: () => void, deps?: DependencyList): void;
2
+ type TargetRef = RefObject<HTMLElement> | RefObject<HTMLElement | undefined> | RefObject<HTMLElement | null>;
3
+ export declare function useClickOutsideEffect(targetRef: TargetRef | TargetRef[], handler: () => void, deps?: DependencyList): void;
4
+ export {};
@@ -6,8 +6,10 @@ export function useClickOutsideEffect(targetRef, handler, deps = []) {
6
6
  return;
7
7
  let isOutside = true;
8
8
  let node = event.target;
9
+ const targetRefs = [].concat(targetRef);
10
+ const targetNodes = targetRefs.map(ref => ref.current);
9
11
  while (node) {
10
- if (node === targetRef.current) {
12
+ if (targetNodes.find(t => t === node)) {
11
13
  isOutside = false;
12
14
  break;
13
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "7.0.3",
3
+ "version": "7.2.0",
4
4
  "description": "A study of headless React components",
5
5
  "type": "module",
6
6
  "scripts": {