@decaf-ts/for-angular 0.0.16 → 0.0.18

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 (65) hide show
  1. package/assets/i18n/en.json +9 -69
  2. package/assets/i18n/pt.json +80 -0
  3. package/assets/icons/icon-128.webp +0 -0
  4. package/assets/icons/icon-192.webp +0 -0
  5. package/assets/icons/icon-256.webp +0 -0
  6. package/assets/icons/icon-48.webp +0 -0
  7. package/assets/icons/icon-512.webp +0 -0
  8. package/assets/icons/icon-72.webp +0 -0
  9. package/assets/icons/icon-96.webp +0 -0
  10. package/assets/images/apple-touch-icon.png +0 -0
  11. package/assets/images/favicon.png +0 -0
  12. package/assets/images/favicon.svg +29 -0
  13. package/components/component-renderer/component-renderer.component.d.ts +5 -4
  14. package/components/crud-field/crud-field.component.d.ts +186 -22
  15. package/components/crud-form/crud-form.component.d.ts +194 -8
  16. package/components/empty-state/empty-state.component.d.ts +9 -10
  17. package/components/fieldset/fieldset.component.d.ts +383 -36
  18. package/components/filter/filter.component.d.ts +11 -2
  19. package/components/list/list.component.d.ts +1 -1
  20. package/components/list-item/list-item.component.d.ts +2 -2
  21. package/components/model-renderer/model-renderer.component.d.ts +1 -5
  22. package/directives/collapsable.directive.d.ts +1 -0
  23. package/engine/NgxBaseComponent.d.ts +43 -43
  24. package/engine/NgxCrudFormField.d.ts +7 -3
  25. package/engine/NgxFormService.d.ts +113 -12
  26. package/engine/NgxRenderingEngine.d.ts +178 -25
  27. package/engine/constants.d.ts +11 -6
  28. package/engine/decorators.d.ts +2 -2
  29. package/engine/index.d.ts +4 -2
  30. package/engine/interfaces.d.ts +271 -0
  31. package/engine/types.d.ts +11 -206
  32. package/esm2022/components/component-renderer/component-renderer.component.mjs +13 -11
  33. package/esm2022/components/crud-field/crud-field.component.mjs +213 -8
  34. package/esm2022/components/crud-form/crud-form.component.mjs +133 -13
  35. package/esm2022/components/empty-state/empty-state.component.mjs +13 -12
  36. package/esm2022/components/fieldset/fieldset.component.mjs +485 -43
  37. package/esm2022/components/filter/filter.component.mjs +16 -6
  38. package/esm2022/components/layout/layout.component.mjs +3 -3
  39. package/esm2022/components/list/list.component.mjs +4 -5
  40. package/esm2022/components/list-item/list-item.component.mjs +10 -10
  41. package/esm2022/components/model-renderer/model-renderer.component.mjs +9 -8
  42. package/esm2022/components/pagination/pagination.component.mjs +7 -7
  43. package/esm2022/components/searchbar/searchbar.component.mjs +3 -3
  44. package/esm2022/directives/collapsable.directive.mjs +3 -2
  45. package/esm2022/engine/NgxBaseComponent.mjs +64 -63
  46. package/esm2022/engine/NgxCrudFormField.mjs +14 -4
  47. package/esm2022/engine/NgxFormService.mjs +239 -27
  48. package/esm2022/engine/NgxRenderingEngine.mjs +218 -46
  49. package/esm2022/engine/ValidatorFactory.mjs +6 -4
  50. package/esm2022/engine/constants.mjs +14 -9
  51. package/esm2022/engine/decorators.mjs +6 -6
  52. package/esm2022/engine/index.mjs +5 -3
  53. package/esm2022/engine/interfaces.mjs +4 -0
  54. package/esm2022/engine/types.mjs +1 -3
  55. package/esm2022/helpers/utils.mjs +53 -32
  56. package/esm2022/i18n/Loader.mjs +82 -0
  57. package/fesm2022/decaf-ts-for-angular.mjs +3030 -2097
  58. package/fesm2022/decaf-ts-for-angular.mjs.map +1 -1
  59. package/helpers/utils.d.ts +42 -16
  60. package/i18n/Loader.d.ts +48 -0
  61. package/package.json +11 -1
  62. package/engine/NgxRenderingEngine2.d.ts +0 -250
  63. package/esm2022/engine/NgxRenderingEngine2.mjs +0 -332
  64. package/esm2022/interfaces.mjs +0 -2
  65. package/interfaces.d.ts +0 -28
@@ -152,22 +152,7 @@ export declare function isNotUndefined(prop: StringOrBoolean | undefined): boole
152
152
  * @function getLocaleFromClassName
153
153
  * @memberOf module:for-angular
154
154
  */
155
- export declare function getLocaleFromClassName(instance: string | FunctionLike | object, suffix?: string): string;
156
- /**
157
- * @description Generates a localized string by combining locale and phrase
158
- * @summary This utility function creates a properly formatted locale string by combining
159
- * a locale identifier with a phrase. It handles edge cases such as empty phrases,
160
- * missing locales, and phrases that already include the locale prefix. This function
161
- * is useful for ensuring consistent formatting of localized strings throughout the application.
162
- *
163
- * @param {string} locale - The locale identifier (e.g., 'en', 'fr')
164
- * @param {string | undefined} phrase - The phrase to localize
165
- * @return {string} The formatted locale string, or empty string if phrase is undefined
166
- *
167
- * @function generateLocaleFromString
168
- * @memberOf module:for-angular
169
- */
170
- export declare function generateLocaleFromString(locale: string, phrase: string | undefined): string;
155
+ export declare function getLocaleFromClassName(instance: string | FunctionLike | KeyValue, suffix?: string): string;
171
156
  /**
172
157
  * @description Retrieves the current locale language
173
158
  * @summary This utility function gets the current locale language based on the user's browser settings.
@@ -250,4 +235,45 @@ export declare function itemMapper(item: KeyValue, mapper: KeyValue, props?: Key
250
235
  * the original item is returned instead.
251
236
  */
252
237
  export declare function dataMapper<T>(data: T[], mapper: KeyValue, props?: KeyValue): T[];
238
+ /**
239
+ * @description Removes focus from the currently active DOM element
240
+ * @summary This utility function blurs the currently focused element in the document,
241
+ * effectively removing focus traps that might prevent proper navigation or keyboard
242
+ * interaction. It safely accesses the document's activeElement and calls blur() if
243
+ * an element is currently focused. This is useful for accessibility and user experience
244
+ * improvements, particularly when closing modals or dialogs.
245
+ *
246
+ * @return {void}
247
+ *
248
+ * @function removeFocusTrap
249
+ * @memberOf module:for-angular
250
+ */
253
251
  export declare function removeFocusTrap(): void;
252
+ /**
253
+ * @description Cleans and normalizes whitespace in a string value
254
+ * @summary This utility function trims leading and trailing whitespace from a string
255
+ * and replaces multiple consecutive whitespace characters with a single space.
256
+ * Optionally converts the result to lowercase for consistent text processing.
257
+ * This is useful for normalizing user input, search terms, or data sanitization.
258
+ *
259
+ * @param {string} value - The string value to clean and normalize
260
+ * @param {boolean} [lowercase=false] - Whether to convert the result to lowercase
261
+ * @return {string} The cleaned and normalized string
262
+ *
263
+ * @function cleanSpaces
264
+ * @memberOf module:for-angular
265
+ */
266
+ export declare function cleanSpaces(value?: string, lowercase?: boolean): string;
267
+ /**
268
+ * @description Determines if the user's system is currently in dark mode
269
+ * @summary This function checks the user's color scheme preference using the CSS media query
270
+ * '(prefers-color-scheme: dark)'. It returns a boolean indicating whether the system is
271
+ * currently set to dark mode. This is useful for implementing theme-aware functionality
272
+ * and adjusting UI elements based on the user's preferred color scheme.
273
+ *
274
+ * @return {Promise<boolean>} True if the system is in dark mode, false otherwise
275
+ *
276
+ * @function isDarkMode
277
+ * @memberOf module:for-angular
278
+ */
279
+ export declare function isDarkMode(): Promise<boolean>;
@@ -0,0 +1,48 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { TranslateLoader, TranslationObject } from '@ngx-translate/core';
3
+ import { Observable } from 'rxjs';
4
+ import { I18nResourceConfig } from '../engine/interfaces';
5
+ import { InjectionToken } from '@angular/core';
6
+ import { FunctionLike } from '../engine';
7
+ export declare class I18nLoader {
8
+ static loadFromHttp(http: HttpClient): TranslateLoader;
9
+ }
10
+ export declare function getLocaleContext(clazz: FunctionLike | object | string, suffix?: string): string;
11
+ /**
12
+ * @description Generates a localized string by combining locale and phrase
13
+ * @summary This utility function creates a properly formatted locale string by combining
14
+ * a locale identifier with a phrase. It handles edge cases such as empty phrases,
15
+ * missing locales, and phrases that already include the locale prefix. This function
16
+ * is useful for ensuring consistent formatting of localized strings throughout the application.
17
+ *
18
+ * @param {string} locale - The locale identifier (e.g., 'en', 'fr')
19
+ * @param {string | undefined} phrase - The phrase to localize
20
+ * @return {string} The formatted locale string, or empty string if phrase is undefined
21
+ *
22
+ * @function generateLocaleFromString
23
+ * @memberOf module:for-angular
24
+ */
25
+ export declare function getLocaleContextByKey(locale: string, phrase: string | undefined): string;
26
+ export declare const I18N_CONFIG_TOKEN: InjectionToken<{
27
+ resources: I18nResourceConfig[];
28
+ versionedSuffix: false;
29
+ }>;
30
+ export declare function I18nLoaderFactory(http: HttpClient): TranslateLoader;
31
+ export declare function getI18nLoaderFactoryProviderConfig(resources?: I18nResourceConfig | I18nResourceConfig[], versionedSuffix?: boolean): {
32
+ provide: InjectionToken<{
33
+ resources: I18nResourceConfig[];
34
+ versionedSuffix: false;
35
+ }>;
36
+ useValue: {
37
+ resources: I18nResourceConfig[];
38
+ versionedSuffix: boolean;
39
+ };
40
+ };
41
+ export declare class MultiI18nLoader implements I18nLoader {
42
+ private http;
43
+ private resources;
44
+ private versionedSuffix;
45
+ constructor(http: HttpClient, resources?: I18nResourceConfig[], versionedSuffix?: boolean);
46
+ private getSuffix;
47
+ getTranslation(lang: string): Observable<TranslationObject>;
48
+ }
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "@decaf-ts/for-angular",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "author": "Tiago Venceslau",
5
5
  "license": "AGPL-3.0-or-later",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/decaf-ts/for-angular.git"
9
+ },
10
+ "engines": {
11
+ "node": ">=20.0.0",
12
+ "npm": ">=10.0.0"
13
+ },
6
14
  "peerDependencies": {
7
15
  "@angular/animations": "^18.2.13",
16
+ "@angular/cdk": "^18.2.14",
8
17
  "@angular/common": "^18.2.13",
9
18
  "@angular/compiler": "^18.2.13",
10
19
  "@angular/core": "^18.2.13",
@@ -18,6 +27,7 @@
18
27
  "@decaf-ts/decorator-validation": "^1.6.4",
19
28
  "@decaf-ts/for-http": "latest",
20
29
  "@decaf-ts/reflection": "latest",
30
+ "@decaf-ts/styles": "^0.0.3",
21
31
  "@decaf-ts/ui-decorators": "latest",
22
32
  "@ionic/angular": "^8.5.5",
23
33
  "@ngx-translate/core": "^16.0.4",
@@ -1,250 +0,0 @@
1
- import { FieldDefinition, RenderingEngine } from '@decaf-ts/ui-decorators';
2
- import { AngularDynamicOutput, AngularFieldDefinition, KeyValue } from './types';
3
- import { Constructor, Model } from '@decaf-ts/decorator-validation';
4
- import { ComponentMirror, ComponentRef, Injector, TemplateRef, Type, ViewContainerRef } from '@angular/core';
5
- /**
6
- * @description Angular implementation of the RenderingEngine with enhanced features
7
- * @summary This class extends the base RenderingEngine to provide Angular-specific rendering capabilities
8
- * with additional features compared to NgxRenderingEngine. It handles the conversion of field definitions
9
- * to Angular components, manages component registration, and provides utilities for component creation
10
- * and input handling. This implementation uses Angular's newer component APIs.
11
- *
12
- * @template AngularFieldDefinition - Type for Angular-specific field definitions
13
- * @template AngularDynamicOutput - Type for Angular-specific component output
14
- *
15
- * @class NgxRenderingEngine2
16
- * @example
17
- * ```typescript
18
- * const engine = NgxRenderingEngine2.get();
19
- * engine.initialize();
20
- * const output = engine.render(myModel, {}, viewContainerRef, injector, templateRef);
21
- * ```
22
- *
23
- * @mermaid
24
- * sequenceDiagram
25
- * participant Client
26
- * participant Engine as NgxRenderingEngine2
27
- * participant Components as RegisteredComponents
28
- *
29
- * Client->>Engine: get()
30
- * Client->>Engine: initialize()
31
- * Client->>Engine: render(model, props, vcr, injector, tpl)
32
- * Engine->>Engine: toFieldDefinition(model, props)
33
- * Engine->>Engine: fromFieldDefinition(fieldDef, vcr, injector, tpl)
34
- * Engine->>Components: components(fieldDef.tag)
35
- * Components-->>Engine: component constructor
36
- * Engine->>Engine: createComponent(component, inputs, metadata, vcr, injector, template)
37
- * Engine-->>Client: return AngularDynamicOutput
38
- */
39
- export declare class NgxRenderingEngine2 extends RenderingEngine<AngularFieldDefinition, AngularDynamicOutput> {
40
- /**
41
- * @description Registry of registered components
42
- * @summary Static registry that maps component names to their constructors.
43
- * This allows the engine to look up components by name when rendering.
44
- * @type {Record<string, { constructor: Constructor<unknown> }>}
45
- */
46
- private static _components;
47
- /**
48
- * @description Collection of child component outputs
49
- * @summary Stores the outputs of child components during rendering.
50
- * @type {AngularDynamicOutput[]}
51
- */
52
- private _childs;
53
- /**
54
- * @description Current model being rendered
55
- * @summary Reference to the model currently being processed by the rendering engine.
56
- * @type {Model}
57
- */
58
- private _model;
59
- /**
60
- * @description Static reference to the current instance
61
- * @summary Singleton instance reference for the rendering engine.
62
- * @type {Type<unknown> | undefined}
63
- */
64
- private static _instance;
65
- /**
66
- * @description Creates a new instance of NgxRenderingEngine2
67
- * @summary Initializes the rendering engine with the 'angular' engine type.
68
- * This constructor sets up the base configuration needed for Angular-specific rendering.
69
- */
70
- constructor();
71
- /**
72
- * @description Converts a field definition to an Angular component output
73
- * @summary This private method takes a field definition and creates the corresponding Angular component.
74
- * It handles component instantiation, input property mapping, and child component rendering.
75
- * The method validates input properties against the component's metadata and processes
76
- * child components recursively.
77
- *
78
- * @param {FieldDefinition<AngularFieldDefinition>} fieldDef - The field definition to convert
79
- * @param {ViewContainerRef} vcr - The view container reference for component creation
80
- * @param {Injector} injector - The Angular injector for dependency injection
81
- * @param {TemplateRef<any>} tpl - The template reference for content projection
82
- * @param {string} registryFormId - Form identifier for the component renderer
83
- * @return {AngularDynamicOutput} The Angular component output with component reference and inputs
84
- *
85
- * @mermaid
86
- * sequenceDiagram
87
- * participant Method as fromFieldDefinition
88
- * participant Components as NgxRenderingEngine2.components
89
- * participant Angular as Angular Core
90
- * participant Process as processChild
91
- *
92
- * Method->>Components: components(fieldDef.tag)
93
- * Components-->>Method: component constructor
94
- * Method->>Angular: reflectComponentType(component)
95
- * Angular-->>Method: componentMetadata
96
- * Method->>Method: Validate input properties
97
- * Method->>Method: Create result object
98
- * alt Has children
99
- * Method->>Process: Process children recursively
100
- * Process->>Method: Return processed children
101
- * Method->>Angular: Create embedded view
102
- * Method->>Method: Create component instance
103
- * end
104
- * Method-->>Caller: return AngularDynamicOutput
105
- */
106
- private fromFieldDefinition;
107
- /**
108
- * @description Creates an Angular component instance
109
- * @summary This static utility method creates an Angular component instance with the specified
110
- * inputs and template. It uses Angular's component creation API to instantiate the component
111
- * and then sets the input properties using the provided metadata.
112
- *
113
- * @param {Type<unknown>} component - The component type to create
114
- * @param {KeyValue} [inputs={}] - The input properties to set on the component
115
- * @param {ComponentMirror<unknown>} metadata - The component metadata for input validation
116
- * @param {ViewContainerRef} vcr - The view container reference for component creation
117
- * @param {Injector} injector - The Angular injector for dependency injection
118
- * @param {Node[]} [template=[]] - The template nodes to project into the component
119
- * @return {ComponentRef<unknown>} The created component reference
120
- */
121
- static createComponent(component: Type<unknown>, inputs: KeyValue | undefined, metadata: ComponentMirror<unknown>, vcr: ViewContainerRef, injector: Injector, template?: Node[]): ComponentRef<unknown>;
122
- /**
123
- * @description Extracts decorator metadata from a model
124
- * @summary This method provides access to the field definition generated from a model's
125
- * decorators. It's a convenience wrapper around the toFieldDefinition method that
126
- * converts a model to a field definition based on its decorators and the provided
127
- * global properties.
128
- *
129
- * @param {Model} model - The model to extract decorators from
130
- * @param {Record<string, unknown>} globalProps - Global properties to include in the field definition
131
- * @return {FieldDefinition<AngularFieldDefinition>} The field definition generated from the model
132
- */
133
- getDecorators(model: Model, globalProps: Record<string, unknown>): FieldDefinition<AngularFieldDefinition>;
134
- /**
135
- * @description Destroys the current engine instance
136
- * @summary This static method clears the current instance reference, effectively
137
- * destroying the singleton instance of the rendering engine. This can be used
138
- * to reset the engine state or to prepare for a new instance creation.
139
- *
140
- * @return {Promise<void>} A promise that resolves when the instance is destroyed
141
- */
142
- static destroy(): Promise<void>;
143
- /**
144
- * @description Renders a model into an Angular component output
145
- * @summary This method takes a model and converts it to an Angular component output.
146
- * It first stores a reference to the model, then converts it to a field definition
147
- * using the base RenderingEngine's toFieldDefinition method, and finally converts
148
- * that field definition to an Angular component output using fromFieldDefinition.
149
- *
150
- * @template M - Type extending Model
151
- * @param {M} model - The model to render
152
- * @param {Record<string, unknown>} globalProps - Global properties to pass to the component
153
- * @param {ViewContainerRef} vcr - The view container reference for component creation
154
- * @param {Injector} injector - The Angular injector for dependency injection
155
- * @param {TemplateRef<any>} tpl - The template reference for content projection
156
- * @return {AngularDynamicOutput} The Angular component output with component reference and inputs
157
- *
158
- * @mermaid
159
- * sequenceDiagram
160
- * participant Client as Client Code
161
- * participant Render as render method
162
- * participant ToField as toFieldDefinition
163
- * participant FromField as fromFieldDefinition
164
- *
165
- * Client->>Render: render(model, globalProps, vcr, injector, tpl)
166
- * Render->>Render: Store model reference
167
- * Render->>ToField: toFieldDefinition(model, globalProps)
168
- * ToField-->>Render: fieldDef
169
- * Render->>FromField: fromFieldDefinition(fieldDef, vcr, injector, tpl)
170
- * FromField-->>Render: AngularDynamicOutput
171
- * Render-->>Client: return AngularDynamicOutput
172
- */
173
- render<M extends Model>(model: M, globalProps: Record<string, unknown>, vcr: ViewContainerRef, injector: Injector, tpl: TemplateRef<unknown>): AngularDynamicOutput;
174
- /**
175
- * @description Initializes the rendering engine
176
- * @summary This method initializes the rendering engine. It checks if the engine is already initialized
177
- * and sets the initialized flag to true. This method is called before the engine is used
178
- * to ensure it's properly set up for rendering operations.
179
- *
180
- * @return {Promise<void>} A promise that resolves when initialization is complete
181
- */
182
- initialize(): Promise<void>;
183
- /**
184
- * @description Registers a component with the rendering engine
185
- * @summary This static method registers a component constructor with the rendering engine
186
- * under a specific name. It initializes the components registry if needed and throws
187
- * an error if a component is already registered under the same name to prevent
188
- * accidental overrides.
189
- *
190
- * @param {string} name - The name to register the component under
191
- * @param {Constructor<unknown>} constructor - The component constructor
192
- * @return {void}
193
- */
194
- static registerComponent(name: string, constructor: Constructor<unknown>): void;
195
- /**
196
- * @description Retrieves registered components from the rendering engine
197
- * @summary This static method retrieves either all registered components or a specific component
198
- * by its selector. When called without a selector, it returns an array of all registered
199
- * components. When called with a selector, it returns the specific component if found,
200
- * or throws an error if the component is not registered.
201
- *
202
- * @param {string} [selector] - Optional selector to retrieve a specific component
203
- * @return {Object|Array} Either a specific component or an array of all components
204
- */
205
- static components(selector?: string): object | string[];
206
- /**
207
- * @description Generates a key for reflection metadata
208
- * @summary This static method generates a key for reflection metadata by prefixing the input key
209
- * with the Angular engine's reflection prefix. This is used for storing and retrieving
210
- * metadata in a namespaced way to avoid conflicts with other metadata.
211
- *
212
- * @param {string} key - The base key to prefix
213
- * @return {string} The prefixed key for reflection metadata
214
- */
215
- static key(key: string): string;
216
- /**
217
- * @description Sets input properties on a component instance
218
- * @summary This static utility method sets input properties on a component instance
219
- * based on the provided inputs object and component metadata. It handles both simple
220
- * values and nested objects, recursively processing object properties. The method
221
- * validates each input against the component's metadata to ensure only valid inputs
222
- * are set.
223
- *
224
- * @param {ComponentRef<unknown>} component - The component reference to set inputs on
225
- * @param {KeyValue} inputs - The input properties to set
226
- * @param {ComponentMirror<unknown>} metadata - The component metadata for input validation
227
- * @return {void}
228
- *
229
- * @mermaid
230
- * sequenceDiagram
231
- * participant Caller
232
- * participant SetInputs as setInputs
233
- * participant Parse as parseInputValue
234
- * participant Component as ComponentRef
235
- *
236
- * Caller->>SetInputs: setInputs(component, inputs, metadata)
237
- * SetInputs->>SetInputs: Iterate through inputs
238
- * loop For each input
239
- * SetInputs->>SetInputs: Check if input exists in metadata
240
- * alt Input is 'props'
241
- * SetInputs->>Parse: parseInputValue(component, value)
242
- * Parse->>Parse: Recursively process nested objects
243
- * Parse->>Component: setInput(key, value)
244
- * else Input is valid
245
- * SetInputs->>Component: setInput(key, value)
246
- * end
247
- * end
248
- */
249
- static setInputs(component: ComponentRef<unknown>, inputs: KeyValue, metadata: ComponentMirror<unknown>): void;
250
- }