@whitesev/pops 1.8.5 → 1.8.7

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 CHANGED
@@ -212,6 +212,9 @@ define((function () { 'use strict';
212
212
  return this.contains(PopsCore.document.body || PopsCore.document.documentElement, arguments[0]);
213
213
  }
214
214
  else {
215
+ if (target == null) {
216
+ return false;
217
+ }
215
218
  if (typeof target[Symbol.iterator] === "function") {
216
219
  // 可遍历的数组
217
220
  let flag = true;
@@ -4099,289 +4102,6 @@ define((function () { 'use strict';
4099
4102
  }
4100
4103
  }
4101
4104
 
4102
- const PopsTooltipConfig = () => {
4103
- return {
4104
- // @ts-ignore
4105
- target: null,
4106
- content: "默认文字",
4107
- position: "top",
4108
- className: "",
4109
- alwaysShow: false,
4110
- triggerShowEventName: "mouseenter touchstart",
4111
- triggerCloseEventName: "mouseleave touchend",
4112
- zIndex: 10000,
4113
- only: false,
4114
- eventOption: {
4115
- passive: false,
4116
- capture: true,
4117
- once: false,
4118
- },
4119
- showBeforeCallBack() { },
4120
- showAfterCallBack() { },
4121
- closeBeforeCallBack() { },
4122
- closeAfterCallBack() { },
4123
- arrowDistance: 12.5,
4124
- otherDistance: 0,
4125
- style: "",
4126
- beforeAppendToPageCallBack() { },
4127
- };
4128
- };
4129
-
4130
- class PopsTooltip {
4131
- constructor(details) {
4132
- const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow();
4133
- PopsHandler.handleInit($shadowRoot, [
4134
- pops.config.cssText.index,
4135
- pops.config.cssText.anim,
4136
- pops.config.cssText.common,
4137
- pops.config.cssText.tooltipCSS,
4138
- ]);
4139
- let config = PopsTooltipConfig();
4140
- config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
4141
- config = popsUtils.assign(config, details);
4142
- if (!(config.target instanceof HTMLElement)) {
4143
- throw "config.target 必须是HTMLElement类型";
4144
- }
4145
- let guid = popsUtils.getRandomGUID();
4146
- const PopsType = "tooltip";
4147
- config = PopsHandler.handleOnly(PopsType, config);
4148
- function getContent() {
4149
- return typeof config.content === "function"
4150
- ? config.content()
4151
- : config.content;
4152
- }
4153
- /**
4154
- * 获取悬浮提示的元素信息
4155
- */
4156
- function getToolTipElementInfo() {
4157
- let _toolTipHTML_ = `<div class="pops-tip"></div>`;
4158
- let _toolTipElement_ = popsUtils.parseTextToDOM(_toolTipHTML_);
4159
- if (typeof config.className === "string" &&
4160
- config.className.trim() !== "") {
4161
- popsDOMUtils.addClassName(_toolTipElement_, config.className);
4162
- }
4163
- _toolTipElement_.setAttribute("data-guid", guid);
4164
- _toolTipElement_.style.zIndex = PopsHandler.handleZIndex(config.zIndex).toString();
4165
- _toolTipElement_.innerHTML = `<div style="text-align: center;">${getContent()}</div>`;
4166
- /* 箭头元素 */
4167
- let _toolTipArrowHTML_ = '<div class="pops-tip-arrow"></div>';
4168
- let _toolTipArrowNode_ = popsUtils.parseTextToDOM(_toolTipArrowHTML_);
4169
- _toolTipElement_.appendChild(_toolTipArrowNode_);
4170
- if (config.style != null) {
4171
- /* 添加自定义style */
4172
- let cssNode = document.createElement("style");
4173
- cssNode.setAttribute("type", "text/css");
4174
- cssNode.innerHTML = config.style;
4175
- _toolTipElement_.appendChild(cssNode);
4176
- }
4177
- return {
4178
- toolTipElement: _toolTipElement_,
4179
- toolTipArrowElement: _toolTipArrowNode_,
4180
- toolTipHTML: _toolTipHTML_,
4181
- toolTipArrowHTML: _toolTipArrowHTML_,
4182
- };
4183
- }
4184
- config.position =
4185
- config.position.toLowerCase();
4186
- let { toolTipElement } = getToolTipElementInfo();
4187
- /**
4188
- * 设置 提示框的位置
4189
- */
4190
- function setToolTipPosition(positionDetails) {
4191
- let positionDetail = positionDetails[config.position.toUpperCase()];
4192
- if (positionDetail) {
4193
- toolTipElement.style.left = positionDetail.left + "px";
4194
- toolTipElement.style.top = positionDetail.top + "px";
4195
- toolTipElement.setAttribute("data-motion", positionDetail.motion);
4196
- toolTipElement
4197
- .querySelector(".pops-tip-arrow")
4198
- ?.setAttribute("data-position", positionDetail.arrow);
4199
- }
4200
- else {
4201
- console.error("不存在该位置", config.position);
4202
- }
4203
- }
4204
- /**
4205
- * 获取 提示框的位置
4206
- * @param targetElement 目标元素
4207
- * @param arrowDistance 箭头和目标元素的距离
4208
- * @param otherDistance 其它位置的偏移
4209
- */
4210
- function getToolTipPosition(targetElement, arrowDistance, otherDistance) {
4211
- let targetElement_width = popsDOMUtils.offset(targetElement).width;
4212
- let targetElement_height = popsDOMUtils.offset(targetElement).height;
4213
- let targetElement_top = popsDOMUtils.offset(targetElement).top;
4214
- // let targetElement_bottom = popsDOMUtils.offset(targetElement).bottom;
4215
- let targetElement_left = popsDOMUtils.offset(targetElement).left;
4216
- // let targetElement_right = popsDOMUtils.offset(targetElement).right;
4217
- let toolTipElement_width = popsDOMUtils.outerWidth(toolTipElement);
4218
- let toolTipElement_height = popsDOMUtils.outerHeight(toolTipElement);
4219
- /* 目标元素的x轴的中间位置 */
4220
- let targetElement_X_center_pos = targetElement_left + targetElement_width / 2 - toolTipElement_width / 2;
4221
- /* 目标元素的Y轴的中间位置 */
4222
- let targetElement_Y_center_pos = targetElement_top +
4223
- targetElement_height / 2 -
4224
- toolTipElement_height / 2;
4225
- return {
4226
- TOP: {
4227
- left: targetElement_X_center_pos - otherDistance,
4228
- top: targetElement_top - toolTipElement_height - arrowDistance,
4229
- arrow: "bottom",
4230
- motion: "fadeInTop",
4231
- },
4232
- RIGHT: {
4233
- left: targetElement_left + targetElement_width + arrowDistance,
4234
- top: targetElement_Y_center_pos + otherDistance,
4235
- arrow: "left",
4236
- motion: "fadeInRight",
4237
- },
4238
- BOTTOM: {
4239
- left: targetElement_X_center_pos - otherDistance,
4240
- top: targetElement_top + targetElement_height + arrowDistance,
4241
- arrow: "top",
4242
- motion: "fadeInBottom",
4243
- },
4244
- LEFT: {
4245
- left: targetElement_left - toolTipElement_width - arrowDistance,
4246
- top: targetElement_Y_center_pos + otherDistance,
4247
- arrow: "right",
4248
- motion: "fadeInLeft",
4249
- },
4250
- };
4251
- }
4252
- /**
4253
- * 显示提示框
4254
- */
4255
- function showToolTipNode() {
4256
- if (typeof config.showBeforeCallBack === "function") {
4257
- let result = config.showBeforeCallBack();
4258
- if (typeof result === "boolean" && !result) {
4259
- return;
4260
- }
4261
- }
4262
- if (!popsUtils.contains($shadowRoot, toolTipElement)) {
4263
- popsDOMUtils.append($shadowRoot, toolTipElement);
4264
- }
4265
- if (!popsUtils.contains($shadowContainer)) {
4266
- if (typeof config.beforeAppendToPageCallBack === "function") {
4267
- config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
4268
- }
4269
- popsDOMUtils.append(document.body, $shadowContainer);
4270
- }
4271
- setToolTipPosition(getToolTipPosition(config.target, config.arrowDistance, config.otherDistance));
4272
- if (typeof config.showAfterCallBack === "function") {
4273
- config.showAfterCallBack(toolTipElement);
4274
- }
4275
- }
4276
- /**
4277
- * 关闭提示框
4278
- */
4279
- function closeToolTipNode() {
4280
- if (typeof config.closeBeforeCallBack === "function") {
4281
- let result = config.closeBeforeCallBack(toolTipElement);
4282
- if (typeof result === "boolean" && !result) {
4283
- return;
4284
- }
4285
- }
4286
- toolTipElement.setAttribute("data-motion", toolTipElement.getAttribute("data-motion").replace("fadeIn", "fadeOut"));
4287
- if (typeof config.closeAfterCallBack === "function") {
4288
- config.closeAfterCallBack(toolTipElement);
4289
- }
4290
- }
4291
- /**
4292
- * 绑定 显示事件
4293
- */
4294
- function onShowEvent() {
4295
- popsDOMUtils.on(config.target, config.triggerShowEventName, showToolTipNode, config.eventOption);
4296
- }
4297
- /**
4298
- * 绑定 关闭事件
4299
- */
4300
- function onCloseEvent() {
4301
- popsDOMUtils.on(config.target, config.triggerCloseEventName, closeToolTipNode, config.eventOption);
4302
- }
4303
- /**
4304
- * 取消绑定 显示事件
4305
- */
4306
- function offShowEvent() {
4307
- popsDOMUtils.off(config.target, config.triggerShowEventName, showToolTipNode, {
4308
- capture: true,
4309
- });
4310
- }
4311
- /**
4312
- * 取消绑定 关闭事件
4313
- */
4314
- function offCloseEvent() {
4315
- popsDOMUtils.off(config.target, config.triggerCloseEventName, closeToolTipNode, {
4316
- capture: true,
4317
- });
4318
- }
4319
- /**
4320
- * 即使存在动画属性,但是当前设置的动画Out结束后移除元素
4321
- */
4322
- function endEvent() {
4323
- if (toolTipElement.getAttribute("data-motion").includes("In")) {
4324
- return;
4325
- }
4326
- toolTipElement.remove();
4327
- }
4328
- if (config.alwaysShow) {
4329
- /* 总是显示 */
4330
- showToolTipNode();
4331
- return {
4332
- guid: guid,
4333
- config: config,
4334
- toolTipNode: toolTipElement,
4335
- show: showToolTipNode,
4336
- close() {
4337
- popsDOMUtils.on(toolTipElement, popsDOMUtils.getAnimationEndNameList(), endEvent, config.eventOption);
4338
- closeToolTipNode();
4339
- },
4340
- off: null,
4341
- on: null,
4342
- };
4343
- }
4344
- else {
4345
- /* 事件触发才显示 */
4346
- /**
4347
- * 当鼠标|手触摸,暂停当前动画
4348
- */
4349
- popsDOMUtils.on(toolTipElement, "mouseenter touchstart", () => {
4350
- toolTipElement.style.animationPlayState = "paused";
4351
- // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
4352
- // toolTipElement.style.animationPlayState = "paused";
4353
- // }
4354
- }, config.eventOption);
4355
- /**
4356
- * 当鼠标|手离开,开始当前动画
4357
- */
4358
- popsDOMUtils.on(toolTipElement, "mouseleave touchend", () => {
4359
- toolTipElement.style.animationPlayState = "running";
4360
- }, config.eventOption);
4361
- popsDOMUtils.on(toolTipElement, popsDOMUtils.getAnimationEndNameList(), endEvent, config.eventOption);
4362
- onShowEvent();
4363
- onCloseEvent();
4364
- return {
4365
- guid: guid,
4366
- $shadowContainer: $shadowContainer,
4367
- $shadowRoot: $shadowRoot,
4368
- config: config,
4369
- toolTipNode: toolTipElement,
4370
- show: showToolTipNode,
4371
- close: closeToolTipNode,
4372
- off() {
4373
- offShowEvent();
4374
- offCloseEvent();
4375
- },
4376
- on() {
4377
- onShowEvent();
4378
- onCloseEvent();
4379
- },
4380
- };
4381
- }
4382
- }
4383
- }
4384
-
4385
4105
  const PopsDrawerConfig = () => {
4386
4106
  return {
4387
4107
  title: {
@@ -6364,21 +6084,20 @@ define((function () { 'use strict';
6364
6084
  };
6365
6085
  let tooltip = pops.tooltip({
6366
6086
  target: rangeInputElement.parentElement,
6367
- content: getToolTipContent(rangeInputElement.value),
6368
- zIndex: 1000000,
6369
- className: "github-tooltip",
6370
- showBeforeCallBack() {
6371
- tooltip.toolTipNode.querySelector("div").innerText =
6372
- getToolTipContent(rangeInputElement.value);
6087
+ content: () => {
6088
+ return getToolTipContent(rangeInputElement.value);
6373
6089
  },
6090
+ zIndex: () => {
6091
+ return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
6092
+ },
6093
+ className: "github-tooltip",
6374
6094
  alwaysShow: false,
6375
6095
  only: false,
6376
6096
  position: "top",
6377
6097
  arrowDistance: 10,
6378
6098
  });
6379
6099
  popsDOMUtils.on(rangeInputElement, ["input", "propertychange"], void 0, function (event) {
6380
- tooltip.toolTipNode.querySelector("div").innerText =
6381
- getToolTipContent(rangeInputElement.value);
6100
+ tooltip.toolTip.changeContent(getToolTipContent(rangeInputElement.value));
6382
6101
  if (typeof formConfig.callback === "function") {
6383
6102
  formConfig.callback(event, event.target.value);
6384
6103
  }
@@ -6474,6 +6193,7 @@ define((function () { 'use strict';
6474
6193
  * 10 => 160px~200px
6475
6194
  */
6476
6195
  stepBlockMap: new Map(),
6196
+ tooltip: null,
6477
6197
  },
6478
6198
  $ele: {
6479
6199
  slider: liElement.querySelector(".pops-slider"),
@@ -6481,7 +6201,6 @@ define((function () { 'use strict';
6481
6201
  bar: liElement.querySelector(".pops-slider__bar"),
6482
6202
  buttonWrapper: liElement.querySelector(".pops-slider__button-wrapper"),
6483
6203
  button: liElement.querySelector(".pops-slider__button"),
6484
- tooltip: null,
6485
6204
  },
6486
6205
  $interval: {
6487
6206
  isCheck: false,
@@ -6861,13 +6580,13 @@ define((function () { 'use strict';
6861
6580
  * 显示悬浮的
6862
6581
  */
6863
6582
  showToolTip() {
6864
- this.$ele.tooltip.show();
6583
+ this.$data.tooltip.toolTip.show();
6865
6584
  },
6866
6585
  /**
6867
6586
  * 关闭悬浮的
6868
6587
  */
6869
6588
  closeToolTip() {
6870
- this.$ele.tooltip.close();
6589
+ this.$data.tooltip.toolTip.close();
6871
6590
  },
6872
6591
  /**
6873
6592
  * 检测在1000ms内,是否停止了拖拽
@@ -6904,11 +6623,12 @@ define((function () { 'use strict';
6904
6623
  return PopsPanelSlider.value;
6905
6624
  }
6906
6625
  }
6907
- let tooltipContent = null;
6908
- this.$ele.tooltip = pops.tooltip({
6626
+ let tooltip = pops.tooltip({
6909
6627
  target: this.$ele.button,
6910
6628
  content: getToolTipContent,
6911
- zIndex: 1000000,
6629
+ zIndex: () => {
6630
+ return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
6631
+ },
6912
6632
  className: "github-tooltip",
6913
6633
  only: false,
6914
6634
  eventOption: {
@@ -6919,7 +6639,7 @@ define((function () { 'use strict';
6919
6639
  this.intervalInit();
6920
6640
  },
6921
6641
  showAfterCallBack: (toolTipNode) => {
6922
- tooltipContent.innerText = getToolTipContent();
6642
+ tooltip.toolTip.changeContent(getToolTipContent());
6923
6643
  },
6924
6644
  closeBeforeCallBack: () => {
6925
6645
  if (this.$data.isMove) {
@@ -6932,8 +6652,7 @@ define((function () { 'use strict';
6932
6652
  position: "top",
6933
6653
  arrowDistance: 10,
6934
6654
  });
6935
- tooltipContent =
6936
- this.$ele.tooltip.toolTipNode.querySelector("div");
6655
+ this.$data.tooltip = tooltip;
6937
6656
  },
6938
6657
  };
6939
6658
  PopsPanelSlider.init();
@@ -9702,11 +9421,460 @@ define((function () { 'use strict';
9702
9421
  }
9703
9422
  }
9704
9423
 
9424
+ const PopsTooltipConfig = () => {
9425
+ return {
9426
+ // @ts-ignore
9427
+ target: null,
9428
+ content: "默认文字",
9429
+ position: "top",
9430
+ className: "",
9431
+ alwaysShow: false,
9432
+ triggerShowEventName: "mouseenter touchstart",
9433
+ triggerCloseEventName: "mouseleave touchend",
9434
+ zIndex: 10000,
9435
+ only: false,
9436
+ eventOption: {
9437
+ passive: false,
9438
+ capture: true,
9439
+ once: false,
9440
+ },
9441
+ showBeforeCallBack() { },
9442
+ showAfterCallBack() { },
9443
+ closeBeforeCallBack() { },
9444
+ closeAfterCallBack() { },
9445
+ arrowDistance: 12.5,
9446
+ otherDistance: 0,
9447
+ style: "",
9448
+ beforeAppendToPageCallBack() { },
9449
+ };
9450
+ };
9451
+
9452
+ class ToolTip {
9453
+ $el = {
9454
+ $shadowContainer: null,
9455
+ $shadowRoot: null,
9456
+ $toolTip: null,
9457
+ $content: null,
9458
+ $arrow: null,
9459
+ };
9460
+ $data = {
9461
+ config: null,
9462
+ guid: null,
9463
+ timeId_show: [],
9464
+ timeId_close: [],
9465
+ };
9466
+ constructor(config, guid, ShadowInfo) {
9467
+ this.$data.config = config;
9468
+ this.$data.guid = guid;
9469
+ this.$el.$shadowContainer = ShadowInfo.$shadowContainer;
9470
+ this.$el.$shadowRoot = ShadowInfo.$shadowRoot;
9471
+ this.init();
9472
+ }
9473
+ init() {
9474
+ let toolTipInfo = this.createToolTip();
9475
+ this.$el.$toolTip = toolTipInfo.$toolTipContainer;
9476
+ this.$el.$content = toolTipInfo.$toolTipContent;
9477
+ this.$el.$arrow = toolTipInfo.$toolTipArrow;
9478
+ this.changeContent();
9479
+ this.changeZIndex();
9480
+ this.changePosition();
9481
+ if (!this.$data.config.alwaysShow) {
9482
+ this.offEvent();
9483
+ this.onEvent();
9484
+ }
9485
+ }
9486
+ /**
9487
+ * 创建提示元素
9488
+ */
9489
+ createToolTip() {
9490
+ let $toolTipContainer = popsDOMUtils.createElement("div", {
9491
+ className: "pops-tip",
9492
+ innerHTML: /*html*/ `
9493
+ <div class="pops-tip-content" style="text-align: center;"></div>
9494
+ <div class="pops-tip-arrow"></div>
9495
+ `,
9496
+ });
9497
+ /** 内容 */
9498
+ let $toolTipContent = $toolTipContainer.querySelector(".pops-tip-content");
9499
+ /** 箭头 */
9500
+ let $toolTipArrow = $toolTipContainer.querySelector(".pops-tip-arrow");
9501
+ // 处理className
9502
+ if (typeof this.$data.config.className === "string" &&
9503
+ this.$data.config.className.trim() !== "") {
9504
+ popsDOMUtils.addClassName($toolTipContainer, this.$data.config.className);
9505
+ }
9506
+ // 添加attr
9507
+ $toolTipContainer.setAttribute("data-guid", this.$data.guid);
9508
+ // 添加z-index
9509
+ $toolTipContainer.style.zIndex = PopsHandler.handleZIndex(this.$data.config.zIndex).toString();
9510
+ if (this.$data.config.style != null) {
9511
+ /* 添加自定义style */
9512
+ let cssNode = popsDOMUtils.createElement("style", {
9513
+ type: "text/css",
9514
+ innerHTML: this.$data.config.style,
9515
+ });
9516
+ $toolTipContainer.appendChild(cssNode);
9517
+ }
9518
+ return {
9519
+ $toolTipContainer: $toolTipContainer,
9520
+ $toolTipArrow: $toolTipArrow,
9521
+ $toolTipContent: $toolTipContent,
9522
+ };
9523
+ }
9524
+ /**
9525
+ * 获取提示的内容
9526
+ */
9527
+ getContent() {
9528
+ return typeof this.$data.config.content === "function"
9529
+ ? this.$data.config.content()
9530
+ : this.$data.config.content;
9531
+ }
9532
+ /**
9533
+ * 修改提示的内容
9534
+ * @param text
9535
+ */
9536
+ changeContent(text) {
9537
+ if (text == null) {
9538
+ text = this.getContent();
9539
+ }
9540
+ this.$el.$content.innerHTML = text;
9541
+ }
9542
+ /**
9543
+ * 获取z-index
9544
+ */
9545
+ getZIndex() {
9546
+ const zIndex = PopsHandler.handleZIndex(this.$data.config.zIndex);
9547
+ return zIndex;
9548
+ }
9549
+ /**
9550
+ * 动态修改z-index
9551
+ */
9552
+ changeZIndex() {
9553
+ const zIndex = this.getZIndex();
9554
+ this.$el.$toolTip.style.setProperty("z-index", zIndex.toString());
9555
+ }
9556
+ /**
9557
+ * 获取 提示框的位置
9558
+ * @param targetElement 目标元素
9559
+ * @param arrowDistance 箭头和目标元素的距离
9560
+ * @param otherDistance 其它位置的偏移
9561
+ */
9562
+ getPosition(targetElement, arrowDistance, otherDistance) {
9563
+ let targetElement_width = popsDOMUtils.offset(targetElement).width;
9564
+ let targetElement_height = popsDOMUtils.offset(targetElement).height;
9565
+ let targetElement_top = popsDOMUtils.offset(targetElement).top;
9566
+ // let targetElement_bottom = popsDOMUtils.offset(targetElement).bottom;
9567
+ let targetElement_left = popsDOMUtils.offset(targetElement).left;
9568
+ // let targetElement_right = popsDOMUtils.offset(targetElement).right;
9569
+ let toolTipElement_width = popsDOMUtils.outerWidth(this.$el.$toolTip);
9570
+ let toolTipElement_height = popsDOMUtils.outerHeight(this.$el.$toolTip);
9571
+ /* 目标元素的x轴的中间位置 */
9572
+ let targetElement_X_center_pos = targetElement_left + targetElement_width / 2 - toolTipElement_width / 2;
9573
+ /* 目标元素的Y轴的中间位置 */
9574
+ let targetElement_Y_center_pos = targetElement_top + targetElement_height / 2 - toolTipElement_height / 2;
9575
+ return {
9576
+ TOP: {
9577
+ left: targetElement_X_center_pos - otherDistance,
9578
+ top: targetElement_top - toolTipElement_height - arrowDistance,
9579
+ arrow: "bottom",
9580
+ motion: "fadeInTop",
9581
+ },
9582
+ RIGHT: {
9583
+ left: targetElement_left + targetElement_width + arrowDistance,
9584
+ top: targetElement_Y_center_pos + otherDistance,
9585
+ arrow: "left",
9586
+ motion: "fadeInRight",
9587
+ },
9588
+ BOTTOM: {
9589
+ left: targetElement_X_center_pos - otherDistance,
9590
+ top: targetElement_top + targetElement_height + arrowDistance,
9591
+ arrow: "top",
9592
+ motion: "fadeInBottom",
9593
+ },
9594
+ LEFT: {
9595
+ left: targetElement_left - toolTipElement_width - arrowDistance,
9596
+ top: targetElement_Y_center_pos + otherDistance,
9597
+ arrow: "right",
9598
+ motion: "fadeInLeft",
9599
+ },
9600
+ };
9601
+ }
9602
+ /**
9603
+ * 动态修改tooltip的位置
9604
+ */
9605
+ changePosition() {
9606
+ let positionInfo = this.getPosition(this.$data.config.target, this.$data.config.arrowDistance, this.$data.config.otherDistance);
9607
+ let positionKey = this.$data.config.position.toUpperCase();
9608
+ let positionDetail = positionInfo[positionKey];
9609
+ if (positionDetail) {
9610
+ this.$el.$toolTip.style.left = positionDetail.left + "px";
9611
+ this.$el.$toolTip.style.top = positionDetail.top + "px";
9612
+ this.$el.$toolTip.setAttribute("data-motion", positionDetail.motion);
9613
+ this.$el.$arrow.setAttribute("data-position", positionDetail.arrow);
9614
+ }
9615
+ else {
9616
+ console.error("不存在该位置", this.$data.config.position);
9617
+ }
9618
+ }
9619
+ /**
9620
+ * 事件绑定
9621
+ */
9622
+ onEvent() {
9623
+ // 监听动画结束事件
9624
+ this.onAnimationFinishEvent();
9625
+ this.onShowEvent();
9626
+ this.onCloseEvent();
9627
+ this.onMouseEnterEvent();
9628
+ this.onMouseLeaveEvent();
9629
+ }
9630
+ /**
9631
+ * 取消事件绑定
9632
+ */
9633
+ offEvent() {
9634
+ this.offAnimationFinishEvent();
9635
+ this.offShowEvent();
9636
+ this.offCloseEvent();
9637
+ this.offMouseEnterEvent();
9638
+ this.offMouseLeaveEvent();
9639
+ }
9640
+ /**
9641
+ * 清除延迟的timeId
9642
+ */
9643
+ clearCloseTimeoutId(timeId) {
9644
+ for (let index = 0; index < this.$data.timeId_close.length; index++) {
9645
+ const currentTimeId = this.$data.timeId_close[index];
9646
+ if (typeof timeId === "number") {
9647
+ // 只清除一个
9648
+ if (timeId == currentTimeId) {
9649
+ clearTimeout(timeId);
9650
+ this.$data.timeId_close.splice(index, 1);
9651
+ break;
9652
+ }
9653
+ }
9654
+ else {
9655
+ clearTimeout(currentTimeId);
9656
+ this.$data.timeId_close.splice(index, 1);
9657
+ index--;
9658
+ }
9659
+ }
9660
+ }
9661
+ /**
9662
+ * 显示提示框
9663
+ */
9664
+ show() {
9665
+ if (typeof this.$data.config.showBeforeCallBack === "function") {
9666
+ let result = this.$data.config.showBeforeCallBack(this.$el.$toolTip);
9667
+ if (typeof result === "boolean" && !result) {
9668
+ return;
9669
+ }
9670
+ }
9671
+ this.clearCloseTimeoutId();
9672
+ if (!popsUtils.contains(this.$el.$shadowRoot, this.$el.$toolTip)) {
9673
+ // 不在容器中,添加
9674
+ this.init();
9675
+ popsDOMUtils.append(this.$el.$shadowRoot, this.$el.$toolTip);
9676
+ }
9677
+ if (!popsUtils.contains(this.$el.$shadowContainer)) {
9678
+ // 页面不存在Shadow,添加
9679
+ if (typeof this.$data.config.beforeAppendToPageCallBack === "function") {
9680
+ this.$data.config.beforeAppendToPageCallBack(this.$el.$shadowRoot, this.$el.$shadowContainer);
9681
+ }
9682
+ popsDOMUtils.append(document.body, this.$el.$shadowContainer);
9683
+ }
9684
+ // 更新内容
9685
+ this.changeContent();
9686
+ // 更新tip的位置
9687
+ this.changePosition();
9688
+ if (typeof this.$data.config.showAfterCallBack === "function") {
9689
+ this.$data.config.showAfterCallBack(this.$el.$toolTip);
9690
+ }
9691
+ }
9692
+ /**
9693
+ * 绑定 显示事件
9694
+ */
9695
+ onShowEvent() {
9696
+ popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerShowEventName, this.show.bind(this), this.$data.config.eventOption);
9697
+ }
9698
+ /**
9699
+ * 取消绑定 显示事件
9700
+ */
9701
+ offShowEvent() {
9702
+ popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerShowEventName, this.show.bind(this), {
9703
+ capture: true,
9704
+ });
9705
+ }
9706
+ /**
9707
+ * 关闭提示框
9708
+ */
9709
+ close(...args) {
9710
+ let event = args[0];
9711
+ // 只判断鼠标事件
9712
+ // 其它的如Touch事件不做处理
9713
+ if (event && event instanceof MouseEvent) {
9714
+ let $target = event.composedPath()[0];
9715
+ // 如果是子元素触发的话,忽视
9716
+ if ($target != this.$data.config.target) {
9717
+ return;
9718
+ }
9719
+ }
9720
+ if (typeof this.$data.config.closeBeforeCallBack === "function") {
9721
+ let result = this.$data.config.closeBeforeCallBack(this.$el.$toolTip);
9722
+ if (typeof result === "boolean" && !result) {
9723
+ return;
9724
+ }
9725
+ }
9726
+ if (this.$data.config.delayCloseTime == null ||
9727
+ (typeof this.$data.config.delayCloseTime === "number" &&
9728
+ this.$data.config.delayCloseTime <= 0)) {
9729
+ this.$data.config.delayCloseTime = 100;
9730
+ }
9731
+ let timeId = setTimeout(() => {
9732
+ // 设置属性触发关闭动画
9733
+ this.clearCloseTimeoutId(timeId);
9734
+ this.$el.$toolTip.setAttribute("data-motion", this.$el.$toolTip
9735
+ .getAttribute("data-motion")
9736
+ .replace("fadeIn", "fadeOut"));
9737
+ }, this.$data.config.delayCloseTime);
9738
+ this.$data.timeId_close.push(timeId);
9739
+ if (typeof this.$data.config.closeAfterCallBack === "function") {
9740
+ this.$data.config.closeAfterCallBack(this.$el.$toolTip);
9741
+ }
9742
+ }
9743
+ /**
9744
+ * 绑定 关闭事件
9745
+ */
9746
+ onCloseEvent() {
9747
+ popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close.bind(this), this.$data.config.eventOption);
9748
+ }
9749
+ /**
9750
+ * 取消绑定 关闭事件
9751
+ */
9752
+ offCloseEvent() {
9753
+ popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close.bind(this), {
9754
+ capture: true,
9755
+ });
9756
+ }
9757
+ /**
9758
+ * 销毁元素
9759
+ */
9760
+ destory() {
9761
+ if (this.$el.$toolTip) {
9762
+ this.$el.$shadowRoot.removeChild(this.$el.$toolTip);
9763
+ }
9764
+ // @ts-ignore
9765
+ this.$el.$toolTip = null;
9766
+ // @ts-ignore
9767
+ this.$el.$arrow = null;
9768
+ // @ts-ignore
9769
+ this.$el.$content = null;
9770
+ }
9771
+ /**
9772
+ * 动画结束事件
9773
+ */
9774
+ animationFinishEvent() {
9775
+ if (!this.$el.$toolTip) {
9776
+ return;
9777
+ }
9778
+ if (this.$el.$toolTip.getAttribute("data-motion").includes("In")) {
9779
+ return;
9780
+ }
9781
+ this.destory();
9782
+ }
9783
+ /**
9784
+ * 监听动画结束
9785
+ */
9786
+ onAnimationFinishEvent() {
9787
+ popsDOMUtils.on(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.animationFinishEvent.bind(this));
9788
+ }
9789
+ /**
9790
+ * 取消监听动画结束
9791
+ */
9792
+ offAnimationFinishEvent() {
9793
+ popsDOMUtils.off(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.animationFinishEvent.bind(this));
9794
+ }
9795
+ /**
9796
+ * 鼠标|触摸进入事件
9797
+ */
9798
+ mouseEnterEvent() {
9799
+ this.$el.$toolTip.style.animationPlayState = "paused";
9800
+ // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
9801
+ // toolTipElement.style.animationPlayState = "paused";
9802
+ // }
9803
+ }
9804
+ /**
9805
+ * 监听鼠标|触摸事件
9806
+ */
9807
+ onMouseEnterEvent() {
9808
+ this.clearCloseTimeoutId();
9809
+ popsDOMUtils.on(this.$el.$toolTip, "mouseenter touchstart", this.mouseEnterEvent.bind(this), this.$data.config.eventOption);
9810
+ }
9811
+ /**
9812
+ * 取消监听鼠标|触摸事件
9813
+ */
9814
+ offMouseEnterEvent() {
9815
+ popsDOMUtils.off(this.$el.$toolTip, "mouseenter touchstart", this.mouseEnterEvent.bind(this), this.$data.config.eventOption);
9816
+ }
9817
+ /**
9818
+ * 鼠标|触摸离开事件
9819
+ */
9820
+ mouseLeaveEvent() {
9821
+ this.$el.$toolTip.style.animationPlayState = "running";
9822
+ }
9823
+ /**
9824
+ * 监听鼠标|触摸离开事件
9825
+ */
9826
+ onMouseLeaveEvent() {
9827
+ popsDOMUtils.on(this.$el.$toolTip, "mouseleave touchend", this.mouseLeaveEvent.bind(this), this.$data.config.eventOption);
9828
+ }
9829
+ /**
9830
+ * 取消监听鼠标|触摸离开事件
9831
+ */
9832
+ offMouseLeaveEvent() {
9833
+ popsDOMUtils.off(this.$el.$toolTip, "mouseleave touchend", this.mouseLeaveEvent.bind(this), this.$data.config.eventOption);
9834
+ }
9835
+ }
9836
+ class PopsTooltip {
9837
+ constructor(details) {
9838
+ const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow();
9839
+ PopsHandler.handleInit($shadowRoot, [
9840
+ pops.config.cssText.index,
9841
+ pops.config.cssText.anim,
9842
+ pops.config.cssText.common,
9843
+ pops.config.cssText.tooltipCSS,
9844
+ ]);
9845
+ let config = PopsTooltipConfig();
9846
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
9847
+ config = popsUtils.assign(config, details);
9848
+ if (!(config.target instanceof HTMLElement)) {
9849
+ throw "config.target 必须是HTMLElement类型";
9850
+ }
9851
+ let guid = popsUtils.getRandomGUID();
9852
+ const PopsType = "tooltip";
9853
+ config = PopsHandler.handleOnly(PopsType, config);
9854
+ let toolTip = new ToolTip(config, guid, {
9855
+ $shadowContainer,
9856
+ $shadowRoot,
9857
+ });
9858
+ if (config.alwaysShow) {
9859
+ /* 总是显示 */
9860
+ /* 直接显示 */
9861
+ toolTip.show();
9862
+ }
9863
+ return {
9864
+ guid: guid,
9865
+ config: config,
9866
+ $shadowContainer: $shadowContainer,
9867
+ $shadowRoot: $shadowRoot,
9868
+ toolTip: toolTip,
9869
+ };
9870
+ }
9871
+ }
9872
+
9705
9873
  class Pops {
9706
9874
  /** 配置 */
9707
9875
  config = {
9708
9876
  /** 版本号 */
9709
- version: "2024.11.2",
9877
+ version: "2024.11.3",
9710
9878
  cssText: {
9711
9879
  /** 主CSS */
9712
9880
  index: indexCSS,
@@ -9806,7 +9974,6 @@ define((function () { 'use strict';
9806
9974
  /** pops.panel中用于处理各个类型的工具 */
9807
9975
  panelHandleContentUtils: PanelHandleContentDetails,
9808
9976
  };
9809
- constructor() { }
9810
9977
  init() {
9811
9978
  if (!this.config.isInit) {
9812
9979
  /* 处理获取当前所有的动画名 */
@@ -9888,7 +10055,8 @@ define((function () { 'use strict';
9888
10055
  * @param details 配置
9889
10056
  */
9890
10057
  tooltip = (details) => {
9891
- return new PopsTooltip(details);
10058
+ let popsTooltip = new PopsTooltip(details);
10059
+ return popsTooltip;
9892
10060
  };
9893
10061
  /**
9894
10062
  * 抽屉