-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Angular adapter for tanstack table initial
- Loading branch information
1 parent
1bbac0f
commit 72635a0
Showing
10 changed files
with
533 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,5 @@ yarn.lock | |
*.tsbuildinfo | ||
|
||
.nx/cache | ||
|
||
.angular |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
**/docs | ||
**/old-examples | ||
pnpm-lock.yaml | ||
|
||
.angular |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "@tanstack/angular-table", | ||
"version": "8.11.7", | ||
"description": "Headless UI for building powerful tables & datagrids for Angular.", | ||
"author": "Tanner Linsley", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/TanStack/table.git", | ||
"directory": "packages/angular-table" | ||
}, | ||
"homepage": "https://tanstack.com/table", | ||
"funding": { | ||
"type": "github", | ||
"url": "https://github.com/sponsors/tannerlinsley" | ||
}, | ||
"keywords": [ | ||
"angular", | ||
"table", | ||
"angular-table", | ||
"datagrid" | ||
], | ||
"type": "commonjs", | ||
"module": "build/lib/index.esm.js", | ||
"main": "build/lib/index.js", | ||
"types": "build/lib/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./build/lib/index.d.ts", | ||
"import": "./build/lib/index.mjs", | ||
"default": "./build/lib/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"files": [ | ||
"build/lib/*", | ||
"build/umd/*", | ||
"src" | ||
], | ||
"scripts": { | ||
"clean": "rimraf ./build", | ||
"test:types": "tsc --noEmit", | ||
"build": "pnpm build:rollup && pnpm build:types", | ||
"build:rollup": "rollup --config rollup.config.mjs", | ||
"build:types": "tsc --emitDeclarationOnly" | ||
}, | ||
"dependencies": { | ||
"@tanstack/table-core": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"@angular/common": "^17.0.0", | ||
"@angular/core": "^17.0.0" | ||
}, | ||
"sideEffects": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { defineConfig } from 'rollup' | ||
import { buildConfigs } from '../../scripts/getRollupConfig.js' | ||
export default defineConfig( | ||
buildConfigs({ | ||
name: 'angular-table', | ||
jsName: 'AngularTable', | ||
outputFile: 'index', | ||
entryFile: 'src/index.ts', | ||
external: ['@angular/core', '@angular/common', '@tanstack/table-core'], | ||
globals: { | ||
'@angular/core': 'AngularCore', | ||
'@angular/common': 'AngularCommon', | ||
}, | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
Directive, | ||
Input, | ||
OnInit, | ||
TemplateRef, | ||
ViewContainerRef, | ||
} from '@angular/core' | ||
|
||
@Directive({ | ||
selector: '[flexRender]', | ||
standalone: true, | ||
}) | ||
export class FlexRenderDirective implements OnInit { | ||
private _flexRender: any | ||
|
||
/** properties to render */ | ||
private _flexRenderProps: any | ||
|
||
@Input() | ||
set flexRender(render: any) { | ||
this._flexRender = render | ||
} | ||
|
||
@Input() | ||
set flexRenderProps(props: any) { | ||
this._flexRenderProps = props | ||
} | ||
|
||
constructor( | ||
private viewContainer: ViewContainerRef, | ||
private templateRef: TemplateRef<any> | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.renderComponent() | ||
} | ||
|
||
renderComponent() { | ||
this.viewContainer.clear() | ||
if (!this._flexRender) { | ||
return '' | ||
} | ||
|
||
if (typeof this._flexRender === 'string') { | ||
return this.viewContainer.createEmbeddedView(this.templateRef, { | ||
$implicit: this._flexRender, | ||
}) | ||
} | ||
|
||
if (typeof this._flexRender === 'function') { | ||
const componentInstance = this._flexRender(this._flexRenderProps) | ||
return this.viewContainer.createEmbeddedView(this.templateRef, { | ||
$implicit: componentInstance, | ||
}) | ||
} | ||
|
||
return '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
RowData, | ||
TableOptions, | ||
TableOptionsResolved, | ||
createTable, | ||
} from '@tanstack/table-core' | ||
|
||
export * from '@tanstack/table-core' | ||
|
||
export * from './flexrender.directive' | ||
|
||
export function createAngularTable<TData extends RowData>( | ||
options: TableOptions<TData> | ||
) { | ||
const resolvedOptions: TableOptionsResolved<TData> = { | ||
state: {}, | ||
onStateChange: () => {}, | ||
renderFallbackValue: null, | ||
...options, | ||
} | ||
|
||
let table = createTable<TData>(resolvedOptions) | ||
let state = table.initialState | ||
|
||
// Compose the default state above with any user state. | ||
table.setOptions((prev: any) => { | ||
return { | ||
...prev, | ||
...options, | ||
state: { | ||
...state, | ||
...options.state, | ||
}, | ||
onStateChange: (updater: any) => { | ||
options.onStateChange?.(updater) | ||
}, | ||
} | ||
}) | ||
|
||
return table | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./build/lib", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.