@plait/draw 0.36.0 → 0.37.0
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/esm2022/generators/line-auto-complete.generator.mjs +1 -1
- package/esm2022/geometry.component.mjs +3 -3
- package/esm2022/image.component.mjs +14 -1
- package/esm2022/interfaces/index.mjs +1 -1
- package/esm2022/plugins/with-geometry-create.mjs +59 -49
- package/esm2022/plugins/with-line-auto-complete-reaction.mjs +5 -4
- package/esm2022/plugins/with-line-auto-complete.mjs +5 -4
- package/esm2022/plugins/with-line-create.mjs +1 -1
- package/esm2022/transforms/geometry.mjs +3 -3
- package/esm2022/transforms/index.mjs +2 -7
- package/esm2022/utils/geometry.mjs +21 -11
- package/esm2022/utils/line.mjs +1 -1
- package/esm2022/utils/memorize.mjs +2 -2
- package/fesm2022/plait-draw.mjs +308 -292
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/generators/line-auto-complete.generator.d.ts +3 -3
- package/image.component.d.ts +2 -0
- package/interfaces/index.d.ts +1 -1
- package/package.json +1 -1
- package/plugins/with-geometry-create.d.ts +7 -2
- package/transforms/index.d.ts +0 -4
- package/utils/geometry.d.ts +10 -4
- package/utils/line.d.ts +4 -4
- package/utils/memorize.d.ts +7 -1
- package/esm2022/transforms/property.mjs +0 -15
- package/transforms/property.d.ts +0 -5
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PlaitElement, ACTIVE_STROKE_WIDTH, ThemeColorMode, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle,
|
|
2
|
-
import { getRectangleByPoints, Generator,
|
|
3
|
-
import {
|
|
1
|
+
import { PlaitElement, ACTIVE_STROKE_WIDTH, ThemeColorMode, PlaitBoard, setStrokeLinecap, isPointInPolygon, getNearestPointBetweenPointAndSegments, RectangleClient, isPointInEllipse, drawRectangle, drawRoundRectangle, isPointInRoundRectangle, createG, transformPoint, toPoint, preventTouchMove, Transforms, clearSelectedElement, addSelectedElement, BoardTransforms, PlaitPointerType, idCreator, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, drawCircle, distanceBetweenPointAndSegment, arrowPoints, createPath, distanceBetweenPointAndPoint, drawLinearPath, rotate, depthFirstRecursion, getIsRecursionFunc, getElementById, Direction, catmullRomFitting, distanceBetweenPointAndSegments, createMask, createRect, findElements, Point, getSelectedElements, isPolylineHitRectangle, PlaitNode, BOARD_TO_HOST, isSelectionMoving, RgbaToHEX, PlaitPluginElementComponent, setClipboardData, getDataFromClipboard, getHitElementByPoint, CursorClass, temporaryDisableSelection, PRESS_AND_MOVE_BUFFER } from '@plait/core';
|
|
2
|
+
import { getRectangleByPoints, Generator, isDndMode, isDrawingMode, normalizeShapePoints, RESIZE_HANDLE_DIAMETER, getExtendPoint, getFactorByPoints, getRectangleResizeHandleRefs, getMemorizedLatest, memorizeLatest, getDirectionByVector, getOppositeDirection, getDirectionFactor, DEFAULT_ROUTE_MARGIN, reduceRouteMargin, getNextPoint, generateElbowLineRoute, getPoints, removeDuplicatePoints, getPointByVector, getPointOnPolyline, getDirectionByPointOfRectangle, rotateVectorAnti90, TRANSPARENT, PRIMARY_COLOR, CommonPluginElement, ActiveGenerator, WithTextPluginKey, isVirtualKey, isDelete, isSpaceHotkey, acceptImageTypes, getElementOfFocusedImage, buildImage, ResizeHandle, withResize, isResizingByCondition, getRatioByPoint, ImageGenerator } from '@plait/common';
|
|
3
|
+
import { TextManage, Alignment, buildText, DEFAULT_FONT_SIZE, getTextSize, AlignEditor, getTextFromClipboard } from '@plait/text';
|
|
4
4
|
import { isKeyHotkey } from 'is-hotkey';
|
|
5
|
-
import { pointsOnBezierCurves } from 'points-on-curve';
|
|
6
5
|
import * as i0 from '@angular/core';
|
|
7
|
-
import { Component, ChangeDetectionStrategy } from '@angular/core';
|
|
6
|
+
import { NgZone, Component, ChangeDetectionStrategy } from '@angular/core';
|
|
7
|
+
import { pointsOnBezierCurves } from 'points-on-curve';
|
|
8
8
|
import { Subject } from 'rxjs';
|
|
9
9
|
import { Node } from 'slate';
|
|
10
10
|
|
|
@@ -1223,236 +1223,11 @@ class GeometryShapeGenerator extends Generator {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
}
|
|
1225
1225
|
|
|
1226
|
-
const SHAPE_MAX_LENGTH = 6;
|
|
1227
|
-
const memorizedShape = new WeakMap();
|
|
1228
|
-
const getMemorizeKey = (element) => {
|
|
1229
|
-
let key = '';
|
|
1230
|
-
switch (true) {
|
|
1231
|
-
case PlaitDrawElement.isText(element): {
|
|
1232
|
-
key = MemorizeKey.text;
|
|
1233
|
-
break;
|
|
1234
|
-
}
|
|
1235
|
-
case PlaitDrawElement.isBasicShape(element): {
|
|
1236
|
-
key = MemorizeKey.basicShape;
|
|
1237
|
-
break;
|
|
1238
|
-
}
|
|
1239
|
-
case PlaitDrawElement.isFlowchart(element): {
|
|
1240
|
-
key = MemorizeKey.flowchart;
|
|
1241
|
-
break;
|
|
1242
|
-
}
|
|
1243
|
-
case PlaitDrawElement.isLine(element): {
|
|
1244
|
-
key = MemorizeKey.line;
|
|
1245
|
-
break;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
return key;
|
|
1249
|
-
};
|
|
1250
|
-
const getLineMemorizedLatest = () => {
|
|
1251
|
-
const properties = getMemorizedLatest(MemorizeKey.line);
|
|
1252
|
-
delete properties?.text;
|
|
1253
|
-
return properties || {};
|
|
1254
|
-
};
|
|
1255
|
-
const getMemorizedLatestByPointer = (pointer) => {
|
|
1256
|
-
let memorizeKey = '';
|
|
1257
|
-
if (PlaitDrawElement.isBasicShape({ shape: pointer })) {
|
|
1258
|
-
memorizeKey = pointer === BasicShapes.text ? MemorizeKey.text : MemorizeKey.basicShape;
|
|
1259
|
-
}
|
|
1260
|
-
else {
|
|
1261
|
-
memorizeKey = MemorizeKey.flowchart;
|
|
1262
|
-
}
|
|
1263
|
-
const properties = { ...getMemorizedLatest(memorizeKey) } || {};
|
|
1264
|
-
const textProperties = properties.text || {};
|
|
1265
|
-
delete properties.text;
|
|
1266
|
-
return { textProperties, geometryProperties: properties };
|
|
1267
|
-
};
|
|
1268
|
-
const memorizeLatestText = (element, operations) => {
|
|
1269
|
-
const memorizeKey = getMemorizeKey(element);
|
|
1270
|
-
let textMemory = getMemorizedLatest(memorizeKey)?.text || {};
|
|
1271
|
-
const setNodeOperation = operations.find(operation => operation.type === 'set_node');
|
|
1272
|
-
if (setNodeOperation) {
|
|
1273
|
-
const newProperties = setNodeOperation.newProperties;
|
|
1274
|
-
textMemory = { ...textMemory, ...newProperties };
|
|
1275
|
-
memorizeLatest(memorizeKey, 'text', textMemory);
|
|
1276
|
-
}
|
|
1277
|
-
};
|
|
1278
|
-
const memorizeLatestShape = (board, shape) => {
|
|
1279
|
-
const shapes = memorizedShape.has(board) ? memorizedShape.get(board) : [];
|
|
1280
|
-
const shapeIndex = shapes.indexOf(shape);
|
|
1281
|
-
if (shape === BasicShapes.text || shapeIndex === 0) {
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
if (shapeIndex !== -1) {
|
|
1285
|
-
shapes.splice(shapeIndex, 1);
|
|
1286
|
-
}
|
|
1287
|
-
else {
|
|
1288
|
-
if (shapes.length === SHAPE_MAX_LENGTH) {
|
|
1289
|
-
shapes.pop();
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
shapes.unshift(shape);
|
|
1293
|
-
memorizedShape.set(board, shapes);
|
|
1294
|
-
};
|
|
1295
|
-
const getMemorizedLatestShape = (board) => {
|
|
1296
|
-
return memorizedShape.get(board);
|
|
1297
|
-
};
|
|
1298
|
-
|
|
1299
|
-
const setStrokeColor = (board, strokeColor) => {
|
|
1300
|
-
PropertyTransforms.setProperty(board, { strokeColor }, { getMemorizeKey });
|
|
1301
|
-
};
|
|
1302
|
-
const setStrokeWidth = (board, strokeWidth) => {
|
|
1303
|
-
PropertyTransforms.setProperty(board, { strokeWidth }, { getMemorizeKey });
|
|
1304
|
-
};
|
|
1305
|
-
const setFillColor = (board, fill) => {
|
|
1306
|
-
PropertyTransforms.setProperty(board, { fill }, { getMemorizeKey });
|
|
1307
|
-
};
|
|
1308
|
-
const setStrokeStyle = (board, strokeStyle) => {
|
|
1309
|
-
PropertyTransforms.setProperty(board, { strokeStyle }, { getMemorizeKey });
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
|
-
const insertGeometry = (board, points, shape) => {
|
|
1313
|
-
let newElement = createGeometryElement(shape, points, '', {
|
|
1314
|
-
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
1315
|
-
});
|
|
1316
|
-
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
1317
|
-
clearSelectedElement(board);
|
|
1318
|
-
addSelectedElement(board, newElement);
|
|
1319
|
-
};
|
|
1320
|
-
const insertText = (board, points, text = '文本') => {
|
|
1321
|
-
let newElement = createGeometryElement(BasicShapes.text, points, text);
|
|
1322
|
-
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
1323
|
-
clearSelectedElement(board);
|
|
1324
|
-
addSelectedElement(board, newElement);
|
|
1325
|
-
};
|
|
1326
|
-
const resizeGeometry = (board, points, textHeight, path) => {
|
|
1327
|
-
const normalizePoints = normalizeShapePoints(points);
|
|
1328
|
-
const element = PlaitNode.get(board, path);
|
|
1329
|
-
const newHeight = textHeight / board.viewport.zoom;
|
|
1330
|
-
const newProperties = { points: normalizePoints, textHeight: newHeight };
|
|
1331
|
-
if (PlaitDrawElement.isText(element) && element.autoSize) {
|
|
1332
|
-
newProperties.autoSize = false;
|
|
1333
|
-
}
|
|
1334
|
-
Transforms.setNode(board, newProperties, path);
|
|
1335
|
-
};
|
|
1336
|
-
const transformShape = (board, element, shape) => {
|
|
1337
|
-
const path = PlaitBoard.findPath(board, element);
|
|
1338
|
-
Transforms.setNode(board, { shape }, path);
|
|
1339
|
-
};
|
|
1340
|
-
|
|
1341
|
-
const normalizePoints = (board, element, width, textHeight) => {
|
|
1342
|
-
let points = element.points;
|
|
1343
|
-
let autoSize = element.autoSize;
|
|
1344
|
-
const defaultSpace = ShapeDefaultSpace.rectangleAndText;
|
|
1345
|
-
if (autoSize) {
|
|
1346
|
-
const editor = PlaitGeometry.getTextEditor(element);
|
|
1347
|
-
if (AlignEditor.isActive(editor, Alignment.right)) {
|
|
1348
|
-
points = [
|
|
1349
|
-
[points[1][0] - (width + defaultSpace * 2), points[0][1]],
|
|
1350
|
-
[points[1][0], points[0][1] + textHeight]
|
|
1351
|
-
];
|
|
1352
|
-
}
|
|
1353
|
-
else if (AlignEditor.isActive(editor, Alignment.center)) {
|
|
1354
|
-
const oldWidth = Math.abs(points[0][0] - points[1][0]);
|
|
1355
|
-
const offset = (width - oldWidth) / 2;
|
|
1356
|
-
points = [
|
|
1357
|
-
[points[0][0] - offset - defaultSpace, points[0][1]],
|
|
1358
|
-
[points[1][0] + offset + defaultSpace, points[0][1] + textHeight]
|
|
1359
|
-
];
|
|
1360
|
-
}
|
|
1361
|
-
else {
|
|
1362
|
-
points = [points[0], [points[0][0] + width + defaultSpace * 2, points[0][1] + textHeight]];
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
return { points };
|
|
1366
|
-
};
|
|
1367
|
-
const setText = (board, element, text, width, textHeight) => {
|
|
1368
|
-
const newElement = {
|
|
1369
|
-
text,
|
|
1370
|
-
textHeight,
|
|
1371
|
-
...normalizePoints(board, element, width, textHeight)
|
|
1372
|
-
};
|
|
1373
|
-
const path = board.children.findIndex(child => child === element);
|
|
1374
|
-
Transforms.setNode(board, newElement, [path]);
|
|
1375
|
-
};
|
|
1376
|
-
const setTextSize = (board, element, textWidth, textHeight) => {
|
|
1377
|
-
if (element.autoSize) {
|
|
1378
|
-
const newElement = {
|
|
1379
|
-
textHeight,
|
|
1380
|
-
...normalizePoints(board, element, textWidth, textHeight)
|
|
1381
|
-
};
|
|
1382
|
-
const isPointsEqual = Point.isEquals(element.points[0], newElement.points[0]) && Point.isEquals(element.points[1], newElement.points[1]);
|
|
1383
|
-
const isTextHeightEqual = Math.round(textHeight) === Math.round(element.textHeight);
|
|
1384
|
-
if (!isPointsEqual || !isTextHeightEqual) {
|
|
1385
|
-
const path = board.children.findIndex(child => child === element);
|
|
1386
|
-
Transforms.setNode(board, newElement, [path]);
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
};
|
|
1390
|
-
|
|
1391
|
-
const insertImage = (board, imageItem, startPoint) => {
|
|
1392
|
-
const { width, height, url } = imageItem;
|
|
1393
|
-
const host = BOARD_TO_HOST.get(board);
|
|
1394
|
-
const viewportWidth = PlaitBoard.getComponent(board).nativeElement.clientWidth;
|
|
1395
|
-
const viewportHeight = PlaitBoard.getComponent(board).nativeElement.clientHeight;
|
|
1396
|
-
const point = transformPoint(board, toPoint(viewportWidth / 2, viewportHeight / 2, host));
|
|
1397
|
-
const points = startPoint
|
|
1398
|
-
? [startPoint, [startPoint[0] + width, startPoint[1] + height]]
|
|
1399
|
-
: [
|
|
1400
|
-
[point[0] - width / 2, point[1] - height / 2],
|
|
1401
|
-
[point[0] + width / 2, point[1] + height / 2]
|
|
1402
|
-
];
|
|
1403
|
-
const imageElement = {
|
|
1404
|
-
id: idCreator(),
|
|
1405
|
-
type: 'image',
|
|
1406
|
-
points,
|
|
1407
|
-
url
|
|
1408
|
-
};
|
|
1409
|
-
Transforms.insertNode(board, imageElement, [board.children.length]);
|
|
1410
|
-
Transforms.addSelectionWithTemporaryElements(board, [imageElement]);
|
|
1411
|
-
};
|
|
1412
|
-
|
|
1413
|
-
const resizeLine = (board, options, path) => {
|
|
1414
|
-
Transforms.setNode(board, options, path);
|
|
1415
|
-
};
|
|
1416
|
-
const setLineTexts = (board, element, texts) => {
|
|
1417
|
-
const path = PlaitBoard.findPath(board, element);
|
|
1418
|
-
Transforms.setNode(board, { texts }, path);
|
|
1419
|
-
};
|
|
1420
|
-
const removeLineText = (board, element, index) => {
|
|
1421
|
-
const path = PlaitBoard.findPath(board, element);
|
|
1422
|
-
const texts = element.texts?.length ? [...element.texts] : [];
|
|
1423
|
-
const newTexts = [...texts];
|
|
1424
|
-
newTexts.splice(index, 1);
|
|
1425
|
-
Transforms.setNode(board, { texts: newTexts }, path);
|
|
1426
|
-
};
|
|
1427
|
-
const setLineMark = (board, element, handleKey, marker) => {
|
|
1428
|
-
const path = PlaitBoard.findPath(board, element);
|
|
1429
|
-
let handle = handleKey === LineHandleKey.source ? element.source : element.target;
|
|
1430
|
-
handle = { ...handle, marker };
|
|
1431
|
-
memorizeLatest(MemorizeKey.line, handleKey, marker);
|
|
1432
|
-
Transforms.setNode(board, { [handleKey]: handle }, path);
|
|
1433
|
-
};
|
|
1434
|
-
|
|
1435
|
-
const DrawTransforms = {
|
|
1436
|
-
setText,
|
|
1437
|
-
insertGeometry,
|
|
1438
|
-
resizeGeometry,
|
|
1439
|
-
insertText,
|
|
1440
|
-
setTextSize,
|
|
1441
|
-
resizeLine,
|
|
1442
|
-
setLineTexts,
|
|
1443
|
-
removeLineText,
|
|
1444
|
-
setLineMark,
|
|
1445
|
-
insertImage,
|
|
1446
|
-
transformShape,
|
|
1447
|
-
setStrokeColor,
|
|
1448
|
-
setStrokeWidth,
|
|
1449
|
-
setFillColor,
|
|
1450
|
-
setStrokeStyle
|
|
1451
|
-
};
|
|
1452
|
-
|
|
1453
1226
|
const withGeometryCreateByDrag = (board) => {
|
|
1454
1227
|
const { pointerMove, pointerUp } = board;
|
|
1455
1228
|
let geometryShapeG = null;
|
|
1229
|
+
let temporaryElement = null;
|
|
1230
|
+
let fakeCreateTextRef = null;
|
|
1456
1231
|
board.pointerMove = (event) => {
|
|
1457
1232
|
geometryShapeG?.remove();
|
|
1458
1233
|
geometryShapeG = createG();
|
|
@@ -1463,16 +1238,39 @@ const withGeometryCreateByDrag = (board) => {
|
|
|
1463
1238
|
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1464
1239
|
const pointer = PlaitBoard.getPointer(board);
|
|
1465
1240
|
if (dragMode) {
|
|
1466
|
-
const
|
|
1241
|
+
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1467
1242
|
if (pointer === BasicShapes.text) {
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
|
|
1243
|
+
const points = getDefaultGeometryPoints(board, pointer, movingPoint, memorizedLatest.textProperties['font-size']);
|
|
1244
|
+
temporaryElement = createGeometryElement(board, BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, memorizedLatest.textProperties);
|
|
1245
|
+
if (!fakeCreateTextRef) {
|
|
1246
|
+
const textManage = new TextManage(board, PlaitBoard.getComponent(board).viewContainerRef, {
|
|
1247
|
+
getRectangle: () => {
|
|
1248
|
+
return getTextRectangle(temporaryElement);
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
PlaitBoard.getComponent(board)
|
|
1252
|
+
.viewContainerRef.injector.get(NgZone)
|
|
1253
|
+
.run(() => {
|
|
1254
|
+
textManage.draw(temporaryElement.text);
|
|
1255
|
+
});
|
|
1256
|
+
fakeCreateTextRef = {
|
|
1257
|
+
g: createG(),
|
|
1258
|
+
textManage
|
|
1259
|
+
};
|
|
1260
|
+
PlaitBoard.getHost(board).append(fakeCreateTextRef.g);
|
|
1261
|
+
fakeCreateTextRef.g.append(textManage.g);
|
|
1262
|
+
}
|
|
1263
|
+
else {
|
|
1264
|
+
fakeCreateTextRef.textManage.updateRectangle();
|
|
1265
|
+
fakeCreateTextRef.g.append(fakeCreateTextRef.textManage.g);
|
|
1266
|
+
}
|
|
1471
1267
|
}
|
|
1472
1268
|
else {
|
|
1473
|
-
const
|
|
1474
|
-
|
|
1475
|
-
|
|
1269
|
+
const points = getDefaultGeometryPoints(board, pointer, movingPoint);
|
|
1270
|
+
temporaryElement = createGeometryElement(board, pointer, points, '', {
|
|
1271
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
1272
|
+
...memorizedLatest.geometryProperties
|
|
1273
|
+
}, memorizedLatest.textProperties);
|
|
1476
1274
|
geometryGenerator.processDrawing(temporaryElement, geometryShapeG);
|
|
1477
1275
|
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
1478
1276
|
}
|
|
@@ -1480,20 +1278,14 @@ const withGeometryCreateByDrag = (board) => {
|
|
|
1480
1278
|
pointerMove(event);
|
|
1481
1279
|
};
|
|
1482
1280
|
board.pointerUp = (event) => {
|
|
1483
|
-
const pointer = PlaitBoard.getPointer(board);
|
|
1484
1281
|
const geometryPointers = getGeometryPointers();
|
|
1485
1282
|
const isGeometryPointer = PlaitBoard.isInPointer(board, geometryPointers);
|
|
1486
1283
|
const dragMode = isGeometryPointer && isDndMode(board);
|
|
1487
|
-
if (dragMode) {
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
}
|
|
1493
|
-
else {
|
|
1494
|
-
DrawTransforms.insertGeometry(board, points, pointer);
|
|
1495
|
-
}
|
|
1496
|
-
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
1284
|
+
if (dragMode && temporaryElement) {
|
|
1285
|
+
insertElement(board, temporaryElement);
|
|
1286
|
+
fakeCreateTextRef?.textManage.destroy();
|
|
1287
|
+
fakeCreateTextRef?.g.remove();
|
|
1288
|
+
fakeCreateTextRef = null;
|
|
1497
1289
|
}
|
|
1498
1290
|
geometryShapeG?.remove();
|
|
1499
1291
|
geometryShapeG = null;
|
|
@@ -1526,8 +1318,8 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
1526
1318
|
preventTouchMove(board, event, true);
|
|
1527
1319
|
if (pointer === BasicShapes.text) {
|
|
1528
1320
|
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1529
|
-
const points = getDefaultGeometryPoints(pointer, point);
|
|
1530
|
-
const textElement = createGeometryElement(BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, memorizedLatest.textProperties);
|
|
1321
|
+
const points = getDefaultGeometryPoints(board, pointer, point, memorizedLatest.textProperties['font-size']);
|
|
1322
|
+
const textElement = createGeometryElement(board, BasicShapes.text, points, DefaultTextProperty.text, memorizedLatest.geometryProperties, memorizedLatest.textProperties);
|
|
1531
1323
|
Transforms.insertNode(board, textElement, [board.children.length]);
|
|
1532
1324
|
clearSelectedElement(board);
|
|
1533
1325
|
addSelectedElement(board, textElement);
|
|
@@ -1547,7 +1339,7 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
1547
1339
|
if (drawMode && pointer !== BasicShapes.text) {
|
|
1548
1340
|
const points = normalizeShapePoints([start, movingPoint], isShift);
|
|
1549
1341
|
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1550
|
-
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
1342
|
+
temporaryElement = createGeometryElement(board, pointer, points, '', {
|
|
1551
1343
|
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
1552
1344
|
...memorizedLatest.geometryProperties
|
|
1553
1345
|
}, memorizedLatest.textProperties);
|
|
@@ -1563,10 +1355,10 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
1563
1355
|
const { width, height } = RectangleClient.toRectangleClient([start, targetPoint]);
|
|
1564
1356
|
if (Math.hypot(width, height) === 0) {
|
|
1565
1357
|
const pointer = PlaitBoard.getPointer(board);
|
|
1566
|
-
const points = getDefaultGeometryPoints(pointer, targetPoint);
|
|
1358
|
+
const points = getDefaultGeometryPoints(board, pointer, targetPoint);
|
|
1567
1359
|
if (pointer !== BasicShapes.text) {
|
|
1568
1360
|
const memorizedLatest = getMemorizedLatestByPointer(pointer);
|
|
1569
|
-
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
1361
|
+
temporaryElement = createGeometryElement(board, pointer, points, '', {
|
|
1570
1362
|
strokeWidth: DefaultBasicShapeProperty.strokeWidth,
|
|
1571
1363
|
...memorizedLatest.geometryProperties
|
|
1572
1364
|
}, memorizedLatest.textProperties);
|
|
@@ -1574,11 +1366,7 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
1574
1366
|
}
|
|
1575
1367
|
}
|
|
1576
1368
|
if (temporaryElement) {
|
|
1577
|
-
|
|
1578
|
-
Transforms.insertNode(board, temporaryElement, [board.children.length]);
|
|
1579
|
-
clearSelectedElement(board);
|
|
1580
|
-
addSelectedElement(board, temporaryElement);
|
|
1581
|
-
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
1369
|
+
insertElement(board, temporaryElement);
|
|
1582
1370
|
}
|
|
1583
1371
|
geometryShapeG?.remove();
|
|
1584
1372
|
geometryShapeG = null;
|
|
@@ -1589,15 +1377,15 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
1589
1377
|
};
|
|
1590
1378
|
return board;
|
|
1591
1379
|
};
|
|
1592
|
-
const getDefaultGeometryPoints = (pointer, targetPoint) => {
|
|
1593
|
-
const defaultProperty = getGeometryDefaultProperty(pointer);
|
|
1380
|
+
const getDefaultGeometryPoints = (board, pointer, targetPoint, fontSize) => {
|
|
1381
|
+
const defaultProperty = getGeometryDefaultProperty(board, pointer, fontSize);
|
|
1594
1382
|
return getPointsByCenterPoint(targetPoint, defaultProperty.width, defaultProperty.height);
|
|
1595
1383
|
};
|
|
1596
|
-
const getGeometryDefaultProperty = (pointer) => {
|
|
1384
|
+
const getGeometryDefaultProperty = (board, pointer, fontSize) => {
|
|
1597
1385
|
const isText = pointer === BasicShapes.text;
|
|
1598
1386
|
const isFlowChart = getFlowchartPointers().includes(pointer);
|
|
1599
1387
|
if (isText) {
|
|
1600
|
-
return
|
|
1388
|
+
return getDefaultTextShapeProperty(board, fontSize);
|
|
1601
1389
|
}
|
|
1602
1390
|
else if (isFlowChart) {
|
|
1603
1391
|
return getDefaultFlowchartProperty(pointer);
|
|
@@ -1606,17 +1394,12 @@ const getGeometryDefaultProperty = (pointer) => {
|
|
|
1606
1394
|
return DefaultBasicShapeProperty;
|
|
1607
1395
|
}
|
|
1608
1396
|
};
|
|
1609
|
-
const
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
richtext.style.fontSize = `${DEFAULT_FONT_SIZE}px`;
|
|
1616
|
-
richtext.style.cursor = 'default';
|
|
1617
|
-
foreignObject.appendChild(richtext);
|
|
1618
|
-
textG.appendChild(foreignObject);
|
|
1619
|
-
return textG;
|
|
1397
|
+
const insertElement = (board, element) => {
|
|
1398
|
+
memorizeLatestShape(board, element.shape);
|
|
1399
|
+
Transforms.insertNode(board, element, [board.children.length]);
|
|
1400
|
+
clearSelectedElement(board);
|
|
1401
|
+
addSelectedElement(board, element);
|
|
1402
|
+
BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
|
|
1620
1403
|
};
|
|
1621
1404
|
|
|
1622
1405
|
const DefaultLineStyle = {
|
|
@@ -1629,7 +1412,7 @@ const LINE_AUTO_COMPLETE_OPACITY = 0.6;
|
|
|
1629
1412
|
const LINE_AUTO_COMPLETE_HOVERED_OPACITY = 0.8;
|
|
1630
1413
|
const LINE_AUTO_COMPLETE_HOVERED_DIAMETER = 10;
|
|
1631
1414
|
|
|
1632
|
-
const createGeometryElement = (shape, points, text, options = {}, textProperties = {}) => {
|
|
1415
|
+
const createGeometryElement = (board, shape, points, text, options = {}, textProperties = {}) => {
|
|
1633
1416
|
let textOptions = {};
|
|
1634
1417
|
let alignment = Alignment.center;
|
|
1635
1418
|
if (shape === BasicShapes.text) {
|
|
@@ -1639,13 +1422,14 @@ const createGeometryElement = (shape, points, text, options = {}, textProperties
|
|
|
1639
1422
|
textProperties = { ...textProperties };
|
|
1640
1423
|
textProperties?.align && (alignment = textProperties?.align);
|
|
1641
1424
|
delete textProperties?.align;
|
|
1425
|
+
const textHeight = getDefaultTextShapeProperty(board, textProperties['font-size']).height;
|
|
1642
1426
|
return {
|
|
1643
1427
|
id: idCreator(),
|
|
1644
1428
|
type: 'geometry',
|
|
1645
1429
|
shape,
|
|
1646
1430
|
angle: 0,
|
|
1647
1431
|
opacity: 1,
|
|
1648
|
-
textHeight
|
|
1432
|
+
textHeight,
|
|
1649
1433
|
text: buildText(text, alignment, textProperties),
|
|
1650
1434
|
points,
|
|
1651
1435
|
...textOptions,
|
|
@@ -1724,7 +1508,7 @@ const getEdgeOnPolygonByPoint = (corners, point) => {
|
|
|
1724
1508
|
const getDefaultFlowchartProperty = (symbol) => {
|
|
1725
1509
|
return DefaultFlowchartPropertyMap[symbol];
|
|
1726
1510
|
};
|
|
1727
|
-
const createDefaultFlowchart = (point) => {
|
|
1511
|
+
const createDefaultFlowchart = (board, point) => {
|
|
1728
1512
|
const decisionProperty = getDefaultFlowchartProperty(FlowchartSymbols.decision);
|
|
1729
1513
|
const processProperty = getDefaultFlowchartProperty(FlowchartSymbols.process);
|
|
1730
1514
|
const terminalProperty = getDefaultFlowchartProperty(FlowchartSymbols.terminal);
|
|
@@ -1734,15 +1518,15 @@ const createDefaultFlowchart = (point) => {
|
|
|
1734
1518
|
const lineOptions = {
|
|
1735
1519
|
strokeWidth: DefaultLineStyle.strokeWidth
|
|
1736
1520
|
};
|
|
1737
|
-
const startElement = createGeometryElement(FlowchartSymbols.terminal, getDefaultGeometryPoints(FlowchartSymbols.terminal, point), '开始', options);
|
|
1521
|
+
const startElement = createGeometryElement(board, FlowchartSymbols.terminal, getDefaultGeometryPoints(board, FlowchartSymbols.terminal, point), '开始', options);
|
|
1738
1522
|
const processPoint1 = [point[0], point[1] + terminalProperty.height / 2 + 55 + processProperty.height / 2];
|
|
1739
|
-
const processElement1 = createGeometryElement(FlowchartSymbols.process, getDefaultGeometryPoints(FlowchartSymbols.process, processPoint1), '过程', options);
|
|
1523
|
+
const processElement1 = createGeometryElement(board, FlowchartSymbols.process, getDefaultGeometryPoints(board, FlowchartSymbols.process, processPoint1), '过程', options);
|
|
1740
1524
|
const decisionPoint = [processPoint1[0], processPoint1[1] + processProperty.height / 2 + 55 + decisionProperty.height / 2];
|
|
1741
|
-
const decisionElement = createGeometryElement(FlowchartSymbols.decision, getDefaultGeometryPoints(FlowchartSymbols.decision, decisionPoint), '过程', options);
|
|
1525
|
+
const decisionElement = createGeometryElement(board, FlowchartSymbols.decision, getDefaultGeometryPoints(board, FlowchartSymbols.decision, decisionPoint), '过程', options);
|
|
1742
1526
|
const processPoint2 = [decisionPoint[0] + decisionProperty.width / 2 + 75 + processProperty.width / 2, decisionPoint[1]];
|
|
1743
|
-
const processElement2 = createGeometryElement(FlowchartSymbols.process, getDefaultGeometryPoints(FlowchartSymbols.process, processPoint2), '过程', options);
|
|
1527
|
+
const processElement2 = createGeometryElement(board, FlowchartSymbols.process, getDefaultGeometryPoints(board, FlowchartSymbols.process, processPoint2), '过程', options);
|
|
1744
1528
|
const endPoint = [decisionPoint[0], decisionPoint[1] + decisionProperty.height / 2 + 95 + terminalProperty.height / 2];
|
|
1745
|
-
const endElement = createGeometryElement(FlowchartSymbols.terminal, getDefaultGeometryPoints(FlowchartSymbols.terminal, endPoint), '结束', options);
|
|
1529
|
+
const endElement = createGeometryElement(board, FlowchartSymbols.terminal, getDefaultGeometryPoints(board, FlowchartSymbols.terminal, endPoint), '结束', options);
|
|
1746
1530
|
const line1 = createLineElement(LineShape.elbow, [
|
|
1747
1531
|
[0, 0],
|
|
1748
1532
|
[0, 0]
|
|
@@ -1799,6 +1583,15 @@ const getDrawDefaultStrokeColor = (theme) => {
|
|
|
1799
1583
|
const getFlowchartDefaultFill = (theme) => {
|
|
1800
1584
|
return DrawThemeColors[theme].fill;
|
|
1801
1585
|
};
|
|
1586
|
+
const getDefaultTextShapeProperty = (board, fontSize) => {
|
|
1587
|
+
fontSize = fontSize ? Number(fontSize) : DEFAULT_FONT_SIZE;
|
|
1588
|
+
const textSize = getTextSize(board, '文本', 10, { fontSize });
|
|
1589
|
+
return {
|
|
1590
|
+
width: textSize.width + ShapeDefaultSpace.rectangleAndText * 2,
|
|
1591
|
+
height: textSize.height,
|
|
1592
|
+
text: '文本'
|
|
1593
|
+
};
|
|
1594
|
+
};
|
|
1802
1595
|
|
|
1803
1596
|
const ARROW_LENGTH = 20;
|
|
1804
1597
|
const drawLineArrow = (element, points, options) => {
|
|
@@ -1954,6 +1747,79 @@ const getHitOutlineGeometry = (board, point, offset = 0) => {
|
|
|
1954
1747
|
return geometry;
|
|
1955
1748
|
};
|
|
1956
1749
|
|
|
1750
|
+
const SHAPE_MAX_LENGTH = 6;
|
|
1751
|
+
const memorizedShape = new WeakMap();
|
|
1752
|
+
const getMemorizeKey = (element) => {
|
|
1753
|
+
let key = '';
|
|
1754
|
+
switch (true) {
|
|
1755
|
+
case PlaitDrawElement.isText(element): {
|
|
1756
|
+
key = MemorizeKey.text;
|
|
1757
|
+
break;
|
|
1758
|
+
}
|
|
1759
|
+
case PlaitDrawElement.isBasicShape(element): {
|
|
1760
|
+
key = MemorizeKey.basicShape;
|
|
1761
|
+
break;
|
|
1762
|
+
}
|
|
1763
|
+
case PlaitDrawElement.isFlowchart(element): {
|
|
1764
|
+
key = MemorizeKey.flowchart;
|
|
1765
|
+
break;
|
|
1766
|
+
}
|
|
1767
|
+
case PlaitDrawElement.isLine(element): {
|
|
1768
|
+
key = MemorizeKey.line;
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
return key;
|
|
1773
|
+
};
|
|
1774
|
+
const getLineMemorizedLatest = () => {
|
|
1775
|
+
const properties = getMemorizedLatest(MemorizeKey.line);
|
|
1776
|
+
delete properties?.text;
|
|
1777
|
+
return { ...properties } || {};
|
|
1778
|
+
};
|
|
1779
|
+
const getMemorizedLatestByPointer = (pointer) => {
|
|
1780
|
+
let memorizeKey = '';
|
|
1781
|
+
if (PlaitDrawElement.isBasicShape({ shape: pointer })) {
|
|
1782
|
+
memorizeKey = pointer === BasicShapes.text ? MemorizeKey.text : MemorizeKey.basicShape;
|
|
1783
|
+
}
|
|
1784
|
+
else {
|
|
1785
|
+
memorizeKey = MemorizeKey.flowchart;
|
|
1786
|
+
}
|
|
1787
|
+
const properties = { ...getMemorizedLatest(memorizeKey) } || {};
|
|
1788
|
+
const textProperties = properties.text || {};
|
|
1789
|
+
delete properties.text;
|
|
1790
|
+
return { textProperties, geometryProperties: properties };
|
|
1791
|
+
};
|
|
1792
|
+
const memorizeLatestText = (element, operations) => {
|
|
1793
|
+
const memorizeKey = getMemorizeKey(element);
|
|
1794
|
+
let textMemory = getMemorizedLatest(memorizeKey)?.text || {};
|
|
1795
|
+
const setNodeOperation = operations.find(operation => operation.type === 'set_node');
|
|
1796
|
+
if (setNodeOperation) {
|
|
1797
|
+
const newProperties = setNodeOperation.newProperties;
|
|
1798
|
+
textMemory = { ...textMemory, ...newProperties };
|
|
1799
|
+
memorizeLatest(memorizeKey, 'text', textMemory);
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
const memorizeLatestShape = (board, shape) => {
|
|
1803
|
+
const shapes = memorizedShape.has(board) ? memorizedShape.get(board) : [];
|
|
1804
|
+
const shapeIndex = shapes.indexOf(shape);
|
|
1805
|
+
if (shape === BasicShapes.text || shapeIndex === 0) {
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
if (shapeIndex !== -1) {
|
|
1809
|
+
shapes.splice(shapeIndex, 1);
|
|
1810
|
+
}
|
|
1811
|
+
else {
|
|
1812
|
+
if (shapes.length === SHAPE_MAX_LENGTH) {
|
|
1813
|
+
shapes.pop();
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
shapes.unshift(shape);
|
|
1817
|
+
memorizedShape.set(board, shapes);
|
|
1818
|
+
};
|
|
1819
|
+
const getMemorizedLatestShape = (board) => {
|
|
1820
|
+
return memorizedShape.get(board);
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1957
1823
|
const createLineElement = (shape, points, source, target, texts, options) => {
|
|
1958
1824
|
return {
|
|
1959
1825
|
id: idCreator(),
|
|
@@ -2506,6 +2372,143 @@ const PlaitDrawElement = {
|
|
|
2506
2372
|
}
|
|
2507
2373
|
};
|
|
2508
2374
|
|
|
2375
|
+
const insertGeometry = (board, points, shape) => {
|
|
2376
|
+
let newElement = createGeometryElement(board, shape, points, '', {
|
|
2377
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
2378
|
+
});
|
|
2379
|
+
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
2380
|
+
clearSelectedElement(board);
|
|
2381
|
+
addSelectedElement(board, newElement);
|
|
2382
|
+
};
|
|
2383
|
+
const insertText = (board, points, text = '文本') => {
|
|
2384
|
+
let newElement = createGeometryElement(board, BasicShapes.text, points, text);
|
|
2385
|
+
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
2386
|
+
clearSelectedElement(board);
|
|
2387
|
+
addSelectedElement(board, newElement);
|
|
2388
|
+
};
|
|
2389
|
+
const resizeGeometry = (board, points, textHeight, path) => {
|
|
2390
|
+
const normalizePoints = normalizeShapePoints(points);
|
|
2391
|
+
const element = PlaitNode.get(board, path);
|
|
2392
|
+
const newHeight = textHeight / board.viewport.zoom;
|
|
2393
|
+
const newProperties = { points: normalizePoints, textHeight: newHeight };
|
|
2394
|
+
if (PlaitDrawElement.isText(element) && element.autoSize) {
|
|
2395
|
+
newProperties.autoSize = false;
|
|
2396
|
+
}
|
|
2397
|
+
Transforms.setNode(board, newProperties, path);
|
|
2398
|
+
};
|
|
2399
|
+
const transformShape = (board, element, shape) => {
|
|
2400
|
+
const path = PlaitBoard.findPath(board, element);
|
|
2401
|
+
Transforms.setNode(board, { shape }, path);
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
const normalizePoints = (board, element, width, textHeight) => {
|
|
2405
|
+
let points = element.points;
|
|
2406
|
+
let autoSize = element.autoSize;
|
|
2407
|
+
const defaultSpace = ShapeDefaultSpace.rectangleAndText;
|
|
2408
|
+
if (autoSize) {
|
|
2409
|
+
const editor = PlaitGeometry.getTextEditor(element);
|
|
2410
|
+
if (AlignEditor.isActive(editor, Alignment.right)) {
|
|
2411
|
+
points = [
|
|
2412
|
+
[points[1][0] - (width + defaultSpace * 2), points[0][1]],
|
|
2413
|
+
[points[1][0], points[0][1] + textHeight]
|
|
2414
|
+
];
|
|
2415
|
+
}
|
|
2416
|
+
else if (AlignEditor.isActive(editor, Alignment.center)) {
|
|
2417
|
+
const oldWidth = Math.abs(points[0][0] - points[1][0]);
|
|
2418
|
+
const offset = (width - oldWidth) / 2;
|
|
2419
|
+
points = [
|
|
2420
|
+
[points[0][0] - offset - defaultSpace, points[0][1]],
|
|
2421
|
+
[points[1][0] + offset + defaultSpace, points[0][1] + textHeight]
|
|
2422
|
+
];
|
|
2423
|
+
}
|
|
2424
|
+
else {
|
|
2425
|
+
points = [points[0], [points[0][0] + width + defaultSpace * 2, points[0][1] + textHeight]];
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
return { points };
|
|
2429
|
+
};
|
|
2430
|
+
const setText = (board, element, text, width, textHeight) => {
|
|
2431
|
+
const newElement = {
|
|
2432
|
+
text,
|
|
2433
|
+
textHeight,
|
|
2434
|
+
...normalizePoints(board, element, width, textHeight)
|
|
2435
|
+
};
|
|
2436
|
+
const path = board.children.findIndex(child => child === element);
|
|
2437
|
+
Transforms.setNode(board, newElement, [path]);
|
|
2438
|
+
};
|
|
2439
|
+
const setTextSize = (board, element, textWidth, textHeight) => {
|
|
2440
|
+
if (element.autoSize) {
|
|
2441
|
+
const newElement = {
|
|
2442
|
+
textHeight,
|
|
2443
|
+
...normalizePoints(board, element, textWidth, textHeight)
|
|
2444
|
+
};
|
|
2445
|
+
const isPointsEqual = Point.isEquals(element.points[0], newElement.points[0]) && Point.isEquals(element.points[1], newElement.points[1]);
|
|
2446
|
+
const isTextHeightEqual = Math.round(textHeight) === Math.round(element.textHeight);
|
|
2447
|
+
if (!isPointsEqual || !isTextHeightEqual) {
|
|
2448
|
+
const path = board.children.findIndex(child => child === element);
|
|
2449
|
+
Transforms.setNode(board, newElement, [path]);
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
};
|
|
2453
|
+
|
|
2454
|
+
const insertImage = (board, imageItem, startPoint) => {
|
|
2455
|
+
const { width, height, url } = imageItem;
|
|
2456
|
+
const host = BOARD_TO_HOST.get(board);
|
|
2457
|
+
const viewportWidth = PlaitBoard.getComponent(board).nativeElement.clientWidth;
|
|
2458
|
+
const viewportHeight = PlaitBoard.getComponent(board).nativeElement.clientHeight;
|
|
2459
|
+
const point = transformPoint(board, toPoint(viewportWidth / 2, viewportHeight / 2, host));
|
|
2460
|
+
const points = startPoint
|
|
2461
|
+
? [startPoint, [startPoint[0] + width, startPoint[1] + height]]
|
|
2462
|
+
: [
|
|
2463
|
+
[point[0] - width / 2, point[1] - height / 2],
|
|
2464
|
+
[point[0] + width / 2, point[1] + height / 2]
|
|
2465
|
+
];
|
|
2466
|
+
const imageElement = {
|
|
2467
|
+
id: idCreator(),
|
|
2468
|
+
type: 'image',
|
|
2469
|
+
points,
|
|
2470
|
+
url
|
|
2471
|
+
};
|
|
2472
|
+
Transforms.insertNode(board, imageElement, [board.children.length]);
|
|
2473
|
+
Transforms.addSelectionWithTemporaryElements(board, [imageElement]);
|
|
2474
|
+
};
|
|
2475
|
+
|
|
2476
|
+
const resizeLine = (board, options, path) => {
|
|
2477
|
+
Transforms.setNode(board, options, path);
|
|
2478
|
+
};
|
|
2479
|
+
const setLineTexts = (board, element, texts) => {
|
|
2480
|
+
const path = PlaitBoard.findPath(board, element);
|
|
2481
|
+
Transforms.setNode(board, { texts }, path);
|
|
2482
|
+
};
|
|
2483
|
+
const removeLineText = (board, element, index) => {
|
|
2484
|
+
const path = PlaitBoard.findPath(board, element);
|
|
2485
|
+
const texts = element.texts?.length ? [...element.texts] : [];
|
|
2486
|
+
const newTexts = [...texts];
|
|
2487
|
+
newTexts.splice(index, 1);
|
|
2488
|
+
Transforms.setNode(board, { texts: newTexts }, path);
|
|
2489
|
+
};
|
|
2490
|
+
const setLineMark = (board, element, handleKey, marker) => {
|
|
2491
|
+
const path = PlaitBoard.findPath(board, element);
|
|
2492
|
+
let handle = handleKey === LineHandleKey.source ? element.source : element.target;
|
|
2493
|
+
handle = { ...handle, marker };
|
|
2494
|
+
memorizeLatest(MemorizeKey.line, handleKey, marker);
|
|
2495
|
+
Transforms.setNode(board, { [handleKey]: handle }, path);
|
|
2496
|
+
};
|
|
2497
|
+
|
|
2498
|
+
const DrawTransforms = {
|
|
2499
|
+
setText,
|
|
2500
|
+
insertGeometry,
|
|
2501
|
+
resizeGeometry,
|
|
2502
|
+
insertText,
|
|
2503
|
+
setTextSize,
|
|
2504
|
+
resizeLine,
|
|
2505
|
+
setLineTexts,
|
|
2506
|
+
removeLineText,
|
|
2507
|
+
setLineMark,
|
|
2508
|
+
insertImage,
|
|
2509
|
+
transformShape
|
|
2510
|
+
};
|
|
2511
|
+
|
|
2509
2512
|
class LineAutoCompleteGenerator extends Generator {
|
|
2510
2513
|
constructor(board) {
|
|
2511
2514
|
super(board);
|
|
@@ -2636,7 +2639,7 @@ class GeometryComponent extends CommonPluginElement {
|
|
|
2636
2639
|
this.textManage.updateRectangle();
|
|
2637
2640
|
}
|
|
2638
2641
|
initializeTextManage() {
|
|
2639
|
-
const plugins = this.board.getPluginOptions(WithTextPluginKey).textPlugins;
|
|
2642
|
+
const plugins = (this.board.getPluginOptions(WithTextPluginKey) || {}).textPlugins;
|
|
2640
2643
|
const manage = new TextManage(this.board, this.viewContainerRef, {
|
|
2641
2644
|
getRectangle: () => {
|
|
2642
2645
|
const getRectangle = getEngine(this.element.shape).getTextRectangle;
|
|
@@ -2674,7 +2677,7 @@ class GeometryComponent extends CommonPluginElement {
|
|
|
2674
2677
|
this.destroy$.next();
|
|
2675
2678
|
this.destroy$.complete();
|
|
2676
2679
|
this.activeGenerator.destroy();
|
|
2677
|
-
this.lineAutoCompleteGenerator;
|
|
2680
|
+
this.lineAutoCompleteGenerator.destroy();
|
|
2678
2681
|
}
|
|
2679
2682
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: GeometryComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2680
2683
|
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: GeometryComponent, isStandalone: true, selector: "plait-draw-geometry", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
@@ -3455,22 +3458,32 @@ class ImageComponent extends CommonPluginElement {
|
|
|
3455
3458
|
};
|
|
3456
3459
|
}
|
|
3457
3460
|
});
|
|
3461
|
+
this.lineAutoCompleteGenerator = new LineAutoCompleteGenerator(this.board);
|
|
3458
3462
|
}
|
|
3459
3463
|
ngOnInit() {
|
|
3460
3464
|
super.ngOnInit();
|
|
3461
3465
|
this.initializeGenerator();
|
|
3462
3466
|
this.imageGenerator.processDrawing(this.element, this.g, this.viewContainerRef);
|
|
3467
|
+
this.lineAutoCompleteGenerator.processDrawing(this.element, PlaitBoard.getElementActiveHost(this.board), {
|
|
3468
|
+
selected: this.selected
|
|
3469
|
+
});
|
|
3463
3470
|
}
|
|
3464
3471
|
onContextChanged(value, previous) {
|
|
3465
3472
|
if (value.element !== previous.element) {
|
|
3466
3473
|
this.imageGenerator.updateImage(this.g, previous.element, value.element);
|
|
3467
3474
|
this.imageGenerator.componentRef.instance.isFocus = this.selected;
|
|
3475
|
+
this.lineAutoCompleteGenerator.processDrawing(this.element, PlaitBoard.getElementActiveHost(this.board), {
|
|
3476
|
+
selected: this.selected
|
|
3477
|
+
});
|
|
3468
3478
|
}
|
|
3469
3479
|
else {
|
|
3470
3480
|
const hasSameSelected = value.selected === previous.selected;
|
|
3471
3481
|
const hasSameHandleState = this.activeGenerator.options.hasResizeHandle() === this.activeGenerator.hasResizeHandle;
|
|
3472
3482
|
if (!hasSameSelected || !hasSameHandleState) {
|
|
3473
3483
|
this.imageGenerator.componentRef.instance.isFocus = this.selected;
|
|
3484
|
+
this.lineAutoCompleteGenerator.processDrawing(this.element, PlaitBoard.getElementActiveHost(this.board), {
|
|
3485
|
+
selected: this.selected
|
|
3486
|
+
});
|
|
3474
3487
|
}
|
|
3475
3488
|
}
|
|
3476
3489
|
}
|
|
@@ -3479,6 +3492,7 @@ class ImageComponent extends CommonPluginElement {
|
|
|
3479
3492
|
this.destroy$.next();
|
|
3480
3493
|
this.destroy$.complete();
|
|
3481
3494
|
this.imageGenerator.destroy();
|
|
3495
|
+
this.lineAutoCompleteGenerator.destroy();
|
|
3482
3496
|
}
|
|
3483
3497
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ImageComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3484
3498
|
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: ImageComponent, isStandalone: true, selector: "plait-draw-geometry", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
@@ -3500,12 +3514,13 @@ const withLineAutoCompleteReaction = (board) => {
|
|
|
3500
3514
|
reactionG?.remove();
|
|
3501
3515
|
PlaitBoard.getBoardContainer(board).classList.remove(CursorClass.crosshair);
|
|
3502
3516
|
const selectedElements = getSelectedDrawElements(board);
|
|
3517
|
+
const targetElement = selectedElements.length === 1 && selectedElements[0];
|
|
3503
3518
|
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
3504
|
-
if (!PlaitBoard.isReadonly(board) && !isSelectionMoving(board) &&
|
|
3505
|
-
const points = getAutoCompletePoints(
|
|
3519
|
+
if (!PlaitBoard.isReadonly(board) && !isSelectionMoving(board) && targetElement && PlaitDrawElement.isShape(targetElement)) {
|
|
3520
|
+
const points = getAutoCompletePoints(targetElement);
|
|
3506
3521
|
const hitIndex = getHitIndexOfAutoCompletePoint(movingPoint, points);
|
|
3507
3522
|
const hitPoint = points[hitIndex];
|
|
3508
|
-
const component = PlaitElement.getComponent(
|
|
3523
|
+
const component = PlaitElement.getComponent(targetElement);
|
|
3509
3524
|
component.lineAutoCompleteGenerator.recoverAutoCompleteG();
|
|
3510
3525
|
if (hitPoint) {
|
|
3511
3526
|
component.lineAutoCompleteGenerator.removeAutoCompleteG(hitIndex);
|
|
@@ -3532,15 +3547,16 @@ const withLineAutoComplete = (board) => {
|
|
|
3532
3547
|
let temporaryElement;
|
|
3533
3548
|
board.pointerDown = (event) => {
|
|
3534
3549
|
const selectedElements = getSelectedDrawElements(board);
|
|
3550
|
+
const targetElement = selectedElements.length === 1 && selectedElements[0];
|
|
3535
3551
|
const clickPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
3536
|
-
if (!PlaitBoard.isReadonly(board) &&
|
|
3537
|
-
const points = getAutoCompletePoints(
|
|
3552
|
+
if (!PlaitBoard.isReadonly(board) && targetElement && PlaitDrawElement.isShape(targetElement)) {
|
|
3553
|
+
const points = getAutoCompletePoints(targetElement);
|
|
3538
3554
|
const index = getHitIndexOfAutoCompletePoint(clickPoint, points);
|
|
3539
3555
|
const hitPoint = points[index];
|
|
3540
3556
|
if (hitPoint) {
|
|
3541
3557
|
temporaryDisableSelection(board);
|
|
3542
3558
|
startPoint = clickPoint;
|
|
3543
|
-
sourceElement =
|
|
3559
|
+
sourceElement = targetElement;
|
|
3544
3560
|
BoardTransforms.updatePointerType(board, LineShape.elbow);
|
|
3545
3561
|
}
|
|
3546
3562
|
}
|
|
@@ -3656,5 +3672,5 @@ const withDraw = (board) => {
|
|
|
3656
3672
|
* Generated bundle index. Do not edit.
|
|
3657
3673
|
*/
|
|
3658
3674
|
|
|
3659
|
-
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawThemeColors, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, MemorizeKey, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, REACTION_MARGIN, ShapeDefaultSpace, StrokeStyle, alignPoints, createDefaultFlowchart, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getAutoCompletePoints, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getDrawDefaultStrokeColor, getEdgeOnPolygonByPoint, getElbowPoints, getFillByElement, getFlowchartDefaultFill, getFlowchartPointers, getGeometryPointers, getHitConnectorPoint, getHitIndexOfAutoCompletePoint, getHitLineTextIndex, getLineDashByElement, getLineHandleRefPair, getLineMemorizedLatest, getLinePointers, getLinePoints, getLineTextRectangle, getMemorizeKey, getMemorizedLatestByPointer, getMemorizedLatestShape, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedLineElements, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, getVectorByConnection, handleLineCreating, isHitDrawElement, isHitLineText, isHitPolyLine, isRectangleHitDrawElement, isTextExceedingBounds, memorizeLatestShape, memorizeLatestText, transformOpsToPoints, transformPointToConnection, withDraw };
|
|
3675
|
+
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawThemeColors, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, MemorizeKey, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, REACTION_MARGIN, ShapeDefaultSpace, StrokeStyle, alignPoints, createDefaultFlowchart, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getAutoCompletePoints, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getDefaultTextShapeProperty, getDrawDefaultStrokeColor, getEdgeOnPolygonByPoint, getElbowPoints, getFillByElement, getFlowchartDefaultFill, getFlowchartPointers, getGeometryPointers, getHitConnectorPoint, getHitIndexOfAutoCompletePoint, getHitLineTextIndex, getLineDashByElement, getLineHandleRefPair, getLineMemorizedLatest, getLinePointers, getLinePoints, getLineTextRectangle, getMemorizeKey, getMemorizedLatestByPointer, getMemorizedLatestShape, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedLineElements, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, getVectorByConnection, handleLineCreating, isHitDrawElement, isHitLineText, isHitPolyLine, isRectangleHitDrawElement, isTextExceedingBounds, memorizeLatestShape, memorizeLatestText, transformOpsToPoints, transformPointToConnection, withDraw };
|
|
3660
3676
|
//# sourceMappingURL=plait-draw.mjs.map
|