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
  */
@@ -3098,9 +3098,6 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3098
3098
  }
3099
3099
  }
3100
3100
 
3101
- function numberOrFallback(maybeNumber, fallback) {
3102
- return typeof maybeNumber === 'number' ? maybeNumber : fallback;
3103
- }
3104
3101
  function directionToPosition(direction) {
3105
3102
  switch (direction) {
3106
3103
  case 'above':
@@ -3133,6 +3130,16 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3133
3130
  throw new Error(`invalid position '${position}'`);
3134
3131
  }
3135
3132
  }
3133
+ const DEFAULT_ACTIVATION_SIZE = {
3134
+ value: 20,
3135
+ type: 'percentage',
3136
+ };
3137
+ const DEFAULT_SIZE = {
3138
+ value: 50,
3139
+ type: 'percentage',
3140
+ };
3141
+ const SMALL_WIDTH_BOUNDARY = 100;
3142
+ const SMALL_HEIGHT_BOUNDARY = 100;
3136
3143
  class Droptarget extends CompositeDisposable {
3137
3144
  get state() {
3138
3145
  return this._state;
@@ -3193,7 +3200,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3193
3200
  this.element.append(this.targetElement);
3194
3201
  }
3195
3202
  this.toggleClasses(quadrant, width, height);
3196
- this.setState(quadrant);
3203
+ this._state = quadrant;
3197
3204
  },
3198
3205
  onDragLeave: () => {
3199
3206
  this.removeDropTarget();
@@ -3218,6 +3225,9 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3218
3225
  setTargetZones(acceptedTargetZones) {
3219
3226
  this._acceptedTargetZonesSet = new Set(acceptedTargetZones);
3220
3227
  }
3228
+ setOverlayModel(model) {
3229
+ this.options.overlayModel = model;
3230
+ }
3221
3231
  dispose() {
3222
3232
  this.removeDropTarget();
3223
3233
  super.dispose();
@@ -3229,19 +3239,19 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3229
3239
  event[Droptarget.USED_EVENT_ID] = true;
3230
3240
  }
3231
3241
  /**
3232
- * Check is the event has already been used by another instance od DropTarget
3242
+ * Check is the event has already been used by another instance of DropTarget
3233
3243
  */
3234
3244
  isAlreadyUsed(event) {
3235
3245
  const value = event[Droptarget.USED_EVENT_ID];
3236
3246
  return typeof value === 'boolean' && value;
3237
3247
  }
3238
3248
  toggleClasses(quadrant, width, height) {
3239
- var _a, _b, _c, _d;
3249
+ var _a, _b;
3240
3250
  if (!this.overlayElement) {
3241
3251
  return;
3242
3252
  }
3243
- const isSmallX = width < 100;
3244
- const isSmallY = height < 100;
3253
+ const isSmallX = width < SMALL_WIDTH_BOUNDARY;
3254
+ const isSmallY = height < SMALL_HEIGHT_BOUNDARY;
3245
3255
  const isLeft = quadrant === 'left';
3246
3256
  const isRight = quadrant === 'right';
3247
3257
  const isTop = quadrant === 'top';
@@ -3250,20 +3260,17 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3250
3260
  const leftClass = !isSmallX && isLeft;
3251
3261
  const topClass = !isSmallY && isTop;
3252
3262
  const bottomClass = !isSmallY && isBottom;
3253
- let size = 0.5;
3254
- if (((_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.type) === 'percentage') {
3255
- size = clamp(this.options.overlayModel.size.value, 0, 100) / 100;
3263
+ let size = 1;
3264
+ const sizeOptions = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : DEFAULT_SIZE;
3265
+ if (sizeOptions.type === 'percentage') {
3266
+ size = clamp(sizeOptions.value, 0, 100) / 100;
3256
3267
  }
3257
- if (((_d = (_c = this.options.overlayModel) === null || _c === void 0 ? void 0 : _c.size) === null || _d === void 0 ? void 0 : _d.type) === 'pixels') {
3268
+ else {
3258
3269
  if (rightClass || leftClass) {
3259
- size =
3260
- clamp(0, this.options.overlayModel.size.value, width) /
3261
- width;
3270
+ size = clamp(0, sizeOptions.value, width) / width;
3262
3271
  }
3263
3272
  if (topClass || bottomClass) {
3264
- size =
3265
- clamp(0, this.options.overlayModel.size.value, height) /
3266
- height;
3273
+ size = clamp(0, sizeOptions.value, height) / height;
3267
3274
  }
3268
3275
  }
3269
3276
  const translate = (1 - size) / 2;
@@ -3285,39 +3292,22 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
3285
3292
  transform = '';
3286
3293
  }
3287
3294
  this.overlayElement.style.transform = transform;
3288
- toggleClass(this.overlayElement, 'small-right', isSmallX && isRight);
3289
- toggleClass(this.overlayElement, 'small-left', isSmallX && isLeft);
3290
- toggleClass(this.overlayElement, 'small-top', isSmallY && isTop);
3291
- toggleClass(this.overlayElement, 'small-bottom', isSmallY && isBottom);
3292
- }
3293
- setState(quadrant) {
3294
- switch (quadrant) {
3295
- case 'top':
3296
- this._state = 'top';
3297
- break;
3298
- case 'left':
3299
- this._state = 'left';
3300
- break;
3301
- case 'bottom':
3302
- this._state = 'bottom';
3303
- break;
3304
- case 'right':
3305
- this._state = 'right';
3306
- break;
3307
- case 'center':
3308
- this._state = 'center';
3309
- break;
3310
- }
3295
+ toggleClass(this.overlayElement, 'dv-drop-target-small-vertical', isSmallY);
3296
+ toggleClass(this.overlayElement, 'dv-drop-target-small-horizontal', isSmallX);
3297
+ toggleClass(this.overlayElement, 'dv-drop-target-left', isLeft);
3298
+ toggleClass(this.overlayElement, 'dv-drop-target-right', isRight);
3299
+ toggleClass(this.overlayElement, 'dv-drop-target-top', isTop);
3300
+ toggleClass(this.overlayElement, 'dv-drop-target-bottom', isBottom);
3301
+ toggleClass(this.overlayElement, 'dv-drop-target-center', quadrant === 'center');
3311
3302
  }
3312
3303
  calculateQuadrant(overlayType, x, y, width, height) {
3313
- var _a, _b, _c, _d, _e, _f;
3314
- const isPercentage = ((_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) === undefined ||
3315
- ((_c = (_b = this.options.overlayModel) === null || _b === void 0 ? void 0 : _b.activationSize) === null || _c === void 0 ? void 0 : _c.type) === 'percentage';
3316
- 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);
3304
+ var _a, _b;
3305
+ const activationSizeOptions = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) !== null && _b !== void 0 ? _b : DEFAULT_ACTIVATION_SIZE;
3306
+ const isPercentage = activationSizeOptions.type === 'percentage';
3317
3307
  if (isPercentage) {
3318
- return calculateQuadrantAsPercentage(overlayType, x, y, width, height, value);
3308
+ return calculateQuadrantAsPercentage(overlayType, x, y, width, height, activationSizeOptions.value);
3319
3309
  }
3320
- return calculateQuadrantAsPixels(overlayType, x, y, width, height, value);
3310
+ return calculateQuadrantAsPixels(overlayType, x, y, width, height, activationSizeOptions.value);
3321
3311
  }
3322
3312
  removeDropTarget() {
3323
3313
  if (this.targetElement) {
@@ -4509,6 +4499,21 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
4509
4499
  if (this.disableResizing) {
4510
4500
  return;
4511
4501
  }
4502
+ if (!this._element.offsetParent) {
4503
+ /**
4504
+ * offsetParent === null is equivalent to display: none being set on the element or one
4505
+ * of it's parents. In the display: none case the size will become (0, 0) which we do
4506
+ * not want to propagate.
4507
+ *
4508
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
4509
+ *
4510
+ * You could use checkVisibility() but at the time of writing it's not supported across
4511
+ * all Browsers
4512
+ *
4513
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility
4514
+ */
4515
+ return;
4516
+ }
4512
4517
  if (!isInDocument(this._element)) {
4513
4518
  /**
4514
4519
  * since the event is dispatched through requestAnimationFrame there is a small chance
@@ -6517,6 +6522,10 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6517
6522
  }
6518
6523
  }
6519
6524
 
6525
+ const DEFAULT_ROOT_OVERLAY_MODEL = {
6526
+ activationSize: { type: 'pixels', value: 10 },
6527
+ size: { type: 'pixels', value: 20 },
6528
+ };
6520
6529
  function getTheme(element) {
6521
6530
  function toClassList(element) {
6522
6531
  const list = [];
@@ -6561,7 +6570,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6561
6570
  return (_a = this.options.defaultRenderer) !== null && _a !== void 0 ? _a : 'onlyWhenVisibile';
6562
6571
  }
6563
6572
  constructor(options) {
6564
- var _a;
6573
+ var _a, _b;
6565
6574
  super({
6566
6575
  proportionalLayout: true,
6567
6576
  orientation: (_a = options.orientation) !== null && _a !== void 0 ? _a : exports.Orientation.HORIZONTAL,
@@ -6625,7 +6634,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6625
6634
  !this.options.watermarkFrameworkComponent) {
6626
6635
  this.options.watermarkComponent = Watermark;
6627
6636
  }
6628
- const dropTarget = new Droptarget(this.element, {
6637
+ this._rootDropTarget = new Droptarget(this.element, {
6629
6638
  canDisplayOverlay: (event, position) => {
6630
6639
  const data = getPanelData();
6631
6640
  if (data) {
@@ -6658,12 +6667,9 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6658
6667
  return false;
6659
6668
  },
6660
6669
  acceptedTargetZones: ['top', 'bottom', 'left', 'right', 'center'],
6661
- overlayModel: {
6662
- activationSize: { type: 'pixels', value: 10 },
6663
- size: { type: 'pixels', value: 20 },
6664
- },
6670
+ overlayModel: (_b = this.options.rootOverlayModel) !== null && _b !== void 0 ? _b : DEFAULT_ROOT_OVERLAY_MODEL,
6665
6671
  });
6666
- this.addDisposables(dropTarget.onDrop((event) => {
6672
+ this.addDisposables(this._rootDropTarget.onDrop((event) => {
6667
6673
  var _a;
6668
6674
  const data = getPanelData();
6669
6675
  if (data) {
@@ -6672,7 +6678,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6672
6678
  else {
6673
6679
  this._onDidDrop.fire(Object.assign(Object.assign({}, event), { api: this._api, group: null, getData: getPanelData }));
6674
6680
  }
6675
- }), dropTarget);
6681
+ }), this._rootDropTarget);
6676
6682
  this._api = new DockviewApi(this);
6677
6683
  this.updateWatermark();
6678
6684
  }
@@ -6835,15 +6841,17 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6835
6841
  }
6836
6842
  updateOptions(options) {
6837
6843
  var _a, _b;
6838
- const hasOrientationChanged = typeof options.orientation === 'string' &&
6844
+ const changed_orientation = typeof options.orientation === 'string' &&
6839
6845
  this.gridview.orientation !== options.orientation;
6840
- const hasFloatingGroupOptionsChanged = options.floatingGroupBounds !== undefined &&
6846
+ const changed_floatingGroupBounds = options.floatingGroupBounds !== undefined &&
6841
6847
  options.floatingGroupBounds !== this.options.floatingGroupBounds;
6848
+ const changed_rootOverlayOptions = options.rootOverlayModel !== undefined &&
6849
+ options.rootOverlayModel !== this.options.rootOverlayModel;
6842
6850
  this._options = Object.assign(Object.assign({}, this.options), options);
6843
- if (hasOrientationChanged) {
6851
+ if (changed_orientation) {
6844
6852
  this.gridview.orientation = options.orientation;
6845
6853
  }
6846
- if (hasFloatingGroupOptionsChanged) {
6854
+ if (changed_floatingGroupBounds) {
6847
6855
  for (const group of this._floatingGroups) {
6848
6856
  switch (this.options.floatingGroupBounds) {
6849
6857
  case 'boundedWithinViewport':
@@ -6865,6 +6873,9 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
6865
6873
  group.overlay.setBounds({});
6866
6874
  }
6867
6875
  }
6876
+ if (changed_rootOverlayOptions) {
6877
+ this._rootDropTarget.setOverlayModel(options.rootOverlayModel);
6878
+ }
6868
6879
  this.layout(this.gridview.width, this.gridview.height, true);
6869
6880
  }
6870
6881
  layout(width, height, forceResize) {
@@ -8840,6 +8851,7 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8840
8851
  floatingGroupBounds: props.floatingGroupBounds,
8841
8852
  defaultRenderer: props.defaultRenderer,
8842
8853
  debug: props.debug,
8854
+ rootOverlayModel: props.rootOverlayModel,
8843
8855
  });
8844
8856
  const { clientWidth, clientHeight } = domRef.current;
8845
8857
  dockview.layout(clientWidth, clientHeight);
@@ -8947,6 +8959,14 @@ define(['exports', 'react', 'react-dom'], (function (exports, React, ReactDOM) {
8947
8959
  createLeftHeaderActionsElement: createGroupControlElement(props.leftHeaderActionsComponent, { addPortal }),
8948
8960
  });
8949
8961
  }, [props.leftHeaderActionsComponent]);
8962
+ React__namespace.useEffect(() => {
8963
+ if (!dockviewRef.current) {
8964
+ return;
8965
+ }
8966
+ dockviewRef.current.updateOptions({
8967
+ rootOverlayModel: props.rootOverlayModel,
8968
+ });
8969
+ }, [props.rootOverlayModel]);
8950
8970
  React__namespace.useEffect(() => {
8951
8971
  if (!dockviewRef.current) {
8952
8972
  return;