@stephenchenorg/astro 1.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/LICENSE.md +21 -0
- package/README.md +24 -0
- package/dist/api/error.d.ts +29 -0
- package/dist/api/error.js +74 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/company-setting/fragments.d.ts +1 -0
- package/dist/company-setting/fragments.js +20 -0
- package/dist/company-setting/index.d.ts +2 -0
- package/dist/company-setting/index.js +2 -0
- package/dist/company-setting/types.d.ts +20 -0
- package/dist/company-setting/types.js +0 -0
- package/dist/image/components/Image.astro +10 -0
- package/dist/image/components/ResponsiveImage.astro +23 -0
- package/dist/image/fragments.d.ts +3 -0
- package/dist/image/fragments.js +25 -0
- package/dist/image/index.d.ts +5 -0
- package/dist/image/index.js +5 -0
- package/dist/image/types.d.ts +6 -0
- package/dist/image/types.js +0 -0
- package/dist/page/components/PageFieldRender.astro +34 -0
- package/dist/page/field/fragments.d.ts +5 -0
- package/dist/page/field/fragments.js +23 -0
- package/dist/page/field/helpers.d.ts +7 -0
- package/dist/page/field/helpers.js +20 -0
- package/dist/page/field/index.d.ts +2 -0
- package/dist/page/field/index.js +2 -0
- package/dist/page/index.d.ts +5 -0
- package/dist/page/index.js +5 -0
- package/dist/page/seo-meta/fragments.d.ts +1 -0
- package/dist/page/seo-meta/fragments.js +14 -0
- package/dist/page/seo-meta/helpers.d.ts +7 -0
- package/dist/page/seo-meta/helpers.js +14 -0
- package/dist/page/seo-meta/index.d.ts +2 -0
- package/dist/page/seo-meta/index.js +2 -0
- package/dist/page/types.d.ts +69 -0
- package/dist/page/types.js +0 -0
- package/dist/pagination/index.d.ts +2 -0
- package/dist/pagination/index.js +2 -0
- package/dist/pagination/stub/Pagination.astro +39 -0
- package/dist/pagination/types.d.ts +5 -0
- package/dist/pagination/types.js +0 -0
- package/dist/pagination/usePagination.d.ts +20 -0
- package/dist/pagination/usePagination.js +42 -0
- package/dist/query-params/components/ProvideUrlConfig.astro +30 -0
- package/dist/query-params/config.d.ts +2 -0
- package/dist/query-params/config.js +3 -0
- package/dist/query-params/index.d.ts +6 -0
- package/dist/query-params/index.js +6 -0
- package/dist/query-params/store.d.ts +2 -0
- package/dist/query-params/store.js +6 -0
- package/dist/query-params/types.d.ts +5 -0
- package/dist/query-params/types.js +0 -0
- package/dist/query-params/url.d.ts +7 -0
- package/dist/query-params/url.js +25 -0
- package/dist/query-params/utils.d.ts +2 -0
- package/dist/query-params/utils.js +19 -0
- package/package.json +81 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Lucas Yang <yangchenshin77@gmail.com>
|
|
4
|
+
|
|
5
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
> in the Software without restriction, including without limitation the rights
|
|
8
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
> furnished to do so, subject to the following conditions:
|
|
11
|
+
>
|
|
12
|
+
> The above copyright notice and this permission notice shall be included in
|
|
13
|
+
> all copies or substantial portions of the Software.
|
|
14
|
+
>
|
|
15
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
> THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Stephenchenorg Astro 前端通用套件
|
|
2
|
+
|
|
3
|
+
## 使用
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# npm
|
|
7
|
+
npm install @stephenchenorg/astro
|
|
8
|
+
# yarn
|
|
9
|
+
yarn add @stephenchenorg/astro
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 開發
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn
|
|
16
|
+
yarn build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 發布新版
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm login
|
|
23
|
+
npm publish
|
|
24
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface GraphQLRequestExtensions {
|
|
2
|
+
debugMessage?: string;
|
|
3
|
+
file?: string;
|
|
4
|
+
line?: number;
|
|
5
|
+
trace?: {
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
call: number;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export declare class GraphQLRequestError extends Error {
|
|
12
|
+
type: string;
|
|
13
|
+
name: string;
|
|
14
|
+
title: string;
|
|
15
|
+
originalMessage: string;
|
|
16
|
+
query: string;
|
|
17
|
+
variables: Record<string, any> | undefined;
|
|
18
|
+
extensions: GraphQLRequestExtensions | undefined;
|
|
19
|
+
constructor(props: {
|
|
20
|
+
message: string;
|
|
21
|
+
query: string;
|
|
22
|
+
variables?: Record<string, any>;
|
|
23
|
+
extensions?: GraphQLRequestExtensions;
|
|
24
|
+
}, options?: ErrorOptions);
|
|
25
|
+
isNotFound(): boolean;
|
|
26
|
+
private buildMessage;
|
|
27
|
+
static is(err: unknown): err is GraphQLRequestError;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export class GraphQLRequestError extends Error {
|
|
2
|
+
type = "GraphQLRequestError";
|
|
3
|
+
name = "GraphQLRequestError";
|
|
4
|
+
title = "GraphQL request error.";
|
|
5
|
+
originalMessage;
|
|
6
|
+
query;
|
|
7
|
+
variables;
|
|
8
|
+
extensions;
|
|
9
|
+
constructor(props, options) {
|
|
10
|
+
const { message, query, variables, extensions } = props;
|
|
11
|
+
super("GraphQL request error.", options);
|
|
12
|
+
const originalStack = this.stack;
|
|
13
|
+
this.title = "GraphQL request error.";
|
|
14
|
+
this.originalMessage = message;
|
|
15
|
+
this.query = query;
|
|
16
|
+
this.variables = variables;
|
|
17
|
+
this.extensions = extensions;
|
|
18
|
+
this.message = this.buildMessage();
|
|
19
|
+
this.stack = originalStack;
|
|
20
|
+
}
|
|
21
|
+
isNotFound() {
|
|
22
|
+
return this.originalMessage.includes("Http Status 404");
|
|
23
|
+
}
|
|
24
|
+
buildMessage() {
|
|
25
|
+
let message = `${this.originalMessage}
|
|
26
|
+
`;
|
|
27
|
+
if (this.extensions) {
|
|
28
|
+
if (this.extensions.debugMessage) {
|
|
29
|
+
message += "\n";
|
|
30
|
+
message += `${this.extensions.debugMessage}
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
if (this.extensions.file || this.extensions.line || this.extensions.trace) {
|
|
34
|
+
message += "\n";
|
|
35
|
+
message += "[stacktrace]\n";
|
|
36
|
+
if (this.extensions.file) {
|
|
37
|
+
message += `file: ${this.extensions.file}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
if (this.extensions.line) {
|
|
41
|
+
message += `line: ${this.extensions.line}
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
if (this.extensions.trace && Array.isArray(this.extensions.trace)) {
|
|
45
|
+
message += "trace:\n";
|
|
46
|
+
for (const trace of this.extensions.trace.slice(0, 3)) {
|
|
47
|
+
message += ` - file: ${trace.file}
|
|
48
|
+
`;
|
|
49
|
+
message += ` line: ${trace.line}
|
|
50
|
+
`;
|
|
51
|
+
message += ` call: ${trace.call}
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (this.query) {
|
|
58
|
+
message += "\n";
|
|
59
|
+
message += `[query]
|
|
60
|
+
${this.query}
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
if (this.variables) {
|
|
64
|
+
message += "\n";
|
|
65
|
+
message += `[variables]
|
|
66
|
+
${JSON.stringify(this.variables, null, 2)}
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
return message;
|
|
70
|
+
}
|
|
71
|
+
static is(err) {
|
|
72
|
+
return err.type === "GraphQLRequestError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './error';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./error.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const companySettingFields: import("graphql/language/ast").DocumentNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
export const companySettingFields = gql`
|
|
3
|
+
fragment CompanySettingFields on CompanySetting {
|
|
4
|
+
lang
|
|
5
|
+
name
|
|
6
|
+
description
|
|
7
|
+
logo
|
|
8
|
+
address_1
|
|
9
|
+
address_2
|
|
10
|
+
email_1
|
|
11
|
+
email_2
|
|
12
|
+
fb_link
|
|
13
|
+
ig_link
|
|
14
|
+
line_link
|
|
15
|
+
phone_1
|
|
16
|
+
phone_2
|
|
17
|
+
twitter_link
|
|
18
|
+
threads_link
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface DataCompanySetting {
|
|
2
|
+
companySetting: CompanySetting;
|
|
3
|
+
}
|
|
4
|
+
export interface CompanySetting {
|
|
5
|
+
lang: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
logo: string;
|
|
9
|
+
address_1: string;
|
|
10
|
+
address_2: string;
|
|
11
|
+
email_1: string;
|
|
12
|
+
email_2: string;
|
|
13
|
+
fb_link: string;
|
|
14
|
+
ig_link: string;
|
|
15
|
+
line_link: string;
|
|
16
|
+
phone_1: string;
|
|
17
|
+
phone_2: string;
|
|
18
|
+
twitter_link: string;
|
|
19
|
+
threads_link: string;
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
interface Props extends astroHTML.JSX.ImgHTMLAttributes {
|
|
3
|
+
desktop: string | null
|
|
4
|
+
desktopBlur?: string | null
|
|
5
|
+
mobile?: string | null
|
|
6
|
+
mobileBlur?: string | null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { desktop, desktopBlur, mobile, mobileBlur, src: _, ...attributes } = Astro.props
|
|
10
|
+
|
|
11
|
+
const breakpoint = 768
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
{desktop && (
|
|
15
|
+
mobile ? (
|
|
16
|
+
<picture>
|
|
17
|
+
{mobile && <source media={`(max-width: ${breakpoint - 0.02}px)`} srcset={mobile} />}
|
|
18
|
+
<img src={desktop} {...attributes} />
|
|
19
|
+
</picture>
|
|
20
|
+
) : (
|
|
21
|
+
<img src={desktop} {...attributes} />
|
|
22
|
+
)
|
|
23
|
+
)}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
export const imageFields = gql`
|
|
3
|
+
fragment ImageFields on Image {
|
|
4
|
+
desktop
|
|
5
|
+
desktop_blur
|
|
6
|
+
mobile
|
|
7
|
+
mobile_blur
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
export const coverFields = gql`
|
|
11
|
+
fragment CoverFields on Cover {
|
|
12
|
+
desktop
|
|
13
|
+
desktop_blur
|
|
14
|
+
mobile
|
|
15
|
+
mobile_blur
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
export const backgroundFields = gql`
|
|
19
|
+
fragment BackgroundFields on Background {
|
|
20
|
+
desktop
|
|
21
|
+
desktop_blur
|
|
22
|
+
mobile
|
|
23
|
+
mobile_blur
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { isPlainTextField, isPlainTextareaField, isContentField, isImageField } from '../field/helpers'
|
|
3
|
+
import type { PageField } from '../types'
|
|
4
|
+
import { ResponsiveImage } from '../../image'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
fields: PageField[]
|
|
8
|
+
key: string
|
|
9
|
+
attributes?: Record<string, any>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { fields, key, attributes } = Astro.props
|
|
13
|
+
|
|
14
|
+
const field = fields.find(field => field.key === key)
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
field && (
|
|
19
|
+
isPlainTextField(field) ? <Fragment set:text={field.content} /> :
|
|
20
|
+
isPlainTextareaField(field) ? <Fragment set:html={field.content} /> :
|
|
21
|
+
isContentField(field) ? <Fragment set:html={field.content} /> :
|
|
22
|
+
isImageField(field) ? (
|
|
23
|
+
<ResponsiveImage
|
|
24
|
+
desktop={field.image.desktop}
|
|
25
|
+
desktopBlur={field.image.desktop_blur}
|
|
26
|
+
mobile={field.image.mobile}
|
|
27
|
+
mobileBlur={field.image.mobile_blur}
|
|
28
|
+
alt={`Image of ${key}`}
|
|
29
|
+
{...attributes}
|
|
30
|
+
/>
|
|
31
|
+
) :
|
|
32
|
+
null
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
export const pageFields = gql`
|
|
3
|
+
fragment PageFields on Page {
|
|
4
|
+
title
|
|
5
|
+
seo_title
|
|
6
|
+
seo_description
|
|
7
|
+
seo_keyword
|
|
8
|
+
seo_json_ld
|
|
9
|
+
seo_head
|
|
10
|
+
seo_body
|
|
11
|
+
og_title
|
|
12
|
+
og_description
|
|
13
|
+
og_image
|
|
14
|
+
fields {
|
|
15
|
+
key
|
|
16
|
+
content
|
|
17
|
+
type
|
|
18
|
+
image {
|
|
19
|
+
...ImageFields
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PageField, PagePlainTextField, PagePlainTextareaField, PageContentField, PageImageField } from '../types';
|
|
2
|
+
export declare function isPlainTextField(field: PageField): field is PagePlainTextField;
|
|
3
|
+
export declare function isPlainTextareaField(field: PageField): field is PagePlainTextareaField;
|
|
4
|
+
export declare function isContentField(field: PageField): field is PageContentField;
|
|
5
|
+
export declare function isImageField(field: PageField): field is PageImageField;
|
|
6
|
+
export declare function pageTextField(fields: PageField[], key: string): any;
|
|
7
|
+
export declare function pageImageFieldForBackground(fields: PageField[], key: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function isPlainTextField(field) {
|
|
2
|
+
return field.type === "text";
|
|
3
|
+
}
|
|
4
|
+
export function isPlainTextareaField(field) {
|
|
5
|
+
return field.type === "textarea";
|
|
6
|
+
}
|
|
7
|
+
export function isContentField(field) {
|
|
8
|
+
return field.type === "html";
|
|
9
|
+
}
|
|
10
|
+
export function isImageField(field) {
|
|
11
|
+
return field.type === "image";
|
|
12
|
+
}
|
|
13
|
+
export function pageTextField(fields, key) {
|
|
14
|
+
const field = fields.find((field2) => field2.key === key && isPlainTextField(field2));
|
|
15
|
+
return field ? field.content : "";
|
|
16
|
+
}
|
|
17
|
+
export function pageImageFieldForBackground(fields, key) {
|
|
18
|
+
const field = fields.find((field2) => field2.key === key && isImageField(field2));
|
|
19
|
+
return field ? `background-image: url('${field.image.desktop}');` : "";
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const seoMetaFields: (dummyClass: string) => import("graphql/language/ast").DocumentNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
export const seoMetaFields = (dummyClass) => gql(`
|
|
3
|
+
fragment DummyClassSeoMetaFields on DummyClass {
|
|
4
|
+
seo_title
|
|
5
|
+
seo_description
|
|
6
|
+
seo_keyword
|
|
7
|
+
seo_json_ld
|
|
8
|
+
seo_head
|
|
9
|
+
seo_body
|
|
10
|
+
og_title
|
|
11
|
+
og_description
|
|
12
|
+
og_image
|
|
13
|
+
}
|
|
14
|
+
`.replace(/DummyClass/g, dummyClass));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PageMeta } from '../types';
|
|
2
|
+
export type UseSeoMetaOptions = Partial<Omit<PageMeta, 'title'>> & {
|
|
3
|
+
title: string;
|
|
4
|
+
description?: string | null;
|
|
5
|
+
image?: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function seoMeta(options: UseSeoMetaOptions, userOptions?: PageMeta): PageMeta;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function seoMeta(options, userOptions) {
|
|
2
|
+
return {
|
|
3
|
+
title: userOptions?.title || options.title,
|
|
4
|
+
seo_title: userOptions?.seo_title || options.seo_title || null,
|
|
5
|
+
seo_description: userOptions?.seo_description || options.description || null,
|
|
6
|
+
seo_keyword: userOptions?.seo_keyword || options.seo_keyword || null,
|
|
7
|
+
seo_json_ld: userOptions?.seo_json_ld || options.seo_json_ld || null,
|
|
8
|
+
seo_head: userOptions?.seo_head || options.seo_head,
|
|
9
|
+
seo_body: userOptions?.seo_body || options.seo_body,
|
|
10
|
+
og_title: userOptions?.og_title || options.og_title || options.title || null,
|
|
11
|
+
og_description: userOptions?.og_description || options.og_description || options.description || null,
|
|
12
|
+
og_image: userOptions?.og_image || options.og_image || options.image || null
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export interface DataPage {
|
|
2
|
+
page: Page;
|
|
3
|
+
}
|
|
4
|
+
export interface Page extends PageMeta {
|
|
5
|
+
fields: PageField[];
|
|
6
|
+
}
|
|
7
|
+
export interface PageMeta {
|
|
8
|
+
title: string;
|
|
9
|
+
seo_title: string | null;
|
|
10
|
+
seo_description: string | null;
|
|
11
|
+
seo_keyword: string | null;
|
|
12
|
+
seo_json_ld: string | null;
|
|
13
|
+
seo_head?: string | null;
|
|
14
|
+
seo_body?: string | null;
|
|
15
|
+
og_title: string | null;
|
|
16
|
+
og_description: string | null;
|
|
17
|
+
og_image: string | null;
|
|
18
|
+
}
|
|
19
|
+
export interface PageField {
|
|
20
|
+
key: string;
|
|
21
|
+
type: 'text' | 'textarea' | 'html' | 'image';
|
|
22
|
+
content: string | null;
|
|
23
|
+
image: {
|
|
24
|
+
desktop: string | null;
|
|
25
|
+
desktop_blur: string | null;
|
|
26
|
+
mobile: string | null;
|
|
27
|
+
mobile_blur: string | null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface PagePlainTextField extends PageField {
|
|
31
|
+
type: 'text';
|
|
32
|
+
content: string;
|
|
33
|
+
image: {
|
|
34
|
+
desktop: null;
|
|
35
|
+
desktop_blur: null;
|
|
36
|
+
mobile: null;
|
|
37
|
+
mobile_blur: null;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface PagePlainTextareaField extends PageField {
|
|
41
|
+
type: 'textarea';
|
|
42
|
+
content: string;
|
|
43
|
+
image: {
|
|
44
|
+
desktop: null;
|
|
45
|
+
desktop_blur: null;
|
|
46
|
+
mobile: null;
|
|
47
|
+
mobile_blur: null;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface PageContentField extends PageField {
|
|
51
|
+
type: 'html';
|
|
52
|
+
content: string;
|
|
53
|
+
image: {
|
|
54
|
+
desktop: null;
|
|
55
|
+
desktop_blur: null;
|
|
56
|
+
mobile: null;
|
|
57
|
+
mobile_blur: null;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface PageImageField extends PageField {
|
|
61
|
+
type: 'image';
|
|
62
|
+
content: null;
|
|
63
|
+
image: {
|
|
64
|
+
desktop: string;
|
|
65
|
+
desktop_blur: string;
|
|
66
|
+
mobile: string;
|
|
67
|
+
mobile_blur: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
canPrev,
|
|
16
|
+
canNext,
|
|
17
|
+
prevUrl,
|
|
18
|
+
nextUrl,
|
|
19
|
+
getUrl,
|
|
20
|
+
} = usePagination({
|
|
21
|
+
total: Astro.props.total,
|
|
22
|
+
perPage: Astro.props.perPage,
|
|
23
|
+
visiblePages: Astro.props.visiblePages,
|
|
24
|
+
currentPage: Astro.props.currentPage || Number(Astro.url.searchParams.get('page')) || 1,
|
|
25
|
+
url: Astro.request.url,
|
|
26
|
+
})
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
{showPagination && (
|
|
30
|
+
<div>
|
|
31
|
+
{canPrev && <a href={prevUrl}><</a>}
|
|
32
|
+
{items.map(page =>
|
|
33
|
+
page === currentPage
|
|
34
|
+
? <span>{page}</span>
|
|
35
|
+
: <a href={getUrl(page)}>{page}</a>
|
|
36
|
+
)}
|
|
37
|
+
{canNext && <a href={nextUrl}>></a>}
|
|
38
|
+
</div>
|
|
39
|
+
)}
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function usePagination(options: {
|
|
2
|
+
total: number;
|
|
3
|
+
currentPage: number;
|
|
4
|
+
url: string;
|
|
5
|
+
perPage?: number;
|
|
6
|
+
visiblePages?: number;
|
|
7
|
+
}): {
|
|
8
|
+
items: never[];
|
|
9
|
+
showPagination: boolean;
|
|
10
|
+
currentPage: number;
|
|
11
|
+
canFirst: boolean;
|
|
12
|
+
canPrev: boolean;
|
|
13
|
+
canNext: boolean;
|
|
14
|
+
canLast: boolean;
|
|
15
|
+
firstUrl: string;
|
|
16
|
+
prevUrl: string;
|
|
17
|
+
nextUrl: string;
|
|
18
|
+
lastUrl: string;
|
|
19
|
+
getUrl: (page: number) => string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function usePagination(options) {
|
|
2
|
+
const {
|
|
3
|
+
total,
|
|
4
|
+
currentPage,
|
|
5
|
+
perPage = 12
|
|
6
|
+
} = options;
|
|
7
|
+
const items = [];
|
|
8
|
+
const totalPages = Math.ceil(total / perPage);
|
|
9
|
+
const visiblePages = Math.min(options.visiblePages || 5, totalPages);
|
|
10
|
+
const sideCount = Math.floor(visiblePages / 2);
|
|
11
|
+
let start = Math.max(1, currentPage - sideCount);
|
|
12
|
+
let end = Math.min(totalPages, currentPage + sideCount);
|
|
13
|
+
if (end - start + 1 < visiblePages && currentPage > 0) {
|
|
14
|
+
if (currentPage <= sideCount) {
|
|
15
|
+
end = Math.min(totalPages, start + visiblePages - 1);
|
|
16
|
+
} else if (currentPage > totalPages - sideCount) {
|
|
17
|
+
start = Math.max(1, end - visiblePages + 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (let i = start; i <= end; i++) {
|
|
21
|
+
items.push(i);
|
|
22
|
+
}
|
|
23
|
+
function getUrl(page) {
|
|
24
|
+
const url = new URL(options.url);
|
|
25
|
+
url.searchParams.set("page", String(page));
|
|
26
|
+
return url.toString();
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
items,
|
|
30
|
+
showPagination: total > perPage,
|
|
31
|
+
currentPage,
|
|
32
|
+
canFirst: currentPage > 1,
|
|
33
|
+
canPrev: currentPage > 1,
|
|
34
|
+
canNext: currentPage < totalPages,
|
|
35
|
+
canLast: currentPage < totalPages,
|
|
36
|
+
firstUrl: getUrl(1),
|
|
37
|
+
prevUrl: getUrl(currentPage - 1),
|
|
38
|
+
nextUrl: getUrl(currentPage + 1),
|
|
39
|
+
lastUrl: getUrl(totalPages),
|
|
40
|
+
getUrl
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { UrlConfig } from '../types'
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
config: UrlConfig
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const config: UrlConfig = {
|
|
9
|
+
baseUrl: Astro.props.config.baseUrl,
|
|
10
|
+
params: Astro.props.config.params,
|
|
11
|
+
defaultParams: Astro.props.config.defaultParams,
|
|
12
|
+
}
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<script is:inline define:vars={{ config }}>
|
|
16
|
+
window.__astro_provide_url_config__ = config;
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script>
|
|
20
|
+
import { urlConfigStore } from '../store'
|
|
21
|
+
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const props = window.__astro_provide_url_config__
|
|
24
|
+
|
|
25
|
+
const baseUrl: string = props?.baseUrl || location.pathname
|
|
26
|
+
const params: Record<string, any> = props?.params || {}
|
|
27
|
+
const defaultParams: Record<string, any> = props?.defaultParams || {}
|
|
28
|
+
|
|
29
|
+
urlConfigStore.set({ baseUrl, params, defaultParams })
|
|
30
|
+
</script>
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import qs from 'query-string';
|
|
2
|
+
import type { UrlConfig } from './types';
|
|
3
|
+
export interface QueryParamsUrlOptions {
|
|
4
|
+
transformParams?: (params: Record<string, any>) => Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
export declare function queryParamsUrl(additionalParams: Record<string, any>, urlConfig?: UrlConfig, options?: QueryParamsUrlOptions): string;
|
|
7
|
+
export declare function parseQueryParams(search: string): qs.ParsedQuery<string>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import qs from "query-string";
|
|
2
|
+
import { urlConfigStore } from "./store.js";
|
|
3
|
+
import { cleanParams, mergeUrlParams } from "./utils.js";
|
|
4
|
+
export function queryParamsUrl(additionalParams, urlConfig = {
|
|
5
|
+
baseUrl: "",
|
|
6
|
+
params: {},
|
|
7
|
+
defaultParams: {}
|
|
8
|
+
}, options = {}) {
|
|
9
|
+
const { transformParams } = options;
|
|
10
|
+
const config = typeof window !== "undefined" ? urlConfigStore.get() : urlConfig;
|
|
11
|
+
let params = mergeUrlParams(config.params, additionalParams);
|
|
12
|
+
if (transformParams) {
|
|
13
|
+
params = transformParams(params);
|
|
14
|
+
}
|
|
15
|
+
const cleanedParams = cleanParams(params, config.defaultParams || {});
|
|
16
|
+
const queryString = qs.stringify(cleanedParams, {
|
|
17
|
+
skipEmptyString: true,
|
|
18
|
+
skipNull: true,
|
|
19
|
+
sort: false
|
|
20
|
+
});
|
|
21
|
+
return `${config.baseUrl}${queryString ? "?" : ""}${queryString}`;
|
|
22
|
+
}
|
|
23
|
+
export function parseQueryParams(search) {
|
|
24
|
+
return qs.parse(search);
|
|
25
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function mergeUrlParams<Params extends Record<string, any> = Record<string, any>>(baseParams: Params, userParams: Partial<Params>): Params;
|
|
2
|
+
export declare function cleanParams(params: Record<string, any>, defaultParams: Record<string, any>): Record<string, any>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function mergeUrlParams(baseParams, userParams) {
|
|
2
|
+
return Object.keys(baseParams).reduce((result, key) => {
|
|
3
|
+
if (Array.isArray(baseParams[key])) {
|
|
4
|
+
result[key] = Array.from(/* @__PURE__ */ new Set([...baseParams[key], ...userParams[key] || []]));
|
|
5
|
+
} else {
|
|
6
|
+
result[key] = typeof userParams[key] !== "undefined" ? userParams[key] : baseParams[key];
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
export function cleanParams(params, defaultParams) {
|
|
12
|
+
const newParams = JSON.parse(JSON.stringify(params));
|
|
13
|
+
Object.keys(newParams).forEach((key) => {
|
|
14
|
+
if (Object.keys(defaultParams).includes(key) && newParams[key] === defaultParams[key]) {
|
|
15
|
+
newParams[key] = null;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return newParams;
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stephenchenorg/astro",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Stephenchenorg Astro 前端通用套件",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://stephenchenorg-astro.netlify.app",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/stephenchenorg/astro.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"astro"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
"./api": {
|
|
17
|
+
"types": "./dist/api/index.d.ts",
|
|
18
|
+
"import": "./dist/api/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./company-setting": {
|
|
21
|
+
"types": "./dist/company-setting/index.d.ts",
|
|
22
|
+
"import": "./dist/company-setting/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./image": {
|
|
25
|
+
"types": "./dist/image/index.d.ts",
|
|
26
|
+
"import": "./dist/image/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./page": {
|
|
29
|
+
"types": "./dist/page/index.d.ts",
|
|
30
|
+
"import": "./dist/page/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./pagination": {
|
|
33
|
+
"types": "./dist/pagination/index.d.ts",
|
|
34
|
+
"import": "./dist/pagination/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./query-params": {
|
|
37
|
+
"types": "./dist/query-params/index.d.ts",
|
|
38
|
+
"import": "./dist/query-params/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"typesVersions": {
|
|
42
|
+
"*": {
|
|
43
|
+
"*": [
|
|
44
|
+
"./dist/*"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist"
|
|
50
|
+
],
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=22"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "mkdist --declaration --ext=js",
|
|
59
|
+
"code-check": "astro check",
|
|
60
|
+
"prepack": "npm run build",
|
|
61
|
+
"release": "bumpp --commit \"Release v%s\" && npm publish"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"astro": "^5.0.0"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"awesome-graphql-client": "^2.1.0",
|
|
68
|
+
"graphql": "^16.10.0",
|
|
69
|
+
"graphql-tag": "^2.12.6",
|
|
70
|
+
"nanostores": "^0.11.4",
|
|
71
|
+
"query-string": "^9.1.1"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@astrojs/check": "^0.9.4",
|
|
75
|
+
"@graphql-typed-document-node/core": "^3.2.0",
|
|
76
|
+
"astro": "^5.3.1",
|
|
77
|
+
"bumpp": "^10.0.3",
|
|
78
|
+
"mkdist": "^2.2.0",
|
|
79
|
+
"typescript": "~5.7.2"
|
|
80
|
+
}
|
|
81
|
+
}
|