37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
// Rôle : regroupe les constantes et helpers DOM du Bloc Note riche.
|
|
export { DRAWING_COLORS as TEXT_COLORS, DRAWING_WIDTHS } from "../../../utils/drawingOptions.js";
|
|
export const HIGHLIGHT_COLORS = ["#f6c453", "#22d3ee", "#8b5cf6", "#d946ef", "#202745"];
|
|
|
|
export function getPlainText(element) {
|
|
return (element?.innerText || "").replace(/\n{3,}/g, "\n\n").trim();
|
|
}
|
|
|
|
export function isHtmlEmpty(html, text) {
|
|
return !text && !String(html || "").replace(/<br\s*\/?>/gi, "").replace(/<[^>]*>/g, "").replace(/ /gi, " ").trim();
|
|
}
|
|
|
|
export function formatUpdatedAt(value) {
|
|
if (!value) return "";
|
|
const date = new Date(value);
|
|
if (Number.isNaN(date.getTime())) return "";
|
|
return new Intl.DateTimeFormat("fr-FR", {
|
|
dateStyle: "short",
|
|
timeStyle: "short"
|
|
}).format(date);
|
|
}
|
|
|
|
export function queryCommandState(command) {
|
|
try {
|
|
return document.queryCommandState(command);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function queryBlockFormat() {
|
|
try {
|
|
return String(document.queryCommandValue("formatBlock") || "").replace(/[<>]/g, "").toLowerCase();
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|