@plait/mind 0.14.0 → 0.16.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.
Files changed (33) hide show
  1. package/constants/default.d.ts +1 -0
  2. package/constants/node-topic-style.d.ts +2 -0
  3. package/esm2020/constants/default.mjs +2 -1
  4. package/esm2020/constants/node-topic-style.mjs +3 -1
  5. package/esm2020/interfaces/options.mjs +1 -1
  6. package/esm2020/node.component.mjs +8 -5
  7. package/esm2020/plugins/with-abstract-resize.board.mjs +1 -1
  8. package/esm2020/plugins/with-mind-create.mjs +3 -3
  9. package/esm2020/plugins/with-mind-extend.mjs +3 -4
  10. package/esm2020/plugins/with-mind-hotkey.mjs +42 -32
  11. package/esm2020/plugins/with-mind.board.mjs +1 -1
  12. package/esm2020/plugins/with-mind.mjs +7 -9
  13. package/esm2020/plugins/with-node-dnd.mjs +13 -6
  14. package/esm2020/transforms/abstract-node.mjs +1 -3
  15. package/esm2020/utils/abstract/common.mjs +5 -1
  16. package/esm2020/utils/clipboard.mjs +14 -5
  17. package/esm2020/utils/draw/node-link/indented-link.mjs +4 -15
  18. package/esm2020/utils/node/adjust-node.mjs +3 -7
  19. package/esm2020/utils/node-style/branch.mjs +6 -1
  20. package/esm2020/utils/node-style/shape.mjs +8 -1
  21. package/esm2020/utils/space/emoji.mjs +3 -2
  22. package/esm2020/utils/space/node-space.mjs +3 -2
  23. package/fesm2015/plait-mind.mjs +259 -239
  24. package/fesm2015/plait-mind.mjs.map +1 -1
  25. package/fesm2020/plait-mind.mjs +259 -239
  26. package/fesm2020/plait-mind.mjs.map +1 -1
  27. package/interfaces/options.d.ts +2 -1
  28. package/package.json +1 -1
  29. package/plugins/with-abstract-resize.board.d.ts +2 -2
  30. package/plugins/with-mind-hotkey.d.ts +2 -0
  31. package/plugins/with-mind.board.d.ts +0 -2
  32. package/utils/abstract/common.d.ts +1 -0
  33. package/utils/clipboard.d.ts +1 -1
@@ -1,9 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Component, ChangeDetectionStrategy, NgModule, NgZone, Directive, Input, HostListener } from '@angular/core';
3
3
  import * as i2 from '@plait/core';
4
- import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, RectangleClient, PlaitElement, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitBoard, depthFirstRecursion, Path, drawLinearPath, createG, updateForeignObject, PlaitNode, drawRoundRectangle, getRectangleByElements, getSelectedElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, drawAbstractRoundRectangle, createText, PlaitPointerType, PlaitPluginElementComponent, NODE_TO_INDEX, PlaitModule, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CLIP_BOARD_FORMAT_KEY, isMainPointer, BOARD_TO_HOST, PlaitPluginKey, throttleRAF, BoardTransforms, removeSelectedElement, PlaitHistoryBoard, hotkeys } from '@plait/core';
5
- import { MindLayoutType, isIndentedLayout, getNonAbstractChildren, isStandardLayout, AbstractNode, isLeftLayout, isRightLayout, isVerticalLogicLayout, isHorizontalLogicLayout, isTopLayout, isBottomLayout, isHorizontalLayout, getCorrectStartEnd, getAbstractLayout, ConnectingPosition, GlobalLayout } from '@plait/layouts';
6
- import { TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, TextModule, getTextFromClipboard } from '@plait/text';
4
+ import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, RectangleClient, PlaitElement, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Path, PlaitBoard, depthFirstRecursion, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, getSelectedElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, drawAbstractRoundRectangle, createText, PlaitPointerType, PlaitPluginElementComponent, NODE_TO_INDEX, PlaitModule, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CLIP_BOARD_FORMAT_KEY, isMainPointer, BOARD_TO_HOST, PlaitPluginKey, throttleRAF, BoardTransforms, removeSelectedElement, PlaitHistoryBoard, hotkeys } from '@plait/core';
5
+ import { MindLayoutType, isIndentedLayout, AbstractNode, getNonAbstractChildren, isStandardLayout, isLeftLayout, isRightLayout, isVerticalLogicLayout, isHorizontalLogicLayout, isTopLayout, isBottomLayout, isHorizontalLayout, getCorrectStartEnd, getAbstractLayout, ConnectingPosition, GlobalLayout } from '@plait/layouts';
6
+ import { TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, ExitOrigin, TextModule, getTextFromClipboard } from '@plait/text';
7
7
  import { fromEvent, Subject } from 'rxjs';
8
8
  import { Node, Path as Path$1 } from 'slate';
9
9
  import { isKeyHotkey } from 'is-hotkey';
@@ -149,6 +149,7 @@ const MindThemeColor = {
149
149
  }
150
150
  };
151
151
 
152
+ const WithMindPluginKey = 'plait-mind-plugin-key';
152
153
  const BASE = 4;
153
154
  const PRIMARY_COLOR = '#6698FF';
154
155
  const TRANSPARENT = 'transparent';
@@ -162,7 +163,7 @@ const QUICK_INSERT_CIRCLE_COLOR = '#6698FF';
162
163
  const QUICK_INSERT_INNER_CROSS_COLOR = 'white';
163
164
 
164
165
  function getEmojisWidthHeight(board, element) {
165
- const options = board.getMindOptions();
166
+ const options = board.getPluginOptions(WithMindPluginKey);
166
167
  const count = element.data.emojis.length;
167
168
  const fontSize = getEmojiFontSize(element);
168
169
  return {
@@ -242,7 +243,7 @@ const NodeSpace = {
242
243
  return nodeAndText;
243
244
  },
244
245
  getEmojiLeftSpace(board, element) {
245
- const options = board.getMindOptions();
246
+ const options = board.getPluginOptions(WithMindPluginKey);
246
247
  const nodeAndText = getHorizontalSpaceBetweenNodeAndText(board, element);
247
248
  return nodeAndText - options.emojiPadding;
248
249
  },
@@ -305,6 +306,8 @@ const TOPIC_FONT_SIZE = 14;
305
306
  const ROOT_TOPIC_FONT_SIZE = 18;
306
307
  const ROOT_TOPIC_HEIGHT = 25;
307
308
  const TOPIC_DEFAULT_MAX_WORD_COUNT = 34;
309
+ const DEFAULT_FONT_FAMILY = 'PingFangSC-Regular, "PingFang SC"';
310
+ const BRANCH_FONT_FAMILY = 'PingFangSC-Medium, "PingFang SC"';
308
311
 
309
312
  const createEmptyMind = (point) => {
310
313
  const element = createMindElement('思维导图', 72, ROOT_TOPIC_HEIGHT, { layout: MindLayoutType.right });
@@ -555,10 +558,6 @@ const adjustRootToNode = (board, node) => {
555
558
  delete newNode.isRoot;
556
559
  delete newNode.rightNodeCount;
557
560
  delete newNode.type;
558
- const text = Node.string(node.data.topic.children[0]) || ' ';
559
- const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT);
560
- newNode.width = Math.max(width, NODE_MIN_WIDTH);
561
- newNode.height = height;
562
561
  if (newNode.layout === MindLayoutType.standard) {
563
562
  delete newNode.layout;
564
563
  }
@@ -583,7 +582,7 @@ const adjustNodeToRoot = (board, node) => {
583
582
  newElement === null || newElement === void 0 ? true : delete newElement.isCollapsed;
584
583
  const { width, height } = getTextSize(board, newElement.data.topic, TOPIC_DEFAULT_MAX_WORD_COUNT, {
585
584
  fontSize: ROOT_TOPIC_FONT_SIZE,
586
- fontFamily: 'PingFangSC-Medium, "PingFang SC"'
585
+ fontFamily: BRANCH_FONT_FAMILY
587
586
  });
588
587
  newElement.width = Math.max(width, NODE_MIN_WIDTH);
589
588
  newElement.height = height;
@@ -606,10 +605,180 @@ const getAvailableProperty = (board, element, propertyKey) => {
606
605
  return element[propertyKey];
607
606
  };
608
607
 
608
+ const separateChildren = (parentElement) => {
609
+ const rightNodeCount = parentElement.rightNodeCount;
610
+ const children = parentElement.children;
611
+ let rightChildren = [], leftChildren = [];
612
+ for (let i = 0; i < children.length; i++) {
613
+ const child = children[i];
614
+ if (AbstractNode.isAbstract(child) && child.end < rightNodeCount) {
615
+ rightChildren.push(child);
616
+ continue;
617
+ }
618
+ if (AbstractNode.isAbstract(child) && child.start >= rightNodeCount) {
619
+ leftChildren.push(child);
620
+ continue;
621
+ }
622
+ if (i < rightNodeCount) {
623
+ rightChildren.push(child);
624
+ }
625
+ else {
626
+ leftChildren.push(child);
627
+ }
628
+ }
629
+ return { leftChildren, rightChildren };
630
+ };
631
+ const isSetAbstract = (element) => {
632
+ return !!getCorrespondingAbstract(element);
633
+ };
634
+ const canSetAbstract = (element) => {
635
+ return !PlaitElement.isRootElement(element) && !AbstractNode.isAbstract(element) && !isSetAbstract(element);
636
+ };
637
+ const getCorrespondingAbstract = (element) => {
638
+ const parent = MindElement.findParent(element);
639
+ if (!parent)
640
+ return undefined;
641
+ const elementIndex = parent.children.indexOf(element);
642
+ return parent.children.find(child => {
643
+ return AbstractNode.isAbstract(child) && elementIndex >= child.start && elementIndex <= child.end;
644
+ });
645
+ };
646
+ const getBehindAbstracts = (element) => {
647
+ const parent = MindElement.findParent(element);
648
+ if (!parent)
649
+ return [];
650
+ const index = parent.children.indexOf(element);
651
+ return parent.children.filter(child => AbstractNode.isAbstract(child) && child.start > index);
652
+ };
653
+ /**
654
+ * return corresponding abstract that is not child of elements
655
+ */
656
+ const getOverallAbstracts = (board, elements) => {
657
+ const overallAbstracts = [];
658
+ elements
659
+ .filter(value => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
660
+ .forEach(value => {
661
+ const abstract = getCorrespondingAbstract(value);
662
+ if (abstract && elements.indexOf(abstract) === -1 && overallAbstracts.indexOf(abstract) === -1) {
663
+ const { start, end } = abstract;
664
+ const parent = MindElement.getParent(value);
665
+ const isOverall = parent.children.slice(start, end + 1).every(includedElement => elements.indexOf(includedElement) > -1);
666
+ if (isOverall) {
667
+ overallAbstracts.push(abstract);
668
+ }
669
+ }
670
+ });
671
+ return overallAbstracts;
672
+ };
673
+ /**
674
+ * abstract node is valid when elements contains at least one element it is referenced with
675
+ */
676
+ const getValidAbstractRefs = (board, elements) => {
677
+ const validAbstractRefs = [];
678
+ elements
679
+ .filter(value => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
680
+ .forEach(value => {
681
+ const abstract = getCorrespondingAbstract(value);
682
+ if (abstract && elements.indexOf(abstract) > 0) {
683
+ const index = validAbstractRefs.findIndex(value => value.abstract === abstract);
684
+ if (index === -1) {
685
+ validAbstractRefs.push({
686
+ abstract: abstract,
687
+ references: [value]
688
+ });
689
+ }
690
+ else {
691
+ validAbstractRefs[index].references.push(value);
692
+ }
693
+ }
694
+ });
695
+ return validAbstractRefs;
696
+ };
697
+ function getRelativeStartEndByAbstractRef(abstractRef, elements) {
698
+ const start = elements.indexOf(abstractRef.references[0]);
699
+ const end = elements.indexOf(abstractRef.references[abstractRef.references.length - 1]);
700
+ return { start, end };
701
+ }
702
+ const insertElementHandleAbstract = (board, path, step = 1,
703
+ //由此区分拖拽和新增到概要概括最后一个节点
704
+ isExtendPreviousNode = true, effectedAbstracts = new Map()) => {
705
+ const parent = PlaitNode.parent(board, path);
706
+ const hasPreviousNode = path[path.length - 1] !== 0;
707
+ let behindAbstracts;
708
+ if (!hasPreviousNode) {
709
+ behindAbstracts = parent.children.filter(child => AbstractNode.isAbstract(child));
710
+ }
711
+ else {
712
+ const selectedElement = PlaitNode.get(board, Path.previous(path));
713
+ behindAbstracts = getBehindAbstracts(selectedElement);
714
+ }
715
+ if (behindAbstracts.length) {
716
+ behindAbstracts.forEach(abstract => {
717
+ let newProperties = effectedAbstracts.get(abstract);
718
+ if (!newProperties) {
719
+ newProperties = { start: 0, end: 0 };
720
+ effectedAbstracts.set(abstract, newProperties);
721
+ }
722
+ newProperties.start = newProperties.start + step;
723
+ newProperties.end = newProperties.end + step;
724
+ });
725
+ }
726
+ if (!hasPreviousNode) {
727
+ return effectedAbstracts;
728
+ }
729
+ const selectedElement = PlaitNode.get(board, Path.previous(path));
730
+ const correspondingAbstract = getCorrespondingAbstract(selectedElement);
731
+ const isDragToLast = !isExtendPreviousNode && correspondingAbstract && correspondingAbstract.end === path[path.length - 1] - 1;
732
+ if (correspondingAbstract && !isDragToLast) {
733
+ let newProperties = effectedAbstracts.get(correspondingAbstract);
734
+ if (!newProperties) {
735
+ newProperties = { start: 0, end: 0 };
736
+ effectedAbstracts.set(correspondingAbstract, newProperties);
737
+ }
738
+ newProperties.end = newProperties.end + step;
739
+ }
740
+ return effectedAbstracts;
741
+ };
742
+ const deleteElementHandleAbstract = (board, deletableElements, effectedAbstracts = new Map()) => {
743
+ deletableElements.forEach(node => {
744
+ if (!PlaitMind.isMind(node)) {
745
+ const behindAbstracts = getBehindAbstracts(node).filter(abstract => !deletableElements.includes(abstract));
746
+ if (behindAbstracts.length) {
747
+ behindAbstracts.forEach(abstract => {
748
+ let newProperties = effectedAbstracts.get(abstract);
749
+ if (!newProperties) {
750
+ newProperties = { start: 0, end: 0 };
751
+ effectedAbstracts.set(abstract, newProperties);
752
+ }
753
+ newProperties.start = newProperties.start - 1;
754
+ newProperties.end = newProperties.end - 1;
755
+ });
756
+ }
757
+ const correspondingAbstract = getCorrespondingAbstract(node);
758
+ if (correspondingAbstract && !deletableElements.includes(correspondingAbstract)) {
759
+ let newProperties = effectedAbstracts.get(correspondingAbstract);
760
+ if (!newProperties) {
761
+ newProperties = { start: 0, end: 0 };
762
+ effectedAbstracts.set(correspondingAbstract, newProperties);
763
+ }
764
+ newProperties.end = newProperties.end - 1;
765
+ }
766
+ }
767
+ });
768
+ return effectedAbstracts;
769
+ };
770
+ const isChildOfAbstract = (board, element) => {
771
+ const ancestors = MindElement.getAncestors(board, element);
772
+ return !!ancestors.find((value) => AbstractNode.isAbstract(value));
773
+ };
774
+
609
775
  /**
610
776
  * Processing of branch color, width, style, etc. of the mind node
611
777
  */
612
778
  const getBranchColorByMindElement = (board, element) => {
779
+ if (AbstractNode.isAbstract(element) || isChildOfAbstract(board, element)) {
780
+ return getAbstractBranchColor(board, element);
781
+ }
613
782
  const branchColor = getAvailableProperty(board, element, 'branchColor');
614
783
  return branchColor || getDefaultBranchColor(board, element);
615
784
  };
@@ -663,6 +832,10 @@ const getStrokeByMindElement = (board, element) => {
663
832
  const defaultRootStroke = getMindThemeColor(board).rootFill;
664
833
  return element.strokeColor || defaultRootStroke;
665
834
  }
835
+ if (AbstractNode.isAbstract(element) || isChildOfAbstract(board, element)) {
836
+ return element.strokeColor || DefaultAbstractNodeStyle.strokeColor;
837
+ ;
838
+ }
666
839
  return getAvailableProperty(board, element, 'strokeColor') || getDefaultBranchColor(board, element);
667
840
  };
668
841
  const getShapeByElement = (board, element) => {
@@ -1073,15 +1246,6 @@ function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnde
1073
1246
  endY = isUnderlineShape ? endNode.y + endNode.height - endNode.vGap : endNode.y + endNode.height / 2;
1074
1247
  //根据位置,设置正负参数
1075
1248
  let plusMinus = isChildUp(node, child) ? (node.left ? [-1, -1] : [1, -1]) : node.left ? [-1, 1] : [1, 1];
1076
- const layout = MindQueries.getCorrectLayoutByElement(board, node.origin);
1077
- if (beginNode.origin.isRoot) {
1078
- if (layout === MindLayoutType.leftBottomIndented || layout === MindLayoutType.rightBottomIndented) {
1079
- beginY += branchWidth;
1080
- }
1081
- if (layout === MindLayoutType.leftTopIndented || layout === MindLayoutType.rightTopIndented) {
1082
- beginY -= branchWidth;
1083
- }
1084
- }
1085
1249
  let curve = [
1086
1250
  [beginX, beginY],
1087
1251
  [beginX, beginY],
@@ -1103,8 +1267,8 @@ function drawIndentedLink(board, node, child, defaultStroke = null, needDrawUnde
1103
1267
  ];
1104
1268
  return drawLinearPath(polylinePoints, { stroke: branchColor, strokeWidth: branchWidth });
1105
1269
  }
1106
- const points = pointsOnBezierCurves(curve);
1107
- return PlaitBoard.getRoughSVG(board).curve(points, { stroke: branchColor, strokeWidth: branchWidth });
1270
+ const points = pointsOnBezierCurves(curve, 0.001);
1271
+ return drawBezierPath(points, { stroke: branchColor, strokeWidth: branchWidth });
1108
1272
  }
1109
1273
 
1110
1274
  function drawLogicLink(board, parent, node, isHorizontal, defaultStroke = null, defaultStrokeWidth) {
@@ -1303,169 +1467,6 @@ const drawFakeDropNode = (board, dropTarget, path) => {
1303
1467
  return fakeDropNodeG;
1304
1468
  };
1305
1469
 
1306
- const separateChildren = (parentElement) => {
1307
- const rightNodeCount = parentElement.rightNodeCount;
1308
- const children = parentElement.children;
1309
- let rightChildren = [], leftChildren = [];
1310
- for (let i = 0; i < children.length; i++) {
1311
- const child = children[i];
1312
- if (AbstractNode.isAbstract(child) && child.end < rightNodeCount) {
1313
- rightChildren.push(child);
1314
- continue;
1315
- }
1316
- if (AbstractNode.isAbstract(child) && child.start >= rightNodeCount) {
1317
- leftChildren.push(child);
1318
- continue;
1319
- }
1320
- if (i < rightNodeCount) {
1321
- rightChildren.push(child);
1322
- }
1323
- else {
1324
- leftChildren.push(child);
1325
- }
1326
- }
1327
- return { leftChildren, rightChildren };
1328
- };
1329
- const isSetAbstract = (element) => {
1330
- return !!getCorrespondingAbstract(element);
1331
- };
1332
- const canSetAbstract = (element) => {
1333
- return !PlaitElement.isRootElement(element) && !AbstractNode.isAbstract(element) && !isSetAbstract(element);
1334
- };
1335
- const getCorrespondingAbstract = (element) => {
1336
- const parent = MindElement.findParent(element);
1337
- if (!parent)
1338
- return undefined;
1339
- const elementIndex = parent.children.indexOf(element);
1340
- return parent.children.find(child => {
1341
- return AbstractNode.isAbstract(child) && elementIndex >= child.start && elementIndex <= child.end;
1342
- });
1343
- };
1344
- const getBehindAbstracts = (element) => {
1345
- const parent = MindElement.findParent(element);
1346
- if (!parent)
1347
- return [];
1348
- const index = parent.children.indexOf(element);
1349
- return parent.children.filter(child => AbstractNode.isAbstract(child) && child.start > index);
1350
- };
1351
- /**
1352
- * return corresponding abstract that is not child of elements
1353
- */
1354
- const getOverallAbstracts = (board, elements) => {
1355
- const overallAbstracts = [];
1356
- elements
1357
- .filter(value => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
1358
- .forEach(value => {
1359
- const abstract = getCorrespondingAbstract(value);
1360
- if (abstract && elements.indexOf(abstract) === -1 && overallAbstracts.indexOf(abstract) === -1) {
1361
- const { start, end } = abstract;
1362
- const parent = MindElement.getParent(value);
1363
- const isOverall = parent.children.slice(start, end + 1).every(includedElement => elements.indexOf(includedElement) > -1);
1364
- if (isOverall) {
1365
- overallAbstracts.push(abstract);
1366
- }
1367
- }
1368
- });
1369
- return overallAbstracts;
1370
- };
1371
- /**
1372
- * abstract node is valid when elements contains at least one element it is referenced with
1373
- */
1374
- const getValidAbstractRefs = (board, elements) => {
1375
- const validAbstractRefs = [];
1376
- elements
1377
- .filter(value => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
1378
- .forEach(value => {
1379
- const abstract = getCorrespondingAbstract(value);
1380
- if (abstract && elements.indexOf(abstract) > 0) {
1381
- const index = validAbstractRefs.findIndex(value => value.abstract === abstract);
1382
- if (index === -1) {
1383
- validAbstractRefs.push({
1384
- abstract: abstract,
1385
- references: [value]
1386
- });
1387
- }
1388
- else {
1389
- validAbstractRefs[index].references.push(value);
1390
- }
1391
- }
1392
- });
1393
- return validAbstractRefs;
1394
- };
1395
- function getRelativeStartEndByAbstractRef(abstractRef, elements) {
1396
- const start = elements.indexOf(abstractRef.references[0]);
1397
- const end = elements.indexOf(abstractRef.references[abstractRef.references.length - 1]);
1398
- return { start, end };
1399
- }
1400
- const insertElementHandleAbstract = (board, path, step = 1,
1401
- //由此区分拖拽和新增到概要概括最后一个节点
1402
- isExtendPreviousNode = true, effectedAbstracts = new Map()) => {
1403
- const parent = PlaitNode.parent(board, path);
1404
- const hasPreviousNode = path[path.length - 1] !== 0;
1405
- let behindAbstracts;
1406
- if (!hasPreviousNode) {
1407
- behindAbstracts = parent.children.filter(child => AbstractNode.isAbstract(child));
1408
- }
1409
- else {
1410
- const selectedElement = PlaitNode.get(board, Path.previous(path));
1411
- behindAbstracts = getBehindAbstracts(selectedElement);
1412
- }
1413
- if (behindAbstracts.length) {
1414
- behindAbstracts.forEach(abstract => {
1415
- let newProperties = effectedAbstracts.get(abstract);
1416
- if (!newProperties) {
1417
- newProperties = { start: 0, end: 0 };
1418
- effectedAbstracts.set(abstract, newProperties);
1419
- }
1420
- newProperties.start = newProperties.start + step;
1421
- newProperties.end = newProperties.end + step;
1422
- });
1423
- }
1424
- if (!hasPreviousNode) {
1425
- return effectedAbstracts;
1426
- }
1427
- const selectedElement = PlaitNode.get(board, Path.previous(path));
1428
- const correspondingAbstract = getCorrespondingAbstract(selectedElement);
1429
- const isDragToLast = !isExtendPreviousNode && correspondingAbstract && correspondingAbstract.end === path[path.length - 1] - 1;
1430
- if (correspondingAbstract && !isDragToLast) {
1431
- let newProperties = effectedAbstracts.get(correspondingAbstract);
1432
- if (!newProperties) {
1433
- newProperties = { start: 0, end: 0 };
1434
- effectedAbstracts.set(correspondingAbstract, newProperties);
1435
- }
1436
- newProperties.end = newProperties.end + step;
1437
- }
1438
- return effectedAbstracts;
1439
- };
1440
- const deleteElementHandleAbstract = (board, deletableElements, effectedAbstracts = new Map()) => {
1441
- deletableElements.forEach(node => {
1442
- if (!PlaitMind.isMind(node)) {
1443
- const behindAbstracts = getBehindAbstracts(node).filter(abstract => !deletableElements.includes(abstract));
1444
- if (behindAbstracts.length) {
1445
- behindAbstracts.forEach(abstract => {
1446
- let newProperties = effectedAbstracts.get(abstract);
1447
- if (!newProperties) {
1448
- newProperties = { start: 0, end: 0 };
1449
- effectedAbstracts.set(abstract, newProperties);
1450
- }
1451
- newProperties.start = newProperties.start - 1;
1452
- newProperties.end = newProperties.end - 1;
1453
- });
1454
- }
1455
- const correspondingAbstract = getCorrespondingAbstract(node);
1456
- if (correspondingAbstract && !deletableElements.includes(correspondingAbstract)) {
1457
- let newProperties = effectedAbstracts.get(correspondingAbstract);
1458
- if (!newProperties) {
1459
- newProperties = { start: 0, end: 0 };
1460
- effectedAbstracts.set(correspondingAbstract, newProperties);
1461
- }
1462
- newProperties.end = newProperties.end - 1;
1463
- }
1464
- }
1465
- });
1466
- return effectedAbstracts;
1467
- };
1468
-
1469
1470
  var AbstractHandlePosition;
1470
1471
  (function (AbstractHandlePosition) {
1471
1472
  AbstractHandlePosition["start"] = "start";
@@ -2110,9 +2111,7 @@ const setAbstractByElements = (board, groupParent, group) => {
2110
2111
  };
2111
2112
  const insertAbstractNode = (board, path, start, end) => {
2112
2113
  const mindElement = createMindElement('概要', 28, 20, {
2113
- strokeColor: DefaultAbstractNodeStyle.strokeColor,
2114
2114
  strokeWidth: DefaultAbstractNodeStyle.branchWidth,
2115
- branchColor: DefaultAbstractNodeStyle.branchColor,
2116
2115
  branchWidth: DefaultAbstractNodeStyle.branchWidth
2117
2116
  });
2118
2117
  mindElement.start = start;
@@ -2594,7 +2593,7 @@ class MindNodeComponent extends PlaitPluginElementComponent {
2594
2593
  this.nodeInsertDrawer = new NodeInsertDrawer(this.board);
2595
2594
  this.activeDrawer = new NodeActiveDrawer(this.board);
2596
2595
  this.collapseDrawer = new CollapseDrawer(this.board);
2597
- const plugins = this.board.getMindOptions().textPlugins;
2596
+ const plugins = this.board.getPluginOptions(WithMindPluginKey).textPlugins;
2598
2597
  this.textManage = new TextManage(this.board, this.viewContainerRef, () => {
2599
2598
  const rect = getTopicRectangleByNode(this.board, this.node);
2600
2599
  return rect;
@@ -2630,8 +2629,10 @@ class MindNodeComponent extends PlaitPluginElementComponent {
2630
2629
  }
2631
2630
  editTopic() {
2632
2631
  this.activeDrawer.draw(this.element, this.g, { selected: this.selected, isEditing: true });
2633
- this.textManage.edit(() => {
2634
- this.activeDrawer.draw(this.element, this.g, { selected: this.selected, isEditing: false });
2632
+ this.textManage.edit((origin) => {
2633
+ if (origin === ExitOrigin.default) {
2634
+ this.activeDrawer.draw(this.element, this.g, { selected: this.selected, isEditing: false });
2635
+ }
2635
2636
  });
2636
2637
  }
2637
2638
  onContextChanged(value, previous) {
@@ -2920,12 +2921,11 @@ const withNodeDnd = (board) => {
2920
2921
  !AbstractNode.isAbstract(targetElement)) {
2921
2922
  const targetElements = selectedElements.filter(element => MindElement.isMindElement(board, element) && !element.isRoot && !AbstractNode.isAbstract(element));
2922
2923
  const isMultiple = selectedElements.length > 0 && selectedElements.includes(targetElement);
2923
- const isSingle = !isMultiple && selectedElements.length === 0;
2924
2924
  if (isMultiple) {
2925
2925
  activeElements = targetElements;
2926
2926
  startPoint = point;
2927
2927
  }
2928
- else if (isSingle) {
2928
+ else {
2929
2929
  activeElements = [targetElement];
2930
2930
  startPoint = point;
2931
2931
  }
@@ -2979,6 +2979,7 @@ const withNodeDnd = (board) => {
2979
2979
  }
2980
2980
  if (dropTarget) {
2981
2981
  const targetPathRef = board.pathRef(targetPath);
2982
+ const targetPreviousPathRef = Path.hasPrevious(targetPath) && board.pathRef(Path.previous(targetPath));
2982
2983
  const targetElementPathRef = board.pathRef(PlaitBoard.findPath(board, dropTarget.target));
2983
2984
  let abstractRefs = getValidAbstractRefs(board, firstLevelElements);
2984
2985
  const normalElements = firstLevelElements
@@ -3016,9 +3017,16 @@ const withNodeDnd = (board) => {
3016
3017
  let insertPath = targetPathRef.current;
3017
3018
  const parentPath = Path.parent(targetPathRef.current || targetPath);
3018
3019
  if (!insertPath) {
3019
- const parent = PlaitNode.get(board, parentPath);
3020
- const children = getNonAbstractChildren(parent);
3021
- insertPath = [...parentPath, children.length || 0];
3020
+ //当插入位置和选中节点位置相同时,使用记录的 previousPath
3021
+ const previousPath = targetPreviousPathRef && targetPreviousPathRef.unref();
3022
+ if (previousPath) {
3023
+ insertPath = Path.next(previousPath);
3024
+ }
3025
+ else {
3026
+ const parent = PlaitNode.get(board, parentPath);
3027
+ const children = getNonAbstractChildren(parent);
3028
+ insertPath = [...parentPath, children.length || 0];
3029
+ }
3022
3030
  }
3023
3031
  MindTransforms.insertNodes(board, normalElements, insertPath);
3024
3032
  if (abstractRefs.length) {
@@ -3122,6 +3130,10 @@ const insertClipboardData = (board, elements, targetPoint) => {
3122
3130
  if (hasTargetParent) {
3123
3131
  if (item.isRoot) {
3124
3132
  newElement = adjustRootToNode(board, newElement);
3133
+ const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
3134
+ const { width, height } = getTextSize(board, newElement.data.topic, TOPIC_DEFAULT_MAX_WORD_COUNT, styles);
3135
+ newElement.width = Math.max(width, NODE_MIN_WIDTH);
3136
+ newElement.height = height;
3125
3137
  }
3126
3138
  // handle abstract start and end
3127
3139
  if (AbstractNode.isAbstract(newElement)) {
@@ -3147,10 +3159,11 @@ const insertClipboardData = (board, elements, targetPoint) => {
3147
3159
  });
3148
3160
  Transforms.setSelectionWithTemporaryElements(board, newELements);
3149
3161
  };
3150
- const insertClipboardText = (board, parentElement, text, width, height) => {
3162
+ const insertClipboardText = (board, targetParent, text) => {
3163
+ const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
3164
+ const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, styles);
3151
3165
  const newElement = createMindElement(text, width, height, {});
3152
- const path = PlaitBoard.findPath(board, parentElement).concat((parentElement.children || []).length);
3153
- Transforms.insertNode(board, newElement, path);
3166
+ Transforms.insertNode(board, newElement, findNewChildNodePath(board, targetParent));
3154
3167
  return;
3155
3168
  };
3156
3169
 
@@ -3263,9 +3276,7 @@ const withMindExtend = (board) => {
3263
3276
  newBoard.drawEmoji = (emoji, element) => {
3264
3277
  throw new Error('Not implement drawEmoji method error.');
3265
3278
  };
3266
- newBoard.getMindOptions = () => {
3267
- return { spaceBetweenEmojis: 4, emojiPadding: 0 };
3268
- };
3279
+ board.setPluginOptions(WithMindPluginKey, { spaceBetweenEmojis: 4, emojiPadding: 0 });
3269
3280
  return newBoard;
3270
3281
  };
3271
3282
 
@@ -3293,7 +3304,7 @@ const withCreateMind = (board) => {
3293
3304
  }
3294
3305
  if (PlaitBoard.isPointer(board, MindPointerType.mind)) {
3295
3306
  throttleRAF(() => {
3296
- const movingPoint = PlaitBoard.getMovingPoint(board);
3307
+ const movingPoint = PlaitBoard.getMovingPointInBoard(board);
3297
3308
  if (movingPoint) {
3298
3309
  const targetPoint = transformPoint(board, toPoint(movingPoint[0], movingPoint[1], PlaitBoard.getHost(board)));
3299
3310
  const emptyMind = createEmptyMind(targetPoint);
@@ -3335,7 +3346,7 @@ const withCreateMind = (board) => {
3335
3346
  mousemove(event);
3336
3347
  };
3337
3348
  newBoard.mouseup = (event) => {
3338
- const movingPoint = PlaitBoard.getMovingPoint(board);
3349
+ const movingPoint = PlaitBoard.getMovingPointInBoard(board);
3339
3350
  if (movingPoint && fakeCreateNodeRef && PlaitBoard.isPointer(board, MindPointerType.mind)) {
3340
3351
  const targetPoint = transformPoint(board, toPoint(movingPoint[0], movingPoint[1], PlaitBoard.getHost(board)));
3341
3352
  const emptyMind = createEmptyMind(targetPoint);
@@ -3414,38 +3425,18 @@ const withMindHotkey = (board) => {
3414
3425
  event.preventDefault();
3415
3426
  const targetMindElements = selectedElements.filter(el => MindElement.isMindElement(board, el));
3416
3427
  const firstLevelElements = getFirstLevelElement(targetMindElements);
3417
- const deletableElements = firstLevelElements.reverse();
3418
- const abstractRefs = deleteElementHandleAbstract(board, deletableElements);
3419
- MindTransforms.setAbstractsByRefs(board, abstractRefs);
3420
- const refs = deleteElementsHandleRightNodeCount(board, targetMindElements);
3421
- MindTransforms.setRightNodeCountByRefs(board, refs);
3422
- MindTransforms.removeElements(board, targetMindElements);
3423
- let activeElement;
3424
- if (AbstractNode.isAbstract(firstLevelElements[0])) {
3425
- const parent = MindElement.getParent(firstLevelElements[0]);
3426
- activeElement = parent.children[firstLevelElements[0].start];
3427
- }
3428
- const firstElement = firstLevelElements[0];
3429
- const firstElementParent = MindElement.findParent(firstElement);
3430
- const hasSameParent = firstLevelElements.every(element => {
3431
- return MindElement.findParent(element) === firstElementParent;
3432
- });
3433
- if (firstElementParent && hasSameParent && !activeElement) {
3434
- const firstElementIndex = firstElementParent.children.indexOf(firstElement);
3435
- const childrenCount = firstElementParent.children.length;
3436
- // active parent element
3437
- if (childrenCount === firstLevelElements.length) {
3438
- activeElement = firstElementParent;
3439
- }
3440
- else {
3441
- if (firstElementIndex > 0) {
3442
- activeElement = firstElementParent.children[firstElementIndex - 1];
3443
- }
3428
+ if (firstLevelElements.length > 0) {
3429
+ const deletableElements = [...firstLevelElements].reverse();
3430
+ const abstractRefs = deleteElementHandleAbstract(board, deletableElements);
3431
+ MindTransforms.setAbstractsByRefs(board, abstractRefs);
3432
+ const refs = deleteElementsHandleRightNodeCount(board, targetMindElements);
3433
+ MindTransforms.setRightNodeCountByRefs(board, refs);
3434
+ MindTransforms.removeElements(board, targetMindElements);
3435
+ const nextSelected = getNextSelectedElement(board, firstLevelElements);
3436
+ if (nextSelected) {
3437
+ addSelectedElement(board, nextSelected);
3444
3438
  }
3445
3439
  }
3446
- if (activeElement) {
3447
- addSelectedElement(board, activeElement);
3448
- }
3449
3440
  return;
3450
3441
  }
3451
3442
  if (!isVirtualKey(event) && !isSpaceHotkey(event) && isSingleSelection) {
@@ -3458,6 +3449,36 @@ const withMindHotkey = (board) => {
3458
3449
  };
3459
3450
  return board;
3460
3451
  };
3452
+ const getNextSelectedElement = (board, firstLevelElements) => {
3453
+ let activeElement;
3454
+ const firstLevelElement = firstLevelElements[0];
3455
+ const firstLevelElementPath = PlaitBoard.findPath(board, firstLevelElement);
3456
+ let nextSelectedPath = firstLevelElementPath;
3457
+ if (Path.hasPrevious(firstLevelElementPath)) {
3458
+ nextSelectedPath = Path.previous(firstLevelElementPath);
3459
+ }
3460
+ if (AbstractNode.isAbstract(firstLevelElement)) {
3461
+ const parent = MindElement.getParent(firstLevelElement);
3462
+ if (!firstLevelElements.includes(parent.children[firstLevelElement.start])) {
3463
+ activeElement = parent.children[firstLevelElement.start];
3464
+ }
3465
+ }
3466
+ try {
3467
+ if (!activeElement) {
3468
+ activeElement = PlaitNode.get(board, nextSelectedPath);
3469
+ }
3470
+ }
3471
+ catch (error) { }
3472
+ const firstElement = firstLevelElements[0];
3473
+ const firstElementParent = MindElement.findParent(firstElement);
3474
+ const hasSameParent = firstLevelElements.every(element => {
3475
+ return MindElement.findParent(element) === firstElementParent;
3476
+ });
3477
+ if (firstElementParent && hasSameParent && !activeElement) {
3478
+ activeElement = firstElementParent;
3479
+ }
3480
+ return activeElement;
3481
+ };
3461
3482
  const isExpandHotkey = (event) => {
3462
3483
  return isKeyHotkey('mod+/', event);
3463
3484
  };
@@ -3630,13 +3651,12 @@ const withMind = (board) => {
3630
3651
  insertClipboardData(board, elements, targetPoint || [0, 0]);
3631
3652
  }
3632
3653
  else {
3633
- const text = getTextFromClipboard(data);
3634
- const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, {
3635
- fontFamily: 'PingFangSC-Regular, "PingFang SC"'
3636
- });
3637
3654
  const selectedElements = getSelectedElements(board);
3638
- if (text && selectedElements.length === 1) {
3639
- insertClipboardText(board, selectedElements[0], buildText(text), width, height);
3655
+ if (selectedElements.length === 1) {
3656
+ const text = getTextFromClipboard(data);
3657
+ if (text) {
3658
+ insertClipboardText(board, selectedElements[0], buildText(text));
3659
+ }
3640
3660
  }
3641
3661
  }
3642
3662
  insertFragment(data, targetPoint);
@@ -3705,5 +3725,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
3705
3725
  * Generated bundle index. Do not edit.
3706
3726
  */
3707
3727
 
3708
- export { ABSTRACT_HANDLE_COLOR, ABSTRACT_HANDLE_LENGTH, ABSTRACT_HANDLE_MASK_WIDTH, ABSTRACT_INCLUDED_OUTLINE_OFFSET, AbstractHandlePosition, AbstractResizeState, BASE, BRANCH_WIDTH, BaseDrawer, BranchShape, DefaultAbstractNodeStyle, DefaultNodeStyle, ELEMENT_TO_NODE, EXTEND_DIAMETER, EXTEND_OFFSET, GRAY_COLOR, INHERIT_ATTRIBUTE_KEYS, IS_DRAGGING, LayoutDirection, LayoutDirectionsMap, MindColorfulThemeColor, MindDarkThemeColor, MindDefaultThemeColor, MindElement, MindElementShape, MindEmojiBaseComponent, MindModule, MindNode, MindNodeComponent, MindPointerType, MindQueries, MindRetroThemeColor, MindSoftThemeColor, MindStarryThemeColor, MindThemeColor, MindThemeColors, MindTransforms, NODE_MIN_WIDTH, PRIMARY_COLOR, PlaitMind, PlaitMindComponent, QUICK_INSERT_CIRCLE_COLOR, QUICK_INSERT_CIRCLE_OFFSET, QUICK_INSERT_INNER_CROSS_COLOR, ROOT_TOPIC_FONT_SIZE, ROOT_TOPIC_HEIGHT, STROKE_WIDTH, TOPIC_COLOR, TOPIC_DEFAULT_MAX_WORD_COUNT, TOPIC_FONT_SIZE, TRANSPARENT, addActiveOnDragOrigin, adjustAbstractToNode, adjustNodeToRoot, adjustRootToNode, canSetAbstract, copyNewNode, correctLayoutByDirection, createDefaultMind, createEmptyMind, createMindElement, deleteElementHandleAbstract, deleteElementsHandleRightNodeCount, detectDropTarget, directionCorrector, directionDetector, divideElementByParent, drawFakeDragNode, drawFakeDropNode, editTopic, extractNodesText, findLastChild, findLocationLeftIndex, getAbstractBranchColor, getAbstractBranchWidth, getAbstractHandleRectangle, getAllowedDirection, getAvailableSubLayoutsByLayoutDirections, getBehindAbstracts, getBranchColorByMindElement, getBranchDirectionsByLayouts, getBranchShapeByMindElement, getBranchWidthByMindElement, getChildrenCount, getCorrespondingAbstract, getDefaultBranchColor, getDefaultBranchColorByIndex, getDefaultLayout, getEmojiForeignRectangle, getEmojiRectangle, getFirstLevelElement, getHitAbstractHandle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNextBranchColor, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getShapeByElement, getStrokeByMindElement, getTopicRectangleByElement, getTopicRectangleByNode, getValidAbstractRefs, handleTouchedAbstract, hasAfterDraw, hasPreviousOrNextOfDropPath, insertElementHandleAbstract, insertElementHandleRightNodeCount, insertMindElement, isChildElement, isChildRight, isChildUp, isCorrectLayout, isDragging, isDropStandardRight, isHitEmojis, isHitMindElement, isInRightBranchOfStandardLayout, isMixedLayout, isSetAbstract, isValidTarget, isVirtualKey, removeActiveOnDragOrigin, separateChildren, setIsDragging, withMind, withMindExtend };
3728
+ export { ABSTRACT_HANDLE_COLOR, ABSTRACT_HANDLE_LENGTH, ABSTRACT_HANDLE_MASK_WIDTH, ABSTRACT_INCLUDED_OUTLINE_OFFSET, AbstractHandlePosition, AbstractResizeState, BASE, BRANCH_FONT_FAMILY, BRANCH_WIDTH, BaseDrawer, BranchShape, DEFAULT_FONT_FAMILY, DefaultAbstractNodeStyle, DefaultNodeStyle, ELEMENT_TO_NODE, EXTEND_DIAMETER, EXTEND_OFFSET, GRAY_COLOR, INHERIT_ATTRIBUTE_KEYS, IS_DRAGGING, LayoutDirection, LayoutDirectionsMap, MindColorfulThemeColor, MindDarkThemeColor, MindDefaultThemeColor, MindElement, MindElementShape, MindEmojiBaseComponent, MindModule, MindNode, MindNodeComponent, MindPointerType, MindQueries, MindRetroThemeColor, MindSoftThemeColor, MindStarryThemeColor, MindThemeColor, MindThemeColors, MindTransforms, NODE_MIN_WIDTH, PRIMARY_COLOR, PlaitMind, PlaitMindComponent, QUICK_INSERT_CIRCLE_COLOR, QUICK_INSERT_CIRCLE_OFFSET, QUICK_INSERT_INNER_CROSS_COLOR, ROOT_TOPIC_FONT_SIZE, ROOT_TOPIC_HEIGHT, STROKE_WIDTH, TOPIC_COLOR, TOPIC_DEFAULT_MAX_WORD_COUNT, TOPIC_FONT_SIZE, TRANSPARENT, WithMindPluginKey, addActiveOnDragOrigin, adjustAbstractToNode, adjustNodeToRoot, adjustRootToNode, canSetAbstract, copyNewNode, correctLayoutByDirection, createDefaultMind, createEmptyMind, createMindElement, deleteElementHandleAbstract, deleteElementsHandleRightNodeCount, detectDropTarget, directionCorrector, directionDetector, divideElementByParent, drawFakeDragNode, drawFakeDropNode, editTopic, extractNodesText, findLastChild, findLocationLeftIndex, getAbstractBranchColor, getAbstractBranchWidth, getAbstractHandleRectangle, getAllowedDirection, getAvailableSubLayoutsByLayoutDirections, getBehindAbstracts, getBranchColorByMindElement, getBranchDirectionsByLayouts, getBranchShapeByMindElement, getBranchWidthByMindElement, getChildrenCount, getCorrespondingAbstract, getDefaultBranchColor, getDefaultBranchColorByIndex, getDefaultLayout, getEmojiForeignRectangle, getEmojiRectangle, getFirstLevelElement, getHitAbstractHandle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNextBranchColor, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getShapeByElement, getStrokeByMindElement, getTopicRectangleByElement, getTopicRectangleByNode, getValidAbstractRefs, handleTouchedAbstract, hasAfterDraw, hasPreviousOrNextOfDropPath, insertElementHandleAbstract, insertElementHandleRightNodeCount, insertMindElement, isChildElement, isChildOfAbstract, isChildRight, isChildUp, isCorrectLayout, isDragging, isDropStandardRight, isHitEmojis, isHitMindElement, isInRightBranchOfStandardLayout, isMixedLayout, isSetAbstract, isValidTarget, isVirtualKey, removeActiveOnDragOrigin, separateChildren, setIsDragging, withMind, withMindExtend };
3709
3729
  //# sourceMappingURL=plait-mind.mjs.map