@antv/l7-component 2.25.7 → 2.25.9

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.
Files changed (151) hide show
  1. package/es/assets/iconfont/iconfont.d.ts +21 -0
  2. package/es/assets/iconfont/iconfont.js +61 -0
  3. package/es/constants/index.d.ts +60 -0
  4. package/es/constants/index.js +60 -0
  5. package/es/control/baseControl/buttonControl.d.ts +60 -0
  6. package/es/control/baseControl/buttonControl.js +142 -0
  7. package/es/control/baseControl/control.d.ts +112 -0
  8. package/es/control/baseControl/control.js +256 -0
  9. package/es/control/baseControl/index.d.ts +4 -0
  10. package/es/control/baseControl/index.js +4 -0
  11. package/es/control/baseControl/popperControl.d.ts +28 -0
  12. package/es/control/baseControl/popperControl.js +92 -0
  13. package/es/control/baseControl/selectControl.d.ts +53 -0
  14. package/es/control/baseControl/selectControl.js +173 -0
  15. package/es/control/exportImage.d.ts +19 -0
  16. package/es/control/exportImage.js +73 -0
  17. package/es/control/fullscreen.d.ts +20 -0
  18. package/es/control/fullscreen.js +88 -0
  19. package/es/control/geoLocate.d.ts +17 -0
  20. package/es/control/geoLocate.js +60 -0
  21. package/es/control/layerSwitch.d.ts +27 -0
  22. package/es/control/layerSwitch.js +155 -0
  23. package/es/control/logo.d.ts +14 -0
  24. package/es/control/logo.js +49 -0
  25. package/es/control/mapTheme.d.ts +11 -0
  26. package/es/control/mapTheme.js +69 -0
  27. package/es/control/mouseLocation.d.ts +16 -0
  28. package/es/control/mouseLocation.js +52 -0
  29. package/es/control/scale.d.ts +35 -0
  30. package/es/control/scale.js +121 -0
  31. package/es/control/swipe.d.ts +66 -0
  32. package/es/control/swipe.js +392 -0
  33. package/es/control/zoom.d.ts +39 -0
  34. package/es/control/zoom.js +100 -0
  35. package/es/css/button.less +77 -0
  36. package/es/css/control.less +82 -0
  37. package/es/css/index.css +653 -0
  38. package/es/css/index.less +13 -0
  39. package/es/css/l7.less +69 -0
  40. package/es/css/layerPopup.less +9 -0
  41. package/es/css/logo.less +21 -0
  42. package/es/css/mouseLocation.less +9 -0
  43. package/es/css/popper.less +74 -0
  44. package/es/css/popup.less +176 -0
  45. package/es/css/scale.less +37 -0
  46. package/es/css/select.less +96 -0
  47. package/es/css/swipe.less +80 -0
  48. package/es/css/variables.less +29 -0
  49. package/es/css/zoom.less +34 -0
  50. package/es/images/layers.png +0 -0
  51. package/es/images/layers.svg +1 -0
  52. package/es/images/logo.png +0 -0
  53. package/es/images/quanping.svg +12 -0
  54. package/es/index.d.ts +19 -0
  55. package/es/index.js +717 -0
  56. package/es/interface.d.ts +29 -0
  57. package/es/interface.js +1 -0
  58. package/es/marker-layer.d.ts +46 -0
  59. package/es/marker-layer.js +509 -0
  60. package/es/marker.d.ts +66 -0
  61. package/es/marker.js +495 -0
  62. package/es/popup/layerPopup.d.ts +105 -0
  63. package/es/popup/layerPopup.js +341 -0
  64. package/es/popup/popup.d.ts +147 -0
  65. package/es/popup/popup.js +587 -0
  66. package/es/utils/anchor.d.ts +22 -0
  67. package/es/utils/anchor.js +31 -0
  68. package/es/utils/eventManager.d.ts +42 -0
  69. package/es/utils/eventManager.js +84 -0
  70. package/es/utils/icon.d.ts +1 -0
  71. package/es/utils/icon.js +12 -0
  72. package/es/utils/popper.d.ts +76 -0
  73. package/es/utils/popper.js +257 -0
  74. package/es/utils/screenfull.d.ts +2 -0
  75. package/es/utils/screenfull.js +106 -0
  76. package/lib/assets/iconfont/iconfont.d.ts +21 -0
  77. package/lib/assets/iconfont/iconfont.js +68 -0
  78. package/lib/constants/index.d.ts +60 -0
  79. package/lib/constants/index.js +66 -0
  80. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  81. package/lib/control/baseControl/buttonControl.js +149 -0
  82. package/lib/control/baseControl/control.d.ts +112 -0
  83. package/lib/control/baseControl/control.js +269 -0
  84. package/lib/control/baseControl/index.d.ts +4 -0
  85. package/lib/control/baseControl/index.js +39 -0
  86. package/lib/control/baseControl/popperControl.d.ts +28 -0
  87. package/lib/control/baseControl/popperControl.js +99 -0
  88. package/lib/control/baseControl/selectControl.d.ts +53 -0
  89. package/lib/control/baseControl/selectControl.js +180 -0
  90. package/lib/control/exportImage.d.ts +19 -0
  91. package/lib/control/exportImage.js +80 -0
  92. package/lib/control/fullscreen.d.ts +20 -0
  93. package/lib/control/fullscreen.js +95 -0
  94. package/lib/control/geoLocate.d.ts +17 -0
  95. package/lib/control/geoLocate.js +67 -0
  96. package/lib/control/layerSwitch.d.ts +27 -0
  97. package/lib/control/layerSwitch.js +162 -0
  98. package/lib/control/logo.d.ts +14 -0
  99. package/lib/control/logo.js +55 -0
  100. package/lib/control/mapTheme.d.ts +11 -0
  101. package/lib/control/mapTheme.js +76 -0
  102. package/lib/control/mouseLocation.d.ts +16 -0
  103. package/lib/control/mouseLocation.js +59 -0
  104. package/lib/control/scale.d.ts +35 -0
  105. package/lib/control/scale.js +128 -0
  106. package/lib/control/swipe.d.ts +66 -0
  107. package/lib/control/swipe.js +399 -0
  108. package/lib/control/zoom.d.ts +39 -0
  109. package/lib/control/zoom.js +107 -0
  110. package/lib/css/button.less +77 -0
  111. package/lib/css/control.less +82 -0
  112. package/lib/css/index.css +653 -0
  113. package/lib/css/index.less +13 -0
  114. package/lib/css/l7.less +69 -0
  115. package/lib/css/layerPopup.less +9 -0
  116. package/lib/css/logo.less +21 -0
  117. package/lib/css/mouseLocation.less +9 -0
  118. package/lib/css/popper.less +74 -0
  119. package/lib/css/popup.less +176 -0
  120. package/lib/css/scale.less +37 -0
  121. package/lib/css/select.less +96 -0
  122. package/lib/css/swipe.less +80 -0
  123. package/lib/css/variables.less +29 -0
  124. package/lib/css/zoom.less +34 -0
  125. package/lib/images/layers.png +0 -0
  126. package/lib/images/layers.svg +1 -0
  127. package/lib/images/logo.png +0 -0
  128. package/lib/images/quanping.svg +12 -0
  129. package/lib/index.d.ts +19 -0
  130. package/lib/index.js +844 -0
  131. package/lib/interface.d.ts +29 -0
  132. package/lib/interface.js +5 -0
  133. package/lib/marker-layer.d.ts +46 -0
  134. package/lib/marker-layer.js +518 -0
  135. package/lib/marker.d.ts +66 -0
  136. package/lib/marker.js +502 -0
  137. package/lib/popup/layerPopup.d.ts +105 -0
  138. package/lib/popup/layerPopup.js +348 -0
  139. package/lib/popup/popup.d.ts +147 -0
  140. package/lib/popup/popup.js +594 -0
  141. package/lib/utils/anchor.d.ts +22 -0
  142. package/lib/utils/anchor.js +38 -0
  143. package/lib/utils/eventManager.d.ts +42 -0
  144. package/lib/utils/eventManager.js +92 -0
  145. package/lib/utils/icon.d.ts +1 -0
  146. package/lib/utils/icon.js +19 -0
  147. package/lib/utils/popper.d.ts +76 -0
  148. package/lib/utils/popper.js +264 -0
  149. package/lib/utils/screenfull.d.ts +2 -0
  150. package/lib/utils/screenfull.js +112 -0
  151. package/package.json +5 -5
@@ -0,0 +1,256 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import { PositionType } from '@antv/l7-core';
4
+ import { DOM } from '@antv/l7-utils';
5
+ import EventEmitter from 'eventemitter3';
6
+ export { PositionType } from '@antv/l7-core';
7
+ export { Control };
8
+ export default class Control extends EventEmitter {
9
+ constructor(option) {
10
+ super();
11
+ /**
12
+ * 当前控件实例配置
13
+ */
14
+ _defineProperty(this, "controlOption", void 0);
15
+ /**
16
+ * 控件的 DOM 容器
17
+ * @protected
18
+ */
19
+ _defineProperty(this, "container", void 0);
20
+ /**
21
+ * 当前控件是否显示
22
+ * @protected
23
+ */
24
+ _defineProperty(this, "isShow", void 0);
25
+ _defineProperty(this, "sceneContainer", void 0);
26
+ _defineProperty(this, "scene", void 0);
27
+ _defineProperty(this, "mapsService", void 0);
28
+ _defineProperty(this, "renderService", void 0);
29
+ _defineProperty(this, "layerService", void 0);
30
+ _defineProperty(this, "controlService", void 0);
31
+ _defineProperty(this, "configService", void 0);
32
+ Control.controlCount++;
33
+ this.controlOption = _objectSpread(_objectSpread({}, this.getDefault(option)), option || {});
34
+ }
35
+ getOptions() {
36
+ return this.controlOption;
37
+ }
38
+
39
+ /**
40
+ * 更新配置的方法,子类如果有自己的配置,也需要重写该方法
41
+ * @param newOptions
42
+ */
43
+ setOptions(newOptions) {
44
+ const defaultOptions = this.getDefault(newOptions);
45
+ Object.entries(newOptions).forEach(([key, value]) => {
46
+ if (value === undefined) {
47
+ newOptions[key] = defaultOptions[key];
48
+ }
49
+ });
50
+ if ('position' in newOptions) {
51
+ this.setPosition(newOptions.position);
52
+ }
53
+ if ('className' in newOptions) {
54
+ this.setClassName(newOptions.className);
55
+ }
56
+ if ('style' in newOptions) {
57
+ this.setStyle(newOptions.style);
58
+ }
59
+ this.controlOption = _objectSpread(_objectSpread({}, this.controlOption), newOptions);
60
+ }
61
+
62
+ /**
63
+ * 当 Control 被添加至 Scene 中,被 controlService 调用的方法
64
+ * @param sceneContainer
65
+ */
66
+ addTo(sceneContainer) {
67
+ // 初始化各个 Service 实例
68
+ this.mapsService = sceneContainer.mapService;
69
+ this.renderService = sceneContainer.rendererService;
70
+ this.layerService = sceneContainer.layerService;
71
+ this.controlService = sceneContainer.controlService;
72
+ this.configService = sceneContainer.globalConfigService;
73
+ this.scene = sceneContainer.sceneService;
74
+ this.sceneContainer = sceneContainer;
75
+ this.isShow = true;
76
+
77
+ // 初始化 container
78
+ this.container = this.onAdd();
79
+ DOM.addClass(this.container, 'l7-control');
80
+ const {
81
+ className,
82
+ style
83
+ } = this.controlOption;
84
+ if (className) {
85
+ this.setClassName(className);
86
+ }
87
+ if (style) {
88
+ this.setStyle(style);
89
+ }
90
+ // 将 container 插入容器中
91
+ this.insertContainer();
92
+ this.emit('add', this);
93
+ return this;
94
+ }
95
+
96
+ /**
97
+ * 将控件移除时触发
98
+ */
99
+ remove() {
100
+ if (!this.mapsService) {
101
+ return this;
102
+ }
103
+ DOM.remove(this.container);
104
+ this.onRemove();
105
+ this.emit('remove', this);
106
+ }
107
+
108
+ /**
109
+ * Control 被添加的时候被调用,返回 Control 对应的 DOM 容器
110
+ */
111
+ onAdd() {
112
+ return DOM.create('div');
113
+ }
114
+
115
+ /**
116
+ * Control 被移除时调用
117
+ */
118
+ // tslint:disable-next-line:no-empty
119
+ onRemove() {}
120
+
121
+ /**
122
+ * 显示控件时触发
123
+ */
124
+ show() {
125
+ const container = this.container;
126
+ DOM.removeClass(container, 'l7-control--hide');
127
+ this.isShow = true;
128
+ this.emit('show', this);
129
+ }
130
+
131
+ /**
132
+ * 隐藏控件时触发
133
+ */
134
+ hide() {
135
+ const container = this.container;
136
+ DOM.addClass(container, 'l7-control--hide');
137
+ this.isShow = false;
138
+ this.emit('hide', this);
139
+ }
140
+
141
+ /**
142
+ * 获取默认构造器参数
143
+ */
144
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
145
+ getDefault(option) {
146
+ // tslint:disable-next-line:no-object-literal-type-assertion
147
+ return {
148
+ position: PositionType.TOPRIGHT,
149
+ name: `${Control.controlCount}`
150
+ };
151
+ }
152
+
153
+ /**
154
+ * 获取当前控件对应的 DOM 容器
155
+ */
156
+ getContainer() {
157
+ return this.container;
158
+ }
159
+
160
+ /**
161
+ * 获取当前 Control 是否展示
162
+ */
163
+ getIsShow() {
164
+ return this.isShow;
165
+ }
166
+ _refocusOnMap(e) {
167
+ // if map exists and event is not a keyboard event
168
+ if (this.mapsService && e && e.screenX > 0 && e.screenY > 0) {
169
+ const container = this.mapsService.getContainer();
170
+ if (container !== null) {
171
+ container.focus();
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ * 设置当前控件位置
178
+ * @param position
179
+ */
180
+ setPosition(position = PositionType.TOPLEFT) {
181
+ // 考虑组件的自动布局,需要销毁重建
182
+ const controlService = this.controlService;
183
+ if (controlService) {
184
+ controlService.removeControl(this);
185
+ }
186
+ this.controlOption.position = position;
187
+ if (controlService) {
188
+ controlService.addControl(this, this.sceneContainer);
189
+ }
190
+ return this;
191
+ }
192
+
193
+ /**
194
+ * 设置容器 container 的样式相关位置,包含 className
195
+ * @param className
196
+ */
197
+ setClassName(className) {
198
+ const container = this.container;
199
+ const {
200
+ className: oldClassName
201
+ } = this.controlOption;
202
+ if (oldClassName) {
203
+ DOM.removeClass(container, oldClassName);
204
+ }
205
+ if (className) {
206
+ DOM.addClass(container, className);
207
+ }
208
+ }
209
+
210
+ /**
211
+ * 设置容器 container 的样式相关位置,包含 style
212
+ * @param style
213
+ */
214
+ setStyle(style) {
215
+ const container = this.container;
216
+ if (style) {
217
+ container.setAttribute('style', style);
218
+ } else {
219
+ container.removeAttribute('style');
220
+ }
221
+ }
222
+
223
+ /**
224
+ * 将控件 DOM 插入到对应 position 的容器中
225
+ * @protected
226
+ */
227
+ insertContainer() {
228
+ const position = this.controlOption.position;
229
+ const container = this.container;
230
+ if (position instanceof Element) {
231
+ position.appendChild(container);
232
+ } else {
233
+ const corner = this.controlService.controlCorners[position];
234
+ if (['bottomleft', 'bottomright', 'righttop', 'rightbottom'].includes(position)) {
235
+ corner.insertBefore(container, corner.firstChild);
236
+ } else {
237
+ corner.appendChild(container);
238
+ }
239
+ }
240
+ }
241
+
242
+ /**
243
+ * 检查当前传入 option 是否包含 keys 字段
244
+ * @param option
245
+ * @param keys
246
+ * @protected
247
+ */
248
+ checkUpdateOption(option, keys) {
249
+ return keys.some(key => key in option);
250
+ }
251
+ }
252
+ /**
253
+ * 当前类型控件实例个数
254
+ * @protected
255
+ */
256
+ _defineProperty(Control, "controlCount", 0);
@@ -0,0 +1,4 @@
1
+ export { ButtonControl, type IButtonControlOption } from './buttonControl';
2
+ export { Control, PositionType, type IControlOption } from './control';
3
+ export { PopperControl, type IPopperControlOption } from './popperControl';
4
+ export { SelectControl, type ControlOptionItem, type ISelectControlOption } from './selectControl';
@@ -0,0 +1,4 @@
1
+ export { ButtonControl } from "./buttonControl";
2
+ export { Control, PositionType } from "./control";
3
+ export { PopperControl } from "./popperControl";
4
+ export { SelectControl } from "./selectControl";
@@ -0,0 +1,28 @@
1
+ import type { PopperPlacement, PopperTrigger } from '../../utils/popper';
2
+ import { Popper } from '../../utils/popper';
3
+ import type { IButtonControlOption } from './buttonControl';
4
+ import ButtonControl from './buttonControl';
5
+ export { PopperControl };
6
+ export interface IPopperControlOption extends IButtonControlOption {
7
+ popperPlacement: PopperPlacement;
8
+ popperClassName?: string;
9
+ popperTrigger: PopperTrigger;
10
+ }
11
+ export default class PopperControl<O extends IPopperControlOption = IPopperControlOption> extends ButtonControl<O> {
12
+ /**
13
+ * 气泡实例
14
+ * @protected
15
+ */
16
+ protected popper: Popper;
17
+ getPopper(): Popper;
18
+ hide(): void;
19
+ /**
20
+ * 获取默认配置
21
+ * @param option
22
+ */
23
+ getDefault(option?: Partial<O>): O;
24
+ onAdd(): HTMLElement;
25
+ onRemove(): void;
26
+ initPopper(): Popper;
27
+ setOptions(option: Partial<O>): void;
28
+ }
@@ -0,0 +1,92 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import { Popper } from "../../utils/popper";
4
+ import ButtonControl from "./buttonControl";
5
+ export { PopperControl };
6
+ const PopperPlacementMap = {
7
+ topleft: 'right-start',
8
+ topcenter: 'bottom',
9
+ topright: 'left-start',
10
+ bottomleft: 'right-end',
11
+ bottomcenter: 'top',
12
+ bottomright: 'left-end',
13
+ lefttop: 'bottom-start',
14
+ leftcenter: 'right',
15
+ leftbottom: 'top-start',
16
+ righttop: 'bottom-end',
17
+ rightcenter: 'left',
18
+ rightbottom: 'top-end'
19
+ };
20
+ export default class PopperControl extends ButtonControl {
21
+ constructor(...args) {
22
+ super(...args);
23
+ /**
24
+ * 气泡实例
25
+ * @protected
26
+ */
27
+ _defineProperty(this, "popper", void 0);
28
+ }
29
+ getPopper() {
30
+ return this.popper;
31
+ }
32
+ hide() {
33
+ this.popper.hide();
34
+ super.hide();
35
+ }
36
+
37
+ /**
38
+ * 获取默认配置
39
+ * @param option
40
+ */
41
+ getDefault(option) {
42
+ var _option$position;
43
+ const defaultOption = super.getDefault(option);
44
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45
+ const position = (_option$position = option === null || option === void 0 ? void 0 : option.position) !== null && _option$position !== void 0 ? _option$position : defaultOption.position;
46
+ return _objectSpread(_objectSpread({}, super.getDefault(option)), {}, {
47
+ popperPlacement: position instanceof Element ? 'bottom' : PopperPlacementMap[position],
48
+ popperTrigger: 'click'
49
+ });
50
+ }
51
+ onAdd() {
52
+ const button = super.onAdd();
53
+ this.initPopper();
54
+ return button;
55
+ }
56
+ onRemove() {
57
+ this.popper.destroy();
58
+ }
59
+ initPopper() {
60
+ const {
61
+ popperClassName,
62
+ popperPlacement,
63
+ popperTrigger
64
+ } = this.controlOption;
65
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
66
+ const popperContainer = this.mapsService.getMapContainer();
67
+
68
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
+ this.popper = new Popper(this.button, {
70
+ className: popperClassName,
71
+ placement: popperPlacement,
72
+ trigger: popperTrigger,
73
+ container: popperContainer,
74
+ unique: true
75
+ });
76
+ this.popper.on('show', () => {
77
+ this.emit('popperShow', this);
78
+ }).on('hide', () => {
79
+ this.emit('popperHide', this);
80
+ });
81
+ return this.popper;
82
+ }
83
+ setOptions(option) {
84
+ super.setOptions(option);
85
+ if (this.checkUpdateOption(option, ['popperPlacement', 'popperTrigger', 'popperClassName'])) {
86
+ const content = this.popper.getContent();
87
+ this.popper.destroy();
88
+ this.initPopper();
89
+ this.popper.setContent(content);
90
+ }
91
+ }
92
+ }
@@ -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
+ }
@@ -0,0 +1,173 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { DOM } from '@antv/l7-utils';
3
+ import { PopperControl } from "./popperControl";
4
+ export { SelectControl };
5
+ var SelectControlConstant = /*#__PURE__*/function (SelectControlConstant) {
6
+ SelectControlConstant["ActiveOptionClassName"] = "l7-select-control-item-active";
7
+ SelectControlConstant["OptionValueAttrKey"] = "data-option-value";
8
+ SelectControlConstant["OptionIndexAttrKey"] = "data-option-index";
9
+ return SelectControlConstant;
10
+ }(SelectControlConstant || {});
11
+ export default class SelectControl extends PopperControl {
12
+ constructor(...args) {
13
+ super(...args);
14
+ /**
15
+ * 当前选中的值
16
+ * @protected
17
+ */
18
+ _defineProperty(this, "selectValue", []);
19
+ /**
20
+ * 选项对应的 DOM 列表
21
+ * @protected
22
+ */
23
+ _defineProperty(this, "optionDOMList", void 0);
24
+ _defineProperty(this, "createNormalOption", option => {
25
+ const isSelect = this.selectValue.includes(option.value);
26
+ const optionDOM = DOM.create('div', `l7-select-control-item ${isSelect ? SelectControlConstant.ActiveOptionClassName : ''}`);
27
+ if (this.getIsMultiple()) {
28
+ optionDOM.appendChild(this.createCheckbox(isSelect));
29
+ } else {
30
+ optionDOM.appendChild(this.createRadio(isSelect));
31
+ }
32
+ if (option.icon) {
33
+ optionDOM.appendChild(option.icon);
34
+ }
35
+ const textDOM = DOM.create('span');
36
+ textDOM.innerText = option.text;
37
+ optionDOM.appendChild(textDOM);
38
+ return optionDOM;
39
+ });
40
+ _defineProperty(this, "onItemClick", item => {
41
+ if (this.getIsMultiple()) {
42
+ const targetIndex = this.selectValue.findIndex(value => value === item.value);
43
+ if (targetIndex > -1) {
44
+ this.selectValue.splice(targetIndex, 1);
45
+ } else {
46
+ this.selectValue = [...this.selectValue, item.value];
47
+ }
48
+ } else {
49
+ this.selectValue = [item.value];
50
+ }
51
+ this.setSelectValue(this.selectValue);
52
+ });
53
+ }
54
+ setOptions(option) {
55
+ super.setOptions(option);
56
+ const {
57
+ options
58
+ } = option;
59
+ if (options) {
60
+ this.popper.setContent(this.getPopperContent(options));
61
+ }
62
+ }
63
+ onAdd() {
64
+ const button = super.onAdd();
65
+ const {
66
+ defaultValue
67
+ } = this.controlOption;
68
+ if (defaultValue) {
69
+ this.selectValue = this.transSelectValue(defaultValue);
70
+ }
71
+ this.popper.setContent(this.getPopperContent(this.controlOption.options));
72
+ return button;
73
+ }
74
+ getSelectValue() {
75
+ return this.getIsMultiple() ? this.selectValue : this.selectValue[0];
76
+ }
77
+ setSelectValue(value, emitEvent = true) {
78
+ const finalValue = this.transSelectValue(value);
79
+ this.optionDOMList.forEach(optionDOM => {
80
+ const optionValue = optionDOM.getAttribute(SelectControlConstant.OptionValueAttrKey);
81
+ const checkboxDOM = optionDOM.querySelector('input[type=checkbox]');
82
+ const radioDOM = optionDOM.querySelector('input[type=radio]');
83
+ const isActive = finalValue.includes(optionValue);
84
+
85
+ // 设置类名和选中状态的函数
86
+ const setDOMState = (dom, active) => {
87
+ DOM.toggleClass(optionDOM, SelectControlConstant.ActiveOptionClassName, active);
88
+ if (dom) {
89
+ DOM.setChecked(dom, active);
90
+ }
91
+ };
92
+ setDOMState(checkboxDOM, isActive);
93
+ setDOMState(radioDOM, isActive);
94
+ });
95
+ this.selectValue = finalValue;
96
+ if (emitEvent) {
97
+ this.emit('selectChange', this.getIsMultiple() ? finalValue : finalValue[0]);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * 是否为多选
103
+ * @protected
104
+ */
105
+ getIsMultiple() {
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * 渲染弹窗内容
111
+ * @param options
112
+ * @returns
113
+ */
114
+ getPopperContent(options) {
115
+ const isImageOptions = this.isImageOptions();
116
+ const content = DOM.create('div', isImageOptions ? 'l7-select-control--image' : 'l7-select-control--normal');
117
+ if (this.getIsMultiple()) {
118
+ DOM.addClass(content, 'l7-select-control--multiple');
119
+ }
120
+ const optionsDOMList = options.map((option, optionIndex) => {
121
+ const optionDOM = isImageOptions ?
122
+ // @ts-ignore
123
+ this.createImageOption(option) : this.createNormalOption(option);
124
+ optionDOM.setAttribute(SelectControlConstant.OptionValueAttrKey, option.value);
125
+ optionDOM.setAttribute(SelectControlConstant.OptionIndexAttrKey, window.String(optionIndex));
126
+ optionDOM.addEventListener('click', this.onItemClick.bind(this, option));
127
+ return optionDOM;
128
+ });
129
+ content.append(...optionsDOMList);
130
+ this.optionDOMList = optionsDOMList;
131
+ return content;
132
+ }
133
+ createImageOption(option) {
134
+ const isSelect = this.selectValue.includes(option.value);
135
+ const optionDOM = DOM.create('div', `l7-select-control-item ${isSelect ? SelectControlConstant.ActiveOptionClassName : ''}`);
136
+ const imgDOM = DOM.create('img');
137
+ imgDOM.setAttribute('src', option.img);
138
+ DOM.setUnDraggable(imgDOM);
139
+ optionDOM.appendChild(imgDOM);
140
+ const rowDOM = DOM.create('div', 'l7-select-control-item-row');
141
+ if (this.getIsMultiple()) {
142
+ optionDOM.appendChild(this.createCheckbox(isSelect));
143
+ }
144
+ const textDOM = DOM.create('span');
145
+ textDOM.innerText = option.text;
146
+ rowDOM.appendChild(textDOM);
147
+ optionDOM.appendChild(rowDOM);
148
+ return optionDOM;
149
+ }
150
+ createCheckbox(isSelect) {
151
+ const checkboxDOM = DOM.create('input');
152
+ checkboxDOM.setAttribute('type', 'checkbox');
153
+ if (isSelect) {
154
+ DOM.setChecked(checkboxDOM, true);
155
+ }
156
+ return checkboxDOM;
157
+ }
158
+ createRadio(isSelect) {
159
+ const radioDOM = DOM.create('input');
160
+ radioDOM.setAttribute('type', 'radio');
161
+ if (isSelect) {
162
+ DOM.setChecked(radioDOM, true);
163
+ }
164
+ return radioDOM;
165
+ }
166
+ isImageOptions() {
167
+ // @ts-ignore
168
+ return !!this.controlOption.options.find(item => item.img);
169
+ }
170
+ transSelectValue(value) {
171
+ return Array.isArray(value) ? value : [value];
172
+ }
173
+ }
@@ -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
+ }