@windwalker-io/unicorn-next 0.1.17 → 0.1.19
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/chunks/unicorn.js +72 -32
- package/dist/chunks/unicorn.js.map +1 -1
- package/dist/index.d.ts +22 -12
- package/package.json +1 -1
- package/src/composable/useBsModalAlert.ts +63 -12
- package/src/composable/useForm.ts +8 -9
- package/src/service/dom.ts +1 -1
- package/src/service/ui.ts +31 -15
package/dist/chunks/unicorn.js
CHANGED
|
@@ -432,16 +432,16 @@ _AlertAdapter.confirmText = () => "OK";
|
|
|
432
432
|
_AlertAdapter.cancelText = () => "Cancel";
|
|
433
433
|
_AlertAdapter.deleteText = () => "Delete";
|
|
434
434
|
let AlertAdapter = _AlertAdapter;
|
|
435
|
-
async function simpleAlert(title, text = "", icon
|
|
435
|
+
async function simpleAlert(title, text = "", icon, extra) {
|
|
436
436
|
return AlertAdapter.alert(title, text, icon, extra);
|
|
437
437
|
}
|
|
438
|
-
async function simpleConfirm(title, text = "", icon
|
|
438
|
+
async function simpleConfirm(title, text = "", icon, extra) {
|
|
439
439
|
return AlertAdapter.confirm(title, text, icon, extra);
|
|
440
440
|
}
|
|
441
|
-
async function deleteConfirm(title, text = "", icon
|
|
441
|
+
async function deleteConfirm(title, text = "", icon, extra) {
|
|
442
442
|
return AlertAdapter.deleteConfirm(title, text, icon, extra);
|
|
443
443
|
}
|
|
444
|
-
async function simpleNotify(title, text = "", type
|
|
444
|
+
async function simpleNotify(title, text = "", type, extra) {
|
|
445
445
|
return AlertAdapter.notify(title, text, type, extra);
|
|
446
446
|
}
|
|
447
447
|
async function clearNotifies() {
|
|
@@ -1179,6 +1179,7 @@ const useBs5ButtonRadio = async (selector, options = {}) => {
|
|
|
1179
1179
|
const bs5 = await useUIBootstrap5();
|
|
1180
1180
|
return bs5.buttonRadio(selector, options);
|
|
1181
1181
|
};
|
|
1182
|
+
let currentOpenedModals = {};
|
|
1182
1183
|
const defaultOptions = {
|
|
1183
1184
|
buttons: [
|
|
1184
1185
|
"OK"
|
|
@@ -1196,7 +1197,7 @@ async function useBsModalAlert(id, options) {
|
|
|
1196
1197
|
}
|
|
1197
1198
|
if (!modalElement) {
|
|
1198
1199
|
modalElement = html(`<div id="${id}" class="uni-modal-alert modal fade" tabindex="-1" role="dialog">
|
|
1199
|
-
<div class="modal-dialog" role="document">
|
|
1200
|
+
<div class="modal-dialog modal-dialog-centered" role="document">
|
|
1200
1201
|
<div class="modal-content">
|
|
1201
1202
|
<div class="modal-body text-center p-4"></div>
|
|
1202
1203
|
<div class="modal-footer"></div>
|
|
@@ -1205,9 +1206,15 @@ async function useBsModalAlert(id, options) {
|
|
|
1205
1206
|
</div>`);
|
|
1206
1207
|
document.body.appendChild(modalElement);
|
|
1207
1208
|
}
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1209
|
+
const bsModal = Modal.getOrCreateInstance(modalElement, options);
|
|
1210
|
+
modalElement.addEventListener("show.bs.modal", () => {
|
|
1211
|
+
currentOpenedModals[modalElement.id] = instance;
|
|
1212
|
+
});
|
|
1213
|
+
modalElement.addEventListener("hidden.bs.modal", () => {
|
|
1214
|
+
delete currentOpenedModals[modalElement.id];
|
|
1215
|
+
});
|
|
1216
|
+
const instance = {
|
|
1217
|
+
show: async (title, text, icon, options2) => {
|
|
1211
1218
|
if (typeof title === "string") {
|
|
1212
1219
|
options2 = options2 || {};
|
|
1213
1220
|
options2.title = title;
|
|
@@ -1216,27 +1223,51 @@ async function useBsModalAlert(id, options) {
|
|
|
1216
1223
|
} else {
|
|
1217
1224
|
options2 = title;
|
|
1218
1225
|
}
|
|
1226
|
+
await closeCurrentOpened(modalElement);
|
|
1219
1227
|
return new Promise((resolve) => {
|
|
1220
1228
|
prepareModalElement(modalElement, resolve, options2);
|
|
1221
|
-
|
|
1229
|
+
bsModal.show(options2?.relatedTarget);
|
|
1222
1230
|
});
|
|
1223
1231
|
},
|
|
1224
1232
|
hide: () => {
|
|
1225
|
-
|
|
1233
|
+
bsModal.hide();
|
|
1226
1234
|
},
|
|
1227
1235
|
dispose: () => {
|
|
1228
|
-
|
|
1236
|
+
bsModal.dispose();
|
|
1229
1237
|
},
|
|
1230
1238
|
toggle: (relatedTarget) => {
|
|
1231
|
-
|
|
1239
|
+
bsModal.toggle(relatedTarget);
|
|
1232
1240
|
},
|
|
1233
1241
|
destroy: () => {
|
|
1234
|
-
|
|
1242
|
+
bsModal.dispose();
|
|
1235
1243
|
modalElement.remove();
|
|
1236
1244
|
},
|
|
1237
|
-
instance:
|
|
1238
|
-
el: modalElement
|
|
1245
|
+
instance: bsModal,
|
|
1246
|
+
el: modalElement,
|
|
1247
|
+
on: (event, handler) => {
|
|
1248
|
+
modalElement.addEventListener(event, handler);
|
|
1249
|
+
return () => {
|
|
1250
|
+
modalElement.removeEventListener(event, handler);
|
|
1251
|
+
};
|
|
1252
|
+
},
|
|
1253
|
+
off: (event, handler) => {
|
|
1254
|
+
modalElement.removeEventListener(event, handler);
|
|
1255
|
+
}
|
|
1239
1256
|
};
|
|
1257
|
+
return instance;
|
|
1258
|
+
}
|
|
1259
|
+
async function closeCurrentOpened(modalElement) {
|
|
1260
|
+
return new Promise((resolve) => {
|
|
1261
|
+
let currentOpenedModal = currentOpenedModals[modalElement.id];
|
|
1262
|
+
if (!currentOpenedModal) {
|
|
1263
|
+
resolve();
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
currentOpenedModal.el.addEventListener("hidden.bs.modal", () => {
|
|
1267
|
+
resolve();
|
|
1268
|
+
}, { once: true });
|
|
1269
|
+
currentOpenedModal.hide();
|
|
1270
|
+
});
|
|
1240
1271
|
}
|
|
1241
1272
|
async function prepareModalElement(modalElement, handler, options) {
|
|
1242
1273
|
options = Object.assign({}, defaultOptions, options || {});
|
|
@@ -1255,6 +1286,7 @@ async function prepareModalElement(modalElement, handler, options) {
|
|
|
1255
1286
|
</div>`;
|
|
1256
1287
|
}
|
|
1257
1288
|
header = await anyToElement(header);
|
|
1289
|
+
modalElement.querySelector(".modal-header")?.remove();
|
|
1258
1290
|
modalElement.querySelector(".modal-content").insertAdjacentElement("afterbegin", header);
|
|
1259
1291
|
}
|
|
1260
1292
|
if (content) {
|
|
@@ -1266,7 +1298,7 @@ async function prepareModalElement(modalElement, handler, options) {
|
|
|
1266
1298
|
let icon = options.icon;
|
|
1267
1299
|
if (icon) {
|
|
1268
1300
|
if (typeof icon === "string") {
|
|
1269
|
-
icon = `<div class="uni-modal-alert__icon text-center mb-
|
|
1301
|
+
icon = `<div class="uni-modal-alert__icon text-center mb-3"><span class="${icon}" style="font-size: 64px;"></span></div>`;
|
|
1270
1302
|
}
|
|
1271
1303
|
icon = await anyToElement(icon);
|
|
1272
1304
|
modalElement.querySelector(".modal-body").appendChild(icon);
|
|
@@ -1294,6 +1326,9 @@ async function prepareModalElement(modalElement, handler, options) {
|
|
|
1294
1326
|
if (options.size) {
|
|
1295
1327
|
modalElement.querySelector(".modal-dialog").classList.add(`modal-${options.size}`);
|
|
1296
1328
|
}
|
|
1329
|
+
if (options.configure) {
|
|
1330
|
+
modalElement = options.configure(modalElement) ?? modalElement;
|
|
1331
|
+
}
|
|
1297
1332
|
return modalElement;
|
|
1298
1333
|
}
|
|
1299
1334
|
async function anyToElement(content) {
|
|
@@ -1407,20 +1442,19 @@ function useFormAsync(ele, options = {}) {
|
|
|
1407
1442
|
const proxy = new Proxy({}, {
|
|
1408
1443
|
get(target, prop) {
|
|
1409
1444
|
return (...args) => {
|
|
1445
|
+
if (prop === "then" || prop === "catch") {
|
|
1446
|
+
return promise[prop].apply(promise, args);
|
|
1447
|
+
}
|
|
1410
1448
|
return promise.then((form) => {
|
|
1411
|
-
const
|
|
1412
|
-
if (typeof
|
|
1413
|
-
return
|
|
1449
|
+
const p = form[prop];
|
|
1450
|
+
if (typeof p === "function") {
|
|
1451
|
+
return p.apply(form, args);
|
|
1414
1452
|
}
|
|
1415
|
-
|
|
1453
|
+
return p;
|
|
1416
1454
|
});
|
|
1417
1455
|
};
|
|
1418
1456
|
}
|
|
1419
1457
|
});
|
|
1420
|
-
Object.assign(proxy, {
|
|
1421
|
-
then: promise.then.bind(promise),
|
|
1422
|
-
catch: promise.catch.bind(promise)
|
|
1423
|
-
});
|
|
1424
1458
|
return proxy;
|
|
1425
1459
|
}
|
|
1426
1460
|
function useForm(ele, options = {}) {
|
|
@@ -1934,7 +1968,7 @@ function useDisableOnSubmit(formSelector = "#admin-form", buttonSelector = "", o
|
|
|
1934
1968
|
].join(",");
|
|
1935
1969
|
const event = options.event || "submit";
|
|
1936
1970
|
const spinnerClass = options.spinnerClass || "spinner-border spinner-border-sm";
|
|
1937
|
-
const loadingClass = options.loadingCass || "is-loading";
|
|
1971
|
+
const loadingClass = options.loadingCass || "is-uni-loading";
|
|
1938
1972
|
selectAll(buttonSelector, (button) => {
|
|
1939
1973
|
button.addEventListener("click", (e) => {
|
|
1940
1974
|
button.dataset.clicked = "1";
|
|
@@ -1954,17 +1988,23 @@ function useDisableOnSubmit(formSelector = "#admin-form", buttonSelector = "", o
|
|
|
1954
1988
|
button.setAttribute("disabled", "disabled");
|
|
1955
1989
|
button.classList.add("disabled");
|
|
1956
1990
|
if (button.dataset.clicked) {
|
|
1957
|
-
|
|
1958
|
-
button.classList.add(loadingClass);
|
|
1959
|
-
if (icon) {
|
|
1960
|
-
const i = html("<i></i>");
|
|
1961
|
-
icon.parentNode.replaceChild(i, icon);
|
|
1962
|
-
i.setAttribute("class", spinnerClass);
|
|
1963
|
-
}
|
|
1991
|
+
makeButtonLoading(button);
|
|
1964
1992
|
}
|
|
1965
1993
|
});
|
|
1994
|
+
if (e instanceof SubmitEvent && e.submitter) {
|
|
1995
|
+
makeButtonLoading(e.submitter);
|
|
1996
|
+
}
|
|
1966
1997
|
}, 0);
|
|
1967
1998
|
});
|
|
1999
|
+
function makeButtonLoading(button) {
|
|
2000
|
+
let icon = button.querySelector(iconSelector);
|
|
2001
|
+
button.classList.add(loadingClass);
|
|
2002
|
+
if (icon) {
|
|
2003
|
+
const i = html("<i></i>");
|
|
2004
|
+
icon.parentNode?.replaceChild(i, icon);
|
|
2005
|
+
i.setAttribute("class", spinnerClass);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
1968
2008
|
}
|
|
1969
2009
|
function useDisableIfStackNotEmpty(buttonSelector = "[data-task=save]", stackName = "uploading") {
|
|
1970
2010
|
const stack2 = useStack(stackName);
|