diff --git a/package.json b/package.json index eb21fab098..8bac49f743 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@babel/plugin-transform-destructuring": "^7.22.5", "@babel/plugin-transform-regenerator": "^7.22.10", "@babel/preset-env": "^7.20.0", - "@babel/preset-react": "^7.22.5", + "@babel/preset-react": "^7.22.15", "@benrbray/prosemirror-math": "^0.2.2", "@bull-board/api": "^4.2.2", "@bull-board/koa": "^4.12.2", @@ -145,7 +145,7 @@ "mobx-react": "^6.3.1", "mobx-utils": "^4.0.1", "natural-sort": "^1.0.0", - "node-fetch": "2.6.12", + "node-fetch": "2.7.0", "nodemailer": "^6.9.4", "outline-icons": "^2.4.0", "oy-vey": "^0.12.0", @@ -269,7 +269,7 @@ "@types/mime-types": "^2.1.1", "@types/natural-sort": "^0.0.21", "@types/node": "18.0.6", - "@types/node-fetch": "^2.6.2", + "@types/node-fetch": "^2.6.5", "@types/nodemailer": "^6.4.9", "@types/passport-oauth2": "^1.4.11", "@types/quoted-printable": "^1.0.0", @@ -287,7 +287,7 @@ "@types/readable-stream": "^4.0.2", "@types/redis-info": "^3.0.0", "@types/refractor": "^3.0.2", - "@types/semver": "^7.5.0", + "@types/semver": "^7.5.2", "@types/sequelize": "^4.28.10", "@types/slug": "^5.0.3", "@types/stoppable": "^1.1.1", diff --git a/server/routes/api/comments/comments.ts b/server/routes/api/comments/comments.ts index f43ba7f47d..73d693ae6f 100644 --- a/server/routes/api/comments/comments.ts +++ b/server/routes/api/comments/comments.ts @@ -1,7 +1,10 @@ +import { Next } from "koa"; import Router from "koa-router"; +import { TeamPreference } from "@shared/types"; import commentCreator from "@server/commands/commentCreator"; import commentDestroyer from "@server/commands/commentDestroyer"; import commentUpdater from "@server/commands/commentUpdater"; +import { ValidationError } from "@server/errors"; import auth from "@server/middlewares/authentication"; import { rateLimiter } from "@server/middlewares/rateLimiter"; import { transaction } from "@server/middlewares/transaction"; @@ -20,6 +23,7 @@ router.post( "comments.create", rateLimiter(RateLimiterStrategy.TenPerMinute), auth(), + checkCommentingEnabled(), validate(T.CommentsCreateSchema), transaction(), async (ctx: APIContext) => { @@ -54,6 +58,7 @@ router.post( "comments.list", auth(), pagination(), + checkCommentingEnabled(), validate(T.CollectionsListSchema), async (ctx: APIContext) => { const { sort, direction, documentId } = ctx.input.body; @@ -80,6 +85,7 @@ router.post( router.post( "comments.update", auth(), + checkCommentingEnabled(), validate(T.CommentsUpdateSchema), transaction(), async (ctx: APIContext) => { @@ -119,6 +125,7 @@ router.post( router.post( "comments.delete", auth(), + checkCommentingEnabled(), validate(T.CommentsDeleteSchema), transaction(), async (ctx: APIContext) => { @@ -149,6 +156,18 @@ router.post( } ); +function checkCommentingEnabled() { + return async function checkCommentingEnabledMiddleware( + ctx: APIContext, + next: Next + ) { + if (!ctx.state.auth.user.team.getPreference(TeamPreference.Commenting)) { + throw ValidationError("Commenting is currently disabled"); + } + return next(); + }; +} + // router.post("comments.resolve", auth(), async (ctx) => { // router.post("comments.unresolve", auth(), async (ctx) => { diff --git a/shared/editor/extensions/Mermaid.ts b/shared/editor/extensions/Mermaid.ts index 7926ff3f7d..302936cd73 100644 --- a/shared/editor/extensions/Mermaid.ts +++ b/shared/editor/extensions/Mermaid.ts @@ -62,14 +62,17 @@ function getNewState({ theme: pluginState.isDark ? "dark" : "default", fontFamily: "inherit", }); + try { module.default.render( "mermaid-diagram-" + diagramId, block.node.textContent, - (svgCode) => { + (svgCode, bindFunctions) => { element.classList.remove("parse-error", "empty"); element.innerHTML = svgCode; - } + bindFunctions?.(element); + }, + element ); } catch (error) { const isEmpty = block.node.textContent.trim().length === 0; diff --git a/shared/editor/extensions/PasteHandler.ts b/shared/editor/extensions/PasteHandler.ts index bc4ce2481c..aaef0e92f4 100644 --- a/shared/editor/extensions/PasteHandler.ts +++ b/shared/editor/extensions/PasteHandler.ts @@ -155,10 +155,10 @@ export default class PasteHandler extends Extension { // If the users selection is currently in a code block then paste // as plain text, ignore all formatting and HTML content. - if (isInCode(view.state)) { + if (isInCode(state)) { event.preventDefault(); - view.dispatch(view.state.tr.insertText(text)); + view.dispatch(state.tr.insertText(text)); return true; } @@ -167,26 +167,41 @@ export default class PasteHandler extends Extension { // was pasted. const vscodeMeta = vscode ? JSON.parse(vscode) : undefined; const pasteCodeLanguage = vscodeMeta?.mode; - const supportsCodeBlock = !!view.state.schema.nodes.code_block; + const supportsCodeBlock = !!state.schema.nodes.code_block; + const supportsCodeMark = !!state.schema.marks.code_inline; - if ( - supportsCodeBlock && - pasteCodeLanguage && - pasteCodeLanguage !== "markdown" - ) { - event.preventDefault(); - view.dispatch( - view.state.tr - .replaceSelectionWith( - view.state.schema.nodes.code_block.create({ - language: Object.keys(LANGUAGES).includes(vscodeMeta.mode) - ? vscodeMeta.mode - : null, - }) - ) - .insertText(text) - ); - return true; + if (pasteCodeLanguage && pasteCodeLanguage !== "markdown") { + if (text.includes("\n") && supportsCodeBlock) { + event.preventDefault(); + view.dispatch( + state.tr + .replaceSelectionWith( + state.schema.nodes.code_block.create({ + language: Object.keys(LANGUAGES).includes( + vscodeMeta.mode + ) + ? vscodeMeta.mode + : null, + }) + ) + .insertText(text) + ); + return true; + } + + if (supportsCodeMark) { + event.preventDefault(); + view.dispatch( + state.tr + .insertText(text, state.selection.from, state.selection.to) + .addMark( + state.selection.from, + state.selection.to + text.length, + state.schema.marks.code_inline.create() + ) + ); + return true; + } } // If the HTML on the clipboard is from Prosemirror then the best diff --git a/yarn.lock b/yarn.lock index 891633e986..2434982809 100644 --- a/yarn.lock +++ b/yarn.lock @@ -191,12 +191,12 @@ dependencies: "@babel/types" "^7.21.0" -"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.10.4", "@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.14.5", "@babel/helper-module-imports@^7.18.6", "@babel/helper-module-imports@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.22.5.tgz#1a8f4c9f4027d23f520bd76b364d44434a72660c" - integrity sha512-8Dl6+HD/cKifutF5qGd/8ZJi84QeAKh+CEe1sBzz8UayBBGg1dAIJrdHOcOM5b2MpzWL2yuotJTtGjETq0qjXg== +"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.10.4", "@babel/helper-module-imports@^7.12.13", "@babel/helper-module-imports@^7.14.5", "@babel/helper-module-imports@^7.18.6", "@babel/helper-module-imports@^7.22.15", "@babel/helper-module-imports@^7.22.5": + version "7.22.15" + resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.22.15.tgz#16146307acdc40cc00c3b2c647713076464bdbf0" + integrity sha512-0pYVBnDKZO2fnSPCrgM/6WMc7eS20Fbok+0r88fp+YtWVLZrp4CkafFGIp+W0VKw4a22sgebPT99y+FDNMdP4w== dependencies: - "@babel/types" "^7.22.5" + "@babel/types" "^7.22.15" "@babel/helper-module-transforms@^7.18.6", "@babel/helper-module-transforms@^7.20.11", "@babel/helper-module-transforms@^7.21.2", "@babel/helper-module-transforms@^7.22.5": version "7.22.5" @@ -272,15 +272,15 @@ resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f" integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw== -"@babel/helper-validator-identifier@^7.19.1", "@babel/helper-validator-identifier@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193" - integrity sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ== +"@babel/helper-validator-identifier@^7.19.1", "@babel/helper-validator-identifier@^7.22.19", "@babel/helper-validator-identifier@^7.22.5": + version "7.22.20" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0" + integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A== -"@babel/helper-validator-option@^7.18.6", "@babel/helper-validator-option@^7.21.0", "@babel/helper-validator-option@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.22.5.tgz#de52000a15a177413c8234fa3a8af4ee8102d0ac" - integrity sha512-R3oB6xlIVKUnxNUxbmgq7pKjxpru24zlimpE8WK47fACIlM0II/Hm1RS8IaOI7NgCr6LNS+jl5l75m20npAziw== +"@babel/helper-validator-option@^7.18.6", "@babel/helper-validator-option@^7.21.0", "@babel/helper-validator-option@^7.22.15", "@babel/helper-validator-option@^7.22.5": + version "7.22.15" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.22.15.tgz#694c30dfa1d09a6534cdfcafbe56789d36aba040" + integrity sha512-bMn7RmyFjY/mdECUbgn9eoSY4vqvacUnS9i9vGAGttgFWesO6B4CYWA7XlpbWgBt71iv/hfbPlynohStqnu5hA== "@babel/helper-wrap-function@^7.18.9": version "7.20.5" @@ -824,16 +824,16 @@ dependencies: "@babel/helper-plugin-utils" "^7.19.0" -"@babel/plugin-transform-react-jsx@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.22.5.tgz#932c291eb6dd1153359e2a90cb5e557dcf068416" - integrity sha512-rog5gZaVbUip5iWDMTYbVM15XQq+RkUKhET/IHR6oizR+JEoN6CAfTTuHcK4vwUyzca30qqHqEpzBOnaRMWYMA== +"@babel/plugin-transform-react-jsx@^7.22.15", "@babel/plugin-transform-react-jsx@^7.22.5": + version "7.22.15" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.22.15.tgz#7e6266d88705d7c49f11c98db8b9464531289cd6" + integrity sha512-oKckg2eZFa8771O/5vi7XeTvmM6+O9cxZu+kanTU7tD4sin5nO/G8jGJhq8Hvt2Z0kUoEDRayuZLaUlYl8QuGA== dependencies: "@babel/helper-annotate-as-pure" "^7.22.5" - "@babel/helper-module-imports" "^7.22.5" + "@babel/helper-module-imports" "^7.22.15" "@babel/helper-plugin-utils" "^7.22.5" "@babel/plugin-syntax-jsx" "^7.22.5" - "@babel/types" "^7.22.5" + "@babel/types" "^7.22.15" "@babel/plugin-transform-react-pure-annotations@^7.22.5": version "7.22.5" @@ -1023,15 +1023,15 @@ "@babel/types" "^7.4.4" esutils "^2.0.2" -"@babel/preset-react@^7.22.5": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.22.5.tgz#c4d6058fbf80bccad02dd8c313a9aaa67e3c3dd6" - integrity sha512-M+Is3WikOpEJHgR385HbuCITPTaPRaNkibTEa9oiofmJvIsrceb4yp9RL9Kb+TE8LznmeyZqpP+Lopwcx59xPQ== +"@babel/preset-react@^7.22.15": + version "7.22.15" + resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.22.15.tgz#9a776892b648e13cc8ca2edf5ed1264eea6b6afc" + integrity sha512-Csy1IJ2uEh/PecCBXXoZGAZBeCATTuePzCSB7dLYWS0vOEj6CNpjxIhW4duWwZodBNueH7QO14WbGn8YyeuN9w== dependencies: "@babel/helper-plugin-utils" "^7.22.5" - "@babel/helper-validator-option" "^7.22.5" + "@babel/helper-validator-option" "^7.22.15" "@babel/plugin-transform-react-display-name" "^7.22.5" - "@babel/plugin-transform-react-jsx" "^7.22.5" + "@babel/plugin-transform-react-jsx" "^7.22.15" "@babel/plugin-transform-react-jsx-development" "^7.22.5" "@babel/plugin-transform-react-pure-annotations" "^7.22.5" @@ -1083,13 +1083,13 @@ debug "^4.1.0" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.20.0", "@babel/types@^7.20.2", "@babel/types@^7.20.5", "@babel/types@^7.20.7", "@babel/types@^7.21.0", "@babel/types@^7.22.5", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@^7.7.0": - version "7.22.5" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.5.tgz#cd93eeaab025880a3a47ec881f4b096a5b786fbe" - integrity sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA== +"@babel/types@^7.0.0", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.20.0", "@babel/types@^7.20.2", "@babel/types@^7.20.5", "@babel/types@^7.20.7", "@babel/types@^7.21.0", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@^7.7.0": + version "7.22.19" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.19.tgz#7425343253556916e440e662bb221a93ddb75684" + integrity sha512-P7LAw/LbojPzkgp5oznjE6tQEIWbp4PkkfrZDINTro9zgBRtI324/EYsiSI7lhPbpIQ+DCeR2NNmMWANGGfZsg== dependencies: "@babel/helper-string-parser" "^7.22.5" - "@babel/helper-validator-identifier" "^7.22.5" + "@babel/helper-validator-identifier" "^7.22.19" to-fast-properties "^2.0.0" "@bcoe/v8-coverage@^0.2.3": @@ -3219,13 +3219,13 @@ resolved "https://registry.yarnpkg.com/@types/natural-sort/-/natural-sort-0.0.21.tgz#5583cfcd250f72e45af8611ef515d4e881f49556" integrity sha512-WYMWhAQLuBym+6qQ2Ojptm6qIACnkkYYs08sj+PVgRCrB6b7k1QpTRk0yMmxhlpPn5MbXcSfd6sHOYlzaokU3w== -"@types/node-fetch@^2.6.2": - version "2.6.4" - resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660" - integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg== +"@types/node-fetch@^2.6.5": + version "2.6.5" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.5.tgz#972756a9a0fe354b2886bf3defe667ddb4f0d30a" + integrity sha512-OZsUlr2nxvkqUFLSaY2ZbA+P1q22q+KrlxWOn/38RX+u5kTkYL2mTujEpzUhGkS+K/QCYp9oagfXG39XOzyySg== dependencies: "@types/node" "*" - form-data "^3.0.0" + form-data "^4.0.0" "@types/node@*", "@types/node@>=10.0.0", "@types/node@>=13.7.0": version "20.5.9" @@ -3440,10 +3440,10 @@ resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== -"@types/semver@^7.3.12", "@types/semver@^7.5.0": - version "7.5.0" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a" - integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw== +"@types/semver@^7.3.12", "@types/semver@^7.5.2": + version "7.5.2" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.2.tgz#31f6eec1ed7ec23f4f05608d3a2d381df041f564" + integrity sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw== "@types/sequelize@^4.28.10": version "4.28.10" @@ -9867,10 +9867,10 @@ node-addon-api@^6.1.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-6.1.0.tgz#ac8470034e58e67d0c6f1204a18ae6995d9c0d76" integrity sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA== -node-fetch@2.6.12, node-fetch@2.6.7, node-fetch@^2.6.1, node-fetch@^2.6.12: - version "2.6.12" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.12.tgz#02eb8e22074018e3d5a83016649d04df0e348fba" - integrity sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g== +node-fetch@2.6.7, node-fetch@2.7.0, node-fetch@^2.6.1, node-fetch@^2.6.12: + version "2.7.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" + integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A== dependencies: whatwg-url "^5.0.0"