@ticatec/topside-elements 1.0.6 → 1.1.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.
@@ -4,6 +4,7 @@
4
4
  import DataCell from "./DataCell.svelte";
5
5
  import type DataColumn from "../lib/DataColumn";
6
6
  import type { IndicatorColumn } from "..";
7
+ import { onRowExpandRequest, type RowEventHandlers, type IsRowExpandable } from "../lib/RowExpansion";
7
8
 
8
9
  interface Props {
9
10
  selectable?: boolean;
@@ -19,6 +20,9 @@
19
20
  expandRow?: any;
20
21
  rowHeight?: number;
21
22
  indicatorColumn?: IndicatorColumn | null;
23
+ /** 该行是否允许展开(决定是否显示图标) */
24
+ isExpandable?: IsRowExpandable<TableRow>;
25
+ rowEvents?: RowEventHandlers<TableRow> | null;
22
26
  }
23
27
 
24
28
  let {
@@ -35,8 +39,12 @@
35
39
  expandRow = null,
36
40
  rowHeight,
37
41
  indicatorColumn = null,
42
+ isExpandable = () => true,
43
+ rowEvents = null,
38
44
  }: Props = $props();
39
45
 
46
+ let showToggle = $derived(expandable && isExpandable(row));
47
+
40
48
  let style = $derived(rowHeight == null ? '' : `height: ${rowHeight}px`);
41
49
 
42
50
  const showInlineData = (e: MouseEvent) => {
@@ -59,7 +67,16 @@
59
67
  };
60
68
  </script>
61
69
 
62
- <div class="data-row" class:alternative style="width: 100%; {style}">
70
+ <!-- 行级单击 / 双击展开是鼠标快捷方式;键盘用户通过指示列图标(可聚焦)操作 -->
71
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
72
+ <div
73
+ class="data-row"
74
+ class:alternative
75
+ style="width: 100%; {style}"
76
+ onclick={(e) => rowEvents?.onRowClick(row, e)}
77
+ ondblclick={(e) => rowEvents?.onRowDblClick(row, e)}
78
+ use:onRowExpandRequest={(e) => rowEvents?.onExpandRequest(row, e)}
79
+ >
63
80
  {#if indicatorColumn}
64
81
  <div class="data-cell indicator-cell" style="width: {indicatorColumn.width}px">
65
82
  {#if selectable}
@@ -70,7 +87,7 @@
70
87
  <span>{rowNo}</span>
71
88
  </div>
72
89
  {/if}
73
- {#if expandable}
90
+ {#if showToggle}
74
91
  <div class="expand-icon" style="flex: 0 0 auto">
75
92
  <i
76
93
  class={row == expandRow ? 'icon_google_folder' : 'icon_google_folder_open'}
@@ -2,6 +2,7 @@ import type TableRow from "./TableRow";
2
2
  import type { OnRowExpand } from "../UniDataTable";
3
3
  import type DataColumn from "../lib/DataColumn";
4
4
  import type { IndicatorColumn } from "..";
5
+ import { type RowEventHandlers, type IsRowExpandable } from "../lib/RowExpansion";
5
6
  interface Props {
6
7
  selectable?: boolean;
7
8
  rowNo: number;
@@ -16,6 +17,9 @@ interface Props {
16
17
  expandRow?: any;
17
18
  rowHeight?: number;
18
19
  indicatorColumn?: IndicatorColumn | null;
20
+ /** 该行是否允许展开(决定是否显示图标) */
21
+ isExpandable?: IsRowExpandable<TableRow>;
22
+ rowEvents?: RowEventHandlers<TableRow> | null;
19
23
  }
20
24
  declare const FixedRow: import("svelte").Component<Props, {}, "">;
21
25
  type FixedRow = ReturnType<typeof FixedRow>;
@@ -100,7 +100,7 @@
100
100
 
101
101
  | 组件 | 导入路径 | 示例 | 属性数 |
102
102
  | --- | --- | --- | ---: |
103
- | [DataTable](./data-table/README.md) | `@ticatec/topside-elements/DataTable` | [示例](./data-table/example.svelte) | 17 |
103
+ | [DataTable](./data-table/README.md) | `@ticatec/topside-elements/DataTable` | [示例](./data-table/example.svelte) | 18 |
104
104
 
105
105
  ## 数据展示
106
106
 
@@ -38,6 +38,7 @@ import DataTable from '@ticatec/topside-elements/DataTable';
38
38
  | `overscan` | 否 | `number` | 否 | `8` | 否 | 虚拟化时可视区上下额外渲染的行数。 |
39
39
  | `summaryLabel` | 否 | `string` | 否 | `undefined` | 否 | 合计行的标签,默认取 i18n(uniface.dataTable.summaryLabel,"合计" / "Total");传空串则不显示标签 |
40
40
  | `summaryValues` | 否 | `Record<string, any> \| null` | 否 | `null` | 否 | 外部提供的合计值,按列 field 取值,优先于列的 summary 在当前 list 上的计算。 分页场景下用它显示服务端算好的全量合计(数字串会按数字格式化)。 |
41
+ | `rowExpansion` | 否 | `RowExpansion<T> \| null` | 否 | `null` | 否 | 行展开配置:展开区组件、是否显示指示列图标(默认显示)、整行单击 / 双击触发等。 不配置图标时可以用组件方法 expandRow / collapseRow / toggleRowExpand, 或在行内(自定义单元格、操作列、展开区)派发 ROW_EXPAND_EVENT 事件来控制。 同一时间只展开一行。 |
41
42
 
42
43
  > 组件的“可绑定”表示源码使用了 Svelte 5 的 `$bindable`;服务的“响应式”表示成员使用了 `$state`。复杂类型请同时参考 TypeScript 自动补全。
43
44
 
@@ -81,6 +82,18 @@ import DataTable from '@ticatec/topside-elements/DataTable';
81
82
  - 默认值:`$bindable(80)`
82
83
  - 推荐写法:`bind:inlineRowHeight`
83
84
 
85
+ ## 组件实例方法
86
+
87
+ 通过 `bind:this` 获取组件实例后调用。
88
+
89
+ | 方法 | 类型 | 说明 |
90
+ | --- | --- | --- |
91
+ | `expandRow()` | `(data: T) => Promise<void>` | 展开指定行(按行数据对象匹配);行不存在或不允许展开时不做任何事 |
92
+ | `collapseRow()` | `(data?: T) => void` | 收起指定行;不传参数则收起当前展开的行 |
93
+ | `toggleRowExpand()` | `(data: T) => Promise<void>` | 切换指定行的展开状态 |
94
+ | `isRowExpanded()` | `(data: T) => boolean` | 某行当前是否展开 |
95
+ | `getExpandedRow()` | `() => T \| null` | 当前展开行的数据,没有则为 null |
96
+
84
97
  ## 相关类型定义
85
98
 
86
99
  以下定义帮助理解复杂属性的数据结构;其中部分辅助类型属于内部实现,不一定是独立导出入口。
@@ -218,7 +231,8 @@ export default interface IndicatorColumn {
218
231
  selectable?: boolean;
219
232
 
220
233
  /**
221
- *
234
+ * @deprecated 请改用 DataTable 的 `rowExpansion` 属性(`{ build, showToggle, trigger, ... }`)。
235
+ * 保留兼容:等价于 rowExpansion = { build: buildInlineComponent }。
222
236
  */
223
237
  buildInlineComponent?: (data:any) => Promise<any>;
224
238
 
@@ -237,6 +251,26 @@ export default interface IndicatorColumn {
237
251
  export type GetRowFontStyle<T = any> = (data: T) => RowFontStyle;
238
252
  ```
239
253
 
254
+ ### `RowExpansion`
255
+
256
+ ```ts
257
+ export default interface RowExpansion<T = any> {
258
+ /** 展开区组件生成器 */
259
+ build: BuildInlineComponent<T>;
260
+ /**
261
+ * 是否在指示列显示展开 / 收起图标,默认 true。
262
+ * 需要同时配置 indicatorColumn;设为 false 时只靠 trigger / 方法 / 事件触发。
263
+ */
264
+ showToggle?: boolean;
265
+ /** 整行触发方式(单击 / 双击),默认不设置 */
266
+ trigger?: RowExpandTrigger;
267
+ /** 判定某行是否允许展开,默认所有行都可以 */
268
+ isExpandable?: IsRowExpandable<T>;
269
+ /** 展开状态变化回调:展开时为该行数据,收起时为 null */
270
+ onExpandChange?: (data: T | null) => void;
271
+ }
272
+ ```
273
+
240
274
  ### `Column`
241
275
 
242
276
  ```ts
@@ -337,6 +371,24 @@ export interface RowFontStyle {
337
371
  }
338
372
  ```
339
373
 
374
+ ### `BuildInlineComponent`
375
+
376
+ ```ts
377
+ export type BuildInlineComponent<T = any> = (data: T) => Promise<Component<any>> | Component<any>;
378
+ ```
379
+
380
+ ### `RowExpandTrigger`
381
+
382
+ ```ts
383
+ export type RowExpandTrigger = 'click' | 'dblclick';
384
+ ```
385
+
386
+ ### `IsRowExpandable`
387
+
388
+ ```ts
389
+ export type IsRowExpandable<T = any> = (data: T) => boolean;
390
+ ```
391
+
340
392
  ### `HrefLink`
341
393
 
342
394
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/topside-elements",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "A comprehensive UI component library for Svelte applications with rich form controls, data tables, layouts and interactive elements",
5
5
  "keywords": [
6
6
  "svelte",