plain-design 1.0.0-beta.19 → 1.0.0-beta.20

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plain-design",
3
- "version": "1.0.0-beta.19",
3
+ "version": "1.0.0-beta.20",
4
4
  "description": "",
5
5
  "main": "dist/plain-design.min.js",
6
6
  "module": "dist/plain-design.commonjs.min.js",
@@ -3,6 +3,7 @@ import {delay} from "plain-utils/utils/delay";
3
3
  import './virtual-list.scss';
4
4
  import Scroll from "../Scroll";
5
5
  import {unit} from "plain-utils/string/unit";
6
+ import {createEnum} from "plain-utils/utils/createEnum";
6
7
 
7
8
  interface DataNode {
8
9
  top: number;
@@ -13,6 +14,8 @@ interface DataNode {
13
14
  index: number;
14
15
  }
15
16
 
17
+ const ScrollDirection = createEnum(['up', 'down', 'none'] as const);
18
+
16
19
  export function useVirtualList(
17
20
  {
18
21
  props,
@@ -53,6 +56,7 @@ export function useVirtualList(
53
56
  nodes: [] as DataNode[], // 格式化的data数组数据
54
57
  scrollTop: 0, // 当前滚动scrollTop(非实时的)
55
58
  pageSize: 0, // 页大小
59
+ scrollDirection: ScrollDirection.none as typeof ScrollDirection.TYPE,
56
60
  });
57
61
 
58
62
  /**
@@ -189,18 +193,37 @@ export function useVirtualList(
189
193
  * @date 2020/12/14 22:44
190
194
  */
191
195
  getPageIndex: (scrollTop: number, pageSize: number) => {
196
+ if (scrollTop < 0) {
197
+ scrollTop = 0;
198
+ }
192
199
  const data = props.data || [];
193
200
  /*当前scrollTop对应的数据中数据的索引*/
194
201
  let scrollIndex = utils.getIndex(scrollTop);
195
202
  let pageIndex = Math.floor(scrollIndex / pageSize);
196
- let start = pageIndex === 0 ? 0 : (pageIndex - 1) * pageSize;
197
- let end = start + pageSize * 3;
203
+ let start = (() => {
204
+ if (state.scrollDirection === 'none') {
205
+ return scrollIndex - Math.floor(pageSize * 0.5);
206
+ } else if (state.scrollDirection === 'up') {
207
+ return scrollIndex - pageSize;
208
+ } else {
209
+ return scrollIndex;
210
+ }
211
+ })();
212
+ let end = start + pageSize * 2;
213
+ start -= 1;
214
+ end += 1;
215
+ if (start < 0) {
216
+ end -= start;
217
+ start = 0;
218
+ }
198
219
  /*console.log({
199
- scrollIndex,
200
- pageIndex,
201
- start,
202
- end,
203
- })*/
220
+ scrollIndex,
221
+ pageIndex,
222
+ start,
223
+ end,
224
+ pageSize,
225
+ scrollDirection: state.scrollDirection
226
+ });*/
204
227
  const exceed = end - data.length;
205
228
  if (exceed > 0) {
206
229
  end = data.length;
@@ -242,13 +265,13 @@ export function useVirtualList(
242
265
  if (props.disabled) {
243
266
  return;
244
267
  }
245
- freezeState.scrollTop = (e.target as HTMLDivElement).scrollTop;
268
+ const newScrollTop = (e.target as HTMLDivElement).scrollTop;
269
+ state.scrollDirection = newScrollTop > freezeState.scrollTop ? ScrollDirection.down : ScrollDirection.up;
270
+ freezeState.scrollTop = newScrollTop;
246
271
  const current = utils.getPageIndex((e.target as HTMLDivElement).scrollTop, state.pageSize);
247
- if (freezeState.current.pageIndex != current.pageIndex || freezeState.current.start != current.start) {
248
- state.scrollTop = (e.target as HTMLDivElement).scrollTop;
249
- freezeState.current = current;
250
- emit.onPageIndexChange(current);
251
- }
272
+ state.scrollTop = (e.target as HTMLDivElement).scrollTop;
273
+ freezeState.current = current;
274
+ emit.onPageIndexChange(current);
252
275
  }
253
276
  };
254
277
 
@@ -265,8 +288,17 @@ export function useVirtualList(
265
288
  });
266
289
 
267
290
  onMounted(() => {
268
- const hostHeight = refs.scroll!.refs.host!.offsetHeight;
269
- state.pageSize = Math.ceil(hostHeight / props.size);
291
+ let hostHeight = refs.scroll!.refs.host!.offsetHeight;
292
+ const headEl = refs.scroll!.refs.host!.querySelector('[data-virtual-head]') as undefined | HTMLDivElement;
293
+ const footEl = refs.scroll!.refs.host!.querySelector('[data-virtual-foot]') as undefined | HTMLDivElement;
294
+ if (!!headEl) {
295
+ hostHeight -= headEl.offsetHeight;
296
+ }
297
+ if (!!footEl) {
298
+ hostHeight -= footEl.offsetHeight;
299
+ }
300
+
301
+ state.pageSize = Math.floor(hostHeight / props.size);
270
302
  if (props.dynamicSize && !props.disabled) {
271
303
  utils.resetData(props.data);
272
304
  }
@@ -157,7 +157,7 @@ export const VirtualTable = designComponent({
157
157
  <>
158
158
  {!!headHeight.value && (
159
159
  <div className="virtual-table-head-table-wrapper" ref={onRef.head}>
160
- <table className="virtual-table-head-table" style={headTableStyles.value} {...PublicTableAttrs}>
160
+ <table className="virtual-table-head-table" style={headTableStyles.value} {...PublicTableAttrs} data-virtual-head>
161
161
  {slots.headColgroup()}
162
162
  <thead>{slots.head()}</thead>
163
163
  </table>
@@ -175,7 +175,7 @@ export const VirtualTable = designComponent({
175
175
  </div>
176
176
  {!!props.summaryData?.length && (
177
177
  <div className="virtual-table-summary-table-wrapper" ref={onRef.summary}>
178
- <table className="virtual-table-summary-table" style={summaryTableStyles.value}{...PublicTableAttrs}>
178
+ <table className="virtual-table-summary-table" style={summaryTableStyles.value}{...PublicTableAttrs} data-virtual-foot>
179
179
  {slots.colgroup()}
180
180
  <tbody>{!props.summaryData ? null : props.summaryData.map((item, index) => scopeSlots.default({ item, index, virtualIndex: index }))}</tbody>
181
181
  </table>
@@ -82,6 +82,7 @@ export const PopupItem = designComponent({
82
82
  'popup-item-is-dark': !application.value.theme.dark && !state.option.status && !!state.option.dark,
83
83
  [`popup-item-status-${state.option.status}`]: !!state.option.status,
84
84
  'popup-item-dark-app': application.value.theme.dark,
85
+ 'popup-item-no-interactive': !state.option.interactive,
85
86
  }
86
87
  ]);
87
88
 
@@ -112,6 +112,10 @@
112
112
  &.popup-item-no-border {
113
113
  filter: none !important;
114
114
  }
115
+
116
+ &.popup-item-no-interactive {
117
+ pointer-events: none;
118
+ }
115
119
  /*---------------------------------------animation-------------------------------------------*/
116
120
 
117
121
  &.popup-item-animation-fade {