ag-grid-aurelia-plugin 31.3.4

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/README.md ADDED
@@ -0,0 +1,83 @@
1
+ ag-Grid Aurelia Component
2
+ ==============
3
+
4
+ This project contains the Aurelia Component for use with ag-Grid.
5
+
6
+ Usage
7
+ ==============
8
+
9
+ Please refer to www.ag-grid.com for full documentation on ag-Grid and Aurelia integration. Also take a look a the provided examples at https://github.com/ag-grid/ag-grid-aurelia-example.
10
+
11
+ Frameworks Supported
12
+ ====================
13
+ Framework specific Getting Started guides:
14
+ [Angular 1](https://www.ag-grid.com/best-angularjs-data-grid/) | [Angular 2](https://www.ag-grid.com/best-angular-2-data-grid/) | [Aurelia](https://www.ag-grid.com/best-aurelia-data-grid/)
15
+ [Javascript](https://www.ag-grid.com/best-javascript-data-grid/) | [React](https://www.ag-grid.com/best-react-data-grid/) | [TypeScript](https://www.ag-grid.com/ag-grid-typescript-webpack-2/)
16
+ [VueJS](https://www.ag-grid.com/best-vuejs-data-grid/) | [Web Components](https://www.ag-grid.com/best-web-component-data-grid/)
17
+
18
+ In your main entry.
19
+ ```
20
+ aurelia.use
21
+ .standardConfiguration()
22
+ .plugin('ag-grid-aurelia');
23
+ ```
24
+
25
+ In your view model
26
+ ```
27
+ import {GridOptions} from 'ag-grid';
28
+ export class MyGridPage {
29
+
30
+ public gridOptions:GridOptions;
31
+
32
+ constructor() {
33
+ this.gridOptions = <GridOptions>{};
34
+ this.gridOptions.rowData = [{id: 1, name: 'Shane'}, {id: 2, name: 'Sean'}];
35
+ }
36
+
37
+ public onGridReady(){
38
+ console.log('Grid is ready!!');
39
+ console.log('1st col field = ' + this.gridOptions.columnDefs[0].field);
40
+ }
41
+
42
+ public onIdClicked(row){
43
+ console.log('id clicked ' + row.id);
44
+ }
45
+ }
46
+
47
+
48
+ ```
49
+ In your view template. Here we are adding columns using markup. ColumnDefs can be added from your view model if you wish.
50
+ ```
51
+ <template>
52
+ <div style="width: 100%; height: 350px;">
53
+ <ag-grid-aurelia grid-options.bind="gridOptions" class="ag-material"
54
+ row-height.bind="48"
55
+ grid-ready.call="onGridReady()">
56
+ <ag-grid-column header-name="My Group Column">
57
+ <ag-grid-column header-name="Id" field="id">
58
+ <ag-cell-template>
59
+ <button md-button class="btn accent" click.delegate="params.context.onIdClicked(params.data)">${params.value}</button>
60
+ </ag-cell-template>
61
+ </ag-grid-column>
62
+ <ag-grid-column header-name="Name" field="name" >
63
+ </ag-grid-column>
64
+ </ag-grid-column>
65
+
66
+ </ag-grid-aurelia>
67
+ </div>
68
+
69
+ </template>
70
+ ```
71
+
72
+ Building
73
+ ==============
74
+
75
+ To build:
76
+ - npm install
77
+ - npm install gulp -g
78
+ - npm install aurelia-framework
79
+ - npm install ag-grid
80
+ - (or: npm install aurelia-framework@1.0.x && npm install ag-grid@13.0.2)
81
+
82
+ - npm run build
83
+ # ag-grid-aurelia1
package/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './lib/agGridAurelia';
2
+ export * from './lib/agGridColumn';
3
+ export * from './lib/agTemplate';
4
+ export * from './lib/aureliaFrameworkFactory';
package/main.js ADDED
@@ -0,0 +1,19 @@
1
+ var PLATFORM = require('aurelia-pal').PLATFORM;
2
+
3
+ exports.AgGridAurelia = require('./lib/agGridAurelia').AgGridAurelia;
4
+ exports.AgGridColumn = require('./lib/agGridColumn').AgGridColumn;
5
+ exports.AgCellTemplate = require('./lib/agTemplate').AgCellTemplate;
6
+ exports.AgEditorTemplate = require('./lib/agTemplate').AgEditorTemplate;
7
+ exports.AgFullWidthRowTemplate = require('./lib/agTemplate').AgFullWidthRowTemplate;
8
+ exports.AgFilterTemplate = require('./lib/agTemplate').AgFilterTemplate;
9
+ exports.AureliaFrameworkFactory = require('./lib/aureliaFrameworkFactory').AureliaFrameworkFactory;
10
+
11
+ function configure(config) {
12
+ config.globalResources(
13
+ PLATFORM.moduleName('./lib/agGridAurelia'),
14
+ PLATFORM.moduleName('./lib/agGridColumn'),
15
+ PLATFORM.moduleName('./lib/agTemplate')
16
+ );
17
+ }
18
+
19
+ exports.configure = configure;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "ag-grid-aurelia-plugin",
3
+ "version": "31.3.4",
4
+ "description": "ag-Grid Aurelia Component, a fork of Niall Crosby <niall.crosby@gmail.com>",
5
+ "credits": "Niall Crosby <niall.crosby@gmail.com>",
6
+ "main": "./main.js",
7
+ "typings": "./main.d.ts",
8
+ "scripts": {
9
+ "clean": "rimraf lib",
10
+ "build": "npm run clean && npm run compile && npm run add-headers",
11
+ "compile": "tsc",
12
+ "add-headers": "node scripts/add-headers.js",
13
+ "watch": "tsc --watch"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/ag-grid/ag-grid.git"
18
+ },
19
+ "keywords": [
20
+ "grid",
21
+ "data",
22
+ "table",
23
+ "aurelia"
24
+ ],
25
+ "author": "Vladimir Varbanov <vlado.var@gmail.com>",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/ag-grid/ag-grid/issues"
29
+ },
30
+ "homepage": "http://www.ag-grid.com/",
31
+ "devDependencies": {
32
+ "@types/core-js": "^2.5.0",
33
+ "ag-grid-community": "^31.3.4",
34
+ "aurelia-framework": "1.x",
35
+ "reflect-metadata": "^0.1.12",
36
+ "rimraf": "^6.0.1",
37
+ "systemjs": "^6.15.1",
38
+ "typescript": "~5.6.0"
39
+ },
40
+ "peerDependencies": {
41
+ "ag-grid-community": "^31.3.4",
42
+ "aurelia-framework": "1.x"
43
+ },
44
+ "aurelia": {
45
+ "build": {
46
+ "resources": [
47
+ "ag-grid-aurelia/lib/agGridAurelia",
48
+ "ag-grid-aurelia/lib/agGridColumn",
49
+ "ag-grid-aurelia/lib/agTemplate"
50
+ ]
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const pkg = require('../package.json');
6
+
7
+ const headerTemplate = `// ${pkg.name} v${pkg.version}\n`;
8
+ const libDir = 'lib';
9
+
10
+ function addHeaderToFiles() {
11
+ if (!fs.existsSync(libDir)) {
12
+ console.error(`Directory ${libDir} does not exist`);
13
+ return;
14
+ }
15
+
16
+ const files = fs.readdirSync(libDir);
17
+
18
+ files.forEach(file => {
19
+ if (file.endsWith('.js') || file.endsWith('.d.ts')) {
20
+ const filePath = path.join(libDir, file);
21
+ const content = fs.readFileSync(filePath, 'utf8');
22
+
23
+ // Only add header if it doesn't already exist
24
+ if (!content.startsWith('//')) {
25
+ const newContent = headerTemplate + content;
26
+ fs.writeFileSync(filePath, newContent, 'utf8');
27
+ console.log(`Added header to ${file}`);
28
+ }
29
+ }
30
+ });
31
+ }
32
+
33
+ addHeaderToFiles();
@@ -0,0 +1,163 @@
1
+ import type {
2
+ GridOptions,
3
+ GridParams
4
+ } from "ag-grid-community";
5
+ import {
6
+ ColumnApi,
7
+ ComponentUtil,
8
+ Grid,
9
+ GridApi
10
+ } from "ag-grid-community";
11
+ import {
12
+ ComponentAttached,
13
+ ComponentDetached,
14
+ bindable,
15
+ child,
16
+ children,
17
+ Container,
18
+ customElement,
19
+ inlineView,
20
+ TaskQueue,
21
+ ViewResources
22
+ } from "aurelia-framework";
23
+ import {AureliaFrameworkFactory} from "./aureliaFrameworkFactory";
24
+ import {AgGridColumn} from "./agGridColumn";
25
+ import {generateBindables} from "./agUtils";
26
+ import {AgDateTemplate, AgFullWidthRowTemplate} from './agTemplate';
27
+ import {AureliaFrameworkComponentWrapper} from "./aureliaFrameworkComponentWrapper";
28
+
29
+ interface IPropertyChanges {
30
+ [key: string]: any
31
+ }
32
+
33
+ @customElement('ag-grid-aurelia')
34
+ @generateBindables(ComponentUtil.ALL_PROPERTIES.filter((property) => property !== 'gridOptions' as any))
35
+ @generateBindables(ComponentUtil.EVENTS)
36
+ // <slot> is required for @children to work. https://github.com/aurelia/templating/issues/451#issuecomment-254206622
37
+ @inlineView(`<template><slot></slot></template>`)
38
+ export class AgGridAurelia implements ComponentAttached, ComponentDetached {
39
+ // not intended for user to interact with. so putting _ in so if user gets reference
40
+ // to this object, they kind'a know it's not part of the agreed interface
41
+ private _nativeElement: any;
42
+ private _initialised = false;
43
+ private _destroyed = false;
44
+
45
+ @bindable() public gridOptions: GridOptions;
46
+ @bindable() public context: any;
47
+
48
+ private gridParams: GridParams;
49
+
50
+ // making these public, so they are accessible to people using the aurelia component references
51
+ public api: GridApi;
52
+ public columnApi: ColumnApi;
53
+
54
+ @children('ag-grid-column')
55
+ public columns: AgGridColumn[] = [];
56
+
57
+ @child('ag-full-width-row-template')
58
+ public fullWidthRowTemplate: AgFullWidthRowTemplate;
59
+
60
+ @child('ag-date-template')
61
+ public dateTemplate: AgDateTemplate;
62
+
63
+ constructor(element: Element,
64
+ private taskQueue: TaskQueue,
65
+ private auFrameworkFactory: AureliaFrameworkFactory,
66
+ private container: Container,
67
+ private viewResources: ViewResources,
68
+ private aureliaFrameworkComponentWrapper: AureliaFrameworkComponentWrapper) {
69
+ this._nativeElement = element;
70
+ // create all the events generically. this is done generically so that
71
+ // if the list of grid events change, we don't need to change this code.
72
+ ComponentUtil.EVENTS.forEach((eventName) => {
73
+ //create an empty event
74
+ (<any>this)[eventName] = () => {
75
+ };
76
+ });
77
+ }
78
+
79
+ attached() {
80
+ // initialize the grid in the queue
81
+ // because of bug in @children
82
+ // https://github.com/aurelia/templating/issues/403
83
+ this.taskQueue.queueTask(this.initGrid.bind(this));
84
+ }
85
+
86
+ initGrid(): void {
87
+ this._initialised = false;
88
+ this._destroyed = false;
89
+
90
+ this.auFrameworkFactory.setContainer(this.container);
91
+ this.auFrameworkFactory.setViewResources(this.viewResources);
92
+
93
+ this.aureliaFrameworkComponentWrapper.setContainer(this.container);
94
+ this.aureliaFrameworkComponentWrapper.setViewResources(this.viewResources);
95
+
96
+ this.gridParams = <any>{
97
+ globalEventListener: this.globalEventListener.bind(this),
98
+ frameworkFactory: this.auFrameworkFactory,
99
+ seedBeanInstances: {
100
+ frameworkComponentWrapper: this.aureliaFrameworkComponentWrapper
101
+ }
102
+ };
103
+
104
+ if (this.columns && this.columns.length > 0) {
105
+ this.gridOptions.columnDefs = this.columns
106
+ .map((column: AgGridColumn) => {
107
+ return column.toColDef();
108
+ });
109
+ }
110
+
111
+ if (this.fullWidthRowTemplate) {
112
+ this.gridOptions.fullWidthCellRenderer =
113
+ {template: this.fullWidthRowTemplate.template};
114
+ }
115
+
116
+ if (this.dateTemplate) {
117
+ (<any>this.gridOptions).dateComponentFramework =
118
+ {template: this.dateTemplate.template};
119
+ }
120
+
121
+ new Grid(this._nativeElement, this.gridOptions, this.gridParams);
122
+ this.api = this.gridOptions.api;
123
+ this.columnApi = this.gridOptions.columnApi;
124
+
125
+ this._initialised = true;
126
+ }
127
+
128
+ /**
129
+ * Called by Aurelia whenever a bound property changes
130
+ */
131
+ propertyChanged(propertyName: string, newValue: any, oldValue: any) {
132
+ // emulate an Angular2 SimpleChanges Object
133
+ let changes: IPropertyChanges = {};
134
+ changes[propertyName] = <any>{currentValue: newValue, previousValue: oldValue};
135
+
136
+ if (this._initialised) {
137
+ ComponentUtil.processOnChange(changes, this.api);
138
+ }
139
+ }
140
+
141
+ public detached(): void {
142
+ if (this._initialised) {
143
+ // need to do this before the destroy, so we know not to emit any events
144
+ // while tearing down the grid.
145
+ this._destroyed = true;
146
+ this.api.destroy();
147
+ }
148
+ }
149
+
150
+ private globalEventListener(eventType: string, event: any): void {
151
+ // if we are tearing down, don't emit events
152
+ if (this._destroyed) {
153
+ return;
154
+ }
155
+ // generically look up the eventType
156
+ let emitter = (<any>this)[eventType];
157
+ if (emitter) {
158
+ emitter(event);
159
+ } else {
160
+ console.log('ag-Grid-aurelia: could not find EventEmitter: ' + eventType);
161
+ }
162
+ }
163
+ }
@@ -0,0 +1,146 @@
1
+ import {autoinject, child, children, customElement, inlineView} from "aurelia-framework";
2
+ import {ColDef} from "ag-grid-community";
3
+ import {
4
+ AgCellTemplate,
5
+ AgEditorTemplate,
6
+ AgFilterTemplate,
7
+ AgHeaderGroupTemplate,
8
+ AgHeaderTemplate, AgPinnedRowTemplate
9
+ } from "./agTemplate";
10
+ import {generateBindables} from "./agUtils";
11
+
12
+ @customElement('ag-grid-column')
13
+ @generateBindables(["colId", "sort", "sortedAt", "sortingOrder", "field", "headerValueGetter", "hideCol", "pinned",
14
+ "tooltipField", "headerTooltip", "valueGetter", "keyCreator", "floatingFilterComponentFramework", "rowDrag",
15
+ "width", "minWidth", "maxWidth", "cellClass", "cellStyle", "cellRenderer", "cellRendererFramework",
16
+ "cellRendererParams", "cellEditor", "cellEditorFramework", "cellEditorParams", "floatingCellRenderer",
17
+ "floatingCellRendererFramework", "floatingCellRendererParams", "cellFormatter", "floatingCellFormatter",
18
+ "getQuickFilterText", "aggFunc", "rowGroupIndex", "pivotIndex", "comparator", "checkboxSelection", "suppressMenu",
19
+ "suppressSorting", "suppressMovable", "suppressFilter", "unSortIcon", "suppressSizeToFit", "suppressResize",
20
+ "suppressAutoSize", "suppressToolPanel", "suppressKeyboardEvent", "enableRowGroup", "enablePivot", "enableValue",
21
+ "editable", "suppressNavigable", "newValueHandler", "volatile", "filter", "filterFramework", "filterParams",
22
+ "cellClassRules", "onCellValueChanged", "onCellClicked", "onCellDoubleClicked", "onCellContextMenu", "icons",
23
+ "enableCellChangeFlash", "headerName", "columnGroupShow", "headerClass", "toolPanelClass", "children", "groupId", "openByDefault",
24
+ "marryChildren", "headerCheckboxSelection", "headerCheckboxSelectionFilteredOnly", "type", "valueSetter",
25
+ "pinnedRowCellRenderer", "pinnedRowCellRendererFramework", "pinnedRowCellRendererParams", "valueFormatter",
26
+ "pinnedRowValueFormatter", "valueParser", "allowedAggFuncs", "rowGroup", "showRowGroup", "pivot", "equals", "pivotComparator",
27
+ "menuTabs", "colSpan", "suppressPaste", "template", "templateUrl", "pivotValueColumn", "pivotTotalColumnIds", "headerComponent",
28
+ "headerComponentFramework", "headerComponentParams", "floatingFilterComponent", "floatingFilterComponentParams",
29
+ "lockPinned"])
30
+ // <slot> is required for @children to work. https://github.com/aurelia/templating/issues/451#issuecomment-254206622
31
+ @inlineView(`<template><slot></slot></template>`)
32
+ @autoinject()
33
+ export class AgGridColumn {
34
+ private mappedColumnProperties: any = {
35
+ "hideCol": "hide" // hide exists in aurelia-templating-resources and will conflict
36
+ };
37
+
38
+ @children('ag-grid-column')
39
+ public childColumns: AgGridColumn[] = [];
40
+
41
+ @child('ag-cell-template')
42
+ public cellTemplate: AgCellTemplate;
43
+
44
+ @child('ag-editor-template')
45
+ public editorTemplate: AgEditorTemplate;
46
+
47
+ @child('ag-filter-template')
48
+ public filterTemplate: AgFilterTemplate;
49
+
50
+ @child('ag-header-template')
51
+ public headerTemplate: AgHeaderTemplate;
52
+
53
+ @child('ag-header-group-template')
54
+ public headerGroupTemplate: AgHeaderGroupTemplate;
55
+
56
+ @child('ag-pinned-row-template')
57
+ public pinnedRowTemplate: AgPinnedRowTemplate;
58
+
59
+ constructor() {
60
+ }
61
+
62
+ public hasChildColumns(): boolean {
63
+ return this.childColumns && this.childColumns.length > 0;
64
+ }
65
+
66
+ public toColDef(): ColDef {
67
+ let colDef: ColDef = this.createColDefFromGridColumn();
68
+
69
+ if (this.hasChildColumns()) {
70
+ (<any>colDef)["children"] = AgGridColumn.getChildColDefs(this.childColumns);
71
+ }
72
+
73
+ const defaultAction = (templateName:string) => {
74
+ let self = <any>this;
75
+
76
+ if(self[templateName]) {
77
+ const frameworkName = templates[templateName].frameworkName;
78
+ (<any>colDef)[frameworkName] = {template: self[templateName].template};
79
+ delete (<any>colDef)[templateName];
80
+ }
81
+ };
82
+
83
+ const editorAction = (templateName:string) => {
84
+ if (colDef.editable === undefined) {
85
+ colDef.editable = true;
86
+ }
87
+
88
+ defaultAction(templateName);
89
+ };
90
+
91
+ const templates : any = {
92
+ cellTemplate: {
93
+ frameworkName: 'cellRendererFramework'
94
+ },
95
+ editorTemplate: {
96
+ frameworkName: 'cellEditorFramework',
97
+ action: editorAction
98
+ },
99
+ filterTemplate: {
100
+ frameworkName: 'filterFramework'
101
+ },
102
+ headerTemplate: {
103
+ frameworkName: 'headerComponentFramework'
104
+ },
105
+ headerGroupTemplate: {
106
+ frameworkName: 'headerGroupComponentFramework'
107
+ },
108
+ pinnedRowTemplate: {
109
+ frameworkName: 'pinnedRowCellRendererFramework'
110
+ }
111
+ };
112
+
113
+ const addTemplate = (templateName: string) => {
114
+ const action = templates[templateName].action ? templates[templateName].action : defaultAction;
115
+ action(templateName);
116
+ };
117
+
118
+ Object.keys(templates)
119
+ .forEach(addTemplate);
120
+
121
+ return colDef;
122
+ }
123
+
124
+ private static getChildColDefs(childColumns: AgGridColumn[]) {
125
+ return childColumns
126
+ .filter(column => !column.hasChildColumns())
127
+ .map((column: AgGridColumn) => {
128
+ return column.toColDef();
129
+ });
130
+ };
131
+
132
+ private createColDefFromGridColumn(): ColDef {
133
+ let colDef: ColDef = {};
134
+ for (let prop in this) {
135
+ // only map this property if it's been actually been set
136
+ if (this[prop] === undefined) {
137
+ continue;
138
+ }
139
+
140
+ let colDefProperty = this.mappedColumnProperties[prop] ? this.mappedColumnProperties[prop] : prop;
141
+ (<any>colDef)[colDefProperty] = (<any>this)[prop];
142
+ }
143
+ delete (<any>colDef).childColumns;
144
+ return colDef;
145
+ };
146
+ }
@@ -0,0 +1,118 @@
1
+ import {autoinject, customElement, noView, processContent, TargetInstruction} from "aurelia-framework";
2
+
3
+ /**
4
+ * Function will move the elements innerHtml to a template property
5
+ * and then remove html from the element so that Aurelia will not render
6
+ * the template elements
7
+ * @param compiler
8
+ * @param resources
9
+ * @param element
10
+ * @param instruction
11
+ */
12
+ function parseElement(compiler: any, resources: any, element: any, instruction: any) {
13
+ let html = element.innerHTML;
14
+ if (html !== '') {
15
+ instruction.template = html;
16
+ }
17
+ element.innerHTML = '';
18
+ }
19
+
20
+ function getTemplate(targetInstruction: any) {
21
+ return `<template>` + <any> targetInstruction.elementInstruction.template + `</template>`
22
+ }
23
+
24
+ @customElement('ag-cell-template')
25
+ @noView()
26
+ @autoinject()
27
+ @processContent(parseElement)
28
+ export class AgCellTemplate {
29
+ template: string;
30
+
31
+ constructor(targetInstruction: TargetInstruction) {
32
+ this.template = getTemplate(targetInstruction);
33
+ }
34
+ }
35
+
36
+ @customElement('ag-editor-template')
37
+ @noView()
38
+ @autoinject()
39
+ @processContent(parseElement)
40
+ export class AgEditorTemplate {
41
+ template: string;
42
+
43
+ constructor(targetInstruction: TargetInstruction) {
44
+ this.template = getTemplate(targetInstruction);
45
+ }
46
+ }
47
+
48
+ @customElement('ag-filter-template')
49
+ @noView()
50
+ @autoinject()
51
+ @processContent(parseElement)
52
+ export class AgFilterTemplate {
53
+ template: string;
54
+
55
+ constructor(targetInstruction: TargetInstruction) {
56
+ this.template = getTemplate(targetInstruction);
57
+ }
58
+ }
59
+
60
+ @customElement('ag-header-template')
61
+ @noView()
62
+ @autoinject()
63
+ @processContent(parseElement)
64
+ export class AgHeaderTemplate {
65
+ template: string;
66
+
67
+ constructor(targetInstruction: TargetInstruction) {
68
+ this.template = getTemplate(targetInstruction);
69
+ }
70
+ }
71
+
72
+ @customElement('ag-header-group-template')
73
+ @noView()
74
+ @autoinject()
75
+ @processContent(parseElement)
76
+ export class AgHeaderGroupTemplate {
77
+ template: string;
78
+
79
+ constructor(targetInstruction: TargetInstruction) {
80
+ this.template = getTemplate(targetInstruction);
81
+ }
82
+ }
83
+
84
+ @customElement('ag-pinned-row-template')
85
+ @noView()
86
+ @autoinject()
87
+ @processContent(parseElement)
88
+ export class AgPinnedRowTemplate {
89
+ template: string;
90
+
91
+ constructor(targetInstruction: TargetInstruction) {
92
+ this.template = getTemplate(targetInstruction);
93
+ }
94
+ }
95
+
96
+ @customElement('ag-date-template')
97
+ @noView()
98
+ @autoinject()
99
+ @processContent(parseElement)
100
+ export class AgDateTemplate {
101
+ template: string;
102
+
103
+ constructor(targetInstruction: TargetInstruction) {
104
+ this.template = getTemplate(targetInstruction);
105
+ }
106
+ }
107
+
108
+ @customElement('ag-full-width-row-template')
109
+ @noView()
110
+ @autoinject()
111
+ @processContent(parseElement)
112
+ export class AgFullWidthRowTemplate {
113
+ template: string;
114
+
115
+ constructor(targetInstruction: TargetInstruction) {
116
+ this.template = getTemplate(targetInstruction);
117
+ }
118
+ }
package/src/agUtils.ts ADDED
@@ -0,0 +1,26 @@
1
+ import {BindableProperty, HtmlBehaviorResource, metadata} from "aurelia-framework";
2
+
3
+ export function generateBindables(names: string[], bindingModeToUse?: any): any {
4
+ return function (target: any, key: any, descriptor: any) {
5
+ // get or create the HtmlBehaviorResource
6
+ // on which we're going to create the BindableProperty's
7
+ let behaviorResource: HtmlBehaviorResource = <HtmlBehaviorResource>metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target);
8
+
9
+ let nameOrConfigOrTargets: any[] = names.map((name) => {
10
+ let nameOrConfigOrTarget: any = {
11
+ name: name
12
+ };
13
+
14
+ if (bindingModeToUse) {
15
+ nameOrConfigOrTarget["defaultBindingMode"] = bindingModeToUse;
16
+ }
17
+
18
+ return nameOrConfigOrTarget;
19
+ });
20
+
21
+ nameOrConfigOrTargets.forEach((nameOrConfigOrTarget) => {
22
+ let prop = new BindableProperty(nameOrConfigOrTarget);
23
+ prop.registerWith(target, behaviorResource, descriptor);
24
+ });
25
+ };
26
+ }
@@ -0,0 +1,118 @@
1
+ import { autoinject, Container, TaskQueue, transient, View, ViewCompiler, ViewResources } from "aurelia-framework";
2
+ import { BaseComponentWrapper, Bean, FrameworkComponentWrapper, WrappableInterface } from 'ag-grid-community';
3
+
4
+ @autoinject()
5
+ @transient()
6
+ @Bean("frameworkComponentWrapper")
7
+ export class AureliaFrameworkComponentWrapper extends BaseComponentWrapper<WrappableInterface> implements FrameworkComponentWrapper {
8
+ private _container: Container;
9
+ private _viewResources: ViewResources;
10
+
11
+ constructor(private taskQueue: TaskQueue, private _viewCompiler: ViewCompiler) {
12
+ super();
13
+ }
14
+
15
+ createWrapper(template: any): WrappableInterface {
16
+ let that = this;
17
+
18
+ class DynamicComponent extends BaseGuiComponent implements WrappableInterface {
19
+ constructor() {
20
+ super(that.taskQueue, that._viewCompiler);
21
+ }
22
+
23
+ init(params: any): void {
24
+ super.init(params, template.template, that._viewResources, that._container);
25
+ }
26
+
27
+ hasMethod(name: string): boolean {
28
+ return wrapper.getFrameworkComponentInstance() && wrapper.getFrameworkComponentInstance()[name] != null;
29
+ }
30
+
31
+ callMethod(name: string, args: IArguments): void {
32
+ const componentRef = this.getFrameworkComponentInstance();
33
+ return wrapper.getFrameworkComponentInstance()[name].apply(componentRef, args);
34
+
35
+ }
36
+
37
+ addMethod(name: string, callback: Function): void {
38
+ (<any>wrapper)[name] = callback
39
+ }
40
+ }
41
+
42
+ const wrapper: DynamicComponent = new DynamicComponent();
43
+ return wrapper;
44
+ }
45
+
46
+ public setContainer(container: Container): void {
47
+ this._container = container;
48
+ }
49
+
50
+ public setViewResources(viewResources: ViewResources): void {
51
+ this._viewResources = viewResources;
52
+ }
53
+ }
54
+
55
+ abstract class BaseGuiComponent {
56
+ private _taskQueue: TaskQueue;
57
+ private _viewCompiler: ViewCompiler;
58
+
59
+ protected _params: any;
60
+ protected _view: View;
61
+
62
+ constructor(taskQueue: TaskQueue, viewCompiler: ViewCompiler) {
63
+ this._taskQueue = taskQueue;
64
+ this._viewCompiler = viewCompiler;
65
+ }
66
+
67
+ init(params: any, template: any, viewResources: ViewResources, container: Container) {
68
+ this._params = params;
69
+
70
+ let bindingContext = {params: params};
71
+
72
+ let viewFactory = this._viewCompiler.compile(template, viewResources);
73
+ this._view = viewFactory.create(container);
74
+ let controllers: any[] = (<any>this._view).controllers;
75
+ //initialize each controller
76
+ if (controllers && controllers.length) {
77
+ controllers.forEach((c) => {
78
+ c.viewModel.params = params;
79
+ });
80
+ this._view.bind(bindingContext);
81
+ //ICellRenderer doesn't have a guiAttached method so
82
+ //we call attach on the queue;
83
+ this._taskQueue.queueMicroTask(() => this._view.attached());
84
+ } else {
85
+ this._view.bind(bindingContext);
86
+ }
87
+ }
88
+
89
+ getGui(): HTMLElement {
90
+ return this._view.fragment as HTMLElement;
91
+ }
92
+
93
+
94
+ destroy() {
95
+ this._view.returnToCache();
96
+ }
97
+
98
+ refresh(params: any): boolean {
99
+ return false;
100
+ }
101
+
102
+ public getFrameworkComponentInstance(): any {
103
+ let controllers: any[] = (<any>this._view).controllers;
104
+
105
+ //only one controller is allowed in editor template
106
+ if (controllers &&
107
+ controllers.length == 1 &&
108
+ controllers[0].viewModel) {
109
+ let editorVm = controllers[0].viewModel;
110
+ //this is a 'hack' because we don't have params.bind="" in the template
111
+ //must reset params or it will be nothing
112
+ editorVm.params = this._params;
113
+ return editorVm;
114
+ }
115
+ return null;
116
+ }
117
+
118
+ }
@@ -0,0 +1,45 @@
1
+ import {autoinject, Container, transient, ViewResources} from "aurelia-framework";
2
+ import {VanillaFrameworkOverrides, IFrameworkOverrides, AgPromise, FrameworkOverridesIncomingSource} from "ag-grid-community";
3
+
4
+ @autoinject()
5
+ @transient()
6
+ export class AureliaFrameworkFactory implements IFrameworkOverrides {
7
+ setInterval(action: any, interval?: any): AgPromise<number> {
8
+ throw new Error("Method not implemented.");
9
+ }
10
+ addEventListener(element: HTMLElement, type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {
11
+ throw new Error("Method not implemented.");
12
+ }
13
+ wrapIncoming: <T>(callback: () => T, source?: FrameworkOverridesIncomingSource) => T;
14
+ wrapOutgoing: <T>(callback: () => T) => T;
15
+ shouldWrapOutgoing?: boolean;
16
+ frameworkComponent(name: string, components?: any) {
17
+ throw new Error("Method not implemented.");
18
+ }
19
+ isFrameworkComponent(comp: any): boolean {
20
+ throw new Error("Method not implemented.");
21
+ }
22
+ renderingEngine: "vanilla" | "react";
23
+ getDocLink(path?: string): string {
24
+ throw new Error("Method not implemented.");
25
+ }
26
+ private _container: Container;
27
+ private _viewResources: ViewResources;
28
+ private _baseFrameworkFactory: IFrameworkOverrides = new VanillaFrameworkOverrides(); // todo - inject this
29
+
30
+ public setContainer(container: Container): void {
31
+ this._container = container;
32
+ }
33
+
34
+ public setViewResources(viewResources: ViewResources): void {
35
+ this._viewResources = viewResources;
36
+ }
37
+
38
+ setTimeout(action: any, timeout?: any): void {
39
+ window.setTimeout(action, timeout);
40
+ }
41
+
42
+ addEventListenerOutsideAngular(element: HTMLElement, type: string, listener: EventListener | EventListenerObject, useCapture?: boolean): void {
43
+ element.addEventListener(type, listener, useCapture);
44
+ }
45
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "emitDecoratorMetadata": true,
5
+ "experimentalDecorators": true,
6
+ "noImplicitAny": true,
7
+ "noEmitOnError": false,
8
+ "moduleResolution": "bundler",
9
+ "module": "es2022",
10
+ "target": "es2022",
11
+ "outDir": "lib",
12
+ "rootDir": "src",
13
+ "lib": ["dom", "es2023"],
14
+ "esModuleInterop": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "skipLibCheck": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "resolveJsonModule": true,
19
+ "isolatedModules": true,
20
+ "exactOptionalPropertyTypes": false,
21
+ "noUncheckedIndexedAccess": false,
22
+ "strictPropertyInitialization": false,
23
+ "types": [
24
+ "core-js"
25
+ ]
26
+ },
27
+ "include": [
28
+ "src/**/*.ts"
29
+ ],
30
+ "exclude": [
31
+ "node_modules",
32
+ "lib"
33
+ ]
34
+ }