microboard-temp 0.13.36 → 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/esm/index.js
CHANGED
|
@@ -20895,8 +20895,8 @@ class SpatialIndex {
|
|
|
20895
20895
|
}
|
|
20896
20896
|
this.subject.publish(this.items);
|
|
20897
20897
|
};
|
|
20898
|
-
remove(item) {
|
|
20899
|
-
if ("index" in item && item.index) {
|
|
20898
|
+
remove(item, preserveChildren = false) {
|
|
20899
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
20900
20900
|
item.removeChildItems(item.index.list());
|
|
20901
20901
|
}
|
|
20902
20902
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -21136,6 +21136,9 @@ class SpatialIndex {
|
|
|
21136
21136
|
return false;
|
|
21137
21137
|
}
|
|
21138
21138
|
}
|
|
21139
|
+
if (item.itemType === "Group") {
|
|
21140
|
+
return false;
|
|
21141
|
+
}
|
|
21139
21142
|
return true;
|
|
21140
21143
|
});
|
|
21141
21144
|
return [...clearItems, ...children];
|
|
@@ -21457,8 +21460,8 @@ class SimpleSpatialIndex {
|
|
|
21457
21460
|
}
|
|
21458
21461
|
this.subject.publish(this.items);
|
|
21459
21462
|
};
|
|
21460
|
-
remove(item) {
|
|
21461
|
-
if ("index" in item && item.index) {
|
|
21463
|
+
remove(item, preserveChildren = false) {
|
|
21464
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
21462
21465
|
item.removeChildItems(item.index.list());
|
|
21463
21466
|
}
|
|
21464
21467
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -21841,7 +21844,7 @@ class BaseItem extends Mbr {
|
|
|
21841
21844
|
if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
|
|
21842
21845
|
if (!this.index?.getById(childId) && foundItem) {
|
|
21843
21846
|
const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
|
|
21844
|
-
this.board.items.index.remove(foundItem);
|
|
21847
|
+
this.board.items.index.remove(foundItem, true);
|
|
21845
21848
|
foundItem.parent = this.getId();
|
|
21846
21849
|
foundItem.onParentChanged(this.getId());
|
|
21847
21850
|
foundItem.transformation.setLocalMatrix(localMatrix);
|
|
@@ -21863,7 +21866,7 @@ class BaseItem extends Mbr {
|
|
|
21863
21866
|
if (this.parent !== childId && this.getId() !== childId) {
|
|
21864
21867
|
if (foundItem) {
|
|
21865
21868
|
const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
|
|
21866
|
-
this.index?.remove(foundItem);
|
|
21869
|
+
this.index?.remove(foundItem, true);
|
|
21867
21870
|
foundItem.parent = "Board";
|
|
21868
21871
|
foundItem.onParentChanged("Board");
|
|
21869
21872
|
foundItem.transformation.setLocalMatrix(worldMatrix);
|
|
@@ -47981,8 +47984,8 @@ class Tools extends ToolContext {
|
|
|
47981
47984
|
const zoomOffset = 25;
|
|
47982
47985
|
this.board.camera.zoomToFit(frameMbr, zoomOffset, 0);
|
|
47983
47986
|
this.board.selection.removeAll();
|
|
47984
|
-
this.board.selection.
|
|
47985
|
-
this.board.selection.
|
|
47987
|
+
this.board.selection.add(frames[newFrameIndex]);
|
|
47988
|
+
this.board.selection.setContext("SelectUnderPointer");
|
|
47986
47989
|
localStorage.setItem(`lastVisitedFrame`, frames[newFrameIndex].getId());
|
|
47987
47990
|
this.publish();
|
|
47988
47991
|
}
|
|
@@ -49132,9 +49135,9 @@ function createDeck(event, board) {
|
|
|
49132
49135
|
const deck = new Deck(board, "");
|
|
49133
49136
|
deck.transformation.setLocal(cardsOrDecks[cardsOrDecks.length - 1].left, cardsOrDecks[cardsOrDecks.length - 1].top);
|
|
49134
49137
|
const addedDeck = board.add(deck);
|
|
49135
|
-
board.selection.
|
|
49138
|
+
board.selection.removeAll();
|
|
49136
49139
|
addedDeck.addChildItems(cardsOrDecks);
|
|
49137
|
-
board.selection.
|
|
49140
|
+
board.selection.add(addedDeck);
|
|
49138
49141
|
} else {
|
|
49139
49142
|
let mainDeck = null;
|
|
49140
49143
|
const cards = [];
|
|
@@ -49151,9 +49154,9 @@ function createDeck(event, board) {
|
|
|
49151
49154
|
}
|
|
49152
49155
|
}
|
|
49153
49156
|
});
|
|
49154
|
-
board.selection.
|
|
49157
|
+
board.selection.removeAll();
|
|
49155
49158
|
mainDeck.addChildItems(cards);
|
|
49156
|
-
board.selection.
|
|
49159
|
+
board.selection.add(mainDeck);
|
|
49157
49160
|
}
|
|
49158
49161
|
}
|
|
49159
49162
|
registerHotkey({
|
|
@@ -53223,7 +53226,7 @@ class BoardSelection {
|
|
|
53223
53226
|
selectedItems.forEach((itemId) => {
|
|
53224
53227
|
const item = this.board.items.getById(itemId);
|
|
53225
53228
|
if (item) {
|
|
53226
|
-
this.
|
|
53229
|
+
this.add(item);
|
|
53227
53230
|
}
|
|
53228
53231
|
});
|
|
53229
53232
|
}
|
|
@@ -53310,13 +53313,22 @@ class BoardSelection {
|
|
|
53310
53313
|
};
|
|
53311
53314
|
decoratedItemObserver = this.decorateObserverToScheduleUpdate(this.itemObserver);
|
|
53312
53315
|
add(value) {
|
|
53313
|
-
|
|
53314
|
-
|
|
53315
|
-
|
|
53316
|
-
|
|
53317
|
-
|
|
53318
|
-
|
|
53319
|
-
|
|
53316
|
+
const values2 = Array.isArray(value) ? value : [value];
|
|
53317
|
+
const nextItems = this.normalizeSelectionItems([
|
|
53318
|
+
...this.items.list(),
|
|
53319
|
+
...values2
|
|
53320
|
+
]);
|
|
53321
|
+
const currentIds = new Set(this.items.ids());
|
|
53322
|
+
const nextIds = new Set(nextItems.map((item) => item.getId()));
|
|
53323
|
+
const removed = this.items.list().filter((item) => !nextIds.has(item.getId()));
|
|
53324
|
+
const added = nextItems.filter((item) => !currentIds.has(item.getId()));
|
|
53325
|
+
if (removed.length > 0) {
|
|
53326
|
+
this.items.remove(removed);
|
|
53327
|
+
removed.forEach((item) => item.subject.unsubscribe(this.itemObserver));
|
|
53328
|
+
}
|
|
53329
|
+
if (added.length > 0) {
|
|
53330
|
+
this.items.add(added);
|
|
53331
|
+
added.forEach((item) => item.subject.subscribe(this.itemObserver));
|
|
53320
53332
|
}
|
|
53321
53333
|
this.subject.publish(this);
|
|
53322
53334
|
this.itemsSubject.publish([]);
|
|
@@ -53396,15 +53408,54 @@ class BoardSelection {
|
|
|
53396
53408
|
if (!item) {
|
|
53397
53409
|
return null;
|
|
53398
53410
|
}
|
|
53399
|
-
if (
|
|
53400
|
-
return
|
|
53401
|
-
}
|
|
53402
|
-
const parent = this.board.items.getById(item.parent);
|
|
53403
|
-
if (parent instanceof Group) {
|
|
53404
|
-
return parent;
|
|
53411
|
+
if (item instanceof Group) {
|
|
53412
|
+
return null;
|
|
53405
53413
|
}
|
|
53406
53414
|
return item;
|
|
53407
53415
|
}
|
|
53416
|
+
getParentItem(item) {
|
|
53417
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
53418
|
+
if (!resolved || !(resolved instanceof BaseItem) || resolved.parent === "Board") {
|
|
53419
|
+
return null;
|
|
53420
|
+
}
|
|
53421
|
+
return this.board.items.getById(resolved.parent) || null;
|
|
53422
|
+
}
|
|
53423
|
+
isAncestor(candidate, descendant) {
|
|
53424
|
+
if (!(descendant instanceof BaseItem)) {
|
|
53425
|
+
return false;
|
|
53426
|
+
}
|
|
53427
|
+
let parentId = descendant.parent;
|
|
53428
|
+
while (parentId && parentId !== "Board") {
|
|
53429
|
+
if (parentId === candidate.getId()) {
|
|
53430
|
+
return true;
|
|
53431
|
+
}
|
|
53432
|
+
const parent = this.board.items.getById(parentId);
|
|
53433
|
+
if (!parent || parent.parent === parentId) {
|
|
53434
|
+
return false;
|
|
53435
|
+
}
|
|
53436
|
+
parentId = parent.parent;
|
|
53437
|
+
}
|
|
53438
|
+
return false;
|
|
53439
|
+
}
|
|
53440
|
+
normalizeSelectionItems(items) {
|
|
53441
|
+
const normalized = [];
|
|
53442
|
+
for (const item of items) {
|
|
53443
|
+
const alreadyCovered = normalized.some((selected) => selected.getId() === item.getId() || this.isAncestor(selected, item));
|
|
53444
|
+
if (alreadyCovered) {
|
|
53445
|
+
continue;
|
|
53446
|
+
}
|
|
53447
|
+
for (let i = normalized.length - 1;i >= 0; i -= 1) {
|
|
53448
|
+
if (this.isAncestor(item, normalized[i])) {
|
|
53449
|
+
normalized.splice(i, 1);
|
|
53450
|
+
}
|
|
53451
|
+
}
|
|
53452
|
+
normalized.push(item);
|
|
53453
|
+
}
|
|
53454
|
+
return normalized;
|
|
53455
|
+
}
|
|
53456
|
+
getCanvasSelectableItems(items) {
|
|
53457
|
+
return items.filter((item) => !(item instanceof Group));
|
|
53458
|
+
}
|
|
53408
53459
|
selectUnderPointer() {
|
|
53409
53460
|
this.removeAll();
|
|
53410
53461
|
const stack = this.board.items.getUnderPointer();
|
|
@@ -53542,7 +53593,7 @@ class BoardSelection {
|
|
|
53542
53593
|
}
|
|
53543
53594
|
selectEnclosedBy(rect) {
|
|
53544
53595
|
this.removeAll();
|
|
53545
|
-
const list6 = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom);
|
|
53596
|
+
const list6 = this.getCanvasSelectableItems(this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom));
|
|
53546
53597
|
if (list6.length !== 0) {
|
|
53547
53598
|
this.add(list6);
|
|
53548
53599
|
this.setContext("SelectByRect");
|
|
@@ -53553,7 +53604,7 @@ class BoardSelection {
|
|
|
53553
53604
|
selectEnclosedOrCrossedBy(rect) {
|
|
53554
53605
|
this.removeAll();
|
|
53555
53606
|
const enclosedFrames = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => !item.transformation.isLocked);
|
|
53556
|
-
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);
|
|
53607
|
+
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));
|
|
53557
53608
|
if (list6.length !== 0) {
|
|
53558
53609
|
this.add(list6);
|
|
53559
53610
|
this.setContext("SelectByRect");
|
|
@@ -53752,6 +53803,79 @@ class BoardSelection {
|
|
|
53752
53803
|
}
|
|
53753
53804
|
return this.textToEdit;
|
|
53754
53805
|
}
|
|
53806
|
+
getParent(item) {
|
|
53807
|
+
return this.getParentItem(item);
|
|
53808
|
+
}
|
|
53809
|
+
getParentChain(item) {
|
|
53810
|
+
const chain = [];
|
|
53811
|
+
let parent = this.getParentItem(item);
|
|
53812
|
+
while (parent) {
|
|
53813
|
+
chain.push(parent);
|
|
53814
|
+
parent = this.getParentItem(parent);
|
|
53815
|
+
}
|
|
53816
|
+
return chain;
|
|
53817
|
+
}
|
|
53818
|
+
getHierarchyPath(item) {
|
|
53819
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
53820
|
+
if (!resolved) {
|
|
53821
|
+
return [];
|
|
53822
|
+
}
|
|
53823
|
+
const nodes = [...this.getParentChain(resolved).reverse(), resolved];
|
|
53824
|
+
return nodes.filter((node2) => node2 instanceof BaseItem).map((node2) => ({
|
|
53825
|
+
id: node2.getId(),
|
|
53826
|
+
itemType: node2.itemType,
|
|
53827
|
+
parentId: node2.parent === "Board" ? null : node2.parent,
|
|
53828
|
+
hasChildren: (node2.getChildrenIds()?.length || 0) > 0,
|
|
53829
|
+
isCanvasSelectable: !(node2 instanceof Group)
|
|
53830
|
+
}));
|
|
53831
|
+
}
|
|
53832
|
+
getSelectionHierarchyPaths() {
|
|
53833
|
+
return this.items.list().map((item) => this.getHierarchyPath(item));
|
|
53834
|
+
}
|
|
53835
|
+
getCommonParent() {
|
|
53836
|
+
const selected = this.items.list();
|
|
53837
|
+
if (selected.length === 0) {
|
|
53838
|
+
return null;
|
|
53839
|
+
}
|
|
53840
|
+
const firstParent = this.getParentItem(selected[0]);
|
|
53841
|
+
if (!firstParent) {
|
|
53842
|
+
return null;
|
|
53843
|
+
}
|
|
53844
|
+
const firstParentId = firstParent.getId();
|
|
53845
|
+
const hasSameParent = selected.every((item) => this.getParentItem(item)?.getId() === firstParentId);
|
|
53846
|
+
return hasSameParent ? firstParent : null;
|
|
53847
|
+
}
|
|
53848
|
+
canPromoteSelectionToParent() {
|
|
53849
|
+
return this.getCommonParent() !== null;
|
|
53850
|
+
}
|
|
53851
|
+
selectParent() {
|
|
53852
|
+
const parent = this.getCommonParent();
|
|
53853
|
+
if (!parent) {
|
|
53854
|
+
return null;
|
|
53855
|
+
}
|
|
53856
|
+
this.removeAll();
|
|
53857
|
+
this.add(parent);
|
|
53858
|
+
this.setContext("SelectUnderPointer");
|
|
53859
|
+
return parent;
|
|
53860
|
+
}
|
|
53861
|
+
selectAncestorById(ancestorId) {
|
|
53862
|
+
const selected = this.items.list();
|
|
53863
|
+
if (selected.length === 0) {
|
|
53864
|
+
return null;
|
|
53865
|
+
}
|
|
53866
|
+
const ancestor = this.board.items.getById(ancestorId);
|
|
53867
|
+
if (!(ancestor instanceof BaseItem)) {
|
|
53868
|
+
return null;
|
|
53869
|
+
}
|
|
53870
|
+
const isSharedAncestor = selected.every((item) => item.getId() === ancestorId || this.isAncestor(ancestor, item));
|
|
53871
|
+
if (!isSharedAncestor) {
|
|
53872
|
+
return null;
|
|
53873
|
+
}
|
|
53874
|
+
this.removeAll();
|
|
53875
|
+
this.add(ancestor);
|
|
53876
|
+
this.setContext("SelectUnderPointer");
|
|
53877
|
+
return ancestor;
|
|
53878
|
+
}
|
|
53755
53879
|
nestSelectedItems(unselectedItem, checkFrames = true) {
|
|
53756
53880
|
const selected = this.board.selection.items.list();
|
|
53757
53881
|
if (unselectedItem && !selected.find((item) => item.getId() === unselectedItem.getId())) {
|
package/dist/esm/node.js
CHANGED
|
@@ -23362,8 +23362,8 @@ class SpatialIndex {
|
|
|
23362
23362
|
}
|
|
23363
23363
|
this.subject.publish(this.items);
|
|
23364
23364
|
};
|
|
23365
|
-
remove(item) {
|
|
23366
|
-
if ("index" in item && item.index) {
|
|
23365
|
+
remove(item, preserveChildren = false) {
|
|
23366
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
23367
23367
|
item.removeChildItems(item.index.list());
|
|
23368
23368
|
}
|
|
23369
23369
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -23603,6 +23603,9 @@ class SpatialIndex {
|
|
|
23603
23603
|
return false;
|
|
23604
23604
|
}
|
|
23605
23605
|
}
|
|
23606
|
+
if (item.itemType === "Group") {
|
|
23607
|
+
return false;
|
|
23608
|
+
}
|
|
23606
23609
|
return true;
|
|
23607
23610
|
});
|
|
23608
23611
|
return [...clearItems, ...children];
|
|
@@ -23924,8 +23927,8 @@ class SimpleSpatialIndex {
|
|
|
23924
23927
|
}
|
|
23925
23928
|
this.subject.publish(this.items);
|
|
23926
23929
|
};
|
|
23927
|
-
remove(item) {
|
|
23928
|
-
if ("index" in item && item.index) {
|
|
23930
|
+
remove(item, preserveChildren = false) {
|
|
23931
|
+
if (!preserveChildren && "index" in item && item.index) {
|
|
23929
23932
|
item.removeChildItems(item.index.list());
|
|
23930
23933
|
}
|
|
23931
23934
|
this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
|
|
@@ -24308,7 +24311,7 @@ class BaseItem extends Mbr {
|
|
|
24308
24311
|
if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
|
|
24309
24312
|
if (!this.index?.getById(childId) && foundItem) {
|
|
24310
24313
|
const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
|
|
24311
|
-
this.board.items.index.remove(foundItem);
|
|
24314
|
+
this.board.items.index.remove(foundItem, true);
|
|
24312
24315
|
foundItem.parent = this.getId();
|
|
24313
24316
|
foundItem.onParentChanged(this.getId());
|
|
24314
24317
|
foundItem.transformation.setLocalMatrix(localMatrix);
|
|
@@ -24330,7 +24333,7 @@ class BaseItem extends Mbr {
|
|
|
24330
24333
|
if (this.parent !== childId && this.getId() !== childId) {
|
|
24331
24334
|
if (foundItem) {
|
|
24332
24335
|
const worldMatrix = foundItem.transformation.toMatrix().composeWith(containerNestingMatrix);
|
|
24333
|
-
this.index?.remove(foundItem);
|
|
24336
|
+
this.index?.remove(foundItem, true);
|
|
24334
24337
|
foundItem.parent = "Board";
|
|
24335
24338
|
foundItem.onParentChanged("Board");
|
|
24336
24339
|
foundItem.transformation.setLocalMatrix(worldMatrix);
|
|
@@ -50449,8 +50452,8 @@ class Tools extends ToolContext {
|
|
|
50449
50452
|
const zoomOffset = 25;
|
|
50450
50453
|
this.board.camera.zoomToFit(frameMbr, zoomOffset, 0);
|
|
50451
50454
|
this.board.selection.removeAll();
|
|
50452
|
-
this.board.selection.
|
|
50453
|
-
this.board.selection.
|
|
50455
|
+
this.board.selection.add(frames[newFrameIndex]);
|
|
50456
|
+
this.board.selection.setContext("SelectUnderPointer");
|
|
50454
50457
|
localStorage.setItem(`lastVisitedFrame`, frames[newFrameIndex].getId());
|
|
50455
50458
|
this.publish();
|
|
50456
50459
|
}
|
|
@@ -51600,9 +51603,9 @@ function createDeck(event, board) {
|
|
|
51600
51603
|
const deck = new Deck(board, "");
|
|
51601
51604
|
deck.transformation.setLocal(cardsOrDecks[cardsOrDecks.length - 1].left, cardsOrDecks[cardsOrDecks.length - 1].top);
|
|
51602
51605
|
const addedDeck = board.add(deck);
|
|
51603
|
-
board.selection.
|
|
51606
|
+
board.selection.removeAll();
|
|
51604
51607
|
addedDeck.addChildItems(cardsOrDecks);
|
|
51605
|
-
board.selection.
|
|
51608
|
+
board.selection.add(addedDeck);
|
|
51606
51609
|
} else {
|
|
51607
51610
|
let mainDeck = null;
|
|
51608
51611
|
const cards = [];
|
|
@@ -51619,9 +51622,9 @@ function createDeck(event, board) {
|
|
|
51619
51622
|
}
|
|
51620
51623
|
}
|
|
51621
51624
|
});
|
|
51622
|
-
board.selection.
|
|
51625
|
+
board.selection.removeAll();
|
|
51623
51626
|
mainDeck.addChildItems(cards);
|
|
51624
|
-
board.selection.
|
|
51627
|
+
board.selection.add(mainDeck);
|
|
51625
51628
|
}
|
|
51626
51629
|
}
|
|
51627
51630
|
registerHotkey({
|
|
@@ -55691,7 +55694,7 @@ class BoardSelection {
|
|
|
55691
55694
|
selectedItems.forEach((itemId) => {
|
|
55692
55695
|
const item = this.board.items.getById(itemId);
|
|
55693
55696
|
if (item) {
|
|
55694
|
-
this.
|
|
55697
|
+
this.add(item);
|
|
55695
55698
|
}
|
|
55696
55699
|
});
|
|
55697
55700
|
}
|
|
@@ -55778,13 +55781,22 @@ class BoardSelection {
|
|
|
55778
55781
|
};
|
|
55779
55782
|
decoratedItemObserver = this.decorateObserverToScheduleUpdate(this.itemObserver);
|
|
55780
55783
|
add(value) {
|
|
55781
|
-
|
|
55782
|
-
|
|
55783
|
-
|
|
55784
|
-
|
|
55785
|
-
|
|
55786
|
-
|
|
55787
|
-
|
|
55784
|
+
const values2 = Array.isArray(value) ? value : [value];
|
|
55785
|
+
const nextItems = this.normalizeSelectionItems([
|
|
55786
|
+
...this.items.list(),
|
|
55787
|
+
...values2
|
|
55788
|
+
]);
|
|
55789
|
+
const currentIds = new Set(this.items.ids());
|
|
55790
|
+
const nextIds = new Set(nextItems.map((item) => item.getId()));
|
|
55791
|
+
const removed = this.items.list().filter((item) => !nextIds.has(item.getId()));
|
|
55792
|
+
const added = nextItems.filter((item) => !currentIds.has(item.getId()));
|
|
55793
|
+
if (removed.length > 0) {
|
|
55794
|
+
this.items.remove(removed);
|
|
55795
|
+
removed.forEach((item) => item.subject.unsubscribe(this.itemObserver));
|
|
55796
|
+
}
|
|
55797
|
+
if (added.length > 0) {
|
|
55798
|
+
this.items.add(added);
|
|
55799
|
+
added.forEach((item) => item.subject.subscribe(this.itemObserver));
|
|
55788
55800
|
}
|
|
55789
55801
|
this.subject.publish(this);
|
|
55790
55802
|
this.itemsSubject.publish([]);
|
|
@@ -55864,15 +55876,54 @@ class BoardSelection {
|
|
|
55864
55876
|
if (!item) {
|
|
55865
55877
|
return null;
|
|
55866
55878
|
}
|
|
55867
|
-
if (
|
|
55868
|
-
return
|
|
55869
|
-
}
|
|
55870
|
-
const parent = this.board.items.getById(item.parent);
|
|
55871
|
-
if (parent instanceof Group) {
|
|
55872
|
-
return parent;
|
|
55879
|
+
if (item instanceof Group) {
|
|
55880
|
+
return null;
|
|
55873
55881
|
}
|
|
55874
55882
|
return item;
|
|
55875
55883
|
}
|
|
55884
|
+
getParentItem(item) {
|
|
55885
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
55886
|
+
if (!resolved || !(resolved instanceof BaseItem) || resolved.parent === "Board") {
|
|
55887
|
+
return null;
|
|
55888
|
+
}
|
|
55889
|
+
return this.board.items.getById(resolved.parent) || null;
|
|
55890
|
+
}
|
|
55891
|
+
isAncestor(candidate, descendant) {
|
|
55892
|
+
if (!(descendant instanceof BaseItem)) {
|
|
55893
|
+
return false;
|
|
55894
|
+
}
|
|
55895
|
+
let parentId = descendant.parent;
|
|
55896
|
+
while (parentId && parentId !== "Board") {
|
|
55897
|
+
if (parentId === candidate.getId()) {
|
|
55898
|
+
return true;
|
|
55899
|
+
}
|
|
55900
|
+
const parent = this.board.items.getById(parentId);
|
|
55901
|
+
if (!parent || parent.parent === parentId) {
|
|
55902
|
+
return false;
|
|
55903
|
+
}
|
|
55904
|
+
parentId = parent.parent;
|
|
55905
|
+
}
|
|
55906
|
+
return false;
|
|
55907
|
+
}
|
|
55908
|
+
normalizeSelectionItems(items) {
|
|
55909
|
+
const normalized = [];
|
|
55910
|
+
for (const item of items) {
|
|
55911
|
+
const alreadyCovered = normalized.some((selected) => selected.getId() === item.getId() || this.isAncestor(selected, item));
|
|
55912
|
+
if (alreadyCovered) {
|
|
55913
|
+
continue;
|
|
55914
|
+
}
|
|
55915
|
+
for (let i = normalized.length - 1;i >= 0; i -= 1) {
|
|
55916
|
+
if (this.isAncestor(item, normalized[i])) {
|
|
55917
|
+
normalized.splice(i, 1);
|
|
55918
|
+
}
|
|
55919
|
+
}
|
|
55920
|
+
normalized.push(item);
|
|
55921
|
+
}
|
|
55922
|
+
return normalized;
|
|
55923
|
+
}
|
|
55924
|
+
getCanvasSelectableItems(items) {
|
|
55925
|
+
return items.filter((item) => !(item instanceof Group));
|
|
55926
|
+
}
|
|
55876
55927
|
selectUnderPointer() {
|
|
55877
55928
|
this.removeAll();
|
|
55878
55929
|
const stack = this.board.items.getUnderPointer();
|
|
@@ -56010,7 +56061,7 @@ class BoardSelection {
|
|
|
56010
56061
|
}
|
|
56011
56062
|
selectEnclosedBy(rect) {
|
|
56012
56063
|
this.removeAll();
|
|
56013
|
-
const list6 = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom);
|
|
56064
|
+
const list6 = this.getCanvasSelectableItems(this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom));
|
|
56014
56065
|
if (list6.length !== 0) {
|
|
56015
56066
|
this.add(list6);
|
|
56016
56067
|
this.setContext("SelectByRect");
|
|
@@ -56021,7 +56072,7 @@ class BoardSelection {
|
|
|
56021
56072
|
selectEnclosedOrCrossedBy(rect) {
|
|
56022
56073
|
this.removeAll();
|
|
56023
56074
|
const enclosedFrames = this.board.items.getEnclosed(rect.left, rect.top, rect.right, rect.bottom).filter((item) => !item.transformation.isLocked);
|
|
56024
|
-
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);
|
|
56075
|
+
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));
|
|
56025
56076
|
if (list6.length !== 0) {
|
|
56026
56077
|
this.add(list6);
|
|
56027
56078
|
this.setContext("SelectByRect");
|
|
@@ -56220,6 +56271,79 @@ class BoardSelection {
|
|
|
56220
56271
|
}
|
|
56221
56272
|
return this.textToEdit;
|
|
56222
56273
|
}
|
|
56274
|
+
getParent(item) {
|
|
56275
|
+
return this.getParentItem(item);
|
|
56276
|
+
}
|
|
56277
|
+
getParentChain(item) {
|
|
56278
|
+
const chain = [];
|
|
56279
|
+
let parent = this.getParentItem(item);
|
|
56280
|
+
while (parent) {
|
|
56281
|
+
chain.push(parent);
|
|
56282
|
+
parent = this.getParentItem(parent);
|
|
56283
|
+
}
|
|
56284
|
+
return chain;
|
|
56285
|
+
}
|
|
56286
|
+
getHierarchyPath(item) {
|
|
56287
|
+
const resolved = typeof item === "string" ? this.board.items.getById(item) : item || null;
|
|
56288
|
+
if (!resolved) {
|
|
56289
|
+
return [];
|
|
56290
|
+
}
|
|
56291
|
+
const nodes = [...this.getParentChain(resolved).reverse(), resolved];
|
|
56292
|
+
return nodes.filter((node2) => node2 instanceof BaseItem).map((node2) => ({
|
|
56293
|
+
id: node2.getId(),
|
|
56294
|
+
itemType: node2.itemType,
|
|
56295
|
+
parentId: node2.parent === "Board" ? null : node2.parent,
|
|
56296
|
+
hasChildren: (node2.getChildrenIds()?.length || 0) > 0,
|
|
56297
|
+
isCanvasSelectable: !(node2 instanceof Group)
|
|
56298
|
+
}));
|
|
56299
|
+
}
|
|
56300
|
+
getSelectionHierarchyPaths() {
|
|
56301
|
+
return this.items.list().map((item) => this.getHierarchyPath(item));
|
|
56302
|
+
}
|
|
56303
|
+
getCommonParent() {
|
|
56304
|
+
const selected = this.items.list();
|
|
56305
|
+
if (selected.length === 0) {
|
|
56306
|
+
return null;
|
|
56307
|
+
}
|
|
56308
|
+
const firstParent = this.getParentItem(selected[0]);
|
|
56309
|
+
if (!firstParent) {
|
|
56310
|
+
return null;
|
|
56311
|
+
}
|
|
56312
|
+
const firstParentId = firstParent.getId();
|
|
56313
|
+
const hasSameParent = selected.every((item) => this.getParentItem(item)?.getId() === firstParentId);
|
|
56314
|
+
return hasSameParent ? firstParent : null;
|
|
56315
|
+
}
|
|
56316
|
+
canPromoteSelectionToParent() {
|
|
56317
|
+
return this.getCommonParent() !== null;
|
|
56318
|
+
}
|
|
56319
|
+
selectParent() {
|
|
56320
|
+
const parent = this.getCommonParent();
|
|
56321
|
+
if (!parent) {
|
|
56322
|
+
return null;
|
|
56323
|
+
}
|
|
56324
|
+
this.removeAll();
|
|
56325
|
+
this.add(parent);
|
|
56326
|
+
this.setContext("SelectUnderPointer");
|
|
56327
|
+
return parent;
|
|
56328
|
+
}
|
|
56329
|
+
selectAncestorById(ancestorId) {
|
|
56330
|
+
const selected = this.items.list();
|
|
56331
|
+
if (selected.length === 0) {
|
|
56332
|
+
return null;
|
|
56333
|
+
}
|
|
56334
|
+
const ancestor = this.board.items.getById(ancestorId);
|
|
56335
|
+
if (!(ancestor instanceof BaseItem)) {
|
|
56336
|
+
return null;
|
|
56337
|
+
}
|
|
56338
|
+
const isSharedAncestor = selected.every((item) => item.getId() === ancestorId || this.isAncestor(ancestor, item));
|
|
56339
|
+
if (!isSharedAncestor) {
|
|
56340
|
+
return null;
|
|
56341
|
+
}
|
|
56342
|
+
this.removeAll();
|
|
56343
|
+
this.add(ancestor);
|
|
56344
|
+
this.setContext("SelectUnderPointer");
|
|
56345
|
+
return ancestor;
|
|
56346
|
+
}
|
|
56223
56347
|
nestSelectedItems(unselectedItem, checkFrames = true) {
|
|
56224
56348
|
const selected = this.board.selection.items.list();
|
|
56225
56349
|
if (unselectedItem && !selected.find((item) => item.getId() === unselectedItem.getId())) {
|
|
@@ -15,6 +15,7 @@ import { Tool } from "../Tools/Tool";
|
|
|
15
15
|
import { QuickAddButtons } from "./QuickAddButtons";
|
|
16
16
|
import { SelectionItems } from "./SelectionItems";
|
|
17
17
|
import { BaseSelection, BaseRange } from "slate";
|
|
18
|
+
import { BaseItem } from "../Items/BaseItem";
|
|
18
19
|
export type SelectionContext = "SelectUnderPointer" | "HoverUnderPointer" | "EditUnderPointer" | "EditTextUnderPointer" | "SelectByRect" | "None";
|
|
19
20
|
type SelectionSnapshot = {
|
|
20
21
|
selectedItems: string;
|
|
@@ -24,6 +25,13 @@ type SelectionSnapshot = {
|
|
|
24
25
|
textToEdit: string;
|
|
25
26
|
} | null;
|
|
26
27
|
};
|
|
28
|
+
export type SelectionHierarchyNode = {
|
|
29
|
+
id: string;
|
|
30
|
+
itemType: string;
|
|
31
|
+
parentId: string | null;
|
|
32
|
+
hasChildren: boolean;
|
|
33
|
+
isCanvasSelectable: boolean;
|
|
34
|
+
};
|
|
27
35
|
export declare class BoardSelection {
|
|
28
36
|
private board;
|
|
29
37
|
readonly subject: Subject<BoardSelection>;
|
|
@@ -67,6 +75,10 @@ export declare class BoardSelection {
|
|
|
67
75
|
setContext(context: SelectionContext): void;
|
|
68
76
|
getMbr(): Mbr | undefined;
|
|
69
77
|
getSelectableItem(item: Item | null | undefined): Item | null;
|
|
78
|
+
private getParentItem;
|
|
79
|
+
private isAncestor;
|
|
80
|
+
private normalizeSelectionItems;
|
|
81
|
+
private getCanvasSelectableItems;
|
|
70
82
|
selectUnderPointer(): void;
|
|
71
83
|
editSelected(): void;
|
|
72
84
|
editText(shouldReplace?: string, moveCursorToEnd?: boolean, shouldSelect?: boolean): void;
|
|
@@ -110,6 +122,14 @@ export declare class BoardSelection {
|
|
|
110
122
|
setConnectorLineStyle(style: ConnectorLineStyle): void;
|
|
111
123
|
getConnectorLineStyle(): string;
|
|
112
124
|
getTextToEdit(): RichText | undefined;
|
|
125
|
+
getParent(item: Item | string | null | undefined): BaseItem | null;
|
|
126
|
+
getParentChain(item: Item | string | null | undefined): BaseItem[];
|
|
127
|
+
getHierarchyPath(item: Item | string | null | undefined): SelectionHierarchyNode[];
|
|
128
|
+
getSelectionHierarchyPaths(): SelectionHierarchyNode[][];
|
|
129
|
+
getCommonParent(): BaseItem | null;
|
|
130
|
+
canPromoteSelectionToParent(): boolean;
|
|
131
|
+
selectParent(): BaseItem | null;
|
|
132
|
+
selectAncestorById(ancestorId: string): BaseItem | null;
|
|
113
133
|
nestSelectedItems(unselectedItem?: Item | null, checkFrames?: boolean): void;
|
|
114
134
|
/** Emits applyMatrix with multiple items */
|
|
115
135
|
transformMany(items: ApplyMatrixItem[], timeStamp?: number): void;
|
|
@@ -15,7 +15,7 @@ export declare class SimpleSpatialIndex {
|
|
|
15
15
|
clear(): void;
|
|
16
16
|
insert(item: Item): void;
|
|
17
17
|
change: (item: Item) => void;
|
|
18
|
-
remove(item: Item): void;
|
|
18
|
+
remove(item: Item, preserveChildren?: boolean): void;
|
|
19
19
|
copy(): ItemDataWithId[];
|
|
20
20
|
moveToZIndex(item: Item, zIndex: number): void;
|
|
21
21
|
moveManyToZIndex(itemsRecord: ItemsIndexRecord): void;
|
|
@@ -17,7 +17,7 @@ export declare class SpatialIndex {
|
|
|
17
17
|
clear(): void;
|
|
18
18
|
insert(item: Item): void;
|
|
19
19
|
change: (item: Item) => void;
|
|
20
|
-
remove(item: Item): void;
|
|
20
|
+
remove(item: Item, preserveChildren?: boolean): void;
|
|
21
21
|
copy(): ItemDataWithId[];
|
|
22
22
|
getItemsWithIncludedChildren(items: Item[]): Item[];
|
|
23
23
|
getItemChildren(item: Item): Item[];
|