@mdbase-dev/ui 0.2.3 → 0.2.5

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
@@ -47,9 +47,12 @@ applyThemePreference(loadThemePreference());
47
47
  collection in another app. Every deployment passes its own URLs to
48
48
  `withAppUrls` (or `AppSwitcher`'s `urls` prop, which accepts all official
49
49
  apps). Apps without a configured URL are omitted; shared metadata never falls
50
- back to production origins. The switcher includes an AI clients (MCP) link by
51
- default (pass `mcpUrl={null}` to omit on custom servers) and ends with a
52
- "Build your own" link to the SDK guide.
50
+ back to production origins. `AppSwitcher` accepts any `OfficialAppId` as
51
+ `current`, optional `children`/`className`/`align` for apps with their own
52
+ trigger identity (such as TaskNotes), and an optional `collectionId` when the
53
+ app does not carry `?collection=` in `location.href`. The switcher includes an
54
+ AI clients (MCP) link by default (pass `mcpUrl={null}` to omit on custom
55
+ servers) and ends with a "Build your own" link to the SDK guide.
53
56
 
54
57
  ## Opening screen
55
58
 
@@ -1,5 +1,5 @@
1
- import { type JSX } from "react";
2
- import { type MdbaseAppId, type OfficialApp } from "./apps.js";
1
+ import { type JSX, type ReactNode } from "react";
2
+ import { type OfficialApp, type OfficialAppId } from "./apps.js";
3
3
  import { type MdbaseMarkMotion } from "./brand.js";
4
4
  /**
5
5
  * The product wordmark as a menu for opening the current collection in the other mdbase apps.
@@ -8,11 +8,18 @@ import { type MdbaseMarkMotion } from "./brand.js";
8
8
  * Its mark shows the page's activity (see `mark-activity`): progress, then a held loop,
9
9
  * then `motion`. Without a `motion` it plays `keys-first` the first time it appears.
10
10
  */
11
- export declare function AppSwitcher({ current, urls, mcpUrl, motion }: {
12
- readonly current: MdbaseAppId;
11
+ export declare function AppSwitcher({ current, urls, mcpUrl, motion, collectionId, className, align, children }: {
12
+ readonly current: OfficialAppId;
13
13
  /** Lab and local builds, for example `{ writer: import.meta.env.VITE_MDBASE_WRITER_URL }`. */
14
14
  readonly urls?: Partial<Record<OfficialApp["id"], string | undefined>>;
15
15
  /** Setup guide for AI clients using MCP; pass `null` to omit on custom servers. */
16
16
  readonly mcpUrl?: string | null | undefined;
17
17
  readonly motion?: MdbaseMarkMotion | undefined;
18
+ /** Current collection ID for apps that do not carry `?collection=` in `location.href`. */
19
+ readonly collectionId?: string | null | undefined;
20
+ readonly className?: string | undefined;
21
+ /** Which edge of the trigger the menu aligns to. Defaults to `"start"`. */
22
+ readonly align?: "start" | "end" | undefined;
23
+ /** Custom trigger content (mark and name) for apps with their own identity, such as TaskNotes. */
24
+ readonly children?: ReactNode;
18
25
  }): JSX.Element;
@@ -8,6 +8,9 @@ import { useMdbaseMarkActivity } from "./mark-activity.js";
8
8
  import { Menu } from "./Menu.js";
9
9
  /** Where the menu's "Build your own" link goes: the same SDK guide in every environment. */
10
10
  const sdkDocumentationUrl = "https://mdbase.dev/sdk/";
11
+ function isMdbaseAppId(id) {
12
+ return id === "editor" || id === "reader" || id === "writer";
13
+ }
11
14
  /**
12
15
  * The product wordmark as a menu for opening the current collection in the other mdbase apps.
13
16
  * Each opens in a new tab so the current app stays where it is.
@@ -19,7 +22,11 @@ export function AppSwitcher({
19
22
  current,
20
23
  urls = {},
21
24
  mcpUrl = mcpSetupUrl,
22
- motion
25
+ motion,
26
+ collectionId,
27
+ className,
28
+ align = "start",
29
+ children
23
30
  }) {
24
31
  useLocaleRevision();
25
32
  const menuId = useId();
@@ -30,11 +37,28 @@ export function AppSwitcher({
30
37
  setOpen(false);
31
38
  if (refocus) triggerRef.current?.focus();
32
39
  };
40
+ const triggerContent = children ?? (isMdbaseAppId(current) ? _jsx(Wordmark, {
41
+ app: current,
42
+ motion: activity.busy ?? motion ?? "keys-first",
43
+ signal: activity.signal,
44
+ progress: activity.progress
45
+ }) : _jsxs("span", {
46
+ className: "wordmark",
47
+ children: [_jsx(MdbaseAppMark, {
48
+ app: current,
49
+ className: "wordmark-mark"
50
+ }), _jsx("span", {
51
+ className: "wordmark-label",
52
+ children: _jsx("span", {
53
+ children: officialApps.find(app => app.id === current)?.name ?? current
54
+ })
55
+ })]
56
+ }));
33
57
  return _jsxs(_Fragment, {
34
58
  children: [_jsxs("button", {
35
59
  ref: triggerRef,
36
60
  type: "button",
37
- className: "mdbase-app-switcher",
61
+ className: className ? `mdbase-app-switcher ${className}` : "mdbase-app-switcher",
38
62
  "aria-haspopup": "menu",
39
63
  "aria-expanded": open,
40
64
  "aria-controls": open ? menuId : undefined,
@@ -51,12 +75,7 @@ export function AppSwitcher({
51
75
  setOpen(true);
52
76
  }
53
77
  },
54
- children: [_jsx(Wordmark, {
55
- app: current,
56
- motion: activity.busy ?? motion ?? "keys-first",
57
- signal: activity.signal,
58
- progress: activity.progress
59
- }), _jsx("svg", {
78
+ children: [triggerContent, _jsx("svg", {
60
79
  className: "mdbase-app-switcher-chevron",
61
80
  viewBox: "0 0 24 24",
62
81
  "aria-hidden": "true",
@@ -75,9 +94,11 @@ export function AppSwitcher({
75
94
  id: "vDwCOr",
76
95
  message: "mdbase apps"
77
96
  }),
97
+ align: align,
78
98
  children: _jsx(AppMenu, {
79
99
  apps: withAppUrls(urls, officialApps),
80
100
  current: current,
101
+ collectionId: collectionId,
81
102
  mcpUrl: mcpUrl,
82
103
  onClose: close
83
104
  })
@@ -87,11 +108,13 @@ export function AppSwitcher({
87
108
  function AppMenu({
88
109
  apps,
89
110
  current,
111
+ collectionId,
90
112
  mcpUrl,
91
113
  onClose
92
114
  }) {
93
115
  useLocaleRevision();
94
- const heading = new URL(location.href).searchParams.has("collection") ? _i18n._(
116
+ const hasCollection = Boolean(collectionId) || new URL(location.href).searchParams.has("collection");
117
+ const heading = hasCollection ? _i18n._(
95
118
  /** i18n */
96
119
  {
97
120
  id: "xxbaLR",
@@ -112,6 +135,7 @@ function AppMenu({
112
135
  children: apps.map(app => _jsx(AppItem, {
113
136
  app: app,
114
137
  current: app.id === current,
138
+ collectionId: collectionId,
115
139
  onOpen: () => onClose(false)
116
140
  }, app.id))
117
141
  }), mcpUrl && _jsxs(_Fragment, {
@@ -232,6 +256,7 @@ function McpItem({
232
256
  function AppItem({
233
257
  app,
234
258
  current,
259
+ collectionId,
235
260
  onOpen
236
261
  }) {
237
262
  useLocaleRevision();
@@ -269,7 +294,7 @@ function AppItem({
269
294
  return _jsxs("a", {
270
295
  className: "mdbase-menu-item",
271
296
  role: "menuitem",
272
- href: mdbaseAppHref(app.url, location.href),
297
+ href: mdbaseAppHref(app.url, location.href, collectionId),
273
298
  target: "_blank",
274
299
  rel: "noopener",
275
300
  onClick: onOpen,
package/dist/apps.d.ts CHANGED
@@ -31,4 +31,4 @@ export declare const mcpEndpointUrl = "https://mcp.mdbase.dev/mcp";
31
31
  */
32
32
  export declare function withAppUrls<App extends OfficialApp = MdbaseApp>(urls: Partial<Record<App["id"], string | undefined>>, apps?: readonly App[]): readonly App[];
33
33
  /** A link that opens the current page's collection in another app. */
34
- export declare function mdbaseAppHref(appUrl: string, currentHref: string): string;
34
+ export declare function mdbaseAppHref(appUrl: string, currentHref: string, collectionId?: string | null): string;
package/dist/apps.js CHANGED
@@ -89,12 +89,13 @@ export function withAppUrls(urls, apps = mdbaseApps) {
89
89
  */
90
90
  const sharedParameters = ["collection", "server"];
91
91
  /** A link that opens the current page's collection in another app. */
92
- export function mdbaseAppHref(appUrl, currentHref) {
92
+ export function mdbaseAppHref(appUrl, currentHref, collectionId) {
93
93
  const target = new URL(appUrl);
94
94
  const current = new URL(currentHref);
95
95
  for (const key of sharedParameters) {
96
96
  const value = current.searchParams.get(key);
97
97
  if (value) target.searchParams.set(key, value);
98
98
  }
99
+ if (collectionId) target.searchParams.set("collection", collectionId);
99
100
  return target.href;
100
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdbase-dev/ui",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -281,6 +281,6 @@
281
281
  "typecheck": "node scripts/compile-catalogues.mjs && tsc -p tsconfig.json --noEmit"
282
282
  },
283
283
  "mdbaseRelease": {
284
- "commit": "5bb9c376b241546766b342e09ed92924852cbbe7"
284
+ "commit": "0b2fd11aba6e542af6558dd92df5a7556f4c1444"
285
285
  }
286
286
  }