@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,18 +1,18 @@
|
|
|
1
1
|
# ctx.modal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shortcut API built on Ant Design Modal for opening modals (info, confirm, etc.) from RunJS. Implemented by `ctx.viewer` / the view system.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **
|
|
11
|
-
| **Linkage
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / JSField** | Show result, error, or confirmation after user action |
|
|
10
|
+
| **Event flow / action events** | Confirm before submit; use `ctx.exit()` when user cancels |
|
|
11
|
+
| **Linkage** | Show modal when validation fails |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.modal` is available in RunJS
|
|
13
|
+
> Note: `ctx.modal` is available in RunJS when a view context exists (e.g. JSBlock on a page, event flow); in backend or no-UI contexts it may be absent—use optional chaining: `ctx.modal?.confirm?.()`.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
modal: {
|
|
@@ -20,89 +20,89 @@ modal: {
|
|
|
20
20
|
success: (config: ModalConfig) => Promise<void>;
|
|
21
21
|
error: (config: ModalConfig) => Promise<void>;
|
|
22
22
|
warning: (config: ModalConfig) => Promise<void>;
|
|
23
|
-
confirm: (config: ModalConfig) => Promise<boolean>; //
|
|
23
|
+
confirm: (config: ModalConfig) => Promise<boolean>; // true = OK, false = Cancel
|
|
24
24
|
};
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
`ModalConfig`
|
|
27
|
+
`ModalConfig` matches Ant Design Modal static method config.
|
|
28
28
|
|
|
29
29
|
## Common Methods
|
|
30
30
|
|
|
31
|
-
| Method |
|
|
32
|
-
|
|
33
|
-
| `info(config)` | `Promise<void>` |
|
|
34
|
-
| `success(config)` | `Promise<void>` | Success
|
|
35
|
-
| `error(config)` | `Promise<void>` | Error
|
|
36
|
-
| `warning(config)` | `Promise<void>` | Warning
|
|
37
|
-
| `confirm(config)` | `Promise<boolean>` |
|
|
31
|
+
| Method | Returns | Description |
|
|
32
|
+
|--------|--------|-------------|
|
|
33
|
+
| `info(config)` | `Promise<void>` | Info modal |
|
|
34
|
+
| `success(config)` | `Promise<void>` | Success modal |
|
|
35
|
+
| `error(config)` | `Promise<void>` | Error modal |
|
|
36
|
+
| `warning(config)` | `Promise<void>` | Warning modal |
|
|
37
|
+
| `confirm(config)` | `Promise<boolean>` | Confirm; OK → `true`, Cancel → `false` |
|
|
38
38
|
|
|
39
|
-
##
|
|
39
|
+
## Config
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Same as Ant Design `Modal`; common fields:
|
|
42
42
|
|
|
43
43
|
| Parameter | Type | Description |
|
|
44
|
-
|
|
44
|
+
|-----------|------|-------------|
|
|
45
45
|
| `title` | `ReactNode` | Title |
|
|
46
46
|
| `content` | `ReactNode` | Content |
|
|
47
47
|
| `okText` | `string` | OK button text |
|
|
48
|
-
| `cancelText` | `string` | Cancel button text (
|
|
49
|
-
| `onOk` | `() => void \| Promise<void>` |
|
|
50
|
-
| `onCancel` | `() => void` |
|
|
48
|
+
| `cancelText` | `string` | Cancel button text (`confirm` only) |
|
|
49
|
+
| `onOk` | `() => void \| Promise<void>` | On OK click |
|
|
50
|
+
| `onCancel` | `() => void` | On Cancel click |
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## Relation to ctx.message, ctx.openView
|
|
53
53
|
|
|
54
|
-
|
|
|
55
|
-
|
|
56
|
-
| **
|
|
57
|
-
| **Info/
|
|
58
|
-
| **
|
|
59
|
-
| **Complex
|
|
54
|
+
| Use | Recommended |
|
|
55
|
+
|-----|-------------|
|
|
56
|
+
| **Short auto-dismiss** | `ctx.message` |
|
|
57
|
+
| **Info/success/error/warning modal** | `ctx.modal.info` / `success` / `error` / `warning` |
|
|
58
|
+
| **Confirm (user choice)** | `ctx.modal.confirm`; use `ctx.exit()` to control flow |
|
|
59
|
+
| **Complex form, list, etc.** | `ctx.openView` for custom view (page/drawer/dialog) |
|
|
60
60
|
|
|
61
61
|
## Examples
|
|
62
62
|
|
|
63
|
-
### Simple
|
|
63
|
+
### Simple info
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
66
|
ctx.modal.info({
|
|
67
|
-
title: '
|
|
67
|
+
title: 'Notice',
|
|
68
68
|
content: 'Operation completed',
|
|
69
69
|
});
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
###
|
|
72
|
+
### Confirm and control flow
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
75
|
const confirmed = await ctx.modal.confirm({
|
|
76
|
-
title: 'Confirm
|
|
77
|
-
content: '
|
|
78
|
-
okText: '
|
|
76
|
+
title: 'Confirm delete',
|
|
77
|
+
content: 'Delete this record?',
|
|
78
|
+
okText: 'OK',
|
|
79
79
|
cancelText: 'Cancel',
|
|
80
80
|
});
|
|
81
81
|
if (!confirmed) {
|
|
82
|
-
ctx.exit();
|
|
82
|
+
ctx.exit();
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
await ctx.runAction('destroy', { filterByTk: ctx.record?.id });
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
###
|
|
88
|
+
### Confirm with onOk
|
|
89
89
|
|
|
90
90
|
```ts
|
|
91
91
|
await ctx.modal.confirm({
|
|
92
|
-
title: 'Confirm
|
|
93
|
-
content: '
|
|
92
|
+
title: 'Confirm submit',
|
|
93
|
+
content: 'Cannot be changed after submit. Continue?',
|
|
94
94
|
async onOk() {
|
|
95
95
|
await ctx.form.submit();
|
|
96
96
|
},
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
### Error
|
|
100
|
+
### Error
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
103
|
try {
|
|
104
104
|
await someOperation();
|
|
105
|
-
ctx.modal.success({ title: 'Success', content: '
|
|
105
|
+
ctx.modal.success({ title: 'Success', content: 'Done' });
|
|
106
106
|
} catch (e) {
|
|
107
107
|
ctx.modal.error({ title: 'Error', content: e.message });
|
|
108
108
|
}
|
|
@@ -110,6 +110,6 @@ try {
|
|
|
110
110
|
|
|
111
111
|
## Related
|
|
112
112
|
|
|
113
|
-
- [ctx.message](./message.md):
|
|
114
|
-
- [ctx.exit()](./exit.md):
|
|
115
|
-
- [ctx.openView()](./open-view.md):
|
|
113
|
+
- [ctx.message](./message.md): short auto-dismiss messages
|
|
114
|
+
- [ctx.exit()](./exit.md): when user cancels confirm, use `if (!confirmed) ctx.exit()`
|
|
115
|
+
- [ctx.openView()](./open-view.md): open custom view for complex flows
|
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
# ctx.model
|
|
2
2
|
|
|
3
|
-
The `FlowModel` instance
|
|
3
|
+
The `FlowModel` instance for the current RunJS execution context; the default entry in JSBlock, JSField, JSAction, etc. The concrete type varies: e.g. `BlockModel`, `ActionModel`, `JSEditableFieldModel`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** | `ctx.model` is the
|
|
10
|
-
| **JSField / JSItem / JSColumn** | `ctx.model` is the field model
|
|
11
|
-
| **Action
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock** | `ctx.model` is the block model; access `resource`, `collection`, `setProps`, etc. |
|
|
10
|
+
| **JSField / JSItem / JSColumn** | `ctx.model` is the field model; access `setProps`, `dispatchEvent`, etc. |
|
|
11
|
+
| **Action events / ActionModel** | `ctx.model` is the action model; read/write step params, dispatch events, etc. |
|
|
12
12
|
|
|
13
|
-
> Tip:
|
|
13
|
+
> Tip: For the **parent block** that hosts the current JS (e.g. form/table block), use `ctx.blockModel`; for **other models** use `ctx.getModel(uid)`.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
model: FlowModel;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
`FlowModel` is the base
|
|
21
|
+
`FlowModel` is the base; at runtime it is a subclass (e.g. `BlockModel`, `FormBlockModel`, `TableBlockModel`, `JSEditableFieldModel`, `ActionModel`). Properties and methods depend on the type.
|
|
22
22
|
|
|
23
23
|
## Common Properties
|
|
24
24
|
|
|
25
25
|
| Property | Type | Description |
|
|
26
|
-
|
|
27
|
-
| `uid` | `string` |
|
|
28
|
-
| `collection` | `Collection` |
|
|
29
|
-
| `resource` | `Resource` |
|
|
30
|
-
| `props` | `object` | UI/behavior
|
|
31
|
-
| `subModels` | `Record<string, FlowModel>` |
|
|
32
|
-
| `parent` | `FlowModel` | Parent model (if any)
|
|
26
|
+
|----------|------|-------------|
|
|
27
|
+
| `uid` | `string` | Model unique id; use with `ctx.getModel(uid)` or popup binding |
|
|
28
|
+
| `collection` | `Collection` | Collection bound to the model (when block/field is bound to data) |
|
|
29
|
+
| `resource` | `Resource` | Resource instance; refresh, get selected rows, etc. |
|
|
30
|
+
| `props` | `object` | UI/behavior config; update with `setProps` |
|
|
31
|
+
| `subModels` | `Record<string, FlowModel>` | Child models (e.g. form fields, table columns) |
|
|
32
|
+
| `parent` | `FlowModel` | Parent model (if any) |
|
|
33
33
|
|
|
34
34
|
## Common Methods
|
|
35
35
|
|
|
36
36
|
| Method | Description |
|
|
37
|
-
|
|
38
|
-
| `setProps(partialProps: any): void` |
|
|
39
|
-
| `dispatchEvent(eventName: string, payload?: any, options?: any): Promise<any[]>` |
|
|
40
|
-
| `getStepParams?.(flowKey, stepKey)` |
|
|
41
|
-
| `setStepParams?.(flowKey, stepKey, params)` |
|
|
37
|
+
|--------|-------------|
|
|
38
|
+
| `setProps(partialProps: any): void` | Update model config and trigger re-render (e.g. `ctx.model.setProps({ loading: true })`) |
|
|
39
|
+
| `dispatchEvent(eventName: string, payload?: any, options?: any): Promise<any[]>` | Dispatch event to the model; runs flows listening for that event. Optional `payload` to handler; `options.debounce` for debounce |
|
|
40
|
+
| `getStepParams?.(flowKey, stepKey)` | Read flow step params (settings panel, custom actions, etc.) |
|
|
41
|
+
| `setStepParams?.(flowKey, stepKey, params)` | Write flow step params |
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Relation to ctx.blockModel, ctx.getModel
|
|
44
44
|
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
| **Model
|
|
48
|
-
| **Parent block of
|
|
49
|
-
| **
|
|
45
|
+
| Need | Recommended |
|
|
46
|
+
|------|-------------|
|
|
47
|
+
| **Model for current execution context** | `ctx.model` |
|
|
48
|
+
| **Parent block of current JS** | `ctx.blockModel`; use for `resource`, `form`, `collection` |
|
|
49
|
+
| **Any model by uid** | `ctx.getModel(uid)` or `ctx.getModel(uid, true)` (cross view stack) |
|
|
50
50
|
|
|
51
|
-
In
|
|
51
|
+
In JSField, `ctx.model` is the field model and `ctx.blockModel` is the form/table block that hosts it.
|
|
52
52
|
|
|
53
53
|
## Examples
|
|
54
54
|
|
|
55
|
-
###
|
|
55
|
+
### Update block/action state
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
ctx.model.setProps({ loading: true });
|
|
@@ -60,26 +60,23 @@ await doSomething();
|
|
|
60
60
|
ctx.model.setProps({ loading: false });
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
###
|
|
63
|
+
### Dispatch model event
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
// Dispatch an event to trigger a workflow configured on this model that listens for this event name
|
|
67
66
|
await ctx.model.dispatchEvent('remove');
|
|
68
67
|
|
|
69
|
-
// When a payload is provided, it is passed to the workflow handler's ctx.inputArgs
|
|
70
68
|
await ctx.model.dispatchEvent('customEvent', { id: 123 });
|
|
71
69
|
```
|
|
72
70
|
|
|
73
|
-
###
|
|
71
|
+
### Use uid for popup or cross-model
|
|
74
72
|
|
|
75
73
|
```ts
|
|
76
74
|
const myUid = ctx.model.uid;
|
|
77
|
-
// In popup configuration, you can pass openerUid: myUid for association
|
|
78
75
|
const other = ctx.getModel('other-block-uid');
|
|
79
76
|
if (other) other.rerender?.();
|
|
80
77
|
```
|
|
81
78
|
|
|
82
79
|
## Related
|
|
83
80
|
|
|
84
|
-
- [ctx.blockModel](./block-model.md):
|
|
85
|
-
- [ctx.getModel()](./get-model.md):
|
|
81
|
+
- [ctx.blockModel](./block-model.md): parent block of current JS
|
|
82
|
+
- [ctx.getModel()](./get-model.md): get another model by uid
|
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
# ctx.notification
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Global notification API based on Ant Design Notification; shows notifications in the **top-right**. Compared to `ctx.message`, notifications can have title and description and stay longer.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock /
|
|
10
|
-
| **
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock / action events** | Task done, batch result, export done |
|
|
10
|
+
| **Event flow** | System notice after async flow ends |
|
|
11
|
+
| **Longer content** | Full notification with title, description, actions |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
notification: NotificationInstance;
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`NotificationInstance` is the Ant Design notification
|
|
19
|
+
`NotificationInstance` is the Ant Design notification API.
|
|
20
20
|
|
|
21
21
|
## Common Methods
|
|
22
22
|
|
|
23
23
|
| Method | Description |
|
|
24
|
-
|
|
25
|
-
| `open(config)` |
|
|
26
|
-
| `success(config)` |
|
|
27
|
-
| `info(config)` |
|
|
28
|
-
| `warning(config)` |
|
|
29
|
-
| `error(config)` |
|
|
30
|
-
| `destroy(key?)` |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `open(config)` | Open with custom config |
|
|
26
|
+
| `success(config)` | Success notification |
|
|
27
|
+
| `info(config)` | Info notification |
|
|
28
|
+
| `warning(config)` | Warning notification |
|
|
29
|
+
| `error(config)` | Error notification |
|
|
30
|
+
| `destroy(key?)` | Close notification by key; no key = close all |
|
|
31
31
|
|
|
32
|
-
**
|
|
32
|
+
**Config** (same as [Ant Design notification](https://ant.design/components/notification)):
|
|
33
33
|
|
|
34
34
|
| Parameter | Type | Description |
|
|
35
|
-
|
|
36
|
-
| `message` | `ReactNode` |
|
|
37
|
-
| `description` | `ReactNode` |
|
|
38
|
-
| `duration` | `number` | Auto-close
|
|
39
|
-
| `key` | `string` | Unique
|
|
40
|
-
| `onClose` | `() => void` |
|
|
41
|
-
| `placement` | `string` |
|
|
35
|
+
|-----------|------|-------------|
|
|
36
|
+
| `message` | `ReactNode` | Title |
|
|
37
|
+
| `description` | `ReactNode` | Description |
|
|
38
|
+
| `duration` | `number` | Auto-close seconds; default 4.5; 0 = no auto-close |
|
|
39
|
+
| `key` | `string` | Unique id for `destroy(key)` |
|
|
40
|
+
| `onClose` | `() => void` | On close |
|
|
41
|
+
| `placement` | `string` | `topLeft` \| `topRight` \| `bottomLeft` \| `bottomRight` |
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
### Basic
|
|
45
|
+
### Basic
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
ctx.notification.open({
|
|
49
|
-
message: '
|
|
50
|
-
description: 'Data
|
|
49
|
+
message: 'Success',
|
|
50
|
+
description: 'Data saved.',
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### By type
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
ctx.notification.success({
|
|
@@ -61,7 +61,7 @@ ctx.notification.success({
|
|
|
61
61
|
|
|
62
62
|
ctx.notification.error({
|
|
63
63
|
message: ctx.t('Export failed'),
|
|
64
|
-
description: ctx.t('
|
|
64
|
+
description: ctx.t('Check console for details'),
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
ctx.notification.warning({
|
|
@@ -70,37 +70,36 @@ ctx.notification.warning({
|
|
|
70
70
|
});
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### Custom
|
|
73
|
+
### Custom duration and key
|
|
74
74
|
|
|
75
75
|
```ts
|
|
76
76
|
ctx.notification.open({
|
|
77
77
|
key: 'task-123',
|
|
78
78
|
message: ctx.t('Task in progress'),
|
|
79
79
|
description: ctx.t('Please wait...'),
|
|
80
|
-
duration: 0,
|
|
80
|
+
duration: 0,
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
// Manually close after task completion
|
|
84
83
|
ctx.notification.destroy('task-123');
|
|
85
84
|
```
|
|
86
85
|
|
|
87
|
-
### Close
|
|
86
|
+
### Close all
|
|
88
87
|
|
|
89
88
|
```ts
|
|
90
89
|
ctx.notification.destroy();
|
|
91
90
|
```
|
|
92
91
|
|
|
93
|
-
##
|
|
92
|
+
## ctx.message vs ctx.notification
|
|
94
93
|
|
|
95
|
-
|
|
|
96
|
-
|
|
97
|
-
| **Position** | Top center
|
|
98
|
-
| **Structure** | Single
|
|
99
|
-
| **
|
|
100
|
-
| **Typical
|
|
94
|
+
| | ctx.message | ctx.notification |
|
|
95
|
+
|---|-------------|-------------------|
|
|
96
|
+
| **Position** | Top center | Top right (configurable) |
|
|
97
|
+
| **Structure** | Single line | Title + description |
|
|
98
|
+
| **Use** | Short, auto-dismiss | Longer, can stay |
|
|
99
|
+
| **Typical** | Success, validation, copy | Task done, system notice |
|
|
101
100
|
|
|
102
101
|
## Related
|
|
103
102
|
|
|
104
|
-
- [ctx.message](./message.md) -
|
|
105
|
-
- [ctx.modal](./modal.md)
|
|
106
|
-
- [ctx.t()](./t.md)
|
|
103
|
+
- [ctx.message](./message.md): top-center short messages
|
|
104
|
+
- [ctx.modal](./modal.md): modal confirm
|
|
105
|
+
- [ctx.t()](./t.md): i18n; often used with notification
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# ctx.off()
|
|
2
2
|
|
|
3
|
-
Removes
|
|
3
|
+
Removes a listener registered with `ctx.on(eventName, handler)`. Use with [ctx.on](./on.md) and unsubscribe when appropriate to avoid leaks or duplicate triggers.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **React useEffect
|
|
10
|
-
| **JSField / JSEditableField** | Unsubscribe from `js-field:value-change`
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **React useEffect cleanup** | Call in `useEffect` cleanup; remove on unmount |
|
|
10
|
+
| **JSField / JSEditableField** | Unsubscribe from `js-field:value-change` when doing two-way binding |
|
|
11
|
+
| **resource** | Unsubscribe from `ctx.resource.on` (refresh, saved, etc.) |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
off(eventName: string, handler: (event?: any) => void): void;
|
|
@@ -18,7 +18,7 @@ off(eventName: string, handler: (event?: any) => void): void;
|
|
|
18
18
|
|
|
19
19
|
## Examples
|
|
20
20
|
|
|
21
|
-
###
|
|
21
|
+
### Pair with on in useEffect
|
|
22
22
|
|
|
23
23
|
```tsx
|
|
24
24
|
React.useEffect(() => {
|
|
@@ -28,21 +28,21 @@ React.useEffect(() => {
|
|
|
28
28
|
}, []);
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
###
|
|
31
|
+
### Unsubscribe resource event
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
34
|
const handler = () => { /* ... */ };
|
|
35
35
|
ctx.resource?.on('refresh', handler);
|
|
36
|
-
//
|
|
36
|
+
// Later
|
|
37
37
|
ctx.resource?.off('refresh', handler);
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Notes
|
|
41
41
|
|
|
42
|
-
1. **
|
|
43
|
-
2. **
|
|
42
|
+
1. **Same handler reference**: The `handler` passed to `ctx.off` must be the same reference as in `ctx.on`, or it will not be removed.
|
|
43
|
+
2. **Clean up in time**: Call `ctx.off` before unmount or context destroy to avoid leaks.
|
|
44
44
|
|
|
45
|
-
## Related
|
|
45
|
+
## Related
|
|
46
46
|
|
|
47
|
-
- [ctx.on](./on.md)
|
|
48
|
-
- [ctx.resource](./resource.md)
|
|
47
|
+
- [ctx.on](./on.md): subscribe to events
|
|
48
|
+
- [ctx.resource](./resource.md): resource and its `on`/`off`
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# ctx.on()
|
|
2
2
|
|
|
3
|
-
Subscribe to context events (
|
|
3
|
+
Subscribe to context events in RunJS (e.g. field value change, property change, resource refresh). Events are mapped to custom DOM events on `ctx.element` or the internal event bus on `ctx.resource`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField / JSEditableField** |
|
|
10
|
-
| **JSBlock / JSItem / JSColumn** | Listen
|
|
11
|
-
| **resource
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSField / JSEditableField** | Sync UI when field value changes from outside (form, linkage); two-way binding |
|
|
10
|
+
| **JSBlock / JSItem / JSColumn** | Listen to custom events on the container; react to data/state changes |
|
|
11
|
+
| **resource** | Listen to refresh, save, etc.; run logic after data updates |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
on(eventName: string, handler: (event?: any) => void): void;
|
|
@@ -18,17 +18,17 @@ on(eventName: string, handler: (event?: any) => void): void;
|
|
|
18
18
|
|
|
19
19
|
## Common Events
|
|
20
20
|
|
|
21
|
-
| Event
|
|
22
|
-
|
|
23
|
-
| `js-field:value-change` | Field value
|
|
24
|
-
| `resource:refresh` | Resource data
|
|
25
|
-
| `resource:saved` | Resource
|
|
21
|
+
| Event | Description | Source |
|
|
22
|
+
|-------|-------------|--------|
|
|
23
|
+
| `js-field:value-change` | Field value changed from outside (form linkage, default value) | CustomEvent on `ctx.element`; `ev.detail` = new value |
|
|
24
|
+
| `resource:refresh` | Resource data refreshed | `ctx.resource` event bus |
|
|
25
|
+
| `resource:saved` | Resource save completed | `ctx.resource` event bus |
|
|
26
26
|
|
|
27
|
-
>
|
|
27
|
+
> Events with `resource:` prefix use `ctx.resource.on`; others typically use DOM events on `ctx.element` when present.
|
|
28
28
|
|
|
29
29
|
## Examples
|
|
30
30
|
|
|
31
|
-
###
|
|
31
|
+
### Two-way binding (React useEffect + cleanup)
|
|
32
32
|
|
|
33
33
|
```tsx
|
|
34
34
|
React.useEffect(() => {
|
|
@@ -40,41 +40,40 @@ React.useEffect(() => {
|
|
|
40
40
|
}, []);
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
### Native DOM
|
|
43
|
+
### Native DOM when ctx.on not available
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
-
// When ctx.on is not provided, you can use ctx.element directly
|
|
47
46
|
const handler = (ev) => {
|
|
48
47
|
if (selectEl) selectEl.value = String(ev?.detail ?? '');
|
|
49
48
|
};
|
|
50
49
|
ctx.element?.addEventListener('js-field:value-change', handler);
|
|
51
|
-
//
|
|
50
|
+
// Cleanup: ctx.element?.removeEventListener('js-field:value-change', handler);
|
|
52
51
|
```
|
|
53
52
|
|
|
54
|
-
###
|
|
53
|
+
### Update UI after resource refresh
|
|
55
54
|
|
|
56
55
|
```ts
|
|
57
56
|
ctx.resource?.on('refresh', () => {
|
|
58
57
|
const data = ctx.resource?.getData?.();
|
|
59
|
-
// Update
|
|
58
|
+
// Update render from data
|
|
60
59
|
});
|
|
61
60
|
```
|
|
62
61
|
|
|
63
|
-
##
|
|
62
|
+
## With ctx.off
|
|
64
63
|
|
|
65
|
-
-
|
|
66
|
-
- In React, `ctx.off`
|
|
67
|
-
- `ctx.off` may not exist;
|
|
64
|
+
- Unsubscribe with [ctx.off](./off.md) when appropriate to avoid leaks or duplicate handlers.
|
|
65
|
+
- In React, usually call `ctx.off` in `useEffect` cleanup.
|
|
66
|
+
- `ctx.off` may not exist; use optional chaining: `ctx.off?.('eventName', handler)`.
|
|
68
67
|
|
|
69
68
|
## Notes
|
|
70
69
|
|
|
71
|
-
1. **
|
|
72
|
-
2. **Lifecycle**: Remove listeners before
|
|
73
|
-
3. **Event
|
|
70
|
+
1. **Pair with off**: Each `ctx.on(eventName, handler)` should have a matching `ctx.off(eventName, handler)` with the same `handler` reference.
|
|
71
|
+
2. **Lifecycle**: Remove listeners before unmount or context destroy to avoid leaks.
|
|
72
|
+
3. **Event support**: Different context types support different events; see component docs.
|
|
74
73
|
|
|
75
|
-
## Related
|
|
74
|
+
## Related
|
|
76
75
|
|
|
77
|
-
- [ctx.off](./off.md)
|
|
78
|
-
- [ctx.element](./element.md)
|
|
79
|
-
- [ctx.resource](./resource.md)
|
|
80
|
-
- [ctx.setValue](./set-value.md)
|
|
76
|
+
- [ctx.off](./off.md): remove listener
|
|
77
|
+
- [ctx.element](./element.md): container and DOM events
|
|
78
|
+
- [ctx.resource](./resource.md): resource and its `on`/`off`
|
|
79
|
+
- [ctx.setValue](./set-value.md): sets field value; triggers `js-field:value-change`
|