@whitesev/pops 4.0.1 → 4.1.0
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.amd.js +229 -141
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +229 -141
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +229 -141
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +229 -141
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +229 -141
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +229 -141
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Pops.d.ts +126 -9
- package/dist/types/src/components/loading/types/index.d.ts +1 -1
- package/dist/types/src/components/panel/index.d.ts +3 -2
- package/dist/types/src/components/rightClickMenu/types/index.d.ts +1 -1
- package/dist/types/src/components/searchSuggestion/types/index.d.ts +1 -1
- package/dist/types/src/components/tooltip/index.d.ts +82 -1
- package/dist/types/src/components/tooltip/types/index.d.ts +1 -1
- package/dist/types/src/config/GlobalConfig.d.ts +3 -3
- package/dist/types/src/event/EventEmiter.d.ts +7 -1
- package/dist/types/src/handler/PopsInstHandler.d.ts +4 -4
- package/dist/types/src/types/EventEmitter.d.ts +21 -0
- package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +1 -1
- package/dist/types/src/types/components.d.ts +15 -18
- package/dist/types/src/types/global.d.ts +2 -0
- package/dist/types/src/utils/PopsDOMUtils.d.ts +14 -2
- package/dist/types/src/utils/PopsUtils.d.ts +20 -15
- package/package.json +1 -1
- package/src/Pops.ts +6 -0
- package/src/components/alert/defaultConfig.ts +1 -1
- package/src/components/alert/index.ts +1 -1
- package/src/components/confirm/defaultConfig.ts +1 -1
- package/src/components/confirm/index.ts +1 -1
- package/src/components/drawer/defaultConfig.ts +1 -1
- package/src/components/drawer/index.ts +2 -1
- package/src/components/folder/defaultConfig.ts +1 -1
- package/src/components/folder/index.ts +1 -1
- package/src/components/iframe/defaultConfig.ts +1 -1
- package/src/components/iframe/index.ts +10 -6
- package/src/components/loading/defaultConfig.ts +1 -0
- package/src/components/loading/index.ts +10 -10
- package/src/components/loading/types/index.ts +1 -4
- package/src/components/panel/defaultConfig.ts +1 -1
- package/src/components/panel/index.ts +3 -2
- package/src/components/prompt/defaultConfig.ts +1 -1
- package/src/components/prompt/index.ts +1 -1
- package/src/components/rightClickMenu/defaultConfig.ts +1 -1
- package/src/components/rightClickMenu/index.ts +1 -1
- package/src/components/rightClickMenu/types/index.ts +1 -1
- package/src/components/searchSuggestion/defaultConfig.ts +1 -0
- package/src/components/searchSuggestion/index.ts +1 -1
- package/src/components/searchSuggestion/types/index.ts +1 -1
- package/src/components/tooltip/defaultConfig.ts +1 -1
- package/src/components/tooltip/index.ts +1 -1
- package/src/components/tooltip/types/index.ts +1 -1
- package/src/event/EventEmiter.ts +15 -14
- package/src/handler/PopsInstHandler.ts +64 -47
- package/src/types/EventEmitter.d.ts +21 -0
- package/src/types/PopsDOMUtilsEventType.d.ts +1 -1
- package/src/types/components.d.ts +15 -18
- package/src/types/global.d.ts +2 -0
- package/src/utils/PopsDOMUtils.ts +32 -2
- package/src/utils/PopsUtils.ts +94 -67
package/src/utils/PopsUtils.ts
CHANGED
|
@@ -2,6 +2,7 @@ import AnyTouch from "any-touch";
|
|
|
2
2
|
import doubletap from "@any-touch/doubletap";
|
|
3
3
|
import { PopsCore } from "../PopsCore";
|
|
4
4
|
import type { PopsUtilsOwnObject } from "../types/main";
|
|
5
|
+
import { EventEmiter } from "../event/EventEmiter";
|
|
5
6
|
|
|
6
7
|
class PopsUtils {
|
|
7
8
|
/**
|
|
@@ -136,7 +137,8 @@ class PopsUtils {
|
|
|
136
137
|
typeof sourceValue === "object" &&
|
|
137
138
|
sourceValue != null &&
|
|
138
139
|
keyName in target &&
|
|
139
|
-
!UtilsContext.isDOM(sourceValue)
|
|
140
|
+
!UtilsContext.isDOM(sourceValue) &&
|
|
141
|
+
!(sourceValue instanceof EventEmiter)
|
|
140
142
|
) {
|
|
141
143
|
// 源端的值是object类型,且不是元素节点
|
|
142
144
|
// 如果是数组,那此数组中有值,清空旧的数组再赋值
|
|
@@ -151,7 +153,7 @@ class PopsUtils {
|
|
|
151
153
|
}
|
|
152
154
|
Reflect.set(target, keyName, childObjectValue);
|
|
153
155
|
} else {
|
|
154
|
-
|
|
156
|
+
// 直接赋值
|
|
155
157
|
Reflect.set(target, keyName, sourceValue);
|
|
156
158
|
}
|
|
157
159
|
}
|
|
@@ -414,18 +416,24 @@ class PopsUtils {
|
|
|
414
416
|
/**
|
|
415
417
|
* 获取页面的坐标中最大的z-index的元素信息
|
|
416
418
|
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* + 左上角(宽: 1/8,高: 1/8)
|
|
420
|
-
* + 右上角(宽: 7/8,高: 1/8)
|
|
421
|
-
* + 左下角(宽: 1/8,高: 7/8)
|
|
422
|
-
* + 右下角(宽: 7/8,高: 7/8)
|
|
423
|
-
* + 中间(宽: 1/2,高: 1/2)
|
|
419
|
+
* 矩阵坐标计算
|
|
424
420
|
* @param $el 仅检测目标元素最大的z-index(自动往上层找)
|
|
425
421
|
* @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
|
|
422
|
+
* @example
|
|
423
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"));
|
|
424
|
+
* @example
|
|
425
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"), 20);
|
|
426
|
+
* @example
|
|
427
|
+
* Utils.getMaxZIndexNodeInfoFromPoint([document.querySelector("a"), document.querySelector("div")]);
|
|
428
|
+
* @example
|
|
429
|
+
* Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500});
|
|
430
|
+
* @example
|
|
431
|
+
* Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500}, 20);
|
|
432
|
+
* @example
|
|
433
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(() => {x: 500, y: 500}, 20);
|
|
426
434
|
*/
|
|
427
435
|
getMaxZIndexNodeInfoFromPoint(
|
|
428
|
-
$el?: IFunction<HTMLElement |
|
|
436
|
+
$el?: IFunction<IArray<HTMLElement> | IArray<{ x: number; y: number }>>,
|
|
429
437
|
deviation?: number
|
|
430
438
|
): {
|
|
431
439
|
/** 处理了偏移量后的z-index值 */
|
|
@@ -444,14 +452,10 @@ class PopsUtils {
|
|
|
444
452
|
/**
|
|
445
453
|
* 获取页面的坐标中最大的z-index的元素信息
|
|
446
454
|
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
* + 左上角(宽: 1/8,高: 1/8)
|
|
450
|
-
* + 右上角(宽: 7/8,高: 1/8)
|
|
451
|
-
* + 左下角(宽: 1/8,高: 7/8)
|
|
452
|
-
* + 右下角(宽: 7/8,高: 7/8)
|
|
453
|
-
* + 中间(宽: 1/2,高: 1/2)
|
|
455
|
+
* 矩阵坐标计算
|
|
454
456
|
* @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
|
|
457
|
+
* @example
|
|
458
|
+
* Utils.getMaxZIndexNodeInfoFromPoint(20);
|
|
455
459
|
*/
|
|
456
460
|
getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
|
|
457
461
|
/** 处理了偏移量后的z-index值 */
|
|
@@ -468,7 +472,7 @@ class PopsUtils {
|
|
|
468
472
|
positionY: number;
|
|
469
473
|
}[];
|
|
470
474
|
getMaxZIndexNodeInfoFromPoint(
|
|
471
|
-
$el?: IFunction<HTMLElement |
|
|
475
|
+
$el?: IFunction<IArray<HTMLElement> | number | IArray<{ x: number; y: number }>>,
|
|
472
476
|
deviation?: number
|
|
473
477
|
): {
|
|
474
478
|
/** 处理了偏移量后的z-index值 */
|
|
@@ -494,33 +498,34 @@ class PopsUtils {
|
|
|
494
498
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
495
499
|
deviation = 10;
|
|
496
500
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
501
|
+
/** 坐标偏移 */
|
|
502
|
+
const positionDistance = 10;
|
|
503
|
+
const defaultCalcPostion: {
|
|
504
|
+
x: number;
|
|
505
|
+
y: number;
|
|
506
|
+
}[] = [];
|
|
507
|
+
const maxPostionX = globalThis.innerWidth;
|
|
508
|
+
const maxPostionY = globalThis.innerHeight;
|
|
509
|
+
const gridXCount = 8;
|
|
510
|
+
const gridYCount = 8;
|
|
511
|
+
for (let i = 0; i < gridXCount; i++) {
|
|
512
|
+
for (let j = 0; j < gridYCount; j++) {
|
|
513
|
+
const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
|
|
514
|
+
const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
|
|
515
|
+
const position: (typeof defaultCalcPostion)[0] = {
|
|
516
|
+
x: positionX,
|
|
517
|
+
y: positionY,
|
|
518
|
+
};
|
|
519
|
+
if (position.x > maxPostionX) {
|
|
520
|
+
position.x = maxPostionX;
|
|
521
|
+
}
|
|
522
|
+
if (position.y > maxPostionY) {
|
|
523
|
+
position.y = maxPostionY;
|
|
524
|
+
}
|
|
525
|
+
defaultCalcPostion.push(position);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const delayHandlerElementPostionList: ({ x: number; y: number } | HTMLElement)[] = defaultCalcPostion;
|
|
524
529
|
if ($el) {
|
|
525
530
|
delayHandlerElementPostionList.length = 0;
|
|
526
531
|
if (Array.isArray($el)) {
|
|
@@ -531,55 +536,77 @@ class PopsUtils {
|
|
|
531
536
|
}
|
|
532
537
|
const positionInfoList = delayHandlerElementPostionList
|
|
533
538
|
.map((position) => {
|
|
534
|
-
let
|
|
539
|
+
let $position: Element | null;
|
|
535
540
|
let positionX: number;
|
|
536
541
|
let positionY: number;
|
|
537
542
|
if (position instanceof HTMLElement) {
|
|
538
|
-
|
|
543
|
+
$position = position;
|
|
539
544
|
const nodeRect = position.getBoundingClientRect();
|
|
540
545
|
positionX = nodeRect.x + nodeRect.width / 2;
|
|
541
546
|
positionY = nodeRect.y + nodeRect.height / 2;
|
|
542
547
|
} else {
|
|
543
|
-
|
|
548
|
+
$position = document.elementFromPoint(position.x, position.y);
|
|
544
549
|
positionX = position.x;
|
|
545
550
|
positionY = position.y;
|
|
546
551
|
}
|
|
547
|
-
const shadowRoot =
|
|
552
|
+
const shadowRoot = $position?.shadowRoot;
|
|
548
553
|
if (shadowRoot) {
|
|
549
|
-
|
|
554
|
+
// 处理ShadowRoot
|
|
555
|
+
$position = shadowRoot.elementFromPoint(positionX, positionY);
|
|
550
556
|
}
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
if (positionNode instanceof HTMLMetaElement) return;
|
|
554
|
-
if (positionNode instanceof HTMLHeadElement) return;
|
|
555
|
-
if (!(positionNode instanceof HTMLElement)) return;
|
|
556
|
-
let parent: HTMLElement | null = positionNode;
|
|
557
|
+
if (!($position instanceof HTMLElement)) return;
|
|
558
|
+
let $parent: HTMLElement | null = $position;
|
|
557
559
|
let zIndex = 0;
|
|
558
|
-
let maxZIndexNode: HTMLElement | null = null;
|
|
559
|
-
|
|
560
|
-
|
|
560
|
+
let $maxZIndexNode: HTMLElement | null = null;
|
|
561
|
+
let rect = {
|
|
562
|
+
x: 0,
|
|
563
|
+
y: 0,
|
|
564
|
+
width: 0,
|
|
565
|
+
height: 0,
|
|
566
|
+
top: 0,
|
|
567
|
+
right: 0,
|
|
568
|
+
bottom: 0,
|
|
569
|
+
left: 0,
|
|
570
|
+
} as Omit<DOMRect, "toJSON">;
|
|
571
|
+
while ($parent) {
|
|
572
|
+
const nodeStyle = globalThis.getComputedStyle($parent);
|
|
561
573
|
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
562
574
|
if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
|
|
563
575
|
if (nodeZIndex > zIndex) {
|
|
564
576
|
zIndex = nodeZIndex;
|
|
565
|
-
maxZIndexNode = parent;
|
|
577
|
+
$maxZIndexNode = $parent;
|
|
566
578
|
}
|
|
567
579
|
}
|
|
568
|
-
parent = parent.parentElement;
|
|
580
|
+
$parent = $parent.parentElement;
|
|
581
|
+
}
|
|
582
|
+
if ($maxZIndexNode) {
|
|
583
|
+
const maxRect = $maxZIndexNode.getBoundingClientRect();
|
|
584
|
+
rect = {
|
|
585
|
+
x: maxRect.x,
|
|
586
|
+
y: maxRect.y,
|
|
587
|
+
width: maxRect.width,
|
|
588
|
+
height: maxRect.height,
|
|
589
|
+
top: maxRect.top,
|
|
590
|
+
right: maxRect.right,
|
|
591
|
+
bottom: maxRect.bottom,
|
|
592
|
+
left: maxRect.left,
|
|
593
|
+
};
|
|
569
594
|
}
|
|
570
595
|
return {
|
|
571
|
-
/**
|
|
596
|
+
/** 计算偏移量后的z-index值 */
|
|
572
597
|
zIndex: zIndex + deviation,
|
|
573
|
-
/**
|
|
598
|
+
/** 获取到的最大的z-index值 */
|
|
574
599
|
originZIndex: zIndex,
|
|
575
600
|
/** 拥有最大z-index的元素 */
|
|
576
|
-
node: maxZIndexNode,
|
|
601
|
+
node: $maxZIndexNode,
|
|
577
602
|
/** 目标坐标元素 */
|
|
578
|
-
positionNode:
|
|
579
|
-
/** x坐标 */
|
|
603
|
+
positionNode: $position,
|
|
604
|
+
/** 目标x坐标 */
|
|
580
605
|
positionX: positionX,
|
|
581
|
-
/** y坐标 */
|
|
606
|
+
/** 目标y坐标 */
|
|
582
607
|
positionY: positionY,
|
|
608
|
+
/** node位置信息 */
|
|
609
|
+
rect,
|
|
583
610
|
};
|
|
584
611
|
})
|
|
585
612
|
.filter((it) => it != null);
|