@whitesev/pops 3.0.1 → 3.1.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.
Files changed (48) hide show
  1. package/dist/index.amd.js +974 -546
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.amd.min.js +1 -1
  4. package/dist/index.amd.min.js.map +1 -1
  5. package/dist/index.cjs.js +974 -546
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.cjs.min.js +1 -1
  8. package/dist/index.cjs.min.js.map +1 -1
  9. package/dist/index.esm.js +974 -546
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +974 -546
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.system.js +974 -546
  18. package/dist/index.system.js.map +1 -1
  19. package/dist/index.system.min.js +1 -1
  20. package/dist/index.system.min.js.map +1 -1
  21. package/dist/index.umd.js +974 -546
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/index.umd.min.js +1 -1
  24. package/dist/index.umd.min.js.map +1 -1
  25. package/dist/types/src/Pops.d.ts +89 -49
  26. package/dist/types/src/components/panel/handlerComponents.d.ts +205 -60
  27. package/dist/types/src/components/panel/index.d.ts +1 -1
  28. package/dist/types/src/components/panel/types/components-select.d.ts +42 -5
  29. package/dist/types/src/components/tooltip/index.d.ts +2 -2
  30. package/dist/types/src/components/tooltip/types/index.d.ts +3 -3
  31. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +22 -0
  32. package/dist/types/src/utils/PopsDOMUtils.d.ts +29 -29
  33. package/dist/types/src/utils/PopsInstanceUtils.d.ts +1 -1
  34. package/package.json +4 -4
  35. package/src/components/folder/index.ts +3 -3
  36. package/src/components/panel/defaultConfig.ts +278 -228
  37. package/src/components/panel/handlerComponents.ts +558 -206
  38. package/src/components/panel/index.css +67 -12
  39. package/src/components/panel/types/components-select.ts +42 -5
  40. package/src/components/rightClickMenu/index.css +1 -1
  41. package/src/components/rightClickMenu/index.ts +3 -3
  42. package/src/components/tooltip/defaultConfig.ts +2 -2
  43. package/src/components/tooltip/index.ts +4 -4
  44. package/src/components/tooltip/types/index.ts +3 -3
  45. package/src/css/common.css +4 -4
  46. package/src/types/PopsDOMUtilsEventType.d.ts +22 -0
  47. package/src/utils/PopsDOMUtils.ts +90 -59
  48. package/src/utils/PopsInstanceUtils.ts +5 -5
@@ -459,7 +459,7 @@ export const PanelHandlerComponents = () => {
459
459
  * 获取中间容器的元素<li>
460
460
  * @param viewConfig
461
461
  */
462
- createSectionContainerItem_slider_new(viewConfig: PopsPanelSliderConfig) {
462
+ createSectionContainerItem_slider(viewConfig: PopsPanelSliderConfig) {
463
463
  const $li = popsDOMUtils.createElement("li");
464
464
  Reflect.set($li, this.$data.nodeStoreConfigKey, viewConfig);
465
465
  this.setElementClassName($li, viewConfig.className);
@@ -1329,7 +1329,7 @@ export const PanelHandlerComponents = () => {
1329
1329
  /**
1330
1330
  * 主动触发输入框改变事件
1331
1331
  */
1332
- triggerValueChange() {
1332
+ emitValueChange() {
1333
1333
  this.$el.input.dispatchEvent(new Event("input"));
1334
1334
  },
1335
1335
  /**
@@ -1486,12 +1486,212 @@ export const PanelHandlerComponents = () => {
1486
1486
  </div>
1487
1487
  `
1488
1488
  );
1489
+ const $itemLeftContainer = $li.querySelector<HTMLElement>(".pops-panel-item-left-text")!;
1490
+ const $container = $li.querySelector<HTMLElement>(".pops-panel-select")!;
1491
+ const $select = $li.querySelector<HTMLSelectElement>(".pops-panel-select select")!;
1492
+ const width = (typeof viewConfig.width === "number" ? `${viewConfig.width}px` : viewConfig.width) ?? "200px";
1493
+ popsDOMUtils.css($container, "width", width);
1494
+ const mode = viewConfig.mode ?? "native";
1489
1495
  let handler;
1490
- if (viewConfig.useDialog) {
1496
+ if (mode === "native") {
1497
+ const PopsPanelSelectNative = {
1498
+ [Symbol.toStringTag]: "PopsPanelSelectNative",
1499
+ $el: {
1500
+ itemLeftTextContainer: $itemLeftContainer,
1501
+ $container: $container,
1502
+ $select: $select,
1503
+ },
1504
+ $eleKey: {
1505
+ disable: "__disable__",
1506
+ value: "__value__",
1507
+ viewConfig: "data-view-config",
1508
+ },
1509
+ $data: {
1510
+ data: [] as PopsPanelSelectDataOption<any>[],
1511
+ defaultValue: viewConfig.getValue(),
1512
+ },
1513
+ init() {
1514
+ this.$el.$container.setAttribute("data-mode", mode);
1515
+ this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
1516
+ popsDOMUtils.addClassName(this.$el.$container, PopsCommonCSSClassName.userSelectNone);
1517
+ this.initOption();
1518
+ this.onValueChange();
1519
+ this.onClick();
1520
+ const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
1521
+ if (disabled) {
1522
+ this.disable();
1523
+ }
1524
+ },
1525
+ /**
1526
+ * 给option元素设置属性
1527
+ * @param $ele
1528
+ * @param key
1529
+ * @param value
1530
+ */
1531
+ setNodeValue($ele: HTMLElement, key: string, value: any) {
1532
+ Reflect.set($ele, key, value);
1533
+ },
1534
+ /**
1535
+ * 获取option元素上设置的属性
1536
+ * @param $ele
1537
+ * @param value
1538
+ * @param key
1539
+ */
1540
+ getNodeValue($ele: HTMLElement, key: string) {
1541
+ return Reflect.get($ele, key);
1542
+ },
1543
+ /**
1544
+ * 禁用选项
1545
+ */
1546
+ disable() {
1547
+ this.$el.$select.setAttribute("disabled", "true");
1548
+ popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
1549
+ popsDOMUtils.addClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
1550
+ },
1551
+ /**
1552
+ * 取消禁用
1553
+ */
1554
+ notDisable() {
1555
+ this.$el.$select.removeAttribute("disabled");
1556
+ popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
1557
+ popsDOMUtils.removeClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
1558
+ },
1559
+ /**
1560
+ * 判断是否禁用
1561
+ */
1562
+ isDisabled() {
1563
+ return (
1564
+ this.$el.$select.hasAttribute("disabled") ||
1565
+ popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable")
1566
+ );
1567
+ },
1568
+ /**
1569
+ * 初始化选项
1570
+ */
1571
+ initOption() {
1572
+ this.$data.data.forEach((dataItem) => {
1573
+ // 初始化默认选中
1574
+ const optionElement = popsDOMUtils.createElement("option");
1575
+ this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
1576
+ this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
1577
+ this.setNodeValue(optionElement, this.$eleKey.viewConfig, dataItem.views);
1578
+ if (dataItem.value === this.$data.defaultValue) {
1579
+ this.setOptionSelected(optionElement);
1580
+ }
1581
+ if (typeof dataItem.text === "function") {
1582
+ optionElement.innerText = dataItem.text(dataItem.value, dataItem);
1583
+ } else {
1584
+ optionElement.innerText = dataItem.text;
1585
+ }
1586
+ this.$el.$select.appendChild(optionElement);
1587
+ });
1588
+ },
1589
+ /**
1590
+ * 设置选项选中
1591
+ * @param $option
1592
+ */
1593
+ setOptionSelected($option: HTMLOptionElement) {
1594
+ $option.setAttribute("selected", "true");
1595
+ },
1596
+ /**
1597
+ * 检测所有option并设置禁用状态
1598
+ */
1599
+ setSelectOptionsDisableStatus() {
1600
+ if (this.$el.$select.options && this.$el.$select.options.length) {
1601
+ Array.from(this.$el.$select.options).forEach((optionItem) => {
1602
+ this.setOptionDisableStatus(optionItem);
1603
+ });
1604
+ }
1605
+ },
1606
+ /**
1607
+ * 设置禁用状态
1608
+ * @param $option
1609
+ */
1610
+ setOptionDisableStatus($option: HTMLOptionElement) {
1611
+ let disable = false;
1612
+ const optionDisableAttr = this.getNodeValue($option, this.$eleKey.disable);
1613
+ if (optionDisableAttr === "function") {
1614
+ const value = this.getNodeValue($option, this.$eleKey.value);
1615
+ disable = Boolean(optionDisableAttr(value));
1616
+ }
1617
+ if (disable) {
1618
+ $option.setAttribute("disabled", "true");
1619
+ } else {
1620
+ $option.removeAttribute("disabled");
1621
+ }
1622
+ },
1623
+ /**
1624
+ * 获取option上的信息
1625
+ * @param $option
1626
+ */
1627
+ getSelectOptionInfo($option: HTMLOptionElement) {
1628
+ const optionValue = this.getNodeValue($option, this.$eleKey.value);
1629
+ const optionText = $option.innerText || $option.textContent!;
1630
+ const views = this.getNodeValue($option, this.$eleKey.viewConfig) as NonNullable<
1631
+ PopsPanelSelectDataOption<any>["views"]
1632
+ >;
1633
+ return {
1634
+ value: optionValue,
1635
+ text: optionText,
1636
+ views: views,
1637
+ $option: $option,
1638
+ };
1639
+ },
1640
+ /**
1641
+ * 监听选择内容改变
1642
+ */
1643
+ onValueChange() {
1644
+ popsDOMUtils.on<PointerEvent | TouchEvent>(this.$el.$select, "change", () => {
1645
+ const $isSelectedElement = this.$el.$select[this.$el.$select.selectedIndex] as HTMLOptionElement;
1646
+ const selectInfo = this.getSelectOptionInfo($isSelectedElement);
1647
+ this.setSelectOptionsDisableStatus();
1648
+ if (typeof viewConfig.callback === "function") {
1649
+ viewConfig.callback(selectInfo);
1650
+ }
1651
+ const views = typeof selectInfo.views === "function" ? selectInfo.views() : selectInfo.views;
1652
+ if (Array.isArray(views)) {
1653
+ // 如果成功创建,加入到中间容器中
1654
+ const childUListClassName = "pops-panel-select-child-forms";
1655
+ // 移除旧的元素
1656
+ while ($li.nextElementSibling) {
1657
+ if ($li.nextElementSibling.classList.contains(childUListClassName)) {
1658
+ $li.nextElementSibling.remove();
1659
+ } else {
1660
+ break;
1661
+ }
1662
+ }
1663
+ const $childUList = popsDOMUtils.createElement("ul");
1664
+ $childUList.className = childUListClassName;
1665
+ popsDOMUtils.after($li, $childUList);
1666
+ that.uListContainerAddItem(viewConfig, {
1667
+ ulElement: $childUList,
1668
+ });
1669
+ }
1670
+ });
1671
+ },
1672
+ /**
1673
+ * 监听点击事件
1674
+ */
1675
+ onClick() {
1676
+ popsDOMUtils.on(this.$el.$select, "click", void 0, (event) => {
1677
+ this.setSelectOptionsDisableStatus();
1678
+ if (typeof viewConfig.clickCallBack === "function") {
1679
+ const $isSelectedElement = this.$el.$select[this.$el.$select.selectedIndex] as HTMLOptionElement;
1680
+ const selectInfo = this.getSelectOptionInfo($isSelectedElement);
1681
+ viewConfig.clickCallBack(event, selectInfo);
1682
+ }
1683
+ });
1684
+ },
1685
+ };
1686
+
1687
+ PopsPanelSelectNative.init();
1688
+ Reflect.set($li, "data-select", PopsPanelSelectNative);
1689
+ handler = PopsPanelSelectNative;
1690
+ } else if (mode === "dialog") {
1491
1691
  const PopsPanelSelect = {
1492
1692
  [Symbol.toStringTag]: "PopsPanelSelect",
1493
1693
  $el: {
1494
- itemLeftTextContainer: $li.querySelector<HTMLElement>(".pops-panel-item-left-text"),
1694
+ $itemLeftContainer: $itemLeftContainer,
1495
1695
  /** 选择框容器 */
1496
1696
  $container: void 0 as any as HTMLElement,
1497
1697
  /** 选择框包裹的容器 */
@@ -1548,7 +1748,8 @@ export const PanelHandlerComponents = () => {
1548
1748
  initDefault() {
1549
1749
  this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
1550
1750
  this.$data.data.forEach((dataItem) => {
1551
- if (this.$data.defaultValue.includes(dataItem.value)) {
1751
+ const flag = this.$data.defaultValue.includes(dataItem.value);
1752
+ if (flag) {
1552
1753
  // 初始化选中的配置
1553
1754
  this.resetCurrentSelectedInfo();
1554
1755
  this.updateSelectedInfo(dataItem);
@@ -1557,7 +1758,8 @@ export const PanelHandlerComponents = () => {
1557
1758
  },
1558
1759
  /** 初始化$ele变量 */
1559
1760
  initEl() {
1560
- this.$el.$container = $li.querySelector<HTMLElement>(".pops-panel-select")!;
1761
+ this.$el.$container = $container;
1762
+ this.$el.$container.setAttribute("data-mode", mode);
1561
1763
  PopsSafeUtils.setSafeHTML(
1562
1764
  this.$el.$container,
1563
1765
  /*html*/ `
@@ -1663,23 +1865,23 @@ export const PanelHandlerComponents = () => {
1663
1865
  * 禁用选项容器
1664
1866
  */
1665
1867
  disable() {
1666
- popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-multiple-disable");
1667
- popsDOMUtils.addClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
1868
+ popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
1869
+ popsDOMUtils.addClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
1668
1870
  },
1669
1871
  /**
1670
1872
  * 取消禁用选项容器
1671
1873
  */
1672
1874
  cancleDisable() {
1673
- popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-multiple-disable");
1674
- popsDOMUtils.removeClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
1875
+ popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
1876
+ popsDOMUtils.removeClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
1675
1877
  },
1676
1878
  /**
1677
1879
  * 判断当前是否已禁用选项容器
1678
1880
  */
1679
1881
  isDisabled() {
1680
1882
  return (
1681
- popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-multiple-disable") ||
1682
- popsDOMUtils.containsClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled)
1883
+ popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable") ||
1884
+ popsDOMUtils.containsClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled)
1683
1885
  );
1684
1886
  },
1685
1887
  /**
@@ -1915,23 +2117,22 @@ export const PanelHandlerComponents = () => {
1915
2117
  isItemSelected($el: HTMLElement): boolean {
1916
2118
  return $el.classList.contains("select-item-is-selected");
1917
2119
  },
2120
+ /**
2121
+ * 获取项上存储的信息
2122
+ * @param $el 选项元素
2123
+ */
2124
+ getItemDataOption($el: HTMLElement): PopsPanelSelectDataOption<any> {
2125
+ return Reflect.get($el, "data-info");
2126
+ },
1918
2127
  /**
1919
2128
  * 添加选中信息
1920
2129
  * @param data 选择项的数据
1921
- * @param [triggerValueChangeCallBack=true] 主动触发值改变回调
1922
2130
  */
1923
2131
  addSelectedItemInfo(data: PopsPanelSelectDataOption<any>) {
1924
2132
  this.resetCurrentSelectedInfo();
1925
2133
  this.updateSelectedInfo(data);
1926
2134
  this.onValueChangeCallback(data);
1927
2135
  },
1928
- /**
1929
- * 获取项上存储的信息
1930
- * @param $el 选项元素
1931
- */
1932
- getItemDataOption($el: HTMLElement): PopsPanelSelectDataOption<any> {
1933
- return Reflect.get($el, "data-info");
1934
- },
1935
2136
  /**
1936
2137
  * 移除选中信息
1937
2138
  * @param data 选择项的数据
@@ -2090,219 +2291,370 @@ export const PanelHandlerComponents = () => {
2090
2291
  }
2091
2292
  });
2092
2293
  },
2093
- /** 显示输入框 */
2094
- showInputWrapper() {
2095
- popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
2096
- },
2097
- /** 隐藏输入框 */
2098
- hideInputWrapper() {
2099
- popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
2100
- },
2101
- /** 显示palceholder */
2102
- showPlaceHolderWrapper() {
2103
- popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
2104
- },
2105
- /** 隐藏palceholder */
2106
- hidePlaceHolderWrapper() {
2107
- popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
2108
- },
2109
- };
2110
- PopsPanelSelect.init();
2111
- Reflect.set($li, "data-select", PopsPanelSelect);
2112
- handler = PopsPanelSelect;
2113
- } else {
2114
- const PopsPanelSelectNative = {
2115
- [Symbol.toStringTag]: "PopsPanelSelectNative",
2116
- $el: {
2117
- itemLeftTextContainer: $li.querySelector<HTMLElement>(".pops-panel-item-left-text"),
2118
- panelSelect: $li.querySelector<HTMLDivElement>(".pops-panel-select")!,
2119
- select: $li.querySelector<HTMLSelectElement>(".pops-panel-select select")!,
2120
- },
2121
- $eleKey: {
2122
- disable: "__disable__",
2123
- value: "__value__",
2124
- viewConfig: "data-view-config",
2125
- },
2126
- $data: {
2127
- data: [] as PopsPanelSelectDataOption<any>[],
2128
- defaultValue: viewConfig.getValue(),
2129
- },
2130
- init() {
2131
- this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
2132
- popsDOMUtils.addClassName(this.$el.panelSelect, PopsCommonCSSClassName.userSelectNone);
2133
- this.initOption();
2134
- this.onValueChange();
2135
- this.onClick();
2136
- const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
2137
- if (disabled) {
2138
- this.disable();
2294
+ /** 显示输入框 */
2295
+ showInputWrapper() {
2296
+ popsDOMUtils.cssShow(this.$el.$selectedInputWrapper);
2297
+ },
2298
+ /** 隐藏输入框 */
2299
+ hideInputWrapper() {
2300
+ popsDOMUtils.cssHide(this.$el.$selectedInputWrapper, true);
2301
+ },
2302
+ /** 显示palceholder */
2303
+ showPlaceHolderWrapper() {
2304
+ popsDOMUtils.cssShow(this.$el.$selectedPlaceHolderWrapper);
2305
+ },
2306
+ /** 隐藏palceholder */
2307
+ hidePlaceHolderWrapper() {
2308
+ popsDOMUtils.cssHide(this.$el.$selectedPlaceHolderWrapper, true);
2309
+ },
2310
+ };
2311
+ PopsPanelSelect.init();
2312
+ Reflect.set($li, "data-select", PopsPanelSelect);
2313
+ handler = PopsPanelSelect;
2314
+ } else if (mode === "horizontal") {
2315
+ const PopsPanelSelectHorizontal = {
2316
+ [Symbol.toStringTag]: "PopsPanelSelectHorizontal",
2317
+ $el: {
2318
+ $itemLeftContainer: $itemLeftContainer,
2319
+ /** 选择框容器 */
2320
+ $container: $container,
2321
+ /** 选择框包裹的容器 */
2322
+ $wrapper: void 0 as any as HTMLElement,
2323
+ },
2324
+ $data: {
2325
+ /**
2326
+ * 数据
2327
+ */
2328
+ data: [] as PopsPanelSelectDataOption<any>[],
2329
+ /**
2330
+ * 默认值
2331
+ */
2332
+ defaultValue: viewConfig.getValue(),
2333
+ /**
2334
+ * 选择的信息
2335
+ */
2336
+ selectedData: void 0 as PopsPanelSelectDataOption<any> | undefined,
2337
+ /**
2338
+ * 箭头旋转的属性
2339
+ */
2340
+ rotateKey: "data-show-option",
2341
+ },
2342
+ /** 初始化 */
2343
+ init() {
2344
+ this.initDefault();
2345
+ this.initEl();
2346
+
2347
+ const disabled = typeof viewConfig.disabled === "function" ? viewConfig.disabled() : viewConfig.disabled;
2348
+ if (disabled) {
2349
+ this.disable();
2350
+ }
2351
+ },
2352
+ /** 初始化默认值 */
2353
+ initDefault() {
2354
+ this.$data.data = typeof viewConfig.data === "function" ? viewConfig.data() : viewConfig.data;
2355
+ if (!this.$data.data.length) {
2356
+ throw new Error("PopsPanelSelect: data is empty");
2357
+ }
2358
+ },
2359
+ /** 初始化$ele变量 */
2360
+ initEl() {
2361
+ this.$el.$container.setAttribute("data-mode", mode);
2362
+ PopsSafeUtils.setSafeHTML(
2363
+ this.$el.$container,
2364
+ /*html*/ `
2365
+ <div class="el-select__wrapper">
2366
+ </div>`
2367
+ );
2368
+ this.$el.$wrapper = $li.querySelector<HTMLElement>(".el-select__wrapper")!;
2369
+
2370
+ this.$data.data.forEach((dataItem) => {
2371
+ const $item = this.createSelectItemElement(dataItem);
2372
+ this.onSelectItemClick(dataItem, $item);
2373
+ if (this.$data.defaultValue === dataItem.value) {
2374
+ this.addSelectedItemInfo(dataItem);
2375
+ }
2376
+ this.$el.$wrapper.appendChild($item);
2377
+ });
2378
+ this.updateAllSelectItemStatus();
2379
+ },
2380
+ /**
2381
+ * 禁用选项容器
2382
+ */
2383
+ disable() {
2384
+ popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
2385
+ popsDOMUtils.addClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
2386
+ },
2387
+ /**
2388
+ * 取消禁用选项容器
2389
+ */
2390
+ cancleDisable() {
2391
+ popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
2392
+ popsDOMUtils.removeClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
2393
+ },
2394
+ /**
2395
+ * 判断当前是否已禁用选项容器
2396
+ */
2397
+ isDisabled() {
2398
+ return (
2399
+ popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable") ||
2400
+ popsDOMUtils.containsClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled)
2401
+ );
2402
+ },
2403
+ /**
2404
+ * 创建选择项
2405
+ * @param data 数据
2406
+ */
2407
+ createSelectItemElement(data: PopsPanelSelectDataOption<any>) {
2408
+ const $select = popsDOMUtils.createElement("div", {
2409
+ className: "select-item",
2410
+ innerHTML: /*html*/ `
2411
+ <span class="select-item-text"></span>
2412
+ `,
2413
+ });
2414
+ this.setSelectItemText(data, $select);
2415
+ Reflect.set($select, "data-info", data);
2416
+ return $select;
2417
+ },
2418
+ /**
2419
+ * 设置选择项的文字
2420
+ * @param data 选择项的数据
2421
+ * @param $select 选择项元素
2422
+ */
2423
+ setSelectItemText(data: PopsPanelSelectDataOption<any>, $select: HTMLElement) {
2424
+ const text = typeof data.text === "function" ? data.text(data.value, this.$data.selectedData) : data.text;
2425
+ const $selectSpan = $select.querySelector<HTMLElement>(".select-item-text");
2426
+ if (!$selectSpan) return;
2427
+ if (data.isHTML) {
2428
+ PopsSafeUtils.setSafeHTML($selectSpan, text);
2429
+ } else {
2430
+ $selectSpan.innerText = text;
2431
+ }
2432
+ },
2433
+ /**
2434
+ * 设置选择项点击事件
2435
+ */
2436
+ onSelectItemClick(data: PopsPanelSelectDataOption<any> | undefined, $el: HTMLElement) {
2437
+ popsDOMUtils.on<PointerEvent | MouseEvent>($el, "click", (event) => {
2438
+ popsDOMUtils.preventEvent(event);
2439
+ if (this.isDisabled()) {
2440
+ return;
2441
+ }
2442
+ if (this.isSelectItemDisabled($el)) {
2443
+ // 被禁用了
2444
+ return;
2445
+ }
2446
+ if (typeof viewConfig.clickCallBack === "function") {
2447
+ const clickResult = viewConfig.clickCallBack(event, this.$data.selectedData!);
2448
+ if (typeof clickResult === "boolean" && !clickResult) {
2449
+ return;
2450
+ }
2451
+ } // 修改选中状态
2452
+ if (this.isItemSelected($el)) {
2453
+ // 移除选中
2454
+ this.removeItemSelected($el);
2455
+ this.removeSelectedItemInfo();
2456
+ } else {
2457
+ // 添加选中
2458
+ this.setItemSelected($el);
2459
+ this.addSelectedItemInfo(data!);
2460
+ }
2461
+ });
2462
+ },
2463
+ /**
2464
+ * 选中的值改变的回调
2465
+ * @param data 当前的选中信息
2466
+ */
2467
+ onValueChangeCallback(data?: PopsPanelSelectDataOption<any>, isUpdateSelectItem: boolean = true) {
2468
+ // 动态更新禁用状态、选中状态
2469
+ isUpdateSelectItem && this.updateAllSelectItemStatus();
2470
+ // 触发回调
2471
+ if (typeof viewConfig.callback === "function") {
2472
+ viewConfig.callback(data || this.$data.selectedData!);
2473
+ }
2474
+ },
2475
+ /**
2476
+ * 更新选项弹窗内的所有选项元素的状态
2477
+ *
2478
+ * + 更新禁用状态
2479
+ * + 更新选中状态
2480
+ */
2481
+ updateAllSelectItemStatus() {
2482
+ const allSelectItems = this.getAllSelectItems(false);
2483
+ allSelectItems.forEach(($selectInfo) => {
2484
+ const { data, $select } = $selectInfo;
2485
+ // 更新文字
2486
+ this.setSelectItemText(data, $selectInfo.$select);
2487
+ if (typeof data.disable === "function" && data.disable(data.value, this.$data.selectedData)) {
2488
+ // 移除选中状态
2489
+ this.removeItemSelected($select);
2490
+ // 禁用
2491
+ this.setSelectItemDisabled($select);
2492
+ } else {
2493
+ // 移除禁用状态
2494
+ this.removeSelectItemDisabled($select);
2495
+ }
2496
+ // 根据当前已选择的信息,判断并更新选中状态
2497
+ if (this.$data.selectedData != null && this.$data.selectedData.value === data.value) {
2498
+ // 就是这个项
2499
+ // 设置选中
2500
+ this.setItemSelected($select);
2501
+ } else {
2502
+ // 不是这个项
2503
+ // 移除选中状态
2504
+ this.removeItemSelected($select);
2505
+ }
2506
+ });
2507
+ },
2508
+ /**
2509
+ * 重置所有已选中的项以下状态
2510
+ *
2511
+ * + 更新选项显示的文字
2512
+ * + 移除禁用状态
2513
+ * + 移除选中状态
2514
+ */
2515
+ resetAllSelectedItemStatus() {
2516
+ const allSelectedItems = this.getAllSelectItems(true);
2517
+ if (allSelectedItems.length) {
2518
+ // 移除选中信息
2519
+ this.resetCurrentSelectedInfo();
2139
2520
  }
2521
+ allSelectedItems.forEach(($selectInfo) => {
2522
+ const { data, $select } = $selectInfo;
2523
+ // 更新文字
2524
+ this.setSelectItemText(data, $selectInfo.$select);
2525
+ // 移除选中状态
2526
+ this.removeItemSelected($select);
2527
+ // 取消禁用
2528
+ this.removeSelectItemDisabled($select);
2529
+ });
2140
2530
  },
2141
2531
  /**
2142
- * 给option元素设置属性
2143
- * @param $ele
2144
- * @param key
2145
- * @param value
2532
+ * 添加选中信息
2533
+ * @param data 选择项的数据
2146
2534
  */
2147
- setNodeValue($ele: HTMLElement, key: string, value: any) {
2148
- Reflect.set($ele, key, value);
2535
+ addSelectedItemInfo(data: PopsPanelSelectDataOption<any>) {
2536
+ this.resetCurrentSelectedInfo();
2537
+ this.updateSelectedInfo(data);
2538
+ this.onValueChangeCallback(data);
2149
2539
  },
2150
2540
  /**
2151
- * 获取option元素上设置的属性
2152
- * @param $ele
2153
- * @param value
2154
- * @param key
2541
+ * 移除选中信息
2542
+ * @param data 选择项的数据
2155
2543
  */
2156
- getNodeValue($ele: HTMLElement, key: string) {
2157
- return Reflect.get($ele, key);
2544
+ removeSelectedItemInfo() {
2545
+ // 删除
2546
+ this.updateSelectedInfo();
2547
+ this.onValueChangeCallback();
2158
2548
  },
2159
2549
  /**
2160
- * 禁用选项
2550
+ * 更新选中信息
2551
+ * @param data 数据
2161
2552
  */
2162
- disable() {
2163
- this.$el.select.setAttribute("disabled", "true");
2164
- popsDOMUtils.addClassName(this.$el.panelSelect, "pops-panel-select-disable");
2165
- popsDOMUtils.addClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
2553
+ updateSelectedInfo(data?: PopsPanelSelectDataOption<any>) {
2554
+ // 先删除再赋值
2555
+ this.$data.selectedData = void 0;
2556
+ if (data) {
2557
+ if (data.addCustomInput && data.value.toString() === "") {
2558
+ // 自定义输入框,但是内容是空字符串
2559
+ // 不更新选中信息
2560
+ return;
2561
+ }
2562
+ this.$data.selectedData = data;
2563
+ }
2166
2564
  },
2167
2565
  /**
2168
- * 取消禁用
2566
+ * 从保存的已选中的信息列表中移除目标信息
2169
2567
  */
2170
- notDisable() {
2171
- this.$el.select.removeAttribute("disabled");
2172
- popsDOMUtils.removeClassName(this.$el.panelSelect, "pops-panel-select-disable");
2173
- popsDOMUtils.removeClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
2568
+ resetCurrentSelectedInfo() {
2569
+ this.updateSelectedInfo();
2174
2570
  },
2175
2571
  /**
2176
- * 判断是否禁用
2572
+ * 设置选择项禁用
2573
+ * @param $select 选择项元素
2177
2574
  */
2178
- isDisabled() {
2179
- return (
2180
- this.$el.select.hasAttribute("disabled") ||
2181
- popsDOMUtils.containsClassName(this.$el.panelSelect, "pops-panel-select-disable")
2182
- );
2575
+ setSelectItemDisabled($select: HTMLElement) {
2576
+ $select.setAttribute("aria-disabled", "true");
2577
+ $select.setAttribute("disabled", "true");
2183
2578
  },
2184
2579
  /**
2185
- * 初始化选项
2580
+ * 移除选择项的禁用状态
2581
+ * @param $select 选择项元素
2186
2582
  */
2187
- initOption() {
2188
- this.$data.data.forEach((dataItem) => {
2189
- // 初始化默认选中
2190
- const optionElement = popsDOMUtils.createElement("option");
2191
- this.setNodeValue(optionElement, this.$eleKey.value, dataItem.value);
2192
- this.setNodeValue(optionElement, this.$eleKey.disable, dataItem.disable);
2193
- this.setNodeValue(optionElement, this.$eleKey.viewConfig, dataItem.views);
2194
- if (dataItem.value === this.$data.defaultValue) {
2195
- this.setOptionSelected(optionElement);
2196
- }
2197
- if (typeof dataItem.text === "function") {
2198
- optionElement.innerText = dataItem.text(dataItem.value, dataItem);
2199
- } else {
2200
- optionElement.innerText = dataItem.text;
2201
- }
2202
- this.$el.select.appendChild(optionElement);
2203
- });
2583
+ removeSelectItemDisabled($select: HTMLElement) {
2584
+ $select.removeAttribute("aria-disabled");
2585
+ $select.removeAttribute("disabled");
2204
2586
  },
2205
2587
  /**
2206
- * 设置选项选中
2207
- * @param $option
2588
+ * 判断选择项是否禁用
2589
+ * @param $select 选择项元素
2208
2590
  */
2209
- setOptionSelected($option: HTMLOptionElement) {
2210
- $option.setAttribute("selected", "true");
2591
+ isSelectItemDisabled($select: HTMLElement) {
2592
+ return $select.hasAttribute("disabled") || $select.ariaDisabled;
2211
2593
  },
2212
2594
  /**
2213
- * 检测所有option并设置禁用状态
2595
+ * 设置选择项选中
2596
+ * @param $select 选择项元素(.select-item)
2214
2597
  */
2215
- setSelectOptionsDisableStatus() {
2216
- if (this.$el.select.options && this.$el.select.options.length) {
2217
- Array.from(this.$el.select.options).forEach((optionItem) => {
2218
- this.setOptionDisableStatus(optionItem);
2219
- });
2220
- }
2598
+ setItemSelected($select: HTMLElement) {
2599
+ if (this.isItemSelected($select)) return;
2600
+ $select.classList.add("select__selected-item");
2221
2601
  },
2222
2602
  /**
2223
- * 设置禁用状态
2224
- * @param $option
2603
+ * 移除选择项选中
2604
+ * @param $select 选择项元素(.select-item)
2225
2605
  */
2226
- setOptionDisableStatus($option: HTMLOptionElement) {
2227
- let disable = false;
2228
- const optionDisableAttr = this.getNodeValue($option, this.$eleKey.disable);
2229
- if (optionDisableAttr === "function") {
2230
- const value = this.getNodeValue($option, this.$eleKey.value);
2231
- disable = Boolean(optionDisableAttr(value));
2232
- }
2233
- if (disable) {
2234
- $option.setAttribute("disabled", "true");
2235
- } else {
2236
- $option.removeAttribute("disabled");
2237
- }
2606
+ removeItemSelected($select: HTMLElement) {
2607
+ $select.classList.remove("select__selected-item");
2238
2608
  },
2239
2609
  /**
2240
- * 获取option上的信息
2241
- * @param $option
2610
+ * 判断选择项是否选中
2611
+ * @param $select 选择项元素(.select-item)
2242
2612
  */
2243
- getSelectOptionInfo($option: HTMLOptionElement) {
2244
- const optionValue = this.getNodeValue($option, this.$eleKey.value);
2245
- const optionText = $option.innerText || $option.textContent!;
2246
- const views = this.getNodeValue($option, this.$eleKey.viewConfig) as NonNullable<
2247
- PopsPanelSelectDataOption<any>["views"]
2248
- >;
2249
- return {
2250
- value: optionValue,
2251
- text: optionText,
2252
- views: views,
2253
- $option: $option,
2254
- };
2613
+ isItemSelected($select: HTMLElement) {
2614
+ return $select.classList.contains("select__selected-item");
2255
2615
  },
2256
2616
  /**
2257
- * 监听选择内容改变
2617
+ * 获取所有选项的信息
2618
+ * @param [onlySelected=true] 是否仅获取选中的项的信息
2619
+ * + true (默认)仅获取选中项的信息
2620
+ * + false 获取所有选择项的信息
2258
2621
  */
2259
- onValueChange() {
2260
- popsDOMUtils.on<PointerEvent | TouchEvent>(this.$el.select, "change", () => {
2261
- const $isSelectedElement = this.$el.select[this.$el.select.selectedIndex] as HTMLOptionElement;
2262
- const selectInfo = this.getSelectOptionInfo($isSelectedElement);
2263
- this.setSelectOptionsDisableStatus();
2264
- if (typeof viewConfig.callback === "function") {
2265
- viewConfig.callback(selectInfo);
2266
- }
2267
- const views = typeof selectInfo.views === "function" ? selectInfo.views() : selectInfo.views;
2268
- if (Array.isArray(views)) {
2269
- // 如果成功创建,加入到中间容器中
2270
- const childUListClassName = "pops-panel-select-child-forms";
2271
- // 移除旧的元素
2272
- while ($li.nextElementSibling) {
2273
- if ($li.nextElementSibling.classList.contains(childUListClassName)) {
2274
- $li.nextElementSibling.remove();
2275
- } else {
2276
- break;
2622
+ getAllSelectItems(onlySelected: boolean = true) {
2623
+ return Array.from(this.$el.$wrapper?.querySelectorAll<HTMLElement>(".select-item") ?? [])
2624
+ .map(($select) => {
2625
+ const data = this.getItemDataOption($select);
2626
+ const result = {
2627
+ /** 选项信息数据 */
2628
+ data: data,
2629
+ /** 选项元素 */
2630
+ $select: $select,
2631
+ };
2632
+ if (onlySelected) {
2633
+ // 仅选中
2634
+ const isSelected = this.isItemSelected($select);
2635
+ if (isSelected) {
2636
+ return result;
2277
2637
  }
2638
+ return;
2639
+ } else {
2640
+ return result;
2278
2641
  }
2279
- const $childUList = popsDOMUtils.createElement("ul");
2280
- $childUList.className = childUListClassName;
2281
- popsDOMUtils.after($li, $childUList);
2282
- that.uListContainerAddItem(viewConfig, {
2283
- ulElement: $childUList,
2284
- });
2285
- }
2286
- });
2642
+ })
2643
+ .filter((item) => {
2644
+ return item != null;
2645
+ });
2287
2646
  },
2288
2647
  /**
2289
- * 监听点击事件
2648
+ * 获取项上存储的信息
2649
+ * @param $el 选项元素
2290
2650
  */
2291
- onClick() {
2292
- popsDOMUtils.on(this.$el.select, "click", void 0, (event) => {
2293
- this.setSelectOptionsDisableStatus();
2294
- if (typeof viewConfig.clickCallBack === "function") {
2295
- const $isSelectedElement = this.$el.select[this.$el.select.selectedIndex] as HTMLOptionElement;
2296
- const selectInfo = this.getSelectOptionInfo($isSelectedElement);
2297
- viewConfig.clickCallBack(event, selectInfo);
2298
- }
2299
- });
2651
+ getItemDataOption($el: HTMLElement): PopsPanelSelectDataOption<any> {
2652
+ return Reflect.get($el, "data-info");
2300
2653
  },
2301
2654
  };
2302
-
2303
- PopsPanelSelectNative.init();
2304
- Reflect.set($li, "data-select", PopsPanelSelectNative);
2305
- handler = PopsPanelSelectNative;
2655
+ PopsPanelSelectHorizontal.init();
2656
+ Reflect.set($li, "data-select", PopsPanelSelectHorizontal);
2657
+ handler = PopsPanelSelectHorizontal;
2306
2658
  }
2307
2659
  return {
2308
2660
  $el: $li,
@@ -2357,7 +2709,7 @@ export const PanelHandlerComponents = () => {
2357
2709
  [Symbol.toStringTag]: "PopsPanelSelectMultiple",
2358
2710
  $el: {
2359
2711
  /** 左侧文本容器 */
2360
- itemLeftTextContainer: $li.querySelector<HTMLElement>(".pops-panel-item-left-text"),
2712
+ $itemLeftContainer: $li.querySelector<HTMLElement>(".pops-panel-item-left-text"),
2361
2713
  /** 选择框容器 */
2362
2714
  $container: void 0 as any as HTMLElement,
2363
2715
  /** 选择框包裹的容器 */
@@ -2901,11 +3253,11 @@ export const PanelHandlerComponents = () => {
2901
3253
  /**
2902
3254
  * 从保存的已选中的信息列表中移除目标信息
2903
3255
  * @param data 需要移除的信息
2904
- * @param [triggerValueChangeCallBack=true] 是否触发值改变的回调
3256
+ * @param [emitValueChangeCallBack=true] 是否触发值改变的回调
2905
3257
  * + true (默认)触发值改变的回调
2906
3258
  * + false 不触发值改变的回调
2907
3259
  */
2908
- removeSelectedInfo(data: PopsPanelSelectMultipleDataOption<any>, triggerValueChangeCallBack: boolean = true) {
3260
+ removeSelectedInfo(data: PopsPanelSelectMultipleDataOption<any>, emitValueChangeCallBack: boolean = true) {
2909
3261
  for (let index = 0; index < this.$data.selectedDataList.length; index++) {
2910
3262
  const selectInfo = this.$data.selectedDataList[index];
2911
3263
  if (selectInfo.value === data.value) {
@@ -2913,7 +3265,7 @@ export const PanelHandlerComponents = () => {
2913
3265
  break;
2914
3266
  }
2915
3267
  }
2916
- triggerValueChangeCallBack && this.onValueChange();
3268
+ emitValueChangeCallBack && this.onValueChange();
2917
3269
  },
2918
3270
  /** 显示输入框 */
2919
3271
  showInputWrapper() {
@@ -2943,21 +3295,21 @@ export const PanelHandlerComponents = () => {
2943
3295
  * 禁用标签
2944
3296
  */
2945
3297
  disable() {
2946
- popsDOMUtils.addClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
2947
- popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-multiple-disable");
3298
+ popsDOMUtils.addClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
3299
+ popsDOMUtils.addClassName(this.$el.$container, "pops-panel-select-disable");
2948
3300
  },
2949
3301
  /**
2950
3302
  * 判断是否被禁用
2951
3303
  */
2952
3304
  isDisabled() {
2953
- return popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-multiple-disable");
3305
+ return popsDOMUtils.containsClassName(this.$el.$container, "pops-panel-select-disable");
2954
3306
  },
2955
3307
  /**
2956
3308
  * 取消禁用标签
2957
3309
  */
2958
3310
  cancleDisable() {
2959
- popsDOMUtils.removeClassName(this.$el.itemLeftTextContainer, PopsCommonCSSClassName.textIsDisabled);
2960
- popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-multiple-disable");
3311
+ popsDOMUtils.removeClassName(this.$el.$itemLeftContainer, PopsCommonCSSClassName.textIsDisabled);
3312
+ popsDOMUtils.removeClassName(this.$el.$container, "pops-panel-select-disable");
2961
3313
  },
2962
3314
  };
2963
3315
 
@@ -3344,7 +3696,7 @@ export const PanelHandlerComponents = () => {
3344
3696
  } else {
3345
3697
  leaveViewTransition();
3346
3698
  }
3347
- that.triggerRenderRightContainer($currentSection);
3699
+ that.emitRenderRightContainer($currentSection);
3348
3700
  },
3349
3701
  {
3350
3702
  once: true,
@@ -3391,7 +3743,7 @@ export const PanelHandlerComponents = () => {
3391
3743
  $sectionBodyContainer: $deepMenuMain,
3392
3744
  });
3393
3745
  }
3394
- that.triggerRenderRightContainer($deepMenuSection);
3746
+ that.emitRenderRightContainer($deepMenuSection);
3395
3747
  },
3396
3748
  /** 设置项的点击事件 */
3397
3749
  onLiClick() {
@@ -3442,7 +3794,7 @@ export const PanelHandlerComponents = () => {
3442
3794
  if (componentType === "switch") {
3443
3795
  return this.createSectionContainerItem_switch(viewConfig);
3444
3796
  } else if (componentType === "slider") {
3445
- return this.createSectionContainerItem_slider_new(viewConfig);
3797
+ return this.createSectionContainerItem_slider(viewConfig);
3446
3798
  } else if (componentType === "input") {
3447
3799
  return this.createSectionContainerItem_input(viewConfig);
3448
3800
  } else if (componentType === "textarea") {
@@ -3546,7 +3898,7 @@ export const PanelHandlerComponents = () => {
3546
3898
  * 主动触发触发渲染右侧容器的事件
3547
3899
  * @param $container 容器
3548
3900
  */
3549
- triggerRenderRightContainer($container: HTMLElement) {
3901
+ emitRenderRightContainer($container: HTMLElement) {
3550
3902
  const dataViewConfig: PopsPanelEventType["pops:renderRightContainer"]["viewConfig"] = Reflect.get(
3551
3903
  $container,
3552
3904
  this.$data.nodeStoreConfigKey
@@ -3634,7 +3986,7 @@ export const PanelHandlerComponents = () => {
3634
3986
  return;
3635
3987
  }
3636
3988
  }
3637
- this.triggerRenderRightContainer(this.$el.$panelContentSectionContainer);
3989
+ this.emitRenderRightContainer(this.$el.$panelContentSectionContainer);
3638
3990
  });
3639
3991
  },
3640
3992
  };