@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.
- package/dist/components/reproduction-widget/ReproductionWidget.d.ts +3 -1
- package/dist/components/reproduction-widget/ReproductionWidget.js +2 -3
- package/dist/components/reproduction-widget/inner-players/YouTubeInnerPlayer.js +1 -0
- package/dist/components/reproduction-widget/models/Reproduction.d.ts +1 -1
- package/dist/components/reproduction-widget/models/Reproduction.js +3 -3
- package/dist/components/timeline/Timeline.d.ts +1 -0
- package/dist/components/timeline/Timeline.js +3 -1
- package/dist/components/timeline/TimelineMarkers/TimelineMarkers.d.ts +6 -0
- package/dist/components/timeline/TimelineMarkers/TimelineMarkers.js +26 -0
- package/dist/components/timeline/TimelineValue/TimelineValue.js +1 -0
- package/dist/stories/timeline.stories.d.ts +1 -0
- package/dist/stories/timeline.stories.js +8 -0
- package/package.json +1 -1
|
@@ -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(
|
|
9
|
+
.withSongDuration(duration)
|
|
11
10
|
.withSongTempo(songTempo)
|
|
12
11
|
.withCountingIn(songTempo > 0)
|
|
13
12
|
.withInnerPlayer(event.target)
|
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
138
|
+
this.countInAndPlay(this.getBPMInterval() * 2, 3);
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
141
141
|
this.play();
|
|
@@ -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,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
|
+
};
|
|
@@ -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
|
+
};
|