@crombolo/content 0.79.1 → 0.80.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/workspace-merge-run.ts +44 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/content",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.80.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The rules every page, media and Library write follows, whoever starts it: who may, where it may go, approvals, and what it announces. No transport.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@crombolo/core": "0.
|
|
33
|
-
"@crombolo/data": "0.
|
|
32
|
+
"@crombolo/core": "0.80.1",
|
|
33
|
+
"@crombolo/data": "0.80.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -223,6 +223,12 @@ const KIND_OF: Record<string, (typeof KINDS)[number]> = {
|
|
|
223
223
|
[ObjectTypes.WorkspaceDocumentBlueprint]: 'blueprint',
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
const BINS: readonly number[] = [
|
|
227
|
+
SystemNodes.ContentRecycleBin,
|
|
228
|
+
SystemNodes.MediaRecycleBin,
|
|
229
|
+
SystemNodes.ElementRecycleBin,
|
|
230
|
+
]
|
|
231
|
+
|
|
226
232
|
async function planFor(
|
|
227
233
|
shared: DocumentRepository,
|
|
228
234
|
workspaces: WorkspaceRepository,
|
|
@@ -239,7 +245,9 @@ async function planFor(
|
|
|
239
245
|
if (!node) continue
|
|
240
246
|
const kind = KIND_OF[node.objectType ?? ''] ?? 'document'
|
|
241
247
|
p.objectKind = kind
|
|
242
|
-
|
|
248
|
+
// Story 430: a move recorded while the page stood in the bin takes it out.
|
|
249
|
+
const leaves = p.kind === 'move' && p.baseParentId !== null && BINS.includes(p.baseParentId)
|
|
250
|
+
if (!node.trashed || leaves)
|
|
243
251
|
where.set(p.nodeId, {
|
|
244
252
|
parentId: node.parentId,
|
|
245
253
|
head: await shared.ofKind(kind).sharedHeadEvent(node.id),
|
|
@@ -664,6 +672,27 @@ async function apply(
|
|
|
664
672
|
removed: ChangeItemInput[]
|
|
665
673
|
},
|
|
666
674
|
): Promise<void> {
|
|
675
|
+
const keyOf = async (id: number | null) =>
|
|
676
|
+
id === null || id === SystemNodes.Root ? null : ((await sharedAll.nodes.byId(id))?.key ?? null)
|
|
677
|
+
// Story 430: out of the recycle bin first, as a page in it cannot be published.
|
|
678
|
+
const outOfBin = new Map<
|
|
679
|
+
number,
|
|
680
|
+
{
|
|
681
|
+
from: { parentKey: string | null; trashed: boolean }
|
|
682
|
+
before: Awaited<ReturnType<DocumentRepository['eventMarkers']>>
|
|
683
|
+
}
|
|
684
|
+
>()
|
|
685
|
+
for (const { pending } of plan.pending) {
|
|
686
|
+
if (pending.kind !== 'move' || pending.key === null) continue
|
|
687
|
+
const shared = sharedAll.ofKind(pending.objectKind ?? 'document')
|
|
688
|
+
const node = await shared.nodes.byId(pending.nodeId)
|
|
689
|
+
if (!node?.trashed) continue
|
|
690
|
+
const from = { parentKey: await keyOf(node.parentId ?? null), trashed: true }
|
|
691
|
+
const before = await shared.eventMarkers(pending.key)
|
|
692
|
+
await shared.move(pending.key, await keyOf(pending.targetParentId))
|
|
693
|
+
await record({ type: 'moved', key: pending.key, from })
|
|
694
|
+
outOfBin.set(pending.nodeId, { from, before })
|
|
695
|
+
}
|
|
667
696
|
for (const pagePlan of plan.pages) {
|
|
668
697
|
const { page } = pagePlan
|
|
669
698
|
// Each kind through its own repository: pages, media, Library items (story 390).
|
|
@@ -718,8 +747,6 @@ async function apply(
|
|
|
718
747
|
})
|
|
719
748
|
}
|
|
720
749
|
|
|
721
|
-
const keyOf = async (id: number | null) =>
|
|
722
|
-
id === null || id === SystemNodes.Root ? null : ((await sharedAll.nodes.byId(id))?.key ?? null)
|
|
723
750
|
// Story 411: each parent's children's order before its first reorder, for the change.
|
|
724
751
|
const orders = new Map<string, { parentKey: string | null; before: string[] }>()
|
|
725
752
|
const childKeys = async (parentKey: string | null) =>
|
|
@@ -728,7 +755,8 @@ async function apply(
|
|
|
728
755
|
const key = pending.key
|
|
729
756
|
if (pending.kind === 'gone' || key === null) continue
|
|
730
757
|
const shared = sharedAll.ofKind(pending.objectKind ?? 'document')
|
|
731
|
-
const
|
|
758
|
+
const left = pending.kind === 'move' ? outOfBin.get(pending.nodeId) : undefined
|
|
759
|
+
const before = left ? left.before : await shared.eventMarkers(key)
|
|
732
760
|
// A delete takes the page's history with it: its change keeps the page as it stood (story 383).
|
|
733
761
|
// Story 411: so does one moved to the bin, which the bin may empty before the change is taken.
|
|
734
762
|
if (pending.kind === 'delete' || pending.kind === 'trash') {
|
|
@@ -744,18 +772,24 @@ async function apply(
|
|
|
744
772
|
}
|
|
745
773
|
if (pending.kind === 'move') {
|
|
746
774
|
const node = await shared.nodes.byId(pending.nodeId)
|
|
747
|
-
const from = {
|
|
775
|
+
const from = left?.from ?? {
|
|
748
776
|
parentKey: await keyOf(node?.parentId ?? null),
|
|
749
777
|
trashed: node?.trashed ?? false,
|
|
750
778
|
}
|
|
751
779
|
const to = await keyOf(pending.targetParentId)
|
|
752
|
-
|
|
753
|
-
|
|
780
|
+
if (!left) {
|
|
781
|
+
await shared.move(key, to)
|
|
782
|
+
await record({ type: 'moved', key, from })
|
|
783
|
+
}
|
|
754
784
|
const published = (await shared.byKey(key))?.published ?? false
|
|
755
785
|
out.removed.push(
|
|
756
786
|
placeItem(
|
|
757
787
|
key,
|
|
758
|
-
{
|
|
788
|
+
{
|
|
789
|
+
...from,
|
|
790
|
+
published: from.trashed ? false : published,
|
|
791
|
+
...(from.trashed ? { trashed: true } : {}),
|
|
792
|
+
},
|
|
759
793
|
{ parentKey: to, published },
|
|
760
794
|
),
|
|
761
795
|
)
|
|
@@ -767,7 +801,8 @@ async function apply(
|
|
|
767
801
|
await shared.sort(parentKey, [{ key, sortOrder: pending.sortOrder }])
|
|
768
802
|
await record({ type: 'sorted', parentKey })
|
|
769
803
|
} else if (pending.kind === 'trash') {
|
|
770
|
-
|
|
804
|
+
// One that went with its branch stays in it.
|
|
805
|
+
if (!(await shared.nodes.byId(pending.nodeId))?.trashed) await shared.moveToRecycleBin(key)
|
|
771
806
|
await record({ type: 'trashed', key })
|
|
772
807
|
} else if (pending.kind === 'delete') {
|
|
773
808
|
await shared.delete(key)
|