@nocobase/plugin-flow-engine 2.1.0-alpha.9 → 2.1.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/ai/docs/runjs/context/block-model.md +35 -35
  2. package/dist/ai/docs/runjs/context/collection-field.md +51 -53
  3. package/dist/ai/docs/runjs/context/collection.md +39 -39
  4. package/dist/ai/docs/runjs/context/data-source-manager.md +30 -40
  5. package/dist/ai/docs/runjs/context/data-source.md +44 -52
  6. package/dist/ai/docs/runjs/context/element.md +38 -44
  7. package/dist/ai/docs/runjs/context/exit-all.md +35 -37
  8. package/dist/ai/docs/runjs/context/exit.md +35 -38
  9. package/dist/ai/docs/runjs/context/filter-manager.md +30 -36
  10. package/dist/ai/docs/runjs/context/form.md +57 -57
  11. package/dist/ai/docs/runjs/context/get-model.md +21 -22
  12. package/dist/ai/docs/runjs/context/get-value.md +19 -20
  13. package/dist/ai/docs/runjs/context/get-var.md +55 -61
  14. package/dist/ai/docs/runjs/context/i18n.md +14 -17
  15. package/dist/ai/docs/runjs/context/import-async.md +45 -333
  16. package/dist/ai/docs/runjs/context/init-resource.md +20 -20
  17. package/dist/ai/docs/runjs/context/libs.md +31 -31
  18. package/dist/ai/docs/runjs/context/location.md +31 -34
  19. package/dist/ai/docs/runjs/context/logger.md +40 -41
  20. package/dist/ai/docs/runjs/context/make-resource.md +26 -27
  21. package/dist/ai/docs/runjs/context/message.md +41 -42
  22. package/dist/ai/docs/runjs/context/modal.md +44 -44
  23. package/dist/ai/docs/runjs/context/model.md +33 -36
  24. package/dist/ai/docs/runjs/context/notification.md +40 -41
  25. package/dist/ai/docs/runjs/context/off.md +14 -14
  26. package/dist/ai/docs/runjs/context/on.md +29 -30
  27. package/dist/ai/docs/runjs/context/open-view.md +40 -40
  28. package/dist/ai/docs/runjs/context/render.md +32 -37
  29. package/dist/ai/docs/runjs/context/request.md +45 -46
  30. package/dist/ai/docs/runjs/context/require-async.md +25 -28
  31. package/dist/ai/docs/runjs/context/resource.md +34 -34
  32. package/dist/ai/docs/runjs/context/route.md +34 -36
  33. package/dist/ai/docs/runjs/context/router.md +31 -43
  34. package/dist/ai/docs/runjs/context/set-value.md +17 -18
  35. package/dist/ai/docs/runjs/context/t.md +17 -20
  36. package/dist/ai/docs/runjs/context/view.md +46 -49
  37. package/dist/ai/docs/runjs/document.md +0 -1
  38. package/dist/ai/docs/runjs/import-modules.md +32 -32
  39. package/dist/ai/docs/runjs/index.md +13 -13
  40. package/dist/ai/docs/runjs/jsx.md +19 -19
  41. package/dist/ai/docs/runjs/model/form-block-model.md +3 -1
  42. package/dist/ai/docs/runjs/render.md +15 -15
  43. package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
  44. package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
  45. package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
  46. package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
  47. package/dist/ai/docs/runjs/window.md +5 -5
  48. package/dist/externalVersion.js +10 -10
  49. package/dist/node_modules/ses/package.json +1 -1
  50. package/dist/node_modules/zod/package.json +1 -1
  51. package/package.json +2 -2
@@ -1,17 +1,17 @@
1
1
  # ctx.openView()
2
2
 
3
- Programmatically open a specified view (drawer, dialog, embedded page, etc.). Provided by `FlowModelContext`, it is used to open configured `ChildPage` or `PopupAction` views in scenarios such as `JSBlock`, table cells, and workflows.
3
+ Opens a configured view (drawer, dialog, embed, etc.) programmatically. Provided by FlowModelContext; used in JSBlock, table cells, event flow, etc. to open ChildPage or PopupAction views.
4
4
 
5
5
  ## Use Cases
6
6
 
7
7
  | Scenario | Description |
8
- |------|------|
9
- | **JSBlock** | Open a detail/edit dialog after a button click, passing the current row's `filterByTk`. |
10
- | **Table Cell** | Render a button within a cell that opens a row detail dialog when clicked. |
11
- | **Workflow / JSAction** | Open the next view or a dialog after a successful operation. |
12
- | **Association Field** | Open a selection/edit dialog via `ctx.runAction('openView', params)`. |
8
+ |----------|-------------|
9
+ | **JSBlock** | Button opens detail/edit dialog; pass current row `filterByTk` |
10
+ | **Table cell** | Button in cell opens row detail dialog |
11
+ | **Event flow / JSAction** | Open next view or dialog after action success |
12
+ | **Association field** | `ctx.runAction('openView', params)` for select/edit dialog |
13
13
 
14
- > Note: `ctx.openView` is available in a RunJS environment where a `FlowModel` context exists. If the model corresponding to the `uid` does not exist, a `PopupActionModel` will be automatically created and persisted.
14
+ > Note: `ctx.openView` requires a FlowModel context; if no model exists for the uid, a PopupActionModel is created and persisted.
15
15
 
16
16
  ## Signature
17
17
 
@@ -23,46 +23,46 @@ openView(uid: string, options?: OpenViewOptions): Promise<void>
23
23
 
24
24
  ### uid
25
25
 
26
- The unique identifier of the view model. If it does not exist, it will be automatically created and saved. It is recommended to use a stable UID, such as `${ctx.model.uid}-detail`, so that the configuration can be reused when opening the same dialog multiple times.
26
+ Unique id of the view model. If missing, it is created and saved. Use a stable uid (e.g. `${ctx.model.uid}-detail`) so the same popup can be reused.
27
27
 
28
- ### Common options Fields
28
+ ### options (common fields)
29
29
 
30
30
  | Field | Type | Description |
31
- |------|------|------|
32
- | `mode` | `drawer` / `dialog` / `embed` | Opening method: drawer, dialog, or embedded. Defaults to `drawer`. |
33
- | `size` | `small` / `medium` / `large` | Size of the dialog or drawer. Defaults to `medium`. |
34
- | `title` | `string` | View title. |
35
- | `params` | `Record<string, any>` | Arbitrary parameters passed to the view. |
36
- | `filterByTk` | `any` | Primary key value, used for single record detail/edit scenarios. |
37
- | `sourceId` | `string` | Source record ID, used in association scenarios. |
38
- | `dataSourceKey` | `string` | Data source. |
39
- | `collectionName` | `string` | Collection name. |
40
- | `associationName` | `string` | Association field name. |
41
- | `navigation` | `boolean` | Whether to use route navigation. If `defineProperties` or `defineMethods` are provided, this is forced to `false`. |
42
- | `preventClose` | `boolean` | Whether to prevent closing. |
43
- | `defineProperties` | `Record<string, PropertyOptions>` | Dynamically inject properties into the model within the view. |
44
- | `defineMethods` | `Record<string, Function>` | Dynamically inject methods into the model within the view. |
31
+ |-------|------|-------------|
32
+ | `mode` | `drawer` / `dialog` / `embed` | How to open: drawer, dialog, embed; default `drawer` |
33
+ | `size` | `small` / `medium` / `large` | Dialog/drawer size; default `medium` |
34
+ | `title` | `string` | View title |
35
+ | `params` | `Record<string, any>` | Arbitrary params passed to the view |
36
+ | `filterByTk` | `any` | Primary key for single-record detail/edit |
37
+ | `sourceId` | `string` | Source record id (associations) |
38
+ | `dataSourceKey` | `string` | Data source |
39
+ | `collectionName` | `string` | Collection name |
40
+ | `associationName` | `string` | Association field name |
41
+ | `navigation` | `boolean` | Use route navigation; forced `false` when passing `defineProperties` / `defineMethods` |
42
+ | `preventClose` | `boolean` | Prevent close |
43
+ | `defineProperties` | `Record<string, PropertyOptions>` | Inject properties into view models |
44
+ | `defineMethods` | `Record<string, Function>` | Inject methods into view models |
45
45
 
46
46
  ## Examples
47
47
 
48
- ### Basic Usage: Open a Drawer
48
+ ### Basic: open drawer
49
49
 
50
50
  ```ts
51
51
  const popupUid = `${ctx.model.uid}-detail`;
52
52
  await ctx.openView(popupUid, {
53
53
  mode: 'drawer',
54
54
  size: 'medium',
55
- title: ctx.t('Details'),
55
+ title: ctx.t('Detail'),
56
56
  });
57
57
  ```
58
58
 
59
- ### Passing Current Row Context
59
+ ### Pass current row context
60
60
 
61
61
  ```ts
62
62
  const primaryKey = ctx.collection?.primaryKey || 'id';
63
63
  await ctx.openView(`${ctx.model.uid}-1`, {
64
64
  mode: 'dialog',
65
- title: ctx.t('Row Details'),
65
+ title: ctx.t('Row detail'),
66
66
  params: {
67
67
  filterByTk: ctx.record?.[primaryKey],
68
68
  record: ctx.record,
@@ -72,7 +72,7 @@ await ctx.openView(`${ctx.model.uid}-1`, {
72
72
 
73
73
  ### Open via runAction
74
74
 
75
- When a model is configured with an `openView` action (such as association fields or clickable fields), you can call:
75
+ When the model has an openView action (e.g. association field, clickable field):
76
76
 
77
77
  ```ts
78
78
  await ctx.runAction('openView', {
@@ -83,7 +83,7 @@ await ctx.runAction('openView', {
83
83
  });
84
84
  ```
85
85
 
86
- ### Injecting Custom Context
86
+ ### Inject custom context
87
87
 
88
88
  ```ts
89
89
  await ctx.openView(`${ctx.model.uid}-edit`, {
@@ -98,23 +98,23 @@ await ctx.openView(`${ctx.model.uid}-edit`, {
98
98
  });
99
99
  ```
100
100
 
101
- ## Relationship with ctx.viewer and ctx.view
101
+ ## Relation to ctx.viewer, ctx.view
102
102
 
103
- | Purpose | Recommended Usage |
104
- |------|----------|
105
- | **Open a configured flow view** | `ctx.openView(uid, options)` |
103
+ | Use | Recommended |
104
+ |-----|-------------|
105
+ | **Open configured flow view** | `ctx.openView(uid, options)` |
106
106
  | **Open custom content (no flow)** | `ctx.viewer.dialog()` / `ctx.viewer.drawer()` |
107
- | **Operate on the currently open view** | `ctx.view.close()`, `ctx.view.inputArgs` |
107
+ | **Operate current view** | `ctx.view.close()`, `ctx.view.inputArgs` |
108
108
 
109
- `ctx.openView` opens a `FlowPage` (`ChildPageModel`), which renders a complete flow page internally; `ctx.viewer` opens arbitrary React content.
109
+ `ctx.openView` opens a FlowPage (ChildPageModel) with a full flow; `ctx.viewer` opens arbitrary React content.
110
110
 
111
111
  ## Notes
112
112
 
113
- - It is recommended to associate the `uid` with `ctx.model.uid` (e.g., `${ctx.model.uid}-xxx`) to avoid conflicts between multiple blocks.
114
- - When `defineProperties` or `defineMethods` are passed, `navigation` is forced to `false` to prevent context loss after a refresh.
115
- - Inside the dialog, `ctx.view` refers to the current view instance, and `ctx.view.inputArgs` can be used to read the parameters passed during opening.
113
+ - Prefer uids related to `ctx.model.uid` (e.g. `${ctx.model.uid}-xxx`) to avoid conflicts between blocks.
114
+ - When passing `defineProperties` / `defineMethods`, `navigation` is forced to `false` so context is not lost on refresh.
115
+ - Inside a popup, `ctx.view` is the current view and `ctx.view.inputArgs` holds the params passed when opening.
116
116
 
117
117
  ## Related
118
118
 
119
- - [ctx.view](./view.md): The currently open view instance.
120
- - [ctx.model](./model.md): The current model, used to construct a stable `popupUid`.
119
+ - [ctx.view](./view.md): current view instance
120
+ - [ctx.model](./model.md): current model; use for stable popupUid
@@ -1,18 +1,18 @@
1
1
  # ctx.render()
2
2
 
3
- Renders React elements, HTML strings, or DOM nodes into a specified container. If `container` is not provided, it defaults to rendering into `ctx.element` and automatically inherits the application's context, such as ConfigProvider and themes.
3
+ Renders a React element, HTML string, or DOM node into a container. Without `container`, renders into `ctx.element` and inherits the app’s ConfigProvider, theme, etc.
4
4
 
5
5
  ## Use Cases
6
6
 
7
7
  | Scenario | Description |
8
- |------|------|
9
- | **JSBlock** | Render custom block content (charts, lists, cards, etc.) |
10
- | **JSField / JSItem / JSColumn** | Render custom displays for editable fields or table columns |
11
- | **Details Block** | Customize the display format of fields in details pages |
8
+ |----------|-------------|
9
+ | **JSBlock** | Custom block content (charts, lists, cards, etc.) |
10
+ | **JSField / JSItem / JSColumn** | Custom editable field or table column |
11
+ | **Detail block** | Custom detail field display |
12
12
 
13
- > Note: `ctx.render()` requires a rendering container. If `container` is not passed and `ctx.element` does not exist (e.g., in pure logic scenarios without a UI), an error will be thrown.
13
+ > Note: `ctx.render()` needs a container. If you don’t pass `container` and `ctx.element` is missing (e.g. no-UI logic), an error is thrown.
14
14
 
15
- ## Type Definition
15
+ ## Type
16
16
 
17
17
  ```ts
18
18
  render(
@@ -22,27 +22,27 @@ render(
22
22
  ```
23
23
 
24
24
  | Parameter | Type | Description |
25
- |------|------|------|
26
- | `vnode` | `React.ReactElement` \| `Node` \| `DocumentFragment` \| `string` | Content to be rendered |
27
- | `container` | `Element` \| `DocumentFragment` (Optional) | Target rendering container, defaults to `ctx.element` |
25
+ |------------|------|-------------|
26
+ | `vnode` | `React.ReactElement` \| `Node` \| `DocumentFragment` \| `string` | Content to render |
27
+ | `container` | `Element` \| `DocumentFragment` (optional) | Target container; default `ctx.element` |
28
28
 
29
- **Return Value**:
29
+ **Returns**:
30
30
 
31
- - When rendering a **React element**: Returns `ReactDOMClient.Root`, making it easy to call `root.render()` for subsequent updates.
32
- - When rendering an **HTML string** or **DOM node**: Returns `null`.
31
+ - For **React element**: `ReactDOMClient.Root` (for later `root.render()` updates).
32
+ - For **HTML string** or **DOM node**: `null`.
33
33
 
34
- ## vnode Type Description
34
+ ## vnode types
35
35
 
36
36
  | Type | Behavior |
37
- |------|------|
38
- | `React.ReactElement` (JSX) | Rendered using React's `createRoot`, providing full React capabilities and automatically inheriting the application context. |
39
- | `string` | Sets the container's `innerHTML` after sanitization with DOMPurify; any existing React root will be unmounted first. |
40
- | `Node` (Element, Text, etc.) | Appends via `appendChild` after clearing the container; any existing React root will be unmounted first. |
41
- | `DocumentFragment` | Appends fragment child nodes to the container; any existing React root will be unmounted first. |
37
+ |------|----------|
38
+ | `React.ReactElement` (JSX) | Rendered with React `createRoot`; full React; inherits app context |
39
+ | `string` | Sanitized with DOMPurify and set as container `innerHTML`; existing React root is unmounted first |
40
+ | `Node` (Element, Text, etc.) | Container cleared then `appendChild`; existing React root unmounted first |
41
+ | `DocumentFragment` | Fragment children appended to container; existing React root unmounted first |
42
42
 
43
43
  ## Examples
44
44
 
45
- ### Rendering React Elements (JSX)
45
+ ### React (JSX)
46
46
 
47
47
  ```tsx
48
48
  const { Button, Card } = ctx.libs.antd;
@@ -56,26 +56,23 @@ ctx.render(
56
56
  );
57
57
  ```
58
58
 
59
- ### Rendering HTML Strings
59
+ ### HTML string
60
60
 
61
61
  ```ts
62
62
  ctx.render('<h1>Hello World</h1>');
63
63
 
64
- // Combining with ctx.t for internationalization
65
64
  ctx.render('<div style="padding:16px">' + ctx.t('Content') + '</div>');
66
65
 
67
- // Conditional rendering
68
66
  ctx.render(hasData ? `<ul>${items.map(i => `<li>${i}</li>`).join('')}</ul>` : '<span style="color:#999">' + ctx.t('No data') + '</span>');
69
67
  ```
70
68
 
71
- ### Rendering DOM Nodes
69
+ ### DOM node
72
70
 
73
71
  ```ts
74
72
  const div = document.createElement('div');
75
73
  div.textContent = 'Hello World';
76
74
  ctx.render(div);
77
75
 
78
- // Render an empty container first, then hand it over to a third-party library (e.g., ECharts) for initialization
79
76
  const container = document.createElement('div');
80
77
  container.style.width = '100%';
81
78
  container.style.height = '400px';
@@ -84,31 +81,29 @@ const chart = echarts.init(container);
84
81
  chart.setOption({ ... });
85
82
  ```
86
83
 
87
- ### Specifying a Custom Container
84
+ ### Custom container
88
85
 
89
86
  ```ts
90
- // Render to a specific DOM element
91
87
  const customEl = document.getElementById('my-container');
92
88
  ctx.render(<div>Content</div>, customEl);
93
89
  ```
94
90
 
95
- ### Multiple Calls Will Replace Content
91
+ ### Multiple calls replace content
96
92
 
97
93
  ```ts
98
- // The second call will replace the existing content in the container
99
94
  ctx.render(<div>First</div>);
100
- ctx.render(<div>Second</div>); // Only "Second" will be displayed
95
+ ctx.render(<div>Second</div>); // Only "Second" is shown
101
96
  ```
102
97
 
103
98
  ## Notes
104
99
 
105
- - **Multiple calls will replace content**: Each `ctx.render()` call replaces the existing content in the container rather than appending to it.
106
- - **HTML string safety**: Passed HTML is sanitized via DOMPurify to reduce XSS risks, but it is still recommended to avoid concatenating untrusted user input.
107
- - **Do not manipulate ctx.element directly**: `ctx.element.innerHTML` is deprecated; `ctx.render()` should be used consistently instead.
108
- - **Pass container when no default exists**: In scenarios where `ctx.element` is `undefined` (e.g., within modules loaded via `ctx.importAsync`), a `container` must be explicitly provided.
100
+ - **Each call replaces**: Content is replaced, not appended.
101
+ - **HTML safety**: HTML is sanitized with DOMPurify; still avoid concatenating untrusted user input.
102
+ - **Don’t touch ctx.element directly**: `ctx.element.innerHTML` is deprecated; use `ctx.render()`.
103
+ - **No container**: When `ctx.element` is `undefined` (e.g. inside a module loaded by `ctx.importAsync`), pass `container` explicitly.
109
104
 
110
105
  ## Related
111
106
 
112
- - [ctx.element](./element.md) - Default rendering container, used when no container is passed to `ctx.render()`.
113
- - [ctx.libs](./libs.md) - Built-in libraries like React and Ant Design, used for JSX rendering.
114
- - [ctx.importAsync()](./import-async.md) - Used in conjunction with `ctx.render()` after loading external React/component libraries on demand.
107
+ - [ctx.element](./element.md): default container when `container` is not passed
108
+ - [ctx.libs](./libs.md): React, antd, etc. for JSX
109
+ - [ctx.importAsync()](./import-async.md): load external React/components then use with `ctx.render()`
@@ -1,60 +1,60 @@
1
1
  # ctx.request()
2
2
 
3
- Initiate an authenticated HTTP request within RunJS. The request automatically carries the current application's `baseURL`, `Token`, `locale`, `role`, etc., and follows the application's request interception and error handling logic.
3
+ Sends authenticated HTTP requests from RunJS. Requests use the app’s baseURL, token, locale, role, etc., and the app’s interceptors and error handling.
4
4
 
5
5
  ## Use Cases
6
6
 
7
- Applicable to any scenario in RunJS where a remote HTTP request needs to be initiated, such as JSBlock, JSField, JSItem, JSColumn, Workflow, Linkage, JSAction, etc.
7
+ Use whenever RunJS needs to call a remote HTTP API: JSBlock, JSField, JSItem, JSColumn, event flow, linkage, JSAction, etc.
8
8
 
9
- ## Type Definition
9
+ ## Type
10
10
 
11
11
  ```typescript
12
12
  request(options: RequestOptions): Promise<AxiosResponse<any>>;
13
13
  ```
14
14
 
15
- `RequestOptions` extends Axios's `AxiosRequestConfig`:
15
+ `RequestOptions` extends Axios `AxiosRequestConfig`:
16
16
 
17
17
  ```typescript
18
18
  type RequestOptions = AxiosRequestConfig & {
19
- skipNotify?: boolean | ((error: any) => boolean); // Whether to skip global error prompts when the request fails
20
- skipAuth?: boolean; // Whether to skip authentication redirection (e.g., do not redirect to login page on 401)
19
+ skipNotify?: boolean | ((error: any) => boolean); // Skip global error toast on failure
20
+ skipAuth?: boolean; // Skip auth redirect (e.g. 401 login)
21
21
  };
22
22
  ```
23
23
 
24
- ## Common Parameters
24
+ ## Common parameters
25
25
 
26
26
  | Parameter | Type | Description |
27
- |------|------|------|
28
- | `url` | string | Request URL. Supports resource style (e.g., `users:list`, `posts:create`), or a full URL |
29
- | `method` | 'get' \| 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method, defaults to `'get'` |
30
- | `params` | object | Query parameters, serialized into the URL |
31
- | `data` | any | Request body, used for post/put/patch |
32
- | `headers` | object | Custom request headers |
33
- | `skipNotify` | boolean \| (error) => boolean | If true or the function returns true, global error prompts will not pop up on failure |
34
- | `skipAuth` | boolean | If true, 401 errors etc. will not trigger authentication redirection (e.g., redirecting to the login page) |
27
+ |-----------|------|-------------|
28
+ | `url` | string | URL. Supports resource style (e.g. `users:list`, `posts:create`) or full URL |
29
+ | `method` | 'get' \| 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method; default `'get'` |
30
+ | `params` | object | Query params (serialized to URL) |
31
+ | `data` | any | Request body for post/put/patch |
32
+ | `headers` | object | Custom headers |
33
+ | `skipNotify` | boolean \| (error) => boolean | When true or function returns true, no global error message |
34
+ | `skipAuth` | boolean | When true, 401 etc. do not trigger auth redirect (e.g. to login) |
35
35
 
36
- ## Resource Style URL
36
+ ## Resource-style URL
37
37
 
38
- NocoBase Resource API supports a shorthand `resource:action` format:
38
+ NocoBase resource API supports `resource:action` shorthand:
39
39
 
40
40
  | Format | Description | Example |
41
- |------|------|------|
42
- | `collection:action` | Single collection CRUD | `users:list`, `users:get`, `users:create`, `posts:update` |
43
- | `collection.relation:action` | Associated resources (requires passing the primary key via `resourceOf` or URL) | `posts.comments:list` |
41
+ |--------|-------------|---------|
42
+ | `collection:action` | Single-table CRUD | `users:list`, `users:get`, `users:create`, `posts:update` |
43
+ | `collection.relation:action` | Association (need `resourceOf` or primary key in URL) | `posts.comments:list` |
44
44
 
45
- Relative paths will be concatenated with the application's `baseURL` (usually `/api`); cross-origin requests must use a full URL, and the target service must be configured with CORS.
45
+ Relative URLs are joined with the app baseURL (usually `/api`). For cross-origin, use a full URL and ensure CORS on the target.
46
46
 
47
- ## Response Structure
47
+ ## Response
48
48
 
49
- The return value is an Axios response object. Common fields include:
49
+ Returns Axios response. Common usage:
50
50
 
51
- - `response.data`: Response body
52
- - List interfaces usually return `data.data` (array of records) + `data.meta` (pagination, etc.)
53
- - Single record/create/update interfaces usually return the record in `data.data`
51
+ - `response.data`: response body
52
+ - List APIs often have `data.data` (records) + `data.meta` (pagination)
53
+ - Single/create/update often have `data.data` as one record
54
54
 
55
55
  ## Examples
56
56
 
57
- ### List Query
57
+ ### List
58
58
 
59
59
  ```javascript
60
60
  const { data } = await ctx.request({
@@ -64,22 +64,22 @@ const { data } = await ctx.request({
64
64
  });
65
65
 
66
66
  const rows = Array.isArray(data?.data) ? data.data : [];
67
- const meta = data?.meta; // Pagination and other info
67
+ const meta = data?.meta;
68
68
  ```
69
69
 
70
- ### Submit Data
70
+ ### Create
71
71
 
72
72
  ```javascript
73
73
  const res = await ctx.request({
74
74
  url: 'users:create',
75
75
  method: 'post',
76
- data: { nickname: 'John Doe', email: 'johndoe@example.com' },
76
+ data: { nickname: 'John', email: 'john@example.com' },
77
77
  });
78
78
 
79
79
  const newRecord = res?.data?.data;
80
80
  ```
81
81
 
82
- ### With Filtering and Sorting
82
+ ### Filter and sort
83
83
 
84
84
  ```javascript
85
85
  const res = await ctx.request({
@@ -93,16 +93,15 @@ const res = await ctx.request({
93
93
  });
94
94
  ```
95
95
 
96
- ### Skip Error Notification
96
+ ### Skip error notify
97
97
 
98
98
  ```javascript
99
99
  const res = await ctx.request({
100
100
  url: 'some:action',
101
101
  method: 'get',
102
- skipNotify: true, // Do not pop up global message on failure
102
+ skipNotify: true,
103
103
  });
104
104
 
105
- // Or decide whether to skip based on error type
106
105
  const res2 = await ctx.request({
107
106
  url: 'some:action',
108
107
  method: 'get',
@@ -110,9 +109,9 @@ const res2 = await ctx.request({
110
109
  });
111
110
  ```
112
111
 
113
- ### Cross-Origin Request
112
+ ### Cross-origin
114
113
 
115
- When using a full URL to request other domains, the target service must be configured with CORS to allow the current application's origin. If the target interface requires its own token, it can be passed via headers:
114
+ For other domains, the target must allow CORS. For its own token, pass in headers:
116
115
 
117
116
  ```javascript
118
117
  const res = await ctx.request({
@@ -124,12 +123,12 @@ const res2 = await ctx.request({
124
123
  url: 'https://api.other.com/items',
125
124
  method: 'get',
126
125
  headers: {
127
- Authorization: 'Bearer <target_service_token>',
126
+ Authorization: 'Bearer <target-token>',
128
127
  },
129
128
  });
130
129
  ```
131
130
 
132
- ### Displaying with ctx.render
131
+ ### With ctx.render
133
132
 
134
133
  ```javascript
135
134
  const { data } = await ctx.request({
@@ -141,7 +140,7 @@ const rows = Array.isArray(data?.data) ? data.data : [];
141
140
 
142
141
  ctx.render([
143
142
  '<div style="padding:12px">',
144
- '<h4>' + ctx.t('User List') + '</h4>',
143
+ '<h4>' + ctx.t('User list') + '</h4>',
145
144
  '<ul>',
146
145
  ...rows.map((r) => '<li>' + (r.nickname ?? r.username ?? '') + '</li>'),
147
146
  '</ul>',
@@ -151,13 +150,13 @@ ctx.render([
151
150
 
152
151
  ## Notes
153
152
 
154
- - **Error Handling**: Request failure will throw an exception, and a global error prompt will pop up by default. Use `skipNotify: true` to catch and handle it yourself.
155
- - **Authentication**: Same-origin requests will automatically carry the current user's Token, locale, and role; cross-origin requests require the target to support CORS and pass the token in headers as needed.
156
- - **Resource Permissions**: Requests are subject to ACL constraints and can only access resources the current user has permission for.
153
+ - **Errors**: Failed requests throw; by default a global error message is shown. Use `skipNotify: true` to handle yourself.
154
+ - **Auth**: Same-origin requests automatically send token, locale, role; cross-origin needs CORS and optional token in headers.
155
+ - **ACL**: Requests are subject to ACL; only resources the user can access are available.
157
156
 
158
157
  ## Related
159
158
 
160
- - [ctx.message](./message.md) - Display lightweight prompts after the request is completed
161
- - [ctx.notification](./notification.md) - Display notifications after the request is completed
162
- - [ctx.render](./render.md) - Render request results to the interface
163
- - [ctx.makeResource](./make-resource.md) - Construct a resource object for chained data loading (alternative to `ctx.request`)
159
+ - [ctx.message](./message.md): short feedback after request
160
+ - [ctx.notification](./notification.md): notification after request
161
+ - [ctx.render](./render.md): render result in UI
162
+ - [ctx.makeResource](./make-resource.md): build resource for chained loading (alternative to direct `ctx.request`)
@@ -1,12 +1,12 @@
1
1
  # ctx.requireAsync()
2
2
 
3
- Asynchronously loads **UMD/AMD** or globally mounted scripts via URL, as well as **CSS**. It is suitable for RunJS scenarios that require UMD/AMD libraries such as ECharts, Chart.js, FullCalendar (UMD version), or jQuery plugins. If a library also provides an ESM version, prioritize using [ctx.importAsync()](./import-async.md).
3
+ Loads **UMD/AMD** or global scripts by URL asynchronously; can also load **CSS**. Use for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins, etc. in RunJS; pass a `.css` URL to load and inject styles. If a library provides ESM, prefer [ctx.importAsync()](./import-async.md).
4
4
 
5
5
  ## Use Cases
6
6
 
7
- Can be used in any RunJS scenario where UMD/AMD/global scripts or CSS need to be loaded on demand, such as JSBlock, JSField, JSItem, JSColumn, Workflow, JSAction, etc. Typical uses: ECharts, Chart.js, FullCalendar (UMD), dayjs (UMD), jQuery plugins, etc.
7
+ Use whenever RunJS needs to load UMD/AMD/global scripts or CSS: JSBlock, JSField, JSItem, JSColumn, event flow, JSAction, etc. Typical: ECharts, Chart.js, FullCalendar (UMD), dayjs (UMD), jQuery plugins.
8
8
 
9
- ## Type Definition
9
+ ## Type
10
10
 
11
11
  ```ts
12
12
  requireAsync<T = any>(url: string): Promise<T>;
@@ -16,40 +16,37 @@ requireAsync<T = any>(url: string): Promise<T>;
16
16
 
17
17
  | Parameter | Type | Description |
18
18
  |-----------|------|-------------|
19
- | `url` | `string` | The script or CSS address. Supports **shorthand** `<package>@<version>/<file-path>` (appends `?raw` for the original UMD file when resolved via ESM CDN) or a **full URL**. Loads and injects styles if a `.css` file is passed. |
19
+ | `url` | `string` | Script or CSS URL. Supports **shorthand** `<package>@<version>/<path>` (ESM CDN adds `?raw` for raw UMD) or **full URL**. `.css` URLs load and inject styles. |
20
20
 
21
- ## Return Value
21
+ ## Returns
22
22
 
23
- - The loaded library object (the first module value of the UMD/AMD callback). Many UMD libraries attach themselves to `window` (e.g., `window.echarts`), so the return value might be `undefined`. In such cases, access the global variable as per the library's documentation.
24
- - Returns the result of `loadCSS` when a `.css` file is passed.
23
+ - Loaded library object (first module value from UMD/AMD callback). Many UMD libs attach to `window` (e.g. `window.echarts`); return value may be `undefined`—use the library’s docs for how to access.
24
+ - For `.css` URLs, returns the result of `loadCSS`.
25
25
 
26
- ## URL Format Description
26
+ ## URL format
27
27
 
28
- - **Shorthand path**: e.g., `echarts@5/dist/echarts.min.js`. Under the default ESM CDN (esm.sh), it requests `https://esm.sh/echarts@5/dist/echarts.min.js?raw`. The `?raw` parameter is used to fetch the original UMD file instead of an ESM wrapper.
29
- - **Full URL**: Any CDN address can be used directly, such as `https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js`.
30
- - **CSS**: A URL ending in `.css` will be loaded and injected into the page.
28
+ - **Shorthand**: e.g. `echarts@5/dist/echarts.min.js`; with default ESM CDN (esm.sh) becomes `https://esm.sh/echarts@5/dist/echarts.min.js?raw`; `?raw` fetches the raw UMD file.
29
+ - **Full URL**: Any CDN URL, e.g. `https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js`.
30
+ - **CSS**: URLs ending in `.css` are loaded and injected.
31
31
 
32
- ## Difference from ctx.importAsync()
32
+ ## vs ctx.importAsync()
33
33
 
34
- - **ctx.requireAsync()**: Loads **UMD/AMD/global** scripts. Suitable for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins, etc. Libraries often attach to `window` after loading; the return value may be the library object or `undefined`.
35
- - **ctx.importAsync()**: Loads **ESM modules** and returns the module namespace. If a library provides ESM, use `ctx.importAsync()` for better module semantics and Tree-shaking.
34
+ - **ctx.requireAsync()**: Loads **UMD/AMD/global** scripts; good for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins; lib often on `window`; return may be the lib or `undefined`.
35
+ - **ctx.importAsync()**: Loads **ESM**; returns module namespace. If a lib has ESM, prefer `ctx.importAsync()` for better module semantics and tree-shaking.
36
36
 
37
37
  ## Examples
38
38
 
39
- ### Basic Usage
39
+ ### Basic
40
40
 
41
41
  ```javascript
42
- // Shorthand path (resolved via ESM CDN as ...?raw)
43
42
  const echarts = await ctx.requireAsync('echarts@5/dist/echarts.min.js');
44
43
 
45
- // Full URL
46
44
  const dayjs = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js');
47
45
 
48
- // Load CSS and inject into the page
49
46
  await ctx.requireAsync('https://cdn.example.com/theme.css');
50
47
  ```
51
48
 
52
- ### ECharts Chart
49
+ ### ECharts
53
50
 
54
51
  ```javascript
55
52
  const container = document.createElement('div');
@@ -62,13 +59,13 @@ if (!echarts) throw new Error('ECharts library not loaded');
62
59
 
63
60
  const chart = echarts.init(container);
64
61
  chart.setOption({
65
- title: { text: ctx.t('Sales Overview') },
62
+ title: { text: ctx.t('Sales overview') },
66
63
  series: [{ type: 'pie', data: [{ value: 1, name: ctx.t('A') }] }],
67
64
  });
68
65
  chart.resize();
69
66
  ```
70
67
 
71
- ### Chart.js Bar Chart
68
+ ### Chart.js bar
72
69
 
73
70
  ```javascript
74
71
  async function renderChart() {
@@ -83,7 +80,7 @@ async function renderChart() {
83
80
  type: 'bar',
84
81
  data: {
85
82
  labels: ['A', 'B', 'C'],
86
- datasets: [{ label: ctx.t('Quantity'), data: [12, 19, 3] }],
83
+ datasets: [{ label: ctx.t('Count'), data: [12, 19, 3] }],
87
84
  },
88
85
  });
89
86
  }
@@ -99,12 +96,12 @@ console.log(dayjs?.default || dayjs);
99
96
 
100
97
  ## Notes
101
98
 
102
- - **Return value format**: UMD export methods vary; the return value may be the library object or `undefined`. If `undefined`, access it via `window` according to the library's documentation.
103
- - **Network dependency**: Requires CDN access. In internal network environments, you can point to a self-hosted service via **ESM_CDN_BASE_URL**.
104
- - **Choosing between importAsync**: If a library provides both ESM and UMD, prioritize `ctx.importAsync()`.
99
+ - **Return shape**: UMD libs vary; return may be the lib or `undefined`; if `undefined`, use the lib’s docs (often `window`).
100
+ - **Network**: Requires CDN access; for intranet set **ESM_CDN_BASE_URL** to your own service.
101
+ - **Choice**: If a lib has both ESM and UMD, prefer `ctx.importAsync()`.
105
102
 
106
103
  ## Related
107
104
 
108
- - [ctx.importAsync()](./import-async.md) - Loads ESM modules, suitable for Vue, dayjs (ESM), etc.
109
- - [ctx.render()](./render.md) - Renders charts and other components into a container.
110
- - [ctx.libs](./libs.md) - Built-in React, antd, dayjs, etc., no asynchronous loading required.
105
+ - [ctx.importAsync()](./import-async.md): load ESM; good for Vue, dayjs (ESM), etc.
106
+ - [ctx.render()](./render.md): render charts etc. into container
107
+ - [ctx.libs](./libs.md): built-in React, antd, dayjs; no async load