@plait/mind 0.13.0 → 0.14.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.
@@ -3,7 +3,7 @@ import { Component, ChangeDetectionStrategy, NgModule, NgZone, Directive, Input,
3
3
  import * as i2 from '@plait/core';
4
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
5
  import { MindLayoutType, isIndentedLayout, getNonAbstractChildren, isStandardLayout, AbstractNode, isLeftLayout, isRightLayout, isVerticalLogicLayout, isHorizontalLogicLayout, isTopLayout, isBottomLayout, isHorizontalLayout, getCorrectStartEnd, getAbstractLayout, ConnectingPosition, GlobalLayout } from '@plait/layouts';
6
- import { getTextSize, TEXT_DEFAULT_HEIGHT, TextManage, TextModule } from '@plait/text';
6
+ import { TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, 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';
@@ -336,54 +336,12 @@ const ROOT_TOPIC_FONT_SIZE = 18;
336
336
  const ROOT_TOPIC_HEIGHT = 25;
337
337
  const TOPIC_DEFAULT_MAX_WORD_COUNT = 34;
338
338
 
339
- const adjustRootToNode = (board, node) => {
340
- const newNode = { ...node };
341
- delete newNode.isRoot;
342
- delete newNode.rightNodeCount;
343
- delete newNode.type;
344
- const text = Node.string(node.data.topic.children[0]) || ' ';
345
- const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT);
346
- newNode.width = Math.max(width, NODE_MIN_WIDTH);
347
- newNode.height = height;
348
- if (newNode.layout === MindLayoutType.standard) {
349
- delete newNode.layout;
350
- }
351
- return newNode;
352
- };
353
- const adjustAbstractToNode = (node) => {
354
- const newNode = { ...node };
355
- delete newNode.start;
356
- delete newNode.end;
357
- return newNode;
358
- };
359
- const adjustNodeToRoot = (board, node) => {
360
- const newElement = { ...node };
361
- let text = Node.string(newElement.data.topic);
362
- if (!text) {
363
- text = '思维导图';
364
- newElement.data.topic = { children: [{ text }] };
365
- }
366
- delete newElement?.strokeColor;
367
- delete newElement?.fill;
368
- delete newElement?.shape;
369
- delete newElement?.strokeWidth;
370
- const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, ROOT_TOPIC_FONT_SIZE);
371
- newElement.width = Math.max(width, NODE_MIN_WIDTH);
372
- newElement.height = height;
373
- return {
374
- ...newElement,
375
- layout: newElement.layout ?? MindLayoutType.right,
376
- isCollapsed: false,
377
- isRoot: true,
378
- type: 'mindmap'
379
- };
380
- };
381
-
382
- const createEmptyMind = (board, point) => {
383
- const element = createMindElement('', 0, 0, { layout: MindLayoutType.right });
384
- const rootElement = adjustNodeToRoot(board, element);
385
- rootElement.points = [point];
386
- return rootElement;
339
+ const createEmptyMind = (point) => {
340
+ const element = createMindElement('思维导图', 72, ROOT_TOPIC_HEIGHT, { layout: MindLayoutType.right });
341
+ element.isRoot = true;
342
+ element.points = [point];
343
+ element.type = 'mindmap';
344
+ return element;
387
345
  };
388
346
  const createDefaultMind = (point, rightNodeCount, layout) => {
389
347
  const root = createMindElement('思维导图', 72, ROOT_TOPIC_HEIGHT, { layout });
@@ -401,7 +359,7 @@ const createMindElement = (text, width, height, options) => {
401
359
  const newElement = {
402
360
  id: idCreator(),
403
361
  data: {
404
- topic: { children: [{ text }] }
362
+ topic: buildText(text)
405
363
  },
406
364
  children: [],
407
365
  width,
@@ -622,6 +580,50 @@ const getRootLayout = (root) => {
622
580
  return root.layout || getDefaultLayout();
623
581
  };
624
582
 
583
+ const adjustRootToNode = (board, node) => {
584
+ const newNode = { ...node };
585
+ delete newNode.isRoot;
586
+ delete newNode.rightNodeCount;
587
+ delete newNode.type;
588
+ const text = Node.string(node.data.topic.children[0]) || ' ';
589
+ const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT);
590
+ newNode.width = Math.max(width, NODE_MIN_WIDTH);
591
+ newNode.height = height;
592
+ if (newNode.layout === MindLayoutType.standard) {
593
+ delete newNode.layout;
594
+ }
595
+ return newNode;
596
+ };
597
+ const adjustAbstractToNode = (node) => {
598
+ const newNode = { ...node };
599
+ delete newNode.start;
600
+ delete newNode.end;
601
+ return newNode;
602
+ };
603
+ const adjustNodeToRoot = (board, node) => {
604
+ const newElement = { ...node };
605
+ if (!Node.string(newElement.data.topic)) {
606
+ newElement.data.topic = { children: [{ text: '思维导图' }] };
607
+ }
608
+ delete newElement?.strokeColor;
609
+ delete newElement?.fill;
610
+ delete newElement?.shape;
611
+ delete newElement?.strokeWidth;
612
+ delete newElement?.isCollapsed;
613
+ const { width, height } = getTextSize(board, newElement.data.topic, TOPIC_DEFAULT_MAX_WORD_COUNT, {
614
+ fontSize: ROOT_TOPIC_FONT_SIZE,
615
+ fontFamily: 'PingFangSC-Medium, "PingFang SC"'
616
+ });
617
+ newElement.width = Math.max(width, NODE_MIN_WIDTH);
618
+ newElement.height = height;
619
+ return {
620
+ ...newElement,
621
+ layout: newElement.layout ?? MindLayoutType.right,
622
+ isRoot: true,
623
+ type: 'mindmap'
624
+ };
625
+ };
626
+
625
627
  const DefaultAbstractNodeStyle = {
626
628
  strokeColor: GRAY_COLOR,
627
629
  strokeWidth: 2,
@@ -1923,8 +1925,16 @@ const MindElement = {
1923
1925
  getEmojis(element) {
1924
1926
  return element.data.emojis;
1925
1927
  },
1926
- getEditor(element) {
1927
- return PlaitElement.getComponent(element).textManage.componentRef.instance.editor;
1928
+ hasMounted(element) {
1929
+ const component = PlaitElement.getComponent(element);
1930
+ return !!component;
1931
+ },
1932
+ getTextEditor(element) {
1933
+ const component = PlaitElement.getComponent(element);
1934
+ if (component) {
1935
+ return component.textManage.componentRef.instance.editor;
1936
+ }
1937
+ throw new Error('can not get correctly component in get text editor');
1928
1938
  }
1929
1939
  };
1930
1940
  var MindElementShape;
@@ -3039,9 +3049,6 @@ const withNodeDnd = (board) => {
3039
3049
  if (AbstractNode.isAbstract(element)) {
3040
3050
  return adjustAbstractToNode(element);
3041
3051
  }
3042
- if (PlaitMind.isMind(element)) {
3043
- return adjustRootToNode(board, element);
3044
- }
3045
3052
  return element;
3046
3053
  });
3047
3054
  const hasPreviousNode = targetPath[targetPath.length - 1] !== 0;
@@ -3357,7 +3364,7 @@ const withCreateMind = (board) => {
3357
3364
  const movingPoint = PlaitBoard.getMovingPoint(board);
3358
3365
  if (movingPoint) {
3359
3366
  const targetPoint = transformPoint(board, toPoint(movingPoint[0], movingPoint[1], PlaitBoard.getHost(board)));
3360
- const emptyMind = createEmptyMind(board, targetPoint);
3367
+ const emptyMind = createEmptyMind(targetPoint);
3361
3368
  const nodeRectangle = getRectangleByElement(newBoard, targetPoint, emptyMind);
3362
3369
  const nodeG = drawRoundRectangleByElement(board, nodeRectangle, emptyMind);
3363
3370
  const topicRectangle = getTopicRectangleByElement(newBoard, nodeRectangle, emptyMind);
@@ -3376,6 +3383,7 @@ const withCreateMind = (board) => {
3376
3383
  textManage
3377
3384
  };
3378
3385
  fakeCreateNodeRef.g.classList.add('root');
3386
+ fakeCreateNodeRef.g.setAttribute('plait-mind-temporary', 'true');
3379
3387
  PlaitBoard.getHost(board).append(fakeCreateNodeRef.g);
3380
3388
  fakeCreateNodeRef.g.append(...[fakeCreateNodeRef.nodeG, textManage.g]);
3381
3389
  }
@@ -3398,7 +3406,7 @@ const withCreateMind = (board) => {
3398
3406
  const movingPoint = PlaitBoard.getMovingPoint(board);
3399
3407
  if (movingPoint && fakeCreateNodeRef && PlaitBoard.isPointer(board, MindPointerType.mind)) {
3400
3408
  const targetPoint = transformPoint(board, toPoint(movingPoint[0], movingPoint[1], PlaitBoard.getHost(board)));
3401
- const emptyMind = createEmptyMind(board, targetPoint);
3409
+ const emptyMind = createEmptyMind(targetPoint);
3402
3410
  Transforms.insertNode(board, emptyMind, [board.children.length]);
3403
3411
  clearSelectedElement(board);
3404
3412
  addSelectedElement(board, emptyMind);
@@ -3690,11 +3698,13 @@ const withMind = (board) => {
3690
3698
  insertClipboardData(board, elements, targetPoint || [0, 0]);
3691
3699
  }
3692
3700
  else {
3693
- const text = data?.getData(`text/plain`);
3694
- const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT);
3701
+ const text = getTextFromClipboard(data);
3702
+ const { width, height } = getTextSize(board, text, TOPIC_DEFAULT_MAX_WORD_COUNT, {
3703
+ fontFamily: 'PingFangSC-Regular, "PingFang SC"'
3704
+ });
3695
3705
  const selectedElements = getSelectedElements(board);
3696
3706
  if (text && selectedElements.length === 1) {
3697
- insertClipboardText(board, selectedElements[0], text, width, height);
3707
+ insertClipboardText(board, selectedElements[0], buildText(text), width, height);
3698
3708
  }
3699
3709
  }
3700
3710
  insertFragment(data, targetPoint);