@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.
@@ -1,4 +1,6 @@
1
1
  import type { PopsPanelCommonDetails } from "./commonType";
2
+ import type { PopsPanelFormsDetails } from "./formsType";
3
+ import type { PopsPanelFormsTotalDetails } from "./indexType";
2
4
  /**
3
5
  * pops.panel的 select
4
6
  */
@@ -71,5 +73,9 @@ export interface PopsPanelSelectDetails<T = any> extends PopsPanelCommonDetails<
71
73
  * + select元素触发change事件
72
74
  */
73
75
  disable?(value: T): boolean;
76
+ /**
77
+ * 子配置,跟随切换改变
78
+ */
79
+ forms?: (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[] | (() => (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[]);
74
80
  }[];
75
81
  }
@@ -174,16 +174,7 @@ export declare const PopsHandler: {
174
174
  /**
175
175
  * 处理返回的配置,针对popsHandler.handleEventDetails
176
176
  */
177
- handleResultDetails(details: any): {
178
- $shadowContainer: HTMLDivElement;
179
- $shadowRoot: ShadowRoot;
180
- animElement: HTMLElement;
181
- popsElement: HTMLElement;
182
- maskElement: HTMLElement;
183
- close: () => void;
184
- hide: () => void;
185
- show: () => void;
186
- };
177
+ handleResultDetails<T extends unknown>(details: T): Omit<T, "type" | "function">;
187
178
  /**
188
179
  * 处理点击事件
189
180
  * @param type 当前按钮类型
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "1.9.5",
3
+ "version": "1.9.7",
4
4
  "description": "弹窗库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Pops.ts CHANGED
@@ -83,7 +83,7 @@ class Pops {
83
83
  /** 配置 */
84
84
  config = {
85
85
  /** 版本号 */
86
- version: "2024.12.8",
86
+ version: "2025.1.1",
87
87
  cssText: {
88
88
  /** 主CSS */
89
89
  index: indexCSS,
@@ -16,7 +16,7 @@ export class PopsDrawer {
16
16
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
17
17
  config = popsUtils.assign(config, details);
18
18
  config = PopsHandler.handleOnly(PopsType, config);
19
-
19
+
20
20
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
21
21
  PopsHandler.handleInit($shadowRoot, [
22
22
  pops.config.cssText.index,
@@ -121,7 +121,6 @@ export class PopsDrawer {
121
121
  $shadowContainer,
122
122
  $shadowRoot,
123
123
  PopsType,
124
-
125
124
  $anim,
126
125
  $pops,
127
126
  $mask!,
@@ -243,11 +242,8 @@ export class PopsDrawer {
243
242
 
244
243
  PopsHandler.handlePush(PopsType, {
245
244
  guid: guid,
246
-
247
245
  animElement: $anim,
248
-
249
246
  popsElement: $pops,
250
-
251
247
  maskElement: $mask!,
252
248
  $shadowContainer: $shadowContainer,
253
249
  $shadowRoot: $shadowRoot,
@@ -1325,6 +1325,7 @@ export const PanelHandleContentDetails = () => {
1325
1325
  * @param formConfig
1326
1326
  */
1327
1327
  createSectionContainerItem_select(formConfig: PopsPanelSelectDetails<any>) {
1328
+ const that = this;
1328
1329
  let liElement = document.createElement("li");
1329
1330
  (liElement as any)["__formConfig__"] = formConfig;
1330
1331
  this.setElementClassName(liElement, formConfig.className);
@@ -1357,6 +1358,7 @@ export const PanelHandleContentDetails = () => {
1357
1358
  $eleKey: {
1358
1359
  disable: "__disable__",
1359
1360
  value: "__value__",
1361
+ forms: "__forms__",
1360
1362
  },
1361
1363
  $data: {
1362
1364
  defaultValue: formConfig.getValue(),
@@ -1387,14 +1389,23 @@ export const PanelHandleContentDetails = () => {
1387
1389
  getNodeValue($ele: HTMLElement, key: string) {
1388
1390
  return Reflect.get($ele, key);
1389
1391
  },
1392
+ /**
1393
+ * 禁用选项
1394
+ */
1390
1395
  disable() {
1391
1396
  this.$ele.select.setAttribute("disabled", "true");
1392
1397
  this.$ele.panelSelect.classList.add("pops-panel-select-disable");
1393
1398
  },
1399
+ /**
1400
+ * 取消禁用
1401
+ */
1394
1402
  notDisable() {
1395
1403
  this.$ele.select.removeAttribute("disabled");
1396
1404
  this.$ele.panelSelect.classList.remove("pops-panel-select-disable");
1397
1405
  },
1406
+ /**
1407
+ * 判断是否禁用
1408
+ */
1398
1409
  isDisabled() {
1399
1410
  return (
1400
1411
  this.$ele.select.hasAttribute("disabled") ||
@@ -1403,6 +1414,9 @@ export const PanelHandleContentDetails = () => {
1403
1414
  )
1404
1415
  );
1405
1416
  },
1417
+ /**
1418
+ * 初始化选项
1419
+ */
1406
1420
  initOption() {
1407
1421
  formConfig.data.forEach((dataItem) => {
1408
1422
  // 初始化默认选中
@@ -1417,13 +1431,24 @@ export const PanelHandleContentDetails = () => {
1417
1431
  this.$eleKey.disable,
1418
1432
  dataItem.disable
1419
1433
  );
1434
+ this.setNodeValue(
1435
+ optionElement,
1436
+ this.$eleKey.forms,
1437
+ dataItem.forms
1438
+ );
1420
1439
  if (dataItem.value === this.$data.defaultValue) {
1421
- optionElement.setAttribute("selected", "true");
1440
+ this.setOptionSelected(optionElement);
1422
1441
  }
1423
1442
  optionElement.innerText = dataItem.text;
1424
1443
  this.$ele.select.appendChild(optionElement);
1425
1444
  });
1426
1445
  },
1446
+ /**
1447
+ * 设置选项选中
1448
+ */
1449
+ setOptionSelected($option: HTMLOptionElement) {
1450
+ $option.setAttribute("selected", "true");
1451
+ },
1427
1452
  /** 检测所有option并设置禁用状态 */
1428
1453
  setSelectOptionsDisableStatus() {
1429
1454
  if (this.$ele.select.options && this.$ele.select.options.length) {
@@ -1453,9 +1478,14 @@ export const PanelHandleContentDetails = () => {
1453
1478
  getSelectOptionInfo($option: HTMLOptionElement) {
1454
1479
  let optionValue = this.getNodeValue($option, this.$eleKey.value);
1455
1480
  let optionText = $option.innerText || $option.textContent!;
1481
+ let optionForms = this.getNodeValue(
1482
+ $option,
1483
+ this.$eleKey.forms
1484
+ ) as (typeof formConfig.data)[0]["forms"];
1456
1485
  return {
1457
1486
  value: optionValue,
1458
1487
  text: optionText,
1488
+ forms: optionForms,
1459
1489
  $option: $option,
1460
1490
  };
1461
1491
  },
@@ -1464,18 +1494,44 @@ export const PanelHandleContentDetails = () => {
1464
1494
  */
1465
1495
  setChangeEvent() {
1466
1496
  popsDOMUtils.on(this.$ele.select, "change", void 0, (event) => {
1497
+ let $isSelectedElement = (event as any).target[
1498
+ (event as any).target.selectedIndex
1499
+ ] as HTMLOptionElement;
1500
+ let selectInfo = this.getSelectOptionInfo($isSelectedElement);
1467
1501
  this.setSelectOptionsDisableStatus();
1468
1502
  if (typeof formConfig.callback === "function") {
1469
- let $isSelectedElement = (event as any).target[
1470
- (event as any).target.selectedIndex
1471
- ] as HTMLOptionElement;
1472
- let selectInfo = this.getSelectOptionInfo($isSelectedElement);
1473
1503
  formConfig.callback(
1474
1504
  event as any,
1475
1505
  selectInfo.value,
1476
1506
  selectInfo.text
1477
1507
  );
1478
1508
  }
1509
+ let forms =
1510
+ typeof selectInfo.forms === "function"
1511
+ ? selectInfo.forms()
1512
+ : selectInfo.forms;
1513
+ if (Array.isArray(forms)) {
1514
+ /* 如果成功创建,加入到中间容器中 */
1515
+ let childUListClassName = "pops-panel-select-child-forms";
1516
+ // 移除旧的元素
1517
+ while (liElement.nextElementSibling) {
1518
+ if (
1519
+ liElement.nextElementSibling.classList.contains(
1520
+ childUListClassName
1521
+ )
1522
+ ) {
1523
+ liElement.nextElementSibling.remove();
1524
+ } else {
1525
+ break;
1526
+ }
1527
+ }
1528
+ let $childUList = document.createElement("ul");
1529
+ $childUList.className = childUListClassName;
1530
+ popsDOMUtils.after(liElement, $childUList);
1531
+ that.uListContainerAddItem(formConfig as any, {
1532
+ ulElement: $childUList,
1533
+ });
1534
+ }
1479
1535
  });
1480
1536
  },
1481
1537
  /**
@@ -1852,6 +1908,19 @@ export const PanelHandleContentDetails = () => {
1852
1908
  Reflect.set($item, "data-info", dataInfo);
1853
1909
  return $item;
1854
1910
  }
1911
+ /**
1912
+ * 设置选择项的禁用状态
1913
+ */
1914
+ function setSelectItemDisabled($el: HTMLElement) {
1915
+ $el.setAttribute("aria-disabled", "true");
1916
+ }
1917
+ /**
1918
+ * 移除选择项的禁用状态
1919
+ */
1920
+ function removeSelectItemDisabled($el: HTMLElement) {
1921
+ $el.removeAttribute("aria-disabled");
1922
+ $el.removeAttribute("disabled");
1923
+ }
1855
1924
  /**
1856
1925
  * 设置选择项的点击事件
1857
1926
  */
@@ -1861,6 +1930,9 @@ export const PanelHandleContentDetails = () => {
1861
1930
  "click",
1862
1931
  (event) => {
1863
1932
  popsDOMUtils.preventEvent(event);
1933
+ if ($ele.hasAttribute("disabled") || $ele.ariaDisabled) {
1934
+ return;
1935
+ }
1864
1936
  if (typeof formConfig.clickCallBack === "function") {
1865
1937
  let clickResult = formConfig.clickCallBack(
1866
1938
  event,
@@ -1931,7 +2003,6 @@ export const PanelHandleContentDetails = () => {
1931
2003
  --el-fill-color-light: #f5f7fa;
1932
2004
  }
1933
2005
  .select-item{
1934
- cursor: pointer;
1935
2006
  cursor: pointer;
1936
2007
  font-size: var(--el-font-size-base);
1937
2008
  padding: 0 32px 0 20px;
@@ -1944,6 +2015,12 @@ export const PanelHandleContentDetails = () => {
1944
2015
  line-height: 34px;
1945
2016
  box-sizing: border-box;
1946
2017
  }
2018
+ .select-item[aria-disabled],
2019
+ .select-item[disabled]{
2020
+ cursor: not-allowed;
2021
+ color: #a8abb2;
2022
+ background: unset;
2023
+ }
1947
2024
  .select-item:hover{
1948
2025
  background-color: var(--el-fill-color-light);
1949
2026
  }
@@ -1986,6 +2063,17 @@ export const PanelHandleContentDetails = () => {
1986
2063
  $selectContainer.appendChild($select);
1987
2064
  // 设置每一项的点击事件
1988
2065
  setSelectElementClickEvent($select);
2066
+ // 设置禁用状态
2067
+ if (
2068
+ typeof item.disable === "function" &&
2069
+ item.disable(item.value)
2070
+ ) {
2071
+ setSelectItemDisabled($select);
2072
+ // 后续不设置元素的选中状态
2073
+ return;
2074
+ }
2075
+ // 移除禁用状态
2076
+ removeSelectItemDisabled($select);
1989
2077
  let findValue = selectedInfo.find(
1990
2078
  (value) => value.value === item.value
1991
2079
  );
@@ -187,6 +187,7 @@ export const PopsPanelConfig = (): DeepRequired<PopsPanelDetails> => {
187
187
  disable() {
188
188
  return false;
189
189
  },
190
+ forms: [],
190
191
  },
191
192
  {
192
193
  value: "text",
@@ -194,6 +195,7 @@ export const PopsPanelConfig = (): DeepRequired<PopsPanelDetails> => {
194
195
  disable() {
195
196
  return false;
196
197
  },
198
+ forms: [],
197
199
  },
198
200
  {
199
201
  value: "html",
@@ -201,6 +203,7 @@ export const PopsPanelConfig = (): DeepRequired<PopsPanelDetails> => {
201
203
  disable() {
202
204
  return false;
203
205
  },
206
+ forms: [],
204
207
  },
205
208
  ],
206
209
  },
@@ -1,4 +1,6 @@
1
1
  import type { PopsPanelCommonDetails } from "./commonType";
2
+ import type { PopsPanelFormsDetails } from "./formsType";
3
+ import type { PopsPanelFormsTotalDetails } from "./indexType";
2
4
 
3
5
  /**
4
6
  * pops.panel的 select
@@ -80,5 +82,11 @@ export interface PopsPanelSelectDetails<T = any>
80
82
  * + select元素触发change事件
81
83
  */
82
84
  disable?(value: T): boolean;
85
+ /**
86
+ * 子配置,跟随切换改变
87
+ */
88
+ forms?:
89
+ | (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[]
90
+ | (() => (PopsPanelFormsDetails | PopsPanelFormsTotalDetails)[]);
83
91
  }[];
84
92
  }
@@ -34,7 +34,12 @@ export class ToolTip {
34
34
  this.$data.guid = guid;
35
35
  this.$el.$shadowContainer = ShadowInfo.$shadowContainer;
36
36
  this.$el.$shadowRoot = ShadowInfo.$shadowRoot;
37
-
37
+ this.show = this.show.bind(this);
38
+ this.close = this.close.bind(this);
39
+ this.toolTipAnimationFinishEvent =
40
+ this.toolTipAnimationFinishEvent.bind(this);
41
+ this.toolTipMouseEnterEvent = this.toolTipMouseEnterEvent.bind(this);
42
+ this.toolTipMouseLeaveEvent = this.toolTipMouseLeaveEvent.bind(this);
38
43
  this.init();
39
44
  }
40
45
  init() {
@@ -328,7 +333,7 @@ export class ToolTip {
328
333
  popsDOMUtils.on(
329
334
  this.$data.config.target,
330
335
  this.$data.config.triggerShowEventName,
331
- this.show.bind(this),
336
+ this.show,
332
337
  this.$data.config.eventOption
333
338
  );
334
339
  }
@@ -339,7 +344,7 @@ export class ToolTip {
339
344
  popsDOMUtils.off(
340
345
  this.$data.config.target,
341
346
  this.$data.config.triggerShowEventName,
342
- this.show.bind(this),
347
+ this.show,
343
348
  {
344
349
  capture: true,
345
350
  }
@@ -400,7 +405,7 @@ export class ToolTip {
400
405
  popsDOMUtils.on(
401
406
  this.$data.config.target,
402
407
  this.$data.config.triggerCloseEventName,
403
- this.close.bind(this),
408
+ this.close,
404
409
  this.$data.config.eventOption
405
410
  );
406
411
  }
@@ -411,7 +416,7 @@ export class ToolTip {
411
416
  popsDOMUtils.off(
412
417
  this.$data.config.target,
413
418
  this.$data.config.triggerCloseEventName,
414
- this.close.bind(this),
419
+ this.close,
415
420
  {
416
421
  capture: true,
417
422
  }
@@ -450,7 +455,7 @@ export class ToolTip {
450
455
  popsDOMUtils.on(
451
456
  this.$el.$toolTip,
452
457
  popsDOMUtils.getAnimationEndNameList(),
453
- this.toolTipAnimationFinishEvent.bind(this)
458
+ this.toolTipAnimationFinishEvent
454
459
  );
455
460
  }
456
461
  /**
@@ -460,7 +465,7 @@ export class ToolTip {
460
465
  popsDOMUtils.off(
461
466
  this.$el.$toolTip,
462
467
  popsDOMUtils.getAnimationEndNameList(),
463
- this.toolTipAnimationFinishEvent.bind(this)
468
+ this.toolTipAnimationFinishEvent
464
469
  );
465
470
  }
466
471
  /**
@@ -484,7 +489,7 @@ export class ToolTip {
484
489
  popsDOMUtils.on(
485
490
  this.$el.$toolTip,
486
491
  "mouseenter touchstart",
487
- this.toolTipMouseEnterEvent.bind(this),
492
+ this.toolTipMouseEnterEvent,
488
493
  this.$data.config.eventOption
489
494
  );
490
495
  }
@@ -495,7 +500,7 @@ export class ToolTip {
495
500
  popsDOMUtils.off(
496
501
  this.$el.$toolTip,
497
502
  "mouseenter touchstart",
498
- this.toolTipMouseEnterEvent.bind(this),
503
+ this.toolTipMouseEnterEvent,
499
504
  this.$data.config.eventOption
500
505
  );
501
506
  }
@@ -513,7 +518,7 @@ export class ToolTip {
513
518
  popsDOMUtils.on(
514
519
  this.$el.$toolTip,
515
520
  "mouseleave touchend",
516
- this.toolTipMouseLeaveEvent.bind(this),
521
+ this.toolTipMouseLeaveEvent,
517
522
  this.$data.config.eventOption
518
523
  );
519
524
  }
@@ -524,7 +529,7 @@ export class ToolTip {
524
529
  popsDOMUtils.off(
525
530
  this.$el.$toolTip,
526
531
  "mouseleave touchend",
527
- this.toolTipMouseLeaveEvent.bind(this),
532
+ this.toolTipMouseLeaveEvent,
528
533
  this.$data.config.eventOption
529
534
  );
530
535
  }
@@ -496,16 +496,7 @@ export const PopsHandler = {
496
496
  /**
497
497
  * 处理返回的配置,针对popsHandler.handleEventDetails
498
498
  */
499
- handleResultDetails(details: any): {
500
- $shadowContainer: HTMLDivElement;
501
- $shadowRoot: ShadowRoot;
502
- animElement: HTMLElement;
503
- popsElement: HTMLElement;
504
- maskElement: HTMLElement;
505
- close: () => void;
506
- hide: () => void;
507
- show: () => void;
508
- } {
499
+ handleResultDetails<T extends any>(details: T): Omit<T, "type" | "function"> {
509
500
  let resultDetails = Object.assign({}, details);
510
501
  popsUtils.delete(resultDetails, "type");
511
502
  popsUtils.delete(resultDetails, "function");