@softure-ai/theme-notion 0.35.0 → 0.36.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ Newest first. Each version lists what changed for an app that uses the theme. Wh
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done").
6
6
 
7
+ ## 0.36.0
8
+
9
+ - `RowActionsMenu` (#1492): a destructive `onSelect` may return a promise (a server action); with `confirm` the
10
+ dialog stays open while it is pending, both buttons disabled and the confirm button showing `confirm.pendingLabel`
11
+ ("Deleting…"), closes when it resolves and stays open when it rejects. `RowMenuAction.opensDialog` leaves focus to
12
+ the app's own dialog when the menu closes, and `triggerRef` reaches the menu button so that dialog can return focus
13
+ to it. Below `md` every item is the 44 px touch target; `id` on an action renders as `data-row-action` for browser
14
+ tests.
15
+ - `ResultBadge` (#1493): every other `span` prop (`data-*`, `id`, ARIA) reaches the badge, so an app marks a badge
16
+ with what it shows (`data-read-status="ok"`) without wrapping it. The theme's `data-slot`, `data-tone`,
17
+ `data-color` and `data-spinning` stay the theme's.
18
+
7
19
  ## 0.35.0
8
20
 
9
21
  - `RowActionsMenu` (#1486): a row's overflow menu. An icon-only "More actions" button (`label` for the app's words)
package/README.md CHANGED
@@ -560,7 +560,12 @@ primary action. Every other action goes into `menu`, a `RowActionsMenu` on the s
560
560
  button (its name from `label`, English by default) that opens a menu of `actions`, with `destructiveAction` last,
561
561
  after a separator, in the danger tone. Give the destructive action a `confirm` (`title`, `description`,
562
562
  `confirmLabel`, `cancelLabel`) and it opens an alert dialog first, running only on the destructive confirm; focus goes
563
- back to the menu button. The menu opens with Enter, Space or ArrowDown, and the arrow keys move between items. A row
563
+ back to the menu button. A destructive `onSelect` that returns a promise (a server action) keeps the dialog open with
564
+ both buttons disabled and `confirm.pendingLabel` ("Deleting…") on the confirm button until it settles: it closes on
565
+ success and stays open on failure, where the app shows its own error. An action that opens the app's own dialog sets
566
+ `opensDialog`, so the menu leaves focus to that dialog; pass `triggerRef` and return focus to the menu button from the
567
+ dialog's `onCloseAutoFocus`. Below `md` every item is the 44 px touch target; an action's `id` renders as
568
+ `data-row-action` for browser tests. The menu opens with Enter, Space or ArrowDown, and the arrow keys move between items. A row
564
569
  with a single action keeps it inline and has no menu. The inline control and the menu button never wrap apart, and on
565
570
  a phone each is at least the touch target (44 px): pass the switch `size="touch"` (with `className="md:m-0 md:h-4
566
571
  md:w-[26px]"` for the plain switch on a desktop), since the row never stretches a switch's track. Each fact is said once: a switch is its own on/off state, so no
@@ -577,12 +582,19 @@ badge or label repeats it; a `ResultBadge` carries its own icon, so no separate
577
582
  label={t.rows.more}
578
583
  actions={[
579
584
  { label: t.hooks.test, onSelect: test },
580
- { label: t.hooks.replaceToken, onSelect: replaceToken },
585
+ { id: "replace-token", label: t.hooks.replaceToken, onSelect: openReplaceDialog, opensDialog: true },
581
586
  ]}
587
+ triggerRef={menuButton}
582
588
  destructiveAction={{
589
+ id: "delete",
583
590
  label: t.hooks.delete,
584
- onSelect: remove,
585
- confirm: { title: t.hooks.deleteTitle, confirmLabel: t.hooks.delete, cancelLabel: t.common.cancel },
591
+ onSelect: () => deleteHook(hook.id),
592
+ confirm: {
593
+ title: t.hooks.deleteTitle,
594
+ confirmLabel: t.hooks.delete,
595
+ pendingLabel: t.hooks.deleting,
596
+ cancelLabel: t.common.cancel,
597
+ },
586
598
  }}
587
599
  />
588
600
  }
@@ -595,11 +607,14 @@ the tone's icon (`RESULT_BADGE_ICONS`: `CircleCheck`, `TriangleAlert`, `CircleX`
595
607
  `icon` for another) and always a word. The app keeps its own table of which result takes which tone; the theme owns
596
608
  the colours, so "failed" is red in every list. `isSpinning` marks a run still in progress: the icon (a
597
609
  `LoaderCircle` unless `icon` is given) spins with `motion-safe:animate-spin`, still for a reader who asked for reduced
598
- motion. `Status` is the ghost counterpart, for a state written in text colour.
610
+ motion. `Status` is the ghost counterpart, for a state written in text colour. Every other `span` prop (`data-*`,
611
+ `id`, ARIA) reaches the badge, so an app marks it with what it shows and its tests read that; the theme's own
612
+ `data-slot`, `data-tone`, `data-color` and `data-spinning` always win.
599
613
 
600
614
  ```tsx
601
615
  <ResultBadge tone="danger">Failed</ResultBadge>
602
616
  <ResultBadge tone="muted" isSpinning>Running</ResultBadge>
617
+ <ResultBadge tone="success" data-read-status="ok">Read</ResultBadge>
603
618
  ```
604
619
 
605
620
  **`ListGroup`, `ListGroupHeading`: a sticky group heading.** A heading over a run of rows (a country's days, a month's
@@ -1,9 +1,14 @@
1
1
  import { type LucideIcon } from "lucide-react";
2
- import type { ReactNode } from "react";
2
+ import type { ComponentProps, ReactNode } from "react";
3
3
  import { type Tone } from "./tones.js";
4
4
  /** The icon a result badge draws for each tone when the app passes none. */
5
5
  export declare const RESULT_BADGE_ICONS: Readonly<Record<Tone, LucideIcon>>;
6
- export interface ResultBadgeProps {
6
+ /**
7
+ * The badge's remaining `span` props (`data-*`, `id`, ARIA, handlers) reach the element, so an app can mark a badge with
8
+ * what it shows (`data-read-status="ok"`). The theme's own `data-slot`, `data-tone`, `data-color` and `data-spinning`
9
+ * always win, and the look (`variant`, `color`) is the theme's.
10
+ */
11
+ export interface ResultBadgeProps extends Omit<ComponentProps<"span">, "color" | "children" | "title" | "className"> {
7
12
  /** What the result means; the theme owns its colour (`TONE_COLORS`), so one result reads alike in every list. */
8
13
  readonly tone: Tone;
9
14
  /** The app's own icon in place of the tone's default (a spinning run defaults to a loader). */
@@ -16,5 +21,5 @@ export interface ResultBadgeProps {
16
21
  readonly title?: string;
17
22
  readonly className?: string;
18
23
  }
19
- export declare function ResultBadge({ tone, icon, isSpinning, children, title, className }: ResultBadgeProps): import("react").JSX.Element;
24
+ export declare function ResultBadge({ tone, icon, isSpinning, children, title, className, ...attributes }: ResultBadgeProps): import("react").JSX.Element;
20
25
  //# sourceMappingURL=ResultBadge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResultBadge.d.ts","sourceRoot":"","sources":["../../src/notion/ResultBadge.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0E,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACvH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAe,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEpD,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAMjE,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,iHAAiH;IACjH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,2FAA2F;IAC3F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AASD,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,gBAAgB,+BAmB3G"}
1
+ {"version":3,"file":"ResultBadge.d.ts","sourceRoot":"","sources":["../../src/notion/ResultBadge.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0E,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACvH,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvD,OAAO,EAAe,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEpD,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAMjE,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,WAAW,CAAC;IAClH,iHAAiH;IACjH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,2FAA2F;IAC3F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AASD,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,EAAE,gBAAgB,+BAoB1H"}
@@ -18,8 +18,8 @@ function getPlainText(children) {
18
18
  }
19
19
  // A result (passed, failed, skipped, running): a filled tag in its tone's colour, with an icon and a word. The filled
20
20
  // counterpart of `Status`, for a list whose rows each end in a result.
21
- export function ResultBadge({ tone, icon, isSpinning = false, children, title, className }) {
21
+ export function ResultBadge({ tone, icon, isSpinning = false, children, title, className, ...attributes }) {
22
22
  const Icon = icon ?? (isSpinning ? LoaderCircle : RESULT_BADGE_ICONS[tone]);
23
- return (_jsxs(Badge, { variant: "tag", color: TONE_COLORS[tone] ?? "default", "data-slot": "result-badge", "data-tone": tone, "data-color": TONE_COLORS[tone] ?? "default", "data-spinning": isSpinning || undefined, title: title ?? getPlainText(children), className: cn("gap-1 [&>svg]:size-3.5 [&>svg]:shrink-0", className), children: [_jsx(Icon, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH, className: isSpinning ? "motion-safe:animate-spin" : undefined }), _jsx("span", { "data-slot": "result-badge-label", className: "min-w-0 truncate", children: children })] }));
23
+ return (_jsxs(Badge, { ...attributes, variant: "tag", color: TONE_COLORS[tone] ?? "default", "data-slot": "result-badge", "data-tone": tone, "data-color": TONE_COLORS[tone] ?? "default", "data-spinning": isSpinning || undefined, title: title ?? getPlainText(children), className: cn("gap-1 [&>svg]:size-3.5 [&>svg]:shrink-0", className), children: [_jsx(Icon, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH, className: isSpinning ? "motion-safe:animate-spin" : undefined }), _jsx("span", { "data-slot": "result-badge-label", className: "min-w-0 truncate", children: children })] }));
24
24
  }
25
25
  //# sourceMappingURL=ResultBadge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResultBadge.js","sourceRoot":"","sources":["../../src/notion/ResultBadge.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAGvH,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAa,MAAM,YAAY,CAAC;AAEpD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,kBAAkB,GAAuC;IACpE,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,WAAW;IACpB,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,OAAO;IACf,KAAK,EAAE,WAAW;CACnB,CAAC;AAgBF,sEAAsE;AACtE,SAAS,YAAY,CAAC,QAAmB;IACvC,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrG,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C;AACJ,CAAC"}
@@ -1,11 +1,18 @@
1
- import { type ReactNode } from "react";
1
+ import { type ReactNode, type Ref } from "react";
2
2
  /** One secondary action of a row: its words, an optional icon, and what it does. */
3
3
  export interface RowMenuAction {
4
+ /** A stable hook for browser tests, rendered as `data-row-action` on the item. */
5
+ readonly id?: string;
4
6
  readonly label: string;
5
7
  /** A line icon before the words (the theme's stroke and size apply). */
6
8
  readonly icon?: ReactNode;
7
9
  readonly onSelect: () => void;
8
10
  readonly isDisabled?: boolean;
11
+ /**
12
+ * The action opens the app's own dialog: the menu leaves focus to that dialog when it closes instead of taking it
13
+ * back to its button. Return focus to the button from the dialog's `onCloseAutoFocus` through `triggerRef`.
14
+ */
15
+ readonly opensDialog?: boolean;
9
16
  }
10
17
  /** The confirmation a destructive action asks for: the app's own copy. */
11
18
  export interface RowMenuConfirmation {
@@ -13,11 +20,19 @@ export interface RowMenuConfirmation {
13
20
  readonly description?: ReactNode;
14
21
  /** The words of the destructive confirm button. */
15
22
  readonly confirmLabel: string;
23
+ /** The words of the confirm button while an async action runs ("Deleting…"); `confirmLabel` when not given. */
24
+ readonly pendingLabel?: string;
16
25
  /** The words of the button that keeps things as they are. */
17
26
  readonly cancelLabel: string;
18
27
  }
19
28
  /** The destructive action of a row (delete, revoke): last in the menu, in the danger tone. */
20
- export interface RowMenuDestructiveAction extends RowMenuAction {
29
+ export interface RowMenuDestructiveAction extends Omit<RowMenuAction, "onSelect"> {
30
+ /**
31
+ * What the action does. With `confirm` it may return a promise (a server action): the dialog then stays open with
32
+ * both buttons disabled and `pendingLabel` on the confirm button until it settles, closes when it resolves and stays
33
+ * open when it rejects. The app reports the error itself; the menu only keeps the dialog open.
34
+ */
35
+ readonly onSelect: () => void | Promise<unknown>;
21
36
  /** Ask first: the action runs only after the alert dialog's confirm button. Without it the action runs at once. */
22
37
  readonly confirm?: RowMenuConfirmation;
23
38
  }
@@ -30,6 +45,8 @@ export interface RowActionsMenuProps {
30
45
  readonly label?: string;
31
46
  /** The menu's edge against the button; `end` (the row's right edge) by default. */
32
47
  readonly align?: "start" | "center" | "end";
48
+ /** Reaches the menu button, so an app's dialog opened from the menu can return focus to it. */
49
+ readonly triggerRef?: Ref<HTMLButtonElement>;
33
50
  readonly className?: string;
34
51
  }
35
52
  /**
@@ -38,5 +55,5 @@ export interface RowActionsMenuProps {
38
55
  * Enter, Space or ArrowDown; the arrow keys move between items. Place it in `ListEntry`'s `menu` slot, next to the
39
56
  * row's one inline control.
40
57
  */
41
- export declare function RowActionsMenu({ actions, destructiveAction, label, align, className, }: RowActionsMenuProps): import("react").JSX.Element;
58
+ export declare function RowActionsMenu({ actions, destructiveAction, label, align, triggerRef, className, }: RowActionsMenuProps): import("react").JSX.Element;
42
59
  //# sourceMappingURL=RowActionsMenu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RowActionsMenu.d.ts","sourceRoot":"","sources":["../../src/notion/RowActionsMenu.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAyBzD,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC;IACjC,mDAAmD;IACnD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,8FAA8F;AAC9F,MAAM,WAAW,wBAAyB,SAAQ,aAAa;IAC7D,mHAA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WAAW,CAAC,EAAE,SAAS,CAAC;IACjC,mDAAmD;IACnD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,+GAA+G;IAC/G,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,8FAA8F;AAC9F,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;IAC/E;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,mHAAmH;IACnH,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,8DAA8D;IAC9D,QAAQ,CAAC,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IACtD,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC5C,+FAA+F;IAC/F,QAAQ,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAUD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAC7B,OAAY,EACZ,iBAAiB,EACjB,KAAgC,EAChC,KAAa,EACb,UAAU,EACV,SAAS,GACV,EAAE,mBAAmB,+BA2IrB"}
@@ -1,36 +1,84 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Ellipsis } from "lucide-react";
4
- import { useRef, useState } from "react";
4
+ import { useCallback, useRef, useState } from "react";
5
5
  import { cn } from "../lib/utils.js";
6
6
  import { en as messages } from "../messages/en.js";
7
7
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "../ui/alert-dialog.js";
8
8
  import { Button } from "../ui/button.js";
9
9
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "../ui/dropdown-menu.js";
10
10
  import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
11
+ // Below `md` every item is the touch target, as the row's own controls are; a desktop keeps the compact items.
12
+ const ITEM_TOUCH_CLASS = "max-md:min-h-touch-target";
13
+ function assignRef(ref, value) {
14
+ if (typeof ref === "function")
15
+ ref(value);
16
+ else if (ref !== null && ref !== undefined)
17
+ ref.current = value;
18
+ }
11
19
  /**
12
20
  * A row's overflow menu: an icon-only "More actions" button that opens a menu of the row's secondary actions, the
13
21
  * destructive one last, after a separator and in the danger tone, optionally confirmed in an alert dialog. Opens with
14
22
  * Enter, Space or ArrowDown; the arrow keys move between items. Place it in `ListEntry`'s `menu` slot, next to the
15
23
  * row's one inline control.
16
24
  */
17
- export function RowActionsMenu({ actions = [], destructiveAction, label = messages.rowActions.more, align = "end", className, }) {
25
+ export function RowActionsMenu({ actions = [], destructiveAction, label = messages.rowActions.more, align = "end", triggerRef, className, }) {
18
26
  const [isConfirming, setIsConfirming] = useState(false);
27
+ const [isPending, setIsPending] = useState(false);
19
28
  const trigger = useRef(null);
29
+ const isLeavingFocus = useRef(false);
20
30
  const confirmation = destructiveAction?.confirm;
31
+ const setTrigger = useCallback((node) => {
32
+ trigger.current = node;
33
+ assignRef(triggerRef, node);
34
+ }, [triggerRef]);
35
+ const selectAction = (action) => {
36
+ isLeavingFocus.current = action.opensDialog === true;
37
+ action.onSelect();
38
+ };
21
39
  const selectDestructive = () => {
22
40
  if (destructiveAction === undefined)
23
41
  return;
42
+ isLeavingFocus.current = false;
24
43
  if (confirmation === undefined) {
25
- destructiveAction.onSelect();
44
+ // The menu is already closed, so a returned promise is the app's to handle.
45
+ void destructiveAction.onSelect();
26
46
  return;
27
47
  }
28
48
  setIsConfirming(true);
29
49
  };
30
- return (_jsxs(_Fragment, { children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { ref: trigger, "data-slot": "row-actions-menu-trigger", type: "button", variant: "ghost", size: "icon", "aria-label": label, className: cn("text-muted-foreground", className), children: _jsx(Ellipsis, { strokeWidth: ICON_STROKE_WIDTH, "aria-hidden": "true" }) }) }), _jsxs(DropdownMenuContent, { align: align, children: [actions.map((action) => (_jsxs(DropdownMenuItem, { disabled: action.isDisabled, onSelect: action.onSelect, children: [action.icon, action.label] }, action.label))), destructiveAction !== undefined && actions.length > 0 ? _jsx(DropdownMenuSeparator, {}) : null, destructiveAction !== undefined ? (_jsxs(DropdownMenuItem, { variant: "destructive", disabled: destructiveAction.isDisabled, onSelect: selectDestructive, children: [destructiveAction.icon, destructiveAction.label] })) : null] })] }), confirmation !== undefined && destructiveAction !== undefined ? (_jsx(AlertDialog, { open: isConfirming, onOpenChange: setIsConfirming, children: _jsxs(AlertDialogContent, { size: "sm", onCloseAutoFocus: (event) => {
50
+ const confirmDestructive = (event) => {
51
+ if (destructiveAction === undefined)
52
+ return;
53
+ const result = destructiveAction.onSelect();
54
+ if (!(result instanceof Promise))
55
+ return;
56
+ // Keep the dialog open until the action settles.
57
+ event.preventDefault();
58
+ setIsPending(true);
59
+ result.then(() => {
60
+ setIsPending(false);
61
+ setIsConfirming(false);
62
+ }, () => {
63
+ // The app reports its own error; the dialog stays open so the reader can retry or cancel.
64
+ setIsPending(false);
65
+ });
66
+ };
67
+ const changeConfirming = (isOpen) => {
68
+ if (isPending)
69
+ return;
70
+ setIsConfirming(isOpen);
71
+ };
72
+ return (_jsxs(_Fragment, { children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { ref: setTrigger, "data-slot": "row-actions-menu-trigger", type: "button", variant: "ghost", size: "icon", "aria-label": label, className: cn("text-muted-foreground", className), children: _jsx(Ellipsis, { strokeWidth: ICON_STROKE_WIDTH, "aria-hidden": "true" }) }) }), _jsxs(DropdownMenuContent, { align: align, onCloseAutoFocus: (event) => {
73
+ // An item that opened the app's dialog leaves focus to that dialog.
74
+ if (!isLeavingFocus.current)
75
+ return;
76
+ isLeavingFocus.current = false;
77
+ event.preventDefault();
78
+ }, children: [actions.map((action) => (_jsxs(DropdownMenuItem, { "data-row-action": action.id, className: ITEM_TOUCH_CLASS, disabled: action.isDisabled, onSelect: () => selectAction(action), children: [action.icon, action.label] }, action.label))), destructiveAction !== undefined && actions.length > 0 ? _jsx(DropdownMenuSeparator, {}) : null, destructiveAction !== undefined ? (_jsxs(DropdownMenuItem, { variant: "destructive", "data-row-action": destructiveAction.id, className: ITEM_TOUCH_CLASS, disabled: destructiveAction.isDisabled, onSelect: selectDestructive, children: [destructiveAction.icon, destructiveAction.label] })) : null] })] }), confirmation !== undefined && destructiveAction !== undefined ? (_jsx(AlertDialog, { open: isConfirming, onOpenChange: changeConfirming, children: _jsxs(AlertDialogContent, { size: "sm", onCloseAutoFocus: (event) => {
31
79
  // The menu item that opened the dialog is gone: focus goes back to the menu button.
32
80
  event.preventDefault();
33
81
  trigger.current?.focus();
34
- }, children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: confirmation.title }), confirmation.description !== undefined ? (_jsx(AlertDialogDescription, { children: confirmation.description })) : null] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: confirmation.cancelLabel }), _jsx(AlertDialogAction, { variant: "destructive", onClick: destructiveAction.onSelect, children: confirmation.confirmLabel })] })] }) })) : null] }));
82
+ }, children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: confirmation.title }), confirmation.description !== undefined ? (_jsx(AlertDialogDescription, { children: confirmation.description })) : null] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: isPending, children: confirmation.cancelLabel }), _jsx(AlertDialogAction, { variant: "destructive", disabled: isPending, "aria-busy": isPending || undefined, onClick: confirmDestructive, children: isPending ? (confirmation.pendingLabel ?? confirmation.confirmLabel) : confirmation.confirmLabel })] })] }) })) : null] }));
35
83
  }
36
84
  //# sourceMappingURL=RowActionsMenu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RowActionsMenu.js","sourceRoot":"","sources":["../../src/notion/RowActionsMenu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAuCrD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,OAAO,GAAG,EAAE,EACZ,iBAAiB,EACjB,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,EAChC,KAAK,GAAG,KAAK,EACb,SAAS,GACW;IACpB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC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
1
  {
2
2
  "name": "@softure-ai/theme-notion",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "SOFTURE AI Notion theme: shadcn/ui components (new-york v4, Radix, Tailwind CSS v4, lucide) with the Notion design system's tokens and deltas, ready to import.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import { Circle, CircleCheck, CircleMinus, CircleX, LoaderCircle, TriangleAlert, type LucideIcon } from "lucide-react";
2
- import type { ReactNode } from "react";
2
+ import type { ComponentProps, ReactNode } from "react";
3
3
 
4
4
  import { cn } from "../lib/utils.js";
5
5
  import { Badge } from "../ui/badge.js";
@@ -16,7 +16,12 @@ export const RESULT_BADGE_ICONS: Readonly<Record<Tone, LucideIcon>> = {
16
16
  muted: CircleMinus,
17
17
  };
18
18
 
19
- export interface ResultBadgeProps {
19
+ /**
20
+ * The badge's remaining `span` props (`data-*`, `id`, ARIA, handlers) reach the element, so an app can mark a badge with
21
+ * what it shows (`data-read-status="ok"`). The theme's own `data-slot`, `data-tone`, `data-color` and `data-spinning`
22
+ * always win, and the look (`variant`, `color`) is the theme's.
23
+ */
24
+ export interface ResultBadgeProps extends Omit<ComponentProps<"span">, "color" | "children" | "title" | "className"> {
20
25
  /** What the result means; the theme owns its colour (`TONE_COLORS`), so one result reads alike in every list. */
21
26
  readonly tone: Tone;
22
27
  /** The app's own icon in place of the tone's default (a spinning run defaults to a loader). */
@@ -37,10 +42,11 @@ function getPlainText(children: ReactNode): string | undefined {
37
42
 
38
43
  // A result (passed, failed, skipped, running): a filled tag in its tone's colour, with an icon and a word. The filled
39
44
  // counterpart of `Status`, for a list whose rows each end in a result.
40
- export function ResultBadge({ tone, icon, isSpinning = false, children, title, className }: ResultBadgeProps) {
45
+ export function ResultBadge({ tone, icon, isSpinning = false, children, title, className, ...attributes }: ResultBadgeProps) {
41
46
  const Icon = icon ?? (isSpinning ? LoaderCircle : RESULT_BADGE_ICONS[tone]);
42
47
  return (
43
48
  <Badge
49
+ {...attributes}
44
50
  variant="tag"
45
51
  color={TONE_COLORS[tone] ?? "default"}
46
52
  data-slot="result-badge"
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { Ellipsis } from "lucide-react";
4
- import { useRef, useState, type ReactNode } from "react";
4
+ import { useCallback, useRef, useState, type MouseEvent, type ReactNode, type Ref } from "react";
5
5
 
6
6
  import { cn } from "../lib/utils.js";
7
7
  import { en as messages } from "../messages/en.js";
@@ -28,11 +28,18 @@ import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
28
28
 
29
29
  /** One secondary action of a row: its words, an optional icon, and what it does. */
30
30
  export interface RowMenuAction {
31
+ /** A stable hook for browser tests, rendered as `data-row-action` on the item. */
32
+ readonly id?: string;
31
33
  readonly label: string;
32
34
  /** A line icon before the words (the theme's stroke and size apply). */
33
35
  readonly icon?: ReactNode;
34
36
  readonly onSelect: () => void;
35
37
  readonly isDisabled?: boolean;
38
+ /**
39
+ * The action opens the app's own dialog: the menu leaves focus to that dialog when it closes instead of taking it
40
+ * back to its button. Return focus to the button from the dialog's `onCloseAutoFocus` through `triggerRef`.
41
+ */
42
+ readonly opensDialog?: boolean;
36
43
  }
37
44
 
38
45
  /** The confirmation a destructive action asks for: the app's own copy. */
@@ -41,12 +48,20 @@ export interface RowMenuConfirmation {
41
48
  readonly description?: ReactNode;
42
49
  /** The words of the destructive confirm button. */
43
50
  readonly confirmLabel: string;
51
+ /** The words of the confirm button while an async action runs ("Deleting…"); `confirmLabel` when not given. */
52
+ readonly pendingLabel?: string;
44
53
  /** The words of the button that keeps things as they are. */
45
54
  readonly cancelLabel: string;
46
55
  }
47
56
 
48
57
  /** The destructive action of a row (delete, revoke): last in the menu, in the danger tone. */
49
- export interface RowMenuDestructiveAction extends RowMenuAction {
58
+ export interface RowMenuDestructiveAction extends Omit<RowMenuAction, "onSelect"> {
59
+ /**
60
+ * What the action does. With `confirm` it may return a promise (a server action): the dialog then stays open with
61
+ * both buttons disabled and `pendingLabel` on the confirm button until it settles, closes when it resolves and stays
62
+ * open when it rejects. The app reports the error itself; the menu only keeps the dialog open.
63
+ */
64
+ readonly onSelect: () => void | Promise<unknown>;
50
65
  /** Ask first: the action runs only after the alert dialog's confirm button. Without it the action runs at once. */
51
66
  readonly confirm?: RowMenuConfirmation;
52
67
  }
@@ -60,9 +75,19 @@ export interface RowActionsMenuProps {
60
75
  readonly label?: string;
61
76
  /** The menu's edge against the button; `end` (the row's right edge) by default. */
62
77
  readonly align?: "start" | "center" | "end";
78
+ /** Reaches the menu button, so an app's dialog opened from the menu can return focus to it. */
79
+ readonly triggerRef?: Ref<HTMLButtonElement>;
63
80
  readonly className?: string;
64
81
  }
65
82
 
83
+ // Below `md` every item is the touch target, as the row's own controls are; a desktop keeps the compact items.
84
+ const ITEM_TOUCH_CLASS = "max-md:min-h-touch-target";
85
+
86
+ function assignRef<T>(ref: Ref<T> | undefined, value: T | null): void {
87
+ if (typeof ref === "function") ref(value);
88
+ else if (ref !== null && ref !== undefined) ref.current = value;
89
+ }
90
+
66
91
  /**
67
92
  * A row's overflow menu: an icon-only "More actions" button that opens a menu of the row's secondary actions, the
68
93
  * destructive one last, after a separator and in the danger tone, optionally confirmed in an alert dialog. Opens with
@@ -74,27 +99,69 @@ export function RowActionsMenu({
74
99
  destructiveAction,
75
100
  label = messages.rowActions.more,
76
101
  align = "end",
102
+ triggerRef,
77
103
  className,
78
104
  }: RowActionsMenuProps) {
79
105
  const [isConfirming, setIsConfirming] = useState(false);
80
- const trigger = useRef<HTMLButtonElement>(null);
106
+ const [isPending, setIsPending] = useState(false);
107
+ const trigger = useRef<HTMLButtonElement | null>(null);
108
+ const isLeavingFocus = useRef(false);
81
109
  const confirmation = destructiveAction?.confirm;
82
110
 
111
+ const setTrigger = useCallback(
112
+ (node: HTMLButtonElement | null) => {
113
+ trigger.current = node;
114
+ assignRef(triggerRef, node);
115
+ },
116
+ [triggerRef],
117
+ );
118
+
119
+ const selectAction = (action: RowMenuAction) => {
120
+ isLeavingFocus.current = action.opensDialog === true;
121
+ action.onSelect();
122
+ };
123
+
83
124
  const selectDestructive = () => {
84
125
  if (destructiveAction === undefined) return;
126
+ isLeavingFocus.current = false;
85
127
  if (confirmation === undefined) {
86
- destructiveAction.onSelect();
128
+ // The menu is already closed, so a returned promise is the app's to handle.
129
+ void destructiveAction.onSelect();
87
130
  return;
88
131
  }
89
132
  setIsConfirming(true);
90
133
  };
91
134
 
135
+ const confirmDestructive = (event: MouseEvent<HTMLButtonElement>) => {
136
+ if (destructiveAction === undefined) return;
137
+ const result = destructiveAction.onSelect();
138
+ if (!(result instanceof Promise)) return;
139
+ // Keep the dialog open until the action settles.
140
+ event.preventDefault();
141
+ setIsPending(true);
142
+ result.then(
143
+ () => {
144
+ setIsPending(false);
145
+ setIsConfirming(false);
146
+ },
147
+ () => {
148
+ // The app reports its own error; the dialog stays open so the reader can retry or cancel.
149
+ setIsPending(false);
150
+ },
151
+ );
152
+ };
153
+
154
+ const changeConfirming = (isOpen: boolean) => {
155
+ if (isPending) return;
156
+ setIsConfirming(isOpen);
157
+ };
158
+
92
159
  return (
93
160
  <>
94
161
  <DropdownMenu>
95
162
  <DropdownMenuTrigger asChild>
96
163
  <Button
97
- ref={trigger}
164
+ ref={setTrigger}
98
165
  data-slot="row-actions-menu-trigger"
99
166
  type="button"
100
167
  variant="ghost"
@@ -105,16 +172,36 @@ export function RowActionsMenu({
105
172
  <Ellipsis strokeWidth={ICON_STROKE_WIDTH} aria-hidden="true" />
106
173
  </Button>
107
174
  </DropdownMenuTrigger>
108
- <DropdownMenuContent align={align}>
175
+ <DropdownMenuContent
176
+ align={align}
177
+ onCloseAutoFocus={(event) => {
178
+ // An item that opened the app's dialog leaves focus to that dialog.
179
+ if (!isLeavingFocus.current) return;
180
+ isLeavingFocus.current = false;
181
+ event.preventDefault();
182
+ }}
183
+ >
109
184
  {actions.map((action) => (
110
- <DropdownMenuItem key={action.label} disabled={action.isDisabled} onSelect={action.onSelect}>
185
+ <DropdownMenuItem
186
+ key={action.label}
187
+ data-row-action={action.id}
188
+ className={ITEM_TOUCH_CLASS}
189
+ disabled={action.isDisabled}
190
+ onSelect={() => selectAction(action)}
191
+ >
111
192
  {action.icon}
112
193
  {action.label}
113
194
  </DropdownMenuItem>
114
195
  ))}
115
196
  {destructiveAction !== undefined && actions.length > 0 ? <DropdownMenuSeparator /> : null}
116
197
  {destructiveAction !== undefined ? (
117
- <DropdownMenuItem variant="destructive" disabled={destructiveAction.isDisabled} onSelect={selectDestructive}>
198
+ <DropdownMenuItem
199
+ variant="destructive"
200
+ data-row-action={destructiveAction.id}
201
+ className={ITEM_TOUCH_CLASS}
202
+ disabled={destructiveAction.isDisabled}
203
+ onSelect={selectDestructive}
204
+ >
118
205
  {destructiveAction.icon}
119
206
  {destructiveAction.label}
120
207
  </DropdownMenuItem>
@@ -122,7 +209,7 @@ export function RowActionsMenu({
122
209
  </DropdownMenuContent>
123
210
  </DropdownMenu>
124
211
  {confirmation !== undefined && destructiveAction !== undefined ? (
125
- <AlertDialog open={isConfirming} onOpenChange={setIsConfirming}>
212
+ <AlertDialog open={isConfirming} onOpenChange={changeConfirming}>
126
213
  <AlertDialogContent
127
214
  size="sm"
128
215
  onCloseAutoFocus={(event) => {
@@ -138,9 +225,14 @@ export function RowActionsMenu({
138
225
  ) : null}
139
226
  </AlertDialogHeader>
140
227
  <AlertDialogFooter>
141
- <AlertDialogCancel>{confirmation.cancelLabel}</AlertDialogCancel>
142
- <AlertDialogAction variant="destructive" onClick={destructiveAction.onSelect}>
143
- {confirmation.confirmLabel}
228
+ <AlertDialogCancel disabled={isPending}>{confirmation.cancelLabel}</AlertDialogCancel>
229
+ <AlertDialogAction
230
+ variant="destructive"
231
+ disabled={isPending}
232
+ aria-busy={isPending || undefined}
233
+ onClick={confirmDestructive}
234
+ >
235
+ {isPending ? (confirmation.pendingLabel ?? confirmation.confirmLabel) : confirmation.confirmLabel}
144
236
  </AlertDialogAction>
145
237
  </AlertDialogFooter>
146
238
  </AlertDialogContent>