Skip to content

Commit

Permalink
Merge pull request #231 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
1.x
  • Loading branch information
MohamedRejeb authored Mar 31, 2024
2 parents 3e2acb7 + e70d3b1 commit 83c8464
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,7 @@ internal class RichParagraph(
var type: ParagraphType = DefaultParagraph(),
) {

@OptIn(ExperimentalRichTextApi::class)
fun getRichSpanByTextIndex(
paragraphIndex: Int,
textIndex: Int,
Expand Down Expand Up @@ -60,6 +62,7 @@ internal class RichParagraph(
return index to null
}

@OptIn(ExperimentalRichTextApi::class)
fun getRichSpanListByTextRange(
paragraphIndex: Int,
searchTextRange: TextRange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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

internal class DefaultParagraph : ParagraphType {
override val style: ParagraphStyle =
ParagraphStyle()

@OptIn(ExperimentalRichTextApi::class)
override val startRichSpan: RichSpan =
RichSpan(paragraph = RichParagraph(type = this))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -46,6 +47,7 @@ internal class OrderedList(
override var startRichSpan: RichSpan =
getNewStartRichSpan()

@OptIn(ExperimentalRichTextApi::class)
private fun getNewStartRichSpan() =
RichSpan(
paragraph = RichParagraph(type = this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,6 +20,7 @@ internal class UnorderedList : ParagraphType {
)
)

@OptIn(ExperimentalRichTextApi::class)
override var startRichSpan: RichSpan =
RichSpan(
paragraph = RichParagraph(type = this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +19,7 @@ import com.mohamedrejeb.richeditor.utils.fastForEachIndexed

internal object RichTextStateHtmlParser : RichTextStateParser<String> {

@OptIn(ExperimentalRichTextApi::class)
override fun encode(input: String): RichTextState {
val openedTags = mutableListOf<Pair<String, Map<String, String>>>()
val stringBuilder = StringBuilder()
Expand Down Expand Up @@ -238,6 +240,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
return builder.toString()
}

@OptIn(ExperimentalRichTextApi::class)
private fun decodeRichSpanToHtml(richSpan: RichSpan, parentFormattingTags: List<String> = emptyList()): String {
val stringBuilder = StringBuilder()

Expand Down Expand Up @@ -353,6 +356,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
/**
* Encodes HTML elements to [RichSpanStyle].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun encodeHtmlElementToRichSpanStyle(
tagName: String,
attributes: Map<String, String>,
Expand All @@ -369,6 +373,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
/**
* Decodes HTML elements from [RichSpanStyle].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun decodeHtmlElementFromRichSpanStyle(
richSpanStyle: RichSpanStyle,
): Pair<String, Map<String, String>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ import org.intellij.markdown.flavours.gfm.GFMElementTypes

internal object RichTextStateMarkdownParser : RichTextStateParser<String> {

@OptIn(ExperimentalRichTextApi::class)
override fun encode(input: String): RichTextState {
val openedNodes = mutableListOf<ASTNode>()
val stringBuilder = StringBuilder()
Expand Down Expand Up @@ -149,7 +151,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {

currentRichSpan = currentRichSpan?.parent
},
onHtml = { html ->
onHtml = { _ ->
// Todo: support HTML in markdown
}
)
Expand Down Expand Up @@ -187,6 +189,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
return builder.toString()
}

@OptIn(ExperimentalRichTextApi::class)
private fun decodeRichSpanToMarkdown(richSpan: RichSpan): String {
val stringBuilder = StringBuilder()

Expand Down Expand Up @@ -239,6 +242,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
/**
* Encodes Markdown elements to [RichSpanStyle].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun encodeMarkdownElementToRichSpanStyle(
node: ASTNode,
markdown: String,
Expand Down Expand Up @@ -269,6 +273,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
/**
* Decodes HTML elements from [RichSpan].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun decodeMarkdownElementFromRichSpan(
text: String,
richSpanStyle: RichSpanStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -83,7 +83,7 @@ internal fun DebugRichTextEditor(
RichTextStyleTreeRepresentation(childIndex, richTextStyle, " -")
}

Divider(modifier = Modifier.padding(vertical = 20.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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)
)
}
Expand All @@ -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(
Expand All @@ -93,8 +94,8 @@ internal class CssDecoderTest {
"12.5px",
CssDecoder.decodeSizeToCss(size5)
)
assertEquals(
"-12.0px",
assertContains(
listOf("-12.0px", "-12px"),
CssDecoder.decodeSizeToCss(size6)
)
}
Expand All @@ -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(
Expand All @@ -130,8 +131,8 @@ internal class CssDecoderTest {
"12.5em",
CssDecoder.decodeTextUnitToCss(textUnit5)
)
assertEquals(
"24.0px",
assertContains(
listOf("24.0px", "24px"),
CssDecoder.decodeTextUnitToCss(textUnit6)
)
assertEquals(
Expand Down Expand Up @@ -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)
)
}
Expand Down
Loading

0 comments on commit 83c8464

Please sign in to comment.