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.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 动作的基本参数
3
+ * @export
4
+ * @interface TimelineAction
5
+ */
6
+ export interface TimelineAction {
7
+ /** 动作id */
8
+ id: string;
9
+ /** 动作开始时间 */
10
+ start: number;
11
+ /** 动作结束时间 */
12
+ end: number;
13
+ /** 动作所对应的effectId */
14
+ effectId: string;
15
+ /** 动作是否被选中 */
16
+ selected?: boolean;
17
+ /** 动作是否可伸缩 */
18
+ flexible?: boolean;
19
+ /** 动作是否可移动 */
20
+ movable?: boolean;
21
+ /** 动作是否禁止运行 */
22
+ disable?: boolean;
23
+ /** 动作最小开始时间限制 */
24
+ minStart?: number;
25
+ /** 动作最大结束时间限制 */
26
+ maxEnd?: number;
27
+ }
28
+ /**
29
+ * 动作行基本参数
30
+ * @export
31
+ * @interface TimelineRow
32
+ */
33
+ export interface TimelineRow {
34
+ /** 动作行id */
35
+ id: string;
36
+ /** 行的动作列表 */
37
+ actions: TimelineAction[];
38
+ /** 自定义行高 */
39
+ rowHeight?: number;
40
+ /** 行是否选中 */
41
+ selected?: boolean;
42
+ /** 行的扩展类名 */
43
+ classNames?: string[];
44
+ }
@@ -0,0 +1,12 @@
1
+ import { EditData } from "./timeline";
2
+ /** 组件公共参数 */
3
+ export interface CommonProp extends EditData {
4
+ /** 刻度个数 */
5
+ scaleCount: number;
6
+ /** 设置刻度个数 */
7
+ setScaleCount: (scaleCount: number) => void;
8
+ /** 光标时间 */
9
+ cursorTime: number;
10
+ /** 当前时间轴宽度 */
11
+ timelineWidth: number;
12
+ }
@@ -0,0 +1,26 @@
1
+ export declare const PREFIX = "timeline-editor";
2
+ /** 开始时光标所在时间 */
3
+ export declare const START_CURSOR_TIME = 0;
4
+ /** 默认刻度 */
5
+ export declare const DEFAULT_SCALE = 1;
6
+ /** 默认刻度分割数量 */
7
+ export declare const DEFAULT_SCALE_SPLIT_COUNT = 10;
8
+ /** 默认刻度显示宽度 */
9
+ export declare const DEFAULT_SCALE_WIDTH = 160;
10
+ /** 默认刻度左侧开始距离 */
11
+ export declare const DEFAULT_START_LEFT = 20;
12
+ /** 默认移动最小像素 */
13
+ export declare const DEFAULT_MOVE_GRID = 1;
14
+ /** 默认吸附像素 */
15
+ export declare const DEFAULT_ADSORPTION_DISTANCE = 8;
16
+ /** 默认动作行高度 */
17
+ export declare const DEFAULT_ROW_HEIGHT = 32;
18
+ /** 最小scale数量 */
19
+ export declare const MIN_SCALE_COUNT = 20;
20
+ /** 每次新增scale个数 */
21
+ export declare const ADD_SCALE_COUNT = 5;
22
+ /** 错误信息 */
23
+ export declare const ERROR: {
24
+ START_TIME_LESS_THEN_ZERO: string;
25
+ END_TIME_LESS_THEN_START_TIME: string;
26
+ };
@@ -0,0 +1,39 @@
1
+ import { TimelineEngine } from "../engine/engine";
2
+ import { TimelineAction } from "./action";
3
+ export interface TimelineEffect {
4
+ /** 效果id */
5
+ id: string;
6
+ /** 效果名称 */
7
+ name?: string;
8
+ /** 效果运行代码 */
9
+ source?: TimeLineEffectSource;
10
+ }
11
+ export interface EffectSourceParam {
12
+ /** 当前时间 */
13
+ time: number;
14
+ /** 是否正在运行 */
15
+ isPlaying: boolean;
16
+ /** 动作 */
17
+ action: TimelineAction;
18
+ /** 动作效果 */
19
+ effect: TimelineEffect;
20
+ /** 运行引擎 */
21
+ engine: TimelineEngine;
22
+ }
23
+ /**
24
+ * 效果执行回调
25
+ * @export
26
+ * @interface TimeLineEffectSource
27
+ */
28
+ export interface TimeLineEffectSource {
29
+ /** 在当前动作时间区域开始播放时回调 */
30
+ start?: (param: EffectSourceParam) => void;
31
+ /** 时间进入动作时执行回调 */
32
+ enter?: (param: EffectSourceParam) => void;
33
+ /** 动作更新时回调 */
34
+ update?: (param: EffectSourceParam) => void;
35
+ /** 时间离开动作时执行回调 */
36
+ leave?: (param: EffectSourceParam) => void;
37
+ /** 在当前动作时间区域停止播放时回调 */
38
+ stop?: (param: EffectSourceParam) => void;
39
+ }
@@ -0,0 +1,285 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { OnScrollParams } from 'react-virtualized';
3
+ import { ITimelineEngine } from '..';
4
+ import { Emitter } from '../engine/emitter';
5
+ import { EventTypes } from '../engine/events';
6
+ import { TimelineAction, TimelineRow } from './action';
7
+ import { TimelineEffect } from './effect';
8
+ export * from './action';
9
+ export * from './effect';
10
+ export interface EditData {
11
+ /**
12
+ * @description 时间轴编辑数据
13
+ */
14
+ editorData: TimelineRow[];
15
+ /**
16
+ * @description 时间轴动作效果map
17
+ */
18
+ effects: Record<string, TimelineEffect>;
19
+ /**
20
+ * @description 单个刻度标记范畴(>0)
21
+ * @default 1
22
+ */
23
+ scale?: number;
24
+ /**
25
+ * @description 最少刻度个数(>=1)
26
+ * @default 20
27
+ */
28
+ minScaleCount?: number;
29
+ /**
30
+ * @description 最大刻度个数(>=minScaleCount)
31
+ * @default Infinity
32
+ */
33
+ maxScaleCount?: number;
34
+ /**
35
+ * @description 单个刻度细分单元数(>0整数)
36
+ * @default 10
37
+ */
38
+ scaleSplitCount?: number;
39
+ /**
40
+ * @description 单个刻度的显示宽度(>0, 单位:px)
41
+ * @default 160
42
+ */
43
+ scaleWidth?: number;
44
+ /**
45
+ * @description 刻度开始距离左侧的距离(>=0, 单位:px)
46
+ * @default 20
47
+ */
48
+ startLeft?: number;
49
+ /**
50
+ * @description 每个编辑行默认高度(>0, 单位:px)
51
+ * @default 32
52
+ */
53
+ rowHeight?: number;
54
+ /**
55
+ * @description 是否启动网格移动吸附
56
+ * @default false
57
+ */
58
+ gridSnap?: boolean;
59
+ /**
60
+ * @description 启动拖拽辅助线吸附
61
+ * @default false
62
+ */
63
+ dragLine?: boolean;
64
+ /**
65
+ * @description 是否隐藏光标
66
+ * @default false
67
+ */
68
+ hideCursor?: boolean;
69
+ /**
70
+ * @description 禁止全部动作区域拖动
71
+ * @default false
72
+ */
73
+ disableDrag?: boolean;
74
+ /**
75
+ * @description timeline运行器,不传则使用内置运行器
76
+ */
77
+ engine?: ITimelineEngine;
78
+ /**
79
+ * @description 自定义action区域渲染
80
+ */
81
+ getActionRender?: (action: TimelineAction, row: TimelineRow) => ReactNode;
82
+ /**
83
+ * @description 自定义scale渲染
84
+ */
85
+ getScaleRender?: (scale: number) => ReactNode;
86
+ /**
87
+ * @description 开始移动回调
88
+ */
89
+ onActionMoveStart?: (params: {
90
+ action: TimelineAction;
91
+ row: TimelineRow;
92
+ }) => void;
93
+ /**
94
+ * @description 移动回调(return false可阻止移动)
95
+ */
96
+ onActionMoving?: (params: {
97
+ action: TimelineAction;
98
+ row: TimelineRow;
99
+ start: number;
100
+ end: number;
101
+ }) => void | boolean;
102
+ /**
103
+ * @description 移动结束回调(return false可阻止onChange触发)
104
+ */
105
+ onActionMoveEnd?: (params: {
106
+ action: TimelineAction;
107
+ row: TimelineRow;
108
+ start: number;
109
+ end: number;
110
+ }) => void;
111
+ /**
112
+ * @description 开始改变大小回调
113
+ */
114
+ onActionResizeStart?: (params: {
115
+ action: TimelineAction;
116
+ row: TimelineRow;
117
+ dir: 'right' | 'left';
118
+ }) => void;
119
+ /**
120
+ * @description 开始大小回调(return false可阻止改变)
121
+ */
122
+ onActionResizing?: (params: {
123
+ action: TimelineAction;
124
+ row: TimelineRow;
125
+ start: number;
126
+ end: number;
127
+ dir: 'right' | 'left';
128
+ }) => void | boolean;
129
+ /**
130
+ * @description 改变大小结束回调(return false可阻止onChange触发)
131
+ */
132
+ onActionResizeEnd?: (params: {
133
+ action: TimelineAction;
134
+ row: TimelineRow;
135
+ start: number;
136
+ end: number;
137
+ dir: 'right' | 'left';
138
+ }) => void;
139
+ /**
140
+ * @description 点击行回调
141
+ */
142
+ onClickRow?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
143
+ row: TimelineRow;
144
+ time: number;
145
+ }) => void;
146
+ /**
147
+ * @description 点击动作回调
148
+ */
149
+ onClickAction?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
150
+ action: TimelineAction;
151
+ row: TimelineRow;
152
+ time: number;
153
+ }) => void;
154
+ /**
155
+ * @description 点击动作回调(触发drag时不执行)
156
+ */
157
+ onClickActionOnly?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
158
+ action: TimelineAction;
159
+ row: TimelineRow;
160
+ time: number;
161
+ }) => void;
162
+ /**
163
+ * @description 双击行回调
164
+ */
165
+ onDoubleClickRow?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
166
+ row: TimelineRow;
167
+ time: number;
168
+ }) => void;
169
+ /**
170
+ * @description 双击动作回调
171
+ */
172
+ onDoubleClickAction?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
173
+ action: TimelineAction;
174
+ row: TimelineRow;
175
+ time: number;
176
+ }) => void;
177
+ /**
178
+ * @description 右键行回调
179
+ */
180
+ onContextMenuRow?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
181
+ row: TimelineRow;
182
+ time: number;
183
+ }) => void;
184
+ /**
185
+ * @description 右键动作回调
186
+ */
187
+ onContextMenuAction?: (e: React.MouseEvent<HTMLElement, MouseEvent>, param: {
188
+ action: TimelineAction;
189
+ row: TimelineRow;
190
+ time: number;
191
+ }) => void;
192
+ /**
193
+ * @description 获取要提示辅助线的action id列表,在move/resize start 时进行计算,默认获取除当前移动action的全部
194
+ */
195
+ getAssistDragLineActionIds?: (params: {
196
+ action: TimelineAction;
197
+ editorData: TimelineRow[];
198
+ row: TimelineRow;
199
+ }) => string[];
200
+ /**
201
+ * @description cursor开始拖拽事件
202
+ */
203
+ onCursorDragStart?: (time: number) => void;
204
+ /**
205
+ * @description cursor结束拖拽事件
206
+ */
207
+ onCursorDragEnd?: (time: number) => void;
208
+ /**
209
+ * @description cursor拖拽事件
210
+ */
211
+ onCursorDrag?: (time: number) => void;
212
+ /**
213
+ * @description 点击时间区域事件, 返回false时阻止设置时间
214
+ */
215
+ onClickTimeArea?: (time: number, e: React.MouseEvent<HTMLDivElement, MouseEvent>) => boolean | undefined;
216
+ }
217
+ export interface TimelineState {
218
+ /** dom节点 */
219
+ target: HTMLElement;
220
+ /** 运行监听器 */
221
+ listener: Emitter<EventTypes>;
222
+ /** 是否正在播放 */
223
+ isPlaying: boolean;
224
+ /** 是否暂停中 */
225
+ isPaused: boolean;
226
+ /** 设置当前播放时间 */
227
+ setTime: (time: number) => void;
228
+ /** 获取当前播放时间 */
229
+ getTime: () => number;
230
+ /** 设置播放速率 */
231
+ setPlayRate: (rate: number) => void;
232
+ /** 设置播放速率 */
233
+ getPlayRate: () => number;
234
+ /** 重新渲染当前时间 */
235
+ reRender: () => void;
236
+ /** 播放 */
237
+ play: (param: {
238
+ /** 默认从头运行到尾, 优先级大于autoEnd */
239
+ toTime?: number;
240
+ /** 是否播放完后自动结束 */
241
+ autoEnd?: boolean;
242
+ /** 运行的actionId列表,不穿默认全部运行 */
243
+ runActionIds?: string[];
244
+ }) => boolean;
245
+ /** 暂停 */
246
+ pause: () => void;
247
+ /** 设置scroll left */
248
+ setScrollLeft: (val: number) => void;
249
+ /** 设置scroll top */
250
+ setScrollTop: (val: number) => void;
251
+ }
252
+ /**
253
+ * 动画编辑器参数
254
+ * @export
255
+ * @interface TimelineProp
256
+ */
257
+ export interface TimelineEditor extends EditData {
258
+ /**
259
+ * @description 编辑区域距离顶部滚动距离 (请使用ref.setScrollTop代替)
260
+ * @deprecated
261
+ */
262
+ scrollTop?: number;
263
+ /**
264
+ * @description 编辑区域滚动回调 (用于控制与编辑行滚动同步)
265
+ */
266
+ onScroll?: (params: OnScrollParams) => void;
267
+ /**
268
+ * @description 拖拽时是否启动自动滚动
269
+ * @default false
270
+ */
271
+ autoScroll?: boolean;
272
+ /**
273
+ * @description 自定义timeline样式
274
+ */
275
+ style?: React.CSSProperties;
276
+ /**
277
+ * @description 是否自动重新渲染(当数据改变或光标时间改变时update tick)
278
+ * @default true
279
+ */
280
+ autoReRender?: boolean;
281
+ /**
282
+ * @description 数据改变回调,会在操作动作end改变数据后触发(返回false会阻止自动engine同步,用于减少性能开销)
283
+ */
284
+ onChange?: (editorData: TimelineRow[]) => void | boolean;
285
+ }
@@ -0,0 +1,2 @@
1
+ import { TimelineEditor } from "../interface/timeline";
2
+ export declare function checkProps(props: TimelineEditor): TimelineEditor;
@@ -0,0 +1 @@
1
+ export declare function prefix(...classNames: string[]): string;
@@ -0,0 +1,53 @@
1
+ import { TimelineAction, TimelineRow } from "../interface/action";
2
+ /** 时间转像素 */
3
+ export declare function parserTimeToPixel(data: number, param: {
4
+ startLeft: number;
5
+ scale: number;
6
+ scaleWidth: number;
7
+ }): number;
8
+ /** 像素转时间 */
9
+ export declare function parserPixelToTime(data: number, param: {
10
+ startLeft: number;
11
+ scale: number;
12
+ scaleWidth: number;
13
+ }): number;
14
+ /** 位置 + 宽度 转 start + end */
15
+ export declare function parserTransformToTime(data: {
16
+ left: number;
17
+ width: number;
18
+ }, param: {
19
+ startLeft: number;
20
+ scale: number;
21
+ scaleWidth: number;
22
+ }): {
23
+ start: number;
24
+ end: number;
25
+ };
26
+ /** start + end 转 位置 + 宽度 */
27
+ export declare function parserTimeToTransform(data: {
28
+ start: number;
29
+ end: number;
30
+ }, param: {
31
+ startLeft: number;
32
+ scale: number;
33
+ scaleWidth: number;
34
+ }): {
35
+ left: number;
36
+ width: number;
37
+ };
38
+ /** 根据数据获取刻度个数 */
39
+ export declare function getScaleCountByRows(data: TimelineRow[], param: {
40
+ scale: number;
41
+ }): number;
42
+ /** 根据时间获取目前刻度数 */
43
+ export declare function getScaleCountByPixel(data: number, param: {
44
+ startLeft: number;
45
+ scaleWidth: number;
46
+ scaleCount: number;
47
+ }): number;
48
+ /** 获取动作全部时间的位置集合 */
49
+ export declare function parserActionsToPositions(actions: TimelineAction[], param: {
50
+ startLeft: number;
51
+ scale: number;
52
+ scaleWidth: number;
53
+ }): number[];
@@ -0,0 +1,132 @@
1
+ export declare enum LogLevel {
2
+ VERBOSE = 0,
3
+ LOG = 1,
4
+ INFO = 2,
5
+ WARN = 3,
6
+ ERROR = 4,
7
+ FATAL = 5,
8
+ SILENT = Infinity
9
+ }
10
+ export declare const LogLevels: {
11
+ VERBOSE: LogLevel;
12
+ LOG: LogLevel;
13
+ INFO: LogLevel;
14
+ WARN: LogLevel;
15
+ ERROR: LogLevel;
16
+ SILENT: LogLevel;
17
+ };
18
+ export default class ConsoleLogger {
19
+ static readonly instances: ConsoleLogger[];
20
+ static level: LogLevel;
21
+ static Levels: {
22
+ VERBOSE: LogLevel;
23
+ LOG: LogLevel;
24
+ INFO: LogLevel;
25
+ WARN: LogLevel;
26
+ ERROR: LogLevel;
27
+ SILENT: LogLevel;
28
+ };
29
+ static noColor: boolean;
30
+ Levels: {
31
+ VERBOSE: LogLevel;
32
+ LOG: LogLevel;
33
+ INFO: LogLevel;
34
+ WARN: LogLevel;
35
+ ERROR: LogLevel;
36
+ SILENT: LogLevel;
37
+ };
38
+ level: LogLevel;
39
+ prefix: string;
40
+ enabled: boolean;
41
+ debugColor: string;
42
+ logColor: string;
43
+ infoColor: string;
44
+ warnColor: string;
45
+ errorColor: string;
46
+ fatalColor: string;
47
+ /**
48
+ * ConsoleLogger
49
+ * @param {string} prefix Logger prefix
50
+ * @return {ConsoleLogger}
51
+ */
52
+ constructor(prefix: string);
53
+ static setLevel(level: LogLevel): void;
54
+ static enable(level?: LogLevel): void;
55
+ static disable(): void;
56
+ /**
57
+ * set logger prefix
58
+ * @param prefix
59
+ */
60
+ setPrefix(prefix: string): void;
61
+ /**
62
+ * enable logger with optional log level
63
+ * @param level
64
+ */
65
+ enable(level?: LogLevel): void;
66
+ /**
67
+ * disable logger
68
+ */
69
+ disable(): void;
70
+ /**
71
+ * Set log level
72
+ * @param {LogLevel} level
73
+ * @return {void}
74
+ */
75
+ setLevel(level: LogLevel): void;
76
+ /**
77
+ * trace
78
+ * @param title
79
+ * @param args
80
+ */
81
+ trace(title: string, ...args: any[]): void;
82
+ /**
83
+ * debug
84
+ * @param title
85
+ * @param args
86
+ */
87
+ debug(title: string, ...args: any[]): void;
88
+ /**
89
+ * log
90
+ * @param title
91
+ * @param args
92
+ */
93
+ log(title: string, ...args: any[]): void;
94
+ /**
95
+ * info
96
+ * @param title
97
+ * @param args
98
+ */
99
+ info(title: string, ...args: any[]): void;
100
+ /**
101
+ * warn
102
+ * @param title
103
+ * @param args
104
+ */
105
+ warn(title: string, ...args: any[]): void;
106
+ /**
107
+ * error
108
+ * @param title
109
+ * @param args
110
+ */
111
+ error(title: string, ...args: any[]): void;
112
+ /**
113
+ * fatal error
114
+ * @param title
115
+ * @param args
116
+ */
117
+ fatal(title: string, ...args: any[]): void;
118
+ /**
119
+ * start a group with label
120
+ * @param label
121
+ */
122
+ group(...label: any[]): void;
123
+ /**
124
+ * end a group
125
+ */
126
+ groupEnd(): void;
127
+ /**
128
+ * collapse log group
129
+ * @param label
130
+ */
131
+ groupCollapsed(...label: any[]): void;
132
+ }
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "sense-react-timeline-editor",
3
+ "version": "1.0.0",
4
+ "author": "xzdarcy",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "timeline",
8
+ "animation",
9
+ "editor",
10
+ "react",
11
+ "typescript"
12
+ ],
13
+ "bugs": {
14
+ "url": "https://github.com/xzdarcy/react-timeline-editor/issues"
15
+ },
16
+ "homepage": "https://github.com/xzdarcy/react-timeline-editor#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/xzdarcy/react-timeline-editor.git"
20
+ },
21
+ "scripts": {
22
+ "start": "NODE_OPTIONS=--openssl-legacy-provider dumi dev",
23
+ "docs:build": "dumi build",
24
+ "docs:deploy": "",
25
+ "build": "father-build",
26
+ "deploy": "npm run docs:build && npm run docs:deploy",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "main": "dist/index.js",
33
+ "module": "dist/index.esm.js",
34
+ "typings": "dist/index.d.ts",
35
+ "peerDependencies": {
36
+ "react": "^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0 || ^19.0.0",
37
+ "react-dom": "^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0 || ^19.0.0"
38
+ },
39
+ "dependencies": {
40
+ "@interactjs/types": "^1.10.11",
41
+ "@types/react-virtualized": "^9.21.14",
42
+ "framework-utils": "^1.1.0",
43
+ "interactjs": "^1.10.11",
44
+ "react-virtualized": "^9.22.3"
45
+ },
46
+ "devDependencies": {
47
+ "@types/howler": "^2.2.4",
48
+ "@types/lodash": "^4.14.177",
49
+ "@types/react": "^17.0.17",
50
+ "@types/react-dom": "^17.0.17",
51
+ "@umijs/test": "^3.0.5",
52
+ "antd": "^4.16.13",
53
+ "dumi": "^1.0.17",
54
+ "father-build": "^1.17.2",
55
+ "gh-pages": "^3.0.0",
56
+ "howler": "^2.2.3",
57
+ "lint-staged": "^10.0.7",
58
+ "lodash": "^4.17.21",
59
+ "lottie-web": "^5.8.1",
60
+ "prettier": "^2.2.1",
61
+ "react": "^17.0.0",
62
+ "react-dom": "^17.0.0",
63
+ "typescript": "^4.8.4",
64
+ "yorkie": "^2.0.0"
65
+ }
66
+ }