tsgrid-ui 2.7.1 → 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.
Files changed (68) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/dist/base.d.ts +148 -0
  3. package/dist/base.es6.js +11 -0
  4. package/dist/base.es6.js.map +1 -0
  5. package/dist/chunks/chunk-26XP2XU3.js +1795 -0
  6. package/dist/chunks/chunk-26XP2XU3.js.map +1 -0
  7. package/dist/chunks/chunk-3NYH6545.js +2423 -0
  8. package/dist/chunks/chunk-3NYH6545.js.map +1 -0
  9. package/dist/chunks/chunk-BIB3X2TW.js +1638 -0
  10. package/dist/chunks/chunk-BIB3X2TW.js.map +1 -0
  11. package/dist/chunks/chunk-DXZJHS4M.js +1283 -0
  12. package/dist/chunks/chunk-DXZJHS4M.js.map +1 -0
  13. package/dist/chunks/chunk-EVZMMVXO.js +1212 -0
  14. package/dist/chunks/chunk-EVZMMVXO.js.map +1 -0
  15. package/dist/chunks/chunk-GJD5NFWQ.js +2305 -0
  16. package/dist/chunks/chunk-GJD5NFWQ.js.map +1 -0
  17. package/dist/chunks/chunk-IYF3Q7GX.js +127 -0
  18. package/dist/chunks/chunk-IYF3Q7GX.js.map +1 -0
  19. package/dist/chunks/chunk-OFASTA2A.js +2980 -0
  20. package/dist/chunks/chunk-OFASTA2A.js.map +1 -0
  21. package/dist/chunks/chunk-OMLGN735.js +677 -0
  22. package/dist/chunks/chunk-OMLGN735.js.map +1 -0
  23. package/dist/chunks/chunk-WKSLGUB3.js +1127 -0
  24. package/dist/chunks/chunk-WKSLGUB3.js.map +1 -0
  25. package/dist/chunks/chunk-YBY52G2U.js +849 -0
  26. package/dist/chunks/chunk-YBY52G2U.js.map +1 -0
  27. package/dist/field.d.ts +329 -0
  28. package/dist/field.es6.js +11 -0
  29. package/dist/field.es6.js.map +1 -0
  30. package/dist/form.d.ts +162 -0
  31. package/dist/form.es6.js +14 -0
  32. package/dist/form.es6.js.map +1 -0
  33. package/dist/layout.d.ts +108 -0
  34. package/dist/layout.es6.js +13 -0
  35. package/dist/layout.es6.js.map +1 -0
  36. package/dist/locale.d.ts +30 -0
  37. package/dist/locale.es6.js +7 -0
  38. package/dist/locale.es6.js.map +1 -0
  39. package/dist/metafile-esm.json +1 -0
  40. package/dist/popup.d.ts +92 -0
  41. package/dist/popup.es6.js +18 -0
  42. package/dist/popup.es6.js.map +1 -0
  43. package/dist/query-CKGg5Ugv.d.ts +81 -0
  44. package/dist/sidebar.d.ts +138 -0
  45. package/dist/sidebar.es6.js +11 -0
  46. package/dist/sidebar.es6.js.map +1 -0
  47. package/dist/tabs.d.ts +63 -0
  48. package/dist/tabs.es6.js +11 -0
  49. package/dist/tabs.es6.js.map +1 -0
  50. package/dist/toolbar.d.ts +97 -0
  51. package/dist/toolbar.es6.js +11 -0
  52. package/dist/toolbar.es6.js.map +1 -0
  53. package/dist/tooltip.d.ts +322 -0
  54. package/dist/tooltip.es6.js +18 -0
  55. package/dist/tooltip.es6.js.map +1 -0
  56. package/dist/tsgrid-ui.css +2 -2
  57. package/dist/tsgrid-ui.d.ts +16 -2004
  58. package/dist/tsgrid-ui.es6.js +7750 -23830
  59. package/dist/tsgrid-ui.es6.js.map +1 -1
  60. package/dist/tsgrid-ui.es6.min.js +28 -28
  61. package/dist/tsgrid-ui.js +96 -17
  62. package/dist/tsgrid-ui.min.css +2 -2
  63. package/dist/tsgrid-ui.min.js +24 -24
  64. package/dist/tsutils-message-CogFtVtO.d.ts +82 -0
  65. package/dist/utils.d.ts +418 -0
  66. package/dist/utils.es6.js +14 -0
  67. package/dist/utils.es6.js.map +1 -0
  68. package/package.json +26 -5
@@ -0,0 +1,849 @@
1
+ import {
2
+ TsUtils
3
+ } from "./chunk-3NYH6545.js";
4
+ import {
5
+ TsBase,
6
+ query
7
+ } from "./chunk-DXZJHS4M.js";
8
+
9
+ // src/tspopup.ts
10
+ var query2 = query;
11
+ var TsDialog = class extends TsBase {
12
+ defaults;
13
+ options;
14
+ status;
15
+ tmp;
16
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ handleResize;
19
+ _promCreated;
20
+ _promOpened;
21
+ _promClosing;
22
+ _promClosed;
23
+ _timer;
24
+ constructor() {
25
+ super();
26
+ this.defaults = {
27
+ title: "",
28
+ text: "",
29
+ // just a text (will be centered)
30
+ body: "",
31
+ buttons: "",
32
+ width: 450,
33
+ height: 250,
34
+ focus: null,
35
+ // brings focus to the element, can be a number or selector
36
+ actions: null,
37
+ // actions object
38
+ style: "",
39
+ // style of the message div
40
+ speed: 0.3,
41
+ blockPage: true,
42
+ modal: false,
43
+ maximized: false,
44
+ // this is a flag to show the state - to open the popup maximized use openMaximized instead
45
+ keyboard: true,
46
+ // will close popup on esc if not modal
47
+ showClose: true,
48
+ showMax: false,
49
+ resizable: false,
50
+ transition: null,
51
+ openMaximized: false,
52
+ moved: false
53
+ };
54
+ this.name = "popup";
55
+ this.status = "closed";
56
+ this["onOpen"] = null;
57
+ this["onClose"] = null;
58
+ this["onMax"] = null;
59
+ this["onMin"] = null;
60
+ this["onToggle"] = null;
61
+ this["onKeydown"] = null;
62
+ this["onAction"] = null;
63
+ this["onMove"] = null;
64
+ this.tmp = {};
65
+ this.handleResize = (_event) => {
66
+ if (!this.options.moved) {
67
+ this.center(void 0, void 0, true);
68
+ }
69
+ };
70
+ }
71
+ /**
72
+ * Sample calls
73
+ * - TsPopup.open('ddd').ok(() => { TsPopup.close() })
74
+ * - TsPopup.open('ddd', { height: 120 }).ok(() => { TsPopup.close() })
75
+ * - TsPopup.open({ body: 'text', title: 'caption', actions: ["Close"] }).close(() => { TsPopup.close() })
76
+ * - TsPopup.open({ body: 'text', title: 'caption', actions: { Close() { TsPopup.close() }} })
77
+ */
78
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ open(options, extraOptions) {
81
+ const self = this;
82
+ if (this.status == "closing" || query2("#tsg-popup").hasClass("animating")) {
83
+ this.close(true);
84
+ }
85
+ const old_options = this.options;
86
+ if (["string", "number"].includes(typeof options)) {
87
+ options = TsUtils.extend({
88
+ title: "Notification",
89
+ body: `<div class="tsg-centered">${options}</div>`,
90
+ actions: { Ok() {
91
+ self.close();
92
+ } },
93
+ cancelAction: "ok"
94
+ }, extraOptions ?? {});
95
+ }
96
+ if (options.text != null) options.body = `<div class="tsg-centered tsg-msg-text">${options.text}</div>`;
97
+ options = Object.assign({}, this.defaults, old_options, { title: "", body: "" }, options, { maximized: false });
98
+ this.options = options;
99
+ if (query2("#tsg-popup").length === 0) {
100
+ this.off("*");
101
+ Object.keys(this).forEach((key) => {
102
+ if (key.startsWith("on") && key != "on") this[key] = null;
103
+ });
104
+ }
105
+ Object.keys(options).forEach((key) => {
106
+ if (key.startsWith("on") && key != "on" && options[key]) {
107
+ this[key] = options[key];
108
+ }
109
+ });
110
+ options.width = parseInt(options.width);
111
+ options.height = parseInt(options.height);
112
+ let edata, msg;
113
+ const { top, left, width, height } = this.center();
114
+ if (options.width > width) options.width = width;
115
+ if (options.height > height) options.height = height;
116
+ const prom = {
117
+ self: this,
118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
+ action(callBack) {
120
+ self.on("action.prom", callBack);
121
+ return prom;
122
+ },
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ close(callBack) {
125
+ self.on("close.prom", callBack);
126
+ return prom;
127
+ },
128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
+ then(callBack) {
130
+ self.on("open:after.prom", callBack);
131
+ return prom;
132
+ }
133
+ };
134
+ if (options.actions != null && !options.buttons) {
135
+ options.buttons = "";
136
+ Object.keys(options.actions).forEach((action) => {
137
+ const handler = options.actions[action];
138
+ let btnAction = action;
139
+ if (typeof handler == "function") {
140
+ options.buttons += `<button class="tsg-btn tsg-eaction" name="${action}" data-click='["action","${action}","event"]'>${action}</button>`;
141
+ }
142
+ if (typeof handler == "object") {
143
+ options.buttons += `<button class="tsg-btn tsg-eaction ${handler.class || ""}" name="${action}" data-click='["action","${action}","event"]'
144
+ style="${handler.style}" ${handler.attrs}>${handler.text || action}</button>`;
145
+ btnAction = Array.isArray(options.actions) ? handler.text : action;
146
+ }
147
+ if (typeof handler == "string") {
148
+ if (handler.trim().startsWith("<")) {
149
+ btnAction = "none";
150
+ options.buttons += handler;
151
+ } else {
152
+ btnAction = (handler[0] ?? "").toLowerCase() + handler.substr(1).replace(/\s+/g, "");
153
+ options.buttons += `<button class="tsg-btn tsg-eaction" name="${action}" data-click='["action","${btnAction}","event"]'>${handler}</button>`;
154
+ }
155
+ }
156
+ if (typeof btnAction == "string") {
157
+ btnAction = (btnAction[0] ?? "").toLowerCase() + btnAction.substr(1).replace(/\s+/g, "");
158
+ }
159
+ prom[btnAction] = function(callBack) {
160
+ self.on("action.buttons", (event) => {
161
+ const target = (event.detail.action[0] ?? "").toLowerCase() + event.detail.action.substr(1).replace(/\s+/g, "");
162
+ if (target == btnAction) callBack(event);
163
+ });
164
+ return prom;
165
+ };
166
+ });
167
+ }
168
+ let titleBtns = "";
169
+ if (options.showClose) {
170
+ titleBtns += `<div class="tsg-popup-button tsg-popup-close">
171
+ <span class="tsg-icon tsg-icon-cross tsg-eaction" data-mousedown="stop" data-click="close"></span>
172
+ </div>`;
173
+ }
174
+ if (options.showMax) {
175
+ titleBtns += `<div class="tsg-popup-button tsg-popup-max">
176
+ <span class="tsg-icon tsg-icon-box tsg-eaction" data-mousedown="stop" data-click="toggle"></span>
177
+ </div>`;
178
+ }
179
+ if (query2("#tsg-popup").length === 0) {
180
+ edata = this.trigger("open", { target: "popup", present: false });
181
+ if (edata.isCancelled === true) return;
182
+ this.status = "opening";
183
+ if (options.blockPage) {
184
+ TsUtils.lock(document.body, {
185
+ opacity: 0.3,
186
+ ...options.modal ? {} : { onClick: () => {
187
+ this.close();
188
+ } }
189
+ });
190
+ }
191
+ let styles = `
192
+ left: ${left}px;
193
+ top: ${top}px;
194
+ width: ${parseInt(options.width)}px;
195
+ height: ${parseInt(options.height)}px;
196
+ transition: ${options.speed}s
197
+ `;
198
+ msg = `<div id="tsg-popup" class="tsg-popup tsg-anim-open animating ${!options.blockPage ? "tsg-non-blocking" : ""}" style="${TsUtils.stripSpaces(styles)}"></div>`;
199
+ query2("body").append(msg);
200
+ query2("#tsg-popup")[0]._w2popup = {
201
+ self: this,
202
+ created: new Promise((resolve) => {
203
+ this._promCreated = resolve;
204
+ }),
205
+ opened: new Promise((resolve) => {
206
+ this._promOpened = resolve;
207
+ }),
208
+ closing: new Promise((resolve) => {
209
+ this._promClosing = resolve;
210
+ }),
211
+ closed: new Promise((resolve) => {
212
+ this._promClosed = resolve;
213
+ })
214
+ };
215
+ styles = `${!options.title ? "top: 0px !important;" : ""} ${!options.buttons ? "bottom: 0px !important;" : ""}`;
216
+ msg = `
217
+ <span name="hidden-first" tabindex="0" style="position: absolute; top: -100px"></span>
218
+ <div class="tsg-popup-title-btns">${titleBtns}</div>
219
+ <div class="tsg-popup-title" style="${!options.title ? "display: none" : ""}"></div>
220
+ <div class="tsg-box" style="${styles}">
221
+ <div class="tsg-popup-body ${!options.title || " tsg-popup-no-title"}
222
+ ${!options.buttons || " tsg-popup-no-buttons"}" style="${options.style}">
223
+ </div>
224
+ </div>
225
+ <div class="tsg-popup-buttons" style="${!options.buttons ? "display: none" : ""}"></div>
226
+ <div class="tsg-popup-resizer resize-point resize-icon"></div>
227
+ <span name="hidden-last" tabindex="0" style="position: absolute; top: -100px"></span>
228
+ `;
229
+ query2("#tsg-popup").html(msg);
230
+ if (options.title) query2("#tsg-popup .tsg-popup-title").append(TsUtils.lang(options.title));
231
+ if (options.buttons) query2("#tsg-popup .tsg-popup-buttons").append(options.buttons);
232
+ if (options.body) query2("#tsg-popup .tsg-popup-body").append(options.body);
233
+ setTimeout(() => {
234
+ ;
235
+ query2("#tsg-popup").css("transition", options.speed + "s").removeClass("tsg-anim-open");
236
+ TsUtils.bindEvents("#tsg-popup .tsg-eaction", this);
237
+ query2("#tsg-popup").find(".tsg-popup-body").show();
238
+ this._promCreated();
239
+ }, 1);
240
+ clearTimeout(this._timer);
241
+ this._timer = setTimeout(() => {
242
+ this.status = "open";
243
+ self.setFocus(options.focus);
244
+ edata.finish();
245
+ this._promOpened();
246
+ query2("#tsg-popup").removeClass("animating");
247
+ }, options.speed * 1e3);
248
+ } else {
249
+ edata = this.trigger("open", { target: "popup", present: true });
250
+ if (edata.isCancelled === true) return;
251
+ this.status = "opening";
252
+ if (old_options != null) {
253
+ if (!old_options.maximized && (old_options.width != options.width || old_options.height != options.height)) {
254
+ this.resize(options.width, options.height);
255
+ }
256
+ options.prevSize = options.width + "px:" + options.height + "px";
257
+ options.maximized = old_options.maximized;
258
+ }
259
+ const cloned = query2("#tsg-popup .tsg-box").get(0).cloneNode(true);
260
+ query2(cloned).removeClass("tsg-box").addClass("tsg-box-temp").find(".tsg-popup-body").empty().append(options.body);
261
+ query2("#tsg-popup .tsg-box").after(cloned);
262
+ if (options.buttons) {
263
+ ;
264
+ query2("#tsg-popup .tsg-popup-buttons").show().html("").append(options.buttons);
265
+ query2("#tsg-popup .tsg-popup-body").removeClass("tsg-popup-no-buttons");
266
+ query2("#tsg-popup .tsg-box, #tsg-popup .tsg-box-temp").css("bottom", "");
267
+ } else {
268
+ query2("#tsg-popup .tsg-popup-buttons").hide().html("");
269
+ query2("#tsg-popup .tsg-popup-body").addClass("tsg-popup-no-buttons");
270
+ query2("#tsg-popup .tsg-box, #tsg-popup .tsg-box-temp").css("bottom", "0px");
271
+ }
272
+ if (options.title) {
273
+ query2("#tsg-popup .tsg-popup-title").show().html(TsUtils.lang(options.title));
274
+ query2("#tsg-popup .tsg-popup-body").removeClass("tsg-popup-no-title");
275
+ query2("#tsg-popup .tsg-box, #tsg-popup .tsg-box-temp").css("top", "");
276
+ } else {
277
+ query2("#tsg-popup .tsg-popup-title").hide().html("");
278
+ query2("#tsg-popup .tsg-popup-body").addClass("tsg-popup-no-title");
279
+ query2("#tsg-popup .tsg-box, #tsg-popup .tsg-box-temp").css("top", "0px");
280
+ }
281
+ if (titleBtns) {
282
+ query2("#tsg-popup .tsg-popup-title-btns").show().html(titleBtns);
283
+ } else {
284
+ query2("#tsg-popup .tsg-popup-title-btns").hide();
285
+ }
286
+ const div_old = query2("#tsg-popup .tsg-box")[0];
287
+ const div_new = query2("#tsg-popup .tsg-box-temp")[0];
288
+ query2("#tsg-popup").addClass("animating");
289
+ TsUtils.transition(div_old, div_new, options.transition, () => {
290
+ query2(div_old).remove();
291
+ query2(div_new).removeClass("tsg-box-temp").addClass("tsg-box");
292
+ const $body = query2(div_new).find(".tsg-popup-body");
293
+ if ($body.length == 1) {
294
+ $body[0].style.cssText = options.style;
295
+ $body.show();
296
+ }
297
+ self.setFocus(options.focus);
298
+ query2("#tsg-popup").removeClass("animating");
299
+ });
300
+ this.status = "open";
301
+ edata.finish();
302
+ TsUtils.bindEvents("#tsg-popup .tsg-eaction", this);
303
+ query2("#tsg-popup").find(".tsg-popup-body").show();
304
+ }
305
+ if (options.openMaximized) {
306
+ this.max();
307
+ }
308
+ options._last_focus = document.activeElement;
309
+ if (options.keyboard) {
310
+ query2(document.body).off(".TsPopup").on("keydown.TsPopup", (event) => {
311
+ this.keydown(event);
312
+ });
313
+ }
314
+ query2(window).on("resize", this.handleResize);
315
+ const tmp = {
316
+ changing: false,
317
+ mvMove,
318
+ mvStop
319
+ };
320
+ query2("#tsg-popup .tsg-popup-title").off("mousedown").on("mousedown", function(event) {
321
+ if (!self.options.maximized) mvStart(event);
322
+ });
323
+ if (options.resizable) {
324
+ query2("#tsg-popup .tsg-popup-resizer").show();
325
+ query2("#tsg-popup .tsg-popup-resizer").off("mousedown").on("mousedown", (event) => {
326
+ mvStart(event, true);
327
+ });
328
+ } else {
329
+ query2("#tsg-popup .tsg-popup-resizer").hide();
330
+ }
331
+ return prom;
332
+ function mvStart(evt, resizer) {
333
+ if (!evt) evt = window.event;
334
+ self.status = resizer ? "resizing" : "moving";
335
+ const rect = query2("#tsg-popup").get(0).getBoundingClientRect();
336
+ Object.assign(tmp, {
337
+ changing: true,
338
+ isLocked: query2("#tsg-popup > .tsg-lock").length == 1 ? true : false,
339
+ x: evt.screenX,
340
+ y: evt.screenY,
341
+ pos_x: rect.x,
342
+ pos_y: rect.y,
343
+ width: rect.width,
344
+ height: rect.height
345
+ });
346
+ if (!tmp.isLocked) self.lock({ opacity: 0 });
347
+ query2(document.body).on("mousemove.tsg-popup", tmp.mvMove).on("mouseup.tsg-popup", tmp.mvStop);
348
+ if (evt.stopPropagation) evt.stopPropagation();
349
+ else evt.cancelBubble = true;
350
+ if (evt.preventDefault) evt.preventDefault();
351
+ else return false;
352
+ }
353
+ function mvMove(evt) {
354
+ if (tmp.changing != true) return;
355
+ if (!evt) evt = window.event;
356
+ tmp.div_x = evt.screenX - tmp.x;
357
+ tmp.div_y = evt.screenY - tmp.y;
358
+ const edata2 = self.trigger("move", { target: "popup", div_x: tmp.div_x, div_y: tmp.div_y, originalEvent: evt });
359
+ if (edata2.isCancelled === true) return;
360
+ if (self.status == "moving") {
361
+ query2("#tsg-popup").css({
362
+ "transition": "none",
363
+ "transform": "translate3d(" + tmp.div_x + "px, " + tmp.div_y + "px, 0px)"
364
+ });
365
+ self.options.moved = true;
366
+ } else {
367
+ query2("#tsg-popup").css({
368
+ transition: "none",
369
+ width: tmp.width + tmp.div_x + "px",
370
+ height: tmp.height + tmp.div_y + "px"
371
+ });
372
+ }
373
+ edata2.finish();
374
+ }
375
+ function mvStop(evt) {
376
+ if (tmp.changing != true) return;
377
+ if (!evt) evt = window.event;
378
+ tmp.div_x = evt.screenX - tmp.x;
379
+ tmp.div_y = evt.screenY - tmp.y;
380
+ if (self.status == "moving") {
381
+ ;
382
+ query2("#tsg-popup").css({
383
+ "left": tmp.pos_x + tmp.div_x + "px",
384
+ "top": tmp.pos_y + tmp.div_y + "px"
385
+ }).css({
386
+ "transition": "none",
387
+ "transform": "translate3d(0px, 0px, 0px)"
388
+ });
389
+ } else {
390
+ query2("#tsg-popup").css({
391
+ transition: "none",
392
+ width: tmp.width + tmp.div_x + "px",
393
+ height: tmp.height + tmp.div_y + "px"
394
+ });
395
+ self.resizeMessages();
396
+ }
397
+ tmp.changing = false;
398
+ self.status = "open";
399
+ query2(document.body).off(".tsg-popup");
400
+ if (!tmp.isLocked) self.unlock();
401
+ }
402
+ }
403
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
404
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
405
+ load(options) {
406
+ return new Promise((resolve, reject) => {
407
+ if (typeof options == "string") {
408
+ options = { url: options };
409
+ }
410
+ if (options.url == null) {
411
+ console.log("ERROR: The url is not defined.");
412
+ reject("The url is not defined");
413
+ return;
414
+ }
415
+ this.status = "loading";
416
+ const [url, selector] = String(options.url).split("#");
417
+ if (url) {
418
+ fetch(url).then((res) => res.text()).then((html) => {
419
+ resolve(this.template(html, selector, options));
420
+ });
421
+ }
422
+ });
423
+ }
424
+ // any: parameter typed any — runtime dispatch by call site; TsPopup options accept untyped user payloads at runtime
425
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
426
+ template(data, id, options = {}) {
427
+ let html;
428
+ try {
429
+ html = query2(data);
430
+ } catch (e) {
431
+ html = query.html(data);
432
+ }
433
+ if (id) html = html.filter("#" + id);
434
+ Object.assign(options, {
435
+ width: parseInt(query2(html).css("width")),
436
+ height: parseInt(query2(html).css("height")),
437
+ title: query2(html).find("[rel=title]").html(),
438
+ body: query2(html).find("[rel=body]").html(),
439
+ buttons: query2(html).find("[rel=buttons]").html(),
440
+ style: query2(html).find("[rel=body]").get(0).style.cssText
441
+ });
442
+ return this.open(options);
443
+ }
444
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
445
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
446
+ action(action, event) {
447
+ let click = this.options.actions?.[action];
448
+ if (click instanceof Object && click.onClick) click = click.onClick;
449
+ const edata = this.trigger("action", {
450
+ action,
451
+ target: "popup",
452
+ self: this,
453
+ // any: cast-to-any for dynamic dispatch; TsPopup options accept untyped user payloads at runtime
454
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
455
+ originalEvent: event,
456
+ value: this["input"] ? this["input"].value : null
457
+ });
458
+ if (edata.isCancelled === true) return;
459
+ if (typeof click === "function") click.call(this, event);
460
+ edata.finish();
461
+ }
462
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
463
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
464
+ keydown(event) {
465
+ if (this.options && !this.options.keyboard) return;
466
+ const edata = this.trigger("keydown", { target: "popup", originalEvent: event });
467
+ if (edata.isCancelled === true) return;
468
+ switch (event.keyCode) {
469
+ case 27:
470
+ event.preventDefault();
471
+ if (query2("#tsg-popup .tsg-message").length == 0) {
472
+ if (this.options.cancelAction) {
473
+ this.action(this.options.cancelAction);
474
+ } else {
475
+ this.close();
476
+ }
477
+ }
478
+ break;
479
+ }
480
+ edata.finish();
481
+ }
482
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
483
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
484
+ close(immediate) {
485
+ const edata = this.trigger("close", { target: "popup" });
486
+ if (edata.isCancelled === true) return;
487
+ const cleanUp = () => {
488
+ query2("#tsg-popup").remove();
489
+ if (this.options._last_focus) this.options._last_focus.focus();
490
+ this.status = "closed";
491
+ this.options = {};
492
+ edata.finish();
493
+ this._promClosed();
494
+ };
495
+ if (query2("#tsg-popup").length === 0 || this.status == "closed") {
496
+ return;
497
+ }
498
+ if (this.status == "opening") {
499
+ immediate = true;
500
+ }
501
+ if (this.status == "closing" && immediate === true) {
502
+ cleanUp();
503
+ clearTimeout(this.tmp["closingTimer"]);
504
+ TsUtils.unlock(document.body, 0);
505
+ return;
506
+ }
507
+ this.status = "closing";
508
+ query2("#tsg-popup").css("transition", this.options.speed + "s").addClass("tsg-anim-close animating");
509
+ TsUtils.unlock(document.body, 300);
510
+ this._promClosing();
511
+ if (immediate) {
512
+ cleanUp();
513
+ } else {
514
+ this.tmp["closingTimer"] = setTimeout(cleanUp, (this.options.speed ?? 0.3) * 1e3);
515
+ }
516
+ if (this.options.keyboard) {
517
+ query2(document.body).off("keydown", this.keydown);
518
+ }
519
+ query2(window).off("resize", this.handleResize);
520
+ }
521
+ toggle() {
522
+ const edata = this.trigger("toggle", { target: "popup" });
523
+ if (edata.isCancelled === true) return;
524
+ if (this.options.maximized === true) this.min();
525
+ else this.max();
526
+ setTimeout(() => {
527
+ edata.finish();
528
+ }, (this.options.speed ?? 0.3) * 1e3 + 50);
529
+ }
530
+ max() {
531
+ if (this.options.maximized === true) return;
532
+ const edata = this.trigger("max", { target: "popup" });
533
+ if (edata.isCancelled === true) return;
534
+ this.status = "resizing";
535
+ const rect = query2("#tsg-popup").get(0).getBoundingClientRect();
536
+ this.options.prevSize = rect.width + ":" + rect.height;
537
+ this.resize(1e4, 1e4, () => {
538
+ this.status = "open";
539
+ this.options.maximized = true;
540
+ edata.finish();
541
+ });
542
+ }
543
+ min() {
544
+ if (this.options.maximized !== true) return;
545
+ const size = (this.options.prevSize ?? "").split(":");
546
+ const edata = this.trigger("min", { target: "popup" });
547
+ if (edata.isCancelled === true) return;
548
+ this.status = "resizing";
549
+ this.options.maximized = false;
550
+ this.resize(parseInt(size[0] ?? "0"), parseInt(size[1] ?? "0"), () => {
551
+ this.status = "open";
552
+ this.options.prevSize = null;
553
+ edata.finish();
554
+ });
555
+ }
556
+ clear() {
557
+ query2("#tsg-popup .tsg-popup-title").html("");
558
+ query2("#tsg-popup .tsg-popup-body").html("");
559
+ query2("#tsg-popup .tsg-popup-buttons").html("");
560
+ }
561
+ reset() {
562
+ this.open(this.defaults);
563
+ }
564
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
565
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
566
+ message(options) {
567
+ return TsUtils.message({
568
+ owner: this,
569
+ box: query2("#tsg-popup").get(0),
570
+ after: ".tsg-popup-title"
571
+ }, options);
572
+ }
573
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
574
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
575
+ confirm(options) {
576
+ return TsUtils.confirm({
577
+ owner: this,
578
+ box: query2("#tsg-popup").get(0),
579
+ after: ".tsg-popup-title"
580
+ }, options);
581
+ }
582
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
583
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
584
+ setFocus(focus) {
585
+ const box = query2("#tsg-popup");
586
+ const sel = "input, button, select, textarea, [contentEditable], [tabindex], .tsg-input";
587
+ if (focus != null) {
588
+ const el = isNaN(focus) ? box.find(sel).filter(focus).filter(":not([name=hidden-first])").get(0) : box.find(sel).filter(":not([name=hidden-first])").get(focus);
589
+ el?.focus();
590
+ } else {
591
+ const el = box.find("[name=hidden-first]").get(0);
592
+ if (el) el.focus();
593
+ }
594
+ query2(box).find(sel).off(".keep-focus").on("blur.keep-focus", function(_event) {
595
+ setTimeout(() => {
596
+ const focus2 = document.activeElement;
597
+ const inside = query2(box).find(sel).filter(focus2).length > 0;
598
+ const name = query2(focus2).attr("name");
599
+ if (!inside && focus2 && focus2 !== document.body) {
600
+ query2(box).find(sel).get(0)?.focus();
601
+ }
602
+ if (name == "hidden-last") {
603
+ query2(box).find(sel).get(1)?.focus();
604
+ }
605
+ if (name == "hidden-first") {
606
+ query2(box).find(sel).get(-2)?.focus();
607
+ }
608
+ }, 1);
609
+ });
610
+ }
611
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
612
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
613
+ lock(msg, showSpinner) {
614
+ TsUtils.lock(query2("#tsg-popup"), msg, showSpinner);
615
+ }
616
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
617
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
618
+ unlock(speed) {
619
+ TsUtils.unlock(query2("#tsg-popup"), speed);
620
+ }
621
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
622
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
623
+ center(width, height, force) {
624
+ let maxW, maxH;
625
+ if (window.innerHeight == void 0) {
626
+ maxW = Math.floor(document.documentElement.offsetWidth);
627
+ maxH = Math.floor(document.documentElement.offsetHeight);
628
+ } else {
629
+ maxW = Math.floor(window.innerWidth);
630
+ maxH = Math.floor(window.innerHeight);
631
+ }
632
+ width = parseInt(width ?? this.options.width);
633
+ height = parseInt(height ?? this.options.height);
634
+ if (this.options.maximized === true) {
635
+ width = maxW;
636
+ height = maxH;
637
+ }
638
+ if (maxW - 10 < width) width = maxW - 10;
639
+ if (maxH - 10 < height) height = maxH - 10;
640
+ const top = (maxH - height) / 3;
641
+ const left = (maxW - width) / 2;
642
+ if (force) {
643
+ query2("#tsg-popup").css({
644
+ "transition": "none",
645
+ "top": top + "px",
646
+ "left": left + "px",
647
+ "width": width + "px",
648
+ "height": height + "px"
649
+ });
650
+ this.resizeMessages();
651
+ }
652
+ return { top, left, width, height };
653
+ }
654
+ // any: callback parameter — caller signature varies; TsPopup options accept untyped user payloads at runtime
655
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
656
+ resize(newWidth, newHeight, callBack) {
657
+ return new Promise((resolve) => {
658
+ const self = this;
659
+ if (this.options.speed == null) this.options.speed = 0;
660
+ const { top, left, width, height } = this.center(newWidth, newHeight);
661
+ const speed = this.options.speed;
662
+ query2("#tsg-popup").css({
663
+ "transition": `${speed}s width, ${speed}s height, ${speed}s left, ${speed}s top`,
664
+ "top": top + "px",
665
+ "left": left + "px",
666
+ "width": width + "px",
667
+ "height": height + "px"
668
+ });
669
+ const tmp_int = setInterval(() => {
670
+ self.resizeMessages();
671
+ }, 10);
672
+ setTimeout(() => {
673
+ clearInterval(tmp_int);
674
+ self.resizeMessages();
675
+ if (typeof callBack == "function") callBack();
676
+ resolve(void 0);
677
+ }, this.options.speed * 1e3 + 50);
678
+ });
679
+ }
680
+ // internal function
681
+ resizeMessages() {
682
+ query2("#tsg-popup .tsg-message").each((node) => {
683
+ const msg = node;
684
+ const mopt = msg._msg_options;
685
+ const popup = query2("#tsg-popup");
686
+ if (parseInt(mopt.width) < 10) mopt.width = 10;
687
+ if (parseInt(mopt.height) < 10) mopt.height = 10;
688
+ const rect = popup[0].getBoundingClientRect();
689
+ const titleHeight = popup.find(".tsg-popup-title")[0].clientHeight;
690
+ const pWidth = Math.floor(rect.width);
691
+ const pHeight = Math.floor(rect.height);
692
+ mopt.width = mopt.originalWidth;
693
+ if (mopt.width > pWidth - 10) {
694
+ mopt.width = pWidth - 10;
695
+ }
696
+ mopt.height = mopt.originalHeight;
697
+ if (mopt.height > pHeight - titleHeight - 5) {
698
+ mopt.height = pHeight - titleHeight - 5;
699
+ }
700
+ if (mopt.originalHeight < 0) mopt.height = pHeight + mopt.originalHeight - titleHeight;
701
+ if (mopt.originalWidth < 0) mopt.width = pWidth + mopt.originalWidth * 2;
702
+ query2(msg).css({
703
+ left: (pWidth - mopt.width) / 2 + "px",
704
+ width: mopt.width + "px",
705
+ height: mopt.height + "px"
706
+ });
707
+ });
708
+ }
709
+ };
710
+ function TsAlert(msg, title, callBack) {
711
+ let prom;
712
+ const options = {
713
+ title: TsUtils.lang(title ?? "Notification"),
714
+ body: `<div class="tsg-centered tsg-msg-text">${msg}</div>`,
715
+ showClose: false,
716
+ actions: { ok: TsUtils.lang("Ok") },
717
+ cancelAction: "ok"
718
+ };
719
+ if (query2("#tsg-popup").length > 0 && TsPopup.status != "closing") {
720
+ prom = TsPopup.message(options);
721
+ } else {
722
+ prom = TsPopup.open(options);
723
+ }
724
+ prom["ok"]((event) => {
725
+ if (typeof event.detail.self?.close == "function") {
726
+ event.detail.self.close();
727
+ }
728
+ if (typeof callBack == "function") callBack();
729
+ });
730
+ return prom;
731
+ }
732
+ function TsConfirm(msg, title, callBack) {
733
+ let prom;
734
+ let options = msg;
735
+ if (["string", "number"].includes(typeof options)) {
736
+ options = { msg: options };
737
+ }
738
+ if (options.msg) {
739
+ options.body = `<div class="tsg-centered tsg-msg-text">${options.msg}</div>`, delete options.msg;
740
+ }
741
+ if (typeof title == "function" && callBack == null) {
742
+ callBack = title;
743
+ title = void 0;
744
+ }
745
+ TsUtils.extend(options, {
746
+ title: TsUtils.lang(title ?? options.title ?? "Confirmation"),
747
+ showClose: false,
748
+ modal: true,
749
+ cancelAction: "no"
750
+ });
751
+ if (callBack == null && options.callBack != null) {
752
+ callBack = options.callBack;
753
+ }
754
+ TsUtils.normButtons(options, { yes: TsUtils.lang("Yes"), no: TsUtils.lang("No") });
755
+ if (query2("#tsg-popup").length > 0 && TsPopup.status != "closing") {
756
+ prom = TsPopup.message(options);
757
+ } else {
758
+ prom = TsPopup.open(options);
759
+ }
760
+ prom.self.off(".confirm").on("action:after.confirm", (event) => {
761
+ if (typeof event.detail.self?.close == "function") {
762
+ event.detail.self.close();
763
+ }
764
+ if (typeof callBack == "function") callBack(event.detail.action);
765
+ });
766
+ return prom;
767
+ }
768
+ function TsPrompt(label, title, callBack) {
769
+ let prom;
770
+ let options = label;
771
+ if (["string", "number"].includes(typeof options)) {
772
+ options = { label: options };
773
+ }
774
+ if (options.label) {
775
+ options.focus = 0;
776
+ options.body = options.textarea ? `<div class="tsg-prompt textarea">
777
+ <div>${options.label}</div>
778
+ <textarea id="TsPrompt" class="tsg-input" ${options.attrs ?? ""}
779
+ data-keydown="keydown|event" data-keyup="change|event"></textarea>
780
+ </div>` : `<div class="tsg-prompt tsg-centered">
781
+ <label>${options.label}</label>
782
+ <input id="TsPrompt" class="tsg-input" ${options.attrs ?? ""}
783
+ data-keydown="keydown|event" data-keyup="change|event">
784
+ </div>`;
785
+ }
786
+ TsUtils.extend(options, {
787
+ title: TsUtils.lang(title ?? options.title ?? "Notification"),
788
+ showClose: false,
789
+ modal: true,
790
+ cancelAction: "cancel"
791
+ });
792
+ TsUtils.normButtons(options, { ok: TsUtils.lang("Ok"), cancel: TsUtils.lang("Cancel") });
793
+ if (query2("#tsg-popup").length > 0 && TsPopup.status != "closing") {
794
+ prom = TsPopup.message(options);
795
+ } else {
796
+ prom = TsPopup.open(options);
797
+ }
798
+ if (prom.self.box) {
799
+ prom.self["input"] = query2(prom.self.box).find("#TsPrompt").get(0);
800
+ } else {
801
+ prom.self["input"] = query2("#tsg-popup .tsg-popup-body #TsPrompt").get(0);
802
+ }
803
+ if (options.value != null) {
804
+ prom.self["input"].value = options.value;
805
+ prom.self["input"].select();
806
+ }
807
+ prom.change = function(callback) {
808
+ prom.self.on("change", callback);
809
+ return this;
810
+ };
811
+ prom.self.off(".prompt").on("open:after.prompt", (event) => {
812
+ const box = event.detail.box ? event.detail.box : query2("#tsg-popup .tsg-popup-body").get(0);
813
+ TsUtils.bindEvents(query2(box).find("#TsPrompt"), {
814
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
815
+ keydown(evt) {
816
+ if (evt.keyCode == 27) evt.stopPropagation();
817
+ },
818
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
819
+ change(evt) {
820
+ const edata = prom.self.trigger("change", { target: "prompt", originalEvent: evt });
821
+ if (edata.isCancelled === true) return;
822
+ if (evt.keyCode == 13 && (evt.ctrlKey || evt.metaKey || evt.target.tagName != "TEXTAREA")) {
823
+ prom.self.action("Ok", evt);
824
+ }
825
+ if (evt.keyCode == 27) {
826
+ prom.self.action("Cancel", evt);
827
+ }
828
+ edata.finish();
829
+ }
830
+ });
831
+ query2(box).find(".tsg-eaction").trigger("keyup");
832
+ }).on("action:after.prompt", (event) => {
833
+ if (typeof event.detail.self?.close == "function") {
834
+ event.detail.self.close();
835
+ }
836
+ if (typeof callBack == "function") callBack(event.detail.action);
837
+ });
838
+ return prom;
839
+ }
840
+ var TsPopup = new TsDialog();
841
+
842
+ export {
843
+ TsDialog,
844
+ TsAlert,
845
+ TsConfirm,
846
+ TsPrompt,
847
+ TsPopup
848
+ };
849
+ //# sourceMappingURL=chunk-YBY52G2U.js.map