@nocobase/plugin-flow-engine 2.1.0-beta.14 → 2.1.0-beta.16
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/ai-employees/nathan/index.d.ts +10 -0
- package/dist/ai/ai-employees/nathan/index.js +41 -0
- package/dist/ai/ai-employees/nathan/prompt.md +132 -0
- package/dist/ai/ai-employees/nathan/skills/frontend-developer/SKILLS.md +69 -0
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.js +2 -2
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.js +2 -2
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.js +2 -2
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.js +2 -2
- 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 +11 -10
- package/dist/node_modules/ses/dist/ses.cjs +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/action-scope.d.ts +38 -0
- package/dist/server/flow-surfaces/action-scope.js +152 -0
- package/dist/server/flow-surfaces/apply/compiler.d.ts +13 -0
- package/dist/server/flow-surfaces/apply/compiler.js +969 -0
- package/dist/server/flow-surfaces/apply/layout.d.ts +34 -0
- package/dist/server/flow-surfaces/apply/layout.js +175 -0
- package/dist/server/flow-surfaces/apply/matching.d.ts +16 -0
- package/dist/server/flow-surfaces/apply/matching.js +181 -0
- package/dist/server/flow-surfaces/approval/blueprint-service.d.ts +84 -0
- package/dist/server/flow-surfaces/approval/blueprint-service.js +589 -0
- package/dist/server/flow-surfaces/approval/blueprint.d.ts +21 -0
- package/dist/server/flow-surfaces/approval/blueprint.js +187 -0
- package/dist/server/flow-surfaces/approval/builder.d.ts +225 -0
- package/dist/server/flow-surfaces/approval/builder.js +384 -0
- package/dist/server/flow-surfaces/approval/catalog-specs.d.ts +33 -0
- package/dist/server/flow-surfaces/approval/catalog-specs.js +156 -0
- package/dist/server/flow-surfaces/approval/index.d.ts +14 -0
- package/dist/server/flow-surfaces/approval/index.js +40 -0
- package/dist/server/flow-surfaces/approval/runtime-config.d.ts +44 -0
- package/dist/server/flow-surfaces/approval/runtime-config.js +299 -0
- package/dist/server/flow-surfaces/approval/semantic-use.d.ts +23 -0
- package/dist/server/flow-surfaces/approval/semantic-use.js +155 -0
- package/dist/server/flow-surfaces/association-title-field.d.ts +20 -0
- package/dist/server/flow-surfaces/association-title-field.js +158 -0
- package/dist/server/flow-surfaces/blueprint/compile-blocks.d.ts +14 -0
- package/dist/server/flow-surfaces/blueprint/compile-blocks.js +1007 -0
- package/dist/server/flow-surfaces/blueprint/compile-plan.d.ts +13 -0
- package/dist/server/flow-surfaces/blueprint/compile-plan.js +308 -0
- package/dist/server/flow-surfaces/blueprint/compile-reaction.d.ts +11 -0
- package/dist/server/flow-surfaces/blueprint/compile-reaction.js +72 -0
- package/dist/server/flow-surfaces/blueprint/defaults.d.ts +26 -0
- package/dist/server/flow-surfaces/blueprint/defaults.js +133 -0
- package/dist/server/flow-surfaces/blueprint/index.d.ts +12 -0
- package/dist/server/flow-surfaces/blueprint/index.js +44 -0
- package/dist/server/flow-surfaces/blueprint/normalize-document.d.ts +10 -0
- package/dist/server/flow-surfaces/blueprint/normalize-document.js +416 -0
- package/dist/server/flow-surfaces/blueprint/private-utils.d.ts +26 -0
- package/dist/server/flow-surfaces/blueprint/private-utils.js +182 -0
- package/dist/server/flow-surfaces/blueprint/public-types.d.ts +193 -0
- package/dist/server/flow-surfaces/blueprint/public-types.js +24 -0
- package/dist/server/flow-surfaces/builder.d.ts +211 -0
- package/dist/server/flow-surfaces/builder.js +1029 -0
- package/dist/server/flow-surfaces/catalog-smart.d.ts +18 -0
- package/dist/server/flow-surfaces/catalog-smart.js +239 -0
- package/dist/server/flow-surfaces/catalog-smart.projector.d.ts +15 -0
- package/dist/server/flow-surfaces/catalog-smart.projector.js +157 -0
- package/dist/server/flow-surfaces/catalog-smart.types.d.ts +99 -0
- package/dist/server/flow-surfaces/catalog-smart.types.js +24 -0
- package/dist/server/flow-surfaces/catalog.d.ts +78 -0
- package/dist/server/flow-surfaces/catalog.js +3496 -0
- package/dist/server/flow-surfaces/chart-config.d.ts +121 -0
- package/dist/server/flow-surfaces/chart-config.js +1394 -0
- package/dist/server/flow-surfaces/compose-compiler.d.ts +108 -0
- package/dist/server/flow-surfaces/compose-compiler.js +167 -0
- package/dist/server/flow-surfaces/compose-runtime.d.ts +93 -0
- package/dist/server/flow-surfaces/compose-runtime.js +375 -0
- package/dist/server/flow-surfaces/configure-options.d.ts +23 -0
- package/dist/server/flow-surfaces/configure-options.js +827 -0
- package/dist/server/flow-surfaces/constants.d.ts +351 -0
- package/dist/server/flow-surfaces/constants.js +104 -0
- package/dist/server/flow-surfaces/context.d.ts +72 -0
- package/dist/server/flow-surfaces/context.js +556 -0
- package/dist/server/flow-surfaces/contract-guard.d.ts +19 -0
- package/dist/server/flow-surfaces/contract-guard.js +402 -0
- package/dist/server/flow-surfaces/default-action-popup.d.ts +63 -0
- package/dist/server/flow-surfaces/default-action-popup.js +322 -0
- package/dist/server/flow-surfaces/default-block-actions.d.ts +32 -0
- package/dist/server/flow-surfaces/default-block-actions.js +185 -0
- package/dist/server/flow-surfaces/errors.d.ts +47 -0
- package/dist/server/flow-surfaces/errors.js +145 -0
- package/dist/server/flow-surfaces/executor.d.ts +23 -0
- package/dist/server/flow-surfaces/executor.js +132 -0
- package/dist/server/flow-surfaces/field-binding-registry.d.ts +23 -0
- package/dist/server/flow-surfaces/field-binding-registry.js +391 -0
- package/dist/server/flow-surfaces/field-semantics.d.ts +15 -0
- package/dist/server/flow-surfaces/field-semantics.js +81 -0
- package/dist/server/flow-surfaces/filter-group.d.ts +15 -0
- package/dist/server/flow-surfaces/filter-group.js +94 -0
- package/dist/server/flow-surfaces/index.d.ts +11 -0
- package/dist/server/flow-surfaces/index.js +243 -0
- package/dist/server/flow-surfaces/locator.d.ts +28 -0
- package/dist/server/flow-surfaces/locator.js +240 -0
- package/dist/server/flow-surfaces/node-use-sets.d.ts +15 -0
- package/dist/server/flow-surfaces/node-use-sets.js +131 -0
- package/dist/server/flow-surfaces/payload-shape.d.ts +9 -0
- package/dist/server/flow-surfaces/payload-shape.js +61 -0
- package/dist/server/flow-surfaces/placement.d.ts +33 -0
- package/dist/server/flow-surfaces/placement.js +195 -0
- package/dist/server/flow-surfaces/planning/action-specs.d.ts +179 -0
- package/dist/server/flow-surfaces/planning/action-specs.js +190 -0
- package/dist/server/flow-surfaces/planning/compiler.d.ts +37 -0
- package/dist/server/flow-surfaces/planning/compiler.js +376 -0
- package/dist/server/flow-surfaces/planning/context.d.ts +30 -0
- package/dist/server/flow-surfaces/planning/context.js +139 -0
- package/dist/server/flow-surfaces/planning/created-keys.d.ts +34 -0
- package/dist/server/flow-surfaces/planning/created-keys.js +375 -0
- package/dist/server/flow-surfaces/planning/key-kind.d.ts +11 -0
- package/dist/server/flow-surfaces/planning/key-kind.js +88 -0
- package/dist/server/flow-surfaces/planning/key-persistence.d.ts +34 -0
- package/dist/server/flow-surfaces/planning/key-persistence.js +148 -0
- package/dist/server/flow-surfaces/planning/key-registry.d.ts +40 -0
- package/dist/server/flow-surfaces/planning/key-registry.js +206 -0
- package/dist/server/flow-surfaces/planning/runtime.d.ts +37 -0
- package/dist/server/flow-surfaces/planning/runtime.js +259 -0
- package/dist/server/flow-surfaces/planning/step-link.d.ts +14 -0
- package/dist/server/flow-surfaces/planning/step-link.js +104 -0
- package/dist/server/flow-surfaces/planning/types.d.ts +55 -0
- package/dist/server/flow-surfaces/planning/types.js +24 -0
- package/dist/server/flow-surfaces/public-data-surface-default-filter.d.ts +20 -0
- package/dist/server/flow-surfaces/public-data-surface-default-filter.js +111 -0
- package/dist/server/flow-surfaces/reaction/errors.d.ts +20 -0
- package/dist/server/flow-surfaces/reaction/errors.js +69 -0
- package/dist/server/flow-surfaces/reaction/field-value.d.ts +34 -0
- package/dist/server/flow-surfaces/reaction/field-value.js +181 -0
- package/dist/server/flow-surfaces/reaction/fingerprint.d.ts +16 -0
- package/dist/server/flow-surfaces/reaction/fingerprint.js +71 -0
- package/dist/server/flow-surfaces/reaction/linkage.d.ts +136 -0
- package/dist/server/flow-surfaces/reaction/linkage.js +882 -0
- package/dist/server/flow-surfaces/reaction/meta.d.ts +11 -0
- package/dist/server/flow-surfaces/reaction/meta.js +451 -0
- package/dist/server/flow-surfaces/reaction/registry.d.ts +156 -0
- package/dist/server/flow-surfaces/reaction/registry.js +206 -0
- package/dist/server/flow-surfaces/reaction/resolver.d.ts +22 -0
- package/dist/server/flow-surfaces/reaction/resolver.js +202 -0
- package/dist/server/flow-surfaces/reaction/types.d.ts +241 -0
- package/dist/server/flow-surfaces/reaction/types.js +24 -0
- package/dist/server/flow-surfaces/reaction/utils.d.ts +17 -0
- package/dist/server/flow-surfaces/reaction/utils.js +67 -0
- package/dist/server/flow-surfaces/reaction/value-expr.d.ts +15 -0
- package/dist/server/flow-surfaces/reaction/value-expr.js +209 -0
- package/dist/server/flow-surfaces/reference-guards.d.ts +19 -0
- package/dist/server/flow-surfaces/reference-guards.js +103 -0
- package/dist/server/flow-surfaces/route-sync.d.ts +47 -0
- package/dist/server/flow-surfaces/route-sync.js +392 -0
- package/dist/server/flow-surfaces/service-helpers.d.ts +42 -0
- package/dist/server/flow-surfaces/service-helpers.js +377 -0
- package/dist/server/flow-surfaces/service-utils.d.ts +108 -0
- package/dist/server/flow-surfaces/service-utils.js +811 -0
- package/dist/server/flow-surfaces/service.d.ts +773 -0
- package/dist/server/flow-surfaces/service.js +13008 -0
- package/dist/server/flow-surfaces/support-matrix.d.ts +31 -0
- package/dist/server/flow-surfaces/support-matrix.js +259 -0
- package/dist/server/flow-surfaces/surface-context.d.ts +52 -0
- package/dist/server/flow-surfaces/surface-context.js +437 -0
- package/dist/server/flow-surfaces/template-compatibility.d.ts +42 -0
- package/dist/server/flow-surfaces/template-compatibility.js +189 -0
- package/dist/server/flow-surfaces/template-display.d.ts +20 -0
- package/dist/server/flow-surfaces/template-display.js +289 -0
- package/dist/server/flow-surfaces/template-service-utils.d.ts +62 -0
- package/dist/server/flow-surfaces/template-service-utils.js +281 -0
- package/dist/server/flow-surfaces/types.d.ts +288 -0
- package/dist/server/flow-surfaces/types.js +24 -0
- package/dist/server/plugin.js +2 -0
- package/dist/swagger/flow-surfaces.d.ts +5964 -0
- package/dist/swagger/flow-surfaces.examples.d.ts +1533 -0
- package/dist/swagger/flow-surfaces.examples.js +1758 -0
- package/dist/swagger/flow-surfaces.js +5315 -0
- package/dist/swagger/flow-surfaces.template-action-docs.d.ts +62 -0
- package/dist/swagger/flow-surfaces.template-action-docs.js +121 -0
- package/dist/swagger/flow-surfaces.template-schemas.d.ts +239 -0
- package/dist/swagger/flow-surfaces.template-schemas.js +255 -0
- package/dist/swagger/index.d.ts +5969 -0
- package/dist/swagger/index.js +50 -0
- package/package.json +2 -2
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.d.ts +0 -0
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.d.ts +0 -0
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.d.ts +0 -0
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.d.ts +0 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.collection
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Collection instance associated with the current RunJS execution context, used to access collection metadata, field definitions, primary keys, and other configurations. It usually originates from `ctx.blockModel.collection` or `ctx.collectionField?.collection`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **JSField / JSItem / JSColumn** |
|
|
11
|
-
| **Table
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock** | The collection bound to the block; can access `name`, `getFields`, `filterTargetKey`, etc. |
|
|
10
|
+
| **JSField / JSItem / JSColumn** | The collection the current field belongs to (or the parent block's collection), used to retrieve field lists, primary keys, etc. |
|
|
11
|
+
| **Table Column / Detail Block** | Used for rendering based on collection structure or passing `filterByTk` when opening popups. |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.collection` is available
|
|
13
|
+
> Note: `ctx.collection` is available in scenarios where a data block, form block, or table block is bound to a collection. In an independent JSBlock that is not bound to a collection, it may be `null`. It is recommended to perform a null check before use.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
collection: Collection | null | undefined;
|
|
@@ -21,39 +21,39 @@ collection: Collection | null | undefined;
|
|
|
21
21
|
## Common Properties
|
|
22
22
|
|
|
23
23
|
| Property | Type | Description |
|
|
24
|
-
|
|
25
|
-
| `name` | `string` | Collection name (e.g
|
|
26
|
-
| `title` | `string` | Collection title (
|
|
27
|
-
| `filterTargetKey` | `string \| string[]` | Primary key field name
|
|
28
|
-
| `dataSourceKey` | `string` | Data source key (e.g
|
|
29
|
-
| `dataSource` | `DataSource` |
|
|
30
|
-
| `template` | `string` | Collection template (e.g
|
|
31
|
-
| `titleableFields` | `CollectionField[]` |
|
|
32
|
-
| `titleCollectionField` | `CollectionField` |
|
|
24
|
+
|------|------|------|
|
|
25
|
+
| `name` | `string` | Collection name (e.g., `users`, `orders`) |
|
|
26
|
+
| `title` | `string` | Collection title (includes internationalization) |
|
|
27
|
+
| `filterTargetKey` | `string \| string[]` | Primary key field name, used for `filterByTk` and `getFilterByTK` |
|
|
28
|
+
| `dataSourceKey` | `string` | Data source key (e.g., `main`) |
|
|
29
|
+
| `dataSource` | `DataSource` | The data source instance it belongs to |
|
|
30
|
+
| `template` | `string` | Collection template (e.g., `general`, `file`, `tree`) |
|
|
31
|
+
| `titleableFields` | `CollectionField[]` | List of fields that can be displayed as titles |
|
|
32
|
+
| `titleCollectionField` | `CollectionField` | The title field instance |
|
|
33
33
|
|
|
34
34
|
## Common Methods
|
|
35
35
|
|
|
36
36
|
| Method | Description |
|
|
37
|
-
|
|
38
|
-
| `getFields(): CollectionField[]` |
|
|
39
|
-
| `getField(name: string): CollectionField \| undefined` |
|
|
40
|
-
| `getFieldByPath(path: string): CollectionField \| undefined` |
|
|
41
|
-
| `getAssociationFields(types?): CollectionField[]` |
|
|
42
|
-
| `getFilterByTK(record): any` |
|
|
37
|
+
|------|------|
|
|
38
|
+
| `getFields(): CollectionField[]` | Get all fields (including inherited ones) |
|
|
39
|
+
| `getField(name: string): CollectionField \| undefined` | Get a single field by field name |
|
|
40
|
+
| `getFieldByPath(path: string): CollectionField \| undefined` | Get a field by path (supports associations, e.g., `user.name`) |
|
|
41
|
+
| `getAssociationFields(types?): CollectionField[]` | Get association fields; `types` can be `['one']`, `['many']`, etc. |
|
|
42
|
+
| `getFilterByTK(record): any` | Extract the primary key value from a record, used for the API's `filterByTk` |
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## Relationship with ctx.collectionField and ctx.blockModel
|
|
45
45
|
|
|
46
|
-
|
|
|
47
|
-
|
|
48
|
-
| **Collection
|
|
49
|
-
| **Collection of current field** | `ctx.collectionField?.collection` |
|
|
50
|
-
| **
|
|
46
|
+
| Requirement | Recommended Usage |
|
|
47
|
+
|------|----------|
|
|
48
|
+
| **Collection associated with current context** | `ctx.collection` (equivalent to `ctx.blockModel?.collection` or `ctx.collectionField?.collection`) |
|
|
49
|
+
| **Collection definition of the current field** | `ctx.collectionField?.collection` (the collection the field belongs to) |
|
|
50
|
+
| **Association target collection** | `ctx.collectionField?.targetCollection` (the target collection of an association field) |
|
|
51
51
|
|
|
52
|
-
In sub-tables
|
|
52
|
+
In scenarios like sub-tables, `ctx.collection` might be the association target collection; in standard forms/tables, it is usually the collection bound to the block.
|
|
53
53
|
|
|
54
54
|
## Examples
|
|
55
55
|
|
|
56
|
-
### Get
|
|
56
|
+
### Get Primary Key and Open Popup
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
const primaryKey = ctx.collection?.filterTargetKey ?? 'id';
|
|
@@ -66,7 +66,7 @@ await ctx.openView(popupUid, {
|
|
|
66
66
|
});
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
### Iterate
|
|
69
|
+
### Iterate Through Fields for Validation or Linkage
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
const fields = ctx.collection?.getFields() ?? [];
|
|
@@ -80,21 +80,21 @@ for (const f of requiredFields) {
|
|
|
80
80
|
}
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
### Get
|
|
83
|
+
### Get Association Fields
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
86
|
const oneToMany = ctx.collection?.getAssociationFields(['many']) ?? [];
|
|
87
|
-
//
|
|
87
|
+
// Used for building sub-tables, associated resources, etc.
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
## Notes
|
|
91
91
|
|
|
92
|
-
- `filterTargetKey` is the
|
|
93
|
-
- In **sub-tables
|
|
94
|
-
- `getFields()` merges inherited
|
|
92
|
+
- `filterTargetKey` is the primary key field name of the collection. Some collections may use a `string[]` for composite primary keys. If not configured, `'id'` is commonly used as a fallback.
|
|
93
|
+
- In scenarios like **sub-tables or association fields**, `ctx.collection` may point to the association target collection, which differs from `ctx.blockModel.collection`.
|
|
94
|
+
- `getFields()` merges fields from inherited collections; local fields override inherited fields with the same name.
|
|
95
95
|
|
|
96
96
|
## Related
|
|
97
97
|
|
|
98
|
-
- [ctx.collectionField](./collection-field.md):
|
|
99
|
-
- [ctx.blockModel](./block-model.md): parent block
|
|
100
|
-
- [ctx.model](./model.md): current model
|
|
98
|
+
- [ctx.collectionField](./collection-field.md): The collection field definition of the current field
|
|
99
|
+
- [ctx.blockModel](./block-model.md): The parent block hosting the current JS, containing `collection`
|
|
100
|
+
- [ctx.model](./model.md): The current model, which may contain `collection`
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.dataSourceManager
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The Data Source Manager (`DataSourceManager` instance) is used to manage and access multiple data sources (e.g., the main database `main`, logging database `logging`, etc.). It is used when multiple data sources exist or when cross-data source metadata access is required.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **
|
|
10
|
-
| **Cross
|
|
11
|
-
| **
|
|
8
|
+
|------|------|
|
|
9
|
+
| **Multi-data source** | Enumerate all data sources, or get a specific data source by key. |
|
|
10
|
+
| **Cross-data source access** | Access metadata using the "data source key + collection name" format when the data source of the current context is unknown. |
|
|
11
|
+
| **Get fields by full path** | Use the `dataSourceKey.collectionName.fieldPath` format to retrieve field definitions across different data sources. |
|
|
12
12
|
|
|
13
|
-
> Note: If you only
|
|
13
|
+
> Note: If you are only operating on the current data source, prioritize using `ctx.dataSource`. Use `ctx.dataSourceManager` only when you need to enumerate or switch between data sources.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
dataSourceManager: DataSourceManager;
|
|
@@ -20,64 +20,74 @@ dataSourceManager: DataSourceManager;
|
|
|
20
20
|
class DataSourceManager {
|
|
21
21
|
constructor();
|
|
22
22
|
|
|
23
|
+
// Data source management
|
|
23
24
|
addDataSource(ds: DataSource | DataSourceOptions): void;
|
|
24
25
|
upsertDataSource(ds: DataSource | DataSourceOptions): void;
|
|
25
26
|
removeDataSource(key: string): void;
|
|
26
27
|
clearDataSources(): void;
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// Read data sources
|
|
30
|
+
getDataSources(): DataSource[]; // Get all data sources
|
|
31
|
+
getDataSource(key: string): DataSource | undefined; // Get data source by key
|
|
30
32
|
|
|
33
|
+
// Access metadata directly by data source + collection
|
|
31
34
|
getCollection(dataSourceKey: string, collectionName: string): Collection | undefined;
|
|
32
35
|
getCollectionField(fieldPathWithDataSource: string): CollectionField | undefined;
|
|
33
36
|
}
|
|
34
37
|
```
|
|
35
38
|
|
|
36
|
-
##
|
|
39
|
+
## Relationship with ctx.dataSource
|
|
37
40
|
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
| **Single data source
|
|
41
|
-
| **Entry
|
|
41
|
+
| Requirement | Recommended Usage |
|
|
42
|
+
|------|----------|
|
|
43
|
+
| **Single data source bound to the current context** | `ctx.dataSource` (e.g., the data source of the current page/block) |
|
|
44
|
+
| **Entry point for all data sources** | `ctx.dataSourceManager` |
|
|
42
45
|
| **List or switch data sources** | `ctx.dataSourceManager.getDataSources()` / `getDataSource(key)` |
|
|
43
|
-
| **
|
|
44
|
-
| **
|
|
45
|
-
| **
|
|
46
|
-
| **
|
|
46
|
+
| **Get collection within the current data source** | `ctx.dataSource.getCollection(name)` |
|
|
47
|
+
| **Get collection across data sources** | `ctx.dataSourceManager.getCollection(dataSourceKey, collectionName)` |
|
|
48
|
+
| **Get field within the current data source** | `ctx.dataSource.getCollectionField('users.profile.avatar')` |
|
|
49
|
+
| **Get field across data sources** | `ctx.dataSourceManager.getCollectionField('main.users.profile.avatar')` |
|
|
47
50
|
|
|
48
51
|
## Examples
|
|
49
52
|
|
|
50
|
-
### Get a
|
|
53
|
+
### Get a Specific Data Source
|
|
51
54
|
|
|
52
55
|
```ts
|
|
56
|
+
// Get the data source named 'main'
|
|
53
57
|
const mainDS = ctx.dataSourceManager.getDataSource('main');
|
|
58
|
+
|
|
59
|
+
// Get all collections under this data source
|
|
54
60
|
const collections = mainDS?.getCollections();
|
|
55
61
|
```
|
|
56
62
|
|
|
57
|
-
###
|
|
63
|
+
### Access Collection Metadata Across Data Sources
|
|
58
64
|
|
|
59
65
|
```ts
|
|
66
|
+
// Get collection by dataSourceKey + collectionName
|
|
60
67
|
const users = ctx.dataSourceManager.getCollection('main', 'users');
|
|
61
68
|
const orders = ctx.dataSourceManager.getCollection('main', 'orders');
|
|
62
69
|
|
|
70
|
+
// Get the primary key of the collection
|
|
63
71
|
const primaryKey = users?.filterTargetKey ?? 'id';
|
|
64
72
|
```
|
|
65
73
|
|
|
66
|
-
### Field by
|
|
74
|
+
### Get Field Definition by Full Path
|
|
67
75
|
|
|
68
76
|
```ts
|
|
69
77
|
// Format: dataSourceKey.collectionName.fieldPath
|
|
78
|
+
// Get field definition by "data source key.collection name.field path"
|
|
70
79
|
const field = ctx.dataSourceManager.getCollectionField('main.users.profile.avatar');
|
|
71
80
|
|
|
81
|
+
// Supports association field paths
|
|
72
82
|
const userNameField = ctx.dataSourceManager.getCollectionField('main.orders.createdBy.name');
|
|
73
83
|
```
|
|
74
84
|
|
|
75
|
-
### Iterate
|
|
85
|
+
### Iterate Through All Data Sources
|
|
76
86
|
|
|
77
87
|
```ts
|
|
78
88
|
const dataSources = ctx.dataSourceManager.getDataSources();
|
|
79
89
|
for (const ds of dataSources) {
|
|
80
|
-
ctx.logger.info(`Data
|
|
90
|
+
ctx.logger.info(`Data Source: ${ds.key}, Display Name: ${ds.displayName}`);
|
|
81
91
|
const collections = ds.getCollections();
|
|
82
92
|
for (const col of collections) {
|
|
83
93
|
ctx.logger.info(` - Collection: ${col.name}`);
|
|
@@ -85,7 +95,7 @@ for (const ds of dataSources) {
|
|
|
85
95
|
}
|
|
86
96
|
```
|
|
87
97
|
|
|
88
|
-
###
|
|
98
|
+
### Dynamically Select Data Source Based on Variables
|
|
89
99
|
|
|
90
100
|
```ts
|
|
91
101
|
const dsKey = ctx.getVar('dataSourceKey') ?? 'main';
|
|
@@ -99,12 +109,12 @@ if (col) {
|
|
|
99
109
|
|
|
100
110
|
## Notes
|
|
101
111
|
|
|
102
|
-
-
|
|
103
|
-
- `getDataSource(key)` returns `undefined` if the data source
|
|
104
|
-
- `addDataSource`
|
|
112
|
+
- The path format for `getCollectionField` is `dataSourceKey.collectionName.fieldPath`, where the first segment is the data source key, followed by the collection name and the field path.
|
|
113
|
+
- `getDataSource(key)` returns `undefined` if the data source does not exist; it is recommended to perform a null check before use.
|
|
114
|
+
- `addDataSource` will throw an exception if the key already exists; `upsertDataSource` will either overwrite the existing one or add a new one.
|
|
105
115
|
|
|
106
116
|
## Related
|
|
107
117
|
|
|
108
|
-
- [ctx.dataSource](./data-source.md):
|
|
109
|
-
- [ctx.collection](./collection.md):
|
|
110
|
-
- [ctx.collectionField](./collection-field.md):
|
|
118
|
+
- [ctx.dataSource](./data-source.md): Current data source instance
|
|
119
|
+
- [ctx.collection](./collection.md): Collection associated with the current context
|
|
120
|
+
- [ctx.collectionField](./collection-field.md): Collection field definition for the current field
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.dataSource
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The `DataSource` instance bound to the current RunJS execution context, used to access collections, field metadata, and manage collection configurations **within the current data source**. It usually corresponds to the data source selected for the current page or block (e.g., the main database `main`).
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **Single
|
|
10
|
-
| **Collection
|
|
11
|
-
| **
|
|
8
|
+
|------|------|
|
|
9
|
+
| **Single Data Source Operations** | Get collection and field metadata when the current data source is known. |
|
|
10
|
+
| **Collection Management** | Get, add, update, or delete collections under the current data source. |
|
|
11
|
+
| **Get Fields by Path** | Use the `collectionName.fieldPath` format to get field definitions (supports association paths). |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.dataSource`
|
|
13
|
+
> Note: `ctx.dataSource` represents a single data source for the current context. To enumerate or access other data sources, please use [ctx.dataSourceManager](./data-source-manager.md).
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
dataSource: DataSource;
|
|
@@ -20,15 +20,18 @@ dataSource: DataSource;
|
|
|
20
20
|
class DataSource {
|
|
21
21
|
constructor(options?: Record<string, any>);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
get
|
|
25
|
-
get
|
|
26
|
-
get
|
|
23
|
+
// Read-only properties
|
|
24
|
+
get flowEngine(): FlowEngine; // Current FlowEngine instance
|
|
25
|
+
get displayName(): string; // Display name (supports i18n)
|
|
26
|
+
get key(): string; // Data source key, e.g., 'main'
|
|
27
|
+
get name(): string; // Same as key
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Collection reading
|
|
30
|
+
getCollections(): Collection[]; // Get all collections
|
|
31
|
+
getCollection(name: string): Collection | undefined; // Get collection by name
|
|
32
|
+
getAssociation(associationName: string): CollectionField | undefined; // Get association field (e.g., users.roles)
|
|
31
33
|
|
|
34
|
+
// Collection management
|
|
32
35
|
addCollection(collection: Collection | CollectionOptions): void;
|
|
33
36
|
updateCollection(newOptions: CollectionOptions): void;
|
|
34
37
|
upsertCollection(options: CollectionOptions): Collection | undefined;
|
|
@@ -36,6 +39,7 @@ class DataSource {
|
|
|
36
39
|
removeCollection(name: string): void;
|
|
37
40
|
clearCollections(): void;
|
|
38
41
|
|
|
42
|
+
// Field metadata
|
|
39
43
|
getCollectionField(fieldPath: string): CollectionField | undefined;
|
|
40
44
|
}
|
|
41
45
|
```
|
|
@@ -43,57 +47,61 @@ class DataSource {
|
|
|
43
47
|
## Common Properties
|
|
44
48
|
|
|
45
49
|
| Property | Type | Description |
|
|
46
|
-
|
|
47
|
-
| `key` | `string` | Data source key
|
|
50
|
+
|------|------|------|
|
|
51
|
+
| `key` | `string` | Data source key, e.g., `'main'` |
|
|
48
52
|
| `name` | `string` | Same as key |
|
|
49
|
-
| `displayName` | `string` | Display name (i18n) |
|
|
53
|
+
| `displayName` | `string` | Display name (supports i18n) |
|
|
50
54
|
| `flowEngine` | `FlowEngine` | Current FlowEngine instance |
|
|
51
55
|
|
|
52
56
|
## Common Methods
|
|
53
57
|
|
|
54
58
|
| Method | Description |
|
|
55
|
-
|
|
56
|
-
| `getCollections()` |
|
|
57
|
-
| `getCollection(name)` |
|
|
58
|
-
| `getAssociation(associationName)` |
|
|
59
|
-
| `getCollectionField(fieldPath)` |
|
|
59
|
+
|------|------|
|
|
60
|
+
| `getCollections()` | Gets all collections under the current data source (sorted, with hidden ones filtered). |
|
|
61
|
+
| `getCollection(name)` | Gets a collection by name; `name` can be `collectionName.fieldName` to get the target collection of an association. |
|
|
62
|
+
| `getAssociation(associationName)` | Gets an association field definition by `collectionName.fieldName`. |
|
|
63
|
+
| `getCollectionField(fieldPath)` | Gets a field definition by `collectionName.fieldPath`, supporting association paths like `users.profile.avatar`. |
|
|
60
64
|
|
|
61
|
-
##
|
|
65
|
+
## Relationship with ctx.dataSourceManager
|
|
62
66
|
|
|
63
|
-
|
|
|
64
|
-
|
|
65
|
-
| **Single data source
|
|
66
|
-
| **Entry
|
|
67
|
-
| **
|
|
68
|
-
| **
|
|
69
|
-
| **
|
|
70
|
-
| **
|
|
67
|
+
| Requirement | Recommended Usage |
|
|
68
|
+
|------|----------|
|
|
69
|
+
| **Single data source bound to current context** | `ctx.dataSource` |
|
|
70
|
+
| **Entry point for all data sources** | `ctx.dataSourceManager` |
|
|
71
|
+
| **Get collection within current data source** | `ctx.dataSource.getCollection(name)` |
|
|
72
|
+
| **Get collection across data sources** | `ctx.dataSourceManager.getCollection(dataSourceKey, collectionName)` |
|
|
73
|
+
| **Get field within current data source** | `ctx.dataSource.getCollectionField('users.profile.avatar')` |
|
|
74
|
+
| **Get field across data sources** | `ctx.dataSourceManager.getCollectionField('main.users.profile.avatar')` |
|
|
71
75
|
|
|
72
|
-
##
|
|
76
|
+
## Example
|
|
73
77
|
|
|
74
|
-
### Get
|
|
78
|
+
### Get Collections and Fields
|
|
75
79
|
|
|
76
80
|
```ts
|
|
81
|
+
// Get all collections
|
|
77
82
|
const collections = ctx.dataSource.getCollections();
|
|
78
83
|
|
|
84
|
+
// Get collection by name
|
|
79
85
|
const users = ctx.dataSource.getCollection('users');
|
|
80
86
|
const primaryKey = users?.filterTargetKey ?? 'id';
|
|
81
87
|
|
|
88
|
+
// Get field definition by "collectionName.fieldPath" (supports associations)
|
|
82
89
|
const field = ctx.dataSource.getCollectionField('users.profile.avatar');
|
|
83
90
|
const userNameField = ctx.dataSource.getCollectionField('orders.createdBy.name');
|
|
84
91
|
```
|
|
85
92
|
|
|
86
|
-
### Get
|
|
93
|
+
### Get Association Fields
|
|
87
94
|
|
|
88
95
|
```ts
|
|
96
|
+
// Get association field definition by collectionName.fieldName
|
|
89
97
|
const rolesField = ctx.dataSource.getAssociation('users.roles');
|
|
90
98
|
if (rolesField?.isAssociationField()) {
|
|
91
99
|
const targetCol = rolesField.targetCollection;
|
|
92
|
-
//
|
|
100
|
+
// Process based on target collection structure
|
|
93
101
|
}
|
|
94
102
|
```
|
|
95
103
|
|
|
96
|
-
### Iterate
|
|
104
|
+
### Iterate Through Collections for Dynamic Processing
|
|
97
105
|
|
|
98
106
|
```ts
|
|
99
107
|
const collections = ctx.dataSource.getCollections();
|
|
@@ -104,25 +112,25 @@ for (const col of collections) {
|
|
|
104
112
|
}
|
|
105
113
|
```
|
|
106
114
|
|
|
107
|
-
### Validation or
|
|
115
|
+
### Perform Validation or Dynamic UI Based on Field Metadata
|
|
108
116
|
|
|
109
117
|
```ts
|
|
110
118
|
const field = ctx.dataSource.getCollectionField('users.status');
|
|
111
119
|
if (field) {
|
|
112
120
|
const options = field.enum ?? [];
|
|
113
121
|
const operators = field.getFilterOperators();
|
|
114
|
-
//
|
|
122
|
+
// Perform UI logic or validation based on interface, enum, validation, etc.
|
|
115
123
|
}
|
|
116
124
|
```
|
|
117
125
|
|
|
118
126
|
## Notes
|
|
119
127
|
|
|
120
|
-
- `getCollectionField(fieldPath)`
|
|
121
|
-
- `getCollection(name)` supports `collectionName.fieldName`
|
|
122
|
-
- In RunJS, `ctx.dataSource` is usually determined by the current block
|
|
128
|
+
- The path format for `getCollectionField(fieldPath)` is `collectionName.fieldPath`, where the first segment is the collection name and the subsequent segments are the field path (supports associations, e.g., `user.name`).
|
|
129
|
+
- `getCollection(name)` supports the `collectionName.fieldName` format, returning the target collection of the association field.
|
|
130
|
+
- In the RunJS context, `ctx.dataSource` is usually determined by the data source of the current block or page. If no data source is bound to the context, it may be `undefined`; it is recommended to perform a null check before use.
|
|
123
131
|
|
|
124
132
|
## Related
|
|
125
133
|
|
|
126
|
-
- [ctx.dataSourceManager](./data-source-manager.md): manager
|
|
127
|
-
- [ctx.collection](./collection.md): collection
|
|
128
|
-
- [ctx.collectionField](./collection-field.md):
|
|
134
|
+
- [ctx.dataSourceManager](./data-source-manager.md): Data source manager, manages all data sources.
|
|
135
|
+
- [ctx.collection](./collection.md): The collection associated with the current context.
|
|
136
|
+
- [ctx.collectionField](./collection-field.md): The collection field definition for the current field.
|
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
# ctx.element
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An `ElementProxy` instance pointing to the sandbox DOM container, serving as the default rendering target for `ctx.render()`. It is available in scenarios where a rendering container exists, such as `JSBlock`, `JSField`, `JSItem`, and `JSColumn`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Applicable Scenarios
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **JSField / JSItem / FormJSFieldItem** |
|
|
11
|
-
| **JSColumn** |
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock** | The DOM container for the block, used to render custom block content. |
|
|
10
|
+
| **JSField / JSItem / FormJSFieldItem** | The rendering container for a field or form item (usually a `<span>`). |
|
|
11
|
+
| **JSColumn** | The DOM container for a table cell, used to render custom column content. |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.element` is only available in RunJS contexts that have a
|
|
13
|
+
> Note: `ctx.element` is only available in RunJS contexts that have a rendering container. In contexts without a UI (such as pure backend logic), it may be `undefined`. It is recommended to perform a null check before use.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
18
|
element: ElementProxy | undefined;
|
|
19
19
|
|
|
20
|
+
// ElementProxy is a proxy for the raw HTMLElement, exposing a secure API
|
|
20
21
|
class ElementProxy {
|
|
21
|
-
__el: HTMLElement; //
|
|
22
|
-
innerHTML: string; //
|
|
23
|
-
outerHTML: string;
|
|
22
|
+
__el: HTMLElement; // The internal raw DOM element (accessible only in specific scenarios)
|
|
23
|
+
innerHTML: string; // Sanitized via DOMPurify during read/write
|
|
24
|
+
outerHTML: string; // Same as above
|
|
24
25
|
appendChild(child: HTMLElement | string): void;
|
|
25
|
-
// Other HTMLElement methods passed through (not recommended)
|
|
26
|
+
// Other HTMLElement methods are passed through (direct use is not recommended)
|
|
26
27
|
}
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
## Security
|
|
30
|
+
## Security Requirements
|
|
30
31
|
|
|
31
|
-
**Recommended:
|
|
32
|
+
**Recommended: All rendering should be performed via `ctx.render()`.** Avoid using the DOM APIs of `ctx.element` directly (e.g., `innerHTML`, `appendChild`, `querySelector`, etc.).
|
|
32
33
|
|
|
33
|
-
### Why
|
|
34
|
+
### Why ctx.render() is Recommended
|
|
34
35
|
|
|
35
|
-
|
|
|
36
|
-
|
|
37
|
-
| **Security** | Centralized control
|
|
38
|
-
| **React** | Full JSX, components, and
|
|
39
|
-
| **Context** |
|
|
40
|
-
| **
|
|
36
|
+
| Advantage | Description |
|
|
37
|
+
|------|------|
|
|
38
|
+
| **Security** | Centralized security control to prevent XSS and improper DOM operations. |
|
|
39
|
+
| **React Support** | Full support for JSX, React components, and lifecycles. |
|
|
40
|
+
| **Context Inheritance** | Automatically inherits the application's `ConfigProvider`, themes, etc. |
|
|
41
|
+
| **Conflict Handling** | Automatically manages React root creation/unmounting to avoid multi-instance conflicts. |
|
|
41
42
|
|
|
42
|
-
### ❌ Not
|
|
43
|
+
### ❌ Not Recommended: Direct Manipulation of ctx.element
|
|
43
44
|
|
|
44
45
|
```ts
|
|
46
|
+
// ❌ Not recommended: Using ctx.element APIs directly
|
|
45
47
|
ctx.element.innerHTML = '<div>Content</div>';
|
|
46
48
|
ctx.element.appendChild(node);
|
|
47
49
|
ctx.element.querySelector('.class');
|
|
48
50
|
```
|
|
49
51
|
|
|
50
|
-
> `ctx.element.innerHTML` is deprecated
|
|
52
|
+
> `ctx.element.innerHTML` is deprecated. Please use `ctx.render()` instead.
|
|
51
53
|
|
|
52
|
-
### ✅ Recommended: ctx.render()
|
|
54
|
+
### ✅ Recommended: Using ctx.render()
|
|
53
55
|
|
|
54
56
|
```ts
|
|
57
|
+
// ✅ Rendering a React component
|
|
55
58
|
const { Button, Card } = ctx.libs.antd;
|
|
56
59
|
ctx.render(
|
|
57
60
|
<Card title={ctx.t('Welcome')}>
|
|
@@ -59,40 +62,43 @@ ctx.render(
|
|
|
59
62
|
</Card>
|
|
60
63
|
);
|
|
61
64
|
|
|
65
|
+
// ✅ Rendering an HTML string
|
|
62
66
|
ctx.render('<div style="padding:16px;">' + ctx.t('Content') + '</div>');
|
|
63
67
|
|
|
68
|
+
// ✅ Rendering a DOM node
|
|
64
69
|
const div = document.createElement('div');
|
|
65
70
|
div.textContent = ctx.t('Hello');
|
|
66
71
|
ctx.render(div);
|
|
67
72
|
```
|
|
68
73
|
|
|
69
|
-
##
|
|
74
|
+
## Special Case: As a Popover Anchor
|
|
70
75
|
|
|
71
|
-
When you need the current element as
|
|
76
|
+
When you need to open a Popover using the current element as an anchor, you can access `ctx.element?.__el` to get the raw DOM as the `target`:
|
|
72
77
|
|
|
73
78
|
```ts
|
|
79
|
+
// ctx.viewer.popover requires a raw DOM as the target
|
|
74
80
|
await ctx.viewer.popover({
|
|
75
81
|
target: ctx.element?.__el,
|
|
76
|
-
content: <div>
|
|
82
|
+
content: <div>Popup Content</div>,
|
|
77
83
|
});
|
|
78
84
|
```
|
|
79
85
|
|
|
80
|
-
> Use `__el` only
|
|
86
|
+
> Use `__el` only in scenarios like "using the current container as an anchor"; do not manipulate the DOM directly in other cases.
|
|
81
87
|
|
|
82
|
-
##
|
|
88
|
+
## Relationship with ctx.render
|
|
83
89
|
|
|
84
|
-
- `ctx.render(vnode)` without a `container` argument renders into `ctx.element
|
|
85
|
-
- If
|
|
86
|
-
- You can
|
|
90
|
+
- If `ctx.render(vnode)` is called without a `container` argument, it renders into the `ctx.element` container by default.
|
|
91
|
+
- If both `ctx.element` is missing and no `container` is provided, an error will be thrown.
|
|
92
|
+
- You can explicitly specify a container: `ctx.render(vnode, customContainer)`.
|
|
87
93
|
|
|
88
94
|
## Notes
|
|
89
95
|
|
|
90
|
-
-
|
|
91
|
-
- In contexts without a
|
|
92
|
-
-
|
|
96
|
+
- `ctx.element` is intended for internal use by `ctx.render()`. Directly accessing or modifying its properties/methods is not recommended.
|
|
97
|
+
- In contexts without a rendering container, `ctx.element` will be `undefined`. Ensure the container is available or pass a `container` manually before calling `ctx.render()`.
|
|
98
|
+
- Although `innerHTML`/`outerHTML` in `ElementProxy` are sanitized via DOMPurify, it is still recommended to use `ctx.render()` for unified rendering management.
|
|
93
99
|
|
|
94
100
|
## Related
|
|
95
101
|
|
|
96
|
-
- [ctx.render](./render.md):
|
|
97
|
-
- [ctx.view](./view.md):
|
|
98
|
-
- [ctx.modal](./modal.md):
|
|
102
|
+
- [ctx.render](./render.md): Rendering content into a container
|
|
103
|
+
- [ctx.view](./view.md): Current view controller
|
|
104
|
+
- [ctx.modal](./modal.md): Shortcut API for modals
|