@movk/nuxt 1.4.1 → 1.4.2
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/README.en.md +308 -0
- package/README.md +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/StarRating.d.vue.ts +2 -2
- package/dist/runtime/components/StarRating.vue.d.ts +2 -2
- package/dist/runtime/components/Tree.vue +4 -3
- package/dist/runtime/composables/useApiFetch.d.ts +4 -1
- package/dist/runtime/composables/useApiFetch.js +14 -2
- package/dist/runtime/domains/api/deep-to-value.d.ts +9 -0
- package/dist/runtime/domains/api/deep-to-value.js +11 -0
- package/dist/runtime/domains/api/interceptors/compose.d.ts +24 -0
- package/dist/runtime/domains/api/interceptors/compose.js +18 -0
- package/dist/runtime/domains/auto-form/controls.d.ts +7 -6
- package/dist/runtime/domains/data-table/columns/resize.d.ts +4 -0
- package/dist/runtime/domains/data-table/columns/resize.js +134 -0
- package/dist/runtime/domains/data-table/columns/resolve-data-column.js +3 -46
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.js +2 -1
- package/dist/runtime/domains/data-table/columns/style.d.ts +1 -0
- package/dist/runtime/domains/data-table/columns/style.js +22 -5
- package/dist/runtime/domains/tree/components/TreeToolbar.vue +1 -1
- package/dist/runtime/plugins/api.factory.js +9 -3
- package/dist/runtime/types/auto-form/zod-factory.d.ts +20 -5
- package/dist/runtime/types/components/date-picker.d.ts +3 -0
- package/dist/runtime/types/components/tree.d.ts +1 -0
- package/package.json +5 -5
package/README.en.md
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
[](https://nuxt.mhaibaraai.cn/)
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.md)
|
|
4
|
+
|
|
5
|
+
> A UI engineering toolkit built on top of Nuxt UI — Schema-driven AutoForm (Zod v4), a full-featured DataTable, standalone components and Composables. Get the complete capability set in Nuxt 4, including API integration with authentication and progress tracking; its UI, forms, tables, and theming also work directly in plain Vue + Vite projects through a Vite plugin (the API integration domain is Nuxt-only).
|
|
6
|
+
|
|
7
|
+
[](https://nuxt.mhaibaraai.cn/mcp/deeplink)
|
|
8
|
+
[](https://nuxt.mhaibaraai.cn/mcp/deeplink?ide=vscode)
|
|
9
|
+
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
[](https://nuxt.com/)
|
|
12
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
13
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
14
|
+
[![License][license-src]][license-href]
|
|
15
|
+
[![Nuxt UI][nuxt-ui-src]][nuxt-ui-href]
|
|
16
|
+
|
|
17
|
+
- 📖 [Online Documentation](https://nuxt.mhaibaraai.cn)
|
|
18
|
+
|
|
19
|
+
## ✨ Features
|
|
20
|
+
|
|
21
|
+
Movk Nuxt is a UI engineering toolkit built on top of Nuxt UI, offering two ways to use it: the complete capability set with API integration in **Nuxt 4**, or its UI layer in plain **Vue + Vite** projects through a **Vite plugin**. The supported frameworks for each capability are:
|
|
22
|
+
|
|
23
|
+
- **AutoForm — Schema-driven forms** (✅ Nuxt | ✅ Vue + Vite) - Built on Zod v4 with a "define-is-render" model: a single Schema declares the data structure, validation rules, and UI configuration at once, automatically generating a complete form interface.
|
|
24
|
+
- **DataTable — Data table** (✅ Nuxt | ✅ Vue + Vite) - Wraps TanStack Table, covering data columns, special columns (selection / index / expand / actions), tree-structured data, row interactions, appearance customization, pagination, and load-more.
|
|
25
|
+
- **Standalone component library** (✅ Nuxt | ✅ Vue + Vite) - General-purpose UI components such as DatePicker, StarRating, PillGroup, SearchForm, Tree, WithCopy, and ThemePicker, usable on their own without AutoForm.
|
|
26
|
+
- **Theming and Composables** (✅ Nuxt | ✅ Vue + Vite) - Non-server composition functions such as useTheme (theme read/write and export), useMessageBox (imperative dialogs), and useDateFormatter (i18n dates).
|
|
27
|
+
- **API integration system** (✅ Nuxt | ❌ Vue + Vite) - The useApiFetch / useLazyApiFetch / useClientApiFetch trio plus useUploadWithProgress / useDownloadWithProgress, providing multi-endpoint support, automatic authentication, business status-code checks, data unwrapping, Toast notifications, and progress monitoring; **depends on the Nuxt server runtime and is available in Nuxt mode only**.
|
|
28
|
+
- **Type safety** - Full TypeScript type inference, from Schema to form data, with component prop callbacks and event handler types derivable via indexed access.
|
|
29
|
+
- **AI friendly** - Built-in MCP Server and llms.txt, so components, composables, and docs can be retrieved by AI agents.
|
|
30
|
+
|
|
31
|
+
## 🚀 Getting Started
|
|
32
|
+
|
|
33
|
+
### Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# pnpm
|
|
37
|
+
pnpm add @movk/nuxt @nuxt/ui zod
|
|
38
|
+
|
|
39
|
+
# yarn
|
|
40
|
+
yarn add @movk/nuxt @nuxt/ui zod
|
|
41
|
+
|
|
42
|
+
# npm
|
|
43
|
+
npm install @movk/nuxt @nuxt/ui zod
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Nuxt
|
|
47
|
+
|
|
48
|
+
Register the module in `nuxt.config.ts`:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
export default defineNuxtConfig({
|
|
52
|
+
modules: ['@movk/nuxt'],
|
|
53
|
+
movk: {
|
|
54
|
+
prefix: 'M' // Component prefix, defaults to 'M'
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Vue / Vite
|
|
60
|
+
|
|
61
|
+
In a plain Vue + Vite project, use the UI layer (components, theming, AutoForm, DataTable, non-server Composables) through the Vite plugin + Vue plugin. **The API integration domain is not available in this mode.**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm add @movk/nuxt @nuxt/ui zod tailwindcss vue-router
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// vite.config.ts
|
|
69
|
+
import { defineConfig } from 'vite'
|
|
70
|
+
import vue from '@vitejs/plugin-vue'
|
|
71
|
+
import movk from '@movk/nuxt/vite'
|
|
72
|
+
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
plugins: [vue(), movk()]
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// src/main.ts
|
|
80
|
+
import './assets/css/main.css'
|
|
81
|
+
import { createApp } from 'vue'
|
|
82
|
+
import { createRouter, createWebHistory } from 'vue-router'
|
|
83
|
+
import movk from '@movk/nuxt/vue-plugin'
|
|
84
|
+
import App from './App.vue'
|
|
85
|
+
|
|
86
|
+
const router = createRouter({ routes: [], history: createWebHistory() })
|
|
87
|
+
createApp(App).use(router).use(movk).mount('#app')
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```css
|
|
91
|
+
/* src/assets/css/main.css — chains Tailwind CSS + Nuxt UI + Movk theme */
|
|
92
|
+
@import "@movk/nuxt";
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Wrap the root component in `<UApp>` (required for Toast / Tooltip / useMessageBox). See [Online Docs · Vue / Vite](https://nuxt.mhaibaraai.cn/docs/getting-started/vue).
|
|
96
|
+
|
|
97
|
+
### Basic Example
|
|
98
|
+
|
|
99
|
+
Create a simple user registration form:
|
|
100
|
+
|
|
101
|
+
```vue
|
|
102
|
+
<script setup lang="ts">
|
|
103
|
+
import type { FormSubmitEvent } from '@nuxt/ui'
|
|
104
|
+
import type { z } from 'zod'
|
|
105
|
+
|
|
106
|
+
const { afz } = useAutoForm()
|
|
107
|
+
|
|
108
|
+
// Define the Schema
|
|
109
|
+
const schema = afz.object({
|
|
110
|
+
username: afz.string().min(3).meta({ label: 'Username' }),
|
|
111
|
+
email: afz.email().meta({ label: 'Email' }),
|
|
112
|
+
age: afz.number().min(18).meta({ label: 'Age' })
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// Type inference
|
|
116
|
+
type Schema = z.output<typeof schema>
|
|
117
|
+
|
|
118
|
+
// Form state
|
|
119
|
+
const form = ref<Partial<Schema>>({})
|
|
120
|
+
|
|
121
|
+
// Submit handler
|
|
122
|
+
async function onSubmit(event: FormSubmitEvent<Schema>) {
|
|
123
|
+
console.log('Submitted data:', event.data)
|
|
124
|
+
}
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<template>
|
|
128
|
+
<MAutoForm :schema="schema" :state="form" @submit="onSubmit" />
|
|
129
|
+
</template>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 📦 Core Features
|
|
133
|
+
|
|
134
|
+
### Standalone Components
|
|
135
|
+
|
|
136
|
+
High-quality, ready-to-use UI components across four categories: input enhancements, forms, feedback, and advanced interactions.
|
|
137
|
+
|
|
138
|
+
### DataTable - Full-featured Data Table
|
|
139
|
+
|
|
140
|
+
`MDataTable`, wrapping TanStack Table, driven by declarative column configuration:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import type { DataTableColumn } from '@movk/nuxt'
|
|
144
|
+
|
|
145
|
+
const columns: DataTableColumn<Person>[] = [
|
|
146
|
+
{ type: 'selection' }, // Special column: row selection
|
|
147
|
+
{ accessorKey: 'name', header: 'Name', sortable: true, pinable: true },
|
|
148
|
+
{ accessorKey: 'salary', header: 'Salary', sortable: true, truncate: true },
|
|
149
|
+
{ type: 'actions', actions: row => [{ label: 'Edit', onClick: () => edit(row) }] }
|
|
150
|
+
]
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Supports data columns (sorting / column pinning / column resize / truncate + Tooltip / visibility), special columns (selection / index / expand / actions / grouping), tree-structured data with cascading selection, row interactions (click / expand / context menu), appearance customization, client/server-side pagination, and load-more.
|
|
154
|
+
|
|
155
|
+
### AutoForm - Schema-driven Form System
|
|
156
|
+
|
|
157
|
+
A "define-is-render" form solution based on Zod Schemas:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const { afz } = useAutoForm()
|
|
161
|
+
|
|
162
|
+
const schema = afz.object({
|
|
163
|
+
// Basic types
|
|
164
|
+
username: afz.string().min(3),
|
|
165
|
+
age: afz.number().min(18),
|
|
166
|
+
isActive: afz.boolean(),
|
|
167
|
+
|
|
168
|
+
// Advanced types
|
|
169
|
+
email: afz.email(),
|
|
170
|
+
birthdate: afz.calendarDate(),
|
|
171
|
+
role: afz.enum(['admin', 'user']),
|
|
172
|
+
avatar: afz.file(),
|
|
173
|
+
|
|
174
|
+
// Nested objects
|
|
175
|
+
profile: afz.object({
|
|
176
|
+
bio: afz.string(),
|
|
177
|
+
website: afz.url()
|
|
178
|
+
}),
|
|
179
|
+
|
|
180
|
+
// Arrays
|
|
181
|
+
tags: afz.array(afz.string())
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Composables
|
|
186
|
+
|
|
187
|
+
#### useDateFormatter
|
|
188
|
+
|
|
189
|
+
A powerful tool for date formatting, parsing, and range handling:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const { format, parse, isDateValue, formatRange } = useDateFormatter()
|
|
193
|
+
|
|
194
|
+
// Format a date
|
|
195
|
+
const formatted = format(new Date(), 'iso') // "2024-01-01"
|
|
196
|
+
|
|
197
|
+
// Parse a date string
|
|
198
|
+
const date = parse('2024-01-01', 'iso')
|
|
199
|
+
|
|
200
|
+
// Format a date range
|
|
201
|
+
const range = formatRange({ start: date1, end: date2 }, 'iso')
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### useAutoForm
|
|
205
|
+
|
|
206
|
+
The core logic wrapper for AutoForm:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
const { afz, defineControl, getAutoFormMetadata } = useAutoForm()
|
|
210
|
+
|
|
211
|
+
// Create a Schema
|
|
212
|
+
const schema = afz.object({
|
|
213
|
+
username: afz.string()
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
// Define a custom control
|
|
217
|
+
const customControl = defineControl({
|
|
218
|
+
component: MyCustomInput,
|
|
219
|
+
controlProps: { class: 'w-full' }
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
// Get field metadata
|
|
223
|
+
const meta = getAutoFormMetadata(schema)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### useApiFetch
|
|
227
|
+
|
|
228
|
+
An API request wrapper built on Nuxt's useFetch:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
// Basic usage
|
|
232
|
+
const { data, pending, error } = await useApiFetch<User[]>('/users')
|
|
233
|
+
|
|
234
|
+
// POST request
|
|
235
|
+
const { data } = await useApiFetch<User>('/users', {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
body: { name: 'test' },
|
|
238
|
+
toast: { successMessage: 'Created successfully' }
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
// Use another endpoint
|
|
242
|
+
const { data } = await useApiFetch('/users', { endpoint: 'v2' })
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### useUploadWithProgress
|
|
246
|
+
|
|
247
|
+
File upload with progress monitoring:
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
const { progress, uploading, upload, abort } = useUploadWithProgress()
|
|
251
|
+
|
|
252
|
+
// Upload a file
|
|
253
|
+
await upload('/api/upload', file, {
|
|
254
|
+
fieldName: 'avatar',
|
|
255
|
+
onSuccess: (response) => console.log('Upload succeeded:', response)
|
|
256
|
+
})
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
#### useDownloadWithProgress
|
|
260
|
+
|
|
261
|
+
File download with progress monitoring:
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
const { progress, downloading, download, abort } = useDownloadWithProgress()
|
|
265
|
+
|
|
266
|
+
// Download a file
|
|
267
|
+
await download('/api/export/report', {
|
|
268
|
+
filename: 'report.pdf',
|
|
269
|
+
onSuccess: (filename) => console.log('Download complete:', filename)
|
|
270
|
+
})
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 🏗️ Architecture Layers
|
|
274
|
+
|
|
275
|
+
Movk Nuxt adopts a clear layered architecture:
|
|
276
|
+
|
|
277
|
+
- **Core Systems** - AutoForm (Schema-driven forms), DataTable (data table)
|
|
278
|
+
- **API System** - useApiFetch / useLazyApiFetch / useClientApiFetch, useUploadWithProgress, useDownloadWithProgress, providing a complete API request solution
|
|
279
|
+
- **Standalone Components** - Standalone UI components such as DatePicker, StarRating, PillGroup, SearchForm, Tree, WithCopy, and ThemePicker
|
|
280
|
+
- **Composables** - General-purpose composition functions such as useDateFormatter, useTheme, useMessageBox, and useAutoForm
|
|
281
|
+
- **Foundation** - Built on [Nuxt UI](https://ui.nuxt.com), [Zod v4](https://zod.dev), [VueUse](https://vueuse.org), and [TanStack Table](https://tanstack.com/table)
|
|
282
|
+
|
|
283
|
+
## ⚡ Tech Stack
|
|
284
|
+
|
|
285
|
+
- [Nuxt 4](https://nuxt.com/) - The Intuitive Vue Framework
|
|
286
|
+
- [Nuxt UI](https://ui.nuxt.com/) - A UI Library for Modern Web Apps
|
|
287
|
+
- [Zod v4](https://zod.dev/) - TypeScript-first schema validation
|
|
288
|
+
- [TypeScript](https://www.typescriptlang.org/) - JavaScript with syntax for types
|
|
289
|
+
- [VueUse](https://vueuse.org/) - Collection of Vue Composition Utilities
|
|
290
|
+
- [Vitest](https://vitest.dev/) - Next Generation Testing Framework
|
|
291
|
+
|
|
292
|
+
## 📄 License
|
|
293
|
+
|
|
294
|
+
[MIT](./LICENSE) License © 2024-PRESENT [YiXuan](https://github.com/mhaibaraai)
|
|
295
|
+
|
|
296
|
+
<!-- Badges -->
|
|
297
|
+
|
|
298
|
+
[npm-version-src]: https://img.shields.io/npm/v/@movk/nuxt?style=flat&colorA=080f12&colorB=1fa669
|
|
299
|
+
[npm-version-href]: https://npmjs.com/package/@movk/nuxt
|
|
300
|
+
|
|
301
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@movk/nuxt?style=flat&colorA=080f12&colorB=1fa669
|
|
302
|
+
[npm-downloads-href]: https://npmjs.com/package/@movk/nuxt
|
|
303
|
+
|
|
304
|
+
[license-src]: https://img.shields.io/github/license/mhaibaraai/movk-nuxt.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
305
|
+
[license-href]: https://github.com/mhaibaraai/movk-nuxt/blob/main/LICENSE
|
|
306
|
+
|
|
307
|
+
[nuxt-ui-src]: https://img.shields.io/badge/Nuxt%20UI-4-00DC82?style=flat&colorA=080f12
|
|
308
|
+
[nuxt-ui-href]: https://ui.nuxt.com
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
[](https://nuxt.mhaibaraai.cn/)
|
|
2
2
|
|
|
3
|
+
简体中文 | [English](./README.en.md)
|
|
4
|
+
|
|
3
5
|
> 构建在 Nuxt UI 之上的 UI 工程套件 —— Schema 驱动的 AutoForm(Zod v4)、功能完备的 DataTable、独立组件与 Composables。在 Nuxt 4 中获得含认证与进度追踪的 API 集成在内的完整能力;其 UI、表单、表格与主题亦可经 Vite 插件直接用于纯 Vue + Vite 项目(API 集成域仅 Nuxt)。
|
|
4
6
|
|
|
5
7
|
[](https://nuxt.mhaibaraai.cn/mcp/deeplink)
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -29,12 +29,12 @@ type __VLS_Slots = {} & {
|
|
|
29
29
|
};
|
|
30
30
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
31
31
|
change: (value: number) => any;
|
|
32
|
-
"update:modelValue": (value: number) => any;
|
|
33
32
|
hover: (value: number | null) => any;
|
|
33
|
+
"update:modelValue": (value: number) => any;
|
|
34
34
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
35
35
|
onChange?: ((value: number) => any) | undefined;
|
|
36
|
-
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
37
36
|
onHover?: ((value: number | null) => any) | undefined;
|
|
37
|
+
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
38
38
|
}>, {
|
|
39
39
|
max: number;
|
|
40
40
|
showBadge: boolean;
|
|
@@ -29,12 +29,12 @@ type __VLS_Slots = {} & {
|
|
|
29
29
|
};
|
|
30
30
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
31
31
|
change: (value: number) => any;
|
|
32
|
-
"update:modelValue": (value: number) => any;
|
|
33
32
|
hover: (value: number | null) => any;
|
|
33
|
+
"update:modelValue": (value: number) => any;
|
|
34
34
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
35
35
|
onChange?: ((value: number) => any) | undefined;
|
|
36
|
-
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
37
36
|
onHover?: ((value: number | null) => any) | undefined;
|
|
37
|
+
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
38
38
|
}>, {
|
|
39
39
|
max: number;
|
|
40
40
|
showBadge: boolean;
|
|
@@ -38,7 +38,8 @@ const props = defineProps({
|
|
|
38
38
|
loadChildren: { type: Function, required: false },
|
|
39
39
|
toolbar: { type: Boolean, required: false },
|
|
40
40
|
checkable: { type: Boolean, required: false },
|
|
41
|
-
ui: { type: Object, required: false }
|
|
41
|
+
ui: { type: Object, required: false },
|
|
42
|
+
class: { type: null, required: false }
|
|
42
43
|
});
|
|
43
44
|
const emit = defineEmits(["update:modelValue", "update:expanded", "update:search", "change"]);
|
|
44
45
|
defineSlots();
|
|
@@ -275,7 +276,7 @@ defineExpose({
|
|
|
275
276
|
</script>
|
|
276
277
|
|
|
277
278
|
<template>
|
|
278
|
-
<div :class="extraUi.container">
|
|
279
|
+
<div :class="extraUi.container" data-slot="container">
|
|
279
280
|
<slot
|
|
280
281
|
v-if="props.toolbar || props.searchable || slots.toolbar"
|
|
281
282
|
name="toolbar"
|
|
@@ -314,7 +315,7 @@ defineExpose({
|
|
|
314
315
|
</TreeToolbar>
|
|
315
316
|
</slot>
|
|
316
317
|
|
|
317
|
-
<div v-if="isEmpty" :class="extraUi.empty">
|
|
318
|
+
<div v-if="isEmpty" :class="extraUi.empty" data-slot="empty">
|
|
318
319
|
<slot name="empty">
|
|
319
320
|
无匹配结果
|
|
320
321
|
</slot>
|
|
@@ -38,13 +38,16 @@ import type { UseApiFetchOptions, UseApiFetchReturn } from '../types/api';
|
|
|
38
38
|
* // 跳过解包,拿原始响应(与 skipBusinessCheck 正交)
|
|
39
39
|
* const { data } = await useApiFetch<ApiResponse>('/external', { skipUnwrap: true })
|
|
40
40
|
*
|
|
41
|
-
* // 用户自定义 hooks
|
|
41
|
+
* // 用户自定义 hooks:与内置拦截器组合(内置先执行),不会覆盖认证/业务校验/解包/Toast
|
|
42
42
|
* const { data } = await useApiFetch('/users', {
|
|
43
43
|
* onResponse({ response }) {
|
|
44
44
|
* // response._data 已是解包后的业务数据(除非传入 skipUnwrap: true)
|
|
45
|
+
* // 仅业务成功时触发;返回值被 ofetch 忽略,副作用专用
|
|
45
46
|
* console.log('自定义处理:', response._data)
|
|
46
47
|
* }
|
|
47
48
|
* })
|
|
49
|
+
*
|
|
50
|
+
* // 变形输出请用 transform 或直接消费自动解包后的 data,而非在 onResponse 中 return
|
|
48
51
|
* ```
|
|
49
52
|
*/
|
|
50
53
|
export declare function useApiFetch<T = unknown, DataT = T>(url: NitroFetchRequest | (() => NitroFetchRequest), options?: UseApiFetchOptions<T, DataT>): UseApiFetchReturn<DataT>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { computed, toValue } from "vue";
|
|
2
2
|
import { useNuxtApp, useFetch } from "#app";
|
|
3
3
|
import { buildApiFetchKey } from "../domains/api/fetch-key.js";
|
|
4
|
+
import { deepToValue } from "../domains/api/deep-to-value.js";
|
|
5
|
+
import { composeHook, getInterceptors } from "../domains/api/interceptors/compose.js";
|
|
4
6
|
export function useApiFetch(url, options = {}) {
|
|
5
7
|
const { $api } = useNuxtApp();
|
|
6
8
|
const {
|
|
@@ -11,6 +13,15 @@ export function useApiFetch(url, options = {}) {
|
|
|
11
13
|
...fetchOptions
|
|
12
14
|
} = options;
|
|
13
15
|
const apiInstance = endpoint ? $api.use(endpoint) : $api;
|
|
16
|
+
const movk = getInterceptors(apiInstance);
|
|
17
|
+
const composedHooks = movk ? {
|
|
18
|
+
onRequest: composeHook(movk.onRequest, fetchOptions.onRequest),
|
|
19
|
+
onResponse: composeHook(movk.onResponse, fetchOptions.onResponse),
|
|
20
|
+
onResponseError: composeHook(movk.onResponseError, fetchOptions.onResponseError)
|
|
21
|
+
} : {};
|
|
22
|
+
const definedHooks = Object.fromEntries(
|
|
23
|
+
Object.entries(composedHooks).filter(([, value]) => value !== void 0)
|
|
24
|
+
);
|
|
14
25
|
const fetchKey = computed(() => {
|
|
15
26
|
const userKey = toValue(fetchOptions.key);
|
|
16
27
|
if (userKey) return userKey;
|
|
@@ -21,12 +32,13 @@ export function useApiFetch(url, options = {}) {
|
|
|
21
32
|
toast,
|
|
22
33
|
method: toValue(fetchOptions.method),
|
|
23
34
|
url: typeof url === "function" ? url() : url,
|
|
24
|
-
query:
|
|
25
|
-
body:
|
|
35
|
+
query: deepToValue(fetchOptions.query),
|
|
36
|
+
body: deepToValue(fetchOptions.body)
|
|
26
37
|
});
|
|
27
38
|
});
|
|
28
39
|
return useFetch(url, {
|
|
29
40
|
...fetchOptions,
|
|
41
|
+
...definedHooks,
|
|
30
42
|
key: fetchKey,
|
|
31
43
|
$fetch: apiInstance,
|
|
32
44
|
context: { toast, skipBusinessCheck, skipUnwrap }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 递归解包嵌套 ref,产出纯值结构
|
|
3
|
+
*
|
|
4
|
+
* @description Vue 的 toValue 仅解包顶层 ref,不会解包普通对象 / 数组内部的嵌套 ref。
|
|
5
|
+
* useApiFetch 的 query / body 常写成 `{ key: ref }`(Nuxt useFetch 允许字段为 ref),
|
|
6
|
+
* 若仅浅解包,buildApiFetchKey 序列化时会把 Ref 对象本身计入,导致不同值派生出相同 key 而缓存碰撞。
|
|
7
|
+
* 仅对纯对象 / 数组递归;Date / File / FormData 等非纯对象原样返回,避免破坏与栈溢出。
|
|
8
|
+
*/
|
|
9
|
+
export declare function deepToValue(value: unknown): unknown;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { toValue } from "vue";
|
|
2
|
+
export function deepToValue(value) {
|
|
3
|
+
const resolved = toValue(value);
|
|
4
|
+
if (Array.isArray(resolved)) return resolved.map(deepToValue);
|
|
5
|
+
if (resolved !== null && typeof resolved === "object" && Object.getPrototypeOf(resolved) === Object.prototype) {
|
|
6
|
+
return Object.fromEntries(
|
|
7
|
+
Object.entries(resolved).map(([k, v]) => [k, deepToValue(v)])
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return resolved;
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { $Fetch } from 'nitropack/types';
|
|
2
|
+
import type { FetchHook } from 'ofetch';
|
|
3
|
+
/**
|
|
4
|
+
* 单端点的 movk 内置拦截器集合
|
|
5
|
+
* @description 由 api.factory 在创建 $fetch 实例时挂到实例上,供 useApiFetch 在用户传入同名钩子时组合复用
|
|
6
|
+
*/
|
|
7
|
+
export interface MovkInterceptors {
|
|
8
|
+
onRequest: FetchHook;
|
|
9
|
+
onResponse: FetchHook;
|
|
10
|
+
onResponseError: FetchHook;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 把 movk 内置拦截器以非枚举符号挂到 $fetch 实例
|
|
14
|
+
* @description 符号键不进入 ApiInstance 公共类型,强转集中于此
|
|
15
|
+
*/
|
|
16
|
+
export declare function attachInterceptors(instance: $Fetch, interceptors: MovkInterceptors): void;
|
|
17
|
+
/** 读取实例上挂载的 movk 内置拦截器 */
|
|
18
|
+
export declare function getInterceptors(instance: $Fetch): MovkInterceptors | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* 组合 movk 内置钩子与用户钩子为数组(movk 先执行)
|
|
21
|
+
* @description 用户未传钩子时返回 undefined,让 ofetch 沿用实例 default(不覆盖);
|
|
22
|
+
* 用户传入时返回 `[movkHook, ...userHooks]`,使用户钩子拿到 movk 处理后的上下文
|
|
23
|
+
*/
|
|
24
|
+
export declare function composeHook<H>(movkHook: H, userHook: H | H[] | undefined): H[] | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const MOVK_INTERCEPTORS = Symbol("movk:interceptors");
|
|
2
|
+
export function attachInterceptors(instance, interceptors) {
|
|
3
|
+
Object.defineProperty(instance, MOVK_INTERCEPTORS, {
|
|
4
|
+
value: interceptors,
|
|
5
|
+
enumerable: false,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export function getInterceptors(instance) {
|
|
10
|
+
return instance[MOVK_INTERCEPTORS];
|
|
11
|
+
}
|
|
12
|
+
function toArray(value) {
|
|
13
|
+
return Array.isArray(value) ? value : [value];
|
|
14
|
+
}
|
|
15
|
+
export function composeHook(movkHook, userHook) {
|
|
16
|
+
if (userHook === void 0) return void 0;
|
|
17
|
+
return [movkHook, ...toArray(userHook)];
|
|
18
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IsComponent } from '@movk/core';
|
|
2
2
|
import type { AutoFormControl, _Unset } from '../../types/auto-form/controls';
|
|
3
3
|
import type { InputProps, InputSlots, TextareaProps, TextareaSlots } from '@nuxt/ui';
|
|
4
|
+
import type { CalendarDateControlProps } from '../../types/components/date-picker';
|
|
4
5
|
import { UInput, UTextarea } from '#components';
|
|
5
6
|
export declare function defineControl<C extends IsComponent, P = _Unset, S = _Unset>(e: AutoFormControl<C, P, S>): AutoFormControl<C, P, S>;
|
|
6
7
|
declare const DEFAULT_CONTROL_COMPONENTS: {
|
|
@@ -423,12 +424,12 @@ declare const DEFAULT_CONTROL_COMPONENTS: {
|
|
|
423
424
|
modelValue?: number;
|
|
424
425
|
}> & Readonly<{
|
|
425
426
|
onChange?: ((value: number) => any) | undefined;
|
|
426
|
-
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
427
427
|
onHover?: ((value: number | null) => any) | undefined;
|
|
428
|
+
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
428
429
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
429
430
|
change: (value: number) => any;
|
|
430
|
-
"update:modelValue": (value: number) => any;
|
|
431
431
|
hover: (value: number | null) => any;
|
|
432
|
+
"update:modelValue": (value: number) => any;
|
|
432
433
|
}, import("vue").PublicProps, {
|
|
433
434
|
max: number;
|
|
434
435
|
showBadge: boolean;
|
|
@@ -448,8 +449,8 @@ declare const DEFAULT_CONTROL_COMPONENTS: {
|
|
|
448
449
|
modelValue?: number;
|
|
449
450
|
}> & Readonly<{
|
|
450
451
|
onChange?: ((value: number) => any) | undefined;
|
|
451
|
-
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
452
452
|
onHover?: ((value: number | null) => any) | undefined;
|
|
453
|
+
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
453
454
|
}>, {}, {}, {}, {}, {
|
|
454
455
|
max: number;
|
|
455
456
|
showBadge: boolean;
|
|
@@ -466,12 +467,12 @@ declare const DEFAULT_CONTROL_COMPONENTS: {
|
|
|
466
467
|
modelValue?: number;
|
|
467
468
|
}> & Readonly<{
|
|
468
469
|
onChange?: ((value: number) => any) | undefined;
|
|
469
|
-
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
470
470
|
onHover?: ((value: number | null) => any) | undefined;
|
|
471
|
+
"onUpdate:modelValue"?: ((value: number) => any) | undefined;
|
|
471
472
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
472
473
|
change: (value: number) => any;
|
|
473
|
-
"update:modelValue": (value: number) => any;
|
|
474
474
|
hover: (value: number | null) => any;
|
|
475
|
+
"update:modelValue": (value: number) => any;
|
|
475
476
|
}, string, {
|
|
476
477
|
max: number;
|
|
477
478
|
showBadge: boolean;
|
|
@@ -675,7 +676,7 @@ declare const DEFAULT_CONTROL_COMPONENTS: {
|
|
|
675
676
|
};
|
|
676
677
|
type DefaultControlComponents = typeof DEFAULT_CONTROL_COMPONENTS;
|
|
677
678
|
type DefaultControlMap = {
|
|
678
|
-
readonly [K in keyof DefaultControlComponents]: K extends 'string' ? AutoFormControl<typeof UInput, InputProps, InputSlots> : K extends 'textarea' ? AutoFormControl<typeof UTextarea, TextareaProps, TextareaSlots> : AutoFormControl<DefaultControlComponents[K]>;
|
|
679
|
+
readonly [K in keyof DefaultControlComponents]: K extends 'string' ? AutoFormControl<typeof UInput, InputProps, InputSlots> : K extends 'textarea' ? AutoFormControl<typeof UTextarea, TextareaProps, TextareaSlots> : K extends 'calendarDate' ? AutoFormControl<DefaultControlComponents[K], CalendarDateControlProps> : AutoFormControl<DefaultControlComponents[K]>;
|
|
679
680
|
};
|
|
680
681
|
export declare const DEFAULT_CONTROLS: DefaultControlMap;
|
|
681
682
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HeaderContext } from '@tanstack/vue-table';
|
|
2
|
+
import type { VNode } from 'vue';
|
|
3
|
+
import type { DataTableProps } from '../../../types/data-table/component';
|
|
4
|
+
export declare function buildResizeHandle<T>(ctx: HeaderContext<T, unknown>, options: DataTableProps<T>): VNode;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { h } from "vue";
|
|
2
|
+
import { clampSize } from "./style.js";
|
|
3
|
+
const DRAG_THRESHOLD = 2;
|
|
4
|
+
const HANDLE_STYLE = {
|
|
5
|
+
position: "absolute",
|
|
6
|
+
insetBlock: "0",
|
|
7
|
+
right: "0",
|
|
8
|
+
width: "14px",
|
|
9
|
+
cursor: "col-resize",
|
|
10
|
+
display: "flex",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
justifyContent: "flex-end",
|
|
13
|
+
zIndex: "15",
|
|
14
|
+
touchAction: "none",
|
|
15
|
+
userSelect: "none"
|
|
16
|
+
};
|
|
17
|
+
const BADGE_STYLE = {
|
|
18
|
+
position: "absolute",
|
|
19
|
+
top: "50%",
|
|
20
|
+
right: "0",
|
|
21
|
+
transform: "translateY(-50%)",
|
|
22
|
+
marginRight: "6px",
|
|
23
|
+
padding: "2px 6px",
|
|
24
|
+
borderRadius: "4px",
|
|
25
|
+
backgroundColor: "var(--ui-primary)",
|
|
26
|
+
color: "var(--ui-text-inverted)",
|
|
27
|
+
fontSize: "12px",
|
|
28
|
+
fontWeight: "500",
|
|
29
|
+
lineHeight: "1",
|
|
30
|
+
whiteSpace: "nowrap",
|
|
31
|
+
fontVariantNumeric: "tabular-nums",
|
|
32
|
+
pointerEvents: "none",
|
|
33
|
+
zIndex: "20"
|
|
34
|
+
};
|
|
35
|
+
function lineStyle(active) {
|
|
36
|
+
return {
|
|
37
|
+
width: active ? "2px" : "1px",
|
|
38
|
+
height: "60%",
|
|
39
|
+
marginRight: "3px",
|
|
40
|
+
borderRadius: "1px",
|
|
41
|
+
backgroundColor: active ? "var(--ui-primary)" : "var(--ui-border-accented)",
|
|
42
|
+
opacity: active ? "1" : "0.6",
|
|
43
|
+
transition: "background-color 0.15s, width 0.15s, opacity 0.15s"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function highlightLine(handle, active) {
|
|
47
|
+
const line = handle?.firstElementChild;
|
|
48
|
+
if (line) Object.assign(line.style, lineStyle(active));
|
|
49
|
+
}
|
|
50
|
+
function clientXOf(e) {
|
|
51
|
+
return "touches" in e ? e.touches[0]?.clientX : e.clientX;
|
|
52
|
+
}
|
|
53
|
+
function startResize(ctx, options, e) {
|
|
54
|
+
const id = ctx.column.id;
|
|
55
|
+
const th = e.currentTarget?.closest("th");
|
|
56
|
+
const startWidth = th ? th.getBoundingClientRect().width : ctx.column.getSize();
|
|
57
|
+
const startX = clientXOf(e) ?? 0;
|
|
58
|
+
const min = ctx.column.columnDef.minSize ?? 20;
|
|
59
|
+
const max = ctx.column.columnDef.maxSize ?? Number.MAX_SAFE_INTEGER;
|
|
60
|
+
const liveMode = (options.columnResizeMode ?? "onChange") === "onChange";
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
let moved = false;
|
|
63
|
+
let lastX = startX;
|
|
64
|
+
let rafId = 0;
|
|
65
|
+
const widthAt = (x) => clampSize(Math.round(startWidth + (x - startX)), min, max);
|
|
66
|
+
const apply = () => {
|
|
67
|
+
rafId = 0;
|
|
68
|
+
ctx.table.setColumnSizing((prev) => ({ ...prev, [id]: widthAt(lastX) }));
|
|
69
|
+
};
|
|
70
|
+
const freezeLeftColumns = () => {
|
|
71
|
+
const tr = th?.closest("tr");
|
|
72
|
+
const headers = ctx.table.getHeaderGroups().at(-1)?.headers ?? [];
|
|
73
|
+
const draggedIndex = headers.findIndex((hd) => hd.column.id === id);
|
|
74
|
+
if (!tr || draggedIndex <= 0) return;
|
|
75
|
+
const ths = Array.from(tr.querySelectorAll(":scope > th"));
|
|
76
|
+
const frozen = {};
|
|
77
|
+
for (let i = 0; i < draggedIndex; i++) {
|
|
78
|
+
const el = ths[i];
|
|
79
|
+
const hd = headers[i];
|
|
80
|
+
if (el && hd) frozen[hd.column.id] = Math.round(el.getBoundingClientRect().width);
|
|
81
|
+
}
|
|
82
|
+
if (Object.keys(frozen).length) ctx.table.setColumnSizing((prev) => ({ ...prev, ...frozen }));
|
|
83
|
+
};
|
|
84
|
+
const stop = () => {
|
|
85
|
+
window.removeEventListener("mousemove", onMove);
|
|
86
|
+
window.removeEventListener("mouseup", onEnd);
|
|
87
|
+
window.removeEventListener("touchmove", onMove);
|
|
88
|
+
window.removeEventListener("touchend", onEnd);
|
|
89
|
+
};
|
|
90
|
+
const onMove = (ev) => {
|
|
91
|
+
const x = clientXOf(ev);
|
|
92
|
+
if (typeof x !== "number") return;
|
|
93
|
+
if (!moved) {
|
|
94
|
+
if (Math.abs(x - startX) <= DRAG_THRESHOLD) return;
|
|
95
|
+
moved = true;
|
|
96
|
+
freezeLeftColumns();
|
|
97
|
+
ctx.table.setColumnSizingInfo((prev) => ({ ...prev, isResizingColumn: id }));
|
|
98
|
+
}
|
|
99
|
+
lastX = x;
|
|
100
|
+
if (liveMode && !rafId) rafId = requestAnimationFrame(apply);
|
|
101
|
+
};
|
|
102
|
+
const onEnd = (ev) => {
|
|
103
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
104
|
+
if (moved) {
|
|
105
|
+
const x = clientXOf(ev);
|
|
106
|
+
if (typeof x === "number") lastX = x;
|
|
107
|
+
ctx.table.setColumnSizing((prev) => ({ ...prev, [id]: widthAt(lastX) }));
|
|
108
|
+
ctx.table.setColumnSizingInfo((prev) => ({ ...prev, isResizingColumn: false }));
|
|
109
|
+
}
|
|
110
|
+
stop();
|
|
111
|
+
};
|
|
112
|
+
window.addEventListener("mousemove", onMove);
|
|
113
|
+
window.addEventListener("mouseup", onEnd);
|
|
114
|
+
window.addEventListener("touchmove", onMove);
|
|
115
|
+
window.addEventListener("touchend", onEnd);
|
|
116
|
+
}
|
|
117
|
+
export function buildResizeHandle(ctx, options) {
|
|
118
|
+
const isResizing = ctx.column.getIsResizing();
|
|
119
|
+
return h("div", {
|
|
120
|
+
style: HANDLE_STYLE,
|
|
121
|
+
onMousedown: (e) => startResize(ctx, options, e),
|
|
122
|
+
onTouchstart: (e) => startResize(ctx, options, e),
|
|
123
|
+
onClick: (e) => e.stopPropagation(),
|
|
124
|
+
onMouseenter: (e) => {
|
|
125
|
+
if (!isResizing) highlightLine(e.currentTarget, true);
|
|
126
|
+
},
|
|
127
|
+
onMouseleave: (e) => {
|
|
128
|
+
if (!isResizing) highlightLine(e.currentTarget, false);
|
|
129
|
+
}
|
|
130
|
+
}, [
|
|
131
|
+
h("div", { style: lineStyle(isResizing) }),
|
|
132
|
+
isResizing ? h("div", { style: BADGE_STYLE }, `${Math.round(ctx.column.getSize())}px`) : null
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
@@ -3,6 +3,7 @@ import { resolveCallbackValue, resolveColumnFlag, resolveTemplate } from "./util
|
|
|
3
3
|
import DataTableCellTooltip from "../components/CellTooltip.vue";
|
|
4
4
|
import { UButton } from "#components";
|
|
5
5
|
import { applyBaseState, buildClassMeta, makeColumnStyle, resolveAlignClass } from "./style.js";
|
|
6
|
+
import { buildResizeHandle } from "./resize.js";
|
|
6
7
|
function buildDataCellRenderer(col, options) {
|
|
7
8
|
const maybeTooltip = col.tooltip !== void 0 ? !!col.tooltip : !!options.tooltip;
|
|
8
9
|
const maybeTruncate = col.truncate !== void 0 ? !!col.truncate : !!options.truncate;
|
|
@@ -110,53 +111,9 @@ export function renderHeaderActions(ctx, col, options, label, sortable, pinable,
|
|
|
110
111
|
if (sortable) actions.push(buildSortAction(col, options));
|
|
111
112
|
const leading = actions.filter((a) => a.position === "leading").map((a) => a.render(ctx));
|
|
112
113
|
const trailing = actions.filter((a) => a.position === "trailing").map((a) => a.render(ctx));
|
|
113
|
-
const
|
|
114
|
-
const id = ctx.column.id;
|
|
115
|
-
const seeded = !(id in ctx.table.getState().columnSizing);
|
|
116
|
-
if (seeded) {
|
|
117
|
-
const th = e.currentTarget?.closest("th");
|
|
118
|
-
const w = th ? Math.round(th.getBoundingClientRect().width) : 0;
|
|
119
|
-
if (w > 0) ctx.table.setColumnSizing((prev) => ({ ...prev, [id]: w }));
|
|
120
|
-
}
|
|
121
|
-
ctx.header.getResizeHandler()(e);
|
|
122
|
-
if (!seeded) return;
|
|
123
|
-
const startX = "touches" in e ? e.touches[0]?.clientX ?? 0 : e.clientX;
|
|
124
|
-
let moved = false;
|
|
125
|
-
const onMove = (ev) => {
|
|
126
|
-
const x = "touches" in ev ? ev.touches[0]?.clientX : ev.clientX;
|
|
127
|
-
if (typeof x === "number" && Math.abs(x - startX) > 2) moved = true;
|
|
128
|
-
};
|
|
129
|
-
const onEnd = () => {
|
|
130
|
-
if (!moved) {
|
|
131
|
-
ctx.table.setColumnSizing(
|
|
132
|
-
(prev) => Object.fromEntries(Object.entries(prev).filter(([key]) => key !== id))
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
window.removeEventListener("mousemove", onMove);
|
|
136
|
-
window.removeEventListener("mouseup", onEnd);
|
|
137
|
-
window.removeEventListener("touchmove", onMove);
|
|
138
|
-
window.removeEventListener("touchend", onEnd);
|
|
139
|
-
};
|
|
140
|
-
window.addEventListener("mousemove", onMove);
|
|
141
|
-
window.addEventListener("mouseup", onEnd);
|
|
142
|
-
window.addEventListener("touchmove", onMove);
|
|
143
|
-
window.addEventListener("touchend", onEnd);
|
|
144
|
-
};
|
|
145
|
-
const resizeHandle = resizable ? h("div", {
|
|
146
|
-
class: "absolute top-0 bottom-0 right-0 w-4 -mr-2 cursor-col-resize select-none touch-none flex items-center justify-center group/resize",
|
|
147
|
-
onMousedown: startResize,
|
|
148
|
-
onTouchstart: startResize,
|
|
149
|
-
onClick: (e) => e.stopPropagation()
|
|
150
|
-
}, [
|
|
151
|
-
h("div", {
|
|
152
|
-
class: [
|
|
153
|
-
"h-full transition-colors",
|
|
154
|
-
ctx.column.getIsResizing() ? "w-0.5 bg-primary" : "w-px opacity-50 group-hover:opacity-100 bg-(--ui-border-accented) group-hover/resize:w-0.5 group-hover/resize:bg-primary"
|
|
155
|
-
].join(" ")
|
|
156
|
-
})
|
|
157
|
-
]) : null;
|
|
114
|
+
const resizeHandle = resizable ? buildResizeHandle(ctx, options) : null;
|
|
158
115
|
const labelNode = isVNode(label) ? label : h("span", { class: "truncate" }, String(label ?? ""));
|
|
159
|
-
return h("div", { class: "flex items-center gap-1
|
|
116
|
+
return h("div", { class: "flex items-center gap-1 group" }, [
|
|
160
117
|
...leading,
|
|
161
118
|
labelNode,
|
|
162
119
|
...trailing,
|
|
@@ -27,10 +27,11 @@ function buildSpecialColumnDef(col, type, ctx, render) {
|
|
|
27
27
|
const defaults = SPECIAL_COLUMN_DEFAULTS[type];
|
|
28
28
|
const { options, density } = ctx;
|
|
29
29
|
const { id } = defaults;
|
|
30
|
+
const hasExplicitBounds = col.minSize != null || col.maxSize != null;
|
|
30
31
|
const resolvedSize = applyBaseState(
|
|
31
32
|
id,
|
|
32
33
|
col.fixed ?? defaults.fixed,
|
|
33
|
-
col.size ?? defaults.size,
|
|
34
|
+
col.size ?? (hasExplicitBounds ? void 0 : defaults.size),
|
|
34
35
|
ctx
|
|
35
36
|
);
|
|
36
37
|
if (col.visibility === false) ctx.visibility[id] = false;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Cell, ColumnMeta, Header } from '@tanstack/vue-table';
|
|
2
2
|
import type { ResolveContext } from './constants';
|
|
3
|
+
export declare function clampSize(n: number, min: number, max: number): number;
|
|
3
4
|
export declare function resolveColumnSize<T>(ctx: Header<T, unknown> | Cell<T, unknown>): Record<string, string>;
|
|
4
5
|
export declare function makeColumnStyle<T>(align?: 'left' | 'center' | 'right'): {
|
|
5
6
|
th: (ctx: Header<T, unknown>) => Record<string, string>;
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { isString } from "@movk/core";
|
|
2
2
|
import { resolvePresetSize } from "./utils.js";
|
|
3
|
+
export function clampSize(n, min, max) {
|
|
4
|
+
return Math.min(Math.max(n, min), max);
|
|
5
|
+
}
|
|
6
|
+
function fixedWidth(n) {
|
|
7
|
+
const w = `${n}px`;
|
|
8
|
+
return { width: w, minWidth: w, maxWidth: w };
|
|
9
|
+
}
|
|
10
|
+
function clampWidth(size, columnDef) {
|
|
11
|
+
return fixedWidth(clampSize(size, columnDef.minSize ?? -Infinity, columnDef.maxSize ?? Infinity));
|
|
12
|
+
}
|
|
13
|
+
function clampMinWidth(size, columnDef) {
|
|
14
|
+
return fixedWidth(clampSize(size, columnDef.minSize ?? -Infinity, Infinity));
|
|
15
|
+
}
|
|
16
|
+
function isInnermostPinned(column, table, pinned) {
|
|
17
|
+
const cols = pinned === "left" ? table.getLeftLeafColumns() : table.getRightLeafColumns();
|
|
18
|
+
const target = pinned === "left" ? cols[cols.length - 1] : cols[0];
|
|
19
|
+
return target?.id === column.id;
|
|
20
|
+
}
|
|
3
21
|
export function resolveColumnSize(ctx) {
|
|
4
22
|
const { columnDef } = ctx.column;
|
|
5
23
|
const table = ctx.getContext().table;
|
|
6
|
-
const
|
|
24
|
+
const pinned = ctx.column.getIsPinned();
|
|
7
25
|
const isSized = ctx.column.id in table.getState().columnSizing;
|
|
8
26
|
const hasExplicitSize = columnDef.size != table._getDefaultColumnDef().size;
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
27
|
+
if (hasExplicitSize) return clampWidth(ctx.column.getSize(), columnDef);
|
|
28
|
+
if (isSized) return clampMinWidth(ctx.column.getSize(), columnDef);
|
|
29
|
+
if (pinned && !isInnermostPinned(ctx.column, table, pinned)) return clampWidth(ctx.column.getSize(), columnDef);
|
|
13
30
|
const style = {};
|
|
14
31
|
if (columnDef.minSize != null) style.minWidth = `${columnDef.minSize}px`;
|
|
15
32
|
if (columnDef.maxSize != null) style.maxWidth = `${columnDef.maxSize}px`;
|
|
@@ -2,15 +2,21 @@ import { resolveEndpointConfig } from "../domains/api/endpoint-config.js";
|
|
|
2
2
|
import { createOnRequest } from "../domains/api/interceptors/request.js";
|
|
3
3
|
import { createOnResponse } from "../domains/api/interceptors/response.js";
|
|
4
4
|
import { createOnResponseError } from "../domains/api/interceptors/error.js";
|
|
5
|
+
import { attachInterceptors } from "../domains/api/interceptors/compose.js";
|
|
5
6
|
import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from "#imports";
|
|
6
7
|
function createEndpointFetch(resolvedConfig, publicConfig, nuxtApp) {
|
|
7
|
-
|
|
8
|
-
baseURL: resolvedConfig.baseURL,
|
|
9
|
-
headers: resolvedConfig.headers,
|
|
8
|
+
const interceptors = {
|
|
10
9
|
onRequest: createOnRequest(resolvedConfig, publicConfig, nuxtApp),
|
|
11
10
|
onResponse: createOnResponse(resolvedConfig, publicConfig, nuxtApp),
|
|
12
11
|
onResponseError: createOnResponseError(resolvedConfig, publicConfig, nuxtApp)
|
|
12
|
+
};
|
|
13
|
+
const instance = $fetch.create({
|
|
14
|
+
baseURL: resolvedConfig.baseURL,
|
|
15
|
+
headers: resolvedConfig.headers,
|
|
16
|
+
...interceptors
|
|
13
17
|
});
|
|
18
|
+
attachInterceptors(instance, interceptors);
|
|
19
|
+
return instance;
|
|
14
20
|
}
|
|
15
21
|
export default defineNuxtPlugin(() => {
|
|
16
22
|
const nuxtApp = useNuxtApp();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
import type { CalendarDate, DateValue, Time } from '@internationalized/date';
|
|
2
|
+
import type { CalendarDate, Time } from '@internationalized/date';
|
|
4
3
|
import type { ComponentProps, ComponentSlots, IsAny, IsComponent, KnownKeys, OmitByKey, Prettify, ReactiveValue, UnionToIntersection, WidenLiteral } from '@movk/core';
|
|
4
|
+
import type { ValueFormat } from '../../composables/useDateFormatter';
|
|
5
5
|
import type { AutoFormFieldContext } from './fields';
|
|
6
6
|
import type { AutoFormControl, AutoFormControls, AutoFormControlsMeta, _Unset, AutoFormLayoutConfig } from './controls';
|
|
7
7
|
import type { AUTOFORM_META } from '../../domains/auto-form/constants';
|
|
@@ -72,10 +72,25 @@ type EnumFactory<TControls extends AutoFormControls> = {
|
|
|
72
72
|
<const T extends EnumValues>(values: T, overwrite: MetaByDefaultIfExists<TControls, 'enum'>): EnumFactoryResult<T>;
|
|
73
73
|
<const T extends EnumValues, C extends IsComponent>(values: T, overwrite: MetaByComponent<C>): EnumFactoryResult<T>;
|
|
74
74
|
};
|
|
75
|
+
type _CalendarSingle<V> = V extends 'iso' ? string : V extends 'timestamp' | 'unix' ? number : V extends 'date' ? Date : CalendarDate;
|
|
76
|
+
type _ResolveControlProps<CP> = CP extends (...args: any[]) => infer R ? R : CP;
|
|
77
|
+
type _ValueFormatOf<CP> = CP extends {
|
|
78
|
+
valueFormat: infer V extends ValueFormat;
|
|
79
|
+
} ? V : 'date-value';
|
|
80
|
+
type InferCalendarDateValue<Meta> = Meta extends {
|
|
81
|
+
controlProps?: infer CP;
|
|
82
|
+
} ? _ResolveControlProps<CP> extends infer P ? P extends {
|
|
83
|
+
multiple: true;
|
|
84
|
+
} ? _CalendarSingle<_ValueFormatOf<P>>[] : P extends {
|
|
85
|
+
range: true;
|
|
86
|
+
} ? {
|
|
87
|
+
start: _CalendarSingle<_ValueFormatOf<P>> | undefined;
|
|
88
|
+
end: _CalendarSingle<_ValueFormatOf<P>> | undefined;
|
|
89
|
+
} | undefined : _CalendarSingle<_ValueFormatOf<P>> : CalendarDate : CalendarDate;
|
|
75
90
|
type CalendarDateFactory<TControls extends AutoFormControls> = {
|
|
76
|
-
<
|
|
77
|
-
<
|
|
78
|
-
<
|
|
91
|
+
<const Meta = unknown>(meta?: Meta & MetaByDefaultIfExists<TControls, 'calendarDate'>): z.ZodType<InferCalendarDateValue<Meta>>;
|
|
92
|
+
<const Meta = unknown, K extends ControlKey<TControls> = ControlKey<TControls>>(meta: Meta & MetaByControlKey<TControls, K>): z.ZodType<InferCalendarDateValue<Meta>>;
|
|
93
|
+
<const Meta = unknown, C extends IsComponent = IsComponent>(meta: Meta & MetaByComponent<C>): z.ZodType<InferCalendarDateValue<Meta>>;
|
|
79
94
|
};
|
|
80
95
|
type ArrayFactory<TControls extends AutoFormControls> = {
|
|
81
96
|
<T extends z.ZodType, K extends ControlKey<TControls>>(schema: T, overwrite?: MetaByControlKey<TControls, K>): z.ZodArray<T>;
|
|
@@ -35,6 +35,9 @@ export interface DatePickerProps<R extends boolean, M extends boolean, P extends
|
|
|
35
35
|
presets?: DatePickerPreset<R, M>[] | 'default';
|
|
36
36
|
ui?: Record<string, ClassNameValue>;
|
|
37
37
|
}
|
|
38
|
+
type CalendarUnportableKeys = 'isDateDisabled' | 'isDateUnavailable' | 'isMonthDisabled' | 'isMonthUnavailable' | 'isYearDisabled' | 'isYearUnavailable' | 'weekStartsOn' | 'weekdayFormat';
|
|
39
|
+
/** AutoForm calendarDate 控件可移植 props(DatePicker props 去除 reka-ui 不可移植项),用于 controlProps 类型提示 */
|
|
40
|
+
export type CalendarDateControlProps = OmitByKey<DatePickerProps<boolean, boolean, PopoverMode, ValueFormat>, CalendarUnportableKeys>;
|
|
38
41
|
export type DatePickerEmits<R extends boolean, M extends boolean, V extends ValueFormat = 'date-value'> = PopoverEmits & Omit<CalendarEmits<R, M>, 'update:modelValue'> & {
|
|
39
42
|
'update:modelValue': [value: FormattedValue<R, M, V>];
|
|
40
43
|
};
|
|
@@ -84,6 +84,7 @@ export interface TreeProps<T extends TreeItem[] = TreeItem[], M extends boolean
|
|
|
84
84
|
/** 渲染复选框并启用多选(multiple + strategy,默认 cascade) */
|
|
85
85
|
checkable?: M & boolean;
|
|
86
86
|
ui?: Record<string, ClassNameValue>;
|
|
87
|
+
class?: ClassNameValue;
|
|
87
88
|
}
|
|
88
89
|
/** 父子勾选策略 */
|
|
89
90
|
export type TreeSelectionStrategy = 'cascade' | 'isolated';
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movk/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
5
|
-
"packageManager": "pnpm@11.
|
|
4
|
+
"version": "1.4.2",
|
|
5
|
+
"packageManager": "pnpm@11.9.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>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
"maska": "^3.2.0",
|
|
141
141
|
"mlly": "^1.8.2",
|
|
142
142
|
"nuxt-auth-utils": "^0.5.29",
|
|
143
|
-
"nuxt-site-config": "^4.1.
|
|
143
|
+
"nuxt-site-config": "^4.1.1",
|
|
144
144
|
"pathe": "^2.0.3",
|
|
145
145
|
"reka-ui": "2.9.10",
|
|
146
146
|
"scule": "^1.3.0",
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
"tailwindcss": "^4.3.1",
|
|
149
149
|
"tinyglobby": "^0.2.17",
|
|
150
150
|
"unifont": "^0.7.4",
|
|
151
|
-
"unplugin": "^3.
|
|
151
|
+
"unplugin": "^3.2.0",
|
|
152
152
|
"zod": "^4.4.3"
|
|
153
153
|
},
|
|
154
154
|
"devDependencies": {
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"unplugin-auto-import": "^21.0.0",
|
|
167
167
|
"unplugin-vue-components": "^32.1.0",
|
|
168
168
|
"vitest": "^4.1.9",
|
|
169
|
-
"vue": "^3.5.
|
|
169
|
+
"vue": "^3.5.39",
|
|
170
170
|
"vue-tsc": "^3.3.5"
|
|
171
171
|
}
|
|
172
172
|
}
|