Skip to content

Commit

Permalink
feat: show empty paragraph formatting in dev tool treeview
Browse files Browse the repository at this point in the history
  • Loading branch information
umaranis committed May 7, 2024
1 parent 53f8ebd commit 3dd164f
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
LexicalCommand,
LexicalEditor,
LexicalNode,
ParagraphNode,
RangeSelection,
TextNode,
} from 'lexical';
Expand All @@ -21,6 +22,7 @@
$isRangeSelection as isRangeSelection,
$isTextNode as isTextNode,
$isNodeSelection as isNodeSelection,
$isParagraphNode as isParagraphNode,
} from 'lexical';
import {
$isTableSelection as isTableSelection,
Expand Down Expand Up @@ -323,6 +325,9 @@
.filter(Boolean)
.join(' ')
.trim();
} else if (isParagraphNode(node)) {
const formatText = printTextFormatProperties(node);
return formatText !== '' ? `{ ${formatText} }` : '';
} else {
return '';
}
Expand All @@ -342,6 +347,17 @@
node.hasFormat('underline') && 'Underline',
];
const FORMAT_PREDICATES_PARAGRAPH = [
(node: ParagraphNode) => node.hasTextFormat('bold') && 'Bold',
(node: ParagraphNode) => node.hasTextFormat('code') && 'Code',
(node: ParagraphNode) => node.hasTextFormat('italic') && 'Italic',
(node: ParagraphNode) =>
node.hasTextFormat('strikethrough') && 'Strikethrough',
(node: ParagraphNode) => node.hasTextFormat('subscript') && 'Subscript',
(node: ParagraphNode) => node.hasTextFormat('superscript') && 'Superscript',
(node: ParagraphNode) => node.hasTextFormat('underline') && 'Underline',
];
const DETAIL_PREDICATES = [
(node: TextNode) => node.isDirectionless() && 'Directionless',
(node: TextNode) => node.isUnmergeable() && 'Unmergeable',
Expand Down Expand Up @@ -398,6 +414,21 @@
return str;
}
function printTextFormatProperties(nodeOrSelection: ParagraphNode) {
let str = FORMAT_PREDICATES_PARAGRAPH.map((predicate) =>
predicate(nodeOrSelection),
)
.filter(Boolean)
.join(', ')
.toLocaleLowerCase();
if (str !== '') {
str = 'format: ' + str;
}
return str;
}
function printFormatProperties(nodeOrSelection: TextNode | RangeSelection) {
let str = FORMAT_PREDICATES.map((predicate) => predicate(nodeOrSelection))
.filter(Boolean)
Expand Down

0 comments on commit 3dd164f

Please sign in to comment.