@particle-academy/fancy-sheets 0.4.2 → 0.4.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.
package/dist/index.cjs CHANGED
@@ -1237,10 +1237,15 @@ function getRecalculationOrder(graph) {
1237
1237
 
1238
1238
  // src/hooks/use-spreadsheet-store.ts
1239
1239
  function recalculateWorkbook(workbook) {
1240
- return {
1241
- ...workbook,
1242
- sheets: workbook.sheets.map((s) => recalculateSheet(s, workbook.sheets))
1243
- };
1240
+ const recalculated = [];
1241
+ for (const sheet of workbook.sheets) {
1242
+ recalculated.push(recalculateSheet(sheet, recalculated));
1243
+ }
1244
+ const finalSheets = [];
1245
+ for (const sheet of recalculated) {
1246
+ finalSheets.push(recalculateSheet(sheet, recalculated));
1247
+ }
1248
+ return { ...workbook, sheets: finalSheets };
1244
1249
  }
1245
1250
  function createInitialState(data) {
1246
1251
  const workbook = data ?? createEmptyWorkbook();
@@ -1340,10 +1345,11 @@ function reducer(state, action) {
1340
1345
  const sheet = getActiveSheet(state);
1341
1346
  const existing = sheet.cells[action.address];
1342
1347
  if (existing?.format) cellData.format = existing.format;
1343
- const workbook = updateActiveSheet(state, (s) => {
1344
- const updated = { ...s, cells: { ...s.cells, [action.address]: cellData } };
1345
- return recalculateSheet(updated, state.workbook.sheets);
1346
- });
1348
+ const updatedWorkbook = updateActiveSheet(state, (s) => ({
1349
+ ...s,
1350
+ cells: { ...s.cells, [action.address]: cellData }
1351
+ }));
1352
+ const workbook = recalculateWorkbook(updatedWorkbook);
1347
1353
  return { ...state, workbook, ...history };
1348
1354
  }
1349
1355
  case "SET_CELL_FORMAT": {
@@ -2198,7 +2204,18 @@ function DefaultToolbar() {
2198
2204
  const isItalic = cell?.format?.italic ?? false;
2199
2205
  const textAlign = cell?.format?.textAlign ?? "left";
2200
2206
  const displayFormat = cell?.format?.displayFormat ?? "auto";
2201
- const decimals = cell?.format?.decimals;
2207
+ const explicitDecimals = cell?.format?.decimals;
2208
+ const cellValue = cell?.computedValue ?? cell?.value;
2209
+ const inferredDecimals = (() => {
2210
+ if (explicitDecimals !== void 0) return explicitDecimals;
2211
+ if (typeof cellValue === "number") {
2212
+ const str = String(cellValue);
2213
+ const dotIdx = str.indexOf(".");
2214
+ return dotIdx === -1 ? 0 : str.length - dotIdx - 1;
2215
+ }
2216
+ return 0;
2217
+ })();
2218
+ const currentDecimals = explicitDecimals ?? inferredDecimals;
2202
2219
  const selectedAddresses = [selection.activeCell];
2203
2220
  const handleFormulaBarChange = (e) => {
2204
2221
  if (editingCell) {
@@ -2335,9 +2352,9 @@ function DefaultToolbar() {
2335
2352
  "button",
2336
2353
  {
2337
2354
  className: btnClass,
2338
- onClick: () => setCellFormat(selectedAddresses, { decimals: Math.max(0, (decimals ?? 0) - 1) }),
2339
- disabled: readOnly || (decimals ?? 0) <= 0,
2340
- title: "Decrease decimal places",
2355
+ onClick: () => setCellFormat(selectedAddresses, { decimals: Math.max(0, currentDecimals - 1) }),
2356
+ disabled: readOnly || currentDecimals <= 0,
2357
+ title: `Decrease decimal places (currently ${currentDecimals})`,
2341
2358
  children: [
2342
2359
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: ".0" }),
2343
2360
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: "\u2190" })
@@ -2348,9 +2365,9 @@ function DefaultToolbar() {
2348
2365
  "button",
2349
2366
  {
2350
2367
  className: btnClass,
2351
- onClick: () => setCellFormat(selectedAddresses, { decimals: (decimals ?? 0) + 1 }),
2368
+ onClick: () => setCellFormat(selectedAddresses, { decimals: currentDecimals + 1 }),
2352
2369
  disabled: readOnly,
2353
- title: "Increase decimal places",
2370
+ title: `Increase decimal places (currently ${currentDecimals})`,
2354
2371
  children: [
2355
2372
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[10px]", children: ".00" }),
2356
2373
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[8px]", children: "\u2192" })