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

feat: schemaDataAsync #885

Merged
merged 24 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ab7838d
feat: schemaDataAsync
chilingling Oct 29, 2024
82600ee
fix: adapt schema plugin
chilingling Oct 29, 2024
f850e97
fix: add import export schema
chilingling Oct 29, 2024
d6b7bd3
fix: remove useless code
chilingling Oct 29, 2024
7433a96
fix: shcmea change cant't trigger canvas rerender
chilingling Nov 4, 2024
b4e0b1f
fix: replace setSchema
chilingling Nov 5, 2024
bc18709
refactor: schema data sync to canvas
chilingling Nov 7, 2024
b307cec
refactor: change synchoronized method between canvas and host
chilingling Nov 9, 2024
5993ff1
fix: remove useless node tree
chilingling Nov 9, 2024
15f843a
fix: support recursive update attr
chilingling Nov 9, 2024
d7de2fd
feat: support recursive update nodesMap
chilingling Nov 11, 2024
b9d1d83
fix: selectNode updateRect conflict
chilingling Nov 11, 2024
67e44f9
refactor: sync update to schemaService
chilingling Nov 15, 2024
961fa21
feat: migrade canvas collection
chilingling Nov 25, 2024
6dfdf3f
fix: dataSourceMap update
chilingling Nov 25, 2024
a3a12a0
feat: add docs
chilingling Nov 26, 2024
a4f51d8
fix: add direct change schema api doc
chilingling Nov 26, 2024
9fa53a5
fix: use toRaw optimize performance
chilingling Nov 27, 2024
780e5fd
fix: add default fallback for changeProps
chilingling Dec 3, 2024
cf258bb
fix: schema update issue
chilingling Dec 7, 2024
fc978ca
fix: add compatible for empty children
chilingling Dec 7, 2024
9c8802d
fix: provide schemaUtils to canvas
chilingling Dec 11, 2024
972b781
fix: update collection table data
chilingling Dec 11, 2024
93bb06d
fix: add error handling
chilingling Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
757 changes: 243 additions & 514 deletions designer-demo/public/mock/bundle.json

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions packages/canvas/DesignCanvas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# schema 元服务相关API(Experimental)

## 直接修改 schema 引用 & 调用通知更新

使用示例:

```javascript
import { useCanvas, useMessage } from '@opentiny/tiny-engine-meta-register'

const pageSchema = useCanvas().getPageSchema()

pageSchema.css = "xxxx"

useMessage().publish({ topic: 'schemaChange' })
```

注意:直接修改 schema 引用当前不能涉及到节点的增加、删除,不然会节点树 nodesMap 无法更新,导致画布无法选中新增的组件。


> 注意:以下所有 API 皆为 Experimental 实验 API,请不要用在生产阶段

## 导入/导出 schema

> 这里的导入导出仅包含页面级别,不包含应用级别 schema

**导入 schema:**

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

const data = { /*页面/区块 schema*/ }

useCanvas().importSchema(data)
```

**导出 schema:**

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

useCanvas().exportSchema()
```

## 页面 schema相关操作

> 主要描述对页面 schema 的增删查改操作

### 获取当前页面/区块 schema:

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

useCanvas().getPageSchema()
```

### 获取当前选中节点 schema:

```javascript
import { useProperties } from '@opentiny/tiny-engine-meta-register'

const schema = useProperties().getSchema()
```

### 根据 id 查询对应的 节点schema(schema 片段)

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

const schema = useCanvas().getNode('453254', false)
```

类型:

```typescript
/**
* 根据节点 id 获取 schema 片段
* id: schema id
* parent: 是否需要同时获取 parent 节点
*/
type getNode = (id: string, parent: boolean) => INode | { node: INode; parent: INode }
```

### 节点操作

#### 插入节点

使用示例:

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

useCanvas().operateNode({
type: 'insert',
parentId: '432423',
newNodeData: { componentName: 'div', props: {}, children: [] },
position: 'after',
referTargetNodeId: '898432'
})
```

类型:

```typescript
interface IInsertOperation {
// 操作类型为 insert
type: 'insert';
// 要插入的节点的 父节点 id
parentId: string;
// 新节点数据
newNodeData: INode;
// 相对节点的 id,比如我们想要插入父节点 id 中 第 5 个 children 的后面,或者前面
referTargetNodeId: string;
// 相对节点的位置
position: 'after' | 'before';
}
```

#### 删除节点

使用示例:

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

useCanvas().operateNode({
type: 'delete',
id: '432423'
})
```

类型:

```typescript
interface IDeleteOperation {
type: 'delete';
id: string;
}
```

#### 修改节点 props

使用示例:

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

useCanvas().operateNode({
type: 'changeProps',
id: '432423',
value: { text: 'TinyEngine' },
option: { overwrite: false }
})
```

类型:

```typescript
interface IChangePropsOperation {
type: 'changeProps';
// 节点 id
id: string;
// 新的 props 值
value: Record<string, any>;
// 操作类型:是否覆写
option: { overwrite: boolean; }
}
```

#### 更新节点属性

使用示例:

```javascript
import { useCanvas } from '@opentiny/tiny-engine-meta-register'

useCanvas().operateNode({
type: 'updateAttributes',
id: '432423',
value: { props: { ... }, loop: { ... } },
overwrite: boolean
})
```

类型:

```typescript
interface IUpdateAttrOperation {
type: 'updateAttributes';
id: string;
// 对节点的属性修改
value: Record<string, any>;
// 是否是直接覆盖
overwrite: boolean;
}
```
25 changes: 16 additions & 9 deletions packages/canvas/DesignCanvas/src/DesignCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {
getMergeMeta,
getOptions,
getMetaApi,
META_SERVICE
META_SERVICE,
useMessage,
useNotify
} from '@opentiny/tiny-engine-meta-register'
import { constants } from '@opentiny/tiny-engine-utils'
import * as ast from '@opentiny/tiny-engine-common/js/ast'
Expand Down Expand Up @@ -66,7 +68,7 @@ export default {

const removeNode = (node) => {
const { pageState } = useCanvas()
footData.value = useCanvas().canvasApi.value.getNodePath(node?.id)
footData.value = useCanvas().getNodePath(node?.id)
pageState.currentSchema = {}
pageState.properties = null
}
Expand Down Expand Up @@ -130,19 +132,21 @@ export default {
}
)

const nodeSelected = (node, parent, type) => {
const nodeSelected = (node, parent, type, id) => {
const { toolbars } = useLayout().layoutState
if (type !== 'clickTree') {
useLayout().closePlugin()
}

const { getSchema, getNodePath } = useCanvas().canvasApi.value
const { getSchema, getNodePath } = useCanvas()
const schemaItem = useCanvas().getNodeById(id)

const pageSchema = getSchema()

const schema = getSchema()
// 如果选中的节点是画布,就设置成默认选中最外层schema
useProperties().getProps(node || schema, parent)
useCanvas().setCurrentSchema(node || schema)
footData.value = getNodePath(node?.id)
useProperties().getProps(schemaItem || pageSchema, parent)
useCanvas().setCurrentSchema(schemaItem || pageSchema)
footData.value = getNodePath(schemaItem?.id)
toolbars.visiblePopover = false
}

Expand Down Expand Up @@ -182,7 +186,10 @@ export default {
addHistory: useHistory().addHistory,
registerBlock: useMaterial().registerBlock,
request: getMetaApi(META_SERVICE.Http).getHttp(),
ast
ast,
useModal,
useMessage,
useNotify
},
CanvasLayout,
canvasRef,
Expand Down
Loading
Loading