@plait/mind 0.7.0 → 0.9.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.
@@ -555,10 +555,8 @@ const getAvailableProperty = (board, element, propertyKey) => {
555
555
  * Processing of branch color, width, style, etc. of the mind node
556
556
  */
557
557
  const getBranchColorByMindElement = (board, element) => {
558
- var _a;
559
558
  const branchColor = getAvailableProperty(board, element, 'branchColor');
560
- const parentBranchColor = (_a = MindElement.getParent(element)) === null || _a === void 0 ? void 0 : _a.branchColor;
561
- return parentBranchColor || branchColor || getDefaultBranchColor(board, element);
559
+ return branchColor || getDefaultBranchColor(board, element);
562
560
  };
563
561
  const getBranchShapeByMindElement = (board, element) => {
564
562
  const branchShape = getAvailableProperty(board, element, 'branchShape');
@@ -830,11 +828,13 @@ const getPathByDropTarget = (board, dropTarget) => {
830
828
  }
831
829
  // 水平布局/标准布局:上下是兄弟节点,左右是子节点
832
830
  if (isHorizontalLogicLayout(layout)) {
833
- if (dropTarget.detectResult === 'right' && !PlaitMind.isMind(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.target)) {
834
- targetPath.push(children.length);
835
- }
836
- if (dropTarget.detectResult === 'right' && PlaitMind.isMind(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.target) && isStandardLayout(layout)) {
837
- targetPath.push(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.target.rightNodeCount);
831
+ if (dropTarget.detectResult === 'right') {
832
+ if (PlaitMind.isMind(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.target) && isStandardLayout(layout)) {
833
+ targetPath.push(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.target.rightNodeCount);
834
+ }
835
+ else {
836
+ targetPath.push(children.length);
837
+ }
838
838
  }
839
839
  if (dropTarget.detectResult === 'left') {
840
840
  targetPath.push(children.length);
@@ -1011,9 +1011,10 @@ const transformPlacement = (placement, direction) => {
1011
1011
  };
1012
1012
 
1013
1013
  function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnderline = true, defaultStrokeWidth) {
1014
+ var _a;
1014
1015
  const branchShape = getBranchShapeByMindElement(board, node.origin);
1015
1016
  const branchWidth = defaultStrokeWidth || getBranchWidthByMindElement(board, node.origin);
1016
- const branchColor = defaultStroke || getBranchColorByMindElement(board, child.origin);
1017
+ const branchColor = defaultStroke || ((_a = node.origin) === null || _a === void 0 ? void 0 : _a.branchColor) || getBranchColorByMindElement(board, child.origin);
1017
1018
  const isUnderlineShape = getShapeByElement(board, child.origin) === MindElementShape.underline;
1018
1019
  let beginX, beginY, endX, endY, beginNode = node, endNode = child;
1019
1020
  const beginRectangle = getRectangleByNode(beginNode);
@@ -1049,7 +1050,8 @@ function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnde
1049
1050
  const polylinePoints = [
1050
1051
  [beginX, beginY],
1051
1052
  [beginX, endY],
1052
- [endX, endY]
1053
+ [endX, endY],
1054
+ isUnderlineShape && needDrawUnderline ? [endX + (endNode.width - endNode.hGap * 2) * plusMinus[0], endY] : [endX, endY]
1053
1055
  ];
1054
1056
  return drawLinearPath(polylinePoints, { stroke: branchColor, strokeWidth: branchWidth });
1055
1057
  }
@@ -1058,10 +1060,11 @@ function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnde
1058
1060
  }
1059
1061
 
1060
1062
  function drawLogicLink(board, parent, node, isHorizontal, defaultStroke = null, defaultStrokeWidth) {
1063
+ var _a;
1061
1064
  const branchShape = getBranchShapeByMindElement(board, parent.origin);
1062
- const branchColor = defaultStroke || getBranchColorByMindElement(board, node.origin);
1065
+ const branchColor = defaultStroke || ((_a = parent.origin) === null || _a === void 0 ? void 0 : _a.branchColor) || getBranchColorByMindElement(board, node.origin);
1063
1066
  const branchWidth = defaultStrokeWidth || getBranchWidthByMindElement(board, parent.origin);
1064
- const hasStraightLine = !parent.origin.isRoot;
1067
+ const hasStraightLine = branchShape === BranchShape.polyline ? true : !parent.origin.isRoot;
1065
1068
  const parentShape = getShapeByElement(board, parent.origin);
1066
1069
  const shape = node.origin.shape ? node.origin.shape : parentShape;
1067
1070
  const hasUnderlineShape = shape === MindElementShape.underline;
@@ -1952,7 +1955,7 @@ function drawAbstractLink(board, node, isHorizontal) {
1952
1955
  const branchWidth = getAbstractBranchWidth(board, node.origin);
1953
1956
  const branchColor = getAbstractBranchColor(board, node.origin);
1954
1957
  const parent = node.parent;
1955
- const branchShape = getBranchShapeByMindElement(board, parent.origin);
1958
+ const branchShape = getBranchShapeByMindElement(board, node.origin);
1956
1959
  const abstractRectangle = getRectangleByNode(node);
1957
1960
  let includedElements = parent.children.slice(node.origin.start, node.origin.end + 1).map(node => {
1958
1961
  return node.origin;
@@ -2171,7 +2174,9 @@ const setTopicSize = (board, element, width, height) => {
2171
2174
  height: height / board.viewport.zoom
2172
2175
  };
2173
2176
  const path = PlaitBoard.findPath(board, element);
2174
- Transforms.setNode(board, newElement, path);
2177
+ if (newElement.width !== element.width || newElement.height !== element.height) {
2178
+ Transforms.setNode(board, newElement, path);
2179
+ }
2175
2180
  };
2176
2181
  const removeElements = (board, elements) => {
2177
2182
  const deletableElements = getFirstLevelElement(elements);
@@ -2364,176 +2369,61 @@ class QuickInsertDrawer extends BaseDrawer {
2364
2369
  return true;
2365
2370
  }
2366
2371
  draw(element) {
2367
- let offset = element.children.length > 0 && !element.isRoot ? EXTEND_RADIUS : 0;
2368
2372
  const quickInsertG = createG();
2369
2373
  this.g = quickInsertG;
2370
2374
  quickInsertG.classList.add('quick-insert');
2371
2375
  const node = MindElement.getNode(element);
2372
- const { x, y, width, height } = getRectangleByNode(node);
2373
- /**
2374
- * 方位:
2375
- * 1. 左、左上、左下
2376
- * 2. 右、右上、右下
2377
- * 3. 上、上左、上右
2378
- * 4. 下、下左、下右
2379
- */
2380
- const shape = getShapeByElement(this.board, element);
2381
- // 形状是矩形要偏移边框的线宽
2382
- const branchWidth = getBranchWidthByMindElement(this.board, element);
2383
- let offsetBorderLineWidth = 0;
2384
- if (shape === MindElementShape.roundRectangle && offset === 0) {
2385
- offsetBorderLineWidth = branchWidth;
2386
- }
2387
- let offsetRootBorderLineWidth = 0;
2388
- if (element.isRoot) {
2389
- offsetRootBorderLineWidth = branchWidth;
2390
- }
2391
- // 当没有子节点时,需要缩小的偏移量
2392
- const extraOffset = 3;
2393
- const underlineCoordinates = {
2394
- // 画线方向:右向左 <--
2395
- [MindLayoutType.left]: {
2396
- // EXTEND_RADIUS * 0.5 是 左方向,折叠/收起的偏移量
2397
- startX: x - (offset > 0 ? offset + EXTEND_RADIUS * 0.5 : 0) - offsetRootBorderLineWidth,
2398
- startY: y + height,
2399
- endX: x -
2400
- offsetBorderLineWidth -
2401
- offsetRootBorderLineWidth -
2402
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) -
2403
- EXTEND_RADIUS,
2404
- endY: y + height
2405
- },
2406
- // 画线方向:左向右 -->
2407
- [MindLayoutType.right]: {
2408
- startX: x + width + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2409
- startY: y + height,
2410
- endX: x +
2411
- width +
2412
- offsetBorderLineWidth +
2413
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2414
- EXTEND_RADIUS +
2415
- offsetRootBorderLineWidth,
2416
- endY: y + height
2417
- },
2418
- // 画线方向:下向上 -->
2419
- [MindLayoutType.upward]: {
2420
- startX: x + width * 0.5,
2421
- startY: y - offsetBorderLineWidth - (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) - offsetRootBorderLineWidth,
2422
- endX: x + width * 0.5,
2423
- endY: y -
2424
- offsetBorderLineWidth -
2425
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) -
2426
- EXTEND_RADIUS -
2427
- offsetRootBorderLineWidth
2428
- },
2429
- // 画线方向:上向下 -->
2430
- [MindLayoutType.downward]: {
2431
- startX: x + width * 0.5,
2432
- startY: y + height + offsetBorderLineWidth + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2433
- endX: x + width * 0.5,
2434
- endY: y +
2435
- height +
2436
- offsetBorderLineWidth +
2437
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2438
- EXTEND_RADIUS +
2439
- offsetRootBorderLineWidth
2440
- },
2441
- [MindLayoutType.leftBottomIndented]: {
2442
- startX: x + width * 0.5,
2443
- startY: y + height + offsetBorderLineWidth + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2444
- endX: x + width * 0.5,
2445
- endY: y +
2446
- height +
2447
- offsetBorderLineWidth +
2448
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2449
- EXTEND_RADIUS +
2450
- offsetRootBorderLineWidth
2451
- },
2452
- [MindLayoutType.leftTopIndented]: {
2453
- startX: x + width * 0.5,
2454
- startY: y - offsetBorderLineWidth - (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) - offsetRootBorderLineWidth,
2455
- endX: x + width * 0.5,
2456
- endY: y -
2457
- offsetBorderLineWidth -
2458
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) -
2459
- EXTEND_RADIUS -
2460
- offsetRootBorderLineWidth
2461
- },
2462
- [MindLayoutType.rightBottomIndented]: {
2463
- startX: x + width * 0.5,
2464
- startY: y + height + offsetBorderLineWidth + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2465
- endX: x + width * 0.5,
2466
- endY: y +
2467
- height +
2468
- offsetBorderLineWidth +
2469
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2470
- EXTEND_RADIUS +
2471
- offsetRootBorderLineWidth
2472
- },
2473
- [MindLayoutType.rightTopIndented]: {
2474
- startX: x + width * 0.5,
2475
- startY: y - offsetBorderLineWidth - (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) - offsetRootBorderLineWidth,
2476
- endX: x + width * 0.5,
2477
- endY: y -
2478
- offsetBorderLineWidth -
2479
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) -
2480
- EXTEND_RADIUS -
2481
- offsetRootBorderLineWidth
2482
- }
2483
- };
2484
- if (shape === MindElementShape.roundRectangle || element.isRoot) {
2485
- underlineCoordinates[MindLayoutType.left].startY -= height * 0.5;
2486
- underlineCoordinates[MindLayoutType.left].endY -= height * 0.5;
2487
- underlineCoordinates[MindLayoutType.right].startY -= height * 0.5;
2488
- underlineCoordinates[MindLayoutType.right].endY -= height * 0.5;
2376
+ const layout = MindQueries.getLayoutByElement(element);
2377
+ const isHorizontal = isHorizontalLayout(layout);
2378
+ let linkDirection = getLayoutDirection(node, isHorizontal);
2379
+ if (isIndentedLayout(layout)) {
2380
+ linkDirection = isTopLayout(layout) ? LayoutDirection.top : LayoutDirection.bottom;
2489
2381
  }
2382
+ const isUnderlineShape = getShapeByElement(this.board, element) === MindElementShape.underline;
2383
+ const nodeClient = getRectangleByNode(node);
2384
+ const branchWidth = getBranchWidthByMindElement(this.board, element);
2490
2385
  const branchColor = PlaitMind.isMind(element)
2491
2386
  ? getNextBranchColor(this.board, element)
2492
2387
  : getBranchColorByMindElement(this.board, element);
2493
- let nodeLayout = MindQueries.getCorrectLayoutByElement(this.board, element);
2494
- if (element.isRoot && isStandardLayout(nodeLayout)) {
2495
- const root = element;
2496
- nodeLayout = root.children.length >= root.rightNodeCount ? MindLayoutType.left : MindLayoutType.right;
2497
- }
2498
- const underlineCoordinate = underlineCoordinates[nodeLayout];
2499
- if (underlineCoordinate) {
2500
- const underline = PlaitBoard.getRoughSVG(this.board).line(underlineCoordinate.startX, underlineCoordinate.startY, underlineCoordinate.endX, underlineCoordinate.endY, { stroke: branchColor, strokeWidth: branchWidth });
2501
- const circleCoordinates = {
2502
- startX: underlineCoordinate.endX,
2503
- startY: underlineCoordinate.endY
2504
- };
2505
- const circle = PlaitBoard.getRoughSVG(this.board).circle(circleCoordinates.startX, circleCoordinates.startY, EXTEND_RADIUS, {
2506
- fill: QUICK_INSERT_CIRCLE_COLOR,
2507
- stroke: QUICK_INSERT_CIRCLE_COLOR,
2508
- fillStyle: 'solid'
2509
- });
2510
- const innerCrossCoordinates = {
2511
- horizontal: {
2512
- startX: circleCoordinates.startX - EXTEND_RADIUS * 0.5 + 3,
2513
- startY: circleCoordinates.startY,
2514
- endX: circleCoordinates.startX + EXTEND_RADIUS * 0.5 - 3,
2515
- endY: circleCoordinates.startY
2516
- },
2517
- vertical: {
2518
- startX: circleCoordinates.startX,
2519
- startY: circleCoordinates.startY - EXTEND_RADIUS * 0.5 + 3,
2520
- endX: circleCoordinates.startX,
2521
- endY: circleCoordinates.startY + EXTEND_RADIUS * 0.5 - 3
2522
- }
2523
- };
2524
- const innerCrossHLine = PlaitBoard.getRoughSVG(this.board).line(innerCrossCoordinates.horizontal.startX, innerCrossCoordinates.horizontal.startY, innerCrossCoordinates.horizontal.endX, innerCrossCoordinates.horizontal.endY, {
2525
- stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2526
- strokeWidth: 2
2527
- });
2528
- const innerRingVLine = PlaitBoard.getRoughSVG(this.board).line(innerCrossCoordinates.vertical.startX, innerCrossCoordinates.vertical.startY, innerCrossCoordinates.vertical.endX, innerCrossCoordinates.vertical.endY, {
2529
- stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2530
- strokeWidth: 2
2531
- });
2532
- quickInsertG.appendChild(underline);
2533
- quickInsertG.appendChild(circle);
2534
- quickInsertG.appendChild(innerCrossHLine);
2535
- quickInsertG.appendChild(innerRingVLine);
2388
+ let distance = 8;
2389
+ let placement = [HorizontalPlacement.right, VerticalPlacement.middle];
2390
+ transformPlacement(placement, linkDirection);
2391
+ // underline shape and horizontal
2392
+ if (isHorizontal && isUnderlineShape && !element.isRoot) {
2393
+ placement[1] = VerticalPlacement.bottom;
2394
+ }
2395
+ let beginPoint = getPointByPlacement(nodeClient, placement);
2396
+ if (element.children.length > 0 && !element.isRoot) {
2397
+ beginPoint = moveXOfPoint(beginPoint, EXTEND_RADIUS + 8, linkDirection);
2398
+ distance = 5;
2536
2399
  }
2400
+ const endPoint = moveXOfPoint(beginPoint, distance, linkDirection);
2401
+ const circleCenter = moveXOfPoint(endPoint, 8, linkDirection);
2402
+ const line = PlaitBoard.getRoughSVG(this.board).line(beginPoint[0], beginPoint[1], endPoint[0], endPoint[1], {
2403
+ stroke: branchColor,
2404
+ strokeWidth: branchWidth
2405
+ });
2406
+ const circle = PlaitBoard.getRoughSVG(this.board).circle(circleCenter[0], circleCenter[1], EXTEND_RADIUS, {
2407
+ fill: QUICK_INSERT_CIRCLE_COLOR,
2408
+ stroke: QUICK_INSERT_CIRCLE_COLOR,
2409
+ fillStyle: 'solid'
2410
+ });
2411
+ const HLineBeginPoint = [circleCenter[0] - 5, circleCenter[1]];
2412
+ const HLineEndPoint = [circleCenter[0] + 5, circleCenter[1]];
2413
+ const VLineBeginPoint = [circleCenter[0], circleCenter[1] - 5];
2414
+ const VLineEndPoint = [circleCenter[0], circleCenter[1] + 5];
2415
+ const innerCrossHLine = PlaitBoard.getRoughSVG(this.board).line(HLineBeginPoint[0], HLineBeginPoint[1], HLineEndPoint[0], HLineEndPoint[1], {
2416
+ stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2417
+ strokeWidth: 2
2418
+ });
2419
+ const innerCrossVLine = PlaitBoard.getRoughSVG(this.board).line(VLineBeginPoint[0], VLineBeginPoint[1], VLineEndPoint[0], VLineEndPoint[1], {
2420
+ stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2421
+ strokeWidth: 2
2422
+ });
2423
+ quickInsertG.appendChild(line);
2424
+ quickInsertG.appendChild(circle);
2425
+ quickInsertG.appendChild(innerCrossHLine);
2426
+ quickInsertG.appendChild(innerCrossVLine);
2537
2427
  return quickInsertG;
2538
2428
  }
2539
2429
  afterDraw(element) {
@@ -2914,7 +2804,7 @@ class MindNodeComponent extends PlaitPluginElementComponent {
2914
2804
  const hideCircleG = this.roughSVG.circle(extendLineXY[1][0] + circleOffset[0], extendLineXY[1][1] + circleOffset[1], EXTEND_RADIUS - 1, {
2915
2805
  fill: '#fff',
2916
2806
  stroke,
2917
- strokeWidth: branchWidth,
2807
+ strokeWidth: branchWidth > 3 ? 3 : branchWidth,
2918
2808
  fillStyle: 'solid'
2919
2809
  });
2920
2810
  collapseG.appendChild(hideCircleG);
@@ -3237,7 +3127,10 @@ const withDnd = (board) => {
3237
3127
  let dropTarget = null;
3238
3128
  let targetPath;
3239
3129
  board.mousedown = (event) => {
3240
- if (board.options.readonly || IS_TEXT_EDITABLE.get(board) || event.button === 2) {
3130
+ if (PlaitBoard.isReadonly(board) ||
3131
+ PlaitBoard.hasBeenTextEditing(board) ||
3132
+ !PlaitBoard.isPointer(board, PlaitPointerType.selection) ||
3133
+ event.button === 2) {
3241
3134
  mousedown(event);
3242
3135
  return;
3243
3136
  }
@@ -3270,6 +3163,7 @@ const withDnd = (board) => {
3270
3163
  });
3271
3164
  if (activeElements.length) {
3272
3165
  correspondingElements = getOverallAbstracts(board, activeElements);
3166
+ event.preventDefault();
3273
3167
  }
3274
3168
  mousedown(event);
3275
3169
  };
@@ -3671,6 +3565,7 @@ const withCreateMind = (board) => {
3671
3565
  const targetPoint = transformPoint(board, toPoint(movingPoint[0], movingPoint[1], PlaitBoard.getHost(board)));
3672
3566
  const emptyMind = createEmptyMind(board, targetPoint);
3673
3567
  Transforms.insertNode(board, emptyMind, [board.children.length]);
3568
+ clearSelectedElement(board);
3674
3569
  addSelectedElement(board, emptyMind);
3675
3570
  BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
3676
3571
  }