@jameskabz/nextcraft-ui 0.5.0 → 0.6.0
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/README.md +94 -0
- package/dist/chunk-6F7FN2ZF.js +671 -0
- package/dist/chunk-6F7FN2ZF.js.map +1 -0
- package/dist/chunk-7Q4Z47HT.js +657 -0
- package/dist/chunk-7Q4Z47HT.js.map +1 -0
- package/dist/chunk-7SKDTIEK.js +49 -0
- package/dist/chunk-7SKDTIEK.js.map +1 -0
- package/dist/chunk-FEFH5O5K.js +49 -0
- package/dist/chunk-FEFH5O5K.js.map +1 -0
- package/dist/chunk-M2EKVXB6.js +127 -0
- package/dist/chunk-M2EKVXB6.js.map +1 -0
- package/dist/chunk-SBLIF6UU.js +1029 -0
- package/dist/chunk-SBLIF6UU.js.map +1 -0
- package/dist/chunk-VQ6T3HIX.js +9 -0
- package/dist/chunk-VQ6T3HIX.js.map +1 -0
- package/dist/chunk-YVZL4GET.js +328 -0
- package/dist/chunk-YVZL4GET.js.map +1 -0
- package/dist/chunk-ZRV4Y374.js +582 -0
- package/dist/chunk-ZRV4Y374.js.map +1 -0
- package/dist/craft/components.cjs +1838 -0
- package/dist/craft/components.cjs.map +1 -0
- package/dist/craft/components.d.cts +369 -0
- package/dist/craft/components.d.ts +369 -0
- package/dist/craft/components.js +78 -0
- package/dist/craft/components.js.map +1 -0
- package/dist/craft/forms.cjs +1376 -0
- package/dist/craft/forms.cjs.map +1 -0
- package/dist/craft/forms.d.cts +101 -0
- package/dist/craft/forms.d.ts +101 -0
- package/dist/craft/forms.js +14 -0
- package/dist/craft/forms.js.map +1 -0
- package/dist/craft/layout.cjs +410 -0
- package/dist/craft/layout.cjs.map +1 -0
- package/dist/craft/layout.d.cts +170 -0
- package/dist/craft/layout.d.ts +170 -0
- package/dist/craft/layout.js +27 -0
- package/dist/craft/layout.js.map +1 -0
- package/dist/craft/table.cjs +662 -0
- package/dist/craft/table.cjs.map +1 -0
- package/dist/craft/table.d.cts +99 -0
- package/dist/craft/table.d.ts +99 -0
- package/dist/craft/table.js +15 -0
- package/dist/craft/table.js.map +1 -0
- package/dist/craft/theme.cjs +166 -0
- package/dist/craft/theme.cjs.map +1 -0
- package/dist/craft/theme.d.cts +10 -0
- package/dist/craft/theme.d.ts +10 -0
- package/dist/craft/theme.js +12 -0
- package/dist/craft/theme.js.map +1 -0
- package/dist/index.cjs +1000 -299
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -499
- package/dist/index.d.ts +10 -499
- package/dist/index.js +81 -2689
- package/dist/index.js.map +1 -1
- package/dist/styles.css +124 -0
- package/dist/theme-context-EVI9PfKv.d.cts +22 -0
- package/dist/theme-context-EVI9PfKv.d.ts +22 -0
- package/package.json +28 -1
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/craft/table.ts
|
|
31
|
+
var table_exports = {};
|
|
32
|
+
__export(table_exports, {
|
|
33
|
+
CraftDataTable: () => CraftDataTable,
|
|
34
|
+
CraftFilterBar: () => CraftFilterBar,
|
|
35
|
+
CraftPagination: () => CraftPagination,
|
|
36
|
+
CraftTableToolbar: () => CraftTableToolbar
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(table_exports);
|
|
39
|
+
|
|
40
|
+
// src/components/craft-data-table.tsx
|
|
41
|
+
var React = __toESM(require("react"), 1);
|
|
42
|
+
|
|
43
|
+
// src/utils/cn.ts
|
|
44
|
+
function cn(...values) {
|
|
45
|
+
return values.filter(Boolean).join(" ");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/components/craft-pagination.tsx
|
|
49
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
50
|
+
function getPageNumbers(pageIndex, pageCount, maxButtons = 5) {
|
|
51
|
+
if (pageCount <= maxButtons) {
|
|
52
|
+
return Array.from({ length: pageCount }, (_, i) => i);
|
|
53
|
+
}
|
|
54
|
+
const pages = [];
|
|
55
|
+
const start = Math.max(0, pageIndex - 1);
|
|
56
|
+
const end = Math.min(pageCount - 1, pageIndex + 1);
|
|
57
|
+
pages.push(0);
|
|
58
|
+
if (start > 1) pages.push("ellipsis");
|
|
59
|
+
for (let i = start; i <= end; i += 1) {
|
|
60
|
+
if (i !== 0 && i !== pageCount - 1) pages.push(i);
|
|
61
|
+
}
|
|
62
|
+
if (end < pageCount - 2) pages.push("ellipsis");
|
|
63
|
+
pages.push(pageCount - 1);
|
|
64
|
+
return pages;
|
|
65
|
+
}
|
|
66
|
+
function CraftPagination({
|
|
67
|
+
pageIndex,
|
|
68
|
+
pageCount,
|
|
69
|
+
onPageChange,
|
|
70
|
+
canPrevious = pageIndex > 0,
|
|
71
|
+
canNext = pageIndex < pageCount - 1,
|
|
72
|
+
pageSize,
|
|
73
|
+
pageSizeOptions = [10, 20, 50],
|
|
74
|
+
onPageSizeChange,
|
|
75
|
+
tone,
|
|
76
|
+
className
|
|
77
|
+
}) {
|
|
78
|
+
const pages = getPageNumbers(pageIndex, pageCount);
|
|
79
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
className: cn(
|
|
83
|
+
"flex flex-wrap items-center justify-between gap-4",
|
|
84
|
+
className
|
|
85
|
+
),
|
|
86
|
+
"data-nc-theme": tone,
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
89
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
90
|
+
"button",
|
|
91
|
+
{
|
|
92
|
+
type: "button",
|
|
93
|
+
className: cn(
|
|
94
|
+
"rounded-xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] px-3 py-2 text-xs text-[rgb(var(--nc-fg))] transition",
|
|
95
|
+
"hover:bg-[rgb(var(--nc-surface)/0.2)]",
|
|
96
|
+
!canPrevious && "opacity-50 cursor-not-allowed"
|
|
97
|
+
),
|
|
98
|
+
onClick: () => onPageChange(Math.max(pageIndex - 1, 0)),
|
|
99
|
+
disabled: !canPrevious,
|
|
100
|
+
children: "Prev"
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
pages.map(
|
|
104
|
+
(page, index) => page === "ellipsis" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "px-2 text-[rgb(var(--nc-fg-muted))]", children: "..." }, `ellipsis-${index}`) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
105
|
+
"button",
|
|
106
|
+
{
|
|
107
|
+
type: "button",
|
|
108
|
+
className: cn(
|
|
109
|
+
"rounded-xl border px-3 py-2 text-xs transition",
|
|
110
|
+
page === pageIndex ? "border-[rgb(var(--nc-accent-1)/0.6)] bg-[rgb(var(--nc-accent-1)/0.2)] text-[rgb(var(--nc-fg))]" : "border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] text-[rgb(var(--nc-fg-muted))] hover:text-[rgb(var(--nc-fg))] hover:bg-[rgb(var(--nc-surface)/0.2)]"
|
|
111
|
+
),
|
|
112
|
+
onClick: () => onPageChange(page),
|
|
113
|
+
children: page + 1
|
|
114
|
+
},
|
|
115
|
+
page
|
|
116
|
+
)
|
|
117
|
+
),
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
119
|
+
"button",
|
|
120
|
+
{
|
|
121
|
+
type: "button",
|
|
122
|
+
className: cn(
|
|
123
|
+
"rounded-xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] px-3 py-2 text-xs text-[rgb(var(--nc-fg))] transition",
|
|
124
|
+
"hover:bg-[rgb(var(--nc-surface)/0.2)]",
|
|
125
|
+
!canNext && "opacity-50 cursor-not-allowed"
|
|
126
|
+
),
|
|
127
|
+
onClick: () => onPageChange(Math.min(pageIndex + 1, pageCount - 1)),
|
|
128
|
+
disabled: !canNext,
|
|
129
|
+
children: "Next"
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
] }),
|
|
133
|
+
onPageSizeChange && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2 text-xs text-[rgb(var(--nc-fg-muted))]", children: [
|
|
134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Rows" }),
|
|
135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
+
"select",
|
|
137
|
+
{
|
|
138
|
+
className: "rounded-xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] px-2 py-1 text-xs text-[rgb(var(--nc-fg))]",
|
|
139
|
+
value: pageSize,
|
|
140
|
+
onChange: (event) => onPageSizeChange(Number(event.target.value)),
|
|
141
|
+
children: pageSizeOptions.map((size) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: size, children: size }, size))
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
] })
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/components/craft-data-table.tsx
|
|
151
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
152
|
+
function getColumnValue(column, row) {
|
|
153
|
+
if (typeof column.accessor === "function") return column.accessor(row);
|
|
154
|
+
const record = row;
|
|
155
|
+
if (typeof column.accessor === "string") return record[column.accessor];
|
|
156
|
+
return record[column.id];
|
|
157
|
+
}
|
|
158
|
+
function normalizeValue(value) {
|
|
159
|
+
if (value === null || value === void 0) return "";
|
|
160
|
+
if (typeof value === "number") return value;
|
|
161
|
+
if (typeof value === "string") return value.toLowerCase();
|
|
162
|
+
if (value instanceof Date) return value.getTime();
|
|
163
|
+
return String(value).toLowerCase();
|
|
164
|
+
}
|
|
165
|
+
function CraftDataTable({
|
|
166
|
+
data,
|
|
167
|
+
columns,
|
|
168
|
+
tone,
|
|
169
|
+
className,
|
|
170
|
+
loading = false,
|
|
171
|
+
emptyState,
|
|
172
|
+
toolbar,
|
|
173
|
+
enableSorting = true,
|
|
174
|
+
enableFiltering = true,
|
|
175
|
+
enableColumnVisibility = true,
|
|
176
|
+
enableRowSelection = true,
|
|
177
|
+
enablePagination = true,
|
|
178
|
+
showGlobalFilter,
|
|
179
|
+
manualSorting = false,
|
|
180
|
+
manualFiltering = false,
|
|
181
|
+
manualPagination = false,
|
|
182
|
+
sortBy,
|
|
183
|
+
onSortChange,
|
|
184
|
+
filters,
|
|
185
|
+
onFiltersChange,
|
|
186
|
+
globalFilter,
|
|
187
|
+
onGlobalFilterChange,
|
|
188
|
+
columnVisibility,
|
|
189
|
+
onColumnVisibilityChange,
|
|
190
|
+
selectedRowIds,
|
|
191
|
+
onRowSelectionChange,
|
|
192
|
+
getRowId,
|
|
193
|
+
pageIndex,
|
|
194
|
+
pageSize = 10,
|
|
195
|
+
pageCount,
|
|
196
|
+
onPageChange,
|
|
197
|
+
onPageSizeChange
|
|
198
|
+
}) {
|
|
199
|
+
const [internalSort, setInternalSort] = React.useState(null);
|
|
200
|
+
const [internalFilters, setInternalFilters] = React.useState({});
|
|
201
|
+
const [internalGlobalFilter, setInternalGlobalFilter] = React.useState("");
|
|
202
|
+
const [internalVisibility, setInternalVisibility] = React.useState(
|
|
203
|
+
() => columns.reduce((acc, column) => {
|
|
204
|
+
acc[column.id] = !column.hidden;
|
|
205
|
+
return acc;
|
|
206
|
+
}, {})
|
|
207
|
+
);
|
|
208
|
+
const [internalSelection, setInternalSelection] = React.useState({});
|
|
209
|
+
const [internalPageIndex, setInternalPageIndex] = React.useState(0);
|
|
210
|
+
const [showColumns, setShowColumns] = React.useState(false);
|
|
211
|
+
const resolvedSort = sortBy != null ? sortBy : internalSort;
|
|
212
|
+
const resolvedFilters = filters != null ? filters : internalFilters;
|
|
213
|
+
const resolvedGlobalFilter = globalFilter != null ? globalFilter : internalGlobalFilter;
|
|
214
|
+
const resolvedVisibility = columnVisibility != null ? columnVisibility : internalVisibility;
|
|
215
|
+
const resolvedSelection = selectedRowIds != null ? selectedRowIds : internalSelection;
|
|
216
|
+
const resolvedPageIndex = pageIndex != null ? pageIndex : internalPageIndex;
|
|
217
|
+
const setSort = (next) => {
|
|
218
|
+
if (sortBy === void 0) setInternalSort(next);
|
|
219
|
+
onSortChange == null ? void 0 : onSortChange(next);
|
|
220
|
+
};
|
|
221
|
+
const setFilters = (next) => {
|
|
222
|
+
if (filters === void 0) setInternalFilters(next);
|
|
223
|
+
onFiltersChange == null ? void 0 : onFiltersChange(next);
|
|
224
|
+
};
|
|
225
|
+
const setVisibility = (next) => {
|
|
226
|
+
if (columnVisibility === void 0) setInternalVisibility(next);
|
|
227
|
+
onColumnVisibilityChange == null ? void 0 : onColumnVisibilityChange(next);
|
|
228
|
+
};
|
|
229
|
+
const setSelection = (next) => {
|
|
230
|
+
if (selectedRowIds === void 0) setInternalSelection(next);
|
|
231
|
+
onRowSelectionChange == null ? void 0 : onRowSelectionChange(next);
|
|
232
|
+
};
|
|
233
|
+
const setPageIndex = React.useCallback(
|
|
234
|
+
(next) => {
|
|
235
|
+
if (pageIndex === void 0) setInternalPageIndex(next);
|
|
236
|
+
onPageChange == null ? void 0 : onPageChange(next);
|
|
237
|
+
},
|
|
238
|
+
[pageIndex, onPageChange]
|
|
239
|
+
);
|
|
240
|
+
const visibleColumns = columns.filter(
|
|
241
|
+
(column) => resolvedVisibility[column.id] !== false
|
|
242
|
+
);
|
|
243
|
+
const filteredData = React.useMemo(() => {
|
|
244
|
+
if (manualFiltering) return data;
|
|
245
|
+
const globalValue = resolvedGlobalFilter.trim();
|
|
246
|
+
return data.filter((row) => {
|
|
247
|
+
if (globalValue) {
|
|
248
|
+
const matchesGlobal = columns.some((column) => {
|
|
249
|
+
const value = normalizeValue(getColumnValue(column, row));
|
|
250
|
+
return String(value).includes(globalValue.toLowerCase());
|
|
251
|
+
});
|
|
252
|
+
if (!matchesGlobal) return false;
|
|
253
|
+
}
|
|
254
|
+
return Object.entries(resolvedFilters).every(([columnId, value]) => {
|
|
255
|
+
if (!value) return true;
|
|
256
|
+
const column = columns.find((col) => col.id === columnId);
|
|
257
|
+
if (!column) return true;
|
|
258
|
+
const cellValue = normalizeValue(getColumnValue(column, row));
|
|
259
|
+
return String(cellValue).includes(value.toLowerCase());
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}, [columns, data, manualFiltering, resolvedFilters, resolvedGlobalFilter]);
|
|
263
|
+
const sortedData = React.useMemo(() => {
|
|
264
|
+
if (manualSorting || !resolvedSort) return filteredData;
|
|
265
|
+
const column = columns.find((col) => col.id === resolvedSort.id);
|
|
266
|
+
if (!column) return filteredData;
|
|
267
|
+
const sorted = [...filteredData].sort((a, b) => {
|
|
268
|
+
const valueA = normalizeValue(getColumnValue(column, a));
|
|
269
|
+
const valueB = normalizeValue(getColumnValue(column, b));
|
|
270
|
+
if (typeof valueA === "number" && typeof valueB === "number") {
|
|
271
|
+
return valueA - valueB;
|
|
272
|
+
}
|
|
273
|
+
return String(valueA).localeCompare(String(valueB));
|
|
274
|
+
});
|
|
275
|
+
return resolvedSort.desc ? sorted.reverse() : sorted;
|
|
276
|
+
}, [columns, filteredData, manualSorting, resolvedSort]);
|
|
277
|
+
const resolvedPageCount = manualPagination ? Math.max(pageCount != null ? pageCount : 1, 1) : Math.max(Math.ceil(sortedData.length / pageSize), 1);
|
|
278
|
+
React.useEffect(() => {
|
|
279
|
+
if (resolvedPageIndex > resolvedPageCount - 1) {
|
|
280
|
+
setPageIndex(Math.max(resolvedPageCount - 1, 0));
|
|
281
|
+
}
|
|
282
|
+
}, [resolvedPageCount, resolvedPageIndex, setPageIndex]);
|
|
283
|
+
const pagedData = React.useMemo(() => {
|
|
284
|
+
if (!enablePagination || manualPagination) return sortedData;
|
|
285
|
+
const start = resolvedPageIndex * pageSize;
|
|
286
|
+
return sortedData.slice(start, start + pageSize);
|
|
287
|
+
}, [enablePagination, manualPagination, pageSize, resolvedPageIndex, sortedData]);
|
|
288
|
+
const rowIdFor = React.useCallback(
|
|
289
|
+
(row, index) => {
|
|
290
|
+
var _a;
|
|
291
|
+
return (_a = getRowId == null ? void 0 : getRowId(row, index)) != null ? _a : String(index);
|
|
292
|
+
},
|
|
293
|
+
[getRowId]
|
|
294
|
+
);
|
|
295
|
+
const pageStartIndex = enablePagination && !manualPagination ? resolvedPageIndex * pageSize : 0;
|
|
296
|
+
const pageRowIds = pagedData.map(
|
|
297
|
+
(row, index) => rowIdFor(row, pageStartIndex + index)
|
|
298
|
+
);
|
|
299
|
+
const allSelected = pageRowIds.length > 0 && pageRowIds.every((id) => resolvedSelection[id]);
|
|
300
|
+
const someSelected = pageRowIds.some((id) => resolvedSelection[id]);
|
|
301
|
+
const headerCheckboxRef = React.useRef(null);
|
|
302
|
+
React.useEffect(() => {
|
|
303
|
+
if (headerCheckboxRef.current) {
|
|
304
|
+
headerCheckboxRef.current.indeterminate = someSelected && !allSelected;
|
|
305
|
+
}
|
|
306
|
+
}, [someSelected, allSelected]);
|
|
307
|
+
const toggleSort = (column) => {
|
|
308
|
+
if (!enableSorting || column.sortable === false) return;
|
|
309
|
+
const current = resolvedSort;
|
|
310
|
+
if (!current || current.id !== column.id) {
|
|
311
|
+
setSort({ id: column.id, desc: false });
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (!current.desc) {
|
|
315
|
+
setSort({ id: column.id, desc: true });
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
setSort(null);
|
|
319
|
+
};
|
|
320
|
+
const emptyContent = emptyState != null ? emptyState : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "text-center text-sm text-[rgb(var(--nc-fg-muted))]", children: "No results found." });
|
|
321
|
+
const resolvedShowGlobalFilter = showGlobalFilter != null ? showGlobalFilter : enableFiltering && !toolbar;
|
|
322
|
+
const setGlobalFilter = (next) => {
|
|
323
|
+
if (globalFilter === void 0) setInternalGlobalFilter(next);
|
|
324
|
+
onGlobalFilterChange == null ? void 0 : onGlobalFilterChange(next);
|
|
325
|
+
};
|
|
326
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cn("space-y-4", className), "data-nc-theme": tone, children: [
|
|
327
|
+
toolbar,
|
|
328
|
+
resolvedShowGlobalFilter && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center justify-between gap-3 rounded-2xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] px-3 py-2 text-sm text-[rgb(var(--nc-fg))]", children: [
|
|
329
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-xs text-[rgb(var(--nc-fg-muted))]", children: "Global filter" }),
|
|
330
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
331
|
+
"input",
|
|
332
|
+
{
|
|
333
|
+
type: "search",
|
|
334
|
+
value: resolvedGlobalFilter,
|
|
335
|
+
onChange: (event) => setGlobalFilter(event.target.value),
|
|
336
|
+
placeholder: "Search all columns...",
|
|
337
|
+
className: "w-full max-w-xs rounded-xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.18)] px-3 py-2 text-xs text-[rgb(var(--nc-fg))]"
|
|
338
|
+
}
|
|
339
|
+
)
|
|
340
|
+
] }),
|
|
341
|
+
enableColumnVisibility && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "relative flex justify-end", children: [
|
|
342
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
343
|
+
"button",
|
|
344
|
+
{
|
|
345
|
+
type: "button",
|
|
346
|
+
className: "rounded-xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] px-3 py-2 text-xs text-[rgb(var(--nc-fg))] transition hover:bg-[rgb(var(--nc-surface)/0.2)]",
|
|
347
|
+
onClick: () => setShowColumns((prev) => !prev),
|
|
348
|
+
children: "Columns"
|
|
349
|
+
}
|
|
350
|
+
),
|
|
351
|
+
showColumns && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "absolute right-0 top-10 z-20 w-48 rounded-2xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.2)] p-3 shadow-[0_12px_30px_rgba(0,0,0,0.35)] backdrop-blur-2xl", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "grid gap-2", children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
352
|
+
"label",
|
|
353
|
+
{
|
|
354
|
+
className: "flex items-center gap-2 text-xs text-[rgb(var(--nc-fg))]",
|
|
355
|
+
children: [
|
|
356
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
357
|
+
"input",
|
|
358
|
+
{
|
|
359
|
+
type: "checkbox",
|
|
360
|
+
className: "h-4 w-4 accent-[rgb(var(--nc-accent-1))]",
|
|
361
|
+
checked: resolvedVisibility[column.id] !== false,
|
|
362
|
+
onChange: (event) => setVisibility({
|
|
363
|
+
...resolvedVisibility,
|
|
364
|
+
[column.id]: event.target.checked
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
),
|
|
368
|
+
column.header
|
|
369
|
+
]
|
|
370
|
+
},
|
|
371
|
+
column.id
|
|
372
|
+
)) }) })
|
|
373
|
+
] }),
|
|
374
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "overflow-hidden rounded-3xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.08)] shadow-[0_18px_50px_rgba(0,0,0,0.35)] backdrop-blur-2xl", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("table", { className: "w-full border-collapse text-left text-sm", children: [
|
|
375
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { className: "bg-[rgb(var(--nc-surface)/0.12)] text-[rgb(var(--nc-fg-muted))]", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { children: [
|
|
376
|
+
enableRowSelection && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-12 px-4 py-3", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
377
|
+
"input",
|
|
378
|
+
{
|
|
379
|
+
ref: headerCheckboxRef,
|
|
380
|
+
type: "checkbox",
|
|
381
|
+
className: "h-4 w-4 accent-[rgb(var(--nc-accent-1))]",
|
|
382
|
+
checked: allSelected,
|
|
383
|
+
onChange: (event) => {
|
|
384
|
+
const next = { ...resolvedSelection };
|
|
385
|
+
pageRowIds.forEach((id) => {
|
|
386
|
+
next[id] = event.target.checked;
|
|
387
|
+
});
|
|
388
|
+
setSelection(next);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
) }),
|
|
392
|
+
visibleColumns.map((column) => {
|
|
393
|
+
var _a;
|
|
394
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
395
|
+
"th",
|
|
396
|
+
{
|
|
397
|
+
className: cn(
|
|
398
|
+
"px-4 py-3 text-xs font-semibold uppercase tracking-[0.2em]",
|
|
399
|
+
column.headerClassName
|
|
400
|
+
),
|
|
401
|
+
style: { width: column.width },
|
|
402
|
+
children: [
|
|
403
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
404
|
+
"button",
|
|
405
|
+
{
|
|
406
|
+
type: "button",
|
|
407
|
+
className: cn(
|
|
408
|
+
"flex items-center gap-2",
|
|
409
|
+
enableSorting && column.sortable !== false ? "cursor-pointer" : "cursor-default"
|
|
410
|
+
),
|
|
411
|
+
onClick: () => toggleSort(column),
|
|
412
|
+
children: [
|
|
413
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: column.header }),
|
|
414
|
+
(resolvedSort == null ? void 0 : resolvedSort.id) === column.id && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[rgb(var(--nc-accent-1))]", children: resolvedSort.desc ? "\u2193" : "\u2191" })
|
|
415
|
+
]
|
|
416
|
+
}
|
|
417
|
+
),
|
|
418
|
+
enableFiltering && column.filterable !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
419
|
+
"input",
|
|
420
|
+
{
|
|
421
|
+
type: "text",
|
|
422
|
+
value: (_a = resolvedFilters[column.id]) != null ? _a : "",
|
|
423
|
+
onChange: (event) => setFilters({
|
|
424
|
+
...resolvedFilters,
|
|
425
|
+
[column.id]: event.target.value
|
|
426
|
+
}),
|
|
427
|
+
placeholder: "Filter",
|
|
428
|
+
className: "mt-2 w-full rounded-xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.18)] px-2 py-1 text-xs text-[rgb(var(--nc-fg))]"
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
]
|
|
432
|
+
},
|
|
433
|
+
column.id
|
|
434
|
+
);
|
|
435
|
+
})
|
|
436
|
+
] }) }),
|
|
437
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tbody", { className: "text-[rgb(var(--nc-fg))]", children: [
|
|
438
|
+
loading && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
439
|
+
"td",
|
|
440
|
+
{
|
|
441
|
+
colSpan: visibleColumns.length + (enableRowSelection ? 1 : 0),
|
|
442
|
+
className: "px-4 py-10 text-center text-sm text-[rgb(var(--nc-fg-muted))]",
|
|
443
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "inline-flex items-center gap-2", children: [
|
|
444
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "h-4 w-4 animate-spin rounded-full border-2 border-[rgb(var(--nc-fg-muted))] border-t-transparent" }),
|
|
445
|
+
"Loading data..."
|
|
446
|
+
] })
|
|
447
|
+
}
|
|
448
|
+
) }),
|
|
449
|
+
!loading && pagedData.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
450
|
+
"td",
|
|
451
|
+
{
|
|
452
|
+
colSpan: visibleColumns.length + (enableRowSelection ? 1 : 0),
|
|
453
|
+
className: "px-4 py-10",
|
|
454
|
+
children: emptyContent
|
|
455
|
+
}
|
|
456
|
+
) }),
|
|
457
|
+
!loading && pagedData.map((row, rowIndex) => {
|
|
458
|
+
const rowId = rowIdFor(row, pageStartIndex + rowIndex);
|
|
459
|
+
const isSelected = resolvedSelection[rowId];
|
|
460
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
461
|
+
"tr",
|
|
462
|
+
{
|
|
463
|
+
className: cn(
|
|
464
|
+
"border-t border-[rgb(var(--nc-border)/0.15)]",
|
|
465
|
+
isSelected && "bg-[rgb(var(--nc-accent-1)/0.08)]"
|
|
466
|
+
),
|
|
467
|
+
children: [
|
|
468
|
+
enableRowSelection && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { className: "px-4 py-4", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
469
|
+
"input",
|
|
470
|
+
{
|
|
471
|
+
type: "checkbox",
|
|
472
|
+
className: "h-4 w-4 accent-[rgb(var(--nc-accent-1))]",
|
|
473
|
+
checked: isSelected,
|
|
474
|
+
onChange: (event) => setSelection({
|
|
475
|
+
...resolvedSelection,
|
|
476
|
+
[rowId]: event.target.checked
|
|
477
|
+
})
|
|
478
|
+
}
|
|
479
|
+
) }),
|
|
480
|
+
visibleColumns.map((column) => {
|
|
481
|
+
var _a;
|
|
482
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
483
|
+
"td",
|
|
484
|
+
{
|
|
485
|
+
className: cn(
|
|
486
|
+
"px-4 py-4",
|
|
487
|
+
column.align === "center" && "text-center",
|
|
488
|
+
column.align === "right" && "text-right",
|
|
489
|
+
column.cellClassName
|
|
490
|
+
),
|
|
491
|
+
children: column.cell ? column.cell(row) : String((_a = getColumnValue(column, row)) != null ? _a : "")
|
|
492
|
+
},
|
|
493
|
+
column.id
|
|
494
|
+
);
|
|
495
|
+
})
|
|
496
|
+
]
|
|
497
|
+
},
|
|
498
|
+
rowId
|
|
499
|
+
);
|
|
500
|
+
})
|
|
501
|
+
] })
|
|
502
|
+
] }) }),
|
|
503
|
+
enablePagination && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
504
|
+
CraftPagination,
|
|
505
|
+
{
|
|
506
|
+
pageIndex: resolvedPageIndex,
|
|
507
|
+
pageCount: resolvedPageCount,
|
|
508
|
+
onPageChange: setPageIndex,
|
|
509
|
+
pageSize,
|
|
510
|
+
onPageSizeChange,
|
|
511
|
+
tone
|
|
512
|
+
}
|
|
513
|
+
)
|
|
514
|
+
] });
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/components/craft-input.tsx
|
|
518
|
+
var React2 = __toESM(require("react"), 1);
|
|
519
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
520
|
+
var inputSizeClasses = {
|
|
521
|
+
sm: "h-10 px-4 text-sm",
|
|
522
|
+
md: "h-12 px-5 text-base",
|
|
523
|
+
lg: "h-14 px-6 text-lg"
|
|
524
|
+
};
|
|
525
|
+
var CraftInput = React2.forwardRef(
|
|
526
|
+
({ className, tone, inputSize = "md", glow = true, icon, ...props }, ref) => {
|
|
527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "relative w-full", "data-nc-theme": tone, children: [
|
|
528
|
+
icon && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "absolute left-4 top-1/2 -translate-y-1/2 text-[rgb(var(--nc-fg-soft))]", children: icon }),
|
|
529
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
530
|
+
"input",
|
|
531
|
+
{
|
|
532
|
+
ref,
|
|
533
|
+
className: cn(
|
|
534
|
+
"w-full rounded-2xl border-2 bg-[rgb(var(--nc-surface)/0.08)] text-[rgb(var(--nc-fg))] backdrop-blur-xl",
|
|
535
|
+
"shadow-[inset_0_2px_8px_rgba(0,0,0,0.3)]",
|
|
536
|
+
"focus:outline-none focus:ring-4",
|
|
537
|
+
"transition-all duration-300",
|
|
538
|
+
"disabled:opacity-50 disabled:cursor-not-allowed",
|
|
539
|
+
inputSizeClasses[inputSize],
|
|
540
|
+
"border-[rgb(var(--nc-border)/0.35)]",
|
|
541
|
+
"focus:border-[rgb(var(--nc-accent-1)/0.8)] focus:ring-[rgb(var(--nc-accent-1)/0.3)]",
|
|
542
|
+
"placeholder:text-[rgb(var(--nc-fg-soft))]",
|
|
543
|
+
glow ? "focus:shadow-[0_0_30px_-5px_var(--glow-color)]" : "",
|
|
544
|
+
icon ? "pl-12" : "",
|
|
545
|
+
className
|
|
546
|
+
),
|
|
547
|
+
style: {
|
|
548
|
+
"--glow-color": "rgb(var(--nc-accent-1) / 0.5)"
|
|
549
|
+
},
|
|
550
|
+
...props
|
|
551
|
+
}
|
|
552
|
+
)
|
|
553
|
+
] });
|
|
554
|
+
}
|
|
555
|
+
);
|
|
556
|
+
CraftInput.displayName = "CraftInput";
|
|
557
|
+
|
|
558
|
+
// src/components/craft-filter-bar.tsx
|
|
559
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
560
|
+
function CraftFilterBar({
|
|
561
|
+
title,
|
|
562
|
+
description,
|
|
563
|
+
searchValue,
|
|
564
|
+
onSearchChange,
|
|
565
|
+
searchPlaceholder = "Search...",
|
|
566
|
+
actions,
|
|
567
|
+
filters,
|
|
568
|
+
tone,
|
|
569
|
+
className
|
|
570
|
+
}) {
|
|
571
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
572
|
+
"div",
|
|
573
|
+
{
|
|
574
|
+
className: cn(
|
|
575
|
+
"rounded-3xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] p-4 text-[rgb(var(--nc-fg))] shadow-[0_12px_36px_rgba(0,0,0,0.2)] backdrop-blur-2xl",
|
|
576
|
+
className
|
|
577
|
+
),
|
|
578
|
+
"data-nc-theme": tone,
|
|
579
|
+
children: [
|
|
580
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [
|
|
581
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
|
|
582
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h3", { className: "text-lg font-semibold", children: title }),
|
|
583
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "text-sm text-[rgb(var(--nc-fg-muted))]", children: description })
|
|
584
|
+
] }),
|
|
585
|
+
actions && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex items-center gap-3", children: actions })
|
|
586
|
+
] }),
|
|
587
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "mt-4 grid gap-4 md:grid-cols-[minmax(0,1fr)_auto]", children: [
|
|
588
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
589
|
+
CraftInput,
|
|
590
|
+
{
|
|
591
|
+
type: "search",
|
|
592
|
+
placeholder: searchPlaceholder,
|
|
593
|
+
value: searchValue != null ? searchValue : "",
|
|
594
|
+
onChange: (event) => onSearchChange == null ? void 0 : onSearchChange(event.target.value),
|
|
595
|
+
tone
|
|
596
|
+
}
|
|
597
|
+
),
|
|
598
|
+
filters && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "flex flex-wrap items-center gap-3", children: filters })
|
|
599
|
+
] })
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// src/components/craft-table-toolbar.tsx
|
|
606
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
607
|
+
function CraftTableToolbar({
|
|
608
|
+
title,
|
|
609
|
+
description,
|
|
610
|
+
searchValue,
|
|
611
|
+
onSearchChange,
|
|
612
|
+
searchPlaceholder = "Search table...",
|
|
613
|
+
actions,
|
|
614
|
+
filters,
|
|
615
|
+
bulkActions,
|
|
616
|
+
tone,
|
|
617
|
+
className
|
|
618
|
+
}) {
|
|
619
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
620
|
+
"div",
|
|
621
|
+
{
|
|
622
|
+
className: cn(
|
|
623
|
+
"rounded-3xl border border-[rgb(var(--nc-border)/0.3)] bg-[rgb(var(--nc-surface)/0.12)] p-4 text-[rgb(var(--nc-fg))] shadow-[0_12px_36px_rgba(0,0,0,0.2)] backdrop-blur-2xl",
|
|
624
|
+
className
|
|
625
|
+
),
|
|
626
|
+
"data-nc-theme": tone,
|
|
627
|
+
children: [
|
|
628
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [
|
|
629
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
630
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { className: "text-lg font-semibold", children: title }),
|
|
631
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-sm text-[rgb(var(--nc-fg-muted))]", children: description })
|
|
632
|
+
] }),
|
|
633
|
+
actions && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex items-center gap-3", children: actions })
|
|
634
|
+
] }),
|
|
635
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mt-4 grid gap-4 lg:grid-cols-[minmax(0,1fr)_auto]", children: [
|
|
636
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
637
|
+
CraftInput,
|
|
638
|
+
{
|
|
639
|
+
type: "search",
|
|
640
|
+
placeholder: searchPlaceholder,
|
|
641
|
+
value: searchValue != null ? searchValue : "",
|
|
642
|
+
onChange: (event) => onSearchChange == null ? void 0 : onSearchChange(event.target.value),
|
|
643
|
+
tone
|
|
644
|
+
}
|
|
645
|
+
),
|
|
646
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
647
|
+
filters,
|
|
648
|
+
bulkActions
|
|
649
|
+
] })
|
|
650
|
+
] })
|
|
651
|
+
]
|
|
652
|
+
}
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
656
|
+
0 && (module.exports = {
|
|
657
|
+
CraftDataTable,
|
|
658
|
+
CraftFilterBar,
|
|
659
|
+
CraftPagination,
|
|
660
|
+
CraftTableToolbar
|
|
661
|
+
});
|
|
662
|
+
//# sourceMappingURL=table.cjs.map
|