@eztrak/shared 0.7.0 → 0.7.3
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 +228 -9
- package/dist/chunk-GED6IT3S.mjs +1 -0
- package/dist/chunk-GED6IT3S.mjs.map +1 -0
- package/dist/{chunk-GIBPOQGL.mjs → chunk-GVIHLI67.mjs} +81 -2
- package/dist/chunk-GVIHLI67.mjs.map +1 -0
- package/dist/{chunk-J6FBBM4R.mjs → chunk-KQHEJS62.mjs} +227 -5
- package/dist/chunk-KQHEJS62.mjs.map +1 -0
- package/dist/components/index.d.mts +31 -1
- package/dist/components/index.d.ts +31 -1
- package/dist/components/index.js +239 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +217 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -21
- package/dist/utils/index.mjs +6 -7
- package/package.json +1 -1
- package/dist/chunk-5OG22DIX.mjs +0 -82
- package/dist/chunk-5OG22DIX.mjs.map +0 -1
- package/dist/chunk-GIBPOQGL.mjs.map +0 -1
- package/dist/chunk-J6FBBM4R.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
CustomCellEditor: () => CustomCellEditor,
|
|
33
34
|
CustomPagination: () => CustomPagination,
|
|
34
35
|
EztrakTabs: () => EztrakTabs,
|
|
35
36
|
Loader: () => Loader,
|
|
@@ -1078,7 +1079,7 @@ function SearchInput({
|
|
|
1078
1079
|
{
|
|
1079
1080
|
onSubmit: handleSearch,
|
|
1080
1081
|
className: cn(
|
|
1081
|
-
"flex items-center justify-between bg-white rounded-
|
|
1082
|
+
"flex items-center justify-between bg-white rounded-xl px-2 h-11 border",
|
|
1082
1083
|
searchWrapperClass
|
|
1083
1084
|
),
|
|
1084
1085
|
children: [
|
|
@@ -1314,8 +1315,223 @@ function Modal({
|
|
|
1314
1315
|
}
|
|
1315
1316
|
return (0, import_react_dom.createPortal)(modalContent, modalRoot);
|
|
1316
1317
|
}
|
|
1318
|
+
|
|
1319
|
+
// src/components/cell-editor/CustomCellEditor.tsx
|
|
1320
|
+
var import_react6 = require("react");
|
|
1321
|
+
var import_react_hot_toast2 = __toESM(require("react-hot-toast"));
|
|
1322
|
+
var import_fa2 = require("react-icons/fa");
|
|
1323
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1324
|
+
function ButtonSpinner() {
|
|
1325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1326
|
+
"svg",
|
|
1327
|
+
{
|
|
1328
|
+
className: "animate-spin",
|
|
1329
|
+
width: 8,
|
|
1330
|
+
height: 8,
|
|
1331
|
+
viewBox: "0 0 24 24",
|
|
1332
|
+
fill: "none",
|
|
1333
|
+
"aria-hidden": true,
|
|
1334
|
+
children: [
|
|
1335
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1336
|
+
"circle",
|
|
1337
|
+
{
|
|
1338
|
+
cx: "12",
|
|
1339
|
+
cy: "12",
|
|
1340
|
+
r: "10",
|
|
1341
|
+
stroke: "white",
|
|
1342
|
+
strokeWidth: "4",
|
|
1343
|
+
strokeOpacity: "0.25"
|
|
1344
|
+
}
|
|
1345
|
+
),
|
|
1346
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1347
|
+
"path",
|
|
1348
|
+
{
|
|
1349
|
+
d: "M12 2a10 10 0 0 1 10 10",
|
|
1350
|
+
stroke: "white",
|
|
1351
|
+
strokeWidth: "4",
|
|
1352
|
+
strokeLinecap: "round"
|
|
1353
|
+
}
|
|
1354
|
+
)
|
|
1355
|
+
]
|
|
1356
|
+
}
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
function normalizeInitialValue(initialValue, inputType) {
|
|
1360
|
+
if (inputType === "date" && initialValue != null && initialValue !== "") {
|
|
1361
|
+
return toDateInputValue(String(initialValue));
|
|
1362
|
+
}
|
|
1363
|
+
if (initialValue == null) {
|
|
1364
|
+
return "";
|
|
1365
|
+
}
|
|
1366
|
+
return initialValue;
|
|
1367
|
+
}
|
|
1368
|
+
var CustomCellEditor = (0, import_react6.forwardRef)(
|
|
1369
|
+
({
|
|
1370
|
+
value: initialValue,
|
|
1371
|
+
name,
|
|
1372
|
+
inputType = "text",
|
|
1373
|
+
stopEditing,
|
|
1374
|
+
entityId,
|
|
1375
|
+
entityName = "Record",
|
|
1376
|
+
onSave,
|
|
1377
|
+
dropdownOptions = [],
|
|
1378
|
+
className
|
|
1379
|
+
}, ref) => {
|
|
1380
|
+
const normalizedInitial = normalizeInitialValue(initialValue, inputType);
|
|
1381
|
+
const [value, setValue] = (0, import_react6.useState)(normalizedInitial);
|
|
1382
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
1383
|
+
const inputRef = (0, import_react6.useRef)(null);
|
|
1384
|
+
const selectRef = (0, import_react6.useRef)(null);
|
|
1385
|
+
(0, import_react6.useImperativeHandle)(ref, () => ({
|
|
1386
|
+
getValue: () => value,
|
|
1387
|
+
isCancelBeforeStart: () => false,
|
|
1388
|
+
isCancelAfterEnd: () => false
|
|
1389
|
+
}));
|
|
1390
|
+
(0, import_react6.useEffect)(() => {
|
|
1391
|
+
if (inputType === "dropdown") {
|
|
1392
|
+
const el2 = selectRef.current;
|
|
1393
|
+
if (el2) {
|
|
1394
|
+
el2.focus();
|
|
1395
|
+
}
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
const el = inputRef.current;
|
|
1399
|
+
if (!el) {
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
el.focus();
|
|
1403
|
+
if (inputType !== "date") {
|
|
1404
|
+
el.select();
|
|
1405
|
+
}
|
|
1406
|
+
}, [inputType]);
|
|
1407
|
+
const handleSave = async () => {
|
|
1408
|
+
if (isLoading) {
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (String(value) === String(normalizedInitial)) {
|
|
1412
|
+
stopEditing();
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
if (!entityId) {
|
|
1416
|
+
import_react_hot_toast2.default.error("Entity ID is required");
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
if (!name) {
|
|
1420
|
+
import_react_hot_toast2.default.error("Property name is required");
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
setIsLoading(true);
|
|
1424
|
+
const payloadValue = inputType === "number" && value !== "" ? parseFloat(String(value)) : value;
|
|
1425
|
+
const payload = {
|
|
1426
|
+
propertyName: name,
|
|
1427
|
+
propertyValue: payloadValue,
|
|
1428
|
+
entityId,
|
|
1429
|
+
entityName
|
|
1430
|
+
};
|
|
1431
|
+
try {
|
|
1432
|
+
await onSave(payload);
|
|
1433
|
+
import_react_hot_toast2.default.success("Record updated successfully");
|
|
1434
|
+
stopEditing();
|
|
1435
|
+
} catch (error) {
|
|
1436
|
+
console.error("Update error:", error);
|
|
1437
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to update record";
|
|
1438
|
+
import_react_hot_toast2.default.error(errorMessage);
|
|
1439
|
+
} finally {
|
|
1440
|
+
setIsLoading(false);
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
const handleCancel = () => {
|
|
1444
|
+
setValue(normalizedInitial);
|
|
1445
|
+
stopEditing();
|
|
1446
|
+
};
|
|
1447
|
+
const handleKeyDown = (event) => {
|
|
1448
|
+
if (event.key === "Enter") {
|
|
1449
|
+
event.preventDefault();
|
|
1450
|
+
handleSave();
|
|
1451
|
+
} else if (event.key === "Escape") {
|
|
1452
|
+
event.preventDefault();
|
|
1453
|
+
handleCancel();
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
const handleInputChange = (event) => {
|
|
1457
|
+
let newValue = event.target.value;
|
|
1458
|
+
if (inputType === "number") {
|
|
1459
|
+
newValue = newValue.replace(/[^0-9.-]/g, "");
|
|
1460
|
+
}
|
|
1461
|
+
setValue(newValue);
|
|
1462
|
+
};
|
|
1463
|
+
const handleDropdownChange = (event) => {
|
|
1464
|
+
setValue(event.target.value);
|
|
1465
|
+
};
|
|
1466
|
+
const isSaveDisabled = isLoading || String(value) === String(normalizedInitial);
|
|
1467
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1468
|
+
"div",
|
|
1469
|
+
{
|
|
1470
|
+
className: cn(
|
|
1471
|
+
"flex items-center w-full h-full min-h-0 overflow-hidden gap-0.5 min-w-[80px]",
|
|
1472
|
+
className
|
|
1473
|
+
),
|
|
1474
|
+
children: [
|
|
1475
|
+
inputType === "dropdown" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1476
|
+
"select",
|
|
1477
|
+
{
|
|
1478
|
+
ref: selectRef,
|
|
1479
|
+
value: String(value),
|
|
1480
|
+
onChange: handleDropdownChange,
|
|
1481
|
+
onKeyDown: handleKeyDown,
|
|
1482
|
+
className: "flex-1 h-full p-0 text-[10px] border border-gray-300 rounded-sm focus:outline-none focus:ring-1 focus:ring-blue-400 min-w-0 truncate",
|
|
1483
|
+
disabled: isLoading,
|
|
1484
|
+
children: [
|
|
1485
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", disabled: true, children: "Select option..." }),
|
|
1486
|
+
dropdownOptions.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
|
|
1487
|
+
]
|
|
1488
|
+
}
|
|
1489
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1490
|
+
"input",
|
|
1491
|
+
{
|
|
1492
|
+
ref: inputRef,
|
|
1493
|
+
type: inputType,
|
|
1494
|
+
value: String(value),
|
|
1495
|
+
onChange: handleInputChange,
|
|
1496
|
+
onKeyDown: handleKeyDown,
|
|
1497
|
+
className: "flex-1 h-full p-0 text-[10px] border border-gray-300 rounded-sm focus:outline-none focus:ring-1 focus:ring-blue-400 min-w-0 truncate",
|
|
1498
|
+
placeholder: "...",
|
|
1499
|
+
disabled: isLoading
|
|
1500
|
+
}
|
|
1501
|
+
),
|
|
1502
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center shrink-0 gap-0.5", children: [
|
|
1503
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1504
|
+
"button",
|
|
1505
|
+
{
|
|
1506
|
+
type: "button",
|
|
1507
|
+
onClick: handleSave,
|
|
1508
|
+
disabled: isSaveDisabled,
|
|
1509
|
+
className: "flex items-center justify-center w-4 h-4 text-white bg-green-500 rounded-sm hover:bg-green-600 disabled:opacity-50",
|
|
1510
|
+
title: "Save (Enter)",
|
|
1511
|
+
children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ButtonSpinner, {}) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_fa2.FaCheck, { size: 7, "aria-hidden": true })
|
|
1512
|
+
}
|
|
1513
|
+
),
|
|
1514
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1515
|
+
"button",
|
|
1516
|
+
{
|
|
1517
|
+
type: "button",
|
|
1518
|
+
onClick: handleCancel,
|
|
1519
|
+
disabled: isLoading,
|
|
1520
|
+
className: "flex items-center justify-center w-4 h-4 text-white bg-red-500 rounded-sm hover:bg-red-600 disabled:opacity-50",
|
|
1521
|
+
title: "Cancel (Escape)",
|
|
1522
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_fa2.FaTimes, { size: 7, "aria-hidden": true })
|
|
1523
|
+
}
|
|
1524
|
+
)
|
|
1525
|
+
] })
|
|
1526
|
+
]
|
|
1527
|
+
}
|
|
1528
|
+
);
|
|
1529
|
+
}
|
|
1530
|
+
);
|
|
1531
|
+
CustomCellEditor.displayName = "CustomCellEditor";
|
|
1317
1532
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1318
1533
|
0 && (module.exports = {
|
|
1534
|
+
CustomCellEditor,
|
|
1319
1535
|
CustomPagination,
|
|
1320
1536
|
EztrakTabs,
|
|
1321
1537
|
Loader,
|