Skip to content

Commit

Permalink
Support import HTML with the new core
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Jul 15, 2023
1 parent ee9ed24 commit 08cffec
Show file tree
Hide file tree
Showing 49 changed files with 1,592 additions and 623 deletions.
16 changes: 4 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
group = "com.mohamedrejeb.richeditor"
version = "1.0.0-alpha01"

buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
mavenLocal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
classpath(libs.bundles.plugins)
}
plugins {
alias(libs.plugins.androidLibrary).apply(false)
alias(libs.plugins.kotlinMultiplatform).apply(false)
alias(libs.plugins.composeMultiplatform).apply(false)
}

allprojects {
Expand Down
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ kotlin.mpp.enableCInteropCommonization=true
#Android
android.useAndroidX=true
android.disableAutomaticComponentCreation=true
android.compileSdk=33
android.targetSdk=33
android.minSdk=21

#Web
org.jetbrains.compose.experimental.jscanvas.enabled=true
Expand Down
50 changes: 18 additions & 32 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
[versions]
plugin-android = "7.4.2"
plugin-kotlin = "1.8.20"
plugin-gver = "0.46.0"
agp = "7.4.2"
kotlin = "1.8.20"
compose = "1.4.0"

ksoup = "0.2.0-dev01"

# For sample
compose-compiler = "1.4.6"
compose = "1.4.0"
kotlinx-serialization = "1.5.0"
kotlinx-coroutines = "1.6.4"
jetbrains-kotlin-wrappers = "1.0.0-pre.510"
androidx-appcompat = "1.6.1"
activity-compose = "1.7.0"
compose-uitooling = "1.4.1"
composeImageLoader = "1.3.1"
voyager = "1.0.0-rc05"
richeditor = "1.0.0-alpha01"
android-minSdk = "21"
android-compileSdk = "33"

[libraries]
plugin-android = { module = "com.android.tools.build:gradle", version.ref = "plugin-android" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin" }
plugin-kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "plugin-kotlin" }
plugin-gver = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "plugin-gver" }
jetbrains-compose-gradle-plugin = { group = "org.jetbrains.compose", name = "compose-gradle-plugin", version.ref = "compose" }

jetbrains-kotlin-wrappers-bom = { group = "org.jetbrains.kotlin-wrappers", name = "kotlin-wrappers-bom", version.ref = "jetbrains-kotlin-wrappers" }
#jetbrains-kotlinWrappers-kotlinStyled = { group = "org.jetbrains.kotlin-wrappers", name = "kotlin-styled" }

kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }

kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
ksoup = { module = "com.mohamedrejeb.ksoup:ksoup-html", version.ref = "ksoup" }

# For sample
activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" }
voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" }
richeditor-compose = { module = "com.mohamedrejeb.richeditor:richeditor-compose", version.ref = "richeditor" }

[bundles]
plugins = [
"plugin-android",
"plugin-kotlin",
"plugin-kotlin-serialization",
"plugin-gver",
"jetbrains-compose-gradle-plugin",
]
[plugins]
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 12 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
24 changes: 11 additions & 13 deletions richeditor-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("org.jetbrains.compose")
id("com.android.library")
}

kotlin {
android()
android {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
jvm("desktop") {
jvmToolchain(11)
}
Expand All @@ -26,9 +32,7 @@ kotlin {
api(compose.material3)
api(compose.materialIconsExtended)

implementation(libs.kotlinx.serialization.json)

implementation("com.mohamedrejeb.ksoup:ksoup-html:0.1.2")
implementation(libs.ksoup)
}
}

Expand Down Expand Up @@ -70,15 +74,9 @@ kotlin {

android {
namespace = "com.mohamedrejeb.richeditor"
compileSdk = (findProperty("android.compileSdk") as String).toInt()
compileSdk = libs.versions.android.compileSdk.get().toInt()

defaultConfig {
minSdk = (findProperty("android.minSdk") as String).toInt()
targetSdk = (findProperty("android.targetSdk") as String).toInt()
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.BaselineShift
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextDirection
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.assertEquals

Expand Down Expand Up @@ -94,6 +99,51 @@ internal class CssDecoderTest {
)
}

@Test
fun testDecodeTextUnitToCss() {
val textUnit = 12.em
val textUnit2 = 16.em
val textUnit3 = 192.em
val textUnit4 = 1.92.em
val textUnit5 = 12.5.em
val textUnit6 = 24.sp
val textUnit7 = TextUnit.Unspecified
val textUnit8: TextUnit? = null

assertEquals(
"12.0em",
CssDecoder.decodeTextUnitToCss(textUnit)
)
assertEquals(
"16.0em",
CssDecoder.decodeTextUnitToCss(textUnit2)
)
assertEquals(
"192.0em",
CssDecoder.decodeTextUnitToCss(textUnit3)
)
assertEquals(
"1.92em",
CssDecoder.decodeTextUnitToCss(textUnit4)
)
assertEquals(
"12.5em",
CssDecoder.decodeTextUnitToCss(textUnit5)
)
assertEquals(
"24.0px",
CssDecoder.decodeTextUnitToCss(textUnit6)
)
assertEquals(
null,
CssDecoder.decodeTextUnitToCss(textUnit7)
)
assertEquals(
null,
CssDecoder.decodeTextUnitToCss(textUnit8)
)
}

@Test
fun testDecodeFontWeightToCss() {
val fontWeight = FontWeight.Thin
Expand Down Expand Up @@ -245,4 +295,72 @@ internal class CssDecoderTest {
CssDecoder.decodeTextShadowToCss(textShadow3)
)
}

@Test
fun testDecodeTextAlignToCss() {
val textAlign = TextAlign.Left
val textAlign2 = TextAlign.Right
val textAlign3 = TextAlign.Center
val textAlign4 = TextAlign.Justify
val textAlign5 = TextAlign.Start
val textAlign6 = TextAlign.End
val textAlign7: TextAlign? = null

assertEquals(
"left",
CssDecoder.decodeTextAlignToCss(textAlign)
)
assertEquals(
"right",
CssDecoder.decodeTextAlignToCss(textAlign2)
)
assertEquals(
"center",
CssDecoder.decodeTextAlignToCss(textAlign3)
)
assertEquals(
"justify",
CssDecoder.decodeTextAlignToCss(textAlign4)
)
assertEquals(
"left",
CssDecoder.decodeTextAlignToCss(textAlign5, TextDirection.Ltr)
)
assertEquals(
"right",
CssDecoder.decodeTextAlignToCss(textAlign5, TextDirection.Rtl)
)
assertEquals(
"right",
CssDecoder.decodeTextAlignToCss(textAlign6, TextDirection.Ltr)
)
assertEquals(
"left",
CssDecoder.decodeTextAlignToCss(textAlign6, TextDirection.Rtl)
)
assertEquals(
null,
CssDecoder.decodeTextAlignToCss(textAlign7)
)
}

@Test
fun testDecodeTextDirectionToCss() {
val textDirection = TextDirection.Ltr
val textDirection2 = TextDirection.Rtl
val textDirection3: TextDirection? = null

assertEquals(
"ltr",
CssDecoder.decodeTextDirectionToCss(textDirection)
)
assertEquals(
"rtl",
CssDecoder.decodeTextDirectionToCss(textDirection2)
)
assertEquals(
null,
CssDecoder.decodeTextDirectionToCss(textDirection3)
)
}
}
Loading

0 comments on commit 08cffec

Please sign in to comment.