From 897faf25cae35f59b1cc04921ef97007c06a348f Mon Sep 17 00:00:00 2001 From: themashcodee Date: Sat, 23 Nov 2024 13:34:39 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20rich=20text=20list?= =?UTF-8?q?=20nested=20list=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/blocks/rich_text/rich_text.tsx | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a35fe7c..fa1483e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/blocks/rich_text/rich_text.tsx b/src/components/blocks/rich_text/rich_text.tsx index 3f3741f..e4bb9e9 100644 --- a/src/components/blocks/rich_text/rich_text.tsx +++ b/src/components/blocks/rich_text/rich_text.tsx @@ -12,7 +12,17 @@ type RichTextProps = { export const RichText = (props: RichTextProps) => { const { elements, block_id } = props.data; - let _consecutive_index: number = 0; + let _consecutive_index_map: Record, number> = { + "0": 0, + "1": 0, + "2": 0, + "3": 0, + "4": 0, + "5": 0, + "6": 0, + "7": 0, + "8": 0, + }; return (
@@ -20,10 +30,18 @@ export const RichText = (props: RichTextProps) => { 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] = 0; + } + } else { + const indent = element.indent || 0; + + for (let i = indent + 1; i <= 8; i++) { + _consecutive_index_map[i as NonNullable] = 0; + } + + _local_index = _consecutive_index_map[indent]; + _consecutive_index_map[indent] += element.elements.length; } return ( @@ -69,8 +87,10 @@ const Element = (props: ElementProps) => { {(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)}.`} )}