@nocobase/plugin-flow-engine 2.0.22 → 2.1.0-alpha.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 +53 -51
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
- package/dist/ai/docs/runjs/context/data-source.md +52 -44
- package/dist/ai/docs/runjs/context/element.md +44 -38
- package/dist/ai/docs/runjs/context/exit-all.md +37 -35
- package/dist/ai/docs/runjs/context/exit.md +38 -35
- package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +22 -21
- package/dist/ai/docs/runjs/context/get-value.md +20 -19
- package/dist/ai/docs/runjs/context/get-var.md +61 -55
- package/dist/ai/docs/runjs/context/i18n.md +17 -14
- package/dist/ai/docs/runjs/context/import-async.md +333 -45
- 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 +34 -31
- package/dist/ai/docs/runjs/context/logger.md +41 -40
- package/dist/ai/docs/runjs/context/make-resource.md +27 -26
- package/dist/ai/docs/runjs/context/message.md +42 -41
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +36 -33
- package/dist/ai/docs/runjs/context/notification.md +41 -40
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +30 -29
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +37 -32
- package/dist/ai/docs/runjs/context/request.md +46 -45
- package/dist/ai/docs/runjs/context/require-async.md +28 -25
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +36 -34
- package/dist/ai/docs/runjs/context/router.md +43 -31
- package/dist/ai/docs/runjs/context/set-value.md +18 -17
- package/dist/ai/docs/runjs/context/t.md +20 -17
- package/dist/ai/docs/runjs/context/view.md +49 -46
- package/dist/ai/docs/runjs/document.md +1 -0
- 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 +1 -3
- 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/client/index.js +1 -1
- 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
|
+
A shortcut API based on Ant Design Modal, used to actively open modal boxes (information prompts, confirmation pop-ups, etc.) in RunJS. It is 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** | Display operation results, error prompts, or secondary confirmations after user interaction. |
|
|
10
|
+
| **Workflow / Action Events** | Pop-up confirmation before submission; terminate subsequent steps via `ctx.exit()` if the user cancels. |
|
|
11
|
+
| **Linkage Rules** | Pop-up prompts for the user when validation fails. |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.modal` is available in RunJS
|
|
13
|
+
> Note: `ctx.modal` is available in RunJS environments with a view context (such as JSBlocks within a page, workflows, etc.); it may not exist in the backend or non-UI contexts. It is recommended to use optional chaining (`ctx.modal?.confirm?.()`) when calling it.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
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>; // true
|
|
23
|
+
confirm: (config: ModalConfig) => Promise<boolean>; // Returns true if the user clicks OK, false if they cancel
|
|
24
24
|
};
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
`ModalConfig`
|
|
27
|
+
`ModalConfig` is consistent with the configuration of Ant Design `Modal` static methods.
|
|
28
28
|
|
|
29
29
|
## Common Methods
|
|
30
30
|
|
|
31
|
-
| Method |
|
|
32
|
-
|
|
33
|
-
| `info(config)` | `Promise<void>` |
|
|
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>` |
|
|
31
|
+
| Method | Return Value | Description |
|
|
32
|
+
|------|--------|------|
|
|
33
|
+
| `info(config)` | `Promise<void>` | Information prompt modal |
|
|
34
|
+
| `success(config)` | `Promise<void>` | Success prompt modal |
|
|
35
|
+
| `error(config)` | `Promise<void>` | Error prompt modal |
|
|
36
|
+
| `warning(config)` | `Promise<void>` | Warning prompt modal |
|
|
37
|
+
| `confirm(config)` | `Promise<boolean>` | Confirmation modal; returns `true` if the user clicks OK, and `false` if they cancel |
|
|
38
38
|
|
|
39
|
-
##
|
|
39
|
+
## Configuration Parameters
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Consistent with Ant Design `Modal`, common fields include:
|
|
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 (`confirm`
|
|
49
|
-
| `onOk` | `() => void \| Promise<void>` |
|
|
50
|
-
| `onCancel` | `() => void` |
|
|
48
|
+
| `cancelText` | `string` | Cancel button text (only for `confirm`) |
|
|
49
|
+
| `onOk` | `() => void \| Promise<void>` | Executed when clicking OK |
|
|
50
|
+
| `onCancel` | `() => void` | Executed when clicking Cancel |
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## Relationship with ctx.message and ctx.openView
|
|
53
53
|
|
|
54
|
-
|
|
|
55
|
-
|
|
56
|
-
| **
|
|
57
|
-
| **Info/
|
|
58
|
-
| **
|
|
59
|
-
| **Complex
|
|
54
|
+
| Purpose | Recommended Usage |
|
|
55
|
+
|------|----------|
|
|
56
|
+
| **Lightweight temporary prompt** | `ctx.message`, disappears automatically |
|
|
57
|
+
| **Info/Success/Error/Warning modal** | `ctx.modal.info` / `success` / `error` / `warning` |
|
|
58
|
+
| **Secondary confirmation (requires user choice)** | `ctx.modal.confirm`, used with `ctx.exit()` to control the flow |
|
|
59
|
+
| **Complex interactions like forms or lists** | `ctx.openView` to open a custom view (page/drawer/modal) |
|
|
60
60
|
|
|
61
61
|
## Examples
|
|
62
62
|
|
|
63
|
-
### Simple
|
|
63
|
+
### Simple Information Modal
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
66
|
ctx.modal.info({
|
|
67
|
-
title: '
|
|
67
|
+
title: 'Prompt',
|
|
68
68
|
content: 'Operation completed',
|
|
69
69
|
});
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
###
|
|
72
|
+
### Confirmation Modal and Flow Control
|
|
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: 'Are you sure you want to delete this record?',
|
|
78
|
+
okText: 'Confirm',
|
|
79
79
|
cancelText: 'Cancel',
|
|
80
80
|
});
|
|
81
81
|
if (!confirmed) {
|
|
82
|
-
ctx.exit();
|
|
82
|
+
ctx.exit(); // Terminate subsequent steps if the user cancels
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
await ctx.runAction('destroy', { filterByTk: ctx.record?.id });
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
###
|
|
88
|
+
### Confirmation Modal with onOk
|
|
89
89
|
|
|
90
90
|
```ts
|
|
91
91
|
await ctx.modal.confirm({
|
|
92
|
-
title: 'Confirm
|
|
93
|
-
content: '
|
|
92
|
+
title: 'Confirm Submission',
|
|
93
|
+
content: 'Changes cannot be modified after submission. Do you want to continue?',
|
|
94
94
|
async onOk() {
|
|
95
95
|
await ctx.form.submit();
|
|
96
96
|
},
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
### Error
|
|
100
|
+
### Error Prompt
|
|
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: 'Operation completed' });
|
|
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): Lightweight temporary prompt, disappears automatically
|
|
114
|
+
- [ctx.exit()](./exit.md): Commonly used as `if (!confirmed) ctx.exit()` to terminate the flow when a user cancels confirmation
|
|
115
|
+
- [ctx.openView()](./open-view.md): Opens a custom view, suitable for complex interactions
|
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
# ctx.model
|
|
2
2
|
|
|
3
|
-
The `FlowModel` instance
|
|
3
|
+
The `FlowModel` instance where the current RunJS execution context is located. It serves as the default entry point for scenarios like JSBlock, JSField, and JSAction. The specific type varies depending on the context: it could be a subclass such as `BlockModel`, `ActionModel`, or `JSEditableFieldModel`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Scenarios
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** | `ctx.model` is the block model
|
|
10
|
-
| **JSField / JSItem / JSColumn** | `ctx.model` is the field model
|
|
11
|
-
| **Action
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock** | `ctx.model` is the current block model. You can access `resource`, `collection`, `setProps`, etc. |
|
|
10
|
+
| **JSField / JSItem / JSColumn** | `ctx.model` is the field model. You can access `setProps`, `dispatchEvent`, etc. |
|
|
11
|
+
| **Action Events / ActionModel** | `ctx.model` is the action model. You can read/write step parameters, dispatch events, etc. |
|
|
12
12
|
|
|
13
|
-
> Tip:
|
|
13
|
+
> Tip: If you need to access the **parent block carrying the current JS** (e.g., a Form or Table block), use `ctx.blockModel`. To access **other models**, use `ctx.getModel(uid)`.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
model: FlowModel;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
`FlowModel` is the base
|
|
21
|
+
`FlowModel` is the base class. At runtime, it is an instance of various subclasses (such as `BlockModel`, `FormBlockModel`, `TableBlockModel`, `JSEditableFieldModel`, `ActionModel`, etc.). Available properties and methods depend on the specific 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` | Unique identifier of the model. Can be used for `ctx.getModel(uid)` or popup UID binding. |
|
|
28
|
+
| `collection` | `Collection` | The collection bound to the current model (exists when the block/field is bound to data). |
|
|
29
|
+
| `resource` | `Resource` | Associated resource instance, used for refreshing, getting selected rows, etc. |
|
|
30
|
+
| `props` | `object` | UI/behavior configuration of the model. Can be updated using `setProps`. |
|
|
31
|
+
| `subModels` | `Record<string, FlowModel>` | Collection of child models (e.g., fields within a form, columns within a table). |
|
|
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` | Updates model configuration and triggers re-rendering (e.g., `ctx.model.setProps({ loading: true })`). |
|
|
39
|
+
| `dispatchEvent(eventName: string, payload?: any, options?: any): Promise<any[]>` | Dispatches an event to the model, triggering workflows configured on that model that listen for the event name. Optional `payload` is passed to the workflow handler; `options.debounce` enables debouncing. |
|
|
40
|
+
| `getStepParams?.(flowKey, stepKey)` | Reads configuration flow step parameters (used in settings panels, custom actions, etc.). |
|
|
41
|
+
| `setStepParams?.(flowKey, stepKey, params)` | Writes configuration flow step parameters. |
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Relationship with ctx.blockModel and ctx.getModel
|
|
44
44
|
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
| **Model
|
|
48
|
-
| **Parent block of current JS** | `ctx.blockModel
|
|
49
|
-
| **
|
|
45
|
+
| Requirement | Recommended Usage |
|
|
46
|
+
|------|----------|
|
|
47
|
+
| **Model of the current execution context** | `ctx.model` |
|
|
48
|
+
| **Parent block of the current JS** | `ctx.blockModel`. Often used to access `resource`, `form`, or `collection`. |
|
|
49
|
+
| **Get any model by UID** | `ctx.getModel(uid)` or `ctx.getModel(uid, true)` (search across view stacks). |
|
|
50
50
|
|
|
51
|
-
In JSField, `ctx.model` is the field model
|
|
51
|
+
In a JSField, `ctx.model` is the field model, while `ctx.blockModel` is the Form or Table block containing that field.
|
|
52
52
|
|
|
53
53
|
## Examples
|
|
54
54
|
|
|
55
|
-
###
|
|
55
|
+
### Updating Block/Action Status
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
ctx.model.setProps({ loading: true });
|
|
@@ -60,23 +60,26 @@ await doSomething();
|
|
|
60
60
|
ctx.model.setProps({ loading: false });
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
###
|
|
63
|
+
### Dispatching Model Events
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
+
// Dispatch an event to trigger a workflow configured on this model that listens for this event name
|
|
66
67
|
await ctx.model.dispatchEvent('remove');
|
|
67
68
|
|
|
69
|
+
// When a payload is provided, it is passed to the workflow handler's ctx.inputArgs
|
|
68
70
|
await ctx.model.dispatchEvent('customEvent', { id: 123 });
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
###
|
|
73
|
+
### Using UID for Popup Binding or Cross-Model Access
|
|
72
74
|
|
|
73
75
|
```ts
|
|
74
76
|
const myUid = ctx.model.uid;
|
|
77
|
+
// In popup configuration, you can pass openerUid: myUid for association
|
|
75
78
|
const other = ctx.getModel('other-block-uid');
|
|
76
79
|
if (other) other.rerender?.();
|
|
77
80
|
```
|
|
78
81
|
|
|
79
82
|
## Related
|
|
80
83
|
|
|
81
|
-
- [ctx.blockModel](./block-model.md): parent block
|
|
82
|
-
- [ctx.getModel()](./get-model.md):
|
|
84
|
+
- [ctx.blockModel](./block-model.md): The parent block model where the current JS is located.
|
|
85
|
+
- [ctx.getModel()](./get-model.md): Get other models by UID.
|
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
# ctx.notification
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Based on Ant Design Notification, this global notification API is used to display notification panels in the **top-right corner** of the page. Compared to `ctx.message`, notifications can include a title and description, making them suitable for content that needs to be displayed for a longer period or requires user attention.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock /
|
|
10
|
-
| **
|
|
11
|
-
| **
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / Action Events** | Task completion notifications, batch operation results, export completion, etc. |
|
|
10
|
+
| **FlowEngine** | System-level alerts after asynchronous processes end. |
|
|
11
|
+
| **Content requiring longer display** | Full notifications with titles, descriptions, and action buttons. |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type Definition
|
|
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 interface, providing the following methods.
|
|
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)` | Opens a notification with custom configuration |
|
|
26
|
+
| `success(config)` | Displays a success notification |
|
|
27
|
+
| `info(config)` | Displays an information notification |
|
|
28
|
+
| `warning(config)` | Displays a warning notification |
|
|
29
|
+
| `error(config)` | Displays an error notification |
|
|
30
|
+
| `destroy(key?)` | Closes the notification with the specified key; if no key is provided, closes all notifications |
|
|
31
31
|
|
|
32
|
-
**
|
|
32
|
+
**Configuration Parameters** (Consistent with [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 seconds
|
|
39
|
-
| `key` | `string` | Unique
|
|
40
|
-
| `onClose` | `() => void` |
|
|
41
|
-
| `placement` | `string` | `topLeft` \| `topRight` \| `bottomLeft` \| `bottomRight` |
|
|
35
|
+
|------|------|------|
|
|
36
|
+
| `message` | `ReactNode` | Notification title |
|
|
37
|
+
| `description` | `ReactNode` | Notification description |
|
|
38
|
+
| `duration` | `number` | Auto-close delay (seconds). Default is 4.5 seconds; set to 0 to disable auto-close |
|
|
39
|
+
| `key` | `string` | Unique identifier for the notification, used for `destroy(key)` to close a specific notification |
|
|
40
|
+
| `onClose` | `() => void` | Callback function triggered when the notification is closed |
|
|
41
|
+
| `placement` | `string` | Position: `topLeft` \| `topRight` \| `bottomLeft` \| `bottomRight` |
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
### Basic
|
|
45
|
+
### Basic Usage
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
ctx.notification.open({
|
|
49
|
-
message: '
|
|
50
|
-
description: 'Data saved.',
|
|
49
|
+
message: 'Operation successful',
|
|
50
|
+
description: 'Data has been saved to the server.',
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### Shortcut Calls 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('Please check the console for details'),
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
ctx.notification.warning({
|
|
@@ -70,36 +70,37 @@ 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, // Do not auto-close
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
// Manually close after task completion
|
|
83
84
|
ctx.notification.destroy('task-123');
|
|
84
85
|
```
|
|
85
86
|
|
|
86
|
-
### Close
|
|
87
|
+
### Close All Notifications
|
|
87
88
|
|
|
88
89
|
```ts
|
|
89
90
|
ctx.notification.destroy();
|
|
90
91
|
```
|
|
91
92
|
|
|
92
|
-
##
|
|
93
|
+
## Difference from ctx.message
|
|
93
94
|
|
|
94
|
-
| | ctx.message | ctx.notification |
|
|
95
|
-
|
|
96
|
-
| **Position** | Top center | Top right (configurable) |
|
|
97
|
-
| **Structure** | Single
|
|
98
|
-
| **
|
|
99
|
-
| **Typical** |
|
|
95
|
+
| Feature | ctx.message | ctx.notification |
|
|
96
|
+
|------|--------------|------------------|
|
|
97
|
+
| **Position** | Top center of the page | Top right corner (configurable) |
|
|
98
|
+
| **Structure** | Single-line light hint | Includes title + description |
|
|
99
|
+
| **Purpose** | Temporary feedback, disappears automatically | Complete notification, can be displayed for a long time |
|
|
100
|
+
| **Typical Scenarios** | Operation success, validation failure, copy success | Task completion, system messages, longer content requiring user attention |
|
|
100
101
|
|
|
101
102
|
## Related
|
|
102
103
|
|
|
103
|
-
- [ctx.message](./message.md)
|
|
104
|
-
- [ctx.modal](./modal.md)
|
|
105
|
-
- [ctx.t()](./t.md)
|
|
104
|
+
- [ctx.message](./message.md) - Top light hint, suitable for quick feedback
|
|
105
|
+
- [ctx.modal](./modal.md) - Modal confirmation, blocking interaction
|
|
106
|
+
- [ctx.t()](./t.md) - Internationalization, often used in conjunction with notifications
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# ctx.off()
|
|
2
2
|
|
|
3
|
-
Removes
|
|
3
|
+
Removes event listeners registered via `ctx.on(eventName, handler)`. It is often used in conjunction with [ctx.on](./on.md) to unsubscribe at the appropriate time, preventing memory 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** | Called within the `useEffect` cleanup function to remove listeners when the component unmounts. |
|
|
10
|
+
| **JSField / JSEditableField** | Unsubscribe from `js-field:value-change` during two-way data binding for fields. |
|
|
11
|
+
| **Resource Related** | Unsubscribe from listeners like `refresh` or `saved` registered via `ctx.resource.on`. |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type Definition
|
|
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
|
+
### Paired usage in React useEffect
|
|
22
22
|
|
|
23
23
|
```tsx
|
|
24
24
|
React.useEffect(() => {
|
|
@@ -28,21 +28,21 @@ React.useEffect(() => {
|
|
|
28
28
|
}, []);
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
###
|
|
31
|
+
### Unsubscribing from resource events
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
34
|
const handler = () => { /* ... */ };
|
|
35
35
|
ctx.resource?.on('refresh', handler);
|
|
36
|
-
//
|
|
36
|
+
// At the appropriate time
|
|
37
37
|
ctx.resource?.off('refresh', handler);
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Notes
|
|
41
41
|
|
|
42
|
-
1. **
|
|
43
|
-
2. **
|
|
42
|
+
1. **Consistent handler reference**: The `handler` passed to `ctx.off` must be the same reference as the one used in `ctx.on`; otherwise, it cannot be correctly removed.
|
|
43
|
+
2. **Timely cleanup**: Call `ctx.off` before the component unmounts or the context is destroyed to avoid memory leaks.
|
|
44
44
|
|
|
45
|
-
## Related
|
|
45
|
+
## Related Documents
|
|
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 instance and its `on`/`off` methods
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# ctx.on()
|
|
2
2
|
|
|
3
|
-
Subscribe to context events
|
|
3
|
+
Subscribe to context events (such as field value changes, property changes, resource refreshes, etc.) in RunJS. Events are mapped to custom DOM events on `ctx.element` or internal event bus events of `ctx.resource` based on their type.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField / JSEditableField** |
|
|
10
|
-
| **JSBlock / JSItem / JSColumn** | Listen
|
|
11
|
-
| **resource** | Listen
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSField / JSEditableField** | Listen for field value changes from external sources (forms, linkages, etc.) to synchronously update the UI, achieving two-way binding. |
|
|
10
|
+
| **JSBlock / JSItem / JSColumn** | Listen for custom events on the container to respond to data or state changes. |
|
|
11
|
+
| **resource related** | Listen for resource lifecycle events such as refresh or save to execute logic after data updates. |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type Definition
|
|
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 | Description | Source |
|
|
22
|
-
|
|
23
|
-
| `js-field:value-change` | Field value
|
|
24
|
-
| `resource:refresh` | Resource data refreshed | `ctx.resource` event bus |
|
|
25
|
-
| `resource:saved` | Resource
|
|
21
|
+
| Event Name | Description | Event Source |
|
|
22
|
+
|--------|------|----------|
|
|
23
|
+
| `js-field:value-change` | Field value modified externally (e.g., form linkage, default value update) | CustomEvent on `ctx.element`, where `ev.detail` is the new value |
|
|
24
|
+
| `resource:refresh` | Resource data has been refreshed | `ctx.resource` event bus |
|
|
25
|
+
| `resource:saved` | Resource saving completed | `ctx.resource` event bus |
|
|
26
26
|
|
|
27
|
-
> Events with `resource:`
|
|
27
|
+
> Event mapping rules: Events prefixed with `resource:` go through `ctx.resource.on`, while others typically go through DOM events on `ctx.element` (if it exists).
|
|
28
28
|
|
|
29
29
|
## Examples
|
|
30
30
|
|
|
31
|
-
### Two-way
|
|
31
|
+
### Field Two-way Binding (React useEffect + Cleanup)
|
|
32
32
|
|
|
33
33
|
```tsx
|
|
34
34
|
React.useEffect(() => {
|
|
@@ -40,40 +40,41 @@ React.useEffect(() => {
|
|
|
40
40
|
}, []);
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
### Native DOM when ctx.on
|
|
43
|
+
### Native DOM Listening (Alternative when ctx.on is unavailable)
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
+
// When ctx.on is not provided, you can use ctx.element directly
|
|
46
47
|
const handler = (ev) => {
|
|
47
48
|
if (selectEl) selectEl.value = String(ev?.detail ?? '');
|
|
48
49
|
};
|
|
49
50
|
ctx.element?.addEventListener('js-field:value-change', handler);
|
|
50
|
-
//
|
|
51
|
+
// During cleanup: ctx.element?.removeEventListener('js-field:value-change', handler);
|
|
51
52
|
```
|
|
52
53
|
|
|
53
|
-
###
|
|
54
|
+
### Updating UI After Resource Refresh
|
|
54
55
|
|
|
55
56
|
```ts
|
|
56
57
|
ctx.resource?.on('refresh', () => {
|
|
57
58
|
const data = ctx.resource?.getData?.();
|
|
58
|
-
// Update
|
|
59
|
+
// Update rendering based on data
|
|
59
60
|
});
|
|
60
61
|
```
|
|
61
62
|
|
|
62
|
-
##
|
|
63
|
+
## Coordination with ctx.off
|
|
63
64
|
|
|
64
|
-
-
|
|
65
|
-
- In React,
|
|
66
|
-
- `ctx.off` may not exist; use optional chaining: `ctx.off?.('eventName', handler)`.
|
|
65
|
+
- Listeners registered using `ctx.on` should be removed at the appropriate time via [ctx.off](./off.md) to avoid memory leaks or duplicate triggers.
|
|
66
|
+
- In React, `ctx.off` is typically called within the cleanup function of `useEffect`.
|
|
67
|
+
- `ctx.off` may not exist; it is recommended to use optional chaining: `ctx.off?.('eventName', handler)`.
|
|
67
68
|
|
|
68
69
|
## Notes
|
|
69
70
|
|
|
70
|
-
1. **
|
|
71
|
-
2. **Lifecycle**: Remove listeners before
|
|
72
|
-
3. **Event
|
|
71
|
+
1. **Paired Cancellation**: Every `ctx.on(eventName, handler)` should have a corresponding `ctx.off(eventName, handler)`, and the `handler` reference passed must be identical.
|
|
72
|
+
2. **Lifecycle**: Remove listeners before the component unmounts or the context is destroyed to prevent memory leaks.
|
|
73
|
+
3. **Event Availability**: Different context types support different events. Please refer to the specific component documentation for details.
|
|
73
74
|
|
|
74
|
-
## Related
|
|
75
|
+
## Related Documentation
|
|
75
76
|
|
|
76
|
-
- [ctx.off](./off.md)
|
|
77
|
-
- [ctx.element](./element.md)
|
|
78
|
-
- [ctx.resource](./resource.md)
|
|
79
|
-
- [ctx.setValue](./set-value.md)
|
|
77
|
+
- [ctx.off](./off.md) - Remove event listeners
|
|
78
|
+
- [ctx.element](./element.md) - Rendering container and DOM events
|
|
79
|
+
- [ctx.resource](./resource.md) - Resource instance and its `on`/`off` methods
|
|
80
|
+
- [ctx.setValue](./set-value.md) - Set field value (triggers `js-field:value-change`)
|