@uni-design-system/uni-angular 2.0.2 → 2.0.3
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/package.json +18 -31
- 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/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/{dist/fesm2022 → fesm2022}/uni-design-system-uni-angular.mjs +0 -0
- /package/{dist/fesm2022 → fesm2022}/uni-design-system-uni-angular.mjs.map +0 -0
- /package/{dist/types → types}/uni-design-system-uni-angular.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uni-design-system/uni-angular",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/uni-design-system/uni",
|
|
@@ -8,43 +8,30 @@
|
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public",
|
|
11
|
-
"provenance": true
|
|
11
|
+
"provenance": true,
|
|
12
|
+
"directory": "dist"
|
|
12
13
|
},
|
|
13
14
|
"private": false,
|
|
14
15
|
"peerDependencies": {
|
|
15
16
|
"@angular/common": "21.2.12",
|
|
16
17
|
"@angular/core": "21.2.12",
|
|
17
18
|
"@emotion/css": "^11.0.0",
|
|
18
|
-
"@uni-design-system/uni-core": "2.0.
|
|
19
|
+
"@uni-design-system/uni-core": "2.0.3"
|
|
19
20
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"@storybook/addon-a11y": "^10.4.0",
|
|
31
|
-
"@storybook/addon-docs": "^10.4.0",
|
|
32
|
-
"@storybook/angular": "^10.4.0",
|
|
33
|
-
"@storybook/builder-vite": "^10.4.0",
|
|
34
|
-
"@types/react": "^18.3.28",
|
|
35
|
-
"ng-packagr": "^21.0.0",
|
|
36
|
-
"react": "^18.2.0",
|
|
37
|
-
"storybook": "^10.4.0",
|
|
38
|
-
"tslib": "^2.8.1",
|
|
39
|
-
"typescript": "5.9.3",
|
|
40
|
-
"vite": "^8.0.10",
|
|
41
|
-
"vite-tsconfig-paths": "^6.1.1",
|
|
42
|
-
"@uni-design-system/tsconfig": "0.0.0"
|
|
21
|
+
"module": "fesm2022/uni-design-system-uni-angular.mjs",
|
|
22
|
+
"typings": "types/uni-design-system-uni-angular.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
"./package.json": {
|
|
25
|
+
"default": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./types/uni-design-system-uni-angular.d.ts",
|
|
29
|
+
"default": "./fesm2022/uni-design-system-uni-angular.mjs"
|
|
30
|
+
}
|
|
43
31
|
},
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"release": "pnpm build && pnpm changeset publish"
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"type": "module",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"tslib": "^2.3.0"
|
|
49
36
|
}
|
|
50
37
|
}
|
package/.storybook/main.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { dirname } from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
import { mergeConfig } from 'vite';
|
|
4
|
-
import type { StorybookConfig as StorybookConfigBase } from '@storybook/angular';
|
|
5
|
-
import type { StorybookConfigVite } from '@storybook/builder-vite';
|
|
6
|
-
|
|
7
|
-
function getAbsolutePath(value: string) {
|
|
8
|
-
return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`)));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type StorybookConfig = StorybookConfigBase & StorybookConfigVite;
|
|
12
|
-
|
|
13
|
-
const config: StorybookConfig = {
|
|
14
|
-
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
|
|
15
|
-
addons: [getAbsolutePath('@storybook/addon-a11y'), getAbsolutePath('@storybook/addon-docs')],
|
|
16
|
-
framework: {
|
|
17
|
-
name: getAbsolutePath('@storybook/angular') as '@storybook/angular',
|
|
18
|
-
options: {
|
|
19
|
-
builder: {
|
|
20
|
-
name: getAbsolutePath('@storybook/builder-vite') as '@storybook/builder-vite',
|
|
21
|
-
options: {},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
staticDirs: ['../../../public'],
|
|
26
|
-
managerHead: (head) => `${head}<link rel="icon" href="/favicon.ico" />`,
|
|
27
|
-
async viteFinal(config) {
|
|
28
|
-
return mergeConfig(config, {
|
|
29
|
-
optimizeDeps: {
|
|
30
|
-
exclude: ['@angular/animations', '@angular/animations/browser'],
|
|
31
|
-
},
|
|
32
|
-
build: {
|
|
33
|
-
rollupOptions: {
|
|
34
|
-
external: ['@angular/animations', '@angular/animations/browser'],
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default config;
|
package/.storybook/manager.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { addons } from 'storybook/manager-api';
|
|
2
|
-
import { create } from 'storybook/theming';
|
|
3
|
-
|
|
4
|
-
const theme = create({
|
|
5
|
-
base: 'light',
|
|
6
|
-
brandTitle: 'UNI Design System',
|
|
7
|
-
brandUrl: 'https://uni-design-system.github.io/uni/docs/angular',
|
|
8
|
-
brandImage: 'uni-storybook-logo.png',
|
|
9
|
-
|
|
10
|
-
appBg: 'white',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
addons.setConfig({
|
|
14
|
-
theme,
|
|
15
|
-
sidebar: {
|
|
16
|
-
// This filter excludes individual stories from the sidebar list,
|
|
17
|
-
// leaving only the MDX documentation pages visible.
|
|
18
|
-
filters: {
|
|
19
|
-
patterns: (item) => {
|
|
20
|
-
return item.type === 'docs';
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
});
|
package/.storybook/preview.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { applicationConfig, type Preview } from '@storybook/angular';
|
|
2
|
-
import { UNI_THEMES } from '../src/lib/theming/theme.token';
|
|
3
|
-
import { UniThemes } from '@uni-design-system/uni-core';
|
|
4
|
-
|
|
5
|
-
const preview: Preview = {
|
|
6
|
-
parameters: {
|
|
7
|
-
controls: {
|
|
8
|
-
matchers: {
|
|
9
|
-
color: /(background|color)$/i,
|
|
10
|
-
date: /Date$/i,
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
decorators: [
|
|
15
|
-
applicationConfig({
|
|
16
|
-
providers: [{ provide: UNI_THEMES, useValue: UniThemes }],
|
|
17
|
-
}),
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default preview;
|
package/.storybook/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"moduleResolution": "bundler",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"types": ["node", "vite/client"],
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowSyntheticDefaultImports": true,
|
|
10
|
-
"resolveJsonModule": true,
|
|
11
|
-
"experimentalDecorators": true,
|
|
12
|
-
"emitDecoratorMetadata": true
|
|
13
|
-
},
|
|
14
|
-
"exclude": ["../src/test.ts", "../src/**/*.spec.ts"],
|
|
15
|
-
"include": [
|
|
16
|
-
"../src/**/*.ts",
|
|
17
|
-
"../src/**/*.tsx",
|
|
18
|
-
"../src/**/*.stories.ts",
|
|
19
|
-
"./preview.ts",
|
|
20
|
-
"./main.ts",
|
|
21
|
-
"./vite.config.ts"
|
|
22
|
-
],
|
|
23
|
-
"files": ["./typings.d.ts"]
|
|
24
|
-
}
|
package/.storybook/typings.d.ts
DELETED
package/.turbo/turbo-build.log
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
$ pnpm ng-packagr -p ng-package.json
|
|
2
|
-
Building Angular Package
|
|
3
|
-
|
|
4
|
-
------------------------------------------------------------------------------
|
|
5
|
-
Building entry point '@uni-design-system/uni-angular'
|
|
6
|
-
------------------------------------------------------------------------------
|
|
7
|
-
- Compiling with Angular sources in partial compilation mode.
|
|
8
|
-
[32m✔[39m Compiling with Angular sources in partial compilation mode.
|
|
9
|
-
[32m✔[39m Generating FESM and DTS bundles
|
|
10
|
-
- Copying assets
|
|
11
|
-
[32m✔[39m Copying assets
|
|
12
|
-
- Writing package manifest
|
|
13
|
-
[34mℹ[39m Removing scripts section in package.json as it's considered a potential security vulnerability.
|
|
14
|
-
[34mℹ[39m Removing devDependencies section in package.json.
|
|
15
|
-
[32m✔[39m Writing package manifest
|
|
16
|
-
[32m✔[39m Built @uni-design-system/uni-angular
|
|
17
|
-
|
|
18
|
-
------------------------------------------------------------------------------
|
|
19
|
-
Built Angular Package
|
|
20
|
-
- from: /home/runner/work/uni/uni/packages/angular
|
|
21
|
-
- to: /home/runner/work/uni/uni/packages/angular/dist
|
|
22
|
-
------------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
Build at: 2026-05-19T16:22:00.800Z - Time: 1835ms
|
|
25
|
-
|
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
|
-
}
|
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
|
-
}
|