@fileverse-dev/fortune-react 1.0.98 → 1.0.100

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,4 +1,4 @@
1
- import { locale, searchAll, searchNext, normalizeSelection, onSearchDialogMoveStart, replace, replaceAll, scrollToHighlightCell } from "@fileverse-dev/fortune-core";
1
+ import { locale, searchAll, searchNext, normalizeSelection, replace, replaceAll, scrollToHighlightCell } from "@fileverse-dev/fortune-core";
2
2
  import { Button, Checkbox, cn, Divider, IconButton, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, TextField } from "@fileverse/ui";
3
3
  import produce from "immer";
4
4
  import React, { useContext, useState, useCallback, useRef } from "react";
@@ -6,36 +6,35 @@ import _ from "lodash";
6
6
  import WorkbookContext from "../../context";
7
7
  import { useAlert } from "../../hooks/useAlert";
8
8
  import "./index.css";
9
- var SearchReplace = function SearchReplace(_a) {
10
- var getContainer = _a.getContainer;
11
- var _b = useContext(WorkbookContext),
12
- context = _b.context,
13
- setContext = _b.setContext,
14
- refs = _b.refs;
9
+ var SearchReplace = function SearchReplace() {
10
+ var _a = useContext(WorkbookContext),
11
+ context = _a.context,
12
+ setContext = _a.setContext,
13
+ refs = _a.refs;
15
14
  var findAndReplace = locale(context).findAndReplace;
15
+ var _b = useState(""),
16
+ searchText = _b[0],
17
+ setSearchText = _b[1];
16
18
  var _c = useState(""),
17
- searchText = _c[0],
18
- setSearchText = _c[1];
19
- var _d = useState(""),
20
- replaceText = _d[0],
21
- setReplaceText = _d[1];
22
- var _e = useState([]),
23
- searchResult = _e[0],
24
- setSearchResult = _e[1];
25
- var _f = useState(),
26
- selectedCell = _f[0],
27
- setSelectedCell = _f[1];
19
+ replaceText = _c[0],
20
+ setReplaceText = _c[1];
21
+ var _d = useState([]),
22
+ searchResult = _d[0],
23
+ setSearchResult = _d[1];
24
+ var _e = useState(),
25
+ selectedCell = _e[0],
26
+ setSelectedCell = _e[1];
28
27
  var showAlert = useAlert().showAlert;
29
28
  var tableContainerRef = useRef(null);
30
29
  var searchInputRef = useRef(null);
31
30
  var replaceInputRef = useRef(null);
32
- var _g = useState({
31
+ var _f = useState({
33
32
  regCheck: false,
34
33
  wordCheck: false,
35
34
  caseCheck: false
36
35
  }),
37
- checkMode = _g[0],
38
- checkModeReplace = _g[1];
36
+ checkMode = _f[0],
37
+ checkModeReplace = _f[1];
39
38
  var closeDialog = useCallback(function () {
40
39
  _.set(refs.globalCache, "searchDialog.mouseEnter", false);
41
40
  setContext(function (draftCtx) {
@@ -48,27 +47,19 @@ var SearchReplace = function SearchReplace(_a) {
48
47
  _.set(draft, mode, value);
49
48
  }));
50
49
  }, []);
51
- var getInitialPosition = useCallback(function (container) {
52
- var rect = container.getBoundingClientRect();
53
- return {
54
- left: (rect.width - 500) / 2,
55
- top: (rect.height - 200) / 3
56
- };
57
- }, []);
58
50
  return /*#__PURE__*/React.createElement("div", {
59
51
  id: "fortune-search-replace",
60
52
  className: "fortune-search-replace fortune-dialog",
61
- style: getInitialPosition(getContainer()),
53
+ style: {
54
+ top: "50%",
55
+ left: "50%",
56
+ transform: "translate(-50%, -50%)"
57
+ },
62
58
  onMouseEnter: function onMouseEnter() {
63
59
  _.set(refs.globalCache, "searchDialog.mouseEnter", true);
64
60
  },
65
61
  onMouseLeave: function onMouseLeave() {
66
62
  _.set(refs.globalCache, "searchDialog.mouseEnter", false);
67
- },
68
- onMouseDown: function onMouseDown(e) {
69
- var nativeEvent = e.nativeEvent;
70
- onSearchDialogMoveStart(refs.globalCache, nativeEvent, getContainer());
71
- e.stopPropagation();
72
63
  }
73
64
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
74
65
  className: "flex items-center justify-between border-b color-border-default py-3 px-6"
@@ -144,11 +144,12 @@ var Sheet = function Sheet(_a) {
144
144
  }
145
145
  }, [context, refs.canvas, refs.globalCache.freezen, setContext, sheet.id]);
146
146
  var onWheel = useCallback(function (e) {
147
+ var _a, _b;
147
148
  var functionDetailsEl = document.getElementById("function-details");
148
149
  var formulaSearchEl = document.getElementById("luckysheet-formula-search-c");
149
150
  var isMouseOverFunctionDetails = functionDetailsEl === null || functionDetailsEl === void 0 ? void 0 : functionDetailsEl.matches(":hover");
150
151
  var isMouseOverFormulaSearch = formulaSearchEl === null || formulaSearchEl === void 0 ? void 0 : formulaSearchEl.matches(":hover");
151
- if (functionDetailsEl && isMouseOverFunctionDetails || formulaSearchEl && isMouseOverFormulaSearch) return;
152
+ if (functionDetailsEl && isMouseOverFunctionDetails || formulaSearchEl && isMouseOverFormulaSearch || ((_b = (_a = refs === null || refs === void 0 ? void 0 : refs.globalCache) === null || _a === void 0 ? void 0 : _a.searchDialog) === null || _b === void 0 ? void 0 : _b.mouseEnter)) return;
152
153
  setContext(function (draftCtx) {
153
154
  handleGlobalWheel(draftCtx, e, refs.globalCache, refs.scrollbarX.current, refs.scrollbarY.current);
154
155
  });
@@ -7,6 +7,7 @@ type Props = {
7
7
  onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
8
8
  children: (setOpen: React.Dispatch<React.SetStateAction<boolean>>) => React.ReactNode;
9
9
  fillColor?: string;
10
+ triggerRef?: React.RefObject<HTMLButtonElement | null>;
10
11
  };
11
12
  declare const Combo: React.FC<Props>;
12
13
  export default Combo;
@@ -10,7 +10,8 @@ var Combo = function Combo(_a) {
10
10
  _b = _a.showArrow,
11
11
  showArrow = _b === void 0 ? true : _b,
12
12
  children = _a.children,
13
- fillColor = _a.fillColor;
13
+ fillColor = _a.fillColor,
14
+ triggerRef = _a.triggerRef;
14
15
  var style = {
15
16
  userSelect: "none"
16
17
  };
@@ -18,6 +19,10 @@ var Combo = function Combo(_a) {
18
19
  open = _c[0],
19
20
  setOpen = _c[1];
20
21
  var buttonRef = useRef(null);
22
+ var ref = useRef(null);
23
+ if (!triggerRef) {
24
+ triggerRef = ref;
25
+ }
21
26
  var handleOpenChange = function handleOpenChange(newOpen) {
22
27
  setOpen(newOpen);
23
28
  };
@@ -73,7 +78,7 @@ var Combo = function Combo(_a) {
73
78
  icon: getLucideIcon(iconId),
74
79
  variant: "ghost",
75
80
  onClick: function onClick() {
76
- return setOpen(!open);
81
+ setOpen(!open);
77
82
  },
78
83
  className: cn("fortune-toolbar-combo-button", {
79
84
  "custom-color-button": iconId === "font-color" && fillColor,
@@ -94,6 +99,7 @@ var Combo = function Combo(_a) {
94
99
  onOpenChange: handleOpenChange,
95
100
  modal: true
96
101
  }, /*#__PURE__*/React.createElement(PopoverTrigger, {
102
+ ref: triggerRef,
97
103
  asChild: true
98
104
  }, /*#__PURE__*/React.createElement("div", {
99
105
  className: "flex items-center"
@@ -1,6 +1,12 @@
1
1
  import React from "react";
2
+ import { Cell } from "@fileverse-dev/fortune-core";
2
3
  import "./index.css";
3
4
  export declare const getLucideIcon: (title: string) => "Ethereum" | "DollarSign" | "" | "ChevronDown" | "Undo" | "Redo" | "PaintRoller" | "Bold" | "Italic" | "Strikethrough" | "Underline" | "AlignLeft" | "AlignCenter" | "AlignRight" | "ArrowUpFromLine" | "AlignVerticalMiddle" | "ArrowDownToLine" | "TextOverflow" | "WrapText" | "TextClip" | "Baseline" | "PaintBucket" | "Border" | "MergeHorizontal" | "Percent" | "DecimalsArrowLeft" | "DecimalsArrowRight" | "PaintbrushVertical" | "Filter" | "Link" | "MessageSquarePlus" | "Image" | "Sigma" | "ShieldCheck" | "Search" | "DuneChart" | "Ellipsis";
5
+ export declare const CurrencySelector: ({ cell, defaultTextFormat, toolTipText, }: {
6
+ cell: Cell | null | undefined;
7
+ defaultTextFormat: string;
8
+ toolTipText: string;
9
+ }) => React.JSX.Element;
4
10
  declare const Toolbar: React.FC<{
5
11
  setMoreItems: React.Dispatch<React.SetStateAction<React.ReactNode>>;
6
12
  moreItemsOpen: boolean;
@@ -227,6 +227,226 @@ export var getLucideIcon = function getLucideIcon(title) {
227
227
  return "";
228
228
  }
229
229
  };
230
+ export var CurrencySelector = function CurrencySelector(_a) {
231
+ var cell = _a.cell,
232
+ defaultTextFormat = _a.defaultTextFormat,
233
+ toolTipText = _a.toolTipText;
234
+ var _b = useContext(WorkbookContext),
235
+ context = _b.context,
236
+ setContext = _b.setContext,
237
+ refs = _b.refs;
238
+ var _c = useState(""),
239
+ searchTerm = _c[0],
240
+ setSearchTerm = _c[1];
241
+ var _d = useState(2),
242
+ decimals = _d[0],
243
+ setDecimals = _d[1];
244
+ var _e = useState("USD"),
245
+ selectedFiat = _e[0],
246
+ setSelectedFiat = _e[1];
247
+ var currentFmt = defaultTextFormat;
248
+ var currentIcon = "currency";
249
+ if (cell) {
250
+ var curr_1 = normalizedCellAttr(cell, "ct");
251
+ if (curr_1 === null || curr_1 === void 0 ? void 0 : curr_1.fa) {
252
+ var allOptions = __spreadArray(__spreadArray([], CRYPTO_OPTIONS, true), locale(context).currencyDetail.map(function (c) {
253
+ return {
254
+ label: c.name,
255
+ value: c.value,
256
+ icon: undefined,
257
+ type: "fiat"
258
+ };
259
+ }), true);
260
+ var found = __spreadArray([], allOptions, true).sort(function (a, b) {
261
+ return b.value.length - a.value.length;
262
+ }).find(function (o) {
263
+ return curr_1.fa.includes(o.value);
264
+ });
265
+ if (found) {
266
+ currentFmt = found.label;
267
+ }
268
+ }
269
+ }
270
+ var groupedOptions = getGroupedCurrencyOptions(locale(context).currencyDetail);
271
+ var filterOptions = function filterOptions(options) {
272
+ if (!searchTerm.trim()) return options;
273
+ var query = searchTerm.trim().toLowerCase();
274
+ return options.filter(function (opt) {
275
+ return query.split(/\s+/).every(function (word) {
276
+ return opt.label.toLowerCase().includes(word) || opt.value.toLowerCase().includes(word);
277
+ });
278
+ });
279
+ };
280
+ var dedupeByValue = function dedupeByValue(options) {
281
+ var seen = new Set();
282
+ return options.filter(function (opt) {
283
+ if (seen.has(opt.value)) return false;
284
+ seen.add(opt.value);
285
+ return true;
286
+ });
287
+ };
288
+ var handleCurrencyDecimalsChange = function handleCurrencyDecimalsChange(newDecimals) {
289
+ setDecimals(newDecimals);
290
+ var isCrypto = false;
291
+ if (cell && cell.ct && typeof cell.ct.fa === "string") {
292
+ var _a = cell.ct.fa.match(/"([A-Z]+)"/) || [],
293
+ matchedDenom = _a[1];
294
+ if (matchedDenom) isCrypto = true;
295
+ }
296
+ updateCellsDecimalFormat({
297
+ context: context,
298
+ setContext: setContext,
299
+ decimals: newDecimals,
300
+ denomination: isCrypto ? undefined : selectedFiat
301
+ });
302
+ };
303
+ var triggerRef = useRef(null);
304
+ return /*#__PURE__*/React.createElement("div", {
305
+ style: {
306
+ padding: "0px"
307
+ },
308
+ className: "items-center fortune-toolbar-button"
309
+ }, /*#__PURE__*/React.createElement(Tooltip, {
310
+ text: toolTipText,
311
+ placement: "bottom"
312
+ }, /*#__PURE__*/React.createElement("div", {
313
+ className: "",
314
+ onClick: function onClick() {
315
+ var _a;
316
+ (_a = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current) === null || _a === void 0 ? void 0 : _a.click();
317
+ },
318
+ tabIndex: 0,
319
+ role: "button"
320
+ }, /*#__PURE__*/React.createElement(LucideIcon, {
321
+ name: getLucideIcon("currency-format"),
322
+ width: 16,
323
+ height: 16
324
+ }))), /*#__PURE__*/React.createElement(Combo, {
325
+ iconId: currentIcon,
326
+ text: currentFmt,
327
+ key: "currency",
328
+ tooltip: "",
329
+ showArrow: true,
330
+ triggerRef: triggerRef
331
+ }, function (setOpen) {
332
+ return /*#__PURE__*/React.createElement("div", {
333
+ style: {
334
+ minWidth: "20rem",
335
+ boxShadow: "2px 2px 10px rgba(0, 0, 0, 0.2)",
336
+ borderRadius: "8px"
337
+ }
338
+ }, /*#__PURE__*/React.createElement(Command, {
339
+ className: "border color-border-default rounded-lg"
340
+ }, /*#__PURE__*/React.createElement("div", {
341
+ id: "search-input-container"
342
+ }, /*#__PURE__*/React.createElement(CommandInput, {
343
+ placeholder: "Search by name or code",
344
+ value: searchTerm,
345
+ onValueChange: setSearchTerm
346
+ })), /*#__PURE__*/React.createElement("div", {
347
+ className: "px-4 py-2 border-b color-border-default flex items-center justify-between gap-2 text-body-sm color-text-default",
348
+ onClick: function onClick(e) {
349
+ return e.stopPropagation();
350
+ }
351
+ }, /*#__PURE__*/React.createElement("span", null, "Decimal places:"), /*#__PURE__*/React.createElement("span", {
352
+ className: "cds-row flex items-center"
353
+ }, /*#__PURE__*/React.createElement(IconButton, {
354
+ icon: "Minus",
355
+ variant: "ghost",
356
+ size: "sm",
357
+ className: "",
358
+ disabled: decimals === 1,
359
+ onClick: function onClick() {
360
+ return handleCurrencyDecimalsChange(Math.max(1, decimals - 1));
361
+ }
362
+ }), /*#__PURE__*/React.createElement("input", {
363
+ type: "number",
364
+ min: 1,
365
+ max: 18,
366
+ value: decimals,
367
+ onChange: function onChange(e) {
368
+ return handleCurrencyDecimalsChange(Math.max(1, Math.min(18, Number(e.target.value))));
369
+ }
370
+ }), /*#__PURE__*/React.createElement(IconButton, {
371
+ icon: "Plus",
372
+ variant: "ghost",
373
+ size: "sm",
374
+ disabled: decimals === 18,
375
+ onClick: function onClick() {
376
+ return handleCurrencyDecimalsChange(Math.min(18, decimals + 1));
377
+ }
378
+ }))), /*#__PURE__*/React.createElement(CommandList, null, /*#__PURE__*/React.createElement(CommandEmpty, {
379
+ className: "text-center text-body-sm color-text-secondary flex items-center justify-center",
380
+ style: {
381
+ minHeight: "5rem"
382
+ }
383
+ }, "No results found."), groupedOptions.map(function (group) {
384
+ var filtered = dedupeByValue(filterOptions(group.options));
385
+ return /*#__PURE__*/React.createElement(CommandGroup, {
386
+ key: group.group,
387
+ heading: group.group
388
+ }, filtered.map(function (opt) {
389
+ return /*#__PURE__*/React.createElement(CommandItem, {
390
+ key: opt.value,
391
+ value: "".concat(opt.label, " ").concat(opt.value),
392
+ onSelect: function onSelect() {
393
+ return __awaiter(void 0, void 0, void 0, function () {
394
+ return __generator(this, function (_a) {
395
+ switch (_a.label) {
396
+ case 0:
397
+ if (!(opt.type === "crypto")) return [3, 2];
398
+ return [4, convertCellsToCrypto({
399
+ context: context,
400
+ setContext: setContext,
401
+ denomination: opt.value,
402
+ decimals: decimals
403
+ })];
404
+ case 1:
405
+ _a.sent();
406
+ return [3, 3];
407
+ case 2:
408
+ setSelectedFiat(opt.value);
409
+ setContext(function (ctx) {
410
+ var d = getFlowdata(ctx);
411
+ if (d == null) return;
412
+ var formatString = "".concat(getFiatSymbol(opt.value), " #,##0.").concat("0".repeat(decimals));
413
+ updateFormat(ctx, refs.cellInput.current, d, "ct", formatString);
414
+ });
415
+ _a.label = 3;
416
+ case 3:
417
+ setOpen(false);
418
+ return [2];
419
+ }
420
+ });
421
+ });
422
+ }
423
+ }, /*#__PURE__*/React.createElement("div", {
424
+ className: "fortune-toolbar-menu-line flex items-center justify-between w-full"
425
+ }, /*#__PURE__*/React.createElement("div", {
426
+ className: "flex items-center gap-2 w-[250px]"
427
+ }, currentFmt === opt.label ? (/*#__PURE__*/React.createElement(LucideIcon, {
428
+ name: "Check",
429
+ className: "w-4 h-4"
430
+ })) : (/*#__PURE__*/React.createElement("span", {
431
+ className: "w-4 h-4"
432
+ })), /*#__PURE__*/React.createElement("span", {
433
+ className: "truncate flex-1 overflow-hidden whitespace-nowrap"
434
+ }, opt.label)), opt.type === "crypto" ? (/*#__PURE__*/React.createElement("span", {
435
+ className: "color-text-secondary"
436
+ }, /*#__PURE__*/React.createElement(LucideIcon, {
437
+ name: opt.icon,
438
+ className: "cds-icon"
439
+ }), opt.value === "SOL" && (/*#__PURE__*/React.createElement(SVGIcon, {
440
+ name: "solana",
441
+ width: 16,
442
+ height: 16
443
+ })))) : (/*#__PURE__*/React.createElement("span", {
444
+ className: "color-text-secondary"
445
+ }, opt.value))));
446
+ }));
447
+ }))));
448
+ }));
449
+ };
230
450
  var Toolbar = function Toolbar(_a) {
231
451
  var _b, _c, _d;
232
452
  var setMoreItems = _a.setMoreItems,
@@ -286,15 +506,6 @@ var Toolbar = function Toolbar(_a) {
286
506
  var defaultFormat = defaultFmt(currency);
287
507
  var customColor = useState("#000000")[0];
288
508
  var customStyle = useState("1")[0];
289
- var _m = useState(""),
290
- searchTerm = _m[0],
291
- setSearchTerm = _m[1];
292
- var _o = useState(2),
293
- decimals = _o[0],
294
- setDecimals = _o[1];
295
- var _p = useState("USD"),
296
- selectedFiat = _p[0],
297
- setSelectedFiat = _p[1];
298
509
  var showSubMenu = useCallback(function (e, className) {
299
510
  var target = e.target;
300
511
  var menuItem = target.className === "fortune-toolbar-menu-line" ? target.parentElement : target;
@@ -429,11 +640,11 @@ var Toolbar = function Toolbar(_a) {
429
640
  if (name === "format") {
430
641
  var currentFmt = defaultFormat[0].text;
431
642
  if (cell) {
432
- var curr_1 = normalizedCellAttr(cell, "ct");
643
+ var curr_2 = normalizedCellAttr(cell, "ct");
433
644
  var format = _.find(defaultFormat, function (v) {
434
- return v.value === (curr_1 === null || curr_1 === void 0 ? void 0 : curr_1.fa);
645
+ return v.value === (curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa);
435
646
  });
436
- if ((curr_1 === null || curr_1 === void 0 ? void 0 : curr_1.fa) != null) {
647
+ if ((curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa) != null) {
437
648
  if (format != null) {
438
649
  currentFmt = format.text;
439
650
  } else {
@@ -1210,12 +1421,12 @@ var Toolbar = function Toolbar(_a) {
1210
1421
  iconId: "text-wrap",
1211
1422
  value: "wrap"
1212
1423
  }];
1213
- var curr_2 = items_7[0];
1424
+ var curr_3 = items_7[0];
1214
1425
  if ((cell === null || cell === void 0 ? void 0 : cell.tb) != null) {
1215
- curr_2 = _.get(items_7, cell.tb);
1426
+ curr_3 = _.get(items_7, cell.tb);
1216
1427
  }
1217
1428
  return /*#__PURE__*/React.createElement(Combo, {
1218
- iconId: curr_2.iconId,
1429
+ iconId: curr_3.iconId,
1219
1430
  key: name,
1220
1431
  tooltip: toolbar.textWrap,
1221
1432
  showArrow: false
@@ -1234,7 +1445,7 @@ var Toolbar = function Toolbar(_a) {
1234
1445
  value = _a.value;
1235
1446
  return /*#__PURE__*/React.createElement(IconButton, {
1236
1447
  key: value,
1237
- isActive: curr_2.value === value,
1448
+ isActive: curr_3.value === value,
1238
1449
  icon: getLucideIcon(iconId),
1239
1450
  variant: "ghost",
1240
1451
  onClick: function onClick() {
@@ -1388,185 +1599,10 @@ var Toolbar = function Toolbar(_a) {
1388
1599
  });
1389
1600
  }
1390
1601
  if (name === "currency") {
1391
- var currentFmt_1 = defaultFormat[0].text;
1392
- var currentIcon = "currency";
1393
- if (cell) {
1394
- var curr_3 = normalizedCellAttr(cell, "ct");
1395
- if (curr_3 === null || curr_3 === void 0 ? void 0 : curr_3.fa) {
1396
- var allOptions = __spreadArray(__spreadArray([], CRYPTO_OPTIONS, true), locale(context).currencyDetail.map(function (c) {
1397
- return {
1398
- label: c.name,
1399
- value: c.value,
1400
- icon: undefined,
1401
- type: "fiat"
1402
- };
1403
- }), true);
1404
- var found = __spreadArray([], allOptions, true).sort(function (a, b) {
1405
- return b.value.length - a.value.length;
1406
- }).find(function (o) {
1407
- return curr_3.fa.includes(o.value);
1408
- });
1409
- if (found) {
1410
- currentFmt_1 = found.label;
1411
- }
1412
- }
1413
- }
1414
- var groupedOptions_1 = getGroupedCurrencyOptions(locale(context).currencyDetail);
1415
- var filterOptions_1 = function filterOptions_1(options) {
1416
- if (!searchTerm.trim()) return options;
1417
- var query = searchTerm.trim().toLowerCase();
1418
- return options.filter(function (opt) {
1419
- return query.split(/\s+/).every(function (word) {
1420
- return opt.label.toLowerCase().includes(word) || opt.value.toLowerCase().includes(word);
1421
- });
1422
- });
1423
- };
1424
- var dedupeByValue_1 = function dedupeByValue_1(options) {
1425
- var seen = new Set();
1426
- return options.filter(function (opt) {
1427
- if (seen.has(opt.value)) return false;
1428
- seen.add(opt.value);
1429
- return true;
1430
- });
1431
- };
1432
- var handleCurrencyDecimalsChange_1 = function handleCurrencyDecimalsChange_1(newDecimals) {
1433
- setDecimals(newDecimals);
1434
- var isCrypto = false;
1435
- if (cell && cell.ct && typeof cell.ct.fa === "string") {
1436
- var _a = cell.ct.fa.match(/"([A-Z]+)"/) || [],
1437
- matchedDenom = _a[1];
1438
- if (matchedDenom) isCrypto = true;
1439
- }
1440
- updateCellsDecimalFormat({
1441
- context: context,
1442
- setContext: setContext,
1443
- decimals: newDecimals,
1444
- denomination: isCrypto ? undefined : selectedFiat
1445
- });
1446
- };
1447
- return /*#__PURE__*/React.createElement(Combo, {
1448
- iconId: currentIcon,
1449
- text: currentFmt_1,
1450
- key: name,
1451
- tooltip: tooltip,
1452
- showArrow: true
1453
- }, function (setOpen) {
1454
- return /*#__PURE__*/React.createElement("div", {
1455
- style: {
1456
- minWidth: "20rem",
1457
- boxShadow: "2px 2px 10px rgba(0, 0, 0, 0.2)",
1458
- borderRadius: "8px"
1459
- }
1460
- }, /*#__PURE__*/React.createElement(Command, {
1461
- className: "border color-border-default rounded-lg"
1462
- }, /*#__PURE__*/React.createElement("div", {
1463
- id: "search-input-container"
1464
- }, /*#__PURE__*/React.createElement(CommandInput, {
1465
- placeholder: "Search by name or code",
1466
- value: searchTerm,
1467
- onValueChange: setSearchTerm
1468
- })), /*#__PURE__*/React.createElement("div", {
1469
- className: "px-4 py-2 border-b color-border-default flex items-center justify-between gap-2 text-body-sm color-text-default",
1470
- onClick: function onClick(e) {
1471
- return e.stopPropagation();
1472
- }
1473
- }, /*#__PURE__*/React.createElement("span", null, "Decimal places:"), /*#__PURE__*/React.createElement("span", {
1474
- className: "cds-row flex items-center"
1475
- }, /*#__PURE__*/React.createElement(IconButton, {
1476
- icon: "Minus",
1477
- variant: "ghost",
1478
- size: "sm",
1479
- className: "",
1480
- disabled: decimals === 1,
1481
- onClick: function onClick() {
1482
- return handleCurrencyDecimalsChange_1(Math.max(1, decimals - 1));
1483
- }
1484
- }), /*#__PURE__*/React.createElement("input", {
1485
- type: "number",
1486
- min: 1,
1487
- max: 18,
1488
- value: decimals,
1489
- onChange: function onChange(e) {
1490
- return handleCurrencyDecimalsChange_1(Math.max(1, Math.min(18, Number(e.target.value))));
1491
- }
1492
- }), /*#__PURE__*/React.createElement(IconButton, {
1493
- icon: "Plus",
1494
- variant: "ghost",
1495
- size: "sm",
1496
- disabled: decimals === 18,
1497
- onClick: function onClick() {
1498
- return handleCurrencyDecimalsChange_1(Math.min(18, decimals + 1));
1499
- }
1500
- }))), /*#__PURE__*/React.createElement(CommandList, null, /*#__PURE__*/React.createElement(CommandEmpty, {
1501
- className: "text-center text-body-sm color-text-secondary flex items-center justify-center",
1502
- style: {
1503
- minHeight: "5rem"
1504
- }
1505
- }, "No results found."), groupedOptions_1.map(function (group) {
1506
- var filtered = dedupeByValue_1(filterOptions_1(group.options));
1507
- return /*#__PURE__*/React.createElement(CommandGroup, {
1508
- key: group.group,
1509
- heading: group.group
1510
- }, filtered.map(function (opt) {
1511
- return /*#__PURE__*/React.createElement(CommandItem, {
1512
- key: opt.value,
1513
- value: "".concat(opt.label, " ").concat(opt.value),
1514
- onSelect: function onSelect() {
1515
- return __awaiter(void 0, void 0, void 0, function () {
1516
- return __generator(this, function (_a) {
1517
- switch (_a.label) {
1518
- case 0:
1519
- if (!(opt.type === "crypto")) return [3, 2];
1520
- return [4, convertCellsToCrypto({
1521
- context: context,
1522
- setContext: setContext,
1523
- denomination: opt.value,
1524
- decimals: decimals
1525
- })];
1526
- case 1:
1527
- _a.sent();
1528
- return [3, 3];
1529
- case 2:
1530
- setSelectedFiat(opt.value);
1531
- setContext(function (ctx) {
1532
- var d = getFlowdata(ctx);
1533
- if (d == null) return;
1534
- var formatString = "".concat(getFiatSymbol(opt.value), " #,##0.").concat("0".repeat(decimals));
1535
- updateFormat(ctx, refs.cellInput.current, d, "ct", formatString);
1536
- });
1537
- _a.label = 3;
1538
- case 3:
1539
- setOpen(false);
1540
- return [2];
1541
- }
1542
- });
1543
- });
1544
- }
1545
- }, /*#__PURE__*/React.createElement("div", {
1546
- className: "fortune-toolbar-menu-line flex items-center justify-between w-full"
1547
- }, /*#__PURE__*/React.createElement("div", {
1548
- className: "flex items-center gap-2 w-[250px]"
1549
- }, currentFmt_1 === opt.label ? (/*#__PURE__*/React.createElement(LucideIcon, {
1550
- name: "Check",
1551
- className: "w-4 h-4"
1552
- })) : (/*#__PURE__*/React.createElement("span", {
1553
- className: "w-4 h-4"
1554
- })), /*#__PURE__*/React.createElement("span", {
1555
- className: "truncate flex-1 overflow-hidden whitespace-nowrap"
1556
- }, opt.label)), opt.type === "crypto" ? (/*#__PURE__*/React.createElement("span", {
1557
- className: "color-text-secondary"
1558
- }, /*#__PURE__*/React.createElement(LucideIcon, {
1559
- name: opt.icon,
1560
- className: "cds-icon"
1561
- }), opt.value === "SOL" && (/*#__PURE__*/React.createElement(SVGIcon, {
1562
- name: "solana",
1563
- width: 16,
1564
- height: 16
1565
- })))) : (/*#__PURE__*/React.createElement("span", {
1566
- className: "color-text-secondary"
1567
- }, opt.value))));
1568
- }));
1569
- }))));
1602
+ return /*#__PURE__*/React.createElement(CurrencySelector, {
1603
+ cell: cell,
1604
+ defaultTextFormat: defaultFormat[0].text,
1605
+ toolTipText: toolbar["currency-format"]
1570
1606
  });
1571
1607
  }
1572
1608
  return /*#__PURE__*/React.createElement(Tooltip, {
@@ -15,36 +15,35 @@ var _useAlert = require("../../hooks/useAlert");
15
15
  require("./index.css");
16
16
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
- var SearchReplace = function SearchReplace(_a) {
19
- var getContainer = _a.getContainer;
20
- var _b = (0, _react.useContext)(_context.default),
21
- context = _b.context,
22
- setContext = _b.setContext,
23
- refs = _b.refs;
18
+ var SearchReplace = function SearchReplace() {
19
+ var _a = (0, _react.useContext)(_context.default),
20
+ context = _a.context,
21
+ setContext = _a.setContext,
22
+ refs = _a.refs;
24
23
  var findAndReplace = (0, _fortuneCore.locale)(context).findAndReplace;
24
+ var _b = (0, _react.useState)(""),
25
+ searchText = _b[0],
26
+ setSearchText = _b[1];
25
27
  var _c = (0, _react.useState)(""),
26
- searchText = _c[0],
27
- setSearchText = _c[1];
28
- var _d = (0, _react.useState)(""),
29
- replaceText = _d[0],
30
- setReplaceText = _d[1];
31
- var _e = (0, _react.useState)([]),
32
- searchResult = _e[0],
33
- setSearchResult = _e[1];
34
- var _f = (0, _react.useState)(),
35
- selectedCell = _f[0],
36
- setSelectedCell = _f[1];
28
+ replaceText = _c[0],
29
+ setReplaceText = _c[1];
30
+ var _d = (0, _react.useState)([]),
31
+ searchResult = _d[0],
32
+ setSearchResult = _d[1];
33
+ var _e = (0, _react.useState)(),
34
+ selectedCell = _e[0],
35
+ setSelectedCell = _e[1];
37
36
  var showAlert = (0, _useAlert.useAlert)().showAlert;
38
37
  var tableContainerRef = (0, _react.useRef)(null);
39
38
  var searchInputRef = (0, _react.useRef)(null);
40
39
  var replaceInputRef = (0, _react.useRef)(null);
41
- var _g = (0, _react.useState)({
40
+ var _f = (0, _react.useState)({
42
41
  regCheck: false,
43
42
  wordCheck: false,
44
43
  caseCheck: false
45
44
  }),
46
- checkMode = _g[0],
47
- checkModeReplace = _g[1];
45
+ checkMode = _f[0],
46
+ checkModeReplace = _f[1];
48
47
  var closeDialog = (0, _react.useCallback)(function () {
49
48
  _lodash.default.set(refs.globalCache, "searchDialog.mouseEnter", false);
50
49
  setContext(function (draftCtx) {
@@ -57,27 +56,19 @@ var SearchReplace = function SearchReplace(_a) {
57
56
  _lodash.default.set(draft, mode, value);
58
57
  }));
59
58
  }, []);
60
- var getInitialPosition = (0, _react.useCallback)(function (container) {
61
- var rect = container.getBoundingClientRect();
62
- return {
63
- left: (rect.width - 500) / 2,
64
- top: (rect.height - 200) / 3
65
- };
66
- }, []);
67
59
  return /*#__PURE__*/_react.default.createElement("div", {
68
60
  id: "fortune-search-replace",
69
61
  className: "fortune-search-replace fortune-dialog",
70
- style: getInitialPosition(getContainer()),
62
+ style: {
63
+ top: "50%",
64
+ left: "50%",
65
+ transform: "translate(-50%, -50%)"
66
+ },
71
67
  onMouseEnter: function onMouseEnter() {
72
68
  _lodash.default.set(refs.globalCache, "searchDialog.mouseEnter", true);
73
69
  },
74
70
  onMouseLeave: function onMouseLeave() {
75
71
  _lodash.default.set(refs.globalCache, "searchDialog.mouseEnter", false);
76
- },
77
- onMouseDown: function onMouseDown(e) {
78
- var nativeEvent = e.nativeEvent;
79
- (0, _fortuneCore.onSearchDialogMoveStart)(refs.globalCache, nativeEvent, getContainer());
80
- e.stopPropagation();
81
72
  }
82
73
  }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
83
74
  className: "flex items-center justify-between border-b color-border-default py-3 px-6"
@@ -153,11 +153,12 @@ var Sheet = function Sheet(_a) {
153
153
  }
154
154
  }, [context, refs.canvas, refs.globalCache.freezen, setContext, sheet.id]);
155
155
  var onWheel = (0, _react.useCallback)(function (e) {
156
+ var _a, _b;
156
157
  var functionDetailsEl = document.getElementById("function-details");
157
158
  var formulaSearchEl = document.getElementById("luckysheet-formula-search-c");
158
159
  var isMouseOverFunctionDetails = functionDetailsEl === null || functionDetailsEl === void 0 ? void 0 : functionDetailsEl.matches(":hover");
159
160
  var isMouseOverFormulaSearch = formulaSearchEl === null || formulaSearchEl === void 0 ? void 0 : formulaSearchEl.matches(":hover");
160
- if (functionDetailsEl && isMouseOverFunctionDetails || formulaSearchEl && isMouseOverFormulaSearch) return;
161
+ if (functionDetailsEl && isMouseOverFunctionDetails || formulaSearchEl && isMouseOverFormulaSearch || ((_b = (_a = refs === null || refs === void 0 ? void 0 : refs.globalCache) === null || _a === void 0 ? void 0 : _a.searchDialog) === null || _b === void 0 ? void 0 : _b.mouseEnter)) return;
161
162
  setContext(function (draftCtx) {
162
163
  (0, _fortuneCore.handleGlobalWheel)(draftCtx, e, refs.globalCache, refs.scrollbarX.current, refs.scrollbarY.current);
163
164
  });
@@ -7,6 +7,7 @@ type Props = {
7
7
  onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
8
8
  children: (setOpen: React.Dispatch<React.SetStateAction<boolean>>) => React.ReactNode;
9
9
  fillColor?: string;
10
+ triggerRef?: React.RefObject<HTMLButtonElement | null>;
10
11
  };
11
12
  declare const Combo: React.FC<Props>;
12
13
  export default Combo;
@@ -19,7 +19,8 @@ var Combo = function Combo(_a) {
19
19
  _b = _a.showArrow,
20
20
  showArrow = _b === void 0 ? true : _b,
21
21
  children = _a.children,
22
- fillColor = _a.fillColor;
22
+ fillColor = _a.fillColor,
23
+ triggerRef = _a.triggerRef;
23
24
  var style = {
24
25
  userSelect: "none"
25
26
  };
@@ -27,6 +28,10 @@ var Combo = function Combo(_a) {
27
28
  open = _c[0],
28
29
  setOpen = _c[1];
29
30
  var buttonRef = (0, _react.useRef)(null);
31
+ var ref = (0, _react.useRef)(null);
32
+ if (!triggerRef) {
33
+ triggerRef = ref;
34
+ }
30
35
  var handleOpenChange = function handleOpenChange(newOpen) {
31
36
  setOpen(newOpen);
32
37
  };
@@ -82,7 +87,7 @@ var Combo = function Combo(_a) {
82
87
  icon: (0, _.getLucideIcon)(iconId),
83
88
  variant: "ghost",
84
89
  onClick: function onClick() {
85
- return setOpen(!open);
90
+ setOpen(!open);
86
91
  },
87
92
  className: (0, _ui.cn)("fortune-toolbar-combo-button", {
88
93
  "custom-color-button": iconId === "font-color" && fillColor,
@@ -103,6 +108,7 @@ var Combo = function Combo(_a) {
103
108
  onOpenChange: handleOpenChange,
104
109
  modal: true
105
110
  }, /*#__PURE__*/_react.default.createElement(_ui.PopoverTrigger, {
111
+ ref: triggerRef,
106
112
  asChild: true
107
113
  }, /*#__PURE__*/_react.default.createElement("div", {
108
114
  className: "flex items-center"
@@ -1,6 +1,12 @@
1
1
  import React from "react";
2
+ import { Cell } from "@fileverse-dev/fortune-core";
2
3
  import "./index.css";
3
4
  export declare const getLucideIcon: (title: string) => "Ethereum" | "DollarSign" | "" | "ChevronDown" | "Undo" | "Redo" | "PaintRoller" | "Bold" | "Italic" | "Strikethrough" | "Underline" | "AlignLeft" | "AlignCenter" | "AlignRight" | "ArrowUpFromLine" | "AlignVerticalMiddle" | "ArrowDownToLine" | "TextOverflow" | "WrapText" | "TextClip" | "Baseline" | "PaintBucket" | "Border" | "MergeHorizontal" | "Percent" | "DecimalsArrowLeft" | "DecimalsArrowRight" | "PaintbrushVertical" | "Filter" | "Link" | "MessageSquarePlus" | "Image" | "Sigma" | "ShieldCheck" | "Search" | "DuneChart" | "Ellipsis";
5
+ export declare const CurrencySelector: ({ cell, defaultTextFormat, toolTipText, }: {
6
+ cell: Cell | null | undefined;
7
+ defaultTextFormat: string;
8
+ toolTipText: string;
9
+ }) => React.JSX.Element;
4
10
  declare const Toolbar: React.FC<{
5
11
  setMoreItems: React.Dispatch<React.SetStateAction<React.ReactNode>>;
6
12
  moreItemsOpen: boolean;
@@ -4,7 +4,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getLucideIcon = exports.default = void 0;
7
+ exports.getLucideIcon = exports.default = exports.CurrencySelector = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _fortuneCore = require("@fileverse-dev/fortune-core");
10
10
  var _lodash = _interopRequireDefault(require("lodash"));
@@ -236,6 +236,226 @@ var getLucideIcon = exports.getLucideIcon = function getLucideIcon(title) {
236
236
  return "";
237
237
  }
238
238
  };
239
+ var CurrencySelector = exports.CurrencySelector = function CurrencySelector(_a) {
240
+ var cell = _a.cell,
241
+ defaultTextFormat = _a.defaultTextFormat,
242
+ toolTipText = _a.toolTipText;
243
+ var _b = (0, _react.useContext)(_context.default),
244
+ context = _b.context,
245
+ setContext = _b.setContext,
246
+ refs = _b.refs;
247
+ var _c = (0, _react.useState)(""),
248
+ searchTerm = _c[0],
249
+ setSearchTerm = _c[1];
250
+ var _d = (0, _react.useState)(2),
251
+ decimals = _d[0],
252
+ setDecimals = _d[1];
253
+ var _e = (0, _react.useState)("USD"),
254
+ selectedFiat = _e[0],
255
+ setSelectedFiat = _e[1];
256
+ var currentFmt = defaultTextFormat;
257
+ var currentIcon = "currency";
258
+ if (cell) {
259
+ var curr_1 = (0, _fortuneCore.normalizedCellAttr)(cell, "ct");
260
+ if (curr_1 === null || curr_1 === void 0 ? void 0 : curr_1.fa) {
261
+ var allOptions = __spreadArray(__spreadArray([], _constants.CRYPTO_OPTIONS, true), (0, _fortuneCore.locale)(context).currencyDetail.map(function (c) {
262
+ return {
263
+ label: c.name,
264
+ value: c.value,
265
+ icon: undefined,
266
+ type: "fiat"
267
+ };
268
+ }), true);
269
+ var found = __spreadArray([], allOptions, true).sort(function (a, b) {
270
+ return b.value.length - a.value.length;
271
+ }).find(function (o) {
272
+ return curr_1.fa.includes(o.value);
273
+ });
274
+ if (found) {
275
+ currentFmt = found.label;
276
+ }
277
+ }
278
+ }
279
+ var groupedOptions = (0, _constants.getGroupedCurrencyOptions)((0, _fortuneCore.locale)(context).currencyDetail);
280
+ var filterOptions = function filterOptions(options) {
281
+ if (!searchTerm.trim()) return options;
282
+ var query = searchTerm.trim().toLowerCase();
283
+ return options.filter(function (opt) {
284
+ return query.split(/\s+/).every(function (word) {
285
+ return opt.label.toLowerCase().includes(word) || opt.value.toLowerCase().includes(word);
286
+ });
287
+ });
288
+ };
289
+ var dedupeByValue = function dedupeByValue(options) {
290
+ var seen = new Set();
291
+ return options.filter(function (opt) {
292
+ if (seen.has(opt.value)) return false;
293
+ seen.add(opt.value);
294
+ return true;
295
+ });
296
+ };
297
+ var handleCurrencyDecimalsChange = function handleCurrencyDecimalsChange(newDecimals) {
298
+ setDecimals(newDecimals);
299
+ var isCrypto = false;
300
+ if (cell && cell.ct && typeof cell.ct.fa === "string") {
301
+ var _a = cell.ct.fa.match(/"([A-Z]+)"/) || [],
302
+ matchedDenom = _a[1];
303
+ if (matchedDenom) isCrypto = true;
304
+ }
305
+ (0, _updateCellsDecimalFormat.updateCellsDecimalFormat)({
306
+ context: context,
307
+ setContext: setContext,
308
+ decimals: newDecimals,
309
+ denomination: isCrypto ? undefined : selectedFiat
310
+ });
311
+ };
312
+ var triggerRef = (0, _react.useRef)(null);
313
+ return /*#__PURE__*/_react.default.createElement("div", {
314
+ style: {
315
+ padding: "0px"
316
+ },
317
+ className: "items-center fortune-toolbar-button"
318
+ }, /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
319
+ text: toolTipText,
320
+ placement: "bottom"
321
+ }, /*#__PURE__*/_react.default.createElement("div", {
322
+ className: "",
323
+ onClick: function onClick() {
324
+ var _a;
325
+ (_a = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current) === null || _a === void 0 ? void 0 : _a.click();
326
+ },
327
+ tabIndex: 0,
328
+ role: "button"
329
+ }, /*#__PURE__*/_react.default.createElement(_ui.LucideIcon, {
330
+ name: getLucideIcon("currency-format"),
331
+ width: 16,
332
+ height: 16
333
+ }))), /*#__PURE__*/_react.default.createElement(_Combo.default, {
334
+ iconId: currentIcon,
335
+ text: currentFmt,
336
+ key: "currency",
337
+ tooltip: "",
338
+ showArrow: true,
339
+ triggerRef: triggerRef
340
+ }, function (setOpen) {
341
+ return /*#__PURE__*/_react.default.createElement("div", {
342
+ style: {
343
+ minWidth: "20rem",
344
+ boxShadow: "2px 2px 10px rgba(0, 0, 0, 0.2)",
345
+ borderRadius: "8px"
346
+ }
347
+ }, /*#__PURE__*/_react.default.createElement(_ui.Command, {
348
+ className: "border color-border-default rounded-lg"
349
+ }, /*#__PURE__*/_react.default.createElement("div", {
350
+ id: "search-input-container"
351
+ }, /*#__PURE__*/_react.default.createElement(_ui.CommandInput, {
352
+ placeholder: "Search by name or code",
353
+ value: searchTerm,
354
+ onValueChange: setSearchTerm
355
+ })), /*#__PURE__*/_react.default.createElement("div", {
356
+ className: "px-4 py-2 border-b color-border-default flex items-center justify-between gap-2 text-body-sm color-text-default",
357
+ onClick: function onClick(e) {
358
+ return e.stopPropagation();
359
+ }
360
+ }, /*#__PURE__*/_react.default.createElement("span", null, "Decimal places:"), /*#__PURE__*/_react.default.createElement("span", {
361
+ className: "cds-row flex items-center"
362
+ }, /*#__PURE__*/_react.default.createElement(_ui.IconButton, {
363
+ icon: "Minus",
364
+ variant: "ghost",
365
+ size: "sm",
366
+ className: "",
367
+ disabled: decimals === 1,
368
+ onClick: function onClick() {
369
+ return handleCurrencyDecimalsChange(Math.max(1, decimals - 1));
370
+ }
371
+ }), /*#__PURE__*/_react.default.createElement("input", {
372
+ type: "number",
373
+ min: 1,
374
+ max: 18,
375
+ value: decimals,
376
+ onChange: function onChange(e) {
377
+ return handleCurrencyDecimalsChange(Math.max(1, Math.min(18, Number(e.target.value))));
378
+ }
379
+ }), /*#__PURE__*/_react.default.createElement(_ui.IconButton, {
380
+ icon: "Plus",
381
+ variant: "ghost",
382
+ size: "sm",
383
+ disabled: decimals === 18,
384
+ onClick: function onClick() {
385
+ return handleCurrencyDecimalsChange(Math.min(18, decimals + 1));
386
+ }
387
+ }))), /*#__PURE__*/_react.default.createElement(_ui.CommandList, null, /*#__PURE__*/_react.default.createElement(_ui.CommandEmpty, {
388
+ className: "text-center text-body-sm color-text-secondary flex items-center justify-center",
389
+ style: {
390
+ minHeight: "5rem"
391
+ }
392
+ }, "No results found."), groupedOptions.map(function (group) {
393
+ var filtered = dedupeByValue(filterOptions(group.options));
394
+ return /*#__PURE__*/_react.default.createElement(_ui.CommandGroup, {
395
+ key: group.group,
396
+ heading: group.group
397
+ }, filtered.map(function (opt) {
398
+ return /*#__PURE__*/_react.default.createElement(_ui.CommandItem, {
399
+ key: opt.value,
400
+ value: "".concat(opt.label, " ").concat(opt.value),
401
+ onSelect: function onSelect() {
402
+ return __awaiter(void 0, void 0, void 0, function () {
403
+ return __generator(this, function (_a) {
404
+ switch (_a.label) {
405
+ case 0:
406
+ if (!(opt.type === "crypto")) return [3, 2];
407
+ return [4, (0, _convertCellsToCrypto.convertCellsToCrypto)({
408
+ context: context,
409
+ setContext: setContext,
410
+ denomination: opt.value,
411
+ decimals: decimals
412
+ })];
413
+ case 1:
414
+ _a.sent();
415
+ return [3, 3];
416
+ case 2:
417
+ setSelectedFiat(opt.value);
418
+ setContext(function (ctx) {
419
+ var d = (0, _fortuneCore.getFlowdata)(ctx);
420
+ if (d == null) return;
421
+ var formatString = "".concat((0, _convertCellsToCrypto.getFiatSymbol)(opt.value), " #,##0.").concat("0".repeat(decimals));
422
+ (0, _fortuneCore.updateFormat)(ctx, refs.cellInput.current, d, "ct", formatString);
423
+ });
424
+ _a.label = 3;
425
+ case 3:
426
+ setOpen(false);
427
+ return [2];
428
+ }
429
+ });
430
+ });
431
+ }
432
+ }, /*#__PURE__*/_react.default.createElement("div", {
433
+ className: "fortune-toolbar-menu-line flex items-center justify-between w-full"
434
+ }, /*#__PURE__*/_react.default.createElement("div", {
435
+ className: "flex items-center gap-2 w-[250px]"
436
+ }, currentFmt === opt.label ? (/*#__PURE__*/_react.default.createElement(_ui.LucideIcon, {
437
+ name: "Check",
438
+ className: "w-4 h-4"
439
+ })) : (/*#__PURE__*/_react.default.createElement("span", {
440
+ className: "w-4 h-4"
441
+ })), /*#__PURE__*/_react.default.createElement("span", {
442
+ className: "truncate flex-1 overflow-hidden whitespace-nowrap"
443
+ }, opt.label)), opt.type === "crypto" ? (/*#__PURE__*/_react.default.createElement("span", {
444
+ className: "color-text-secondary"
445
+ }, /*#__PURE__*/_react.default.createElement(_ui.LucideIcon, {
446
+ name: opt.icon,
447
+ className: "cds-icon"
448
+ }), opt.value === "SOL" && (/*#__PURE__*/_react.default.createElement(_SVGIcon.default, {
449
+ name: "solana",
450
+ width: 16,
451
+ height: 16
452
+ })))) : (/*#__PURE__*/_react.default.createElement("span", {
453
+ className: "color-text-secondary"
454
+ }, opt.value))));
455
+ }));
456
+ }))));
457
+ }));
458
+ };
239
459
  var Toolbar = function Toolbar(_a) {
240
460
  var _b, _c, _d;
241
461
  var setMoreItems = _a.setMoreItems,
@@ -295,15 +515,6 @@ var Toolbar = function Toolbar(_a) {
295
515
  var defaultFormat = defaultFmt(currency);
296
516
  var customColor = (0, _react.useState)("#000000")[0];
297
517
  var customStyle = (0, _react.useState)("1")[0];
298
- var _m = (0, _react.useState)(""),
299
- searchTerm = _m[0],
300
- setSearchTerm = _m[1];
301
- var _o = (0, _react.useState)(2),
302
- decimals = _o[0],
303
- setDecimals = _o[1];
304
- var _p = (0, _react.useState)("USD"),
305
- selectedFiat = _p[0],
306
- setSelectedFiat = _p[1];
307
518
  var showSubMenu = (0, _react.useCallback)(function (e, className) {
308
519
  var target = e.target;
309
520
  var menuItem = target.className === "fortune-toolbar-menu-line" ? target.parentElement : target;
@@ -438,11 +649,11 @@ var Toolbar = function Toolbar(_a) {
438
649
  if (name === "format") {
439
650
  var currentFmt = defaultFormat[0].text;
440
651
  if (cell) {
441
- var curr_1 = (0, _fortuneCore.normalizedCellAttr)(cell, "ct");
652
+ var curr_2 = (0, _fortuneCore.normalizedCellAttr)(cell, "ct");
442
653
  var format = _lodash.default.find(defaultFormat, function (v) {
443
- return v.value === (curr_1 === null || curr_1 === void 0 ? void 0 : curr_1.fa);
654
+ return v.value === (curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa);
444
655
  });
445
- if ((curr_1 === null || curr_1 === void 0 ? void 0 : curr_1.fa) != null) {
656
+ if ((curr_2 === null || curr_2 === void 0 ? void 0 : curr_2.fa) != null) {
446
657
  if (format != null) {
447
658
  currentFmt = format.text;
448
659
  } else {
@@ -1219,12 +1430,12 @@ var Toolbar = function Toolbar(_a) {
1219
1430
  iconId: "text-wrap",
1220
1431
  value: "wrap"
1221
1432
  }];
1222
- var curr_2 = items_7[0];
1433
+ var curr_3 = items_7[0];
1223
1434
  if ((cell === null || cell === void 0 ? void 0 : cell.tb) != null) {
1224
- curr_2 = _lodash.default.get(items_7, cell.tb);
1435
+ curr_3 = _lodash.default.get(items_7, cell.tb);
1225
1436
  }
1226
1437
  return /*#__PURE__*/_react.default.createElement(_Combo.default, {
1227
- iconId: curr_2.iconId,
1438
+ iconId: curr_3.iconId,
1228
1439
  key: name,
1229
1440
  tooltip: toolbar.textWrap,
1230
1441
  showArrow: false
@@ -1243,7 +1454,7 @@ var Toolbar = function Toolbar(_a) {
1243
1454
  value = _a.value;
1244
1455
  return /*#__PURE__*/_react.default.createElement(_ui.IconButton, {
1245
1456
  key: value,
1246
- isActive: curr_2.value === value,
1457
+ isActive: curr_3.value === value,
1247
1458
  icon: getLucideIcon(iconId),
1248
1459
  variant: "ghost",
1249
1460
  onClick: function onClick() {
@@ -1397,185 +1608,10 @@ var Toolbar = function Toolbar(_a) {
1397
1608
  });
1398
1609
  }
1399
1610
  if (name === "currency") {
1400
- var currentFmt_1 = defaultFormat[0].text;
1401
- var currentIcon = "currency";
1402
- if (cell) {
1403
- var curr_3 = (0, _fortuneCore.normalizedCellAttr)(cell, "ct");
1404
- if (curr_3 === null || curr_3 === void 0 ? void 0 : curr_3.fa) {
1405
- var allOptions = __spreadArray(__spreadArray([], _constants.CRYPTO_OPTIONS, true), (0, _fortuneCore.locale)(context).currencyDetail.map(function (c) {
1406
- return {
1407
- label: c.name,
1408
- value: c.value,
1409
- icon: undefined,
1410
- type: "fiat"
1411
- };
1412
- }), true);
1413
- var found = __spreadArray([], allOptions, true).sort(function (a, b) {
1414
- return b.value.length - a.value.length;
1415
- }).find(function (o) {
1416
- return curr_3.fa.includes(o.value);
1417
- });
1418
- if (found) {
1419
- currentFmt_1 = found.label;
1420
- }
1421
- }
1422
- }
1423
- var groupedOptions_1 = (0, _constants.getGroupedCurrencyOptions)((0, _fortuneCore.locale)(context).currencyDetail);
1424
- var filterOptions_1 = function filterOptions_1(options) {
1425
- if (!searchTerm.trim()) return options;
1426
- var query = searchTerm.trim().toLowerCase();
1427
- return options.filter(function (opt) {
1428
- return query.split(/\s+/).every(function (word) {
1429
- return opt.label.toLowerCase().includes(word) || opt.value.toLowerCase().includes(word);
1430
- });
1431
- });
1432
- };
1433
- var dedupeByValue_1 = function dedupeByValue_1(options) {
1434
- var seen = new Set();
1435
- return options.filter(function (opt) {
1436
- if (seen.has(opt.value)) return false;
1437
- seen.add(opt.value);
1438
- return true;
1439
- });
1440
- };
1441
- var handleCurrencyDecimalsChange_1 = function handleCurrencyDecimalsChange_1(newDecimals) {
1442
- setDecimals(newDecimals);
1443
- var isCrypto = false;
1444
- if (cell && cell.ct && typeof cell.ct.fa === "string") {
1445
- var _a = cell.ct.fa.match(/"([A-Z]+)"/) || [],
1446
- matchedDenom = _a[1];
1447
- if (matchedDenom) isCrypto = true;
1448
- }
1449
- (0, _updateCellsDecimalFormat.updateCellsDecimalFormat)({
1450
- context: context,
1451
- setContext: setContext,
1452
- decimals: newDecimals,
1453
- denomination: isCrypto ? undefined : selectedFiat
1454
- });
1455
- };
1456
- return /*#__PURE__*/_react.default.createElement(_Combo.default, {
1457
- iconId: currentIcon,
1458
- text: currentFmt_1,
1459
- key: name,
1460
- tooltip: tooltip,
1461
- showArrow: true
1462
- }, function (setOpen) {
1463
- return /*#__PURE__*/_react.default.createElement("div", {
1464
- style: {
1465
- minWidth: "20rem",
1466
- boxShadow: "2px 2px 10px rgba(0, 0, 0, 0.2)",
1467
- borderRadius: "8px"
1468
- }
1469
- }, /*#__PURE__*/_react.default.createElement(_ui.Command, {
1470
- className: "border color-border-default rounded-lg"
1471
- }, /*#__PURE__*/_react.default.createElement("div", {
1472
- id: "search-input-container"
1473
- }, /*#__PURE__*/_react.default.createElement(_ui.CommandInput, {
1474
- placeholder: "Search by name or code",
1475
- value: searchTerm,
1476
- onValueChange: setSearchTerm
1477
- })), /*#__PURE__*/_react.default.createElement("div", {
1478
- className: "px-4 py-2 border-b color-border-default flex items-center justify-between gap-2 text-body-sm color-text-default",
1479
- onClick: function onClick(e) {
1480
- return e.stopPropagation();
1481
- }
1482
- }, /*#__PURE__*/_react.default.createElement("span", null, "Decimal places:"), /*#__PURE__*/_react.default.createElement("span", {
1483
- className: "cds-row flex items-center"
1484
- }, /*#__PURE__*/_react.default.createElement(_ui.IconButton, {
1485
- icon: "Minus",
1486
- variant: "ghost",
1487
- size: "sm",
1488
- className: "",
1489
- disabled: decimals === 1,
1490
- onClick: function onClick() {
1491
- return handleCurrencyDecimalsChange_1(Math.max(1, decimals - 1));
1492
- }
1493
- }), /*#__PURE__*/_react.default.createElement("input", {
1494
- type: "number",
1495
- min: 1,
1496
- max: 18,
1497
- value: decimals,
1498
- onChange: function onChange(e) {
1499
- return handleCurrencyDecimalsChange_1(Math.max(1, Math.min(18, Number(e.target.value))));
1500
- }
1501
- }), /*#__PURE__*/_react.default.createElement(_ui.IconButton, {
1502
- icon: "Plus",
1503
- variant: "ghost",
1504
- size: "sm",
1505
- disabled: decimals === 18,
1506
- onClick: function onClick() {
1507
- return handleCurrencyDecimalsChange_1(Math.min(18, decimals + 1));
1508
- }
1509
- }))), /*#__PURE__*/_react.default.createElement(_ui.CommandList, null, /*#__PURE__*/_react.default.createElement(_ui.CommandEmpty, {
1510
- className: "text-center text-body-sm color-text-secondary flex items-center justify-center",
1511
- style: {
1512
- minHeight: "5rem"
1513
- }
1514
- }, "No results found."), groupedOptions_1.map(function (group) {
1515
- var filtered = dedupeByValue_1(filterOptions_1(group.options));
1516
- return /*#__PURE__*/_react.default.createElement(_ui.CommandGroup, {
1517
- key: group.group,
1518
- heading: group.group
1519
- }, filtered.map(function (opt) {
1520
- return /*#__PURE__*/_react.default.createElement(_ui.CommandItem, {
1521
- key: opt.value,
1522
- value: "".concat(opt.label, " ").concat(opt.value),
1523
- onSelect: function onSelect() {
1524
- return __awaiter(void 0, void 0, void 0, function () {
1525
- return __generator(this, function (_a) {
1526
- switch (_a.label) {
1527
- case 0:
1528
- if (!(opt.type === "crypto")) return [3, 2];
1529
- return [4, (0, _convertCellsToCrypto.convertCellsToCrypto)({
1530
- context: context,
1531
- setContext: setContext,
1532
- denomination: opt.value,
1533
- decimals: decimals
1534
- })];
1535
- case 1:
1536
- _a.sent();
1537
- return [3, 3];
1538
- case 2:
1539
- setSelectedFiat(opt.value);
1540
- setContext(function (ctx) {
1541
- var d = (0, _fortuneCore.getFlowdata)(ctx);
1542
- if (d == null) return;
1543
- var formatString = "".concat((0, _convertCellsToCrypto.getFiatSymbol)(opt.value), " #,##0.").concat("0".repeat(decimals));
1544
- (0, _fortuneCore.updateFormat)(ctx, refs.cellInput.current, d, "ct", formatString);
1545
- });
1546
- _a.label = 3;
1547
- case 3:
1548
- setOpen(false);
1549
- return [2];
1550
- }
1551
- });
1552
- });
1553
- }
1554
- }, /*#__PURE__*/_react.default.createElement("div", {
1555
- className: "fortune-toolbar-menu-line flex items-center justify-between w-full"
1556
- }, /*#__PURE__*/_react.default.createElement("div", {
1557
- className: "flex items-center gap-2 w-[250px]"
1558
- }, currentFmt_1 === opt.label ? (/*#__PURE__*/_react.default.createElement(_ui.LucideIcon, {
1559
- name: "Check",
1560
- className: "w-4 h-4"
1561
- })) : (/*#__PURE__*/_react.default.createElement("span", {
1562
- className: "w-4 h-4"
1563
- })), /*#__PURE__*/_react.default.createElement("span", {
1564
- className: "truncate flex-1 overflow-hidden whitespace-nowrap"
1565
- }, opt.label)), opt.type === "crypto" ? (/*#__PURE__*/_react.default.createElement("span", {
1566
- className: "color-text-secondary"
1567
- }, /*#__PURE__*/_react.default.createElement(_ui.LucideIcon, {
1568
- name: opt.icon,
1569
- className: "cds-icon"
1570
- }), opt.value === "SOL" && (/*#__PURE__*/_react.default.createElement(_SVGIcon.default, {
1571
- name: "solana",
1572
- width: 16,
1573
- height: 16
1574
- })))) : (/*#__PURE__*/_react.default.createElement("span", {
1575
- className: "color-text-secondary"
1576
- }, opt.value))));
1577
- }));
1578
- }))));
1611
+ return /*#__PURE__*/_react.default.createElement(CurrencySelector, {
1612
+ cell: cell,
1613
+ defaultTextFormat: defaultFormat[0].text,
1614
+ toolTipText: toolbar["currency-format"]
1579
1615
  });
1580
1616
  }
1581
1617
  return /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.0.98",
3
+ "version": "1.0.100",
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.98",
19
+ "@fileverse-dev/fortune-core": "1.0.100",
20
20
  "@fileverse/ui": "^4.1.7-patch-21",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",