Fix toolbox persistence, table evaluation, and onboarding panel styling
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
0171c9fc98
commit
184314d913
9 changed files with 119 additions and 32 deletions
|
|
@ -47,10 +47,11 @@ export function DrawingOverlay({ active, erase, strokes, color, width, onChange,
|
|||
useEffect(() => {
|
||||
function syncSize() {
|
||||
const nextSize = getSurfaceSize?.() || { width: 0, height: 0 };
|
||||
setSize({
|
||||
width: Math.max(0, Math.ceil(nextSize.width || 0)),
|
||||
height: Math.max(0, Math.ceil(nextSize.height || 0))
|
||||
});
|
||||
const nextWidth = Math.max(0, Math.ceil(nextSize.width || 0));
|
||||
const nextHeight = Math.max(0, Math.ceil(nextSize.height || 0));
|
||||
setSize((current) => current.width === nextWidth && current.height === nextHeight
|
||||
? current
|
||||
: { width: nextWidth, height: nextHeight });
|
||||
}
|
||||
|
||||
syncSize();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { DrawingControls } from "./DrawingControls.jsx";
|
|||
import { DrawingOverlay } from "./DrawingOverlay.jsx";
|
||||
import { NotepadToolbar } from "./NotepadToolbar.jsx";
|
||||
import { TextExchangeActions } from "./TextExchangeActions.jsx";
|
||||
import { normalizeNotepadData } from "../storage/toolboxStorage.js";
|
||||
import {
|
||||
DRAWING_WIDTHS,
|
||||
HIGHLIGHT_COLORS,
|
||||
|
|
@ -21,7 +22,7 @@ import {
|
|||
|
||||
export function NotepadModule({ toolboxId, moduleId, context, textExchangeOpen }) {
|
||||
const storedData = context.getModuleData(toolboxId, moduleId, { text: "" });
|
||||
const normalizedData = useMemo(() => context.normalizeNotepadData(storedData), [context, storedData]);
|
||||
const normalizedData = useMemo(() => normalizeNotepadData(storedData), [storedData]);
|
||||
const textContent = context.moduleText?.notepad || {};
|
||||
const notify = context.notify;
|
||||
const activePage = normalizedData.pages.find((page) => page.id === normalizedData.activePageId) || normalizedData.pages[0];
|
||||
|
|
@ -43,7 +44,7 @@ export function NotepadModule({ toolboxId, moduleId, context, textExchangeOpen }
|
|||
const [textColor, setTextColor] = useState(TEXT_COLORS[0]);
|
||||
const [highlightColor, setHighlightColor] = useState(HIGHLIGHT_COLORS[0]);
|
||||
const [editingPageId, setEditingPageId] = useState("");
|
||||
const [pageTitleDrafts, setPageTitleDrafts] = useState({});
|
||||
const [pageTitleDrafts, setPageTitleDrafts] = useState(() => Object.fromEntries(normalizedData.pages.map((page) => [page.id, page.title])));
|
||||
const [activeFormats, setActiveFormats] = useState({
|
||||
bold: false,
|
||||
italic: false,
|
||||
|
|
@ -56,10 +57,6 @@ export function NotepadModule({ toolboxId, moduleId, context, textExchangeOpen }
|
|||
const sessionKey = `sokkog:notepad-drawings:${toolboxId}:${moduleId}:${activePage.id}`;
|
||||
const [temporaryStrokes, setTemporaryStrokes] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
setPageTitleDrafts(Object.fromEntries(normalizedData.pages.map((page) => [page.id, page.title])));
|
||||
}, [normalizedData.pages]);
|
||||
|
||||
useEffect(() => {
|
||||
const pageKey = `${toolboxId}:${moduleId}:${activePage.id}`;
|
||||
if (pageKeyRef.current !== pageKey) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ import {
|
|||
import { useTableInteractions } from "./useTableInteractions.js";
|
||||
|
||||
export function TableModule({ toolboxId, moduleId, context, textExchangeOpen }) {
|
||||
const data = context.normalizeTableData(context.getModuleData(toolboxId, moduleId, { rows: DEFAULT_ROWS, columns: DEFAULT_COLUMNS, cells: {} }));
|
||||
const rawData = context.getModuleData(toolboxId, moduleId, { rows: DEFAULT_ROWS, columns: DEFAULT_COLUMNS, cells: {} });
|
||||
const data = useMemo(() => context.normalizeTableData(rawData), [context, rawData]);
|
||||
const textContent = context.moduleText?.table || {};
|
||||
const evaluatedCells = useMemo(() => evaluateTable(data.cells, data), [data]);
|
||||
const columnWidths = useMemo(() => getColumnWidths(data, evaluatedCells), [data, evaluatedCells]);
|
||||
|
|
|
|||
|
|
@ -162,6 +162,11 @@ export function evaluateFormula(expression, resolveReference) {
|
|||
}
|
||||
|
||||
export function evaluateTableCell(address, cells, dimensions, stack = []) {
|
||||
return evaluateTableCellWithCache(address, cells, dimensions, stack, new Map());
|
||||
}
|
||||
|
||||
function evaluateTableCellWithCache(address, cells, dimensions, stack, cache) {
|
||||
if (!stack.length && cache.has(address)) return cache.get(address);
|
||||
const raw = String(cells?.[address] || "").trim();
|
||||
if (!raw) return { value: null, display: "", error: "empty" };
|
||||
|
||||
|
|
@ -176,25 +181,30 @@ export function evaluateTableCell(address, cells, dimensions, stack = []) {
|
|||
|
||||
const result = evaluateFormula(raw.slice(1), (reference) => {
|
||||
if (!CELL_REFERENCE_RE.test(reference) || !isCellInBounds(reference, dimensions.rows, dimensions.columns)) throw new Error("reference");
|
||||
const value = evaluateTableCell(reference, cells, dimensions, [...stack, address]);
|
||||
const value = evaluateTableCellWithCache(reference, cells, dimensions, [...stack, address], cache);
|
||||
if (value.error || value.value == null) throw new Error(value.error === "cycle" ? "cycle" : "reference");
|
||||
return value.value;
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
const label = result.error === "cycle" ? "#CYCLE" : result.error === "division" ? "#DIV/0" : "#ERREUR";
|
||||
return { value: null, display: label, error: result.error };
|
||||
const evaluated = { value: null, display: label, error: result.error };
|
||||
if (!stack.length) cache.set(address, evaluated);
|
||||
return evaluated;
|
||||
}
|
||||
|
||||
return { value: result.value, display: formatNumber(result.value), error: "" };
|
||||
const evaluated = { value: result.value, display: formatNumber(result.value), error: "" };
|
||||
if (!stack.length) cache.set(address, evaluated);
|
||||
return evaluated;
|
||||
}
|
||||
|
||||
export function evaluateTable(cells, dimensions) {
|
||||
const evaluated = {};
|
||||
const cache = new Map();
|
||||
for (let rowIndex = 0; rowIndex < dimensions.rows; rowIndex += 1) {
|
||||
for (let columnIndex = 0; columnIndex < dimensions.columns; columnIndex += 1) {
|
||||
const address = cellAddress(rowIndex, columnIndex);
|
||||
evaluated[address] = evaluateTableCell(address, cells, dimensions);
|
||||
evaluated[address] = evaluateTableCellWithCache(address, cells, dimensions, [], cache);
|
||||
}
|
||||
}
|
||||
return evaluated;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue