@praful.pathare/q-table 0.0.1 → 0.0.2

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 CHANGED
@@ -1,63 +1,10 @@
1
- # QTable
2
-
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.1.0.
4
-
5
- ## Code scaffolding
6
-
7
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
8
-
9
- ```bash
10
- ng generate component component-name
11
- ```
12
-
13
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
14
-
15
- ```bash
16
- ng generate --help
17
- ```
18
-
19
- ## Building
20
-
21
- To build the library, run:
22
-
23
- ```bash
24
- ng build q-table
25
- ```
26
-
27
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
-
29
- ### Publishing the Library
30
-
31
- Once the project is built, you can publish your library by following these steps:
32
-
33
- 1. Navigate to the `dist` directory:
34
- ```bash
35
- cd dist/q-table
36
- ```
37
-
38
- 2. Run the `npm publish` command to publish your library to the npm registry:
39
- ```bash
40
- npm publish
41
- ```
42
-
43
- ## Running unit tests
44
-
45
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
46
-
47
- ```bash
48
- ng test
49
- ```
50
-
51
- ## Running end-to-end tests
52
-
53
- For end-to-end (e2e) testing, run:
54
-
55
- ```bash
56
- ng e2e
57
- ```
58
-
59
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
60
-
61
- ## Additional Resources
62
-
63
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
1
+ # q-table
2
+ [npmjs.com/q-table](https://www.npmjs.com/package/@praful.pathare/q-table)
3
+ #### Usage
4
+ ```html
5
+ <q-table
6
+ [data]="data"
7
+ />
8
+ ```
9
+ #
10
+ [Reference](https://chatgpt.com/share/699064df-7c34-8000-a2b4-6907b359be5a)
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/q-table",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,23 +1,12 @@
1
- {
2
- "name": "@praful.pathare/q-table",
3
- "version": "0.0.1",
4
- "peerDependencies": {
5
- "@angular/common": "^21.1.0",
6
- "@angular/core": "^21.1.0"
7
- },
8
- "dependencies": {
9
- "tslib": "^2.3.0"
10
- },
11
- "sideEffects": false,
12
- "module": "fesm2022/q-table.mjs",
13
- "typings": "types/q-table.d.ts",
14
- "exports": {
15
- "./package.json": {
16
- "default": "./package.json"
17
- },
18
- ".": {
19
- "types": "./types/q-table.d.ts",
20
- "default": "./fesm2022/q-table.mjs"
21
- }
22
- }
23
- }
1
+ {
2
+ "name": "@praful.pathare/q-table",
3
+ "version": "0.0.2",
4
+ "peerDependencies": {
5
+ "@angular/common": "^21.1.0",
6
+ "@angular/core": "^21.1.0"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "sideEffects": false
12
+ }
@@ -0,0 +1,39 @@
1
+
2
+ #q-table-wrapper {
3
+ white-space: nowrap;
4
+ overflow-x: auto;
5
+ overflow-y: hidden;
6
+ }
7
+
8
+ .input {
9
+ border: 1px solid #888;
10
+ border-radius: 5px;
11
+ line-height: 26px;
12
+ padding: 0 10px;
13
+ cursor: text;
14
+ }
15
+
16
+ .search-result-description-wrapper {
17
+ margin: 10px;
18
+ }
19
+
20
+ .header {
21
+ text-transform: capitalize;
22
+ font-weight: bold;
23
+ }
24
+
25
+ .row-wrapper {
26
+ }
27
+
28
+ .row-wrapper:nth-child(even){
29
+ background-color: #f8f8f8;
30
+ }
31
+
32
+ .row {
33
+ display: flex;
34
+ }
35
+
36
+ .cell {
37
+ flex: 1;
38
+ padding: 10px;
39
+ }
@@ -0,0 +1,30 @@
1
+ <div id="q-table-wrapper">
2
+
3
+
4
+ <div class="search-wrapper">
5
+ <input type="text" class="input search-input" placeholder="Search..." [(ngModel)]="q" (keyup)="search()" />
6
+
7
+ <div *ngIf="q" class="search-result-description-wrapper">
8
+ {{searchResultCount}} search results found for '{{q}}'
9
+ </div>
10
+ </div>
11
+
12
+ <div class="row">
13
+ <div class="cell" *ngFor="let header of headers">
14
+ <div class="header">
15
+ {{header}}
16
+ </div>
17
+ </div>
18
+ </div>
19
+
20
+ <div class="row-wrapper" *ngFor="let row of rows">
21
+ <div class="row" *ngIf="row.visible">
22
+ <div *ngFor="let cell of row.cells" class="cell">
23
+ {{ cell.value }}
24
+ </div>
25
+ </div>
26
+ </div>
27
+
28
+
29
+
30
+ </div>
@@ -0,0 +1,23 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { QTable } from './q-table';
4
+
5
+ describe('QTable', () => {
6
+ let component: QTable;
7
+ let fixture: ComponentFixture<QTable>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [QTable]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(QTable);
16
+ component = fixture.componentInstance;
17
+ await fixture.whenStable();
18
+ });
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
@@ -0,0 +1,110 @@
1
+ import { NgFor, NgIf } from '@angular/common';
2
+ import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
3
+ import { FormsModule, NgModel } from '@angular/forms';
4
+
5
+ @Component({
6
+ selector: 'q-table',
7
+ imports: [NgFor, NgIf, FormsModule],
8
+ templateUrl: `./q-table.html`,
9
+ styleUrl: `./q-table.css`
10
+ })
11
+ export class QTable implements OnChanges {
12
+
13
+ @Input('data')
14
+ data?: any[]
15
+
16
+ q: string = '';
17
+ searchResultCount: number = 0;
18
+
19
+ headers: string[] = []
20
+ rows: Row[] = []
21
+ columnIndex: any = {};
22
+ totalColumns: number = 0;
23
+
24
+
25
+ ngOnChanges(changes: SimpleChanges): void {
26
+
27
+ if (this.data === undefined) {
28
+ return;
29
+ }
30
+
31
+ this.data.forEach(item => this.updateHeaders(Object.keys(item)))
32
+ this.data.forEach(item => this.updateRows(item))
33
+ }
34
+
35
+ updateRows(item: any): void {
36
+
37
+ let row: Row = new Row(this.totalColumns);
38
+
39
+ Object.keys(item).forEach(key => {
40
+ row.updateCell(this.columnIndex[key], item[key]);
41
+ })
42
+
43
+ this.rows.push(row);
44
+ }
45
+
46
+ updateHeaders(keys: string[]): void {
47
+
48
+ if (this.headers === undefined || this.headers.length == 0) {
49
+ this.headers = keys;
50
+ }
51
+ else {
52
+ keys.forEach(key => {
53
+ if (this.headers.indexOf(key) < 0) {
54
+ this.headers.push(key)
55
+ }
56
+ })
57
+ }
58
+
59
+ this.headers.forEach((header, index) => {
60
+ this.columnIndex[header] = index;
61
+ })
62
+
63
+ this.totalColumns = Object.keys(this.columnIndex).length;
64
+ }
65
+
66
+ search(): void {
67
+
68
+ this.searchResultCount = 0;
69
+
70
+ this.rows.forEach((row) => {
71
+
72
+ row.visible = false;
73
+
74
+ row.cells.forEach((cell) => {
75
+ if((""+cell.value).toLowerCase().includes(this.q.toLowerCase())) {
76
+ row.visible = true;
77
+ this.searchResultCount++;
78
+ }
79
+ })
80
+
81
+ })
82
+ }
83
+
84
+
85
+ }
86
+
87
+ class Cell {
88
+ value: any = undefined;
89
+ hidden: boolean = false;
90
+
91
+ constructor() {
92
+ }
93
+ }
94
+
95
+ class Row {
96
+ cells: Cell[] = []
97
+ visible: boolean = true;
98
+
99
+ constructor(totalCells: number) {
100
+ for (let i = 0; i < totalCells; i++) {
101
+ this.cells.push(new Cell());
102
+ }
103
+
104
+ this.visible = true;
105
+ }
106
+
107
+ updateCell(columnIndex: number, value: any): void {
108
+ this.cells[columnIndex].value = value;
109
+ }
110
+ }
@@ -0,0 +1,16 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { Utils } from './utils';
4
+
5
+ describe('Utils', () => {
6
+ let service: Utils;
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({});
10
+ service = TestBed.inject(Utils);
11
+ });
12
+
13
+ it('should be created', () => {
14
+ expect(service).toBeTruthy();
15
+ });
16
+ });
@@ -0,0 +1,8 @@
1
+ import { Injectable } from '@angular/core';
2
+
3
+ @Injectable({
4
+ providedIn: 'root',
5
+ })
6
+ export class Utils {
7
+
8
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Public API Surface of q-table
3
+ */
4
+
5
+ export * from './lib/q-table';
6
+ export * from './lib/services/utils';
@@ -0,0 +1,17 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "../../tsconfig.json",
5
+ "compilerOptions": {
6
+ "outDir": "../../out-tsc/lib",
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "types": []
10
+ },
11
+ "include": [
12
+ "src/**/*.ts"
13
+ ],
14
+ "exclude": [
15
+ "**/*.spec.ts"
16
+ ]
17
+ }
@@ -0,0 +1,11 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "./tsconfig.lib.json",
5
+ "compilerOptions": {
6
+ "declarationMap": false
7
+ },
8
+ "angularCompilerOptions": {
9
+ "compilationMode": "partial"
10
+ }
11
+ }
@@ -0,0 +1,15 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "../../tsconfig.json",
5
+ "compilerOptions": {
6
+ "outDir": "../../out-tsc/spec",
7
+ "types": [
8
+ "vitest/globals"
9
+ ]
10
+ },
11
+ "include": [
12
+ "src/**/*.d.ts",
13
+ "src/**/*.spec.ts"
14
+ ]
15
+ }
@@ -1,34 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { Component, Injectable } from '@angular/core';
3
-
4
- class QTable {
5
- headers = ['id', 'name', 'price'];
6
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: QTable, deps: [], target: i0.ɵɵFactoryTarget.Component });
7
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.1.4", type: QTable, isStandalone: true, selector: "q-table", ngImport: i0, template: "<div id=\"q-table-wrapper\">\r\n\r\n <div *ngFor=\"let header of headers\">\r\n <span>{{header}}</span>\r\n </div>\r\n\r\n</div>", styles: [""] });
8
- }
9
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: QTable, decorators: [{
10
- type: Component,
11
- args: [{ selector: 'q-table', imports: [], template: "<div id=\"q-table-wrapper\">\r\n\r\n <div *ngFor=\"let header of headers\">\r\n <span>{{header}}</span>\r\n </div>\r\n\r\n</div>" }]
12
- }] });
13
-
14
- class Utils {
15
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: Utils, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
16
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: Utils, providedIn: 'root' });
17
- }
18
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: Utils, decorators: [{
19
- type: Injectable,
20
- args: [{
21
- providedIn: 'root',
22
- }]
23
- }] });
24
-
25
- /*
26
- * Public API Surface of q-table
27
- */
28
-
29
- /**
30
- * Generated bundle index. Do not edit.
31
- */
32
-
33
- export { QTable, Utils };
34
- //# sourceMappingURL=q-table.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"q-table.mjs","sources":["../../../projects/q-table/src/lib/q-table.ts","../../../projects/q-table/src/lib/q-table.html","../../../projects/q-table/src/lib/services/utils.ts","../../../projects/q-table/src/public-api.ts","../../../projects/q-table/src/q-table.ts"],"sourcesContent":["import { Component, Input } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'q-table',\r\n imports: [],\r\n templateUrl: `./q-table.html`,\r\n styles: ``,\r\n})\r\nexport class QTable {\r\n\r\n headers?: string[] = ['id', 'name', 'price']\r\n\r\n\r\n}\r\n","<div id=\"q-table-wrapper\">\r\n\r\n <div *ngFor=\"let header of headers\">\r\n <span>{{header}}</span>\r\n </div>\r\n\r\n</div>","import { Injectable } from '@angular/core';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class Utils {\r\n \r\n}\r\n","/*\r\n * Public API Surface of q-table\r\n */\r\n\r\nexport * from './lib/q-table';\r\nexport * from './lib/services/utils';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAQa,MAAM,CAAA;IAEjB,OAAO,GAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC;uGAFjC,MAAM,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAN,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAM,mECRnB,uIAMM,EAAA,MAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;2FDEO,MAAM,EAAA,UAAA,EAAA,CAAA;kBANlB,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,SAAS,WACV,EAAE,EAAA,QAAA,EAAA,uIAAA,EAAA;;;MECA,KAAK,CAAA;uGAAL,KAAK,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAL,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,KAAK,cAFJ,MAAM,EAAA,CAAA;;2FAEP,KAAK,EAAA,UAAA,EAAA,CAAA;kBAHjB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACJD;;AAEG;;ACFH;;AAEG;;;;"}
@@ -1,14 +0,0 @@
1
- import * as i0 from '@angular/core';
2
-
3
- declare class QTable {
4
- headers?: string[];
5
- static ɵfac: i0.ɵɵFactoryDeclaration<QTable, never>;
6
- static ɵcmp: i0.ɵɵComponentDeclaration<QTable, "q-table", never, {}, {}, never, never, true, never>;
7
- }
8
-
9
- declare class Utils {
10
- static ɵfac: i0.ɵɵFactoryDeclaration<Utils, never>;
11
- static ɵprov: i0.ɵɵInjectableDeclaration<Utils>;
12
- }
13
-
14
- export { QTable, Utils };