1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | var componentUtil_1 = require("./componentUtil");
|
10 | var grid_1 = require("../grid");
|
11 | var registered = false;
|
12 | function initialiseAgGridWithWebComponents() {
|
13 | console.warn('ag-grid: initialiseAgGridWithWebComponents is deprecated. Please use the ag-grid-webcomponent dependency instead. ');
|
14 |
|
15 | if (registered) {
|
16 | return;
|
17 | }
|
18 | registered = true;
|
19 | if (typeof document === 'undefined' || !document.registerElement) {
|
20 | console.error('ag-Grid: unable to find document.registerElement() function, unable to initialise ag-Grid as a Web Component');
|
21 | }
|
22 |
|
23 |
|
24 | var AgileGridProto = Object.create(HTMLElement.prototype);
|
25 |
|
26 | componentUtil_1.ComponentUtil.ALL_PROPERTIES.forEach(function (key) {
|
27 | Object.defineProperty(AgileGridProto, key, {
|
28 | set: function (v) {
|
29 | this.__agGridSetProperty(key, v);
|
30 | },
|
31 | get: function () {
|
32 | return this.__agGridGetProperty(key);
|
33 | },
|
34 | enumerable: true,
|
35 | configurable: true
|
36 | });
|
37 | });
|
38 | var agGridProtoNoType = AgileGridProto;
|
39 | agGridProtoNoType.__agGridSetProperty = function (key, value) {
|
40 | if (!this.__attributes) {
|
41 | this.__attributes = {};
|
42 | }
|
43 | this.__attributes[key] = value;
|
44 |
|
45 | var changeObject = {};
|
46 | changeObject[key] = { currentValue: value };
|
47 | this.onChange(changeObject);
|
48 | };
|
49 | agGridProtoNoType.onChange = function (changes) {
|
50 | if (this._initialised) {
|
51 | componentUtil_1.ComponentUtil.processOnChange(changes, this._gridOptions, this.api, this.columnApi);
|
52 | }
|
53 | };
|
54 | agGridProtoNoType.__agGridGetProperty = function (key) {
|
55 | if (!this.__attributes) {
|
56 | this.__attributes = {};
|
57 | }
|
58 | return this.__attributes[key];
|
59 | };
|
60 | agGridProtoNoType.setGridOptions = function (options) {
|
61 | var globalEventListener = this.globalEventListener.bind(this);
|
62 | this._gridOptions = componentUtil_1.ComponentUtil.copyAttributesToGridOptions(options, this);
|
63 | var gridParams = {
|
64 | globalEventListener: globalEventListener
|
65 | };
|
66 | this._agGrid = new grid_1.Grid(this, this._gridOptions, gridParams);
|
67 | this.api = options.api;
|
68 | this.columnApi = options.columnApi;
|
69 | this._initialised = true;
|
70 | };
|
71 |
|
72 | agGridProtoNoType.createdCallback = function () {
|
73 | for (var i = 0; i < this.attributes.length; i++) {
|
74 | var attribute = this.attributes[i];
|
75 | this.setPropertyFromAttribute(attribute);
|
76 | }
|
77 | };
|
78 | agGridProtoNoType.setPropertyFromAttribute = function (attribute) {
|
79 | var name = toCamelCase(attribute.nodeName);
|
80 | var value = attribute.nodeValue;
|
81 | if (componentUtil_1.ComponentUtil.ALL_PROPERTIES.indexOf(name) >= 0) {
|
82 | this[name] = value;
|
83 | }
|
84 | };
|
85 | agGridProtoNoType.attachedCallback = function (params) { };
|
86 | agGridProtoNoType.detachedCallback = function (params) { };
|
87 | agGridProtoNoType.attributeChangedCallback = function (attributeName) {
|
88 | var attribute = this.attributes[attributeName];
|
89 | this.setPropertyFromAttribute(attribute);
|
90 | };
|
91 | agGridProtoNoType.globalEventListener = function (eventType, event) {
|
92 | var eventLowerCase = eventType.toLowerCase();
|
93 | var browserEvent = new Event(eventLowerCase);
|
94 | var browserEventNoType = browserEvent;
|
95 | browserEventNoType.agGridDetails = event;
|
96 | this.dispatchEvent(browserEvent);
|
97 | var callbackMethod = 'on' + eventLowerCase;
|
98 | if (typeof this[callbackMethod] === 'function') {
|
99 | this[callbackMethod](browserEvent);
|
100 | }
|
101 | };
|
102 |
|
103 | document.registerElement('ag-grid', { prototype: AgileGridProto });
|
104 | }
|
105 | exports.initialiseAgGridWithWebComponents = initialiseAgGridWithWebComponents;
|
106 | function toCamelCase(myString) {
|
107 | if (typeof myString === 'string') {
|
108 | var result = myString.replace(/-([a-z])/g, function (g) {
|
109 | return g[1].toUpperCase();
|
110 | });
|
111 | return result;
|
112 | }
|
113 | else {
|
114 | return myString;
|
115 | }
|
116 | }
|