@syncfusion/ej2-angular-base 32.1.19 → 32.1.24

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.
@@ -1,171 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
2
- import { EventEmitter, ElementRef, ChangeDetectorRef } from '@angular/core';
3
- import { getValue, setValue, isNullOrUndefined, isObject } from '@syncfusion/ej2-base';
4
- import { ControlValueAccessor } from '@angular/forms';
5
- /**
6
- * Angular Form Base Module
7
- */
8
- export class FormBase<T> implements ControlValueAccessor {
9
- public value: T;
10
- public checked: boolean;
11
- private skipFromEvent: boolean;
12
- static readonly isFormBase: boolean = true;
13
-
14
- public propagateChange(_?: T): void { return; }
15
- public propagateTouch(): void { return; }
16
- public enabled: Object;
17
- public disabled: Object;
18
- public angularValue: T;
19
- private isFormInit: boolean;
20
- public objCheck: boolean;
21
- public duplicateValue: string;
22
- public duplicateAngularValue: string;
23
-
24
- public element: HTMLElement;
25
- public inputElement: HTMLInputElement;
26
- private ngEle: ElementRef;
27
- public appendTo: (ele: string | HTMLElement) => void;
28
-
29
- public focus: EventEmitter<Object>;
30
- public blur: EventEmitter<Object>;
31
- public preventChange: boolean;
32
- public isUpdated: boolean;
33
- public oldValue: any;
34
- public cdr: ChangeDetectorRef;
35
- public ngOnBlurBound: () => void;
36
- public ngOnFocusBound: () => void;
37
- public localChange(e: { value?: T, checked?: T }): void {
38
- const value: T | any = (e.checked === undefined ? e.value : e.checked);
39
- this.objCheck = isObject(value);
40
- if (this.isUpdated === true) {
41
- this.angularValue = this.oldValue;
42
- }
43
- if (this.objCheck === true) {
44
- this.duplicateValue = JSON.stringify(value);
45
- this.duplicateAngularValue = JSON.stringify(this.angularValue);
46
- if (this.duplicateValue !== this.duplicateAngularValue && this.propagateChange !== undefined && value !== undefined) {
47
- // Update angular from our control
48
- this.propagateChange(value);
49
- this.angularValue = value;
50
- }
51
- } else {
52
- if (value !== this.angularValue && this.propagateChange !== undefined && value !== undefined) {
53
- // While reset form using reset() method ng-dirty not get updated, so while value is empty just update angularValue only
54
- if (value !== '' && value !== null) {
55
- // Update angular from our control
56
- this.propagateChange(value);
57
- this.angularValue = value;
58
- } else {
59
- const optionalValue: any = value;
60
- this.propagateChange(optionalValue);
61
- this.angularValue = value;
62
- }
63
- }
64
- }
65
- this.cdr.markForCheck();
66
- }
67
-
68
- public properties: Object;
69
- public saveChanges: Function;
70
-
71
-
72
- public registerOnChange(registerFunction: (_: T) => void): void {
73
- this.propagateChange = registerFunction;
74
- }
75
-
76
- public registerOnTouched(registerFunction: () => void): void {
77
- this.propagateTouch = registerFunction;
78
- }
79
- public twoWaySetter(newVal: Object, prop: string): void {
80
- const oldVal: Object = this.oldValue || getValue(prop, this.properties);
81
- const ele: HTMLElement = this.inputElement || this.element;
82
- if (ele && oldVal === newVal && this.value === newVal &&
83
- ((<HTMLInputElement>ele).value === undefined || (<HTMLInputElement>ele).value === '')) {
84
- return;
85
- }
86
- this.saveChanges(prop, newVal, oldVal);
87
- setValue(prop, (isNullOrUndefined(newVal) ? null : newVal), this.properties);
88
- getValue(prop + 'Change', this).emit(newVal);
89
- }
90
-
91
- public ngAfterViewInit(isTempRef?: any): void {
92
- const tempFormAfterViewThis: any = isTempRef || this;
93
- // Used setTimeout for template binding
94
- // Refer Link: https://github.com/angular/angular/issues/6005
95
- // Removed setTimeout, Because we have called markForCheck() method in Angular Template Compiler
96
- /* istanbul ignore else */
97
- tempFormAfterViewThis.ngOnBlurBound = this.ngOnBlur.bind(this);
98
- tempFormAfterViewThis.ngOnFocusBound = this.ngOnFocus.bind(this);
99
- if (typeof window !== 'undefined') {
100
- if ((tempFormAfterViewThis.getModuleName()).includes('dropdowntree')) {
101
- setTimeout(function (): any {
102
- tempFormAfterViewThis.appendTo(tempFormAfterViewThis.element);
103
- });
104
- }
105
- else {
106
- tempFormAfterViewThis.appendTo(tempFormAfterViewThis.element);
107
- }
108
- const ele: HTMLElement = tempFormAfterViewThis.inputElement || tempFormAfterViewThis.element;
109
- ele.addEventListener('focus', tempFormAfterViewThis.ngOnFocusBound);
110
- ele.addEventListener('blur', tempFormAfterViewThis.ngOnBlurBound);
111
- }
112
- this.isFormInit = false;
113
- }
114
- public setDisabledState(disabled: boolean): void {
115
- this.enabled = !disabled;
116
- this.disabled = disabled;
117
- }
118
-
119
- public writeValue(value: T): void {
120
- const regExp: RegExp = /ejs-radiobutton/g;
121
- //update control value from angular
122
- if (this.checked === undefined) {
123
- this.value = value;
124
- } else {
125
- // To resolve boolean type formControl value is not working for radio button control.
126
- /* istanbul ignore next */
127
- if (this.ngEle) {
128
- if (typeof value === 'boolean') {
129
- if (regExp.test(this.ngEle.nativeElement.outerHTML)) {
130
- this.checked = value === this.value;
131
- } else {
132
- this.checked = value;
133
- }
134
- } else {
135
- this.checked = value === this.value;
136
- }
137
- }
138
- }
139
- const isNullValue: boolean = this.angularValue == null;
140
- this.angularValue = value;
141
- this.isUpdated = true;
142
- // When binding Html textbox value to syncfusion textbox, change event triggered dynamically.
143
- // To prevent change event, trigger change in component side based on `preventChange` value
144
- this.preventChange = this.isFormInit ? false : true;
145
- this.cdr.markForCheck();
146
- if (value === null) {
147
- if (isNullValue) {
148
- this.preventChange = false;
149
- }
150
- return;
151
- }
152
-
153
- }
154
-
155
- public ngOnFocus(e: Event): void {
156
- /* istanbul ignore else */
157
- if (this.skipFromEvent !== true) {
158
- this.focus.emit(e);
159
- }
160
- this.cdr.markForCheck();
161
- }
162
-
163
- public ngOnBlur(e: Event): void {
164
- this.propagateTouch();
165
- /* istanbul ignore else */
166
- if (this.skipFromEvent !== true) {
167
- this.blur.emit(e);
168
- }
169
- this.cdr.markForCheck();
170
- }
171
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Index
3
- */
4
- export * from './complex-array-base';
5
- export * from './component-base';
6
- export * from './form-base';
7
- export * from './util';
8
- export * from './template';
package/dist/ts/index.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Index
3
- */
4
- export * from './complex-array-base';
5
- export * from './component-base';
6
- export * from './form-base';
7
- export * from './util';
8
- export * from './template';
@@ -1,19 +0,0 @@
1
- import { ElementRef } from '@angular/core';
2
- /**
3
- * Angular Template Compiler
4
- *
5
- * @param {AngularElementType} templateEle - The element representing the template.
6
- * @param {Object} [helper] - Optional helper object.
7
- * @returns {Function} A function that compiles the template.
8
- */
9
- export declare function compile(templateEle: AngularElementType, helper?: Object): (data: Object | JSON, component?: any, propName?: any) => Object;
10
- /**
11
- * Property decorator for angular.
12
- *
13
- * @param {Object} [defaultValue] - Default value for the property.
14
- * @returns {PropertyDecorator} The decorator function.
15
- */
16
- export declare function Template(defaultValue?: Object): PropertyDecorator;
17
- export interface AngularElementType {
18
- elementRef: ElementRef;
19
- }
@@ -1,107 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ViewContainerRef, EmbeddedViewRef, ElementRef, TemplateRef } from '@angular/core';
3
- import { setTemplateEngine, getTemplateEngine } from '@syncfusion/ej2-base';
4
- import { setValue, getValue } from '@syncfusion/ej2-base';
5
-
6
- const stringCompiler: (template: string | Function, helper?: object) => (data: Object | JSON) => string = getTemplateEngine();
7
-
8
- /**
9
- * Angular Template Compiler
10
- *
11
- * @param {AngularElementType} templateEle - The element representing the template.
12
- * @param {Object} [helper] - Optional helper object.
13
- * @returns {Function} A function that compiles the template.
14
- */
15
- export function compile(templateEle: AngularElementType, helper?: Object):
16
-
17
- (data: Object | JSON, component?: any, propName?: any) => Object {
18
- if (typeof templateEle === 'string' || (typeof templateEle === 'function' && (templateEle as Function).prototype && (templateEle as Function).prototype.CSPTemplate)) {
19
- return stringCompiler(templateEle, helper);
20
- } else {
21
- const contRef: ViewContainerRef = templateEle.elementRef.nativeElement._viewContainerRef;
22
- const pName: string = templateEle.elementRef.nativeElement.propName;
23
- return (data: Object, component?: any, propName?: any): Object => {
24
- const context: Object = { $implicit: data };
25
- /* istanbul ignore next */
26
- const conRef: ViewContainerRef = contRef ? contRef : component.viewContainerRef;
27
- const viewRef: EmbeddedViewRef<Object> = conRef.createEmbeddedView(templateEle as TemplateRef<Object>, context);
28
- if (/EJS-MENTION|EJS-DROPDOWNLIST/.test(getValue('currentInstance.element.nodeName', conRef)) ||
29
- (/E-TABITEM/.test(getValue('element.nativeElement.nodeName', conRef)) &&
30
- getValue('currentInstance.headerTemplateRef', conRef))) {
31
- viewRef.detectChanges();
32
- } else {
33
- viewRef.markForCheck();
34
- }
35
- /* istanbul ignore next */
36
- const viewCollection: { [key: string]: EmbeddedViewRef<Object>[] } = (component && component.registeredTemplate) ?
37
- component.registeredTemplate : getValue('currentInstance.registeredTemplate', conRef);
38
- propName = (propName && component.registeredTemplate) ? propName : pName;
39
- if (typeof viewCollection[`${propName}`] === 'undefined') {
40
- viewCollection[`${propName}`] = [];
41
- }
42
- viewCollection[`${propName}`].push(viewRef);
43
- return viewRef.rootNodes;
44
- };
45
- }
46
- }
47
-
48
- /**
49
- * Property decorator for angular.
50
- *
51
- * @param {Object} [defaultValue] - Default value for the property.
52
- * @returns {PropertyDecorator} The decorator function.
53
- */
54
- export function Template(defaultValue?: Object): PropertyDecorator {
55
- return (target: Object, key: string) => {
56
- const propertyDescriptor: Object = {
57
- set: setter(key),
58
- get: getter(key, defaultValue),
59
- enumerable: true,
60
- configurable: true
61
- };
62
- Object.defineProperty(target, key, propertyDescriptor);
63
- };
64
- }
65
-
66
- /**
67
- * Creates a setter function for a given property key.
68
- *
69
- * @param {string} key - The property key.
70
- * @returns {Function} The setter function.
71
- */
72
- function setter(key: string): Function {
73
- return function (val: any): void {
74
- if (val === undefined) { return; }
75
- setValue(key + 'Ref', val, this);
76
- if (typeof val !== 'string' && !(typeof val === 'function' && (val as Function).prototype && (val as Function).prototype.CSPTemplate)) {
77
- (val as any).elementRef.nativeElement._viewContainerRef = this.viewContainerRef;
78
- (val as any).elementRef.nativeElement.propName = key;
79
- } else {
80
- if (this.saveChanges) {
81
- this.saveChanges(key, val, undefined);
82
- this.dataBind();
83
- }
84
- }
85
- };
86
- }
87
-
88
- /**
89
- * Returns a getter function for the specified key and default value.
90
- *
91
- * @param {string} key - The key for the property.
92
- * @param {Object} defaultValue - The default value for the property.
93
- * @returns {Function} The getter function.
94
- */
95
- function getter(key: string, defaultValue: Object): Function {
96
- return function (): Object {
97
- /* istanbul ignore next */
98
- return getValue(key + 'Ref', this) || defaultValue;
99
- };
100
- }
101
-
102
- export interface AngularElementType {
103
- elementRef: ElementRef;
104
- }
105
-
106
-
107
- setTemplateEngine({ compile: (compile as any) });
package/dist/ts/util.d.ts DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * Angular Utility Module
3
- *
4
- * @param {Function} derivedClass The derived class to which mixins are applied.
5
- * @param {Function[]} baseClass An array of base classes whose methods are applied as mixins.
6
- * @returns {void}
7
- */
8
- export declare function applyMixins(derivedClass: any, baseClass: any[]): void;
9
- /**
10
- * Decorator function to apply mixins to a derived class.
11
- *
12
- * @param {Function[]} baseClass - An array of mixin classes to be applied to the derived class.
13
- * @returns {ClassDecorator} The decorator function.
14
- */
15
- export declare function ComponentMixins(baseClass: Function[]): ClassDecorator;
16
- /**
17
- * Registers events.
18
- *
19
- * @private
20
- * @param {string[]} eventList - The list of events to register.
21
- * @param {any} obj - The object on which to register the events.
22
- * @param {boolean} [direct] - Whether to register events directly on the object or not.
23
- * @returns {void}
24
- */
25
- export declare function registerEvents(eventList: string[], obj: any, direct?: boolean): void;
26
- /**
27
- * Clears registered templates.
28
- *
29
- * @private
30
- * @param {any} _this - The context object.
31
- * @param {string[]} [templateNames] - Optional. An array of template names to clear.
32
- * @param {any[]} [index] - Optional. An array of indices specifying templates to clear.
33
- * @returns {void}
34
- */
35
- export declare function clearTemplate(_this: any, templateNames?: string[], index?: any): void;
36
- /**
37
- * To set value for the nameSpace in desired object.
38
- *
39
- * @param {string} nameSpace - String value to get the inner object.
40
- * @param {any} value - Value that you need to set.
41
- * @param {any} object - Object to get the inner object value.
42
- * @returns {void}
43
- * @private
44
- */
45
- export declare function setValue(nameSpace: string, value: any, object: any): any;
46
- export interface PropertyCollectionInfo {
47
- props: PropertyDetails[];
48
- complexProps: PropertyDetails[];
49
- colProps: PropertyDetails[];
50
- events: PropertyDetails[];
51
- propNames: string[];
52
- complexPropNames: string[];
53
- colPropNames: string[];
54
- eventNames: string[];
55
- }
56
- export interface PropertyDetails {
57
- propertyName: string;
58
- type: FunctionConstructor | Object;
59
- defaultValue: Object;
60
- }
package/dist/ts/util.ts DELETED
@@ -1,177 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
2
- import { EventEmitter } from '@angular/core';
3
- import { isNullOrUndefined } from '@syncfusion/ej2-base';
4
-
5
- /**
6
- * Angular Utility Module
7
- *
8
- * @param {Function} derivedClass The derived class to which mixins are applied.
9
- * @param {Function[]} baseClass An array of base classes whose methods are applied as mixins.
10
- * @returns {void}
11
- */
12
- export function applyMixins(derivedClass: any, baseClass: any[]): void {
13
- baseClass.forEach((baseClass: any) => {
14
- Object.getOwnPropertyNames(baseClass.prototype).forEach((name: string) => {
15
- if (!Object.prototype.hasOwnProperty.call(derivedClass.prototype, name) || (baseClass.isFormBase && name !== 'constructor')) {
16
- derivedClass.prototype[`${name}`] = baseClass.prototype[`${name}`];
17
- }
18
- });
19
- });
20
- }
21
-
22
- /**
23
- * Decorator function to apply mixins to a derived class.
24
- *
25
- * @param {Function[]} baseClass - An array of mixin classes to be applied to the derived class.
26
- * @returns {ClassDecorator} The decorator function.
27
- */
28
- export function ComponentMixins(baseClass: Function[]): ClassDecorator {
29
- return function (derivedClass: Function): void {
30
- applyMixins(derivedClass, baseClass);
31
- };
32
- }
33
-
34
- /**
35
- * Registers events.
36
- *
37
- * @private
38
- * @param {string[]} eventList - The list of events to register.
39
- * @param {any} obj - The object on which to register the events.
40
- * @param {boolean} [direct] - Whether to register events directly on the object or not.
41
- * @returns {void}
42
- */
43
- export function registerEvents(eventList: string[], obj: any, direct?: boolean): void {
44
- const ngEventsEmitter: { [key: string]: Object } = {};
45
- if (eventList && eventList.length) {
46
- for (const event of eventList) {
47
- if (direct === true) {
48
- obj.propCollection[`${event}`] = new EventEmitter(false);
49
- obj[`${event}`] = obj.propCollection[`${event}`];
50
- } else {
51
- ngEventsEmitter[`${event}`] = new EventEmitter(false);
52
- }
53
- }
54
- if (direct !== true) {
55
- obj.setProperties(ngEventsEmitter, true);
56
- }
57
- }
58
- }
59
-
60
- /**
61
- * Clears registered templates.
62
- *
63
- * @private
64
- * @param {any} _this - The context object.
65
- * @param {string[]} [templateNames] - Optional. An array of template names to clear.
66
- * @param {any[]} [index] - Optional. An array of indices specifying templates to clear.
67
- * @returns {void}
68
- */
69
- export function clearTemplate(_this: any, templateNames?: string[], index?: any): void {
70
- const regTemplates: string[] = Object.keys(_this.registeredTemplate);
71
- if (regTemplates.length) {
72
- /* istanbul ignore next */
73
- const regProperties: string[] = templateNames && templateNames.filter(
74
- (val: string) => {
75
- return (/\./g.test(val) ? false : true);
76
- });
77
- const tabaccordionTemp: boolean = /tab|accordion|toolbar/.test(_this.getModuleName?.());
78
- for (const registeredTemplate of (regProperties && regProperties || regTemplates)) {
79
- /* istanbul ignore next */
80
- if (index && index.length) {
81
- for (let e: number = 0; e < index.length; e++) {
82
- if (tabaccordionTemp) {
83
- for (let m: number = 0; m < _this.registeredTemplate[`${registeredTemplate}`].length; m++) {
84
- const value: any = _this.registeredTemplate[`${registeredTemplate}`][parseInt(m.toString(), 10)];
85
- if (value && value === index[`${e}`]) {
86
- value.destroy();
87
- _this.registeredTemplate[`${registeredTemplate}`].splice(m, 1);
88
- }
89
- }
90
- } else {
91
- for (let m: number = 0; m < _this.registeredTemplate.template.length; m++) {
92
- const value: any = _this.registeredTemplate.template[parseInt(m.toString(), 10)].rootNodes[0];
93
- if (value === index[`${e}`]) {
94
- const rt: any = _this.registeredTemplate[`${registeredTemplate}`];
95
- rt[parseInt(m.toString(), 10)].destroy();
96
- }
97
- }
98
- }
99
- }
100
- } else {
101
- if (_this.registeredTemplate[`${registeredTemplate}`]) {
102
- for (const rt of _this.registeredTemplate[`${registeredTemplate}`]) {
103
- if (!rt.destroyed) {
104
- if (rt._view) {
105
- const pNode: any = rt._view.renderer.parentNode(rt.rootNodes[0]);
106
- if (!isNullOrUndefined(pNode)) {
107
- for (let m: number = 0; m < rt.rootNodes.length; m++) {
108
- pNode.appendChild(rt.rootNodes[parseInt(m.toString(), 10)]);
109
- }
110
- }
111
- }
112
- rt.destroy();
113
- }
114
- }
115
- }
116
- }
117
- if (!tabaccordionTemp || !index) {
118
- delete _this.registeredTemplate[`${registeredTemplate}`];
119
- }
120
- }
121
- }
122
- for (const tagObject of _this.tagObjects) {
123
- if (tagObject.instance) {
124
- /* istanbul ignore next */
125
- tagObject.instance.clearTemplate((templateNames && templateNames.filter(
126
- (val: string) => {
127
- const regExp: RegExpConstructor = RegExp;
128
- return (new regExp(tagObject.name).test(val) ? true : false);
129
- })));
130
- }
131
- }
132
- }
133
-
134
- /**
135
- * To set value for the nameSpace in desired object.
136
- *
137
- * @param {string} nameSpace - String value to get the inner object.
138
- * @param {any} value - Value that you need to set.
139
- * @param {any} object - Object to get the inner object value.
140
- * @returns {void}
141
- * @private
142
- */
143
- export function setValue(nameSpace: string, value: any, object: any): any {
144
- const keys: string[] = nameSpace.replace(/\[/g, '.').replace(/\]/g, '').split('.');
145
- /* istanbul ignore next */
146
- let fromObj: any = object || {};
147
- for (let i: number = 0; i < keys.length; i++) {
148
- const key: string = keys[parseInt(i.toString(), 10)];
149
- if (i + 1 === keys.length) {
150
- fromObj[`${key}`] = value === undefined ? {} : value;
151
- } else if (fromObj[`${key}`] === undefined) {
152
- fromObj[`${key}`] = {};
153
- }
154
- fromObj = fromObj[`${key}`];
155
- }
156
- return fromObj;
157
- }
158
-
159
-
160
-
161
-
162
- export interface PropertyCollectionInfo {
163
- props: PropertyDetails[];
164
- complexProps: PropertyDetails[];
165
- colProps: PropertyDetails[];
166
- events: PropertyDetails[];
167
- propNames: string[];
168
- complexPropNames: string[];
169
- colPropNames: string[];
170
- eventNames: string[];
171
- }
172
-
173
- export interface PropertyDetails {
174
- propertyName: string;
175
- type: FunctionConstructor | Object;
176
- defaultValue: Object;
177
- }