From ceede9f7e22bf20d95c8d51f1e297d5bb5d2f07d Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 31 Mar 2024 19:40:33 +0100 Subject: [PATCH 1/3] Update version to 1.0.0-rc03 --- README.md | 2 +- convention-plugins/src/main/kotlin/root.publication.gradle.kts | 2 +- docs/index.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db9f2c99..4da30187 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ A rich text editor library for both Jetpack Compose and Compose Multiplatform, f Compose Rich Editor is available on `mavenCentral()`. ```kotlin -implementation("com.mohamedrejeb.richeditor:richeditor-compose:1.0.0-rc01") +implementation("com.mohamedrejeb.richeditor:richeditor-compose:1.0.0-rc03") ``` ## Quick Start diff --git a/convention-plugins/src/main/kotlin/root.publication.gradle.kts b/convention-plugins/src/main/kotlin/root.publication.gradle.kts index 7550d3ca..33d2e05c 100644 --- a/convention-plugins/src/main/kotlin/root.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/root.publication.gradle.kts @@ -4,7 +4,7 @@ plugins { allprojects { group = "com.mohamedrejeb.richeditor" - version = System.getenv("VERSION") ?: "1.0.0-rc02" + version = System.getenv("VERSION") ?: "1.0.0-rc03" } nexusPublishing { diff --git a/docs/index.md b/docs/index.md index ab370add..558adfd6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,7 +18,7 @@ A rich text editor library for both Jetpack Compose and Compose Multiplatform, f Compose Rich Editor is available on `mavenCentral()`. ```kotlin -implementation("com.mohamedrejeb.richeditor:richeditor-compose:1.0.0-rc01") +implementation("com.mohamedrejeb.richeditor:richeditor-compose:1.0.0-rc03") ``` ## Quick Start From 896e90c93ecdca0c063577eaaf01d62abe37aa2c Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 31 Mar 2024 19:54:37 +0100 Subject: [PATCH 2/3] Fix warnings --- .../richeditor/paragraph/RichParagraph.kt | 3 +++ .../paragraph/type/DefaultParagraph.kt | 2 ++ .../richeditor/paragraph/type/OrderedList.kt | 2 ++ .../richeditor/paragraph/type/UnorderedList.kt | 3 ++- .../parser/html/RichTextStateHtmlParser.kt | 5 +++++ .../markdown/RichTextStateMarkdownParser.kt | 7 ++++++- .../richeditor/ui/RichTextClipboardManager.kt | 2 ++ .../richeditor/ui/test/DebugRichTextEditor.kt | 4 ++-- .../model/RichParagraphStyleTest.kt | 2 ++ .../model/RichSpanStyleTest.kt | 2 ++ .../sample/common/components/RichTextStyleRow.kt | 11 ++++++++--- .../common/htmleditor/HtmlEditorContent.kt | 6 ++---- .../sample/common/htmleditor/HtmlToRichText.kt | 2 +- .../sample/common/htmleditor/RichTextToHtml.kt | 2 +- .../markdowneditor/MarkdownEditorContent.kt | 7 +++---- .../common/markdowneditor/MarkdownToRichText.kt | 2 +- .../common/markdowneditor/RichTextToMarkdown.kt | 2 +- .../common/richeditor/RichEditorContent.kt | 16 +++++++--------- .../sample/common/richeditor/SpellCheckSpan.kt | 4 ++-- .../sample/common/slack/SlackDemoPanel.kt | 9 ++++++--- 20 files changed, 60 insertions(+), 33 deletions(-) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/RichParagraph.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/RichParagraph.kt index 7ee74f6b..87f11056 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/RichParagraph.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/RichParagraph.kt @@ -2,6 +2,7 @@ package com.mohamedrejeb.richeditor.paragraph import androidx.compose.ui.text.ParagraphStyle import androidx.compose.ui.text.TextRange +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichSpan import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph import com.mohamedrejeb.richeditor.paragraph.type.ParagraphType @@ -17,6 +18,7 @@ internal class RichParagraph( var type: ParagraphType = DefaultParagraph(), ) { + @OptIn(ExperimentalRichTextApi::class) fun getRichSpanByTextIndex( paragraphIndex: Int, textIndex: Int, @@ -60,6 +62,7 @@ internal class RichParagraph( return index to null } + @OptIn(ExperimentalRichTextApi::class) fun getRichSpanListByTextRange( paragraphIndex: Int, searchTextRange: TextRange, diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/DefaultParagraph.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/DefaultParagraph.kt index 7e5256c2..4dbce3e5 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/DefaultParagraph.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/DefaultParagraph.kt @@ -1,6 +1,7 @@ package com.mohamedrejeb.richeditor.paragraph.type import androidx.compose.ui.text.ParagraphStyle +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichSpan import com.mohamedrejeb.richeditor.paragraph.RichParagraph @@ -8,6 +9,7 @@ internal class DefaultParagraph : ParagraphType { override val style: ParagraphStyle = ParagraphStyle() + @OptIn(ExperimentalRichTextApi::class) override val startRichSpan: RichSpan = RichSpan(paragraph = RichParagraph(type = this)) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/OrderedList.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/OrderedList.kt index a3d6025d..fc1e721c 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/OrderedList.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/OrderedList.kt @@ -5,6 +5,7 @@ import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.style.TextIndent import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.sp +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichSpan import com.mohamedrejeb.richeditor.paragraph.RichParagraph @@ -46,6 +47,7 @@ internal class OrderedList( override var startRichSpan: RichSpan = getNewStartRichSpan() + @OptIn(ExperimentalRichTextApi::class) private fun getNewStartRichSpan() = RichSpan( paragraph = RichParagraph(type = this), diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/UnorderedList.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/UnorderedList.kt index 6b1fa28d..e6188275 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/UnorderedList.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/type/UnorderedList.kt @@ -2,8 +2,8 @@ package com.mohamedrejeb.richeditor.paragraph.type import androidx.compose.ui.text.ParagraphStyle import androidx.compose.ui.text.style.TextIndent -import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.sp +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichSpan import com.mohamedrejeb.richeditor.paragraph.RichParagraph @@ -20,6 +20,7 @@ internal class UnorderedList : ParagraphType { ) ) + @OptIn(ExperimentalRichTextApi::class) override var startRichSpan: RichSpan = RichSpan( paragraph = RichParagraph(type = this), diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt index f5a2fbe6..b977fa82 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/html/RichTextStateHtmlParser.kt @@ -4,6 +4,7 @@ import androidx.compose.ui.text.SpanStyle import com.mohamedrejeb.ksoup.entities.KsoupEntities import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlHandler import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlParser +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.* import com.mohamedrejeb.richeditor.paragraph.RichParagraph import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph @@ -18,6 +19,7 @@ import com.mohamedrejeb.richeditor.utils.fastForEachIndexed internal object RichTextStateHtmlParser : RichTextStateParser { + @OptIn(ExperimentalRichTextApi::class) override fun encode(input: String): RichTextState { val openedTags = mutableListOf>>() val stringBuilder = StringBuilder() @@ -238,6 +240,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser { return builder.toString() } + @OptIn(ExperimentalRichTextApi::class) private fun decodeRichSpanToHtml(richSpan: RichSpan, parentFormattingTags: List = emptyList()): String { val stringBuilder = StringBuilder() @@ -353,6 +356,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser { /** * Encodes HTML elements to [RichSpanStyle]. */ + @OptIn(ExperimentalRichTextApi::class) private fun encodeHtmlElementToRichSpanStyle( tagName: String, attributes: Map, @@ -369,6 +373,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser { /** * Decodes HTML elements from [RichSpanStyle]. */ + @OptIn(ExperimentalRichTextApi::class) private fun decodeHtmlElementFromRichSpanStyle( richSpanStyle: RichSpanStyle, ): Pair> = diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/markdown/RichTextStateMarkdownParser.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/markdown/RichTextStateMarkdownParser.kt index 233001b6..df8925a5 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/markdown/RichTextStateMarkdownParser.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/markdown/RichTextStateMarkdownParser.kt @@ -3,6 +3,7 @@ package com.mohamedrejeb.richeditor.parser.markdown import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.style.TextDecoration +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.* import com.mohamedrejeb.richeditor.paragraph.RichParagraph import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph @@ -22,6 +23,7 @@ import org.intellij.markdown.flavours.gfm.GFMElementTypes internal object RichTextStateMarkdownParser : RichTextStateParser { + @OptIn(ExperimentalRichTextApi::class) override fun encode(input: String): RichTextState { val openedNodes = mutableListOf() val stringBuilder = StringBuilder() @@ -149,7 +151,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser { currentRichSpan = currentRichSpan?.parent }, - onHtml = { html -> + onHtml = { _ -> // Todo: support HTML in markdown } ) @@ -187,6 +189,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser { return builder.toString() } + @OptIn(ExperimentalRichTextApi::class) private fun decodeRichSpanToMarkdown(richSpan: RichSpan): String { val stringBuilder = StringBuilder() @@ -239,6 +242,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser { /** * Encodes Markdown elements to [RichSpanStyle]. */ + @OptIn(ExperimentalRichTextApi::class) private fun encodeMarkdownElementToRichSpanStyle( node: ASTNode, markdown: String, @@ -269,6 +273,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser { /** * Decodes HTML elements from [RichSpan]. */ + @OptIn(ExperimentalRichTextApi::class) private fun decodeMarkdownElementFromRichSpan( text: String, richSpanStyle: RichSpanStyle, diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/RichTextClipboardManager.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/RichTextClipboardManager.kt index 8d77b6ce..37618b55 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/RichTextClipboardManager.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/RichTextClipboardManager.kt @@ -4,6 +4,7 @@ import androidx.compose.ui.platform.ClipboardManager import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.withStyle +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichSpanStyle import com.mohamedrejeb.richeditor.model.RichTextState import com.mohamedrejeb.richeditor.paragraph.type.ParagraphType.Companion.startText @@ -27,6 +28,7 @@ internal class RichTextClipboardManager( return clipboardManager.getText() } + @OptIn(ExperimentalRichTextApi::class) override fun setText(annotatedString: AnnotatedString) { val selection = richTextState.selection val richTextAnnotatedString = buildAnnotatedString { diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/test/DebugRichTextEditor.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/test/DebugRichTextEditor.kt index 1eeda332..613dd0c7 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/test/DebugRichTextEditor.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/test/DebugRichTextEditor.kt @@ -43,7 +43,7 @@ internal fun DebugRichTextEditor( .padding(8.dp), ) - Divider(modifier = Modifier.padding(vertical = 20.dp)) + HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp)) Text( text = "Annotation Length: ${richTextState.annotatedString.text.length}", @@ -83,7 +83,7 @@ internal fun DebugRichTextEditor( RichTextStyleTreeRepresentation(childIndex, richTextStyle, " -") } - Divider(modifier = Modifier.padding(vertical = 20.dp)) + HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp)) } } } diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichParagraphStyleTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichParagraphStyleTest.kt index ed85c15c..4667d2d7 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichParagraphStyleTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichParagraphStyleTest.kt @@ -2,12 +2,14 @@ package com.mohamedrejeb.richeditor.model import androidx.compose.runtime.mutableStateListOf import androidx.compose.ui.text.TextRange +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.paragraph.RichParagraph import kotlin.test.Test import kotlin.test.assertEquals class RichParagraphStyleTest { private val paragraph = RichParagraph(key = 0) + @OptIn(ExperimentalRichTextApi::class) private val richSpanLists get() = listOf( RichSpan( key = 0, diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichSpanStyleTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichSpanStyleTest.kt index 8407e7e3..4d1856ac 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichSpanStyleTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichSpanStyleTest.kt @@ -1,12 +1,14 @@ package com.mohamedrejeb.richeditor.model import androidx.compose.ui.text.TextRange +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.paragraph.RichParagraph import kotlin.test.Test import kotlin.test.assertEquals class RichSpanTest { private val paragraph = RichParagraph(key = 0) + @OptIn(ExperimentalRichTextApi::class) private val richSpan get() = RichSpan( key = 0, paragraph = paragraph, diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/components/RichTextStyleRow.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/components/RichTextStyleRow.kt index 523b96f7..13561e4b 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/components/RichTextStyleRow.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/components/RichTextStyleRow.kt @@ -6,6 +6,9 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyRow import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.outlined.FormatAlignLeft +import androidx.compose.material.icons.automirrored.outlined.FormatAlignRight +import androidx.compose.material.icons.automirrored.outlined.FormatListBulleted import androidx.compose.material.icons.filled.Circle import androidx.compose.material.icons.outlined.* import androidx.compose.runtime.Composable @@ -20,9 +23,11 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichTextState import com.mohamedrejeb.richeditor.sample.common.richeditor.SpellCheck +@OptIn(ExperimentalRichTextApi::class) @Composable fun RichTextStyleRow( modifier: Modifier = Modifier, @@ -42,7 +47,7 @@ fun RichTextStyleRow( ) }, isSelected = state.currentParagraphStyle.textAlign == TextAlign.Left, - icon = Icons.Outlined.FormatAlignLeft + icon = Icons.AutoMirrored.Outlined.FormatAlignLeft ) } @@ -70,7 +75,7 @@ fun RichTextStyleRow( ) }, isSelected = state.currentParagraphStyle.textAlign == TextAlign.Right, - icon = Icons.Outlined.FormatAlignRight + icon = Icons.AutoMirrored.Outlined.FormatAlignRight ) } @@ -189,7 +194,7 @@ fun RichTextStyleRow( state.toggleUnorderedList() }, isSelected = state.isUnorderedList, - icon = Icons.Outlined.FormatListBulleted, + icon = Icons.AutoMirrored.Outlined.FormatListBulleted, ) } diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlEditorContent.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlEditorContent.kt index 304f330a..8ad96751 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlEditorContent.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlEditorContent.kt @@ -2,16 +2,14 @@ package com.mohamedrejeb.richeditor.sample.common.htmleditor import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.SwapHoriz import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.TextFieldValue import cafe.adriel.voyager.navigator.LocalNavigator -import cafe.adriel.voyager.navigator.currentOrThrow import com.mohamedrejeb.richeditor.model.rememberRichTextState -import com.mohamedrejeb.richeditor.sample.common.ui.theme.ComposeRichEditorTheme @OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable @@ -39,7 +37,7 @@ fun HtmlEditorContent() { IconButton( onClick = { navigator?.pop() } ) { - Icon(Icons.Default.ArrowBack, contentDescription = "Back") + Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } }, actions = { diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlToRichText.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlToRichText.kt index d0ef36c9..afa9751c 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlToRichText.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/HtmlToRichText.kt @@ -52,7 +52,7 @@ fun HtmlToRichText( Spacer(Modifier.width(8.dp)) - Divider( + HorizontalDivider( modifier = Modifier .fillMaxHeight() .width(2.dp) diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/RichTextToHtml.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/RichTextToHtml.kt index cd1c8e92..42bdb490 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/RichTextToHtml.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/htmleditor/RichTextToHtml.kt @@ -55,7 +55,7 @@ fun RichTextToHtml( Spacer(Modifier.width(8.dp)) - Divider( + HorizontalDivider( modifier = Modifier .fillMaxHeight() .width(2.dp) diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownEditorContent.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownEditorContent.kt index 337df462..948e0e94 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownEditorContent.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownEditorContent.kt @@ -2,7 +2,7 @@ package com.mohamedrejeb.richeditor.sample.common.markdowneditor import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.SwapHoriz import androidx.compose.material3.* import androidx.compose.runtime.* @@ -11,9 +11,8 @@ import androidx.compose.ui.text.input.TextFieldValue import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import com.mohamedrejeb.richeditor.model.rememberRichTextState -import com.mohamedrejeb.richeditor.sample.common.ui.theme.ComposeRichEditorTheme -@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) +@OptIn(ExperimentalMaterial3Api::class) @Composable fun MarkdownEditorContent() { val navigator = LocalNavigator.currentOrThrow @@ -39,7 +38,7 @@ fun MarkdownEditorContent() { IconButton( onClick = { navigator.pop() } ) { - Icon(Icons.Default.ArrowBack, contentDescription = "Back") + Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } }, actions = { diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownToRichText.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownToRichText.kt index 9d20af67..283aa77b 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownToRichText.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/MarkdownToRichText.kt @@ -53,7 +53,7 @@ fun MarkdownToRichText( Spacer(Modifier.width(8.dp)) - Divider( + HorizontalDivider( modifier = Modifier .fillMaxHeight() .width(2.dp) diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/RichTextToMarkdown.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/RichTextToMarkdown.kt index 84b98d8d..f9d7d375 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/RichTextToMarkdown.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/markdowneditor/RichTextToMarkdown.kt @@ -55,7 +55,7 @@ fun RichTextToMarkdown( Spacer(Modifier.width(8.dp)) - Divider( + HorizontalDivider( modifier = Modifier .fillMaxHeight() .width(2.dp) diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt index 16357646..4bf028eb 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt @@ -2,14 +2,12 @@ package com.mohamedrejeb.richeditor.sample.common.richeditor import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.* -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Modifier -import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow @@ -47,7 +45,7 @@ fun RichEditorContent() { IconButton( onClick = { navigator.pop() } ) { - Icon(Icons.Default.ArrowBack, contentDescription = "Back") + Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") } } ) @@ -90,7 +88,7 @@ fun RichEditorContent() { } item { - Divider(modifier = Modifier.padding(vertical = 20.dp)) + HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp)) } // RichTextEditor @@ -121,7 +119,7 @@ fun RichEditorContent() { } item { - Divider(modifier = Modifier.padding(vertical = 20.dp)) + HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp)) } // OutlinedRichTextEditor @@ -151,7 +149,7 @@ fun RichEditorContent() { } item { - Divider(modifier = Modifier.padding(vertical = 20.dp)) + HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp)) } // RichText diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/SpellCheckSpan.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/SpellCheckSpan.kt index adf1e8d6..c8a1c048 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/SpellCheckSpan.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/SpellCheckSpan.kt @@ -8,10 +8,10 @@ import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.text.TextRange import androidx.compose.ui.unit.dp +import androidx.compose.ui.util.fastForEach import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi import com.mohamedrejeb.richeditor.model.RichSpanStyle import com.mohamedrejeb.richeditor.model.RichTextConfig -import com.mohamedrejeb.richeditor.utils.fastForEachIndexed import com.mohamedrejeb.richeditor.utils.getBoundingBoxes @OptIn(ExperimentalRichTextApi::class) @@ -35,7 +35,7 @@ object SpellCheck: RichSpanStyle { flattenForFullParagraphs = true, ) - boxes.fastForEachIndexed { index, box -> + boxes.fastForEach { box -> path.moveTo(box.left + startPadding, box.bottom + topPadding) path.lineTo(box.right + startPadding, box.bottom + topPadding) diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanel.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanel.kt index a8c72bdc..0ef297de 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanel.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanel.kt @@ -7,6 +7,9 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyRow import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.outlined.FormatAlignLeft +import androidx.compose.material.icons.automirrored.outlined.FormatAlignRight +import androidx.compose.material.icons.automirrored.outlined.FormatListBulleted import androidx.compose.material.icons.filled.Circle import androidx.compose.material.icons.outlined.* import androidx.compose.runtime.Composable @@ -45,7 +48,7 @@ fun SlackDemoPanel( ) }, isSelected = state.currentParagraphStyle.textAlign == TextAlign.Left, - icon = Icons.Outlined.FormatAlignLeft + icon = Icons.AutoMirrored.Outlined.FormatAlignLeft ) } @@ -73,7 +76,7 @@ fun SlackDemoPanel( ) }, isSelected = state.currentParagraphStyle.textAlign == TextAlign.Right, - icon = Icons.Outlined.FormatAlignRight + icon = Icons.AutoMirrored.Outlined.FormatAlignRight ) } @@ -229,7 +232,7 @@ fun SlackDemoPanel( state.toggleUnorderedList() }, isSelected = state.isUnorderedList, - icon = Icons.Outlined.FormatListBulleted, + icon = Icons.AutoMirrored.Outlined.FormatListBulleted, ) } From e70d3b1abdb7374885b85f0ba6aae21ffb85b47f Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 31 Mar 2024 20:02:36 +0100 Subject: [PATCH 3/3] Fix JS tests --- .../parser/html/CssDecoderTest.kt | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssDecoderTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssDecoderTest.kt index 2ed04bb5..1e2618a4 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssDecoderTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/html/CssDecoderTest.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp import kotlin.test.Test +import kotlin.test.assertContains import kotlin.test.assertEquals internal class CssDecoderTest { @@ -46,8 +47,8 @@ internal class CssDecoderTest { val color3 = Color(255, 0, 0, 107) val color4 = Color(0, 0, 255) - assertEquals( - "rgba(255, 0, 0, 1.0)", + assertContains( + listOf("rgba(255, 0, 0, 1.0)", "rgba(255, 0, 0, 1)"), CssDecoder.decodeColorToCss(color) ) assertEquals( @@ -58,8 +59,8 @@ internal class CssDecoderTest { "rgba(255, 0, 0, 0.42)", CssDecoder.decodeColorToCss(color3) ) - assertEquals( - "rgba(0, 0, 255, 1.0)", + assertContains( + listOf("rgba(0, 0, 255, 1.0)", "rgba(0, 0, 255, 1)"), CssDecoder.decodeColorToCss(color4) ) } @@ -77,12 +78,12 @@ internal class CssDecoderTest { "12.0px", CssDecoder.decodeSizeToCss(size) ) - assertEquals( - "16.0px", + assertContains( + listOf("16.0px", "16px"), CssDecoder.decodeSizeToCss(size2) ) - assertEquals( - "192.0px", + assertContains( + listOf("192.0px", "192px"), CssDecoder.decodeSizeToCss(size3) ) assertEquals( @@ -93,8 +94,8 @@ internal class CssDecoderTest { "12.5px", CssDecoder.decodeSizeToCss(size5) ) - assertEquals( - "-12.0px", + assertContains( + listOf("-12.0px", "-12px"), CssDecoder.decodeSizeToCss(size6) ) } @@ -110,16 +111,16 @@ internal class CssDecoderTest { val textUnit7 = TextUnit.Unspecified val textUnit8: TextUnit? = null - assertEquals( - "12.0em", + assertContains( + listOf("12.0em", "12em"), CssDecoder.decodeTextUnitToCss(textUnit) ) - assertEquals( - "16.0em", + assertContains( + listOf("16.0em", "16em"), CssDecoder.decodeTextUnitToCss(textUnit2) ) - assertEquals( - "192.0em", + assertContains( + listOf("192.0em", "192em"), CssDecoder.decodeTextUnitToCss(textUnit3) ) assertEquals( @@ -130,8 +131,8 @@ internal class CssDecoderTest { "12.5em", CssDecoder.decodeTextUnitToCss(textUnit5) ) - assertEquals( - "24.0px", + assertContains( + listOf("24.0px", "24px"), CssDecoder.decodeTextUnitToCss(textUnit6) ) assertEquals( @@ -282,16 +283,25 @@ internal class CssDecoderTest { color = Color(255, 204, 0) ) - assertEquals( - "1.0px 1.0px 1.0px rgba(0, 0, 0, 1.0)", + assertContains( + listOf( + "1.0px 1.0px 1.0px rgba(0, 0, 0, 1.0)", + "1px 1px 1px rgba(0, 0, 0, 1)" + ), CssDecoder.decodeTextShadowToCss(textShadow) ) - assertEquals( - "1.0px 1.0px 2.0px rgba(0, 0, 0, 1.0)", + assertContains( + listOf( + "1.0px 1.0px 2.0px rgba(0, 0, 0, 1.0)", + "1px 1px 2px rgba(0, 0, 0, 1)" + ), CssDecoder.decodeTextShadowToCss(textShadow2) ) - assertEquals( - "1.0px 1.0px 2.0px rgba(255, 204, 0, 1.0)", + assertContains( + listOf( + "1.0px 1.0px 2.0px rgba(255, 204, 0, 1.0)", + "1px 1px 2px rgba(255, 204, 0, 1)" + ), CssDecoder.decodeTextShadowToCss(textShadow3) ) }