@t007/dialog 0.0.11 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.global.js +25 -29
- package/dist/index.js +2 -2
- package/package.json +2 -4
- package/dist/standalone.js +0 -231
package/dist/index.global.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
-
// ../
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
// ../sia-reactor/dist/chunk-UQIMMJTY.js
|
|
4
|
+
function onAllMethods(owner, callback, skipOwn = true, nested = false) {
|
|
5
|
+
let proto = owner;
|
|
6
|
+
while (proto && proto !== Object.prototype) {
|
|
7
|
+
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
8
|
+
if (method === "constructor") continue;
|
|
9
|
+
if (nested && skipOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
10
|
+
if ("function" === typeof Object.getOwnPropertyDescriptor(proto, method)?.value) callback(method, owner);
|
|
11
|
+
}
|
|
12
|
+
proto = Object.getPrototypeOf(proto), nested = true;
|
|
13
|
+
}
|
|
12
14
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
+
function bindAllMethods(owner) {
|
|
16
|
+
onAllMethods(owner, (method, owner2) => {
|
|
17
|
+
owner2[method] = owner2[method].bind(owner2);
|
|
18
|
+
});
|
|
15
19
|
}
|
|
20
|
+
|
|
21
|
+
// ../utils/dist/index.js
|
|
16
22
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
17
23
|
return assignEl(el, props, dataset, styles), el;
|
|
18
24
|
}
|
|
@@ -56,6 +62,12 @@
|
|
|
56
62
|
});
|
|
57
63
|
return w.t007._resourceCache[src];
|
|
58
64
|
}
|
|
65
|
+
function isSym(val) {
|
|
66
|
+
return "symbol" === typeof val;
|
|
67
|
+
}
|
|
68
|
+
function isStr(val) {
|
|
69
|
+
return "string" === typeof val;
|
|
70
|
+
}
|
|
59
71
|
function isSameURL(src1, src2) {
|
|
60
72
|
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
61
73
|
try {
|
|
@@ -65,23 +77,7 @@
|
|
|
65
77
|
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
|
-
|
|
69
|
-
let proto = owner;
|
|
70
|
-
while (proto && proto !== Object.prototype) {
|
|
71
|
-
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
72
|
-
if (method === "constructor") continue;
|
|
73
|
-
if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
74
|
-
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
|
|
75
|
-
}
|
|
76
|
-
proto = Object.getPrototypeOf(proto), nested = true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function bindAllMethods(owner) {
|
|
80
|
-
onAllMethods(owner, (method, owner2) => {
|
|
81
|
-
owner2[method] = owner2[method].bind(owner2);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
if (isDef(window)) {
|
|
80
|
+
if ("undefined" !== typeof window) {
|
|
85
81
|
window.t007 ??= {};
|
|
86
82
|
t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
|
|
87
83
|
window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
|
|
@@ -216,7 +212,7 @@
|
|
|
216
212
|
function prompt(question, defaultValue, options) {
|
|
217
213
|
return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
|
|
218
214
|
}
|
|
219
|
-
if (
|
|
215
|
+
if ("undefined" !== typeof window) {
|
|
220
216
|
t007.alert = alert;
|
|
221
217
|
t007.confirm = confirm;
|
|
222
218
|
t007.prompt = prompt;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.js
|
|
2
|
-
import {
|
|
2
|
+
import { bindAllMethods, createEl, loadResource } from "@t007/utils";
|
|
3
3
|
var T007_Dialog = class {
|
|
4
4
|
dialog;
|
|
5
5
|
confirmBtn;
|
|
@@ -123,7 +123,7 @@ function confirm(question, options) {
|
|
|
123
123
|
function prompt(question, defaultValue, options) {
|
|
124
124
|
return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
|
|
125
125
|
}
|
|
126
|
-
if (
|
|
126
|
+
if ("undefined" !== typeof window) {
|
|
127
127
|
t007.alert = alert;
|
|
128
128
|
t007.confirm = confirm;
|
|
129
129
|
t007.prompt = prompt;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/dialog",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "A lightweight, pure JS dialog system.",
|
|
5
5
|
"author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,8 +29,6 @@
|
|
|
29
29
|
"import": "./dist/index.js",
|
|
30
30
|
"default": "./dist/index.js"
|
|
31
31
|
},
|
|
32
|
-
"./standalone": "./dist/standalone.js",
|
|
33
|
-
"./global": "./dist/index.global.js",
|
|
34
32
|
"./style.css": "./dist/index.css"
|
|
35
33
|
},
|
|
36
34
|
"publishConfig": {
|
|
@@ -57,6 +55,6 @@
|
|
|
57
55
|
"accessible"
|
|
58
56
|
],
|
|
59
57
|
"dependencies": {
|
|
60
|
-
"@t007/utils": "^0.0.
|
|
58
|
+
"@t007/utils": "^0.0.18"
|
|
61
59
|
}
|
|
62
60
|
}
|
package/dist/standalone.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
// ../utils/dist/index.js
|
|
2
|
-
function isDef(val) {
|
|
3
|
-
return "undefined" !== typeof val;
|
|
4
|
-
}
|
|
5
|
-
function isSym(val) {
|
|
6
|
-
return "symbol" === typeof val;
|
|
7
|
-
}
|
|
8
|
-
function isStr(val) {
|
|
9
|
-
return "string" === typeof val;
|
|
10
|
-
}
|
|
11
|
-
function isFunc(val) {
|
|
12
|
-
return "function" === typeof val;
|
|
13
|
-
}
|
|
14
|
-
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
15
|
-
return assignEl(el, props, dataset, styles), el;
|
|
16
|
-
}
|
|
17
|
-
function assignEl(el, props, dataset, styles) {
|
|
18
|
-
if (!el) return;
|
|
19
|
-
if (props) {
|
|
20
|
-
for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
|
|
21
|
-
}
|
|
22
|
-
if (dataset) {
|
|
23
|
-
for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
|
|
24
|
-
}
|
|
25
|
-
if (styles) {
|
|
26
|
-
for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
|
|
30
|
-
function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
|
|
31
|
-
w.t007 ??= {}, w.t007._resourceCache ??= {};
|
|
32
|
-
if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
|
|
33
|
-
const src = req;
|
|
34
|
-
if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
|
|
35
|
-
const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
|
|
36
|
-
if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
|
|
37
|
-
w.t007._resourceCache[src] = new Promise((resolve, reject) => {
|
|
38
|
-
(function tryLoad(remaining, el) {
|
|
39
|
-
const onerror = () => {
|
|
40
|
-
el?.remove?.();
|
|
41
|
-
if (remaining > 1) {
|
|
42
|
-
setTimeout(tryLoad, 1e3, remaining - 1);
|
|
43
|
-
console.warn(`Retrying ${type} load (${attempts - remaining + 1}): ${src}...`);
|
|
44
|
-
} else {
|
|
45
|
-
delete w.t007._resourceCache[src];
|
|
46
|
-
reject(new Error(`${type} load failed after ${attempts} attempts: ${src}`));
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
|
|
50
|
-
if (type === "script") w.document.body.append(el = createEl("script", { src: url, type: module ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
51
|
-
else if (type === "style") w.document.head.append(el = createEl("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
52
|
-
else reject(new Error(`Unsupported resource type: ${type}`));
|
|
53
|
-
})(attempts);
|
|
54
|
-
});
|
|
55
|
-
return w.t007._resourceCache[src];
|
|
56
|
-
}
|
|
57
|
-
function isSameURL(src1, src2) {
|
|
58
|
-
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
59
|
-
try {
|
|
60
|
-
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
61
|
-
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
62
|
-
} catch {
|
|
63
|
-
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
|
|
67
|
-
let proto = owner;
|
|
68
|
-
while (proto && proto !== Object.prototype) {
|
|
69
|
-
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
70
|
-
if (method === "constructor") continue;
|
|
71
|
-
if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
72
|
-
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
|
|
73
|
-
}
|
|
74
|
-
proto = Object.getPrototypeOf(proto), nested = true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function bindAllMethods(owner) {
|
|
78
|
-
onAllMethods(owner, (method, owner2) => {
|
|
79
|
-
owner2[method] = owner2[method].bind(owner2);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (isDef(window)) {
|
|
83
|
-
window.t007 ??= {};
|
|
84
|
-
t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
|
|
85
|
-
window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
|
|
86
|
-
window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
|
|
87
|
-
window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
|
|
88
|
-
window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css`;
|
|
89
|
-
window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css`;
|
|
90
|
-
window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/index.js
|
|
94
|
-
var T007_Dialog = class {
|
|
95
|
-
dialog;
|
|
96
|
-
confirmBtn;
|
|
97
|
-
cancelBtn;
|
|
98
|
-
constructor(resolve) {
|
|
99
|
-
bindAllMethods(this);
|
|
100
|
-
this.resolve = resolve;
|
|
101
|
-
document.body.append(
|
|
102
|
-
this.dialog = createEl("dialog", {
|
|
103
|
-
className: "t007-dialog",
|
|
104
|
-
closedBy: "any"
|
|
105
|
-
})
|
|
106
|
-
);
|
|
107
|
-
this.dialog.addEventListener("cancel", this.cancel);
|
|
108
|
-
}
|
|
109
|
-
show() {
|
|
110
|
-
this.dialog.showModal();
|
|
111
|
-
this.confirmBtn.focus();
|
|
112
|
-
}
|
|
113
|
-
remove() {
|
|
114
|
-
this.dialog.close();
|
|
115
|
-
this.dialog.remove();
|
|
116
|
-
}
|
|
117
|
-
confirm() {
|
|
118
|
-
this.remove();
|
|
119
|
-
this.resolve(true);
|
|
120
|
-
}
|
|
121
|
-
cancel() {
|
|
122
|
-
this.remove();
|
|
123
|
-
this.resolve(false);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
var T007_Alert_Dialog = class extends T007_Dialog {
|
|
127
|
-
constructor({ message, resolve, options }) {
|
|
128
|
-
super(resolve);
|
|
129
|
-
this.render(message, options);
|
|
130
|
-
}
|
|
131
|
-
render(message, options = {}) {
|
|
132
|
-
this.dialog.innerHTML = `
|
|
133
|
-
<div class="t007-dialog-top-section">
|
|
134
|
-
<p class="t007-dialog-question">${message}</p>
|
|
135
|
-
</div>
|
|
136
|
-
<div class="t007-dialog-bottom-section">
|
|
137
|
-
<button class="t007-dialog-confirm-button" type="button">${options.confirmText || "OK"}</button>
|
|
138
|
-
</div>
|
|
139
|
-
`;
|
|
140
|
-
this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
|
|
141
|
-
this.confirmBtn.addEventListener("click", this.confirm);
|
|
142
|
-
this.show();
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
var T007_Confirm_Dialog = class extends T007_Dialog {
|
|
146
|
-
constructor({ question, resolve, options }) {
|
|
147
|
-
super(resolve);
|
|
148
|
-
this.render(question, options);
|
|
149
|
-
}
|
|
150
|
-
render(question, options = {}) {
|
|
151
|
-
this.dialog.innerHTML = `
|
|
152
|
-
<div class="t007-dialog-top-section">
|
|
153
|
-
<p class="t007-dialog-question">${question}</p>
|
|
154
|
-
</div>
|
|
155
|
-
<div class="t007-dialog-bottom-section">
|
|
156
|
-
<button class="t007-dialog-confirm-button" type="button">${options.confirmText || "OK"}</button>
|
|
157
|
-
<button class="t007-dialog-cancel-button" type="button">${options.cancelText || "Cancel"}</button>
|
|
158
|
-
</div>
|
|
159
|
-
`;
|
|
160
|
-
this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
|
|
161
|
-
this.cancelBtn = this.dialog.querySelector(".t007-dialog-cancel-button");
|
|
162
|
-
this.confirmBtn.addEventListener("click", this.confirm);
|
|
163
|
-
this.cancelBtn.addEventListener("click", this.cancel);
|
|
164
|
-
this.show();
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
var T007_Prompt_Dialog = class extends T007_Dialog {
|
|
168
|
-
constructor({ question, defaultValue, resolve, options }) {
|
|
169
|
-
super(resolve);
|
|
170
|
-
this.render(question, defaultValue, options);
|
|
171
|
-
}
|
|
172
|
-
async render(question, defaultValue, options = {}) {
|
|
173
|
-
await loadResource(window.T007_INPUT_JS_SRC, "script");
|
|
174
|
-
options.value = defaultValue;
|
|
175
|
-
this.dialog.innerHTML = `
|
|
176
|
-
<form class="t007-input-form" novalidate>
|
|
177
|
-
<div class="t007-dialog-top-section">
|
|
178
|
-
<p class="t007-dialog-question">${question}</p>
|
|
179
|
-
</div>
|
|
180
|
-
<div class="t007-dialog-bottom-section">
|
|
181
|
-
<button class="t007-dialog-confirm-button" type="submit">${options.confirmText || "OK"}</button>
|
|
182
|
-
<button class="t007-dialog-cancel-button" type="button">${options.cancelText || "Cancel"}</button>
|
|
183
|
-
</div>
|
|
184
|
-
</form>
|
|
185
|
-
`;
|
|
186
|
-
(this.form = this.dialog.querySelector("form")).lastElementChild.insertAdjacentElement("beforebegin", t007.FM?.field(options) || createEl("input", options));
|
|
187
|
-
this.form.onSubmit = this.confirm;
|
|
188
|
-
this.confirmBtn = this.dialog.querySelector(".t007-dialog-confirm-button");
|
|
189
|
-
this.cancelBtn = this.dialog.querySelector(".t007-dialog-cancel-button");
|
|
190
|
-
this.cancelBtn.addEventListener("click", this.cancel);
|
|
191
|
-
t007.FM?.handleFormValidation?.(this.form);
|
|
192
|
-
this.show();
|
|
193
|
-
}
|
|
194
|
-
show() {
|
|
195
|
-
this.dialog.showModal();
|
|
196
|
-
this.form.elements[0]?.focus();
|
|
197
|
-
this.form.elements[0]?.select?.();
|
|
198
|
-
}
|
|
199
|
-
confirm() {
|
|
200
|
-
this.remove();
|
|
201
|
-
this.resolve(this.form.elements[0]?.value);
|
|
202
|
-
}
|
|
203
|
-
cancel() {
|
|
204
|
-
this.remove();
|
|
205
|
-
this.resolve(null);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
function alert(message, options) {
|
|
209
|
-
return new Promise((resolve) => new T007_Alert_Dialog({ message, resolve, options }));
|
|
210
|
-
}
|
|
211
|
-
function confirm(question, options) {
|
|
212
|
-
return new Promise((resolve) => new T007_Confirm_Dialog({ question, resolve, options }));
|
|
213
|
-
}
|
|
214
|
-
function prompt(question, defaultValue, options) {
|
|
215
|
-
return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
|
|
216
|
-
}
|
|
217
|
-
if (isDef(window)) {
|
|
218
|
-
t007.alert = alert;
|
|
219
|
-
t007.confirm = confirm;
|
|
220
|
-
t007.prompt = prompt;
|
|
221
|
-
loadResource(T007_DIALOG_CSS_SRC), loadResource(window.T007_INPUT_JS_SRC, "script");
|
|
222
|
-
window.Alert ??= t007.alert;
|
|
223
|
-
window.Confirm ??= t007.confirm;
|
|
224
|
-
window.Prompt ??= t007.prompt;
|
|
225
|
-
console.log("%cT007 Dialogs attached to window!", "color: darkturquoise");
|
|
226
|
-
}
|
|
227
|
-
export {
|
|
228
|
-
alert,
|
|
229
|
-
confirm,
|
|
230
|
-
prompt
|
|
231
|
-
};
|