@musnows/scriverse 0.4.2 → 0.4.3
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/dist/app.js +23 -0
- package/dist/app.js.map +1 -1
- package/dist/collaboration-presence.js +75 -0
- package/dist/collaboration-presence.js.map +1 -0
- package/dist/public/app.js +461 -120
- package/dist/public/character-version.js +1 -1
- package/dist/public/display-labels.d.ts +16 -0
- package/dist/public/display-labels.js +81 -0
- package/dist/public/entity-version.js +5 -3
- package/dist/public/index.html +21 -10
- package/dist/public/page-route.js +3 -1
- package/dist/public/styles.css +90 -21
- package/dist/user-auth.js +2 -0
- package/dist/user-auth.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const presencePageKinds = [
|
|
2
|
+
"welcome",
|
|
3
|
+
"editor",
|
|
4
|
+
"module",
|
|
5
|
+
"entity-editor",
|
|
6
|
+
"settings"
|
|
7
|
+
];
|
|
8
|
+
const moduleLabels = {
|
|
9
|
+
settings: "设定库",
|
|
10
|
+
characters: "角色",
|
|
11
|
+
races: "种族",
|
|
12
|
+
organizations: "组织",
|
|
13
|
+
timeline: "时间轴",
|
|
14
|
+
relationships: "人物关系",
|
|
15
|
+
outlines: "大纲与伏笔",
|
|
16
|
+
reviews: "审核队列",
|
|
17
|
+
tasks: "AI 分析",
|
|
18
|
+
"ai-settings": "AI 设置"
|
|
19
|
+
};
|
|
20
|
+
const entityLabels = {
|
|
21
|
+
setting: "设定编辑",
|
|
22
|
+
character: "角色编辑",
|
|
23
|
+
race: "种族编辑",
|
|
24
|
+
organization: "组织编辑"
|
|
25
|
+
};
|
|
26
|
+
function normalizedPage(page) {
|
|
27
|
+
const module = String(page.module ?? "");
|
|
28
|
+
const resourceId = String(page.resourceId ?? "");
|
|
29
|
+
if (page.kind === "editor")
|
|
30
|
+
return { key: `editor:${resourceId}`, label: "正文编辑" };
|
|
31
|
+
if (page.kind === "entity-editor")
|
|
32
|
+
return { key: `entity-editor:${module}:${resourceId}`, label: entityLabels[module] ?? "资料编辑" };
|
|
33
|
+
if (page.kind === "module")
|
|
34
|
+
return { key: `module:${module}`, label: moduleLabels[module] ?? "作品模块" };
|
|
35
|
+
if (page.kind === "settings")
|
|
36
|
+
return { key: "settings", label: "设置中心" };
|
|
37
|
+
return { key: "welcome", label: "作品首页" };
|
|
38
|
+
}
|
|
39
|
+
export class CollaborationPresence {
|
|
40
|
+
timeoutMs;
|
|
41
|
+
now;
|
|
42
|
+
entries = new Map();
|
|
43
|
+
constructor(timeoutMs = 45_000, now = Date.now) {
|
|
44
|
+
this.timeoutMs = timeoutMs;
|
|
45
|
+
this.now = now;
|
|
46
|
+
}
|
|
47
|
+
heartbeat(workId, clientId, user, page) {
|
|
48
|
+
const now = this.now();
|
|
49
|
+
this.prune(now);
|
|
50
|
+
const normalized = normalizedPage(page);
|
|
51
|
+
this.entries.set(`${workId}:${clientId}`, {
|
|
52
|
+
workId,
|
|
53
|
+
clientId,
|
|
54
|
+
...user,
|
|
55
|
+
page: normalized,
|
|
56
|
+
lastSeenAt: new Date(now).toISOString(),
|
|
57
|
+
lastSeenMs: now
|
|
58
|
+
});
|
|
59
|
+
return this.list(workId, now);
|
|
60
|
+
}
|
|
61
|
+
list(workId, now) {
|
|
62
|
+
this.prune(now);
|
|
63
|
+
return [...this.entries.values()]
|
|
64
|
+
.filter((entry) => entry.workId === workId)
|
|
65
|
+
.sort((left, right) => right.lastSeenMs - left.lastSeenMs || left.displayName.localeCompare(right.displayName, "zh-CN"))
|
|
66
|
+
.map(({ workId: _workId, lastSeenMs: _lastSeenMs, ...participant }) => participant);
|
|
67
|
+
}
|
|
68
|
+
prune(now) {
|
|
69
|
+
for (const [key, entry] of this.entries) {
|
|
70
|
+
if (now - entry.lastSeenMs > this.timeoutMs)
|
|
71
|
+
this.entries.delete(key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=collaboration-presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collaboration-presence.js","sourceRoot":"","sources":["../src/collaboration-presence.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,eAAe;IACf,UAAU;CACF,CAAC;AA+BX,MAAM,YAAY,GAA2B;IAC3C,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,IAAI;IACX,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,KAAK;IACf,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,OAAO;CACvB,CAAC;AAEF,MAAM,YAAY,GAA2B;IAC3C,OAAO,EAAE,MAAM;IACf,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,MAAM;CACrB,CAAC;AAEF,SAAS,cAAc,CAAC,IAAkB;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;IACjD,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,UAAU,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAClF,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,MAAM,IAAI,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;IAClI,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,UAAU,MAAM,EAAE,EAAE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