|
|
@ -10,8 +10,11 @@ export const useColumnDrag = ({ |
|
|
|
gridWrapper: Ref<HTMLElement | undefined> |
|
|
|
gridWrapper: Ref<HTMLElement | undefined> |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const { eventBus } = useSmartsheetStoreOrThrow() |
|
|
|
const { eventBus } = useSmartsheetStoreOrThrow() |
|
|
|
|
|
|
|
const { addUndo, defineViewScope } = useUndoRedo() |
|
|
|
|
|
|
|
|
|
|
|
const { updateGridViewColumn, gridViewCols } = useViewColumnsOrThrow() |
|
|
|
const { activeView } = storeToRefs(useViewsStore()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { gridViewCols, updateGridViewColumn } = useViewColumnsOrThrow() |
|
|
|
const { leftSidebarWidth } = storeToRefs(useSidebarStore()) |
|
|
|
const { leftSidebarWidth } = storeToRefs(useSidebarStore()) |
|
|
|
const { width } = useWindowSize() |
|
|
|
const { width } = useWindowSize() |
|
|
|
|
|
|
|
|
|
|
@ -20,18 +23,50 @@ export const useColumnDrag = ({ |
|
|
|
const toBeDroppedColId = ref<string | null>(null) |
|
|
|
const toBeDroppedColId = ref<string | null>(null) |
|
|
|
|
|
|
|
|
|
|
|
const reorderColumn = async (colId: string, toColId: string) => { |
|
|
|
const reorderColumn = async (colId: string, toColId: string) => { |
|
|
|
const col = gridViewCols.value[colId] |
|
|
|
const toBeReorderedViewCol = gridViewCols.value[colId] |
|
|
|
const toCol = gridViewCols.value[toColId]! |
|
|
|
|
|
|
|
|
|
|
|
const toViewCol = gridViewCols.value[toColId]! |
|
|
|
const toColIndex = fields.value.findIndex((f) => f.id === toColId) |
|
|
|
const toColIndex = fields.value.findIndex((f) => f.id === toColId) |
|
|
|
|
|
|
|
|
|
|
|
const nextToColField = toColIndex < fields.value.length - 1 ? fields.value[toColIndex + 1] : null |
|
|
|
const nextToColField = toColIndex < fields.value.length - 1 ? fields.value[toColIndex + 1] : null |
|
|
|
const nextToCol = nextToColField ? gridViewCols.value[nextToColField.id!] : null |
|
|
|
const nextToViewCol = nextToColField ? gridViewCols.value[nextToColField.id!] : null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastCol = fields.value[fields.value.length - 1] |
|
|
|
|
|
|
|
const lastViewCol = gridViewCols.value[lastCol.id!] |
|
|
|
|
|
|
|
|
|
|
|
const newOrder = nextToCol ? toCol.order! + (nextToCol.order! - toCol.order!) / 2 : toCol.order! + 1 |
|
|
|
const newOrder = nextToViewCol ? toViewCol.order! + (nextToViewCol.order! - toViewCol.order!) / 2 : lastViewCol.order! + 1 |
|
|
|
|
|
|
|
const oldOrder = toBeReorderedViewCol.order |
|
|
|
|
|
|
|
|
|
|
|
col.order = newOrder |
|
|
|
toBeReorderedViewCol.order = newOrder |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addUndo({ |
|
|
|
|
|
|
|
undo: { |
|
|
|
|
|
|
|
fn: async () => { |
|
|
|
|
|
|
|
if (!fields.value) return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toBeReorderedViewCol.order = oldOrder |
|
|
|
|
|
|
|
await updateGridViewColumn(colId, { order: oldOrder } as any) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
args: [], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
redo: { |
|
|
|
|
|
|
|
fn: async () => { |
|
|
|
|
|
|
|
if (!fields.value) return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toBeReorderedViewCol.order = newOrder |
|
|
|
await updateGridViewColumn(colId, { order: newOrder } as any) |
|
|
|
await updateGridViewColumn(colId, { order: newOrder } as any) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
args: [], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
scope: defineViewScope({ view: activeView.value }), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await updateGridViewColumn(colId, { order: newOrder } as any, true) |
|
|
|
|
|
|
|
|
|
|
|
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) |
|
|
|
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -94,13 +129,13 @@ export const useColumnDrag = ({ |
|
|
|
|
|
|
|
|
|
|
|
const remInPx = parseFloat(getComputedStyle(document.documentElement).fontSize) |
|
|
|
const remInPx = parseFloat(getComputedStyle(document.documentElement).fontSize) |
|
|
|
|
|
|
|
|
|
|
|
if (x > width.value * 0.5) { |
|
|
|
if (x < leftSidebarWidth.value + 1 * remInPx) { |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
gridWrapper.value!.scrollLeft += 2.5 |
|
|
|
gridWrapper.value!.scrollLeft -= 2.5 |
|
|
|
}, 250) |
|
|
|
}, 250) |
|
|
|
} else if (x < leftSidebarWidth.value + 10 * remInPx) { |
|
|
|
} else if (width.value - x - leftSidebarWidth.value < 15 * remInPx) { |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
gridWrapper.value!.scrollLeft -= 2.5 |
|
|
|
gridWrapper.value!.scrollLeft += 2.5 |
|
|
|
}, 250) |
|
|
|
}, 250) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|