@uni-design-system/uni-angular 2.0.2 → 2.0.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 +57 -0
- package/fesm2022/uni-design-system-uni-angular.mjs +1944 -0
- package/fesm2022/uni-design-system-uni-angular.mjs.map +1 -0
- package/package.json +22 -34
- package/types/uni-design-system-uni-angular.d.ts +483 -0
- package/.storybook/main.ts +0 -41
- package/.storybook/manager.ts +0 -24
- package/.storybook/preview.ts +0 -21
- package/.storybook/tsconfig.json +0 -24
- package/.storybook/typings.d.ts +0 -4
- package/.storybook/vite.config.ts +0 -7
- package/.turbo/turbo-build.log +0 -25
- package/CHANGELOG.md +0 -35
- package/angular.json +0 -47
- package/dist/fesm2022/uni-design-system-uni-angular.mjs +0 -32
- package/dist/fesm2022/uni-design-system-uni-angular.mjs.map +0 -1
- package/dist/types/uni-design-system-uni-angular.d.ts +0 -11
- package/ng-package.json +0 -7
- package/src/lib/button.component.ts +0 -28
- package/src/lib/button.stories.ts +0 -20
- package/src/lib/cdk/datasource/base-datasource.ts +0 -113
- package/src/lib/cdk/datasource/datasource.types.ts +0 -10
- package/src/lib/cdk/datasource/record-datasource.ts +0 -115
- package/src/lib/cdk/datasource/server-side-datasource.ts +0 -172
- package/src/lib/cdk/helpers/memoize.helper.ts +0 -15
- package/src/lib/cdk/helpers/number.helper.ts +0 -2
- package/src/lib/cdk/index.ts +0 -3
- package/src/lib/cdk/local-storage/local-storage.service.ts +0 -124
- package/src/lib/cdk/option/option.model.ts +0 -6
- package/src/lib/cdk/timer/timer.ts +0 -66
- package/src/lib/components/text/text.component.ts +0 -57
- package/src/lib/components/text/text.mdx +0 -15
- package/src/lib/components/text/text.stories.ts +0 -39
- package/src/lib/theming/theme.service.ts +0 -270
- package/src/lib/theming/theme.token.ts +0 -7
- package/src/public-api.ts +0 -1
- package/src/stories/blocks/StoryUsage.tsx +0 -21
- package/tsconfig.json +0 -19
package/CHANGELOG.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# @uni-design-system/uni-angular
|
|
2
|
-
|
|
3
|
-
## 2.0.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies []:
|
|
8
|
-
- @uni-design-system/uni-core@2.0.2
|
|
9
|
-
|
|
10
|
-
## 2.0.1
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- [`be0fb26`](https://github.com/uni-design-system/uni/commit/be0fb2626c248fed37c2609d50eb1bfae40269e4) Thanks [@gaenglish](https://github.com/gaenglish)! - Setting Fixed Versioning for all packages.
|
|
15
|
-
|
|
16
|
-
- Updated dependencies [[`e2cad74`](https://github.com/uni-design-system/uni/commit/e2cad74631b3a9d2caf4816bcadedf19db99fec4), [`be0fb26`](https://github.com/uni-design-system/uni/commit/be0fb2626c248fed37c2609d50eb1bfae40269e4)]:
|
|
17
|
-
- @uni-design-system/uni-core@2.0.1
|
|
18
|
-
|
|
19
|
-
## 2.0.0
|
|
20
|
-
|
|
21
|
-
### Patch Changes
|
|
22
|
-
|
|
23
|
-
- Updated dependencies [[`4a049de`](https://github.com/uni-design-system/uni/commit/4a049def689d56d6b6cc1d2da73c9facd93ed515)]:
|
|
24
|
-
- @uni-design-system/uni-core@1.1.0
|
|
25
|
-
|
|
26
|
-
## 1.0.0
|
|
27
|
-
|
|
28
|
-
### Major Changes
|
|
29
|
-
|
|
30
|
-
- [`7d18157`](https://github.com/uni-design-system/uni/commit/7d18157cb131098688b70286513643423c37c756) Thanks [@gaenglish](https://github.com/gaenglish)! - init release
|
|
31
|
-
|
|
32
|
-
### Patch Changes
|
|
33
|
-
|
|
34
|
-
- Updated dependencies [[`7d18157`](https://github.com/uni-design-system/uni/commit/7d18157cb131098688b70286513643423c37c756)]:
|
|
35
|
-
- @uni-design-system/uni-core@1.0.0
|
package/angular.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../../node_modules/@angular/cli/lib/config/schema.json",
|
|
3
|
-
"version": 1,
|
|
4
|
-
"newProjectRoot": "projects",
|
|
5
|
-
"projects": {
|
|
6
|
-
"@uni-design-system/uni-angular": {
|
|
7
|
-
"projectType": "library",
|
|
8
|
-
"root": "",
|
|
9
|
-
"sourceRoot": "src",
|
|
10
|
-
"prefix": "uni",
|
|
11
|
-
"architect": {
|
|
12
|
-
"build": {
|
|
13
|
-
"builder": "@angular-devkit/build-angular:ng-packagr",
|
|
14
|
-
"options": {
|
|
15
|
-
"project": "ng-package.json"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"test": {
|
|
19
|
-
"builder": "@angular-devkit/build-angular:karma",
|
|
20
|
-
"options": {
|
|
21
|
-
"main": "src/test.ts",
|
|
22
|
-
"tsConfig": "tsconfig.spec.json",
|
|
23
|
-
"karmaConfig": "karma.conf.js"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"storybook": {
|
|
27
|
-
"builder": "@storybook/angular:start-storybook",
|
|
28
|
-
"options": {
|
|
29
|
-
"configDir": ".storybook",
|
|
30
|
-
"browserTarget": "@uni-design-system/uni-angular:build",
|
|
31
|
-
"compodoc": false,
|
|
32
|
-
"port": 6007
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"build-storybook": {
|
|
36
|
-
"builder": "@storybook/angular:build-storybook",
|
|
37
|
-
"options": {
|
|
38
|
-
"configDir": ".storybook",
|
|
39
|
-
"browserTarget": "@uni-design-system/uni-angular:build",
|
|
40
|
-
"compodoc": false,
|
|
41
|
-
"outputDir": "storybook-static"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Input, Component } from '@angular/core';
|
|
3
|
-
import { CommonModule } from '@angular/common';
|
|
4
|
-
|
|
5
|
-
class UniButtonComponent {
|
|
6
|
-
label = 'Button';
|
|
7
|
-
bgColor = '#000000';
|
|
8
|
-
textColor = '#fff';
|
|
9
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: UniButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
10
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.12", type: UniButtonComponent, isStandalone: true, selector: "uni-button", inputs: { label: "label" }, ngImport: i0, template: `
|
|
11
|
-
<button [style.background-color]="bgColor" [style.color]="textColor">
|
|
12
|
-
{{ label }}
|
|
13
|
-
</button>
|
|
14
|
-
`, isInline: true, styles: ["button{padding:12px 24px;border-radius:4px;border:none;cursor:pointer}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }] });
|
|
15
|
-
}
|
|
16
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: UniButtonComponent, decorators: [{
|
|
17
|
-
type: Component,
|
|
18
|
-
args: [{ selector: 'uni-button', standalone: true, imports: [CommonModule], template: `
|
|
19
|
-
<button [style.background-color]="bgColor" [style.color]="textColor">
|
|
20
|
-
{{ label }}
|
|
21
|
-
</button>
|
|
22
|
-
`, styles: ["button{padding:12px 24px;border-radius:4px;border:none;cursor:pointer}\n"] }]
|
|
23
|
-
}], propDecorators: { label: [{
|
|
24
|
-
type: Input
|
|
25
|
-
}] } });
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Generated bundle index. Do not edit.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
export { UniButtonComponent };
|
|
32
|
-
//# sourceMappingURL=uni-design-system-uni-angular.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uni-design-system-uni-angular.mjs","sources":["../../src/lib/button.component.ts","../../src/uni-design-system-uni-angular.ts"],"sourcesContent":["import { Component, Input } from '@angular/core';\nimport { CommonModule } from '@angular/common'; // Still useful for pipes/directives\n\n@Component({\n selector: 'uni-button',\n standalone: true, // Optional but explicit\n imports: [CommonModule],\n template: `\n <button [style.background-color]=\"bgColor\" [style.color]=\"textColor\">\n {{ label }}\n </button>\n `,\n styles: [\n `\n button {\n padding: 12px 24px;\n border-radius: 4px;\n border: none;\n cursor: pointer;\n }\n `,\n ],\n})\nexport class UniButtonComponent {\n @Input() label: string = 'Button';\n bgColor = '#000000';\n textColor = '#fff';\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAuBa,kBAAkB,CAAA;IACpB,KAAK,GAAW,QAAQ;IACjC,OAAO,GAAG,SAAS;IACnB,SAAS,GAAG,MAAM;wGAHP,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAlB,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,kBAAkB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,YAAA,EAAA,MAAA,EAAA,EAAA,KAAA,EAAA,OAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAhBnB;;;;AAIT,EAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,0EAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,UAAA,EAAA,IAAA,EALS,YAAY,EAAA,CAAA,EAAA,CAAA;;4FAiBX,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBApB9B,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,YAAY,cACV,IAAI,EAAA,OAAA,EACP,CAAC,YAAY,CAAC,EAAA,QAAA,EACb;;;;AAIT,EAAA,CAAA,EAAA,MAAA,EAAA,CAAA,0EAAA,CAAA,EAAA;;sBAaA;;;ACxBH;;AAEG;;;;"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
|
|
3
|
-
declare class UniButtonComponent {
|
|
4
|
-
label: string;
|
|
5
|
-
bgColor: string;
|
|
6
|
-
textColor: string;
|
|
7
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<UniButtonComponent, never>;
|
|
8
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<UniButtonComponent, "uni-button", never, { "label": { "alias": "label"; "required": false; }; }, {}, never, never, true, never>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { UniButtonComponent };
|
package/ng-package.json
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../../node_modules/.pnpm/ng-packagr@21.2.3_@angular+compiler-cli@21.2.11_@angular+compiler@21.2.11_typescript@6.0.3__tslib@2.8.1_typescript@6.0.3/node_modules/ng-packagr/ng-package.schema.json",
|
|
3
|
-
"lib": {
|
|
4
|
-
"entryFile": "src/public-api.ts"
|
|
5
|
-
},
|
|
6
|
-
"dest": "dist"
|
|
7
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Component, Input } from '@angular/core';
|
|
2
|
-
import { CommonModule } from '@angular/common'; // Still useful for pipes/directives
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'uni-button',
|
|
6
|
-
standalone: true, // Optional but explicit
|
|
7
|
-
imports: [CommonModule],
|
|
8
|
-
template: `
|
|
9
|
-
<button [style.background-color]="bgColor" [style.color]="textColor">
|
|
10
|
-
{{ label }}
|
|
11
|
-
</button>
|
|
12
|
-
`,
|
|
13
|
-
styles: [
|
|
14
|
-
`
|
|
15
|
-
button {
|
|
16
|
-
padding: 12px 24px;
|
|
17
|
-
border-radius: 4px;
|
|
18
|
-
border: none;
|
|
19
|
-
cursor: pointer;
|
|
20
|
-
}
|
|
21
|
-
`,
|
|
22
|
-
],
|
|
23
|
-
})
|
|
24
|
-
export class UniButtonComponent {
|
|
25
|
-
@Input() label: string = 'Button';
|
|
26
|
-
bgColor = '#000000';
|
|
27
|
-
textColor = '#fff';
|
|
28
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
-
import { UniButtonComponent } from './button.component';
|
|
3
|
-
|
|
4
|
-
const meta: Meta<UniButtonComponent> = {
|
|
5
|
-
title: 'Components/UniButton',
|
|
6
|
-
component: UniButtonComponent, // Storybook 11+ handles standalone components automatically here
|
|
7
|
-
render: (args) => ({
|
|
8
|
-
props: args,
|
|
9
|
-
// We don't need 'template' if we just want to render the component as is
|
|
10
|
-
}),
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default meta;
|
|
14
|
-
type Story = StoryObj<UniButtonComponent>;
|
|
15
|
-
|
|
16
|
-
export const Primary: Story = {
|
|
17
|
-
args: {
|
|
18
|
-
label: 'My Angular Component',
|
|
19
|
-
},
|
|
20
|
-
};
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { computed, signal, Signal, WritableSignal } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
export type SortDirection = 'asc' | 'desc' | 'indet';
|
|
4
|
-
|
|
5
|
-
export interface Sort<T> {
|
|
6
|
-
column?: keyof T;
|
|
7
|
-
direction: SortDirection;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export abstract class UniBaseDatasource<T> {
|
|
11
|
-
abstract records: Signal<T[]>;
|
|
12
|
-
abstract recordCount: Signal<number>;
|
|
13
|
-
|
|
14
|
-
selections = signal<T[]>([]);
|
|
15
|
-
|
|
16
|
-
sort: WritableSignal<Sort<T>> = signal({
|
|
17
|
-
column: undefined,
|
|
18
|
-
direction: 'indet',
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
sortColumn = computed(() => this.sort().column);
|
|
22
|
-
sortDirection = computed(() => this.sort().direction);
|
|
23
|
-
|
|
24
|
-
abstract pageIndex: Signal<number>;
|
|
25
|
-
abstract pageSize: Signal<number>;
|
|
26
|
-
abstract pageCount: Signal<number>;
|
|
27
|
-
|
|
28
|
-
pages = computed(() => Array.from({ length: this.pageCount() }, (_, index) => index + 1));
|
|
29
|
-
|
|
30
|
-
startIndex = computed(() => {
|
|
31
|
-
const pageSize = this.pageSize();
|
|
32
|
-
const pageIndex = this.pageIndex();
|
|
33
|
-
return pageSize > 0 ? pageIndex * pageSize : 0;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
endIndex = computed(() => {
|
|
37
|
-
const pageSize = this.pageSize();
|
|
38
|
-
const total = this.recordCount();
|
|
39
|
-
|
|
40
|
-
// If unpaginated (pageSize = 0), return total count
|
|
41
|
-
if (pageSize === 0) {
|
|
42
|
-
return total;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const start = this.startIndex();
|
|
46
|
-
return Math.min(start + pageSize, total);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
disablePrevious = computed(() => {
|
|
50
|
-
const pageSize = this.pageSize();
|
|
51
|
-
return pageSize === 0 ? true : this.pageIndex() === 0;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
disableNext = computed(() => {
|
|
55
|
-
const pageSize = this.pageSize();
|
|
56
|
-
return pageSize === 0 ? true : this.pageIndex() + 1 >= this.pageCount();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
truncatedPages = computed(() => {
|
|
60
|
-
const currentPage = this.pageIndex() + 1;
|
|
61
|
-
const displayRange = 3;
|
|
62
|
-
const totalPages = this.pageCount();
|
|
63
|
-
|
|
64
|
-
const pages: (number | string)[] = [];
|
|
65
|
-
const startPage = Math.max(1, currentPage - displayRange);
|
|
66
|
-
const endPage = Math.min(totalPages, currentPage + displayRange);
|
|
67
|
-
|
|
68
|
-
if (startPage > 1) {
|
|
69
|
-
pages.push(1);
|
|
70
|
-
if (startPage > 2) {
|
|
71
|
-
pages.push('...');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for (let i = startPage; i <= endPage; i++) {
|
|
76
|
-
pages.push(i);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (endPage < totalPages) {
|
|
80
|
-
if (endPage < totalPages - 1) {
|
|
81
|
-
pages.push('...');
|
|
82
|
-
}
|
|
83
|
-
pages.push(totalPages);
|
|
84
|
-
}
|
|
85
|
-
return pages;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
isSelected(row: T): boolean {
|
|
89
|
-
return this.selections().some((selection) => selection === row);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
toggleSelection(row: T) {
|
|
93
|
-
this.selections.update((selections) => {
|
|
94
|
-
return selections.includes(row) ? selections.filter((i) => i !== row) : [...selections, row];
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
clearSelections() {
|
|
99
|
-
this.selections.set([]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
selectAll() {
|
|
103
|
-
this.selections.set([...this.records()]);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
abstract sortRecords(sort: Sort<T>): void;
|
|
107
|
-
abstract firstPage(): void;
|
|
108
|
-
abstract nextPage(): void;
|
|
109
|
-
abstract previousPage(): void;
|
|
110
|
-
abstract lastPage(): void;
|
|
111
|
-
abstract jumpToPage(page: number): void;
|
|
112
|
-
abstract setPageSize(size: number): void;
|
|
113
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UniBaseDatasource } from './base-datasource';
|
|
2
|
-
import { UniRecordDatasource } from './record-datasource';
|
|
3
|
-
import { UniServerSideDatasource } from './server-side-datasource';
|
|
4
|
-
|
|
5
|
-
export type UniDatasource<T> = UniBaseDatasource<T>;
|
|
6
|
-
|
|
7
|
-
export type { Sort, SortDirection } from './base-datasource';
|
|
8
|
-
export type { DataLoader, PageRequest, PageResponse } from './server-side-datasource';
|
|
9
|
-
|
|
10
|
-
export { UniBaseDatasource, UniRecordDatasource, UniServerSideDatasource };
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { computed, signal } from '@angular/core';
|
|
2
|
-
import { UniBaseDatasource, Sort } from './base-datasource';
|
|
3
|
-
|
|
4
|
-
export class UniRecordDatasource<T> extends UniBaseDatasource<T> {
|
|
5
|
-
private _pageNumber = signal(1);
|
|
6
|
-
private _pageSize = signal<number>(0); // 0 = unpaginated (show all)
|
|
7
|
-
|
|
8
|
-
initialRecords = signal<T[]>([]);
|
|
9
|
-
override recordCount = computed((): number => this.initialRecords().filter(this.filter()).length);
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
filter = signal<(value: T) => boolean>((value) => true);
|
|
13
|
-
|
|
14
|
-
override pageIndex = signal<number>(0);
|
|
15
|
-
override pageSize = computed(() => this._pageSize());
|
|
16
|
-
|
|
17
|
-
override pageCount = computed(() => {
|
|
18
|
-
const pageSize = this.pageSize();
|
|
19
|
-
return pageSize > 0 ? Math.ceil(this.recordCount() / pageSize) : 1;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
override records = computed(() => {
|
|
23
|
-
const { column, direction } = this.sort();
|
|
24
|
-
const filter = this.filter();
|
|
25
|
-
const pageSize = this.pageSize();
|
|
26
|
-
|
|
27
|
-
let filteredRecords = this.initialRecords().filter(filter);
|
|
28
|
-
|
|
29
|
-
// Apply sorting if specified
|
|
30
|
-
if (column && direction !== 'indet') {
|
|
31
|
-
filteredRecords = [...filteredRecords].sort((a, b) => {
|
|
32
|
-
const valueA = a[column];
|
|
33
|
-
const valueB = b[column];
|
|
34
|
-
|
|
35
|
-
const isString = typeof valueA === 'string';
|
|
36
|
-
const isAsc = direction === 'asc';
|
|
37
|
-
|
|
38
|
-
return isString
|
|
39
|
-
? stringCompare(valueA as string, valueB as string, isAsc)
|
|
40
|
-
: numberCompare(valueA as number, valueB as number, isAsc);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Apply pagination only if pageSize > 0
|
|
45
|
-
if (pageSize > 0) {
|
|
46
|
-
return filteredRecords.slice(this.startIndex(), this.endIndex());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Return all records (unpaginated)
|
|
50
|
-
return filteredRecords;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
constructor(data: T[]) {
|
|
54
|
-
super();
|
|
55
|
-
this.initialRecords.set(data);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
override sortRecords(sort: Sort<T>) {
|
|
59
|
-
this.sort.set(sort);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
override firstPage() {
|
|
63
|
-
this.pageIndex.set(0);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
override nextPage() {
|
|
67
|
-
if (this.pageIndex() < this.pageCount() - 1) {
|
|
68
|
-
this.pageIndex.update((i) => i + 1);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
override previousPage() {
|
|
73
|
-
this.pageIndex.update((i) => (i > 1 ? i - 1 : 0));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
override lastPage() {
|
|
77
|
-
this.pageIndex.set(this.pageCount() - 1);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
override jumpToPage(page: number) {
|
|
81
|
-
const i = page - 1;
|
|
82
|
-
if (i >= 0 && i < this.pageCount()) {
|
|
83
|
-
this.pageIndex.set(i);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
override setPageSize(size: number) {
|
|
88
|
-
this._pageSize.set(size);
|
|
89
|
-
if (size > 0) {
|
|
90
|
-
this._pageNumber.set(1);
|
|
91
|
-
this.pageIndex.set(0);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
setFilter(filter: (value: T) => boolean) {
|
|
96
|
-
this.filter.set(filter);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
clearFilter() {
|
|
100
|
-
this.filter.set(() => true);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function stringCompare(a = 'zzz', b = 'zzz', isAsc: boolean): number {
|
|
105
|
-
a = a.toString();
|
|
106
|
-
b = b.toString();
|
|
107
|
-
|
|
108
|
-
return isAsc
|
|
109
|
-
? a.localeCompare(b, undefined, { sensitivity: 'base' })
|
|
110
|
-
: b.localeCompare(a, undefined, { sensitivity: 'base' });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function numberCompare(a = 0, b = 0, isAsc: boolean): number {
|
|
114
|
-
return isAsc ? a - b : b - a;
|
|
115
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computed,
|
|
3
|
-
linkedSignal,
|
|
4
|
-
resource,
|
|
5
|
-
ResourceLoaderParams,
|
|
6
|
-
ResourceRef,
|
|
7
|
-
type ResourceStatus,
|
|
8
|
-
signal,
|
|
9
|
-
} from '@angular/core';
|
|
10
|
-
import { UniBaseDatasource, Sort, SortDirection } from './base-datasource';
|
|
11
|
-
|
|
12
|
-
export interface PageRequest {
|
|
13
|
-
pageNumber: number;
|
|
14
|
-
pageSize: number;
|
|
15
|
-
sortColumn?: string;
|
|
16
|
-
sortDirection?: SortDirection;
|
|
17
|
-
filter?: Record<string, any>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface PageResponse<T> {
|
|
21
|
-
data: T[];
|
|
22
|
-
totalRecords: number;
|
|
23
|
-
pageNumber: number;
|
|
24
|
-
pageSize: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type DataLoader<T> = (request: PageRequest) => Promise<PageResponse<T>>;
|
|
28
|
-
|
|
29
|
-
export class UniServerSideDatasource<T> extends UniBaseDatasource<T> {
|
|
30
|
-
private _pageNumber = signal(1);
|
|
31
|
-
private _pageSize = signal(10);
|
|
32
|
-
private _sortColumn = signal<keyof T | undefined>(undefined);
|
|
33
|
-
private _sortDirection = signal<SortDirection>('indet');
|
|
34
|
-
private filter = signal<Record<string, any>>({});
|
|
35
|
-
|
|
36
|
-
override sortColumn = computed(() => this._sortColumn());
|
|
37
|
-
override sortDirection = computed(() => this._sortDirection());
|
|
38
|
-
|
|
39
|
-
private totalRecords = signal(0);
|
|
40
|
-
|
|
41
|
-
private dataResource: ResourceRef<PageResponse<T> | undefined>;
|
|
42
|
-
|
|
43
|
-
override pageIndex = computed(() => this._pageNumber() - 1);
|
|
44
|
-
override pageSize = computed(() => this._pageSize());
|
|
45
|
-
|
|
46
|
-
override pageCount = computed(() => {
|
|
47
|
-
const total = this.totalRecords();
|
|
48
|
-
const size = this.pageSize();
|
|
49
|
-
return total > 0 ? Math.ceil(total / size) : 0;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
private readonly _records = linkedSignal<
|
|
53
|
-
{
|
|
54
|
-
val: PageResponse<T> | undefined;
|
|
55
|
-
status: ResourceStatus;
|
|
56
|
-
},
|
|
57
|
-
T[]
|
|
58
|
-
>({
|
|
59
|
-
source: () => ({
|
|
60
|
-
val: this.dataResource.value(),
|
|
61
|
-
status: this.dataResource.status(),
|
|
62
|
-
}),
|
|
63
|
-
computation: (source, previous) => {
|
|
64
|
-
if (source.status === 'loading' && previous) {
|
|
65
|
-
return previous.value;
|
|
66
|
-
}
|
|
67
|
-
return source.val?.data ?? [];
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
override records = this._records.asReadonly();
|
|
72
|
-
|
|
73
|
-
override recordCount = computed(() => this.totalRecords());
|
|
74
|
-
|
|
75
|
-
isLoading = computed(() => this.dataResource.isLoading());
|
|
76
|
-
|
|
77
|
-
error = computed(() => this.dataResource.error());
|
|
78
|
-
|
|
79
|
-
hasError = computed(() => this.dataResource.hasValue() === false && this.error() !== undefined);
|
|
80
|
-
|
|
81
|
-
constructor(
|
|
82
|
-
private dataLoader: DataLoader<T>,
|
|
83
|
-
initialPageSize = 10
|
|
84
|
-
) {
|
|
85
|
-
super();
|
|
86
|
-
this._pageSize.set(initialPageSize);
|
|
87
|
-
|
|
88
|
-
this.dataResource = resource({
|
|
89
|
-
params: () => ({
|
|
90
|
-
pageNumber: this._pageNumber(),
|
|
91
|
-
pageSize: this._pageSize(),
|
|
92
|
-
sortColumn: this._sortColumn() as string | undefined,
|
|
93
|
-
sortDirection: this._sortDirection(),
|
|
94
|
-
filter: this.filter(),
|
|
95
|
-
}),
|
|
96
|
-
loader: async (params: ResourceLoaderParams<PageRequest>) => {
|
|
97
|
-
const request = params.params;
|
|
98
|
-
const response = await this.dataLoader(request);
|
|
99
|
-
|
|
100
|
-
if (request.pageNumber === 1 || this.totalRecords() === 0) {
|
|
101
|
-
this.totalRecords.set(response.totalRecords);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return response;
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
override sortRecords(sort: Sort<T>) {
|
|
110
|
-
this.sort.set(sort);
|
|
111
|
-
this._sortColumn.set(sort.column);
|
|
112
|
-
this._sortDirection.set(sort.direction);
|
|
113
|
-
this._pageNumber.set(1);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
override firstPage() {
|
|
117
|
-
this._pageNumber.set(1);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
override nextPage() {
|
|
121
|
-
if (this._pageNumber() < this.pageCount()) {
|
|
122
|
-
this._pageNumber.update((n) => n + 1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
override previousPage() {
|
|
127
|
-
if (this._pageNumber() > 1) {
|
|
128
|
-
this._pageNumber.update((n) => n - 1);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
override lastPage() {
|
|
133
|
-
this._pageNumber.set(this.pageCount());
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
override jumpToPage(page: number) {
|
|
137
|
-
if (page >= 1 && page <= this.pageCount()) {
|
|
138
|
-
this._pageNumber.set(page);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
override setPageSize(size: number) {
|
|
143
|
-
if (size > 0) {
|
|
144
|
-
this._pageSize.set(size);
|
|
145
|
-
this._pageNumber.set(1);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
setFilter(filterValues: Record<string, any>) {
|
|
150
|
-
this.filter.set(filterValues);
|
|
151
|
-
this._pageNumber.set(1);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
clearFilter() {
|
|
155
|
-
this.filter.set({});
|
|
156
|
-
this._pageNumber.set(1);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
refresh() {
|
|
160
|
-
this.dataResource.reload();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
getPageRequest(): PageRequest {
|
|
164
|
-
return {
|
|
165
|
-
pageNumber: this._pageNumber(),
|
|
166
|
-
pageSize: this._pageSize(),
|
|
167
|
-
sortColumn: this._sortColumn() as string | undefined,
|
|
168
|
-
sortDirection: this._sortDirection(),
|
|
169
|
-
filter: this.filter(),
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function memoize<T extends (...args: any[]) => any>(fn: T): T {
|
|
2
|
-
const cache = new Map<string, ReturnType<T>>();
|
|
3
|
-
|
|
4
|
-
return ((...args: Parameters<T>): ReturnType<T> => {
|
|
5
|
-
const key = JSON.stringify(args);
|
|
6
|
-
|
|
7
|
-
if (cache.has(key)) {
|
|
8
|
-
return cache.get(key)!;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const result = fn(...args);
|
|
12
|
-
cache.set(key, result);
|
|
13
|
-
return result;
|
|
14
|
-
}) as T;
|
|
15
|
-
}
|
package/src/lib/cdk/index.ts
DELETED