react-modern-audio-player 1.1.2 → 1.1.5

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 = {
@@ -8119,10 +8119,11 @@ const audioPlayerReducer = (state, action) => {
8119
8119
  console.error("UPDATE_PLAY_LIST ERROR - curPlayId is not found on playList");
8120
8120
  return state;
8121
8121
  }
8122
+ const curIdx = action.playList.findIndex((item) => item.id === state.curPlayId);
8122
8123
  return {
8123
8124
  ...state,
8124
8125
  playList: action.playList,
8125
- curIdx: curPlayListItem.index
8126
+ curIdx
8126
8127
  };
8127
8128
  }
8128
8129
  case "SET_VOLUME":
@@ -8156,7 +8157,7 @@ const audioPlayerReducer = (state, action) => {
8156
8157
  isPlaying: !state.curAudioState.isPlaying
8157
8158
  }
8158
8159
  };
8159
- case "SET_CURRENT_INDEX":
8160
+ case "SET_CURRENT_AUDIO":
8160
8161
  return {
8161
8162
  ...state,
8162
8163
  curPlayId: action.currentAudioId,
@@ -12645,6 +12646,12 @@ const useWaveSurfer = () => {
12645
12646
  const curTime = elementRefs.waveformInst.getCurrentTime();
12646
12647
  trackCurTimeEl.innerText = getTimeWithPadStart(curTime);
12647
12648
  }, [elementRefs]);
12649
+ const waveEl = document.getElementsByTagName("wave");
12650
+ useEffect(() => {
12651
+ if (waveEl.length > 1) {
12652
+ waveEl[0].setAttribute("style", "display: none");
12653
+ }
12654
+ }, [waveEl]);
12648
12655
  const [curAudioData, setCurAudioData] = useState();
12649
12656
  useEffect(() => {
12650
12657
  if (!(elementRefs == null ? void 0 : elementRefs.waveformInst) || !playList[curIdx])
@@ -12780,6 +12787,8 @@ const StyledBtn = styled.button`
12780
12787
  height: 100%;
12781
12788
  pointer-events: none;
12782
12789
  }
12790
+
12791
+ /** //TODO : animation on off */
12783
12792
  &:hover {
12784
12793
  transform: scale(1.1);
12785
12794
  }
@@ -12888,7 +12897,7 @@ const PlayBtn = () => {
12888
12897
  customIcons
12889
12898
  } = useNonNullableContext(audioPlayerStateContext);
12890
12899
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12891
- const onClick = () => audioPlayerDispatch({
12900
+ const changePlayState = () => audioPlayerDispatch({
12892
12901
  type: "SET_PlAY_STATE"
12893
12902
  });
12894
12903
  const PlayIcon = useMemo(() => {
@@ -12903,7 +12912,7 @@ const PlayBtn = () => {
12903
12912
  });
12904
12913
  }, [curAudioState.isPlaying, customIcons == null ? void 0 : customIcons.pause, customIcons == null ? void 0 : customIcons.play]);
12905
12914
  return /* @__PURE__ */ jsx(StyledPlayBtn, {
12906
- onClick,
12915
+ onClick: changePlayState,
12907
12916
  className: "play-button",
12908
12917
  children: PlayIcon
12909
12918
  });
@@ -12922,7 +12931,7 @@ const PrevNnextBtn = ({
12922
12931
  customIcons
12923
12932
  } = useNonNullableContext(audioPlayerStateContext);
12924
12933
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12925
- const onClickBtn = () => {
12934
+ const changeAudio = () => {
12926
12935
  if (type === "next") {
12927
12936
  audioPlayerDispatch({
12928
12937
  type: "NEXT_AUDIO"
@@ -12950,7 +12959,7 @@ const PrevNnextBtn = ({
12950
12959
  return null;
12951
12960
  }, [customIcons == null ? void 0 : customIcons.next, customIcons == null ? void 0 : customIcons.prev, type]);
12952
12961
  return visible ? /* @__PURE__ */ jsx(StyledBtn, {
12953
- onClick: onClickBtn,
12962
+ onClick: changeAudio,
12954
12963
  className: "prev-n-next-button",
12955
12964
  children: PrevNnextIcon
12956
12965
  }) : null;
@@ -12982,7 +12991,7 @@ const RepeatTypeBtn = () => {
12982
12991
  customIcons
12983
12992
  } = useNonNullableContext(audioPlayerStateContext);
12984
12993
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
12985
- const onClick = useCallback(() => {
12994
+ const changeRepeatType = useCallback(() => {
12986
12995
  switch (curAudioState.repeatType) {
12987
12996
  case "ALL":
12988
12997
  audioPlayerDispatch({
@@ -13035,7 +13044,7 @@ const RepeatTypeBtn = () => {
13035
13044
  }
13036
13045
  }, [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
13046
  return /* @__PURE__ */ jsx(StyledBtn, {
13038
- onClick,
13047
+ onClick: changeRepeatType,
13039
13048
  className: "repeat-button",
13040
13049
  children: RepeatIcon
13041
13050
  });
@@ -13062,7 +13071,7 @@ const VolumeTriggerBtn = forwardRef((_, ref) => {
13062
13071
  customIcons
13063
13072
  } = useNonNullableContext(audioPlayerStateContext);
13064
13073
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
13065
- const onClickMuted = useCallback(() => audioPlayerDispatch({
13074
+ const changeMuteState = useCallback(() => audioPlayerDispatch({
13066
13075
  type: "SET_MUTED",
13067
13076
  muted: !curAudioState.muted
13068
13077
  }), [audioPlayerDispatch, curAudioState.muted]);
@@ -13112,7 +13121,7 @@ const VolumeTriggerBtn = forwardRef((_, ref) => {
13112
13121
  }
13113
13122
  }, [curAudioState.muted, curAudioState.volume, customIcons == null ? void 0 : customIcons.volumeMuted, customIcons == null ? void 0 : customIcons.volumeFull, customIcons == null ? void 0 : customIcons.volumeHalf]);
13114
13123
  return /* @__PURE__ */ jsx(StyledBtn, {
13115
- onClick: onClickMuted,
13124
+ onClick: changeMuteState,
13116
13125
  className: "volume-trigger-container",
13117
13126
  ref,
13118
13127
  children: VolumeIcon
@@ -13751,7 +13760,7 @@ const usePlayList = ({
13751
13760
  const [dragStartIdx, setDragStartIdx] = useState(0);
13752
13761
  const onClickItem = useCallback((index) => {
13753
13762
  audioPlayerDispatch({
13754
- type: "SET_CURRENT_INDEX",
13763
+ type: "SET_CURRENT_AUDIO",
13755
13764
  currentIndex: index,
13756
13765
  currentAudioId: playList[index].id
13757
13766
  });
@@ -13816,7 +13825,6 @@ const PlayList = ({
13816
13825
  }), document.querySelector(".sortable-play-list")) : /* @__PURE__ */ jsx(Fragment, {});
13817
13826
  };
13818
13827
  const PlayListContainer = styled.div`
13819
- height: 20vh;
13820
13828
  transition-property: max-height, opacity;
13821
13829
  overflow-x: hidden;
13822
13830
  overflow-y: auto;
@@ -14398,29 +14406,39 @@ const DropdownTrigger = ({
14398
14406
  };
14399
14407
  Dropdown.Content = DropdownContent;
14400
14408
  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");
14409
+ const useVolumeSliderPlacement = ({
14410
+ ref,
14411
+ initialState
14412
+ }) => {
14413
+ const [volumeSliderPlacement, setVolumeSliderPlacement] = useState(initialState);
14409
14414
  useEffect(() => {
14410
- if (triggerRef.current) {
14415
+ if (ref.current) {
14411
14416
  const placementValidation = () => {
14412
- if (triggerRef.current.getBoundingClientRect().top < window.innerHeight / 2) {
14417
+ if (ref.current.getBoundingClientRect().top < window.innerHeight / 2) {
14413
14418
  return "bottom";
14414
14419
  }
14415
14420
  return "top";
14416
14421
  };
14417
14422
  setVolumeSliderPlacement(placementValidation());
14418
14423
  }
14419
- }, [triggerRef.current]);
14424
+ }, [ref.current]);
14425
+ return volumeSliderPlacement;
14426
+ };
14427
+ const Volume = () => {
14428
+ const triggerRef = useRef(null);
14429
+ const {
14430
+ activeUI: {
14431
+ volumeSlider: volumeSliderEl
14432
+ }
14433
+ } = useNonNullableContext(audioPlayerStateContext);
14434
+ const volumeSliderPlacement = useVolumeSliderPlacement({
14435
+ ref: triggerRef,
14436
+ initialState: "bottom"
14437
+ });
14420
14438
  return /* @__PURE__ */ jsxs(Dropdown, {
14421
14439
  placement: volumeSliderPlacement,
14422
14440
  triggerType: "hover",
14423
- disabled: !volumeSlider,
14441
+ disabled: !volumeSliderEl,
14424
14442
  children: [/* @__PURE__ */ jsx(Dropdown.Trigger, {
14425
14443
  children: /* @__PURE__ */ jsx(VolumeTriggerBtn, {
14426
14444
  ref: triggerRef
@@ -14541,18 +14559,10 @@ const TrackTimeCurrent = () => {
14541
14559
  const {
14542
14560
  activeUI
14543
14561
  } = 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]);
14562
+ useTrackTimeRefDispatchEffect({
14563
+ ref: trackCurTimeRef,
14564
+ refName: "trackCurTimeEl"
14565
+ });
14556
14566
  return /* @__PURE__ */ jsx(TrackTimeCurrentContainer, {
14557
14567
  type: activeUI.trackTime,
14558
14568
  className: "track-time-current-container",
@@ -14568,18 +14578,10 @@ const TrackTimeDuration = () => {
14568
14578
  const {
14569
14579
  activeUI
14570
14580
  } = 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]);
14581
+ useTrackTimeRefDispatchEffect({
14582
+ ref: trackDurationRef,
14583
+ refName: "trackDurationEl"
14584
+ });
14583
14585
  return /* @__PURE__ */ jsx(TrackTimeDurationContainer, {
14584
14586
  type: activeUI.trackTime,
14585
14587
  className: "track-time-duration-container",
@@ -14590,6 +14592,23 @@ const TrackTimeDuration = () => {
14590
14592
  })
14591
14593
  });
14592
14594
  };
14595
+ const useTrackTimeRefDispatchEffect = ({
14596
+ ref,
14597
+ refName
14598
+ }) => {
14599
+ const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14600
+ useEffect(() => {
14601
+ const trackTimeRef = ref.current;
14602
+ if (trackTimeRef) {
14603
+ audioPlayerDispatch({
14604
+ type: "SET_ELEMENT_REFS",
14605
+ elementRefs: {
14606
+ [refName]: trackTimeRef
14607
+ }
14608
+ });
14609
+ }
14610
+ }, [ref.current, audioPlayerDispatch, refName]);
14611
+ };
14593
14612
  const TrackTimeContainer = styled.div`
14594
14613
  display: flex;
14595
14614
  align-items: center;
@@ -14635,7 +14654,7 @@ const Information = () => {
14635
14654
  curIdx,
14636
14655
  activeUI
14637
14656
  } = 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);
14657
+ 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
14658
  return /* @__PURE__ */ jsxs(Fragment, {
14640
14659
  children: [/* @__PURE__ */ jsx(Grid.Item, {
14641
14660
  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 +14662,7 @@ const Information = () => {
14643
14662
  children: /* @__PURE__ */ jsx(Artwork, {})
14644
14663
  }), /* @__PURE__ */ jsx(Grid.Item, {
14645
14664
  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,
14665
+ visible: isTrackInfoActive,
14647
14666
  children: /* @__PURE__ */ jsx(TrackInfo, {})
14648
14667
  }), /* @__PURE__ */ jsx(Grid.Item, {
14649
14668
  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 +14778,13 @@ const Interface = () => {
14759
14778
  })]
14760
14779
  });
14761
14780
  };
14762
- const AudioPlayer = ({
14763
- playList,
14764
- audioInitialState,
14781
+ const usePropsStateEffect = ({
14765
14782
  placement = {},
14766
14783
  activeUI,
14767
- customIcons,
14768
- coverImgsCss
14784
+ coverImgsCss,
14785
+ audioInitialState,
14786
+ playList,
14787
+ customIcons
14769
14788
  }) => {
14770
14789
  const audioPlayerDispatch = useNonNullableContext(audioPlayerDispatchContext);
14771
14790
  useLayoutEffect(() => {
@@ -14783,18 +14802,12 @@ const AudioPlayer = ({
14783
14802
  }, [audioPlayerDispatch, placement]);
14784
14803
  useLayoutEffect(() => {
14785
14804
  if (activeUI) {
14786
- audioPlayerDispatch({
14787
- type: "SET_ACTIVE_UI",
14788
- activeUI
14789
- });
14805
+ audioPlayerDispatch({ type: "SET_ACTIVE_UI", activeUI });
14790
14806
  }
14791
14807
  }, [activeUI, audioPlayerDispatch]);
14792
14808
  useLayoutEffect(() => {
14793
14809
  if (coverImgsCss) {
14794
- audioPlayerDispatch({
14795
- type: "SET_COVER_IMGS_CSS",
14796
- coverImgsCss
14797
- });
14810
+ audioPlayerDispatch({ type: "SET_COVER_IMGS_CSS", coverImgsCss });
14798
14811
  }
14799
14812
  }, [audioPlayerDispatch, coverImgsCss]);
14800
14813
  useEffect(() => {
@@ -14806,19 +14819,16 @@ const AudioPlayer = ({
14806
14819
  }
14807
14820
  }, [audioInitialState, audioPlayerDispatch]);
14808
14821
  useEffect(() => {
14809
- audioPlayerDispatch({
14810
- type: "UPDATE_PLAY_LIST",
14811
- playList
14812
- });
14822
+ audioPlayerDispatch({ type: "UPDATE_PLAY_LIST", playList });
14813
14823
  }, [audioPlayerDispatch, playList]);
14814
14824
  useEffect(() => {
14815
14825
  if (customIcons) {
14816
- audioPlayerDispatch({
14817
- type: "SET_CUSTOM_ICONS",
14818
- customIcons
14819
- });
14826
+ audioPlayerDispatch({ type: "SET_CUSTOM_ICONS", customIcons });
14820
14827
  }
14821
14828
  }, [customIcons, audioPlayerDispatch]);
14829
+ };
14830
+ const AudioPlayer = (props) => {
14831
+ usePropsStateEffect(props);
14822
14832
  return /* @__PURE__ */ jsxs($b9606c0c41d55371$export$27a5bd065ad55220, {
14823
14833
  id: "rm-audio-player",
14824
14834
  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,11 @@
1
1
  {
2
2
  "name": "react-modern-audio-player",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
+ "author": {
5
+ "name": "LYH",
6
+ "email": "slash9494@naver.com",
7
+ "url": "https://github.com/slash9494"
8
+ },
4
9
  "homepage": "https://github.com/slash9494/react-modern-audio-player/",
5
10
  "module": "dist/index.es.js",
6
11
  "main": "dist/index.cjs",
@@ -9,6 +14,7 @@
9
14
  "files": [
10
15
  "dist"
11
16
  ],
17
+ "license": "MIT",
12
18
  "repository": {
13
19
  "type": "git",
14
20
  "url": "git+https://github.com/slash9494/react-modern-audio-player.git"