@ifto/mantine-kit 0.4.0 → 0.5.2

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 (38) hide show
  1. package/README.md +81 -10
  2. package/dist/component/organism/Table/Table.d.ts +9 -9
  3. package/dist/component/organism/Table/Table.js +21 -24
  4. package/dist/component/organism/Table/Table.js.map +1 -1
  5. package/dist/component/organism/Table/TableData.d.ts +24 -0
  6. package/dist/component/organism/Table/TableData.js +1 -0
  7. package/dist/component/organism/Table/useClientPagination.d.ts +21 -0
  8. package/dist/component/organism/Table/useClientPagination.js +43 -0
  9. package/dist/component/organism/Table/useClientPagination.js.map +1 -0
  10. package/dist/component/organism/Table/useServerPagination.d.ts +24 -0
  11. package/dist/component/organism/Table/useServerPagination.js +105 -0
  12. package/dist/component/organism/Table/useServerPagination.js.map +1 -0
  13. package/dist/component/organism/ViewTable/DataTableView.d.ts +39 -0
  14. package/dist/component/organism/ViewTable/DataTableView.js +52 -0
  15. package/dist/component/organism/ViewTable/DataTableView.js.map +1 -0
  16. package/dist/component/organism/ViewTable/TableState.d.ts +30 -0
  17. package/dist/component/organism/ViewTable/TableState.js +19 -0
  18. package/dist/component/organism/ViewTable/TableState.js.map +1 -0
  19. package/dist/component/organism/ViewTable/ViewTable.d.ts +11 -33
  20. package/dist/component/organism/ViewTable/ViewTable.js +16 -101
  21. package/dist/component/organism/ViewTable/ViewTable.js.map +1 -1
  22. package/dist/component/organism/ViewTable/useClientTableState.d.ts +25 -0
  23. package/dist/component/organism/ViewTable/useClientTableState.js +68 -0
  24. package/dist/component/organism/ViewTable/useClientTableState.js.map +1 -0
  25. package/dist/component/template/ListPage/ListPage.d.ts +9 -19
  26. package/dist/component/template/ListPage/ListPage.js +5 -14
  27. package/dist/component/template/ListPage/ListPage.js.map +1 -1
  28. package/dist/data/PageDataSource.d.ts +10 -0
  29. package/dist/data/PageDataSource.js +1 -0
  30. package/dist/data/PageRequest.d.ts +29 -0
  31. package/dist/data/PageRequest.js +1 -0
  32. package/dist/hook/useService.d.ts +3 -3
  33. package/dist/hook/useService.js +2 -0
  34. package/dist/hook/useService.js.map +1 -1
  35. package/dist/util/ArrayUtil.d.ts +4 -3
  36. package/dist/util/ArrayUtil.js +3 -2
  37. package/dist/util/ArrayUtil.js.map +1 -1
  38. package/package.json +1 -1
@@ -7,6 +7,8 @@ function useService(fetchMethod, initialData) {
7
7
  const [loading, setLoading] = useState(true);
8
8
  useEffect(() => {
9
9
  let obsolete = false;
10
+ setLoading(true);
11
+ setError(null);
10
12
  fetchMethod().then((responseData) => !obsolete && setData(responseData)).catch((e) => !obsolete && setError(e)).finally(() => !obsolete && setLoading(false));
11
13
  return () => {
12
14
  obsolete = true;
@@ -1 +1 @@
1
- {"version":3,"file":"useService.js","names":[],"sources":["../../src/hook/useService.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** Values returned by {@link useService}. */\nexport type UseService<D> = {\n /** Data of the fetch, or the initial value while it has not finished (or if it failed). */\n data: D;\n\n /** Error of the fetch; `null` if it has not finished yet or succeeded. */\n error: unknown | null;\n\n /** Whether the fetch has not finished yet. */\n loading: boolean;\n};\n\n/**\n * Fetches data when the component mounts and every time `fetchMethod` changes.\n * Without an initial value, `data` is `undefined` while loading (or after a failure), so the caller must handle it.\n * @param fetchMethod function that fetches the data. It must be stable (e.g. with `useCallback`), since a new function\n * triggers a new fetch\n * @return the data (`undefined` until the fetch finishes), the error and whether the fetch is still running\n */\nfunction useService<T>(fetchMethod: () => Promise<T>): UseService<T | undefined>;\n\n/**\n * Fetches data when the component mounts and every time `fetchMethod` changes, starting with the given value (e.g. an\n * empty array for a list), so `data` always has the type of the fetched data.\n * @param fetchMethod function that fetches the data. It must be stable (e.g. with `useCallback`), since a new function\n * triggers a new fetch\n * @param initialData value of `data` until the fetch finishes (and after a failure)\n * @return the data, the error and whether the fetch is still running\n */\nfunction useService<T>(fetchMethod: () => Promise<T>, initialData: T): UseService<T>;\n\nfunction useService<T>(fetchMethod: () => Promise<T>, initialData?: T): UseService<T | undefined> {\n const [data, setData] = useState<T | undefined>(initialData);\n const [error, setError] = useState<unknown | null>(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n /* When fetchMethod changes (e.g. another filter), the previous fetch becomes obsolete. If its response arrives\n after the one of the new fetch, it cannot overwrite the current data. */\n let obsolete = false;\n fetchMethod()\n .then(responseData => !obsolete && setData(responseData))\n .catch(e => !obsolete && setError(e))\n .finally(() => !obsolete && setLoading(false));\n\n return () => {\n obsolete = true;\n };\n }, [fetchMethod]);\n\n return { data, error, loading };\n}\n\nexport default useService;\n"],"mappings":";;;AAiCA,SAAS,WAAc,aAA+B,aAA4C;CAC9F,MAAM,CAAC,MAAM,WAAW,SAAwB,WAAW;CAC3D,MAAM,CAAC,OAAO,YAAY,SAAyB,IAAI;CACvD,MAAM,CAAC,SAAS,cAAc,SAAS,IAAI;CAE3C,gBAAgB;EAGZ,IAAI,WAAW;EACf,YAAY,CAAC,CACR,MAAK,iBAAgB,CAAC,YAAY,QAAQ,YAAY,CAAC,CAAC,CACxD,OAAM,MAAK,CAAC,YAAY,SAAS,CAAC,CAAC,CAAC,CACpC,cAAc,CAAC,YAAY,WAAW,KAAK,CAAC;EAEjD,aAAa;GACT,WAAW;EACf;CACJ,GAAG,CAAC,WAAW,CAAC;CAEhB,OAAO;EAAE;EAAM;EAAO;CAAQ;AAClC"}
1
+ {"version":3,"file":"useService.js","names":[],"sources":["../../src/hook/useService.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** Values returned by {@link useService}. */\nexport type UseService<D> = {\n /** Data of the last successful fetch, or the initial value if none has finished yet. */\n data: D;\n\n /** Error of the current fetch; `null` if it has not finished yet or succeeded. */\n error: unknown | null;\n\n /** Whether the current fetch has not finished yet. */\n loading: boolean;\n};\n\n/**\n * Fetches data when the component mounts and every time `fetchMethod` changes.\n * Without an initial value, `data` is `undefined` while loading (or after a failure), so the caller must handle it.\n * @param fetchMethod function that fetches the data. It must be stable (e.g. with `useCallback`), since a new function\n * triggers a new fetch\n * @return the data (`undefined` until the fetch finishes), the error and whether the fetch is still running\n */\nfunction useService<T>(fetchMethod: () => Promise<T>): UseService<T | undefined>;\n\n/**\n * Fetches data when the component mounts and every time `fetchMethod` changes, starting with the given value (e.g. an\n * empty array for a list), so `data` always has the type of the fetched data.\n * @param fetchMethod function that fetches the data. It must be stable (e.g. with `useCallback`), since a new function\n * triggers a new fetch\n * @param initialData value of `data` until the fetch finishes (and after a failure)\n * @return the data, the error and whether the fetch is still running\n */\nfunction useService<T>(fetchMethod: () => Promise<T>, initialData: T): UseService<T>;\n\nfunction useService<T>(fetchMethod: () => Promise<T>, initialData?: T): UseService<T | undefined> {\n const [data, setData] = useState<T | undefined>(initialData);\n const [error, setError] = useState<unknown | null>(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n /* When fetchMethod changes (e.g. another filter), the previous fetch becomes obsolete. If its response arrives\n after the one of the new fetch, it cannot overwrite the current data. */\n let obsolete = false;\n setLoading(true);\n setError(null);\n fetchMethod()\n .then(responseData => !obsolete && setData(responseData))\n .catch(e => !obsolete && setError(e))\n .finally(() => !obsolete && setLoading(false));\n\n return () => {\n obsolete = true;\n };\n }, [fetchMethod]);\n\n return { data, error, loading };\n}\n\nexport default useService;\n"],"mappings":";;;AAiCA,SAAS,WAAc,aAA+B,aAA4C;CAC9F,MAAM,CAAC,MAAM,WAAW,SAAwB,WAAW;CAC3D,MAAM,CAAC,OAAO,YAAY,SAAyB,IAAI;CACvD,MAAM,CAAC,SAAS,cAAc,SAAS,IAAI;CAE3C,gBAAgB;EAGZ,IAAI,WAAW;EACf,WAAW,IAAI;EACf,SAAS,IAAI;EACb,YAAY,CAAC,CACR,MAAK,iBAAgB,CAAC,YAAY,QAAQ,YAAY,CAAC,CAAC,CACxD,OAAM,MAAK,CAAC,YAAY,SAAS,CAAC,CAAC,CAAC,CACpC,cAAc,CAAC,YAAY,WAAW,KAAK,CAAC;EAEjD,aAAa;GACT,WAAW;EACf;CACJ,GAAG,CAAC,WAAW,CAAC;CAEhB,OAAO;EAAE;EAAM;EAAO;CAAQ;AAClC"}
@@ -29,11 +29,12 @@ export type NumbersMapFunction = (number1: number, number2: number) => number;
29
29
  export declare function arraysMap(array1: number[], array2: number[], operation: NumbersMapFunction, defaultItemValue?: number): number[];
30
30
  /**
31
31
  * Transposes a matrix, turning the rows into columns and vice versa.
32
- * @param matrix matrix to transpose, where each row is an array of values
32
+ * @param matrix matrix to transpose, where each row is an array of values of any type
33
33
  * @param defaultValForUndefinedCol value used when a row has no value for a column, which happens when the rows have
34
- * different sizes. Without it, the missing column is `undefined`. The parameter has no default value on purpose:
34
+ * different sizes. It also replaces an element that is already `undefined` or `null` in the matrix. Without it,
35
+ * the missing column is `undefined`. The parameter has no default value on purpose:
35
36
  * in JavaScript, passing `undefined` to a parameter with a default uses the default, so an `undefined`
36
37
  * explicitly asked by the caller would become another value.
37
38
  * @return the transposed matrix
38
39
  */
39
- export declare function transposeMatrix(matrix: number[][], defaultValForUndefinedCol?: number): number[][];
40
+ export declare function transposeMatrix<T>(matrix: T[][], defaultValForUndefinedCol?: T): (T | undefined)[][];
@@ -32,9 +32,10 @@ function arraysMap(array1, array2, operation, defaultItemValue = 0) {
32
32
  }
33
33
  /**
34
34
  * Transposes a matrix, turning the rows into columns and vice versa.
35
- * @param matrix matrix to transpose, where each row is an array of values
35
+ * @param matrix matrix to transpose, where each row is an array of values of any type
36
36
  * @param defaultValForUndefinedCol value used when a row has no value for a column, which happens when the rows have
37
- * different sizes. Without it, the missing column is `undefined`. The parameter has no default value on purpose:
37
+ * different sizes. It also replaces an element that is already `undefined` or `null` in the matrix. Without it,
38
+ * the missing column is `undefined`. The parameter has no default value on purpose:
38
39
  * in JavaScript, passing `undefined` to a parameter with a default uses the default, so an `undefined`
39
40
  * explicitly asked by the caller would become another value.
40
41
  * @return the transposed matrix
@@ -1 +1 @@
1
- {"version":3,"file":"ArrayUtil.js","names":[],"sources":["../../src/util/ArrayUtil.ts"],"sourcesContent":["/**\n * Creates an array of the given size, with the values from 0 to size - 1.\n * @param size size of the array\n */\nexport function createSequentialArray(size: number): number[] {\n return Array.from({ length: size }, (_, i) => i);\n}\n\n/**\n * Creates an array of any size, filled with the given value.\n * @param size size of the array\n * @param fillValue value of every element\n */\nexport function createFilledArray(size: number, fillValue: number = 0): number[] {\n return Array(size).fill(fillValue);\n}\n\n/**\n * Operation over two numbers that returns a new value from them.\n * @param number1 a number\n * @param number2 another number\n * @return a new value computed from the two numbers\n */\nexport type NumbersMapFunction = (number1: number, number2: number) => number;\n\n/**\n * Applies an operation to the elements at the same position of two arrays, mapping each pair of values to a new value.\n * @param array1 an array\n * @param array2 another array\n * @param operation operation applied to each pair of elements at the same position (see {@link NumbersMapFunction})\n * @param defaultItemValue value used when one array has no element at a position of the other one (when the arrays\n * have different sizes). A `NaN` (e.g. an empty year) is not replaced by the default: it propagates, so the\n * result for that position is empty too.\n * @return a new array with the result of the operation for each position\n */\nexport function arraysMap(\n array1: number[],\n array2: number[],\n operation: NumbersMapFunction,\n defaultItemValue: number = 0\n): number[] {\n if (array1.length === 0) return array2;\n\n if (array2.length === 0) return array1;\n\n const maxLen = Math.max(array1.length, array2.length);\n\n /* An array with just the indexes of the longest array, so that the result has the size of the longest one while\n keeping the order of the arguments (which may change the result of the operation). */\n const indexesArray = createSequentialArray(maxLen);\n return indexesArray.map(i => operation(array1[i] ?? defaultItemValue, array2[i] ?? defaultItemValue));\n}\n\n/**\n * Transposes a matrix, turning the rows into columns and vice versa.\n * @param matrix matrix to transpose, where each row is an array of values\n * @param defaultValForUndefinedCol value used when a row has no value for a column, which happens when the rows have\n * different sizes. Without it, the missing column is `undefined`. The parameter has no default value on purpose:\n * in JavaScript, passing `undefined` to a parameter with a default uses the default, so an `undefined`\n * explicitly asked by the caller would become another value.\n * @return the transposed matrix\n */\nexport function transposeMatrix(matrix: number[][], defaultValForUndefinedCol?: number): number[][] {\n const reducer = (acc: number, curr: number) => (curr > acc ? curr : acc);\n\n // Length of the longest row of the matrix\n const maxCols = matrix.map(line => line.length).reduce(reducer, 0);\n const colIndexes = createSequentialArray(maxCols);\n // `??`, not `||`: a 0 (a real value) and a NaN (an empty year) are kept, and only a missing column uses the default.\n return colIndexes.map(col => matrix.map(line => line[col] ?? defaultValForUndefinedCol));\n}\n"],"mappings":";;;;;;AAIA,SAAgB,sBAAsB,MAAwB;CAC1D,OAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,MAAM,CAAC;AACnD;;;;;;AAOA,SAAgB,kBAAkB,MAAc,YAAoB,GAAa;CAC7E,OAAO,MAAM,IAAI,CAAC,CAAC,KAAK,SAAS;AACrC;;;;;;;;;;;AAoBA,SAAgB,UACZ,QACA,QACA,WACA,mBAA2B,GACnB;CACR,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,IAAI,OAAO,WAAW,GAAG,OAAO;CAOhC,OADqB,sBAJN,KAAK,IAAI,OAAO,QAAQ,OAAO,MAIH,CACpC,CAAA,CAAa,KAAI,MAAK,UAAU,OAAO,MAAM,kBAAkB,OAAO,MAAM,gBAAgB,CAAC;AACxG;;;;;;;;;;AAWA,SAAgB,gBAAgB,QAAoB,2BAAgD;CAChG,MAAM,WAAW,KAAa,SAAkB,OAAO,MAAM,OAAO;CAMpE,OAFmB,sBADH,OAAO,KAAI,SAAQ,KAAK,MAAM,CAAC,CAAC,OAAO,SAAS,CACvB,CAElC,CAAA,CAAW,KAAI,QAAO,OAAO,KAAI,SAAQ,KAAK,QAAQ,yBAAyB,CAAC;AAC3F"}
1
+ {"version":3,"file":"ArrayUtil.js","names":[],"sources":["../../src/util/ArrayUtil.ts"],"sourcesContent":["/**\n * Creates an array of the given size, with the values from 0 to size - 1.\n * @param size size of the array\n */\nexport function createSequentialArray(size: number): number[] {\n return Array.from({ length: size }, (_, i) => i);\n}\n\n/**\n * Creates an array of any size, filled with the given value.\n * @param size size of the array\n * @param fillValue value of every element\n */\nexport function createFilledArray(size: number, fillValue: number = 0): number[] {\n return Array(size).fill(fillValue);\n}\n\n/**\n * Operation over two numbers that returns a new value from them.\n * @param number1 a number\n * @param number2 another number\n * @return a new value computed from the two numbers\n */\nexport type NumbersMapFunction = (number1: number, number2: number) => number;\n\n/**\n * Applies an operation to the elements at the same position of two arrays, mapping each pair of values to a new value.\n * @param array1 an array\n * @param array2 another array\n * @param operation operation applied to each pair of elements at the same position (see {@link NumbersMapFunction})\n * @param defaultItemValue value used when one array has no element at a position of the other one (when the arrays\n * have different sizes). A `NaN` (e.g. an empty year) is not replaced by the default: it propagates, so the\n * result for that position is empty too.\n * @return a new array with the result of the operation for each position\n */\nexport function arraysMap(\n array1: number[],\n array2: number[],\n operation: NumbersMapFunction,\n defaultItemValue: number = 0\n): number[] {\n if (array1.length === 0) return array2;\n\n if (array2.length === 0) return array1;\n\n const maxLen = Math.max(array1.length, array2.length);\n\n /* An array with just the indexes of the longest array, so that the result has the size of the longest one while\n keeping the order of the arguments (which may change the result of the operation). */\n const indexesArray = createSequentialArray(maxLen);\n return indexesArray.map(i => operation(array1[i] ?? defaultItemValue, array2[i] ?? defaultItemValue));\n}\n\n/**\n * Transposes a matrix, turning the rows into columns and vice versa.\n * @param matrix matrix to transpose, where each row is an array of values of any type\n * @param defaultValForUndefinedCol value used when a row has no value for a column, which happens when the rows have\n * different sizes. It also replaces an element that is already `undefined` or `null` in the matrix. Without it,\n * the missing column is `undefined`. The parameter has no default value on purpose:\n * in JavaScript, passing `undefined` to a parameter with a default uses the default, so an `undefined`\n * explicitly asked by the caller would become another value.\n * @return the transposed matrix\n */\nexport function transposeMatrix<T>(matrix: T[][], defaultValForUndefinedCol?: T): (T | undefined)[][] {\n const reducer = (acc: number, curr: number) => (curr > acc ? curr : acc);\n\n // Length of the longest row of the matrix\n const maxCols = matrix.map(line => line.length).reduce(reducer, 0);\n const colIndexes = createSequentialArray(maxCols);\n // `??`, not `||`: a 0 (a real value) and a NaN (an empty year) are kept, and only a missing column uses the default.\n return colIndexes.map(col => matrix.map(line => line[col] ?? defaultValForUndefinedCol));\n}\n"],"mappings":";;;;;;AAIA,SAAgB,sBAAsB,MAAwB;CAC1D,OAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,MAAM,CAAC;AACnD;;;;;;AAOA,SAAgB,kBAAkB,MAAc,YAAoB,GAAa;CAC7E,OAAO,MAAM,IAAI,CAAC,CAAC,KAAK,SAAS;AACrC;;;;;;;;;;;AAoBA,SAAgB,UACZ,QACA,QACA,WACA,mBAA2B,GACnB;CACR,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,IAAI,OAAO,WAAW,GAAG,OAAO;CAOhC,OADqB,sBAJN,KAAK,IAAI,OAAO,QAAQ,OAAO,MAIH,CACpC,CAAA,CAAa,KAAI,MAAK,UAAU,OAAO,MAAM,kBAAkB,OAAO,MAAM,gBAAgB,CAAC;AACxG;;;;;;;;;;;AAYA,SAAgB,gBAAmB,QAAe,2BAAoD;CAClG,MAAM,WAAW,KAAa,SAAkB,OAAO,MAAM,OAAO;CAMpE,OAFmB,sBADH,OAAO,KAAI,SAAQ,KAAK,MAAM,CAAC,CAAC,OAAO,SAAS,CACvB,CAElC,CAAA,CAAW,KAAI,QAAO,OAAO,KAAI,SAAQ,KAAK,QAAQ,yBAAyB,CAAC;AAC3F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ifto/mantine-kit",
3
- "version": "0.4.0",
3
+ "version": "0.5.2",
4
4
  "description": "General purpose Mantine components for React apps: CRUD tables and forms, layout, ECharts charts, Excel/CSV export, print pages and a REST HTTP client, with i18n (en-US and pt-BR).",
5
5
  "license": "MIT",
6
6
  "author": "IFTO - Campus Palmas",