tsgrid-ui 2.7.0 → 2.9.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.
- package/CHANGELOG.md +229 -0
- package/dist/base.d.ts +148 -0
- package/dist/base.es6.js +11 -0
- package/dist/base.es6.js.map +1 -0
- package/dist/chunks/chunk-26XP2XU3.js +1795 -0
- package/dist/chunks/chunk-26XP2XU3.js.map +1 -0
- package/dist/chunks/chunk-3NYH6545.js +2423 -0
- package/dist/chunks/chunk-3NYH6545.js.map +1 -0
- package/dist/chunks/chunk-BIB3X2TW.js +1638 -0
- package/dist/chunks/chunk-BIB3X2TW.js.map +1 -0
- package/dist/chunks/chunk-DXZJHS4M.js +1283 -0
- package/dist/chunks/chunk-DXZJHS4M.js.map +1 -0
- package/dist/chunks/chunk-EVZMMVXO.js +1212 -0
- package/dist/chunks/chunk-EVZMMVXO.js.map +1 -0
- package/dist/chunks/chunk-GJD5NFWQ.js +2305 -0
- package/dist/chunks/chunk-GJD5NFWQ.js.map +1 -0
- package/dist/chunks/chunk-IYF3Q7GX.js +127 -0
- package/dist/chunks/chunk-IYF3Q7GX.js.map +1 -0
- package/dist/chunks/chunk-OFASTA2A.js +2980 -0
- package/dist/chunks/chunk-OFASTA2A.js.map +1 -0
- package/dist/chunks/chunk-OMLGN735.js +677 -0
- package/dist/chunks/chunk-OMLGN735.js.map +1 -0
- package/dist/chunks/chunk-WKSLGUB3.js +1127 -0
- package/dist/chunks/chunk-WKSLGUB3.js.map +1 -0
- package/dist/chunks/chunk-YBY52G2U.js +849 -0
- package/dist/chunks/chunk-YBY52G2U.js.map +1 -0
- package/dist/field.d.ts +329 -0
- package/dist/field.es6.js +11 -0
- package/dist/field.es6.js.map +1 -0
- package/dist/form.d.ts +162 -0
- package/dist/form.es6.js +14 -0
- package/dist/form.es6.js.map +1 -0
- package/dist/layout.d.ts +108 -0
- package/dist/layout.es6.js +13 -0
- package/dist/layout.es6.js.map +1 -0
- package/dist/locale.d.ts +30 -0
- package/dist/locale.es6.js +7 -0
- package/dist/locale.es6.js.map +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/popup.d.ts +92 -0
- package/dist/popup.es6.js +18 -0
- package/dist/popup.es6.js.map +1 -0
- package/dist/query-CKGg5Ugv.d.ts +81 -0
- package/dist/sidebar.d.ts +138 -0
- package/dist/sidebar.es6.js +11 -0
- package/dist/sidebar.es6.js.map +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.es6.js +11 -0
- package/dist/tabs.es6.js.map +1 -0
- package/dist/toolbar.d.ts +97 -0
- package/dist/toolbar.es6.js +11 -0
- package/dist/toolbar.es6.js.map +1 -0
- package/dist/tooltip.d.ts +322 -0
- package/dist/tooltip.es6.js +18 -0
- package/dist/tooltip.es6.js.map +1 -0
- package/dist/tsgrid-ui.css +2 -2
- package/dist/tsgrid-ui.d.ts +16 -2004
- package/dist/tsgrid-ui.es6.js +7750 -23831
- package/dist/tsgrid-ui.es6.js.map +1 -1
- package/dist/tsgrid-ui.es6.min.js +28 -28
- package/dist/tsgrid-ui.js +103 -25
- package/dist/tsgrid-ui.min.css +2 -2
- package/dist/tsgrid-ui.min.js +24 -24
- package/dist/tsutils-message-CogFtVtO.d.ts +82 -0
- package/dist/utils.d.ts +418 -0
- package/dist/utils.es6.js +14 -0
- package/dist/utils.es6.js.map +1 -0
- package/package.json +26 -5
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TsTooltip
|
|
3
|
+
} from "./chunk-OFASTA2A.js";
|
|
4
|
+
import {
|
|
5
|
+
TsUtils
|
|
6
|
+
} from "./chunk-3NYH6545.js";
|
|
7
|
+
import {
|
|
8
|
+
TsBase,
|
|
9
|
+
TsUi,
|
|
10
|
+
query
|
|
11
|
+
} from "./chunk-DXZJHS4M.js";
|
|
12
|
+
|
|
13
|
+
// src/tstabs.ts
|
|
14
|
+
var query2 = query;
|
|
15
|
+
var TsTabs = class extends TsBase {
|
|
16
|
+
// any: targeted-any per typing_policy; TsTabs tab item shape is user-defined at runtime
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
active;
|
|
19
|
+
reorder;
|
|
20
|
+
flow;
|
|
21
|
+
tooltip;
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
tabs;
|
|
24
|
+
// any: tab objects have dynamic shape
|
|
25
|
+
routeData;
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
last;
|
|
28
|
+
// any: accumulates reordering state, observeResize, moving bag
|
|
29
|
+
right;
|
|
30
|
+
style;
|
|
31
|
+
tab_template;
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
constructor(options) {
|
|
34
|
+
super(options.name);
|
|
35
|
+
this.box = null;
|
|
36
|
+
this.name = "";
|
|
37
|
+
this.active = null;
|
|
38
|
+
this.reorder = false;
|
|
39
|
+
this.flow = "down";
|
|
40
|
+
this.tooltip = "top|left";
|
|
41
|
+
this.tabs = [];
|
|
42
|
+
this.routeData = {};
|
|
43
|
+
this.last = {};
|
|
44
|
+
this.right = "";
|
|
45
|
+
this.style = "";
|
|
46
|
+
this["onClick"] = null;
|
|
47
|
+
this["onMouseEnter"] = null;
|
|
48
|
+
this["onMouseLeave"] = null;
|
|
49
|
+
this["onMouseDown"] = null;
|
|
50
|
+
this["onMouseUp"] = null;
|
|
51
|
+
this["onClose"] = null;
|
|
52
|
+
this["onRender"] = null;
|
|
53
|
+
this["onRefresh"] = null;
|
|
54
|
+
this["onResize"] = null;
|
|
55
|
+
this["onDestroy"] = null;
|
|
56
|
+
this.tab_template = {
|
|
57
|
+
id: null,
|
|
58
|
+
text: null,
|
|
59
|
+
icon: null,
|
|
60
|
+
route: null,
|
|
61
|
+
hidden: false,
|
|
62
|
+
disabled: false,
|
|
63
|
+
closable: false,
|
|
64
|
+
tooltip: null,
|
|
65
|
+
style: "",
|
|
66
|
+
onClick: null,
|
|
67
|
+
onRefresh: null,
|
|
68
|
+
onClose: null
|
|
69
|
+
};
|
|
70
|
+
const tabs = options.tabs;
|
|
71
|
+
delete options.tabs;
|
|
72
|
+
Object.assign(this, options);
|
|
73
|
+
if (Array.isArray(tabs)) this.add(tabs);
|
|
74
|
+
options.tabs = tabs;
|
|
75
|
+
if (typeof this.box == "string") this.box = query2(this.box).get(0);
|
|
76
|
+
if (this.box) this.render(this.box);
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
add(tab) {
|
|
80
|
+
return this.insert(null, tab);
|
|
81
|
+
}
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
insert(id, tabs) {
|
|
84
|
+
if (!Array.isArray(tabs)) tabs = [tabs];
|
|
85
|
+
const proms = [];
|
|
86
|
+
tabs.forEach((tab) => {
|
|
87
|
+
if (tab.id == null) {
|
|
88
|
+
console.log(`ERROR: The parameter "id" is required but not supplied. (obj: ${this.name})`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!TsUtils.checkUniqueId(tab.id, this.tabs, "tabs", this.name)) return;
|
|
92
|
+
const it = Object.assign({}, this.tab_template, tab);
|
|
93
|
+
if (id == null) {
|
|
94
|
+
this.tabs.push(it);
|
|
95
|
+
proms.push(this.animateInsert(null, it));
|
|
96
|
+
} else {
|
|
97
|
+
const middle = this.get(id, true);
|
|
98
|
+
const before = this.tabs[middle].id;
|
|
99
|
+
this.tabs.splice(middle, 0, it);
|
|
100
|
+
proms.push(this.animateInsert(before, it));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return Promise.all(proms);
|
|
104
|
+
}
|
|
105
|
+
// any: array of heterogeneous runtime values; TsTabs tab item shape is user-defined at runtime
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
remove(...ids) {
|
|
108
|
+
let effected = 0;
|
|
109
|
+
ids.forEach((it) => {
|
|
110
|
+
const tab = this.get(it);
|
|
111
|
+
if (!tab) return;
|
|
112
|
+
effected++;
|
|
113
|
+
this.tabs.splice(this.get(tab.id, true), 1);
|
|
114
|
+
query2(this.box).find(`#tabs_${this.name}_tab_${TsUtils.escapeId(tab.id)}`).remove();
|
|
115
|
+
});
|
|
116
|
+
this.resize();
|
|
117
|
+
return effected;
|
|
118
|
+
}
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
select(id) {
|
|
121
|
+
if (this.active == id || this.get(id) == null) return false;
|
|
122
|
+
this.active = id;
|
|
123
|
+
this.refresh();
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
+
set(id, tab) {
|
|
128
|
+
const index = this.get(id, true);
|
|
129
|
+
if (index == null) return false;
|
|
130
|
+
TsUtils.extend(this.tabs[index], tab);
|
|
131
|
+
this.refresh(id);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
// any: parameter typed any — runtime dispatch by call site; TsTabs tab item shape is user-defined at runtime
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
|
+
get(id, returnIndex) {
|
|
137
|
+
if (arguments.length === 0) {
|
|
138
|
+
const all = [];
|
|
139
|
+
for (let i1 = 0; i1 < this.tabs.length; i1++) {
|
|
140
|
+
if (this.tabs[i1].id != null) {
|
|
141
|
+
all.push(this.tabs[i1].id);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return all;
|
|
145
|
+
} else {
|
|
146
|
+
for (let i2 = 0; i2 < this.tabs.length; i2++) {
|
|
147
|
+
if (this.tabs[i2].id == id) {
|
|
148
|
+
return returnIndex === true ? i2 : this.tabs[i2];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
// any: array of heterogeneous runtime values; TsTabs tab item shape is user-defined at runtime
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
+
show(...ids) {
|
|
157
|
+
const effected = [];
|
|
158
|
+
ids.forEach((it) => {
|
|
159
|
+
const tab = this.get(it);
|
|
160
|
+
if (!tab || tab.hidden === false) return;
|
|
161
|
+
tab.hidden = false;
|
|
162
|
+
effected.push(tab.id);
|
|
163
|
+
});
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
effected.forEach((it) => {
|
|
166
|
+
this.refresh(it);
|
|
167
|
+
this.resize();
|
|
168
|
+
});
|
|
169
|
+
}, 15);
|
|
170
|
+
return effected;
|
|
171
|
+
}
|
|
172
|
+
// any: array of heterogeneous runtime values; TsTabs tab item shape is user-defined at runtime
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
174
|
+
hide(...ids) {
|
|
175
|
+
const effected = [];
|
|
176
|
+
ids.forEach((it) => {
|
|
177
|
+
const tab = this.get(it);
|
|
178
|
+
if (!tab || tab.hidden === true) return;
|
|
179
|
+
tab.hidden = true;
|
|
180
|
+
effected.push(tab.id);
|
|
181
|
+
});
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
effected.forEach((it) => {
|
|
184
|
+
this.refresh(it);
|
|
185
|
+
this.resize();
|
|
186
|
+
});
|
|
187
|
+
}, 15);
|
|
188
|
+
return effected;
|
|
189
|
+
}
|
|
190
|
+
// any: array of heterogeneous runtime values; TsTabs tab item shape is user-defined at runtime
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
192
|
+
enable(...ids) {
|
|
193
|
+
const effected = [];
|
|
194
|
+
ids.forEach((it) => {
|
|
195
|
+
const tab = this.get(it);
|
|
196
|
+
if (!tab || tab.disabled === false) return;
|
|
197
|
+
tab.disabled = false;
|
|
198
|
+
effected.push(tab.id);
|
|
199
|
+
});
|
|
200
|
+
setTimeout(() => {
|
|
201
|
+
effected.forEach((it) => {
|
|
202
|
+
this.refresh(it);
|
|
203
|
+
});
|
|
204
|
+
}, 15);
|
|
205
|
+
return effected;
|
|
206
|
+
}
|
|
207
|
+
// any: array of heterogeneous runtime values; TsTabs tab item shape is user-defined at runtime
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
209
|
+
disable(...ids) {
|
|
210
|
+
const effected = [];
|
|
211
|
+
ids.forEach((it) => {
|
|
212
|
+
const tab = this.get(it);
|
|
213
|
+
if (!tab || tab.disabled === true) return;
|
|
214
|
+
tab.disabled = true;
|
|
215
|
+
effected.push(tab.id);
|
|
216
|
+
});
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
effected.forEach((it) => {
|
|
219
|
+
this.refresh(it);
|
|
220
|
+
});
|
|
221
|
+
}, 15);
|
|
222
|
+
return effected;
|
|
223
|
+
}
|
|
224
|
+
dragMove(event) {
|
|
225
|
+
if (!this.last.reordering) return;
|
|
226
|
+
const self = this;
|
|
227
|
+
const info = this.last.moving;
|
|
228
|
+
const tab = this.tabs[info.index];
|
|
229
|
+
const next = _find(info.index, 1);
|
|
230
|
+
const prev = _find(info.index, -1);
|
|
231
|
+
const $el = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(tab.id));
|
|
232
|
+
if (info.divX > 0 && next) {
|
|
233
|
+
const $nextEl = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(next.id));
|
|
234
|
+
let width1 = $el.get(0).clientWidth;
|
|
235
|
+
let width2 = $nextEl.get(0).clientWidth;
|
|
236
|
+
if (width1 < width2) {
|
|
237
|
+
width1 = Math.floor(width1 / 3);
|
|
238
|
+
width2 = width2 - width1;
|
|
239
|
+
} else {
|
|
240
|
+
width1 = Math.floor(width2 / 3);
|
|
241
|
+
width2 = width2 - width1;
|
|
242
|
+
}
|
|
243
|
+
if (info.divX > width2) {
|
|
244
|
+
const index = this.tabs.indexOf(next);
|
|
245
|
+
this.tabs.splice(info.index, 0, this.tabs.splice(index, 1)[0]);
|
|
246
|
+
info.$tab.before($nextEl.get(0));
|
|
247
|
+
info.$tab.css("opacity", 0);
|
|
248
|
+
Object.assign(this.last.moving, {
|
|
249
|
+
index,
|
|
250
|
+
divX: -width1,
|
|
251
|
+
x: event.pageX + width1,
|
|
252
|
+
left: info.left + info.divX + width1
|
|
253
|
+
});
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (info.divX < 0 && prev) {
|
|
258
|
+
const $prevEl = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(prev.id));
|
|
259
|
+
let width1 = $el.get(0).clientWidth;
|
|
260
|
+
let width2 = $prevEl.get(0).clientWidth;
|
|
261
|
+
if (width1 < width2) {
|
|
262
|
+
width1 = Math.floor(width1 / 3);
|
|
263
|
+
width2 = width2 - width1;
|
|
264
|
+
} else {
|
|
265
|
+
width1 = Math.floor(width2 / 3);
|
|
266
|
+
width2 = width2 - width1;
|
|
267
|
+
}
|
|
268
|
+
if (Math.abs(info.divX) > width2) {
|
|
269
|
+
const index = this.tabs.indexOf(prev);
|
|
270
|
+
this.tabs.splice(info.index, 0, this.tabs.splice(index, 1)[0]);
|
|
271
|
+
$prevEl.before(info.$tab);
|
|
272
|
+
info.$tab.css("opacity", 0);
|
|
273
|
+
Object.assign(info, {
|
|
274
|
+
index,
|
|
275
|
+
divX: width1,
|
|
276
|
+
x: event.pageX - width1,
|
|
277
|
+
left: info.left + info.divX - width1
|
|
278
|
+
});
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function _find(ind, inc) {
|
|
283
|
+
ind += inc;
|
|
284
|
+
const tab2 = self.tabs[ind];
|
|
285
|
+
if (tab2 && tab2.hidden) {
|
|
286
|
+
return _find(ind, inc);
|
|
287
|
+
}
|
|
288
|
+
return tab2;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
|
+
mouseAction(action, id, event) {
|
|
293
|
+
const tab = this.get(id);
|
|
294
|
+
const edata = this.trigger("mouse" + action, { target: id, tab, object: tab, originalEvent: event });
|
|
295
|
+
if (edata.isCancelled === true || tab?.disabled || tab?.hidden) return;
|
|
296
|
+
switch (action) {
|
|
297
|
+
case "Enter":
|
|
298
|
+
this.tooltipShow(id);
|
|
299
|
+
break;
|
|
300
|
+
case "Leave":
|
|
301
|
+
this.tooltipHide(id);
|
|
302
|
+
break;
|
|
303
|
+
case "Down":
|
|
304
|
+
this.initReorder(id, event);
|
|
305
|
+
break;
|
|
306
|
+
case "Up":
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
edata.finish();
|
|
310
|
+
}
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
312
|
+
tooltipShow(id) {
|
|
313
|
+
const tab = this.get(id);
|
|
314
|
+
const el = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(id)).get(0);
|
|
315
|
+
if (this.tooltip == null || tab?.disabled || this.last.reordering) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const pos = this.tooltip;
|
|
319
|
+
let txt = tab?.tooltip;
|
|
320
|
+
if (typeof txt == "function") txt = txt.call(this, tab);
|
|
321
|
+
TsTooltip.show({
|
|
322
|
+
anchor: el,
|
|
323
|
+
name: this.name + "_tooltip",
|
|
324
|
+
html: txt,
|
|
325
|
+
position: pos
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
329
|
+
tooltipHide(_id) {
|
|
330
|
+
if (this.tooltip == null) return;
|
|
331
|
+
TsTooltip.hide(this.name + "_tooltip");
|
|
332
|
+
}
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
|
+
getTabHTML(id) {
|
|
335
|
+
const index = this.get(id, true);
|
|
336
|
+
const tab = this.tabs[index];
|
|
337
|
+
if (tab == null) return false;
|
|
338
|
+
if (tab.text == null && tab.caption != null) tab.text = tab.caption;
|
|
339
|
+
if (tab.tooltip == null && tab.hint != null) tab.tooltip = tab.hint;
|
|
340
|
+
if (tab.caption != null) {
|
|
341
|
+
console.log("NOTICE: tabs tab.caption property is deprecated, please use tab.text. Tab -> ", tab);
|
|
342
|
+
}
|
|
343
|
+
if (tab.hint != null) {
|
|
344
|
+
console.log("NOTICE: tabs tab.hint property is deprecated, please use tab.tooltip. Tab -> ", tab);
|
|
345
|
+
}
|
|
346
|
+
let text = tab.text;
|
|
347
|
+
if (typeof text == "function") text = text.call(this, tab);
|
|
348
|
+
if (text == null) text = "";
|
|
349
|
+
let closable = "";
|
|
350
|
+
let addStyle = "";
|
|
351
|
+
if (tab.hidden) {
|
|
352
|
+
addStyle += "display: none;";
|
|
353
|
+
}
|
|
354
|
+
if (tab.disabled) {
|
|
355
|
+
addStyle += "opacity: 0.2;";
|
|
356
|
+
}
|
|
357
|
+
if (tab.closable && !tab.disabled) {
|
|
358
|
+
closable = `<div class="tsg-tab-close tsg-eaction ${this.active === tab.id ? "active" : ""}"
|
|
359
|
+
data-mousedown="stop" data-mouseup="clickClose|${tab.id}|event">
|
|
360
|
+
</div>`;
|
|
361
|
+
}
|
|
362
|
+
let icon = "";
|
|
363
|
+
if (tab.icon) {
|
|
364
|
+
icon = `<span class="tsg-tab-icon ${tab.icon}"></span>`;
|
|
365
|
+
}
|
|
366
|
+
return `
|
|
367
|
+
<div id="tabs_${this.name}_tab_${tab.id}" style="${addStyle} ${tab.style}"
|
|
368
|
+
class="tsg-tab tsg-eaction ${this.active === tab.id ? "active" : ""} ${tab.closable ? "closable" : ""} ${tab.class ? tab.class : ""}"
|
|
369
|
+
data-mouseenter="mouseAction|Enter|${tab.id}|event]"
|
|
370
|
+
data-mouseleave="mouseAction|Leave|${tab.id}|event]"
|
|
371
|
+
data-mousedown="mouseAction|Down|${tab.id}|event"
|
|
372
|
+
data-mouseup="mouseAction|Up|${tab.id}|event"
|
|
373
|
+
data-click="click|${tab.id}|event">
|
|
374
|
+
${icon + TsUtils.lang(text) + closable}
|
|
375
|
+
</div>`;
|
|
376
|
+
}
|
|
377
|
+
// any: callback parameter — caller signature varies; TsTabs tab item shape is user-defined at runtime
|
|
378
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
379
|
+
refresh(id) {
|
|
380
|
+
const time = Date.now();
|
|
381
|
+
if (this.flow == "up") {
|
|
382
|
+
query2(this.box).addClass("tsg-tabs-up");
|
|
383
|
+
} else {
|
|
384
|
+
query2(this.box).removeClass("tsg-tabs-up");
|
|
385
|
+
}
|
|
386
|
+
const edata = this.trigger("refresh", { target: id != null ? id : this.name, object: this.get(id) });
|
|
387
|
+
if (edata.isCancelled === true) return;
|
|
388
|
+
if (id == null) {
|
|
389
|
+
for (let i = 0; i < this.tabs.length; i++) {
|
|
390
|
+
this.refresh(this.tabs[i].id);
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
const selector = "#tabs_" + this.name + "_tab_" + TsUtils.escapeId(id);
|
|
394
|
+
const $tab = query2(this.box).find(selector);
|
|
395
|
+
const tabHTML = this.getTabHTML(id);
|
|
396
|
+
if ($tab.length === 0) {
|
|
397
|
+
if (tabHTML) query2(this.box).find("#tabs_" + this.name + "_right").before(tabHTML);
|
|
398
|
+
} else {
|
|
399
|
+
if (query2(this.box).find(".tab-animate-insert").length == 0) {
|
|
400
|
+
if (tabHTML) $tab.replace(tabHTML);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
TsUtils.bindEvents(query2(this.box).find(`${selector}, ${selector} .tsg-eaction`), this);
|
|
404
|
+
}
|
|
405
|
+
query2(this.box).find("#tabs_" + this.name + "_right").html(this.right);
|
|
406
|
+
edata.finish();
|
|
407
|
+
return Date.now() - time;
|
|
408
|
+
}
|
|
409
|
+
// any: callback parameter — caller signature varies; TsTabs tab item shape is user-defined at runtime
|
|
410
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
411
|
+
render(box) {
|
|
412
|
+
const time = Date.now();
|
|
413
|
+
if (typeof box == "string") box = query2(box).get(0);
|
|
414
|
+
const edata = this.trigger("render", { target: this.name, box: box ?? this.box });
|
|
415
|
+
if (edata.isCancelled === true) return;
|
|
416
|
+
if (box != null) {
|
|
417
|
+
this.unmount();
|
|
418
|
+
this.box = box;
|
|
419
|
+
}
|
|
420
|
+
if (!this.box) return false;
|
|
421
|
+
const html = `
|
|
422
|
+
<div class="tsg-tabs-line"></div>
|
|
423
|
+
<div class="tsg-scroll-wrapper tsg-eaction" data-mousedown="resize">
|
|
424
|
+
<div id="tabs_${this.name}_right" class="tsg-tabs-right">${this.right}</div>
|
|
425
|
+
</div>
|
|
426
|
+
<div class="tsg-scroll-left tsg-eaction" data-click='["scroll","left"]'></div>
|
|
427
|
+
<div class="tsg-scroll-right tsg-eaction" data-click='["scroll","right"]'></div>`;
|
|
428
|
+
query2(this.box).attr("name", this.name).addClass("tsg-reset tsg-tabs").html(html);
|
|
429
|
+
if (query2(this.box).length > 0) {
|
|
430
|
+
query2(this.box)[0].style.cssText += this.style;
|
|
431
|
+
}
|
|
432
|
+
TsUtils.bindEvents(query2(this.box).find(".tsg-eaction"), this);
|
|
433
|
+
this.last.observeResize = new ResizeObserver(() => {
|
|
434
|
+
this.resize();
|
|
435
|
+
});
|
|
436
|
+
this.last.observeResize.observe(this.box);
|
|
437
|
+
edata.finish();
|
|
438
|
+
this.refresh();
|
|
439
|
+
this.resize();
|
|
440
|
+
return Date.now() - time;
|
|
441
|
+
}
|
|
442
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
443
|
+
initReorder(id, event) {
|
|
444
|
+
if (!this.reorder) return;
|
|
445
|
+
const self = this;
|
|
446
|
+
const $tab = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(id));
|
|
447
|
+
const tabIndex = this.get(id, true);
|
|
448
|
+
const $ghost = query2($tab.get(0).cloneNode(true));
|
|
449
|
+
let edata;
|
|
450
|
+
$ghost.attr("id", "#tabs_" + this.name + "_tab_ghost");
|
|
451
|
+
this.last.moving = {
|
|
452
|
+
index: tabIndex,
|
|
453
|
+
indexFrom: tabIndex,
|
|
454
|
+
$tab,
|
|
455
|
+
$ghost,
|
|
456
|
+
divX: 0,
|
|
457
|
+
left: $tab.get(0).getBoundingClientRect().left,
|
|
458
|
+
parentX: query2(this.box).get(0).getBoundingClientRect().left,
|
|
459
|
+
x: event.pageX,
|
|
460
|
+
opacity: $tab.css("opacity")
|
|
461
|
+
};
|
|
462
|
+
query2(document).off(".w2uiTabReorder").on("mousemove.w2uiTabReorder", function(event2) {
|
|
463
|
+
const mouseEvent = event2;
|
|
464
|
+
if (!self.last.reordering) {
|
|
465
|
+
edata = self.trigger("reorder", { target: self.tabs[tabIndex].id, indexFrom: tabIndex, tab: self.tabs[tabIndex] });
|
|
466
|
+
if (edata.isCancelled === true) return;
|
|
467
|
+
TsTooltip.hide(self.name + "_tooltip");
|
|
468
|
+
self.last.reordering = true;
|
|
469
|
+
$ghost.addClass("moving");
|
|
470
|
+
$ghost.css({
|
|
471
|
+
"pointer-events": "none",
|
|
472
|
+
"position": "absolute",
|
|
473
|
+
"left": $tab.get(0).getBoundingClientRect().left
|
|
474
|
+
});
|
|
475
|
+
$tab.css("opacity", 0);
|
|
476
|
+
query2(self.box).find(".tsg-scroll-wrapper").append($ghost.get(0));
|
|
477
|
+
query2(self.box).find(".tsg-tab-close").hide();
|
|
478
|
+
}
|
|
479
|
+
self.last.moving.divX = mouseEvent.pageX - self.last.moving.x;
|
|
480
|
+
$ghost.css("left", self.last.moving.left - self.last.moving.parentX + self.last.moving.divX + "px");
|
|
481
|
+
self.dragMove(mouseEvent);
|
|
482
|
+
}).on("mouseup.w2uiTabReorder", function() {
|
|
483
|
+
query2(document).off(".w2uiTabReorder");
|
|
484
|
+
$ghost.css({
|
|
485
|
+
"transition": "0.1s",
|
|
486
|
+
"left": self.last.moving.$tab.get(0).getBoundingClientRect().left - self.last.moving.parentX
|
|
487
|
+
});
|
|
488
|
+
query2(self.box).find(".tsg-tab-close").show();
|
|
489
|
+
$ghost.remove();
|
|
490
|
+
$tab.css({ opacity: self.last.moving.opacity });
|
|
491
|
+
if (self.last.reordering) {
|
|
492
|
+
edata.finish({ indexTo: self.last.moving.index });
|
|
493
|
+
}
|
|
494
|
+
self.last.reordering = false;
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
// any: callback parameter — caller signature varies; TsTabs tab item shape is user-defined at runtime
|
|
498
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
499
|
+
scroll(direction, instant) {
|
|
500
|
+
return new Promise((resolve, _reject) => {
|
|
501
|
+
const scrollBox = query2(this.box).find(".tsg-scroll-wrapper");
|
|
502
|
+
const scrollBoxEl = scrollBox.get(0);
|
|
503
|
+
const scrollLeft = scrollBoxEl.scrollLeft;
|
|
504
|
+
const right = scrollBox.find(".tsg-tabs-right").get(0);
|
|
505
|
+
const width1 = scrollBox.parent().get(0).getBoundingClientRect().width;
|
|
506
|
+
const width2 = scrollLeft + right.offsetLeft + right.clientWidth;
|
|
507
|
+
switch (direction) {
|
|
508
|
+
case "left": {
|
|
509
|
+
let scroll = scrollLeft - width1 + 50;
|
|
510
|
+
if (scroll <= 0) scroll = 0;
|
|
511
|
+
scrollBoxEl.scrollTo({ top: 0, left: scroll, behavior: instant ? "auto" : "smooth" });
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
case "right": {
|
|
515
|
+
let scroll = scrollLeft + width1 - 50;
|
|
516
|
+
if (scroll >= width2 - width1) scroll = width2 - width1;
|
|
517
|
+
scrollBoxEl.scrollTo({ top: 0, left: scroll, behavior: instant ? "auto" : "smooth" });
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
setTimeout(() => {
|
|
522
|
+
this.resize();
|
|
523
|
+
resolve();
|
|
524
|
+
}, instant ? 0 : 350);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
// any: callback parameter — caller signature varies; TsTabs tab item shape is user-defined at runtime
|
|
528
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
529
|
+
scrollIntoView(id, instant) {
|
|
530
|
+
return new Promise((resolve, _reject) => {
|
|
531
|
+
if (id == null) id = this.active;
|
|
532
|
+
const tab = this.get(id);
|
|
533
|
+
if (tab == null) return;
|
|
534
|
+
const tabEl = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(id)).get(0);
|
|
535
|
+
tabEl.scrollIntoView({ block: "start", inline: "center", behavior: instant ? "auto" : "smooth" });
|
|
536
|
+
setTimeout(() => {
|
|
537
|
+
this.resize();
|
|
538
|
+
resolve();
|
|
539
|
+
}, instant ? 0 : 500);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
resize() {
|
|
543
|
+
const time = Date.now();
|
|
544
|
+
if (this.box == null) return;
|
|
545
|
+
const edata = this.trigger("resize", { target: this.name });
|
|
546
|
+
if (edata.isCancelled === true) return;
|
|
547
|
+
if (this.box != null) {
|
|
548
|
+
const box = query2(this.box);
|
|
549
|
+
box.find(".tsg-scroll-left, .tsg-scroll-right").hide();
|
|
550
|
+
const scrollBox = box.find(".tsg-scroll-wrapper").get(0);
|
|
551
|
+
const $right = box.find(".tsg-tabs-right");
|
|
552
|
+
const boxWidth = box.get(0).getBoundingClientRect().width;
|
|
553
|
+
const itemsWidth = $right.length > 0 ? $right[0].offsetLeft + $right[0].clientWidth : 0;
|
|
554
|
+
if (boxWidth < itemsWidth) {
|
|
555
|
+
if (scrollBox.scrollLeft > 0) {
|
|
556
|
+
box.find(".tsg-scroll-left").show();
|
|
557
|
+
}
|
|
558
|
+
if (boxWidth < itemsWidth - scrollBox.scrollLeft) {
|
|
559
|
+
box.find(".tsg-scroll-right").show();
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
edata.finish();
|
|
564
|
+
return Date.now() - time;
|
|
565
|
+
}
|
|
566
|
+
destroy() {
|
|
567
|
+
const edata = this.trigger("destroy", { target: this.name });
|
|
568
|
+
if (edata.isCancelled === true) return;
|
|
569
|
+
if (query2(this.box).find("#tabs_" + this.name + "_right").length > 0) {
|
|
570
|
+
this.unmount();
|
|
571
|
+
}
|
|
572
|
+
delete TsUi[this.name];
|
|
573
|
+
edata.finish();
|
|
574
|
+
}
|
|
575
|
+
unmount() {
|
|
576
|
+
super.unmount();
|
|
577
|
+
this.last.observeResize?.disconnect();
|
|
578
|
+
}
|
|
579
|
+
// ===================================================
|
|
580
|
+
// -- Internal Event Handlers
|
|
581
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
582
|
+
click(id, event) {
|
|
583
|
+
if (event && query2(event.target).hasClass("tsg-tab-close")) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const tab = this.get(id);
|
|
587
|
+
if (tab == null || tab.disabled || this.last.reordering) return false;
|
|
588
|
+
const edata = this.trigger("click", { target: id, tab, object: tab, originalEvent: event });
|
|
589
|
+
if (edata.isCancelled === true) return;
|
|
590
|
+
query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(this.active)).removeClass("active");
|
|
591
|
+
this.active = tab.id;
|
|
592
|
+
query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(this.active)).addClass("active");
|
|
593
|
+
if (typeof tab.route == "string") {
|
|
594
|
+
let route = tab.route !== "" ? String("/" + tab.route).replace(/\/{2,}/g, "/") : "";
|
|
595
|
+
const info = TsUtils.parseRoute(route);
|
|
596
|
+
if (info.keys.length > 0) {
|
|
597
|
+
for (let k = 0; k < info.keys.length; k++) {
|
|
598
|
+
const key = info.keys[k];
|
|
599
|
+
if (key == null || this.routeData[key.name] == null) continue;
|
|
600
|
+
route = route.replace(new RegExp(":" + key.name, "g"), this.routeData[key.name]);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
setTimeout(() => {
|
|
604
|
+
window.location.hash = route;
|
|
605
|
+
}, 1);
|
|
606
|
+
}
|
|
607
|
+
edata.finish();
|
|
608
|
+
}
|
|
609
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
610
|
+
clickClose(id, event) {
|
|
611
|
+
const tab = this.get(id);
|
|
612
|
+
if (tab == null || tab.disabled) return false;
|
|
613
|
+
const edata = this.trigger("close", { target: id, object: tab, tab, originalEvent: event });
|
|
614
|
+
if (edata.isCancelled === true) return;
|
|
615
|
+
this.animateClose(id).then(() => {
|
|
616
|
+
this.remove(id);
|
|
617
|
+
edata.finish();
|
|
618
|
+
this.refresh();
|
|
619
|
+
});
|
|
620
|
+
event?.stopPropagation();
|
|
621
|
+
}
|
|
622
|
+
// any: callback parameter — caller signature varies; TsTabs tab item shape is user-defined at runtime
|
|
623
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
624
|
+
animateClose(id) {
|
|
625
|
+
return new Promise((resolve, _reject) => {
|
|
626
|
+
const $tab = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(id));
|
|
627
|
+
const width = $tab.get(0).clientWidth || 0;
|
|
628
|
+
const anim = `<div class="tab-animate-close" style="display: inline-block; flex-shrink: 0; width: ${width}px; transition: width 0.25s"></div>`;
|
|
629
|
+
const $anim = $tab.replace(anim);
|
|
630
|
+
setTimeout(() => {
|
|
631
|
+
$anim.css({ width: "0px" });
|
|
632
|
+
}, 1);
|
|
633
|
+
setTimeout(() => {
|
|
634
|
+
$anim.remove();
|
|
635
|
+
this.resize();
|
|
636
|
+
resolve();
|
|
637
|
+
}, 500);
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
641
|
+
animateInsert(id, tab) {
|
|
642
|
+
return new Promise((resolve, _reject) => {
|
|
643
|
+
let $before = query2(this.box).find("#tabs_" + this.name + "_tab_" + TsUtils.escapeId(id));
|
|
644
|
+
const tabHTML = this.getTabHTML(tab.id);
|
|
645
|
+
const $tab = query.html(tabHTML);
|
|
646
|
+
if ($before.length == 0) {
|
|
647
|
+
$before = query2(this.box).find("#tabs_tabs_right");
|
|
648
|
+
$before.before($tab);
|
|
649
|
+
this.resize();
|
|
650
|
+
} else {
|
|
651
|
+
$tab.css({ opacity: 0 });
|
|
652
|
+
query2(this.box).find("#tabs_tabs_right").before($tab.get(0));
|
|
653
|
+
const $tmp = query2(this.box).find("#" + $tab.attr("id"));
|
|
654
|
+
const width = $tmp.get(0)?.clientWidth ?? 0;
|
|
655
|
+
const $anim = query.html('<div class="tab-animate-insert" style="flex-shrink: 0; width: 0; transition: width 0.25s"></div>');
|
|
656
|
+
$before.before($anim);
|
|
657
|
+
$tab.hide();
|
|
658
|
+
$anim.before($tab[0]);
|
|
659
|
+
setTimeout(() => {
|
|
660
|
+
$anim.css({ width: width + "px" });
|
|
661
|
+
}, 1);
|
|
662
|
+
setTimeout(() => {
|
|
663
|
+
$anim.remove();
|
|
664
|
+
$tab.css({ opacity: 1 }).show();
|
|
665
|
+
this.refresh(tab.id);
|
|
666
|
+
this.resize();
|
|
667
|
+
resolve();
|
|
668
|
+
}, 500);
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
export {
|
|
675
|
+
TsTabs
|
|
676
|
+
};
|
|
677
|
+
//# sourceMappingURL=chunk-OMLGN735.js.map
|