@stephenchenorg/astro 8.6.0 → 9.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 +4 -0
- package/dist/company-setting/index.d.ts +1 -6
- package/dist/company-setting/index.js +1 -25
- package/dist/page/index.d.ts +1 -79
- package/dist/page/index.js +1 -71
- package/dist/pagination-vue-client-side/index.d.ts +7 -7
- package/dist/pagination-vue-server-side/index.d.ts +11 -11
- package/package.json +6 -27
- package/dist/api/index.d.ts +0 -76
- package/dist/api/index.js +0 -139
- package/dist/image/components/Image.astro +0 -10
- package/dist/image/components/ResponsiveImage.astro +0 -41
- package/dist/image/index.d.ts +0 -16
- package/dist/image/index.js +0 -30
- package/dist/page/components/PageFieldRender.astro +0 -34
package/README.md
CHANGED
|
@@ -31,6 +31,10 @@ npm login
|
|
|
31
31
|
npm run release
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
[MIT LICENSE](LICENSE.md)
|
|
37
|
+
|
|
34
38
|
[ico-version]: https://img.shields.io/npm/v/@stephenchenorg/astro?style=flat-square
|
|
35
39
|
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen?style=flat-square
|
|
36
40
|
[ico-downloads]: https://img.shields.io/npm/dt/@stephenchenorg/astro?style=flat-square
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as graphql0 from "graphql";
|
|
2
|
-
|
|
3
1
|
//#region src/company-setting/types.d.ts
|
|
4
2
|
interface DataCompanySetting {
|
|
5
3
|
companySetting: CompanySetting;
|
|
@@ -41,7 +39,4 @@ declare function createCompanySetting(companySetting: Partial<CompanySetting>):
|
|
|
41
39
|
threads_link: string;
|
|
42
40
|
};
|
|
43
41
|
//#endregion
|
|
44
|
-
|
|
45
|
-
declare const companySettingFields: graphql0.DocumentNode;
|
|
46
|
-
//#endregion
|
|
47
|
-
export { CompanySetting, DataCompanySetting, companySettingFields, createCompanySetting };
|
|
42
|
+
export { CompanySetting, DataCompanySetting, createCompanySetting };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { gql } from "graphql-tag";
|
|
2
|
-
|
|
3
1
|
//#region src/company-setting/create.ts
|
|
4
2
|
function createCompanySetting(companySetting) {
|
|
5
3
|
return {
|
|
@@ -22,26 +20,4 @@ function createCompanySetting(companySetting) {
|
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
//#endregion
|
|
25
|
-
|
|
26
|
-
const companySettingFields = gql`
|
|
27
|
-
fragment CompanySettingFields on CompanySetting {
|
|
28
|
-
lang
|
|
29
|
-
name
|
|
30
|
-
description
|
|
31
|
-
logo
|
|
32
|
-
address_1
|
|
33
|
-
address_2
|
|
34
|
-
email_1
|
|
35
|
-
email_2
|
|
36
|
-
fb_link
|
|
37
|
-
ig_link
|
|
38
|
-
line_link
|
|
39
|
-
phone_1
|
|
40
|
-
phone_2
|
|
41
|
-
twitter_link
|
|
42
|
-
threads_link
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
export { companySettingFields, createCompanySetting };
|
|
23
|
+
export { createCompanySetting };
|
package/dist/page/index.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
import * as graphql4 from "graphql";
|
|
2
|
-
|
|
3
|
-
//#region src/page/field/fragments.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Page fields fragment requires explicit import image
|
|
7
|
-
* fields fragment `imageFields` from Image module.
|
|
8
|
-
*/
|
|
9
|
-
declare const pageFields: graphql4.DocumentNode;
|
|
10
|
-
//#endregion
|
|
11
1
|
//#region src/page/types.d.ts
|
|
12
|
-
interface DataPage {
|
|
13
|
-
page: Page;
|
|
14
|
-
}
|
|
15
|
-
interface Page extends PageMeta {
|
|
16
|
-
fields: PageField[];
|
|
17
|
-
}
|
|
18
2
|
interface PageMeta {
|
|
19
3
|
title: string;
|
|
20
4
|
seo_title: string | null;
|
|
@@ -27,68 +11,6 @@ interface PageMeta {
|
|
|
27
11
|
og_description: string | null;
|
|
28
12
|
og_image: string | null;
|
|
29
13
|
}
|
|
30
|
-
interface PageField {
|
|
31
|
-
key: string;
|
|
32
|
-
type: 'text' | 'textarea' | 'html' | 'image';
|
|
33
|
-
content: string | null;
|
|
34
|
-
image: {
|
|
35
|
-
desktop: string | null;
|
|
36
|
-
desktop_blur: string | null;
|
|
37
|
-
mobile: string | null;
|
|
38
|
-
mobile_blur: string | null;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
interface PagePlainTextField extends PageField {
|
|
42
|
-
type: 'text';
|
|
43
|
-
content: string;
|
|
44
|
-
image: {
|
|
45
|
-
desktop: null;
|
|
46
|
-
desktop_blur: null;
|
|
47
|
-
mobile: null;
|
|
48
|
-
mobile_blur: null;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
interface PagePlainTextareaField extends PageField {
|
|
52
|
-
type: 'textarea';
|
|
53
|
-
content: string;
|
|
54
|
-
image: {
|
|
55
|
-
desktop: null;
|
|
56
|
-
desktop_blur: null;
|
|
57
|
-
mobile: null;
|
|
58
|
-
mobile_blur: null;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
interface PageContentField extends PageField {
|
|
62
|
-
type: 'html';
|
|
63
|
-
content: string;
|
|
64
|
-
image: {
|
|
65
|
-
desktop: null;
|
|
66
|
-
desktop_blur: null;
|
|
67
|
-
mobile: null;
|
|
68
|
-
mobile_blur: null;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
interface PageImageField extends PageField {
|
|
72
|
-
type: 'image';
|
|
73
|
-
content: null;
|
|
74
|
-
image: {
|
|
75
|
-
desktop: string;
|
|
76
|
-
desktop_blur: string;
|
|
77
|
-
mobile: string;
|
|
78
|
-
mobile_blur: string;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/page/field/helpers.d.ts
|
|
83
|
-
declare function isPlainTextField(field: PageField): field is PagePlainTextField;
|
|
84
|
-
declare function isPlainTextareaField(field: PageField): field is PagePlainTextareaField;
|
|
85
|
-
declare function isContentField(field: PageField): field is PageContentField;
|
|
86
|
-
declare function isImageField(field: PageField): field is PageImageField;
|
|
87
|
-
declare function pageTextField(fields: PageField[], key: string): string | null;
|
|
88
|
-
declare function pageImageFieldForBackground(fields: PageField[], key: string): string;
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/page/seo-meta/fragments.d.ts
|
|
91
|
-
declare const seoMetaFields: (dummyClass: string) => graphql4.DocumentNode;
|
|
92
14
|
//#endregion
|
|
93
15
|
//#region src/page/seo-meta/helpers.d.ts
|
|
94
16
|
type UseSeoMetaOptions = Partial<Omit<PageMeta, 'title'>> & {
|
|
@@ -98,4 +20,4 @@ type UseSeoMetaOptions = Partial<Omit<PageMeta, 'title'>> & {
|
|
|
98
20
|
};
|
|
99
21
|
declare function seoMeta(options: UseSeoMetaOptions, modelMeta?: PageMeta): PageMeta;
|
|
100
22
|
//#endregion
|
|
101
|
-
export {
|
|
23
|
+
export { PageMeta, UseSeoMetaOptions, seoMeta };
|
package/dist/page/index.js
CHANGED
|
@@ -1,73 +1,3 @@
|
|
|
1
|
-
import { gql } from "graphql-tag";
|
|
2
|
-
|
|
3
|
-
//#region src/page/field/fragments.ts
|
|
4
|
-
/**
|
|
5
|
-
* Page fields fragment requires explicit import image
|
|
6
|
-
* fields fragment `imageFields` from Image module.
|
|
7
|
-
*/
|
|
8
|
-
const pageFields = gql`
|
|
9
|
-
fragment PageFields on Page {
|
|
10
|
-
title
|
|
11
|
-
seo_title
|
|
12
|
-
seo_description
|
|
13
|
-
seo_keyword
|
|
14
|
-
seo_json_ld
|
|
15
|
-
seo_head
|
|
16
|
-
seo_body
|
|
17
|
-
og_title
|
|
18
|
-
og_description
|
|
19
|
-
og_image
|
|
20
|
-
fields {
|
|
21
|
-
key
|
|
22
|
-
content
|
|
23
|
-
type
|
|
24
|
-
image {
|
|
25
|
-
...ImageFields
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/page/field/helpers.ts
|
|
33
|
-
function isPlainTextField(field) {
|
|
34
|
-
return field.type === "text";
|
|
35
|
-
}
|
|
36
|
-
function isPlainTextareaField(field) {
|
|
37
|
-
return field.type === "textarea";
|
|
38
|
-
}
|
|
39
|
-
function isContentField(field) {
|
|
40
|
-
return field.type === "html";
|
|
41
|
-
}
|
|
42
|
-
function isImageField(field) {
|
|
43
|
-
return field.type === "image";
|
|
44
|
-
}
|
|
45
|
-
function pageTextField(fields, key) {
|
|
46
|
-
const field = fields.find((field$1) => field$1.key === key && isPlainTextField(field$1));
|
|
47
|
-
return field ? field.content : "";
|
|
48
|
-
}
|
|
49
|
-
function pageImageFieldForBackground(fields, key) {
|
|
50
|
-
const field = fields.find((field$1) => field$1.key === key && isImageField(field$1));
|
|
51
|
-
return field ? `background-image: url('${field.image.desktop}');` : "";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/page/seo-meta/fragments.ts
|
|
56
|
-
const seoMetaFields = (dummyClass) => gql(`
|
|
57
|
-
fragment DummyClassSeoMetaFields on DummyClass {
|
|
58
|
-
seo_title
|
|
59
|
-
seo_description
|
|
60
|
-
seo_keyword
|
|
61
|
-
seo_json_ld
|
|
62
|
-
seo_head
|
|
63
|
-
seo_body
|
|
64
|
-
og_title
|
|
65
|
-
og_description
|
|
66
|
-
og_image
|
|
67
|
-
}
|
|
68
|
-
`.replace(/DummyClass/g, dummyClass));
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
1
|
//#region src/page/seo-meta/helpers.ts
|
|
72
2
|
function seoMeta(options, modelMeta) {
|
|
73
3
|
return {
|
|
@@ -85,4 +15,4 @@ function seoMeta(options, modelMeta) {
|
|
|
85
15
|
}
|
|
86
16
|
|
|
87
17
|
//#endregion
|
|
88
|
-
export {
|
|
18
|
+
export { seoMeta };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue0 from "vue";
|
|
2
2
|
import { MaybeRefOrGetter } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/pagination-vue-client-side/types.d.ts
|
|
@@ -16,12 +16,12 @@ declare function usePagination(options: {
|
|
|
16
16
|
visiblePages?: MaybeRefOrGetter<number | undefined>;
|
|
17
17
|
onChange?: (page: number) => void;
|
|
18
18
|
}): {
|
|
19
|
-
items:
|
|
20
|
-
showPagination:
|
|
21
|
-
canFirst:
|
|
22
|
-
canPrev:
|
|
23
|
-
canNext:
|
|
24
|
-
canLast:
|
|
19
|
+
items: vue0.ComputedRef<number[]>;
|
|
20
|
+
showPagination: vue0.ComputedRef<boolean>;
|
|
21
|
+
canFirst: vue0.ComputedRef<boolean>;
|
|
22
|
+
canPrev: vue0.ComputedRef<boolean>;
|
|
23
|
+
canNext: vue0.ComputedRef<boolean>;
|
|
24
|
+
canLast: vue0.ComputedRef<boolean>;
|
|
25
25
|
gotoFirst: () => void;
|
|
26
26
|
gotoPrev: () => void;
|
|
27
27
|
gotoNext: () => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue5 from "vue";
|
|
2
2
|
import { MaybeRefOrGetter } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/pagination-vue-server-side/types.d.ts
|
|
@@ -16,16 +16,16 @@ declare function usePagination(options: {
|
|
|
16
16
|
perPage?: MaybeRefOrGetter<number | undefined>;
|
|
17
17
|
visiblePages?: MaybeRefOrGetter<number | undefined>;
|
|
18
18
|
}): {
|
|
19
|
-
items:
|
|
20
|
-
showPagination:
|
|
21
|
-
canFirst:
|
|
22
|
-
canPrev:
|
|
23
|
-
canNext:
|
|
24
|
-
canLast:
|
|
25
|
-
firstUrl:
|
|
26
|
-
prevUrl:
|
|
27
|
-
nextUrl:
|
|
28
|
-
lastUrl:
|
|
19
|
+
items: vue5.ComputedRef<number[]>;
|
|
20
|
+
showPagination: vue5.ComputedRef<boolean>;
|
|
21
|
+
canFirst: vue5.ComputedRef<boolean>;
|
|
22
|
+
canPrev: vue5.ComputedRef<boolean>;
|
|
23
|
+
canNext: vue5.ComputedRef<boolean>;
|
|
24
|
+
canLast: vue5.ComputedRef<boolean>;
|
|
25
|
+
firstUrl: vue5.ComputedRef<string>;
|
|
26
|
+
prevUrl: vue5.ComputedRef<string>;
|
|
27
|
+
nextUrl: vue5.ComputedRef<string>;
|
|
28
|
+
lastUrl: vue5.ComputedRef<string>;
|
|
29
29
|
getUrl: (page: number) => string;
|
|
30
30
|
};
|
|
31
31
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stephenchenorg/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "9.0.0",
|
|
5
5
|
"description": "Stephenchenorg Astro 前端通用套件",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://stephenchenorg-astro.netlify.app",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/stephenchenorg/package.astro.git"
|
|
10
|
+
"url": "git+https://github.com/stephenchenorg/package.astro.git",
|
|
11
|
+
"directory": "packages/core"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [
|
|
13
14
|
"astro",
|
|
@@ -19,10 +20,6 @@
|
|
|
19
20
|
"query-params"
|
|
20
21
|
],
|
|
21
22
|
"exports": {
|
|
22
|
-
"./api": {
|
|
23
|
-
"types": "./dist/api/index.d.ts",
|
|
24
|
-
"import": "./dist/api/index.js"
|
|
25
|
-
},
|
|
26
23
|
"./company-setting": {
|
|
27
24
|
"types": "./dist/company-setting/index.d.ts",
|
|
28
25
|
"import": "./dist/company-setting/index.js"
|
|
@@ -31,17 +28,10 @@
|
|
|
31
28
|
"types": "./dist/form-validator/index.d.ts",
|
|
32
29
|
"import": "./dist/form-validator/index.js"
|
|
33
30
|
},
|
|
34
|
-
"./image": {
|
|
35
|
-
"types": "./dist/image/index.d.ts",
|
|
36
|
-
"import": "./dist/image/index.js"
|
|
37
|
-
},
|
|
38
|
-
"./image/components/Image.astro": "./dist/image/components/Image.astro",
|
|
39
|
-
"./image/components/ResponsiveImage.astro": "./dist/image/components/ResponsiveImage.astro",
|
|
40
31
|
"./page": {
|
|
41
32
|
"types": "./dist/page/index.d.ts",
|
|
42
33
|
"import": "./dist/page/index.js"
|
|
43
34
|
},
|
|
44
|
-
"./page/components/PageFieldRender.astro": "./dist/page/components/PageFieldRender.astro",
|
|
45
35
|
"./pagination-astro": {
|
|
46
36
|
"types": "./dist/pagination-astro/index.d.ts",
|
|
47
37
|
"import": "./dist/pagination-astro/index.js"
|
|
@@ -78,11 +68,9 @@
|
|
|
78
68
|
},
|
|
79
69
|
"scripts": {
|
|
80
70
|
"build": "tsdown",
|
|
81
|
-
"lint": "eslint \"*.{js,ts,json}\" \"src/**/*.ts\"",
|
|
82
71
|
"test": "vitest",
|
|
83
|
-
"code-check": "astro check && npm run
|
|
84
|
-
"prepack": "npm run build"
|
|
85
|
-
"release": "bumpp --commit \"Release v%s\" && npm publish"
|
|
72
|
+
"code-check": "astro check && npm run test -- --run",
|
|
73
|
+
"prepack": "npm run build"
|
|
86
74
|
},
|
|
87
75
|
"peerDependencies": {
|
|
88
76
|
"astro": "^5.0.0",
|
|
@@ -94,23 +82,14 @@
|
|
|
94
82
|
}
|
|
95
83
|
},
|
|
96
84
|
"dependencies": {
|
|
97
|
-
"@graphql-typed-document-node/core": "^3.2.0",
|
|
98
|
-
"awesome-graphql-client": "^2.1.0",
|
|
99
|
-
"graphql": "^16.12.0",
|
|
100
|
-
"graphql-tag": "^2.12.6",
|
|
101
85
|
"nanostores": "^1.1.0",
|
|
102
86
|
"query-string": "^9.3.1"
|
|
103
87
|
},
|
|
104
88
|
"devDependencies": {
|
|
105
89
|
"@astrojs/check": "^0.9.6",
|
|
106
90
|
"@astrojs/vue": "^5.1.3",
|
|
107
|
-
"@ycs77/eslint-config": "^6.1.0",
|
|
108
91
|
"astro": "^5.16.4",
|
|
109
|
-
"
|
|
110
|
-
"eslint": "^9.39.1",
|
|
111
|
-
"eslint-plugin-astro": "^1.5.0",
|
|
112
|
-
"eslint-plugin-astro-explicit-wrapper": "^1.0.5",
|
|
113
|
-
"tsdown": "^0.17.2",
|
|
92
|
+
"tsdown": "^0.18.1",
|
|
114
93
|
"typescript": "^5.9.3",
|
|
115
94
|
"vitest": "^4.0.15",
|
|
116
95
|
"vue": "^3.5.25"
|
package/dist/api/index.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { gql } from "graphql-tag";
|
|
2
|
-
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
3
|
-
import { APIContext } from "astro";
|
|
4
|
-
|
|
5
|
-
//#region src/api/error.d.ts
|
|
6
|
-
interface GraphQLFieldError {
|
|
7
|
-
code?: number;
|
|
8
|
-
message: string;
|
|
9
|
-
locations?: {
|
|
10
|
-
line: number;
|
|
11
|
-
column: number;
|
|
12
|
-
}[];
|
|
13
|
-
path?: (string | number)[];
|
|
14
|
-
extensions?: GraphQLRequestExtensions;
|
|
15
|
-
data?: Record<string, any>;
|
|
16
|
-
}
|
|
17
|
-
interface GraphQLRequestExtensions {
|
|
18
|
-
debugMessage?: string;
|
|
19
|
-
file?: string;
|
|
20
|
-
line?: number;
|
|
21
|
-
trace?: {
|
|
22
|
-
file: string;
|
|
23
|
-
line: number;
|
|
24
|
-
call: number;
|
|
25
|
-
}[];
|
|
26
|
-
}
|
|
27
|
-
interface GraphQLRequestErrorOptions {
|
|
28
|
-
code?: number;
|
|
29
|
-
message: string;
|
|
30
|
-
query: string;
|
|
31
|
-
variables?: Record<string, any>;
|
|
32
|
-
extensions?: GraphQLRequestExtensions;
|
|
33
|
-
fieldErrors?: GraphQLFieldError[];
|
|
34
|
-
}
|
|
35
|
-
declare class GraphQLRequestError extends Error {
|
|
36
|
-
type: string;
|
|
37
|
-
name: string;
|
|
38
|
-
title: string;
|
|
39
|
-
code: number | undefined;
|
|
40
|
-
originalMessage: string;
|
|
41
|
-
query: string;
|
|
42
|
-
variables: Record<string, any> | undefined;
|
|
43
|
-
extensions: GraphQLRequestExtensions | undefined;
|
|
44
|
-
fieldErrors: GraphQLFieldError[] | undefined;
|
|
45
|
-
constructor(props: GraphQLRequestErrorOptions, options?: ErrorOptions);
|
|
46
|
-
isNotFound(): boolean;
|
|
47
|
-
private buildMessage;
|
|
48
|
-
static is(err: unknown): err is GraphQLRequestError;
|
|
49
|
-
}
|
|
50
|
-
declare class GraphQLNotFoundError extends GraphQLRequestError {
|
|
51
|
-
type: string;
|
|
52
|
-
name: string;
|
|
53
|
-
}
|
|
54
|
-
declare class GraphQLValidationError extends GraphQLRequestError {
|
|
55
|
-
type: string;
|
|
56
|
-
name: string;
|
|
57
|
-
errors: Record<string, string[]>;
|
|
58
|
-
constructor(props: GraphQLRequestErrorOptions, options?: ErrorOptions);
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/api/errorResponse.d.ts
|
|
62
|
-
declare function handleErrorResponse(e: unknown): Response | undefined;
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/api/fetch.d.ts
|
|
65
|
-
interface CreateGraphQLAPIOptions {
|
|
66
|
-
endpoint: string;
|
|
67
|
-
defaultVariables?: Record<string, any> | ((astroContext?: APIContext) => Record<string, any>);
|
|
68
|
-
fetchOptions?: RequestInit | ((astroContext?: APIContext) => RequestInit);
|
|
69
|
-
}
|
|
70
|
-
declare function createGraphQLAPI(globalOptions: CreateGraphQLAPIOptions): <TData extends Record<string, any>, TVariables extends Record<string, any> = Record<string, any>>(query: TypedDocumentNode<TData, TVariables>, options?: {
|
|
71
|
-
variables?: TVariables;
|
|
72
|
-
fetchOptions?: RequestInit;
|
|
73
|
-
Astro?: APIContext;
|
|
74
|
-
}) => Promise<TData>;
|
|
75
|
-
//#endregion
|
|
76
|
-
export { CreateGraphQLAPIOptions, GraphQLFieldError, GraphQLNotFoundError, GraphQLRequestError, GraphQLRequestErrorOptions, GraphQLRequestExtensions, GraphQLValidationError, createGraphQLAPI, gql, handleErrorResponse };
|
package/dist/api/index.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { AwesomeGraphQLClient, GraphQLRequestError as GraphQLRequestError$1 } from "awesome-graphql-client";
|
|
2
|
-
import { print } from "graphql/language/printer";
|
|
3
|
-
import { gql } from "graphql-tag";
|
|
4
|
-
|
|
5
|
-
//#region src/api/error.ts
|
|
6
|
-
var GraphQLRequestError = class extends Error {
|
|
7
|
-
type = "GraphQLRequestError";
|
|
8
|
-
name = "GraphQLRequestError";
|
|
9
|
-
title = "GraphQL request error.";
|
|
10
|
-
code;
|
|
11
|
-
originalMessage;
|
|
12
|
-
query;
|
|
13
|
-
variables;
|
|
14
|
-
extensions;
|
|
15
|
-
fieldErrors;
|
|
16
|
-
constructor(props, options) {
|
|
17
|
-
const { code, message, query, variables, extensions, fieldErrors } = props;
|
|
18
|
-
super("GraphQL request error.", options);
|
|
19
|
-
const originalStack = this.stack;
|
|
20
|
-
this.title = "GraphQL request error.";
|
|
21
|
-
this.code = code;
|
|
22
|
-
this.originalMessage = message;
|
|
23
|
-
this.query = query;
|
|
24
|
-
this.variables = variables;
|
|
25
|
-
this.extensions = extensions;
|
|
26
|
-
this.fieldErrors = fieldErrors;
|
|
27
|
-
this.message = this.buildMessage();
|
|
28
|
-
this.stack = originalStack;
|
|
29
|
-
}
|
|
30
|
-
isNotFound() {
|
|
31
|
-
return this.originalMessage.includes("Http Status 404");
|
|
32
|
-
}
|
|
33
|
-
buildMessage() {
|
|
34
|
-
let message = `${this.originalMessage}\n`;
|
|
35
|
-
if (this.code) {
|
|
36
|
-
message += "\n";
|
|
37
|
-
message += `[code]\n${this.code}\n`;
|
|
38
|
-
}
|
|
39
|
-
if (this.extensions) {
|
|
40
|
-
if (this.extensions.debugMessage) {
|
|
41
|
-
message += "\n";
|
|
42
|
-
message += `${this.extensions.debugMessage}\n`;
|
|
43
|
-
}
|
|
44
|
-
if (this.extensions.file || this.extensions.line || this.extensions.trace) {
|
|
45
|
-
message += "\n";
|
|
46
|
-
message += "[stacktrace]\n";
|
|
47
|
-
if (this.extensions.file) message += `file: ${this.extensions.file}\n`;
|
|
48
|
-
if (this.extensions.line) message += `line: ${this.extensions.line}\n`;
|
|
49
|
-
if (this.extensions.trace && Array.isArray(this.extensions.trace)) {
|
|
50
|
-
message += "trace:\n";
|
|
51
|
-
for (const trace of this.extensions.trace.slice(0, 3)) {
|
|
52
|
-
message += ` - file: ${trace.file}\n`;
|
|
53
|
-
message += ` line: ${trace.line}\n`;
|
|
54
|
-
message += ` call: ${trace.call}\n`;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (this.query) {
|
|
60
|
-
message += "\n";
|
|
61
|
-
message += `[query]\n${this.query}\n`;
|
|
62
|
-
}
|
|
63
|
-
if (this.variables) {
|
|
64
|
-
message += "\n";
|
|
65
|
-
message += `[variables]\n${JSON.stringify(this.variables, null, 2)}\n`;
|
|
66
|
-
}
|
|
67
|
-
return message;
|
|
68
|
-
}
|
|
69
|
-
static is(err) {
|
|
70
|
-
return err.type === "GraphQLRequestError";
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var GraphQLNotFoundError = class extends GraphQLRequestError {
|
|
74
|
-
type = "GraphQLNotFoundError";
|
|
75
|
-
name = "GraphQLNotFoundError";
|
|
76
|
-
};
|
|
77
|
-
var GraphQLValidationError = class extends GraphQLRequestError {
|
|
78
|
-
type = "GraphQLValidationError";
|
|
79
|
-
name = "GraphQLValidationError";
|
|
80
|
-
errors;
|
|
81
|
-
constructor(props, options) {
|
|
82
|
-
super(props, options);
|
|
83
|
-
this.errors = this.fieldErrors?.[0]?.data?.validation || {};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/api/errorResponse.ts
|
|
89
|
-
function handleErrorResponse(e) {
|
|
90
|
-
if (e instanceof GraphQLNotFoundError) return new Response(null, {
|
|
91
|
-
status: 404,
|
|
92
|
-
statusText: "Not found"
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/api/fetch.ts
|
|
98
|
-
function createGraphQLAPI(globalOptions) {
|
|
99
|
-
const client = new AwesomeGraphQLClient({
|
|
100
|
-
endpoint: globalOptions.endpoint,
|
|
101
|
-
formatQuery: (query) => print(query)
|
|
102
|
-
});
|
|
103
|
-
return function graphQLAPI(query, options) {
|
|
104
|
-
const { variables, fetchOptions, Astro: astroContext } = options || {};
|
|
105
|
-
const defaultVariables = typeof globalOptions.defaultVariables === "function" ? globalOptions.defaultVariables(astroContext) : globalOptions.defaultVariables;
|
|
106
|
-
const defaultFetchOptions = typeof globalOptions.fetchOptions === "function" ? globalOptions.fetchOptions(astroContext) : globalOptions.fetchOptions;
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
client.request(query, {
|
|
109
|
-
...defaultVariables,
|
|
110
|
-
...variables
|
|
111
|
-
}, {
|
|
112
|
-
...defaultFetchOptions,
|
|
113
|
-
...fetchOptions,
|
|
114
|
-
headers: {
|
|
115
|
-
...defaultFetchOptions?.headers,
|
|
116
|
-
...fetchOptions?.headers
|
|
117
|
-
}
|
|
118
|
-
}).then((data) => resolve(data)).catch((error) => {
|
|
119
|
-
if (error instanceof GraphQLRequestError$1) {
|
|
120
|
-
const code = (error.fieldErrors?.[0])?.code;
|
|
121
|
-
const errorProps = {
|
|
122
|
-
code,
|
|
123
|
-
message: error.message,
|
|
124
|
-
query: error.query,
|
|
125
|
-
variables: error.variables,
|
|
126
|
-
extensions: error.extensions,
|
|
127
|
-
fieldErrors: error.fieldErrors
|
|
128
|
-
};
|
|
129
|
-
if (code === 404) reject(new GraphQLNotFoundError(errorProps));
|
|
130
|
-
else if (code === 422) reject(new GraphQLValidationError(errorProps));
|
|
131
|
-
reject(new GraphQLRequestError(errorProps));
|
|
132
|
-
} else reject(error);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
|
-
export { GraphQLNotFoundError, GraphQLRequestError, GraphQLValidationError, createGraphQLAPI, gql, handleErrorResponse };
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
// GraphQL image props
|
|
9
|
-
desktop_blur?: string | null
|
|
10
|
-
mobile_blur?: string | null
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
desktop,
|
|
15
|
-
desktopBlur: _desktopBlur,
|
|
16
|
-
mobile,
|
|
17
|
-
mobileBlur: _mobileBlur,
|
|
18
|
-
|
|
19
|
-
desktop_blur: _desktop_blur,
|
|
20
|
-
mobile_blur: _mobile_blur,
|
|
21
|
-
src: _src,
|
|
22
|
-
|
|
23
|
-
...attributes
|
|
24
|
-
} = Astro.props
|
|
25
|
-
|
|
26
|
-
// const desktopBlur = Astro.props.desktopBlur || Astro.props.desktop_blur
|
|
27
|
-
// const mobileBlur = Astro.props.mobileBlur || Astro.props.mobile_blur
|
|
28
|
-
|
|
29
|
-
const breakpoint = 768
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
{desktop && (
|
|
33
|
-
mobile ? (
|
|
34
|
-
<picture>
|
|
35
|
-
{mobile && <source media={`(max-width: ${breakpoint - 0.02}px)`} srcset={mobile} />}
|
|
36
|
-
<img src={desktop} {...attributes} />
|
|
37
|
-
</picture>
|
|
38
|
-
) : (
|
|
39
|
-
<img src={desktop} {...attributes} />
|
|
40
|
-
)
|
|
41
|
-
)}
|
package/dist/image/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as graphql0 from "graphql";
|
|
2
|
-
|
|
3
|
-
//#region src/image/fragments.d.ts
|
|
4
|
-
declare const imageFields: graphql0.DocumentNode;
|
|
5
|
-
declare const coverFields: graphql0.DocumentNode;
|
|
6
|
-
declare const backgroundFields: graphql0.DocumentNode;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/image/types.d.ts
|
|
9
|
-
interface ImageSource {
|
|
10
|
-
desktop: string | null;
|
|
11
|
-
desktop_blur: string | null;
|
|
12
|
-
mobile: string | null;
|
|
13
|
-
mobile_blur: string | null;
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { ImageSource, backgroundFields, coverFields, imageFields };
|
package/dist/image/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { gql } from "graphql-tag";
|
|
2
|
-
|
|
3
|
-
//#region src/image/fragments.ts
|
|
4
|
-
const imageFields = gql`
|
|
5
|
-
fragment ImageFields on Image {
|
|
6
|
-
desktop
|
|
7
|
-
desktop_blur
|
|
8
|
-
mobile
|
|
9
|
-
mobile_blur
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
-
const coverFields = gql`
|
|
13
|
-
fragment CoverFields on Cover {
|
|
14
|
-
desktop
|
|
15
|
-
desktop_blur
|
|
16
|
-
mobile
|
|
17
|
-
mobile_blur
|
|
18
|
-
}
|
|
19
|
-
`;
|
|
20
|
-
const backgroundFields = gql`
|
|
21
|
-
fragment BackgroundFields on Background {
|
|
22
|
-
desktop
|
|
23
|
-
desktop_blur
|
|
24
|
-
mobile
|
|
25
|
-
mobile_blur
|
|
26
|
-
}
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
export { backgroundFields, coverFields, imageFields };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { isContentField, isImageField, isPlainTextField, isPlainTextareaField } from '@stephenchenorg/astro/page'
|
|
3
|
-
import type { PageField } from '@stephenchenorg/astro/page'
|
|
4
|
-
import ResponsiveImage from '@stephenchenorg/astro/image/components/ResponsiveImage.astro'
|
|
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
|
-
}
|