-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lexical-playground] 3 Bug Fixes, 1 UX Improvement: All Regarding Excalidraw Node #6666
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08c4dd9
dont create node if discard
neysanfoo e24325c
don't add modal to undo stack
neysanfoo e8b0b63
decorator node has no exportJSON method
neysanfoo b39a1b2
add tag for close and delete
neysanfoo 92d883b
revert uhistory-merge tags
neysanfoo f6eb541
move modal into ui
neysanfoo 43c9e63
Merge branch 'main' into excalidraw_discard_bug
ivailop7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 0 additions & 55 deletions
55
packages/lexical-playground/src/plugins/ExcalidrawPlugin/index.ts
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
packages/lexical-playground/src/plugins/ExcalidrawPlugin/index.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,96 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
import type {ExcalidrawInitialElements} from '../../ui/ExcalidrawModal'; | ||
import type {AppState, BinaryFiles} from '@excalidraw/excalidraw/types/types'; | ||
|
||
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; | ||
import {$wrapNodeInElement} from '@lexical/utils'; | ||
import { | ||
$createParagraphNode, | ||
$insertNodes, | ||
$isRootOrShadowRoot, | ||
COMMAND_PRIORITY_EDITOR, | ||
createCommand, | ||
LexicalCommand, | ||
} from 'lexical'; | ||
import {useEffect, useState} from 'react'; | ||
|
||
import { | ||
$createExcalidrawNode, | ||
ExcalidrawNode, | ||
} from '../../nodes/ExcalidrawNode'; | ||
import ExcalidrawModal from '../../ui/ExcalidrawModal'; | ||
|
||
export const INSERT_EXCALIDRAW_COMMAND: LexicalCommand<void> = createCommand( | ||
'INSERT_EXCALIDRAW_COMMAND', | ||
); | ||
|
||
export default function ExcalidrawPlugin(): JSX.Element | null { | ||
const [editor] = useLexicalComposerContext(); | ||
const [isModalOpen, setModalOpen] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (!editor.hasNodes([ExcalidrawNode])) { | ||
throw new Error( | ||
'ExcalidrawPlugin: ExcalidrawNode not registered on editor', | ||
); | ||
} | ||
|
||
return editor.registerCommand( | ||
INSERT_EXCALIDRAW_COMMAND, | ||
() => { | ||
setModalOpen(true); | ||
return true; | ||
}, | ||
COMMAND_PRIORITY_EDITOR, | ||
); | ||
}, [editor]); | ||
|
||
const onClose = () => { | ||
setModalOpen(false); | ||
}; | ||
|
||
const onDelete = () => { | ||
setModalOpen(false); | ||
}; | ||
|
||
const onSave = ( | ||
elements: ExcalidrawInitialElements, | ||
appState: Partial<AppState>, | ||
files: BinaryFiles, | ||
) => { | ||
editor.update(() => { | ||
const excalidrawNode = $createExcalidrawNode(); | ||
excalidrawNode.setData( | ||
JSON.stringify({ | ||
appState, | ||
elements, | ||
files, | ||
}), | ||
); | ||
$insertNodes([excalidrawNode]); | ||
if ($isRootOrShadowRoot(excalidrawNode.getParentOrThrow())) { | ||
$wrapNodeInElement(excalidrawNode, $createParagraphNode).selectEnd(); | ||
} | ||
}); | ||
setModalOpen(false); | ||
}; | ||
|
||
return isModalOpen ? ( | ||
<ExcalidrawModal | ||
initialElements={[]} | ||
initialAppState={{} as AppState} | ||
initialFiles={{}} | ||
isShown={isModalOpen} | ||
onDelete={onDelete} | ||
onClose={onClose} | ||
onSave={onSave} | ||
closeOnClickOutside={false} | ||
/> | ||
) : null; | ||
} |
File renamed without changes.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!