react-native-chatbot-ai 0.1.2 → 0.1.4

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 (79) hide show
  1. package/lib/module/components/chat/footer/index.js +2 -2
  2. package/lib/module/components/chat/footer/index.js.map +1 -1
  3. package/lib/module/components/chat/item/ChatAIAnswerMessageItem.js +207 -40
  4. package/lib/module/components/chat/item/ChatAIAnswerMessageItem.js.map +1 -1
  5. package/lib/module/components/chat/item/ChatTable.js +77 -0
  6. package/lib/module/components/chat/item/ChatTable.js.map +1 -0
  7. package/lib/module/components/chat/item/DeeplinkItem.js +66 -0
  8. package/lib/module/components/chat/item/DeeplinkItem.js.map +1 -0
  9. package/lib/module/components/product/CardHorizontal.js +339 -0
  10. package/lib/module/components/product/CardHorizontal.js.map +1 -0
  11. package/lib/module/constants/query.js +2 -1
  12. package/lib/module/constants/query.js.map +1 -1
  13. package/lib/module/context/ChatContext.js +18 -3
  14. package/lib/module/context/ChatContext.js.map +1 -1
  15. package/lib/module/hooks/message/useStreamMessage.js +0 -1
  16. package/lib/module/hooks/message/useStreamMessage.js.map +1 -1
  17. package/lib/module/hooks/product/useSearchProduct.js +26 -0
  18. package/lib/module/hooks/product/useSearchProduct.js.map +1 -0
  19. package/lib/module/hooks/upload/useFileUpload.js +0 -4
  20. package/lib/module/hooks/upload/useFileUpload.js.map +1 -1
  21. package/lib/module/services/endpoints.js +3 -0
  22. package/lib/module/services/endpoints.js.map +1 -1
  23. package/lib/module/store/products.js +11 -0
  24. package/lib/module/store/products.js.map +1 -0
  25. package/lib/module/store/session.js +1 -1
  26. package/lib/module/store/session.js.map +1 -1
  27. package/lib/module/types/common.js +20 -0
  28. package/lib/module/types/common.js.map +1 -1
  29. package/lib/module/utils/device.js +0 -1
  30. package/lib/module/utils/device.js.map +1 -1
  31. package/lib/module/utils/prototype.js +136 -0
  32. package/lib/module/utils/prototype.js.map +1 -0
  33. package/lib/typescript/src/components/chat/item/ChatAIAnswerMessageItem.d.ts +0 -7
  34. package/lib/typescript/src/components/chat/item/ChatAIAnswerMessageItem.d.ts.map +1 -1
  35. package/lib/typescript/src/components/chat/item/ChatTable.d.ts +11 -0
  36. package/lib/typescript/src/components/chat/item/ChatTable.d.ts.map +1 -0
  37. package/lib/typescript/src/components/chat/item/DeeplinkItem.d.ts +8 -0
  38. package/lib/typescript/src/components/chat/item/DeeplinkItem.d.ts.map +1 -0
  39. package/lib/typescript/src/components/product/CardHorizontal.d.ts +6 -0
  40. package/lib/typescript/src/components/product/CardHorizontal.d.ts.map +1 -0
  41. package/lib/typescript/src/constants/query.d.ts +1 -0
  42. package/lib/typescript/src/constants/query.d.ts.map +1 -1
  43. package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
  44. package/lib/typescript/src/hooks/message/useStreamMessage.d.ts.map +1 -1
  45. package/lib/typescript/src/hooks/product/useSearchProduct.d.ts +6 -0
  46. package/lib/typescript/src/hooks/product/useSearchProduct.d.ts.map +1 -0
  47. package/lib/typescript/src/hooks/upload/useFileUpload.d.ts.map +1 -1
  48. package/lib/typescript/src/services/endpoints.d.ts +3 -0
  49. package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
  50. package/lib/typescript/src/store/products.d.ts +4 -0
  51. package/lib/typescript/src/store/products.d.ts.map +1 -0
  52. package/lib/typescript/src/types/chat.d.ts +15 -1
  53. package/lib/typescript/src/types/chat.d.ts.map +1 -1
  54. package/lib/typescript/src/types/common.d.ts +17 -0
  55. package/lib/typescript/src/types/common.d.ts.map +1 -1
  56. package/lib/typescript/src/types/dto.d.ts +67 -0
  57. package/lib/typescript/src/types/dto.d.ts.map +1 -1
  58. package/lib/typescript/src/utils/device.d.ts.map +1 -1
  59. package/lib/typescript/src/utils/prototype.d.ts +34 -0
  60. package/lib/typescript/src/utils/prototype.d.ts.map +1 -0
  61. package/package.json +7 -5
  62. package/src/components/chat/footer/index.tsx +3 -3
  63. package/src/components/chat/item/ChatAIAnswerMessageItem.tsx +264 -49
  64. package/src/components/chat/item/ChatTable.tsx +116 -0
  65. package/src/components/chat/item/DeeplinkItem.tsx +74 -0
  66. package/src/components/product/CardHorizontal.tsx +390 -0
  67. package/src/constants/query.ts +1 -0
  68. package/src/context/ChatContext.tsx +27 -2
  69. package/src/hooks/message/useStreamMessage.ts +0 -1
  70. package/src/hooks/product/useSearchProduct.ts +29 -0
  71. package/src/hooks/upload/useFileUpload.ts +0 -4
  72. package/src/services/endpoints.ts +3 -0
  73. package/src/store/products.ts +9 -0
  74. package/src/store/session.ts +1 -1
  75. package/src/types/chat.ts +16 -1
  76. package/src/types/common.ts +20 -0
  77. package/src/types/dto.ts +74 -0
  78. package/src/utils/device.ts +0 -1
  79. package/src/utils/prototype.ts +185 -0
@@ -0,0 +1,185 @@
1
+ class Prototype {
2
+ private static _instance: Prototype | null = null;
3
+
4
+ public static get instance() {
5
+ if (!Prototype._instance) {
6
+ Prototype._instance = new Prototype();
7
+ }
8
+
9
+ return Prototype._instance;
10
+ }
11
+
12
+ private constructor() {}
13
+
14
+ number = {
15
+ isNumeric: (n: any) => {
16
+ return !isNaN(parseFloat(n)) && isFinite(n);
17
+ },
18
+ isInteger: (i: any) => {
19
+ return this.number.isNumeric(i) && i % 1 === 0;
20
+ },
21
+ random: (min: number, max: number) =>
22
+ Math.floor(Math.random() * (max - min + 1) + min),
23
+ formatCurrency: (
24
+ value: string | number = 0,
25
+ options?: {
26
+ ignoreUnit?: boolean;
27
+ locale?: string;
28
+ comma?: string;
29
+ revert?: boolean;
30
+ unit?: string;
31
+ withSign?: boolean;
32
+ postfix?: string;
33
+ fixed?: number;
34
+ }
35
+ ) => {
36
+ const mValue =
37
+ typeof value === 'string' ? parseInt(value, 10) : value || 0;
38
+ const {
39
+ comma = ',',
40
+ ignoreUnit = false,
41
+ revert = false,
42
+ unit = '₫',
43
+ withSign = false,
44
+ postfix = '',
45
+ fixed = 0,
46
+ } = options || {};
47
+ const pattern = ignoreUnit ? '' : `${unit}`;
48
+ let withComma: string | number = Math.abs(mValue);
49
+ if (fixed >= 0) {
50
+ withComma = withComma.toFixed(fixed).replace('.', comma);
51
+ } else {
52
+ withComma = withComma.toString();
53
+ }
54
+ withComma = withComma?.replace?.(/\B(?=(\d{3})+(?!\d))/g, comma);
55
+ const sign = mValue === 0 ? '' : mValue < 0 ? '-' : withSign ? '+' : '';
56
+ const result = revert
57
+ ? `${withComma}${pattern}`
58
+ : `${pattern}${withComma}`;
59
+ return `${sign}${result}${postfix}`;
60
+ },
61
+ formatShortenedCurrency: (
62
+ amount: number | undefined,
63
+ isFullUnit = false,
64
+ fixed?: number
65
+ ) => {
66
+ if (!amount) {
67
+ return '0';
68
+ }
69
+ if (amount < 1e6) {
70
+ return this.number.formatCurrency(amount);
71
+ } else {
72
+ const billion = Math.floor((1e1 * amount) / 1e9) / 10;
73
+ const millionAmount = amount % 1e9;
74
+ const million = Math.round((1e2 * millionAmount) / 1e6) / 100;
75
+ return billion && billion >= 1
76
+ ? this.number.formatCurrency(billion, {
77
+ unit: ' ' + (!isFullUnit ? 'tỷ' : 'tỷ đồng'),
78
+ revert: true,
79
+ fixed,
80
+ })
81
+ : million
82
+ ? this.number.formatCurrency(million, {
83
+ unit: ' ' + (!isFullUnit ? 'triệu' : 'triệu đồng'),
84
+ revert: true,
85
+ fixed,
86
+ })
87
+ : '';
88
+ }
89
+ },
90
+ numberWithCommas(x: number | string = '', placeholder = '0') {
91
+ if (x === null || x === undefined) {
92
+ return placeholder;
93
+ }
94
+ const result = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
95
+ return result?.length > 0 ? result : placeholder;
96
+ },
97
+ clamp(num: number, min: number, max: number) {
98
+ return Math.min(Math.max(num, min), max);
99
+ },
100
+
101
+ stringToNumber(str: string, fallback: number = 0) {
102
+ const converted = str === '' ? fallback : Number(str);
103
+ // Remove all chars that not a number
104
+ const result = Number.isNaN(converted)
105
+ ? str.replace(/\D/g, '')
106
+ : converted;
107
+ const number = result === '' ? fallback : Number(result);
108
+ if (Number.isNaN(number)) {
109
+ return fallback;
110
+ }
111
+ return number;
112
+ },
113
+
114
+ formatShortened(
115
+ value: number | undefined,
116
+ roundingStrategy: 'floor' | 'round' = 'floor',
117
+ options?: {
118
+ ignoreUnit?: boolean;
119
+ unit?: string;
120
+ precisionValue?: number;
121
+ decimalSeparators?: '.' | ',';
122
+ }
123
+ ) {
124
+ const {
125
+ ignoreUnit = true,
126
+ unit = '₫',
127
+ precisionValue = 1,
128
+ decimalSeparators = '.',
129
+ } = options || {};
130
+
131
+ const BILLION = 1e9;
132
+ const MILLION = 1e6;
133
+ const THOUSAND = 1e3;
134
+
135
+ const format = (_value: number, precision = 0) => {
136
+ const multiplier = Math.pow(10, precision || 0);
137
+ const result = (
138
+ Math[roundingStrategy](_value * multiplier) / multiplier
139
+ )
140
+ .toString()
141
+ .replace(/\./g, decimalSeparators);
142
+ return !ignoreUnit ? `${unit}${result}` : result;
143
+ };
144
+
145
+ if (typeof value === 'number') {
146
+ if (value / BILLION >= 1) {
147
+ return `${format(value / BILLION, precisionValue)}B`;
148
+ }
149
+ if (value / MILLION >= 1) {
150
+ return `${format(value / MILLION, precisionValue)}M`;
151
+ }
152
+ if (value / THOUSAND >= 1) {
153
+ return `${format(value / THOUSAND, precisionValue)}K`;
154
+ }
155
+
156
+ return !ignoreUnit ? `${unit}${value}` : `${value}`;
157
+ }
158
+
159
+ return !ignoreUnit ? `${unit}${0}` : '0';
160
+ },
161
+ formatShortenedVN(value: number | undefined) {
162
+ const MILLION = 1e6;
163
+ const THOUSAND = 1e3;
164
+
165
+ if (typeof value === 'number') {
166
+ if (value / MILLION >= 1) {
167
+ return this.formatCurrency(Number((value / MILLION).toFixed(2)), {
168
+ postfix: 'tr',
169
+ fixed: -1,
170
+ });
171
+ }
172
+ if (value / THOUSAND >= 1) {
173
+ return this.formatCurrency(Number((value / THOUSAND).toFixed(1)), {
174
+ postfix: 'K',
175
+ fixed: -1,
176
+ });
177
+ }
178
+ return this.formatCurrency(value);
179
+ }
180
+ return 0;
181
+ },
182
+ };
183
+ }
184
+
185
+ export const PTManager = Prototype.instance;