@movk/nuxt 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/DataTable.vue +16 -24
- package/dist/runtime/domains/data-table/columns/constants.d.ts +6 -1
- package/dist/runtime/domains/data-table/columns/resolve-columns.d.ts +2 -2
- package/dist/runtime/domains/data-table/columns/resolve-columns.js +2 -1
- package/dist/runtime/domains/data-table/columns/resolve-data-column.js +4 -3
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.js +3 -2
- package/dist/runtime/types/data-table/component.d.ts +10 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import { Tree, useInfiniteScrollBinding, separate } from "@movk/core";
|
|
|
14
14
|
import theme from "#build/movk-ui/data-table";
|
|
15
15
|
import tableTheme from "#build/ui/table";
|
|
16
16
|
import DataTablePagination from "../domains/data-table/components/Pagination.vue";
|
|
17
|
+
const HEADER_SLOT_SUFFIX = "-header";
|
|
18
|
+
const PAGINATION_SLOTS = ["pagination", "pagination-summary", "pagination-actions"];
|
|
17
19
|
const props = defineProps({
|
|
18
20
|
rowKey: { type: [String, Object], required: false },
|
|
19
21
|
columns: { type: Array, required: false },
|
|
@@ -76,8 +78,17 @@ const columnVisibilityKeysState = defineModel("columnVisibilityKeys", { type: Ar
|
|
|
76
78
|
const columnVisibilityExcludeKeysState = defineModel("columnVisibilityExcludeKeys", { type: Array });
|
|
77
79
|
const rowSelectionKeysState = defineModel("rowSelectionKeys", { type: Array });
|
|
78
80
|
const expandedKeysState = defineModel("expandedKeys", { type: Array });
|
|
79
|
-
defineSlots();
|
|
80
|
-
const
|
|
81
|
+
const slots = defineSlots();
|
|
82
|
+
const slotRecord = slots;
|
|
83
|
+
const headerSlots = Object.fromEntries(
|
|
84
|
+
Object.keys(slots).filter((name) => name.endsWith(HEADER_SLOT_SUFFIX)).map((name) => [name, (ctx) => slotRecord[name]?.(ctx) ?? []])
|
|
85
|
+
);
|
|
86
|
+
const resolved = computed(() => resolveColumns(props.columns || [], props, headerSlots));
|
|
87
|
+
const forwardSlots = computed(() => Object.keys(slots).filter((name) => {
|
|
88
|
+
if (PAGINATION_SLOTS.includes(name)) return false;
|
|
89
|
+
if (!name.endsWith(HEADER_SLOT_SUFFIX)) return true;
|
|
90
|
+
return !resolved.value.allColumnIds.includes(name.slice(0, -HEADER_SLOT_SUFFIX.length));
|
|
91
|
+
}));
|
|
81
92
|
function hasEntries(v) {
|
|
82
93
|
return typeof v === "object" && v !== null && Object.keys(v).length > 0;
|
|
83
94
|
}
|
|
@@ -556,28 +567,9 @@ defineExpose({
|
|
|
556
567
|
:style="borderedStyle"
|
|
557
568
|
v-bind="uTableProps"
|
|
558
569
|
>
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
<template v-if="$slots.empty" #empty>
|
|
564
|
-
<slot name="empty" />
|
|
565
|
-
</template>
|
|
566
|
-
|
|
567
|
-
<template v-if="$slots.loading" #loading>
|
|
568
|
-
<slot name="loading" />
|
|
569
|
-
</template>
|
|
570
|
-
|
|
571
|
-
<template v-if="$slots.caption" #caption>
|
|
572
|
-
<slot name="caption" />
|
|
573
|
-
</template>
|
|
574
|
-
|
|
575
|
-
<template v-if="$slots['body-top']" #body-top>
|
|
576
|
-
<slot name="body-top" />
|
|
577
|
-
</template>
|
|
578
|
-
|
|
579
|
-
<template v-if="$slots['body-bottom']" #body-bottom>
|
|
580
|
-
<slot name="body-bottom" />
|
|
570
|
+
<!-- 插槽名是联合类型,vue-tsc 会把作用域参数收敛成全部插槽 props 的交叉类型,转发时只能绕过 -->
|
|
571
|
+
<template v-for="name in forwardSlots" #[name]="slotProps" :key="name">
|
|
572
|
+
<slot :name="name" v-bind="slotProps ?? {}" />
|
|
581
573
|
</template>
|
|
582
574
|
</UTable>
|
|
583
575
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ColumnDef, ColumnMeta, ColumnPinningState, ColumnSizingState, VisibilityState } from '@tanstack/vue-table';
|
|
1
|
+
import type { ColumnDef, ColumnMeta, ColumnPinningState, ColumnSizingState, HeaderContext, VisibilityState } from '@tanstack/vue-table';
|
|
2
|
+
import type { VNode } from 'vue';
|
|
2
3
|
import type { DataTableDensityPreset, DataTableSizePreset, DataTableTreeSelectionStrategy } from '../../../types/data-table';
|
|
3
4
|
import type { DataTableProps } from '../../../types/data-table/component';
|
|
4
5
|
export declare const DENSITY_PRESETS: Record<DataTableDensityPreset, {
|
|
@@ -30,8 +31,12 @@ export interface ResolvedColumnState<T> {
|
|
|
30
31
|
subRowSelection?: boolean;
|
|
31
32
|
allColumnIds: string[];
|
|
32
33
|
}
|
|
34
|
+
/** 列表头插槽渲染器,键为 `<columnId>-header` */
|
|
35
|
+
export type HeaderSlotMap<T> = Record<string, ((ctx: HeaderContext<T, unknown>) => VNode[]) | undefined>;
|
|
33
36
|
export interface ResolveContext<T> {
|
|
34
37
|
options: DataTableProps<T>;
|
|
38
|
+
/** 用户提供的表头插槽,命中列 id 时取代该列 header 标签 */
|
|
39
|
+
headerSlots?: HeaderSlotMap<T>;
|
|
35
40
|
density: ColumnMeta<T, unknown>['class'] | null;
|
|
36
41
|
pinning: ColumnPinningState;
|
|
37
42
|
visibility: VisibilityState;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DataTableColumn } from '../../../types/data-table';
|
|
2
|
-
import type { ResolvedColumnState } from './constants';
|
|
2
|
+
import type { HeaderSlotMap, ResolvedColumnState } from './constants';
|
|
3
3
|
import type { DataTableProps } from '../../../types/data-table/component';
|
|
4
|
-
export declare function resolveColumns<T>(columns: DataTableColumn<T>[], options: DataTableProps<T>): ResolvedColumnState<T>;
|
|
4
|
+
export declare function resolveColumns<T>(columns: DataTableColumn<T>[], options: DataTableProps<T>, headerSlots?: HeaderSlotMap<T>): ResolvedColumnState<T>;
|
|
@@ -29,10 +29,11 @@ function resolveColumn(col, ctx, inheritedFixed) {
|
|
|
29
29
|
}
|
|
30
30
|
return col;
|
|
31
31
|
}
|
|
32
|
-
export function resolveColumns(columns, options) {
|
|
32
|
+
export function resolveColumns(columns, options, headerSlots) {
|
|
33
33
|
let groupCounter = 0;
|
|
34
34
|
const ctx = {
|
|
35
35
|
options,
|
|
36
|
+
headerSlots,
|
|
36
37
|
density: options.density ? isString(options.density) ? DENSITY_PRESETS[options.density] : options.density : null,
|
|
37
38
|
pinning: { left: [], right: [] },
|
|
38
39
|
visibility: {},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h, isVNode } from "vue";
|
|
1
|
+
import { Fragment, h, isVNode } from "vue";
|
|
2
2
|
import { resolveCallbackValue, resolveColumnFlag, resolveTemplate } from "./utils.js";
|
|
3
3
|
import DataTableCellTooltip from "../components/CellTooltip.vue";
|
|
4
4
|
import { UButton } from "#components";
|
|
@@ -112,7 +112,7 @@ export function renderHeaderActions(ctx, col, options, label, sortable, pinable,
|
|
|
112
112
|
const leading = actions.filter((a) => a.position === "leading").map((a) => a.render(ctx));
|
|
113
113
|
const trailing = actions.filter((a) => a.position === "trailing").map((a) => a.render(ctx));
|
|
114
114
|
const resizeHandle = resizable ? buildResizeHandle(ctx, options) : null;
|
|
115
|
-
const labelNode = isVNode(label) ? label : h("span", { class: "truncate" }, String(label ?? ""));
|
|
115
|
+
const labelNode = Array.isArray(label) ? h(Fragment, label) : isVNode(label) ? label : h("span", { class: "truncate" }, String(label ?? ""));
|
|
116
116
|
return h("div", { class: "flex items-center gap-1 group" }, [
|
|
117
117
|
...leading,
|
|
118
118
|
labelNode,
|
|
@@ -133,9 +133,10 @@ export function resolveDataColumn(col, ctx, inheritedFixed) {
|
|
|
133
133
|
if (col.visibility === false) ctx.visibility[id] = false;
|
|
134
134
|
ctx.allColumnIds.push(id);
|
|
135
135
|
const cellRenderer = buildDataCellRenderer(col, options);
|
|
136
|
+
const headerSlot = ctx.headerSlots?.[`${id}-header`];
|
|
136
137
|
const def = {
|
|
137
138
|
accessorKey: id,
|
|
138
|
-
header: effectiveSortable || effectivePinable || effectiveResizable ? (hctx) => renderHeaderActions(hctx, col, options, col.header ?? id, effectiveSortable, effectivePinable, effectiveResizable) : col.header ?? id,
|
|
139
|
+
header: effectiveSortable || effectivePinable || effectiveResizable ? (hctx) => renderHeaderActions(hctx, col, options, headerSlot ? headerSlot(hctx) : col.header ?? id, effectiveSortable, effectivePinable, effectiveResizable) : headerSlot ? (hctx) => headerSlot(hctx) : col.header ?? id,
|
|
139
140
|
...col.minSize != null && { minSize: col.minSize },
|
|
140
141
|
...col.maxSize != null && { maxSize: col.maxSize },
|
|
141
142
|
...resolvedSize != null && { size: resolvedSize },
|
|
@@ -42,10 +42,11 @@ function buildSpecialColumnDef(col, type, ctx, render) {
|
|
|
42
42
|
ctx.flags.hasResizing ||= effectiveResizable;
|
|
43
43
|
const effectiveAlign = col.align ?? defaults.align;
|
|
44
44
|
const alignClass = resolveAlignClass(effectiveAlign);
|
|
45
|
+
const headerSlot = ctx.headerSlots?.[`${id}-header`];
|
|
45
46
|
const resolvedHeader = effectivePinable || effectiveResizable ? (hctx) => {
|
|
46
|
-
const label = isFunction(render.header) ? render.header(hctx) : render.header ?? "";
|
|
47
|
+
const label = headerSlot ? headerSlot(hctx) : isFunction(render.header) ? render.header(hctx) : render.header ?? "";
|
|
47
48
|
return renderHeaderActions(hctx, col, options, label, false, effectivePinable, effectiveResizable);
|
|
48
|
-
} : render.header;
|
|
49
|
+
} : headerSlot ? (hctx) => headerSlot(hctx) : render.header;
|
|
49
50
|
const classMeta = buildClassMeta(density, alignClass, effectiveResizable, defaults.tdClass);
|
|
50
51
|
const checkboxClass = type === "selection" ? {
|
|
51
52
|
td: [classMeta?.td, "[&:has([role=checkbox])]:px-0"].filter(Boolean).join(" "),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CellContext, ColumnDefTemplate, ColumnMeta, PaginationState, Row, Table, TableMeta } from '@tanstack/vue-table';
|
|
1
|
+
import type { CellContext, ColumnDefTemplate, ColumnMeta, HeaderContext, PaginationState, Row, Table, TableMeta } from '@tanstack/vue-table';
|
|
2
2
|
import type { ButtonProps, TableData, TableProps, TableRow, TooltipProps } from '@nuxt/ui';
|
|
3
3
|
import type { FirstParameter, OmitByKey } from '@movk/core';
|
|
4
4
|
import type { VNode } from 'vue';
|
|
@@ -180,7 +180,7 @@ export interface DataTablePaginationSlotProps<T extends TableData> {
|
|
|
180
180
|
setPage: (page: number) => void;
|
|
181
181
|
setPageSize: (pageSize: unknown) => void;
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
interface DataTableNamedSlots<T extends TableData> {
|
|
184
184
|
'expanded'(props: {
|
|
185
185
|
row: Row<T>;
|
|
186
186
|
}): VNode[];
|
|
@@ -193,3 +193,11 @@ export interface DataTableSlots<T extends TableData> {
|
|
|
193
193
|
'pagination-summary'(props: FirstParameter<DataTablePaginationSlots<T>['summary']>): VNode[];
|
|
194
194
|
'pagination-actions'(props: FirstParameter<DataTablePaginationSlots<T>['actions']>): VNode[];
|
|
195
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* 按列 id 命名的动态插槽,转发至 UTable:
|
|
198
|
+
* `<id>-header` 由 MDataTable 注入列表头标签位(排序/固定按钮与 resize 手柄保留),
|
|
199
|
+
* `<id>-cell` / `<id>-footer` 整体替换单元格与表尾内容
|
|
200
|
+
*/
|
|
201
|
+
type DataTableColumnSlots<T extends TableData> = Record<`${string}-header` | `${string}-footer`, (props: HeaderContext<T, unknown>) => VNode[]> & Record<`${string}-cell`, (props: CellContext<T, unknown>) => VNode[]>;
|
|
202
|
+
export type DataTableSlots<T extends TableData> = DataTableNamedSlots<T> & Partial<DataTableColumnSlots<T>>;
|
|
203
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movk/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.1",
|
|
5
5
|
"packageManager": "pnpm@11.22.0",
|
|
6
6
|
"description": "An engineering suite built on Nuxt UI: schema-driven AutoForm (Zod v4), a full-featured DataTable, standalone UI components and composables. Get the full capabilities — including API integration with auth & progress — in Nuxt 4, and use its UI, forms, tables and theming in plain Vue + Vite via the Vite plugin.",
|
|
7
7
|
"author": "YiXuan <mhaibaraai@gmail.com>",
|