@underverse-ui/underverse 1.0.152 → 1.0.153

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,6 +1,6 @@
1
1
  {
2
2
  "package": "@underverse-ui/underverse",
3
- "version": "1.0.152",
3
+ "version": "1.0.153",
4
4
  "sourceEntry": "src/index.ts",
5
5
  "totalExports": 232,
6
6
  "exports": [
package/dist/index.cjs CHANGED
@@ -1030,6 +1030,9 @@ var en_default = {
1030
1030
  borderColor: "Border Color",
1031
1031
  clearBorder: "Clear Border",
1032
1032
  formula: "Formula",
1033
+ numberFormat: "Number Format",
1034
+ formatText: "Text",
1035
+ formatDate: "Date",
1033
1036
  apply: "Apply",
1034
1037
  clear: "Clear",
1035
1038
  recalculate: "Recalculate",
@@ -1410,6 +1413,9 @@ var vi_default = {
1410
1413
  borderColor: "M\xE0u vi\u1EC1n",
1411
1414
  clearBorder: "X\xF3a vi\u1EC1n",
1412
1415
  formula: "C\xF4ng th\u1EE9c",
1416
+ numberFormat: "\u0110\u1ECBnh d\u1EA1ng s\u1ED1",
1417
+ formatText: "Ch\u1EEF",
1418
+ formatDate: "Ng\xE0y",
1413
1419
  apply: "\xC1p d\u1EE5ng",
1414
1420
  clear: "X\xF3a",
1415
1421
  recalculate: "T\xEDnh l\u1EA1i",
@@ -30022,6 +30028,50 @@ function normalizeTableFormula(formula) {
30022
30028
  function formatFormulaError(error) {
30023
30029
  return `#${error.toUpperCase()}`;
30024
30030
  }
30031
+ function normalizeTableNumberFormat(format) {
30032
+ return format === "text" || format === "number" || format === "currency" || format === "percent" || format === "date" ? format : "text";
30033
+ }
30034
+ function formatTableFormulaDisplayValue(value, numberFormat) {
30035
+ const stringValue = String(value);
30036
+ if (stringValue.startsWith("#")) {
30037
+ return stringValue;
30038
+ }
30039
+ const normalizedFormat = normalizeTableNumberFormat(numberFormat);
30040
+ if (normalizedFormat === "text") {
30041
+ return stringValue;
30042
+ }
30043
+ const numericValue = typeof value === "number" ? value : Number.parseFloat(stringValue.replace(/,/g, ""));
30044
+ if (!Number.isFinite(numericValue)) {
30045
+ return stringValue;
30046
+ }
30047
+ if (normalizedFormat === "number") {
30048
+ return new Intl.NumberFormat("en-US", { maximumFractionDigits: 6 }).format(numericValue);
30049
+ }
30050
+ if (normalizedFormat === "currency") {
30051
+ return new Intl.NumberFormat("en-US", {
30052
+ style: "currency",
30053
+ currency: "USD",
30054
+ maximumFractionDigits: 2
30055
+ }).format(numericValue);
30056
+ }
30057
+ if (normalizedFormat === "percent") {
30058
+ return new Intl.NumberFormat("en-US", {
30059
+ style: "percent",
30060
+ maximumFractionDigits: 2
30061
+ }).format(numericValue);
30062
+ }
30063
+ const excelEpochMs = Date.UTC(1899, 11, 30);
30064
+ const date = new Date(excelEpochMs + numericValue * 24 * 60 * 60 * 1e3);
30065
+ if (Number.isNaN(date.getTime())) {
30066
+ return stringValue;
30067
+ }
30068
+ return new Intl.DateTimeFormat("en-US", {
30069
+ year: "numeric",
30070
+ month: "2-digit",
30071
+ day: "2-digit",
30072
+ timeZone: "UTC"
30073
+ }).format(date);
30074
+ }
30025
30075
  function getTableFormulaReferences(formula) {
30026
30076
  const normalized = normalizeTableFormula(formula);
30027
30077
  if (!normalized) return [];
@@ -30418,6 +30468,16 @@ function setSelectedTableCellFormula(editor, formula) {
30418
30468
  function clearSelectedTableCellFormula(editor) {
30419
30469
  return setSelectedTableCellFormula(editor, "");
30420
30470
  }
30471
+ function setSelectedTableCellNumberFormat(editor, numberFormat) {
30472
+ const value = numberFormat && numberFormat !== "text" ? numberFormat : null;
30473
+ const { state, view } = editor;
30474
+ const applied = (0, import_tables2.setCellAttr)("numberFormat", value)(state, view.dispatch.bind(view));
30475
+ if (!applied) return false;
30476
+ recalculateSelectedTable(editor);
30477
+ view.focus();
30478
+ dispatchTableLayoutChange(editor);
30479
+ return true;
30480
+ }
30421
30481
  function promoteFormulaTextInTableNode(tableNode) {
30422
30482
  let changed = false;
30423
30483
  const rows = getTableRows2(tableNode).map((rowInfo) => {
@@ -30496,14 +30556,15 @@ function recalculateTableNode(tableNode) {
30496
30556
  const label = `${indexToColumnName(rectForCell.left)}${rectForCell.top + 1}`;
30497
30557
  const computedValue = computedValues.get(label);
30498
30558
  if (computedValue == null) continue;
30499
- const contentMatchesComputedValue = getCellText(entry.node) === computedValue;
30559
+ const displayValue = formatTableFormulaDisplayValue(computedValue, entry.node.attrs.numberFormat);
30560
+ const contentMatchesComputedValue = getCellText(entry.node) === displayValue;
30500
30561
  if (entry.node.attrs.computedValue === computedValue && contentMatchesComputedValue) continue;
30501
30562
  cells[entry.index] = entry.node.type.create(
30502
30563
  {
30503
30564
  ...entry.node.attrs,
30504
30565
  computedValue
30505
30566
  },
30506
- createCellDisplayContent(entry.node, computedValue),
30567
+ createCellDisplayContent(entry.node, displayValue),
30507
30568
  entry.node.marks
30508
30569
  );
30509
30570
  changed = true;
@@ -30592,6 +30653,7 @@ var BubbleMenuContent = ({
30592
30653
  const currentHighlightColor = normalizeStyleValue(editor.getAttributes("highlight").color) || "";
30593
30654
  const currentCellBgColor = normalizeStyleValue(editor.getAttributes("tableCell").backgroundColor || editor.getAttributes("tableHeader").backgroundColor) || "";
30594
30655
  const currentCellFormula = normalizeStyleValue(editor.getAttributes("tableCell").formula || editor.getAttributes("tableHeader").formula) || "";
30656
+ const currentCellNumberFormat = normalizeStyleValue(editor.getAttributes("tableCell").numberFormat || editor.getAttributes("tableHeader").numberFormat) || "text";
30595
30657
  const isInTable2 = (0, import_tables3.isInTable)(editor.state);
30596
30658
  const canMergeCells = isInTable2 && editor.can().mergeCells();
30597
30659
  const canSplitCell = isInTable2 && editor.can().splitCell();
@@ -30851,6 +30913,28 @@ var BubbleMenuContent = ({
30851
30913
  className: "h-full min-w-0 flex-1 bg-transparent px-2 text-sm font-medium text-foreground outline-none"
30852
30914
  }
30853
30915
  ) }),
30916
+ /* @__PURE__ */ (0, import_jsx_runtime86.jsxs)("div", { className: "mt-2", children: [
30917
+ /* @__PURE__ */ (0, import_jsx_runtime86.jsx)("div", { className: "mb-1 px-1 text-[11px] font-medium text-muted-foreground", children: t("tableMenu.numberFormat") || "Number format" }),
30918
+ /* @__PURE__ */ (0, import_jsx_runtime86.jsx)("div", { className: "grid grid-cols-5 gap-1", children: [
30919
+ ["text", "Text"],
30920
+ ["number", "123"],
30921
+ ["currency", "$"],
30922
+ ["percent", "%"],
30923
+ ["date", "Date"]
30924
+ ].map(([format, label]) => /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(
30925
+ "button",
30926
+ {
30927
+ type: "button",
30928
+ onClick: () => setSelectedTableCellNumberFormat(editor, format),
30929
+ className: cn(
30930
+ "h-8 rounded-md text-[11px] font-semibold transition-colors hover:bg-muted",
30931
+ currentCellNumberFormat === format || format === "text" && !currentCellNumberFormat ? "bg-primary/10 text-primary" : "bg-muted/40 text-foreground"
30932
+ ),
30933
+ children: format === "text" ? t("tableMenu.formatText") || label : format === "date" ? t("tableMenu.formatDate") || label : label
30934
+ },
30935
+ format
30936
+ )) })
30937
+ ] }),
30854
30938
  /* @__PURE__ */ (0, import_jsx_runtime86.jsxs)("div", { className: "mt-2 grid grid-cols-3 gap-1", children: [
30855
30939
  /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(
30856
30940
  "button",