()
| 26 | checkData(); |
| 27 | |
| 28 | async function checkData() { |
| 29 | try { |
| 30 | const query = new URLSearchParams( |
| 31 | [ |
| 32 | ['key', key], |
| 33 | ['content', state.content.ts], |
| 34 | ['line', state.line.ts], |
| 35 | ].map((pair) => pair.map((s) => `${s}`)), |
| 36 | ); |
| 37 | const resp = await fetch(`/~data?${query}`); |
| 38 | if (!resp.ok) |
| 39 | throw { |
| 40 | status: resp.status, |
| 41 | }; |
| 42 | const res = (await resp.json()) as IFileState; |
| 43 | if (res.content) { |
| 44 | const value = res.content.value as ITransformResult; |
| 45 | mm.setOptions(markmap.deriveOptions(value.frontmatter?.markmap)); |
| 46 | await mm.setData(value.root); |
| 47 | if (!state.content.ts) await mm.fit(); |
| 48 | } |
| 49 | Object.assign(state, res); |
| 50 | if (res.line && state.content.value) { |
| 51 | await setCursor({ line: res.line.value as number }); |
| 52 | } |
| 53 | setTimeout(checkData); |
| 54 | } catch (err) { |
| 55 | if ((err as { status: number }).status !== 404) { |
| 56 | setTimeout(checkData, 1000); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function findActiveNode({ |
| 62 | line, |
no test coverage detected