add multi-page notepad and memos toolbox tool
All checks were successful
Deploy Sokko G / deploy (push) Successful in 16s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 16s
This commit is contained in:
parent
fcabbe8029
commit
6125336338
33 changed files with 3787 additions and 138 deletions
43
website/src/features/toolboxes/storage/modules/memos.js
Normal file
43
website/src/features/toolboxes/storage/modules/memos.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Rôle : normalise et compacte les mémos courts des toolboxes.
|
||||
import { NOTEPAD_ALLOWED_COLORS } from "./drawing.js";
|
||||
import { normalizeIsoDate, uid } from "./shared.js";
|
||||
|
||||
const DEFAULT_MEMO_COLOR = "#f6c453";
|
||||
|
||||
function normalizeMemoItem(item) {
|
||||
const text = String(item?.text || "").trim();
|
||||
if (!text) return null;
|
||||
const color = NOTEPAD_ALLOWED_COLORS.has(String(item?.color || "").toLowerCase()) ? String(item.color).toLowerCase() : DEFAULT_MEMO_COLOR;
|
||||
return {
|
||||
id: item?.id || uid("memo"),
|
||||
text,
|
||||
color,
|
||||
updatedAt: normalizeIsoDate(item?.updatedAt)
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeMemosData(data) {
|
||||
const source = data && typeof data === "object" ? data : {};
|
||||
return {
|
||||
tickerEnabled: source.tickerEnabled !== false,
|
||||
items: (Array.isArray(source.items) ? source.items : []).map(normalizeMemoItem).filter(Boolean)
|
||||
};
|
||||
}
|
||||
|
||||
export function compactMemosDataForStorage(value) {
|
||||
const normalized = normalizeMemosData(value);
|
||||
const compact = {};
|
||||
if (normalized.tickerEnabled === false) compact.tickerEnabled = false;
|
||||
if (normalized.items.length) {
|
||||
compact.items = normalized.items.map((item) => {
|
||||
const compactItem = {
|
||||
id: item.id,
|
||||
text: item.text,
|
||||
color: item.color
|
||||
};
|
||||
if (item.updatedAt) compactItem.updatedAt = item.updatedAt;
|
||||
return compactItem;
|
||||
});
|
||||
}
|
||||
return Object.keys(compact).length ? compact : null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue