From 722610998924b8ed9da54177682ef7f273292fd0 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Oct 2024 19:23:01 -0400 Subject: [PATCH 001/120] perf: Avoid expensive DocumentHelper.toMarkdown call in presenter --- server/presenters/document.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/presenters/document.ts b/server/presenters/document.ts index 745aa9fac9..792095363f 100644 --- a/server/presenters/document.ts +++ b/server/presenters/document.ts @@ -41,7 +41,7 @@ async function presentDocument( const text = !asData || options?.includeText - ? DocumentHelper.toMarkdown(data) + ? document.text || DocumentHelper.toMarkdown(data) : undefined; const res: Record = { From 02c29e06fb27abc95dbb7071c44437b6b042d911 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Oct 2024 20:24:49 -0400 Subject: [PATCH 002/120] perf: filter -> find to reduce policies iterated through (#7816) --- server/policies/utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/policies/utils.ts b/server/policies/utils.ts index 5ed3399b98..176b9b9bbc 100644 --- a/server/policies/utils.ts +++ b/server/policies/utils.ts @@ -11,8 +11,7 @@ export function and(...args: Args[]) { } export function or(...args: Args[]) { - const filtered = args.filter(Boolean); - return filtered.length > 0 ? filtered : false; + return args.find(Boolean) || false; } /** From 597106cb489bce73ccc74f3f998a7634d8b4179a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:25:27 -0700 Subject: [PATCH 003/120] chore(deps): bump prosemirror-transform from 1.10.0 to 1.10.2 (#7813) Bumps [prosemirror-transform](https://github.com/prosemirror/prosemirror-transform) from 1.10.0 to 1.10.2. - [Changelog](https://github.com/ProseMirror/prosemirror-transform/blob/master/CHANGELOG.md) - [Commits](https://github.com/prosemirror/prosemirror-transform/compare/1.10.0...1.10.2) --- updated-dependencies: - dependency-name: prosemirror-transform 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 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 428d7ed5ea..064ff0e83b 100644 --- a/package.json +++ b/package.json @@ -182,7 +182,7 @@ "prosemirror-schema-list": "^1.4.1", "prosemirror-state": "^1.4.3", "prosemirror-tables": "^1.4.0", - "prosemirror-transform": "^1.10.0", + "prosemirror-transform": "^1.10.2", "prosemirror-view": "^1.34.3", "query-string": "^7.1.3", "randomstring": "1.3.0", diff --git a/yarn.lock b/yarn.lock index fd8f0ee159..608d636298 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12596,10 +12596,10 @@ prosemirror-tables@^1.4.0: prosemirror-transform "^1.2.1" prosemirror-view "^1.13.3" -prosemirror-transform@^1.0.0, prosemirror-transform@^1.1.0, prosemirror-transform@^1.10.0, prosemirror-transform@^1.2.1, prosemirror-transform@^1.7.3: - version "1.10.0" - resolved "https://registry.yarnpkg.com/prosemirror-transform/-/prosemirror-transform-1.10.0.tgz#2211ddcb13f12e4e530de97c077f82ab46177b0c" - integrity sha512-9UOgFSgN6Gj2ekQH5CTDJ8Rp/fnKR2IkYfGdzzp5zQMFsS4zDllLVx/+jGcX86YlACpG7UR5fwAXiWzxqWtBTg== +prosemirror-transform@^1.0.0, prosemirror-transform@^1.1.0, prosemirror-transform@^1.10.2, prosemirror-transform@^1.2.1, prosemirror-transform@^1.7.3: + version "1.10.2" + resolved "https://registry.yarnpkg.com/prosemirror-transform/-/prosemirror-transform-1.10.2.tgz#8ebac4e305b586cd96595aa028118c9191bbf052" + integrity sha512-2iUq0wv2iRoJO/zj5mv8uDUriOHWzXRnOTVgCzSXnktS/2iQRa3UUQwVlkBlYZFtygw6Nh1+X4mGqoYBINn5KQ== dependencies: prosemirror-model "^1.21.0" From c0fba3913cef088de66333a3570e9df605dc92de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:25:37 -0700 Subject: [PATCH 004/120] chore(deps-dev): bump @types/turndown from 5.0.4 to 5.0.5 (#7812) Bumps [@types/turndown](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/turndown) from 5.0.4 to 5.0.5. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/turndown) --- updated-dependencies: - dependency-name: "@types/turndown" dependency-type: direct:development 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 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 064ff0e83b..4d5be73914 100644 --- a/package.json +++ b/package.json @@ -316,7 +316,7 @@ "@types/styled-components": "^5.1.32", "@types/throng": "^5.0.7", "@types/tmp": "^0.2.6", - "@types/turndown": "^5.0.4", + "@types/turndown": "^5.0.5", "@types/utf8": "^3.0.3", "@types/validator": "^13.12.1", "@types/yauzl": "^2.10.3", diff --git a/yarn.lock b/yarn.lock index 608d636298..7b37d42878 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5080,10 +5080,10 @@ resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756" integrity "sha1-/CWtmUO8rBHM64Fo208nXg5y51Y= sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==" -"@types/turndown@^5.0.4": - version "5.0.4" - resolved "https://registry.yarnpkg.com/@types/turndown/-/turndown-5.0.4.tgz#61fcdda2e539a86b1d40cb3277505f22ca76f014" - integrity "sha1-YfzdouU5qGsdQMsyd1BfIsp28BQ= sha512-28GI33lCCkU4SGH1GvjDhFgOVr+Tym4PXGBIU1buJUa6xQolniPArtUT+kv42RR2N9MsMLInkr904Aq+ESHBJg==" +"@types/turndown@^5.0.5": + version "5.0.5" + resolved "https://registry.yarnpkg.com/@types/turndown/-/turndown-5.0.5.tgz#614de24fc9ace4d8c0d9483ba81dc8c1976dd26f" + integrity sha512-TL2IgGgc7B5j78rIccBtlYAnkuv8nUQqhQc+DSYV5j9Be9XOcm/SKOVRuA47xAVI3680Tk9B1d8flK2GWT2+4w== "@types/unist@*": version "2.0.6" From 3523ee4c35a07f82012893249a4138c405e8e555 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:25:51 -0700 Subject: [PATCH 005/120] chore(deps-dev): bump @relative-ci/agent from 4.2.9 to 4.2.12 (#7810) Bumps [@relative-ci/agent](https://github.com/relative-ci/agent) from 4.2.9 to 4.2.12. - [Release notes](https://github.com/relative-ci/agent/releases) - [Commits](https://github.com/relative-ci/agent/compare/v4.2.9...v4.2.12) --- updated-dependencies: - dependency-name: "@relative-ci/agent" dependency-type: direct:development 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 | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 4d5be73914..b4a66dc438 100644 --- a/package.json +++ b/package.json @@ -253,7 +253,7 @@ "@babel/cli": "^7.23.4", "@babel/preset-typescript": "^7.24.1", "@faker-js/faker": "^8.4.1", - "@relative-ci/agent": "^4.2.9", + "@relative-ci/agent": "^4.2.12", "@testing-library/react": "^12.0.0", "@types/addressparser": "^1.0.3", "@types/body-scroll-lock": "^3.1.2", diff --git a/yarn.lock b/yarn.lock index 7b37d42878..dbe129de71 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1792,18 +1792,18 @@ dependencies: "@bull-board/api" "4.12.2" -"@bundle-stats/plugin-webpack-filter@4.13.3": - version "4.13.3" - resolved "https://registry.yarnpkg.com/@bundle-stats/plugin-webpack-filter/-/plugin-webpack-filter-4.13.3.tgz#319cc922c306ae735fdd7d144e76e8b762e760aa" - integrity sha512-jMMt2Hz5FgHMBT+52L2zsB14RJBLVjV9UxnFhpd8iH1JWgxTvQFmUG/FpubMdzhIXZx6QAHFslrtCSExgMYgtQ== +"@bundle-stats/plugin-webpack-filter@4.15.1": + version "4.15.1" + resolved "https://registry.yarnpkg.com/@bundle-stats/plugin-webpack-filter/-/plugin-webpack-filter-4.15.1.tgz#486771ba1ff2233212862d87532ebe53553dc7ca" + integrity sha512-NCQy/KvCeGNyRfcB4IoMFIfCmA4U448rHCnVIV5l4xr1QAaeVR2fQqdhoNZEzwKvsmbpfEk3fTwNuB7ZPIGBhw== -"@bundle-stats/plugin-webpack-validate@4.13.3": - version "4.13.3" - resolved "https://registry.yarnpkg.com/@bundle-stats/plugin-webpack-validate/-/plugin-webpack-validate-4.13.3.tgz#c9534bcaae628fa07d7350f46cae5a40a75428e6" - integrity sha512-R7qGmWsWq5rhv/Zu6pS+d1S29gV1rxogl/udmbH/L4LysX+TxcotFENsCKn9J7nNBlmLyqDVZpynfGm14ywXjg== +"@bundle-stats/plugin-webpack-validate@4.15.1": + version "4.15.1" + resolved "https://registry.yarnpkg.com/@bundle-stats/plugin-webpack-validate/-/plugin-webpack-validate-4.15.1.tgz#c67c60eb837d09d1eedc8769cef45608fa29b334" + integrity sha512-VycwooUWK3yCAWK2fKN7Qr2ies+Ujzvq0LmAs7zYUUkCKfQgBeyY/vLfq8WrsS17poVJ+05XCJQavQm6IQEldg== dependencies: lodash "4.17.21" - superstruct "1.0.4" + superstruct "2.0.2" "@chakra-ui/counter@^1.2.5": version "1.2.10" @@ -3361,16 +3361,16 @@ dependencies: "@react-types/shared" "^3.14.1" -"@relative-ci/agent@^4.2.9": - version "4.2.9" - resolved "https://registry.yarnpkg.com/@relative-ci/agent/-/agent-4.2.9.tgz#c69a9524886fb54e307dd5ae831fc9c6207d7b08" - integrity sha512-VrpE0eHi6DMVnfS5epTzo6Z9aGC3l7QuwqP/h2NQrpKMyXfLjqBrYNVzttHueIqxvLP9FzBXmpYm7OxjcTYJuQ== +"@relative-ci/agent@^4.2.12": + version "4.2.12" + resolved "https://registry.yarnpkg.com/@relative-ci/agent/-/agent-4.2.12.tgz#de1b9697aaad78c79a3b802059e7bb69a63dc473" + integrity sha512-391B0ABbQYexBe0CHTd8QiQuW5o/qKZRdhdR+rHe0MJpmYSXFEI54pU/EJgZByAjm5c1TYKXafyn0mMAMZ0iKQ== dependencies: - "@bundle-stats/plugin-webpack-filter" "4.13.3" - "@bundle-stats/plugin-webpack-validate" "4.13.3" - core-js "3.37.1" + "@bundle-stats/plugin-webpack-filter" "4.15.1" + "@bundle-stats/plugin-webpack-validate" "4.15.1" + core-js "3.38.1" cosmiconfig "9.0.0" - debug "4.3.5" + debug "4.3.7" dotenv "16.4.5" env-ci "7.3.0" fs-extra "11.2.0" @@ -6660,10 +6660,10 @@ core-js-compat@^3.38.0, core-js-compat@^3.38.1, core-js-compat@^3.9.1: dependencies: browserslist "^4.23.3" -core-js@3.37.1, core-js@^3.37.0: - version "3.37.1" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.37.1.tgz#d21751ddb756518ac5a00e4d66499df981a62db9" - integrity sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw== +core-js@3.38.1, core-js@^3.37.0: + version "3.38.1" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.38.1.tgz#aa375b79a286a670388a1a363363d53677c0383e" + integrity sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw== core-js@^2.4.0: version "2.6.11" @@ -7244,7 +7244,7 @@ de-indent@^1.0.2: resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d" integrity "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0= sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==" -debug@4, debug@4.3.4, debug@4.3.5, debug@^2.2.0, debug@^2.6.8, debug@^3.1.0, debug@^3.2.7, debug@^4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@^4.3.5, debug@~4.3.1, debug@~4.3.2: +debug@4, debug@4.3.4, debug@4.3.7, debug@^2.2.0, debug@^2.6.8, debug@^3.1.0, debug@^3.2.7, debug@^4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@^4.3.5, debug@~4.3.1, debug@~4.3.2: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity "sha1-Exn2V5NX8jONMzfSzdSRS7XcyGU= sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==" @@ -14179,10 +14179,10 @@ stylis@^4.1.2: resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.1.3.tgz#fd2fbe79f5fed17c55269e16ed8da14c84d069f7" integrity "sha1-/S++efX+0XxVJp4W7Y2hTITQafc= sha512-GP6WDNWf+o403jrEp9c5jibKavrtLW+/qYGhFxFrG8maXhwTBI7gLLhiBb0o7uFccWN+EOS9aMO6cGHWAO07OA==" -superstruct@1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-1.0.4.tgz#0adb99a7578bd2f1c526220da6571b2d485d91ca" - integrity sha512-7JpaAoX2NGyoFlI9NBh66BQXGONc+uE+MRS5i2iOBKuS4e+ccgMDjATgZldkah+33DakBxDHiss9kvUcGAO8UQ== +superstruct@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-2.0.2.tgz#3f6d32fbdc11c357deff127d591a39b996300c54" + integrity sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A== supports-color@^2.0.0: version "2.0.0" From 0e75edf7e3eaaf725982afaf4654dfac6638ed75 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:50:32 -0700 Subject: [PATCH 006/120] chore(deps): bump prosemirror-markdown from 1.13.0 to 1.13.1 (#7811) * chore(deps): bump prosemirror-markdown from 1.13.0 to 1.13.1 Bumps [prosemirror-markdown](https://github.com/prosemirror/prosemirror-markdown) from 1.13.0 to 1.13.1. - [Changelog](https://github.com/ProseMirror/prosemirror-markdown/blob/master/CHANGELOG.md) - [Commits](https://github.com/prosemirror/prosemirror-markdown/compare/1.13.0...1.13.1) --- updated-dependencies: - dependency-name: prosemirror-markdown dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * tsc --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom Moor --- package.json | 4 +-- shared/editor/lib/ExtensionManager.ts | 4 +-- shared/editor/marks/Link.tsx | 2 +- shared/editor/nodes/Attachment.tsx | 2 +- shared/editor/nodes/CheckboxItem.ts | 2 +- shared/editor/nodes/CodeFence.ts | 2 +- shared/editor/nodes/Embed.tsx | 2 +- shared/editor/nodes/Emoji.tsx | 2 +- shared/editor/nodes/HorizontalRule.ts | 2 +- shared/editor/nodes/Image.tsx | 2 +- shared/editor/nodes/Mention.ts | 2 +- shared/editor/nodes/Notice.tsx | 2 +- shared/editor/nodes/OrderedList.ts | 2 +- shared/editor/nodes/SimpleImage.tsx | 2 +- shared/editor/nodes/TableCell.ts | 2 +- shared/editor/nodes/TableHeader.ts | 2 +- shared/editor/nodes/Video.tsx | 2 +- shared/editor/rules/breaks.ts | 11 ++++---- shared/editor/rules/checkboxes.ts | 3 +-- shared/editor/rules/embeds.ts | 5 ++-- shared/editor/rules/links.ts | 7 +++-- shared/editor/rules/mark.ts | 4 +-- shared/editor/rules/math.ts | 4 +-- shared/editor/rules/mention.ts | 6 ++--- shared/editor/rules/notices.ts | 3 +-- shared/editor/rules/tables.ts | 9 +++---- yarn.lock | 37 ++++++++++++++------------- 27 files changed, 59 insertions(+), 68 deletions(-) diff --git a/package.json b/package.json index b4a66dc438..b57b19a4e9 100644 --- a/package.json +++ b/package.json @@ -177,7 +177,7 @@ "prosemirror-history": "^1.4.1", "prosemirror-inputrules": "^1.4.0", "prosemirror-keymap": "^1.2.2", - "prosemirror-markdown": "^1.13.0", + "prosemirror-markdown": "^1.13.1", "prosemirror-model": "^1.23.0", "prosemirror-schema-list": "^1.4.1", "prosemirror-state": "^1.4.3", @@ -281,7 +281,7 @@ "@types/koa-send": "^4.1.6", "@types/koa-sslify": "^4.0.6", "@types/koa-useragent": "^2.1.2", - "@types/markdown-it": "^12.2.3", + "@types/markdown-it": "^14.1.2", "@types/markdown-it-container": "^2.0.9", "@types/markdown-it-emoji": "^2.0.4", "@types/mermaid": "^9.2.0", diff --git a/shared/editor/lib/ExtensionManager.ts b/shared/editor/lib/ExtensionManager.ts index 2fe94f4249..2fc33a3383 100644 --- a/shared/editor/lib/ExtensionManager.ts +++ b/shared/editor/lib/ExtensionManager.ts @@ -1,4 +1,4 @@ -import { PluginSimple } from "markdown-it"; +import { Options, PluginSimple } from "markdown-it"; import { observer } from "mobx-react"; import { keymap } from "prosemirror-keymap"; import { MarkdownParser } from "prosemirror-markdown"; @@ -136,7 +136,7 @@ export default class ExtensionManager { plugins, }: { schema: Schema; - rules?: markdownit.Options; + rules?: Options; plugins?: PluginSimple[]; }): MarkdownParser { const tokens = this.extensions diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index 0aabea525a..139f712df1 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { toggleMark } from "prosemirror-commands"; import { InputRule } from "prosemirror-inputrules"; import { MarkdownSerializerState } from "prosemirror-markdown"; diff --git a/shared/editor/nodes/Attachment.tsx b/shared/editor/nodes/Attachment.tsx index 73c5908ae5..ab88e93087 100644 --- a/shared/editor/nodes/Attachment.tsx +++ b/shared/editor/nodes/Attachment.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { DownloadIcon } from "outline-icons"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; import { Command, NodeSelection } from "prosemirror-state"; diff --git a/shared/editor/nodes/CheckboxItem.ts b/shared/editor/nodes/CheckboxItem.ts index 88edc5c6ff..12fb5c993d 100644 --- a/shared/editor/nodes/CheckboxItem.ts +++ b/shared/editor/nodes/CheckboxItem.ts @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec, Node as ProsemirrorNode, NodeType } from "prosemirror-model"; import { splitListItem, diff --git a/shared/editor/nodes/CodeFence.ts b/shared/editor/nodes/CodeFence.ts index 079f3728ad..258bfd6652 100644 --- a/shared/editor/nodes/CodeFence.ts +++ b/shared/editor/nodes/CodeFence.ts @@ -1,5 +1,5 @@ import copy from "copy-to-clipboard"; -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { textblockTypeInputRule } from "prosemirror-inputrules"; import { NodeSpec, diff --git a/shared/editor/nodes/Embed.tsx b/shared/editor/nodes/Embed.tsx index c4dc16da79..ad193a25c3 100644 --- a/shared/editor/nodes/Embed.tsx +++ b/shared/editor/nodes/Embed.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; import { Command } from "prosemirror-state"; import * as React from "react"; diff --git a/shared/editor/nodes/Emoji.tsx b/shared/editor/nodes/Emoji.tsx index 5ba8bb9e82..0ecd72a7a7 100644 --- a/shared/editor/nodes/Emoji.tsx +++ b/shared/editor/nodes/Emoji.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec, Node as ProsemirrorNode, diff --git a/shared/editor/nodes/HorizontalRule.ts b/shared/editor/nodes/HorizontalRule.ts index a2b2deeda2..5214643251 100644 --- a/shared/editor/nodes/HorizontalRule.ts +++ b/shared/editor/nodes/HorizontalRule.ts @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { InputRule } from "prosemirror-inputrules"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; import { Command } from "prosemirror-state"; diff --git a/shared/editor/nodes/Image.tsx b/shared/editor/nodes/Image.tsx index ba4b32860d..3c6483cfec 100644 --- a/shared/editor/nodes/Image.tsx +++ b/shared/editor/nodes/Image.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { InputRule } from "prosemirror-inputrules"; import { Node as ProsemirrorNode, NodeSpec, NodeType } from "prosemirror-model"; import { diff --git a/shared/editor/nodes/Mention.ts b/shared/editor/nodes/Mention.ts index 6cfecd90aa..b8761cafaf 100644 --- a/shared/editor/nodes/Mention.ts +++ b/shared/editor/nodes/Mention.ts @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec, Node as ProsemirrorNode, diff --git a/shared/editor/nodes/Notice.tsx b/shared/editor/nodes/Notice.tsx index bd976e69b6..3c34b50389 100644 --- a/shared/editor/nodes/Notice.tsx +++ b/shared/editor/nodes/Notice.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { WarningIcon, InfoIcon, StarredIcon, DoneIcon } from "outline-icons"; import { wrappingInputRule } from "prosemirror-inputrules"; import { NodeSpec, Node as ProsemirrorNode, NodeType } from "prosemirror-model"; diff --git a/shared/editor/nodes/OrderedList.ts b/shared/editor/nodes/OrderedList.ts index 2e35daf4a7..c34f7449ea 100644 --- a/shared/editor/nodes/OrderedList.ts +++ b/shared/editor/nodes/OrderedList.ts @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { wrappingInputRule } from "prosemirror-inputrules"; import { NodeSpec, diff --git a/shared/editor/nodes/SimpleImage.tsx b/shared/editor/nodes/SimpleImage.tsx index d84fdf5277..07900a0313 100644 --- a/shared/editor/nodes/SimpleImage.tsx +++ b/shared/editor/nodes/SimpleImage.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { InputRule } from "prosemirror-inputrules"; import { Node as ProsemirrorNode, NodeSpec, NodeType } from "prosemirror-model"; import { TextSelection, NodeSelection, Command } from "prosemirror-state"; diff --git a/shared/editor/nodes/TableCell.ts b/shared/editor/nodes/TableCell.ts index 8deeb2aad5..3ad331c6c2 100644 --- a/shared/editor/nodes/TableCell.ts +++ b/shared/editor/nodes/TableCell.ts @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec, Slice } from "prosemirror-model"; import { Plugin } from "prosemirror-state"; import { DecorationSet, Decoration } from "prosemirror-view"; diff --git a/shared/editor/nodes/TableHeader.ts b/shared/editor/nodes/TableHeader.ts index b776aba257..c44e83c942 100644 --- a/shared/editor/nodes/TableHeader.ts +++ b/shared/editor/nodes/TableHeader.ts @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec } from "prosemirror-model"; import { Plugin } from "prosemirror-state"; import { DecorationSet, Decoration, EditorView } from "prosemirror-view"; diff --git a/shared/editor/nodes/Video.tsx b/shared/editor/nodes/Video.tsx index 7c9b268bc8..57f2f9f729 100644 --- a/shared/editor/nodes/Video.tsx +++ b/shared/editor/nodes/Video.tsx @@ -1,4 +1,4 @@ -import Token from "markdown-it/lib/token"; +import { Token } from "markdown-it"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; import { NodeSelection, TextSelection } from "prosemirror-state"; import * as React from "react"; diff --git a/shared/editor/rules/breaks.ts b/shared/editor/rules/breaks.ts index 6876e71ed1..023d8eaccd 100644 --- a/shared/editor/rules/breaks.ts +++ b/shared/editor/rules/breaks.ts @@ -1,5 +1,4 @@ -import MarkdownIt from "markdown-it"; -import Token from "markdown-it/lib/token"; +import MarkdownIt, { Token } from "markdown-it"; function isHardbreak(token: Token) { return ( @@ -32,19 +31,19 @@ export default function markdownBreakToParagraphs(md: MarkdownIt) { for (let j = 0; j < count; j++) { const isLast = j === count - 1; - token = new Token("paragraph_open", "p", 1); + token = new state.Token("paragraph_open", "p", 1); nodes.push(token); - const text = new Token("text", "", 0); + const text = new state.Token("text", "", 0); text.content = ""; - token = new Token("inline", "", 0); + token = new state.Token("inline", "", 0); token.level = 1; token.children = isLast ? [text, ...children] : [text]; token.content = ""; nodes.push(token); - token = new Token("paragraph_close", "p", -1); + token = new state.Token("paragraph_close", "p", -1); nodes.push(token); } diff --git a/shared/editor/rules/checkboxes.ts b/shared/editor/rules/checkboxes.ts index 8a3fbd17f5..ed7fef4708 100644 --- a/shared/editor/rules/checkboxes.ts +++ b/shared/editor/rules/checkboxes.ts @@ -1,5 +1,4 @@ -import MarkdownIt from "markdown-it"; -import Token from "markdown-it/lib/token"; +import MarkdownIt, { Token } from "markdown-it"; const CHECKBOX_REGEX = /\[(X|\s|_|-)\]\s(.*)?/i; diff --git a/shared/editor/rules/embeds.ts b/shared/editor/rules/embeds.ts index 1cdc317c11..cccc22b24a 100644 --- a/shared/editor/rules/embeds.ts +++ b/shared/editor/rules/embeds.ts @@ -1,5 +1,4 @@ -import MarkdownIt from "markdown-it"; -import Token from "markdown-it/lib/token"; +import MarkdownIt, { Token } from "markdown-it"; import { EmbedDescriptor } from "../embeds"; function isParagraph(token: Token) { @@ -76,7 +75,7 @@ export default function linksToEmbeds(embeds: EmbedDescriptor[]) { const { content } = current; // convert to embed token - const token = new Token("embed", "iframe", 0); + const token = new state.Token("embed", "iframe", 0); token.attrSet("href", content); // delete the inline link – this makes the assumption that the diff --git a/shared/editor/rules/links.ts b/shared/editor/rules/links.ts index 0745e7bfde..98c1e5f897 100644 --- a/shared/editor/rules/links.ts +++ b/shared/editor/rules/links.ts @@ -1,5 +1,4 @@ -import MarkdownIt from "markdown-it"; -import Token from "markdown-it/lib/token"; +import MarkdownIt, { Token } from "markdown-it"; import env from "../../env"; function isParagraph(token: Token) { @@ -72,7 +71,7 @@ export default function linksToNodes(md: MarkdownIt) { if (size?.includes("x")) { // convert to video - const token = new Token("video", "video", 0); + const token = new state.Token("video", "video", 0); token.attrSet("src", insideLink.attrGet("href") || ""); token.attrSet("width", size.split("x")[0] || "0"); token.attrSet("height", size.split("x")[1] || "0"); @@ -80,7 +79,7 @@ export default function linksToNodes(md: MarkdownIt) { tokens.splice(i - 1, 3, token); } else { // convert to attachment token - const token = new Token("attachment", "a", 0); + const token = new state.Token("attachment", "a", 0); token.attrSet("href", insideLink.attrGet("href") || ""); token.attrSet("size", size || "0"); token.attrSet("title", title); diff --git a/shared/editor/rules/mark.ts b/shared/editor/rules/mark.ts index 57a010259f..cb5dc85d43 100644 --- a/shared/editor/rules/mark.ts +++ b/shared/editor/rules/mark.ts @@ -1,8 +1,7 @@ // Adapted from: // https://github.com/markdown-it/markdown-it-mark/blob/master/index.js -import MarkdownIt from "markdown-it"; -import StateInline from "markdown-it/lib/rules_inline/state_inline"; +import MarkdownIt, { StateInline } from "markdown-it"; export default function (options: { delim: string; mark: string }) { const delimCharCode = options.delim.charCodeAt(0); @@ -47,6 +46,7 @@ export default function (options: { delim: string; mark: string }) { state.delimiters.push({ marker, length: 0, // disable "rule of 3" length checks meant for emphasis + // @ts-expect-error unknown property jump: i, token: state.tokens.length - 1, end: -1, diff --git a/shared/editor/rules/math.ts b/shared/editor/rules/math.ts index f18191d6be..c393f481a4 100644 --- a/shared/editor/rules/math.ts +++ b/shared/editor/rules/math.ts @@ -1,6 +1,4 @@ -import MarkdownIt from "markdown-it"; -import StateBlock from "markdown-it/lib/rules_block/state_block"; -import StateInline from "markdown-it/lib/rules_inline/state_inline"; +import MarkdownIt, { StateBlock, StateInline } from "markdown-it"; export const REGEX_INLINE_MATH_DOLLARS = /\$\$(.+)\$\$/; diff --git a/shared/editor/rules/mention.ts b/shared/editor/rules/mention.ts index 5423e7c681..07b78dba1f 100644 --- a/shared/editor/rules/mention.ts +++ b/shared/editor/rules/mention.ts @@ -1,6 +1,4 @@ -import MarkdownIt from "markdown-it"; -import StateCore from "markdown-it/lib/rules_core/state_core"; -import Token from "markdown-it/lib/token"; +import MarkdownIt, { Token, StateCore } from "markdown-it"; function renderMention(tokens: Token[], idx: number) { const id = tokens[idx].attrGet("id"); @@ -64,7 +62,7 @@ function parseMentions(state: StateCore) { const matches = href.match(hrefRE); const [id, mType, mId] = matches!.slice(1); - const mentionToken = new Token("mention", "", 0); + const mentionToken = new state.Token("mention", "", 0); mentionToken.attrSet("id", id); mentionToken.attrSet("type", mType); mentionToken.attrSet("modelId", mId); diff --git a/shared/editor/rules/notices.ts b/shared/editor/rules/notices.ts index b4ee4221f2..231f5cdef6 100644 --- a/shared/editor/rules/notices.ts +++ b/shared/editor/rules/notices.ts @@ -1,5 +1,4 @@ -import MarkdownIt from "markdown-it"; -import Token from "markdown-it/lib/token"; +import MarkdownIt, { Token } from "markdown-it"; import customFence from "markdown-it-container"; export default function notice(md: MarkdownIt): void { diff --git a/shared/editor/rules/tables.ts b/shared/editor/rules/tables.ts index cf86772b67..0bb3ddc48d 100644 --- a/shared/editor/rules/tables.ts +++ b/shared/editor/rules/tables.ts @@ -1,5 +1,4 @@ import MarkdownIt from "markdown-it"; -import Token from "markdown-it/lib/token"; const BREAK_REGEX = /(?:^|[^\\])\\n/; @@ -26,12 +25,12 @@ export default function markdownTables(md: MarkdownIt): void { // great, for now we are stuck checking the node type. if (breakParts.length > 1 && child.type !== "code_inline") { breakParts.forEach((part, index) => { - const token = new Token("text", "", 1); + const token = new state.Token("text", "", 1); token.content = part.trim(); tokens[i].children?.push(token); if (index < breakParts.length - 1) { - const brToken = new Token("br", "br", 1); + const brToken = new state.Token("br", "br", 1); tokens[i].children?.push(brToken); } }); @@ -55,7 +54,7 @@ export default function markdownTables(md: MarkdownIt): void { if (["th_open", "td_open"].includes(tokens[i].type)) { // markdown-it table parser does not return paragraphs inside the cells // but prosemirror requires them, so we add 'em in here. - tokens.splice(i + 1, 0, new Token("paragraph_open", "p", 1)); + tokens.splice(i + 1, 0, new state.Token("paragraph_open", "p", 1)); // markdown-it table parser stores alignment as html styles, convert // to a simple string here @@ -67,7 +66,7 @@ export default function markdownTables(md: MarkdownIt): void { } if (["th_close", "td_close"].includes(tokens[i].type)) { - tokens.splice(i, 0, new Token("paragraph_close", "p", -1)); + tokens.splice(i, 0, new state.Token("paragraph_close", "p", -1)); } } diff --git a/yarn.lock b/yarn.lock index dbe129de71..02b11a9079 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4691,10 +4691,10 @@ "@types/koa-compose" "*" "@types/node" "*" -"@types/linkify-it@*": - version "3.0.2" - resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.2.tgz#fd2cd2edbaa7eaac7e7f3c1748b52a19143846c9" - integrity "sha1-/SzS7bqn6qx+fzwXSLUqGRQ4Rsk= sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==" +"@types/linkify-it@^5": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-5.0.0.tgz#21413001973106cda1c3a9b91eedd4ccd5469d76" + integrity sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q== "@types/lodash.mergewith@4.6.6": version "4.6.6" @@ -4730,18 +4730,18 @@ dependencies: "@types/markdown-it" "*" -"@types/markdown-it@*", "@types/markdown-it@^12.2.3": - version "12.2.3" - resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-12.2.3.tgz#0d6f6e5e413f8daaa26522904597be3d6cd93b51" - integrity "sha1-DW9uXkE/jaqiZSKQRZe+PWzZO1E= sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==" +"@types/markdown-it@*", "@types/markdown-it@^14.0.0", "@types/markdown-it@^14.1.2": + version "14.1.2" + resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-14.1.2.tgz#57f2532a0800067d9b934f3521429a2e8bfb4c61" + integrity sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog== dependencies: - "@types/linkify-it" "*" - "@types/mdurl" "*" + "@types/linkify-it" "^5" + "@types/mdurl" "^2" -"@types/mdurl@*": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9" - integrity "sha1-4s6dg6YTus8oTHvn1JGUXjnh+Ok= sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==" +"@types/mdurl@^2": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-2.0.0.tgz#d43878b5b20222682163ae6f897b20447233bdfd" + integrity sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg== "@types/mermaid@^9.2.0": version "9.2.0" @@ -12552,11 +12552,12 @@ prosemirror-keymap@^1.0.0, prosemirror-keymap@^1.1.2, prosemirror-keymap@^1.2.2: prosemirror-state "^1.0.0" w3c-keyname "^2.2.0" -prosemirror-markdown@^1.13.0: - version "1.13.0" - resolved "https://registry.yarnpkg.com/prosemirror-markdown/-/prosemirror-markdown-1.13.0.tgz#67ebfa40af48a22d1e4ed6cad2e29851eb61e649" - integrity sha512-UziddX3ZYSYibgx8042hfGKmukq5Aljp2qoBiJRejD/8MH70siQNz5RB1TrdTPheqLMy4aCe4GYNF10/3lQS5g== +prosemirror-markdown@^1.13.1: + version "1.13.1" + resolved "https://registry.yarnpkg.com/prosemirror-markdown/-/prosemirror-markdown-1.13.1.tgz#23feb6652dacb3dd78ffd8f131da37c20e4e4cf8" + integrity sha512-Sl+oMfMtAjWtlcZoj/5L/Q39MpEnVZ840Xo330WJWUvgyhNmLBLN7MsHn07s53nG/KImevWHSE6fEj4q/GihHw== dependencies: + "@types/markdown-it" "^14.0.0" markdown-it "^14.0.0" prosemirror-model "^1.20.0" From bb988b551d26f8515789c1573ca22d402888bd74 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Oct 2024 21:03:29 -0400 Subject: [PATCH 007/120] fix: Remove overflow from floating toolbar in desktop, as it sometimes causes the content to be misplaced --- app/editor/components/ToolbarMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/editor/components/ToolbarMenu.tsx b/app/editor/components/ToolbarMenu.tsx index 7c04904a81..4342562cd4 100644 --- a/app/editor/components/ToolbarMenu.tsx +++ b/app/editor/components/ToolbarMenu.tsx @@ -126,13 +126,13 @@ function ToolbarMenu(props: Props) { const FlexibleWrapper = styled.div` color: ${s("textSecondary")}; - overflow: hidden; display: flex; gap: 6px; ${breakpoint("mobile", "tablet")` justify-content: space-evenly; align-items: baseline; + overflow: hidden; `} `; From 10c51ef08dcfbccdaad9465fa899f514aba992c7 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Oct 2024 21:22:48 -0400 Subject: [PATCH 008/120] fix: Add syntax highlighting for Mermaid diagrams --- package.json | 2 +- shared/editor/extensions/Prism.ts | 6 +++++- shared/editor/nodes/CodeFence.ts | 3 +++ yarn.lock | 8 ++++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b57b19a4e9..d08fcaa53e 100644 --- a/package.json +++ b/package.json @@ -307,7 +307,7 @@ "@types/react-window": "^1.8.8", "@types/readable-stream": "^4.0.15", "@types/redis-info": "^3.0.3", - "@types/refractor": "^3.4.0", + "@types/refractor": "^3.4.1", "@types/resolve-path": "^1.4.2", "@types/semver": "^7.5.8", "@types/sequelize": "^4.28.20", diff --git a/shared/editor/extensions/Prism.ts b/shared/editor/extensions/Prism.ts index 6643cdf519..e276071e62 100644 --- a/shared/editor/extensions/Prism.ts +++ b/shared/editor/extensions/Prism.ts @@ -108,7 +108,11 @@ function getDecorations({ blocks.forEach((block) => { let startPos = block.pos + 1; - const language = block.node.attrs.language; + const language = ( + block.node.attrs.language === "mermaidjs" + ? "mermaid" + : block.node.attrs.language + ) as string; if (!language || language === "none" || !refractor.registered(language)) { return; } diff --git a/shared/editor/nodes/CodeFence.ts b/shared/editor/nodes/CodeFence.ts index 258bfd6652..1c95979f37 100644 --- a/shared/editor/nodes/CodeFence.ts +++ b/shared/editor/nodes/CodeFence.ts @@ -32,6 +32,8 @@ import kotlin from "refractor/lang/kotlin"; import lisp from "refractor/lang/lisp"; import lua from "refractor/lang/lua"; import markup from "refractor/lang/markup"; +// @ts-expect-error type definition is missing, but package exists +import mermaid from "refractor/lang/mermaid"; import nginx from "refractor/lang/nginx"; import nix from "refractor/lang/nix"; import objectivec from "refractor/lang/objectivec"; @@ -109,6 +111,7 @@ const DEFAULT_LANGUAGE = "javascript"; lisp, lua, markup, + mermaid, nginx, nix, objectivec, diff --git a/yarn.lock b/yarn.lock index 02b11a9079..4b1d030f3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4972,10 +4972,10 @@ resolved "https://registry.yarnpkg.com/@types/redis-info/-/redis-info-3.0.3.tgz#4963fa015a6b448d9c7e27d6cba96d5db7201550" integrity "sha1-SWP6AVprRI2cfifWy6ltXbcgFVA= sha512-VIkNy6JbYI/RLdbPHdm9JQvv6RVld2uE2/6Hdid38Qdq+zvDli2FTpImI8pC5zwp8xS8qVqfzlfyAub8xZEd5g==" -"@types/refractor@^3.4.0": - version "3.4.0" - resolved "https://registry.yarnpkg.com/@types/refractor/-/refractor-3.4.0.tgz#7a8f982e100d3319ee0e8f93a088d093cd145a21" - integrity "sha1-eo+YLhANMxnuDo+ToIjQk80UWiE= sha512-ZVLDkJxBQgvulG7R+xzgsJVODJVr0hlpCiMnEcxeJwCIzCSUwCHrsuQmd9KGZm//ujeuV9WHiVGUawaZkLLJrQ==" +"@types/refractor@^3.4.1": + version "3.4.1" + resolved "https://registry.yarnpkg.com/@types/refractor/-/refractor-3.4.1.tgz#8b109804f77b3da8fad543d3f575fef1ece8835a" + integrity sha512-wYuorIiCTSuvRT9srwt+taF6mH/ww+SyN2psM0sjef2qW+sS8GmshgDGTEDgWB1sTVGgYVE6EK7dBA2MxQxibg== dependencies: "@types/prismjs" "*" From c8d307c2d4c73032567901eadbcba5608082201b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 21 Oct 2024 21:42:27 -0400 Subject: [PATCH 009/120] fix: Improve safety around image toolbar, related #7815 --- app/editor/components/FloatingToolbar.tsx | 94 ++++++++++++----------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/app/editor/components/FloatingToolbar.tsx b/app/editor/components/FloatingToolbar.tsx index c153bdb0db..78e53203da 100644 --- a/app/editor/components/FloatingToolbar.tsx +++ b/app/editor/components/FloatingToolbar.tsx @@ -130,59 +130,61 @@ function usePosition({ // Images need their own positioning to get the toolbar in the center if (isImageSelection) { - const element = view.nodeDOM(selection.from); + const element = view.nodeDOM(selection.from) as HTMLElement; // Images are wrapped which impacts positioning - need to get the element // specifically tagged as the handle - const imageElement = (element as HTMLElement).getElementsByClassName( + const imageElement = element.getElementsByClassName( EditorStyleHelper.imageHandle )[0]; - const { left, top, width } = imageElement.getBoundingClientRect(); + if (imageElement) { + const { left, top, width } = imageElement.getBoundingClientRect(); - return { - left: Math.round(left + width / 2 - menuWidth / 2 - offsetParent.left), - top: Math.round(top - menuHeight - offsetParent.top), - offset: 0, - visible: true, - }; - } else { - // calculate the horizontal center of the selection - const halfSelection = - Math.abs(selectionBounds.right - selectionBounds.left) / 2; - const centerOfSelection = selectionBounds.left + halfSelection; - - // position the menu so that it is centered over the selection except in - // the cases where it would extend off the edge of the screen. In these - // instances leave a margin - const margin = 12; - const left = Math.min( - Math.min( - offsetParent.x + offsetParent.width - menuWidth - margin, - window.innerWidth - margin - ), - Math.max( - Math.max(offsetParent.x, margin), - centerOfSelection - menuWidth / 2 - ) - ); - const top = Math.min( - window.innerHeight - menuHeight - margin, - Math.max(margin, selectionBounds.top - menuHeight) - ); - - // if the menu has been offset to not extend offscreen then we should adjust - // the position of the triangle underneath to correctly point to the center - // of the selection still - const offset = left - (centerOfSelection - menuWidth / 2); - return { - left: Math.round(left - offsetParent.left), - top: Math.round(top - offsetParent.top), - offset: Math.round(offset), - maxWidth: Math.min(window.innerWidth - margin * 2, offsetParent.width), - blockSelection: codeBlock || isColSelection || isRowSelection, - visible: true, - }; + return { + left: Math.round(left + width / 2 - menuWidth / 2 - offsetParent.left), + top: Math.round(top - menuHeight - offsetParent.top), + offset: 0, + visible: true, + }; + } } + + // calculate the horizontal center of the selection + const halfSelection = + Math.abs(selectionBounds.right - selectionBounds.left) / 2; + const centerOfSelection = selectionBounds.left + halfSelection; + + // position the menu so that it is centered over the selection except in + // the cases where it would extend off the edge of the screen. In these + // instances leave a margin + const margin = 12; + const left = Math.min( + Math.min( + offsetParent.x + offsetParent.width - menuWidth - margin, + window.innerWidth - margin + ), + Math.max( + Math.max(offsetParent.x, margin), + centerOfSelection - menuWidth / 2 + ) + ); + const top = Math.min( + window.innerHeight - menuHeight - margin, + Math.max(margin, selectionBounds.top - menuHeight) + ); + + // if the menu has been offset to not extend offscreen then we should adjust + // the position of the triangle underneath to correctly point to the center + // of the selection still + const offset = left - (centerOfSelection - menuWidth / 2); + return { + left: Math.round(left - offsetParent.left), + top: Math.round(top - offsetParent.top), + offset: Math.round(offset), + maxWidth: Math.min(window.innerWidth - margin * 2, offsetParent.width), + blockSelection: codeBlock || isColSelection || isRowSelection, + visible: true, + }; } const FloatingToolbar = React.forwardRef(function FloatingToolbar_( From 0d7ce76c21646938b28740d9d89243befc1210ce Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Tue, 22 Oct 2024 20:24:11 +0530 Subject: [PATCH 010/120] Allow querying by user emails in order to `@mention` them (#7807) * fix: readEmail permission * fix: allow querying over user email in users.list * fix: allow searching by email in @mention * fix: include email in mentioned user's hover card * fix: put email on separate line in hover card --- app/components/HoverPreview/HoverPreview.tsx | 1 + .../HoverPreview/HoverPreviewMention.tsx | 3 +- app/editor/extensions/MentionMenu.tsx | 2 +- server/policies/user.ts | 18 ++- server/policies/utils.ts | 11 ++ server/presenters/unfurl.ts | 11 +- server/presenters/user.ts | 5 + server/routes/api/urls/urls.ts | 15 +- server/routes/api/users/users.test.ts | 152 +++++++++++++++++- server/routes/api/users/users.ts | 16 +- shared/types.ts | 2 + 11 files changed, 213 insertions(+), 23 deletions(-) diff --git a/app/components/HoverPreview/HoverPreview.tsx b/app/components/HoverPreview/HoverPreview.tsx index 4d1c6ec0bd..c6a79d8f6e 100644 --- a/app/components/HoverPreview/HoverPreview.tsx +++ b/app/components/HoverPreview/HoverPreview.tsx @@ -125,6 +125,7 @@ function HoverPreviewDesktop({ element, data, dataLoading, onClose }: Props) { avatarUrl={data.avatarUrl} color={data.color} lastActive={data.lastActive} + email={data.email} /> ) : data.type === UnfurlResourceType.Document ? ( ; const HoverPreviewMention = React.forwardRef(function _HoverPreviewMention( - { avatarUrl, name, lastActive, color }: Props, + { avatarUrl, name, lastActive, color, email }: Props, ref: React.Ref ) { return ( @@ -25,6 +25,7 @@ const HoverPreviewMention = React.forwardRef(function _HoverPreviewMention( /> {name} + {email && {email}} {lastActive} diff --git a/app/editor/extensions/MentionMenu.tsx b/app/editor/extensions/MentionMenu.tsx index ffbf16cfe7..4e9fc1c68e 100644 --- a/app/editor/extensions/MentionMenu.tsx +++ b/app/editor/extensions/MentionMenu.tsx @@ -8,7 +8,7 @@ export default class MentionMenuExtension extends Suggestion { get defaultOptions() { return { // ported from https://github.com/tc39/proposal-regexp-unicode-property-escapes#unicode-aware-version-of-w - openRegex: /(?:^|\s|\()@([\p{L}\p{M}\d\s{1}]+)?$/u, + openRegex: /(?:^|\s|\()@([\p{L}\p{M}\d\s{1}@\.]+)?$/u, closeRegex: /(?:^|\s|\()@(([\p{L}\p{M}\d]*\s{2})|(\s+[\p{L}\p{M}\d]+))$/u, }; } diff --git a/server/policies/user.ts b/server/policies/user.ts index e254a3be59..af8b7d897f 100644 --- a/server/policies/user.ts +++ b/server/policies/user.ts @@ -1,7 +1,14 @@ import { TeamPreference } from "@shared/types"; import { User, Team } from "@server/models"; import { allow } from "./cancan"; -import { and, isTeamAdmin, isTeamModel, isTeamMutable, or } from "./utils"; +import { + and, + isTeamAdmin, + isTeamMember, + isTeamModel, + isTeamMutable, + or, +} from "./utils"; allow(User, "read", User, isTeamModel); @@ -31,6 +38,15 @@ allow(User, ["update", "readDetails", "listApiKeys"], User, (actor, user) => ) ); +allow(User, "readEmail", User, (actor, user) => + or( + // + isTeamAdmin(actor, user), + isTeamMember(actor, user), + actor.id === user?.id + ) +); + allow(User, "delete", User, (actor, user) => or( isTeamAdmin(actor, user), diff --git a/server/policies/utils.ts b/server/policies/utils.ts index 176b9b9bbc..c7f97a0672 100644 --- a/server/policies/utils.ts +++ b/server/policies/utils.ts @@ -71,6 +71,17 @@ export function isTeamAdmin( return !!and(isTeamModel(actor, model), actor.isAdmin); } +/** + * Check if the actor is a member of the team. + * + * @param actor The actor to check + * @param model The model to check + * @returns True if the actor is a member of the team the model belongs to + */ +export function isTeamMember(actor: User, model: Model | null | undefined) { + return !!and(isTeamModel(actor, model), actor.isMember); +} + /** * Check the actors team is mutable, meaning the team models can be modified. * diff --git a/server/presenters/unfurl.ts b/server/presenters/unfurl.ts index c9fc136372..0a7826bbee 100644 --- a/server/presenters/unfurl.ts +++ b/server/presenters/unfurl.ts @@ -6,10 +6,13 @@ import { Document, User, View } from "@server/models"; import { opts } from "@server/utils/i18n"; import { GitHubUtils } from "plugins/github/shared/GitHubUtils"; -async function presentUnfurl(data: Record) { +async function presentUnfurl( + data: Record, + options?: { includeEmail: boolean } +) { switch (data.type) { case UnfurlResourceType.Mention: - return presentMention(data); + return presentMention(data, options); case UnfurlResourceType.Document: return presentDocument(data); case UnfurlResourceType.PR: @@ -32,7 +35,8 @@ const presentOEmbed = ( }); const presentMention = async ( - data: Record + data: Record, + options?: { includeEmail: boolean } ): Promise => { const user: User = data.user; const document: Document = data.document; @@ -43,6 +47,7 @@ const presentMention = async ( return { type: UnfurlResourceType.Mention, name: user.name, + email: options && options.includeEmail ? user.email : null, avatarUrl: user.avatarUrl, color: user.color, lastActive: `${lastOnlineInfo} • ${lastViewedInfo}`, diff --git a/server/presenters/user.ts b/server/presenters/user.ts index d01d940f3c..c877a86039 100644 --- a/server/presenters/user.ts +++ b/server/presenters/user.ts @@ -4,6 +4,7 @@ import { User } from "@server/models"; type Options = { includeDetails?: boolean; + includeEmail?: boolean; }; type UserPresentation = { @@ -45,5 +46,9 @@ export default function presentUser( userData.notificationSettings = user.notificationSettings; } + if (options.includeEmail) { + userData.email = user.email; + } + return userData; } diff --git a/server/routes/api/urls/urls.ts b/server/routes/api/urls/urls.ts index 55dfb220b7..e77b985128 100644 --- a/server/routes/api/urls/urls.ts +++ b/server/routes/api/urls/urls.ts @@ -10,7 +10,7 @@ import auth from "@server/middlewares/authentication"; import { rateLimiter } from "@server/middlewares/rateLimiter"; import validate from "@server/middlewares/validate"; import { Document, Share, Team, User } from "@server/models"; -import { authorize } from "@server/policies"; +import { authorize, can } from "@server/policies"; import presentUnfurl from "@server/presenters/unfurl"; import { APIContext, Unfurl } from "@server/types"; import { CacheHelper } from "@server/utils/CacheHelper"; @@ -53,11 +53,14 @@ router.post( authorize(actor, "read", user); authorize(actor, "read", document); - ctx.body = await presentUnfurl({ - type: UnfurlResourceType.Mention, - user, - document, - }); + ctx.body = await presentUnfurl( + { + type: UnfurlResourceType.Mention, + user, + document, + }, + { includeEmail: !!can(actor, "readEmail", user) } + ); return; } diff --git a/server/routes/api/users/users.test.ts b/server/routes/api/users/users.test.ts index 0d835987a7..33f7bafb62 100644 --- a/server/routes/api/users/users.test.ts +++ b/server/routes/api/users/users.test.ts @@ -18,6 +18,24 @@ afterAll(() => { }); describe("#users.list", () => { + it("should return users whose emails match the query", async () => { + const user = await buildUser({ + name: "John Doe", + email: "john.doe@example.com", + }); + + const res = await server.post("/api/users.list", { + body: { + query: "john.doe@e", + token: user.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(1); + expect(body.data[0].id).toEqual(user.id); + }); + it("should allow filtering by user name", async () => { const user = await buildUser({ name: "Tèster", @@ -189,20 +207,142 @@ describe("#users.list", () => { expect(body.data[0].id).toEqual(user.id); }); - it("should require admin for detailed info", async () => { + it("should restrict guest from viewing other user's email", async () => { const team = await buildTeam(); - await buildAdmin({ teamId: team.id }); - const user = await buildUser({ teamId: team.id }); + await buildUser({ teamId: team.id }); + const guest = await buildUser({ teamId: team.id, role: UserRole.Guest }); const res = await server.post("/api/users.list", { body: { - token: user.getJwtToken(), + token: guest.getJwtToken(), }, }); const body = await res.json(); expect(res.status).toEqual(200); - expect(body.data.length).toEqual(2); + expect(body.data).toHaveLength(2); expect(body.data[0].email).toEqual(undefined); - expect(body.data[1].email).toEqual(user.email); + expect(body.data[1].email).toEqual(guest.email); + }); + + it("should restrict viewer from viewing other user's email", async () => { + const team = await buildTeam(); + await buildUser({ teamId: team.id }); + const viewer = await buildUser({ teamId: team.id, role: UserRole.Viewer }); + const res = await server.post("/api/users.list", { + body: { + token: viewer.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(2); + expect(body.data[0].email).toEqual(undefined); + expect(body.data[1].email).toEqual(viewer.email); + }); + + it("should allow member to view other user's email", async () => { + const team = await buildTeam(); + const user = await buildUser({ teamId: team.id }); + const member = await buildUser({ teamId: team.id, role: UserRole.Member }); + const res = await server.post("/api/users.list", { + body: { + token: member.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(2); + expect(body.data[0].email).toEqual(user.email); + expect(body.data[1].email).toEqual(member.email); + }); + + it("should restrict guest from viewing other user's details", async () => { + const team = await buildTeam(); + await buildUser({ teamId: team.id }); + const guest = await buildUser({ teamId: team.id, role: UserRole.Guest }); + const res = await server.post("/api/users.list", { + body: { + token: guest.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(2); + expect(body.data[0].language).toEqual(undefined); + expect(body.data[0].preferences).toEqual(undefined); + expect(body.data[0].notificationSettings).toEqual(undefined); + expect(body.data[1].language).toEqual(guest.language); + expect(body.data[1].preferences).toEqual(guest.preferences); + expect(body.data[1].notificationSettings).toEqual( + guest.notificationSettings + ); + }); + + it("should restrict viewer from viewing other user's details", async () => { + const team = await buildTeam(); + await buildUser({ teamId: team.id }); + const viewer = await buildUser({ teamId: team.id, role: UserRole.Viewer }); + const res = await server.post("/api/users.list", { + body: { + token: viewer.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(2); + expect(body.data[0].language).toEqual(undefined); + expect(body.data[0].preferences).toEqual(undefined); + expect(body.data[0].notificationSettings).toEqual(undefined); + expect(body.data[1].language).toEqual(viewer.language); + expect(body.data[1].preferences).toEqual(viewer.preferences); + expect(body.data[1].notificationSettings).toEqual( + viewer.notificationSettings + ); + }); + + it("should restrict member from viewing other user's details", async () => { + const team = await buildTeam(); + await buildUser({ teamId: team.id }); + const member = await buildUser({ teamId: team.id, role: UserRole.Member }); + const res = await server.post("/api/users.list", { + body: { + token: member.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(2); + expect(body.data[0].language).toEqual(undefined); + expect(body.data[0].preferences).toEqual(undefined); + expect(body.data[0].notificationSettings).toEqual(undefined); + expect(body.data[1].language).toEqual(member.language); + expect(body.data[1].preferences).toEqual(member.preferences); + expect(body.data[1].notificationSettings).toEqual( + member.notificationSettings + ); + }); + + it("should allow admin to view other user's details", async () => { + const team = await buildTeam(); + const admin = await buildAdmin({ teamId: team.id }); + const user = await buildUser({ teamId: team.id }); + const res = await server.post("/api/users.list", { + body: { + token: admin.getJwtToken(), + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data).toHaveLength(2); + expect(body.data[0].language).toEqual(user.language); + expect(body.data[0].preferences).toEqual(user.preferences); + expect(body.data[0].notificationSettings).toEqual( + user.notificationSettings + ); + expect(body.data[1].language).toEqual(admin.language); + expect(body.data[1].preferences).toEqual(admin.preferences); + expect(body.data[1].notificationSettings).toEqual( + admin.notificationSettings + ); }); }); diff --git a/server/routes/api/users/users.ts b/server/routes/api/users/users.ts index a745ff21fd..71adf6467a 100644 --- a/server/routes/api/users/users.ts +++ b/server/routes/api/users/users.ts @@ -124,11 +124,16 @@ router.post( if (query) { where = { ...where, - [Op.and]: [ - Sequelize.literal( - `unaccent(LOWER(name)) like unaccent(LOWER(:query))` - ), - ], + [Op.and]: { + [Op.or]: [ + Sequelize.literal( + `unaccent(LOWER(email)) like unaccent(LOWER(:query))` + ), + Sequelize.literal( + `unaccent(LOWER(name)) like unaccent(LOWER(:query))` + ), + ], + }, }; } @@ -167,6 +172,7 @@ router.post( pagination: { ...ctx.state.pagination, total }, data: users.map((user) => presentUser(user, { + includeEmail: !!can(actor, "readEmail", user), includeDetails: !!can(actor, "readDetails", user), }) ), diff --git a/shared/types.ts b/shared/types.ts index 5a6488cb07..627f6f0fd1 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -335,6 +335,8 @@ export type UnfurlResponse = { type: UnfurlResourceType.Mention; /** Mentioned user's name */ name: string; + /** Mentioned user's email */ + email: string | null; /** Mentioned user's avatar URL */ avatarUrl: string | null; /** Used to create mentioned user's avatar if no avatar URL provided */ From 57e9abd77f8271a5f37521c8581fa78779af3c0c Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Wed, 23 Oct 2024 08:48:33 +0530 Subject: [PATCH 011/120] feat: allow sort by position for comments (#7770) * feat: allow sort by position for comments * wait for prosemirror nodes to load * Move to menu * remove sort; rename enum * asc sort for in-thread display * revert sort --------- Co-authored-by: Tom Moor --- app/components/DocumentContext.tsx | 8 ++ app/components/InputSelect.tsx | 6 +- app/editor/index.tsx | 25 +++++ .../Document/components/CommentSortMenu.tsx | 86 +++++++++++++++++ app/scenes/Document/components/Comments.tsx | 92 +++++-------------- app/scenes/Document/components/Editor.tsx | 8 +- app/stores/CommentsStore.ts | 37 ++++++-- app/types.ts | 9 ++ shared/constants.ts | 1 + shared/i18n/locales/en_US/translation.json | 7 +- shared/types.ts | 2 + 11 files changed, 199 insertions(+), 82 deletions(-) create mode 100644 app/scenes/Document/components/CommentSortMenu.tsx diff --git a/app/components/DocumentContext.tsx b/app/components/DocumentContext.tsx index 38808b6408..e7584da577 100644 --- a/app/components/DocumentContext.tsx +++ b/app/components/DocumentContext.tsx @@ -11,6 +11,9 @@ class DocumentContext { /** The editor instance for this document */ editor?: Editor; + @observable + isEditorInitialized: boolean = false; + @observable headings: Heading[] = []; @@ -31,6 +34,11 @@ class DocumentContext { this.updateState(); }; + @action + setEditorInitialized = (initialized: boolean) => { + this.isEditorInitialized = initialized; + }; + @action updateState = () => { this.updateHeadings(); diff --git a/app/components/InputSelect.tsx b/app/components/InputSelect.tsx index 3c4214c793..6552c84b8a 100644 --- a/app/components/InputSelect.tsx +++ b/app/components/InputSelect.tsx @@ -10,7 +10,7 @@ import * as React from "react"; import { VisuallyHidden } from "reakit/VisuallyHidden"; import styled, { css } from "styled-components"; import { s } from "@shared/styles"; -import Button, { Inner } from "~/components/Button"; +import Button, { Props as ButtonProps, Inner } from "~/components/Button"; import Text from "~/components/Text"; import useMenuHeight from "~/hooks/useMenuHeight"; import useMobile from "~/hooks/useMobile"; @@ -33,7 +33,7 @@ export type Option = { divider?: boolean; }; -export type Props = { +export type Props = Omit, "onChange"> & { id?: string; name?: string; value?: string | null; @@ -313,7 +313,7 @@ const StyledButton = styled(Button)<{ $nude?: boolean }>` margin-bottom: 16px; display: block; width: 100%; - cursor: default; + cursor: var(--pointer); &:hover:not(:disabled) { background: ${s("buttonNeutralBackground")}; diff --git a/app/editor/index.tsx b/app/editor/index.tsx index 3cbc9403de..ef48c9bd6e 100644 --- a/app/editor/index.tsx +++ b/app/editor/index.tsx @@ -91,6 +91,10 @@ export type Props = { scrollTo?: string; /** Callback for handling uploaded images, should return the url of uploaded file */ uploadFile?: (file: File) => Promise; + /** Callback when prosemirror nodes are initialized on document mount. */ + onInit?: () => void; + /** Callback when prosemirror nodes are destroyed on document unmount. */ + onDestroy?: () => void; /** Callback when editor is blurred, as native input */ onBlur?: () => void; /** Callback when editor is focused, as native input */ @@ -176,6 +180,7 @@ export class Editor extends React.PureComponent< linkToolbarOpen: false, }; + isInitialized = false; isBlurred = true; extensions: ExtensionManager; elementRef = React.createRef(); @@ -283,6 +288,7 @@ export class Editor extends React.PureComponent< window.removeEventListener("theme-changed", this.dispatchThemeChanged); this.view?.destroy(); this.mutationObserver?.disconnect(); + this.handleEditorDestroy(); } private init() { @@ -480,6 +486,9 @@ export class Editor extends React.PureComponent< (self.props.canComment && transactions.some(isEditingComment))) ) { self.handleChange(); + // Wait for the first transaction to initialize the nodes. + // This is bound to happen always - New / empty document has a "paragraph" node in it. + self.handleEditorInit(); } self.calculateDir(); @@ -740,6 +749,22 @@ export class Editor extends React.PureComponent< ); }; + private handleEditorInit = () => { + if (!this.props.onInit || this.isInitialized) { + return; + } + + this.props.onInit(); + this.isInitialized = true; + }; + + private handleEditorDestroy = () => { + if (!this.props.onDestroy) { + return; + } + this.props.onDestroy(); + }; + private handleEditorBlur = () => { this.setState({ isEditorFocused: false }); return false; diff --git a/app/scenes/Document/components/CommentSortMenu.tsx b/app/scenes/Document/components/CommentSortMenu.tsx new file mode 100644 index 0000000000..db8227f3d0 --- /dev/null +++ b/app/scenes/Document/components/CommentSortMenu.tsx @@ -0,0 +1,86 @@ +import queryString from "query-string"; +import React from "react"; +import { useTranslation } from "react-i18next"; +import { useHistory, useLocation } from "react-router-dom"; +import styled from "styled-components"; +import { s } from "@shared/styles"; +import { UserPreference } from "@shared/types"; +import InputSelect from "~/components/InputSelect"; +import useCurrentUser from "~/hooks/useCurrentUser"; +import useQuery from "~/hooks/useQuery"; +import { CommentSortType } from "~/types"; + +const CommentSortMenu = () => { + const { t } = useTranslation(); + const location = useLocation(); + const history = useHistory(); + const user = useCurrentUser(); + const params = useQuery(); + + const viewingResolved = params.get("resolved") === ""; + const value = viewingResolved + ? "resolved" + : user.getPreference(UserPreference.SortCommentsByOrderInDocument) + ? CommentSortType.OrderInDocument + : CommentSortType.MostRecent; + + const handleSortTypeChange = (type: CommentSortType) => { + user.setPreference( + UserPreference.SortCommentsByOrderInDocument, + type === CommentSortType.OrderInDocument + ); + void user.save(); + }; + + const showResolved = () => { + history.push({ + search: queryString.stringify({ + ...queryString.parse(location.search), + resolved: "", + }), + pathname: location.pathname, + }); + }; + + const showUnresolved = () => { + history.push({ + search: queryString.stringify({ + ...queryString.parse(location.search), + resolved: undefined, + }), + pathname: location.pathname, + }); + }; + + return ( +