Files
cinny/src/app/utils/draft.ts
T

20 lines
719 B
TypeScript
Raw Normal View History

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 {
try {
return toPlainText(draft, false).trim().length > 0;
} catch {
// A corrupted/foreign draft shape must never crash a render that calls this.
return false;
}
}