@antv/l7-component 2.21.1 → 2.21.3
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/es/assets/iconfont/iconfont.js +6 -6
- package/es/constants/index.js +2 -2
- package/es/control/baseControl/buttonControl.js +109 -144
- package/es/control/baseControl/control.js +212 -258
- package/es/control/baseControl/popperControl.js +67 -95
- package/es/control/baseControl/selectControl.js +132 -178
- package/es/control/exportImage.js +59 -142
- package/es/control/fullscreen.js +69 -100
- package/es/control/geoLocate.js +37 -84
- package/es/control/layerSwitch.js +111 -154
- package/es/control/logo.js +43 -69
- package/es/control/mapTheme.js +57 -98
- package/es/control/mouseLocation.js +37 -69
- package/es/control/scale.js +107 -135
- package/es/control/swipe.js +297 -389
- package/es/control/zoom.js +80 -112
- package/es/css/index.css +10 -7
- package/es/index.js +675 -1
- package/es/marker-layer.js +275 -326
- package/es/marker.js +394 -446
- package/es/popup/layerPopup.js +277 -321
- package/es/popup/popup.js +422 -482
- package/es/utils/anchor.js +6 -6
- package/es/utils/icon.js +4 -4
- package/es/utils/popper.js +180 -196
- package/es/utils/screenfull.js +29 -51
- package/lib/assets/iconfont/iconfont.js +6 -6
- package/lib/constants/index.d.ts +60 -0
- package/lib/constants/index.js +2 -2
- package/lib/control/baseControl/buttonControl.d.ts +60 -0
- package/lib/control/baseControl/buttonControl.js +110 -143
- package/lib/control/baseControl/control.d.ts +112 -0
- package/lib/control/baseControl/control.js +213 -257
- package/lib/control/baseControl/index.d.ts +4 -0
- package/lib/control/baseControl/index.js +5 -5
- package/lib/control/baseControl/popperControl.d.ts +28 -0
- package/lib/control/baseControl/popperControl.js +68 -94
- package/lib/control/baseControl/selectControl.d.ts +53 -0
- package/lib/control/baseControl/selectControl.js +133 -177
- package/lib/control/exportImage.d.ts +19 -0
- package/lib/control/exportImage.js +60 -141
- package/lib/control/fullscreen.d.ts +20 -0
- package/lib/control/fullscreen.js +70 -99
- package/lib/control/geoLocate.d.ts +17 -0
- package/lib/control/geoLocate.js +38 -83
- package/lib/control/layerSwitch.d.ts +27 -0
- package/lib/control/layerSwitch.js +112 -153
- package/lib/control/logo.d.ts +14 -0
- package/lib/control/logo.js +44 -69
- package/lib/control/mapTheme.d.ts +11 -0
- package/lib/control/mapTheme.js +58 -97
- package/lib/control/mouseLocation.d.ts +16 -0
- package/lib/control/mouseLocation.js +38 -68
- package/lib/control/scale.d.ts +35 -0
- package/lib/control/scale.js +108 -134
- package/lib/control/swipe.d.ts +66 -0
- package/lib/control/swipe.js +298 -388
- package/lib/control/zoom.d.ts +39 -0
- package/lib/control/zoom.js +81 -111
- package/lib/css/index.css +10 -7
- package/lib/index.d.ts +19 -0
- package/lib/index.js +691 -17
- package/lib/interface.d.ts +18 -0
- package/lib/marker-layer.d.ts +55 -0
- package/lib/marker-layer.js +277 -324
- package/lib/marker.d.ts +58 -0
- package/lib/marker.js +395 -445
- package/lib/popup/layerPopup.d.ts +99 -0
- package/lib/popup/layerPopup.js +278 -320
- package/lib/popup/popup.d.ts +142 -0
- package/lib/popup/popup.js +423 -481
- package/lib/utils/anchor.d.ts +22 -0
- package/lib/utils/anchor.js +6 -6
- package/lib/utils/icon.d.ts +1 -0
- package/lib/utils/icon.js +6 -5
- package/lib/utils/popper.d.ts +76 -0
- package/lib/utils/popper.js +184 -196
- package/lib/utils/screenfull.d.ts +2 -0
- package/lib/utils/screenfull.js +29 -52
- package/package.json +16 -20
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum anchorType {
|
|
2
|
+
'CENTER' = "center",
|
|
3
|
+
'TOP' = "top",
|
|
4
|
+
'TOP-LEFT' = "top-left",
|
|
5
|
+
'TOP-RIGHT' = "top-right",
|
|
6
|
+
'BOTTOM' = "bottom",
|
|
7
|
+
'BOTTOM-LEFT' = "bottom-left",
|
|
8
|
+
'LEFT' = "left",
|
|
9
|
+
'RIGHT' = "right"
|
|
10
|
+
}
|
|
11
|
+
export declare const anchorTranslate: {
|
|
12
|
+
center: string;
|
|
13
|
+
top: string;
|
|
14
|
+
'top-left': string;
|
|
15
|
+
'top-right': string;
|
|
16
|
+
bottom: string;
|
|
17
|
+
'bottom-left': string;
|
|
18
|
+
'bottom-right': string;
|
|
19
|
+
left: string;
|
|
20
|
+
right: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function applyAnchorClass(element: HTMLElement, anchor: string, prefix: string): void;
|
package/lib/utils/anchor.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.anchorType = exports.anchorTranslate = void 0;
|
|
7
7
|
exports.applyAnchorClass = applyAnchorClass;
|
|
8
|
-
|
|
8
|
+
let anchorType = exports.anchorType = /*#__PURE__*/function (anchorType) {
|
|
9
9
|
anchorType["CENTER"] = "center";
|
|
10
10
|
anchorType["TOP"] = "top";
|
|
11
11
|
anchorType["TOP-LEFT"] = "top-left";
|
|
@@ -16,7 +16,7 @@ var anchorType = exports.anchorType = /*#__PURE__*/function (anchorType) {
|
|
|
16
16
|
anchorType["RIGHT"] = "right";
|
|
17
17
|
return anchorType;
|
|
18
18
|
}({});
|
|
19
|
-
|
|
19
|
+
const anchorTranslate = exports.anchorTranslate = {
|
|
20
20
|
center: 'translate(-50%,-50%)',
|
|
21
21
|
top: 'translate(-50%,0)',
|
|
22
22
|
'top-left': 'translate(0,0)',
|
|
@@ -28,11 +28,11 @@ var anchorTranslate = exports.anchorTranslate = {
|
|
|
28
28
|
right: 'translate(-100%,-50%)'
|
|
29
29
|
};
|
|
30
30
|
function applyAnchorClass(element, anchor, prefix) {
|
|
31
|
-
|
|
32
|
-
for (
|
|
31
|
+
const classList = element.classList;
|
|
32
|
+
for (const key in anchorTranslate) {
|
|
33
33
|
if (anchorTranslate.hasOwnProperty(key)) {
|
|
34
|
-
classList.remove(
|
|
34
|
+
classList.remove(`l7-${prefix}-anchor-${key}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
classList.add(
|
|
37
|
+
classList.add(`l7-${prefix}-anchor-${anchor}`);
|
|
38
38
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createL7Icon: (className: string) => SVGSVGElement;
|
package/lib/utils/icon.js
CHANGED
|
@@ -4,12 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createL7Icon = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const createL7Icon = className => {
|
|
8
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
9
9
|
svg.classList.add('l7-iconfont');
|
|
10
10
|
svg.setAttribute('aria-hidden', 'true');
|
|
11
|
-
|
|
12
|
-
use.setAttributeNS('http://www.w3.org/1999/xlink', 'href',
|
|
11
|
+
const use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
|
|
12
|
+
use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', `#${className}`);
|
|
13
13
|
svg.appendChild(use);
|
|
14
14
|
return svg;
|
|
15
|
-
};
|
|
15
|
+
};
|
|
16
|
+
exports.createL7Icon = createL7Icon;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
/**
|
|
3
|
+
* 气泡位置枚举
|
|
4
|
+
*/
|
|
5
|
+
export type PopperPlacement = 'top-start' | 'top' | 'top-end' | 'left-start' | 'left' | 'left-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'right-start' | 'right' | 'right-end';
|
|
6
|
+
/**
|
|
7
|
+
* 气泡触发类型,当前支持 click 和 hover 两种类型
|
|
8
|
+
*/
|
|
9
|
+
export type PopperTrigger = 'click' | 'hover';
|
|
10
|
+
/**
|
|
11
|
+
* 气泡内容类型
|
|
12
|
+
*/
|
|
13
|
+
export type PopperContent = string | HTMLElement | null;
|
|
14
|
+
export interface IPopperOption {
|
|
15
|
+
placement: PopperPlacement;
|
|
16
|
+
trigger: PopperTrigger;
|
|
17
|
+
content?: PopperContent;
|
|
18
|
+
offset?: [number, number];
|
|
19
|
+
className?: string;
|
|
20
|
+
container: HTMLElement;
|
|
21
|
+
unique?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class Popper extends EventEmitter<'show' | 'hide'> {
|
|
24
|
+
protected get buttonRect(): DOMRect;
|
|
25
|
+
protected static conflictPopperList: Popper[];
|
|
26
|
+
popperDOM: HTMLElement;
|
|
27
|
+
contentDOM: HTMLElement;
|
|
28
|
+
/**
|
|
29
|
+
* 按钮实体
|
|
30
|
+
* @protected
|
|
31
|
+
*/
|
|
32
|
+
protected button: HTMLElement;
|
|
33
|
+
/**
|
|
34
|
+
* Popper 配置
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
protected option: IPopperOption;
|
|
38
|
+
/**
|
|
39
|
+
* 当前是否展示
|
|
40
|
+
* @protected
|
|
41
|
+
*/
|
|
42
|
+
protected isShow: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 当前气泡展示的内容
|
|
45
|
+
* @protected
|
|
46
|
+
*/
|
|
47
|
+
protected content: PopperContent;
|
|
48
|
+
/**
|
|
49
|
+
* 关闭气泡的定时器
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
protected timeout: number | null;
|
|
53
|
+
constructor(button: HTMLElement, option: IPopperOption);
|
|
54
|
+
getPopperDOM(): HTMLElement;
|
|
55
|
+
getIsShow(): boolean;
|
|
56
|
+
getContent(): PopperContent;
|
|
57
|
+
setContent(content: PopperContent): void;
|
|
58
|
+
show: () => this;
|
|
59
|
+
hide: () => this;
|
|
60
|
+
/**
|
|
61
|
+
* 设置隐藏气泡的定时器
|
|
62
|
+
*/
|
|
63
|
+
setHideTimeout: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* 销毁隐藏气泡的定时器
|
|
66
|
+
*/
|
|
67
|
+
clearHideTimeout: () => void;
|
|
68
|
+
init(): void;
|
|
69
|
+
destroy(): void;
|
|
70
|
+
resetPopperPosition(): void;
|
|
71
|
+
protected createPopper(): HTMLElement;
|
|
72
|
+
protected onBtnClick: () => void;
|
|
73
|
+
protected onPopperUnClick: (e: MouseEvent) => void;
|
|
74
|
+
protected onBtnMouseLeave: () => void;
|
|
75
|
+
protected onBtnMouseMove: () => void;
|
|
76
|
+
}
|
package/lib/utils/popper.js
CHANGED
|
@@ -5,264 +5,252 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.Popper = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
9
|
var _l7Utils = require("@antv/l7-utils");
|
|
17
10
|
var _eventemitter = require("eventemitter3");
|
|
18
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
19
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
11
|
/**
|
|
21
12
|
* 气泡位置枚举
|
|
22
13
|
*/
|
|
14
|
+
|
|
23
15
|
/**
|
|
24
16
|
* 气泡触发类型,当前支持 click 和 hover 两种类型
|
|
25
17
|
*/
|
|
18
|
+
|
|
26
19
|
/**
|
|
27
20
|
* 气泡内容类型
|
|
28
21
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
|
|
23
|
+
class Popper extends _eventemitter.EventEmitter {
|
|
24
|
+
get buttonRect() {
|
|
25
|
+
return this.button.getBoundingClientRect();
|
|
26
|
+
}
|
|
27
|
+
constructor(button, option) {
|
|
28
|
+
super();
|
|
29
|
+
// 气泡容器 DOM
|
|
30
|
+
(0, _defineProperty2.default)(this, "popperDOM", void 0);
|
|
31
|
+
// 气泡中展示的内容容器 DOM
|
|
32
|
+
(0, _defineProperty2.default)(this, "contentDOM", void 0);
|
|
33
|
+
/**
|
|
34
|
+
* 按钮实体
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
(0, _defineProperty2.default)(this, "button", void 0);
|
|
38
|
+
/**
|
|
39
|
+
* Popper 配置
|
|
40
|
+
* @protected
|
|
41
|
+
*/
|
|
42
|
+
(0, _defineProperty2.default)(this, "option", void 0);
|
|
36
43
|
/**
|
|
37
44
|
* 当前是否展示
|
|
38
45
|
* @protected
|
|
39
46
|
*/
|
|
40
|
-
(0, _defineProperty2.default)(
|
|
47
|
+
(0, _defineProperty2.default)(this, "isShow", false);
|
|
48
|
+
/**
|
|
49
|
+
* 当前气泡展示的内容
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
(0, _defineProperty2.default)(this, "content", void 0);
|
|
41
53
|
/**
|
|
42
54
|
* 关闭气泡的定时器
|
|
43
55
|
* @protected
|
|
44
56
|
*/
|
|
45
|
-
(0, _defineProperty2.default)(
|
|
46
|
-
(0, _defineProperty2.default)(
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
57
|
+
(0, _defineProperty2.default)(this, "timeout", null);
|
|
58
|
+
(0, _defineProperty2.default)(this, "show", () => {
|
|
59
|
+
if (this.isShow || !this.contentDOM.innerHTML) {
|
|
60
|
+
return this;
|
|
49
61
|
}
|
|
50
|
-
|
|
51
|
-
_l7Utils.DOM.removeClass(
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
Popper.conflictPopperList.forEach(
|
|
55
|
-
if (popper !==
|
|
62
|
+
this.resetPopperPosition();
|
|
63
|
+
_l7Utils.DOM.removeClass(this.popperDOM, 'l7-popper-hide');
|
|
64
|
+
this.isShow = true;
|
|
65
|
+
if (this.option.unique) {
|
|
66
|
+
Popper.conflictPopperList.forEach(popper => {
|
|
67
|
+
if (popper !== this && popper.isShow) {
|
|
56
68
|
popper.hide();
|
|
57
69
|
}
|
|
58
70
|
});
|
|
59
71
|
}
|
|
60
|
-
|
|
61
|
-
window.addEventListener('pointerdown',
|
|
62
|
-
return
|
|
72
|
+
this.emit('show');
|
|
73
|
+
window.addEventListener('pointerdown', this.onPopperUnClick);
|
|
74
|
+
return this;
|
|
63
75
|
});
|
|
64
|
-
(0, _defineProperty2.default)(
|
|
65
|
-
if (!
|
|
66
|
-
return
|
|
76
|
+
(0, _defineProperty2.default)(this, "hide", () => {
|
|
77
|
+
if (!this.isShow) {
|
|
78
|
+
return this;
|
|
67
79
|
}
|
|
68
|
-
_l7Utils.DOM.addClass(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
window.removeEventListener('pointerdown',
|
|
72
|
-
return
|
|
80
|
+
_l7Utils.DOM.addClass(this.popperDOM, 'l7-popper-hide');
|
|
81
|
+
this.isShow = false;
|
|
82
|
+
this.emit('hide');
|
|
83
|
+
window.removeEventListener('pointerdown', this.onPopperUnClick);
|
|
84
|
+
return this;
|
|
73
85
|
});
|
|
74
86
|
/**
|
|
75
87
|
* 设置隐藏气泡的定时器
|
|
76
88
|
*/
|
|
77
|
-
(0, _defineProperty2.default)(
|
|
78
|
-
if (
|
|
89
|
+
(0, _defineProperty2.default)(this, "setHideTimeout", () => {
|
|
90
|
+
if (this.timeout) {
|
|
79
91
|
return;
|
|
80
92
|
}
|
|
81
|
-
|
|
82
|
-
if (!
|
|
93
|
+
this.timeout = window.setTimeout(() => {
|
|
94
|
+
if (!this.isShow) {
|
|
83
95
|
return;
|
|
84
96
|
}
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
this.hide();
|
|
98
|
+
this.timeout = null;
|
|
87
99
|
}, 300);
|
|
88
100
|
});
|
|
89
101
|
/**
|
|
90
102
|
* 销毁隐藏气泡的定时器
|
|
91
103
|
*/
|
|
92
|
-
(0, _defineProperty2.default)(
|
|
93
|
-
if (
|
|
94
|
-
window.clearTimeout(
|
|
95
|
-
|
|
104
|
+
(0, _defineProperty2.default)(this, "clearHideTimeout", () => {
|
|
105
|
+
if (this.timeout) {
|
|
106
|
+
window.clearTimeout(this.timeout);
|
|
107
|
+
this.timeout = null;
|
|
96
108
|
}
|
|
97
109
|
});
|
|
98
|
-
(0, _defineProperty2.default)(
|
|
99
|
-
if (
|
|
100
|
-
|
|
110
|
+
(0, _defineProperty2.default)(this, "onBtnClick", () => {
|
|
111
|
+
if (this.isShow) {
|
|
112
|
+
this.hide();
|
|
101
113
|
} else {
|
|
102
|
-
|
|
114
|
+
this.show();
|
|
103
115
|
}
|
|
104
116
|
});
|
|
105
|
-
(0, _defineProperty2.default)(
|
|
117
|
+
(0, _defineProperty2.default)(this, "onPopperUnClick", e => {
|
|
106
118
|
if (!_l7Utils.DOM.findParentElement(e.target, ['.l7-button-control', '.l7-popper-content'])) {
|
|
107
|
-
|
|
119
|
+
this.hide();
|
|
108
120
|
}
|
|
109
121
|
});
|
|
110
|
-
(0, _defineProperty2.default)(
|
|
111
|
-
|
|
122
|
+
(0, _defineProperty2.default)(this, "onBtnMouseLeave", () => {
|
|
123
|
+
this.setHideTimeout();
|
|
112
124
|
});
|
|
113
|
-
(0, _defineProperty2.default)(
|
|
114
|
-
|
|
115
|
-
if (
|
|
125
|
+
(0, _defineProperty2.default)(this, "onBtnMouseMove", () => {
|
|
126
|
+
this.clearHideTimeout();
|
|
127
|
+
if (this.isShow) {
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
|
-
|
|
130
|
+
this.show();
|
|
119
131
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
this.button = button;
|
|
133
|
+
this.option = option;
|
|
134
|
+
this.init();
|
|
123
135
|
if (option.unique) {
|
|
124
|
-
Popper.conflictPopperList.push(
|
|
136
|
+
Popper.conflictPopperList.push(this);
|
|
125
137
|
}
|
|
126
|
-
return _this;
|
|
127
138
|
}
|
|
128
|
-
(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
getPopperDOM() {
|
|
140
|
+
return this.popperDOM;
|
|
141
|
+
}
|
|
142
|
+
getIsShow() {
|
|
143
|
+
return this.isShow;
|
|
144
|
+
}
|
|
145
|
+
getContent() {
|
|
146
|
+
return this.content;
|
|
147
|
+
}
|
|
148
|
+
setContent(content) {
|
|
149
|
+
if (typeof content === 'string') {
|
|
150
|
+
this.contentDOM.innerHTML = content;
|
|
151
|
+
} else if (content instanceof HTMLElement) {
|
|
152
|
+
_l7Utils.DOM.clearChildren(this.contentDOM);
|
|
153
|
+
this.contentDOM.appendChild(content);
|
|
142
154
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
this.content = content;
|
|
156
|
+
}
|
|
157
|
+
init() {
|
|
158
|
+
const {
|
|
159
|
+
trigger
|
|
160
|
+
} = this.option;
|
|
161
|
+
this.popperDOM = this.createPopper();
|
|
162
|
+
if (trigger === 'click') {
|
|
163
|
+
this.button.addEventListener('click', this.onBtnClick);
|
|
164
|
+
} else {
|
|
165
|
+
this.button.addEventListener('mousemove', this.onBtnMouseMove);
|
|
166
|
+
this.button.addEventListener('mouseleave', this.onBtnMouseLeave);
|
|
167
|
+
this.popperDOM.addEventListener('mousemove', this.onBtnMouseMove);
|
|
168
|
+
this.popperDOM.addEventListener('mouseleave', this.onBtnMouseLeave);
|
|
147
169
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
170
|
+
}
|
|
171
|
+
destroy() {
|
|
172
|
+
this.button.removeEventListener('click', this.onBtnClick);
|
|
173
|
+
this.button.removeEventListener('mousemove', this.onBtnMouseMove);
|
|
174
|
+
this.button.removeEventListener('mousemove', this.onBtnMouseLeave);
|
|
175
|
+
this.popperDOM.removeEventListener('mousemove', this.onBtnMouseMove);
|
|
176
|
+
this.popperDOM.removeEventListener('mouseleave', this.onBtnMouseLeave);
|
|
177
|
+
_l7Utils.DOM.remove(this.popperDOM);
|
|
178
|
+
}
|
|
179
|
+
resetPopperPosition() {
|
|
180
|
+
const popperStyleObj = {};
|
|
181
|
+
const {
|
|
182
|
+
container,
|
|
183
|
+
offset = [0, 0],
|
|
184
|
+
placement
|
|
185
|
+
} = this.option;
|
|
186
|
+
const [offsetX, offsetY] = offset;
|
|
187
|
+
const buttonRect = this.button.getBoundingClientRect();
|
|
188
|
+
const containerRect = container.getBoundingClientRect();
|
|
189
|
+
const {
|
|
190
|
+
left,
|
|
191
|
+
right,
|
|
192
|
+
top,
|
|
193
|
+
bottom
|
|
194
|
+
} = _l7Utils.DOM.getDiffRect(buttonRect, containerRect);
|
|
195
|
+
let isTransformX = false;
|
|
196
|
+
let isTransformY = false;
|
|
197
|
+
if (/^(left|right)/.test(placement)) {
|
|
198
|
+
if (placement.includes('left')) {
|
|
199
|
+
popperStyleObj.right = `${buttonRect.width + right}px`;
|
|
200
|
+
} else if (placement.includes('right')) {
|
|
201
|
+
popperStyleObj.left = `${buttonRect.width + left}px`;
|
|
156
202
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
value: function init() {
|
|
162
|
-
var trigger = this.option.trigger;
|
|
163
|
-
this.popperDOM = this.createPopper();
|
|
164
|
-
if (trigger === 'click') {
|
|
165
|
-
this.button.addEventListener('click', this.onBtnClick);
|
|
203
|
+
if (placement.includes('start')) {
|
|
204
|
+
popperStyleObj.top = `${top}px`;
|
|
205
|
+
} else if (placement.includes('end')) {
|
|
206
|
+
popperStyleObj.bottom = `${bottom}px`;
|
|
166
207
|
} else {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.popperDOM.addEventListener('mouseleave', this.onBtnMouseLeave);
|
|
208
|
+
popperStyleObj.top = `${top + buttonRect.height / 2}px`;
|
|
209
|
+
isTransformY = true;
|
|
210
|
+
popperStyleObj.transform = `translate(${offsetX}px, calc(${offsetY}px - 50%))`;
|
|
171
211
|
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.button.removeEventListener('mousemove', this.onBtnMouseMove);
|
|
178
|
-
this.button.removeEventListener('mousemove', this.onBtnMouseLeave);
|
|
179
|
-
this.popperDOM.removeEventListener('mousemove', this.onBtnMouseMove);
|
|
180
|
-
this.popperDOM.removeEventListener('mouseleave', this.onBtnMouseLeave);
|
|
181
|
-
_l7Utils.DOM.remove(this.popperDOM);
|
|
182
|
-
}
|
|
183
|
-
}, {
|
|
184
|
-
key: "resetPopperPosition",
|
|
185
|
-
value: function resetPopperPosition() {
|
|
186
|
-
var popperStyleObj = {};
|
|
187
|
-
var _this$option = this.option,
|
|
188
|
-
container = _this$option.container,
|
|
189
|
-
_this$option$offset = _this$option.offset,
|
|
190
|
-
offset = _this$option$offset === void 0 ? [0, 0] : _this$option$offset,
|
|
191
|
-
placement = _this$option.placement;
|
|
192
|
-
var _offset = (0, _slicedToArray2.default)(offset, 2),
|
|
193
|
-
offsetX = _offset[0],
|
|
194
|
-
offsetY = _offset[1];
|
|
195
|
-
var buttonRect = this.button.getBoundingClientRect();
|
|
196
|
-
var containerRect = container.getBoundingClientRect();
|
|
197
|
-
var _DOM$getDiffRect = _l7Utils.DOM.getDiffRect(buttonRect, containerRect),
|
|
198
|
-
left = _DOM$getDiffRect.left,
|
|
199
|
-
right = _DOM$getDiffRect.right,
|
|
200
|
-
top = _DOM$getDiffRect.top,
|
|
201
|
-
bottom = _DOM$getDiffRect.bottom;
|
|
202
|
-
var isTransformX = false;
|
|
203
|
-
var isTransformY = false;
|
|
204
|
-
if (/^(left|right)/.test(placement)) {
|
|
205
|
-
if (placement.includes('left')) {
|
|
206
|
-
popperStyleObj.right = "".concat(buttonRect.width + right, "px");
|
|
207
|
-
} else if (placement.includes('right')) {
|
|
208
|
-
popperStyleObj.left = "".concat(buttonRect.width + left, "px");
|
|
209
|
-
}
|
|
210
|
-
if (placement.includes('start')) {
|
|
211
|
-
popperStyleObj.top = "".concat(top, "px");
|
|
212
|
-
} else if (placement.includes('end')) {
|
|
213
|
-
popperStyleObj.bottom = "".concat(bottom, "px");
|
|
214
|
-
} else {
|
|
215
|
-
popperStyleObj.top = "".concat(top + buttonRect.height / 2, "px");
|
|
216
|
-
isTransformY = true;
|
|
217
|
-
popperStyleObj.transform = "translate(".concat(offsetX, "px, calc(").concat(offsetY, "px - 50%))");
|
|
218
|
-
}
|
|
219
|
-
} else if (/^(top|bottom)/.test(placement)) {
|
|
220
|
-
if (placement.includes('top')) {
|
|
221
|
-
popperStyleObj.bottom = "".concat(buttonRect.height + bottom, "px");
|
|
222
|
-
} else if (placement.includes('bottom')) {
|
|
223
|
-
popperStyleObj.top = "".concat(buttonRect.height + top, "px");
|
|
224
|
-
}
|
|
225
|
-
if (placement.includes('start')) {
|
|
226
|
-
popperStyleObj.left = "".concat(left, "px");
|
|
227
|
-
} else if (placement.includes('end')) {
|
|
228
|
-
popperStyleObj.right = "".concat(right, "px");
|
|
229
|
-
} else {
|
|
230
|
-
popperStyleObj.left = "".concat(left + buttonRect.width / 2, "px");
|
|
231
|
-
isTransformX = true;
|
|
232
|
-
popperStyleObj.transform = "translate(calc(".concat(offsetX, "px - 50%), ").concat(offsetY, "px)");
|
|
233
|
-
}
|
|
212
|
+
} else if (/^(top|bottom)/.test(placement)) {
|
|
213
|
+
if (placement.includes('top')) {
|
|
214
|
+
popperStyleObj.bottom = `${buttonRect.height + bottom}px`;
|
|
215
|
+
} else if (placement.includes('bottom')) {
|
|
216
|
+
popperStyleObj.top = `${buttonRect.height + top}px`;
|
|
234
217
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
218
|
+
if (placement.includes('start')) {
|
|
219
|
+
popperStyleObj.left = `${left}px`;
|
|
220
|
+
} else if (placement.includes('end')) {
|
|
221
|
+
popperStyleObj.right = `${right}px`;
|
|
222
|
+
} else {
|
|
223
|
+
popperStyleObj.left = `${left + buttonRect.width / 2}px`;
|
|
224
|
+
isTransformX = true;
|
|
225
|
+
popperStyleObj.transform = `translate(calc(${offsetX}px - 50%), ${offsetY}px)`;
|
|
241
226
|
}
|
|
242
|
-
_l7Utils.DOM.addStyle(this.popperDOM, _l7Utils.DOM.css2Style(popperStyleObj));
|
|
243
227
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
228
|
+
popperStyleObj.transform = `translate(calc(${offsetX}px - ${isTransformX ? '50%' : '0%'}), calc(${offsetY}px - ${isTransformY ? '50%' : '0%'})`;
|
|
229
|
+
const posList = placement.split('-');
|
|
230
|
+
if (posList.length) {
|
|
231
|
+
_l7Utils.DOM.addClass(this.popperDOM, posList.map(pos => `l7-popper-${pos}`).join(' '));
|
|
232
|
+
}
|
|
233
|
+
_l7Utils.DOM.addStyle(this.popperDOM, _l7Utils.DOM.css2Style(popperStyleObj));
|
|
234
|
+
}
|
|
235
|
+
createPopper() {
|
|
236
|
+
const {
|
|
237
|
+
container,
|
|
238
|
+
className = '',
|
|
239
|
+
content
|
|
240
|
+
} = this.option;
|
|
241
|
+
const popper = _l7Utils.DOM.create('div', `l7-popper l7-popper-hide ${className}`);
|
|
242
|
+
const popperContent = _l7Utils.DOM.create('div', 'l7-popper-content');
|
|
243
|
+
const popperArrow = _l7Utils.DOM.create('div', 'l7-popper-arrow');
|
|
244
|
+
popper.appendChild(popperContent);
|
|
245
|
+
popper.appendChild(popperArrow);
|
|
246
|
+
container.appendChild(popper);
|
|
247
|
+
this.popperDOM = popper;
|
|
248
|
+
this.contentDOM = popperContent;
|
|
249
|
+
if (content) {
|
|
250
|
+
this.setContent(content);
|
|
264
251
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
252
|
+
return popper;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.Popper = Popper;
|
|
268
256
|
(0, _defineProperty2.default)(Popper, "conflictPopperList", []);
|