@stephenchenorg/astro 6.1.0 → 7.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.
@@ -1,10 +1,10 @@
1
- import * as vue27 from "vue";
1
+ import * as vue17 from "vue";
2
2
  import { PropType } from "vue";
3
3
 
4
4
  //#region src/form-validator/types.d.ts
5
5
  type FormErrors = Record<string, string[]>;
6
6
  interface FormRule {
7
- validate: (value: any) => boolean;
7
+ validate: (value: any, form: Record<string, any>) => boolean;
8
8
  message: string;
9
9
  }
10
10
  //#endregion
@@ -22,7 +22,7 @@ declare class FormValidator {
22
22
  }
23
23
  //#endregion
24
24
  //#region src/form-validator/components/FormField.d.ts
25
- declare const FormField: vue27.DefineComponent<vue27.ExtractPropTypes<{
25
+ declare const FormField: vue17.DefineComponent<vue17.ExtractPropTypes<{
26
26
  id: {
27
27
  type: StringConstructor;
28
28
  required: true;
@@ -31,9 +31,9 @@ declare const FormField: vue27.DefineComponent<vue27.ExtractPropTypes<{
31
31
  type: PropType<FormRule[]>;
32
32
  default: () => never[];
33
33
  };
34
- }>, () => vue27.VNode<vue27.RendererNode, vue27.RendererElement, {
34
+ }>, () => vue17.VNode<vue17.RendererNode, vue17.RendererElement, {
35
35
  [key: string]: any;
36
- }>[] | undefined, {}, {}, {}, vue27.ComponentOptionsMixin, vue27.ComponentOptionsMixin, {}, string, vue27.PublicProps, Readonly<vue27.ExtractPropTypes<{
36
+ }>[] | undefined, {}, {}, {}, vue17.ComponentOptionsMixin, vue17.ComponentOptionsMixin, {}, string, vue17.PublicProps, Readonly<vue17.ExtractPropTypes<{
37
37
  id: {
38
38
  type: StringConstructor;
39
39
  required: true;
@@ -44,27 +44,27 @@ declare const FormField: vue27.DefineComponent<vue27.ExtractPropTypes<{
44
44
  };
45
45
  }>> & Readonly<{}>, {
46
46
  rules: FormRule[];
47
- }, {}, {}, {}, string, vue27.ComponentProvideOptions, true, {}, any>;
47
+ }, {}, {}, {}, string, vue17.ComponentProvideOptions, true, {}, any>;
48
48
  //#endregion
49
49
  //#region src/form-validator/components/FormValidatorProvider.d.ts
50
50
  interface FormValidatorProviderExposed {
51
51
  formValidator: () => FormValidator;
52
52
  }
53
- declare const FormValidatorProvider: vue27.DefineComponent<vue27.ExtractPropTypes<{
53
+ declare const FormValidatorProvider: vue17.DefineComponent<vue17.ExtractPropTypes<{
54
54
  errors: {
55
55
  type: PropType<FormErrors>;
56
56
  default: () => {};
57
57
  };
58
- }>, () => vue27.VNode<vue27.RendererNode, vue27.RendererElement, {
58
+ }>, () => vue17.VNode<vue17.RendererNode, vue17.RendererElement, {
59
59
  [key: string]: any;
60
- }>[] | undefined, {}, {}, {}, vue27.ComponentOptionsMixin, vue27.ComponentOptionsMixin, {}, string, vue27.PublicProps, Readonly<vue27.ExtractPropTypes<{
60
+ }>[] | undefined, {}, {}, {}, vue17.ComponentOptionsMixin, vue17.ComponentOptionsMixin, {}, string, vue17.PublicProps, Readonly<vue17.ExtractPropTypes<{
61
61
  errors: {
62
62
  type: PropType<FormErrors>;
63
63
  default: () => {};
64
64
  };
65
65
  }>> & Readonly<{}>, {
66
66
  errors: FormErrors;
67
- }, {}, {}, {}, string, vue27.ComponentProvideOptions, true, {}, any>;
67
+ }, {}, {}, {}, string, vue17.ComponentProvideOptions, true, {}, any>;
68
68
  //#endregion
69
69
  //#region src/form-validator/useFormValidator.d.ts
70
70
  declare function useFormValidator(): FormValidator;
@@ -49,7 +49,7 @@ var FormValidator = class {
49
49
  for (const field in this.rules) {
50
50
  const fieldRules = this.rules[field];
51
51
  const value = data[field];
52
- for (const rule of fieldRules) if (!rule.validate(value)) {
52
+ for (const rule of fieldRules) if (!rule.validate(value, data)) {
53
53
  isValid = false;
54
54
  if (!errors[field]) errors[field] = [];
55
55
  errors[field].push(rule.message);
@@ -1,4 +1,4 @@
1
- import * as nanostores16 from "nanostores";
1
+ import * as nanostores15 from "nanostores";
2
2
  import qs from "query-string";
3
3
 
4
4
  //#region src/query-params/types.d.ts
@@ -13,7 +13,7 @@ interface UrlConfig {
13
13
  declare function createUrlConfig(config: UrlConfig): UrlConfig;
14
14
  //#endregion
15
15
  //#region src/query-params/store.d.ts
16
- declare const urlConfigStore: nanostores16.PreinitializedWritableAtom<UrlConfig> & object;
16
+ declare const urlConfigStore: nanostores15.PreinitializedWritableAtom<UrlConfig> & object;
17
17
  //#endregion
18
18
  //#region src/query-params/url.d.ts
19
19
  declare global {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stephenchenorg/astro",
3
3
  "type": "module",
4
- "version": "6.1.0",
4
+ "version": "7.1.0",
5
5
  "description": "Stephenchenorg Astro 前端通用套件",
6
6
  "license": "MIT",
7
7
  "homepage": "https://stephenchenorg-astro.netlify.app",
@@ -15,7 +15,6 @@
15
15
  "components",
16
16
  "query-string",
17
17
  "pagination",
18
- "product-variant",
19
18
  "form-validator",
20
19
  "query-params"
21
20
  ],
@@ -51,10 +50,6 @@
51
50
  "types": "./dist/pagination-vue/index.d.ts",
52
51
  "import": "./dist/pagination-vue/index.js"
53
52
  },
54
- "./product-variant": {
55
- "types": "./dist/product-variant/index.d.ts",
56
- "import": "./dist/product-variant/index.js"
57
- },
58
53
  "./query-params": {
59
54
  "types": "./dist/query-params/index.d.ts",
60
55
  "import": "./dist/query-params/index.js"
@@ -1,73 +0,0 @@
1
- //#region src/product-variant/types.d.ts
2
- interface ProductVariant {
3
- id: number;
4
- /** 商品規格 Key */
5
- combination_key: string | null;
6
- /** 原價 */
7
- listing_price: number;
8
- /** 實際售價 */
9
- selling_price: number;
10
- /** 商品庫存數量 */
11
- inventory: number;
12
- }
13
- interface ProductVariantAttribute {
14
- id: number;
15
- title: string;
16
- options: ProductVariantAttributeOption[];
17
- }
18
- interface ProductVariantAttributeOption {
19
- id: number;
20
- title: string;
21
- }
22
- //#endregion
23
- //#region src/product-variant/ProductVariantSelector.d.ts
24
- declare class ProductVariantSelector {
25
- /**
26
- * 可用的商品變體列表(所有 SKU)
27
- */
28
- availableVariants: ProductVariant[];
29
- /**
30
- * 商品屬性選項列表(如顏色、尺寸等)
31
- */
32
- variantAttributes: ProductVariantAttribute[];
33
- /**
34
- * 使用者已選擇的屬性值
35
- */
36
- selectedAttributes: Record<number, {
37
- optionId: number;
38
- label: string;
39
- }>;
40
- /**
41
- * 匹配到的商品規格物件
42
- */
43
- currentVariant: ProductVariant | undefined;
44
- constructor({
45
- availableVariants,
46
- variantAttributes
47
- }: {
48
- availableVariants: ProductVariant[];
49
- variantAttributes: ProductVariantAttribute[];
50
- });
51
- /**
52
- * 選擇商品規格
53
- */
54
- selectVariant(attributeId: number, optionId: number, label: string): void;
55
- /**
56
- * 獲取已選擇的商品規格選項標籤
57
- */
58
- getSelectedAttributesLabel(): string;
59
- /**
60
- * 確認是否已選擇所有商品規格選項
61
- */
62
- areAllAttributesSelected(): boolean;
63
- /**
64
- * 確認是否已選擇有效的商品規格
65
- */
66
- isValidVariantSelected(): boolean;
67
- /**
68
- * 確認是否有足夠的庫存
69
- */
70
- hasEnoughStock(stock: number): boolean;
71
- }
72
- //#endregion
73
- export { ProductVariant, ProductVariantAttribute, ProductVariantAttributeOption, ProductVariantSelector };
@@ -1,63 +0,0 @@
1
- //#region src/product-variant/ProductVariantSelector.ts
2
- var ProductVariantSelector = class {
3
- /**
4
- * 可用的商品變體列表(所有 SKU)
5
- */
6
- availableVariants = [];
7
- /**
8
- * 商品屬性選項列表(如顏色、尺寸等)
9
- */
10
- variantAttributes = [];
11
- /**
12
- * 使用者已選擇的屬性值
13
- */
14
- selectedAttributes = {};
15
- /**
16
- * 匹配到的商品規格物件
17
- */
18
- currentVariant = void 0;
19
- constructor({ availableVariants, variantAttributes }) {
20
- this.availableVariants = availableVariants;
21
- this.variantAttributes = variantAttributes;
22
- if (availableVariants.length === 1 && availableVariants[0].combination_key === null) this.currentVariant = availableVariants[0];
23
- }
24
- /**
25
- * 選擇商品規格
26
- */
27
- selectVariant(attributeId, optionId, label) {
28
- this.selectedAttributes[attributeId] = {
29
- optionId,
30
- label
31
- };
32
- const variantCombinationKey = Object.values(this.selectedAttributes).map((attr) => attr.optionId).sort((a, b) => a - b).join("-");
33
- this.currentVariant = this.availableVariants.find((variant) => variant.combination_key === variantCombinationKey);
34
- }
35
- /**
36
- * 獲取已選擇的商品規格選項標籤
37
- */
38
- getSelectedAttributesLabel() {
39
- return Object.values(this.selectedAttributes).map((attr) => attr.label).join(", ");
40
- }
41
- /**
42
- * 確認是否已選擇所有商品規格選項
43
- */
44
- areAllAttributesSelected() {
45
- return Object.keys(this.selectedAttributes).length === this.variantAttributes.length;
46
- }
47
- /**
48
- * 確認是否已選擇有效的商品規格
49
- */
50
- isValidVariantSelected() {
51
- return typeof this.currentVariant !== "undefined" && this.currentVariant.inventory > 0;
52
- }
53
- /**
54
- * 確認是否有足夠的庫存
55
- */
56
- hasEnoughStock(stock) {
57
- const specificationStock = this.currentVariant?.inventory || 0;
58
- return specificationStock > 0 && specificationStock >= stock;
59
- }
60
- };
61
-
62
- //#endregion
63
- export { ProductVariantSelector };