@mdbase-dev/ui 0.1.0-beta.158 → 0.1.0-beta.160

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
@@ -35,8 +35,9 @@ applyThemePreference(loadThemePreference());
35
35
  total is known, and `holdMdbaseMarkBusy(loop)` (or `useMdbaseMarkBusy`) while
36
36
  it is not.
37
37
  - `apps` lists the mdbase apps and builds links that open the current
38
- collection in another app. Lab and local builds pass their own URLs to
39
- `withAppUrls`.
38
+ collection in another app. Every deployment passes its own URLs to
39
+ `withAppUrls` (or `AppSwitcher`'s `urls` prop). Apps without a configured URL
40
+ are omitted; shared metadata never falls back to production origins.
40
41
 
41
42
  ## Icon-button tooltips
42
43
 
@@ -615,7 +615,7 @@
615
615
  gap: 4px;
616
616
  }
617
617
 
618
- .mdbase-collections-setup-section h3 {
618
+ .mdbase-collections-setup-section :is(h2, h3) {
619
619
  margin: 0;
620
620
  color: var(--_text-soft);
621
621
  font-size: var(--_font-size-caption);
package/css/controls.css CHANGED
@@ -322,16 +322,12 @@ textarea.mdbase-field {
322
322
  cursor: pointer;
323
323
  }
324
324
 
325
+ /* Pointer and keyboard share one highlight; hovering moves focus, so only one row is ever marked. */
325
326
  .mdbase-menu-item:hover:not(:disabled, [aria-disabled="true"]),
326
327
  .mdbase-menu .mdbase-menu-item:focus-visible {
328
+ outline: 0;
327
329
  color: var(--color-text);
328
- background: var(--color-surface-subtle);
329
- }
330
-
331
- /* One focus mark inside the row, instead of an outline around it. */
332
- .mdbase-menu .mdbase-menu-item:focus-visible {
333
- outline: var(--focus-ring);
334
- outline-offset: -1px;
330
+ background: var(--color-accent-soft);
335
331
  }
336
332
 
337
333
  .mdbase-menu-item:disabled {
package/css/motion.css CHANGED
@@ -21,6 +21,14 @@
21
21
  transition: opacity var(--motion-enter) var(--ease-out), transform var(--motion-enter) var(--ease-out);
22
22
  }
23
23
  .mdbase-overlay::backdrop { opacity: 1; transition: opacity var(--motion-enter) var(--ease-out); }
24
+ .mdbase-dialog.mdbase-overlay {
25
+ transition-property: opacity, transform, display, overlay;
26
+ transition-behavior: normal, normal, allow-discrete, allow-discrete;
27
+ }
28
+ .mdbase-dialog.mdbase-overlay::backdrop {
29
+ transition-property: opacity, display, overlay;
30
+ transition-behavior: normal, allow-discrete, allow-discrete;
31
+ }
24
32
  .mdbase-overlay[data-open="false"]::backdrop { opacity: 0; transition-duration: var(--motion-exit); transition-timing-function: var(--ease-exit); }
25
33
  .mdbase-overlay[data-open="false"] {
26
34
  opacity: 0;
@@ -4,7 +4,7 @@ import { useLocaleRevision } from "./i18n.js";
4
4
  import { Dialog } from "./Dialog.js";
5
5
  import { shortcutLabel } from "./shortcuts.js";
6
6
  export { isApplePlatform, shortcutLabel } from "./shortcuts.js";
7
- import { Fragment, useEffect, useLayoutEffect, useId, useMemo, useRef, useState } from "react";
7
+ import { Fragment, useLayoutEffect, useId, useMemo, useRef, useState } from "react";
8
8
  const browseLimit = 6;
9
9
  const searchLimit = 40;
10
10
  function contextualCommands(commands) {
@@ -106,16 +106,18 @@ function OpenCommandPalette({
106
106
  }) {
107
107
  useLocaleRevision();
108
108
  const [query, setQuery] = useState(initialQuery);
109
- const [active, setActive] = useState(0);
109
+ const [selected, setActive] = useState(0);
110
110
  const inputRef = useRef(null);
111
111
  const resultsRef = useRef(null);
112
112
  const matches = useMemo(() => getResults ? contextualCommands(getResults(query)) : matchingCommands(commands, query, showAll), [commands, query, showAll, getResults]);
113
+ // Live command updates can shrink the list under the selection.
114
+ const active = Math.min(selected, Math.max(0, matches.length - 1));
113
115
  useLayoutEffect(() => {
114
116
  resultsRef.current.querySelector('[aria-selected="true"]')?.scrollIntoView({
115
117
  block: "nearest"
116
118
  });
117
119
  }, [active, matches]);
118
- useEffect(() => {
120
+ useLayoutEffect(() => {
119
121
  if (open) {
120
122
  setQuery(initialQuery);
121
123
  setActive(0);
package/dist/Dialog.js CHANGED
@@ -66,6 +66,15 @@ export function Dialog({
66
66
  preventScroll: true
67
67
  });
68
68
  }, [closeDisabled, open, ref]);
69
+ useLayoutEffect(() => {
70
+ const dialog = ref.current;
71
+ if (open || !dialog) return;
72
+ const ownedFocus = dialog.contains(document.activeElement) || document.activeElement === document.body;
73
+ if (dialog.open) dialog.close();
74
+ if (ownedFocus) (returnFocusRef?.current ?? invoker.current)?.focus({
75
+ preventScroll: true
76
+ });
77
+ }, [open, ref, returnFocusRef]);
69
78
  useEffect(() => {
70
79
  const dialog = ref.current;
71
80
  return () => {
@@ -81,13 +90,16 @@ export function Dialog({
81
90
  ref: ref,
82
91
  className: ["mdbase-dialog mdbase-overlay", className].filter(Boolean).join(" "),
83
92
  "data-open": open,
93
+ inert: !open,
94
+ "aria-hidden": !open || undefined,
84
95
  role: role,
85
96
  "aria-modal": "true",
86
97
  "aria-labelledby": titleId,
87
98
  "aria-describedby": descriptionId,
88
99
  tabIndex: -1,
89
100
  onKeyDown: event => {
90
- event.stopPropagation();
101
+ // An exiting dialog no longer owns the keyboard, so app shortcuts still work.
102
+ if (open) event.stopPropagation();
91
103
  if (event.key === "Escape") {
92
104
  event.preventDefault();
93
105
  if (!closeDisabled) onClose();
@@ -106,6 +118,9 @@ export function Dialog({
106
118
  event.preventDefault();
107
119
  if (!closeDisabled) onClose();
108
120
  },
121
+ onMouseDown: event => {
122
+ if (event.target === event.currentTarget) event.preventDefault();
123
+ },
109
124
  onClick: event => {
110
125
  if (!closeDisabled && event.target === event.currentTarget) onClose();
111
126
  },
package/dist/Menu.js CHANGED
@@ -31,9 +31,19 @@ export function Menu({
31
31
  "aria-label": label,
32
32
  tabIndex: -1,
33
33
  onKeyDown: event => moveMenuFocus(event, ref.current),
34
+ onPointerMove: focusMenuItemUnderPointer,
34
35
  children: children
35
36
  }) : null;
36
37
  }
38
+ /** Hovering a row takes focus from the keyboard-marked one, unless a field in the menu is being typed in. */
39
+ function focusMenuItemUnderPointer(event) {
40
+ const menu = event.currentTarget;
41
+ if (event.pointerType !== "mouse" || document.activeElement instanceof HTMLInputElement && menu.contains(document.activeElement)) return;
42
+ const item = event.target.closest('[role^="menuitem"]:not(:disabled):not([aria-disabled="true"])');
43
+ if (item && menu.contains(item) && item !== document.activeElement) item.focus({
44
+ preventScroll: true
45
+ });
46
+ }
37
47
  export function useMenuTrigger() {
38
48
  const id = useId();
39
49
  const [open, setOpen] = useState(false);
package/dist/apps.d.ts CHANGED
@@ -8,13 +8,13 @@ export interface MdbaseApp {
8
8
  readonly id: MdbaseAppId;
9
9
  readonly name: string;
10
10
  readonly description: string;
11
- /** Production origin. Lab and local builds substitute their own with `withAppUrls`. */
11
+ /** Deployment URL supplied by the consumer with `withAppUrls`. */
12
12
  readonly url: string;
13
13
  }
14
14
  export declare const mdbaseApps: readonly MdbaseApp[];
15
15
  /**
16
16
  * Replaces app URLs for a lab or local build, for example from
17
- * `import.meta.env.VITE_MDBASE_WRITER_URL`. Unset entries keep production.
17
+ * `import.meta.env.VITE_MDBASE_WRITER_URL`. Apps without a URL are omitted.
18
18
  */
19
19
  export declare function withAppUrls(urls: Partial<Record<MdbaseAppId, string | undefined>>, apps?: readonly MdbaseApp[]): readonly MdbaseApp[];
20
20
  /** A link that opens the current page's collection in another app. */
package/dist/apps.js CHANGED
@@ -11,7 +11,7 @@ export const mdbaseApps = [{
11
11
  message: "Browse and edit records"
12
12
  });
13
13
  },
14
- url: "https://editor.mdbase.dev/"
14
+ url: ""
15
15
  }, {
16
16
  id: "reader",
17
17
  name: "Reader",
@@ -23,7 +23,7 @@ export const mdbaseApps = [{
23
23
  message: "Read and annotate sources"
24
24
  });
25
25
  },
26
- url: "https://reader.mdbase.dev/"
26
+ url: ""
27
27
  }, {
28
28
  id: "writer",
29
29
  name: "Writer",
@@ -35,11 +35,11 @@ export const mdbaseApps = [{
35
35
  message: "Write manuscripts that cite your sources"
36
36
  });
37
37
  },
38
- url: "https://writer.mdbase.dev/"
38
+ url: ""
39
39
  }];
40
40
  /**
41
41
  * Replaces app URLs for a lab or local build, for example from
42
- * `import.meta.env.VITE_MDBASE_WRITER_URL`. Unset entries keep production.
42
+ * `import.meta.env.VITE_MDBASE_WRITER_URL`. Apps without a URL are omitted.
43
43
  */
44
44
  export function withAppUrls(urls, apps = mdbaseApps) {
45
45
  return apps.map(app => {
@@ -48,7 +48,7 @@ export function withAppUrls(urls, apps = mdbaseApps) {
48
48
  ...app,
49
49
  url
50
50
  } : app;
51
- });
51
+ }).filter(app => app.url);
52
52
  }
53
53
  /**
54
54
  * Parameters every mdbase app reads the same way: `collection` is the Connect SDK's
@@ -156,10 +156,13 @@ function GateScreen({
156
156
  });
157
157
  }, [view.kind]);
158
158
  const Heading = layout === "page" ? "h1" : "h2";
159
+ const Container = layout === "page" ? "main" : "div";
159
160
  const opening = view.kind === "starting" || view.kind === "opening";
160
161
  const announce = view.kind === "authorizing" ? view.heading : "";
161
- return _jsxs("div", {
162
- ref: root,
162
+ return _jsxs(Container, {
163
+ ref: element => {
164
+ root.current = element;
165
+ },
163
166
  className: "mdbase-collections mdbase-collections-gate",
164
167
  "data-layout": layout,
165
168
  "data-phase": view.kind,
@@ -182,17 +185,18 @@ function GateScreen({
182
185
  children: headingText
183
186
  }), opening ? _jsx(OpeningScreen, {
184
187
  app: options.app,
185
- layout: layout,
188
+ layout: "panel",
186
189
  title: headingText,
187
190
  detail: lead ?? undefined
188
- }) : lead && _jsx("p", {
191
+ }) : lead && view.kind !== "needs_setup" && _jsx("p", {
189
192
  className: "mdbase-collections-lead",
190
193
  children: lead
191
194
  }), _jsx(GateBody, {
192
195
  ui: ui,
196
+ layout: layout,
193
197
  extraActions: view.kind === "signed_out" ? extra : undefined,
194
198
  onDialog: setDialog
195
- }), ui.error && _jsx(NoticeBlock, {
199
+ }), ui.error && !(view.kind === "choosing" && ui.error.key === "account_collection_quota_exceeded") && _jsx(NoticeBlock, {
196
200
  notice: ui.error,
197
201
  ui: ui,
198
202
  variant: "inline"
@@ -230,6 +234,7 @@ function showsChooseAnother(view) {
230
234
  }
231
235
  function GateBody({
232
236
  ui,
237
+ layout,
233
238
  extraActions,
234
239
  onDialog
235
240
  }) {
@@ -291,7 +296,11 @@ function GateBody({
291
296
  onDialog: onDialog
292
297
  }), _jsx("div", {
293
298
  className: "mdbase-collections-actions",
294
- children: _jsx(ActionButton, {
299
+ children: ui.error?.key === "account_collection_quota_exceeded" ? _jsx(NoticeBlock, {
300
+ notice: ui.error,
301
+ ui: ui,
302
+ variant: "inline"
303
+ }) : _jsx(ActionButton, {
295
304
  tone: view.collections.length > 0 ? "secondary" : "primary",
296
305
  inert: inert,
297
306
  progress: busy === "add" ? copy.addingCollection : null,
@@ -313,7 +322,8 @@ function GateBody({
313
322
  });
314
323
  case "needs_setup":
315
324
  return _jsx(SetupReview, {
316
- ui: ui
325
+ ui: ui,
326
+ layout: layout
317
327
  }, view.collectionId);
318
328
  case "problem":
319
329
  return _jsx(NoticeBlock, {
@@ -4,6 +4,7 @@ import type { CollectionUi } from "./use-collection-ui.js";
4
4
  * Reviewable setup: `setup.plan()` (read-only, so it starts at once), then
5
5
  * `setup.apply(plan)` only from the person's click. Never configures silently.
6
6
  */
7
- export declare function SetupReview({ ui }: {
7
+ export declare function SetupReview({ ui, layout }: {
8
8
  readonly ui: CollectionUi;
9
+ readonly layout?: "page" | "panel";
9
10
  }): JSX.Element;
@@ -10,7 +10,8 @@ const TRANSIENT_REPLANS = 15;
10
10
  * `setup.apply(plan)` only from the person's click. Never configures silently.
11
11
  */
12
12
  export function SetupReview({
13
- ui
13
+ ui,
14
+ layout = "panel"
14
15
  }) {
15
16
  const {
16
17
  mdbase
@@ -153,6 +154,7 @@ export function SetupReview({
153
154
  const nothing = plan.status === "current" || plan.changes.length === 0 && plan.conflicts.length === 0;
154
155
  const adoptable = Object.keys(plan.adoptable).length > 0;
155
156
  const applicable = !refusal && plan.canApply;
157
+ const Heading = layout === "page" ? "h2" : "h3";
156
158
  // NoticeBlock shows a refusal's own control, except `set_up` (this is setup).
157
159
  const refusalActs = !!refusalNotice?.control && refusalNotice.control.kind !== "set_up";
158
160
  // Never leave the review without a way forward.
@@ -171,7 +173,7 @@ export function SetupReview({
171
173
  children: nothing ? ui.copy.setupNothing : plan.summary
172
174
  }), plan.changes.length > 0 && _jsxs("section", {
173
175
  className: "mdbase-collections-setup-section",
174
- children: [_jsx("h3", {
176
+ children: [_jsx(Heading, {
175
177
  children: ui.copy.setupChanges
176
178
  }), _jsx("ul", {
177
179
  className: "mdbase-collections-setup-list",
@@ -181,7 +183,7 @@ export function SetupReview({
181
183
  })]
182
184
  }), plan.conflicts.length > 0 && _jsxs("section", {
183
185
  className: "mdbase-collections-setup-section",
184
- children: [_jsx("h3", {
186
+ children: [_jsx(Heading, {
185
187
  children: ui.copy.setupConflicts
186
188
  }), _jsx("ul", {
187
189
  className: "mdbase-collections-setup-list",
@@ -53,6 +53,9 @@ export function useCollectionUi(options) {
53
53
  }), [snapshot, app.name, copy]);
54
54
  const [busy, setBusy] = useState(null);
55
55
  const [error, setError] = useState(null);
56
+ useEffect(() => {
57
+ setError(previous => previous?.notice.key === "account_collection_quota_exceeded" ? null : previous);
58
+ }, [snapshot.collections.length]);
56
59
  const [signOutPrompt, setSignOutPrompt] = useState(null);
57
60
  const running = useRef(null);
58
61
  const latest = useRef({
package/dist/overlay.js CHANGED
@@ -7,14 +7,18 @@ export function useOverlay(open) {
7
7
  setRetained(true);
8
8
  return;
9
9
  }
10
- // The resolved transition duration is always in seconds, whatever a build does to the token.
11
- const duration = ref.current ? parseFloat(getComputedStyle(ref.current).transitionDuration) * 1000 : 0;
12
- if (!duration) {
10
+ const animations = ref.current?.getAnimations() ?? [];
11
+ if (animations.length === 0) {
13
12
  setRetained(false);
14
13
  return;
15
14
  }
16
- const timeout = setTimeout(() => setRetained(false), duration);
17
- return () => clearTimeout(timeout);
15
+ let cancelled = false;
16
+ void Promise.allSettled(animations.map(animation => animation.finished)).then(() => {
17
+ if (!cancelled) setRetained(false);
18
+ });
19
+ return () => {
20
+ cancelled = true;
21
+ };
18
22
  }, [open]);
19
23
  return {
20
24
  ref,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdbase-dev/ui",
3
- "version": "0.1.0-beta.158",
3
+ "version": "0.1.0-beta.160",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -158,7 +158,7 @@
158
158
  "@lingui/format-po": "6.9.0",
159
159
  "@lingui/react": "6.9.0",
160
160
  "@lingui/vite-plugin": "6.9.0",
161
- "@mdbase-dev/sdk": "file:vendor/sdk-0.0.0-bd131b16.tgz",
161
+ "@mdbase-dev/sdk": "0.1.0-beta.160",
162
162
  "@rolldown/plugin-babel": "^0.2.4",
163
163
  "@types/react": "^19.3.0",
164
164
  "@types/react-dom": "^19.3.0",
@@ -190,6 +190,6 @@
190
190
  "typecheck": "node scripts/compile-catalogues.mjs && tsc -p tsconfig.json --noEmit"
191
191
  },
192
192
  "mdbaseRelease": {
193
- "commit": "89548fc762b799ae686cb0143fe4ba11a0e537f3"
193
+ "commit": "42591b388b09cdeb8b291e8d9f3c949ce1fa8fb5"
194
194
  }
195
195
  }