dockview 1.9.0 → 1.9.1

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dockview
3
- * @version 1.9.0
3
+ * @version 1.9.1
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -3131,9 +3131,6 @@ class DragAndDropObserver extends CompositeDisposable {
3131
3131
  }
3132
3132
  }
3133
3133
 
3134
- function numberOrFallback(maybeNumber, fallback) {
3135
- return typeof maybeNumber === 'number' ? maybeNumber : fallback;
3136
- }
3137
3134
  function directionToPosition(direction) {
3138
3135
  switch (direction) {
3139
3136
  case 'above':
@@ -3166,6 +3163,16 @@ function positionToDirection(position) {
3166
3163
  throw new Error(`invalid position '${position}'`);
3167
3164
  }
3168
3165
  }
3166
+ const DEFAULT_ACTIVATION_SIZE = {
3167
+ value: 20,
3168
+ type: 'percentage',
3169
+ };
3170
+ const DEFAULT_SIZE = {
3171
+ value: 50,
3172
+ type: 'percentage',
3173
+ };
3174
+ const SMALL_WIDTH_BOUNDARY = 100;
3175
+ const SMALL_HEIGHT_BOUNDARY = 100;
3169
3176
  class Droptarget extends CompositeDisposable {
3170
3177
  get state() {
3171
3178
  return this._state;
@@ -3226,7 +3233,7 @@ class Droptarget extends CompositeDisposable {
3226
3233
  this.element.append(this.targetElement);
3227
3234
  }
3228
3235
  this.toggleClasses(quadrant, width, height);
3229
- this.setState(quadrant);
3236
+ this._state = quadrant;
3230
3237
  },
3231
3238
  onDragLeave: () => {
3232
3239
  this.removeDropTarget();
@@ -3251,6 +3258,9 @@ class Droptarget extends CompositeDisposable {
3251
3258
  setTargetZones(acceptedTargetZones) {
3252
3259
  this._acceptedTargetZonesSet = new Set(acceptedTargetZones);
3253
3260
  }
3261
+ setOverlayModel(model) {
3262
+ this.options.overlayModel = model;
3263
+ }
3254
3264
  dispose() {
3255
3265
  this.removeDropTarget();
3256
3266
  super.dispose();
@@ -3262,19 +3272,19 @@ class Droptarget extends CompositeDisposable {
3262
3272
  event[Droptarget.USED_EVENT_ID] = true;
3263
3273
  }
3264
3274
  /**
3265
- * Check is the event has already been used by another instance od DropTarget
3275
+ * Check is the event has already been used by another instance of DropTarget
3266
3276
  */
3267
3277
  isAlreadyUsed(event) {
3268
3278
  const value = event[Droptarget.USED_EVENT_ID];
3269
3279
  return typeof value === 'boolean' && value;
3270
3280
  }
3271
3281
  toggleClasses(quadrant, width, height) {
3272
- var _a, _b, _c, _d;
3282
+ var _a, _b;
3273
3283
  if (!this.overlayElement) {
3274
3284
  return;
3275
3285
  }
3276
- const isSmallX = width < 100;
3277
- const isSmallY = height < 100;
3286
+ const isSmallX = width < SMALL_WIDTH_BOUNDARY;
3287
+ const isSmallY = height < SMALL_HEIGHT_BOUNDARY;
3278
3288
  const isLeft = quadrant === 'left';
3279
3289
  const isRight = quadrant === 'right';
3280
3290
  const isTop = quadrant === 'top';
@@ -3283,20 +3293,17 @@ class Droptarget extends CompositeDisposable {
3283
3293
  const leftClass = !isSmallX && isLeft;
3284
3294
  const topClass = !isSmallY && isTop;
3285
3295
  const bottomClass = !isSmallY && isBottom;
3286
- let size = 0.5;
3287
- if (((_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.type) === 'percentage') {
3288
- size = clamp(this.options.overlayModel.size.value, 0, 100) / 100;
3296
+ let size = 1;
3297
+ const sizeOptions = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : DEFAULT_SIZE;
3298
+ if (sizeOptions.type === 'percentage') {
3299
+ size = clamp(sizeOptions.value, 0, 100) / 100;
3289
3300
  }
3290
- if (((_d = (_c = this.options.overlayModel) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.type) === 'pixels') {
3301
+ else {
3291
3302
  if (rightClass || leftClass) {
3292
- size =
3293
- clamp(0, this.options.overlayModel.size.value, width) /
3294
- width;
3303
+ size = clamp(0, sizeOptions.value, width) / width;
3295
3304
  }
3296
3305
  if (topClass || bottomClass) {
3297
- size =
3298
- clamp(0, this.options.overlayModel.size.value, height) /
3299
- height;
3306
+ size = clamp(0, sizeOptions.value, height) / height;
3300
3307
  }
3301
3308
  }
3302
3309
  const translate = (1 - size) / 2;
@@ -3318,39 +3325,22 @@ class Droptarget extends CompositeDisposable {
3318
3325
  transform = '';
3319
3326
  }
3320
3327
  this.overlayElement.style.transform = transform;
3321
- toggleClass(this.overlayElement, 'small-right', isSmallX && isRight);
3322
- toggleClass(this.overlayElement, 'small-left', isSmallX && isLeft);
3323
- toggleClass(this.overlayElement, 'small-top', isSmallY && isTop);
3324
- toggleClass(this.overlayElement, 'small-bottom', isSmallY && isBottom);
3325
- }
3326
- setState(quadrant) {
3327
- switch (quadrant) {
3328
- case 'top':
3329
- this._state = 'top';
3330
- break;
3331
- case 'left':
3332
- this._state = 'left';
3333
- break;
3334
- case 'bottom':
3335
- this._state = 'bottom';
3336
- break;
3337
- case 'right':
3338
- this._state = 'right';
3339
- break;
3340
- case 'center':
3341
- this._state = 'center';
3342
- break;
3343
- }
3328
+ toggleClass(this.overlayElement, 'dv-drop-target-small-vertical', isSmallY);
3329
+ toggleClass(this.overlayElement, 'dv-drop-target-small-horizontal', isSmallX);
3330
+ toggleClass(this.overlayElement, 'dv-drop-target-left', isLeft);
3331
+ toggleClass(this.overlayElement, 'dv-drop-target-right', isRight);
3332
+ toggleClass(this.overlayElement, 'dv-drop-target-top', isTop);
3333
+ toggleClass(this.overlayElement, 'dv-drop-target-bottom', isBottom);
3334
+ toggleClass(this.overlayElement, 'dv-drop-target-center', quadrant === 'center');
3344
3335
  }
3345
3336
  calculateQuadrant(overlayType, x, y, width, height) {
3346
- var _a, _b, _c, _d, _e, _f;
3347
- const isPercentage = ((_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) === undefined ||
3348
- ((_c = (_b = this.options.overlayModel) === null || _b === void 0 ? void 0 : _b.activationSize) === null || _c === void 0 ? void 0 : _c.type) === 'percentage';
3349
- const value = numberOrFallback((_f = (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.overlayModel) === null || _e === void 0 ? void 0 : _e.activationSize) === null || _f === void 0 ? void 0 : _f.value, 20);
3337
+ var _a, _b;
3338
+ const activationSizeOptions = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) !== null && _b !== void 0 ? _b : DEFAULT_ACTIVATION_SIZE;
3339
+ const isPercentage = activationSizeOptions.type === 'percentage';
3350
3340
  if (isPercentage) {
3351
- return calculateQuadrantAsPercentage(overlayType, x, y, width, height, value);
3341
+ return calculateQuadrantAsPercentage(overlayType, x, y, width, height, activationSizeOptions.value);
3352
3342
  }
3353
- return calculateQuadrantAsPixels(overlayType, x, y, width, height, value);
3343
+ return calculateQuadrantAsPixels(overlayType, x, y, width, height, activationSizeOptions.value);
3354
3344
  }
3355
3345
  removeDropTarget() {
3356
3346
  if (this.targetElement) {
@@ -4542,6 +4532,21 @@ class Resizable extends CompositeDisposable {
4542
4532
  if (this.disableResizing) {
4543
4533
  return;
4544
4534
  }
4535
+ if (!this._element.offsetParent) {
4536
+ /**
4537
+ * offsetParent === null is equivalent to display: none being set on the element or one
4538
+ * of it's parents. In the display: none case the size will become (0, 0) which we do
4539
+ * not want to propagate.
4540
+ *
4541
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
4542
+ *
4543
+ * You could use checkVisibility() but at the time of writing it's not supported across
4544
+ * all Browsers
4545
+ *
4546
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility
4547
+ */
4548
+ return;
4549
+ }
4545
4550
  if (!isInDocument(this._element)) {
4546
4551
  /**
4547
4552
  * since the event is dispatched through requestAnimationFrame there is a small chance
@@ -6550,6 +6555,10 @@ class OverlayRenderContainer extends CompositeDisposable {
6550
6555
  }
6551
6556
  }
6552
6557
 
6558
+ const DEFAULT_ROOT_OVERLAY_MODEL = {
6559
+ activationSize: { type: 'pixels', value: 10 },
6560
+ size: { type: 'pixels', value: 20 },
6561
+ };
6553
6562
  function getTheme(element) {
6554
6563
  function toClassList(element) {
6555
6564
  const list = [];
@@ -6594,7 +6603,7 @@ class DockviewComponent extends BaseGrid {
6594
6603
  return (_a = this.options.defaultRenderer) !== null && _a !== void 0 ? _a : 'onlyWhenVisibile';
6595
6604
  }
6596
6605
  constructor(options) {
6597
- var _a;
6606
+ var _a, _b;
6598
6607
  super({
6599
6608
  proportionalLayout: true,
6600
6609
  orientation: (_a = options.orientation) !== null && _a !== void 0 ? _a : exports.Orientation.HORIZONTAL,
@@ -6658,7 +6667,7 @@ class DockviewComponent extends BaseGrid {
6658
6667
  !this.options.watermarkFrameworkComponent) {
6659
6668
  this.options.watermarkComponent = Watermark;
6660
6669
  }
6661
- const dropTarget = new Droptarget(this.element, {
6670
+ this._rootDropTarget = new Droptarget(this.element, {
6662
6671
  canDisplayOverlay: (event, position) => {
6663
6672
  const data = getPanelData();
6664
6673
  if (data) {
@@ -6691,12 +6700,9 @@ class DockviewComponent extends BaseGrid {
6691
6700
  return false;
6692
6701
  },
6693
6702
  acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
6694
- overlayModel: {
6695
- activationSize: { type: 'pixels', value: 10 },
6696
- size: { type: 'pixels', value: 20 },
6697
- },
6703
+ overlayModel: (_b = this.options.rootOverlayModel) !== null && _b !== void 0 ? _b : DEFAULT_ROOT_OVERLAY_MODEL,
6698
6704
  });
6699
- this.addDisposables(dropTarget.onDrop((event) => {
6705
+ this.addDisposables(this._rootDropTarget.onDrop((event) => {
6700
6706
  var _a;
6701
6707
  const data = getPanelData();
6702
6708
  if (data) {
@@ -6705,7 +6711,7 @@ class DockviewComponent extends BaseGrid {
6705
6711
  else {
6706
6712
  this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: null, getData: getPanelData }));
6707
6713
  }
6708
- }), dropTarget);
6714
+ }), this._rootDropTarget);
6709
6715
  this._api = new DockviewApi(this);
6710
6716
  this.updateWatermark();
6711
6717
  }
@@ -6868,15 +6874,17 @@ class DockviewComponent extends BaseGrid {
6868
6874
  }
6869
6875
  updateOptions(options) {
6870
6876
  var _a, _b;
6871
- const hasOrientationChanged = typeof options.orientation === 'string' &&
6877
+ const changed_orientation = typeof options.orientation === 'string' &&
6872
6878
  this.gridview.orientation !== options.orientation;
6873
- const hasFloatingGroupOptionsChanged = options.floatingGroupBounds !== undefined &&
6879
+ const changed_floatingGroupBounds = options.floatingGroupBounds !== undefined &&
6874
6880
  options.floatingGroupBounds !== this.options.floatingGroupBounds;
6881
+ const changed_rootOverlayOptions = options.rootOverlayModel !== undefined &&
6882
+ options.rootOverlayModel !== this.options.rootOverlayModel;
6875
6883
  this._options = Object.assign(Object.assign({}, this.options), options);
6876
- if (hasOrientationChanged) {
6884
+ if (changed_orientation) {
6877
6885
  this.gridview.orientation = options.orientation;
6878
6886
  }
6879
- if (hasFloatingGroupOptionsChanged) {
6887
+ if (changed_floatingGroupBounds) {
6880
6888
  for (const group of this._floatingGroups) {
6881
6889
  switch (this.options.floatingGroupBounds) {
6882
6890
  case 'boundedWithinViewport':
@@ -6898,6 +6906,9 @@ class DockviewComponent extends BaseGrid {
6898
6906
  group.overlay.setBounds({});
6899
6907
  }
6900
6908
  }
6909
+ if (changed_rootOverlayOptions) {
6910
+ this._rootDropTarget.setOverlayModel(options.rootOverlayModel);
6911
+ }
6901
6912
  this.layout(this.gridview.width, this.gridview.height, true);
6902
6913
  }
6903
6914
  layout(width, height, forceResize) {
@@ -8873,6 +8884,7 @@ const DockviewReact = React__namespace.forwardRef((props, ref) => {
8873
8884
  floatingGroupBounds: props.floatingGroupBounds,
8874
8885
  defaultRenderer: props.defaultRenderer,
8875
8886
  debug: props.debug,
8887
+ rootOverlayModel: props.rootOverlayModel,
8876
8888
  });
8877
8889
  const { clientWidth, clientHeight } = domRef.current;
8878
8890
  dockview.layout(clientWidth, clientHeight);
@@ -8980,6 +8992,14 @@ const DockviewReact = React__namespace.forwardRef((props, ref) => {
8980
8992
  createLeftHeaderActionsElement: createGroupControlElement(props.leftHeaderActionsComponent, { addPortal }),
8981
8993
  });
8982
8994
  }, [props.leftHeaderActionsComponent]);
8995
+ React__namespace.useEffect(() => {
8996
+ if (!dockviewRef.current) {
8997
+ return;
8998
+ }
8999
+ dockviewRef.current.updateOptions({
9000
+ rootOverlayModel: props.rootOverlayModel,
9001
+ });
9002
+ }, [props.rootOverlayModel]);
8983
9003
  React__namespace.useEffect(() => {
8984
9004
  if (!dockviewRef.current) {
8985
9005
  return;