@mcpview/components 0.11.0 → 0.12.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.
Files changed (32) hide show
  1. package/README.md +52 -6
  2. package/esm/preact-context.d.ts +10 -0
  3. package/esm/preact-context.d.ts.map +1 -0
  4. package/esm/preact-context.js +6 -0
  5. package/esm/src/context-basket-labels.d.ts +21 -0
  6. package/esm/src/context-basket-labels.d.ts.map +1 -0
  7. package/esm/src/context-basket-labels.js +40 -0
  8. package/esm/src/context-basket-styles.d.ts +8 -0
  9. package/esm/src/context-basket-styles.d.ts.map +1 -0
  10. package/esm/src/context-basket-styles.js +113 -0
  11. package/esm/src/preact/context-basket.d.ts +61 -0
  12. package/esm/src/preact/context-basket.d.ts.map +1 -0
  13. package/esm/src/preact/context-basket.js +201 -0
  14. package/esm/src/preact/use-active-context.d.ts +15 -0
  15. package/esm/src/preact/use-active-context.d.ts.map +1 -0
  16. package/esm/src/preact/use-active-context.js +28 -0
  17. package/package.json +10 -2
  18. package/script/preact-context.d.ts +10 -0
  19. package/script/preact-context.d.ts.map +1 -0
  20. package/script/preact-context.js +17 -0
  21. package/script/src/context-basket-labels.d.ts +21 -0
  22. package/script/src/context-basket-labels.d.ts.map +1 -0
  23. package/script/src/context-basket-labels.js +44 -0
  24. package/script/src/context-basket-styles.d.ts +8 -0
  25. package/script/src/context-basket-styles.d.ts.map +1 -0
  26. package/script/src/context-basket-styles.js +116 -0
  27. package/script/src/preact/context-basket.d.ts +61 -0
  28. package/script/src/preact/context-basket.d.ts.map +1 -0
  29. package/script/src/preact/context-basket.js +204 -0
  30. package/script/src/preact/use-active-context.d.ts +15 -0
  31. package/script/src/preact/use-active-context.d.ts.map +1 -0
  32. package/script/src/preact/use-active-context.js +31 -0
package/README.md CHANGED
@@ -31,11 +31,11 @@ npm i @mcpview/components
31
31
  SysML renderer.
32
32
 
33
33
  The package root is renderer-neutral and carries no MCP Apps runtime: `@mcpview/view` and
34
- `@modelcontextprotocol/ext-apps` are reached only through the `/surface` entry, which owns the App
35
- lifecycle. The responsive layout decision and its hooks live in the `/layout` entry, which takes the
36
- host context as a value and loads no App runtime. The embedded webfonts are reached only through the
37
- `/fonts` entry. Preact is an optional peer and is loaded only through the Preact subpaths and
38
- `/layout`, whose hooks are Preact:
34
+ `@modelcontextprotocol/ext-apps` are reached through the `/surface` entry (also re-exported by
35
+ `/preact`), which owns the App lifecycle. The responsive layout decision and its hooks live in the
36
+ `/layout` entry, which takes the host context as a value and loads no App runtime. The embedded
37
+ webfonts are reached only through the `/fonts` entry. Preact is an optional peer and is loaded only
38
+ through the Preact subpaths and `/layout`, whose hooks are Preact:
39
39
 
40
40
  ```ts
41
41
  import { defineComponentRegistry, installMcpViewTheme } from "@mcpview/components";
@@ -586,9 +586,55 @@ local checkout); the `/surface` entry is derived from the latter unless
586
586
  `MCP_VIEW_COMPONENTS_SURFACE_MODULE` names it. Run the generator from JSR:
587
587
 
588
588
  ```sh
589
- deno run -A jsr:@mcpview/components@0.11.0/scaffold result-viewer ./result-viewer
589
+ deno run -A jsr:@mcpview/components@0.12.0/scaffold result-viewer ./result-viewer
590
590
  ```
591
591
 
592
592
  The npm package contains only the runtime and presentation entry points. It does not export or ship
593
593
  `@mcpview/components/scaffold`; Node ESM imports and CommonJS requires of that subpath are expected
594
594
  to fail with `ERR_PACKAGE_PATH_NOT_EXPORTED` rather than loading a Deno-only module.
595
+
596
+ ## Active context
597
+
598
+ `@mcpview/components/preact/context` exports `ActiveContextChip`, `useActiveContext`,
599
+ `MCP_VIEW_CONTEXT_BASKET_CSS`, `MCP_VIEW_CONTEXT_SELECTION_CSS` and English/French labels through
600
+ `contextBasketLabels(locale)`. This narrow entry uses an existing `@mcpview/view/context` controller
601
+ and loads no App lifecycle, surface mounting or embedded fonts. Preact remains an optional peer.
602
+
603
+ Create the controller once outside the component tree, then call
604
+ `useActiveContext(controller, scopeKey)` in the view. The hook subscribes to acknowledged
605
+ selections, pending updates, failures and root-scoped actions. `selectionState(itemOrId)` exposes
606
+ `selected | adding | removing | none` for rows/cards immediately, including provisional pointer
607
+ intent; `isSelected(item)` retains its ACK-confirmed meaning. `ActiveContextChip` displays the
608
+ basket and calls the supplied removal, clear and optional retry callbacks. Labels, tool-resolvable
609
+ IDs, grouping and resource disclosure belong to the App; groups affect presentation rather than the
610
+ wire snapshot.
611
+
612
+ ```ts
613
+ import { createActiveContextController, createActiveContextPolicy } from "@mcpview/view/context";
614
+ import {
615
+ ActiveContextChip,
616
+ contextBasketLabels,
617
+ MCP_VIEW_CONTEXT_BASKET_CSS,
618
+ MCP_VIEW_CONTEXT_SELECTION_CSS,
619
+ useActiveContext,
620
+ } from "@mcpview/components/preact/context";
621
+ ```
622
+
623
+ Install the exported CSS once for the view; importing the entry does not inject styles. The chip
624
+ keeps confirmed selections visible while an update is pending or fails, exposes failures to
625
+ assistive technology and lets the App provide retry. Accepted Retry restores focus to a retained
626
+ basket control, or an external control if the basket disappears; rejected results preserve focus.
627
+ Use explicit buttons for selection/removal alongside optional gestures. Before sending a resource,
628
+ show its name, byte size and that it will be sent to the model.
629
+
630
+ For optional row styling, install `MCP_VIEW_CONTEXT_SELECTION_CSS` alongside the shared
631
+ `MCP_VIEW_THEME_CSS` from `@mcpview/components`. Apply class `mcp-view-context-selection` and
632
+ `data-context-state={context.selectionState(item)}` to the selection control. The styles use the
633
+ shared light/dark theme tokens; dashed borders distinguish adding/removing from confirmed selection.
634
+ Expose the pending state in accessible text or `aria-busy`, and derive desired `aria-pressed` from
635
+ `selected`/`adding`. The basket count still uses acknowledged selections. Connect `onPreview` to
636
+ `context.previewToggle(item)` for immediate row feedback during the arbiter's default 500 ms delay.
637
+
638
+ See the [context example](../view/examples/context/README.md) for a complete integration. The
639
+ controls are experimental. An ACK confirms host acceptance only; model consumption, production host
640
+ behavior and cross-iframe ownership require separate validation.
@@ -0,0 +1,10 @@
1
+ /** Context controls without the MCP Apps lifecycle or surface runtime. @module */
2
+ import "./_dnt.polyfills.js";
3
+ export { ActiveContextChip } from "./src/preact/context-basket.js";
4
+ export type { ActiveContextChipProps, ContextBasketEntry, ContextBasketGroup, ContextBasketLabels, ContextBasketSelection, ContextBasketSlot, ContextMutation, } from "./src/preact/context-basket.js";
5
+ export { useActiveContext } from "./src/preact/use-active-context.js";
6
+ export type { ActiveContextHook } from "./src/preact/use-active-context.js";
7
+ export { CONTEXT_BASKET_MESSAGES_EN, CONTEXT_BASKET_MESSAGES_FR, contextBasketLabels, contextBasketMessages, } from "./src/context-basket-labels.js";
8
+ export type { ContextBasketMessages } from "./src/context-basket-labels.js";
9
+ export { MCP_VIEW_CONTEXT_BASKET_CSS, MCP_VIEW_CONTEXT_SELECTION_CSS, } from "./src/context-basket-styles.js";
10
+ //# sourceMappingURL=preact-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preact-context.d.ts","sourceRoot":"","sources":["../src/preact-context.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EACV,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,GAChB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Context controls without the MCP Apps lifecycle or surface runtime. @module */
2
+ import "./_dnt.polyfills.js";
3
+ export { ActiveContextChip } from "./src/preact/context-basket.js";
4
+ export { useActiveContext } from "./src/preact/use-active-context.js";
5
+ export { CONTEXT_BASKET_MESSAGES_EN, CONTEXT_BASKET_MESSAGES_FR, contextBasketLabels, contextBasketMessages, } from "./src/context-basket-labels.js";
6
+ export { MCP_VIEW_CONTEXT_BASKET_CSS, MCP_VIEW_CONTEXT_SELECTION_CSS, } from "./src/context-basket-styles.js";
@@ -0,0 +1,21 @@
1
+ import { type TranslatorSelector } from "./i18n.js";
2
+ import type { ContextBasketLabels } from "./preact/context-basket.js";
3
+ /** Interface text only; selection labels and group summaries remain caller data. */
4
+ export declare const CONTEXT_BASKET_MESSAGES_EN: {
5
+ readonly active: "Active context";
6
+ readonly items: "Context items";
7
+ readonly remove: "Remove {label} from context";
8
+ readonly clearAll: "Clear context";
9
+ readonly pending: "Updating context…";
10
+ readonly error: "Context update failed";
11
+ readonly retry: "Retry";
12
+ readonly evicted: "Removed oldest item: {label}";
13
+ };
14
+ export type ContextBasketMessages = {
15
+ readonly [Key in keyof typeof CONTEXT_BASKET_MESSAGES_EN]: string;
16
+ };
17
+ export declare const CONTEXT_BASKET_MESSAGES_FR: ContextBasketMessages;
18
+ export declare const contextBasketMessages: TranslatorSelector<keyof ContextBasketMessages>;
19
+ /** Optional EN/FR kit labels. Pass your own labels to customize any interface text. */
20
+ export declare function contextBasketLabels(locale?: string): ContextBasketLabels;
21
+ //# sourceMappingURL=context-basket-labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-basket-labels.d.ts","sourceRoot":"","sources":["../../src/src/context-basket-labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,oFAAoF;AACpF,eAAO,MAAM,0BAA0B;;;;;;;;;CAS7B,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,GAAG,IAAI,MAAM,OAAO,0BAA0B,GAAG,MAAM;CAClE,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,qBASxC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,CAAC,MAAM,qBAAqB,CAI9E,CAAC;AAEL,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAYxE"}
@@ -0,0 +1,40 @@
1
+ import { createTranslator } from "./i18n.js";
2
+ /** Interface text only; selection labels and group summaries remain caller data. */
3
+ export const CONTEXT_BASKET_MESSAGES_EN = {
4
+ active: "Active context",
5
+ items: "Context items",
6
+ remove: "Remove {label} from context",
7
+ clearAll: "Clear context",
8
+ pending: "Updating context…",
9
+ error: "Context update failed",
10
+ retry: "Retry",
11
+ evicted: "Removed oldest item: {label}",
12
+ };
13
+ export const CONTEXT_BASKET_MESSAGES_FR = {
14
+ active: "Contexte actif",
15
+ items: "Éléments du contexte",
16
+ remove: "Retirer {label} du contexte",
17
+ clearAll: "Vider le contexte",
18
+ pending: "Mise à jour du contexte…",
19
+ error: "Échec de la mise à jour du contexte",
20
+ retry: "Réessayer",
21
+ evicted: "Élément le plus ancien retiré : {label}",
22
+ };
23
+ export const contextBasketMessages = createTranslator({
24
+ messages: CONTEXT_BASKET_MESSAGES_EN,
25
+ translations: { fr: CONTEXT_BASKET_MESSAGES_FR },
26
+ });
27
+ /** Optional EN/FR kit labels. Pass your own labels to customize any interface text. */
28
+ export function contextBasketLabels(locale) {
29
+ const t = contextBasketMessages(locale);
30
+ return {
31
+ active: t("active"),
32
+ items: t("items"),
33
+ clearAll: t("clearAll"),
34
+ pending: t("pending"),
35
+ error: t("error"),
36
+ retry: t("retry"),
37
+ remove: (label) => t("remove", { label }),
38
+ evicted: (label) => t("evicted", { label }),
39
+ };
40
+ }
@@ -0,0 +1,8 @@
1
+ /** Optional plain CSS for the controlled context basket; uses the shared theme tokens. */
2
+ export declare const MCP_VIEW_CONTEXT_BASKET_CSS: string;
3
+ /**
4
+ * Optional row/card selection treatment. Set data-context-state from
5
+ * useActiveContext().selectionState(item); shared light/dark theme tokens apply.
6
+ */
7
+ export declare const MCP_VIEW_CONTEXT_SELECTION_CSS: string;
8
+ //# sourceMappingURL=context-basket-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-basket-styles.d.ts","sourceRoot":"","sources":["../../src/src/context-basket-styles.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,eAAO,MAAM,2BAA2B,EAAE,MAiFzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAyB5C,CAAC"}
@@ -0,0 +1,113 @@
1
+ /** Optional plain CSS for the controlled context basket; uses the shared theme tokens. */
2
+ export const MCP_VIEW_CONTEXT_BASKET_CSS = String.raw `
3
+ .mcp-view-context-root {
4
+ position: relative; display: inline-flex; min-width: 0; max-width: 100%;
5
+ align-items: center; gap: .375rem; color: var(--mcp-view-muted);
6
+ font-family: var(--mcp-view-font-body); font-size: var(--mcp-view-size-chip);
7
+ }
8
+ .mcp-view-context-single, .mcp-view-context-trigger {
9
+ display: inline-flex; min-width: 0; align-items: center; gap: .25rem;
10
+ border: 1px solid color-mix(in srgb, var(--mcp-view-accent) 30%, transparent);
11
+ border-radius: var(--mcp-view-radius-control, 5px);
12
+ background: color-mix(in srgb, var(--mcp-view-accent) 8%, transparent);
13
+ }
14
+ .mcp-view-context-single { padding: .125rem .125rem .125rem .5rem; }
15
+ .mcp-view-context-activeLabel, .mcp-view-context-trigger { color: var(--mcp-view-accent-text); }
16
+ .mcp-view-context-activeLabel, .mcp-view-context-chevron { flex-shrink: 0; }
17
+ .mcp-view-context-singleLabel, .mcp-view-context-itemLabel { color: var(--mcp-view-text); }
18
+ .mcp-view-context-singleLabel, .mcp-view-context-itemLabel, .mcp-view-context-itemDetail,
19
+ .mcp-view-context-eviction, .mcp-view-context-pendingLabel {
20
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
21
+ }
22
+ .mcp-view-context-trigger, .mcp-view-context-remove, .mcp-view-context-clearAll,
23
+ .mcp-view-context-retry {
24
+ font: inherit; cursor: pointer;
25
+ }
26
+ .mcp-view-context-trigger { padding: .25rem .5rem; }
27
+ .mcp-view-context-remove {
28
+ display: grid; width: 1.5rem; height: 1.5rem; flex-shrink: 0; place-items: center;
29
+ padding: 0; border: 0; border-radius: var(--mcp-view-radius-sm, 3px);
30
+ background: transparent; color: var(--mcp-view-quiet); font-size: var(--mcp-view-size-body); line-height: 1;
31
+ }
32
+ .mcp-view-context-trigger:hover, .mcp-view-context-remove:hover {
33
+ background: color-mix(in srgb, var(--mcp-view-accent) 12%, transparent);
34
+ }
35
+ .mcp-view-context-remove:hover { color: var(--mcp-view-text); }
36
+ .mcp-view-context-root button:focus-visible {
37
+ outline: 2px solid var(--mcp-view-accent); outline-offset: 1px;
38
+ }
39
+ .mcp-view-context-popover {
40
+ position: absolute; top: 100%; z-index: 30; margin-top: .375rem;
41
+ width: 14rem; max-width: calc(100vw - 24px); padding: .375rem;
42
+ border: 1px solid var(--mcp-view-border); border-radius: var(--mcp-view-radius, 8px);
43
+ background: var(--mcp-view-panel);
44
+ }
45
+ .mcp-view-context-popover[data-align="start"] { left: 0; }
46
+ .mcp-view-context-popover[data-align="end"] { right: 0; }
47
+ .mcp-view-context-list { display: flex; max-height: 16rem; flex-direction: column; overflow-y: auto; }
48
+ .mcp-view-context-item {
49
+ display: flex; min-width: 0; align-items: center; gap: .5rem;
50
+ border-radius: var(--mcp-view-radius-sm, 3px); padding: .25rem .375rem;
51
+ }
52
+ .mcp-view-context-item:hover { background: var(--mcp-view-subtle); }
53
+ .mcp-view-context-itemContent { min-width: 0; flex: 1; }
54
+ .mcp-view-context-itemLabel, .mcp-view-context-itemDetail { display: block; }
55
+ .mcp-view-context-itemDetail, .mcp-view-context-clearAll, .mcp-view-context-eviction {
56
+ font-size: var(--mcp-view-size-micro); color: var(--mcp-view-quiet);
57
+ }
58
+ .mcp-view-context-clearAll {
59
+ width: 100%; margin-top: .25rem; padding: .375rem .375rem 0;
60
+ border: 0; border-top: 1px solid var(--mcp-view-border-soft);
61
+ background: transparent; text-align: left;
62
+ }
63
+ .mcp-view-context-clearAll:hover, .mcp-view-context-error { color: var(--mcp-view-danger); }
64
+ .mcp-view-context-pending, .mcp-view-context-error { display: inline-flex; align-items: center; gap: .25rem; }
65
+ .mcp-view-context-pending { min-width: 0; }
66
+ .mcp-view-context-error { flex-shrink: 0; }
67
+ .mcp-view-context-spinner { flex-shrink: 0; animation: mcp-view-context-spin 1s linear infinite; }
68
+ .mcp-view-context-eviction { max-width: 9rem; }
69
+ .mcp-view-context-root[data-compact] .mcp-view-context-singleLabel,
70
+ .mcp-view-context-root[data-compact] .mcp-view-context-eviction { max-width: 6rem; }
71
+ .mcp-view-context-root[data-compact] .mcp-view-context-activeLabel,
72
+ .mcp-view-context-errorLabel[data-hidden] {
73
+ position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
74
+ overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
75
+ }
76
+ .mcp-view-context-retry {
77
+ border: 1px solid currentColor; border-radius: var(--mcp-view-radius-sm, 3px);
78
+ padding: .125rem .375rem; background: transparent; color: inherit;
79
+ }
80
+ .mcp-view-context-root button:disabled { cursor: default; opacity: .55; }
81
+ @keyframes mcp-view-context-spin { to { transform: rotate(360deg); } }
82
+ @media (prefers-reduced-motion: reduce) { .mcp-view-context-spinner { animation: none; } }
83
+ `;
84
+ /**
85
+ * Optional row/card selection treatment. Set data-context-state from
86
+ * useActiveContext().selectionState(item); shared light/dark theme tokens apply.
87
+ */
88
+ export const MCP_VIEW_CONTEXT_SELECTION_CSS = String.raw `
89
+ .mcp-view-context-selection {
90
+ border: 1px solid var(--mcp-view-border); border-radius: var(--mcp-view-radius-control, 5px);
91
+ background: var(--mcp-view-panel); color: var(--mcp-view-text);
92
+ }
93
+ .mcp-view-context-selection[data-context-state="selected"] {
94
+ border-color: var(--mcp-view-accent);
95
+ background: color-mix(in srgb, var(--mcp-view-accent) 12%, var(--mcp-view-panel));
96
+ box-shadow: inset 3px 0 var(--mcp-view-accent);
97
+ }
98
+ .mcp-view-context-selection[data-context-state="adding"] {
99
+ border-color: var(--mcp-view-accent); border-style: dashed;
100
+ background: color-mix(in srgb, var(--mcp-view-accent) 12%, var(--mcp-view-panel));
101
+ box-shadow: inset 3px 0 var(--mcp-view-accent);
102
+ }
103
+ .mcp-view-context-selection[data-context-state="removing"] {
104
+ border-color: var(--mcp-view-quiet); border-style: dashed;
105
+ background: var(--mcp-view-subtle); color: var(--mcp-view-muted);
106
+ }
107
+ .mcp-view-context-selection:focus-visible {
108
+ outline: 2px solid var(--mcp-view-accent); outline-offset: 2px;
109
+ }
110
+ .mcp-view-context-selection-status {
111
+ margin-inline-start: .5rem; font-size: var(--mcp-view-size-chip); color: var(--mcp-view-muted);
112
+ }
113
+ `;
@@ -0,0 +1,61 @@
1
+ /** @jsxImportSource preact */
2
+ import type { JSX } from "preact";
3
+ /** Minimum presentation identity; the owning controller retains the full payload. */
4
+ export interface ContextBasketSelection {
5
+ readonly scopeKey: string;
6
+ readonly item: {
7
+ readonly id: string;
8
+ readonly label: string;
9
+ readonly view?: string;
10
+ readonly value?: string;
11
+ };
12
+ }
13
+ /** A caller-projected group: identities, membership and summaries remain caller-owned. */
14
+ export interface ContextBasketGroup {
15
+ readonly scopeKey: string;
16
+ readonly id: string;
17
+ readonly label: string;
18
+ readonly summary?: string;
19
+ readonly view?: string;
20
+ readonly value?: string;
21
+ }
22
+ export type ContextBasketEntry<T extends ContextBasketSelection = ContextBasketSelection> = {
23
+ readonly kind: "single";
24
+ readonly selection: T;
25
+ } | {
26
+ readonly kind: "group";
27
+ readonly group: ContextBasketGroup;
28
+ };
29
+ /** Every visible message and accessible name follows the caller's locale. */
30
+ export interface ContextBasketLabels {
31
+ readonly active: string;
32
+ readonly items: string;
33
+ readonly remove: (label: string) => string;
34
+ readonly clearAll: string;
35
+ readonly pending: string;
36
+ readonly error: string;
37
+ readonly retry: string;
38
+ readonly evicted: (label: string) => string;
39
+ }
40
+ export type ContextBasketSlot = "root" | "single" | "activeLabel" | "singleLabel" | "remove" | "trigger" | "chevron" | "popover" | "list" | "item" | "itemContent" | "itemLabel" | "itemDetail" | "clearAll" | "pending" | "spinner" | "error" | "errorLabel" | "eviction" | "pendingLabel" | "retry";
41
+ export type ContextMutation = () => unknown | Promise<unknown>;
42
+ export interface ActiveContextChipProps<T extends ContextBasketSelection = ContextBasketSelection> {
43
+ readonly selections: readonly T[];
44
+ /** Overrides the visible list, e.g. one entry per group instead of its projected members. */
45
+ readonly entries?: readonly ContextBasketEntry<T>[];
46
+ readonly labels: ContextBasketLabels;
47
+ readonly failed?: boolean;
48
+ readonly pending?: boolean;
49
+ readonly evictedLabel?: string | null;
50
+ readonly onRemove?: (selection: T) => unknown | Promise<unknown>;
51
+ readonly onRemoveGroup?: (group: ContextBasketGroup) => unknown | Promise<unknown>;
52
+ readonly onClear: ContextMutation;
53
+ readonly onRetry?: ContextMutation;
54
+ readonly compact?: boolean;
55
+ readonly popoverAlign?: "start" | "end";
56
+ readonly className?: string;
57
+ readonly classes?: Partial<Record<ContextBasketSlot, string>>;
58
+ }
59
+ /** Controlled basket. Acknowledged selections and mutation results remain caller-owned. */
60
+ export declare function ActiveContextChip<T extends ContextBasketSelection>({ selections, entries, labels, failed, pending, evictedLabel, onRemove, onRemoveGroup, onClear, onRetry, compact, popoverAlign, className, classes, }: ActiveContextChipProps<T>): JSX.Element | null;
61
+ //# sourceMappingURL=context-basket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-basket.d.ts","sourceRoot":"","sources":["../../../src/src/preact/context-basket.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAGlC,qFAAqF;AACrF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,C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;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IACxC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;CAC/D;AAsCD,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,sBAAsB,EAChE,EACE,UAAU,EACV,OAAO,EACP,MAAM,EACN,MAAc,EACd,OAAe,EACf,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,OAAO,EACP,OAAO,EACP,OAAe,EACf,YAAoB,EACpB,SAAS,EACT,OAAO,GACR,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAC3B,GAAG,CAAC,OAAO,GAAG,IAAI,CA0QpB"}
@@ -0,0 +1,201 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "preact/hooks";
3
+ const FOCUSABLE_SELECTOR = [
4
+ "a[href]",
5
+ "button:not([disabled])",
6
+ "input:not([disabled])",
7
+ "select:not([disabled])",
8
+ "textarea:not([disabled])",
9
+ '[tabindex]:not([tabindex="-1"])',
10
+ ].join(",");
11
+ function accepted(result) {
12
+ return result === "shared" || result === "cleared";
13
+ }
14
+ function outsideFocusable(wrapper) {
15
+ if (!wrapper)
16
+ return null;
17
+ const elements = Array.from(wrapper.ownerDocument.querySelectorAll(FOCUSABLE_SELECTOR));
18
+ const current = elements.indexOf(wrapper.ownerDocument.activeElement);
19
+ return elements.slice(current + 1).find((element) => !wrapper.contains(element)) ??
20
+ elements.slice(0, Math.max(0, current)).reverse().find((element) => !wrapper.contains(element)) ??
21
+ null;
22
+ }
23
+ function entryKey(entry) {
24
+ return entry.kind === "group"
25
+ ? JSON.stringify(["group", entry.group.scopeKey, entry.group.id])
26
+ : JSON.stringify(["single", entry.selection.scopeKey, entry.selection.item.id]);
27
+ }
28
+ function display(entry) {
29
+ return entry.kind === "group" ? entry.group : entry.selection.item;
30
+ }
31
+ /** Controlled basket. Acknowledged selections and mutation results remain caller-owned. */
32
+ export function ActiveContextChip({ selections, entries, labels, failed = false, pending = false, evictedLabel, onRemove, onRemoveGroup, onClear, onRetry, compact = false, popoverAlign = "end", className, classes, }) {
33
+ const slot = (name) => [`mcp-view-context-${name}`, classes?.[name]].filter(Boolean).join(" ");
34
+ const [open, setOpen] = useState(false);
35
+ const wrapperRef = useRef(null);
36
+ const triggerRef = useRef(null);
37
+ const singleRemoveRef = useRef(null);
38
+ const removeRefs = useRef(new Map());
39
+ const mountedRef = useRef(true);
40
+ const operationRef = useRef(0);
41
+ const popoverId = useId();
42
+ const visible = entries ??
43
+ selections.map((selection) => ({ kind: "single", selection }));
44
+ const visibleRef = useRef(visible);
45
+ visibleRef.current = visible;
46
+ const count = visible.length;
47
+ useLayoutEffect(() => {
48
+ mountedRef.current = true;
49
+ return () => {
50
+ mountedRef.current = false;
51
+ operationRef.current++;
52
+ };
53
+ }, []);
54
+ useEffect(() => {
55
+ if (count <= 1)
56
+ setOpen(false);
57
+ }, [count]);
58
+ useEffect(() => {
59
+ if (!open)
60
+ return;
61
+ const doc = wrapperRef.current.ownerDocument;
62
+ function pointer(event) {
63
+ if (!wrapperRef.current?.contains(event.target)) {
64
+ operationRef.current++;
65
+ setOpen(false);
66
+ }
67
+ }
68
+ function key(event) {
69
+ if (event.key !== "Escape")
70
+ return;
71
+ event.preventDefault();
72
+ operationRef.current++;
73
+ setOpen(false);
74
+ triggerRef.current?.focus();
75
+ }
76
+ doc.addEventListener("pointerdown", pointer);
77
+ doc.addEventListener("keydown", key);
78
+ return () => {
79
+ doc.removeEventListener("pointerdown", pointer);
80
+ doc.removeEventListener("keydown", key);
81
+ };
82
+ }, [open]);
83
+ // Run after the controlled render, and never steal focus back from a user who moved away.
84
+ function afterAccepted(operation, origin, callback) {
85
+ queueMicrotask(() => {
86
+ if (!mountedRef.current || operation !== operationRef.current)
87
+ return;
88
+ const current = origin?.ownerDocument.activeElement;
89
+ // A removed button naturally loses browser focus; a deliberate focus change wins.
90
+ if (origin && current !== origin && current !== origin.ownerDocument.body)
91
+ return;
92
+ callback();
93
+ });
94
+ }
95
+ async function remove(entry, index) {
96
+ const operation = ++operationRef.current;
97
+ const origin = wrapperRef.current?.ownerDocument.activeElement ?? null;
98
+ const external = outsideFocusable(wrapperRef.current);
99
+ let result;
100
+ try {
101
+ result = await (entry.kind === "group"
102
+ ? onRemoveGroup?.(entry.group)
103
+ : onRemove
104
+ ? onRemove(entry.selection)
105
+ : count === 1
106
+ ? onClear()
107
+ : undefined);
108
+ }
109
+ catch {
110
+ return;
111
+ }
112
+ if (!accepted(result))
113
+ return;
114
+ afterAccepted(operation, origin, () => {
115
+ const remaining = visibleRef.current;
116
+ if (!remaining.length) {
117
+ if (external?.isConnected)
118
+ external.focus({ preventScroll: true });
119
+ }
120
+ else if (remaining.length === 1) {
121
+ singleRemoveRef.current?.focus({ preventScroll: true });
122
+ }
123
+ else {
124
+ const neighbour = remaining[Math.min(index, remaining.length - 1)];
125
+ (removeRefs.current.get(entryKey(neighbour)) ?? triggerRef.current)?.focus({
126
+ preventScroll: true,
127
+ });
128
+ }
129
+ });
130
+ }
131
+ async function clear() {
132
+ const operation = ++operationRef.current;
133
+ const origin = wrapperRef.current?.ownerDocument.activeElement ?? null;
134
+ const external = outsideFocusable(wrapperRef.current);
135
+ let result;
136
+ try {
137
+ result = await onClear();
138
+ }
139
+ catch {
140
+ return;
141
+ }
142
+ if (!accepted(result))
143
+ return;
144
+ afterAccepted(operation, origin, () => {
145
+ setOpen(false);
146
+ if (external?.isConnected)
147
+ external.focus({ preventScroll: true });
148
+ });
149
+ }
150
+ async function retry() {
151
+ const operation = ++operationRef.current;
152
+ const origin = wrapperRef.current?.ownerDocument.activeElement ?? null;
153
+ const external = outsideFocusable(wrapperRef.current);
154
+ let result;
155
+ try {
156
+ result = await onRetry?.();
157
+ }
158
+ catch {
159
+ return;
160
+ }
161
+ if (!accepted(result))
162
+ return;
163
+ afterAccepted(operation, origin, () => {
164
+ // Retry may clear the basket, remove one item, or retain its confirmed list.
165
+ // Choose from the controlled render after ACK rather than the failed intent.
166
+ const retained = visibleRef.current.length === 1
167
+ ? singleRemoveRef.current
168
+ : triggerRef.current;
169
+ if (retained?.isConnected && !retained.disabled) {
170
+ retained.focus({ preventScroll: true });
171
+ }
172
+ else if (origin?.isConnected) {
173
+ origin.focus({ preventScroll: true });
174
+ }
175
+ else if (external?.isConnected) {
176
+ external.focus({ preventScroll: true });
177
+ }
178
+ });
179
+ }
180
+ function removeButton(entry, index, single = false) {
181
+ const item = display(entry);
182
+ return (_jsx("button", { type: "button", class: slot("remove"), ref: (element) => {
183
+ if (single)
184
+ singleRemoveRef.current = element;
185
+ if (element)
186
+ removeRefs.current.set(entryKey(entry), element);
187
+ else
188
+ removeRefs.current.delete(entryKey(entry));
189
+ }, disabled: pending || (entry.kind === "group" ? !onRemoveGroup : !onRemove && count > 1), "aria-label": labels.remove(item.label), title: labels.remove(item.label), onClick: () => void remove(entry, index), children: _jsx("span", { "aria-hidden": "true", children: "\u00D7" }) }));
190
+ }
191
+ if (count === 0 && !failed && !pending && !evictedLabel)
192
+ return null;
193
+ return (_jsxs("span", { ref: wrapperRef, "aria-busy": pending || undefined, class: [slot("root"), className].filter(Boolean).join(" "), "data-compact": compact || undefined, children: [count === 1 && (_jsxs("span", { class: slot("single"), "aria-live": "polite", "aria-atomic": "true", children: [_jsx("span", { class: slot("activeLabel"), children: labels.active }), _jsx("span", { class: slot("singleLabel"), title: display(visible[0]).label, children: display(visible[0]).label }), removeButton(visible[0], 0, true)] })), count > 1 && (_jsxs(_Fragment, { children: [_jsxs("button", { ref: triggerRef, type: "button", class: slot("trigger"), "aria-expanded": open, "aria-controls": open ? popoverId : undefined, "aria-haspopup": "dialog", onClick: () => {
194
+ operationRef.current++;
195
+ setOpen((value) => !value);
196
+ }, children: [_jsxs("span", { "aria-live": "polite", "aria-atomic": "true", children: [labels.active, " \u00B7 ", count] }), _jsx("span", { "aria-hidden": "true", class: slot("chevron"), children: open ? "▴" : "▾" })] }), open && (_jsxs("span", { id: popoverId, role: "dialog", "aria-label": labels.items, class: slot("popover"), "data-align": popoverAlign, children: [_jsx("span", { role: "list", class: slot("list"), children: visible.map((entry, index) => {
197
+ const item = display(entry);
198
+ const summary = entry.kind === "group" ? entry.group.summary : undefined;
199
+ return (_jsxs("span", { role: "listitem", class: slot("item"), children: [_jsxs("span", { class: slot("itemContent"), children: [_jsx("span", { class: slot("itemLabel"), children: item.label }), _jsx("span", { class: slot("itemDetail"), children: summary ?? [item.view, item.value].filter(Boolean).join(" · ") })] }), removeButton(entry, index)] }, entryKey(entry)));
200
+ }) }), _jsx("button", { type: "button", class: slot("clearAll"), disabled: pending, onClick: () => void clear(), children: labels.clearAll })] }))] })), pending && (_jsxs("span", { role: "status", "aria-live": "polite", class: slot("pending"), title: labels.pending, children: [_jsx("span", { "aria-hidden": "true", class: slot("spinner"), children: "\u25CC" }), _jsx("span", { class: slot("pendingLabel"), children: labels.pending })] })), failed && (_jsxs("span", { role: "status", class: slot("error"), title: labels.error, children: [_jsx("span", { "aria-hidden": "true", children: "!" }), _jsx("span", { class: slot("errorLabel"), "data-hidden": compact && count > 0 || undefined, children: labels.error }), onRetry && (_jsx("button", { type: "button", class: slot("retry"), disabled: pending, onClick: () => void retry(), children: labels.retry }))] })), evictedLabel && (_jsx("span", { role: "status", "aria-live": "polite", class: slot("eviction"), title: labels.evicted(evictedLabel), children: labels.evicted(evictedLabel) }))] }));
201
+ }
@@ -0,0 +1,15 @@
1
+ import type { ActiveContextActions, ActiveContextController, ActiveContextState } from "@mcpview/view/context";
2
+ export type { ActiveContextReconcileResult } from "@mcpview/view/context";
3
+ /** ACK-confirmed basket, provisional row states and actions for the current root. */
4
+ export interface ActiveContextHook extends ActiveContextState, ActiveContextActions {
5
+ retry: ActiveContextController["retry"];
6
+ dismissFailure: ActiveContextController["dismissFailure"];
7
+ dismissEviction: ActiveContextController["dismissEviction"];
8
+ }
9
+ /**
10
+ * Subscribe to a controller owned outside the render tree. Surface remounts only
11
+ * unsubscribe; they never clear, dispose or recreate the App's context queue.
12
+ * Changing scope invalidates old handlers immediately, then queues the root clear.
13
+ */
14
+ export declare function useActiveContext(controller: ActiveContextController, scopeKey: string): ActiveContextHook;
15
+ //# sourceMappingURL=use-active-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-active-context.d.ts","sourceRoot":"","sources":["../../../src/src/preact/use-active-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,qFAAqF;AACrF,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB,EAAE,oBAAoB;IACjF,KAAK,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxC,cAAc,EAAE,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,eAAe,EAAE,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;CAC7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,uBAAuB,EACnC,QAAQ,EAAE,MAAM,GACf,iBAAiB,CAqBnB"}
@@ -0,0 +1,28 @@
1
+ import { useLayoutEffect, useMemo, useState } from "preact/hooks";
2
+ /**
3
+ * Subscribe to a controller owned outside the render tree. Surface remounts only
4
+ * unsubscribe; they never clear, dispose or recreate the App's context queue.
5
+ * Changing scope invalidates old handlers immediately, then queues the root clear.
6
+ */
7
+ export function useActiveContext(controller, scopeKey) {
8
+ const [observed, setObserved] = useState(() => ({ controller, state: controller.getSnapshot() }));
9
+ controller.setScope(scopeKey);
10
+ const actions = useMemo(() => controller.actionsForScope(scopeKey), [controller, scopeKey]);
11
+ useLayoutEffect(() => {
12
+ const update = () => setObserved({ controller, state: controller.getSnapshot() });
13
+ const unsubscribe = controller.subscribe(update);
14
+ update();
15
+ return unsubscribe;
16
+ }, [controller]);
17
+ useLayoutEffect(() => {
18
+ void controller.clearPreviousScope();
19
+ }, [controller, scopeKey]);
20
+ const state = observed.controller === controller ? observed.state : controller.getSnapshot();
21
+ return {
22
+ ...state,
23
+ ...actions,
24
+ retry: controller.retry,
25
+ dismissFailure: controller.dismissFailure,
26
+ dismissEviction: controller.dismissEviction,
27
+ };
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpview/components",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Optional light-first component runtime for small composable MCP App viewers",
5
5
  "keywords": [
6
6
  "mcp",
@@ -27,6 +27,11 @@
27
27
  "import": "./esm/mod.js",
28
28
  "require": "./script/mod.js"
29
29
  },
30
+ "./preact/context": {
31
+ "types": "./esm/preact-context.d.ts",
32
+ "import": "./esm/preact-context.js",
33
+ "require": "./script/preact-context.js"
34
+ },
30
35
  "./preact": {
31
36
  "types": "./esm/preact.d.ts",
32
37
  "import": "./esm/preact.js",
@@ -53,8 +58,11 @@
53
58
  "require": "./script/fonts.js"
54
59
  }
55
60
  },
61
+ "engines": {
62
+ "node": ">=20"
63
+ },
56
64
  "dependencies": {
57
- "@mcpview/view": "^0.10.1",
65
+ "@mcpview/view": "^0.11.0",
58
66
  "@mcpview/contracts": "^0.2.0"
59
67
  },
60
68
  "_generatedBy": "dnt@dev",
@@ -0,0 +1,10 @@
1
+ /** Context controls without the MCP Apps lifecycle or surface runtime. @module */
2
+ import "./_dnt.polyfills.js";
3
+ export { ActiveContextChip } from "./src/preact/context-basket.js";
4
+ export type { ActiveContextChipProps, ContextBasketEntry, ContextBasketGroup, ContextBasketLabels, ContextBasketSelection, ContextBasketSlot, ContextMutation, } from "./src/preact/context-basket.js";
5
+ export { useActiveContext } from "./src/preact/use-active-context.js";
6
+ export type { ActiveContextHook } from "./src/preact/use-active-context.js";
7
+ export { CONTEXT_BASKET_MESSAGES_EN, CONTEXT_BASKET_MESSAGES_FR, contextBasketLabels, contextBasketMessages, } from "./src/context-basket-labels.js";
8
+ export type { ContextBasketMessages } from "./src/context-basket-labels.js";
9
+ export { MCP_VIEW_CONTEXT_BASKET_CSS, MCP_VIEW_CONTEXT_SELECTION_CSS, } from "./src/context-basket-styles.js";
10
+ //# sourceMappingURL=preact-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preact-context.d.ts","sourceRoot":"","sources":["../src/preact-context.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EACV,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,GAChB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EACL,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_VIEW_CONTEXT_SELECTION_CSS = exports.MCP_VIEW_CONTEXT_BASKET_CSS = exports.contextBasketMessages = exports.contextBasketLabels = exports.CONTEXT_BASKET_MESSAGES_FR = exports.CONTEXT_BASKET_MESSAGES_EN = exports.useActiveContext = exports.ActiveContextChip = void 0;
4
+ /** Context controls without the MCP Apps lifecycle or surface runtime. @module */
5
+ require("./_dnt.polyfills.js");
6
+ var context_basket_js_1 = require("./src/preact/context-basket.js");
7
+ Object.defineProperty(exports, "ActiveContextChip", { enumerable: true, get: function () { return context_basket_js_1.ActiveContextChip; } });
8
+ var use_active_context_js_1 = require("./src/preact/use-active-context.js");
9
+ Object.defineProperty(exports, "useActiveContext", { enumerable: true, get: function () { return use_active_context_js_1.useActiveContext; } });
10
+ var context_basket_labels_js_1 = require("./src/context-basket-labels.js");
11
+ Object.defineProperty(exports, "CONTEXT_BASKET_MESSAGES_EN", { enumerable: true, get: function () { return context_basket_labels_js_1.CONTEXT_BASKET_MESSAGES_EN; } });
12
+ Object.defineProperty(exports, "CONTEXT_BASKET_MESSAGES_FR", { enumerable: true, get: function () { return context_basket_labels_js_1.CONTEXT_BASKET_MESSAGES_FR; } });
13
+ Object.defineProperty(exports, "contextBasketLabels", { enumerable: true, get: function () { return context_basket_labels_js_1.contextBasketLabels; } });
14
+ Object.defineProperty(exports, "contextBasketMessages", { enumerable: true, get: function () { return context_basket_labels_js_1.contextBasketMessages; } });
15
+ var context_basket_styles_js_1 = require("./src/context-basket-styles.js");
16
+ Object.defineProperty(exports, "MCP_VIEW_CONTEXT_BASKET_CSS", { enumerable: true, get: function () { return context_basket_styles_js_1.MCP_VIEW_CONTEXT_BASKET_CSS; } });
17
+ Object.defineProperty(exports, "MCP_VIEW_CONTEXT_SELECTION_CSS", { enumerable: true, get: function () { return context_basket_styles_js_1.MCP_VIEW_CONTEXT_SELECTION_CSS; } });
@@ -0,0 +1,21 @@
1
+ import { type TranslatorSelector } from "./i18n.js";
2
+ import type { ContextBasketLabels } from "./preact/context-basket.js";
3
+ /** Interface text only; selection labels and group summaries remain caller data. */
4
+ export declare const CONTEXT_BASKET_MESSAGES_EN: {
5
+ readonly active: "Active context";
6
+ readonly items: "Context items";
7
+ readonly remove: "Remove {label} from context";
8
+ readonly clearAll: "Clear context";
9
+ readonly pending: "Updating context…";
10
+ readonly error: "Context update failed";
11
+ readonly retry: "Retry";
12
+ readonly evicted: "Removed oldest item: {label}";
13
+ };
14
+ export type ContextBasketMessages = {
15
+ readonly [Key in keyof typeof CONTEXT_BASKET_MESSAGES_EN]: string;
16
+ };
17
+ export declare const CONTEXT_BASKET_MESSAGES_FR: ContextBasketMessages;
18
+ export declare const contextBasketMessages: TranslatorSelector<keyof ContextBasketMessages>;
19
+ /** Optional EN/FR kit labels. Pass your own labels to customize any interface text. */
20
+ export declare function contextBasketLabels(locale?: string): ContextBasketLabels;
21
+ //# sourceMappingURL=context-basket-labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-basket-labels.d.ts","sourceRoot":"","sources":["../../src/src/context-basket-labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,oFAAoF;AACpF,eAAO,MAAM,0BAA0B;;;;;;;;;CAS7B,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,GAAG,IAAI,MAAM,OAAO,0BAA0B,GAAG,MAAM;CAClE,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,qBASxC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,kBAAkB,CAAC,MAAM,qBAAqB,CAI9E,CAAC;AAEL,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAYxE"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contextBasketMessages = exports.CONTEXT_BASKET_MESSAGES_FR = exports.CONTEXT_BASKET_MESSAGES_EN = void 0;
4
+ exports.contextBasketLabels = contextBasketLabels;
5
+ const i18n_js_1 = require("./i18n.js");
6
+ /** Interface text only; selection labels and group summaries remain caller data. */
7
+ exports.CONTEXT_BASKET_MESSAGES_EN = {
8
+ active: "Active context",
9
+ items: "Context items",
10
+ remove: "Remove {label} from context",
11
+ clearAll: "Clear context",
12
+ pending: "Updating context…",
13
+ error: "Context update failed",
14
+ retry: "Retry",
15
+ evicted: "Removed oldest item: {label}",
16
+ };
17
+ exports.CONTEXT_BASKET_MESSAGES_FR = {
18
+ active: "Contexte actif",
19
+ items: "Éléments du contexte",
20
+ remove: "Retirer {label} du contexte",
21
+ clearAll: "Vider le contexte",
22
+ pending: "Mise à jour du contexte…",
23
+ error: "Échec de la mise à jour du contexte",
24
+ retry: "Réessayer",
25
+ evicted: "Élément le plus ancien retiré : {label}",
26
+ };
27
+ exports.contextBasketMessages = (0, i18n_js_1.createTranslator)({
28
+ messages: exports.CONTEXT_BASKET_MESSAGES_EN,
29
+ translations: { fr: exports.CONTEXT_BASKET_MESSAGES_FR },
30
+ });
31
+ /** Optional EN/FR kit labels. Pass your own labels to customize any interface text. */
32
+ function contextBasketLabels(locale) {
33
+ const t = (0, exports.contextBasketMessages)(locale);
34
+ return {
35
+ active: t("active"),
36
+ items: t("items"),
37
+ clearAll: t("clearAll"),
38
+ pending: t("pending"),
39
+ error: t("error"),
40
+ retry: t("retry"),
41
+ remove: (label) => t("remove", { label }),
42
+ evicted: (label) => t("evicted", { label }),
43
+ };
44
+ }
@@ -0,0 +1,8 @@
1
+ /** Optional plain CSS for the controlled context basket; uses the shared theme tokens. */
2
+ export declare const MCP_VIEW_CONTEXT_BASKET_CSS: string;
3
+ /**
4
+ * Optional row/card selection treatment. Set data-context-state from
5
+ * useActiveContext().selectionState(item); shared light/dark theme tokens apply.
6
+ */
7
+ export declare const MCP_VIEW_CONTEXT_SELECTION_CSS: string;
8
+ //# sourceMappingURL=context-basket-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-basket-styles.d.ts","sourceRoot":"","sources":["../../src/src/context-basket-styles.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,eAAO,MAAM,2BAA2B,EAAE,MAiFzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAyB5C,CAAC"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_VIEW_CONTEXT_SELECTION_CSS = exports.MCP_VIEW_CONTEXT_BASKET_CSS = void 0;
4
+ /** Optional plain CSS for the controlled context basket; uses the shared theme tokens. */
5
+ exports.MCP_VIEW_CONTEXT_BASKET_CSS = String.raw `
6
+ .mcp-view-context-root {
7
+ position: relative; display: inline-flex; min-width: 0; max-width: 100%;
8
+ align-items: center; gap: .375rem; color: var(--mcp-view-muted);
9
+ font-family: var(--mcp-view-font-body); font-size: var(--mcp-view-size-chip);
10
+ }
11
+ .mcp-view-context-single, .mcp-view-context-trigger {
12
+ display: inline-flex; min-width: 0; align-items: center; gap: .25rem;
13
+ border: 1px solid color-mix(in srgb, var(--mcp-view-accent) 30%, transparent);
14
+ border-radius: var(--mcp-view-radius-control, 5px);
15
+ background: color-mix(in srgb, var(--mcp-view-accent) 8%, transparent);
16
+ }
17
+ .mcp-view-context-single { padding: .125rem .125rem .125rem .5rem; }
18
+ .mcp-view-context-activeLabel, .mcp-view-context-trigger { color: var(--mcp-view-accent-text); }
19
+ .mcp-view-context-activeLabel, .mcp-view-context-chevron { flex-shrink: 0; }
20
+ .mcp-view-context-singleLabel, .mcp-view-context-itemLabel { color: var(--mcp-view-text); }
21
+ .mcp-view-context-singleLabel, .mcp-view-context-itemLabel, .mcp-view-context-itemDetail,
22
+ .mcp-view-context-eviction, .mcp-view-context-pendingLabel {
23
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
24
+ }
25
+ .mcp-view-context-trigger, .mcp-view-context-remove, .mcp-view-context-clearAll,
26
+ .mcp-view-context-retry {
27
+ font: inherit; cursor: pointer;
28
+ }
29
+ .mcp-view-context-trigger { padding: .25rem .5rem; }
30
+ .mcp-view-context-remove {
31
+ display: grid; width: 1.5rem; height: 1.5rem; flex-shrink: 0; place-items: center;
32
+ padding: 0; border: 0; border-radius: var(--mcp-view-radius-sm, 3px);
33
+ background: transparent; color: var(--mcp-view-quiet); font-size: var(--mcp-view-size-body); line-height: 1;
34
+ }
35
+ .mcp-view-context-trigger:hover, .mcp-view-context-remove:hover {
36
+ background: color-mix(in srgb, var(--mcp-view-accent) 12%, transparent);
37
+ }
38
+ .mcp-view-context-remove:hover { color: var(--mcp-view-text); }
39
+ .mcp-view-context-root button:focus-visible {
40
+ outline: 2px solid var(--mcp-view-accent); outline-offset: 1px;
41
+ }
42
+ .mcp-view-context-popover {
43
+ position: absolute; top: 100%; z-index: 30; margin-top: .375rem;
44
+ width: 14rem; max-width: calc(100vw - 24px); padding: .375rem;
45
+ border: 1px solid var(--mcp-view-border); border-radius: var(--mcp-view-radius, 8px);
46
+ background: var(--mcp-view-panel);
47
+ }
48
+ .mcp-view-context-popover[data-align="start"] { left: 0; }
49
+ .mcp-view-context-popover[data-align="end"] { right: 0; }
50
+ .mcp-view-context-list { display: flex; max-height: 16rem; flex-direction: column; overflow-y: auto; }
51
+ .mcp-view-context-item {
52
+ display: flex; min-width: 0; align-items: center; gap: .5rem;
53
+ border-radius: var(--mcp-view-radius-sm, 3px); padding: .25rem .375rem;
54
+ }
55
+ .mcp-view-context-item:hover { background: var(--mcp-view-subtle); }
56
+ .mcp-view-context-itemContent { min-width: 0; flex: 1; }
57
+ .mcp-view-context-itemLabel, .mcp-view-context-itemDetail { display: block; }
58
+ .mcp-view-context-itemDetail, .mcp-view-context-clearAll, .mcp-view-context-eviction {
59
+ font-size: var(--mcp-view-size-micro); color: var(--mcp-view-quiet);
60
+ }
61
+ .mcp-view-context-clearAll {
62
+ width: 100%; margin-top: .25rem; padding: .375rem .375rem 0;
63
+ border: 0; border-top: 1px solid var(--mcp-view-border-soft);
64
+ background: transparent; text-align: left;
65
+ }
66
+ .mcp-view-context-clearAll:hover, .mcp-view-context-error { color: var(--mcp-view-danger); }
67
+ .mcp-view-context-pending, .mcp-view-context-error { display: inline-flex; align-items: center; gap: .25rem; }
68
+ .mcp-view-context-pending { min-width: 0; }
69
+ .mcp-view-context-error { flex-shrink: 0; }
70
+ .mcp-view-context-spinner { flex-shrink: 0; animation: mcp-view-context-spin 1s linear infinite; }
71
+ .mcp-view-context-eviction { max-width: 9rem; }
72
+ .mcp-view-context-root[data-compact] .mcp-view-context-singleLabel,
73
+ .mcp-view-context-root[data-compact] .mcp-view-context-eviction { max-width: 6rem; }
74
+ .mcp-view-context-root[data-compact] .mcp-view-context-activeLabel,
75
+ .mcp-view-context-errorLabel[data-hidden] {
76
+ position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
77
+ overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
78
+ }
79
+ .mcp-view-context-retry {
80
+ border: 1px solid currentColor; border-radius: var(--mcp-view-radius-sm, 3px);
81
+ padding: .125rem .375rem; background: transparent; color: inherit;
82
+ }
83
+ .mcp-view-context-root button:disabled { cursor: default; opacity: .55; }
84
+ @keyframes mcp-view-context-spin { to { transform: rotate(360deg); } }
85
+ @media (prefers-reduced-motion: reduce) { .mcp-view-context-spinner { animation: none; } }
86
+ `;
87
+ /**
88
+ * Optional row/card selection treatment. Set data-context-state from
89
+ * useActiveContext().selectionState(item); shared light/dark theme tokens apply.
90
+ */
91
+ exports.MCP_VIEW_CONTEXT_SELECTION_CSS = String.raw `
92
+ .mcp-view-context-selection {
93
+ border: 1px solid var(--mcp-view-border); border-radius: var(--mcp-view-radius-control, 5px);
94
+ background: var(--mcp-view-panel); color: var(--mcp-view-text);
95
+ }
96
+ .mcp-view-context-selection[data-context-state="selected"] {
97
+ border-color: var(--mcp-view-accent);
98
+ background: color-mix(in srgb, var(--mcp-view-accent) 12%, var(--mcp-view-panel));
99
+ box-shadow: inset 3px 0 var(--mcp-view-accent);
100
+ }
101
+ .mcp-view-context-selection[data-context-state="adding"] {
102
+ border-color: var(--mcp-view-accent); border-style: dashed;
103
+ background: color-mix(in srgb, var(--mcp-view-accent) 12%, var(--mcp-view-panel));
104
+ box-shadow: inset 3px 0 var(--mcp-view-accent);
105
+ }
106
+ .mcp-view-context-selection[data-context-state="removing"] {
107
+ border-color: var(--mcp-view-quiet); border-style: dashed;
108
+ background: var(--mcp-view-subtle); color: var(--mcp-view-muted);
109
+ }
110
+ .mcp-view-context-selection:focus-visible {
111
+ outline: 2px solid var(--mcp-view-accent); outline-offset: 2px;
112
+ }
113
+ .mcp-view-context-selection-status {
114
+ margin-inline-start: .5rem; font-size: var(--mcp-view-size-chip); color: var(--mcp-view-muted);
115
+ }
116
+ `;
@@ -0,0 +1,61 @@
1
+ /** @jsxImportSource preact */
2
+ import type { JSX } from "preact";
3
+ /** Minimum presentation identity; the owning controller retains the full payload. */
4
+ export interface ContextBasketSelection {
5
+ readonly scopeKey: string;
6
+ readonly item: {
7
+ readonly id: string;
8
+ readonly label: string;
9
+ readonly view?: string;
10
+ readonly value?: string;
11
+ };
12
+ }
13
+ /** A caller-projected group: identities, membership and summaries remain caller-owned. */
14
+ export interface ContextBasketGroup {
15
+ readonly scopeKey: string;
16
+ readonly id: string;
17
+ readonly label: string;
18
+ readonly summary?: string;
19
+ readonly view?: string;
20
+ readonly value?: string;
21
+ }
22
+ export type ContextBasketEntry<T extends ContextBasketSelection = ContextBasketSelection> = {
23
+ readonly kind: "single";
24
+ readonly selection: T;
25
+ } | {
26
+ readonly kind: "group";
27
+ readonly group: ContextBasketGroup;
28
+ };
29
+ /** Every visible message and accessible name follows the caller's locale. */
30
+ export interface ContextBasketLabels {
31
+ readonly active: string;
32
+ readonly items: string;
33
+ readonly remove: (label: string) => string;
34
+ readonly clearAll: string;
35
+ readonly pending: string;
36
+ readonly error: string;
37
+ readonly retry: string;
38
+ readonly evicted: (label: string) => string;
39
+ }
40
+ export type ContextBasketSlot = "root" | "single" | "activeLabel" | "singleLabel" | "remove" | "trigger" | "chevron" | "popover" | "list" | "item" | "itemContent" | "itemLabel" | "itemDetail" | "clearAll" | "pending" | "spinner" | "error" | "errorLabel" | "eviction" | "pendingLabel" | "retry";
41
+ export type ContextMutation = () => unknown | Promise<unknown>;
42
+ export interface ActiveContextChipProps<T extends ContextBasketSelection = ContextBasketSelection> {
43
+ readonly selections: readonly T[];
44
+ /** Overrides the visible list, e.g. one entry per group instead of its projected members. */
45
+ readonly entries?: readonly ContextBasketEntry<T>[];
46
+ readonly labels: ContextBasketLabels;
47
+ readonly failed?: boolean;
48
+ readonly pending?: boolean;
49
+ readonly evictedLabel?: string | null;
50
+ readonly onRemove?: (selection: T) => unknown | Promise<unknown>;
51
+ readonly onRemoveGroup?: (group: ContextBasketGroup) => unknown | Promise<unknown>;
52
+ readonly onClear: ContextMutation;
53
+ readonly onRetry?: ContextMutation;
54
+ readonly compact?: boolean;
55
+ readonly popoverAlign?: "start" | "end";
56
+ readonly className?: string;
57
+ readonly classes?: Partial<Record<ContextBasketSlot, string>>;
58
+ }
59
+ /** Controlled basket. Acknowledged selections and mutation results remain caller-owned. */
60
+ export declare function ActiveContextChip<T extends ContextBasketSelection>({ selections, entries, labels, failed, pending, evictedLabel, onRemove, onRemoveGroup, onClear, onRetry, compact, popoverAlign, className, classes, }: ActiveContextChipProps<T>): JSX.Element | null;
61
+ //# sourceMappingURL=context-basket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-basket.d.ts","sourceRoot":"","sources":["../../../src/src/preact/context-basket.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAGlC,qFAAqF;AACrF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ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AAC;CAC/D;AAsCD,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,sBAAsB,EAChE,EACE,UAAU,EACV,OAAO,EACP,MAAM,EACN,MAAc,EACd,OAAe,EACf,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,OAAO,EACP,OAAO,EACP,OAAe,EACf,YAAoB,EACpB,SAAS,EACT,OAAO,GACR,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAC3B,GAAG,CAAC,OAAO,GAAG,IAAI,CA0QpB"}
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActiveContextChip = ActiveContextChip;
4
+ const jsx_runtime_1 = require("preact/jsx-runtime");
5
+ const hooks_1 = require("preact/hooks");
6
+ const FOCUSABLE_SELECTOR = [
7
+ "a[href]",
8
+ "button:not([disabled])",
9
+ "input:not([disabled])",
10
+ "select:not([disabled])",
11
+ "textarea:not([disabled])",
12
+ '[tabindex]:not([tabindex="-1"])',
13
+ ].join(",");
14
+ function accepted(result) {
15
+ return result === "shared" || result === "cleared";
16
+ }
17
+ function outsideFocusable(wrapper) {
18
+ if (!wrapper)
19
+ return null;
20
+ const elements = Array.from(wrapper.ownerDocument.querySelectorAll(FOCUSABLE_SELECTOR));
21
+ const current = elements.indexOf(wrapper.ownerDocument.activeElement);
22
+ return elements.slice(current + 1).find((element) => !wrapper.contains(element)) ??
23
+ elements.slice(0, Math.max(0, current)).reverse().find((element) => !wrapper.contains(element)) ??
24
+ null;
25
+ }
26
+ function entryKey(entry) {
27
+ return entry.kind === "group"
28
+ ? JSON.stringify(["group", entry.group.scopeKey, entry.group.id])
29
+ : JSON.stringify(["single", entry.selection.scopeKey, entry.selection.item.id]);
30
+ }
31
+ function display(entry) {
32
+ return entry.kind === "group" ? entry.group : entry.selection.item;
33
+ }
34
+ /** Controlled basket. Acknowledged selections and mutation results remain caller-owned. */
35
+ function ActiveContextChip({ selections, entries, labels, failed = false, pending = false, evictedLabel, onRemove, onRemoveGroup, onClear, onRetry, compact = false, popoverAlign = "end", className, classes, }) {
36
+ const slot = (name) => [`mcp-view-context-${name}`, classes?.[name]].filter(Boolean).join(" ");
37
+ const [open, setOpen] = (0, hooks_1.useState)(false);
38
+ const wrapperRef = (0, hooks_1.useRef)(null);
39
+ const triggerRef = (0, hooks_1.useRef)(null);
40
+ const singleRemoveRef = (0, hooks_1.useRef)(null);
41
+ const removeRefs = (0, hooks_1.useRef)(new Map());
42
+ const mountedRef = (0, hooks_1.useRef)(true);
43
+ const operationRef = (0, hooks_1.useRef)(0);
44
+ const popoverId = (0, hooks_1.useId)();
45
+ const visible = entries ??
46
+ selections.map((selection) => ({ kind: "single", selection }));
47
+ const visibleRef = (0, hooks_1.useRef)(visible);
48
+ visibleRef.current = visible;
49
+ const count = visible.length;
50
+ (0, hooks_1.useLayoutEffect)(() => {
51
+ mountedRef.current = true;
52
+ return () => {
53
+ mountedRef.current = false;
54
+ operationRef.current++;
55
+ };
56
+ }, []);
57
+ (0, hooks_1.useEffect)(() => {
58
+ if (count <= 1)
59
+ setOpen(false);
60
+ }, [count]);
61
+ (0, hooks_1.useEffect)(() => {
62
+ if (!open)
63
+ return;
64
+ const doc = wrapperRef.current.ownerDocument;
65
+ function pointer(event) {
66
+ if (!wrapperRef.current?.contains(event.target)) {
67
+ operationRef.current++;
68
+ setOpen(false);
69
+ }
70
+ }
71
+ function key(event) {
72
+ if (event.key !== "Escape")
73
+ return;
74
+ event.preventDefault();
75
+ operationRef.current++;
76
+ setOpen(false);
77
+ triggerRef.current?.focus();
78
+ }
79
+ doc.addEventListener("pointerdown", pointer);
80
+ doc.addEventListener("keydown", key);
81
+ return () => {
82
+ doc.removeEventListener("pointerdown", pointer);
83
+ doc.removeEventListener("keydown", key);
84
+ };
85
+ }, [open]);
86
+ // Run after the controlled render, and never steal focus back from a user who moved away.
87
+ function afterAccepted(operation, origin, callback) {
88
+ queueMicrotask(() => {
89
+ if (!mountedRef.current || operation !== operationRef.current)
90
+ return;
91
+ const current = origin?.ownerDocument.activeElement;
92
+ // A removed button naturally loses browser focus; a deliberate focus change wins.
93
+ if (origin && current !== origin && current !== origin.ownerDocument.body)
94
+ return;
95
+ callback();
96
+ });
97
+ }
98
+ async function remove(entry, index) {
99
+ const operation = ++operationRef.current;
100
+ const origin = wrapperRef.current?.ownerDocument.activeElement ?? null;
101
+ const external = outsideFocusable(wrapperRef.current);
102
+ let result;
103
+ try {
104
+ result = await (entry.kind === "group"
105
+ ? onRemoveGroup?.(entry.group)
106
+ : onRemove
107
+ ? onRemove(entry.selection)
108
+ : count === 1
109
+ ? onClear()
110
+ : undefined);
111
+ }
112
+ catch {
113
+ return;
114
+ }
115
+ if (!accepted(result))
116
+ return;
117
+ afterAccepted(operation, origin, () => {
118
+ const remaining = visibleRef.current;
119
+ if (!remaining.length) {
120
+ if (external?.isConnected)
121
+ external.focus({ preventScroll: true });
122
+ }
123
+ else if (remaining.length === 1) {
124
+ singleRemoveRef.current?.focus({ preventScroll: true });
125
+ }
126
+ else {
127
+ const neighbour = remaining[Math.min(index, remaining.length - 1)];
128
+ (removeRefs.current.get(entryKey(neighbour)) ?? triggerRef.current)?.focus({
129
+ preventScroll: true,
130
+ });
131
+ }
132
+ });
133
+ }
134
+ async function clear() {
135
+ const operation = ++operationRef.current;
136
+ const origin = wrapperRef.current?.ownerDocument.activeElement ?? null;
137
+ const external = outsideFocusable(wrapperRef.current);
138
+ let result;
139
+ try {
140
+ result = await onClear();
141
+ }
142
+ catch {
143
+ return;
144
+ }
145
+ if (!accepted(result))
146
+ return;
147
+ afterAccepted(operation, origin, () => {
148
+ setOpen(false);
149
+ if (external?.isConnected)
150
+ external.focus({ preventScroll: true });
151
+ });
152
+ }
153
+ async function retry() {
154
+ const operation = ++operationRef.current;
155
+ const origin = wrapperRef.current?.ownerDocument.activeElement ?? null;
156
+ const external = outsideFocusable(wrapperRef.current);
157
+ let result;
158
+ try {
159
+ result = await onRetry?.();
160
+ }
161
+ catch {
162
+ return;
163
+ }
164
+ if (!accepted(result))
165
+ return;
166
+ afterAccepted(operation, origin, () => {
167
+ // Retry may clear the basket, remove one item, or retain its confirmed list.
168
+ // Choose from the controlled render after ACK rather than the failed intent.
169
+ const retained = visibleRef.current.length === 1
170
+ ? singleRemoveRef.current
171
+ : triggerRef.current;
172
+ if (retained?.isConnected && !retained.disabled) {
173
+ retained.focus({ preventScroll: true });
174
+ }
175
+ else if (origin?.isConnected) {
176
+ origin.focus({ preventScroll: true });
177
+ }
178
+ else if (external?.isConnected) {
179
+ external.focus({ preventScroll: true });
180
+ }
181
+ });
182
+ }
183
+ function removeButton(entry, index, single = false) {
184
+ const item = display(entry);
185
+ return ((0, jsx_runtime_1.jsx)("button", { type: "button", class: slot("remove"), ref: (element) => {
186
+ if (single)
187
+ singleRemoveRef.current = element;
188
+ if (element)
189
+ removeRefs.current.set(entryKey(entry), element);
190
+ else
191
+ removeRefs.current.delete(entryKey(entry));
192
+ }, disabled: pending || (entry.kind === "group" ? !onRemoveGroup : !onRemove && count > 1), "aria-label": labels.remove(item.label), title: labels.remove(item.label), onClick: () => void remove(entry, index), children: (0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", children: "\u00D7" }) }));
193
+ }
194
+ if (count === 0 && !failed && !pending && !evictedLabel)
195
+ return null;
196
+ return ((0, jsx_runtime_1.jsxs)("span", { ref: wrapperRef, "aria-busy": pending || undefined, class: [slot("root"), className].filter(Boolean).join(" "), "data-compact": compact || undefined, children: [count === 1 && ((0, jsx_runtime_1.jsxs)("span", { class: slot("single"), "aria-live": "polite", "aria-atomic": "true", children: [(0, jsx_runtime_1.jsx)("span", { class: slot("activeLabel"), children: labels.active }), (0, jsx_runtime_1.jsx)("span", { class: slot("singleLabel"), title: display(visible[0]).label, children: display(visible[0]).label }), removeButton(visible[0], 0, true)] })), count > 1 && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("button", { ref: triggerRef, type: "button", class: slot("trigger"), "aria-expanded": open, "aria-controls": open ? popoverId : undefined, "aria-haspopup": "dialog", onClick: () => {
197
+ operationRef.current++;
198
+ setOpen((value) => !value);
199
+ }, children: [(0, jsx_runtime_1.jsxs)("span", { "aria-live": "polite", "aria-atomic": "true", children: [labels.active, " \u00B7 ", count] }), (0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", class: slot("chevron"), children: open ? "▴" : "▾" })] }), open && ((0, jsx_runtime_1.jsxs)("span", { id: popoverId, role: "dialog", "aria-label": labels.items, class: slot("popover"), "data-align": popoverAlign, children: [(0, jsx_runtime_1.jsx)("span", { role: "list", class: slot("list"), children: visible.map((entry, index) => {
200
+ const item = display(entry);
201
+ const summary = entry.kind === "group" ? entry.group.summary : undefined;
202
+ return ((0, jsx_runtime_1.jsxs)("span", { role: "listitem", class: slot("item"), children: [(0, jsx_runtime_1.jsxs)("span", { class: slot("itemContent"), children: [(0, jsx_runtime_1.jsx)("span", { class: slot("itemLabel"), children: item.label }), (0, jsx_runtime_1.jsx)("span", { class: slot("itemDetail"), children: summary ?? [item.view, item.value].filter(Boolean).join(" · ") })] }), removeButton(entry, index)] }, entryKey(entry)));
203
+ }) }), (0, jsx_runtime_1.jsx)("button", { type: "button", class: slot("clearAll"), disabled: pending, onClick: () => void clear(), children: labels.clearAll })] }))] })), pending && ((0, jsx_runtime_1.jsxs)("span", { role: "status", "aria-live": "polite", class: slot("pending"), title: labels.pending, children: [(0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", class: slot("spinner"), children: "\u25CC" }), (0, jsx_runtime_1.jsx)("span", { class: slot("pendingLabel"), children: labels.pending })] })), failed && ((0, jsx_runtime_1.jsxs)("span", { role: "status", class: slot("error"), title: labels.error, children: [(0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", children: "!" }), (0, jsx_runtime_1.jsx)("span", { class: slot("errorLabel"), "data-hidden": compact && count > 0 || undefined, children: labels.error }), onRetry && ((0, jsx_runtime_1.jsx)("button", { type: "button", class: slot("retry"), disabled: pending, onClick: () => void retry(), children: labels.retry }))] })), evictedLabel && ((0, jsx_runtime_1.jsx)("span", { role: "status", "aria-live": "polite", class: slot("eviction"), title: labels.evicted(evictedLabel), children: labels.evicted(evictedLabel) }))] }));
204
+ }
@@ -0,0 +1,15 @@
1
+ import type { ActiveContextActions, ActiveContextController, ActiveContextState } from "@mcpview/view/context";
2
+ export type { ActiveContextReconcileResult } from "@mcpview/view/context";
3
+ /** ACK-confirmed basket, provisional row states and actions for the current root. */
4
+ export interface ActiveContextHook extends ActiveContextState, ActiveContextActions {
5
+ retry: ActiveContextController["retry"];
6
+ dismissFailure: ActiveContextController["dismissFailure"];
7
+ dismissEviction: ActiveContextController["dismissEviction"];
8
+ }
9
+ /**
10
+ * Subscribe to a controller owned outside the render tree. Surface remounts only
11
+ * unsubscribe; they never clear, dispose or recreate the App's context queue.
12
+ * Changing scope invalidates old handlers immediately, then queues the root clear.
13
+ */
14
+ export declare function useActiveContext(controller: ActiveContextController, scopeKey: string): ActiveContextHook;
15
+ //# sourceMappingURL=use-active-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-active-context.d.ts","sourceRoot":"","sources":["../../../src/src/preact/use-active-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,qFAAqF;AACrF,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB,EAAE,oBAAoB;IACjF,KAAK,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxC,cAAc,EAAE,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,eAAe,EAAE,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;CAC7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,uBAAuB,EACnC,QAAQ,EAAE,MAAM,GACf,iBAAiB,CAqBnB"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useActiveContext = useActiveContext;
4
+ const hooks_1 = require("preact/hooks");
5
+ /**
6
+ * Subscribe to a controller owned outside the render tree. Surface remounts only
7
+ * unsubscribe; they never clear, dispose or recreate the App's context queue.
8
+ * Changing scope invalidates old handlers immediately, then queues the root clear.
9
+ */
10
+ function useActiveContext(controller, scopeKey) {
11
+ const [observed, setObserved] = (0, hooks_1.useState)(() => ({ controller, state: controller.getSnapshot() }));
12
+ controller.setScope(scopeKey);
13
+ const actions = (0, hooks_1.useMemo)(() => controller.actionsForScope(scopeKey), [controller, scopeKey]);
14
+ (0, hooks_1.useLayoutEffect)(() => {
15
+ const update = () => setObserved({ controller, state: controller.getSnapshot() });
16
+ const unsubscribe = controller.subscribe(update);
17
+ update();
18
+ return unsubscribe;
19
+ }, [controller]);
20
+ (0, hooks_1.useLayoutEffect)(() => {
21
+ void controller.clearPreviousScope();
22
+ }, [controller, scopeKey]);
23
+ const state = observed.controller === controller ? observed.state : controller.getSnapshot();
24
+ return {
25
+ ...state,
26
+ ...actions,
27
+ retry: controller.retry,
28
+ dismissFailure: controller.dismissFailure,
29
+ dismissEviction: controller.dismissEviction,
30
+ };
31
+ }