dockview 1.9.0 → 1.9.2

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.2
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
@@ -3109,9 +3109,6 @@ class DragAndDropObserver extends CompositeDisposable {
3109
3109
  }
3110
3110
  }
3111
3111
 
3112
- function numberOrFallback(maybeNumber, fallback) {
3113
- return typeof maybeNumber === 'number' ? maybeNumber : fallback;
3114
- }
3115
3112
  function directionToPosition(direction) {
3116
3113
  switch (direction) {
3117
3114
  case 'above':
@@ -3144,6 +3141,16 @@ function positionToDirection(position) {
3144
3141
  throw new Error(`invalid position '${position}'`);
3145
3142
  }
3146
3143
  }
3144
+ const DEFAULT_ACTIVATION_SIZE = {
3145
+ value: 20,
3146
+ type: 'percentage',
3147
+ };
3148
+ const DEFAULT_SIZE = {
3149
+ value: 50,
3150
+ type: 'percentage',
3151
+ };
3152
+ const SMALL_WIDTH_BOUNDARY = 100;
3153
+ const SMALL_HEIGHT_BOUNDARY = 100;
3147
3154
  class Droptarget extends CompositeDisposable {
3148
3155
  get state() {
3149
3156
  return this._state;
@@ -3204,7 +3211,7 @@ class Droptarget extends CompositeDisposable {
3204
3211
  this.element.append(this.targetElement);
3205
3212
  }
3206
3213
  this.toggleClasses(quadrant, width, height);
3207
- this.setState(quadrant);
3214
+ this._state = quadrant;
3208
3215
  },
3209
3216
  onDragLeave: () => {
3210
3217
  this.removeDropTarget();
@@ -3229,6 +3236,9 @@ class Droptarget extends CompositeDisposable {
3229
3236
  setTargetZones(acceptedTargetZones) {
3230
3237
  this._acceptedTargetZonesSet = new Set(acceptedTargetZones);
3231
3238
  }
3239
+ setOverlayModel(model) {
3240
+ this.options.overlayModel = model;
3241
+ }
3232
3242
  dispose() {
3233
3243
  this.removeDropTarget();
3234
3244
  super.dispose();
@@ -3240,19 +3250,19 @@ class Droptarget extends CompositeDisposable {
3240
3250
  event[Droptarget.USED_EVENT_ID] = true;
3241
3251
  }
3242
3252
  /**
3243
- * Check is the event has already been used by another instance od DropTarget
3253
+ * Check is the event has already been used by another instance of DropTarget
3244
3254
  */
3245
3255
  isAlreadyUsed(event) {
3246
3256
  const value = event[Droptarget.USED_EVENT_ID];
3247
3257
  return typeof value === 'boolean' && value;
3248
3258
  }
3249
3259
  toggleClasses(quadrant, width, height) {
3250
- var _a, _b, _c, _d;
3260
+ var _a, _b;
3251
3261
  if (!this.overlayElement) {
3252
3262
  return;
3253
3263
  }
3254
- const isSmallX = width < 100;
3255
- const isSmallY = height < 100;
3264
+ const isSmallX = width < SMALL_WIDTH_BOUNDARY;
3265
+ const isSmallY = height < SMALL_HEIGHT_BOUNDARY;
3256
3266
  const isLeft = quadrant === 'left';
3257
3267
  const isRight = quadrant === 'right';
3258
3268
  const isTop = quadrant === 'top';
@@ -3261,20 +3271,17 @@ class Droptarget extends CompositeDisposable {
3261
3271
  const leftClass = !isSmallX && isLeft;
3262
3272
  const topClass = !isSmallY && isTop;
3263
3273
  const bottomClass = !isSmallY && isBottom;
3264
- let size = 0.5;
3265
- if (((_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.type) === 'percentage') {
3266
- size = clamp(this.options.overlayModel.size.value, 0, 100) / 100;
3274
+ let size = 1;
3275
+ const sizeOptions = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : DEFAULT_SIZE;
3276
+ if (sizeOptions.type === 'percentage') {
3277
+ size = clamp(sizeOptions.value, 0, 100) / 100;
3267
3278
  }
3268
- if (((_d = (_c = this.options.overlayModel) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.type) === 'pixels') {
3279
+ else {
3269
3280
  if (rightClass || leftClass) {
3270
- size =
3271
- clamp(0, this.options.overlayModel.size.value, width) /
3272
- width;
3281
+ size = clamp(0, sizeOptions.value, width) / width;
3273
3282
  }
3274
3283
  if (topClass || bottomClass) {
3275
- size =
3276
- clamp(0, this.options.overlayModel.size.value, height) /
3277
- height;
3284
+ size = clamp(0, sizeOptions.value, height) / height;
3278
3285
  }
3279
3286
  }
3280
3287
  const translate = (1 - size) / 2;
@@ -3296,39 +3303,22 @@ class Droptarget extends CompositeDisposable {
3296
3303
  transform = '';
3297
3304
  }
3298
3305
  this.overlayElement.style.transform = transform;
3299
- toggleClass(this.overlayElement, 'small-right', isSmallX && isRight);
3300
- toggleClass(this.overlayElement, 'small-left', isSmallX && isLeft);
3301
- toggleClass(this.overlayElement, 'small-top', isSmallY && isTop);
3302
- toggleClass(this.overlayElement, 'small-bottom', isSmallY && isBottom);
3303
- }
3304
- setState(quadrant) {
3305
- switch (quadrant) {
3306
- case 'top':
3307
- this._state = 'top';
3308
- break;
3309
- case 'left':
3310
- this._state = 'left';
3311
- break;
3312
- case 'bottom':
3313
- this._state = 'bottom';
3314
- break;
3315
- case 'right':
3316
- this._state = 'right';
3317
- break;
3318
- case 'center':
3319
- this._state = 'center';
3320
- break;
3321
- }
3306
+ toggleClass(this.overlayElement, 'dv-drop-target-small-vertical', isSmallY);
3307
+ toggleClass(this.overlayElement, 'dv-drop-target-small-horizontal', isSmallX);
3308
+ toggleClass(this.overlayElement, 'dv-drop-target-left', isLeft);
3309
+ toggleClass(this.overlayElement, 'dv-drop-target-right', isRight);
3310
+ toggleClass(this.overlayElement, 'dv-drop-target-top', isTop);
3311
+ toggleClass(this.overlayElement, 'dv-drop-target-bottom', isBottom);
3312
+ toggleClass(this.overlayElement, 'dv-drop-target-center', quadrant === 'center');
3322
3313
  }
3323
3314
  calculateQuadrant(overlayType, x, y, width, height) {
3324
- var _a, _b, _c, _d, _e, _f;
3325
- const isPercentage = ((_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) === undefined ||
3326
- ((_c = (_b = this.options.overlayModel) === null || _b === void 0 ? void 0 : _b.activationSize) === null || _c === void 0 ? void 0 : _c.type) === 'percentage';
3327
- 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);
3315
+ var _a, _b;
3316
+ const activationSizeOptions = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) !== null && _b !== void 0 ? _b : DEFAULT_ACTIVATION_SIZE;
3317
+ const isPercentage = activationSizeOptions.type === 'percentage';
3328
3318
  if (isPercentage) {
3329
- return calculateQuadrantAsPercentage(overlayType, x, y, width, height, value);
3319
+ return calculateQuadrantAsPercentage(overlayType, x, y, width, height, activationSizeOptions.value);
3330
3320
  }
3331
- return calculateQuadrantAsPixels(overlayType, x, y, width, height, value);
3321
+ return calculateQuadrantAsPixels(overlayType, x, y, width, height, activationSizeOptions.value);
3332
3322
  }
3333
3323
  removeDropTarget() {
3334
3324
  if (this.targetElement) {
@@ -3502,11 +3492,11 @@ class ContentContainer extends CompositeDisposable {
3502
3492
  }
3503
3493
  closePanel() {
3504
3494
  if (this.panel) {
3505
- if (this.accessor.options.defaultRenderer === 'onlyWhenVisibile') {
3495
+ if (this.panel.api.renderer === 'onlyWhenVisibile') {
3506
3496
  this._element.removeChild(this.panel.view.content.element);
3507
3497
  }
3508
- this.panel = undefined;
3509
3498
  }
3499
+ this.panel = undefined;
3510
3500
  }
3511
3501
  dispose() {
3512
3502
  this.disposable.dispose();
@@ -4257,6 +4247,7 @@ class DockviewGroupPanelModel extends CompositeDisposable {
4257
4247
  if (!skipSetGroupActive) {
4258
4248
  this.accessor.doSetGroupActive(this.groupPanel);
4259
4249
  }
4250
+ this.contentContainer.renderPanel(panel, { asActive: true });
4260
4251
  return;
4261
4252
  }
4262
4253
  this.doAddPanel(panel, options.index, skipSetPanelActive);
@@ -4520,6 +4511,21 @@ class Resizable extends CompositeDisposable {
4520
4511
  if (this.disableResizing) {
4521
4512
  return;
4522
4513
  }
4514
+ if (!this._element.offsetParent) {
4515
+ /**
4516
+ * offsetParent === null is equivalent to display: none being set on the element or one
4517
+ * of it's parents. In the display: none case the size will become (0, 0) which we do
4518
+ * not want to propagate.
4519
+ *
4520
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
4521
+ *
4522
+ * You could use checkVisibility() but at the time of writing it's not supported across
4523
+ * all Browsers
4524
+ *
4525
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility
4526
+ */
4527
+ return;
4528
+ }
4523
4529
  if (!isInDocument(this._element)) {
4524
4530
  /**
4525
4531
  * since the event is dispatched through requestAnimationFrame there is a small chance
@@ -6528,6 +6534,10 @@ class OverlayRenderContainer extends CompositeDisposable {
6528
6534
  }
6529
6535
  }
6530
6536
 
6537
+ const DEFAULT_ROOT_OVERLAY_MODEL = {
6538
+ activationSize: { type: 'pixels', value: 10 },
6539
+ size: { type: 'pixels', value: 20 },
6540
+ };
6531
6541
  function getTheme(element) {
6532
6542
  function toClassList(element) {
6533
6543
  const list = [];
@@ -6572,7 +6582,7 @@ class DockviewComponent extends BaseGrid {
6572
6582
  return (_a = this.options.defaultRenderer) !== null && _a !== void 0 ? _a : 'onlyWhenVisibile';
6573
6583
  }
6574
6584
  constructor(options) {
6575
- var _a;
6585
+ var _a, _b;
6576
6586
  super({
6577
6587
  proportionalLayout: true,
6578
6588
  orientation: (_a = options.orientation) !== null && _a !== void 0 ? _a : Orientation.HORIZONTAL,
@@ -6636,7 +6646,7 @@ class DockviewComponent extends BaseGrid {
6636
6646
  !this.options.watermarkFrameworkComponent) {
6637
6647
  this.options.watermarkComponent = Watermark;
6638
6648
  }
6639
- const dropTarget = new Droptarget(this.element, {
6649
+ this._rootDropTarget = new Droptarget(this.element, {
6640
6650
  canDisplayOverlay: (event, position) => {
6641
6651
  const data = getPanelData();
6642
6652
  if (data) {
@@ -6669,12 +6679,9 @@ class DockviewComponent extends BaseGrid {
6669
6679
  return false;
6670
6680
  },
6671
6681
  acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
6672
- overlayModel: {
6673
- activationSize: { type: 'pixels', value: 10 },
6674
- size: { type: 'pixels', value: 20 },
6675
- },
6682
+ overlayModel: (_b = this.options.rootOverlayModel) !== null && _b !== void 0 ? _b : DEFAULT_ROOT_OVERLAY_MODEL,
6676
6683
  });
6677
- this.addDisposables(dropTarget.onDrop((event) => {
6684
+ this.addDisposables(this._rootDropTarget.onDrop((event) => {
6678
6685
  var _a;
6679
6686
  const data = getPanelData();
6680
6687
  if (data) {
@@ -6683,7 +6690,7 @@ class DockviewComponent extends BaseGrid {
6683
6690
  else {
6684
6691
  this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: null, getData: getPanelData }));
6685
6692
  }
6686
- }), dropTarget);
6693
+ }), this._rootDropTarget);
6687
6694
  this._api = new DockviewApi(this);
6688
6695
  this.updateWatermark();
6689
6696
  }
@@ -6846,15 +6853,17 @@ class DockviewComponent extends BaseGrid {
6846
6853
  }
6847
6854
  updateOptions(options) {
6848
6855
  var _a, _b;
6849
- const hasOrientationChanged = typeof options.orientation === 'string' &&
6856
+ const changed_orientation = typeof options.orientation === 'string' &&
6850
6857
  this.gridview.orientation !== options.orientation;
6851
- const hasFloatingGroupOptionsChanged = options.floatingGroupBounds !== undefined &&
6858
+ const changed_floatingGroupBounds = options.floatingGroupBounds !== undefined &&
6852
6859
  options.floatingGroupBounds !== this.options.floatingGroupBounds;
6860
+ const changed_rootOverlayOptions = options.rootOverlayModel !== undefined &&
6861
+ options.rootOverlayModel !== this.options.rootOverlayModel;
6853
6862
  this._options = Object.assign(Object.assign({}, this.options), options);
6854
- if (hasOrientationChanged) {
6863
+ if (changed_orientation) {
6855
6864
  this.gridview.orientation = options.orientation;
6856
6865
  }
6857
- if (hasFloatingGroupOptionsChanged) {
6866
+ if (changed_floatingGroupBounds) {
6858
6867
  for (const group of this._floatingGroups) {
6859
6868
  switch (this.options.floatingGroupBounds) {
6860
6869
  case 'boundedWithinViewport':
@@ -6876,6 +6885,9 @@ class DockviewComponent extends BaseGrid {
6876
6885
  group.overlay.setBounds({});
6877
6886
  }
6878
6887
  }
6888
+ if (changed_rootOverlayOptions) {
6889
+ this._rootDropTarget.setOverlayModel(options.rootOverlayModel);
6890
+ }
6879
6891
  this.layout(this.gridview.width, this.gridview.height, true);
6880
6892
  }
6881
6893
  layout(width, height, forceResize) {
@@ -7257,7 +7269,7 @@ class DockviewComponent extends BaseGrid {
7257
7269
  }
7258
7270
  addGroup(options) {
7259
7271
  var _a;
7260
- const group = this.createGroup();
7272
+ const group = this.createGroup(options);
7261
7273
  if (options) {
7262
7274
  let referenceGroup;
7263
7275
  if (isGroupOptionsWithPanel(options)) {
@@ -8851,6 +8863,7 @@ const DockviewReact = React.forwardRef((props, ref) => {
8851
8863
  floatingGroupBounds: props.floatingGroupBounds,
8852
8864
  defaultRenderer: props.defaultRenderer,
8853
8865
  debug: props.debug,
8866
+ rootOverlayModel: props.rootOverlayModel,
8854
8867
  });
8855
8868
  const { clientWidth, clientHeight } = domRef.current;
8856
8869
  dockview.layout(clientWidth, clientHeight);
@@ -8958,6 +8971,14 @@ const DockviewReact = React.forwardRef((props, ref) => {
8958
8971
  createLeftHeaderActionsElement: createGroupControlElement(props.leftHeaderActionsComponent, { addPortal }),
8959
8972
  });
8960
8973
  }, [props.leftHeaderActionsComponent]);
8974
+ React.useEffect(() => {
8975
+ if (!dockviewRef.current) {
8976
+ return;
8977
+ }
8978
+ dockviewRef.current.updateOptions({
8979
+ rootOverlayModel: props.rootOverlayModel,
8980
+ });
8981
+ }, [props.rootOverlayModel]);
8961
8982
  React.useEffect(() => {
8962
8983
  if (!dockviewRef.current) {
8963
8984
  return;