@tangle-network/ui 11.51.6 → 11.51.8

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 (41) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -0
  3. package/dist/chat/agent-timeline.d.ts +1 -1
  4. package/dist/chat/speaker.d.ts +2 -2
  5. package/dist/chat.d.ts +2 -2
  6. package/dist/index.d.ts +4 -4
  7. package/package.json +31 -1
  8. package/src/editor/source-markdown-editor.test.tsx +7 -7
  9. package/src/editor/document-editor-pane.test.tsx +0 -60
  10. package/src/editor/editor-lazy.test.tsx +0 -102
  11. package/src/editor/editor-peers.test.ts +0 -250
  12. package/src/editor/editor-provider.test.tsx +0 -226
  13. package/src/editor/markdown-document-editor.test.tsx +0 -126
  14. package/src/editor/tiptap-editor.test.tsx +0 -228
  15. package/src/files/file-artifact-pane.test.tsx +0 -301
  16. package/src/files/file-card.test.tsx +0 -62
  17. package/src/files/file-list.test.tsx +0 -81
  18. package/src/files/pdf-loader.test.ts +0 -130
  19. package/src/files/pdf-viewer.test.tsx +0 -245
  20. package/src/files/rich-file-tree.test.tsx +0 -90
  21. package/src/markdown/api-presentation.test.tsx +0 -63
  22. package/src/markdown/code-block.test.tsx +0 -201
  23. package/src/markdown/markdown-table.test.tsx +0 -76
  24. package/src/markdown/markdown.test.tsx +0 -166
  25. package/src/openui/schema.test.tsx +0 -158
  26. package/src/primitives/button.test.tsx +0 -230
  27. package/src/primitives/card.test.tsx +0 -71
  28. package/src/primitives/chip.test.tsx +0 -200
  29. package/src/primitives/date-picker.test.tsx +0 -146
  30. package/src/primitives/dialog.test.tsx +0 -75
  31. package/src/primitives/input.test.tsx +0 -161
  32. package/src/primitives/interaction-states.test.tsx +0 -287
  33. package/src/primitives/pagination-alert.test.tsx +0 -180
  34. package/src/primitives/popover-collapsible-alert-dialog-context-menu-slider.test.tsx +0 -165
  35. package/src/primitives/radio-group.test.tsx +0 -26
  36. package/src/primitives/segmented-control.test.tsx +0 -451
  37. package/src/primitives/table.test.tsx +0 -72
  38. package/src/primitives/theme-toggle.test.tsx +0 -168
  39. package/src/primitives/toast.test.tsx +0 -130
  40. package/src/primitives/wizard.test.tsx +0 -106
  41. package/src/run/expandable-content.test.tsx +0 -52
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @tangle-network/ui
2
2
 
3
+ ## 11.51.8
4
+
5
+ - Retire mock-dependent component tests while preserving the real editor source-saving integration without callback spies. Component implementations and built exports are unchanged; packed-consumer and browser checks remain.
6
+
7
+ ## 11.51.7
8
+
9
+ - Expose the existing retained report component and follow-tail modules without optional chat stores. Derive all build entries from the package export map.
10
+
3
11
  ## 11.51.6
4
12
 
5
13
  - Expose the existing run-clock and status modules directly so minimal graph/server consumers do not load unrelated optional session stores.
package/README.md CHANGED
@@ -163,3 +163,5 @@ An http(s) `src` on another origin needs CORS, as any `fetch` does. When it fail
163
163
  Those entries create values at module scope, so consumers must install their peers before importing them.
164
164
  The package root also re-exports `./stores`, so a root import requires both nanostores peers.
165
165
  Consumers that use only other subpath entries do not need these three peers.
166
+
167
+ Retained report readers can import existing `chat/agent-timeline`, `chat/speaker`, `run/expanded-tool-detail`, `run/inline-thinking-item`, `run/run-row-shell` and `hooks/use-follow-tail` modules directly. These entries preserve their broad-entry bindings without importing chat session stores.
@@ -1,6 +1,6 @@
1
1
  import { ChatAuthor } from "../types/message.js";
2
- import { ToolPart } from "../types/parts.js";
3
2
  import { MessageRole } from "./chat-message.js";
3
+ import { ToolPart } from "../types/parts.js";
4
4
  import { ToolCallData } from "../run/tool-call-feed.js";
5
5
  import { ReactNode } from "react";
6
6
  export type AgentTimelineTone = "default" | "info" | "success" | "warning" | "error";
@@ -1,7 +1,7 @@
1
1
  import { HTMLAttributes } from "react";
2
2
  import { Speaker, Speaker as Speaker$1, SpeakerPart, SpeakerSection, SpeakerState, partitionBySpeaker } from "@tangle-network/agent-interface/speaker";
3
3
  export interface SpeakerHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
4
- speaker: Speaker;
4
+ speaker: Speaker$1;
5
5
  /** The turn is still running, so a responder that has not reported an end is answering. */
6
6
  live?: boolean;
7
7
  }
@@ -15,4 +15,4 @@ export interface SpeakerHeaderProps extends Omit<HTMLAttributes<HTMLDivElement>,
15
15
  * nothing, as a settled run row does. `data-speaker-state` carries all three.
16
16
  */
17
17
  export declare function SpeakerHeader({ speaker, live, ...props }: SpeakerHeaderProps): import("react").JSX.Element;
18
- export { type Speaker$1 as Speaker, type SpeakerPart, type SpeakerSection, type SpeakerState, partitionBySpeaker };
18
+ export { type Speaker, type SpeakerPart, type SpeakerSection, type SpeakerState, partitionBySpeaker };
package/dist/chat.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ChatAuthor } from "./types/message.js";
2
+ import { ChatMessage, ChatMessageProps, MessageRole } from "./chat/chat-message.js";
3
+ import { AgentTimeline, AgentTimelineArtifactItem, AgentTimelineColumn, AgentTimelineCustomItem, AgentTimelineFoldItem, AgentTimelineItem, AgentTimelineMessageItem, AgentTimelineProps, AgentTimelineStatusItem, AgentTimelineStep, AgentTimelineStepKind, AgentTimelineStepProps, AgentTimelineTone, AgentTimelineToolGroupItem, AgentTimelineToolItem, agentTimelineStepKind, foldSummary } from "./chat/agent-timeline.js";
2
4
  import { ChatContainer, ChatContainerProps } from "./chat/chat-container.js";
3
5
  import { MessageList, MessageListProps } from "./chat/message-list.js";
4
6
  import { UserMessage, UserMessageProps } from "./chat/user-message.js";
5
- import { ChatMessage, ChatMessageProps, MessageRole } from "./chat/chat-message.js";
6
7
  import { MessageAuthor, MessageAuthorProps, isViewerMessage } from "./chat/message-author.js";
7
8
  import { Speaker, SpeakerHeader, SpeakerHeaderProps, SpeakerPart, SpeakerSection, SpeakerState, partitionBySpeaker } from "./chat/speaker.js";
8
9
  import { ThinkingIndicator, ThinkingIndicatorProps } from "./chat/thinking-indicator.js";
9
- import { AgentTimeline, AgentTimelineArtifactItem, AgentTimelineColumn, AgentTimelineCustomItem, AgentTimelineFoldItem, AgentTimelineItem, AgentTimelineMessageItem, AgentTimelineProps, AgentTimelineStatusItem, AgentTimelineStep, AgentTimelineStepKind, AgentTimelineStepProps, AgentTimelineTone, AgentTimelineToolGroupItem, AgentTimelineToolItem, agentTimelineStepKind, foldSummary } from "./chat/agent-timeline.js";
10
10
  import { TRANSCRIPT_TEXT } from "./chat/transcript-text.js";
11
11
  export { AgentTimeline, type AgentTimelineArtifactItem, AgentTimelineColumn, type AgentTimelineCustomItem, type AgentTimelineFoldItem, type AgentTimelineItem, type AgentTimelineMessageItem, type AgentTimelineProps, type AgentTimelineStatusItem, AgentTimelineStep, type AgentTimelineStepKind, type AgentTimelineStepProps, type AgentTimelineTone, type AgentTimelineToolGroupItem, type AgentTimelineToolItem, type ChatAuthor, ChatContainer, type ChatContainerProps, ChatMessage, type ChatMessageProps, MessageAuthor, type MessageAuthorProps, MessageList, type MessageListProps, type MessageRole, type Speaker, SpeakerHeader, type SpeakerHeaderProps, type SpeakerPart, type SpeakerSection, type SpeakerState, TRANSCRIPT_TEXT, ThinkingIndicator, type ThinkingIndicatorProps, UserMessage, type UserMessageProps, agentTimelineStepKind, foldSummary, isViewerMessage, partitionBySpeaker };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,11 @@ import { AuthHeader, AuthHeaderProps, GitHubLoginButton, GitHubLoginButtonProps,
5
5
  import { LoginLayout, LoginLayoutProps } from "./auth/login-layout.js";
6
6
  import "./auth.js";
7
7
  import { ChatAuthor, SessionMessage } from "./types/message.js";
8
+ import { ChatMessage, ChatMessageProps, MessageRole } from "./chat/chat-message.js";
8
9
  import { ReasoningPart, SessionPart, TextPart, ToolPart, ToolState, ToolStatus, ToolTime } from "./types/parts.js";
10
+ import { ToolCallStatus, ToolCallType } from "./run/tool-call-step.js";
11
+ import { FeedSegment, ToolCallData, ToolCallFeed, ToolCallFeedProps, parseToolEvent } from "./run/tool-call-feed.js";
12
+ import { AgentTimeline, AgentTimelineArtifactItem, AgentTimelineColumn, AgentTimelineCustomItem, AgentTimelineFoldItem, AgentTimelineItem, AgentTimelineMessageItem, AgentTimelineProps, AgentTimelineStatusItem, AgentTimelineStep, AgentTimelineStepKind, AgentTimelineStepProps, AgentTimelineTone, AgentTimelineToolGroupItem, AgentTimelineToolItem, agentTimelineStepKind, foldSummary } from "./chat/agent-timeline.js";
9
13
  import { AgentBranding } from "./types/branding.js";
10
14
  import { CustomToolRenderer, DisplayVariant, ToolDisplayMetadata } from "./types/tool-display.js";
11
15
  import { FinalTextPart, GroupedMessage, MessageRun, MessageUser, Run, RunStats, ToolCategory } from "./types/run.js";
@@ -14,13 +18,9 @@ import { OpenUIAction, OpenUIActionsNode, OpenUIArtifactRenderer, OpenUIArtifact
14
18
  import { ChatContainer, ChatContainerProps } from "./chat/chat-container.js";
15
19
  import { MessageList, MessageListProps } from "./chat/message-list.js";
16
20
  import { UserMessage, UserMessageProps } from "./chat/user-message.js";
17
- import { ChatMessage, ChatMessageProps, MessageRole } from "./chat/chat-message.js";
18
21
  import { MessageAuthor, MessageAuthorProps, isViewerMessage } from "./chat/message-author.js";
19
22
  import { Speaker, SpeakerHeader, SpeakerHeaderProps, SpeakerPart, SpeakerSection, SpeakerState, partitionBySpeaker } from "./chat/speaker.js";
20
23
  import { ThinkingIndicator, ThinkingIndicatorProps } from "./chat/thinking-indicator.js";
21
- import { ToolCallStatus, ToolCallType } from "./run/tool-call-step.js";
22
- import { FeedSegment, ToolCallData, ToolCallFeed, ToolCallFeedProps, parseToolEvent } from "./run/tool-call-feed.js";
23
- import { AgentTimeline, AgentTimelineArtifactItem, AgentTimelineColumn, AgentTimelineCustomItem, AgentTimelineFoldItem, AgentTimelineItem, AgentTimelineMessageItem, AgentTimelineProps, AgentTimelineStatusItem, AgentTimelineStep, AgentTimelineStepKind, AgentTimelineStepProps, AgentTimelineTone, AgentTimelineToolGroupItem, AgentTimelineToolItem, agentTimelineStepKind, foldSummary } from "./chat/agent-timeline.js";
24
24
  import { TRANSCRIPT_TEXT } from "./chat/transcript-text.js";
25
25
  import "./chat.js";
26
26
  import { codeBlockGrammar } from "./lib/code-presentation.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/ui",
3
- "version": "11.51.6",
3
+ "version": "11.51.8",
4
4
  "description": "Generic React UI components for Tangle products — primitives, chat, run, files, editor, markdown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -135,6 +135,36 @@
135
135
  "types": "./dist/run/status-meta.d.ts",
136
136
  "import": "./dist/run/status-meta.js",
137
137
  "default": "./dist/run/status-meta.js"
138
+ },
139
+ "./chat/agent-timeline": {
140
+ "types": "./dist/chat/agent-timeline.d.ts",
141
+ "import": "./dist/chat/agent-timeline.js",
142
+ "default": "./dist/chat/agent-timeline.js"
143
+ },
144
+ "./chat/speaker": {
145
+ "types": "./dist/chat/speaker.d.ts",
146
+ "import": "./dist/chat/speaker.js",
147
+ "default": "./dist/chat/speaker.js"
148
+ },
149
+ "./run/expanded-tool-detail": {
150
+ "types": "./dist/run/expanded-tool-detail.d.ts",
151
+ "import": "./dist/run/expanded-tool-detail.js",
152
+ "default": "./dist/run/expanded-tool-detail.js"
153
+ },
154
+ "./run/inline-thinking-item": {
155
+ "types": "./dist/run/inline-thinking-item.d.ts",
156
+ "import": "./dist/run/inline-thinking-item.js",
157
+ "default": "./dist/run/inline-thinking-item.js"
158
+ },
159
+ "./run/run-row-shell": {
160
+ "types": "./dist/run/run-row-shell.d.ts",
161
+ "import": "./dist/run/run-row-shell.js",
162
+ "default": "./dist/run/run-row-shell.js"
163
+ },
164
+ "./hooks/use-follow-tail": {
165
+ "types": "./dist/hooks/use-follow-tail.d.ts",
166
+ "import": "./dist/hooks/use-follow-tail.js",
167
+ "default": "./dist/hooks/use-follow-tail.js"
138
168
  }
139
169
  },
140
170
  "dependencies": {
@@ -1,6 +1,6 @@
1
1
  import { act, render, waitFor } from "@testing-library/react";
2
2
  import type { Editor } from "@tiptap/react";
3
- import { describe, expect, it, vi } from "vitest";
3
+ import { describe, expect, it } from "vitest";
4
4
  import { MarkdownDocumentEditor } from "./markdown-document-editor";
5
5
  import { CALL_SHEET, KITCHEN_SINK } from "./source-markdown.fixtures";
6
6
 
@@ -10,12 +10,12 @@ const PEERS_LOADED = { timeout: 15_000 };
10
10
  const LOADS_PEERS = 30_000;
11
11
 
12
12
  async function openEditor(value: string) {
13
- const onChange = vi.fn<(markdown: string) => void>();
13
+ const changes: string[] = [];
14
14
  let editor: Editor | null = null;
15
15
  const view = render(
16
16
  <MarkdownDocumentEditor
17
17
  value={value}
18
- onChange={(markdown) => onChange(markdown)}
18
+ onChange={(markdown) => changes.push(markdown)}
19
19
  onReady={(ready) => {
20
20
  editor = ready;
21
21
  }}
@@ -32,9 +32,9 @@ async function openEditor(value: string) {
32
32
  get editor() {
33
33
  return editor! as Editor;
34
34
  },
35
- onChange,
35
+ changes,
36
36
  /** The Markdown the editor last reported, or the value it opened. */
37
- saved: () => onChange.mock.calls.at(-1)?.[0] ?? value,
37
+ saved: () => changes.at(-1) ?? value,
38
38
  };
39
39
  }
40
40
 
@@ -63,13 +63,13 @@ function tableRows(markdown: string) {
63
63
 
64
64
  describe("MarkdownDocumentEditor source preservation", () => {
65
65
  it("opens every Markdown construct without reporting a change", async () => {
66
- const { editor, onChange, view } = await openEditor(KITCHEN_SINK);
66
+ const { editor, changes, view } = await openEditor(KITCHEN_SINK);
67
67
  act(() => {
68
68
  editor.commands.setTextSelection(1);
69
69
  editor.setEditable(false);
70
70
  editor.setEditable(true);
71
71
  });
72
- expect(onChange).not.toHaveBeenCalled();
72
+ expect(changes).toHaveLength(0);
73
73
  // The table is shown as a table, read-only, instead of a run-on paragraph.
74
74
  const table = view.container.querySelector('[data-md-kind="table"] table');
75
75
  expect(table?.querySelectorAll("tbody tr")).toHaveLength(1);
@@ -1,60 +0,0 @@
1
- import { render, screen, waitFor } from "@testing-library/react";
2
- import { afterEach, describe, expect, it, vi } from "vitest";
3
- import type * as EditorPeers from "./editor-peers";
4
-
5
- const markdown = "# Release notes\n\nThe editor loads on demand.";
6
-
7
- afterEach(() => {
8
- vi.resetModules();
9
- });
10
-
11
- /** Loads the pane with every peer loader rejecting, as for a consumer that
12
- * installed neither tiptap nor the collaboration stack. The spies report
13
- * whether a render reached a loader at all. */
14
- async function paneWithoutPeers(message: string) {
15
- const loaders = {
16
- loadDocumentEditorPeers: vi.fn(async () => {
17
- throw new Error(message);
18
- }),
19
- loadCollaborationPeers: vi.fn(async () => {
20
- throw new Error(message);
21
- }),
22
- loadEditorProviderPeers: vi.fn(async () => {
23
- throw new Error(message);
24
- }),
25
- };
26
- vi.resetModules();
27
- vi.doMock("./editor-peers", async () => ({
28
- ...(await vi.importActual<typeof EditorPeers>("./editor-peers")),
29
- ...loaders,
30
- }));
31
- const { DocumentEditorPane } = await import("./document-editor-pane");
32
- return { DocumentEditorPane, loaders };
33
- }
34
-
35
- // The pane is imported on a fresh module graph, which re-transforms its whole
36
- // dependency tree: seconds on a busy runner, past the 5s default.
37
- describe("DocumentEditorPane without the editor peers", () => {
38
- it("renders the preview, because only the edit tab needs the peers", async () => {
39
- const { DocumentEditorPane, loaders } = await paneWithoutPeers(
40
- "peers are not installed",
41
- );
42
-
43
- render(<DocumentEditorPane title="Notes" markdown={markdown} />);
44
-
45
- // The promise this pane's editors carry is exactly this: a consumer that
46
- // never opens the edit tab pays nothing for tiptap.
47
- expect(screen.getByText("Release notes")).toBeInTheDocument();
48
- expect(screen.getByText("The editor loads on demand.")).toBeInTheDocument();
49
- expect(screen.getByRole("tab", { name: "Edit" })).toBeInTheDocument();
50
-
51
- // Reaching no loader is the claim. Asserting only that the placeholder is
52
- // absent would also pass for a pane that rendered nothing at all.
53
- await waitFor(() => {
54
- expect(screen.queryByText("Loading editor…")).toBeNull();
55
- });
56
- expect(loaders.loadDocumentEditorPeers).not.toHaveBeenCalled();
57
- expect(loaders.loadCollaborationPeers).not.toHaveBeenCalled();
58
- expect(loaders.loadEditorProviderPeers).not.toHaveBeenCalled();
59
- }, 30_000);
60
- });
@@ -1,102 +0,0 @@
1
- import { fireEvent, render, screen } from "@testing-library/react";
2
- import { Component, type ReactNode, Suspense } from "react";
3
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
- import { retryableLazyEditor } from "./editor-lazy";
5
- import { MissingEditorPeersError } from "./editor-peers";
6
-
7
- /** Catches the rejection the lazy component throws, and can mount it again. */
8
- class ResettableBoundary extends Component<
9
- { children: ReactNode },
10
- { failure: Error | null }
11
- > {
12
- state = { failure: null as Error | null };
13
-
14
- static getDerivedStateFromError(error: Error) {
15
- return { failure: error };
16
- }
17
-
18
- render() {
19
- if (this.state.failure) {
20
- return (
21
- <button type="button" onClick={() => this.setState({ failure: null })}>
22
- failed: {this.state.failure.message}
23
- </button>
24
- );
25
- }
26
- return this.props.children;
27
- }
28
- }
29
-
30
- function Loaded() {
31
- return <span>editor</span>;
32
- }
33
-
34
- /** React reports a caught render error on the console; the assertions read it. */
35
- let consoleError: ReturnType<typeof vi.spyOn>;
36
-
37
- beforeEach(() => {
38
- consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
39
- });
40
-
41
- afterEach(() => {
42
- consoleError.mockRestore();
43
- });
44
-
45
- function renderRetryable(load: () => Promise<typeof Loaded>) {
46
- const lazyEditor = retryableLazyEditor(load);
47
- function Host() {
48
- const LazyEditor = lazyEditor();
49
- return (
50
- <Suspense fallback={<span>loading</span>}>
51
- <LazyEditor />
52
- </Suspense>
53
- );
54
- }
55
- return render(
56
- <ResettableBoundary>
57
- <Host />
58
- </ResettableBoundary>,
59
- );
60
- }
61
-
62
- describe("retryableLazyEditor", () => {
63
- it("re-attempts the load after a transient failure", async () => {
64
- // `lazy` caches its first rejection for the life of the component, so one
65
- // failed chunk fetch would otherwise hold the editor broken until a full
66
- // page reload.
67
- const load = vi
68
- .fn<() => Promise<typeof Loaded>>()
69
- .mockRejectedValueOnce(new Error("Failed to fetch dynamically imported module"))
70
- .mockResolvedValue(Loaded);
71
-
72
- renderRetryable(load);
73
-
74
- const retry = await screen.findByRole("button");
75
- expect(retry).toHaveTextContent("Failed to fetch dynamically imported module");
76
- expect(load).toHaveBeenCalledTimes(1);
77
-
78
- fireEvent.click(retry);
79
-
80
- expect(await screen.findByText("editor")).toBeInTheDocument();
81
- expect(load).toHaveBeenCalledTimes(2);
82
- });
83
-
84
- it("keeps a missing peer permanent, so a remount does not import it again", async () => {
85
- // A package does not install itself mid-session. Retrying would only
86
- // repeat the same failure and hide the install list behind a loop.
87
- const load = vi
88
- .fn<() => Promise<typeof Loaded>>()
89
- .mockRejectedValue(new MissingEditorPeersError("Install @tiptap/react."));
90
-
91
- renderRetryable(load);
92
-
93
- const retry = await screen.findByRole("button");
94
- expect(retry).toHaveTextContent("Install @tiptap/react.");
95
- expect(load).toHaveBeenCalledTimes(1);
96
-
97
- fireEvent.click(retry);
98
-
99
- expect(await screen.findByRole("button")).toHaveTextContent("Install @tiptap/react.");
100
- expect(load).toHaveBeenCalledTimes(1);
101
- });
102
- });
@@ -1,250 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import {
3
- asMissingEditorPeersError,
4
- isMissingEditorPeersError,
5
- isMissingPeerError,
6
- } from "./editor-peers";
7
-
8
- /** The namespace shape each peer has when it is installed. */
9
- const installedPeers: Record<string, Record<string, unknown>> = {
10
- "@tiptap/react": { useEditor: () => null, EditorContent: () => null },
11
- "@tiptap/starter-kit": { default: { configure: () => ({}) } },
12
- "@tiptap/extension-collaboration": { default: { configure: () => ({}) } },
13
- "@tiptap/extension-collaboration-caret": { default: { configure: () => ({}) } },
14
- "@hocuspocus/provider": { HocuspocusProvider: class {} },
15
- yjs: { Doc: class {} },
16
- };
17
-
18
- /**
19
- * Loads the module under test with the named peers replaced. The loaders read
20
- * their peers through a dynamic import, so the substitution has to happen
21
- * before the module graph is built — hence the reset and the dynamic import.
22
- */
23
- async function loadPeerLoaders(
24
- replacements: Record<string, Record<string, unknown>> = {},
25
- ) {
26
- vi.resetModules();
27
- for (const specifier of Object.keys(installedPeers)) {
28
- const namespace = replacements[specifier] ?? installedPeers[specifier];
29
- vi.doMock(specifier, () => namespace);
30
- }
31
- return await import("./editor-peers");
32
- }
33
-
34
- afterEach(() => {
35
- vi.resetModules();
36
- });
37
-
38
- describe("isMissingPeerError", () => {
39
- it("recognises what each bundler and runtime says for an uninstalled package", () => {
40
- const messages = [
41
- // Vite's stub for an optional peer that is not installed.
42
- 'Could not resolve "@tiptap/react" imported by "@tangle-network/ui". Is it installed?',
43
- // Node ESM.
44
- "Cannot find package '@tiptap/react' imported from /app/index.js",
45
- // CommonJS.
46
- "Cannot find module '@tiptap/react'",
47
- // webpack.
48
- "Module not found: Error: Can't resolve '@tiptap/react' in '/app'",
49
- // esbuild.
50
- 'Failed to resolve entry for package "@tiptap/react"',
51
- ];
52
-
53
- for (const message of messages) {
54
- expect(isMissingPeerError(new Error(message)), message).toBe(true);
55
- }
56
- });
57
-
58
- it("leaves a transient chunk failure to report its own cause", () => {
59
- // Enriching this one with "install the peers" sends the reader to the
60
- // wrong fix, and the peers are already installed.
61
- expect(
62
- isMissingPeerError(new Error("Failed to fetch dynamically imported module")),
63
- ).toBe(false);
64
- expect(isMissingPeerError(new Error("Network request failed"))).toBe(false);
65
- expect(isMissingPeerError("Could not resolve")).toBe(false);
66
- });
67
- });
68
-
69
- describe("editor optional peer loaders", () => {
70
- it("returns the namespaces the editors call", async () => {
71
- const { loadCollaborationPeers, loadDocumentEditorPeers } = await loadPeerLoaders();
72
-
73
- const documentPeers = await loadDocumentEditorPeers();
74
- expect(documentPeers.react.useEditor).toBe(installedPeers["@tiptap/react"].useEditor);
75
- expect(documentPeers.starterKit.default).toBe(
76
- installedPeers["@tiptap/starter-kit"].default,
77
- );
78
-
79
- const collaborationPeers = await loadCollaborationPeers();
80
- expect(collaborationPeers.hocuspocus.HocuspocusProvider).toBe(
81
- installedPeers["@hocuspocus/provider"].HocuspocusProvider,
82
- );
83
- expect(collaborationPeers.yjs.Doc).toBe(installedPeers.yjs.Doc);
84
- });
85
-
86
- it("names the install list when a peer resolves to a namespace with no editor in it", async () => {
87
- // A bundler can stub a missing optional peer as a silent empty namespace
88
- // rather than a throwing module. That shape must still fail with the peers
89
- // named, and not as an undefined-property crash in the middle of a render.
90
- const { loadDocumentEditorPeers } = await loadPeerLoaders({
91
- "@tiptap/starter-kit": { default: undefined },
92
- });
93
-
94
- await expect(loadDocumentEditorPeers()).rejects.toThrow(
95
- /Install @tiptap\/react and @tiptap\/starter-kit/,
96
- );
97
- });
98
-
99
- it("names the install list when an extension stub carries a default it cannot configure", async () => {
100
- // The commonest stub shape is a default export that is present but empty.
101
- // It passes a plain "is the default defined" test, and then the factory
102
- // calls .configure() on it and throws an opaque TypeError mid-render.
103
- const { loadDocumentEditorPeers } = await loadPeerLoaders({
104
- "@tiptap/starter-kit": { default: {} },
105
- });
106
-
107
- await expect(loadDocumentEditorPeers()).rejects.toThrow(
108
- /Install @tiptap\/react and @tiptap\/starter-kit/,
109
- );
110
- });
111
-
112
- it.each([
113
- "@tiptap/extension-collaboration",
114
- "@tiptap/extension-collaboration-caret",
115
- ])("names the collaboration install list when %s is an empty default", async (specifier) => {
116
- const { loadCollaborationPeers } = await loadPeerLoaders({
117
- [specifier]: { default: {} },
118
- });
119
-
120
- await expect(loadCollaborationPeers()).rejects.toThrow(
121
- /@hocuspocus\/provider and yjs/,
122
- );
123
- });
124
-
125
- it("marks a missing peer permanent and leaves any other failure retryable", async () => {
126
- // editor-lazy.ts reads this distinction to decide whether a remount may
127
- // try the import again.
128
- const { loadDocumentEditorPeers } = await loadPeerLoaders({
129
- "@tiptap/starter-kit": { default: {} },
130
- });
131
-
132
- await expect(loadDocumentEditorPeers()).rejects.toSatisfy(isMissingEditorPeersError);
133
- expect(isMissingEditorPeersError(new Error("Failed to fetch dynamically imported module"))).toBe(
134
- false,
135
- );
136
- });
137
-
138
- it("reports an unresolved import as a permanent missing peer and keeps the cause", async () => {
139
- // The rejection a throwing stub gives must become the install list, so a
140
- // consumer reads which packages to add, and must count as permanent so a
141
- // remount does not retry an import that cannot start to succeed.
142
- const resolutionFailure = new Error('Could not resolve "@tiptap/starter-kit"');
143
- const mapped = asMissingEditorPeersError(resolutionFailure, "install the peers");
144
-
145
- expect(isMissingEditorPeersError(mapped)).toBe(true);
146
- expect(mapped).toHaveProperty("cause", resolutionFailure);
147
- // The install list holds every peer the surface needs, so the message also
148
- // names the one that is actually absent.
149
- expect((mapped as Error).message).toBe(
150
- "install the peers @tiptap/starter-kit did not resolve.",
151
- );
152
- });
153
-
154
- it("names the caret package rather than the collaboration package it contains", async () => {
155
- // "@tiptap/extension-collaboration" is a prefix of the caret specifier, so
156
- // a naive substring match reports the wrong package.
157
- const caretFailure = new Error(
158
- 'Could not resolve "@tiptap/extension-collaboration-caret"',
159
- );
160
- const mapped = asMissingEditorPeersError(caretFailure, "install the peers");
161
-
162
- expect((mapped as Error).message).toBe(
163
- "install the peers @tiptap/extension-collaboration-caret did not resolve.",
164
- );
165
- });
166
-
167
- it("leaves a resolution failure that names no peer alone, so it stays retryable", async () => {
168
- // An application chunk, or a dependency of a peer that did load, can fail
169
- // to resolve too. Installing the editor peers would not fix that, and
170
- // marking it permanent would stop a remount from trying again.
171
- const unrelated = new Error("Cannot find module './app-chunk-a91f.js'");
172
- const mapped = asMissingEditorPeersError(unrelated, "install the peers");
173
-
174
- expect(mapped).toBe(unrelated);
175
- expect(isMissingEditorPeersError(mapped)).toBe(false);
176
- });
177
-
178
- it("treats a @tiptap/core failure as a missing peer, though no loader imports it", async () => {
179
- // The tiptap packages need @tiptap/core in turn, so a consumer that
180
- // resolves it to nothing breaks exactly as one missing @tiptap/react
181
- // does. Leaving it out of the list left that failure retryable.
182
- const coreFailure = new Error('Could not resolve "@tiptap/core"');
183
- const mapped = asMissingEditorPeersError(coreFailure, "install the peers");
184
-
185
- expect(isMissingEditorPeersError(mapped)).toBe(true);
186
- expect((mapped as Error).message).toBe(
187
- "install the peers @tiptap/core did not resolve.",
188
- );
189
- });
190
-
191
- it("keeps the install list alone when the failure names several peers", async () => {
192
- const both = new Error(
193
- 'Could not resolve "@tiptap/react" or "@hocuspocus/provider"',
194
- );
195
- const mapped = asMissingEditorPeersError(both, "install the peers");
196
-
197
- expect(isMissingEditorPeersError(mapped)).toBe(true);
198
- expect((mapped as Error).message).toBe("install the peers");
199
- });
200
-
201
- it("leaves a transient chunk failure unchanged, so a remount can retry it", async () => {
202
- const transient = new Error("Failed to fetch dynamically imported module");
203
-
204
- expect(asMissingEditorPeersError(transient, "install the peers")).toBe(transient);
205
- expect(isMissingEditorPeersError(transient)).toBe(false);
206
- });
207
-
208
- it("names the install list when a peer carries the wrong member type", async () => {
209
- const { loadDocumentEditorPeers } = await loadPeerLoaders({
210
- "@tiptap/react": { useEditor: undefined, EditorContent: undefined },
211
- });
212
-
213
- await expect(loadDocumentEditorPeers()).rejects.toThrow(
214
- /Install @tiptap\/react and @tiptap\/starter-kit/,
215
- );
216
- });
217
-
218
- it("accepts the shapes the installed peers really have", async () => {
219
- // The other cases in this file describe the peers, so nothing here would
220
- // notice a tiptap release that moves `configure` off the default export.
221
- // Loading the real packages is what turns that into a failure here rather
222
- // than in a consumer's editor.
223
- vi.resetModules();
224
- for (const specifier of Object.keys(installedPeers)) {
225
- vi.doUnmock(specifier);
226
- }
227
- const { loadCollaborationPeers } = await import("./editor-peers");
228
-
229
- const peers = await loadCollaborationPeers();
230
- // Prove the substitutions are gone; against the stubs this case would
231
- // pass without reading a real package at all.
232
- expect(peers.starterKit.default).not.toBe(installedPeers["@tiptap/starter-kit"].default);
233
- expect(typeof peers.starterKit.default.configure).toBe("function");
234
- expect(typeof peers.collaboration.default.configure).toBe("function");
235
- expect(typeof peers.collaborationCaret.default.configure).toBe("function");
236
- });
237
-
238
- it("keeps the local editor usable when only a collaboration peer is missing", async () => {
239
- // sandbox-ui installs the tiptap packages alone, so the local markdown
240
- // editor must not start to require yjs or Hocuspocus.
241
- const { loadCollaborationPeers, loadDocumentEditorPeers } = await loadPeerLoaders({
242
- yjs: { Doc: undefined },
243
- });
244
-
245
- await expect(loadDocumentEditorPeers()).resolves.toBeDefined();
246
- await expect(loadCollaborationPeers()).rejects.toThrow(
247
- /@hocuspocus\/provider and yjs/,
248
- );
249
- });
250
- });