@etsoo/appscript 1.4.49 → 1.4.51

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,5 +1,10 @@
1
+ import { ArrayUtils } from '@etsoo/shared';
2
+ import { CultureGridItem } from '../../src';
1
3
  import { BusinessUtils } from '../../src/business/BusinessUtils';
2
4
 
5
+ // Import the ArrayUtils
6
+ ArrayUtils.differences([], []);
7
+
3
8
  test('Tests for BusinessUtils.formatAvatarTitle', () => {
4
9
  // Assert
5
10
  expect(BusinessUtils.formatAvatarTitle('Garry Xiao')).toBe('GX');
@@ -7,3 +12,35 @@ test('Tests for BusinessUtils.formatAvatarTitle', () => {
7
12
  expect(BusinessUtils.formatAvatarTitle('Etsoo', 3, 'E')).toBe('E');
8
13
  expect(BusinessUtils.formatAvatarTitle('Etsoo', 5)).toBe('ETSOO');
9
14
  });
15
+
16
+ test('Tests for BusinessUtils.formatCultues', () => {
17
+ // Arrange
18
+ const cultures = [
19
+ {
20
+ id: 'zh-Hans',
21
+ label: '中文(简体), Chinese (Simplified)'
22
+ },
23
+ {
24
+ id: 'en',
25
+ label: '英语, English'
26
+ },
27
+ {
28
+ id: 'de',
29
+ label: '德语, German'
30
+ },
31
+ {
32
+ id: 'zh-Hant',
33
+ label: '中文(繁体), Chinese (Traditional)'
34
+ }
35
+ ];
36
+ const data: { cultures: CultureGridItem[] } = {
37
+ cultures: [{ id: 'zh-Hant', title: '繁体' }]
38
+ };
39
+
40
+ // Act
41
+ BusinessUtils.formatCultues(cultures, data);
42
+
43
+ // Assert
44
+ expect(data.cultures[0].id).toBe('en');
45
+ expect(data.cultures.slice(-1)[0].id).toBe('zh-Hant');
46
+ });
@@ -1,4 +1,5 @@
1
- import { DataTypes, ListType } from '@etsoo/shared';
1
+ import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
+ import { CultureGridItem } from './CultureItem';
2
3
  /**
3
4
  * Business utils
4
5
  */
@@ -11,6 +12,14 @@ export declare namespace BusinessUtils {
11
12
  * @returns Result
12
13
  */
13
14
  function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
15
+ /**
16
+ * Format cultures for data
17
+ * @param cultures Supported cultures
18
+ * @param data Data to format
19
+ */
20
+ function formatCultues(cultures: ListType1[], data: {
21
+ cultures?: CultureGridItem[];
22
+ }): void;
14
23
  /**
15
24
  * Get 12-month items
16
25
  * @param monthLabels Month labels
@@ -38,6 +38,30 @@ var BusinessUtils;
38
38
  return defaultTitle;
39
39
  }
40
40
  BusinessUtils.formatAvatarTitle = formatAvatarTitle;
41
+ /**
42
+ * Format cultures for data
43
+ * @param cultures Supported cultures
44
+ * @param data Data to format
45
+ */
46
+ function formatCultues(cultures, data) {
47
+ var _a;
48
+ // Add the lost cultures
49
+ const allCultures = (_a = data.cultures) !== null && _a !== void 0 ? _a : [];
50
+ cultures.forEach((culture) => {
51
+ if (!allCultures.some((a) => a.id === culture.id)) {
52
+ allCultures.push({ id: culture.id, title: '' });
53
+ }
54
+ });
55
+ // Remove the default culture
56
+ const index = allCultures.findIndex((a) => a.id === cultures[0].id);
57
+ if (index !== -1)
58
+ allCultures.splice(index, 1);
59
+ // Sort
60
+ allCultures.sortByProperty('id', cultures.map((c) => c.id));
61
+ // Set back
62
+ data.cultures = allCultures;
63
+ }
64
+ BusinessUtils.formatCultues = formatCultues;
41
65
  /**
42
66
  * Get 12-month items
43
67
  * @param monthLabels Month labels
@@ -218,7 +218,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
218
218
  * Cached prices
219
219
  * 缓存的价格
220
220
  */
221
- private readonly prices;
221
+ private prices;
222
222
  /**
223
223
  * Onchange callback
224
224
  * 改变时回调
@@ -219,6 +219,7 @@ class ShoppingCart {
219
219
  clear(keepOwner) {
220
220
  this.items.length = 0;
221
221
  this.promotions.length = 0;
222
+ this.prices = {};
222
223
  if (keepOwner) {
223
224
  this.save();
224
225
  }
@@ -1,4 +1,5 @@
1
- import { DataTypes, ListType } from '@etsoo/shared';
1
+ import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
+ import { CultureGridItem } from './CultureItem';
2
3
  /**
3
4
  * Business utils
4
5
  */
@@ -11,6 +12,14 @@ export declare namespace BusinessUtils {
11
12
  * @returns Result
12
13
  */
13
14
  function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
15
+ /**
16
+ * Format cultures for data
17
+ * @param cultures Supported cultures
18
+ * @param data Data to format
19
+ */
20
+ function formatCultues(cultures: ListType1[], data: {
21
+ cultures?: CultureGridItem[];
22
+ }): void;
14
23
  /**
15
24
  * Get 12-month items
16
25
  * @param monthLabels Month labels
@@ -35,6 +35,30 @@ export var BusinessUtils;
35
35
  return defaultTitle;
36
36
  }
37
37
  BusinessUtils.formatAvatarTitle = formatAvatarTitle;
38
+ /**
39
+ * Format cultures for data
40
+ * @param cultures Supported cultures
41
+ * @param data Data to format
42
+ */
43
+ function formatCultues(cultures, data) {
44
+ var _a;
45
+ // Add the lost cultures
46
+ const allCultures = (_a = data.cultures) !== null && _a !== void 0 ? _a : [];
47
+ cultures.forEach((culture) => {
48
+ if (!allCultures.some((a) => a.id === culture.id)) {
49
+ allCultures.push({ id: culture.id, title: '' });
50
+ }
51
+ });
52
+ // Remove the default culture
53
+ const index = allCultures.findIndex((a) => a.id === cultures[0].id);
54
+ if (index !== -1)
55
+ allCultures.splice(index, 1);
56
+ // Sort
57
+ allCultures.sortByProperty('id', cultures.map((c) => c.id));
58
+ // Set back
59
+ data.cultures = allCultures;
60
+ }
61
+ BusinessUtils.formatCultues = formatCultues;
38
62
  /**
39
63
  * Get 12-month items
40
64
  * @param monthLabels Month labels
@@ -218,7 +218,7 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
218
218
  * Cached prices
219
219
  * 缓存的价格
220
220
  */
221
- private readonly prices;
221
+ private prices;
222
222
  /**
223
223
  * Onchange callback
224
224
  * 改变时回调
@@ -216,6 +216,7 @@ export class ShoppingCart {
216
216
  clear(keepOwner) {
217
217
  this.items.length = 0;
218
218
  this.promotions.length = 0;
219
+ this.prices = {};
219
220
  if (keepOwner) {
220
221
  this.save();
221
222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.49",
3
+ "version": "1.4.51",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -1,4 +1,5 @@
1
- import { DataTypes, ListType } from '@etsoo/shared';
1
+ import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
+ import { CultureGridItem } from './CultureItem';
2
3
 
3
4
  /**
4
5
  * Business utils
@@ -43,6 +44,37 @@ export namespace BusinessUtils {
43
44
  return defaultTitle;
44
45
  }
45
46
 
47
+ /**
48
+ * Format cultures for data
49
+ * @param cultures Supported cultures
50
+ * @param data Data to format
51
+ */
52
+ export function formatCultues(
53
+ cultures: ListType1[],
54
+ data: { cultures?: CultureGridItem[] }
55
+ ) {
56
+ // Add the lost cultures
57
+ const allCultures = data.cultures ?? [];
58
+ cultures.forEach((culture) => {
59
+ if (!allCultures.some((a) => a.id === culture.id)) {
60
+ allCultures.push({ id: culture.id, title: '' });
61
+ }
62
+ });
63
+
64
+ // Remove the default culture
65
+ const index = allCultures.findIndex((a) => a.id === cultures[0].id);
66
+ if (index !== -1) allCultures.splice(index, 1);
67
+
68
+ // Sort
69
+ allCultures.sortByProperty(
70
+ 'id',
71
+ cultures.map((c) => c.id)
72
+ );
73
+
74
+ // Set back
75
+ data.cultures = allCultures;
76
+ }
77
+
46
78
  /**
47
79
  * Get 12-month items
48
80
  * @param monthLabels Month labels
@@ -334,7 +334,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
334
334
  * Cached prices
335
335
  * 缓存的价格
336
336
  */
337
- private readonly prices: Record<T['id'], number> = {} as any;
337
+ private prices: Record<T['id'], number> = {} as any;
338
338
 
339
339
  /**
340
340
  * Onchange callback
@@ -427,6 +427,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
427
427
  clear(keepOwner?: boolean) {
428
428
  this.items.length = 0;
429
429
  this.promotions.length = 0;
430
+ this.prices = {} as any;
430
431
 
431
432
  if (keepOwner) {
432
433
  this.save();