Skip to content

Commit

Permalink
group support
Browse files Browse the repository at this point in the history
  • Loading branch information
YOKE committed Apr 27, 2023
1 parent fafd3e8 commit 50c1531
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/Plugins/Children.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Items = defineComponent({
key: dataKey,
'data-key': dataKey,
},
{default: () => slots.default?.()}
{ default: () => slots.default?.() }
);
};
},
Expand All @@ -45,7 +45,7 @@ export const Slots = defineComponent({
key: dataKey,
'data-key': dataKey,
},
{default: () => slots.default?.()}
{ default: () => slots.default?.() }
);
};
},
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/Sortable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Sortable {
const fromList = [...this.initialList];
const fromState = this._getFromTo({ node }, fromList);

await Store.setValue({ from: { ...fromState } });
await Store.setValue({ from: { list: fromList, ...fromState } });

if (callback) {
this.rangeChanged = false;
Expand Down Expand Up @@ -136,7 +136,7 @@ class Sortable {
const key = getDataKey(item, this.context.dataKey);

await Store.setValue({
to: { index, item, key },
to: { list: [...this.initialList], index, item, key },
});

const store = await Store.getValue();
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const storeKey = 'virtualSortableState';

type Item = {
list: any[];
item: any;
key: string;
index: number;
Expand Down
60 changes: 32 additions & 28 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ const VirtualDragList = defineComponent({
event: 'resize',
onResize: onHeaderResized,
},
{default: () => slots.header()}
{ default: () => slots.header() }
)
: null,

Expand All @@ -343,31 +343,35 @@ const VirtualDragList = defineComponent({
style: wrapStyle,
},
{
default: () => viewlist.value.slice(start, end + 1).map((item) => {
const index = getItemIndex(item);
const dataKey = getDataKey(item, props.dataKey);
const itemStyle = {
...props.itemStyle,
...getItemStyle(dataKey),
};

return slots.item
? h(
Items,
{
key: dataKey,
tag: ItemTag,
class: props.itemClass,
style: itemStyle,
event: 'resize',
dataKey: dataKey,
isHorizontal: isHorizontal,
onResize: onItemResized,
},
{default: () => slots.item({ record: item, index, dataKey })}
)
: null
})
default: () =>
viewlist.value.slice(start, end + 1).map((item) => {
const index = getItemIndex(item);
const dataKey = getDataKey(item, props.dataKey);
const itemStyle = {
...props.itemStyle,
...getItemStyle(dataKey),
};

return slots.item
? h(
Items,
{
key: dataKey,
tag: ItemTag,
class: props.itemClass,
style: itemStyle,
event: 'resize',
dataKey: dataKey,
isHorizontal: isHorizontal,
onResize: onItemResized,
},
{
default: () =>
slots.item({ record: item, index, dataKey }),
}
)
: null;
}),
}
),

Expand All @@ -382,7 +386,7 @@ const VirtualDragList = defineComponent({
event: 'resize',
onResize: onFooterResized,
},
{default: () => slots.footer()}
{ default: () => slots.footer() }
)
: null,

Expand All @@ -394,7 +398,7 @@ const VirtualDragList = defineComponent({
height: isHorizontal ? '100%' : '0px',
},
}),
]
],
}
);
};
Expand Down
10 changes: 5 additions & 5 deletions src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Direction = 'vertical' | 'horizontal';
export const VirtualProps = {
dataSource: {
type: Array,
default: () => ([])
default: () => [],
},
dataKey: {
type: String,
Expand All @@ -15,10 +15,10 @@ export const VirtualProps = {
type: [Function, String],
},
handle: {
type: [Function, String]
type: [Function, String],
},
group: {
type: [Object, String]
type: [Object, String],
},
direction: {
type: String as PropType<Direction>,
Expand All @@ -33,7 +33,7 @@ export const VirtualProps = {
},
delay: {
type: Number,
default: 10,
default: 0,
},
animation: {
type: Number,
Expand All @@ -45,7 +45,7 @@ export const VirtualProps = {
},
scrollThreshold: {
type: Number,
default: 15,
default: 25,
},
keepOffset: {
type: Boolean,
Expand Down

0 comments on commit 50c1531

Please sign in to comment.