plain-design 1.0.0-beta.76 → 1.0.0-beta.77
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/plain-design.commonjs.min.js +2 -2
- package/dist/plain-design.min.js +2 -2
- package/dist/report.html +2 -2
- package/package.json +1 -1
- package/src/packages/components/FormItem/index.tsx +2 -2
- package/src/packages/components/Input/index.tsx +2 -2
- package/src/packages/components/Table/standard/PlcExpand.tsx +7 -1
- package/src/packages/components/VirtualList/useVirtualList.tsx +30 -24
package/package.json
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {designComponent, getComponentCls, useClasses, useRefs} from "plain-design-composition";
|
1
|
+
import {designComponent, Fragment, getComponentCls, useClasses, useRefs} from "plain-design-composition";
|
2
2
|
import {FormItemValidatePropsOption} from "../Form/validate/validate.utils";
|
3
3
|
import {EditProps, useEdit} from "../../uses/useEdit";
|
4
4
|
import {StyleProps, ThemeStatus, useStyle} from "../../uses/useStyle";
|
@@ -109,7 +109,7 @@ export const FormItem = designComponent({
|
|
109
109
|
<div className="form-item-content box-message-reference" style={formItemLayout.contentStyles.value}>
|
110
110
|
{slots.prepend.isExist() && <div className="form-item-prepend-content">{slots.prepend()}</div>}
|
111
111
|
<div className="form-item-content-inner">
|
112
|
-
{slots.default()}
|
112
|
+
<Fragment key="slot_default">{slots.default()}</Fragment>
|
113
113
|
{/*校验消息放下边的时候放在 form-item-content-inner 内部使得与输入框左或者右对齐*/}
|
114
114
|
{formItemLayout.validateMessagePosition.value !== 'right' && <FormItemValidateMessage message={formItemValidation.validateMessage.value!}/>}
|
115
115
|
</div>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {computed, designComponent, getComponentCls, iHTMLDivElement, mergeAttrs, useClasses, useRefs, useStyles} from "plain-design-composition";
|
1
|
+
import {computed, designComponent, Fragment, getComponentCls, iHTMLDivElement, mergeAttrs, useClasses, useRefs, useStyles} from "plain-design-composition";
|
2
2
|
import './index.scss';
|
3
3
|
import {ThemeStatus, useStyle} from "../../uses/useStyle";
|
4
4
|
import {useEdit} from "../../uses/useEdit";
|
@@ -134,7 +134,7 @@ export const Input = designComponent({
|
|
134
134
|
{content}
|
135
135
|
|
136
136
|
{inputSuffixIcon.render()}
|
137
|
-
{hooks.onRenderSuffix.exec(slots.suffix())}
|
137
|
+
{hooks.onRenderSuffix.exec(<Fragment key="slot_suffix">{slots.suffix()}</Fragment>)}
|
138
138
|
</span>
|
139
139
|
);
|
140
140
|
},
|
@@ -133,13 +133,19 @@ export const PlcExpand = designComponent({
|
|
133
133
|
* @author 韦胜健
|
134
134
|
* @date 2022/11/17 14:15
|
135
135
|
*/
|
136
|
+
const weakMap = new WeakMap<PlainObject, (param: any) => any>();
|
136
137
|
onBeforeUnmount(table.hooks.onTableMessyData.use(({ data }) => {
|
137
138
|
const newData = [] as any[];
|
138
139
|
data.forEach(item => {
|
139
140
|
newData.push(item);
|
140
141
|
if (typeof item === "function") {return;}
|
141
142
|
if (utils.isExpand(item.data)) {
|
142
|
-
|
143
|
+
let dataFunc = weakMap.get(item.data);
|
144
|
+
if (!dataFunc) {
|
145
|
+
dataFunc = (param: any) => utils.renderExpand(item, param.vIndex, param.vid, param.index);
|
146
|
+
weakMap.set(item.data, dataFunc);
|
147
|
+
}
|
148
|
+
newData.push(dataFunc);
|
143
149
|
}
|
144
150
|
});
|
145
151
|
return { data: newData };
|
@@ -75,12 +75,26 @@ export function useVirtualList(
|
|
75
75
|
hostSize: null as null | number, // 容器高度
|
76
76
|
scrollDirection: ScrollDirection.none as typeof ScrollDirection.TYPE,
|
77
77
|
id2size: {} as Record<string, number | undefined>,
|
78
|
-
|
78
|
+
});
|
79
|
+
|
80
|
+
const _avgSize = computed((): number => {
|
81
|
+
const total = Object.values(state.id2size).reduce((prev, item) => {
|
82
|
+
if (item != null) {
|
83
|
+
prev.total += item;
|
84
|
+
prev.count++;
|
85
|
+
}
|
86
|
+
return prev;
|
87
|
+
}, { total: 0, count: 0 });
|
88
|
+
if (!!total.count) {
|
89
|
+
return Math.floor(total.total / total.count);
|
90
|
+
} else {
|
91
|
+
return props.size;
|
92
|
+
}
|
79
93
|
});
|
80
94
|
|
81
95
|
const _pageSize = computed(() => {
|
82
96
|
if (state.hostSize == null) {return null;}
|
83
|
-
return Math.floor(state.hostSize /
|
97
|
+
return Math.floor(state.hostSize / _avgSize.value);
|
84
98
|
});
|
85
99
|
|
86
100
|
const idMap = new WeakMap<PlainObject, string>();
|
@@ -94,7 +108,7 @@ export function useVirtualList(
|
|
94
108
|
id = nextRowId();
|
95
109
|
idMap.set(item, id);
|
96
110
|
}
|
97
|
-
const size: number = state.id2size[id] ||
|
111
|
+
const size: number = state.id2size[id] || _avgSize.value;
|
98
112
|
let start = prevEnd;
|
99
113
|
let end = start + size;
|
100
114
|
prevEnd = end;
|
@@ -120,7 +134,7 @@ export function useVirtualList(
|
|
120
134
|
startPageIndex: 0,
|
121
135
|
};
|
122
136
|
}
|
123
|
-
const { startIndex, endIndex, pageIndex } = utils.getPageIndex(scrollValue
|
137
|
+
const { startIndex, endIndex, pageIndex } = utils.getPageIndex(scrollValue);
|
124
138
|
return {
|
125
139
|
list: nodes.value.slice(startIndex, endIndex),
|
126
140
|
startPageIndex: pageIndex,
|
@@ -264,10 +278,11 @@ export function useVirtualList(
|
|
264
278
|
* @author 韦胜健
|
265
279
|
* @date 2020/12/14 22:44
|
266
280
|
*/
|
267
|
-
getPageIndex: (scrollValue: number
|
281
|
+
getPageIndex: (scrollValue: number) => {
|
268
282
|
if (scrollValue < 0) {
|
269
283
|
scrollValue = 0;
|
270
284
|
}
|
285
|
+
const pageSize = _pageSize.value;
|
271
286
|
const data = dataModel.value || [];
|
272
287
|
if (pageSize == null) {
|
273
288
|
return {
|
@@ -322,18 +337,15 @@ export function useVirtualList(
|
|
322
337
|
};
|
323
338
|
},
|
324
339
|
resetHostSize: () => {
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
}
|
331
|
-
if (!!footEl) {
|
332
|
-
|
333
|
-
}
|
334
|
-
if (state.hostSize != hostSize) {
|
335
|
-
state.hostSize = hostSize;
|
336
|
-
}
|
340
|
+
const hostEl = refs.scroll?.refs.host;
|
341
|
+
if (!hostEl) {return;}
|
342
|
+
let hostSize = hostEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];
|
343
|
+
const headEl = hostEl.querySelector('[data-virtual-head]') as undefined | HTMLDivElement;
|
344
|
+
const footEl = hostEl.querySelector('[data-virtual-foot]') as undefined | HTMLDivElement;
|
345
|
+
if (!!headEl) {hostSize -= headEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];}
|
346
|
+
if (!!footEl) {hostSize -= footEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];}
|
347
|
+
|
348
|
+
if (state.hostSize != hostSize) {state.hostSize = hostSize;}
|
337
349
|
},
|
338
350
|
};
|
339
351
|
|
@@ -348,7 +360,7 @@ export function useVirtualList(
|
|
348
360
|
const newScrollValue = (e.target as HTMLDivElement)[props.horizontal ? 'scrollLeft' : 'scrollTop'];
|
349
361
|
state.scrollDirection = newScrollValue > freezeState.scrollValue ? ScrollDirection.end : ScrollDirection.start;
|
350
362
|
freezeState.scrollValue = newScrollValue;
|
351
|
-
const current = utils.getPageIndex((e.target as HTMLDivElement).scrollTop
|
363
|
+
const current = utils.getPageIndex((e.target as HTMLDivElement).scrollTop);
|
352
364
|
state.scrollValue = (e.target as HTMLDivElement)[props.horizontal ? 'scrollLeft' : 'scrollTop'];
|
353
365
|
freezeState.current = current;
|
354
366
|
emit.onPageIndexChange(current);
|
@@ -387,7 +399,6 @@ export function useVirtualList(
|
|
387
399
|
await delay();
|
388
400
|
// console.log('dynamic scan height')
|
389
401
|
const elNodes = (refs.content?.querySelectorAll('[data-vid],[vid]') || []) as HTMLElement[];
|
390
|
-
let newAvgSize = state.avgSize;
|
391
402
|
|
392
403
|
for (let i = 0; i < elNodes.length; i++) {
|
393
404
|
const el = elNodes[i];
|
@@ -398,13 +409,8 @@ export function useVirtualList(
|
|
398
409
|
}
|
399
410
|
if (state.id2size[vid] != size) {
|
400
411
|
state.id2size[vid] = size;
|
401
|
-
newAvgSize = Number(((state.avgSize + size) / 2).toFixed(0));
|
402
412
|
}
|
403
413
|
}
|
404
|
-
|
405
|
-
if (newAvgSize != state.avgSize) {
|
406
|
-
state.avgSize = newAvgSize;
|
407
|
-
}
|
408
414
|
});
|
409
415
|
|
410
416
|
return {
|