@fileverse-dev/fortune-react 1.0.39 → 1.0.40

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 (49) hide show
  1. package/es/components/CryptoDenominationSelector/index.css +67 -0
  2. package/es/components/CryptoDenominationSelector/index.d.ts +8 -0
  3. package/es/components/CryptoDenominationSelector/index.js +272 -0
  4. package/es/components/FormatSearch/index.js +9 -5
  5. package/es/components/SVGDefines.js +60 -1
  6. package/es/components/SheetTab/index.js +23 -2
  7. package/es/components/Toolbar/Combo.js +18 -4
  8. package/es/components/Toolbar/index.css +6 -0
  9. package/es/components/Toolbar/index.d.ts +1 -1
  10. package/es/components/Toolbar/index.js +334 -3
  11. package/es/components/Workbook/api.d.ts +2 -0
  12. package/es/components/Workbook/api.js +2 -0
  13. package/es/components/Workbook/index.d.ts +24 -23
  14. package/es/components/Workbook/index.js +36 -1
  15. package/es/constants.d.ts +26 -0
  16. package/es/constants.js +44 -3
  17. package/es/hooks/useCryptoCells.d.ts +1 -0
  18. package/es/hooks/useCryptoCells.js +1 -0
  19. package/es/utils/convertCellsToCrypto.d.ts +8 -0
  20. package/es/utils/convertCellsToCrypto.js +215 -0
  21. package/es/utils/cryptoApi.d.ts +2 -0
  22. package/es/utils/cryptoApi.js +154 -0
  23. package/es/utils/updateCellsDecimalFormat.d.ts +6 -0
  24. package/es/utils/updateCellsDecimalFormat.js +80 -0
  25. package/lib/components/CryptoDenominationSelector/index.css +67 -0
  26. package/lib/components/CryptoDenominationSelector/index.d.ts +8 -0
  27. package/lib/components/CryptoDenominationSelector/index.js +281 -0
  28. package/lib/components/FormatSearch/index.js +9 -5
  29. package/lib/components/SVGDefines.js +60 -1
  30. package/lib/components/SheetTab/index.js +23 -2
  31. package/lib/components/Toolbar/Combo.js +18 -4
  32. package/lib/components/Toolbar/index.css +6 -0
  33. package/lib/components/Toolbar/index.d.ts +1 -1
  34. package/lib/components/Toolbar/index.js +333 -2
  35. package/lib/components/Workbook/api.d.ts +2 -0
  36. package/lib/components/Workbook/api.js +2 -0
  37. package/lib/components/Workbook/index.d.ts +24 -23
  38. package/lib/components/Workbook/index.js +35 -0
  39. package/lib/constants.d.ts +26 -0
  40. package/lib/constants.js +45 -3
  41. package/lib/hooks/useCryptoCells.d.ts +1 -0
  42. package/lib/hooks/useCryptoCells.js +1 -0
  43. package/lib/utils/convertCellsToCrypto.d.ts +8 -0
  44. package/lib/utils/convertCellsToCrypto.js +222 -0
  45. package/lib/utils/cryptoApi.d.ts +2 -0
  46. package/lib/utils/cryptoApi.js +161 -0
  47. package/lib/utils/updateCellsDecimalFormat.d.ts +6 -0
  48. package/lib/utils/updateCellsDecimalFormat.js +86 -0
  49. package/package.json +2 -2
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertCellsToCrypto = convertCellsToCrypto;
7
+ exports.getFiatSymbol = void 0;
8
+ var _fortuneCore = require("@fileverse-dev/fortune-core");
9
+ var _cryptoApi = require("./cryptoApi");
10
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
11
+ function adopt(value) {
12
+ return value instanceof P ? value : new P(function (resolve) {
13
+ resolve(value);
14
+ });
15
+ }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) {
18
+ try {
19
+ step(generator.next(value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+ function rejected(value) {
25
+ try {
26
+ step(generator["throw"](value));
27
+ } catch (e) {
28
+ reject(e);
29
+ }
30
+ }
31
+ function step(result) {
32
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
33
+ }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
38
+ var _ = {
39
+ label: 0,
40
+ sent: function sent() {
41
+ if (t[0] & 1) throw t[1];
42
+ return t[1];
43
+ },
44
+ trys: [],
45
+ ops: []
46
+ },
47
+ f,
48
+ y,
49
+ t,
50
+ g;
51
+ return g = {
52
+ next: verb(0),
53
+ "throw": verb(1),
54
+ "return": verb(2)
55
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
56
+ return this;
57
+ }), g;
58
+ function verb(n) {
59
+ return function (v) {
60
+ return step([n, v]);
61
+ };
62
+ }
63
+ function step(op) {
64
+ if (f) throw new TypeError("Generator is already executing.");
65
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
66
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
67
+ if (y = 0, t) op = [op[0] & 2, t.value];
68
+ switch (op[0]) {
69
+ case 0:
70
+ case 1:
71
+ t = op;
72
+ break;
73
+ case 4:
74
+ _.label++;
75
+ return {
76
+ value: op[1],
77
+ done: false
78
+ };
79
+ case 5:
80
+ _.label++;
81
+ y = op[1];
82
+ op = [0];
83
+ continue;
84
+ case 7:
85
+ op = _.ops.pop();
86
+ _.trys.pop();
87
+ continue;
88
+ default:
89
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
90
+ _ = 0;
91
+ continue;
92
+ }
93
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
94
+ _.label = op[1];
95
+ break;
96
+ }
97
+ if (op[0] === 6 && _.label < t[1]) {
98
+ _.label = t[1];
99
+ t = op;
100
+ break;
101
+ }
102
+ if (t && _.label < t[2]) {
103
+ _.label = t[2];
104
+ _.ops.push(op);
105
+ break;
106
+ }
107
+ if (t[2]) _.ops.pop();
108
+ _.trys.pop();
109
+ continue;
110
+ }
111
+ op = body.call(thisArg, _);
112
+ } catch (e) {
113
+ op = [6, e];
114
+ y = 0;
115
+ } finally {
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ var getFiatSymbol = exports.getFiatSymbol = function getFiatSymbol(code) {
126
+ switch (code) {
127
+ case "USD":
128
+ return "$";
129
+ case "EUR":
130
+ return "€";
131
+ case "GBP":
132
+ return "£";
133
+ case "JPY":
134
+ return "¥";
135
+ case "CNY":
136
+ return "¥";
137
+ case "INR":
138
+ return "₹";
139
+ default:
140
+ return code;
141
+ }
142
+ };
143
+ var COINGECKO_IDS = {
144
+ BTC: "bitcoin",
145
+ ETH: "ethereum",
146
+ SOL: "solana"
147
+ };
148
+ function convertCellsToCrypto(_a) {
149
+ var context = _a.context,
150
+ setContext = _a.setContext,
151
+ denomination = _a.denomination,
152
+ decimals = _a.decimals,
153
+ baseCurrency = _a.baseCurrency;
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var selections, flowdata, selectedCells, denomStr, coingeckoId, price;
156
+ return __generator(this, function (_b) {
157
+ switch (_b.label) {
158
+ case 0:
159
+ selections = context.luckysheet_select_save;
160
+ flowdata = (0, _fortuneCore.getFlowdata)(context);
161
+ if (!selections || !flowdata) return [2];
162
+ selectedCells = [];
163
+ selections.forEach(function (selection) {
164
+ for (var row = selection.row[0]; row <= selection.row[1]; row += 1) {
165
+ for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
166
+ selectedCells.push({
167
+ row: row,
168
+ col: col
169
+ });
170
+ }
171
+ }
172
+ });
173
+ denomStr = typeof denomination === "string" && denomination.trim() !== "" ? denomination : "ETH";
174
+ denomStr = denomStr.toUpperCase();
175
+ coingeckoId = typeof COINGECKO_IDS[denomStr] === "string" ? COINGECKO_IDS[denomStr] : "ethereum";
176
+ return [4, (0, _cryptoApi.getCryptoPrice)(String(coingeckoId), baseCurrency.toLowerCase())];
177
+ case 1:
178
+ price = _b.sent();
179
+ selectedCells.forEach(function (_a) {
180
+ var _b, _c, _d;
181
+ var row = _a.row,
182
+ col = _a.col;
183
+ var cell = (_b = flowdata[row]) === null || _b === void 0 ? void 0 : _b[col];
184
+ var baseValue = 0;
185
+ if ((cell === null || cell === void 0 ? void 0 : cell.baseValue) !== undefined) {
186
+ baseValue = cell.baseValue;
187
+ } else {
188
+ if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "number") {
189
+ baseValue = cell.v;
190
+ } else if (typeof (cell === null || cell === void 0 ? void 0 : cell.v) === "string") {
191
+ baseValue = parseFloat(cell.v);
192
+ }
193
+ if (((_c = cell === null || cell === void 0 ? void 0 : cell.ct) === null || _c === void 0 ? void 0 : _c.fa) && cell.ct.fa.includes('"')) {
194
+ var numericValue = parseFloat(((_d = cell.v) === null || _d === void 0 ? void 0 : _d.toString()) || "0");
195
+ if (!Number.isNaN(numericValue)) {
196
+ baseValue = numericValue;
197
+ }
198
+ }
199
+ }
200
+ if (!baseValue || Number.isNaN(baseValue)) return;
201
+ var cryptoValue = baseValue / price;
202
+ setContext(function (ctx) {
203
+ var d = (0, _fortuneCore.getFlowdata)(ctx);
204
+ if (!d || !Array.isArray(d) || !d[row] || !d[row][col] || cryptoValue === null) return;
205
+ if (!d[row]) d[row] = [];
206
+ if (!d[row][col]) d[row][col] = {};
207
+ var cellCp = d[row][col];
208
+ cellCp.v = baseValue.toString();
209
+ cellCp.m = "".concat(cryptoValue.toFixed(decimals), " ").concat(denomStr);
210
+ cellCp.ct = {
211
+ fa: "0.".concat("0".repeat(decimals), " \"").concat(denomStr, "\""),
212
+ t: "n"
213
+ };
214
+ cellCp.baseValue = baseValue;
215
+ d[row][col] = cellCp;
216
+ });
217
+ });
218
+ return [2];
219
+ }
220
+ });
221
+ });
222
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getCryptoPrice(crypto: string, fiat: string): Promise<number>;
2
+ export declare function clearCryptoPriceCache(): void;
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clearCryptoPriceCache = clearCryptoPriceCache;
7
+ exports.getCryptoPrice = getCryptoPrice;
8
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) {
10
+ return value instanceof P ? value : new P(function (resolve) {
11
+ resolve(value);
12
+ });
13
+ }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) {
16
+ try {
17
+ step(generator.next(value));
18
+ } catch (e) {
19
+ reject(e);
20
+ }
21
+ }
22
+ function rejected(value) {
23
+ try {
24
+ step(generator["throw"](value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ }
29
+ function step(result) {
30
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
31
+ }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
36
+ var _ = {
37
+ label: 0,
38
+ sent: function sent() {
39
+ if (t[0] & 1) throw t[1];
40
+ return t[1];
41
+ },
42
+ trys: [],
43
+ ops: []
44
+ },
45
+ f,
46
+ y,
47
+ t,
48
+ g;
49
+ return g = {
50
+ next: verb(0),
51
+ "throw": verb(1),
52
+ "return": verb(2)
53
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
54
+ return this;
55
+ }), g;
56
+ function verb(n) {
57
+ return function (v) {
58
+ return step([n, v]);
59
+ };
60
+ }
61
+ function step(op) {
62
+ if (f) throw new TypeError("Generator is already executing.");
63
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
64
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
65
+ if (y = 0, t) op = [op[0] & 2, t.value];
66
+ switch (op[0]) {
67
+ case 0:
68
+ case 1:
69
+ t = op;
70
+ break;
71
+ case 4:
72
+ _.label++;
73
+ return {
74
+ value: op[1],
75
+ done: false
76
+ };
77
+ case 5:
78
+ _.label++;
79
+ y = op[1];
80
+ op = [0];
81
+ continue;
82
+ case 7:
83
+ op = _.ops.pop();
84
+ _.trys.pop();
85
+ continue;
86
+ default:
87
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
88
+ _ = 0;
89
+ continue;
90
+ }
91
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
92
+ _.label = op[1];
93
+ break;
94
+ }
95
+ if (op[0] === 6 && _.label < t[1]) {
96
+ _.label = t[1];
97
+ t = op;
98
+ break;
99
+ }
100
+ if (t && _.label < t[2]) {
101
+ _.label = t[2];
102
+ _.ops.push(op);
103
+ break;
104
+ }
105
+ if (t[2]) _.ops.pop();
106
+ _.trys.pop();
107
+ continue;
108
+ }
109
+ op = body.call(thisArg, _);
110
+ } catch (e) {
111
+ op = [6, e];
112
+ y = 0;
113
+ } finally {
114
+ f = t = 0;
115
+ }
116
+ if (op[0] & 5) throw op[1];
117
+ return {
118
+ value: op[0] ? op[1] : void 0,
119
+ done: true
120
+ };
121
+ }
122
+ };
123
+ var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
124
+ var CACHE_DURATION = 60 * 1000;
125
+ var priceCache = {};
126
+ function getCryptoPrice(crypto, fiat) {
127
+ var _a;
128
+ return __awaiter(this, void 0, void 0, function () {
129
+ var key, now, url, resp, data, price;
130
+ return __generator(this, function (_b) {
131
+ switch (_b.label) {
132
+ case 0:
133
+ key = "".concat(crypto, "-").concat(fiat).toLowerCase();
134
+ now = Date.now();
135
+ if (priceCache[key] && now - priceCache[key].timestamp < CACHE_DURATION) {
136
+ return [2, priceCache[key].price];
137
+ }
138
+ url = "".concat(COINGECKO_API, "?ids=").concat(crypto, "&vs_currencies=").concat(fiat);
139
+ return [4, fetch(url)];
140
+ case 1:
141
+ resp = _b.sent();
142
+ if (!resp.ok) throw new Error("Failed to fetch crypto price");
143
+ return [4, resp.json()];
144
+ case 2:
145
+ data = _b.sent();
146
+ price = (_a = data[crypto]) === null || _a === void 0 ? void 0 : _a[fiat];
147
+ if (typeof price !== "number") throw new Error("Invalid price data");
148
+ priceCache[key] = {
149
+ price: price,
150
+ timestamp: now
151
+ };
152
+ return [2, price];
153
+ }
154
+ });
155
+ });
156
+ }
157
+ function clearCryptoPriceCache() {
158
+ Object.keys(priceCache).forEach(function (key) {
159
+ return delete priceCache[key];
160
+ });
161
+ }
@@ -0,0 +1,6 @@
1
+ export declare function updateCellsDecimalFormat({ context, setContext, decimals, denomination, }: {
2
+ context: any;
3
+ setContext: (fn: (ctx: any) => void) => void;
4
+ decimals: number;
5
+ denomination?: string;
6
+ }): void;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateCellsDecimalFormat = updateCellsDecimalFormat;
7
+ var _fortuneCore = require("@fileverse-dev/fortune-core");
8
+ var _constants = require("../constants");
9
+ function getFiatSymbol(code) {
10
+ switch (code) {
11
+ case "USD":
12
+ return "$";
13
+ case "EUR":
14
+ return "€";
15
+ case "GBP":
16
+ return "£";
17
+ case "JPY":
18
+ return "¥";
19
+ case "CNY":
20
+ return "¥";
21
+ case "INR":
22
+ return "₹";
23
+ default:
24
+ return code;
25
+ }
26
+ }
27
+ function updateCellsDecimalFormat(_a) {
28
+ var context = _a.context,
29
+ setContext = _a.setContext,
30
+ decimals = _a.decimals,
31
+ denomination = _a.denomination;
32
+ var selections = context.luckysheet_select_save;
33
+ var flowdata = (0, _fortuneCore.getFlowdata)(context);
34
+ if (!selections || !flowdata) return;
35
+ var selectedCells = [];
36
+ selections.forEach(function (selection) {
37
+ for (var row = selection.row[0]; row <= selection.row[1]; row += 1) {
38
+ for (var col = selection.column[0]; col <= selection.column[1]; col += 1) {
39
+ selectedCells.push({
40
+ row: row,
41
+ col: col
42
+ });
43
+ }
44
+ }
45
+ });
46
+ setContext(function (ctx) {
47
+ var d = (0, _fortuneCore.getFlowdata)(ctx);
48
+ if (!d) return;
49
+ selectedCells.forEach(function (_a) {
50
+ var _b;
51
+ var row = _a.row,
52
+ col = _a.col;
53
+ var cell = (_b = d[row]) === null || _b === void 0 ? void 0 : _b[col];
54
+ if (!cell) return;
55
+ var denomStr = "ETH";
56
+ var isCrypto = false;
57
+ if (cell.ct && typeof cell.ct.fa === "string") {
58
+ var _c = cell.ct.fa.match(/"([A-Z]+)"/) || [],
59
+ matchedDenom = _c[1];
60
+ if (matchedDenom) {
61
+ denomStr = matchedDenom;
62
+ isCrypto = true;
63
+ }
64
+ }
65
+ if (isCrypto) {
66
+ cell.ct = {
67
+ fa: "0.".concat("0".repeat(decimals), " \"").concat(denomStr, "\""),
68
+ t: "n"
69
+ };
70
+ if (typeof cell.v === "number") {
71
+ cell.m = "".concat(cell.v.toFixed(decimals), " ").concat(denomStr);
72
+ }
73
+ } else {
74
+ var fiat = denomination || "USD";
75
+ var symbol = fiat in _constants.FIAT_ICON_MAP ? getFiatSymbol(fiat) : fiat;
76
+ cell.ct = {
77
+ fa: "".concat(symbol, " #,##0.").concat("0".repeat(decimals)),
78
+ t: "n"
79
+ };
80
+ if (typeof cell.v === "number") {
81
+ cell.m = "".concat(symbol, " ").concat(cell.v.toFixed(decimals));
82
+ }
83
+ }
84
+ });
85
+ });
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "es/index.js",
@@ -16,7 +16,7 @@
16
16
  "tsc": "tsc"
17
17
  },
18
18
  "dependencies": {
19
- "@fileverse-dev/fortune-core": "1.0.39",
19
+ "@fileverse-dev/fortune-core": "1.0.40",
20
20
  "@fileverse/ui": "^4.1.7-patch-16",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",