Skip to content

Commit 991bb06

Browse files
authored
Merge pull request #233 from JetBrains/alpha-compose-stage
2 parents 96f0d75 + 280ab3d commit 991bb06

File tree

61 files changed

+3044
-1996
lines changed

Some content is hidden

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

61 files changed

+3044
-1996
lines changed

.github/workflows/e2e.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ jobs:
2626

2727
steps:
2828
# prepare core binaries
29-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
3030

3131
- name: Install Node.js
32-
uses: actions/setup-node@v3
32+
uses: actions/setup-node@v4
3333
with:
34-
node-version: lts/*
34+
node-version: 20
3535
cache: 'yarn'
3636

3737
- name: Install dependencies
38-
run: yarn
38+
run: yarn install --frozen-lockfile # optional, --immutable
3939

4040
# run lint
4141
- name: Run tests
@@ -49,7 +49,7 @@ jobs:
4949
echo version=$(npm info @playwright/test version) >> $GITHUB_OUTPUT
5050
5151
- name: Cache Playwright binaries
52-
uses: actions/cache@v3
52+
uses: actions/cache@v4
5353
id: playwright-cache
5454
with:
5555
path: |
@@ -75,12 +75,13 @@ jobs:
7575
- name: Run tests
7676
run: TEST_PROJECT_LIST="${{matrix.TEST_PROJECT_LIST}}" yarn test
7777

78-
- uses: actions/upload-artifact@v3
78+
- uses: actions/upload-artifact@v4
7979
if: failure()
8080
with:
81-
name: playwright-report
81+
name: "playwright-report-${{ matrix.os }}"
8282
path: |
8383
test-results/
8484
playwright-report/
8585
tests/**/__screenshots__/github_*
8686
retention-days: 5
87+
compression-level: 9

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

examples.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,120 @@ fun main(args: Array<String>) {
136136

137137
</div>
138138

139+
You can use Compose Wasm.
140+
141+
```html
142+
<div class="kotlin-code" data-target-platform="compose-wasm"></div>
143+
```
144+
<div class="kotlin-code" data-target-platform="compose-wasm">
145+
146+
```kotlin
147+
import androidx.compose.ui.ExperimentalComposeUiApi
148+
import androidx.compose.ui.window.CanvasBasedWindow
149+
import androidx.compose.animation.AnimatedVisibility
150+
import androidx.compose.foundation.Image
151+
import androidx.compose.foundation.layout.Column
152+
import androidx.compose.foundation.layout.fillMaxWidth
153+
import androidx.compose.material.Button
154+
import androidx.compose.material.MaterialTheme
155+
import androidx.compose.material.Text
156+
import androidx.compose.runtime.Composable
157+
import androidx.compose.runtime.getValue
158+
import androidx.compose.runtime.mutableStateOf
159+
import androidx.compose.runtime.remember
160+
import androidx.compose.runtime.setValue
161+
import androidx.compose.ui.Alignment
162+
import androidx.compose.ui.Modifier
163+
164+
//sampleStart
165+
@OptIn(ExperimentalComposeUiApi::class)
166+
fun main() {
167+
CanvasBasedWindow { App() }
168+
}
169+
170+
@Composable
171+
fun App() {
172+
MaterialTheme {
173+
var greetingText by remember { mutableStateOf("Hello World!") }
174+
var showImage by remember { mutableStateOf(false) }
175+
var counter by remember { mutableStateOf(0) }
176+
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
177+
Button(onClick = {
178+
counter++
179+
greetingText = "Compose: ${Greeting().greet()}"
180+
showImage = !showImage
181+
}) {
182+
Text(greetingText)
183+
}
184+
AnimatedVisibility(showImage) {
185+
Text(counter.toString())
186+
}
187+
}
188+
}
189+
}
190+
191+
private val platform = object : Platform {
192+
193+
override val name: String
194+
get() = "Web with Kotlin/Wasm"
195+
}
196+
197+
fun getPlatform(): Platform = platform
198+
199+
class Greeting {
200+
private val platform = getPlatform()
201+
202+
fun greet(): String {
203+
return "Hello, ${platform.name}!"
204+
}
205+
}
206+
207+
interface Platform {
208+
val name: String
209+
}
210+
//sampleEnd
211+
212+
```
213+
214+
</div>
215+
216+
217+
You can try Kotlin export to Swift.
218+
219+
```html
220+
<div class="kotlin-code" data-target-platform="swift-export" data-version="2.0.0-RC3"></div>
221+
```
222+
<div class="kotlin-code" data-target-platform="swift-export" data-version="2.0.0-RC3">
223+
224+
```kotlin
225+
fun mul(a: Int, b: Int): Int {
226+
return a * b
227+
}
228+
229+
fun main(args: Array<String>) {
230+
print(mul(-2, 4))
231+
println(" + 7 =")
232+
print(mul(-2, 4) + 7)
233+
}
234+
```
235+
236+
</div>
237+
238+
<div class="kotlin-code" data-target-platform="swift-export" data-version="2.0.0-RC3" theme="kotlin-docs">
239+
240+
```kotlin
241+
fun mul(a: Int, b: Int): Int {
242+
return a * b
243+
}
244+
245+
fun main(args: Array<String>) {
246+
print(mul(-2, 4))
247+
println(" + 7 =")
248+
print(mul(-2, 4) + 7)
249+
}
250+
```
251+
252+
</div>
139253

140254
Use `data-target-platform` attribute with value `junit` for creating examples with tests:
141255

package.json

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kotlin-playground",
3-
"version": "1.30.0",
3+
"version": "1.32.0",
44
"description": "Self-contained component to embed in websites for running Kotlin code",
55
"keywords": [
66
"kotlin",
@@ -15,38 +15,38 @@
1515
"!dist/REMOVE_ME.js*"
1616
],
1717
"devDependencies": {
18-
"@babel/cli": "^7.21.5",
19-
"@babel/core": "^7.22.1",
20-
"@babel/plugin-transform-runtime": "~7.22.4",
21-
"@babel/preset-env": "~7.22.4",
22-
"@babel/runtime-corejs2": "~7.22.2",
23-
"@playwright/test": "^1.40.1",
24-
"@typescript-eslint/eslint-plugin": "^6.4.0",
25-
"@typescript-eslint/parser": "^6.4.0",
26-
"babel-loader": "^9.1.3",
18+
"@babel/cli": "^7.25.9",
19+
"@babel/core": "^7.25.9",
20+
"@babel/plugin-transform-runtime": "^7.25.9",
21+
"@babel/preset-env": "^7.25.9",
22+
"@babel/runtime-corejs2": "^7.25.9",
23+
"@playwright/test": "^1.48.1",
24+
"@typescript-eslint/eslint-plugin": "^6.21.0",
25+
"@typescript-eslint/parser": "^6.21.0",
26+
"babel-loader": "^9.2.1",
2727
"babel-plugin-async-to-promises": "^1.0.5",
2828
"ci-publish": "^1.3.1",
29-
"codemirror": "^5.49.0",
29+
"codemirror": "^5.65.18",
3030
"css-loader": "^6.8.1",
3131
"debounce": "^1.2.0",
3232
"deepmerge": "^1.5.0",
33-
"dotenv": "^16.3.1",
33+
"dotenv": "^16.4.5",
3434
"es6-promise": "^4.2.6",
3535
"es6-set": "^0.1.5",
3636
"escape-html": "^1.0.3",
37-
"eslint": "^8.47.0",
38-
"eslint-config-prettier": "^9.0.0",
39-
"eslint-plugin-import": "^2.28.0",
40-
"eslint-plugin-prettier": "^5.0.1",
37+
"eslint": "^8.57.1",
38+
"eslint-config-prettier": "^9.1.0",
39+
"eslint-plugin-import": "^2.31.0",
40+
"eslint-plugin-prettier": "^5.2.1",
4141
"fast-async": "7",
4242
"fast-deep-equal": "^3.1.3",
4343
"file-loader": "^6.2.0",
4444
"flatten": "^1.0.2",
4545
"github-markdown-css": "^3.0.1",
46-
"html-webpack-plugin": "^5.5.3",
46+
"html-webpack-plugin": "^5.6.3",
4747
"husky": "^8.0.3",
4848
"is-empty-object": "^1.1.1",
49-
"lint-staged": "^15.0.2",
49+
"lint-staged": "^15.2.10",
5050
"lz-string": "^1.4.4",
5151
"markdown-it": "^12.3.2",
5252
"markdown-it-highlightjs": "^3.0.0",
@@ -55,23 +55,23 @@
5555
"monkberry-directives": "4.0.8",
5656
"monkberry-events": "4.0.8",
5757
"monkberry-loader": "4.0.9",
58-
"postcss": "^8.4.31",
59-
"postcss-loader": "^7.3.3",
60-
"prettier": "^3.0.3",
58+
"postcss": "^8.4.47",
59+
"postcss-loader": "^7.3.4",
60+
"prettier": "^3.3.3",
6161
"query-string": "^6.5.0",
62-
"sass": "^1.66.0",
63-
"sass-loader": "^13.3.2",
62+
"sass": "^1.80.4",
63+
"sass-loader": "^13.3.3",
6464
"shelljs": "^0.8.3",
65-
"style-loader": "^3.3.3",
65+
"style-loader": "^3.3.4",
6666
"svg-fill-loader": "^0.0.8",
6767
"svg-url-loader": "^8.0.0",
68-
"ts-loader": "^9.4.4",
69-
"typescript": "^5.1.6",
68+
"ts-loader": "^9.5.1",
69+
"typescript": "^5.6.3",
7070
"url-search-params": "1.1.0",
71-
"webpack": "^5.88.2",
71+
"webpack": "^5.91.0",
7272
"webpack-cli": "^5.1.4",
73-
"webpack-dev-server": "^4.15.1",
74-
"whatwg-fetch": "^3.0.0"
73+
"webpack-dev-server": "^4.15.2",
74+
"whatwg-fetch": "^3.6.20"
7575
},
7676
"scripts": {
7777
"build": "webpack",
@@ -80,12 +80,13 @@
8080
"copy-examples": "node utils/copy-examples",
8181
"release:ci": "rm -rf dist && npm run build:all && $NPM_TOKEN=%env.NPM_TOKEN% npm publish",
8282
"start": "webpack-dev-server --port 9002",
83-
"start-with-local-compiler": "webpack-dev-server --port 9002 --env webDemoUrl='//localhost:8080'",
83+
"start-with-local-compiler": "webpack-dev-server --port 9002 --env webDemoUrl='//localhost:8080' webDemoResourcesUrl='//localhost:8081'",
8484
"lint": "eslint . --ext .ts",
8585
"fix": "eslint --fix --ext .ts .",
8686
"test": "npm run build:all && npm run test:run",
8787
"test:run": "playwright test",
88-
"test:server": "node tests/utlis/server/index.js",
88+
"test:server": "node tests/utils/server/index.js",
8989
"prepare": "husky install"
90-
}
90+
},
91+
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
9192
}

src/config.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import {getConfigFromElement, getCurrentScript} from './utils';
2-
import {TargetPlatforms} from "./utils/platforms";
1+
import { getConfigFromElement, getCurrentScript } from './utils';
2+
import { TargetPlatforms } from './utils/platforms';
33

44
const currentScript = getCurrentScript();
55

6-
export const RUNTIME_CONFIG = {...getConfigFromElement(currentScript)};
6+
export const RUNTIME_CONFIG = { ...getConfigFromElement(currentScript) };
77

88
/**
99
* API Paths
1010
*
1111
* @type {{COMPILE: string, COMPLETE: string, VERSIONS: string, JQUERY: string, KOTLIN_JS: string}}
1212
*/
1313
export const API_URLS = {
14-
server: RUNTIME_CONFIG.server || __WEBDEMO_URL__,
14+
server: (RUNTIME_CONFIG.server || __WEBDEMO_URL__).replace(/\/$/, ''),
15+
composeServer: 'https://compose-stage.sandbox.intellij.net'.replace(
16+
/\/$/,
17+
'',
18+
),
19+
1520
COMPILE(platform, version) {
1621
let url;
1722

@@ -31,11 +36,17 @@ export const API_URLS = {
3136
case TargetPlatforms.WASM:
3237
url = `${this.server}/api/${version}/compiler/translate?ir=true&compiler=wasm`;
3338
break;
39+
case TargetPlatforms.COMPOSE_WASM:
40+
url = `${this.composeServer}/api/compiler/translate?compiler=${TargetPlatforms.COMPOSE_WASM.id}`;
41+
break;
3442
case TargetPlatforms.JUNIT:
3543
url = `${this.server}/api/${version}/compiler/test`;
3644
break;
45+
case TargetPlatforms.SWIFT_EXPORT:
46+
url = `${this.server}/api/${version}/${TargetPlatforms.SWIFT_EXPORT.id}/compiler/translate?compiler=swift-export`;
47+
break;
3748
default:
38-
console.warn(`Unknown ${platform.id} , used by default JVM`)
49+
console.warn(`Unknown ${platform.id} , used by default JVM`);
3950
url = `${this.server}/api/${version}/compiler/run`;
4051
break;
4152
}
@@ -52,12 +63,27 @@ export const API_URLS = {
5263
get VERSIONS() {
5364
return `${this.server}/versions`;
5465
},
66+
RESOURCE_VERSIONS() {
67+
return `${this.composeServer}/api/resource/compose-wasm-versions`;
68+
},
69+
SKIKO_MJS(version) {
70+
return `${this.composeServer}/api/resource/skiko-${version}.mjs`;
71+
},
72+
SKIKO_WASM(version) {
73+
return `${this.composeServer}/api/resource/skiko-${version}.wasm`;
74+
},
75+
STDLIB_MJS(hash) {
76+
return `${this.composeServer}/api/resource/stdlib-${hash}.mjs`;
77+
},
78+
STDLIB_WASM(hash) {
79+
return `${this.composeServer}/api/resource/stdlib-${hash}.wasm`;
80+
},
5581
get JQUERY() {
5682
return `https://cdn.jsdelivr.net/npm/jquery@1/dist/jquery.min.js`;
5783
},
5884
get KOTLIN_JS() {
5985
return `https://cdn.jsdelivr.net/npm/kotlin@`;
60-
}
86+
},
6187
};
6288

6389
/**
@@ -70,5 +96,5 @@ export default {
7096
* Will be calculated according to user defined `data-min-compiler-version`
7197
* attribute and WebDemo API response
7298
*/
73-
compilerVersion: undefined
74-
}
99+
compilerVersion: undefined,
100+
};

0 commit comments

Comments
 (0)