@antv/l7-component 2.21.0 → 2.21.2
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 -393
- package/es/control/zoom.js +80 -112
- package/es/css/index.css +10 -7
- package/es/index.js +667 -1
- package/es/marker-layer.js +274 -326
- package/es/marker.d.ts +0 -2
- package/es/marker.js +394 -453
- 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 -392
- 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 +683 -17
- package/lib/interface.d.ts +18 -0
- package/lib/marker-layer.d.ts +55 -0
- package/lib/marker-layer.js +276 -324
- package/lib/marker.d.ts +58 -0
- package/lib/marker.js +395 -452
- 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
- package/CHANGELOG.md +0 -325
- package/LICENSE.md +0 -21
|
@@ -6,17 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.PopperControl = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
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"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
10
|
var _popper = require("../../utils/popper");
|
|
16
11
|
var _buttonControl = _interopRequireDefault(require("./buttonControl"));
|
|
17
|
-
|
|
18
|
-
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; } }
|
|
19
|
-
var PopperPlacementMap = {
|
|
12
|
+
const PopperPlacementMap = {
|
|
20
13
|
topleft: 'right-start',
|
|
21
14
|
topcenter: 'bottom',
|
|
22
15
|
topright: 'left-start',
|
|
@@ -30,96 +23,77 @@ var PopperPlacementMap = {
|
|
|
30
23
|
rightcenter: 'left',
|
|
31
24
|
rightbottom: 'top-end'
|
|
32
25
|
};
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
function PopperControl() {
|
|
37
|
-
(0, _classCallCheck2.default)(this, PopperControl);
|
|
38
|
-
return _super.apply(this, arguments);
|
|
39
|
-
}
|
|
40
|
-
(0, _createClass2.default)(PopperControl, [{
|
|
41
|
-
key: "getPopper",
|
|
42
|
-
value:
|
|
26
|
+
class PopperControl extends _buttonControl.default {
|
|
27
|
+
constructor(...args) {
|
|
28
|
+
super(...args);
|
|
43
29
|
/**
|
|
44
30
|
* 气泡实例
|
|
45
31
|
* @protected
|
|
46
32
|
*/
|
|
33
|
+
(0, _defineProperty2.default)(this, "popper", void 0);
|
|
34
|
+
}
|
|
35
|
+
getPopper() {
|
|
36
|
+
return this.popper;
|
|
37
|
+
}
|
|
38
|
+
hide() {
|
|
39
|
+
this.popper.hide();
|
|
40
|
+
super.hide();
|
|
41
|
+
}
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
/**
|
|
44
|
+
* 获取默认配置
|
|
45
|
+
* @param option
|
|
46
|
+
*/
|
|
47
|
+
getDefault(option) {
|
|
48
|
+
var _option$position;
|
|
49
|
+
const defaultOption = super.getDefault(option);
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51
|
+
const position = (_option$position = option === null || option === void 0 ? void 0 : option.position) !== null && _option$position !== void 0 ? _option$position : defaultOption.position;
|
|
52
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
|
|
53
|
+
popperPlacement: position instanceof Element ? 'bottom' : PopperPlacementMap[position],
|
|
54
|
+
popperTrigger: 'click'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
onAdd() {
|
|
58
|
+
const button = super.onAdd();
|
|
59
|
+
this.initPopper();
|
|
60
|
+
return button;
|
|
61
|
+
}
|
|
62
|
+
onRemove() {
|
|
63
|
+
this.popper.destroy();
|
|
64
|
+
}
|
|
65
|
+
initPopper() {
|
|
66
|
+
const {
|
|
67
|
+
popperClassName,
|
|
68
|
+
popperPlacement,
|
|
69
|
+
popperTrigger
|
|
70
|
+
} = this.controlOption;
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
72
|
+
const popperContainer = this.mapsService.getMapContainer();
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var button = (0, _get2.default)((0, _getPrototypeOf2.default)(PopperControl.prototype), "onAdd", this).call(this);
|
|
78
|
-
this.initPopper();
|
|
79
|
-
return button;
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "onRemove",
|
|
83
|
-
value: function onRemove() {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
75
|
+
this.popper = new _popper.Popper(this.button, {
|
|
76
|
+
className: popperClassName,
|
|
77
|
+
placement: popperPlacement,
|
|
78
|
+
trigger: popperTrigger,
|
|
79
|
+
container: popperContainer,
|
|
80
|
+
unique: true
|
|
81
|
+
});
|
|
82
|
+
this.popper.on('show', () => {
|
|
83
|
+
this.emit('popperShow', this);
|
|
84
|
+
}).on('hide', () => {
|
|
85
|
+
this.emit('popperHide', this);
|
|
86
|
+
});
|
|
87
|
+
return this.popper;
|
|
88
|
+
}
|
|
89
|
+
setOptions(option) {
|
|
90
|
+
super.setOptions(option);
|
|
91
|
+
if (this.checkUpdateOption(option, ['popperPlacement', 'popperTrigger', 'popperClassName'])) {
|
|
92
|
+
const content = this.popper.getContent();
|
|
84
93
|
this.popper.destroy();
|
|
94
|
+
this.initPopper();
|
|
95
|
+
this.popper.setContent(content);
|
|
85
96
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var _this = this;
|
|
90
|
-
var _this$controlOption = this.controlOption,
|
|
91
|
-
popperClassName = _this$controlOption.popperClassName,
|
|
92
|
-
popperPlacement = _this$controlOption.popperPlacement,
|
|
93
|
-
popperTrigger = _this$controlOption.popperTrigger;
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
95
|
-
var popperContainer = this.mapsService.getMapContainer();
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
98
|
-
this.popper = new _popper.Popper(this.button, {
|
|
99
|
-
className: popperClassName,
|
|
100
|
-
placement: popperPlacement,
|
|
101
|
-
trigger: popperTrigger,
|
|
102
|
-
container: popperContainer,
|
|
103
|
-
unique: true
|
|
104
|
-
});
|
|
105
|
-
this.popper.on('show', function () {
|
|
106
|
-
_this.emit('popperShow', _this);
|
|
107
|
-
}).on('hide', function () {
|
|
108
|
-
_this.emit('popperHide', _this);
|
|
109
|
-
});
|
|
110
|
-
return this.popper;
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "setOptions",
|
|
114
|
-
value: function setOptions(option) {
|
|
115
|
-
(0, _get2.default)((0, _getPrototypeOf2.default)(PopperControl.prototype), "setOptions", this).call(this, option);
|
|
116
|
-
if (this.checkUpdateOption(option, ['popperPlacement', 'popperTrigger', 'popperClassName'])) {
|
|
117
|
-
var content = this.popper.getContent();
|
|
118
|
-
this.popper.destroy();
|
|
119
|
-
this.initPopper();
|
|
120
|
-
this.popper.setContent(content);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}]);
|
|
124
|
-
return PopperControl;
|
|
125
|
-
}(_buttonControl.default);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.default = exports.PopperControl = PopperControl;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IPopperControlOption } from './popperControl';
|
|
2
|
+
import { PopperControl } from './popperControl';
|
|
3
|
+
type BaseOptionItem = {
|
|
4
|
+
value: string;
|
|
5
|
+
text: string;
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
type NormalOptionItem = BaseOptionItem & {
|
|
9
|
+
icon?: HTMLElement;
|
|
10
|
+
};
|
|
11
|
+
type ImageOptionItem = BaseOptionItem & {
|
|
12
|
+
img: string;
|
|
13
|
+
};
|
|
14
|
+
export type ControlOptionItem = ImageOptionItem | NormalOptionItem;
|
|
15
|
+
export interface ISelectControlOption extends IPopperControlOption {
|
|
16
|
+
options: ControlOptionItem[];
|
|
17
|
+
defaultValue?: string | string[];
|
|
18
|
+
}
|
|
19
|
+
export { SelectControl };
|
|
20
|
+
export default class SelectControl<O extends ISelectControlOption = ISelectControlOption> extends PopperControl<O> {
|
|
21
|
+
/**
|
|
22
|
+
* 当前选中的值
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
protected selectValue: string[];
|
|
26
|
+
/**
|
|
27
|
+
* 选项对应的 DOM 列表
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
protected optionDOMList: HTMLElement[];
|
|
31
|
+
setOptions(option: Partial<O>): void;
|
|
32
|
+
onAdd(): HTMLElement;
|
|
33
|
+
getSelectValue(): string | string[];
|
|
34
|
+
setSelectValue(value: string | string[], emitEvent?: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* 是否为多选
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
protected getIsMultiple(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 渲染弹窗内容
|
|
42
|
+
* @param options
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
protected getPopperContent(options: ControlOptionItem[]): HTMLElement;
|
|
46
|
+
protected createNormalOption: (option: NormalOptionItem) => HTMLElement;
|
|
47
|
+
protected createImageOption(option: ImageOptionItem): HTMLElement;
|
|
48
|
+
protected createCheckbox(isSelect: boolean): HTMLElement;
|
|
49
|
+
protected createRadio(isSelect: boolean): HTMLElement;
|
|
50
|
+
protected onItemClick: (item: ControlOptionItem) => void;
|
|
51
|
+
protected isImageOptions(): boolean;
|
|
52
|
+
protected transSelectValue(value: string | string[]): string[];
|
|
53
|
+
}
|
|
@@ -5,220 +5,176 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.SelectControl = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
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 _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
13
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
15
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
16
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
9
|
var _l7Utils = require("@antv/l7-utils");
|
|
18
10
|
var _popperControl = require("./popperControl");
|
|
19
|
-
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); }; }
|
|
20
|
-
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; } }
|
|
21
11
|
var SelectControlConstant = /*#__PURE__*/function (SelectControlConstant) {
|
|
22
12
|
SelectControlConstant["ActiveOptionClassName"] = "l7-select-control-item-active";
|
|
23
13
|
SelectControlConstant["OptionValueAttrKey"] = "data-option-value";
|
|
24
14
|
SelectControlConstant["OptionIndexAttrKey"] = "data-option-index";
|
|
25
15
|
return SelectControlConstant;
|
|
26
16
|
}(SelectControlConstant || {});
|
|
27
|
-
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
function SelectControl() {
|
|
31
|
-
var _this;
|
|
32
|
-
(0, _classCallCheck2.default)(this, SelectControl);
|
|
33
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
34
|
-
args[_key] = arguments[_key];
|
|
35
|
-
}
|
|
36
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
17
|
+
class SelectControl extends _popperControl.PopperControl {
|
|
18
|
+
constructor(...args) {
|
|
19
|
+
super(...args);
|
|
37
20
|
/**
|
|
38
21
|
* 当前选中的值
|
|
39
22
|
* @protected
|
|
40
23
|
*/
|
|
41
|
-
(0, _defineProperty2.default)(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
24
|
+
(0, _defineProperty2.default)(this, "selectValue", []);
|
|
25
|
+
/**
|
|
26
|
+
* 选项对应的 DOM 列表
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
(0, _defineProperty2.default)(this, "optionDOMList", void 0);
|
|
30
|
+
(0, _defineProperty2.default)(this, "createNormalOption", option => {
|
|
31
|
+
const isSelect = this.selectValue.includes(option.value);
|
|
32
|
+
const optionDOM = _l7Utils.DOM.create('div', `l7-select-control-item ${isSelect ? SelectControlConstant.ActiveOptionClassName : ''}`);
|
|
33
|
+
if (this.getIsMultiple()) {
|
|
34
|
+
optionDOM.appendChild(this.createCheckbox(isSelect));
|
|
47
35
|
} else {
|
|
48
|
-
optionDOM.appendChild(
|
|
36
|
+
optionDOM.appendChild(this.createRadio(isSelect));
|
|
49
37
|
}
|
|
50
38
|
if (option.icon) {
|
|
51
39
|
optionDOM.appendChild(option.icon);
|
|
52
40
|
}
|
|
53
|
-
|
|
41
|
+
const textDOM = _l7Utils.DOM.create('span');
|
|
54
42
|
textDOM.innerText = option.text;
|
|
55
43
|
optionDOM.appendChild(textDOM);
|
|
56
44
|
return optionDOM;
|
|
57
45
|
});
|
|
58
|
-
(0, _defineProperty2.default)(
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
return value === item.value;
|
|
62
|
-
});
|
|
46
|
+
(0, _defineProperty2.default)(this, "onItemClick", item => {
|
|
47
|
+
if (this.getIsMultiple()) {
|
|
48
|
+
const targetIndex = this.selectValue.findIndex(value => value === item.value);
|
|
63
49
|
if (targetIndex > -1) {
|
|
64
|
-
|
|
50
|
+
this.selectValue.splice(targetIndex, 1);
|
|
65
51
|
} else {
|
|
66
|
-
|
|
52
|
+
this.selectValue = [...this.selectValue, item.value];
|
|
67
53
|
}
|
|
68
54
|
} else {
|
|
69
|
-
|
|
55
|
+
this.selectValue = [item.value];
|
|
70
56
|
}
|
|
71
|
-
|
|
57
|
+
this.setSelectValue(this.selectValue);
|
|
72
58
|
});
|
|
73
|
-
return _this;
|
|
74
59
|
}
|
|
75
|
-
(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
function setOptions(option) {
|
|
84
|
-
(0, _get2.default)((0, _getPrototypeOf2.default)(SelectControl.prototype), "setOptions", this).call(this, option);
|
|
85
|
-
var options = option.options;
|
|
86
|
-
if (options) {
|
|
87
|
-
this.popper.setContent(this.getPopperContent(options));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, {
|
|
91
|
-
key: "onAdd",
|
|
92
|
-
value: function onAdd() {
|
|
93
|
-
var button = (0, _get2.default)((0, _getPrototypeOf2.default)(SelectControl.prototype), "onAdd", this).call(this);
|
|
94
|
-
var defaultValue = this.controlOption.defaultValue;
|
|
95
|
-
if (defaultValue) {
|
|
96
|
-
this.selectValue = this.transSelectValue(defaultValue);
|
|
97
|
-
}
|
|
98
|
-
this.popper.setContent(this.getPopperContent(this.controlOption.options));
|
|
99
|
-
return button;
|
|
60
|
+
setOptions(option) {
|
|
61
|
+
super.setOptions(option);
|
|
62
|
+
const {
|
|
63
|
+
options
|
|
64
|
+
} = option;
|
|
65
|
+
if (options) {
|
|
66
|
+
this.popper.setContent(this.getPopperContent(options));
|
|
100
67
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
68
|
+
}
|
|
69
|
+
onAdd() {
|
|
70
|
+
const button = super.onAdd();
|
|
71
|
+
const {
|
|
72
|
+
defaultValue
|
|
73
|
+
} = this.controlOption;
|
|
74
|
+
if (defaultValue) {
|
|
75
|
+
this.selectValue = this.transSelectValue(defaultValue);
|
|
105
76
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
77
|
+
this.popper.setContent(this.getPopperContent(this.controlOption.options));
|
|
78
|
+
return button;
|
|
79
|
+
}
|
|
80
|
+
getSelectValue() {
|
|
81
|
+
return this.getIsMultiple() ? this.selectValue : this.selectValue[0];
|
|
82
|
+
}
|
|
83
|
+
setSelectValue(value, emitEvent = true) {
|
|
84
|
+
const finalValue = this.transSelectValue(value);
|
|
85
|
+
this.optionDOMList.forEach(optionDOM => {
|
|
86
|
+
const optionValue = optionDOM.getAttribute(SelectControlConstant.OptionValueAttrKey);
|
|
87
|
+
const checkboxDOM = optionDOM.querySelector('input[type=checkbox]');
|
|
88
|
+
const radioDOM = optionDOM.querySelector('input[type=radio]');
|
|
89
|
+
const isActive = finalValue.includes(optionValue);
|
|
116
90
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
91
|
+
// 设置类名和选中状态的函数
|
|
92
|
+
const setDOMState = (dom, active) => {
|
|
93
|
+
_l7Utils.DOM.toggleClass(optionDOM, SelectControlConstant.ActiveOptionClassName, active);
|
|
94
|
+
if (dom) {
|
|
95
|
+
_l7Utils.DOM.setChecked(dom, active);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
setDOMState(checkboxDOM, isActive);
|
|
99
|
+
setDOMState(radioDOM, isActive);
|
|
100
|
+
});
|
|
101
|
+
this.selectValue = finalValue;
|
|
102
|
+
if (emitEvent) {
|
|
103
|
+
this.emit('selectChange', this.getIsMultiple() ? finalValue : finalValue[0]);
|
|
131
104
|
}
|
|
105
|
+
}
|
|
132
106
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
107
|
+
/**
|
|
108
|
+
* 是否为多选
|
|
109
|
+
* @protected
|
|
110
|
+
*/
|
|
111
|
+
getIsMultiple() {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
142
114
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
var content = _l7Utils.DOM.create('div', isImageOptions ? 'l7-select-control--image' : 'l7-select-control--normal');
|
|
154
|
-
if (this.getIsMultiple()) {
|
|
155
|
-
_l7Utils.DOM.addClass(content, 'l7-select-control--multiple');
|
|
156
|
-
}
|
|
157
|
-
var optionsDOMList = options.map(function (option, optionIndex) {
|
|
158
|
-
var optionDOM = isImageOptions ?
|
|
159
|
-
// @ts-ignore
|
|
160
|
-
_this2.createImageOption(option) : _this2.createNormalOption(option);
|
|
161
|
-
optionDOM.setAttribute(SelectControlConstant.OptionValueAttrKey, option.value);
|
|
162
|
-
optionDOM.setAttribute(SelectControlConstant.OptionIndexAttrKey, window.String(optionIndex));
|
|
163
|
-
optionDOM.addEventListener('click', _this2.onItemClick.bind(_this2, option));
|
|
164
|
-
return optionDOM;
|
|
165
|
-
});
|
|
166
|
-
content.append.apply(content, (0, _toConsumableArray2.default)(optionsDOMList));
|
|
167
|
-
this.optionDOMList = optionsDOMList;
|
|
168
|
-
return content;
|
|
115
|
+
/**
|
|
116
|
+
* 渲染弹窗内容
|
|
117
|
+
* @param options
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
getPopperContent(options) {
|
|
121
|
+
const isImageOptions = this.isImageOptions();
|
|
122
|
+
const content = _l7Utils.DOM.create('div', isImageOptions ? 'l7-select-control--image' : 'l7-select-control--normal');
|
|
123
|
+
if (this.getIsMultiple()) {
|
|
124
|
+
_l7Utils.DOM.addClass(content, 'l7-select-control--multiple');
|
|
169
125
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
_l7Utils.DOM.setUnDraggable(imgDOM);
|
|
178
|
-
optionDOM.appendChild(imgDOM);
|
|
179
|
-
var rowDOM = _l7Utils.DOM.create('div', 'l7-select-control-item-row');
|
|
180
|
-
if (this.getIsMultiple()) {
|
|
181
|
-
optionDOM.appendChild(this.createCheckbox(isSelect));
|
|
182
|
-
}
|
|
183
|
-
var textDOM = _l7Utils.DOM.create('span');
|
|
184
|
-
textDOM.innerText = option.text;
|
|
185
|
-
rowDOM.appendChild(textDOM);
|
|
186
|
-
optionDOM.appendChild(rowDOM);
|
|
126
|
+
const optionsDOMList = options.map((option, optionIndex) => {
|
|
127
|
+
const optionDOM = isImageOptions ?
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
this.createImageOption(option) : this.createNormalOption(option);
|
|
130
|
+
optionDOM.setAttribute(SelectControlConstant.OptionValueAttrKey, option.value);
|
|
131
|
+
optionDOM.setAttribute(SelectControlConstant.OptionIndexAttrKey, window.String(optionIndex));
|
|
132
|
+
optionDOM.addEventListener('click', this.onItemClick.bind(this, option));
|
|
187
133
|
return optionDOM;
|
|
134
|
+
});
|
|
135
|
+
content.append(...optionsDOMList);
|
|
136
|
+
this.optionDOMList = optionsDOMList;
|
|
137
|
+
return content;
|
|
138
|
+
}
|
|
139
|
+
createImageOption(option) {
|
|
140
|
+
const isSelect = this.selectValue.includes(option.value);
|
|
141
|
+
const optionDOM = _l7Utils.DOM.create('div', `l7-select-control-item ${isSelect ? SelectControlConstant.ActiveOptionClassName : ''}`);
|
|
142
|
+
const imgDOM = _l7Utils.DOM.create('img');
|
|
143
|
+
imgDOM.setAttribute('src', option.img);
|
|
144
|
+
_l7Utils.DOM.setUnDraggable(imgDOM);
|
|
145
|
+
optionDOM.appendChild(imgDOM);
|
|
146
|
+
const rowDOM = _l7Utils.DOM.create('div', 'l7-select-control-item-row');
|
|
147
|
+
if (this.getIsMultiple()) {
|
|
148
|
+
optionDOM.appendChild(this.createCheckbox(isSelect));
|
|
188
149
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
key: "createRadio",
|
|
201
|
-
value: function createRadio(isSelect) {
|
|
202
|
-
var radioDOM = _l7Utils.DOM.create('input');
|
|
203
|
-
radioDOM.setAttribute('type', 'radio');
|
|
204
|
-
if (isSelect) {
|
|
205
|
-
_l7Utils.DOM.setChecked(radioDOM, true);
|
|
206
|
-
}
|
|
207
|
-
return radioDOM;
|
|
208
|
-
}
|
|
209
|
-
}, {
|
|
210
|
-
key: "isImageOptions",
|
|
211
|
-
value: function isImageOptions() {
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
return !!this.controlOption.options.find(function (item) {
|
|
214
|
-
return item.img;
|
|
215
|
-
});
|
|
150
|
+
const textDOM = _l7Utils.DOM.create('span');
|
|
151
|
+
textDOM.innerText = option.text;
|
|
152
|
+
rowDOM.appendChild(textDOM);
|
|
153
|
+
optionDOM.appendChild(rowDOM);
|
|
154
|
+
return optionDOM;
|
|
155
|
+
}
|
|
156
|
+
createCheckbox(isSelect) {
|
|
157
|
+
const checkboxDOM = _l7Utils.DOM.create('input');
|
|
158
|
+
checkboxDOM.setAttribute('type', 'checkbox');
|
|
159
|
+
if (isSelect) {
|
|
160
|
+
_l7Utils.DOM.setChecked(checkboxDOM, true);
|
|
216
161
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
162
|
+
return checkboxDOM;
|
|
163
|
+
}
|
|
164
|
+
createRadio(isSelect) {
|
|
165
|
+
const radioDOM = _l7Utils.DOM.create('input');
|
|
166
|
+
radioDOM.setAttribute('type', 'radio');
|
|
167
|
+
if (isSelect) {
|
|
168
|
+
_l7Utils.DOM.setChecked(radioDOM, true);
|
|
221
169
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
170
|
+
return radioDOM;
|
|
171
|
+
}
|
|
172
|
+
isImageOptions() {
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
return !!this.controlOption.options.find(item => item.img);
|
|
175
|
+
}
|
|
176
|
+
transSelectValue(value) {
|
|
177
|
+
return Array.isArray(value) ? value : [value];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.default = exports.SelectControl = SelectControl;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IButtonControlOption } from './baseControl/buttonControl';
|
|
2
|
+
import ButtonControl from './baseControl/buttonControl';
|
|
3
|
+
export interface IExportImageControlOption extends IButtonControlOption {
|
|
4
|
+
imageType: 'png' | 'jpeg';
|
|
5
|
+
onExport: (base64: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export { ExportImage };
|
|
8
|
+
export default class ExportImage extends ButtonControl<IExportImageControlOption> {
|
|
9
|
+
onAdd(): HTMLElement;
|
|
10
|
+
getDefault(option?: Partial<IExportImageControlOption>): IExportImageControlOption;
|
|
11
|
+
getImage(): Promise<string>;
|
|
12
|
+
protected onClick: () => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* 将多张图片合并为一张图片
|
|
15
|
+
* @protected
|
|
16
|
+
* @param base64List
|
|
17
|
+
*/
|
|
18
|
+
protected mergeImage: (...base64List: string[]) => Promise<string>;
|
|
19
|
+
}
|