Lexical: add hashtag plugin

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-03-08 22:34:57 +01:00
parent 88a6ed0ee1
commit 5104cb4fed
4 changed files with 11 additions and 3 deletions

View file

@ -11,6 +11,7 @@ import { LexicalComposer, InitialConfigType } from '@lexical/react/LexicalCompos
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { ContentEditable } from '@lexical/react/LexicalContentEditable'; import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary'; import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
import { HashtagPlugin } from '@lexical/react/LexicalHashtagPlugin';
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin'; import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin'; import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin'; import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
@ -26,6 +27,7 @@ import { useAppDispatch, useFeatures } from 'soapbox/hooks';
import nodes from './nodes'; import nodes from './nodes';
import FloatingLinkEditorPlugin from './plugins/floating-link-editor-plugin'; import FloatingLinkEditorPlugin from './plugins/floating-link-editor-plugin';
import FloatingTextFormatToolbarPlugin from './plugins/floating-text-format-toolbar-plugin'; import FloatingTextFormatToolbarPlugin from './plugins/floating-text-format-toolbar-plugin';
import NewMentionsPlugin from './plugins/mention-plugin';
const StatePlugin = ({ composeId, autoFocus }: { composeId: string, autoFocus: boolean }) => { const StatePlugin = ({ composeId, autoFocus }: { composeId: string, autoFocus: boolean }) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -52,6 +54,7 @@ const ComposeEditor = React.forwardRef<string, any>(({ composeId, condensed, onF
onError: console.error, onError: console.error,
nodes, nodes,
theme: { theme: {
hashtag: 'hover:underline text-primary-600 dark:text-accent-blue hover:text-primary-800 dark:hover:text-accent-blue',
text: { text: {
bold: 'font-bold', bold: 'font-bold',
code: 'font-mono', code: 'font-mono',
@ -126,11 +129,13 @@ const ComposeEditor = React.forwardRef<string, any>(({ composeId, condensed, onF
}} }}
/> />
<HistoryPlugin /> <HistoryPlugin />
<HashtagPlugin />
{features.richText && <LinkPlugin />} {features.richText && <LinkPlugin />}
{features.richText && floatingAnchorElem && ( {features.richText && floatingAnchorElem && (
<> <>
<FloatingTextFormatToolbarPlugin anchorElem={floatingAnchorElem} /> <FloatingTextFormatToolbarPlugin anchorElem={floatingAnchorElem} />
<FloatingLinkEditorPlugin anchorElem={floatingAnchorElem} /> <FloatingLinkEditorPlugin anchorElem={floatingAnchorElem} />
<NewMentionsPlugin />
</> </>
)} )}
<StatePlugin composeId={composeId} autoFocus={autoFocus} /> <StatePlugin composeId={composeId} autoFocus={autoFocus} />

View file

@ -8,13 +8,14 @@ LICENSE file in the /app/soapbox/features/compose/editor directory.
*/ */
import { CodeHighlightNode, CodeNode } from '@lexical/code'; import { CodeHighlightNode, CodeNode } from '@lexical/code';
import { HashtagNode } from '@lexical/hashtag';
import { AutoLinkNode, LinkNode } from '@lexical/link'; import { AutoLinkNode, LinkNode } from '@lexical/link';
import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode'; import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
import { HeadingNode, QuoteNode } from '@lexical/rich-text'; import { HeadingNode, QuoteNode } from '@lexical/rich-text';
import type { Klass, LexicalNode } from 'lexical'; import type { Klass, LexicalNode } from 'lexical';
const PlaygroundNodes: Array<Klass<LexicalNode>> = [ const ComposeNodes: Array<Klass<LexicalNode>> = [
HeadingNode, HeadingNode,
QuoteNode, QuoteNode,
CodeNode, CodeNode,
@ -22,6 +23,7 @@ const PlaygroundNodes: Array<Klass<LexicalNode>> = [
AutoLinkNode, AutoLinkNode,
LinkNode, LinkNode,
HorizontalRuleNode, HorizontalRuleNode,
HashtagNode,
]; ];
export default PlaygroundNodes; export default ComposeNodes;

View file

@ -55,6 +55,7 @@
"@jest/globals": "^29.0.0", "@jest/globals": "^29.0.0",
"@lcdp/offline-plugin": "^5.1.0", "@lcdp/offline-plugin": "^5.1.0",
"@lexical/code": "^0.8.1", "@lexical/code": "^0.8.1",
"@lexical/hashtag": "^0.8.1",
"@lexical/link": "^0.8.1", "@lexical/link": "^0.8.1",
"@lexical/markdown": "^0.8.1", "@lexical/markdown": "^0.8.1",
"@lexical/react": "^0.8.1", "@lexical/react": "^0.8.1",

View file

@ -2400,7 +2400,7 @@
resolved "https://registry.yarnpkg.com/@lexical/dragon/-/dragon-0.8.1.tgz#b6c872fd618ad4593cf52dd9403e0c536b5ef7d1" resolved "https://registry.yarnpkg.com/@lexical/dragon/-/dragon-0.8.1.tgz#b6c872fd618ad4593cf52dd9403e0c536b5ef7d1"
integrity sha512-AnGolX/J8I+2Wc08fIz2mM52GgvxYLSBfvIMbN2ztc+UPgPB16cVzBVaJOEZm1+D7YeOG2pVRk+rfrsOdL7i4Q== integrity sha512-AnGolX/J8I+2Wc08fIz2mM52GgvxYLSBfvIMbN2ztc+UPgPB16cVzBVaJOEZm1+D7YeOG2pVRk+rfrsOdL7i4Q==
"@lexical/hashtag@0.8.1": "@lexical/hashtag@0.8.1", "@lexical/hashtag@^0.8.1":
version "0.8.1" version "0.8.1"
resolved "https://registry.yarnpkg.com/@lexical/hashtag/-/hashtag-0.8.1.tgz#c1ae42dd98cebbf1cb61373faaa79443ef2bd595" resolved "https://registry.yarnpkg.com/@lexical/hashtag/-/hashtag-0.8.1.tgz#c1ae42dd98cebbf1cb61373faaa79443ef2bd595"
integrity sha512-H7Owb8BxcqexJpihsccvw3sc6PKI+IzosIYUZ5NC+PB/0D6uUSoAyuNugySvTx57iIVzQECDa4kTvqO1lQHXGw== integrity sha512-H7Owb8BxcqexJpihsccvw3sc6PKI+IzosIYUZ5NC+PB/0D6uUSoAyuNugySvTx57iIVzQECDa4kTvqO1lQHXGw==