-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
485 additions
and
4 deletions.
There are no files selected for viewing
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
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,21 @@ | ||
--- | ||
description: Twitter | ||
--- | ||
|
||
|
||
Twitter is a node extension that allows you to add an Twitter to your editor. | ||
|
||
- [react-tweet](https://www.npmjs.com/package/react-tweet) | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { Twitter } from 'reactjs-tiptap-editor'; // [!code ++] | ||
|
||
const extensions = [ | ||
..., | ||
// Import Extensions Here | ||
]; | ||
``` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,5 @@ | ||
export function Twitter() { | ||
return ( | ||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" d="m3 21l7.548-7.548M21 3l-7.548 7.548m0 0L8 3H3l7.548 10.452m2.904-2.904L21 21h-5l-5.452-7.548" color="currentColor"></path></svg> | ||
) | ||
} |
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,97 @@ | ||
/* eslint-disable react/no-useless-fragment */ | ||
import { useCallback, useMemo, useState } from 'react' | ||
|
||
import type { Editor } from '@tiptap/react' | ||
import { BubbleMenu } from '@tiptap/react' | ||
|
||
import { Twitter } from '@/extensions' | ||
import { ActionButton } from '@/components/ActionButton' | ||
import { useLocale } from '@/locales' | ||
import FormEditLinkTwitter from '@/extensions/Twitter/components/FormEditLinkTwitter' | ||
import { deleteNode } from '@/utils/delete-node' | ||
|
||
export interface BubbleMenuTwitterProps { | ||
editor: Editor | ||
disabled?: boolean | ||
} | ||
|
||
function BubbleMenuTwitter({ editor, disabled }: BubbleMenuTwitterProps) { | ||
const [showEdit, setShowEdit] = useState(false) | ||
const { t } = useLocale() | ||
|
||
const srcInit = useMemo(() => { | ||
const { src } = editor.getAttributes(Twitter.name) | ||
return src as string | ||
}, [editor]) | ||
|
||
const shouldShow = useCallback(({ editor }: { editor: Editor }) => { | ||
const isActive = editor.isActive(Twitter.name) | ||
return isActive | ||
}, []) | ||
|
||
const onSetLink = (src: string) => { | ||
editor.commands.updateTweet({ src }) | ||
setShowEdit(false) | ||
} | ||
|
||
const deleteMe = useCallback(() => deleteNode(Twitter.name, editor), [editor]) | ||
|
||
return ( | ||
<> | ||
<BubbleMenu | ||
editor={editor} | ||
shouldShow={shouldShow} | ||
tippyOptions={{ | ||
popperOptions: { | ||
modifiers: [{ name: 'flip', enabled: false }], | ||
}, | ||
placement: 'bottom-start', | ||
offset: [-2, 16], | ||
zIndex: 9999, | ||
onHidden: () => { | ||
setShowEdit(false) | ||
}, | ||
}} | ||
> | ||
{disabled | ||
? ( | ||
<></> | ||
) | ||
: ( | ||
<> | ||
{showEdit | ||
? ( | ||
<FormEditLinkTwitter | ||
onSetLink={onSetLink} | ||
editor={editor} | ||
srcInit={srcInit} | ||
/> | ||
) | ||
: ( | ||
<div className="richtext-flex richtext-items-center richtext-gap-2 richtext-p-2 richtext-bg-white !richtext-border richtext-rounded-lg richtext-shadow-sm dark:richtext-bg-black richtext-border-neutral-200 dark:richtext-border-neutral-800"> | ||
<div className="richtext-flex richtext-flex-nowrap"> | ||
<ActionButton | ||
icon="Pencil" | ||
tooltip={t('editor.link.edit.tooltip')} | ||
action={() => { | ||
setShowEdit(true) | ||
}} | ||
tooltipOptions={{ sideOffset: 15 }} | ||
/> | ||
<ActionButton | ||
icon="Trash" | ||
tooltip={t('editor.delete')} | ||
action={deleteMe} | ||
tooltipOptions={{ sideOffset: 15 }} | ||
/> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
)} | ||
</BubbleMenu> | ||
</> | ||
) | ||
} | ||
|
||
export { BubbleMenuTwitter } |
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
Oops, something went wrong.