@lincyaw/workspace 1.0.0-rc.143 → 1.0.0-rc.144
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 +6 -6
- package/src/node/revisions.ts +54 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workspace",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.144",
|
|
4
4
|
"description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"mime-types": "3.0.2",
|
|
39
39
|
"playwright-chromium": "1.64.1",
|
|
40
40
|
"yaml": "^2.9.1",
|
|
41
|
-
"@lincyaw/compiler": "1.0.0-rc.
|
|
42
|
-
"@lincyaw/
|
|
43
|
-
"@lincyaw/
|
|
44
|
-
"@lincyaw/
|
|
41
|
+
"@lincyaw/compiler": "1.0.0-rc.144",
|
|
42
|
+
"@lincyaw/design": "1.0.0-rc.144",
|
|
43
|
+
"@lincyaw/kernel": "1.0.0-rc.144",
|
|
44
|
+
"@lincyaw/server": "1.0.0-rc.144"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/mime-types": "^3.0.1",
|
|
48
|
-
"@lincyaw/mcp": "1.0.0-rc.
|
|
48
|
+
"@lincyaw/mcp": "1.0.0-rc.144"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/node/revisions.ts
CHANGED
|
@@ -45,7 +45,50 @@ function revertedOf(message: string): string | undefined {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function finder(entries: LogEntry[]): (id: string) => LogEntry | undefined {
|
|
48
|
-
|
|
48
|
+
const full = new Map<string, LogEntry>()
|
|
49
|
+
let longest = 0
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (!full.has(entry.id)) full.set(entry.id, entry)
|
|
52
|
+
longest = Math.max(longest, entry.id.length)
|
|
53
|
+
}
|
|
54
|
+
const prefixes = new Map<number, Map<string, LogEntry>>()
|
|
55
|
+
return id => {
|
|
56
|
+
if (id.length < 7 || id.length >= longest) return full.get(id)
|
|
57
|
+
let index = prefixes.get(id.length)
|
|
58
|
+
if (!index) {
|
|
59
|
+
index = new Map()
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
const prefix = entry.id.slice(0, id.length)
|
|
62
|
+
if (!index.has(prefix)) index.set(prefix, entry)
|
|
63
|
+
}
|
|
64
|
+
prefixes.set(id.length, index)
|
|
65
|
+
}
|
|
66
|
+
return index.get(id)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Removes the most recent occurrence in constant time, retaining the order of all other revisions. */
|
|
71
|
+
function revisionStack() {
|
|
72
|
+
const values: (string | undefined)[] = []
|
|
73
|
+
const positions = new Map<string, number[]>()
|
|
74
|
+
return {
|
|
75
|
+
push(id: string) {
|
|
76
|
+
let indexes = positions.get(id)
|
|
77
|
+
if (!indexes) positions.set(id, indexes = [])
|
|
78
|
+
indexes.push(values.length)
|
|
79
|
+
values.push(id)
|
|
80
|
+
},
|
|
81
|
+
drop(id: string) {
|
|
82
|
+
const indexes = positions.get(id), at = indexes?.pop()
|
|
83
|
+
if (at !== undefined) values[at] = undefined
|
|
84
|
+
if (indexes?.length === 0) positions.delete(id)
|
|
85
|
+
},
|
|
86
|
+
clear() { values.length = 0; positions.clear() },
|
|
87
|
+
last() {
|
|
88
|
+
while (values.length && values.at(-1) === undefined) values.pop()
|
|
89
|
+
return values.at(-1)
|
|
90
|
+
},
|
|
91
|
+
}
|
|
49
92
|
}
|
|
50
93
|
|
|
51
94
|
function redoPredicate(entries: LogEntry[]): (entry: LogEntry) => boolean {
|
|
@@ -84,35 +127,32 @@ function undoTargets(entries: LogEntry[]): UndoTargets {
|
|
|
84
127
|
}
|
|
85
128
|
return current.id
|
|
86
129
|
}
|
|
87
|
-
const done
|
|
88
|
-
const undone
|
|
89
|
-
const drop = (stack: string[], id: string) => {
|
|
90
|
-
const at = stack.lastIndexOf(id)
|
|
91
|
-
if (at >= 0) stack.splice(at, 1)
|
|
92
|
-
}
|
|
130
|
+
const done = revisionStack()
|
|
131
|
+
const undone = revisionStack()
|
|
93
132
|
for (const entry of [...entries].reverse()) {
|
|
94
|
-
if (entry.root) { done.
|
|
133
|
+
if (entry.root) { done.clear(); undone.clear(); continue }
|
|
95
134
|
const origin = originOf(entry.message)
|
|
96
135
|
if (!origin) continue
|
|
97
136
|
if (origin.operation) {
|
|
98
|
-
done.
|
|
99
|
-
undone.
|
|
137
|
+
done.clear()
|
|
138
|
+
undone.clear()
|
|
100
139
|
continue
|
|
101
140
|
}
|
|
102
141
|
const reverted = revertedOf(entry.message)
|
|
103
142
|
const target = reverted === undefined ? undefined : find(reverted)
|
|
104
143
|
if (!target) {
|
|
105
144
|
done.push(entry.id)
|
|
106
|
-
undone.
|
|
145
|
+
undone.clear()
|
|
107
146
|
} else if (isRedo(entry)) {
|
|
108
|
-
drop(
|
|
147
|
+
undone.drop(target.id)
|
|
109
148
|
done.push(changeOf(target))
|
|
110
149
|
} else {
|
|
111
|
-
drop(
|
|
150
|
+
done.drop(changeOf(target))
|
|
112
151
|
undone.push(entry.id)
|
|
113
152
|
}
|
|
114
153
|
}
|
|
115
|
-
|
|
154
|
+
const undo = done.last(), redo = undone.last()
|
|
155
|
+
return { ...undo !== undefined ? { undo } : {}, ...redo !== undefined ? { redo } : {} }
|
|
116
156
|
}
|
|
117
157
|
|
|
118
158
|
function listed(entries: LogEntry[], filter: { task?: string, limit?: number }): HistoryRevision[] {
|