@richardmcquiston01/dashboard-widgets-toolkit 0.11.1 → 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 +189 -24
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +189 -24
- package/dist/react.js.map +1 -1
- package/dist/styles.css +49 -8
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -2418,6 +2418,133 @@ function moveWidgetToPage(definitions, layout, widgetKey, targetKey, options = {
|
|
|
2418
2418
|
}
|
|
2419
2419
|
return ok(moved);
|
|
2420
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
|
+
}
|
|
2421
2548
|
function nextSort(current, column) {
|
|
2422
2549
|
if (current?.column !== column) return { column, direction: "asc" };
|
|
2423
2550
|
return current.direction === "asc" ? { column, direction: "desc" } : void 0;
|
|
@@ -3141,6 +3268,7 @@ function DashboardInner({
|
|
|
3141
3268
|
const [announcement, setAnnouncement] = useState("");
|
|
3142
3269
|
const [pageAnnouncement, setPageAnnouncement] = useState("");
|
|
3143
3270
|
const [pageError, setPageError] = useState(void 0);
|
|
3271
|
+
const [newPage, setNewPage] = useState(void 0);
|
|
3144
3272
|
const [pageEditor, setPageEditor] = useState(void 0);
|
|
3145
3273
|
const editorMode = pageEditor?.key === activeKey ? pageEditor.mode : void 0;
|
|
3146
3274
|
const instanceId = useId();
|
|
@@ -3171,6 +3299,7 @@ function DashboardInner({
|
|
|
3171
3299
|
onActivePageChange?.(pageKey);
|
|
3172
3300
|
setPageError(void 0);
|
|
3173
3301
|
setPageEditor(void 0);
|
|
3302
|
+
setNewPage(void 0);
|
|
3174
3303
|
setPageAnnouncement(
|
|
3175
3304
|
labels.pageTabName(
|
|
3176
3305
|
index + 1,
|
|
@@ -3188,6 +3317,7 @@ function DashboardInner({
|
|
|
3188
3317
|
change(added.value);
|
|
3189
3318
|
const created = added.value.pages?.at(-1);
|
|
3190
3319
|
if (created !== void 0) {
|
|
3320
|
+
setNewPage({ key: created.key, activeBefore: activeKey });
|
|
3191
3321
|
if (activePageProp === void 0) setActiveState(created.key);
|
|
3192
3322
|
onActivePageChange?.(created.key);
|
|
3193
3323
|
setPageError(void 0);
|
|
@@ -3199,8 +3329,21 @@ function DashboardInner({
|
|
|
3199
3329
|
if (!renamed.ok) return renamed.error;
|
|
3200
3330
|
change(renamed.value);
|
|
3201
3331
|
setPageEditor(void 0);
|
|
3332
|
+
setNewPage(void 0);
|
|
3202
3333
|
return void 0;
|
|
3203
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
|
+
}
|
|
3204
3347
|
function deletePageAction() {
|
|
3205
3348
|
const index = pages.findIndex((page) => page.key === activeKey);
|
|
3206
3349
|
const removed = removePage(definitions, layout, activeKey, roomOptions);
|
|
@@ -3374,7 +3517,7 @@ function DashboardInner({
|
|
|
3374
3517
|
{
|
|
3375
3518
|
initial: activePage.title,
|
|
3376
3519
|
onSubmit: renamePageAction,
|
|
3377
|
-
onCancel:
|
|
3520
|
+
onCancel: cancelPageEditor
|
|
3378
3521
|
},
|
|
3379
3522
|
activeKey
|
|
3380
3523
|
),
|
|
@@ -3422,7 +3565,27 @@ function DashboardInner({
|
|
|
3422
3565
|
"aria-label": labels.deletePage(activePage.title),
|
|
3423
3566
|
title: labels.deletePage(activePage.title),
|
|
3424
3567
|
onClick: () => setPageEditor({ mode: "delete", key: activeKey }),
|
|
3425
|
-
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
|
+
)
|
|
3426
3589
|
}
|
|
3427
3590
|
)
|
|
3428
3591
|
] }),
|
|
@@ -3579,29 +3742,31 @@ function DashboardInner({
|
|
|
3579
3742
|
children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2193" })
|
|
3580
3743
|
}
|
|
3581
3744
|
),
|
|
3582
|
-
paged && /* @__PURE__ */
|
|
3583
|
-
|
|
3745
|
+
paged && /* @__PURE__ */ jsx(
|
|
3746
|
+
MoveToPageMenu,
|
|
3584
3747
|
{
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
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
|
+
] : []
|
|
3605
3770
|
]
|
|
3606
3771
|
}
|
|
3607
3772
|
)
|