From b97f0fe9d3102f600e51813a977dc27b121e4a27 Mon Sep 17 00:00:00 2001 From: shuai Date: Mon, 21 Nov 2022 10:12:27 +0800 Subject: [PATCH 001/194] feat: add diff function --- ui/package.json | 1 + ui/pnpm-lock.yaml | 7 +++++++ ui/src/index.scss | 15 +++++++++++++++ ui/src/router/routes.ts | 4 ++++ ui/src/utils/common.ts | 21 +++++++++++++++++++++ 5 files changed, 48 insertions(+) diff --git a/ui/package.json b/ui/package.json index 4dd40263..a26e51bb 100644 --- a/ui/package.json +++ b/ui/package.json @@ -19,6 +19,7 @@ "codemirror": "5.65.0", "copy-to-clipboard": "^3.3.2", "dayjs": "^1.11.5", + "diff": "^5.1.0", "i18next": "^21.9.0", "katex": "^0.16.2", "lodash": "^4.17.21", diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml index 78e83835..6f91fd63 100644 --- a/ui/pnpm-lock.yaml +++ b/ui/pnpm-lock.yaml @@ -25,6 +25,7 @@ specifiers: copy-to-clipboard: ^3.3.2 customize-cra: ^1.0.0 dayjs: ^1.11.5 + diff: ^5.1.0 eslint: ^8.0.1 eslint-config-airbnb: ^19.0.4 eslint-config-airbnb-typescript: ^17.0.0 @@ -72,6 +73,7 @@ dependencies: codemirror: 5.65.0 copy-to-clipboard: 3.3.2 dayjs: 1.11.5 + diff: 5.1.0 i18next: 21.9.2 katex: 0.16.2 lodash: 4.17.21 @@ -4742,6 +4744,11 @@ packages: resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} engines: {node: '>=0.3.1'} + /diff/5.1.0: + resolution: {integrity: sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==} + engines: {node: '>=0.3.1'} + dev: false + /dir-glob/3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} diff --git a/ui/src/index.scss b/ui/src/index.scss index a767e0a0..66b3c299 100644 --- a/ui/src/index.scss +++ b/ui/src/index.scss @@ -253,3 +253,18 @@ a { padding: 1px 0.5rem 2px; height: 24px; } + +.review-text-delete { + color: #842029; + background-color: #F8D7DA; + text-decoration: line-through; + .review-text-add { + text-decoration: none; + } +} + +.review-text-add { + color: #0F5132; + background-color: #D1E7DD; + text-decoration: none !important; +} diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts index be7e61ac..3454738a 100644 --- a/ui/src/router/routes.ts +++ b/ui/src/router/routes.ts @@ -201,6 +201,10 @@ const routes: RouteNode[] = [ return guard.forbidden(); }, }, + { + path: '/revision', + page: 'pages/Revision', + }, // for admin { path: 'admin', diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts index 41622307..46d43ba0 100644 --- a/ui/src/utils/common.ts +++ b/ui/src/utils/common.ts @@ -1,5 +1,7 @@ import i18next from 'i18next'; +const Diff = require('diff'); + function thousandthDivision(num) { const reg = /\d{1,3}(?=(\d{3})+$)/g; return `${num}`.replace(reg, '$&,'); @@ -163,6 +165,24 @@ function handleFormError( return data; } +function diffText(newText: string, oldText: string): string { + const diff = Diff.diffChars(newText, oldText); + const result = diff.map((part) => { + if (part.added) { + return `${part.value}`; + } + if (part.removed) { + return `${part.value}`; + } + return part.value; + }); + return result + .join('') + ?.replace(/\n/gi, '
') + ?.replace(/