@plait/mind 0.19.0 → 0.20.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.
@@ -1,9 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Directive, Input, Component, ChangeDetectionStrategy, NgModule, NgZone, 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, PlaitNode, Path, PlaitBoard, depthFirstRecursion, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, getSelectedElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, 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';
4
+ import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, RectangleClient, PlaitElement, idCreator, isNullOrUndefined, Transforms, clearSelectedElement, addSelectedElement, PlaitNode, Path, PlaitBoard, depthFirstRecursion, getIsRecursionFunc, drawLinearPath, drawBezierPath, createG, updateForeignObject, drawRoundRectangle, getRectangleByElements, getSelectedElements, NODE_TO_PARENT, distanceBetweenPointAndRectangle, createForeignObject, createText, PlaitPointerType, PlaitPluginElementComponent, NODE_TO_INDEX, PlaitModule, isMainPointer, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CLIP_BOARD_FORMAT_KEY, BOARD_TO_HOST, PlaitPluginKey, throttleRAF, BoardTransforms, removeSelectedElement, PlaitHistoryBoard, hotkeys } from '@plait/core';
5
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';
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
8
  import { Node, Path as Path$1 } from 'slate';
9
9
  import { isKeyHotkey } from 'is-hotkey';
@@ -210,6 +210,14 @@ function getEmojiFontSize(element) {
210
210
  }
211
211
  }
212
212
 
213
+ const TOPIC_COLOR = '#333';
214
+ const TOPIC_FONT_SIZE = 14;
215
+ const ROOT_TOPIC_FONT_SIZE = 18;
216
+ const ROOT_TOPIC_HEIGHT = 25;
217
+ const TOPIC_DEFAULT_MAX_WORD_COUNT = 34;
218
+ const DEFAULT_FONT_FAMILY = 'PingFangSC-Regular, "PingFang SC"';
219
+ const BRANCH_FONT_FAMILY = 'PingFangSC-Medium, "PingFang SC"';
220
+
213
221
  const NodeDefaultSpace = {
214
222
  horizontal: {
215
223
  nodeAndText: BASE * 3,
@@ -248,15 +256,14 @@ const getSpaceEmojiAndText = (element) => {
248
256
  const NodeSpace = {
249
257
  getNodeWidth(board, element) {
250
258
  const nodeAndText = getHorizontalSpaceBetweenNodeAndText(board, element);
251
- const imageWidth = MindElement.hasImage(element) ? element.data.image?.width : 0;
252
259
  if (MindElement.hasEmojis(element)) {
253
260
  return (NodeSpace.getEmojiLeftSpace(board, element) +
254
261
  getEmojisWidthHeight(board, element).width +
255
262
  getSpaceEmojiAndText(element) +
256
- Math.max(element.width, imageWidth) +
263
+ NodeSpace.getNodeResizableWidth(board, element) +
257
264
  nodeAndText);
258
265
  }
259
- return nodeAndText + Math.max(element.width, imageWidth) + nodeAndText;
266
+ return nodeAndText + NodeSpace.getNodeResizableWidth(board, element) + nodeAndText;
260
267
  },
261
268
  getNodeHeight(board, element) {
262
269
  const nodeAndText = getVerticalSpaceBetweenNodeAndText(element);
@@ -269,6 +276,26 @@ const NodeSpace = {
269
276
  }
270
277
  return nodeAndText + element.height + nodeAndText;
271
278
  },
279
+ getNodeResizableWidth(board, element) {
280
+ const imageWidth = MindElement.hasImage(element) ? element.data.image?.width : 0;
281
+ return Math.max(element.width, imageWidth);
282
+ },
283
+ getNodeResizableMinWidth(board, element) {
284
+ const minTopicWidth = NodeSpace.getNodeTopicMinWidth(board, element);
285
+ if (MindElement.hasImage(element) && element.data.image.width > minTopicWidth) {
286
+ return element.data.image.width;
287
+ }
288
+ else {
289
+ return minTopicWidth;
290
+ }
291
+ },
292
+ getNodeTopicMinWidth(board, element, isRoot = false) {
293
+ const defaultFontSize = getNodeDefaultFontSize(isRoot);
294
+ const editor = MindElement.getTextEditor(element);
295
+ const marks = PlaitMarkEditor.getMarks(editor);
296
+ const fontSize = marks[MarkTypes.fontSize] || defaultFontSize;
297
+ return fontSize;
298
+ },
272
299
  getTextLeftSpace(board, element) {
273
300
  const nodeAndText = getHorizontalSpaceBetweenNodeAndText(board, element);
274
301
  if (MindElement.hasEmojis(element)) {
@@ -300,6 +327,19 @@ const NodeSpace = {
300
327
  return nodeAndText;
301
328
  }
302
329
  };
330
+ const getFontSizeBySlateElement = (text) => {
331
+ const defaultFontSize = DEFAULT_FONT_SIZE;
332
+ if (typeof text === 'string') {
333
+ return defaultFontSize;
334
+ }
335
+ const marks = PlaitMarkEditor.getMarksByElement(text);
336
+ const fontSize = marks[MarkTypes.fontSize] || defaultFontSize;
337
+ return fontSize;
338
+ };
339
+ const getNodeDefaultFontSize = (isRoot = false) => {
340
+ const defaultFontSize = isRoot ? ROOT_TOPIC_FONT_SIZE : DEFAULT_FONT_SIZE;
341
+ return defaultFontSize;
342
+ };
303
343
 
304
344
  function getEmojiRectangle(board, element) {
305
345
  let { x, y } = getRectangleByNode(MindElement.getNode(element));
@@ -359,21 +399,11 @@ const isHitImage = (board, element, range) => {
359
399
  return RectangleClient.isHit(RectangleClient.toRectangleClient([range.anchor, range.focus]), client);
360
400
  };
361
401
 
362
- const NODE_MIN_WIDTH = 18;
363
-
364
402
  function editTopic(element) {
365
403
  const component = PlaitElement.getComponent(element);
366
404
  component?.editTopic();
367
405
  }
368
406
 
369
- const TOPIC_COLOR = '#333';
370
- const TOPIC_FONT_SIZE = 14;
371
- const ROOT_TOPIC_FONT_SIZE = 18;
372
- const ROOT_TOPIC_HEIGHT = 25;
373
- const TOPIC_DEFAULT_MAX_WORD_COUNT = 34;
374
- const DEFAULT_FONT_FAMILY = 'PingFangSC-Regular, "PingFang SC"';
375
- const BRANCH_FONT_FAMILY = 'PingFangSC-Medium, "PingFang SC"';
376
-
377
407
  const createEmptyMind = (point) => {
378
408
  const element = createMindElement('思维导图', 72, ROOT_TOPIC_HEIGHT, { layout: MindLayoutType.right });
379
409
  element.isRoot = true;
@@ -483,7 +513,7 @@ const insertMindElement = (board, inheritNode, path) => {
483
513
  });
484
514
  delete newNode.layout;
485
515
  }
486
- const newElement = createMindElement('', NODE_MIN_WIDTH, TEXT_DEFAULT_HEIGHT, newNode);
516
+ const newElement = createMindElement('', getNodeDefaultFontSize(), TEXT_DEFAULT_HEIGHT, newNode);
487
517
  Transforms.insertNode(board, newElement, path);
488
518
  clearSelectedElement(board);
489
519
  addSelectedElement(board, newElement);
@@ -648,7 +678,7 @@ const adjustNodeToRoot = (board, node) => {
648
678
  fontSize: ROOT_TOPIC_FONT_SIZE,
649
679
  fontFamily: BRANCH_FONT_FAMILY
650
680
  });
651
- newElement.width = Math.max(width, NODE_MIN_WIDTH);
681
+ newElement.width = Math.max(width, getNodeDefaultFontSize(true));
652
682
  newElement.height = height;
653
683
  return {
654
684
  ...newElement,
@@ -1069,14 +1099,7 @@ const detectDropTarget = (board, detectPoint, dropTarget, activeElements) => {
1069
1099
  if (detectResult && isValid) {
1070
1100
  dropTarget = { target: node.origin, detectResult: detectResult[0] };
1071
1101
  }
1072
- }, node => {
1073
- if (PlaitBoard.isBoard(node) || board.isRecursion(node)) {
1074
- return true;
1075
- }
1076
- else {
1077
- return false;
1078
- }
1079
- });
1102
+ }, getIsRecursionFunc(board));
1080
1103
  return dropTarget;
1081
1104
  };
1082
1105
  const directionDetector = (targetNode, centerPoint) => {
@@ -2265,24 +2288,25 @@ const correctLogicLayoutNode = (board, layout, path) => {
2265
2288
  }
2266
2289
  };
2267
2290
 
2268
- const normalizeWidthAndHeight = (board, width, height) => {
2269
- const newWidth = width < NODE_MIN_WIDTH * board.viewport.zoom ? NODE_MIN_WIDTH : width / board.viewport.zoom;
2291
+ const normalizeWidthAndHeight = (board, element, width, height) => {
2292
+ const minWidth = NodeSpace.getNodeTopicMinWidth(board, element, element.isRoot);
2293
+ const newWidth = width < minWidth * board.viewport.zoom ? minWidth : width / board.viewport.zoom;
2270
2294
  const newHeight = height / board.viewport.zoom;
2271
2295
  return { width: newWidth, height: newHeight };
2272
2296
  };
2273
2297
  const setTopic = (board, element, topic, width, height) => {
2274
2298
  const newElement = {
2275
2299
  data: { ...element.data, topic },
2276
- ...normalizeWidthAndHeight(board, width, height)
2300
+ ...normalizeWidthAndHeight(board, element, width, height)
2277
2301
  };
2278
2302
  const path = PlaitBoard.findPath(board, element);
2279
2303
  Transforms.setNode(board, newElement, path);
2280
2304
  };
2281
2305
  const setTopicSize = (board, element, width, height) => {
2282
2306
  const newElement = {
2283
- ...normalizeWidthAndHeight(board, width, height)
2307
+ ...normalizeWidthAndHeight(board, element, width, height)
2284
2308
  };
2285
- if (element.width !== newElement.width || element.height !== newElement.height) {
2309
+ if (Math.floor(element.width) !== Math.floor(newElement.width) || Math.floor(element.height) !== Math.floor(newElement.height)) {
2286
2310
  const path = PlaitBoard.findPath(board, element);
2287
2311
  Transforms.setNode(board, newElement, path);
2288
2312
  }
@@ -3172,7 +3196,7 @@ const withNodeDnd = (board) => {
3172
3196
  if (PlaitBoard.isReadonly(board) ||
3173
3197
  PlaitBoard.hasBeenTextEditing(board) ||
3174
3198
  !PlaitBoard.isPointer(board, PlaitPointerType.selection) ||
3175
- event.button === 2) {
3199
+ !isMainPointer(event)) {
3176
3200
  mousedown(event);
3177
3201
  return;
3178
3202
  }
@@ -3405,7 +3429,7 @@ const insertClipboardData = (board, elements, targetPoint) => {
3405
3429
  newElement = adjustRootToNode(board, newElement);
3406
3430
  const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
3407
3431
  const { width, height } = getTextSize(board, newElement.data.topic, TOPIC_DEFAULT_MAX_WORD_COUNT, styles);
3408
- newElement.width = Math.max(width, NODE_MIN_WIDTH);
3432
+ newElement.width = Math.max(width, getNodeDefaultFontSize());
3409
3433
  newElement.height = height;
3410
3434
  }
3411
3435
  // handle abstract start and end
@@ -3435,7 +3459,7 @@ const insertClipboardData = (board, elements, targetPoint) => {
3435
3459
  const insertClipboardText = (board, targetParent, text) => {
3436
3460
  const styles = PlaitMind.isMind(targetParent) ? { fontFamily: BRANCH_FONT_FAMILY } : { fontFamily: DEFAULT_FONT_FAMILY };
3437
3461
  const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, styles);
3438
- const newElement = createMindElement(text, width, height, {});
3462
+ const newElement = createMindElement(text, Math.max(width, getFontSizeBySlateElement(text)), height, {});
3439
3463
  Transforms.insertNode(board, newElement, findNewChildNodePath(board, targetParent));
3440
3464
  return;
3441
3465
  };
@@ -3783,14 +3807,7 @@ const withNodeHover = (board) => {
3783
3807
  if (isHitElement) {
3784
3808
  target = element;
3785
3809
  }
3786
- }, node => {
3787
- if (PlaitBoard.isBoard(node) || board.isRecursion(node)) {
3788
- return true;
3789
- }
3790
- else {
3791
- return false;
3792
- }
3793
- }, true);
3810
+ }, getIsRecursionFunc(board), true);
3794
3811
  if (hoveredMindElement && target && hoveredMindElement === target) {
3795
3812
  return;
3796
3813
  }
@@ -3873,8 +3890,9 @@ const withMindImage = (board) => {
3873
3890
  return board;
3874
3891
  };
3875
3892
 
3876
- const withMind = (board) => {
3877
- const { drawElement, dblclick, keydown, insertFragment, setFragment, deleteFragment, isHitSelection, getRectangle, isMovable, isRecursion } = board;
3893
+ const withMind = (baseBoard) => {
3894
+ const board = baseBoard;
3895
+ const { drawElement, dblclick, insertFragment, setFragment, deleteFragment, isHitSelection, getRectangle, isMovable, isRecursion } = board;
3878
3896
  board.drawElement = (context) => {
3879
3897
  if (PlaitMind.isMind(context.element)) {
3880
3898
  return PlaitMindComponent;
@@ -3931,14 +3949,7 @@ const withMind = (board) => {
3931
3949
  if (!PlaitBoard.hasBeenTextEditing(board) && isHitMindElement(board, point, node)) {
3932
3950
  editTopic(node);
3933
3951
  }
3934
- }, node => {
3935
- if (PlaitBoard.isBoard(node) || board.isRecursion(node)) {
3936
- return true;
3937
- }
3938
- else {
3939
- return false;
3940
- }
3941
- });
3952
+ }, getIsRecursionFunc(board));
3942
3953
  });
3943
3954
  if (PlaitBoard.hasBeenTextEditing(board)) {
3944
3955
  return;
@@ -4038,5 +4049,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
4038
4049
  * Generated bundle index. Do not edit.
4039
4050
  */
4040
4051
 
4041
- 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, MindImageBaseComponent, 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, getFillByElement, getFirstLevelElement, getHitAbstractHandle, getImageForeignRectangle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNextBranchColor, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getShapeByElement, getStrokeByMindElement, getStrokeWidthByElement, getTopicRectangleByElement, getTopicRectangleByNode, getValidAbstractRefs, handleTouchedAbstract, hasAfterDraw, hasPreviousOrNextOfDropPath, insertElementHandleAbstract, insertElementHandleRightNodeCount, insertMindElement, isChildElement, isChildOfAbstract, isChildRight, isChildUp, isCorrectLayout, isDragging, isDropStandardRight, isHitEmojis, isHitImage, isHitMindElement, isInRightBranchOfStandardLayout, isMixedLayout, isSetAbstract, isValidTarget, isVirtualKey, removeActiveOnDragOrigin, separateChildren, setIsDragging, withMind, withMindExtend };
4052
+ 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, MindImageBaseComponent, MindModule, MindNode, MindNodeComponent, MindPointerType, MindQueries, MindRetroThemeColor, MindSoftThemeColor, MindStarryThemeColor, MindThemeColor, MindThemeColors, MindTransforms, 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, getFillByElement, getFirstLevelElement, getHitAbstractHandle, getImageForeignRectangle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNextBranchColor, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getShapeByElement, getStrokeByMindElement, getStrokeWidthByElement, getTopicRectangleByElement, getTopicRectangleByNode, getValidAbstractRefs, handleTouchedAbstract, hasAfterDraw, hasPreviousOrNextOfDropPath, insertElementHandleAbstract, insertElementHandleRightNodeCount, insertMindElement, isChildElement, isChildOfAbstract, isChildRight, isChildUp, isCorrectLayout, isDragging, isDropStandardRight, isHitEmojis, isHitImage, isHitMindElement, isInRightBranchOfStandardLayout, isMixedLayout, isSetAbstract, isValidTarget, isVirtualKey, removeActiveOnDragOrigin, separateChildren, setIsDragging, withMind, withMindExtend };
4042
4053
  //# sourceMappingURL=plait-mind.mjs.map