@h-ai/ui 0.1.0-alpha.40 → 0.1.0-alpha.41

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.
@@ -1,17 +1,28 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { DataAttributes } from '../../../types.js';
3
- import type { CrudDensity, CrudFormConfig, CrudPaginationConfig } from './crud-types.js';
3
+ import type { CrudDensity, CrudFormConfig, CrudPaginationConfig, CrudToolbarStyle } from './crud-types.js';
4
4
  import type { NavAdapter } from './nav-adapter.js';
5
+ /** CRUD 字段定义,决定列表、筛选器和表单的字段行为。 */
5
6
  type FieldDef = {
7
+ /** 字段稳定标识,同时对应数据记录中的属性名。 */
6
8
  id: string;
9
+ /** 字段显示文案,允许通过函数延迟读取当前语言。 */
7
10
  label: string | (() => string);
11
+ /** 字段控件类型,最终由表单或筛选器解释。 */
8
12
  type: string;
13
+ /** 是否出现在列表中;未设置时默认显示。 */
9
14
  inList?: boolean;
15
+ /** 是否出现在筛选器中;只有显式为 true 时显示。 */
10
16
  filterable?: boolean;
17
+ /** 编辑时是否禁止修改。 */
11
18
  readonly?: boolean;
19
+ /** 是否出现在新建表单中;未设置时默认显示。 */
12
20
  inCreate?: boolean;
21
+ /** 是否出现在编辑表单中;未设置时默认显示。 */
13
22
  inEdit?: boolean;
23
+ /** 是否出现在详情面板中;未设置时默认显示。 */
14
24
  inDetail?: boolean;
25
+ /** 选择类字段的静态选项或动态选项工厂。 */
15
26
  options?: Array<{
16
27
  label: string;
17
28
  value: string | number | boolean;
@@ -19,6 +30,7 @@ type FieldDef = {
19
30
  label: string;
20
31
  value: string | number | boolean;
21
32
  }>);
33
+ /** 表单校验规则。 */
22
34
  validation?: {
23
35
  required?: boolean;
24
36
  min?: number;
@@ -26,41 +38,73 @@ type FieldDef = {
26
38
  pattern?: string;
27
39
  message?: string;
28
40
  };
41
+ /** 列宽 CSS 值。 */
29
42
  width?: string;
43
+ /** 单元格对齐方式。 */
30
44
  align?: 'left' | 'center' | 'right';
45
+ /** 列表单元格的自定义渲染函数。 */
31
46
  render?: (value: unknown, item: Record<string, unknown>) => string;
47
+ /** 输入控件占位文案。 */
32
48
  placeholder?: string | (() => string);
49
+ /** 日期范围起始值 key。 */
50
+ startKey?: string;
51
+ /** 日期范围结束值 key。 */
52
+ endKey?: string;
53
+ /** 新建记录时使用的默认值。 */
33
54
  defaultValue?: unknown;
55
+ /** 字段排序权重,数值越小越靠前。 */
34
56
  order?: number;
35
57
  };
58
+ /** CrudPage 使用的异步资源操作集合。 */
36
59
  type CrudApi = {
60
+ /** 获取当前分页、筛选和排序结果。 */
37
61
  list(params: Record<string, unknown>): Promise<{
38
62
  items: Record<string, unknown>[];
39
63
  total: number;
40
64
  page: number;
41
65
  pageSize: number;
42
66
  }>;
67
+ /** 按主键获取一条记录。 */
43
68
  get?(id: string): Promise<Record<string, unknown> | null>;
69
+ /** 创建一条记录。 */
44
70
  create?(data: Record<string, unknown>): Promise<Record<string, unknown>>;
71
+ /** 更新一条记录。 */
45
72
  update?(id: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
73
+ /** 删除一条记录。 */
46
74
  remove?(id: string): Promise<void>;
47
75
  };
76
+ /** 声明式 CRUD 资源及字段转换能力。 */
48
77
  type CrudDef = {
78
+ /** 资源元信息与后端 API。 */
49
79
  resource: {
80
+ /** 资源名称,用于识别当前业务实体。 */
50
81
  name: string;
82
+ /** 资源标题文案。 */
51
83
  label: string | (() => string);
84
+ /** 记录主键字段,默认使用 id。 */
52
85
  keyField?: string;
86
+ /** 资源字段定义。 */
53
87
  fields: FieldDef[];
88
+ /** 默认分页条数。 */
54
89
  defaultPageSize?: number;
90
+ /** 是否显示搜索框。 */
55
91
  searchable?: boolean;
92
+ /** 搜索框占位文案。 */
56
93
  searchPlaceholder?: string | (() => string);
94
+ /** 资源 CRUD API。 */
57
95
  api: CrudApi;
58
96
  };
97
+ /** 获取列表字段。 */
59
98
  getListFields: () => FieldDef[];
99
+ /** 获取筛选字段。 */
60
100
  getFilterFields: () => FieldDef[];
101
+ /** 获取新建字段。 */
61
102
  getCreateFields: () => FieldDef[];
103
+ /** 获取编辑字段。 */
62
104
  getEditFields: () => FieldDef[];
105
+ /** 获取详情字段。 */
63
106
  getDetailFields: () => FieldDef[];
107
+ /** 转换为 DataTable 列定义。 */
64
108
  toTableColumns: () => Array<{
65
109
  key: string;
66
110
  label: string;
@@ -68,11 +112,15 @@ type CrudDef = {
68
112
  align?: string;
69
113
  render?: (item: Record<string, unknown>) => string;
70
114
  }>;
115
+ /** 生成新建表单默认值。 */
71
116
  getDefaultValues: () => Record<string, unknown>;
117
+ /** API 操作代理。 */
72
118
  api: CrudApi;
73
119
  };
74
120
  type $$ComponentProps = {
121
+ /** CRUD 资源定义及其 API 操作。 */
75
122
  crud: CrudDef;
123
+ /** 当前页数据与服务端分页元数据。 */
76
124
  data: {
77
125
  items: Record<string, unknown>[];
78
126
  total: number;
@@ -80,23 +128,56 @@ type $$ComponentProps = {
80
128
  pageSize: number;
81
129
  filters?: Record<string, unknown>;
82
130
  };
131
+ /** 新建、编辑、删除权限;未设置的权限默认跟随 API 是否存在。 */
83
132
  permissions?: {
84
133
  create?: boolean;
85
134
  update?: boolean;
86
135
  delete?: boolean;
87
136
  };
137
+ /** 新建/编辑面板展示配置。 */
88
138
  form?: CrudFormConfig;
139
+ /** 分页栏展示配置。 */
89
140
  pagination?: CrudPaginationConfig;
141
+ /** 列表密度,影响行高、操作按钮和面板控件尺寸。 */
90
142
  density?: CrudDensity;
143
+ /** 点击详情图标是否打开详情面板。 */
91
144
  rowClickDetail?: boolean;
145
+ /** 是否显示默认页面标题栏;使用 toolbarLeading 承载标题时可设为 false。 */
146
+ showHeader?: boolean;
147
+ /** 每行额外操作按钮插槽。 */
92
148
  listItemActions?: Snippet<[Record<string, unknown>]>;
149
+ /** 自定义表格单元格;参数依次为行记录和列 key。 */
150
+ tableCell?: Snippet<[Record<string, unknown>, string]>;
151
+ /** 点击表格行时的回调。 */
152
+ onrowclick?: (item: Record<string, unknown>) => void;
153
+ /** 编辑表单额外字段插槽。 */
93
154
  editFormExtra?: Snippet<[Record<string, unknown> | null, 'create' | 'edit']>;
155
+ /** 详情面板额外内容插槽。 */
94
156
  detailExtra?: Snippet<[Record<string, unknown>]>;
157
+ /** 页面标题右侧额外操作插槽。 */
95
158
  headerActions?: Snippet;
159
+ /** 工具栏风格:`toolbar` 使用图标弹层工具栏(默认),`filter-bar` 使用平铺筛选栏。 */
160
+ toolbarStyle?: CrudToolbarStyle;
161
+ /** toolbar 风格下工具栏左侧内容插槽,可用于放置页面标题或说明。 */
162
+ toolbarLeading?: Snippet;
163
+ /** TableToolbar 风格下工具栏右侧自定义操作插槽。 */
164
+ toolbarActions?: Snippet;
165
+ /** 卡片列表项渲染插槽;存在时替代 DataTable,仍复用工具栏、分页和独立滚动容器。 */
166
+ card?: Snippet<[Record<string, unknown>]>;
167
+ /** 可排序列配置;为空时默认使用全部列表列。 */
168
+ sortableColumns?: Array<{
169
+ key: string;
170
+ label: string;
171
+ }>;
172
+ /** 删除前钩子,返回 false 时取消删除。 */
96
173
  onbeforedelete?: (item: Record<string, unknown>) => Promise<boolean> | boolean;
174
+ /** 新建或编辑成功后的回调。 */
97
175
  onaftersubmit?: (item: Record<string, unknown>, mode: 'create' | 'edit') => void;
176
+ /** 删除成功后的回调。 */
98
177
  onafterdelete?: (item: Record<string, unknown>) => void;
178
+ /** 自定义错误回调。 */
99
179
  onerror?: (error: string) => void;
180
+ /** 列表路由基础路径。 */
100
181
  basePath?: string;
101
182
  /**
102
183
  * 路由适配器:用于读取当前 pathname、同步过滤参数到 URL、列表刷新。
@@ -105,6 +186,7 @@ type $$ComponentProps = {
105
186
  * 以获得客户端跳转 + invalidateAll 体验。
106
187
  */
107
188
  nav?: NavAdapter;
189
+ /** 根节点自定义 class。 */
108
190
  class?: string;
109
191
  } & DataAttributes;
110
192
  /**
@@ -49,6 +49,8 @@ export interface CrudPaginationConfig {
49
49
  /** 是否显示首页 / 末页跳转按钮(默认 true;紧凑视图可仅保留上一页 / 下一页) */
50
50
  showFirstLast?: boolean;
51
51
  }
52
+ /** CrudPage 工具栏风格;toolbar 是默认的图标弹层布局。 */
53
+ export type CrudToolbarStyle = 'filter-bar' | 'toolbar';
52
54
  /** CrudPage 初始列表数据(由 +page.server.ts load 返回) */
53
55
  export interface CrudPageData<T = Record<string, unknown>> {
54
56
  items: T[];
@@ -93,6 +95,10 @@ export interface CrudPageProps<T = Record<string, unknown>> extends DataAttribut
93
95
  align?: 'left' | 'center' | 'right';
94
96
  render?: (value: unknown, item: Record<string, unknown>) => string;
95
97
  placeholder?: string | (() => string);
98
+ /** 日期范围起始值 key;默认 `${id}Start`。 */
99
+ startKey?: string;
100
+ /** 日期范围结束值 key;默认 `${id}End`。 */
101
+ endKey?: string;
96
102
  defaultValue?: unknown;
97
103
  order?: number;
98
104
  }>;
@@ -150,14 +156,33 @@ export interface CrudPageProps<T = Record<string, unknown>> extends DataAttribut
150
156
  density?: CrudDensity;
151
157
  /** 列表行点击是否打开详情(默认 true) */
152
158
  rowClickDetail?: boolean;
159
+ /** 是否显示默认页面标题栏;需要把标题放进工具栏左侧时设为 false。 */
160
+ showHeader?: boolean;
153
161
  /** 列表行操作按钮插槽 */
154
162
  listItemActions?: Snippet<[T]>;
163
+ /** 自定义表格单元格插槽;参数依次为行记录和列 key。 */
164
+ tableCell?: Snippet<[T, string]>;
165
+ /** 点击表格行的回调。 */
166
+ onrowclick?: (item: T) => void;
155
167
  /** 编辑表单额外字段插槽 */
156
168
  editFormExtra?: Snippet<[T | null, 'create' | 'edit']>;
157
169
  /** 详情额外内容插槽 */
158
170
  detailExtra?: Snippet<[T]>;
159
171
  /** 页面头部额外操作区插槽 */
160
172
  headerActions?: Snippet;
173
+ /** 工具栏风格;toolbar 使用图标弹层,filter-bar 使用平铺筛选栏。 */
174
+ toolbarStyle?: CrudToolbarStyle;
175
+ /** toolbar 风格下工具栏左侧内容插槽,可放置页面标题或说明。 */
176
+ toolbarLeading?: Snippet;
177
+ /** 工具栏右侧自定义操作插槽。 */
178
+ toolbarActions?: Snippet;
179
+ /** 卡片列表项渲染插槽;存在时替代数据表格,分页和滚动容器保持一致。 */
180
+ card?: Snippet<[T]>;
181
+ /** 可排序列;为空时默认使用全部列表列。 */
182
+ sortableColumns?: Array<{
183
+ key: string;
184
+ label: string;
185
+ }>;
161
186
  /** 删除前钩子(返回 false 取消) */
162
187
  onbeforedelete?: (item: T) => Promise<boolean> | boolean;
163
188
  /** 提交成功后钩子 */
@@ -283,6 +283,23 @@
283
283
  "crud_total": "{count} items total",
284
284
  "crud_detail_empty": "-",
285
285
  "crud_field_required": "This field is required",
286
+ "toolbar_search": "Search",
287
+ "toolbar_filter": "Filter",
288
+ "toolbar_filter_conditions": "Filter conditions",
289
+ "toolbar_filter_reset": "Reset",
290
+ "toolbar_filter_all": "All",
291
+ "toolbar_sort": "Sort",
292
+ "toolbar_sort_conditions": "Sort conditions",
293
+ "toolbar_sort_default": "Default sort",
294
+ "toolbar_sort_field": "Sort field",
295
+ "toolbar_sort_default_order": "Default order",
296
+ "toolbar_sort_direction": "Sort direction",
297
+ "toolbar_sort_desc": "Descending",
298
+ "toolbar_sort_asc": "Ascending",
299
+ "toolbar_sort_summary": "Sorted by {label} {direction}",
300
+ "toolbar_view_switch": "View switch",
301
+ "toolbar_view_table": "Table view",
302
+ "toolbar_view_card": "Card view",
286
303
  "error_go_back": "Go Back",
287
304
  "error_back_home": "Back to Home",
288
305
  "error_401_title": "Unauthorized",
@@ -283,6 +283,23 @@
283
283
  "crud_total": "共 {count} 条",
284
284
  "crud_detail_empty": "-",
285
285
  "crud_field_required": "此字段为必填项",
286
+ "toolbar_search": "搜索",
287
+ "toolbar_filter": "筛选",
288
+ "toolbar_filter_conditions": "筛选条件",
289
+ "toolbar_filter_reset": "重置",
290
+ "toolbar_filter_all": "全部",
291
+ "toolbar_sort": "排序",
292
+ "toolbar_sort_conditions": "排序条件",
293
+ "toolbar_sort_default": "默认排序",
294
+ "toolbar_sort_field": "排序字段",
295
+ "toolbar_sort_default_order": "默认排序",
296
+ "toolbar_sort_direction": "排序方向",
297
+ "toolbar_sort_desc": "降序",
298
+ "toolbar_sort_asc": "升序",
299
+ "toolbar_sort_summary": "按 {label} {direction} 排列",
300
+ "toolbar_view_switch": "视图切换",
301
+ "toolbar_view_table": "表格视图",
302
+ "toolbar_view_card": "卡片视图",
286
303
  "error_go_back": "返回上一页",
287
304
  "error_back_home": "返回首页",
288
305
  "error_401_title": "未授权访问",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/ui",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.40",
4
+ "version": "0.1.0-alpha.41",
5
5
  "description": "Hai Framework UI component library for Svelte 5 Runes.",
6
6
  "license": "Apache-2.0",
7
7
  "svelte": "./dist/index.js",
@@ -52,7 +52,7 @@
52
52
  "mermaid": "^11.12.0",
53
53
  "shiki": "^4.0.2",
54
54
  "tailwind-merge": "^3.5.0",
55
- "@h-ai/core": "0.1.0-alpha.40"
55
+ "@h-ai/core": "0.1.0-alpha.41"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@sveltejs/package": "^2.5.7",