From 805d8a375af7d753f32ed46c60a1ed4a03a96867 Mon Sep 17 00:00:00 2001 From: shuai Date: Fri, 22 Sep 2023 16:46:54 +0800 Subject: [PATCH 1/2] fix: question and answer operate add undelete handle --- ui/src/components/Operate/index.tsx | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ui/src/components/Operate/index.tsx b/ui/src/components/Operate/index.tsx index 972b0501..5b83cb40 100644 --- a/ui/src/components/Operate/index.tsx +++ b/ui/src/components/Operate/index.tsx @@ -13,6 +13,8 @@ import { editCheck, reopenQuestion, questionOpetation, + changeQuestionStatus, + changeAnswerStatus, } from '@/services'; import { tryNormalLogged } from '@/utils/guard'; import { floppyNavigation } from '@/utils'; @@ -139,6 +141,30 @@ const Index: FC = ({ }); } }; + + const handleUndelete = () => { + Modal.confirm({ + title: t('undelete_title'), + content: t('undelete_desc'), + cancelBtnVariant: 'link', + confirmBtnVariant: 'danger', + confirmText: t('undelete', { keyPrefix: 'btns' }), + onConfirm: () => { + if (type === 'question') { + changeQuestionStatus(qid, 'available').then(() => { + callback?.('all'); + }); + } + + if (type === 'answer') { + changeAnswerStatus(aid, 'available').then(() => { + callback?.('all'); + }); + } + }, + }); + }; + const handleEdit = (evt, targetUrl) => { if (!floppyNavigation.shouldProcessLinkClick(evt)) { return; @@ -226,6 +252,10 @@ const Index: FC = ({ handleDelete(); } + if (action === 'undelete') { + handleUndelete(); + } + if (action === 'report') { handleReport(); } @@ -251,7 +281,10 @@ const Index: FC = ({ const firstAction = memberActions?.filter( (v) => - v.action === 'report' || v.action === 'edit' || v.action === 'delete', + v.action === 'report' || + v.action === 'edit' || + v.action === 'delete' || + v.action === 'undelete', ) || []; const secondAction = memberActions?.filter( From f68126c2dbdc1d7791298d108fc44d874c3e1c06 Mon Sep 17 00:00:00 2001 From: robin Date: Fri, 22 Sep 2023 17:15:38 +0800 Subject: [PATCH 2/2] refactor(plugin): Migrate to plugins repository --- ui/src/plugins/answer-chart/.eslintrc.cjs | 18 -- ui/src/plugins/answer-chart/.gitignore | 24 --- ui/src/plugins/answer-chart/Chart.tsx | 157 ------------------ ui/src/plugins/answer-chart/README.md | 3 - ui/src/plugins/answer-chart/hooks.ts | 42 ----- ui/src/plugins/answer-chart/i18n/en_US.json | 15 -- ui/src/plugins/answer-chart/i18n/index.ts | 7 - ui/src/plugins/answer-chart/i18n/zh_CN.json | 15 -- ui/src/plugins/answer-chart/icon.svg | 4 - ui/src/plugins/answer-chart/index.ts | 15 -- ui/src/plugins/answer-chart/package.json | 37 ----- ui/src/plugins/answer-chart/tsconfig.json | 31 ---- .../plugins/answer-chart/tsconfig.node.json | 10 -- ui/src/plugins/answer-chart/vite-env.d.ts | 1 - ui/src/plugins/answer-chart/vite.config.ts | 33 ---- ui/src/plugins/answer-formula/.eslintrc.cjs | 18 -- ui/src/plugins/answer-formula/.gitignore | 24 --- ui/src/plugins/answer-formula/Formula.tsx | 92 ---------- ui/src/plugins/answer-formula/README.md | 3 - ui/src/plugins/answer-formula/hooks.ts | 43 ----- ui/src/plugins/answer-formula/i18n/en_US.json | 11 -- ui/src/plugins/answer-formula/i18n/index.ts | 7 - ui/src/plugins/answer-formula/i18n/zh_CN.json | 11 -- ui/src/plugins/answer-formula/icon.svg | 3 - ui/src/plugins/answer-formula/index.ts | 15 -- ui/src/plugins/answer-formula/package.json | 38 ----- ui/src/plugins/answer-formula/tsconfig.json | 25 --- .../plugins/answer-formula/tsconfig.node.json | 10 -- ui/src/plugins/answer-formula/vite-env.d.ts | 1 - ui/src/plugins/answer-formula/vite.config.ts | 34 ---- ui/src/plugins/index.ts | 5 +- 31 files changed, 3 insertions(+), 749 deletions(-) delete mode 100644 ui/src/plugins/answer-chart/.eslintrc.cjs delete mode 100644 ui/src/plugins/answer-chart/.gitignore delete mode 100644 ui/src/plugins/answer-chart/Chart.tsx delete mode 100644 ui/src/plugins/answer-chart/README.md delete mode 100644 ui/src/plugins/answer-chart/hooks.ts delete mode 100644 ui/src/plugins/answer-chart/i18n/en_US.json delete mode 100644 ui/src/plugins/answer-chart/i18n/index.ts delete mode 100644 ui/src/plugins/answer-chart/i18n/zh_CN.json delete mode 100644 ui/src/plugins/answer-chart/icon.svg delete mode 100644 ui/src/plugins/answer-chart/index.ts delete mode 100644 ui/src/plugins/answer-chart/package.json delete mode 100644 ui/src/plugins/answer-chart/tsconfig.json delete mode 100644 ui/src/plugins/answer-chart/tsconfig.node.json delete mode 100644 ui/src/plugins/answer-chart/vite-env.d.ts delete mode 100644 ui/src/plugins/answer-chart/vite.config.ts delete mode 100644 ui/src/plugins/answer-formula/.eslintrc.cjs delete mode 100644 ui/src/plugins/answer-formula/.gitignore delete mode 100644 ui/src/plugins/answer-formula/Formula.tsx delete mode 100644 ui/src/plugins/answer-formula/README.md delete mode 100644 ui/src/plugins/answer-formula/hooks.ts delete mode 100644 ui/src/plugins/answer-formula/i18n/en_US.json delete mode 100644 ui/src/plugins/answer-formula/i18n/index.ts delete mode 100644 ui/src/plugins/answer-formula/i18n/zh_CN.json delete mode 100644 ui/src/plugins/answer-formula/icon.svg delete mode 100644 ui/src/plugins/answer-formula/index.ts delete mode 100644 ui/src/plugins/answer-formula/package.json delete mode 100644 ui/src/plugins/answer-formula/tsconfig.json delete mode 100644 ui/src/plugins/answer-formula/tsconfig.node.json delete mode 100644 ui/src/plugins/answer-formula/vite-env.d.ts delete mode 100644 ui/src/plugins/answer-formula/vite.config.ts diff --git a/ui/src/plugins/answer-chart/.eslintrc.cjs b/ui/src/plugins/answer-chart/.eslintrc.cjs deleted file mode 100644 index d6c95379..00000000 --- a/ui/src/plugins/answer-chart/.eslintrc.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/ui/src/plugins/answer-chart/.gitignore b/ui/src/plugins/answer-chart/.gitignore deleted file mode 100644 index a547bf36..00000000 --- a/ui/src/plugins/answer-chart/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/ui/src/plugins/answer-chart/Chart.tsx b/ui/src/plugins/answer-chart/Chart.tsx deleted file mode 100644 index 90c0075f..00000000 --- a/ui/src/plugins/answer-chart/Chart.tsx +++ /dev/null @@ -1,157 +0,0 @@ -import { FC, useState } from 'react'; -import { Dropdown } from 'react-bootstrap'; -import { useTranslation } from 'react-i18next'; - -import icon from './icon.svg'; -import { useRenderChart } from './hooks'; - -interface ChartProps { - editor; - previewElement: HTMLElement; -} - -const Chart: FC = ({ editor, previewElement }) => { - useRenderChart(previewElement); - const { t } = useTranslation('plugin', { - keyPrefix: 'chart', - }); - const [isLocked, setLockState] = useState(false); - - const handleMouseEnter = () => { - if (isLocked) { - return; - } - setLockState(true); - }; - - const handleMouseLeave = () => { - setLockState(false); - }; - const headerList = [ - { - label: t('flow_chart'), - tpl: `graph TD - A[Christmas] -->|Get money| B(Go shopping) - B --> C{Let me think} - C -->|One| D[Laptop] - C -->|Two| E[iPhone] - C -->|Three| F[fa:fa-car Car]`, - }, - { - label: t('sequence_diagram'), - tpl: `sequenceDiagram - Alice->>+John: Hello John, how are you? - Alice->>+John: John, can you hear me? - John-->>-Alice: Hi Alice, I can hear you! - John-->>-Alice: I feel great! - `, - }, - { - label: t('state_diagram'), - tpl: `stateDiagram-v2 - [*] --> Still - Still --> [*] - Still --> Moving - Moving --> Still - Moving --> Crash - Crash --> [*] - `, - }, - { - label: t('class_diagram'), - tpl: `classDiagram - Animal <|-- Duck - Animal <|-- Fish - Animal <|-- Zebra - Animal : +int age - Animal : +String gender - Animal: +isMammal() - Animal: +mate() - class Duck{ - +String beakColor - +swim() - +quack() - } - class Fish{ - -int sizeInFeet - -canEat() - } - class Zebra{ - +bool is_wild - +run() - } - `, - }, - { - label: t('pie_chart'), - tpl: `pie title Pets adopted by volunteers - "Dogs" : 386 - "Cats" : 85 - "Rats" : 15 - `, - }, - { - label: t('gantt_chart'), - tpl: `gantt - title A Gantt Diagram - dateFormat YYYY-MM-DD - section Section - A task :a1, 2014-01-01, 30d - Another task :after a1 , 20d - section Another - Task in sec :2014-01-12 , 12d - another task : 24d - `, - }, - { - label: t('entity_relationship_diagram'), - tpl: `erDiagram - CUSTOMER }|..|{ DELIVERY-ADDRESS : has - CUSTOMER ||--o{ ORDER : places - CUSTOMER ||--o{ INVOICE : "liable for" - DELIVERY-ADDRESS ||--o{ ORDER : receives - INVOICE ||--|{ ORDER : covers - ORDER ||--|{ ORDER-ITEM : includes - PRODUCT-CATEGORY ||--|{ PRODUCT : contains - PRODUCT ||--o{ ORDER-ITEM : "ordered in" - `, - }, - ]; - - const handleChange = (tpl: string) => { - const { ch } = editor.getCursor(); - - editor.replaceSelection(`${ch ? '\n' : ''}\`\`\`mermaid\n${tpl}\n\`\`\`\n`); - }; - - return ( -
- - - chart - - - {headerList.map((header) => { - return ( - { - e.preventDefault(); - handleChange(header.tpl); - }}> - {header.label} - - ); - })} - - -
- ); -}; - -export default Chart; diff --git a/ui/src/plugins/answer-chart/README.md b/ui/src/plugins/answer-chart/README.md deleted file mode 100644 index a300d314..00000000 --- a/ui/src/plugins/answer-chart/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# chart plugin -This plugin is used to extend the toolbar of the markdown editor of the answer project. -It provides a toolbar button to insert a chart into the markdown editor. diff --git a/ui/src/plugins/answer-chart/hooks.ts b/ui/src/plugins/answer-chart/hooks.ts deleted file mode 100644 index 6190e3a3..00000000 --- a/ui/src/plugins/answer-chart/hooks.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { useEffect } from 'react'; - -// @ts-ignore -import mermaid from 'mermaid'; - -const useRenderChart = (element: HTMLElement) => { - const render = (element) => { - mermaid.initialize({ startOnLoad: false }); - element.querySelectorAll('.language-mermaid').forEach((pre) => { - const flag = Date.now(); - mermaid.render( - `theGraph${flag}`, - pre.textContent || '', - function (svgCode: string) { - const p = document.createElement('p'); - p.className = 'text-center'; - p.innerHTML = svgCode; - pre.parentNode?.replaceChild(p, pre); - }, - ); - }); - }; - - useEffect(() => { - if (!element) { - return; - } - - render(element); - const observer = new MutationObserver(() => { - render(element); - }); - - observer.observe(element, { - childList: true, - attributes: true, - subtree: true, - }); - }, [element]); -}; - -export { useRenderChart }; diff --git a/ui/src/plugins/answer-chart/i18n/en_US.json b/ui/src/plugins/answer-chart/i18n/en_US.json deleted file mode 100644 index 5514b28d..00000000 --- a/ui/src/plugins/answer-chart/i18n/en_US.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "plugin": { - "chart": { - "text": "Chart", - "flow_chart": "Flow chart", - "sequence_diagram": "Sequence diagram", - "class_diagram": "Class diagram", - "state_diagram": "State diagram", - "entity_relationship_diagram": "Entity relationship diagram", - "user_defined_diagram": "User defined diagram", - "gantt_chart": "Gantt chart", - "pie_chart": "Pie chart" - } - } -} \ No newline at end of file diff --git a/ui/src/plugins/answer-chart/i18n/index.ts b/ui/src/plugins/answer-chart/i18n/index.ts deleted file mode 100644 index bc0b8168..00000000 --- a/ui/src/plugins/answer-chart/i18n/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import en_US from './en_US.json'; -import zh_CN from './zh_CN.json'; - -export default { - en_US, - zh_CN, -}; diff --git a/ui/src/plugins/answer-chart/i18n/zh_CN.json b/ui/src/plugins/answer-chart/i18n/zh_CN.json deleted file mode 100644 index 596d0283..00000000 --- a/ui/src/plugins/answer-chart/i18n/zh_CN.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "plugin": { - "chart": { - "text": "图表", - "flow_chart": "流程图", - "sequence_diagram": "时序图", - "class_diagram": "类图", - "state_diagram": "状态图", - "entity_relationship_diagram": "ER 图", - "user_defined_diagram": "用户自定义图表", - "gantt_chart": "甘特图", - "pie_chart": "饼图" - } - } -} \ No newline at end of file diff --git a/ui/src/plugins/answer-chart/icon.svg b/ui/src/plugins/answer-chart/icon.svg deleted file mode 100644 index 7b226b0d..00000000 --- a/ui/src/plugins/answer-chart/icon.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/ui/src/plugins/answer-chart/index.ts b/ui/src/plugins/answer-chart/index.ts deleted file mode 100644 index b223bb58..00000000 --- a/ui/src/plugins/answer-chart/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Chart from './Chart'; -import i18nConfig from './i18n'; -import { useRenderChart } from './hooks'; - -export default { - info: { - type: 'editor', - slug_name: 'chart', - }, - component: Chart, - i18nConfig, - hooks: { - useRender: [useRenderChart], - }, -}; diff --git a/ui/src/plugins/answer-chart/package.json b/ui/src/plugins/answer-chart/package.json deleted file mode 100644 index 002eb9b3..00000000 --- a/ui/src/plugins/answer-chart/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "answer-chart", - "private": true, - "author": "Answer.dev", - "version": "0.0.1", - "files": [ - "dist", - "README.md" - ], - "main": "./dist/answer-chart.umd.js", - "module": "./dist/answer-chart.es.js", - "exports": { - ".": { - "import": "./dist/answer-chart.es.js", - "require": "./dist/answer-chart.umd.js" - } - }, - "scripts": { - "dev": "vite build --mode development --watch", - "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview" - }, - "devDependencies": { - "@typescript-eslint/eslint-plugin": "^6.0.0", - "@typescript-eslint/parser": "^6.0.0", - "@vitejs/plugin-react-swc": "^3.3.2", - "eslint": "^8.45.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.3", - "typescript": "^5.0.2", - "vite": "^4.4.5" - }, - "dependencies": { - "mermaid": "^9.1.7" - } -} \ No newline at end of file diff --git a/ui/src/plugins/answer-chart/tsconfig.json b/ui/src/plugins/answer-chart/tsconfig.json deleted file mode 100644 index 25005952..00000000 --- a/ui/src/plugins/answer-chart/tsconfig.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "lib": [ - "ES2020", - "DOM", - "DOM.Iterable" - ], - "module": "ESNext", - "skipLibCheck": true, - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noImplicitAny": false, - "noEmit": true, - "jsx": "react-jsx", - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - }, - "references": [ - { - "path": "./tsconfig.node.json" - } - ] -} \ No newline at end of file diff --git a/ui/src/plugins/answer-chart/tsconfig.node.json b/ui/src/plugins/answer-chart/tsconfig.node.json deleted file mode 100644 index 42872c59..00000000 --- a/ui/src/plugins/answer-chart/tsconfig.node.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "composite": true, - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true - }, - "include": ["vite.config.ts"] -} diff --git a/ui/src/plugins/answer-chart/vite-env.d.ts b/ui/src/plugins/answer-chart/vite-env.d.ts deleted file mode 100644 index 11f02fe2..00000000 --- a/ui/src/plugins/answer-chart/vite-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/ui/src/plugins/answer-chart/vite.config.ts b/ui/src/plugins/answer-chart/vite.config.ts deleted file mode 100644 index f9da42b7..00000000 --- a/ui/src/plugins/answer-chart/vite.config.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { defineConfig } from 'vite'; -import react from '@vitejs/plugin-react-swc'; -import packageJson from './package.json'; - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - build: { - lib: { - entry: 'index.ts', - name: packageJson.name, - fileName: (format) => `${packageJson.name}.${format}.js`, - }, - rollupOptions: { - external: [ - 'react', - 'react-dom', - 'react-i18next', - 'react-bootstrap', - 'mermaid', - ], - output: { - globals: { - react: 'React', - 'react-dom': 'ReactDOM', - 'react-i18next': 'reactI18next', - 'react-bootstrap': 'reactBootstrap', - mermaid: 'mermaid', - }, - }, - }, - }, -}); diff --git a/ui/src/plugins/answer-formula/.eslintrc.cjs b/ui/src/plugins/answer-formula/.eslintrc.cjs deleted file mode 100644 index d6c95379..00000000 --- a/ui/src/plugins/answer-formula/.eslintrc.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/ui/src/plugins/answer-formula/.gitignore b/ui/src/plugins/answer-formula/.gitignore deleted file mode 100644 index a547bf36..00000000 --- a/ui/src/plugins/answer-formula/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/ui/src/plugins/answer-formula/Formula.tsx b/ui/src/plugins/answer-formula/Formula.tsx deleted file mode 100644 index f2813bee..00000000 --- a/ui/src/plugins/answer-formula/Formula.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { FC, useState } from 'react'; -import { Dropdown } from 'react-bootstrap'; -import { useTranslation } from 'react-i18next'; - -import 'katex/dist/katex.min.css'; - -import icon from './icon.svg'; -import { useRenderFormula } from './hooks'; - -interface FormulaProps { - editor; - previewElement: HTMLElement; -} - -const Formula: FC = ({ editor, previewElement }) => { - useRenderFormula(previewElement); - const { t } = useTranslation('plugin', { - keyPrefix: 'formula', - }); - const [isLocked, setLockState] = useState(false); - - const handleMouseEnter = () => { - if (isLocked) { - return; - } - setLockState(true); - }; - - const handleMouseLeave = () => { - setLockState(false); - }; - const formulaList = [ - { - type: 'line', - label: t('options.inline'), - }, - { - type: 'block', - label: t('options.block'), - }, - ]; - - const handleClick = (type: string, label: string) => { - if (!editor) { - return; - } - const { wrapText } = editor; - if (type === 'line') { - wrapText('\\\\( ', ' \\\\)', label); - } else { - const cursor = editor.getCursor(); - - wrapText('\n$$\n', '\n$$\n', label); - - editor.setSelection( - { line: cursor.line + 2, ch: 0 }, - { line: cursor.line + 2, ch: label.length }, - ); - } - editor?.focus(); - }; - return ( -
- - - formula - - - {formulaList.map((formula) => { - return ( - { - e.preventDefault(); - handleClick(formula.type, formula.label); - }}> - {formula.label} - - ); - })} - - -
- ); -}; - -export default Formula; diff --git a/ui/src/plugins/answer-formula/README.md b/ui/src/plugins/answer-formula/README.md deleted file mode 100644 index 618c1b23..00000000 --- a/ui/src/plugins/answer-formula/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# formula plugin -This plugin is used to extend the toolbar of the markdown editor of the answer project. -It provides a toolbar button to insert a formula into the markdown editor. diff --git a/ui/src/plugins/answer-formula/hooks.ts b/ui/src/plugins/answer-formula/hooks.ts deleted file mode 100644 index f3bd5719..00000000 --- a/ui/src/plugins/answer-formula/hooks.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { useEffect } from 'react'; - -// @ts-ignore -import katexRender from 'katex/contrib/auto-render/auto-render'; - -const useRenderFormula = (element: HTMLElement) => { - const render = (element) => { - katexRender(element, { - delimiters: [ - { left: '$$', right: '$$', display: true }, - { left: '$$
', right: '
$$', display: true }, - { - left: '\\begin{equation}', - right: '\\end{equation}', - display: true, - }, - { left: '\\begin{align}', right: '\\end{align}', display: true }, - { left: '\\begin{alignat}', right: '\\end{alignat}', display: true }, - { left: '\\begin{gather}', right: '\\end{gather}', display: true }, - { left: '\\(', right: '\\)', display: false }, - { left: '\\[', right: '\\]', display: true }, - ], - }); - }; - useEffect(() => { - if (!element) { - return; - } - - render(element); - const observer = new MutationObserver(() => { - render(element); - }); - - observer.observe(element, { - childList: true, - attributes: true, - subtree: true, - }); - }, [element]); -}; - -export { useRenderFormula }; diff --git a/ui/src/plugins/answer-formula/i18n/en_US.json b/ui/src/plugins/answer-formula/i18n/en_US.json deleted file mode 100644 index 37692898..00000000 --- a/ui/src/plugins/answer-formula/i18n/en_US.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugin": { - "formula": { - "text": "Formula", - "options": { - "inline": "Inline formula", - "block": "Block formula" - } - } - } -} \ No newline at end of file diff --git a/ui/src/plugins/answer-formula/i18n/index.ts b/ui/src/plugins/answer-formula/i18n/index.ts deleted file mode 100644 index bc0b8168..00000000 --- a/ui/src/plugins/answer-formula/i18n/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import en_US from './en_US.json'; -import zh_CN from './zh_CN.json'; - -export default { - en_US, - zh_CN, -}; diff --git a/ui/src/plugins/answer-formula/i18n/zh_CN.json b/ui/src/plugins/answer-formula/i18n/zh_CN.json deleted file mode 100644 index 50c18a95..00000000 --- a/ui/src/plugins/answer-formula/i18n/zh_CN.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugin": { - "formula": { - "text": "公式", - "options": { - "inline": "行内公式", - "block": "公式块" - } - } - } -} \ No newline at end of file diff --git a/ui/src/plugins/answer-formula/icon.svg b/ui/src/plugins/answer-formula/icon.svg deleted file mode 100644 index 06e2ad9d..00000000 --- a/ui/src/plugins/answer-formula/icon.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/ui/src/plugins/answer-formula/index.ts b/ui/src/plugins/answer-formula/index.ts deleted file mode 100644 index d7568c7d..00000000 --- a/ui/src/plugins/answer-formula/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Formula from './Formula'; -import i18nConfig from './i18n'; -import { useRenderFormula } from './hooks'; - -export default { - info: { - type: 'editor', - slug_name: 'formula', - }, - component: Formula, - i18nConfig, - hooks: { - useRender: [useRenderFormula], - }, -}; diff --git a/ui/src/plugins/answer-formula/package.json b/ui/src/plugins/answer-formula/package.json deleted file mode 100644 index 34bd3adc..00000000 --- a/ui/src/plugins/answer-formula/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "answer-formula", - "private": true, - "author": "Answer.dev", - "version": "0.0.1", - "files": [ - "dist", - "README.md" - ], - "main": "./dist/answer-formula.umd.js", - "module": "./dist/answer-formula.es.js", - "exports": { - ".": { - "import": "./dist/answer-formula.es.js", - "require": "./dist/answer-formula.umd.js" - } - }, - "scripts": { - "dev": "vite build --mode development --watch", - "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview" - }, - "devDependencies": { - "@typescript-eslint/eslint-plugin": "^6.0.0", - "@typescript-eslint/parser": "^6.0.0", - "@vitejs/plugin-react-swc": "^3.3.2", - "eslint": "^8.45.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.3", - "typescript": "^5.0.2", - "vite": "^4.4.5", - "vite-plugin-css-injected-by-js": "^3.3.0" - }, - "dependencies": { - "katex": "^0.16.2" - } -} \ No newline at end of file diff --git a/ui/src/plugins/answer-formula/tsconfig.json b/ui/src/plugins/answer-formula/tsconfig.json deleted file mode 100644 index d3c8b521..00000000 --- a/ui/src/plugins/answer-formula/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noImplicitAny": false, - "noEmit": true, - "jsx": "react-jsx", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - }, - "references": [{ "path": "./tsconfig.node.json" }] -} diff --git a/ui/src/plugins/answer-formula/tsconfig.node.json b/ui/src/plugins/answer-formula/tsconfig.node.json deleted file mode 100644 index 42872c59..00000000 --- a/ui/src/plugins/answer-formula/tsconfig.node.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "composite": true, - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true - }, - "include": ["vite.config.ts"] -} diff --git a/ui/src/plugins/answer-formula/vite-env.d.ts b/ui/src/plugins/answer-formula/vite-env.d.ts deleted file mode 100644 index 11f02fe2..00000000 --- a/ui/src/plugins/answer-formula/vite-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/ui/src/plugins/answer-formula/vite.config.ts b/ui/src/plugins/answer-formula/vite.config.ts deleted file mode 100644 index d9e86112..00000000 --- a/ui/src/plugins/answer-formula/vite.config.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { defineConfig } from 'vite'; -import react from '@vitejs/plugin-react-swc'; -import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'; -import packageJson from './package.json'; - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react(), cssInjectedByJsPlugin()], - build: { - lib: { - entry: 'index.ts', - name: packageJson.name, - fileName: (format) => `${packageJson.name}.${format}.js`, - }, - rollupOptions: { - external: [ - 'react', - 'react-dom', - 'react-i18next', - 'react-bootstrap', - 'katex', - ], - output: { - globals: { - react: 'React', - 'react-dom': 'ReactDOM', - 'react-i18next': 'reactI18next', - 'react-bootstrap': 'reactBootstrap', - katex: 'katex', - }, - }, - }, - }, -}); diff --git a/ui/src/plugins/index.ts b/ui/src/plugins/index.ts index e9f227c2..71aa8de7 100644 --- a/ui/src/plugins/index.ts +++ b/ui/src/plugins/index.ts @@ -1,2 +1,3 @@ -export { default as Chart } from 'answer-chart'; -export { default as Formula } from 'answer-formula'; +export default null; + +// export { default as Demo } from './Demo'; \ No newline at end of file