@nccirtu/tablefy 0.6.4 → 0.6.6
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/columns/columns/input-column.d.ts +24 -11
- package/dist/columns/columns/select-column.d.ts +18 -13
- package/dist/columns/index.esm.js +143 -22
- package/dist/columns/index.esm.js.map +1 -1
- package/dist/columns/index.js +143 -22
- package/dist/columns/index.js.map +1 -1
- package/dist/columns/input-column.d.ts +24 -11
- package/dist/columns/select-column.d.ts +18 -13
- package/dist/index.esm.js +143 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +142 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ColumnDef } from "@tanstack/react-table";
|
|
2
|
+
import { BaseColumn } from "./base-column";
|
|
3
|
+
import { BaseColumnConfig } from "./types";
|
|
4
|
+
interface InputColumnConfig<TData> extends BaseColumnConfig<TData> {
|
|
4
5
|
placeholder?: string;
|
|
5
|
-
|
|
6
|
+
type?: "text" | "email" | "number" | "password" | "url";
|
|
7
|
+
disabled?: boolean | ((row: TData) => boolean);
|
|
8
|
+
onSave?: (row: TData, newValue: string) => void;
|
|
9
|
+
onChange?: (row: TData, newValue: string) => void;
|
|
10
|
+
debounce?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class InputColumn<TData> extends BaseColumn<TData, InputColumnConfig<TData>> {
|
|
13
|
+
constructor(accessor: keyof TData | string);
|
|
14
|
+
static make<TData>(accessor: keyof TData | string): InputColumn<TData>;
|
|
15
|
+
placeholder(placeholder: string): this;
|
|
16
|
+
type(type: "text" | "email" | "number" | "password" | "url"): this;
|
|
17
|
+
disabled(disabled: boolean | ((row: TData) => boolean)): this;
|
|
18
|
+
onSave(handler: (row: TData, newValue: string) => void): this;
|
|
19
|
+
onChange(handler: (row: TData, newValue: string) => void): this;
|
|
20
|
+
debounce(ms: number): this;
|
|
21
|
+
email(): this;
|
|
22
|
+
number(): this;
|
|
23
|
+
password(): this;
|
|
24
|
+
url(): this;
|
|
25
|
+
build(): ColumnDef<TData, unknown>;
|
|
6
26
|
}
|
|
7
|
-
export declare const InputColumn: (config: InputColumnConfig) => {
|
|
8
|
-
accessorKey: string;
|
|
9
|
-
header: string;
|
|
10
|
-
cell: ({ row }: {
|
|
11
|
-
row: any;
|
|
12
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
};
|
|
14
27
|
export { InputColumn as inputColumn };
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { ColumnDef } from "@tanstack/react-table";
|
|
2
|
+
import { BaseColumn } from "./base-column";
|
|
3
|
+
import { BaseColumnConfig } from "./types";
|
|
4
|
+
export interface SelectOption {
|
|
2
5
|
label: string;
|
|
3
6
|
value: string;
|
|
7
|
+
disabled?: boolean;
|
|
4
8
|
}
|
|
5
|
-
interface SelectColumnConfig {
|
|
6
|
-
|
|
7
|
-
header?: string;
|
|
9
|
+
interface SelectColumnConfig<TData> extends BaseColumnConfig<TData> {
|
|
10
|
+
options?: SelectOption[];
|
|
8
11
|
placeholder?: string;
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
disabled?: boolean | ((row: TData) => boolean);
|
|
13
|
+
onValueChange?: (row: TData, newValue: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class SelectColumn<TData> extends BaseColumn<TData, SelectColumnConfig<TData>> {
|
|
16
|
+
constructor(accessor: keyof TData | string);
|
|
17
|
+
static make<TData>(accessor: keyof TData | string): SelectColumn<TData>;
|
|
18
|
+
options(options: SelectOption[]): this;
|
|
19
|
+
placeholder(placeholder: string): this;
|
|
20
|
+
disabled(disabled: boolean | ((row: TData) => boolean)): this;
|
|
21
|
+
onValueChange(handler: (row: TData, newValue: string) => void): this;
|
|
22
|
+
build(): ColumnDef<TData, unknown>;
|
|
11
23
|
}
|
|
12
|
-
export declare const SelectColumn: (config: SelectColumnConfig) => {
|
|
13
|
-
accessorKey: string;
|
|
14
|
-
header: string;
|
|
15
|
-
cell: ({ row }: {
|
|
16
|
-
row: any;
|
|
17
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
-
};
|
|
19
24
|
export { SelectColumn as selectColumn };
|
|
@@ -6,6 +6,7 @@ import { ArrowUpDown, Calendar, ExternalLink, MoreHorizontal } from 'lucide-reac
|
|
|
6
6
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
7
7
|
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator } from '@/components/ui/dropdown-menu';
|
|
8
8
|
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip';
|
|
9
|
+
import { useState, useEffect } from 'react';
|
|
9
10
|
import { Input } from '@/components/ui/input';
|
|
10
11
|
import { Progress } from '@/components/ui/progress';
|
|
11
12
|
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
|
|
@@ -722,17 +723,91 @@ class ImageColumn extends BaseColumn {
|
|
|
722
723
|
}
|
|
723
724
|
}
|
|
724
725
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
}
|
|
735
|
-
|
|
726
|
+
class InputColumn extends BaseColumn {
|
|
727
|
+
constructor(accessor) {
|
|
728
|
+
super(accessor);
|
|
729
|
+
const config = this.config;
|
|
730
|
+
config.type = "text";
|
|
731
|
+
config.disabled = false;
|
|
732
|
+
}
|
|
733
|
+
static make(accessor) {
|
|
734
|
+
return new InputColumn(accessor);
|
|
735
|
+
}
|
|
736
|
+
placeholder(placeholder) {
|
|
737
|
+
this.config.placeholder = placeholder;
|
|
738
|
+
return this;
|
|
739
|
+
}
|
|
740
|
+
type(type) {
|
|
741
|
+
this.config.type = type;
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
disabled(disabled) {
|
|
745
|
+
this.config.disabled = disabled;
|
|
746
|
+
return this;
|
|
747
|
+
}
|
|
748
|
+
onSave(handler) {
|
|
749
|
+
this.config.onSave = handler;
|
|
750
|
+
return this;
|
|
751
|
+
}
|
|
752
|
+
onChange(handler) {
|
|
753
|
+
this.config.onChange = handler;
|
|
754
|
+
return this;
|
|
755
|
+
}
|
|
756
|
+
debounce(ms) {
|
|
757
|
+
this.config.debounce = ms;
|
|
758
|
+
return this;
|
|
759
|
+
}
|
|
760
|
+
// Shortcuts
|
|
761
|
+
email() {
|
|
762
|
+
return this.type("email");
|
|
763
|
+
}
|
|
764
|
+
number() {
|
|
765
|
+
return this.type("number");
|
|
766
|
+
}
|
|
767
|
+
password() {
|
|
768
|
+
return this.type("password");
|
|
769
|
+
}
|
|
770
|
+
url() {
|
|
771
|
+
return this.type("url");
|
|
772
|
+
}
|
|
773
|
+
build() {
|
|
774
|
+
const config = this.config;
|
|
775
|
+
const { accessor, label, sortable, placeholder, type, disabled, onSave, onChange, } = config;
|
|
776
|
+
return {
|
|
777
|
+
accessorKey: accessor,
|
|
778
|
+
header: ({ column }) => {
|
|
779
|
+
const displayLabel = label || String(accessor);
|
|
780
|
+
if (!sortable) {
|
|
781
|
+
return (jsx("span", { className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
|
|
782
|
+
}
|
|
783
|
+
return (jsxs(Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsx(ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
|
|
784
|
+
},
|
|
785
|
+
cell: ({ getValue, row }) => {
|
|
786
|
+
const initialValue = getValue();
|
|
787
|
+
const [localValue, setLocalValue] = useState(initialValue || "");
|
|
788
|
+
const isDisabled = typeof disabled === "function" ? disabled(row.original) : disabled;
|
|
789
|
+
// Sync local value with table data when it changes externally
|
|
790
|
+
useEffect(() => {
|
|
791
|
+
setLocalValue(initialValue || "");
|
|
792
|
+
}, [initialValue]);
|
|
793
|
+
const handleChange = (e) => {
|
|
794
|
+
const newValue = e.target.value;
|
|
795
|
+
setLocalValue(newValue);
|
|
796
|
+
if (onChange) {
|
|
797
|
+
onChange(row.original, newValue);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
const handleBlur = (e) => {
|
|
801
|
+
const newValue = e.target.value;
|
|
802
|
+
if (onSave && newValue !== initialValue) {
|
|
803
|
+
onSave(row.original, newValue);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
return (jsx(Input, { type: type || "text", value: localValue, onChange: handleChange, onBlur: handleBlur, placeholder: placeholder, disabled: isDisabled, className: cn("h-8", this.config.cellClassName) }));
|
|
807
|
+
},
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
}
|
|
736
811
|
|
|
737
812
|
class LinkColumn extends BaseColumn {
|
|
738
813
|
constructor(accessor) {
|
|
@@ -1043,17 +1118,63 @@ class ProgressColumn extends BaseColumn {
|
|
|
1043
1118
|
}
|
|
1044
1119
|
}
|
|
1045
1120
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1121
|
+
class SelectColumn extends BaseColumn {
|
|
1122
|
+
constructor(accessor) {
|
|
1123
|
+
super(accessor);
|
|
1124
|
+
const config = this.config;
|
|
1125
|
+
config.options = [];
|
|
1126
|
+
config.disabled = false;
|
|
1127
|
+
}
|
|
1128
|
+
static make(accessor) {
|
|
1129
|
+
return new SelectColumn(accessor);
|
|
1130
|
+
}
|
|
1131
|
+
options(options) {
|
|
1132
|
+
this.config.options = options;
|
|
1133
|
+
return this;
|
|
1134
|
+
}
|
|
1135
|
+
placeholder(placeholder) {
|
|
1136
|
+
this.config.placeholder = placeholder;
|
|
1137
|
+
return this;
|
|
1138
|
+
}
|
|
1139
|
+
disabled(disabled) {
|
|
1140
|
+
this.config.disabled = disabled;
|
|
1141
|
+
return this;
|
|
1142
|
+
}
|
|
1143
|
+
onValueChange(handler) {
|
|
1144
|
+
this.config.onValueChange = handler;
|
|
1145
|
+
return this;
|
|
1146
|
+
}
|
|
1147
|
+
build() {
|
|
1148
|
+
const config = this.config;
|
|
1149
|
+
const { accessor, label, sortable, options, placeholder, disabled, onValueChange, } = config;
|
|
1150
|
+
return {
|
|
1151
|
+
accessorKey: accessor,
|
|
1152
|
+
header: ({ column }) => {
|
|
1153
|
+
const displayLabel = label || String(accessor);
|
|
1154
|
+
if (!sortable) {
|
|
1155
|
+
return (jsx("span", { className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
|
|
1156
|
+
}
|
|
1157
|
+
return (jsxs(Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsx(ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
|
|
1158
|
+
},
|
|
1159
|
+
cell: ({ getValue, row }) => {
|
|
1160
|
+
const initialValue = getValue();
|
|
1161
|
+
const [localValue, setLocalValue] = useState(initialValue || "");
|
|
1162
|
+
const isDisabled = typeof disabled === "function" ? disabled(row.original) : disabled;
|
|
1163
|
+
// Sync local value with table data when it changes externally
|
|
1164
|
+
useEffect(() => {
|
|
1165
|
+
setLocalValue(initialValue || "");
|
|
1166
|
+
}, [initialValue]);
|
|
1167
|
+
const handleValueChange = (newValue) => {
|
|
1168
|
+
setLocalValue(newValue);
|
|
1169
|
+
if (onValueChange) {
|
|
1170
|
+
onValueChange(row.original, newValue);
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
return (jsxs(Select, { value: localValue, onValueChange: handleValueChange, disabled: isDisabled, children: [jsx(SelectTrigger, { className: cn("h-8", this.config.cellClassName), children: jsx(SelectValue, { placeholder: placeholder || "Select..." }) }), jsx(SelectContent, { children: options?.map((option, index) => (jsx(SelectItem, { value: option.value, disabled: option.disabled, children: option.label }, index))) })] }));
|
|
1174
|
+
},
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1057
1178
|
|
|
1058
1179
|
class TextColumn extends BaseColumn {
|
|
1059
1180
|
static make(accessor) {
|