Skip to content

Commit 29d989b

Browse files
authored
chore: cleanup + perf improvements (#4)
* Pass theme instead * Remove vertical scroll * Fix click * Fix gutter height * Minor * Mark library experimental * Change version * Minor UI fixes * Fix height * Copy fix * Copy fix * Minor * Minor * Minor * Temp * Minor * Add large json sample * virtualised json viewer * Fix gutter cell * Add search bar in json viewer * Update sample app * Remove tests * Minor * Enhance domain * Code cleanup+ basic documentation * Update docs * CLeanup * API dump recreated
1 parent 0cd74a8 commit 29d989b

100 files changed

Lines changed: 235942 additions & 4487 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ permissions:
1212
contents: read
1313

1414
jobs:
15+
api-check:
16+
name: API Compatibility
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-java@v4
22+
with:
23+
distribution: zulu
24+
java-version: 17
25+
26+
- uses: gradle/actions/setup-gradle@v4
27+
28+
- name: Check API compatibility
29+
run: ./gradlew apiCheck
30+
1531
detekt:
1632
name: Detekt
1733
runs-on: ubuntu-latest

README.md

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
Kotlin Multiplatform Compose JSON viewer and editor component for Android, iOS, and JVM Desktop.
1010

11+
> **⚠️ Experimental:** This library is in an experimental state. APIs may change without notice between releases. Use in production at your own discretion.
12+
1113
## Features
1214

13-
- **JSON Viewer**Syntax-highlighted, foldable JSON tree with line numbers
14-
- **JSON Editor** — Editable JSON with real-time validation, formatting, and sorting
15+
- **JSON Viewer**Read-only, syntax-highlighted, foldable JSON tree with virtualized rendering (virtually no size limit for valid JSON; invalid JSON truncated at 100 KB)
16+
- **JSON Editor** — Editable JSON with real-time validation, formatting, and sorting (50 KB write limit)
1517
- **Search** — Highlight matching text across the JSON document
16-
- **Multiple Themes** — Dark, Light, Monokai, Dracula, Solarized Dark
18+
- **Multiple Themes** — Dark, Light, Monokai, Dracula, Solarized Dark (+ custom themes)
1719
- **KMP** — Android, iOS, and JVM Desktop support via Compose Multiplatform
1820

1921
## Installation
@@ -41,76 +43,95 @@ dependencies {
4143

4244
## Quick Start
4345

46+
### JSON Viewer
47+
4448
```kotlin
49+
@OptIn(ExperimentalJsonCmpApi::class)
4550
@Composable
46-
fun MyScreen() {
47-
val state = rememberJsonEditorState(
48-
initialJson = """{"name": "John", "age": 30}""",
51+
fun MyViewer() {
52+
val state = rememberJsonViewerState(
53+
json = """{"name": "John", "age": 30}""",
4954
)
5055

51-
JsonCMP(
56+
JsonViewerCMP(
5257
modifier = Modifier.fillMaxSize(),
5358
state = state,
5459
)
5560
}
5661
```
5762

58-
## Editor Mode
63+
### JSON Editor
5964

6065
```kotlin
66+
@OptIn(ExperimentalJsonCmpApi::class)
6167
@Composable
6268
fun MyEditor() {
6369
val state = rememberJsonEditorState(
6470
initialJson = """{"name": "John", "age": 30}""",
65-
isEditing = true,
6671
)
6772

68-
JsonCMP(
73+
JsonEditorCMP(
6974
modifier = Modifier.fillMaxSize(),
7075
state = state,
71-
onJsonChange = { json, parsed, error ->
72-
// React to JSON changes
73-
},
7476
)
77+
78+
// Observe state reactively — no callbacks needed
79+
// state.json, state.parsedJson, state.error
7580
}
7681
```
7782

7883
## Themes
7984

8085
```kotlin
81-
JsonCMP(
86+
JsonViewerCMP(
8287
state = state,
83-
colors = JsonCmpColors.Monokai, // Dark, Light, Monokai, Dracula, SolarizedDark
88+
theme = JsonTheme.Monokai, // Dark, Light, Monokai, Dracula, SolarizedDark
89+
)
90+
91+
// Or use a custom theme
92+
JsonEditorCMP(
93+
state = editorState,
94+
theme = JsonTheme.Custom(myColors),
8495
)
8596
```
8697

8798
## API
8899

89-
### JsonCMP
100+
### JsonViewerCMP
90101

91102
```kotlin
92103
@Composable
93-
fun JsonCMP(
104+
fun JsonViewerCMP(
94105
modifier: Modifier = Modifier,
95-
state: JsonEditorState,
106+
state: JsonViewerState,
96107
searchQuery: String = "",
97-
colors: JsonCmpColors = JsonCmpColors.Dark,
98-
onJsonChange: (json: String, parsed: JsonNode?, error: JsonError?) -> Unit = { _, _, _ -> },
108+
theme: JsonTheme = JsonTheme.Dark,
99109
)
100110
```
101111

102-
### JsonEditorState
112+
### JsonEditorCMP
103113

104114
```kotlin
105-
val state = rememberJsonEditorState(
106-
initialJson = "...",
107-
isEditing = false,
115+
@Composable
116+
fun JsonEditorCMP(
117+
modifier: Modifier = Modifier,
118+
state: JsonEditorState,
119+
searchQuery: String = "",
120+
theme: JsonTheme = JsonTheme.Dark,
108121
)
122+
```
123+
124+
### State
125+
126+
```kotlin
127+
// Viewer — responds to changes in the json parameter
128+
val viewerState = rememberJsonViewerState(json = "...")
129+
130+
// Editor — initialJson is used once to seed; editor owns its text state
131+
val editorState = rememberJsonEditorState(initialJson = "...")
109132

110-
state.updateRawJson(newJson) // Update JSON content
111-
state.format(compact = false) // Pretty-print or minify
112-
state.sortKeys(ascending = true) // Sort object keys
113-
state.collapseAll() // Collapse all foldable nodes
114-
state.expandAll() // Expand all nodes
115-
state.isEditing = true // Toggle editor mode
133+
// Both expose observable properties:
134+
// state.json — current raw JSON text
135+
// state.parsedJson — parsed JsonNode tree, or null if invalid
136+
// state.error — parse error, or null if valid
116137
```

0 commit comments

Comments
 (0)