@whitesev/pops 1.9.5 → 1.9.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.umd.js CHANGED
@@ -5546,6 +5546,7 @@
5546
5546
  disable() {
5547
5547
  return false;
5548
5548
  },
5549
+ forms: [],
5549
5550
  },
5550
5551
  {
5551
5552
  value: "text",
@@ -5553,6 +5554,7 @@
5553
5554
  disable() {
5554
5555
  return false;
5555
5556
  },
5557
+ forms: [],
5556
5558
  },
5557
5559
  {
5558
5560
  value: "html",
@@ -5560,6 +5562,7 @@
5560
5562
  disable() {
5561
5563
  return false;
5562
5564
  },
5565
+ forms: [],
5563
5566
  },
5564
5567
  ],
5565
5568
  },
@@ -7063,6 +7066,7 @@
7063
7066
  * @param formConfig
7064
7067
  */
7065
7068
  createSectionContainerItem_select(formConfig) {
7069
+ const that = this;
7066
7070
  let liElement = document.createElement("li");
7067
7071
  liElement["__formConfig__"] = formConfig;
7068
7072
  this.setElementClassName(liElement, formConfig.className);
@@ -7091,6 +7095,7 @@
7091
7095
  $eleKey: {
7092
7096
  disable: "__disable__",
7093
7097
  value: "__value__",
7098
+ forms: "__forms__",
7094
7099
  },
7095
7100
  $data: {
7096
7101
  defaultValue: formConfig.getValue(),
@@ -7121,31 +7126,50 @@
7121
7126
  getNodeValue($ele, key) {
7122
7127
  return Reflect.get($ele, key);
7123
7128
  },
7129
+ /**
7130
+ * 禁用选项
7131
+ */
7124
7132
  disable() {
7125
7133
  this.$ele.select.setAttribute("disabled", "true");
7126
7134
  this.$ele.panelSelect.classList.add("pops-panel-select-disable");
7127
7135
  },
7136
+ /**
7137
+ * 取消禁用
7138
+ */
7128
7139
  notDisable() {
7129
7140
  this.$ele.select.removeAttribute("disabled");
7130
7141
  this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
7131
7142
  },
7143
+ /**
7144
+ * 判断是否禁用
7145
+ */
7132
7146
  isDisabled() {
7133
7147
  return (this.$ele.select.hasAttribute("disabled") ||
7134
7148
  this.$ele.panelSelect.classList.contains("pops-panel-select-disable"));
7135
7149
  },
7150
+ /**
7151
+ * 初始化选项
7152
+ */
7136
7153
  initOption() {
7137
7154
  formConfig.data.forEach((dataItem) => {
7138
7155
  // 初始化默认选中
7139
7156
  let optionElement = document.createElement("option");
7140
7157
  this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
7141
7158
  this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
7159
+ this.setNodeValue(optionElement, this.$eleKey.forms, dataItem.forms);
7142
7160
  if (dataItem.value === this.$data.defaultValue) {
7143
- optionElement.setAttribute("selected", "true");
7161
+ this.setOptionSelected(optionElement);
7144
7162
  }
7145
7163
  optionElement.innerText = dataItem.text;
7146
7164
  this.$ele.select.appendChild(optionElement);
7147
7165
  });
7148
7166
  },
7167
+ /**
7168
+ * 设置选项选中
7169
+ */
7170
+ setOptionSelected($option) {
7171
+ $option.setAttribute("selected", "true");
7172
+ },
7149
7173
  /** 检测所有option并设置禁用状态 */
7150
7174
  setSelectOptionsDisableStatus() {
7151
7175
  if (this.$ele.select.options && this.$ele.select.options.length) {
@@ -7173,9 +7197,11 @@
7173
7197
  getSelectOptionInfo($option) {
7174
7198
  let optionValue = this.getNodeValue($option, this.$eleKey.value);
7175
7199
  let optionText = $option.innerText || $option.textContent;
7200
+ let optionForms = this.getNodeValue($option, this.$eleKey.forms);
7176
7201
  return {
7177
7202
  value: optionValue,
7178
7203
  text: optionText,
7204
+ forms: optionForms,
7179
7205
  $option: $option,
7180
7206
  };
7181
7207
  },
@@ -7184,12 +7210,34 @@
7184
7210
  */
7185
7211
  setChangeEvent() {
7186
7212
  popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
7213
+ let $isSelectedElement = event.target[event.target.selectedIndex];
7214
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7187
7215
  this.setSelectOptionsDisableStatus();
7188
7216
  if (typeof formConfig.callback === "function") {
7189
- let $isSelectedElement = event.target[event.target.selectedIndex];
7190
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7191
7217
  formConfig.callback(event, selectInfo.value, selectInfo.text);
7192
7218
  }
7219
+ let forms = typeof selectInfo.forms === "function"
7220
+ ? selectInfo.forms()
7221
+ : selectInfo.forms;
7222
+ if (Array.isArray(forms)) {
7223
+ /* 如果成功创建,加入到中间容器中 */
7224
+ let childUListClassName = "pops-panel-select-child-forms";
7225
+ // 移除旧的元素
7226
+ while (liElement.nextElementSibling) {
7227
+ if (liElement.nextElementSibling.classList.contains(childUListClassName)) {
7228
+ liElement.nextElementSibling.remove();
7229
+ }
7230
+ else {
7231
+ break;
7232
+ }
7233
+ }
7234
+ let $childUList = document.createElement("ul");
7235
+ $childUList.className = childUListClassName;
7236
+ popsDOMUtils.after(liElement, $childUList);
7237
+ that.uListContainerAddItem(formConfig, {
7238
+ ulElement: $childUList,
7239
+ });
7240
+ }
7193
7241
  });
7194
7242
  },
7195
7243
  /**
@@ -7528,12 +7576,28 @@
7528
7576
  Reflect.set($item, "data-info", dataInfo);
7529
7577
  return $item;
7530
7578
  }
7579
+ /**
7580
+ * 设置选择项的禁用状态
7581
+ */
7582
+ function setSelectItemDisabled($el) {
7583
+ $el.setAttribute("aria-disabled", "true");
7584
+ }
7585
+ /**
7586
+ * 移除选择项的禁用状态
7587
+ */
7588
+ function removeSelectItemDisabled($el) {
7589
+ $el.removeAttribute("aria-disabled");
7590
+ $el.removeAttribute("disabled");
7591
+ }
7531
7592
  /**
7532
7593
  * 设置选择项的点击事件
7533
7594
  */
7534
7595
  function setSelectElementClickEvent($ele) {
7535
7596
  popsDOMUtils.on($ele, "click", (event) => {
7536
7597
  popsDOMUtils.preventEvent(event);
7598
+ if ($ele.hasAttribute("disabled") || $ele.ariaDisabled) {
7599
+ return;
7600
+ }
7537
7601
  if (typeof formConfig.clickCallBack === "function") {
7538
7602
  let clickResult = formConfig.clickCallBack(event, getAllSelectedInfo());
7539
7603
  if (typeof clickResult === "boolean" && !clickResult) {
@@ -7599,7 +7663,6 @@
7599
7663
  --el-fill-color-light: #f5f7fa;
7600
7664
  }
7601
7665
  .select-item{
7602
- cursor: pointer;
7603
7666
  cursor: pointer;
7604
7667
  font-size: var(--el-font-size-base);
7605
7668
  padding: 0 32px 0 20px;
@@ -7612,6 +7675,12 @@
7612
7675
  line-height: 34px;
7613
7676
  box-sizing: border-box;
7614
7677
  }
7678
+ .select-item[aria-disabled],
7679
+ .select-item[disabled]{
7680
+ cursor: not-allowed;
7681
+ color: #a8abb2;
7682
+ background: unset;
7683
+ }
7615
7684
  .select-item:hover{
7616
7685
  background-color: var(--el-fill-color-light);
7617
7686
  }
@@ -7649,6 +7718,15 @@
7649
7718
  $selectContainer.appendChild($select);
7650
7719
  // 设置每一项的点击事件
7651
7720
  setSelectElementClickEvent($select);
7721
+ // 设置禁用状态
7722
+ if (typeof item.disable === "function" &&
7723
+ item.disable(item.value)) {
7724
+ setSelectItemDisabled($select);
7725
+ // 后续不设置元素的选中状态
7726
+ return;
7727
+ }
7728
+ // 移除禁用状态
7729
+ removeSelectItemDisabled($select);
7652
7730
  let findValue = selectedInfo.find((value) => value.value === item.value);
7653
7731
  if (findValue) {
7654
7732
  setItemSelected($select);
@@ -9607,6 +9685,12 @@
9607
9685
  this.$data.guid = guid;
9608
9686
  this.$el.$shadowContainer = ShadowInfo.$shadowContainer;
9609
9687
  this.$el.$shadowRoot = ShadowInfo.$shadowRoot;
9688
+ this.show = this.show.bind(this);
9689
+ this.close = this.close.bind(this);
9690
+ this.toolTipAnimationFinishEvent =
9691
+ this.toolTipAnimationFinishEvent.bind(this);
9692
+ this.toolTipMouseEnterEvent = this.toolTipMouseEnterEvent.bind(this);
9693
+ this.toolTipMouseLeaveEvent = this.toolTipMouseLeaveEvent.bind(this);
9610
9694
  this.init();
9611
9695
  }
9612
9696
  init() {
@@ -9861,13 +9945,13 @@
9861
9945
  * 绑定 显示事件
9862
9946
  */
9863
9947
  onShowEvent() {
9864
- popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerShowEventName, this.show.bind(this), this.$data.config.eventOption);
9948
+ popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerShowEventName, this.show, this.$data.config.eventOption);
9865
9949
  }
9866
9950
  /**
9867
9951
  * 取消绑定 显示事件
9868
9952
  */
9869
9953
  offShowEvent() {
9870
- popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerShowEventName, this.show.bind(this), {
9954
+ popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerShowEventName, this.show, {
9871
9955
  capture: true,
9872
9956
  });
9873
9957
  }
@@ -9917,13 +10001,13 @@
9917
10001
  * 绑定 关闭事件
9918
10002
  */
9919
10003
  onCloseEvent() {
9920
- popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close.bind(this), this.$data.config.eventOption);
10004
+ popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close, this.$data.config.eventOption);
9921
10005
  }
9922
10006
  /**
9923
10007
  * 取消绑定 关闭事件
9924
10008
  */
9925
10009
  offCloseEvent() {
9926
- popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close.bind(this), {
10010
+ popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close, {
9927
10011
  capture: true,
9928
10012
  });
9929
10013
  }
@@ -9957,13 +10041,13 @@
9957
10041
  * 监听tooltip的动画结束
9958
10042
  */
9959
10043
  onToolTipAnimationFinishEvent() {
9960
- popsDOMUtils.on(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.toolTipAnimationFinishEvent.bind(this));
10044
+ popsDOMUtils.on(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.toolTipAnimationFinishEvent);
9961
10045
  }
9962
10046
  /**
9963
10047
  * 取消tooltip监听动画结束
9964
10048
  */
9965
10049
  offToolTipAnimationFinishEvent() {
9966
- popsDOMUtils.off(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.toolTipAnimationFinishEvent.bind(this));
10050
+ popsDOMUtils.off(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.toolTipAnimationFinishEvent);
9967
10051
  }
9968
10052
  /**
9969
10053
  * 鼠标|触摸进入事件
@@ -9983,13 +10067,13 @@
9983
10067
  onToolTipMouseEnterEvent() {
9984
10068
  this.clearCloseTimeoutId("MouseEvent");
9985
10069
  this.clearCloseTimeoutId("TouchEvent");
9986
- popsDOMUtils.on(this.$el.$toolTip, "mouseenter touchstart", this.toolTipMouseEnterEvent.bind(this), this.$data.config.eventOption);
10070
+ popsDOMUtils.on(this.$el.$toolTip, "mouseenter touchstart", this.toolTipMouseEnterEvent, this.$data.config.eventOption);
9987
10071
  }
9988
10072
  /**
9989
10073
  * 取消监听鼠标|触摸事件
9990
10074
  */
9991
10075
  offToolTipMouseEnterEvent() {
9992
- popsDOMUtils.off(this.$el.$toolTip, "mouseenter touchstart", this.toolTipMouseEnterEvent.bind(this), this.$data.config.eventOption);
10076
+ popsDOMUtils.off(this.$el.$toolTip, "mouseenter touchstart", this.toolTipMouseEnterEvent, this.$data.config.eventOption);
9993
10077
  }
9994
10078
  /**
9995
10079
  * 鼠标|触摸离开事件
@@ -10002,13 +10086,13 @@
10002
10086
  * 监听鼠标|触摸离开事件
10003
10087
  */
10004
10088
  onToolTipMouseLeaveEvent() {
10005
- popsDOMUtils.on(this.$el.$toolTip, "mouseleave touchend", this.toolTipMouseLeaveEvent.bind(this), this.$data.config.eventOption);
10089
+ popsDOMUtils.on(this.$el.$toolTip, "mouseleave touchend", this.toolTipMouseLeaveEvent, this.$data.config.eventOption);
10006
10090
  }
10007
10091
  /**
10008
10092
  * 取消监听鼠标|触摸离开事件
10009
10093
  */
10010
10094
  offToolTipMouseLeaveEvent() {
10011
- popsDOMUtils.off(this.$el.$toolTip, "mouseleave touchend", this.toolTipMouseLeaveEvent.bind(this), this.$data.config.eventOption);
10095
+ popsDOMUtils.off(this.$el.$toolTip, "mouseleave touchend", this.toolTipMouseLeaveEvent, this.$data.config.eventOption);
10012
10096
  }
10013
10097
  }
10014
10098
  class PopsTooltip {
@@ -10053,7 +10137,7 @@
10053
10137
  /** 配置 */
10054
10138
  config = {
10055
10139
  /** 版本号 */
10056
- version: "2024.12.8",
10140
+ version: "2025.1.1",
10057
10141
  cssText: {
10058
10142
  /** 主CSS */
10059
10143
  index: indexCSS,