|
|
@ -1,8 +1,19 @@ |
|
|
|
import type { ColumnType, GridColumnType, GridType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { ColumnType, GridColumnType, ViewType } from 'nocodb-sdk' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import type { Ref } from 'vue' |
|
|
|
import { IsPublicInj, computed, inject, ref, useMetas, useNuxtApp, useStyleTag, useUIPermission, watch } from '#imports' |
|
|
|
import { |
|
|
|
|
|
|
|
IsPublicInj, |
|
|
|
|
|
|
|
computed, |
|
|
|
|
|
|
|
inject, |
|
|
|
|
|
|
|
ref, |
|
|
|
|
|
|
|
useMetas, |
|
|
|
|
|
|
|
useNuxtApp, |
|
|
|
|
|
|
|
useStyleTag, |
|
|
|
|
|
|
|
useUIPermission, |
|
|
|
|
|
|
|
useUndoRedo, |
|
|
|
|
|
|
|
watch, |
|
|
|
|
|
|
|
} from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
export function useGridViewColumnWidth(view: Ref<GridType | undefined>) { |
|
|
|
export function useGridViewColumnWidth(view: Ref<ViewType | undefined>) { |
|
|
|
const { css, load: loadCss, unload: unloadCss } = useStyleTag('') |
|
|
|
const { css, load: loadCss, unload: unloadCss } = useStyleTag('') |
|
|
|
|
|
|
|
|
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
@ -11,12 +22,14 @@ export function useGridViewColumnWidth(view: Ref<GridType | undefined>) { |
|
|
|
|
|
|
|
|
|
|
|
const { metas } = useMetas() |
|
|
|
const { metas } = useMetas() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { addUndo } = useUndoRedo() |
|
|
|
|
|
|
|
|
|
|
|
const gridViewCols = ref<Record<string, GridColumnType>>({}) |
|
|
|
const gridViewCols = ref<Record<string, GridColumnType>>({}) |
|
|
|
const resizingCol = ref('') |
|
|
|
const resizingCol = ref('') |
|
|
|
const resizingColWidth = ref('200px') |
|
|
|
const resizingColWidth = ref('200px') |
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
|
|
|
|
|
|
|
|
const columns = computed<ColumnType[]>(() => metas.value?.[(view.value as ViewType)?.fk_model_id as string]?.columns || []) |
|
|
|
const columns = computed<ColumnType[]>(() => metas.value?.[view.value?.fk_model_id as string]?.columns || []) |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|
[gridViewCols, resizingCol, resizingColWidth], |
|
|
|
[gridViewCols, resizingCol, resizingColWidth], |
|
|
@ -54,7 +67,21 @@ export function useGridViewColumnWidth(view: Ref<GridType | undefined>) { |
|
|
|
* or when view changes reload columns width */ |
|
|
|
* or when view changes reload columns width */ |
|
|
|
watch([() => columns.value?.length, () => view?.value?.id], loadGridViewColumns) |
|
|
|
watch([() => columns.value?.length, () => view?.value?.id], loadGridViewColumns) |
|
|
|
|
|
|
|
|
|
|
|
const updateWidth = async (id: string, width: string) => { |
|
|
|
const updateWidth = async (id: string, width: string, undo = false) => { |
|
|
|
|
|
|
|
if (!undo) { |
|
|
|
|
|
|
|
addUndo({ |
|
|
|
|
|
|
|
redo: { |
|
|
|
|
|
|
|
fn: (w: string) => updateWidth(id, w, true), |
|
|
|
|
|
|
|
args: [width], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
undo: { |
|
|
|
|
|
|
|
fn: (w: string) => updateWidth(id, w, true), |
|
|
|
|
|
|
|
args: [gridViewCols.value[id].width], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
scope: view.value?.is_default ? [view.value.fk_model_id, view.value.title] : view.value?.title, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (gridViewCols?.value?.[id]) { |
|
|
|
if (gridViewCols?.value?.[id]) { |
|
|
|
gridViewCols.value[id].width = width |
|
|
|
gridViewCols.value[id].width = width |
|
|
|
} |
|
|
|
} |
|
|
|