@decaf-ts/ui-decorators 0.9.0 → 0.11.0
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/lib/cjs/index.cjs +9 -8
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/model/Renderable.cjs +1 -0
- package/lib/cjs/model/{Renderable.js.map → Renderable.cjs.map} +1 -1
- package/lib/cjs/model/decorators.cjs +9 -8
- package/lib/cjs/model/decorators.cjs.map +1 -0
- package/lib/cjs/model/index.cjs +1 -0
- package/lib/cjs/model/index.cjs.map +1 -0
- package/lib/cjs/model/model.cjs +1 -0
- package/lib/cjs/model/model.cjs.map +1 -0
- package/lib/cjs/model/overrides.cjs +19 -18
- package/lib/cjs/model/overrides.cjs.map +1 -0
- package/lib/cjs/overrides/ModelBuilderExtensions.cjs +8 -7
- package/lib/cjs/overrides/ModelBuilderExtensions.cjs.map +1 -0
- package/lib/cjs/overrides/index.cjs +1 -0
- package/lib/cjs/overrides/index.cjs.map +1 -0
- package/lib/cjs/ui/DecafComponent.cjs +4 -3
- package/lib/cjs/ui/DecafComponent.cjs.map +1 -0
- package/lib/cjs/ui/DecafEventHandler.cjs +3 -2
- package/lib/cjs/ui/DecafEventHandler.cjs.map +1 -0
- package/lib/cjs/ui/DecafTranslateService.cjs +1 -0
- package/lib/cjs/ui/DecafTranslateService.cjs.map +1 -0
- package/lib/cjs/ui/Rendering.cjs +62 -61
- package/lib/cjs/ui/Rendering.cjs.map +1 -0
- package/lib/cjs/ui/UIValidator.cjs +1 -0
- package/lib/cjs/ui/UIValidator.cjs.map +1 -0
- package/lib/cjs/ui/constants.cjs +4 -4
- package/lib/cjs/ui/constants.cjs.map +1 -0
- package/lib/cjs/ui/decorators.cjs +15 -14
- package/lib/cjs/ui/decorators.cjs.map +1 -0
- package/lib/cjs/ui/errors.cjs +1 -0
- package/lib/cjs/ui/errors.cjs.map +1 -0
- package/lib/cjs/ui/index.cjs +3 -2
- package/lib/cjs/ui/index.cjs.map +1 -0
- package/lib/cjs/ui/interfaces.cjs +1 -8
- package/lib/cjs/ui/interfaces.cjs.map +1 -0
- package/lib/cjs/ui/overrides.cjs +1 -0
- package/lib/cjs/ui/overrides.cjs.map +1 -0
- package/lib/cjs/ui/types.cjs +3 -2
- package/lib/cjs/ui/types.cjs.map +1 -0
- package/lib/cjs/ui/utils.cjs +7 -6
- package/lib/cjs/ui/utils.cjs.map +1 -0
- package/lib/cjs/ui/validator.cjs +1 -0
- package/lib/cjs/ui/validator.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/index.d.cts +19 -0
- package/lib/types/index.d.mts +19 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/model/Renderable.d.cts +18 -0
- package/lib/types/model/Renderable.d.mts +18 -0
- package/lib/types/model/decorators.d.cts +318 -0
- package/lib/types/model/decorators.d.mts +318 -0
- package/lib/types/model/index.d.cts +4 -0
- package/lib/types/model/index.d.mts +4 -0
- package/lib/types/model/model.d.cts +31 -0
- package/lib/types/model/model.d.mts +31 -0
- package/lib/types/model/overrides.d.cts +9 -0
- package/lib/types/model/overrides.d.mts +9 -0
- package/lib/types/overrides/ModelBuilderExtensions.d.cts +16 -0
- package/lib/types/overrides/ModelBuilderExtensions.d.mts +16 -0
- package/lib/types/overrides/index.d.cts +6 -0
- package/lib/types/overrides/index.d.mts +6 -0
- package/lib/types/ui/DecafComponent.d.cts +293 -0
- package/lib/types/ui/DecafComponent.d.mts +293 -0
- package/lib/types/ui/DecafEventHandler.d.cts +43 -0
- package/lib/types/ui/DecafEventHandler.d.mts +43 -0
- package/lib/types/ui/DecafTranslateService.d.cts +5 -0
- package/lib/types/ui/DecafTranslateService.d.mts +5 -0
- package/lib/types/ui/Rendering.d.cts +202 -0
- package/lib/types/ui/Rendering.d.mts +202 -0
- package/lib/types/ui/UIValidator.d.cts +6 -0
- package/lib/types/ui/UIValidator.d.mts +6 -0
- package/lib/types/ui/constants.d.cts +355 -0
- package/lib/types/ui/constants.d.mts +355 -0
- package/lib/types/ui/decorators.d.cts +482 -0
- package/lib/types/ui/decorators.d.mts +482 -0
- package/lib/types/ui/errors.d.cts +32 -0
- package/lib/types/ui/errors.d.mts +32 -0
- package/lib/types/ui/index.d.cts +11 -0
- package/lib/types/ui/index.d.mts +11 -0
- package/lib/types/ui/interfaces.d.cts +64 -0
- package/lib/types/ui/interfaces.d.mts +64 -0
- package/lib/types/ui/overrides.d.cts +1 -0
- package/lib/types/ui/overrides.d.mts +1 -0
- package/lib/types/ui/types.d.cts +186 -0
- package/lib/types/ui/types.d.mts +186 -0
- package/lib/types/ui/utils.d.cts +27 -0
- package/lib/types/ui/utils.d.mts +27 -0
- package/lib/types/ui/validator.d.cts +9 -0
- package/lib/types/ui/validator.d.mts +9 -0
- package/package.json +4 -4
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/model/decorators.js.map +0 -1
- package/lib/cjs/model/index.js.map +0 -1
- package/lib/cjs/model/model.js.map +0 -1
- package/lib/cjs/model/overrides.js.map +0 -1
- package/lib/cjs/overrides/ModelBuilderExtensions.js.map +0 -1
- package/lib/cjs/overrides/index.js.map +0 -1
- package/lib/cjs/ui/DecafComponent.js.map +0 -1
- package/lib/cjs/ui/DecafEventHandler.js.map +0 -1
- package/lib/cjs/ui/DecafTranslateService.js.map +0 -1
- package/lib/cjs/ui/Rendering.js.map +0 -1
- package/lib/cjs/ui/UIValidator.js.map +0 -1
- package/lib/cjs/ui/constants.js.map +0 -1
- package/lib/cjs/ui/decorators.js.map +0 -1
- package/lib/cjs/ui/errors.js.map +0 -1
- package/lib/cjs/ui/index.js.map +0 -1
- package/lib/cjs/ui/interfaces.js.map +0 -1
- package/lib/cjs/ui/overrides.js.map +0 -1
- package/lib/cjs/ui/types.js.map +0 -1
- package/lib/cjs/ui/utils.js.map +0 -1
- package/lib/cjs/ui/validator.js.map +0 -1
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { LoggedClass } from "@decaf-ts/logging";
|
|
2
|
+
import { CrudOperationKeys, UIEventProperty } from "./types.cjs";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { IRepository, OperationKeys } from "@decaf-ts/db-decorators";
|
|
5
|
+
import { DecafEventHandler } from "./DecafEventHandler.cjs";
|
|
6
|
+
import { DecafTranslateService } from "./DecafTranslateService.cjs";
|
|
7
|
+
type PrimaryKeyType = string | number | bigint;
|
|
8
|
+
/**
|
|
9
|
+
* @description Base class for all Decaf UI components
|
|
10
|
+
* @summary Base class for all Decaf UI components, providing common state management,
|
|
11
|
+
* logging, localization, navigation hooks, CRUD context metadata, and
|
|
12
|
+
* repository integration used by higher-level decorators and renderers.
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class DecafComponent<M extends Model> extends LoggedClass {
|
|
15
|
+
/**
|
|
16
|
+
* @description Data model or model name for component operations.
|
|
17
|
+
* @summary The data model that this component will use for CRUD operations. This can be provided
|
|
18
|
+
* as a Model instance, a model constructor, or a string representing the model's registered name.
|
|
19
|
+
* When set, this property provides the component with access to the model's schema, validation rules,
|
|
20
|
+
* and metadata needed for rendering and data operations.
|
|
21
|
+
*/
|
|
22
|
+
model: M | Model | string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* @description Primary key value of the current model instance.
|
|
25
|
+
* @summary Specifies the primary key value for the current model record being displayed or
|
|
26
|
+
* manipulated by the component. This identifier is used for CRUD operations that target
|
|
27
|
+
* specific records, such as read, update, and delete operations. The value corresponds to
|
|
28
|
+
* the field designated as the primary key in the model definition.
|
|
29
|
+
*/
|
|
30
|
+
modelId?: PrimaryKeyType | PrimaryKeyType[];
|
|
31
|
+
/**
|
|
32
|
+
* @description Pre-built filtering expression applied to repository queries.
|
|
33
|
+
* @summary Supply a custom `AttributeOption` to control how records are constrained. When omitted,
|
|
34
|
+
* the directive derives a condition from `filterBy` or `pk`, comparing it against `modelId`.
|
|
35
|
+
*/
|
|
36
|
+
filter: any;
|
|
37
|
+
/**
|
|
38
|
+
* @description Model field used when generating the default condition.
|
|
39
|
+
* @summary Indicates which key should be compared to `modelId` when `filter` is not provided.
|
|
40
|
+
* Defaults to the configured primary key so overrides are only needed for custom lookups.
|
|
41
|
+
*/
|
|
42
|
+
filterBy: string;
|
|
43
|
+
/**
|
|
44
|
+
* @description The CRUD operation type to be performed on the model.
|
|
45
|
+
* @summary Specifies which operation (Create, Read, Update, Delete) this component instance
|
|
46
|
+
* should perform. This determines the UI behavior, form configuration, and available actions.
|
|
47
|
+
* The operation affects form validation, field availability, and the specific repository
|
|
48
|
+
* method called during data submission.
|
|
49
|
+
*
|
|
50
|
+
* @type {OperationKeys}
|
|
51
|
+
*/
|
|
52
|
+
operation?: OperationKeys;
|
|
53
|
+
/**
|
|
54
|
+
* @description Router instance for programmatic navigation.
|
|
55
|
+
* @summary Injected Router service used for programmatic navigation between routes
|
|
56
|
+
* in the application. This service enables navigation to different views and operations,
|
|
57
|
+
* handles route parameters, and manages the browser's navigation history.
|
|
58
|
+
* @protected
|
|
59
|
+
*/
|
|
60
|
+
router?: any;
|
|
61
|
+
/**
|
|
62
|
+
* @description Name identifier for the component instance.
|
|
63
|
+
* @summary Provides a string identifier that can be used to name or label the component
|
|
64
|
+
* instance. This name can be used for debugging purposes, logging, or to identify specific
|
|
65
|
+
* component instances within a larger application structure. It serves as a human-readable
|
|
66
|
+
* identifier that helps distinguish between multiple instances of the same component type.
|
|
67
|
+
*/
|
|
68
|
+
name: string;
|
|
69
|
+
/**
|
|
70
|
+
* @description Parent component identifier for hierarchical component relationships.
|
|
71
|
+
* @summary Specifies the identifier of the parent component in a hierarchical component structure.
|
|
72
|
+
* This property establishes a parent-child relationship between components, allowing for
|
|
73
|
+
* proper nesting and organization of components within a layout. It can be used to track
|
|
74
|
+
* component dependencies and establish component hierarchies for rendering and event propagation.
|
|
75
|
+
*/
|
|
76
|
+
childOf: string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* @description Unique identifier for the component instance.
|
|
79
|
+
* @summary A unique identifier automatically generated for each component instance.
|
|
80
|
+
* This UID is used for DOM element identification, component tracking, and debugging purposes.
|
|
81
|
+
* By default, it generates a random 16-character value, but it can be explicitly set via input.
|
|
82
|
+
*/
|
|
83
|
+
uid?: PrimaryKeyType;
|
|
84
|
+
/**
|
|
85
|
+
* @description Primary key field name for the data model.
|
|
86
|
+
* @summary Specifies which field in the model should be used as the primary key.
|
|
87
|
+
* This is typically used for identifying unique records in operations like update and delete.
|
|
88
|
+
* If not explicitly set, it defaults to the repository's configured primary key or 'id'.
|
|
89
|
+
1 */
|
|
90
|
+
pk: string;
|
|
91
|
+
/**
|
|
92
|
+
* @description Translation service for application internationalization.
|
|
93
|
+
* @summary Injected service that provides translation capabilities for UI text.
|
|
94
|
+
* Used to translate button labels, validation messages, and other text content based
|
|
95
|
+
* on the current locale setting, enabling multilingual support throughout the application.
|
|
96
|
+
* @protected
|
|
97
|
+
*/
|
|
98
|
+
translateService: DecafTranslateService;
|
|
99
|
+
/**
|
|
100
|
+
* @description Angular change detection service for manual change detection control.
|
|
101
|
+
* @summary Injected service that provides manual control over change detection cycles.
|
|
102
|
+
* This is essential for ensuring that programmatic DOM changes (like setting accordion
|
|
103
|
+
* attributes) are properly reflected in the component's state and trigger appropriate
|
|
104
|
+
* view updates when modifications occur outside the normal Angular change detection flow.
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
107
|
+
protected changeDetectorRef?: any;
|
|
108
|
+
/**
|
|
109
|
+
* @description Controls field visibility based on CRUD operations.
|
|
110
|
+
* @summary Can be a boolean or an array of operation keys where the field should be hidden.
|
|
111
|
+
*/
|
|
112
|
+
hidden?: boolean | CrudOperationKeys[];
|
|
113
|
+
/**
|
|
114
|
+
* @description Label for the file upload field.
|
|
115
|
+
* @summary Provides a user-friendly label for the file upload input.
|
|
116
|
+
*/
|
|
117
|
+
label?: string;
|
|
118
|
+
/**
|
|
119
|
+
* @description Whether the field is read-only.
|
|
120
|
+
*/
|
|
121
|
+
readonly?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* @description Flag to enable or disable dark mode support for the component.
|
|
124
|
+
* @summary When enabled, the component will automatically detect the system's dark mode
|
|
125
|
+
* preference using the media service and apply appropriate styling classes. This flag
|
|
126
|
+
* controls whether the component should respond to dark mode changes and apply the
|
|
127
|
+
* dark palette class to its DOM element. By default, dark mode support is disabled.
|
|
128
|
+
* @protected
|
|
129
|
+
*/
|
|
130
|
+
protected enableDarkMode: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* @description Flag to enable or disable dark mode support for the component.
|
|
133
|
+
* @summary When enabled, the component will automatically detect the system's dark mode
|
|
134
|
+
* preference using the media service and apply appropriate styling classes. This flag
|
|
135
|
+
* controls whether the component should respond to dark mode changes and apply the
|
|
136
|
+
* dark palette class to its DOM element. By default, dark mode support is disabled.
|
|
137
|
+
* @protected
|
|
138
|
+
*/
|
|
139
|
+
protected isDarkMode: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* @description Current locale identifier for component internationalization.
|
|
142
|
+
* @summary Specifies the locale code (e.g., 'en-US', 'pt-BR') used for translating UI text
|
|
143
|
+
* and formatting data according to regional conventions. This property can be set to override
|
|
144
|
+
* the default application locale for this specific component instance, enabling per-component
|
|
145
|
+
* localization when needed.
|
|
146
|
+
*/
|
|
147
|
+
locale?: string;
|
|
148
|
+
/**
|
|
149
|
+
* @description Configuration for list item rendering behavior.
|
|
150
|
+
* @summary Defines how list items should be rendered in the component.
|
|
151
|
+
* This property holds a configuration object that specifies the tag name
|
|
152
|
+
* and other properties needed to render list items correctly. The tag property
|
|
153
|
+
* identifies which component should be used to render each item in a list.
|
|
154
|
+
* Additional properties can be included to customize the rendering behavior.
|
|
155
|
+
*/
|
|
156
|
+
item: Record<string, unknown>;
|
|
157
|
+
/**
|
|
158
|
+
* @description Dynamic properties configuration for runtime customization.
|
|
159
|
+
* @summary Contains key-value pairs of dynamic properties that can be applied to the component
|
|
160
|
+
* at runtime. This flexible configuration object allows for dynamic property assignment without
|
|
161
|
+
* requiring explicit input bindings for every possible configuration option. Properties from
|
|
162
|
+
* this object are parsed and applied to the component instance through the parseProps method,
|
|
163
|
+
* enabling customizable component behavior based on external configuration.
|
|
164
|
+
*/
|
|
165
|
+
props: Record<string, unknown>;
|
|
166
|
+
/**
|
|
167
|
+
* @description Base route path for component navigation.
|
|
168
|
+
* @summary Defines the base route path used for navigation actions related to this component.
|
|
169
|
+
* This is often used as a prefix for constructing navigation URLs when transitioning between
|
|
170
|
+
* different operations or views. The route helps establish the component's position in the
|
|
171
|
+
* application's routing hierarchy.
|
|
172
|
+
*/
|
|
173
|
+
route?: string;
|
|
174
|
+
/**
|
|
175
|
+
* @description Controls whether borders are displayed around the component.
|
|
176
|
+
* @summary Boolean flag that determines if the component should be visually outlined with borders.
|
|
177
|
+
* When true, borders are shown to visually separate the component from surrounding content.
|
|
178
|
+
*/
|
|
179
|
+
borders: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* @description Component name identifier for logging and localization contexts.
|
|
182
|
+
* @summary Stores the component's name which is used as a key for logging contexts
|
|
183
|
+
* and as a base for locale resolution.
|
|
184
|
+
* @protected
|
|
185
|
+
*/
|
|
186
|
+
protected componentName?: string;
|
|
187
|
+
/**
|
|
188
|
+
* @description Root key for component locale context resolution.
|
|
189
|
+
* @summary Defines the base key used to resolve localization contexts for this component.
|
|
190
|
+
* If not explicitly provided, it defaults to the component's name. This key is used to
|
|
191
|
+
* load appropriate translation resources and locale-specific configurations.
|
|
192
|
+
* @protected
|
|
193
|
+
*/
|
|
194
|
+
protected localeRoot?: string;
|
|
195
|
+
/**
|
|
196
|
+
* @description Current value of the component.
|
|
197
|
+
* @summary Can be a string, number, date, or array of string or objects.
|
|
198
|
+
*/
|
|
199
|
+
value?: any;
|
|
200
|
+
/**
|
|
201
|
+
* @description Reference to CRUD operation constants for template usage.
|
|
202
|
+
* @summary Exposes the OperationKeys enum to the component template, enabling
|
|
203
|
+
* conditional rendering and behavior based on operation types. This protected
|
|
204
|
+
* readonly property ensures that template logic can access operation constants
|
|
205
|
+
* while maintaining encapsulation and preventing accidental modification.
|
|
206
|
+
* @protected
|
|
207
|
+
* @readonly
|
|
208
|
+
*/
|
|
209
|
+
protected readonly OperationKeys: typeof OperationKeys;
|
|
210
|
+
/**
|
|
211
|
+
* @description Angular Location service.
|
|
212
|
+
* @summary Injected service that provides direct access to the browser's URL and history.
|
|
213
|
+
* Unlike the Router, Location allows for low-level manipulation of the browser's history stack
|
|
214
|
+
* and URL path, such as programmatically navigating back or forward, or updating the URL without
|
|
215
|
+
* triggering a route change. This is useful for scenarios where you need to interact with the
|
|
216
|
+
* browser history or URL outside of Angular's routing system, such as closing modals, handling
|
|
217
|
+
* popstate events, or supporting custom navigation logic.
|
|
218
|
+
*
|
|
219
|
+
*/
|
|
220
|
+
location: any;
|
|
221
|
+
/**
|
|
222
|
+
* @description Repository instance for data layer operations.
|
|
223
|
+
* @summary Provides a connection to the data layer for retrieving and manipulating data.
|
|
224
|
+
* This is an instance of the DecafRepository class, initialized lazily in the repository getter.
|
|
225
|
+
* The repository is used to perform CRUD (Create, Read, Update, Delete) operations on the
|
|
226
|
+
* data model and provides methods for querying and filtering data based on specific criteria.
|
|
227
|
+
*
|
|
228
|
+
* @protected
|
|
229
|
+
*/
|
|
230
|
+
protected _repository?: IRepository<M>;
|
|
231
|
+
/**
|
|
232
|
+
* @description Initialization status flag for the component.
|
|
233
|
+
* @summary Tracks whether the component has completed its initialization process.
|
|
234
|
+
* This flag is used to prevent duplicate initialization and to determine if
|
|
235
|
+
* certain operations that require initialization can be performed.
|
|
236
|
+
* @default false
|
|
237
|
+
*/
|
|
238
|
+
protected initialized: boolean;
|
|
239
|
+
protected events: UIEventProperty;
|
|
240
|
+
protected handlers: UIEventProperty;
|
|
241
|
+
protected constructor();
|
|
242
|
+
get repository(): IRepository<M>;
|
|
243
|
+
set repository(repository: IRepository<M>);
|
|
244
|
+
render(...args: unknown[]): Promise<any>;
|
|
245
|
+
refresh(...args: unknown[]): Promise<any>;
|
|
246
|
+
/**
|
|
247
|
+
* Asynchronously initializes the component with the provided arguments.
|
|
248
|
+
* This method sets the `initialized` property to `true` once the initialization is complete.
|
|
249
|
+
*
|
|
250
|
+
* @param args - A variable number of arguments of unknown types that can be used for initialization.
|
|
251
|
+
* @returns A promise that resolves when the initialization is complete.
|
|
252
|
+
*/
|
|
253
|
+
initialize(...args: unknown[]): Promise<any>;
|
|
254
|
+
/**
|
|
255
|
+
* Translates content based on the provided arguments.
|
|
256
|
+
* Logs the translation request with the component name and arguments.
|
|
257
|
+
*
|
|
258
|
+
* @param args - A variable number of arguments used for translation.
|
|
259
|
+
* @returns A promise that resolves with the translation result.
|
|
260
|
+
*/
|
|
261
|
+
translate(...args: unknown[]): Promise<any>;
|
|
262
|
+
preview(...args: unknown[]): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Submits data or performs an action associated with the component.
|
|
265
|
+
*
|
|
266
|
+
* @param args - A variable number of arguments of any type to be passed to the submit operation.
|
|
267
|
+
* @returns A promise that resolves with the result of the submit operation.
|
|
268
|
+
*/
|
|
269
|
+
submit(...args: unknown[]): Promise<any>;
|
|
270
|
+
/**
|
|
271
|
+
* @description Normalizes handler definitions into executable functions.
|
|
272
|
+
* @summary Iterates through a handlers map and ensures each entry is stored as a callable
|
|
273
|
+
* function on the component. Plain functions are stored directly, while handler classes are
|
|
274
|
+
* instantiated so their `handle` method (or a keyed override) becomes the registered handler.
|
|
275
|
+
* This allows decorators to accept either inline functions or handler classes transparently.
|
|
276
|
+
* @template T Extends `DecafEventHandler` to constrain handler class types.
|
|
277
|
+
* @param handlers - Dictionary of handler names mapped to functions or handler constructors.
|
|
278
|
+
* @param instance - Optional target handler instance; defaults to the current component.
|
|
279
|
+
*/
|
|
280
|
+
protected parseHandlers<T extends DecafEventHandler>(handlers: UIEventProperty, instance: T): UIEventProperty;
|
|
281
|
+
/**
|
|
282
|
+
* @description Registers event callbacks on the component instance.
|
|
283
|
+
* @summary Processes an events map produced by decorators where each value can be a factory
|
|
284
|
+
* returning a function or a component constructor. When a constructor is returned, the method
|
|
285
|
+
* matching the event key is instantiated and stored; otherwise the produced function is
|
|
286
|
+
* assigned directly. This enables flexible event binding definitions for derived components.
|
|
287
|
+
* @template T Extends `DecafComponent<Model>` to scope acceptable event owners.
|
|
288
|
+
* @param events - Dictionary of event names mapped to function factories or component constructors.
|
|
289
|
+
* @param instance - Optional component instance to receive the events; defaults to `this`.
|
|
290
|
+
*/
|
|
291
|
+
protected parseEvents<T extends DecafComponent<Model>>(events: UIEventProperty, instance: T): UIEventProperty;
|
|
292
|
+
}
|
|
293
|
+
export {};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { LoggedClass } from "@decaf-ts/logging";
|
|
2
|
+
import { CrudOperationKeys, UIEventProperty } from "./types.js";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { IRepository, OperationKeys } from "@decaf-ts/db-decorators";
|
|
5
|
+
import { DecafEventHandler } from "./DecafEventHandler.js";
|
|
6
|
+
import { DecafTranslateService } from "./DecafTranslateService.js";
|
|
7
|
+
type PrimaryKeyType = string | number | bigint;
|
|
8
|
+
/**
|
|
9
|
+
* @description Base class for all Decaf UI components
|
|
10
|
+
* @summary Base class for all Decaf UI components, providing common state management,
|
|
11
|
+
* logging, localization, navigation hooks, CRUD context metadata, and
|
|
12
|
+
* repository integration used by higher-level decorators and renderers.
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class DecafComponent<M extends Model> extends LoggedClass {
|
|
15
|
+
/**
|
|
16
|
+
* @description Data model or model name for component operations.
|
|
17
|
+
* @summary The data model that this component will use for CRUD operations. This can be provided
|
|
18
|
+
* as a Model instance, a model constructor, or a string representing the model's registered name.
|
|
19
|
+
* When set, this property provides the component with access to the model's schema, validation rules,
|
|
20
|
+
* and metadata needed for rendering and data operations.
|
|
21
|
+
*/
|
|
22
|
+
model: M | Model | string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* @description Primary key value of the current model instance.
|
|
25
|
+
* @summary Specifies the primary key value for the current model record being displayed or
|
|
26
|
+
* manipulated by the component. This identifier is used for CRUD operations that target
|
|
27
|
+
* specific records, such as read, update, and delete operations. The value corresponds to
|
|
28
|
+
* the field designated as the primary key in the model definition.
|
|
29
|
+
*/
|
|
30
|
+
modelId?: PrimaryKeyType | PrimaryKeyType[];
|
|
31
|
+
/**
|
|
32
|
+
* @description Pre-built filtering expression applied to repository queries.
|
|
33
|
+
* @summary Supply a custom `AttributeOption` to control how records are constrained. When omitted,
|
|
34
|
+
* the directive derives a condition from `filterBy` or `pk`, comparing it against `modelId`.
|
|
35
|
+
*/
|
|
36
|
+
filter: any;
|
|
37
|
+
/**
|
|
38
|
+
* @description Model field used when generating the default condition.
|
|
39
|
+
* @summary Indicates which key should be compared to `modelId` when `filter` is not provided.
|
|
40
|
+
* Defaults to the configured primary key so overrides are only needed for custom lookups.
|
|
41
|
+
*/
|
|
42
|
+
filterBy: string;
|
|
43
|
+
/**
|
|
44
|
+
* @description The CRUD operation type to be performed on the model.
|
|
45
|
+
* @summary Specifies which operation (Create, Read, Update, Delete) this component instance
|
|
46
|
+
* should perform. This determines the UI behavior, form configuration, and available actions.
|
|
47
|
+
* The operation affects form validation, field availability, and the specific repository
|
|
48
|
+
* method called during data submission.
|
|
49
|
+
*
|
|
50
|
+
* @type {OperationKeys}
|
|
51
|
+
*/
|
|
52
|
+
operation?: OperationKeys;
|
|
53
|
+
/**
|
|
54
|
+
* @description Router instance for programmatic navigation.
|
|
55
|
+
* @summary Injected Router service used for programmatic navigation between routes
|
|
56
|
+
* in the application. This service enables navigation to different views and operations,
|
|
57
|
+
* handles route parameters, and manages the browser's navigation history.
|
|
58
|
+
* @protected
|
|
59
|
+
*/
|
|
60
|
+
router?: any;
|
|
61
|
+
/**
|
|
62
|
+
* @description Name identifier for the component instance.
|
|
63
|
+
* @summary Provides a string identifier that can be used to name or label the component
|
|
64
|
+
* instance. This name can be used for debugging purposes, logging, or to identify specific
|
|
65
|
+
* component instances within a larger application structure. It serves as a human-readable
|
|
66
|
+
* identifier that helps distinguish between multiple instances of the same component type.
|
|
67
|
+
*/
|
|
68
|
+
name: string;
|
|
69
|
+
/**
|
|
70
|
+
* @description Parent component identifier for hierarchical component relationships.
|
|
71
|
+
* @summary Specifies the identifier of the parent component in a hierarchical component structure.
|
|
72
|
+
* This property establishes a parent-child relationship between components, allowing for
|
|
73
|
+
* proper nesting and organization of components within a layout. It can be used to track
|
|
74
|
+
* component dependencies and establish component hierarchies for rendering and event propagation.
|
|
75
|
+
*/
|
|
76
|
+
childOf: string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* @description Unique identifier for the component instance.
|
|
79
|
+
* @summary A unique identifier automatically generated for each component instance.
|
|
80
|
+
* This UID is used for DOM element identification, component tracking, and debugging purposes.
|
|
81
|
+
* By default, it generates a random 16-character value, but it can be explicitly set via input.
|
|
82
|
+
*/
|
|
83
|
+
uid?: PrimaryKeyType;
|
|
84
|
+
/**
|
|
85
|
+
* @description Primary key field name for the data model.
|
|
86
|
+
* @summary Specifies which field in the model should be used as the primary key.
|
|
87
|
+
* This is typically used for identifying unique records in operations like update and delete.
|
|
88
|
+
* If not explicitly set, it defaults to the repository's configured primary key or 'id'.
|
|
89
|
+
1 */
|
|
90
|
+
pk: string;
|
|
91
|
+
/**
|
|
92
|
+
* @description Translation service for application internationalization.
|
|
93
|
+
* @summary Injected service that provides translation capabilities for UI text.
|
|
94
|
+
* Used to translate button labels, validation messages, and other text content based
|
|
95
|
+
* on the current locale setting, enabling multilingual support throughout the application.
|
|
96
|
+
* @protected
|
|
97
|
+
*/
|
|
98
|
+
translateService: DecafTranslateService;
|
|
99
|
+
/**
|
|
100
|
+
* @description Angular change detection service for manual change detection control.
|
|
101
|
+
* @summary Injected service that provides manual control over change detection cycles.
|
|
102
|
+
* This is essential for ensuring that programmatic DOM changes (like setting accordion
|
|
103
|
+
* attributes) are properly reflected in the component's state and trigger appropriate
|
|
104
|
+
* view updates when modifications occur outside the normal Angular change detection flow.
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
107
|
+
protected changeDetectorRef?: any;
|
|
108
|
+
/**
|
|
109
|
+
* @description Controls field visibility based on CRUD operations.
|
|
110
|
+
* @summary Can be a boolean or an array of operation keys where the field should be hidden.
|
|
111
|
+
*/
|
|
112
|
+
hidden?: boolean | CrudOperationKeys[];
|
|
113
|
+
/**
|
|
114
|
+
* @description Label for the file upload field.
|
|
115
|
+
* @summary Provides a user-friendly label for the file upload input.
|
|
116
|
+
*/
|
|
117
|
+
label?: string;
|
|
118
|
+
/**
|
|
119
|
+
* @description Whether the field is read-only.
|
|
120
|
+
*/
|
|
121
|
+
readonly?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* @description Flag to enable or disable dark mode support for the component.
|
|
124
|
+
* @summary When enabled, the component will automatically detect the system's dark mode
|
|
125
|
+
* preference using the media service and apply appropriate styling classes. This flag
|
|
126
|
+
* controls whether the component should respond to dark mode changes and apply the
|
|
127
|
+
* dark palette class to its DOM element. By default, dark mode support is disabled.
|
|
128
|
+
* @protected
|
|
129
|
+
*/
|
|
130
|
+
protected enableDarkMode: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* @description Flag to enable or disable dark mode support for the component.
|
|
133
|
+
* @summary When enabled, the component will automatically detect the system's dark mode
|
|
134
|
+
* preference using the media service and apply appropriate styling classes. This flag
|
|
135
|
+
* controls whether the component should respond to dark mode changes and apply the
|
|
136
|
+
* dark palette class to its DOM element. By default, dark mode support is disabled.
|
|
137
|
+
* @protected
|
|
138
|
+
*/
|
|
139
|
+
protected isDarkMode: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* @description Current locale identifier for component internationalization.
|
|
142
|
+
* @summary Specifies the locale code (e.g., 'en-US', 'pt-BR') used for translating UI text
|
|
143
|
+
* and formatting data according to regional conventions. This property can be set to override
|
|
144
|
+
* the default application locale for this specific component instance, enabling per-component
|
|
145
|
+
* localization when needed.
|
|
146
|
+
*/
|
|
147
|
+
locale?: string;
|
|
148
|
+
/**
|
|
149
|
+
* @description Configuration for list item rendering behavior.
|
|
150
|
+
* @summary Defines how list items should be rendered in the component.
|
|
151
|
+
* This property holds a configuration object that specifies the tag name
|
|
152
|
+
* and other properties needed to render list items correctly. The tag property
|
|
153
|
+
* identifies which component should be used to render each item in a list.
|
|
154
|
+
* Additional properties can be included to customize the rendering behavior.
|
|
155
|
+
*/
|
|
156
|
+
item: Record<string, unknown>;
|
|
157
|
+
/**
|
|
158
|
+
* @description Dynamic properties configuration for runtime customization.
|
|
159
|
+
* @summary Contains key-value pairs of dynamic properties that can be applied to the component
|
|
160
|
+
* at runtime. This flexible configuration object allows for dynamic property assignment without
|
|
161
|
+
* requiring explicit input bindings for every possible configuration option. Properties from
|
|
162
|
+
* this object are parsed and applied to the component instance through the parseProps method,
|
|
163
|
+
* enabling customizable component behavior based on external configuration.
|
|
164
|
+
*/
|
|
165
|
+
props: Record<string, unknown>;
|
|
166
|
+
/**
|
|
167
|
+
* @description Base route path for component navigation.
|
|
168
|
+
* @summary Defines the base route path used for navigation actions related to this component.
|
|
169
|
+
* This is often used as a prefix for constructing navigation URLs when transitioning between
|
|
170
|
+
* different operations or views. The route helps establish the component's position in the
|
|
171
|
+
* application's routing hierarchy.
|
|
172
|
+
*/
|
|
173
|
+
route?: string;
|
|
174
|
+
/**
|
|
175
|
+
* @description Controls whether borders are displayed around the component.
|
|
176
|
+
* @summary Boolean flag that determines if the component should be visually outlined with borders.
|
|
177
|
+
* When true, borders are shown to visually separate the component from surrounding content.
|
|
178
|
+
*/
|
|
179
|
+
borders: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* @description Component name identifier for logging and localization contexts.
|
|
182
|
+
* @summary Stores the component's name which is used as a key for logging contexts
|
|
183
|
+
* and as a base for locale resolution.
|
|
184
|
+
* @protected
|
|
185
|
+
*/
|
|
186
|
+
protected componentName?: string;
|
|
187
|
+
/**
|
|
188
|
+
* @description Root key for component locale context resolution.
|
|
189
|
+
* @summary Defines the base key used to resolve localization contexts for this component.
|
|
190
|
+
* If not explicitly provided, it defaults to the component's name. This key is used to
|
|
191
|
+
* load appropriate translation resources and locale-specific configurations.
|
|
192
|
+
* @protected
|
|
193
|
+
*/
|
|
194
|
+
protected localeRoot?: string;
|
|
195
|
+
/**
|
|
196
|
+
* @description Current value of the component.
|
|
197
|
+
* @summary Can be a string, number, date, or array of string or objects.
|
|
198
|
+
*/
|
|
199
|
+
value?: any;
|
|
200
|
+
/**
|
|
201
|
+
* @description Reference to CRUD operation constants for template usage.
|
|
202
|
+
* @summary Exposes the OperationKeys enum to the component template, enabling
|
|
203
|
+
* conditional rendering and behavior based on operation types. This protected
|
|
204
|
+
* readonly property ensures that template logic can access operation constants
|
|
205
|
+
* while maintaining encapsulation and preventing accidental modification.
|
|
206
|
+
* @protected
|
|
207
|
+
* @readonly
|
|
208
|
+
*/
|
|
209
|
+
protected readonly OperationKeys: typeof OperationKeys;
|
|
210
|
+
/**
|
|
211
|
+
* @description Angular Location service.
|
|
212
|
+
* @summary Injected service that provides direct access to the browser's URL and history.
|
|
213
|
+
* Unlike the Router, Location allows for low-level manipulation of the browser's history stack
|
|
214
|
+
* and URL path, such as programmatically navigating back or forward, or updating the URL without
|
|
215
|
+
* triggering a route change. This is useful for scenarios where you need to interact with the
|
|
216
|
+
* browser history or URL outside of Angular's routing system, such as closing modals, handling
|
|
217
|
+
* popstate events, or supporting custom navigation logic.
|
|
218
|
+
*
|
|
219
|
+
*/
|
|
220
|
+
location: any;
|
|
221
|
+
/**
|
|
222
|
+
* @description Repository instance for data layer operations.
|
|
223
|
+
* @summary Provides a connection to the data layer for retrieving and manipulating data.
|
|
224
|
+
* This is an instance of the DecafRepository class, initialized lazily in the repository getter.
|
|
225
|
+
* The repository is used to perform CRUD (Create, Read, Update, Delete) operations on the
|
|
226
|
+
* data model and provides methods for querying and filtering data based on specific criteria.
|
|
227
|
+
*
|
|
228
|
+
* @protected
|
|
229
|
+
*/
|
|
230
|
+
protected _repository?: IRepository<M>;
|
|
231
|
+
/**
|
|
232
|
+
* @description Initialization status flag for the component.
|
|
233
|
+
* @summary Tracks whether the component has completed its initialization process.
|
|
234
|
+
* This flag is used to prevent duplicate initialization and to determine if
|
|
235
|
+
* certain operations that require initialization can be performed.
|
|
236
|
+
* @default false
|
|
237
|
+
*/
|
|
238
|
+
protected initialized: boolean;
|
|
239
|
+
protected events: UIEventProperty;
|
|
240
|
+
protected handlers: UIEventProperty;
|
|
241
|
+
protected constructor();
|
|
242
|
+
get repository(): IRepository<M>;
|
|
243
|
+
set repository(repository: IRepository<M>);
|
|
244
|
+
render(...args: unknown[]): Promise<any>;
|
|
245
|
+
refresh(...args: unknown[]): Promise<any>;
|
|
246
|
+
/**
|
|
247
|
+
* Asynchronously initializes the component with the provided arguments.
|
|
248
|
+
* This method sets the `initialized` property to `true` once the initialization is complete.
|
|
249
|
+
*
|
|
250
|
+
* @param args - A variable number of arguments of unknown types that can be used for initialization.
|
|
251
|
+
* @returns A promise that resolves when the initialization is complete.
|
|
252
|
+
*/
|
|
253
|
+
initialize(...args: unknown[]): Promise<any>;
|
|
254
|
+
/**
|
|
255
|
+
* Translates content based on the provided arguments.
|
|
256
|
+
* Logs the translation request with the component name and arguments.
|
|
257
|
+
*
|
|
258
|
+
* @param args - A variable number of arguments used for translation.
|
|
259
|
+
* @returns A promise that resolves with the translation result.
|
|
260
|
+
*/
|
|
261
|
+
translate(...args: unknown[]): Promise<any>;
|
|
262
|
+
preview(...args: unknown[]): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Submits data or performs an action associated with the component.
|
|
265
|
+
*
|
|
266
|
+
* @param args - A variable number of arguments of any type to be passed to the submit operation.
|
|
267
|
+
* @returns A promise that resolves with the result of the submit operation.
|
|
268
|
+
*/
|
|
269
|
+
submit(...args: unknown[]): Promise<any>;
|
|
270
|
+
/**
|
|
271
|
+
* @description Normalizes handler definitions into executable functions.
|
|
272
|
+
* @summary Iterates through a handlers map and ensures each entry is stored as a callable
|
|
273
|
+
* function on the component. Plain functions are stored directly, while handler classes are
|
|
274
|
+
* instantiated so their `handle` method (or a keyed override) becomes the registered handler.
|
|
275
|
+
* This allows decorators to accept either inline functions or handler classes transparently.
|
|
276
|
+
* @template T Extends `DecafEventHandler` to constrain handler class types.
|
|
277
|
+
* @param handlers - Dictionary of handler names mapped to functions or handler constructors.
|
|
278
|
+
* @param instance - Optional target handler instance; defaults to the current component.
|
|
279
|
+
*/
|
|
280
|
+
protected parseHandlers<T extends DecafEventHandler>(handlers: UIEventProperty, instance: T): UIEventProperty;
|
|
281
|
+
/**
|
|
282
|
+
* @description Registers event callbacks on the component instance.
|
|
283
|
+
* @summary Processes an events map produced by decorators where each value can be a factory
|
|
284
|
+
* returning a function or a component constructor. When a constructor is returned, the method
|
|
285
|
+
* matching the event key is instantiated and stored; otherwise the produced function is
|
|
286
|
+
* assigned directly. This enables flexible event binding definitions for derived components.
|
|
287
|
+
* @template T Extends `DecafComponent<Model>` to scope acceptable event owners.
|
|
288
|
+
* @param events - Dictionary of event names mapped to function factories or component constructors.
|
|
289
|
+
* @param instance - Optional component instance to receive the events; defaults to `this`.
|
|
290
|
+
*/
|
|
291
|
+
protected parseEvents<T extends DecafComponent<Model>>(events: UIEventProperty, instance: T): UIEventProperty;
|
|
292
|
+
}
|
|
293
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { DecafComponent } from "./DecafComponent.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description Class representing an event handler
|
|
5
|
+
* @summary Defines the structure for handling events in the UI decorators system
|
|
6
|
+
* This class provides a foundation for managing and processing events that occur
|
|
7
|
+
* within the UI components generated by the decorators.
|
|
8
|
+
* @class EventHandler
|
|
9
|
+
* @memberOf module:ui-decorators/ui
|
|
10
|
+
*/
|
|
11
|
+
export declare class DecafEventHandler extends DecafComponent<Model> {
|
|
12
|
+
/**
|
|
13
|
+
* @description Creates an instance of DecafEventHandler
|
|
14
|
+
* @summary Initializes a new EventHandler object
|
|
15
|
+
* This constructor currently doesn't take any parameters, but it can be
|
|
16
|
+
* extended in the future to accept configuration options if needed.
|
|
17
|
+
*/
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Handles an event with the provided arguments.
|
|
21
|
+
* Logs the event handling process, including the component name and the arguments passed.
|
|
22
|
+
*
|
|
23
|
+
* @param args - The arguments for the event handler.
|
|
24
|
+
* @returns void
|
|
25
|
+
*/
|
|
26
|
+
handle(...args: unknown[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Handles an click event with the provided arguments.
|
|
29
|
+
* Logs the event handling process, including the component name and the arguments passed.
|
|
30
|
+
*
|
|
31
|
+
* @param args - The arguments for the event handler.
|
|
32
|
+
* @returns void
|
|
33
|
+
*/
|
|
34
|
+
handleClick(...args: unknown[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Handles an click event with the provided arguments.
|
|
37
|
+
* Logs the event handling process, including the component name and the arguments passed.
|
|
38
|
+
*
|
|
39
|
+
* @param args - The arguments for the event handler.
|
|
40
|
+
* @returns void
|
|
41
|
+
*/
|
|
42
|
+
handleAction(...args: unknown[]): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { DecafComponent } from "./DecafComponent.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description Class representing an event handler
|
|
5
|
+
* @summary Defines the structure for handling events in the UI decorators system
|
|
6
|
+
* This class provides a foundation for managing and processing events that occur
|
|
7
|
+
* within the UI components generated by the decorators.
|
|
8
|
+
* @class EventHandler
|
|
9
|
+
* @memberOf module:ui-decorators/ui
|
|
10
|
+
*/
|
|
11
|
+
export declare class DecafEventHandler extends DecafComponent<Model> {
|
|
12
|
+
/**
|
|
13
|
+
* @description Creates an instance of DecafEventHandler
|
|
14
|
+
* @summary Initializes a new EventHandler object
|
|
15
|
+
* This constructor currently doesn't take any parameters, but it can be
|
|
16
|
+
* extended in the future to accept configuration options if needed.
|
|
17
|
+
*/
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Handles an event with the provided arguments.
|
|
21
|
+
* Logs the event handling process, including the component name and the arguments passed.
|
|
22
|
+
*
|
|
23
|
+
* @param args - The arguments for the event handler.
|
|
24
|
+
* @returns void
|
|
25
|
+
*/
|
|
26
|
+
handle(...args: unknown[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Handles an click event with the provided arguments.
|
|
29
|
+
* Logs the event handling process, including the component name and the arguments passed.
|
|
30
|
+
*
|
|
31
|
+
* @param args - The arguments for the event handler.
|
|
32
|
+
* @returns void
|
|
33
|
+
*/
|
|
34
|
+
handleClick(...args: unknown[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Handles an click event with the provided arguments.
|
|
37
|
+
* Logs the event handling process, including the component name and the arguments passed.
|
|
38
|
+
*
|
|
39
|
+
* @param args - The arguments for the event handler.
|
|
40
|
+
* @returns void
|
|
41
|
+
*/
|
|
42
|
+
handleAction(...args: unknown[]): void;
|
|
43
|
+
}
|