forked from neo4j/neo4j-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Lexical editor into Details Pane
- Loading branch information
Showing
7 changed files
with
355 additions
and
2 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
157 changes: 157 additions & 0 deletions
157
...eo4j-arc/graph-visualization/GraphVisualizer/DefaultPanelContent/Editor/DefaultEditor.tsx
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,157 @@ | ||
/* | ||
* Copyright Jiaqi Liu | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import React, { useState } from 'react' | ||
|
||
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin' | ||
import { LexicalComposer } from '@lexical/react/LexicalComposer' | ||
import { ContentEditable } from '@lexical/react/LexicalContentEditable' | ||
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary' | ||
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin' | ||
import { HeadingNode, QuoteNode } from '@lexical/rich-text' | ||
import { TableCellNode, TableNode, TableRowNode } from '@lexical/table' | ||
import { ListItemNode, ListNode } from '@lexical/list' | ||
import { CodeHighlightNode, CodeNode } from '@lexical/code' | ||
import { AutoLinkNode, LinkNode } from '@lexical/link' | ||
import { StyledDefaultEditor } from './styled' | ||
|
||
export default function DefaultEditor(): JSX.Element { | ||
const initialConfig = { | ||
namespace: 'DefaultDetailsPaneEditor', | ||
onError: (error: Error) => { | ||
throw error | ||
}, | ||
nodes: [ | ||
HeadingNode, | ||
ListNode, | ||
ListItemNode, | ||
QuoteNode, | ||
CodeNode, | ||
CodeHighlightNode, | ||
TableNode, | ||
TableCellNode, | ||
TableRowNode, | ||
AutoLinkNode, | ||
LinkNode | ||
], | ||
theme: { | ||
ltr: 'ltr', | ||
rtl: 'rtl', | ||
placeholder: 'editor-placeholder', | ||
paragraph: 'editor-paragraph', | ||
quote: 'editor-quote', | ||
heading: { | ||
h1: 'editor-heading-h1', | ||
h2: 'editor-heading-h2', | ||
h3: 'editor-heading-h3', | ||
h4: 'editor-heading-h4', | ||
h5: 'editor-heading-h5' | ||
}, | ||
list: { | ||
nested: { | ||
listitem: 'editor-nested-listitem' | ||
}, | ||
ol: 'editor-list-ol', | ||
ul: 'editor-list-ul', | ||
listitem: 'editor-listitem' | ||
}, | ||
image: 'editor-image', | ||
link: 'editor-link', | ||
text: { | ||
bold: 'editor-text-bold', | ||
italic: 'editor-text-italic', | ||
overflowed: 'editor-text-overflowed', | ||
hashtag: 'editor-text-hashtag', | ||
underline: 'editor-text-underline', | ||
strikethrough: 'editor-text-strikethrough', | ||
underlineStrikethrough: 'editor-text-underlineStrikethrough', | ||
code: 'editor-text-code' | ||
}, | ||
code: 'editor-code', | ||
codeHighlight: { | ||
atrule: 'editor-tokenAttr', | ||
attr: 'editor-tokenAttr', | ||
boolean: 'editor-tokenProperty', | ||
builtin: 'editor-tokenSelector', | ||
cdata: 'editor-tokenComment', | ||
char: 'editor-tokenSelector', | ||
class: 'editor-tokenFunction', | ||
'class-name': 'editor-tokenFunction', | ||
comment: 'editor-tokenComment', | ||
constant: 'editor-tokenProperty', | ||
deleted: 'editor-tokenProperty', | ||
doctype: 'editor-tokenComment', | ||
entity: 'editor-tokenOperator', | ||
function: 'editor-tokenFunction', | ||
important: 'editor-tokenVariable', | ||
inserted: 'editor-tokenSelector', | ||
keyword: 'editor-tokenAttr', | ||
namespace: 'editor-tokenVariable', | ||
number: 'editor-tokenProperty', | ||
operator: 'editor-tokenOperator', | ||
prolog: 'editor-tokenComment', | ||
property: 'editor-tokenProperty', | ||
punctuation: 'editor-tokenPunctuation', | ||
regex: 'editor-tokenVariable', | ||
selector: 'editor-tokenSelector', | ||
string: 'editor-tokenSelector', | ||
symbol: 'editor-tokenProperty', | ||
tag: 'editor-tokenProperty', | ||
url: 'editor-tokenOperator', | ||
variable: 'editor-tokenVariable' | ||
} | ||
} | ||
} | ||
|
||
const [floatingAnchorElem, setFloatingAnchorElem] = | ||
useState<HTMLDivElement | null>(null) | ||
|
||
const onRef = (_floatingAnchorElem: HTMLDivElement) => { | ||
if (_floatingAnchorElem !== null) { | ||
setFloatingAnchorElem(_floatingAnchorElem) | ||
} | ||
} | ||
|
||
return ( | ||
<StyledDefaultEditor> | ||
<LexicalComposer initialConfig={initialConfig}> | ||
<div className="editor-container"> | ||
<div className="editor-inner"> | ||
<AutoFocusPlugin /> | ||
<RichTextPlugin | ||
placeholder={<Placeholder />} | ||
contentEditable={ | ||
<div className="editor-scroller"> | ||
<div className="editor" ref={onRef}> | ||
<ContentEditable /> | ||
</div> | ||
</div> | ||
} | ||
ErrorBoundary={LexicalErrorBoundary} | ||
/> | ||
</div> | ||
</div> | ||
</LexicalComposer> | ||
</StyledDefaultEditor> | ||
) | ||
} | ||
|
||
function Placeholder() { | ||
return <div className="editor-placeholder">Enter some plain text...</div> | ||
} |
24 changes: 24 additions & 0 deletions
24
src/neo4j-arc/graph-visualization/GraphVisualizer/DefaultPanelContent/Editor/styled.tsx
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,24 @@ | ||
/* | ||
* Copyright Jiaqi Liu | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import styled from 'styled-components' | ||
|
||
export const StyledDefaultEditor = styled.div` | ||
height: 100px; | ||
` |
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.