@apteva/apteva-kit 0.1.111 → 0.1.112
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/index.js +82 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1439,7 +1439,74 @@ function Table({ widget, onAction }) {
|
|
|
1439
1439
|
|
|
1440
1440
|
// src/components/Widgets/widget-library/Form.tsx
|
|
1441
1441
|
|
|
1442
|
-
|
|
1442
|
+
var _reactdom = require('react-dom');
|
|
1443
|
+
|
|
1444
|
+
function PortalDropdown({
|
|
1445
|
+
anchorRef,
|
|
1446
|
+
open,
|
|
1447
|
+
onClose,
|
|
1448
|
+
width,
|
|
1449
|
+
children
|
|
1450
|
+
}) {
|
|
1451
|
+
const dropdownRef = _react.useRef.call(void 0, null);
|
|
1452
|
+
const [pos, setPos] = _react.useState.call(void 0, { top: 0, left: 0, width: 0 });
|
|
1453
|
+
_react.useEffect.call(void 0, () => {
|
|
1454
|
+
if (!open || !anchorRef.current) return;
|
|
1455
|
+
const update = () => {
|
|
1456
|
+
const rect = anchorRef.current.getBoundingClientRect();
|
|
1457
|
+
setPos({
|
|
1458
|
+
top: rect.bottom + window.scrollY + 4,
|
|
1459
|
+
left: rect.left + window.scrollX,
|
|
1460
|
+
width: rect.width
|
|
1461
|
+
});
|
|
1462
|
+
};
|
|
1463
|
+
update();
|
|
1464
|
+
window.addEventListener("scroll", update, true);
|
|
1465
|
+
window.addEventListener("resize", update);
|
|
1466
|
+
return () => {
|
|
1467
|
+
window.removeEventListener("scroll", update, true);
|
|
1468
|
+
window.removeEventListener("resize", update);
|
|
1469
|
+
};
|
|
1470
|
+
}, [open, anchorRef]);
|
|
1471
|
+
_react.useEffect.call(void 0, () => {
|
|
1472
|
+
if (!open) return;
|
|
1473
|
+
const handler = (e) => {
|
|
1474
|
+
const target = e.target;
|
|
1475
|
+
if (dropdownRef.current && !dropdownRef.current.contains(target) && anchorRef.current && !anchorRef.current.contains(target)) {
|
|
1476
|
+
onClose();
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
document.addEventListener("mousedown", handler);
|
|
1480
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
1481
|
+
}, [open, onClose, anchorRef]);
|
|
1482
|
+
_react.useEffect.call(void 0, () => {
|
|
1483
|
+
if (!open) return;
|
|
1484
|
+
const handler = (e) => {
|
|
1485
|
+
if (e.key === "Escape") onClose();
|
|
1486
|
+
};
|
|
1487
|
+
document.addEventListener("keydown", handler);
|
|
1488
|
+
return () => document.removeEventListener("keydown", handler);
|
|
1489
|
+
}, [open, onClose]);
|
|
1490
|
+
if (!open) return null;
|
|
1491
|
+
return _reactdom.createPortal.call(void 0,
|
|
1492
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1493
|
+
"div",
|
|
1494
|
+
{
|
|
1495
|
+
ref: dropdownRef,
|
|
1496
|
+
className: "apteva-widget",
|
|
1497
|
+
style: {
|
|
1498
|
+
position: "absolute",
|
|
1499
|
+
top: pos.top,
|
|
1500
|
+
left: pos.left,
|
|
1501
|
+
width: width === "match" ? pos.width : void 0,
|
|
1502
|
+
zIndex: 99999
|
|
1503
|
+
},
|
|
1504
|
+
children
|
|
1505
|
+
}
|
|
1506
|
+
),
|
|
1507
|
+
document.body
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1443
1510
|
function CustomSelect({
|
|
1444
1511
|
name,
|
|
1445
1512
|
value,
|
|
@@ -1449,17 +1516,10 @@ function CustomSelect({
|
|
|
1449
1516
|
onChange
|
|
1450
1517
|
}) {
|
|
1451
1518
|
const [open, setOpen] = _react.useState.call(void 0, false);
|
|
1452
|
-
const
|
|
1519
|
+
const triggerRef = _react.useRef.call(void 0, null);
|
|
1453
1520
|
const selected = _optionalChain([options, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((o) => o.value === value)]);
|
|
1454
|
-
_react.
|
|
1455
|
-
|
|
1456
|
-
const handler = (e) => {
|
|
1457
|
-
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
1458
|
-
};
|
|
1459
|
-
document.addEventListener("mousedown", handler);
|
|
1460
|
-
return () => document.removeEventListener("mousedown", handler);
|
|
1461
|
-
}, [open]);
|
|
1462
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref, className: "apteva-select relative", children: [
|
|
1521
|
+
const close = _react.useCallback.call(void 0, () => setOpen(false), []);
|
|
1522
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-select relative", children: [
|
|
1463
1523
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1464
1524
|
"select",
|
|
1465
1525
|
{
|
|
@@ -1480,6 +1540,7 @@ function CustomSelect({
|
|
|
1480
1540
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1481
1541
|
"button",
|
|
1482
1542
|
{
|
|
1543
|
+
ref: triggerRef,
|
|
1483
1544
|
type: "button",
|
|
1484
1545
|
onClick: () => setOpen(!open),
|
|
1485
1546
|
className: "apteva-select-trigger w-full flex items-center justify-between px-3 py-2 rounded-lg border transition-colors text-left",
|
|
@@ -1498,14 +1559,14 @@ function CustomSelect({
|
|
|
1498
1559
|
]
|
|
1499
1560
|
}
|
|
1500
1561
|
),
|
|
1501
|
-
open
|
|
1562
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, PortalDropdown, { anchorRef: triggerRef, open, onClose: close, width: "match", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-select-dropdown rounded-lg border shadow-lg overflow-hidden", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "max-h-48 overflow-y-auto py-1", children: [
|
|
1502
1563
|
_optionalChain([options, 'optionalAccess', _22 => _22.map, 'call', _23 => _23((opt) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1503
1564
|
"button",
|
|
1504
1565
|
{
|
|
1505
1566
|
type: "button",
|
|
1506
1567
|
onClick: () => {
|
|
1507
1568
|
onChange(opt.value);
|
|
1508
|
-
|
|
1569
|
+
close();
|
|
1509
1570
|
},
|
|
1510
1571
|
className: `apteva-select-option w-full text-left px-3 py-2 text-sm transition-colors ${opt.value === value ? "apteva-select-option-active" : ""}`,
|
|
1511
1572
|
children: opt.label
|
|
@@ -1513,7 +1574,7 @@ function CustomSelect({
|
|
|
1513
1574
|
opt.value
|
|
1514
1575
|
))]),
|
|
1515
1576
|
(!options || options.length === 0) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-3 py-2 text-sm apteva-select-placeholder", children: "No options" })
|
|
1516
|
-
] }) })
|
|
1577
|
+
] }) }) })
|
|
1517
1578
|
] });
|
|
1518
1579
|
}
|
|
1519
1580
|
function CustomDatePicker({
|
|
@@ -1524,7 +1585,8 @@ function CustomDatePicker({
|
|
|
1524
1585
|
onChange
|
|
1525
1586
|
}) {
|
|
1526
1587
|
const [open, setOpen] = _react.useState.call(void 0, false);
|
|
1527
|
-
const
|
|
1588
|
+
const triggerRef = _react.useRef.call(void 0, null);
|
|
1589
|
+
const close = _react.useCallback.call(void 0, () => setOpen(false), []);
|
|
1528
1590
|
const parseDate = (v) => {
|
|
1529
1591
|
if (v) {
|
|
1530
1592
|
const [y, m, d] = v.split("-").map(Number);
|
|
@@ -1536,14 +1598,6 @@ function CustomDatePicker({
|
|
|
1536
1598
|
const parsed = parseDate(value);
|
|
1537
1599
|
const [viewYear, setViewYear] = _react.useState.call(void 0, parsed.year);
|
|
1538
1600
|
const [viewMonth, setViewMonth] = _react.useState.call(void 0, parsed.month);
|
|
1539
|
-
_react.useEffect.call(void 0, () => {
|
|
1540
|
-
if (!open) return;
|
|
1541
|
-
const handler = (e) => {
|
|
1542
|
-
if (ref.current && !ref.current.contains(e.target)) setOpen(false);
|
|
1543
|
-
};
|
|
1544
|
-
document.addEventListener("mousedown", handler);
|
|
1545
|
-
return () => document.removeEventListener("mousedown", handler);
|
|
1546
|
-
}, [open]);
|
|
1547
1601
|
_react.useEffect.call(void 0, () => {
|
|
1548
1602
|
if (value) {
|
|
1549
1603
|
const p = parseDate(value);
|
|
@@ -1570,7 +1624,7 @@ function CustomDatePicker({
|
|
|
1570
1624
|
const m = String(viewMonth + 1).padStart(2, "0");
|
|
1571
1625
|
const d = String(day).padStart(2, "0");
|
|
1572
1626
|
onChange(`${viewYear}-${m}-${d}`);
|
|
1573
|
-
|
|
1627
|
+
close();
|
|
1574
1628
|
};
|
|
1575
1629
|
const formatDisplay = (v) => {
|
|
1576
1630
|
if (!v) return "";
|
|
@@ -1588,7 +1642,7 @@ function CustomDatePicker({
|
|
|
1588
1642
|
const now = /* @__PURE__ */ new Date();
|
|
1589
1643
|
return now.getFullYear() === viewYear && now.getMonth() === viewMonth && now.getDate() === day;
|
|
1590
1644
|
};
|
|
1591
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
|
|
1645
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker relative", children: [
|
|
1592
1646
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1593
1647
|
"input",
|
|
1594
1648
|
{
|
|
@@ -1606,6 +1660,7 @@ function CustomDatePicker({
|
|
|
1606
1660
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1607
1661
|
"button",
|
|
1608
1662
|
{
|
|
1663
|
+
ref: triggerRef,
|
|
1609
1664
|
type: "button",
|
|
1610
1665
|
onClick: () => setOpen(!open),
|
|
1611
1666
|
className: "apteva-datepicker-trigger w-full flex items-center justify-between px-3 py-2 rounded-lg border transition-colors text-left",
|
|
@@ -1615,7 +1670,7 @@ function CustomDatePicker({
|
|
|
1615
1670
|
]
|
|
1616
1671
|
}
|
|
1617
1672
|
),
|
|
1618
|
-
open
|
|
1673
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, PortalDropdown, { anchorRef: triggerRef, open, onClose: close, width: "auto", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker-dropdown rounded-lg border shadow-lg overflow-hidden", children: [
|
|
1619
1674
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-datepicker-header flex items-center justify-between px-3 py-2", children: [
|
|
1620
1675
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { type: "button", onClick: prevMonth, className: "apteva-datepicker-nav p-1 rounded transition-colors", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 19l-7-7 7-7" }) }) }),
|
|
1621
1676
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "apteva-datepicker-title text-sm font-semibold", children: [
|
|
@@ -1648,7 +1703,7 @@ function CustomDatePicker({
|
|
|
1648
1703
|
);
|
|
1649
1704
|
})
|
|
1650
1705
|
] })
|
|
1651
|
-
] })
|
|
1706
|
+
] }) })
|
|
1652
1707
|
] });
|
|
1653
1708
|
}
|
|
1654
1709
|
function Form({ widget, onAction }) {
|