@movk/nuxt 1.5.1 → 1.6.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.
package/dist/module.d.mts CHANGED
@@ -49,8 +49,20 @@ interface ModuleOptions {
49
49
  * @example 'tw'
50
50
  */
51
51
  prefix?: StrictUiTheme['prefix'];
52
+ /**
53
+ * 默认字体,取值需与 `fonts` 中某一项的 `name` 一致。
54
+ * 缺省时不注入 `--font-sans`,字体由项目 CSS 的 `@theme` 决定
55
+ * @example 'Alibaba PuHuiTi'
56
+ */
57
+ font?: string;
52
58
  /** ThemePicker 字体可选项;提供时完整替换内置列表 */
53
59
  fonts?: ThemeFontConfig[];
60
+ /**
61
+ * 默认圆角(单位 rem)。缺省时不注入 `--ui-radius`,
62
+ * 沿用 `@nuxt/ui` 的默认值或项目 CSS 的声明
63
+ * @example 0.5
64
+ */
65
+ radius?: number;
54
66
  /** ThemePicker 圆角可选项 */
55
67
  radiuses?: number[];
56
68
  /** ThemePicker neutral 颜色可选项 */
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "configKey": "movk",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.4.2"
package/dist/module.mjs CHANGED
@@ -9,7 +9,7 @@ export * from '../dist/runtime/types/index.js';
9
9
  import 'node:url';
10
10
 
11
11
  const name = "@movk/nuxt";
12
- const version = "1.5.1";
12
+ const version = "1.6.0";
13
13
 
14
14
  function getDefaultApiConfig(apiConfig) {
15
15
  const publicEndpoints = {};
@@ -132,7 +132,7 @@ const module$1 = defineNuxtModule({
132
132
  nuxt.options.movk = options;
133
133
  nuxt.options.alias["#movk"] = resolve("./runtime");
134
134
  nuxt.options.css = nuxt.options.css || [];
135
- nuxt.options.css.push(resolve("runtime/index.css"));
135
+ nuxt.options.css.unshift(resolve("runtime/index.css"));
136
136
  const movkUiDeps = UI_COMPONENTS.map((name2) => name2.slice(1));
137
137
  const uiOptions = nuxt.options;
138
138
  const ui = uiOptions.ui ??= {};
@@ -21,7 +21,7 @@ const props = defineProps({
21
21
  globalMeta: { type: Object, required: false },
22
22
  loadingAuto: { type: Boolean, required: false, default: true },
23
23
  validateOn: { type: Array, required: false, default: () => [] },
24
- class: { type: null, required: false },
24
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
25
25
  ui: { type: Object, required: false }
26
26
  });
27
27
  const emits = defineEmits(["error"]);
@@ -61,7 +61,7 @@ const props = defineProps({
61
61
  loadMore: { type: Function, required: false },
62
62
  canLoadMore: { type: Boolean, required: false },
63
63
  loadMoreDistance: { type: Number, required: false },
64
- class: { type: null, required: false },
64
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
65
65
  ui: { type: Object, required: false }
66
66
  });
67
67
  const paginationState = defineModel("pagination", { type: Object });
@@ -25,7 +25,7 @@ const props = defineProps({
25
25
  min: { type: Number, required: false },
26
26
  defaultValue: { type: null, required: false },
27
27
  modelValue: { type: null, required: false },
28
- class: { type: null, required: false },
28
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
29
29
  ui: { type: Object, required: false }
30
30
  });
31
31
  const modelValue = defineModel({ type: null });
@@ -27,7 +27,7 @@ const props = defineProps({
27
27
  globalMeta: { type: Object, required: false },
28
28
  loadingAuto: { type: Boolean, required: false, default: true },
29
29
  validateOn: { type: Array, required: false, default: () => [] },
30
- class: { type: null, required: false },
30
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
31
31
  ui: { type: Object, required: false }
32
32
  });
33
33
  const modelValue = defineModel({ type: Object, ...{ default: () => ({}) } });
@@ -16,7 +16,7 @@ const props = defineProps({
16
16
  icon: { type: null, required: false, default: "i-lucide-chevrons-right" },
17
17
  successIcon: { type: null, required: false, default: "i-lucide-check" },
18
18
  threshold: { type: Number, required: false, default: 0.9 },
19
- class: { type: null, required: false },
19
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
20
20
  ui: { type: Object, required: false }
21
21
  });
22
22
  const emits = defineEmits(["success", "dragStart", "dragEnd"]);
@@ -39,7 +39,7 @@ const props = defineProps({
39
39
  toolbar: { type: Boolean, required: false },
40
40
  checkable: { type: Boolean, required: false },
41
41
  ui: { type: Object, required: false },
42
- class: { type: null, required: false }
42
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true }
43
43
  });
44
44
  const emit = defineEmits(["update:modelValue", "update:expanded", "update:search", "change"]);
45
45
  defineSlots();
@@ -6,11 +6,7 @@ export declare function useTheme(): {
6
6
  id: string;
7
7
  tagPriority: number;
8
8
  }[];
9
- link: import("vue").ComputedRef<{
10
- rel: "stylesheet";
11
- href: string;
12
- id: string;
13
- }[]>;
9
+ link: import("vue").ComputedRef<import("../domains/theme/theme-font").ThemeFontLink[]>;
14
10
  neutralColors: string[];
15
11
  neutral: import("vue").WritableComputedRef<string, string>;
16
12
  primaryColors: string[];
@@ -1,21 +1,28 @@
1
1
  import { useAppConfig, useColorMode, useSiteConfig } from "#imports";
2
2
  import { resolveThemeIcons, themeIcons } from "../domains/theme/theme-icons.js";
3
+ import { resolveActiveFont, resolveFontLinks, resolveFontStyle } from "../domains/theme/theme-font.js";
4
+ import { resolveActiveRadius, resolveRadiusStyle } from "../domains/theme/theme-radius.js";
3
5
  import { omit, kebabCase } from "@movk/core";
4
6
  import { useLocalStorage } from "@vueuse/core";
5
7
  import colors from "tailwindcss/colors";
6
8
  import { computed } from "vue";
7
9
  import { getDefaultConfig } from "../utils/theme-defaults.js";
10
+ const UI_DEFAULT_RADIUS = 0.25;
8
11
  export function useTheme() {
9
12
  const { movk, ui } = useAppConfig();
10
13
  const colorMode = useColorMode();
11
14
  const name = kebabCase(useSiteConfig().name);
12
15
  const color = computed(() => colorMode.value === "dark" ? colors[ui.colors.neutral][900] : "white");
13
16
  const defaultConfig = getDefaultConfig();
14
- const _radius = useLocalStorage(`${name}-ui-radius`, movk?.radius ?? defaultConfig.radius);
15
- const _font = useLocalStorage(`${name}-ui-font`, movk?.font ?? defaultConfig.font);
17
+ const _radius = useLocalStorage(`${name}-ui-radius`, null, { writeDefaults: false });
18
+ const _font = useLocalStorage(`${name}-ui-font`, "", { writeDefaults: false });
16
19
  const _iconSet = useLocalStorage(`${name}-ui-icons`, movk?.icons ?? defaultConfig.icons);
17
20
  const _blackAsPrimary = useLocalStorage(`${name}-ui-black-as-primary`, defaultConfig.blackAsPrimary);
18
21
  const pickerFonts = movk?.picker?.fonts ?? [];
22
+ const configuredFont = movk?.font ?? defaultConfig.font;
23
+ const activeFont = computed(() => resolveActiveFont(_font.value, configuredFont));
24
+ const configuredRadius = movk?.radius ?? defaultConfig.radius;
25
+ const activeRadius = computed(() => resolveActiveRadius(_radius.value, configuredRadius));
19
26
  const neutralColors = movk?.picker?.neutralColors ?? [];
20
27
  const neutral = computed({
21
28
  get() {
@@ -41,7 +48,7 @@ export function useTheme() {
41
48
  const radiuses = movk?.picker?.radiuses ?? [];
42
49
  const radius = computed({
43
50
  get() {
44
- return _radius.value;
51
+ return activeRadius.value ?? UI_DEFAULT_RADIUS;
45
52
  },
46
53
  set(option) {
47
54
  _radius.value = option;
@@ -50,7 +57,7 @@ export function useTheme() {
50
57
  const fonts = pickerFonts.map((f) => f.name);
51
58
  const font = computed({
52
59
  get() {
53
- return _font.value;
60
+ return activeFont.value;
54
61
  },
55
62
  set(option) {
56
63
  _font.value = option;
@@ -87,26 +94,17 @@ export function useTheme() {
87
94
  function setBlackAsPrimary(value) {
88
95
  _blackAsPrimary.value = value;
89
96
  }
90
- const radiusStyle = computed(() => `:root { --ui-radius: ${_radius.value}rem; }`);
97
+ const radiusStyle = computed(() => resolveRadiusStyle(activeRadius.value));
91
98
  const blackAsPrimaryStyle = computed(() => _blackAsPrimary.value ? `:root { --ui-primary: black; } .dark { --ui-primary: white; }` : ":root {}");
92
- const fontStyle = computed(() => `:root { --font-sans: '${_font.value}', sans-serif; }`);
93
- const link = computed(() => {
94
- const fontName = _font.value;
95
- const fontConfig = pickerFonts.find((f) => f.name === fontName);
96
- const href = fontConfig?.href ?? `https://fonts.googleapis.com/css2?family=${encodeURIComponent(fontName)}:wght@400;500;600;700&display=swap`;
97
- return [{
98
- rel: "stylesheet",
99
- href,
100
- id: `font-${fontName.toLowerCase().replace(/\s+/g, "-")}`
101
- }];
102
- });
99
+ const fontStyle = computed(() => resolveFontStyle(activeFont.value));
100
+ const link = computed(() => resolveFontLinks(activeFont.value, pickerFonts));
103
101
  const style = [
104
102
  { innerHTML: radiusStyle, id: `nuxt-ui-radius`, tagPriority: -2 },
105
103
  { innerHTML: blackAsPrimaryStyle, id: `nuxt-ui-black-as-primary`, tagPriority: -2 },
106
104
  { innerHTML: fontStyle, id: `nuxt-ui-font`, tagPriority: -2 }
107
105
  ];
108
106
  const hasCSSChanges = computed(() => {
109
- return _radius.value !== (movk?.radius ?? defaultConfig.radius) || _blackAsPrimary.value || _font.value !== (movk?.font ?? defaultConfig.font);
107
+ return activeRadius.value !== configuredRadius || _blackAsPrimary.value || activeFont.value !== configuredFont;
110
108
  });
111
109
  const hasConfigChanges = computed(() => {
112
110
  return ui.colors.primary !== "blue" || ui.colors.neutral !== "slate" || _iconSet.value !== (movk?.icons ?? defaultConfig.icons);
@@ -116,12 +114,12 @@ export function useTheme() {
116
114
  '@import "tailwindcss";',
117
115
  '@import "@nuxt/ui";'
118
116
  ];
119
- if (_font.value !== defaultConfig.font) {
120
- lines.push("", "@theme {", ` --font-sans: '${_font.value}', sans-serif;`, "}");
117
+ if (activeFont.value && activeFont.value !== configuredFont) {
118
+ lines.push("", "@theme {", ` --font-sans: ${JSON.stringify(activeFont.value)}, sans-serif;`, "}");
121
119
  }
122
120
  const rootLines = [];
123
- if (_radius.value !== defaultConfig.radius) {
124
- rootLines.push(` --ui-radius: ${_radius.value}rem;`);
121
+ if (activeRadius.value !== void 0 && activeRadius.value !== configuredRadius) {
122
+ rootLines.push(` --ui-radius: ${activeRadius.value}rem;`);
125
123
  }
126
124
  if (_blackAsPrimary.value) {
127
125
  rootLines.push(" --ui-primary: black;");
@@ -169,8 +167,8 @@ export function useTheme() {
169
167
  window.localStorage.removeItem(`${name}-ui-primary`);
170
168
  ui.colors.neutral = defaultNeutral;
171
169
  window.localStorage.removeItem(`${name}-ui-neutral`);
172
- _radius.value = movk?.radius ?? defaultConfig.radius;
173
- _font.value = movk?.font ?? defaultConfig.font;
170
+ _radius.value = null;
171
+ _font.value = "";
174
172
  _iconSet.value = defaultIcon;
175
173
  ui.icons = resolveThemeIcons(defaultIcon, ui.icons);
176
174
  _blackAsPrimary.value = movk?.blackAsPrimary ?? defaultConfig.blackAsPrimary;
@@ -10,6 +10,8 @@ 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
15
  */
14
16
  export declare function showToast(type: ToastType, source: ApiResponse | string | undefined, requestOptions: RequestToastOptions | false | undefined, globalConfig: Partial<ApiToastConfig>, responseConfig?: Partial<ApiResponseConfig>): void;
15
17
  export {};
@@ -28,16 +28,19 @@ function compact(obj) {
28
28
  return out;
29
29
  }
30
30
  export function showToast(type, source, requestOptions, globalConfig, responseConfig) {
31
- if (globalConfig.enabled === false || requestOptions === false) return;
31
+ if (requestOptions === false) return;
32
+ const requestTypeOptions = requestOptions?.[type];
33
+ if (requestTypeOptions === false) return;
32
34
  const typeConfig = globalConfig[type];
33
- if (typeConfig?.show === false) return;
34
- if (requestOptions?.[type] === false) return;
35
+ const requestShow = requestTypeOptions?.show;
36
+ const globalShow = globalConfig.enabled !== false && typeConfig?.show !== false;
37
+ if (requestShow === false || requestShow === void 0 && !globalShow) return;
35
38
  const message = pickMessage(type, source, requestOptions, responseConfig);
36
39
  if (!message) return;
37
40
  const toast = getToast();
38
41
  if (!toast) return;
39
42
  const { show: _show, ...typeConfigProps } = typeConfig ?? {};
40
- const requestTypeConfig = typeof requestOptions?.[type] === "object" ? requestOptions[type] : {};
43
+ const { show: _requestShow, ...requestTypeConfig } = requestTypeOptions ?? {};
41
44
  toast.add(compact({
42
45
  title: message,
43
46
  ...typeConfigProps,
@@ -1,8 +1,8 @@
1
1
  import type { IsComponent } from '@movk/core';
2
2
  import type { AutoFormControl, _Unset } from '../../types/auto-form/controls';
3
- import type { InputProps, InputSlots, TextareaProps, TextareaSlots } from '@nuxt/ui';
3
+ import type { CheckboxGroupProps, CheckboxGroupSlots, CheckboxProps, CheckboxSlots, FileUploadProps, FileUploadSlots, InputDateProps, InputDateSlots, InputMenuProps, InputMenuSlots, InputNumberProps, InputNumberSlots, InputProps, InputSlots, InputTagsProps, InputTagsSlots, InputTimeProps, InputTimeSlots, ListboxProps, ListboxSlots, PinInputProps, PinInputSlots, RadioGroupProps, RadioGroupSlots, SelectMenuProps, SelectMenuSlots, SelectProps, SelectSlots, SliderProps, SwitchProps, SwitchSlots, TextareaProps, TextareaSlots } from '@nuxt/ui';
4
4
  import type { CalendarDateControlProps } from '../../types/components/date-picker';
5
- import { UInput, UTextarea } from '#components';
5
+ import { UInput } from '#components';
6
6
  export declare function defineControl<C extends IsComponent, P = _Unset, S = _Unset>(e: AutoFormControl<C, P, S>): AutoFormControl<C, P, S>;
7
7
  declare const DEFAULT_CONTROL_COMPONENTS: {
8
8
  readonly string: any;
@@ -595,8 +595,33 @@ declare const DEFAULT_CONTROL_COMPONENTS: {
595
595
  };
596
596
  };
597
597
  type DefaultControlComponents = typeof DEFAULT_CONTROL_COMPONENTS;
598
+ /**
599
+ * Nuxt UI 控件的 `[props, slots]` 类型登记表。
600
+ *
601
+ * `#components` 在模块声明发射期无法解析,`U*` 组件类型会退化为 `any`,
602
+ * 使 `controlProps` / `controlSlots` 在消费端失去类型提示;此处显式登记以绕开组件推导。
603
+ */
604
+ interface NuxtUIControlTypes {
605
+ string: [InputProps, InputSlots];
606
+ number: [InputNumberProps, InputNumberSlots];
607
+ boolean: [CheckboxProps, CheckboxSlots];
608
+ enum: [SelectProps, SelectSlots];
609
+ file: [FileUploadProps, FileUploadSlots];
610
+ inputDate: [InputDateProps, InputDateSlots];
611
+ inputTime: [InputTimeProps, InputTimeSlots];
612
+ textarea: [TextareaProps, TextareaSlots];
613
+ switch: [SwitchProps, SwitchSlots];
614
+ slider: [SliderProps, _Unset];
615
+ selectMenu: [SelectMenuProps, SelectMenuSlots];
616
+ inputMenu: [InputMenuProps, InputMenuSlots];
617
+ checkboxGroup: [CheckboxGroupProps, CheckboxGroupSlots];
618
+ radioGroup: [RadioGroupProps, RadioGroupSlots];
619
+ inputTags: [InputTagsProps, InputTagsSlots];
620
+ pinInput: [PinInputProps, PinInputSlots];
621
+ listbox: [ListboxProps, ListboxSlots];
622
+ }
598
623
  type DefaultControlMap = {
599
- 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]>;
624
+ readonly [K in keyof DefaultControlComponents]: K extends keyof NuxtUIControlTypes ? AutoFormControl<DefaultControlComponents[K], NuxtUIControlTypes[K][0], NuxtUIControlTypes[K][1]> : K extends 'calendarDate' ? AutoFormControl<DefaultControlComponents[K], CalendarDateControlProps> : AutoFormControl<DefaultControlComponents[K]>;
600
625
  };
601
626
  export declare const DEFAULT_CONTROLS: DefaultControlMap;
602
627
  export {};
@@ -0,0 +1,29 @@
1
+ export interface ThemeFontOption {
2
+ name: string;
3
+ href?: string;
4
+ }
5
+ export type ThemeFontLink = {
6
+ rel: 'stylesheet';
7
+ href: string;
8
+ id: string;
9
+ };
10
+ export declare function googleFontsHref(name: string): string;
11
+ export declare function resolveFontId(name: string): string;
12
+ /**
13
+ * 仅为已登记的字体解析样式表地址:缺省 href 的可选项视为 Google Fonts 托管,
14
+ * 未登记的字体不猜测来源,避免在无法访问 Google 的网络环境下发出必然失败的请求。
15
+ */
16
+ export declare function resolveFontHref(name: string, fonts: ThemeFontOption[]): string | undefined;
17
+ export declare function resolveFontLinks(name: string | undefined, fonts: ThemeFontOption[]): ThemeFontLink[];
18
+ /**
19
+ * 未指定字体时输出空规则。该 style 无层级(unlayered),会压过使用者写在
20
+ * `@theme` 中的 `--font-sans`,因此只在字体被显式配置或用户主动切换时才声明。
21
+ */
22
+ export declare function resolveFontStyle(name: string | undefined): string;
23
+ /**
24
+ * 合并用户选择与配置的默认字体。项目未配置 `theme.font` 时 localStorage 会存下空串,
25
+ * 之后再配置默认字体不应被这份历史残留屏蔽,故空串视同未选择。
26
+ */
27
+ export declare function resolveActiveFont(stored: string | undefined, configured: string | undefined): string;
28
+ /** 预解析全部可选项地址,供预水合脚本查表,避免客户端重复猜测字体来源 */
29
+ export declare function resolveFontHrefMap(fonts: ThemeFontOption[]): Record<string, string>;
@@ -0,0 +1,29 @@
1
+ export function googleFontsHref(name) {
2
+ return `https://fonts.googleapis.com/css2?family=${encodeURIComponent(name)}:wght@400;500;600;700&display=swap`;
3
+ }
4
+ export function resolveFontId(name) {
5
+ return `font-${name.toLowerCase().replace(/\s+/g, "-")}`;
6
+ }
7
+ export function resolveFontHref(name, fonts) {
8
+ const option = fonts.find((f) => f.name === name);
9
+ if (!option) return void 0;
10
+ return option.href ?? googleFontsHref(name);
11
+ }
12
+ export function resolveFontLinks(name, fonts) {
13
+ if (!name) return [];
14
+ const href = resolveFontHref(name, fonts);
15
+ if (!href) return [];
16
+ return [{ rel: "stylesheet", href, id: resolveFontId(name) }];
17
+ }
18
+ export function resolveFontStyle(name) {
19
+ if (!name) return ":root {}";
20
+ return `:root { --font-sans: ${JSON.stringify(name)}, sans-serif; }`;
21
+ }
22
+ export function resolveActiveFont(stored, configured) {
23
+ return stored || configured || "";
24
+ }
25
+ export function resolveFontHrefMap(fonts) {
26
+ return Object.fromEntries(
27
+ fonts.map((f) => [f.name, f.href ?? googleFontsHref(f.name)])
28
+ );
29
+ }
@@ -0,0 +1,7 @@
1
+ /** 合并用户选择与配置的默认圆角。0 是合法档位,仅 null/undefined 视为未选择 */
2
+ export declare function resolveActiveRadius(stored: number | null | undefined, configured: number | undefined): number | undefined;
3
+ /**
4
+ * 缺省时输出空规则。该 style 无层级(unlayered),会压过项目 CSS 写在
5
+ * `@theme` 中的 `--ui-radius`,因此只在圆角被显式配置或用户主动切换时才声明。
6
+ */
7
+ export declare function resolveRadiusStyle(radius: number | undefined): string;
@@ -0,0 +1,7 @@
1
+ export function resolveActiveRadius(stored, configured) {
2
+ return stored ?? configured;
3
+ }
4
+ export function resolveRadiusStyle(radius) {
5
+ if (radius === void 0) return ":root {}";
6
+ return `:root { --ui-radius: ${radius}rem; }`;
7
+ }
@@ -1 +1 @@
1
- @import "tailwindcss" theme(static);@import "@nuxt/ui";@import "#build/movk-ui.css";@source "./components";@theme static{--font-sans:"Alibaba PuHuiTi",sans-serif}@layer base{[role=button]:not(:disabled),button:not(:disabled){cursor:pointer}}
1
+ @import "tailwindcss" theme(static);@import "@nuxt/ui";@import "#build/movk-ui.css";@source "./components";@layer base{[role=button]:not(:disabled),button:not(:disabled){cursor:pointer}}
@@ -1,6 +1,7 @@
1
1
  import { kebabCase } from "@movk/core";
2
2
  import { defineNuxtPlugin, useAppConfig, useHead, useSiteConfig } from "#imports";
3
3
  import { resolveThemeIcons } from "../domains/theme/theme-icons.js";
4
+ import { resolveFontHrefMap } from "../domains/theme/theme-font.js";
4
5
  export default defineNuxtPlugin({
5
6
  enforce: "post",
6
7
  setup() {
@@ -17,11 +18,7 @@ export default defineNuxtPlugin({
17
18
  }
18
19
  if (import.meta.server) {
19
20
  const pickerFonts = appConfig.movk?.picker?.fonts ?? [];
20
- const fontHrefMap = {};
21
- for (const f of pickerFonts) {
22
- if (f.href) fontHrefMap[f.name] = f.href;
23
- }
24
- const fontHrefMapJson = JSON.stringify(fontHrefMap);
21
+ const fontHrefMapJson = JSON.stringify(resolveFontHrefMap(pickerFonts));
25
22
  useHead({
26
23
  script: [{
27
24
  innerHTML: `
@@ -69,8 +66,8 @@ export default defineNuxtPlugin({
69
66
  tagPriority: -1
70
67
  }, {
71
68
  innerHTML: `
72
- var r = localStorage.getItem('${name}-ui-radius');
73
- if (r) document.documentElement.style.setProperty('--ui-radius', r + 'rem');
69
+ var r = parseFloat(localStorage.getItem('${name}-ui-radius'));
70
+ if (isFinite(r)) document.documentElement.style.setProperty('--ui-radius', r + 'rem');
74
71
  `.replace(/\s+/g, " "),
75
72
  type: "text/javascript",
76
73
  tagPriority: -1
@@ -83,16 +80,22 @@ export default defineNuxtPlugin({
83
80
  `.replace(/\s+/g, " ")
84
81
  }, {
85
82
  innerHTML: [
86
- `if (localStorage.getItem('${name}-ui-font')) {`,
87
83
  `var font = localStorage.getItem('${name}-ui-font');`,
84
+ `if (font) {`,
88
85
  `var fontEl = document.querySelector('style#nuxt-ui-font');`,
89
- `if (fontEl) { fontEl.innerHTML = ':root { --font-sans: \\'' + font + '\\', sans-serif; }'; }`,
86
+ // textContent 而非 innerHTML:字体名来自 localStorage,避免被当作标记解析
87
+ `if (fontEl) { fontEl.textContent = ':root { --font-sans: ' + JSON.stringify(font) + ', sans-serif; }'; }`,
90
88
  `var fontMap = ${fontHrefMapJson};`,
89
+ `var href = fontMap[font];`,
90
+ `var id = 'font-' + font.toLowerCase().replace(/\\s+/g, '-');`,
91
+ // 未登记的字体不猜测来源;已由 SSR 输出的 link 不重复插入
92
+ `if (href && !document.getElementById(id)) {`,
91
93
  `var lnk = document.createElement('link');`,
92
94
  `lnk.rel = 'stylesheet';`,
93
- `lnk.href = fontMap[font] || ('https://fonts.googleapis.com/css2?family=' + encodeURIComponent(font) + ':wght@400;500;600;700&display=swap');`,
94
- `lnk.id = 'font-' + font.toLowerCase().replace(/\\s+/g, '-');`,
95
+ `lnk.href = href;`,
96
+ `lnk.id = id;`,
95
97
  `document.head.appendChild(lnk);`,
98
+ `}`,
96
99
  `}`
97
100
  ].join(" ")
98
101
  }]
@@ -79,7 +79,7 @@ export interface ApiAuthConfig {
79
79
  clearSession?: boolean;
80
80
  };
81
81
  }
82
- export interface ApiToast extends Toast {
82
+ export interface ApiToast extends Partial<Toast> {
83
83
  /**
84
84
  * 是否显示提示
85
85
  * @defaultValue true
@@ -1,4 +1,4 @@
1
- import type { Toast } from '@nuxt/ui/composables';
1
+ import type { ApiToast } from './config';
2
2
  declare module 'ofetch' {
3
3
  interface FetchOptions {
4
4
  context?: ApiFetchContext;
@@ -27,10 +27,10 @@ export interface ApiFetchContext {
27
27
  * @description 用于单个请求的 Toast 配置,可覆盖全局配置
28
28
  */
29
29
  export interface RequestToastOptions {
30
- /** 成功提示配置,设置为 false 禁用成功提示 */
31
- success?: Partial<Toast> | false;
32
- /** 错误提示配置,设置为 false 禁用错误提示 */
33
- error?: Partial<Toast> | false;
30
+ /** 成功提示配置,设置为 false 禁用成功提示;`show: true` 可覆盖全局关闭 */
31
+ success?: ApiToast | false;
32
+ /** 错误提示配置,设置为 false 禁用错误提示;`show: true` 可覆盖全局关闭 */
33
+ error?: ApiToast | false;
34
34
  /** 自定义成功消息 */
35
35
  successMessage?: string;
36
36
  /** 自定义错误消息 */
@@ -1,4 +1,5 @@
1
1
  import type { z } from 'zod';
2
+ import type { VNodeProps } from 'vue';
2
3
  import type { CalendarDate, Time } from '@internationalized/date';
3
4
  import type { ComponentProps, ComponentSlots, IsAny, IsComponent, KnownKeys, OmitByKey, Prettify, ReactiveValue, UnionToIntersection, WidenLiteral } from '@movk/core';
4
5
  import type { ValueFormat } from '../../composables/useDateFormatter';
@@ -20,16 +21,29 @@ type _HasLayoutMarker<S> = {
20
21
  }[keyof S] extends never ? false : true;
21
22
  type ExtractLayoutShape<S extends Record<string, any>> = _HasLayoutMarker<S> extends true ? LayoutRestShape<S> & LayoutFieldShape<S> : S;
22
23
  type StrictComponentProps<C extends IsComponent> = {
23
- [K in keyof ComponentProps<C> as {} extends Record<K, unknown> ? never : K]: ComponentProps<C>[K];
24
+ [K in keyof ComponentProps<C> as K extends keyof VNodeProps ? never : {} extends Record<K, unknown> ? never : K]: ComponentProps<C>[K];
25
+ };
26
+ /** 控件事件监听通道;回调由 enhanceEventProps 追加字段上下文作为末位参数 */
27
+ type ControlEventProps = {
28
+ [K in `on${string}`]?: (...args: any[]) => void;
24
29
  };
25
30
  type StrictComponentSlots<C extends IsComponent> = IsAny<ComponentSlots<C>> extends true ? {} : ComponentSlots<C>;
26
31
  type ControlKey<TControls extends AutoFormControls> = Extract<KnownKeys<TControls>, string>;
27
32
  type ControlEntryByKey<TControls extends AutoFormControls, K extends string> = K extends keyof TControls ? TControls[K] : never;
33
+ type _IsUnion<T, U = T> = T extends U ? ([U] extends [T] ? false : true) : never;
34
+ /**
35
+ * 单一字面量放宽、多成员联合保留。
36
+ *
37
+ * Nuxt UI 的 props 泛型默认值偏窄(`M extends boolean = false`、`VK = 'value'`),
38
+ * 不放宽会让 `multiple: true` 之类的合法取值报错;而 `size` / `color` / `orientation`
39
+ * 这类真实字面量联合必须原样保留,否则失去补全。
40
+ */
41
+ type _WidenNarrow<T> = IsAny<T> extends true ? T : [NonNullable<T>] extends [never] ? unknown : _IsUnion<NonNullable<T>> extends true ? T : WidenLiteral<T>;
28
42
  type _WidenForFactory<T> = {
29
- [K in keyof T]+?: WidenLiteral<T[K]>;
43
+ [K in keyof T]+?: _WidenNarrow<T[K]>;
30
44
  };
31
45
  type _IsUnsetLike<P> = [P] extends [_Unset] ? true : IsAny<P> extends true ? true : [unknown] extends [P] ? true : [keyof P] extends [never] ? true : false;
32
- type ResolveControlProps<C extends IsComponent, P> = _IsUnsetLike<P> extends true ? StrictComponentProps<C> : Prettify<_WidenForFactory<P> & {}>;
46
+ type ResolveControlProps<C extends IsComponent, P> = _IsUnsetLike<P> extends true ? StrictComponentProps<C> : Prettify<_WidenForFactory<P> & {}> & ControlEventProps;
33
47
  type ExtractControlProps<T> = T extends AutoFormControl<infer C, infer P, any> ? ResolveControlProps<C, P> : T extends {
34
48
  component: infer C extends IsComponent;
35
49
  } ? StrictComponentProps<C> : {};
@@ -1,10 +1,13 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import { useFormField } from '@nuxt/ui/composables/useFormField';
3
+ import { useFieldGroup } from '@nuxt/ui/composables/useFieldGroup';
1
4
  export declare function omitProps<T extends object, K extends keyof T>(props: T, keys: readonly K[]): Omit<T, K>;
2
- export declare function useForwardedProps<T extends object, K extends keyof T>(props: T, keys: readonly K[]): import("vue").ComputedRef<Omit<T, K>>;
5
+ export declare function useForwardedProps<T extends object, K extends keyof T>(props: T, keys: readonly K[]): ComputedRef<Omit<T, K>>;
3
6
  type SizeProps = {
4
7
  size?: unknown;
5
8
  };
6
9
  export declare function useFormFieldBridge<S = unknown, T extends SizeProps = SizeProps>(props?: T): {
7
- size: import("vue").ComputedRef<S | undefined>;
10
+ size: ComputedRef<S | undefined>;
8
11
  emitFormInput: () => void;
9
12
  emitFormBlur: () => void;
10
13
  emitFormChange: () => void;
@@ -15,19 +18,14 @@ type FieldControlProps = {
15
18
  color?: unknown;
16
19
  disabled?: boolean;
17
20
  };
18
- export declare function useFieldControl<T extends FieldControlProps>(props: T): {
19
- size: import("vue").ComputedRef<NonNullable<T["size"]> | undefined>;
20
- disabled: import("vue").ComputedRef<boolean>;
21
- color: import("vue").ComputedRef<"error" | NonNullable<T["color"]> | undefined>;
22
- fieldGroupSize: import("vue").ComputedRef<"xs" | "sm" | "md" | "lg" | "xl" | NonNullable<import("@nuxt/ui").GetObjectField<T, "size">> | undefined>;
23
- fieldGroupOrientation: import("vue").ComputedRef<"horizontal" | "vertical" | undefined>;
24
- id: import("vue").ComputedRef<string | undefined>;
25
- name: import("vue").ComputedRef<string | undefined>;
26
- highlight: import("vue").ComputedRef<boolean | undefined>;
27
- emitFormBlur: () => void;
28
- emitFormInput: import("@vueuse/core").UseDebounceFnReturn<() => void>;
29
- emitFormChange: () => void;
30
- emitFormFocus: () => void;
31
- ariaAttrs: import("vue").ComputedRef<Record<string, any> | undefined>;
21
+ type FieldSize<T extends FieldControlProps> = NonNullable<T['size']> | undefined;
22
+ type FieldColor<T extends FieldControlProps> = NonNullable<T['color']> | 'error' | undefined;
23
+ type FieldControl<T extends FieldControlProps> = Omit<ReturnType<typeof useFormField<T>>, 'size' | 'color' | 'disabled'> & {
24
+ size: ComputedRef<FieldSize<T>>;
25
+ disabled: ComputedRef<boolean>;
26
+ color: ComputedRef<FieldColor<T>>;
27
+ fieldGroupSize: ReturnType<typeof useFieldGroup<T>>['size'];
28
+ fieldGroupOrientation: ReturnType<typeof useFieldGroup<T>>['orientation'];
32
29
  };
30
+ export declare function useFieldControl<T extends FieldControlProps>(props: T): FieldControl<T>;
33
31
  export {};
@@ -6,7 +6,7 @@ import type { ModuleOptions } from '../../module';
6
6
  */
7
7
  export declare function getDefaultConfig(theme?: ModuleOptions['theme']): {
8
8
  dir: Direction;
9
- radius: number;
9
+ radius: number | undefined;
10
10
  blackAsPrimary: boolean;
11
11
  font: string;
12
12
  icons: string;
@@ -13,9 +13,11 @@ export function getDefaultConfig(theme) {
13
13
  const pickerNeutralColors = theme?.neutralColors ?? ["slate", "gray", "zinc", "neutral", "stone", "taupe", "mauve", "mist", "olive"];
14
14
  return {
15
15
  dir: "ltr",
16
- radius: 0.25,
16
+ // 缺省不指定圆角:运行时不注入 --ui-radius,沿用 @nuxt/ui 默认值或项目 CSS
17
+ radius: theme?.radius,
17
18
  blackAsPrimary: false,
18
- font: "Alibaba PuHuiTi",
19
+ // 缺省不指定字体:运行时不注入 --font-sans,交由项目 CSS 的 @theme 决定
20
+ font: theme?.font ?? "",
19
21
  icons: "lucide",
20
22
  prefix: theme?.prefix,
21
23
  tv: {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
3
  "type": "module",
4
- "version": "1.5.1",
5
- "packageManager": "pnpm@11.17.0",
4
+ "version": "1.6.0",
5
+ "packageManager": "pnpm@11.18.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",
@@ -126,14 +126,14 @@
126
126
  "dependencies": {
127
127
  "@iconify-json/lucide": "^1.2.120",
128
128
  "@iconify-json/ph": "^1.2.2",
129
- "@iconify-json/tabler": "^1.2.37",
129
+ "@iconify-json/tabler": "^1.2.38",
130
130
  "@internationalized/date": "^3.12.2",
131
131
  "@movk/core": "^1.4.1",
132
- "@nuxt/image": "^2.0.0",
132
+ "@nuxt/image": "^2.1.0",
133
133
  "@nuxt/ui": "^4.10.0",
134
134
  "@tanstack/vue-table": "^8.21.3",
135
- "@vueuse/core": "^14.3.0",
136
- "@vueuse/nuxt": "^14.3.0",
135
+ "@vueuse/core": "^14.4.0",
136
+ "@vueuse/nuxt": "^14.4.0",
137
137
  "colortranslator": "^6.1.1",
138
138
  "defu": "^6.1.7",
139
139
  "magic-string": "^1.1.0",
@@ -144,7 +144,7 @@
144
144
  "pathe": "^2.0.3",
145
145
  "reka-ui": "2.10.1",
146
146
  "scule": "^1.3.0",
147
- "tailwind-variants": "^3.2.2",
147
+ "tailwind-variants": "^3.3.0",
148
148
  "tailwindcss": "^4.3.3",
149
149
  "tinyglobby": "^0.2.17",
150
150
  "unifont": "^0.7.4",