@etsoo/appscript 1.3.97 → 1.3.99

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.
@@ -20,7 +20,12 @@ declare enum ProductAssetUnit {
20
20
  * Time
21
21
  * 次
22
22
  */
23
- TIME = 99
23
+ TIME = 99,
24
+ /**
25
+ * Money
26
+ * 储值
27
+ */
28
+ MONEY = 100
24
29
  }
25
30
  /**
26
31
  * Product weight units
@@ -60,6 +65,7 @@ export declare const ProductUnit: {
60
65
  KILOGRAM: ProductWeightUnit.KILOGRAM;
61
66
  TON: ProductWeightUnit.TON;
62
67
  TIME: ProductAssetUnit.TIME;
68
+ MONEY: ProductAssetUnit.MONEY;
63
69
  HOUR: RepeatOption.HOUR;
64
70
  DAY: RepeatOption.DAY;
65
71
  YEAR: RepeatOption.YEAR;
@@ -80,6 +86,7 @@ export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | Pr
80
86
  export declare const AssetUnits: {
81
87
  [x: number]: string;
82
88
  TIME: ProductAssetUnit.TIME;
89
+ MONEY: ProductAssetUnit.MONEY;
83
90
  HOUR: RepeatOption.HOUR;
84
91
  DAY: RepeatOption.DAY;
85
92
  YEAR: RepeatOption.YEAR;
@@ -26,6 +26,11 @@ var ProductAssetUnit;
26
26
  * 次
27
27
  */
28
28
  ProductAssetUnit[ProductAssetUnit["TIME"] = 99] = "TIME";
29
+ /**
30
+ * Money
31
+ * 储值
32
+ */
33
+ ProductAssetUnit[ProductAssetUnit["MONEY"] = 100] = "MONEY";
29
34
  })(ProductAssetUnit || (ProductAssetUnit = {}));
30
35
  /**
31
36
  * Product weight units
@@ -244,8 +244,9 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
244
244
  * Cache price
245
245
  * @param id Item id
246
246
  * @param price Price
247
+ * @param overrideExisting Override existing price
247
248
  */
248
- cachePrice(id: T['id'], price: number): void;
249
+ cachePrice(id: T['id'], price: number, overrideExisting?: boolean): void;
249
250
  /**
250
251
  * Clear storage
251
252
  * @param keepOwner Keep owner data
@@ -202,9 +202,11 @@ class ShoppingCart {
202
202
  * Cache price
203
203
  * @param id Item id
204
204
  * @param price Price
205
+ * @param overrideExisting Override existing price
205
206
  */
206
- cachePrice(id, price) {
207
- this.prices[id] = price;
207
+ cachePrice(id, price, overrideExisting = false) {
208
+ if (overrideExisting || this.prices[id] == null)
209
+ this.prices[id] = price;
208
210
  }
209
211
  /**
210
212
  * Clear storage
@@ -308,6 +310,7 @@ class ShoppingCart {
308
310
  * @returns Updated or not
309
311
  */
310
312
  updateItem(id, qty, itemCreator) {
313
+ var _a;
311
314
  const index = this.items.findIndex((item) => item.id === id);
312
315
  if (qty == null) {
313
316
  // Remove the item
@@ -335,10 +338,12 @@ class ShoppingCart {
335
338
  else {
336
339
  // Update
337
340
  const item = this.items[index];
338
- const price = item.price;
341
+ // Price may be cached first
342
+ const price = (_a = this.prices[id]) !== null && _a !== void 0 ? _a : item.price;
339
343
  const newItem = {
340
344
  ...item,
341
345
  qty,
346
+ price,
342
347
  subtotal: price * qty,
343
348
  discount: 0
344
349
  };
@@ -353,7 +358,7 @@ class ShoppingCart {
353
358
  * @param price New price
354
359
  */
355
360
  updatePrice(id, price) {
356
- this.cachePrice(id, price);
361
+ this.cachePrice(id, price, true);
357
362
  const index = this.items.findIndex((item) => item.id === id);
358
363
  if (index !== -1) {
359
364
  const item = this.items[index];
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "Week",
207
207
  "unitFORTNIGHT": "Fortnight",
208
208
  "unitFOURWEEK": "4-week",
209
+ "unitMONEY": "Money",
209
210
  "unitMONTH": "Month",
210
211
  "unitBIMONTH": "2-month",
211
212
  "unitQUATER": "Quater",
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "周",
207
207
  "unitFORTNIGHT": "两周",
208
208
  "unitFOURWEEK": "四周",
209
+ "unitMONEY": "储值",
209
210
  "unitMONTH": "月",
210
211
  "unitBIMONTH": "两月",
211
212
  "unitQUATER": "季度",
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "週",
207
207
  "unitFORTNIGHT": "兩週",
208
208
  "unitFOURWEEK": "四周",
209
+ "unitMONEY": "儲值",
209
210
  "unitMONTH": "月",
210
211
  "unitBIMONTH": "兩月",
211
212
  "unitQUATER": "季度",
@@ -20,7 +20,12 @@ declare enum ProductAssetUnit {
20
20
  * Time
21
21
  * 次
22
22
  */
23
- TIME = 99
23
+ TIME = 99,
24
+ /**
25
+ * Money
26
+ * 储值
27
+ */
28
+ MONEY = 100
24
29
  }
25
30
  /**
26
31
  * Product weight units
@@ -60,6 +65,7 @@ export declare const ProductUnit: {
60
65
  KILOGRAM: ProductWeightUnit.KILOGRAM;
61
66
  TON: ProductWeightUnit.TON;
62
67
  TIME: ProductAssetUnit.TIME;
68
+ MONEY: ProductAssetUnit.MONEY;
63
69
  HOUR: RepeatOption.HOUR;
64
70
  DAY: RepeatOption.DAY;
65
71
  YEAR: RepeatOption.YEAR;
@@ -80,6 +86,7 @@ export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | Pr
80
86
  export declare const AssetUnits: {
81
87
  [x: number]: string;
82
88
  TIME: ProductAssetUnit.TIME;
89
+ MONEY: ProductAssetUnit.MONEY;
83
90
  HOUR: RepeatOption.HOUR;
84
91
  DAY: RepeatOption.DAY;
85
92
  YEAR: RepeatOption.YEAR;
@@ -23,6 +23,11 @@ var ProductAssetUnit;
23
23
  * 次
24
24
  */
25
25
  ProductAssetUnit[ProductAssetUnit["TIME"] = 99] = "TIME";
26
+ /**
27
+ * Money
28
+ * 储值
29
+ */
30
+ ProductAssetUnit[ProductAssetUnit["MONEY"] = 100] = "MONEY";
26
31
  })(ProductAssetUnit || (ProductAssetUnit = {}));
27
32
  /**
28
33
  * Product weight units
@@ -244,8 +244,9 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
244
244
  * Cache price
245
245
  * @param id Item id
246
246
  * @param price Price
247
+ * @param overrideExisting Override existing price
247
248
  */
248
- cachePrice(id: T['id'], price: number): void;
249
+ cachePrice(id: T['id'], price: number, overrideExisting?: boolean): void;
249
250
  /**
250
251
  * Clear storage
251
252
  * @param keepOwner Keep owner data
@@ -199,9 +199,11 @@ export class ShoppingCart {
199
199
  * Cache price
200
200
  * @param id Item id
201
201
  * @param price Price
202
+ * @param overrideExisting Override existing price
202
203
  */
203
- cachePrice(id, price) {
204
- this.prices[id] = price;
204
+ cachePrice(id, price, overrideExisting = false) {
205
+ if (overrideExisting || this.prices[id] == null)
206
+ this.prices[id] = price;
205
207
  }
206
208
  /**
207
209
  * Clear storage
@@ -305,6 +307,7 @@ export class ShoppingCart {
305
307
  * @returns Updated or not
306
308
  */
307
309
  updateItem(id, qty, itemCreator) {
310
+ var _a;
308
311
  const index = this.items.findIndex((item) => item.id === id);
309
312
  if (qty == null) {
310
313
  // Remove the item
@@ -332,10 +335,12 @@ export class ShoppingCart {
332
335
  else {
333
336
  // Update
334
337
  const item = this.items[index];
335
- const price = item.price;
338
+ // Price may be cached first
339
+ const price = (_a = this.prices[id]) !== null && _a !== void 0 ? _a : item.price;
336
340
  const newItem = {
337
341
  ...item,
338
342
  qty,
343
+ price,
339
344
  subtotal: price * qty,
340
345
  discount: 0
341
346
  };
@@ -350,7 +355,7 @@ export class ShoppingCart {
350
355
  * @param price New price
351
356
  */
352
357
  updatePrice(id, price) {
353
- this.cachePrice(id, price);
358
+ this.cachePrice(id, price, true);
354
359
  const index = this.items.findIndex((item) => item.id === id);
355
360
  if (index !== -1) {
356
361
  const item = this.items[index];
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "Week",
207
207
  "unitFORTNIGHT": "Fortnight",
208
208
  "unitFOURWEEK": "4-week",
209
+ "unitMONEY": "Money",
209
210
  "unitMONTH": "Month",
210
211
  "unitBIMONTH": "2-month",
211
212
  "unitQUATER": "Quater",
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "周",
207
207
  "unitFORTNIGHT": "两周",
208
208
  "unitFOURWEEK": "四周",
209
+ "unitMONEY": "储值",
209
210
  "unitMONTH": "月",
210
211
  "unitBIMONTH": "两月",
211
212
  "unitQUATER": "季度",
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "週",
207
207
  "unitFORTNIGHT": "兩週",
208
208
  "unitFOURWEEK": "四周",
209
+ "unitMONEY": "儲值",
209
210
  "unitMONTH": "月",
210
211
  "unitBIMONTH": "兩月",
211
212
  "unitQUATER": "季度",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.97",
3
+ "version": "1.3.99",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -60,7 +60,7 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "@babel/cli": "^7.21.5",
63
- "@babel/core": "^7.21.5",
63
+ "@babel/core": "^7.21.8",
64
64
  "@babel/plugin-transform-runtime": "^7.21.4",
65
65
  "@babel/preset-env": "^7.21.5",
66
66
  "@babel/runtime-corejs3": "^7.21.5",
@@ -23,7 +23,13 @@ enum ProductAssetUnit {
23
23
  * Time
24
24
  * 次
25
25
  */
26
- TIME = 99
26
+ TIME = 99,
27
+
28
+ /**
29
+ * Money
30
+ * 储值
31
+ */
32
+ MONEY = 100
27
33
  }
28
34
 
29
35
  /**
@@ -397,9 +397,11 @@ export class ShoppingCart<T extends ShoppingCartItem> {
397
397
  * Cache price
398
398
  * @param id Item id
399
399
  * @param price Price
400
+ * @param overrideExisting Override existing price
400
401
  */
401
- cachePrice(id: T['id'], price: number) {
402
- this.prices[id] = price;
402
+ cachePrice(id: T['id'], price: number, overrideExisting: boolean = false) {
403
+ if (overrideExisting || this.prices[id] == null)
404
+ this.prices[id] = price;
403
405
  }
404
406
 
405
407
  /**
@@ -546,10 +548,13 @@ export class ShoppingCart<T extends ShoppingCartItem> {
546
548
  } else {
547
549
  // Update
548
550
  const item = this.items[index];
549
- const price = item.price;
551
+
552
+ // Price may be cached first
553
+ const price = this.prices[id] ?? item.price;
550
554
  const newItem = {
551
555
  ...item,
552
556
  qty,
557
+ price,
553
558
  subtotal: price * qty,
554
559
  discount: 0
555
560
  };
@@ -566,7 +571,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
566
571
  * @param price New price
567
572
  */
568
573
  updatePrice(id: T['id'], price: number) {
569
- this.cachePrice(id, price);
574
+ this.cachePrice(id, price, true);
570
575
 
571
576
  const index = this.items.findIndex((item) => item.id === id);
572
577
  if (index !== -1) {
package/src/i18n/en.json CHANGED
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "Week",
207
207
  "unitFORTNIGHT": "Fortnight",
208
208
  "unitFOURWEEK": "4-week",
209
+ "unitMONEY": "Money",
209
210
  "unitMONTH": "Month",
210
211
  "unitBIMONTH": "2-month",
211
212
  "unitQUATER": "Quater",
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "周",
207
207
  "unitFORTNIGHT": "两周",
208
208
  "unitFOURWEEK": "四周",
209
+ "unitMONEY": "储值",
209
210
  "unitMONTH": "月",
210
211
  "unitBIMONTH": "两月",
211
212
  "unitQUATER": "季度",
@@ -206,6 +206,7 @@
206
206
  "unitWEEK": "週",
207
207
  "unitFORTNIGHT": "兩週",
208
208
  "unitFOURWEEK": "四周",
209
+ "unitMONEY": "儲值",
209
210
  "unitMONTH": "月",
210
211
  "unitBIMONTH": "兩月",
211
212
  "unitQUATER": "季度",