@mdbase-dev/ui 0.1.39 → 0.1.41

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/README.md CHANGED
@@ -333,6 +333,10 @@ import "@mdbase-dev/ui/collections.css";
333
333
  switcher: a popover, and a bottom sheet below 640px. `icon` puts the app's
334
334
  icon before the name, or `icon="mark"` the open collection's initials. In
335
335
  the `icon` variant it replaces the folder glyph.
336
+ - `signedOutExtra` is shown under Sign in in the switcher while no account is
337
+ signed in. An app that opens straight into work before connecting never
338
+ shows the gate's signed-out screen, so it puts the signed-out content from
339
+ `extraActions` here as well.
336
340
  - Pass `open` and `onOpenChange` to control the switcher; `onOpenChange` is
337
341
  called for every open and close it makes itself, controlled or not.
338
342
  `variant="none"` renders no trigger, for an app that opens the switcher from
@@ -1,10 +1,26 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { i18n as _i18n } from "@lingui/core";
3
3
  import { useEffect, useEffectEvent, useLayoutEffect, useRef } from "react";
4
+ import { createPortal } from "react-dom";
4
5
  import { useLocaleRevision } from "./i18n.js";
5
6
  import { anchoredPlacement } from "./popover.js";
6
7
  const FOCUSABLE = ':is(button, input, select, textarea, [tabindex="0"]):not(:disabled)';
7
8
  const OPEN_LIST = '[aria-expanded="true"], [role="listbox"], [role="menu"]';
9
+ /**
10
+ * The topmost open modal `<dialog>`, if one is showing. A modal dialog makes everything outside
11
+ * its subtree inert—even a top-layer popover—so a form opened while one is open mounts inside it.
12
+ */
13
+ function activeModalDialog() {
14
+ if (typeof document === "undefined") return null;
15
+ try {
16
+ const modal = document.querySelectorAll("dialog:modal");
17
+ if (modal.length) return modal[modal.length - 1];
18
+ } catch {
19
+ // Fall through when :modal is unsupported.
20
+ }
21
+ const open = document.querySelectorAll('dialog[open][aria-modal="true"]');
22
+ return open.length ? open[open.length - 1] : null;
23
+ }
8
24
  /**
9
25
  * A short form for a record made in passing, beside the place it is made from: its name, then
10
26
  * the fields the app asks for. It opens in the top layer and takes the keyboard until it is
@@ -107,7 +123,7 @@ export function QuickCreate({
107
123
  window.removeEventListener("resize", place);
108
124
  };
109
125
  }, []);
110
- return _jsx("div", {
126
+ const popover = _jsx("div", {
111
127
  ref: ref,
112
128
  className: `mdbase-quick-create mdbase-overlay${className ? ` ${className}` : ""}`,
113
129
  "data-open": true,
@@ -153,4 +169,6 @@ export function QuickCreate({
153
169
  })]
154
170
  })
155
171
  });
172
+ const host = activeModalDialog();
173
+ return host ? createPortal(popover, host) : popover;
156
174
  }
@@ -3,6 +3,11 @@ import { type RowDialog } from "./parts.js";
3
3
  import { type CollectionUi, type CollectionUiOptions } from "./use-collection-ui.js";
4
4
  export type CollectionSwitcherProps = CollectionUiOptions & {
5
5
  readonly className?: string;
6
+ /**
7
+ * Shown under Sign in while no account is signed in, such as an app's
8
+ * advanced way to open a collection without one.
9
+ */
10
+ readonly signedOutExtra?: ReactNode;
6
11
  /**
7
12
  * Leading content in the trigger: the app's icon, or "mark" for the open
8
13
  * collection's initials. In the "icon" variant it replaces the folder glyph.
@@ -40,11 +45,12 @@ export type CollectionSwitcherProps = CollectionUiOptions & {
40
45
  * trigger, so an app can open it from its own control and pass that control's
41
46
  * element (or the menu button that held it) as `anchorRef`.
42
47
  */
43
- export declare function CollectionSwitcher({ variant, className, icon, open: openProp, onOpenChange, anchorRef, ...options }: CollectionSwitcherProps): JSX.Element;
48
+ export declare function CollectionSwitcher({ variant, className, icon, open: openProp, onOpenChange, anchorRef, signedOutExtra, ...options }: CollectionSwitcherProps): JSX.Element;
44
49
  /** The switcher's list and actions, also shown inline by `CollectionPanel`. */
45
- export declare function SwitcherContent({ ui, onDone, onDialog }: {
50
+ export declare function SwitcherContent({ ui, onDone, onDialog, signedOutExtra }: {
46
51
  readonly ui: CollectionUi;
47
52
  readonly onDone: () => void;
48
53
  /** Open a row's dialog (remove from list, delete), for an SDK collection or an app section item. */
49
54
  readonly onDialog: (dialog: NonNullable<RowDialog>) => void;
55
+ readonly signedOutExtra?: ReactNode;
50
56
  }): JSX.Element;
@@ -22,6 +22,7 @@ export function CollectionSwitcher({
22
22
  open: openProp,
23
23
  onOpenChange,
24
24
  anchorRef,
25
+ signedOutExtra,
25
26
  ...options
26
27
  }) {
27
28
  const ui = useCollectionUi(options);
@@ -61,7 +62,8 @@ export function CollectionSwitcher({
61
62
  const content = _jsx(SwitcherContent, {
62
63
  ui: ui,
63
64
  onDone: () => close(false),
64
- onDialog: toDialog
65
+ onDialog: toDialog,
66
+ signedOutExtra: signedOutExtra
65
67
  });
66
68
  return _jsxs("span", {
67
69
  className: ["mdbase-collections", "mdbase-collections-switcher", className].filter(Boolean).join(" "),
@@ -120,7 +122,8 @@ export function CollectionSwitcher({
120
122
  export function SwitcherContent({
121
123
  ui,
122
124
  onDone,
123
- onDialog
125
+ onDialog,
126
+ signedOutExtra
124
127
  }) {
125
128
  const {
126
129
  view,
@@ -154,7 +157,7 @@ export function SwitcherContent({
154
157
  },
155
158
  children: copy.signIn
156
159
  })
157
- })]
160
+ }), signedOutExtra]
158
161
  });
159
162
  const appSections = sections.map(section => _jsx(SwitcherSection, {
160
163
  ui: ui,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdbase-dev/ui",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -258,6 +258,6 @@
258
258
  "typecheck": "node scripts/compile-catalogues.mjs && tsc -p tsconfig.json --noEmit"
259
259
  },
260
260
  "mdbaseRelease": {
261
- "commit": "751b7fb0fde87d60b847d4991274906aba1ffd42"
261
+ "commit": "74869d0822543c9a4d4621d9c3ee40d6a79b6fd6"
262
262
  }
263
263
  }