@tsed/react-formio 3.0.0-rc.16 → 3.0.0-rc.17
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/dist/molecules/table/filters/TextFieldFilter.js +15 -15
- package/dist/molecules/table/filters/TextFieldFilter.js.map +1 -1
- package/dist/molecules/table/hooks/useTable.d.ts +1 -1
- package/dist/molecules/table/hooks/useTable.js +14 -14
- package/dist/molecules/table/hooks/useTable.js.map +1 -1
- package/package.json +3 -3
- package/src/molecules/table/Table.stories.tsx +4 -1
- package/src/molecules/table/filters/TextFieldFilter.tsx +4 -2
- package/src/molecules/table/hooks/useTable.tsx +5 -10
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsxs as r, Fragment as
|
|
2
|
-
import { registerComponent as
|
|
1
|
+
import { jsxs as r, Fragment as c, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { registerComponent as m, getComponent as d } from "../../../registries/components.js";
|
|
3
3
|
import { useUniqValues as p } from "../hooks/useUniqValues.js";
|
|
4
|
-
function F({ header:
|
|
5
|
-
const o = d("InputText"),
|
|
6
|
-
return /* @__PURE__ */ r(
|
|
7
|
-
!
|
|
8
|
-
/* @__PURE__ */
|
|
4
|
+
function F({ header: l, options: n }) {
|
|
5
|
+
const o = d("InputText"), u = l.column.getFilterValue(), a = p({ header: l }), i = `data_list_${l.column.id}`;
|
|
6
|
+
return /* @__PURE__ */ r(c, { children: [
|
|
7
|
+
!n.disableDatalist && /* @__PURE__ */ e("datalist", { id: i, children: a.map((t) => /* @__PURE__ */ e("option", { value: t.value, children: t.label || t.value }, t.value)) }),
|
|
8
|
+
/* @__PURE__ */ e(
|
|
9
9
|
o,
|
|
10
10
|
{
|
|
11
11
|
size: "small",
|
|
12
|
-
placeholder: `Filter by ${
|
|
13
|
-
...
|
|
14
|
-
name: `filter_${
|
|
15
|
-
"data-testid": `filter_${
|
|
16
|
-
value:
|
|
17
|
-
list:
|
|
18
|
-
onChange: (
|
|
12
|
+
placeholder: `Filter by ${l.column.columnDef.header}`,
|
|
13
|
+
...n,
|
|
14
|
+
name: `filter_${l.column.id}`,
|
|
15
|
+
"data-testid": `filter_${l.column.id}`,
|
|
16
|
+
value: u ?? "",
|
|
17
|
+
list: i,
|
|
18
|
+
onChange: (t, s) => l.column.setFilterValue(s)
|
|
19
19
|
}
|
|
20
20
|
)
|
|
21
21
|
] });
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
m("Filter.text", F);
|
|
24
24
|
export {
|
|
25
25
|
F as TextFieldFilter
|
|
26
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextFieldFilter.js","sources":["../../../../src/molecules/table/filters/TextFieldFilter.tsx"],"sourcesContent":["import { getComponent, registerComponent } from \"../../../registries/components\";\nimport type { InputText as DefaultInputText } from \"../../forms/input-text/InputText\";\nimport type { FilterProps } from \"../components/DefaultFilter\";\nimport { useUniqValues } from \"../hooks/useUniqValues\";\nimport { FilterTextOptions } from \"./Filters\";\n\nexport function TextFieldFilter<Data = any>({ header, options }: FilterProps<Data, FilterTextOptions>) {\n const InputText = getComponent<typeof DefaultInputText>(\"InputText\");\n const columnFilterValue = header.column.getFilterValue();\n const uniqValues = useUniqValues<Data>({ header });\n const datalistId = `data_list_${header.column.id}`;\n\n return (\n <>\n {!options.disableDatalist && (\n <datalist id={datalistId}>\n {uniqValues.map((
|
|
1
|
+
{"version":3,"file":"TextFieldFilter.js","sources":["../../../../src/molecules/table/filters/TextFieldFilter.tsx"],"sourcesContent":["import { getComponent, registerComponent } from \"../../../registries/components\";\nimport type { InputText as DefaultInputText } from \"../../forms/input-text/InputText\";\nimport type { FilterProps } from \"../components/DefaultFilter\";\nimport { useUniqValues } from \"../hooks/useUniqValues\";\nimport { FilterTextOptions } from \"./Filters\";\n\nexport function TextFieldFilter<Data = any>({ header, options }: FilterProps<Data, FilterTextOptions>) {\n const InputText = getComponent<typeof DefaultInputText>(\"InputText\");\n const columnFilterValue = header.column.getFilterValue();\n const uniqValues = useUniqValues<Data>({ header });\n const datalistId = `data_list_${header.column.id}`;\n\n return (\n <>\n {!options.disableDatalist && (\n <datalist id={datalistId}>\n {uniqValues.map((item) => (\n <option value={item.value} key={item.value}>\n {item.label || item.value}\n </option>\n ))}\n </datalist>\n )}\n <InputText<string>\n size='small'\n placeholder={`Filter by ${header.column.columnDef.header}`}\n {...options}\n name={`filter_${header.column.id}`}\n data-testid={`filter_${header.column.id}`}\n value={(columnFilterValue ?? \"\") as string}\n list={datalistId}\n onChange={(_, value) => header.column.setFilterValue(value)}\n />\n </>\n );\n}\n\nregisterComponent(\"Filter.text\", TextFieldFilter);\n"],"names":["TextFieldFilter","header","options","InputText","getComponent","columnFilterValue","uniqValues","useUniqValues","datalistId","jsxs","Fragment","jsx","item","_","value","registerComponent"],"mappings":";;;AAMO,SAASA,EAA4B,EAAE,QAAAC,GAAQ,SAAAC,KAAiD;AACrG,QAAMC,IAAYC,EAAsC,WAAW,GAC7DC,IAAoBJ,EAAO,OAAO,eAAA,GAClCK,IAAaC,EAAoB,EAAE,QAAAN,GAAQ,GAC3CO,IAAa,aAAaP,EAAO,OAAO,EAAE;AAEhD,SACE,gBAAAQ,EAAAC,GAAA,EACG,UAAA;AAAA,IAAA,CAACR,EAAQ,mBACR,gBAAAS,EAAC,YAAA,EAAS,IAAIH,GACX,UAAAF,EAAW,IAAI,CAACM,MACf,gBAAAD,EAAC,YAAO,OAAOC,EAAK,OACjB,UAAAA,EAAK,SAASA,EAAK,MAAA,GADUA,EAAK,KAErC,CACD,EAAA,CACH;AAAA,IAEF,gBAAAD;AAAA,MAACR;AAAA,MAAA;AAAA,QACC,MAAK;AAAA,QACL,aAAa,aAAaF,EAAO,OAAO,UAAU,MAAM;AAAA,QACvD,GAAGC;AAAA,QACJ,MAAM,UAAUD,EAAO,OAAO,EAAE;AAAA,QAChC,eAAa,UAAUA,EAAO,OAAO,EAAE;AAAA,QACvC,OAAQI,KAAqB;AAAA,QAC7B,MAAMG;AAAA,QACN,UAAU,CAACK,GAAGC,MAAUb,EAAO,OAAO,eAAea,CAAK;AAAA,MAAA;AAAA,IAAA;AAAA,EAC5D,GACF;AAEJ;AAEAC,EAAkB,eAAef,CAAe;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TableOptions, TableState } from '@tanstack/react-table';
|
|
2
2
|
import { FormOptions, Operation } from '../../../interfaces';
|
|
3
3
|
import { JSONRecord } from '../../../interfaces/JSONRecord.js';
|
|
4
|
-
export interface UseTableProps<Data extends object = JSONRecord> extends Omit<TableOptions<Data>, "
|
|
4
|
+
export interface UseTableProps<Data extends object = JSONRecord> extends Omit<TableOptions<Data>, "onClick"> {
|
|
5
5
|
operations: Operation<Data>[];
|
|
6
6
|
metadata?: Record<string, unknown>;
|
|
7
7
|
i18n?: FormOptions["i18n"];
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useReactTable as
|
|
1
|
+
import { jsx as w } from "react/jsx-runtime";
|
|
2
|
+
import { useReactTable as M, getFacetedUniqueValues as s, getFacetedRowModel as f, getSortedRowModel as C, getFilteredRowModel as S, getPaginationRowModel as b, getCoreRowModel as h } from "@tanstack/react-table";
|
|
3
3
|
import { useEffect as v } from "react";
|
|
4
4
|
import { useI18n as O } from "../../../hooks/useI18n.js";
|
|
5
|
-
import { getComponent as
|
|
6
|
-
function
|
|
7
|
-
const n =
|
|
5
|
+
import { getComponent as V } from "../../../registries/components.js";
|
|
6
|
+
function x(e) {
|
|
7
|
+
const n = V("CellOperations"), { t } = O(e.i18n), i = e.operations.length ? [
|
|
8
8
|
{
|
|
9
9
|
id: "operations",
|
|
10
10
|
header: t("Operations"),
|
|
11
|
-
cell: (
|
|
11
|
+
cell: (R) => /* @__PURE__ */ w(n, { info: R, operations: e.operations, metadata: e.metadata, onClick: e.onClick, i18n: t })
|
|
12
12
|
}
|
|
13
|
-
] : [], o =
|
|
13
|
+
] : [], o = M({
|
|
14
14
|
...e,
|
|
15
15
|
columns: [...e.columns, ...i],
|
|
16
16
|
getCoreRowModel: h(),
|
|
17
17
|
getPaginationRowModel: b(),
|
|
18
|
-
getFilteredRowModel: e.manualFiltering ? void 0 : S(),
|
|
19
|
-
getSortedRowModel: e.manualSorting ? void 0 : C(),
|
|
20
|
-
getFacetedRowModel: e.manualFaceted ? void 0 :
|
|
18
|
+
getFilteredRowModel: e.manualFiltering ? void 0 : e.getFilteredRowModel || S(),
|
|
19
|
+
getSortedRowModel: e.manualSorting ? void 0 : e.getSortedRowModel || C(),
|
|
20
|
+
getFacetedRowModel: e.manualFaceted ? void 0 : e.getFacetedRowModel || f(),
|
|
21
21
|
// client-side faceting
|
|
22
|
-
getFacetedUniqueValues: e.manualFaceted ? void 0 :
|
|
22
|
+
getFacetedUniqueValues: e.manualFaceted ? void 0 : e.getFacetedUniqueValues || s()
|
|
23
23
|
// generate unique values for select filter/autocomplete
|
|
24
|
-
}), { columnFilters: a, sorting: l, pagination: d, columnOrder: g, columnPinning: c, columnSizing: m, columnSizingInfo:
|
|
24
|
+
}), { columnFilters: a, sorting: l, pagination: d, columnOrder: g, columnPinning: c, columnSizing: m, columnSizingInfo: u, columnVisibility: r, globalFilter: F } = o.getState();
|
|
25
25
|
return v(() => {
|
|
26
26
|
e.onChange && e.onChange(o.getState());
|
|
27
|
-
}, [a, l, d, g, c, m,
|
|
27
|
+
}, [a, l, d, g, c, m, u, r, F]), {
|
|
28
28
|
i18n: t,
|
|
29
29
|
tableInstance: o
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
33
|
-
|
|
33
|
+
x as useTable
|
|
34
34
|
};
|
|
35
35
|
//# sourceMappingURL=useTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.js","sources":["../../../../src/molecules/table/hooks/useTable.tsx"],"sourcesContent":["import {\n type ColumnDef,\n getCoreRowModel,\n getFacetedRowModel,\n getFacetedUniqueValues,\n getFilteredRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n type TableOptions,\n type TableState,\n useReactTable\n} from \"@tanstack/react-table\";\nimport { useEffect } from \"react\";\n\nimport { useI18n } from \"../../../hooks/useI18n.js\";\nimport { type FormOptions, Operation } from \"../../../interfaces\";\nimport type { JSONRecord } from \"../../../interfaces/JSONRecord.js\";\nimport { getComponent } from \"../../../registries/components\";\nimport type { DefaultCellOperations } from \"../components/DefaultCellOperations\";\n\nexport interface UseTableProps<Data extends object = JSONRecord> extends Omit<TableOptions<Data>, \"
|
|
1
|
+
{"version":3,"file":"useTable.js","sources":["../../../../src/molecules/table/hooks/useTable.tsx"],"sourcesContent":["import {\n type ColumnDef,\n getCoreRowModel,\n getFacetedRowModel,\n getFacetedUniqueValues,\n getFilteredRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n type TableOptions,\n type TableState,\n useReactTable\n} from \"@tanstack/react-table\";\nimport { useEffect } from \"react\";\n\nimport { useI18n } from \"../../../hooks/useI18n.js\";\nimport { type FormOptions, Operation } from \"../../../interfaces\";\nimport type { JSONRecord } from \"../../../interfaces/JSONRecord.js\";\nimport { getComponent } from \"../../../registries/components\";\nimport type { DefaultCellOperations } from \"../components/DefaultCellOperations\";\n\nexport interface UseTableProps<Data extends object = JSONRecord> extends Omit<TableOptions<Data>, \"onClick\"> {\n operations: Operation<Data>[];\n metadata?: Record<string, unknown>;\n i18n?: FormOptions[\"i18n\"];\n onClick?: (data: Data, operation: Operation<Data>) => void;\n manualFaceted?: boolean;\n onChange?: (query: TableState) => void;\n pageSizes?: number[];\n}\n\nexport function useTable<Data extends object = JSONRecord>(props: UseTableProps<Data>) {\n const Operations = getComponent<typeof DefaultCellOperations<Data>>(\"CellOperations\");\n const { t } = useI18n(props.i18n);\n\n const operations = props.operations.length\n ? ([\n {\n id: \"operations\",\n header: t(\"Operations\"),\n cell: (info) => (\n <Operations info={info} operations={props.operations} metadata={props.metadata} onClick={props.onClick} i18n={t} />\n )\n }\n ] satisfies ColumnDef<Data>[])\n : [];\n\n const tableInstance = useReactTable({\n ...props,\n columns: [...props.columns, ...operations],\n getCoreRowModel: getCoreRowModel(),\n getPaginationRowModel: getPaginationRowModel(),\n getFilteredRowModel: !props.manualFiltering ? props.getFilteredRowModel || getFilteredRowModel() : undefined,\n getSortedRowModel: !props.manualSorting ? props.getSortedRowModel || getSortedRowModel() : undefined,\n getFacetedRowModel: !props.manualFaceted ? props.getFacetedRowModel || getFacetedRowModel() : undefined, // client-side faceting\n getFacetedUniqueValues: !props.manualFaceted ? props.getFacetedUniqueValues || getFacetedUniqueValues() : undefined // generate unique values for select filter/autocomplete\n });\n\n const { columnFilters, sorting, pagination, columnOrder, columnPinning, columnSizing, columnSizingInfo, columnVisibility, globalFilter } =\n tableInstance.getState();\n\n useEffect(() => {\n if (props.onChange) {\n props.onChange(tableInstance.getState());\n }\n }, [columnFilters, sorting, pagination, columnOrder, columnPinning, columnSizing, columnSizingInfo, columnVisibility, globalFilter]);\n\n return {\n i18n: t,\n tableInstance\n };\n}\n"],"names":["useTable","props","Operations","getComponent","useI18n","operations","info","jsx","tableInstance","useReactTable","getCoreRowModel","getPaginationRowModel","getFilteredRowModel","getSortedRowModel","getFacetedRowModel","getFacetedUniqueValues","columnFilters","sorting","pagination","columnOrder","columnPinning","columnSizing","columnSizingInfo","columnVisibility","globalFilter","useEffect"],"mappings":";;;;;AA8BO,SAASA,EAA2CC,GAA4B;AACrF,QAAMC,IAAaC,EAAiD,gBAAgB,GAC9E,EAAE,EAAA,IAAMC,EAAQH,EAAM,IAAI,GAE1BI,IAAaJ,EAAM,WAAW,SAC/B;AAAA,IACC;AAAA,MACE,IAAI;AAAA,MACJ,QAAQ,EAAE,YAAY;AAAA,MACtB,MAAM,CAACK,MACL,gBAAAC,EAACL,GAAA,EAAW,MAAAI,GAAY,YAAYL,EAAM,YAAY,UAAUA,EAAM,UAAU,SAASA,EAAM,SAAS,MAAM,EAAA,CAAG;AAAA,IAAA;AAAA,EAErH,IAEF,CAAA,GAEEO,IAAgBC,EAAc;AAAA,IAClC,GAAGR;AAAA,IACH,SAAS,CAAC,GAAGA,EAAM,SAAS,GAAGI,CAAU;AAAA,IACzC,iBAAiBK,EAAA;AAAA,IACjB,uBAAuBC,EAAA;AAAA,IACvB,qBAAsBV,EAAM,kBAAuE,SAArDA,EAAM,uBAAuBW;IAC3E,mBAAoBX,EAAM,gBAAiE,SAAjDA,EAAM,qBAAqBY;IACrE,oBAAqBZ,EAAM,gBAAmE,SAAnDA,EAAM,sBAAsBa;;IACvE,wBAAyBb,EAAM,gBAA2E,SAA3DA,EAAM,0BAA0Bc;;EAA2B,CAC3G,GAEK,EAAE,eAAAC,GAAe,SAAAC,GAAS,YAAAC,GAAY,aAAAC,GAAa,eAAAC,GAAe,cAAAC,GAAc,kBAAAC,GAAkB,kBAAAC,GAAkB,cAAAC,MACxHhB,EAAc,SAAA;AAEhB,SAAAiB,EAAU,MAAM;AACd,IAAIxB,EAAM,YACRA,EAAM,SAASO,EAAc,UAAU;AAAA,EAE3C,GAAG,CAACQ,GAAeC,GAASC,GAAYC,GAAaC,GAAeC,GAAcC,GAAkBC,GAAkBC,CAAY,CAAC,GAE5H;AAAA,IACL,MAAM;AAAA,IACN,eAAAhB;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.17",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@tanstack/react-table": ">=8.20.6",
|
|
47
|
-
"@tsed/tailwind-formio": "3.0.0-rc.
|
|
48
|
-
"@tsed/typescript": "3.0.0-rc.
|
|
47
|
+
"@tsed/tailwind-formio": "3.0.0-rc.17",
|
|
48
|
+
"@tsed/typescript": "3.0.0-rc.17",
|
|
49
49
|
"microbundle": "0.13.0",
|
|
50
50
|
"vite": "7.1.5",
|
|
51
51
|
"vitest": "3.2.4"
|
|
@@ -172,7 +172,10 @@ export const Usage: Story = {
|
|
|
172
172
|
return expect(canvas.queryByText("MPEC")).not.toBeInTheDocument();
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
const tableBody = canvasElement.querySelector("tbody");
|
|
176
|
+
|
|
177
|
+
await expect(tableBody).toBeInTheDocument();
|
|
178
|
+
await expect(within(tableBody as HTMLElement).getByText("La Caravelle")).toBeInTheDocument();
|
|
176
179
|
|
|
177
180
|
await delay(300);
|
|
178
181
|
|
|
@@ -14,8 +14,10 @@ export function TextFieldFilter<Data = any>({ header, options }: FilterProps<Dat
|
|
|
14
14
|
<>
|
|
15
15
|
{!options.disableDatalist && (
|
|
16
16
|
<datalist id={datalistId}>
|
|
17
|
-
{uniqValues.map((
|
|
18
|
-
<option value={value} key={value}
|
|
17
|
+
{uniqValues.map((item) => (
|
|
18
|
+
<option value={item.value} key={item.value}>
|
|
19
|
+
{item.label || item.value}
|
|
20
|
+
</option>
|
|
19
21
|
))}
|
|
20
22
|
</datalist>
|
|
21
23
|
)}
|
|
@@ -18,7 +18,7 @@ import type { JSONRecord } from "../../../interfaces/JSONRecord.js";
|
|
|
18
18
|
import { getComponent } from "../../../registries/components";
|
|
19
19
|
import type { DefaultCellOperations } from "../components/DefaultCellOperations";
|
|
20
20
|
|
|
21
|
-
export interface UseTableProps<Data extends object = JSONRecord> extends Omit<TableOptions<Data>, "
|
|
21
|
+
export interface UseTableProps<Data extends object = JSONRecord> extends Omit<TableOptions<Data>, "onClick"> {
|
|
22
22
|
operations: Operation<Data>[];
|
|
23
23
|
metadata?: Record<string, unknown>;
|
|
24
24
|
i18n?: FormOptions["i18n"];
|
|
@@ -32,11 +32,6 @@ export function useTable<Data extends object = JSONRecord>(props: UseTableProps<
|
|
|
32
32
|
const Operations = getComponent<typeof DefaultCellOperations<Data>>("CellOperations");
|
|
33
33
|
const { t } = useI18n(props.i18n);
|
|
34
34
|
|
|
35
|
-
// const [pagination, setPagination] = useState({
|
|
36
|
-
// pageIndex: 0, //initial page index
|
|
37
|
-
// pageSize: 10 //default page size
|
|
38
|
-
// });
|
|
39
|
-
|
|
40
35
|
const operations = props.operations.length
|
|
41
36
|
? ([
|
|
42
37
|
{
|
|
@@ -54,10 +49,10 @@ export function useTable<Data extends object = JSONRecord>(props: UseTableProps<
|
|
|
54
49
|
columns: [...props.columns, ...operations],
|
|
55
50
|
getCoreRowModel: getCoreRowModel(),
|
|
56
51
|
getPaginationRowModel: getPaginationRowModel(),
|
|
57
|
-
getFilteredRowModel: !props.manualFiltering ? getFilteredRowModel() : undefined,
|
|
58
|
-
getSortedRowModel: !props.manualSorting ? getSortedRowModel() : undefined,
|
|
59
|
-
getFacetedRowModel: !props.manualFaceted ? getFacetedRowModel() : undefined, // client-side faceting
|
|
60
|
-
getFacetedUniqueValues: !props.manualFaceted ? getFacetedUniqueValues() : undefined // generate unique values for select filter/autocomplete
|
|
52
|
+
getFilteredRowModel: !props.manualFiltering ? props.getFilteredRowModel || getFilteredRowModel() : undefined,
|
|
53
|
+
getSortedRowModel: !props.manualSorting ? props.getSortedRowModel || getSortedRowModel() : undefined,
|
|
54
|
+
getFacetedRowModel: !props.manualFaceted ? props.getFacetedRowModel || getFacetedRowModel() : undefined, // client-side faceting
|
|
55
|
+
getFacetedUniqueValues: !props.manualFaceted ? props.getFacetedUniqueValues || getFacetedUniqueValues() : undefined // generate unique values for select filter/autocomplete
|
|
61
56
|
});
|
|
62
57
|
|
|
63
58
|
const { columnFilters, sorting, pagination, columnOrder, columnPinning, columnSizing, columnSizingInfo, columnVisibility, globalFilter } =
|