Skip to content

Commit

Permalink
Update lexical
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Sep 2, 2024
1 parent 85e0749 commit 1c6cc14
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 170 deletions.
20 changes: 10 additions & 10 deletions packages/content-editor-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@
"@salt-ds/lab": "1.0.0-alpha.50",
"@salt-ds/theme": "^1.19.0",
"@floating-ui/react": "^0.26.6",
"@lexical/code": "^0.11.1",
"@lexical/link": "^0.11.1",
"@lexical/list": "^0.11.1",
"@lexical/rich-text": "^0.11.1",
"@lexical/table": "^0.11.1",
"@lexical/react": "^0.11.1",
"@lexical/selection": "^0.11.1",
"@lexical/utils": "^0.11.1",
"@lexical/markdown": "^0.11.1",
"@lexical/code": "^0.17.1",
"@lexical/link": "^0.17.1",
"@lexical/list": "^0.17.1",
"@lexical/rich-text": "^0.17.1",
"@lexical/table": "^0.17.1",
"@lexical/react": "^0.17.1",
"@lexical/selection": "^0.17.1",
"@lexical/utils": "^0.17.1",
"@lexical/markdown": "^0.17.1",
"@vanilla-extract/css": "^1.6.0",
"clsx": "^2.0.0",
"gray-matter": "^4.0.3",
"lexical": "^0.11.1",
"lexical": "^0.17.1",
"react-split": "^2.0.14",
"lodash-es": "^4.17.21",
"md5": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';

const ContentEditor = () => (
<RichTextPlugin
Expand Down
2 changes: 2 additions & 0 deletions packages/content-editor-plugin/src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const Editor: FC<EditorProps> = ({
setFocused(false);
};

console.log(markdown);

return (
<LexicalComposer
initialConfig={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Dropdown, Option } from '@salt-ds/core';
import { $createCodeNode } from '@lexical/code';
import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND } from '@lexical/list';
import { $createHeadingNode, $createQuoteNode, HeadingTagType } from '@lexical/rich-text';
import { $wrapNodes } from '@lexical/selection';
import { $setBlocksType } from '@lexical/selection';
import { $createParagraphNode, $getSelection, $isRangeSelection, LexicalEditor } from 'lexical';

interface BlockSourceType {
Expand Down Expand Up @@ -44,7 +44,7 @@ export function InsertBlockDropdown({
const selection = $getSelection();

if ($isRangeSelection(selection)) {
$wrapNodes(selection, () => $createParagraphNode());
$setBlocksType(selection, () => $createParagraphNode());
}
});
}
Expand All @@ -56,7 +56,7 @@ export function InsertBlockDropdown({
const selection = $getSelection();

if ($isRangeSelection(selection)) {
$wrapNodes(selection, () => $createHeadingNode(item.type as HeadingTagType));
$setBlocksType(selection, () => $createHeadingNode(item.type as HeadingTagType));
}
});
}
Expand All @@ -80,7 +80,7 @@ export function InsertBlockDropdown({
const selection = $getSelection();

if ($isRangeSelection(selection)) {
$wrapNodes(selection, () => $createQuoteNode());
$setBlocksType(selection, () => $createQuoteNode());
}
});
}
Expand All @@ -93,7 +93,7 @@ export function InsertBlockDropdown({

if ($isRangeSelection(selection)) {
if (selection.isCollapsed()) {
$wrapNodes(selection, () => $createCodeNode());
$setBlocksType(selection, () => $createCodeNode());
} else {
const textContent = selection.getTextContent();
const codeNode = $createCodeNode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { $createLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { $wrapNodes } from '@lexical/selection';
import {
$createParagraphNode,
$createTextNode,
$getSelection,
$insertNodes,
$isRangeSelection,
$isTextNode,
COMMAND_PRIORITY_EDITOR,
Expand Down Expand Up @@ -40,7 +39,8 @@ function useMarkdownLinkPlugin() {
const linkTextNode = $createTextNode(text);
linkTextNode.setFormat(selection.focus.getNode().getFormat());
linkNode.append(linkTextNode);
$wrapNodes(selection, () => linkNode, $createParagraphNode());
$insertNodes([linkNode]);
linkNode.selectEnd();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
import { $getSelection, $isRangeSelection, LexicalEditor } from 'lexical';
import {
$deleteTableColumn,
$getElementGridForTableNode,
$getElementForTableNode,
$getTableCellNodeFromLexicalNode,
$getTableColumnIndexFromTableCellNode,
$getTableNodeFromLexicalNodeOrThrow,
Expand Down Expand Up @@ -115,7 +115,7 @@ function TableActionMenu({ editor, tableCellNode, onComplete }: TableActionMenuP
if ($isTableCellNode(tableCellNode)) {
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
const tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
const grid = $getElementGridForTableNode(editor, tableNode);
const grid = $getElementForTableNode(editor, tableNode);

$insertTableRow(tableNode, tableRowIndex, shouldInsertAfter, 1, grid);
}
Expand All @@ -132,7 +132,7 @@ function TableActionMenu({ editor, tableCellNode, onComplete }: TableActionMenuP
if ($isTableCellNode(tableCellNode)) {
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
const tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode);
const grid = $getElementGridForTableNode(editor, tableNode);
const grid = $getElementForTableNode(editor, tableNode);

$insertTableColumn(tableNode, tableColumnIndex, shouldInsertAfter, 1, grid);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/site-components/src/AppHeaderControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ActionMenuItem = {
};

function toUpperFirst(str) {
return `${str.substr(0, 1).toUpperCase()}${str.toLowerCase().substr(1)}`;
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
}

export const AppHeaderControls: React.FC = () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ export const AppHeaderControls: React.FC = () => {
{isLoggedIn ? (
<UserProfile
avatarUrl={session?.user?.image || ''}
firstName={toUpperFirst(session?.user?.name)}
firstName={toUpperFirst(session?.user?.name || '')}
prefixText="Welcome, "
/>
) : (
Expand Down
2 changes: 1 addition & 1 deletion packages/site-components/src/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Avatar } from '@salt-ds/core';
import styles from './styles.css';

function toUpperFirst(str) {
return `${str.substr(0, 1).toUpperCase()}${str.toLowerCase().substr(1)}`;
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
}

export function UserProfile({
Expand Down
Loading

0 comments on commit 1c6cc14

Please sign in to comment.