feat: drag
This commit is contained in:
1 parent
05ce7035dd
commit
5c2c682baf
11 files changed
+806
-555
No files matched your search
+15
-8
@@ -2,7 +2,8 @@ import "./css/popup.scss";
|
||||
import { r as lang } from "../utility/lgres";
|
||||
import { nullOrEmpty } from "../utility/strings";
|
||||
import { global } from "../utility";
|
||||
import { appendResizer, createElement, makeMovable, mergeOptions } from "../functions";
|
||||
import { appendResizer, makeMovable } from "../drag";
|
||||
import { createElement, mergeOptions } from "../functions";
|
||||
import { createIcon, changeIcon } from "./icon";
|
||||
import { requestAnimationFrame } from "../ui";
|
||||
|
||||
@@ -241,7 +242,7 @@ export class Popup {
|
||||
} else {
|
||||
|
||||
}
|
||||
let tabIndex = Math.max.apply(null, [...document.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0));
|
||||
let tabIndex = Math.max.apply(null, /** @type {HTMLElement[]} */ ([...document.querySelectorAll('[tabindex]')]).map(e => e.tabIndex ?? 0));
|
||||
if (tabIndex < 0) {
|
||||
tabIndex = 0;
|
||||
}
|
||||
@@ -316,7 +317,7 @@ export class Popup {
|
||||
))
|
||||
);
|
||||
if (Array.isArray(option.buttons) && option.buttons.length > 0) {
|
||||
tabIndex = Math.max.apply(null, [...container.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0));
|
||||
tabIndex = Math.max.apply(null, /** @type {HTMLElement[]} */ ([...container.querySelectorAll('[tabindex]')]).map(e => e.tabIndex ?? 0));
|
||||
container.appendChild(
|
||||
createElement('div', 'ui-popup-footer', ...option.buttons.map((b, i) => {
|
||||
const button = createElement('button', 'ui-popup-button');
|
||||
@@ -351,7 +352,7 @@ export class Popup {
|
||||
return button;
|
||||
}))
|
||||
);
|
||||
const tabs = [...container.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0);
|
||||
const tabs = /** @type {HTMLElement[]} */ ([...container.querySelectorAll('[tabindex]')]).map(e => e.tabIndex ?? 0);
|
||||
const tabMin = Math.min.apply(null, tabs);
|
||||
const tabMax = Math.max.apply(null, tabs);
|
||||
/** @type {HTMLElement | null} */
|
||||
@@ -475,7 +476,7 @@ export function resolvePopup(wrapper, callback, removable, zIndex) {
|
||||
if (!wrapper.classList.contains('dialog')) {
|
||||
return null;
|
||||
}
|
||||
const title = wrapper.querySelector('.dialog-title>.title')?.innerText;
|
||||
const title = /** @type {HTMLElement | null} */ (wrapper.querySelector('.dialog-title>.title'))?.innerText ?? '';
|
||||
/** @type {HTMLElement | null} */
|
||||
const content = wrapper.querySelector('.dialog-title+div');
|
||||
const buttons = /** @type {HTMLInputElement[]} */ ([...wrapper.querySelectorAll('.dialog-func>input[type="button"]')].reverse()).map(b => ({
|
||||
@@ -485,12 +486,13 @@ export function resolvePopup(wrapper, callback, removable, zIndex) {
|
||||
// @ts-ignore
|
||||
trigger: b.onclick == null ? undefined : ((/** @type {IPopup} */ popup) => (b.onclick?.call(popup, null), false))
|
||||
}));
|
||||
const z = parseInt(global.getComputedStyle(wrapper).zIndex);
|
||||
const popup = new Popup({
|
||||
title,
|
||||
content: content ?? '',
|
||||
persistent: !removable,
|
||||
resolve: typeof callback === 'function' ? (result => callback(result)) : undefined,
|
||||
zIndex: wrapper.zIndex ?? zIndex,
|
||||
zIndex: z == null || isNaN(z) ? zIndex : z,
|
||||
buttons
|
||||
});
|
||||
popup.show(document.body, true);
|
||||
@@ -546,7 +548,11 @@ export function showAlert(title, message, iconType = 'info', parent = document.b
|
||||
*/
|
||||
export function showInput(title, multiline, message, options, buttons, parent = document.body) {
|
||||
const r = typeof global.GetTextByKey === 'function' ? global.GetTextByKey : lang;
|
||||
const opts = mergeOptions({}, options);
|
||||
const opts = mergeOptions({
|
||||
tabIndex: undefined,
|
||||
default: undefined,
|
||||
placeholder: undefined
|
||||
}, options);
|
||||
return new Promise(resolve => {
|
||||
const input = multiline ?
|
||||
createElement('textarea', text => {
|
||||
@@ -574,12 +580,13 @@ export function showInput(title, multiline, message, options, buttons, parent =
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// @ts-ignore
|
||||
input[key] = opts[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNaN(opts.tabIndex)) {
|
||||
let tabIndex = Math.max.apply(null, [...document.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0));
|
||||
let tabIndex = Math.max.apply(null, /** @type {HTMLElement[]} */ ([...document.querySelectorAll('[tabindex]')]).map(e => e.tabIndex ?? 0));
|
||||
if (tabIndex < 0) {
|
||||
tabIndex = 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user