@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.resource
|
|
2
2
|
|
|
3
|
-
The **FlowResource** instance in the current context
|
|
3
|
+
The **FlowResource** instance in the current context; used to access and operate on data. In most blocks (form, table, detail, etc.) and popups, the runtime binds `ctx.resource`; in JSBlock and similar contexts that have no resource by default, call [ctx.initResource()](./init-resource.md) first, then use `ctx.resource`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Use whenever RunJS needs structured data (list, single record, custom API, SQL). Form, table, detail blocks and popups usually have it bound; in JSBlock, JSField, JSItem, JSColumn, etc., call `ctx.initResource(type)` first if you need to load data.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
resource: FlowResource | undefined;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
- In
|
|
15
|
+
- When the context has a bound resource, `ctx.resource` is that instance.
|
|
16
|
+
- In JSBlock etc. it is `undefined` by default; after `ctx.initResource(type)` it is set.
|
|
17
17
|
|
|
18
|
-
## Common
|
|
18
|
+
## Common methods
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Different resource types (MultiRecordResource, SingleRecordResource, APIResource, SQLResource) expose slightly different APIs; common ones:
|
|
21
21
|
|
|
22
22
|
| Method | Description |
|
|
23
|
-
|
|
24
|
-
| `getData()` |
|
|
23
|
+
|--------|-------------|
|
|
24
|
+
| `getData()` | Current data (list or single record) |
|
|
25
25
|
| `setData(value)` | Set local data |
|
|
26
|
-
| `refresh()` |
|
|
27
|
-
| `setResourceName(name)` | Set resource name (e.g
|
|
28
|
-
| `setFilterByTk(tk)` | Set primary key filter (
|
|
29
|
-
| `runAction(actionName, options)` | Call any resource action (e.g
|
|
30
|
-
| `on(event, callback)` / `off(event, callback)` | Subscribe/unsubscribe
|
|
26
|
+
| `refresh()` | Refetch with current params |
|
|
27
|
+
| `setResourceName(name)` | Set resource name (e.g. `'users'`, `'users.tags'`) |
|
|
28
|
+
| `setFilterByTk(tk)` | Set primary key filter (single get, etc.) |
|
|
29
|
+
| `runAction(actionName, options)` | Call any resource action (e.g. `create`, `update`) |
|
|
30
|
+
| `on(event, callback)` / `off(event, callback)` | Subscribe/unsubscribe (e.g. `refresh`, `saved`) |
|
|
31
31
|
|
|
32
|
-
**MultiRecordResource
|
|
32
|
+
**MultiRecordResource**: `getSelectedRows()`, `destroySelectedRows()`, `setPage()`, `next()`, `previous()`, etc.
|
|
33
33
|
|
|
34
34
|
## Examples
|
|
35
35
|
|
|
36
|
-
### List
|
|
36
|
+
### List (after initResource)
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
ctx.initResource('MultiRecordResource');
|
|
@@ -42,7 +42,7 @@ await ctx.resource.refresh();
|
|
|
42
42
|
const rows = ctx.resource.getData();
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
### Table
|
|
45
|
+
### Table (pre-bound)
|
|
46
46
|
|
|
47
47
|
```js
|
|
48
48
|
const rows = ctx.resource?.getSelectedRows?.() || [];
|
|
@@ -54,7 +54,7 @@ await ctx.resource.destroySelectedRows();
|
|
|
54
54
|
ctx.message.success(ctx.t('Deleted'));
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
### Single
|
|
57
|
+
### Single record
|
|
58
58
|
|
|
59
59
|
```js
|
|
60
60
|
ctx.initResource('SingleRecordResource');
|
|
@@ -64,29 +64,29 @@ await ctx.resource.refresh();
|
|
|
64
64
|
const record = ctx.resource.getData();
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
###
|
|
67
|
+
### Custom action
|
|
68
68
|
|
|
69
69
|
```js
|
|
70
|
-
await ctx.resource.runAction('create', { data: { name: 'John
|
|
70
|
+
await ctx.resource.runAction('create', { data: { name: 'John' } });
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
##
|
|
73
|
+
## Relation to ctx.initResource / ctx.makeResource
|
|
74
74
|
|
|
75
|
-
- **ctx.initResource(type)**:
|
|
76
|
-
- **ctx.makeResource(type)**: Creates a new
|
|
77
|
-
- **ctx.resource**:
|
|
75
|
+
- **ctx.initResource(type)**: Creates and binds if missing; otherwise returns existing. Ensures `ctx.resource` is set.
|
|
76
|
+
- **ctx.makeResource(type)**: Creates a new instance and returns it; **does not** set `ctx.resource`. Use when you need multiple resources or a temporary one.
|
|
77
|
+
- **ctx.resource**: The bound resource in the current context. Most blocks/popups have it; when not bound it is `undefined` and you must call `ctx.initResource` first.
|
|
78
78
|
|
|
79
79
|
## Notes
|
|
80
80
|
|
|
81
|
-
-
|
|
82
|
-
- After
|
|
83
|
-
-
|
|
81
|
+
- Prefer null checks: `ctx.resource?.refresh()`, especially in JSBlock and similar contexts.
|
|
82
|
+
- After init, call `setResourceName(name)` then `refresh()` to load data.
|
|
83
|
+
- See the resource type docs for full API.
|
|
84
84
|
|
|
85
85
|
## Related
|
|
86
86
|
|
|
87
|
-
- [ctx.initResource()](./init-resource.md)
|
|
88
|
-
- [ctx.makeResource()](./make-resource.md)
|
|
89
|
-
- [MultiRecordResource](../resource/multi-record-resource.md)
|
|
90
|
-
- [SingleRecordResource](../resource/single-record-resource.md)
|
|
91
|
-
- [APIResource](../resource/api-resource.md)
|
|
92
|
-
- [SQLResource](../resource/sql-resource.md)
|
|
87
|
+
- [ctx.initResource()](./init-resource.md): init and bind resource
|
|
88
|
+
- [ctx.makeResource()](./make-resource.md): create resource without binding
|
|
89
|
+
- [MultiRecordResource](../resource/multi-record-resource.md)
|
|
90
|
+
- [SingleRecordResource](../resource/single-record-resource.md)
|
|
91
|
+
- [APIResource](../resource/api-resource.md)
|
|
92
|
+
- [SQLResource](../resource/sql-resource.md)
|
|
@@ -1,76 +1,74 @@
|
|
|
1
1
|
# ctx.route
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Current route match info, corresponding to React Router’s route; used to get the matched route config, params, etc. Use with `ctx.router` and `ctx.location`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **Linkage
|
|
11
|
-
| **View
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField** | Conditional render or display based on `route.pathname` or `route.params` |
|
|
10
|
+
| **Linkage / event flow** | Read route params (e.g. `params.name`) for logic or pass to children |
|
|
11
|
+
| **View navigation** | Compare `ctx.route.pathname` with target path to decide `ctx.router.navigate` |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.route` is only available in RunJS
|
|
13
|
+
> Note: `ctx.route` is only available in RunJS when a router context exists (e.g. JSBlock on a page, Flow page); 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
|
type RouteOptions = {
|
|
19
|
-
name?: string;
|
|
20
|
-
path?: string;
|
|
21
|
-
params?: Record<string, any>;
|
|
22
|
-
pathname?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
path?: string;
|
|
21
|
+
params?: Record<string, any>;
|
|
22
|
+
pathname?: string;
|
|
23
23
|
};
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Common
|
|
26
|
+
## Common fields
|
|
27
27
|
|
|
28
28
|
| Field | Type | Description |
|
|
29
|
-
|
|
30
|
-
| `pathname` | `string` |
|
|
31
|
-
| `params` | `Record<string, any>` | Dynamic
|
|
32
|
-
| `path` | `string` |
|
|
33
|
-
| `name` | `string` |
|
|
29
|
+
|-------|------|-------------|
|
|
30
|
+
| `pathname` | `string` | Full path of current route; same as `ctx.location.pathname` |
|
|
31
|
+
| `params` | `Record<string, any>` | Dynamic params from route template, e.g. `{ name: 'users' }` |
|
|
32
|
+
| `path` | `string` | Route template, e.g. `/admin/:name` |
|
|
33
|
+
| `name` | `string` | Route unique id; often used for tabs/views |
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Relation to ctx.router, ctx.location
|
|
36
36
|
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
| **
|
|
40
|
-
| **
|
|
41
|
-
| **
|
|
42
|
-
| **
|
|
37
|
+
| Use | Recommended |
|
|
38
|
+
|-----|-------------|
|
|
39
|
+
| **Current path** | `ctx.route.pathname` or `ctx.location.pathname`; they match when route is matched |
|
|
40
|
+
| **Route params** | `ctx.route.params`, e.g. `params.name` for current page UID |
|
|
41
|
+
| **Navigate** | `ctx.router.navigate(path)` |
|
|
42
|
+
| **Query params, state** | `ctx.location.search`, `ctx.location.state` |
|
|
43
43
|
|
|
44
|
-
`ctx.route`
|
|
44
|
+
`ctx.route` is “matched route config”; `ctx.location` is “current URL”; together they describe the current route state.
|
|
45
45
|
|
|
46
46
|
## Examples
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### Read pathname
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
|
|
52
|
-
ctx.message.info('Current Page: ' + ctx.route.pathname);
|
|
51
|
+
ctx.message.info('Current page: ' + ctx.route.pathname);
|
|
53
52
|
```
|
|
54
53
|
|
|
55
|
-
###
|
|
54
|
+
### Branch by params
|
|
56
55
|
|
|
57
56
|
```ts
|
|
58
|
-
// params.name is typically the current page UID (e.g., a Flow page identifier)
|
|
59
57
|
if (ctx.route.params?.name === 'users') {
|
|
60
|
-
//
|
|
58
|
+
// On user management page
|
|
61
59
|
}
|
|
62
60
|
```
|
|
63
61
|
|
|
64
|
-
###
|
|
62
|
+
### In Flow page
|
|
65
63
|
|
|
66
64
|
```tsx
|
|
67
65
|
<div>
|
|
68
|
-
<h1>Current
|
|
69
|
-
<p>Route
|
|
66
|
+
<h1>Current page - {ctx.route.pathname}</h1>
|
|
67
|
+
<p>Route id: {ctx.route.params?.name}</p>
|
|
70
68
|
</div>
|
|
71
69
|
```
|
|
72
70
|
|
|
73
71
|
## Related
|
|
74
72
|
|
|
75
|
-
- [ctx.router](./router.md):
|
|
76
|
-
- [ctx.location](./location.md):
|
|
73
|
+
- [ctx.router](./router.md): navigation; after `ctx.router.navigate()`, `ctx.route` updates
|
|
74
|
+
- [ctx.location](./location.md): current URL (pathname, search, hash, state); use with `ctx.route`
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
# ctx.router
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Router instance based on React Router; used for programmatic navigation in RunJS. Use with `ctx.route` and `ctx.location`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **Linkage
|
|
11
|
-
| **JSAction /
|
|
12
|
-
| **View
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField** | Button navigates to detail, list, or external link |
|
|
10
|
+
| **Linkage / event flow** | After submit success, `navigate` to list or detail, or pass state to target |
|
|
11
|
+
| **JSAction / event handler** | Navigate on form submit, link click, etc. |
|
|
12
|
+
| **View navigation** | Update URL when switching views |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.router` is only available in RunJS
|
|
14
|
+
> Note: `ctx.router` is only available in RunJS when a router context exists (e.g. JSBlock on a page, Flow page, event flow); in pure backend or non-routed contexts (e.g. workflow) it may be empty.
|
|
15
15
|
|
|
16
|
-
## Type
|
|
16
|
+
## Type
|
|
17
17
|
|
|
18
18
|
```typescript
|
|
19
19
|
router: Router
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`Router` is
|
|
22
|
+
`Router` is from `@remix-run/router`; use `ctx.router.navigate()` for navigation, back, refresh.
|
|
23
23
|
|
|
24
24
|
## Methods
|
|
25
25
|
|
|
26
26
|
### ctx.router.navigate()
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Navigate to a path, or go back/refresh.
|
|
29
29
|
|
|
30
30
|
**Signature:**
|
|
31
31
|
|
|
@@ -35,77 +35,65 @@ navigate(to: string | number | null, options?: RouterNavigateOptions): Promise<v
|
|
|
35
35
|
|
|
36
36
|
**Parameters:**
|
|
37
37
|
|
|
38
|
-
- `to`: Target path (string), relative history position (number, e.g
|
|
39
|
-
- `options`:
|
|
40
|
-
- `replace?: boolean`:
|
|
41
|
-
- `state?: any`: State
|
|
38
|
+
- `to`: Target path (string), relative history position (number, e.g. `-1` for back), or `null` (refresh current page)
|
|
39
|
+
- `options`:
|
|
40
|
+
- `replace?: boolean`: Replace current history entry (default `false`, i.e. push)
|
|
41
|
+
- `state?: any`: State passed to the target route. Not in URL; target page reads it via `ctx.location.state`. Use for sensitive or temporary data.
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
### Basic
|
|
45
|
+
### Basic navigation
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
-
// Navigate to the user list (pushes a new history entry, allows going back)
|
|
49
48
|
ctx.router.navigate('/admin/users');
|
|
50
49
|
|
|
51
|
-
// Navigate to a detail page
|
|
52
50
|
ctx.router.navigate(`/admin/users/${recordId}`);
|
|
53
51
|
```
|
|
54
52
|
|
|
55
|
-
###
|
|
53
|
+
### Replace (no new history entry)
|
|
56
54
|
|
|
57
55
|
```ts
|
|
58
|
-
// Redirect to the home page after login; the user won't return to the login page when going back
|
|
59
56
|
ctx.router.navigate('/admin', { replace: true });
|
|
60
57
|
|
|
61
|
-
// Replace the current page with the detail page after successful form submission
|
|
62
58
|
ctx.router.navigate(`/admin/users/${newId}`, { replace: true });
|
|
63
59
|
```
|
|
64
60
|
|
|
65
|
-
###
|
|
61
|
+
### Pass state
|
|
66
62
|
|
|
67
63
|
```ts
|
|
68
|
-
// Carry data during navigation; the target page retrieves it via ctx.location.state
|
|
69
64
|
ctx.router.navigate('/admin/users/123', {
|
|
70
65
|
state: { from: 'dashboard', tab: 'profile' }
|
|
71
66
|
});
|
|
72
67
|
```
|
|
73
68
|
|
|
74
|
-
### Back and
|
|
69
|
+
### Back and refresh
|
|
75
70
|
|
|
76
71
|
```ts
|
|
77
|
-
// Go back one page
|
|
78
72
|
ctx.router.navigate(-1);
|
|
79
73
|
|
|
80
|
-
// Go back two pages
|
|
81
74
|
ctx.router.navigate(-2);
|
|
82
75
|
|
|
83
|
-
// Refresh the current page
|
|
84
76
|
ctx.router.navigate(null);
|
|
85
77
|
```
|
|
86
78
|
|
|
87
|
-
##
|
|
79
|
+
## Relation to ctx.route, ctx.location
|
|
88
80
|
|
|
89
|
-
|
|
|
90
|
-
|
|
91
|
-
| **
|
|
92
|
-
| **
|
|
93
|
-
| **
|
|
94
|
-
| **
|
|
81
|
+
| Use | Recommended |
|
|
82
|
+
|-----|-------------|
|
|
83
|
+
| **Navigate** | `ctx.router.navigate(path)` |
|
|
84
|
+
| **Current path** | `ctx.route.pathname` or `ctx.location.pathname` |
|
|
85
|
+
| **State from navigation** | `ctx.location.state` |
|
|
86
|
+
| **Route params** | `ctx.route.params` |
|
|
95
87
|
|
|
96
|
-
`ctx.router`
|
|
88
|
+
`ctx.router` does “navigation”; `ctx.route` and `ctx.location` describe “current route state”.
|
|
97
89
|
|
|
98
90
|
## Notes
|
|
99
91
|
|
|
100
|
-
- `navigate(path)` pushes a new history entry
|
|
101
|
-
- `replace: true` replaces the current
|
|
102
|
-
-
|
|
103
|
-
- Data passed via `state` does not appear in the URL, making it suitable for sensitive or temporary data.
|
|
104
|
-
- It can be accessed via `ctx.location.state` on the target page.
|
|
105
|
-
- `state` is saved in the browser history and remains accessible during forward/backward navigation.
|
|
106
|
-
- `state` will be lost after a hard page refresh.
|
|
92
|
+
- `navigate(path)` by default pushes a new history entry; user can use browser back.
|
|
93
|
+
- `replace: true` replaces the current entry; use after login redirect, submit-success redirect, etc.
|
|
94
|
+
- **`state`**: Data in `state` is not in the URL; target page reads it via `ctx.location.state`. State is stored in history (back/forward keep it); it is lost on page refresh.
|
|
107
95
|
|
|
108
96
|
## Related
|
|
109
97
|
|
|
110
|
-
- [ctx.route](./route.md):
|
|
111
|
-
- [ctx.location](./location.md):
|
|
98
|
+
- [ctx.route](./route.md): current route match (pathname, params)
|
|
99
|
+
- [ctx.location](./location.md): current URL; read `state` here after navigation
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# ctx.setValue()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In JSField, JSItem, and other editable field contexts, sets the current field’s value. Use with `ctx.getValue()` for two-way binding with the form.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Write user
|
|
10
|
-
| **JSItem** | Update
|
|
11
|
-
| **JSColumn** | Update
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSField** | Write user selection or computed value in editable custom fields |
|
|
10
|
+
| **JSItem** | Update current cell value in table/sub-table editable items |
|
|
11
|
+
| **JSColumn** | Update row field value when rendering a column |
|
|
12
12
|
|
|
13
|
-
>
|
|
13
|
+
> Note: `ctx.setValue(v)` is only available in RunJS contexts with form binding; in event flow, linkage, JSBlock, etc. (no field binding) the method may not exist—use optional chaining: `ctx.setValue?.(value)`.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
setValue<T = any>(value: T): void;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
- **
|
|
21
|
+
- **Parameter**: `value` is the value to write; type depends on the field’s form item type.
|
|
22
22
|
|
|
23
23
|
## Behavior
|
|
24
24
|
|
|
25
|
-
- `ctx.setValue(v)` updates the
|
|
26
|
-
- If the form
|
|
25
|
+
- `ctx.setValue(v)` updates the current field’s value in the Ant Design Form and triggers linkage and validation.
|
|
26
|
+
- If the form is not yet rendered or the field is not registered, the call may have no effect; use `ctx.getValue()` to confirm.
|
|
27
27
|
|
|
28
28
|
## Examples
|
|
29
29
|
|
|
@@ -42,7 +42,7 @@ ctx.render(
|
|
|
42
42
|
);
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
###
|
|
45
|
+
### Set default by condition
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
const status = ctx.getValue();
|
|
@@ -51,10 +51,9 @@ if (status == null || status === '') {
|
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### Write current field when linking others
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
// Synchronously update the current field when another field changes
|
|
58
57
|
const otherValue = ctx.form?.getFieldValue('type');
|
|
59
58
|
if (otherValue === 'custom') {
|
|
60
59
|
ctx.setValue?.({ label: 'Custom', value: 'custom' });
|
|
@@ -63,11 +62,11 @@ if (otherValue === 'custom') {
|
|
|
63
62
|
|
|
64
63
|
## Notes
|
|
65
64
|
|
|
66
|
-
- In non-editable
|
|
67
|
-
-
|
|
65
|
+
- In non-editable contexts (e.g. JSField detail mode, JSBlock), `ctx.setValue` may be `undefined`; use `ctx.setValue?.(value)`.
|
|
66
|
+
- For association fields (m2o, o2m, etc.), pass a value that matches the field type (e.g. `{ id, [titleField]: label }`); see field config.
|
|
68
67
|
|
|
69
68
|
## Related
|
|
70
69
|
|
|
71
|
-
- [ctx.getValue()](./get-value.md)
|
|
72
|
-
- [ctx.form](./form.md)
|
|
73
|
-
- `js-field:value-change
|
|
70
|
+
- [ctx.getValue()](./get-value.md): get current field value; use with setValue for two-way binding
|
|
71
|
+
- [ctx.form](./form.md): Ant Design Form; read/write other fields
|
|
72
|
+
- `js-field:value-change`: container event when value changes from outside; use to update display
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ctx.t()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
i18n helper in RunJS for translating copy; uses the current context’s language. Use for buttons, titles, hints, etc.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Available in all RunJS environments.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
t(key: string, options?: Record<string, any>): string
|
|
@@ -16,38 +16,35 @@ t(key: string, options?: Record<string, any>): string
|
|
|
16
16
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
|-----------|------|-------------|
|
|
19
|
-
| `key` | `string` | Translation key or template with placeholders (e.g
|
|
20
|
-
| `options` | `object` | Optional. Interpolation
|
|
19
|
+
| `key` | `string` | Translation key or template with placeholders (e.g. `Hello {{name}}`, `{{count}} rows`) |
|
|
20
|
+
| `options` | `object` | Optional. Interpolation (e.g. `{ name: 'John', count: 5 }`) or i18n options (`defaultValue`, `ns`) |
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Returns
|
|
23
23
|
|
|
24
|
-
-
|
|
24
|
+
- Translated string; if key has no translation and no `defaultValue`, may return the key or the interpolated string.
|
|
25
25
|
|
|
26
26
|
## Namespace (ns)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
RunJS **default namespace is `runjs`**. Without `ns`, `ctx.t(key)` looks up the key in the `runjs` namespace.
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
//
|
|
32
|
-
ctx.t('Submit'); // Equivalent to ctx.t('Submit', { ns: 'runjs' })
|
|
31
|
+
ctx.t('Submit'); // same as ctx.t('Submit', { ns: 'runjs' })
|
|
33
32
|
|
|
34
|
-
// Looks up key from a specific namespace
|
|
35
33
|
ctx.t('Submit', { ns: 'myModule' });
|
|
36
34
|
|
|
37
|
-
// Searches multiple namespaces sequentially (first 'runjs', then 'common')
|
|
38
35
|
ctx.t('Save', { ns: ['runjs', 'common'] });
|
|
39
36
|
```
|
|
40
37
|
|
|
41
38
|
## Examples
|
|
42
39
|
|
|
43
|
-
### Simple
|
|
40
|
+
### Simple key
|
|
44
41
|
|
|
45
42
|
```ts
|
|
46
43
|
ctx.t('Submit');
|
|
47
44
|
ctx.t('No data');
|
|
48
45
|
```
|
|
49
46
|
|
|
50
|
-
### With
|
|
47
|
+
### With interpolation
|
|
51
48
|
|
|
52
49
|
```ts
|
|
53
50
|
const text = ctx.t('Hello {{name}}', { name: ctx.user?.nickname || 'Guest' });
|
|
@@ -58,14 +55,14 @@ ctx.render(`<div>${text}</div>`);
|
|
|
58
55
|
ctx.message.success(ctx.t('Processed {{count}} rows', { count: rows.length }));
|
|
59
56
|
```
|
|
60
57
|
|
|
61
|
-
###
|
|
58
|
+
### Relative time etc.
|
|
62
59
|
|
|
63
60
|
```ts
|
|
64
61
|
if (minutes < 60) return ctx.t('{{count}} minutes ago', { count: minutes });
|
|
65
62
|
if (hours < 24) return ctx.t('{{count}} hours ago', { count: hours });
|
|
66
63
|
```
|
|
67
64
|
|
|
68
|
-
###
|
|
65
|
+
### Specify namespace
|
|
69
66
|
|
|
70
67
|
```ts
|
|
71
68
|
ctx.t('Hello {{name}}', { name: 'Guest', ns: 'myModule' });
|
|
@@ -73,10 +70,10 @@ ctx.t('Hello {{name}}', { name: 'Guest', ns: 'myModule' });
|
|
|
73
70
|
|
|
74
71
|
## Notes
|
|
75
72
|
|
|
76
|
-
- **Localization
|
|
77
|
-
-
|
|
78
|
-
-
|
|
73
|
+
- **Localization plugin**: Activate the localization plugin to manage translations. Missing keys can be collected for translation.
|
|
74
|
+
- i18next-style interpolation: use `{{varName}}` in the key and pass the same name in `options`.
|
|
75
|
+
- Language comes from the current context (e.g. `ctx.i18n.language`, user locale).
|
|
79
76
|
|
|
80
77
|
## Related
|
|
81
78
|
|
|
82
|
-
- [ctx.i18n](./i18n.md):
|
|
79
|
+
- [ctx.i18n](./i18n.md): read or change language
|