@stephenchenorg/astro 5.0.2 → 6.1.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/dist/api/index.d.ts +76 -3
- package/dist/api/index.js +140 -3
- package/dist/company-setting/index.d.ts +47 -3
- package/dist/company-setting/index.js +47 -3
- package/dist/form-validator/index.d.ts +72 -6
- package/dist/form-validator/index.js +106 -5
- package/dist/image/index.d.ts +16 -4
- package/dist/image/index.js +30 -4
- package/dist/page/components/PageFieldRender.astro +3 -3
- package/dist/page/index.d.ts +101 -4
- package/dist/page/index.js +88 -4
- package/dist/pagination-astro/index.d.ts +30 -2
- package/dist/pagination-astro/index.js +37 -2
- package/dist/pagination-vue/index.d.ts +33 -2
- package/dist/pagination-vue/index.js +44 -2
- package/dist/product-variant/index.d.ts +73 -2
- package/dist/product-variant/index.js +63 -2
- package/dist/query-params/components/ProvideUrlConfig.astro +1 -2
- package/dist/query-params/index.d.ts +35 -6
- package/dist/query-params/index.js +62 -6
- package/package.json +16 -5
- package/dist/api/error.d.ts +0 -54
- package/dist/api/error.js +0 -97
- package/dist/api/errorResponse.d.ts +0 -1
- package/dist/api/errorResponse.js +0 -9
- package/dist/api/fetch.d.ts +0 -13
- package/dist/api/fetch.js +0 -49
- package/dist/company-setting/create.d.ts +0 -18
- package/dist/company-setting/create.js +0 -19
- package/dist/company-setting/fragments.d.ts +0 -1
- package/dist/company-setting/fragments.js +0 -20
- package/dist/company-setting/types.d.ts +0 -20
- package/dist/company-setting/types.js +0 -0
- package/dist/form-validator/FormValidator.d.ts +0 -12
- package/dist/form-validator/FormValidator.js +0 -48
- package/dist/form-validator/components/FormField.vue +0 -30
- package/dist/form-validator/components/FormValidatorProvider.d.ts +0 -22
- package/dist/form-validator/components/FormValidatorProvider.js +0 -27
- package/dist/form-validator/injectionKey.d.ts +0 -3
- package/dist/form-validator/injectionKey.js +0 -1
- package/dist/form-validator/types.d.ts +0 -5
- package/dist/form-validator/types.js +0 -0
- package/dist/image/fragments.d.ts +0 -3
- package/dist/image/fragments.js +0 -25
- package/dist/image/types.d.ts +0 -6
- package/dist/image/types.js +0 -0
- package/dist/page/field/fragments.d.ts +0 -5
- package/dist/page/field/fragments.js +0 -23
- package/dist/page/field/helpers.d.ts +0 -7
- package/dist/page/field/helpers.js +0 -20
- package/dist/page/field/index.d.ts +0 -2
- package/dist/page/field/index.js +0 -2
- package/dist/page/seo-meta/fragments.d.ts +0 -1
- package/dist/page/seo-meta/fragments.js +0 -14
- package/dist/page/seo-meta/helpers.d.ts +0 -7
- package/dist/page/seo-meta/helpers.js +0 -14
- package/dist/page/seo-meta/index.d.ts +0 -2
- package/dist/page/seo-meta/index.js +0 -2
- package/dist/page/types.d.ts +0 -69
- package/dist/page/types.js +0 -0
- package/dist/pagination-astro/types.d.ts +0 -5
- package/dist/pagination-astro/types.js +0 -0
- package/dist/pagination-astro/usePagination.d.ts +0 -20
- package/dist/pagination-astro/usePagination.js +0 -42
- package/dist/pagination-vue/types.d.ts +0 -5
- package/dist/pagination-vue/types.js +0 -0
- package/dist/pagination-vue/usePagination.d.ts +0 -21
- package/dist/pagination-vue/usePagination.js +0 -44
- package/dist/product-variant/ProductVariantSelector.d.ts +0 -42
- package/dist/product-variant/ProductVariantSelector.js +0 -52
- package/dist/product-variant/types.d.ts +0 -20
- package/dist/product-variant/types.js +0 -0
- package/dist/query-params/config.d.ts +0 -2
- package/dist/query-params/config.js +0 -3
- package/dist/query-params/store.d.ts +0 -2
- package/dist/query-params/store.js +0 -7
- package/dist/query-params/types.d.ts +0 -6
- package/dist/query-params/types.js +0 -0
- package/dist/query-params/url.d.ts +0 -13
- package/dist/query-params/url.js +0 -30
- package/dist/query-params/utils.d.ts +0 -2
- package/dist/query-params/utils.js +0 -21
package/dist/api/index.d.ts
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
CHANGED
|
@@ -1,3 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 fieldError = error.fieldErrors?.[0];
|
|
121
|
+
const code = fieldError?.code;
|
|
122
|
+
const errorProps = {
|
|
123
|
+
code,
|
|
124
|
+
message: error.message,
|
|
125
|
+
query: error.query,
|
|
126
|
+
variables: error.variables,
|
|
127
|
+
extensions: error.extensions,
|
|
128
|
+
fieldErrors: error.fieldErrors
|
|
129
|
+
};
|
|
130
|
+
if (code === 404) reject(new GraphQLNotFoundError(errorProps));
|
|
131
|
+
else if (code === 422) reject(new GraphQLValidationError(errorProps));
|
|
132
|
+
reject(new GraphQLRequestError(errorProps));
|
|
133
|
+
} else reject(error);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
export { GraphQLNotFoundError, GraphQLRequestError, GraphQLValidationError, createGraphQLAPI, gql, handleErrorResponse };
|
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as graphql0 from "graphql";
|
|
2
|
+
|
|
3
|
+
//#region src/company-setting/types.d.ts
|
|
4
|
+
interface DataCompanySetting {
|
|
5
|
+
companySetting: CompanySetting;
|
|
6
|
+
}
|
|
7
|
+
interface CompanySetting {
|
|
8
|
+
lang: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
logo: string;
|
|
12
|
+
address_1: string;
|
|
13
|
+
address_2: string;
|
|
14
|
+
email_1: string;
|
|
15
|
+
email_2: string;
|
|
16
|
+
fb_link: string;
|
|
17
|
+
ig_link: string;
|
|
18
|
+
line_link: string;
|
|
19
|
+
phone_1: string;
|
|
20
|
+
phone_2: string;
|
|
21
|
+
twitter_link: string;
|
|
22
|
+
threads_link: string;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/company-setting/create.d.ts
|
|
26
|
+
declare function createCompanySetting(companySetting: Partial<CompanySetting>): {
|
|
27
|
+
lang: string;
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
logo: string;
|
|
31
|
+
address_1: string;
|
|
32
|
+
address_2: string;
|
|
33
|
+
email_1: string;
|
|
34
|
+
email_2: string;
|
|
35
|
+
fb_link: string;
|
|
36
|
+
ig_link: string;
|
|
37
|
+
line_link: string;
|
|
38
|
+
phone_1: string;
|
|
39
|
+
phone_2: string;
|
|
40
|
+
twitter_link: string;
|
|
41
|
+
threads_link: string;
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/company-setting/fragments.d.ts
|
|
45
|
+
declare const companySettingFields: graphql0.DocumentNode;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { CompanySetting, DataCompanySetting, companySettingFields, createCompanySetting };
|
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
|
|
3
|
+
//#region src/company-setting/create.ts
|
|
4
|
+
function createCompanySetting(companySetting) {
|
|
5
|
+
return {
|
|
6
|
+
lang: companySetting.lang || "zh_TW",
|
|
7
|
+
name: companySetting.name || "Astro",
|
|
8
|
+
description: companySetting.description || "",
|
|
9
|
+
logo: companySetting.logo || "",
|
|
10
|
+
address_1: companySetting.address_1 || "",
|
|
11
|
+
address_2: companySetting.address_2 || "",
|
|
12
|
+
email_1: companySetting.email_1 || "",
|
|
13
|
+
email_2: companySetting.email_2 || "",
|
|
14
|
+
fb_link: companySetting.fb_link || "",
|
|
15
|
+
ig_link: companySetting.ig_link || "",
|
|
16
|
+
line_link: companySetting.line_link || "",
|
|
17
|
+
phone_1: companySetting.phone_1 || "",
|
|
18
|
+
phone_2: companySetting.phone_2 || "",
|
|
19
|
+
twitter_link: companySetting.twitter_link || "",
|
|
20
|
+
threads_link: companySetting.threads_link || ""
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/company-setting/fragments.ts
|
|
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 };
|
|
@@ -1,6 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as vue27 from "vue";
|
|
2
|
+
import { PropType } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/form-validator/types.d.ts
|
|
5
|
+
type FormErrors = Record<string, string[]>;
|
|
6
|
+
interface FormRule {
|
|
7
|
+
validate: (value: any) => boolean;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/form-validator/FormValidator.d.ts
|
|
12
|
+
declare class FormValidator {
|
|
13
|
+
rules: Record<string, FormRule[]>;
|
|
14
|
+
errors: FormErrors;
|
|
15
|
+
errorsUpdatedCallbacks: ((errors: FormErrors) => void)[];
|
|
16
|
+
validate(data: Record<string, any>): boolean;
|
|
17
|
+
prependRules(field: string, rules: FormRule | FormRule[]): void;
|
|
18
|
+
appendRules(field: string, rules: FormRule | FormRule[]): void;
|
|
19
|
+
setErrors(errors: FormErrors): void;
|
|
20
|
+
resetErrors(): void;
|
|
21
|
+
onErrorsUpdated(callback: (errors: FormErrors) => void): void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/form-validator/components/FormField.d.ts
|
|
25
|
+
declare const FormField: vue27.DefineComponent<vue27.ExtractPropTypes<{
|
|
26
|
+
id: {
|
|
27
|
+
type: StringConstructor;
|
|
28
|
+
required: true;
|
|
29
|
+
};
|
|
30
|
+
rules: {
|
|
31
|
+
type: PropType<FormRule[]>;
|
|
32
|
+
default: () => never[];
|
|
33
|
+
};
|
|
34
|
+
}>, () => vue27.VNode<vue27.RendererNode, vue27.RendererElement, {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}>[] | undefined, {}, {}, {}, vue27.ComponentOptionsMixin, vue27.ComponentOptionsMixin, {}, string, vue27.PublicProps, Readonly<vue27.ExtractPropTypes<{
|
|
37
|
+
id: {
|
|
38
|
+
type: StringConstructor;
|
|
39
|
+
required: true;
|
|
40
|
+
};
|
|
41
|
+
rules: {
|
|
42
|
+
type: PropType<FormRule[]>;
|
|
43
|
+
default: () => never[];
|
|
44
|
+
};
|
|
45
|
+
}>> & Readonly<{}>, {
|
|
46
|
+
rules: FormRule[];
|
|
47
|
+
}, {}, {}, {}, string, vue27.ComponentProvideOptions, true, {}, any>;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/form-validator/components/FormValidatorProvider.d.ts
|
|
50
|
+
interface FormValidatorProviderExposed {
|
|
51
|
+
formValidator: () => FormValidator;
|
|
52
|
+
}
|
|
53
|
+
declare const FormValidatorProvider: vue27.DefineComponent<vue27.ExtractPropTypes<{
|
|
54
|
+
errors: {
|
|
55
|
+
type: PropType<FormErrors>;
|
|
56
|
+
default: () => {};
|
|
57
|
+
};
|
|
58
|
+
}>, () => vue27.VNode<vue27.RendererNode, vue27.RendererElement, {
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
}>[] | undefined, {}, {}, {}, vue27.ComponentOptionsMixin, vue27.ComponentOptionsMixin, {}, string, vue27.PublicProps, Readonly<vue27.ExtractPropTypes<{
|
|
61
|
+
errors: {
|
|
62
|
+
type: PropType<FormErrors>;
|
|
63
|
+
default: () => {};
|
|
64
|
+
};
|
|
65
|
+
}>> & Readonly<{}>, {
|
|
66
|
+
errors: FormErrors;
|
|
67
|
+
}, {}, {}, {}, string, vue27.ComponentProvideOptions, true, {}, any>;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/form-validator/useFormValidator.d.ts
|
|
70
|
+
declare function useFormValidator(): FormValidator;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { FormErrors, FormField, FormRule, FormValidator, FormValidatorProvider, FormValidatorProviderExposed, useFormValidator };
|
|
@@ -1,5 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { defineComponent, inject, onMounted, provide, ref, toRaw, watch } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/form-validator/injectionKey.ts
|
|
4
|
+
const formValidatorInjectionKey = Symbol("");
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/form-validator/useFormValidator.ts
|
|
8
|
+
function useFormValidator() {
|
|
9
|
+
const formValidator = inject(formValidatorInjectionKey);
|
|
10
|
+
if (!formValidator) throw new Error("FormValidator must be provided in the <FormValidatorProvider> component context.");
|
|
11
|
+
return formValidator;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/form-validator/components/FormField.ts
|
|
16
|
+
const FormField = defineComponent({
|
|
17
|
+
name: "FormField",
|
|
18
|
+
props: {
|
|
19
|
+
id: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
type: Object,
|
|
25
|
+
default: () => []
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
setup(props, { slots }) {
|
|
29
|
+
const error = ref(void 0);
|
|
30
|
+
const formValidator = useFormValidator();
|
|
31
|
+
if (props.rules) formValidator.appendRules(props.id, props.rules);
|
|
32
|
+
formValidator.onErrorsUpdated((errors) => {
|
|
33
|
+
error.value = errors[props.id]?.[0];
|
|
34
|
+
});
|
|
35
|
+
return () => slots.default?.({ error: error.value });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var FormField_default = FormField;
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/form-validator/FormValidator.ts
|
|
42
|
+
var FormValidator = class {
|
|
43
|
+
rules = {};
|
|
44
|
+
errors = {};
|
|
45
|
+
errorsUpdatedCallbacks = [];
|
|
46
|
+
validate(data) {
|
|
47
|
+
const errors = {};
|
|
48
|
+
let isValid = true;
|
|
49
|
+
for (const field in this.rules) {
|
|
50
|
+
const fieldRules = this.rules[field];
|
|
51
|
+
const value = data[field];
|
|
52
|
+
for (const rule of fieldRules) if (!rule.validate(value)) {
|
|
53
|
+
isValid = false;
|
|
54
|
+
if (!errors[field]) errors[field] = [];
|
|
55
|
+
errors[field].push(rule.message);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.setErrors(errors);
|
|
60
|
+
return isValid;
|
|
61
|
+
}
|
|
62
|
+
prependRules(field, rules) {
|
|
63
|
+
if (!this.rules[field]) this.rules[field] = [];
|
|
64
|
+
this.rules[field].unshift(...Array.isArray(rules) ? rules : [rules]);
|
|
65
|
+
}
|
|
66
|
+
appendRules(field, rules) {
|
|
67
|
+
if (!this.rules[field]) this.rules[field] = [];
|
|
68
|
+
this.rules[field].push(...Array.isArray(rules) ? rules : [rules]);
|
|
69
|
+
}
|
|
70
|
+
setErrors(errors) {
|
|
71
|
+
this.errors = structuredClone(toRaw(errors));
|
|
72
|
+
this.errorsUpdatedCallbacks.forEach((callback) => callback(this.errors));
|
|
73
|
+
}
|
|
74
|
+
resetErrors() {
|
|
75
|
+
this.setErrors({});
|
|
76
|
+
}
|
|
77
|
+
onErrorsUpdated(callback) {
|
|
78
|
+
this.errorsUpdatedCallbacks.push(callback);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/form-validator/components/FormValidatorProvider.ts
|
|
84
|
+
const FormValidatorProvider = defineComponent({
|
|
85
|
+
name: "FormValidatorProvider",
|
|
86
|
+
props: { errors: {
|
|
87
|
+
type: Object,
|
|
88
|
+
default: () => ({})
|
|
89
|
+
} },
|
|
90
|
+
setup(props, { slots, expose }) {
|
|
91
|
+
const formValidator = new FormValidator();
|
|
92
|
+
provide(formValidatorInjectionKey, formValidator);
|
|
93
|
+
onMounted(() => {
|
|
94
|
+
formValidator.setErrors(props.errors);
|
|
95
|
+
});
|
|
96
|
+
watch(() => props.errors, () => {
|
|
97
|
+
formValidator.setErrors(props.errors);
|
|
98
|
+
}, { deep: true });
|
|
99
|
+
expose({ formValidator: () => formValidator });
|
|
100
|
+
return () => slots.default?.();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
var FormValidatorProvider_default = FormValidatorProvider;
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { FormField_default as FormField, FormValidator, FormValidatorProvider_default as FormValidatorProvider, useFormValidator };
|
package/dist/image/index.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as graphql12 from "graphql";
|
|
2
|
+
|
|
3
|
+
//#region src/image/fragments.d.ts
|
|
4
|
+
declare const imageFields: graphql12.DocumentNode;
|
|
5
|
+
declare const coverFields: graphql12.DocumentNode;
|
|
6
|
+
declare const backgroundFields: graphql12.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
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
import { isContentField, isImageField, isPlainTextField, isPlainTextareaField } from '
|
|
3
|
-
import type { PageField } from '
|
|
4
|
-
import
|
|
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
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
fields: PageField[]
|
package/dist/page/index.d.ts
CHANGED
|
@@ -1,4 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as graphql38 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: graphql38.DocumentNode;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/page/types.d.ts
|
|
12
|
+
interface DataPage {
|
|
13
|
+
page: Page;
|
|
14
|
+
}
|
|
15
|
+
interface Page extends PageMeta {
|
|
16
|
+
fields: PageField[];
|
|
17
|
+
}
|
|
18
|
+
interface PageMeta {
|
|
19
|
+
title: string;
|
|
20
|
+
seo_title: string | null;
|
|
21
|
+
seo_description: string | null;
|
|
22
|
+
seo_keyword: string | null;
|
|
23
|
+
seo_json_ld: string | null;
|
|
24
|
+
seo_head?: string | null;
|
|
25
|
+
seo_body?: string | null;
|
|
26
|
+
og_title: string | null;
|
|
27
|
+
og_description: string | null;
|
|
28
|
+
og_image: string | null;
|
|
29
|
+
}
|
|
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) => graphql38.DocumentNode;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/page/seo-meta/helpers.d.ts
|
|
94
|
+
type UseSeoMetaOptions = Partial<Omit<PageMeta, 'title'>> & {
|
|
95
|
+
title: string;
|
|
96
|
+
description?: string | null;
|
|
97
|
+
image?: string | null;
|
|
98
|
+
};
|
|
99
|
+
declare function seoMeta(options: UseSeoMetaOptions, modelMeta?: PageMeta): PageMeta;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { DataPage, Page, PageContentField, PageField, PageImageField, PageMeta, PagePlainTextField, PagePlainTextareaField, UseSeoMetaOptions, isContentField, isImageField, isPlainTextField, isPlainTextareaField, pageFields, pageImageFieldForBackground, pageTextField, seoMeta, seoMetaFields };
|