fabric-vectr 6.7.14 → 6.7.15

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 CHANGED
@@ -366,7 +366,7 @@
366
366
  }
367
367
  const cache = new Cache();
368
368
 
369
- var version = "6.7.14";
369
+ var version = "6.7.15";
370
370
 
371
371
  // use this syntax so babel plugin see this import here
372
372
  const VERSION = version;
@@ -15820,11 +15820,16 @@
15820
15820
  shouldRender = true;
15821
15821
  } else if (this._shouldClearSelection(e, target)) {
15822
15822
  const objs = this.getActiveObjects();
15823
- this.discardActiveObject(e);
15824
- // 多选取消,重置Coords, 防止无法再次选中
15825
- objs.forEach(obj => obj.setCoords());
15826
- if (!target && this.switchIsolateObject(e)) {
15827
- return;
15823
+ // holding the selection key keeps the current selection alive so that the
15824
+ // following box selection (or click) can add to it instead of replacing it
15825
+ const additive = !!objs.length && !!this.selection && this._isSelectionKeyPressed(e);
15826
+ if (!additive) {
15827
+ this.discardActiveObject(e);
15828
+ // 多选取消,重置Coords, 防止无法再次选中
15829
+ objs.forEach(obj => obj.setCoords());
15830
+ if (!target && this.switchIsolateObject(e)) {
15831
+ return;
15832
+ }
15828
15833
  }
15829
15834
  }
15830
15835
  // we start a group selector rectangle if
@@ -15839,7 +15844,12 @@
15839
15844
  x: p.x,
15840
15845
  y: p.y,
15841
15846
  deltaY: 0,
15842
- deltaX: 0
15847
+ deltaX: 0,
15848
+ // capture the modifier now: releasing the key during the drag
15849
+ // must not turn an additive selection into a replacing one
15850
+ ...(this._isSelectionKeyPressed(e) ? {
15851
+ additive: true
15852
+ } : {})
15843
15853
  };
15844
15854
  }
15845
15855
 
@@ -16222,13 +16232,17 @@
16222
16232
  x,
16223
16233
  y,
16224
16234
  deltaX,
16225
- deltaY
16235
+ deltaY,
16236
+ additive
16226
16237
  } = this._groupSelector,
16227
16238
  point1 = new Point(x, y),
16228
16239
  point2 = point1.add(new Point(deltaX, deltaY)),
16229
16240
  tl = point1.min(point2),
16230
16241
  br = point1.max(point2),
16231
16242
  size = br.subtract(tl);
16243
+
16244
+ // the box only collects the first level objects of the current selection scope,
16245
+ // meaning the children of the isolated group, or the canvas root objects
16232
16246
  const collectedObjects = this.collectObjects(this.getSearchTargets(), {
16233
16247
  left: tl.x,
16234
16248
  top: tl.y,
@@ -16237,6 +16251,16 @@
16237
16251
  }, {
16238
16252
  includeIntersecting: !this.selectionFullyContained
16239
16253
  });
16254
+
16255
+ // cleanup
16256
+ this._groupSelector = null;
16257
+
16258
+ // the selection key was held while dragging and there is something to add to:
16259
+ // keep the current selection and merge the collected objects into it
16260
+ if (additive && this.getActiveObjects().length) {
16261
+ this.addToActiveSelection(e, collectedObjects);
16262
+ return true;
16263
+ }
16240
16264
  const objects =
16241
16265
  // though this method runs only after mouse move the pointer could do a mouse up on the same position as mouse down
16242
16266
  // should it be handled as is?
@@ -16257,12 +16281,63 @@
16257
16281
  canvas: this
16258
16282
  }), e);
16259
16283
  }
16260
-
16261
- // cleanup
16262
- this._groupSelector = null;
16263
16284
  return true;
16264
16285
  }
16265
16286
 
16287
+ /**
16288
+ * Merges the objects collected by a box selection into the current selection.
16289
+ * Only objects belonging to the current selection scope are taken into account:
16290
+ * the first level children of the isolated group, or the canvas root objects
16291
+ * when no group is isolated. Previously selected objects outside of that scope
16292
+ * are removed from the selection, since a selection can't mix objects coming
16293
+ * from different containers.
16294
+ * @private
16295
+ */
16296
+ addToActiveSelection(e, collectedObjects) {
16297
+ const prevActiveObjects = this.getActiveObjects(),
16298
+ scope = this.getSearchTargets(),
16299
+ kept = prevActiveObjects.filter(object => scope.includes(object)),
16300
+ dropped = prevActiveObjects.filter(object => !scope.includes(object)),
16301
+ added = collectedObjects.filter(object => !prevActiveObjects.includes(object) && !object.onSelect({
16302
+ e
16303
+ }));
16304
+ if (!kept.length && !added.length) {
16305
+ // the box didn't add anything and nothing of the current selection
16306
+ // belongs to this scope
16307
+ dropped.length && this.discardActiveObject(e);
16308
+ return;
16309
+ }
16310
+ const activeObject = this._activeObject;
16311
+ if (isActiveSelection(activeObject)) {
16312
+ dropped.length && activeObject.remove(...dropped);
16313
+ added.length && activeObject.multiSelectAdd(...added);
16314
+ if (activeObject.size() === 1) {
16315
+ // deselecting the active selection returns the last remaining object to the canvas
16316
+ this._setActiveObject(activeObject.item(0), e);
16317
+ }
16318
+ this._fireSelectionEvents(prevActiveObjects, e);
16319
+ return;
16320
+ }
16321
+ const objects = kept.concat(added);
16322
+ if (objects.length === 1) {
16323
+ objects[0] !== activeObject && this.setActiveObject(objects[0], e);
16324
+ return;
16325
+ }
16326
+
16327
+ // build the active selection out of the kept and the newly collected objects
16328
+ const klass = classRegistry.getClass('ActiveSelection');
16329
+ const newActiveSelection = new klass([], {
16330
+ /**
16331
+ * it is crucial to pass the canvas ref before calling {@link ActiveSelection#multiSelectAdd}
16332
+ * since it uses {@link FabricObject#isInFrontOf} which relies on the canvas ref
16333
+ */
16334
+ canvas: this
16335
+ });
16336
+ newActiveSelection.multiSelectAdd(...objects);
16337
+ this._setActiveObject(newActiveSelection, e);
16338
+ this._fireSelectionEvents(prevActiveObjects, e);
16339
+ }
16340
+
16266
16341
  /**
16267
16342
  * @override clear {@link textEditingManager}
16268
16343
  */