# Schema design capabilities The design capabilities of Schema are mainly - Neighborhood insertion, which can be used to - Insertion of new schema nodes - Drag-and-drop movement of existing schema nodes - schema parameter modification The core designer APIs and parameters are - Designer API: `createDesignable()` & `useDesignable()` - Schema parameters: `x-designer`, used to adapt the designer component ## Designer API ### createDesignable() ```ts import { Schema } from '@nocobase/client'; const current = new Schema({ type: 'void', 'x-component': 'div', }); const { designable, // whether it is configurable remove, insertAdjacent, // insert at a position, four positions: beforeBegin, afterBegin, beforeEnd, afterEnd insertBeforeBegin, // insert in front of the current node insertAfterBegin, // insert in front of the first child node of the current node insertBeforeEnd, // after the last child of the current node insertAfterEnd, // after the current node } = createDesignable({ current, }); const newSchema = { type: 'void', name: 'hello', 'x-component': 'Hello', }; insertAfterBegin(newSchema); console.log(current.toJSON()); { type: 'void', 'x-component': 'div', properties: { hello: { type: 'void', 'x-component': 'Hello', }, }, } ``` ### useDesignable() React Hook scenarios can also use `useDesignable()` to get the API of the current schema component designer ```ts const { designable, // whether it is configurable remove, insertAdjacent, // insert at a position, four positions: beforeBegin, afterBegin, beforeEnd, afterEnd insertBeforeBegin, // insert in front of the current node insertAfterBegin, // insert in front of the first child node of the current node insertBeforeEnd, // after the last child of the current node insertAfterEnd, // after the current node } = useDesignable(); const schema = { name: uid(), 'x-component': 'Hello', }; // Insert in front of the current node insertBeforeBegin(schema); // Equivalent to insertAdjacent('beforeBegin', schema); // insert in front of the first child of the current node insertAfterBegin(schema); // Equivalent to insertAdjacent('afterBegin', schema); // after the last child of the current node insertBeforeEnd(schema); // Equivalent to insertAdjacent('beforeEnd', schema); // After the current node insertAfterEnd(schema); // Equivalent to 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. The four adjacent positions ```ts { properties: { // beforeBegin insert before the current node node1: { properties: { // afterBegin inserted before the first child of the current node // ... // beforeEnd after the last child of the current node }, }, // 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. ### Inserting a new schema node Within a Schema component, a new node can be inserted directly into the adjacent position of the current Schema with `useDesignable()`. Example ```tsx import React from 'react'; import { SchemaComponentProvider, SchemaComponent, useDesignable } from '@nocobase/client'; import { observer, Schema, useFieldSchema } from '@formily/react'; import { Button, Space } from 'antd'; import { uid } from '@formily/shared'; const Hello = observer((props) => { const { insertAdjacent } = useDesignable(); const fieldSchema = useFieldSchema(); return (