PocketBlocks Docs
English
English
  • Overview
  • Installation
  • Build apps
    • Create a new app
    • App editor
    • Event handlers
    • Write JavaScript
      • Write JavaScript in {{ }}
      • JavaScript query
      • Transformers
      • Temporary state
      • Data responder
      • Built-in JavaScript functions
      • Use third-party libraries
    • Component guides
      • Option lists
      • List View
      • Drawer
      • Image
      • Charts and graphs
      • File upload
      • Custom component
      • Use Markdown
    • Module
    • Design app UI
      • Style, theme, and usability
      • Design an efficient and user-friendly form
    • Navigation
    • Keyboard shortcuts
    • Version and release management
  • Build plugins
    • Develop UI component plugins
  • Workspace management
    • Authentication
    • Members and groups
    • Permissions for resources
    • Custom branding
  • Miscellaneous
    • Where are the Data Sources/Query Library?
    • Embedding Apps
Powered by GitBook
On this page
  • Initialization
  • Component development environment
  • Plugin configurations
  • Export components
  • Publish plugins
  • Import plugins
  • Code demo
  1. Build plugins

Develop UI component plugins

PreviousVersion and release managementNextAuthentication

Last updated 11 months ago

With PocketBLocks plugins, you can develop customized components that are consistent with native components for your specific scenarios.

Initialization

Execute the following commands:

# Project initiation
yarn create pocketblocks-plugin my-plugin

# Go to the project root
cd my-plugin

# Start the development environment
yarn start

Component development environment

After executing yarn start, the browser is automatically opened and you enter the component development environment.

Plugin configurations

In openblocks field in package.json file, you need to define the component properties. For example, the following is the explanation of several fields:

  • comps defines UI components contained in the plugin. For each component, the key name of the object is the unique identity, and the value is metadata.

  • comps[someCompKey].name defines the component name shown in the Insert tab.

  • comps[someCompKey].icon defines the component icon shown on the canvas. Use a relative path to where package.json file is located.

  • comps[someCompKey].layoutInfo defines the component layout:

    • w: width of the component. Counted by the number of grid cells (range: 1 - 24).

    • h: height of the component. Counted by the number of grid cells (range: >= 1).

  "openblocks": {
    "description": "",
    "comps": {
      "hello_world": {
        "name": "Hello World",
        "icon": "./icons/hello_world.png",
        "layoutInfo": {
          "w": 12,
          "h": 5
        }
      },
      "counter": {
        "name": "Counter",
        "icon": "./icons/hello_world.png"
      }
    }
  }

Export components

To export all the components, use src/index.ts, for example:

import HelloWorldComp from "./HelloWorldComp";

export default {
  hello_world: HelloWorldComp,
};

The default exported object key needs to be consistent with the key configured in comps in package.json file.

Publish plugins

When you finish developing and testing the plugin, you can publish it into the npm registry. Login in to the npm registry locally, and then execute the following command:

yarn build --publish

If you do not specify the parameter --publish, the tar file will be saved in the root folder.

Import plugins

Input your npm package's URL or name, and then you can use your customized components.

my-plugin

# or

https://www.npmjs.com/package/my-plugin

Code demo

In the PocketBLocks app, click Insert > Extensions > Add npm plugin in the right pane.

For code demo, refer to PocketBlocks .

Github
Screenshot of component development environment