Skip to content

Commit 34ead56

Browse files
authored
feat(web): preview opendocument, epub, rich text, and notebooks (#21469)
1 parent 9d17a02 commit 34ead56

28 files changed

Lines changed: 3093 additions & 92 deletions

‎apps/server/src/assets/AssetAccess.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ describe("AssetAccess", () => {
221221
["recording.webm", "video/webm"],
222222
["report.html", "text/html"],
223223
["report.pdf", "application/pdf"],
224+
["notes.odt", "application/vnd.oasis.opendocument.text"],
225+
["budget.ods", "application/vnd.oasis.opendocument.spreadsheet"],
226+
["slides.odp", "application/vnd.oasis.opendocument.presentation"],
227+
["notes.rtf", "application/rtf"],
228+
["book.epub", "application/epub+zip"],
229+
["analysis.ipynb", "application/x-ipynb+json"],
224230
["tone.wav", "audio/wav"],
225231
["tone.webm-audio", "audio/webm"],
226232
["archive.zip", "application/zip"],
@@ -944,6 +950,20 @@ describe("AssetAccess", () => {
944950
expect(yield* resolveAsset(token, ".env")).toBeNull();
945951
expect(yield* resolveAsset(`${token}tampered`, "report.html")).toBeNull();
946952
for (const extension of [
953+
"odt",
954+
"ods",
955+
"odp",
956+
"rtf",
957+
"epub",
958+
"ipynb",
959+
"zip",
960+
"jar",
961+
"tar",
962+
"gz",
963+
"tgz",
964+
"sqlite",
965+
"sqlite3",
966+
"db",
947967
"docx",
948968
"xlsx",
949969
"pptx",
@@ -1018,6 +1038,12 @@ describe("AssetAccess", () => {
10181038
);
10191039
for (const extension of [
10201040
"pdf",
1041+
"odt",
1042+
"ods",
1043+
"odp",
1044+
"rtf",
1045+
"epub",
1046+
"ipynb",
10211047
"png",
10221048
"bmp",
10231049
"heic",
@@ -1082,6 +1108,12 @@ describe("AssetAccess", () => {
10821108
"report.docx",
10831109
"workbook.xlsx",
10841110
"slides.pptx",
1111+
"notes.odt",
1112+
"budget.ods",
1113+
"slides.odp",
1114+
"notes.rtf",
1115+
"book.epub",
1116+
"analysis.ipynb",
10851117
"specimen.ttf",
10861118
"specimen.otf",
10871119
"specimen.woff",

‎apps/web/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"culori": "^4.0.2",
6262
"dompurify": "^3.4.16",
6363
"effect": "catalog:",
64+
"entities": "8.1.0",
6465
"fast-xml-parser": "5.7.3",
6566
"hast-util-to-html": "^9.0.5",
6667
"hast-util-to-jsx-runtime": "^2.3.6",
@@ -72,6 +73,7 @@
7273
"lucide": "^0.564.0",
7374
"lucide-react": "^0.564.0",
7475
"morphicons": "^1.7.1",
76+
"pdfjs-dist": "6.4.299",
7577
"pele": "^1.8.0",
7678
"react": "catalog:",
7779
"react-dom": "catalog:",

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { documentIconColorForFileName } from "~/pierre-icons";
12
import { isProviderSkillUserInvocable } from "@t3tools/client-runtime/providerSkills";
23
import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
34
import {
@@ -45,6 +46,7 @@ import {
4546
useLayoutEffect,
4647
useRef,
4748
useState,
49+
type CSSProperties,
4850
type KeyboardEvent as ReactKeyboardEvent,
4951
type RefObject,
5052
} from "react";
@@ -260,9 +262,11 @@ const ComposerMentionExtension = Node.create({
260262
function ComposerMentionNodeView({ node }: NodeViewProps) {
261263
const actions = use(ComposerContextActionsContext);
262264
const path = (node.attrs.path as string) ?? "";
265+
const accent = documentIconColorForFileName(path);
263266
const chip = (
264267
<ContextChip
265268
kind="mention"
269+
style={accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined}
266270
dir="ltr"
267271
render={<button type="button" />}
268272
onClick={() => actions.openMention(path)}

‎apps/web/src/components/chat/MarkdownFileLink.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import {
55
type AtomCommandResult,
66
} from "@t3tools/client-runtime/state/runtime";
77
import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
8-
import { memo, type MouseEvent as ReactMouseEvent } from "react";
8+
import { memo, type CSSProperties, type MouseEvent as ReactMouseEvent } from "react";
99

1010
import { readLocalApi } from "../../localApi";
1111
import { cn } from "../../lib/utils";
1212
import { shouldOpenMarkdownFileLinkInEditor } from "../../markdown-links";
1313
import type { markdownFileCopyPaths } from "../../markdownFileHostPath";
14+
import { documentIconColorForFileName } from "../../pierre-icons";
1415
import { ContextChip } from "../ContextChip";
1516
import { stackedThreadToast, toastManager } from "../ui/toast";
1617
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
@@ -320,6 +321,8 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
320321
canOpenInBrowser,
321322
canOpenInPanel,
322323
});
324+
const accent = documentIconColorForFileName(iconPath);
325+
const chipStyle = accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined;
323326

324327
return (
325328
<Tooltip>
@@ -331,6 +334,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
331334
dir="ltr"
332335
render={<a href={href} />}
333336
className={MARKDOWN_FILE_LINK_CLASS_NAME}
337+
style={chipStyle}
334338
data-markdown-copy={copyMarkdown}
335339
onClick={(event) => {
336340
event.preventDefault();
@@ -362,6 +366,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
362366
aria-label={`File options for ${label}`}
363367
aria-haspopup="menu"
364368
className={cn(MARKDOWN_FILE_LINK_CLASS_NAME, "select-text")}
369+
style={chipStyle}
365370
data-markdown-copy={copyMarkdown}
366371
onClick={handleContextMenu}
367372
onContextMenu={handleContextMenu}

‎apps/web/src/components/chat/UserMessageContextChips.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { documentIconColorForFileName } from "~/pierre-icons";
12
import { isSvgAttachment } from "@t3tools/shared/image";
23
import { useRenderedAppearance } from "../../hooks/useTheme";
34
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
45
import { ReadOnlySourcePreview } from "../files/AttachmentFilePreview";
56
import { useRightPanelStore } from "~/rightPanelStore";
67
import { COMPOSER_CONTEXT_KINDS } from "@t3tools/contracts";
78
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
8-
import { use, type ReactNode } from "react";
9+
import { use, type CSSProperties, type ReactNode } from "react";
910
import { FileDiff } from "@pierre/diffs/react";
1011
import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider";
1112
import {
@@ -61,12 +62,14 @@ function UserMessageMentionChip(props: {
6162
copyMarkdown: string;
6263
}) {
6364
const ctx = use(TimelineRowCtx);
65+
const accent = documentIconColorForFileName(props.record.path);
6466
return (
6567
<Tooltip>
6668
<TooltipTrigger
6769
render={
6870
<ContextChip
6971
kind="mention"
72+
style={accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined}
7073
render={<button type="button" />}
7174
aria-label={`Preview ${props.record.path}`}
7275
data-markdown-copy={props.copyMarkdown}

‎apps/web/src/components/contextChipParts.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type ReactNode,
1010
} from "react";
1111
import { useAssetUrlState } from "~/assets/assetUrls";
12+
import { documentIconColorForFileName } from "~/pierre-icons";
1213

1314
import { PULL_REQUEST_STATE_PRESENTATION } from "~/components/pullRequest/pullRequestIcons";
1415
import type { PullRequestContextDisplayState } from "~/lib/composerContextRecords";
@@ -242,13 +243,15 @@ export function FileChip(props: {
242243
}) {
243244
if (props.svgPreview && !props.unresolved) return <SvgFileChip {...props} />;
244245
const content = <FileChipContent {...props} />;
246+
const accent = props.isVideo ? undefined : documentIconColorForFileName(props.name);
245247
const state = props.unresolved
246248
? ("unresolved" as const)
247249
: props.error
248250
? ("invalid" as const)
249251
: null;
250252
const attributes = {
251253
kind: props.isVideo ? "video" : "file",
254+
style: accent ? ({ "--context-chip-accent": accent } as CSSProperties) : undefined,
252255
...(state ? { state } : {}),
253256
"aria-label": [props.accessibleLabel, props.suffix].filter(Boolean).join(", "),
254257
"data-markdown-copy": props.copyMarkdown,

0 commit comments

Comments
 (0)