Download this file
| 1 | const states = new Set(["saved", "saving", "retrying", "failed"]); |
| 2 | |
| 3 | export function mount(element) { |
| 4 | const texts = new Map([...states].map(state => [state, element.getAttribute(`data-text-${state}`) || ""])); |
| 5 | function setState(requested) { |
| 6 | const state = states.has(requested) ? requested : "idle"; |
| 7 | const text = texts.get(state) || ""; |
| 8 | if (element.getAttribute("data-state") !== state) element.setAttribute("data-state", state); |
| 9 | if (element.textContent !== text) element.textContent = text; |
| 10 | } |
| 11 | setState(element.getAttribute("data-state")); |
| 12 | return setState; |
| 13 | } |
| 14 | |