From aed1e87bb199a34c3a2629b5e040efa370e95e18 Mon Sep 17 00:00:00 2001 From: "linear-code[bot]" <222613912+linear-code[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:55:10 -0400 Subject: [PATCH 01/38] chore: update @modelcontextprotocol/sdk to 1.32.1 (#14145) * chore: update MCP SDK to 1.32.1 Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com> * feat: Limit MCP tool argument elements to 1000 --------- Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com> Co-authored-by: Tom Moor --- package.json | 2 +- server/mcp/index.ts | 3 +++ server/routes/mcp/index.test.ts | 12 ++++++++++++ yarn.lock | 10 +++++----- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8d3ab33590..77392bceb1 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "@koa/router": "^15.7.0", "@koa/send": "^6.0.0", "@linear/sdk": "^97.0.0", - "@modelcontextprotocol/sdk": "^1.31.0", + "@modelcontextprotocol/sdk": "^1.32.1", "@noble/hashes": "^2.4.0", "@node-oauth/oauth2-server": "^5.3.0", "@notionhq/client": "^2.3.0", diff --git a/server/mcp/index.ts b/server/mcp/index.ts index de890cc309..998691f218 100644 --- a/server/mcp/index.ts +++ b/server/mcp/index.ts @@ -57,6 +57,9 @@ export function createMcpServer( }, }, instructions, + + // Tool arguments are flat, so a large element count is never legitimate. + maxToolInputElements: 1000, } ); diff --git a/server/routes/mcp/index.test.ts b/server/routes/mcp/index.test.ts index 4ecda7c262..5349bf0f01 100644 --- a/server/routes/mcp/index.test.ts +++ b/server/routes/mcp/index.test.ts @@ -199,6 +199,18 @@ describe("POST /mcp/", () => { await user.reload(); expect(user.getFlag(UserFlag.MCP)).toEqual(1); }); + + it("should reject tool arguments with too many elements", async () => { + const { accessToken } = await buildOAuthUser(); + + const res = await callMcpTool(server, accessToken, "list_collections", { + extra: Array.from({ length: 1001 }, (_, i) => i), + }); + expect(res?.result?.isError).toBe(true); + expect(res?.result?.content?.[0]?.text).toContain( + "more than the maximum of 1000 elements" + ); + }); }); describe("resources", () => { diff --git a/yarn.lock b/yarn.lock index 34f60e992b..b03088c16d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2713,9 +2713,9 @@ __metadata: languageName: node linkType: hard -"@modelcontextprotocol/sdk@npm:^1.31.0": - version: 1.31.0 - resolution: "@modelcontextprotocol/sdk@npm:1.31.0" +"@modelcontextprotocol/sdk@npm:^1.32.1": + version: 1.32.1 + resolution: "@modelcontextprotocol/sdk@npm:1.32.1" dependencies: "@hono/node-server": "npm:^1.19.9 || ^2.0.5" ajv: "npm:^8.17.1" @@ -2742,7 +2742,7 @@ __metadata: optional: true zod: optional: false - checksum: 10c0/2c4f011a765fb3346ec578455591d062008a842a0f6f8a763baa97b6a01e0f1febb97d1cc44024ee6d0761d43df56e9c71f72a37d47c7ea6aeb1c4f8be0f06d9 + checksum: 10c0/8b6c8ff6aa5358aeb316fedfa2094a4241ce12d98a0f818cee42510ec9149fed21fc75244c5f0e8cb453337f243c09fa8a90425cd2533fd481964d8583a1f0c9 languageName: node linkType: hard @@ -14389,7 +14389,7 @@ __metadata: "@koa/router": "npm:^15.7.0" "@koa/send": "npm:^6.0.0" "@linear/sdk": "npm:^97.0.0" - "@modelcontextprotocol/sdk": "npm:^1.31.0" + "@modelcontextprotocol/sdk": "npm:^1.32.1" "@noble/hashes": "npm:^2.4.0" "@node-oauth/oauth2-server": "npm:^5.3.0" "@notionhq/client": "npm:^2.3.0" From cd12c681ff4d0f21c26696e6b27f328fd9b8b0a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 20:49:31 -0400 Subject: [PATCH 02/38] chore(deps): bump markdown-it from 14.3.2 to 14.3.3 (#14154) Bumps [markdown-it](https://github.com/markdown-it/markdown-it) from 14.3.2 to 14.3.3. - [Changelog](https://github.com/markdown-it/markdown-it/blob/14.3.3/CHANGELOG.md) - [Commits](https://github.com/markdown-it/markdown-it/compare/14.3.2...14.3.3) --- updated-dependencies: - dependency-name: markdown-it dependency-version: 14.3.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 77392bceb1..546e5cb41a 100644 --- a/package.json +++ b/package.json @@ -177,7 +177,7 @@ "lib0": "^0.2.99", "mailparser": "^3.9.28", "mammoth": "^1.11.0", - "markdown-it": "^14.3.2", + "markdown-it": "^14.3.3", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^3.0.0", "mime-types": "^3.0.2", diff --git a/yarn.lock b/yarn.lock index b03088c16d..3f8aba2c36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13371,7 +13371,7 @@ __metadata: languageName: node linkType: hard -"markdown-it@npm:^14.0.0, markdown-it@npm:^14.3.2": +"markdown-it@npm:^14.0.0": version: 14.3.2 resolution: "markdown-it@npm:14.3.2" dependencies: @@ -13387,6 +13387,22 @@ __metadata: languageName: node linkType: hard +"markdown-it@npm:^14.3.3": + version: 14.3.3 + resolution: "markdown-it@npm:14.3.3" + dependencies: + argparse: "npm:^2.0.1" + entities: "npm:^4.5.0" + linkify-it: "npm:^5.0.2" + mdurl: "npm:^2.0.0" + punycode.js: "npm:^2.3.1" + uc.micro: "npm:^2.1.0" + bin: + markdown-it: bin/markdown-it.mjs + checksum: 10c0/d6075ad320731d7fb9f127e496677f4e36cbdba839d7387dabf1f0d07b5c02bdffb46fb3969033817c04e60017e05d4269e4aa74bee58cc0a562a17cc0b6b8ff + languageName: node + linkType: hard + "matcher-collection@npm:^2.0.0": version: 2.0.1 resolution: "matcher-collection@npm:2.0.1" @@ -14542,7 +14558,7 @@ __metadata: lint-staged: "npm:^16.4.0" mailparser: "npm:^3.9.28" mammoth: "npm:^1.11.0" - markdown-it: "npm:^14.3.2" + markdown-it: "npm:^14.3.3" markdown-it-container: "npm:^3.0.0" markdown-it-emoji: "npm:^3.0.0" mime-types: "npm:^3.0.2" From e544bae966bfb58b4812c145357adbfb3993617b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 20:49:34 -0400 Subject: [PATCH 03/38] chore(deps): bump chrono-node from 2.10.1 to 2.10.3 (#14153) Bumps [chrono-node](https://github.com/wanasit/chrono) from 2.10.1 to 2.10.3. - [Release notes](https://github.com/wanasit/chrono/releases) - [Commits](https://github.com/wanasit/chrono/compare/v2.10.1...v2.10.3) --- updated-dependencies: - dependency-name: chrono-node dependency-version: 2.10.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 546e5cb41a..f501dbbd31 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "addressparser": "^1.0.1", "async-sema": "^3.1.1", "bull": "^4.16.5", - "chrono-node": "^2.10.1", + "chrono-node": "^2.10.3", "class-validator": "^0.15.1", "command-score": "^0.1.2", "compressorjs": "^1.3.0", diff --git a/yarn.lock b/yarn.lock index 3f8aba2c36..5581905f56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8283,10 +8283,10 @@ __metadata: languageName: node linkType: hard -"chrono-node@npm:^2.10.1": - version: 2.10.1 - resolution: "chrono-node@npm:2.10.1" - checksum: 10c0/bb3a7259b8fd5b8657486db0482c352e2a5959000042a0962660474a438c3ffc90a85ad807bea4b0bc23f319a5e92362d0394ed093c6291c737612d3990dcd00 +"chrono-node@npm:^2.10.3": + version: 2.10.3 + resolution: "chrono-node@npm:2.10.3" + checksum: 10c0/612aee720148dc692456fb022eeb16808333f364ca55270af8c4ad3069b531c57fc9cb5aa47bf3085eae324027e386a5a20fb9477d6b51c6b86179fb17988214 languageName: node linkType: hard @@ -14495,7 +14495,7 @@ __metadata: async-sema: "npm:^3.1.1" browserslist-to-esbuild: "npm:^1.2.0" bull: "npm:^4.16.5" - chrono-node: "npm:^2.10.1" + chrono-node: "npm:^2.10.3" class-validator: "npm:^0.15.1" command-score: "npm:^0.1.2" compressorjs: "npm:^1.3.0" From 3581f89201c533c0d5cc2f86ba23309783888c3d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 20:49:38 -0400 Subject: [PATCH 04/38] chore(deps): bump i18next-fs-backend from 2.6.8 to 2.6.9 (#14152) Bumps [i18next-fs-backend](https://github.com/i18next/i18next-fs-backend) from 2.6.8 to 2.6.9. - [Changelog](https://github.com/i18next/i18next-fs-backend/blob/master/CHANGELOG.md) - [Commits](https://github.com/i18next/i18next-fs-backend/compare/v2.6.8...v2.6.9) --- updated-dependencies: - dependency-name: i18next-fs-backend dependency-version: 2.6.9 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f501dbbd31..6a771ad98a 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "http-errors": "2.0.1", "https-proxy-agent": "^7.0.6", "i18next": "^22.5.1", - "i18next-fs-backend": "^2.6.8", + "i18next-fs-backend": "^2.6.9", "i18next-http-backend": "^3.0.6", "invariant": "^2.2.4", "ioredis": "^5.11.1", diff --git a/yarn.lock b/yarn.lock index 5581905f56..90eac096e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11422,10 +11422,10 @@ __metadata: languageName: node linkType: hard -"i18next-fs-backend@npm:^2.6.8": - version: 2.6.8 - resolution: "i18next-fs-backend@npm:2.6.8" - checksum: 10c0/c3750724c17bad6276b43bc5342a83a13eebf66b995fa7b2100224451d30754d2c0eb67364b3c025da8e712f01c7aad212fb4440816337552025e0efab9bf470 +"i18next-fs-backend@npm:^2.6.9": + version: 2.6.9 + resolution: "i18next-fs-backend@npm:2.6.9" + checksum: 10c0/881432a5fd1c75cd44db09968807d3d517dec2ac5312629b751f7d0974ec29f6d08018da78f69becb3b43f50d539cb43f4583dd32afcf80691ce90bd6e901b23 languageName: node linkType: hard @@ -14531,7 +14531,7 @@ __metadata: https-proxy-agent: "npm:^7.0.6" husky: "npm:^8.0.3" i18next: "npm:^22.5.1" - i18next-fs-backend: "npm:^2.6.8" + i18next-fs-backend: "npm:^2.6.9" i18next-http-backend: "npm:^3.0.6" i18next-parser: "npm:^9.4.0" invariant: "npm:^2.2.4" From d015a32459b5f5c5a8ef67aeb81742eeab430c52 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 19 Oct 2026 21:58:41 -0400 Subject: [PATCH 05/38] fix: Share state handling for unpublished documents (#14160) * fix: Share state handling for unpublished documents * fix: Update cached shares when a document is unpublished * Revert "fix: Update cached shares when a document is unpublished" This reverts commit 15abf962b87870103230a1e17efe24c8d7799200. --- server/models/Document.ts | 14 +++++++++ server/routes/api/documents/documents.test.ts | 30 +++++++++++++++++++ server/routes/api/shares/shares.test.ts | 23 ++++++++++++++ server/routes/api/shares/shares.ts | 4 ++- 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/server/models/Document.ts b/server/models/Document.ts index c12e1f6bdd..bbc7c687f5 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -69,6 +69,7 @@ import GroupUser from "./GroupUser"; import Import from "./Import"; import Relationship from "./Relationship"; import Revision from "./Revision"; +import Share from "./Share"; import Star from "./Star"; import Team from "./Team"; import User from "./User"; @@ -1426,6 +1427,19 @@ class Document extends ArchivableModel< this.collectionId = null; } + // Withdrawing the document also disables its public share links. + const shares = await Share.findAll({ + where: { + documentId: this.id, + published: true, + revokedAt: { [Op.is]: null }, + }, + transaction, + }); + for (const share of shares) { + await share.updateWithCtx(ctx, { published: false }); + } + return this.saveWithCtx(ctx, undefined, { name: "unpublish" }); }; diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index 101fa5e4b9..d6138c4a42 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -29,6 +29,7 @@ import { FileOperation, GroupMembership, Relationship, + Share, } from "@server/models"; import { RelationshipType } from "@server/models/Relationship"; import { DocumentHelper } from "@server/models/helpers/DocumentHelper"; @@ -7715,6 +7716,35 @@ describe("#documents.unpublish", () => { expect(reloaded!.createdById).toEqual(user.id); }); + it("should disable public shares when unpublishing a document", async () => { + const user = await buildUser(); + const document = await buildDocument({ + userId: user.id, + teamId: user.teamId, + }); + const share = await buildShare({ + documentId: document.id, + teamId: user.teamId, + userId: user.id, + }); + const res = await server.post("/api/documents.unpublish", user, { + body: { + id: document.id, + }, + }); + expect(res.status).toEqual(200); + + const reloaded = await Share.unscoped().findByPk(share.id); + expect(reloaded!.published).toEqual(false); + + const infoRes = await server.post("/api/shares.info", { + body: { + id: share.id, + }, + }); + expect(infoRes.status).toEqual(404); + }); + it("should unpublish a document with archived children", async () => { const user = await buildUser(); const document = await buildDocument({ diff --git a/server/routes/api/shares/shares.test.ts b/server/routes/api/shares/shares.test.ts index 480e70cc83..24e33ed928 100644 --- a/server/routes/api/shares/shares.test.ts +++ b/server/routes/api/shares/shares.test.ts @@ -6,6 +6,7 @@ import { UserMembership, Share, ShareSubscription } from "@server/models"; import { buildUser, buildDocument, + buildDraftDocument, buildShare, buildAdmin, buildViewer, @@ -1312,6 +1313,28 @@ describe("#shares.revoke", () => { expect(res.status).toEqual(200); }); + it("should allow author to revoke a share on a draft", async () => { + const user = await buildUser(); + const document = await buildDraftDocument({ + userId: user.id, + teamId: user.teamId, + }); + const share = await buildShare({ + documentId: document.id, + teamId: user.teamId, + userId: user.id, + }); + const res = await server.post("/api/shares.revoke", user, { + body: { + id: share.id, + }, + }); + expect(res.status).toEqual(200); + + const reloaded = await Share.unscoped().findByPk(share.id); + expect(reloaded!.revokedAt).toBeTruthy(); + }); + it("should allow author to revoke collection share", async () => { const user = await buildUser(); const collection = await buildCollection({ diff --git a/server/routes/api/shares/shares.ts b/server/routes/api/shares/shares.ts index 5a22217add..7e1a26ab6c 100644 --- a/server/routes/api/shares/shares.ts +++ b/server/routes/api/shares/shares.ts @@ -429,7 +429,9 @@ router.post( async (ctx: APIContext) => { const { id } = ctx.input.body; const { user } = ctx.state.auth; - const share = await Share.findByPk(id); + const share = await Share.scope({ + method: ["withCollectionPermissions", user.id], + }).findByPk(id); if (!share?.collection && !share?.document) { throw NotFoundError(); From 56dd0259b3deaed9a5916dc673633a69e132a2de Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 19 Oct 2026 23:21:52 -0400 Subject: [PATCH 06/38] chore: Compile server, shared and plugins in a single SWC process (#14164) --- build.js | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/build.js b/build.js index 177135f0c3..09d238cd4f 100755 --- a/build.js +++ b/build.js @@ -2,7 +2,7 @@ /* oxlint-disable typescript/no-require-imports */ /* oxlint-disable no-undef */ const { exec } = require("child_process"); -const { readdirSync, existsSync } = require("fs"); +const { readdirSync } = require("fs"); const getDirectories = (source) => readdirSync(source, { withFileTypes: true }) @@ -38,34 +38,12 @@ async function build() { const d = getDirectories("./plugins"); - // Compile server and shared + // Compile server, shared and plugins in a single SWC process, as process + // startup costs far more than the compilation itself. console.log("Compiling…"); - const swc = (src, out) => - execAsync( - `yarn swc "${src}" -d "${out}" --strip-leading-paths --extensions .ts,.tsx --ignore "**/*.test.ts,**/*.test.tsx,**/__mocks__/**" --quiet` - ); - - await Promise.all([ - swc("./server", "./build/server"), - swc("./shared", "./build/shared"), - ]); - - // SWC's --strip-leading-paths removes only the topmost path segment, so a - // `plugins//server` input keeps `/server/…` and lands correctly - // under a `./build/plugins` output directory. - for (const plugin of d) { - const hasServer = existsSync(`./plugins/${plugin}/server`); - - if (hasServer) { - await swc(`./plugins/${plugin}/server`, "./build/plugins"); - } - - const hasShared = existsSync(`./plugins/${plugin}/shared`); - - if (hasShared) { - await swc(`./plugins/${plugin}/shared`, "./build/plugins"); - } - } + await execAsync( + `yarn swc ./server ./shared ./plugins -d ./build --extensions .ts,.tsx --ignore "**/*.test.ts,**/*.test.tsx,**/__mocks__/**,plugins/*/client/**" --quiet` + ); // Copy static files console.log("Copying static files…"); From d249b34e8e5fd465d542cad87190d411fdcbd5dc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 19 Oct 2026 23:23:11 -0400 Subject: [PATCH 07/38] fix: Tighten checks when publishing drafts (#14155) * fix: Tighten checks when publishing drafts Detaching a document on unpublish now also clears its parent. * fix: Publish at the root when the parent is in another collection * test: Load detached drafts without the default scope --- server/commands/documentCreator.ts | 14 +- server/models/Document.ts | 12 ++ server/routes/api/documents/documents.test.ts | 148 ++++++++++++++++++ yarn.lock | 30 +--- 4 files changed, 171 insertions(+), 33 deletions(-) diff --git a/server/commands/documentCreator.ts b/server/commands/documentCreator.ts index 8d4afaf09f..2456e8f72e 100644 --- a/server/commands/documentCreator.ts +++ b/server/commands/documentCreator.ts @@ -139,11 +139,15 @@ export async function authorizeDocumentPublish( }); } - if (document.parentDocumentId) { - const parentDocument = await Document.findByPk(document.parentDocumentId, { - userId: user.id, - transaction, - }); + const parentDocument = document.parentDocumentId + ? await Document.findByPk(document.parentDocumentId, { + userId: user.id, + transaction, + }) + : null; + + // The parent only grants access when it is in the destination collection. + if (parentDocument && parentDocument.collectionId === collection?.id) { authorize(user, "createChildDocument", parentDocument, { collection }); } else { authorize(user, "createDocument", collection); diff --git a/server/models/Document.ts b/server/models/Document.ts index bbc7c687f5..2b2ac202b2 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -1315,6 +1315,17 @@ class Document extends ArchivableModel< this.collectionId = collectionId; } + // A parent outside the destination collection is stale, so publish at the root. + if (this.parentDocumentId && this.collectionId) { + const parentDocument = await Document.unscoped().findByPk( + this.parentDocumentId, + { attributes: ["collectionId"], transaction } + ); + if (parentDocument?.collectionId !== this.collectionId) { + this.parentDocumentId = null; + } + } + if (this.collectionId) { const collection = await Collection.findByPk(this.collectionId, { includeDocumentStructure: true, @@ -1425,6 +1436,7 @@ class Document extends ArchivableModel< if (options.detach) { this.collectionId = null; + this.parentDocumentId = null; } // Withdrawing the document also disables its public share links. diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index d6138c4a42..6c101a7928 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -6987,6 +6987,128 @@ describe("#documents.update", () => { expect(res.status).toEqual(403); }); + it("should not allow publishing a child draft into an inaccessible collection", async () => { + const team = await buildTeam(); + const admin = await buildAdmin({ teamId: team.id }); + const user = await buildUser({ teamId: team.id }); + const collection = await buildCollection({ + userId: user.id, + teamId: team.id, + }); + const privateCollection = await buildCollection({ + userId: admin.id, + teamId: team.id, + permission: null, + }); + const parentDocument = await buildDocument({ + userId: user.id, + teamId: team.id, + collectionId: collection.id, + }); + const document = await buildDraftDocument({ + userId: user.id, + teamId: team.id, + collectionId: null, + parentDocumentId: parentDocument.id, + }); + const res = await server.post("/api/documents.update", user, { + body: { + id: document.id, + collectionId: privateCollection.id, + publish: true, + }, + }); + expect(res.status).toEqual(403); + + const reloaded = await Document.unscoped().findByPk(document.id); + expect(reloaded?.publishedAt).toBeNull(); + expect(reloaded?.collectionId).toBeNull(); + }); + + it("should allow publishing a child draft into the parent collection", async () => { + const team = await buildTeam(); + const user = await buildUser({ teamId: team.id }); + const collection = await buildCollection({ + userId: user.id, + teamId: team.id, + }); + const parentDocument = await buildDocument({ + userId: user.id, + teamId: team.id, + collectionId: collection.id, + }); + const document = await buildDraftDocument({ + userId: user.id, + teamId: team.id, + collectionId: null, + parentDocumentId: parentDocument.id, + }); + const res = await server.post("/api/documents.update", user, { + body: { + id: document.id, + collectionId: collection.id, + publish: true, + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.collectionId).toBe(collection.id); + expect(body.data.parentDocumentId).toBe(parentDocument.id); + }); + + it("should publish a child draft at the root of another collection", async () => { + const team = await buildTeam(); + const user = await buildUser({ teamId: team.id }); + const member = await buildUser({ teamId: team.id }); + const collection = await buildCollection({ + userId: user.id, + teamId: team.id, + }); + const otherCollection = await buildCollection({ + userId: user.id, + teamId: team.id, + }); + const parentDocument = await buildDocument({ + userId: user.id, + teamId: team.id, + collectionId: collection.id, + }); + await UserMembership.create({ + userId: member.id, + documentId: parentDocument.id, + permission: DocumentPermission.Read, + createdById: user.id, + }); + const document = await buildDraftDocument({ + userId: user.id, + teamId: team.id, + collectionId: null, + parentDocumentId: parentDocument.id, + }); + const res = await server.post("/api/documents.update", user, { + body: { + id: document.id, + collectionId: otherCollection.id, + publish: true, + }, + }); + expect(res.status).toEqual(200); + + await document.reload(); + expect(document.collectionId).toBe(otherCollection.id); + expect(document.parentDocumentId).toBeNull(); + + await otherCollection.reload(); + expect(otherCollection.documentStructure?.map((node) => node.id)).toContain( + document.id + ); + + const membership = await UserMembership.findOne({ + where: { userId: member.id, documentId: document.id }, + }); + expect(membership).toBeNull(); + }); + it("should fail to update an invalid icon value", async () => { const user = await buildUser(); const document = await buildDocument({ @@ -7716,6 +7838,32 @@ describe("#documents.unpublish", () => { expect(reloaded!.createdById).toEqual(user.id); }); + it("should remove the collection and parent when detaching", async () => { + const user = await buildUser(); + const parentDocument = await buildDocument({ + userId: user.id, + teamId: user.teamId, + }); + const document = await buildDocument({ + userId: user.id, + teamId: user.teamId, + collectionId: parentDocument.collectionId, + parentDocumentId: parentDocument.id, + }); + const res = await server.post("/api/documents.unpublish", user, { + body: { + id: document.id, + detach: true, + }, + }); + expect(res.status).toEqual(200); + + const reloaded = await Document.unscoped().findByPk(document.id); + expect(reloaded?.publishedAt).toBeNull(); + expect(reloaded?.collectionId).toBeNull(); + expect(reloaded?.parentDocumentId).toBeNull(); + }); + it("should disable public shares when unpublishing a document", async () => { const user = await buildUser(); const document = await buildDocument({ diff --git a/yarn.lock b/yarn.lock index 90eac096e3..d2a319ce60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5706,17 +5706,7 @@ __metadata: languageName: node linkType: hard -"@smithy/core@npm:^3.33.2, @smithy/core@npm:^3.33.3, @smithy/core@npm:^3.35.0": - version: 3.35.0 - resolution: "@smithy/core@npm:3.35.0" - dependencies: - "@smithy/types": "npm:^4.19.0" - tslib: "npm:^2.6.2" - checksum: 10c0/9c0b8343c3ea720498e495ffdf83cb587775ff27b5a968c4f2a3da2410689ea593c005a4b8fa5c1e47624b52af5901b7aab79603acd317987920deedb53695d2 - languageName: node - linkType: hard - -"@smithy/core@npm:^3.35.2": +"@smithy/core@npm:^3.33.2, @smithy/core@npm:^3.33.3, @smithy/core@npm:^3.35.0, @smithy/core@npm:^3.35.2": version: 3.35.2 resolution: "@smithy/core@npm:3.35.2" dependencies: @@ -13371,23 +13361,7 @@ __metadata: languageName: node linkType: hard -"markdown-it@npm:^14.0.0": - version: 14.3.2 - resolution: "markdown-it@npm:14.3.2" - dependencies: - argparse: "npm:^2.0.1" - entities: "npm:^4.5.0" - linkify-it: "npm:^5.0.2" - mdurl: "npm:^2.0.0" - punycode.js: "npm:^2.3.1" - uc.micro: "npm:^2.1.0" - bin: - markdown-it: bin/markdown-it.mjs - checksum: 10c0/51d03a244bbacc84aa7229fd784ccc16a76cb853cf93f668c4dfc1e9eb22d03138678e7743accac2304e03151a995068492fde56c7a9fbe6785b4169036cf590 - languageName: node - linkType: hard - -"markdown-it@npm:^14.3.3": +"markdown-it@npm:^14.0.0, markdown-it@npm:^14.3.3": version: 14.3.3 resolution: "markdown-it@npm:14.3.3" dependencies: From 584e27ad10e87fefd61d8a34b06e39843888b29c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 19 Oct 2026 23:33:44 -0400 Subject: [PATCH 08/38] fix: Check permissions earlier in users.update_role (#14156) --- server/routes/api/users/users.test.ts | 28 +++++++++++++++++++++++++++ server/routes/api/users/users.ts | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/server/routes/api/users/users.test.ts b/server/routes/api/users/users.test.ts index ee884ac3eb..fec3e1bd85 100644 --- a/server/routes/api/users/users.test.ts +++ b/server/routes/api/users/users.test.ts @@ -1266,6 +1266,34 @@ describe("#users.update_role", () => { }); expect(res.status).toEqual(400); }); + + it("should return the same error for a user in another team", async () => { + const admin = await buildAdmin(); + const user = await buildAdmin(); + + for (const role of [UserRole.Admin, UserRole.Member]) { + const res = await server.post("/api/users.update_role", admin, { + body: { + id: user.id, + role, + }, + }); + expect(res.status).toEqual(403); + } + expect((await user.reload()).role).toEqual(UserRole.Admin); + }); + + it("should return the same error for an unknown user", async () => { + const admin = await buildAdmin(); + + const res = await server.post("/api/users.update_role", admin, { + body: { + id: faker.string.uuid(), + role: UserRole.Admin, + }, + }); + expect(res.status).toEqual(403); + }); }); describe("#users.promote", () => { diff --git a/server/routes/api/users/users.ts b/server/routes/api/users/users.ts index d1c21b8b34..ca50171450 100644 --- a/server/routes/api/users/users.ts +++ b/server/routes/api/users/users.ts @@ -371,10 +371,11 @@ async function updateRole(ctx: APIContext) { const actor = ctx.state.auth.user; const user = await User.findByPk(userId, { - rejectOnEmpty: true, transaction, lock: transaction.LOCK.UPDATE, }); + authorize(actor, "update", user); + await Team.findByPk(user.teamId, { transaction, lock: transaction.LOCK.UPDATE, From 61e21028750ea4ce6b7c1fad916cd632e0c872e7 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 19 Oct 2026 23:34:01 -0400 Subject: [PATCH 09/38] fix: Align desktop history navigation with document header (#14159) --- app/components/Sidebar/components/HistoryNavigation.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/Sidebar/components/HistoryNavigation.tsx b/app/components/Sidebar/components/HistoryNavigation.tsx index ee9af46a63..49a0430489 100644 --- a/app/components/Sidebar/components/HistoryNavigation.tsx +++ b/app/components/Sidebar/components/HistoryNavigation.tsx @@ -92,7 +92,7 @@ function HistoryNavigation(props: React.ComponentProps) { const Navigation = styled(Flex)` position: absolute; inset-inline-end: 12px; - top: 20px; + top: 17px; button { cursor: default; From f7d4afe26c279eafa90031e993444c6b414e8a27 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Oct 2026 07:32:40 -0400 Subject: [PATCH 10/38] chore(deps): bump the aws group with 5 updates (#14150) Bumps the aws group with 5 updates: | Package | From | To | | --- | --- | --- | | [@aws-sdk/client-s3](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/clients/client-s3) | `3.1149.0` | `3.1152.0` | | [@aws-sdk/lib-storage](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/lib/lib-storage) | `3.1149.0` | `3.1152.0` | | [@aws-sdk/s3-presigned-post](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/packages/s3-presigned-post) | `3.1149.0` | `3.1152.0` | | [@aws-sdk/s3-request-presigner](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/packages/s3-request-presigner) | `3.1149.0` | `3.1152.0` | | [@aws-sdk/signature-v4-crt](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/packages/signature-v4-crt) | `3.1149.0` | `3.1152.0` | Updates `@aws-sdk/client-s3` from 3.1149.0 to 3.1152.0 - [Release notes](https://github.com/aws/aws-sdk-js-v3/releases) - [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-s3/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.1152.0/clients/client-s3) Updates `@aws-sdk/lib-storage` from 3.1149.0 to 3.1152.0 - [Release notes](https://github.com/aws/aws-sdk-js-v3/releases) - [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-storage/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.1152.0/lib/lib-storage) Updates `@aws-sdk/s3-presigned-post` from 3.1149.0 to 3.1152.0 - [Release notes](https://github.com/aws/aws-sdk-js-v3/releases) - [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/packages/s3-presigned-post/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.1152.0/packages/s3-presigned-post) Updates `@aws-sdk/s3-request-presigner` from 3.1149.0 to 3.1152.0 - [Release notes](https://github.com/aws/aws-sdk-js-v3/releases) - [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/packages/s3-request-presigner/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.1152.0/packages/s3-request-presigner) Updates `@aws-sdk/signature-v4-crt` from 3.1149.0 to 3.1152.0 - [Release notes](https://github.com/aws/aws-sdk-js-v3/releases) - [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/packages/signature-v4-crt/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.1152.0/packages/signature-v4-crt) --- updated-dependencies: - dependency-name: "@aws-sdk/client-s3" dependency-version: 3.1152.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws - dependency-name: "@aws-sdk/lib-storage" dependency-version: 3.1152.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws - dependency-name: "@aws-sdk/s3-presigned-post" dependency-version: 3.1152.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws - dependency-name: "@aws-sdk/s3-request-presigner" dependency-version: 3.1152.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws - dependency-name: "@aws-sdk/signature-v4-crt" dependency-version: 3.1152.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: aws ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 10 +- yarn.lock | 304 +++++++++++++++++++++++++-------------------------- 2 files changed, 157 insertions(+), 157 deletions(-) diff --git a/package.json b/package.json index 6a771ad98a..cbabb9bc21 100644 --- a/package.json +++ b/package.json @@ -52,12 +52,12 @@ "> 0.25%, not dead" ], "dependencies": { - "@aws-sdk/client-s3": "^3.1149.0", + "@aws-sdk/client-s3": "^3.1152.0", "@aws-sdk/cloudfront-signer": "^3.1149.0", - "@aws-sdk/lib-storage": "^3.1149.0", - "@aws-sdk/s3-presigned-post": "^3.1149.0", - "@aws-sdk/s3-request-presigner": "^3.1149.0", - "@aws-sdk/signature-v4-crt": "^3.1149.0", + "@aws-sdk/lib-storage": "^3.1152.0", + "@aws-sdk/s3-presigned-post": "^3.1152.0", + "@aws-sdk/s3-request-presigner": "^3.1152.0", + "@aws-sdk/signature-v4-crt": "^3.1152.0", "@benrbray/prosemirror-math": "^0.2.2", "@bull-board/api": "^6.21.3", "@bull-board/koa": "^6.21.3", diff --git a/yarn.lock b/yarn.lock index d2a319ce60..1ab8dbfa16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,27 +18,27 @@ __metadata: languageName: node linkType: hard -"@aws-sdk/checksums@npm:^3.1001.2": - version: 3.1001.2 - resolution: "@aws-sdk/checksums@npm:3.1001.2" +"@aws-sdk/checksums@npm:^3.1001.3": + version: 3.1001.3 + resolution: "@aws-sdk/checksums@npm:3.1001.3" dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/fd40724bbab7641eb7f5ae85737c1d5bed096a2243133b46df1c47a4f6129a93fefa887a9a6d1044c68e179d06e0950309cd5eba8e03c9a29a33787ac42b9ce0 + checksum: 10c0/d7cceb3e63e93ececc00d80d5cbf54aaeec44d5d283433662d768e1eddbfeff999707f71e8bb7124015edbc2531c1b84803912e9fedc07a6c2e893e8b8b33c62 languageName: node linkType: hard -"@aws-sdk/client-s3@npm:3.1149.0, @aws-sdk/client-s3@npm:^3.1149.0": - version: 3.1149.0 - resolution: "@aws-sdk/client-s3@npm:3.1149.0" +"@aws-sdk/client-s3@npm:3.1152.0, @aws-sdk/client-s3@npm:^3.1152.0": + version: 3.1152.0 + resolution: "@aws-sdk/client-s3@npm:3.1152.0" dependencies: - "@aws-sdk/checksums": "npm:^3.1001.2" - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/credential-provider-node": "npm:^3.972.85" - "@aws-sdk/middleware-sdk-s3": "npm:^3.972.78" + "@aws-sdk/checksums": "npm:^3.1001.3" + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/credential-provider-node": "npm:^3.972.86" + "@aws-sdk/middleware-sdk-s3": "npm:^3.972.79" "@aws-sdk/signature-v4-multi-region": "npm:^3.996.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" @@ -46,7 +46,7 @@ __metadata: "@smithy/node-http-handler": "npm:^4.12.1" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/97b8effdcfe2eb958f30c8aa1c7df47f878b32077a6013c0ba6c6efd8a4dc474d507b13839fe222ab9a39c2809670f471879025436a1e425a4c0422f9248897e + checksum: 10c0/3730e9ace5713ba81a1cdb965c21d57c9546327b7f26e379933f0544b199c9b0ac511173361b32a33e672524cb23422d6e99f0fc47c088d59b3ffaa60dd9716a languageName: node linkType: hard @@ -60,9 +60,9 @@ __metadata: languageName: node linkType: hard -"@aws-sdk/core@npm:^3.978.2": - version: 3.978.2 - resolution: "@aws-sdk/core@npm:3.978.2" +"@aws-sdk/core@npm:^3.978.3": + version: 3.978.3 + resolution: "@aws-sdk/core@npm:3.978.3" dependencies: "@aws-sdk/types": "npm:^3.974.6" "@aws-sdk/xml-builder": "npm:^3.972.41" @@ -72,148 +72,148 @@ __metadata: "@smithy/types": "npm:^4.19.0" bowser: "npm:^2.11.0" tslib: "npm:^2.6.2" - checksum: 10c0/d2cb6a2794d1ed57c256e3523023606f86f679c0da361e1cd94ff2b177593a4bc898738031278dac0aaf025f72beca6ffe42c5a2fd6738a874b9dc19b221dbf3 + checksum: 10c0/5f5e14629cf26d4c9d4a09e95cfb1bbd4ec880f4eb94d7bcecfd00a6099ab716bf4871e581dbd5a89cd5a06e13621871b54006aa6a36bf1d385d20816813e337 languageName: node linkType: hard -"@aws-sdk/credential-provider-env@npm:^3.972.73": - version: 3.972.73 - resolution: "@aws-sdk/credential-provider-env@npm:3.972.73" +"@aws-sdk/credential-provider-env@npm:^3.972.74": + version: 3.972.74 + resolution: "@aws-sdk/credential-provider-env@npm:3.972.74" dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/d60d6319390e36883a92d9dbf00a01d76cd449920019f99df3006b4896f434eb007235e052a9173e7f7e518539568f0c4f46278d8c9831682494b90f7dbdfcd2 + checksum: 10c0/ce6963f9e02e5d67ca9cf3bdf08cb73872abd5907ccd51f0e6381fa059148fa7f273e78f4f214b47849c8ab9a1910cb86bcc82d6551ed464a63502a70d9b71b4 languageName: node linkType: hard -"@aws-sdk/credential-provider-http@npm:^3.972.75": - version: 3.972.75 - resolution: "@aws-sdk/credential-provider-http@npm:3.972.75" +"@aws-sdk/credential-provider-http@npm:^3.972.76": + version: 3.972.76 + resolution: "@aws-sdk/credential-provider-http@npm:3.972.76" dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/fetch-http-handler": "npm:^5.8.0" "@smithy/node-http-handler": "npm:^4.12.1" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/9f983e083a232ab0f910db670b2162affac7cc2c6300eebbda4c3822a38761ae67b5925ca1dd1f1c9032ba25b57721721567346ca35b2eb399dc12aa45a7583c + checksum: 10c0/9921862c990f2cf8beb76811bed873a0c01db032476f48e77b71f2e886a49b70837b1e15cf4adf39a8eef16be1636786023ea5a03e9de1453b15babc473739d4 languageName: node linkType: hard -"@aws-sdk/credential-provider-ini@npm:^3.973.18": +"@aws-sdk/credential-provider-ini@npm:^3.973.19": + version: 3.973.19 + resolution: "@aws-sdk/credential-provider-ini@npm:3.973.19" + dependencies: + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/credential-provider-env": "npm:^3.972.74" + "@aws-sdk/credential-provider-http": "npm:^3.972.76" + "@aws-sdk/credential-provider-login": "npm:^3.972.81" + "@aws-sdk/credential-provider-process": "npm:^3.972.74" + "@aws-sdk/credential-provider-sso": "npm:^3.973.18" + "@aws-sdk/credential-provider-web-identity": "npm:^3.972.80" + "@aws-sdk/nested-clients": "npm:^3.997.48" + "@aws-sdk/types": "npm:^3.974.6" + "@smithy/core": "npm:^3.35.2" + "@smithy/credential-provider-imds": "npm:^4.5.2" + "@smithy/types": "npm:^4.19.0" + tslib: "npm:^2.6.2" + checksum: 10c0/f1babaaabc615fb48ce1d293c2c0f9236901edc2a0ccd8b8aa58f7a59df3e5e5a40b877c2f821f3904c52e2c9be39b468eb12470b4ce24d262105d6148e3906e + languageName: node + linkType: hard + +"@aws-sdk/credential-provider-login@npm:^3.972.81": + version: 3.972.81 + resolution: "@aws-sdk/credential-provider-login@npm:3.972.81" + dependencies: + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/nested-clients": "npm:^3.997.48" + "@aws-sdk/types": "npm:^3.974.6" + "@smithy/core": "npm:^3.35.2" + "@smithy/types": "npm:^4.19.0" + tslib: "npm:^2.6.2" + checksum: 10c0/e37ee7146b9b33dd14398e7b63de430dec62067ba960a504f18e078d0d918f070e73b961a8f84edaf6b5a4fa2126e2855d881960df410e607d5392d02184a4ed + languageName: node + linkType: hard + +"@aws-sdk/credential-provider-node@npm:^3.972.86": + version: 3.972.86 + resolution: "@aws-sdk/credential-provider-node@npm:3.972.86" + dependencies: + "@aws-sdk/credential-provider-env": "npm:^3.972.74" + "@aws-sdk/credential-provider-http": "npm:^3.972.76" + "@aws-sdk/credential-provider-ini": "npm:^3.973.19" + "@aws-sdk/credential-provider-process": "npm:^3.972.74" + "@aws-sdk/credential-provider-sso": "npm:^3.973.18" + "@aws-sdk/credential-provider-web-identity": "npm:^3.972.80" + "@aws-sdk/types": "npm:^3.974.6" + "@smithy/core": "npm:^3.35.2" + "@smithy/credential-provider-imds": "npm:^4.5.2" + "@smithy/types": "npm:^4.19.0" + tslib: "npm:^2.6.2" + checksum: 10c0/66cb2ab79cd6fa7eebad84e4fb043bb619e2119cdd6f4ff67b2825068fe51bb41161581566b98042c66593155e39e2a1b8a53e2f89a5a3f4fb56b6d07e5a875d + languageName: node + linkType: hard + +"@aws-sdk/credential-provider-process@npm:^3.972.74": + version: 3.972.74 + resolution: "@aws-sdk/credential-provider-process@npm:3.972.74" + dependencies: + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/types": "npm:^3.974.6" + "@smithy/core": "npm:^3.35.2" + "@smithy/types": "npm:^4.19.0" + tslib: "npm:^2.6.2" + checksum: 10c0/4408a904ee5f9c76746a440985b4c14107c8d29d12f3c412ca23c609017a05e970c471a8adf25f662c284c480baf8aa26def66d30b2ccce532fb4e6c3655a8fb + languageName: node + linkType: hard + +"@aws-sdk/credential-provider-sso@npm:^3.973.18": version: 3.973.18 - resolution: "@aws-sdk/credential-provider-ini@npm:3.973.18" + resolution: "@aws-sdk/credential-provider-sso@npm:3.973.18" dependencies: - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/credential-provider-env": "npm:^3.972.73" - "@aws-sdk/credential-provider-http": "npm:^3.972.75" - "@aws-sdk/credential-provider-login": "npm:^3.972.80" - "@aws-sdk/credential-provider-process": "npm:^3.972.73" - "@aws-sdk/credential-provider-sso": "npm:^3.973.17" - "@aws-sdk/credential-provider-web-identity": "npm:^3.972.79" - "@aws-sdk/nested-clients": "npm:^3.997.47" + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/nested-clients": "npm:^3.997.48" + "@aws-sdk/token-providers": "npm:3.1150.0" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" - "@smithy/credential-provider-imds": "npm:^4.5.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/cf2862ae983155883d08302dee65743d83c3774e473cb4742a55bef90c2a6c523e377ef44d008398f23e3a8120e3bee5338c8c2c2ffd197d9e56581c419e35f7 + checksum: 10c0/49a9852188b043a23795675e93298070d8bfe75b74b1db9217411a96271c678cd53dd06c80d97515ce9884693da551e804fbc3bcfed5e6f5f6d1e1c5e1ae491a languageName: node linkType: hard -"@aws-sdk/credential-provider-login@npm:^3.972.80": +"@aws-sdk/credential-provider-web-identity@npm:^3.972.80": version: 3.972.80 - resolution: "@aws-sdk/credential-provider-login@npm:3.972.80" + resolution: "@aws-sdk/credential-provider-web-identity@npm:3.972.80" dependencies: - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/nested-clients": "npm:^3.997.47" + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/nested-clients": "npm:^3.997.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/d35cffe704c3b30f4569632d4bd87a11ab200e78c9247b1ed113f059b611b1f88729524f2cf32ae5d2bce14815814dc6d453b7cdad64a9106b8996a257b12763 + checksum: 10c0/e97acf071ef2ceb45dd9183f0ca6ac9ce606638beb47d72f3665cb270e3006b79aed8589545639a1bb4e0f2792f5d6f5b3025b7e55e1ab680628280440f998ab languageName: node linkType: hard -"@aws-sdk/credential-provider-node@npm:^3.972.85": - version: 3.972.85 - resolution: "@aws-sdk/credential-provider-node@npm:3.972.85" +"@aws-sdk/crt-loader@npm:^3.972.78": + version: 3.972.78 + resolution: "@aws-sdk/crt-loader@npm:3.972.78" dependencies: - "@aws-sdk/credential-provider-env": "npm:^3.972.73" - "@aws-sdk/credential-provider-http": "npm:^3.972.75" - "@aws-sdk/credential-provider-ini": "npm:^3.973.18" - "@aws-sdk/credential-provider-process": "npm:^3.972.73" - "@aws-sdk/credential-provider-sso": "npm:^3.973.17" - "@aws-sdk/credential-provider-web-identity": "npm:^3.972.79" - "@aws-sdk/types": "npm:^3.974.6" - "@smithy/core": "npm:^3.35.2" - "@smithy/credential-provider-imds": "npm:^4.5.2" - "@smithy/types": "npm:^4.19.0" - tslib: "npm:^2.6.2" - checksum: 10c0/72452c2a98fd18dca3a70b2c851087fb9b39f598c715a6431c3293a0e8183b657ce13cf1ce0803b0192e12d4a65ed9962bb3b930083a9f8e94406abe0178a8f6 - languageName: node - linkType: hard - -"@aws-sdk/credential-provider-process@npm:^3.972.73": - version: 3.972.73 - resolution: "@aws-sdk/credential-provider-process@npm:3.972.73" - dependencies: - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/types": "npm:^3.974.6" - "@smithy/core": "npm:^3.35.2" - "@smithy/types": "npm:^4.19.0" - tslib: "npm:^2.6.2" - checksum: 10c0/b9e265616395409e69d7694d8e884490793fc959b9abd451fe6c424e09651d0c3dd24ea61c9d19250b50d28babb8aae8168ad4107b1b91c7f77344623ae9777d - languageName: node - linkType: hard - -"@aws-sdk/credential-provider-sso@npm:^3.973.17": - version: 3.973.17 - resolution: "@aws-sdk/credential-provider-sso@npm:3.973.17" - dependencies: - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/nested-clients": "npm:^3.997.47" - "@aws-sdk/token-providers": "npm:3.1149.0" - "@aws-sdk/types": "npm:^3.974.6" - "@smithy/core": "npm:^3.35.2" - "@smithy/types": "npm:^4.19.0" - tslib: "npm:^2.6.2" - checksum: 10c0/f658d3fc6cdbeb9d2c0848cdff726733668f1e5efad0f64e86bf24de5a46e619192fad2751d1426ff25bbe116d25c16522103ed2ecd540eac71515bb8a461c90 - languageName: node - linkType: hard - -"@aws-sdk/credential-provider-web-identity@npm:^3.972.79": - version: 3.972.79 - resolution: "@aws-sdk/credential-provider-web-identity@npm:3.972.79" - dependencies: - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/nested-clients": "npm:^3.997.47" - "@aws-sdk/types": "npm:^3.974.6" - "@smithy/core": "npm:^3.35.2" - "@smithy/types": "npm:^4.19.0" - tslib: "npm:^2.6.2" - checksum: 10c0/7110979f1597ceb83de74ddc41675ba67f9bd0d7cc44223ba730304ad3fead7b53463b09eab7065bd76ef5538ac7e57e844fb4d0afacfab917391cc42e4ae7cd - languageName: node - linkType: hard - -"@aws-sdk/crt-loader@npm:^3.972.77": - version: 3.972.77 - resolution: "@aws-sdk/crt-loader@npm:3.972.77" - dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" aws-crt: "npm:^1.31.0" tslib: "npm:^2.6.2" - checksum: 10c0/8acd2f37c9602323e3afd5d6bff50c6ada37eb94814e73d650e495cb34a8c86afe66222f187a7e5b2c35dfd9ace888933e183444a4238a6956f37c4bc8c45d5a + checksum: 10c0/6e94d030487c23e3b23e7b233f1a0a2df8e2ea298975da93bab2c66c0cfddd41d43bc1f33a6deef629791302f5ef9ae8f58de6ea5f9bb0eeff5365a1e7b2fe92 languageName: node linkType: hard -"@aws-sdk/lib-storage@npm:^3.1149.0": - version: 3.1149.0 - resolution: "@aws-sdk/lib-storage@npm:3.1149.0" +"@aws-sdk/lib-storage@npm:^3.1152.0": + version: 3.1152.0 + resolution: "@aws-sdk/lib-storage@npm:3.1152.0" dependencies: "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" @@ -222,30 +222,30 @@ __metadata: stream-browserify: "npm:3.0.0" tslib: "npm:^2.6.2" peerDependencies: - "@aws-sdk/client-s3": ^3.1149.0 - checksum: 10c0/078c2bb30dc438f422bb62c3df2098d8a6b586dda6c669b5c7d591244b1a5a098b44056c86ac5622e8a61164e1a28a9ba5c216b5f4b8f5111b5e28d31512e9a6 + "@aws-sdk/client-s3": ^3.1152.0 + checksum: 10c0/fcc60a9fbdc4a3cb9bd9a94e33a548d22b4ba19eccc234c4256ce30d91960d7e0a3357c1b0117a65f10b23324025aa9c2885c7e34ce96afe7dd90eafbf522aa2 languageName: node linkType: hard -"@aws-sdk/middleware-sdk-s3@npm:^3.972.78": - version: 3.972.78 - resolution: "@aws-sdk/middleware-sdk-s3@npm:3.972.78" +"@aws-sdk/middleware-sdk-s3@npm:^3.972.79": + version: 3.972.79 + resolution: "@aws-sdk/middleware-sdk-s3@npm:3.972.79" dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/signature-v4-multi-region": "npm:^3.996.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/691519cc985504c0bf1bb72c2cc3060737b22197def89c36f5380c981d0e9e68569f547ac7e06677dca7c6d63f64b618f8954bed50a44f482669c686bfcf44e5 + checksum: 10c0/bcf6a328c6039b5c09dc654b8dc3022e31164280feb76520e55e89a01c352b423901b7617134251cc29e6daa37c05e8b5ee030ad480491df6c679460a777ad20 languageName: node linkType: hard -"@aws-sdk/nested-clients@npm:^3.997.47": - version: 3.997.47 - resolution: "@aws-sdk/nested-clients@npm:3.997.47" +"@aws-sdk/nested-clients@npm:^3.997.48": + version: 3.997.48 + resolution: "@aws-sdk/nested-clients@npm:3.997.48" dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/signature-v4-multi-region": "npm:^3.996.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" @@ -253,51 +253,51 @@ __metadata: "@smithy/node-http-handler": "npm:^4.12.1" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/0787cefe45ff4eaae5bd950f93844596bd1eb68949ae1d317de63d2bb22c415f51778db3042dccc3ee28ddf597f967d3ffba0c51dd1c0bc8419e1a9152d395c8 + checksum: 10c0/61ec1e1c3eac42930052bdd1b315f10cde687fd43887b995b74a10d4cc6b60c06d6b2a22cf7f5102926a5473ed4b5a56a91677dc34ceb4777a09057d19391e48 languageName: node linkType: hard -"@aws-sdk/s3-presigned-post@npm:^3.1149.0": - version: 3.1149.0 - resolution: "@aws-sdk/s3-presigned-post@npm:3.1149.0" +"@aws-sdk/s3-presigned-post@npm:^3.1152.0": + version: 3.1152.0 + resolution: "@aws-sdk/s3-presigned-post@npm:3.1152.0" dependencies: - "@aws-sdk/client-s3": "npm:3.1149.0" - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/client-s3": "npm:3.1152.0" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/signature-v4": "npm:^5.7.4" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/5650c09df6bc79596194361765beb0325f35c51293a074767e12ef53e3273e1fc90248cfe2f4ea96813fff3905ca6dde949700c2b07dd62e395ae53fb0cf9844 + checksum: 10c0/5cd36049bcaae06321c14f530f2aeeb9df80a9ffa3f2ce04c7c6c6ab9b65a6604a6f7c9b5906d7c84000cf53a8cef65accec0660fb565a0c89d17223b799530e languageName: node linkType: hard -"@aws-sdk/s3-request-presigner@npm:^3.1149.0": - version: 3.1149.0 - resolution: "@aws-sdk/s3-request-presigner@npm:3.1149.0" +"@aws-sdk/s3-request-presigner@npm:^3.1152.0": + version: 3.1152.0 + resolution: "@aws-sdk/s3-request-presigner@npm:3.1152.0" dependencies: - "@aws-sdk/core": "npm:^3.978.2" + "@aws-sdk/core": "npm:^3.978.3" "@aws-sdk/signature-v4-multi-region": "npm:^3.996.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/f5f0762bde0e62247792d845365cb40f491d7ac6b3d87a9bfe0c85cb1c222b40b48df1873d21fb85c5251fd2ed88394c011cd41432f71825c90cd6a1b95c7c89 + checksum: 10c0/5687935d13d441116796c0be76fd7ac5dabfaba87da8e35cc4658e1c6f98e116fb5675f60dfd1af68dabe68a808691eb46a9d618c4a8d82a2c7ec9f77aa196f5 languageName: node linkType: hard -"@aws-sdk/signature-v4-crt@npm:^3.1149.0": - version: 3.1149.0 - resolution: "@aws-sdk/signature-v4-crt@npm:3.1149.0" +"@aws-sdk/signature-v4-crt@npm:^3.1152.0": + version: 3.1152.0 + resolution: "@aws-sdk/signature-v4-crt@npm:3.1152.0" dependencies: - "@aws-sdk/crt-loader": "npm:^3.972.77" + "@aws-sdk/crt-loader": "npm:^3.972.78" "@aws-sdk/signature-v4-multi-region": "npm:^3.996.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/signature-v4": "npm:^5.7.4" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/c76a967bd52c328a639ebcb79446da4d24e24830e4e2cfbc3a08df8766d4f58cc597142c604485a34c4027a843181634467b46801a31eb105ee2eb2a2987b0a8 + checksum: 10c0/d237a0e08cf3abea95682a58399db70e325e70326b743b8dded326280db20790a9c34e0fd7b9dcb1ada96cd499e3b1666c03fd92b69d68b34a6cf69e8c53a6c5 languageName: node linkType: hard @@ -313,17 +313,17 @@ __metadata: languageName: node linkType: hard -"@aws-sdk/token-providers@npm:3.1149.0": - version: 3.1149.0 - resolution: "@aws-sdk/token-providers@npm:3.1149.0" +"@aws-sdk/token-providers@npm:3.1150.0": + version: 3.1150.0 + resolution: "@aws-sdk/token-providers@npm:3.1150.0" dependencies: - "@aws-sdk/core": "npm:^3.978.2" - "@aws-sdk/nested-clients": "npm:^3.997.47" + "@aws-sdk/core": "npm:^3.978.3" + "@aws-sdk/nested-clients": "npm:^3.997.48" "@aws-sdk/types": "npm:^3.974.6" "@smithy/core": "npm:^3.35.2" "@smithy/types": "npm:^4.19.0" tslib: "npm:^2.6.2" - checksum: 10c0/e58ea6c4000a40f0ce785d7b4494a8f7a8abc76876fd8f3f20028621fe1d23ace999270f6cc40785966ec264f9b23d5a5dedf9fa7dd2fda0c07809a5e51f3fa2 + checksum: 10c0/c9a916dea1e2bdee9292ecf543e4c72a6cdb6e69b00569c78ee5f048095e05ac03b96fb49dae38cefcd8c7e4a1329b7f406d76cb32bb971249858dfca97ef3ad languageName: node linkType: hard @@ -14345,12 +14345,12 @@ __metadata: version: 0.0.0-use.local resolution: "outline@workspace:." dependencies: - "@aws-sdk/client-s3": "npm:^3.1149.0" + "@aws-sdk/client-s3": "npm:^3.1152.0" "@aws-sdk/cloudfront-signer": "npm:^3.1149.0" - "@aws-sdk/lib-storage": "npm:^3.1149.0" - "@aws-sdk/s3-presigned-post": "npm:^3.1149.0" - "@aws-sdk/s3-request-presigner": "npm:^3.1149.0" - "@aws-sdk/signature-v4-crt": "npm:^3.1149.0" + "@aws-sdk/lib-storage": "npm:^3.1152.0" + "@aws-sdk/s3-presigned-post": "npm:^3.1152.0" + "@aws-sdk/s3-request-presigner": "npm:^3.1152.0" + "@aws-sdk/signature-v4-crt": "npm:^3.1152.0" "@benrbray/prosemirror-math": "npm:^0.2.2" "@bull-board/api": "npm:^6.21.3" "@bull-board/koa": "npm:^6.21.3" From 878f41393d71b08b3adcc2da104cc58ea4185b0d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 08:28:41 -0400 Subject: [PATCH 11/38] fix: Cap signed URL redirect caching at guaranteed signature lifetime (#14169) --- .../api/attachments/attachments.test.ts | 16 ++++++++ server/routes/api/attachments/attachments.ts | 2 +- server/routes/api/emojis/emojis.ts | 2 +- server/storage/files/BaseStorage.test.ts | 37 +++++++++++++++++++ server/storage/files/BaseStorage.ts | 30 +++++++++++++-- 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/server/routes/api/attachments/attachments.test.ts b/server/routes/api/attachments/attachments.test.ts index b52058211e..b2e331809c 100644 --- a/server/routes/api/attachments/attachments.test.ts +++ b/server/routes/api/attachments/attachments.test.ts @@ -613,6 +613,22 @@ describe("#attachments.redirect", () => { expect(res.status).toEqual(302); }); + it("should not cache the redirect for longer than the signed URL is valid", async () => { + const user = await buildUser(); + const attachment = await buildAttachment({ + teamId: user.teamId, + userId: user.id, + }); + const res = await server.post("/api/attachments.redirect", user, { + body: { + id: attachment.id, + }, + redirect: "manual", + }); + expect(res.status).toEqual(302); + expect(res.headers.get("Cache-Control")).toEqual("max-age=150, immutable"); + }); + it("should return a redirect for the attachment if id supplied via query params", async () => { const user = await buildUser(); const attachment = await buildAttachment({ diff --git a/server/routes/api/attachments/attachments.ts b/server/routes/api/attachments/attachments.ts index 0fd3543efc..13b377ccba 100644 --- a/server/routes/api/attachments/attachments.ts +++ b/server/routes/api/attachments/attachments.ts @@ -335,7 +335,7 @@ const handleAttachmentsRedirect = async ( } else { ctx.set( "Cache-Control", - `max-age=${BaseStorage.defaultSignedUrlExpires}, immutable` + `max-age=${BaseStorage.getSignedUrlMinimumLifetime()}, immutable` ); ctx.redirect(await attachment.signedUrl); } diff --git a/server/routes/api/emojis/emojis.ts b/server/routes/api/emojis/emojis.ts index 3f9c1b275e..649074341f 100644 --- a/server/routes/api/emojis/emojis.ts +++ b/server/routes/api/emojis/emojis.ts @@ -105,7 +105,7 @@ router.get( ctx.set( "Cache-Control", - `max-age=${BaseStorage.defaultSignedUrlExpires}, immutable` + `max-age=${BaseStorage.getSignedUrlMinimumLifetime()}, immutable` ); ctx.redirect(await emoji.attachment.signedUrl); } diff --git a/server/storage/files/BaseStorage.test.ts b/server/storage/files/BaseStorage.test.ts index 24fa366841..47202fa9f5 100644 --- a/server/storage/files/BaseStorage.test.ts +++ b/server/storage/files/BaseStorage.test.ts @@ -129,6 +129,43 @@ describe("BaseStorage", () => { }); }); + describe("getSignedUrlMinimumLifetime", () => { + afterEach(() => { + vi.useRealTimers(); + }); + + it("should return half of the default lifetime", () => { + expect(BaseStorage.getSignedUrlMinimumLifetime()).toBe( + BaseStorage.defaultSignedUrlExpires / 2 + ); + }); + + it("should subtract the capped window from long lifetimes", () => { + expect(BaseStorage.getSignedUrlMinimumLifetime(Hour.seconds)).toBe( + Hour.seconds - BaseStorage.maxSigningWindow + ); + }); + + it("should return the full lifetime when it is too short to align", () => { + expect(BaseStorage.getSignedUrlMinimumLifetime(1)).toBe(1); + }); + + it("should not exceed the remaining lifetime at the end of a window", () => { + const expiresIn = BaseStorage.defaultSignedUrlExpires; + const now = new Date("2026-04-16T12:07:29.999Z"); + vi.useFakeTimers(); + vi.setSystemTime(now); + + const expiresAt = + MockStorage.signingDateFor(expiresIn).getTime() + expiresIn * 1000; + const remaining = (expiresAt - now.getTime()) / 1000; + + expect( + BaseStorage.getSignedUrlMinimumLifetime(expiresIn) + ).toBeLessThanOrEqual(remaining); + }); + }); + describe("getPresignedPut", () => { it("should return undefined from default implementation", async () => { const storage = new MockStorage(); diff --git a/server/storage/files/BaseStorage.ts b/server/storage/files/BaseStorage.ts index 650d65e50c..6b0dc74b49 100644 --- a/server/storage/files/BaseStorage.ts +++ b/server/storage/files/BaseStorage.ts @@ -31,6 +31,20 @@ export default abstract class BaseStorage { */ public static maxSigningWindow = 15 * Minute.seconds; + /** + * Returns the number of seconds that a signed URL is always valid for, after + * signing time alignment. Use this as the upper limit when a response that + * points to a signed URL is cached. + * + * @param expiresIn The number of seconds until the signed URL expires. + * @returns The minimum number of seconds the signed URL is valid for. + */ + public static getSignedUrlMinimumLifetime( + expiresIn = BaseStorage.defaultSignedUrlExpires + ): number { + return expiresIn - BaseStorage.getSigningWindow(expiresIn); + } + /** * Rounds the current time down to a fixed window so that repeated signatures * of the same file produce an identical URL. Without this every signature is @@ -46,10 +60,7 @@ export default abstract class BaseStorage { * @returns The timestamp to sign with. */ protected static getSigningDate(expiresIn: number): Date { - const window = Math.min( - BaseStorage.maxSigningWindow, - Math.floor(expiresIn / 2) - ); + const window = BaseStorage.getSigningWindow(expiresIn); if (window < 1) { return new Date(); @@ -387,4 +398,15 @@ export default abstract class BaseStorage { "image/gif", "image/webp", ]; + + /** + * Returns the number of seconds that the signing timestamp is held constant + * for a signed URL with the given lifetime. + * + * @param expiresIn The number of seconds until the signed URL expires. + * @returns The window in seconds, or 0 if the lifetime is too short to align. + */ + private static getSigningWindow(expiresIn: number): number { + return Math.min(BaseStorage.maxSigningWindow, Math.floor(expiresIn / 2)); + } } From 94276a743c69eb7371e1b6182357a69465e13f0b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 08:28:54 -0400 Subject: [PATCH 12/38] fix: Prevent duplicate heading anchor IDs (#14162) A heading whose text ends in a number could get the same slug as a numbered duplicate. Heading slugs now come from one HeadingSlugger that skips taken IDs, and the server section lookup counts nested headings like the editor does. --- server/models/helpers/DocumentHelper.test.ts | 48 ++++++++++++++++ server/models/helpers/DocumentHelper.tsx | 44 +++++++-------- shared/editor/lib/headingToSlug.test.ts | 58 ++++++++++++++++++++ shared/editor/lib/headingToSlug.ts | 52 ++++++++++++++---- shared/utils/ProsemirrorHelper.test.ts | 14 +++++ shared/utils/ProsemirrorHelper.ts | 40 ++------------ 6 files changed, 186 insertions(+), 70 deletions(-) create mode 100644 shared/editor/lib/headingToSlug.test.ts diff --git a/server/models/helpers/DocumentHelper.test.ts b/server/models/helpers/DocumentHelper.test.ts index b1ebdeaad1..e9e6f7fc7d 100644 --- a/server/models/helpers/DocumentHelper.test.ts +++ b/server/models/helpers/DocumentHelper.test.ts @@ -1369,6 +1369,54 @@ Second notes.` ); }); + it("should resolve anchors for a heading that ends in a number", async () => { + const document = await buildDocument({ + text: `## Setup + +First setup. + +## Setup + +Second setup. + +## Setup 1 + +Third setup.`, + }); + + expect(DocumentHelper.getAnchorContent(document, "h-setup-1")).toBe( + `## Setup + +Second setup.` + ); + expect(DocumentHelper.getAnchorContent(document, "h-setup-1-1")).toBe( + `## Setup 1 + +Third setup.` + ); + }); + + it("should count nested headings when numbering duplicates", async () => { + const document = await buildDocument({ + text: `> ## Notes +> +> Quoted notes. + +## Notes + +Top-level notes.`, + }); + + expect( + DocumentHelper.getAnchorContent(document, "h-notes") + ).toBeUndefined(); + expect(DocumentHelper.getAnchorContent(document, "h-notes-1")).toBe( + `## Notes + +Top-level notes.` + ); + }); + it("should return undefined when no heading matches", async () => { const document = await buildDocument({ text: `## Installation diff --git a/server/models/helpers/DocumentHelper.tsx b/server/models/helpers/DocumentHelper.tsx index 79ae2fe19c..0009e3e8e9 100644 --- a/server/models/helpers/DocumentHelper.tsx +++ b/server/models/helpers/DocumentHelper.tsx @@ -8,7 +8,7 @@ import { ChangesetHelper, type ExtendedChange, } from "@shared/editor/lib/ChangesetHelper"; -import headingToSlug from "@shared/editor/lib/headingToSlug"; +import { HeadingSlugger } from "@shared/editor/lib/headingToSlug"; import textBetween from "@shared/editor/lib/textBetween"; import { EditorStyleHelper } from "@shared/editor/styles/EditorStyleHelper"; import type { NavigationNode, ProsemirrorData } from "@shared/types"; @@ -267,40 +267,34 @@ export class DocumentHelper { const node = DocumentHelper.toProsemirror(document); - // Headings are always top-level nodes, so iterating the document's direct - // children is sufficient to locate the section. const children: Node[] = []; node.content.forEach((child) => children.push(child)); - const previouslySeen: Record = {}; + // Nested headings (eg. in tables) affect the numbering of duplicates, so + // every heading is visited, but a section can only start at a top-level one. + const slugger = new HeadingSlugger(); let startIndex = -1; - let level = 0; - - for (let i = 0; i < children.length; i++) { - const child = children[i]; - if (child.type.name !== "heading") { - continue; + node.forEach((child, _offset, index) => { + if (startIndex !== -1) { + return; } - - // Calculate the heading id using the same de-duplication logic as the - // editor so that anchors to repeated headings resolve correctly. - const slug = headingToSlug(child); - const headingId = - previouslySeen[slug] > 0 - ? headingToSlug(child, previouslySeen[slug]) - : slug; - previouslySeen[slug] = - previouslySeen[slug] !== undefined ? previouslySeen[slug] + 1 : 1; - - if (startIndex === -1 && headingId === id) { - startIndex = i; - level = child.attrs.level; + if (child.type.name === "heading") { + if (slugger.slug(child) === id) { + startIndex = index; + } + return; } - } + child.descendants((nested) => { + if (nested.type.name === "heading") { + slugger.slug(nested); + } + }); + }); if (startIndex === -1) { return undefined; } + const level = children[startIndex].attrs.level; const sectionNodes: Node[] = [children[startIndex]]; for (let i = startIndex + 1; i < children.length; i++) { diff --git a/shared/editor/lib/headingToSlug.test.ts b/shared/editor/lib/headingToSlug.test.ts new file mode 100644 index 0000000000..9172b1fe26 --- /dev/null +++ b/shared/editor/lib/headingToSlug.test.ts @@ -0,0 +1,58 @@ +import { Schema } from "prosemirror-model"; +import headingToSlug, { HeadingSlugger } from "./headingToSlug"; + +const schema = new Schema({ + nodes: { + doc: { content: "block+" }, + heading: { group: "block", content: "inline*" }, + text: { group: "inline" }, + }, +}); + +const heading = (text: string) => + schema.node("heading", null, [schema.text(text)]); + +const slugs = (...titles: string[]) => { + const slugger = new HeadingSlugger(); + return titles.map((title) => slugger.slug(heading(title))); +}; + +describe("headingToSlug", () => { + it("returns a prefixed slug", () => { + expect(headingToSlug(heading("Getting Started"))).toBe("h-getting-started"); + }); + + it("appends the index when it is not zero", () => { + expect(headingToSlug(heading("Notes"), 2)).toBe("h-notes-2"); + }); +}); + +describe("HeadingSlugger", () => { + it("returns the plain slug for unique headings", () => { + expect(slugs("One", "Two")).toEqual(["h-one", "h-two"]); + }); + + it("appends a suffix to repeated headings", () => { + expect(slugs("Notes", "Notes", "Notes")).toEqual([ + "h-notes", + "h-notes-1", + "h-notes-2", + ]); + }); + + it("does not reuse a slug when a heading ends in a number", () => { + expect(slugs("Setup", "Setup", "Setup 1")).toEqual([ + "h-setup", + "h-setup-1", + "h-setup-1-1", + ]); + }); + + it("skips a suffix already used by an earlier heading", () => { + expect(slugs("Setup 1", "Setup", "Setup")).toEqual([ + "h-setup-1", + "h-setup", + "h-setup-2", + ]); + }); +}); diff --git a/shared/editor/lib/headingToSlug.ts b/shared/editor/lib/headingToSlug.ts index bb64b1543e..8b1ae1b7c0 100644 --- a/shared/editor/lib/headingToSlug.ts +++ b/shared/editor/lib/headingToSlug.ts @@ -2,6 +2,48 @@ import { escape } from "es-toolkit/compat"; import type { Node } from "prosemirror-model"; import slugify from "slugify"; +// calculates a unique slug for this heading based on it's text and position +// in the document that is as stable as possible +export default function headingToSlug(node: Node, index = 0) { + const slugified = safeSlugify(node.textContent); + if (index === 0) { + return slugified; + } + return `${slugified}-${index}`; +} + +/** + * Assigns unique slugs to the headings of a document. Call `slug` for each + * heading in document order; repeated headings are given a numeric suffix. + */ +export class HeadingSlugger { + /** + * Returns a slug for the heading that is not already in use. + * + * @param node the heading node. + * @returns the unique slug. + */ + public slug(node: Node): string { + const base = headingToSlug(node); + let index = this.counts.get(base) ?? 0; + let id = headingToSlug(node, index); + + // A heading whose text ends in a number can match a suffixed duplicate. + while (this.used.has(id)) { + index += 1; + id = headingToSlug(node, index); + } + + this.counts.set(base, index + 1); + this.used.add(id); + return id; + } + + private counts = new Map(); + + private used = new Set(); +} + // Slugify, escape, and remove periods from headings so that they are // compatible with both url hashes AND dom ID's (querySelector does not like // ID's that begin with a number or a period, for example). @@ -13,13 +55,3 @@ function safeSlugify(text: string) { }) )}`; } - -// calculates a unique slug for this heading based on it's text and position -// in the document that is as stable as possible -export default function headingToSlug(node: Node, index = 0) { - const slugified = safeSlugify(node.textContent); - if (index === 0) { - return slugified; - } - return `${slugified}-${index}`; -} diff --git a/shared/utils/ProsemirrorHelper.test.ts b/shared/utils/ProsemirrorHelper.test.ts index 771837ded0..dd37799cd6 100644 --- a/shared/utils/ProsemirrorHelper.test.ts +++ b/shared/utils/ProsemirrorHelper.test.ts @@ -404,6 +404,20 @@ describe("ProsemirrorHelper", () => { }); describe("getHeadings", () => { + it("gives each heading a unique id", () => { + const node = doc( + heading("Setup", 2), + heading("Setup", 2), + heading("Setup 1", 2) + ); + + expect(ProsemirrorHelper.getHeadings(node).map((h) => h.id)).toEqual([ + "h-setup", + "h-setup-1", + "h-setup-1-1", + ]); + }); + it("marks headings that are nested inside tables", () => { const node = doc( heading("One", 1), diff --git a/shared/utils/ProsemirrorHelper.ts b/shared/utils/ProsemirrorHelper.ts index 3157d5de6e..537b2d0272 100644 --- a/shared/utils/ProsemirrorHelper.ts +++ b/shared/utils/ProsemirrorHelper.ts @@ -1,6 +1,6 @@ import type { Schema } from "prosemirror-model"; import type { Node } from "prosemirror-model"; -import headingToSlug from "../editor/lib/headingToSlug"; +import { HeadingSlugger } from "../editor/lib/headingToSlug"; import textBetween from "../editor/lib/textBetween"; import type { ProsemirrorData } from "../types"; import { hashString } from "./string"; @@ -207,31 +207,16 @@ export class ProsemirrorHelper { } private static getAnchorsForHeadingNodes(doc: Node): NodeAnchor[] { - const previouslySeen: Record = {}; + const slugger = new HeadingSlugger(); const anchors: NodeAnchor[] = []; doc.descendants((node, pos) => { if (node.type.name !== "heading") { return; } - // calculate the optimal id - const slug = headingToSlug(node); - let id = slug; - - // check if we've already used it, and if so how many times? - // Make the new id based on that number ensuring that we have - // unique ID's even when headings are identical - if (previouslySeen[slug] > 0) { - id = headingToSlug(node, previouslySeen[slug]); - } - - // record that we've seen this slug for the next loop - previouslySeen[slug] = - previouslySeen[slug] !== undefined ? previouslySeen[slug] + 1 : 1; - anchors.push({ pos, - id, + id: slugger.slug(node), className: EditorStyleHelper.headingPositionAnchor, }); }); @@ -498,7 +483,7 @@ export class ProsemirrorHelper { */ static getHeadings(doc: Node) { const headings: Heading[] = []; - const previouslySeen: Record = {}; + const slugger = new HeadingSlugger(); let tableEnd = 0; doc.descendants((node, pos) => { @@ -507,25 +492,10 @@ export class ProsemirrorHelper { tableEnd = Math.max(tableEnd, pos + node.nodeSize); } if (node.type.name === "heading") { - // calculate the optimal id - const id = headingToSlug(node); - let name = id; - - // check if we've already used it, and if so how many times? - // Make the new id based on that number ensuring that we have - // unique ID's even when headings are identical - if (previouslySeen[id] > 0) { - name = headingToSlug(node, previouslySeen[id]); - } - - // record that we've seen this id for the next loop - previouslySeen[id] = - previouslySeen[id] !== undefined ? previouslySeen[id] + 1 : 1; - headings.push({ title: ProsemirrorHelper.toPlainText(node), level: node.attrs.level, - id: name, + id: slugger.slug(node), inTable: pos < tableEnd, }); } From 4c9c45bcf002cebd29a8e4e55be59c197cb5fb7c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 08:30:38 -0400 Subject: [PATCH 13/38] fix: Mobile drawer bottom spacing and switch size (#14158) --- app/components/Switch.tsx | 42 +++++++++++++++++----------- app/components/primitives/Drawer.tsx | 4 ++- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/components/Switch.tsx b/app/components/Switch.tsx index a1bac9ff45..d24b9c97b5 100644 --- a/app/components/Switch.tsx +++ b/app/components/Switch.tsx @@ -2,6 +2,7 @@ import * as RadixSwitch from "@radix-ui/react-switch"; import { darken } from "polished"; import * as React from "react"; import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; import { s } from "@shared/styles"; import { LabelText } from "~/components/Input"; import Text from "~/components/Text"; @@ -67,7 +68,7 @@ function Switch({ className={label ? undefined : className} {...props} > - + ); @@ -128,15 +129,16 @@ const Label = styled.label<{ const HOVER_EXTRA = 3; -const StyledSwitchThumb = styled(RadixSwitch.Thumb)<{ - width: number; - height: number; -}>` +/** Minimum switch size on mobile, so that small switches stay usable by touch. */ +const MOBILE_MIN_WIDTH = 32; +const MOBILE_MIN_HEIGHT = 18; + +const StyledSwitchThumb = styled(RadixSwitch.Thumb)` display: block; - width: ${(props) => props.height - 8}px; - height: ${(props) => props.height - 8}px; + width: calc(var(--switch-height) - 8px); + height: calc(var(--switch-height) - 8px); background-color: white; - border-radius: ${(props) => (props.height - 8) / 2}px; + border-radius: calc((var(--switch-height) - 8px) / 2); transition: transform 0.2s, width 0.2s; @@ -144,11 +146,11 @@ const StyledSwitchThumb = styled(RadixSwitch.Thumb)<{ will-change: transform, width; &[data-state="checked"] { - transform: translateX(${(props) => props.width - props.height}px); + transform: translateX(calc(var(--switch-width) - var(--switch-height))); } [dir="rtl"] &[data-state="checked"] { - transform: translateX(${(props) => -(props.width - props.height)}px); + transform: translateX(calc(var(--switch-height) - var(--switch-width))); } `; @@ -156,17 +158,25 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{ width: number; height: number; }>` + --switch-width: ${(props) => Math.max(props.width, MOBILE_MIN_WIDTH)}px; + --switch-height: ${(props) => Math.max(props.height, MOBILE_MIN_HEIGHT)}px; + position: relative; - width: ${(props) => props.width}px; - height: ${(props) => props.height}px; + width: var(--switch-width); + height: var(--switch-height); background-color: ${(props) => props.theme.slate}; - border-radius: ${(props) => props.height}px; + border-radius: var(--switch-height); border: none; cursor: var(--pointer); transition: background-color 0.2s; padding: 0 4px; flex-shrink: 0; + ${(props) => breakpoint("tablet")` + --switch-width: ${props.width}px; + --switch-height: ${props.height}px; + `} + &:focus { box-shadow: 0 0 1px ${s("accent")}; outline: none; @@ -190,12 +200,12 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{ } &:hover:not(:disabled) ${StyledSwitchThumb} { - width: ${(props) => props.height - 8 + HOVER_EXTRA}px; + width: calc(var(--switch-height) - 8px + ${HOVER_EXTRA}px); } &:hover:not(:disabled)[data-state="checked"] ${StyledSwitchThumb} { transform: translateX( - ${(props) => props.width - props.height - HOVER_EXTRA}px + calc(var(--switch-width) - var(--switch-height) - ${HOVER_EXTRA}px) ); } @@ -203,7 +213,7 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{ &:hover:not(:disabled)[data-state="checked"] ${StyledSwitchThumb} { transform: translateX( - ${(props) => -(props.width - props.height - HOVER_EXTRA)}px + calc(var(--switch-height) - var(--switch-width) + ${HOVER_EXTRA}px) ); } `; diff --git a/app/components/primitives/Drawer.tsx b/app/components/primitives/Drawer.tsx index f1eda8be44..073e23a92c 100644 --- a/app/components/primitives/Drawer.tsx +++ b/app/components/primitives/Drawer.tsx @@ -108,7 +108,9 @@ const StyledContent = styled(m.div)` const StyledInnerContent = styled(Flex)` padding: 6px; - padding-bottom: calc(6px + var(--sab, 0px)); + + /* The safe area inset is zero unless the viewport uses viewport-fit=cover. */ + padding-bottom: max(24px, calc(6px + var(--sab, 0px))); height: 100%; `; From 6ab6671ffd0ee9f6632169862aaafdadd01ce3d1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 08:31:47 -0400 Subject: [PATCH 14/38] chore: Incremental server compile and restart in dev:backend (#14168) * chore: Incremental server compile and restart in dev:backend Replace nodemon with a watch mode in build.js that compiles only the changed file and restarts the server itself, and call swc directly instead of through yarn. * fix: Sync copied assets and directory moves, recover from failed builds in watch mode --- build.js | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 +- yarn.lock | 129 ++--------------------------- 3 files changed, 235 insertions(+), 127 deletions(-) diff --git a/build.js b/build.js index 09d238cd4f..1b7361441d 100755 --- a/build.js +++ b/build.js @@ -1,8 +1,18 @@ /* oxlint-disable no-console */ /* oxlint-disable typescript/no-require-imports */ /* oxlint-disable no-undef */ -const { exec } = require("child_process"); -const { readdirSync } = require("fs"); +const { exec, spawn } = require("child_process"); +const { + copyFileSync, + existsSync, + mkdirSync, + readdirSync, + rmSync, + statSync, + watch, +} = require("fs"); +const { writeFile } = require("fs/promises"); +const path = require("path"); const getDirectories = (source) => readdirSync(source, { withFileTypes: true }) @@ -42,7 +52,7 @@ async function build() { // startup costs far more than the compilation itself. console.log("Compiling…"); await execAsync( - `yarn swc ./server ./shared ./plugins -d ./build --extensions .ts,.tsx --ignore "**/*.test.ts,**/*.test.tsx,**/__mocks__/**,plugins/*/client/**" --quiet` + `node_modules/.bin/swc ./server ./shared ./plugins -d ./build --extensions .ts,.tsx --ignore "**/*.test.ts,**/*.test.tsx,**/__mocks__/**,plugins/*/client/**" --quiet` ); // Copy static files @@ -69,4 +79,216 @@ async function build() { console.log("Done!"); } -void build(); +/** + * Whether a source file is compiled into the server build. + * @param file {string} path relative to the project root. + * @return {boolean} + */ +function isCompiled(file) { + return ( + /\.tsx?$/.test(file) && + !/\.test\.tsx?$/.test(file) && + !file.split(path.sep).includes("__mocks__") && + !/^plugins[\\/][^\\/]+[\\/]client[\\/]/.test(file) + ); +} + +/** + * The build output path of a source file. + * @param file {string} path relative to the project root. + * @return {string | undefined} the output path, or undefined if the file is not + * part of the build. + */ +function getDest(file) { + if (isCompiled(file)) { + return path.join("build", file.replace(/\.tsx?$/, ".js")); + } + if ( + /^plugins[\\/][^\\/]+[\\/]plugin\.json$/.test(file) || + /^shared[\\/]i18n[\\/]locales[\\/]/.test(file) + ) { + return path.join("build", file); + } + return undefined; +} + +/** + * Builds, then watches the source directories and updates the output of each + * changed, added or removed file. A full build runs again after a failed one. + * When a command is passed it is run, and restarted after each change that + * affects the server. + * @param command {string[]} the command and arguments to run, may be empty. + */ +async function watchSources(command) { + const swc = require("@swc/core"); + const timers = new Map(); + let child; + let restartTimer; + let isBuilt = false; + let isBuilding = false; + let isBuildPending = false; + + const startServer = () => { + // Run in a new process group so the forked service processes are stopped + // together with the master. + child = spawn(command[0], command.slice(1), { + stdio: "inherit", + detached: true, + }); + child.once("exit", (code, signal) => { + child = undefined; + if (signal !== "SIGKILL") { + console.log( + `Server exited with ${signal ?? code}, waiting for changes…` + ); + } + }); + }; + + const stopServer = (callback) => { + if (!child) { + callback?.(); + return; + } + if (callback) { + child.once("exit", callback); + } + process.kill(-child.pid, "SIGKILL"); + }; + + const restartServer = () => { + if (!command.length || !isBuilt) { + return; + } + clearTimeout(restartTimer); + restartTimer = setTimeout(() => { + console.log("Restarting…"); + stopServer(startServer); + }, 100); + }; + + const fullBuild = async () => { + if (isBuilding) { + isBuildPending = true; + return; + } + + isBuilding = true; + try { + await build(); + isBuilt = true; + } catch (err) { + console.error(err.message ?? err); + console.log("Build failed, waiting for changes…"); + } finally { + isBuilding = false; + } + + if (isBuildPending) { + isBuildPending = false; + await fullBuild(); + } else if (isBuilt && command.length) { + startServer(); + } + }; + + const updateFile = async (file) => { + const dest = getDest(file); + if (!dest) { + return false; + } + + if (!isCompiled(file)) { + mkdirSync(path.dirname(dest), { recursive: true }); + copyFileSync(file, dest); + console.log(`Copied ${file}`); + return true; + } + + const start = performance.now(); + try { + const { code } = await swc.transformFile(file); + mkdirSync(path.dirname(dest), { recursive: true }); + await writeFile(dest, code); + console.log( + `Compiled ${file} (${(performance.now() - start).toFixed(1)}ms)` + ); + return true; + } catch (err) { + console.error(err.message ?? err); + return false; + } + }; + + const handleChange = async (file) => { + const stats = statSync(file, { throwIfNoEntry: false }); + let isChanged = false; + + if (!stats) { + // The path of a removed directory maps directly to its output. + const dest = getDest(file) ?? path.join("build", file); + if (existsSync(dest)) { + rmSync(dest, { recursive: true, force: true }); + isChanged = true; + } + } else if (stats.isDirectory()) { + // A directory that was moved in does not emit events for its files. + for (const entry of readdirSync(file, { recursive: true })) { + isChanged = (await updateFile(path.join(file, entry))) || isChanged; + } + } else { + isChanged = await updateFile(file); + } + + // The editor and components are mostly used by the client, so changes + // there are picked up on the next restart. + if (isChanged && !/^shared[\\/](editor|components)[\\/]/.test(file)) { + restartServer(); + } + }; + + for (const dir of ["server", "shared", "plugins"]) { + watch(dir, { recursive: true }, (_event, filename) => { + if (!filename) { + return; + } + if (!isBuilt) { + void fullBuild(); + return; + } + + // Editors can emit several events for one save, so debounce each file. + const file = path.join(dir, filename); + clearTimeout(timers.get(file)); + timers.set( + file, + setTimeout(() => { + timers.delete(file); + void handleChange(file); + }, 50) + ); + }); + } + + watch(".", (_event, filename) => { + if (/^\.env(\.local|\.development)?$/.test(filename ?? "")) { + restartServer(); + } + }); + + for (const signal of ["SIGINT", "SIGTERM"]) { + process.once(signal, () => stopServer(() => process.exit(0))); + } + + await fullBuild(); + console.log("Watching for changes…"); +} + +if (process.argv.includes("--watch")) { + // Arguments after "--" are the command to run, e.g. the server. + const separator = process.argv.indexOf("--"); + const command = separator === -1 ? [] : process.argv.slice(separator + 1); + void watchSources(command); +} else { + void build(); +} diff --git a/package.json b/package.json index cbabb9bc21..776aef6971 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build": "yarn clean && yarn vite:build && yarn build:i18n && yarn build:server", "start": "node ./build/server/index.js", "dev": "NODE_ENV=development yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=cron,collaboration,websockets,admin,web,worker\"", - "dev:backend": "NODE_ENV=development nodemon --quiet --exec \"yarn build:server && yarn dev\" -e js,ts,tsx --watch server --watch shared --watch plugins --watch .env --watch .env.local --watch .env.development --ignore \"shared/components/**/*.tsx?\" --ignore \"plugins/client/**/*.tsx?\" --ignore \"**/*.test.ts\" --ignore data/ --ignore build/ --ignore app/ --ignore \"shared/editor/**\" --ignore server/migrations", + "dev:backend": "NODE_ENV=development node ./build.js --watch -- node --inspect=0.0.0.0 build/server/index.js --services=cron,collaboration,websockets,admin,web,worker", "dev:watch": "NODE_ENV=development yarn concurrently -n backend,frontend \"yarn dev:backend\" \"yarn vite:dev\"", "lint": "oxlint --type-aware app server shared plugins", "lint:changed": "git diff --name-only --diff-filter=ACMRTUXB | grep -E '\\.(js|jsx|ts|tsx)$' | xargs -r oxlint", @@ -345,7 +345,6 @@ "ioredis-mock": "^8.13.1", "lint-staged": "^16.4.0", "msw": "^2.15.0", - "nodemon": "^3.1.14", "oxfmt": "0.72.0", "oxlint": "1.81.0", "oxlint-tsgolint": "7.0.2001", diff --git a/yarn.lock b/yarn.lock index 1ab8dbfa16..bbe8942fd2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7468,7 +7468,7 @@ __metadata: languageName: node linkType: hard -"anymatch@npm:^3.1.3, anymatch@npm:~3.1.2": +"anymatch@npm:^3.1.3": version: 3.1.3 resolution: "anymatch@npm:3.1.3" dependencies: @@ -7772,13 +7772,6 @@ __metadata: languageName: node linkType: hard -"binary-extensions@npm:^2.0.0": - version: 2.3.0 - resolution: "binary-extensions@npm:2.3.0" - checksum: 10c0/75a59cafc10fb12a11d510e77110c6c7ae3f4ca22463d52487709ca7f18f69d886aa387557cc9864fbdb10153d0bdb4caacabf11541f55e89ed6e18d12ece2b5 - languageName: node - linkType: hard - "binary-version-check@npm:^6.1.0": version: 6.1.0 resolution: "binary-version-check@npm:6.1.0" @@ -7918,7 +7911,7 @@ __metadata: languageName: node linkType: hard -"braces@npm:^3.0.3, braces@npm:~3.0.2": +"braces@npm:^3.0.3": version: 3.0.3 resolution: "braces@npm:3.0.3" dependencies: @@ -8247,25 +8240,6 @@ __metadata: languageName: node linkType: hard -"chokidar@npm:^3.5.2": - version: 3.6.0 - resolution: "chokidar@npm:3.6.0" - dependencies: - anymatch: "npm:~3.1.2" - braces: "npm:~3.0.2" - fsevents: "npm:~2.3.2" - glob-parent: "npm:~5.1.2" - is-binary-path: "npm:~2.1.0" - is-glob: "npm:~4.0.1" - normalize-path: "npm:~3.0.0" - readdirp: "npm:~3.6.0" - dependenciesMeta: - fsevents: - optional: true - checksum: 10c0/8361dcd013f2ddbe260eacb1f3cb2f2c6f2b0ad118708a343a5ed8158941a39cb8fb1d272e0f389712e74ee90ce8ba864eece9e0e62b9705cb468a2f6d917462 - languageName: node - linkType: hard - "chownr@npm:^3.0.0": version: 3.0.0 resolution: "chownr@npm:3.0.0" @@ -9068,7 +9042,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:4.4.3, debug@npm:^4, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.4, debug@npm:^4.3.5, debug@npm:^4.3.6, debug@npm:^4.4.0, debug@npm:^4.4.3, debug@npm:~4.4.1": +"debug@npm:4, debug@npm:4.4.3, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.4, debug@npm:^4.3.5, debug@npm:^4.3.6, debug@npm:^4.4.0, debug@npm:^4.4.3, debug@npm:~4.4.1": version: 4.4.3 resolution: "debug@npm:4.4.3" dependencies: @@ -10882,15 +10856,6 @@ __metadata: languageName: node linkType: hard -"glob-parent@npm:~5.1.2": - version: 5.1.2 - resolution: "glob-parent@npm:5.1.2" - dependencies: - is-glob: "npm:^4.0.1" - checksum: 10c0/cab87638e2112bee3f839ef5f6e0765057163d39c66be8ec1602f3823da4692297ad4e972de876ea17c44d652978638d2fd583c6713d0eb6591706825020c9ee - languageName: node - linkType: hard - "glob-stream@npm:^8.0.3": version: 8.0.3 resolution: "glob-stream@npm:8.0.3" @@ -11514,13 +11479,6 @@ __metadata: languageName: node linkType: hard -"ignore-by-default@npm:^1.0.1": - version: 1.0.1 - resolution: "ignore-by-default@npm:1.0.1" - checksum: 10c0/9ab6e70e80f7cc12735def7ecb5527cfa56ab4e1152cd64d294522827f2dcf1f6d85531241537dc3713544e88dd888f65cb3c49c7b2cddb9009087c75274e533 - languageName: node - linkType: hard - "ignore@npm:^5.3.0": version: 5.3.2 resolution: "ignore@npm:5.3.2" @@ -11772,15 +11730,6 @@ __metadata: languageName: node linkType: hard -"is-binary-path@npm:~2.1.0": - version: 2.1.0 - resolution: "is-binary-path@npm:2.1.0" - dependencies: - binary-extensions: "npm:^2.0.0" - checksum: 10c0/a16eaee59ae2b315ba36fad5c5dcaf8e49c3e27318f8ab8fa3cdb8772bf559c8d1ba750a589c2ccb096113bb64497084361a25960899cb6172a6925ab6123d38 - languageName: node - linkType: hard - "is-blob@npm:^2.1.0": version: 2.1.0 resolution: "is-blob@npm:2.1.0" @@ -11910,7 +11859,7 @@ __metadata: languageName: node linkType: hard -"is-glob@npm:^4.0.1, is-glob@npm:^4.0.3, is-glob@npm:~4.0.1": +"is-glob@npm:^4.0.3": version: 4.0.3 resolution: "is-glob@npm:4.0.3" dependencies: @@ -13522,7 +13471,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^10.1.1, minimatch@npm:^10.2.1, minimatch@npm:^10.2.2": +"minimatch@npm:^10.1.1, minimatch@npm:^10.2.2": version: 10.2.5 resolution: "minimatch@npm:10.2.5" dependencies: @@ -14028,26 +13977,6 @@ __metadata: languageName: node linkType: hard -"nodemon@npm:^3.1.14": - version: 3.1.14 - resolution: "nodemon@npm:3.1.14" - dependencies: - chokidar: "npm:^3.5.2" - debug: "npm:^4" - ignore-by-default: "npm:^1.0.1" - minimatch: "npm:^10.2.1" - pstree.remy: "npm:^1.1.8" - semver: "npm:^7.5.3" - simple-update-notifier: "npm:^2.0.0" - supports-color: "npm:^5.5.0" - touch: "npm:^3.1.0" - undefsafe: "npm:^2.0.5" - bin: - nodemon: bin/nodemon.js - checksum: 10c0/074f2056051a148ad11cda0d6c3f905bdef93a878792385f16e1dff0c63dcf07f23ebe1ab3763dca7314d0266e12129f066070545d817a205ee050a22eff50b0 - languageName: node - linkType: hard - "nopt@npm:^7.2.1": version: 7.2.1 resolution: "nopt@npm:7.2.1" @@ -14070,7 +13999,7 @@ __metadata: languageName: node linkType: hard -"normalize-path@npm:3.0.0, normalize-path@npm:^3.0.0, normalize-path@npm:~3.0.0": +"normalize-path@npm:3.0.0, normalize-path@npm:^3.0.0": version: 3.0.0 resolution: "normalize-path@npm:3.0.0" checksum: 10c0/e008c8142bcc335b5e38cf0d63cfd39d6cf2d97480af9abdbe9a439221fd4d749763bab492a8ee708ce7a194bb00c9da6d0a115018672310850489137b3da046 @@ -14543,7 +14472,6 @@ __metadata: natural-sort: "npm:^1.0.0" node-fetch: "npm:2.7.0" nodemailer: "npm:^10.0.9" - nodemon: "npm:^3.1.14" octokit: "npm:^5.0.5" outline-icons: "npm:^4.6.0" oxfmt: "npm:0.72.0" @@ -15440,7 +15368,7 @@ __metadata: languageName: node linkType: hard -"picomatch@npm:^2.0.4, picomatch@npm:^2.2.1, picomatch@npm:^2.3.1": +"picomatch@npm:^2.0.4, picomatch@npm:^2.3.1": version: 2.3.2 resolution: "picomatch@npm:2.3.2" checksum: 10c0/a554d1709e59be97d1acb9eaedbbc700a5c03dbd4579807baed95100b00420bc729335440ef15004ae2378984e2487a7c1cebd743cfdb72b6fa9ab69223c0d61 @@ -15903,13 +15831,6 @@ __metadata: languageName: node linkType: hard -"pstree.remy@npm:^1.1.8": - version: 1.1.8 - resolution: "pstree.remy@npm:1.1.8" - checksum: 10c0/30f78c88ce6393cb3f7834216cb6e282eb83c92ccb227430d4590298ab2811bc4a4745f850a27c5178e79a8f3e316591de0fec87abc19da648c2b3c6eb766d14 - languageName: node - linkType: hard - "pump@npm:^3.0.0": version: 3.0.3 resolution: "pump@npm:3.0.3" @@ -16379,15 +16300,6 @@ __metadata: languageName: node linkType: hard -"readdirp@npm:~3.6.0": - version: 3.6.0 - resolution: "readdirp@npm:3.6.0" - dependencies: - picomatch: "npm:^2.2.1" - checksum: 10c0/6fa848cf63d1b82ab4e985f4cf72bd55b7dcfd8e0a376905804e48c3634b7e749170940ba77b32804d5fe93b3cc521aa95a8d7e7d725f830da6d93f3669ce66b - languageName: node - linkType: hard - "readline-sync@npm:^1.4.10": version: 1.4.10 resolution: "readline-sync@npm:1.4.10" @@ -17442,15 +17354,6 @@ __metadata: languageName: node linkType: hard -"simple-update-notifier@npm:^2.0.0": - version: 2.0.0 - resolution: "simple-update-notifier@npm:2.0.0" - dependencies: - semver: "npm:^7.5.3" - checksum: 10c0/2a00bd03bfbcbf8a737c47ab230d7920f8bfb92d1159d421bdd194479f6d01ebc995d13fbe13d45dace23066a78a3dc6642999b4e3b38b847e6664191575b20c - languageName: node - linkType: hard - "sirv@npm:^3.0.2": version: 3.0.2 resolution: "sirv@npm:3.0.2" @@ -18113,7 +18016,7 @@ __metadata: languageName: node linkType: hard -"supports-color@npm:^5.3.0, supports-color@npm:^5.5.0": +"supports-color@npm:^5.3.0": version: 5.5.0 resolution: "supports-color@npm:5.5.0" dependencies: @@ -18484,15 +18387,6 @@ __metadata: languageName: node linkType: hard -"touch@npm:^3.1.0": - version: 3.1.1 - resolution: "touch@npm:3.1.1" - bin: - nodetouch: bin/nodetouch.js - checksum: 10c0/d2e4d269a42c846a22a29065b9af0b263de58effc85a1764bb7a2e8fc4b47700e9e2fcbd7eb1f5bffbb7c73d860f93600cef282b93ddac8f0b62321cb498b36e - languageName: node - linkType: hard - "tough-cookie@npm:^4.1.2": version: 4.1.4 resolution: "tough-cookie@npm:4.1.4" @@ -18974,13 +18868,6 @@ __metadata: languageName: node linkType: hard -"undefsafe@npm:^2.0.5": - version: 2.0.5 - resolution: "undefsafe@npm:2.0.5" - checksum: 10c0/96c0466a5fbf395917974a921d5d4eee67bca4b30d3a31ce7e621e0228c479cf893e783a109af6e14329b52fe2f0cb4108665fad2b87b0018c0df6ac771261d5 - languageName: node - linkType: hard - "underscore.string@npm:~3.3.6": version: 3.3.6 resolution: "underscore.string@npm:3.3.6" From c963528941ba7e4f80462c12c3724fdb2fef4dad Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 08:32:16 -0400 Subject: [PATCH 15/38] feat: List all contributors in document update emails (#14157) * feat: List all contributors in document update emails * fix: Stable collaborator order, plural wording, and legacy email jobs --- server/emails/templates/BaseEmail.tsx | 21 +++- .../DocumentPublishedOrUpdatedEmail.test.ts | 95 +++++++++++++++++++ .../DocumentPublishedOrUpdatedEmail.tsx | 83 +++++++++++----- server/models/Revision.ts | 9 +- server/queues/processors/EmailsProcessor.ts | 1 + shared/i18n/locales/en_US/translation.json | 3 + tsconfig.json | 2 +- 7 files changed, 187 insertions(+), 27 deletions(-) create mode 100644 server/emails/templates/DocumentPublishedOrUpdatedEmail.test.ts diff --git a/server/emails/templates/BaseEmail.tsx b/server/emails/templates/BaseEmail.tsx index 93ba96b963..a8a9d660ff 100644 --- a/server/emails/templates/BaseEmail.tsx +++ b/server/emails/templates/BaseEmail.tsx @@ -234,6 +234,11 @@ export default abstract class BaseEmail< return ; } + /** The receiving user's language in BCP47 format. */ + private get locale() { + return unicodeCLDRtoBCP47(this.props.language ?? env.DEFAULT_LANGUAGE); + } + /** * Translate a string using the receiving user's language preference. * @@ -244,10 +249,24 @@ export default abstract class BaseEmail< protected t(key: string, options?: Record): string { return i18nT(key, { ...options, - lng: unicodeCLDRtoBCP47(this.props.language ?? env.DEFAULT_LANGUAGE), + lng: this.locale, }) as string; } + /** + * Join a list of items into a single string using the receiving user's + * language preference, e.g. "A, B and C". + * + * @param items The items to join. + * @returns The joined string. + */ + protected formatList(items: string[]): string { + return new Intl.ListFormat(this.locale, { + style: "long", + type: "conjunction", + }).format(items); + } + /** * Returns the subject of the email. * diff --git a/server/emails/templates/DocumentPublishedOrUpdatedEmail.test.ts b/server/emails/templates/DocumentPublishedOrUpdatedEmail.test.ts new file mode 100644 index 0000000000..490ac58c1c --- /dev/null +++ b/server/emails/templates/DocumentPublishedOrUpdatedEmail.test.ts @@ -0,0 +1,95 @@ +import { NotificationEventType } from "@shared/types"; +import { createContext } from "@server/context"; +import mailer from "@server/emails/mailer"; +import env from "@server/env"; +import { Revision } from "@server/models"; +import { buildDocument, buildTeam, buildUser } from "@server/test/factories"; +import { initI18n } from "@server/utils/i18n"; +import DocumentPublishedOrUpdatedEmail from "./DocumentPublishedOrUpdatedEmail"; + +describe("DocumentPublishedOrUpdatedEmail", () => { + beforeAll(async () => { + await initI18n(); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + async function sendEmail( + eventType: + | NotificationEventType.PublishDocument + | NotificationEventType.UpdateDocument, + collaboratorCount: number, + { withActorId = true } = {} + ) { + const spy = vi.spyOn(mailer, "sendMail").mockResolvedValue(undefined); + const team = await buildTeam(); + const [actor, ...others] = await Promise.all( + Array.from({ length: collaboratorCount }, (_, index) => + buildUser({ teamId: team.id, name: `User ${index + 1}` }) + ) + ); + const recipient = await buildUser({ teamId: team.id }); + const document = await buildDocument({ + teamId: team.id, + userId: actor.id, + lastModifiedById: actor.id, + }); + const revision = await Revision.createFromDocument( + createContext({ user: actor }), + document, + [actor.id, ...others.map((user) => user.id)] + ); + + await new DocumentPublishedOrUpdatedEmail({ + to: recipient.email, + userId: recipient.id, + eventType, + revisionId: revision.id, + documentId: document.id, + teamUrl: team.url, + actorId: withActorId ? actor.id : undefined, + actorName: actor.name, + }).send(); + + expect(spy).toHaveBeenCalledTimes(1); + return spy.mock.calls[0][0]; + } + + it("should name the actor when they are the only collaborator", async () => { + const mail = await sendEmail(NotificationEventType.UpdateDocument, 1); + + expect(mail.previewText).toEqual("User 1 updated a document"); + expect(mail.text).toContain("User 1 updated the document"); + }); + + it("should list every collaborator on an update", async () => { + const mail = await sendEmail(NotificationEventType.UpdateDocument, 3); + + expect(mail.previewText).toEqual( + "User 1, User 2, and User 3 updated a document" + ); + expect(mail.text).toContain("User 1, User 2, and User 3 updated the"); + }); + + it("should send from the actor only", async () => { + const mail = await sendEmail(NotificationEventType.UpdateDocument, 2); + + expect(mail.from.name).toEqual(`User 1 via ${env.APP_NAME}`); + }); + + it("should name only the actor on publish", async () => { + const mail = await sendEmail(NotificationEventType.PublishDocument, 2); + + expect(mail.previewText).toEqual("User 1 published a document"); + }); + + it("should name only the actor when the actor ID is missing", async () => { + const mail = await sendEmail(NotificationEventType.UpdateDocument, 2, { + withActorId: false, + }); + + expect(mail.previewText).toEqual("User 1 updated a document"); + }); +}); diff --git a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx index 3d1ac5068d..4bf61e52b0 100644 --- a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx +++ b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx @@ -24,6 +24,7 @@ type InputProps = EmailProps & { userId: string; documentId: string; revisionId?: string; + actorId?: string; actorName: string; eventType: | NotificationEventType.PublishDocument @@ -36,6 +37,10 @@ type BeforeSend = { collection: Collection | null; unsubscribeUrl: string; body: string | undefined; + /** Names of everyone who contributed to the revision, actor first. */ + actorNames: string; + /** The number of contributors named in actorNames. */ + actorCount: number; }; type Props = InputProps & BeforeSend; @@ -61,32 +66,28 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< return false; } - const [collection, team] = await Promise.all([ + const [collection, team, revision] = await Promise.all([ document.$get("collection"), document.$get("team"), + revisionId ? Revision.findByPk(revisionId) : null, ]); let body; - if (revisionId && team?.getPreference(TeamPreference.PreviewsInEmails)) { + if (revision && team?.getPreference(TeamPreference.PreviewsInEmails)) { body = await CacheHelper.getDataOrSet( - `diff:${revisionId}`, + `diff:${revision.id}`, async () => { // generate the diff html for the email - const revision = await Revision.findByPk(revisionId); + const before = await revision.before(); + const content = await DocumentHelper.toEmailDiff(before, revision, { + includeTitle: false, + centered: false, + signedUrls: 4 * Day.seconds, + baseUrl: props.teamUrl, + }); - if (revision) { - const before = await revision.before(); - const content = await DocumentHelper.toEmailDiff(before, revision, { - includeTitle: false, - centered: false, - signedUrls: 4 * Day.seconds, - baseUrl: props.teamUrl, - }); - - // inline all css so that it works in as many email providers as possible. - return content ? await HTMLHelper.inlineCSS(content) : undefined; - } - return; + // inline all css so that it works in as many email providers as possible. + return content ? await HTMLHelper.inlineCSS(content) : undefined; }, 30, 10000 @@ -97,6 +98,7 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< document, collection, body, + ...(await this.actorNames(props, revision)), unsubscribeUrl: this.unsubscribeUrl(props), }; } @@ -123,9 +125,10 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< }); } - protected preview({ actorName, eventType }: Props): string { + protected preview({ actorNames, actorCount, eventType }: Props): string { return this.t("{{ actorName }} {{ eventName }} a document", { - actorName, + actorName: actorNames, + count: actorCount, eventName: this.eventName(eventType), }); } @@ -144,7 +147,8 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< } protected renderAsText({ - actorName, + actorNames, + actorCount, teamUrl, document, collection, @@ -155,7 +159,7 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail< return ` ${this.t("“{{ documentTitle }}” {{ eventName }}", { documentTitle: document.displayTitle, eventName })} -${this.t("{{ actorName }} {{ eventName }} the document “{{ documentTitle }}”", { actorName, eventName, documentTitle: document.displayTitle })}${ +${this.t("{{ actorName }} {{ eventName }} the document “{{ documentTitle }}”", { actorName: actorNames, count: actorCount, eventName, documentTitle: document.displayTitle })}${ collection?.name ? `, ${this.t("in the {{ collectionName }} collection", { collectionName: collection.name })}` : "" @@ -168,7 +172,8 @@ ${this.t("Open Document")}: ${teamUrl}${document.url} protected render(props: Props) { const { document, - actorName, + actorNames, + actorCount, collection, eventType, teamUrl, @@ -194,7 +199,8 @@ ${this.t("Open Document")}: ${teamUrl}${document.url}

{this.t("{{ actorName }} {{ eventName }} the document", { - actorName, + actorName: actorNames, + count: actorCount, eventName, })}{" "} {document.displayTitle} @@ -240,4 +246,35 @@ ${this.t("Open Document")}: ${teamUrl}${document.url} ); } + + /** + * Returns the names of everyone who contributed to an update, with the actor + * first, joined into a single string. + * + * @param props The email props. + * @param revision The revision that triggered the email, if any. + * @returns The joined names and the number of contributors. + */ + private async actorNames( + { actorId, actorName, eventType }: InputProps, + revision: Revision | null + ) { + if ( + !actorId || + !revision || + eventType !== NotificationEventType.UpdateDocument + ) { + return { actorNames: actorName, actorCount: 1 }; + } + + const collaborators = await revision.collaborators; + const names = [ + actorName, + ...collaborators + .filter((user) => user && user.id !== actorId) + .map((user) => user.name), + ]; + + return { actorNames: this.formatList(names), actorCount: names.length }; + } } diff --git a/server/models/Revision.ts b/server/models/Revision.ts index c81fc03017..a724532e52 100644 --- a/server/models/Revision.ts +++ b/server/models/Revision.ts @@ -1,4 +1,5 @@ import type { InferAttributes, InferCreationAttributes } from "sequelize"; +import { sortBy } from "es-toolkit/compat"; import { Op } from "sequelize"; import { AllowNull, @@ -123,7 +124,8 @@ class Revision extends ParanoidModel< collaboratorIds: string[]; /** - * Get the collaborators for this revision. + * Get the collaborators for this revision, with the author first and the + * others in the order they were recorded. */ get collaborators() { const otherCollaboratorIds = (this.collaboratorIds ?? []).filter( @@ -141,7 +143,10 @@ class Revision extends ParanoidModel< }, }, paranoid: false, - }).then((others) => [this.user, ...others]); + }).then((others) => [ + this.user, + ...sortBy(others, [(user) => otherCollaboratorIds.indexOf(user.id)]), + ]); } // hooks diff --git a/server/queues/processors/EmailsProcessor.ts b/server/queues/processors/EmailsProcessor.ts index ec3e39642a..a4b2902e2f 100644 --- a/server/queues/processors/EmailsProcessor.ts +++ b/server/queues/processors/EmailsProcessor.ts @@ -47,6 +47,7 @@ export default class EmailsProcessor extends BaseProcessor { revisionId: notification.revisionId, documentId: notification.documentId, teamUrl: notification.team.url, + actorId: notification.actorId, actorName: notification.actor.name, }, { notificationId } diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 089e1286a0..002b6d8e99 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -1841,8 +1841,11 @@ "updated": "updated", "“{{ documentTitle }}” {{ eventName }}": "“{{ documentTitle }}” {{ eventName }}", "{{ actorName }} {{ eventName }} a document": "{{ actorName }} {{ eventName }} a document", + "{{ actorName }} {{ eventName }} a document_plural": "{{ actorName }} {{ eventName }} a document", "{{ actorName }} {{ eventName }} the document “{{ documentTitle }}”": "{{ actorName }} {{ eventName }} the document “{{ documentTitle }}”", + "{{ actorName }} {{ eventName }} the document “{{ documentTitle }}”_plural": "{{ actorName }} {{ eventName }} the document “{{ documentTitle }}”", "{{ actorName }} {{ eventName }} the document": "{{ actorName }} {{ eventName }} the document", + "{{ actorName }} {{ eventName }} the document_plural": "{{ actorName }} {{ eventName }} the document", "Unsubscribe from this doc": "Unsubscribe from this doc", "{{ actorName }} shared “{{ documentTitle }}” with you": "{{ actorName }} shared “{{ documentTitle }}” with you", "{{ actorName }} shared a document": "{{ actorName }} shared a document", diff --git a/tsconfig.json b/tsconfig.json index 9e95439b84..2413f02a83 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "forceConsistentCasingInFileNames": true, "isolatedModules": true, "jsx": "react-jsx", - "lib": ["dom", "es2020", "es2024.string", "dom.iterable", "esnext.asynciterable"], + "lib": ["dom", "es2020", "es2021.intl", "es2024.string", "dom.iterable", "esnext.asynciterable"], "module": "esnext", "moduleResolution": "bundler", "resolvePackageJsonExports": false, From 90944892732298328b7d7a4e1e67c076537fd447 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Oct 2026 16:48:49 -0400 Subject: [PATCH 16/38] chore(deps): bump follow-redirects from 1.16.0 to 1.16.1 (#14172) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.16.0 to 1.16.1. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.16.0...v1.16.1) --- updated-dependencies: - dependency-name: follow-redirects dependency-version: 1.16.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index bbe8942fd2..f22333bc4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10414,12 +10414,12 @@ __metadata: linkType: hard "follow-redirects@npm:^1.16.0": - version: 1.16.0 - resolution: "follow-redirects@npm:1.16.0" + version: 1.16.1 + resolution: "follow-redirects@npm:1.16.1" peerDependenciesMeta: debug: optional: true - checksum: 10c0/a1e2900163e6f1b4d1ed5c221b607f41decbab65534c63fe7e287e40a5d552a6496e7d9d7d976fa4ba77b4c51c11e5e9f683f10b43011ea11e442ff128d0e181 + checksum: 10c0/544e24ccb93b7afb5dd5a2199bd556e167b84de2af7c13b2ced08494239677359d7883bae56ae43a9ca98ac5451e75cf4834a5fadd6fa79053b9248fac5447a4 languageName: node linkType: hard From 4e52850527a8f8cd4ce13222c6f7e8d9fb265fbc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 18:04:14 -0400 Subject: [PATCH 17/38] feat: Include collectionId in comment webhook payloads (#14176) --- .../server/tasks/DeliverWebhookTask.test.ts | 93 ++++++++++++++++++- .../server/tasks/DeliverWebhookTask.ts | 23 ++++- 2 files changed, 109 insertions(+), 7 deletions(-) diff --git a/plugins/webhooks/server/tasks/DeliverWebhookTask.test.ts b/plugins/webhooks/server/tasks/DeliverWebhookTask.test.ts index ba21f0b824..a7799e850b 100644 --- a/plugins/webhooks/server/tasks/DeliverWebhookTask.test.ts +++ b/plugins/webhooks/server/tasks/DeliverWebhookTask.test.ts @@ -6,16 +6,22 @@ import { type StrictRequest, } from "msw"; import { server } from "@server/test/msw"; -import { WebhookDelivery } from "@server/models"; +import { Revision, WebhookDelivery } from "@server/models"; import { buildCollection, + buildComment, buildDocument, buildPersonalCollection, buildUser, buildWebhookDelivery, buildWebhookSubscription, } from "@server/test/factories"; -import type { DocumentEvent, UserEvent } from "@server/types"; +import type { + CommentEvent, + DocumentEvent, + RevisionEvent, + UserEvent, +} from "@server/types"; import DeliverWebhookTask, { isExpectedNetworkError, } from "./DeliverWebhookTask"; @@ -160,6 +166,89 @@ describe("DeliverWebhookTask", () => { ); }); + test("should include the document collectionId in comment events", async () => { + const user = await buildUser(); + const subscription = await buildWebhookSubscription({ + teamId: user.teamId, + createdById: user.id, + url: "http://example.com", + events: ["*"], + }); + const collection = await buildCollection({ + teamId: user.teamId, + userId: user.id, + }); + const document = await buildDocument({ + teamId: user.teamId, + userId: user.id, + collectionId: collection.id, + }); + const comment = await buildComment({ + userId: user.id, + documentId: document.id, + }); + const captured = captureWebhook("http://example.com"); + + const event: CommentEvent = { + name: "comments.create", + modelId: comment.id, + documentId: document.id, + teamId: user.teamId, + actorId: user.id, + ip, + }; + await new DeliverWebhookTask().perform({ + subscriptionId: subscription.id, + event, + }); + + expect(captured.length).toBe(1); + const parsedBody = JSON.parse(captured[0].body); + expect(parsedBody.payload.id).toBe(comment.id); + expect(parsedBody.payload.model.collectionId).toBe(collection.id); + expect(parsedBody.payload.model.documentId).toBe(document.id); + }); + + test("should include the document collectionId in revision events", async () => { + const user = await buildUser(); + const subscription = await buildWebhookSubscription({ + teamId: user.teamId, + createdById: user.id, + url: "http://example.com", + events: ["*"], + }); + const collection = await buildCollection({ + teamId: user.teamId, + userId: user.id, + }); + const document = await buildDocument({ + teamId: user.teamId, + userId: user.id, + collectionId: collection.id, + }); + const revision = await Revision.buildFromDocument(document).save(); + const captured = captureWebhook("http://example.com"); + + const event: RevisionEvent = { + name: "revisions.create", + modelId: revision.id, + documentId: document.id, + teamId: user.teamId, + actorId: user.id, + ip, + }; + await new DeliverWebhookTask().perform({ + subscriptionId: subscription.id, + event, + }); + + expect(captured.length).toBe(1); + const parsedBody = JSON.parse(captured[0].body); + expect(parsedBody.payload.id).toBe(revision.id); + expect(parsedBody.payload.model.collectionId).toBe(collection.id); + expect(parsedBody.payload.model.documentId).toBe(document.id); + }); + test("should hit the subscription url when the eventing model doesn't exist", async () => { const subscription = await buildWebhookSubscription({ url: "http://example.com", diff --git a/plugins/webhooks/server/tasks/DeliverWebhookTask.ts b/plugins/webhooks/server/tasks/DeliverWebhookTask.ts index 362b306ce7..d1219af8a7 100644 --- a/plugins/webhooks/server/tasks/DeliverWebhookTask.ts +++ b/plugins/webhooks/server/tasks/DeliverWebhookTask.ts @@ -432,15 +432,26 @@ export default class DeliverWebhookTask extends BaseTask { subscription: WebhookSubscription, event: CommentEvent ): Promise { - const model = await Comment.findByPk(event.modelId, { - paranoid: false, - }); + const [model, document] = await Promise.all([ + Comment.findByPk(event.modelId, { + paranoid: false, + }), + Document.unscoped().findOne({ + attributes: ["collectionId"], + where: { id: event.documentId }, + paranoid: false, + }), + ]); + await this.sendWebhook({ event, subscription, payload: { id: event.modelId, - model: model && presentComment(model), + model: model && { + ...presentComment(model), + collectionId: document?.collectionId ?? null, + }, }, }); } @@ -744,7 +755,9 @@ export default class DeliverWebhookTask extends BaseTask { Revision.findByPk(event.modelId, { paranoid: false, }), - Document.findByPk(event.documentId, { + Document.unscoped().findOne({ + attributes: ["collectionId"], + where: { id: event.documentId }, paranoid: false, }), ]); From 190c5e514855333efafb46769c880c449bbc18d9 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 18:55:51 -0400 Subject: [PATCH 18/38] feat: Softer notice colors with matching menu icons (#14177) --- app/editor/components/NoticeIcon.tsx | 44 +++++++++++++++++++ app/editor/menus/block.tsx | 22 +++++----- app/editor/menus/notice.tsx | 17 +++----- shared/editor/components/Styles.ts | 63 +++++++++++----------------- shared/styles/theme.ts | 33 +++++++++------ 5 files changed, 105 insertions(+), 74 deletions(-) create mode 100644 app/editor/components/NoticeIcon.tsx diff --git a/app/editor/components/NoticeIcon.tsx b/app/editor/components/NoticeIcon.tsx new file mode 100644 index 0000000000..a7027df84d --- /dev/null +++ b/app/editor/components/NoticeIcon.tsx @@ -0,0 +1,44 @@ +import { DoneIcon, InfoIcon, StarredIcon, WarningIcon } from "outline-icons"; +import styled from "styled-components"; +import { NoticeTypes } from "@shared/editor/nodes/Notice"; +import { s } from "@shared/styles"; + +interface Props { + /** The style of the notice. */ + type: NoticeTypes; +} + +/** + * Renders the icon for a notice style, colored to match the notice in the editor. + * + * @param props the component props. + * @returns the icon element. + */ +export function NoticeIcon({ type }: Props) { + switch (type) { + case NoticeTypes.Success: + return ; + case NoticeTypes.Warning: + return ; + case NoticeTypes.Tip: + return ; + default: + return ; + } +} + +const NoticeInfoIcon = styled(InfoIcon)` + color: ${s("noticeInfoText")}; +`; + +const SuccessIcon = styled(DoneIcon)` + color: ${s("noticeSuccessText")}; +`; + +const NoticeWarningIcon = styled(WarningIcon)` + color: ${s("noticeWarningText")}; +`; + +const TipIcon = styled(StarredIcon)` + color: ${s("noticeTipText")}; +`; diff --git a/app/editor/menus/block.tsx b/app/editor/menus/block.tsx index 7d4fa7e648..55d4404f40 100644 --- a/app/editor/menus/block.tsx +++ b/app/editor/menus/block.tsx @@ -13,13 +13,9 @@ import { TableIcon, TodoListIcon, ImageIcon, - StarredIcon, - WarningIcon, - InfoIcon, AttachmentIcon, CalendarIcon, MathIcon, - DoneIcon, EmbedIcon, CollapseIcon, } from "outline-icons"; @@ -28,10 +24,12 @@ import styled from "styled-components"; import { v4 as uuidv4 } from "uuid"; import type { TFunction } from "i18next"; import Image from "@shared/editor/components/Img"; +import { NoticeTypes } from "@shared/editor/nodes/Notice"; import type { MenuItem } from "@shared/editor/types"; import { MentionType } from "@shared/types"; import { toISODate } from "@shared/utils/date"; import { metaDisplay } from "@shared/utils/keyboard"; +import { NoticeIcon } from "~/editor/components/NoticeIcon"; import Desktop from "~/utils/Desktop"; const Img = styled(Image)` @@ -243,30 +241,30 @@ export default function blockMenuItems( { name: "container_notice", title: t("Info notice"), - icon: , + icon: , keywords: "card callout hint information note", - attrs: { style: "info" }, + attrs: { style: NoticeTypes.Info }, }, { name: "container_notice", title: t("Success notice"), - icon: , + icon: , keywords: "card callout hint", - attrs: { style: "success" }, + attrs: { style: NoticeTypes.Success }, }, { name: "container_notice", title: t("Warning notice"), - icon: , + icon: , keywords: "card callout hint error caution danger alert", - attrs: { style: "warning" }, + attrs: { style: NoticeTypes.Warning }, }, { name: "container_notice", title: t("Tip notice"), - icon: , + icon: , keywords: "card callout hint suggestion", - attrs: { style: "tip" }, + attrs: { style: NoticeTypes.Tip }, }, { name: "separator", diff --git a/app/editor/menus/notice.tsx b/app/editor/menus/notice.tsx index 549e0682cc..96b78ae3f4 100644 --- a/app/editor/menus/notice.tsx +++ b/app/editor/menus/notice.tsx @@ -1,14 +1,9 @@ import { t } from "i18next"; -import { - DoneIcon, - ExpandedIcon, - InfoIcon, - StarredIcon, - WarningIcon, -} from "outline-icons"; +import { ExpandedIcon } from "outline-icons"; import { NoticeTypes } from "@shared/editor/nodes/Notice"; import { findParentNode } from "@shared/editor/queries/findParentNode"; import type { MenuItem, SelectionContext } from "@shared/editor/types"; +import { NoticeIcon } from "~/editor/components/NoticeIcon"; /** * Returns menu items for the notice/callout selection toolbar. @@ -39,25 +34,25 @@ export default function noticeMenuItems(ctx: SelectionContext): MenuItem[] { children: [ { name: NoticeTypes.Info, - icon: , + icon: , label: t("Info notice"), active: () => currentStyle === NoticeTypes.Info, }, { name: NoticeTypes.Success, - icon: , + icon: , label: t("Success notice"), active: () => currentStyle === NoticeTypes.Success, }, { name: NoticeTypes.Warning, - icon: , + icon: , label: t("Warning notice"), active: () => currentStyle === NoticeTypes.Warning, }, { name: NoticeTypes.Tip, - icon: , + icon: , label: t("Tip notice"), active: () => currentStyle === NoticeTypes.Tip, }, diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index 8a94049be2..440db1ae78 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -86,6 +86,25 @@ const diagramTheme = (theme: DefaultTheme) => css` --pele-font-mono: ${theme.fontFamilyMono}; `; +/** + * Builds the colors of a notice block from its base and text colors. + * + * @param theme the current theme. + * @param base the base color of the notice. + * @param text the color of the notice text and icon. + * @returns the css for the notice colors. + */ +const noticeColors = (theme: DefaultTheme, base: string, text: string) => css` + background: ${transparentize(theme.isDark ? 0.85 : 0.92, base)}; + border: 1px solid ${transparentize(theme.isDark ? 0.6 : 0.7, base)}; + color: ${text}; + + a, + .${EditorStyleHelper.noticeIcon} { + color: ${text}; + } +`; + const mathStyle = (props: Props) => css` /* Based on https://github.com/benrbray/prosemirror-math/blob/master/style/math.css */ @@ -1366,15 +1385,12 @@ ${ display: flex; align-items: center; position: relative; - background: ${transparentize(0.9, props.theme.noticeInfoBackground)}; - border-left: 4px solid ${props.theme.noticeInfoBackground}; - color: ${props.theme.noticeInfoText}; - border-radius: 4px; + ${noticeColors(props.theme, props.theme.noticeInfoBackground, props.theme.noticeInfoText)} + border-radius: ${EditorStyleHelper.blockRadius}; padding: 8px 10px 8px 8px; margin: 8px 0; a { - color: ${props.theme.noticeInfoText}; text-decoration: underline; } @@ -1398,7 +1414,6 @@ ${ height: 24px; align-self: flex-start; margin-right: 4px; - color: ${props.theme.noticeInfoBackground}; } &:dir(rtl) .${EditorStyleHelper.noticeIcon} { @@ -1408,45 +1423,15 @@ ${ } .${EditorStyleHelper.notice}.tip { - background: ${transparentize(0.9, props.theme.noticeTipBackground)}; - border-left: 4px solid ${props.theme.noticeTipBackground}; - color: ${props.theme.noticeTipText}; - - .${EditorStyleHelper.noticeIcon} { - color: ${props.theme.noticeTipBackground}; - } - - a { - color: ${props.theme.noticeTipText}; - } + ${noticeColors(props.theme, props.theme.noticeTipBackground, props.theme.noticeTipText)} } .${EditorStyleHelper.notice}.warning { - background: ${transparentize(0.9, props.theme.noticeWarningBackground)}; - border-left: 4px solid ${props.theme.noticeWarningBackground}; - color: ${props.theme.noticeWarningText}; - - .${EditorStyleHelper.noticeIcon} { - color: ${props.theme.noticeWarningBackground}; - } - - a { - color: ${props.theme.noticeWarningText}; - } + ${noticeColors(props.theme, props.theme.noticeWarningBackground, props.theme.noticeWarningText)} } .${EditorStyleHelper.notice}.success { - background: ${transparentize(0.9, props.theme.noticeSuccessBackground)}; - border-left: 4px solid ${props.theme.noticeSuccessBackground}; - color: ${props.theme.noticeSuccessText}; - - .${EditorStyleHelper.noticeIcon} { - color: ${props.theme.noticeSuccessBackground}; - } - - a { - color: ${props.theme.noticeSuccessText}; - } + ${noticeColors(props.theme, props.theme.noticeSuccessBackground, props.theme.noticeSuccessText)} } blockquote { diff --git a/shared/styles/theme.ts b/shared/styles/theme.ts index fe2a98cf28..d4ab854c51 100644 --- a/shared/styles/theme.ts +++ b/shared/styles/theme.ts @@ -1,4 +1,4 @@ -import { darken, lighten, transparentize } from "polished"; +import { darken, lighten, mix, saturate, transparentize } from "polished"; import type { DefaultTheme, Colors } from "styled-components"; import breakpoints from "./breakpoints"; @@ -102,14 +102,23 @@ const buildBaseTheme = (input: Partial) => { codeConstant: "#0550ae", codeParameter: colors.lightBlack, codeOperator: "#393a34", - noticeInfoBackground: colors.brand.blue, - noticeInfoText: colors.almostBlack, - noticeTipBackground: "#f5be31", - noticeTipText: colors.almostBlack, - noticeWarningBackground: "#d73a49", - noticeWarningText: colors.almostBlack, + noticeInfoBackground: colors.slate, + noticeInfoText: saturate(0.1, mix(0.5, colors.slate, colors.almostBlack)), + noticeTipBackground: colors.brand.blue, + noticeTipText: saturate( + 0.1, + mix(0.5, colors.brand.blue, colors.almostBlack) + ), + noticeWarningBackground: colors.brand.yellow, + noticeWarningText: saturate( + 0.1, + mix(0.5, colors.brand.yellow, colors.almostBlack) + ), noticeSuccessBackground: colors.brand.green, - noticeSuccessText: colors.almostBlack, + noticeSuccessText: saturate( + 0.1, + mix(0.5, colors.brand.green, colors.almostBlack) + ), tableSelectedBackground: transparentize(0.9, colors.accent), breakpoints, ...colors, @@ -263,10 +272,10 @@ export const buildDarkTheme = (input: Partial): DefaultTheme => { codeAttrValue: "#ce9178", embedBorder: colors.black50, horizontalRule: lighten(0.1, colors.almostBlack), - noticeInfoText: colors.white, - noticeTipText: colors.white, - noticeWarningText: colors.white, - noticeSuccessText: colors.white, + noticeInfoText: mix(0.5, colors.slate, colors.white), + noticeTipText: mix(0.5, colors.brand.blue, colors.white), + noticeWarningText: mix(0.5, colors.brand.yellow, colors.white), + noticeSuccessText: mix(0.5, colors.brand.green, colors.white), progressBarBackground: colors.slate, scrollbarBackground: colors.black, scrollbarThumb: colors.lightBlack, From 0d517b45b0ce862ab1e7a065197ebdf107f402e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Oct 2026 18:56:02 -0400 Subject: [PATCH 19/38] chore(deps): bump vite from 8.3.2 to 8.3.3 (#14173) Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 8.3.2 to 8.3.3. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v8.3.3/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-version: 8.3.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 776aef6971..63a82a7e1b 100644 --- a/package.json +++ b/package.json @@ -270,7 +270,7 @@ "uuid": "^11.1.1", "validator": "13.15.35", "vaul": "^1.1.2", - "vite": "^8.3.2", + "vite": "^8.3.3", "vite-plugin-pwa": "1.3.0", "winston": "^3.17.0", "ws": "^7.5.13", diff --git a/yarn.lock b/yarn.lock index f22333bc4f..a7c32e3a1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14565,7 +14565,7 @@ __metadata: uuid: "npm:^11.1.1" validator: "npm:13.15.35" vaul: "npm:^1.1.2" - vite: "npm:^8.3.2" + vite: "npm:^8.3.3" vite-plugin-pwa: "npm:1.3.0" vite-tsconfig-paths: "npm:^6.1.1" vitest: "npm:^4.1.11" @@ -19331,7 +19331,7 @@ __metadata: languageName: node linkType: hard -"vite@npm:^6.0.0 || ^7.0.0 || ^8.0.0, vite@npm:^8.3.2": +"vite@npm:^6.0.0 || ^7.0.0 || ^8.0.0": version: 8.3.2 resolution: "vite@npm:8.3.2" dependencies: @@ -19388,6 +19388,63 @@ __metadata: languageName: node linkType: hard +"vite@npm:^8.3.3": + version: 8.3.3 + resolution: "vite@npm:8.3.3" + dependencies: + fsevents: "npm:~2.3.3" + lightningcss: "npm:^1.33.0" + picomatch: "npm:^4.0.7" + postcss: "npm:^8.5.28" + rolldown: "npm:~1.2.11" + tinyglobby: "npm:^0.2.17" + peerDependencies: + "@types/node": ^20.19.0 || >=22.12.0 + "@vitejs/devtools": ^0.7.1 + esbuild: ^0.27.0 || ^0.28.0 + jiti: ">=1.21.0" + less: ^4.0.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: ">=0.54.8" + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + dependenciesMeta: + fsevents: + optional: true + peerDependenciesMeta: + "@types/node": + optional: true + "@vitejs/devtools": + optional: true + esbuild: + optional: true + jiti: + optional: true + less: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + bin: + vite: bin/vite.js + checksum: 10c0/a1fa945ad1dd98d43e45d491eee11505083b19e00f8c5549cd0771273717f7bdb431eef71ef3568d1effa6ba63719811e5151f3fbec84be5a017d4975470a0d9 + languageName: node + linkType: hard + "vitest@npm:^4.1.11": version: 4.1.11 resolution: "vitest@npm:4.1.11" From a30ea25b2769f7ad1d953295f799b5660d7299ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Oct 2026 18:56:11 -0400 Subject: [PATCH 20/38] chore(deps): bump hono from 4.13.7 to 4.13.13 (#14174) Bumps [hono](https://github.com/honojs/hono) from 4.13.7 to 4.13.13. - [Release notes](https://github.com/honojs/hono/releases) - [Commits](https://github.com/honojs/hono/compare/v4.13.7...v4.13.13) --- updated-dependencies: - dependency-name: hono dependency-version: 4.13.13 dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a7c32e3a1a..dfecc306f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11173,9 +11173,9 @@ __metadata: linkType: hard "hono@npm:^4.11.4": - version: 4.13.7 - resolution: "hono@npm:4.13.7" - checksum: 10c0/29672a94a4f2be7f3f4d959ad69808dd3bbc220909ca4f9660997022ff45d48ae71e42a460e417d808809d68110196f19359aaab2b14ae6a750331d789601b5a + version: 4.13.13 + resolution: "hono@npm:4.13.13" + checksum: 10c0/c8524e685a59b4f23a9bea15385eeac5622218949db251cb871b20fd9ef673b751b44ccdee6c22b3df56e5ed4c1b1cebad17b518bdc1823039da39b53ef9c1cf languageName: node linkType: hard From ed219b8abf5687355620026629300645f4cb734b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 19:00:24 -0400 Subject: [PATCH 21/38] fix: Block menu renders offset by the sidebar width (#14178) Upgrade @floating-ui/utils to 0.2.12, which no longer treats an ancestor with container-type as the containing block for fixed popovers. --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index dfecc306f4..4f76e61392 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2087,9 +2087,9 @@ __metadata: linkType: hard "@floating-ui/utils@npm:^0.2.10": - version: 0.2.10 - resolution: "@floating-ui/utils@npm:0.2.10" - checksum: 10c0/e9bc2a1730ede1ee25843937e911ab6e846a733a4488623cd353f94721b05ec2c9ec6437613a2ac9379a94c2fd40c797a2ba6fa1df2716f5ce4aa6ddb1cf9ea4 + version: 0.2.12 + resolution: "@floating-ui/utils@npm:0.2.12" + checksum: 10c0/bb910b90d56991a62011afaf5f8e0c4b7fb6dab69403f4dd17fbd6eb25560b28d533dff9791f270b4f459852e9006a1077b5d73cbedb5e34d9424afc6a828314 languageName: node linkType: hard From 0853354daf022175dc7f39898e67c8f9965af852 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 19:02:27 -0400 Subject: [PATCH 22/38] feat: Show code block line numbers alongside line wrapping (#14170) * feat: Show code block line numbers alongside line wrapping Render line numbers as a widget at the start of each line so they align with wrapped lines and stay fixed during horizontal scroll. * fix: Keep line number gutter size inside table cells --- shared/editor/components/Styles.ts | 44 +++++++-------- shared/editor/nodes/CodeFence.ts | 15 +---- .../editor/plugins/CodeHighlightingPlugin.ts | 56 +++++++++++++++---- shared/editor/styles/EditorStyleHelper.ts | 3 + 4 files changed, 72 insertions(+), 46 deletions(-) diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index 440db1ae78..29fd925291 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -1894,7 +1894,7 @@ mark { height: auto; overflow: visible; - &::after { + .${EditorStyleHelper.codeBlockLineNumber} { display: none; } } @@ -1913,41 +1913,45 @@ mark { .${EditorStyleHelper.codeBlock}.with-line-numbers { pre { + // Position line numbers against the block, so they stay in place when + // the code scrolls horizontally. + position: static; padding-left: calc(var(--line-number-gutter-width, 0) * 1em + 1.5em); } - &::after { - content: attr(data-line-numbers); + code { + counter-reset: line; + } + + .${EditorStyleHelper.codeBlockLineNumber} { position: absolute; - padding-left: 0.5em; left: 1px; - top: calc(1px + 0.75em); - width: calc(var(--line-number-gutter-width,0) * 1em + .25em); - word-break: break-all; - white-space: break-spaces; - font-family: ${props.theme.fontFamilyMono}; - line-height: 1.4em; + box-sizing: content-box; + width: calc(var(--line-number-gutter-width, 0) * 1em + .25em); + padding: 0 0.75em 0 0.5em; color: ${props.theme.textTertiary}; background: ${props.theme.codeBackground}; text-align: right; font-variant-numeric: tabular-nums; user-select: none; + pointer-events: none; + + &::before { + counter-increment: line; + content: counter(line); + } } } .${EditorStyleHelper.codeBlock}.collapsed { + overflow: clip; + pre { pointer-events: none; max-height: calc(10 * 1.4em + 0.75em); overflow: hidden; } - &::after { - max-height: calc(10 * 1.4em + 0.75em); - overflow: hidden; - clip-path: inset(0 0 calc(100% - 10 * 1.4em - 0.75em) 0); - } - &::before { content: ""; position: absolute; @@ -1967,17 +1971,13 @@ mark { } @media print { + overflow: visible; + pre { max-height: none; overflow: visible; } - &::after { - max-height: none; - overflow: visible; - clip-path: none; - } - &::before { display: none; } diff --git a/shared/editor/nodes/CodeFence.ts b/shared/editor/nodes/CodeFence.ts index 07d697512e..6eb9390e68 100644 --- a/shared/editor/nodes/CodeFence.ts +++ b/shared/editor/nodes/CodeFence.ts @@ -195,17 +195,11 @@ function buildCollapseState( const isCollapsed = collapsedBlocks.has(pos); if (isCollapsed) { - const totalLines = (node.textContent.match(/\n/g)?.length ?? 0) + 1; - const gutterWidth = String(totalLines).length; - const lineNumberText = Array.from({ length: totalLines }, (_, i) => - String(i + 1).padStart(gutterWidth, " ") - ).join("\n"); - decorations.push( Decoration.node( pos, pos + node.nodeSize, - { class: "collapsed", "data-line-numbers": lineNumberText }, + { class: "collapsed" }, { collapsed: true } ) ); @@ -298,11 +292,8 @@ export default class CodeFence extends Node { toDOM: (node) => { const classes = [ EditorStyleHelper.codeBlock, - node.attrs.wrap - ? "with-line-wrap" - : this.showLineNumbers - ? "with-line-numbers" - : "", + node.attrs.wrap ? "with-line-wrap" : "", + this.showLineNumbers ? "with-line-numbers" : "", ] .filter(Boolean) .join(" "); diff --git a/shared/editor/plugins/CodeHighlightingPlugin.ts b/shared/editor/plugins/CodeHighlightingPlugin.ts index 98fea07cd3..20eedd78bf 100644 --- a/shared/editor/plugins/CodeHighlightingPlugin.ts +++ b/shared/editor/plugins/CodeHighlightingPlugin.ts @@ -1,4 +1,4 @@ -import { flattenDeep, padStart } from "es-toolkit/compat"; +import { flattenDeep } from "es-toolkit/compat"; import type { Node } from "prosemirror-model"; import type { Transaction } from "prosemirror-state"; import { Plugin, PluginKey } from "prosemirror-state"; @@ -7,6 +7,7 @@ import type refractorType from "refractor/core"; import { getLoaderForLanguage, getRefractorLangForLanguage } from "../lib/code"; import { isRemoteTransaction } from "../lib/multiplayer"; import { findBlockNodes } from "../queries/findChildren"; +import { EditorStyleHelper } from "../styles/EditorStyleHelper"; type ParsedNode = { text: string; @@ -62,6 +63,36 @@ async function loadLanguage(language: string) { return languagePromises[language]; } +/** + * Create the DOM for a line number. The number itself is a CSS counter, so + * every widget is identical and the view can reuse them as lines change. + * + * @returns the line number element. + */ +function createLineNumber() { + const element = document.createElement("span"); + element.className = EditorStyleHelper.codeBlockLineNumber; + element.setAttribute("aria-hidden", "true"); + return element; +} + +/** + * Create a widget decoration that marks the start of a line in a code block. + * + * @param pos - the position of the start of the line. + * @returns the widget decoration. + */ +function lineNumberWidget(pos: number) { + return Decoration.widget(pos, createLineNumber, { + side: -1, + marks: [], + key: "line-number", + // Keep the widget editable, Chrome otherwise deletes it on Backspace at + // the start of a line instead of the line break. + raw: true, + }); +} + function getDecorations({ doc, name, @@ -109,27 +140,28 @@ function getDecorations({ const lineDecorations = []; if (!cache[block.pos] || !cache[block.pos].node.eq(block.node)) { - if (lineNumbers && !block.node.attrs.wrap) { - const lineCount = - (block.node.textContent.match(/\n/g) || []).length + 1; - const gutterWidth = String(lineCount).length; - - const lineCountText = Array.from({ length: lineCount }) - .map((_, i) => padStart(`${i + 1}`, gutterWidth, " ")) - .join("\n"); + if (lineNumbers) { + const text = block.node.textContent; + const lineStarts = [block.pos + 1]; + for (let i = 0; i < text.length; i++) { + if (text[i] === "\n") { + lineStarts.push(block.pos + 2 + i); + } + } + const gutterWidth = String(lineStarts.length).length; lineDecorations.push( Decoration.node( block.pos, block.pos + block.node.nodeSize, { - "data-line-numbers": `${lineCountText}`, style: `--line-number-gutter-width: ${gutterWidth};`, }, { - key: `line-${lineCount}-gutter`, + key: `line-${gutterWidth}-gutter`, } - ) + ), + ...lineStarts.map(lineNumberWidget) ); } diff --git a/shared/editor/styles/EditorStyleHelper.ts b/shared/editor/styles/EditorStyleHelper.ts index d210380451..9bbe6df45a 100644 --- a/shared/editor/styles/EditorStyleHelper.ts +++ b/shared/editor/styles/EditorStyleHelper.ts @@ -78,6 +78,9 @@ export class EditorStyleHelper { /** Toggle button for collapsible code blocks */ static readonly codeBlockToggle = "code-block-toggle"; + /** Line number shown in the gutter at the start of each code block line */ + static readonly codeBlockLineNumber = "code-block-line-number"; + // Diffs static readonly diffInsertion = "diff-insertion"; From 695e973e6b104b707414508116c4f9d39a2bdab1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 19:05:10 -0400 Subject: [PATCH 23/38] feat: Allow tables inside notices (#14175) * feat: Allow tables inside notices Blend table, rule and code colors onto the notice background, keep table scroll shadows inside the notice, hide full width for tables in notices, and fit new table columns to the available width. * fix: Leave room for table row controls in notices * fix: Blend table grips onto the notice background * fix: Derive notice content colors from the softer notice styles --- app/editor/menus/table.tsx | 1 + shared/editor/commands/table.ts | 12 +- shared/editor/components/Styles.ts | 185 ++++++++++++++++++++++++++--- shared/editor/nodes/Notice.tsx | 2 +- shared/utils/color.test.ts | 24 ++++ shared/utils/color.ts | 31 +++++ 6 files changed, 233 insertions(+), 22 deletions(-) diff --git a/app/editor/menus/table.tsx b/app/editor/menus/table.tsx index 8592d6c319..628b8730b7 100644 --- a/app/editor/menus/table.tsx +++ b/app/editor/menus/table.tsx @@ -31,6 +31,7 @@ export default function tableMenuItems(ctx: SelectionContext): MenuItem[] { label: isFullWidth ? t("Default width") : t("Full width"), icon: , attrs: isFullWidth ? { layout: null } : { layout: TableLayout.fullWidth }, + visible: !ctx.isInNotice, }, { name: "distributeColumns", diff --git a/shared/editor/commands/table.ts b/shared/editor/commands/table.ts index af233e9062..3850f9c611 100644 --- a/shared/editor/commands/table.ts +++ b/shared/editor/commands/table.ts @@ -112,10 +112,18 @@ export function createTable({ /** The widths of each column in the table. */ colWidth: number; }): Command { - return (state, dispatch) => { + return (state, dispatch, view) => { if (dispatch) { const offset = state.tr.selection.anchor + 1; - const nodes = createTableInner(state, rowsCount, colsCount, colWidth); + const { $from } = state.selection; + + // Fit the columns to the block, which is narrower in a notice or list. + const block = $from.depth > 0 ? view?.nodeDOM($from.before()) : null; + const width = + block instanceof HTMLElement && block.clientWidth + ? Math.min(colWidth, Math.floor(block.clientWidth / colsCount)) + : colWidth; + const nodes = createTableInner(state, rowsCount, colsCount, width); const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView(); const resolvedPos = tr.doc.resolve(offset); tr.setSelection(TextSelection.near(resolvedPos)); diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index 29fd925291..6f847f2bbf 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -1,9 +1,10 @@ -import { lighten, transparentize } from "polished"; +import { lighten, mix, transparentize } from "polished"; import type { DefaultTheme } from "styled-components"; import styled, { css, keyframes } from "styled-components"; import { HEADER_HEIGHT } from "../../constants"; import { breakpoints, hover } from "../../styles"; import { light } from "../../styles/theme"; +import { blendColors } from "../../utils/color"; import { EditorStyleHelper } from "../styles/EditorStyleHelper"; import { videoStyle } from "./Video"; @@ -87,23 +88,40 @@ const diagramTheme = (theme: DefaultTheme) => css` `; /** - * Builds the colors of a notice block from its base and text colors. + * Builds the colors of a notice block from its base and text colors. The tint + * is not opaque, so colors for content in the notice are blended onto it. * * @param theme the current theme. * @param base the base color of the notice. * @param text the color of the notice text and icon. * @returns the css for the notice colors. */ -const noticeColors = (theme: DefaultTheme, base: string, text: string) => css` - background: ${transparentize(theme.isDark ? 0.85 : 0.92, base)}; - border: 1px solid ${transparentize(theme.isDark ? 0.6 : 0.7, base)}; - color: ${text}; +const noticeColors = (theme: DefaultTheme, base: string, text: string) => { + const opacity = theme.isDark ? 0.15 : 0.08; + const background = mix(opacity, base, theme.background); + const blend = (value: string) => + blendColors(value, background, theme.isDark ? "screen" : "multiply"); + const divider = blend(theme.divider); - a, - .${EditorStyleHelper.noticeIcon} { + return css` + background: ${transparentize(1 - opacity, base)}; + border: 1px solid ${transparentize(theme.isDark ? 0.6 : 0.7, base)}; color: ${text}; - } -`; + + --notice-background: ${background}; + --notice-divider: ${divider}; + --notice-table-header: ${mix(0.25, divider, background)}; + --notice-code-background: ${blend(theme.codeBackground)}; + --notice-code-border: ${blend(theme.codeBorder)}; + --table-grip: ${divider}; + --table-grip-border: ${background}; + + a, + .${EditorStyleHelper.noticeIcon} { + color: ${text}; + } + `; +}; const mathStyle = (props: Props) => css` /* Based on https://github.com/benrbray/prosemirror-math/blob/master/style/math.css */ @@ -598,6 +616,134 @@ const textStyle = () => css` } `; +const noticeStyle = () => css` + .${EditorStyleHelper.notice} { + hr:not(.ProseMirror-selectednode)::before { + border-top-color: var(--notice-divider); + } + + code, + pre { + background: var(--notice-code-background); + border-color: var(--notice-code-border); + } + + pre code { + background: none; + } + + .${EditorStyleHelper.codeBlock}.with-line-numbers::after { + background: var(--notice-code-background); + } + + .${EditorStyleHelper.codeBlock}.collapsed::before { + background: linear-gradient( + to bottom, + transparent 0%, + var(--notice-code-background) 70%, + var(--notice-code-background) 100% + ); + } + + @media not print { + .${EditorStyleHelper.mermaidDiagram} { + background: var(--notice-code-background); + border-color: var(--notice-code-border); + --pele-bg: var(--notice-code-background); + } + } + + /* above the scroll shadow of a table that follows it */ + .${EditorStyleHelper.noticeIcon} { + position: relative; + z-index: 21; + } + + /* the scroll area fills the notice padding and icon gutter, which leaves + room for the row controls */ + .${EditorStyleHelper.tableScrollable} { + margin-left: -36px; + margin-right: -10px; + padding-left: 36px; + padding-right: 10px; + } + + /* keep the click area inside the scroll area so that it does not scroll */ + .${EditorStyleHelper.tableAddColumn}:not(.first)::before { + right: -10px; + } + + .${EditorStyleHelper.tableShadowLeft}::before { + left: -36px; + border-left: 36px solid var(--notice-background); + } + + .${EditorStyleHelper.tableShadowRight}::after { + right: -10px; + border-right: 10px solid var(--notice-background); + } + + &:dir(rtl) { + .${EditorStyleHelper.tableScrollable} { + margin-left: -8px; + margin-right: -38px; + padding-left: 8px; + padding-right: 38px; + } + + .${EditorStyleHelper.tableShadowLeft}::before { + left: -8px; + border-left-width: 8px; + } + + .${EditorStyleHelper.tableShadowRight}::after { + right: -38px; + border-right-width: 38px; + } + } + + .${EditorStyleHelper.tableFullWidth} { + transform: none; + + .${EditorStyleHelper.tableScrollable} { + width: auto; + } + + table { + width: 100%; + } + + &.${EditorStyleHelper.tableShadowRight}::after { + left: auto; + } + } + + table, + tr, + td, + th { + border-color: var(--notice-divider); + } + + th { + background: var(--notice-table-header); + } + + .${EditorStyleHelper.tableStickyHeader} > .${EditorStyleHelper.tableScrollable} > table > tbody > tr:first-child > th { + box-shadow: + 0 -1px 0 var(--notice-divider), + 0 1px 0 var(--notice-divider); + } + + td[data-bgcolor], + th[data-bgcolor] { + background: + linear-gradient(var(--cell-bg-color), var(--cell-bg-color)), + linear-gradient(var(--notice-background), var(--notice-background)); + } + } +`; + const style = (props: Props) => css` --font-size-p: var(--font-size-body); --font-size-h1: 28px; @@ -2227,7 +2373,7 @@ table { height: 4px; display: ${props.readOnly ? "none" : "block"}; border-radius: 100%; - background-color: ${props.theme.divider}; + background-color: var(--table-grip, ${props.theme.divider}); } &:hover { @@ -2272,7 +2418,7 @@ table { height: 4px; display: ${props.readOnly ? "none" : "block"}; border-radius: 100%; - background-color: ${props.theme.divider}; + background-color: var(--table-grip, ${props.theme.divider}); } &:hover { @@ -2314,7 +2460,7 @@ table { left: var(--span-start, 0); width: var(--span-size, 100%); height: 12px; - background: ${props.theme.divider}; + background: var(--table-grip, ${props.theme.divider}); display: ${props.readOnly ? "none" : "block"}; /* above the add column controls so narrow columns stay draggable */ z-index: 2; @@ -2325,7 +2471,7 @@ table { } body.${EditorStyleHelper.tableDragging} &:hover::after { - background: ${props.theme.divider}; + background: var(--table-grip, ${props.theme.divider}); } &.first::after { border-top-left-radius: 3px; @@ -2349,8 +2495,8 @@ table { top: var(--span-start, 0); height: var(--span-size, 100%); width: 12px; - background: ${props.theme.divider}; - border-color: ${props.theme.background}; + background: var(--table-grip, ${props.theme.divider}); + border-color: var(--table-grip-border, ${props.theme.background}); display: ${props.readOnly ? "none" : "block"}; /* above the add row controls so short rows stay draggable */ z-index: 2; @@ -2361,7 +2507,7 @@ table { } body.${EditorStyleHelper.tableDragging} &:hover::after { - background: ${props.theme.divider}; + background: var(--table-grip, ${props.theme.divider}); } &.first::after { border-top-left-radius: 3px; @@ -2380,11 +2526,11 @@ table { &::after { content: ""; cursor: var(--pointer); - background: ${props.theme.divider}; + background: var(--table-grip, ${props.theme.divider}); width: 13px; height: 13px; border-radius: 13px; - border: 2px solid ${props.theme.background}; + border: 2px solid var(--table-grip-border, ${props.theme.background}); position: absolute; top: -18px; left: -18px; @@ -2876,6 +3022,7 @@ li > .${EditorStyleHelper.toggleBlock} { const EditorContainer = styled.div>` ${style} + ${noticeStyle} ${mathStyle} ${codeMarkCursor} ${codeBlockStyle} diff --git a/shared/editor/nodes/Notice.tsx b/shared/editor/nodes/Notice.tsx index d016da25c0..ffa1e19cfd 100644 --- a/shared/editor/nodes/Notice.tsx +++ b/shared/editor/nodes/Notice.tsx @@ -40,7 +40,7 @@ export default class Notice extends Node { }, }, content: - "(list | blockquote | hr | paragraph | heading | code_block | code_fence | attachment)+", + "(list | blockquote | hr | paragraph | heading | code_block | code_fence | attachment | table)+", group: "block", defining: true, draggable: false, diff --git a/shared/utils/color.test.ts b/shared/utils/color.test.ts index cf40625141..4c443e5faf 100644 --- a/shared/utils/color.test.ts +++ b/shared/utils/color.test.ts @@ -1,4 +1,5 @@ import { + blendColors, ensureContrast, palette, stringToColor, @@ -143,3 +144,26 @@ describe("ensureContrast", () => { expect(ensureContrast("currentColor", true, "#111")).toBe("currentColor"); }); }); + +describe("blendColors", () => { + it("multiplies a color onto the backdrop", () => { + expect(blendColors("#ffffff", "#336699", "multiply")).toBe("#336699"); + expect(blendColors("#000000", "#336699", "multiply")).toBe("#000000"); + expect(blendColors("#808080", "#ff0000", "multiply")).toBe("#800000"); + }); + + it("screens a color onto the backdrop", () => { + expect(blendColors("#000000", "#336699", "screen")).toBe("#336699"); + expect(blendColors("#ffffff", "#336699", "screen")).toBe("#ffffff"); + expect(blendColors("#808080", "#000000", "screen")).toBe("#808080"); + }); + + it("applies the alpha of the color", () => { + expect(blendColors("rgba(0, 0, 0, 0.5)", "#ffffff", "multiply")).toBe( + "#808080" + ); + expect(blendColors("rgba(255, 255, 255, 0)", "#336699", "screen")).toBe( + "#336699" + ); + }); +}); diff --git a/shared/utils/color.ts b/shared/utils/color.ts index 5e3d0e8696..39304df532 100644 --- a/shared/utils/color.ts +++ b/shared/utils/color.ts @@ -196,3 +196,34 @@ export const hexToRgba = (hex: string): RgbaColor => { hex.length === 8 ? round(parseInt(hex.substring(6, 8), 16) / 255, 2) : 1, }; }; + +/** + * Blends a color onto an opaque backdrop with a multiply or screen blend mode. + * Multiply darkens the backdrop, screen lightens it. The alpha of the color + * controls how much of the blend is applied. + * + * @param color the color to blend. + * @param backdrop the color below. + * @param mode the blend mode to use. + * @returns the blended color as a hex string. + */ +export const blendColors = ( + color: string, + backdrop: string, + mode: "multiply" | "screen" +): string => { + const source = parseToRgb(color); + const base = parseToRgb(backdrop); + const alpha = "alpha" in source ? source.alpha : 1; + const blend = (a: number, b: number) => { + const blended = mode === "multiply" ? (a * b) / 255 : a + b - (a * b) / 255; + return Math.round(alpha * blended + (1 - alpha) * b); + }; + + return rgbaToHex({ + red: blend(source.red, base.red), + green: blend(source.green, base.green), + blue: blend(source.blue, base.blue), + alpha: 1, + }); +}; From 97c7ee4a3de5defb57f0051ba7601daf0ca92877 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 19:24:33 -0400 Subject: [PATCH 24/38] Mobile: drag-to-close sidebar and touch-friendly header controls (#14179) * feat: Mobile sidebar drag to close and touch-friendly mobile chrome * fix: Address review feedback on mobile header and sidebar gesture --- app/components/Actions.ts | 5 + app/components/Button.tsx | 27 ++- app/components/Collaborators.tsx | 25 ++- app/components/Facepile.tsx | 2 +- app/components/FilterOptions.tsx | 12 ++ app/components/Header.tsx | 112 ++++++++++- app/components/Heading.ts | 10 +- app/components/Input.tsx | 7 + app/components/InputSearchPage.tsx | 2 + app/components/Menu/DropdownMenu.tsx | 2 +- app/components/PlaceholderDocument.tsx | 7 +- app/components/Sidebar/Sidebar.tsx | 94 ++++++++-- app/components/Table.tsx | 7 + app/components/Tabs/Tab.tsx | 3 + app/components/Tabs/Tabs.tsx | 28 ++- app/hooks/useSwipeToDismiss.ts | 175 ++++++++++++++++++ app/menus/TableOfContentsMenu.tsx | 6 +- app/scenes/Document/components/Document.tsx | 2 +- .../Document/components/DocumentTitle.tsx | 5 +- app/scenes/Document/components/Header.tsx | 9 +- .../Document/components/SharedHeader.tsx | 11 +- app/scenes/Document/hooks/useDocumentSave.ts | 60 +++--- app/scenes/Settings/Users.tsx | 11 +- app/scenes/Settings/components/SettingRow.tsx | 23 +++ .../Settings/components/StickyFilters.tsx | 15 ++ app/styles/animations.ts | 5 + shared/constants.ts | 3 + 27 files changed, 598 insertions(+), 70 deletions(-) create mode 100644 app/hooks/useSwipeToDismiss.ts diff --git a/app/components/Actions.ts b/app/components/Actions.ts index aff0f693c8..44db046c99 100644 --- a/app/components/Actions.ts +++ b/app/components/Actions.ts @@ -1,5 +1,6 @@ import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s } from "@shared/styles"; import Flex from "~/components/Flex"; @@ -10,6 +11,10 @@ export const Action = styled(Flex)` font-size: 15px; flex-shrink: 0; + ${breakpoint("mobile", "tablet")` + height: ${MOBILE_TOUCH_TARGET}px; + `}; + &:empty { display: none; } diff --git a/app/components/Button.tsx b/app/components/Button.tsx index 6bb3d8c9ad..ff7964948a 100644 --- a/app/components/Button.tsx +++ b/app/components/Button.tsx @@ -3,6 +3,8 @@ import { DisclosureIcon } from "outline-icons"; import { darken, lighten, transparentize } from "polished"; import * as React from "react"; import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s } from "@shared/styles"; import type { Props as ActionButtonProps } from "~/components/ActionButton"; import ActionButton from "~/components/ActionButton"; @@ -36,6 +38,12 @@ const RealButton = styled(ActionButton)` transition: background 200ms ease-out; ${undraggableOnDesktop()} + ${breakpoint("mobile", "tablet")` + height: ${MOBILE_TOUCH_TARGET}px; + border-radius: ${MOBILE_TOUCH_TARGET / 2}px; + font-size: 16px; + `}; + &::-moz-focus-inner { padding: 0; border: 0; @@ -126,11 +134,13 @@ const Label = styled.span<{ hasIcon?: boolean }>` ${(props) => props.hasIcon && "padding-inline-start: 4px;"}; `; -export const Inner = styled.span<{ +interface InnerProps { disclosure?: boolean; hasIcon?: boolean; hasText?: boolean; -}>` +} + +export const Inner = styled.span` display: flex; padding: 0 8px; padding-inline-end: ${(props) => (props.disclosure ? 2 : 8)}px; @@ -141,6 +151,18 @@ export const Inner = styled.span<{ ${(props) => props.hasIcon && props.hasText && "padding-inline-start: 4px;"}; ${(props) => props.hasIcon && !props.hasText && "padding: 0 4px;"}; + + ${breakpoint("mobile", "tablet")` + min-height: ${MOBILE_TOUCH_TARGET}px; + padding: 0 16px; + padding-inline-end: ${(props: InnerProps) => (props.disclosure ? 8 : 16)}px; + ${(props: InnerProps) => + props.hasIcon && props.hasText && "padding-inline-start: 12px;"}; + ${(props: InnerProps) => + props.hasIcon && + !props.hasText && + `padding: 0 ${(MOBILE_TOUCH_TARGET - 24) / 2}px;`}; + `}; `; export type Props = ActionButtonProps & { @@ -192,6 +214,7 @@ function Button( $danger={danger} $fullwidth={fullwidth} $borderOnHover={borderOnHover} + data-variant={danger ? "danger" : neutral ? "neutral" : "primary"} {...rest} > diff --git a/app/components/Collaborators.tsx b/app/components/Collaborators.tsx index 2eaece4f7a..fc9dda40ca 100644 --- a/app/components/Collaborators.tsx +++ b/app/components/Collaborators.tsx @@ -1,7 +1,9 @@ import { filter, isEqual, orderBy, uniq } from "es-toolkit/compat"; import { observer } from "mobx-react"; +import styled from "styled-components"; import { useState, useMemo, useEffect, useCallback } from "react"; import { useTranslation } from "react-i18next"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import type Document from "~/models/Document"; import type User from "~/models/User"; import type { AvatarProps } from "~/components/Avatar"; @@ -15,8 +17,12 @@ import { PopoverContent, } from "~/components/primitives/Popover"; import useCurrentUser from "~/hooks/useCurrentUser"; +import useMobile from "~/hooks/useMobile"; import useStores from "~/hooks/useStores"; +/** Space after the avatars on mobile, matching the inset of a 24px icon in a touch target. */ +const MobileIconInset = (MOBILE_TOUCH_TARGET - 24) / 2; + type Props = { /** The document to display live collaborators for */ document: Document; @@ -31,6 +37,8 @@ type Props = { function Collaborators(props: Props) { const { limit = 6 } = props; const { t } = useTranslation(); + const isMobile = useMobile(); + const size = isMobile ? AvatarSize.XLarge : AvatarSize.Large; const user = useCurrentUser(); const currentUserId = user?.id; const [requestedUserIds, setRequestedUserIds] = useState([]); @@ -163,21 +171,23 @@ function Collaborators(props: Props) { return null; } + const facepileWidth = Math.min(collaborators.length, limit) * size; + return ( - - + @@ -186,4 +196,9 @@ function Collaborators(props: Props) { ); } +const FacepileButton = styled(NudeButton)` + display: inline-flex; + align-items: center; +`; + export default observer(Collaborators); diff --git a/app/components/Facepile.tsx b/app/components/Facepile.tsx index 62a36e09cc..e257f06670 100644 --- a/app/components/Facepile.tsx +++ b/app/components/Facepile.tsx @@ -63,7 +63,7 @@ function Facepile({ model, size, style: { - marginRight: lastChild ? 0 : -4, + marginRight: lastChild ? 0 : -Math.round(size / 7), ...(lastChild || filtered.length === 1 ? {} : { clipPath: `url(#${clipPathId(size)})` }), diff --git a/app/components/FilterOptions.tsx b/app/components/FilterOptions.tsx index 99cf68c4a1..1475749137 100644 --- a/app/components/FilterOptions.tsx +++ b/app/components/FilterOptions.tsx @@ -3,6 +3,8 @@ import { CheckmarkIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s } from "@shared/styles"; import type { FetchPageParams } from "~/stores/base/Store"; import Button, { Inner } from "~/components/Button"; @@ -359,6 +361,16 @@ export const StyledButton = styled(Button)` line-height: 28px; min-height: auto; } + + ${breakpoint("mobile", "tablet")` + && { + height: ${MOBILE_TOUCH_TARGET}px; + } + + && ${Inner} { + min-height: ${MOBILE_TOUCH_TARGET}px; + } + `}; `; export default FilterOptions; diff --git a/app/components/Header.tsx b/app/components/Header.tsx index 575d2dcafc..b4548b65b4 100644 --- a/app/components/Header.tsx +++ b/app/components/Header.tsx @@ -6,11 +6,12 @@ import { transparentize } from "polished"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { mergeRefs } from "react-merge-refs"; -import styled from "styled-components"; +import styled, { css } from "styled-components"; +import type { DefaultTheme } from "styled-components"; import breakpoint from "styled-components-breakpoint"; import useMeasure from "react-use-measure"; -import { HEADER_HEIGHT } from "@shared/constants"; -import { depths, s } from "@shared/styles"; +import { HEADER_HEIGHT, MOBILE_TOUCH_TARGET } from "@shared/constants"; +import { depths, hover, s } from "@shared/styles"; import { metaDisplay } from "@shared/utils/keyboard"; import Button from "~/components/Button"; import Fade from "~/components/Fade"; @@ -164,6 +165,26 @@ function Header({ left, title, actions, hasSidebar, className, ref }: Props) { ); } +/** Height of the fade at the bottom of the mobile header background. */ +const HeaderFadeHeight = 64; + +/** Eased mask stops for the header fade, so it has no visible start or end. */ +const headerFadeStops = [1, 0.85, 0.5, 0.15, 0] + .map( + (opacity, index, stops) => + `rgb(0 0 0 / ${opacity}) calc(100% - ${HeaderFadeHeight * (1 - index / (stops.length - 1))}px)` + ) + .join(", "); + +/** Raised capsule that holds header buttons on mobile, like an iOS toolbar. */ +const mobilePill = css` + background: ${s("menuBackground")}; + box-shadow: + 0 0 0 1px ${s("divider")}, + 0 4px 12px rgb(0 0 0 / 8%); + border-radius: ${MOBILE_TOUCH_TARGET / 2}px; +`; + const Breadcrumbs = styled("div")` flex-grow: 1; flex-basis: 0; @@ -172,6 +193,20 @@ const Breadcrumbs = styled("div")` padding-inline: 0 8px; display: flex; + ${breakpoint("mobile", "tablet")` + gap: 8px; + + && [data-variant] { + ${mobilePill} + } + + && [data-variant]:${hover}:not(:disabled), + && [data-variant][aria-expanded="true"] { + ${mobilePill} + background: ${s("buttonNeutralBackground")}; + } + `}; + ${breakpoint("tablet")` min-width: auto; `}; @@ -185,6 +220,45 @@ const Actions = styled(Flex)` gap: 8px; margin-inline-start: 8px; + ${breakpoint("mobile", "tablet")` + flex: 0 0 auto; + gap: 0; + margin-inline-start: auto; + + &:not(:empty) { + ${mobilePill} + padding-inline: 10px; + } + + /* Touch targets overlap so icons sit closer than their 44px hit areas. */ + & > * { + margin-inline: -4px; + } + + && [data-variant] { + background: transparent; + box-shadow: none; + } + + && [data-variant="primary"] { + color: ${s("accent")}; + } + + && [data-variant="primary"]:disabled { + color: ${s("textTertiary")}; + + svg { + fill: currentColor; + } + } + + && [data-variant]:${hover}:not(:disabled), + && [data-variant][aria-expanded="true"] { + background: ${s("buttonNeutralBackground")}; + box-shadow: none; + } + `}; + ${breakpoint("tablet")` position: unset; `}; @@ -224,7 +298,7 @@ const Wrapper = styled(Flex)` backdrop-filter: blur(20px); `}; - padding: 12px 16px; + padding: 6px 16px; padding-inline-end: ${endPadding(16)}; transform: translate3d(0, 0, 0); min-height: ${HEADER_HEIGHT}px; @@ -249,6 +323,35 @@ const Wrapper = styled(Flex)` display: none; } + ${breakpoint("mobile", "tablet")` + ${(props: WrapperProps & { theme: DefaultTheme }) => + !props.$passThrough && + ` + background: transparent; + backdrop-filter: none; + + /* The blurred background extends past the header and fades out, so content blends under it. */ + &::before { + content: ""; + position: absolute; + inset: 0 0 -${HeaderFadeHeight / 2}px; + z-index: -1; + pointer-events: none; + background: ${transparentize(0.2, props.theme.background)}; + backdrop-filter: blur(20px); + mask-image: linear-gradient(to bottom, ${headerFadeStops}); + } + + /* A stuck tab bar continues the header, so the header is solid above it. */ + body:has([data-sticky-tabs][data-stuck]) &::before { + inset: 0; + background: ${props.theme.background}; + backdrop-filter: none; + mask-image: none; + } + `} + `}; + ${breakpoint("tablet")` padding: 12px; padding-inline-end: ${endPadding(12)}; @@ -282,7 +385,6 @@ const Title = styled("div")` `; const MobileMenuButton = styled(Button)` - margin-right: 8px; pointer-events: auto; @media print { diff --git a/app/components/Heading.ts b/app/components/Heading.ts index 940df0a7da..7660c9afdd 100644 --- a/app/components/Heading.ts +++ b/app/components/Heading.ts @@ -1,13 +1,21 @@ import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; +import { IconTitleWrapper } from "@shared/components/Icon"; const Heading = styled.h1<{ as?: string; centered?: boolean }>` display: flex; align-items: center; user-select: none; - ${(props) => (props.as ? "" : "margin-top: 8vh; font-weight: 600;")} + ${(props) => (props.as ? "" : "margin-top: 16px; font-weight: 600;")} ${(props) => (props.centered ? "text-align: center;" : "")} + /* On mobile the title icon sits above the title, so leave room for it. */ + ${breakpoint("mobile", "tablet")` + &:has(> ${IconTitleWrapper}) { + margin-top: 60px; + } + `}; + ${breakpoint("tablet")` ${(props: { as?: string }) => (props.as ? "" : "margin-top: 6vh;")} `}; diff --git a/app/components/Input.tsx b/app/components/Input.tsx index 579ab54dfe..84b1ae14c8 100644 --- a/app/components/Input.tsx +++ b/app/components/Input.tsx @@ -3,6 +3,7 @@ import * as React from "react"; import { mergeRefs } from "react-merge-refs"; import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s, ellipsis } from "@shared/styles"; import Flex from "~/components/Flex"; import Text from "~/components/Text"; @@ -75,6 +76,7 @@ export const NativeInput = styled.input<{ ${breakpoint("mobile", "tablet")` font-size: 16px; + height: ${MOBILE_TOUCH_TARGET - 2}px; `}; `; @@ -121,6 +123,11 @@ export const Outline = styled(Flex)<{ : props.theme.inputBorder}; border-radius: ${(props) => (props.$round ? "16px" : "4px")}; font-weight: normal; + + ${breakpoint("mobile", "tablet")` + ${(props: { $round?: boolean }) => + props.$round && `border-radius: ${MOBILE_TOUCH_TARGET / 2}px;`} + `}; align-items: center; overflow: hidden; background: ${s("background")}; diff --git a/app/components/InputSearchPage.tsx b/app/components/InputSearchPage.tsx index d4536df81a..beef0a9cd6 100644 --- a/app/components/InputSearchPage.tsx +++ b/app/components/InputSearchPage.tsx @@ -122,6 +122,8 @@ const InputMaxWidth = styled(Input).attrs({ round: true })` /* On mobile the input grows to fill the header, so add a gap before the * adjacent action button (e.g. "New doc"). */ ${breakpoint("mobile", "tablet")` + flex: 1; + min-width: 0; margin-inline-end: 8px; `} `; diff --git a/app/components/Menu/DropdownMenu.tsx b/app/components/Menu/DropdownMenu.tsx index 130256fd7d..313e1629b0 100644 --- a/app/components/Menu/DropdownMenu.tsx +++ b/app/components/Menu/DropdownMenu.tsx @@ -226,7 +226,7 @@ function MobileDropdown({ onAnimationStart={disablePointerEvents} onAnimationEnd={enablePointerEvents} > - {ariaLabel} + {content} {!submenuName ? append : null} diff --git a/app/components/PlaceholderDocument.tsx b/app/components/PlaceholderDocument.tsx index cdc16d90b3..53de3fa6a2 100644 --- a/app/components/PlaceholderDocument.tsx +++ b/app/components/PlaceholderDocument.tsx @@ -1,4 +1,5 @@ import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; import DelayedMount from "~/components/DelayedMount"; import Fade from "~/components/Fade"; import Flex from "~/components/Flex"; @@ -54,6 +55,10 @@ export default function PlaceholderDocument({ const Wrapper = styled(Fade)` display: block; - margin: 6vh 0; + margin: 0 0 6vh; padding: 12px 0; + + ${breakpoint("tablet")` + margin-top: 6vh; + `}; `; diff --git a/app/components/Sidebar/Sidebar.tsx b/app/components/Sidebar/Sidebar.tsx index 523ef45694..92a48964b5 100644 --- a/app/components/Sidebar/Sidebar.tsx +++ b/app/components/Sidebar/Sidebar.tsx @@ -12,9 +12,10 @@ import useEventListener from "~/hooks/useEventListener"; import useMobile from "~/hooks/useMobile"; import { useResizeHandle } from "~/hooks/useResizeHandle"; import useStores from "~/hooks/useStores"; +import { useSwipeToDismiss } from "~/hooks/useSwipeToDismiss"; import AccountMenu from "~/menus/AccountMenu"; import { fadeOnDesktopBackgrounded } from "~/styles"; -import { fadeIn } from "~/styles/animations"; +import { drawerTransition } from "~/styles/animations"; import Desktop from "~/utils/Desktop"; import NotificationIcon from "../Notifications/NotificationIcon"; import NotificationsPopover from "../Notifications/NotificationsPopover"; @@ -71,6 +72,7 @@ function Sidebar({ const isSmallerThanMinimum = width < minWidth; const hoverTimeoutRef = React.useRef(null); const internalRef = React.useRef(null); + const backdropRef = React.useRef(null); const mergedRef = React.useMemo(() => mergeRefs([internalRef, ref]), [ref]); const measure = React.useCallback( @@ -258,16 +260,17 @@ function Sidebar({ [ui, history] ); + // On mobile the width comes from the viewport, not the resizable desktop width. const style = React.useMemo( - () => ({ - width: `${width}px`, - }), - [width] + () => (isMobile ? undefined : { width: `${width}px` }), + [isMobile, width] ); - const handleCloseSidebar = () => { - ui.toggleMobileSidebar(); - }; + useSwipeToDismiss(internalRef, backdropRef, { + enabled: isMobile && ui.mobileSidebarVisible, + side: direction === "rtl" ? "right" : "left", + onDismiss: ui.hideMobileSidebar, + }); return ( @@ -316,18 +319,24 @@ function Sidebar({ )} - + {!isMobile && ( + + )} - {ui.mobileSidebarVisible && } + ); } -const Backdrop = styled.a` - animation: ${fadeIn} 250ms ease-in-out; +const Backdrop = styled.a<{ $visible: boolean }>` position: fixed; top: 0; left: 0; @@ -336,6 +345,13 @@ const Backdrop = styled.a` cursor: default; z-index: ${depths.mobileSidebar - 1}; background: ${s("backdrop")}; + opacity: ${(props) => (props.$visible ? 1 : 0)}; + pointer-events: ${(props) => (props.$visible ? "auto" : "none")}; + transition: opacity ${drawerTransition}; + + ${breakpoint("tablet")` + display: none; + `}; `; type ContainerProps = { @@ -372,7 +388,7 @@ const Container = styled(Flex)` background: ${s("sidebarBackground")}; transition: box-shadow 150ms ease-in-out, - transform 250ms cubic-bezier(0.34, 1.15, 0.64, 1) + transform ${drawerTransition} ${(props: ContainerProps) => props.$isAnimating ? `, width ${ANIMATION_MS}ms ease-out` : ""}; transform: translateX( @@ -382,8 +398,54 @@ const Container = styled(Flex)` max-width: 80%; min-width: 280px; padding-inline-start: var(--sal); + padding-bottom: var(--sab, 0px); ${fadeOnDesktopBackgrounded()} + ${breakpoint("mobile", "tablet")` + /* Leaves a strip of the page visible to tap and close, as in Material navigation drawers. */ + width: calc(100% - 56px); + max-width: 360px; + min-width: 0; + border-start-end-radius: 8px; + border-end-end-radius: 8px; + /* The negative spread keeps the shadow off the edge side, so a stretch cannot reveal it. */ + box-shadow: ${(props: ContainerProps) => + props.$mobileSidebarVisible + ? "12px 0 24px -12px rgb(0 0 0 / 16%)" + : "none"}; + + [dir="rtl"] & { + box-shadow: ${(props: ContainerProps) => + props.$mobileSidebarVisible + ? "-12px 0 24px -12px rgb(0 0 0 / 16%)" + : "none"}; + } + + @supports (corner-shape: superellipse(2)) { + border-start-end-radius: 14px; + border-end-end-radius: 14px; + corner-shape: superellipse(2); + } + + /* Fills the space behind the edge when the sidebar is stretched past open, + overlapping by a pixel so no seam shows at fractional offsets. */ + &::after { + content: ""; + position: absolute; + top: 0; + bottom: 0; + inset-inline-end: calc(100% - 1px); + width: 100%; + background: inherit; + } + + /* Horizontal gestures drag the sidebar closed, scroll containers inside reset the value. */ + &, + & * { + touch-action: pan-y pinch-zoom; + } + `}; + [dir="rtl"] & { transform: translateX( ${(props) => (props.$mobileSidebarVisible ? 0 : "100%")} diff --git a/app/components/Table.tsx b/app/components/Table.tsx index 0ede787e92..47b8ae289c 100644 --- a/app/components/Table.tsx +++ b/app/components/Table.tsx @@ -19,6 +19,8 @@ import * as React from "react"; import { useTranslation } from "react-i18next"; import { Waypoint } from "react-waypoint"; import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; +import { HEADER_HEIGHT as APP_HEADER_HEIGHT } from "@shared/constants"; import { s } from "@shared/styles"; import DelayedMount from "~/components/DelayedMount"; import Empty from "~/components/Empty"; @@ -717,6 +719,11 @@ const THead = styled.div<{ $topPos: number }>` border-bottom: 1px solid ${(props) => transparentize(0.3, props.theme.divider)}; background: ${s("background")}; + + ${breakpoint("mobile", "tablet")` + top: ${({ $topPos }: { $topPos: number }) => + `${Math.min($topPos, APP_HEADER_HEIGHT)}px`}; + `}; `; const TBody = styled.div<{ $height: number }>` diff --git a/app/components/Tabs/Tab.tsx b/app/components/Tabs/Tab.tsx index ac69ac36bf..8cfb47d1bf 100644 --- a/app/components/Tabs/Tab.tsx +++ b/app/components/Tabs/Tab.tsx @@ -6,6 +6,7 @@ import queryString from "query-string"; import * as React from "react"; import styled, { css, useTheme } from "styled-components"; import breakpoint from "styled-components-breakpoint"; +import { MOBILE_TOUCH_TARGET } from "@shared/constants"; import { s, hover } from "@shared/styles"; import NavLink from "~/components/NavLink"; @@ -60,9 +61,11 @@ const tabStyles = css` cursor: var(--pointer); user-select: none; padding: 12px 0; + min-height: ${MOBILE_TOUCH_TARGET}px; ${breakpoint("tablet")` padding: 6px 0; + min-height: 0; `}; `; diff --git a/app/components/Tabs/Tabs.tsx b/app/components/Tabs/Tabs.tsx index 8175761e38..5b16d26d3a 100644 --- a/app/components/Tabs/Tabs.tsx +++ b/app/components/Tabs/Tabs.tsx @@ -44,9 +44,12 @@ const Nav = styled.nav<{ $shadowVisible?: boolean }>` // When sticky we need extra background coverage around the sides otherwise // items that scroll past can "stick out" the sides of the heading +/** Offset from the top of the viewport at which the tab bar sticks. */ +const StickyTop = 54; + const Sticky = styled.div` position: sticky; - top: 54px; + top: ${StickyTop}px; margin: 0 -8px; padding: 0 8px; background: ${s("background")}; @@ -76,6 +79,7 @@ export const TabsGroup: React.FC = ({ children }: Props) => { export const Tabs: React.FC = ({ children }: Props) => { const ref = React.useRef(null); + const stickyRef = React.useRef(null); const [shadowVisible, setShadow] = React.useState(false); const { width } = useWindowSize(); @@ -97,9 +101,29 @@ export const Tabs: React.FC = ({ children }: Props) => { updateShadows(); }, [width, updateShadows]); + // Mark the tab bar while it is stuck so the header above can style itself to match. + React.useEffect(() => { + const sticky = stickyRef.current; + if (!sticky) { + return; + } + const observer = new IntersectionObserver( + ([entry]) => { + sticky.toggleAttribute( + "data-stuck", + entry.intersectionRatio < 1 && + entry.boundingClientRect.top <= StickyTop + 1 + ); + }, + { threshold: 1, rootMargin: `-${StickyTop + 1}px 0px 0px 0px` } + ); + observer.observe(sticky); + return () => observer.disconnect(); + }, []); + return ( - +

diff --git a/app/hooks/useSwipeToDismiss.ts b/app/hooks/useSwipeToDismiss.ts new file mode 100644 index 0000000000..be49b7cc50 --- /dev/null +++ b/app/hooks/useSwipeToDismiss.ts @@ -0,0 +1,175 @@ +import { useEffect } from "react"; +import type { RefObject } from "react"; + +interface Options { + /** Whether the panel is open and can be swiped away. */ + enabled: boolean; + /** The screen edge that the panel is attached to. */ + side: "left" | "right"; + /** Called when a swipe passes the dismiss threshold. */ + onDismiss: () => void; +} + +/** Distance in pixels a pointer must move before the gesture is a drag or a scroll. */ +const DragSlop = 8; + +/** Release speed in px/ms above which the panel is dismissed, matches vaul. */ +const VelocityThreshold = 0.4; + +/** Fraction of the panel width past which the panel is dismissed, matches vaul. */ +const CloseThreshold = 0.25; + +/** Rubber band resistance for a drag away from the edge, matches vaul. */ +const dampen = (value: number) => Math.max(8 * (Math.log(value + 1) - 2), 0); + +/** + * Lets the user drag an edge-attached panel toward its edge to dismiss it, with + * the same thresholds as the vaul drawer. The panel follows the pointer, and on + * release it either dismisses or springs back using the CSS transition of the + * panel. A vertical gesture is left to the browser so that the panel can scroll. + * + * @param panelRef ref to the panel element that moves. + * @param overlayRef ref to an optional backdrop that fades as the panel moves. + * @param options the swipe options. + */ +export function useSwipeToDismiss( + panelRef: RefObject, + overlayRef: RefObject, + { enabled, side, onDismiss }: Options +) { + useEffect(() => { + const panel = panelRef.current; + if (!enabled || !panel) { + return; + } + const overlay = overlayRef.current; + const sign = side === "left" ? -1 : 1; + + let start: { x: number; y: number; time: number } | null = null; + let isDragging = false; + let width = 0; + let distance = 0; + + const setStyles = ( + transition: string, + transform: string, + opacity: string + ) => { + panel.style.transition = transition; + panel.style.transform = transform; + if (overlay) { + overlay.style.transition = transition; + overlay.style.opacity = opacity; + } + }; + + const suppressClick = (event: MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + }; + + const handlePointerDown = (event: PointerEvent) => { + if (!event.isPrimary || event.button !== 0) { + return; + } + start = { x: event.clientX, y: event.clientY, time: event.timeStamp }; + isDragging = false; + distance = 0; + }; + + const handlePointerMove = (event: PointerEvent) => { + if (!start || !event.isPrimary) { + return; + } + const dx = event.clientX - start.x; + const dy = event.clientY - start.y; + + if (!isDragging) { + if (Math.abs(dx) < DragSlop && Math.abs(dy) < DragSlop) { + return; + } + + // A mostly vertical gesture is a scroll, so leave it to the browser. + if (Math.abs(dy) >= Math.abs(dx)) { + start = null; + return; + } + isDragging = true; + width = panel.getBoundingClientRect().width; + panel.setPointerCapture(event.pointerId); + } + + // A drag away from the edge stretches with resistance. Whole pixels + // stop a visible line where the panel meets its fill. + const dragged = dx * sign; + distance = Math.round( + dragged >= 0 ? Math.min(dragged, width) : -dampen(-dragged) + ); + setStyles( + "none", + `translateX(${distance * sign}px)`, + String(1 - Math.max(distance, 0) / width) + ); + }; + + const handlePointerUp = (event: PointerEvent) => { + if (!event.isPrimary) { + return; + } + if (!start || !isDragging) { + start = null; + return; + } + const velocity = + Math.abs(event.clientX - start.x) / + Math.max(event.timeStamp - start.time, 1); + start = null; + isDragging = false; + + // The pointer moved, so the click that follows is not a tap. + panel.addEventListener("click", suppressClick, { + capture: true, + once: true, + }); + setTimeout(() => { + panel.removeEventListener("click", suppressClick, { capture: true }); + }, 0); + + if ( + distance > 0 && + (velocity > VelocityThreshold || distance >= width * CloseThreshold) + ) { + // Hold the closed position until the closed styles apply, then the + // cleanup below removes the inline styles. + setStyles("", `translateX(${sign * 100}%)`, "0"); + onDismiss(); + return; + } + setStyles("", "", ""); + }; + + const handlePointerCancel = (event: PointerEvent) => { + if (!event.isPrimary) { + return; + } + if (isDragging) { + setStyles("", "", ""); + } + start = null; + isDragging = false; + }; + + panel.addEventListener("pointerdown", handlePointerDown); + panel.addEventListener("pointermove", handlePointerMove); + panel.addEventListener("pointerup", handlePointerUp); + panel.addEventListener("pointercancel", handlePointerCancel); + + return () => { + panel.removeEventListener("pointerdown", handlePointerDown); + panel.removeEventListener("pointermove", handlePointerMove); + panel.removeEventListener("pointerup", handlePointerUp); + panel.removeEventListener("pointercancel", handlePointerCancel); + setStyles("", "", ""); + }; + }, [panelRef, overlayRef, enabled, side, onDismiss]); +} diff --git a/app/menus/TableOfContentsMenu.tsx b/app/menus/TableOfContentsMenu.tsx index 74cee2f55a..e400eba13c 100644 --- a/app/menus/TableOfContentsMenu.tsx +++ b/app/menus/TableOfContentsMenu.tsx @@ -98,7 +98,11 @@ function TableOfContentsMenu() { const rootAction = useMenuAction(actions); return ( - + )} + {isMobile && ( + + + + )} - ) : null - ) : hasSidebar ? ( + isMobile ? null : hasSidebar ? ( + {hasHeadings && isMobile && ( + + + + )} {hasHeadings && !isMobile && !tocInLeft && {toc}} {allowSubscriptions !== false && env.EMAIL_ENABLED && ( diff --git a/app/scenes/Document/hooks/useDocumentSave.ts b/app/scenes/Document/hooks/useDocumentSave.ts index ce5908bd28..a341a3ae2c 100644 --- a/app/scenes/Document/hooks/useDocumentSave.ts +++ b/app/scenes/Document/hooks/useDocumentSave.ts @@ -338,35 +338,49 @@ export function useDocumentSave({ }, [readOnly, updateIsDirty]); // Auto-delete/auto-save on unmount + debounce cleanup - useEffect( - () => () => { + const isMountedRef = useRef(false); + useEffect(() => { + isMountedRef.current = true; + + return () => { + isMountedRef.current = false; autosave.cancel(); + + // Read the editor now, as it may be destroyed by the time the check runs. + // oxlint-disable-next-line react-hooks/exhaustive-deps const currentDoc = editorRef.current?.view.state.doc; const isEditorEmpty = !currentDoc || ProsemirrorHelper.isEmpty(currentDoc); + const currentTitle = titleRef.current; - if ( - shouldAutoDeleteDraftOnUnmount({ - isEditorEmpty, - title: titleRef.current, - createdById: document.createdBy?.id, - currentUserId: auth.user?.id, - isDraft: document.isDraft, - isActive: document.isActive, - hasEmptyTitle: document.hasEmptyTitle, - isPersistedOnce: document.isPersistedOnce, - }) - ) { - void document.delete(); - } else if (document.isDirty()) { - void document.save(undefined, { - autosave: true, - }); - } - }, + // Defer the check so that a StrictMode remount does not count as an unmount. + queueMicrotask(() => { + if (isMountedRef.current) { + return; + } + + if ( + shouldAutoDeleteDraftOnUnmount({ + isEditorEmpty, + title: currentTitle, + createdById: document.createdBy?.id, + currentUserId: auth.user?.id, + isDraft: document.isDraft, + isActive: document.isActive, + hasEmptyTitle: document.hasEmptyTitle, + isPersistedOnce: document.isPersistedOnce, + }) + ) { + void document.delete(); + } else if (document.isDirty()) { + void document.save(undefined, { + autosave: true, + }); + } + }); + }; // oxlint-disable-next-line react-hooks/exhaustive-deps - [] - ); + }, []); return { isUploading, diff --git a/app/scenes/Settings/Users.tsx b/app/scenes/Settings/Users.tsx index 2d9aa06d3b..df5c1b3def 100644 --- a/app/scenes/Settings/Users.tsx +++ b/app/scenes/Settings/Users.tsx @@ -7,6 +7,7 @@ import { Trans, useTranslation } from "react-i18next"; import { useHistory, useLocation } from "react-router-dom"; import { toast } from "sonner"; import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; import type { Filter } from "@shared/helpers/FilterHelper"; import type UsersStore from "~/stores/UsersStore"; import { queriedUsers } from "~/stores/UsersStore"; @@ -155,7 +156,7 @@ function Users() { - + - + @@ -268,6 +269,12 @@ function getFilteredUsers({ return filteredUsers; } +const FilterGroup = styled(HStack)` + ${breakpoint("mobile", "tablet")` + display: contents; + `}; +`; + const LargeUserStatusFilter = styled(UserStatusFilter)` height: 32px; `; diff --git a/app/scenes/Settings/components/SettingRow.tsx b/app/scenes/Settings/components/SettingRow.tsx index 9d4de82789..bf53f2adab 100644 --- a/app/scenes/Settings/components/SettingRow.tsx +++ b/app/scenes/Settings/components/SettingRow.tsx @@ -27,6 +27,29 @@ const Row = styled(Flex)<{ $border?: boolean; $compact?: boolean }>` &:last-child { border-bottom: 0; } + + ${breakpoint("mobile", "tablet")` + &:has([role="switch"]) { + gap: 16px; + + > :first-child { + min-width: 0; + } + + > :last-child { + flex: 0 0 auto; + } + } + + &:not(:has([role="switch"])) { + flex-direction: column; + gap: 12px; + + > :last-child > * { + align-self: stretch; + } + } + `}; `; const Column = styled.div` diff --git a/app/scenes/Settings/components/StickyFilters.tsx b/app/scenes/Settings/components/StickyFilters.tsx index 2dfe99b294..e878840c7e 100644 --- a/app/scenes/Settings/components/StickyFilters.tsx +++ b/app/scenes/Settings/components/StickyFilters.tsx @@ -1,6 +1,8 @@ import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; import { depths, s } from "@shared/styles"; import { HEADER_HEIGHT } from "~/components/Header"; +import { Wrapper as InputWrapper } from "~/components/Input"; import { HStack } from "~/components/primitives/HStack"; export const FILTER_HEIGHT = 40; @@ -11,4 +13,17 @@ export const StickyFilters = styled(HStack)` top: ${HEADER_HEIGHT}px; z-index: ${depths.header}; background: ${s("background")}; + + ${breakpoint("mobile", "tablet")` + position: static; + height: auto; + flex-wrap: wrap; + justify-content: flex-start; + padding-block: 8px; + + ${InputWrapper} { + flex: 1 1 100%; + max-width: none; + } + `}; `; diff --git a/app/styles/animations.ts b/app/styles/animations.ts index 88e123bd73..e8170960c1 100644 --- a/app/styles/animations.ts +++ b/app/styles/animations.ts @@ -148,3 +148,8 @@ export const pulse = keyframes` * The duration of the sidebar appearing animation in ms */ export const sidebarAppearDuration = 600; + +/** + * The duration and easing of the vaul drawer, shared so that panels move the same way. + */ +export const drawerTransition = "500ms cubic-bezier(0.32, 0.72, 0, 1)"; diff --git a/shared/constants.ts b/shared/constants.ts index 2264b3594d..129fd6953b 100644 --- a/shared/constants.ts +++ b/shared/constants.ts @@ -19,6 +19,9 @@ export const MAX_AVATAR_DISPLAY = 6; /** Height of the app's fixed header in pixels. */ export const HEADER_HEIGHT = 56; +/** Minimum size of touch targets on mobile in pixels, from Apple's guidelines. */ +export const MOBILE_TOUCH_TARGET = 44; + /** Preset colors offered when choosing an icon color. */ export const colorPalette = [ "#4E5C6E", From 71c3f790187b3924861e96aa5dca3e6f5fae9d93 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 20 Oct 2026 19:25:34 -0400 Subject: [PATCH 25/38] fix: Allow every mention notification to be turned off and unsubscribed (#14146) * fix: Allow every mention notification to be turned off and unsubscribed - The Mentioned and Group mentions settings now control both the document and comment event types. - Mention, share, collection invite, and access request emails now have an unsubscribe link and List-Unsubscribe header. * Remove test --- app/scenes/Settings/Notifications.tsx | 70 +++++++++++-------- .../templates/CollectionSharedEmail.tsx | 16 ++++- .../templates/DocumentAccessRequestEmail.tsx | 16 +++++ .../templates/DocumentMentionedEmail.tsx | 16 ++++- .../emails/templates/DocumentSharedEmail.tsx | 16 ++++- .../templates/GroupDocumentMentionedEmail.tsx | 17 ++++- server/queues/processors/EmailsProcessor.ts | 2 + 7 files changed, 121 insertions(+), 32 deletions(-) diff --git a/app/scenes/Settings/Notifications.tsx b/app/scenes/Settings/Notifications.tsx index 0ffabbe29f..b55b658207 100644 --- a/app/scenes/Settings/Notifications.tsx +++ b/app/scenes/Settings/Notifications.tsx @@ -36,7 +36,7 @@ function Notifications() { const options = [ { - event: NotificationEventType.PublishDocument, + events: [NotificationEventType.PublishDocument], icon: , title: t("Document published"), description: t( @@ -44,7 +44,7 @@ function Notifications() { ), }, { - event: NotificationEventType.UpdateDocument, + events: [NotificationEventType.UpdateDocument], icon: , title: t("Document updated"), description: t( @@ -52,7 +52,7 @@ function Notifications() { ), }, { - event: NotificationEventType.CreateComment, + events: [NotificationEventType.CreateComment], icon: , title: t("Comment posted"), description: t( @@ -60,7 +60,10 @@ function Notifications() { ), }, { - event: NotificationEventType.MentionedInComment, + events: [ + NotificationEventType.MentionedInComment, + NotificationEventType.MentionedInDocument, + ], icon: , title: t("Mentioned"), description: t( @@ -68,7 +71,10 @@ function Notifications() { ), }, { - event: NotificationEventType.GroupMentionedInDocument, + events: [ + NotificationEventType.GroupMentionedInDocument, + NotificationEventType.GroupMentionedInComment, + ], icon: , title: t("Group mentions"), description: t( @@ -76,7 +82,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ResolveComment, + events: [NotificationEventType.ResolveComment], icon: , title: t("Resolved"), description: t( @@ -84,7 +90,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ReactionsCreate, + events: [NotificationEventType.ReactionsCreate], icon: , title: t("Reaction added"), description: t( @@ -92,7 +98,7 @@ function Notifications() { ), }, { - event: NotificationEventType.CreateCollection, + events: [NotificationEventType.CreateCollection], icon: , title: t("Collection created"), description: t( @@ -100,7 +106,7 @@ function Notifications() { ), }, { - event: NotificationEventType.InviteAccepted, + events: [NotificationEventType.InviteAccepted], icon: , title: t("Invite accepted"), description: t( @@ -108,7 +114,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToDocument, + events: [NotificationEventType.AddUserToDocument], icon: , title: t("Invited to document"), description: t( @@ -116,7 +122,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToCollection, + events: [NotificationEventType.AddUserToCollection], icon: , title: t("Invited to collection"), description: t( @@ -124,7 +130,7 @@ function Notifications() { ), }, { - event: NotificationEventType.AddUserToGroup, + events: [NotificationEventType.AddUserToGroup], icon: , title: t("Group membership"), description: t( @@ -132,7 +138,7 @@ function Notifications() { ), }, { - event: NotificationEventType.ExportCompleted, + events: [NotificationEventType.ExportCompleted], icon: , title: t("Export completed"), description: t( @@ -140,7 +146,7 @@ function Notifications() { ), }, { - event: NotificationEventType.RequestDocumentAccess, + events: [NotificationEventType.RequestDocumentAccess], icon: , title: t("Document access requested"), description: t( @@ -150,14 +156,14 @@ function Notifications() { { visible: isCloudHosted, icon: , - event: NotificationEventType.Onboarding, + events: [NotificationEventType.Onboarding], title: t("Getting started"), description: t("Tips on getting started with features and functionality"), }, { visible: isCloudHosted, icon: , - event: NotificationEventType.Features, + events: [NotificationEventType.Features], title: t("New features"), description: t("Receive an email when new features of note are added"), }, @@ -170,8 +176,11 @@ function Notifications() { }, 500); const handleChange = React.useCallback( - (eventType: NotificationEventType) => async (checked: boolean) => { - await user.setNotificationEventType(eventType, checked); + (eventTypes: NotificationEventType[]) => async (checked: boolean) => { + // Sequential, as each request saves the full settings object. + for (const eventType of eventTypes) { + await user.setNotificationEventType(eventType, checked); + } showSuccessMessage(); }, [user, showSuccessMessage] @@ -182,7 +191,9 @@ function Notifications() { runInAction(() => { const updated = { ...user.notificationSettings }; for (const option of visibleOptions) { - updated[option.event] = checked; + for (const eventType of option.events) { + updated[eventType] = checked; + } } user.notificationSettings = updated; }); @@ -197,7 +208,7 @@ function Notifications() { ); const allEnabled = visibleOptions.every((o) => - user.subscribedToEventType(o.event) + o.events.every((eventType) => user.subscribedToEventType(eventType)) ); const showSuccessNotice = window.location.search === "?success"; @@ -231,14 +242,17 @@ function Notifications() { {options.map((option) => { - const setting = user.subscribedToEventType(option.event); + const [name] = option.events; + const checked = option.events.every((eventType) => + user.subscribedToEventType(eventType) + ); return ( {option.description} @@ -247,11 +261,11 @@ function Notifications() { compact > ); diff --git a/server/emails/templates/CollectionSharedEmail.tsx b/server/emails/templates/CollectionSharedEmail.tsx index 22b4e2ad8d..02457190f1 100644 --- a/server/emails/templates/CollectionSharedEmail.tsx +++ b/server/emails/templates/CollectionSharedEmail.tsx @@ -1,11 +1,13 @@ import * as React from "react"; -import { CollectionPermission } from "@shared/types"; +import { CollectionPermission, NotificationEventType } from "@shared/types"; import { Collection, UserMembership } from "@server/models"; +import NotificationSettingsHelper from "@server/models/helpers/NotificationSettingsHelper"; import type { EmailProps } from "./BaseEmail"; import BaseEmail, { EmailMessageCategory } from "./BaseEmail"; import Body from "./components/Body"; import Button from "./components/Button"; import EmailTemplate from "./components/EmailLayout"; +import Footer from "./components/Footer"; import Header from "./components/Header"; import Heading from "./components/Heading"; @@ -53,6 +55,13 @@ export default class CollectionSharedEmail extends BaseEmail< return { collection, membership }; } + protected unsubscribeUrl({ userId }: InputProps) { + return NotificationSettingsHelper.unsubscribeUrl( + userId, + NotificationEventType.AddUserToCollection + ); + } + protected subject({ actorName, collection }: Props) { return this.t( "{{ actorName }} invited you to the “{{ collectionName }}” collection", @@ -111,6 +120,11 @@ ${this.t("View Collection")}: ${teamUrl}${collection.path}

+ +