@richardmcquiston01/dashboard-widgets-toolkit 0.11.0 → 0.11.2
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/react.cjs +195 -24
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +195 -24
- package/dist/react.js.map +1 -1
- package/dist/styles.css +49 -8
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -1572,6 +1572,12 @@ function InteractiveTable({
|
|
|
1572
1572
|
const searchId = useId();
|
|
1573
1573
|
const [search, setSearch] = useState("");
|
|
1574
1574
|
const [sort, setSort] = useState(initialSort);
|
|
1575
|
+
const seed = initialSort === void 0 ? "" : `${initialSort.column}:${initialSort.direction}`;
|
|
1576
|
+
const [seededWith, setSeededWith] = useState(seed);
|
|
1577
|
+
if (seededWith !== seed) {
|
|
1578
|
+
setSeededWith(seed);
|
|
1579
|
+
setSort(initialSort);
|
|
1580
|
+
}
|
|
1575
1581
|
const localeTag = typeof locale === "string" ? locale : locale?.[0];
|
|
1576
1582
|
const query = {
|
|
1577
1583
|
page: 1,
|
|
@@ -2412,6 +2418,133 @@ function moveWidgetToPage(definitions, layout, widgetKey, targetKey, options = {
|
|
|
2412
2418
|
}
|
|
2413
2419
|
return ok(moved);
|
|
2414
2420
|
}
|
|
2421
|
+
function MoveToPageMenu({
|
|
2422
|
+
label,
|
|
2423
|
+
heading,
|
|
2424
|
+
options,
|
|
2425
|
+
onPick,
|
|
2426
|
+
initialOpen = false
|
|
2427
|
+
}) {
|
|
2428
|
+
const slot = useSlotClassName();
|
|
2429
|
+
const menuId = useId();
|
|
2430
|
+
const [open, setOpen] = useState(initialOpen);
|
|
2431
|
+
const wrapper = useRef(null);
|
|
2432
|
+
const button = useRef(null);
|
|
2433
|
+
const menu = useRef(null);
|
|
2434
|
+
useEffect(() => {
|
|
2435
|
+
if (!open) return void 0;
|
|
2436
|
+
menu.current?.querySelector('[role="menuitem"]')?.focus();
|
|
2437
|
+
const onPointerDown = (event) => {
|
|
2438
|
+
if (!wrapper.current?.contains(event.target)) setOpen(false);
|
|
2439
|
+
};
|
|
2440
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
2441
|
+
return () => document.removeEventListener("pointerdown", onPointerDown);
|
|
2442
|
+
}, [open]);
|
|
2443
|
+
function close(returnFocus) {
|
|
2444
|
+
setOpen(false);
|
|
2445
|
+
if (returnFocus) button.current?.focus();
|
|
2446
|
+
}
|
|
2447
|
+
function onKeyDown(event) {
|
|
2448
|
+
if (event.key === "Escape") {
|
|
2449
|
+
event.stopPropagation();
|
|
2450
|
+
close(true);
|
|
2451
|
+
return;
|
|
2452
|
+
}
|
|
2453
|
+
const items = [
|
|
2454
|
+
...menu.current?.querySelectorAll('[role="menuitem"]') ?? []
|
|
2455
|
+
];
|
|
2456
|
+
const current = items.indexOf(
|
|
2457
|
+
document.activeElement
|
|
2458
|
+
);
|
|
2459
|
+
let next;
|
|
2460
|
+
if (event.key === "ArrowDown") next = (current + 1) % items.length;
|
|
2461
|
+
else if (event.key === "ArrowUp") {
|
|
2462
|
+
next = (current - 1 + items.length) % items.length;
|
|
2463
|
+
} else if (event.key === "Home") next = 0;
|
|
2464
|
+
else if (event.key === "End") next = items.length - 1;
|
|
2465
|
+
if (next !== void 0) {
|
|
2466
|
+
event.preventDefault();
|
|
2467
|
+
items[next]?.focus();
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
return /* @__PURE__ */ jsxs(
|
|
2471
|
+
"span",
|
|
2472
|
+
{
|
|
2473
|
+
ref: wrapper,
|
|
2474
|
+
className: "dwt-move-menu",
|
|
2475
|
+
onBlur: (event) => {
|
|
2476
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
2477
|
+
setOpen(false);
|
|
2478
|
+
}
|
|
2479
|
+
},
|
|
2480
|
+
children: [
|
|
2481
|
+
/* @__PURE__ */ jsx(
|
|
2482
|
+
"button",
|
|
2483
|
+
{
|
|
2484
|
+
ref: button,
|
|
2485
|
+
type: "button",
|
|
2486
|
+
className: slot("button", "dwt-button", "dwt-icon-button"),
|
|
2487
|
+
"aria-label": label,
|
|
2488
|
+
title: label,
|
|
2489
|
+
"aria-haspopup": "menu",
|
|
2490
|
+
"aria-expanded": open,
|
|
2491
|
+
"aria-controls": open ? menuId : void 0,
|
|
2492
|
+
onClick: () => setOpen((current) => !current),
|
|
2493
|
+
children: /* @__PURE__ */ jsx(
|
|
2494
|
+
"svg",
|
|
2495
|
+
{
|
|
2496
|
+
viewBox: "0 0 16 16",
|
|
2497
|
+
width: "14",
|
|
2498
|
+
height: "14",
|
|
2499
|
+
"aria-hidden": "true",
|
|
2500
|
+
focusable: "false",
|
|
2501
|
+
children: /* @__PURE__ */ jsx(
|
|
2502
|
+
"path",
|
|
2503
|
+
{
|
|
2504
|
+
d: "M2 8h8M7 5l3 3-3 3M13 3v10",
|
|
2505
|
+
fill: "none",
|
|
2506
|
+
stroke: "currentColor",
|
|
2507
|
+
strokeWidth: "1.5",
|
|
2508
|
+
strokeLinecap: "round",
|
|
2509
|
+
strokeLinejoin: "round"
|
|
2510
|
+
}
|
|
2511
|
+
)
|
|
2512
|
+
}
|
|
2513
|
+
)
|
|
2514
|
+
}
|
|
2515
|
+
),
|
|
2516
|
+
open && /* @__PURE__ */ jsxs(
|
|
2517
|
+
"div",
|
|
2518
|
+
{
|
|
2519
|
+
ref: menu,
|
|
2520
|
+
id: menuId,
|
|
2521
|
+
className: "dwt-move-popover",
|
|
2522
|
+
role: "menu",
|
|
2523
|
+
"aria-label": heading,
|
|
2524
|
+
onKeyDown,
|
|
2525
|
+
children: [
|
|
2526
|
+
/* @__PURE__ */ jsx("p", { className: "dwt-move-heading", "aria-hidden": "true", children: heading }),
|
|
2527
|
+
options.map((option) => /* @__PURE__ */ jsx(
|
|
2528
|
+
"button",
|
|
2529
|
+
{
|
|
2530
|
+
type: "button",
|
|
2531
|
+
role: "menuitem",
|
|
2532
|
+
className: "dwt-move-option",
|
|
2533
|
+
onClick: () => {
|
|
2534
|
+
close(false);
|
|
2535
|
+
onPick(option.value);
|
|
2536
|
+
},
|
|
2537
|
+
children: option.label
|
|
2538
|
+
},
|
|
2539
|
+
option.value
|
|
2540
|
+
))
|
|
2541
|
+
]
|
|
2542
|
+
}
|
|
2543
|
+
)
|
|
2544
|
+
]
|
|
2545
|
+
}
|
|
2546
|
+
);
|
|
2547
|
+
}
|
|
2415
2548
|
function nextSort(current, column) {
|
|
2416
2549
|
if (current?.column !== column) return { column, direction: "asc" };
|
|
2417
2550
|
return current.direction === "asc" ? { column, direction: "desc" } : void 0;
|
|
@@ -3135,6 +3268,7 @@ function DashboardInner({
|
|
|
3135
3268
|
const [announcement, setAnnouncement] = useState("");
|
|
3136
3269
|
const [pageAnnouncement, setPageAnnouncement] = useState("");
|
|
3137
3270
|
const [pageError, setPageError] = useState(void 0);
|
|
3271
|
+
const [newPage, setNewPage] = useState(void 0);
|
|
3138
3272
|
const [pageEditor, setPageEditor] = useState(void 0);
|
|
3139
3273
|
const editorMode = pageEditor?.key === activeKey ? pageEditor.mode : void 0;
|
|
3140
3274
|
const instanceId = useId();
|
|
@@ -3165,6 +3299,7 @@ function DashboardInner({
|
|
|
3165
3299
|
onActivePageChange?.(pageKey);
|
|
3166
3300
|
setPageError(void 0);
|
|
3167
3301
|
setPageEditor(void 0);
|
|
3302
|
+
setNewPage(void 0);
|
|
3168
3303
|
setPageAnnouncement(
|
|
3169
3304
|
labels.pageTabName(
|
|
3170
3305
|
index + 1,
|
|
@@ -3182,6 +3317,7 @@ function DashboardInner({
|
|
|
3182
3317
|
change(added.value);
|
|
3183
3318
|
const created = added.value.pages?.at(-1);
|
|
3184
3319
|
if (created !== void 0) {
|
|
3320
|
+
setNewPage({ key: created.key, activeBefore: activeKey });
|
|
3185
3321
|
if (activePageProp === void 0) setActiveState(created.key);
|
|
3186
3322
|
onActivePageChange?.(created.key);
|
|
3187
3323
|
setPageError(void 0);
|
|
@@ -3193,8 +3329,21 @@ function DashboardInner({
|
|
|
3193
3329
|
if (!renamed.ok) return renamed.error;
|
|
3194
3330
|
change(renamed.value);
|
|
3195
3331
|
setPageEditor(void 0);
|
|
3332
|
+
setNewPage(void 0);
|
|
3196
3333
|
return void 0;
|
|
3197
3334
|
}
|
|
3335
|
+
function cancelPageEditor() {
|
|
3336
|
+
const fresh = newPage;
|
|
3337
|
+
setPageEditor(void 0);
|
|
3338
|
+
setNewPage(void 0);
|
|
3339
|
+
if (fresh === void 0 || fresh.key !== activeKey) return;
|
|
3340
|
+
const pagesWithout = pages.filter(
|
|
3341
|
+
(page) => page.key !== fresh.key
|
|
3342
|
+
);
|
|
3343
|
+
if (pagesWithout.length === pages.length) return;
|
|
3344
|
+
change({ ...layout, pages: pagesWithout });
|
|
3345
|
+
selectPage(fresh.activeBefore);
|
|
3346
|
+
}
|
|
3198
3347
|
function deletePageAction() {
|
|
3199
3348
|
const index = pages.findIndex((page) => page.key === activeKey);
|
|
3200
3349
|
const removed = removePage(definitions, layout, activeKey, roomOptions);
|
|
@@ -3368,7 +3517,7 @@ function DashboardInner({
|
|
|
3368
3517
|
{
|
|
3369
3518
|
initial: activePage.title,
|
|
3370
3519
|
onSubmit: renamePageAction,
|
|
3371
|
-
onCancel:
|
|
3520
|
+
onCancel: cancelPageEditor
|
|
3372
3521
|
},
|
|
3373
3522
|
activeKey
|
|
3374
3523
|
),
|
|
@@ -3416,7 +3565,27 @@ function DashboardInner({
|
|
|
3416
3565
|
"aria-label": labels.deletePage(activePage.title),
|
|
3417
3566
|
title: labels.deletePage(activePage.title),
|
|
3418
3567
|
onClick: () => setPageEditor({ mode: "delete", key: activeKey }),
|
|
3419
|
-
children: /* @__PURE__ */ jsx(
|
|
3568
|
+
children: /* @__PURE__ */ jsx(
|
|
3569
|
+
"svg",
|
|
3570
|
+
{
|
|
3571
|
+
viewBox: "0 0 16 16",
|
|
3572
|
+
width: "14",
|
|
3573
|
+
height: "14",
|
|
3574
|
+
"aria-hidden": "true",
|
|
3575
|
+
focusable: "false",
|
|
3576
|
+
children: /* @__PURE__ */ jsx(
|
|
3577
|
+
"path",
|
|
3578
|
+
{
|
|
3579
|
+
d: "M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5M6.8 7v3.5M9.2 7v3.5",
|
|
3580
|
+
fill: "none",
|
|
3581
|
+
stroke: "currentColor",
|
|
3582
|
+
strokeWidth: "1.3",
|
|
3583
|
+
strokeLinecap: "round",
|
|
3584
|
+
strokeLinejoin: "round"
|
|
3585
|
+
}
|
|
3586
|
+
)
|
|
3587
|
+
}
|
|
3588
|
+
)
|
|
3420
3589
|
}
|
|
3421
3590
|
)
|
|
3422
3591
|
] }),
|
|
@@ -3573,29 +3742,31 @@ function DashboardInner({
|
|
|
3573
3742
|
children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2193" })
|
|
3574
3743
|
}
|
|
3575
3744
|
),
|
|
3576
|
-
paged && /* @__PURE__ */
|
|
3577
|
-
|
|
3745
|
+
paged && /* @__PURE__ */ jsx(
|
|
3746
|
+
MoveToPageMenu,
|
|
3578
3747
|
{
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3748
|
+
label: labels.moveToPage(title),
|
|
3749
|
+
heading: labels.moveToPagePlaceholder,
|
|
3750
|
+
onPick: (pageKey) => moveWidgetAction(key, pageKey),
|
|
3751
|
+
options: [
|
|
3752
|
+
...pages.filter((page) => page.key !== activeKey).map((page) => ({
|
|
3753
|
+
value: page.key,
|
|
3754
|
+
label: labels.moveToPageOption(
|
|
3755
|
+
page.title,
|
|
3756
|
+
pageRoom(
|
|
3757
|
+
definitions,
|
|
3758
|
+
layout,
|
|
3759
|
+
page.key,
|
|
3760
|
+
roomOptions
|
|
3761
|
+
)?.rowsFree ?? 0
|
|
3762
|
+
)
|
|
3763
|
+
})),
|
|
3764
|
+
...maxPages === void 0 || pages.length < maxPages ? [
|
|
3765
|
+
{
|
|
3766
|
+
value: NEW_PAGE_VALUE,
|
|
3767
|
+
label: labels.newPageOption
|
|
3768
|
+
}
|
|
3769
|
+
] : []
|
|
3599
3770
|
]
|
|
3600
3771
|
}
|
|
3601
3772
|
)
|