From 682280cc2f1c230b0b5fc7ce442c068707422074 Mon Sep 17 00:00:00 2001 From: Halil Ozercan Date: Thu, 8 Feb 2024 23:54:19 +0000 Subject: [PATCH] Version bump 1.5.12 This change includes bunch of misc tech debt cleaning. - Use Compose Multiplatform dependencies instead of Google's Compose artifacts - Removed Previews from richtext-ui. - Renamed CodeBlock platform files. - Kotlin updated to 1.9.22 - Compose compiler update to 1.5.8 - Changed MarkdownSample to use CommonmarkAstNodeParser and do synchronous Markdown rendering. --- android-sample/build.gradle.kts | 9 ++- .../richtext/sample/MarkdownSample.kt | 13 ++- buildSrc/src/main/kotlin/Dependencies.kt | 15 +--- docs/richtext-ui-material3.md | 2 +- printing/build.gradle.kts | 7 +- richtext-ui/build.gradle.kts | 4 - .../ui/{CodeBlock.kt => CodeBlock.android.kt} | 1 - .../ui/util/ConditionalTapGestureDetector.kt | 4 +- .../ui/{CodeBlock.kt => CodeBlock.desktop.kt} | 1 - .../richtext/ui/previews/BlockQuotePreview.kt | 41 ---------- .../richtext/ui/previews/CodeBlockPreview.kt | 46 ----------- .../ui/previews/FormattedListPreview.kt | 79 ------------------- .../richtext/ui/previews/HeadingPreview.kt | 41 ---------- .../richtext/ui/previews/TablePreview.kt | 54 ------------- .../richtext/ui/previews/TextPreview.kt | 20 ----- slideshow/build.gradle.kts | 7 +- 16 files changed, 29 insertions(+), 315 deletions(-) rename richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/{CodeBlock.kt => CodeBlock.android.kt} (93%) rename richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/{CodeBlock.kt => CodeBlock.desktop.kt} (97%) delete mode 100644 richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/BlockQuotePreview.kt delete mode 100644 richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/CodeBlockPreview.kt delete mode 100644 richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/FormattedListPreview.kt delete mode 100644 richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/HeadingPreview.kt delete mode 100644 richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TablePreview.kt delete mode 100644 richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TextPreview.kt diff --git a/android-sample/build.gradle.kts b/android-sample/build.gradle.kts index 451f9463..3c749205 100644 --- a/android-sample/build.gradle.kts +++ b/android-sample/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.application") kotlin("android") + id("org.jetbrains.compose") version Compose.desktopVersion } android { @@ -36,8 +37,8 @@ dependencies { implementation(project(":slideshow")) implementation(AndroidX.appcompat) implementation(Compose.activity) - implementation(Compose.foundation) - implementation(Compose.icons) - implementation(Compose.material) - implementation(Compose.tooling) + implementation(compose.foundation) + implementation(compose.materialIconsExtended) + implementation(compose.material) + implementation(compose.uiTooling) } diff --git a/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt b/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt index 37fabea1..ad3bf972 100644 --- a/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt +++ b/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt @@ -30,8 +30,9 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em -import com.halilibo.richtext.commonmark.Markdown +import com.halilibo.richtext.commonmark.CommonmarkAstNodeParser import com.halilibo.richtext.commonmark.MarkdownParseOptions +import com.halilibo.richtext.markdown.Markdown import com.halilibo.richtext.ui.RichTextStyle import com.halilibo.richtext.ui.material.RichText import com.halilibo.richtext.ui.resolveDefaults @@ -104,13 +105,19 @@ import com.halilibo.richtext.ui.resolveDefaults SelectionContainer { Column(Modifier.verticalScroll(rememberScrollState())) { ProvideTextStyle(TextStyle(lineHeight = 1.3.em)) { + val parser = remember(markdownParseOptions) { + CommonmarkAstNodeParser(markdownParseOptions) + } + val astNode = remember(parser) { + parser.parse(sampleMarkdown) + } + RichText( style = richTextStyle, modifier = Modifier.padding(8.dp), ) { Markdown( - content = sampleMarkdown, - markdownParseOptions = markdownParseOptions, + astNode = astNode, onLinkClicked = { Toast.makeText(context, it, Toast.LENGTH_SHORT).show() } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 452044e1..a6f9f852 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -16,7 +16,7 @@ object Network { object Kotlin { // keep in sync with buildSrc/build.gradle.kts - val version = "1.9.20" + val version = "1.9.22" val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:0.9.0" val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version" @@ -31,19 +31,12 @@ val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:10.0.0" object Compose { val version = "1.5.4" - val compilerVersion = "1.5.4" - val desktopVersion = "1.5.11" + val compilerVersion = "1.5.8" + val desktopVersion = "1.5.12" val activity = "androidx.activity:activity-compose:1.7.2" - val foundation = "androidx.compose.foundation:foundation:$version" - val material = "androidx.compose.material:material:$version" - val material3 = "androidx.compose.material3:material3:1.0.1" - val icons = "androidx.compose.material:material-icons-extended:$version" - val test = "androidx.ui:ui-test:$version" - val tooling = "androidx.compose.ui:ui-tooling:$version" val toolingData = "androidx.compose.ui:ui-tooling-data:$version" - val desktopPreview = "org.jetbrains.compose.ui:ui-tooling-preview-desktop:$desktopVersion" val multiplatformUiUtil = "org.jetbrains.compose.ui:ui-util:$desktopVersion" - val coil = "io.coil-kt:coil-compose:2.4.0" + val coil = "io.coil-kt:coil-compose:2.5.0" } object Commonmark { diff --git a/docs/richtext-ui-material3.md b/docs/richtext-ui-material3.md index a9d9b8d7..a712090e 100644 --- a/docs/richtext-ui-material3.md +++ b/docs/richtext-ui-material3.md @@ -1,4 +1,4 @@ -# Richtext UI Material +# Richtext UI Material 3 [![Android Library](https://img.shields.io/badge/Platform-Android-green.svg?style=for-the-badge)](https://developer.android.com/studio/build/dependencies) [![JVM Library](https://img.shields.io/badge/Platform-JVM-red.svg?style=for-the-badge)](https://kotlinlang.org/docs/mpp-intro.html) diff --git a/printing/build.gradle.kts b/printing/build.gradle.kts index 21fb919b..5dba13d9 100644 --- a/printing/build.gradle.kts +++ b/printing/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("richtext-android-library") id("org.jetbrains.dokka") + id("org.jetbrains.compose") version Compose.desktopVersion } android { @@ -8,14 +9,14 @@ android { } dependencies { - implementation(Compose.foundation) - implementation(Compose.tooling) + implementation(compose.foundation) + implementation(compose.uiTooling) // For slot table analysis. implementation(Compose.toolingData) implementation(Compose.activity) // TODO Migrate off this. - implementation(Compose.material) + implementation(compose.material) } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all { diff --git a/richtext-ui/build.gradle.kts b/richtext-ui/build.gradle.kts index 5eb08c36..3c960c21 100644 --- a/richtext-ui/build.gradle.kts +++ b/richtext-ui/build.gradle.kts @@ -28,10 +28,6 @@ kotlin { } val jvmMain by getting { kotlin.srcDir("src/commonJvmAndroid/kotlin") - dependencies { - // requires installing https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support - implementation(Compose.desktopPreview) - } } } } diff --git a/richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/CodeBlock.kt b/richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/CodeBlock.android.kt similarity index 93% rename from richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/CodeBlock.kt rename to richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/CodeBlock.android.kt index c045dad1..3368bda7 100644 --- a/richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/CodeBlock.kt +++ b/richtext-ui/src/androidMain/kotlin/com/halilibo/richtext/ui/CodeBlock.android.kt @@ -1,4 +1,3 @@ -@file:JvmName("CodeBlockAndroid") package com.halilibo.richtext.ui import androidx.compose.foundation.horizontalScroll diff --git a/richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/util/ConditionalTapGestureDetector.kt b/richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/util/ConditionalTapGestureDetector.kt index 7e0f7c21..9796d476 100644 --- a/richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/util/ConditionalTapGestureDetector.kt +++ b/richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/util/ConditionalTapGestureDetector.kt @@ -6,13 +6,11 @@ import androidx.compose.foundation.gestures.GestureCancellationException import androidx.compose.foundation.gestures.PressGestureScope import androidx.compose.foundation.gestures.awaitEachGesture import androidx.compose.foundation.gestures.awaitFirstDown -import androidx.compose.foundation.gestures.detectTapGestures -import androidx.compose.foundation.gestures.forEachGesture import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.geometry.Offset import androidx.compose.ui.input.pointer.AwaitPointerEventScope -import androidx.compose.ui.input.pointer.PointerEventTimeoutCancellationException import androidx.compose.ui.input.pointer.PointerEventPass +import androidx.compose.ui.input.pointer.PointerEventTimeoutCancellationException import androidx.compose.ui.input.pointer.PointerInputChange import androidx.compose.ui.input.pointer.PointerInputScope import androidx.compose.ui.input.pointer.changedToUp diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/CodeBlock.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/CodeBlock.desktop.kt similarity index 97% rename from richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/CodeBlock.kt rename to richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/CodeBlock.desktop.kt index e56b52a6..8b101dd8 100644 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/CodeBlock.kt +++ b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/CodeBlock.desktop.kt @@ -1,4 +1,3 @@ -@file:JvmName("CodeBlockJvm") package com.halilibo.richtext.ui import androidx.compose.foundation.HorizontalScrollbar diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/BlockQuotePreview.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/BlockQuotePreview.kt deleted file mode 100644 index aeab4929..00000000 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/BlockQuotePreview.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.halilibo.richtext.ui.previews - -import androidx.compose.desktop.ui.tooling.preview.Preview -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import com.halilibo.richtext.ui.BlockQuote -import com.halilibo.richtext.ui.LocalInternalContentColor -import com.halilibo.richtext.ui.RichTextScope -import com.halilibo.richtext.ui.Text - -@Preview -@Composable -private fun BlockQuotePreviewOnWhite() { - BlockQuotePreview(backgroundColor = Color.White, contentColor = Color.Black) -} - -@Preview -@Composable private fun BlockQuotePreviewOnBlack() { - BlockQuotePreview(backgroundColor = Color.Black, contentColor = Color.White) -} - -@Composable private fun BlockQuotePreview( - backgroundColor: Color, - contentColor: Color -) { - CompositionLocalProvider(LocalInternalContentColor provides contentColor) { - Box(Modifier.background(backgroundColor)) { - RichTextScope.BlockQuote { - Text("Some text.") - Text("Another paragraph.") - BlockQuote { - Text("Nested block quote.") - } - } - } - } -} diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/CodeBlockPreview.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/CodeBlockPreview.kt deleted file mode 100644 index 1f8df1bc..00000000 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/CodeBlockPreview.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.halilibo.richtext.ui.previews - -import androidx.compose.desktop.ui.tooling.preview.Preview -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.padding -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp -import com.halilibo.richtext.ui.CodeBlock -import com.halilibo.richtext.ui.LocalInternalContentColor -import com.halilibo.richtext.ui.RichTextScope - -@Preview -@Composable -private fun CodeBlockPreviewOnWhite() { - CodeBlockPreview(backgroundColor = Color.White, contentColor = Color.Black) -} - -@Preview -@Composable -private fun CodeBlockPreviewOnBlack() { - CodeBlockPreview(backgroundColor = Color.Black, contentColor = Color.White) -} - -@Composable -private fun CodeBlockPreview( - backgroundColor: Color, - contentColor: Color -) { - CompositionLocalProvider(LocalInternalContentColor provides contentColor) { - Box(modifier = Modifier.background(color = backgroundColor)) { - Box(modifier = Modifier.padding(24.dp)) { - RichTextScope.CodeBlock( - """ - data class Hello( - val name: String - ) - """.trimIndent() - ) - } - } - } -} diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/FormattedListPreview.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/FormattedListPreview.kt deleted file mode 100644 index 98efc828..00000000 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/FormattedListPreview.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.halilibo.richtext.ui.previews - -import androidx.compose.desktop.ui.tooling.preview.Preview -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalLayoutDirection -import androidx.compose.ui.unit.LayoutDirection -import com.halilibo.richtext.ui.FormattedList -import com.halilibo.richtext.ui.ListType -import com.halilibo.richtext.ui.RichTextScope -import com.halilibo.richtext.ui.Text - -@Preview -@Composable -private fun UnorderedListPreview() { - ListPreview(listType = ListType.Unordered, layoutDirection = LayoutDirection.Ltr) -} - -@Preview -@Composable -private fun UnorderedListPreviewRtl() { - ListPreview(listType = ListType.Unordered, layoutDirection = LayoutDirection.Rtl) -} - -@Preview -@Composable -private fun OrderedListPreview() { - ListPreview(listType = ListType.Ordered, layoutDirection = LayoutDirection.Ltr) -} - -@Preview -@Composable -private fun OrderedListPreviewRtl() { - ListPreview(listType = ListType.Ordered, layoutDirection = LayoutDirection.Rtl) -} - -@Composable -private fun ListPreview( - listType: ListType, - layoutDirection: LayoutDirection -) { - CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) { - Box(Modifier.background(color = Color.White)) { - RichTextScope.FormattedList( - listType = listType, - items = listOf( - "Foo", - "Bar", - "Baz", - "Foo", - "Bar", - "Baz", - "Foo", - "Bar", - "Foo\nBar\nBaz", - "Foo" - ).withIndex() - .toList() - ) { (index, text) -> - Text(text) - if (index == 0) { - FormattedList(listType, @Composable { - Text("indented $text") - FormattedList(listType, @Composable { - Text("indented $text") - FormattedList(listType, @Composable { - Text("indented $text") - }) - }) - }) - } - } - } - } -} diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/HeadingPreview.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/HeadingPreview.kt deleted file mode 100644 index 56b26f5f..00000000 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/HeadingPreview.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.halilibo.richtext.ui.previews - -import androidx.compose.desktop.ui.tooling.preview.Preview -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import com.halilibo.richtext.ui.Heading -import com.halilibo.richtext.ui.LocalInternalContentColor -import com.halilibo.richtext.ui.RichTextScope - -@Preview -@Composable -private fun HeadingPreviewOnWhite() { - HeadingPreview(backgroundColor = Color.White, contentColor = Color.Black) -} - -@Preview -@Composable -private fun HeadingPreviewOnBlack() { - HeadingPreview(backgroundColor = Color.Black, contentColor = Color.White) -} - -@Composable -private fun HeadingPreview( - backgroundColor: Color, - contentColor: Color -) { - CompositionLocalProvider(LocalInternalContentColor provides contentColor) { - Box(Modifier.background(color = backgroundColor)) { - Column { - for (level in 0 until 10) { - RichTextScope.Heading(level, "Heading ${level + 1}") - } - } - } - } -} diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TablePreview.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TablePreview.kt deleted file mode 100644 index 1ac580e9..00000000 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TablePreview.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.halilibo.richtext.ui.previews - -import androidx.compose.desktop.ui.tooling.preview.Preview -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.padding -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp -import com.halilibo.richtext.ui.BlockQuote -import com.halilibo.richtext.ui.CodeBlock -import com.halilibo.richtext.ui.RichTextScope -import com.halilibo.richtext.ui.Table -import com.halilibo.richtext.ui.Text - -@Preview -@Composable -private fun TablePreview() { - TablePreviewContents() -} - -@Preview -@Composable -private fun TablePreviewFixedWidth() { - TablePreviewContents() -} - -@Composable -private fun TablePreviewContents(modifier: Modifier = Modifier) { - RichTextScope.Table( - modifier = modifier - .background(Color.White) - .padding(4.dp), - headerRow = { - cell { Text("Column 1") } - cell { Text("Column 2") } - } - ) { - row { - cell { Text("Hello") } - cell { - CodeBlock("Foo bar") - } - } - row { - cell { - BlockQuote { - Text("Stuff") - } - } - cell { Text("Hello world this is a really long line that is going to wrap hopefully") } - } - } -} diff --git a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TextPreview.kt b/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TextPreview.kt deleted file mode 100644 index 7501d4c3..00000000 --- a/richtext-ui/src/jvmMain/kotlin/com/halilibo/richtext/ui/previews/TextPreview.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.halilibo.richtext.ui.previews - -import androidx.compose.desktop.ui.tooling.preview.Preview -import androidx.compose.runtime.Composable -import com.halilibo.richtext.ui.RichTextScope -import com.halilibo.richtext.ui.string.RichTextString -import com.halilibo.richtext.ui.string.Text -import com.halilibo.richtext.ui.string.richTextString -import com.halilibo.richtext.ui.string.withFormat - -@Preview -@Composable -private fun TextPreview() { - RichTextScope.Text(richTextString { - append("I'm ") - withFormat(RichTextString.Format.Bold) { - append("bold!") - } - }) -} diff --git a/slideshow/build.gradle.kts b/slideshow/build.gradle.kts index c93de4e8..373ca7df 100644 --- a/slideshow/build.gradle.kts +++ b/slideshow/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("richtext-android-library") id("org.jetbrains.dokka") + id("org.jetbrains.compose") version Compose.desktopVersion } android { @@ -8,7 +9,7 @@ android { } dependencies { - implementation(Compose.foundation) - implementation(Compose.material) - implementation(Compose.tooling) + implementation(compose.foundation) + implementation(compose.material) + implementation(compose.uiTooling) }