@eztrak/shared 0.7.2 → 0.7.4
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/{chunk-BLCEEXZR.mjs → chunk-FSCPBM3X.mjs} +100 -74
- package/dist/chunk-FSCPBM3X.mjs.map +1 -0
- package/dist/components/index.d.mts +34 -5
- package/dist/components/index.d.ts +34 -5
- package/dist/components/index.js +98 -73
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/index.js +98 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-BLCEEXZR.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1319,15 +1319,14 @@ function Modal({
|
|
|
1319
1319
|
// src/components/cell-editor/CustomCellEditor.tsx
|
|
1320
1320
|
var import_react6 = require("react");
|
|
1321
1321
|
var import_react_hot_toast2 = __toESM(require("react-hot-toast"));
|
|
1322
|
-
var import_fa2 = require("react-icons/fa");
|
|
1323
1322
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1324
1323
|
function ButtonSpinner() {
|
|
1325
1324
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1326
1325
|
"svg",
|
|
1327
1326
|
{
|
|
1328
1327
|
className: "animate-spin",
|
|
1329
|
-
width:
|
|
1330
|
-
height:
|
|
1328
|
+
width: 12,
|
|
1329
|
+
height: 12,
|
|
1331
1330
|
viewBox: "0 0 24 24",
|
|
1332
1331
|
fill: "none",
|
|
1333
1332
|
"aria-hidden": true,
|
|
@@ -1374,47 +1373,60 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
|
|
|
1374
1373
|
entityId,
|
|
1375
1374
|
entityName = "Record",
|
|
1376
1375
|
onSave,
|
|
1377
|
-
dropdownOptions = []
|
|
1376
|
+
dropdownOptions = [],
|
|
1377
|
+
customOptions,
|
|
1378
|
+
valueKey = "value",
|
|
1379
|
+
labelKey = "label",
|
|
1380
|
+
containerStyle,
|
|
1381
|
+
className,
|
|
1382
|
+
inputClassName,
|
|
1383
|
+
loadingIndicator,
|
|
1384
|
+
saveButtonContent,
|
|
1385
|
+
cancelButtonContent,
|
|
1386
|
+
saveButtonStyle,
|
|
1387
|
+
cancelButtonStyle,
|
|
1388
|
+
saveButtonClassName,
|
|
1389
|
+
cancelButtonClassName
|
|
1378
1390
|
}, ref) => {
|
|
1379
1391
|
const normalizedInitial = normalizeInitialValue(initialValue, inputType);
|
|
1380
1392
|
const [value, setValue] = (0, import_react6.useState)(normalizedInitial);
|
|
1381
1393
|
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
1382
1394
|
const inputRef = (0, import_react6.useRef)(null);
|
|
1383
1395
|
const selectRef = (0, import_react6.useRef)(null);
|
|
1396
|
+
const normalizedOptions = (0, import_react6.useMemo)(() => {
|
|
1397
|
+
if (customOptions && customOptions.length > 0) {
|
|
1398
|
+
return customOptions.map((opt) => ({
|
|
1399
|
+
value: String(opt[valueKey] ?? ""),
|
|
1400
|
+
label: String(opt[labelKey] ?? "")
|
|
1401
|
+
}));
|
|
1402
|
+
}
|
|
1403
|
+
return dropdownOptions;
|
|
1404
|
+
}, [customOptions, dropdownOptions, valueKey, labelKey]);
|
|
1405
|
+
const isDropdown = inputType === "dropdown" || normalizedOptions.length > 0;
|
|
1384
1406
|
(0, import_react6.useImperativeHandle)(ref, () => ({
|
|
1385
1407
|
getValue: () => value,
|
|
1386
1408
|
isCancelBeforeStart: () => false,
|
|
1387
|
-
isCancelAfterEnd: () => false
|
|
1409
|
+
isCancelAfterEnd: () => false,
|
|
1410
|
+
isPopup: () => true
|
|
1388
1411
|
}));
|
|
1389
1412
|
(0, import_react6.useEffect)(() => {
|
|
1390
|
-
if (
|
|
1391
|
-
|
|
1392
|
-
if (el2) {
|
|
1393
|
-
el2.focus();
|
|
1394
|
-
}
|
|
1413
|
+
if (isDropdown) {
|
|
1414
|
+
selectRef.current?.focus();
|
|
1395
1415
|
return;
|
|
1396
1416
|
}
|
|
1397
1417
|
const el = inputRef.current;
|
|
1398
|
-
if (!el)
|
|
1399
|
-
return;
|
|
1400
|
-
}
|
|
1418
|
+
if (!el) return;
|
|
1401
1419
|
el.focus();
|
|
1402
1420
|
if (inputType !== "date") {
|
|
1403
1421
|
el.select();
|
|
1404
1422
|
}
|
|
1405
|
-
}, [inputType]);
|
|
1423
|
+
}, [isDropdown, inputType]);
|
|
1406
1424
|
const handleSave = async () => {
|
|
1407
|
-
if (isLoading)
|
|
1408
|
-
return;
|
|
1409
|
-
}
|
|
1425
|
+
if (isLoading) return;
|
|
1410
1426
|
if (String(value) === String(normalizedInitial)) {
|
|
1411
1427
|
stopEditing();
|
|
1412
1428
|
return;
|
|
1413
1429
|
}
|
|
1414
|
-
if (!entityId) {
|
|
1415
|
-
import_react_hot_toast2.default.error("Entity ID is required");
|
|
1416
|
-
return;
|
|
1417
|
-
}
|
|
1418
1430
|
if (!name) {
|
|
1419
1431
|
import_react_hot_toast2.default.error("Property name is required");
|
|
1420
1432
|
return;
|
|
@@ -1463,59 +1475,72 @@ var CustomCellEditor = (0, import_react6.forwardRef)(
|
|
|
1463
1475
|
setValue(event.target.value);
|
|
1464
1476
|
};
|
|
1465
1477
|
const isSaveDisabled = isLoading || String(value) === String(normalizedInitial);
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
className
|
|
1475
|
-
disabled: isLoading,
|
|
1476
|
-
children: [
|
|
1477
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", disabled: true, children: "Select option..." }),
|
|
1478
|
-
dropdownOptions.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
|
|
1479
|
-
]
|
|
1480
|
-
}
|
|
1481
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1482
|
-
"input",
|
|
1483
|
-
{
|
|
1484
|
-
ref: inputRef,
|
|
1485
|
-
type: inputType,
|
|
1486
|
-
value: String(value),
|
|
1487
|
-
onChange: handleInputChange,
|
|
1488
|
-
onKeyDown: handleKeyDown,
|
|
1489
|
-
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",
|
|
1490
|
-
placeholder: "...",
|
|
1491
|
-
disabled: isLoading
|
|
1492
|
-
}
|
|
1493
|
-
),
|
|
1494
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center shrink-0 gap-0.5", children: [
|
|
1495
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1496
|
-
"button",
|
|
1497
|
-
{
|
|
1498
|
-
type: "button",
|
|
1499
|
-
onClick: handleSave,
|
|
1500
|
-
disabled: isSaveDisabled,
|
|
1501
|
-
className: "flex items-center justify-center w-4 h-4 text-white bg-green-500 rounded-sm hover:bg-green-600 disabled:opacity-50",
|
|
1502
|
-
title: "Save (Enter)",
|
|
1503
|
-
children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ButtonSpinner, {}) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_fa2.FaCheck, { size: 7, "aria-hidden": true })
|
|
1504
|
-
}
|
|
1478
|
+
const defaultInputClass = "w-48 px-2 py-1 text-sm border border-gray-200 rounded-md bg-white focus:outline-none focus:ring-1 focus:ring-blue-400";
|
|
1479
|
+
const defaultSaveBtnClass = "px-3 py-1 text-sm font-medium text-white bg-green-500 rounded-md hover:bg-green-600 disabled:opacity-50 whitespace-nowrap shrink-0";
|
|
1480
|
+
const defaultCancelBtnClass = "px-3 py-1 text-sm font-medium text-white bg-red-500 rounded-md hover:bg-red-600 disabled:opacity-50 whitespace-nowrap shrink-0";
|
|
1481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1482
|
+
"div",
|
|
1483
|
+
{
|
|
1484
|
+
className: cn(
|
|
1485
|
+
"flex items-center gap-2 px-2 py-1 min-w-[320px] bg-white border border-gray-200 rounded-md shadow-md",
|
|
1486
|
+
className
|
|
1505
1487
|
),
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1488
|
+
style: containerStyle,
|
|
1489
|
+
children: [
|
|
1490
|
+
isDropdown ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1491
|
+
"select",
|
|
1492
|
+
{
|
|
1493
|
+
ref: selectRef,
|
|
1494
|
+
value: String(value),
|
|
1495
|
+
onChange: handleDropdownChange,
|
|
1496
|
+
onKeyDown: handleKeyDown,
|
|
1497
|
+
className: inputClassName ?? defaultInputClass,
|
|
1498
|
+
disabled: isLoading,
|
|
1499
|
+
children: [
|
|
1500
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", disabled: true, children: "Select option..." }),
|
|
1501
|
+
normalizedOptions.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: opt.value, children: opt.label }, opt.value))
|
|
1502
|
+
]
|
|
1503
|
+
}
|
|
1504
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1505
|
+
"input",
|
|
1506
|
+
{
|
|
1507
|
+
ref: inputRef,
|
|
1508
|
+
type: inputType,
|
|
1509
|
+
value: String(value),
|
|
1510
|
+
onChange: handleInputChange,
|
|
1511
|
+
onKeyDown: handleKeyDown,
|
|
1512
|
+
className: inputClassName ?? defaultInputClass,
|
|
1513
|
+
placeholder: "...",
|
|
1514
|
+
disabled: isLoading
|
|
1515
|
+
}
|
|
1516
|
+
),
|
|
1517
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1518
|
+
"button",
|
|
1519
|
+
{
|
|
1520
|
+
type: "button",
|
|
1521
|
+
onClick: handleSave,
|
|
1522
|
+
disabled: isSaveDisabled,
|
|
1523
|
+
className: saveButtonClassName ?? (saveButtonStyle ? void 0 : defaultSaveBtnClass),
|
|
1524
|
+
style: saveButtonStyle,
|
|
1525
|
+
title: "Save (Enter)",
|
|
1526
|
+
children: isLoading ? loadingIndicator ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ButtonSpinner, {}) : saveButtonContent ?? "Save"
|
|
1527
|
+
}
|
|
1528
|
+
),
|
|
1529
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1530
|
+
"button",
|
|
1531
|
+
{
|
|
1532
|
+
type: "button",
|
|
1533
|
+
onClick: handleCancel,
|
|
1534
|
+
disabled: isLoading,
|
|
1535
|
+
className: cancelButtonClassName ?? (cancelButtonStyle ? void 0 : defaultCancelBtnClass),
|
|
1536
|
+
style: cancelButtonStyle,
|
|
1537
|
+
title: "Cancel (Escape)",
|
|
1538
|
+
children: cancelButtonContent ?? "Cancel"
|
|
1539
|
+
}
|
|
1540
|
+
)
|
|
1541
|
+
]
|
|
1542
|
+
}
|
|
1543
|
+
);
|
|
1519
1544
|
}
|
|
1520
1545
|
);
|
|
1521
1546
|
CustomCellEditor.displayName = "CustomCellEditor";
|