sync
This commit is contained in:
1 parent
5cb14ffd44
commit
05ce7035dd
15 files changed
+946
-460
No files matched your search
@@ -124,4 +124,104 @@
|
||||
.ui-notify-message {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
}
|
||||
|
||||
.drag-box {
|
||||
position: relative;
|
||||
|
||||
.drag-hover {
|
||||
cursor: move;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.resizer {
|
||||
position: absolute;
|
||||
touch-action: none;
|
||||
|
||||
&[data-dir="n"],
|
||||
&[data-dir="s"] {
|
||||
width: 100%;
|
||||
height: 7px;
|
||||
left: 0;
|
||||
cursor: ns-resize;
|
||||
}
|
||||
|
||||
&[data-dir="w"],
|
||||
&[data-dir="e"] {
|
||||
width: 7px;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
|
||||
&[data-dir="nw"],
|
||||
&[data-dir="se"],
|
||||
&[data-dir="ne"],
|
||||
&[data-dir="sw"] {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
&[data-dir="nw"],
|
||||
&[data-dir="se"] {
|
||||
cursor: nwse-resize;
|
||||
}
|
||||
|
||||
&[data-dir="ne"],
|
||||
&[data-dir="sw"] {
|
||||
cursor: nesw-resize;
|
||||
}
|
||||
|
||||
&[data-dir="w"],
|
||||
&[data-dir="nw"],
|
||||
&[data-dir="sw"] {
|
||||
left: -4px;
|
||||
}
|
||||
|
||||
&[data-dir="e"],
|
||||
&[data-dir="ne"],
|
||||
&[data-dir="se"] {
|
||||
right: -4px;
|
||||
}
|
||||
|
||||
&[data-dir="n"],
|
||||
&[data-dir="nw"],
|
||||
&[data-dir="ne"] {
|
||||
top: -4px;
|
||||
}
|
||||
|
||||
&[data-dir="s"],
|
||||
&[data-dir="sw"],
|
||||
&[data-dir="se"] {
|
||||
bottom: -4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.snap-line {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
z-index: 9999;
|
||||
display: none;
|
||||
|
||||
&.line-x {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 1px;
|
||||
border-left: 1px dashed var(--red-color);
|
||||
}
|
||||
|
||||
&.line-y {
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
height: 1px;
|
||||
border-top: 1px dashed var(--red-color);
|
||||
}
|
||||
}
|
||||
|
||||
html.is-interacting,
|
||||
html.is-interacting * {
|
||||
user-select: none !important;
|
||||
}
|
||||
+1
-72
@@ -66,15 +66,6 @@ $buttonHeight: 28px;
|
||||
padding: 5px 0 3px 12px;
|
||||
}
|
||||
|
||||
.ui-popup-header-title,
|
||||
.ui-popup-move {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.ui-popup-header-title.no-move {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
>.ui-popup-header-icons {
|
||||
flex: 0 0 auto;
|
||||
padding: 5px 12px 3px 0;
|
||||
@@ -251,75 +242,13 @@ $buttonHeight: 28px;
|
||||
}
|
||||
}
|
||||
|
||||
.ui-popup-border {
|
||||
position: absolute;
|
||||
|
||||
&.ui-popup-border-left,
|
||||
&.ui-popup-border-right {
|
||||
width: 6px;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
|
||||
&.ui-popup-border-top,
|
||||
&.ui-popup-border-bottom {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
left: 0;
|
||||
cursor: ns-resize;
|
||||
}
|
||||
|
||||
&.ui-popup-border-top-left,
|
||||
&.ui-popup-border-top-right,
|
||||
&.ui-popup-border-bottom-right,
|
||||
&.ui-popup-border-bottom-left {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
&.ui-popup-border-top-left,
|
||||
&.ui-popup-border-bottom-right {
|
||||
cursor: nwse-resize;
|
||||
}
|
||||
|
||||
&.ui-popup-border-top-right,
|
||||
&.ui-popup-border-bottom-left {
|
||||
cursor: nesw-resize;
|
||||
}
|
||||
|
||||
&.ui-popup-border-left,
|
||||
&.ui-popup-border-top-left,
|
||||
&.ui-popup-border-bottom-left {
|
||||
left: -4px;
|
||||
}
|
||||
|
||||
&.ui-popup-border-right,
|
||||
&.ui-popup-border-top-right,
|
||||
&.ui-popup-border-bottom-right {
|
||||
right: -4px;
|
||||
}
|
||||
|
||||
&.ui-popup-border-top,
|
||||
&.ui-popup-border-top-left,
|
||||
&.ui-popup-border-top-right {
|
||||
top: -4px;
|
||||
}
|
||||
|
||||
&.ui-popup-border-bottom,
|
||||
&.ui-popup-border-bottom-right,
|
||||
&.ui-popup-border-bottom-left {
|
||||
bottom: -4px;
|
||||
}
|
||||
}
|
||||
|
||||
&.ui-popup-collapse {
|
||||
min-height: 40px;
|
||||
min-width: 160px;
|
||||
|
||||
.ui-popup-body,
|
||||
.ui-popup-footer,
|
||||
.ui-popup-border {
|
||||
.resizer {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +419,6 @@ export class DateSelector {
|
||||
|
||||
/**
|
||||
* 获取日期选择框元素
|
||||
* @readonly
|
||||
* @type {HTMLInputElement | undefined}
|
||||
*/
|
||||
get element() { return this._var.el }
|
||||
|
||||
+11
-24
@@ -1,12 +1,12 @@
|
||||
import './css/dropdown.scss';
|
||||
import { r as lang } from "../utility/lgres";
|
||||
import { contains, nullOrEmpty } from "../utility/strings";
|
||||
import { mergeOptions, global, isPositive, throttle } from "../utility";
|
||||
import { createElement } from "../functions";
|
||||
import { global, isPositive, throttle } from "../utility";
|
||||
import { createElement, mergeOptions } from "../functions";
|
||||
import { createCheckbox } from "./checkbox";
|
||||
import { createIcon } from "./icon"
|
||||
|
||||
/** @import { DropdownOptions } from './dropdown.types' */
|
||||
/** @import { DropdownOptions, DropdownItem, Dropdown as IDropdown, MarkRequired } from '../types' */
|
||||
|
||||
/** @satisfies {Partial<DropdownOptions>} */
|
||||
const DEFAULT_OPTIONS = {
|
||||
@@ -17,7 +17,7 @@ const DEFAULT_OPTIONS = {
|
||||
maxLength: 500
|
||||
};
|
||||
|
||||
/** @typedef {import('../types').MarkRequired<DropdownOptions, keyof typeof DEFAULT_OPTIONS>} ResolvedDropdownOptions */
|
||||
/** @typedef {MarkRequired<DropdownOptions, keyof typeof DEFAULT_OPTIONS>} ResolvedDropdownOptions */
|
||||
|
||||
const SymbolDropdown = Symbol.for('ui-dropdown');
|
||||
const DropdownItemHeight = 30;
|
||||
@@ -142,19 +142,8 @@ function getValue(it, valuekey, textkey) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据项基础类型
|
||||
* @typedef DropdownItemBase
|
||||
* @property {0 | 1 | 2 | undefined} [__checked] 是否选中
|
||||
* @property {string} [__p] 父节点 Id
|
||||
* @property {number} [__level] 层级
|
||||
* @interface
|
||||
* @implements {IDropdown}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 数据项类型
|
||||
* @typedef {DropdownItemBase & Object.<string, any>} DropdownItem
|
||||
*/
|
||||
|
||||
export class Dropdown {
|
||||
_var = {
|
||||
/** @type {ResolvedDropdownOptions} */
|
||||
@@ -180,24 +169,22 @@ export class Dropdown {
|
||||
dropHeight: 0
|
||||
};
|
||||
|
||||
/** @type {(() => DropdownItem[]) | undefined} */
|
||||
/** @type {((this: IDropdown) => DropdownItem[]) | undefined} */
|
||||
sourceFilter;
|
||||
/** @type {((list: DropdownItem[]) => void) | undefined} */
|
||||
/** @type {((this: IDropdown, list: DropdownItem[]) => void) | undefined} */
|
||||
onSelectedList;
|
||||
/** @type {((it: DropdownItem | undefined) => void) | undefined} */
|
||||
/** @type {((this: IDropdown, it: DropdownItem | undefined) => void) | undefined} */
|
||||
onSelected;
|
||||
/** @type {((this: Dropdown) => void) | undefined} */
|
||||
/** @type {((this: IDropdown) => void) | undefined} */
|
||||
onExpanded;
|
||||
/** @type {((this: Dropdown) => void) | undefined} */
|
||||
/** @type {((this: IDropdown) => void) | undefined} */
|
||||
onCollapsed;
|
||||
|
||||
/**
|
||||
* @param {DropdownOptions} [options]
|
||||
*/
|
||||
constructor(options) {
|
||||
if (options != null) {
|
||||
this._var.options = mergeOptions(DEFAULT_OPTIONS, options);
|
||||
}
|
||||
this._var.options = mergeOptions(DEFAULT_OPTIONS, options);
|
||||
const opts = this._var.options;
|
||||
const getText = opts.getText;
|
||||
if (typeof getText === 'function') {
|
||||
|
||||
Vendored
-50
@@ -1,50 +0,0 @@
|
||||
import type { GetTextCallback } from '../types';
|
||||
|
||||
/** 下拉列表参数对象 */
|
||||
interface DropdownOptions {
|
||||
/** 文本关键字 */
|
||||
textKey?: string;
|
||||
/** 值关键字 */
|
||||
valueKey?: string;
|
||||
/** 源码显示的关键字 */
|
||||
htmlKey?: string;
|
||||
/** 子集合的关键字 */
|
||||
childKey?: string;
|
||||
/** 最大输入长度 */
|
||||
maxLength?: number;
|
||||
/**
|
||||
* 模板创建函数
|
||||
* @param this 当前Dropdown
|
||||
* @param it 下拉项目
|
||||
* @returns 返回渲染的字符串
|
||||
*/
|
||||
htmlTemplate?: (this: Dropdown, it: DropdownItem) => string;
|
||||
/** 是否允许多选 */
|
||||
multiSelect?: boolean;
|
||||
/** 选中值 */
|
||||
selected?: string;
|
||||
/** 选中的数组 */
|
||||
selectedList?: string[];
|
||||
/** 是否禁用 */
|
||||
disabled?: boolean;
|
||||
/** 是否支持输入 */
|
||||
input?: boolean;
|
||||
/** 是否支持搜索 */
|
||||
search?: boolean;
|
||||
/** 搜索的关键字数组 */
|
||||
searchKeys?: string[];
|
||||
/** 搜索提示文本,默认值取语言资源 `searchHolder` "Search..." */
|
||||
searchPlaceholder?: string;
|
||||
/** 焦点索引 */
|
||||
tabIndex?: number;
|
||||
/** 输入框的提示文本 */
|
||||
placeholder?: string;
|
||||
/** 是否固定为向下展开 */
|
||||
slideFixed?: boolean;
|
||||
/** 父元素,默认添加到头元素之后 */
|
||||
wrapper?: HTMLElement;
|
||||
/** 是否忽略 All 选项 */
|
||||
ignoreAll?: boolean;
|
||||
/** 获取文本的代理函数 */
|
||||
getText?: GetTextCallback;
|
||||
}
|
||||
@@ -1125,7 +1125,6 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 列类型枚举
|
||||
* @readonly
|
||||
* @type {GridColumnTypeEnum}
|
||||
* @property {number} Common=0 - 通用列(只读)
|
||||
* @property {number} Input=1 - 单行文本列
|
||||
@@ -1179,7 +1178,6 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 获取全局是否可支持点击扩展
|
||||
* @readonly
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isExpandable() {
|
||||
@@ -1192,14 +1190,12 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 获取 Grid 的页面元素
|
||||
* @readonly
|
||||
* @type {HTMLDivElement}
|
||||
*/
|
||||
get element() { return this._var.el }
|
||||
|
||||
/**
|
||||
* 获取当前 Grid 是否已发生改变
|
||||
* @readonly
|
||||
* @type {boolean}
|
||||
*/
|
||||
get changed() {
|
||||
@@ -1212,14 +1208,12 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 返回所有数据的数据(未过滤)
|
||||
* @readonly
|
||||
* @type {GridRowItem[]}
|
||||
*/
|
||||
get allSource() { return this._var.source?.map(s => s.values) }
|
||||
|
||||
/**
|
||||
* 获取已过滤的数据中的扩展对象数组
|
||||
* @readonly
|
||||
* @type {GridExpandableObject[]}
|
||||
* @property {HTMLElement} element - 扩展行元素
|
||||
*/
|
||||
@@ -1227,14 +1221,12 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 获取当前是否为虚模式状态
|
||||
* @readonly
|
||||
* @type {boolean}
|
||||
*/
|
||||
get virtual() { return this._var.currentSource?.length > this.virtualCount }
|
||||
|
||||
/**
|
||||
* 获取当前排序的列关键字,为 null 则当前无排序列
|
||||
* @readonly
|
||||
* @type {string | null}
|
||||
*/
|
||||
get sortKey() {
|
||||
@@ -1246,7 +1238,6 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 获取当前选中的行对象
|
||||
* @readonly
|
||||
* @type {GridRowItem | null}
|
||||
* @since 1.0.7
|
||||
*/
|
||||
@@ -1280,14 +1271,12 @@ export class Grid {
|
||||
|
||||
/**
|
||||
* 获取虚模式起始索引
|
||||
* @readonly
|
||||
* @type {number}
|
||||
*/
|
||||
get startIndex() { return this._var.startIndex }
|
||||
|
||||
/**
|
||||
* 获取当前选中行的索引,为 -1 则当前没有选中行
|
||||
* @readonly
|
||||
* @type {number}
|
||||
*/
|
||||
get selectedIndex() { return (this._var.selectedIndexes && this._var.selectedIndexes[0]) ?? -1 }
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ function createUse(type, id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {typeof SVGElement} K
|
||||
* @template {Element} K
|
||||
* @param {K} svg
|
||||
* @param {string} type
|
||||
* @param {string} id
|
||||
|
||||
+142
-246
@@ -2,36 +2,14 @@ import "./css/popup.scss";
|
||||
import { r as lang } from "../utility/lgres";
|
||||
import { nullOrEmpty } from "../utility/strings";
|
||||
import { global } from "../utility";
|
||||
import { createElement } from "../functions";
|
||||
import { appendResizer, createElement, makeMovable, mergeOptions } from "../functions";
|
||||
import { createIcon, changeIcon } from "./icon";
|
||||
import { requestAnimationFrame } from "../ui";
|
||||
|
||||
/** @import { PopupOptions, PopupRectParam } from '../types' */
|
||||
|
||||
const ResizeMods = {
|
||||
right: 1,
|
||||
bottom: 2,
|
||||
left: 4,
|
||||
top: 8,
|
||||
bottomRight: 2 | 1,
|
||||
bottomLeft: 2 | 4,
|
||||
topRight: 8 | 1,
|
||||
topLeft: 8 | 4
|
||||
}
|
||||
/** @import { PopupOptions, PopupRectParam, PopupButton, Popup as IPopup, MarkRequired, InputOptions } from '../types' */
|
||||
|
||||
const IconStyle = 'fa-light';
|
||||
|
||||
// const Cursors = {
|
||||
// [ResizeMods.right]: 'ew-resize',
|
||||
// [ResizeMods.bottom]: 'ns-resize',
|
||||
// [ResizeMods.bottomRight]: 'nwse-resize',
|
||||
// [ResizeMods.left]: 'ew-resize',
|
||||
// [ResizeMods.bottomLeft]: 'nesw-resize',
|
||||
// [ResizeMods.top]: 'ns-resize',
|
||||
// [ResizeMods.topRight]: 'nesw-resize',
|
||||
// [ResizeMods.topLeft]: 'nwse-resize'
|
||||
// }
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} px
|
||||
@@ -49,28 +27,47 @@ function trimPx(px) {
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {import('../types').Popup} */
|
||||
/** @satisfies {Partial<PopupOptions>} */
|
||||
const DEFAULT_OPTIONS = {
|
||||
content: '',
|
||||
title: '',
|
||||
persistent: false,
|
||||
mask: true,
|
||||
changeZIndex: false,
|
||||
closable: true,
|
||||
movable: true,
|
||||
resizable: false,
|
||||
minWidth: 200,
|
||||
minHeight: 200,
|
||||
collapsable: false
|
||||
};
|
||||
|
||||
/** @typedef {MarkRequired<PopupOptions, keyof typeof DEFAULT_OPTIONS>} ResolvedPopupOptions */
|
||||
|
||||
/**
|
||||
* @implements {IPopup}
|
||||
*/
|
||||
export class Popup {
|
||||
_var = {
|
||||
/** @type {HTMLElement | undefined} */
|
||||
mask: undefined,
|
||||
/** @type {PopupOptions | undefined} */
|
||||
option: undefined,
|
||||
/** @type {ResolvedPopupOptions} */
|
||||
option: DEFAULT_OPTIONS,
|
||||
/** @type {PopupRectParam | undefined} */
|
||||
bounds: undefined,
|
||||
cursor: undefined
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {PopupOptions} [opts]
|
||||
* @param {PopupOptions} opts
|
||||
*/
|
||||
constructor(opts) {
|
||||
this._var.option = opts;
|
||||
this._var.option = mergeOptions(DEFAULT_OPTIONS, opts);
|
||||
}
|
||||
|
||||
get container() { return /** @type {HTMLElement | undefined} */ (this._var.mask?.querySelector('.ui-popup-container')) }
|
||||
|
||||
get title() { return this._var.option?.title ?? ''; }
|
||||
get title() { return this._var.option.title; }
|
||||
set title(title) {
|
||||
const element = this._var.mask?.querySelector('.ui-popup-container .ui-popup-header .ui-popup-header-title');
|
||||
if (element instanceof HTMLElement) {
|
||||
@@ -80,9 +77,7 @@ export class Popup {
|
||||
element.replaceChildren(title);
|
||||
}
|
||||
}
|
||||
if (this._var.option != null) {
|
||||
this._var.option.title = title;
|
||||
}
|
||||
this._var.option.title = title;
|
||||
}
|
||||
|
||||
_getLoadingPanel() {
|
||||
@@ -166,11 +161,15 @@ export class Popup {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} [result]
|
||||
* @param {boolean} [animation]
|
||||
*/
|
||||
close(result = null, animation = true) {
|
||||
const option = this._var.option;
|
||||
const mask = this._var.mask;
|
||||
const doClose = () => {
|
||||
if (option?.persistent) {
|
||||
if (option.persistent) {
|
||||
if (mask != null) {
|
||||
mask.style.display = 'none';
|
||||
}
|
||||
@@ -188,10 +187,10 @@ export class Popup {
|
||||
} else {
|
||||
doClose();
|
||||
}
|
||||
if (typeof option?.onMasking === 'function') {
|
||||
if (typeof option.onMasking === 'function') {
|
||||
option.onMasking.call(this, false);
|
||||
}
|
||||
if (typeof option?.resolve === 'function') {
|
||||
if (typeof option.resolve === 'function') {
|
||||
option.resolve.call(this, {
|
||||
result,
|
||||
popup: this
|
||||
@@ -206,20 +205,24 @@ export class Popup {
|
||||
create() {
|
||||
const mask = createElement('div', 'ui-popup-mask ui-popup-active');
|
||||
const option = this._var.option;
|
||||
if (option?.mask === false) {
|
||||
if (!option.mask) {
|
||||
mask.classList.add('ui-popup-transparent');
|
||||
} else if (typeof option?.onMasking === 'function') {
|
||||
} else if (typeof option.onMasking === 'function') {
|
||||
option.onMasking.call(this, true);
|
||||
}
|
||||
if (option?.zIndex != null && !isNaN(option.zIndex)) {
|
||||
if (option.zIndex != null && !isNaN(option.zIndex)) {
|
||||
mask.style.zIndex = String(option.zIndex);
|
||||
}
|
||||
const container = createElement('div', 'ui-popup-container');
|
||||
if (option?.changeZIndex === true) {
|
||||
const container = createElement('div', 'ui-popup-container drag-box');
|
||||
if (option.changeZIndex) {
|
||||
container.addEventListener('mousedown', () => {
|
||||
const masks = [...this._var.mask?.parentElement?.children].filter(e => e.classList.contains('ui-popup-mask'));
|
||||
const children = this._var.mask?.parentElement?.children;
|
||||
if (children == null) {
|
||||
return;
|
||||
}
|
||||
const masks = [...children].filter(e => e.classList.contains('ui-popup-mask'));
|
||||
let max = 200;
|
||||
masks.forEach(m => {
|
||||
(/** @type {HTMLElement[]} */ (masks)).forEach(m => {
|
||||
let index;
|
||||
if (m.dataset.zindex != null) {
|
||||
index = parseInt(m.dataset.zindex);
|
||||
@@ -243,63 +246,27 @@ export class Popup {
|
||||
tabIndex = 0;
|
||||
}
|
||||
container.tabIndex = tabIndex + 1;
|
||||
let content = option?.content;
|
||||
let content = option.content;
|
||||
if (!(content instanceof HTMLElement)) {
|
||||
content = createElement('div', d => d.innerText = content);
|
||||
content = createElement('div', d => d.innerText = (/** @type {string} */ (content)));
|
||||
}
|
||||
container.append(
|
||||
createElement('div', header => {
|
||||
header.className = 'ui-popup-header';
|
||||
let title = option?.title;
|
||||
let title = option.title;
|
||||
if (!(title instanceof HTMLElement)) {
|
||||
title = createElement('div', t => {
|
||||
if (option?.movable === false) {
|
||||
t.className = 'ui-popup-header-title no-move';
|
||||
} else {
|
||||
t.className = 'ui-popup-header-title';
|
||||
}
|
||||
t.innerText = title;
|
||||
t.className = 'ui-popup-header-title';
|
||||
t.innerText = (/** @type {string} */ (title));
|
||||
});
|
||||
}
|
||||
header.appendChild(title);
|
||||
if (option?.movable !== false) {
|
||||
const move = header; // title.querySelector('.ui-popup-move') ?? title;
|
||||
move.addEventListener('mousedown', e => {
|
||||
if (['svg', 'use'].includes(e.target?.tagName)) {
|
||||
return;
|
||||
}
|
||||
if (e.buttons !== 1) {
|
||||
return;
|
||||
}
|
||||
const parent = option?.mask === false ? mask.parentElement : mask;
|
||||
const x = e.clientX - container.offsetLeft;
|
||||
const y = e.clientY - container.offsetTop;
|
||||
/** @type {boolean} */
|
||||
let moved;
|
||||
const move = e => {
|
||||
if (e.buttons === 1) {
|
||||
container.style.left = `${e.clientX - x}px`;
|
||||
container.style.top = `${e.clientY - y}px`;
|
||||
moved = true;
|
||||
} else {
|
||||
parent.dispatchEvent(new MouseEvent('mouseup'));
|
||||
}
|
||||
};
|
||||
parent.addEventListener('mousemove', move, { passive: false });
|
||||
const up = () => {
|
||||
parent.removeEventListener('mousemove', move, { passive: false });
|
||||
parent.removeEventListener('mouseup', up);
|
||||
if (moved === true && typeof option?.onMoveEnded === 'function') {
|
||||
option.onMoveEnded.call(this);
|
||||
}
|
||||
moved = false;
|
||||
};
|
||||
parent.addEventListener('mouseup', up);
|
||||
});
|
||||
if (option.movable) {
|
||||
header.classList.add('drag-hover');
|
||||
}
|
||||
const icons = createElement('div', icons => {
|
||||
icons.className = 'ui-popup-header-icons';
|
||||
if (option?.collapsable === true) {
|
||||
if (option.collapsable) {
|
||||
const collapse = createIcon(IconStyle, 'compress-alt');
|
||||
collapse.tabIndex = tabIndex + 2;
|
||||
collapse.classList.add('icon-expand');
|
||||
@@ -324,13 +291,13 @@ export class Popup {
|
||||
container.classList.add('ui-popup-collapse');
|
||||
changeIcon(collapse, IconStyle, 'expand-alt');
|
||||
}
|
||||
if (typeof option?.onResizeEnded === 'function') {
|
||||
if (typeof option.onResizeEnded === 'function') {
|
||||
option.onResizeEnded.call(this);
|
||||
}
|
||||
});
|
||||
icons.appendChild(collapse);
|
||||
}
|
||||
if (option?.closable !== false) {
|
||||
if (option.closable) {
|
||||
const cancel = createIcon(IconStyle, 'times');
|
||||
cancel.tabIndex = tabIndex + 3;
|
||||
cancel.addEventListener('keypress', e => {
|
||||
@@ -348,7 +315,7 @@ export class Popup {
|
||||
createElement('div', null, createIcon(IconStyle, 'spinner-third'))
|
||||
))
|
||||
);
|
||||
if (Array.isArray(option?.buttons) && option.buttons.length > 0) {
|
||||
if (Array.isArray(option.buttons) && option.buttons.length > 0) {
|
||||
tabIndex = Math.max.apply(null, [...container.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0));
|
||||
container.appendChild(
|
||||
createElement('div', 'ui-popup-footer', ...option.buttons.map((b, i) => {
|
||||
@@ -368,14 +335,14 @@ export class Popup {
|
||||
button.addEventListener('click', () => {
|
||||
if (typeof b.trigger === 'function') {
|
||||
const result = b.trigger(this);
|
||||
if (typeof result?.then === 'function') {
|
||||
if (typeof result === 'boolean' || typeof result === 'string' || typeof result === 'number') {
|
||||
this.close(result);
|
||||
} else if (typeof result?.then === 'function') {
|
||||
result.then(r => {
|
||||
if (r !== false) {
|
||||
this.close(r);
|
||||
}
|
||||
}).catch(reason => console.warn(reason));
|
||||
} else if (result !== false) {
|
||||
this.close(result);
|
||||
}
|
||||
} else {
|
||||
this.close(b.key ?? i);
|
||||
@@ -387,10 +354,12 @@ export class Popup {
|
||||
const tabs = [...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} */
|
||||
const last = container.querySelector(`[tabindex="${tabMax}"]`);
|
||||
if (last != null) {
|
||||
last.addEventListener('keydown', e => {
|
||||
if (e.key === 'Tab') {
|
||||
/** @type {HTMLElement | null} */
|
||||
const first = container.querySelector(`[tabindex="${tabMin}"]`);
|
||||
first?.focus();
|
||||
e.preventDefault();
|
||||
@@ -398,50 +367,34 @@ export class Popup {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
container.querySelector('.ui-popup-body>.ui-popup-loading').classList.add('ui-popup-loading-content');
|
||||
container.querySelector('.ui-popup-body>.ui-popup-loading')?.classList.add('ui-popup-loading-content');
|
||||
}
|
||||
// resizable
|
||||
if (option?.resizable === true) {
|
||||
container.append(
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-right';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.right, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-bottom';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.bottom, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-left';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.left, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-top';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.top, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-bottom-right';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.bottomRight, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-bottom-left';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.bottomLeft, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-top-left';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.topLeft, e));
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.className = 'ui-popup-border ui-popup-border-top-right';
|
||||
layer.addEventListener('mousedown', e => this._resize(ResizeMods.topRight, e));
|
||||
})
|
||||
)
|
||||
if (option.resizable) {
|
||||
appendResizer(container);
|
||||
}
|
||||
if (option.movable || option.resizable) {
|
||||
const parent = !option.mask ? document.body : mask;
|
||||
makeMovable(parent, {
|
||||
movable: option.movable,
|
||||
resizable: option.resizable,
|
||||
context: this,
|
||||
onMoved: option.onMoveEnded,
|
||||
onResizeStart: option.onResizeStarted,
|
||||
onResized: option.onResizeEnded
|
||||
});
|
||||
}
|
||||
|
||||
mask.appendChild(container);
|
||||
this._var.mask = mask;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} parent
|
||||
* @param {boolean} hidden
|
||||
* @returns {Promise<HTMLElement> | undefined}
|
||||
*/
|
||||
show(parent = document.body, hidden = false) {
|
||||
if (parent == null) {
|
||||
return;
|
||||
@@ -469,7 +422,7 @@ export class Popup {
|
||||
return Promise.resolve(mask);
|
||||
}
|
||||
}
|
||||
if (this._var.option?.mask === false) {
|
||||
if (!this._var.option.mask) {
|
||||
// calculator position
|
||||
const container = this.container;
|
||||
if (container != null) {
|
||||
@@ -487,97 +440,14 @@ export class Popup {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_resize(mod, e) {
|
||||
if (e.buttons !== 1) {
|
||||
return;
|
||||
}
|
||||
const container = this.container;
|
||||
if (container == null) {
|
||||
return;
|
||||
}
|
||||
const option = this._var.option;
|
||||
if (typeof option?.onResizeStarted === 'function') {
|
||||
option.onResizeStarted.call(this);
|
||||
}
|
||||
const mask = this._var.mask;
|
||||
// this._var.cursor = mask.style.cursor;
|
||||
// mask.style.cursor = Cursors[mod];
|
||||
const originalX = e.clientX;
|
||||
const originalY = e.clientY;
|
||||
const original = {
|
||||
width: container.offsetWidth,
|
||||
height: container.offsetHeight,
|
||||
left: container.offsetLeft,
|
||||
top: container.offsetTop
|
||||
};
|
||||
const minWidth = option?.minWidth ?? 200;
|
||||
const minHeight = option?.minHeight ?? 200;
|
||||
/** @type {boolean} */
|
||||
let resized;
|
||||
const parent = option?.mask === false ? mask.parentElement : mask;
|
||||
const move = e => {
|
||||
if (e.buttons !== 1) {
|
||||
parent?.dispatchEvent(new MouseEvent('mouseup'));
|
||||
return;
|
||||
}
|
||||
const offsetX = e.clientX - originalX;
|
||||
const offsetY = e.clientY - originalY;
|
||||
let width = original.width;
|
||||
let height = original.height;
|
||||
let x = original.left;
|
||||
let y = original.top;
|
||||
if ((mod & ResizeMods.right) === ResizeMods.right) {
|
||||
width += offsetX;
|
||||
if (width < minWidth) {
|
||||
width = minWidth;
|
||||
}
|
||||
}
|
||||
if ((mod & ResizeMods.bottom) === ResizeMods.bottom) {
|
||||
height += offsetY;
|
||||
if (height < minHeight) {
|
||||
height = minHeight;
|
||||
}
|
||||
}
|
||||
if ((mod & ResizeMods.left) === ResizeMods.left) {
|
||||
width -= offsetX;
|
||||
if (width < minWidth) {
|
||||
width = minWidth;
|
||||
x = originalX + original.width - minWidth;
|
||||
} else {
|
||||
x += offsetX;
|
||||
}
|
||||
}
|
||||
if ((mod & ResizeMods.top) === ResizeMods.top) {
|
||||
height -= offsetY;
|
||||
if (height < minHeight) {
|
||||
height = minHeight;
|
||||
y = originalY + original.height - minHeight;
|
||||
} else {
|
||||
y += offsetY;
|
||||
}
|
||||
}
|
||||
if (typeof option?.onResizing === 'function') {
|
||||
option.onResizing.call(this, x, y, width, height);
|
||||
} else {
|
||||
container.style.cssText += `left: ${x}px; top: ${y}px; width: ${width}px; height: ${height}px`;
|
||||
}
|
||||
resized = true;
|
||||
}
|
||||
parent?.addEventListener('mousemove', move, { passive: false });
|
||||
const up = () => {
|
||||
parent.removeEventListener('mousemove', move, { passive: false });
|
||||
parent.removeEventListener('mouseup', up);
|
||||
// mask.style.cursor = this._var.cursor;
|
||||
if (resized === true && typeof option?.onResizeEnded === 'function') {
|
||||
option.onResizeEnded.call(this);
|
||||
}
|
||||
resized = false;
|
||||
};
|
||||
parent?.addEventListener('mouseup', up);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | HTMLElement} title
|
||||
* @param {string | HTMLElement} content
|
||||
* @param {...PopupButton} buttons
|
||||
* @returns {Popup}
|
||||
*/
|
||||
export function createPopup(title, content, ...buttons) {
|
||||
const popup = new Popup({
|
||||
title,
|
||||
@@ -589,11 +459,11 @@ export function createPopup(title, content, ...buttons) {
|
||||
|
||||
/**
|
||||
* 解析对话框元素
|
||||
* @param {HTMLElement | string} wrapper - 解析该 `.dialog` 元素
|
||||
* @param {HTMLElement | string | null} wrapper - 解析该 `.dialog` 元素
|
||||
* @param {Function} [callback] - 关闭对话框时的回调
|
||||
* @param {boolean} [removable] - 是否可移除
|
||||
* @param {number} [zIndex] - 对话框默认 `z-index`
|
||||
* @returns {Popup} 返回弹出框字典
|
||||
* @returns {Popup | null} 返回弹出框字典
|
||||
*/
|
||||
export function resolvePopup(wrapper, callback, removable, zIndex) {
|
||||
if (typeof wrapper === 'string') {
|
||||
@@ -606,18 +476,20 @@ export function resolvePopup(wrapper, callback, removable, zIndex) {
|
||||
return null;
|
||||
}
|
||||
const title = wrapper.querySelector('.dialog-title>.title')?.innerText;
|
||||
/** @type {HTMLElement | null} */
|
||||
const content = wrapper.querySelector('.dialog-title+div');
|
||||
const buttons = [...wrapper.querySelectorAll('.dialog-func>input[type="button"]')].reverse().map(b => ({
|
||||
const buttons = /** @type {HTMLInputElement[]} */ ([...wrapper.querySelectorAll('.dialog-func>input[type="button"]')].reverse()).map(b => ({
|
||||
tabIndex: b.tabIndex,
|
||||
text: b.value,
|
||||
isPrimary: b.dataset.primary != null,
|
||||
trigger: b.onclick == null ? null : (popup => (b.onclick.call(popup), false))
|
||||
// @ts-ignore
|
||||
trigger: b.onclick == null ? undefined : ((/** @type {IPopup} */ popup) => (b.onclick?.call(popup, null), false))
|
||||
}));
|
||||
const popup = new Popup({
|
||||
title,
|
||||
content,
|
||||
content: content ?? '',
|
||||
persistent: !removable,
|
||||
resolve: typeof callback === 'function' ? (result => callback(result)) : null,
|
||||
resolve: typeof callback === 'function' ? (result => callback(result)) : undefined,
|
||||
zIndex: wrapper.zIndex ?? zIndex,
|
||||
buttons
|
||||
});
|
||||
@@ -634,8 +506,15 @@ const iconTypes = {
|
||||
'error': 'times-circle'
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | HTMLElement} title
|
||||
* @param {string} message
|
||||
* @param {keyof iconTypes} iconType
|
||||
* @param {HTMLElement} parent
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export function showAlert(title, message, iconType = 'info', parent = document.body) {
|
||||
const r = typeof GetTextByKey === 'function' ? GetTextByKey : lang;
|
||||
const r = typeof global.GetTextByKey === 'function' ? global.GetTextByKey : lang;
|
||||
return new Promise(resolve => {
|
||||
const popup = new Popup({
|
||||
title,
|
||||
@@ -648,16 +527,26 @@ export function showAlert(title, message, iconType = 'info', parent = document.b
|
||||
{ text: r('ok', 'OK'), isPrimary: true }
|
||||
]
|
||||
});
|
||||
popup.show(parent).then(mask => {
|
||||
popup.show(parent)?.then(mask => {
|
||||
/** @type {HTMLElement | null} */
|
||||
const button = mask.querySelector('.ui-popup-container .ui-popup-footer .ui-popup-button');
|
||||
button?.focus();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | HTMLElement} title
|
||||
* @param {boolean} multiline
|
||||
* @param {string} message
|
||||
* @param {InputOptions} options
|
||||
* @param {PopupButton[]} buttons
|
||||
* @param {HTMLElement} parent
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export function showInput(title, multiline, message, options, buttons, parent = document.body) {
|
||||
const r = typeof GetTextByKey === 'function' ? GetTextByKey : lang;
|
||||
options ??= {};
|
||||
const r = typeof global.GetTextByKey === 'function' ? global.GetTextByKey : lang;
|
||||
const opts = mergeOptions({}, options);
|
||||
return new Promise(resolve => {
|
||||
const input = multiline ?
|
||||
createElement('textarea', text => {
|
||||
@@ -667,29 +556,29 @@ export function showInput(title, multiline, message, options, buttons, parent =
|
||||
input.type = 'text';
|
||||
input.className = 'ui-input';
|
||||
});
|
||||
for (let key of Object.keys(options)) {
|
||||
for (let key of Object.keys(opts)) {
|
||||
switch (key) {
|
||||
case 'tabIndex':
|
||||
if (!isNaN(options.tabIndex)) {
|
||||
input.tabIndex = options.tabIndex;
|
||||
if (!isNaN(opts.tabIndex)) {
|
||||
input.tabIndex = opts.tabIndex;
|
||||
}
|
||||
break;
|
||||
case 'default':
|
||||
if (!nullOrEmpty(options.default)) {
|
||||
input.value = options.default;
|
||||
if (!nullOrEmpty(opts.default)) {
|
||||
input.value = opts.default;
|
||||
}
|
||||
break;
|
||||
case 'placeholder':
|
||||
if (!nullOrEmpty(options.placeholder)) {
|
||||
input.placeholder = options.placeholder;
|
||||
if (!nullOrEmpty(opts.placeholder)) {
|
||||
input.placeholder = opts.placeholder;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
input[key] = options[key];
|
||||
input[key] = opts[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNaN(options.tabIndex)) {
|
||||
if (isNaN(opts.tabIndex)) {
|
||||
let tabIndex = Math.max.apply(null, [...document.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0));
|
||||
if (tabIndex < 0) {
|
||||
tabIndex = 0;
|
||||
@@ -708,12 +597,21 @@ export function showInput(title, multiline, message, options, buttons, parent =
|
||||
{ key: 'no', text: r('no', 'No') }
|
||||
]
|
||||
});
|
||||
popup.show(parent).then(() => input.focus());
|
||||
popup.show(parent)?.then(() => input.focus());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string | HTMLElement} title
|
||||
* @param {string | HTMLElement} content
|
||||
* @param {PopupButton[]} buttons
|
||||
* @param {keyof iconTypes} iconType
|
||||
* @param {HTMLElement} parent
|
||||
* @returns
|
||||
*/
|
||||
export function showConfirm(title, content, buttons, iconType = 'question', parent = document.body) {
|
||||
const r = typeof GetTextByKey === 'function' ? GetTextByKey : lang;
|
||||
const r = typeof global.GetTextByKey === 'function' ? global.GetTextByKey : lang;
|
||||
return new Promise(resolve => {
|
||||
const wrapper = createElement('div', 'message-wrapper');
|
||||
if (!nullOrEmpty(iconType)) {
|
||||
@@ -731,13 +629,10 @@ export function showConfirm(title, content, buttons, iconType = 'question', pare
|
||||
text: b.text,
|
||||
isPrimary: b.isPrimary,
|
||||
trigger: p => {
|
||||
let result;
|
||||
if (typeof b.trigger === 'function') {
|
||||
result = b.trigger(p, b);
|
||||
} else {
|
||||
result = b.key ?? i;
|
||||
return b.trigger(p, b);
|
||||
}
|
||||
return result;
|
||||
return b.key ?? i;
|
||||
}
|
||||
};
|
||||
}) ??
|
||||
@@ -746,7 +641,8 @@ export function showConfirm(title, content, buttons, iconType = 'question', pare
|
||||
{ key: 'no', text: r('no', 'No') }
|
||||
]
|
||||
});
|
||||
popup.show(parent).then(mask => {
|
||||
popup.show(parent)?.then(mask => {
|
||||
/** @type {HTMLElement | null} */
|
||||
const button = mask.querySelector('.ui-popup-container .ui-popup-footer .ui-popup-button:first-child');
|
||||
button?.focus();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user