fabric-vectr 6.7.14 → 6.7.16
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/index.js +90 -12
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +90 -12
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +90 -12
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +90 -12
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/canvas/Canvas.d.ts +10 -0
- package/dist/src/canvas/Canvas.d.ts.map +1 -1
- package/dist/src/canvas/Canvas.min.mjs +1 -1
- package/dist/src/canvas/Canvas.min.mjs.map +1 -1
- package/dist/src/canvas/Canvas.mjs +85 -10
- package/dist/src/canvas/Canvas.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.d.ts +6 -0
- package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.min.mjs +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs +4 -1
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist-extensions/src/canvas/Canvas.d.ts +10 -0
- package/dist-extensions/src/canvas/Canvas.d.ts.map +1 -1
- package/dist-extensions/src/canvas/SelectableCanvas.d.ts +6 -0
- package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/canvas/Canvas.ts +89 -8
- package/src/canvas/SelectableCanvas.ts +6 -0
- package/src/canvas/__tests__/additiveSelection.test.ts +118 -0
- package/src/shapes/Textbox.ts +4 -1
|
@@ -953,11 +953,16 @@ class Canvas extends SelectableCanvas {
|
|
|
953
953
|
shouldRender = true;
|
|
954
954
|
} else if (this._shouldClearSelection(e, target)) {
|
|
955
955
|
const objs = this.getActiveObjects();
|
|
956
|
-
|
|
957
|
-
//
|
|
958
|
-
objs.
|
|
959
|
-
if (!
|
|
960
|
-
|
|
956
|
+
// holding the selection key keeps the current selection alive so that the
|
|
957
|
+
// following box selection (or click) can add to it instead of replacing it
|
|
958
|
+
const additive = !!objs.length && !!this.selection && this._isSelectionKeyPressed(e);
|
|
959
|
+
if (!additive) {
|
|
960
|
+
this.discardActiveObject(e);
|
|
961
|
+
// 多选取消,重置Coords, 防止无法再次选中
|
|
962
|
+
objs.forEach(obj => obj.setCoords());
|
|
963
|
+
if (!target && this.switchIsolateObject(e)) {
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
961
966
|
}
|
|
962
967
|
}
|
|
963
968
|
// we start a group selector rectangle if
|
|
@@ -972,7 +977,12 @@ class Canvas extends SelectableCanvas {
|
|
|
972
977
|
x: p.x,
|
|
973
978
|
y: p.y,
|
|
974
979
|
deltaY: 0,
|
|
975
|
-
deltaX: 0
|
|
980
|
+
deltaX: 0,
|
|
981
|
+
// capture the modifier now: releasing the key during the drag
|
|
982
|
+
// must not turn an additive selection into a replacing one
|
|
983
|
+
...(this._isSelectionKeyPressed(e) ? {
|
|
984
|
+
additive: true
|
|
985
|
+
} : {})
|
|
976
986
|
};
|
|
977
987
|
}
|
|
978
988
|
|
|
@@ -1355,13 +1365,17 @@ class Canvas extends SelectableCanvas {
|
|
|
1355
1365
|
x,
|
|
1356
1366
|
y,
|
|
1357
1367
|
deltaX,
|
|
1358
|
-
deltaY
|
|
1368
|
+
deltaY,
|
|
1369
|
+
additive
|
|
1359
1370
|
} = this._groupSelector,
|
|
1360
1371
|
point1 = new Point(x, y),
|
|
1361
1372
|
point2 = point1.add(new Point(deltaX, deltaY)),
|
|
1362
1373
|
tl = point1.min(point2),
|
|
1363
1374
|
br = point1.max(point2),
|
|
1364
1375
|
size = br.subtract(tl);
|
|
1376
|
+
|
|
1377
|
+
// the box only collects the first level objects of the current selection scope,
|
|
1378
|
+
// meaning the children of the isolated group, or the canvas root objects
|
|
1365
1379
|
const collectedObjects = this.collectObjects(this.getSearchTargets(), {
|
|
1366
1380
|
left: tl.x,
|
|
1367
1381
|
top: tl.y,
|
|
@@ -1370,6 +1384,16 @@ class Canvas extends SelectableCanvas {
|
|
|
1370
1384
|
}, {
|
|
1371
1385
|
includeIntersecting: !this.selectionFullyContained
|
|
1372
1386
|
});
|
|
1387
|
+
|
|
1388
|
+
// cleanup
|
|
1389
|
+
this._groupSelector = null;
|
|
1390
|
+
|
|
1391
|
+
// the selection key was held while dragging and there is something to add to:
|
|
1392
|
+
// keep the current selection and merge the collected objects into it
|
|
1393
|
+
if (additive && this.getActiveObjects().length) {
|
|
1394
|
+
this.addToActiveSelection(e, collectedObjects);
|
|
1395
|
+
return true;
|
|
1396
|
+
}
|
|
1373
1397
|
const objects =
|
|
1374
1398
|
// though this method runs only after mouse move the pointer could do a mouse up on the same position as mouse down
|
|
1375
1399
|
// should it be handled as is?
|
|
@@ -1390,12 +1414,63 @@ class Canvas extends SelectableCanvas {
|
|
|
1390
1414
|
canvas: this
|
|
1391
1415
|
}), e);
|
|
1392
1416
|
}
|
|
1393
|
-
|
|
1394
|
-
// cleanup
|
|
1395
|
-
this._groupSelector = null;
|
|
1396
1417
|
return true;
|
|
1397
1418
|
}
|
|
1398
1419
|
|
|
1420
|
+
/**
|
|
1421
|
+
* Merges the objects collected by a box selection into the current selection.
|
|
1422
|
+
* Only objects belonging to the current selection scope are taken into account:
|
|
1423
|
+
* the first level children of the isolated group, or the canvas root objects
|
|
1424
|
+
* when no group is isolated. Previously selected objects outside of that scope
|
|
1425
|
+
* are removed from the selection, since a selection can't mix objects coming
|
|
1426
|
+
* from different containers.
|
|
1427
|
+
* @private
|
|
1428
|
+
*/
|
|
1429
|
+
addToActiveSelection(e, collectedObjects) {
|
|
1430
|
+
const prevActiveObjects = this.getActiveObjects(),
|
|
1431
|
+
scope = this.getSearchTargets(),
|
|
1432
|
+
kept = prevActiveObjects.filter(object => scope.includes(object)),
|
|
1433
|
+
dropped = prevActiveObjects.filter(object => !scope.includes(object)),
|
|
1434
|
+
added = collectedObjects.filter(object => !prevActiveObjects.includes(object) && !object.onSelect({
|
|
1435
|
+
e
|
|
1436
|
+
}));
|
|
1437
|
+
if (!kept.length && !added.length) {
|
|
1438
|
+
// the box didn't add anything and nothing of the current selection
|
|
1439
|
+
// belongs to this scope
|
|
1440
|
+
dropped.length && this.discardActiveObject(e);
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
const activeObject = this._activeObject;
|
|
1444
|
+
if (isActiveSelection(activeObject)) {
|
|
1445
|
+
dropped.length && activeObject.remove(...dropped);
|
|
1446
|
+
added.length && activeObject.multiSelectAdd(...added);
|
|
1447
|
+
if (activeObject.size() === 1) {
|
|
1448
|
+
// deselecting the active selection returns the last remaining object to the canvas
|
|
1449
|
+
this._setActiveObject(activeObject.item(0), e);
|
|
1450
|
+
}
|
|
1451
|
+
this._fireSelectionEvents(prevActiveObjects, e);
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
const objects = kept.concat(added);
|
|
1455
|
+
if (objects.length === 1) {
|
|
1456
|
+
objects[0] !== activeObject && this.setActiveObject(objects[0], e);
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
// build the active selection out of the kept and the newly collected objects
|
|
1461
|
+
const klass = classRegistry.getClass('ActiveSelection');
|
|
1462
|
+
const newActiveSelection = new klass([], {
|
|
1463
|
+
/**
|
|
1464
|
+
* it is crucial to pass the canvas ref before calling {@link ActiveSelection#multiSelectAdd}
|
|
1465
|
+
* since it uses {@link FabricObject#isInFrontOf} which relies on the canvas ref
|
|
1466
|
+
*/
|
|
1467
|
+
canvas: this
|
|
1468
|
+
});
|
|
1469
|
+
newActiveSelection.multiSelectAdd(...objects);
|
|
1470
|
+
this._setActiveObject(newActiveSelection, e);
|
|
1471
|
+
this._fireSelectionEvents(prevActiveObjects, e);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1399
1474
|
/**
|
|
1400
1475
|
* @override clear {@link textEditingManager}
|
|
1401
1476
|
*/
|