web-component 增强,支持多种数据类型作为参数,支持事件
- Dominant language
- TypeScript
- Stars
- 18.9k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
## 概述
web-component 增强
- 支持多种类型的 props 参数,不仅仅是字符串参数
- 支持事件的捕获
- 支持具名插槽
## 动机
当作为 SDK 方式使用 amis 时,可将其他工具例如 stencil 或 svelte 编译,较为复杂的 web-component 更加方便的引入进来;
可直接传入数组、对象,避免使用 custom 组件在 onMount() 函数中进行初始化,仅需 json 即可正常使用该组件,让 amis 生态和扩展性更强;
实现该目标,工作量较小,无兼容性问题;
## 示例
```json
{
"type": "web-component",
"tag": "user-defined-svelte-component",
"props": {
"title": "const text",
"number": "${number_var}",
"object": "${obj_var}",
"user_obj": {
"name": "object prop from json"
},
"list": [
{ "name": "user from amis -0 1" }
]
},
"onEvent": {
"custom-dom-event-name": {}
}
"body": [
{
"type": "html",
"slot": "slot-name",
"body": "named slot here"
},
{
"type": "html",
"body": "default slot here"
}
]
}
```
## 详细设计
可选。
## 缺陷
暂无。
## 替代选择
使用 custom 组件虽可完成初始化和多种类型的 props 传递, 但对 slot 不支持:
```javascript
{
type: 'custom',
onMount: (dom, value, onChange) => {
const ele = document.createElement('user-defined-svelte-component');
ele.title_string = "custom component "// + value.name;
ele.object = value.obj_var,
ele.user_obj = {
"name": "object prop from js"
};
ele.list = [
{ "name": "user from amis custom component - 1" }
];
dom.appendChild(ele);
}
}
```
## 适配策略
兼容以前的接口和使用策略,无兼容适配问题
Contributor guide
No contributing guide indexed for this repository
Research direction
No files, tests, or entry points are named. Start by locating the existing web-component implementation and compare its current prop, event, and slot handling with the JSON example; done means supporting non-string props, event capture, and named slots while preserving existing interfaces.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100