-
Notifications
You must be signed in to change notification settings - Fork 0
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
change tiptap #94
Open
binnmti
wants to merge
13
commits into
main
Choose a base branch
from
TipTap
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
change tiptap #94
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eb32653
change tiptap
binnmti 6d046d6
test commit
binnmti 5153a1d
test
binnmti 01d4870
test
binnmti 4e79efd
test
binnmti b119aa7
plus format
binnmti 43f5261
repair
binnmti 5ab07ba
test
binnmti e9f5c68
revert & review repair
binnmti 9d9dbd4
repair
binnmti f294d1e
repair tiptap
binnmti 069d01d
Add Comment
binnmti 00a450c
div file And Add Test
binnmti 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
Binary file not shown.
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useEditor, EditorContent } from '@tiptap/react' | ||
import Document from '@tiptap/extension-document' | ||
import Paragraph from '@tiptap/extension-paragraph' | ||
import Text from '@tiptap/extension-text' | ||
import HardBreak from '@tiptap/extension-hard-break' | ||
|
||
interface MyEditorProps { | ||
content: string; | ||
onUpdate: (content: string, markdownText: string) => void; | ||
} | ||
|
||
export const Tiptap: React.FC<MyEditorProps> = ({ content, onUpdate }) => { | ||
const editor = useEditor({ | ||
extensions: [ | ||
Document, | ||
Paragraph, | ||
Text, | ||
HardBreak, | ||
], | ||
content: content, | ||
editorProps: { | ||
attributes: { | ||
class: "p-1", | ||
}, | ||
}, | ||
onUpdate: ({ editor }) => { | ||
if (typeof onUpdate !== 'function') return; | ||
|
||
// TODO: The same procedure is required if you copy | ||
onUpdate(editor.getText({blockSeparator: '\n'}), editor.getText()); | ||
} | ||
}) | ||
return ( | ||
<div> | ||
<EditorContent editor={editor} /> | ||
</div> | ||
) | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class ContentConverter { | ||
static toHtml = (content: string): string => | ||
content.split(/\n/).map(line => `<p>${line}</p>`).join(''); | ||
|
||
static toMarkdownText = (content: string): string => | ||
content.split(/\n/).map(line => `${line}\n\n`).join(''); | ||
} | ||
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expect, test } from "vitest"; | ||
import {ContentConverter} from "../../src/model/ContentConverter"; | ||
|
||
test("Html", () => { | ||
expect(ContentConverter.toHtml(`a | ||
b | ||
c | ||
d`)).toEqual("<p>a</p><p>b</p><p>c</p><p>d</p>")}); | ||
|
||
|
||
test("MarkdownText", () => { | ||
expect(ContentConverter.toMarkdownText(`a | ||
b | ||
c | ||
d`)).toEqual(`a | ||
|
||
b | ||
|
||
c | ||
|
||
d | ||
|
||
`)}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider refactoring the
ContentConverter
class to use standalone functions instead of static methods, as the class only contains static members. This can simplify the structure and reduce overhead.Committable suggestion
Tools
Biome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
質問 : 上の書き方はC#だと良く書く書き方です(classにもstaticをつけます)。使う側も、クラス名+メソッド名の方がその内容をより端的に表せて分かりやすい気がします。下の書き方だとtoHtmlだけだと、何を変換するときに使うものかが分かりづらいような気がします。ただBiomeにnoStaticOnlyClassとあるところを見るとTypescriptでは下の書き方の方が推奨されるのでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binnmti お問い合わせありがとうございます。TypeScriptでは、確かにC#のようにクラスで静的メソッドを使うこともできますが、インスタンスメソッドやプロパティが不要な場合、クラスのオーバーヘッドを避けるために単独の関数を使用することが推奨されています。Biomeのlintルール
noStaticOnlyClass
はこの実践を推奨しています。ただし、ご指摘のように、関数だけでは何を変換するかが分かりにくい場合、モジュールやオブジェクトリテラルを使って関数をグループ化することで、クラス名を使うような文脈を提供することができます。例えば、次のように書くことが可能です:
このようにすると、
HtmlConverter.toHtml
やMarkdownConverter.toMarkdownText
として使用することで、どの変換が行われるかが明確になり、コードの可読性が向上します。この方法で、名前空間を利用しながらも、クラスのオーバーヘッドを避けることができます。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今教えてくれた、HtmlConverter.toHtmlとする書き方はtypescriptではポピュラーな書き方なのですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binnmti はい、TypeScriptでは、オブジェクトリテラルを使って関数をグループ化する方法は一定の人気がありますが、クラスやモジュールを使用する方法と比べると、それほど一般的ではありません。この方法は、特に関数が密接に関連しているがクラスインスタンスが必要でない場合に便利です。例えば、ユーティリティ関数や軽量な構造が必要な場合によく使用されます。
また、このパターンは、特定の機能をグループ化し、コードの読みやすさを向上させるために便利です。しかし、TypeScriptのコミュニティでは、より広範なソリューションとしてモジュールやクラスが推奨されることが多いです。そのため、プロジェクトの要件やチームの好みに応じて、適切な構造を選択することが重要です。
もし他の質問や懸念があれば、お気軽にお問い合わせください。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この書き方ってパフォーマンス的に問題ないですか?色々聞いて、HtmlConvertertoHtmlという名前にするのが一番良い気がしています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binnmti オブジェクトリテラルを使用して関数をグループ化する方法は、パフォーマンスにほとんど影響を与えません。TypeScriptやJavaScriptでは、オブジェクトリテラルは非常に軽量であり、クラスのインスタンス化に伴うオーバーヘッドが不要な場合には、特に有効です。このため、パフォーマンスの面から見ても問題はないと言えます。
また、
HtmlConvertertoHtml
という名前についてですが、この名前は非常に明確で、何をする関数なのかをよく表しています。ただし、通常の命名規則に従うと、HtmlConverter.toHtml
のようにピリオドを使用してメソッドを示す方が一般的です。もしHtmlConvertertoHtml
という名前をクラスやオブジェクトなしで関数名として使用する場合は、convertHtmlToHtml
などの動詞を含む形式がより適切かもしれません。これにより、関数が何をするのかがさらに明確になります。ご検討のほど、よろしくお願いいたします。もし他にご質問があれば、お気軽にどうぞ。
Learnings added