@syncfusion/ej2-angular-base 20.3.50 → 20.3.52

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