@h-ai/ui 1.0.0-beta.2 → 1.0.0-beta.20

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 (139) hide show
  1. package/README.en.md +228 -70
  2. package/README.ja.md +227 -69
  3. package/README.md +229 -72
  4. package/auto-import.d.ts +4 -0
  5. package/auto-import.js +241 -65
  6. package/dist/components/compounds/Accordion.svelte +6 -2
  7. package/dist/components/compounds/BottomNav.svelte +14 -2
  8. package/dist/components/compounds/Card.svelte +3 -1
  9. package/dist/components/compounds/Combobox.svelte +41 -5
  10. package/dist/components/compounds/DataTable.svelte +28 -8
  11. package/dist/components/compounds/DatePicker.svelte +6 -1
  12. package/dist/components/compounds/Drawer.svelte +12 -4
  13. package/dist/components/compounds/Dropdown.svelte +135 -59
  14. package/dist/components/compounds/Empty.svelte +10 -2
  15. package/dist/components/compounds/FormField.svelte +10 -2
  16. package/dist/components/compounds/JsonViewer.svelte +18 -6
  17. package/dist/components/compounds/Modal.svelte +8 -2
  18. package/dist/components/compounds/Pagination.svelte +22 -7
  19. package/dist/components/compounds/Popover.svelte +93 -12
  20. package/dist/components/compounds/Steps.svelte +24 -8
  21. package/dist/components/compounds/SwipeCell.svelte +3 -1
  22. package/dist/components/compounds/TableToolbar.svelte +32 -9
  23. package/dist/components/compounds/Tabs.svelte +25 -5
  24. package/dist/components/compounds/TagInput.svelte +2 -0
  25. package/dist/components/compounds/Timeline.svelte +6 -2
  26. package/dist/components/compounds/ToastContainer.svelte +41 -10
  27. package/dist/components/compounds/Tooltip.svelte +1 -1
  28. package/dist/components/compounds/Tooltip.svelte.d.ts +1 -1
  29. package/dist/components/control-size.js +48 -8
  30. package/dist/components/primitives/Avatar.svelte +9 -3
  31. package/dist/components/primitives/BareInput.svelte +3 -1
  32. package/dist/components/primitives/Button.svelte +6 -2
  33. package/dist/components/primitives/Checkbox.svelte +5 -0
  34. package/dist/components/primitives/IconButton.svelte +3 -1
  35. package/dist/components/primitives/Input.svelte +19 -3
  36. package/dist/components/primitives/Radio.svelte +4 -1
  37. package/dist/components/primitives/Range.svelte +3 -1
  38. package/dist/components/primitives/Rating.svelte +9 -3
  39. package/dist/components/primitives/Select.svelte +21 -5
  40. package/dist/components/primitives/Tag.svelte +6 -10
  41. package/dist/components/primitives/Textarea.svelte +14 -2
  42. package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
  43. package/dist/components/scenes/ai/document-download.js +6 -2
  44. package/dist/components/scenes/ai/document-parse.js +24 -8
  45. package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
  46. package/dist/components/scenes/ai/highlight.js +18 -1
  47. package/dist/components/scenes/ai/markdown-parse.js +81 -28
  48. package/dist/components/scenes/ai/mermaid-render.js +13 -1
  49. package/dist/components/scenes/ai/safe-html.js +9 -3
  50. package/dist/components/scenes/ai/table/AiTableEditor.svelte +27 -9
  51. package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
  52. package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
  53. package/dist/components/scenes/app/FeedbackList.svelte +138 -21
  54. package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
  55. package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
  56. package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
  57. package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
  58. package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
  59. package/dist/components/scenes/app/ThemeSelector.svelte +29 -5
  60. package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
  61. package/dist/components/scenes/app/WorkspaceLayout.svelte +1 -1
  62. package/dist/components/scenes/app/feedback-functions.js +6 -2
  63. package/dist/components/scenes/charts/Chart.svelte +55 -21
  64. package/dist/components/scenes/charts/Chart.svelte.d.ts +0 -1
  65. package/dist/components/scenes/charts/ChartLoadError.svelte +13 -0
  66. package/dist/components/scenes/charts/ChartLoadError.svelte.d.ts +6 -0
  67. package/dist/components/scenes/charts/DashboardGrid.svelte +34 -0
  68. package/dist/components/scenes/charts/DashboardGrid.svelte.d.ts +15 -0
  69. package/dist/components/scenes/charts/MetricCard.svelte +69 -0
  70. package/dist/components/scenes/charts/MetricCard.svelte.d.ts +15 -0
  71. package/dist/components/scenes/charts/ReportCard.svelte +48 -0
  72. package/dist/components/scenes/charts/ReportCard.svelte.d.ts +15 -0
  73. package/dist/components/scenes/charts/chart-presets.d.ts +15 -0
  74. package/dist/components/scenes/charts/chart-presets.js +56 -0
  75. package/dist/components/scenes/charts/chart-types.d.ts +13 -2
  76. package/dist/components/scenes/charts/dashboard-types.d.ts +79 -0
  77. package/dist/components/scenes/charts/dashboard-types.js +1 -0
  78. package/dist/components/scenes/charts/index.d.ts +6 -2
  79. package/dist/components/scenes/charts/index.js +4 -1
  80. package/dist/components/scenes/charts/renderers/AreaChart.svelte +1 -0
  81. package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +1 -0
  82. package/dist/components/scenes/charts/renderers/BarChart.svelte +1 -0
  83. package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +1 -0
  84. package/dist/components/scenes/charts/renderers/LineChart.svelte +39 -12
  85. package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +1 -0
  86. package/dist/components/scenes/charts/renderers/PieChart.svelte +1 -0
  87. package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +1 -0
  88. package/dist/components/scenes/charts/renderers/ScatterChart.svelte +1 -0
  89. package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +1 -0
  90. package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
  91. package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
  92. package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
  93. package/dist/components/scenes/crud/CrudPage.svelte +34 -9
  94. package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
  95. package/dist/components/scenes/crud/crud-form-validation.js +27 -9
  96. package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
  97. package/dist/components/scenes/error/error-presets.js +30 -5
  98. package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
  99. package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
  100. package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
  101. package/dist/components/scenes/iam/AuthPanel.svelte +74 -16
  102. package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
  103. package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
  104. package/dist/components/scenes/iam/LoginForm.svelte +32 -8
  105. package/dist/components/scenes/iam/PasswordInput.svelte +50 -12
  106. package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
  107. package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
  108. package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
  109. package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
  110. package/dist/components/scenes/iam/UserProfile.svelte +41 -14
  111. package/dist/components/scenes/iam/auth-captcha.js +9 -2
  112. package/dist/components/scenes/iam/auth-error-message.d.ts +2 -2
  113. package/dist/components/scenes/iam/auth-error-message.js +16 -3
  114. package/dist/components/scenes/iam/password-utils.js +9 -2
  115. package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
  116. package/dist/components/scenes/storage/FileList.svelte +3 -1
  117. package/dist/components/scenes/storage/FileUpload.svelte +7 -2
  118. package/dist/components/scenes/types.d.ts +2 -2
  119. package/dist/guide-storage.js +12 -4
  120. package/dist/guide.svelte.js +59 -16
  121. package/dist/i18n.svelte.js +9 -3
  122. package/dist/internal/dialog-focus.d.ts +19 -0
  123. package/dist/internal/dialog-focus.js +104 -4
  124. package/dist/internal/form-validation.svelte.js +46 -15
  125. package/dist/internal/icon-safety.js +6 -2
  126. package/dist/message.svelte.js +6 -2
  127. package/dist/messagebox.svelte.js +6 -2
  128. package/dist/messages/en-US.json +7 -1
  129. package/dist/messages/ja-JP.json +7 -1
  130. package/dist/messages/zh-CN.json +7 -1
  131. package/dist/styles/eye-care.css +55 -0
  132. package/dist/styles/global.css +16 -0
  133. package/dist/styles/theme.css +1 -0
  134. package/dist/theme-config.d.ts +1 -1
  135. package/dist/theme-config.js +136 -21
  136. package/dist/toast.svelte.js +14 -3
  137. package/dist/types.d.ts +3 -3
  138. package/dist/utils.js +6 -2
  139. package/package.json +19 -19
@@ -0,0 +1,15 @@
1
+ /** @h-ai/ui — 常用图表预设,仅定义默认值,调用方原生配置优先。 @module chart-presets */
2
+ import type { ChartPreset, ChartType } from './chart-types.js';
3
+ /**
4
+ * 解析预设,不读取或转换业务数据。
5
+ * @param preset - 可选预设名称。
6
+ * @returns 图形类型及可被调用方覆盖的默认属性。
7
+ * @example 模块内部上下文
8
+ * ```ts
9
+ * const preset = resolveChartPreset('donut')
10
+ * ```
11
+ */
12
+ export declare function resolveChartPreset(preset?: ChartPreset): {
13
+ type?: ChartType;
14
+ props: Record<string, unknown>;
15
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 解析预设,不读取或转换业务数据。
3
+ * @param preset - 可选预设名称。
4
+ * @returns 图形类型及可被调用方覆盖的默认属性。
5
+ * @example 模块内部上下文
6
+ * ```ts
7
+ * const preset = resolveChartPreset('donut')
8
+ * ```
9
+ */
10
+ export function resolveChartPreset(preset) {
11
+ switch (preset) {
12
+ case 'grouped-bar': return {
13
+ type: 'bar',
14
+ props: {
15
+ seriesLayout: 'group',
16
+ axis: true,
17
+ grid: true,
18
+ legend: true,
19
+ },
20
+ };
21
+ case 'stacked-bar': return {
22
+ type: 'bar',
23
+ props: {
24
+ seriesLayout: 'stack',
25
+ axis: true,
26
+ grid: true,
27
+ legend: true,
28
+ },
29
+ };
30
+ case 'stacked-area': return {
31
+ type: 'area',
32
+ props: {
33
+ seriesLayout: 'stack',
34
+ axis: true,
35
+ grid: true,
36
+ legend: true,
37
+ },
38
+ };
39
+ case 'donut': return {
40
+ type: 'pie',
41
+ props: { innerRadius: 0.65, legend: true },
42
+ };
43
+ case 'sparkline': return {
44
+ type: 'line',
45
+ props: {
46
+ axis: false,
47
+ grid: false,
48
+ legend: false,
49
+ points: false,
50
+ padding: { top: 4, right: 0, bottom: 4, left: 0 },
51
+ height: 64,
52
+ },
53
+ };
54
+ default: return { props: {} };
55
+ }
56
+ }
@@ -43,6 +43,15 @@ export type ChartAccessor = string | number | ((item: ChartDataItem) => unknown)
43
43
  * ```
44
44
  */
45
45
  export type ChartType = 'bar' | 'line' | 'area' | 'pie' | 'scatter';
46
+ /**
47
+ * 常用图形的可覆盖默认配置;无需同时传 type。
48
+ * @example
49
+ * ```ts
50
+ * import type { ChartPreset } from '@h-ai/ui'
51
+ * const preset: ChartPreset = 'donut'
52
+ * ```
53
+ */
54
+ export type ChartPreset = 'grouped-bar' | 'stacked-bar' | 'stacked-area' | 'donut' | 'sparkline';
46
55
  /**
47
56
  * Chart 预设高度档位;具体像素值在 Chart.svelte 中固定映射。
48
57
  *
@@ -116,8 +125,10 @@ export interface ChartSeries {
116
125
  * ```
117
126
  */
118
127
  export interface ChartProps extends DataAttributes {
119
- /** 选择内部 LayerChart 高阶组件;必填。 */
120
- type: ChartType;
128
+ /** 选择内部 LayerChart 高阶组件;优先于 preset 的图形类型,未指定时默认 line。 */
129
+ type?: ChartType;
130
+ /** 常用图表预设;原生属性覆盖预设默认值。 */
131
+ preset?: ChartPreset;
121
132
  /** 图表数据源;空数组会触发内置空态。 */
122
133
  data: ChartDataItem[];
123
134
  /** x 轴字段名;饼图中默认映射为 key 和 label。 */
@@ -0,0 +1,79 @@
1
+ /** @h-ai/ui — 轻量看板组件契约。 @module dashboard-types */
2
+ import type { Snippet } from 'svelte';
3
+ import type { DataAttributes } from '../../../types.js';
4
+ /**
5
+ * 指标卡展示数据;百分比变化由业务计算,正负方向与业务好坏分别表达。
6
+ * @example
7
+ * ```ts
8
+ * import type { MetricCardProps } from '@h-ai/ui'
9
+ * const metric: MetricCardProps = { title: 'Revenue', value: '128,430', unit: 'CNY', trend: 12.8, trendLabel: 'vs previous month', trendTone: 'success' }
10
+ * ```
11
+ */
12
+ export interface MetricCardProps extends DataAttributes {
13
+ /** 指标名称,由应用提供翻译。 */
14
+ title: string;
15
+ /** 已格式化文本或数值;缺失和非有限数显示占位符,零值正常显示。 */
16
+ value?: string | number | null;
17
+ /** 单位文本。 */
18
+ unit?: string;
19
+ /** 变化百分数,例如 12.8 表示 +12.8%,不是 0.128。 */
20
+ trend?: number;
21
+ /** 比较基准,例如“较上月”。 */
22
+ trendLabel?: string;
23
+ /** 业务语义色;默认 neutral,下降也可以是 success。 */
24
+ trendTone?: 'success' | 'warning' | 'error' | 'neutral';
25
+ /** 辅助说明。 */
26
+ description?: string;
27
+ /** 加载时隐藏旧数值及趋势内容。 */
28
+ loading?: boolean;
29
+ /** 可选趋势图或其他补充内容;未提供时不加载图形引擎。 */
30
+ children?: Snippet;
31
+ /** 外层样式。 */
32
+ class?: string;
33
+ }
34
+ /**
35
+ * 报表卡片负责布局和状态,children 可放统一 Chart 或任意 LayerChart 原生组件。
36
+ * @example
37
+ * ```ts
38
+ * import type { ReportCardProps } from '@h-ai/ui'
39
+ * const report: ReportCardProps = { title: 'Revenue trend', description: 'Monthly totals', loading: false }
40
+ * ```
41
+ */
42
+ export interface ReportCardProps extends DataAttributes {
43
+ /** 卡片标题。 */
44
+ title: string;
45
+ /** 标题下的说明。 */
46
+ description?: string;
47
+ /** 标题旁的操作区域。 */
48
+ actions?: Snippet;
49
+ /** 报表或原生图形内容。 */
50
+ children?: Snippet;
51
+ /** 可选页脚。 */
52
+ footer?: Snippet;
53
+ /** 加载状态;保留卡片高度,不挂载图形。 */
54
+ loading?: boolean;
55
+ /** 空态;不挂载图形。 */
56
+ empty?: boolean;
57
+ /** 状态区域的最小高度,默认 240 像素。 */
58
+ minHeight?: number;
59
+ /** 外层样式。 */
60
+ class?: string;
61
+ }
62
+ /**
63
+ * 看板的响应式网格,按容器宽度收拢,children 保持 DOM 阅读顺序。
64
+ * @example
65
+ * ```ts
66
+ * import type { DashboardGridProps } from '@h-ai/ui'
67
+ * const grid: DashboardGridProps = { label: 'Key metrics', columns: 4 }
68
+ * ```
69
+ */
70
+ export interface DashboardGridProps extends DataAttributes {
71
+ /** 网格的无障碍名称。 */
72
+ label: string;
73
+ /** 宽容器列数;窄容器一列,中等容器最多两列。 */
74
+ columns?: 1 | 2 | 3 | 4;
75
+ /** 指标卡或报表卡。 */
76
+ children?: Snippet;
77
+ /** 外层样式。 */
78
+ class?: string;
79
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * @h-ai/ui — 图表场景组件
3
3
  *
4
- * 仅导出统一 Chart 入口和公共类型;内部 renderer 不对外暴露。
4
+ * 导出统一 Chart、轻量看板组件和公共类型;内部 renderer 不对外暴露。
5
5
  * @module index
6
6
  */
7
- export type { ChartDataItem, ChartLineVariant, ChartProps, ChartSeries, ChartSize, ChartTooltipMode, ChartType } from './chart-types.js';
7
+ export type { ChartDataItem, ChartLineVariant, ChartPreset, ChartProps, ChartSeries, ChartSize, ChartTooltipMode, ChartType } from './chart-types.js';
8
8
  export { default as Chart } from './Chart.svelte';
9
+ export type { DashboardGridProps, MetricCardProps, ReportCardProps } from './dashboard-types.js';
10
+ export { default as DashboardGrid } from './DashboardGrid.svelte';
11
+ export { default as MetricCard } from './MetricCard.svelte';
12
+ export { default as ReportCard } from './ReportCard.svelte';
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * @h-ai/ui — 图表场景组件
3
3
  *
4
- * 仅导出统一 Chart 入口和公共类型;内部 renderer 不对外暴露。
4
+ * 导出统一 Chart、轻量看板组件和公共类型;内部 renderer 不对外暴露。
5
5
  * @module index
6
6
  */
7
7
  export { default as Chart } from './Chart.svelte';
8
+ export { default as DashboardGrid } from './DashboardGrid.svelte';
9
+ export { default as MetricCard } from './MetricCard.svelte';
10
+ export { default as ReportCard } from './ReportCard.svelte';
@@ -10,6 +10,7 @@
10
10
  import type { AreaChartProps } from 'layerchart'
11
11
  import type { ChartDataItem } from '../chart-types.js'
12
12
  import { AreaChart as LayerAreaChart } from 'layerchart'
13
+ import 'layerchart/daisyui-5.css'
13
14
 
14
15
  /** 透传给 LayerChart AreaChart 的全部原生属性。 */
15
16
  const { ...props }: AreaChartProps<ChartDataItem> = $props()
@@ -1,5 +1,6 @@
1
1
  import type { AreaChartProps } from 'layerchart';
2
2
  import type { ChartDataItem } from '../chart-types.js';
3
+ import 'layerchart/daisyui-5.css';
3
4
  declare const AreaChart: import("svelte").Component<AreaChartProps<ChartDataItem>, {}, "">;
4
5
  type AreaChart = ReturnType<typeof AreaChart>;
5
6
  export default AreaChart;
@@ -10,6 +10,7 @@
10
10
  import type { BarChartProps } from 'layerchart'
11
11
  import type { ChartDataItem } from '../chart-types.js'
12
12
  import { BarChart as LayerBarChart } from 'layerchart'
13
+ import 'layerchart/daisyui-5.css'
13
14
 
14
15
  /** 透传给 LayerChart BarChart 的全部原生属性。 */
15
16
  const { ...props }: BarChartProps<ChartDataItem> = $props()
@@ -1,5 +1,6 @@
1
1
  import type { BarChartProps } from 'layerchart';
2
2
  import type { ChartDataItem } from '../chart-types.js';
3
+ import 'layerchart/daisyui-5.css';
3
4
  declare const BarChart: import("svelte").Component<BarChartProps<ChartDataItem>, {}, "">;
4
5
  type BarChart = ReturnType<typeof BarChart>;
5
6
  export default BarChart;
@@ -16,6 +16,7 @@
16
16
  ChartTooltipMode,
17
17
  } from '../chart-types.js'
18
18
  import { LineChart as LayerLineChart } from 'layerchart'
19
+ import 'layerchart/daisyui-5.css'
19
20
 
20
21
  /**
21
22
  * 分段折线图单个数据点,保留展示标签与数值。
@@ -215,9 +216,13 @@
215
216
  * @returns 有限数字,无法转换时返回 0
216
217
  */
217
218
  function toFiniteNumber(value: unknown): number {
218
- const numberValue = typeof value === 'number' ? value : Number(value)
219
+ const numberValue = typeof value === 'number'
220
+ ? value
221
+ : Number(value)
219
222
 
220
- return Number.isFinite(numberValue) ? numberValue : 0
223
+ return Number.isFinite(numberValue)
224
+ ? numberValue
225
+ : 0
221
226
  }
222
227
 
223
228
  /**
@@ -247,7 +252,15 @@
247
252
  * @returns CSS 颜色值或变量
248
253
  */
249
254
  function getSeriesColor(item: ChartSeries, index: number): string {
250
- return item.color ?? `var(--color-${['primary', 'secondary', 'accent', 'success', 'warning', 'error', 'info'][index % 7]})`
255
+ return item.color ?? `var(--color-${[
256
+ 'primary',
257
+ 'secondary',
258
+ 'accent',
259
+ 'success',
260
+ 'warning',
261
+ 'error',
262
+ 'info',
263
+ ][index % 7]})`
251
264
  }
252
265
 
253
266
  /**
@@ -274,17 +287,27 @@
274
287
 
275
288
  if (Array.isArray(yAccessor)) {
276
289
  return yAccessor.map((accessor, index) => ({
277
- key: typeof accessor === 'string' ? accessor : `series-${index}`,
278
- label: typeof accessor === 'string' ? accessor : `series-${index + 1}`,
290
+ key: typeof accessor === 'string'
291
+ ? accessor
292
+ : `series-${index}`,
293
+ label: typeof accessor === 'string'
294
+ ? accessor
295
+ : `series-${index + 1}`,
279
296
  value: accessor,
280
297
  }))
281
298
  }
282
299
 
283
- return [{
284
- key: typeof yAccessor === 'string' ? yAccessor : 'value',
285
- label: typeof yAccessor === 'string' ? yAccessor : 'value',
286
- value: yAccessor,
287
- }]
300
+ return [
301
+ {
302
+ key: typeof yAccessor === 'string'
303
+ ? yAccessor
304
+ : 'value',
305
+ label: typeof yAccessor === 'string'
306
+ ? yAccessor
307
+ : 'value',
308
+ value: yAccessor,
309
+ },
310
+ ]
288
311
  }
289
312
 
290
313
  /**
@@ -322,7 +345,9 @@
322
345
  function getSegmentedLineMax(items: SegmentedLineSeries[]): number {
323
346
  const maxValue = Math.max(...items.flatMap(item => item.points.map(point => point.value)))
324
347
 
325
- return maxValue > 0 ? maxValue : 1
348
+ return maxValue > 0
349
+ ? maxValue
350
+ : 1
326
351
  }
327
352
 
328
353
  /**
@@ -405,7 +430,9 @@
405
430
  const currentDistance = Math.abs(point.x - pointerX)
406
431
  const bestDistance = Math.abs((primaryCoordinates[bestIndex]?.x ?? point.x) - pointerX)
407
432
 
408
- return currentDistance < bestDistance ? index : bestIndex
433
+ return currentDistance < bestDistance
434
+ ? index
435
+ : bestIndex
409
436
  }, 0)
410
437
  const nearestPoint = primaryCoordinates[nearestIndex]
411
438
  if (nearestPoint)
@@ -1,5 +1,6 @@
1
1
  import type { LineChartProps } from 'layerchart';
2
2
  import type { ChartDataItem, ChartLineVariant, ChartTooltipMode } from '../chart-types.js';
3
+ import 'layerchart/daisyui-5.css';
3
4
  /**
4
5
  * LineChart 组件的属性契约;通过公开组件配置使用。
5
6
  *
@@ -10,6 +10,7 @@
10
10
  import type { PieChartProps } from 'layerchart'
11
11
  import type { ChartDataItem } from '../chart-types.js'
12
12
  import { PieChart as LayerPieChart } from 'layerchart'
13
+ import 'layerchart/daisyui-5.css'
13
14
 
14
15
  /** 透传给 LayerChart PieChart 的全部原生属性。 */
15
16
  const { ...props }: PieChartProps<ChartDataItem> = $props()
@@ -1,5 +1,6 @@
1
1
  import type { PieChartProps } from 'layerchart';
2
2
  import type { ChartDataItem } from '../chart-types.js';
3
+ import 'layerchart/daisyui-5.css';
3
4
  declare const PieChart: import("svelte").Component<PieChartProps<ChartDataItem>, {}, "">;
4
5
  type PieChart = ReturnType<typeof PieChart>;
5
6
  export default PieChart;
@@ -10,6 +10,7 @@
10
10
  import type { ScatterChartProps } from 'layerchart'
11
11
  import type { ChartDataItem } from '../chart-types.js'
12
12
  import { ScatterChart as LayerScatterChart } from 'layerchart'
13
+ import 'layerchart/daisyui-5.css'
13
14
 
14
15
  /** 透传给 LayerChart ScatterChart 的全部原生属性。 */
15
16
  const { ...props }: ScatterChartProps<ChartDataItem> = $props()
@@ -1,5 +1,6 @@
1
1
  import type { ScatterChartProps } from 'layerchart';
2
2
  import type { ChartDataItem } from '../chart-types.js';
3
+ import 'layerchart/daisyui-5.css';
3
4
  declare const ScatterChart: import("svelte").Component<ScatterChartProps<ChartDataItem>, {}, "">;
4
5
  type ScatterChart = ReturnType<typeof ScatterChart>;
5
6
  export default ScatterChart;
@@ -71,13 +71,17 @@
71
71
 
72
72
  const dataAttributes = $derived(getDataAttributes(restProps))
73
73
  function resolveText(text: string | (() => string)): string {
74
- return typeof text === 'function' ? text() : text
74
+ return typeof text === 'function'
75
+ ? text()
76
+ : text
75
77
  }
76
78
 
77
79
  function resolveOptions(options?: FieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
78
80
  if (!options)
79
81
  return []
80
- return typeof options === 'function' ? options() : options
82
+ return typeof options === 'function'
83
+ ? options()
84
+ : options
81
85
  }
82
86
 
83
87
  function formatValue(field: FieldDef, value: unknown): string {
@@ -87,13 +87,17 @@
87
87
 
88
88
  const dataAttributes = $derived(getDataAttributes(restProps))
89
89
  function resolveText(text: string | (() => string)): string {
90
- return typeof text === 'function' ? text() : text
90
+ return typeof text === 'function'
91
+ ? text()
92
+ : text
91
93
  }
92
94
 
93
95
  function resolveOptions(options?: FieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
94
96
  if (!options)
95
97
  return []
96
- return typeof options === 'function' ? options() : options
98
+ return typeof options === 'function'
99
+ ? options()
100
+ : options
97
101
  }
98
102
 
99
103
  function formatValue(field: FieldDef, value: unknown): string {
@@ -103,7 +103,9 @@
103
103
  function resolveOptions(options?: CrudFieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
104
104
  if (!options)
105
105
  return []
106
- return typeof options === 'function' ? options() : options
106
+ return typeof options === 'function'
107
+ ? options()
108
+ : options
107
109
  }
108
110
 
109
111
  const sortedFields = $derived(
@@ -115,8 +117,11 @@
115
117
  if ((!attempted && !touched[field.id]) || (mode === 'edit' && field.readonly))
116
118
  continue
117
119
  const issue = getCrudValidationIssue(field, formData[field.id])
118
- if (issue)
119
- errors[field.id] = field.validation?.message ? resolveText(field.validation.message) : uiM(issue.key, issue.params)
120
+ if (issue) {
121
+ errors[field.id] = field.validation?.message
122
+ ? resolveText(field.validation.message)
123
+ : uiM(issue.key, issue.params)
124
+ }
120
125
  }
121
126
  return errors
122
127
  })
@@ -204,14 +209,23 @@
204
209
  {@const isReadonly = field.readonly && mode === 'edit'}
205
210
  {@const isRequired = field.validation?.required}
206
211
  {@const fieldValue = formData[field.id]}
207
- {@const placeholder = field.placeholder ? resolveText(field.placeholder) : ''}
212
+ {@const placeholder = field.placeholder
213
+ ? resolveText(field.placeholder)
214
+ : ''}
208
215
  {@const controlId = `${panelId}-${field.id}`}
209
216
  <FormField
210
217
  for={controlId}
211
218
  label={resolveText(field.label)}
212
219
  required={isRequired}
213
220
  error={fieldErrors[field.id]}
214
- colSpan={field.colSpan ?? (['textarea', 'multi-select', 'date-range', 'custom'].includes(field.type) ? 2 : 'auto')}
221
+ colSpan={field.colSpan ?? ([
222
+ 'textarea',
223
+ 'multi-select',
224
+ 'date-range',
225
+ 'custom',
226
+ ].includes(field.type)
227
+ ? 2
228
+ : 'auto')}
215
229
  data-field={field.id}
216
230
  >
217
231
 
@@ -240,7 +254,10 @@
240
254
  disabled={submitting || isReadonly}
241
255
  options={[
242
256
  { value: '', label: placeholder || uiM('crud_filter_all') },
243
- ...opts.map(opt => ({ value: String(opt.value), label: opt.label })),
257
+ ...opts.map(opt => ({
258
+ value: String(opt.value),
259
+ label: opt.label,
260
+ })),
244
261
  ]}
245
262
  onchange={value => updateField(field.id, opts.find(opt => String(opt.value) === value)?.value ?? value)}
246
263
  />
@@ -285,11 +302,21 @@
285
302
  disabled={submitting || isReadonly}
286
303
  required={isRequired}
287
304
  pattern={field.validation?.pattern}
288
- minlength={field.type !== 'number' ? field.validation?.min : undefined}
289
- maxlength={field.type !== 'number' ? field.validation?.max : undefined}
290
- min={field.type === 'number' ? field.validation?.min : undefined}
291
- max={field.type === 'number' ? field.validation?.max : undefined}
292
- oninput={e => updateField(field.id, field.type === 'number' && e.currentTarget.value !== '' ? Number(e.currentTarget.value) : e.currentTarget.value)}
305
+ minlength={field.type !== 'number'
306
+ ? field.validation?.min
307
+ : undefined}
308
+ maxlength={field.type !== 'number'
309
+ ? field.validation?.max
310
+ : undefined}
311
+ min={field.type === 'number'
312
+ ? field.validation?.min
313
+ : undefined}
314
+ max={field.type === 'number'
315
+ ? field.validation?.max
316
+ : undefined}
317
+ oninput={e => updateField(field.id, field.type === 'number' && e.currentTarget.value !== ''
318
+ ? Number(e.currentTarget.value)
319
+ : e.currentTarget.value)}
293
320
  />
294
321
  {/if}
295
322
  </FormField>
@@ -311,7 +338,9 @@
311
338
  {#if submitting}
312
339
  <span class='loading loading-spinner loading-xs mr-2'></span>
313
340
  {/if}
314
- {mode === 'create' ? uiM('crud_create') : uiM('crud_save')}
341
+ {mode === 'create'
342
+ ? uiM('crud_create')
343
+ : uiM('crud_save')}
315
344
  </Button>
316
345
  {/snippet}
317
346
 
@@ -361,7 +361,9 @@
361
361
 
362
362
  /** 解析静态或延迟读取的显示文案。 */
363
363
  function resolveText(text: string | (() => string)): string {
364
- return typeof text === 'function' ? text() : text
364
+ return typeof text === 'function'
365
+ ? text()
366
+ : text
365
367
  }
366
368
 
367
369
  // 同步 data.filters → 本地过滤/排序状态;没有 filters 时也要清空旧状态。
@@ -369,7 +371,9 @@
369
371
  const filters = data.filters ?? {}
370
372
  searchValue = String(filters.search ?? '')
371
373
  sortBy = String(filters.sortBy ?? '')
372
- sortDirection = filters.sortDirection === 'asc' ? 'asc' : 'desc'
374
+ sortDirection = filters.sortDirection === 'asc'
375
+ ? 'asc'
376
+ : 'desc'
373
377
  const fv: Record<string, unknown> = {}
374
378
  for (const f of crud.getFilterFields()) {
375
379
  if (filters[f.id] !== undefined) {
@@ -405,9 +409,18 @@
405
409
  sortBy,
406
410
  sortDirection,
407
411
  ...Object.fromEntries(
408
- Object.entries(conditions).filter(([key]) => !['search', 'sortBy', 'sortDirection', 'page', 'pageSize'].includes(key))
412
+ Object.entries(conditions).filter(([key]) => ![
413
+ 'search',
414
+ 'sortBy',
415
+ 'sortDirection',
416
+ 'page',
417
+ 'pageSize',
418
+ ].includes(key))
409
419
  .filter(([, v]) => v !== undefined && v !== '')
410
- .map(([k, v]) => [k, String(v)]),
420
+ .map(([k, v]) => [
421
+ k,
422
+ String(v),
423
+ ]),
411
424
  ),
412
425
  ...overrides,
413
426
  }
@@ -423,7 +436,9 @@
423
436
  /** 序列化后的查询字符串。 */
424
437
  const qs = params.toString()
425
438
  /** 交给宿主路由的目标 URL。 */
426
- const url = `${currentBasePath}${qs ? `?${qs}` : ''}`
439
+ const url = `${currentBasePath}${qs
440
+ ? `?${qs}`
441
+ : ''}`
427
442
  void Promise.resolve(nav.navigate(url)).then(() => nav.refresh?.())
428
443
  }
429
444
 
@@ -469,7 +484,9 @@
469
484
  /** 打开新建面板并填充默认值。 */
470
485
  function openCreate() {
471
486
  selectedItem = null
472
- formData = { ...crud.getDefaultValues() }
487
+ formData = {
488
+ ...crud.getDefaultValues(),
489
+ }
473
490
  formError = ''
474
491
  panelMode = 'create'
475
492
  }
@@ -644,7 +661,11 @@
644
661
  : undefined,
645
662
  })),
646
663
  )
647
- useToastFeedback(() => error ? typeof error === 'string' ? error : uiM('crud_load_failed') : '')
664
+ useToastFeedback(() => error
665
+ ? typeof error === 'string'
666
+ ? error
667
+ : uiM('crud_load_failed')
668
+ : '')
648
669
  useToastFeedback(() => deleteError)
649
670
  </script>
650
671
 
@@ -845,8 +866,12 @@
845
866
  <!-- 编辑/新建:抽屉或弹窗 -->
846
867
  <CrudEditPanel
847
868
  open={editOpen}
848
- mode={panelMode === 'create' ? 'create' : 'edit'}
849
- fields={panelMode === 'create' ? createFields : editFields}
869
+ mode={panelMode === 'create'
870
+ ? 'create'
871
+ : 'edit'}
872
+ fields={panelMode === 'create'
873
+ ? createFields
874
+ : editFields}
850
875
  {density}
851
876
  bind:formData
852
877
  title={panelTitle}