From a56f95f182f87ede9b77eff240f4be934f5b50a6 Mon Sep 17 00:00:00 2001 From: Camiel van Schoonhoven Date: Mon, 2 Nov 2026 13:28:14 -0700 Subject: [PATCH 1/5] feat(documents): add a document from a file, in a code editor The Add a document dialog had two plain fields, so the only way to add an existing file was to paste it in. Long content also pushed the dialog off the page: the textarea grew to fit every line, down and sideways. A dashed strip above Title now takes a dropped file, or a browsed one. The whole form accepts the drop, so a near miss doesn't open the file in the tab. The file's name becomes the title unless one was typed, and its text becomes the content. Only UTF-8 text up to 1 MB is accepted; anything else says why and leaves the fields alone. Content is now the shared code editor in a fixed-height box, with word wrap, so long files scroll and long lines wrap. It highlights by the title's extension, the same rule the document viewers use, which is why a dropped file keeps its extension in the title. Both document dialogs are wider to give the editor room. CodeEditor takes an options override for the editor's aria label and placeholder. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../Project/AddDocumentDialog.test.tsx | 18 ++ src/components/Project/AddDocumentDialog.tsx | 2 +- .../Project/DocumentFileDropZone.tsx | 77 +++++++ src/components/Project/DocumentForm.test.tsx | 213 ++++++++++++++++++ src/components/Project/DocumentForm.tsx | 66 +++++- src/components/Project/documentFile.test.ts | 55 +++++ src/components/Project/documentFile.ts | 42 ++++ src/components/Project/useFileDrop.ts | 45 ++++ .../shared/CodeViewer/CodeEditor.tsx | 11 +- .../Tangent/components/AddResourceButton.tsx | 6 +- 10 files changed, 519 insertions(+), 16 deletions(-) create mode 100644 src/components/Project/DocumentFileDropZone.tsx create mode 100644 src/components/Project/DocumentForm.test.tsx create mode 100644 src/components/Project/documentFile.test.ts create mode 100644 src/components/Project/documentFile.ts create mode 100644 src/components/Project/useFileDrop.ts diff --git a/src/components/Project/AddDocumentDialog.test.tsx b/src/components/Project/AddDocumentDialog.test.tsx index b0b0fef1bc..91a630f9cc 100644 --- a/src/components/Project/AddDocumentDialog.test.tsx +++ b/src/components/Project/AddDocumentDialog.test.tsx @@ -23,6 +23,24 @@ vi.mock("@/providers/AnalyticsProvider", () => ({ useAnalytics: () => ({ track }), })); +vi.mock("@/components/shared/CodeViewer/CodeEditor", () => ({ + default: ({ + value, + onChange, + options, + }: { + value: string; + onChange: (value: string) => void; + options: { ariaLabel: string }; + }) => ( +