@sankhyalabs/ezui 5.17.2 → 5.18.0-dev.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.
- package/dist/cjs/ez-split-item.cjs.entry.js +19 -0
- package/dist/cjs/ez-split-panel.cjs.entry.js +776 -0
- package/dist/cjs/ezui.cjs.js +1 -1
- package/dist/cjs/index-1064511f.js +8 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +2 -0
- package/dist/collection/components/ez-split-panel/ez-split-panel.css +8 -0
- package/dist/collection/components/ez-split-panel/ez-split-panel.js +122 -0
- package/dist/collection/components/ez-split-panel/structure/item/ez-split-item.css +12 -0
- package/dist/collection/components/ez-split-panel/structure/item/ez-split-item.js +17 -0
- package/dist/custom-elements/index.d.ts +12 -0
- package/dist/custom-elements/index.js +791 -5
- package/dist/esm/ez-split-item.entry.js +15 -0
- package/dist/esm/ez-split-panel.entry.js +772 -0
- package/dist/esm/ezui.js +1 -1
- package/dist/esm/index-296b8458.js +8 -0
- package/dist/esm/loader.js +1 -1
- package/dist/ezui/ezui.esm.js +1 -1
- package/dist/ezui/p-76d16a24.entry.js +1 -0
- package/dist/ezui/p-d20ed286.entry.js +1 -0
- package/dist/types/components/ez-split-panel/structure/item/ez-split-item.d.ts +3 -0
- package/dist/types/components.d.ts +28 -0
- package/package.json +2 -1
- package/react/components.d.ts +2 -0
- package/react/components.js +2 -0
- package/react/components.js.map +1 -1
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
import { r as registerInstance, h, H as Host, g as getElement } from './index-296b8458.js';
|
|
2
|
+
import { StringUtils } from '@sankhyalabs/core';
|
|
3
|
+
|
|
4
|
+
var numeric = function (value, unit) { return Number(value.slice(0, -1 * unit.length)); };
|
|
5
|
+
|
|
6
|
+
var parseValue = function (value) {
|
|
7
|
+
if (value.endsWith('px'))
|
|
8
|
+
{ return { value: value, type: 'px', numeric: numeric(value, 'px') } }
|
|
9
|
+
if (value.endsWith('fr'))
|
|
10
|
+
{ return { value: value, type: 'fr', numeric: numeric(value, 'fr') } }
|
|
11
|
+
if (value.endsWith('%'))
|
|
12
|
+
{ return { value: value, type: '%', numeric: numeric(value, '%') } }
|
|
13
|
+
if (value === 'auto') { return { value: value, type: 'auto' } }
|
|
14
|
+
return null
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var parse = function (rule) { return rule.split(' ').map(parseValue); };
|
|
18
|
+
|
|
19
|
+
var getSizeAtTrack = function (index, tracks, gap, end) {
|
|
20
|
+
if ( gap === void 0 ) { gap = 0; }
|
|
21
|
+
if ( end === void 0 ) { end = false; }
|
|
22
|
+
|
|
23
|
+
var newIndex = end ? index + 1 : index;
|
|
24
|
+
var trackSum = tracks
|
|
25
|
+
.slice(0, newIndex)
|
|
26
|
+
.reduce(function (accum, value) { return accum + value.numeric; }, 0);
|
|
27
|
+
var gapSum = gap ? index * gap : 0;
|
|
28
|
+
|
|
29
|
+
return trackSum + gapSum
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var getStyles = function (rule, ownRules, matchedRules) { return ownRules.concat( matchedRules)
|
|
33
|
+
.map(function (r) { return r.style[rule]; })
|
|
34
|
+
.filter(function (style) { return style !== undefined && style !== ''; }); };
|
|
35
|
+
|
|
36
|
+
var getGapValue = function (unit, size) {
|
|
37
|
+
if (size.endsWith(unit)) {
|
|
38
|
+
return Number(size.slice(0, -1 * unit.length))
|
|
39
|
+
}
|
|
40
|
+
return null
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var firstNonZero = function (tracks) {
|
|
44
|
+
// eslint-disable-next-line no-plusplus
|
|
45
|
+
for (var i = 0; i < tracks.length; i++) {
|
|
46
|
+
if (tracks[i].numeric > 0) {
|
|
47
|
+
return i
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var NOOP = function () { return false; };
|
|
54
|
+
|
|
55
|
+
var defaultWriteStyle = function (element, gridTemplateProp, style) {
|
|
56
|
+
// eslint-disable-next-line no-param-reassign
|
|
57
|
+
element.style[gridTemplateProp] = style;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var getOption = function (options, propName, def) {
|
|
61
|
+
var value = options[propName];
|
|
62
|
+
if (value !== undefined) {
|
|
63
|
+
return value
|
|
64
|
+
}
|
|
65
|
+
return def
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function getMatchedCSSRules (el) {
|
|
69
|
+
var ref;
|
|
70
|
+
|
|
71
|
+
return (ref = [])
|
|
72
|
+
.concat.apply(
|
|
73
|
+
ref, Array.from(el.ownerDocument.styleSheets).map(function (s) {
|
|
74
|
+
var rules = [];
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
rules = Array.from(s.cssRules || []);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
// Ignore results on security error
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return rules
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
.filter(function (r) {
|
|
86
|
+
var matches = false;
|
|
87
|
+
try {
|
|
88
|
+
matches = el.matches(r.selectorText);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
// Ignore matching erros
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return matches
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var gridTemplatePropColumns = 'grid-template-columns';
|
|
98
|
+
var gridTemplatePropRows = 'grid-template-rows';
|
|
99
|
+
|
|
100
|
+
var Gutter = function Gutter(direction, options, parentOptions) {
|
|
101
|
+
this.direction = direction;
|
|
102
|
+
this.element = options.element;
|
|
103
|
+
this.track = options.track;
|
|
104
|
+
|
|
105
|
+
if (direction === 'column') {
|
|
106
|
+
this.gridTemplateProp = gridTemplatePropColumns;
|
|
107
|
+
this.gridGapProp = 'grid-column-gap';
|
|
108
|
+
this.cursor = getOption(
|
|
109
|
+
parentOptions,
|
|
110
|
+
'columnCursor',
|
|
111
|
+
getOption(parentOptions, 'cursor', 'col-resize')
|
|
112
|
+
);
|
|
113
|
+
this.snapOffset = getOption(
|
|
114
|
+
parentOptions,
|
|
115
|
+
'columnSnapOffset',
|
|
116
|
+
getOption(parentOptions, 'snapOffset', 30)
|
|
117
|
+
);
|
|
118
|
+
this.dragInterval = getOption(
|
|
119
|
+
parentOptions,
|
|
120
|
+
'columnDragInterval',
|
|
121
|
+
getOption(parentOptions, 'dragInterval', 1)
|
|
122
|
+
);
|
|
123
|
+
this.clientAxis = 'clientX';
|
|
124
|
+
this.optionStyle = getOption(parentOptions, 'gridTemplateColumns');
|
|
125
|
+
} else if (direction === 'row') {
|
|
126
|
+
this.gridTemplateProp = gridTemplatePropRows;
|
|
127
|
+
this.gridGapProp = 'grid-row-gap';
|
|
128
|
+
this.cursor = getOption(
|
|
129
|
+
parentOptions,
|
|
130
|
+
'rowCursor',
|
|
131
|
+
getOption(parentOptions, 'cursor', 'row-resize')
|
|
132
|
+
);
|
|
133
|
+
this.snapOffset = getOption(
|
|
134
|
+
parentOptions,
|
|
135
|
+
'rowSnapOffset',
|
|
136
|
+
getOption(parentOptions, 'snapOffset', 30)
|
|
137
|
+
);
|
|
138
|
+
this.dragInterval = getOption(
|
|
139
|
+
parentOptions,
|
|
140
|
+
'rowDragInterval',
|
|
141
|
+
getOption(parentOptions, 'dragInterval', 1)
|
|
142
|
+
);
|
|
143
|
+
this.clientAxis = 'clientY';
|
|
144
|
+
this.optionStyle = getOption(parentOptions, 'gridTemplateRows');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this.onDragStart = getOption(parentOptions, 'onDragStart', NOOP);
|
|
148
|
+
this.onDragEnd = getOption(parentOptions, 'onDragEnd', NOOP);
|
|
149
|
+
this.onDrag = getOption(parentOptions, 'onDrag', NOOP);
|
|
150
|
+
this.writeStyle = getOption(
|
|
151
|
+
parentOptions,
|
|
152
|
+
'writeStyle',
|
|
153
|
+
defaultWriteStyle
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
this.startDragging = this.startDragging.bind(this);
|
|
157
|
+
this.stopDragging = this.stopDragging.bind(this);
|
|
158
|
+
this.drag = this.drag.bind(this);
|
|
159
|
+
|
|
160
|
+
this.minSizeStart = options.minSizeStart;
|
|
161
|
+
this.minSizeEnd = options.minSizeEnd;
|
|
162
|
+
|
|
163
|
+
if (options.element) {
|
|
164
|
+
this.element.addEventListener('mousedown', this.startDragging);
|
|
165
|
+
this.element.addEventListener('touchstart', this.startDragging);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
Gutter.prototype.getDimensions = function getDimensions () {
|
|
170
|
+
var ref = this.grid.getBoundingClientRect();
|
|
171
|
+
var width = ref.width;
|
|
172
|
+
var height = ref.height;
|
|
173
|
+
var top = ref.top;
|
|
174
|
+
var bottom = ref.bottom;
|
|
175
|
+
var left = ref.left;
|
|
176
|
+
var right = ref.right;
|
|
177
|
+
|
|
178
|
+
if (this.direction === 'column') {
|
|
179
|
+
this.start = top;
|
|
180
|
+
this.end = bottom;
|
|
181
|
+
this.size = height;
|
|
182
|
+
} else if (this.direction === 'row') {
|
|
183
|
+
this.start = left;
|
|
184
|
+
this.end = right;
|
|
185
|
+
this.size = width;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
Gutter.prototype.getSizeAtTrack = function getSizeAtTrack$1 (track, end) {
|
|
190
|
+
return getSizeAtTrack(
|
|
191
|
+
track,
|
|
192
|
+
this.computedPixels,
|
|
193
|
+
this.computedGapPixels,
|
|
194
|
+
end
|
|
195
|
+
)
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
Gutter.prototype.getSizeOfTrack = function getSizeOfTrack (track) {
|
|
199
|
+
return this.computedPixels[track].numeric
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
Gutter.prototype.getRawTracks = function getRawTracks () {
|
|
203
|
+
var tracks = getStyles(
|
|
204
|
+
this.gridTemplateProp,
|
|
205
|
+
[this.grid],
|
|
206
|
+
getMatchedCSSRules(this.grid)
|
|
207
|
+
);
|
|
208
|
+
if (!tracks.length) {
|
|
209
|
+
if (this.optionStyle) { return this.optionStyle }
|
|
210
|
+
|
|
211
|
+
throw Error('Unable to determine grid template tracks from styles.')
|
|
212
|
+
}
|
|
213
|
+
return tracks[0]
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
Gutter.prototype.getGap = function getGap () {
|
|
217
|
+
var gap = getStyles(
|
|
218
|
+
this.gridGapProp,
|
|
219
|
+
[this.grid],
|
|
220
|
+
getMatchedCSSRules(this.grid)
|
|
221
|
+
);
|
|
222
|
+
if (!gap.length) {
|
|
223
|
+
return null
|
|
224
|
+
}
|
|
225
|
+
return gap[0]
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
Gutter.prototype.getRawComputedTracks = function getRawComputedTracks () {
|
|
229
|
+
return window.getComputedStyle(this.grid)[this.gridTemplateProp]
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
Gutter.prototype.getRawComputedGap = function getRawComputedGap () {
|
|
233
|
+
return window.getComputedStyle(this.grid)[this.gridGapProp]
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
Gutter.prototype.setTracks = function setTracks (raw) {
|
|
237
|
+
this.tracks = raw.split(' ');
|
|
238
|
+
this.trackValues = parse(raw);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
Gutter.prototype.setComputedTracks = function setComputedTracks (raw) {
|
|
242
|
+
this.computedTracks = raw.split(' ');
|
|
243
|
+
this.computedPixels = parse(raw);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
Gutter.prototype.setGap = function setGap (raw) {
|
|
247
|
+
this.gap = raw;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
Gutter.prototype.setComputedGap = function setComputedGap (raw) {
|
|
251
|
+
this.computedGap = raw;
|
|
252
|
+
this.computedGapPixels = getGapValue('px', this.computedGap) || 0;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
Gutter.prototype.getMousePosition = function getMousePosition (e) {
|
|
256
|
+
if ('touches' in e) { return e.touches[0][this.clientAxis] }
|
|
257
|
+
return e[this.clientAxis]
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
Gutter.prototype.startDragging = function startDragging (e) {
|
|
261
|
+
if ('button' in e && e.button !== 0) {
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Don't actually drag the element. We emulate that in the drag function.
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
|
|
268
|
+
if (this.element) {
|
|
269
|
+
this.grid = this.element.parentNode;
|
|
270
|
+
} else {
|
|
271
|
+
this.grid = e.target.parentNode;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
this.getDimensions();
|
|
275
|
+
this.setTracks(this.getRawTracks());
|
|
276
|
+
this.setComputedTracks(this.getRawComputedTracks());
|
|
277
|
+
this.setGap(this.getGap());
|
|
278
|
+
this.setComputedGap(this.getRawComputedGap());
|
|
279
|
+
|
|
280
|
+
var trackPercentage = this.trackValues.filter(
|
|
281
|
+
function (track) { return track.type === '%'; }
|
|
282
|
+
);
|
|
283
|
+
var trackFr = this.trackValues.filter(function (track) { return track.type === 'fr'; });
|
|
284
|
+
|
|
285
|
+
this.totalFrs = trackFr.length;
|
|
286
|
+
|
|
287
|
+
if (this.totalFrs) {
|
|
288
|
+
var track = firstNonZero(trackFr);
|
|
289
|
+
|
|
290
|
+
if (track !== null) {
|
|
291
|
+
this.frToPixels =
|
|
292
|
+
this.computedPixels[track].numeric / trackFr[track].numeric;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (trackPercentage.length) {
|
|
297
|
+
var track$1 = firstNonZero(trackPercentage);
|
|
298
|
+
|
|
299
|
+
if (track$1 !== null) {
|
|
300
|
+
this.percentageToPixels =
|
|
301
|
+
this.computedPixels[track$1].numeric /
|
|
302
|
+
trackPercentage[track$1].numeric;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// get start of gutter track
|
|
307
|
+
var gutterStart = this.getSizeAtTrack(this.track, false) + this.start;
|
|
308
|
+
this.dragStartOffset = this.getMousePosition(e) - gutterStart;
|
|
309
|
+
|
|
310
|
+
this.aTrack = this.track - 1;
|
|
311
|
+
|
|
312
|
+
if (this.track < this.tracks.length - 1) {
|
|
313
|
+
this.bTrack = this.track + 1;
|
|
314
|
+
} else {
|
|
315
|
+
throw Error(
|
|
316
|
+
("Invalid track index: " + (this.track) + ". Track must be between two other tracks and only " + (this.tracks.length) + " tracks were found.")
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
this.aTrackStart = this.getSizeAtTrack(this.aTrack, false) + this.start;
|
|
321
|
+
this.bTrackEnd = this.getSizeAtTrack(this.bTrack, true) + this.start;
|
|
322
|
+
|
|
323
|
+
// Set the dragging property of the pair object.
|
|
324
|
+
this.dragging = true;
|
|
325
|
+
|
|
326
|
+
// All the binding. `window` gets the stop events in case we drag out of the elements.
|
|
327
|
+
window.addEventListener('mouseup', this.stopDragging);
|
|
328
|
+
window.addEventListener('touchend', this.stopDragging);
|
|
329
|
+
window.addEventListener('touchcancel', this.stopDragging);
|
|
330
|
+
window.addEventListener('mousemove', this.drag);
|
|
331
|
+
window.addEventListener('touchmove', this.drag);
|
|
332
|
+
|
|
333
|
+
// Disable selection. Disable!
|
|
334
|
+
this.grid.addEventListener('selectstart', NOOP);
|
|
335
|
+
this.grid.addEventListener('dragstart', NOOP);
|
|
336
|
+
|
|
337
|
+
this.grid.style.userSelect = 'none';
|
|
338
|
+
this.grid.style.webkitUserSelect = 'none';
|
|
339
|
+
this.grid.style.MozUserSelect = 'none';
|
|
340
|
+
this.grid.style.pointerEvents = 'none';
|
|
341
|
+
|
|
342
|
+
// Set the cursor at multiple levels
|
|
343
|
+
this.grid.style.cursor = this.cursor;
|
|
344
|
+
window.document.body.style.cursor = this.cursor;
|
|
345
|
+
|
|
346
|
+
this.onDragStart(this.direction, this.track);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
Gutter.prototype.stopDragging = function stopDragging () {
|
|
350
|
+
this.dragging = false;
|
|
351
|
+
|
|
352
|
+
// Remove the stored event listeners. This is why we store them.
|
|
353
|
+
this.cleanup();
|
|
354
|
+
|
|
355
|
+
this.onDragEnd(this.direction, this.track);
|
|
356
|
+
|
|
357
|
+
if (this.needsDestroy) {
|
|
358
|
+
if (this.element) {
|
|
359
|
+
this.element.removeEventListener(
|
|
360
|
+
'mousedown',
|
|
361
|
+
this.startDragging
|
|
362
|
+
);
|
|
363
|
+
this.element.removeEventListener(
|
|
364
|
+
'touchstart',
|
|
365
|
+
this.startDragging
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
this.destroyCb();
|
|
369
|
+
this.needsDestroy = false;
|
|
370
|
+
this.destroyCb = null;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
Gutter.prototype.drag = function drag (e) {
|
|
375
|
+
var mousePosition = this.getMousePosition(e);
|
|
376
|
+
|
|
377
|
+
var gutterSize = this.getSizeOfTrack(this.track);
|
|
378
|
+
var minMousePosition =
|
|
379
|
+
this.aTrackStart +
|
|
380
|
+
this.minSizeStart +
|
|
381
|
+
this.dragStartOffset +
|
|
382
|
+
this.computedGapPixels;
|
|
383
|
+
var maxMousePosition =
|
|
384
|
+
this.bTrackEnd -
|
|
385
|
+
this.minSizeEnd -
|
|
386
|
+
this.computedGapPixels -
|
|
387
|
+
(gutterSize - this.dragStartOffset);
|
|
388
|
+
var minMousePositionOffset = minMousePosition + this.snapOffset;
|
|
389
|
+
var maxMousePositionOffset = maxMousePosition - this.snapOffset;
|
|
390
|
+
|
|
391
|
+
if (mousePosition < minMousePositionOffset) {
|
|
392
|
+
mousePosition = minMousePosition;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (mousePosition > maxMousePositionOffset) {
|
|
396
|
+
mousePosition = maxMousePosition;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (mousePosition < minMousePosition) {
|
|
400
|
+
mousePosition = minMousePosition;
|
|
401
|
+
} else if (mousePosition > maxMousePosition) {
|
|
402
|
+
mousePosition = maxMousePosition;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
var aTrackSize =
|
|
406
|
+
mousePosition -
|
|
407
|
+
this.aTrackStart -
|
|
408
|
+
this.dragStartOffset -
|
|
409
|
+
this.computedGapPixels;
|
|
410
|
+
var bTrackSize =
|
|
411
|
+
this.bTrackEnd -
|
|
412
|
+
mousePosition +
|
|
413
|
+
this.dragStartOffset -
|
|
414
|
+
gutterSize -
|
|
415
|
+
this.computedGapPixels;
|
|
416
|
+
|
|
417
|
+
if (this.dragInterval > 1) {
|
|
418
|
+
var aTrackSizeIntervaled =
|
|
419
|
+
Math.round(aTrackSize / this.dragInterval) * this.dragInterval;
|
|
420
|
+
bTrackSize -= aTrackSizeIntervaled - aTrackSize;
|
|
421
|
+
aTrackSize = aTrackSizeIntervaled;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (aTrackSize < this.minSizeStart) {
|
|
425
|
+
aTrackSize = this.minSizeStart;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (bTrackSize < this.minSizeEnd) {
|
|
429
|
+
bTrackSize = this.minSizeEnd;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (this.trackValues[this.aTrack].type === 'px') {
|
|
433
|
+
this.tracks[this.aTrack] = aTrackSize + "px";
|
|
434
|
+
} else if (this.trackValues[this.aTrack].type === 'fr') {
|
|
435
|
+
if (this.totalFrs === 1) {
|
|
436
|
+
this.tracks[this.aTrack] = '1fr';
|
|
437
|
+
} else {
|
|
438
|
+
var targetFr = aTrackSize / this.frToPixels;
|
|
439
|
+
this.tracks[this.aTrack] = targetFr + "fr";
|
|
440
|
+
}
|
|
441
|
+
} else if (this.trackValues[this.aTrack].type === '%') {
|
|
442
|
+
var targetPercentage = aTrackSize / this.percentageToPixels;
|
|
443
|
+
this.tracks[this.aTrack] = targetPercentage + "%";
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (this.trackValues[this.bTrack].type === 'px') {
|
|
447
|
+
this.tracks[this.bTrack] = bTrackSize + "px";
|
|
448
|
+
} else if (this.trackValues[this.bTrack].type === 'fr') {
|
|
449
|
+
if (this.totalFrs === 1) {
|
|
450
|
+
this.tracks[this.bTrack] = '1fr';
|
|
451
|
+
} else {
|
|
452
|
+
var targetFr$1 = bTrackSize / this.frToPixels;
|
|
453
|
+
this.tracks[this.bTrack] = targetFr$1 + "fr";
|
|
454
|
+
}
|
|
455
|
+
} else if (this.trackValues[this.bTrack].type === '%') {
|
|
456
|
+
var targetPercentage$1 = bTrackSize / this.percentageToPixels;
|
|
457
|
+
this.tracks[this.bTrack] = targetPercentage$1 + "%";
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
var style = this.tracks.join(' ');
|
|
461
|
+
this.writeStyle(this.grid, this.gridTemplateProp, style);
|
|
462
|
+
this.onDrag(this.direction, this.track, style);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
Gutter.prototype.cleanup = function cleanup () {
|
|
466
|
+
window.removeEventListener('mouseup', this.stopDragging);
|
|
467
|
+
window.removeEventListener('touchend', this.stopDragging);
|
|
468
|
+
window.removeEventListener('touchcancel', this.stopDragging);
|
|
469
|
+
window.removeEventListener('mousemove', this.drag);
|
|
470
|
+
window.removeEventListener('touchmove', this.drag);
|
|
471
|
+
|
|
472
|
+
if (this.grid) {
|
|
473
|
+
this.grid.removeEventListener('selectstart', NOOP);
|
|
474
|
+
this.grid.removeEventListener('dragstart', NOOP);
|
|
475
|
+
|
|
476
|
+
this.grid.style.userSelect = '';
|
|
477
|
+
this.grid.style.webkitUserSelect = '';
|
|
478
|
+
this.grid.style.MozUserSelect = '';
|
|
479
|
+
this.grid.style.pointerEvents = '';
|
|
480
|
+
|
|
481
|
+
this.grid.style.cursor = '';
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
window.document.body.style.cursor = '';
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
Gutter.prototype.destroy = function destroy (immediate, cb) {
|
|
488
|
+
if ( immediate === void 0 ) immediate = true;
|
|
489
|
+
|
|
490
|
+
if (immediate || this.dragging === false) {
|
|
491
|
+
this.cleanup();
|
|
492
|
+
if (this.element) {
|
|
493
|
+
this.element.removeEventListener(
|
|
494
|
+
'mousedown',
|
|
495
|
+
this.startDragging
|
|
496
|
+
);
|
|
497
|
+
this.element.removeEventListener(
|
|
498
|
+
'touchstart',
|
|
499
|
+
this.startDragging
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (cb) {
|
|
504
|
+
cb();
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
this.needsDestroy = true;
|
|
508
|
+
if (cb) {
|
|
509
|
+
this.destroyCb = cb;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
var getTrackOption = function (options, track, defaultValue) {
|
|
515
|
+
if (track in options) {
|
|
516
|
+
return options[track]
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return defaultValue
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
var createGutter = function (direction, options) { return function (gutterOptions) {
|
|
523
|
+
if (gutterOptions.track < 1) {
|
|
524
|
+
throw Error(
|
|
525
|
+
("Invalid track index: " + (gutterOptions.track) + ". Track must be between two other tracks.")
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
var trackMinSizes =
|
|
530
|
+
direction === 'column'
|
|
531
|
+
? options.columnMinSizes || {}
|
|
532
|
+
: options.rowMinSizes || {};
|
|
533
|
+
var trackMinSize = direction === 'column' ? 'columnMinSize' : 'rowMinSize';
|
|
534
|
+
|
|
535
|
+
return new Gutter(
|
|
536
|
+
direction,
|
|
537
|
+
Object.assign({}, {minSizeStart: getTrackOption(
|
|
538
|
+
trackMinSizes,
|
|
539
|
+
gutterOptions.track - 1,
|
|
540
|
+
getOption(
|
|
541
|
+
options,
|
|
542
|
+
trackMinSize,
|
|
543
|
+
getOption(options, 'minSize', 0)
|
|
544
|
+
)
|
|
545
|
+
),
|
|
546
|
+
minSizeEnd: getTrackOption(
|
|
547
|
+
trackMinSizes,
|
|
548
|
+
gutterOptions.track + 1,
|
|
549
|
+
getOption(
|
|
550
|
+
options,
|
|
551
|
+
trackMinSize,
|
|
552
|
+
getOption(options, 'minSize', 0)
|
|
553
|
+
)
|
|
554
|
+
)},
|
|
555
|
+
gutterOptions),
|
|
556
|
+
options
|
|
557
|
+
)
|
|
558
|
+
}; };
|
|
559
|
+
|
|
560
|
+
var Grid = function Grid(options) {
|
|
561
|
+
var this$1 = this;
|
|
562
|
+
|
|
563
|
+
this.columnGutters = {};
|
|
564
|
+
this.rowGutters = {};
|
|
565
|
+
|
|
566
|
+
this.options = Object.assign({}, {columnGutters: options.columnGutters || [],
|
|
567
|
+
rowGutters: options.rowGutters || [],
|
|
568
|
+
columnMinSizes: options.columnMinSizes || {},
|
|
569
|
+
rowMinSizes: options.rowMinSizes || {}},
|
|
570
|
+
options);
|
|
571
|
+
|
|
572
|
+
this.options.columnGutters.forEach(function (gutterOptions) {
|
|
573
|
+
this$1.columnGutters[gutterOptions.track] = createGutter(
|
|
574
|
+
'column',
|
|
575
|
+
this$1.options
|
|
576
|
+
)(gutterOptions);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
this.options.rowGutters.forEach(function (gutterOptions) {
|
|
580
|
+
this$1.rowGutters[gutterOptions.track] = createGutter(
|
|
581
|
+
'row',
|
|
582
|
+
this$1.options
|
|
583
|
+
)(gutterOptions);
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
Grid.prototype.addColumnGutter = function addColumnGutter (element, track) {
|
|
588
|
+
if (this.columnGutters[track]) {
|
|
589
|
+
this.columnGutters[track].destroy();
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
this.columnGutters[track] = createGutter(
|
|
593
|
+
'column',
|
|
594
|
+
this.options
|
|
595
|
+
)({
|
|
596
|
+
element: element,
|
|
597
|
+
track: track,
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
Grid.prototype.addRowGutter = function addRowGutter (element, track) {
|
|
602
|
+
if (this.rowGutters[track]) {
|
|
603
|
+
this.rowGutters[track].destroy();
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
this.rowGutters[track] = createGutter(
|
|
607
|
+
'row',
|
|
608
|
+
this.options
|
|
609
|
+
)({
|
|
610
|
+
element: element,
|
|
611
|
+
track: track,
|
|
612
|
+
});
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
Grid.prototype.removeColumnGutter = function removeColumnGutter (track, immediate) {
|
|
616
|
+
var this$1 = this;
|
|
617
|
+
if ( immediate === void 0 ) immediate = true;
|
|
618
|
+
|
|
619
|
+
if (this.columnGutters[track]) {
|
|
620
|
+
this.columnGutters[track].destroy(immediate, function () {
|
|
621
|
+
delete this$1.columnGutters[track];
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
Grid.prototype.removeRowGutter = function removeRowGutter (track, immediate) {
|
|
627
|
+
var this$1 = this;
|
|
628
|
+
if ( immediate === void 0 ) immediate = true;
|
|
629
|
+
|
|
630
|
+
if (this.rowGutters[track]) {
|
|
631
|
+
this.rowGutters[track].destroy(immediate, function () {
|
|
632
|
+
delete this$1.rowGutters[track];
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
Grid.prototype.handleDragStart = function handleDragStart (e, direction, track) {
|
|
638
|
+
if (direction === 'column') {
|
|
639
|
+
if (this.columnGutters[track]) {
|
|
640
|
+
this.columnGutters[track].destroy();
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
this.columnGutters[track] = createGutter(
|
|
644
|
+
'column',
|
|
645
|
+
this.options
|
|
646
|
+
)({
|
|
647
|
+
track: track,
|
|
648
|
+
});
|
|
649
|
+
this.columnGutters[track].startDragging(e);
|
|
650
|
+
} else if (direction === 'row') {
|
|
651
|
+
if (this.rowGutters[track]) {
|
|
652
|
+
this.rowGutters[track].destroy();
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
this.rowGutters[track] = createGutter(
|
|
656
|
+
'row',
|
|
657
|
+
this.options
|
|
658
|
+
)({
|
|
659
|
+
track: track,
|
|
660
|
+
});
|
|
661
|
+
this.rowGutters[track].startDragging(e);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
Grid.prototype.destroy = function destroy (immediate) {
|
|
666
|
+
var this$1 = this;
|
|
667
|
+
if ( immediate === void 0 ) immediate = true;
|
|
668
|
+
|
|
669
|
+
Object.keys(this.columnGutters).forEach(function (track) { return this$1.columnGutters[track].destroy(immediate, function () {
|
|
670
|
+
delete this$1.columnGutters[track];
|
|
671
|
+
}); }
|
|
672
|
+
);
|
|
673
|
+
Object.keys(this.rowGutters).forEach(function (track) { return this$1.rowGutters[track].destroy(immediate, function () {
|
|
674
|
+
delete this$1.rowGutters[track];
|
|
675
|
+
}); }
|
|
676
|
+
);
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
function index (options) { return new Grid(options); }
|
|
680
|
+
|
|
681
|
+
const ezSplitPanelCss = ".ez-split-gutter{cursor:grab;background-color:transparent}";
|
|
682
|
+
|
|
683
|
+
const SplitPanel = class {
|
|
684
|
+
constructor(hostRef) {
|
|
685
|
+
registerInstance(this, hostRef);
|
|
686
|
+
this._items = [];
|
|
687
|
+
this.direction = 'column';
|
|
688
|
+
}
|
|
689
|
+
componentDidLoad() {
|
|
690
|
+
this._panelID = StringUtils.generateUUID();
|
|
691
|
+
this._element.dataset.panelId = this._panelID;
|
|
692
|
+
let itemsElements = Array.from(this._element.children);
|
|
693
|
+
this._items = itemsElements.filter(child => { var _a; return ((_a = child.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'EZ-SPLIT-ITEM'; });
|
|
694
|
+
let trackCount = 1;
|
|
695
|
+
this._items.forEach((item, index) => {
|
|
696
|
+
item.dataset.trackNumber = trackCount.toString();
|
|
697
|
+
if (this._items.length > 1 && index != this._items.length - 1) {
|
|
698
|
+
this.addItemGutter(item);
|
|
699
|
+
}
|
|
700
|
+
trackCount += 2;
|
|
701
|
+
});
|
|
702
|
+
this.initSplit();
|
|
703
|
+
}
|
|
704
|
+
initSplit() {
|
|
705
|
+
if (!this._items.length) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
this._element.style[this.direction == 'row' ? 'grid-template-rows' : 'grid-template-columns'] = this.getGridTemplate();
|
|
709
|
+
index(this.getGutters());
|
|
710
|
+
}
|
|
711
|
+
getGutters() {
|
|
712
|
+
const gutters = {
|
|
713
|
+
columnGutters: [],
|
|
714
|
+
rowGutters: []
|
|
715
|
+
};
|
|
716
|
+
if (!this._items.length) {
|
|
717
|
+
return gutters;
|
|
718
|
+
}
|
|
719
|
+
const proToChange = this.direction == 'row' ? 'rowGutters' : 'columnGutters';
|
|
720
|
+
this._items.forEach((item, index) => {
|
|
721
|
+
if (index == this._items.length - 1)
|
|
722
|
+
return;
|
|
723
|
+
let gutterTrack = item.dataset.trackNumber;
|
|
724
|
+
if (index === (this._items.length - 1)) {
|
|
725
|
+
gutterTrack = this._items.length.toString();
|
|
726
|
+
}
|
|
727
|
+
gutters[proToChange].push({
|
|
728
|
+
track: Number(gutterTrack),
|
|
729
|
+
element: this._element.querySelector(`ez-split-panel[data-panel-id="${this._panelID}"] > [data-item-track="${item.dataset.trackNumber}"]`)
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
return gutters;
|
|
733
|
+
}
|
|
734
|
+
addItemGutter(item) {
|
|
735
|
+
const gutter = document.createElement('div');
|
|
736
|
+
gutter.classList.add("ez-split-gutter");
|
|
737
|
+
gutter.classList.add(this.direction);
|
|
738
|
+
gutter.dataset.itemTrack = `${item.dataset.trackNumber}`;
|
|
739
|
+
gutter.dataset.trackNumber = (Number(item.dataset.trackNumber) + 1).toString();
|
|
740
|
+
item.parentNode.insertBefore(gutter, item.nextSibling);
|
|
741
|
+
}
|
|
742
|
+
getElementStyle() {
|
|
743
|
+
const style = {
|
|
744
|
+
'display': "grid",
|
|
745
|
+
'height': '100%',
|
|
746
|
+
'width': '100%'
|
|
747
|
+
};
|
|
748
|
+
return style;
|
|
749
|
+
}
|
|
750
|
+
getGridTemplate() {
|
|
751
|
+
let template = '';
|
|
752
|
+
this._items.forEach((_col, index) => {
|
|
753
|
+
if (index === this._items.length - 1) {
|
|
754
|
+
template += ` 1fr`;
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (index === 0) {
|
|
758
|
+
template += `1fr 5px`;
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
template += ` 1fr 5px`;
|
|
762
|
+
});
|
|
763
|
+
return template;
|
|
764
|
+
}
|
|
765
|
+
render() {
|
|
766
|
+
return (h(Host, { style: this.getElementStyle() }));
|
|
767
|
+
}
|
|
768
|
+
get _element() { return getElement(this); }
|
|
769
|
+
};
|
|
770
|
+
SplitPanel.style = ezSplitPanelCss;
|
|
771
|
+
|
|
772
|
+
export { SplitPanel as ez_split_panel };
|