@cmstops/pro-compo 0.1.81 → 0.1.83

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.
@@ -2,7 +2,7 @@
2
2
  var vue = require("vue");
3
3
  var webVue = require("@arco-design/web-vue");
4
4
  var icon = require("@arco-design/web-vue/es/icon");
5
- var core = require("@popperjs/core");
5
+ var usePopper = require("../../hooks/usePopper.js");
6
6
  const _hoisted_1 = { class: "filter-view-container" };
7
7
  const _hoisted_2 = { class: "more-btn" };
8
8
  const _hoisted_3 = { class: "right-prefix" };
@@ -15,120 +15,89 @@ const _hoisted_6 = {
15
15
  const _sfc_main = vue.defineComponent({
16
16
  __name: "FilterGroup",
17
17
  setup(__props) {
18
- const documentWidth = vue.ref(0);
19
- const overflowWidth = vue.ref(0);
20
- vue.watch(
21
- () => documentWidth.value,
22
- (n) => checkOverflow()
23
- );
24
- vue.watch(
25
- () => overflowWidth.value,
26
- (n) => setPannelItem()
27
- );
28
- const initDocWidthListener = function() {
29
- window.onresize = (() => {
30
- return () => {
31
- documentWidth.value = document.body.clientWidth;
32
- };
33
- })();
18
+ const getRect = (el) => {
19
+ if (!el || !el.getClientRects())
20
+ return { right: 0, width: 0 };
21
+ const [{ right, width }] = el.getClientRects();
22
+ return {
23
+ right,
24
+ width
25
+ };
34
26
  };
35
- const filterItemsRef = vue.ref();
36
27
  const moreBtnRef = vue.ref();
37
28
  const dpPannelRef = vue.ref();
38
- const initPopper = function() {
39
- core.createPopper(moreBtnRef.value, dpPannelRef.value, {
40
- placement: "bottom-start"
41
- });
29
+ const { initPopper, show, visible } = usePopper(dpPannelRef, moreBtnRef);
30
+ const filterItemsRef = vue.ref();
31
+ const windowWidth = vue.ref(0);
32
+ const filterWidth = vue.ref(0);
33
+ const filterBorder = vue.ref(0);
34
+ const initWidth = () => {
35
+ var _a;
36
+ windowWidth.value = ((_a = document.body) == null ? void 0 : _a.clientWidth) || 0;
37
+ if (filterItemsRef.value) {
38
+ filterWidth.value = filterItemsRef.value.clientWidth || 0;
39
+ filterBorder.value = getRect(filterItemsRef.value).right;
40
+ }
42
41
  };
43
- const popperShowFlag = vue.ref(false);
44
- function showPopper() {
45
- popperShowFlag.value = true;
46
- window.onclick = hidePopper;
47
- }
48
- function hidePopper() {
49
- popperShowFlag.value = false;
50
- }
51
- const itemNodeArr = vue.ref([]);
52
- const itemWidthArr = vue.ref([]);
53
- const itemArr = vue.ref([]);
54
- function checkOverflow() {
55
- if (!filterItemsRef.value)
42
+ const initDocWidthListener = () => window.onresize = () => initWidth();
43
+ const hideElementList = vue.ref([]);
44
+ const inNode = (el) => {
45
+ var _a, _b;
46
+ hideElementList.value.push({ width: getRect(el).width, el });
47
+ (_a = filterItemsRef.value) == null ? void 0 : _a.removeChild(el);
48
+ (_b = dpPannelRef.value) == null ? void 0 : _b.appendChild(el);
49
+ };
50
+ const outNode = () => {
51
+ var _a, _b;
52
+ if (!hideElementList.value.length || !filterItemsRef.value)
56
53
  return;
57
- const parent = filterItemsRef.value.parentNode;
58
- if (!itemNodeArr.value.length) {
59
- itemNodeArr.value = mapNodes(filterItemsRef.value.childNodes);
60
- itemWidthArr.value = itemNodeArr.value.map((node) => node.clientWidth + 10);
61
- itemArr.value = itemWidthArr.value.map((_, idx) => idx);
62
- }
63
- const parentWidth = parent.clientWidth;
64
- const leftWidth = getArrWidth(itemWidthArr.value);
65
- const rightWidth = parent.childNodes[parent.childNodes.length - 1].clientWidth;
66
- overflowWidth.value = leftWidth + rightWidth - parentWidth;
67
- }
68
- function mapNodes(nodes) {
69
- const nodeArr = [];
70
- for (let i = 0; i < nodes.length; i++) {
71
- const element = nodes[i];
72
- nodeArr.push(element);
54
+ const popEl = hideElementList.value.pop();
55
+ if (!popEl)
56
+ return;
57
+ const { width, el } = popEl;
58
+ el.style.width = `${width}px`;
59
+ (_a = dpPannelRef.value) == null ? void 0 : _a.removeChild(el);
60
+ (_b = filterItemsRef.value) == null ? void 0 : _b.appendChild(el);
61
+ hideElementList.value.splice(-1, 0);
62
+ };
63
+ const checkOverflow = () => {
64
+ if (!filterItemsRef.value)
65
+ return -1;
66
+ const elements = Array.from(filterItemsRef.value.childNodes);
67
+ let rightBorder = 0;
68
+ elements.forEach((item) => {
69
+ if (item.className !== "filter-item-view")
70
+ return;
71
+ const { right } = getRect(item);
72
+ if (right <= filterBorder.value) {
73
+ rightBorder = right;
74
+ return;
75
+ }
76
+ inNode(item);
77
+ });
78
+ return rightBorder;
79
+ };
80
+ const refreshPanel = () => {
81
+ const border = checkOverflow();
82
+ if (hideElementList.value.length && border !== -1) {
83
+ const spaceWidth = filterBorder.value - border;
84
+ const { width } = hideElementList.value[hideElementList.value.length - 1];
85
+ if (spaceWidth > width + 20) {
86
+ outNode();
87
+ }
73
88
  }
74
- return nodeArr.filter((item) => item.clientWidth);
75
- }
76
- function getArrWidth(arr) {
77
- return arr.reduce((prev, cur) => prev + cur, 0);
78
- }
79
- const pannelArray = vue.ref("");
89
+ };
80
90
  vue.watch(
81
- () => pannelArray.value,
82
- (n, o) => refreshPannel(n, o)
91
+ () => windowWidth.value,
92
+ () => refreshPanel()
83
93
  );
84
- function refreshPannel(newStr, oldStr) {
85
- const nArr = newStr ? newStr.split(",") : [];
86
- const oArr = oldStr ? oldStr.split(",") : [];
87
- if (nArr.length && nArr.length > oArr.length) {
88
- diff(nArr, oArr).forEach((index) => inNode(parseInt(index, 10)));
89
- } else if (nArr.length >= 0 && nArr.length < oArr.length) {
90
- diff(oArr, nArr).forEach((index) => outNode(parseInt(index, 10)));
91
- }
92
- }
93
- const diff = (arr1, arr2) => {
94
- const diff2 = [];
95
- for (let i = 0; i < arr1.length; i++) {
96
- const item = arr1[i];
97
- if (!arr2.includes(item))
98
- diff2.push(item);
99
- }
100
- return diff2;
101
- };
102
- function inNode(index) {
103
- var _a, _b, _c;
104
- const node = mapNodes((_a = filterItemsRef.value) == null ? void 0 : _a.childNodes)[index];
105
- const temp = document.createElement("div");
106
- temp.style.width = `${itemWidthArr.value[index]}px`;
107
- temp.style.position = "absolute";
108
- temp.style.left = `${50}px`;
109
- (_b = filterItemsRef.value) == null ? void 0 : _b.replaceChild(temp, node);
110
- (_c = dpPannelRef.value) == null ? void 0 : _c.appendChild(node);
111
- }
112
- function outNode(index) {
113
- var _a;
114
- const node = itemNodeArr.value[index];
115
- (_a = filterItemsRef.value) == null ? void 0 : _a.replaceChild(
116
- node,
117
- mapNodes(filterItemsRef.value.childNodes)[index]
118
- );
119
- }
120
- function setPannelItem() {
121
- let inPannelNum = 0;
122
- if (overflowWidth.value > 0) {
123
- const avgWidth = 120;
124
- inPannelNum = Math.ceil((overflowWidth.value + 200) / avgWidth);
125
- }
126
- pannelArray.value = itemArr.value.slice(0, inPannelNum).join(",");
127
- }
128
94
  vue.onMounted(() => {
129
95
  initDocWidthListener();
130
96
  initPopper();
131
- setTimeout(() => checkOverflow());
97
+ initWidth();
98
+ setTimeout(() => {
99
+ refreshPanel();
100
+ });
132
101
  });
133
102
  return (_ctx, _cache) => {
134
103
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
@@ -138,7 +107,7 @@ const _sfc_main = vue.defineComponent({
138
107
  ref: moreBtnRef
139
108
  }, [
140
109
  vue.withDirectives(vue.createVNode(vue.unref(webVue.Button), {
141
- onClick: vue.withModifiers(showPopper, ["stop"])
110
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers(() => vue.unref(show)(), ["stop"]))
142
111
  }, {
143
112
  default: vue.withCtx(() => [
144
113
  vue.createElementVNode("span", _hoisted_3, [
@@ -148,7 +117,7 @@ const _sfc_main = vue.defineComponent({
148
117
  ]),
149
118
  _: 1
150
119
  }, 512), [
151
- [vue.vShow, pannelArray.value]
120
+ [vue.vShow, hideElementList.value.length]
152
121
  ])
153
122
  ], 512),
154
123
  vue.withDirectives(vue.createElementVNode("div", {
@@ -157,7 +126,7 @@ const _sfc_main = vue.defineComponent({
157
126
  ref: dpPannelRef,
158
127
  class: "filter-pannel"
159
128
  }, null, 512), [
160
- [vue.vShow, popperShowFlag.value]
129
+ [vue.vShow, vue.unref(visible)]
161
130
  ])
162
131
  ]),
163
132
  vue.createElementVNode("div", _hoisted_4, [
@@ -1,60 +1,53 @@
1
1
  // FilterGroup 内部样式
2
2
  .filter-view-container {
3
3
  display: flex;
4
+ gap: 10px;
4
5
  align-items: center;
6
+ justify-content: space-between;
7
+ width: 100%;
5
8
  margin-bottom: 10px;
6
9
  font-size: 14px;
7
10
 
8
- .filter-search {
9
- display: flex;
10
- gap: 10px;
11
- width: 180px;
12
- margin-right: 10px;
11
+ .more-btn {
12
+ .right-prefix {
13
+ display: flex;
14
+ gap: 10px;
15
+ align-items: center;
16
+ }
17
+
18
+ .filter-pannel {
19
+ z-index: 1002;
20
+ display: flex;
21
+ gap: 10px;
22
+ padding: 10px;
23
+ background-color: white;
24
+ border-radius: 6px;
25
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
26
+ }
13
27
  }
14
28
 
15
29
  .filter-content {
16
- position: relative;
17
30
  display: flex;
18
31
  flex: 1;
19
32
  align-items: center;
20
33
  justify-content: space-between;
21
- }
22
34
 
23
- .left {
24
- display: flex;
25
- gap: 10px;
26
- align-items: center;
27
- }
35
+ .left {
36
+ display: flex;
37
+ flex: 1;
38
+ gap: 10px;
39
+ width: 100px;
40
+ overflow: hidden;
41
+ background-color: #fff;
42
+ }
28
43
 
29
- .right {
30
- position: absolute;
31
- right: 0;
32
- z-index: 1;
33
- display: flex;
34
- flex-wrap: nowrap;
35
- align-items: center;
36
- height: 100%;
37
- padding-left: 20px;
38
- background: white;
39
- }
40
-
41
- .more-btn {
42
- z-index: 10;
43
- margin-right: 10px;
44
- }
45
-
46
- .right-prefix {
47
- display: flex;
48
- gap: 10px;
49
- align-items: center;
50
- }
51
-
52
- .filter-pannel {
53
- display: flex;
54
- gap: 10px;
55
- padding: 10px;
56
- background-color: white;
57
- border-radius: 6px;
58
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
44
+ .right {
45
+ display: flex;
46
+ flex-wrap: nowrap;
47
+ align-items: center;
48
+ height: 100%;
49
+ padding-left: 20px;
50
+ background: white;
51
+ }
59
52
  }
60
53
  }
@@ -1,31 +1,41 @@
1
1
  .filter-view-container {
2
2
  display: flex;
3
+ gap: 10px;
3
4
  align-items: center;
5
+ justify-content: space-between;
6
+ width: 100%;
4
7
  margin-bottom: 10px;
5
8
  font-size: 14px;
6
9
  }
7
- .filter-view-container .filter-search {
10
+ .filter-view-container .more-btn .right-prefix {
11
+ display: flex;
12
+ gap: 10px;
13
+ align-items: center;
14
+ }
15
+ .filter-view-container .more-btn .filter-pannel {
16
+ z-index: 1002;
8
17
  display: flex;
9
18
  gap: 10px;
10
- width: 180px;
11
- margin-right: 10px;
19
+ padding: 10px;
20
+ background-color: white;
21
+ border-radius: 6px;
22
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
12
23
  }
13
24
  .filter-view-container .filter-content {
14
- position: relative;
15
25
  display: flex;
16
26
  flex: 1;
17
27
  align-items: center;
18
28
  justify-content: space-between;
19
29
  }
20
- .filter-view-container .left {
30
+ .filter-view-container .filter-content .left {
21
31
  display: flex;
32
+ flex: 1;
22
33
  gap: 10px;
23
- align-items: center;
34
+ width: 100px;
35
+ overflow: hidden;
36
+ background-color: #fff;
24
37
  }
25
- .filter-view-container .right {
26
- position: absolute;
27
- right: 0;
28
- z-index: 1;
38
+ .filter-view-container .filter-content .right {
29
39
  display: flex;
30
40
  flex-wrap: nowrap;
31
41
  align-items: center;
@@ -33,23 +43,6 @@
33
43
  padding-left: 20px;
34
44
  background: white;
35
45
  }
36
- .filter-view-container .more-btn {
37
- z-index: 10;
38
- margin-right: 10px;
39
- }
40
- .filter-view-container .right-prefix {
41
- display: flex;
42
- gap: 10px;
43
- align-items: center;
44
- }
45
- .filter-view-container .filter-pannel {
46
- display: flex;
47
- gap: 10px;
48
- padding: 10px;
49
- background-color: white;
50
- border-radius: 6px;
51
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
52
- }
53
46
  .base-filter-container {
54
47
  display: flex;
55
48
  align-items: center;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var core = require("@popperjs/core");
3
+ var vue = require("vue");
4
+ function usePopper(pannel, triggerEl) {
5
+ const visible = vue.ref(false);
6
+ const show = () => {
7
+ visible.value = true;
8
+ window.onclick = (e) => {
9
+ visible.value = false;
10
+ window.onclick = null;
11
+ };
12
+ };
13
+ const initPopper = (placement = "bottom-start") => {
14
+ if (!pannel.value || !triggerEl.value)
15
+ return;
16
+ core.createPopper(triggerEl.value, pannel.value, {
17
+ placement
18
+ });
19
+ };
20
+ return {
21
+ initPopper,
22
+ show,
23
+ visible
24
+ };
25
+ }
26
+ module.exports = usePopper;
package/lib/index.css CHANGED
@@ -3498,32 +3498,42 @@
3498
3498
  }
3499
3499
  .filter-view-container {
3500
3500
  display: flex;
3501
+ gap: 10px;
3501
3502
  align-items: center;
3503
+ justify-content: space-between;
3504
+ width: 100%;
3502
3505
  margin-bottom: 10px;
3503
3506
  font-size: 14px;
3504
3507
  }
3505
- .filter-view-container .filter-search {
3508
+ .filter-view-container .more-btn .right-prefix {
3506
3509
  display: flex;
3507
3510
  gap: 10px;
3508
- width: 180px;
3509
- margin-right: 10px;
3511
+ align-items: center;
3512
+ }
3513
+ .filter-view-container .more-btn .filter-pannel {
3514
+ z-index: 1002;
3515
+ display: flex;
3516
+ gap: 10px;
3517
+ padding: 10px;
3518
+ background-color: white;
3519
+ border-radius: 6px;
3520
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
3510
3521
  }
3511
3522
  .filter-view-container .filter-content {
3512
- position: relative;
3513
3523
  display: flex;
3514
3524
  flex: 1;
3515
3525
  align-items: center;
3516
3526
  justify-content: space-between;
3517
3527
  }
3518
- .filter-view-container .left {
3528
+ .filter-view-container .filter-content .left {
3519
3529
  display: flex;
3530
+ flex: 1;
3520
3531
  gap: 10px;
3521
- align-items: center;
3532
+ width: 100px;
3533
+ overflow: hidden;
3534
+ background-color: #fff;
3522
3535
  }
3523
- .filter-view-container .right {
3524
- position: absolute;
3525
- right: 0;
3526
- z-index: 1;
3536
+ .filter-view-container .filter-content .right {
3527
3537
  display: flex;
3528
3538
  flex-wrap: nowrap;
3529
3539
  align-items: center;
@@ -3531,23 +3541,6 @@
3531
3541
  padding-left: 20px;
3532
3542
  background: white;
3533
3543
  }
3534
- .filter-view-container .more-btn {
3535
- z-index: 10;
3536
- margin-right: 10px;
3537
- }
3538
- .filter-view-container .right-prefix {
3539
- display: flex;
3540
- gap: 10px;
3541
- align-items: center;
3542
- }
3543
- .filter-view-container .filter-pannel {
3544
- display: flex;
3545
- gap: 10px;
3546
- padding: 10px;
3547
- background-color: white;
3548
- border-radius: 6px;
3549
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
3550
- }
3551
3544
  .base-filter-container {
3552
3545
  display: flex;
3553
3546
  align-items: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmstops/pro-compo",
3
- "version": "0.1.81",
3
+ "version": "0.1.83",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vue",