@plait/mind 0.85.0 → 0.86.1

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.
@@ -478,7 +478,7 @@ const getFillByElement = (board, element) => {
478
478
  return element.fill;
479
479
  }
480
480
  const defaultRootFill = getMindThemeColor(board).rootFill;
481
- return element.isRoot ? defaultRootFill : DefaultNodeStyle.shape.fill;
481
+ return PlaitMind.isMind(element) ? defaultRootFill : DefaultNodeStyle.shape.fill;
482
482
  };
483
483
  const getShapeByElement = (board, element) => {
484
484
  const shape = getAvailableProperty(board, element, 'shape');
@@ -602,7 +602,7 @@ const getRootLayout = (root) => {
602
602
 
603
603
  const getLayoutOptions = (board) => {
604
604
  function getMainAxle(element, parent) {
605
- if (element.isRoot) {
605
+ if (PlaitMind.isMind(element)) {
606
606
  return BASE * 12;
607
607
  }
608
608
  if (parent && parent.isRoot()) {
@@ -611,7 +611,7 @@ const getLayoutOptions = (board) => {
611
611
  return BASE * 3;
612
612
  }
613
613
  function getSecondAxle(element, parent) {
614
- if (element.isRoot) {
614
+ if (PlaitMind.isMind(element)) {
615
615
  return BASE * 12;
616
616
  }
617
617
  return BASE * 8.5;
@@ -676,7 +676,6 @@ const getAbstractNodeText = (board) => {
676
676
  const createEmptyMind = (board, point) => {
677
677
  const text = getDefaultMindNameText(board);
678
678
  const element = createMindElement(text, { layout: MindLayoutType.right });
679
- element.isRoot = true;
680
679
  element.type = 'mind';
681
680
  const width = NodeSpace.getNodeWidth(board, element);
682
681
  const height = NodeSpace.getNodeHeight(board, element);
@@ -761,7 +760,7 @@ const copyNewNode = (node) => {
761
760
  };
762
761
  const insertMindElement = (board, inheritNode, path) => {
763
762
  const newNode = {};
764
- if (!inheritNode.isRoot) {
763
+ if (!PlaitMind.isMind(inheritNode)) {
765
764
  INHERIT_ATTRIBUTE_KEYS.forEach((attr) => {
766
765
  newNode[attr] = inheritNode[attr];
767
766
  });
@@ -1051,7 +1050,6 @@ const getHitImageResizeHandleDirection = (board, element, point) => {
1051
1050
 
1052
1051
  const adjustRootToNode = (board, node) => {
1053
1052
  const newNode = { ...node };
1054
- delete newNode.isRoot;
1055
1053
  delete newNode.rightNodeCount;
1056
1054
  newNode.type = 'mind_child';
1057
1055
  if (newNode.layout === MindLayoutType.standard) {
@@ -1078,7 +1076,6 @@ const adjustNodeToRoot = (board, node) => {
1078
1076
  return {
1079
1077
  ...newElement,
1080
1078
  layout: newElement.layout ?? MindLayoutType.right,
1081
- isRoot: true,
1082
1079
  type: 'mind'
1083
1080
  };
1084
1081
  };
@@ -1165,10 +1162,10 @@ const isDropStandardRight = (parent, dropTarget) => {
1165
1162
  };
1166
1163
 
1167
1164
  const directionCorrector = (board, node, detectResults) => {
1168
- if (!node.origin.isRoot && !AbstractNode.isAbstract(node.origin)) {
1165
+ if (!PlaitMind.isMind(node.origin) && !AbstractNode.isAbstract(node.origin)) {
1169
1166
  const parentLayout = MindQueries.getCorrectLayoutByElement(board, node?.parent.origin);
1170
1167
  if (isStandardLayout(parentLayout)) {
1171
- const idx = node.parent.children.findIndex(x => x === node);
1168
+ const idx = node.parent.children.findIndex((x) => x === node);
1172
1169
  const isLeft = idx >= (node.parent.origin.rightNodeCount || 0);
1173
1170
  return getAllowedDirection(detectResults, [isLeft ? 'right' : 'left']);
1174
1171
  }
@@ -1207,8 +1204,8 @@ const directionCorrector = (board, node, detectResults) => {
1207
1204
  };
1208
1205
  const getAllowedDirection = (detectResults, illegalDirections) => {
1209
1206
  const directions = detectResults;
1210
- illegalDirections.forEach(item => {
1211
- const bottomDirectionIndex = directions.findIndex(direction => direction === item);
1207
+ illegalDirections.forEach((item) => {
1208
+ const bottomDirectionIndex = directions.findIndex((direction) => direction === item);
1212
1209
  if (bottomDirectionIndex !== -1) {
1213
1210
  directions.splice(bottomDirectionIndex, 1);
1214
1211
  }
@@ -1217,7 +1214,7 @@ const getAllowedDirection = (detectResults, illegalDirections) => {
1217
1214
  };
1218
1215
  const detectDropTarget = (board, detectPoint, dropTarget, activeElements) => {
1219
1216
  let detectResult = null;
1220
- depthFirstRecursion(board, element => {
1217
+ depthFirstRecursion(board, (element) => {
1221
1218
  if (!MindElement.isMindElement(board, element) || detectResult) {
1222
1219
  return;
1223
1220
  }
@@ -1227,7 +1224,7 @@ const detectDropTarget = (board, detectPoint, dropTarget, activeElements) => {
1227
1224
  detectResult = directionCorrector(board, node, directions);
1228
1225
  }
1229
1226
  dropTarget = null;
1230
- const isValid = activeElements.every(element => isValidTarget(element, node.origin));
1227
+ const isValid = activeElements.every((element) => isValidTarget(element, node.origin));
1231
1228
  if (detectResult && isValid) {
1232
1229
  dropTarget = { target: node.origin, detectResult: detectResult[0] };
1233
1230
  }
@@ -1489,7 +1486,7 @@ function drawLogicLink(board, parent, node, isHorizontal, defaultStrokeColor = n
1489
1486
  const branchColor = defaultStrokeColor || getBranchColorByMindElement(board, node.origin);
1490
1487
  const branchWidth = defaultStrokeWidth || getBranchWidthByMindElement(board, node.origin);
1491
1488
  const strokeStyle = defaultStrokeStyle || getStrokeStyleByElement(board, node.origin);
1492
- const hasStraightLine = branchShape === BranchShape.polyline ? true : !parent.origin.isRoot;
1489
+ const hasStraightLine = branchShape === BranchShape.polyline ? true : !PlaitMind.isMind(parent.origin);
1493
1490
  const parentShape = getShapeByElement(board, parent.origin);
1494
1491
  const shape = getShapeByElement(board, node.origin);
1495
1492
  const hasUnderlineShape = shape === MindElementShape.underline;
@@ -1504,7 +1501,7 @@ function drawLogicLink(board, parent, node, isHorizontal, defaultStrokeColor = n
1504
1501
  transformPlacement(beginPlacement, linkDirection);
1505
1502
  transformPlacement(endPlacement, linkDirection);
1506
1503
  // underline shape and horizontal
1507
- if (isHorizontal && hasUnderlineShapeOfParent && !parent.origin.isRoot) {
1504
+ if (isHorizontal && hasUnderlineShapeOfParent && !PlaitMind.isMind(parent.origin)) {
1508
1505
  beginPlacement[1] = VerticalPlacement.bottom;
1509
1506
  }
1510
1507
  if (isHorizontal && hasUnderlineShape) {
@@ -2113,8 +2110,8 @@ function handleTouchedAbstract(board, touchedAbstract, endPoint) {
2113
2110
  const isInRightBranchOfStandardLayout = (selectedElement) => {
2114
2111
  const parentElement = MindElement.findParent(selectedElement);
2115
2112
  if (parentElement) {
2116
- const nodeIndex = parentElement.children.findIndex(item => item.id === selectedElement.id);
2117
- if (parentElement.isRoot &&
2113
+ const nodeIndex = parentElement.children.findIndex((item) => item.id === selectedElement.id);
2114
+ if (PlaitMind.isMind(parentElement) &&
2118
2115
  getRootLayout(parentElement) === MindLayoutType.standard &&
2119
2116
  parentElement.rightNodeCount &&
2120
2117
  nodeIndex <= parentElement.rightNodeCount - 1) {
@@ -2124,7 +2121,7 @@ const isInRightBranchOfStandardLayout = (selectedElement) => {
2124
2121
  return false;
2125
2122
  };
2126
2123
  const insertElementHandleRightNodeCount = (board, path, insertCount, effectedRightNodeCount = []) => {
2127
- let index = effectedRightNodeCount.findIndex(ref => Path.equals(ref.path, path));
2124
+ let index = effectedRightNodeCount.findIndex((ref) => Path.equals(ref.path, path));
2128
2125
  const mind = PlaitNode.get(board, path);
2129
2126
  if (index === -1) {
2130
2127
  effectedRightNodeCount.push({ path, rightNodeCount: mind.rightNodeCount + insertCount });
@@ -2135,11 +2132,11 @@ const insertElementHandleRightNodeCount = (board, path, insertCount, effectedRig
2135
2132
  return effectedRightNodeCount;
2136
2133
  };
2137
2134
  const deleteElementsHandleRightNodeCount = (board, deletableElements, effectedRightNodeCount = []) => {
2138
- deletableElements.forEach(element => {
2135
+ deletableElements.forEach((element) => {
2139
2136
  if (isInRightBranchOfStandardLayout(element)) {
2140
2137
  const mind = MindElement.getParent(element);
2141
2138
  const path = PlaitBoard.findPath(board, mind);
2142
- let index = effectedRightNodeCount.findIndex(ref => Path.equals(ref.path, path));
2139
+ let index = effectedRightNodeCount.findIndex((ref) => Path.equals(ref.path, path));
2143
2140
  if (index === -1) {
2144
2141
  effectedRightNodeCount.push({ path, rightNodeCount: mind.rightNodeCount - 1 });
2145
2142
  }
@@ -2854,7 +2851,7 @@ const getMoreStartAndEnd = (board, element, linkLineDirection) => {
2854
2851
  // underline shape and horizontal
2855
2852
  const layout = MindQueries.getLayoutByElement(element);
2856
2853
  const isHorizontal = isHorizontalLayout(layout);
2857
- if (isHorizontal && isUnderlineShape && !element.isRoot) {
2854
+ if (isHorizontal && isUnderlineShape && !PlaitMind.isMind(element)) {
2858
2855
  placement[1] = VerticalPlacement.bottom;
2859
2856
  }
2860
2857
  let startPoint = getPointByPlacement(nodeClient, placement);
@@ -3074,7 +3071,7 @@ const withNodeDnd = (board) => {
3074
3071
  MindElement.isMindElement(board, hitElement) &&
3075
3072
  !PlaitMind.isMind(hitElement) &&
3076
3073
  !AbstractNode.isAbstract(hitElement)) {
3077
- const targetElements = selectedElements.filter(element => MindElement.isMindElement(board, element) && !element.isRoot && !AbstractNode.isAbstract(element));
3074
+ const targetElements = selectedElements.filter((element) => MindElement.isMindElement(board, element) && !PlaitMind.isMind(element) && !AbstractNode.isAbstract(element));
3078
3075
  const isMultipleSelection = selectedElements.length > 0 && selectedElements.includes(hitElement);
3079
3076
  if (isMultipleSelection) {
3080
3077
  activeElements = targetElements;
@@ -3110,10 +3107,10 @@ const withNodeDnd = (board) => {
3110
3107
  const offsetY = endPoint[1] - startPoint[1];
3111
3108
  dragFakeNodeG?.remove();
3112
3109
  dragFakeNodeG = createG();
3113
- [...activeElements, ...correspondingElements].forEach(element => {
3110
+ [...activeElements, ...correspondingElements].forEach((element) => {
3114
3111
  addActiveOnDragOrigin(element);
3115
3112
  });
3116
- activeElements.forEach(element => {
3113
+ activeElements.forEach((element) => {
3117
3114
  const nodeG = drawFakeDragNode(board, element, offsetX, offsetY);
3118
3115
  dragFakeNodeG?.appendChild(nodeG);
3119
3116
  });
@@ -3127,7 +3124,7 @@ const withNodeDnd = (board) => {
3127
3124
  if (!board.options.readonly && firstLevelElements.length) {
3128
3125
  firstLevelElements.push(...correspondingElements);
3129
3126
  if (isDragging(board)) {
3130
- firstLevelElements.forEach(element => {
3127
+ firstLevelElements.forEach((element) => {
3131
3128
  removeActiveOnDragOrigin(element);
3132
3129
  });
3133
3130
  }
@@ -3137,8 +3134,8 @@ const withNodeDnd = (board) => {
3137
3134
  const targetElementPathRef = board.pathRef(PlaitBoard.findPath(board, dropTarget.target));
3138
3135
  let abstractRefs = getValidAbstractRefs(board, firstLevelElements);
3139
3136
  const normalElements = firstLevelElements
3140
- .filter(element => !abstractRefs.some(refs => refs.abstract === element))
3141
- .map(element => {
3137
+ .filter((element) => !abstractRefs.some((refs) => refs.abstract === element))
3138
+ .map((element) => {
3142
3139
  if (AbstractNode.isAbstract(element)) {
3143
3140
  return adjustAbstractToNode(element);
3144
3141
  }
@@ -3150,7 +3147,7 @@ const withNodeDnd = (board) => {
3150
3147
  const correspondingAbstract = getCorrespondingAbstract(previousElement);
3151
3148
  const targetHasCorrespondAbstract = correspondingAbstract && correspondingAbstract.end !== targetPath[targetPath.length - 1] - 1;
3152
3149
  if (targetHasCorrespondAbstract) {
3153
- const adjustedNode = abstractRefs.map(ref => {
3150
+ const adjustedNode = abstractRefs.map((ref) => {
3154
3151
  return adjustAbstractToNode(ref.abstract);
3155
3152
  });
3156
3153
  normalElements.push(...adjustedNode);
@@ -3195,8 +3192,8 @@ const withNodeDnd = (board) => {
3195
3192
  targetElementPathRef.unref();
3196
3193
  targetPathRef.unref();
3197
3194
  let setActiveElements = [];
3198
- depthFirstRecursion(board, node => {
3199
- const isSelected = activeElements.some(element => element.id === node.id);
3195
+ depthFirstRecursion(board, (node) => {
3196
+ const isSelected = activeElements.some((element) => element.id === node.id);
3200
3197
  if (isSelected) {
3201
3198
  setActiveElements.push(node);
3202
3199
  }
@@ -3891,7 +3888,7 @@ const insertClipboardData = (board, elements, targetPoint, operationType) => {
3891
3888
  elements.forEach((item, index) => {
3892
3889
  newElement = copyNewNode(item);
3893
3890
  if (hasTargetParent && operationType !== WritableClipboardOperationType.duplicate) {
3894
- if (item.isRoot) {
3891
+ if (PlaitMind.isMind(item)) {
3895
3892
  newElement = adjustRootToNode(board, newElement);
3896
3893
  }
3897
3894
  // handle abstract start and end
@@ -3907,7 +3904,7 @@ const insertClipboardData = (board, elements, targetPoint, operationType) => {
3907
3904
  if (AbstractNode.isAbstract(item)) {
3908
3905
  newElement = adjustAbstractToNode(newElement);
3909
3906
  }
3910
- if (!item.isRoot) {
3907
+ if (!PlaitMind.isMind(item)) {
3911
3908
  newElement = adjustNodeToRoot(board, newElement);
3912
3909
  }
3913
3910
  path = [board.children.length];
@@ -4088,13 +4085,13 @@ const withMind = (baseBoard) => {
4088
4085
  return getRectangle(element);
4089
4086
  };
4090
4087
  board.canAddToGroup = (element) => {
4091
- if (MindElement.isMindElement(board, element) && !element.isRoot) {
4088
+ if (MindElement.isMindElement(board, element) && !PlaitMind.isMind(element)) {
4092
4089
  return false;
4093
4090
  }
4094
4091
  return canAddToGroup(element);
4095
4092
  };
4096
4093
  board.canSetZIndex = (element) => {
4097
- if (MindElement.isMindElement(board, element) && !element.isRoot) {
4094
+ if (MindElement.isMindElement(board, element) && !PlaitMind.isMind(element)) {
4098
4095
  return false;
4099
4096
  }
4100
4097
  return canSetZIndex(element);
@@ -4129,7 +4126,7 @@ const withMind = (baseBoard) => {
4129
4126
  return getOneHitElement(elements);
4130
4127
  };
4131
4128
  board.isMovable = (element) => {
4132
- if (PlaitMind.isMind(element) && element.isRoot) {
4129
+ if (PlaitMind.isMind(element)) {
4133
4130
  return true;
4134
4131
  }
4135
4132
  return isMovable(element);
@@ -4141,7 +4138,7 @@ const withMind = (baseBoard) => {
4141
4138
  return isImageBindingAllowed(element);
4142
4139
  };
4143
4140
  board.isAlign = (element) => {
4144
- if (PlaitMind.isMind(element) && element.isRoot) {
4141
+ if (PlaitMind.isMind(element)) {
4145
4142
  return true;
4146
4143
  }
4147
4144
  return isAlign(element);