@movk/nuxt 1.1.1 → 1.2.0

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.
Files changed (121) hide show
  1. package/README.md +5 -29
  2. package/dist/module.d.mts +3 -31
  3. package/dist/module.json +3 -3
  4. package/dist/module.mjs +135 -77
  5. package/dist/runtime/auto-form/controls.d.ts +221 -0
  6. package/dist/runtime/auto-form/controls.js +70 -0
  7. package/dist/runtime/{utils → auto-form}/field-utils.d.ts +4 -20
  8. package/dist/runtime/{utils → auto-form}/field-utils.js +1 -2
  9. package/dist/runtime/auto-form/metadata.d.ts +22 -0
  10. package/dist/runtime/auto-form/metadata.js +53 -0
  11. package/dist/runtime/auto-form/provider.d.ts +27 -0
  12. package/dist/runtime/{internal/useAutoFormProvider.js → auto-form/provider.js} +1 -1
  13. package/dist/runtime/{utils → auto-form}/reactive-utils.d.ts +4 -22
  14. package/dist/runtime/{utils → auto-form}/schema-introspector.d.ts +3 -9
  15. package/dist/runtime/{utils → auto-form}/schema-introspector.js +11 -9
  16. package/dist/runtime/components/AutoForm.d.vue.ts +4 -5
  17. package/dist/runtime/components/AutoForm.vue +12 -35
  18. package/dist/runtime/components/AutoForm.vue.d.ts +4 -5
  19. package/dist/runtime/components/ColorChooser.d.vue.ts +10 -6
  20. package/dist/runtime/components/ColorChooser.vue +4 -7
  21. package/dist/runtime/components/ColorChooser.vue.d.ts +10 -6
  22. package/dist/runtime/components/DatePicker.d.vue.ts +16 -10
  23. package/dist/runtime/components/DatePicker.vue.d.ts +16 -10
  24. package/dist/runtime/components/SearchForm.d.vue.ts +171 -0
  25. package/dist/runtime/components/SearchForm.vue +216 -0
  26. package/dist/runtime/components/SearchForm.vue.d.ts +171 -0
  27. package/dist/runtime/components/SlideVerify.d.vue.ts +5 -32
  28. package/dist/runtime/components/SlideVerify.vue +4 -4
  29. package/dist/runtime/components/SlideVerify.vue.d.ts +5 -32
  30. package/dist/runtime/components/StarRating.d.vue.ts +8 -16
  31. package/dist/runtime/components/StarRating.vue +50 -65
  32. package/dist/runtime/components/StarRating.vue.d.ts +8 -16
  33. package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +10 -2
  34. package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue +16 -23
  35. package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +10 -2
  36. package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.d.vue.ts +26 -0
  37. package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue +50 -0
  38. package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue.d.ts +26 -0
  39. package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +8 -2
  40. package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +2 -2
  41. package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +8 -2
  42. package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +8 -2
  43. package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +29 -64
  44. package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +8 -2
  45. package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +8 -2
  46. package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +15 -69
  47. package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +8 -2
  48. package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +36 -0
  49. package/dist/runtime/components/input/AsPhoneNumberInput.vue +35 -0
  50. package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +36 -0
  51. package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +17 -9
  52. package/dist/runtime/components/input/WithCharacterLimit.vue +5 -5
  53. package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +17 -9
  54. package/dist/runtime/components/input/WithClear.d.vue.ts +13 -9
  55. package/dist/runtime/components/input/WithClear.vue +2 -2
  56. package/dist/runtime/components/input/WithClear.vue.d.ts +13 -9
  57. package/dist/runtime/components/input/WithCopy.d.vue.ts +16 -10
  58. package/dist/runtime/components/input/WithCopy.vue +3 -3
  59. package/dist/runtime/components/input/WithCopy.vue.d.ts +16 -10
  60. package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +36 -0
  61. package/dist/runtime/components/input/WithFloatingLabel.vue +67 -0
  62. package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +36 -0
  63. package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +11 -9
  64. package/dist/runtime/components/input/WithPasswordToggle.vue +3 -3
  65. package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +11 -9
  66. package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +1 -1
  67. package/dist/runtime/components/theme-picker/ThemePicker.vue +19 -25
  68. package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +1 -1
  69. package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +1 -7
  70. package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +1 -7
  71. package/dist/runtime/composables/index.d.ts +8 -0
  72. package/dist/runtime/composables/index.js +8 -0
  73. package/dist/runtime/composables/useApiFetch.d.ts +17 -14
  74. package/dist/runtime/composables/useApiFetch.js +3 -28
  75. package/dist/runtime/composables/useAutoForm.d.ts +14 -98
  76. package/dist/runtime/composables/useAutoForm.js +37 -157
  77. package/dist/runtime/composables/useClientApiFetch.d.ts +5 -6
  78. package/dist/runtime/composables/useDownloadWithProgress.js +5 -6
  79. package/dist/runtime/composables/useLazyApiFetch.d.ts +18 -0
  80. package/dist/runtime/composables/useLazyApiFetch.js +4 -0
  81. package/dist/runtime/composables/useTheme.d.ts +17 -14
  82. package/dist/runtime/composables/useTheme.js +68 -72
  83. package/dist/runtime/composables/useUploadWithProgress.d.ts +2 -2
  84. package/dist/runtime/composables/useUploadWithProgress.js +7 -7
  85. package/dist/runtime/constants/api-defaults.d.ts +9 -0
  86. package/dist/runtime/constants/api-defaults.js +32 -0
  87. package/dist/runtime/constants/auto-form.d.ts +0 -2
  88. package/dist/runtime/constants/auto-form.js +0 -25
  89. package/dist/runtime/constants/grid-cols.d.ts +7 -0
  90. package/dist/runtime/constants/grid-cols.js +44 -0
  91. package/dist/runtime/plugins/api.factory.js +78 -121
  92. package/dist/runtime/plugins/theme.js +44 -64
  93. package/dist/runtime/style.css +1 -1
  94. package/dist/runtime/types/api.d.ts +277 -146
  95. package/dist/runtime/types/auto-form.d.ts +122 -411
  96. package/dist/runtime/types/index.d.ts +3 -2
  97. package/dist/runtime/types/index.js +3 -2
  98. package/dist/runtime/types/module.d.ts +96 -0
  99. package/dist/runtime/types/theme.d.ts +2 -0
  100. package/dist/runtime/types/zod.d.ts +11 -10
  101. package/dist/runtime/utils/api-utils.d.ts +27 -48
  102. package/dist/runtime/utils/api-utils.js +18 -47
  103. package/dist/runtime/utils/meta.d.ts +7 -0
  104. package/dist/runtime/utils/meta.js +16 -0
  105. package/dist/types.d.mts +6 -2
  106. package/package.json +68 -37
  107. package/dist/runtime/composables/useApiAuth.d.ts +0 -47
  108. package/dist/runtime/composables/useApiAuth.js +0 -66
  109. package/dist/runtime/internal/useAutoFormProvider.d.ts +0 -50
  110. package/dist/runtime/schemas/api.d.ts +0 -590
  111. package/dist/runtime/schemas/api.js +0 -228
  112. package/dist/runtime/server/api/_movk/session.post.d.ts +0 -10
  113. package/dist/runtime/server/api/_movk/session.post.js +0 -18
  114. package/dist/runtime/types/auth.d.ts +0 -34
  115. package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
  116. package/dist/runtime/types/components.d.ts +0 -43
  117. package/dist/runtime/utils/auto-form.d.ts +0 -3
  118. package/dist/runtime/utils/auto-form.js +0 -18
  119. /package/dist/runtime/{utils → auto-form}/reactive-utils.js +0 -0
  120. /package/dist/runtime/types/{auto-form-renderer.js → module.js} +0 -0
  121. /package/dist/runtime/types/{components.js → theme.js} +0 -0
@@ -1,4 +1,5 @@
1
1
  export * from './auto-form.js';
2
- export * from './components.js';
3
- export * from './auto-form-renderer.js';
2
+ export * from './zod.d.js';
4
3
  export * from './api.js';
4
+ export * from './module.js';
5
+ export * from './theme.js';
@@ -1,4 +1,5 @@
1
1
  export * from "./auto-form.js";
2
- export * from "./components.js";
3
- export * from "./auto-form-renderer.js";
2
+ export * from "./zod.d.ts";
4
3
  export * from "./api.js";
4
+ export * from "./module.js";
5
+ export * from "./theme.js";
@@ -0,0 +1,96 @@
1
+ import type { FetchContext, FetchResponse } from 'ofetch';
2
+ import type { ApiInstance, MovkApiPublicConfig, EndpointPrivateConfig, MovkApiFullConfig } from './api.js';
3
+ interface MovkFontProviderConfig {
4
+ /**
5
+ * CDN 基础 URL
6
+ * @see 'https://fonts.nuxt.com/get-started/providers#custom-providers'
7
+ * @example 'https://cdn.org/fonts'
8
+ */
9
+ cdn: string;
10
+ /**
11
+ * 需要加载的字重,默认全部加载
12
+ * @example [300, 400, 500, 700]
13
+ */
14
+ weights?: number[];
15
+ }
16
+ export interface ModuleOptions {
17
+ /**
18
+ * 组件前缀
19
+ * @defaultValue 'M'
20
+ */
21
+ prefix?: string;
22
+ /** API 模块配置 */
23
+ api?: MovkApiFullConfig;
24
+ /** 主题系统配置 */
25
+ theme?: {
26
+ /**
27
+ * 是否启用主题模块(appConfig 默认值、theme plugin、ThemePicker 组件)
28
+ * @defaultValue true
29
+ */
30
+ enabled?: boolean;
31
+ };
32
+ /** 字体提供器配置 */
33
+ fonts?: {
34
+ /**
35
+ * 是否启用字体模块
36
+ * @defaultValue true
37
+ */
38
+ enabled?: boolean;
39
+ /**
40
+ * 阿里巴巴普惠体字体
41
+ * @defaultValue 'https://cdn.mhaibaraai.cn/fonts'
42
+ */
43
+ alibabaPuhuiti?: MovkFontProviderConfig;
44
+ };
45
+ }
46
+ declare module 'nuxt/app' {
47
+ interface NuxtApp {
48
+ $api: ApiInstance;
49
+ }
50
+ interface RuntimeNuxtHooks {
51
+ /** 请求发送前(认证注入后) */
52
+ 'movk:api:request': (context: FetchContext) => void | Promise<void>;
53
+ /** 响应成功(业务检查 + 解包后) */
54
+ 'movk:api:response': (context: FetchContext & {
55
+ response: FetchResponse<any>;
56
+ }) => void | Promise<void>;
57
+ /** 任何错误(业务错误 + HTTP 错误) */
58
+ 'movk:api:error': (context: FetchContext & {
59
+ response: FetchResponse<any>;
60
+ }) => void | Promise<void>;
61
+ /** 401 专用(支持 handled 标记跳过默认行为) */
62
+ 'movk:api:unauthorized': (context: FetchContext & {
63
+ response: FetchResponse<any>;
64
+ }, result: {
65
+ handled: boolean;
66
+ }) => void | Promise<void>;
67
+ }
68
+ }
69
+ declare module 'nuxt/schema' {
70
+ interface NuxtConfig {
71
+ movk?: ModuleOptions;
72
+ }
73
+ interface NuxtOptions {
74
+ movk: ModuleOptions;
75
+ }
76
+ interface PublicRuntimeConfig {
77
+ movkApi: MovkApiPublicConfig;
78
+ }
79
+ interface RuntimeConfig {
80
+ movkApi: {
81
+ endpoints?: Record<string, EndpointPrivateConfig>;
82
+ };
83
+ }
84
+ interface AppConfig {
85
+ ui: {
86
+ colors: {
87
+ primary: string;
88
+ neutral: string;
89
+ [key: string]: string;
90
+ };
91
+ icons: Record<string, string>;
92
+ };
93
+ toaster?: import('@nuxt/ui').ToasterProps | null;
94
+ }
95
+ }
96
+ export {};
@@ -0,0 +1,2 @@
1
+ export type ClassNameValue = ClassNameArray | string | null | undefined | 0 | 0n | false;
2
+ export type ClassNameArray = ClassNameValue[];
@@ -1,18 +1,17 @@
1
- import type { AutoFormFieldContext, AutoFormFieldSlots, AutoFormNestedCollapsible } from '#movk/types/auto-form'
2
- import type { ClassNameValue } from 'tailwind-merge'
1
+ import type { AutoFormFieldContext, AutoFormFieldSlots, AutoFormNestedCollapsible, ClassNameValue } from '#movk/types'
3
2
  import type { ReactiveValue } from '@movk/core'
4
3
 
5
4
  type ZodValue<T, CTX = AutoFormFieldContext> = ReactiveValue<T, CTX>
6
5
 
7
6
  export interface ZodAutoFormFieldMeta {
8
7
  /**
9
- * The element or component this component should render as.
8
+ * 当前字段渲染使用的元素或组件。
10
9
  * @defaultValue 'div'
11
10
  */
12
11
  as?: ZodValue<any>
13
- /** The name of the FormField. Also used to match form errors. */
12
+ /** 表单字段名,同时用于匹配表单错误。 */
14
13
  name?: ZodValue<string>
15
- /** A regular expression to match form error names. */
14
+ /** 用于匹配表单错误名称的正则表达式。 */
16
15
  errorPattern?: ZodValue<RegExp>
17
16
  label?: ZodValue<string>
18
17
  description?: ZodValue<string>
@@ -20,22 +19,24 @@ export interface ZodAutoFormFieldMeta {
20
19
  error?: ZodValue<boolean | string>
21
20
  hint?: ZodValue<string>
22
21
  /**
22
+ * 字段尺寸。
23
23
  * @defaultValue 'md'
24
24
  */
25
25
  size?: ZodValue<'md' | 'xs' | 'sm' | 'lg' | 'xl'>
26
26
  /**
27
+ * 是否必填。
27
28
  * @defaultValue true
28
29
  */
29
30
  required?: ZodValue<boolean>
30
- /** If true, validation on input will be active immediately instead of waiting for a blur event. */
31
+ /** 是否在输入时立即触发校验(而不是等待 blur 事件)。 */
31
32
  eagerValidation?: ZodValue<boolean>
32
33
  /**
33
- * Delay in milliseconds before validating the form on input events.
34
+ * 输入事件触发后,延迟多少毫秒执行表单校验。
34
35
  * @defaultValue `300`
35
36
  */
36
37
  validateOnInputDelay?: ZodValue<number>
37
38
  class?: ZodValue<any>
38
- ui?: ZodValue<{ root?: ClassNameValue, wrapper?: ClassNameValue, labelWrapper?: ClassNameValue, label?: strClassNameValueing, container?: ClassNameValue, description?: ClassNameValue, error?: ClassNameValue, hint?: ClassNameValue, help?: ClassNameValue }>
39
+ ui?: ZodValue<{ root?: ClassNameValue, wrapper?: ClassNameValue, labelWrapper?: ClassNameValue, label?: ClassNameValue, container?: ClassNameValue, description?: ClassNameValue, error?: ClassNameValue, hint?: ClassNameValue, help?: ClassNameValue }>
39
40
  /**
40
41
  * @see https://ui4.nuxt.com/docs/components/form-field#slots
41
42
  */
@@ -46,7 +47,7 @@ export interface ZodAutoFormFieldMeta {
46
47
  /** 是否隐藏 */
47
48
  hidden?: ZodValue<boolean>
48
49
  /**
49
- * object field
50
+ * 对象字段折叠配置。
50
51
  */
51
52
  collapsible?: ZodValue<AutoFormNestedCollapsible>
52
53
 
@@ -54,7 +55,7 @@ export interface ZodAutoFormFieldMeta {
54
55
  [key: string]: unknown
55
56
  }
56
57
 
57
- declare module 'zod/v4' {
58
+ declare module 'zod' {
58
59
 
59
60
  interface GlobalMeta extends ZodAutoFormFieldMeta { }
60
61
 
@@ -1,79 +1,58 @@
1
- import type { FetchContext, FetchHooks } from 'ofetch';
2
- import type { ApiResponse, ApiError, ApiResponseConfig, ApiToastConfig, RequestToastOptions, ResolvedEndpointConfig } from '../types/api.js';
1
+ import type { ApiResponse, ApiError, ApiResponseConfig, ApiToastConfig, RequestToastOptions, ResolvedEndpointConfig, MovkApiPublicConfig } from '../types/api.js';
3
2
  /**
4
- * 判断API响应是否业务成功
5
- * @param response - API响应对象
6
- * @param config - 响应配置(包含codeKey和successCodes)
3
+ * 判断 API 响应是否业务成功
4
+ * @param response - API 响应对象
5
+ * @param config - 响应配置(包含 codeKey successCodes)
7
6
  * @returns 是否业务成功
8
7
  */
9
8
  export declare function isBusinessSuccess(response: ApiResponse, config?: Partial<ApiResponseConfig>): boolean;
10
9
  /**
11
- * 从API响应中提取消息内容
12
- * @param response - API响应对象
13
- * @param config - 响应配置(包含messageKey)
14
- * @returns 消息字符串或undefined
10
+ * 从 API 响应中提取消息内容
11
+ * @param response - API 响应对象
12
+ * @param config - 响应配置(包含 messageKey)
13
+ * @returns 消息字符串或 undefined
15
14
  */
16
15
  export declare function extractMessage(response: ApiResponse, config?: Partial<ApiResponseConfig>): string | undefined;
17
16
  /**
18
- * 从API响应中提取业务数据
19
- * @param response - API响应对象
20
- * @param config - 响应配置(包含dataKey)
17
+ * 从 API 响应中提取业务数据
18
+ * @param response - API 响应对象
19
+ * @param config - 响应配置(包含 dataKey)
21
20
  * @returns 业务数据
22
21
  */
23
- export declare function extractData<T>(response: ApiResponse<T>, config?: Partial<ApiResponseConfig>): T;
22
+ export declare function extractData(response: ApiResponse, config?: Partial<ApiResponseConfig>): unknown;
24
23
  /**
25
24
  * 创建业务错误对象
26
- * @param response - API响应对象
25
+ * @param response - API 响应对象
27
26
  * @param message - 错误消息(可选)
28
27
  * @returns 业务错误对象
29
28
  */
30
29
  export declare function createApiError(response: ApiResponse, message?: string): ApiError;
31
30
  /**
32
- * 提取Toast消息内容
33
- * @param toast - Toast配置选项
31
+ * 提取 Toast 消息内容
32
+ * @param toast - Toast 配置选项
34
33
  * @param type - 消息类型
35
34
  * @param fallback - 默认消息
36
35
  * @returns 最终显示的消息内容
37
36
  */
38
37
  export declare function extractToastMessage(toast: RequestToastOptions | false | undefined, type: 'success' | 'error', fallback: string): string;
39
38
  /**
40
- * 显示Toast提示
39
+ * 显示 Toast 提示
41
40
  * @param type - 提示类型
42
41
  * @param message - 提示消息
43
- * @param requestOptions - 请求级别的Toast配置
44
- * @param globalConfig - 全局Toast配置
42
+ * @param requestOptions - 请求级别的 Toast 配置
43
+ * @param globalConfig - 全局 Toast 配置
45
44
  */
46
45
  export declare function showToast(type: 'success' | 'error', message: string | undefined, requestOptions: RequestToastOptions | false | undefined, globalConfig: Partial<ApiToastConfig>): void;
47
- interface CreateTransformOptions<ResT, DataT = ResT> {
48
- skipBusinessCheck: boolean;
49
- userTransform?: (data: ResT) => DataT;
50
- successConfig: Partial<ApiResponseConfig>;
51
- }
52
- /**
53
- * 创建响应转换函数
54
- * @description 用于 useFetch 的 transform 选项,处理业务状态码检查和数据提取
55
- * @param options - 转换选项(包含skipBusinessCheck、userTransform、successConfig)
56
- * @returns 响应转换函数
57
- */
58
- export declare function createTransform<ResT, DataT = ResT>(options: CreateTransformOptions<ResT, DataT>): (response: ApiResponse<ResT>) => DataT;
59
- type HookFunction = (context: FetchContext) => void | Promise<void>;
60
- /**
61
- * 合并多个钩子函数为一个
62
- * @param hooks - 钩子函数数组
63
- * @returns 合并后的钩子函数
64
- */
65
- export declare function mergeHooks(...hooks: (HookFunction | undefined)[]): HookFunction;
66
- /**
67
- * 合并内置钩子和用户钩子
68
- * @param builtinHooks - 内置钩子集合
69
- * @param userHooks - 用户自定义钩子集合
70
- * @returns 合并后的完整钩子集合
71
- */
72
- export declare function mergeFetchHooks(builtinHooks: Partial<FetchHooks>, userHooks: Partial<FetchHooks>): FetchHooks;
73
46
  /**
74
47
  * 获取认证请求头
75
- * @param config - 已解析的端点配置
48
+ * @param config - 已解析的端点配置(或至少包含 auth 字段)
76
49
  * @returns 认证请求头对象
77
50
  */
78
- export declare function getAuthHeaders(config: ResolvedEndpointConfig): Record<string, string>;
79
- export {};
51
+ export declare function getAuthHeaders(config: Pick<ResolvedEndpointConfig, 'auth'>): Record<string, string>;
52
+ /**
53
+ * 从 publicConfig 解析端点配置(合并全局默认值)
54
+ * @param publicConfig - 模块公共配置
55
+ * @param endpoint - 端点名称(可选,默认使用 defaultEndpoint)
56
+ * @returns 已解析的端点配置(含 baseURL、auth、toast、response)
57
+ */
58
+ export declare function resolveEndpointConfig(publicConfig: MovkApiPublicConfig, endpoint?: string): Pick<ResolvedEndpointConfig, 'baseURL' | 'auth' | 'toast' | 'response'>;
@@ -1,4 +1,5 @@
1
1
  import { getPath } from "@movk/core";
2
+ import defu from "defu";
2
3
  import { useNuxtApp, useToast, useUserSession } from "#imports";
3
4
  export function isBusinessSuccess(response, config = {}) {
4
5
  const codeKey = config.codeKey || "code";
@@ -12,7 +13,7 @@ export function extractMessage(response, config = {}) {
12
13
  }
13
14
  export function extractData(response, config = {}) {
14
15
  const dataKey = config.dataKey || "data";
15
- return response[dataKey] ?? response.result ?? response;
16
+ return response[dataKey] ?? response;
16
17
  }
17
18
  export function createApiError(response, message) {
18
19
  const error = new Error(message || "\u8BF7\u6C42\u5931\u8D25");
@@ -24,7 +25,7 @@ export function createApiError(response, message) {
24
25
  function getToast() {
25
26
  try {
26
27
  const nuxtApp = useNuxtApp();
27
- return nuxtApp.runWithContext(() => useToast());
28
+ return nuxtApp.vueApp.runWithContext(() => useToast());
28
29
  } catch {
29
30
  return null;
30
31
  }
@@ -51,54 +52,10 @@ export function showToast(type, message, requestOptions, globalConfig) {
51
52
  ...requestTypeConfig
52
53
  });
53
54
  }
54
- export function createTransform(options) {
55
- const { skipBusinessCheck, userTransform, successConfig } = options;
56
- return (response) => {
57
- if (!skipBusinessCheck && !isBusinessSuccess(response, successConfig)) {
58
- throw createApiError(response, extractMessage(response, successConfig));
59
- }
60
- const unwrappedData = extractData(response, successConfig);
61
- if (userTransform) {
62
- return userTransform(unwrappedData);
63
- }
64
- return unwrappedData;
65
- };
66
- }
67
- export function mergeHooks(...hooks) {
68
- const validHooks = hooks.filter((h) => typeof h === "function");
69
- if (validHooks.length === 0) return () => {
70
- };
71
- if (validHooks.length === 1) return validHooks[0];
72
- return async (context) => {
73
- for (const hook of validHooks) {
74
- await hook(context);
75
- }
76
- };
77
- }
78
- export function mergeFetchHooks(builtinHooks, userHooks) {
79
- return {
80
- onRequest: mergeHooks(
81
- builtinHooks.onRequest,
82
- userHooks.onRequest
83
- ),
84
- onRequestError: mergeHooks(
85
- builtinHooks.onRequestError,
86
- userHooks.onRequestError
87
- ),
88
- onResponse: mergeHooks(
89
- builtinHooks.onResponse,
90
- userHooks.onResponse
91
- ),
92
- onResponseError: mergeHooks(
93
- builtinHooks.onResponseError,
94
- userHooks.onResponseError
95
- )
96
- };
97
- }
98
55
  function getUserSession() {
99
56
  try {
100
57
  const nuxtApp = useNuxtApp();
101
- return nuxtApp.runWithContext(() => useUserSession());
58
+ return nuxtApp.vueApp.runWithContext(() => useUserSession());
102
59
  } catch {
103
60
  return null;
104
61
  }
@@ -125,3 +82,17 @@ export function getAuthHeaders(config) {
125
82
  }
126
83
  return headers;
127
84
  }
85
+ export function resolveEndpointConfig(publicConfig, endpoint) {
86
+ const endpointName = endpoint || publicConfig.defaultEndpoint || "default";
87
+ const endpointConfig = publicConfig.endpoints[endpointName];
88
+ if (!endpointConfig) {
89
+ console.warn(`[Movk API] Endpoint "${endpointName}" not found, using default`);
90
+ return resolveEndpointConfig(publicConfig, publicConfig.defaultEndpoint || "default");
91
+ }
92
+ return {
93
+ baseURL: endpointConfig.baseURL || "",
94
+ auth: defu(endpointConfig.auth, publicConfig.auth),
95
+ toast: defu(endpointConfig.toast, publicConfig.toast),
96
+ response: defu(endpointConfig.response, publicConfig.response)
97
+ };
98
+ }
@@ -0,0 +1,7 @@
1
+ export declare function getPackageJsonMetadata(dir: string): Promise<{
2
+ name: any;
3
+ description: any;
4
+ } | {
5
+ name: string;
6
+ description?: undefined;
7
+ }>;
@@ -0,0 +1,16 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ export async function getPackageJsonMetadata(dir) {
4
+ try {
5
+ const packageJson = await readFile(resolve(dir, "package.json"), "utf-8");
6
+ const parsed = JSON.parse(packageJson);
7
+ return {
8
+ name: parsed.name,
9
+ description: parsed.description
10
+ };
11
+ } catch {
12
+ return {
13
+ name: "docs"
14
+ };
15
+ }
16
+ }
package/dist/types.d.mts CHANGED
@@ -1,5 +1,9 @@
1
- export { default } from './module.mjs'
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
2
4
 
3
- export { type ModuleOptions } from './module.mjs'
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
4
8
 
5
9
  export * from '../dist/runtime/types/index.js'
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
3
  "type": "module",
4
- "version": "1.1.1",
5
- "packageManager": "pnpm@10.28.0",
6
- "description": "Modular engineering suite for Nuxt 4 with schema-driven forms, API integration, UI components and composables",
4
+ "version": "1.2.0",
5
+ "packageManager": "pnpm@10.33.0",
6
+ "description": "Nuxt 4 modular engineering suite schema-driven auto forms (Zod v4), API integration with auth & progress tracking, standalone UI components, and utility composables",
7
7
  "author": "YiXuan <mhaibaraai@gmail.com>",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -36,67 +36,98 @@
36
36
  ],
37
37
  "exports": {
38
38
  ".": {
39
- "types": "./dist/types.d.mts",
39
+ "types": "./dist/module.d.mts",
40
+ "style": "./dist/runtime/style.css",
40
41
  "import": "./dist/module.mjs"
42
+ },
43
+ "./runtime/*": "./dist/runtime/*",
44
+ "./components/*": "./dist/runtime/components/*",
45
+ "./composables": {
46
+ "types": "./dist/runtime/composables/index.d.ts",
47
+ "import": "./dist/runtime/composables/index.js"
48
+ },
49
+ "./composables/*": {
50
+ "types": "./dist/runtime/composables/*.d.ts",
51
+ "import": "./dist/runtime/composables/*.js"
41
52
  }
42
53
  },
54
+ "typesVersions": {
55
+ "*": {
56
+ ".": [
57
+ "./dist/module.d.mts"
58
+ ],
59
+ "runtime/*": [
60
+ "./dist/runtime/*"
61
+ ],
62
+ "components/*": [
63
+ "./dist/runtime/components/*"
64
+ ],
65
+ "composables": [
66
+ "./dist/runtime/composables/index.d.ts"
67
+ ],
68
+ "composables/*": [
69
+ "./dist/runtime/composables/*.d.ts"
70
+ ]
71
+ }
72
+ },
73
+ "style": "./dist/runtime/index.css",
43
74
  "main": "./dist/module.mjs",
44
- "types": "./dist/types.d.mts",
45
75
  "files": [
46
76
  "dist"
47
77
  ],
48
78
  "peerDependencies": {
49
- "@nuxt/ui": ">=4.3.0",
50
- "zod": ">=4.3.5"
79
+ "@nuxt/ui": ">=4.6.0",
80
+ "zod": ">=4.3.6"
51
81
  },
52
82
  "scripts": {
53
83
  "prepack": "pnpm build",
54
84
  "build": "nuxt-module-build build",
55
- "dev": "nuxt dev playground",
56
- "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground && nuxt prepare docs",
57
- "dev:build": "nuxt build playground",
85
+ "dev": "nuxt dev playgrounds/play",
86
+ "dev:build": "nuxt build playgrounds/play",
87
+ "dev:dashboard": "nuxt dev playgrounds/dashboard",
88
+ "dev:dashboard:build": "nuxt build playgrounds/dashboard",
89
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playgrounds/play && nuxt prepare playgrounds/dashboard && nuxt prepare docs",
58
90
  "docs": "nuxt dev docs",
59
91
  "docs:build": "nuxt build docs",
60
92
  "release": "release-it && npm publish",
61
93
  "lint": "eslint .",
62
94
  "lint:fix": "eslint . --fix",
63
- "typecheck": "vue-tsc --noEmit && nuxt typecheck playground && nuxt typecheck docs",
95
+ "typecheck": "vue-tsc --noEmit && nuxt typecheck playgrounds/play && nuxt typecheck playgrounds/dashboard && nuxt typecheck docs",
64
96
  "clean": "movk-clean",
65
97
  "test": "vitest"
66
98
  },
67
99
  "dependencies": {
68
- "@iconify-json/lucide": "^1.2.86",
100
+ "@iconify-json/lucide": "^1.2.101",
69
101
  "@iconify-json/ph": "^1.2.2",
70
- "@iconify-json/tabler": "^1.2.26",
71
- "@internationalized/date": "^3.10.1",
72
- "@movk/core": "^1.1.0",
102
+ "@iconify-json/tabler": "^1.2.33",
103
+ "@internationalized/date": "^3.12.0",
104
+ "@movk/core": "^1.2.3",
73
105
  "@nuxt/image": "^2.0.0",
74
- "@nuxt/ui": "^4.3.0",
75
- "@vueuse/core": "^14.1.0",
76
- "@vueuse/nuxt": "^14.1.0",
77
- "defu": "^6.1.4",
78
- "motion-v": "^1.9.0",
79
- "nuxt-auth-utils": "^0.5.27",
80
- "nuxt-og-image": "^5.1.13",
106
+ "@nuxt/ui": "^4.6.1",
107
+ "@vueuse/core": "^14.2.1",
108
+ "@vueuse/nuxt": "^14.2.1",
109
+ "defu": "^6.1.6",
110
+ "maska": "^3.2.0",
111
+ "motion-v": "^2.2.0",
112
+ "nuxt-auth-utils": "^0.5.29",
113
+ "nuxt-og-image": "^6.3.2",
114
+ "reka-ui": "^2.9.3",
81
115
  "scule": "^1.3.0",
82
- "tailwindcss": "^4.1.18",
83
- "zod": "^4.3.5"
116
+ "tailwindcss": "^4.2.2",
117
+ "unifont": "^0.7.4",
118
+ "zod": "^4.3.6"
84
119
  },
85
120
  "devDependencies": {
86
- "@nuxt/devtools": "^3.1.1",
87
- "@nuxt/eslint": "^1.12.1",
88
- "@nuxt/kit": "^4.2.2",
121
+ "@nuxt/eslint-config": "^1.15.2",
122
+ "@nuxt/kit": "^4.4.2",
89
123
  "@nuxt/module-builder": "^1.0.2",
90
- "@nuxt/schema": "^4.2.2",
91
- "@nuxt/test-utils": "^3.23.0",
124
+ "@nuxt/schema": "^4.4.2",
92
125
  "@release-it/bumper": "^7.0.5",
93
- "@release-it/conventional-changelog": "^10.0.4",
94
- "@vitest/coverage-v8": "^4.0.17",
95
- "eslint": "9.39.2",
96
- "jsdom": "^27.4.0",
97
- "nuxt": "^4.2.2",
98
- "typescript": "^5.9.3",
99
- "vitest": "^4.0.17",
100
- "vue-tsc": "^3.2.2"
126
+ "@release-it/conventional-changelog": "^10.0.6",
127
+ "eslint": "^10.2.0",
128
+ "nuxt": "^4.4.2",
129
+ "typescript": "^6.0.2",
130
+ "vitest": "^4.1.2",
131
+ "vue-tsc": "^3.2.6"
101
132
  }
102
133
  }
@@ -1,47 +0,0 @@
1
- import type { UseApiAuthReturn } from '../types/api.js';
2
- /**
3
- * API 认证 Composable
4
- *
5
- * 提供完整的登录、登出、刷新用户信息等功能,
6
- * 与 nuxt-auth-utils 无缝集成。
7
- *
8
- * @returns UseApiAuthReturn 认证相关方法和状态
9
- *
10
- * @example
11
- * ```ts
12
- * const { login, clear, loggedIn, user } = useApiAuth()
13
- *
14
- * // 基础登录
15
- * await login({
16
- * loginPath: '/auth/login',
17
- * credentials: { username: 'admin', password: '123456' }
18
- * })
19
- *
20
- * // 登录后获取用户信息
21
- * await login({
22
- * loginPath: '/auth/login',
23
- * credentials: { username: 'admin', password: '123456' },
24
- * userInfoPath: '/auth/me'
25
- * })
26
- *
27
- * // 自定义 token 提取和 session 构建
28
- * await login({
29
- * loginPath: '/auth/login',
30
- * credentials: { username: 'admin', password: '123456' },
31
- * tokenExtractor: (res) => res.data?.accessToken,
32
- * sessionBuilder: (user, token) => ({
33
- * user: { id: user.id, name: user.name },
34
- * secure: { token, permissions: user.permissions }
35
- * })
36
- * })
37
- *
38
- * // 登出
39
- * await clear()
40
- *
41
- * // 响应式状态
42
- * if (loggedIn.value) {
43
- * console.log('当前用户:', user.value)
44
- * }
45
- * ```
46
- */
47
- export declare function useApiAuth(): UseApiAuthReturn;