@whitesev/pops 1.9.6 → 2.0.0

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
@@ -316,6 +316,31 @@
316
316
  }
317
317
  const popsUtils = new PopsUtils();
318
318
 
319
+ const PopsSafeUtils = {
320
+ /**
321
+ * 设置安全的html
322
+ */
323
+ setSafeHTML($el, text) {
324
+ // 创建 TrustedHTML 策略(需 CSP 允许)
325
+ try {
326
+ $el.innerHTML = text;
327
+ }
328
+ catch (error) {
329
+ // @ts-ignore
330
+ if (globalThis.trustedTypes) {
331
+ // @ts-ignore
332
+ const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
333
+ createHTML: (html) => html,
334
+ });
335
+ $el.innerHTML = policy.createHTML(text);
336
+ }
337
+ else {
338
+ throw new Error("trustedTypes is not defined");
339
+ }
340
+ }
341
+ },
342
+ };
343
+
319
344
  class PopsDOMUtilsEvent {
320
345
  on(element, eventType, selector, callback, option) {
321
346
  /**
@@ -1253,7 +1278,7 @@
1253
1278
  attributes) {
1254
1279
  let tempElement = PopsCore.document.createElement(tagName);
1255
1280
  if (typeof property === "string") {
1256
- tempElement.innerHTML = property;
1281
+ PopsSafeUtils.setSafeHTML(tempElement, property);
1257
1282
  return tempElement;
1258
1283
  }
1259
1284
  if (property == null) {
@@ -1264,6 +1289,11 @@
1264
1289
  }
1265
1290
  Object.keys(property).forEach((key) => {
1266
1291
  let value = property[key];
1292
+ if (key === "innerHTML") {
1293
+ PopsSafeUtils.setSafeHTML(tempElement, value);
1294
+ return;
1295
+ }
1296
+ // @ts-ignore
1267
1297
  tempElement[key] = value;
1268
1298
  });
1269
1299
  Object.keys(attributes).forEach((key) => {
@@ -1466,7 +1496,7 @@
1466
1496
  }
1467
1497
  function parseHTMLByCreateDom() {
1468
1498
  let tempDIV = PopsCore.document.createElement("div");
1469
- tempDIV.innerHTML = html;
1499
+ PopsSafeUtils.setSafeHTML(tempDIV, html);
1470
1500
  if (isComplete) {
1471
1501
  return tempDIV;
1472
1502
  }
@@ -4862,26 +4892,29 @@
4862
4892
  fileNameElement.className = "pops-folder-list-table__body-td";
4863
4893
  fileTimeElement.className = "pops-folder-list-table__body-td";
4864
4894
  fileFormatSize.className = "pops-folder-list-table__body-td";
4865
- fileNameElement.innerHTML = `
4866
- <div class="pops-folder-list-file-name cursor-p">
4867
- <div>
4868
- <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
4869
- <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">
4870
- ${fileName}
4871
- </a>
4872
- </div>
4873
- </div>
4874
- `;
4875
- fileTimeElement.innerHTML = `
4876
- <div class="pops-folder-list__time">
4877
- <span>${latestTime}</span>
4878
- </div>
4879
- `;
4880
- fileFormatSize.innerHTML = `
4881
- <div class="pops-folder-list-format-size">
4882
- <span>${fileSize}</span>
4883
- </div>
4884
- `;
4895
+ PopsSafeUtils.setSafeHTML(fileNameElement,
4896
+ /*html*/ `
4897
+ <div class="pops-folder-list-file-name cursor-p">
4898
+ <div>
4899
+ <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
4900
+ <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">
4901
+ ${fileName}
4902
+ </a>
4903
+ </div>
4904
+ </div>
4905
+ `);
4906
+ PopsSafeUtils.setSafeHTML(fileTimeElement,
4907
+ /*html*/ `
4908
+ <div class="pops-folder-list__time">
4909
+ <span>${latestTime}</span>
4910
+ </div>
4911
+ `);
4912
+ PopsSafeUtils.setSafeHTML(fileFormatSize,
4913
+ /*html*/ `
4914
+ <div class="pops-folder-list-format-size">
4915
+ <span>${fileSize}</span>
4916
+ </div>
4917
+ `);
4885
4918
  /* 存储原来的值 */
4886
4919
  let __value__ = {
4887
4920
  fileName: origin_fileName,
@@ -4942,17 +4975,18 @@
4942
4975
  }
4943
4976
  folderELement.className = "pops-folder-list-table__body-row";
4944
4977
  fileNameElement.className = "pops-folder-list-table__body-td";
4945
- fileNameElement.innerHTML = `
4946
- <div class="pops-folder-list-file-name pops-mobile-folder-list-file-name cursor-p">
4947
- <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
4948
- <div>
4949
- <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">
4950
- ${fileName}
4951
- </a>
4952
- <span>${latestTime} ${fileSize}</span>
4953
- </div>
4954
- </div>
4955
- `;
4978
+ PopsSafeUtils.setSafeHTML(fileNameElement,
4979
+ /*html*/ `
4980
+ <div class="pops-folder-list-file-name pops-mobile-folder-list-file-name cursor-p">
4981
+ <img src="${fileIcon}" alt="${fileType}" class="pops-folder-list-file-icon u-file-icon u-file-icon--list">
4982
+ <div>
4983
+ <a title="${fileName}" class="pops-folder-list-file-name-title-text inline-block-v-middle text-ellip list-name-text">
4984
+ ${fileName}
4985
+ </a>
4986
+ <span>${latestTime} ${fileSize}</span>
4987
+ </div>
4988
+ </div>
4989
+ `);
4956
4990
  /* 存储原来的值 */
4957
4991
  let __value__ = {
4958
4992
  fileName: origin_fileName,
@@ -4972,7 +5006,7 @@
4972
5006
  * 清空每行的元素
4973
5007
  */
4974
5008
  function clearFolerRow() {
4975
- folderListBodyElement.innerHTML = "";
5009
+ PopsSafeUtils.setSafeHTML(folderListBodyElement, "");
4976
5010
  }
4977
5011
  function getArrowIconElement() {
4978
5012
  let iconArrowElement = popsDOMUtils.createElement("div", {
@@ -5546,6 +5580,7 @@
5546
5580
  disable() {
5547
5581
  return false;
5548
5582
  },
5583
+ forms: [],
5549
5584
  },
5550
5585
  {
5551
5586
  value: "text",
@@ -5553,6 +5588,7 @@
5553
5588
  disable() {
5554
5589
  return false;
5555
5590
  },
5591
+ forms: [],
5556
5592
  },
5557
5593
  {
5558
5594
  value: "html",
@@ -5560,6 +5596,7 @@
5560
5596
  disable() {
5561
5597
  return false;
5562
5598
  },
5599
+ forms: [],
5563
5600
  },
5564
5601
  ],
5565
5602
  },
@@ -5968,8 +6005,8 @@
5968
6005
  * 清空container容器的元素
5969
6006
  */
5970
6007
  clearContainer() {
5971
- this.sectionContainerHeaderULElement.innerHTML = "";
5972
- this.sectionContainerULElement.innerHTML = "";
6008
+ PopsSafeUtils.setSafeHTML(this.sectionContainerHeaderULElement, "");
6009
+ PopsSafeUtils.setSafeHTML(this.sectionContainerULElement, "");
5973
6010
  this.$el.$content
5974
6011
  ?.querySelectorAll("section.pops-panel-deepMenu-container")
5975
6012
  .forEach((ele) => ele.remove());
@@ -6055,8 +6092,9 @@
6055
6092
  createAsideItem(asideConfig) {
6056
6093
  let liElement = document.createElement("li");
6057
6094
  liElement.id = asideConfig.id;
6095
+ // @ts-ignore
6058
6096
  liElement["__forms__"] = asideConfig.forms;
6059
- liElement.innerHTML = asideConfig.title;
6097
+ PopsSafeUtils.setSafeHTML(liElement, asideConfig.title);
6060
6098
  /* 处理className */
6061
6099
  this.setElementClassName(liElement, asideConfig.className);
6062
6100
  this.setElementAttributes(liElement, asideConfig.attributes);
@@ -6079,18 +6117,19 @@
6079
6117
  if (Boolean(formConfig.description)) {
6080
6118
  leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
6081
6119
  }
6082
- liElement.innerHTML = /*html*/ `
6083
- <div class="pops-panel-item-left-text">
6084
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6085
- ${leftDescriptionText}
6086
- </div>
6087
- <div class="pops-panel-switch">
6088
- <input class="pops-panel-switch__input" type="checkbox">
6089
- <span class="pops-panel-switch__core">
6090
- <div class="pops-panel-switch__action">
6091
- </div>
6092
- </span>
6093
- </div>`;
6120
+ PopsSafeUtils.setSafeHTML(liElement,
6121
+ /*html*/ `
6122
+ <div class="pops-panel-item-left-text">
6123
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6124
+ ${leftDescriptionText}
6125
+ </div>
6126
+ <div class="pops-panel-switch">
6127
+ <input class="pops-panel-switch__input" type="checkbox">
6128
+ <span class="pops-panel-switch__core">
6129
+ <div class="pops-panel-switch__action">
6130
+ </div>
6131
+ </span>
6132
+ </div>`);
6094
6133
  const PopsPanelSwitch = {
6095
6134
  [Symbol.toStringTag]: "PopsPanelSwitch",
6096
6135
  $data: {
@@ -6180,14 +6219,16 @@
6180
6219
  if (Boolean(formConfig.description)) {
6181
6220
  leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
6182
6221
  }
6183
- liElement.innerHTML = `
6184
- <div class="pops-panel-item-left-text">
6185
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6186
- ${leftDescriptionText}
6187
- </div>
6188
- <div class="pops-panel-slider">
6189
- <input type="range" min="${formConfig.min}" max="${formConfig.max}">
6190
- </div>`;
6222
+ PopsSafeUtils.setSafeHTML(liElement,
6223
+ /*html*/ `
6224
+ <div class="pops-panel-item-left-text">
6225
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6226
+ ${leftDescriptionText}
6227
+ </div>
6228
+ <div class="pops-panel-slider">
6229
+ <input type="range" min="${formConfig.min}" max="${formConfig.max}">
6230
+ </div>
6231
+ `);
6191
6232
  let rangeInputElement = liElement.querySelector(".pops-panel-slider input[type=range]");
6192
6233
  if (formConfig.step) {
6193
6234
  rangeInputElement.setAttribute("step", formConfig.step.toString());
@@ -6243,19 +6284,20 @@
6243
6284
  if (Boolean(formConfig.description)) {
6244
6285
  leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
6245
6286
  }
6246
- liElement.innerHTML = /*html*/ `
6247
- <div class="pops-panel-item-left-text" style="flex: 1;">
6248
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6249
- ${leftDescriptionText}
6250
- </div>
6251
- <div class="pops-slider pops-slider-width">
6252
- <div class="pops-slider__runway">
6253
- <div class="pops-slider__bar" style="width: 0%; left: 0%"></div>
6254
- <div class="pops-slider__button-wrapper" style="left: 0%">
6255
- <div class="pops-slider__button"></div>
6256
- </div>
6287
+ PopsSafeUtils.setSafeHTML(liElement,
6288
+ /*html*/ `
6289
+ <div class="pops-panel-item-left-text" style="flex: 1;">
6290
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6291
+ ${leftDescriptionText}
6257
6292
  </div>
6258
- </div>`;
6293
+ <div class="pops-slider pops-slider-width">
6294
+ <div class="pops-slider__runway">
6295
+ <div class="pops-slider__bar" style="width: 0%; left: 0%"></div>
6296
+ <div class="pops-slider__button-wrapper" style="left: 0%">
6297
+ <div class="pops-slider__button"></div>
6298
+ </div>
6299
+ </div>
6300
+ </div>`);
6259
6301
  const PopsPanelSlider = {
6260
6302
  [Symbol.toStringTag]: "PopsPanelSlider",
6261
6303
  /**
@@ -6805,15 +6847,16 @@
6805
6847
  if (Boolean(formConfig.description)) {
6806
6848
  leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
6807
6849
  }
6808
- liElement.innerHTML = `
6809
- <div class="pops-panel-item-left-text">
6810
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6811
- ${leftDescriptionText}
6812
- </div>
6813
- <div class="pops-panel-input pops-user-select-none">
6814
- <input type="${inputType}" placeholder="${formConfig.placeholder}">
6815
- </div>
6816
- `;
6850
+ PopsSafeUtils.setSafeHTML(liElement,
6851
+ /*html*/ `
6852
+ <div class="pops-panel-item-left-text">
6853
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
6854
+ ${leftDescriptionText}
6855
+ </div>
6856
+ <div class="pops-panel-input pops-user-select-none">
6857
+ <input type="${inputType}" placeholder="${formConfig.placeholder}">
6858
+ </div>
6859
+ `);
6817
6860
  const PopsPanelInput = {
6818
6861
  [Symbol.toStringTag]: "PopsPanelInput",
6819
6862
  $ele: {
@@ -6856,11 +6899,12 @@
6856
6899
  initEle() {
6857
6900
  this.$ele.input.parentElement.insertBefore(this.$ele.inputSpanIcon, this.$ele.input.nextSibling);
6858
6901
  this.$ele.inputSpanIcon.className = "pops-panel-input__suffix";
6859
- this.$ele.inputSpanIcon.innerHTML = `
6860
- <span class="pops-panel-input__suffix-inner">
6861
- <i class="pops-panel-icon"></i>
6862
- </span>
6863
- `;
6902
+ PopsSafeUtils.setSafeHTML(this.$ele.inputSpanIcon,
6903
+ /*html*/ `
6904
+ <span class="pops-panel-input__suffix-inner">
6905
+ <i class="pops-panel-icon"></i>
6906
+ </span>
6907
+ `);
6864
6908
  this.$ele.inputSpanIconInner =
6865
6909
  this.$ele.inputSpanIcon.querySelector(".pops-panel-input__suffix-inner");
6866
6910
  this.$ele.icon =
@@ -6895,7 +6939,7 @@
6895
6939
  },
6896
6940
  /**
6897
6941
  * 设置input元素的type
6898
- * @param {string} [typeValue="text"] type值
6942
+ * @param [typeValue="text"] type值
6899
6943
  */
6900
6944
  setInputType(typeValue = "text") {
6901
6945
  this.$ele.input.setAttribute("type", typeValue);
@@ -6904,14 +6948,14 @@
6904
6948
  * 删除图标按钮
6905
6949
  */
6906
6950
  removeCircleIcon() {
6907
- this.$ele.icon.innerHTML = "";
6951
+ PopsSafeUtils.setSafeHTML(this.$ele.icon, "");
6908
6952
  },
6909
6953
  /**
6910
6954
  * 添加清空图标按钮
6911
- * @param {string} [svgHTML=pops.config.iconSVG.circleClose] svg图标,默认为清空的图标
6955
+ * @param [svgHTML=pops.config.iconSVG.circleClose] svg图标,默认为清空的图标
6912
6956
  */
6913
6957
  setCircleIcon(svgHTML = pops.config.iconSVG.circleClose) {
6914
- this.$ele.icon.innerHTML = svgHTML;
6958
+ PopsSafeUtils.setSafeHTML(this.$ele.icon, svgHTML);
6915
6959
  },
6916
6960
  /**
6917
6961
  * 添加图标按钮的点击事件
@@ -7000,16 +7044,17 @@
7000
7044
  if (Boolean(formConfig.description)) {
7001
7045
  leftDescriptionText = `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7002
7046
  }
7003
- liElement.innerHTML = `
7004
- <div class="pops-panel-item-left-text">
7005
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7006
- ${leftDescriptionText}
7007
- </div>
7008
- <div class="pops-panel-textarea">
7009
- <textarea placeholder="${formConfig.placeholder ?? ""}">
7010
- </textarea>
7011
- </div>
7012
- `;
7047
+ PopsSafeUtils.setSafeHTML(liElement,
7048
+ /*html*/ `
7049
+ <div class="pops-panel-item-left-text">
7050
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7051
+ ${leftDescriptionText}
7052
+ </div>
7053
+ <div class="pops-panel-textarea">
7054
+ <textarea placeholder="${formConfig.placeholder ?? ""}">
7055
+ </textarea>
7056
+ </div>
7057
+ `);
7013
7058
  const PopsPanelTextArea = {
7014
7059
  [Symbol.toStringTag]: "PopsPanelTextArea",
7015
7060
  $ele: {
@@ -7063,6 +7108,7 @@
7063
7108
  * @param formConfig
7064
7109
  */
7065
7110
  createSectionContainerItem_select(formConfig) {
7111
+ const that = this;
7066
7112
  let liElement = document.createElement("li");
7067
7113
  liElement["__formConfig__"] = formConfig;
7068
7114
  this.setElementClassName(liElement, formConfig.className);
@@ -7073,15 +7119,16 @@
7073
7119
  if (Boolean(formConfig.description)) {
7074
7120
  leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7075
7121
  }
7076
- liElement.innerHTML = /*html*/ `
7077
- <div class="pops-panel-item-left-text">
7078
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7079
- ${leftDescriptionText}
7080
- </div>
7081
- <div class="pops-panel-select pops-user-select-none">
7082
- <select></select>
7083
- </div>
7084
- `;
7122
+ PopsSafeUtils.setSafeHTML(liElement,
7123
+ /*html*/ `
7124
+ <div class="pops-panel-item-left-text">
7125
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7126
+ ${leftDescriptionText}
7127
+ </div>
7128
+ <div class="pops-panel-select pops-user-select-none">
7129
+ <select></select>
7130
+ </div>
7131
+ `);
7085
7132
  const PopsPanelSelect = {
7086
7133
  [Symbol.toStringTag]: "PopsPanelSelect",
7087
7134
  $ele: {
@@ -7091,6 +7138,7 @@
7091
7138
  $eleKey: {
7092
7139
  disable: "__disable__",
7093
7140
  value: "__value__",
7141
+ forms: "__forms__",
7094
7142
  },
7095
7143
  $data: {
7096
7144
  defaultValue: formConfig.getValue(),
@@ -7121,31 +7169,50 @@
7121
7169
  getNodeValue($ele, key) {
7122
7170
  return Reflect.get($ele, key);
7123
7171
  },
7172
+ /**
7173
+ * 禁用选项
7174
+ */
7124
7175
  disable() {
7125
7176
  this.$ele.select.setAttribute("disabled", "true");
7126
7177
  this.$ele.panelSelect.classList.add("pops-panel-select-disable");
7127
7178
  },
7179
+ /**
7180
+ * 取消禁用
7181
+ */
7128
7182
  notDisable() {
7129
7183
  this.$ele.select.removeAttribute("disabled");
7130
7184
  this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
7131
7185
  },
7186
+ /**
7187
+ * 判断是否禁用
7188
+ */
7132
7189
  isDisabled() {
7133
7190
  return (this.$ele.select.hasAttribute("disabled") ||
7134
7191
  this.$ele.panelSelect.classList.contains("pops-panel-select-disable"));
7135
7192
  },
7193
+ /**
7194
+ * 初始化选项
7195
+ */
7136
7196
  initOption() {
7137
7197
  formConfig.data.forEach((dataItem) => {
7138
7198
  // 初始化默认选中
7139
7199
  let optionElement = document.createElement("option");
7140
7200
  this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
7141
7201
  this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
7202
+ this.setNodeValue(optionElement, this.$eleKey.forms, dataItem.forms);
7142
7203
  if (dataItem.value === this.$data.defaultValue) {
7143
- optionElement.setAttribute("selected", "true");
7204
+ this.setOptionSelected(optionElement);
7144
7205
  }
7145
7206
  optionElement.innerText = dataItem.text;
7146
7207
  this.$ele.select.appendChild(optionElement);
7147
7208
  });
7148
7209
  },
7210
+ /**
7211
+ * 设置选项选中
7212
+ */
7213
+ setOptionSelected($option) {
7214
+ $option.setAttribute("selected", "true");
7215
+ },
7149
7216
  /** 检测所有option并设置禁用状态 */
7150
7217
  setSelectOptionsDisableStatus() {
7151
7218
  if (this.$ele.select.options && this.$ele.select.options.length) {
@@ -7173,9 +7240,11 @@
7173
7240
  getSelectOptionInfo($option) {
7174
7241
  let optionValue = this.getNodeValue($option, this.$eleKey.value);
7175
7242
  let optionText = $option.innerText || $option.textContent;
7243
+ let optionForms = this.getNodeValue($option, this.$eleKey.forms);
7176
7244
  return {
7177
7245
  value: optionValue,
7178
7246
  text: optionText,
7247
+ forms: optionForms,
7179
7248
  $option: $option,
7180
7249
  };
7181
7250
  },
@@ -7184,12 +7253,34 @@
7184
7253
  */
7185
7254
  setChangeEvent() {
7186
7255
  popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
7256
+ let $isSelectedElement = event.target[event.target.selectedIndex];
7257
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7187
7258
  this.setSelectOptionsDisableStatus();
7188
7259
  if (typeof formConfig.callback === "function") {
7189
- let $isSelectedElement = event.target[event.target.selectedIndex];
7190
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
7191
7260
  formConfig.callback(event, selectInfo.value, selectInfo.text);
7192
7261
  }
7262
+ let forms = typeof selectInfo.forms === "function"
7263
+ ? selectInfo.forms()
7264
+ : selectInfo.forms;
7265
+ if (Array.isArray(forms)) {
7266
+ /* 如果成功创建,加入到中间容器中 */
7267
+ let childUListClassName = "pops-panel-select-child-forms";
7268
+ // 移除旧的元素
7269
+ while (liElement.nextElementSibling) {
7270
+ if (liElement.nextElementSibling.classList.contains(childUListClassName)) {
7271
+ liElement.nextElementSibling.remove();
7272
+ }
7273
+ else {
7274
+ break;
7275
+ }
7276
+ }
7277
+ let $childUList = document.createElement("ul");
7278
+ $childUList.className = childUListClassName;
7279
+ popsDOMUtils.after(liElement, $childUList);
7280
+ that.uListContainerAddItem(formConfig, {
7281
+ ulElement: $childUList,
7282
+ });
7283
+ }
7193
7284
  });
7194
7285
  },
7195
7286
  /**
@@ -7224,33 +7315,34 @@
7224
7315
  if (Boolean(formConfig.description)) {
7225
7316
  leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7226
7317
  }
7227
- liElement.innerHTML = /*html*/ `
7228
- <div class="pops-panel-item-left-text">
7229
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7230
- ${leftDescriptionText}
7231
- </div>
7232
- <div class="pops-panel-select-multiple">
7233
- <div class="el-select__wrapper">
7234
- <div class="el-select__selection">
7235
- <!-- 这个是用于手动输入的,这里暂不适配 -->
7236
- <div class="el-select__selected-item el-select__input-wrapper">
7237
-
7318
+ PopsSafeUtils.setSafeHTML(liElement,
7319
+ /*html*/ `
7320
+ <div class="pops-panel-item-left-text">
7321
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7322
+ ${leftDescriptionText}
7323
+ </div>
7324
+ <div class="pops-panel-select-multiple">
7325
+ <div class="el-select__wrapper">
7326
+ <div class="el-select__selection">
7327
+ <!-- 这个是用于手动输入的,这里暂不适配 -->
7328
+ <div class="el-select__selected-item el-select__input-wrapper">
7329
+
7330
+ </div>
7331
+ <!-- 这个是placeholder -->
7332
+ <div class="el-select__selected-item el-select__placeholder">
7333
+ </div>
7238
7334
  </div>
7239
- <!-- 这个是placeholder -->
7240
- <div class="el-select__selected-item el-select__placeholder">
7335
+ <!-- 下拉箭头 -->
7336
+ <div class="el-select__suffix">
7337
+ <i class="el-icon el-select__caret el-select__icon">
7338
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
7339
+ <path fill="currentColor" d="M831.872 340.864 512 652.672 192.128 340.864a30.592 30.592 0 0 0-42.752 0 29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728 30.592 30.592 0 0 0-42.752 0z"></path>
7340
+ </svg>
7341
+ </i>
7241
7342
  </div>
7242
7343
  </div>
7243
- <!-- 下拉箭头 -->
7244
- <div class="el-select__suffix">
7245
- <i class="el-icon el-select__caret el-select__icon">
7246
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
7247
- <path fill="currentColor" d="M831.872 340.864 512 652.672 192.128 340.864a30.592 30.592 0 0 0-42.752 0 29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728 30.592 30.592 0 0 0-42.752 0z"></path>
7248
- </svg>
7249
- </i>
7250
- </div>
7251
7344
  </div>
7252
- </div>
7253
- `;
7345
+ `);
7254
7346
  const PopsPanelSelectMultiple = {
7255
7347
  [Symbol.toStringTag]: "PopsPanelSelectMultiple",
7256
7348
  $el: {
@@ -7375,7 +7467,7 @@
7375
7467
  /** 关闭图标 */
7376
7468
  const $closeIcon = $selectedItem.querySelector(".el-icon.el-tag__close");
7377
7469
  if (data.isHTML) {
7378
- $tagText.innerHTML = data.text;
7470
+ PopsSafeUtils.setSafeHTML($tagText, data.text);
7379
7471
  }
7380
7472
  else {
7381
7473
  $tagText.innerText = data.text;
@@ -7528,12 +7620,28 @@
7528
7620
  Reflect.set($item, "data-info", dataInfo);
7529
7621
  return $item;
7530
7622
  }
7623
+ /**
7624
+ * 设置选择项的禁用状态
7625
+ */
7626
+ function setSelectItemDisabled($el) {
7627
+ $el.setAttribute("aria-disabled", "true");
7628
+ }
7629
+ /**
7630
+ * 移除选择项的禁用状态
7631
+ */
7632
+ function removeSelectItemDisabled($el) {
7633
+ $el.removeAttribute("aria-disabled");
7634
+ $el.removeAttribute("disabled");
7635
+ }
7531
7636
  /**
7532
7637
  * 设置选择项的点击事件
7533
7638
  */
7534
7639
  function setSelectElementClickEvent($ele) {
7535
7640
  popsDOMUtils.on($ele, "click", (event) => {
7536
7641
  popsDOMUtils.preventEvent(event);
7642
+ if ($ele.hasAttribute("disabled") || $ele.ariaDisabled) {
7643
+ return;
7644
+ }
7537
7645
  if (typeof formConfig.clickCallBack === "function") {
7538
7646
  let clickResult = formConfig.clickCallBack(event, getAllSelectedInfo());
7539
7647
  if (typeof clickResult === "boolean" && !clickResult) {
@@ -7599,7 +7707,6 @@
7599
7707
  --el-fill-color-light: #f5f7fa;
7600
7708
  }
7601
7709
  .select-item{
7602
- cursor: pointer;
7603
7710
  cursor: pointer;
7604
7711
  font-size: var(--el-font-size-base);
7605
7712
  padding: 0 32px 0 20px;
@@ -7612,6 +7719,12 @@
7612
7719
  line-height: 34px;
7613
7720
  box-sizing: border-box;
7614
7721
  }
7722
+ .select-item[aria-disabled],
7723
+ .select-item[disabled]{
7724
+ cursor: not-allowed;
7725
+ color: #a8abb2;
7726
+ background: unset;
7727
+ }
7615
7728
  .select-item:hover{
7616
7729
  background-color: var(--el-fill-color-light);
7617
7730
  }
@@ -7649,6 +7762,15 @@
7649
7762
  $selectContainer.appendChild($select);
7650
7763
  // 设置每一项的点击事件
7651
7764
  setSelectElementClickEvent($select);
7765
+ // 设置禁用状态
7766
+ if (typeof item.disable === "function" &&
7767
+ item.disable(item.value)) {
7768
+ setSelectItemDisabled($select);
7769
+ // 后续不设置元素的选中状态
7770
+ return;
7771
+ }
7772
+ // 移除禁用状态
7773
+ removeSelectItemDisabled($select);
7652
7774
  let findValue = selectedInfo.find((value) => value.value === item.value);
7653
7775
  if (findValue) {
7654
7776
  setItemSelected($select);
@@ -7752,18 +7874,19 @@
7752
7874
  if (Boolean(formConfig.description)) {
7753
7875
  leftDescriptionText = /*html*/ `<p class="pops-panel-item-left-desc-text">${formConfig.description}</p>`;
7754
7876
  }
7755
- liElement.innerHTML = /*html*/ `
7756
- <div class="pops-panel-item-left-text">
7757
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7758
- ${leftDescriptionText}
7759
- </div>
7760
- <div class="pops-panel-button">
7761
- <button class="pops-panel-button_inner">
7762
- <i class="pops-bottom-icon"></i>
7763
- <span class="pops-panel-button-text"></span>
7764
- </button>
7765
- </div>
7766
- `;
7877
+ PopsSafeUtils.setSafeHTML(liElement,
7878
+ /*html*/ `
7879
+ <div class="pops-panel-item-left-text">
7880
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7881
+ ${leftDescriptionText}
7882
+ </div>
7883
+ <div class="pops-panel-button">
7884
+ <button class="pops-panel-button_inner">
7885
+ <i class="pops-bottom-icon"></i>
7886
+ <span class="pops-panel-button-text"></span>
7887
+ </button>
7888
+ </div>
7889
+ `);
7767
7890
  const PopsPanelButton = {
7768
7891
  [Symbol.toStringTag]: "PopsPanelButton",
7769
7892
  $ele: {
@@ -7833,7 +7956,7 @@
7833
7956
  * 设置icon图标的svg
7834
7957
  */
7835
7958
  setIconSVG(svgHTML) {
7836
- this.$ele.icon.innerHTML = svgHTML;
7959
+ PopsSafeUtils.setSafeHTML(this.$ele.icon, svgHTML);
7837
7960
  },
7838
7961
  /**
7839
7962
  * 设置icon图标是否旋转
@@ -7872,7 +7995,7 @@
7872
7995
  * @param text
7873
7996
  */
7874
7997
  setButtonText(text) {
7875
- this.$ele.spanText.innerHTML = text;
7998
+ PopsSafeUtils.setSafeHTML(this.$ele.spanText, text);
7876
7999
  },
7877
8000
  setClickEvent() {
7878
8001
  popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
@@ -7918,16 +8041,17 @@
7918
8041
  if (formConfig.rightText) {
7919
8042
  rightText = /*html*/ `<p class="pops-panel-item-right-text">${formConfig.rightText}</p>`;
7920
8043
  }
7921
- $li.innerHTML = /*html*/ `
7922
- <div class="pops-panel-item-left-text">
7923
- <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
7924
- ${leftDescriptionText}
7925
- </div>
7926
- <div class="pops-panel-deepMenu">
7927
- ${rightText}
7928
- ${arrowRightIconHTML}
7929
- </div>
7930
- `;
8044
+ PopsSafeUtils.setSafeHTML($li,
8045
+ /*html*/ `
8046
+ <div class="pops-panel-item-left-text">
8047
+ <p class="pops-panel-item-left-main-text">${formConfig.text}</p>
8048
+ ${leftDescriptionText}
8049
+ </div>
8050
+ <div class="pops-panel-deepMenu">
8051
+ ${rightText}
8052
+ ${arrowRightIconHTML}
8053
+ </div>
8054
+ `);
7931
8055
  const PopsPanelDeepMenu = {
7932
8056
  [Symbol.toStringTag]: "PopsPanelDeepMenu",
7933
8057
  $ele: {
@@ -7957,19 +8081,19 @@
7957
8081
  let formHeaderDivElement = popsDOMUtils.createElement("div", {
7958
8082
  className: "pops-panel-forms-container-item-header-text",
7959
8083
  });
7960
- formHeaderDivElement.innerHTML = formConfig_forms["text"];
8084
+ PopsSafeUtils.setSafeHTML(formHeaderDivElement, formConfig_forms["text"]);
7961
8085
  if (formConfig_forms.isFold) {
7962
8086
  /* 添加第一个 */
7963
8087
  /* 加进容器内 */
7964
- formHeaderDivElement.innerHTML = /*html*/ `
8088
+ PopsSafeUtils.setSafeHTML(formHeaderDivElement,
8089
+ /*html*/ `
7965
8090
  <p>${formConfig_forms.text}</p>
7966
8091
  <i class="pops-panel-forms-fold-container-icon">
7967
8092
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
7968
8093
  <path d="M340.864 149.312a30.592 30.592 0 0 0 0 42.752L652.736 512 340.864 831.872a30.592 30.592 0 0 0 0 42.752 29.12 29.12 0 0 0 41.728 0L714.24 534.336a32 32 0 0 0 0-44.672L382.592 149.376a29.12 29.12 0 0 0-41.728 0z"></path>
7969
8094
  </svg>
7970
8095
  </i>
7971
-
7972
- `;
8096
+ `);
7973
8097
  // 添加点击事件
7974
8098
  popsDOMUtils.on(formHeaderDivElement, "click", (event) => {
7975
8099
  if (formContainerListElement.hasAttribute("data-fold-enable")) {
@@ -8167,18 +8291,18 @@
8167
8291
  let formHeaderDivElement = popsDOMUtils.createElement("div", {
8168
8292
  className: "pops-panel-forms-container-item-header-text",
8169
8293
  });
8170
- formHeaderDivElement.innerHTML = formConfig_forms["text"];
8294
+ PopsSafeUtils.setSafeHTML(formHeaderDivElement, formConfig_forms["text"]);
8171
8295
  if (formConfig_forms.isFold) {
8172
8296
  /* 加进容器内 */
8173
- formHeaderDivElement.innerHTML = /*html*/ `
8297
+ PopsSafeUtils.setSafeHTML(formHeaderDivElement,
8298
+ /*html*/ `
8174
8299
  <p>${formConfig_forms.text}</p>
8175
8300
  <i class="pops-panel-forms-fold-container-icon">
8176
8301
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
8177
8302
  <path d="M340.864 149.312a30.592 30.592 0 0 0 0 42.752L652.736 512 340.864 831.872a30.592 30.592 0 0 0 0 42.752 29.12 29.12 0 0 0 41.728 0L714.24 534.336a32 32 0 0 0 0-44.672L382.592 149.376a29.12 29.12 0 0 0-41.728 0z"></path>
8178
8303
  </svg>
8179
8304
  </i>
8180
-
8181
- `;
8305
+ `);
8182
8306
  // 添加点击事件
8183
8307
  popsDOMUtils.on(formHeaderDivElement, "click", (event) => {
8184
8308
  if (formContainerListElement.hasAttribute("data-fold-enable")) {
@@ -8264,7 +8388,7 @@
8264
8388
  let containerHeaderTitleLIElement = document.createElement("li");
8265
8389
  containerHeaderTitleLIElement["__asideConfig__"] =
8266
8390
  asideConfig;
8267
- containerHeaderTitleLIElement.innerHTML = headerTitleText;
8391
+ PopsSafeUtils.setSafeHTML(containerHeaderTitleLIElement, headerTitleText);
8268
8392
  this.sectionContainerHeaderULElement.appendChild(containerHeaderTitleLIElement);
8269
8393
  }
8270
8394
  let __forms__ = asideLiElement["__forms__"];
@@ -8553,9 +8677,11 @@
8553
8677
  pops.config.cssText.rightClickMenu,
8554
8678
  ]);
8555
8679
  if (config.style != null) {
8556
- let cssNode = document.createElement("style");
8557
- cssNode.setAttribute("type", "text/css");
8558
- cssNode.innerHTML = config.style;
8680
+ let cssNode = popsDOMUtils.createElement("style", {
8681
+ innerHTML: config.style,
8682
+ }, {
8683
+ type: "text/css",
8684
+ });
8559
8685
  $shadowRoot.appendChild(cssNode);
8560
8686
  }
8561
8687
  const PopsContextMenu = {
@@ -9037,8 +9163,11 @@
9037
9163
  ]);
9038
9164
  if (config.style != null) {
9039
9165
  let cssNode = document.createElement("style");
9040
- cssNode.setAttribute("type", "text/css");
9041
- cssNode.innerHTML = config.style;
9166
+ popsDOMUtils.createElement("style", {
9167
+ innerHTML: config.style,
9168
+ }, {
9169
+ type: "text/css",
9170
+ });
9042
9171
  $shadowRoot.appendChild(cssNode);
9043
9172
  }
9044
9173
  const SearchSuggestion = {
@@ -9415,7 +9544,7 @@
9415
9544
  * 清空所有的搜索结果
9416
9545
  */
9417
9546
  clearAllSearchItemLi() {
9418
- SearchSuggestion.$el.$hintULContainer.innerHTML = "";
9547
+ PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
9419
9548
  },
9420
9549
  /**
9421
9550
  * 更新搜索建议框的位置(top、left)
@@ -9497,7 +9626,8 @@
9497
9626
  * 动态更新CSS
9498
9627
  */
9499
9628
  updateDynamicCSS() {
9500
- this.$el.$dynamicCSS.innerHTML = this.getDynamicCSS();
9629
+ let cssText = this.getDynamicCSS();
9630
+ PopsSafeUtils.setSafeHTML(this.$el.$dynamicCSS, cssText);
9501
9631
  },
9502
9632
  /**
9503
9633
  * 更新页面显示的搜索结果
@@ -9687,7 +9817,7 @@
9687
9817
  if (text == null) {
9688
9818
  text = this.getContent();
9689
9819
  }
9690
- this.$el.$content.innerHTML = text;
9820
+ PopsSafeUtils.setSafeHTML(this.$el.$content, text);
9691
9821
  }
9692
9822
  /**
9693
9823
  * 获取z-index
@@ -10059,7 +10189,7 @@
10059
10189
  /** 配置 */
10060
10190
  config = {
10061
10191
  /** 版本号 */
10062
- version: "2024.12.8",
10192
+ version: "2025.3.2",
10063
10193
  cssText: {
10064
10194
  /** 主CSS */
10065
10195
  index: indexCSS,
@@ -10164,7 +10294,7 @@
10164
10294
  /* 处理获取当前所有的动画名 */
10165
10295
  this.config.isInit = true;
10166
10296
  let animationStyle = document.createElement("style");
10167
- animationStyle.innerHTML = this.config.cssText.anim;
10297
+ PopsSafeUtils.setSafeHTML(animationStyle, this.config.cssText.anim);
10168
10298
  popsDOMUtils.appendHead(animationStyle);
10169
10299
  this.config.animation = null;
10170
10300
  this.config.animation = PopsInstanceUtils.getKeyFrames(animationStyle.sheet);