(draftKey: string)
| 195 | * so an unedited migration is never lost. |
| 196 | */ |
| 197 | export function loadMessageInputDraftV2(draftKey: string): LoadedDraftV2 { |
| 198 | const cached = draftDocCache.get(draftKey) |
| 199 | if (cached) return { kind: "doc", doc: cached } |
| 200 | |
| 201 | if (typeof window !== "undefined") { |
| 202 | try { |
| 203 | const raw = localStorage.getItem(storageKeyForDraftKeyV2(draftKey)) |
| 204 | if (raw) { |
| 205 | const parsed = JSON.parse(raw) as Partial<PersistedDraftStateV2> |
| 206 | if (isTiptapDoc(parsed?.doc)) { |
| 207 | draftDocCache.set(draftKey, parsed.doc) |
| 208 | return { kind: "doc", doc: parsed.doc } |
| 209 | } |
| 210 | } |
| 211 | } catch { |
| 212 | // Fall through to the legacy v1 draft. |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | const legacy = loadMessageInputDraft(draftKey) |
| 217 | if (legacy != null && legacy.length > 0) { |
| 218 | return { kind: "legacyMarkdown", markdown: legacy } |
| 219 | } |
| 220 | return null |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Persist the composer document for a key (v2). The host calls this only for a |
no test coverage detected