-
Notifications
You must be signed in to change notification settings - Fork 20
/
Paper.types.js
67 lines (59 loc) · 1.6 KB
/
Paper.types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// @flow
import * as React from 'react';
import Paper from 'paper';
export type Types = {
[type: string]: (props: {}, paper: typeof Paper.PaperScope, children?: Node) => Object
};
export type Components = {
[key: string]: React.AbstractComponent<any>
};
const PAPER = {
Tool: 'Tool',
Layer: 'Layer',
Group: 'Group',
Path: 'Path',
Line: 'Line',
Raster: 'Raster',
Rectangle: 'Rectangle',
Circle: 'Circle',
PointText: 'PointText',
};
export const CONSTANTS = {
PaperScope: 'PaperScope',
...PAPER,
};
const TYPES: Types = {
[CONSTANTS.PaperScope]: (props, paper) => new paper.PaperScope(),
[CONSTANTS.Tool]: (props, paper) => new paper.Tool(props),
[CONSTANTS.Layer]: (props, paper) => new paper.Layer(props),
[CONSTANTS.Group]: (props, paper) => new paper.Group(props),
[CONSTANTS.Path]: (props, paper) => new paper.Path(props),
[CONSTANTS.Raster]: (props, paper) => new paper.Raster(props),
[CONSTANTS.Line]: (props, paper) => new paper.Path.Line(props),
[CONSTANTS.Rectangle]: (props, paper) => new paper.Path.Rectangle(props),
[CONSTANTS.Circle]: (props, paper) => new paper.Path.Circle(props),
[CONSTANTS.PointText]: (props, paper, children) => new paper.PointText({
...props,
content: children,
}),
};
export default TYPES;
export const components: Components = Object.entries(PAPER).reduce(
(types: Components, [key, Type]) => ({
...types,
// $FlowFixMe
[key]: React.forwardRef((props, ref) => <Type ref={ref} {...props} />),
}),
{},
);
export const {
Tool,
Layer,
Group,
Path,
Line,
Raster,
Rectangle,
Circle,
PointText,
} = components;