@movk/nuxt 1.7.1 → 1.7.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/.nuxt/movk-ui.css CHANGED
@@ -1,3 +1,3 @@
1
- @source "/Users/yixuanmiao/MOVK/movk-nuxt/**/*";
1
+ @source "/Users/yixuanmiao/Projects/movk-nuxt/**/*";
2
2
  @source "./movk-ui";
3
3
  @source inline("{,sm:,md:,lg:,xl:}grid-cols-{1,2,3,4,5,6,7,8,9,10,11,12}");
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "configKey": "movk",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.4.2"
package/dist/module.mjs CHANGED
@@ -15,7 +15,7 @@ import 'pathe';
15
15
  import 'tinyglobby';
16
16
 
17
17
  const name = "@movk/nuxt";
18
- const version = "1.7.1";
18
+ const version = "1.7.2";
19
19
 
20
20
  const MOVK_CSS_IMPORT = /@import\s+["']@movk\/nuxt["']/;
21
21
  async function checkMovkCss(nuxt) {
@@ -64,7 +64,7 @@ export function useDownloadWithProgress() {
64
64
  }
65
65
  try {
66
66
  const response = await fetch(fullUrl, fetchInit);
67
- const fetchContext = buildFetchContext(fullUrl, { context: { toast, skipBusinessCheck } }, {
67
+ const fetchContext = buildFetchContext(fullUrl, { method, context: { toast, skipBusinessCheck } }, {
68
68
  status: response.status,
69
69
  headers: response.headers
70
70
  });
@@ -61,7 +61,7 @@ export function useUploadWithProgress() {
61
61
  });
62
62
  const finishWith = async (raw, fallback) => {
63
63
  const responseHeaders = parseXhrHeaders(xhr.getAllResponseHeaders());
64
- const fetchContext = buildFetchContext(fullUrl, { context: { toast, skipBusinessCheck } }, {
64
+ const fetchContext = buildFetchContext(fullUrl, { method: "POST", context: { toast, skipBusinessCheck } }, {
65
65
  status: xhr.status,
66
66
  headers: responseHeaders
67
67
  });
@@ -1,4 +1,11 @@
1
- import defu from "defu";
1
+ import defu, { createDefu } from "defu";
2
+ const mergeToastConfig = createDefu((obj, key, value) => {
3
+ if (key === "methods" && Array.isArray(value)) {
4
+ obj[key] = value;
5
+ return true;
6
+ }
7
+ return false;
8
+ });
2
9
  export function resolveEndpointConfig(publicConfig, endpoint, privateEndpoints) {
3
10
  const endpointName = endpoint || publicConfig.defaultEndpoint || "default";
4
11
  const endpointConfig = publicConfig.endpoints?.[endpointName];
@@ -15,7 +22,7 @@ export function resolveEndpointConfig(publicConfig, endpoint, privateEndpoints)
15
22
  baseURL: endpointConfig.baseURL || "",
16
23
  headers: Object.keys(mergedHeaders).length > 0 ? mergedHeaders : void 0,
17
24
  auth: defu(endpointConfig.auth, publicConfig.auth),
18
- toast: defu(endpointConfig.toast, publicConfig.toast),
25
+ toast: mergeToastConfig(endpointConfig.toast ?? {}, publicConfig.toast ?? {}),
19
26
  response: defu(endpointConfig.response, publicConfig.response)
20
27
  };
21
28
  }
@@ -41,7 +41,7 @@ export function createOnResponseError(resolvedConfig, publicConfig, nuxtApp) {
41
41
  }
42
42
  const data = response._data;
43
43
  const fallback = `\u8BF7\u6C42\u5931\u8D25 (${response.status})`;
44
- showToast("error", data ?? fallback, toast, toastConfig, responseConfig);
44
+ showToast("error", data ?? fallback, toast, toastConfig, responseConfig, context.options.method);
45
45
  if (publicConfig.debug) {
46
46
  console.error("[@movk/nuxt] Error:", response.status, response._data);
47
47
  }
@@ -17,11 +17,11 @@ export function createOnResponse(resolvedConfig, publicConfig, nuxtApp) {
17
17
  context.response._data = extractData(raw, responseConfig);
18
18
  }
19
19
  await nuxtApp.callHook("movk:api:response", context);
20
- showToast("success", raw, toast, toastConfig, responseConfig);
20
+ showToast("success", raw, toast, toastConfig, responseConfig, context.options.method);
21
21
  return;
22
22
  }
23
23
  await nuxtApp.callHook("movk:api:error", context);
24
- showToast("error", raw, toast, toastConfig, responseConfig);
24
+ showToast("error", raw, toast, toastConfig, responseConfig, context.options.method);
25
25
  throw createApiError(raw, extractMessage(raw, responseConfig));
26
26
  };
27
27
  }
@@ -10,8 +10,10 @@ type ToastType = 'success' | 'error';
10
10
  * @param requestOptions 单次请求覆盖配置;为 false 时整体禁用
11
11
  * @param globalConfig 全局 Toast 配置(已合并端点级覆盖)
12
12
  * @param responseConfig 用于从 ApiResponse 抽取 message 的字段映射;source 为字符串时可省略
13
- * @description 开关优先级:请求级 show 显式声明 > 全局 typeConfig.show > 全局 enabled。
14
- * 请求级 `show: true` 可在全局关闭时单次开启。
13
+ * @param method 当前请求的 HTTP 方法,用于匹配 globalConfig 的方法白名单;缺省按 GET 处理
14
+ * @description 开关优先级:请求级 show 显式声明 > 请求级 successMessage / errorMessage >
15
+ * 全局 typeConfig.show / typeConfig.methods > 全局 enabled。
16
+ * 请求级 `show: true` 或自定义文案均可在全局关闭时单次开启。
15
17
  */
16
- export declare function showToast(type: ToastType, source: ApiResponse | string | undefined, requestOptions: RequestToastOptions | false | undefined, globalConfig: Partial<ApiToastConfig>, responseConfig?: Partial<ApiResponseConfig>): void;
18
+ export declare function showToast(type: ToastType, source: ApiResponse | string | undefined, requestOptions: RequestToastOptions | false | undefined, globalConfig: Partial<ApiToastConfig>, responseConfig?: Partial<ApiResponseConfig>, method?: string): void;
17
19
  export {};
@@ -20,6 +20,11 @@ function pickMessage(type, source, requestOptions, responseConfig) {
20
20
  }
21
21
  return type === "success" ? "\u64CD\u4F5C\u6210\u529F" : "\u8BF7\u6C42\u5931\u8D25";
22
22
  }
23
+ function matchesMethod(methods, method) {
24
+ if (!methods) return true;
25
+ const current = (method || "GET").toUpperCase();
26
+ return methods.some((item) => item.toUpperCase() === current);
27
+ }
23
28
  function compact(obj) {
24
29
  const out = {};
25
30
  for (const [k, v] of Object.entries(obj)) {
@@ -27,19 +32,20 @@ function compact(obj) {
27
32
  }
28
33
  return out;
29
34
  }
30
- export function showToast(type, source, requestOptions, globalConfig, responseConfig) {
35
+ export function showToast(type, source, requestOptions, globalConfig, responseConfig, method) {
31
36
  if (requestOptions === false) return;
32
37
  const requestTypeOptions = requestOptions?.[type];
33
38
  if (requestTypeOptions === false) return;
34
39
  const typeConfig = globalConfig[type];
35
40
  const requestShow = requestTypeOptions?.show;
36
- const globalShow = globalConfig.enabled !== false && typeConfig?.show !== false;
37
- if (requestShow === false || requestShow === void 0 && !globalShow) return;
41
+ const globalShow = globalConfig.enabled !== false && typeConfig?.show !== false && matchesMethod(typeConfig?.methods, method);
42
+ const hasRequestMessage = typeof requestOptions === "object" && !!requestOptions?.[`${type}Message`];
43
+ if (requestShow === false || requestShow === void 0 && !globalShow && !hasRequestMessage) return;
38
44
  const message = pickMessage(type, source, requestOptions, responseConfig);
39
45
  if (!message) return;
40
46
  const toast = getToast();
41
47
  if (!toast) return;
42
- const { show: _show, ...typeConfigProps } = typeConfig ?? {};
48
+ const { show: _show, methods: _methods, ...typeConfigProps } = typeConfig ?? {};
43
49
  const { show: _requestShow, ...requestTypeConfig } = requestTypeOptions ?? {};
44
50
  toast.add(compact({
45
51
  title: message,
@@ -48,6 +48,7 @@ export function parseXhrHeaders(raw) {
48
48
  export async function finalizeTransfer(nuxtApp, ctx) {
49
49
  const { raw, fallback, config, publicConfig, requestToast, skipBusinessCheck, fetchContext } = ctx;
50
50
  const { response: responseConfig, toast: toastConfig } = config;
51
+ const method = fetchContext.options?.method;
51
52
  if (publicConfig.debug) {
52
53
  console.info("[@movk/nuxt] Transfer response:", raw ?? fallback);
53
54
  }
@@ -59,7 +60,7 @@ export async function finalizeTransfer(nuxtApp, ctx) {
59
60
  fetchContext.response._data = data;
60
61
  }
61
62
  await nuxtApp.callHook("movk:api:response", fetchContext);
62
- showToast("success", raw ?? fallback?.message, requestToast, toastConfig, responseConfig);
63
+ showToast("success", raw ?? fallback?.message, requestToast, toastConfig, responseConfig, method);
63
64
  return { data, error: null, aborted: false };
64
65
  }
65
66
  const message = hasRaw ? extractMessage(raw, responseConfig) || fallback?.message : fallback?.message;
@@ -69,7 +70,7 @@ export async function finalizeTransfer(nuxtApp, ctx) {
69
70
  }
70
71
  fetchContext.error = apiError;
71
72
  await nuxtApp.callHook("movk:api:error", fetchContext);
72
- showToast("error", raw ?? message, requestToast, toastConfig, responseConfig);
73
+ showToast("error", raw ?? message, requestToast, toastConfig, responseConfig, method);
73
74
  return { data: null, error: apiError, aborted: false };
74
75
  }
75
76
  export function buildFetchContext(request, options, response) {
@@ -86,6 +86,17 @@ export interface ApiToast extends Partial<Toast> {
86
86
  */
87
87
  show?: boolean;
88
88
  }
89
+ /**
90
+ * 全局 / 端点级的单类型 Toast 配置
91
+ * @description 在 ApiToast 基础上增加方法白名单,请求级配置不含 methods
92
+ */
93
+ export interface ApiToastTypeConfig extends ApiToast {
94
+ /**
95
+ * 仅在这些 HTTP 方法上显示(大小写不敏感),未声明表示不限制
96
+ * @example `['POST', 'PUT', 'PATCH', 'DELETE']`
97
+ */
98
+ methods?: Suggest<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'>[];
99
+ }
89
100
  /**
90
101
  * Toast 提示配置
91
102
  * @description 定义成功和错误提示的全局样式和行为
@@ -99,11 +110,11 @@ export interface ApiToastConfig {
99
110
  /**
100
111
  * 成功提示配置
101
112
  */
102
- success?: ApiToast;
113
+ success?: ApiToastTypeConfig;
103
114
  /**
104
115
  * 错误提示配置
105
116
  */
106
- error?: ApiToast;
117
+ error?: ApiToastTypeConfig;
107
118
  }
108
119
  /**
109
120
  * API 端点公共配置
@@ -31,9 +31,9 @@ export interface RequestToastOptions {
31
31
  success?: ApiToast | false;
32
32
  /** 错误提示配置,设置为 false 禁用错误提示;`show: true` 可覆盖全局关闭 */
33
33
  error?: ApiToast | false;
34
- /** 自定义成功消息 */
34
+ /** 自定义成功消息;传入即视为本次开启成功提示,可覆盖全局关闭 */
35
35
  successMessage?: string;
36
- /** 自定义错误消息 */
36
+ /** 自定义错误消息;传入即视为本次开启错误提示,可覆盖全局关闭 */
37
37
  errorMessage?: string;
38
38
  }
39
39
  /**
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
3
  "type": "module",
4
- "version": "1.7.1",
5
- "packageManager": "pnpm@11.20.0",
4
+ "version": "1.7.2",
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>",
8
8
  "license": "MIT",
@@ -133,11 +133,11 @@
133
133
  "@vueuse/nuxt": "^14.4.0",
134
134
  "colortranslator": "^6.1.1",
135
135
  "defu": "^6.1.7",
136
- "magic-string": "^1.1.0",
136
+ "magic-string": "^1.2.0",
137
137
  "maska": "^3.2.0",
138
138
  "mlly": "^1.8.2",
139
139
  "nuxt-auth-utils": "^0.5.30",
140
- "nuxt-site-config": "^4.1.5",
140
+ "nuxt-site-config": "^4.2.3",
141
141
  "pathe": "^2.0.3",
142
142
  "reka-ui": "2.10.1",
143
143
  "scule": "^1.3.0",
@@ -148,24 +148,24 @@
148
148
  "zod": "^4.4.3"
149
149
  },
150
150
  "devDependencies": {
151
- "@iconify-json/lucide": "^1.2.121",
151
+ "@iconify-json/lucide": "^1.2.123",
152
152
  "@iconify-json/ph": "^1.2.2",
153
153
  "@iconify-json/tabler": "^1.2.38",
154
- "@nuxt/eslint-config": "^1.16.0",
155
- "@nuxt/kit": "^4.5.1",
154
+ "@nuxt/eslint-config": "^1.17.0",
155
+ "@nuxt/kit": "^4.5.2",
156
156
  "@nuxt/module-builder": "^1.0.3",
157
- "@nuxt/schema": "^4.5.1",
157
+ "@nuxt/schema": "^4.5.2",
158
158
  "@release-it/conventional-changelog": "^12.0.0",
159
- "eslint": "^10.8.0",
160
- "happy-dom": "^20.11.1",
161
- "nuxt": "^4.5.1",
162
- "release-it": "^21.0.1",
159
+ "eslint": "^10.8.1",
160
+ "happy-dom": "^20.11.2",
161
+ "nuxt": "^4.5.2",
162
+ "release-it": "^21.0.2",
163
163
  "typescript": "^6.0.3",
164
164
  "unbuild": "^3.6.1",
165
165
  "unplugin-auto-import": "^21.1.0",
166
166
  "unplugin-vue-components": "^32.1.0",
167
167
  "vitest": "^4.1.10",
168
- "vue": "^3.5.40",
169
- "vue-tsc": "^3.3.9"
168
+ "vue": "^3.5.41",
169
+ "vue-tsc": "^3.3.10"
170
170
  }
171
171
  }