(position: number)
| 174 | ); |
| 175 | |
| 176 | async function addElement(position: number) { |
| 177 | // When an element is created, it should be a Resource that has this document as its parent. |
| 178 | // or maybe a nested resource? |
| 179 | const elementSubject = store.createSubject('element'); |
| 180 | elements.splice(position, 0, elementSubject); |
| 181 | try { |
| 182 | const newElement = new Resource(elementSubject, true); |
| 183 | await Promise.all([ |
| 184 | newElement.set(properties.isA, [classes.elements.paragraph], store), |
| 185 | newElement.set(properties.parent, resource.getSubject(), store), |
| 186 | newElement.set(properties.description, '', store), |
| 187 | ]); |
| 188 | // This is a dubious hack to make sure the element is instantly usable. |
| 189 | store.addResource(newElement); |
| 190 | // This makes things slow, but it prevents that an empty element is added to the store |
| 191 | newElement.save(store); |
| 192 | await setElements(elements); |
| 193 | focusElement(position); |
| 194 | // window.setTimeout(() => { |
| 195 | // focusElement(position); |
| 196 | // }, 10); |
| 197 | } catch (e) { |
| 198 | setErr(e); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | function focusElement(goto: number) { |
| 203 | if (goto > elements.length - 1) { |
no test coverage detected