Skip to content

Commit

Permalink
feat : update variable names in different turnIntoDropdownMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarajay0412 committed Jun 8, 2024
1 parent 6294793 commit 0c988fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,24 @@ const defaultItem = items.find((item) => item.value === ELEMENT_PARAGRAPH)!;

export function PlaygroundTurnIntoDropdownMenu(props: DropdownMenuProps) {
const value: string = useEditorSelector((editor) => {
let firstNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchFirstNode = false;
let initialNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchInitialNodeType = false;
const codeBlockEntries = getNodeEntries(editor, {
match: (n) => isBlock(editor, n),
mode: 'highest',
});
const nodes = Array.from(codeBlockEntries);

if (nodes.length > 0) {
firstNodeType = nodes[0][0].type as string;
allNodesMatchFirstNode = nodes.every(([node]) => {
initialNodeType = nodes[0][0].type as string;
allNodesMatchInitialNodeType = nodes.every(([node]) => {
const type: string = (node?.type as string) || ELEMENT_PARAGRAPH;

return type === firstNodeType;
return type === initialNodeType;
});
}

return allNodesMatchFirstNode ? firstNodeType : ELEMENT_PARAGRAPH;
return allNodesMatchInitialNodeType ? initialNodeType : ELEMENT_PARAGRAPH;
}, []);

const editor = useEditorRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ const defaultItem = items.find((item) => item.value === ELEMENT_PARAGRAPH)!;

export function TurnIntoDropdownMenu(props: DropdownMenuProps) {
const value: string = useEditorSelector((editor) => {
let firstNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchFirstNode = false;
let initialNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchInitialNodeType = false;
const codeBlockEntries = getNodeEntries(editor, {
match: (n) => isBlock(editor, n),
mode: 'highest',
});
const nodes = Array.from(codeBlockEntries);

if (nodes.length > 0) {
firstNodeType = nodes[0][0].type as string;
allNodesMatchFirstNode = nodes.every(([node]) => {
initialNodeType = nodes[0][0].type as string;
allNodesMatchInitialNodeType = nodes.every(([node]) => {
const type: string = (node?.type as string) || ELEMENT_PARAGRAPH;

return type === firstNodeType;
return type === initialNodeType;
});
}

return allNodesMatchFirstNode ? firstNodeType : ELEMENT_PARAGRAPH;
return allNodesMatchInitialNodeType ? initialNodeType : ELEMENT_PARAGRAPH;
}, []);

const editor = useEditorRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,24 @@ const defaultItem = items.find((item) => item.value === ELEMENT_PARAGRAPH)!;

export function TurnIntoDropdownMenu(props: DropdownMenuProps) {
const value: string = useEditorSelector((editor) => {
let firstNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchFirstNode = false;
let initialNodeType: string = ELEMENT_PARAGRAPH;
let allNodesMatchInitialNodeType = false;
const codeBlockEntries = getNodeEntries(editor, {
match: (n) => isBlock(editor, n),
mode: 'highest',
});
const nodes = Array.from(codeBlockEntries);

if (nodes.length > 0) {
firstNodeType = nodes[0][0].type as string;
allNodesMatchFirstNode = nodes.every(([node]) => {
initialNodeType = nodes[0][0].type as string;
allNodesMatchInitialNodeType = nodes.every(([node]) => {
const type: string = (node?.type as string) || ELEMENT_PARAGRAPH;

return type === firstNodeType;
return type === initialNodeType;
});
}

return allNodesMatchFirstNode ? firstNodeType : ELEMENT_PARAGRAPH;
return allNodesMatchInitialNodeType ? initialNodeType : ELEMENT_PARAGRAPH;
}, []);

const editor = useEditorRef();
Expand Down

0 comments on commit 0c988fb

Please sign in to comment.