@idraw/core 0.4.0-beta.29 → 0.4.0-beta.30
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/dist/esm/middleware/layout-selector/config.d.ts +4 -1
- package/dist/esm/middleware/layout-selector/config.js +4 -1
- package/dist/esm/middleware/layout-selector/index.d.ts +2 -0
- package/dist/esm/middleware/layout-selector/index.js +176 -95
- package/dist/esm/middleware/layout-selector/types.d.ts +7 -4
- package/dist/esm/middleware/layout-selector/types.js +2 -2
- package/dist/esm/middleware/layout-selector/util.d.ts +4 -1
- package/dist/esm/middleware/layout-selector/util.js +15 -0
- package/dist/esm/middleware/scroller/config.d.ts +2 -0
- package/dist/esm/middleware/scroller/config.js +2 -0
- package/dist/esm/middleware/scroller/index.js +29 -2
- package/dist/esm/middleware/scroller/types.d.ts +3 -1
- package/dist/esm/middleware/scroller/types.js +1 -1
- package/dist/esm/middleware/scroller/util.js +14 -9
- package/dist/esm/middleware/selector/index.d.ts +2 -2
- package/dist/esm/middleware/selector/index.js +6 -1
- package/dist/esm/middleware/selector/types.d.ts +2 -0
- package/dist/esm/middleware/selector/types.js +1 -0
- package/dist/esm/middleware/text-editor/index.js +2 -1
- package/dist/index.global.js +661 -520
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -2,5 +2,8 @@ export declare const key = "LAYOUT_SELECT";
|
|
|
2
2
|
export declare const keyLayoutActionType: unique symbol;
|
|
3
3
|
export declare const keyLayoutControlType: unique symbol;
|
|
4
4
|
export declare const keyLayoutController: unique symbol;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const keyLayoutIsHover: unique symbol;
|
|
6
|
+
export declare const keyLayoutIsSelected: unique symbol;
|
|
7
|
+
export declare const selectColor = "#b331c9";
|
|
6
8
|
export declare const disableColor = "#5b5959b5";
|
|
9
|
+
export declare const controllerSize = 10;
|
|
@@ -2,5 +2,8 @@ export const key = 'LAYOUT_SELECT';
|
|
|
2
2
|
export const keyLayoutActionType = Symbol(`${key}_layoutActionType`);
|
|
3
3
|
export const keyLayoutControlType = Symbol(`${key}_layoutControlType`);
|
|
4
4
|
export const keyLayoutController = Symbol(`${key}_layoutController`);
|
|
5
|
-
export const
|
|
5
|
+
export const keyLayoutIsHover = Symbol(`${key}_layoutIsHover`);
|
|
6
|
+
export const keyLayoutIsSelected = Symbol(`${key}_layoutIsSelected`);
|
|
7
|
+
export const selectColor = '#b331c9';
|
|
6
8
|
export const disableColor = '#5b5959b5';
|
|
9
|
+
export const controllerSize = 10;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { BoardMiddleware } from '@idraw/types';
|
|
2
2
|
import type { LayoutSelectorSharedStorage } from './types';
|
|
3
|
+
import { keyLayoutIsSelected } from './config';
|
|
4
|
+
export { keyLayoutIsSelected };
|
|
3
5
|
export declare const MiddlewareLayoutSelector: BoardMiddleware<LayoutSelectorSharedStorage>;
|
|
@@ -1,54 +1,40 @@
|
|
|
1
|
-
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot } from '@idraw/util';
|
|
2
|
-
import { keyLayoutActionType, keyLayoutController, keyLayoutControlType } from './config';
|
|
3
|
-
import { keyActionType as keyElementActionType, middlewareEventSelectClear } from '../selector';
|
|
4
|
-
import { drawLayoutController } from './util';
|
|
1
|
+
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot, isViewPointInElementSize, calcViewElementSize } from '@idraw/util';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutController, keyLayoutControlType, keyLayoutIsHover, keyLayoutIsSelected, controllerSize } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType, keyHoverElement, middlewareEventSelectClear } from '../selector';
|
|
4
|
+
import { drawLayoutController, drawLayoutHover } from './util';
|
|
5
5
|
import { eventChange } from '../../config';
|
|
6
|
+
export { keyLayoutIsSelected };
|
|
6
7
|
export const MiddlewareLayoutSelector = (opts) => {
|
|
7
8
|
const { sharer, boardContent, calculator, viewer, eventHub } = opts;
|
|
8
9
|
const { overlayContext } = boardContent;
|
|
9
10
|
let prevPoint = null;
|
|
11
|
+
let prevIsHover = null;
|
|
12
|
+
let prevIsSelected = null;
|
|
13
|
+
let isBusy = null;
|
|
10
14
|
const clear = () => {
|
|
11
15
|
prevPoint = null;
|
|
12
16
|
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
13
17
|
sharer.setSharedStorage(keyLayoutControlType, null);
|
|
14
18
|
sharer.setSharedStorage(keyLayoutController, null);
|
|
19
|
+
sharer.setSharedStorage(keyLayoutIsHover, null);
|
|
20
|
+
sharer.setSharedStorage(keyLayoutIsSelected, null);
|
|
21
|
+
prevIsHover = null;
|
|
22
|
+
prevIsSelected = null;
|
|
23
|
+
isBusy = null;
|
|
15
24
|
};
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
25
|
+
const isInElementHover = () => {
|
|
26
|
+
const hoverElement = sharer.getSharedStorage(keyHoverElement);
|
|
27
|
+
if (hoverElement) {
|
|
28
|
+
clear();
|
|
19
29
|
return true;
|
|
20
30
|
}
|
|
21
31
|
return false;
|
|
22
32
|
};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (controlType === 'left' && operations.disabledLeft === true) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
if (controlType === 'top' && operations.disabledTop === true) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
if (controlType === 'right' && operations.disabledRight === true) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
if (controlType === 'bottom' && operations.disabledBottom === true) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
if (controlType === 'top-left' && operations.disabledTopLeft === true) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
if (controlType === 'top-right' && operations.disabledTopRight === true) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
if (controlType === 'bottom-left' && operations.disabledBottomLeft === true) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
if (controlType === 'bottom-right' && operations.disabledBottomRight === true) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
33
|
+
const isInElementAction = () => {
|
|
34
|
+
const elementActionType = sharer.getSharedStorage(keyElementActionType);
|
|
35
|
+
if (elementActionType && elementActionType !== 'area') {
|
|
36
|
+
clear();
|
|
37
|
+
return true;
|
|
52
38
|
}
|
|
53
39
|
return false;
|
|
54
40
|
};
|
|
@@ -60,6 +46,21 @@ export const MiddlewareLayoutSelector = (opts) => {
|
|
|
60
46
|
}
|
|
61
47
|
return null;
|
|
62
48
|
};
|
|
49
|
+
const isInLayout = (p) => {
|
|
50
|
+
const size = getLayoutSize();
|
|
51
|
+
if (size) {
|
|
52
|
+
const { x, y, w, h } = size;
|
|
53
|
+
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
54
|
+
const viewSize = calcViewElementSize({
|
|
55
|
+
x: x - controllerSize / 2,
|
|
56
|
+
y: y - controllerSize / 2,
|
|
57
|
+
w: w + controllerSize,
|
|
58
|
+
h: h + controllerSize
|
|
59
|
+
}, { viewScaleInfo });
|
|
60
|
+
return isViewPointInElementSize(p, viewSize);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
63
64
|
const resetController = () => {
|
|
64
65
|
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
65
66
|
const size = getLayoutSize();
|
|
@@ -95,6 +96,16 @@ export const MiddlewareLayoutSelector = (opts) => {
|
|
|
95
96
|
}
|
|
96
97
|
return null;
|
|
97
98
|
};
|
|
99
|
+
const updateCursor = (controlType) => {
|
|
100
|
+
if (isBusy === true) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
eventHub.trigger('cursor', {
|
|
104
|
+
type: controlType ? `resize-${controlType}` : controlType,
|
|
105
|
+
groupQueue: [],
|
|
106
|
+
element: getLayoutSize()
|
|
107
|
+
});
|
|
108
|
+
};
|
|
98
109
|
return {
|
|
99
110
|
name: '@middleware/layout-selector',
|
|
100
111
|
use: () => {
|
|
@@ -102,74 +113,105 @@ export const MiddlewareLayoutSelector = (opts) => {
|
|
|
102
113
|
resetController();
|
|
103
114
|
},
|
|
104
115
|
hover: (e) => {
|
|
116
|
+
if (isBusy === true) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
105
119
|
if (isInElementAction()) {
|
|
106
120
|
return;
|
|
107
121
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
type: `resize-${layoutControlType}`,
|
|
118
|
-
groupQueue: [],
|
|
119
|
-
element: getLayoutSize()
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
+
if (isInElementHover()) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (isInLayout(e.point)) {
|
|
126
|
+
sharer.setSharedStorage(keyLayoutIsHover, true);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
sharer.setSharedStorage(keyLayoutIsHover, false);
|
|
130
|
+
if (prevIsHover === true) {
|
|
122
131
|
viewer.drawFrame();
|
|
123
|
-
|
|
124
|
-
else {
|
|
125
|
-
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
132
|
+
prevIsHover = false;
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
|
-
if (
|
|
129
|
-
|
|
135
|
+
if (sharer.getSharedStorage(keyLayoutIsSelected) === true) {
|
|
136
|
+
const prevLayoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
137
|
+
const data = sharer.getActiveStorage('data');
|
|
138
|
+
if (data === null || data === void 0 ? void 0 : data.layout) {
|
|
139
|
+
if (prevLayoutActionType !== 'resize') {
|
|
140
|
+
resetController();
|
|
141
|
+
const layoutControlType = resetControlType(e);
|
|
142
|
+
if (layoutControlType) {
|
|
143
|
+
updateCursor(layoutControlType);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
updateCursor();
|
|
147
|
+
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const layoutControlType = resetControlType(e);
|
|
152
|
+
updateCursor(layoutControlType);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
130
156
|
}
|
|
131
|
-
if (
|
|
157
|
+
if (sharer.getSharedStorage(keyLayoutIsHover) && !prevIsHover) {
|
|
132
158
|
viewer.drawFrame();
|
|
133
159
|
}
|
|
160
|
+
prevIsHover = sharer.getSharedStorage(keyLayoutIsHover);
|
|
134
161
|
},
|
|
135
162
|
pointStart: (e) => {
|
|
136
163
|
if (isInElementAction()) {
|
|
137
164
|
return;
|
|
138
165
|
}
|
|
166
|
+
if (isInLayout(e.point)) {
|
|
167
|
+
sharer.setSharedStorage(keyLayoutIsSelected, true);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
if (prevIsSelected === true) {
|
|
171
|
+
clear();
|
|
172
|
+
viewer.drawFrame();
|
|
173
|
+
}
|
|
174
|
+
sharer.setSharedStorage(keyLayoutIsSelected, false);
|
|
175
|
+
}
|
|
139
176
|
resetController();
|
|
140
177
|
const layoutControlType = resetControlType(e);
|
|
141
178
|
prevPoint = e.point;
|
|
142
179
|
if (layoutControlType) {
|
|
143
|
-
if (isDisbaledControl(layoutControlType)) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
180
|
sharer.setSharedStorage(keyLayoutActionType, 'resize');
|
|
147
|
-
return false;
|
|
148
181
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return false;
|
|
182
|
+
if (sharer.getSharedStorage(keyLayoutIsSelected) === true && !prevIsSelected) {
|
|
183
|
+
viewer.drawFrame();
|
|
152
184
|
}
|
|
185
|
+
prevIsSelected = sharer.getSharedStorage(keyLayoutIsSelected);
|
|
153
186
|
},
|
|
154
187
|
pointMove: (e) => {
|
|
155
|
-
if (
|
|
156
|
-
|
|
188
|
+
if (!sharer.getSharedStorage(keyLayoutIsSelected)) {
|
|
189
|
+
if (isInElementAction()) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
157
192
|
}
|
|
158
193
|
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
159
194
|
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
160
195
|
const data = sharer.getActiveStorage('data');
|
|
161
|
-
if (layoutControlType && isDisbaledControl(layoutControlType)) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
196
|
if (layoutActionType === 'resize' && layoutControlType && (data === null || data === void 0 ? void 0 : data.layout)) {
|
|
165
197
|
if (prevPoint) {
|
|
198
|
+
isBusy = true;
|
|
166
199
|
const scale = sharer.getActiveStorage('scale');
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
200
|
+
const viewMoveX = e.point.x - prevPoint.x;
|
|
201
|
+
const viewMoveY = e.point.y - prevPoint.y;
|
|
202
|
+
const moveX = viewMoveX / scale;
|
|
203
|
+
const moveY = viewMoveY / scale;
|
|
204
|
+
const { x, y, w, h, operations = {} } = data.layout;
|
|
205
|
+
const { position = 'absolute' } = operations;
|
|
170
206
|
if (layoutControlType === 'top') {
|
|
171
|
-
|
|
172
|
-
|
|
207
|
+
if (position === 'relative') {
|
|
208
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
209
|
+
viewer.scroll({ moveY: viewMoveY });
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
213
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
214
|
+
}
|
|
173
215
|
}
|
|
174
216
|
else if (layoutControlType === 'right') {
|
|
175
217
|
data.layout.w = calculator.toGridNum(w + moveX);
|
|
@@ -178,28 +220,59 @@ export const MiddlewareLayoutSelector = (opts) => {
|
|
|
178
220
|
data.layout.h = calculator.toGridNum(h + moveY);
|
|
179
221
|
}
|
|
180
222
|
else if (layoutControlType === 'left') {
|
|
181
|
-
|
|
182
|
-
|
|
223
|
+
if (position === 'relative') {
|
|
224
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
225
|
+
viewer.scroll({ moveX: viewMoveX });
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
229
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
230
|
+
}
|
|
183
231
|
}
|
|
184
232
|
else if (layoutControlType === 'top-left') {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
233
|
+
if (position === 'relative') {
|
|
234
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
235
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
236
|
+
viewer.scroll({ moveX: viewMoveX, moveY: viewMoveY });
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
240
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
241
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
242
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
243
|
+
}
|
|
189
244
|
}
|
|
190
245
|
else if (layoutControlType === 'top-right') {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
246
|
+
if (position === 'relative') {
|
|
247
|
+
viewer.scroll({
|
|
248
|
+
moveY: viewMoveY
|
|
249
|
+
});
|
|
250
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
251
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
255
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
256
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
257
|
+
}
|
|
194
258
|
}
|
|
195
259
|
else if (layoutControlType === 'bottom-right') {
|
|
196
260
|
data.layout.w = calculator.toGridNum(w + moveX);
|
|
197
261
|
data.layout.h = calculator.toGridNum(h + moveY);
|
|
198
262
|
}
|
|
199
263
|
else if (layoutControlType === 'bottom-left') {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
264
|
+
if (position === 'relative') {
|
|
265
|
+
viewer.scroll({
|
|
266
|
+
moveX: viewMoveX
|
|
267
|
+
});
|
|
268
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
269
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
273
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
274
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
275
|
+
}
|
|
203
276
|
}
|
|
204
277
|
}
|
|
205
278
|
prevPoint = e.point;
|
|
@@ -207,33 +280,41 @@ export const MiddlewareLayoutSelector = (opts) => {
|
|
|
207
280
|
viewer.drawFrame();
|
|
208
281
|
return false;
|
|
209
282
|
}
|
|
210
|
-
if (['
|
|
283
|
+
if (['resize'].includes(layoutActionType)) {
|
|
211
284
|
return false;
|
|
212
285
|
}
|
|
213
286
|
},
|
|
214
287
|
pointEnd: () => {
|
|
288
|
+
isBusy = false;
|
|
215
289
|
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
216
290
|
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
217
291
|
const data = sharer.getActiveStorage('data');
|
|
218
|
-
if (data && layoutActionType === 'resize' && layoutControlType
|
|
292
|
+
if (data && layoutActionType === 'resize' && layoutControlType) {
|
|
219
293
|
eventHub.trigger(eventChange, {
|
|
220
294
|
type: 'changeLayout',
|
|
221
295
|
data
|
|
222
296
|
});
|
|
223
297
|
}
|
|
224
|
-
clear();
|
|
225
298
|
},
|
|
226
299
|
beforeDrawFrame: ({ snapshot }) => {
|
|
227
300
|
var _a;
|
|
301
|
+
if (isInElementAction()) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
228
304
|
const { sharedStore, activeStore } = snapshot;
|
|
229
305
|
const layoutActionType = sharedStore[keyLayoutActionType];
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
306
|
+
const layoutIsHover = sharedStore[keyLayoutIsHover];
|
|
307
|
+
const layoutIsSelected = sharedStore[keyLayoutIsSelected];
|
|
308
|
+
if ((_a = activeStore.data) === null || _a === void 0 ? void 0 : _a.layout) {
|
|
309
|
+
const { x, y, w, h } = activeStore.data.layout;
|
|
310
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
311
|
+
const size = { x, y, w, h };
|
|
312
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize });
|
|
313
|
+
if (layoutIsHover === true) {
|
|
314
|
+
const viewSize = calcViewElementSize(size, { viewScaleInfo });
|
|
315
|
+
drawLayoutHover(overlayContext, { layoutSize: viewSize });
|
|
316
|
+
}
|
|
317
|
+
if ((layoutActionType && ['resize'].includes(layoutActionType)) || layoutIsSelected === true) {
|
|
237
318
|
drawLayoutController(overlayContext, { controller, operations: activeStore.data.layout.operations || {} });
|
|
238
319
|
}
|
|
239
320
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import type { LayoutSizeController } from '@idraw/types';
|
|
2
|
-
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController } from './config';
|
|
3
|
-
import { keyActionType as keyElementActionType } from '../selector';
|
|
1
|
+
import type { LayoutSizeController, Element } from '@idraw/types';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHover, keyLayoutIsSelected } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType, keyHoverElement } from '../selector';
|
|
4
4
|
import type { ActionType as ElementActionType } from '../selector';
|
|
5
|
-
export type ActionType = '
|
|
5
|
+
export type ActionType = 'resize' | null;
|
|
6
6
|
export type ControlType = 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
7
7
|
export type LayoutSelectorSharedStorage = {
|
|
8
8
|
[keyLayoutActionType]: ActionType | null;
|
|
9
9
|
[keyLayoutControlType]: ControlType | null;
|
|
10
10
|
[keyLayoutController]: LayoutSizeController | null;
|
|
11
11
|
[keyElementActionType]: ElementActionType | null;
|
|
12
|
+
[keyHoverElement]: Element | null;
|
|
13
|
+
[keyLayoutIsHover]: boolean | null;
|
|
14
|
+
[keyLayoutIsSelected]: boolean | null;
|
|
12
15
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController } from './config';
|
|
2
|
-
import { keyActionType as keyElementActionType } from '../selector';
|
|
1
|
+
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHover, keyLayoutIsSelected } from './config';
|
|
2
|
+
import { keyActionType as keyElementActionType, keyHoverElement } from '../selector';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { ViewContext2D, LayoutSizeController, DataLayout } from '@idraw/types';
|
|
1
|
+
import type { ViewContext2D, LayoutSizeController, DataLayout, ElementSize } from '@idraw/types';
|
|
2
2
|
export declare function drawLayoutController(ctx: ViewContext2D, opts: {
|
|
3
3
|
controller: LayoutSizeController;
|
|
4
4
|
operations: DataLayout['operations'];
|
|
5
5
|
}): void;
|
|
6
|
+
export declare function drawLayoutHover(ctx: ViewContext2D, opts: {
|
|
7
|
+
layoutSize: ElementSize;
|
|
8
|
+
}): void;
|
|
@@ -91,3 +91,18 @@ export function drawLayoutController(ctx, opts) {
|
|
|
91
91
|
drawControllerBox(ctx, bottomLeft.vertexes);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
export function drawLayoutHover(ctx, opts) {
|
|
95
|
+
const { layoutSize } = opts;
|
|
96
|
+
const { x, y, w, h } = layoutSize;
|
|
97
|
+
ctx.setLineDash([]);
|
|
98
|
+
ctx.strokeStyle = selectColor;
|
|
99
|
+
ctx.lineWidth = 1;
|
|
100
|
+
ctx.beginPath();
|
|
101
|
+
ctx.moveTo(x, y);
|
|
102
|
+
ctx.lineTo(x + w, y);
|
|
103
|
+
ctx.lineTo(x + w, y + h);
|
|
104
|
+
ctx.lineTo(x, y + h);
|
|
105
|
+
ctx.lineTo(x, y);
|
|
106
|
+
ctx.closePath();
|
|
107
|
+
ctx.stroke();
|
|
108
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const key = "SCROLL";
|
|
2
2
|
export declare const keyXThumbRect: unique symbol;
|
|
3
3
|
export declare const keyYThumbRect: unique symbol;
|
|
4
|
+
export declare const keyHoverXThumbRect: unique symbol;
|
|
5
|
+
export declare const keyHoverYThumbRect: unique symbol;
|
|
4
6
|
export declare const keyPrevPoint: unique symbol;
|
|
5
7
|
export declare const keyActivePoint: unique symbol;
|
|
6
8
|
export declare const keyActiveThumbType: unique symbol;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const key = 'SCROLL';
|
|
2
2
|
export const keyXThumbRect = Symbol(`${key}_xThumbRect`);
|
|
3
3
|
export const keyYThumbRect = Symbol(`${key}_yThumbRect`);
|
|
4
|
+
export const keyHoverXThumbRect = Symbol(`${key}_hoverXThumbRect`);
|
|
5
|
+
export const keyHoverYThumbRect = Symbol(`${key}_hoverYThumbRect`);
|
|
4
6
|
export const keyPrevPoint = Symbol(`${key}_prevPoint`);
|
|
5
7
|
export const keyActivePoint = Symbol(`${key}_activePoint`);
|
|
6
8
|
export const keyActiveThumbType = Symbol(`${key}_activeThumbType`);
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { drawScroller, isPointInScrollThumb } from './util';
|
|
2
|
-
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
2
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
3
3
|
export const MiddlewareScroller = (opts) => {
|
|
4
|
-
const { viewer, boardContent, sharer } = opts;
|
|
4
|
+
const { viewer, boardContent, sharer, eventHub } = opts;
|
|
5
5
|
const { overlayContext } = boardContent;
|
|
6
6
|
sharer.setSharedStorage(keyXThumbRect, null);
|
|
7
7
|
sharer.setSharedStorage(keyYThumbRect, null);
|
|
8
|
+
let isBusy = false;
|
|
8
9
|
const clear = () => {
|
|
9
10
|
sharer.setSharedStorage(keyPrevPoint, null);
|
|
10
11
|
sharer.setSharedStorage(keyActivePoint, null);
|
|
11
12
|
sharer.setSharedStorage(keyActiveThumbType, null);
|
|
13
|
+
sharer.setSharedStorage(keyHoverXThumbRect, null);
|
|
14
|
+
sharer.setSharedStorage(keyHoverYThumbRect, null);
|
|
15
|
+
isBusy = false;
|
|
12
16
|
};
|
|
13
17
|
clear();
|
|
14
18
|
const scrollX = (p) => {
|
|
@@ -50,10 +54,32 @@ export const MiddlewareScroller = (opts) => {
|
|
|
50
54
|
});
|
|
51
55
|
viewer.drawFrame();
|
|
52
56
|
},
|
|
57
|
+
hover: (e) => {
|
|
58
|
+
if (isBusy === true) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const { point } = e;
|
|
62
|
+
const thumbType = getThumbType(point);
|
|
63
|
+
if (thumbType === 'X' || thumbType === 'Y') {
|
|
64
|
+
if (thumbType === 'X') {
|
|
65
|
+
sharer.setSharedStorage(keyHoverXThumbRect, true);
|
|
66
|
+
sharer.setSharedStorage(keyHoverYThumbRect, false);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
sharer.setSharedStorage(keyHoverXThumbRect, false);
|
|
70
|
+
sharer.setSharedStorage(keyHoverYThumbRect, true);
|
|
71
|
+
}
|
|
72
|
+
eventHub.trigger('cursor', { type: 'default' });
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
sharer.setSharedStorage(keyHoverXThumbRect, false);
|
|
76
|
+
sharer.setSharedStorage(keyHoverYThumbRect, false);
|
|
77
|
+
},
|
|
53
78
|
pointStart: (e) => {
|
|
54
79
|
const { point } = e;
|
|
55
80
|
const thumbType = getThumbType(point);
|
|
56
81
|
if (thumbType === 'X' || thumbType === 'Y') {
|
|
82
|
+
isBusy = true;
|
|
57
83
|
sharer.setSharedStorage(keyActiveThumbType, thumbType);
|
|
58
84
|
sharer.setSharedStorage(keyPrevPoint, point);
|
|
59
85
|
return false;
|
|
@@ -75,6 +101,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
75
101
|
}
|
|
76
102
|
},
|
|
77
103
|
pointEnd: () => {
|
|
104
|
+
isBusy = false;
|
|
78
105
|
const activeThumbType = sharer.getSharedStorage(keyActiveThumbType);
|
|
79
106
|
clear();
|
|
80
107
|
if (activeThumbType === 'X' || activeThumbType === 'Y') {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Point, ElementSize } from '@idraw/types';
|
|
2
|
-
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
2
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
3
3
|
export type DeepScrollerSharedStorage = {
|
|
4
4
|
[keyXThumbRect]: null | ElementSize;
|
|
5
5
|
[keyYThumbRect]: null | ElementSize;
|
|
6
|
+
[keyHoverXThumbRect]: boolean | null;
|
|
7
|
+
[keyHoverYThumbRect]: boolean | null;
|
|
6
8
|
[keyPrevPoint]: null | Point;
|
|
7
9
|
[keyActivePoint]: null | Point;
|
|
8
10
|
[keyActiveThumbType]: null | 'X' | 'Y';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
1
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
-
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect } from './config';
|
|
2
|
+
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
3
3
|
const minScrollerWidth = 12;
|
|
4
4
|
const scrollerLineWidth = 16;
|
|
5
5
|
const scrollerThumbAlpha = 0.3;
|
|
6
6
|
const scrollConfig = {
|
|
7
7
|
width: minScrollerWidth,
|
|
8
|
-
thumbColor: '#
|
|
8
|
+
thumbColor: '#0000008A',
|
|
9
|
+
thumbHoverColor: '#000000EE',
|
|
9
10
|
scrollBarColor: '#FFFFFF60',
|
|
10
11
|
showScrollBar: false
|
|
11
12
|
};
|
|
@@ -38,11 +39,14 @@ function getScrollInfoFromSnapshot(snapshot) {
|
|
|
38
39
|
prevPoint: sharedStore[keyPrevPoint] || null,
|
|
39
40
|
activeThumbType: sharedStore[keyActiveThumbType] || null,
|
|
40
41
|
xThumbRect: sharedStore[keyXThumbRect] || null,
|
|
41
|
-
yThumbRect: sharedStore[keyYThumbRect] || null
|
|
42
|
+
yThumbRect: sharedStore[keyYThumbRect] || null,
|
|
43
|
+
hoverXThumb: sharedStore[keyHoverXThumbRect],
|
|
44
|
+
hoverYThumb: sharedStore[keyHoverYThumbRect]
|
|
42
45
|
};
|
|
43
46
|
return info;
|
|
44
47
|
}
|
|
45
|
-
function calcScrollerInfo(
|
|
48
|
+
function calcScrollerInfo(opts) {
|
|
49
|
+
const { viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb } = opts;
|
|
46
50
|
const { width, height } = viewSizeInfo;
|
|
47
51
|
const { offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
|
|
48
52
|
const sliderMinSize = scrollerLineWidth * 2.5;
|
|
@@ -101,7 +105,8 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
101
105
|
ySize,
|
|
102
106
|
translateY,
|
|
103
107
|
translateX,
|
|
104
|
-
|
|
108
|
+
xThumbColor: hoverXThumb ? scrollConfig.thumbHoverColor : scrollConfig.thumbColor,
|
|
109
|
+
yThumbColor: hoverYThumb ? scrollConfig.thumbHoverColor : scrollConfig.thumbColor,
|
|
105
110
|
scrollBarColor: scrollConfig.scrollBarColor,
|
|
106
111
|
xThumbRect,
|
|
107
112
|
yThumbRect
|
|
@@ -158,9 +163,9 @@ function drawScrollerThumb(ctx, opts) {
|
|
|
158
163
|
function drawScrollerInfo(overlayContext, opts) {
|
|
159
164
|
const ctx = overlayContext;
|
|
160
165
|
const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
|
|
161
|
-
const { activeThumbType, prevPoint, activePoint } = scrollInfo;
|
|
166
|
+
const { activeThumbType, prevPoint, activePoint, hoverXThumb, hoverYThumb } = scrollInfo;
|
|
162
167
|
const { width, height } = viewSizeInfo;
|
|
163
|
-
const wrapper = calcScrollerInfo(viewScaleInfo, viewSizeInfo);
|
|
168
|
+
const wrapper = calcScrollerInfo({ viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb });
|
|
164
169
|
let xThumbRect = Object.assign({}, wrapper.xThumbRect);
|
|
165
170
|
let yThumbRect = Object.assign({}, wrapper.yThumbRect);
|
|
166
171
|
if (activeThumbType && prevPoint && activePoint) {
|
|
@@ -177,12 +182,12 @@ function drawScrollerInfo(overlayContext, opts) {
|
|
|
177
182
|
ctx.fillStyle = wrapper.scrollBarColor;
|
|
178
183
|
ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
|
|
179
184
|
}
|
|
180
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.
|
|
185
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.xThumbColor }));
|
|
181
186
|
if (scrollConfig.showScrollBar === true) {
|
|
182
187
|
ctx.fillStyle = wrapper.scrollBarColor;
|
|
183
188
|
ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
|
|
184
189
|
}
|
|
185
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.
|
|
190
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.yThumbColor }));
|
|
186
191
|
ctx.globalAlpha = 1;
|
|
187
192
|
return {
|
|
188
193
|
xThumbRect,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CoreEventMap } from '@idraw/types';
|
|
2
2
|
import type { BoardMiddleware, ActionType, DeepSelectorSharedStorage } from './types';
|
|
3
|
-
import { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup, middlewareEventSnapToGrid, keyActionType, keyResizeType, keyGroupQueue, keySelectedElementList } from './config';
|
|
4
|
-
export { keySelectedElementList, keyActionType, keyResizeType, keyGroupQueue };
|
|
3
|
+
import { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup, middlewareEventSnapToGrid, keyActionType, keyResizeType, keyGroupQueue, keyHoverElement, keySelectedElementList } from './config';
|
|
4
|
+
export { keySelectedElementList, keyHoverElement, keyActionType, keyResizeType, keyGroupQueue };
|
|
5
5
|
export type { DeepSelectorSharedStorage, ActionType };
|
|
6
6
|
export { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup, middlewareEventSnapToGrid };
|
|
7
7
|
export declare const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, CoreEventMap>;
|