Skip to content

Commit

Permalink
fix: 🐛 fix rich text list nested list order
Browse files Browse the repository at this point in the history
  • Loading branch information
themashcodee committed Nov 23, 2024
1 parent 7c9d24c commit 897faf2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"repository": "https://github.com/themashcodee/slack-blocks-to-jsx.git",
"license": "MIT",
"version": "0.6.4",
"version": "0.6.5",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
34 changes: 27 additions & 7 deletions src/components/blocks/rich_text/rich_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,36 @@ type RichTextProps = {
export const RichText = (props: RichTextProps) => {
const { elements, block_id } = props.data;

let _consecutive_index: number = 0;
let _consecutive_index_map: Record<NonNullable<RichTextList["indent"]>, number> = {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0,
"7": 0,
"8": 0,
};

return (
<div id={block_id} className="slack_blocks_to_jsx__rich_text">
{elements.map((element, i) => {
let _local_index = 0;

if (element.type !== "rich_text_list") {
_consecutive_index = 0;
} else if (element.indent === 0) {
_local_index = _consecutive_index;
_consecutive_index += element.elements.length;
for (let i = 0; i <= 8; i++) {
_consecutive_index_map[i as NonNullable<RichTextList["indent"]>] = 0;
}
} else {
const indent = element.indent || 0;

for (let i = indent + 1; i <= 8; i++) {
_consecutive_index_map[i as NonNullable<RichTextList["indent"]>] = 0;
}

_local_index = _consecutive_index_map[indent];
_consecutive_index_map[indent] += element.elements.length;
}

return (
Expand Down Expand Up @@ -69,8 +87,10 @@ const Element = (props: ElementProps) => {
<span className="w-[22px] h-[22px] shrink-0 flex items-center justify-center">
{(indent === undefined || indent === 0 || indent === 3 || indent === 6) &&
`${consecutive_index + i + 1}.`}
{(indent === 1 || indent === 4 || indent === 7) && `${numberToAlpha(i + 1)}.`}
{(indent === 2 || indent === 5 || indent === 8) && `${numberToRoman(i + 1)}.`}
{(indent === 1 || indent === 4 || indent === 7) &&
`${numberToAlpha(consecutive_index + i + 1)}.`}
{(indent === 2 || indent === 5 || indent === 8) &&
`${numberToRoman(consecutive_index + i + 1)}.`}
</span>
)}

Expand Down

0 comments on commit 897faf2

Please sign in to comment.