@plait/mind 0.27.0-next.4 → 0.27.0-next.6
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/base/image-base.component.mjs +1 -4
- package/esm2022/interfaces/element.mjs +9 -2
- package/esm2022/interfaces/index.mjs +2 -1
- package/esm2022/interfaces/options.mjs +1 -1
- package/esm2022/mind-node.component.mjs +10 -6
- package/esm2022/plugins/with-mind-fragment.mjs +90 -0
- package/esm2022/plugins/with-mind-hotkey.mjs +13 -55
- package/esm2022/plugins/with-mind.mjs +6 -35
- package/esm2022/plugins/with-node-dnd.mjs +3 -3
- package/esm2022/plugins/with-node-resize.mjs +5 -5
- package/esm2022/transforms/index.mjs +2 -3
- package/esm2022/transforms/node.mjs +1 -17
- package/esm2022/utils/draw/node-dnd.mjs +2 -2
- package/esm2022/utils/node/dynamic-width.mjs +3 -3
- package/fesm2022/plait-mind.mjs +214 -211
- package/fesm2022/plait-mind.mjs.map +1 -1
- package/interfaces/element.d.ts +1 -0
- package/interfaces/index.d.ts +1 -0
- package/interfaces/options.d.ts +0 -2
- package/mind-node.component.d.ts +4 -3
- package/package.json +1 -1
- package/plugins/with-mind-fragment.d.ts +5 -0
- package/plugins/with-mind-hotkey.d.ts +0 -2
- package/transforms/index.d.ts +0 -1
- package/transforms/node.d.ts +0 -1
package/fesm2022/plait-mind.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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, PlaitPluginKey, getSelectedElements, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitBoard, Path, PlaitNode, PlaitContextService, depthFirstRecursion, getIsRecursionFunc, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, setStrokeLinecap, createText, PlaitPointerType,
|
|
4
|
+
import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, RectangleClient, PlaitElement, PlaitPluginKey, getSelectedElements, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitBoard, Path, PlaitNode, PlaitContextService, depthFirstRecursion, getIsRecursionFunc, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, setStrokeLinecap, createText, PlaitPointerType, NODE_TO_INDEX, PlaitModule, isMainPointer, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CoreTransforms, BOARD_TO_HOST, BoardTransforms, throttleRAF, removeSelectedElement, PlaitHistoryBoard, hotkeys, setClipboardDataByMedia, getClipboardDataByMedia, ResizeCursorClass, preventTouchMove, PRESS_AND_MOVE_BUFFER, MERGING, setClipboardData, setClipboardDataByText, getDataFromClipboard } from '@plait/core';
|
|
5
5
|
import { MindLayoutType, isIndentedLayout, isHorizontalLayout, isHorizontalLogicLayout, ConnectingPosition, AbstractNode, isStandardLayout, isVerticalLogicLayout, getNonAbstractChildren, isLeftLayout, isRightLayout, isTopLayout, isBottomLayout, getCorrectStartEnd, getAbstractLayout, GlobalLayout } from '@plait/layouts';
|
|
6
6
|
import { PlaitMarkEditor, MarkTypes, DEFAULT_FONT_SIZE, TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, ExitOrigin, TextModule, getTextFromClipboard } from '@plait/text';
|
|
7
7
|
import { fromEvent, Subject } from 'rxjs';
|
|
8
|
-
import { RESIZE_HANDLE_DIAMETER, getRectangleResizeHandleRefs, isDrawingMode, isDndMode, setCreationMode, BoardCreationMode, isExpandHotkey, isTabHotkey, isEnterHotkey, isVirtualKey, isSpaceHotkey, MediaKeys, ResizeHandle, withResize, ActiveGenerator } from '@plait/common';
|
|
8
|
+
import { RESIZE_HANDLE_DIAMETER, getRectangleResizeHandleRefs, CommonPluginElement, WithTextPluginKey, isDrawingMode, isDndMode, setCreationMode, BoardCreationMode, isExpandHotkey, isTabHotkey, isEnterHotkey, isVirtualKey, isDelete, isSpaceHotkey, MediaKeys, ResizeHandle, withResize, ActiveGenerator } from '@plait/common';
|
|
9
9
|
import { Node as Node$1, Path as Path$1 } from 'slate';
|
|
10
10
|
import { pointsOnBezierCurves } from 'points-on-curve';
|
|
11
11
|
import { take, filter } from 'rxjs/operators';
|
|
@@ -1107,21 +1107,6 @@ const setTopicSize = (board, element, width, height) => {
|
|
|
1107
1107
|
Transforms.setNode(board, newElement, path);
|
|
1108
1108
|
}
|
|
1109
1109
|
};
|
|
1110
|
-
const removeElements = (board, elements) => {
|
|
1111
|
-
const deletableElements = getFirstLevelElement(elements);
|
|
1112
|
-
deletableElements
|
|
1113
|
-
.map(element => {
|
|
1114
|
-
const path = PlaitBoard.findPath(board, element);
|
|
1115
|
-
const ref = board.pathRef(path);
|
|
1116
|
-
return () => {
|
|
1117
|
-
Transforms.removeNode(board, ref.current);
|
|
1118
|
-
ref.unref();
|
|
1119
|
-
};
|
|
1120
|
-
})
|
|
1121
|
-
.forEach(action => {
|
|
1122
|
-
action();
|
|
1123
|
-
});
|
|
1124
|
-
};
|
|
1125
1110
|
const insertNodes = (board, elements, path) => {
|
|
1126
1111
|
const pathRef = board.pathRef(path);
|
|
1127
1112
|
elements.forEach(element => {
|
|
@@ -1194,7 +1179,7 @@ const replaceEmoji = (board, element, oldEmoji, newEmoji) => {
|
|
|
1194
1179
|
* 2. new height is effected by zoom
|
|
1195
1180
|
*/
|
|
1196
1181
|
const getNewNodeHeight = (board, element, newNodeDynamicWidth) => {
|
|
1197
|
-
const textManage =
|
|
1182
|
+
const textManage = MindElement.getTextManage(element);
|
|
1198
1183
|
const { height } = textManage.getSize();
|
|
1199
1184
|
textManage.updateRectangleWidth(newNodeDynamicWidth);
|
|
1200
1185
|
const { height: newHeight } = textManage.getSize();
|
|
@@ -1245,7 +1230,6 @@ const MindTransforms = {
|
|
|
1245
1230
|
insertAbstract,
|
|
1246
1231
|
setAbstractsByRefs,
|
|
1247
1232
|
setAbstractByStandardLayout,
|
|
1248
|
-
removeElements,
|
|
1249
1233
|
insertNodes,
|
|
1250
1234
|
insertAbstractNodes,
|
|
1251
1235
|
setRightNodeCountByRefs,
|
|
@@ -1889,7 +1873,7 @@ const drawFakeDragNode = (board, element, offsetX, offsetY) => {
|
|
|
1889
1873
|
};
|
|
1890
1874
|
const textRectangle = getTopicRectangleByNode(board, activeComponent.node);
|
|
1891
1875
|
const fakeNodeG = drawRoundRectangleByNode(board, fakeDraggingNode);
|
|
1892
|
-
const richtextG =
|
|
1876
|
+
const richtextG = MindElement.getTextManage(element).g.cloneNode(true);
|
|
1893
1877
|
updateForeignObject(richtextG, textRectangle.width, textRectangle.height, textRectangle.x + offsetX, textRectangle.y + offsetY);
|
|
1894
1878
|
dragFakeNodeG?.append(fakeNodeG);
|
|
1895
1879
|
dragFakeNodeG?.append(richtextG);
|
|
@@ -2452,7 +2436,14 @@ const MindElement = {
|
|
|
2452
2436
|
getTextEditor(element) {
|
|
2453
2437
|
const component = PlaitElement.getComponent(element);
|
|
2454
2438
|
if (component) {
|
|
2455
|
-
return
|
|
2439
|
+
return MindElement.getTextManage(element).componentRef.instance.editor;
|
|
2440
|
+
}
|
|
2441
|
+
throw new Error('can not get correctly component in get text editor');
|
|
2442
|
+
},
|
|
2443
|
+
getTextManage(element) {
|
|
2444
|
+
const component = PlaitElement.getComponent(element);
|
|
2445
|
+
if (component) {
|
|
2446
|
+
return component.textManage;
|
|
2456
2447
|
}
|
|
2457
2448
|
throw new Error('can not get correctly component in get text editor');
|
|
2458
2449
|
}
|
|
@@ -3046,7 +3037,10 @@ class NodeImageDrawer {
|
|
|
3046
3037
|
}
|
|
3047
3038
|
}
|
|
3048
3039
|
|
|
3049
|
-
class MindNodeComponent extends
|
|
3040
|
+
class MindNodeComponent extends CommonPluginElement {
|
|
3041
|
+
get textManage() {
|
|
3042
|
+
return this.getTextManages()[0];
|
|
3043
|
+
}
|
|
3050
3044
|
constructor(viewContainerRef, cdr) {
|
|
3051
3045
|
super(cdr);
|
|
3052
3046
|
this.viewContainerRef = viewContainerRef;
|
|
@@ -3063,8 +3057,8 @@ class MindNodeComponent extends PlaitPluginElementComponent {
|
|
|
3063
3057
|
this.activeDrawer = new NodeActiveDrawer(this.board);
|
|
3064
3058
|
this.collapseDrawer = new CollapseDrawer(this.board);
|
|
3065
3059
|
this.imageDrawer = new NodeImageDrawer(this.board, this.viewContainerRef);
|
|
3066
|
-
const plugins = this.board.getPluginOptions(
|
|
3067
|
-
|
|
3060
|
+
const plugins = this.board.getPluginOptions(WithTextPluginKey).textPlugins;
|
|
3061
|
+
const textManage = new TextManage(this.board, this.viewContainerRef, {
|
|
3068
3062
|
getRectangle: () => {
|
|
3069
3063
|
const rect = getTopicRectangleByNode(this.board, this.node);
|
|
3070
3064
|
return rect;
|
|
@@ -3089,6 +3083,7 @@ class MindNodeComponent extends PlaitPluginElementComponent {
|
|
|
3089
3083
|
}
|
|
3090
3084
|
}
|
|
3091
3085
|
});
|
|
3086
|
+
this.initializeTextManages([textManage]);
|
|
3092
3087
|
}
|
|
3093
3088
|
ngOnInit() {
|
|
3094
3089
|
super.ngOnInit();
|
|
@@ -3432,7 +3427,7 @@ const withNodeDnd = (board) => {
|
|
|
3432
3427
|
refs = insertElementHandleRightNodeCount(board, targetElementPathRef.current.slice(0, 1), normalElements.length, refs);
|
|
3433
3428
|
}
|
|
3434
3429
|
MindTransforms.setRightNodeCountByRefs(board, refs);
|
|
3435
|
-
|
|
3430
|
+
CoreTransforms.removeElements(board, firstLevelElements);
|
|
3436
3431
|
let insertPath = targetPathRef.current;
|
|
3437
3432
|
const parentPath = Path.parent(targetPathRef.current || targetPath);
|
|
3438
3433
|
if (!insertPath) {
|
|
@@ -3481,108 +3476,6 @@ const withNodeDnd = (board) => {
|
|
|
3481
3476
|
return board;
|
|
3482
3477
|
};
|
|
3483
3478
|
|
|
3484
|
-
const buildClipboardData = (board, selectedElements, startPoint) => {
|
|
3485
|
-
let result = [];
|
|
3486
|
-
// get overall abstract
|
|
3487
|
-
const overallAbstracts = getOverallAbstracts(board, selectedElements);
|
|
3488
|
-
// get valid abstract refs
|
|
3489
|
-
const validAbstractRefs = getValidAbstractRefs(board, [...selectedElements, ...overallAbstracts]);
|
|
3490
|
-
// keep correct order
|
|
3491
|
-
const newSelectedElements = selectedElements.filter(value => !validAbstractRefs.find(ref => ref.abstract === value));
|
|
3492
|
-
newSelectedElements.push(...validAbstractRefs.map(value => value.abstract));
|
|
3493
|
-
const selectedMindNodes = newSelectedElements.map(value => MindElement.getNode(value));
|
|
3494
|
-
newSelectedElements.forEach((element, index) => {
|
|
3495
|
-
// handle relative location
|
|
3496
|
-
const nodeRectangle = getRectangleByNode(selectedMindNodes[index]);
|
|
3497
|
-
const points = [[nodeRectangle.x - startPoint[0], nodeRectangle.y - startPoint[1]]];
|
|
3498
|
-
// handle invalid abstract
|
|
3499
|
-
const abstractRef = validAbstractRefs.find(ref => ref.abstract === element);
|
|
3500
|
-
if (AbstractNode.isAbstract(element) && abstractRef) {
|
|
3501
|
-
const { start, end } = getRelativeStartEndByAbstractRef(abstractRef, newSelectedElements);
|
|
3502
|
-
result.push({
|
|
3503
|
-
...element,
|
|
3504
|
-
points,
|
|
3505
|
-
start,
|
|
3506
|
-
end
|
|
3507
|
-
});
|
|
3508
|
-
}
|
|
3509
|
-
else {
|
|
3510
|
-
if (AbstractNode.isAbstract(element)) {
|
|
3511
|
-
let newElement = { ...element, points };
|
|
3512
|
-
delete newElement.start;
|
|
3513
|
-
delete newElement.end;
|
|
3514
|
-
result.push(newElement);
|
|
3515
|
-
}
|
|
3516
|
-
else {
|
|
3517
|
-
result.push({
|
|
3518
|
-
...element,
|
|
3519
|
-
points: points
|
|
3520
|
-
});
|
|
3521
|
-
}
|
|
3522
|
-
}
|
|
3523
|
-
});
|
|
3524
|
-
return result;
|
|
3525
|
-
};
|
|
3526
|
-
const setMindClipboardData = (data, elements) => {
|
|
3527
|
-
const text = elements.reduce((string, currentNode) => {
|
|
3528
|
-
return string + extractNodesText(currentNode);
|
|
3529
|
-
}, '');
|
|
3530
|
-
setClipboardData(data, elements);
|
|
3531
|
-
setClipboardDataByText(data, text);
|
|
3532
|
-
};
|
|
3533
|
-
const insertClipboardData = (board, elements, targetPoint) => {
|
|
3534
|
-
let newElement, path;
|
|
3535
|
-
const selectedElements = getSelectedElements(board);
|
|
3536
|
-
let newELements = [];
|
|
3537
|
-
const hasTargetParent = selectedElements.length === 1;
|
|
3538
|
-
const targetParent = selectedElements[0];
|
|
3539
|
-
const targetParentPath = targetParent && PlaitBoard.findPath(board, targetParent);
|
|
3540
|
-
const nonAbstractChildrenLength = targetParent && getNonAbstractChildren(targetParent).length;
|
|
3541
|
-
elements.forEach((item, index) => {
|
|
3542
|
-
newElement = copyNewNode(item);
|
|
3543
|
-
if (hasTargetParent) {
|
|
3544
|
-
if (item.isRoot) {
|
|
3545
|
-
newElement = adjustRootToNode(board, newElement);
|
|
3546
|
-
const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
|
|
3547
|
-
const { width, height } = getTextSize(board, newElement.data.topic, TOPIC_DEFAULT_MAX_WORD_COUNT, {
|
|
3548
|
-
...styles,
|
|
3549
|
-
width: newElement.manualWidth ? newElement.manualWidth : undefined
|
|
3550
|
-
});
|
|
3551
|
-
newElement.width = Math.max(width, getNodeDefaultFontSize());
|
|
3552
|
-
newElement.height = height;
|
|
3553
|
-
}
|
|
3554
|
-
// handle abstract start and end
|
|
3555
|
-
if (AbstractNode.isAbstract(newElement)) {
|
|
3556
|
-
newElement.start = newElement.start + nonAbstractChildrenLength;
|
|
3557
|
-
newElement.end = newElement.end + nonAbstractChildrenLength;
|
|
3558
|
-
}
|
|
3559
|
-
path = [...targetParentPath, nonAbstractChildrenLength + index];
|
|
3560
|
-
}
|
|
3561
|
-
else {
|
|
3562
|
-
const point = [targetPoint[0] + item.points[0][0], targetPoint[1] + item.points[0][1]];
|
|
3563
|
-
newElement.points = [point];
|
|
3564
|
-
if (AbstractNode.isAbstract(item)) {
|
|
3565
|
-
newElement = adjustAbstractToNode(newElement);
|
|
3566
|
-
}
|
|
3567
|
-
if (!item.isRoot) {
|
|
3568
|
-
newElement = adjustNodeToRoot(board, newElement);
|
|
3569
|
-
}
|
|
3570
|
-
path = [board.children.length];
|
|
3571
|
-
}
|
|
3572
|
-
newELements.push(newElement);
|
|
3573
|
-
Transforms.insertNode(board, newElement, path);
|
|
3574
|
-
return;
|
|
3575
|
-
});
|
|
3576
|
-
Transforms.setSelectionWithTemporaryElements(board, newELements);
|
|
3577
|
-
};
|
|
3578
|
-
const insertClipboardText = (board, targetParent, text) => {
|
|
3579
|
-
const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
|
|
3580
|
-
const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, styles);
|
|
3581
|
-
const newElement = createMindElement(text, Math.max(width, getFontSizeBySlateElement(text)), height, {});
|
|
3582
|
-
Transforms.insertNode(board, newElement, findNewChildNodePath(board, targetParent));
|
|
3583
|
-
return;
|
|
3584
|
-
};
|
|
3585
|
-
|
|
3586
3479
|
const withAbstract = (board) => {
|
|
3587
3480
|
const newBoard = board;
|
|
3588
3481
|
const { mousedown, mousemove, mouseup } = board;
|
|
@@ -3803,7 +3696,7 @@ const withCreateMind = (board) => {
|
|
|
3803
3696
|
|
|
3804
3697
|
const withMindHotkey = (baseBoard) => {
|
|
3805
3698
|
const board = baseBoard;
|
|
3806
|
-
const { keydown
|
|
3699
|
+
const { keydown } = board;
|
|
3807
3700
|
board.keydown = (event) => {
|
|
3808
3701
|
const selectedElements = getSelectedElements(board);
|
|
3809
3702
|
const isSingleSelection = selectedElements.length === 1;
|
|
@@ -3843,7 +3736,11 @@ const withMindHotkey = (baseBoard) => {
|
|
|
3843
3736
|
insertMindElement(board, targetElement, findNewSiblingNodePath(board, targetElement));
|
|
3844
3737
|
return;
|
|
3845
3738
|
}
|
|
3846
|
-
if (!isVirtualKey(event) &&
|
|
3739
|
+
if (!isVirtualKey(event) &&
|
|
3740
|
+
!isDelete(event) &&
|
|
3741
|
+
!isSpaceHotkey(event) &&
|
|
3742
|
+
isSingleSelection &&
|
|
3743
|
+
MindElement.isMindElement(board, targetElement)) {
|
|
3847
3744
|
event.preventDefault();
|
|
3848
3745
|
editTopic(targetElement);
|
|
3849
3746
|
return;
|
|
@@ -3851,54 +3748,8 @@ const withMindHotkey = (baseBoard) => {
|
|
|
3851
3748
|
}
|
|
3852
3749
|
keydown(event);
|
|
3853
3750
|
};
|
|
3854
|
-
board.deleteFragment = (data) => {
|
|
3855
|
-
const targetMindElements = getSelectedMindElements(board);
|
|
3856
|
-
if (targetMindElements.length) {
|
|
3857
|
-
const firstLevelElements = getFirstLevelElement(targetMindElements).reverse();
|
|
3858
|
-
const abstractRefs = deleteElementHandleAbstract(board, firstLevelElements);
|
|
3859
|
-
MindTransforms.setAbstractsByRefs(board, abstractRefs);
|
|
3860
|
-
const refs = deleteElementsHandleRightNodeCount(board, targetMindElements);
|
|
3861
|
-
MindTransforms.setRightNodeCountByRefs(board, refs);
|
|
3862
|
-
MindTransforms.removeElements(board, targetMindElements);
|
|
3863
|
-
const nextSelected = getNextSelectedElement(board, firstLevelElements);
|
|
3864
|
-
if (nextSelected) {
|
|
3865
|
-
addSelectedElement(board, nextSelected);
|
|
3866
|
-
}
|
|
3867
|
-
}
|
|
3868
|
-
deleteFragment(data);
|
|
3869
|
-
};
|
|
3870
3751
|
return board;
|
|
3871
3752
|
};
|
|
3872
|
-
const getNextSelectedElement = (board, firstLevelElements) => {
|
|
3873
|
-
let activeElement;
|
|
3874
|
-
const firstLevelElement = firstLevelElements[0];
|
|
3875
|
-
const firstLevelElementPath = PlaitBoard.findPath(board, firstLevelElement);
|
|
3876
|
-
let nextSelectedPath = firstLevelElementPath;
|
|
3877
|
-
if (Path.hasPrevious(firstLevelElementPath)) {
|
|
3878
|
-
nextSelectedPath = Path.previous(firstLevelElementPath);
|
|
3879
|
-
}
|
|
3880
|
-
if (AbstractNode.isAbstract(firstLevelElement)) {
|
|
3881
|
-
const parent = MindElement.getParent(firstLevelElement);
|
|
3882
|
-
if (!firstLevelElements.includes(parent.children[firstLevelElement.start])) {
|
|
3883
|
-
activeElement = parent.children[firstLevelElement.start];
|
|
3884
|
-
}
|
|
3885
|
-
}
|
|
3886
|
-
try {
|
|
3887
|
-
if (!activeElement) {
|
|
3888
|
-
activeElement = PlaitNode.get(board, nextSelectedPath);
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
catch (error) { }
|
|
3892
|
-
const firstElement = firstLevelElements[0];
|
|
3893
|
-
const firstElementParent = MindElement.findParent(firstElement);
|
|
3894
|
-
const hasSameParent = firstLevelElements.every(element => {
|
|
3895
|
-
return MindElement.findParent(element) === firstElementParent;
|
|
3896
|
-
});
|
|
3897
|
-
if (firstElementParent && hasSameParent && !activeElement) {
|
|
3898
|
-
activeElement = firstElementParent;
|
|
3899
|
-
}
|
|
3900
|
-
return activeElement;
|
|
3901
|
-
};
|
|
3902
3753
|
|
|
3903
3754
|
const mouseMoveHandle = (board, event, nodeHoveredExtendRef) => {
|
|
3904
3755
|
let target = null;
|
|
@@ -4067,6 +3918,7 @@ const withNodeResize = (board) => {
|
|
|
4067
3918
|
PlaitBoard.getBoardContainer(board).classList.add(ResizeCursorClass['ew-resize']);
|
|
4068
3919
|
targetElement = newTargetElement;
|
|
4069
3920
|
startPoint = [event.x, event.y];
|
|
3921
|
+
preventTouchMove(board, event, true);
|
|
4070
3922
|
return;
|
|
4071
3923
|
}
|
|
4072
3924
|
pointerDown(event);
|
|
@@ -4079,7 +3931,6 @@ const withNodeResize = (board) => {
|
|
|
4079
3931
|
if (startPoint && targetElement && !isMindNodeResizing(board)) {
|
|
4080
3932
|
// prevent text from being selected
|
|
4081
3933
|
event.preventDefault();
|
|
4082
|
-
preventTouchMove(board, true);
|
|
4083
3934
|
const endPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
4084
3935
|
const distance = distanceBetweenPointAndPoint(startPoint[0], startPoint[1], endPoint[0], endPoint[1]);
|
|
4085
3936
|
if (distance > PRESS_AND_MOVE_BUFFER) {
|
|
@@ -4088,7 +3939,7 @@ const withNodeResize = (board) => {
|
|
|
4088
3939
|
minWidth: NodeSpace.getNodeResizableMinWidth(board, targetElement),
|
|
4089
3940
|
currentWidth: NodeSpace.getNodeDynamicWidth(board, targetElement),
|
|
4090
3941
|
path: PlaitBoard.findPath(board, targetElement),
|
|
4091
|
-
textManage:
|
|
3942
|
+
textManage: MindElement.getTextManage(targetElement)
|
|
4092
3943
|
};
|
|
4093
3944
|
MERGING.set(board, true);
|
|
4094
3945
|
}
|
|
@@ -4096,7 +3947,7 @@ const withNodeResize = (board) => {
|
|
|
4096
3947
|
if (isMindNodeResizing(board) && startPoint && targetElementRef) {
|
|
4097
3948
|
// prevent text from being selected
|
|
4098
3949
|
event.preventDefault();
|
|
4099
|
-
preventTouchMove(board, true);
|
|
3950
|
+
preventTouchMove(board, event, true);
|
|
4100
3951
|
throttleRAF(() => {
|
|
4101
3952
|
if (!startPoint) {
|
|
4102
3953
|
return;
|
|
@@ -4140,7 +3991,7 @@ const withNodeResize = (board) => {
|
|
|
4140
3991
|
targetElement = null;
|
|
4141
3992
|
startPoint = null;
|
|
4142
3993
|
MERGING.set(board, false);
|
|
4143
|
-
preventTouchMove(board, false);
|
|
3994
|
+
preventTouchMove(board, event, false);
|
|
4144
3995
|
}
|
|
4145
3996
|
};
|
|
4146
3997
|
return board;
|
|
@@ -4224,9 +4075,191 @@ const withNodeImageResize = (board) => {
|
|
|
4224
4075
|
return board;
|
|
4225
4076
|
};
|
|
4226
4077
|
|
|
4078
|
+
const buildClipboardData = (board, selectedElements, startPoint) => {
|
|
4079
|
+
let result = [];
|
|
4080
|
+
// get overall abstract
|
|
4081
|
+
const overallAbstracts = getOverallAbstracts(board, selectedElements);
|
|
4082
|
+
// get valid abstract refs
|
|
4083
|
+
const validAbstractRefs = getValidAbstractRefs(board, [...selectedElements, ...overallAbstracts]);
|
|
4084
|
+
// keep correct order
|
|
4085
|
+
const newSelectedElements = selectedElements.filter(value => !validAbstractRefs.find(ref => ref.abstract === value));
|
|
4086
|
+
newSelectedElements.push(...validAbstractRefs.map(value => value.abstract));
|
|
4087
|
+
const selectedMindNodes = newSelectedElements.map(value => MindElement.getNode(value));
|
|
4088
|
+
newSelectedElements.forEach((element, index) => {
|
|
4089
|
+
// handle relative location
|
|
4090
|
+
const nodeRectangle = getRectangleByNode(selectedMindNodes[index]);
|
|
4091
|
+
const points = [[nodeRectangle.x - startPoint[0], nodeRectangle.y - startPoint[1]]];
|
|
4092
|
+
// handle invalid abstract
|
|
4093
|
+
const abstractRef = validAbstractRefs.find(ref => ref.abstract === element);
|
|
4094
|
+
if (AbstractNode.isAbstract(element) && abstractRef) {
|
|
4095
|
+
const { start, end } = getRelativeStartEndByAbstractRef(abstractRef, newSelectedElements);
|
|
4096
|
+
result.push({
|
|
4097
|
+
...element,
|
|
4098
|
+
points,
|
|
4099
|
+
start,
|
|
4100
|
+
end
|
|
4101
|
+
});
|
|
4102
|
+
}
|
|
4103
|
+
else {
|
|
4104
|
+
if (AbstractNode.isAbstract(element)) {
|
|
4105
|
+
let newElement = { ...element, points };
|
|
4106
|
+
delete newElement.start;
|
|
4107
|
+
delete newElement.end;
|
|
4108
|
+
result.push(newElement);
|
|
4109
|
+
}
|
|
4110
|
+
else {
|
|
4111
|
+
result.push({
|
|
4112
|
+
...element,
|
|
4113
|
+
points: points
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
}
|
|
4117
|
+
});
|
|
4118
|
+
return result;
|
|
4119
|
+
};
|
|
4120
|
+
const setMindClipboardData = (data, elements) => {
|
|
4121
|
+
const text = elements.reduce((string, currentNode) => {
|
|
4122
|
+
return string + extractNodesText(currentNode);
|
|
4123
|
+
}, '');
|
|
4124
|
+
setClipboardData(data, elements);
|
|
4125
|
+
setClipboardDataByText(data, text);
|
|
4126
|
+
};
|
|
4127
|
+
const insertClipboardData = (board, elements, targetPoint) => {
|
|
4128
|
+
let newElement, path;
|
|
4129
|
+
const selectedElements = getSelectedElements(board);
|
|
4130
|
+
let newELements = [];
|
|
4131
|
+
const hasTargetParent = selectedElements.length === 1;
|
|
4132
|
+
const targetParent = selectedElements[0];
|
|
4133
|
+
const targetParentPath = targetParent && PlaitBoard.findPath(board, targetParent);
|
|
4134
|
+
const nonAbstractChildrenLength = targetParent && getNonAbstractChildren(targetParent).length;
|
|
4135
|
+
elements.forEach((item, index) => {
|
|
4136
|
+
newElement = copyNewNode(item);
|
|
4137
|
+
if (hasTargetParent) {
|
|
4138
|
+
if (item.isRoot) {
|
|
4139
|
+
newElement = adjustRootToNode(board, newElement);
|
|
4140
|
+
const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
|
|
4141
|
+
const { width, height } = getTextSize(board, newElement.data.topic, TOPIC_DEFAULT_MAX_WORD_COUNT, {
|
|
4142
|
+
...styles,
|
|
4143
|
+
width: newElement.manualWidth ? newElement.manualWidth : undefined
|
|
4144
|
+
});
|
|
4145
|
+
newElement.width = Math.max(width, getNodeDefaultFontSize());
|
|
4146
|
+
newElement.height = height;
|
|
4147
|
+
}
|
|
4148
|
+
// handle abstract start and end
|
|
4149
|
+
if (AbstractNode.isAbstract(newElement)) {
|
|
4150
|
+
newElement.start = newElement.start + nonAbstractChildrenLength;
|
|
4151
|
+
newElement.end = newElement.end + nonAbstractChildrenLength;
|
|
4152
|
+
}
|
|
4153
|
+
path = [...targetParentPath, nonAbstractChildrenLength + index];
|
|
4154
|
+
}
|
|
4155
|
+
else {
|
|
4156
|
+
const point = [targetPoint[0] + item.points[0][0], targetPoint[1] + item.points[0][1]];
|
|
4157
|
+
newElement.points = [point];
|
|
4158
|
+
if (AbstractNode.isAbstract(item)) {
|
|
4159
|
+
newElement = adjustAbstractToNode(newElement);
|
|
4160
|
+
}
|
|
4161
|
+
if (!item.isRoot) {
|
|
4162
|
+
newElement = adjustNodeToRoot(board, newElement);
|
|
4163
|
+
}
|
|
4164
|
+
path = [board.children.length];
|
|
4165
|
+
}
|
|
4166
|
+
newELements.push(newElement);
|
|
4167
|
+
Transforms.insertNode(board, newElement, path);
|
|
4168
|
+
return;
|
|
4169
|
+
});
|
|
4170
|
+
Transforms.setSelectionWithTemporaryElements(board, newELements);
|
|
4171
|
+
};
|
|
4172
|
+
const insertClipboardText = (board, targetParent, text) => {
|
|
4173
|
+
const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
|
|
4174
|
+
const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, styles);
|
|
4175
|
+
const newElement = createMindElement(text, Math.max(width, getFontSizeBySlateElement(text)), height, {});
|
|
4176
|
+
Transforms.insertNode(board, newElement, findNewChildNodePath(board, targetParent));
|
|
4177
|
+
return;
|
|
4178
|
+
};
|
|
4179
|
+
|
|
4180
|
+
const withMindFragment = (baseBoard) => {
|
|
4181
|
+
const board = baseBoard;
|
|
4182
|
+
const { getDeletedFragment, insertFragment, setFragment } = board;
|
|
4183
|
+
board.getDeletedFragment = (data) => {
|
|
4184
|
+
const targetMindElements = getSelectedMindElements(board);
|
|
4185
|
+
if (targetMindElements.length) {
|
|
4186
|
+
const firstLevelElements = getFirstLevelElement(targetMindElements).reverse();
|
|
4187
|
+
const abstractRefs = deleteElementHandleAbstract(board, firstLevelElements);
|
|
4188
|
+
MindTransforms.setAbstractsByRefs(board, abstractRefs);
|
|
4189
|
+
const refs = deleteElementsHandleRightNodeCount(board, targetMindElements);
|
|
4190
|
+
MindTransforms.setRightNodeCountByRefs(board, refs);
|
|
4191
|
+
const deletableElements = getFirstLevelElement(targetMindElements);
|
|
4192
|
+
data.push(...deletableElements);
|
|
4193
|
+
const nextSelected = getNextSelectedElement(board, firstLevelElements);
|
|
4194
|
+
if (nextSelected) {
|
|
4195
|
+
addSelectedElement(board, nextSelected);
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
return getDeletedFragment(data);
|
|
4199
|
+
};
|
|
4200
|
+
board.setFragment = (data, rectangle) => {
|
|
4201
|
+
const targetMindElements = getSelectedMindElements(board);
|
|
4202
|
+
const firstLevelElements = getFirstLevelElement(targetMindElements);
|
|
4203
|
+
if (firstLevelElements.length) {
|
|
4204
|
+
const elements = buildClipboardData(board, firstLevelElements, rectangle ? [rectangle.x, rectangle.y] : [0, 0]);
|
|
4205
|
+
setMindClipboardData(data, elements);
|
|
4206
|
+
}
|
|
4207
|
+
setFragment(data, rectangle);
|
|
4208
|
+
};
|
|
4209
|
+
board.insertFragment = (data, targetPoint) => {
|
|
4210
|
+
const elements = getDataFromClipboard(data);
|
|
4211
|
+
const mindElements = elements.filter(value => MindElement.isMindElement(board, value));
|
|
4212
|
+
if (elements.length > 0 && mindElements.length > 0) {
|
|
4213
|
+
insertClipboardData(board, mindElements, targetPoint);
|
|
4214
|
+
}
|
|
4215
|
+
else if (elements.length === 0) {
|
|
4216
|
+
const mindElements = getSelectedMindElements(board);
|
|
4217
|
+
if (mindElements.length === 1) {
|
|
4218
|
+
const text = getTextFromClipboard(data);
|
|
4219
|
+
if (text) {
|
|
4220
|
+
insertClipboardText(board, mindElements[0], buildText(text));
|
|
4221
|
+
return;
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
insertFragment(data, targetPoint);
|
|
4226
|
+
};
|
|
4227
|
+
return board;
|
|
4228
|
+
};
|
|
4229
|
+
const getNextSelectedElement = (board, firstLevelElements) => {
|
|
4230
|
+
let activeElement;
|
|
4231
|
+
const firstLevelElement = firstLevelElements[0];
|
|
4232
|
+
const firstLevelElementPath = PlaitBoard.findPath(board, firstLevelElement);
|
|
4233
|
+
let nextSelectedPath = firstLevelElementPath;
|
|
4234
|
+
if (Path.hasPrevious(firstLevelElementPath)) {
|
|
4235
|
+
nextSelectedPath = Path.previous(firstLevelElementPath);
|
|
4236
|
+
}
|
|
4237
|
+
if (AbstractNode.isAbstract(firstLevelElement)) {
|
|
4238
|
+
const parent = MindElement.getParent(firstLevelElement);
|
|
4239
|
+
if (!firstLevelElements.includes(parent.children[firstLevelElement.start])) {
|
|
4240
|
+
activeElement = parent.children[firstLevelElement.start];
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
try {
|
|
4244
|
+
if (!activeElement) {
|
|
4245
|
+
activeElement = PlaitNode.get(board, nextSelectedPath);
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
catch (error) { }
|
|
4249
|
+
const firstElement = firstLevelElements[0];
|
|
4250
|
+
const firstElementParent = MindElement.findParent(firstElement);
|
|
4251
|
+
const hasSameParent = firstLevelElements.every(element => {
|
|
4252
|
+
return MindElement.findParent(element) === firstElementParent;
|
|
4253
|
+
});
|
|
4254
|
+
if (firstElementParent && hasSameParent && !activeElement) {
|
|
4255
|
+
activeElement = firstElementParent;
|
|
4256
|
+
}
|
|
4257
|
+
return activeElement;
|
|
4258
|
+
};
|
|
4259
|
+
|
|
4227
4260
|
const withMind = (baseBoard) => {
|
|
4228
4261
|
const board = baseBoard;
|
|
4229
|
-
const { drawElement, dblclick,
|
|
4262
|
+
const { drawElement, dblclick, isHitSelection, getRectangle, isMovable, isRecursion } = board;
|
|
4230
4263
|
board.drawElement = (context) => {
|
|
4231
4264
|
if (PlaitMind.isMind(context.element)) {
|
|
4232
4265
|
return PlaitMindComponent;
|
|
@@ -4290,34 +4323,7 @@ const withMind = (baseBoard) => {
|
|
|
4290
4323
|
}
|
|
4291
4324
|
dblclick(event);
|
|
4292
4325
|
};
|
|
4293
|
-
|
|
4294
|
-
const targetMindElements = getSelectedMindElements(board);
|
|
4295
|
-
const firstLevelElements = getFirstLevelElement(targetMindElements);
|
|
4296
|
-
if (firstLevelElements.length) {
|
|
4297
|
-
const elements = buildClipboardData(board, firstLevelElements, rectangle ? [rectangle.x, rectangle.y] : [0, 0]);
|
|
4298
|
-
setMindClipboardData(data, elements);
|
|
4299
|
-
}
|
|
4300
|
-
setFragment(data, rectangle);
|
|
4301
|
-
};
|
|
4302
|
-
board.insertFragment = (data, targetPoint) => {
|
|
4303
|
-
const elements = getDataFromClipboard(data);
|
|
4304
|
-
const mindElements = elements.filter(value => MindElement.isMindElement(board, value));
|
|
4305
|
-
if (elements.length > 0 && mindElements.length > 0) {
|
|
4306
|
-
insertClipboardData(board, mindElements, targetPoint);
|
|
4307
|
-
}
|
|
4308
|
-
else if (elements.length === 0) {
|
|
4309
|
-
const mindElements = getSelectedMindElements(board);
|
|
4310
|
-
if (mindElements.length === 1) {
|
|
4311
|
-
const text = getTextFromClipboard(data);
|
|
4312
|
-
if (text) {
|
|
4313
|
-
insertClipboardText(board, mindElements[0], buildText(text));
|
|
4314
|
-
return;
|
|
4315
|
-
}
|
|
4316
|
-
}
|
|
4317
|
-
}
|
|
4318
|
-
insertFragment(data, targetPoint);
|
|
4319
|
-
};
|
|
4320
|
-
return withNodeResize(withNodeImageResize(withNodeImage(withNodeHoverDetect(withMindHotkey(withMindExtend(withCreateMind(withAbstract(withNodeDnd(board)))))))));
|
|
4326
|
+
return withNodeResize(withNodeImageResize(withNodeImage(withNodeHoverDetect(withMindFragment(withMindHotkey(withMindExtend(withCreateMind(withAbstract(withNodeDnd(board))))))))));
|
|
4321
4327
|
};
|
|
4322
4328
|
|
|
4323
4329
|
class MindEmojiBaseComponent {
|
|
@@ -4395,9 +4401,6 @@ class MindImageBaseComponent {
|
|
|
4395
4401
|
getRectangle: (element) => {
|
|
4396
4402
|
return getImageForeignRectangle(this.board, this.element);
|
|
4397
4403
|
},
|
|
4398
|
-
getStrokeWidthByElement: () => {
|
|
4399
|
-
return 0;
|
|
4400
|
-
},
|
|
4401
4404
|
hasResizeHandle: () => true
|
|
4402
4405
|
});
|
|
4403
4406
|
this.initialized = true;
|