For existing Mini Program component libraries, the visual editor now supports displaying them. As long as the component library package is located in the
miniprogram_npmdirectory and the corresponding configuration file interface is set up in the root directory of the component library, the visual editor can parse and add the component library's information, allowing components to be dragged into the respective WXML and JSON files on the page.
Runtime Environment
Developer Tools version 1.05.2206242 or later
Create New Operation Flow
Integrating the third-party component library for tool visualization requires adding a new JSON configuration for management.
1. Create a New Configuration
- Create a new
.wechatide.ib.jsonin the root directory of the component library. The packagedminiprogram_rootis required.
2. Configuration Composition Description
2.1 Main Structure: components and menu
.wechatide-ib.jsonis a JSON object containing the followingkey
export interface IIBComponentLibConfig {
key: string // Component library identifier, e.g., tdesign
label: string // Human-readable name, e.g., "Tdesign Components"
// Component list configuration
components: {
[propName: string]: IIBComponentLibConfigComponent
};
// Menu-related
menu: IIBComponentLibConfigMenu[], // Component panel menu configuration
common: IIBComponentLibConfigCommon // @TODO Common properties and configuration
}
2.2 Component Definition IIBComponentLibConfigComponent
The tool retrieves basic information about the defined components from the components content.
export interface IIBComponentLibConfigComponent {
key?: string; // Component tag name, e.g., "t-button". It should match the key in the component list. The tool fills this in by default, so it is optional.
label: string; // Human-readable name of the component, e.g., "Button"
icon: string; // Component icon preview (local or network URL). Recommended size: 200 * 100, e.g., "../../xxx.png" or "https://xxxx/xx.png"
topIcon?: string // Icon required if the component is placed in the header. Local or network URL. Recommended size: 44 * 44, padding: 10. E.g., "../../xxx.png" or "https://xxxx/xx.png"
events?: IIBComponentLibConfigEvent[]; // List of events
properties?: IIBComponentLibConfigProperty[]; // List of properties
tpl?: string; // Custom component module code. If empty, a default tpl is generated using the key as the tag name: `<$key></$key>`
path?: string, // Relative path of the atomic component to the npm root directory
require?: {
[propName: string]: string
} // Other components required by this component. Fill in the key of the dependent component. This is usually required only for composite component templates.
externalClasses?: string[] // External style classes
}
Component icon, as shown below
Component topIcon, as shown below
For example, the simplest component, button, although not very useful:
{
"button": {
"key": "td-button",
"icon": "",
"label": "Button"
}
2.2.1 Component Custom Template tpl
The tpl field specifies the node structure content generated by using the component. If it is empty, the system defaults to constructing an empty tag using the component's key, such as <td-button />.
{
"key": "td-button",
"icon": "",
"label": "Button",
"tpl": "<td-button />"
}
If you need to customize it, the corresponding tpl will be output, such as <td-button type="warn">Button</td-view>.
{
"key": "td-button",
"icon": "",
"label": "Button",
"tpl": "<td-button type=\"warn\">Button</td-button>"
}
2.2.2 Component Dependency Path path
If a component is a custom component, it must be loaded via dependency. path specifies the component's defined path, relative to the root directory of the component library.
{
"key": "td-button",
"icon": "",
"label": "Button",
"tpl": "<td-button type=\"warn\">Button</td-button>",
"path": "./dist/components/button/index"
}
2.2.3 Explanation of Dependency Configuration for Composite Components: require
If the tpl configuration consists of multiple custom components (i.e., not a single custom component), and there are multiple dependencies, you can configure them using the require field.
{
"key": "td-button-group",
"icon": "",
"label": "Button",
"tpl": "<view><td-button type=\"warn\">Button</td-button> <t-icon></t-icon><view>",
"require": {
"td-icon": "./dist/components/icon/index",
"td-button": "./dist/components/button/index"
}
}
2.2.4 Component Event IComponentEvent
The component event IComponentEvent defines the events that can be configured for custom components.
interface IIBComponentLibConfigEvent {
key: string; // Event name, e.g., "onChange"
label: string; // Human-readable label for the event
desc: string; // Description of the event
references?: IIBComponentLibConfigPropertyReferences // Documentation for component properties
}
// Documentation URL for event details
interface IIBComponentLibConfigPropertyReferences {
desc: string,
url: string
}
Example: The following code defines an onClick event property.
{
"key": "td-button-group",
"icon": "",
"label": "Button",
"tpl": "<td-button type=\"warn\">Button</td-button>",
"path": "./dist/components/button/index",
"events": [
{
"key": "onClick",
"label": "Click Handler",
"desc": "Triggered when the button is clicked"
}
]
}
2.2.5 Component Properties IComponentProperty
The IComponentProperty interface describes the configurable properties of a component.
type ComponentPropertyType = 'Boolean' | 'String' | 'Color' | 'Image' | 'Enum' | 'Number' | 'Object' | 'Array'
export interface IIBComponentLibConfigProperty {
key: string; // Property name, e.g., "value"
label: string; // Human-readable name for the property
desc: string; // Description of the property
type: ComponentPropertyType[]; // Property value type(s) (multiple allowed)
defaultValue?: any // @TODO
enum?: any[] // @TODO Enumeration, corresponds to dropdown selection
references?: IIBComponentLibConfigPropertyReferences // @TODO Component property documentation
}
The following example defines the type property of a button, where its value type is a string and the default value is "normal".
{
"key": "td-button-group",
"icon": "",
"label": "Button",
"tpl": "<td-button type=\"warn\">Button</td-button>",
"path": "./dist/components/button/index",
"properties": [
{
"key": "text",
"label": "Text",
"desc": "Button text",
"type": "String",
"defaultValue": "normal"
},
{
"key": "type",
"label": "Type",
"desc": "Button type",
"type": "Enum",
"defaultValue": "a",
"details": [
"a", "b", "c"
]
}
]
}
2.2.6 Reusing Common properties and events (Not supported yet)
You can define common properties and events in common. When using the components, you only need to specify the corresponding key values.
{
"common": {
"properties": {
"commonText": {
"key": "text",
"label": "Text",
"desc": "Button text",
"type": "String",
"defaultValue": "normal"
}
}
},
"components": [
{
"key": "td-button-group",
"icon": "",
"label": "Button",
"tpl": "<td-button type=\"warn\">Button</td-button>",
"path": "./dist/components/button/index",
"properties": [
"commonText",
{
"key": "type",
"label": "Type",
"desc": "Button type",
"type": "Enum",
"defaultValue": "a",
"details": ["a", "b", "c"]
}
]
}
]
}
2.3 Component Definition Menu
The menu defines the hierarchical structure of display components. Currently, only a three-level structure is supported.
- Component type
- Component sub-type
- Specific component
// Level 1 Menu
// Level 1 Menu
export interface IIBComponentLibConfigMenu {
key: string; // Unique identifier for the menu
label: string; // Human-readable name of the menu
icon?: string // Menu icon (20*20)
submenu: IIBComponentLibConfigSubMenu[];
}
// Level 2 Menu
export interface IIBComponentLibConfigSubMenu {
key: string; // Unique identifier for the level 2 menu
label: string; // Human-readable name of the level 2 menu
components: string[]; // Corresponding component keys
}
Example:
{
"menu": [
{
"key": "form",
"label": "Form Components",
"icon": "",
"submenu": [
{
"label": "Button",
"key": "button",
"compnents": ["button", "button-group"]
}
]
}
]
}
Complete Description
/**
* Visual Component Library Configuration Specification
*/
export interface IIBComponentLibConfig {
key: string // Component library identifier
label: string // Readable name
// Component list description configuration
components: {
[propName: string]: IIBComponentLibConfigComponent
};
// Menu related
topList?: string[], // General component list at the top of the component panel, max 5 items. The configured content is the key of the components in components
menu: IIBComponentLibConfigMenu[], // Menu status of the component panel
// @TODO: Other configurations
remote?: string // @TODO Remote configuration address, will be read to update later
common: IIBComponentLibConfigCommon // @TODO
}
// Common properties and events
export interface IIBComponentLibConfigCommon {
properties?: {
[proName: string]: IIBComponentLibConfigProperty;
}, // General properties
events?: {
[proName: string]: IIBComponentLibConfigEvent;
}, // General events
}
export interface IIBComponentLibConfigComponent {
key?: string; // Component tag name, should be the same as the key in the component list, the tool will fill it in by default
label: string; // Readable name of the component
icon: string; // Component icon schematic, local or network address, recommended size is 200 * 100
topIcon?: string // If the component needs to be placed in the header, local or network address, recommended size 44 * 44, padding is 10
events?: IIBComponentLibConfigEvent[]; // Event list
properties?: IIBComponentLibConfigProperty[]; // Property list
tpl?: string; // Custom component module code, if empty, use key as the tag name to generate default tpl `<$key></$key>`
path?: string, // Relative path of atomic component from the npm root directory
require?: string[] // Other components dependent by the component, fill in the key of the dependent component, usually only needed for combined component tpl
}
interface IIBComponentLibConfigEvent {
key: string; // Event name, e.g., "onChange"
label: string; // Readable display name of the event
desc: string; // Description displayed for the event
references?: IIBComponentLibConfigPropertyReferences // Component property documentation
}
type ComponentPropertyType = 'Boolean' | 'String' | 'Color' | 'Image' | 'Enum' | 'Number' | 'Object' | 'Array'
export interface IIBComponentLibConfigProperty {
key: string; // Property name, e.g., "value"
label: string; // Readable display name of the property
desc: string; // Description displayed for the property
type: ComponentPropertyType[]; // Property value type(s) (multiple types)
defaultValue?: any // @TODO
enum?: any[] // @TODO Enum, corresponds to dropdown selection
references?: IIBComponentLibConfigPropertyReferences // @TODO Component property documentation
}
// Corresponding documentation address
export interface IIBComponentLibConfigPropertyReferences {
desc: string,
url: string
}
// First-level menu
export interface IIBComponentLibConfigMenu {
key: string; // Unique identifier for the menu
label: string; // Readable name of the menu
icon?: string // Menu icon 20*20
submenu: IIBComponentLibConfigSubMenu[];
}
// Second-level menu
export interface IIBComponentLibConfigSubMenu {
key: string; // Unique identifier for the second-level menu
label: string; // Readable name of the second-level menu
components: string[]; // Corresponding component keys
}