react-modern-audio-player 1.1.1 → 1.1.4

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/dist/index.es.js CHANGED
@@ -7920,7 +7920,7 @@ let $bf24a13e98395dd3$export$bca14c5b3b88a9c9 = {
7920
7920
  const useNonNullableContext = (context) => {
7921
7921
  const state = useContext(context);
7922
7922
  if (!state)
7923
- throw new Error(`Cannot find ${context}Provider`);
7923
+ throw new Error(`${context} is not provided or null`);
7924
7924
  return state;
7925
7925
  };
7926
7926
  const defaultInterfacePlacement = {
@@ -8122,7 +8122,7 @@ const audioPlayerReducer = (state, action) => {
8122
8122
  return {
8123
8123
  ...state,
8124
8124
  playList: action.playList,
8125
- curIdx: curPlayListItem.index
8125
+ curIdx: state.curIdx
8126
8126
  };
8127
8127
  }
8128
8128
  case "SET_VOLUME":
@@ -8156,7 +8156,7 @@ const audioPlayerReducer = (state, action) => {
8156
8156
  isPlaying: !state.curAudioState.isPlaying
8157
8157
  }
8158
8158
  };
8159
- case "SET_CURRENT_INDEX":
8159
+ case "SET_CURRENT_AUDIO":
8160
8160
  return {
8161
8161
  ...state,
8162
8162
  curPlayId: action.currentAudioId,
@@ -12645,6 +12645,12 @@ const useWaveSurfer = () => {
12645
12645
  const curTime = elementRefs.waveformInst.getCurrentTime();
12646
12646
  trackCurTimeEl.innerText = getTimeWithPadStart(curTime);
12647
12647
  }, [elementRefs]);
12648
+ const waveEl = document.getElementsByTagName("wave");
12649
+ useEffect(() => {
12650
+ if (waveEl.length > 1) {
12651
+ waveEl[0].setAttribute("style", "display: none");
12652
+ }
12653
+ }, [waveEl]);
12648
12654
  const [curAudioData, setCurAudioData] = useState();
12649
12655
  useEffect(() => {
12650
12656
  if (!(elementRefs == null ? void 0 : elementRefs.waveformInst) || !playList[curIdx])
@@ -12780,6 +12786,8 @@ const StyledBtn = styled.button`
12780
12786
  height: 100%;
12781
12787
  pointer-events: none;
12782
12788
  }
12789
+
12790
+ /** //TODO : animation on off */
12783
12791
  &:hover {
12784
12792
  transform: scale(1.1);
12785
12793
  }
@@ -12888,7 +12896,7 @@ const PlayBtn = () => {
12888
12896
  customIcons
12889
12897
  } = useNonNullableContext(audioPlayerStateContext);
12890
12898
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12891
- const onClick = () => audioPlayerDispatch({
12899
+ const changePlayState = () => audioPlayerDispatch({
12892
12900
  type: "SET_PlAY_STATE"
12893
12901
  });
12894
12902
  const PlayIcon = useMemo(() => {
@@ -12903,7 +12911,7 @@ const PlayBtn = () => {
12903
12911
  });
12904
12912
  }, [curAudioState.isPlaying, customIcons == null ? void 0 : customIcons.pause, customIcons == null ? void 0 : customIcons.play]);
12905
12913
  return /* @__PURE__ */ jsx(StyledPlayBtn, {
12906
- onClick,
12914
+ onClick: changePlayState,
12907
12915
  className: "play-button",
12908
12916
  children: PlayIcon
12909
12917
  });
@@ -12922,7 +12930,7 @@ const PrevNnextBtn = ({
12922
12930
  customIcons
12923
12931
  } = useNonNullableContext(audioPlayerStateContext);
12924
12932
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12925
- const onClickBtn = () => {
12933
+ const changeAudio = () => {
12926
12934
  if (type === "next") {
12927
12935
  audioPlayerDispatch({
12928
12936
  type: "NEXT_AUDIO"
@@ -12950,7 +12958,7 @@ const PrevNnextBtn = ({
12950
12958
  return null;
12951
12959
  }, [customIcons == null ? void 0 : customIcons.next, customIcons == null ? void 0 : customIcons.prev, type]);
12952
12960
  return visible ? /* @__PURE__ */ jsx(StyledBtn, {
12953
- onClick: onClickBtn,
12961
+ onClick: changeAudio,
12954
12962
  className: "prev-n-next-button",
12955
12963
  children: PrevNnextIcon
12956
12964
  }) : null;
@@ -12982,7 +12990,7 @@ const RepeatTypeBtn = () => {
12982
12990
  customIcons
12983
12991
  } = useNonNullableContext(audioPlayerStateContext);
12984
12992
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12985
- const onClick = useCallback(() => {
12993
+ const changeRepeatType = useCallback(() => {
12986
12994
  switch (curAudioState.repeatType) {
12987
12995
  case "ALL":
12988
12996
  audioPlayerDispatch({
@@ -13035,7 +13043,7 @@ const RepeatTypeBtn = () => {
13035
13043
  }
13036
13044
  }, [curAudioState.repeatType, customIcons == null ? void 0 : customIcons.repeatAll, customIcons == null ? void 0 : customIcons.repeatNone, customIcons == null ? void 0 : customIcons.repeatOne, customIcons == null ? void 0 : customIcons.repeatShuffle]);
13037
13045
  return /* @__PURE__ */ jsx(StyledBtn, {
13038
- onClick,
13046
+ onClick: changeRepeatType,
13039
13047
  className: "repeat-button",
13040
13048
  children: RepeatIcon
13041
13049
  });
@@ -13062,7 +13070,7 @@ const VolumeTriggerBtn = forwardRef((_, ref) => {
13062
13070
  customIcons
13063
13071
  } = useNonNullableContext(audioPlayerStateContext);
13064
13072
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
13065
- const onClickMuted = useCallback(() => audioPlayerDispatch({
13073
+ const changeMuteState = useCallback(() => audioPlayerDispatch({
13066
13074
  type: "SET_MUTED",
13067
13075
  muted: !curAudioState.muted
13068
13076
  }), [audioPlayerDispatch, curAudioState.muted]);
@@ -13112,7 +13120,7 @@ const VolumeTriggerBtn = forwardRef((_, ref) => {
13112
13120
  }
13113
13121
  }, [curAudioState.muted, curAudioState.volume, customIcons == null ? void 0 : customIcons.volumeMuted, customIcons == null ? void 0 : customIcons.volumeFull, customIcons == null ? void 0 : customIcons.volumeHalf]);
13114
13122
  return /* @__PURE__ */ jsx(StyledBtn, {
13115
- onClick: onClickMuted,
13123
+ onClick: changeMuteState,
13116
13124
  className: "volume-trigger-container",
13117
13125
  ref,
13118
13126
  children: VolumeIcon
@@ -13751,7 +13759,7 @@ const usePlayList = ({
13751
13759
  const [dragStartIdx, setDragStartIdx] = useState(0);
13752
13760
  const onClickItem = useCallback((index) => {
13753
13761
  audioPlayerDispatch({
13754
- type: "SET_CURRENT_INDEX",
13762
+ type: "SET_CURRENT_AUDIO",
13755
13763
  currentIndex: index,
13756
13764
  currentAudioId: playList[index].id
13757
13765
  });
@@ -13816,7 +13824,6 @@ const PlayList = ({
13816
13824
  }), document.querySelector(".sortable-play-list")) : /* @__PURE__ */ jsx(Fragment, {});
13817
13825
  };
13818
13826
  const PlayListContainer = styled.div`
13819
- height: 20vh;
13820
13827
  transition-property: max-height, opacity;
13821
13828
  overflow-x: hidden;
13822
13829
  overflow-y: auto;
@@ -14398,29 +14405,39 @@ const DropdownTrigger = ({
14398
14405
  };
14399
14406
  Dropdown.Content = DropdownContent;
14400
14407
  Dropdown.Trigger = DropdownTrigger;
14401
- const Volume = () => {
14402
- const triggerRef = useRef(null);
14403
- const {
14404
- activeUI: {
14405
- volumeSlider
14406
- }
14407
- } = useNonNullableContext(audioPlayerStateContext);
14408
- const [volumeSliderPlacement, setVolumeSliderPlacement] = useState("bottom");
14408
+ const useVolumeSliderPlacement = ({
14409
+ ref,
14410
+ initialState
14411
+ }) => {
14412
+ const [volumeSliderPlacement, setVolumeSliderPlacement] = useState(initialState);
14409
14413
  useEffect(() => {
14410
- if (triggerRef.current) {
14414
+ if (ref.current) {
14411
14415
  const placementValidation = () => {
14412
- if (triggerRef.current.getBoundingClientRect().top < window.innerHeight / 2) {
14416
+ if (ref.current.getBoundingClientRect().top < window.innerHeight / 2) {
14413
14417
  return "bottom";
14414
14418
  }
14415
14419
  return "top";
14416
14420
  };
14417
14421
  setVolumeSliderPlacement(placementValidation());
14418
14422
  }
14419
- }, [triggerRef.current]);
14423
+ }, [ref.current]);
14424
+ return volumeSliderPlacement;
14425
+ };
14426
+ const Volume = () => {
14427
+ const triggerRef = useRef(null);
14428
+ const {
14429
+ activeUI: {
14430
+ volumeSlider: volumeSliderEl
14431
+ }
14432
+ } = useNonNullableContext(audioPlayerStateContext);
14433
+ const volumeSliderPlacement = useVolumeSliderPlacement({
14434
+ ref: triggerRef,
14435
+ initialState: "bottom"
14436
+ });
14420
14437
  return /* @__PURE__ */ jsxs(Dropdown, {
14421
14438
  placement: volumeSliderPlacement,
14422
14439
  triggerType: "hover",
14423
- disabled: volumeSlider,
14440
+ disabled: !volumeSliderEl,
14424
14441
  children: [/* @__PURE__ */ jsx(Dropdown.Trigger, {
14425
14442
  children: /* @__PURE__ */ jsx(VolumeTriggerBtn, {
14426
14443
  ref: triggerRef
@@ -14541,18 +14558,10 @@ const TrackTimeCurrent = () => {
14541
14558
  const {
14542
14559
  activeUI
14543
14560
  } = useNonNullableContext(audioPlayerStateContext);
14544
- const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14545
- useEffect(() => {
14546
- if (trackCurTimeRef.current) {
14547
- const trackCurTimeEl = trackCurTimeRef.current;
14548
- audioPlayerDispatch({
14549
- type: "SET_ELEMENT_REFS",
14550
- elementRefs: {
14551
- trackCurTimeEl
14552
- }
14553
- });
14554
- }
14555
- }, [trackCurTimeRef.current, audioPlayerDispatch]);
14561
+ useTrackTimeRefDispatchEffect({
14562
+ ref: trackCurTimeRef,
14563
+ refName: "trackCurTimeEl"
14564
+ });
14556
14565
  return /* @__PURE__ */ jsx(TrackTimeCurrentContainer, {
14557
14566
  type: activeUI.trackTime,
14558
14567
  className: "track-time-current-container",
@@ -14568,18 +14577,10 @@ const TrackTimeDuration = () => {
14568
14577
  const {
14569
14578
  activeUI
14570
14579
  } = useNonNullableContext(audioPlayerStateContext);
14571
- const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14572
- useEffect(() => {
14573
- if (trackDurationRef.current) {
14574
- const trackDurationEl = trackDurationRef.current;
14575
- audioPlayerDispatch({
14576
- type: "SET_ELEMENT_REFS",
14577
- elementRefs: {
14578
- trackDurationEl
14579
- }
14580
- });
14581
- }
14582
- }, [trackDurationRef.current, audioPlayerDispatch]);
14580
+ useTrackTimeRefDispatchEffect({
14581
+ ref: trackDurationRef,
14582
+ refName: "trackDurationEl"
14583
+ });
14583
14584
  return /* @__PURE__ */ jsx(TrackTimeDurationContainer, {
14584
14585
  type: activeUI.trackTime,
14585
14586
  className: "track-time-duration-container",
@@ -14590,6 +14591,23 @@ const TrackTimeDuration = () => {
14590
14591
  })
14591
14592
  });
14592
14593
  };
14594
+ const useTrackTimeRefDispatchEffect = ({
14595
+ ref,
14596
+ refName
14597
+ }) => {
14598
+ const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14599
+ useEffect(() => {
14600
+ const trackTimeRef = ref.current;
14601
+ if (trackTimeRef) {
14602
+ audioPlayerDispatch({
14603
+ type: "SET_ELEMENT_REFS",
14604
+ elementRefs: {
14605
+ [refName]: trackTimeRef
14606
+ }
14607
+ });
14608
+ }
14609
+ }, [ref.current, audioPlayerDispatch, refName]);
14610
+ };
14593
14611
  const TrackTimeContainer = styled.div`
14594
14612
  display: flex;
14595
14613
  align-items: center;
@@ -14635,7 +14653,7 @@ const Information = () => {
14635
14653
  curIdx,
14636
14654
  activeUI
14637
14655
  } = useNonNullableContext(audioPlayerStateContext);
14638
- const trackInfoActive = Boolean((_e = (_c = (_a2 = playList[curIdx]) == null ? void 0 : _a2.customTrackInfo) != null ? _c : (_b = playList[curIdx]) == null ? void 0 : _b.writer) != null ? _e : (_d = playList[curIdx]) == null ? void 0 : _d.name) && Boolean((_f = activeUI.trackInfo) != null ? _f : activeUI.all);
14656
+ const isTrackInfoActive = Boolean((_e = (_c = (_a2 = playList[curIdx]) == null ? void 0 : _a2.customTrackInfo) != null ? _c : (_b = playList[curIdx]) == null ? void 0 : _b.writer) != null ? _e : (_d = playList[curIdx]) == null ? void 0 : _d.name) && Boolean((_f = activeUI.trackInfo) != null ? _f : activeUI.all);
14639
14657
  return /* @__PURE__ */ jsxs(Fragment, {
14640
14658
  children: [/* @__PURE__ */ jsx(Grid.Item, {
14641
14659
  gridArea: ((_g = interfacePlacement == null ? void 0 : interfacePlacement.itemCustomArea) == null ? void 0 : _g.artwork) || ((_h = interfacePlacement == null ? void 0 : interfacePlacement.templateArea) == null ? void 0 : _h.artwork) || defaultInterfacePlacement.templateArea.artwork,
@@ -14643,7 +14661,7 @@ const Information = () => {
14643
14661
  children: /* @__PURE__ */ jsx(Artwork, {})
14644
14662
  }), /* @__PURE__ */ jsx(Grid.Item, {
14645
14663
  gridArea: ((_k = interfacePlacement == null ? void 0 : interfacePlacement.itemCustomArea) == null ? void 0 : _k.trackInfo) || ((_l = interfacePlacement == null ? void 0 : interfacePlacement.templateArea) == null ? void 0 : _l.trackInfo) || defaultInterfacePlacement.templateArea.trackInfo,
14646
- visible: trackInfoActive,
14664
+ visible: isTrackInfoActive,
14647
14665
  children: /* @__PURE__ */ jsx(TrackInfo, {})
14648
14666
  }), /* @__PURE__ */ jsx(Grid.Item, {
14649
14667
  gridArea: ((_m = interfacePlacement == null ? void 0 : interfacePlacement.itemCustomArea) == null ? void 0 : _m.trackTimeCurrent) || ((_n = interfacePlacement == null ? void 0 : interfacePlacement.templateArea) == null ? void 0 : _n.trackTimeCurrent) || defaultInterfacePlacement.templateArea.trackTimeCurrent,
@@ -14759,13 +14777,13 @@ const Interface = () => {
14759
14777
  })]
14760
14778
  });
14761
14779
  };
14762
- const AudioPlayer = ({
14763
- playList,
14764
- audioInitialState,
14780
+ const usePropsStateEffect = ({
14765
14781
  placement = {},
14766
14782
  activeUI,
14767
- customIcons,
14768
- coverImgsCss
14783
+ coverImgsCss,
14784
+ audioInitialState,
14785
+ playList,
14786
+ customIcons
14769
14787
  }) => {
14770
14788
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14771
14789
  useLayoutEffect(() => {
@@ -14783,18 +14801,12 @@ const AudioPlayer = ({
14783
14801
  }, [audioPlayerDispatch, placement]);
14784
14802
  useLayoutEffect(() => {
14785
14803
  if (activeUI) {
14786
- audioPlayerDispatch({
14787
- type: "SET_ACTIVE_UI",
14788
- activeUI
14789
- });
14804
+ audioPlayerDispatch({ type: "SET_ACTIVE_UI", activeUI });
14790
14805
  }
14791
14806
  }, [activeUI, audioPlayerDispatch]);
14792
14807
  useLayoutEffect(() => {
14793
14808
  if (coverImgsCss) {
14794
- audioPlayerDispatch({
14795
- type: "SET_COVER_IMGS_CSS",
14796
- coverImgsCss
14797
- });
14809
+ audioPlayerDispatch({ type: "SET_COVER_IMGS_CSS", coverImgsCss });
14798
14810
  }
14799
14811
  }, [audioPlayerDispatch, coverImgsCss]);
14800
14812
  useEffect(() => {
@@ -14806,19 +14818,16 @@ const AudioPlayer = ({
14806
14818
  }
14807
14819
  }, [audioInitialState, audioPlayerDispatch]);
14808
14820
  useEffect(() => {
14809
- audioPlayerDispatch({
14810
- type: "UPDATE_PLAY_LIST",
14811
- playList
14812
- });
14821
+ audioPlayerDispatch({ type: "UPDATE_PLAY_LIST", playList });
14813
14822
  }, [audioPlayerDispatch, playList]);
14814
14823
  useEffect(() => {
14815
14824
  if (customIcons) {
14816
- audioPlayerDispatch({
14817
- type: "SET_CUSTOM_ICONS",
14818
- customIcons
14819
- });
14825
+ audioPlayerDispatch({ type: "SET_CUSTOM_ICONS", customIcons });
14820
14826
  }
14821
14827
  }, [customIcons, audioPlayerDispatch]);
14828
+ };
14829
+ const AudioPlayer = (props) => {
14830
+ usePropsStateEffect(props);
14822
14831
  return /* @__PURE__ */ jsxs($b9606c0c41d55371$export$27a5bd065ad55220, {
14823
14832
  id: "rm-audio-player",
14824
14833
  UNSAFE_className: "rm-audio-player-container",
@@ -11,7 +11,6 @@ export declare type AudioCustomProps = {
11
11
  export declare type AudioData = {
12
12
  src: string;
13
13
  id: number;
14
- index: number;
15
14
  name?: string | ReactNode;
16
15
  writer?: string | ReactNode;
17
16
  img?: string;
@@ -14,7 +14,7 @@ export declare type AudioContextAction = {
14
14
  type: "SET_PlAY_STATE";
15
15
  state?: boolean;
16
16
  } | {
17
- type: "SET_CURRENT_INDEX";
17
+ type: "SET_CURRENT_AUDIO";
18
18
  currentIndex: number;
19
19
  currentAudioId: number;
20
20
  } | {
@@ -0,0 +1,5 @@
1
+ import { VolumeSliderPlacement } from "./Content";
2
+ export declare const useVolumeSliderPlacement: ({ ref, initialState, }: {
3
+ ref: React.RefObject<HTMLElement>;
4
+ initialState: VolumeSliderPlacement;
5
+ }) => VolumeSliderPlacement;
@@ -1,5 +1,5 @@
1
1
  import { FC } from "react";
2
- import { ActiveUI, PlayListPlacement, CustomIcons, PlayerPlacement, PlayList, AudioInitialState, InterfacePlacement, CoverImgsCss } from '../AudioPlayer/Context';
2
+ import { ActiveUI, PlayListPlacement, CustomIcons, PlayerPlacement, PlayList, AudioInitialState, InterfacePlacement, CoverImgsCss } from '../../AudioPlayer/Context';
3
3
  export interface AudioPlayerProps {
4
4
  playList: PlayList;
5
5
  audioInitialState?: AudioInitialState;
@@ -0,0 +1,2 @@
1
+ import { AudioPlayerProps } from ".";
2
+ export declare const usePropsStateEffect: ({ placement, activeUI, coverImgsCss, audioInitialState, playList, customIcons, }: AudioPlayerProps) => void;
@@ -1,8 +1,6 @@
1
1
  import SortableList from "./SortableList";
2
2
  export default SortableList;
3
3
  export declare type ListData<T> = Array<T>;
4
- export declare type ListItem = Record<string, any> & {
5
- index: number;
6
- };
4
+ export declare type ListItem = Record<string, any>;
7
5
  export type { UseSortableListItemProps } from "./useSortableListItem";
8
6
  export type { SortableListItemProps } from "./SortableListItem";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-modern-audio-player",
3
- "version": "1.1.1",
3
+ "version": "1.1.4",
4
4
  "homepage": "https://github.com/slash9494/react-modern-audio-player/",
5
5
  "module": "dist/index.es.js",
6
6
  "main": "dist/index.cjs",
@@ -16,8 +16,7 @@
16
16
  "scripts": {
17
17
  "dev": "vite --host",
18
18
  "build": "rm -rf dist && tsc && vite build",
19
- "preview": "vite preview",
20
- "publish": "npm publish --access public"
19
+ "preview": "vite preview"
21
20
  },
22
21
  "peerDependencies": {
23
22
  "react": ">=16.8.0",