import { Descendant } from 'slate'; import { toPlainText } from '../components/editor/output'; /** localStorage key prefix for a persisted composer draft (`draft-msg-`). */ export const DRAFT_MSG_KEY_PREFIX = 'draft-msg-'; /** * Whether a Slate composer draft holds real (non-whitespace) text, as opposed to * an empty editor (which is still a non-empty array of empty paragraphs). Shared * by the composer's DraftIndicator and the room-nav draft indicator. */ export function hasMsgDraft(draft: Descendant[]): boolean { try { return toPlainText(draft, false).trim().length > 0; } catch { // A corrupted/foreign draft shape must never crash a render that calls this. return false; } }