@nocobase/plugin-flow-engine 2.1.0-alpha.7 → 2.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/ai/docs/runjs/context/block-model.md +35 -35
  2. package/dist/ai/docs/runjs/context/collection-field.md +53 -51
  3. package/dist/ai/docs/runjs/context/collection.md +39 -39
  4. package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
  5. package/dist/ai/docs/runjs/context/data-source.md +52 -44
  6. package/dist/ai/docs/runjs/context/element.md +44 -38
  7. package/dist/ai/docs/runjs/context/exit-all.md +37 -35
  8. package/dist/ai/docs/runjs/context/exit.md +38 -35
  9. package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
  10. package/dist/ai/docs/runjs/context/form.md +57 -57
  11. package/dist/ai/docs/runjs/context/get-model.md +22 -21
  12. package/dist/ai/docs/runjs/context/get-value.md +20 -19
  13. package/dist/ai/docs/runjs/context/get-var.md +61 -55
  14. package/dist/ai/docs/runjs/context/i18n.md +17 -14
  15. package/dist/ai/docs/runjs/context/import-async.md +333 -45
  16. package/dist/ai/docs/runjs/context/init-resource.md +20 -20
  17. package/dist/ai/docs/runjs/context/libs.md +31 -31
  18. package/dist/ai/docs/runjs/context/location.md +34 -31
  19. package/dist/ai/docs/runjs/context/logger.md +41 -40
  20. package/dist/ai/docs/runjs/context/make-resource.md +27 -26
  21. package/dist/ai/docs/runjs/context/message.md +42 -41
  22. package/dist/ai/docs/runjs/context/modal.md +44 -44
  23. package/dist/ai/docs/runjs/context/model.md +36 -33
  24. package/dist/ai/docs/runjs/context/notification.md +41 -40
  25. package/dist/ai/docs/runjs/context/off.md +14 -14
  26. package/dist/ai/docs/runjs/context/on.md +30 -29
  27. package/dist/ai/docs/runjs/context/open-view.md +40 -40
  28. package/dist/ai/docs/runjs/context/render.md +37 -32
  29. package/dist/ai/docs/runjs/context/request.md +46 -45
  30. package/dist/ai/docs/runjs/context/require-async.md +28 -25
  31. package/dist/ai/docs/runjs/context/resource.md +34 -34
  32. package/dist/ai/docs/runjs/context/route.md +36 -34
  33. package/dist/ai/docs/runjs/context/router.md +43 -31
  34. package/dist/ai/docs/runjs/context/set-value.md +18 -17
  35. package/dist/ai/docs/runjs/context/sql.md +7 -15
  36. package/dist/ai/docs/runjs/context/t.md +20 -17
  37. package/dist/ai/docs/runjs/context/view.md +49 -46
  38. package/dist/ai/docs/runjs/document.md +1 -0
  39. package/dist/ai/docs/runjs/import-modules.md +32 -32
  40. package/dist/ai/docs/runjs/index.md +13 -13
  41. package/dist/ai/docs/runjs/jsx.md +19 -19
  42. package/dist/ai/docs/runjs/model/form-block-model.md +1 -3
  43. package/dist/ai/docs/runjs/render.md +15 -15
  44. package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
  45. package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
  46. package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
  47. package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
  48. package/dist/ai/docs/runjs/window.md +5 -5
  49. package/dist/externalVersion.js +10 -10
  50. package/dist/node_modules/ses/package.json +1 -1
  51. package/dist/node_modules/zod/package.json +1 -1
  52. package/dist/server/collections/flowsql.js +1 -0
  53. package/package.json +2 -2
@@ -1,18 +1,18 @@
1
1
  # ctx.modal
2
2
 
3
- Shortcut API built on Ant Design Modal for opening modals (info, confirm, etc.) from RunJS. Implemented by `ctx.viewer` / the view system.
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** | 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 |
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 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?.()`.
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 = OK, false = Cancel
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` matches Ant Design Modal static method config.
27
+ `ModalConfig` is consistent with the configuration of Ant Design `Modal` static methods.
28
28
 
29
29
  ## Common Methods
30
30
 
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` |
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
- ## Config
39
+ ## Configuration Parameters
40
40
 
41
- Same as Ant Design `Modal`; common fields:
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` only) |
49
- | `onOk` | `() => void \| Promise<void>` | On OK click |
50
- | `onCancel` | `() => void` | On Cancel click |
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
- ## Relation to ctx.message, ctx.openView
52
+ ## Relationship with ctx.message and ctx.openView
53
53
 
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) |
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 info
63
+ ### Simple Information Modal
64
64
 
65
65
  ```ts
66
66
  ctx.modal.info({
67
- title: 'Notice',
67
+ title: 'Prompt',
68
68
  content: 'Operation completed',
69
69
  });
70
70
  ```
71
71
 
72
- ### Confirm and control flow
72
+ ### Confirmation Modal and Flow Control
73
73
 
74
74
  ```ts
75
75
  const confirmed = await ctx.modal.confirm({
76
- title: 'Confirm delete',
77
- content: 'Delete this record?',
78
- okText: 'OK',
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
- ### Confirm with onOk
88
+ ### Confirmation Modal with onOk
89
89
 
90
90
  ```ts
91
91
  await ctx.modal.confirm({
92
- title: 'Confirm submit',
93
- content: 'Cannot be changed after submit. Continue?',
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: 'Done' });
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): 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
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 for the current RunJS execution context; the default entry in JSBlock, JSField, JSAction, etc. The concrete type varies: e.g. `BlockModel`, `ActionModel`, `JSEditableFieldModel`.
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
- ## Use Cases
5
+ ## Scenarios
6
6
 
7
7
  | Scenario | Description |
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. |
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: For the **parent block** that hosts the current JS (e.g. form/table block), use `ctx.blockModel`; for **other models** use `ctx.getModel(uid)`.
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; at runtime it is a subclass (e.g. `BlockModel`, `FormBlockModel`, `TableBlockModel`, `JSEditableFieldModel`, `ActionModel`). Properties and methods depend on the type.
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` | 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) |
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` | 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 |
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
- ## Relation to ctx.blockModel, ctx.getModel
43
+ ## Relationship with ctx.blockModel and ctx.getModel
44
44
 
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) |
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 and `ctx.blockModel` is the form/table block that hosts it.
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
- ### Update block/action state
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
- ### Dispatch model event
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
- ### Use uid for popup or cross-model
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 of current JS
82
- - [ctx.getModel()](./get-model.md): get another model by uid
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
- 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.
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 / 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 |
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 API.
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)` | 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 |
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
- **Config** (same as [Ant Design notification](https://ant.design/components/notification)):
32
+ **Configuration Parameters** (Consistent with [Ant Design notification](https://ant.design/components/notification)):
33
33
 
34
34
  | Parameter | Type | Description |
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` |
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: 'Success',
50
- description: 'Data saved.',
49
+ message: 'Operation successful',
50
+ description: 'Data has been saved to the server.',
51
51
  });
52
52
  ```
53
53
 
54
- ### By type
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('Check console for details'),
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 duration and key
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 all
87
+ ### Close All Notifications
87
88
 
88
89
  ```ts
89
90
  ctx.notification.destroy();
90
91
  ```
91
92
 
92
- ## ctx.message vs ctx.notification
93
+ ## Difference from ctx.message
93
94
 
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 |
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): top-center short messages
104
- - [ctx.modal](./modal.md): modal confirm
105
- - [ctx.t()](./t.md): i18n; often used with notification
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 a listener registered with `ctx.on(eventName, handler)`. Use with [ctx.on](./on.md) and unsubscribe when appropriate to avoid leaks or duplicate triggers.
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 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.) |
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
- ### Pair with on in useEffect
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
- ### Unsubscribe resource event
31
+ ### Unsubscribing from resource events
32
32
 
33
33
  ```ts
34
34
  const handler = () => { /* ... */ };
35
35
  ctx.resource?.on('refresh', handler);
36
- // Later
36
+ // At the appropriate time
37
37
  ctx.resource?.off('refresh', handler);
38
38
  ```
39
39
 
40
40
  ## Notes
41
41
 
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.
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): subscribe to events
48
- - [ctx.resource](./resource.md): resource and its `on`/`off`
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 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`.
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** | 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 |
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 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 |
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:` prefix use `ctx.resource.on`; others typically use DOM events on `ctx.element` when present.
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 binding (React useEffect + cleanup)
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 not available
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
- // Cleanup: ctx.element?.removeEventListener('js-field:value-change', handler);
51
+ // During cleanup: ctx.element?.removeEventListener('js-field:value-change', handler);
51
52
  ```
52
53
 
53
- ### Update UI after resource refresh
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 render from data
59
+ // Update rendering based on data
59
60
  });
60
61
  ```
61
62
 
62
- ## With ctx.off
63
+ ## Coordination with ctx.off
63
64
 
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)`.
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. **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.
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): 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`
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`)