@tint-ui/data-table 0.3.5
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/LICENSE +21 -0
- package/README.md +9 -0
- package/adapters/boolean.d.ts +10 -0
- package/adapters/boolean.js +38 -0
- package/adapters/index.d.ts +6 -0
- package/adapters/index.js +18 -0
- package/adapters/number-format.d.ts +1 -0
- package/adapters/number-format.js +42 -0
- package/adapters/number.d.ts +12 -0
- package/adapters/number.js +51 -0
- package/adapters/text.d.ts +4 -0
- package/adapters/text.js +9 -0
- package/cell-adapter-type.d.ts +43 -0
- package/cell-adapter-type.js +306 -0
- package/cjs/adapters/boolean.js +43 -0
- package/cjs/adapters/index.js +21 -0
- package/cjs/adapters/number-format.js +46 -0
- package/cjs/adapters/number.js +56 -0
- package/cjs/adapters/text.js +13 -0
- package/cjs/cell-adapter-type.js +312 -0
- package/cjs/classes.js +27 -0
- package/cjs/context.js +14 -0
- package/cjs/data-table-content.js +105 -0
- package/cjs/data-table-pagination.js +38 -0
- package/cjs/data-table-text-filter.js +83 -0
- package/cjs/data-table-toolbar.js +103 -0
- package/cjs/data-table-views-options.js +137 -0
- package/cjs/data-table.js +63 -0
- package/cjs/filter-adapter-type.js +162 -0
- package/cjs/filter-adapters/index.js +10 -0
- package/cjs/filter-adapters/option.js +152 -0
- package/cjs/filter-adapters/use-option-filter.js +195 -0
- package/cjs/filter-classes.js +26 -0
- package/cjs/filter-fn.js +84 -0
- package/cjs/index.js +99 -0
- package/cjs/package.json +3 -0
- package/cjs/pagination-arrow.js +93 -0
- package/cjs/pagination-classes.js +20 -0
- package/cjs/pagination-number.js +66 -0
- package/cjs/pagination-size-options.js +48 -0
- package/cjs/row-button-menu.js +49 -0
- package/cjs/row-popover-menu.js +52 -0
- package/cjs/toolbar-classes.js +24 -0
- package/cjs/types.js +3 -0
- package/cjs/use-data-table.js +768 -0
- package/cjs/use-lexicon.js +155 -0
- package/cjs/use-row-menu.js +60 -0
- package/cjs/use-visibility-column.js +105 -0
- package/cjs/use-visibility-filter.js +149 -0
- package/cjs/utils.js +136 -0
- package/classes.d.ts +34 -0
- package/classes.js +23 -0
- package/context.d.ts +5 -0
- package/context.js +9 -0
- package/data-table-content.d.ts +9 -0
- package/data-table-content.js +98 -0
- package/data-table-pagination.d.ts +5 -0
- package/data-table-pagination.js +31 -0
- package/data-table-text-filter.d.ts +7 -0
- package/data-table-text-filter.js +76 -0
- package/data-table-toolbar.d.ts +5 -0
- package/data-table-toolbar.js +95 -0
- package/data-table-views-options.d.ts +2 -0
- package/data-table-views-options.js +133 -0
- package/data-table.d.ts +18 -0
- package/data-table.js +56 -0
- package/filter-adapter-type.d.ts +9 -0
- package/filter-adapter-type.js +155 -0
- package/filter-adapters/index.d.ts +5 -0
- package/filter-adapters/index.js +7 -0
- package/filter-adapters/option.d.ts +3 -0
- package/filter-adapters/option.js +147 -0
- package/filter-adapters/use-option-filter.d.ts +27 -0
- package/filter-adapters/use-option-filter.js +192 -0
- package/filter-classes.d.ts +32 -0
- package/filter-classes.js +22 -0
- package/filter-fn.d.ts +7 -0
- package/filter-fn.js +76 -0
- package/index.d.ts +16 -0
- package/index.js +16 -0
- package/package.json +97 -0
- package/pagination-arrow.d.ts +5 -0
- package/pagination-arrow.js +86 -0
- package/pagination-classes.d.ts +20 -0
- package/pagination-classes.js +16 -0
- package/pagination-number.d.ts +5 -0
- package/pagination-number.js +59 -0
- package/pagination-size-options.d.ts +3 -0
- package/pagination-size-options.js +44 -0
- package/row-button-menu.d.ts +5 -0
- package/row-button-menu.js +45 -0
- package/row-popover-menu.d.ts +5 -0
- package/row-popover-menu.js +48 -0
- package/styles-filter.css +1 -0
- package/styles-filter.module.css +64 -0
- package/styles-filter.module.scss +65 -0
- package/styles-pagination.css +1 -0
- package/styles-pagination.module.css +28 -0
- package/styles-pagination.module.scss +31 -0
- package/styles-toolbar.css +1 -0
- package/styles-toolbar.module.css +70 -0
- package/styles-toolbar.module.scss +67 -0
- package/styles.css +1 -0
- package/styles.json +8 -0
- package/styles.module.css +39 -0
- package/styles.module.scss +38 -0
- package/toolbar-classes.d.ts +26 -0
- package/toolbar-classes.js +20 -0
- package/types.d.ts +226 -0
- package/types.js +2 -0
- package/use-data-table.d.ts +3 -0
- package/use-data-table.js +768 -0
- package/use-lexicon.d.ts +12 -0
- package/use-lexicon.js +151 -0
- package/use-row-menu.d.ts +7 -0
- package/use-row-menu.js +58 -0
- package/use-visibility-column.d.ts +7 -0
- package/use-visibility-column.js +101 -0
- package/use-visibility-filter.d.ts +7 -0
- package/use-visibility-filter.js +145 -0
- package/utils.d.ts +14 -0
- package/utils.js +128 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2017, Jon Schlinkert.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DataTableCellAdapter, DataTableCellAdapterOptions } from "../types";
|
|
2
|
+
type TableDataCellBooleanConfig = {
|
|
3
|
+
iconTrue?: string;
|
|
4
|
+
iconFalse?: string;
|
|
5
|
+
iconNull?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const booleanAdapter: DataTableCellAdapter<TableDataCellBooleanConfig>;
|
|
8
|
+
declare const booleanAdapterOptions: DataTableCellAdapterOptions<TableDataCellBooleanConfig>;
|
|
9
|
+
export { booleanAdapter, booleanAdapterOptions };
|
|
10
|
+
export type { TableDataCellBooleanConfig };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { SvgThemeIcon } from "@tint-ui/svg-icon";
|
|
6
|
+
import { useDataTableClasses } from "../classes.js";
|
|
7
|
+
const typeIcon = {
|
|
8
|
+
iconTrue: "data-table-boolean-true",
|
|
9
|
+
iconFalse: "data-table-boolean-false",
|
|
10
|
+
iconNull: "data-table-boolean-null"
|
|
11
|
+
};
|
|
12
|
+
const BooleanType = props => {
|
|
13
|
+
const {
|
|
14
|
+
value
|
|
15
|
+
} = props;
|
|
16
|
+
const variant = value == null ? "iconNull" : value ? "iconTrue" : "iconFalse";
|
|
17
|
+
const classes = useDataTableClasses();
|
|
18
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
19
|
+
className: classes.booleanCellType
|
|
20
|
+
}, /*#__PURE__*/React.createElement(SvgThemeIcon, {
|
|
21
|
+
className: classes[variant],
|
|
22
|
+
icon: props[variant] || typeIcon[variant]
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
BooleanType.displayName = "BooleanType";
|
|
26
|
+
const booleanAdapter = (value, cell) => {
|
|
27
|
+
return /*#__PURE__*/React.createElement(BooleanType, _extends({
|
|
28
|
+
value: value
|
|
29
|
+
}, cell.config));
|
|
30
|
+
};
|
|
31
|
+
const booleanAdapterOptions = {
|
|
32
|
+
nullable(cell) {
|
|
33
|
+
const config = cell.config || {};
|
|
34
|
+
return /*#__PURE__*/React.createElement(BooleanType, config);
|
|
35
|
+
},
|
|
36
|
+
align: "center"
|
|
37
|
+
};
|
|
38
|
+
export { booleanAdapter, booleanAdapterOptions };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { textAdapter, textAdapterOptions } from "./text.js";
|
|
2
|
+
import { numberAdapter, numberAdapterOptions } from "./number.js";
|
|
3
|
+
import { booleanAdapter, booleanAdapterOptions } from "./boolean.js";
|
|
4
|
+
const adapters = {
|
|
5
|
+
text: {
|
|
6
|
+
adapter: textAdapter,
|
|
7
|
+
options: textAdapterOptions
|
|
8
|
+
},
|
|
9
|
+
number: {
|
|
10
|
+
adapter: numberAdapter,
|
|
11
|
+
options: numberAdapterOptions
|
|
12
|
+
},
|
|
13
|
+
boolean: {
|
|
14
|
+
adapter: booleanAdapter,
|
|
15
|
+
options: booleanAdapterOptions
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export { adapters };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function numberFormat(value: number, decimal?: number, decimalRequired?: boolean): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const nobrSpace = "\xa0";
|
|
2
|
+
const ditSign = ".";
|
|
3
|
+
export function numberFormat(value, decimal = 2, decimalRequired = false) {
|
|
4
|
+
let number = String(value);
|
|
5
|
+
const ended = number.indexOf(".");
|
|
6
|
+
let end = "";
|
|
7
|
+
if (ended !== -1) {
|
|
8
|
+
end = number.substring(ended + 1);
|
|
9
|
+
if (end.length > decimal) {
|
|
10
|
+
if (decimal > 0) {
|
|
11
|
+
const endNum = parseInt(end.substring(0, decimal));
|
|
12
|
+
end = endNum === 0 ? "" : String(endNum);
|
|
13
|
+
} else {
|
|
14
|
+
end = "";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (end.length) {
|
|
18
|
+
end = ditSign + end;
|
|
19
|
+
}
|
|
20
|
+
number = number.substring(0, ended);
|
|
21
|
+
}
|
|
22
|
+
if (decimalRequired && decimal > 0) {
|
|
23
|
+
if (!end) {
|
|
24
|
+
end = ".";
|
|
25
|
+
}
|
|
26
|
+
const delta = end.length - 1;
|
|
27
|
+
if (delta > 0 && delta < decimal) {
|
|
28
|
+
end += "0".repeat(delta);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let len = number.length;
|
|
32
|
+
if (len < 4) {
|
|
33
|
+
return number + end;
|
|
34
|
+
}
|
|
35
|
+
let ceil = "";
|
|
36
|
+
while (len > 3) {
|
|
37
|
+
len -= 3;
|
|
38
|
+
ceil = nobrSpace + number.substring(len) + ceil;
|
|
39
|
+
number = number.substring(0, len);
|
|
40
|
+
}
|
|
41
|
+
return number + ceil + end;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DataTableCellAdapter, DataTableCellAdapterOptions } from "../types";
|
|
2
|
+
type TableDataCellNumberConfig = {
|
|
3
|
+
prefix?: string;
|
|
4
|
+
suffix?: string;
|
|
5
|
+
format?: boolean;
|
|
6
|
+
decimal?: number;
|
|
7
|
+
decimalRequired?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const numberAdapter: DataTableCellAdapter<TableDataCellNumberConfig>;
|
|
10
|
+
declare const numberAdapterOptions: DataTableCellAdapterOptions<TableDataCellNumberConfig>;
|
|
11
|
+
export { numberAdapter, numberAdapterOptions };
|
|
12
|
+
export type { TableDataCellNumberConfig };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { numberFormat } from "./number-format.js";
|
|
6
|
+
import { useDataTableClasses } from "../classes.js";
|
|
7
|
+
const NumberType = props => {
|
|
8
|
+
const {
|
|
9
|
+
value,
|
|
10
|
+
format,
|
|
11
|
+
prefix,
|
|
12
|
+
suffix,
|
|
13
|
+
decimal = 2,
|
|
14
|
+
decimalRequired = false
|
|
15
|
+
} = props;
|
|
16
|
+
const numberValue = typeof value === "number" ? value : parseFloat(String(value));
|
|
17
|
+
const numberIsNaN = !Number.isFinite(numberValue);
|
|
18
|
+
let node;
|
|
19
|
+
if (numberIsNaN) {
|
|
20
|
+
node = Number.isNaN(numberValue) ? "NaN" : "Infinite";
|
|
21
|
+
} else {
|
|
22
|
+
if (format) {
|
|
23
|
+
node = numberFormat(numberValue, decimal, decimalRequired);
|
|
24
|
+
} else {
|
|
25
|
+
node = String(numberValue);
|
|
26
|
+
}
|
|
27
|
+
if (prefix) {
|
|
28
|
+
node = prefix + node;
|
|
29
|
+
}
|
|
30
|
+
if (suffix) {
|
|
31
|
+
node += suffix;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const classes = useDataTableClasses();
|
|
35
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
36
|
+
className: classes.numberCellType + (numberIsNaN ? ` ${classes.isNaN}` : "")
|
|
37
|
+
}, node);
|
|
38
|
+
};
|
|
39
|
+
NumberType.displayName = "NumberType";
|
|
40
|
+
const numberAdapter = (value, cell) => {
|
|
41
|
+
return /*#__PURE__*/React.createElement(NumberType, _extends({
|
|
42
|
+
value: value
|
|
43
|
+
}, cell.config));
|
|
44
|
+
};
|
|
45
|
+
const numberAdapterOptions = {
|
|
46
|
+
nullable() {
|
|
47
|
+
return "";
|
|
48
|
+
},
|
|
49
|
+
align: "end"
|
|
50
|
+
};
|
|
51
|
+
export { numberAdapter, numberAdapterOptions };
|
package/adapters/text.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Header, Cell } from "@tanstack/react-table";
|
|
2
|
+
import type { DataTableCellAdapter, DataTableCellAdapterOptions, DataTableDisplayCell } from "./types";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
declare const hasCellAdapter: (type: string) => boolean;
|
|
5
|
+
declare const addCellAdapter: <TConfig extends object>(name: string, adapter: DataTableCellAdapter<TConfig, string, any>, options?: DataTableCellAdapterOptions<any>) => void;
|
|
6
|
+
declare const addCellAdapterAsync: <TConfig extends object>(name: string, handler: () => Promise<{
|
|
7
|
+
default: DataTableCellAdapter<TConfig, string, any>;
|
|
8
|
+
}>, options?: DataTableCellAdapterOptions<any>) => void;
|
|
9
|
+
declare const renderDataTableCell: <TData = object>(value: unknown, cell: DataTableDisplayCell<keyof TData, any>, data: TData) => React.ReactNode;
|
|
10
|
+
type DataTableCellNoRef<TData = object> = Omit<React.TdHTMLAttributes<HTMLTableCellElement>, "align"> & {
|
|
11
|
+
cell: Cell<TData, unknown>;
|
|
12
|
+
themePropsType?: string;
|
|
13
|
+
withWidth?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare const DataTableCell: (<TData>(props: Omit<React.TdHTMLAttributes<HTMLTableCellElement>, "align"> & {
|
|
16
|
+
cell: Cell<TData, unknown>;
|
|
17
|
+
themePropsType?: string | undefined;
|
|
18
|
+
withWidth?: boolean | undefined;
|
|
19
|
+
} & {
|
|
20
|
+
ref?: React.Ref<HTMLTableCellElement> | undefined;
|
|
21
|
+
}) => React.ReactElement) & {
|
|
22
|
+
readonly $$typeof: symbol;
|
|
23
|
+
displayName?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
type DataTableHeadPropsNoRef<TData> = Omit<React.TdHTMLAttributes<HTMLTableCellElement>, "align"> & {
|
|
26
|
+
header: Header<TData, unknown>;
|
|
27
|
+
themePropsType?: string;
|
|
28
|
+
withWidth?: boolean;
|
|
29
|
+
};
|
|
30
|
+
declare const DataTableHead: (<TData>(props: Omit<React.TdHTMLAttributes<HTMLTableCellElement>, "align"> & {
|
|
31
|
+
header: Header<TData, unknown>;
|
|
32
|
+
themePropsType?: string | undefined;
|
|
33
|
+
withWidth?: boolean | undefined;
|
|
34
|
+
} & {
|
|
35
|
+
ref?: React.Ref<HTMLTableCellElement> | undefined;
|
|
36
|
+
}) => React.ReactElement) & {
|
|
37
|
+
readonly $$typeof: symbol;
|
|
38
|
+
displayName?: string | undefined;
|
|
39
|
+
};
|
|
40
|
+
type DataTableCellProps = React.ComponentProps<typeof DataTableCell>;
|
|
41
|
+
type DataTableHeadProps = React.ComponentProps<typeof DataTableHead>;
|
|
42
|
+
export { hasCellAdapter, addCellAdapter, addCellAdapterAsync, renderDataTableCell, DataTableCell, DataTableHead };
|
|
43
|
+
export type { DataTableCellProps, DataTableHeadProps };
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { flexRender } from "@tanstack/react-table";
|
|
6
|
+
import { TableCell, TableHead, TableButtonSort } from "@tint-ui/table";
|
|
7
|
+
import { invariant, warningOnce } from "@tint-ui/tools/proof";
|
|
8
|
+
import { errorMessage } from "@tint-ui/tools/error-message";
|
|
9
|
+
import { adapters as coreAdapters } from "./adapters/index.js";
|
|
10
|
+
import { useDataTableClasses } from "./classes.js";
|
|
11
|
+
import { useDataTableContext } from "./context.js";
|
|
12
|
+
const adapters = new Map();
|
|
13
|
+
const defaultAdapters = new Map();
|
|
14
|
+
Object.entries(coreAdapters).forEach(([name, {
|
|
15
|
+
adapter,
|
|
16
|
+
options
|
|
17
|
+
}]) => {
|
|
18
|
+
defaultAdapters.set(name, {
|
|
19
|
+
adapter,
|
|
20
|
+
options
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
const getAdapt = type => {
|
|
24
|
+
const adapter = adapters.get(type) || defaultAdapters.get(type);
|
|
25
|
+
if (!adapter) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return adapter;
|
|
29
|
+
};
|
|
30
|
+
const privateTypes = [];
|
|
31
|
+
const checkAdapt = type => {
|
|
32
|
+
if (!type) {
|
|
33
|
+
throw new Error(`Adapter type is empty`);
|
|
34
|
+
}
|
|
35
|
+
if (privateTypes.includes(type)) {
|
|
36
|
+
throw new Error(`The ${type} type is private`);
|
|
37
|
+
}
|
|
38
|
+
if (adapters.has(type)) {
|
|
39
|
+
throw new Error(`The ${type} form adapter already exists`);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const hasCellAdapter = type => adapters.has(type);
|
|
43
|
+
const addCellAdapter = function (name, adapter, options = {}) {
|
|
44
|
+
checkAdapt(name);
|
|
45
|
+
adapters.set(name, {
|
|
46
|
+
adapter,
|
|
47
|
+
options
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const addCellAdapterAsync = function (name, handler, options = {}) {
|
|
51
|
+
checkAdapt(name);
|
|
52
|
+
adapters.set(name, {
|
|
53
|
+
adapter: createAsyncAdapterCallback(name, handler, options),
|
|
54
|
+
options
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const getAsyncAdapter = function (type, result) {
|
|
58
|
+
const adapter = result?.default;
|
|
59
|
+
invariant(typeof adapter === "function", `Async ${type} adapter failure: default is not function`);
|
|
60
|
+
return adapter;
|
|
61
|
+
};
|
|
62
|
+
const createAsyncAdapterCallback = function (type, handler, options) {
|
|
63
|
+
const adapt = {
|
|
64
|
+
waiters: new Set(),
|
|
65
|
+
handler,
|
|
66
|
+
error: null,
|
|
67
|
+
options
|
|
68
|
+
};
|
|
69
|
+
const adapter = (value, cell, data) => {
|
|
70
|
+
return /*#__PURE__*/React.createElement(DataTableCellAdapterAsync, {
|
|
71
|
+
adapt: adapt,
|
|
72
|
+
type: type,
|
|
73
|
+
value: value,
|
|
74
|
+
cell: cell,
|
|
75
|
+
data: data
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
adapt.adapter = adapter;
|
|
79
|
+
return adapter;
|
|
80
|
+
};
|
|
81
|
+
const createAsyncPromise = async (type, adapt) => {
|
|
82
|
+
try {
|
|
83
|
+
const result = await adapt.handler();
|
|
84
|
+
const adapter = getAsyncAdapter(type, result);
|
|
85
|
+
adapt.error = null;
|
|
86
|
+
adapt.adapter = adapter;
|
|
87
|
+
adapters.set(type, {
|
|
88
|
+
adapter,
|
|
89
|
+
options: adapt.options
|
|
90
|
+
});
|
|
91
|
+
} catch (err) {
|
|
92
|
+
adapt.error = errorMessage(err).message;
|
|
93
|
+
}
|
|
94
|
+
let event;
|
|
95
|
+
if (adapt.error != null) {
|
|
96
|
+
event = {
|
|
97
|
+
error: adapt.error
|
|
98
|
+
};
|
|
99
|
+
} else if (adapt.adapter) {
|
|
100
|
+
event = {
|
|
101
|
+
adapter: adapt.adapter
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const handlers = Array.from(adapt.waiters.values());
|
|
107
|
+
adapt.waiters.clear();
|
|
108
|
+
handlers.forEach(handler => {
|
|
109
|
+
handler(event);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const DataTableCellAdapterAsync = props => {
|
|
113
|
+
const classes = useDataTableClasses();
|
|
114
|
+
const {
|
|
115
|
+
adapt,
|
|
116
|
+
cell,
|
|
117
|
+
value,
|
|
118
|
+
data,
|
|
119
|
+
type
|
|
120
|
+
} = props;
|
|
121
|
+
const [state, setState] = React.useState(() => {
|
|
122
|
+
return adapt.adapter ? {
|
|
123
|
+
adapter: adapt.adapter
|
|
124
|
+
} : adapt.error != null ? {
|
|
125
|
+
error: adapt.error
|
|
126
|
+
} : null;
|
|
127
|
+
});
|
|
128
|
+
React.useEffect(() => {
|
|
129
|
+
const {
|
|
130
|
+
adapter,
|
|
131
|
+
error,
|
|
132
|
+
promise
|
|
133
|
+
} = adapt;
|
|
134
|
+
if (error != null || adapter != null) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (promise == null) {
|
|
138
|
+
adapt.promise = createAsyncPromise(type, adapt);
|
|
139
|
+
}
|
|
140
|
+
adapt.waiters.add(setState);
|
|
141
|
+
return () => {
|
|
142
|
+
adapt.waiters.delete(setState);
|
|
143
|
+
};
|
|
144
|
+
}, [type, adapt]);
|
|
145
|
+
if (state == null) {
|
|
146
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
147
|
+
className: classes.loader
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if ("error" in state) {
|
|
151
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
152
|
+
className: classes.error
|
|
153
|
+
}, state.error);
|
|
154
|
+
}
|
|
155
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, state.adapter(value, cell, data));
|
|
156
|
+
};
|
|
157
|
+
DataTableCellAdapterAsync.displayName = "DataTableCellAdapterAsync";
|
|
158
|
+
const renderDataTableCell = function (value, cell, data) {
|
|
159
|
+
const {
|
|
160
|
+
type = "text"
|
|
161
|
+
} = cell;
|
|
162
|
+
const adapt = getAdapt(type);
|
|
163
|
+
if (!adapt) {
|
|
164
|
+
warningOnce(`table-cell:${type}`, false, `The ${type} cell type not found`);
|
|
165
|
+
switch (typeof value) {
|
|
166
|
+
case "string":
|
|
167
|
+
case "number":
|
|
168
|
+
case "boolean":
|
|
169
|
+
return String(value);
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const {
|
|
174
|
+
adapter
|
|
175
|
+
} = adapt;
|
|
176
|
+
if (value != null) {
|
|
177
|
+
return adapter(value, cell, data);
|
|
178
|
+
}
|
|
179
|
+
const {
|
|
180
|
+
options: {
|
|
181
|
+
nullable
|
|
182
|
+
}
|
|
183
|
+
} = adapt;
|
|
184
|
+
if (nullable) {
|
|
185
|
+
return nullable(cell, data);
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
};
|
|
189
|
+
const DataTableCell = /*#__PURE__*/React.forwardRef(({
|
|
190
|
+
cell: tableCell,
|
|
191
|
+
withWidth,
|
|
192
|
+
style,
|
|
193
|
+
...props
|
|
194
|
+
}, ref) => {
|
|
195
|
+
const colDef = tableCell.column.columnDef;
|
|
196
|
+
const cell = colDef.meta?._cell;
|
|
197
|
+
const minProps = {
|
|
198
|
+
...props,
|
|
199
|
+
style,
|
|
200
|
+
ref,
|
|
201
|
+
"data-cell-id": tableCell.id
|
|
202
|
+
};
|
|
203
|
+
if (!cell) {
|
|
204
|
+
if (withWidth && String(tableCell.column.id).startsWith("__#")) {
|
|
205
|
+
minProps.style = {
|
|
206
|
+
...style,
|
|
207
|
+
width: "1%"
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return /*#__PURE__*/React.createElement(TableCell, minProps);
|
|
211
|
+
}
|
|
212
|
+
const {
|
|
213
|
+
name,
|
|
214
|
+
type = "text"
|
|
215
|
+
} = cell;
|
|
216
|
+
const adapt = getAdapt(type);
|
|
217
|
+
if (!adapt) {
|
|
218
|
+
return /*#__PURE__*/React.createElement(TableCell, _extends({}, minProps, {
|
|
219
|
+
"data-cell-name": name
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
let align = "start";
|
|
223
|
+
const {
|
|
224
|
+
options
|
|
225
|
+
} = adapt;
|
|
226
|
+
if (options.align) {
|
|
227
|
+
align = options.align;
|
|
228
|
+
}
|
|
229
|
+
if (withWidth && options.width) {
|
|
230
|
+
style = {
|
|
231
|
+
...style,
|
|
232
|
+
width: options.width
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return /*#__PURE__*/React.createElement(TableCell, _extends({}, minProps, {
|
|
236
|
+
style: style,
|
|
237
|
+
align: align,
|
|
238
|
+
"data-cell-name": name,
|
|
239
|
+
"data-cell-type": type
|
|
240
|
+
}));
|
|
241
|
+
});
|
|
242
|
+
DataTableCell.displayName = "DataTableCell";
|
|
243
|
+
const DataTableHead = /*#__PURE__*/React.forwardRef(({
|
|
244
|
+
header,
|
|
245
|
+
withWidth,
|
|
246
|
+
children,
|
|
247
|
+
style,
|
|
248
|
+
...props
|
|
249
|
+
}, ref) => {
|
|
250
|
+
const table = useDataTableContext();
|
|
251
|
+
const colDef = header.column.columnDef;
|
|
252
|
+
const cell = colDef.meta?._cell;
|
|
253
|
+
const body = header.isPlaceholder ? null : flexRender(colDef.header, header.getContext());
|
|
254
|
+
const minProps = {
|
|
255
|
+
...props,
|
|
256
|
+
ref,
|
|
257
|
+
style,
|
|
258
|
+
"data-cell-id": header.id
|
|
259
|
+
};
|
|
260
|
+
if (!cell || body == null) {
|
|
261
|
+
if (withWidth && String(header.column.id).startsWith("__#")) {
|
|
262
|
+
minProps.style = {
|
|
263
|
+
...style,
|
|
264
|
+
width: "1%"
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return /*#__PURE__*/React.createElement(TableHead, minProps, body);
|
|
268
|
+
}
|
|
269
|
+
const {
|
|
270
|
+
name,
|
|
271
|
+
type = "text"
|
|
272
|
+
} = cell;
|
|
273
|
+
let node = body;
|
|
274
|
+
let align = "start";
|
|
275
|
+
const adapt = getAdapt(type);
|
|
276
|
+
if (adapt) {
|
|
277
|
+
const {
|
|
278
|
+
options
|
|
279
|
+
} = adapt;
|
|
280
|
+
if (options.align) {
|
|
281
|
+
align = options.align;
|
|
282
|
+
}
|
|
283
|
+
if (withWidth && options.width) {
|
|
284
|
+
style = {
|
|
285
|
+
...style,
|
|
286
|
+
width: options.width
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (header.column.getCanSort()) {
|
|
291
|
+
const sorted = header.column.getIsSorted();
|
|
292
|
+
node = /*#__PURE__*/React.createElement(TableButtonSort, {
|
|
293
|
+
disabled: table.loading,
|
|
294
|
+
direction: sorted ? sorted : "none",
|
|
295
|
+
onClick: header.column.getToggleSortingHandler()
|
|
296
|
+
}, node);
|
|
297
|
+
}
|
|
298
|
+
return /*#__PURE__*/React.createElement(TableHead, _extends({}, minProps, {
|
|
299
|
+
style: style,
|
|
300
|
+
align: align,
|
|
301
|
+
"data-cell-name": name,
|
|
302
|
+
"data-cell-type": type
|
|
303
|
+
}), node);
|
|
304
|
+
});
|
|
305
|
+
DataTableHead.displayName = "DataTableHead";
|
|
306
|
+
export { hasCellAdapter, addCellAdapter, addCellAdapterAsync, renderDataTableCell, DataTableCell, DataTableHead };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
+
exports.__esModule = true;
|
|
7
|
+
exports.booleanAdapterOptions = exports.booleanAdapter = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _svgIcon = require("@tint-ui/svg-icon");
|
|
11
|
+
var _classes = require("../classes");
|
|
12
|
+
const typeIcon = {
|
|
13
|
+
iconTrue: "data-table-boolean-true",
|
|
14
|
+
iconFalse: "data-table-boolean-false",
|
|
15
|
+
iconNull: "data-table-boolean-null"
|
|
16
|
+
};
|
|
17
|
+
const BooleanType = props => {
|
|
18
|
+
const {
|
|
19
|
+
value
|
|
20
|
+
} = props;
|
|
21
|
+
const variant = value == null ? "iconNull" : value ? "iconTrue" : "iconFalse";
|
|
22
|
+
const classes = (0, _classes.useDataTableClasses)();
|
|
23
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
24
|
+
className: classes.booleanCellType
|
|
25
|
+
}, /*#__PURE__*/React.createElement(_svgIcon.SvgThemeIcon, {
|
|
26
|
+
className: classes[variant],
|
|
27
|
+
icon: props[variant] || typeIcon[variant]
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
BooleanType.displayName = "BooleanType";
|
|
31
|
+
const booleanAdapter = (value, cell) => {
|
|
32
|
+
return /*#__PURE__*/React.createElement(BooleanType, (0, _extends2.default)({
|
|
33
|
+
value: value
|
|
34
|
+
}, cell.config));
|
|
35
|
+
};
|
|
36
|
+
exports.booleanAdapter = booleanAdapter;
|
|
37
|
+
const booleanAdapterOptions = exports.booleanAdapterOptions = {
|
|
38
|
+
nullable(cell) {
|
|
39
|
+
const config = cell.config || {};
|
|
40
|
+
return /*#__PURE__*/React.createElement(BooleanType, config);
|
|
41
|
+
},
|
|
42
|
+
align: "center"
|
|
43
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.adapters = void 0;
|
|
5
|
+
var _text = require("./text");
|
|
6
|
+
var _number = require("./number");
|
|
7
|
+
var _boolean = require("./boolean");
|
|
8
|
+
const adapters = exports.adapters = {
|
|
9
|
+
text: {
|
|
10
|
+
adapter: _text.textAdapter,
|
|
11
|
+
options: _text.textAdapterOptions
|
|
12
|
+
},
|
|
13
|
+
number: {
|
|
14
|
+
adapter: _number.numberAdapter,
|
|
15
|
+
options: _number.numberAdapterOptions
|
|
16
|
+
},
|
|
17
|
+
boolean: {
|
|
18
|
+
adapter: _boolean.booleanAdapter,
|
|
19
|
+
options: _boolean.booleanAdapterOptions
|
|
20
|
+
}
|
|
21
|
+
};
|