sense-react-timeline-editor 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 zdarcy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # React Timeline Editor
2
+ [![npm version](https://img.shields.io/npm/v/@xzdarcy/react-timeline-editor.svg?style=flat-square)](https://www.npmjs.com/package/@xzdarcy/react-timeline-editor)
3
+ [![npm downloads](https://img.shields.io/npm/dm/@xzdarcy/react-timeline-editor.svg?style=flat-square)](https://www.npmjs.com/package/@xzdarcy/react-timeline-editor)
4
+
5
+ **[React Timeline Editor](https://zdarcy.com/)** is a react component used to quickly build a timeline animation editor.
6
+
7
+ ![example](https://github.com/xzdarcy/react-timeline-editor/blob/f79d85eee8a723e5210c04232daf2c51888418c0/public/assets/timeline.gif)
8
+ ## Getting Started
9
+
10
+ ```bash
11
+ npm install @xzdarcy/react-timeline-editor
12
+ ```
13
+
14
+ ```ts
15
+ import { Timeline, TimelineEffect, TimelineRow } from '@xzdarcy/react-timeline-editor';
16
+ import React from 'react';
17
+
18
+ const mockData: TimelineRow[] = [{
19
+ id: "0",
20
+ actions: [
21
+ {
22
+ id: "action00",
23
+ start: 0,
24
+ end: 2,
25
+ effectId: "effect0",
26
+ },
27
+ ],
28
+ },
29
+ {
30
+ id: "1",
31
+ actions: [
32
+ {
33
+ id: "action10",
34
+ start: 1.5,
35
+ end: 5,
36
+ effectId: "effect1",
37
+ }
38
+ ],
39
+ }]
40
+
41
+ const mockEffect: Record<string, TimelineEffect> = {
42
+ effect0: {
43
+ id: "effect0",
44
+ name: "效果0",
45
+ },
46
+ effect1: {
47
+ id: "effect1",
48
+ name: "效果1",
49
+ },
50
+ };
51
+
52
+ const TimelineEditor = () => {
53
+ return (
54
+ <Timeline
55
+ editorData={mockData}
56
+ effects={mockEffect}
57
+ />
58
+ );
59
+ };
60
+ ```
61
+
62
+ ## Documention
63
+ Checkout the [Docs](https://zdarcy.com/) for a demonstration of some basic and advanced features.
64
+
File without changes
@@ -0,0 +1,21 @@
1
+ import React, { FC } from 'react';
2
+ import { ScrollSync } from 'react-virtualized';
3
+ import { CommonProp } from '../../interface/common_prop';
4
+ import './cursor.less';
5
+ /** 动画时间轴组件参数 */
6
+ export declare type CursorProps = CommonProp & {
7
+ /** 距离左侧滚动距离 */
8
+ scrollLeft: number;
9
+ /** 设置光标位置 */
10
+ setCursor: (param: {
11
+ left?: number;
12
+ time?: number;
13
+ }) => boolean;
14
+ /** 时间轴区域dom ref */
15
+ areaRef: React.MutableRefObject<HTMLDivElement>;
16
+ /** 设置scroll left */
17
+ deltaScrollLeft: (delta: number) => void;
18
+ /** 滚动同步ref(TODO: 该数据用于临时解决scrollLeft拖住时不同步问题) */
19
+ scrollSync: React.MutableRefObject<ScrollSync>;
20
+ };
21
+ export declare const Cursor: FC<CursorProps>;
@@ -0,0 +1,12 @@
1
+ import { FC } from "react";
2
+ import './drag_lines.less';
3
+ export interface DragLineData {
4
+ isMoving: boolean;
5
+ movePositions: number[];
6
+ assistPositions: number[];
7
+ }
8
+ export declare type DragLineProps = DragLineData & {
9
+ scrollLeft: number;
10
+ };
11
+ /** 拖拽辅助线 */
12
+ export declare const DragLines: FC<DragLineProps>;
@@ -0,0 +1,16 @@
1
+ import React, { FC } from 'react';
2
+ import { TimelineAction, TimelineRow } from '../../interface/action';
3
+ import { CommonProp } from '../../interface/common_prop';
4
+ import { DragLineData } from './drag_lines';
5
+ import './edit_action.less';
6
+ export declare type EditActionProps = CommonProp & {
7
+ row: TimelineRow;
8
+ action: TimelineAction;
9
+ dragLineData: DragLineData;
10
+ setEditorData: (params: TimelineRow[]) => void;
11
+ handleTime: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => number;
12
+ areaRef: React.MutableRefObject<HTMLDivElement>;
13
+ /** 设置scroll left */
14
+ deltaScrollLeft?: (delta: number) => void;
15
+ };
16
+ export declare const EditAction: FC<EditActionProps>;
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { OnScrollParams } from 'react-virtualized';
3
+ import { TimelineRow } from '../../interface/action';
4
+ import { CommonProp } from '../../interface/common_prop';
5
+ import './edit_area.less';
6
+ export declare type EditAreaProps = CommonProp & {
7
+ /** 距离左侧滚动距离 */
8
+ scrollLeft: number;
9
+ /** 距离顶部滚动距离 */
10
+ scrollTop: number;
11
+ /** 滚动回调,用于同步滚动 */
12
+ onScroll: (params: OnScrollParams) => void;
13
+ /** 设置编辑器数据 */
14
+ setEditorData: (params: TimelineRow[]) => void;
15
+ /** 设置scroll left */
16
+ deltaScrollLeft: (scrollLeft: number) => void;
17
+ };
18
+ /** edit area ref数据 */
19
+ export interface EditAreaState {
20
+ domRef: React.MutableRefObject<HTMLDivElement>;
21
+ }
22
+ export declare const EditArea: React.ForwardRefExoticComponent<CommonProp & {
23
+ /** 距离左侧滚动距离 */
24
+ scrollLeft: number;
25
+ /** 距离顶部滚动距离 */
26
+ scrollTop: number;
27
+ /** 滚动回调,用于同步滚动 */
28
+ onScroll: (params: OnScrollParams) => void;
29
+ /** 设置编辑器数据 */
30
+ setEditorData: (params: TimelineRow[]) => void;
31
+ /** 设置scroll left */
32
+ deltaScrollLeft: (scrollLeft: number) => void;
33
+ } & React.RefAttributes<EditAreaState>>;
@@ -0,0 +1,17 @@
1
+ import React, { FC } from 'react';
2
+ import { TimelineRow } from '../../interface/action';
3
+ import { CommonProp } from '../../interface/common_prop';
4
+ import { DragLineData } from './drag_lines';
5
+ import './edit_row.less';
6
+ export declare type EditRowProps = CommonProp & {
7
+ areaRef: React.MutableRefObject<HTMLDivElement>;
8
+ rowData?: TimelineRow;
9
+ style?: React.CSSProperties;
10
+ dragLineData: DragLineData;
11
+ setEditorData: (params: TimelineRow[]) => void;
12
+ /** 距离左侧滚动距离 */
13
+ scrollLeft: number;
14
+ /** 设置scroll left */
15
+ deltaScrollLeft: (scrollLeft: number) => void;
16
+ };
17
+ export declare const EditRow: FC<EditRowProps>;
@@ -0,0 +1,33 @@
1
+ import { TimelineAction, TimelineRow } from "../../../interface/action";
2
+ import { DragLineData } from "../drag_lines";
3
+ export declare function useDragLine(): {
4
+ initDragLine: (data: {
5
+ movePositions?: number[];
6
+ assistPositions?: number[];
7
+ }) => void;
8
+ updateDragLine: (data: {
9
+ movePositions?: number[];
10
+ assistPositions?: number[];
11
+ }) => void;
12
+ disposeDragLine: () => void;
13
+ dragLineData: DragLineData;
14
+ defaultGetAssistPosition: (data: {
15
+ editorData: TimelineRow[];
16
+ assistActionIds?: string[];
17
+ action: TimelineAction;
18
+ row: TimelineRow;
19
+ startLeft: number;
20
+ scale: number;
21
+ scaleWidth: number;
22
+ hideCursor: boolean;
23
+ cursorLeft: number;
24
+ }) => number[];
25
+ defaultGetMovePosition: (data: {
26
+ start: number;
27
+ end: number;
28
+ dir?: "right" | "left";
29
+ startLeft: number;
30
+ scale: number;
31
+ scaleWidth: number;
32
+ }) => number[];
33
+ };
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { DragEvent, ResizeEvent } from '@interactjs/types/index';
3
+ export declare function useAutoScroll(target: React.MutableRefObject<HTMLDivElement>): {
4
+ initAutoScroll: () => void;
5
+ dealDragAutoScroll: (e: DragEvent, deltaScroll?: (delta: number) => void) => boolean;
6
+ dealResizeAutoScroll: (e: ResizeEvent, dir: 'left' | 'right', deltaScroll?: (delta: number) => void) => boolean;
7
+ stopAutoScroll: () => void;
8
+ };
@@ -0,0 +1,11 @@
1
+ import { DraggableOptions } from "@interactjs/actions/drag/plugin";
2
+ import { ResizableOptions } from "@interactjs/actions/resize/plugin";
3
+ import { Interactable } from "@interactjs/types";
4
+ import { FC } from "react";
5
+ export declare const InteractComp: FC<{
6
+ interactRef?: React.MutableRefObject<Interactable>;
7
+ draggable: boolean;
8
+ draggableOptions: DraggableOptions;
9
+ resizable: boolean;
10
+ resizableOptions: ResizableOptions;
11
+ }>;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { RowRndApi, RowRndProps } from './row_rnd_interface';
3
+ export declare const RowDnd: React.ForwardRefExoticComponent<RowRndProps & React.RefAttributes<RowRndApi>>;
@@ -0,0 +1,60 @@
1
+ /// <reference types="react" />
2
+ declare type EventData = {
3
+ lastLeft: number;
4
+ left: number;
5
+ lastWidth: number;
6
+ width: number;
7
+ lastTop?: number;
8
+ top?: number;
9
+ lastHeight?: number;
10
+ height?: number;
11
+ };
12
+ export declare type RndDragStartCallback = () => void;
13
+ export declare type RndDragCallback = (data: EventData, scrollDelta?: number) => boolean | void;
14
+ export declare type RndDragEndCallback = (data: Pick<EventData, 'left' | 'width' | 'top' | 'height'>) => void;
15
+ export declare type Direction = "left" | "right";
16
+ export declare type RndResizeStartCallback = (dir: Direction) => void;
17
+ export declare type RndResizeCallback = (dir: Direction, data: EventData) => boolean | void;
18
+ export declare type RndResizeEndCallback = (dir: Direction, data: Pick<EventData, 'left' | 'width' | 'top' | 'height'>) => void;
19
+ export interface RowRndApi {
20
+ updateWidth: (size: number) => void;
21
+ updateLeft: (left: number) => void;
22
+ updateHeight: (size: number) => void;
23
+ updateTop: (top: number) => void;
24
+ getLeft: () => number;
25
+ getWidth: () => number;
26
+ getTop: () => number;
27
+ getHeight: () => number;
28
+ }
29
+ export interface RowRndProps {
30
+ width?: number;
31
+ left?: number;
32
+ height?: number;
33
+ top?: number;
34
+ grid?: number;
35
+ start?: number;
36
+ bounds?: {
37
+ left: number;
38
+ right: number;
39
+ top?: number;
40
+ bottom?: number;
41
+ };
42
+ edges?: {
43
+ left: boolean | string;
44
+ right: boolean | string;
45
+ };
46
+ onResizeStart?: RndResizeStartCallback;
47
+ onResize?: RndResizeCallback;
48
+ onResizeEnd?: RndResizeEndCallback;
49
+ onDragStart?: RndDragStartCallback;
50
+ onDrag?: RndDragCallback;
51
+ onDragEnd?: RndDragEndCallback;
52
+ parentRef?: React.MutableRefObject<HTMLDivElement>;
53
+ deltaScrollLeft?: (delta: number) => void;
54
+ children?: React.ReactNode;
55
+ enableResizing?: boolean;
56
+ enableDragging?: boolean;
57
+ adsorptionPositions?: number[];
58
+ adsorptionDistance?: number;
59
+ }
60
+ export {};
@@ -0,0 +1,18 @@
1
+ import { FC } from 'react';
2
+ import { OnScrollParams } from 'react-virtualized';
3
+ import { CommonProp } from '../../interface/common_prop';
4
+ import './time_area.less';
5
+ /** 动画时间轴组件参数 */
6
+ export declare type TimeAreaProps = CommonProp & {
7
+ /** 左侧滚动距离 */
8
+ scrollLeft: number;
9
+ /** 滚动回调,用于同步滚动 */
10
+ onScroll: (params: OnScrollParams) => void;
11
+ /** 设置光标位置 */
12
+ setCursor: (param: {
13
+ left?: number;
14
+ time?: number;
15
+ }) => void;
16
+ };
17
+ /** 动画时间轴组件 */
18
+ export declare const TimeArea: FC<TimeAreaProps>;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { TimelineEditor, TimelineState } from '../interface/timeline';
3
+ import './timeline.less';
4
+ export declare const Timeline: React.ForwardRefExoticComponent<TimelineEditor & React.RefAttributes<TimelineState>>;
@@ -0,0 +1,16 @@
1
+ import { Events } from './events';
2
+ /**
3
+ * 事件派发器
4
+ */
5
+ export declare class Emitter<EventTypes> {
6
+ events: {
7
+ [key: string]: CallableFunction[];
8
+ };
9
+ constructor(events: Events);
10
+ on<K extends keyof EventTypes>(names: K | K[], handler: (args: EventTypes[K]) => boolean | unknown): this;
11
+ trigger<K extends keyof EventTypes>(name: K, params: EventTypes[K]): boolean;
12
+ bind(name: string): void;
13
+ exist(name: string): boolean;
14
+ off<K extends keyof EventTypes>(name: K, handler?: (args: EventTypes[K]) => boolean | unknown): void;
15
+ offAll(): void;
16
+ }
@@ -0,0 +1,125 @@
1
+ import { TimelineRow } from '../interface/action';
2
+ import { TimelineEffect } from '../interface/effect';
3
+ import { Emitter } from './emitter';
4
+ import { EventTypes } from './events';
5
+ export interface ITimelineEngine extends Emitter<EventTypes> {
6
+ readonly isPlaying: boolean;
7
+ readonly isPaused: boolean;
8
+ effects: Record<string, TimelineEffect>;
9
+ data: TimelineRow[];
10
+ /** 设置播放速率 */
11
+ setPlayRate(rate: number): boolean;
12
+ /** 获取播放速率 */
13
+ getPlayRate(): number;
14
+ /** 重新渲染当前时间 */
15
+ reRender(): void;
16
+ /** 设置播放时间 */
17
+ setTime(time: number, isTick?: boolean): boolean;
18
+ /** 获取播放时间 */
19
+ getTime(): number;
20
+ /** 播放 */
21
+ play(param: {
22
+ /** 默认从头运行到尾, 优先级大于autoEnd */
23
+ toTime?: number;
24
+ /** 是否播放完后自动结束 */
25
+ autoEnd?: boolean;
26
+ }): boolean;
27
+ /** 暂停 */
28
+ pause(): void;
29
+ }
30
+ /**
31
+ * 时间轴播放器
32
+ * 可脱离编辑器单独运行
33
+ * @export
34
+ * @class TimelineEngine
35
+ * @extends {Emitter<EventTypes>}
36
+ */
37
+ export declare class TimelineEngine extends Emitter<EventTypes> implements ITimelineEngine {
38
+ constructor();
39
+ /** requestAnimationFrame timerId */
40
+ private _timerId;
41
+ /** 播放速率 */
42
+ private _playRate;
43
+ /** 当前时间 */
44
+ private _currentTime;
45
+ /** 播放状态 */
46
+ private _playState;
47
+ /** 时间帧pre数据 */
48
+ private _prev;
49
+ /** 动作效果map */
50
+ private _effectMap;
51
+ /** 需要运行的动作map */
52
+ private _actionMap;
53
+ /** 按动作开始时间正序排列后的动作id数组 */
54
+ private _actionSortIds;
55
+ /** 当前遍历到的action index */
56
+ private _next;
57
+ /** 动作时间范围包含当前时间的actionId列表 */
58
+ private _activeActionIds;
59
+ /** 是否正在播放 */
60
+ get isPlaying(): boolean;
61
+ /** 是否暂停中 */
62
+ get isPaused(): boolean;
63
+ set effects(effects: Record<string, TimelineEffect>);
64
+ set data(data: TimelineRow[]);
65
+ /**
66
+ * 设置播放速率
67
+ * @memberof TimelineEngine
68
+ */
69
+ setPlayRate(rate: number): boolean;
70
+ /**
71
+ * 获取播放速率
72
+ * @memberof TimelineEngine
73
+ */
74
+ getPlayRate(): number;
75
+ /**
76
+ * 重新渲染当前时间
77
+ * @return {*}
78
+ * @memberof TimelineEngine
79
+ */
80
+ reRender(): void;
81
+ /**
82
+ * 设置播放时间
83
+ * @param {number} time
84
+ * @param {boolean} [isTick] 是否是tick触发
85
+ * @memberof TimelineEngine
86
+ */
87
+ setTime(time: number, isTick?: boolean): boolean;
88
+ /**
89
+ * 获取当前时间
90
+ * @return {*} {number}
91
+ * @memberof TimelineEngine
92
+ */
93
+ getTime(): number;
94
+ /**
95
+ * 运行: 开始时间为当前time
96
+ * @param param
97
+ * @return {boolean} {boolean}
98
+ */
99
+ play(param: {
100
+ /** 默认从头运行到尾, 优先级大于autoEnd */
101
+ toTime?: number;
102
+ /** 是否播放完后自动结束 */
103
+ autoEnd?: boolean;
104
+ }): boolean;
105
+ /**
106
+ * 暂停播放
107
+ * @memberof TimelineEngine
108
+ */
109
+ pause(): void;
110
+ /** 播放完成 */
111
+ private _end;
112
+ private _startOrStop;
113
+ /** 每帧执行 */
114
+ private _tick;
115
+ /** tick运行actions */
116
+ private _tickAction;
117
+ /** 重置active数据 */
118
+ private _dealClear;
119
+ /** 处理action time enter */
120
+ private _dealEnter;
121
+ /** 处理action time leave */
122
+ private _dealLeave;
123
+ /** 处理数据 */
124
+ private _dealData;
125
+ }
@@ -0,0 +1,77 @@
1
+ import { TimelineEngine } from "./engine";
2
+ export declare class Events {
3
+ handlers: {};
4
+ constructor(handlers?: {});
5
+ }
6
+ export interface EventTypes {
7
+ /**
8
+ * 设置时间前(手动)
9
+ * @type {{ time: number, engine: TimelineEngine }}
10
+ * @memberof EventTypes
11
+ */
12
+ beforeSetTime: {
13
+ time: number;
14
+ engine: TimelineEngine;
15
+ };
16
+ /**
17
+ * 设置时间后(手动)
18
+ * @type {{ time: number, engine: TimelineEngine }}
19
+ * @memberof EventTypes
20
+ */
21
+ afterSetTime: {
22
+ time: number;
23
+ engine: TimelineEngine;
24
+ };
25
+ /**
26
+ * tick设置时间后
27
+ * @type {{ time: number, engine: TimelineEngine }}
28
+ * @memberof EventTypes
29
+ */
30
+ setTimeByTick: {
31
+ time: number;
32
+ engine: TimelineEngine;
33
+ };
34
+ /**
35
+ * 设置运行速率前
36
+ * return false 将阻止设置速率
37
+ * @type {{ speed: number, engine: TimelineEngine }}
38
+ * @memberof EventTypes
39
+ */
40
+ beforeSetPlayRate: {
41
+ rate: number;
42
+ engine: TimelineEngine;
43
+ };
44
+ /**
45
+ * 设置运行速率后
46
+ * @type {{ speed: number, engine: TimelineEngine }}
47
+ * @memberof EventTypes
48
+ */
49
+ afterSetPlayRate: {
50
+ rate: number;
51
+ engine: TimelineEngine;
52
+ };
53
+ /**
54
+ * 运行
55
+ * @type {{engine: TimelineEngine}}
56
+ * @memberof EventTypes
57
+ */
58
+ play: {
59
+ engine: TimelineEngine;
60
+ };
61
+ /**
62
+ * 停止
63
+ * @type {{ engine: TimelineEngine }}
64
+ * @memberof EventTypes
65
+ */
66
+ paused: {
67
+ engine: TimelineEngine;
68
+ };
69
+ /**
70
+ * 运行结束
71
+ * @type {{ engine: TimelineEngine }}
72
+ * @memberof EventTypes
73
+ */
74
+ ended: {
75
+ engine: TimelineEngine;
76
+ };
77
+ }
@@ -0,0 +1,3 @@
1
+ export * from './components/timeline';
2
+ export * from './interface/timeline';
3
+ export * from './engine/engine';