@elmeragroup/fuse 0.1.0-canary.2 → 0.1.0-canary.4

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 (114) hide show
  1. package/components/data-table/actions-column.d.ts +50 -0
  2. package/components/data-table/actions-column.d.ts.map +1 -0
  3. package/components/data-table/actions-column.js +31 -0
  4. package/components/data-table/actions-column.js.map +1 -0
  5. package/components/data-table/create-fuse-table-hook.d.ts +119 -0
  6. package/components/data-table/create-fuse-table-hook.d.ts.map +1 -0
  7. package/components/data-table/create-fuse-table-hook.js +76 -0
  8. package/components/data-table/create-fuse-table-hook.js.map +1 -0
  9. package/components/data-table/data-table-cells.d.ts +64 -0
  10. package/components/data-table/data-table-cells.d.ts.map +1 -0
  11. package/components/data-table/data-table-cells.js +71 -0
  12. package/components/data-table/data-table-cells.js.map +1 -0
  13. package/components/data-table/data-table-column-toggle.d.ts +28 -0
  14. package/components/data-table/data-table-column-toggle.d.ts.map +1 -0
  15. package/components/data-table/data-table-column-toggle.js +40 -0
  16. package/components/data-table/data-table-column-toggle.js.map +1 -0
  17. package/components/data-table/data-table-contexts.d.ts +14 -0
  18. package/components/data-table/data-table-contexts.d.ts.map +1 -0
  19. package/components/data-table/data-table-contexts.js +17 -0
  20. package/components/data-table/data-table-contexts.js.map +1 -0
  21. package/components/data-table/data-table-format.d.ts +19 -0
  22. package/components/data-table/data-table-format.d.ts.map +1 -0
  23. package/components/data-table/data-table-format.js +69 -0
  24. package/components/data-table/data-table-format.js.map +1 -0
  25. package/components/data-table/data-table-pagination-status.d.ts +44 -0
  26. package/components/data-table/data-table-pagination-status.d.ts.map +1 -0
  27. package/components/data-table/data-table-pagination-status.js +34 -0
  28. package/components/data-table/data-table-pagination-status.js.map +1 -0
  29. package/components/data-table/data-table-pagination.d.ts +40 -0
  30. package/components/data-table/data-table-pagination.d.ts.map +1 -0
  31. package/components/data-table/data-table-pagination.js +121 -0
  32. package/components/data-table/data-table-pagination.js.map +1 -0
  33. package/components/data-table/data-table-registered.d.ts +69 -0
  34. package/components/data-table/data-table-registered.d.ts.map +1 -0
  35. package/components/data-table/data-table-registered.js +205 -0
  36. package/components/data-table/data-table-registered.js.map +1 -0
  37. package/components/data-table/data-table-row-actions.d.ts +34 -0
  38. package/components/data-table/data-table-row-actions.d.ts.map +1 -0
  39. package/components/data-table/data-table-row-actions.js +61 -0
  40. package/components/data-table/data-table-row-actions.js.map +1 -0
  41. package/components/data-table/data-table-selection.d.ts +35 -0
  42. package/components/data-table/data-table-selection.d.ts.map +1 -0
  43. package/components/data-table/data-table-selection.js +44 -0
  44. package/components/data-table/data-table-selection.js.map +1 -0
  45. package/components/data-table/data-table-sort-button.d.ts +22 -0
  46. package/components/data-table/data-table-sort-button.d.ts.map +1 -0
  47. package/components/data-table/data-table-sort-button.js +43 -0
  48. package/components/data-table/data-table-sort-button.js.map +1 -0
  49. package/components/data-table/data-table-source.d.ts +99 -0
  50. package/components/data-table/data-table-source.d.ts.map +1 -0
  51. package/components/data-table/data-table-source.js +0 -0
  52. package/components/data-table/data-table-variants.d.ts +61 -0
  53. package/components/data-table/data-table-variants.d.ts.map +1 -0
  54. package/components/data-table/data-table-variants.js +30 -0
  55. package/components/data-table/data-table-variants.js.map +1 -0
  56. package/components/data-table/data-table.d.ts +108 -0
  57. package/components/data-table/data-table.d.ts.map +1 -0
  58. package/components/data-table/data-table.js +209 -0
  59. package/components/data-table/data-table.js.map +1 -0
  60. package/components/data-table/index.d.ts +27 -0
  61. package/components/data-table/index.d.ts.map +1 -0
  62. package/components/data-table/index.js +34 -0
  63. package/components/data-table/index.js.map +1 -0
  64. package/components/data-table/intl/en-US.d.ts +19 -0
  65. package/components/data-table/intl/en-US.d.ts.map +1 -0
  66. package/components/data-table/intl/en-US.js +20 -0
  67. package/components/data-table/intl/en-US.js.map +1 -0
  68. package/components/data-table/intl/fi-FI.d.ts +19 -0
  69. package/components/data-table/intl/fi-FI.d.ts.map +1 -0
  70. package/components/data-table/intl/fi-FI.js +20 -0
  71. package/components/data-table/intl/fi-FI.js.map +1 -0
  72. package/components/data-table/intl/index.d.ts +5 -0
  73. package/components/data-table/intl/index.d.ts.map +1 -0
  74. package/components/data-table/intl/index.js +17 -0
  75. package/components/data-table/intl/index.js.map +1 -0
  76. package/components/data-table/intl/nb-NO.d.ts +19 -0
  77. package/components/data-table/intl/nb-NO.d.ts.map +1 -0
  78. package/components/data-table/intl/nb-NO.js +20 -0
  79. package/components/data-table/intl/nb-NO.js.map +1 -0
  80. package/components/data-table/intl/sv-SE.d.ts +19 -0
  81. package/components/data-table/intl/sv-SE.d.ts.map +1 -0
  82. package/components/data-table/intl/sv-SE.js +20 -0
  83. package/components/data-table/intl/sv-SE.js.map +1 -0
  84. package/components/data-table/select-column.d.ts +47 -0
  85. package/components/data-table/select-column.d.ts.map +1 -0
  86. package/components/data-table/select-column.js +29 -0
  87. package/components/data-table/select-column.js.map +1 -0
  88. package/components/dropdown-menu/dropdown-menu-variants.d.ts +40 -0
  89. package/components/dropdown-menu/dropdown-menu-variants.d.ts.map +1 -0
  90. package/components/phone-number-field/phone-number-field.js +2 -2
  91. package/components/phone-number-field/phone-number-field.js.map +1 -1
  92. package/components/selection-item/selection-item.js +3 -3
  93. package/components/selection-item/selection-item.js.map +1 -1
  94. package/components/sidebar/sidebar.js +1 -1
  95. package/components/toast/toast.js +2 -2
  96. package/components/toast/toast.js.map +1 -1
  97. package/data-table.d.ts +14 -0
  98. package/data-table.js +6 -0
  99. package/icons/generated/caret-double-left.d.ts +10 -0
  100. package/icons/generated/caret-double-left.d.ts.map +1 -0
  101. package/icons/generated/caret-double-left.js +13 -0
  102. package/icons/generated/caret-double-left.js.map +1 -0
  103. package/icons/generated/caret-double-right.d.ts +10 -0
  104. package/icons/generated/caret-double-right.d.ts.map +1 -0
  105. package/icons/generated/caret-double-right.js +13 -0
  106. package/icons/generated/caret-double-right.js.map +1 -0
  107. package/icons.d.ts +3 -1
  108. package/icons.js +7 -5
  109. package/index.d.ts +2 -2
  110. package/index.js +2 -2
  111. package/package.json +10 -2
  112. package/react-aria/calendar/calendar.js +1 -1
  113. package/styles.css +15 -0
  114. package/theme.d.ts +1 -1
@@ -0,0 +1,50 @@
1
+ import { DisplayColumnHelper } from "./data-table-source.js";
2
+ import { ReactNode } from "react";
3
+ //#region src/components/data-table/actions-column.d.ts
4
+ /** The cell render context the actions column reads. */
5
+ type ActionsCellContext<TData> = {
6
+ readonly row: {
7
+ readonly original: TData;
8
+ };
9
+ };
10
+ /**
11
+ * The display column `actionsColumn` builds. It reads only the row's data, so it needs no table
12
+ * feature.
13
+ */
14
+ export type ActionsColumnDef<TData> = {
15
+ readonly id: "actions";
16
+ readonly enableSorting: false;
17
+ readonly enableHiding: false;
18
+ readonly header: () => ReactNode;
19
+ readonly cell: (context: ActionsCellContext<TData>) => ReactNode;
20
+ };
21
+ /** `DisplayColumnHelper` for `actionsColumn`. */
22
+ export type ActionsColumnHelper<TData, TColumn> = DisplayColumnHelper<ActionsColumnDef<TData>, TColumn>;
23
+ /** Options for `actionsColumn`. */
24
+ export type ActionsColumnOptions<TData> = {
25
+ /**
26
+ * The row's own name, such as `(product) => product.name`. Fuse builds the trigger's localized
27
+ * accessible name from it ("Actions for 4K Ultra HD Monitor"), so no two triggers share a name.
28
+ */
29
+ getRowName: (row: TData) => string;
30
+ /**
31
+ * The menu items for a row: `DropdownMenu.Item`, including `variant="destructive"`, and
32
+ * `DropdownMenu.Separator`.
33
+ */
34
+ items: (row: TData) => ReactNode;
35
+ };
36
+ /**
37
+ * Build the row-actions column: `DataTable.RowActions` in each cell, right-aligned, with a
38
+ * per-row accessible name. The header names the column "Actions" for assistive technology without
39
+ * visible text, the column shrinks to the trigger, and sorting and hiding are disabled. Clicks in
40
+ * the open menu do not press a pressable row.
41
+ *
42
+ * @template TData - The row data type, inferred from the column helper.
43
+ * @template TColumn - The column definition type the helper returns.
44
+ * @param columnHelper - A column helper for the table.
45
+ * @param options - The row's name and its menu items.
46
+ * @returns A display column with the id `"actions"`.
47
+ */
48
+ export declare function actionsColumn<TData, TColumn>(columnHelper: ActionsColumnHelper<TData, TColumn>, { getRowName, items }: ActionsColumnOptions<NoInfer<TData>>): TColumn;
49
+ //#endregion
50
+ //# sourceMappingURL=actions-column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions-column.d.ts","names":[],"sources":["../../../src/components/data-table/actions-column.tsx"],"mappings":";;;;KAMK,mBAAmB;WAAoB;aAAgB,UAAU;;;;;;;YAM1D,iBAAiB;WAClB;WACA;WACA;WACA,cAAc;WACd,OAAO,SAAS,mBAAmB,WAAW;;;YAI7C,oBAAoB,OAAO,WAAW,oBAAoB,iBAAiB,QAAQ;;YAGnF,qBAAqB;;;;;EAK/B,aAAa,KAAK;;;;;EAKlB,QAAQ,KAAK,UAAU;;;;;;;;;;;;;;wBAeT,cAAc,OAAO,SACnC,cAAc,oBAAoB,OAAO,YACvC,YAAY,SAAS,qBAAqB,QAAQ,UACnD"}
@@ -0,0 +1,31 @@
1
+ import { RowActionsCell, RowActionsHeader } from "./data-table-row-actions.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ //#region src/components/data-table/actions-column.tsx
4
+ /**
5
+ * Build the row-actions column: `DataTable.RowActions` in each cell, right-aligned, with a
6
+ * per-row accessible name. The header names the column "Actions" for assistive technology without
7
+ * visible text, the column shrinks to the trigger, and sorting and hiding are disabled. Clicks in
8
+ * the open menu do not press a pressable row.
9
+ *
10
+ * @template TData - The row data type, inferred from the column helper.
11
+ * @template TColumn - The column definition type the helper returns.
12
+ * @param columnHelper - A column helper for the table.
13
+ * @param options - The row's name and its menu items.
14
+ * @returns A display column with the id `"actions"`.
15
+ */
16
+ function actionsColumn(columnHelper, { getRowName, items }) {
17
+ return columnHelper.display({
18
+ id: "actions",
19
+ enableSorting: false,
20
+ enableHiding: false,
21
+ header: () => /* @__PURE__ */ jsx(RowActionsHeader, {}),
22
+ cell: ({ row }) => /* @__PURE__ */ jsx(RowActionsCell, {
23
+ name: getRowName(row.original),
24
+ children: items(row.original)
25
+ })
26
+ });
27
+ }
28
+ //#endregion
29
+ export { actionsColumn };
30
+
31
+ //# sourceMappingURL=actions-column.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions-column.js","names":[],"sources":["../../../src/components/data-table/actions-column.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport { RowActionsCell, RowActionsHeader } from \"./data-table-row-actions\";\nimport type { DisplayColumnHelper } from \"./data-table-source\";\n\n/** The cell render context the actions column reads. */\ntype ActionsCellContext<TData> = { readonly row: { readonly original: TData } };\n\n/**\n * The display column `actionsColumn` builds. It reads only the row's data, so it needs no table\n * feature.\n */\nexport type ActionsColumnDef<TData> = {\n readonly id: \"actions\";\n readonly enableSorting: false;\n readonly enableHiding: false;\n readonly header: () => ReactNode;\n readonly cell: (context: ActionsCellContext<TData>) => ReactNode;\n};\n\n/** `DisplayColumnHelper` for `actionsColumn`. */\nexport type ActionsColumnHelper<TData, TColumn> = DisplayColumnHelper<ActionsColumnDef<TData>, TColumn>;\n\n/** Options for `actionsColumn`. */\nexport type ActionsColumnOptions<TData> = {\n /**\n * The row's own name, such as `(product) => product.name`. Fuse builds the trigger's localized\n * accessible name from it (\"Actions for 4K Ultra HD Monitor\"), so no two triggers share a name.\n */\n getRowName: (row: TData) => string;\n /**\n * The menu items for a row: `DropdownMenu.Item`, including `variant=\"destructive\"`, and\n * `DropdownMenu.Separator`.\n */\n items: (row: TData) => ReactNode;\n};\n\n/**\n * Build the row-actions column: `DataTable.RowActions` in each cell, right-aligned, with a\n * per-row accessible name. The header names the column \"Actions\" for assistive technology without\n * visible text, the column shrinks to the trigger, and sorting and hiding are disabled. Clicks in\n * the open menu do not press a pressable row.\n *\n * @template TData - The row data type, inferred from the column helper.\n * @template TColumn - The column definition type the helper returns.\n * @param columnHelper - A column helper for the table.\n * @param options - The row's name and its menu items.\n * @returns A display column with the id `\"actions\"`.\n */\nexport function actionsColumn<TData, TColumn>(\n columnHelper: ActionsColumnHelper<TData, TColumn>,\n { getRowName, items }: ActionsColumnOptions<NoInfer<TData>>\n): TColumn {\n return columnHelper.display({\n id: \"actions\",\n enableSorting: false,\n enableHiding: false,\n header: () => <RowActionsHeader />,\n cell: ({ row }) => <RowActionsCell name={getRowName(row.original)}>{items(row.original)}</RowActionsCell>,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,SAAgB,cACd,cACA,EAAE,YAAY,SACL;CACT,OAAO,aAAa,QAAQ;EAC1B,IAAI;EACJ,eAAe;EACf,cAAc;EACd,cAAc,oBAAC,kBAAD,CAAmB,CAAA;EACjC,OAAO,EAAE,UAAU,oBAAC,gBAAD;GAAgB,MAAM,WAAW,IAAI,QAAQ;GAAI,UAAA,MAAM,IAAI,QAAQ;EAAkB,CAAA;CAC1G,CAAC;AACH"}
@@ -0,0 +1,119 @@
1
+ import { NoComponents } from "./data-table-source.js";
2
+ import { CurrencyCellProps, DateCellProps, DateTimeCellProps, NumberCellProps, RegisteredColumnToggleProps, RegisteredContentProps, RegisteredPaginationProps, RegisteredRowProps, RegisteredSortButtonProps, TextCellProps } from "./data-table-registered.js";
3
+ import { ComponentType, ReactElement } from "react";
4
+ import { AppReactTable, Column, CreateTableHookOptions, CreateTableHookResult, Row, RowData, TableFeatures, TableOptions, TableState } from "@tanstack/react-table";
5
+ //#region src/components/data-table/create-fuse-table-hook.d.ts
6
+ /** A registry of named components, as `createTableHook` accepts them. */
7
+ type ComponentRegistry = Record<string, ComponentType<any>>;
8
+ /**
9
+ * The app's table registry. A replacement `Row` must accept the props `table.Content` renders its
10
+ * default rows with, since the registered parts call it with only those.
11
+ */
12
+ type TableRegistry<TFeatures extends TableFeatures> = ComponentRegistry & {
13
+ readonly Row?: ComponentType<RegisteredRowProps<Row<TFeatures, any>>>;
14
+ };
15
+ /**
16
+ * The app's registry wins by key, and a replaced Fuse component's props are gone. An intersection
17
+ * would overload the two and keep accepting the replaced props.
18
+ */
19
+ type Merge<TFuse, TApp> = Omit<TFuse, keyof TApp> & TApp;
20
+ /** Includes `TPart` exactly when `TFeatures` registers `TFeature`. */
21
+ type WithFeature<TFeatures, TFeature extends string, TPart> = TFeature extends keyof TFeatures ? TPart : NoComponents;
22
+ /**
23
+ * The table parts Fuse registers on the table `useFuseTable` returns. One registry serves every
24
+ * table the hook creates, so each part is generic over the row data and defaults it to `TData`, the
25
+ * row data of the table it is read from: `table.Content`'s row takeover receives `Row<TFeatures,
26
+ * TData>`, while `table.Row` takes any row it is given. `Pagination` and `ColumnToggle` appear only
27
+ * with their feature.
28
+ */
29
+ export type FuseTableComponents<TFeatures extends TableFeatures, TData extends RowData = RowData> = {
30
+ /** The whole table, rendered through the registered header and cell wrappers. */
31
+ Content: <TRowData extends RowData = TData>(props: RegisteredContentProps<Row<TFeatures, TRowData>>) => ReactElement;
32
+ /** One row. It renders inside `Content`'s row takeover, which keeps it current. */
33
+ Row: <TRowData extends RowData = TData>(props: RegisteredRowProps<Row<TFeatures, TRowData>>) => ReactElement;
34
+ } & WithFeature<TFeatures, "rowPaginationFeature", {
35
+ /** Rows-per-page select, page status and page buttons. */
36
+ Pagination: (props: RegisteredPaginationProps) => ReactElement;
37
+ }> & WithFeature<TFeatures, "columnVisibilityFeature", {
38
+ /** The column visibility menu. */
39
+ ColumnToggle: <TRowData extends RowData = TData>(props: RegisteredColumnToggleProps<Column<TFeatures, TRowData, unknown>>) => ReactElement;
40
+ }>;
41
+ /** The header parts Fuse registers. `SortButton` appears only with `rowSortingFeature`. */
42
+ export type FuseHeaderComponents<TFeatures extends TableFeatures> = WithFeature<TFeatures, "rowSortingFeature", {
43
+ /** The header's sort toggle. */
44
+ SortButton: (props: RegisteredSortButtonProps) => ReactElement;
45
+ }>;
46
+ /** The default cells Fuse registers. An app replaces one by registering its own under the key. */
47
+ export type FuseCellComponents = {
48
+ /** The cell value as text. */
49
+ TextCell: (props: TextCellProps) => ReactElement;
50
+ /** A number, formatted for the locale. */
51
+ NumberCell: (props: NumberCellProps) => ReactElement;
52
+ /** An amount in a required currency, formatted for the locale. */
53
+ CurrencyCell: (props: CurrencyCellProps) => ReactElement;
54
+ /** A date, formatted for the locale. */
55
+ DateCell: (props: DateCellProps) => ReactElement;
56
+ /** A date and time, formatted for the locale. */
57
+ DateTimeCell: (props: DateTimeCellProps) => ReactElement;
58
+ };
59
+ /**
60
+ * Options for `createFuseTableHook`: every `createTableHook` option except the contexts, which
61
+ * Fuse owns.
62
+ */
63
+ export type CreateFuseTableHookOptions<TFeatures extends TableFeatures, TTableComponents extends TableRegistry<TFeatures>, TCellComponents extends ComponentRegistry, THeaderComponents extends ComponentRegistry> = CreateTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents> & {
64
+ /** Fuse owns the table context. */
65
+ readonly tableContext?: never;
66
+ /** Fuse owns the cell context. */
67
+ readonly cellContext?: never;
68
+ /** Fuse owns the header context. */
69
+ readonly headerContext?: never;
70
+ };
71
+ /** A table from `useAppTable` or `useTableContext`, with Fuse's parts defaulted to its row data. */
72
+ type FuseAppTable<TFeatures extends TableFeatures, TData extends RowData, TSelected, TTableComponents extends TableRegistry<TFeatures>, TCellComponents extends ComponentRegistry, THeaderComponents extends ComponentRegistry> = AppReactTable<TFeatures, TData, TSelected, Merge<FuseTableComponents<TFeatures, TData>, TTableComponents>, Merge<FuseCellComponents, TCellComponents>, Merge<FuseHeaderComponents<TFeatures>, THeaderComponents>>;
73
+ /**
74
+ * What `createFuseTableHook` returns: `createTableHook`'s result over the merged registries.
75
+ * `useAppTable` and `useTableContext` default Fuse's table parts to the table's row data, which
76
+ * TanStack's result cannot express: it types the registry once, for every table.
77
+ */
78
+ export type CreateFuseTableHookResult<TFeatures extends TableFeatures, TTableComponents extends TableRegistry<TFeatures>, TCellComponents extends ComponentRegistry, THeaderComponents extends ComponentRegistry> = Omit<CreateTableHookResult<TFeatures, Merge<FuseTableComponents<TFeatures>, TTableComponents>, Merge<FuseCellComponents, TCellComponents>, Merge<FuseHeaderComponents<TFeatures>, THeaderComponents>>, "useAppTable" | "useTableContext"> & {
79
+ /** `createTableHook`'s `useAppTable`, with Fuse's table parts defaulted to the table's row data. */
80
+ useAppTable: <TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: Omit<TableOptions<TFeatures, TData>, "features">, selector?: (state: TableState<TFeatures>) => TSelected) => FuseAppTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
81
+ /**
82
+ * `createTableHook`'s `useTableContext`, with Fuse's table parts defaulted to `TData`. Pass the
83
+ * row data type to type `table.Content`'s row takeover in a component that reads the table from
84
+ * context.
85
+ */
86
+ useTableContext: <TData extends RowData = RowData, TSelected = TableState<TFeatures>>() => FuseAppTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
87
+ };
88
+ /**
89
+ * Bind an app's table features, default options and components into one `useFuseTable` hook, with
90
+ * Fuse's parts registered: `table.Content`, `table.Row`, `table.Pagination`,
91
+ * `table.ColumnToggle`, `header.SortButton` and the default cells `TextCell`, `NumberCell`,
92
+ * `CurrencyCell`, `DateCell` and `DateTimeCell`.
93
+ *
94
+ * It wraps TanStack's `createTableHook` and passes `features` and every default option through
95
+ * untouched; Fuse adds no features of its own. The app's components are registered after Fuse's,
96
+ * so registering `cellComponents: { NumberCell }` replaces Fuse's `NumberCell`, props included. A
97
+ * registered part appears in the types only when its feature is in `features`: `Pagination` needs
98
+ * `rowPaginationFeature`, `ColumnToggle` `columnVisibilityFeature` and `SortButton`
99
+ * `rowSortingFeature`. Render the registered table parts inside `<table.AppTable>`.
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * export const { useAppTable: useFuseTable, createAppColumnHelper } = createFuseTableHook({
104
+ * features: tableFeatures({ rowPaginationFeature, rowSortingFeature }),
105
+ * enableSortingRemoval: false,
106
+ * cellComponents: { OrderIdCell },
107
+ * });
108
+ * ```
109
+ *
110
+ * @template TFeatures - The app's `tableFeatures({...})` object.
111
+ * @template TTableComponents - The app's table components.
112
+ * @template TCellComponents - The app's cell components.
113
+ * @template THeaderComponents - The app's header components.
114
+ * @param options - Features, default table options and the app's components.
115
+ * @returns TanStack's table hook result, typed with Fuse's parts merged under the app's.
116
+ */
117
+ export declare function createFuseTableHook<TFeatures extends TableFeatures, const TTableComponents extends TableRegistry<TFeatures> = NoComponents, const TCellComponents extends ComponentRegistry = NoComponents, const THeaderComponents extends ComponentRegistry = NoComponents>(options: CreateFuseTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents>): CreateFuseTableHookResult<TFeatures, TTableComponents, TCellComponents, THeaderComponents>;
118
+ //#endregion
119
+ //# sourceMappingURL=create-fuse-table-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-fuse-table-hook.d.ts","names":[],"sources":["../../../src/components/data-table/create-fuse-table-hook.ts"],"mappings":";;;;;;KA8CK,oBAAoB,eAAe;;;;;KAMnC,cAAc,kBAAkB,iBAAiB;WAE3C,MAAM,cAAc,mBAAmB,IAAI;;;;;;KAOjD,MAAM,OAAO,QAAQ,KAAK,aAAa,QAAQ;;KAG/C,YAAY,WAAW,yBAAyB,SAAS,uBAAuB,YACjF,QACA;;;;;;;;YASQ,oBAAoB,kBAAkB,eAAe,cAAc,UAAU;;EAEvF,UAAU,iBAAiB,UAAU,OACnC,OAAO,uBAAuB,IAAI,WAAW,eAC1C;;EAEL,MAAM,iBAAiB,UAAU,OAC/B,OAAO,mBAAmB,IAAI,WAAW,eACtC;IACH,YACF;;EAIE,aAAa,OAAO,8BAA8B;KAGpD,YACE;;EAIE,eAAe,iBAAiB,UAAU,OACxC,OAAO,4BAA4B,OAAO,WAAW,wBAClD;;;YAKC,qBAAqB,kBAAkB,iBAAiB,YAClE;;EAIE,aAAa,OAAO,8BAA8B;;;YAK1C;;EAEV,WAAW,OAAO,kBAAkB;;EAEpC,aAAa,OAAO,oBAAoB;;EAExC,eAAe,OAAO,sBAAsB;;EAE5C,WAAW,OAAO,kBAAkB;;EAEpC,eAAe,OAAO,sBAAsB;;;;;;YAOlC,2BACV,kBAAkB,eAClB,yBAAyB,cAAc,YACvC,wBAAwB,mBACxB,0BAA0B,qBACxB,uBAAuB,WAAW,kBAAkB,iBAAiB;;WAE9D;;WAEA;;WAEA;;;KAIN,aACH,kBAAkB,eAClB,cAAc,SACd,WACA,yBAAyB,cAAc,YACvC,wBAAwB,mBACxB,0BAA0B,qBACxB,cACF,WACA,OACA,WACA,MAAM,oBAAoB,WAAW,QAAQ,mBAC7C,MAAM,oBAAoB,kBAC1B,MAAM,qBAAqB,YAAY;;;;;;YAQ7B,0BACV,kBAAkB,eAClB,yBAAyB,cAAc,YACvC,wBAAwB,mBACxB,0BAA0B,qBACxB,KACF,sBACE,WACA,MAAM,oBAAoB,YAAY,mBACtC,MAAM,oBAAoB,kBAC1B,MAAM,qBAAqB,YAAY;;EAKzC,cAAc,cAAc,SAAS,YAAY,WAAW,YAC1D,cAAc,KAAK,aAAa,WAAW,qBAC3C,YAAY,OAAO,WAAW,eAAe,cAC1C,aAAa,WAAW,OAAO,WAAW,kBAAkB,iBAAiB;;;;;;EAMlF,kBAAkB,cAAc,UAAU,SAAS,YAAY,WAAW,iBAAiB,aACzF,WACA,OACA,WACA,kBACA,iBACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiEY,oBACd,kBAAkB,qBACZ,yBAAyB,cAAc,aAAa,oBACpD,wBAAwB,oBAAoB,oBAC5C,0BAA0B,oBAAoB,cAEpD,SAAS,2BAA2B,WAAW,kBAAkB,iBAAiB,qBACjF,0BAA0B,WAAW,kBAAkB,iBAAiB"}
@@ -0,0 +1,76 @@
1
+ "use client";
2
+ import { fuseTableContexts } from "./data-table-contexts.js";
3
+ import { CurrencyCell, DateCell, DateTimeCell, NumberCell, RegisteredColumnToggle, RegisteredContent, RegisteredPagination, RegisteredRow, RegisteredSortButton, TextCell } from "./data-table-registered.js";
4
+ import { createTableHook } from "@tanstack/react-table";
5
+ //#region src/components/data-table/create-fuse-table-hook.ts
6
+ /**
7
+ * Erased to the registry constraint: the parts are typed over every stock feature, which TypeScript
8
+ * cannot compare with the app's `TFeatures`, so the factory retypes them with one cast.
9
+ */
10
+ const FUSE_TABLE_COMPONENTS = {
11
+ Content: RegisteredContent,
12
+ Row: RegisteredRow,
13
+ Pagination: RegisteredPagination,
14
+ ColumnToggle: RegisteredColumnToggle
15
+ };
16
+ const FUSE_HEADER_COMPONENTS = { SortButton: RegisteredSortButton };
17
+ const FUSE_CELL_COMPONENTS = {
18
+ TextCell,
19
+ NumberCell,
20
+ CurrencyCell,
21
+ DateCell,
22
+ DateTimeCell
23
+ };
24
+ /** Fuse's parts first, then the app's, so the app wins by key at runtime, as `Merge` describes. */
25
+ function mergeRegistry(fuse, app) {
26
+ return {
27
+ ...fuse,
28
+ ...app ?? {}
29
+ };
30
+ }
31
+ /**
32
+ * Bind an app's table features, default options and components into one `useFuseTable` hook, with
33
+ * Fuse's parts registered: `table.Content`, `table.Row`, `table.Pagination`,
34
+ * `table.ColumnToggle`, `header.SortButton` and the default cells `TextCell`, `NumberCell`,
35
+ * `CurrencyCell`, `DateCell` and `DateTimeCell`.
36
+ *
37
+ * It wraps TanStack's `createTableHook` and passes `features` and every default option through
38
+ * untouched; Fuse adds no features of its own. The app's components are registered after Fuse's,
39
+ * so registering `cellComponents: { NumberCell }` replaces Fuse's `NumberCell`, props included. A
40
+ * registered part appears in the types only when its feature is in `features`: `Pagination` needs
41
+ * `rowPaginationFeature`, `ColumnToggle` `columnVisibilityFeature` and `SortButton`
42
+ * `rowSortingFeature`. Render the registered table parts inside `<table.AppTable>`.
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * export const { useAppTable: useFuseTable, createAppColumnHelper } = createFuseTableHook({
47
+ * features: tableFeatures({ rowPaginationFeature, rowSortingFeature }),
48
+ * enableSortingRemoval: false,
49
+ * cellComponents: { OrderIdCell },
50
+ * });
51
+ * ```
52
+ *
53
+ * @template TFeatures - The app's `tableFeatures({...})` object.
54
+ * @template TTableComponents - The app's table components.
55
+ * @template TCellComponents - The app's cell components.
56
+ * @template THeaderComponents - The app's header components.
57
+ * @param options - Features, default table options and the app's components.
58
+ * @returns TanStack's table hook result, typed with Fuse's parts merged under the app's.
59
+ */
60
+ function createFuseTableHook(options) {
61
+ const fuseTableComponents = FUSE_TABLE_COMPONENTS;
62
+ const fuseHeaderComponents = FUSE_HEADER_COMPONENTS;
63
+ return createTableHook({
64
+ ...options,
65
+ tableContext: fuseTableContexts.tableContext,
66
+ cellContext: fuseTableContexts.cellContext,
67
+ headerContext: fuseTableContexts.headerContext,
68
+ tableComponents: mergeRegistry(fuseTableComponents, options.tableComponents),
69
+ cellComponents: mergeRegistry(FUSE_CELL_COMPONENTS, options.cellComponents),
70
+ headerComponents: mergeRegistry(fuseHeaderComponents, options.headerComponents)
71
+ });
72
+ }
73
+ //#endregion
74
+ export { createFuseTableHook };
75
+
76
+ //# sourceMappingURL=create-fuse-table-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-fuse-table-hook.js","names":[],"sources":["../../../src/components/data-table/create-fuse-table-hook.ts"],"sourcesContent":["\"use client\";\n\nimport type { ComponentType, ReactElement } from \"react\";\n\nimport { createTableHook } from \"@tanstack/react-table\";\nimport type {\n AppReactTable,\n Column,\n CreateTableHookOptions,\n CreateTableHookResult,\n Row,\n RowData,\n TableFeatures,\n TableOptions,\n TableState,\n} from \"@tanstack/react-table\";\n\nimport { fuseTableContexts } from \"./data-table-contexts\";\nimport {\n CurrencyCell,\n DateCell,\n DateTimeCell,\n NumberCell,\n RegisteredColumnToggle,\n RegisteredContent,\n RegisteredPagination,\n RegisteredRow,\n RegisteredSortButton,\n TextCell,\n} from \"./data-table-registered\";\nimport type {\n CurrencyCellProps,\n DateCellProps,\n DateTimeCellProps,\n NumberCellProps,\n RegisteredColumnToggleProps,\n RegisteredContentProps,\n RegisteredPaginationProps,\n RegisteredRowProps,\n RegisteredSortButtonProps,\n TextCellProps,\n} from \"./data-table-registered\";\nimport type { NoComponents } from \"./data-table-source\";\n\n/** A registry of named components, as `createTableHook` accepts them. */\n// oxlint-disable-next-line typescript/no-explicit-any -- SAFETY: createTableHook's own registry constraint; a component's props are contravariant, so only `any` admits every component\ntype ComponentRegistry = Record<string, ComponentType<any>>;\n\n/**\n * The app's table registry. A replacement `Row` must accept the props `table.Content` renders its\n * default rows with, since the registered parts call it with only those.\n */\ntype TableRegistry<TFeatures extends TableFeatures> = ComponentRegistry & {\n // oxlint-disable-next-line typescript/no-explicit-any -- SAFETY: the app's row data type is bound per column helper, not per hook, so the constraint admits a Row typed over any of them\n readonly Row?: ComponentType<RegisteredRowProps<Row<TFeatures, any>>>;\n};\n\n/**\n * The app's registry wins by key, and a replaced Fuse component's props are gone. An intersection\n * would overload the two and keep accepting the replaced props.\n */\ntype Merge<TFuse, TApp> = Omit<TFuse, keyof TApp> & TApp;\n\n/** Includes `TPart` exactly when `TFeatures` registers `TFeature`. */\ntype WithFeature<TFeatures, TFeature extends string, TPart> = TFeature extends keyof TFeatures\n ? TPart\n : NoComponents;\n\n/**\n * The table parts Fuse registers on the table `useFuseTable` returns. One registry serves every\n * table the hook creates, so each part is generic over the row data and defaults it to `TData`, the\n * row data of the table it is read from: `table.Content`'s row takeover receives `Row<TFeatures,\n * TData>`, while `table.Row` takes any row it is given. `Pagination` and `ColumnToggle` appear only\n * with their feature.\n */\nexport type FuseTableComponents<TFeatures extends TableFeatures, TData extends RowData = RowData> = {\n /** The whole table, rendered through the registered header and cell wrappers. */\n Content: <TRowData extends RowData = TData>(\n props: RegisteredContentProps<Row<TFeatures, TRowData>>\n ) => ReactElement;\n /** One row. It renders inside `Content`'s row takeover, which keeps it current. */\n Row: <TRowData extends RowData = TData>(\n props: RegisteredRowProps<Row<TFeatures, TRowData>>\n ) => ReactElement;\n} & WithFeature<\n TFeatures,\n \"rowPaginationFeature\",\n {\n /** Rows-per-page select, page status and page buttons. */\n Pagination: (props: RegisteredPaginationProps) => ReactElement;\n }\n> &\n WithFeature<\n TFeatures,\n \"columnVisibilityFeature\",\n {\n /** The column visibility menu. */\n ColumnToggle: <TRowData extends RowData = TData>(\n props: RegisteredColumnToggleProps<Column<TFeatures, TRowData, unknown>>\n ) => ReactElement;\n }\n >;\n\n/** The header parts Fuse registers. `SortButton` appears only with `rowSortingFeature`. */\nexport type FuseHeaderComponents<TFeatures extends TableFeatures> = WithFeature<\n TFeatures,\n \"rowSortingFeature\",\n {\n /** The header's sort toggle. */\n SortButton: (props: RegisteredSortButtonProps) => ReactElement;\n }\n>;\n\n/** The default cells Fuse registers. An app replaces one by registering its own under the key. */\nexport type FuseCellComponents = {\n /** The cell value as text. */\n TextCell: (props: TextCellProps) => ReactElement;\n /** A number, formatted for the locale. */\n NumberCell: (props: NumberCellProps) => ReactElement;\n /** An amount in a required currency, formatted for the locale. */\n CurrencyCell: (props: CurrencyCellProps) => ReactElement;\n /** A date, formatted for the locale. */\n DateCell: (props: DateCellProps) => ReactElement;\n /** A date and time, formatted for the locale. */\n DateTimeCell: (props: DateTimeCellProps) => ReactElement;\n};\n\n/**\n * Options for `createFuseTableHook`: every `createTableHook` option except the contexts, which\n * Fuse owns.\n */\nexport type CreateFuseTableHookOptions<\n TFeatures extends TableFeatures,\n TTableComponents extends TableRegistry<TFeatures>,\n TCellComponents extends ComponentRegistry,\n THeaderComponents extends ComponentRegistry,\n> = CreateTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents> & {\n /** Fuse owns the table context. */\n readonly tableContext?: never;\n /** Fuse owns the cell context. */\n readonly cellContext?: never;\n /** Fuse owns the header context. */\n readonly headerContext?: never;\n};\n\n/** A table from `useAppTable` or `useTableContext`, with Fuse's parts defaulted to its row data. */\ntype FuseAppTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TTableComponents extends TableRegistry<TFeatures>,\n TCellComponents extends ComponentRegistry,\n THeaderComponents extends ComponentRegistry,\n> = AppReactTable<\n TFeatures,\n TData,\n TSelected,\n Merge<FuseTableComponents<TFeatures, TData>, TTableComponents>,\n Merge<FuseCellComponents, TCellComponents>,\n Merge<FuseHeaderComponents<TFeatures>, THeaderComponents>\n>;\n\n/**\n * What `createFuseTableHook` returns: `createTableHook`'s result over the merged registries.\n * `useAppTable` and `useTableContext` default Fuse's table parts to the table's row data, which\n * TanStack's result cannot express: it types the registry once, for every table.\n */\nexport type CreateFuseTableHookResult<\n TFeatures extends TableFeatures,\n TTableComponents extends TableRegistry<TFeatures>,\n TCellComponents extends ComponentRegistry,\n THeaderComponents extends ComponentRegistry,\n> = Omit<\n CreateTableHookResult<\n TFeatures,\n Merge<FuseTableComponents<TFeatures>, TTableComponents>,\n Merge<FuseCellComponents, TCellComponents>,\n Merge<FuseHeaderComponents<TFeatures>, THeaderComponents>\n >,\n \"useAppTable\" | \"useTableContext\"\n> & {\n /** `createTableHook`'s `useAppTable`, with Fuse's table parts defaulted to the table's row data. */\n useAppTable: <TData extends RowData, TSelected = TableState<TFeatures>>(\n tableOptions: Omit<TableOptions<TFeatures, TData>, \"features\">,\n selector?: (state: TableState<TFeatures>) => TSelected\n ) => FuseAppTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;\n /**\n * `createTableHook`'s `useTableContext`, with Fuse's table parts defaulted to `TData`. Pass the\n * row data type to type `table.Content`'s row takeover in a component that reads the table from\n * context.\n */\n useTableContext: <TData extends RowData = RowData, TSelected = TableState<TFeatures>>() => FuseAppTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n >;\n};\n\n/**\n * Erased to the registry constraint: the parts are typed over every stock feature, which TypeScript\n * cannot compare with the app's `TFeatures`, so the factory retypes them with one cast.\n */\n// oxlint-disable-next-line anti-slop/no-known-value-widening -- deliberate erasure; see above\nconst FUSE_TABLE_COMPONENTS: ComponentRegistry = {\n Content: RegisteredContent,\n Row: RegisteredRow,\n Pagination: RegisteredPagination,\n ColumnToggle: RegisteredColumnToggle,\n};\n\nconst FUSE_HEADER_COMPONENTS = { SortButton: RegisteredSortButton };\n\nconst FUSE_CELL_COMPONENTS: FuseCellComponents = {\n TextCell,\n NumberCell,\n CurrencyCell,\n DateCell,\n DateTimeCell,\n};\n\n/** Fuse's parts first, then the app's, so the app wins by key at runtime, as `Merge` describes. */\nfunction mergeRegistry<TFuse extends ComponentRegistry, TApp extends ComponentRegistry>(\n fuse: TFuse,\n app: TApp | undefined\n): Merge<TFuse, TApp> {\n // SAFETY: an omitted registry option leaves `TApp` at its `NoComponents` default, which the\n // empty registry is. Only explicit type arguments without the option break this.\n return { ...fuse, ...(app ?? ({} as TApp)) };\n}\n\n/**\n * Bind an app's table features, default options and components into one `useFuseTable` hook, with\n * Fuse's parts registered: `table.Content`, `table.Row`, `table.Pagination`,\n * `table.ColumnToggle`, `header.SortButton` and the default cells `TextCell`, `NumberCell`,\n * `CurrencyCell`, `DateCell` and `DateTimeCell`.\n *\n * It wraps TanStack's `createTableHook` and passes `features` and every default option through\n * untouched; Fuse adds no features of its own. The app's components are registered after Fuse's,\n * so registering `cellComponents: { NumberCell }` replaces Fuse's `NumberCell`, props included. A\n * registered part appears in the types only when its feature is in `features`: `Pagination` needs\n * `rowPaginationFeature`, `ColumnToggle` `columnVisibilityFeature` and `SortButton`\n * `rowSortingFeature`. Render the registered table parts inside `<table.AppTable>`.\n *\n * @example\n * ```tsx\n * export const { useAppTable: useFuseTable, createAppColumnHelper } = createFuseTableHook({\n * features: tableFeatures({ rowPaginationFeature, rowSortingFeature }),\n * enableSortingRemoval: false,\n * cellComponents: { OrderIdCell },\n * });\n * ```\n *\n * @template TFeatures - The app's `tableFeatures({...})` object.\n * @template TTableComponents - The app's table components.\n * @template TCellComponents - The app's cell components.\n * @template THeaderComponents - The app's header components.\n * @param options - Features, default table options and the app's components.\n * @returns TanStack's table hook result, typed with Fuse's parts merged under the app's.\n */\nexport function createFuseTableHook<\n TFeatures extends TableFeatures,\n const TTableComponents extends TableRegistry<TFeatures> = NoComponents,\n const TCellComponents extends ComponentRegistry = NoComponents,\n const THeaderComponents extends ComponentRegistry = NoComponents,\n>(\n options: CreateFuseTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents>\n): CreateFuseTableHookResult<TFeatures, TTableComponents, TCellComponents, THeaderComponents> {\n // SAFETY: Fuse's parts read the context table typed over every stock feature, and a registered\n // part reads a feature's members only when its public type is present. The public type lists\n // Pagination and ColumnToggle only with their feature and types rows and columns over the app's\n // `TFeatures`, which TanStack's feature-mapped `Row` and `Column` keep TypeScript from relating\n // to the stock features.\n const fuseTableComponents = FUSE_TABLE_COMPONENTS as FuseTableComponents<TFeatures>;\n // The header part's props name no feature, so it satisfies either branch of `WithFeature`.\n const fuseHeaderComponents: FuseHeaderComponents<TFeatures> = FUSE_HEADER_COMPONENTS;\n return createTableHook({\n ...options,\n tableContext: fuseTableContexts.tableContext,\n cellContext: fuseTableContexts.cellContext,\n headerContext: fuseTableContexts.headerContext,\n tableComponents: mergeRegistry(fuseTableComponents, options.tableComponents),\n cellComponents: mergeRegistry(FUSE_CELL_COMPONENTS, options.cellComponents),\n headerComponents: mergeRegistry(fuseHeaderComponents, options.headerComponents),\n });\n}\n"],"mappings":";;;;;;;;;AA8MA,MAAM,wBAA2C;CAC/C,SAAS;CACT,KAAK;CACL,YAAY;CACZ,cAAc;AAChB;AAEA,MAAM,yBAAyB,EAAE,YAAY,qBAAqB;AAElE,MAAM,uBAA2C;CAC/C;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAS,cACP,MACA,KACoB;CAGpB,OAAO;EAAE,GAAG;EAAM,GAAI,OAAQ,CAAC;CAAY;AAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,oBAMd,SAC4F;CAM5F,MAAM,sBAAsB;CAE5B,MAAM,uBAAwD;CAC9D,OAAO,gBAAgB;EACrB,GAAG;EACH,cAAc,kBAAkB;EAChC,aAAa,kBAAkB;EAC/B,eAAe,kBAAkB;EACjC,iBAAiB,cAAc,qBAAqB,QAAQ,eAAe;EAC3E,gBAAgB,cAAc,sBAAsB,QAAQ,cAAc;EAC1E,kBAAkB,cAAc,sBAAsB,QAAQ,gBAAgB;CAChF,CAAC;AACH"}
@@ -0,0 +1,64 @@
1
+ import { DateFormatOptions, DateTimeFormatOptions, NumberFormatOptions } from "./data-table-format.js";
2
+ import { ReactElement } from "react";
3
+ //#region src/components/data-table/data-table-cells.d.ts
4
+ type CellClassName = {
5
+ /** Extra classes, merged last through `cn`. */
6
+ className?: string;
7
+ };
8
+ /** Props for `DataTable.Text`. */
9
+ export type DataTableTextProps = CellClassName & {
10
+ /** The text to render. */
11
+ value: string;
12
+ };
13
+ /** Props for `DataTable.Number`. */
14
+ export type DataTableNumberProps = CellClassName & NumberFormatOptions & {
15
+ /** The number to format for the active locale. */
16
+ value: number;
17
+ };
18
+ /** Props for `DataTable.Currency`. */
19
+ export type DataTableCurrencyProps = CellClassName & NumberFormatOptions & {
20
+ /** The amount to format for the active locale. */
21
+ value: number;
22
+ /** The ISO 4217 currency code, such as `"NOK"`. Required: there is no sensible default. */
23
+ currency: string;
24
+ };
25
+ /** Props for `DataTable.Date`. */
26
+ export type DataTableDateProps = CellClassName & DateFormatOptions & {
27
+ /** The date to format for the active locale. */
28
+ value: Date;
29
+ };
30
+ /** Props for `DataTable.DateTime`. */
31
+ export type DataTableDateTimeProps = CellClassName & DateTimeFormatOptions & {
32
+ /** The date and time to format for the active locale. */
33
+ value: Date;
34
+ };
35
+ /** A text cell. */
36
+ export declare function DataTableText({ value, className }: DataTableTextProps): ReactElement;
37
+ export declare namespace DataTableText {
38
+ var displayName: string;
39
+ }
40
+ /** A number cell, formatted for the active locale with tabular figures. */
41
+ export declare function DataTableNumber({ value, className, ...options }: DataTableNumberProps): ReactElement;
42
+ export declare namespace DataTableNumber {
43
+ var displayName: string;
44
+ }
45
+ /** An amount in a currency, formatted for the active locale with tabular figures. */
46
+ export declare function DataTableCurrency({ value, currency, className, ...options }: DataTableCurrencyProps): ReactElement;
47
+ export declare namespace DataTableCurrency {
48
+ var displayName: string;
49
+ }
50
+ /** A date, formatted for the active locale. `dateStyle` defaults to `"medium"`. */
51
+ export declare function DataTableDate({ value, className, dateStyle, ...options }: DataTableDateProps): ReactElement;
52
+ export declare namespace DataTableDate {
53
+ var displayName: string;
54
+ }
55
+ /**
56
+ * A date and time, formatted for the active locale. `dateStyle` defaults to `"medium"` and
57
+ * `timeStyle` to `"short"`.
58
+ */
59
+ export declare function DataTableDateTime({ value, className, dateStyle, timeStyle, ...options }: DataTableDateTimeProps): ReactElement;
60
+ export declare namespace DataTableDateTime {
61
+ var displayName: string;
62
+ }
63
+ //#endregion
64
+ //# sourceMappingURL=data-table-cells.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-cells.d.ts","names":[],"sources":["../../../src/components/data-table/data-table-cells.tsx"],"mappings":";;;KAYK;;EAEH;;;YAIU,qBAAqB;;EAE/B;;;YAIU,uBAAuB,gBACjC;;EAEE;;;YAIQ,yBAAyB,gBACnC;;EAEE;;EAEA;;;YAIQ,qBAAqB,gBAC/B;;EAEE,OAAO;;;YAIC,yBAAyB,gBACnC;;EAEE,OAAO;;;wBAIK,gBAAgB,OAAO,aAAa,qBAAqB;yBAAzD;MAAA;;;wBASA,kBAAkB,OAAO,cAAc,WAAW,uBAAuB;yBAAzE;MAAA;;;wBAUA,oBACd,OACA,UACA,cACG,WACF,yBAAyB;yBALZ;MAAA;;;wBAeA,gBACd,OACA,WACA,cACG,WACF,qBAAqB;yBALR;MAAA;;;;;;wBAkBA,oBACd,OACA,WACA,WACA,cACG,WACF,yBAAyB;yBANZ;MAAA"}
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ import { cn } from "../../styles/cn.js";
3
+ import { useLocale } from "../../intl/locale-context.js";
4
+ import { dataTableVariants } from "./data-table-variants.js";
5
+ import { formatCurrencyCell, formatDateCell, formatNumberCell } from "./data-table-format.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ //#region src/components/data-table/data-table-cells.tsx
8
+ const { cellNumber } = dataTableVariants();
9
+ /** A text cell. */
10
+ function DataTableText({ value, className }) {
11
+ return /* @__PURE__ */ jsx("span", {
12
+ "data-slot": "data-table-text",
13
+ className,
14
+ children: value
15
+ });
16
+ }
17
+ /** A number cell, formatted for the active locale with tabular figures. */
18
+ function DataTableNumber({ value, className, ...options }) {
19
+ const { locale } = useLocale();
20
+ return /* @__PURE__ */ jsx("span", {
21
+ "data-slot": "data-table-number",
22
+ className: cn(cellNumber(), className),
23
+ children: formatNumberCell(locale, value, options)
24
+ });
25
+ }
26
+ /** An amount in a currency, formatted for the active locale with tabular figures. */
27
+ function DataTableCurrency({ value, currency, className, ...options }) {
28
+ const { locale } = useLocale();
29
+ return /* @__PURE__ */ jsx("span", {
30
+ "data-slot": "data-table-currency",
31
+ className: cn(cellNumber(), className),
32
+ children: formatCurrencyCell(locale, value, currency, options)
33
+ });
34
+ }
35
+ /** A date, formatted for the active locale. `dateStyle` defaults to `"medium"`. */
36
+ function DataTableDate({ value, className, dateStyle = "medium", ...options }) {
37
+ const { locale } = useLocale();
38
+ return /* @__PURE__ */ jsx("span", {
39
+ "data-slot": "data-table-date",
40
+ className,
41
+ children: formatDateCell(locale, value, {
42
+ dateStyle,
43
+ ...options
44
+ })
45
+ });
46
+ }
47
+ /**
48
+ * A date and time, formatted for the active locale. `dateStyle` defaults to `"medium"` and
49
+ * `timeStyle` to `"short"`.
50
+ */
51
+ function DataTableDateTime({ value, className, dateStyle = "medium", timeStyle = "short", ...options }) {
52
+ const { locale } = useLocale();
53
+ return /* @__PURE__ */ jsx("span", {
54
+ "data-slot": "data-table-date-time",
55
+ className,
56
+ children: formatDateCell(locale, value, {
57
+ dateStyle,
58
+ timeStyle,
59
+ ...options
60
+ })
61
+ });
62
+ }
63
+ DataTableText.displayName = "DataTable.Text";
64
+ DataTableNumber.displayName = "DataTable.Number";
65
+ DataTableCurrency.displayName = "DataTable.Currency";
66
+ DataTableDate.displayName = "DataTable.Date";
67
+ DataTableDateTime.displayName = "DataTable.DateTime";
68
+ //#endregion
69
+ export { DataTableCurrency, DataTableDate, DataTableDateTime, DataTableNumber, DataTableText };
70
+
71
+ //# sourceMappingURL=data-table-cells.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-cells.js","names":[],"sources":["../../../src/components/data-table/data-table-cells.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactElement } from \"react\";\n\nimport { useLocale } from \"../../intl/locale-context\";\nimport { cn } from \"../../styles/cn\";\nimport { formatCurrencyCell, formatDateCell, formatNumberCell } from \"./data-table-format\";\nimport type { DateFormatOptions, DateTimeFormatOptions, NumberFormatOptions } from \"./data-table-format\";\nimport { dataTableVariants } from \"./data-table-variants\";\n\nconst { cellNumber } = dataTableVariants();\n\ntype CellClassName = {\n /** Extra classes, merged last through `cn`. */\n className?: string;\n};\n\n/** Props for `DataTable.Text`. */\nexport type DataTableTextProps = CellClassName & {\n /** The text to render. */\n value: string;\n};\n\n/** Props for `DataTable.Number`. */\nexport type DataTableNumberProps = CellClassName &\n NumberFormatOptions & {\n /** The number to format for the active locale. */\n value: number;\n };\n\n/** Props for `DataTable.Currency`. */\nexport type DataTableCurrencyProps = CellClassName &\n NumberFormatOptions & {\n /** The amount to format for the active locale. */\n value: number;\n /** The ISO 4217 currency code, such as `\"NOK\"`. Required: there is no sensible default. */\n currency: string;\n };\n\n/** Props for `DataTable.Date`. */\nexport type DataTableDateProps = CellClassName &\n DateFormatOptions & {\n /** The date to format for the active locale. */\n value: Date;\n };\n\n/** Props for `DataTable.DateTime`. */\nexport type DataTableDateTimeProps = CellClassName &\n DateTimeFormatOptions & {\n /** The date and time to format for the active locale. */\n value: Date;\n };\n\n/** A text cell. */\nexport function DataTableText({ value, className }: DataTableTextProps): ReactElement {\n return (\n <span data-slot=\"data-table-text\" className={className}>\n {value}\n </span>\n );\n}\n\n/** A number cell, formatted for the active locale with tabular figures. */\nexport function DataTableNumber({ value, className, ...options }: DataTableNumberProps): ReactElement {\n const { locale } = useLocale();\n return (\n <span data-slot=\"data-table-number\" className={cn(cellNumber(), className)}>\n {formatNumberCell(locale, value, options)}\n </span>\n );\n}\n\n/** An amount in a currency, formatted for the active locale with tabular figures. */\nexport function DataTableCurrency({\n value,\n currency,\n className,\n ...options\n}: DataTableCurrencyProps): ReactElement {\n const { locale } = useLocale();\n return (\n <span data-slot=\"data-table-currency\" className={cn(cellNumber(), className)}>\n {formatCurrencyCell(locale, value, currency, options)}\n </span>\n );\n}\n\n/** A date, formatted for the active locale. `dateStyle` defaults to `\"medium\"`. */\nexport function DataTableDate({\n value,\n className,\n dateStyle = \"medium\",\n ...options\n}: DataTableDateProps): ReactElement {\n const { locale } = useLocale();\n return (\n <span data-slot=\"data-table-date\" className={className}>\n {formatDateCell(locale, value, { dateStyle, ...options })}\n </span>\n );\n}\n\n/**\n * A date and time, formatted for the active locale. `dateStyle` defaults to `\"medium\"` and\n * `timeStyle` to `\"short\"`.\n */\nexport function DataTableDateTime({\n value,\n className,\n dateStyle = \"medium\",\n timeStyle = \"short\",\n ...options\n}: DataTableDateTimeProps): ReactElement {\n const { locale } = useLocale();\n return (\n <span data-slot=\"data-table-date-time\" className={className}>\n {formatDateCell(locale, value, { dateStyle, timeStyle, ...options })}\n </span>\n );\n}\n\nDataTableText.displayName = \"DataTable.Text\";\nDataTableNumber.displayName = \"DataTable.Number\";\nDataTableCurrency.displayName = \"DataTable.Currency\";\nDataTableDate.displayName = \"DataTable.Date\";\nDataTableDateTime.displayName = \"DataTable.DateTime\";\n"],"mappings":";;;;;;;AAUA,MAAM,EAAE,eAAe,kBAAkB;;AA4CzC,SAAgB,cAAc,EAAE,OAAO,aAA+C;CACpF,OACE,oBAAC,QAAD;EAAM,aAAU;EAA6B;EAC1C,UAAA;CACG,CAAA;AAEV;;AAGA,SAAgB,gBAAgB,EAAE,OAAO,WAAW,GAAG,WAA+C;CACpG,MAAM,EAAE,WAAW,UAAU;CAC7B,OACE,oBAAC,QAAD;EAAM,aAAU;EAAoB,WAAW,GAAG,WAAW,GAAG,SAAS;EACtE,UAAA,iBAAiB,QAAQ,OAAO,OAAO;CACpC,CAAA;AAEV;;AAGA,SAAgB,kBAAkB,EAChC,OACA,UACA,WACA,GAAG,WACoC;CACvC,MAAM,EAAE,WAAW,UAAU;CAC7B,OACE,oBAAC,QAAD;EAAM,aAAU;EAAsB,WAAW,GAAG,WAAW,GAAG,SAAS;EACxE,UAAA,mBAAmB,QAAQ,OAAO,UAAU,OAAO;CAChD,CAAA;AAEV;;AAGA,SAAgB,cAAc,EAC5B,OACA,WACA,YAAY,UACZ,GAAG,WACgC;CACnC,MAAM,EAAE,WAAW,UAAU;CAC7B,OACE,oBAAC,QAAD;EAAM,aAAU;EAA6B;EAC1C,UAAA,eAAe,QAAQ,OAAO;GAAE;GAAW,GAAG;EAAQ,CAAC;CACpD,CAAA;AAEV;;;;;AAMA,SAAgB,kBAAkB,EAChC,OACA,WACA,YAAY,UACZ,YAAY,SACZ,GAAG,WACoC;CACvC,MAAM,EAAE,WAAW,UAAU;CAC7B,OACE,oBAAC,QAAD;EAAM,aAAU;EAAkC;EAC/C,UAAA,eAAe,QAAQ,OAAO;GAAE;GAAW;GAAW,GAAG;EAAQ,CAAC;CAC/D,CAAA;AAEV;AAEA,cAAc,cAAc;AAC5B,gBAAgB,cAAc;AAC9B,kBAAkB,cAAc;AAChC,cAAc,cAAc;AAC5B,kBAAkB,cAAc"}
@@ -0,0 +1,28 @@
1
+ import { ButtonProps } from "../button/button.js";
2
+ import { ColumnToggleSource, VisibilityColumnSource } from "./data-table-source.js";
3
+ import { DropdownMenuTrigger } from "../dropdown-menu/dropdown-menu.js";
4
+ import { ComponentProps, ReactElement, ReactNode } from "react";
5
+ //#region src/components/data-table/data-table-column-toggle.d.ts
6
+ /** Props for `DataTable.ColumnToggle`. */
7
+ export type DataTableColumnToggleProps<TColumn extends VisibilityColumnSource> = Omit<ComponentProps<typeof DropdownMenuTrigger>, "children" | "render"> & {
8
+ /** The trigger button's look. Defaults to `"outline"`. */
9
+ variant?: ButtonProps["variant"];
10
+ /** The table, from `useTable` with `columnVisibilityFeature`. */
11
+ table: ColumnToggleSource<TColumn>;
12
+ /**
13
+ * A column's menu label. Defaults to the column id. Fuse reads no `columnDef.meta` field, since
14
+ * augmenting TanStack's global `ColumnMeta` would clash with an app's own declaration.
15
+ */
16
+ getLabel?: (column: TColumn) => ReactNode;
17
+ /** The trigger's visible text. Defaults to the locale dictionary. */
18
+ label?: string;
19
+ };
20
+ /**
21
+ * A menu of checkbox items that shows and hides every column whose `getCanHide()` is true.
22
+ */
23
+ export declare function DataTableColumnToggle<TColumn extends VisibilityColumnSource>({ table, getLabel, label, variant, ...props }: DataTableColumnToggleProps<TColumn>): ReactElement;
24
+ export declare namespace DataTableColumnToggle {
25
+ var displayName: string;
26
+ }
27
+ //#endregion
28
+ //# sourceMappingURL=data-table-column-toggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-column-toggle.d.ts","names":[],"sources":["../../../src/components/data-table/data-table-column-toggle.tsx"],"mappings":";;;;;;YAkBY,2BAA2B,gBAAgB,0BAA0B,KAC/E,sBAAsB;;EAItB,UAAU;;EAEV,OAAO,mBAAmB;;;;;EAK1B,YAAY,QAAQ,YAAY;;EAEhC;;;;;wBAMc,sBAAsB,gBAAgB,0BACpD,OACA,UACA,OACA,YACG,SACF,2BAA2B,WAAW;yBANzB;MAAA"}
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { useLocalizedStrings } from "../../hooks/use-localized-strings.js";
3
+ import { Button } from "../button/button.js";
4
+ import { DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuRoot, DropdownMenuTrigger } from "../dropdown-menu/dropdown-menu.js";
5
+ import { dataTableStrings } from "./intl/index.js";
6
+ import { SlidersHorizontal } from "../../icons/generated/sliders-horizontal.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/components/data-table/data-table-column-toggle.tsx
9
+ /**
10
+ * A menu of checkbox items that shows and hides every column whose `getCanHide()` is true.
11
+ */
12
+ function DataTableColumnToggle({ table, getLabel, label, variant = "outline", ...props }) {
13
+ const strings = useLocalizedStrings(dataTableStrings);
14
+ return /* @__PURE__ */ jsxs(DropdownMenuRoot, { children: [/* @__PURE__ */ jsxs(DropdownMenuTrigger, {
15
+ "data-slot": "data-table-column-toggle",
16
+ render: /* @__PURE__ */ jsx(Button, {
17
+ variant,
18
+ size: "sm"
19
+ }),
20
+ ...props,
21
+ children: [/* @__PURE__ */ jsx(SlidersHorizontal, {
22
+ "aria-hidden": "true",
23
+ "data-icon": "inline-start"
24
+ }), label ?? strings.format("columns")]
25
+ }), /* @__PURE__ */ jsx(DropdownMenuContent, {
26
+ align: "end",
27
+ children: table.getAllLeafColumns().filter((column) => column.getCanHide()).map((column) => /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
28
+ checked: column.getIsVisible(),
29
+ onCheckedChange: (checked) => {
30
+ column.toggleVisibility(checked);
31
+ },
32
+ children: getLabel?.(column) ?? column.id
33
+ }, column.id))
34
+ })] });
35
+ }
36
+ DataTableColumnToggle.displayName = "DataTable.ColumnToggle";
37
+ //#endregion
38
+ export { DataTableColumnToggle };
39
+
40
+ //# sourceMappingURL=data-table-column-toggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-column-toggle.js","names":[],"sources":["../../../src/components/data-table/data-table-column-toggle.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps, ReactElement, ReactNode } from \"react\";\n\nimport { useLocalizedStrings } from \"../../hooks/use-localized-strings\";\nimport { SlidersHorizontal } from \"../../icons/generated/sliders-horizontal\";\nimport { Button } from \"../button/button\";\nimport type { ButtonProps } from \"../button/button\";\nimport {\n DropdownMenuCheckboxItem,\n DropdownMenuContent,\n DropdownMenuRoot,\n DropdownMenuTrigger,\n} from \"../dropdown-menu/dropdown-menu\";\nimport type { ColumnToggleSource, VisibilityColumnSource } from \"./data-table-source\";\nimport { dataTableStrings } from \"./intl\";\n\n/** Props for `DataTable.ColumnToggle`. */\nexport type DataTableColumnToggleProps<TColumn extends VisibilityColumnSource> = Omit<\n ComponentProps<typeof DropdownMenuTrigger>,\n \"children\" | \"render\"\n> & {\n /** The trigger button's look. Defaults to `\"outline\"`. */\n variant?: ButtonProps[\"variant\"];\n /** The table, from `useTable` with `columnVisibilityFeature`. */\n table: ColumnToggleSource<TColumn>;\n /**\n * A column's menu label. Defaults to the column id. Fuse reads no `columnDef.meta` field, since\n * augmenting TanStack's global `ColumnMeta` would clash with an app's own declaration.\n */\n getLabel?: (column: TColumn) => ReactNode;\n /** The trigger's visible text. Defaults to the locale dictionary. */\n label?: string;\n};\n\n/**\n * A menu of checkbox items that shows and hides every column whose `getCanHide()` is true.\n */\nexport function DataTableColumnToggle<TColumn extends VisibilityColumnSource>({\n table,\n getLabel,\n label,\n variant = \"outline\",\n ...props\n}: DataTableColumnToggleProps<TColumn>): ReactElement {\n const strings = useLocalizedStrings(dataTableStrings);\n return (\n <DropdownMenuRoot>\n <DropdownMenuTrigger\n data-slot=\"data-table-column-toggle\"\n render={<Button variant={variant} size=\"sm\" />}\n {...props}>\n <SlidersHorizontal aria-hidden=\"true\" data-icon=\"inline-start\" />\n {label ?? strings.format(\"columns\")}\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n {table\n .getAllLeafColumns()\n .filter((column) => column.getCanHide())\n .map((column) => (\n <DropdownMenuCheckboxItem\n key={column.id}\n checked={column.getIsVisible()}\n onCheckedChange={(checked) => {\n column.toggleVisibility(checked);\n }}>\n {getLabel?.(column) ?? column.id}\n </DropdownMenuCheckboxItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenuRoot>\n );\n}\n\nDataTableColumnToggle.displayName = \"DataTable.ColumnToggle\";\n"],"mappings":";;;;;;;;;;;AAsCA,SAAgB,sBAA8D,EAC5E,OACA,UACA,OACA,UAAU,WACV,GAAG,SACiD;CACpD,MAAM,UAAU,oBAAoB,gBAAgB;CACpD,OACE,qBAAC,kBAAD,EAAA,UAAA,CACE,qBAAC,qBAAD;EACE,aAAU;EACV,QAAQ,oBAAC,QAAD;GAAiB;GAAS,MAAK;EAAM,CAAA;EAC7C,GAAI;EAHN,UAAA,CAIE,oBAAC,mBAAD;GAAmB,eAAY;GAAO,aAAU;EAAgB,CAAA,GAC/D,SAAS,QAAQ,OAAO,SAAS,CACf;CACrB,CAAA,GAAA,oBAAC,qBAAD;EAAqB,OAAM;EACxB,UAAA,MACE,kBAAkB,CAAC,CACnB,QAAQ,WAAW,OAAO,WAAW,CAAC,CAAC,CACvC,KAAK,WACJ,oBAAC,0BAAD;GAEE,SAAS,OAAO,aAAa;GAC7B,kBAAkB,YAAY;IAC5B,OAAO,iBAAiB,OAAO;GACjC;GACC,UAAA,WAAW,MAAM,KAAK,OAAO;EACN,GANnB,OAAO,EAMY,CAC3B;CACgB,CAAA,CACL,EAAA,CAAA;AAEtB;AAEA,sBAAsB,cAAc"}
@@ -0,0 +1,14 @@
1
+ import { StockFeatures } from "@tanstack/react-table";
2
+ //#region src/components/data-table/data-table-contexts.d.ts
3
+ /**
4
+ * Fuse's own table, header and cell contexts, passed to every `createTableHook` call Fuse makes.
5
+ * They isolate the registered parts from an app that also calls `createTableHook` with TanStack's
6
+ * shared default contexts. One module-level set is enough: a nested Fuse table's provider shadows
7
+ * the outer one, which is right for the parts rendered inside it.
8
+ *
9
+ * The hooks are typed with every stock feature. A registered part reads a feature's members only
10
+ * when its public type is present, which the factory ties to that feature being registered.
11
+ */
12
+ export declare const fuseTableContexts: import("@tanstack/react-table").TableHookContexts<StockFeatures, import("@tanstack/react-table").RowData>;
13
+ //#endregion
14
+ //# sourceMappingURL=data-table-contexts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-contexts.d.ts","names":[],"sources":["../../../src/components/data-table/data-table-contexts.ts"],"mappings":";;;;;;;;;;;qBAca,mDAAiB,kBAAA,+CAAA"}
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { createTableHookContexts } from "@tanstack/react-table";
3
+ //#region src/components/data-table/data-table-contexts.ts
4
+ /**
5
+ * Fuse's own table, header and cell contexts, passed to every `createTableHook` call Fuse makes.
6
+ * They isolate the registered parts from an app that also calls `createTableHook` with TanStack's
7
+ * shared default contexts. One module-level set is enough: a nested Fuse table's provider shadows
8
+ * the outer one, which is right for the parts rendered inside it.
9
+ *
10
+ * The hooks are typed with every stock feature. A registered part reads a feature's members only
11
+ * when its public type is present, which the factory ties to that feature being registered.
12
+ */
13
+ const fuseTableContexts = createTableHookContexts();
14
+ //#endregion
15
+ export { fuseTableContexts };
16
+
17
+ //# sourceMappingURL=data-table-contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-contexts.js","names":[],"sources":["../../../src/components/data-table/data-table-contexts.ts"],"sourcesContent":["\"use client\";\n\nimport { createTableHookContexts } from \"@tanstack/react-table\";\nimport type { StockFeatures } from \"@tanstack/react-table\";\n\n/**\n * Fuse's own table, header and cell contexts, passed to every `createTableHook` call Fuse makes.\n * They isolate the registered parts from an app that also calls `createTableHook` with TanStack's\n * shared default contexts. One module-level set is enough: a nested Fuse table's provider shadows\n * the outer one, which is right for the parts rendered inside it.\n *\n * The hooks are typed with every stock feature. A registered part reads a feature's members only\n * when its public type is present, which the factory ties to that feature being registered.\n */\nexport const fuseTableContexts = createTableHookContexts<StockFeatures>();\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,oBAAoB,wBAAuC"}