This file contains hidden or 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
| <TextField | |
| variant="outlined" | |
| InputProps={{ | |
| endAdornment: ( | |
| <InputAdornment position="start"> | |
| <IconButton | |
| onClick={() => { | |
| setEditorState( | |
| draftUtils.createLinkAtSelection(editorState, anchorElUrl) | |
| ); |
This file contains hidden or 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
| import * as React from "react"; | |
| import { EditorContext } from "./EditorContext"; | |
| export function DecoratedLink({ | |
| className, | |
| children, | |
| entityKey, | |
| target | |
| }: { | |
| className: string; |
This file contains hidden or 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
| import { ContentBlock, ContentState } from "draft-js"; | |
| const matchesEntityType = (type: string) => type === "LINK"; | |
| export function linkStrategy( | |
| contentBlock: ContentBlock, | |
| cb: (start: number, end: number) => void, | |
| contentState: ContentState | |
| ) { | |
| if (!contentState) return; | |
| contentBlock.findEntityRanges(character => { |
This file contains hidden or 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
| import { ContentBlock, ContentState } from "draft-js"; | |
| const matchesEntityType = (type: string) => type === "LINK"; | |
| export function linkStrategy( | |
| contentBlock: ContentBlock, | |
| cb: (start: number, end: number) => void, | |
| contentState: ContentState | |
| ) { | |
| if (!contentState) return; | |
| contentBlock.findEntityRanges(character => { |
This file contains hidden or 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
| const [selectionRect, setSelectionRect] = React.useState<{ | |
| left: number; | |
| width: number; | |
| right: number; | |
| top: number; | |
| bottom: number; | |
| height: number; | |
| }>({ left: 0, width: 0, right: 0, top: 0, bottom: 0, height: 0 }); |
This file contains hidden or 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
| React.useEffect(() => { | |
| if (getVisibleSelectionRect(window) !== null) { | |
| setSelectionRect(getVisibleSelectionRect(window)); | |
| } | |
| }, [editorState, setSelectionRect]); |
This file contains hidden or 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
| declare module "draft-js-plugins-utils" { | |
| import { EditorState, DraftEntityType, EntityInstance } from "draft-js"; | |
| function createLinkAtSelection( | |
| editorState: EditorState, | |
| url: string | |
| ): EditorState; | |
| function getCurrentEntityKey(editorState: EditorState): string | null; |
OlderNewer