@plait/mind 0.54.0 → 0.55.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.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Component, ChangeDetectionStrategy, NgZone, Directive, Input, HostListener } from '@angular/core';
3
- import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, PlaitElement, PlaitNode, Path, isNullOrUndefined, PlaitBoard, getSelectedElements, idCreator, Transforms, clearSelectedElement, addSelectedElement, distanceBetweenPointAndRectangle, RectangleClient, depthFirstRecursion, getIsRecursionFunc, drawRoundRectangle, drawLinearPath, drawBezierPath, createG, updateForeignObject, getRectangleByElements, NODE_TO_PARENT, createForeignObject, removeSelectedElement, PlaitHistoryBoard, setStrokeLinecap, ACTIVE_STROKE_WIDTH, createText, PlaitPointerType, NODE_TO_INDEX, PlaitChildrenElementComponent, isMainPointer, toViewBoxPoint, toHostPoint, getHitElementByPoint, distanceBetweenPointAndPoint, CoreTransforms, BOARD_TO_HOST, BoardTransforms, throttleRAF, isContextmenu, temporaryDisableSelection, hotkeys, createClipboardContext, WritableClipboardType, ResizeCursorClass, Point, addClipboardContext, PlaitPluginKey } from '@plait/core';
3
+ import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, PlaitElement, PlaitNode, Path, isNullOrUndefined, PlaitBoard, getSelectedElements, idCreator, Transforms, clearSelectedElement, addSelectedElement, distanceBetweenPointAndRectangle, RectangleClient, depthFirstRecursion, getIsRecursionFunc, drawRoundRectangle, drawLinearPath, drawBezierPath, createG, updateForeignObject, getRectangleByElements, NODE_TO_PARENT, createForeignObject, removeSelectedElement, PlaitHistoryBoard, setStrokeLinecap, ACTIVE_STROKE_WIDTH, createText, PlaitPointerType, NODE_TO_INDEX, isMainPointer, toViewBoxPoint, toHostPoint, getHitElementByPoint, distanceBetweenPointAndPoint, CoreTransforms, BOARD_TO_HOST, BoardTransforms, throttleRAF, isContextmenu, temporaryDisableSelection, hotkeys, createClipboardContext, WritableClipboardType, ResizeCursorClass, Point, addClipboardContext, PlaitPluginKey } from '@plait/core';
4
4
  import { MindLayoutType, AbstractNode, isIndentedLayout, isHorizontalLayout, isHorizontalLogicLayout, ConnectingPosition, getNonAbstractChildren, isStandardLayout, isLeftLayout, isRightLayout, isVerticalLogicLayout, isTopLayout, isBottomLayout, getCorrectStartEnd, getAbstractLayout, GlobalLayout } from '@plait/layouts';
5
5
  import { TEXT_DEFAULT_HEIGHT, buildText, PlaitMarkEditor, MarkTypes, DEFAULT_FONT_SIZE, getTextSize, TextManage, ExitOrigin } from '@plait/text';
6
6
  import { fromEvent, Subject } from 'rxjs';
@@ -8,7 +8,6 @@ import { getFirstTextEditor, RESIZE_HANDLE_DIAMETER, getRectangleResizeHandleRef
8
8
  import { Node as Node$1, Path as Path$1 } from 'slate';
9
9
  import { pointsOnBezierCurves } from 'points-on-curve';
10
10
  import { take, filter } from 'rxjs/operators';
11
- import { NgIf } from '@angular/common';
12
11
 
13
12
  const ELEMENT_TO_NODE = new WeakMap();
14
13
 
@@ -1113,16 +1112,14 @@ const getNewNodeHeight = (board, element, newNodeDynamicWidth) => {
1113
1112
 
1114
1113
  const IS_DRAGGING = new WeakMap();
1115
1114
  const addActiveOnDragOrigin = (activeElement) => {
1116
- const activeComponent = PlaitElement.getComponent(activeElement);
1117
- activeComponent.g.classList.add('dragging-node');
1115
+ PlaitElement.getElementG(activeElement).classList.add('dragging-node');
1118
1116
  !activeElement.isCollapsed &&
1119
1117
  activeElement.children.forEach(child => {
1120
1118
  addActiveOnDragOrigin(child);
1121
1119
  });
1122
1120
  };
1123
1121
  const removeActiveOnDragOrigin = (activeElement) => {
1124
- const activeComponent = PlaitElement.getComponent(activeElement);
1125
- activeComponent.g.classList.remove('dragging-node');
1122
+ PlaitElement.getElementG(activeElement).classList.remove('dragging-node');
1126
1123
  !activeElement.isCollapsed &&
1127
1124
  activeElement.children.forEach(child => {
1128
1125
  removeActiveOnDragOrigin(child);
@@ -2931,9 +2928,8 @@ class MindNodeComponent extends CommonPluginElement {
2931
2928
  get textManage() {
2932
2929
  return this.getTextManages()[0];
2933
2930
  }
2934
- constructor(viewContainerRef, cdr) {
2931
+ constructor(cdr) {
2935
2932
  super(cdr);
2936
- this.viewContainerRef = viewContainerRef;
2937
2933
  this.cdr = cdr;
2938
2934
  this.shapeG = null;
2939
2935
  this.destroy$ = new Subject();
@@ -2989,8 +2985,7 @@ class MindNodeComponent extends CommonPluginElement {
2989
2985
  this.node = MindElement.getNode(this.element);
2990
2986
  this.index = NODE_TO_INDEX.get(this.element) || 0;
2991
2987
  this.roughSVG = PlaitBoard.getRoughSVG(this.board);
2992
- this.parentG = PlaitElement.getComponent(MindElement.getRoot(this.board, this.element)).rootG;
2993
- this.nodeShapeGenerator.processDrawing(this.element, this.g, { node: this.node });
2988
+ this.nodeShapeGenerator.processDrawing(this.element, this.getElementG(), { node: this.node });
2994
2989
  this.drawLink();
2995
2990
  this.drawTopic();
2996
2991
  this.activeGenerator.processDrawing(this.element, PlaitBoard.getElementActiveHost(this.board), {
@@ -2999,9 +2994,9 @@ class MindNodeComponent extends CommonPluginElement {
2999
2994
  });
3000
2995
  this.drawEmojis();
3001
2996
  this.drawExtend();
3002
- this.imageGenerator.processDrawing(this.element, this.g, this.viewContainerRef);
2997
+ this.imageGenerator.processDrawing(this.element, this.getElementG(), this.viewContainerRef);
3003
2998
  if (PlaitMind.isMind(this.context.parent)) {
3004
- this.g.classList.add('branch');
2999
+ this.getElementG().classList.add('branch');
3005
3000
  }
3006
3001
  }
3007
3002
  onContextChanged(value, previous) {
@@ -3014,15 +3009,15 @@ class MindNodeComponent extends CommonPluginElement {
3014
3009
  selected: this.selected,
3015
3010
  isEditing: this.textManage.isEditing
3016
3011
  });
3017
- this.nodeShapeGenerator.processDrawing(this.element, this.g, { node: this.node });
3012
+ this.nodeShapeGenerator.processDrawing(this.element, this.getElementG(), { node: this.node });
3018
3013
  this.drawLink();
3019
3014
  this.drawEmojis();
3020
3015
  this.drawExtend();
3021
3016
  if (!MindElement.hasImage(previous.element) && MindElement.hasImage(this.element)) {
3022
- this.imageGenerator.processDrawing(this.element, this.g, this.viewContainerRef);
3017
+ this.imageGenerator.processDrawing(this.element, this.getElementG(), this.viewContainerRef);
3023
3018
  }
3024
3019
  if (MindElement.hasImage(previous.element) && MindElement.hasImage(this.element)) {
3025
- this.imageGenerator.updateImage(this.g, previous.element, value.element);
3020
+ this.imageGenerator.updateImage(this.getElementG(), previous.element, value.element);
3026
3021
  }
3027
3022
  if (MindElement.hasImage(previous.element) && !MindElement.hasImage(this.element)) {
3028
3023
  this.imageGenerator.destroy();
@@ -3046,7 +3041,7 @@ class MindNodeComponent extends CommonPluginElement {
3046
3041
  drawEmojis() {
3047
3042
  const g = this.nodeEmojisGenerator.drawEmojis(this.element);
3048
3043
  if (g) {
3049
- this.g.append(g);
3044
+ this.getElementG().append(g);
3050
3045
  }
3051
3046
  }
3052
3047
  drawLink() {
@@ -3065,26 +3060,26 @@ class MindNodeComponent extends CommonPluginElement {
3065
3060
  else {
3066
3061
  this.linkG = drawLink(this.board, parentNode, this.node, isHorizontalLayout(layout));
3067
3062
  }
3068
- this.g.append(this.linkG);
3063
+ this.getElementG().append(this.linkG);
3069
3064
  }
3070
3065
  drawExtend() {
3071
3066
  if (!this.extendG) {
3072
3067
  this.extendG = createG();
3073
3068
  this.extendG.classList.add('extend');
3074
- this.g.append(this.extendG);
3069
+ this.getElementG().append(this.extendG);
3075
3070
  }
3076
3071
  if (this.element.isCollapsed) {
3077
- this.g.classList.add('collapsed');
3072
+ this.getElementG().classList.add('collapsed');
3078
3073
  }
3079
3074
  else {
3080
- this.g.classList.remove('collapsed');
3075
+ this.getElementG().classList.remove('collapsed');
3081
3076
  }
3082
3077
  this.nodePlusGenerator.processDrawing(this.element, this.extendG);
3083
3078
  this.collapseGenerator.processDrawing(this.element, this.extendG);
3084
3079
  }
3085
3080
  drawTopic() {
3086
3081
  this.textManage.draw(this.element.data.topic);
3087
- this.g.append(this.textManage.g);
3082
+ this.getElementG().append(this.textManage.g);
3088
3083
  }
3089
3084
  updateTopic() {
3090
3085
  this.textManage.updateText(this.element.data.topic);
@@ -3116,41 +3111,24 @@ class MindNodeComponent extends CommonPluginElement {
3116
3111
  ELEMENT_TO_NODE.delete(this.element);
3117
3112
  }
3118
3113
  }
3119
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: MindNodeComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
3120
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.4", type: MindNodeComponent, isStandalone: true, selector: "plait-mind-node", usesInheritance: true, ngImport: i0, template: `
3121
- <plait-children
3122
- *ngIf="!element.isCollapsed"
3123
- [board]="board"
3124
- [parent]="element"
3125
- [effect]="effect"
3126
- [parentG]="parentG"
3127
- ></plait-children>
3128
- `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: PlaitChildrenElementComponent, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3114
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: MindNodeComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
3115
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.4", type: MindNodeComponent, isStandalone: true, selector: "plait-mind-node", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3129
3116
  }
3130
3117
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: MindNodeComponent, decorators: [{
3131
3118
  type: Component,
3132
3119
  args: [{
3133
3120
  selector: 'plait-mind-node',
3134
- template: `
3135
- <plait-children
3136
- *ngIf="!element.isCollapsed"
3137
- [board]="board"
3138
- [parent]="element"
3139
- [effect]="effect"
3140
- [parentG]="parentG"
3141
- ></plait-children>
3142
- `,
3121
+ template: ``,
3143
3122
  changeDetection: ChangeDetectionStrategy.OnPush,
3144
- standalone: true,
3145
- imports: [NgIf, PlaitChildrenElementComponent]
3123
+ standalone: true
3146
3124
  }]
3147
- }], ctorParameters: () => [{ type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }] });
3125
+ }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }] });
3148
3126
 
3149
3127
  class PlaitMindComponent extends MindNodeComponent {
3150
3128
  ngOnInit() {
3151
3129
  this.updateMindLayout();
3152
3130
  super.ngOnInit();
3153
- this.g.classList.add('root');
3131
+ this.getElementG().classList.add('root');
3154
3132
  }
3155
3133
  beforeContextChange(value) {
3156
3134
  if (value.element !== this.element && this.initialized) {
@@ -3173,20 +3151,16 @@ class PlaitMindComponent extends MindNodeComponent {
3173
3151
  });
3174
3152
  }
3175
3153
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: PlaitMindComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
3176
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.4", type: PlaitMindComponent, isStandalone: true, selector: "plait-mind", usesInheritance: true, ngImport: i0, template: `
3177
- <plait-children [board]="board" [parent]="element" [effect]="effect" [parentG]="rootG"></plait-children>
3178
- `, isInline: true, dependencies: [{ kind: "component", type: PlaitChildrenElementComponent, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3154
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.4", type: PlaitMindComponent, isStandalone: true, selector: "plait-mind", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3179
3155
  }
3180
3156
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: PlaitMindComponent, decorators: [{
3181
3157
  type: Component,
3182
3158
  args: [{
3183
3159
  selector: 'plait-mind',
3184
- template: `
3185
- <plait-children [board]="board" [parent]="element" [effect]="effect" [parentG]="rootG"></plait-children>
3186
- `,
3160
+ template: ``,
3187
3161
  changeDetection: ChangeDetectionStrategy.OnPush,
3188
3162
  standalone: true,
3189
- imports: [PlaitChildrenElementComponent, MindNodeComponent]
3163
+ imports: [MindNodeComponent]
3190
3164
  }]
3191
3165
  }] });
3192
3166
 
@@ -3485,6 +3459,7 @@ const withCreateMind = (board) => {
3485
3459
  clearSelectedElement(board);
3486
3460
  addSelectedElement(board, emptyMind);
3487
3461
  BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
3462
+ return;
3488
3463
  }
3489
3464
  pointerDown(event);
3490
3465
  };
@@ -3656,14 +3631,10 @@ const pointerLeaveHandle = (board, event, nodeExtendHoveredRef) => {
3656
3631
  }
3657
3632
  };
3658
3633
  const addHovered = (element) => {
3659
- const component = PlaitElement.getComponent(element);
3660
- component.g.classList.add('hovered');
3634
+ PlaitElement.getElementG(element).classList.add('hovered');
3661
3635
  };
3662
3636
  const removeHovered = (element) => {
3663
- const component = PlaitElement.getComponent(element);
3664
- if (component && component.g) {
3665
- component.g.classList.remove('hovered');
3666
- }
3637
+ PlaitElement.getElementG(element)?.classList?.remove('hovered');
3667
3638
  };
3668
3639
 
3669
3640
  const withNodeHoverHitTest = (board) => {
@@ -3671,6 +3642,10 @@ const withNodeHoverHitTest = (board) => {
3671
3642
  let nodeExtendHoveredRef = null;
3672
3643
  board.pointerMove = (event) => {
3673
3644
  throttleRAF(board, 'with-mind-node-hover-hit-test', () => {
3645
+ // element has been deleted
3646
+ if (nodeExtendHoveredRef && !PlaitElement.hasMounted(nodeExtendHoveredRef.element)) {
3647
+ nodeExtendHoveredRef = null;
3648
+ }
3674
3649
  nodeExtendHoveredRef = pointerMoveHandle(board, event, nodeExtendHoveredRef);
3675
3650
  });
3676
3651
  pointerMove(event);
@@ -3684,7 +3659,7 @@ const withNodeHoverHitTest = (board) => {
3684
3659
  };
3685
3660
 
3686
3661
  const withNodeImage = (board) => {
3687
- const { keyDown, pointerUp, globalPointerUp, setFragment, insertFragment, deleteFragment } = board;
3662
+ const { keyDown, pointerUp, globalPointerUp, buildFragment, insertFragment, deleteFragment } = board;
3688
3663
  board.pointerUp = (event) => {
3689
3664
  const elementOfFocusedImage = getElementOfFocusedImage(board);
3690
3665
  if (elementOfFocusedImage &&
@@ -3735,12 +3710,12 @@ const withNodeImage = (board) => {
3735
3710
  }
3736
3711
  globalPointerUp(event);
3737
3712
  };
3738
- board.setFragment = (data, clipboardContext, rectangle, type) => {
3713
+ board.buildFragment = (clipboardContext, rectangle, type) => {
3739
3714
  const selectedImageElement = getElementOfFocusedImage(board);
3740
3715
  if (selectedImageElement) {
3741
3716
  clipboardContext = createClipboardContext(WritableClipboardType.medias, [selectedImageElement.data.image], '');
3742
3717
  }
3743
- setFragment(data, clipboardContext, rectangle, type);
3718
+ return buildFragment(clipboardContext, rectangle, type);
3744
3719
  };
3745
3720
  board.deleteFragment = (elements) => {
3746
3721
  const selectedImageElement = getElementOfFocusedImage(board);
@@ -3749,7 +3724,7 @@ const withNodeImage = (board) => {
3749
3724
  }
3750
3725
  deleteFragment(elements);
3751
3726
  };
3752
- board.insertFragment = (data, clipboardData, targetPoint) => {
3727
+ board.insertFragment = (clipboardData, targetPoint) => {
3753
3728
  const selectedElements = getSelectedElements(board);
3754
3729
  const isSelectedImage = !!getElementOfFocusedImage(board);
3755
3730
  const isSingleSelection = selectedElements.length === 1 && MindElement.isMindElement(board, selectedElements[0]);
@@ -3771,7 +3746,7 @@ const withNodeImage = (board) => {
3771
3746
  return;
3772
3747
  }
3773
3748
  }
3774
- insertFragment(data, clipboardData, targetPoint);
3749
+ insertFragment(clipboardData, targetPoint);
3775
3750
  };
3776
3751
  return board;
3777
3752
  };
@@ -3978,7 +3953,7 @@ const insertClipboardText = (board, targetParent, text) => {
3978
3953
  const withMindFragment = (baseBoard) => {
3979
3954
  const board = baseBoard;
3980
3955
  let firstLevelElements;
3981
- const { getDeletedFragment, insertFragment, setFragment, deleteFragment } = board;
3956
+ const { getDeletedFragment, insertFragment, buildFragment, deleteFragment } = board;
3982
3957
  board.getDeletedFragment = (data) => {
3983
3958
  const targetMindElements = getSelectedMindElements(board);
3984
3959
  if (targetMindElements.length) {
@@ -4002,7 +3977,7 @@ const withMindFragment = (baseBoard) => {
4002
3977
  firstLevelElements = null;
4003
3978
  }
4004
3979
  };
4005
- board.setFragment = (data, clipboardContext, rectangle, type) => {
3980
+ board.buildFragment = (clipboardContext, rectangle, type) => {
4006
3981
  const targetMindElements = getSelectedMindElements(board);
4007
3982
  const firstLevelElements = getFirstLevelElement(targetMindElements);
4008
3983
  if (firstLevelElements.length) {
@@ -4015,13 +3990,13 @@ const withMindFragment = (baseBoard) => {
4015
3990
  clipboardContext = addClipboardContext(clipboardContext, {
4016
3991
  text,
4017
3992
  type: WritableClipboardType.elements,
4018
- data: elements
3993
+ elements
4019
3994
  });
4020
3995
  }
4021
3996
  }
4022
- setFragment(data, clipboardContext, rectangle, type);
3997
+ return buildFragment(clipboardContext, rectangle, type);
4023
3998
  };
4024
- board.insertFragment = (data, clipboardData, targetPoint) => {
3999
+ board.insertFragment = (clipboardData, targetPoint) => {
4025
4000
  if (clipboardData?.elements?.length) {
4026
4001
  const mindElements = clipboardData.elements?.filter(value => MindElement.isMindElement(board, value));
4027
4002
  if (mindElements && mindElements.length > 0) {
@@ -4035,7 +4010,7 @@ const withMindFragment = (baseBoard) => {
4035
4010
  return;
4036
4011
  }
4037
4012
  }
4038
- insertFragment(data, clipboardData, targetPoint);
4013
+ insertFragment(clipboardData, targetPoint);
4039
4014
  };
4040
4015
  return board;
4041
4016
  };
@@ -4072,7 +4047,7 @@ const getNextSelectedElement = (board, firstLevelElements) => {
4072
4047
 
4073
4048
  const withMind = (baseBoard) => {
4074
4049
  const board = baseBoard;
4075
- const { drawElement, dblClick, isRectangleHit, isHit, getRectangle, isMovable, isRecursion, isAlign, isImageBindingAllowed, canAddToGroup } = board;
4050
+ const { drawElement, dblClick, isRectangleHit, isHit, getRectangle, isMovable, isRecursion, isAlign, isImageBindingAllowed, canAddToGroup, canSetZIndex, isExpanded } = board;
4076
4051
  board.drawElement = (context) => {
4077
4052
  if (PlaitMind.isMind(context.element)) {
4078
4053
  return PlaitMindComponent;
@@ -4102,6 +4077,12 @@ const withMind = (baseBoard) => {
4102
4077
  }
4103
4078
  return canAddToGroup(element);
4104
4079
  };
4080
+ board.canSetZIndex = (element) => {
4081
+ if (MindElement.isMindElement(board, element) && !element.isRoot) {
4082
+ return false;
4083
+ }
4084
+ return canSetZIndex(element);
4085
+ };
4105
4086
  board.isRecursion = element => {
4106
4087
  if (MindElement.isMindElement(board, element) && element.isCollapsed) {
4107
4088
  return false;
@@ -4142,6 +4123,12 @@ const withMind = (baseBoard) => {
4142
4123
  }
4143
4124
  return isAlign(element);
4144
4125
  };
4126
+ board.isExpanded = (element) => {
4127
+ if (MindElement.isMindElement(board, element) && !PlaitMind.isMind(element)) {
4128
+ return !element.isCollapsed;
4129
+ }
4130
+ return isExpanded(element);
4131
+ };
4145
4132
  board.dblClick = (event) => {
4146
4133
  if (PlaitBoard.isReadonly(board)) {
4147
4134
  dblClick(event);