-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feature/2052-tree-…
…displayname-name-switcher
- Loading branch information
Showing
21 changed files
with
315 additions
and
61 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
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
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
87 changes: 87 additions & 0 deletions
87
packages/sn-editor-react/src/components/controls/html-editor-control.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,87 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
IconButton, | ||
IconButtonProps, | ||
Tooltip, | ||
} from '@material-ui/core' | ||
import CodeIcon from '@material-ui/icons/Code' | ||
import { Editor } from '@tiptap/react' | ||
import React, { FC, useState } from 'react' | ||
import { useLocalization } from '../../hooks' | ||
import { HtmlEditor } from '../html-editor' | ||
|
||
interface HTMLEditorControlProps { | ||
editor: Editor | ||
buttonProps?: Partial<IconButtonProps> | ||
} | ||
|
||
export const HTMLEditorControl: FC<HTMLEditorControlProps> = ({ editor, buttonProps }) => { | ||
const [open, setOpen] = useState(false) | ||
const [html, setHtml] = useState(editor.getHTML()) | ||
const localization = useLocalization() | ||
|
||
const handleClickOpen = () => { | ||
setOpen(true) | ||
} | ||
|
||
const handleClose = () => { | ||
if (editor.getHTML() === html) { | ||
setOpen(false) | ||
return | ||
} | ||
|
||
const confirmResult = window.confirm(localization.HTMLEditorControl.confirm) | ||
if (!confirmResult) { | ||
return | ||
} | ||
editor.commands.setContent(html) | ||
|
||
setOpen(false) | ||
} | ||
|
||
return ( | ||
<> | ||
<Tooltip title={`${localization.menubar.EditHtml}`}> | ||
<IconButton | ||
onClick={() => handleClickOpen()} | ||
color={editor.isActive('code') ? 'primary' : 'default'} | ||
{...buttonProps}> | ||
<CodeIcon style={{ marginTop: '-7px' }} /> | ||
<span style={{ position: 'absolute', fontSize: '12px', top: '13px', fontWeight: 'bold' }}>html</span> | ||
</IconButton> | ||
</Tooltip> | ||
<Dialog | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby="html-editor-control-title" | ||
fullWidth | ||
maxWidth="lg" | ||
onExited={() => { }}> | ||
<DialogTitle id="html-editor-control-title">{localization.HTMLEditorControl.title}</DialogTitle> | ||
<DialogContent> | ||
<HtmlEditor initialState={editor.getHTML()} fieldOnChange={setHtml} /> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
onClick={() => { | ||
setOpen(false) | ||
}}> | ||
{localization.common.cancel} | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
editor.commands.setContent(html) | ||
setOpen(false) | ||
}} | ||
color="primary"> | ||
{localization.linkControl.submit} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
) | ||
} |
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.