-
-
Notifications
You must be signed in to change notification settings - Fork 5
🐛 fix(rich-text): Fix missing alt attribute and use TipTap over Quill #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
caverav
wants to merge
19
commits into
main
Choose a base branch
from
bugfix/bad-html-from-quill
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3e4cbf1
🔧 chore: update frontend dependencies including tiptap extensions and…
caverav 5adcaf6
✨ feat: Update RichText component with Tiptap editor and custom styling
caverav 3955940
💄 style: Add CSS styles for a rich text editor component
caverav 4d65e63
✨ feat: update frontend dependencies
caverav 18f7f01
✨ feat: Update frontend dependencies, adding "@tiptap/core" version "…
caverav 76c608e
✨ feat: Updated RichText component with additional features like Kate…
caverav a9b1426
💄 style: Improve editor styling and add new features including table …
caverav 11611a6
✨ feat: update packages in frontend/package.json by adding "@tiptap/p…
caverav 2c743c1
✨ feat: Add CustomImage component and update images URL configuration
caverav d399932
✨ feat: Add image service with functions for fetching, creating, and …
caverav e4cb4d5
✨ feat: Add util functions.
caverav e727293
✨ feat: Add ImageHandler component with image handling logic
caverav 0a463a9
✨ feat: Configure Image extension in RichText editor to handle image …
caverav 01d14d4
refactor(useAuth.tsx): extract API endpoint URL to a constant for con…
caverav 35851ae
🐛 fix(report-generator.js): fix regex to handle optional alt attribut…
caverav 268562f
♻️ refactor(RichText.tsx): remove commented-out code and simplify ret…
caverav e39f7e9
🔥 remove(frontend): remove unused ImageHandler component and related …
caverav ea43193
♻️ refactor(report-generator.js): refactor splitHTMLParagraphs for cl…
caverav e4a3292
🔧 chore: Remove unused tiptap packages and react-quill-new from front…
caverav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,173 @@ | ||
| import './css/quill.snow.css'; | ||
| import './css/quill-styles.css'; | ||
| import 'katex/dist/katex.min.css'; | ||
| import 'reactjs-tiptap-editor/style.css'; | ||
|
|
||
| import { Field, Label } from '@headlessui/react'; | ||
| import ReactQuill from 'react-quill-new'; | ||
| import { useRef, useState } from 'react'; | ||
| import RcTiptapEditor, { | ||
| Attachment, | ||
| BaseKit, | ||
| Blockquote, | ||
| Bold, | ||
| BulletList, | ||
| Clear, | ||
| Code, | ||
| CodeBlock, | ||
| Color, | ||
| ColumnActionButton, | ||
| Emoji, | ||
| Excalidraw, | ||
| FontFamily, | ||
| FontSize, | ||
| FormatPainter, | ||
| Heading, | ||
| Highlight, | ||
| History, | ||
| Iframe, | ||
| Image, | ||
| Indent, | ||
| Italic, | ||
| Katex, | ||
| Link, | ||
| Mention, | ||
| MoreMark, | ||
| OrderedList, | ||
| SearchAndReplace, | ||
| SlashCommand, | ||
| Strike, | ||
| Table, | ||
| TableOfContents, | ||
| TaskList, | ||
| Underline, | ||
| } from 'reactjs-tiptap-editor'; | ||
|
|
||
| type RichTextEditorProps = { | ||
| const imagesUrl = import.meta.env.VITE_API_URL + '/api/images'; | ||
|
|
||
| const extensions = [ | ||
| BaseKit.configure({ | ||
| multiColumn: true, | ||
| placeholder: { | ||
| showOnlyCurrent: true, | ||
| }, | ||
| characterCount: { | ||
| limit: 50_000, | ||
| }, | ||
| }), | ||
| History, | ||
| SearchAndReplace, | ||
| TableOfContents, | ||
| FormatPainter.configure({ spacer: true }), | ||
| Clear, | ||
| FontFamily, | ||
| Heading.configure({ spacer: true }), | ||
| FontSize, | ||
| Bold, | ||
| Italic, | ||
| Underline, | ||
| Strike, | ||
| MoreMark, | ||
| Katex, | ||
| Emoji, | ||
| Color.configure({ spacer: true }), | ||
| Highlight, | ||
| BulletList, | ||
| OrderedList, | ||
| Indent, | ||
| TaskList.configure({ | ||
| spacer: true, | ||
| taskItem: { | ||
| nested: true, | ||
| }, | ||
| }), | ||
| Link, | ||
| Image.configure({ | ||
| upload: async (file: File) => { | ||
| // eslint-disable-next-line sonarjs/prefer-immediate-return -- we need to wait for the file to be read | ||
| const base64Value = await new Promise<string>((resolve, reject) => { | ||
| const reader = new FileReader(); | ||
| reader.readAsDataURL(file); | ||
| reader.onload = () => { | ||
| if (reader.result) { | ||
| resolve(reader.result.toString()); | ||
| } else { | ||
| reject(new Error('File reading failed')); | ||
| } | ||
| }; | ||
| reader.onerror = error => reject(error); | ||
| }); | ||
| return base64Value; | ||
| }, | ||
| }), | ||
caverav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Blockquote.configure({ spacer: true }), | ||
| SlashCommand, | ||
| Code.configure({ | ||
| toolbar: false, | ||
| }), | ||
| CodeBlock.configure({ defaultTheme: 'dracula' }), | ||
| ColumnActionButton, | ||
| Table, | ||
| Iframe, | ||
| Excalidraw, | ||
| Mention, | ||
| Attachment.configure({ | ||
| upload: async (file: File) => { | ||
| const formData = new FormData(); | ||
| formData.append('value', await file.text()); | ||
| const response = await fetch(imagesUrl, { | ||
| method: 'POST', | ||
| body: formData, | ||
| }); | ||
| const data = await response.json(); | ||
| return data.value; | ||
| }, | ||
| }), | ||
| ]; | ||
caverav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function debounce(func: (value: string) => void, wait: number) { | ||
| let timeout: NodeJS.Timeout; | ||
| return function (this: unknown, ...args: [string]) { | ||
| clearTimeout(timeout); | ||
|
|
||
| timeout = setTimeout(() => func.apply(this, args), wait); | ||
| }; | ||
| } | ||
|
|
||
| type RichTextProps = { | ||
| label: string; | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| placeholder: string; | ||
| onChange: (content: string) => void; | ||
| value: string; | ||
| }; | ||
|
|
||
| const RichText: React.FC<RichTextEditorProps> = ({ | ||
| label, | ||
| value, | ||
| placeholder, | ||
| onChange, | ||
| }) => { | ||
| const modules = { | ||
| toolbar: [ | ||
| [{ header: [1, 2, 3, false] }, { font: [] }], | ||
| [{ size: [] }], | ||
| ['bold', 'italic', 'underline', 'strike', 'blockquote'], | ||
| [ | ||
| { list: 'ordered' }, | ||
| { list: 'bullet' }, | ||
| { indent: '-1' }, | ||
| { indent: '+1' }, | ||
| ], | ||
| ['link', 'image', 'code-block'], | ||
| ['clean'], | ||
| ], | ||
| clipboard: { | ||
| matchVisual: false, | ||
| }, | ||
| }; | ||
| const RichText = ({ label, onChange, placeholder, value }: RichTextProps) => { | ||
| const [content, setContent] = useState(value || placeholder); | ||
| const refEditor = useRef(null); | ||
|
|
||
| const disable = false; | ||
|
|
||
| const onValueChange = debounce((value: string) => { | ||
| onChange(value); | ||
| setContent(value); | ||
| }, 300); | ||
|
|
||
| return ( | ||
| <div className="p-4 w-full rounded-md border-0 text-gray-900 ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"> | ||
| <Field> | ||
| <Label className="block font-medium leading-6 text-gray-300"> | ||
| {label} | ||
| </Label> | ||
| <ReactQuill | ||
| className="w-full overflow-auto bg-white mt-2 p-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500" | ||
| formats={[ | ||
| 'header', | ||
| 'font', | ||
| 'size', | ||
| 'bold', | ||
| 'italic', | ||
| 'underline', | ||
| 'strike', | ||
| 'blockquote', | ||
| 'list', | ||
| 'indent', | ||
| 'link', | ||
| 'image', | ||
| 'code-block', | ||
| ]} | ||
| modules={modules} | ||
| onChange={(value: string) => onChange(value)} | ||
| placeholder={placeholder} | ||
| theme="snow" | ||
| value={value} | ||
| <main | ||
| style={{ | ||
| padding: '0 20px', | ||
| }} | ||
| > | ||
| <p>{label}</p> | ||
| <div className="m-4"> | ||
| <RcTiptapEditor | ||
| content={content} | ||
| dark={true} | ||
| disabled={disable} | ||
| extensions={extensions} | ||
| onChangeContent={onValueChange} | ||
| output="html" | ||
| ref={refEditor} | ||
| /> | ||
| </Field> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| ); | ||
caverav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| export default RichText; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.