@plait/mind 0.92.2 → 0.93.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.
@@ -267,7 +267,7 @@ const getCorrespondingAbstract = (element) => {
267
267
  if (!parent)
268
268
  return undefined;
269
269
  const elementIndex = parent.children.indexOf(element);
270
- return parent.children.find(child => {
270
+ return parent.children.find((child) => {
271
271
  return AbstractNode.isAbstract(child) && elementIndex >= child.start && elementIndex <= child.end;
272
272
  });
273
273
  };
@@ -276,7 +276,7 @@ const getBehindAbstracts = (element) => {
276
276
  if (!parent)
277
277
  return [];
278
278
  const index = parent.children.indexOf(element);
279
- return parent.children.filter(child => AbstractNode.isAbstract(child) && child.start > index);
279
+ return parent.children.filter((child) => AbstractNode.isAbstract(child) && child.start > index);
280
280
  };
281
281
  /**
282
282
  * return corresponding abstract that is not child of elements
@@ -284,13 +284,15 @@ const getBehindAbstracts = (element) => {
284
284
  const getOverallAbstracts = (board, elements) => {
285
285
  const overallAbstracts = [];
286
286
  elements
287
- .filter(value => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
288
- .forEach(value => {
287
+ .filter((value) => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
288
+ .forEach((value) => {
289
289
  const abstract = getCorrespondingAbstract(value);
290
290
  if (abstract && elements.indexOf(abstract) === -1 && overallAbstracts.indexOf(abstract) === -1) {
291
291
  const { start, end } = abstract;
292
292
  const parent = MindElement.getParent(value);
293
- const isOverall = parent.children.slice(start, end + 1).every(includedElement => elements.indexOf(includedElement) > -1);
293
+ const isOverall = parent.children
294
+ .slice(start, end + 1)
295
+ .every((includedElement) => elements.indexOf(includedElement) > -1);
294
296
  if (isOverall) {
295
297
  overallAbstracts.push(abstract);
296
298
  }
@@ -304,11 +306,11 @@ const getOverallAbstracts = (board, elements) => {
304
306
  const getValidAbstractRefs = (board, elements) => {
305
307
  const validAbstractRefs = [];
306
308
  elements
307
- .filter(value => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
308
- .forEach(value => {
309
+ .filter((value) => !AbstractNode.isAbstract(value) && !PlaitMind.isMind(value))
310
+ .forEach((value) => {
309
311
  const abstract = getCorrespondingAbstract(value);
310
312
  if (abstract && elements.indexOf(abstract) > 0) {
311
- const index = validAbstractRefs.findIndex(value => value.abstract === abstract);
313
+ const index = validAbstractRefs.findIndex((value) => value.abstract === abstract);
312
314
  if (index === -1) {
313
315
  validAbstractRefs.push({
314
316
  abstract: abstract,
@@ -334,14 +336,14 @@ isExtendPreviousNode = true, effectedAbstracts = new Map()) => {
334
336
  const hasPreviousNode = path[path.length - 1] !== 0;
335
337
  let behindAbstracts;
336
338
  if (!hasPreviousNode) {
337
- behindAbstracts = parent.children.filter(child => AbstractNode.isAbstract(child));
339
+ behindAbstracts = parent.children.filter((child) => AbstractNode.isAbstract(child));
338
340
  }
339
341
  else {
340
342
  const selectedElement = PlaitNode.get(board, Path.previous(path));
341
343
  behindAbstracts = getBehindAbstracts(selectedElement);
342
344
  }
343
345
  if (behindAbstracts.length) {
344
- behindAbstracts.forEach(abstract => {
346
+ behindAbstracts.forEach((abstract) => {
345
347
  let newProperties = effectedAbstracts.get(abstract);
346
348
  if (!newProperties) {
347
349
  newProperties = { start: 0, end: 0 };
@@ -368,11 +370,11 @@ isExtendPreviousNode = true, effectedAbstracts = new Map()) => {
368
370
  return effectedAbstracts;
369
371
  };
370
372
  const deleteElementHandleAbstract = (board, deletableElements, effectedAbstracts = new Map()) => {
371
- deletableElements.forEach(node => {
373
+ deletableElements.forEach((node) => {
372
374
  if (!PlaitMind.isMind(node)) {
373
- const behindAbstracts = getBehindAbstracts(node).filter(abstract => !deletableElements.includes(abstract));
375
+ const behindAbstracts = getBehindAbstracts(node).filter((abstract) => !deletableElements.includes(abstract));
374
376
  if (behindAbstracts.length) {
375
- behindAbstracts.forEach(abstract => {
377
+ behindAbstracts.forEach((abstract) => {
376
378
  let newProperties = effectedAbstracts.get(abstract);
377
379
  if (!newProperties) {
378
380
  newProperties = { start: 0, end: 0 };
@@ -397,7 +399,7 @@ const deleteElementHandleAbstract = (board, deletableElements, effectedAbstracts
397
399
  };
398
400
  const isChildOfAbstract = (board, element) => {
399
401
  const ancestors = MindElement.getAncestors(board, element);
400
- return !!ancestors.find(value => AbstractNode.isAbstract(value));
402
+ return !!ancestors.find((value) => AbstractNode.isAbstract(value));
401
403
  };
402
404
 
403
405
  /**
@@ -446,7 +448,7 @@ const getDefaultBranchColorByIndex = (board, index) => {
446
448
  };
447
449
  const getMindThemeColor = (board) => {
448
450
  const themeColors = PlaitBoard.getThemeColors(board);
449
- const themeColor = themeColors.find(val => val.mode === board.theme.themeColorMode);
451
+ const themeColor = themeColors.find((val) => val.mode === board.theme.themeColorMode);
450
452
  if (themeColor && MindThemeColor.isMindThemeColor(themeColor)) {
451
453
  return themeColor;
452
454
  }
@@ -487,21 +489,21 @@ const getShapeByElement = (board, element) => {
487
489
 
488
490
  function editTopic(element) {
489
491
  const textManage = getFirstTextManage(element);
490
- textManage?.edit(() => { }, event => {
492
+ textManage?.edit(() => { }, (event) => {
491
493
  const keyboardEvent = event;
492
494
  return keyboardEvent.key === 'Enter' && !keyboardEvent.shiftKey;
493
495
  });
494
496
  }
495
497
  const getSelectedMindElements = (board, elements) => {
496
498
  const selectedElements = elements?.length ? elements : getSelectedElements(board);
497
- return selectedElements.filter(value => MindElement.isMindElement(board, value));
499
+ return selectedElements.filter((value) => MindElement.isMindElement(board, value));
498
500
  };
499
501
 
500
502
  const getBranchDirectionsByLayouts = (branchLayouts) => {
501
503
  const branchDirections = [];
502
- branchLayouts.forEach(l => {
504
+ branchLayouts.forEach((l) => {
503
505
  const directions = LayoutDirectionsMap[l];
504
- directions.forEach(d => {
506
+ directions.forEach((d) => {
505
507
  if (!branchDirections.includes(d) && !branchDirections.includes(getLayoutReverseDirection(d))) {
506
508
  branchDirections.push(d);
507
509
  }
@@ -522,7 +524,7 @@ const getInCorrectLayoutDirection = (rootLayout, layout) => {
522
524
  if (!subLayoutDirections) {
523
525
  throw new Error(`unexpected layout: ${layout} on correct layout`);
524
526
  }
525
- return subLayoutDirections.find(d => directions.includes(getLayoutReverseDirection(d)));
527
+ return subLayoutDirections.find((d) => directions.includes(getLayoutReverseDirection(d)));
526
528
  };
527
529
  const correctLayoutByDirection = (layout, direction) => {
528
530
  const isHorizontal = direction === LayoutDirection.left || direction === LayoutDirection.right ? true : false;
@@ -569,8 +571,8 @@ const getAvailableSubLayoutsByLayoutDirections = (directions) => {
569
571
  const layout = MindLayoutType[key];
570
572
  const layoutDirections = LayoutDirectionsMap[layout];
571
573
  if (layoutDirections) {
572
- const hasSameDirection = layoutDirections.some(d => directions.includes(d));
573
- const hasReverseDirection = layoutDirections.some(r => reverseDirections.includes(r));
574
+ const hasSameDirection = layoutDirections.some((d) => directions.includes(d));
575
+ const hasReverseDirection = layoutDirections.some((r) => reverseDirections.includes(r));
574
576
  if (hasSameDirection && !hasReverseDirection) {
575
577
  result.push(layout);
576
578
  }
@@ -1042,7 +1044,7 @@ const isHitImage = (board, element, point) => {
1042
1044
  const getHitImageResizeHandleDirection = (board, element, point) => {
1043
1045
  const imageRectangle = getImageForeignRectangle(board, element);
1044
1046
  const resizeHandleRefs = getRectangleResizeHandleRefs(imageRectangle, RESIZE_HANDLE_DIAMETER);
1045
- const result = resizeHandleRefs.find(resizeHandleRef => {
1047
+ const result = resizeHandleRefs.find((resizeHandleRef) => {
1046
1048
  return RectangleClient.isHit(RectangleClient.getRectangleByPoints([point, point]), resizeHandleRef.rectangle);
1047
1049
  });
1048
1050
  return result;
@@ -1109,14 +1111,14 @@ const getNewNodeHeight = (board, element, newNodeDynamicWidth) => {
1109
1111
  const addActiveOnDragOrigin = (activeElement) => {
1110
1112
  PlaitElement.getElementG(activeElement).classList.add('dragging-node');
1111
1113
  !activeElement.isCollapsed &&
1112
- activeElement.children.forEach(child => {
1114
+ activeElement.children.forEach((child) => {
1113
1115
  addActiveOnDragOrigin(child);
1114
1116
  });
1115
1117
  };
1116
1118
  const removeActiveOnDragOrigin = (activeElement) => {
1117
1119
  PlaitElement.getElementG(activeElement).classList.remove('dragging-node');
1118
1120
  !activeElement.isCollapsed &&
1119
- activeElement.children.forEach(child => {
1121
+ activeElement.children.forEach((child) => {
1120
1122
  removeActiveOnDragOrigin(child);
1121
1123
  });
1122
1124
  };
@@ -1598,7 +1600,7 @@ class NodeEmojisGenerator {
1598
1600
  const container = document.createElement('div');
1599
1601
  container.classList.add('node-emojis-container');
1600
1602
  foreignObject.append(container);
1601
- this.emojiGenerators = element.data.emojis.map(emojiItem => {
1603
+ this.emojiGenerators = element.data.emojis.map((emojiItem) => {
1602
1604
  const drawer = new EmojiGenerator(this.board);
1603
1605
  drawer.draw(container, emojiItem, element);
1604
1606
  return drawer;
@@ -1611,7 +1613,7 @@ class NodeEmojisGenerator {
1611
1613
  if (this.g) {
1612
1614
  this.g.remove();
1613
1615
  }
1614
- this.emojiGenerators.forEach(drawer => drawer.destroy());
1616
+ this.emojiGenerators.forEach((drawer) => drawer.destroy());
1615
1617
  this.emojiGenerators = [];
1616
1618
  }
1617
1619
  }
@@ -1959,11 +1961,11 @@ const getLocationScope = (board, handlePosition, parentChildren, element, parent
1959
1961
  const startNode = parentChildren[start];
1960
1962
  const endNode = parentChildren[end];
1961
1963
  if (handlePosition === AbstractHandlePosition.start) {
1962
- const abstractNode = parentChildren.filter(child => AbstractNode.isAbstract(child) && child.end < element.start);
1964
+ const abstractNode = parentChildren.filter((child) => AbstractNode.isAbstract(child) && child.end < element.start);
1963
1965
  let minNode;
1964
1966
  if (abstractNode.length) {
1965
1967
  const index = abstractNode
1966
- .map(node => {
1968
+ .map((node) => {
1967
1969
  const { end } = getCorrectStartEnd(node, parent);
1968
1970
  return end;
1969
1971
  })
@@ -1989,11 +1991,11 @@ const getLocationScope = (board, handlePosition, parentChildren, element, parent
1989
1991
  }
1990
1992
  }
1991
1993
  else {
1992
- const abstractNode = parentChildren.filter(child => AbstractNode.isAbstract(child) && child.start > element.end);
1994
+ const abstractNode = parentChildren.filter((child) => AbstractNode.isAbstract(child) && child.start > element.end);
1993
1995
  let maxNode;
1994
1996
  if (abstractNode.length) {
1995
1997
  const index = abstractNode
1996
- .map(node => {
1998
+ .map((node) => {
1997
1999
  const { start } = getCorrectStartEnd(node, parent);
1998
2000
  return start;
1999
2001
  })
@@ -2001,7 +2003,7 @@ const getLocationScope = (board, handlePosition, parentChildren, element, parent
2001
2003
  maxNode = parentChildren[index - 1];
2002
2004
  }
2003
2005
  else {
2004
- const children = parentChildren.filter(child => !AbstractNode.isAbstract(child));
2006
+ const children = parentChildren.filter((child) => !AbstractNode.isAbstract(child));
2005
2007
  maxNode = parentChildren[children.length - 1];
2006
2008
  }
2007
2009
  const maxNodeRectangle = getRectangleByElements(board, [maxNode], true);
@@ -2051,10 +2053,10 @@ const getAbstractHandleRectangle = (rectangle, isHorizontal, position) => {
2051
2053
  return result;
2052
2054
  };
2053
2055
  function findLocationLeftIndex(board, parentChildren, location, isHorizontal) {
2054
- const children = parentChildren.filter(child => {
2056
+ const children = parentChildren.filter((child) => {
2055
2057
  return !AbstractNode.isAbstract(child);
2056
2058
  });
2057
- const recArray = children.map(child => {
2059
+ const recArray = children.map((child) => {
2058
2060
  return getRectangleByElements(board, [child], false);
2059
2061
  });
2060
2062
  const firstRec = getRectangleByElements(board, [children[0]], true);
@@ -2085,7 +2087,7 @@ function findLocationLeftIndex(board, parentChildren, location, isHorizontal) {
2085
2087
  }
2086
2088
  function handleTouchedAbstract(board, touchedAbstract, endPoint) {
2087
2089
  let touchedHandle;
2088
- const abstract = getSelectedElements(board).filter(element => AbstractNode.isAbstract(element)).find(element => {
2090
+ const abstract = getSelectedElements(board).filter((element) => AbstractNode.isAbstract(element)).find((element) => {
2089
2091
  touchedHandle = getHitAbstractHandle(board, element, endPoint);
2090
2092
  return touchedHandle;
2091
2093
  });
@@ -2180,7 +2182,7 @@ const getCorrectLayoutByElement = (board, element) => {
2180
2182
  correctRootLayout = node.left ? MindLayoutType.left : MindLayoutType.right;
2181
2183
  }
2182
2184
  let layout = null;
2183
- const elementWithLayout = ancestors.find(value => value.layout || AbstractNode.isAbstract(value));
2185
+ const elementWithLayout = ancestors.find((value) => value.layout || AbstractNode.isAbstract(value));
2184
2186
  if (elementWithLayout) {
2185
2187
  if (AbstractNode.isAbstract(elementWithLayout)) {
2186
2188
  const parent = MindElement.getParent(elementWithLayout);
@@ -2234,7 +2236,7 @@ const getAvailableSubLayoutsByElement = (board, element) => {
2234
2236
  const parentLayout = [branchLayouts[branchLayouts.length - 1]];
2235
2237
  const parentDirections = getBranchDirectionsByLayouts(parentLayout);
2236
2238
  const parentAvailableSubLayouts = getAvailableSubLayoutsByLayoutDirections(parentDirections);
2237
- availableSubLayouts = availableSubLayouts.filter(layout => parentAvailableSubLayouts.some(parentAvailableSubLayout => parentAvailableSubLayout === layout));
2239
+ availableSubLayouts = availableSubLayouts.filter((layout) => parentAvailableSubLayouts.some((parentAvailableSubLayout) => parentAvailableSubLayout === layout));
2238
2240
  return availableSubLayouts;
2239
2241
  }
2240
2242
  return undefined;
@@ -2347,7 +2349,7 @@ function drawAbstractLink(board, node, isHorizontal) {
2347
2349
  const parent = node.parent;
2348
2350
  const branchShape = getBranchShapeByMindElement(board, node.origin);
2349
2351
  const abstractRectangle = getRectangleByNode(node);
2350
- let includedElements = parent.children.slice(node.origin.start, node.origin.end + 1).map(node => {
2352
+ let includedElements = parent.children.slice(node.origin.start, node.origin.end + 1).map((node) => {
2351
2353
  return node.origin;
2352
2354
  });
2353
2355
  const includedElementsRectangle = getRectangleByElements(board, includedElements, true);
@@ -2539,7 +2541,7 @@ const addEmoji = (board, element, emojiItem) => {
2539
2541
  Transforms.setNode(board, newElement, path);
2540
2542
  };
2541
2543
  const removeEmoji = (board, element, emojiItem) => {
2542
- const emojis = element.data.emojis.filter(value => value !== emojiItem);
2544
+ const emojis = element.data.emojis.filter((value) => value !== emojiItem);
2543
2545
  const newElement = {
2544
2546
  data: { topic: element.data.topic }
2545
2547
  };
@@ -2556,7 +2558,7 @@ const replaceEmoji = (board, element, oldEmoji, newEmoji) => {
2556
2558
  const newElement = {
2557
2559
  data: { ...element.data }
2558
2560
  };
2559
- const newEmojis = element.data.emojis.map(value => {
2561
+ const newEmojis = element.data.emojis.map((value) => {
2560
2562
  if (value === oldEmoji) {
2561
2563
  return newEmoji;
2562
2564
  }
@@ -3487,7 +3489,10 @@ const withMindHotkey = (baseBoard) => {
3487
3489
  const { history } = board;
3488
3490
  const { undos } = history;
3489
3491
  const previousOp = undos.length > 0 ? undos[undos.length - 1][0] : undefined;
3490
- if (previousOp && previousOp.type === 'insert_node' && MindElement.isMindElement(board, previousOp.node) && getFirstTextManage(previousOp.node).isEditing) {
3492
+ if (previousOp &&
3493
+ previousOp.type === 'insert_node' &&
3494
+ MindElement.isMindElement(board, previousOp.node) &&
3495
+ getFirstTextManage(previousOp.node).isEditing) {
3491
3496
  board.undo();
3492
3497
  }
3493
3498
  }
@@ -4050,7 +4055,7 @@ const withMindFragment = (baseBoard) => {
4050
4055
  };
4051
4056
  board.insertFragment = (clipboardData, targetPoint, operationType) => {
4052
4057
  if (clipboardData?.elements?.length) {
4053
- const mindElements = clipboardData.elements?.filter(value => MindElement.isMindElement(board, value));
4058
+ const mindElements = clipboardData.elements?.filter((value) => MindElement.isMindElement(board, value));
4054
4059
  if (mindElements && mindElements.length > 0) {
4055
4060
  insertClipboardData(board, mindElements, targetPoint, operationType);
4056
4061
  }
@@ -4088,7 +4093,7 @@ const getNextSelectedElement = (board, firstLevelElements) => {
4088
4093
  catch (error) { }
4089
4094
  const firstElement = firstLevelElements[0];
4090
4095
  const firstElementParent = MindElement.findParent(firstElement);
4091
- const hasSameParent = firstLevelElements.every(element => {
4096
+ const hasSameParent = firstLevelElements.every((element) => {
4092
4097
  return MindElement.findParent(element) === firstElementParent;
4093
4098
  });
4094
4099
  if (firstElementParent && hasSameParent && !activeElement) {
@@ -4203,12 +4208,12 @@ const withMind = (baseBoard) => {
4203
4208
  }
4204
4209
  return isHit(element, point, isStrict);
4205
4210
  };
4206
- board.getOneHitElement = (elements) => {
4211
+ board.getOneHitElement = (elements, hitPoint) => {
4207
4212
  const isAllMindElements = elements.every((item) => MindElement.isMindElement(board, item));
4208
4213
  if (isAllMindElements) {
4209
4214
  return elements[0];
4210
4215
  }
4211
- return getOneHitElement(elements);
4216
+ return getOneHitElement(elements, hitPoint);
4212
4217
  };
4213
4218
  board.isMovable = (element) => {
4214
4219
  if (PlaitMind.isMind(element)) {