@plait/mind 0.27.0-next.9 → 0.29.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.
Files changed (52) hide show
  1. package/base/index.d.ts +0 -1
  2. package/constants/default.d.ts +1 -0
  3. package/esm2022/base/emoji-base.component.mjs +4 -4
  4. package/esm2022/base/index.mjs +1 -2
  5. package/esm2022/constants/abstract-node.mjs +1 -1
  6. package/esm2022/constants/default.mjs +2 -1
  7. package/esm2022/constants/index.mjs +1 -1
  8. package/esm2022/constants/node-topic-style.mjs +2 -2
  9. package/esm2022/interfaces/element-data.mjs +1 -1
  10. package/esm2022/interfaces/index.mjs +1 -1
  11. package/esm2022/interfaces/options.mjs +1 -1
  12. package/esm2022/interfaces/theme-color.mjs +1 -1
  13. package/esm2022/mind-node.component.mjs +31 -15
  14. package/esm2022/mind.component.mjs +9 -8
  15. package/esm2022/plugins/with-abstract-resize.mjs +2 -2
  16. package/esm2022/plugins/with-mind-fragment.mjs +1 -1
  17. package/esm2022/plugins/with-mind.mjs +8 -2
  18. package/esm2022/plugins/with-node-dnd.mjs +5 -6
  19. package/esm2022/plugins/with-node-image.mjs +8 -6
  20. package/esm2022/plugins/with-node-resize.mjs +1 -1
  21. package/esm2022/public-api.mjs +1 -2
  22. package/esm2022/transforms/image.mjs +1 -1
  23. package/esm2022/transforms/index.mjs +1 -1
  24. package/esm2022/utils/abstract/common.mjs +2 -2
  25. package/esm2022/utils/clipboard.mjs +1 -1
  26. package/esm2022/utils/draw/abstract-outline.mjs +1 -1
  27. package/esm2022/utils/draw/node-dnd.mjs +2 -2
  28. package/esm2022/utils/node/create-node.mjs +1 -1
  29. package/esm2022/utils/node/image.mjs +4 -44
  30. package/esm2022/utils/space/index.mjs +1 -1
  31. package/esm2022/utils/space/layout-options.mjs +6 -6
  32. package/fesm2022/plait-mind.mjs +355 -511
  33. package/fesm2022/plait-mind.mjs.map +1 -1
  34. package/interfaces/element-data.d.ts +3 -7
  35. package/interfaces/options.d.ts +2 -2
  36. package/mind-node.component.d.ts +4 -4
  37. package/mind.component.d.ts +1 -1
  38. package/package.json +1 -1
  39. package/public-api.d.ts +0 -1
  40. package/transforms/image.d.ts +3 -2
  41. package/transforms/index.d.ts +1 -1
  42. package/utils/node/create-node.d.ts +3 -3
  43. package/utils/node/image.d.ts +0 -2
  44. package/utils/space/layout-options.d.ts +2 -2
  45. package/base/image-base.component.d.ts +0 -28
  46. package/constants/image.d.ts +0 -3
  47. package/drawer/node-image.drawer.d.ts +0 -15
  48. package/esm2022/base/image-base.component.mjs +0 -75
  49. package/esm2022/constants/image.mjs +0 -4
  50. package/esm2022/drawer/node-image.drawer.mjs +0 -59
  51. package/esm2022/mind.module.mjs +0 -21
  52. package/mind.module.d.ts +0 -11
@@ -1,16 +1,14 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Component, ChangeDetectionStrategy, NgModule, NgZone, Directive, Input, HostListener } from '@angular/core';
3
- import * as i2 from '@plait/core';
4
- import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, PlaitElement, PlaitNode, Path, isNullOrUndefined, PlaitBoard, distanceBetweenPointAndRectangle, RectangleClient, PlaitPluginKey, getSelectedElements, idCreator, Transforms, clearSelectedElement, addSelectedElement, PlaitContextService, depthFirstRecursion, getIsRecursionFunc, drawRoundRectangle, drawLinearPath, drawBezierPath, createG, updateForeignObject, getRectangleByElements, NODE_TO_PARENT, createForeignObject, setStrokeLinecap, ACTIVE_STROKE_WIDTH, createText, PlaitPointerType, NODE_TO_INDEX, PlaitModule, isMainPointer, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CoreTransforms, BOARD_TO_HOST, BoardTransforms, throttleRAF, removeSelectedElement, PlaitHistoryBoard, hotkeys, setClipboardDataByMedia, getClipboardDataByMedia, ResizeCursorClass, preventTouchMove, PRESS_AND_MOVE_BUFFER, MERGING, setClipboardData, setClipboardDataByText, getDataFromClipboard } from '@plait/core';
5
- import { MindLayoutType, AbstractNode, isIndentedLayout, isHorizontalLayout, isHorizontalLogicLayout, ConnectingPosition, isStandardLayout, isVerticalLogicLayout, getNonAbstractChildren, isLeftLayout, isRightLayout, isTopLayout, isBottomLayout, getCorrectStartEnd, getAbstractLayout, GlobalLayout } from '@plait/layouts';
6
- import { PlaitMarkEditor, MarkTypes, DEFAULT_FONT_SIZE, TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, ExitOrigin, TextModule, getTextFromClipboard } from '@plait/text';
2
+ import { Component, ChangeDetectionStrategy, NgZone, Directive, Input, HostListener } from '@angular/core';
3
+ import { DefaultThemeColor, ColorfulThemeColor, SoftThemeColor, RetroThemeColor, DarkThemeColor, StarryThemeColor, PlaitElement, PlaitNode, Path, isNullOrUndefined, PlaitBoard, distanceBetweenPointAndRectangle, RectangleClient, PlaitPluginKey, getSelectedElements, idCreator, Transforms, clearSelectedElement, addSelectedElement, depthFirstRecursion, getIsRecursionFunc, drawRoundRectangle, drawLinearPath, drawBezierPath, createG, updateForeignObject, getRectangleByElements, NODE_TO_PARENT, createForeignObject, setStrokeLinecap, ACTIVE_STROKE_WIDTH, createText, PlaitPointerType, NODE_TO_INDEX, PlaitChildrenElementComponent, isMainPointer, transformPoint, toPoint, getHitElements, distanceBetweenPointAndPoint, CoreTransforms, BOARD_TO_HOST, BoardTransforms, throttleRAF, removeSelectedElement, PlaitHistoryBoard, hotkeys, setClipboardDataByMedia, getClipboardDataByMedia, ResizeCursorClass, preventTouchMove, PRESS_AND_MOVE_BUFFER, MERGING, setClipboardData, setClipboardDataByText, getDataFromClipboard } from '@plait/core';
4
+ import { MindLayoutType, AbstractNode, isIndentedLayout, isHorizontalLayout, isHorizontalLogicLayout, ConnectingPosition, getNonAbstractChildren, isStandardLayout, isLeftLayout, isRightLayout, isVerticalLogicLayout, isTopLayout, isBottomLayout, getCorrectStartEnd, getAbstractLayout, GlobalLayout } from '@plait/layouts';
5
+ import { PlaitMarkEditor, MarkTypes, DEFAULT_FONT_SIZE, TEXT_DEFAULT_HEIGHT, buildText, getTextSize, TextManage, ExitOrigin, getTextFromClipboard } from '@plait/text';
7
6
  import { fromEvent, Subject } from 'rxjs';
8
- import { RESIZE_HANDLE_DIAMETER, getRectangleResizeHandleRefs, Generator, CommonPluginElement, WithTextPluginKey, isDrawingMode, isDndMode, setCreationMode, BoardCreationMode, isExpandHotkey, isTabHotkey, isEnterHotkey, isVirtualKey, isDelete, isSpaceHotkey, MediaKeys, ResizeHandle, withResize, ActiveGenerator } from '@plait/common';
7
+ import { RESIZE_HANDLE_DIAMETER, getRectangleResizeHandleRefs, Generator, CommonPluginElement, ImageGenerator, WithTextPluginKey, isDrawingMode, isDndMode, setCreationMode, BoardCreationMode, isExpandHotkey, isTabHotkey, isEnterHotkey, isVirtualKey, isDelete, isSpaceHotkey, MediaKeys, acceptImageTypes, buildImage, ResizeHandle, withResize } from '@plait/common';
9
8
  import { Node as Node$1, Path as Path$1 } from 'slate';
10
9
  import { pointsOnBezierCurves } from 'points-on-curve';
11
10
  import { take, filter } from 'rxjs/operators';
12
- import * as i1 from '@angular/common';
13
- import { CommonModule } from '@angular/common';
11
+ import { NgIf } from '@angular/common';
14
12
 
15
13
  const ELEMENT_TO_NODE = new WeakMap();
16
14
 
@@ -191,6 +189,7 @@ const EXTEND_DIAMETER = 16;
191
189
  const QUICK_INSERT_CIRCLE_OFFSET = 9;
192
190
  const QUICK_INSERT_CIRCLE_COLOR = '#6698FF';
193
191
  const QUICK_INSERT_INNER_CROSS_COLOR = 'white';
192
+ const DEFAULT_MIND_IMAGE_WIDTH = 240;
194
193
 
195
194
  function getEmojisWidthHeight(board, element) {
196
195
  const options = board.getPluginOptions(WithMindPluginKey);
@@ -219,7 +218,7 @@ const TOPIC_DEFAULT_MAX_WORD_COUNT = 34;
219
218
  const DEFAULT_FONT_FAMILY = 'PingFangSC-Regular, "PingFang SC"';
220
219
  const BRANCH_FONT_FAMILY = 'PingFangSC-Medium, "PingFang SC"';
221
220
  const NodeTopicThreshold = {
222
- defaultTextMaxWidth: 34 * 14,
221
+ defaultTextMaxWidth: 34 * 14
223
222
  };
224
223
 
225
224
  const getAvailableProperty = (board, element, propertyKey) => {
@@ -408,7 +407,7 @@ const deleteElementHandleAbstract = (board, deletableElements, effectedAbstracts
408
407
  };
409
408
  const isChildOfAbstract = (board, element) => {
410
409
  const ancestors = MindElement.getAncestors(board, element);
411
- return !!ancestors.find((value) => AbstractNode.isAbstract(value));
410
+ return !!ancestors.find(value => AbstractNode.isAbstract(value));
412
411
  };
413
412
 
414
413
  /**
@@ -1096,193 +1095,26 @@ const adjustNodeToRoot = (board, node) => {
1096
1095
  };
1097
1096
  };
1098
1097
 
1099
- const setAbstractsByRefs = (board, abstractRefs) => {
1100
- abstractRefs.forEach((newProperty, element) => {
1101
- const start = element.start + newProperty.start;
1102
- const end = element.end + newProperty.end;
1103
- const path = PlaitBoard.findPath(board, element);
1104
- if (start > end) {
1105
- Transforms.removeNode(board, path);
1106
- }
1107
- else {
1108
- Transforms.setNode(board, { start, end }, path);
1109
- }
1110
- });
1098
+ const BOARD_TO_SELECTED_IMAGE_ELEMENT = new WeakMap();
1099
+ const getSelectedImageElement = (board) => {
1100
+ return BOARD_TO_SELECTED_IMAGE_ELEMENT.get(board);
1111
1101
  };
1112
- const setAbstractByStandardLayout = (board, element) => {
1113
- const rightNodeCount = element.rightNodeCount;
1114
- const abstract = element.children.find(child => {
1115
- return AbstractNode.isAbstract(child) && child.end >= rightNodeCount && child.start < rightNodeCount;
1116
- });
1117
- if (abstract) {
1118
- const path = PlaitBoard.findPath(board, abstract);
1119
- Transforms.setNode(board, { end: rightNodeCount - 1 }, path);
1120
- }
1102
+ const addSelectedImageElement = (board, element) => {
1103
+ BOARD_TO_SELECTED_IMAGE_ELEMENT.set(board, element);
1121
1104
  };
1122
- const insertAbstract = (board, elements) => {
1123
- let elementGroup = getFirstLevelElement(elements);
1124
- const { parentElements, abstractIncludedGroups } = divideElementByParent(elementGroup);
1125
- abstractIncludedGroups.forEach((group, index) => {
1126
- const groupParent = parentElements[index];
1127
- setAbstractByElements(board, groupParent, group);
1128
- });
1105
+ const removeSelectedImageElement = (board) => {
1106
+ BOARD_TO_SELECTED_IMAGE_ELEMENT.delete(board);
1129
1107
  };
1130
- const setAbstractByElements = (board, groupParent, group) => {
1131
- const indexArray = group.map(child => groupParent.children.indexOf(child)).sort((a, b) => a - b);
1132
- const rightNodeCount = groupParent?.rightNodeCount;
1133
- const start = indexArray[0], end = indexArray[indexArray.length - 1];
1134
- if (isStandardLayout(MindQueries.getLayoutByElement(groupParent)) &&
1135
- rightNodeCount &&
1136
- start < rightNodeCount &&
1137
- end >= rightNodeCount) {
1138
- const childrenLength = groupParent.children.length;
1139
- const path = [...PlaitBoard.findPath(board, groupParent), childrenLength];
1140
- const leftChildren = indexArray.filter(index => index >= rightNodeCount);
1141
- const rightChildren = indexArray.filter(index => index < rightNodeCount);
1142
- insertAbstractNode(board, path, rightChildren[0], rightChildren[rightChildren.length - 1]);
1143
- insertAbstractNode(board, Path.next(path), leftChildren[0], leftChildren[leftChildren.length - 1]);
1108
+ const setImageFocus = (board, element, isFocus) => {
1109
+ if (isFocus) {
1110
+ addSelectedImageElement(board, element);
1144
1111
  }
1145
1112
  else {
1146
- const path = [...PlaitBoard.findPath(board, groupParent), groupParent.children.length];
1147
- insertAbstractNode(board, path, start, end);
1148
- }
1149
- };
1150
- const insertAbstractNode = (board, path, start, end) => {
1151
- const mindElement = createMindElement('概要', 28, 20, {
1152
- strokeWidth: DefaultAbstractNodeStyle.branch.width,
1153
- branchWidth: DefaultAbstractNodeStyle.branch.width
1154
- });
1155
- mindElement.start = start;
1156
- mindElement.end = end;
1157
- Transforms.insertNode(board, mindElement, path);
1158
- clearSelectedElement(board);
1159
- addSelectedElement(board, mindElement);
1160
- };
1161
-
1162
- const setLayout = (board, layout, path) => {
1163
- correctLogicLayoutNode(board, layout, path);
1164
- const element = PlaitNode.get(board, path);
1165
- if (PlaitMind.isMind(element) && isStandardLayout(layout)) {
1166
- MindTransforms.setAbstractByStandardLayout(board, element);
1167
- }
1168
- Transforms.setNode(board, { layout }, path);
1169
- };
1170
- const correctLogicLayoutNode = (board, layout, path) => {
1171
- const node = PlaitNode.get(board, path);
1172
- if (node && layout) {
1173
- node.children?.forEach((value, index) => {
1174
- if (value.layout) {
1175
- if ((isHorizontalLogicLayout(layout) && isVerticalLogicLayout(value.layout)) ||
1176
- (isVerticalLogicLayout(layout) && isHorizontalLogicLayout(value.layout))) {
1177
- Transforms.setNode(board, { layout: null }, [...path, index]);
1178
- }
1179
- if (value.children?.length) {
1180
- correctLogicLayoutNode(board, layout, [...path, index]);
1181
- }
1182
- }
1183
- });
1184
- }
1185
- };
1186
-
1187
- const normalizeWidthAndHeight = (board, element, width, height) => {
1188
- const minWidth = NodeSpace.getNodeTopicMinWidth(board, element, element.isRoot);
1189
- const newWidth = width < minWidth * board.viewport.zoom ? minWidth : width / board.viewport.zoom;
1190
- const newHeight = height / board.viewport.zoom;
1191
- return { width: Math.ceil(newWidth), height: newHeight };
1192
- };
1193
- const setTopic = (board, element, topic, width, height) => {
1194
- const newElement = {
1195
- data: { ...element.data, topic },
1196
- ...normalizeWidthAndHeight(board, element, width, height)
1197
- };
1198
- const path = PlaitBoard.findPath(board, element);
1199
- Transforms.setNode(board, newElement, path);
1200
- };
1201
- const setNodeManualWidth = (board, element, width, height) => {
1202
- const path = PlaitBoard.findPath(board, element);
1203
- const { width: normalizedWidth, height: normalizedHeight } = normalizeWidthAndHeight(board, element, width, height);
1204
- const newElement = { manualWidth: normalizedWidth, height: normalizedHeight };
1205
- Transforms.setNode(board, newElement, path);
1206
- };
1207
- const setTopicSize = (board, element, width, height) => {
1208
- const newElement = {
1209
- ...normalizeWidthAndHeight(board, element, width, height)
1210
- };
1211
- let isEqualWidth = Math.ceil(element.width) === Math.ceil(newElement.width);
1212
- let isEqualHeight = Math.ceil(element.height) === Math.ceil(newElement.height);
1213
- if (element.manualWidth) {
1214
- isEqualWidth = true;
1215
- }
1216
- if (!isEqualWidth || !isEqualHeight) {
1217
- const path = PlaitBoard.findPath(board, element);
1218
- Transforms.setNode(board, newElement, path);
1219
- }
1220
- };
1221
- const insertNodes = (board, elements, path) => {
1222
- const pathRef = board.pathRef(path);
1223
- elements.forEach(element => {
1224
- if (pathRef.current) {
1225
- Transforms.insertNode(board, element, pathRef.current);
1226
- }
1227
- });
1228
- pathRef.unref();
1229
- };
1230
- const insertAbstractNodes = (board, validAbstractRefs, elements, path) => {
1231
- const parent = PlaitNode.get(board, Path$1.parent(path));
1232
- const abstractPath = [...Path$1.parent(path), parent.children?.length];
1233
- const abstracts = validAbstractRefs.map(refs => {
1234
- const { start, end } = getRelativeStartEndByAbstractRef(refs, elements);
1235
- return {
1236
- ...refs.abstract,
1237
- start: start + path[path.length - 1],
1238
- end: end + path[path.length - 1]
1239
- };
1240
- });
1241
- insertNodes(board, abstracts, abstractPath);
1242
- };
1243
- const setRightNodeCountByRefs = (board, refs) => {
1244
- refs.forEach(ref => {
1245
- Transforms.setNode(board, { rightNodeCount: ref.rightNodeCount }, ref.path);
1246
- });
1247
- };
1248
-
1249
- const addEmoji = (board, element, emojiItem) => {
1250
- const emojis = element.data.emojis || [];
1251
- const newEmojis = [...emojis];
1252
- newEmojis.push(emojiItem);
1253
- const newElement = {
1254
- data: { ...element.data, emojis: newEmojis }
1255
- };
1256
- const path = PlaitBoard.findPath(board, element);
1257
- Transforms.setNode(board, newElement, path);
1258
- };
1259
- const removeEmoji = (board, element, emojiItem) => {
1260
- const emojis = element.data.emojis.filter(value => value !== emojiItem);
1261
- const newElement = {
1262
- data: { topic: element.data.topic }
1263
- };
1264
- if (MindElement.hasImage(element)) {
1265
- newElement.data.image = element.data.image;
1266
- }
1267
- if (emojis.length > 0) {
1268
- newElement.data.emojis = emojis;
1113
+ removeSelectedImageElement(board);
1269
1114
  }
1270
- const path = PlaitBoard.findPath(board, element);
1271
- Transforms.setNode(board, newElement, path);
1272
- };
1273
- const replaceEmoji = (board, element, oldEmoji, newEmoji) => {
1274
- const newElement = {
1275
- data: { ...element.data }
1276
- };
1277
- const newEmojis = element.data.emojis.map(value => {
1278
- if (value === oldEmoji) {
1279
- return newEmoji;
1280
- }
1281
- return value;
1282
- });
1283
- newElement.data.emojis = newEmojis;
1284
- const path = PlaitBoard.findPath(board, element);
1285
- Transforms.setNode(board, newElement, path);
1115
+ const elementComponent = PlaitElement.getComponent(element);
1116
+ elementComponent.imageGenerator.componentRef.instance.isFocus = isFocus;
1117
+ elementComponent.imageGenerator.componentRef.instance.cdr.markForCheck();
1286
1118
  };
1287
1119
 
1288
1120
  /**
@@ -1303,115 +1135,6 @@ const getNewNodeHeight = (board, element, newNodeDynamicWidth) => {
1303
1135
  return undefined;
1304
1136
  };
1305
1137
 
1306
- const removeImage = (board, element) => {
1307
- setImageFocus(board, element, false);
1308
- const newElement = {
1309
- data: { ...element.data }
1310
- };
1311
- delete newElement.data.image;
1312
- const path = PlaitBoard.findPath(board, element);
1313
- const newDynamicWidth = NodeSpace.getNodeNewDynamicWidth(board, element, 0);
1314
- const newHeight = getNewNodeHeight(board, element, newDynamicWidth);
1315
- if (newHeight) {
1316
- newElement.height = newHeight / board.viewport.zoom;
1317
- }
1318
- Transforms.setNode(board, newElement, path);
1319
- };
1320
- const setImage = (board, element, imageItem) => {
1321
- const newElement = {
1322
- data: { ...element.data, image: imageItem }
1323
- };
1324
- const newDynamicWidth = NodeSpace.getNodeNewDynamicWidth(board, element, imageItem.width);
1325
- const newHeight = getNewNodeHeight(board, element, newDynamicWidth);
1326
- if (newHeight) {
1327
- newElement.height = newHeight / board.viewport.zoom;
1328
- }
1329
- const path = PlaitBoard.findPath(board, element);
1330
- Transforms.setNode(board, newElement, path);
1331
- };
1332
-
1333
- const MindTransforms = {
1334
- setLayout,
1335
- setTopic,
1336
- setTopicSize,
1337
- setNodeManualWidth,
1338
- addEmoji,
1339
- removeEmoji,
1340
- replaceEmoji,
1341
- insertAbstract,
1342
- setAbstractsByRefs,
1343
- setAbstractByStandardLayout,
1344
- insertNodes,
1345
- insertAbstractNodes,
1346
- setRightNodeCountByRefs,
1347
- removeImage,
1348
- setImage
1349
- };
1350
-
1351
- const PICTURE_ACCEPTED_UPLOAD_SIZE = 20;
1352
- const acceptImageTypes = ['png', 'jpeg', 'gif', 'bmp'];
1353
- const DEFAULT_IMAGE_WIDTH = 240;
1354
-
1355
- const BOARD_TO_SELECTED_IMAGE_ELEMENT = new WeakMap();
1356
- const getSelectedImageElement = (board) => {
1357
- return BOARD_TO_SELECTED_IMAGE_ELEMENT.get(board);
1358
- };
1359
- const addSelectedImageElement = (board, element) => {
1360
- BOARD_TO_SELECTED_IMAGE_ELEMENT.set(board, element);
1361
- };
1362
- const removeSelectedImageElement = (board) => {
1363
- BOARD_TO_SELECTED_IMAGE_ELEMENT.delete(board);
1364
- };
1365
- const setImageFocus = (board, element, isFocus) => {
1366
- if (isFocus) {
1367
- addSelectedImageElement(board, element);
1368
- }
1369
- else {
1370
- removeSelectedImageElement(board);
1371
- }
1372
- const elementComponent = PlaitElement.getComponent(element);
1373
- elementComponent.imageDrawer.componentRef.instance.isFocus = isFocus;
1374
- elementComponent.imageDrawer.componentRef.instance.cdr.markForCheck();
1375
- };
1376
- const selectImage = (board, element, acceptImageTypes = ['png', 'jpeg', 'gif', 'bmp']) => {
1377
- const inputFile = document.createElement('input');
1378
- inputFile.setAttribute('type', 'file');
1379
- const acceptImageTypesString = '.' + acceptImageTypes.join(',.');
1380
- inputFile.setAttribute('accept', acceptImageTypesString);
1381
- inputFile.onchange = (event) => {
1382
- buildImage(board, element, event.target.files[0]);
1383
- };
1384
- inputFile.click();
1385
- };
1386
- const buildImage = async (board, element, imageFile) => {
1387
- let width = 0, height = 0;
1388
- await getImageSize(imageFile).then((value) => {
1389
- width = value.width;
1390
- height = value.height;
1391
- });
1392
- let imageItem = null;
1393
- const url = URL.createObjectURL(imageFile);
1394
- const context = PlaitBoard.getComponent(board).viewContainerRef.injector.get(PlaitContextService);
1395
- context.setUploadingFile({ url, file: imageFile });
1396
- imageItem = {
1397
- url,
1398
- width,
1399
- height
1400
- };
1401
- MindTransforms.setImage(board, element, imageItem);
1402
- };
1403
- function getImageSize(file, defaultImageWidth = DEFAULT_IMAGE_WIDTH) {
1404
- return new Promise((resolve, reject) => {
1405
- const image = new Image();
1406
- image.src = URL.createObjectURL(file);
1407
- image.onload = function () {
1408
- const width = defaultImageWidth;
1409
- const height = (defaultImageWidth * image.naturalHeight) / image.naturalWidth;
1410
- resolve(image.naturalWidth > defaultImageWidth ? { width, height } : { width: image.naturalWidth, height: image.naturalHeight });
1411
- };
1412
- });
1413
- }
1414
-
1415
1138
  const IS_DRAGGING = new WeakMap();
1416
1139
  const addActiveOnDragOrigin = (activeElement) => {
1417
1140
  const activeComponent = PlaitElement.getComponent(activeElement);
@@ -1928,7 +1651,7 @@ const drawFakeDragNode = (board, element, offsetX, offsetY) => {
1928
1651
  dragFakeNodeG?.append(fakeEmojisG);
1929
1652
  }
1930
1653
  if (MindElement.hasImage(element)) {
1931
- const fakeImageG = activeComponent.imageDrawer.g.cloneNode(true);
1654
+ const fakeImageG = activeComponent.imageGenerator.g.cloneNode(true);
1932
1655
  const foreignRectangle = getImageForeignRectangle(board, element);
1933
1656
  updateForeignObject(fakeImageG, foreignRectangle.width, foreignRectangle.height, foreignRectangle.x + offsetX, foreignRectangle.y + offsetY);
1934
1657
  dragFakeNodeG?.append(fakeImageG);
@@ -2565,58 +2288,292 @@ class EmojiDrawer {
2565
2288
  this.componentRef.instance.element = element;
2566
2289
  this.componentRef.instance.fontSize = getEmojiFontSize(element);
2567
2290
  }
2568
- get nativeElement() {
2569
- if (this.componentRef) {
2570
- return this.componentRef.instance.nativeElement;
2571
- }
2572
- else {
2573
- return null;
2574
- }
2291
+ get nativeElement() {
2292
+ if (this.componentRef) {
2293
+ return this.componentRef.instance.nativeElement;
2294
+ }
2295
+ else {
2296
+ return null;
2297
+ }
2298
+ }
2299
+ destroy() {
2300
+ if (this.componentRef) {
2301
+ this.componentRef.destroy();
2302
+ this.componentRef = null;
2303
+ }
2304
+ }
2305
+ }
2306
+ class NodeEmojisDrawer {
2307
+ constructor(board, viewContainerRef) {
2308
+ this.board = board;
2309
+ this.viewContainerRef = viewContainerRef;
2310
+ this.emojiDrawers = [];
2311
+ }
2312
+ drawEmojis(element) {
2313
+ this.destroy();
2314
+ if (MindElement.hasEmojis(element)) {
2315
+ this.g = createG();
2316
+ this.g.classList.add('emojis');
2317
+ const foreignRectangle = getEmojiForeignRectangle(this.board, element);
2318
+ const foreignObject = createForeignObject(foreignRectangle.x, foreignRectangle.y, foreignRectangle.width, foreignRectangle.height);
2319
+ this.g.append(foreignObject);
2320
+ const container = document.createElement('div');
2321
+ container.classList.add('node-emojis-container');
2322
+ foreignObject.append(container);
2323
+ this.emojiDrawers = element.data.emojis.map(emojiItem => {
2324
+ const drawer = new EmojiDrawer(this.board, this.viewContainerRef);
2325
+ drawer.draw(emojiItem, element);
2326
+ return drawer;
2327
+ });
2328
+ this.emojiDrawers.forEach(drawer => {
2329
+ container.append(drawer.nativeElement);
2330
+ });
2331
+ return this.g;
2332
+ }
2333
+ return undefined;
2334
+ }
2335
+ destroy() {
2336
+ if (this.g) {
2337
+ this.g.remove();
2338
+ }
2339
+ this.emojiDrawers.forEach(drawer => drawer.destroy());
2340
+ this.emojiDrawers = [];
2341
+ }
2342
+ }
2343
+
2344
+ const setAbstractsByRefs = (board, abstractRefs) => {
2345
+ abstractRefs.forEach((newProperty, element) => {
2346
+ const start = element.start + newProperty.start;
2347
+ const end = element.end + newProperty.end;
2348
+ const path = PlaitBoard.findPath(board, element);
2349
+ if (start > end) {
2350
+ Transforms.removeNode(board, path);
2351
+ }
2352
+ else {
2353
+ Transforms.setNode(board, { start, end }, path);
2354
+ }
2355
+ });
2356
+ };
2357
+ const setAbstractByStandardLayout = (board, element) => {
2358
+ const rightNodeCount = element.rightNodeCount;
2359
+ const abstract = element.children.find(child => {
2360
+ return AbstractNode.isAbstract(child) && child.end >= rightNodeCount && child.start < rightNodeCount;
2361
+ });
2362
+ if (abstract) {
2363
+ const path = PlaitBoard.findPath(board, abstract);
2364
+ Transforms.setNode(board, { end: rightNodeCount - 1 }, path);
2365
+ }
2366
+ };
2367
+ const insertAbstract = (board, elements) => {
2368
+ let elementGroup = getFirstLevelElement(elements);
2369
+ const { parentElements, abstractIncludedGroups } = divideElementByParent(elementGroup);
2370
+ abstractIncludedGroups.forEach((group, index) => {
2371
+ const groupParent = parentElements[index];
2372
+ setAbstractByElements(board, groupParent, group);
2373
+ });
2374
+ };
2375
+ const setAbstractByElements = (board, groupParent, group) => {
2376
+ const indexArray = group.map(child => groupParent.children.indexOf(child)).sort((a, b) => a - b);
2377
+ const rightNodeCount = groupParent?.rightNodeCount;
2378
+ const start = indexArray[0], end = indexArray[indexArray.length - 1];
2379
+ if (isStandardLayout(MindQueries.getLayoutByElement(groupParent)) &&
2380
+ rightNodeCount &&
2381
+ start < rightNodeCount &&
2382
+ end >= rightNodeCount) {
2383
+ const childrenLength = groupParent.children.length;
2384
+ const path = [...PlaitBoard.findPath(board, groupParent), childrenLength];
2385
+ const leftChildren = indexArray.filter(index => index >= rightNodeCount);
2386
+ const rightChildren = indexArray.filter(index => index < rightNodeCount);
2387
+ insertAbstractNode(board, path, rightChildren[0], rightChildren[rightChildren.length - 1]);
2388
+ insertAbstractNode(board, Path.next(path), leftChildren[0], leftChildren[leftChildren.length - 1]);
2389
+ }
2390
+ else {
2391
+ const path = [...PlaitBoard.findPath(board, groupParent), groupParent.children.length];
2392
+ insertAbstractNode(board, path, start, end);
2393
+ }
2394
+ };
2395
+ const insertAbstractNode = (board, path, start, end) => {
2396
+ const mindElement = createMindElement('概要', 28, 20, {
2397
+ strokeWidth: DefaultAbstractNodeStyle.branch.width,
2398
+ branchWidth: DefaultAbstractNodeStyle.branch.width
2399
+ });
2400
+ mindElement.start = start;
2401
+ mindElement.end = end;
2402
+ Transforms.insertNode(board, mindElement, path);
2403
+ clearSelectedElement(board);
2404
+ addSelectedElement(board, mindElement);
2405
+ };
2406
+
2407
+ const setLayout = (board, layout, path) => {
2408
+ correctLogicLayoutNode(board, layout, path);
2409
+ const element = PlaitNode.get(board, path);
2410
+ if (PlaitMind.isMind(element) && isStandardLayout(layout)) {
2411
+ MindTransforms.setAbstractByStandardLayout(board, element);
2412
+ }
2413
+ Transforms.setNode(board, { layout }, path);
2414
+ };
2415
+ const correctLogicLayoutNode = (board, layout, path) => {
2416
+ const node = PlaitNode.get(board, path);
2417
+ if (node && layout) {
2418
+ node.children?.forEach((value, index) => {
2419
+ if (value.layout) {
2420
+ if ((isHorizontalLogicLayout(layout) && isVerticalLogicLayout(value.layout)) ||
2421
+ (isVerticalLogicLayout(layout) && isHorizontalLogicLayout(value.layout))) {
2422
+ Transforms.setNode(board, { layout: null }, [...path, index]);
2423
+ }
2424
+ if (value.children?.length) {
2425
+ correctLogicLayoutNode(board, layout, [...path, index]);
2426
+ }
2427
+ }
2428
+ });
2429
+ }
2430
+ };
2431
+
2432
+ const normalizeWidthAndHeight = (board, element, width, height) => {
2433
+ const minWidth = NodeSpace.getNodeTopicMinWidth(board, element, element.isRoot);
2434
+ const newWidth = width < minWidth * board.viewport.zoom ? minWidth : width / board.viewport.zoom;
2435
+ const newHeight = height / board.viewport.zoom;
2436
+ return { width: Math.ceil(newWidth), height: newHeight };
2437
+ };
2438
+ const setTopic = (board, element, topic, width, height) => {
2439
+ const newElement = {
2440
+ data: { ...element.data, topic },
2441
+ ...normalizeWidthAndHeight(board, element, width, height)
2442
+ };
2443
+ const path = PlaitBoard.findPath(board, element);
2444
+ Transforms.setNode(board, newElement, path);
2445
+ };
2446
+ const setNodeManualWidth = (board, element, width, height) => {
2447
+ const path = PlaitBoard.findPath(board, element);
2448
+ const { width: normalizedWidth, height: normalizedHeight } = normalizeWidthAndHeight(board, element, width, height);
2449
+ const newElement = { manualWidth: normalizedWidth, height: normalizedHeight };
2450
+ Transforms.setNode(board, newElement, path);
2451
+ };
2452
+ const setTopicSize = (board, element, width, height) => {
2453
+ const newElement = {
2454
+ ...normalizeWidthAndHeight(board, element, width, height)
2455
+ };
2456
+ let isEqualWidth = Math.ceil(element.width) === Math.ceil(newElement.width);
2457
+ let isEqualHeight = Math.ceil(element.height) === Math.ceil(newElement.height);
2458
+ if (element.manualWidth) {
2459
+ isEqualWidth = true;
2460
+ }
2461
+ if (!isEqualWidth || !isEqualHeight) {
2462
+ const path = PlaitBoard.findPath(board, element);
2463
+ Transforms.setNode(board, newElement, path);
2575
2464
  }
2576
- destroy() {
2577
- if (this.componentRef) {
2578
- this.componentRef.destroy();
2579
- this.componentRef = null;
2465
+ };
2466
+ const insertNodes = (board, elements, path) => {
2467
+ const pathRef = board.pathRef(path);
2468
+ elements.forEach(element => {
2469
+ if (pathRef.current) {
2470
+ Transforms.insertNode(board, element, pathRef.current);
2580
2471
  }
2472
+ });
2473
+ pathRef.unref();
2474
+ };
2475
+ const insertAbstractNodes = (board, validAbstractRefs, elements, path) => {
2476
+ const parent = PlaitNode.get(board, Path$1.parent(path));
2477
+ const abstractPath = [...Path$1.parent(path), parent.children?.length];
2478
+ const abstracts = validAbstractRefs.map(refs => {
2479
+ const { start, end } = getRelativeStartEndByAbstractRef(refs, elements);
2480
+ return {
2481
+ ...refs.abstract,
2482
+ start: start + path[path.length - 1],
2483
+ end: end + path[path.length - 1]
2484
+ };
2485
+ });
2486
+ insertNodes(board, abstracts, abstractPath);
2487
+ };
2488
+ const setRightNodeCountByRefs = (board, refs) => {
2489
+ refs.forEach(ref => {
2490
+ Transforms.setNode(board, { rightNodeCount: ref.rightNodeCount }, ref.path);
2491
+ });
2492
+ };
2493
+
2494
+ const addEmoji = (board, element, emojiItem) => {
2495
+ const emojis = element.data.emojis || [];
2496
+ const newEmojis = [...emojis];
2497
+ newEmojis.push(emojiItem);
2498
+ const newElement = {
2499
+ data: { ...element.data, emojis: newEmojis }
2500
+ };
2501
+ const path = PlaitBoard.findPath(board, element);
2502
+ Transforms.setNode(board, newElement, path);
2503
+ };
2504
+ const removeEmoji = (board, element, emojiItem) => {
2505
+ const emojis = element.data.emojis.filter(value => value !== emojiItem);
2506
+ const newElement = {
2507
+ data: { topic: element.data.topic }
2508
+ };
2509
+ if (MindElement.hasImage(element)) {
2510
+ newElement.data.image = element.data.image;
2581
2511
  }
2582
- }
2583
- class NodeEmojisDrawer {
2584
- constructor(board, viewContainerRef) {
2585
- this.board = board;
2586
- this.viewContainerRef = viewContainerRef;
2587
- this.emojiDrawers = [];
2512
+ if (emojis.length > 0) {
2513
+ newElement.data.emojis = emojis;
2588
2514
  }
2589
- drawEmojis(element) {
2590
- this.destroy();
2591
- if (MindElement.hasEmojis(element)) {
2592
- this.g = createG();
2593
- this.g.classList.add('emojis');
2594
- const foreignRectangle = getEmojiForeignRectangle(this.board, element);
2595
- const foreignObject = createForeignObject(foreignRectangle.x, foreignRectangle.y, foreignRectangle.width, foreignRectangle.height);
2596
- this.g.append(foreignObject);
2597
- const container = document.createElement('div');
2598
- container.classList.add('node-emojis-container');
2599
- foreignObject.append(container);
2600
- this.emojiDrawers = element.data.emojis.map(emojiItem => {
2601
- const drawer = new EmojiDrawer(this.board, this.viewContainerRef);
2602
- drawer.draw(emojiItem, element);
2603
- return drawer;
2604
- });
2605
- this.emojiDrawers.forEach(drawer => {
2606
- container.append(drawer.nativeElement);
2607
- });
2608
- return this.g;
2515
+ const path = PlaitBoard.findPath(board, element);
2516
+ Transforms.setNode(board, newElement, path);
2517
+ };
2518
+ const replaceEmoji = (board, element, oldEmoji, newEmoji) => {
2519
+ const newElement = {
2520
+ data: { ...element.data }
2521
+ };
2522
+ const newEmojis = element.data.emojis.map(value => {
2523
+ if (value === oldEmoji) {
2524
+ return newEmoji;
2609
2525
  }
2610
- return undefined;
2526
+ return value;
2527
+ });
2528
+ newElement.data.emojis = newEmojis;
2529
+ const path = PlaitBoard.findPath(board, element);
2530
+ Transforms.setNode(board, newElement, path);
2531
+ };
2532
+
2533
+ const removeImage = (board, element) => {
2534
+ setImageFocus(board, element, false);
2535
+ const newElement = {
2536
+ data: { ...element.data }
2537
+ };
2538
+ delete newElement.data.image;
2539
+ const path = PlaitBoard.findPath(board, element);
2540
+ const newDynamicWidth = NodeSpace.getNodeNewDynamicWidth(board, element, 0);
2541
+ const newHeight = getNewNodeHeight(board, element, newDynamicWidth);
2542
+ if (newHeight) {
2543
+ newElement.height = newHeight / board.viewport.zoom;
2611
2544
  }
2612
- destroy() {
2613
- if (this.g) {
2614
- this.g.remove();
2615
- }
2616
- this.emojiDrawers.forEach(drawer => drawer.destroy());
2617
- this.emojiDrawers = [];
2545
+ Transforms.setNode(board, newElement, path);
2546
+ };
2547
+ const setImage = (board, element, imageItem) => {
2548
+ const newElement = {
2549
+ data: { ...element.data, image: imageItem }
2550
+ };
2551
+ const newDynamicWidth = NodeSpace.getNodeNewDynamicWidth(board, element, imageItem.width);
2552
+ const newHeight = getNewNodeHeight(board, element, newDynamicWidth);
2553
+ if (newHeight) {
2554
+ newElement.height = newHeight / board.viewport.zoom;
2618
2555
  }
2619
- }
2556
+ const path = PlaitBoard.findPath(board, element);
2557
+ Transforms.setNode(board, newElement, path);
2558
+ };
2559
+
2560
+ const MindTransforms = {
2561
+ setLayout,
2562
+ setTopic,
2563
+ setTopicSize,
2564
+ setNodeManualWidth,
2565
+ addEmoji,
2566
+ removeEmoji,
2567
+ replaceEmoji,
2568
+ insertAbstract,
2569
+ setAbstractsByRefs,
2570
+ setAbstractByStandardLayout,
2571
+ insertNodes,
2572
+ insertAbstractNodes,
2573
+ setRightNodeCountByRefs,
2574
+ removeImage,
2575
+ setImage
2576
+ };
2620
2577
 
2621
2578
  class BaseDrawer {
2622
2579
  constructor(board) {
@@ -2973,61 +2930,6 @@ class CollapseDrawer extends BaseDrawer {
2973
2930
  }
2974
2931
  }
2975
2932
 
2976
- class NodeImageDrawer {
2977
- constructor(board, viewContainerRef) {
2978
- this.board = board;
2979
- this.viewContainerRef = viewContainerRef;
2980
- this.componentRef = null;
2981
- }
2982
- drawImage(nodeG, element) {
2983
- if (!MindElement.hasImage(element)) {
2984
- this.destroy();
2985
- return;
2986
- }
2987
- this.g = createG();
2988
- const foreignRectangle = getImageForeignRectangle(this.board, element);
2989
- this.foreignObject = createForeignObject(foreignRectangle.x, foreignRectangle.y, foreignRectangle.width, foreignRectangle.height);
2990
- this.g.append(this.foreignObject);
2991
- const componentType = this.board.getPluginOptions(WithMindPluginKey).imageComponentType;
2992
- if (!componentType) {
2993
- throw new Error('Not implement drawEmoji method error.');
2994
- }
2995
- this.componentRef = this.viewContainerRef.createComponent(componentType);
2996
- this.componentRef.instance.board = this.board;
2997
- this.componentRef.instance.element = element;
2998
- this.componentRef.instance.imageItem = element.data.image;
2999
- this.componentRef.instance.cdr.markForCheck();
3000
- this.foreignObject.append(this.componentRef.instance.nativeElement);
3001
- nodeG.appendChild(this.g);
3002
- }
3003
- updateImage(nodeG, previous, current) {
3004
- if (!MindElement.hasImage(previous) || !MindElement.hasImage(current)) {
3005
- this.drawImage(nodeG, current);
3006
- return;
3007
- }
3008
- if (previous !== current && this.componentRef) {
3009
- this.componentRef.instance.element = current;
3010
- this.componentRef.instance.imageItem = current.data.image;
3011
- }
3012
- const currentForeignObject = getImageForeignRectangle(this.board, current);
3013
- updateForeignObject(this.g, currentForeignObject.width, currentForeignObject.height, currentForeignObject.x, currentForeignObject.y);
3014
- // solve image lose on move node
3015
- if (this.foreignObject.children.length === 0) {
3016
- this.foreignObject.append(this.componentRef.instance.nativeElement);
3017
- }
3018
- this.componentRef?.instance.cdr.markForCheck();
3019
- }
3020
- destroy() {
3021
- if (this.g) {
3022
- this.g.remove();
3023
- }
3024
- if (this.componentRef) {
3025
- this.componentRef.destroy();
3026
- this.componentRef = null;
3027
- }
3028
- }
3029
- }
3030
-
3031
2933
  class NodeShapeGenerator extends Generator {
3032
2934
  canDraw(element, data) {
3033
2935
  const shape = getShapeByElement(this.board, element);
@@ -3062,7 +2964,14 @@ class MindNodeComponent extends CommonPluginElement {
3062
2964
  this.nodeInsertDrawer = new NodeInsertDrawer(this.board);
3063
2965
  this.activeGenerator = new NodeActiveGenerator(this.board);
3064
2966
  this.collapseDrawer = new CollapseDrawer(this.board);
3065
- this.imageDrawer = new NodeImageDrawer(this.board, this.viewContainerRef);
2967
+ this.imageGenerator = new ImageGenerator(this.board, {
2968
+ getRectangle: (element) => {
2969
+ return getImageForeignRectangle(this.board, element);
2970
+ },
2971
+ getImageItem: (element) => {
2972
+ return element.data.image;
2973
+ }
2974
+ });
3066
2975
  const plugins = this.board.getPluginOptions(WithTextPluginKey).textPlugins;
3067
2976
  const textManage = new TextManage(this.board, this.viewContainerRef, {
3068
2977
  getRectangle: () => {
@@ -3104,7 +3013,7 @@ class MindNodeComponent extends CommonPluginElement {
3104
3013
  this.activeGenerator.draw(this.element, this.g, { selected: this.selected, isEditing: this.textManage.isEditing });
3105
3014
  this.drawEmojis();
3106
3015
  this.drawExtend();
3107
- this.imageDrawer.drawImage(this.g, this.element);
3016
+ this.imageGenerator.draw(this.element, this.g, this.viewContainerRef);
3108
3017
  if (PlaitMind.isMind(this.context.parent)) {
3109
3018
  this.g.classList.add('branch');
3110
3019
  }
@@ -3120,7 +3029,15 @@ class MindNodeComponent extends CommonPluginElement {
3120
3029
  this.drawLink();
3121
3030
  this.drawEmojis();
3122
3031
  this.drawExtend();
3123
- this.imageDrawer.updateImage(this.g, previous.element, value.element);
3032
+ if (!MindElement.hasImage(previous.element) && MindElement.hasImage(this.element)) {
3033
+ this.imageGenerator.draw(this.element, this.g, this.viewContainerRef);
3034
+ }
3035
+ if (MindElement.hasImage(previous.element) && MindElement.hasImage(this.element)) {
3036
+ this.imageGenerator.updateImage(this.g, previous.element, value.element);
3037
+ }
3038
+ if (MindElement.hasImage(previous.element) && !MindElement.hasImage(this.element)) {
3039
+ this.imageGenerator.destroy();
3040
+ }
3124
3041
  this.updateTopic();
3125
3042
  }
3126
3043
  else {
@@ -3202,15 +3119,15 @@ class MindNodeComponent extends CommonPluginElement {
3202
3119
  super.ngOnDestroy();
3203
3120
  this.textManage.destroy();
3204
3121
  this.nodeEmojisDrawer.destroy();
3205
- this.imageDrawer.destroy();
3122
+ this.imageGenerator.destroy();
3206
3123
  this.destroy$.next();
3207
3124
  this.destroy$.complete();
3208
3125
  if (ELEMENT_TO_NODE.get(this.element) === this.node) {
3209
3126
  ELEMENT_TO_NODE.delete(this.element);
3210
3127
  }
3211
3128
  }
3212
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindNodeComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
3213
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: MindNodeComponent, selector: "plait-mind-node", usesInheritance: true, ngImport: i0, template: `
3129
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MindNodeComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
3130
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: MindNodeComponent, isStandalone: true, selector: "plait-mind-node", usesInheritance: true, ngImport: i0, template: `
3214
3131
  <plait-children
3215
3132
  *ngIf="!element.isCollapsed"
3216
3133
  [board]="board"
@@ -3218,9 +3135,9 @@ class MindNodeComponent extends CommonPluginElement {
3218
3135
  [effect]="effect"
3219
3136
  [parentG]="parentG"
3220
3137
  ></plait-children>
3221
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.PlaitChildrenElement, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3138
+ `, 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 }); }
3222
3139
  }
3223
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindNodeComponent, decorators: [{
3140
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MindNodeComponent, decorators: [{
3224
3141
  type: Component,
3225
3142
  args: [{
3226
3143
  selector: 'plait-mind-node',
@@ -3233,7 +3150,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImpor
3233
3150
  [parentG]="parentG"
3234
3151
  ></plait-children>
3235
3152
  `,
3236
- changeDetection: ChangeDetectionStrategy.OnPush
3153
+ changeDetection: ChangeDetectionStrategy.OnPush,
3154
+ standalone: true,
3155
+ imports: [NgIf, PlaitChildrenElementComponent]
3237
3156
  }]
3238
3157
  }], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }]; } });
3239
3158
 
@@ -3263,33 +3182,21 @@ class PlaitMindComponent extends MindNodeComponent {
3263
3182
  ELEMENT_TO_NODE.set(node.origin, node);
3264
3183
  });
3265
3184
  }
3266
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: PlaitMindComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
3267
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.3", type: PlaitMindComponent, selector: "plait-mind", usesInheritance: true, ngImport: i0, template: `
3185
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PlaitMindComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
3186
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: PlaitMindComponent, isStandalone: true, selector: "plait-mind", usesInheritance: true, ngImport: i0, template: `
3268
3187
  <plait-children [board]="board" [parent]="element" [effect]="effect" [parentG]="rootG"></plait-children>
3269
- `, isInline: true, dependencies: [{ kind: "component", type: i2.PlaitChildrenElement, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3188
+ `, isInline: true, dependencies: [{ kind: "component", type: PlaitChildrenElementComponent, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
3270
3189
  }
3271
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: PlaitMindComponent, decorators: [{
3190
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PlaitMindComponent, decorators: [{
3272
3191
  type: Component,
3273
3192
  args: [{
3274
3193
  selector: 'plait-mind',
3275
3194
  template: `
3276
3195
  <plait-children [board]="board" [parent]="element" [effect]="effect" [parentG]="rootG"></plait-children>
3277
3196
  `,
3278
- changeDetection: ChangeDetectionStrategy.OnPush
3279
- }]
3280
- }] });
3281
-
3282
- class MindModule {
3283
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
3284
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.3", ngImport: i0, type: MindModule, declarations: [PlaitMindComponent, MindNodeComponent], imports: [CommonModule, TextModule, PlaitModule], exports: [PlaitMindComponent, MindNodeComponent] }); }
3285
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindModule, imports: [CommonModule, TextModule, PlaitModule] }); }
3286
- }
3287
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindModule, decorators: [{
3288
- type: NgModule,
3289
- args: [{
3290
- declarations: [PlaitMindComponent, MindNodeComponent],
3291
- imports: [CommonModule, TextModule, PlaitModule],
3292
- exports: [PlaitMindComponent, MindNodeComponent]
3197
+ changeDetection: ChangeDetectionStrategy.OnPush,
3198
+ standalone: true,
3199
+ imports: [PlaitChildrenElementComponent, MindNodeComponent]
3293
3200
  }]
3294
3201
  }] });
3295
3202
 
@@ -3313,10 +3220,8 @@ const withNodeDnd = (board) => {
3313
3220
  }
3314
3221
  const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
3315
3222
  const selectedElements = getSelectedElements(board);
3316
- const hitTarget = getHitElements(board, { ranges: [{ anchor: point, focus: point }] }, (element) => {
3317
- return MindElement.isMindElement(board, element);
3318
- });
3319
- const targetElement = hitTarget && hitTarget.length === 1 ? hitTarget[0] : null;
3223
+ const hitTarget = getHitElements(board, { ranges: [{ anchor: point, focus: point }] });
3224
+ const targetElement = hitTarget && hitTarget.length === 1 && MindElement.isMindElement(board, hitTarget[0]) ? hitTarget[0] : null;
3320
3225
  if (targetElement &&
3321
3226
  MindElement.isMindElement(board, targetElement) &&
3322
3227
  !targetElement.isRoot &&
@@ -3338,7 +3243,8 @@ const withNodeDnd = (board) => {
3338
3243
  pointerDown(event);
3339
3244
  };
3340
3245
  board.pointerMove = (event) => {
3341
- if (!board.options.readonly && activeElements?.length && startPoint) {
3246
+ // const xx = activeElements.
3247
+ if (!board.options.readonly && activeElements.length && startPoint) {
3342
3248
  // prevent text from being selected
3343
3249
  event.preventDefault();
3344
3250
  const endPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
@@ -3875,11 +3781,13 @@ const withNodeImage = (board) => {
3875
3781
  const isSelectedImage = !!getSelectedImageElement(board);
3876
3782
  const isSingleSelection = selectedElements.length === 1 && MindElement.isMindElement(board, selectedElements[0]);
3877
3783
  if (data?.files.length && (isSingleSelection || isSelectedImage)) {
3878
- const selectedElement = (selectedElements[0] || getSelectedImageElement(board));
3879
3784
  const acceptImageArray = acceptImageTypes.map(type => 'image/' + type);
3785
+ const selectedElement = (selectedElements[0] || getSelectedImageElement(board));
3880
3786
  if (acceptImageArray.includes(data?.files[0].type)) {
3881
3787
  const imageFile = data.files[0];
3882
- buildImage(board, selectedElement, imageFile);
3788
+ buildImage(board, imageFile, DEFAULT_MIND_IMAGE_WIDTH, imageItem => {
3789
+ MindTransforms.setImage(board, selectedElement, imageItem);
3790
+ });
3883
3791
  return;
3884
3792
  }
3885
3793
  }
@@ -4247,7 +4155,7 @@ const getNextSelectedElement = (board, firstLevelElements) => {
4247
4155
 
4248
4156
  const withMind = (baseBoard) => {
4249
4157
  const board = baseBoard;
4250
- const { drawElement, dblclick, isHitSelection, getRectangle, isMovable, isRecursion } = board;
4158
+ const { drawElement, dblclick, isHitSelection, getRectangle, isMovable, isRecursion, isAlign } = board;
4251
4159
  board.drawElement = (context) => {
4252
4160
  if (PlaitMind.isMind(context.element)) {
4253
4161
  return PlaitMindComponent;
@@ -4291,6 +4199,12 @@ const withMind = (baseBoard) => {
4291
4199
  }
4292
4200
  return isMovable(element);
4293
4201
  };
4202
+ board.isAlign = (element) => {
4203
+ if (PlaitMind.isMind(element) && element.isRoot) {
4204
+ return true;
4205
+ }
4206
+ return isAlign(element);
4207
+ };
4294
4208
  board.dblclick = (event) => {
4295
4209
  if (PlaitBoard.isReadonly(board)) {
4296
4210
  dblclick(event);
@@ -4334,10 +4248,10 @@ class MindEmojiBaseComponent {
4334
4248
  ngOnInit() {
4335
4249
  this.elementRef.nativeElement.style.fontSize = `${this.fontSize}px`;
4336
4250
  }
4337
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindEmojiBaseComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
4338
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.3", type: MindEmojiBaseComponent, inputs: { fontSize: "fontSize", emojiItem: "emojiItem", board: "board", element: "element" }, host: { listeners: { "pointerdown": "handlePointerDown()" }, classAttribute: "mind-node-emoji" }, ngImport: i0 }); }
4251
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MindEmojiBaseComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
4252
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: MindEmojiBaseComponent, inputs: { fontSize: "fontSize", emojiItem: "emojiItem", board: "board", element: "element" }, host: { listeners: { "pointerdown": "handlePointerDown()" }, classAttribute: "mind-node-emoji" }, ngImport: i0 }); }
4339
4253
  }
4340
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindEmojiBaseComponent, decorators: [{
4254
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MindEmojiBaseComponent, decorators: [{
4341
4255
  type: Directive,
4342
4256
  args: [{
4343
4257
  host: {
@@ -4357,76 +4271,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImpor
4357
4271
  args: ['pointerdown']
4358
4272
  }] } });
4359
4273
 
4360
- class MindImageBaseComponent {
4361
- set imageItem(value) {
4362
- this.afterImageItemChange(this._imageItem, value);
4363
- this._imageItem = value;
4364
- this.drawFocus();
4365
- }
4366
- get imageItem() {
4367
- return this._imageItem;
4368
- }
4369
- set isFocus(value) {
4370
- this._isFocus = value;
4371
- this.drawFocus();
4372
- }
4373
- get isFocus() {
4374
- return this._isFocus;
4375
- }
4376
- get nativeElement() {
4377
- return this.elementRef.nativeElement;
4378
- }
4379
- constructor(elementRef, cdr) {
4380
- this.elementRef = elementRef;
4381
- this.cdr = cdr;
4382
- this.initialized = false;
4383
- }
4384
- ngOnInit() {
4385
- this.activeGenerator = new ActiveGenerator(this.board, {
4386
- getStrokeWidth: () => {
4387
- return 1;
4388
- },
4389
- getStrokeOpacity: () => {
4390
- return 1;
4391
- },
4392
- getRectangle: (element) => {
4393
- return getImageForeignRectangle(this.board, this.element);
4394
- },
4395
- hasResizeHandle: () => true
4396
- });
4397
- this.initialized = true;
4398
- }
4399
- drawFocus() {
4400
- if (this.initialized) {
4401
- const com = PlaitElement.getComponent(this.element);
4402
- this.activeGenerator.draw(this.element, com.g, { selected: this._isFocus });
4403
- }
4404
- }
4405
- ngOnDestroy() {
4406
- if (this.activeGenerator) {
4407
- this.activeGenerator.destroy();
4408
- }
4409
- }
4410
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindImageBaseComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
4411
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.3", type: MindImageBaseComponent, inputs: { imageItem: "imageItem", board: "board", element: "element", isFocus: "isFocus" }, host: { classAttribute: "mind-node-image" }, ngImport: i0 }); }
4412
- }
4413
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImport: i0, type: MindImageBaseComponent, decorators: [{
4414
- type: Directive,
4415
- args: [{
4416
- host: {
4417
- class: 'mind-node-image'
4418
- }
4419
- }]
4420
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { imageItem: [{
4421
- type: Input
4422
- }], board: [{
4423
- type: Input
4424
- }], element: [{
4425
- type: Input
4426
- }], isFocus: [{
4427
- type: Input
4428
- }] } });
4429
-
4430
4274
  /*
4431
4275
  * Public API Surface of mind
4432
4276
  */
@@ -4435,5 +4279,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.3", ngImpor
4435
4279
  * Generated bundle index. Do not edit.
4436
4280
  */
4437
4281
 
4438
- 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, NodeSpace, NodeTopicThreshold, PRIMARY_COLOR, PlaitMind, PlaitMindComponent, QUICK_INSERT_CIRCLE_COLOR, QUICK_INSERT_CIRCLE_OFFSET, QUICK_INSERT_INNER_CROSS_COLOR, ROOT_TOPIC_FONT_SIZE, ROOT_TOPIC_HEIGHT, ROOT_TOPIC_WIDTH, STROKE_WIDTH, TOPIC_COLOR, TOPIC_DEFAULT_MAX_WORD_COUNT, TOPIC_FONT_SIZE, TRANSPARENT, WithMindPluginKey, addActiveOnDragOrigin, addSelectedImageElement, adjustAbstractToNode, adjustNodeToRoot, adjustRootToNode, buildImage, 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, getEmojiFontSize, getEmojiForeignRectangle, getEmojiRectangle, getEmojisWidthHeight, getFillByElement, getFirstLevelElement, getFontSizeBySlateElement, getHitAbstractHandle, getHitImageResizeHandleDirection, getImageForeignRectangle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutOptions, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNewNodeHeight, getNextBranchColor, getNodeDefaultFontSize, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getSelectedImageElement, getSelectedMindElements, 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, removeActiveOnDragOrigin, removeSelectedImageElement, selectImage, separateChildren, setImageFocus, setIsDragging, temporaryDisableSelection, withMind, withMindExtend };
4282
+ 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, DEFAULT_MIND_IMAGE_WIDTH, DefaultAbstractNodeStyle, DefaultNodeStyle, ELEMENT_TO_NODE, EXTEND_DIAMETER, EXTEND_OFFSET, GRAY_COLOR, INHERIT_ATTRIBUTE_KEYS, IS_DRAGGING, LayoutDirection, LayoutDirectionsMap, MindColorfulThemeColor, MindDarkThemeColor, MindDefaultThemeColor, MindElement, MindElementShape, MindEmojiBaseComponent, MindNode, MindNodeComponent, MindPointerType, MindQueries, MindRetroThemeColor, MindSoftThemeColor, MindStarryThemeColor, MindThemeColor, MindThemeColors, MindTransforms, NodeSpace, NodeTopicThreshold, PRIMARY_COLOR, PlaitMind, PlaitMindComponent, QUICK_INSERT_CIRCLE_COLOR, QUICK_INSERT_CIRCLE_OFFSET, QUICK_INSERT_INNER_CROSS_COLOR, ROOT_TOPIC_FONT_SIZE, ROOT_TOPIC_HEIGHT, ROOT_TOPIC_WIDTH, STROKE_WIDTH, TOPIC_COLOR, TOPIC_DEFAULT_MAX_WORD_COUNT, TOPIC_FONT_SIZE, TRANSPARENT, WithMindPluginKey, addActiveOnDragOrigin, addSelectedImageElement, 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, getEmojiFontSize, getEmojiForeignRectangle, getEmojiRectangle, getEmojisWidthHeight, getFillByElement, getFirstLevelElement, getFontSizeBySlateElement, getHitAbstractHandle, getHitImageResizeHandleDirection, getImageForeignRectangle, getInCorrectLayoutDirection, getLayoutDirection$1 as getLayoutDirection, getLayoutOptions, getLayoutReverseDirection, getLocationScope, getMindThemeColor, getNewNodeHeight, getNextBranchColor, getNodeDefaultFontSize, getOverallAbstracts, getPathByDropTarget, getRectangleByElement, getRectangleByNode, getRectangleByResizingLocation, getRelativeStartEndByAbstractRef, getRootLayout, getSelectedImageElement, getSelectedMindElements, 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, removeActiveOnDragOrigin, removeSelectedImageElement, separateChildren, setImageFocus, setIsDragging, temporaryDisableSelection, withMind, withMindExtend };
4439
4283
  //# sourceMappingURL=plait-mind.mjs.map