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