2026-07-10 11:37:21 -04:00
|
|
|
import { Descendant } from 'slate';
|
|
|
|
|
import { toPlainText } from '../components/editor/output';
|
|
|
|
|
|
|
|
|
|
/** localStorage key prefix for a persisted composer draft (`draft-msg-<draftKey>`). */
|
|
|
|
|
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 {
|
2026-07-10 11:48:35 -04:00
|
|
|
try {
|
|
|
|
|
return toPlainText(draft, false).trim().length > 0;
|
|
|
|
|
} catch {
|
|
|
|
|
// A corrupted/foreign draft shape must never crash a render that calls this.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-07-10 11:37:21 -04:00
|
|
|
}
|