-
Notifications
You must be signed in to change notification settings - Fork 30
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 editor integration #2940
Open
kukollu
wants to merge
8
commits into
Codecademy:main
Choose a base branch
from
kukollu:lexical-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10aa9ca
lexical editor integration
kukollu 45fd00a
lexical editor changes
kukollu 8da314f
lexical editor changes
kukollu ccb6373
lexical editor changes
kukollu 2ab5c1b
lexical editor changes
kukollu d1759dd
ignore lint error
kukollu c5dd130
fix package.json
dreamwasp 935fdfc
changes lexical editor to run
kukollu 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,21 @@ | |
"version": "57.2.2", | ||
"author": "Codecademy Engineering <[email protected]>", | ||
"dependencies": { | ||
"@lexical/clipboard": "0.16.0", | ||
"@lexical/code": "0.16.0", | ||
"@lexical/file": "0.16.0", | ||
"@lexical/hashtag": "0.16.0", | ||
"@lexical/link": "0.16.0", | ||
"@lexical/list": "0.16.0", | ||
"@lexical/mark": "0.16.0", | ||
"@lexical/overflow": "0.16.0", | ||
"@lexical/plain-text": "0.16.0", | ||
"@lexical/react": "0.16.0", | ||
"@lexical/rich-text": "0.16.0", | ||
"@lexical/selection": "0.16.0", | ||
"@lexical/table": "0.16.0", | ||
"@lexical/utils": "0.16.0", | ||
"lexical": "0.16.0", | ||
"@codecademy/gamut-icons": "9.31.0", | ||
"@codecademy/gamut-illustrations": "0.48.0", | ||
"@codecademy/gamut-patterns": "0.9.14", | ||
|
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,218 @@ | ||
/** | ||
* 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 {AutoFocusPlugin} from '@lexical/react/LexicalAutoFocusPlugin'; | ||
import {CharacterLimitPlugin} from '@lexical/react/LexicalCharacterLimitPlugin'; | ||
import {CheckListPlugin} from '@lexical/react/LexicalCheckListPlugin'; | ||
import {ClearEditorPlugin} from '@lexical/react/LexicalClearEditorPlugin'; | ||
import {ClickableLinkPlugin} from '@lexical/react/LexicalClickableLinkPlugin'; | ||
// import {CollaborationPlugin} from '@lexical/react/LexicalCollaborationPlugin'; | ||
import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary'; | ||
import {HashtagPlugin} from '@lexical/react/LexicalHashtagPlugin'; | ||
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin'; | ||
import {HorizontalRulePlugin} from '@lexical/react/LexicalHorizontalRulePlugin'; | ||
import {ListPlugin} from '@lexical/react/LexicalListPlugin'; | ||
import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin'; | ||
import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin'; | ||
import {TabIndentationPlugin} from '@lexical/react/LexicalTabIndentationPlugin'; | ||
import {TablePlugin} from '@lexical/react/LexicalTablePlugin'; | ||
import {useLexicalEditable} from '@lexical/react/useLexicalEditable'; | ||
import * as React from 'react'; | ||
import {useEffect, useState} from 'react'; | ||
// import {CAN_USE_DOM} from './shared/canUseDOM'; | ||
|
||
// import {createWebsocketProvider} from './collaboration'; | ||
import {useSettings} from './context/SettingsContext'; | ||
import {useSharedHistoryContext} from './context/SharedHistoryContext'; | ||
// import ActionsPlugin from './plugins/ActionsPlugin'; | ||
import AutocompletePlugin from './plugins/AutocompletePlugin'; | ||
// import AutoEmbedPlugin from './plugins/AutoEmbedPlugin'; | ||
import AutoLinkPlugin from './plugins/AutoLinkPlugin'; | ||
// import CodeActionMenuPlugin from './plugins/CodeActionMenuPlugin'; | ||
import CodeHighlightPlugin from './plugins/CodeHighlightPlugin'; | ||
import ComponentPickerPlugin from './plugins/ComponentPickerPlugin'; | ||
import ContextMenuPlugin from './plugins/ContextMenuPlugin'; | ||
import FloatingLinkEditorPlugin from './plugins/FloatingLinkEditorPlugin'; | ||
import FloatingTextFormatToolbarPlugin from './plugins/FloatingTextFormatToolbarPlugin'; | ||
import ImagesPlugin from './plugins/ImagesPlugin'; | ||
import KeywordsPlugin from './plugins/KeywordsPlugin'; | ||
import {LayoutPlugin} from './plugins/LayoutPlugin/LayoutPlugin'; | ||
import LinkPlugin from './plugins/LinkPlugin'; | ||
import ListMaxIndentLevelPlugin from './plugins/ListMaxIndentLevelPlugin'; | ||
import MarkdownShortcutPlugin from './plugins/MarkdownShortcutPlugin'; | ||
import {MaxLengthPlugin} from './plugins/MaxLengthPlugin'; | ||
import MentionsPlugin from './plugins/MentionsPlugin'; | ||
import TabFocusPlugin from './plugins/TabFocusPlugin'; | ||
import TableCellActionMenuPlugin from './plugins/TableActionMenuPlugin'; | ||
import TableCellResizer from './plugins/TableCellResizer'; | ||
import TableOfContentsPlugin from './plugins/TableOfContentsPlugin'; | ||
import ToolbarPlugin from './plugins/ToolbarPlugin'; | ||
import TreeViewPlugin from './plugins/TreeViewPlugin'; | ||
import ContentEditable from './ui/ContentEditable'; | ||
import Placeholder from './ui/Placeholder'; | ||
|
||
const skipCollaborationInit = | ||
// @ts-expect-error | ||
window.parent != null && window.parent.frames.right === window; | ||
|
||
export default function Editor(): JSX.Element { | ||
const {historyState} = useSharedHistoryContext(); | ||
const { | ||
settings: { | ||
isCollab, | ||
isAutocomplete, | ||
isMaxLength, | ||
isCharLimit, | ||
isCharLimitUtf8, | ||
isRichText, | ||
showTreeView, | ||
showTableOfContents, | ||
shouldUseLexicalContextMenu, | ||
shouldPreserveNewLinesInMarkdown, | ||
tableCellMerge, | ||
tableCellBackgroundColor, | ||
}, | ||
} = useSettings(); | ||
const isEditable = useLexicalEditable(); | ||
const text = isCollab | ||
? 'Enter some collaborative rich text...' | ||
: isRichText | ||
? 'Enter some rich text...' | ||
: 'Enter some plain text...'; | ||
const placeholder = <Placeholder>{text}</Placeholder>; | ||
const [floatingAnchorElem, setFloatingAnchorElem] = | ||
useState<HTMLDivElement | null>(null); | ||
const [isSmallWidthViewport, setIsSmallWidthViewport] = | ||
useState<boolean>(false); | ||
const [isLinkEditMode, setIsLinkEditMode] = useState<boolean>(false); | ||
|
||
const onRef = (_floatingAnchorElem: HTMLDivElement) => { | ||
if (_floatingAnchorElem !== null) { | ||
setFloatingAnchorElem(_floatingAnchorElem); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const updateViewPortWidth = () => { | ||
// const isNextSmallWidthViewport = | ||
// CAN_USE_DOM && window.matchMedia('(max-width: 1025px)').matches; | ||
|
||
// if (isNextSmallWidthViewport !== isSmallWidthViewport) { | ||
// setIsSmallWidthViewport(isNextSmallWidthViewport); | ||
// } | ||
}; | ||
updateViewPortWidth(); | ||
window.addEventListener('resize', updateViewPortWidth); | ||
|
||
return () => { | ||
window.removeEventListener('resize', updateViewPortWidth); | ||
}; | ||
}, [isSmallWidthViewport]); | ||
|
||
return ( | ||
<> | ||
{isRichText && <ToolbarPlugin setIsLinkEditMode={setIsLinkEditMode} />} | ||
<div | ||
className={`editor-container ${showTreeView ? 'tree-view' : ''} ${ | ||
!isRichText ? 'plain-text' : '' | ||
}`}> | ||
{isMaxLength && <MaxLengthPlugin maxLength={30} />} | ||
<AutoFocusPlugin /> | ||
<ClearEditorPlugin /> | ||
<ComponentPickerPlugin /> | ||
{/* <AutoEmbedPlugin /> */} | ||
|
||
<MentionsPlugin /> | ||
<HashtagPlugin /> | ||
<KeywordsPlugin /> | ||
<AutoLinkPlugin /> | ||
{isRichText ? ( | ||
<> | ||
{/* {isCollab ? ( | ||
// <CollaborationPlugin | ||
// id="main" | ||
// providerFactory={createWebsocketProvider} | ||
// shouldBootstrap={!skipCollaborationInit} | ||
// /> | ||
) : ( | ||
<HistoryPlugin externalHistoryState={historyState} /> | ||
)} */} | ||
<RichTextPlugin | ||
contentEditable={ | ||
<div className="editor-scroller"> | ||
<div className="editor" ref={onRef}> | ||
<ContentEditable /> | ||
</div> | ||
</div> | ||
} | ||
placeholder={placeholder} | ||
ErrorBoundary={LexicalErrorBoundary} | ||
/> | ||
<MarkdownShortcutPlugin /> | ||
<CodeHighlightPlugin /> | ||
<ListPlugin /> | ||
<CheckListPlugin /> | ||
<ListMaxIndentLevelPlugin maxDepth={7} /> | ||
<TablePlugin | ||
hasCellMerge={tableCellMerge} | ||
hasCellBackgroundColor={tableCellBackgroundColor} | ||
/> | ||
<TableCellResizer /> | ||
<LinkPlugin /> | ||
<ClickableLinkPlugin disabled={isEditable} /> | ||
<HorizontalRulePlugin /> | ||
<TabFocusPlugin /> | ||
<TabIndentationPlugin /> | ||
<LayoutPlugin /> | ||
{floatingAnchorElem && !isSmallWidthViewport && ( | ||
<> | ||
{/* <CodeActionMenuPlugin anchorElem={floatingAnchorElem} /> */} | ||
<FloatingLinkEditorPlugin | ||
anchorElem={floatingAnchorElem} | ||
isLinkEditMode={isLinkEditMode} | ||
setIsLinkEditMode={setIsLinkEditMode} | ||
/> | ||
<TableCellActionMenuPlugin | ||
anchorElem={floatingAnchorElem} | ||
cellMerge={true} | ||
/> | ||
<FloatingTextFormatToolbarPlugin | ||
anchorElem={floatingAnchorElem} | ||
setIsLinkEditMode={setIsLinkEditMode} | ||
/> | ||
</> | ||
)} | ||
</> | ||
) : ( | ||
<> | ||
<PlainTextPlugin | ||
contentEditable={<ContentEditable />} | ||
placeholder={placeholder} | ||
ErrorBoundary={LexicalErrorBoundary} | ||
/> | ||
<HistoryPlugin externalHistoryState={historyState} /> | ||
</> | ||
)} | ||
{(isCharLimit || isCharLimitUtf8) && ( | ||
<CharacterLimitPlugin | ||
charset={isCharLimit ? 'UTF-16' : 'UTF-8'} | ||
maxLength={5} | ||
/> | ||
)} | ||
{isAutocomplete && <AutocompletePlugin />} | ||
<div>{showTableOfContents && <TableOfContentsPlugin />}</div> | ||
{shouldUseLexicalContextMenu && <ContextMenuPlugin />} | ||
{/* <ActionsPlugin | ||
isRichText={isRichText} | ||
shouldPreserveNewLinesInMarkdown={shouldPreserveNewLinesInMarkdown} | ||
/> */} | ||
</div> | ||
{showTreeView && <TreeViewPlugin />} | ||
</> | ||
); | ||
} |
Oops, something went wrong.
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.
gamut-kit is what is produced by these packages, so shouldn't be a dependency here