MCPcopy Create free account
hub / github.com/atomicdata-dev/atomic-data-browser / addElement

Function addElement

data-browser/src/views/DocumentPage.tsx:176–200  ·  view source on GitHub ↗
(position: number)

Source from the content-addressed store, hash-verified

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) {

Callers 3

DocumentPageEditFunction · 0.85
setElementFunction · 0.85
handleNewLineMaybeFunction · 0.85

Calls 6

setMethod · 0.95
saveMethod · 0.95
focusElementFunction · 0.85
createSubjectMethod · 0.80
getSubjectMethod · 0.80
addResourceMethod · 0.80

Tested by

no test coverage detected