Skip to content

Commit

Permalink
Reorganize and expand the Markdown modules
Browse files Browse the repository at this point in the history
 * Split out theming from Core (except for jewel.ui deps)
 * Implement both bridge and standalone Int UI themes
 * Reorganize modules to make adding extensions easier
 * Add Markdown rendering to IDE plugin sample

> [!NOTE]
> The leaf modules are named `*Styling` because Gradle doesn't allow you
> to have modules with the same name and that depend on each other. It
> says it's a circular dependency, even if it's not (the modules have
> different paths). Since the Standalone Markdown module depends on the
> Int UI Standalone, and the Bridge Markdown depends on the Bridge
> theme, this would break the build. We are, however, going to try and
> figure this out so that we can remove the suffix.
  • Loading branch information
rock3r committed Mar 26, 2024
1 parent 247e136 commit b2b44a7
Show file tree
Hide file tree
Showing 44 changed files with 1,002 additions and 261 deletions.
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ custom repository for it in `settings.gradle.kts`:

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

Then, in your app's `build.gradle.kts`:

```kotlin
plugins {
// Should align with the Kotlin and Compose dependencies in Jewel
kotlin("jvm") version "1.9.21"
id("org.jetbrains.compose") version "1.6.0-dev1440"
// Should align with the Kotlin and Compose dependencies in Jewel
kotlin("jvm") version "1.9.21"
id("org.jetbrains.compose") version "1.6.0-dev1440"
}

repositories {
Expand Down Expand Up @@ -89,7 +89,7 @@ dependencies {

// Do not bring in Material (we use Jewel)
implementation(compose.desktop.currentOs) {
exclude(group = "org.jetbrains.compose.material")
exclude(group = "org.jetbrains.compose.material")
}
}
```
Expand All @@ -104,8 +104,8 @@ dependencies {

// Do not bring in Material (we use Jewel) and Coroutines (the IDE has its own)
api(compose.desktop.currentOs) {
exclude(group = "org.jetbrains.compose.material")
exclude(group = "org.jetbrains.kotlinx")
exclude(group = "org.jetbrains.compose.material")
exclude(group = "org.jetbrains.kotlinx")
}
}
```
Expand All @@ -119,9 +119,11 @@ dependencies {

## Using ProGuard/obfuscation/minification

Jewel doesn't officially support using ProGuard to minimize and/or obfuscate your code, and there is currently no plan to.
Jewel doesn't officially support using ProGuard to minimize and/or obfuscate your code, and there is currently no plan
to.
That said, people are reporting successes in using it. Please note that there is no guarantee that it will keep working,
and you most definitely need to have some rules in place. We don't provide any official rule set, but these have been known
and you most definitely need to have some rules in place. We don't provide any official rule set, but these have been
known
to work for some: https://github.com/romainguy/kotlin-explorer/blob/main/compose-desktop.pro

> [!IMPORTANT]
Expand All @@ -131,12 +133,12 @@ to work for some: https://github.com/romainguy/kotlin-explorer/blob/main/compose

For each version of Jewel, these are the minimum supported Kotlin and Compose Multiplatform versions:

Jewel version | Kotlin version | Compose version
--- | --- | ---
0.15.2 -> * | 1.8.21 | 1.6.10-dev1490
0.15.1 | 1.8.21 | 1.6.10-dev1457
0.15.0 | 1.8.21 | 1.6.0-dev1440
0.13.1 -> 0.14.1 | 1.8.21 | 1.6.0-dev1369
| Jewel version | Kotlin version | Compose version |
|------------------|----------------|-----------------|
| 0.15.2 -> * | 1.8.21 | 1.6.10-dev1490 |
| 0.15.1 | 1.8.21 | 1.6.10-dev1457 |
| 0.15.0 | 1.8.21 | 1.6.0-dev1440 |
| 0.13.1 -> 0.14.1 | 1.8.21 | 1.6.0-dev1369 |

For older versions please refer to the Jewel tags and release notes.

Expand Down Expand Up @@ -171,7 +173,9 @@ The project is split in modules:
6. `ide-laf-bridge` contains the Swing LaF bridge to use in IntelliJ Platform plugins (see more below)
7. `markdown` contains a few modules:
* `core` the core logic for parsing and rendering Markdown documents with Jewel, using GitHub-like styling
* `extensions` contains several extensions to the base CommonMark specs that can be used to add more features
* `extension` contains several extensions to the base CommonMark specs that can be used to add more features
* `ide-laf-bridge-styling` contains the IntelliJ Platform bridge theming for the Markdown renderer
* `int-ui-standalone-styling` contains the standalone Int UI theming for the Markdown renderer
8. `samples` contains the example apps, which showcase the available components:
* `standalone` is a regular CfD app, using the standalone theme definitions and custom window decoration
* `ide-plugin` is an IntelliJ plugin that showcases the use of the Swing Bridge
Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ dependencies {
sarif(projects.intUi.intUiDecoratedWindow)
sarif(projects.intUi.intUiStandalone)
sarif(projects.markdown.core)
sarif(projects.markdown.extensionGfmAlerts)
sarif(projects.markdown.extension.gfmAlerts)
sarif(projects.markdown.ideLafBridgeStyling)
sarif(projects.markdown.intUiStandaloneStyling)
sarif(projects.samples.idePlugin)
sarif(projects.samples.standalone)
sarif(projects.ui)
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/jewel-publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ val javadocJar by tasks.registering(Jar::class) {
publishing {
configureJewelRepositories(project)

val ijpTarget = project.property("ijp.target") as String

publications {
register<MavenPublication>("main") {
from(components["kotlin"])
artifact(javadocJar)
artifact(sourcesJar)
version = project.properties["jewel.release.version"] as String
artifactId = "jewel-${project.name}"
artifactId = "jewel-${project.name}-$ijpTarget"
pom { configureJewelPom() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import org.gradle.api.Project

val Project.currentIjpVersion: String
get() {
val rawValue = property("bridge.ijp.target") as? String
?: error("Property bridge.ijp.target not defined. Check your gradle.properties!")
val rawValue = property("ijp.target") as? String
?: error("Property ijp.target not defined. Check your gradle.properties!")

if (rawValue.length != 3 || rawValue.toIntOrNull()?.let { it < 0 } == true) {
error("Invalid bridge.ijp.target property value: '$rawValue'")
error("Invalid ijp.target property value: '$rawValue'")
}

return rawValue
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ kotlin.stdlib.default.dependency=false
# See https://jb.gg/intellij-platform-kotlin-oom
kotlin.incremental.useClasspathSnapshot=false

bridge.ijp.target=241
ijp.target=241
jewel.release.version=0.15.2
4 changes: 4 additions & 0 deletions ide-laf-bridge/api/ide-laf-bridge.api
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public final class org/jetbrains/jewel/bridge/theme/BridgeThemeColorPaletteKt {
public static final fun readFromLaF (Lorg/jetbrains/jewel/foundation/theme/ThemeColorPalette$Companion;)Lorg/jetbrains/jewel/foundation/theme/ThemeColorPalette;
}

public final class org/jetbrains/jewel/bridge/theme/IntUiBridgeKt {
public static final fun retrieveDefaultTextStyle ()Landroidx/compose/ui/text/TextStyle;
}

public final class org/jetbrains/jewel/bridge/theme/SwingBridgeThemeKt {
public static final fun SwingBridgeTheme (Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;I)V
}
Expand Down
8 changes: 0 additions & 8 deletions ide-laf-bridge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ plugins {
alias(libs.plugins.composeDesktop)
}

val bridgeIjpTarget = project.property("bridge.ijp.target") as String

dependencies {
api(projects.ui) {
exclude(group = "org.jetbrains.kotlinx")
Expand All @@ -20,9 +18,3 @@ dependencies {
exclude(group = "org.jetbrains.compose.material")
}
}

publishing.publications {
named<MavenPublication>("main") {
artifactId = "jewel-${project.name}-$bridgeIjpTarget"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.intellij.util.ui.JBDimension
import com.intellij.util.ui.JBFont
import com.intellij.util.ui.JBInsets
import com.intellij.util.ui.JBValue
import org.jetbrains.skiko.DependsOnJBR
import java.awt.Dimension
import java.awt.Insets
import javax.swing.UIManager
Expand Down Expand Up @@ -153,14 +152,12 @@ public fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSize
keysNotFound(keys.toList(), "Int")
}

@DependsOnJBR
public fun retrieveTextStyle(fontKey: String, colorKey: String? = null): TextStyle {
val baseColor = colorKey?.let { retrieveColorOrUnspecified(colorKey) } ?: Color.Unspecified
return retrieveTextStyle(fontKey, color = baseColor)
}

@OptIn(ExperimentalTextApi::class)
@DependsOnJBR
public fun retrieveTextStyle(
key: String,
color: Color = Color.Unspecified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ import org.jetbrains.jewel.ui.component.styling.TextFieldStyle
import org.jetbrains.jewel.ui.component.styling.TooltipColors
import org.jetbrains.jewel.ui.component.styling.TooltipMetrics
import org.jetbrains.jewel.ui.component.styling.TooltipStyle
import org.jetbrains.skiko.DependsOnJBR
import javax.swing.UIManager
import kotlin.time.Duration.Companion.milliseconds

Expand All @@ -121,12 +120,14 @@ internal val uiDefaults
private val iconsBasePath
get() = DirProvider().dir()

@OptIn(DependsOnJBR::class)
internal fun createBridgeThemeDefinition(): ThemeDefinition {
val textStyle = retrieveTextStyle("Label.font", "Label.foreground")
val textStyle = retrieveDefaultTextStyle()
return createBridgeThemeDefinition(textStyle)
}

public fun retrieveDefaultTextStyle(): TextStyle =
retrieveTextStyle("Label.font", "Label.foreground")

internal fun createBridgeThemeDefinition(textStyle: TextStyle): ThemeDefinition {
val isDark = !JBColor.isBright()

Expand All @@ -143,7 +144,6 @@ internal fun createBridgeThemeDefinition(textStyle: TextStyle): ThemeDefinition
)
}

@OptIn(DependsOnJBR::class)
internal fun createBridgeComponentStyling(
theme: ThemeDefinition,
) =
Expand Down
14 changes: 9 additions & 5 deletions markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Currently supports the [CommonMark 0.31.2](https://spec.commonmark.org/0.31.2/)

Additional supported Markdown, via extensions:

* Alerts ([GitHub Flavored Markdown][alerts-specs]) — see [`extension-gfm-alerts`](extension-gfm-alerts)
* Alerts ([GitHub Flavored Markdown][alerts-specs]) — see [`extension-gfm-alerts`](extension/gfm-alerts)

[alerts-specs]: https://github.com/orgs/community/discussions/16925

Expand Down Expand Up @@ -46,16 +46,20 @@ Not supported, and not on the roadmap:

## Add the Markdown renderer to your project

You need to add the renderer **alongside** either a `jewel-standalone` or `jewel-ide-laf-bridge-*` dependency in order
for the renderer to work, as it assumes that the necessary `jewel-ui` and `jewel-foundation` are on the classpath
already.
The Jewel Markdown renderer is designed to be run in a project that already has a `jewel-standalone` or
`jewel-ide-laf-bridge-*` dependency. The `core` module doesn't contain any styling, and you're supposed to use either
the `jewel-markdown-int-ui-standalone-styling` or `jewel-markdown-ide-laf-bridge-styling` instead. They will carry the
necessary dependencies.

> [!CAUTION]
> Don't use the standalone artifact in an IDE plugin, and don't use the bridge artifact in a standalone project!
If you want to use extensions, you also need to add them **alongside** the `jewel-markdown-core`:

```kotlin
dependencies {
implementation(libs.jewel.standalone)
implementation(libs.jewel.markdown.core)
implementation(libs.jewel.markdown.intUiStandaloneStyling)
implementation(libs.jewel.markdown.extension.gfm.alerts) // Optional
// Et cetera...
}
Expand Down
Loading

0 comments on commit b2b44a7

Please sign in to comment.