@ldelia/react-media 0.5.2 → 0.5.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.
@@ -7,12 +7,14 @@ interface BaseProps {
7
7
  }
8
8
  interface TrainingProps extends BaseProps {
9
9
  trainingMode: true;
10
+ duration?: never;
10
11
  videoId: string;
11
12
  }
12
13
  interface NonTrainingProps extends BaseProps {
13
14
  trainingMode: false;
15
+ duration: number;
14
16
  videoId?: never;
15
17
  }
16
18
  export type ReproductionWidgetProps = TrainingProps | NonTrainingProps;
17
- export declare const ReproductionWidget: ({ trainingMode, videoId, songTempo, onInit, }: ReproductionWidgetProps) => React.JSX.Element;
19
+ export declare const ReproductionWidget: ({ trainingMode, duration, videoId, songTempo, onInit, }: ReproductionWidgetProps) => React.JSX.Element;
18
20
  export {};
@@ -2,12 +2,11 @@ import React from 'react';
2
2
  import { YouTubeInnerPlayer } from './inner-players/YouTubeInnerPlayer';
3
3
  import { PlayAlongInnerPlayer } from './inner-players/PlayAlongInnerPlayer';
4
4
  import { Reproduction } from './models/Reproduction';
5
- export const ReproductionWidget = ({ trainingMode, videoId, songTempo = 0, onInit, }) => {
6
- const DURATION_TO_TEST = 30;
5
+ export const ReproductionWidget = ({ trainingMode, duration, videoId, songTempo = 0, onInit, }) => {
7
6
  function onPlayAlongInnerPlayerReadyHandler(event) {
8
7
  let newReproduction = Reproduction.newBuilder()
9
8
  .withTrainingMode(false)
10
- .withSongDuration(DURATION_TO_TEST)
9
+ .withSongDuration(duration)
11
10
  .withSongTempo(songTempo)
12
11
  .withCountingIn(songTempo > 0)
13
12
  .withInnerPlayer(event.target)
@@ -17,6 +17,7 @@ export const YouTubeInnerPlayer = ({ videoId, onReady }) => {
17
17
  origin: origin,
18
18
  },
19
19
  };
20
+ console.log(videoId, opts);
20
21
  if (origin === null) {
21
22
  return null;
22
23
  }
@@ -43,7 +43,7 @@ export declare class Reproduction {
43
43
  constructor(player: Player, requiresCountingIn: boolean, songTempo: number);
44
44
  on(eventName: keyof typeof Reproduction.EVENTS, handler: Handler): number | undefined;
45
45
  dispatch(eventName: keyof typeof Reproduction.EVENTS, args?: {}): void;
46
- private countIn;
46
+ private countInAndPlay;
47
47
  start(): void;
48
48
  play(): void;
49
49
  pause(): void;
@@ -108,7 +108,7 @@ export class Reproduction {
108
108
  // setTimeout(handler, 0);
109
109
  }
110
110
  }
111
- countIn(timeout, limit) {
111
+ countInAndPlay(timeout, limit) {
112
112
  // the initial count starts instantly, no need to wait
113
113
  this.countingInCounter++;
114
114
  this.dispatch(Reproduction.EVENTS.COUNTING_IN, { countingInCounter: this.countingInCounter });
@@ -118,7 +118,7 @@ export class Reproduction {
118
118
  clearInterval(interval);
119
119
  this.countingInCounter = 0;
120
120
  if (limit !== 5) {
121
- this.countIn(this.getBPMInterval(), 5);
121
+ this.countInAndPlay(this.getBPMInterval(), 5);
122
122
  }
123
123
  else {
124
124
  this.play();
@@ -135,7 +135,7 @@ export class Reproduction {
135
135
  }
136
136
  if (this.requiresCountingIn && this.getCurrentTime() === 0) {
137
137
  this.state = Reproduction.STATES.COUNTING_IN;
138
- this.countIn(this.getBPMInterval() * 2, 3);
138
+ this.countInAndPlay(this.getBPMInterval() * 2, 3);
139
139
  }
140
140
  else {
141
141
  this.play();
@@ -6,6 +6,7 @@ export interface TimelineProps {
6
6
  className?: string;
7
7
  selectedRange?: number[];
8
8
  withTimeBlocks?: boolean;
9
+ markers?: number[];
9
10
  onChange?: (value: number) => void;
10
11
  onRangeChange?: (value: number[]) => void;
11
12
  }
@@ -6,6 +6,7 @@ import styled from 'styled-components';
6
6
  import { TimelineValue } from './TimelineValue/TimelineValue';
7
7
  import { ZoomContext } from './ZoomContext/ZoomContext';
8
8
  import { getBlockOffsetForZoomLevel, getTimelineWrapperWidth, numberToPxString, } from './utils/utils';
9
+ import { TimelineMarkers } from './TimelineMarkers/TimelineMarkers';
9
10
  const TimelineContainer = styled.div `
10
11
  background-color: #f0f0f0;
11
12
  border: 1px solid #c9c9c9;
@@ -24,7 +25,7 @@ const TimelineWrapper = styled.div `
24
25
  align-items: center;
25
26
  overflow: hidden;
26
27
  `;
27
- export const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], withTimeBlocks = true, onChange = () => { }, onRangeChange = () => { }, className = '', }) => {
28
+ export const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], markers = [], withTimeBlocks = true, onChange = () => { }, onRangeChange = () => { }, className = '', }) => {
28
29
  const timeLineContainerRef = useRef(null);
29
30
  const canvasRef = useRef(null);
30
31
  const [zoomContextValue, setZoomContextValue] = useState({
@@ -73,5 +74,6 @@ export const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], w
73
74
  React.createElement(ZoomContext.Provider, { value: zoomContextValue },
74
75
  React.createElement(TimelineCanvas, { ref: canvasRef, duration: duration, withTimeBlocks: withTimeBlocks }),
75
76
  React.createElement(TimelineValue, { value: value, canvasRef: canvasRef }),
77
+ React.createElement(TimelineMarkers, { markers: markers }),
76
78
  React.createElement(RangeSelectorCanvas, { selectedRange: selectedRange, onChange: onChange, onRangeChange: onRangeChange })))));
77
79
  };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ markers: number[];
4
+ }
5
+ export declare const TimelineMarkers: ({ markers }: Props) => React.JSX.Element;
6
+ export {};
@@ -0,0 +1,26 @@
1
+ import React, { useContext } from 'react';
2
+ import styled from 'styled-components';
3
+ import { ZoomContext } from '../ZoomContext/ZoomContext';
4
+ import { secondsToPixel } from '../utils/utils';
5
+ const MarkerContainer = styled.div `
6
+ position: relative;
7
+ height: 100px;
8
+ display: flex;
9
+ justify-content: center;
10
+ align-items: flex-start;
11
+ `;
12
+ const MarkerInner = styled.div `
13
+ & {
14
+ width: 0;
15
+ height: 0;
16
+ border-left: 10px solid transparent;
17
+ border-right: 10px solid transparent;
18
+ border-top: 20px solid #4CAF50; /* Green color */
19
+ position: absolute;
20
+ }
21
+ `;
22
+ export const TimelineMarkers = ({ markers }) => {
23
+ const zoomContextValue = useContext(ZoomContext);
24
+ return (React.createElement(React.Fragment, null, markers.map((marker, index) => (React.createElement(MarkerContainer, { key: index, style: { left: secondsToPixel(zoomContextValue, marker) } },
25
+ React.createElement(MarkerInner, null))))));
26
+ };
@@ -12,6 +12,7 @@ const ValueLine = styled.span `
12
12
  width: 1px;
13
13
  height: 100%;
14
14
  background-color: #575757;
15
+ z-index: 1; // force the ValueLine to be on top of the Markers
15
16
  `;
16
17
  const PostValueLine = styled.span `
17
18
  position: absolute;
@@ -7,3 +7,4 @@ export declare const WithSelectedRange: import("@storybook/csf").AnnotatedStoryF
7
7
  export declare const WithCustomClassName: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
8
8
  export declare const WithoutTimeBlocks: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
9
9
  export declare const Minimalist: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
10
+ export declare const WithSelectedRangeAndMarkers: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-a5624094").R, TimelineProps>;
@@ -52,3 +52,11 @@ Minimalist.args = {
52
52
  withTimeBlocks: false,
53
53
  className: 'minimalist',
54
54
  };
55
+ export const WithSelectedRangeAndMarkers = Template.bind({});
56
+ WithSelectedRangeAndMarkers.args = {
57
+ duration: 305,
58
+ value: 31,
59
+ zoomLevel: 0,
60
+ selectedRange: [20, 30],
61
+ markers: [90, 108],
62
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldelia/react-media",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "A React components collection for media-related features.",
5
5
  "private": false,
6
6
  "keywords": [