Skip to content

Commit cee2ccb

Browse files
committed
feat: update skill component props and event binding rules
1 parent e39da95 commit cee2ccb

8 files changed

Lines changed: 343 additions & 798 deletions

File tree

.agents/skills/tinyengine-dsl-generator/SKILL.md

Lines changed: 97 additions & 603 deletions
Large diffs are not rendered by default.

.agents/skills/tinyengine-dsl-generator/references/components.md

Lines changed: 10 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ interface TinyInputProps {
6464
"modelValue": {
6565
"type": "JSExpression",
6666
"value": "this.state.inputText",
67-
"model": true // 必须设置为 true
67+
"model": true // 标准双向绑定 (v-model)
6868
}
6969

7070
// ⚠️ 事件绑定示例:
@@ -189,14 +189,14 @@ interface TinyFormProps {
189189
"modelValue": {
190190
"type": "JSExpression",
191191
"value": "this.state.formData",
192-
"model": true // 必须设置为 true
192+
"model": true // 标准双向绑定 (v-model)
193193
}
194194

195195
// ⚠️ 表单内输入框双向绑定:
196196
"modelValue": {
197197
"type": "JSExpression",
198198
"value": "this.state.formData.name",
199-
"model": true // 必须设置为 true,而不是 { "prop": "name" }
199+
"model": true // 标准双向绑定用 true;{prop} 仅用于具名 v-model (v-model:xxx)
200200
}
201201

202202
// 表单验证示例:
@@ -460,155 +460,15 @@ interface TinyPieChartProps {
460460

461461
## 组件查询
462462

463-
当需要查找特定组件时,使用以下模式搜索 bundle.json:
463+
不要手动 grep bundle.json(≈1MB)。用查询脚本
464464

465465
```bash
466-
# 查找组件
467-
grep -A 20 '"component": "ComponentName"' bundle.json
468-
469-
# 查找分类
470-
grep '"category"' bundle.json | sort | uniq
471-
```
472-
473-
## 注意事项
474-
475-
1. **保留字**: Page, Block, Component, Template, Slot, Collection, Text 不应用作组件名
476-
2. **事件绑定**: 事件名以 `on` 开头,如 `onClick`, `onChange`,使用 `JSExpression` 引用方法
477-
3. **双向绑定**: 使用 `modelValue` 属性配合 `type: "JSExpression"`,并设置 `model: true`
478-
4. **样式**: 优先使用 `className` 引用 CSS 类,内联样式用 `style` 属性
479-
480-
## 常见问题排查
481-
482-
### 问题:输入框无法输入
483-
484-
**检查**:
485-
486-
- `modelValue` 中是否包含 `model: true`
487-
- 绑定的 state 变量是否存在
488-
489-
```json
490-
// ✅ 正确配置
491-
"modelValue": {
492-
"type": "JSExpression",
493-
"value": "this.state.inputText",
494-
"model": true // 必须有这个
495-
}
496-
```
497-
498-
### 问题:事件不触发
499-
500-
**检查**:
501-
502-
1. 是否使用 `JSExpression` 而非 `JSFunction`
503-
2. 方法名是否正确
504-
3. 方法是否在 `methods` 中定义
505-
506-
```json
507-
// ❌ 错误
508-
"onClick": {
509-
"type": "JSFunction",
510-
"value": "function() { this.handleClick(); }"
511-
}
512-
513-
// ✅ 正确
514-
"methods": {
515-
"handleClick": {
516-
"type": "JSFunction",
517-
"value": "function(event) { /* 处理逻辑 */ }"
518-
}
519-
},
520-
"onClick": {
521-
"type": "JSExpression",
522-
"value": "this.handleClick"
523-
}
524-
```
525-
526-
### 问题:页面无法编辑
527-
528-
**检查**: `occupier` 是否为 `null`
529-
530-
```json
531-
// ✅ 页面可编辑
532-
{
533-
"componentName": "Page",
534-
"occupier": null, // 必须是 null
535-
...
536-
}
466+
node scripts/query_components.mjs props TinyButton # 某组件的属性表(模糊匹配)
467+
node scripts/query_components.mjs list # 全部组件
468+
node scripts/query_components.mjs cat 表单 # 某分类下的组件
469+
node scripts/query_components.mjs search 表格 # 全字段搜索
537470
```
538471

539-
### 问题:参数传递错误
472+
## 常见问题与规则
540473

541-
**检查**:
542-
543-
1. 方法第一个参数是否为 `event`
544-
2. `params` 中的参数是否正确追加
545-
546-
```json
547-
// 方法定义 - 第一个参数是 event
548-
"methods": {
549-
"handleDelete": {
550-
"type": "JSFunction",
551-
"value": "function(event, id) { /* event 和 id 都可用 */ }"
552-
}
553-
}
554-
555-
// 事件绑定
556-
"onClick": {
557-
"type": "JSExpression",
558-
"value": "this.handleDelete",
559-
"params": ["123"] // 实际调用: handleDelete(event, 123)
560-
}
561-
```
562-
563-
### 问题:CSS 样式不生效
564-
565-
**检查**:
566-
567-
- 类名是否正确引用
568-
569-
```json
570-
// ✅ 正确的 CSS 格式
571-
"css": ".container {\n padding: 20px;\n background: #fff;\n}\n\n.title {\n font-size: 18px;\n}"
572-
```
573-
574-
### 问题:生命周期不执行
575-
576-
**检查**:
577-
578-
- 生命周期名是否以 `on` 开头(除 `setup` 外)
579-
- 函数体是否完整
580-
581-
```json
582-
// ✅ 正确的生命周期配置
583-
"lifeCycles": {
584-
"onMounted": {
585-
"type": "JSFunction",
586-
"value": "function onMounted() { this.loadData(); }"
587-
},
588-
"setup": {
589-
"type": "JSFunction",
590-
"value": "function setup({ props, state, watch }) { /* setup 逻辑 */ }"
591-
}
592-
}
593-
```
594-
595-
### 问题:条件渲染不工作
596-
597-
**检查**:
598-
599-
- `condition` 是否使用 `JSExpression`
600-
- 条件表达式是否返回布尔值
601-
602-
```json
603-
// ✅ 正确的条件渲染
604-
{
605-
"componentName": "div",
606-
"props": {
607-
"condition": {
608-
"type": "JSExpression",
609-
"value": "this.state.items.length > 0"
610-
}
611-
},
612-
"children": [...]
613-
}
614-
```
474+
通用规则(事件绑定、双向绑定 `model``occupier``className`、生命周期、参数传递)的精简表见 [SKILL.md](../SKILL.md)「Critical Rules / Troubleshooting」;完整 ❌/✅ 示例与 TS 接口见 [protocol.md](protocol.md);条件渲染 / 循环渲染等模式见 [patterns.md](patterns.md)。本文件专注于各组件的 props/events 参考。

.agents/skills/tinyengine-dsl-generator/references/patterns.md

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
{
8383
"componentName": "TinyForm",
8484
"props": {
85-
"modelValue": {
85+
"model": {
8686
"type": "JSExpression",
8787
"value": "this.state.searchForm"
8888
},
@@ -210,7 +210,7 @@
210210
"componentName": "TinyForm",
211211
"props": {
212212
"ref": "formRef",
213-
"modelValue": {
213+
"model": {
214214
"type": "JSExpression",
215215
"value": "this.state.formData"
216216
},
@@ -286,36 +286,7 @@
286286

287287
## 常见交互模式
288288

289-
### 事件绑定基础规则
290-
291-
**重要**: 事件绑定必须使用 `JSExpression` 引用 methods 中定义的方法,不能直接使用 `JSFunction`
292-
293-
❌ 错误示例:
294-
295-
```json
296-
"onClick": {
297-
"type": "JSFunction",
298-
"value": "function() { this.handleClick(); }"
299-
}
300-
```
301-
302-
✅ 正确示例:
303-
304-
```json
305-
// methods 中定义
306-
"methods": {
307-
"handleClick": {
308-
"type": "JSFunction",
309-
"value": "function(event) { /* 处理点击逻辑 */ }"
310-
}
311-
}
312-
313-
// 事件绑定
314-
"onClick": {
315-
"type": "JSExpression",
316-
"value": "this.handleClick"
317-
}
318-
```
289+
> **事件绑定规则**: 事件必须用 `JSExpression` 引用 `methods` 中的方法,不能用 `JSFunction``value` 里也不准写函数体。完整 ❌/✅ 见 [SKILL.md](../SKILL.md)「Critical Rules」与 [protocol.md](protocol.md)。下面只给模板。
319290
320291
### 事件参数传递
321292

@@ -416,7 +387,7 @@
416387
{
417388
"componentName": "TinyForm",
418389
"props": {
419-
"modelValue": {
390+
"model": {
420391
"type": "JSExpression",
421392
"value": "this.state.dialogForm"
422393
}
@@ -837,8 +808,9 @@
837808
"text": "编辑",
838809
"size": "small",
839810
"onClick": {
840-
"type": "JSFunction",
841-
"value": "function() { this.handleEdit(row); }"
811+
"type": "JSExpression",
812+
"value": "this.handleEdit",
813+
"params": ["row"]
842814
}
843815
},
844816
"id": "btn-edit"
@@ -938,6 +910,12 @@
938910
}
939911
}
940912
},
913+
"methods": {
914+
"handleConfirm": {
915+
"type": "JSFunction",
916+
"value": "function(event) { this.emit('confirm'); }"
917+
}
918+
},
941919
"children": [
942920
{
943921
"componentName": "div",
@@ -974,7 +952,7 @@
974952
"text": "确认",
975953
"onClick": {
976954
"type": "JSExpression",
977-
"value": "function() { this.emit('confirm'); }"
955+
"value": "this.handleConfirm"
978956
}
979957
}
980958
}

.agents/skills/tinyengine-dsl-generator/scripts/check_css.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* 检查DSL中的CSS字段是否有语法错误(基础模式:括号匹配、基本语法,无需额外依赖)。
66
*
7-
* Node.js port of check_css.py 的 basic 模式 —— 行为保持一致,零依赖
7+
* 零依赖(仅用 Node 标准库)
88
* (原 tinycss2 / postcss 模式依赖外部环境,已精简;basic 是默认且为编排脚本使用的模式。)
99
*/
1010

.agents/skills/tinyengine-dsl-generator/scripts/check_event_bindings.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 检查DSL文件中的事件绑定是否正确使用JSExpression引用方法,
66
* 而不是在value中直接写函数定义。
77
*
8-
* Node.js port of check_event_bindings.py — 行为保持一致,零依赖
8+
* 零依赖(仅用 Node 标准库)
99
*/
1010

1111
import fs from 'node:fs';

0 commit comments

Comments
 (0)