@nocobase/plugin-flow-engine 2.1.0-alpha.6 → 2.1.0-alpha.8

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 (53) hide show
  1. package/dist/ai/docs/runjs/context/block-model.md +35 -35
  2. package/dist/ai/docs/runjs/context/collection-field.md +53 -51
  3. package/dist/ai/docs/runjs/context/collection.md +39 -39
  4. package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
  5. package/dist/ai/docs/runjs/context/data-source.md +52 -44
  6. package/dist/ai/docs/runjs/context/element.md +44 -38
  7. package/dist/ai/docs/runjs/context/exit-all.md +37 -35
  8. package/dist/ai/docs/runjs/context/exit.md +38 -35
  9. package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
  10. package/dist/ai/docs/runjs/context/form.md +57 -57
  11. package/dist/ai/docs/runjs/context/get-model.md +22 -21
  12. package/dist/ai/docs/runjs/context/get-value.md +20 -19
  13. package/dist/ai/docs/runjs/context/get-var.md +61 -55
  14. package/dist/ai/docs/runjs/context/i18n.md +17 -14
  15. package/dist/ai/docs/runjs/context/import-async.md +333 -45
  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 +34 -31
  19. package/dist/ai/docs/runjs/context/logger.md +41 -40
  20. package/dist/ai/docs/runjs/context/make-resource.md +27 -26
  21. package/dist/ai/docs/runjs/context/message.md +42 -41
  22. package/dist/ai/docs/runjs/context/modal.md +44 -44
  23. package/dist/ai/docs/runjs/context/model.md +36 -33
  24. package/dist/ai/docs/runjs/context/notification.md +41 -40
  25. package/dist/ai/docs/runjs/context/off.md +14 -14
  26. package/dist/ai/docs/runjs/context/on.md +30 -29
  27. package/dist/ai/docs/runjs/context/open-view.md +40 -40
  28. package/dist/ai/docs/runjs/context/render.md +37 -32
  29. package/dist/ai/docs/runjs/context/request.md +46 -45
  30. package/dist/ai/docs/runjs/context/require-async.md +28 -25
  31. package/dist/ai/docs/runjs/context/resource.md +34 -34
  32. package/dist/ai/docs/runjs/context/route.md +36 -34
  33. package/dist/ai/docs/runjs/context/router.md +43 -31
  34. package/dist/ai/docs/runjs/context/set-value.md +18 -17
  35. package/dist/ai/docs/runjs/context/sql.md +7 -15
  36. package/dist/ai/docs/runjs/context/t.md +20 -17
  37. package/dist/ai/docs/runjs/context/view.md +49 -46
  38. package/dist/ai/docs/runjs/document.md +1 -0
  39. package/dist/ai/docs/runjs/import-modules.md +32 -32
  40. package/dist/ai/docs/runjs/index.md +13 -13
  41. package/dist/ai/docs/runjs/jsx.md +19 -19
  42. package/dist/ai/docs/runjs/model/form-block-model.md +1 -3
  43. package/dist/ai/docs/runjs/render.md +15 -15
  44. package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
  45. package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
  46. package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
  47. package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
  48. package/dist/ai/docs/runjs/window.md +5 -5
  49. package/dist/externalVersion.js +10 -10
  50. package/dist/node_modules/ses/package.json +1 -1
  51. package/dist/node_modules/zod/package.json +1 -1
  52. package/dist/server/collections/flowsql.js +1 -0
  53. package/package.json +2 -2
@@ -1,17 +1,17 @@
1
1
  # ctx.openView()
2
2
 
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.
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.
4
4
 
5
5
  ## Use Cases
6
6
 
7
7
  | Scenario | Description |
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 |
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)`. |
13
13
 
14
- > Note: `ctx.openView` requires a FlowModel context; if no model exists for the uid, a PopupActionModel is created and persisted.
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.
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
- 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.
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.
27
27
 
28
- ### options (common fields)
28
+ ### Common options Fields
29
29
 
30
30
  | Field | Type | Description |
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 |
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. |
45
45
 
46
46
  ## Examples
47
47
 
48
- ### Basic: open drawer
48
+ ### Basic Usage: Open a 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('Detail'),
55
+ title: ctx.t('Details'),
56
56
  });
57
57
  ```
58
58
 
59
- ### Pass current row context
59
+ ### Passing 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 detail'),
65
+ title: ctx.t('Row Details'),
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 the model has an openView action (e.g. association field, clickable field):
75
+ When a model is configured with an `openView` action (such as association fields or clickable fields), you can call:
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
- ### Inject custom context
86
+ ### Injecting 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
- ## Relation to ctx.viewer, ctx.view
101
+ ## Relationship with ctx.viewer and ctx.view
102
102
 
103
- | Use | Recommended |
104
- |-----|-------------|
105
- | **Open configured flow view** | `ctx.openView(uid, options)` |
103
+ | Purpose | Recommended Usage |
104
+ |------|----------|
105
+ | **Open a configured flow view** | `ctx.openView(uid, options)` |
106
106
  | **Open custom content (no flow)** | `ctx.viewer.dialog()` / `ctx.viewer.drawer()` |
107
- | **Operate current view** | `ctx.view.close()`, `ctx.view.inputArgs` |
107
+ | **Operate on the currently open view** | `ctx.view.close()`, `ctx.view.inputArgs` |
108
108
 
109
- `ctx.openView` opens a FlowPage (ChildPageModel) with a full flow; `ctx.viewer` opens arbitrary React content.
109
+ `ctx.openView` opens a `FlowPage` (`ChildPageModel`), which renders a complete flow page internally; `ctx.viewer` opens arbitrary React content.
110
110
 
111
111
  ## Notes
112
112
 
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.
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.
116
116
 
117
117
  ## Related
118
118
 
119
- - [ctx.view](./view.md): current view instance
120
- - [ctx.model](./model.md): current model; use for stable popupUid
119
+ - [ctx.view](./view.md): The currently open view instance.
120
+ - [ctx.model](./model.md): The current model, used to construct a stable `popupUid`.
@@ -1,18 +1,18 @@
1
1
  # ctx.render()
2
2
 
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.
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.
4
4
 
5
5
  ## Use Cases
6
6
 
7
7
  | Scenario | Description |
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 |
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 |
12
12
 
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.
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.
14
14
 
15
- ## Type
15
+ ## Type Definition
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 render |
27
- | `container` | `Element` \| `DocumentFragment` (optional) | Target container; default `ctx.element` |
25
+ |------|------|------|
26
+ | `vnode` | `React.ReactElement` \| `Node` \| `DocumentFragment` \| `string` | Content to be rendered |
27
+ | `container` | `Element` \| `DocumentFragment` (Optional) | Target rendering container, defaults to `ctx.element` |
28
28
 
29
- **Returns**:
29
+ **Return Value**:
30
30
 
31
- - For **React element**: `ReactDOMClient.Root` (for later `root.render()` updates).
32
- - For **HTML string** or **DOM node**: `null`.
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`.
33
33
 
34
- ## vnode types
34
+ ## vnode Type Description
35
35
 
36
36
  | Type | Behavior |
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 |
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. |
42
42
 
43
43
  ## Examples
44
44
 
45
- ### React (JSX)
45
+ ### Rendering React Elements (JSX)
46
46
 
47
47
  ```tsx
48
48
  const { Button, Card } = ctx.libs.antd;
@@ -56,23 +56,26 @@ ctx.render(
56
56
  );
57
57
  ```
58
58
 
59
- ### HTML string
59
+ ### Rendering HTML Strings
60
60
 
61
61
  ```ts
62
62
  ctx.render('<h1>Hello World</h1>');
63
63
 
64
+ // Combining with ctx.t for internationalization
64
65
  ctx.render('<div style="padding:16px">' + ctx.t('Content') + '</div>');
65
66
 
67
+ // Conditional rendering
66
68
  ctx.render(hasData ? `<ul>${items.map(i => `<li>${i}</li>`).join('')}</ul>` : '<span style="color:#999">' + ctx.t('No data') + '</span>');
67
69
  ```
68
70
 
69
- ### DOM node
71
+ ### Rendering DOM Nodes
70
72
 
71
73
  ```ts
72
74
  const div = document.createElement('div');
73
75
  div.textContent = 'Hello World';
74
76
  ctx.render(div);
75
77
 
78
+ // Render an empty container first, then hand it over to a third-party library (e.g., ECharts) for initialization
76
79
  const container = document.createElement('div');
77
80
  container.style.width = '100%';
78
81
  container.style.height = '400px';
@@ -81,29 +84,31 @@ const chart = echarts.init(container);
81
84
  chart.setOption({ ... });
82
85
  ```
83
86
 
84
- ### Custom container
87
+ ### Specifying a Custom Container
85
88
 
86
89
  ```ts
90
+ // Render to a specific DOM element
87
91
  const customEl = document.getElementById('my-container');
88
92
  ctx.render(<div>Content</div>, customEl);
89
93
  ```
90
94
 
91
- ### Multiple calls replace content
95
+ ### Multiple Calls Will Replace Content
92
96
 
93
97
  ```ts
98
+ // The second call will replace the existing content in the container
94
99
  ctx.render(<div>First</div>);
95
- ctx.render(<div>Second</div>); // Only "Second" is shown
100
+ ctx.render(<div>Second</div>); // Only "Second" will be displayed
96
101
  ```
97
102
 
98
103
  ## Notes
99
104
 
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.
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.
104
109
 
105
110
  ## Related
106
111
 
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()`
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.
@@ -1,60 +1,60 @@
1
1
  # ctx.request()
2
2
 
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.
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.
4
4
 
5
5
  ## Use Cases
6
6
 
7
- Use whenever RunJS needs to call a remote HTTP API: JSBlock, JSField, JSItem, JSColumn, event flow, linkage, JSAction, etc.
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.
8
8
 
9
- ## Type
9
+ ## Type Definition
10
10
 
11
11
  ```typescript
12
12
  request(options: RequestOptions): Promise<AxiosResponse<any>>;
13
13
  ```
14
14
 
15
- `RequestOptions` extends Axios `AxiosRequestConfig`:
15
+ `RequestOptions` extends Axios's `AxiosRequestConfig`:
16
16
 
17
17
  ```typescript
18
18
  type RequestOptions = AxiosRequestConfig & {
19
- skipNotify?: boolean | ((error: any) => boolean); // Skip global error toast on failure
20
- skipAuth?: boolean; // Skip auth redirect (e.g. 401 login)
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)
21
21
  };
22
22
  ```
23
23
 
24
- ## Common parameters
24
+ ## Common Parameters
25
25
 
26
26
  | Parameter | Type | Description |
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) |
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) |
35
35
 
36
- ## Resource-style URL
36
+ ## Resource Style URL
37
37
 
38
- NocoBase resource API supports `resource:action` shorthand:
38
+ NocoBase Resource API supports a shorthand `resource:action` format:
39
39
 
40
40
  | Format | Description | Example |
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` |
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` |
44
44
 
45
- Relative URLs are joined with the app baseURL (usually `/api`). For cross-origin, use a full URL and ensure CORS on the target.
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.
46
46
 
47
- ## Response
47
+ ## Response Structure
48
48
 
49
- Returns Axios response. Common usage:
49
+ The return value is an Axios response object. Common fields include:
50
50
 
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
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`
54
54
 
55
55
  ## Examples
56
56
 
57
- ### List
57
+ ### List Query
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;
67
+ const meta = data?.meta; // Pagination and other info
68
68
  ```
69
69
 
70
- ### Create
70
+ ### Submit Data
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', email: 'john@example.com' },
76
+ data: { nickname: 'John Doe', email: 'johndoe@example.com' },
77
77
  });
78
78
 
79
79
  const newRecord = res?.data?.data;
80
80
  ```
81
81
 
82
- ### Filter and sort
82
+ ### With Filtering and Sorting
83
83
 
84
84
  ```javascript
85
85
  const res = await ctx.request({
@@ -93,15 +93,16 @@ const res = await ctx.request({
93
93
  });
94
94
  ```
95
95
 
96
- ### Skip error notify
96
+ ### Skip Error Notification
97
97
 
98
98
  ```javascript
99
99
  const res = await ctx.request({
100
100
  url: 'some:action',
101
101
  method: 'get',
102
- skipNotify: true,
102
+ skipNotify: true, // Do not pop up global message on failure
103
103
  });
104
104
 
105
+ // Or decide whether to skip based on error type
105
106
  const res2 = await ctx.request({
106
107
  url: 'some:action',
107
108
  method: 'get',
@@ -109,9 +110,9 @@ const res2 = await ctx.request({
109
110
  });
110
111
  ```
111
112
 
112
- ### Cross-origin
113
+ ### Cross-Origin Request
113
114
 
114
- For other domains, the target must allow CORS. For its own token, pass in headers:
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:
115
116
 
116
117
  ```javascript
117
118
  const res = await ctx.request({
@@ -123,12 +124,12 @@ const res2 = await ctx.request({
123
124
  url: 'https://api.other.com/items',
124
125
  method: 'get',
125
126
  headers: {
126
- Authorization: 'Bearer <target-token>',
127
+ Authorization: 'Bearer <target_service_token>',
127
128
  },
128
129
  });
129
130
  ```
130
131
 
131
- ### With ctx.render
132
+ ### Displaying with ctx.render
132
133
 
133
134
  ```javascript
134
135
  const { data } = await ctx.request({
@@ -140,7 +141,7 @@ const rows = Array.isArray(data?.data) ? data.data : [];
140
141
 
141
142
  ctx.render([
142
143
  '<div style="padding:12px">',
143
- '<h4>' + ctx.t('User list') + '</h4>',
144
+ '<h4>' + ctx.t('User List') + '</h4>',
144
145
  '<ul>',
145
146
  ...rows.map((r) => '<li>' + (r.nickname ?? r.username ?? '') + '</li>'),
146
147
  '</ul>',
@@ -150,13 +151,13 @@ ctx.render([
150
151
 
151
152
  ## Notes
152
153
 
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.
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.
156
157
 
157
158
  ## Related
158
159
 
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`)
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`)
@@ -1,12 +1,12 @@
1
1
  # ctx.requireAsync()
2
2
 
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).
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).
4
4
 
5
5
  ## Use Cases
6
6
 
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.
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.
8
8
 
9
- ## Type
9
+ ## Type Definition
10
10
 
11
11
  ```ts
12
12
  requireAsync<T = any>(url: string): Promise<T>;
@@ -16,37 +16,40 @@ requireAsync<T = any>(url: string): Promise<T>;
16
16
 
17
17
  | Parameter | Type | Description |
18
18
  |-----------|------|-------------|
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. |
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. |
20
20
 
21
- ## Returns
21
+ ## Return Value
22
22
 
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`.
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.
25
25
 
26
- ## URL format
26
+ ## URL Format Description
27
27
 
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.
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.
31
31
 
32
- ## vs ctx.importAsync()
32
+ ## Difference from ctx.importAsync()
33
33
 
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.
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.
36
36
 
37
37
  ## Examples
38
38
 
39
- ### Basic
39
+ ### Basic Usage
40
40
 
41
41
  ```javascript
42
+ // Shorthand path (resolved via ESM CDN as ...?raw)
42
43
  const echarts = await ctx.requireAsync('echarts@5/dist/echarts.min.js');
43
44
 
45
+ // Full URL
44
46
  const dayjs = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js');
45
47
 
48
+ // Load CSS and inject into the page
46
49
  await ctx.requireAsync('https://cdn.example.com/theme.css');
47
50
  ```
48
51
 
49
- ### ECharts
52
+ ### ECharts Chart
50
53
 
51
54
  ```javascript
52
55
  const container = document.createElement('div');
@@ -59,13 +62,13 @@ if (!echarts) throw new Error('ECharts library not loaded');
59
62
 
60
63
  const chart = echarts.init(container);
61
64
  chart.setOption({
62
- title: { text: ctx.t('Sales overview') },
65
+ title: { text: ctx.t('Sales Overview') },
63
66
  series: [{ type: 'pie', data: [{ value: 1, name: ctx.t('A') }] }],
64
67
  });
65
68
  chart.resize();
66
69
  ```
67
70
 
68
- ### Chart.js bar
71
+ ### Chart.js Bar Chart
69
72
 
70
73
  ```javascript
71
74
  async function renderChart() {
@@ -80,7 +83,7 @@ async function renderChart() {
80
83
  type: 'bar',
81
84
  data: {
82
85
  labels: ['A', 'B', 'C'],
83
- datasets: [{ label: ctx.t('Count'), data: [12, 19, 3] }],
86
+ datasets: [{ label: ctx.t('Quantity'), data: [12, 19, 3] }],
84
87
  },
85
88
  });
86
89
  }
@@ -96,12 +99,12 @@ console.log(dayjs?.default || dayjs);
96
99
 
97
100
  ## Notes
98
101
 
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()`.
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()`.
102
105
 
103
106
  ## Related
104
107
 
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
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.