@decaf-ts/for-angular 0.0.4 → 0.0.5

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 (85) hide show
  1. package/LICENSE.md +646 -144
  2. package/README.md +37 -242
  3. package/dist/lib/README.md +92 -0
  4. package/dist/lib/assets/i18n/en.json +131 -0
  5. package/dist/lib/assets/images/angular-logo.svg +45 -0
  6. package/dist/lib/assets/images/decaf-logo-black.svg +22 -0
  7. package/dist/lib/assets/images/decaf-logo-lw.svg +50 -0
  8. package/dist/lib/assets/images/decaf-logo-white.svg +22 -0
  9. package/dist/lib/assets/images/decaf-logo.svg +54 -0
  10. package/dist/lib/components/component-renderer/component-renderer.component.d.ts +267 -0
  11. package/dist/lib/components/crud-field/crud-field.component.d.ts +447 -0
  12. package/dist/{for-angular/components/decaf-crud-form → lib/components/crud-form}/constants.d.ts +0 -0
  13. package/dist/lib/components/crud-form/crud-form.component.d.ts +102 -0
  14. package/dist/{for-angular/components/decaf-crud-form → lib/components/crud-form}/types.d.ts +0 -0
  15. package/dist/lib/components/model-renderer/model-renderer.component.d.ts +97 -0
  16. package/dist/lib/engine/DynamicModule.d.ts +17 -0
  17. package/dist/{for-angular → lib}/engine/NgxCrudFormField.d.ts +22 -14
  18. package/dist/lib/engine/NgxFormService.d.ts +167 -0
  19. package/dist/lib/engine/NgxRenderingEngine.d.ts +128 -0
  20. package/dist/lib/engine/NgxRenderingEngine2.d.ts +251 -0
  21. package/dist/lib/engine/ValidatorFactory.d.ts +15 -0
  22. package/dist/lib/engine/constants.d.ts +151 -0
  23. package/dist/lib/engine/decorators.d.ts +25 -0
  24. package/dist/lib/engine/index.d.ts +15 -0
  25. package/dist/lib/engine/types.d.ts +293 -0
  26. package/dist/lib/esm2022/components/component-renderer/component-renderer.component.mjs +309 -0
  27. package/dist/lib/esm2022/components/crud-field/crud-field.component.mjs +288 -0
  28. package/dist/lib/esm2022/components/crud-form/constants.mjs +14 -0
  29. package/dist/lib/esm2022/components/crud-form/crud-form.component.mjs +140 -0
  30. package/dist/lib/esm2022/components/crud-form/types.mjs +2 -0
  31. package/dist/lib/esm2022/components/model-renderer/model-renderer.component.mjs +137 -0
  32. package/dist/{for-angular → lib}/esm2022/decaf-ts-for-angular.mjs +0 -0
  33. package/dist/lib/esm2022/engine/DynamicModule.mjs +18 -0
  34. package/dist/lib/esm2022/engine/NgxCrudFormField.mjs +117 -0
  35. package/dist/lib/esm2022/engine/NgxFormService.mjs +315 -0
  36. package/dist/lib/esm2022/engine/NgxRenderingEngine.mjs +194 -0
  37. package/dist/lib/esm2022/engine/NgxRenderingEngine2.mjs +333 -0
  38. package/dist/lib/esm2022/engine/ValidatorFactory.mjs +102 -0
  39. package/dist/lib/esm2022/engine/constants.mjs +160 -0
  40. package/dist/lib/esm2022/engine/decorators.mjs +38 -0
  41. package/dist/lib/esm2022/engine/index.mjs +16 -0
  42. package/dist/lib/esm2022/engine/types.mjs +2 -0
  43. package/dist/lib/esm2022/for-angular.module.mjs +118 -0
  44. package/dist/lib/esm2022/interfaces.mjs +2 -0
  45. package/dist/lib/esm2022/public-apis.mjs +13 -0
  46. package/dist/lib/fesm2022/decaf-ts-for-angular.mjs +2138 -0
  47. package/dist/lib/fesm2022/decaf-ts-for-angular.mjs.map +1 -0
  48. package/dist/lib/for-angular.module.d.ts +44 -0
  49. package/dist/{for-angular → lib}/index.d.ts +0 -0
  50. package/dist/lib/interfaces.d.ts +28 -0
  51. package/dist/lib/public-apis.d.ts +12 -0
  52. package/package.json +73 -26
  53. package/dist/for-angular/README.md +0 -297
  54. package/dist/for-angular/assets/i18n/en.json +0 -21
  55. package/dist/for-angular/components/decaf-crud-field/decaf-crud-field.component.d.ts +0 -49
  56. package/dist/for-angular/components/decaf-crud-form/decaf-crud-form.component.d.ts +0 -28
  57. package/dist/for-angular/components/decaf-model-renderer/decaf-model-renderer.component.d.ts +0 -20
  58. package/dist/for-angular/engine/DynamicModule.d.ts +0 -2
  59. package/dist/for-angular/engine/NgxFormService.d.ts +0 -119
  60. package/dist/for-angular/engine/NgxRenderingEngine.d.ts +0 -18
  61. package/dist/for-angular/engine/ValidatorFactory.d.ts +0 -4
  62. package/dist/for-angular/engine/constants.d.ts +0 -13
  63. package/dist/for-angular/engine/decorators.d.ts +0 -1
  64. package/dist/for-angular/engine/index.d.ts +0 -5
  65. package/dist/for-angular/engine/types.d.ts +0 -44
  66. package/dist/for-angular/esm2022/components/decaf-crud-field/decaf-crud-field.component.mjs +0 -129
  67. package/dist/for-angular/esm2022/components/decaf-crud-form/constants.mjs +0 -14
  68. package/dist/for-angular/esm2022/components/decaf-crud-form/decaf-crud-form.component.mjs +0 -80
  69. package/dist/for-angular/esm2022/components/decaf-crud-form/types.mjs +0 -2
  70. package/dist/for-angular/esm2022/components/decaf-model-renderer/decaf-model-renderer.component.mjs +0 -47
  71. package/dist/for-angular/esm2022/engine/DynamicModule.mjs +0 -3
  72. package/dist/for-angular/esm2022/engine/NgxCrudFormField.mjs +0 -115
  73. package/dist/for-angular/esm2022/engine/NgxFormService.mjs +0 -235
  74. package/dist/for-angular/esm2022/engine/NgxRenderingEngine.mjs +0 -84
  75. package/dist/for-angular/esm2022/engine/ValidatorFactory.mjs +0 -48
  76. package/dist/for-angular/esm2022/engine/constants.mjs +0 -15
  77. package/dist/for-angular/esm2022/engine/decorators.mjs +0 -14
  78. package/dist/for-angular/esm2022/engine/index.mjs +0 -6
  79. package/dist/for-angular/esm2022/engine/types.mjs +0 -2
  80. package/dist/for-angular/esm2022/interfaces.mjs +0 -2
  81. package/dist/for-angular/esm2022/public-apis.mjs +0 -6
  82. package/dist/for-angular/fesm2022/decaf-ts-for-angular.mjs +0 -759
  83. package/dist/for-angular/fesm2022/decaf-ts-for-angular.mjs.map +0 -1
  84. package/dist/for-angular/interfaces.d.ts +0 -8
  85. package/dist/for-angular/public-apis.d.ts +0 -5
@@ -1,759 +0,0 @@
1
- import { UIKeys, RenderingEngine, HTML5CheckTypes, escapeHtml, HTML5InputTypes, parseToNumber } from '@decaf-ts/ui-decorators';
2
- import * as i0 from '@angular/core';
3
- import { reflectComponentType, TemplateRef, Component, Input, ViewChild, ElementRef, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, EventEmitter, Output } from '@angular/core';
4
- import { Model, sf, Validation, ValidationKeys } from '@decaf-ts/decorator-validation';
5
- import { NgComponentOutlet } from '@angular/common';
6
- import { apply, metadata } from '@decaf-ts/reflection';
7
- import { InternalError, OperationKeys } from '@decaf-ts/db-decorators';
8
- import { __decorate } from 'tslib';
9
- import * as i1 from '@angular/forms';
10
- import { FormGroup, FormControl, Validators, ReactiveFormsModule } from '@angular/forms';
11
- import { IonInput, IonItem, IonCheckbox, IonRadioGroup, IonRadio, IonSelect, IonSelectOption, IonTextarea } from '@ionic/angular/standalone';
12
- import { TranslatePipe } from '@ngx-translate/core';
13
- import * as i1$1 from '@ionic/angular';
14
- import { IonicModule } from '@ionic/angular';
15
-
16
- const AngularEngineKeys = {
17
- REFLECT: `${UIKeys.REFLECT}.angular.`,
18
- DYNAMIC: 'dynamic-component',
19
- ANNOTATIONS: '__annotations__',
20
- ECMP: 'ecmp',
21
- NG_REFLECT: 'ng-reflect-',
22
- RENDERED: 'rendered-as-',
23
- RENDERED_ID: 'rendered-as-{0}',
24
- };
25
- const FormConstants = {
26
- VALID: 'VALID',
27
- INVALID: 'INVALID',
28
- };
29
-
30
- class NgxRenderingEngine extends RenderingEngine {
31
- constructor() {
32
- super('angular');
33
- }
34
- fromFieldDefinition(fieldDef, vcr, injector, tpl) {
35
- const component = NgxRenderingEngine.components(fieldDef.tag)
36
- .constructor;
37
- const componentMetadata = reflectComponentType(component);
38
- if (!componentMetadata) {
39
- throw new InternalError(`Metadata for component ${fieldDef.tag} not found.`);
40
- }
41
- const inputs = fieldDef.props;
42
- const possibleInputs = componentMetadata.inputs;
43
- const inputKeys = Object.keys(inputs);
44
- for (let input of possibleInputs) {
45
- const index = inputKeys.indexOf(input.propName);
46
- if (index !== -1) {
47
- inputKeys.splice(index, 1);
48
- }
49
- if (!inputKeys.length)
50
- break;
51
- }
52
- if (inputKeys.length)
53
- console.warn(`Unmapped input properties for component ${fieldDef.tag}: ${inputKeys.join(', ')}`);
54
- const result = {
55
- component: component,
56
- inputs: inputs || {},
57
- injector: injector,
58
- };
59
- if (fieldDef.rendererId) {
60
- result.inputs['rendererId'] =
61
- fieldDef.rendererId;
62
- }
63
- if (fieldDef.children && fieldDef.children.length) {
64
- result.children = fieldDef.children.map((child) => {
65
- return this.fromFieldDefinition(child, vcr, injector, tpl);
66
- });
67
- const template = vcr.createEmbeddedView(tpl, injector).rootNodes;
68
- result.content = [template];
69
- }
70
- return result;
71
- }
72
- render(model, globalProps, vcr, injector, tpl) {
73
- let result;
74
- try {
75
- const fieldDef = this.toFieldDefinition(model, globalProps);
76
- result = this.fromFieldDefinition(fieldDef, vcr, injector, tpl);
77
- }
78
- catch (e) {
79
- throw new InternalError(`Failed to render Model ${model.constructor.name}: ${e}`);
80
- }
81
- return result;
82
- }
83
- async initialize(...args) {
84
- if (this.initialized)
85
- return;
86
- // ValidatableByType[]
87
- this.initialized = true;
88
- }
89
- static registerComponent(name, constructor) {
90
- if (!this._components)
91
- this._components = {};
92
- if (name in this._components)
93
- throw new InternalError(`Component already registered under ${name}`);
94
- this._components[name] = {
95
- constructor: constructor,
96
- };
97
- }
98
- static components(selector) {
99
- if (!selector)
100
- return Object.values(this._components);
101
- if (!(selector in this._components))
102
- throw new InternalError(`No Component registered under ${selector}`);
103
- return this._components[selector];
104
- }
105
- static key(key) {
106
- return `${AngularEngineKeys.REFLECT}${key}`;
107
- }
108
- }
109
-
110
- function Dynamic() {
111
- return apply((original) => {
112
- const metadata = reflectComponentType(original);
113
- if (!metadata)
114
- throw new InternalError(`Could not find Component metadata. @Dynamic decorator must come above @Component`);
115
- NgxRenderingEngine.registerComponent(metadata.selector, original);
116
- }, metadata(NgxRenderingEngine.key(AngularEngineKeys.DYNAMIC), true));
117
- }
118
-
119
- class DynamicModule {
120
- }
121
-
122
- class DecafModelRendererComponent {
123
- constructor(vcr, injector) {
124
- this.vcr = vcr;
125
- this.injector = injector;
126
- this.JSON = JSON;
127
- }
128
- refresh(model) {
129
- model =
130
- typeof model === 'string'
131
- ? Model.build({}, JSON.parse(model))
132
- : model;
133
- this.output = model.render(this.globals || {}, this.vcr, this.injector, this.inner);
134
- this.rendererId = sf(AngularEngineKeys.RENDERED_ID, this.output.inputs['rendererId']);
135
- }
136
- ngOnChanges(changes) {
137
- if (changes['model']) {
138
- const { currentValue, previousValue, firstChange } = changes['model'];
139
- this.refresh(currentValue);
140
- }
141
- // this.refresh();
142
- }
143
- ngOnDestroy() {
144
- this.output = undefined;
145
- }
146
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecafModelRendererComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component }); }
147
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: DecafModelRendererComponent, isStandalone: true, selector: "decaf-model-renderer", inputs: { model: "model", globals: "globals", rendererId: "rendererId" }, viewQueries: [{ propertyName: "inner", first: true, predicate: ["inner"], descendants: true, read: (TemplateRef), static: true }], usesOnChanges: true, ngImport: i0, template: "<div #renderer>\n <ng-container #outer *ngComponentOutlet=\"output?.component;\n inputs: output?.inputs;\n content: output?.content;\">\n </ng-container>\n <ng-template #inner>\n <div [id]=\"rendererId || null\">\n @for (child of output?.children; track child.inputs.name) {\n <ng-container *ngComponentOutlet=\"child.component;\n injector: child.injector;\n inputs: child.inputs\n content: child.content\">\n </ng-container>\n }\n </div>\n </ng-template>\n</div>\n\n\n", styles: [""], dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletContent", "ngComponentOutletNgModule", "ngComponentOutletNgModuleFactory"] }] }); }
148
- }
149
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecafModelRendererComponent, decorators: [{
150
- type: Component,
151
- args: [{ standalone: true, imports: [NgComponentOutlet], selector: 'decaf-model-renderer', template: "<div #renderer>\n <ng-container #outer *ngComponentOutlet=\"output?.component;\n inputs: output?.inputs;\n content: output?.content;\">\n </ng-container>\n <ng-template #inner>\n <div [id]=\"rendererId || null\">\n @for (child of output?.children; track child.inputs.name) {\n <ng-container *ngComponentOutlet=\"child.component;\n injector: child.injector;\n inputs: child.inputs\n content: child.content\">\n </ng-container>\n }\n </div>\n </ng-template>\n</div>\n\n\n" }]
152
- }], ctorParameters: () => [{ type: i0.ViewContainerRef }, { type: i0.Injector }], propDecorators: { model: [{
153
- type: Input,
154
- args: [{ required: true }]
155
- }], globals: [{
156
- type: Input
157
- }], inner: [{
158
- type: ViewChild,
159
- args: ['inner', { read: (TemplateRef), static: true }]
160
- }], rendererId: [{
161
- type: Input
162
- }] } });
163
-
164
- class ValidatorFactory {
165
- static spawn(key, arg) {
166
- if (!Validation.keys().includes(key))
167
- throw new Error('Unsupported custom validation');
168
- /**
169
- * TODO: This is only needed until the validator refacture
170
- * @param arg
171
- */
172
- const parseArgs = (arg) => {
173
- switch (key) {
174
- case ValidationKeys.REQUIRED:
175
- case ValidationKeys.EMAIL:
176
- case ValidationKeys.URL:
177
- case ValidationKeys.PASSWORD:
178
- return [];
179
- case ValidationKeys.TYPE:
180
- arg = RenderingEngine.get().translate(arg, false);
181
- }
182
- return [arg];
183
- };
184
- const validatorFn = (control) => {
185
- const validator = Validation.get(key);
186
- const value = control.value;
187
- const actualArg = parseArgs(arg);
188
- if (key === ValidationKeys.TYPE) {
189
- }
190
- let errs;
191
- try {
192
- errs = validator.hasErrors(value, ...actualArg);
193
- }
194
- catch (e) {
195
- console.warn(`${key} validator failed to validate: ${e}`);
196
- }
197
- if (!errs)
198
- return null;
199
- const result = {};
200
- result[key] = true;
201
- return result;
202
- };
203
- Object.defineProperty(validatorFn, 'name', {
204
- value: `${key}Validator`,
205
- });
206
- return validatorFn;
207
- }
208
- }
209
-
210
- /**
211
- * @summary Service for managing Angular forms and form controls.
212
- * @description
213
- * The NgxFormService provides utility methods for handling form initialization,
214
- * validation, data retrieval, and form control management in Angular applications.
215
- * It offers a centralized way to manage form controls, perform validations, and
216
- * handle form-related operations.
217
- */
218
- class NgxFormService {
219
- /**
220
- * @summary Storage for form controls.
221
- * @description
222
- * A static object that stores form controls indexed by form ID and field name.
223
- * @type {Record<string, Record<string, { control: FormGroup; props: AngularFieldDefinition }>>}
224
- */
225
- static { this.controls = {}; }
226
- // eslint-disable-next-line @typescript-eslint/no-empty-function
227
- constructor() { }
228
- /**
229
- * Initializes the form after the view has been initialized.
230
- * This method sets up the form controls and creates a FormGroup.
231
- *
232
- * @param el - The form element to initialize.
233
- * @param formId - The unique identifier for the form.
234
- * @param formUpdateMode - The update mode for the form. Defaults to 'blur'.
235
- */
236
- /**
237
- * @summary Initializes the form after view initialization.
238
- * @description
239
- * Sets up form controls and creates a FormGroup for the given form element.
240
- *
241
- * @param {FormElement} el - The form element to initialize.
242
- * @param {string} formId - The unique identifier for the form.
243
- * @param {FieldUpdateMode} [formUpdateMode='blur'] - The update mode for the form.
244
- */
245
- static formAfterViewInit(el, formId, formUpdateMode = 'blur') {
246
- const selector = `*[${AngularEngineKeys.NG_REFLECT}name]`;
247
- const elements = Array.from(el.component.nativeElement.querySelectorAll(selector));
248
- const controls = elements.map((f) => {
249
- const fieldName = f
250
- .attributes[`${AngularEngineKeys.NG_REFLECT}name`].value;
251
- const control = NgxFormService.getFieldByName(formId, fieldName);
252
- return control.control;
253
- });
254
- el.formGroup = new FormGroup(controls, {
255
- updateOn: formUpdateMode,
256
- });
257
- }
258
- /**
259
- * @summary Handles form component destruction.
260
- * @description
261
- * Unregisters the form from the service when the component is destroyed.
262
- *
263
- * @param {FormElement} el - The form element being destroyed.
264
- * @param {string} formId - The unique identifier of the form to unregister.
265
- */
266
- static forOnDestroy(el, formId) {
267
- NgxFormService.unregister(formId, el.component.nativeElement);
268
- }
269
- /**
270
- * @summary Retrieves form data for a given form ID.
271
- * @description
272
- * Processes form controls and returns their values as an object.
273
- *
274
- * @param {string} formId - The unique identifier of the form to retrieve data from.
275
- * @returns {Record<string, unknown>} An object containing the form data.
276
- * @throws {Error} If the form with the given ID is not found.
277
- */
278
- static getFormData(formId) {
279
- if (!(formId in this.controls))
280
- throw new Error(`form ${formId} not found`);
281
- const form = this.controls[formId];
282
- let control;
283
- let val;
284
- const data = {};
285
- for (const key in form) {
286
- control = form[key].control;
287
- if (!HTML5CheckTypes.includes(form[key].props.type)) {
288
- switch (form[key].props.type) {
289
- case HTML5InputTypes.NUMBER:
290
- val = parseToNumber(control.value);
291
- break;
292
- case HTML5InputTypes.DATE:
293
- case HTML5InputTypes.DATETIME_LOCAL:
294
- val = new Date(control.value[key]);
295
- break;
296
- default:
297
- val = escapeHtml(control.value[key]);
298
- }
299
- }
300
- else {
301
- val = control.value;
302
- }
303
- data[key] = val;
304
- }
305
- return data;
306
- }
307
- /**
308
- * @summary Validates form fields.
309
- * @description
310
- * Validates either a specific field or all fields in the form group.
311
- *
312
- * @param {FormGroup} formGroup - The FormGroup to validate.
313
- * @param {string} [fieldName] - Optional name of a specific field to validate.
314
- * @returns {boolean} Indicates whether the validation passed (true) or failed (false).
315
- */
316
- static validateFields(formGroup, fieldName) {
317
- function isValid(formGroup, fieldName) {
318
- const control = formGroup.get(fieldName);
319
- if (control instanceof FormControl) {
320
- control.markAsTouched();
321
- control.markAsDirty();
322
- return !control.invalid;
323
- }
324
- else {
325
- throw new Error('This should be impossible');
326
- }
327
- }
328
- if (fieldName)
329
- return isValid(formGroup, fieldName);
330
- let isValidForm = true;
331
- for (const fg of formGroup.controls) {
332
- for (const key in fg.controls) {
333
- const validate = isValid(fg, key);
334
- if (!validate)
335
- isValidForm = false;
336
- }
337
- }
338
- return isValidForm;
339
- }
340
- /**
341
- * @summary Creates a FormGroup from field properties.
342
- * @description
343
- * Generates a new FormGroup instance based on the provided field definition and update mode.
344
- *
345
- * @param {AngularFieldDefinition} props - The Angular field definition properties.
346
- * @param {FieldUpdateMode} updateMode - The update mode for the form group.
347
- * @returns {FormGroup} A new FormGroup instance.
348
- */
349
- static fromProps(props, updateMode) {
350
- const controls = {};
351
- const validators = this.validatorsFromProps(props);
352
- const composed = validators.length ? Validators.compose(validators) : null;
353
- controls[props.name] = new FormControl({
354
- value: props.value && props.type !== HTML5InputTypes.CHECKBOX
355
- ? props.value
356
- : undefined,
357
- disabled: props.disabled,
358
- }, composed);
359
- return new FormGroup(controls, { updateOn: updateMode });
360
- }
361
- /**
362
- * Retrieves a form by its ID from the stored controls.
363
- *
364
- * @param id - The unique identifier of the form to retrieve.
365
- * @returns The form controls associated with the given ID.
366
- * @throws Error if the form with the given ID is not found.
367
- */
368
- static getFormById(id) {
369
- if (!(id in NgxFormService.controls))
370
- throw new Error(`Could not find formId ${id}`);
371
- return NgxFormService.controls[id];
372
- }
373
- /**
374
- * Retrieves a specific field from a form by its name.
375
- *
376
- * @param formId - The unique identifier of the form.
377
- * @param name - The name of the field to retrieve.
378
- * @returns The field control and properties.
379
- * @throws Error if the field is not found in the form.
380
- */
381
- static getFieldByName(formId, name) {
382
- const form = NgxFormService.getFormById(formId);
383
- if (!(name in form))
384
- throw new Error(`Could not find field ${name} in form`);
385
- return form[name];
386
- }
387
- /**
388
- * Generates an array of validator functions from the provided field properties.
389
- *
390
- * @param props - The field properties containing validation rules.
391
- * @returns An array of ValidatorFn instances.
392
- */
393
- static validatorsFromProps(props) {
394
- const supportedValidationKeys = Validation.keys();
395
- return Object.keys(props)
396
- .filter((k) => supportedValidationKeys.includes(k))
397
- .map((k) => ValidatorFactory.spawn(k, props[k]));
398
- }
399
- /**
400
- *
401
- * @param el
402
- * @param tag
403
- *
404
- * @throws {Error} when no parent exists with the provided tag
405
- */
406
- static getParentEl(el, tag) {
407
- let parent;
408
- while ((parent = el.parentElement) !== null) {
409
- if (parent.tagName.toLowerCase() === tag.toLowerCase()) {
410
- return parent;
411
- }
412
- el = parent;
413
- }
414
- throw new Error(`No parent with the tag ${tag} was found for provided element`);
415
- }
416
- static register(formId, control, props) {
417
- if (formId.includes(AngularEngineKeys.RENDERED)) {
418
- formId = formId.split(AngularEngineKeys.RENDERED)[1];
419
- }
420
- this.controls[formId] = this.controls[formId] || {};
421
- this.controls[formId][props.name] = {
422
- control: control,
423
- props: props,
424
- };
425
- }
426
- /**
427
- * Unregisters a form or a specific field from the service.
428
- *
429
- * @param formId - The unique identifier of the form.
430
- * @param field - Optional. The specific field to unregister. If not provided, the entire form is unregistered.
431
- */
432
- static unregister(formId, field) {
433
- if (!field)
434
- delete this.controls[formId];
435
- else
436
- delete this.controls[formId][field.name];
437
- }
438
- }
439
-
440
- /**
441
- * @class NgxCrudFormField
442
- * @implements {CrudFormField<AngularFieldDefinition>}
443
- * @implements {ControlValueAccessor}
444
- * @summary Abstract class representing a CRUD form field for Angular applications
445
- * @description This class provides the base implementation for CRUD form fields in Angular,
446
- * implementing both CrudFormField and ControlValueAccessor interfaces.
447
- */
448
- class NgxCrudFormField {
449
- constructor() {
450
- /**
451
- * @summary String formatting function
452
- * @description Provides access to the sf function for error message formatting
453
- */
454
- this.sf = sf;
455
- /**
456
- * @summary Change callback function
457
- * @description Function called when the field value changes
458
- */
459
- this.onChange = () => { };
460
- /**
461
- * @summary Touch callback function
462
- * @description Function called when the field is touched
463
- */
464
- this.onTouch = () => { };
465
- }
466
- /**
467
- * @summary Write value to the field
468
- * @description Sets the value of the field
469
- * @param {string} obj - The value to be set
470
- */
471
- writeValue(obj) {
472
- this.value = obj;
473
- }
474
- /**
475
- * @summary Register change callback
476
- * @description Registers a function to be called when the field value changes
477
- * @param {() => unknown} fn - The function to be called on change
478
- */
479
- registerOnChange(fn) {
480
- this.onChange = fn;
481
- }
482
- /**
483
- * @summary Register touch callback
484
- * @description Registers a function to be called when the field is touched
485
- * @param {() => unknown} fn - The function to be called on touch
486
- */
487
- registerOnTouched(fn) {
488
- this.onTouch = fn;
489
- }
490
- /**
491
- * @summary Set disabled state
492
- * @description Sets the disabled state of the field
493
- * @param {boolean} isDisabled - Whether the field should be disabled
494
- */
495
- setDisabledState(isDisabled) {
496
- this.disabled = isDisabled;
497
- }
498
- /**
499
- * @summary After view initialization logic
500
- * @description Performs necessary setup after the view has been initialized
501
- * @returns {HTMLElement} The parent element of the field
502
- */
503
- afterViewInit() {
504
- let parent;
505
- switch (this.operation) {
506
- case OperationKeys.CREATE:
507
- case OperationKeys.UPDATE:
508
- case OperationKeys.DELETE:
509
- try {
510
- parent = NgxFormService.getParentEl(this.component.nativeElement, 'div');
511
- }
512
- catch (e) {
513
- throw new Error(`Unable to retrieve parent form element for the ${this.operation}: ${e instanceof Error ? e.message : e}`);
514
- }
515
- NgxFormService.register(parent.id, this.formGroup, this);
516
- return parent;
517
- default:
518
- throw new Error(`Invalid operation: ${this.operation}`);
519
- }
520
- }
521
- /**
522
- * @summary Cleanup on component destruction
523
- * @description Unregisters the field when the component is destroyed
524
- */
525
- onDestroy() {
526
- if (this.parent)
527
- NgxFormService.unregister(this.parent.id, this.component.nativeElement);
528
- }
529
- /**
530
- * @summary Initialize the field
531
- * @description Sets up the form group and field name
532
- * @param {FieldUpdateMode} updateOn - The update mode for the field
533
- */
534
- onInit(updateOn) {
535
- this.formGroup = NgxFormService.fromProps(this, updateOn);
536
- }
537
- /**
538
- * @summary Get field errors
539
- * @description Retrieves all errors associated with the field
540
- * @returns {{key: string, message: string}[]} An array of error objects
541
- */
542
- getErrors() {
543
- return Object.entries(this.formGroup.controls).reduce((accum, [prop, control]) => {
544
- Object.entries(control.errors).forEach(([k, c]) => {
545
- accum.push({ key: k, message: k });
546
- });
547
- return accum;
548
- }, []);
549
- }
550
- }
551
-
552
- let DecafCrudFieldComponent = class DecafCrudFieldComponent extends NgxCrudFormField {
553
- constructor() {
554
- super(...arguments);
555
- this.value = '';
556
- this.spellcheck = false;
557
- this.inputmode = 'none';
558
- this.autocomplete = 'off';
559
- this.fill = 'outline';
560
- this.labelPlacement = 'stacked';
561
- // Component
562
- this.updateOn = 'change';
563
- this.translatable = true;
564
- }
565
- ngAfterViewInit() {
566
- super.afterViewInit();
567
- }
568
- ngOnDestroy() {
569
- this.onDestroy();
570
- }
571
- ngOnInit() {
572
- super.onInit(this.updateOn);
573
- }
574
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecafCrudFieldComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
575
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: DecafCrudFieldComponent, isStandalone: true, selector: "decaf-crud-field", inputs: { operation: "operation", name: "name", type: "type", value: "value", disabled: "disabled", label: "label", placeholder: "placeholder", format: "format", hidden: "hidden", max: "max", maxlength: "maxlength", min: "min", minlength: "minlength", pattern: "pattern", readonly: "readonly", required: "required", step: "step", cols: "cols", rows: "rows", alignment: "alignment", checked: "checked", justify: "justify", cancelText: "cancelText", interface: "interface", options: "options", mode: "mode", spellcheck: "spellcheck", inputmode: "inputmode", autocomplete: "autocomplete", fill: "fill", labelPlacement: "labelPlacement", updateOn: "updateOn", formGroup: "formGroup", translatable: "translatable" }, viewQueries: [{ propertyName: "component", first: true, predicate: ["component"], descendants: true, read: ElementRef }], usesInheritance: true, ngImport: i0, template: "<ng-container #component [formGroup]=\"formGroup\">\n @if(type === 'textarea') {\n <ion-item>\n <ion-textarea\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [required]=\"required !== undefined ? required : null\"\n [minlength]=\"minlength !== undefined ? minlength : null\"\n [maxlength]=\"maxlength !== undefined ? maxlength : null\"\n [readonly]=\"readonly !== undefined ? readonly : null\"\n [inputmode]=\"inputmode\"\n [spellcheck]=\"spellcheck\"\n [rows]=\"rows\"\n [labelPlacement]=\"labelPlacement\"\n [value]=\"value\"\n [fill]=\"fill\"\n [placeholder]=\"translatable ? (placeholder | translate) : placeholder\"\n [formControlName]=\"name\"\n [label]=\"translatable ? (label | translate) : label\">\n </ion-textarea>\n </ion-item>\n }\n @if(type === 'checkbox') {\n <ion-item [formControlName]=\"name\">\n <ion-checkbox\n #checkboxElement\n [name]=\"name\"\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [labelPlacement]=\"labelPlacement\"\n [justify]=\"justify\"\n [disabled]=\"disabled || readonly\"\n [value]=\"value\"\n [checked]=\"checked\"\n (ionChange)=\"checked = !checked\"\n [formControlName]=\"name\">\n <span [innerHTML]=\"label | translate\"></span>\n </ion-checkbox>\n </ion-item>\n }\n @else if(type === 'radio') {\n <ion-radio-group [formControlName]=\"name\" [name]=\"name\" [value]=\"value\">\n <label class=\"radio-group-label\">{{label | translate}}</label>\n @for(option of options; track option.value) {\n <ion-item>\n <ion-radio\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [disabled]=\"readonly || disabled\"\n [labelPlacement]=\"labelPlacement\"\n [alignment]=\"alignment\"\n [justify]=\"justify\"\n [value]=\"option.value\"\n >{{ option.text | translate }}</ion-radio>\n </ion-item>\n }\n </ion-radio-group>\n }\n @else if(type === 'select') {\n <ion-item>\n <ion-select\n [name]=\"name\"\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [labelPlacement]=\"labelPlacement\"\n [cancelText]=\"cancelText | translate\"\n [label]=\"translatable ? (label | translate) : label\"\n [value]=\"value\"\n [fill]=\"fill\"\n [disabled]=\"readonly || disabled\"\n [placeholder]=\"placeholder | translate\"\n [formControlName]=\"name\"\n [interface]=\"interface\">\n @for(option of options; track option.value) {\n <ion-select-option [value]=\"option.value\">\n {{ translatable ? (option.text | translate) : option.text }}\n </ion-select-option>\n }\n </ion-select>\n </ion-item>\n }\n @else {\n <ion-item>\n <ion-input\n [type]=\"type\"\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [inputmode]=\"inputmode\"\n [autocomplete]=\"autocomplete\"\n [spellcheck]=\"spellcheck\"\n [labelPlacement]=\"labelPlacement\"\n [required]=\"required !== undefined ? required : false\"\n [minlength]=\"minlength !== undefined ? minlength : null\"\n [maxlength]=\"maxlength !== undefined ? maxlength : null\"\n [readonly]=\"readonly !== undefined ? readonly : null\"\n [max]=\"max !== undefined ? max : null\"\n [min]=\"min !== undefined ? min : null\"\n [pattern]=\"pattern !== undefined ? pattern : null\"\n [step]=\"step !== undefined ? step : null\"\n [value]=\"value\"\n [fill]=\"fill\"\n [placeholder]=\"placeholder | translate\"\n [formControlName]=\"name\"\n [label]=\"label | translate\">\n </ion-input>\n </ion-item>\n }\n @if((!formGroup.pristine || formGroup.touched) && !formGroup.valid) {\n <div class=\"error uk-flex uk-flex-top\">\n @for(item of getErrors(); track item.key) {\n <p>\n <span color=\"danger\" class=\"ti ti-alert-triangle\"></span>\n <span>{{item.key}} - {{ sf((\"errors.\" + item.message) | translate, this[item.key]) }}</span>\n </p>\n }\n </div>\n }\n</ng-container>\n", styles: [".disabled{opacity:.7;pointer-events:none;touch-action:none}.disabled *{pointer-events:none;touch-action:none}.proccessing,.proccessing *{pointer-events:none;touch-action:none;cursor:text}ion-item{--border-color: transparent;--padding-start: .75rem;--background: transparent;--background-hover-opacity: .1;--background-hover: var(--ion-color-primary);--background-activated-opacity: .15;--background-focused: var(--ion-color-primary);--background-focused-opacity: .15}ion-textarea textarea{scrollbar-width:thin!important;margin-bottom:.5rem!important}ion-select.select-label-placement-floating::part(label){line-height:1.2rem!important}.radio-group-label{margin-left:.5rem}.radio-group-label+ion-item{margin-top:.5rem}ion-checkbox{--size: 1.5rem;--checkbox-background-checked: var(--ion-color-primary);--checkmark-width: 2px}ion-checkbox::part(container){border-radius:50%;border:2px solid var(--ion-color-primary);padding:3px}ion-item+.helper,ion-radio-group+.helper{padding-left:.75rem;position:relative}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.MinLengthValidator, selector: "[minlength][formControlName],[minlength][formControl],[minlength][ngModel]", inputs: ["minlength"] }, { kind: "directive", type: i1.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i1.PatternValidator, selector: "[pattern][formControlName],[pattern][formControl],[pattern][ngModel]", inputs: ["pattern"] }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: IonInput, selector: "ion-input", inputs: ["accept", "autocapitalize", "autocomplete", "autocorrect", "autofocus", "clearInput", "clearOnEdit", "color", "counter", "counterFormatter", "debounce", "disabled", "enterkeyhint", "errorText", "fill", "helperText", "inputmode", "label", "labelPlacement", "max", "maxlength", "min", "minlength", "mode", "multiple", "name", "pattern", "placeholder", "readonly", "required", "shape", "size", "spellcheck", "step", "type", "value"] }, { kind: "component", type: IonItem, selector: "ion-item", inputs: ["button", "color", "detail", "detailIcon", "disabled", "download", "href", "lines", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonCheckbox, selector: "ion-checkbox", inputs: ["checked", "color", "disabled", "indeterminate", "justify", "labelPlacement", "mode", "name", "value"] }, { kind: "component", type: IonRadioGroup, selector: "ion-radio-group", inputs: ["allowEmptySelection", "compareWith", "name", "value"] }, { kind: "component", type: IonRadio, selector: "ion-radio", inputs: ["alignment", "color", "disabled", "justify", "labelPlacement", "mode", "name", "value"] }, { kind: "component", type: IonSelect, selector: "ion-select", inputs: ["cancelText", "color", "compareWith", "disabled", "expandedIcon", "fill", "interface", "interfaceOptions", "justify", "label", "labelPlacement", "mode", "multiple", "name", "okText", "placeholder", "selectedText", "shape", "toggleIcon", "value"] }, { kind: "pipe", type: TranslatePipe, name: "translate" }, { kind: "component", type: IonSelectOption, selector: "ion-select-option", inputs: ["disabled", "value"] }, { kind: "component", type: IonTextarea, selector: "ion-textarea", inputs: ["autoGrow", "autocapitalize", "autofocus", "clearOnEdit", "color", "cols", "counter", "counterFormatter", "debounce", "disabled", "enterkeyhint", "errorText", "fill", "helperText", "inputmode", "label", "labelPlacement", "maxlength", "minlength", "mode", "name", "placeholder", "readonly", "required", "rows", "shape", "spellcheck", "value", "wrap"] }] }); }
576
- };
577
- DecafCrudFieldComponent = __decorate([
578
- Dynamic()
579
- ], DecafCrudFieldComponent);
580
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecafCrudFieldComponent, decorators: [{
581
- type: Component,
582
- args: [{ standalone: true, imports: [
583
- ReactiveFormsModule,
584
- IonInput,
585
- IonItem,
586
- IonCheckbox,
587
- IonRadioGroup,
588
- IonRadio,
589
- IonSelect,
590
- TranslatePipe,
591
- IonSelectOption,
592
- IonTextarea,
593
- ], schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], selector: 'decaf-crud-field', template: "<ng-container #component [formGroup]=\"formGroup\">\n @if(type === 'textarea') {\n <ion-item>\n <ion-textarea\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [required]=\"required !== undefined ? required : null\"\n [minlength]=\"minlength !== undefined ? minlength : null\"\n [maxlength]=\"maxlength !== undefined ? maxlength : null\"\n [readonly]=\"readonly !== undefined ? readonly : null\"\n [inputmode]=\"inputmode\"\n [spellcheck]=\"spellcheck\"\n [rows]=\"rows\"\n [labelPlacement]=\"labelPlacement\"\n [value]=\"value\"\n [fill]=\"fill\"\n [placeholder]=\"translatable ? (placeholder | translate) : placeholder\"\n [formControlName]=\"name\"\n [label]=\"translatable ? (label | translate) : label\">\n </ion-textarea>\n </ion-item>\n }\n @if(type === 'checkbox') {\n <ion-item [formControlName]=\"name\">\n <ion-checkbox\n #checkboxElement\n [name]=\"name\"\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [labelPlacement]=\"labelPlacement\"\n [justify]=\"justify\"\n [disabled]=\"disabled || readonly\"\n [value]=\"value\"\n [checked]=\"checked\"\n (ionChange)=\"checked = !checked\"\n [formControlName]=\"name\">\n <span [innerHTML]=\"label | translate\"></span>\n </ion-checkbox>\n </ion-item>\n }\n @else if(type === 'radio') {\n <ion-radio-group [formControlName]=\"name\" [name]=\"name\" [value]=\"value\">\n <label class=\"radio-group-label\">{{label | translate}}</label>\n @for(option of options; track option.value) {\n <ion-item>\n <ion-radio\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [disabled]=\"readonly || disabled\"\n [labelPlacement]=\"labelPlacement\"\n [alignment]=\"alignment\"\n [justify]=\"justify\"\n [value]=\"option.value\"\n >{{ option.text | translate }}</ion-radio>\n </ion-item>\n }\n </ion-radio-group>\n }\n @else if(type === 'select') {\n <ion-item>\n <ion-select\n [name]=\"name\"\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [labelPlacement]=\"labelPlacement\"\n [cancelText]=\"cancelText | translate\"\n [label]=\"translatable ? (label | translate) : label\"\n [value]=\"value\"\n [fill]=\"fill\"\n [disabled]=\"readonly || disabled\"\n [placeholder]=\"placeholder | translate\"\n [formControlName]=\"name\"\n [interface]=\"interface\">\n @for(option of options; track option.value) {\n <ion-select-option [value]=\"option.value\">\n {{ translatable ? (option.text | translate) : option.text }}\n </ion-select-option>\n }\n </ion-select>\n </ion-item>\n }\n @else {\n <ion-item>\n <ion-input\n [type]=\"type\"\n [mode]=\"mode\"\n [hidden]=\"hidden\"\n [inputmode]=\"inputmode\"\n [autocomplete]=\"autocomplete\"\n [spellcheck]=\"spellcheck\"\n [labelPlacement]=\"labelPlacement\"\n [required]=\"required !== undefined ? required : false\"\n [minlength]=\"minlength !== undefined ? minlength : null\"\n [maxlength]=\"maxlength !== undefined ? maxlength : null\"\n [readonly]=\"readonly !== undefined ? readonly : null\"\n [max]=\"max !== undefined ? max : null\"\n [min]=\"min !== undefined ? min : null\"\n [pattern]=\"pattern !== undefined ? pattern : null\"\n [step]=\"step !== undefined ? step : null\"\n [value]=\"value\"\n [fill]=\"fill\"\n [placeholder]=\"placeholder | translate\"\n [formControlName]=\"name\"\n [label]=\"label | translate\">\n </ion-input>\n </ion-item>\n }\n @if((!formGroup.pristine || formGroup.touched) && !formGroup.valid) {\n <div class=\"error uk-flex uk-flex-top\">\n @for(item of getErrors(); track item.key) {\n <p>\n <span color=\"danger\" class=\"ti ti-alert-triangle\"></span>\n <span>{{item.key}} - {{ sf((\"errors.\" + item.message) | translate, this[item.key]) }}</span>\n </p>\n }\n </div>\n }\n</ng-container>\n", styles: [".disabled{opacity:.7;pointer-events:none;touch-action:none}.disabled *{pointer-events:none;touch-action:none}.proccessing,.proccessing *{pointer-events:none;touch-action:none;cursor:text}ion-item{--border-color: transparent;--padding-start: .75rem;--background: transparent;--background-hover-opacity: .1;--background-hover: var(--ion-color-primary);--background-activated-opacity: .15;--background-focused: var(--ion-color-primary);--background-focused-opacity: .15}ion-textarea textarea{scrollbar-width:thin!important;margin-bottom:.5rem!important}ion-select.select-label-placement-floating::part(label){line-height:1.2rem!important}.radio-group-label{margin-left:.5rem}.radio-group-label+ion-item{margin-top:.5rem}ion-checkbox{--size: 1.5rem;--checkbox-background-checked: var(--ion-color-primary);--checkmark-width: 2px}ion-checkbox::part(container){border-radius:50%;border:2px solid var(--ion-color-primary);padding:3px}ion-item+.helper,ion-radio-group+.helper{padding-left:.75rem;position:relative}\n"] }]
594
- }], propDecorators: { operation: [{
595
- type: Input,
596
- args: [{ required: true }]
597
- }], name: [{
598
- type: Input,
599
- args: [{ required: true }]
600
- }], type: [{
601
- type: Input,
602
- args: [{ required: true }]
603
- }], value: [{
604
- type: Input
605
- }], disabled: [{
606
- type: Input
607
- }], label: [{
608
- type: Input,
609
- args: [{ required: true }]
610
- }], placeholder: [{
611
- type: Input
612
- }], format: [{
613
- type: Input
614
- }], hidden: [{
615
- type: Input
616
- }], max: [{
617
- type: Input
618
- }], maxlength: [{
619
- type: Input
620
- }], min: [{
621
- type: Input
622
- }], minlength: [{
623
- type: Input
624
- }], pattern: [{
625
- type: Input
626
- }], readonly: [{
627
- type: Input
628
- }], required: [{
629
- type: Input
630
- }], step: [{
631
- type: Input
632
- }], cols: [{
633
- type: Input
634
- }], rows: [{
635
- type: Input
636
- }], alignment: [{
637
- type: Input
638
- }], checked: [{
639
- type: Input
640
- }], justify: [{
641
- type: Input
642
- }], cancelText: [{
643
- type: Input
644
- }], interface: [{
645
- type: Input
646
- }], options: [{
647
- type: Input
648
- }], mode: [{
649
- type: Input
650
- }], spellcheck: [{
651
- type: Input
652
- }], inputmode: [{
653
- type: Input
654
- }], autocomplete: [{
655
- type: Input
656
- }], fill: [{
657
- type: Input
658
- }], labelPlacement: [{
659
- type: Input
660
- }], updateOn: [{
661
- type: Input
662
- }], component: [{
663
- type: ViewChild,
664
- args: ['component', { read: ElementRef }]
665
- }], formGroup: [{
666
- type: Input
667
- }], translatable: [{
668
- type: Input
669
- }] } });
670
-
671
- const CssClasses = {
672
- BUTTONS_CONTAINER: 'buttons-container',
673
- };
674
- const DefaultFormReactiveOptions = {
675
- buttons: {
676
- submit: {
677
- text: 'Submit',
678
- },
679
- clear: {
680
- text: 'Clear',
681
- },
682
- },
683
- };
684
-
685
- let DecafCrudFormComponent = class DecafCrudFormComponent {
686
- constructor() {
687
- this.updateOn = 'change';
688
- this.target = '_self';
689
- this.method = 'event';
690
- this.formGroup = new FormGroup({});
691
- this.submitEvent = new EventEmitter();
692
- }
693
- ngAfterViewInit() {
694
- NgxFormService.formAfterViewInit(this, this.rendererId);
695
- }
696
- ngOnInit() {
697
- this.options = Object.assign({}, DefaultFormReactiveOptions, this.options || {});
698
- }
699
- ngOnDestroy() {
700
- NgxFormService.forOnDestroy(this, this.rendererId);
701
- }
702
- /**
703
- * @param {Event} event
704
- */
705
- submit(event) {
706
- event.preventDefault();
707
- event.stopImmediatePropagation();
708
- event.stopPropagation();
709
- if (!this.formGroup.valid)
710
- return NgxFormService.validateFields(this.formGroup);
711
- console.log('onSubmit');
712
- // fix para valores de campos radio e check
713
- const data = NgxFormService.getFormData(this.rendererId);
714
- const submitEvent = {
715
- data: data,
716
- };
717
- if (this.action)
718
- return this.component.nativeElement.dispatchEvent(new CustomEvent('submit', data));
719
- this.submitEvent.emit(submitEvent);
720
- }
721
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecafCrudFormComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
722
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: DecafCrudFormComponent, isStandalone: true, selector: "decaf-crud-form", inputs: { updateOn: "updateOn", target: "target", method: "method", options: "options", action: "action", operation: "operation", formGroup: "formGroup", rendererId: "rendererId" }, outputs: { submitEvent: "submitEvent" }, viewQueries: [{ propertyName: "component", first: true, predicate: ["reactiveForm"], descendants: true, read: ElementRef }], ngImport: i0, template: "<form #reactiveForm [id]=\"rendererId\" [formGroup]=\"formGroup\" (submit)=\"submit($event)\" [target]=\"target\">\n <ng-content #formContent></ng-content>\n <div class=\"buttons-container\">\n <ion-button\n type=\"submit\">\n<!-- [shape]=\"buttons?.submit?.shape || 'round'\"-->\n<!-- [color]=\"buttons?.submit?.color || 'primary'\"-->\n<!-- [size]=\"buttons?.submit?.size || 'default'\"-->\n<!-- [fill]=\"buttons?.submit?.fill || 'solid'\"-->\n<!-- [disabled]=\"buttons?.submit?.disabled || false\"-->\n<!-- expand=\"block\"-->\n<!-- [disabled]=\"disableSubmitButtonWhenInvalid ? !form.valid : false\"-->\n @if(options.buttons.submit.icon) {\n <ion-icon [slot]=\"options.buttons.submit.iconSlot\" [name]=\"options.buttons.submit.icon\"></ion-icon>\n }\n {{options.buttons.submit.text}}\n </ion-button>\n @if(options.buttons.clear) {\n <ion-button>\n<!-- type=\"clear\"-->\n<!-- (click)=\"clear($event)\"-->\n<!-- [shape]=\"buttons?.clear?.shape || 'round'\"-->\n<!-- [color]=\"buttons?.clear?.color || 'primary'\"-->\n<!-- [size]=\"buttons?.clear?.size || 'default'\"-->\n<!-- [fill]=\"buttons?.clear?.fill || 'clear'\"-->\n<!-- [disabled]=\"buttons?.clear?.disabled || false\"-->\n<!-- expand=\"block\"-->\n @if(options.buttons.clear?.icon) {\n <ion-icon [slot]=\"options.buttons.clear?.iconSlot\" [name]=\"options.buttons.clear?.icon\"></ion-icon>\n }\n {{options.buttons.clear?.text}}\n </ion-button>\n }\n </div>\n</form>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: IonicModule }, { kind: "component", type: i1$1.IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"] }, { kind: "component", type: i1$1.IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }] }); }
723
- };
724
- DecafCrudFormComponent = __decorate([
725
- Dynamic()
726
- ], DecafCrudFormComponent);
727
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecafCrudFormComponent, decorators: [{
728
- type: Component,
729
- args: [{ standalone: true, selector: 'decaf-crud-form', imports: [IonicModule, ReactiveFormsModule], template: "<form #reactiveForm [id]=\"rendererId\" [formGroup]=\"formGroup\" (submit)=\"submit($event)\" [target]=\"target\">\n <ng-content #formContent></ng-content>\n <div class=\"buttons-container\">\n <ion-button\n type=\"submit\">\n<!-- [shape]=\"buttons?.submit?.shape || 'round'\"-->\n<!-- [color]=\"buttons?.submit?.color || 'primary'\"-->\n<!-- [size]=\"buttons?.submit?.size || 'default'\"-->\n<!-- [fill]=\"buttons?.submit?.fill || 'solid'\"-->\n<!-- [disabled]=\"buttons?.submit?.disabled || false\"-->\n<!-- expand=\"block\"-->\n<!-- [disabled]=\"disableSubmitButtonWhenInvalid ? !form.valid : false\"-->\n @if(options.buttons.submit.icon) {\n <ion-icon [slot]=\"options.buttons.submit.iconSlot\" [name]=\"options.buttons.submit.icon\"></ion-icon>\n }\n {{options.buttons.submit.text}}\n </ion-button>\n @if(options.buttons.clear) {\n <ion-button>\n<!-- type=\"clear\"-->\n<!-- (click)=\"clear($event)\"-->\n<!-- [shape]=\"buttons?.clear?.shape || 'round'\"-->\n<!-- [color]=\"buttons?.clear?.color || 'primary'\"-->\n<!-- [size]=\"buttons?.clear?.size || 'default'\"-->\n<!-- [fill]=\"buttons?.clear?.fill || 'clear'\"-->\n<!-- [disabled]=\"buttons?.clear?.disabled || false\"-->\n<!-- expand=\"block\"-->\n @if(options.buttons.clear?.icon) {\n <ion-icon [slot]=\"options.buttons.clear?.iconSlot\" [name]=\"options.buttons.clear?.icon\"></ion-icon>\n }\n {{options.buttons.clear?.text}}\n </ion-button>\n }\n </div>\n</form>\n" }]
730
- }], propDecorators: { updateOn: [{
731
- type: Input
732
- }], component: [{
733
- type: ViewChild,
734
- args: ['reactiveForm', { static: false, read: ElementRef }]
735
- }], target: [{
736
- type: Input
737
- }], method: [{
738
- type: Input
739
- }], options: [{
740
- type: Input
741
- }], action: [{
742
- type: Input
743
- }], operation: [{
744
- type: Input,
745
- args: [{ required: true }]
746
- }], formGroup: [{
747
- type: Input
748
- }], rendererId: [{
749
- type: Input
750
- }], submitEvent: [{
751
- type: Output
752
- }] } });
753
-
754
- /**
755
- * Generated bundle index. Do not edit.
756
- */
757
-
758
- export { AngularEngineKeys, DecafCrudFieldComponent, DecafCrudFormComponent, DecafModelRendererComponent, Dynamic, DynamicModule, FormConstants, NgxRenderingEngine };
759
- //# sourceMappingURL=decaf-ts-for-angular.mjs.map