1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | var __rest = (this && this.__rest) || function (s, e) {
|
27 | var t = {};
|
28 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
29 | t[p] = s[p];
|
30 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
31 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
32 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
33 | t[p[i]] = s[p[i]];
|
34 | }
|
35 | return t;
|
36 | };
|
37 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
38 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
39 | };
|
40 | Object.defineProperty(exports, "__esModule", { value: true });
|
41 | var react_1 = __importDefault(require("react"));
|
42 | var g_canvas_1 = require("@antv/g-canvas");
|
43 | var g_svg_1 = require("@antv/g-svg");
|
44 | var withContainer_1 = __importDefault(require("../boundary/withContainer"));
|
45 | var ErrorBoundary_1 = __importDefault(require("../boundary/ErrorBoundary"));
|
46 | var canvas_1 = __importDefault(require("../context/canvas"));
|
47 | var group_1 = __importDefault(require("../context/group"));
|
48 | var CanvasHelper = (function () {
|
49 | function CanvasHelper() {
|
50 | }
|
51 | CanvasHelper.prototype.createInstance = function (props) {
|
52 | var children = props.children, renderer = props.renderer, config = __rest(props, ["children", "renderer"]);
|
53 | if (renderer === 'svg') {
|
54 | this.instance = new g_svg_1.Canvas(__assign({}, config));
|
55 | }
|
56 | else {
|
57 | this.instance = new g_canvas_1.Canvas(__assign({}, config));
|
58 | }
|
59 | };
|
60 | CanvasHelper.prototype.update = function (newConfig) {
|
61 | if (!this.instance) {
|
62 | this.createInstance(newConfig);
|
63 | }
|
64 | };
|
65 | CanvasHelper.prototype.draw = function () {
|
66 | if (!this.instance) {
|
67 | return;
|
68 | }
|
69 | this.instance.draw();
|
70 | };
|
71 | CanvasHelper.prototype.destory = function () {
|
72 | if (this.instance) {
|
73 | this.instance.remove();
|
74 | this.instance = null;
|
75 | }
|
76 | };
|
77 | return CanvasHelper;
|
78 | }());
|
79 | var Canvas = (function (_super) {
|
80 | __extends(Canvas, _super);
|
81 | function Canvas(props) {
|
82 | var _this = _super.call(this, props) || this;
|
83 | _this.helper = new CanvasHelper();
|
84 | return _this;
|
85 | }
|
86 | Canvas.prototype.componentDidMount = function () {
|
87 | this.helper.draw();
|
88 | };
|
89 | Canvas.prototype.componentWillUnmount = function () {
|
90 | this.helper.destory();
|
91 | };
|
92 | Canvas.prototype.getInstance = function () {
|
93 | return this.helper.instance;
|
94 | };
|
95 | Canvas.prototype.render = function () {
|
96 | this.helper.update(this.props);
|
97 | return react_1.default.createElement(ErrorBoundary_1.default, __assign({}, this.props.ErrorBoundaryProps),
|
98 | react_1.default.createElement(canvas_1.default.Provider, { value: this.helper },
|
99 | react_1.default.createElement(group_1.default.Provider, { value: this.helper.instance },
|
100 | react_1.default.createElement(react_1.default.Fragment, null, this.props.children))));
|
101 | };
|
102 | return Canvas;
|
103 | }(react_1.default.Component));
|
104 | exports.default = withContainer_1.default(Canvas);
|
105 |
|
\ | No newline at end of file |