@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.
@@ -591,8 +591,7 @@ const getAvailableProperty = (board, element, propertyKey) => {
591
591
  */
592
592
  const getBranchColorByMindElement = (board, element) => {
593
593
  const branchColor = getAvailableProperty(board, element, 'branchColor');
594
- const parentBranchColor = MindElement.getParent(element)?.branchColor;
595
- return parentBranchColor || branchColor || getDefaultBranchColor(board, element);
594
+ return branchColor || getDefaultBranchColor(board, element);
596
595
  };
597
596
  const getBranchShapeByMindElement = (board, element) => {
598
597
  const branchShape = getAvailableProperty(board, element, 'branchShape');
@@ -864,11 +863,13 @@ const getPathByDropTarget = (board, dropTarget) => {
864
863
  }
865
864
  // 水平布局/标准布局:上下是兄弟节点,左右是子节点
866
865
  if (isHorizontalLogicLayout(layout)) {
867
- if (dropTarget.detectResult === 'right' && !PlaitMind.isMind(dropTarget?.target)) {
868
- targetPath.push(children.length);
869
- }
870
- if (dropTarget.detectResult === 'right' && PlaitMind.isMind(dropTarget?.target) && isStandardLayout(layout)) {
871
- targetPath.push(dropTarget?.target.rightNodeCount);
866
+ if (dropTarget.detectResult === 'right') {
867
+ if (PlaitMind.isMind(dropTarget?.target) && isStandardLayout(layout)) {
868
+ targetPath.push(dropTarget?.target.rightNodeCount);
869
+ }
870
+ else {
871
+ targetPath.push(children.length);
872
+ }
872
873
  }
873
874
  if (dropTarget.detectResult === 'left') {
874
875
  targetPath.push(children.length);
@@ -1047,7 +1048,7 @@ const transformPlacement = (placement, direction) => {
1047
1048
  function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnderline = true, defaultStrokeWidth) {
1048
1049
  const branchShape = getBranchShapeByMindElement(board, node.origin);
1049
1050
  const branchWidth = defaultStrokeWidth || getBranchWidthByMindElement(board, node.origin);
1050
- const branchColor = defaultStroke || getBranchColorByMindElement(board, child.origin);
1051
+ const branchColor = defaultStroke || node.origin?.branchColor || getBranchColorByMindElement(board, child.origin);
1051
1052
  const isUnderlineShape = getShapeByElement(board, child.origin) === MindElementShape.underline;
1052
1053
  let beginX, beginY, endX, endY, beginNode = node, endNode = child;
1053
1054
  const beginRectangle = getRectangleByNode(beginNode);
@@ -1083,7 +1084,8 @@ function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnde
1083
1084
  const polylinePoints = [
1084
1085
  [beginX, beginY],
1085
1086
  [beginX, endY],
1086
- [endX, endY]
1087
+ [endX, endY],
1088
+ isUnderlineShape && needDrawUnderline ? [endX + (endNode.width - endNode.hGap * 2) * plusMinus[0], endY] : [endX, endY]
1087
1089
  ];
1088
1090
  return drawLinearPath(polylinePoints, { stroke: branchColor, strokeWidth: branchWidth });
1089
1091
  }
@@ -1093,9 +1095,9 @@ function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnde
1093
1095
 
1094
1096
  function drawLogicLink(board, parent, node, isHorizontal, defaultStroke = null, defaultStrokeWidth) {
1095
1097
  const branchShape = getBranchShapeByMindElement(board, parent.origin);
1096
- const branchColor = defaultStroke || getBranchColorByMindElement(board, node.origin);
1098
+ const branchColor = defaultStroke || parent.origin?.branchColor || getBranchColorByMindElement(board, node.origin);
1097
1099
  const branchWidth = defaultStrokeWidth || getBranchWidthByMindElement(board, parent.origin);
1098
- const hasStraightLine = !parent.origin.isRoot;
1100
+ const hasStraightLine = branchShape === BranchShape.polyline ? true : !parent.origin.isRoot;
1099
1101
  const parentShape = getShapeByElement(board, parent.origin);
1100
1102
  const shape = node.origin.shape ? node.origin.shape : parentShape;
1101
1103
  const hasUnderlineShape = shape === MindElementShape.underline;
@@ -2009,7 +2011,7 @@ function drawAbstractLink(board, node, isHorizontal) {
2009
2011
  const branchWidth = getAbstractBranchWidth(board, node.origin);
2010
2012
  const branchColor = getAbstractBranchColor(board, node.origin);
2011
2013
  const parent = node.parent;
2012
- const branchShape = getBranchShapeByMindElement(board, parent.origin);
2014
+ const branchShape = getBranchShapeByMindElement(board, node.origin);
2013
2015
  const abstractRectangle = getRectangleByNode(node);
2014
2016
  let includedElements = parent.children.slice(node.origin.start, node.origin.end + 1).map(node => {
2015
2017
  return node.origin;
@@ -2226,7 +2228,9 @@ const setTopicSize = (board, element, width, height) => {
2226
2228
  height: height / board.viewport.zoom
2227
2229
  };
2228
2230
  const path = PlaitBoard.findPath(board, element);
2229
- Transforms.setNode(board, newElement, path);
2231
+ if (newElement.width !== element.width || newElement.height !== element.height) {
2232
+ Transforms.setNode(board, newElement, path);
2233
+ }
2230
2234
  };
2231
2235
  const removeElements = (board, elements) => {
2232
2236
  const deletableElements = getFirstLevelElement(elements);
@@ -2422,176 +2426,61 @@ class QuickInsertDrawer extends BaseDrawer {
2422
2426
  return true;
2423
2427
  }
2424
2428
  draw(element) {
2425
- let offset = element.children.length > 0 && !element.isRoot ? EXTEND_RADIUS : 0;
2426
2429
  const quickInsertG = createG();
2427
2430
  this.g = quickInsertG;
2428
2431
  quickInsertG.classList.add('quick-insert');
2429
2432
  const node = MindElement.getNode(element);
2430
- const { x, y, width, height } = getRectangleByNode(node);
2431
- /**
2432
- * 方位:
2433
- * 1. 左、左上、左下
2434
- * 2. 右、右上、右下
2435
- * 3. 上、上左、上右
2436
- * 4. 下、下左、下右
2437
- */
2438
- const shape = getShapeByElement(this.board, element);
2439
- // 形状是矩形要偏移边框的线宽
2440
- const branchWidth = getBranchWidthByMindElement(this.board, element);
2441
- let offsetBorderLineWidth = 0;
2442
- if (shape === MindElementShape.roundRectangle && offset === 0) {
2443
- offsetBorderLineWidth = branchWidth;
2444
- }
2445
- let offsetRootBorderLineWidth = 0;
2446
- if (element.isRoot) {
2447
- offsetRootBorderLineWidth = branchWidth;
2448
- }
2449
- // 当没有子节点时,需要缩小的偏移量
2450
- const extraOffset = 3;
2451
- const underlineCoordinates = {
2452
- // 画线方向:右向左 <--
2453
- [MindLayoutType.left]: {
2454
- // EXTEND_RADIUS * 0.5 是 左方向,折叠/收起的偏移量
2455
- startX: x - (offset > 0 ? offset + EXTEND_RADIUS * 0.5 : 0) - offsetRootBorderLineWidth,
2456
- startY: y + height,
2457
- endX: x -
2458
- offsetBorderLineWidth -
2459
- offsetRootBorderLineWidth -
2460
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) -
2461
- EXTEND_RADIUS,
2462
- endY: y + height
2463
- },
2464
- // 画线方向:左向右 -->
2465
- [MindLayoutType.right]: {
2466
- startX: x + width + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2467
- startY: y + height,
2468
- endX: x +
2469
- width +
2470
- offsetBorderLineWidth +
2471
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2472
- EXTEND_RADIUS +
2473
- offsetRootBorderLineWidth,
2474
- endY: y + height
2475
- },
2476
- // 画线方向:下向上 -->
2477
- [MindLayoutType.upward]: {
2478
- startX: x + width * 0.5,
2479
- startY: y - offsetBorderLineWidth - (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) - offsetRootBorderLineWidth,
2480
- endX: x + width * 0.5,
2481
- endY: y -
2482
- offsetBorderLineWidth -
2483
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) -
2484
- EXTEND_RADIUS -
2485
- offsetRootBorderLineWidth
2486
- },
2487
- // 画线方向:上向下 -->
2488
- [MindLayoutType.downward]: {
2489
- startX: x + width * 0.5,
2490
- startY: y + height + offsetBorderLineWidth + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2491
- endX: x + width * 0.5,
2492
- endY: y +
2493
- height +
2494
- offsetBorderLineWidth +
2495
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2496
- EXTEND_RADIUS +
2497
- offsetRootBorderLineWidth
2498
- },
2499
- [MindLayoutType.leftBottomIndented]: {
2500
- startX: x + width * 0.5,
2501
- startY: y + height + offsetBorderLineWidth + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2502
- endX: x + width * 0.5,
2503
- endY: y +
2504
- height +
2505
- offsetBorderLineWidth +
2506
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2507
- EXTEND_RADIUS +
2508
- offsetRootBorderLineWidth
2509
- },
2510
- [MindLayoutType.leftTopIndented]: {
2511
- startX: x + width * 0.5,
2512
- startY: y - offsetBorderLineWidth - (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) - offsetRootBorderLineWidth,
2513
- endX: x + width * 0.5,
2514
- endY: y -
2515
- offsetBorderLineWidth -
2516
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) -
2517
- EXTEND_RADIUS -
2518
- offsetRootBorderLineWidth
2519
- },
2520
- [MindLayoutType.rightBottomIndented]: {
2521
- startX: x + width * 0.5,
2522
- startY: y + height + offsetBorderLineWidth + (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) + offsetRootBorderLineWidth,
2523
- endX: x + width * 0.5,
2524
- endY: y +
2525
- height +
2526
- offsetBorderLineWidth +
2527
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET - extraOffset : 0) +
2528
- EXTEND_RADIUS +
2529
- offsetRootBorderLineWidth
2530
- },
2531
- [MindLayoutType.rightTopIndented]: {
2532
- startX: x + width * 0.5,
2533
- startY: y - offsetBorderLineWidth - (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) - offsetRootBorderLineWidth,
2534
- endX: x + width * 0.5,
2535
- endY: y -
2536
- offsetBorderLineWidth -
2537
- (offset > 0 ? offset + QUICK_INSERT_CIRCLE_OFFSET : 0) -
2538
- EXTEND_RADIUS -
2539
- offsetRootBorderLineWidth
2540
- }
2541
- };
2542
- if (shape === MindElementShape.roundRectangle || element.isRoot) {
2543
- underlineCoordinates[MindLayoutType.left].startY -= height * 0.5;
2544
- underlineCoordinates[MindLayoutType.left].endY -= height * 0.5;
2545
- underlineCoordinates[MindLayoutType.right].startY -= height * 0.5;
2546
- underlineCoordinates[MindLayoutType.right].endY -= height * 0.5;
2433
+ const layout = MindQueries.getLayoutByElement(element);
2434
+ const isHorizontal = isHorizontalLayout(layout);
2435
+ let linkDirection = getLayoutDirection(node, isHorizontal);
2436
+ if (isIndentedLayout(layout)) {
2437
+ linkDirection = isTopLayout(layout) ? LayoutDirection.top : LayoutDirection.bottom;
2547
2438
  }
2439
+ const isUnderlineShape = getShapeByElement(this.board, element) === MindElementShape.underline;
2440
+ const nodeClient = getRectangleByNode(node);
2441
+ const branchWidth = getBranchWidthByMindElement(this.board, element);
2548
2442
  const branchColor = PlaitMind.isMind(element)
2549
2443
  ? getNextBranchColor(this.board, element)
2550
2444
  : getBranchColorByMindElement(this.board, element);
2551
- let nodeLayout = MindQueries.getCorrectLayoutByElement(this.board, element);
2552
- if (element.isRoot && isStandardLayout(nodeLayout)) {
2553
- const root = element;
2554
- nodeLayout = root.children.length >= root.rightNodeCount ? MindLayoutType.left : MindLayoutType.right;
2555
- }
2556
- const underlineCoordinate = underlineCoordinates[nodeLayout];
2557
- if (underlineCoordinate) {
2558
- const underline = PlaitBoard.getRoughSVG(this.board).line(underlineCoordinate.startX, underlineCoordinate.startY, underlineCoordinate.endX, underlineCoordinate.endY, { stroke: branchColor, strokeWidth: branchWidth });
2559
- const circleCoordinates = {
2560
- startX: underlineCoordinate.endX,
2561
- startY: underlineCoordinate.endY
2562
- };
2563
- const circle = PlaitBoard.getRoughSVG(this.board).circle(circleCoordinates.startX, circleCoordinates.startY, EXTEND_RADIUS, {
2564
- fill: QUICK_INSERT_CIRCLE_COLOR,
2565
- stroke: QUICK_INSERT_CIRCLE_COLOR,
2566
- fillStyle: 'solid'
2567
- });
2568
- const innerCrossCoordinates = {
2569
- horizontal: {
2570
- startX: circleCoordinates.startX - EXTEND_RADIUS * 0.5 + 3,
2571
- startY: circleCoordinates.startY,
2572
- endX: circleCoordinates.startX + EXTEND_RADIUS * 0.5 - 3,
2573
- endY: circleCoordinates.startY
2574
- },
2575
- vertical: {
2576
- startX: circleCoordinates.startX,
2577
- startY: circleCoordinates.startY - EXTEND_RADIUS * 0.5 + 3,
2578
- endX: circleCoordinates.startX,
2579
- endY: circleCoordinates.startY + EXTEND_RADIUS * 0.5 - 3
2580
- }
2581
- };
2582
- const innerCrossHLine = PlaitBoard.getRoughSVG(this.board).line(innerCrossCoordinates.horizontal.startX, innerCrossCoordinates.horizontal.startY, innerCrossCoordinates.horizontal.endX, innerCrossCoordinates.horizontal.endY, {
2583
- stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2584
- strokeWidth: 2
2585
- });
2586
- const innerRingVLine = PlaitBoard.getRoughSVG(this.board).line(innerCrossCoordinates.vertical.startX, innerCrossCoordinates.vertical.startY, innerCrossCoordinates.vertical.endX, innerCrossCoordinates.vertical.endY, {
2587
- stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2588
- strokeWidth: 2
2589
- });
2590
- quickInsertG.appendChild(underline);
2591
- quickInsertG.appendChild(circle);
2592
- quickInsertG.appendChild(innerCrossHLine);
2593
- quickInsertG.appendChild(innerRingVLine);
2445
+ let distance = 8;
2446
+ let placement = [HorizontalPlacement.right, VerticalPlacement.middle];
2447
+ transformPlacement(placement, linkDirection);
2448
+ // underline shape and horizontal
2449
+ if (isHorizontal && isUnderlineShape && !element.isRoot) {
2450
+ placement[1] = VerticalPlacement.bottom;
2594
2451
  }
2452
+ let beginPoint = getPointByPlacement(nodeClient, placement);
2453
+ if (element.children.length > 0 && !element.isRoot) {
2454
+ beginPoint = moveXOfPoint(beginPoint, EXTEND_RADIUS + 8, linkDirection);
2455
+ distance = 5;
2456
+ }
2457
+ const endPoint = moveXOfPoint(beginPoint, distance, linkDirection);
2458
+ const circleCenter = moveXOfPoint(endPoint, 8, linkDirection);
2459
+ const line = PlaitBoard.getRoughSVG(this.board).line(beginPoint[0], beginPoint[1], endPoint[0], endPoint[1], {
2460
+ stroke: branchColor,
2461
+ strokeWidth: branchWidth
2462
+ });
2463
+ const circle = PlaitBoard.getRoughSVG(this.board).circle(circleCenter[0], circleCenter[1], EXTEND_RADIUS, {
2464
+ fill: QUICK_INSERT_CIRCLE_COLOR,
2465
+ stroke: QUICK_INSERT_CIRCLE_COLOR,
2466
+ fillStyle: 'solid'
2467
+ });
2468
+ const HLineBeginPoint = [circleCenter[0] - 5, circleCenter[1]];
2469
+ const HLineEndPoint = [circleCenter[0] + 5, circleCenter[1]];
2470
+ const VLineBeginPoint = [circleCenter[0], circleCenter[1] - 5];
2471
+ const VLineEndPoint = [circleCenter[0], circleCenter[1] + 5];
2472
+ const innerCrossHLine = PlaitBoard.getRoughSVG(this.board).line(HLineBeginPoint[0], HLineBeginPoint[1], HLineEndPoint[0], HLineEndPoint[1], {
2473
+ stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2474
+ strokeWidth: 2
2475
+ });
2476
+ const innerCrossVLine = PlaitBoard.getRoughSVG(this.board).line(VLineBeginPoint[0], VLineBeginPoint[1], VLineEndPoint[0], VLineEndPoint[1], {
2477
+ stroke: QUICK_INSERT_INNER_CROSS_COLOR,
2478
+ strokeWidth: 2
2479
+ });
2480
+ quickInsertG.appendChild(line);
2481
+ quickInsertG.appendChild(circle);
2482
+ quickInsertG.appendChild(innerCrossHLine);
2483
+ quickInsertG.appendChild(innerCrossVLine);
2595
2484
  return quickInsertG;
2596
2485
  }
2597
2486
  afterDraw(element) {
@@ -2969,7 +2858,7 @@ class MindNodeComponent extends PlaitPluginElementComponent {
2969
2858
  const hideCircleG = this.roughSVG.circle(extendLineXY[1][0] + circleOffset[0], extendLineXY[1][1] + circleOffset[1], EXTEND_RADIUS - 1, {
2970
2859
  fill: '#fff',
2971
2860
  stroke,
2972
- strokeWidth: branchWidth,
2861
+ strokeWidth: branchWidth > 3 ? 3 : branchWidth,
2973
2862
  fillStyle: 'solid'
2974
2863
  });
2975
2864
  collapseG.appendChild(hideCircleG);
@@ -3289,7 +3178,10 @@ const withDnd = (board) => {
3289
3178
  let dropTarget = null;
3290
3179
  let targetPath;
3291
3180
  board.mousedown = (event) => {
3292
- if (board.options.readonly || IS_TEXT_EDITABLE.get(board) || event.button === 2) {
3181
+ if (PlaitBoard.isReadonly(board) ||
3182
+ PlaitBoard.hasBeenTextEditing(board) ||
3183
+ !PlaitBoard.isPointer(board, PlaitPointerType.selection) ||
3184
+ event.button === 2) {
3293
3185
  mousedown(event);
3294
3186
  return;
3295
3187
  }
@@ -3322,6 +3214,7 @@ const withDnd = (board) => {
3322
3214
  });
3323
3215
  if (activeElements.length) {
3324
3216
  correspondingElements = getOverallAbstracts(board, activeElements);
3217
+ event.preventDefault();
3325
3218
  }
3326
3219
  mousedown(event);
3327
3220
  };
@@ -3729,6 +3622,7 @@ const withCreateMind = (board) => {
3729
3622
  const targetPoint = transformPoint(board, toPoint(movingPoint[0], movingPoint[1], PlaitBoard.getHost(board)));
3730
3623
  const emptyMind = createEmptyMind(board, targetPoint);
3731
3624
  Transforms.insertNode(board, emptyMind, [board.children.length]);
3625
+ clearSelectedElement(board);
3732
3626
  addSelectedElement(board, emptyMind);
3733
3627
  BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
3734
3628
  }