microboard-temp 0.13.37 → 0.13.39
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.
- package/dist/cjs/browser.js +152 -28
- package/dist/cjs/index.js +152 -28
- package/dist/cjs/node.js +152 -28
- package/dist/esm/browser.js +152 -28
- package/dist/esm/index.js +152 -28
- package/dist/esm/node.js +152 -28
- package/dist/types/Selection/Selection.d.ts +20 -0
- package/dist/types/SpatialIndex/SimpleSpatialIndex.d.ts +1 -1
- package/dist/types/SpatialIndex/SpacialIndex.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/node.js
CHANGED
|
@@ -23545,8 +23545,8 @@ class SpatialIndex {
|
|
|
23545
23545
|
}
|
|
23546
23546
|
this.subject.publish(this.items);
|
|
23547
23547
|
};
|
|
23548
|
-
remove(item) {
|
|
23549
|
-
if ("index" in item && item.index) {
|
|
23548
|
+
remove(item, preserveChildren = false) {
|
|
23549
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
23550
23550
|
item.removeChildItems(item.index.list());
|
|
23551
23551
|
}
|
|
23552
23552
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -23786,6 +23786,9 @@ class SpatialIndex {
|
|
|
23786
23786
|
return false;
|
|
23787
23787
|
}
|
|
23788
23788
|
}
|
|
23789
|
+
if (item.itemType === "Group") {
|
|
23790
|
+
return false;
|
|
23791
|
+
}
|
|
23789
23792
|
return true;
|
|
23790
23793
|
});
|
|
23791
23794
|
return [...clearItems, ...children];
|
|
@@ -24107,8 +24110,8 @@ class SimpleSpatialIndex {
|
|
|
24107
24110
|
}
|
|
24108
24111
|
this.subject.publish(this.items);
|
|
24109
24112
|
};
|
|
24110
|
-
remove(item) {
|
|
24111
|
-
if ("index" in item && item.index) {
|
|
24113
|
+
remove(item, preserveChildren = false) {
|
|
24114
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
24112
24115
|
item.removeChildItems(item.index.list());
|
|
24113
24116
|
}
|
|
24114
24117
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -24491,7 +24494,7 @@ class BaseItem extends Mbr {
|
|
|
24491
24494
|
if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
|
|
24492
24495
|
if (!this.index?.getById(childId) && foundItem) {
|
|
24493
24496
|
const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
|
|
24494
|
-
this.board.items.index.remove(foundItem);
|
|
24497
|
+
this.board.items.index.remove(foundItem, true);
|
|
24495
24498
|
foundItem.parent = this.getId();
|
|
24496
24499
|
foundItem.onParentChanged(this.getId());
|
|
24497
24500
|
foundItem.transformation.setLocalMatrix(localMatrix);
|
|
@@ -24513,7 +24516,7 @@ class BaseItem extends Mbr {
|
|
|
24513
24516
|
if (this.parent !== childId && this.getId() !== childId) {
|
|
24514
24517
|
if (foundItem) {
|
|
24515
24518
|
const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
|
|
24516
|
-
this.index?.remove(foundItem);
|
|
24519
|
+
this.index?.remove(foundItem, true);
|
|
24517
24520
|
foundItem.parent = "Board";
|
|
24518
24521
|
foundItem.onParentChanged("Board");
|
|
24519
24522
|
foundItem.transformation.setLocalMatrix(worldMatrix);
|
|
@@ -50632,8 +50635,8 @@ class Tools extends ToolContext {
|
|
|
50632
50635
|
const zoomOffset = 25;
|
|
50633
50636
|
this.board.camera.zoomToFit(frameMbr, zoomOffset, 0);
|
|
50634
50637
|
this.board.selection.removeAll();
|
|
50635
|
-
this.board.selection.
|
|
50636
|
-
this.board.selection.
|
|
50638
|
+
this.board.selection.add(frames[newFrameIndex]);
|
|
50639
|
+
this.board.selection.setContext("SelectUnderPointer");
|
|
50637
50640
|
localStorage.setItem(`lastVisitedFrame`, frames[newFrameIndex].getId());
|
|
50638
50641
|
this.publish();
|
|
50639
50642
|
}
|
|
@@ -51783,9 +51786,9 @@ function createDeck(event, board) {
|
|
|
51783
51786
|
const deck = new Deck(board, "");
|
|
51784
51787
|
deck.transformation.setLocal(cardsOrDecks[cardsOrDecks.length - 1].left, cardsOrDecks[cardsOrDecks.length - 1].top);
|
|
51785
51788
|
const addedDeck = board.add(deck);
|
|
51786
|
-
board.selection.
|
|
51789
|
+
board.selection.removeAll();
|
|
51787
51790
|
addedDeck.addChildItems(cardsOrDecks);
|
|
51788
|
-
board.selection.
|
|
51791
|
+
board.selection.add(addedDeck);
|
|
51789
51792
|
} else {
|
|
51790
51793
|
let mainDeck = null;
|
|
51791
51794
|
const cards = [];
|
|
@@ -51802,9 +51805,9 @@ function createDeck(event, board) {
|
|
|
51802
51805
|
}
|
|
51803
51806
|
}
|
|
51804
51807
|
});
|
|
51805
|
-
board.selection.
|
|
51808
|
+
board.selection.removeAll();
|
|
51806
51809
|
mainDeck.addChildItems(cards);
|
|
51807
|
-
board.selection.
|
|
51810
|
+
board.selection.add(mainDeck);
|
|
51808
51811
|
}
|
|
51809
51812
|
}
|
|
51810
51813
|
registerHotkey({
|
|
@@ -55874,7 +55877,7 @@ class BoardSelection {
|
|
|
55874
55877
|
selectedItems.forEach((itemId) => {
|
|
55875
55878
|
const item = this.board.items.getById(itemId);
|
|
55876
55879
|
if (item) {
|
|
55877
|
-
this.
|
|
55880
|
+
this.add(item);
|
|
55878
55881
|
}
|
|
55879
55882
|
});
|
|
55880
55883
|
}
|
|
@@ -55961,13 +55964,22 @@ class BoardSelection {
|
|
|
55961
55964
|
};
|
|
55962
55965
|
decoratedItemObserver = this.decorateObserverToScheduleUpdate(this.itemObserver);
|
|
55963
55966
|
add(value) {
|
|
55964
|
-
|
|
55965
|
-
|
|
55966
|
-
|
|
55967
|
-
|
|
55968
|
-
|
|
55969
|
-
|
|
55970
|
-
|
|
55967
|
+
const values2 = Array.isArray(value) ? value : [value];
|
|
55968
|
+
const nextItems = this.normalizeSelectionItems([
|
|
55969
|
+
...this.items.list(),
|
|
55970
|
+
...values2
|
|
55971
|
+
]);
|
|
55972
|
+
const currentIds = new Set(this.items.ids());
|
|
55973
|
+
const nextIds = new Set(nextItems.map((item) => item.getId()));
|
|
55974
|
+
const removed = this.items.list().filter((item) => !nextIds.has(item.getId()));
|
|
55975
|
+
const added = nextItems.filter((item) => !currentIds.has(item.getId()));
|
|
55976
|
+
if (removed.length > 0) {
|
|
55977
|
+
this.items.remove(removed);
|
|
55978
|
+
removed.forEach((item) => item.subject.unsubscribe(this.itemObserver));
|
|
55979
|
+
}
|
|
55980
|
+
if (added.length > 0) {
|
|
55981
|
+
this.items.add(added);
|
|
55982
|
+
added.forEach((item) => item.subject.subscribe(this.itemObserver));
|
|
55971
55983
|
}
|
|
55972
55984
|
this.subject.publish(this);
|
|
55973
55985
|
this.itemsSubject.publish([]);
|
|
@@ -56047,15 +56059,54 @@ class BoardSelection {
|
|
|
56047
56059
|
if (!item) {
|
|
56048
56060
|
return null;
|
|
56049
56061
|
}
|
|
56050
|
-
if (
|
|
56051
|
-
return
|
|
56052
|
-
}
|
|
56053
|
-
const parent = this.board.items.getById(item.parent);
|
|
56054
|
-
if (parent instanceof Group) {
|
|
56055
|
-
return parent;
|
|
56062
|
+
if (item instanceof Group) {
|
|
56063
|
+
return null;
|
|
56056
56064
|
}
|
|
56057
56065
|
return item;
|
|
56058
56066
|
}
|
|
56067
|
+
getParentItem(item) {
|
|
56068
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
56069
|
+
if (!resolved || !(resolved instanceof BaseItem) || resolved.parent === "Board") {
|
|
56070
|
+
return null;
|
|
56071
|
+
}
|
|
56072
|
+
return this.board.items.getById(resolved.parent) || null;
|
|
56073
|
+
}
|
|
56074
|
+
isAncestor(candidate, descendant) {
|
|
56075
|
+
if (!(descendant instanceof BaseItem)) {
|
|
56076
|
+
return false;
|
|
56077
|
+
}
|
|
56078
|
+
let parentId = descendant.parent;
|
|
56079
|
+
while (parentId && parentId !== "Board") {
|
|
56080
|
+
if (parentId === candidate.getId()) {
|
|
56081
|
+
return true;
|
|
56082
|
+
}
|
|
56083
|
+
const parent = this.board.items.getById(parentId);
|
|
56084
|
+
if (!parent || parent.parent === parentId) {
|
|
56085
|
+
return false;
|
|
56086
|
+
}
|
|
56087
|
+
parentId = parent.parent;
|
|
56088
|
+
}
|
|
56089
|
+
return false;
|
|
56090
|
+
}
|
|
56091
|
+
normalizeSelectionItems(items) {
|
|
56092
|
+
const normalized = [];
|
|
56093
|
+
for (const item of items) {
|
|
56094
|
+
const alreadyCovered = normalized.some((selected) => selected.getId() === item.getId() || this.isAncestor(selected, item));
|
|
56095
|
+
if (alreadyCovered) {
|
|
56096
|
+
continue;
|
|
56097
|
+
}
|
|
56098
|
+
for (let i = normalized.length - 1;i >= 0; i -= 1) {
|
|
56099
|
+
if (this.isAncestor(item, normalized[i])) {
|
|
56100
|
+
normalized.splice(i, 1);
|
|
56101
|
+
}
|
|
56102
|
+
}
|
|
56103
|
+
normalized.push(item);
|
|
56104
|
+
}
|
|
56105
|
+
return normalized;
|
|
56106
|
+
}
|
|
56107
|
+
getCanvasSelectableItems(items) {
|
|
56108
|
+
return items.filter((item) => !(item instanceof Group));
|
|
56109
|
+
}
|
|
56059
56110
|
selectUnderPointer() {
|
|
56060
56111
|
this.removeAll();
|
|
56061
56112
|
const stack = this.board.items.getUnderPointer();
|
|
@@ -56193,7 +56244,7 @@ class BoardSelection {
|
|
|
56193
56244
|
}
|
|
56194
56245
|
selectEnclosedBy(rect) {
|
|
56195
56246
|
this.removeAll();
|
|
56196
|
-
const list6 = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom);
|
|
56247
|
+
const list6 = this.getCanvasSelectableItems(this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom));
|
|
56197
56248
|
if (list6.length !== 0) {
|
|
56198
56249
|
this.add(list6);
|
|
56199
56250
|
this.setContext("SelectByRect");
|
|
@@ -56204,7 +56255,7 @@ class BoardSelection {
|
|
|
56204
56255
|
selectEnclosedOrCrossedBy(rect) {
|
|
56205
56256
|
this.removeAll();
|
|
56206
56257
|
const enclosedFrames = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => !item.transformation.isLocked);
|
|
56207
|
-
const list6 = this.board.items.getEnclosedOrCrossed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => (!(item instanceof Frame2) || enclosedFrames.includes(item)) && !item.transformation.isLocked);
|
|
56258
|
+
const list6 = this.getCanvasSelectableItems(this.board.items.getEnclosedOrCrossed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => (!(item instanceof Frame2) || enclosedFrames.includes(item)) && !item.transformation.isLocked));
|
|
56208
56259
|
if (list6.length !== 0) {
|
|
56209
56260
|
this.add(list6);
|
|
56210
56261
|
this.setContext("SelectByRect");
|
|
@@ -56403,6 +56454,79 @@ class BoardSelection {
|
|
|
56403
56454
|
}
|
|
56404
56455
|
return this.textToEdit;
|
|
56405
56456
|
}
|
|
56457
|
+
getParent(item) {
|
|
56458
|
+
return this.getParentItem(item);
|
|
56459
|
+
}
|
|
56460
|
+
getParentChain(item) {
|
|
56461
|
+
const chain = [];
|
|
56462
|
+
let parent = this.getParentItem(item);
|
|
56463
|
+
while (parent) {
|
|
56464
|
+
chain.push(parent);
|
|
56465
|
+
parent = this.getParentItem(parent);
|
|
56466
|
+
}
|
|
56467
|
+
return chain;
|
|
56468
|
+
}
|
|
56469
|
+
getHierarchyPath(item) {
|
|
56470
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
56471
|
+
if (!resolved) {
|
|
56472
|
+
return [];
|
|
56473
|
+
}
|
|
56474
|
+
const nodes = [...this.getParentChain(resolved).reverse(), resolved];
|
|
56475
|
+
return nodes.filter((node2) => node2 instanceof BaseItem).map((node2) => ({
|
|
56476
|
+
id: node2.getId(),
|
|
56477
|
+
itemType: node2.itemType,
|
|
56478
|
+
parentId: node2.parent === "Board" ? null : node2.parent,
|
|
56479
|
+
hasChildren: (node2.getChildrenIds()?.length || 0) > 0,
|
|
56480
|
+
isCanvasSelectable: !(node2 instanceof Group)
|
|
56481
|
+
}));
|
|
56482
|
+
}
|
|
56483
|
+
getSelectionHierarchyPaths() {
|
|
56484
|
+
return this.items.list().map((item) => this.getHierarchyPath(item));
|
|
56485
|
+
}
|
|
56486
|
+
getCommonParent() {
|
|
56487
|
+
const selected = this.items.list();
|
|
56488
|
+
if (selected.length === 0) {
|
|
56489
|
+
return null;
|
|
56490
|
+
}
|
|
56491
|
+
const firstParent = this.getParentItem(selected[0]);
|
|
56492
|
+
if (!firstParent) {
|
|
56493
|
+
return null;
|
|
56494
|
+
}
|
|
56495
|
+
const firstParentId = firstParent.getId();
|
|
56496
|
+
const hasSameParent = selected.every((item) => this.getParentItem(item)?.getId() === firstParentId);
|
|
56497
|
+
return hasSameParent ? firstParent : null;
|
|
56498
|
+
}
|
|
56499
|
+
canPromoteSelectionToParent() {
|
|
56500
|
+
return this.getCommonParent() !== null;
|
|
56501
|
+
}
|
|
56502
|
+
selectParent() {
|
|
56503
|
+
const parent = this.getCommonParent();
|
|
56504
|
+
if (!parent) {
|
|
56505
|
+
return null;
|
|
56506
|
+
}
|
|
56507
|
+
this.removeAll();
|
|
56508
|
+
this.add(parent);
|
|
56509
|
+
this.setContext("SelectUnderPointer");
|
|
56510
|
+
return parent;
|
|
56511
|
+
}
|
|
56512
|
+
selectAncestorById(ancestorId) {
|
|
56513
|
+
const selected = this.items.list();
|
|
56514
|
+
if (selected.length === 0) {
|
|
56515
|
+
return null;
|
|
56516
|
+
}
|
|
56517
|
+
const ancestor = this.board.items.getById(ancestorId);
|
|
56518
|
+
if (!(ancestor instanceof BaseItem)) {
|
|
56519
|
+
return null;
|
|
56520
|
+
}
|
|
56521
|
+
const isSharedAncestor = selected.every((item) => item.getId() === ancestorId || this.isAncestor(ancestor, item));
|
|
56522
|
+
if (!isSharedAncestor) {
|
|
56523
|
+
return null;
|
|
56524
|
+
}
|
|
56525
|
+
this.removeAll();
|
|
56526
|
+
this.add(ancestor);
|
|
56527
|
+
this.setContext("SelectUnderPointer");
|
|
56528
|
+
return ancestor;
|
|
56529
|
+
}
|
|
56406
56530
|
nestSelectedItems(unselectedItem, checkFrames = true) {
|
|
56407
56531
|
const selected = this.board.selection.items.list();
|
|
56408
56532
|
if (unselectedItem && !selected.find((item) => item.getId() === unselectedItem.getId())) {
|
package/dist/esm/browser.js
CHANGED
|
@@ -20902,8 +20902,8 @@ class SpatialIndex {
|
|
|
20902
20902
|
}
|
|
20903
20903
|
this.subject.publish(this.items);
|
|
20904
20904
|
};
|
|
20905
|
-
remove(item) {
|
|
20906
|
-
if ("index" in item && item.index) {
|
|
20905
|
+
remove(item, preserveChildren = false) {
|
|
20906
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
20907
20907
|
item.removeChildItems(item.index.list());
|
|
20908
20908
|
}
|
|
20909
20909
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -21143,6 +21143,9 @@ class SpatialIndex {
|
|
|
21143
21143
|
return false;
|
|
21144
21144
|
}
|
|
21145
21145
|
}
|
|
21146
|
+
if (item.itemType === "Group") {
|
|
21147
|
+
return false;
|
|
21148
|
+
}
|
|
21146
21149
|
return true;
|
|
21147
21150
|
});
|
|
21148
21151
|
return [...clearItems, ...children];
|
|
@@ -21464,8 +21467,8 @@ class SimpleSpatialIndex {
|
|
|
21464
21467
|
}
|
|
21465
21468
|
this.subject.publish(this.items);
|
|
21466
21469
|
};
|
|
21467
|
-
remove(item) {
|
|
21468
|
-
if ("index" in item && item.index) {
|
|
21470
|
+
remove(item, preserveChildren = false) {
|
|
21471
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
21469
21472
|
item.removeChildItems(item.index.list());
|
|
21470
21473
|
}
|
|
21471
21474
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -21848,7 +21851,7 @@ class BaseItem extends Mbr {
|
|
|
21848
21851
|
if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
|
|
21849
21852
|
if (!this.index?.getById(childId) && foundItem) {
|
|
21850
21853
|
const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
|
|
21851
|
-
this.board.items.index.remove(foundItem);
|
|
21854
|
+
this.board.items.index.remove(foundItem, true);
|
|
21852
21855
|
foundItem.parent = this.getId();
|
|
21853
21856
|
foundItem.onParentChanged(this.getId());
|
|
21854
21857
|
foundItem.transformation.setLocalMatrix(localMatrix);
|
|
@@ -21870,7 +21873,7 @@ class BaseItem extends Mbr {
|
|
|
21870
21873
|
if (this.parent !== childId && this.getId() !== childId) {
|
|
21871
21874
|
if (foundItem) {
|
|
21872
21875
|
const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
|
|
21873
|
-
this.index?.remove(foundItem);
|
|
21876
|
+
this.index?.remove(foundItem, true);
|
|
21874
21877
|
foundItem.parent = "Board";
|
|
21875
21878
|
foundItem.onParentChanged("Board");
|
|
21876
21879
|
foundItem.transformation.setLocalMatrix(worldMatrix);
|
|
@@ -47988,8 +47991,8 @@ class Tools extends ToolContext {
|
|
|
47988
47991
|
const zoomOffset = 25;
|
|
47989
47992
|
this.board.camera.zoomToFit(frameMbr, zoomOffset, 0);
|
|
47990
47993
|
this.board.selection.removeAll();
|
|
47991
|
-
this.board.selection.
|
|
47992
|
-
this.board.selection.
|
|
47994
|
+
this.board.selection.add(frames[newFrameIndex]);
|
|
47995
|
+
this.board.selection.setContext("SelectUnderPointer");
|
|
47993
47996
|
localStorage.setItem(`lastVisitedFrame`, frames[newFrameIndex].getId());
|
|
47994
47997
|
this.publish();
|
|
47995
47998
|
}
|
|
@@ -49139,9 +49142,9 @@ function createDeck(event, board) {
|
|
|
49139
49142
|
const deck = new Deck(board, "");
|
|
49140
49143
|
deck.transformation.setLocal(cardsOrDecks[cardsOrDecks.length - 1].left, cardsOrDecks[cardsOrDecks.length - 1].top);
|
|
49141
49144
|
const addedDeck = board.add(deck);
|
|
49142
|
-
board.selection.
|
|
49145
|
+
board.selection.removeAll();
|
|
49143
49146
|
addedDeck.addChildItems(cardsOrDecks);
|
|
49144
|
-
board.selection.
|
|
49147
|
+
board.selection.add(addedDeck);
|
|
49145
49148
|
} else {
|
|
49146
49149
|
let mainDeck = null;
|
|
49147
49150
|
const cards = [];
|
|
@@ -49158,9 +49161,9 @@ function createDeck(event, board) {
|
|
|
49158
49161
|
}
|
|
49159
49162
|
}
|
|
49160
49163
|
});
|
|
49161
|
-
board.selection.
|
|
49164
|
+
board.selection.removeAll();
|
|
49162
49165
|
mainDeck.addChildItems(cards);
|
|
49163
|
-
board.selection.
|
|
49166
|
+
board.selection.add(mainDeck);
|
|
49164
49167
|
}
|
|
49165
49168
|
}
|
|
49166
49169
|
registerHotkey({
|
|
@@ -53230,7 +53233,7 @@ class BoardSelection {
|
|
|
53230
53233
|
selectedItems.forEach((itemId) => {
|
|
53231
53234
|
const item = this.board.items.getById(itemId);
|
|
53232
53235
|
if (item) {
|
|
53233
|
-
this.
|
|
53236
|
+
this.add(item);
|
|
53234
53237
|
}
|
|
53235
53238
|
});
|
|
53236
53239
|
}
|
|
@@ -53317,13 +53320,22 @@ class BoardSelection {
|
|
|
53317
53320
|
};
|
|
53318
53321
|
decoratedItemObserver = this.decorateObserverToScheduleUpdate(this.itemObserver);
|
|
53319
53322
|
add(value) {
|
|
53320
|
-
|
|
53321
|
-
|
|
53322
|
-
|
|
53323
|
-
|
|
53324
|
-
|
|
53325
|
-
|
|
53326
|
-
|
|
53323
|
+
const values2 = Array.isArray(value) ? value : [value];
|
|
53324
|
+
const nextItems = this.normalizeSelectionItems([
|
|
53325
|
+
...this.items.list(),
|
|
53326
|
+
...values2
|
|
53327
|
+
]);
|
|
53328
|
+
const currentIds = new Set(this.items.ids());
|
|
53329
|
+
const nextIds = new Set(nextItems.map((item) => item.getId()));
|
|
53330
|
+
const removed = this.items.list().filter((item) => !nextIds.has(item.getId()));
|
|
53331
|
+
const added = nextItems.filter((item) => !currentIds.has(item.getId()));
|
|
53332
|
+
if (removed.length > 0) {
|
|
53333
|
+
this.items.remove(removed);
|
|
53334
|
+
removed.forEach((item) => item.subject.unsubscribe(this.itemObserver));
|
|
53335
|
+
}
|
|
53336
|
+
if (added.length > 0) {
|
|
53337
|
+
this.items.add(added);
|
|
53338
|
+
added.forEach((item) => item.subject.subscribe(this.itemObserver));
|
|
53327
53339
|
}
|
|
53328
53340
|
this.subject.publish(this);
|
|
53329
53341
|
this.itemsSubject.publish([]);
|
|
@@ -53403,15 +53415,54 @@ class BoardSelection {
|
|
|
53403
53415
|
if (!item) {
|
|
53404
53416
|
return null;
|
|
53405
53417
|
}
|
|
53406
|
-
if (
|
|
53407
|
-
return
|
|
53408
|
-
}
|
|
53409
|
-
const parent = this.board.items.getById(item.parent);
|
|
53410
|
-
if (parent instanceof Group) {
|
|
53411
|
-
return parent;
|
|
53418
|
+
if (item instanceof Group) {
|
|
53419
|
+
return null;
|
|
53412
53420
|
}
|
|
53413
53421
|
return item;
|
|
53414
53422
|
}
|
|
53423
|
+
getParentItem(item) {
|
|
53424
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
53425
|
+
if (!resolved || !(resolved instanceof BaseItem) || resolved.parent === "Board") {
|
|
53426
|
+
return null;
|
|
53427
|
+
}
|
|
53428
|
+
return this.board.items.getById(resolved.parent) || null;
|
|
53429
|
+
}
|
|
53430
|
+
isAncestor(candidate, descendant) {
|
|
53431
|
+
if (!(descendant instanceof BaseItem)) {
|
|
53432
|
+
return false;
|
|
53433
|
+
}
|
|
53434
|
+
let parentId = descendant.parent;
|
|
53435
|
+
while (parentId && parentId !== "Board") {
|
|
53436
|
+
if (parentId === candidate.getId()) {
|
|
53437
|
+
return true;
|
|
53438
|
+
}
|
|
53439
|
+
const parent = this.board.items.getById(parentId);
|
|
53440
|
+
if (!parent || parent.parent === parentId) {
|
|
53441
|
+
return false;
|
|
53442
|
+
}
|
|
53443
|
+
parentId = parent.parent;
|
|
53444
|
+
}
|
|
53445
|
+
return false;
|
|
53446
|
+
}
|
|
53447
|
+
normalizeSelectionItems(items) {
|
|
53448
|
+
const normalized = [];
|
|
53449
|
+
for (const item of items) {
|
|
53450
|
+
const alreadyCovered = normalized.some((selected) => selected.getId() === item.getId() || this.isAncestor(selected, item));
|
|
53451
|
+
if (alreadyCovered) {
|
|
53452
|
+
continue;
|
|
53453
|
+
}
|
|
53454
|
+
for (let i = normalized.length - 1;i >= 0; i -= 1) {
|
|
53455
|
+
if (this.isAncestor(item, normalized[i])) {
|
|
53456
|
+
normalized.splice(i, 1);
|
|
53457
|
+
}
|
|
53458
|
+
}
|
|
53459
|
+
normalized.push(item);
|
|
53460
|
+
}
|
|
53461
|
+
return normalized;
|
|
53462
|
+
}
|
|
53463
|
+
getCanvasSelectableItems(items) {
|
|
53464
|
+
return items.filter((item) => !(item instanceof Group));
|
|
53465
|
+
}
|
|
53415
53466
|
selectUnderPointer() {
|
|
53416
53467
|
this.removeAll();
|
|
53417
53468
|
const stack = this.board.items.getUnderPointer();
|
|
@@ -53549,7 +53600,7 @@ class BoardSelection {
|
|
|
53549
53600
|
}
|
|
53550
53601
|
selectEnclosedBy(rect) {
|
|
53551
53602
|
this.removeAll();
|
|
53552
|
-
const list6 = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom);
|
|
53603
|
+
const list6 = this.getCanvasSelectableItems(this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom));
|
|
53553
53604
|
if (list6.length !== 0) {
|
|
53554
53605
|
this.add(list6);
|
|
53555
53606
|
this.setContext("SelectByRect");
|
|
@@ -53560,7 +53611,7 @@ class BoardSelection {
|
|
|
53560
53611
|
selectEnclosedOrCrossedBy(rect) {
|
|
53561
53612
|
this.removeAll();
|
|
53562
53613
|
const enclosedFrames = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => !item.transformation.isLocked);
|
|
53563
|
-
const list6 = this.board.items.getEnclosedOrCrossed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => (!(item instanceof Frame2) || enclosedFrames.includes(item)) && !item.transformation.isLocked);
|
|
53614
|
+
const list6 = this.getCanvasSelectableItems(this.board.items.getEnclosedOrCrossed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => (!(item instanceof Frame2) || enclosedFrames.includes(item)) && !item.transformation.isLocked));
|
|
53564
53615
|
if (list6.length !== 0) {
|
|
53565
53616
|
this.add(list6);
|
|
53566
53617
|
this.setContext("SelectByRect");
|
|
@@ -53759,6 +53810,79 @@ class BoardSelection {
|
|
|
53759
53810
|
}
|
|
53760
53811
|
return this.textToEdit;
|
|
53761
53812
|
}
|
|
53813
|
+
getParent(item) {
|
|
53814
|
+
return this.getParentItem(item);
|
|
53815
|
+
}
|
|
53816
|
+
getParentChain(item) {
|
|
53817
|
+
const chain = [];
|
|
53818
|
+
let parent = this.getParentItem(item);
|
|
53819
|
+
while (parent) {
|
|
53820
|
+
chain.push(parent);
|
|
53821
|
+
parent = this.getParentItem(parent);
|
|
53822
|
+
}
|
|
53823
|
+
return chain;
|
|
53824
|
+
}
|
|
53825
|
+
getHierarchyPath(item) {
|
|
53826
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
53827
|
+
if (!resolved) {
|
|
53828
|
+
return [];
|
|
53829
|
+
}
|
|
53830
|
+
const nodes = [...this.getParentChain(resolved).reverse(), resolved];
|
|
53831
|
+
return nodes.filter((node2) => node2 instanceof BaseItem).map((node2) => ({
|
|
53832
|
+
id: node2.getId(),
|
|
53833
|
+
itemType: node2.itemType,
|
|
53834
|
+
parentId: node2.parent === "Board" ? null : node2.parent,
|
|
53835
|
+
hasChildren: (node2.getChildrenIds()?.length || 0) > 0,
|
|
53836
|
+
isCanvasSelectable: !(node2 instanceof Group)
|
|
53837
|
+
}));
|
|
53838
|
+
}
|
|
53839
|
+
getSelectionHierarchyPaths() {
|
|
53840
|
+
return this.items.list().map((item) => this.getHierarchyPath(item));
|
|
53841
|
+
}
|
|
53842
|
+
getCommonParent() {
|
|
53843
|
+
const selected = this.items.list();
|
|
53844
|
+
if (selected.length === 0) {
|
|
53845
|
+
return null;
|
|
53846
|
+
}
|
|
53847
|
+
const firstParent = this.getParentItem(selected[0]);
|
|
53848
|
+
if (!firstParent) {
|
|
53849
|
+
return null;
|
|
53850
|
+
}
|
|
53851
|
+
const firstParentId = firstParent.getId();
|
|
53852
|
+
const hasSameParent = selected.every((item) => this.getParentItem(item)?.getId() === firstParentId);
|
|
53853
|
+
return hasSameParent ? firstParent : null;
|
|
53854
|
+
}
|
|
53855
|
+
canPromoteSelectionToParent() {
|
|
53856
|
+
return this.getCommonParent() !== null;
|
|
53857
|
+
}
|
|
53858
|
+
selectParent() {
|
|
53859
|
+
const parent = this.getCommonParent();
|
|
53860
|
+
if (!parent) {
|
|
53861
|
+
return null;
|
|
53862
|
+
}
|
|
53863
|
+
this.removeAll();
|
|
53864
|
+
this.add(parent);
|
|
53865
|
+
this.setContext("SelectUnderPointer");
|
|
53866
|
+
return parent;
|
|
53867
|
+
}
|
|
53868
|
+
selectAncestorById(ancestorId) {
|
|
53869
|
+
const selected = this.items.list();
|
|
53870
|
+
if (selected.length === 0) {
|
|
53871
|
+
return null;
|
|
53872
|
+
}
|
|
53873
|
+
const ancestor = this.board.items.getById(ancestorId);
|
|
53874
|
+
if (!(ancestor instanceof BaseItem)) {
|
|
53875
|
+
return null;
|
|
53876
|
+
}
|
|
53877
|
+
const isSharedAncestor = selected.every((item) => item.getId() === ancestorId || this.isAncestor(ancestor, item));
|
|
53878
|
+
if (!isSharedAncestor) {
|
|
53879
|
+
return null;
|
|
53880
|
+
}
|
|
53881
|
+
this.removeAll();
|
|
53882
|
+
this.add(ancestor);
|
|
53883
|
+
this.setContext("SelectUnderPointer");
|
|
53884
|
+
return ancestor;
|
|
53885
|
+
}
|
|
53762
53886
|
nestSelectedItems(unselectedItem, checkFrames = true) {
|
|
53763
53887
|
const selected = this.board.selection.items.list();
|
|
53764
53888
|
if (unselectedItem && !selected.find((item) => item.getId() === unselectedItem.getId())) {
|