Dynamically load ESM modules or CSS via URL, applicable to various RunJS scenarios. Use ctx.importAsync() when third-party ESM libraries are required, and ctx.requireAsync() for UMD/AMD libraries. Passing a .css address will load and inject the styles into the page.
| Scenario | Description |
|---|---|
| JSBlock | Dynamically load ESM libraries such as Vue, ECharts, or Tabulator to implement custom charts, tables, dashboards, etc. |
| JSField / JSItem / JSColumn | Load lightweight ESM utility libraries (e.g., dayjs plugins) to assist in rendering. |
| Workflow / Action Events | Load dependencies on demand before executing business logic. |
| Parameter | Type | Description |
|---|---|---|
url | string | The address of the ESM module or CSS. Supports shorthand <package>@<version> or subpaths <package>@<version>/<file-path> (e.g., vue@3.4.0, dayjs@1/plugin/relativeTime.js), which will be concatenated with the CDN prefix according to the configuration. Full URLs are also supported. When a .css file is passed, it will be loaded and injected as a style. For libraries depending on React, you can append ?deps=react@18.2.0,react-dom@18.2.0 to ensure they share the same React instance with the page. |
.css URL to load and inject it into the page).vue@3.4.0 actually requests https://esm.sh/vue@3.4.0.@dnd-kit/core, react-big-calendar) should append ?deps=react@18.2.0,react-dom@18.2.0 to avoid conflicts with the page's React instance, which could lead to "Invalid hook call" errors.https://esm.sh)./+esm for jsDelivr).ctx.importAsync() is preferred.Demonstrates the most basic usage of dynamically loading ESM modules and CSS by package name or full URL.
Use ECharts to draw a sales overview chart with bar and line graphs.
Demonstrates rendering a data table with pagination and row click events in a block using Tabulator.
Shows how to load FullCalendar and its plugins via ESM and render a basic monthly view calendar.
Uses @dnd-kit/core to implement a minimal example of dragging a Box to a target area within a block.
This example relies only on @dnd-kit/core to trigger a notification when a Box is dropped into a specific area, demonstrating the simplest drag-and-drop interaction combining ctx.importAsync and React in RunJS.
Implements a vertical sortable list using dnd-kit's core, sortable, and utilities.
This example uses @dnd-kit/core, @dnd-kit/sortable, and @dnd-kit/utilities to implement a sortable list that updates its order and displays a "List reordered" message after dragging.
Renders a calendar component supporting event display in the current block using react-big-calendar and date-fns for localization.
Uses frappe-gantt to render a Gantt chart view showing task start/end times and progress.
Utilizes @asseinfo/react-kanban to render a basic Kanban board with columns like Backlog and Doing within a block.
ctx.importAsync() for better module semantics.?deps=react@18.2.0,react-dom@18.2.0. The version must match the React version used by the page, otherwise, an "Invalid hook call" error may occur.