@syncfusion/ej2-base 24.2.7 → 25.1.35-579988
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +2 -1
- package/CHANGELOG.md +641 -677
- package/{README.md → ReadMe.md} +100 -100
- package/dist/ej2-base.umd.min.js +1 -10
- package/dist/ej2-base.umd.min.js.map +1 -1
- package/dist/es6/ej2-base.es2015.js +178 -1025
- package/dist/es6/ej2-base.es2015.js.map +1 -1
- package/dist/es6/ej2-base.es5.js +226 -934
- package/dist/es6/ej2-base.es5.js.map +1 -1
- package/dist/global/ej2-base.min.js +1 -10
- package/dist/global/ej2-base.min.js.map +1 -1
- package/dist/global/index.d.ts +0 -9
- package/dist/ts/ajax.ts +236 -0
- package/dist/ts/animation.ts +544 -0
- package/dist/ts/base.ts +357 -0
- package/dist/ts/browser.ts +387 -0
- package/dist/ts/child-property.ts +192 -0
- package/dist/ts/component.ts +519 -0
- package/dist/ts/dom.ts +488 -0
- package/dist/ts/draggable.ts +1155 -0
- package/dist/ts/droppable.ts +172 -0
- package/dist/ts/event-handler.ts +169 -0
- package/dist/ts/internationalization.ts +369 -0
- package/dist/ts/intl/date-formatter.ts +317 -0
- package/dist/ts/intl/date-parser.ts +426 -0
- package/dist/ts/intl/intl-base.ts +1104 -0
- package/dist/ts/intl/number-formatter.ts +411 -0
- package/dist/ts/intl/number-parser.ts +158 -0
- package/dist/ts/intl/parser-base.ts +394 -0
- package/dist/ts/keyboard.ts +238 -0
- package/dist/ts/l10n.ts +94 -0
- package/dist/ts/module-loader.ts +149 -0
- package/dist/ts/notify-property-change.ts +726 -0
- package/dist/ts/observer.ts +236 -0
- package/dist/ts/sanitize-helper.ts +224 -0
- package/dist/ts/template-engine.ts +191 -0
- package/dist/ts/template.ts +329 -0
- package/dist/ts/touch.ts +544 -0
- package/dist/ts/util.ts +523 -0
- package/dist/ts/validate-lic.ts +0 -0
- package/e2e/crypto.js +16 -16
- package/e2e/m.protractor.config.js +286 -286
- package/e2e/modified-protractor/protractor.config.js +316 -316
- package/e2e/protractor.config.js +389 -332
- package/helpers/e2e/index.js +3 -3
- package/license +10 -10
- package/package.json +225 -174
- package/src/ajax.d.ts +1 -1
- package/src/ajax.js +3 -8
- package/src/animation-model.d.ts +41 -41
- package/src/animation.d.ts +6 -6
- package/src/animation.js +25 -25
- package/src/base.d.ts +2 -1
- package/src/base.js +9 -7
- package/src/component-model.d.ts +16 -16
- package/src/component.d.ts +9 -3
- package/src/component.js +50 -38
- package/src/draggable-model.d.ts +113 -113
- package/src/draggable.d.ts +2 -0
- package/src/draggable.js +45 -29
- package/src/droppable-model.d.ts +23 -23
- package/src/droppable.js +19 -19
- package/src/event-handler.js +2 -1
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -3
- package/src/intl/date-formatter.js +2 -6
- package/src/intl/date-parser.js +1 -20
- package/src/intl/intl-base.js +1 -164
- package/src/intl/number-formatter.d.ts +3 -0
- package/src/intl/number-formatter.js +7 -7
- package/src/intl/number-parser.js +1 -0
- package/src/keyboard-model.d.ts +16 -16
- package/src/keyboard.js +19 -19
- package/src/module-loader.d.ts +12 -0
- package/src/module-loader.js +11 -0
- package/src/notify-property-change.js +3 -2
- package/src/observer.js +2 -0
- package/src/sanitize-helper.js +5 -0
- package/src/template-engine.js +1 -0
- package/src/template.js +3 -2
- package/src/touch-model.d.ts +39 -39
- package/src/touch.js +19 -19
- package/src/validate-lic.d.ts +0 -11
- package/src/validate-lic.js +1 -259
- package/styles/_all.scss +2 -2
- package/styles/_bds-dark-definition.scss +15 -0
- package/styles/_bds-definition.scss +15 -0
- package/styles/_bootstrap-dark-definition.scss +42 -42
- package/styles/_bootstrap-definition.scss +42 -42
- package/styles/_bootstrap4-definition.scss +11 -11
- package/styles/_bootstrap5-dark-definition.scss +9 -9
- package/styles/_bootstrap5-definition.scss +8 -8
- package/styles/_fabric-dark-definition.scss +42 -42
- package/styles/_fabric-definition.scss +42 -42
- package/styles/_fluent-dark-definition.scss +9 -9
- package/styles/_fluent-definition.scss +9 -9
- package/styles/_fluent2-definition.scss +9 -0
- package/styles/_fusionnew-dark-definition.scss +8 -8
- package/styles/_fusionnew-definition.scss +8 -8
- package/styles/_highcontrast-definition.scss +42 -42
- package/styles/_highcontrast-light-definition.scss +42 -42
- package/styles/_material-dark-definition.scss +48 -48
- package/styles/_material-definition.scss +49 -49
- package/styles/_material3-dark-definition.scss +14 -14
- package/styles/_material3-definition.scss +15 -15
- package/styles/_tailwind-dark-definition.scss +15 -15
- package/styles/_tailwind-definition.scss +15 -15
- package/styles/animation/_all.scss +560 -560
- package/styles/bootstrap-dark.css +10 -1
- package/styles/bootstrap.css +10 -1
- package/styles/bootstrap4.css +10 -1
- package/styles/bootstrap5-dark.css +10 -1
- package/styles/bootstrap5.css +10 -1
- package/styles/common/_all.scss +2 -2
- package/styles/common/_core.scss +117 -117
- package/styles/common/_mixin.scss +9 -9
- package/styles/definition/_bds-dark.scss +1179 -0
- package/styles/definition/_bds.scss +1474 -0
- package/styles/definition/_bootstrap-dark.scss +219 -219
- package/styles/definition/_bootstrap.scss +215 -215
- package/styles/definition/_bootstrap4.scss +167 -167
- package/styles/definition/_bootstrap5-dark.scss +493 -493
- package/styles/definition/_bootstrap5.scss +494 -494
- package/styles/definition/_fabric-dark.scss +200 -200
- package/styles/definition/_fabric.scss +198 -198
- package/styles/definition/_fluent-dark.scss +557 -557
- package/styles/definition/_fluent.scss +558 -558
- package/styles/definition/_fluent2.scss +2198 -0
- package/styles/definition/_fusionnew-dark.scss +362 -362
- package/styles/definition/_fusionnew.scss +363 -363
- package/styles/definition/_highcontrast-light.scss +193 -193
- package/styles/definition/_highcontrast.scss +195 -195
- package/styles/definition/_material-dark.scss +198 -198
- package/styles/definition/_material.scss +192 -192
- package/styles/definition/_material3-dark.scss +710 -710
- package/styles/definition/_material3.scss +792 -792
- package/styles/definition/_tailwind-dark.scss +488 -488
- package/styles/definition/_tailwind.scss +485 -485
- package/styles/fabric-dark.css +10 -1
- package/styles/fabric.css +10 -1
- package/styles/fluent-dark.css +10 -1
- package/styles/fluent.css +10 -1
- package/styles/highcontrast-light.css +10 -1
- package/styles/highcontrast.css +10 -1
- package/styles/material-dark.css +10 -1
- package/styles/material.css +10 -1
- package/styles/material3-dark.css +10 -1
- package/styles/material3.css +10 -1
- package/styles/offline-theme/material-dark.css +10 -1
- package/styles/offline-theme/material.css +10 -1
- package/styles/offline-theme/tailwind-dark.css +10 -1
- package/styles/offline-theme/tailwind.css +10 -1
- package/styles/tailwind-dark.css +10 -1
- package/styles/tailwind.css +10 -1
- package/.github/PULL_REQUEST_TEMPLATE/Bug.md +0 -60
- package/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -42
- package/bin/syncfusion-license.js +0 -2
- package/dist/ej2-base.min.js +0 -10
- package/e2e/index.d.ts +0 -27
- package/src/fetch.d.ts +0 -114
- package/src/fetch.js +0 -116
- package/src/hijri-parser.d.ts +0 -19
- package/src/hijri-parser.js +0 -204
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Base } from './base';
|
|
2
|
+
import { Browser } from './browser';
|
|
3
|
+
import { isVisible, matches } from './dom';
|
|
4
|
+
import { Property, NotifyPropertyChanges, INotifyPropertyChanged, Event } from './notify-property-change';
|
|
5
|
+
import { EventHandler } from './event-handler';
|
|
6
|
+
import { compareElementParent } from './util';
|
|
7
|
+
import { DroppableModel } from './droppable-model';
|
|
8
|
+
import {Coordinates, DropInfo} from './draggable';
|
|
9
|
+
/**
|
|
10
|
+
* Droppable arguments in drop callback.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export interface DropData {
|
|
15
|
+
/**
|
|
16
|
+
* Specifies that current element can be dropped.
|
|
17
|
+
*/
|
|
18
|
+
canDrop: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Specifies target to drop.
|
|
21
|
+
*/
|
|
22
|
+
target: HTMLElement;
|
|
23
|
+
}
|
|
24
|
+
export interface DropEvents extends MouseEvent, TouchEvent {
|
|
25
|
+
dropTarget?: HTMLElement;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface for drop event args
|
|
29
|
+
*/
|
|
30
|
+
export interface DropEventArgs {
|
|
31
|
+
/**
|
|
32
|
+
* Specifies the original mouse or touch event arguments.
|
|
33
|
+
*/
|
|
34
|
+
event?: MouseEvent & TouchEvent;
|
|
35
|
+
/**
|
|
36
|
+
* Specifies the target element.
|
|
37
|
+
*/
|
|
38
|
+
target?: HTMLElement;
|
|
39
|
+
/**
|
|
40
|
+
* Specifies the dropped element.
|
|
41
|
+
*/
|
|
42
|
+
droppedElement?: HTMLElement;
|
|
43
|
+
/**
|
|
44
|
+
* Specifies the dragData
|
|
45
|
+
*/
|
|
46
|
+
dragData?: DropInfo;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Droppable Module provides support to enable droppable functionality in Dom Elements.
|
|
50
|
+
* ```html
|
|
51
|
+
* <div id='drop'>Droppable</div>
|
|
52
|
+
* <script>
|
|
53
|
+
* let ele:HTMLElement = document.getElementById('drop');
|
|
54
|
+
* var drag:Droppable = new Droppable(ele,{
|
|
55
|
+
* accept:'.drop',
|
|
56
|
+
* drop: function(e) {
|
|
57
|
+
* //drop handler code.
|
|
58
|
+
* }
|
|
59
|
+
* });
|
|
60
|
+
* </script>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
@NotifyPropertyChanges
|
|
64
|
+
export class Droppable extends Base<HTMLElement> implements INotifyPropertyChanged {
|
|
65
|
+
/**
|
|
66
|
+
* Defines the selector for draggable element to be accepted by the droppable.
|
|
67
|
+
*/
|
|
68
|
+
@Property()
|
|
69
|
+
public accept: string;
|
|
70
|
+
/**
|
|
71
|
+
* Defines the scope value to group sets of draggable and droppable items.
|
|
72
|
+
* A draggable with the same scope value will only be accepted by the droppable.
|
|
73
|
+
*/
|
|
74
|
+
@Property('default')
|
|
75
|
+
public scope: string;
|
|
76
|
+
/**
|
|
77
|
+
* Specifies the callback function, which will be triggered while drag element is dropped in droppable.
|
|
78
|
+
*
|
|
79
|
+
* @event drop
|
|
80
|
+
*/
|
|
81
|
+
@Event()
|
|
82
|
+
public drop: (args: DropEventArgs) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Specifies the callback function, which will be triggered while drag element is moved over droppable element.
|
|
85
|
+
*
|
|
86
|
+
* @event over
|
|
87
|
+
*/
|
|
88
|
+
@Event()
|
|
89
|
+
public over: Function;
|
|
90
|
+
/**
|
|
91
|
+
* Specifies the callback function, which will be triggered while drag element is moved out of droppable element.
|
|
92
|
+
*
|
|
93
|
+
* @event bind
|
|
94
|
+
*/
|
|
95
|
+
@Event()
|
|
96
|
+
public out: Function;
|
|
97
|
+
private mouseOver: boolean = false;
|
|
98
|
+
public dragData: { [key: string]: DropInfo } = {};
|
|
99
|
+
constructor(element: HTMLElement, options?: DroppableModel) {
|
|
100
|
+
super(options, element);
|
|
101
|
+
this.bind();
|
|
102
|
+
}
|
|
103
|
+
protected bind(): void {
|
|
104
|
+
this.wireEvents();
|
|
105
|
+
}
|
|
106
|
+
private wireEvents(): void {
|
|
107
|
+
EventHandler.add(this.element, Browser.isSafari() ? 'touchend' : Browser.touchEndEvent, this.intDrop, this);
|
|
108
|
+
}
|
|
109
|
+
// triggers when property changed
|
|
110
|
+
// eslint-disable-next-line
|
|
111
|
+
public onPropertyChanged(newProp: DroppableModel, oldProp: DroppableModel): void {
|
|
112
|
+
//No Code to handle
|
|
113
|
+
}
|
|
114
|
+
public getModuleName(): string {
|
|
115
|
+
return 'droppable';
|
|
116
|
+
}
|
|
117
|
+
private dragStopCalled: boolean = false;
|
|
118
|
+
public intOver(event: MouseEvent & TouchEvent, element?: Element): void {
|
|
119
|
+
if (!this.mouseOver) {
|
|
120
|
+
const drag: DropInfo = this.dragData[this.scope];
|
|
121
|
+
this.trigger('over', { event: event, target: element, dragData: drag });
|
|
122
|
+
this.mouseOver = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
public intOut(event: MouseEvent & TouchEvent, element?: Element): void {
|
|
126
|
+
if (this.mouseOver) {
|
|
127
|
+
this.trigger('out', { evt: event, target: element });
|
|
128
|
+
this.mouseOver = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
private intDrop(evt: MouseEvent & TouchEvent, element?: HTMLElement): void {
|
|
132
|
+
if (!this.dragStopCalled) {
|
|
133
|
+
return;
|
|
134
|
+
} else {
|
|
135
|
+
this.dragStopCalled = false;
|
|
136
|
+
}
|
|
137
|
+
let accept: boolean = true;
|
|
138
|
+
const drag: DropInfo = this.dragData[this.scope];
|
|
139
|
+
const isDrag: boolean = drag ? (drag.helper && isVisible(drag.helper)) : false;
|
|
140
|
+
let area: DropData;
|
|
141
|
+
if (isDrag ) {
|
|
142
|
+
area = this.isDropArea(evt, drag.helper, element);
|
|
143
|
+
if (this.accept) {
|
|
144
|
+
accept = matches(drag.helper, this.accept);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (isDrag && this.drop && area.canDrop && accept) {
|
|
148
|
+
this.trigger('drop', { event: evt, target: area.target, droppedElement: drag.helper, dragData: drag });
|
|
149
|
+
}
|
|
150
|
+
this.mouseOver = false;
|
|
151
|
+
}
|
|
152
|
+
private isDropArea(evt: MouseEvent & TouchEvent, helper: HTMLElement, element?: HTMLElement): DropData {
|
|
153
|
+
const area: DropData = { canDrop: true, target: element || (<HTMLElement>evt.target) };
|
|
154
|
+
const isTouch: boolean = evt.type === 'touchend';
|
|
155
|
+
if ( isTouch || area.target === helper) {
|
|
156
|
+
helper.style.display = 'none';
|
|
157
|
+
const coord: Coordinates = isTouch ? (evt.changedTouches[0]) : evt;
|
|
158
|
+
const ele: Element = document.elementFromPoint(coord.clientX, coord.clientY);
|
|
159
|
+
area.canDrop = false;
|
|
160
|
+
area.canDrop = compareElementParent(ele, this.element);
|
|
161
|
+
if (area.canDrop) {
|
|
162
|
+
area.target = <HTMLElement>ele;
|
|
163
|
+
}
|
|
164
|
+
helper.style.display = '';
|
|
165
|
+
}
|
|
166
|
+
return area;
|
|
167
|
+
}
|
|
168
|
+
public destroy(): void {
|
|
169
|
+
EventHandler.remove(this.element, Browser.isSafari() ? 'touchend' : Browser.touchEndEvent, this.intDrop);
|
|
170
|
+
super.destroy();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { debounce, extend } from './util';
|
|
2
|
+
import { Browser } from './browser';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* EventHandler class provides option to add, remove, clear and trigger events to a HTML DOM element
|
|
6
|
+
* ```html
|
|
7
|
+
* <div id="Eventdiv"> </div>
|
|
8
|
+
* <script>
|
|
9
|
+
* let node: HTMLElement = document.querySelector("#Eventdiv");
|
|
10
|
+
* EventHandler.addEventListener(node, "click", function(){
|
|
11
|
+
* // click handler function code
|
|
12
|
+
* });
|
|
13
|
+
* EventHandler.addEventListener(node, "onmouseover", function(){
|
|
14
|
+
* // mouseover handler function code
|
|
15
|
+
* });
|
|
16
|
+
* EventHandler.removeEventListener(node, "click", function(){
|
|
17
|
+
* // click handler function code
|
|
18
|
+
* });
|
|
19
|
+
* eventObj.clearEvents();
|
|
20
|
+
* </script>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class EventHandler {
|
|
24
|
+
|
|
25
|
+
// to get the event data based on element
|
|
26
|
+
private static addOrGetEventData(element: Element | HTMLElement | Document): EventOptions[] {
|
|
27
|
+
if ('__eventList' in element) {
|
|
28
|
+
return (<EventData>element).__eventList.events;
|
|
29
|
+
} else {
|
|
30
|
+
(<EventData>element).__eventList = {};
|
|
31
|
+
return (<EventData>element).__eventList.events = [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Add an event to the specified DOM element.
|
|
37
|
+
*
|
|
38
|
+
* @param {any} element - Target HTML DOM element
|
|
39
|
+
* @param {string} eventName - A string that specifies the name of the event
|
|
40
|
+
* @param {Function} listener - Specifies the function to run when the event occurs
|
|
41
|
+
* @param {Object} bindTo - A object that binds 'this' variable in the event handler
|
|
42
|
+
* @param {number} intDebounce - Specifies at what interval given event listener should be triggered.
|
|
43
|
+
* @returns {Function} ?
|
|
44
|
+
*/
|
|
45
|
+
public static add(
|
|
46
|
+
element: Element | HTMLElement | Document,
|
|
47
|
+
eventName: string,
|
|
48
|
+
listener: Function,
|
|
49
|
+
bindTo?: Object,
|
|
50
|
+
intDebounce?: number): Function {
|
|
51
|
+
const eventData: EventOptions[] = EventHandler.addOrGetEventData(element);
|
|
52
|
+
let debounceListener: Function;
|
|
53
|
+
if (intDebounce) {
|
|
54
|
+
debounceListener = debounce(listener, intDebounce);
|
|
55
|
+
} else {
|
|
56
|
+
debounceListener = listener;
|
|
57
|
+
}
|
|
58
|
+
if (bindTo) {
|
|
59
|
+
debounceListener = debounceListener.bind(bindTo);
|
|
60
|
+
}
|
|
61
|
+
const event: string[] = eventName.split(' ');
|
|
62
|
+
for (let i: number = 0; i < event.length; i++) {
|
|
63
|
+
eventData.push({
|
|
64
|
+
name: event[parseInt(i.toString(), 10)],
|
|
65
|
+
listener: listener,
|
|
66
|
+
debounce: debounceListener
|
|
67
|
+
});
|
|
68
|
+
if (Browser.isIE) {
|
|
69
|
+
element.addEventListener(event[parseInt(i.toString(), 10)], <EventListener>debounceListener);
|
|
70
|
+
} else {
|
|
71
|
+
element.addEventListener(event[parseInt(i.toString(), 10)], <EventListener>debounceListener, { passive: false });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return debounceListener;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Remove an event listener that has been attached before.
|
|
79
|
+
*
|
|
80
|
+
* @param {any} element - Specifies the target html element to remove the event
|
|
81
|
+
* @param {string} eventName - A string that specifies the name of the event to remove
|
|
82
|
+
* @param {Function} listener - Specifies the function to remove
|
|
83
|
+
* @returns {void} ?
|
|
84
|
+
*/
|
|
85
|
+
public static remove(element: Element | HTMLElement | Document, eventName: string, listener: Function): void {
|
|
86
|
+
const eventData: EventOptions[] = EventHandler.addOrGetEventData(element);
|
|
87
|
+
const event: string[] = eventName.split(' ');
|
|
88
|
+
for (let j: number = 0; j < event.length; j++) {
|
|
89
|
+
let index: number = -1;
|
|
90
|
+
let debounceListener: Function;
|
|
91
|
+
if (eventData && eventData.length !== 0) {
|
|
92
|
+
eventData.some((x: EventOptions, i: number) => {
|
|
93
|
+
return x.name === event[parseInt(j.toString(), 10)] && x.listener === listener ?
|
|
94
|
+
(index = i, debounceListener = x.debounce, true) : false;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (index !== -1) {
|
|
98
|
+
eventData.splice(index, 1);
|
|
99
|
+
}
|
|
100
|
+
if (debounceListener) {
|
|
101
|
+
element.removeEventListener(event[parseInt(j.toString(), 10)], <EventListener>debounceListener);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Clear all the event listeners that has been previously attached to the element.
|
|
108
|
+
*
|
|
109
|
+
* @param {any} element - Specifies the target html element to clear the events
|
|
110
|
+
* @returns {void} ?
|
|
111
|
+
*/
|
|
112
|
+
public static clearEvents(element: Element): void {
|
|
113
|
+
let eventData: EventOptions[];
|
|
114
|
+
let copyData: EventOptions[];
|
|
115
|
+
// eslint-disable-next-line
|
|
116
|
+
eventData = EventHandler.addOrGetEventData(element);
|
|
117
|
+
// eslint-disable-next-line
|
|
118
|
+
copyData = extend([], copyData, eventData) as EventOptions[];
|
|
119
|
+
for (let i: number = 0; i < copyData.length; i++) {
|
|
120
|
+
const parseValue: EventOptions = copyData[parseInt(i.toString(), 10)];
|
|
121
|
+
element.removeEventListener(<string>parseValue.name, <EventListener>parseValue.debounce);
|
|
122
|
+
eventData.shift();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Trigger particular event of the element.
|
|
128
|
+
*
|
|
129
|
+
* @param {any} element - Specifies the target html element to trigger the events
|
|
130
|
+
* @param {string} eventName - Specifies the event to trigger for the specified element.
|
|
131
|
+
* Can be a custom event, or any of the standard events.
|
|
132
|
+
* @param {any} eventProp - Additional parameters to pass on to the event properties
|
|
133
|
+
* @returns {void} ?
|
|
134
|
+
*/
|
|
135
|
+
public static trigger(element: HTMLElement, eventName: string, eventProp?: Object): void {
|
|
136
|
+
const eventData: EventOptions[] = EventHandler.addOrGetEventData(element);
|
|
137
|
+
for (const event of eventData) {
|
|
138
|
+
if (event.name === eventName) {
|
|
139
|
+
event.debounce.call(this, eventProp);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface EventData extends Element {
|
|
146
|
+
__eventList: EventList;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface EventList {
|
|
150
|
+
events?: EventOptions[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface EventOptions {
|
|
154
|
+
name: string;
|
|
155
|
+
listener: Function;
|
|
156
|
+
debounce?: Function;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Common Event argument for all base Essential JavaScript 2 Events.
|
|
161
|
+
*
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
export interface BaseEventArgs {
|
|
165
|
+
/**
|
|
166
|
+
* Specifies name of the event.
|
|
167
|
+
*/
|
|
168
|
+
name?: string;
|
|
169
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { DateFormat } from './intl/date-formatter';
|
|
2
|
+
import { NumberFormat } from './intl/number-formatter';
|
|
3
|
+
import { DateParser } from './intl/date-parser';
|
|
4
|
+
import { NumberParser } from './intl/number-parser';
|
|
5
|
+
import { IntlBase } from './intl/intl-base';
|
|
6
|
+
import { extend, getValue, isBlazor } from './util';
|
|
7
|
+
import { Observer } from './observer';
|
|
8
|
+
/**
|
|
9
|
+
* Specifies the observer used for external change detection.
|
|
10
|
+
*/
|
|
11
|
+
export const onIntlChange: Observer = new Observer();
|
|
12
|
+
/**
|
|
13
|
+
* Specifies the default rtl status for EJ2 components.
|
|
14
|
+
*/
|
|
15
|
+
export let rightToLeft: boolean = false;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Interface for dateFormatOptions
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export interface DateFormatOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Specifies the skeleton for date formatting.
|
|
24
|
+
*/
|
|
25
|
+
skeleton?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Specifies the type of date formatting either date, dateTime or time.
|
|
28
|
+
*/
|
|
29
|
+
type?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Specifies custom date formatting to be used.
|
|
32
|
+
*/
|
|
33
|
+
format?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Specifies the calendar mode other than gregorian
|
|
36
|
+
*/
|
|
37
|
+
calendar?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Enable server side date formating.
|
|
40
|
+
*/
|
|
41
|
+
isServerRendered?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Interface for numberFormatOptions
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export interface NumberFormatOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Specifies minimum fraction digits in formatted value.
|
|
50
|
+
*/
|
|
51
|
+
minimumFractionDigits?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Specifies maximum fraction digits in formatted value.
|
|
54
|
+
*/
|
|
55
|
+
maximumFractionDigits?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Specifies minimum significant digits in formatted value.
|
|
58
|
+
*/
|
|
59
|
+
minimumSignificantDigits?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Specifies maximum significant digits in formatted value.
|
|
62
|
+
*/
|
|
63
|
+
maximumSignificantDigits?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Specifies whether to use grouping or not in formatted value,
|
|
66
|
+
*/
|
|
67
|
+
useGrouping?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Specifies the skeleton for perform formatting.
|
|
70
|
+
*/
|
|
71
|
+
skeleton?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Specifies the currency code to be used for formatting.
|
|
74
|
+
*/
|
|
75
|
+
currency?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Specifies minimum integer digits in formatted value.
|
|
78
|
+
*/
|
|
79
|
+
minimumIntegerDigits?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Specifies custom number format for formatting.
|
|
82
|
+
*/
|
|
83
|
+
format?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Species which currency symbol to consider.
|
|
86
|
+
*/
|
|
87
|
+
altSymbol?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Specifies the CLDR data loaded for internationalization functionalities.
|
|
91
|
+
*
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
export const cldrData: Object = {};
|
|
95
|
+
/**
|
|
96
|
+
* Specifies the default culture value to be considered.
|
|
97
|
+
*
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
export let defaultCulture: string = 'en-US';
|
|
101
|
+
/**
|
|
102
|
+
* Specifies default currency code to be considered
|
|
103
|
+
*
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
export let defaultCurrencyCode: string = 'USD';
|
|
107
|
+
|
|
108
|
+
const mapper: string[] = ['numericObject', 'dateObject'];
|
|
109
|
+
/**
|
|
110
|
+
* Internationalization class provides support to parse and format the number and date object to the desired format.
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // To set the culture globally
|
|
113
|
+
* setCulture('en-GB');
|
|
114
|
+
*
|
|
115
|
+
* // To set currency code globally
|
|
116
|
+
* setCurrencyCode('EUR');
|
|
117
|
+
*
|
|
118
|
+
* //Load cldr data
|
|
119
|
+
* loadCldr(gregorainData);
|
|
120
|
+
* loadCldr(timeZoneData);
|
|
121
|
+
* loadCldr(numbersData);
|
|
122
|
+
* loadCldr(numberSystemData);
|
|
123
|
+
*
|
|
124
|
+
* // To use formatter in component side
|
|
125
|
+
* let Intl:Internationalization = new Internationalization();
|
|
126
|
+
*
|
|
127
|
+
* // Date formatting
|
|
128
|
+
* let dateFormatter: Function = Intl.getDateFormat({skeleton:'long',type:'dateTime'});
|
|
129
|
+
* dateFormatter(new Date('11/2/2016'));
|
|
130
|
+
* dateFormatter(new Date('25/2/2030'));
|
|
131
|
+
* Intl.formatDate(new Date(),{skeleton:'E'});
|
|
132
|
+
*
|
|
133
|
+
* //Number formatting
|
|
134
|
+
* let numberFormatter: Function = Intl.getNumberFormat({skeleton:'C5'})
|
|
135
|
+
* numberFormatter(24563334);
|
|
136
|
+
* Intl.formatNumber(123123,{skeleton:'p2'});
|
|
137
|
+
*
|
|
138
|
+
* // Date parser
|
|
139
|
+
* let dateParser: Function = Intl.getDateParser({skeleton:'short',type:'time'});
|
|
140
|
+
* dateParser('10:30 PM');
|
|
141
|
+
* Intl.parseDate('10',{skeleton:'H'});
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export class Internationalization {
|
|
145
|
+
public culture: string;
|
|
146
|
+
constructor(cultureName?: string) {
|
|
147
|
+
if (cultureName) {
|
|
148
|
+
this.culture = cultureName;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns the format function for given options.
|
|
153
|
+
*
|
|
154
|
+
* @param {DateFormatOptions} options - Specifies the format options in which the format function will return.
|
|
155
|
+
* @returns {Function} ?
|
|
156
|
+
*/
|
|
157
|
+
public getDateFormat(options?: DateFormatOptions): Function {
|
|
158
|
+
return DateFormat.dateFormat(this.getCulture(), options || { type: 'date', skeleton: 'short' }, cldrData);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the format function for given options.
|
|
162
|
+
*
|
|
163
|
+
* @param {NumberFormatOptions} options - Specifies the format options in which the format function will return.
|
|
164
|
+
* @returns {Function} ?
|
|
165
|
+
*/
|
|
166
|
+
public getNumberFormat(options?: NumberFormatOptions): Function {
|
|
167
|
+
if (options && !options.currency) {
|
|
168
|
+
options.currency = defaultCurrencyCode;
|
|
169
|
+
}
|
|
170
|
+
if (isBlazor() && options && !options.format) {
|
|
171
|
+
options.minimumFractionDigits = 0;
|
|
172
|
+
}
|
|
173
|
+
return NumberFormat.numberFormatter(this.getCulture(), options || {}, cldrData);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Returns the parser function for given options.
|
|
177
|
+
*
|
|
178
|
+
* @param {DateFormatOptions} options - Specifies the format options in which the parser function will return.
|
|
179
|
+
* @returns {Function} ?
|
|
180
|
+
*/
|
|
181
|
+
public getDateParser(options?: DateFormatOptions): Function {
|
|
182
|
+
return DateParser.dateParser(this.getCulture(), options || { skeleton: 'short', type: 'date' }, cldrData);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Returns the parser function for given options.
|
|
186
|
+
*
|
|
187
|
+
* @param {NumberFormatOptions} options - Specifies the format options in which the parser function will return.
|
|
188
|
+
* @returns {Function} ?
|
|
189
|
+
*/
|
|
190
|
+
public getNumberParser(options?: NumberFormatOptions): Function {
|
|
191
|
+
if (isBlazor() && options && !options.format) {
|
|
192
|
+
options.minimumFractionDigits = 0;
|
|
193
|
+
}
|
|
194
|
+
return NumberParser.numberParser(this.getCulture(), options || { format: 'N' }, cldrData);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns the formatted string based on format options.
|
|
198
|
+
*
|
|
199
|
+
* @param {number} value - Specifies the number to format.
|
|
200
|
+
* @param {NumberFormatOptions} option - Specifies the format options in which the number will be formatted.
|
|
201
|
+
* @returns {string} ?
|
|
202
|
+
*/
|
|
203
|
+
public formatNumber(value: number, option?: NumberFormatOptions): string {
|
|
204
|
+
return this.getNumberFormat(option)(value);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Returns the formatted date string based on format options.
|
|
208
|
+
*
|
|
209
|
+
* @param {Date} value - Specifies the number to format.
|
|
210
|
+
* @param {DateFormatOptions} option - Specifies the format options in which the number will be formatted.
|
|
211
|
+
* @returns {string} ?
|
|
212
|
+
*/
|
|
213
|
+
public formatDate(value: Date, option?: DateFormatOptions): string {
|
|
214
|
+
return this.getDateFormat(option)(value);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns the date object for given date string and options.
|
|
218
|
+
*
|
|
219
|
+
* @param {string} value - Specifies the string to parse.
|
|
220
|
+
* @param {DateFormatOptions} option - Specifies the parse options in which the date string will be parsed.
|
|
221
|
+
* @returns {Date} ?
|
|
222
|
+
*/
|
|
223
|
+
public parseDate(value: string, option?: DateFormatOptions): Date {
|
|
224
|
+
return this.getDateParser(option)(value);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Returns the number object from the given string value and options.
|
|
228
|
+
*
|
|
229
|
+
* @param {string} value - Specifies the string to parse.
|
|
230
|
+
* @param {NumberFormatOptions} option - Specifies the parse options in which the string number will be parsed.
|
|
231
|
+
* @returns {number} ?
|
|
232
|
+
*/
|
|
233
|
+
public parseNumber(value: string, option?: NumberFormatOptions): number {
|
|
234
|
+
return this.getNumberParser(option)(value);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns Native Date Time Pattern
|
|
238
|
+
*
|
|
239
|
+
* @param {DateFormatOptions} option - Specifies the parse options for resultant date time pattern.
|
|
240
|
+
* @param {boolean} isExcelFormat - Specifies format value to be converted to excel pattern.
|
|
241
|
+
* @returns {string} ?
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
public getDatePattern(option: DateFormatOptions, isExcelFormat?: boolean): string {
|
|
245
|
+
return IntlBase.getActualDateTimeFormat(this.getCulture(), option, cldrData, isExcelFormat);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns Native Number Pattern
|
|
249
|
+
*
|
|
250
|
+
* @param {NumberFormatOptions} option - Specifies the parse options for resultant number pattern.
|
|
251
|
+
* @param {boolean} isExcel ?
|
|
252
|
+
* @returns {string} ?
|
|
253
|
+
* @private
|
|
254
|
+
*/
|
|
255
|
+
public getNumberPattern(option: NumberFormatOptions, isExcel?: boolean): string {
|
|
256
|
+
return IntlBase.getActualNumberFormat(this.getCulture(), option, cldrData, isExcel);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Returns the First Day of the Week
|
|
260
|
+
*
|
|
261
|
+
* @returns {number} ?
|
|
262
|
+
*/
|
|
263
|
+
public getFirstDayOfWeek(): number {
|
|
264
|
+
return IntlBase.getWeekData(this.getCulture(), cldrData);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Returns the culture
|
|
269
|
+
*
|
|
270
|
+
* @returns {string} ?
|
|
271
|
+
*/
|
|
272
|
+
private getCulture(): string {
|
|
273
|
+
return this.culture || defaultCulture;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Set the default culture to all EJ2 components
|
|
279
|
+
*
|
|
280
|
+
* @param {string} cultureName - Specifies the culture name to be set as default culture.
|
|
281
|
+
* @returns {void} ?
|
|
282
|
+
*/
|
|
283
|
+
export function setCulture(cultureName: string): void {
|
|
284
|
+
defaultCulture = cultureName;
|
|
285
|
+
onIntlChange.notify('notifyExternalChange', { 'locale': defaultCulture });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Set the default currency code to all EJ2 components
|
|
290
|
+
*
|
|
291
|
+
* @param {string} currencyCode Specifies the culture name to be set as default culture.
|
|
292
|
+
* @returns {void} ?
|
|
293
|
+
*/
|
|
294
|
+
export function setCurrencyCode(currencyCode: string): void {
|
|
295
|
+
defaultCurrencyCode = currencyCode;
|
|
296
|
+
onIntlChange.notify('notifyExternalChange', { 'currencyCode': defaultCurrencyCode });
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Load the CLDR data into context
|
|
300
|
+
*
|
|
301
|
+
* @param {Object[]} data Specifies the CLDR data's to be used for formatting and parser.
|
|
302
|
+
* @returns {void} ?
|
|
303
|
+
*/
|
|
304
|
+
export function loadCldr(...data: Object[]): void {
|
|
305
|
+
for (const obj of data) {
|
|
306
|
+
extend(cldrData, obj, {}, true);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* To enable or disable RTL functionality for all components globally.
|
|
313
|
+
*
|
|
314
|
+
* @param {boolean} status - Optional argument Specifies the status value to enable or disable rtl option.
|
|
315
|
+
* @returns {void} ?
|
|
316
|
+
*/
|
|
317
|
+
export function enableRtl(status: boolean = true): void {
|
|
318
|
+
rightToLeft = status;
|
|
319
|
+
onIntlChange.notify('notifyExternalChange', { enableRtl: rightToLeft });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* To get the numeric CLDR object for given culture
|
|
324
|
+
*
|
|
325
|
+
* @param {string} locale - Specifies the locale for which numericObject to be returned.
|
|
326
|
+
* @param {string} type ?
|
|
327
|
+
* @returns {Object} ?
|
|
328
|
+
* @ignore
|
|
329
|
+
* @private
|
|
330
|
+
*/
|
|
331
|
+
export function getNumericObject(locale: string, type?: string): Object {
|
|
332
|
+
// eslint-disable-next-line
|
|
333
|
+
let numObject: Object = (<any>IntlBase.getDependables(cldrData, locale, '', true))[mapper[0]];
|
|
334
|
+
// eslint-disable-next-line
|
|
335
|
+
const dateObject: Object = (<any>IntlBase.getDependables(cldrData, locale, ''))[mapper[1]];
|
|
336
|
+
const numSystem: string = getValue('defaultNumberingSystem', numObject);
|
|
337
|
+
const symbPattern: Object = isBlazor() ? getValue('numberSymbols', numObject) : getValue('symbols-numberSystem-' + numSystem, numObject);
|
|
338
|
+
const pattern: string = IntlBase.getSymbolPattern(type || 'decimal', numSystem, numObject, false);
|
|
339
|
+
return extend(symbPattern, IntlBase.getFormatData(pattern, true, '', true), { 'dateSeparator': IntlBase.getDateSeparator(dateObject) });
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* To get the numeric CLDR number base object for given culture
|
|
344
|
+
*
|
|
345
|
+
* @param {string} locale - Specifies the locale for which numericObject to be returned.
|
|
346
|
+
* @param {string} currency - Specifies the currency for which numericObject to be returned.
|
|
347
|
+
* @returns {string} ?
|
|
348
|
+
* @ignore
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
351
|
+
export function getNumberDependable(locale: string, currency: string): string {
|
|
352
|
+
// eslint-disable-next-line
|
|
353
|
+
const numObject: Object = (<any>IntlBase.getDependables(cldrData, locale, '', true));
|
|
354
|
+
// eslint-disable-next-line
|
|
355
|
+
return IntlBase.getCurrencySymbol((<any>numObject).numericObject, currency);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* To get the default date CLDR object.
|
|
360
|
+
*
|
|
361
|
+
* @param {string} mode ?
|
|
362
|
+
* @returns {Object} ?
|
|
363
|
+
* @ignore
|
|
364
|
+
* @private
|
|
365
|
+
*/
|
|
366
|
+
export function getDefaultDateObject(mode?: string): Object {
|
|
367
|
+
// eslint-disable-next-line
|
|
368
|
+
return (<any>IntlBase.getDependables(cldrData, '', mode, false))[mapper[1]];
|
|
369
|
+
}
|