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