@stephenchenorg/astro 1.6.0 → 3.0.0
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 +16 -2
- package/dist/api/fetch.d.ts +8 -3
- package/dist/api/fetch.js +6 -5
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/company-setting/index.d.ts +1 -1
- package/dist/company-setting/index.js +1 -1
- package/dist/page/field/helpers.d.ts +2 -2
- package/dist/pagination-vue/index.d.ts +2 -0
- package/dist/pagination-vue/index.js +2 -0
- package/dist/pagination-vue/types.d.ts +5 -0
- package/dist/pagination-vue/types.js +0 -0
- package/dist/pagination-vue/usePagination.d.ts +21 -0
- package/dist/pagination-vue/usePagination.js +44 -0
- package/dist/query-params/index.d.ts +1 -1
- package/dist/query-params/index.js +1 -1
- package/dist/query-params/url.d.ts +1 -1
- package/package.json +24 -13
- package/dist/pagination/stub/Pagination.astro +0 -45
- package/dist/{pagination → pagination-astro}/index.d.ts +1 -1
- package/dist/{pagination → pagination-astro}/index.js +1 -1
- /package/dist/{pagination → pagination-astro}/types.d.ts +0 -0
- /package/dist/{pagination → pagination-astro}/types.js +0 -0
- /package/dist/{pagination → pagination-astro}/usePagination.d.ts +0 -0
- /package/dist/{pagination → pagination-astro}/usePagination.js +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Stephenchenorg Astro 前端通用套件
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![NPM version][ico-version]][link-npm]
|
|
4
|
+
[![Software License][ico-license]](LICENSE)
|
|
5
|
+
[![Total Downloads][ico-downloads]][link-downloads]
|
|
6
|
+
|
|
7
|
+
## 安裝
|
|
4
8
|
|
|
5
9
|
```bash
|
|
6
10
|
# npm
|
|
@@ -9,6 +13,10 @@ npm install @stephenchenorg/astro
|
|
|
9
13
|
yarn add @stephenchenorg/astro
|
|
10
14
|
```
|
|
11
15
|
|
|
16
|
+
## 文件
|
|
17
|
+
|
|
18
|
+
https://stephenchenorg-astro.netlify.app
|
|
19
|
+
|
|
12
20
|
## 開發
|
|
13
21
|
|
|
14
22
|
```bash
|
|
@@ -16,9 +24,15 @@ yarn
|
|
|
16
24
|
yarn build
|
|
17
25
|
```
|
|
18
26
|
|
|
19
|
-
##
|
|
27
|
+
## 發布套件
|
|
20
28
|
|
|
21
29
|
```bash
|
|
22
30
|
npm login
|
|
23
31
|
npm run release
|
|
24
32
|
```
|
|
33
|
+
|
|
34
|
+
[ico-version]: https://img.shields.io/npm/v/@stephenchenorg/astro?style=flat-square
|
|
35
|
+
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen?style=flat-square
|
|
36
|
+
[ico-downloads]: https://img.shields.io/npm/dt/@stephenchenorg/astro?style=flat-square
|
|
37
|
+
[link-npm]: https://www.npmjs.com/package/@stephenchenorg/astro
|
|
38
|
+
[link-downloads]: https://www.npmjs.com/package/@stephenchenorg/astro
|
package/dist/api/fetch.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import type { APIContext } from 'astro';
|
|
2
3
|
export interface CreateGraphQLAPIOptions {
|
|
3
4
|
endpoint: string;
|
|
4
|
-
defaultVariables?: Record<string, any> | (() => Record<string, any>);
|
|
5
|
-
fetchOptions?: RequestInit | (() => RequestInit);
|
|
5
|
+
defaultVariables?: Record<string, any> | ((astroContext?: APIContext) => Record<string, any>);
|
|
6
|
+
fetchOptions?: RequestInit | ((astroContext?: APIContext) => RequestInit);
|
|
6
7
|
}
|
|
7
|
-
export declare function createGraphQLAPI(
|
|
8
|
+
export declare function createGraphQLAPI(globalOptions: CreateGraphQLAPIOptions): <TData extends Record<string, any>, TVariables extends Record<string, any> = Record<string, any>>(query: TypedDocumentNode<TData, TVariables>, options?: {
|
|
9
|
+
variables?: TVariables;
|
|
10
|
+
fetchOptions?: RequestInit;
|
|
11
|
+
Astro?: APIContext;
|
|
12
|
+
}) => Promise<TData>;
|
|
8
13
|
export { gql } from 'graphql-tag';
|
package/dist/api/fetch.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { AwesomeGraphQLClient, GraphQLRequestError as AwesomeGraphQLRequestError } from "awesome-graphql-client";
|
|
2
2
|
import { print } from "graphql/language/printer";
|
|
3
3
|
import { GraphQLNotFoundError, GraphQLRequestError, GraphQLValidationError } from "./error.js";
|
|
4
|
-
export function createGraphQLAPI(
|
|
4
|
+
export function createGraphQLAPI(globalOptions) {
|
|
5
5
|
const client = new AwesomeGraphQLClient({
|
|
6
|
-
endpoint:
|
|
6
|
+
endpoint: globalOptions.endpoint,
|
|
7
7
|
formatQuery: (query) => print(query)
|
|
8
8
|
});
|
|
9
|
-
return function graphQLAPI(query,
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
return function graphQLAPI(query, options) {
|
|
10
|
+
const { variables, fetchOptions, Astro: astroContext } = options || {};
|
|
11
|
+
const defaultVariables = typeof globalOptions.defaultVariables === "function" ? globalOptions.defaultVariables(astroContext) : globalOptions.defaultVariables;
|
|
12
|
+
const defaultFetchOptions = typeof globalOptions.fetchOptions === "function" ? globalOptions.fetchOptions(astroContext) : globalOptions.fetchOptions;
|
|
12
13
|
return new Promise((resolve, reject) => {
|
|
13
14
|
client.request(query, {
|
|
14
15
|
...defaultVariables,
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PageContentField, PageField, PageImageField,
|
|
1
|
+
import type { PageContentField, PageField, PageImageField, PagePlainTextareaField, PagePlainTextField } from '../types';
|
|
2
2
|
export declare function isPlainTextField(field: PageField): field is PagePlainTextField;
|
|
3
3
|
export declare function isPlainTextareaField(field: PageField): field is PagePlainTextareaField;
|
|
4
4
|
export declare function isContentField(field: PageField): field is PageContentField;
|
|
5
5
|
export declare function isImageField(field: PageField): field is PageImageField;
|
|
6
|
-
export declare function pageTextField(fields: PageField[], key: string):
|
|
6
|
+
export declare function pageTextField(fields: PageField[], key: string): string | null;
|
|
7
7
|
export declare function pageImageFieldForBackground(fields: PageField[], key: string): string;
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export declare function usePagination(options: {
|
|
3
|
+
total: MaybeRefOrGetter<number>;
|
|
4
|
+
currentPage: MaybeRefOrGetter<number>;
|
|
5
|
+
url: string;
|
|
6
|
+
perPage?: MaybeRefOrGetter<number>;
|
|
7
|
+
visiblePages?: MaybeRefOrGetter<number>;
|
|
8
|
+
}): {
|
|
9
|
+
items: import("vue").ComputedRef<number[]>;
|
|
10
|
+
showPagination: import("vue").ComputedRef<boolean>;
|
|
11
|
+
currentPage: import("vue").ComputedRef<number>;
|
|
12
|
+
canFirst: import("vue").ComputedRef<boolean>;
|
|
13
|
+
canPrev: import("vue").ComputedRef<boolean>;
|
|
14
|
+
canNext: import("vue").ComputedRef<boolean>;
|
|
15
|
+
canLast: import("vue").ComputedRef<boolean>;
|
|
16
|
+
firstUrl: import("vue").ComputedRef<string>;
|
|
17
|
+
prevUrl: import("vue").ComputedRef<string>;
|
|
18
|
+
nextUrl: import("vue").ComputedRef<string>;
|
|
19
|
+
lastUrl: import("vue").ComputedRef<string>;
|
|
20
|
+
getUrl: (page: number) => string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
2
|
+
export function usePagination(options) {
|
|
3
|
+
const total = computed(() => toValue(options.total));
|
|
4
|
+
const currentPage = computed(() => toValue(options.currentPage));
|
|
5
|
+
const perPage = computed(() => toValue(options.perPage || 12));
|
|
6
|
+
const totalPages = computed(() => Math.ceil(total.value / perPage.value));
|
|
7
|
+
const visiblePages = computed(() => Math.min(toValue(options.visiblePages || 5), totalPages.value));
|
|
8
|
+
const sideCount = computed(() => Math.floor(visiblePages.value / 2));
|
|
9
|
+
const items = computed(() => {
|
|
10
|
+
const items2 = [];
|
|
11
|
+
let start = Math.max(1, currentPage.value - sideCount.value);
|
|
12
|
+
let end = Math.min(totalPages.value, currentPage.value + sideCount.value);
|
|
13
|
+
if (end - start + 1 < visiblePages.value && currentPage.value > 0) {
|
|
14
|
+
if (currentPage.value <= sideCount.value) {
|
|
15
|
+
end = Math.min(totalPages.value, start + visiblePages.value - 1);
|
|
16
|
+
} else if (currentPage.value > totalPages.value - sideCount.value) {
|
|
17
|
+
start = Math.max(1, end - visiblePages.value + 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (let i = start; i <= end; i++) {
|
|
21
|
+
items2.push(i);
|
|
22
|
+
}
|
|
23
|
+
return items2;
|
|
24
|
+
});
|
|
25
|
+
function getUrl(page) {
|
|
26
|
+
const url = new URL(options.url);
|
|
27
|
+
url.searchParams.set("page", String(page));
|
|
28
|
+
return url.toString();
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
items,
|
|
32
|
+
showPagination: computed(() => total.value > perPage.value),
|
|
33
|
+
currentPage,
|
|
34
|
+
canFirst: computed(() => currentPage.value > 1),
|
|
35
|
+
canPrev: computed(() => currentPage.value > 1),
|
|
36
|
+
canNext: computed(() => currentPage.value < totalPages.value),
|
|
37
|
+
canLast: computed(() => currentPage.value < totalPages.value),
|
|
38
|
+
firstUrl: computed(() => getUrl(1)),
|
|
39
|
+
prevUrl: computed(() => getUrl(currentPage.value - 1)),
|
|
40
|
+
nextUrl: computed(() => getUrl(currentPage.value + 1)),
|
|
41
|
+
lastUrl: computed(() => getUrl(totalPages.value)),
|
|
42
|
+
getUrl
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ProvideUrlConfig from "./components/ProvideUrlConfig.astro";
|
|
2
2
|
export * from "./config.js";
|
|
3
3
|
export * from "./store.js";
|
|
4
|
+
export * from "./types.js";
|
|
4
5
|
export * from "./url.js";
|
|
5
6
|
export * from "./utils.js";
|
|
6
|
-
export * from "./types.js";
|
|
7
7
|
export { ProvideUrlConfig };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stephenchenorg/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"description": "Stephenchenorg Astro 前端通用套件",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://stephenchenorg-astro.netlify.app",
|
|
@@ -29,9 +29,13 @@
|
|
|
29
29
|
"types": "./dist/page/index.d.ts",
|
|
30
30
|
"import": "./dist/page/index.js"
|
|
31
31
|
},
|
|
32
|
-
"./pagination": {
|
|
33
|
-
"types": "./dist/pagination/index.d.ts",
|
|
34
|
-
"import": "./dist/pagination/index.js"
|
|
32
|
+
"./pagination-astro": {
|
|
33
|
+
"types": "./dist/pagination-astro/index.d.ts",
|
|
34
|
+
"import": "./dist/pagination-astro/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./pagination-vue": {
|
|
37
|
+
"types": "./dist/pagination-vue/index.d.ts",
|
|
38
|
+
"import": "./dist/pagination-vue/index.js"
|
|
35
39
|
},
|
|
36
40
|
"./query-params": {
|
|
37
41
|
"types": "./dist/query-params/index.d.ts",
|
|
@@ -55,31 +59,38 @@
|
|
|
55
59
|
"node": ">=22"
|
|
56
60
|
},
|
|
57
61
|
"scripts": {
|
|
58
|
-
"build": "mkdist --declaration --ext=js",
|
|
62
|
+
"build": "mkdist --declaration --ext=js && sh ./scripts/postbuild.sh",
|
|
59
63
|
"lint": "eslint \"*.{js,ts,json}\" \"src/**/*.ts\"",
|
|
60
64
|
"code-check": "astro check && npm run lint",
|
|
61
65
|
"prepack": "npm run build",
|
|
62
66
|
"release": "bumpp --commit \"Release v%s\" && npm publish"
|
|
63
67
|
},
|
|
64
68
|
"peerDependencies": {
|
|
65
|
-
"astro": "^5.0.0"
|
|
69
|
+
"astro": "^5.0.0",
|
|
70
|
+
"vue": "^3.3.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"vue": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
66
76
|
},
|
|
67
77
|
"dependencies": {
|
|
68
78
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
69
79
|
"awesome-graphql-client": "^2.1.0",
|
|
70
|
-
"graphql": "^16.
|
|
80
|
+
"graphql": "^16.11.0",
|
|
71
81
|
"graphql-tag": "^2.12.6",
|
|
72
82
|
"nanostores": "^1.0.1",
|
|
73
|
-
"query-string": "^9.
|
|
83
|
+
"query-string": "^9.2.0"
|
|
74
84
|
},
|
|
75
85
|
"devDependencies": {
|
|
76
86
|
"@astrojs/check": "^0.9.4",
|
|
77
|
-
"@ycs77/eslint-config": "^4.
|
|
78
|
-
"astro": "^5.
|
|
79
|
-
"bumpp": "^10.1.
|
|
80
|
-
"eslint": "^9.
|
|
87
|
+
"@ycs77/eslint-config": "^4.3.0",
|
|
88
|
+
"astro": "^5.9.1",
|
|
89
|
+
"bumpp": "^10.1.1",
|
|
90
|
+
"eslint": "^9.28.0",
|
|
81
91
|
"eslint-plugin-astro": "^1.3.1",
|
|
82
92
|
"mkdist": "^2.3.0",
|
|
83
|
-
"typescript": "
|
|
93
|
+
"typescript": "^5.8.3",
|
|
94
|
+
"vue": "^3.5.16"
|
|
84
95
|
}
|
|
85
96
|
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { usePagination } from '@stephenchenorg/astro/pagination'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
total: number
|
|
6
|
-
perPage?: number
|
|
7
|
-
visiblePages?: number
|
|
8
|
-
currentPage?: number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
items,
|
|
13
|
-
showPagination,
|
|
14
|
-
currentPage,
|
|
15
|
-
canFirst,
|
|
16
|
-
canPrev,
|
|
17
|
-
canNext,
|
|
18
|
-
canLast,
|
|
19
|
-
firstUrl,
|
|
20
|
-
prevUrl,
|
|
21
|
-
nextUrl,
|
|
22
|
-
lastUrl,
|
|
23
|
-
getUrl,
|
|
24
|
-
} = usePagination({
|
|
25
|
-
total: Astro.props.total,
|
|
26
|
-
perPage: Astro.props.perPage,
|
|
27
|
-
visiblePages: Astro.props.visiblePages,
|
|
28
|
-
currentPage: Astro.props.currentPage || Number(Astro.url.searchParams.get('page')) || 1,
|
|
29
|
-
url: Astro.request.url,
|
|
30
|
-
})
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
{showPagination && (
|
|
34
|
-
<div>
|
|
35
|
-
{canFirst && <a href={firstUrl}>First</a>}
|
|
36
|
-
{canPrev && <a href={prevUrl}>Previous</a>}
|
|
37
|
-
{items.map(page =>
|
|
38
|
-
page === currentPage
|
|
39
|
-
? <span>{page}</span>
|
|
40
|
-
: <a href={getUrl(page)}>{page}</a>
|
|
41
|
-
)}
|
|
42
|
-
{canNext && <a href={nextUrl}>Next</a>}
|
|
43
|
-
{canLast && <a href={lastUrl}>Last</a>}
|
|
44
|
-
</div>
|
|
45
|
-
)}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|