Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 添加文档 #917

Open
wants to merge 10 commits into
base: refactor/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 36 additions & 0 deletions docs/API/API总览.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# API 总览

TinyEngine的API主要分为`TinyEngine能力API`和`开源后端接口API`。

## TinyEngine能力API
主要提供以下几类API
- 主包API
- 画布API
- 布局API
- 物料API
- 属性面板API


## 后端接口API
主要提供以下几类API
- AI功能接口
- 应用管理
- 区块分类
- 应用工具类管理
- 区块管理
- 数据源管理
- DSL代码生成
- 国际化管理
- 物料中心
- 页面管理
- APP服务


## API约定
### 元服务API

所有的元服务,全都为use开头的驼峰式命名。如我们内置的useMaterial,useCanvas等。

## 声明
以上API处于公测阶段,具体API可能会根据实际需求有所调整

Binary file added docs/API/imgs/bindEventApi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
200 changes: 200 additions & 0 deletions docs/API/主包API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# TinyEngine 主包使用API

主包包名为@opentiny/tiny-engine,主要导出所有扩展插件包模块、元服务、meta-register API等,用户设计器中可以按需引用

导出模块如下:

```js
export { init } from './src/init'

// reexport all plugin, user can import ondemand
export { default as Breadcrumb, BreadcrumbService } from '@opentiny/tiny-engine-toolbar-breadcrumb'
export { default as Fullscreen } from '@opentiny/tiny-engine-toolbar-fullscreen'
export { default as Lang } from '@opentiny/tiny-engine-toolbar-lang'
export { default as Logo } from '@opentiny/tiny-engine-toolbar-logo'
export { default as Lock } from '@opentiny/tiny-engine-toolbar-lock'
export { default as Media } from '@opentiny/tiny-engine-toolbar-media'
export { default as Redoundo, HistoryService } from '@opentiny/tiny-engine-toolbar-redoundo'
export { default as Save } from '@opentiny/tiny-engine-toolbar-save'
export { default as Clean } from '@opentiny/tiny-engine-toolbar-clean'
export { default as Preview } from '@opentiny/tiny-engine-toolbar-preview'
export { default as GenerateCode, SaveLocalService } from '@opentiny/tiny-engine-toolbar-generate-code'
export { default as Refresh } from '@opentiny/tiny-engine-toolbar-refresh'
export { default as Collaboration } from '@opentiny/tiny-engine-toolbar-collaboration'
export { default as Setting } from '@opentiny/tiny-engine-toolbar-setting'
export { default as Materials, ResourceService, MaterialService } from '@opentiny/tiny-engine-plugin-materials'
export { default as State } from '@opentiny/tiny-engine-plugin-state'
export { default as Script } from '@opentiny/tiny-engine-plugin-script'
export { default as Tree } from '@opentiny/tiny-engine-plugin-tree'
export { default as Help, HelpService } from '@opentiny/tiny-engine-plugin-help'
export { default as Schema } from '@opentiny/tiny-engine-plugin-schema'
export { default as Page, PageService } from '@opentiny/tiny-engine-plugin-page'
export { default as I18n, TranslateService } from '@opentiny/tiny-engine-plugin-i18n'
export { default as Bridge } from '@opentiny/tiny-engine-plugin-bridge'
export { default as Block, BlockService } from '@opentiny/tiny-engine-plugin-block'
export { default as Datasource, DataSourceService } from '@opentiny/tiny-engine-plugin-datasource'
export { default as Robot } from '@opentiny/tiny-engine-plugin-robot'
export { default as Props, PropertiesService, PropertyService } from '@opentiny/tiny-engine-setting-props'
export { default as Events } from '@opentiny/tiny-engine-setting-events'
export { default as Styles } from '@opentiny/tiny-engine-setting-styles'
export { default as Layout, LayoutService } from '@opentiny/tiny-engine-layout'
export { default as Canvas } from '@opentiny/tiny-engine-canvas'
export { initPreview } from './src/preview/src/main'
export {
GenerateCodeService,
PluginPanel,
PluginSetting,
ToolbarBase,
GlobalService
} from '@opentiny/tiny-engine-common'

export { default as defaultRegistry } from './registry'

export * from '@opentiny/tiny-engine-meta-register'

```

## 使用示例

1. 可以将主包导出的元服务、元应用按需引入到注册表中,如:
```js
// registry.js
import {
Breadcrumb,
Fullscreen,
Lang,
Logo,
Lock,
Media,
Redoundo,
Save,
Clean,
Preview,
GenerateCode,
Refresh,
Collaboration,
Materials,
State,
Script,
Tree,
Help,
Schema,
Page,
I18n,
Bridge,
Block,
Datasource,
Robot,
Props,
Events,
Styles,
Layout,
Canvas,
GenerateCodeService,
GlobalService
} from '@opentiny/tiny-engine'
import engineConfig from './engine.config'

export default {
root: {
id: 'engine.root',
metas: [GenerateCodeService, GlobalService]
},
config: engineConfig,
layout: {
...Layout,
options: {
...Layout.options,
isShowLine: true,
isShowCollapse: true,
toolbars: {
left: ['engine.toolbars.breadcrumb', 'engine.toolbars.lock', 'engine.toolbars.logo'],
center: ['engine.toolbars.media'],
right: [
['engine.toolbars.redoundo', 'engine.toolbars.clean'],
['engine.toolbars.preview'],
['engine.toolbars.generate-code', 'engine.toolbars.save']
],
collapse: [
['engine.toolbars.collaboration'],
['engine.toolbars.refresh', 'engine.toolbars.fullscreen'],
['engine.toolbars.lang']
]
}
}
},
themes: [
{
id: 'engine.theme.light'
},
{
id: 'engine.theme.dark'
}
],
toolbars: [
Logo,
Breadcrumb,
Lock,
Media,
Redoundo,
Collaboration,
Clean,
Preview,
Refresh,
GenerateCode,
Save,
Fullscreen,
Lang
],
plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, State, Schema, Help, Robot],
dsls: [{ id: 'engine.dsls.dslvue' }],
settings: [Props, Styles, Events],
canvas: Canvas
}

```

2. `defineEntry`:提供了defineEntry函数,作为注册表的注册入口,能够将用户注册表注册到TinyEngine中,如:
```js
import registry from '../registry.js'
import { defineEntry } from '@opentiny/tiny-engine'

defineEntry(registry)

export { registry }

```

3. `getMergeMeta`:提供了在各个元服务、元应用获取到注册表的能力
```js
import { getMergeMeta } from '@opentiny/tiny-engine'

// 获取元应用/元服务注册表
getMergeMeta('engine.config')

// 获取完整注册表
getMergeRegistry()
// 获取类型下所有注册表
getMergeRegistry('toolbars')
// 获取元应用/元服务注册表
getMergeRegistry('toolbars', 'engine.toolbars.lang')
```

4. `getMetaApi`:提供了获取元应用/元服务API的能力

```js
import { getMetaApi } from '@opentiny/tiny-engine'

// 通过getMetaApi获取元应用/元服务API
const { selectNode } = getMetaApi('engine.canvas').canvasApi.value


```

5. `getOptions`:提供了在各个元服务、元应用获取到元服务API的能力
```js
import { getOptions } from '@opentiny/tiny-engine'

// 通过getOptions获取元应用/元服务配置项
const options = getOptions('engine.canvas')
```
39 changes: 39 additions & 0 deletions docs/API/全局布局API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 布局模块

## 布局元应用

布局元应用配置如下

```javascript
{
options: {
configProvider, // 全局配置组件
configProviderDesign // 规范,可以通过该属于定制一些自定义的交互规范
},
metas: [LayoutService]
}
```

## 布局元服务

布局元服务api如下

```javascript
{
apis: {
PLUGIN_NAME, // 对象,插件对应的元应用id
activePlugin, // 激活plugin面板,参数(插件名,是否激活对应面板)
activeSetting, // 激活setting面板并高亮提示,参数(属性名)
closePlugin, // 关闭插件面板,参数(是否强制关闭)
getDimension, // 获取样式范围
getPluginState, // 获取插件面板状态
getScale, // 获取规定比例
isEmptyPage, // 判断页面状态是否为空
layoutState, // 对象,layout状态
pluginState, // 对象,插件状态
setDimension // 设置样式范围
}
}
```

###
49 changes: 49 additions & 0 deletions docs/API/后端API/AI功能接口.md

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions docs/API/后端API/APP服务.md

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions docs/API/后端API/DSL代码生成.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# DSL代码生成

## generateCode

<a id=generateCode> </a>

### 基本信息

**Path:** /generateCode

**Method:** GET

**接口描述:**

<p>作为npm包使用generateCode方法生成代码示例:</p>
<pre><code data-language="js" class="lang-js">const path = require('path')
const fs = require('fs')
const { generateCode } = require('@opentiny/tiny-engine-dsl-ng-tiny/lib/generate-code.js')



const result = generateCode({ pageInfo, blocksData })
result.forEach((item) =&gt; fs.writeFileSync(`dist/${item.filePath}/${item.panelName}`, item.panelValue))
</code></pre>

<p>输入示例: { pageInfo, blocksData };</p>
<pre><code data-language="js" class="lang-js">// pageInfo为页面的schema信息,
// pageInfo: { schema, name });
{
name: 'page1',
schema: {
// 页面schema
}
}


// blocksData为页面引用的区块的schema数据
// blocksData: Array&lt;{ label, content }&gt;
[
{
label: 'image-title',
content: {
// 区块的schema
}
},
{
// 其他区块...
}
]
</code></pre>

<p>输出示例:</p>
<pre><code data-language="js" class="lang-js">[
{
"panelName": "page1.component.html", // 文件名
"panelValue": "xxx", // 生成代码的内容
"panelType": "html", // 生成代码的文件类型:html、css、ts
"prettierOpt": { "parser": "html", "tabWidth": 2, "printWidth": 120 }, // prettier格式化选项
"type": "page", // 生成代码类型:page、block、service
"filePath": "pages/page1" // 生成代码文件的相对目录路径
},
{
"panelName": "page1.component.ts",
"panelValue": "xxx",
"panelType": "ts",
"prettierOpt": { "parser": "typescript", "tabWidth": 2, "printWidth": 120 },
"type": "page",
"filePath": "pages/page1"
},
{
"panelName": "block1.component.ts",
"type": "block",
"panelType": "ts",
"prettierOpt": { "parser": "typescript", "tabWidth": 2, "printWidth": 120 },
"filePath": "blocks/block1",
"panelValue": "xxx"
},
{
"panelName": "fetch.service.ts",
"panelType": "ts",
"prettierOpt": { "parser": "typescript", "tabWidth": 2, "printWidth": 120 },
"type": "service",
"filePath": "service",
"panelValue": "xxx"
},
// ...
]
</code></pre>



### 请求参数

### 返回数据

<table>
<thead class="ant-table-thead">
<tr>
<th key=name>名称</th><th key=type>类型</th><th key=required>是否必须</th><th key=default>默认值</th><th key=desc>备注</th><th key=sub>其他信息</th>
</tr>
</thead><tbody className="ant-table-tbody"><tr key=0><td key=0><span style="padding-left: 0px"><span style="color: #8c8a8a"></span> </span></td><td key=1><span>object []</span></td><td key=2>非必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap"></span></td><td key=5><p key=3><span style="font-weight: '700'">item 类型: </span><span>object</span></p></td></tr><tr key=0-0><td key=0><span style="padding-left: 20px"><span style="color: #8c8a8a">├─</span> panelName</span></td><td key=1><span>string</span></td><td key=2>必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">文件名</span></td><td key=5></td></tr><tr key=0-1><td key=0><span style="padding-left: 20px"><span style="color: #8c8a8a">├─</span> panelValue</span></td><td key=1><span>string</span></td><td key=2>必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">文件文本</span></td><td key=5></td></tr><tr key=0-2><td key=0><span style="padding-left: 20px"><span style="color: #8c8a8a">├─</span> panelType</span></td><td key=1><span>string</span></td><td key=2>必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">代码类型</span></td><td key=5></td></tr><tr key=0-3><td key=0><span style="padding-left: 20px"><span style="color: #8c8a8a">├─</span> prettierOpt</span></td><td key=1><span>object</span></td><td key=2>必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">代码美化选项</span></td><td key=5></td></tr><tr key=0-3-0><td key=0><span style="padding-left: 40px"><span style="color: #8c8a8a">├─</span> parser</span></td><td key=1><span>string</span></td><td key=2>非必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">指定要使用的解析器</span></td><td key=5></td></tr><tr key=0-3-1><td key=0><span style="padding-left: 40px"><span style="color: #8c8a8a">├─</span> tabWidth</span></td><td key=1><span>number</span></td><td key=2>非必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">指定使用几个空格来表示一个制表符(Tab)</span></td><td key=5></td></tr><tr key=0-3-2><td key=0><span style="padding-left: 40px"><span style="color: #8c8a8a">├─</span> printWidth</span></td><td key=1><span>number</span></td><td key=2>非必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">指定每行代码的最大列数</span></td><td key=5></td></tr><tr key=0-4><td key=0><span style="padding-left: 20px"><span style="color: #8c8a8a">├─</span> type</span></td><td key=1><span>string</span></td><td key=2>必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">代码类型</span></td><td key=5></td></tr><tr key=0-5><td key=0><span style="padding-left: 20px"><span style="color: #8c8a8a">├─</span> filePath</span></td><td key=1><span>string</span></td><td key=2>必须</td><td key=3></td><td key=4><span style="white-space: pre-wrap">文件路径</span></td><td key=5></td></tr>
</tbody>
</table>

Loading
Loading