Skip to content

Commit 49c2c25

Browse files
committed
fix: add protocol docs
1 parent 12c2b8d commit 49c2c25

File tree

4 files changed

+251
-54
lines changed

4 files changed

+251
-54
lines changed

README.md

+31-9
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,51 @@ This repo is documentation site for [netease/tango](https://github.com/NetEase/t
44

55
Site link: <https://netease.github.io/tango-site/>
66

7-
### Installation
7+
## Installation
88

9-
```
10-
$ yarn
9+
```bash
10+
yarn
1111
```
1212

13-
### Local Development
13+
## Local Development
1414

15-
```
16-
$ yarn start
15+
```bash
16+
yarn start
1717
```
1818

1919
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
2020

21-
### Build
21+
### i18n
22+
23+
Translate plugin data
24+
25+
```bash
26+
npm run write-translations -- --locale zh-Hans
27+
```
28+
29+
Translate docs
2230

31+
```bash
32+
mkdir -p i18n/zh-Hans/docusaurus-plugin-content-docs/current
33+
cp -r docs/** i18n/zh-Hans/docusaurus-plugin-content-docs/current
2334
```
24-
$ yarn build
35+
36+
Translate blog
37+
38+
```bash
39+
mkdir -p i18n/zh-Hans/docusaurus-plugin-content-blog
40+
cp -r blog/** i18n/zh-Hans/docusaurus-plugin-content-blog
41+
```
42+
43+
## Build
44+
45+
```bash
46+
yarn build
2547
```
2648

2749
This command generates static content into the `build` directory and can be served using any static contents hosting service.
2850

29-
### Deployment
51+
## Deployment
3052

3153
Using SSH:
3254

docs/protocol/prototype.mdx

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# 组件配置协议
2+
3+
组件配置协议是附加在组件包上的一层额外描述文件,Tango 设计器将会借助这个配置文件为选中的组件渲染配置面板。
4+
5+
## 组件描述
6+
7+
请参考 [IComponentPrototype](https://netease.github.io/tango/interfaces/_music163_tango_helpers.IComponentPrototype.html)
8+
9+
## 组件属性描述
10+
11+
请参考 [IComponentProps](https://netease.github.io/tango/interfaces/_music163_tango_helpers.IComponentProp.html)
12+
13+
### 嵌套属性
14+
15+
当某个组件属性为嵌套属性时,例如 `<Table scroll={{ x: 800, y: 400 }} />`,此时可以描述如下:
16+
17+
```js
18+
{
19+
name: 'Table',
20+
props: [
21+
{
22+
name: 'scroll',
23+
props: [
24+
{
25+
name: 'x',
26+
setter: 'numberSetter',
27+
},
28+
{
29+
name: 'y',
30+
setter: 'numberSetter',
31+
}
32+
],
33+
}
34+
],
35+
}
36+
```
37+
38+
### 属性的按需展示
39+
40+
当某个属性依赖某个特定的其他属性值时,可以借助 `getVisible` 实现关联展示控制:
41+
42+
```js
43+
{
44+
name: 'Button',
45+
props: [
46+
{
47+
name: 'shape',
48+
},
49+
{
50+
name: 'buttonType',
51+
getVisible: (form) => {
52+
// 配置项 buttonType 仅在配置项 shape 的值为 button 时才展示
53+
return form.getValue('shape') === 'button';
54+
},
55+
},
56+
];
57+
}
58+
```
59+
60+
### 函数模板
61+
62+
当某个属性为函数类型时,且希望在 eventSetter 中快捷生成函数的模板代码时,可以使用 `template` 属性指定
63+
64+
```js
65+
{
66+
name: 'Button',
67+
props: [
68+
{
69+
name: 'shape',
70+
},
71+
{
72+
name: 'onClick',
73+
setter: 'eventSetter',
74+
// {{content}} 为插值变量,会被替换为用户输入的内容,或选定的变量
75+
template: '(e) => {\n {{content}}\n}',
76+
},
77+
];
78+
}
79+
```
80+
81+
### 自定义渲染列表
82+
83+
或某个属性为 renderProps 类型时,可以借助 `options` 属性配置 renderProps 的渲染函数模板
84+
85+
```js
86+
{
87+
name: 'CustomCard',
88+
props: [
89+
{
90+
name: 'renderExtra',
91+
title: 'extra自定义渲染',
92+
setter: 'renderSetter',
93+
options: [
94+
{
95+
label: '占位空间',
96+
value: 'Box',
97+
// 自定义渲染代码
98+
render: '() => <Box>test</Box>',
99+
// 自定义渲染代码需要额外引入的组件
100+
relatedImports: ['Box'],
101+
},
102+
{
103+
label: '占位文本',
104+
value: 'Text',
105+
render: '() => <Text>text</Text>',
106+
relatedImports: ['Text'],
107+
},
108+
],
109+
},
110+
];
111+
}
112+
```
113+
114+
### 动态属性的展示
115+
116+
当组件需要依据某个属性值进行动态设置其他属性时,可以借助 `getProp` 实现控制:
117+
118+
```js
119+
{
120+
name: 'FormItem',
121+
props: [
122+
{
123+
name: 'component',
124+
title: '控件类型',
125+
},
126+
{
127+
name: 'componentProps',
128+
title: '子组件属性',
129+
getProp(form) {
130+
const type = form.getValue('component');
131+
const proto = { ...componentMap[type] };
132+
const props = omitProps(proto.props, [
133+
'placeholder',
134+
'options',
135+
'onChange',
136+
'defaultValue',
137+
'value',
138+
]);
139+
return {
140+
title: proto.title + '属性',
141+
props,
142+
};
143+
},
144+
}
145+
],
146+
}
147+
```
148+
149+
### 属性的补全提示
150+
151+
当某个属性在输入时需要进行输入提示时,例如某个函数属性需要提示其签名的模版,则可以借助属性输入提示实现:
152+
153+
```js
154+
{
155+
name: 'TableColumn',
156+
props: [
157+
{
158+
name: 'render',
159+
setter: 'expressionSetter',
160+
autoCompleteOptions: ['(value, record, index) => { return null; }'],
161+
}
162+
],
163+
}
164+
```
165+
166+
## 组件拖拽规则描述
167+
168+
请参考 [IComponentDnDRules](https://netease.github.io/tango/interfaces/_music163_tango_helpers.IComponentDndRules.html)
169+
170+
### canDrag/canDrop
171+
172+
在 onDragStart 的时候执行。
173+
174+
```js
175+
export const Page = {
176+
name: 'Page',
177+
rules: {
178+
canDrag() {
179+
return false;
180+
},
181+
},
182+
};
183+
```
184+
185+
### canMoveIn/canMoveOut
186+
187+
在 onDragEnter 的时候执行。
188+
189+
```js
190+
export const Modal = {
191+
name: 'Modal',
192+
rules: {
193+
canMoveIn(incomingName) {
194+
return !(incomingName === Modal.name);
195+
},
196+
},
197+
};
198+
```
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
{
22
"version.label": {
3-
"message": "Next",
3+
"message": "下一篇",
44
"description": "The label for version current"
55
},
6-
"sidebar.tutorialSidebar.category.boot": {
7-
"message": "boot",
8-
"description": "The label for category boot in sidebar tutorialSidebar"
9-
},
10-
"sidebar.tutorialSidebar.category.designer": {
11-
"message": "designer",
12-
"description": "The label for category designer in sidebar tutorialSidebar"
13-
},
14-
"sidebar.tutorialSidebar.category.customize": {
15-
"message": "customize",
16-
"description": "The label for category customize in sidebar tutorialSidebar"
17-
},
18-
"sidebar.tutorialSidebar.category.deploy": {
19-
"message": "deploy",
20-
"description": "The label for category deploy in sidebar tutorialSidebar"
21-
},
22-
"sidebar.tutorialSidebar.category.design": {
23-
"message": "design",
24-
"description": "The label for category design in sidebar tutorialSidebar"
25-
},
26-
"sidebar.designer.category.接入指南": {
6+
"sidebar.designer.category.Guide": {
277
"message": "接入指南",
28-
"description": "The label for category 接入指南 in sidebar designer"
8+
"description": "The label for category Guide in sidebar designer"
299
},
30-
"sidebar.designer.category.设计器自定义": {
31-
"message": "设计器自定义",
32-
"description": "The label for category 设计器自定义 in sidebar designer"
10+
"sidebar.designer.category.Customize": {
11+
"message": "自定义",
12+
"description": "The label for category Customize in sidebar designer"
3313
},
34-
"sidebar.designer.category.设计原理": {
14+
"sidebar.designer.category.Design": {
3515
"message": "设计原理",
36-
"description": "The label for category 设计原理 in sidebar designer"
16+
"description": "The label for category Design in sidebar designer"
3717
},
38-
"sidebar.designer.category.应用框架": {
18+
"sidebar.designer.category.Framework": {
3919
"message": "应用框架",
40-
"description": "The label for category 应用框架 in sidebar designer"
20+
"description": "The label for category Framework in sidebar designer"
21+
},
22+
"sidebar.designer.category.Protocols": {
23+
"message": "协议规范",
24+
"description": "The label for category Protocols in sidebar designer"
4125
}
4226
}

sidebars.ts

+8-15
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';
1212
*/
1313
const sidebars: SidebarsConfig = {
1414
// By default, Docusaurus generates a sidebar from the docs folder structure
15-
tutorialSidebar: [{ type: 'autogenerated', dirName: '.' }],
15+
// tutorialSidebar: [{ type: 'autogenerated', dirName: '.' }],
1616

1717
designer: [
1818
'intro',
1919
'designer/quick-start',
2020
{
2121
type: 'category',
22-
label: '接入指南',
22+
label: 'Guide',
2323
items: [
2424
'designer/deploy/designer',
2525
'designer/deploy/component',
@@ -30,7 +30,7 @@ const sidebars: SidebarsConfig = {
3030
},
3131
{
3232
type: 'category',
33-
label: '设计器自定义',
33+
label: 'Customize',
3434
items: [
3535
'designer/customize/panels',
3636
'designer/customize/tools',
@@ -43,7 +43,7 @@ const sidebars: SidebarsConfig = {
4343
},
4444
{
4545
type: 'category',
46-
label: '设计原理',
46+
label: 'Design',
4747
items: [
4848
'designer/design/overview',
4949
'designer/design/filesystem',
@@ -53,7 +53,7 @@ const sidebars: SidebarsConfig = {
5353
},
5454
{
5555
type: 'category',
56-
label: '应用框架',
56+
label: 'Framework',
5757
items: [
5858
'boot/intro',
5959
'boot/app-spec',
@@ -66,20 +66,13 @@ const sidebars: SidebarsConfig = {
6666
],
6767
collapsed: false,
6868
},
69-
],
70-
71-
// But you can create a sidebar manually
72-
/*
73-
tutorialSidebar: [
74-
'intro',
75-
'hello',
7669
{
7770
type: 'category',
78-
label: 'Tutorial',
79-
items: ['tutorial-basics/create-a-document'],
71+
label: 'Protocols',
72+
items: [{ type: 'autogenerated', dirName: 'protocol' }],
73+
collapsed: false,
8074
},
8175
],
82-
*/
8376
};
8477

8578
export default sidebars;

0 commit comments

Comments
 (0)