Skip to content

Commit 4ad516d

Browse files
committed
feat(harmonyos): update ArkUiFlow design method and add ArkUiLayoutType and ArkUiComponentType
1 parent a6ef010 commit 4ad516d

File tree

8 files changed

+84
-14
lines changed

8 files changed

+84
-14
lines changed

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/AutoArkUiAction.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package cc.unitmesh.harmonyos.actions
33
import cc.unitmesh.devti.gui.sendToChatPanel
44
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
55
import cc.unitmesh.devti.llms.LlmFactory
6-
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiContext
7-
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiFlow
8-
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiTask
6+
import cc.unitmesh.harmonyos.actions.auto.*
97
import com.intellij.openapi.editor.Editor
108
import com.intellij.openapi.progress.ProgressManager
119
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
@@ -26,7 +24,11 @@ class AutoArkUiAction : ChatBaseIntention() {
2624
if (editor == null || file == null) return
2725
val selectedText = editor.selectionModel.selectedText ?: return
2826

29-
val context = AutoArkUiContext(selectedText)
27+
val context = AutoArkUiContext(
28+
selectedText,
29+
layoutOverride = ArkUiLayoutType.overview(),
30+
componentOverride = ArkUiComponentType.overview(),
31+
)
3032

3133
sendToChatPanel(project) { contentPanel, _ ->
3234
val llmProvider = LlmFactory().create(project)

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/ArkUiComponentType.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.unitmesh.harmonyos.actions.auto
22

3-
enum class ArkUiComponentType(description: String, example: String) {
3+
enum class ArkUiComponentType(val description: String, val example: String) {
44
Button(
55
"可快速创建不同样式的按钮。", "Button('Ok', { type: ButtonType.Normal, stateEffect: true }) \n" +
66
" .borderRadius(8) \n" +
@@ -150,5 +150,21 @@ enum class ArkUiComponentType(description: String, example: String) {
150150
" })\n" +
151151
" return true\n" +
152152
" })"
153-
)
153+
);
154+
155+
companion object {
156+
fun overview(): String {
157+
return ArkUiComponentType.values().joinToString("\n") {
158+
it.name + ":" + it.description
159+
}
160+
}
161+
162+
fun tryFormat(it: String): String? {
163+
return try {
164+
valueOf(it).example
165+
} catch (e: Exception) {
166+
null
167+
}
168+
}
169+
}
154170
}

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/LayoutType.kt renamed to exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/ArkUiLayoutType.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.unitmesh.harmonyos.actions.auto
22

3-
enum class LayoutType(val description: String, val example: String) {
3+
enum class ArkUiLayoutType(val description: String, val example: String) {
44
FlexLayout(
55
"弹性布局(Flex)提供更加有效的方式对容器中的子元素进行排列、对齐和分配剩余空间。",
66
"Column({ space: 5 }) {\n" +
@@ -100,5 +100,21 @@ enum class LayoutType(val description: String, val example: String) {
100100
" .borderRadius(15)\n" +
101101
" }.width('100%').height('100%').backgroundColor('#CFD0CF')\n" +
102102
"}"
103-
)
103+
);
104+
105+
companion object {
106+
fun overview(): String {
107+
return ArkUiLayoutType.values().joinToString("\n") {
108+
it.name + ":" + it.description
109+
}
110+
}
111+
112+
fun tryFormat(name: String): String? {
113+
return try {
114+
valueOf(name).example
115+
} catch (e: IllegalArgumentException) {
116+
null
117+
}
118+
}
119+
}
104120
}

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/AutoArkUiContext.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ data class AutoArkUiContext(
44
val requirement: String,
55
val layoutOverride: String,
66
val componentOverride: String,
7-
val layouts: List<String> = emptyList(),
8-
val components: List<String> = emptyList(),
7+
var elements: List<String> = emptyList(),
98
)

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/AutoArkUiFlow.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
3333

3434

3535
override fun design(context: Any): List<String> {
36-
val componentList = context as List<ArkUiComponentType>
36+
val componentList = context as List<String>
3737
val stepTwoPrompt = generateStepTwoPrompt(componentList)
3838

3939
panel.addMessage(stepTwoPrompt, true, stepTwoPrompt)
@@ -45,11 +45,14 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
4545
}.let { listOf(it) }
4646
}
4747

48-
private fun generateStepTwoPrompt(selectedComponents: List<ArkUiComponentType>): String {
48+
private fun generateStepTwoPrompt(selectedComponents: List<String>): String {
4949
val templateRender = TemplateRender("genius/harmonyos")
5050
val template = templateRender.getTemplate("arkui-design.vm")
5151

52-
// context.pages = selectedComponents.map { it.format() }
52+
context.elements = selectedComponents.mapNotNull {
53+
ArkUiLayoutType.tryFormat(it) ?: ArkUiComponentType.tryFormat(it)
54+
}
55+
5356
templateRender.context = context
5457

5558
val prompter = templateRender.renderTemplate(template)

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/AutoArkUiTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class AutoArkUiTask(
2222

2323
indicator.fraction = 0.6
2424
indicator.text = AutoDevBundle.message("autopage.generate.design")
25+
flow.design(componentNames)
2526

2627
indicator.fraction = 0.8
2728

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
You are a professional Legacy System migration expert, specif in frontend.
2+
You are working on migration code to ArkUi, a new frontend DSL UI framework with a lot of components and layouts.
3+
According to the user's code/requirements, and Layout/Components info, write Code for the user.
4+
5+
- ArkUi Layout/Components Infos: ${context.elements}
6+
7+
For example:
8+
9+
- User requirements: "a ArkUi Hello, World"
10+
// component info: Row({ space: 35 }) { /*...*/}.width('90%')
11+
// component info: Button('Ok', { type: ButtonType.Normal, stateEffect: true }),
12+
- Answer:
13+
```TypeScript
14+
Row() {
15+
Column() {
16+
Text(this.message)
17+
.fontSize(50)
18+
.fontWeight(FontWeight.Bold)
19+
}
20+
.width('100%')
21+
}
22+
.height('100%')
23+
```
24+
25+
----
26+
27+
Here are the requirements:
28+
29+
```markdown
30+
${context.requirement}
31+
```
32+
33+
Please write your code with Markdown syntax, no explanation is needed:
34+

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPageTask.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ class AutoPageTask(
2929
flow.design(filterComponents)
3030

3131
indicator.fraction = 0.8
32-
3332
}
3433
}

0 commit comments

Comments
 (0)