dock-spawn-ts 3.19.0 → 3.20.0

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,7 @@
1
- import { SplitterBar } from "./SplitterBar.js";
2
- import { Utils } from "./Utils.js";
3
- import { IDockContainer } from "./interfaces/IDockContainer.js";
1
+ import { SplitterBar } from "./SplitterBar.js";
2
+ import { Utils } from "./Utils.js";
3
+ import { ContainerType } from "./ContainerType.js";
4
+ import { IDockContainer } from "./interfaces/IDockContainer.js";
4
5
 
5
6
  /**
6
7
  * A splitter panel manages the child containers inside it with splitter bars.
@@ -160,73 +161,76 @@ export class SplitterPanel {
160
161
  }
161
162
  }
162
163
 
163
- resize(width: number, height: number) {
164
- if (this.childContainers.length <= 1)
165
- return;
166
-
167
- this.panelElement.style.width = width + 'px';
168
- this.panelElement.style.height = height + 'px';
169
-
170
- let i;
171
-
172
- // Adjust the fixed dimension that is common to all (i.e. width, if stacked vertical; height, if stacked horizontally)
173
- for (i = 0; i < this.childContainers.length; i++) {
174
- let childContainer = this.childContainers[i];
175
- if (this.stackedVertical)
176
- childContainer.resize(width, !childContainer.height ? height : childContainer.height);
177
- else
178
- childContainer.resize(!childContainer.width ? width : childContainer.width, height);
179
-
180
- if (i < this.spiltterBars.length) {
181
- let splitBar = this.spiltterBars[i];
182
- if (this.stackedVertical)
183
- splitBar.barElement.style.width = width + 'px';
184
- else
185
- splitBar.barElement.style.height = height + 'px';
186
- }
187
- }
188
-
189
- // Adjust the varying dimension
190
- let totalChildPanelSize = 0;
191
- // Find out how much space existing child containers take up (excluding the splitter bars)
192
- this.childContainers.forEach((container) => {
193
- let size = this.stackedVertical ?
194
- container.height :
195
- container.width;
196
- totalChildPanelSize += size;
197
- });
198
-
199
- // Get the thickness of the bar
200
- let barSize = this.stackedVertical ? this.spiltterBars[0].barElement.clientHeight : this.spiltterBars[0].barElement.clientWidth;
201
-
202
- // Find out how much space existing child containers will take after being resized (excluding the splitter bars)
203
- let targetTotalChildPanelSize = this.stackedVertical ? height : width;
204
- targetTotalChildPanelSize -= barSize * this.spiltterBars.length;
205
-
206
- // Get the scale multiplier
207
- totalChildPanelSize = Math.max(totalChildPanelSize, 1);
208
- let scaleMultiplier = targetTotalChildPanelSize / totalChildPanelSize;
209
-
210
-
211
- // Update the size with this multiplier
212
- let updatedTotalChildPanelSize = 0;
213
- for (i = 0; i < this.childContainers.length; i++) {
214
- let child = this.childContainers[i];
215
- if (child.containerElement.style.display == 'none')
216
- child.containerElement.style.display = 'block';
217
- let original = this.stackedVertical ? child.containerElement.clientHeight : child.containerElement.clientWidth;
218
- let newSize = Math.floor(original * scaleMultiplier);
219
- updatedTotalChildPanelSize += newSize;
220
-
221
- // If this is the last node, add any extra pixels to fix the rounding off errors and match the requested size
222
- if (i === this.childContainers.length - 1)
223
- newSize += targetTotalChildPanelSize - updatedTotalChildPanelSize;
224
-
225
- // Set the size of the panel
226
- if (this.stackedVertical)
227
- child.resize(child.width, newSize);
228
- else
229
- child.resize(newSize, child.height);
230
- }
231
- }
232
- }
164
+ resize(width: number, height: number) {
165
+ if (this.childContainers.length <= 1)
166
+ return;
167
+
168
+ this.panelElement.style.width = width + 'px';
169
+ this.panelElement.style.height = height + 'px';
170
+
171
+ for (let i = 0; i < this.childContainers.length; i++) {
172
+ if (i < this.spiltterBars.length) {
173
+ let splitBar = this.spiltterBars[i];
174
+ if (this.stackedVertical)
175
+ splitBar.barElement.style.width = width + 'px';
176
+ else
177
+ splitBar.barElement.style.height = height + 'px';
178
+ }
179
+ }
180
+
181
+ let barSize = this.stackedVertical ? this.spiltterBars[0].barElement.clientHeight : this.spiltterBars[0].barElement.clientWidth;
182
+ let targetTotalChildPanelSize = this.stackedVertical ? height : width;
183
+ targetTotalChildPanelSize -= barSize * this.spiltterBars.length;
184
+
185
+ let childSizes = this.childContainers.map((container) => this.stackedVertical ? container.height : container.width);
186
+ let totalChildPanelSize = childSizes.reduce((sum, size) => sum + size, 0);
187
+ if (totalChildPanelSize <= 0) {
188
+ let size = targetTotalChildPanelSize / this.childContainers.length;
189
+ childSizes = this.childContainers.map(() => size);
190
+ totalChildPanelSize = targetTotalChildPanelSize;
191
+ }
192
+
193
+ let resizeIndex = this.getElasticChildIndex();
194
+ let sizeDelta = targetTotalChildPanelSize - totalChildPanelSize;
195
+ childSizes[resizeIndex] += sizeDelta;
196
+ if (childSizes[resizeIndex] < 0) {
197
+ let deficit = -childSizes[resizeIndex];
198
+ childSizes[resizeIndex] = 0;
199
+ for (let i = this.childContainers.length - 1; i >= 0 && deficit > 0; i--) {
200
+ if (i === resizeIndex)
201
+ continue;
202
+ let reduction = Math.min(childSizes[i], deficit);
203
+ childSizes[i] -= reduction;
204
+ deficit -= reduction;
205
+ }
206
+ }
207
+
208
+ childSizes = childSizes.map((size) => Math.floor(size));
209
+ childSizes[resizeIndex] += targetTotalChildPanelSize - childSizes.reduce((sum, size) => sum + size, 0);
210
+
211
+ for (let i = 0; i < this.childContainers.length; i++) {
212
+ let child = this.childContainers[i];
213
+ if (child.containerElement.style.display == 'none')
214
+ child.containerElement.style.display = 'block';
215
+ let newSize = childSizes[i];
216
+
217
+ if (this.stackedVertical)
218
+ child.resize(width, newSize);
219
+ else
220
+ child.resize(newSize, height);
221
+ }
222
+ }
223
+
224
+ private getElasticChildIndex(): number {
225
+ let fillIndex = this.childContainers.findIndex((container) => container.containerType === ContainerType.fill);
226
+ if (fillIndex >= 0)
227
+ return fillIndex;
228
+
229
+ let compositeIndex = this.childContainers.findIndex((container) =>
230
+ container.containerType === ContainerType.horizontal || container.containerType === ContainerType.vertical);
231
+ if (compositeIndex >= 0)
232
+ return compositeIndex;
233
+
234
+ return this.childContainers.length - 1;
235
+ }
236
+ }