@idraw/core 0.3.0-beta.3 → 0.3.0-beta.7
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/index.d.ts +44 -44
- package/dist/esm/index.js +85 -80
- package/dist/esm/lib/calculate.d.ts +3 -3
- package/dist/esm/lib/calculate.js +5 -5
- package/dist/esm/lib/check.d.ts +4 -4
- package/dist/esm/lib/check.js +1 -1
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/core-event.d.ts +21 -21
- package/dist/esm/lib/diff.d.ts +6 -6
- package/dist/esm/lib/diff.js +9 -7
- package/dist/esm/lib/draw/base.d.ts +5 -5
- package/dist/esm/lib/draw/wrapper.d.ts +4 -4
- package/dist/esm/lib/element.d.ts +8 -8
- package/dist/esm/lib/element.js +15 -11
- package/dist/esm/lib/engine-temp.d.ts +4 -4
- package/dist/esm/lib/engine.d.ts +5 -5
- package/dist/esm/lib/helper.d.ts +12 -12
- package/dist/esm/lib/is.d.ts +3 -3
- package/dist/esm/lib/mapper.d.ts +4 -4
- package/dist/esm/lib/parse.d.ts +2 -2
- package/dist/esm/lib/parse.js +6 -3
- package/dist/esm/lib/transform.d.ts +4 -4
- package/dist/esm/lib/transform.js +1 -1
- package/dist/esm/mixins/element.d.ts +12 -14
- package/dist/esm/mixins/element.js +60 -62
- package/dist/esm/plugins/helper.d.ts +7 -7
- package/dist/esm/plugins/helper.js +5 -10
- package/dist/index.global.js +400 -439
- package/dist/index.global.min.js +1 -1
- package/package.json +6 -6
- package/dist/esm/lib/element/element-base.d.ts +0 -3
- package/dist/esm/lib/element/element-base.js +0 -5
- package/dist/esm/lib/element/element-controller.d.ts +0 -3
- package/dist/esm/lib/element/element-controller.js +0 -3
- package/dist/esm/lib/element/element-hub.d.ts +0 -9
- package/dist/esm/lib/element/element-hub.js +0 -16
- package/dist/esm/names.d.ts +0 -15
- package/dist/esm/names.js +0 -15
package/dist/esm/lib/element.js
CHANGED
|
@@ -81,7 +81,7 @@ export class Element {
|
|
|
81
81
|
'bottom-left',
|
|
82
82
|
'left'
|
|
83
83
|
].includes(direction)) {
|
|
84
|
-
const p = calcuScaleElemPosition(elem, moveX, moveY, direction
|
|
84
|
+
const p = calcuScaleElemPosition(elem, moveX, moveY, direction);
|
|
85
85
|
elem.x = p.x;
|
|
86
86
|
elem.y = p.y;
|
|
87
87
|
elem.w = p.w;
|
|
@@ -117,10 +117,10 @@ export class Element {
|
|
|
117
117
|
elem.angle = limitAngle(elem.angle || 0);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
function calcuScaleElemPosition(elem, moveX, moveY, direction
|
|
120
|
+
function calcuScaleElemPosition(elem, moveX, moveY, direction) {
|
|
121
121
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
122
122
|
const p = { x: elem.x, y: elem.y, w: elem.w, h: elem.h };
|
|
123
|
-
let angle = elem.angle;
|
|
123
|
+
let angle = elem.angle || 0;
|
|
124
124
|
if (angle < 0) {
|
|
125
125
|
angle = Math.max(0, 360 + angle);
|
|
126
126
|
}
|
|
@@ -142,7 +142,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
144
|
case 'top': {
|
|
145
|
-
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
145
|
+
if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
|
|
146
146
|
if (p.h - moveY > 0) {
|
|
147
147
|
p.y += moveY;
|
|
148
148
|
p.h -= moveY;
|
|
@@ -152,7 +152,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
else if (elem.angle
|
|
155
|
+
else if (elem.angle !== undefined &&
|
|
156
|
+
(elem.angle > 0 || elem.angle < 0)) {
|
|
156
157
|
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
157
158
|
let moveDist = calcMoveDist(moveX, moveY);
|
|
158
159
|
let centerX = p.x + elem.w / 2;
|
|
@@ -215,7 +216,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
215
216
|
break;
|
|
216
217
|
}
|
|
217
218
|
case 'right': {
|
|
218
|
-
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
219
|
+
if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
|
|
219
220
|
if (elem.w + moveX > 0) {
|
|
220
221
|
p.w += moveX;
|
|
221
222
|
if (((_e = elem.operation) === null || _e === void 0 ? void 0 : _e.limitRatio) === true) {
|
|
@@ -224,7 +225,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
|
-
else if (elem.angle
|
|
228
|
+
else if (elem.angle !== undefined &&
|
|
229
|
+
(elem.angle > 0 || elem.angle < 0)) {
|
|
228
230
|
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
229
231
|
let moveDist = calcMoveDist(moveX, moveY);
|
|
230
232
|
let centerX = p.x + elem.w / 2;
|
|
@@ -286,7 +288,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
286
288
|
break;
|
|
287
289
|
}
|
|
288
290
|
case 'bottom': {
|
|
289
|
-
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
291
|
+
if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
|
|
290
292
|
if (elem.h + moveY > 0) {
|
|
291
293
|
p.h += moveY;
|
|
292
294
|
if (((_h = elem.operation) === null || _h === void 0 ? void 0 : _h.limitRatio) === true) {
|
|
@@ -295,7 +297,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
295
297
|
}
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
|
-
else if (elem.angle
|
|
300
|
+
else if (elem.angle !== undefined &&
|
|
301
|
+
(elem.angle > 0 || elem.angle < 0)) {
|
|
299
302
|
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
300
303
|
let moveDist = calcMoveDist(moveX, moveY);
|
|
301
304
|
let centerX = p.x + elem.w / 2;
|
|
@@ -357,7 +360,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
357
360
|
break;
|
|
358
361
|
}
|
|
359
362
|
case 'left': {
|
|
360
|
-
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
363
|
+
if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
|
|
361
364
|
if (elem.w - moveX > 0) {
|
|
362
365
|
p.x += moveX;
|
|
363
366
|
p.w -= moveX;
|
|
@@ -367,7 +370,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
|
367
370
|
}
|
|
368
371
|
}
|
|
369
372
|
}
|
|
370
|
-
else if (elem.angle
|
|
373
|
+
else if (elem.angle !== undefined &&
|
|
374
|
+
(elem.angle > 0 || elem.angle < 0)) {
|
|
371
375
|
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
372
376
|
let moveDist = calcMoveDist(moveX, moveY);
|
|
373
377
|
let centerX = p.x + elem.w / 2;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HelperWrapperControllerDirection, Point } from '@idraw/types';
|
|
2
2
|
import { Mode, CursorStatus } from '../constant/static';
|
|
3
3
|
type TempDataDesc = {
|
|
4
4
|
hasInited: boolean;
|
|
@@ -7,9 +7,9 @@ type TempDataDesc = {
|
|
|
7
7
|
selectedUUID: string | null;
|
|
8
8
|
selectedUUIDList: string[];
|
|
9
9
|
hoverUUID: string | null;
|
|
10
|
-
selectedControllerDirection:
|
|
11
|
-
hoverControllerDirection:
|
|
12
|
-
prevPoint:
|
|
10
|
+
selectedControllerDirection: HelperWrapperControllerDirection | null;
|
|
11
|
+
hoverControllerDirection: HelperWrapperControllerDirection | null;
|
|
12
|
+
prevPoint: Point | null;
|
|
13
13
|
hasChangedElement: boolean;
|
|
14
14
|
};
|
|
15
15
|
export declare class TempData {
|
package/dist/esm/lib/engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Point, InterfaceHelperPlugin, IDrawConfigStrict, IDrawData, HelperConfig } from '@idraw/types';
|
|
2
2
|
import Board from '@idraw/board';
|
|
3
3
|
import { TempData } from './engine-temp';
|
|
4
4
|
import { Helper } from './helper';
|
|
@@ -8,9 +8,9 @@ type Options = {
|
|
|
8
8
|
coreEvent: CoreEvent;
|
|
9
9
|
board: Board;
|
|
10
10
|
element: Element;
|
|
11
|
-
config:
|
|
11
|
+
config: IDrawConfigStrict;
|
|
12
12
|
drawFeekback: () => void;
|
|
13
|
-
getDataFeekback: () =>
|
|
13
|
+
getDataFeekback: () => IDrawData;
|
|
14
14
|
selectElementByIndex: (index: number, opts?: {
|
|
15
15
|
useMode?: boolean;
|
|
16
16
|
}) => void;
|
|
@@ -25,7 +25,7 @@ export declare class Engine {
|
|
|
25
25
|
helper: Helper;
|
|
26
26
|
constructor(opts: Options);
|
|
27
27
|
addPlugin(plugin: InterfaceHelperPlugin): void;
|
|
28
|
-
getHelperConfig():
|
|
28
|
+
getHelperConfig(): HelperConfig;
|
|
29
29
|
updateHelperConfig(opts: {
|
|
30
30
|
width: number;
|
|
31
31
|
height: number;
|
|
@@ -34,7 +34,7 @@ export declare class Engine {
|
|
|
34
34
|
init(): void;
|
|
35
35
|
private _initEvent;
|
|
36
36
|
private _handleDoubleClick;
|
|
37
|
-
_handlePoint(point:
|
|
37
|
+
_handlePoint(point: Point): void;
|
|
38
38
|
private _handleClick;
|
|
39
39
|
private _handleMoveStart;
|
|
40
40
|
private _handleMove;
|
package/dist/esm/lib/helper.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDrawData, HelperConfig, HelperUpdateOpts, HelperWrapperControllerDirection, Point, IDrawConfigStrict } from '@idraw/types';
|
|
2
2
|
import Board from '@idraw/board';
|
|
3
|
-
export declare class Helper
|
|
3
|
+
export declare class Helper {
|
|
4
4
|
private _helperConfig;
|
|
5
5
|
private _coreConfig;
|
|
6
6
|
private _ctx;
|
|
7
7
|
private _board;
|
|
8
8
|
private _areaStart;
|
|
9
9
|
private _areaEnd;
|
|
10
|
-
constructor(board: Board, config:
|
|
11
|
-
updateConfig(data:
|
|
12
|
-
getConfig():
|
|
10
|
+
constructor(board: Board, config: IDrawConfigStrict);
|
|
11
|
+
updateConfig(data: IDrawData, opts: HelperUpdateOpts): void;
|
|
12
|
+
getConfig(): HelperConfig;
|
|
13
13
|
getElementIndexByUUID(uuid: string): number | null;
|
|
14
|
-
isPointInElementWrapperController(p:
|
|
14
|
+
isPointInElementWrapperController(p: Point, data?: IDrawData): {
|
|
15
15
|
uuid: string | null | undefined;
|
|
16
|
-
selectedControllerDirection:
|
|
17
|
-
hoverControllerDirection:
|
|
16
|
+
selectedControllerDirection: HelperWrapperControllerDirection | null;
|
|
17
|
+
hoverControllerDirection: HelperWrapperControllerDirection | null;
|
|
18
18
|
directIndex: number | null;
|
|
19
19
|
};
|
|
20
|
-
isPointInElementList(p:
|
|
21
|
-
startSelectArea(p:
|
|
22
|
-
changeSelectArea(p:
|
|
20
|
+
isPointInElementList(p: Point, data: IDrawData): boolean;
|
|
21
|
+
startSelectArea(p: Point): void;
|
|
22
|
+
changeSelectArea(p: Point): void;
|
|
23
23
|
clearSelectedArea(): void;
|
|
24
|
-
calcSelectedElements(data:
|
|
24
|
+
calcSelectedElements(data: IDrawData): string[];
|
|
25
25
|
private _calcSelectedArea;
|
|
26
26
|
private _updateElementIndex;
|
|
27
27
|
private _updateSelectedElementWrapper;
|
package/dist/esm/lib/is.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const is:
|
|
2
|
-
type
|
|
1
|
+
declare const is: IsTypeUtil;
|
|
2
|
+
type IsTypeUtil = {
|
|
3
3
|
x: (value: any) => boolean;
|
|
4
4
|
y: (value: any) => boolean;
|
|
5
5
|
w: (value: any) => boolean;
|
|
@@ -23,4 +23,4 @@ type TypeIs = {
|
|
|
23
23
|
strokeWidth: (value: any) => boolean;
|
|
24
24
|
};
|
|
25
25
|
export default is;
|
|
26
|
-
export {
|
|
26
|
+
export { IsTypeUtil };
|
package/dist/esm/lib/mapper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IDrawData, Point, PointCursor } from '@idraw/types';
|
|
2
2
|
import Board from '@idraw/board';
|
|
3
3
|
import { Helper } from './helper';
|
|
4
4
|
import { Element } from './element';
|
|
@@ -17,9 +17,9 @@ export declare class Mapper {
|
|
|
17
17
|
private [_helper];
|
|
18
18
|
private [_element];
|
|
19
19
|
constructor(opts: Options);
|
|
20
|
-
isEffectivePoint(p:
|
|
21
|
-
judgePointCursor(p:
|
|
22
|
-
cursor:
|
|
20
|
+
isEffectivePoint(p: Point): boolean;
|
|
21
|
+
judgePointCursor(p: Point, data: IDrawData): {
|
|
22
|
+
cursor: PointCursor;
|
|
23
23
|
elementUUID: string | null;
|
|
24
24
|
};
|
|
25
25
|
}
|
package/dist/esm/lib/parse.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function parseData(data: any):
|
|
1
|
+
import { IDrawData } from '@idraw/types';
|
|
2
|
+
export declare function parseData(data: any): IDrawData;
|
package/dist/esm/lib/parse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { elementNames } from './../constant/element';
|
|
2
2
|
export function parseData(data) {
|
|
3
3
|
const result = {
|
|
4
|
-
elements: []
|
|
4
|
+
elements: []
|
|
5
5
|
};
|
|
6
6
|
if (Array.isArray(data === null || data === void 0 ? void 0 : data.elements)) {
|
|
7
7
|
data === null || data === void 0 ? void 0 : data.elements.forEach((elem = {}) => {
|
|
@@ -16,7 +16,10 @@ export function parseData(data) {
|
|
|
16
16
|
return result;
|
|
17
17
|
}
|
|
18
18
|
function isElement(elem) {
|
|
19
|
-
if (!(isNumber(elem.x) &&
|
|
19
|
+
if (!(isNumber(elem.x) &&
|
|
20
|
+
isNumber(elem.y) &&
|
|
21
|
+
isNumber(elem.w) &&
|
|
22
|
+
isNumber(elem.h))) {
|
|
20
23
|
return false;
|
|
21
24
|
}
|
|
22
25
|
if (!(typeof elem.type === 'string' && elementNames.includes(elem.type))) {
|
|
@@ -25,5 +28,5 @@ function isElement(elem) {
|
|
|
25
28
|
return true;
|
|
26
29
|
}
|
|
27
30
|
function isNumber(num) {
|
|
28
|
-
return
|
|
31
|
+
return num >= 0 || num < 0;
|
|
29
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare function rotateElement(ctx:
|
|
3
|
-
declare function rotateContext(ctx:
|
|
4
|
-
export { rotateContext, rotateElement
|
|
1
|
+
import { IDrawContext, Point, DataElement, DataElemDesc } from '@idraw/types';
|
|
2
|
+
declare function rotateElement(ctx: IDrawContext, elem: DataElement<keyof DataElemDesc>, callback: (ctx: IDrawContext) => void): void;
|
|
3
|
+
declare function rotateContext(ctx: IDrawContext, center: Point | undefined, radian: number, callback: (ctx: IDrawContext) => void): void;
|
|
4
|
+
export { rotateContext, rotateElement };
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Core from '
|
|
3
|
-
export declare function getSelectedElements(core: Core):
|
|
4
|
-
export declare function getElement(core: Core, uuid: string):
|
|
5
|
-
export declare function getElementByIndex(core: Core, index: number):
|
|
6
|
-
export declare function updateElement(core: Core, elem:
|
|
1
|
+
import { DataElement, DataElemDesc, DataElementBase } from '@idraw/types';
|
|
2
|
+
import Core from '../index';
|
|
3
|
+
export declare function getSelectedElements(core: Core): DataElement<keyof DataElemDesc>[];
|
|
4
|
+
export declare function getElement(core: Core, uuid: string): DataElement<keyof DataElemDesc> | null;
|
|
5
|
+
export declare function getElementByIndex(core: Core, index: number): DataElement<keyof DataElemDesc> | null;
|
|
6
|
+
export declare function updateElement(core: Core, elem: DataElement<keyof DataElemDesc>): void;
|
|
7
7
|
export declare function selectElementByIndex(core: Core, index: number): void;
|
|
8
8
|
export declare function selectElement(core: Core, uuid: string): void;
|
|
9
9
|
export declare function cancelElementByIndex(core: Core, index: number): void;
|
|
10
|
-
export declare function cancelElement(core: Core, uuid: string
|
|
11
|
-
useMode?: boolean;
|
|
12
|
-
}): void;
|
|
10
|
+
export declare function cancelElement(core: Core, uuid: string): void;
|
|
13
11
|
export declare function moveUpElement(core: Core, uuid: string): void;
|
|
14
12
|
export declare function moveDownElement(core: Core, uuid: string): void;
|
|
15
|
-
export declare function addElement(core: Core, elem:
|
|
13
|
+
export declare function addElement(core: Core, elem: DataElementBase<keyof DataElemDesc>): string | null;
|
|
16
14
|
export declare function deleteElement(core: Core, uuid: string): void;
|
|
17
|
-
export declare function insertElementBefore(core: Core, elem:
|
|
18
|
-
export declare function insertElementBeforeIndex(core: Core, elem:
|
|
19
|
-
export declare function insertElementAfter(core: Core, elem:
|
|
20
|
-
export declare function insertElementAfterIndex(core: Core, elem:
|
|
15
|
+
export declare function insertElementBefore(core: Core, elem: DataElementBase<keyof DataElemDesc>, beforeUUID: string): any;
|
|
16
|
+
export declare function insertElementBeforeIndex(core: Core, elem: DataElementBase<keyof DataElemDesc>, index: number): any;
|
|
17
|
+
export declare function insertElementAfter(core: Core, elem: DataElementBase<keyof DataElemDesc>, beforeUUID: string): any;
|
|
18
|
+
export declare function insertElementAfterIndex(core: Core, elem: DataElementBase<keyof DataElemDesc>, index: number): any;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { deepClone, createUUID } from '@idraw/util';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Mode } from './../constant/static';
|
|
2
|
+
import { diffElementResourceChange } from '../lib/diff';
|
|
3
|
+
import { Mode } from '../constant/static';
|
|
5
4
|
export function getSelectedElements(core) {
|
|
6
5
|
const elems = [];
|
|
7
6
|
let list = [];
|
|
8
|
-
const uuid = core
|
|
7
|
+
const uuid = core.getEngine().temp.get('selectedUUID');
|
|
9
8
|
if (typeof uuid === 'string' && uuid) {
|
|
10
9
|
list.push(uuid);
|
|
11
10
|
}
|
|
12
11
|
else {
|
|
13
|
-
list = core
|
|
12
|
+
list = core.getEngine().temp.get('selectedUUIDList');
|
|
14
13
|
}
|
|
15
14
|
list.forEach((uuid) => {
|
|
16
|
-
|
|
17
|
-
const index = core[_engine].helper.getElementIndexByUUID(uuid);
|
|
15
|
+
const index = core.getEngine().helper.getElementIndexByUUID(uuid);
|
|
18
16
|
if (index !== null && index >= 0) {
|
|
19
|
-
const elem =
|
|
17
|
+
const elem = core.$data.elements[index];
|
|
20
18
|
if (elem)
|
|
21
19
|
elems.push(elem);
|
|
22
20
|
}
|
|
@@ -25,23 +23,23 @@ export function getSelectedElements(core) {
|
|
|
25
23
|
}
|
|
26
24
|
export function getElement(core, uuid) {
|
|
27
25
|
let elem = null;
|
|
28
|
-
const index = core
|
|
29
|
-
if (index !== null && core
|
|
30
|
-
elem = deepClone(core
|
|
26
|
+
const index = core.getEngine().helper.getElementIndexByUUID(uuid);
|
|
27
|
+
if (index !== null && core.$data.elements[index]) {
|
|
28
|
+
elem = deepClone(core.$data.elements[index]);
|
|
31
29
|
}
|
|
32
30
|
return elem;
|
|
33
31
|
}
|
|
34
32
|
export function getElementByIndex(core, index) {
|
|
35
33
|
let elem = null;
|
|
36
|
-
if (index >= 0 && core
|
|
37
|
-
elem = deepClone(core
|
|
34
|
+
if (index >= 0 && core.$data.elements[index]) {
|
|
35
|
+
elem = deepClone(core.$data.elements[index]);
|
|
38
36
|
}
|
|
39
37
|
return elem;
|
|
40
38
|
}
|
|
41
39
|
export function updateElement(core, elem) {
|
|
42
40
|
var _a;
|
|
43
41
|
const _elem = deepClone(elem);
|
|
44
|
-
const data = core
|
|
42
|
+
const data = core.getData();
|
|
45
43
|
const resourceChangeUUIDs = [];
|
|
46
44
|
for (let i = 0; i < data.elements.length; i++) {
|
|
47
45
|
if (_elem.uuid === ((_a = data.elements[i]) === null || _a === void 0 ? void 0 : _a.uuid)) {
|
|
@@ -53,86 +51,86 @@ export function updateElement(core, elem) {
|
|
|
53
51
|
break;
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
core
|
|
57
|
-
core
|
|
54
|
+
core.$emitChangeData();
|
|
55
|
+
core.$draw({ resourceChangeUUIDs });
|
|
58
56
|
}
|
|
59
57
|
export function selectElementByIndex(core, index) {
|
|
60
|
-
if (core
|
|
61
|
-
const uuid = core
|
|
62
|
-
core
|
|
58
|
+
if (core.$data.elements[index]) {
|
|
59
|
+
const uuid = core.$data.elements[index].uuid;
|
|
60
|
+
core.getEngine().temp.set('mode', Mode.NULL);
|
|
63
61
|
if (typeof uuid === 'string') {
|
|
64
|
-
core
|
|
65
|
-
core
|
|
62
|
+
core.getEngine().temp.set('selectedUUID', uuid);
|
|
63
|
+
core.getEngine().temp.set('selectedUUIDList', []);
|
|
66
64
|
}
|
|
67
|
-
core
|
|
65
|
+
core.$draw();
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
export function selectElement(core, uuid) {
|
|
71
|
-
const index = core
|
|
69
|
+
const index = core.getEngine().helper.getElementIndexByUUID(uuid);
|
|
72
70
|
if (typeof index === 'number' && index >= 0) {
|
|
73
71
|
core.selectElementByIndex(index);
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
74
|
export function cancelElementByIndex(core, index) {
|
|
77
|
-
if (core
|
|
78
|
-
const uuid = core
|
|
79
|
-
const selectedUUID = core
|
|
75
|
+
if (core.$data.elements[index]) {
|
|
76
|
+
const uuid = core.$data.elements[index].uuid;
|
|
77
|
+
const selectedUUID = core.getEngine().temp.get('selectedUUID');
|
|
80
78
|
if (typeof uuid === 'string' && uuid === selectedUUID) {
|
|
81
|
-
core
|
|
82
|
-
core
|
|
83
|
-
core
|
|
79
|
+
core.getEngine().temp.set('mode', Mode.NULL);
|
|
80
|
+
core.getEngine().temp.set('selectedUUID', null);
|
|
81
|
+
core.getEngine().temp.set('selectedUUIDList', []);
|
|
84
82
|
}
|
|
85
|
-
core
|
|
83
|
+
core.$draw();
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
|
-
export function cancelElement(core, uuid
|
|
89
|
-
const index = core
|
|
86
|
+
export function cancelElement(core, uuid) {
|
|
87
|
+
const index = core.getEngine().helper.getElementIndexByUUID(uuid);
|
|
90
88
|
if (typeof index === 'number' && index >= 0) {
|
|
91
|
-
core.cancelElementByIndex(index
|
|
89
|
+
core.cancelElementByIndex(index);
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
export function moveUpElement(core, uuid) {
|
|
95
|
-
const index = core
|
|
93
|
+
const index = core.getEngine().helper.getElementIndexByUUID(uuid);
|
|
96
94
|
if (typeof index === 'number' &&
|
|
97
95
|
index >= 0 &&
|
|
98
|
-
index < core
|
|
99
|
-
const temp = core
|
|
100
|
-
core
|
|
101
|
-
core
|
|
96
|
+
index < core.$data.elements.length - 1) {
|
|
97
|
+
const temp = core.$data.elements[index];
|
|
98
|
+
core.$data.elements[index] = core.$data.elements[index + 1];
|
|
99
|
+
core.$data.elements[index + 1] = temp;
|
|
102
100
|
}
|
|
103
|
-
core
|
|
104
|
-
core
|
|
101
|
+
core.$emitChangeData();
|
|
102
|
+
core.$draw();
|
|
105
103
|
}
|
|
106
104
|
export function moveDownElement(core, uuid) {
|
|
107
|
-
const index = core
|
|
105
|
+
const index = core.getEngine().helper.getElementIndexByUUID(uuid);
|
|
108
106
|
if (typeof index === 'number' &&
|
|
109
107
|
index > 0 &&
|
|
110
|
-
index < core
|
|
111
|
-
const temp = core
|
|
112
|
-
core
|
|
113
|
-
core
|
|
108
|
+
index < core.$data.elements.length) {
|
|
109
|
+
const temp = core.$data.elements[index];
|
|
110
|
+
core.$data.elements[index] = core.$data.elements[index - 1];
|
|
111
|
+
core.$data.elements[index - 1] = temp;
|
|
114
112
|
}
|
|
115
|
-
core
|
|
116
|
-
core
|
|
113
|
+
core.$emitChangeData();
|
|
114
|
+
core.$draw();
|
|
117
115
|
}
|
|
118
116
|
export function addElement(core, elem) {
|
|
119
117
|
const _elem = deepClone(elem);
|
|
120
118
|
_elem.uuid = createUUID();
|
|
121
|
-
core
|
|
122
|
-
core
|
|
123
|
-
core
|
|
119
|
+
core.$data.elements.push(_elem);
|
|
120
|
+
core.$emitChangeData();
|
|
121
|
+
core.$draw();
|
|
124
122
|
return _elem.uuid;
|
|
125
123
|
}
|
|
126
124
|
export function deleteElement(core, uuid) {
|
|
127
|
-
const index = core
|
|
125
|
+
const index = core.$getElementHandler().getElementIndex(core.getData(), uuid);
|
|
128
126
|
if (index >= 0) {
|
|
129
|
-
core
|
|
130
|
-
core
|
|
131
|
-
core
|
|
127
|
+
core.$data.elements.splice(index, 1);
|
|
128
|
+
core.$emitChangeData();
|
|
129
|
+
core.$draw();
|
|
132
130
|
}
|
|
133
131
|
}
|
|
134
132
|
export function insertElementBefore(core, elem, beforeUUID) {
|
|
135
|
-
const index = core
|
|
133
|
+
const index = core.getEngine().helper.getElementIndexByUUID(beforeUUID);
|
|
136
134
|
if (index !== null) {
|
|
137
135
|
return core.insertElementBeforeIndex(elem, index);
|
|
138
136
|
}
|
|
@@ -142,15 +140,15 @@ export function insertElementBeforeIndex(core, elem, index) {
|
|
|
142
140
|
const _elem = deepClone(elem);
|
|
143
141
|
_elem.uuid = createUUID();
|
|
144
142
|
if (index >= 0) {
|
|
145
|
-
core
|
|
146
|
-
core
|
|
147
|
-
core
|
|
143
|
+
core.$data.elements.splice(index, 0, _elem);
|
|
144
|
+
core.$emitChangeData();
|
|
145
|
+
core.$draw();
|
|
148
146
|
return _elem.uuid;
|
|
149
147
|
}
|
|
150
148
|
return null;
|
|
151
149
|
}
|
|
152
150
|
export function insertElementAfter(core, elem, beforeUUID) {
|
|
153
|
-
const index = core
|
|
151
|
+
const index = core.getEngine().helper.getElementIndexByUUID(beforeUUID);
|
|
154
152
|
if (index !== null) {
|
|
155
153
|
return core.insertElementAfterIndex(elem, index);
|
|
156
154
|
}
|
|
@@ -160,9 +158,9 @@ export function insertElementAfterIndex(core, elem, index) {
|
|
|
160
158
|
const _elem = deepClone(elem);
|
|
161
159
|
_elem.uuid = createUUID();
|
|
162
160
|
if (index >= 0) {
|
|
163
|
-
core
|
|
164
|
-
core
|
|
165
|
-
core
|
|
161
|
+
core.$data.elements.splice(index + 1, 0, _elem);
|
|
162
|
+
core.$emitChangeData();
|
|
163
|
+
core.$draw();
|
|
166
164
|
return _elem.uuid;
|
|
167
165
|
}
|
|
168
166
|
return null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { InterfaceHelperPlugin,
|
|
1
|
+
import { InterfaceHelperPlugin, HelperPluginEventDetail, HelperPluginEventResult } from '@idraw/types';
|
|
2
2
|
export declare class HelperPlugin implements Required<InterfaceHelperPlugin> {
|
|
3
3
|
readonly name: string;
|
|
4
4
|
readonly uuid: string;
|
|
5
5
|
constructor();
|
|
6
|
-
onHover(detail:
|
|
7
|
-
onPoint(detail:
|
|
8
|
-
onClick(detail:
|
|
9
|
-
onMoveStart(detail:
|
|
10
|
-
onMove(detail:
|
|
11
|
-
onMoveEnd(detail:
|
|
6
|
+
onHover(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
|
|
7
|
+
onPoint(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
|
|
8
|
+
onClick(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
|
|
9
|
+
onMoveStart(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
|
|
10
|
+
onMove(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
|
|
11
|
+
onMoveEnd(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
|
|
12
12
|
}
|
|
@@ -8,14 +8,9 @@ export class HelperPlugin {
|
|
|
8
8
|
if (detail.controller === null) {
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
onPoint(detail) {
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
onMove(detail) {
|
|
18
|
-
}
|
|
19
|
-
onMoveEnd(detail) {
|
|
20
|
-
}
|
|
11
|
+
onPoint(detail) { }
|
|
12
|
+
onClick(detail) { }
|
|
13
|
+
onMoveStart(detail) { }
|
|
14
|
+
onMove(detail) { }
|
|
15
|
+
onMoveEnd(detail) { }
|
|
21
16
|
}
|