1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.SplitPositionHandler = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const widgets_1 = require("@phosphor/widgets");
|
22 | let SplitPositionHandler = class SplitPositionHandler {
|
23 | constructor() {
|
24 | this.splitMoves = [];
|
25 | this.currentMoveIndex = 0;
|
26 | }
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 | setSplitHandlePosition(parent, index, targetPosition, options) {
|
33 | const move = {
|
34 | ...options,
|
35 | parent, targetPosition, index,
|
36 | started: false,
|
37 | ended: false
|
38 | };
|
39 | return this.moveSplitPos(move);
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 | setSidePanelSize(sidePanel, targetSize, options) {
|
47 | if (targetSize < 0) {
|
48 | return Promise.reject(new Error('Cannot resize to negative value.'));
|
49 | }
|
50 | const parent = sidePanel.parent;
|
51 | if (!(parent instanceof widgets_1.SplitPanel)) {
|
52 | return Promise.reject(new Error('Widget must be contained in a SplitPanel.'));
|
53 | }
|
54 | let index = parent.widgets.indexOf(sidePanel);
|
55 | if (index > 0 && (options.side === 'right' || options.side === 'bottom')) {
|
56 | index--;
|
57 | }
|
58 | const move = {
|
59 | ...options,
|
60 | parent, targetSize, index,
|
61 | started: false,
|
62 | ended: false
|
63 | };
|
64 | return this.moveSplitPos(move);
|
65 | }
|
66 | moveSplitPos(move) {
|
67 | return new Promise((resolve, reject) => {
|
68 | move.resolve = resolve;
|
69 | move.reject = reject;
|
70 | if (this.splitMoves.length === 0) {
|
71 | window.requestAnimationFrame(this.animationFrame.bind(this));
|
72 | }
|
73 | this.splitMoves.push(move);
|
74 | });
|
75 | }
|
76 | animationFrame(time) {
|
77 | const move = this.splitMoves[this.currentMoveIndex];
|
78 | let rejectedOrResolved = false;
|
79 | if (move.ended || move.referenceWidget && move.referenceWidget.isHidden) {
|
80 | this.splitMoves.splice(this.currentMoveIndex, 1);
|
81 | if (move.startPosition === undefined || move.targetPosition === undefined) {
|
82 | move.reject('Panel is not visible.');
|
83 | }
|
84 | else {
|
85 | move.resolve(move.targetPosition);
|
86 | }
|
87 | rejectedOrResolved = true;
|
88 | }
|
89 | else if (!move.started) {
|
90 | this.startMove(move, time);
|
91 | if (move.duration <= 0 || move.startPosition === undefined || move.targetPosition === undefined
|
92 | || move.startPosition === move.targetPosition) {
|
93 | this.endMove(move);
|
94 | }
|
95 | }
|
96 | else {
|
97 | const elapsedTime = time - move.startTime;
|
98 | if (elapsedTime >= move.duration) {
|
99 | this.endMove(move);
|
100 | }
|
101 | else {
|
102 | const t = elapsedTime / move.duration;
|
103 | const start = move.startPosition || 0;
|
104 | const target = move.targetPosition || 0;
|
105 | const pos = start + (target - start) * t;
|
106 | move.parent.layout.moveHandle(move.index, pos);
|
107 | }
|
108 | }
|
109 | if (!rejectedOrResolved) {
|
110 | this.currentMoveIndex++;
|
111 | }
|
112 | if (this.currentMoveIndex >= this.splitMoves.length) {
|
113 | this.currentMoveIndex = 0;
|
114 | }
|
115 | if (this.splitMoves.length > 0) {
|
116 | window.requestAnimationFrame(this.animationFrame.bind(this));
|
117 | }
|
118 | }
|
119 | startMove(move, time) {
|
120 | if (move.targetPosition === undefined && move.targetSize !== undefined) {
|
121 | const { clientWidth, clientHeight } = move.parent.node;
|
122 | if (clientWidth && clientHeight) {
|
123 | switch (move.side) {
|
124 | case 'left':
|
125 | move.targetPosition = Math.max(Math.min(move.targetSize, clientWidth), 0);
|
126 | break;
|
127 | case 'right':
|
128 | move.targetPosition = Math.max(Math.min(clientWidth - move.targetSize, clientWidth), 0);
|
129 | break;
|
130 | case 'top':
|
131 | move.targetPosition = Math.max(Math.min(move.targetSize, clientHeight), 0);
|
132 | break;
|
133 | case 'bottom':
|
134 | move.targetPosition = Math.max(Math.min(clientHeight - move.targetSize, clientHeight), 0);
|
135 | break;
|
136 | }
|
137 | }
|
138 | }
|
139 | if (move.startPosition === undefined) {
|
140 | move.startPosition = this.getCurrentPosition(move);
|
141 | }
|
142 | move.startTime = time;
|
143 | move.started = true;
|
144 | }
|
145 | endMove(move) {
|
146 | if (move.targetPosition !== undefined) {
|
147 | move.parent.layout.moveHandle(move.index, move.targetPosition);
|
148 | }
|
149 | move.ended = true;
|
150 | }
|
151 | getCurrentPosition(move) {
|
152 | const layout = move.parent.layout;
|
153 | let pos;
|
154 | if (layout.orientation === 'horizontal') {
|
155 | pos = layout.handles[move.index].offsetLeft;
|
156 | }
|
157 | else {
|
158 | pos = layout.handles[move.index].offsetTop;
|
159 | }
|
160 |
|
161 | if (pos !== null) {
|
162 | return pos;
|
163 | }
|
164 | else {
|
165 | return undefined;
|
166 | }
|
167 | }
|
168 | };
|
169 | SplitPositionHandler = (0, tslib_1.__decorate)([
|
170 | (0, inversify_1.injectable)()
|
171 | ], SplitPositionHandler);
|
172 | exports.SplitPositionHandler = SplitPositionHandler;
|
173 |
|
\ | No newline at end of file |