@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.
- package/dist/ai/docs/runjs/context/block-model.md +35 -35
- package/dist/ai/docs/runjs/context/collection-field.md +51 -53
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +30 -40
- package/dist/ai/docs/runjs/context/data-source.md +44 -52
- package/dist/ai/docs/runjs/context/element.md +38 -44
- package/dist/ai/docs/runjs/context/exit-all.md +35 -37
- package/dist/ai/docs/runjs/context/exit.md +35 -38
- package/dist/ai/docs/runjs/context/filter-manager.md +30 -36
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +21 -22
- package/dist/ai/docs/runjs/context/get-value.md +19 -20
- package/dist/ai/docs/runjs/context/get-var.md +55 -61
- package/dist/ai/docs/runjs/context/i18n.md +14 -17
- package/dist/ai/docs/runjs/context/import-async.md +45 -333
- package/dist/ai/docs/runjs/context/init-resource.md +20 -20
- package/dist/ai/docs/runjs/context/libs.md +31 -31
- package/dist/ai/docs/runjs/context/location.md +31 -34
- package/dist/ai/docs/runjs/context/logger.md +40 -41
- package/dist/ai/docs/runjs/context/make-resource.md +26 -27
- package/dist/ai/docs/runjs/context/message.md +41 -42
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +33 -36
- package/dist/ai/docs/runjs/context/notification.md +40 -41
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +29 -30
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +32 -37
- package/dist/ai/docs/runjs/context/request.md +45 -46
- package/dist/ai/docs/runjs/context/require-async.md +25 -28
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +34 -36
- package/dist/ai/docs/runjs/context/router.md +31 -43
- package/dist/ai/docs/runjs/context/set-value.md +17 -18
- package/dist/ai/docs/runjs/context/t.md +17 -20
- package/dist/ai/docs/runjs/context/view.md +46 -49
- package/dist/ai/docs/runjs/document.md +0 -1
- package/dist/ai/docs/runjs/import-modules.md +32 -32
- package/dist/ai/docs/runjs/index.md +13 -13
- package/dist/ai/docs/runjs/jsx.md +19 -19
- package/dist/ai/docs/runjs/model/form-block-model.md +3 -1
- package/dist/ai/docs/runjs/render.md +15 -15
- package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
- package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
- package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
- package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
- package/dist/ai/docs/runjs/window.md +5 -5
- package/dist/externalVersion.js +10 -10
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/package.json +2 -2
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
# ctx.libs
|
|
2
2
|
|
|
3
|
-
`ctx.libs` is the unified namespace for built-in libraries
|
|
3
|
+
`ctx.libs` is the unified namespace for RunJS built-in libraries (React, Ant Design, dayjs, lodash, etc.). **No `import` or async loading**; use `ctx.libs.xxx` directly.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField / JSItem / JSColumn** |
|
|
10
|
-
| **
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField / JSItem / JSColumn** | React + Ant Design for UI, dayjs for dates, lodash for data |
|
|
10
|
+
| **Formulas / calculations** | formula or math for Excel-like formulas and math expressions |
|
|
11
|
+
| **Event flow / linkage** | lodash, dayjs, formula, etc. in logic-only code |
|
|
12
12
|
|
|
13
|
-
## Built-in
|
|
13
|
+
## Built-in libraries
|
|
14
14
|
|
|
15
|
-
| Property | Description |
|
|
16
|
-
|
|
17
|
-
| `ctx.libs.React` | React core
|
|
18
|
-
| `ctx.libs.ReactDOM` | ReactDOM
|
|
19
|
-
| `ctx.libs.antd` | Ant Design
|
|
20
|
-
| `ctx.libs.antdIcons` | Ant Design
|
|
21
|
-
| `ctx.libs.dayjs` | Date
|
|
22
|
-
| `ctx.libs.lodash` |
|
|
23
|
-
| `ctx.libs.formula` | Excel-like
|
|
24
|
-
| `ctx.libs.math` |
|
|
15
|
+
| Property | Description | Docs |
|
|
16
|
+
|----------|-------------|------|
|
|
17
|
+
| `ctx.libs.React` | React core for JSX and Hooks | [React](https://react.dev/) |
|
|
18
|
+
| `ctx.libs.ReactDOM` | ReactDOM (e.g. `createRoot`) | [React DOM](https://react.dev/reference/react-dom) |
|
|
19
|
+
| `ctx.libs.antd` | Ant Design (Button, Card, Table, Form, Input, Modal, etc.) | [Ant Design](https://ant.design/components/overview/) |
|
|
20
|
+
| `ctx.libs.antdIcons` | Ant Design icons (PlusOutlined, UserOutlined, etc.) | [@ant-design/icons](https://ant.design/components/icon/) |
|
|
21
|
+
| `ctx.libs.dayjs` | Date/time utilities | [dayjs](https://day.js.org/) |
|
|
22
|
+
| `ctx.libs.lodash` | Utilities (get, set, debounce, etc.) | [Lodash](https://lodash.com/docs/) |
|
|
23
|
+
| `ctx.libs.formula` | Excel-like formulas (SUM, AVERAGE, IF, etc.) | [Formula.js](https://formulajs.info/functions/) |
|
|
24
|
+
| `ctx.libs.math` | Math expressions and evaluation | [Math.js](https://mathjs.org/docs/) |
|
|
25
25
|
|
|
26
|
-
## Top-level
|
|
26
|
+
## Top-level aliases
|
|
27
27
|
|
|
28
|
-
For compatibility
|
|
28
|
+
For backward compatibility, some libs are also on `ctx`: `ctx.React`, `ctx.ReactDOM`, `ctx.antd`, `ctx.dayjs`. **Prefer `ctx.libs.xxx`** for consistency and docs.
|
|
29
29
|
|
|
30
|
-
## Lazy
|
|
30
|
+
## Lazy loading
|
|
31
31
|
|
|
32
|
-
`lodash`, `formula`,
|
|
32
|
+
`lodash`, `formula`, `math` are **lazy-loaded**: the first access to `ctx.libs.lodash` triggers a dynamic import, then the result is cached. `React`, `antd`, `dayjs`, `antdIcons` are preloaded in context.
|
|
33
33
|
|
|
34
34
|
## Examples
|
|
35
35
|
|
|
36
|
-
###
|
|
36
|
+
### React and Ant Design
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
39
|
const { Button, Card } = ctx.libs.antd;
|
|
@@ -45,7 +45,7 @@ ctx.render(
|
|
|
45
45
|
);
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### Hooks
|
|
49
49
|
|
|
50
50
|
```tsx
|
|
51
51
|
const { React } = ctx.libs;
|
|
@@ -59,7 +59,7 @@ const App = () => {
|
|
|
59
59
|
ctx.render(<App />);
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
###
|
|
62
|
+
### Icons
|
|
63
63
|
|
|
64
64
|
```tsx
|
|
65
65
|
const { Button } = ctx.libs.antd;
|
|
@@ -68,7 +68,7 @@ const { UserOutlined, HeartOutlined } = ctx.libs.antdIcons;
|
|
|
68
68
|
ctx.render(<Button icon={<UserOutlined />}>User</Button>);
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
###
|
|
71
|
+
### dayjs
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
const now = ctx.libs.dayjs();
|
|
@@ -76,14 +76,14 @@ const formatted = now.format('YYYY-MM-DD HH:mm:ss');
|
|
|
76
76
|
ctx.message.info(formatted);
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
###
|
|
79
|
+
### lodash
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
82
|
const user = { profile: { name: 'Alice' } };
|
|
83
83
|
const name = ctx.libs.lodash.get(user, 'profile.name', 'Unknown');
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### formula
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
89
|
const values = [1, 2, 3, 4];
|
|
@@ -91,7 +91,7 @@ const sum = ctx.libs.formula.SUM(values);
|
|
|
91
91
|
const avg = ctx.libs.formula.AVERAGE(values);
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
###
|
|
94
|
+
### math
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
97
|
const result = ctx.libs.math.evaluate('2 + 3 * 4');
|
|
@@ -100,10 +100,10 @@ const result = ctx.libs.math.evaluate('2 + 3 * 4');
|
|
|
100
100
|
|
|
101
101
|
## Notes
|
|
102
102
|
|
|
103
|
-
- **Mixing with ctx.importAsync**: If
|
|
104
|
-
- **Multiple React
|
|
103
|
+
- **Mixing with ctx.importAsync**: If you load external React via `ctx.importAsync('react@19')`, JSX uses that instance; **do not** mix with `ctx.libs.antd`. Load antd for that React version (e.g. `ctx.importAsync('antd@5.x')`, `ctx.importAsync('@ant-design/icons@5.x')`).
|
|
104
|
+
- **Multiple React instances**: "Invalid hook call" or null hook dispatcher usually means multiple React instances. Before using `ctx.libs.React` or Hooks, run `await ctx.importAsync('react@version')` so the same React as the page is used.
|
|
105
105
|
|
|
106
106
|
## Related
|
|
107
107
|
|
|
108
|
-
- [ctx.importAsync()](./import-async.md)
|
|
109
|
-
- [ctx.render()](./render.md)
|
|
108
|
+
- [ctx.importAsync()](./import-async.md): load external ESM (e.g. specific React, Vue)
|
|
109
|
+
- [ctx.render()](./render.md): render into container
|
|
@@ -1,88 +1,85 @@
|
|
|
1
1
|
# ctx.location
|
|
2
2
|
|
|
3
|
-
Current route location
|
|
3
|
+
Current route location, equivalent to React Router’s `location`. Use with `ctx.router` and `ctx.route` to read pathname, search, hash, and state passed via navigation.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **Linkage
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField** | Conditional render or logic based on path, query, or hash |
|
|
10
|
+
| **Linkage / event flow** | Read URL params for filtering or use `location.state` for source |
|
|
11
|
+
| **After navigation** | On target page, read `ctx.location.state` from `ctx.router.navigate` |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.location` is only available in RunJS
|
|
13
|
+
> Note: `ctx.location` is only available in RunJS when a router context exists (e.g. JSBlock on a page, event flow); in pure backend or non-routed contexts (e.g. workflow) it may be empty.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
location: Location;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
`Location`
|
|
21
|
+
`Location` is from `react-router-dom`, same as `useLocation()`.
|
|
22
22
|
|
|
23
23
|
## Common Fields
|
|
24
24
|
|
|
25
25
|
| Field | Type | Description |
|
|
26
|
-
|
|
27
|
-
| `pathname` | `string` |
|
|
28
|
-
| `search` | `string` |
|
|
29
|
-
| `hash` | `string` |
|
|
30
|
-
| `state` | `any` |
|
|
31
|
-
| `key` | `string` |
|
|
26
|
+
|-------|------|-------------|
|
|
27
|
+
| `pathname` | `string` | Current path, leading `/` (e.g. `/admin/users`) |
|
|
28
|
+
| `search` | `string` | Query string, leading `?` (e.g. `?page=1&status=active`) |
|
|
29
|
+
| `hash` | `string` | Hash fragment, leading `#` (e.g. `#section-1`) |
|
|
30
|
+
| `state` | `any` | Data passed via `ctx.router.navigate(path, { state })`; not in URL |
|
|
31
|
+
| `key` | `string` | Unique key for this location; initial page is `"default"` |
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Relation to ctx.router, ctx.urlSearchParams
|
|
34
34
|
|
|
35
|
-
|
|
|
36
|
-
|
|
37
|
-
| **
|
|
38
|
-
| **
|
|
39
|
-
| **Parse search
|
|
35
|
+
| Use | Recommended |
|
|
36
|
+
|-----|-------------|
|
|
37
|
+
| **Path, hash, state** | `ctx.location.pathname` / `ctx.location.hash` / `ctx.location.state` |
|
|
38
|
+
| **Query params as object** | `ctx.urlSearchParams` |
|
|
39
|
+
| **Parse search** | `new URLSearchParams(ctx.location.search)` or `ctx.urlSearchParams` |
|
|
40
40
|
|
|
41
|
-
`ctx.urlSearchParams` is
|
|
41
|
+
`ctx.urlSearchParams` is derived from `ctx.location.search`; use it when you only need query params.
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
###
|
|
45
|
+
### Branch by path
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
if (ctx.location.pathname.startsWith('/admin/users')) {
|
|
49
|
-
ctx.message.info('
|
|
49
|
+
ctx.message.info('On user management page');
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
###
|
|
53
|
+
### Parse query params
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
// Method 1: Using ctx.urlSearchParams (Recommended)
|
|
57
56
|
const page = ctx.urlSearchParams.page || 1;
|
|
58
57
|
const status = ctx.urlSearchParams.status;
|
|
59
58
|
|
|
60
|
-
// Method 2: Using URLSearchParams to parse search
|
|
61
59
|
const params = new URLSearchParams(ctx.location.search);
|
|
62
60
|
const page = params.get('page') || '1';
|
|
63
61
|
const status = params.get('status');
|
|
64
62
|
```
|
|
65
63
|
|
|
66
|
-
###
|
|
64
|
+
### Read state from navigation
|
|
67
65
|
|
|
68
66
|
```ts
|
|
69
|
-
// When navigating from the previous page: ctx.router.navigate('/users/123', { state: { from: 'dashboard' } })
|
|
70
67
|
const prevState = ctx.location.state;
|
|
71
68
|
if (prevState?.from === 'dashboard') {
|
|
72
|
-
ctx.message.info('Navigated from
|
|
69
|
+
ctx.message.info('Navigated from dashboard');
|
|
73
70
|
}
|
|
74
71
|
```
|
|
75
72
|
|
|
76
|
-
###
|
|
73
|
+
### Anchor by hash
|
|
77
74
|
|
|
78
75
|
```ts
|
|
79
|
-
const hash = ctx.location.hash;
|
|
76
|
+
const hash = ctx.location.hash;
|
|
80
77
|
if (hash === '#edit') {
|
|
81
|
-
// Scroll to
|
|
78
|
+
// Scroll to edit or run logic
|
|
82
79
|
}
|
|
83
80
|
```
|
|
84
81
|
|
|
85
82
|
## Related
|
|
86
83
|
|
|
87
|
-
- [ctx.router](./router.md):
|
|
88
|
-
- [ctx.route](./route.md):
|
|
84
|
+
- [ctx.router](./router.md): navigation; `state` from `ctx.router.navigate` is available as `ctx.location.state`
|
|
85
|
+
- [ctx.route](./route.md): current route match (params, config); use with `ctx.location`
|
|
@@ -1,85 +1,84 @@
|
|
|
1
1
|
# ctx.logger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Logging built on [pino](https://github.com/pinojs/pino); outputs structured JSON. Prefer `ctx.logger` over `console` for collection and analysis.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Available in all RunJS contexts for debugging, error tracking, and performance.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
logger: pino.Logger;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`ctx.logger` is
|
|
15
|
+
`ctx.logger` is `engine.logger.child({ module: 'flow-engine' })`, i.e. a pino child logger with a `module` context.
|
|
16
16
|
|
|
17
|
-
## Log
|
|
17
|
+
## Log levels
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
From highest to lowest:
|
|
20
20
|
|
|
21
21
|
| Level | Method | Description |
|
|
22
|
-
|
|
23
|
-
| `fatal` | `ctx.logger.fatal()` | Fatal
|
|
24
|
-
| `error` | `ctx.logger.error()` | Error
|
|
25
|
-
| `warn` | `ctx.logger.warn()` | Warning
|
|
26
|
-
| `info` | `ctx.logger.info()` | General runtime
|
|
27
|
-
| `debug` | `ctx.logger.debug()` |
|
|
28
|
-
| `trace` | `ctx.logger.trace()` |
|
|
22
|
+
|-------|--------|-------------|
|
|
23
|
+
| `fatal` | `ctx.logger.fatal()` | Fatal; usually process exit |
|
|
24
|
+
| `error` | `ctx.logger.error()` | Error; request or operation failed |
|
|
25
|
+
| `warn` | `ctx.logger.warn()` | Warning; potential issue |
|
|
26
|
+
| `info` | `ctx.logger.info()` | General runtime info |
|
|
27
|
+
| `debug` | `ctx.logger.debug()` | Debug; development |
|
|
28
|
+
| `trace` | `ctx.logger.trace()` | Verbose; deep diagnosis |
|
|
29
29
|
|
|
30
|
-
## Recommended
|
|
30
|
+
## Recommended usage
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Use `level(msg, meta)`: message first, optional metadata object second.
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
|
-
ctx.logger.info('Block
|
|
36
|
-
ctx.logger.info('
|
|
37
|
-
ctx.logger.warn('
|
|
38
|
-
ctx.logger.error('
|
|
35
|
+
ctx.logger.info('Block loaded');
|
|
36
|
+
ctx.logger.info('Success', { recordId: 456 });
|
|
37
|
+
ctx.logger.warn('Slow', { duration: 5000 });
|
|
38
|
+
ctx.logger.error('Failed', { userId: 123, action: 'create' });
|
|
39
39
|
ctx.logger.error('Request failed', { err });
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
pino also supports `level(meta, msg)`
|
|
42
|
+
pino also supports `level(meta, msg)` or `level({ msg, ...meta })` if needed.
|
|
43
43
|
|
|
44
44
|
## Examples
|
|
45
45
|
|
|
46
|
-
### Basic
|
|
46
|
+
### Basic
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
|
-
ctx.logger.info('Block
|
|
49
|
+
ctx.logger.info('Block loaded');
|
|
50
50
|
ctx.logger.warn('Request failed, using cache', { err });
|
|
51
|
-
ctx.logger.debug('Saving
|
|
51
|
+
ctx.logger.debug('Saving', { recordId: ctx.record?.id });
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### Child logger
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
// Create a child logger with context for the current logic
|
|
58
57
|
const log = ctx.logger.child({ scope: 'myBlock' });
|
|
59
|
-
log.info('
|
|
60
|
-
log.debug('
|
|
58
|
+
log.info('Step 1');
|
|
59
|
+
log.debug('Step 2', { step: 2 });
|
|
61
60
|
```
|
|
62
61
|
|
|
63
|
-
###
|
|
62
|
+
### vs console
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
Prefer `ctx.logger` for structured JSON. Rough mapping: `console.log` → `ctx.logger.info`, `console.error` → `ctx.logger.error`, `console.warn` → `ctx.logger.warn`.
|
|
66
65
|
|
|
67
|
-
##
|
|
66
|
+
## Output format
|
|
68
67
|
|
|
69
|
-
pino outputs
|
|
68
|
+
pino outputs JSON with:
|
|
70
69
|
|
|
71
|
-
- `level`:
|
|
72
|
-
- `time`:
|
|
73
|
-
- `msg`:
|
|
74
|
-
- `module`:
|
|
75
|
-
-
|
|
70
|
+
- `level`: numeric level
|
|
71
|
+
- `time`: timestamp (ms)
|
|
72
|
+
- `msg`: message
|
|
73
|
+
- `module`: `flow-engine`
|
|
74
|
+
- Any custom fields passed in the object
|
|
76
75
|
|
|
77
76
|
## Notes
|
|
78
77
|
|
|
79
|
-
- Logs are
|
|
80
|
-
- Child loggers
|
|
81
|
-
- Some
|
|
78
|
+
- Logs are JSON for easy collection and querying
|
|
79
|
+
- Child loggers from `child()` also work well with `level(msg, meta)`
|
|
80
|
+
- Some environments (e.g. workflow) may use different log handling
|
|
82
81
|
|
|
83
82
|
## Related
|
|
84
83
|
|
|
85
|
-
- [pino](https://github.com/pinojs/pino)
|
|
84
|
+
- [pino](https://github.com/pinojs/pino)
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.makeResource()
|
|
2
2
|
|
|
3
|
-
**Creates**
|
|
3
|
+
**Creates** a new resource instance and returns it; **does not** set or change `ctx.resource`. Use when you need multiple resources or a temporary one.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **Multiple resources** | Load
|
|
10
|
-
| **
|
|
11
|
-
| **Auxiliary data** |
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **Multiple resources** | Load several data sources (e.g. users + orders), each with its own resource |
|
|
10
|
+
| **One-off query** | Single query, no need to bind to `ctx.resource` |
|
|
11
|
+
| **Auxiliary data** | Main data in `ctx.resource`, extra data from a `makeResource` instance |
|
|
12
12
|
|
|
13
|
-
If you only need
|
|
13
|
+
If you only need one resource and want it on `ctx.resource`, use [ctx.initResource()](./init-resource.md).
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
makeResource<T = FlowResource>(
|
|
@@ -21,17 +21,17 @@ makeResource<T = FlowResource>(
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
| Parameter | Type | Description |
|
|
24
|
-
|
|
25
|
-
| `resourceType` | `string` |
|
|
24
|
+
|-----------|------|-------------|
|
|
25
|
+
| `resourceType` | `string` | `'APIResource'`, `'SingleRecordResource'`, `'MultiRecordResource'`, `'SQLResource'` |
|
|
26
26
|
|
|
27
|
-
**Returns**: The
|
|
27
|
+
**Returns**: The new resource instance.
|
|
28
28
|
|
|
29
|
-
##
|
|
29
|
+
## Relation to ctx.initResource()
|
|
30
30
|
|
|
31
31
|
| Method | Behavior |
|
|
32
|
-
|
|
33
|
-
| `ctx.makeResource(type)` |
|
|
34
|
-
| `ctx.initResource(type)` | Creates and binds if
|
|
32
|
+
|--------|----------|
|
|
33
|
+
| `ctx.makeResource(type)` | Creates and returns; **does not** set `ctx.resource`; can call multiple times for multiple resources |
|
|
34
|
+
| `ctx.initResource(type)` | Creates and binds if missing; otherwise returns existing. Ensures `ctx.resource` is set |
|
|
35
35
|
|
|
36
36
|
## Examples
|
|
37
37
|
|
|
@@ -42,7 +42,7 @@ const listRes = ctx.makeResource('MultiRecordResource');
|
|
|
42
42
|
listRes.setResourceName('users');
|
|
43
43
|
await listRes.refresh();
|
|
44
44
|
const users = listRes.getData();
|
|
45
|
-
// ctx.resource
|
|
45
|
+
// ctx.resource unchanged (if it existed)
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
### Multiple resources
|
|
@@ -58,16 +58,15 @@ await ordersRes.refresh();
|
|
|
58
58
|
|
|
59
59
|
ctx.render(
|
|
60
60
|
<div>
|
|
61
|
-
<p>
|
|
62
|
-
<p>
|
|
61
|
+
<p>Users: {usersRes.getData().length}</p>
|
|
62
|
+
<p>Orders: {ordersRes.getData().length}</p>
|
|
63
63
|
</div>
|
|
64
64
|
);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
###
|
|
67
|
+
### One-off query
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
|
-
// One-time query, does not pollute ctx.resource
|
|
71
70
|
const tempRes = ctx.makeResource('SingleRecordResource');
|
|
72
71
|
tempRes.setResourceName('users');
|
|
73
72
|
tempRes.setFilterByTk(1);
|
|
@@ -77,14 +76,14 @@ const record = tempRes.getData();
|
|
|
77
76
|
|
|
78
77
|
## Notes
|
|
79
78
|
|
|
80
|
-
-
|
|
81
|
-
- Each
|
|
79
|
+
- Call `setResourceName(name)` then `refresh()` to load data.
|
|
80
|
+
- Each instance is independent; good for loading several sources in parallel.
|
|
82
81
|
|
|
83
82
|
## Related
|
|
84
83
|
|
|
85
|
-
- [ctx.initResource()](./init-resource.md):
|
|
86
|
-
- [ctx.resource](./resource.md):
|
|
87
|
-
- [MultiRecordResource](../resource/multi-record-resource)
|
|
88
|
-
- [SingleRecordResource](../resource/single-record-resource)
|
|
89
|
-
- [APIResource](../resource/api-resource)
|
|
90
|
-
- [SQLResource](../resource/sql-resource)
|
|
84
|
+
- [ctx.initResource()](./init-resource.md): init and bind to `ctx.resource`
|
|
85
|
+
- [ctx.resource](./resource.md): current context resource
|
|
86
|
+
- [MultiRecordResource](../resource/multi-record-resource.md)
|
|
87
|
+
- [SingleRecordResource](../resource/single-record-resource.md)
|
|
88
|
+
- [APIResource](../resource/api-resource.md)
|
|
89
|
+
- [SQLResource](../resource/sql-resource.md)
|
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
# ctx.message
|
|
2
2
|
|
|
3
|
-
Ant Design global message API
|
|
3
|
+
Ant Design global message API; shows short messages at the top center. Messages auto-close after a while or can be closed by the user.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField / JSItem / JSColumn** |
|
|
10
|
-
| **Form
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField / JSItem / JSColumn** | Quick feedback: validation, copy success, etc. |
|
|
10
|
+
| **Form actions / event flow** | Submit success, save failed, validation failed |
|
|
11
|
+
| **JSAction** | Click or batch action feedback |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
message: MessageInstance;
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`MessageInstance` is the Ant Design message
|
|
19
|
+
`MessageInstance` is the Ant Design message API.
|
|
20
20
|
|
|
21
21
|
## Common Methods
|
|
22
22
|
|
|
23
23
|
| Method | Description |
|
|
24
|
-
|
|
25
|
-
| `success(content, duration?)` |
|
|
26
|
-
| `error(content, duration?)` |
|
|
27
|
-
| `warning(content, duration?)` |
|
|
28
|
-
| `info(content, duration?)` |
|
|
29
|
-
| `loading(content, duration?)` |
|
|
30
|
-
| `open(config)` | Open
|
|
31
|
-
| `destroy()` | Close all
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `success(content, duration?)` | Success message |
|
|
26
|
+
| `error(content, duration?)` | Error message |
|
|
27
|
+
| `warning(content, duration?)` | Warning message |
|
|
28
|
+
| `info(content, duration?)` | Info message |
|
|
29
|
+
| `loading(content, duration?)` | Loading (usually closed manually) |
|
|
30
|
+
| `open(config)` | Open with custom config |
|
|
31
|
+
| `destroy()` | Close all messages |
|
|
32
32
|
|
|
33
33
|
**Parameters:**
|
|
34
34
|
|
|
35
|
-
- `content
|
|
36
|
-
- `duration
|
|
35
|
+
- `content`: `string` or `ConfigOptions`
|
|
36
|
+
- `duration`: optional seconds; default 3; 0 = no auto-close
|
|
37
37
|
|
|
38
|
-
**ConfigOptions** (when
|
|
38
|
+
**ConfigOptions** (when content is an object):
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
interface ConfigOptions {
|
|
42
|
-
content: React.ReactNode;
|
|
43
|
-
duration?: number;
|
|
44
|
-
onClose?: () => void;
|
|
45
|
-
icon?: React.ReactNode;
|
|
42
|
+
content: React.ReactNode;
|
|
43
|
+
duration?: number;
|
|
44
|
+
onClose?: () => void;
|
|
45
|
+
icon?: React.ReactNode;
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Examples
|
|
50
50
|
|
|
51
|
-
### Basic
|
|
51
|
+
### Basic
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
|
-
ctx.message.success('
|
|
55
|
-
ctx.message.error('
|
|
54
|
+
ctx.message.success('Done');
|
|
55
|
+
ctx.message.error('Failed');
|
|
56
56
|
ctx.message.warning('Please select data first');
|
|
57
57
|
ctx.message.info('Processing...');
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
###
|
|
60
|
+
### With ctx.t (i18n)
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
ctx.message.success(ctx.t('Copied'));
|
|
@@ -65,43 +65,42 @@ ctx.message.warning(ctx.t('Please select at least one row'));
|
|
|
65
65
|
ctx.message.success(ctx.t('Exported {{count}} records', { count: rows.length }));
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
### Loading and
|
|
68
|
+
### Loading and manual close
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
const hide = ctx.message.loading(ctx.t('Saving...'));
|
|
72
|
-
// Execute asynchronous operation
|
|
73
72
|
await saveData();
|
|
74
|
-
hide();
|
|
73
|
+
hide();
|
|
75
74
|
ctx.message.success(ctx.t('Saved'));
|
|
76
75
|
```
|
|
77
76
|
|
|
78
|
-
###
|
|
77
|
+
### open with config
|
|
79
78
|
|
|
80
79
|
```ts
|
|
81
80
|
ctx.message.open({
|
|
82
81
|
type: 'success',
|
|
83
|
-
content: 'Custom success
|
|
82
|
+
content: 'Custom success',
|
|
84
83
|
duration: 5,
|
|
85
|
-
onClose: () => console.log('
|
|
84
|
+
onClose: () => console.log('closed'),
|
|
86
85
|
});
|
|
87
86
|
```
|
|
88
87
|
|
|
89
|
-
### Close
|
|
88
|
+
### Close all
|
|
90
89
|
|
|
91
90
|
```ts
|
|
92
91
|
ctx.message.destroy();
|
|
93
92
|
```
|
|
94
93
|
|
|
95
|
-
##
|
|
94
|
+
## ctx.message vs ctx.notification
|
|
96
95
|
|
|
97
|
-
|
|
|
98
|
-
|
|
99
|
-
| **Position** | Top center
|
|
100
|
-
| **
|
|
101
|
-
| **Typical
|
|
96
|
+
| | ctx.message | ctx.notification |
|
|
97
|
+
|---|-------------|-------------------|
|
|
98
|
+
| **Position** | Top center | Top right |
|
|
99
|
+
| **Use** | Short, auto-dismiss | Panel with title/description; can stay longer |
|
|
100
|
+
| **Typical** | Action feedback, validation, copy | Task done, system notice, longer content |
|
|
102
101
|
|
|
103
102
|
## Related
|
|
104
103
|
|
|
105
|
-
- [ctx.notification](./notification.md) -
|
|
106
|
-
- [ctx.modal](./modal.md)
|
|
107
|
-
- [ctx.t()](./t.md)
|
|
104
|
+
- [ctx.notification](./notification.md): top-right notifications
|
|
105
|
+
- [ctx.modal](./modal.md): modal confirm
|
|
106
|
+
- [ctx.t()](./t.md): i18n; often used with message
|