-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjectStore.js
More file actions
35 lines (31 loc) · 1.21 KB
/
objectStore.js
File metadata and controls
35 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
export function objectIdExistsInDoc(doc, objectId) {
if (!doc || !objectId) return false
return doc.allObjects.some((objects) => objects.some((obj) => obj.id === objectId))
}
export function findObjectPageIndex(doc, objectId) {
if (!doc || !objectId) return undefined
for (let pageIndex = 0; pageIndex < doc.allObjects.length; pageIndex++) {
if (doc.allObjects[pageIndex].some((obj) => obj.id === objectId)) {
return pageIndex
}
}
return undefined
}
export function updateObjectInDoc(doc, pageIndex, objectId, payload) {
const objects = doc?.allObjects?.[pageIndex]
if (!objects) return false
const objectIndex = objects.findIndex((obj) => obj.id === objectId)
if (objectIndex === -1) return false
objects.splice(objectIndex, 1, { ...objects[objectIndex], ...payload })
return true
}
export function removeObjectFromDoc(doc, pageIndex, objectId) {
const objects = doc?.allObjects?.[pageIndex]
if (!objects) return false
const objectIndex = objects.findIndex((obj) => obj.id === objectId)
if (objectIndex === -1) return false
objects.splice(objectIndex, 1)
return true
}