-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Text editor for custom workflow templates (#5654)
* add first version of text editor * add new editor to email body * fix line height * remove not needed styles * allow adding html tags + small refactoring * fix error when input is empty * styling of add variable dropdown * fix bg on focus * small design fixes * improve design * show error message for no input * text editor only for email body * remove test button * code clean up * code clean up * code clean up * fix that added variables weren't saved * fix import * first version of editor * connect reminder body of form with new editor * add pencile for link-editor * remove TreeViewPlugin * clean up css file * code clean up * add text indent for list * improve editor design * fix style * slow resizing of editor * fix that new data was removed when leaving tab * dont allow italic and bold at same time * code clean up * fix type error * code clean up * code clean up * remove text if changed from SMS to email or other way around * add add variable dropdown * show error message if email body is empty * add white-space pre-wrap * fix import * prettier * fix add variable dropdown for mobile * move dependencies to correct package.json file * remove html-to-text Co-authored-by: CarinaWolli <wollencarina@gmail.com>
- Loading branch information
1 parent
3137a18
commit 2de3e7f
Showing
20 changed files
with
1,207 additions
and
56 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
69 changes: 69 additions & 0 deletions
69
packages/features/ee/workflows/components/TextEditor/Editor.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,69 @@ | ||
import { CodeHighlightNode, CodeNode } from "@lexical/code"; | ||
import { AutoLinkNode, LinkNode } from "@lexical/link"; | ||
import { ListItemNode, ListNode } from "@lexical/list"; | ||
import { TRANSFORMERS } from "@lexical/markdown"; | ||
import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin"; | ||
import { LexicalComposer } from "@lexical/react/LexicalComposer"; | ||
import { ContentEditable } from "@lexical/react/LexicalContentEditable"; | ||
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin"; | ||
import { ListPlugin } from "@lexical/react/LexicalListPlugin"; | ||
import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin"; | ||
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"; | ||
import { HeadingNode, QuoteNode } from "@lexical/rich-text"; | ||
import { TableCellNode, TableNode, TableRowNode } from "@lexical/table"; | ||
import { UseFormReturn } from "react-hook-form"; | ||
|
||
import { FormValues } from "../../pages/workflow"; | ||
import ExampleTheme from "./ExampleTheme"; | ||
import AutoLinkPlugin from "./plugins/AutoLinkPlugin"; | ||
import ToolbarPlugin from "./plugins/ToolbarPlugin"; | ||
import "./stylesEditor.css"; | ||
|
||
export type TextEditorProps = { | ||
form: UseFormReturn<FormValues>; | ||
stepNumber: number; | ||
}; | ||
|
||
const editorConfig = { | ||
// The editor theme | ||
theme: ExampleTheme, | ||
// Handling of errors during update | ||
onError(error: any) { | ||
throw error; | ||
}, | ||
namespace: "", | ||
// Any custom nodes go here | ||
nodes: [ | ||
HeadingNode, | ||
ListNode, | ||
ListItemNode, | ||
QuoteNode, | ||
CodeNode, | ||
CodeHighlightNode, | ||
TableNode, | ||
TableCellNode, | ||
TableRowNode, | ||
AutoLinkNode, | ||
LinkNode, | ||
], | ||
}; | ||
|
||
export default function Editor(props: TextEditorProps) { | ||
return ( | ||
<div className="editor"> | ||
<LexicalComposer initialConfig={editorConfig}> | ||
<div className="editor-container"> | ||
<ToolbarPlugin form={props.form} stepNumber={props.stepNumber} /> | ||
<div className="editor-inner"> | ||
<RichTextPlugin contentEditable={<ContentEditable className="editor-input" />} placeholder="" /> | ||
<AutoFocusPlugin /> | ||
<ListPlugin /> | ||
<LinkPlugin /> | ||
<AutoLinkPlugin /> | ||
<MarkdownShortcutPlugin transformers={TRANSFORMERS} /> | ||
</div> | ||
</div> | ||
</LexicalComposer> | ||
</div> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/features/ee/workflows/components/TextEditor/ExampleTheme.ts
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 @@ | ||
const exampleTheme = { | ||
placeholder: "editor-placeholder", | ||
paragraph: "editor-paragraph", | ||
heading: { | ||
h1: "editor-heading-h1", | ||
h2: "editor-heading-h2", | ||
}, | ||
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", | ||
}, | ||
}; | ||
|
||
export default exampleTheme; |
4 changes: 4 additions & 0 deletions
4
packages/features/ee/workflows/components/TextEditor/images/icons/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
packages/features/ee/workflows/components/TextEditor/images/icons/list-ol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/features/ee/workflows/components/TextEditor/images/icons/list-ul.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/features/ee/workflows/components/TextEditor/images/icons/pencil-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ges/features/ee/workflows/components/TextEditor/images/icons/text-paragraph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/features/ee/workflows/components/TextEditor/images/icons/type-bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/features/ee/workflows/components/TextEditor/images/icons/type-h1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/features/ee/workflows/components/TextEditor/images/icons/type-h2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
packages/features/ee/workflows/components/TextEditor/images/icons/type-italic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions
36
packages/features/ee/workflows/components/TextEditor/plugins/AutoLinkPlugin.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,36 @@ | ||
import { AutoLinkPlugin } from "@lexical/react/LexicalAutoLinkPlugin"; | ||
|
||
const URL_MATCHER = | ||
/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/; | ||
|
||
const EMAIL_MATCHER = | ||
/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/; | ||
|
||
const MATCHERS = [ | ||
(text: any) => { | ||
const match = URL_MATCHER.exec(text); | ||
return ( | ||
match && { | ||
index: match.index, | ||
length: match[0].length, | ||
text: match[0], | ||
url: match[0], | ||
} | ||
); | ||
}, | ||
(text: any) => { | ||
const match = EMAIL_MATCHER.exec(text); | ||
return ( | ||
match && { | ||
index: match.index, | ||
length: match[0].length, | ||
text: match[0], | ||
url: `mailto:${match[0]}`, | ||
} | ||
); | ||
}, | ||
]; | ||
|
||
export default function PlaygroundAutoLinkPlugin() { | ||
return <AutoLinkPlugin matchers={MATCHERS} />; | ||
} |
Oops, something went wrong.