@wordrhyme/auto-crud 1.7.1 → 1.8.1

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/README.md CHANGED
@@ -370,6 +370,11 @@ interface UseAutoCrudResourceReturn<TSchema, TData> {
370
370
  interface Field {
371
371
  /** 字段标签(表格和表单共用) */
372
372
  label?: string;
373
+ /** 默认表格/详情文本和 CSV 值格式化;undefined 使用原来的默认行为 */
374
+ format?: (
375
+ value: unknown,
376
+ context: { row: Record<string, unknown>; target: 'display' | 'export' },
377
+ ) => string | undefined;
373
378
  /** 是否隐藏(表格和表单都隐藏) */
374
379
  hidden?: boolean;
375
380
  /** 表格特定配置 */
@@ -392,6 +397,31 @@ interface Field {
392
397
  type Fields = Record<string, Field>;
393
398
  ```
394
399
 
400
+ ### 值格式化
401
+
402
+ 在字段上配置 `format`,表格和详情使用 `target: 'display'`,顶部工具栏的选中/筛选导出及内置批量导出使用 `target: 'export'`。`value` 是格式化前的值,`row` 是原始记录。
403
+
404
+ ```tsx
405
+ fields={{
406
+ discount: {
407
+ format: (value) => `${value}%`,
408
+ },
409
+ createdAt: {
410
+ label: t('fields.createdAt'),
411
+ format: (value, { target }) => {
412
+ if (target !== 'export') return undefined;
413
+ if (value === null || value === undefined) return '';
414
+ const date = value instanceof Date ? value : new Date(String(value));
415
+ return Number.isNaN(date.getTime()) ? '' : date.toISOString();
416
+ },
417
+ },
418
+ }}
419
+ ```
420
+
421
+ 返回字符串(包括空字符串)时使用该结果;返回 `undefined` 时保留原有默认展示或原始 CSV 值。格式化只影响输出,不改变排序、筛选、表单或保存的数据。显式自定义 `cell` 仍负责自己的界面渲染;声明式 `table.display` / `table.options` / `table.dataSource` 按已有优先级接管单元格时也会应用 `format`。
422
+
423
+ 导出保留已有的列、字段名表头和权限排除规则。翻译继续在现有 `label`、选项和 `format` 中使用应用的 `t()`;无需另配导出列或语言。
424
+
395
425
  ### 列宽与单元格样式
396
426
 
397
427
  `fields.xxx.table` 中的 `size`、`minSize` 和 `maxSize` 控制列宽。`fields.xxx.table.classNames` 按元素分组配置该列的 CSS 类名:`th` 应用于该列的表头单元格,`td` 应用于该列每一行的正文单元格。
@@ -1578,15 +1608,15 @@ export { humanize } from './lib/humanize';
1578
1608
 
1579
1609
  ## 📄 许可证
1580
1610
 
1581
- MIT © [wordrhyme](https://github.com/pixpilot/shadcn-components)
1611
+ MIT © [wordrhyme](https://github.com/denvey/wordrhyme-components)
1582
1612
 
1583
1613
  ---
1584
1614
 
1585
1615
  ## 🔗 相关链接
1586
1616
 
1587
- - [GitHub](https://github.com/pixpilot/shadcn-components)
1588
- - [文档](https://github.com/pixpilot/shadcn-components/tree/main/packages/auto-crud)
1589
- - [示例](https://github.com/pixpilot/shadcn-components/tree/main/examples)
1617
+ - [GitHub](https://github.com/denvey/wordrhyme-components)
1618
+ - [文档](https://github.com/denvey/wordrhyme-components/tree/main/packages/auto-crud)
1619
+ - [示例](https://github.com/denvey/wordrhyme-components/tree/main/examples)
1590
1620
  - [Changelog](./CHANGELOG.md)
1591
1621
 
1592
1622
  ---
@@ -1699,3 +1729,31 @@ import '@wordrhyme/auto-crud/styles.css';
1699
1729
 
1700
1730
  See the [shared style guide](https://github.com/denvey/wordrhyme-components#styles)
1701
1731
  for theme setup, dark mode, and custom classes.
1732
+
1733
+ ### Optional pagination controls
1734
+
1735
+ Existing pagination defaults are preserved. Set `table.pagination` on `AutoCrudTable`
1736
+ (or `pagination` on `AutoTable` / `DataTable`) to opt in. Applications can also
1737
+ register options for a public CRUD id without changing the owning page:
1738
+
1739
+ ```ts
1740
+ import { tablePagination } from '@wordrhyme/auto-crud';
1741
+
1742
+ tablePagination.register('example.stores', {
1743
+ alwaysShowFirstLast: true,
1744
+ showPageJump: true,
1745
+ pageJumpLabel: 'Go to page',
1746
+ });
1747
+ // Remove the application override when no longer needed.
1748
+ // tablePagination.unregister('example.stores');
1749
+ ```
1750
+
1751
+ Registrations notify mounted tables. Explicit `table.pagination` takes precedence
1752
+ over registration. Page jumps accept only integer pages in the known page range;
1753
+ the control is disabled when the page count is unavailable.
1754
+
1755
+ In `AutoCrudTable`, the jump label follows the existing `locale` unless explicitly overridden.
1756
+
1757
+ Set `responsive: true` alongside these options to hide the extra controls when
1758
+ their measured content does not fit the pagination container. This responds to
1759
+ container resizing and translated text widths, without changing other tables.