@idraw/core 0.4.0-beta.40 → 0.4.0-beta.41
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/board/index.d.ts +2 -4
- package/dist/esm/board/index.js +20 -33
- package/dist/esm/index.d.ts +22 -7
- package/dist/esm/index.js +233 -2
- package/dist/esm/middleware/dragger/index.d.ts +2 -2
- package/dist/esm/middleware/info/draw-info.js +3 -3
- package/dist/esm/middleware/info/index.d.ts +2 -2
- package/dist/esm/middleware/layout-selector/index.d.ts +2 -2
- package/dist/esm/middleware/layout-selector/index.js +24 -2
- package/dist/esm/middleware/layout-selector/util.js +19 -4
- package/dist/esm/middleware/pointer/index.d.ts +2 -2
- package/dist/esm/middleware/pointer/index.js +11 -12
- package/dist/esm/middleware/ruler/config.js +1 -1
- package/dist/esm/middleware/ruler/index.d.ts +2 -2
- package/dist/esm/middleware/ruler/index.js +1 -1
- package/dist/esm/middleware/ruler/util.js +5 -4
- package/dist/esm/middleware/scaler/index.d.ts +2 -2
- package/dist/esm/middleware/scroller/index.d.ts +2 -2
- package/dist/esm/middleware/scroller/util.js +1 -1
- package/dist/esm/middleware/selector/draw-base.js +2 -2
- package/dist/esm/middleware/selector/draw-debug.js +1 -1
- package/dist/esm/middleware/selector/draw-wrapper.js +15 -5
- package/dist/esm/middleware/selector/index.d.ts +2 -2
- package/dist/esm/middleware/selector/index.js +35 -5
- package/dist/esm/middleware/selector/types.d.ts +2 -2
- package/dist/esm/middleware/text-editor/index.d.ts +2 -2
- package/dist/esm/middleware/text-editor/index.js +85 -22
- package/dist/esm/record.d.ts +5 -0
- package/dist/esm/record.js +38 -0
- package/dist/index.global.js +1050 -139
- package/dist/index.global.min.js +1 -1
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Renderer, Calculator } from '@idraw/renderer';
|
|
2
2
|
import { EventEmitter } from '@idraw/util';
|
|
3
|
-
import type { Data, BoardOptions, BoardMiddleware, ViewSizeInfo, PointSize, BoardExtendEventMap
|
|
3
|
+
import type { Data, BoardOptions, BoardMiddleware, ViewSizeInfo, PointSize, BoardExtendEventMap } from '@idraw/types';
|
|
4
4
|
import { Sharer } from './sharer';
|
|
5
5
|
import { Viewer } from './viewer';
|
|
6
6
|
export declare class Board<T extends BoardExtendEventMap = BoardExtendEventMap> {
|
|
@@ -11,9 +11,7 @@ export declare class Board<T extends BoardExtendEventMap = BoardExtendEventMap>
|
|
|
11
11
|
getSharer(): Sharer;
|
|
12
12
|
getViewer(): Viewer;
|
|
13
13
|
getRenderer(): Renderer;
|
|
14
|
-
setData(data: Data
|
|
15
|
-
modifiedOptions?: ModifyOptions;
|
|
16
|
-
}): {
|
|
14
|
+
setData(data: Data): {
|
|
17
15
|
viewSizeInfo: ViewSizeInfo;
|
|
18
16
|
};
|
|
19
17
|
getData(): Data | null;
|
package/dist/esm/board/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Board_instances, _Board_opts, _Board_middlewareMap,
|
|
12
|
+
var _Board_instances, _Board_opts, _Board_middlewareMap, _Board_activeMiddlewareObjs, _Board_watcher, _Board_renderer, _Board_sharer, _Board_viewer, _Board_calculator, _Board_eventHub, _Board_hasDestroyed, _Board_init, _Board_handlePointStart, _Board_handlePointEnd, _Board_handlePointMove, _Board_handlePointLeave, _Board_handleHover, _Board_handleDoubleClick, _Board_handleContextMenu, _Board_handleWheel, _Board_handleWheelScale, _Board_handleScrollX, _Board_handleScrollY, _Board_handleResize, _Board_handleClear, _Board_handleBeforeDrawFrame, _Board_handleAfterDrawFrame, _Board_resetActiveMiddlewareObjs;
|
|
13
13
|
import { Renderer, Calculator } from '@idraw/renderer';
|
|
14
14
|
import { calcElementsContextSize, EventEmitter } from '@idraw/util';
|
|
15
15
|
import { BoardWatcher } from './watcher';
|
|
@@ -19,8 +19,7 @@ export class Board {
|
|
|
19
19
|
constructor(opts) {
|
|
20
20
|
_Board_instances.add(this);
|
|
21
21
|
_Board_opts.set(this, void 0);
|
|
22
|
-
_Board_middlewareMap.set(this, new
|
|
23
|
-
_Board_middlewares.set(this, []);
|
|
22
|
+
_Board_middlewareMap.set(this, new Map());
|
|
24
23
|
_Board_activeMiddlewareObjs.set(this, []);
|
|
25
24
|
_Board_watcher.set(this, void 0);
|
|
26
25
|
_Board_renderer.set(this, void 0);
|
|
@@ -80,8 +79,7 @@ export class Board {
|
|
|
80
79
|
getRenderer() {
|
|
81
80
|
return __classPrivateFieldGet(this, _Board_renderer, "f");
|
|
82
81
|
}
|
|
83
|
-
setData(data
|
|
84
|
-
const { modifiedOptions } = opts || {};
|
|
82
|
+
setData(data) {
|
|
85
83
|
const sharer = __classPrivateFieldGet(this, _Board_sharer, "f");
|
|
86
84
|
__classPrivateFieldGet(this, _Board_sharer, "f").setActiveStorage('data', data);
|
|
87
85
|
const viewSizeInfo = sharer.getActiveViewSizeInfo();
|
|
@@ -91,18 +89,10 @@ export class Board {
|
|
|
91
89
|
viewHeight: viewSizeInfo.height,
|
|
92
90
|
extend: true
|
|
93
91
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
__classPrivateFieldGet(this, _Board_viewer, "f").resetVirtualFlatItemMap(data, {
|
|
102
|
-
viewSizeInfo,
|
|
103
|
-
viewScaleInfo
|
|
104
|
-
});
|
|
105
|
-
}
|
|
92
|
+
__classPrivateFieldGet(this, _Board_viewer, "f").resetVirtualFlatItemMap(data, {
|
|
93
|
+
viewSizeInfo,
|
|
94
|
+
viewScaleInfo
|
|
95
|
+
});
|
|
106
96
|
__classPrivateFieldGet(this, _Board_viewer, "f").drawFrame();
|
|
107
97
|
const newViewSizeInfo = Object.assign(Object.assign({}, viewSizeInfo), newViewContextSize);
|
|
108
98
|
__classPrivateFieldGet(this, _Board_sharer, "f").setActiveViewSizeInfo(newViewSizeInfo);
|
|
@@ -116,13 +106,12 @@ export class Board {
|
|
|
116
106
|
var _a, _b, _c;
|
|
117
107
|
if (__classPrivateFieldGet(this, _Board_middlewareMap, "f").has(middleware)) {
|
|
118
108
|
const item = __classPrivateFieldGet(this, _Board_middlewareMap, "f").get(middleware);
|
|
119
|
-
if (item) {
|
|
120
|
-
(_b = (_a = item.middlewareObject).use) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
109
|
+
if (item && item.status !== 'enable') {
|
|
121
110
|
item.status = 'enable';
|
|
122
|
-
|
|
111
|
+
(_b = (_a = item.middlewareObject).use) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
123
112
|
__classPrivateFieldGet(this, _Board_instances, "m", _Board_resetActiveMiddlewareObjs).call(this);
|
|
124
|
-
return;
|
|
125
113
|
}
|
|
114
|
+
return;
|
|
126
115
|
}
|
|
127
116
|
const { boardContent, container } = __classPrivateFieldGet(this, _Board_opts, "f");
|
|
128
117
|
const sharer = __classPrivateFieldGet(this, _Board_sharer, "f");
|
|
@@ -131,8 +120,6 @@ export class Board {
|
|
|
131
120
|
const eventHub = __classPrivateFieldGet(this, _Board_eventHub, "f");
|
|
132
121
|
const obj = middleware({ boardContent, sharer, viewer, calculator, eventHub: eventHub, container }, config);
|
|
133
122
|
(_c = obj.use) === null || _c === void 0 ? void 0 : _c.call(obj);
|
|
134
|
-
__classPrivateFieldGet(this, _Board_middlewares, "f").push(middleware);
|
|
135
|
-
__classPrivateFieldGet(this, _Board_activeMiddlewareObjs, "f").push(obj);
|
|
136
123
|
__classPrivateFieldGet(this, _Board_middlewareMap, "f").set(middleware, {
|
|
137
124
|
status: 'enable',
|
|
138
125
|
middlewareObject: obj,
|
|
@@ -142,11 +129,13 @@ export class Board {
|
|
|
142
129
|
}
|
|
143
130
|
disuse(middleware) {
|
|
144
131
|
var _a, _b;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
132
|
+
if (__classPrivateFieldGet(this, _Board_middlewareMap, "f").has(middleware)) {
|
|
133
|
+
const item = __classPrivateFieldGet(this, _Board_middlewareMap, "f").get(middleware);
|
|
134
|
+
if (item) {
|
|
135
|
+
(_b = (_a = item.middlewareObject).disuse) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
136
|
+
item.status = 'disable';
|
|
137
|
+
}
|
|
138
|
+
__classPrivateFieldGet(this, _Board_middlewareMap, "f").delete(middleware);
|
|
150
139
|
__classPrivateFieldGet(this, _Board_instances, "m", _Board_resetActiveMiddlewareObjs).call(this);
|
|
151
140
|
}
|
|
152
141
|
}
|
|
@@ -206,7 +195,7 @@ export class Board {
|
|
|
206
195
|
__classPrivateFieldGet(this, _Board_watcher, "f").offEvents();
|
|
207
196
|
}
|
|
208
197
|
}
|
|
209
|
-
_Board_opts = new WeakMap(), _Board_middlewareMap = new WeakMap(),
|
|
198
|
+
_Board_opts = new WeakMap(), _Board_middlewareMap = new WeakMap(), _Board_activeMiddlewareObjs = new WeakMap(), _Board_watcher = new WeakMap(), _Board_renderer = new WeakMap(), _Board_sharer = new WeakMap(), _Board_viewer = new WeakMap(), _Board_calculator = new WeakMap(), _Board_eventHub = new WeakMap(), _Board_hasDestroyed = new WeakMap(), _Board_instances = new WeakSet(), _Board_init = function _Board_init() {
|
|
210
199
|
__classPrivateFieldGet(this, _Board_watcher, "f").on('pointStart', __classPrivateFieldGet(this, _Board_instances, "m", _Board_handlePointStart).bind(this));
|
|
211
200
|
__classPrivateFieldGet(this, _Board_watcher, "f").on('pointEnd', __classPrivateFieldGet(this, _Board_instances, "m", _Board_handlePointEnd).bind(this));
|
|
212
201
|
__classPrivateFieldGet(this, _Board_watcher, "f").on('pointMove', __classPrivateFieldGet(this, _Board_instances, "m", _Board_handlePointMove).bind(this));
|
|
@@ -359,13 +348,11 @@ _Board_opts = new WeakMap(), _Board_middlewareMap = new WeakMap(), _Board_middle
|
|
|
359
348
|
}
|
|
360
349
|
}, _Board_resetActiveMiddlewareObjs = function _Board_resetActiveMiddlewareObjs() {
|
|
361
350
|
const activeMiddlewareObjs = [];
|
|
362
|
-
const
|
|
363
|
-
__classPrivateFieldGet(this, _Board_middlewares, "f").forEach((middleware) => {
|
|
364
|
-
const item = middlewareMap.get(middleware);
|
|
351
|
+
for (const [_, item] of __classPrivateFieldGet(this, _Board_middlewareMap, "f")) {
|
|
365
352
|
if ((item === null || item === void 0 ? void 0 : item.status) === 'enable' && (item === null || item === void 0 ? void 0 : item.middlewareObject)) {
|
|
366
353
|
activeMiddlewareObjs.push(item.middlewareObject);
|
|
367
354
|
}
|
|
368
|
-
}
|
|
355
|
+
}
|
|
369
356
|
__classPrivateFieldSet(this, _Board_activeMiddlewareObjs, activeMiddlewareObjs, "f");
|
|
370
357
|
};
|
|
371
358
|
export { Sharer, Calculator };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Data, PointSize, CoreOptions,
|
|
1
|
+
import type { Data, PointSize, CoreOptions, Middleware, ViewSizeInfo, CoreEventMap, ViewScaleInfo, LoadItemMap, ElementType, RecursivePartial, Element, ModifyRecord, ElementPosition, DataLayout, DataGlobal } from '@idraw/types';
|
|
2
2
|
import { Board, Sharer, Calculator } from './board';
|
|
3
3
|
export { coreEventKeys } from './config';
|
|
4
4
|
export type { CoreEventKeys } from './config';
|
|
@@ -17,12 +17,10 @@ export declare class Core<E extends CoreEventMap = CoreEventMap> {
|
|
|
17
17
|
constructor(container: HTMLDivElement, opts: CoreOptions);
|
|
18
18
|
isDestroyed(): boolean;
|
|
19
19
|
destroy(): void;
|
|
20
|
-
use<C extends any = any>(middleware:
|
|
21
|
-
disuse(middleware:
|
|
22
|
-
resetMiddlewareConfig<C extends any = any>(middleware:
|
|
23
|
-
setData(data: Data
|
|
24
|
-
modifiedOptions?: ModifyOptions;
|
|
25
|
-
}): void;
|
|
20
|
+
use<C extends any = any>(middleware: Middleware<any, any, any>, config?: C): void;
|
|
21
|
+
disuse(middleware: Middleware<any, any, any>): void;
|
|
22
|
+
resetMiddlewareConfig<C extends any = any>(middleware: Middleware<any, any, any>, config?: Partial<C>): void;
|
|
23
|
+
setData(data: Data): void;
|
|
26
24
|
getData(): Data | null;
|
|
27
25
|
scale(opts: {
|
|
28
26
|
scale: number;
|
|
@@ -46,4 +44,21 @@ export declare class Core<E extends CoreEventMap = CoreEventMap> {
|
|
|
46
44
|
getLoadItemMap(): LoadItemMap;
|
|
47
45
|
onBoardWatcherEvents(): void;
|
|
48
46
|
offBoardWatcherEvents(): void;
|
|
47
|
+
createElement<T extends ElementType = ElementType>(type: T, element: RecursivePartial<Element<T>>, opts?: {
|
|
48
|
+
viewCenter?: boolean;
|
|
49
|
+
}): Element<T>;
|
|
50
|
+
updateElement(element: Element): ModifyRecord<'updateElement'> | null;
|
|
51
|
+
modifyElement(element: RecursivePartial<Omit<Element, 'uuid'>> & Pick<Element, 'uuid'>): ModifyRecord<'modifyElement'> | null;
|
|
52
|
+
modifyElements(elements: Array<RecursivePartial<Omit<Element, 'uuid'>> & Pick<Element, 'uuid'>>): ModifyRecord<'modifyElements'> | null;
|
|
53
|
+
addElement(element: Element, opts?: {
|
|
54
|
+
position: ElementPosition;
|
|
55
|
+
}): ModifyRecord<'addElement'>;
|
|
56
|
+
deleteElement(uuid: string): ModifyRecord<'deleteElement'>;
|
|
57
|
+
moveElement(uuid: string, to: ElementPosition): ModifyRecord<'moveElement'>;
|
|
58
|
+
modifyLayout(layout: RecursivePartial<DataLayout> | null): ModifyRecord<'modifyLayout'>;
|
|
59
|
+
modifyGlobal(global: RecursivePartial<DataGlobal> | null): {
|
|
60
|
+
type: "modifyGlobal";
|
|
61
|
+
time: number;
|
|
62
|
+
content: import("@idraw/types").ModifyContentMap["modifyGlobal"];
|
|
63
|
+
};
|
|
49
64
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -9,10 +9,23 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
12
23
|
var _Core_instances, _Core_board, _Core_canvas, _Core_container, _Core_initContainer;
|
|
24
|
+
import { deepClone, createElement, getElementPositionFromList, toFlattenElement, deleteElementInList, findElementFromListByPosition, updateElementInListByPosition, insertElementToListByPosition, moveElementPosition, toFlattenLayout, toFlattenGlobal, get, mergeLayout, mergeGlobal } from '@idraw/util';
|
|
13
25
|
import { Board, Sharer, Calculator } from './board';
|
|
14
26
|
import { createBoardContent, validateElements } from '@idraw/util';
|
|
15
27
|
import { Cursor } from './lib/cursor';
|
|
28
|
+
import { getModifyElementRecord } from './record';
|
|
16
29
|
export { coreEventKeys } from './config';
|
|
17
30
|
export { Board, Sharer, Calculator };
|
|
18
31
|
export { MiddlewareSelector } from './middleware/selector';
|
|
@@ -70,9 +83,9 @@ export class Core {
|
|
|
70
83
|
resetMiddlewareConfig(middleware, config) {
|
|
71
84
|
__classPrivateFieldGet(this, _Core_board, "f").resetMiddlewareConfig(middleware, config);
|
|
72
85
|
}
|
|
73
|
-
setData(data
|
|
86
|
+
setData(data) {
|
|
74
87
|
validateElements((data === null || data === void 0 ? void 0 : data.elements) || []);
|
|
75
|
-
__classPrivateFieldGet(this, _Core_board, "f").setData(data
|
|
88
|
+
__classPrivateFieldGet(this, _Core_board, "f").setData(data);
|
|
76
89
|
}
|
|
77
90
|
getData() {
|
|
78
91
|
return __classPrivateFieldGet(this, _Core_board, "f").getData();
|
|
@@ -128,6 +141,224 @@ export class Core {
|
|
|
128
141
|
offBoardWatcherEvents() {
|
|
129
142
|
__classPrivateFieldGet(this, _Core_board, "f").offWatcherEvents();
|
|
130
143
|
}
|
|
144
|
+
createElement(type, element, opts) {
|
|
145
|
+
const { viewScaleInfo, viewSizeInfo } = this.getViewInfo();
|
|
146
|
+
return createElement(type, element || {}, (opts === null || opts === void 0 ? void 0 : opts.viewCenter) === true
|
|
147
|
+
? {
|
|
148
|
+
viewScaleInfo,
|
|
149
|
+
viewSizeInfo
|
|
150
|
+
}
|
|
151
|
+
: undefined);
|
|
152
|
+
}
|
|
153
|
+
updateElement(element) {
|
|
154
|
+
const data = this.getData() || { elements: [] };
|
|
155
|
+
const uuid = element.uuid;
|
|
156
|
+
const position = getElementPositionFromList(uuid, data.elements);
|
|
157
|
+
const beforeElem = findElementFromListByPosition(position, data.elements);
|
|
158
|
+
if (!beforeElem) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const before = toFlattenElement(beforeElem);
|
|
162
|
+
const updatedElement = updateElementInListByPosition(position, element, data.elements, { strict: true });
|
|
163
|
+
const after = toFlattenElement(updatedElement);
|
|
164
|
+
this.setData(data);
|
|
165
|
+
this.refresh();
|
|
166
|
+
const modifyRecord = {
|
|
167
|
+
type: 'updateElement',
|
|
168
|
+
time: Date.now(),
|
|
169
|
+
content: { method: 'updateElement', uuid, before, after }
|
|
170
|
+
};
|
|
171
|
+
return modifyRecord;
|
|
172
|
+
}
|
|
173
|
+
modifyElement(element) {
|
|
174
|
+
const { uuid } = element, restElement = __rest(element, ["uuid"]);
|
|
175
|
+
const data = this.getData() || { elements: [] };
|
|
176
|
+
const position = getElementPositionFromList(uuid, data.elements);
|
|
177
|
+
const beforeElem = findElementFromListByPosition(position, data.elements);
|
|
178
|
+
if (!beforeElem) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const modifyRecord = getModifyElementRecord({
|
|
182
|
+
modifiedElement: element,
|
|
183
|
+
beforeElement: beforeElem
|
|
184
|
+
});
|
|
185
|
+
updateElementInListByPosition(position, restElement, data.elements);
|
|
186
|
+
this.setData(data);
|
|
187
|
+
this.refresh();
|
|
188
|
+
return modifyRecord;
|
|
189
|
+
}
|
|
190
|
+
modifyElements(elements) {
|
|
191
|
+
const data = this.getData() || { elements: [] };
|
|
192
|
+
let modifyRecord = null;
|
|
193
|
+
const before = [];
|
|
194
|
+
const after = [];
|
|
195
|
+
elements.forEach((element) => {
|
|
196
|
+
const { uuid } = element, restElement = __rest(element, ["uuid"]);
|
|
197
|
+
const position = getElementPositionFromList(uuid, data.elements);
|
|
198
|
+
const beforeElem = findElementFromListByPosition(position, data.elements);
|
|
199
|
+
if (!beforeElem) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
const tempRecord = getModifyElementRecord({
|
|
203
|
+
modifiedElement: element,
|
|
204
|
+
beforeElement: beforeElem
|
|
205
|
+
});
|
|
206
|
+
if (tempRecord.content) {
|
|
207
|
+
before.push(Object.assign(Object.assign({}, tempRecord.content.before), { uuid }));
|
|
208
|
+
after.push(Object.assign(Object.assign({}, tempRecord.content.after), { uuid }));
|
|
209
|
+
}
|
|
210
|
+
updateElementInListByPosition(position, restElement, data.elements);
|
|
211
|
+
});
|
|
212
|
+
modifyRecord = {
|
|
213
|
+
type: 'modifyElements',
|
|
214
|
+
time: Date.now(),
|
|
215
|
+
content: {
|
|
216
|
+
method: 'modifyElements',
|
|
217
|
+
before,
|
|
218
|
+
after
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
this.setData(data);
|
|
222
|
+
this.refresh();
|
|
223
|
+
return modifyRecord;
|
|
224
|
+
}
|
|
225
|
+
addElement(element, opts) {
|
|
226
|
+
var _a;
|
|
227
|
+
const data = this.getData() || { elements: [] };
|
|
228
|
+
if (!opts || !((_a = opts === null || opts === void 0 ? void 0 : opts.position) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
229
|
+
data.elements.push(element);
|
|
230
|
+
}
|
|
231
|
+
else if (opts === null || opts === void 0 ? void 0 : opts.position) {
|
|
232
|
+
const position = [...((opts === null || opts === void 0 ? void 0 : opts.position) || [])];
|
|
233
|
+
insertElementToListByPosition(element, position, data.elements);
|
|
234
|
+
}
|
|
235
|
+
const position = getElementPositionFromList(element.uuid, data.elements);
|
|
236
|
+
const modifyRecord = {
|
|
237
|
+
type: 'addElement',
|
|
238
|
+
time: Date.now(),
|
|
239
|
+
content: { method: 'addElement', uuid: element.uuid, position, element: deepClone(element) }
|
|
240
|
+
};
|
|
241
|
+
this.setData(data);
|
|
242
|
+
this.refresh();
|
|
243
|
+
return modifyRecord;
|
|
244
|
+
}
|
|
245
|
+
deleteElement(uuid) {
|
|
246
|
+
const data = this.getData() || { elements: [] };
|
|
247
|
+
const position = getElementPositionFromList(uuid, data.elements);
|
|
248
|
+
const element = findElementFromListByPosition(position, data.elements);
|
|
249
|
+
const modifyRecord = {
|
|
250
|
+
type: 'deleteElement',
|
|
251
|
+
time: Date.now(),
|
|
252
|
+
content: { method: 'deleteElement', uuid, position, element: element ? deepClone(element) : null }
|
|
253
|
+
};
|
|
254
|
+
deleteElementInList(uuid, data.elements);
|
|
255
|
+
this.setData(data);
|
|
256
|
+
this.refresh();
|
|
257
|
+
return modifyRecord;
|
|
258
|
+
}
|
|
259
|
+
moveElement(uuid, to) {
|
|
260
|
+
const data = this.getData() || { elements: [] };
|
|
261
|
+
const from = getElementPositionFromList(uuid, data.elements);
|
|
262
|
+
const modifyRecord = {
|
|
263
|
+
type: 'moveElement',
|
|
264
|
+
time: Date.now(),
|
|
265
|
+
content: { method: 'moveElement', uuid, from: [...from], to: [...to] }
|
|
266
|
+
};
|
|
267
|
+
const { elements: list } = moveElementPosition(data.elements, { from, to });
|
|
268
|
+
data.elements = list;
|
|
269
|
+
this.setData(data);
|
|
270
|
+
this.refresh();
|
|
271
|
+
return modifyRecord;
|
|
272
|
+
}
|
|
273
|
+
modifyLayout(layout) {
|
|
274
|
+
const data = this.getData() || { elements: [] };
|
|
275
|
+
const modifyRecord = {
|
|
276
|
+
type: 'modifyLayout',
|
|
277
|
+
time: Date.now(),
|
|
278
|
+
content: {
|
|
279
|
+
method: 'modifyLayout',
|
|
280
|
+
before: null,
|
|
281
|
+
after: null
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
if (layout === null) {
|
|
285
|
+
if (data.layout) {
|
|
286
|
+
modifyRecord.content.before = toFlattenLayout(data.layout);
|
|
287
|
+
delete data['layout'];
|
|
288
|
+
this.setData(data);
|
|
289
|
+
this.refresh();
|
|
290
|
+
return modifyRecord;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
return modifyRecord;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const beforeLayout = data.layout;
|
|
297
|
+
let before = {};
|
|
298
|
+
const after = toFlattenLayout(layout);
|
|
299
|
+
if (data.layout) {
|
|
300
|
+
Object.keys(after).forEach((key) => {
|
|
301
|
+
let val = get(beforeLayout, key);
|
|
302
|
+
if (val === undefined && /(borderRadius|borderWidth)\[[0-9]{1,}\]$/.test(key)) {
|
|
303
|
+
key = key.replace(/\[[0-9]{1,}\]$/, '');
|
|
304
|
+
val = get(beforeLayout, key);
|
|
305
|
+
}
|
|
306
|
+
before[key] = val;
|
|
307
|
+
});
|
|
308
|
+
before = toFlattenLayout(before);
|
|
309
|
+
modifyRecord.content.before = before;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
data.layout = {};
|
|
313
|
+
}
|
|
314
|
+
modifyRecord.content.after = after;
|
|
315
|
+
mergeLayout(data.layout, layout);
|
|
316
|
+
this.setData(data);
|
|
317
|
+
this.refresh();
|
|
318
|
+
return modifyRecord;
|
|
319
|
+
}
|
|
320
|
+
modifyGlobal(global) {
|
|
321
|
+
const data = this.getData() || { elements: [] };
|
|
322
|
+
const modifyRecord = {
|
|
323
|
+
type: 'modifyGlobal',
|
|
324
|
+
time: Date.now(),
|
|
325
|
+
content: {
|
|
326
|
+
method: 'modifyGlobal',
|
|
327
|
+
before: null,
|
|
328
|
+
after: null
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
if (global === null) {
|
|
332
|
+
if (data.global) {
|
|
333
|
+
modifyRecord.content.before = toFlattenGlobal(data.global);
|
|
334
|
+
delete data['global'];
|
|
335
|
+
this.setData(data);
|
|
336
|
+
this.refresh();
|
|
337
|
+
return modifyRecord;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
return modifyRecord;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const beforeGlobal = data.global;
|
|
344
|
+
let before = {};
|
|
345
|
+
const after = toFlattenGlobal(global);
|
|
346
|
+
if (data.global) {
|
|
347
|
+
Object.keys(after).forEach((key) => {
|
|
348
|
+
before[key] = get(beforeGlobal, key);
|
|
349
|
+
});
|
|
350
|
+
before = toFlattenGlobal(before);
|
|
351
|
+
modifyRecord.content.before = before;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
data.global = {};
|
|
355
|
+
}
|
|
356
|
+
modifyRecord.content.after = after;
|
|
357
|
+
mergeGlobal(data.global, global);
|
|
358
|
+
this.setData(data);
|
|
359
|
+
this.refresh();
|
|
360
|
+
return modifyRecord;
|
|
361
|
+
}
|
|
131
362
|
}
|
|
132
363
|
_Core_board = new WeakMap(), _Core_canvas = new WeakMap(), _Core_container = new WeakMap(), _Core_instances = new WeakSet(), _Core_initContainer = function _Core_initContainer() {
|
|
133
364
|
const container = __classPrivateFieldGet(this, _Core_container, "f");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Middleware, CoreEventMap, Point } from '@idraw/types';
|
|
2
2
|
declare const keyPrevPoint: unique symbol;
|
|
3
3
|
type DraggerSharedStorage = {
|
|
4
4
|
[keyPrevPoint]: Point | null;
|
|
5
5
|
};
|
|
6
|
-
export declare const MiddlewareDragger:
|
|
6
|
+
export declare const MiddlewareDragger: Middleware<DraggerSharedStorage, CoreEventMap>;
|
|
7
7
|
export {};
|
|
@@ -31,7 +31,7 @@ export function drawSizeInfoText(ctx, opts) {
|
|
|
31
31
|
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
32
32
|
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
33
33
|
ctx.closePath();
|
|
34
|
-
ctx.fill();
|
|
34
|
+
ctx.fill('nonzero');
|
|
35
35
|
ctx.fillStyle = textColor;
|
|
36
36
|
ctx.textBaseline = 'top';
|
|
37
37
|
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
@@ -68,7 +68,7 @@ export function drawPositionInfoText(ctx, opts) {
|
|
|
68
68
|
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
69
69
|
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
70
70
|
ctx.closePath();
|
|
71
|
-
ctx.fill();
|
|
71
|
+
ctx.fill('nonzero');
|
|
72
72
|
ctx.fillStyle = textColor;
|
|
73
73
|
ctx.textBaseline = 'top';
|
|
74
74
|
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
@@ -105,7 +105,7 @@ export function drawAngleInfoText(ctx, opts) {
|
|
|
105
105
|
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
106
106
|
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
107
107
|
ctx.closePath();
|
|
108
|
-
ctx.fill();
|
|
108
|
+
ctx.fill('nonzero');
|
|
109
109
|
ctx.fillStyle = textColor;
|
|
110
110
|
ctx.textBaseline = 'top';
|
|
111
111
|
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Middleware, MiddlewareInfoConfig, CoreEventMap } from '@idraw/types';
|
|
2
2
|
import type { DeepInfoSharedStorage } from './types';
|
|
3
3
|
import { MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE } from './config';
|
|
4
4
|
export { MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE };
|
|
5
|
-
export declare const MiddlewareInfo:
|
|
5
|
+
export declare const MiddlewareInfo: Middleware<DeepInfoSharedStorage, CoreEventMap & {
|
|
6
6
|
[MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE]: {
|
|
7
7
|
show: boolean;
|
|
8
8
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Middleware, MiddlewareLayoutSelectorConfig, CoreEventMap } from '@idraw/types';
|
|
2
2
|
import type { LayoutSelectorSharedStorage } from './types';
|
|
3
3
|
import { keyLayoutIsSelected, keyLayoutIsBusyMoving } from './config';
|
|
4
4
|
export { keyLayoutIsSelected, keyLayoutIsBusyMoving };
|
|
5
|
-
export declare const MiddlewareLayoutSelector:
|
|
5
|
+
export declare const MiddlewareLayoutSelector: Middleware<LayoutSelectorSharedStorage, CoreEventMap, MiddlewareLayoutSelectorConfig>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot, isViewPointInElementSize, calcViewElementSize } from '@idraw/util';
|
|
1
|
+
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot, isViewPointInElementSize, calcViewElementSize, getElementSize, toFlattenLayout } from '@idraw/util';
|
|
2
2
|
import { keyLayoutActionType, keyLayoutController, keyLayoutControlType, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving, controllerSize, defaultStyle } from './config';
|
|
3
3
|
import { keyActionType as keyElementActionType } from '../selector';
|
|
4
4
|
import { drawLayoutController, drawLayoutHover } from './util';
|
|
@@ -11,6 +11,7 @@ export const MiddlewareLayoutSelector = (opts, config) => {
|
|
|
11
11
|
let prevPoint = null;
|
|
12
12
|
let prevIsHoverContent = null;
|
|
13
13
|
let prevIsSelected = null;
|
|
14
|
+
let pointStartLayoutSize = null;
|
|
14
15
|
const clear = () => {
|
|
15
16
|
prevPoint = null;
|
|
16
17
|
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
@@ -179,6 +180,13 @@ export const MiddlewareLayoutSelector = (opts, config) => {
|
|
|
179
180
|
}
|
|
180
181
|
sharer.setSharedStorage(keyLayoutIsSelected, false);
|
|
181
182
|
}
|
|
183
|
+
const data = sharer.getActiveStorage('data');
|
|
184
|
+
if (data === null || data === void 0 ? void 0 : data.layout) {
|
|
185
|
+
pointStartLayoutSize = getElementSize(data.layout);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
pointStartLayoutSize = null;
|
|
189
|
+
}
|
|
182
190
|
resetController();
|
|
183
191
|
const layoutControlType = resetControlType(e);
|
|
184
192
|
prevPoint = e.point;
|
|
@@ -300,11 +308,25 @@ export const MiddlewareLayoutSelector = (opts, config) => {
|
|
|
300
308
|
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
301
309
|
const data = sharer.getActiveStorage('data');
|
|
302
310
|
if (data && layoutActionType === 'resize' && layoutControlType) {
|
|
311
|
+
let modifyRecord = undefined;
|
|
312
|
+
if (pointStartLayoutSize) {
|
|
313
|
+
modifyRecord = {
|
|
314
|
+
type: 'modifyLayout',
|
|
315
|
+
time: Date.now(),
|
|
316
|
+
content: {
|
|
317
|
+
method: 'modifyLayout',
|
|
318
|
+
before: toFlattenLayout(pointStartLayoutSize),
|
|
319
|
+
after: toFlattenLayout(getElementSize(data.layout))
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
303
323
|
eventHub.trigger(coreEventKeys.CHANGE, {
|
|
304
324
|
type: 'dragLayout',
|
|
305
|
-
data
|
|
325
|
+
data,
|
|
326
|
+
modifyRecord
|
|
306
327
|
});
|
|
307
328
|
}
|
|
329
|
+
pointStartLayoutSize = null;
|
|
308
330
|
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
309
331
|
sharer.setSharedStorage(keyLayoutControlType, null);
|
|
310
332
|
if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
|
|
@@ -8,7 +8,7 @@ function drawControllerBox(ctx, boxVertexes, style) {
|
|
|
8
8
|
ctx.lineTo(boxVertexes[2].x, boxVertexes[2].y);
|
|
9
9
|
ctx.lineTo(boxVertexes[3].x, boxVertexes[3].y);
|
|
10
10
|
ctx.closePath();
|
|
11
|
-
ctx.fill();
|
|
11
|
+
ctx.fill('nonzero');
|
|
12
12
|
ctx.strokeStyle = activeColor;
|
|
13
13
|
ctx.lineWidth = 2;
|
|
14
14
|
ctx.beginPath();
|
|
@@ -37,9 +37,24 @@ export function drawLayoutController(ctx, opts) {
|
|
|
37
37
|
const { controller, style } = opts;
|
|
38
38
|
const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, rightMiddle, bottomMiddle, leftMiddle } = controller;
|
|
39
39
|
drawControllerLine(ctx, { start: topLeft.center, end: topRight.center, centerVertexes: topMiddle.vertexes, style });
|
|
40
|
-
drawControllerLine(ctx, {
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
drawControllerLine(ctx, {
|
|
41
|
+
start: topRight.center,
|
|
42
|
+
end: bottomRight.center,
|
|
43
|
+
centerVertexes: rightMiddle.vertexes,
|
|
44
|
+
style
|
|
45
|
+
});
|
|
46
|
+
drawControllerLine(ctx, {
|
|
47
|
+
start: bottomRight.center,
|
|
48
|
+
end: bottomLeft.center,
|
|
49
|
+
centerVertexes: bottomMiddle.vertexes,
|
|
50
|
+
style
|
|
51
|
+
});
|
|
52
|
+
drawControllerLine(ctx, {
|
|
53
|
+
start: bottomLeft.center,
|
|
54
|
+
end: topLeft.center,
|
|
55
|
+
centerVertexes: leftMiddle.vertexes,
|
|
56
|
+
style
|
|
57
|
+
});
|
|
43
58
|
drawControllerBox(ctx, topLeft.vertexes, style);
|
|
44
59
|
drawControllerBox(ctx, topRight.vertexes, style);
|
|
45
60
|
drawControllerBox(ctx, bottomRight.vertexes, style);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Middleware, CoreEventMap } from '@idraw/types';
|
|
2
2
|
import type { DeepPointerSharedStorage } from './types';
|
|
3
|
-
export declare const MiddlewarePointer:
|
|
3
|
+
export declare const MiddlewarePointer: Middleware<DeepPointerSharedStorage, CoreEventMap>;
|
|
@@ -10,23 +10,22 @@ export const MiddlewarePointer = (opts) => {
|
|
|
10
10
|
const { left, top, width, height } = clientRect;
|
|
11
11
|
return { left, top, width, height };
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
contextMenuPointer.setAttribute('id', id);
|
|
15
|
-
contextMenuPointer.style.position = 'fixed';
|
|
16
|
-
contextMenuPointer.style.top = '0';
|
|
17
|
-
contextMenuPointer.style.bottom = 'unset';
|
|
18
|
-
contextMenuPointer.style.left = '0';
|
|
19
|
-
contextMenuPointer.style.right = 'unset';
|
|
20
|
-
container.appendChild(contextMenuPointer);
|
|
13
|
+
let contextMenuPointer = document.createElement('div');
|
|
21
14
|
return {
|
|
22
15
|
name: '@middleware/pointer',
|
|
23
16
|
use() {
|
|
17
|
+
contextMenuPointer.setAttribute('id', id);
|
|
18
|
+
contextMenuPointer.style.position = 'fixed';
|
|
19
|
+
contextMenuPointer.style.top = '0';
|
|
20
|
+
contextMenuPointer.style.bottom = 'unset';
|
|
21
|
+
contextMenuPointer.style.left = '0';
|
|
22
|
+
contextMenuPointer.style.right = 'unset';
|
|
23
|
+
container.appendChild(contextMenuPointer);
|
|
24
24
|
},
|
|
25
25
|
disuse() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
pointEnd() {
|
|
26
|
+
container.removeChild(contextMenuPointer);
|
|
27
|
+
contextMenuPointer.remove();
|
|
28
|
+
contextMenuPointer = null;
|
|
30
29
|
},
|
|
31
30
|
contextMenu(e) {
|
|
32
31
|
const { point } = e;
|
|
@@ -9,7 +9,7 @@ const scaleColor = '#000000';
|
|
|
9
9
|
const textColor = '#00000080';
|
|
10
10
|
const gridColor = '#AAAAAA20';
|
|
11
11
|
const gridPrimaryColor = '#AAAAAA40';
|
|
12
|
-
const selectedAreaColor = '#
|
|
12
|
+
const selectedAreaColor = '#19609780';
|
|
13
13
|
export const defaultStyle = {
|
|
14
14
|
background,
|
|
15
15
|
borderColor,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Middleware, CoreEventMap, MiddlewareRulerConfig } from '@idraw/types';
|
|
2
2
|
import type { DeepRulerSharedStorage } from './types';
|
|
3
|
-
export declare const MiddlewareRuler:
|
|
3
|
+
export declare const MiddlewareRuler: Middleware<DeepRulerSharedStorage, CoreEventMap, MiddlewareRulerConfig>;
|