mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 15:16:31 +00:00
Update designable.md
This commit is contained in:
parent
1c72ee0a1a
commit
4b5b3f966d
@ -1,18 +1,18 @@
|
|||||||
# Schema 的设计能力
|
# Schema design capabilities
|
||||||
|
|
||||||
Schema 的设计能力主要体现在
|
The design capabilities of Schema are mainly
|
||||||
|
|
||||||
- 邻近位置插入,可用于
|
- Neighborhood insertion, which can be used to
|
||||||
- 插入新的 schema 节点
|
- Insertion of new schema nodes
|
||||||
- 现有 schema 节点的拖拽移动
|
- Drag-and-drop movement of existing schema nodes
|
||||||
- schema 参数修改
|
- schema parameter modification
|
||||||
|
|
||||||
设计器核心 API 和参数有:
|
The core designer APIs and parameters are
|
||||||
|
|
||||||
- 设计器 API:`createDesignable()` & `useDesignable()`
|
- Designer API: `createDesignable()` & `useDesignable()`
|
||||||
- Schema 参数:`x-designer`,用于适配设计器组件
|
- Schema parameters: `x-designer`, used to adapt the designer component
|
||||||
|
|
||||||
## 设计器 API
|
## Designer API
|
||||||
|
|
||||||
### createDesignable()
|
### createDesignable()
|
||||||
|
|
||||||
@ -25,13 +25,13 @@ const current = new Schema({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
designable, // 是否可以配置
|
designable, // whether it is configurable
|
||||||
remove,
|
remove,
|
||||||
insertAdjacent, // 在某位置插入,四个位置:beforeBegin、afterBegin、beforeEnd、afterEnd
|
insertAdjacent, // insert at a position, four positions: beforeBegin, afterBegin, beforeEnd, afterEnd
|
||||||
insertBeforeBegin, // 在当前节点的前面插入
|
insertBeforeBegin, // insert in front of the current node
|
||||||
insertAfterBegin, // 在当前节点的第一个子节点前面插入
|
insertAfterBegin, // insert in front of the first child node of the current node
|
||||||
insertBeforeEnd, // 在当前节点的最后一个子节点后面
|
insertBeforeEnd, // after the last child of the current node
|
||||||
insertAfterEnd, // 在当前节点的后面
|
insertAfterEnd, // after the current node
|
||||||
} = createDesignable({
|
} = createDesignable({
|
||||||
current,
|
current,
|
||||||
});
|
});
|
||||||
@ -59,17 +59,17 @@ console.log(current.toJSON());
|
|||||||
|
|
||||||
### useDesignable()
|
### useDesignable()
|
||||||
|
|
||||||
React Hook 场景也可以用 `useDesignable()` 获取当前 schema 组件设计器的 API
|
React Hook scenarios can also use `useDesignable()` to get the API of the current schema component designer
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const {
|
const {
|
||||||
designable, // 是否可以配置
|
designable, // whether it is configurable
|
||||||
remove,
|
remove,
|
||||||
insertAdjacent, // 在某位置插入,四个位置:beforeBegin、afterBegin、beforeEnd、afterEnd
|
insertAdjacent, // insert at a position, four positions: beforeBegin, afterBegin, beforeEnd, afterEnd
|
||||||
insertBeforeBegin, // 在当前节点的前面插入
|
insertBeforeBegin, // insert in front of the current node
|
||||||
insertAfterBegin, // 在当前节点的第一个子节点前面插入
|
insertAfterBegin, // insert in front of the first child node of the current node
|
||||||
insertBeforeEnd, // 在当前节点的最后一个子节点后面
|
insertBeforeEnd, // after the last child of the current node
|
||||||
insertAfterEnd, // 在当前节点的后面
|
insertAfterEnd, // after the current node
|
||||||
} = useDesignable();
|
} = useDesignable();
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
@ -77,57 +77,54 @@ const schema = {
|
|||||||
'x-component': 'Hello',
|
'x-component': 'Hello',
|
||||||
};
|
};
|
||||||
|
|
||||||
// 在当前节点的前面插入
|
// Insert in front of the current node
|
||||||
insertBeforeBegin(schema);
|
insertBeforeBegin(schema);
|
||||||
// 等同于
|
// Equivalent to
|
||||||
insertAdjacent('beforeBegin', schema);
|
insertAdjacent('beforeBegin', schema);
|
||||||
|
|
||||||
// 在当前节点的第一个子节点前面插入
|
// insert in front of the first child of the current node
|
||||||
insertAfterBegin(schema);
|
insertAfterBegin(schema);
|
||||||
// 等同于
|
// Equivalent to
|
||||||
insertAdjacent('afterBegin', schema);
|
insertAdjacent('afterBegin', schema);
|
||||||
|
|
||||||
// 在当前节点的最后一个子节点后面
|
// after the last child of the current node
|
||||||
insertBeforeEnd(schema);
|
insertBeforeEnd(schema);
|
||||||
// 等同于
|
// Equivalent to
|
||||||
insertAdjacent('beforeEnd', schema);
|
insertAdjacent('beforeEnd', schema);
|
||||||
|
|
||||||
// 在当前节点的后面
|
// After the current node
|
||||||
insertAfterEnd(schema);
|
insertAfterEnd(schema);
|
||||||
// 等同于
|
// Equivalent to
|
||||||
insertAdjacent('afterEnd', schema);
|
insertAdjacent('afterEnd', schema);
|
||||||
```
|
```
|
||||||
|
## Neighborhood insertion
|
||||||
|
|
||||||
## 邻近位置插入
|
Similar to the DOM's [insert adjacent](https://dom.spec.whatwg.org/#insert-adjacent) concept, Schema also provides the `insertAdjacent()` method for solving the insertion of adjacent positions.
|
||||||
|
|
||||||
与 DOM 的 [insert adjacent](https://dom.spec.whatwg.org/#insert-adjacent) 概念相似,Schema 也提供了 `insertAdjacent()` 方法用于解决邻近位置的插入问题。
|
The four adjacent positions
|
||||||
|
|
||||||
四个邻近位置
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
{
|
{
|
||||||
properties: {
|
properties: {
|
||||||
// beforeBegin 在当前节点的前面插入
|
// beforeBegin insert before the current node
|
||||||
node1: {
|
node1: {
|
||||||
properties: {
|
properties: {
|
||||||
// afterBegin 在当前节点的第一个子节点前面插入
|
// afterBegin inserted before the first child of the current node
|
||||||
// ...
|
// ...
|
||||||
// beforeEnd 在当前节点的最后一个子节点后面
|
// beforeEnd after the last child of the current node
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// afterEnd 在当前节点的后面
|
// afterEnd after the current node
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Like HTML tags, the components of the Schema component library can be combined with each other and inserted in reasonable proximity as needed via the insertAdjacent API.
|
||||||
|
|
||||||
和 HTML 标签一样,Schema 组件库的组件也是可以相互组合,通过 insertAdjacent API 按实际需要插入在合理的邻近位置。
|
### Inserting a new schema node
|
||||||
|
|
||||||
### 插入新的 schema 节点
|
Within a Schema component, a new node can be inserted directly into the adjacent position of the current Schema with `useDesignable()`.
|
||||||
|
|
||||||
在 Schema 组件里,可以直接通过 `useDesignable()` 在当前 Schema 的相邻位置插入新节点:
|
Example
|
||||||
|
|
||||||
|
|
||||||
示例
|
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@ -210,9 +207,9 @@ export default () => {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 现有 schema 节点的拖拽移动
|
### Drag-and-drop movement of existing schema nodes
|
||||||
|
|
||||||
insertAdjacent 等方法也可用于节点的拖拽移动
|
Methods such as insertAdjacent can also be used to drag and drop nodes
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@ -319,10 +316,9 @@ export default function App() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
## Applications of `x-designer`
|
||||||
|
|
||||||
## `x-designer` 的应用
|
`x-designer` is usually used only in wrapper components such as BlockItem, CardItem, FormItem, etc.
|
||||||
|
|
||||||
`x-designer` 通常只在 BlockItem、CardItem、FormItem 等包装器组件中使用。
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
{
|
{
|
||||||
@ -346,8 +342,8 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
说明:NocoBase 提供的 Schema 设计器是以工具栏形式直接嵌入于界面,当激活界面配置时(`designable = true`),`x-designer` 组件(设计器工具栏)会显示出来,就可以通过工具栏更新当前 schema 组件了,工具栏提供的设计能力包括:
|
Note: The Schema designer provided by NocoBase is directly embedded in the interface in the form of a toolbar. When the UI configuration is activated (`designable = true`), the `x-designer` component (designer toolbar) will be displayed and the current schema component can be updated through the toolbar.
|
||||||
|
|
||||||
- 拖拽移动:DndContext + DragHandler
|
- Drag and Drop: DndContext + DragHandler
|
||||||
- 插入新节点:SchemaInitializer
|
- Inserting new nodes: SchemaInitializer
|
||||||
- 参数配置:SchemaSettings
|
- Parameter configuration: SchemaSettings
|
||||||
|
Loading…
Reference in New Issue
Block a user