@stephenchenorg/astro 5.0.1 → 6.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.
Files changed (82) hide show
  1. package/dist/api/index.d.ts +76 -3
  2. package/dist/api/index.js +140 -3
  3. package/dist/company-setting/index.d.ts +47 -3
  4. package/dist/company-setting/index.js +47 -3
  5. package/dist/form-validator/index.d.ts +72 -6
  6. package/dist/form-validator/index.js +106 -5
  7. package/dist/image/index.d.ts +16 -4
  8. package/dist/image/index.js +30 -4
  9. package/dist/page/components/PageFieldRender.astro +3 -3
  10. package/dist/page/index.d.ts +101 -4
  11. package/dist/page/index.js +88 -4
  12. package/dist/pagination-astro/index.d.ts +30 -2
  13. package/dist/pagination-astro/index.js +37 -2
  14. package/dist/pagination-vue/index.d.ts +33 -2
  15. package/dist/pagination-vue/index.js +44 -2
  16. package/dist/product-variant/index.d.ts +69 -2
  17. package/dist/product-variant/index.js +57 -2
  18. package/dist/query-params/components/ProvideUrlConfig.astro +1 -2
  19. package/dist/query-params/index.d.ts +35 -6
  20. package/dist/query-params/index.js +62 -6
  21. package/package.json +10 -6
  22. package/dist/api/error.d.ts +0 -54
  23. package/dist/api/error.js +0 -97
  24. package/dist/api/errorResponse.d.ts +0 -1
  25. package/dist/api/errorResponse.js +0 -9
  26. package/dist/api/fetch.d.ts +0 -13
  27. package/dist/api/fetch.js +0 -49
  28. package/dist/company-setting/create.d.ts +0 -18
  29. package/dist/company-setting/create.js +0 -19
  30. package/dist/company-setting/fragments.d.ts +0 -1
  31. package/dist/company-setting/fragments.js +0 -20
  32. package/dist/company-setting/types.d.ts +0 -20
  33. package/dist/company-setting/types.js +0 -0
  34. package/dist/form-validator/FormValidator.d.ts +0 -12
  35. package/dist/form-validator/FormValidator.js +0 -47
  36. package/dist/form-validator/components/FormField.vue +0 -30
  37. package/dist/form-validator/components/FormValidatorProvider.d.ts +0 -22
  38. package/dist/form-validator/components/FormValidatorProvider.js +0 -24
  39. package/dist/form-validator/injectionKey.d.ts +0 -3
  40. package/dist/form-validator/injectionKey.js +0 -1
  41. package/dist/form-validator/types.d.ts +0 -5
  42. package/dist/form-validator/types.js +0 -0
  43. package/dist/image/fragments.d.ts +0 -3
  44. package/dist/image/fragments.js +0 -25
  45. package/dist/image/types.d.ts +0 -6
  46. package/dist/image/types.js +0 -0
  47. package/dist/page/field/fragments.d.ts +0 -5
  48. package/dist/page/field/fragments.js +0 -23
  49. package/dist/page/field/helpers.d.ts +0 -7
  50. package/dist/page/field/helpers.js +0 -20
  51. package/dist/page/field/index.d.ts +0 -2
  52. package/dist/page/field/index.js +0 -2
  53. package/dist/page/seo-meta/fragments.d.ts +0 -1
  54. package/dist/page/seo-meta/fragments.js +0 -14
  55. package/dist/page/seo-meta/helpers.d.ts +0 -7
  56. package/dist/page/seo-meta/helpers.js +0 -14
  57. package/dist/page/seo-meta/index.d.ts +0 -2
  58. package/dist/page/seo-meta/index.js +0 -2
  59. package/dist/page/types.d.ts +0 -69
  60. package/dist/page/types.js +0 -0
  61. package/dist/pagination-astro/types.d.ts +0 -5
  62. package/dist/pagination-astro/types.js +0 -0
  63. package/dist/pagination-astro/usePagination.d.ts +0 -20
  64. package/dist/pagination-astro/usePagination.js +0 -42
  65. package/dist/pagination-vue/types.d.ts +0 -5
  66. package/dist/pagination-vue/types.js +0 -0
  67. package/dist/pagination-vue/usePagination.d.ts +0 -21
  68. package/dist/pagination-vue/usePagination.js +0 -44
  69. package/dist/product-variant/ProductVariantSelector.d.ts +0 -42
  70. package/dist/product-variant/ProductVariantSelector.js +0 -52
  71. package/dist/product-variant/types.d.ts +0 -20
  72. package/dist/product-variant/types.js +0 -0
  73. package/dist/query-params/config.d.ts +0 -2
  74. package/dist/query-params/config.js +0 -3
  75. package/dist/query-params/store.d.ts +0 -2
  76. package/dist/query-params/store.js +0 -7
  77. package/dist/query-params/types.d.ts +0 -6
  78. package/dist/query-params/types.js +0 -0
  79. package/dist/query-params/url.d.ts +0 -13
  80. package/dist/query-params/url.js +0 -30
  81. package/dist/query-params/utils.d.ts +0 -2
  82. package/dist/query-params/utils.js +0 -21
@@ -1,20 +0,0 @@
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
- };
@@ -1,42 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- export interface Paginator<T> {
2
- total: number;
3
- per_page: number;
4
- data: T[];
5
- }
File without changes
@@ -1,21 +0,0 @@
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
- };
@@ -1,44 +0,0 @@
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,42 +0,0 @@
1
- import type { ProductVariant, ProductVariantAttribute } from './types';
2
- export declare class ProductVariantSelector {
3
- /**
4
- * 可用的商品變體列表(所有 SKU)
5
- */
6
- availableVariants: ProductVariant[];
7
- /**
8
- * 商品屬性選項列表(如顏色、尺寸等)
9
- */
10
- variantAttributes: ProductVariantAttribute[];
11
- /**
12
- * 使用者已選擇的屬性值
13
- */
14
- selectedAttributes: Record<number, {
15
- optionId: number;
16
- label: string;
17
- }>;
18
- /**
19
- * 匹配到的商品規格物件
20
- */
21
- currentVariant: ProductVariant | undefined;
22
- constructor({ availableVariants, variantAttributes }: {
23
- availableVariants: ProductVariant[];
24
- variantAttributes: ProductVariantAttribute[];
25
- });
26
- /**
27
- * 選擇商品規格
28
- */
29
- selectVariant(attributeId: number, optionId: number, label: string): void;
30
- /**
31
- * 獲取已選擇的商品規格選項標籤
32
- */
33
- getSelectedAttributesLabel(): string;
34
- /**
35
- * 確認是否已選擇所有商品規格選項
36
- */
37
- areAllAttributesSelected(): boolean;
38
- /**
39
- * 確認是否有足夠的庫存
40
- */
41
- hasEnoughStock(stock: number): boolean;
42
- }
@@ -1,52 +0,0 @@
1
- export class ProductVariantSelector {
2
- /**
3
- * 可用的商品變體列表(所有 SKU)
4
- */
5
- availableVariants = [];
6
- /**
7
- * 商品屬性選項列表(如顏色、尺寸等)
8
- */
9
- variantAttributes = [];
10
- /**
11
- * 使用者已選擇的屬性值
12
- */
13
- selectedAttributes = {};
14
- /**
15
- * 匹配到的商品規格物件
16
- */
17
- currentVariant = void 0;
18
- constructor({ availableVariants, variantAttributes }) {
19
- this.availableVariants = availableVariants;
20
- this.variantAttributes = variantAttributes;
21
- if (availableVariants.length === 1 && availableVariants[0].combination_key === null) {
22
- this.currentVariant = availableVariants[0];
23
- }
24
- }
25
- /**
26
- * 選擇商品規格
27
- */
28
- selectVariant(attributeId, optionId, label) {
29
- this.selectedAttributes[attributeId] = { optionId, label };
30
- const variantCombinationKey = Object.values(this.selectedAttributes).map((attr) => attr.optionId).sort((a, b) => a - b).join("-");
31
- this.currentVariant = this.availableVariants.find((variant) => variant.combination_key === variantCombinationKey);
32
- }
33
- /**
34
- * 獲取已選擇的商品規格選項標籤
35
- */
36
- getSelectedAttributesLabel() {
37
- return Object.values(this.selectedAttributes).map((attr) => attr.label).join(", ");
38
- }
39
- /**
40
- * 確認是否已選擇所有商品規格選項
41
- */
42
- areAllAttributesSelected() {
43
- return Object.keys(this.selectedAttributes).length === this.variantAttributes.length;
44
- }
45
- /**
46
- * 確認是否有足夠的庫存
47
- */
48
- hasEnoughStock(stock) {
49
- const specificationStock = this.currentVariant?.inventory || 0;
50
- return specificationStock > 0 && specificationStock >= stock;
51
- }
52
- }
@@ -1,20 +0,0 @@
1
- export interface ProductVariant {
2
- id: number;
3
- /** 商品規格 Key */
4
- combination_key: string | null;
5
- /** 原價 */
6
- listing_price: number;
7
- /** 實際售價 */
8
- selling_price: number;
9
- /** 商品庫存數量 */
10
- inventory: number;
11
- }
12
- export interface ProductVariantAttribute {
13
- id: number;
14
- title: string;
15
- options: ProductVariantAttributeOption[];
16
- }
17
- export interface ProductVariantAttributeOption {
18
- id: number;
19
- title: string;
20
- }
File without changes
@@ -1,2 +0,0 @@
1
- import type { UrlConfig } from './types';
2
- export declare function createUrlConfig(config: UrlConfig): UrlConfig;
@@ -1,3 +0,0 @@
1
- export function createUrlConfig(config) {
2
- return config;
3
- }
@@ -1,2 +0,0 @@
1
- import type { UrlConfig } from './types';
2
- export declare const urlConfigStore: import("nanostores").PreinitializedWritableAtom<UrlConfig> & object;
@@ -1,7 +0,0 @@
1
- import { atom } from "nanostores";
2
- export const urlConfigStore = atom({
3
- baseUrl: "",
4
- hash: "",
5
- params: {},
6
- defaultParams: {}
7
- });
@@ -1,6 +0,0 @@
1
- export interface UrlConfig {
2
- baseUrl: string;
3
- hash?: string;
4
- params: Record<string, any>;
5
- defaultParams?: Record<string, any>;
6
- }
File without changes
@@ -1,13 +0,0 @@
1
- import type { UrlConfig } from './types';
2
- import qs from 'query-string';
3
- declare global {
4
- interface Window {
5
- __astro_provide_url_config__?: UrlConfig;
6
- }
7
- }
8
- export interface QueryParamsUrlOptions {
9
- clear?: boolean;
10
- transformParams?: (params: Record<string, any>) => Record<string, any>;
11
- }
12
- export declare function queryParamsUrl(additionalParams: Record<string, any>, urlConfig?: UrlConfig, options?: QueryParamsUrlOptions): string;
13
- export declare function parseQueryParams(search: string): qs.ParsedQuery<string>;
@@ -1,30 +0,0 @@
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
- }, options = {}) {
8
- const {
9
- clear = false,
10
- transformParams
11
- } = options;
12
- const config = typeof window !== "undefined" ? urlConfigStore.get() : urlConfig;
13
- let params = {};
14
- if (!clear) {
15
- params = mergeUrlParams(config.params, additionalParams);
16
- if (transformParams) {
17
- params = transformParams(params);
18
- }
19
- params = cleanParams(params, config.defaultParams || {});
20
- }
21
- const queryString = qs.stringify(params, {
22
- skipEmptyString: true,
23
- skipNull: true,
24
- sort: false
25
- });
26
- return `${config.baseUrl}${queryString ? "?" : ""}${queryString}${config.hash ? `#${config.hash}` : ""}`;
27
- }
28
- export function parseQueryParams(search) {
29
- return qs.parse(search);
30
- }
@@ -1,2 +0,0 @@
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>;
@@ -1,21 +0,0 @@
1
- export function mergeUrlParams(baseParams, userParams) {
2
- return Object.keys(baseParams).reduce((result, key) => {
3
- if (userParams[key] === null) {
4
- result[key] = null;
5
- } else if (Array.isArray(baseParams[key])) {
6
- result[key] = Array.from(/* @__PURE__ */ new Set([...baseParams[key], ...userParams[key] || []]));
7
- } else {
8
- result[key] = typeof userParams[key] !== "undefined" ? userParams[key] : baseParams[key];
9
- }
10
- return result;
11
- }, {});
12
- }
13
- export function cleanParams(params, defaultParams) {
14
- const newParams = JSON.parse(JSON.stringify(params));
15
- Object.keys(newParams).forEach((key) => {
16
- if (Object.keys(defaultParams).includes(key) && newParams[key] === defaultParams[key]) {
17
- newParams[key] = null;
18
- }
19
- });
20
- return newParams;
21
- }