movable.ts, and fix popup issue.

This commit is contained in:
lchen committed 2026-11-24 10:57:36 +08:00
1 parent 5c2c682baf
commit 9028805363
7 files changed
+167 -40

No files matched your search

+35 -14
View File
@@ -2,7 +2,7 @@ import "./css/popup.scss";
import { r as lang } from "../utility/lgres";
import { nullOrEmpty } from "../utility/strings";
import { global } from "../utility";
import { appendResizer, makeMovable } from "../drag";
import { appendResizer, makeMovable } from "./movable";
import { createElement, mergeOptions } from "../functions";
import { createIcon, changeIcon } from "./icon";
import { requestAnimationFrame } from "../ui";
@@ -56,7 +56,10 @@ export class Popup {
option: DEFAULT_OPTIONS,
/** @type {PopupRectParam | undefined} */
bounds: undefined,
cursor: undefined
cursor: undefined,
/** @type {(() => void) | undefined} */
movableDisposer: undefined,
__resolved: false
};
/**
@@ -170,6 +173,9 @@ export class Popup {
const option = this._var.option;
const mask = this._var.mask;
const doClose = () => {
if (typeof this._var.movableDisposer === 'function') {
this._var.movableDisposer();
}
if (option.persistent) {
if (mask != null) {
mask.style.display = 'none';
@@ -242,7 +248,7 @@ export class Popup {
} else {
}
let tabIndex = Math.max.apply(null, /** @type {HTMLElement[]} */ ([...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;
}
@@ -317,7 +323,7 @@ export class Popup {
))
);
if (Array.isArray(option.buttons) && option.buttons.length > 0) {
tabIndex = Math.max.apply(null, /** @type {HTMLElement[]} */ ([...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');
@@ -334,16 +340,31 @@ export class Popup {
}
button.innerText = b.text;
button.addEventListener('click', () => {
if (this._var.__resolved) {
return;
}
this._var.__resolved = true;
if (typeof b.trigger === 'function') {
const result = b.trigger(this);
if (typeof result === 'boolean' || typeof result === 'string' || typeof result === 'number') {
this.close(result);
if (result !== false) {
this.close(result);
} else {
this._var.__resolved = false;
}
} else if (typeof result?.then === 'function') {
result.then(r => {
if (r !== false) {
this.close(r);
} else {
this._var.__resolved = false;
}
}).catch(reason => console.warn(reason));
}).catch(reason => {
this._var.__resolved = false;
console.warn(reason);
});
} else {
this.close();
}
} else {
this.close(b.key ?? i);
@@ -376,7 +397,7 @@ export class Popup {
}
if (option.movable || option.resizable) {
const parent = !option.mask ? document.body : mask;
makeMovable(parent, {
this._var.movableDisposer = makeMovable(parent, {
movable: option.movable,
resizable: option.resizable,
context: this,
@@ -539,10 +560,10 @@ export function showAlert(title, message, iconType = 'info', parent = document.b
/**
* @param {string | HTMLElement} title
* @param {boolean} multiline
* @param {string} message
* @param {InputOptions} options
* @param {PopupButton[]} buttons
* @param {boolean} [multiline]
* @param {string} [message]
* @param {InputOptions} [options]
* @param {PopupButton[]} [buttons]
* @param {HTMLElement} parent
* @returns {Promise<any>}
*/
@@ -586,7 +607,7 @@ export function showInput(title, multiline, message, options, buttons, parent =
}
}
if (isNaN(opts.tabIndex)) {
let tabIndex = Math.max.apply(null, /** @type {HTMLElement[]} */ ([...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;
}
@@ -612,7 +633,7 @@ export function showInput(title, multiline, message, options, buttons, parent =
*
* @param {string | HTMLElement} title
* @param {string | HTMLElement} content
* @param {PopupButton[]} buttons
* @param {PopupButton[]} [buttons]
* @param {keyof iconTypes} iconType
* @param {HTMLElement} parent
* @returns
@@ -637,7 +658,7 @@ export function showConfirm(title, content, buttons, iconType = 'question', pare
isPrimary: b.isPrimary,
trigger: p => {
if (typeof b.trigger === 'function') {
return b.trigger(p, b);
return b.trigger(p);
}
return b.key ?? i;
}