ryugi-artifacts 1.25.0 → 1.26.0
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/cli.cjs
CHANGED
|
@@ -367,6 +367,9 @@ function isCloudRecord(value) {
|
|
|
367
367
|
const { id, url, publishedAt, visibility } = value;
|
|
368
368
|
return typeof id === "string" && typeof url === "string" && (typeof publishedAt === "string" || publishedAt === null) && isVisibility(visibility);
|
|
369
369
|
}
|
|
370
|
+
function cloudRecord({ id, url, publishedAt, visibility, fingerprint }) {
|
|
371
|
+
return { id, url, publishedAt, visibility, ...typeof fingerprint === "string" ? { fingerprint } : {} };
|
|
372
|
+
}
|
|
370
373
|
function normalize(raw) {
|
|
371
374
|
const config2 = defaults();
|
|
372
375
|
if (typeof raw !== "object" || raw === null) return config2;
|
|
@@ -380,7 +383,7 @@ function normalize(raw) {
|
|
|
380
383
|
if (visibility !== void 0 && !isVisibility(visibility)) continue;
|
|
381
384
|
const entry = {};
|
|
382
385
|
if (visibility) entry.visibility = visibility;
|
|
383
|
-
if (isCloudRecord(cloud)) entry.cloud =
|
|
386
|
+
if (isCloudRecord(cloud)) entry.cloud = cloudRecord(cloud);
|
|
384
387
|
if (autoPublish2 === false) entry.autoPublish = false;
|
|
385
388
|
config2.artifacts[key] = entry;
|
|
386
389
|
}
|
|
@@ -922,7 +925,7 @@ async function main(argv) {
|
|
|
922
925
|
}, emit);
|
|
923
926
|
}
|
|
924
927
|
if (command === "--version" || command === "-v") {
|
|
925
|
-
console.log("1.
|
|
928
|
+
console.log("1.26.0");
|
|
926
929
|
return 0;
|
|
927
930
|
}
|
|
928
931
|
if (command === "--help" || command === "-h") {
|
package/dist/server.cjs
CHANGED
|
@@ -89270,6 +89270,9 @@ function isCloudRecord(value) {
|
|
|
89270
89270
|
const { id: id2, url, publishedAt, visibility } = value;
|
|
89271
89271
|
return typeof id2 === "string" && typeof url === "string" && (typeof publishedAt === "string" || publishedAt === null) && isVisibility(visibility);
|
|
89272
89272
|
}
|
|
89273
|
+
function cloudRecord({ id: id2, url, publishedAt, visibility, fingerprint }) {
|
|
89274
|
+
return { id: id2, url, publishedAt, visibility, ...typeof fingerprint === "string" ? { fingerprint } : {} };
|
|
89275
|
+
}
|
|
89273
89276
|
function normalize(raw) {
|
|
89274
89277
|
const config = defaults();
|
|
89275
89278
|
if (typeof raw !== "object" || raw === null) return config;
|
|
@@ -89283,7 +89286,7 @@ function normalize(raw) {
|
|
|
89283
89286
|
if (visibility !== void 0 && !isVisibility(visibility)) continue;
|
|
89284
89287
|
const entry = {};
|
|
89285
89288
|
if (visibility) entry.visibility = visibility;
|
|
89286
|
-
if (isCloudRecord(cloud)) entry.cloud =
|
|
89289
|
+
if (isCloudRecord(cloud)) entry.cloud = cloudRecord(cloud);
|
|
89287
89290
|
if (autoPublish2 === false) entry.autoPublish = false;
|
|
89288
89291
|
config.artifacts[key2] = entry;
|
|
89289
89292
|
}
|
|
@@ -89896,7 +89899,7 @@ var LOGIN_STATE_TTL_MS = 10 * 60 * 1e3;
|
|
|
89896
89899
|
var UPLOAD_CONCURRENCY = 6;
|
|
89897
89900
|
var MAX_JSON_BODY = 4096;
|
|
89898
89901
|
var CLOUD_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
89899
|
-
var ROUTE = /^\/api\/cloud\/(status|login|logout|artifacts|publish|reserve|visibility|auto-publish)(?:\/([^/]+)(?:\/([^/]+))?)?$/;
|
|
89902
|
+
var ROUTE = /^\/api\/cloud\/(status|login|logout|artifacts|publish|reserve|visibility|auto-publish|sync)(?:\/([^/]+)(?:\/([^/]+))?)?$/;
|
|
89900
89903
|
var SignedOut = class extends Error {
|
|
89901
89904
|
};
|
|
89902
89905
|
var CloudRefused = class extends Error {
|
|
@@ -89938,6 +89941,11 @@ async function errorMessage(res) {
|
|
|
89938
89941
|
return text2 || res.statusText;
|
|
89939
89942
|
}
|
|
89940
89943
|
}
|
|
89944
|
+
function fingerprintPayload(payload) {
|
|
89945
|
+
const versions = payload.versions;
|
|
89946
|
+
if (!versions) return payload;
|
|
89947
|
+
return { ...payload, versions: Object.fromEntries(Object.entries(versions).map(([file, version2]) => [file, version2 > 0])) };
|
|
89948
|
+
}
|
|
89941
89949
|
function createCloudRoutes(options) {
|
|
89942
89950
|
const { origin, credentialsFile: credentialsFile2, configFile, project } = options;
|
|
89943
89951
|
const settingsFile = settingsFileFor(credentialsFile2);
|
|
@@ -90015,22 +90023,43 @@ function createCloudRoutes(options) {
|
|
|
90015
90023
|
}
|
|
90016
90024
|
return artifactEntry(key2).cloud?.url ?? null;
|
|
90017
90025
|
};
|
|
90018
|
-
const
|
|
90026
|
+
const prepare = async (ref) => {
|
|
90019
90027
|
const inspected = await options.inspect(ref);
|
|
90020
90028
|
if (!inspected) throw new CloudRefused(404, `${ref.type}/${ref.id} not found`);
|
|
90021
|
-
if (inspected.reasons.length > 0 || !inspected.payload) return {
|
|
90022
|
-
let
|
|
90029
|
+
if (inspected.reasons.length > 0 || !inspected.payload) return { ready: false, reasons: inspected.reasons };
|
|
90030
|
+
let packed;
|
|
90023
90031
|
try {
|
|
90024
|
-
|
|
90032
|
+
packed = packArtifact(inspected.dir, ref.type);
|
|
90025
90033
|
} catch (err) {
|
|
90026
90034
|
throw new CloudRefused(413, err.message);
|
|
90027
90035
|
}
|
|
90036
|
+
const sha = (data) => import_node_crypto6.default.createHash("sha256").update(data).digest("hex");
|
|
90037
|
+
const hashed = withCloudRuntime(ref.type, packed).map((file) => ({ ...file, hash: sha(file.data) }));
|
|
90038
|
+
const content = { title: inspected.title, payload: inspected.payload, files: hashed.map(({ path: path22, hash }) => ({ path: path22, hash })) };
|
|
90039
|
+
const fingerprint = sha(JSON.stringify({ title: inspected.title, payload: fingerprintPayload(inspected.payload), files: packed.map((file) => ({ path: file.path, hash: sha(file.data) })) }));
|
|
90040
|
+
return { ready: true, hashed, content, fingerprint };
|
|
90041
|
+
};
|
|
90042
|
+
const upToDate = async (ref) => {
|
|
90043
|
+
const cloud = artifactEntry(`${ref.type}/${ref.id}`).cloud;
|
|
90044
|
+
if (!cloud?.publishedAt) {
|
|
90045
|
+
if (!await options.inspect(ref)) throw new CloudRefused(404, `${ref.type}/${ref.id} not found`);
|
|
90046
|
+
return null;
|
|
90047
|
+
}
|
|
90048
|
+
const prepared = await prepare(ref);
|
|
90049
|
+
return prepared.ready ? prepared.fingerprint === cloud.fingerprint : null;
|
|
90050
|
+
};
|
|
90051
|
+
const publish = async (ref, requested, { recreate = true, skipUnchanged = false } = {}) => {
|
|
90052
|
+
const prepared = await prepare(ref);
|
|
90053
|
+
if (!prepared.ready) return { status: 409, body: { error: "fix these before publishing", reasons: prepared.reasons } };
|
|
90054
|
+
const { hashed, content, fingerprint } = prepared;
|
|
90028
90055
|
const key2 = `${ref.type}/${ref.id}`;
|
|
90029
90056
|
const entry = artifactEntry(key2);
|
|
90030
|
-
const
|
|
90057
|
+
const current = entry.cloud;
|
|
90058
|
+
if (skipUnchanged && current?.publishedAt && current.fingerprint === fingerprint) {
|
|
90059
|
+
return { status: 200, body: { id: current.id, url: current.url, visibility: current.visibility, publishedAt: current.publishedAt } };
|
|
90060
|
+
}
|
|
90031
90061
|
const byHash = new Map(hashed.map((file) => [file.hash, file.data]));
|
|
90032
|
-
const
|
|
90033
|
-
const version2 = (visibility) => ({ title: inspected.title, payload: inspected.payload, files: manifest, project, ...visibility ? { visibility } : {} });
|
|
90062
|
+
const version2 = (visibility) => ({ ...content, project, ...visibility ? { visibility } : {} });
|
|
90034
90063
|
const create3 = () => createRecord2(ref, requested ?? entry.visibility ?? "private");
|
|
90035
90064
|
const upload = async (id2, hashes) => {
|
|
90036
90065
|
for (let i6 = 0; i6 < hashes.length; i6 += UPLOAD_CONCURRENCY) {
|
|
@@ -90059,7 +90088,7 @@ function createCloudRoutes(options) {
|
|
|
90059
90088
|
const published = await (await expectOk(res)).json();
|
|
90060
90089
|
updateArtifactConfig(configFile, key2, {
|
|
90061
90090
|
visibility: published.visibility,
|
|
90062
|
-
cloud: { id: published.id, url: published.url, publishedAt: published.updatedAt, visibility: published.visibility }
|
|
90091
|
+
cloud: { id: published.id, url: published.url, publishedAt: published.updatedAt, visibility: published.visibility, fingerprint }
|
|
90063
90092
|
});
|
|
90064
90093
|
return { status: 200, body: { id: published.id, url: published.url, visibility: published.visibility, publishedAt: published.updatedAt } };
|
|
90065
90094
|
};
|
|
@@ -90099,7 +90128,7 @@ function createCloudRoutes(options) {
|
|
|
90099
90128
|
const entry = artifactEntry(key2);
|
|
90100
90129
|
if (entry.autoPublish === false) return { kind: "opted-out" };
|
|
90101
90130
|
try {
|
|
90102
|
-
const result = await publish(ref, void 0, { recreate: false });
|
|
90131
|
+
const result = await publish(ref, void 0, { recreate: false, skipUnchanged: true });
|
|
90103
90132
|
if (result.status !== 200) return { kind: "not-ready" };
|
|
90104
90133
|
return { kind: "published", created: result.body.id !== entry.cloud?.id };
|
|
90105
90134
|
} catch (err) {
|
|
@@ -90162,6 +90191,10 @@ function createCloudRoutes(options) {
|
|
|
90162
90191
|
sendJson(res, result.status, result.body);
|
|
90163
90192
|
return;
|
|
90164
90193
|
}
|
|
90194
|
+
if (action === "sync" && ref && method === "GET") {
|
|
90195
|
+
sendJson(res, 200, { upToDate: await serialized(`${ref.type}/${ref.id}`, () => upToDate(ref)) });
|
|
90196
|
+
return;
|
|
90197
|
+
}
|
|
90165
90198
|
if (action === "reserve" && ref && method === "POST") {
|
|
90166
90199
|
sendJson(res, 200, { url: await serialized(`${ref.type}/${ref.id}`, () => reserve(ref)) });
|
|
90167
90200
|
return;
|
|
@@ -90398,6 +90431,8 @@ function allowInlineScripts(csp, html) {
|
|
|
90398
90431
|
// src/server/auto-publish.ts
|
|
90399
90432
|
var import_node_crypto8 = __toESM(require("node:crypto"), 1);
|
|
90400
90433
|
var import_node_fs20 = __toESM(require("node:fs"), 1);
|
|
90434
|
+
var IDLE_MS = 5 * 60 * 1e3;
|
|
90435
|
+
var MAX_WAIT_MS = 15 * 60 * 1e3;
|
|
90401
90436
|
var SIGNED_OUT_MESSAGE = "auto-publish paused: the Ryugi Cloud sign-in expired";
|
|
90402
90437
|
function isNotice(value) {
|
|
90403
90438
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -90429,7 +90464,20 @@ function createAutoPublisher(options) {
|
|
|
90429
90464
|
const raise = (kind, message) => {
|
|
90430
90465
|
if (notice?.kind !== kind) notice = { id: import_node_crypto8.default.randomUUID(), kind, message };
|
|
90431
90466
|
};
|
|
90467
|
+
let idleTimer = null;
|
|
90468
|
+
let maxTimer = null;
|
|
90469
|
+
const clearTimers = () => {
|
|
90470
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
90471
|
+
if (maxTimer) clearTimeout(maxTimer);
|
|
90472
|
+
idleTimer = maxTimer = null;
|
|
90473
|
+
};
|
|
90474
|
+
const schedule = () => {
|
|
90475
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
90476
|
+
idleTimer = setTimeout(() => void flush(), options.idleMs ?? IDLE_MS).unref();
|
|
90477
|
+
maxTimer ??= setTimeout(() => void flush(), options.maxWaitMs ?? MAX_WAIT_MS).unref();
|
|
90478
|
+
};
|
|
90432
90479
|
const run2 = async () => {
|
|
90480
|
+
clearTimers();
|
|
90433
90481
|
if (!options.enabled() || dirty.size === 0) return;
|
|
90434
90482
|
const token = options.token();
|
|
90435
90483
|
if (paused && paused.token === token) return;
|
|
@@ -90437,6 +90485,7 @@ function createAutoPublisher(options) {
|
|
|
90437
90485
|
paused = null;
|
|
90438
90486
|
if (notice?.kind === "signed-out") notice = null;
|
|
90439
90487
|
}
|
|
90488
|
+
let retry = false;
|
|
90440
90489
|
for (const key2 of [...dirty]) {
|
|
90441
90490
|
remarked.delete(key2);
|
|
90442
90491
|
const outcome = await options.publish(key2);
|
|
@@ -90446,15 +90495,19 @@ function createAutoPublisher(options) {
|
|
|
90446
90495
|
break;
|
|
90447
90496
|
}
|
|
90448
90497
|
if (outcome.kind === "published") {
|
|
90449
|
-
if (
|
|
90498
|
+
if (remarked.has(key2)) retry = true;
|
|
90499
|
+
else dirty.delete(key2);
|
|
90450
90500
|
if (outcome.created && notice?.kind === "cap") notice = null;
|
|
90451
90501
|
} else if (outcome.kind === "opted-out" || outcome.kind === "gone") {
|
|
90452
90502
|
dirty.delete(key2);
|
|
90453
90503
|
} else if (outcome.kind === "cannot-create") {
|
|
90454
90504
|
raise("cap", outcome.message);
|
|
90505
|
+
} else {
|
|
90506
|
+
retry = true;
|
|
90455
90507
|
}
|
|
90456
90508
|
}
|
|
90457
90509
|
save();
|
|
90510
|
+
if (retry) schedule();
|
|
90458
90511
|
};
|
|
90459
90512
|
let running = null;
|
|
90460
90513
|
let queued = null;
|
|
@@ -90471,18 +90524,21 @@ function createAutoPublisher(options) {
|
|
|
90471
90524
|
});
|
|
90472
90525
|
return queued;
|
|
90473
90526
|
};
|
|
90527
|
+
if (dirty.size > 0) schedule();
|
|
90474
90528
|
return {
|
|
90475
90529
|
changed(key2) {
|
|
90476
90530
|
if (!options.enabled()) return;
|
|
90477
90531
|
dirty.add(key2);
|
|
90478
90532
|
remarked.add(key2);
|
|
90479
90533
|
save();
|
|
90534
|
+
schedule();
|
|
90480
90535
|
},
|
|
90481
90536
|
removed(key2) {
|
|
90482
90537
|
if (!dirty.delete(key2)) return;
|
|
90483
90538
|
save();
|
|
90484
90539
|
},
|
|
90485
|
-
flush
|
|
90540
|
+
flush,
|
|
90541
|
+
close: clearTimers
|
|
90486
90542
|
};
|
|
90487
90543
|
}
|
|
90488
90544
|
|
|
@@ -90709,7 +90765,19 @@ async function startArtifactsServer(options) {
|
|
|
90709
90765
|
return { dir, title, reasons, payload: published };
|
|
90710
90766
|
};
|
|
90711
90767
|
const cloud = options.cloud && options.configFile ? createCloudRoutes({ ...options.cloud, configFile: options.configFile, project: import_node_path20.default.basename(import_node_path20.default.resolve(root, "../..")), port: () => port, inspect }) : null;
|
|
90712
|
-
const autoPublisher = cloud ? createAutoPublisher({
|
|
90768
|
+
const autoPublisher = cloud ? createAutoPublisher({
|
|
90769
|
+
stateFile: import_node_path20.default.join(stateDir, "auto-publish.json"),
|
|
90770
|
+
enabled: cloud.autoPublishEnabled,
|
|
90771
|
+
token: cloud.token,
|
|
90772
|
+
publish: async (key2) => {
|
|
90773
|
+
const outcome = await cloud.autoPublish(key2);
|
|
90774
|
+
if (outcome.kind === "published") {
|
|
90775
|
+
const frame = textFrame(JSON.stringify({ type: "cloud-published", artifact: key2 }));
|
|
90776
|
+
for (const socket of clients) socket.write(frame);
|
|
90777
|
+
}
|
|
90778
|
+
return outcome;
|
|
90779
|
+
}
|
|
90780
|
+
}) : null;
|
|
90713
90781
|
const sameOrigin = (req) => {
|
|
90714
90782
|
const origin2 = req.headers.origin;
|
|
90715
90783
|
const host = req.headers.host ?? "";
|
|
@@ -91366,6 +91434,7 @@ async function startArtifactsServer(options) {
|
|
|
91366
91434
|
onActivity: (listener) => activityListeners.push(listener),
|
|
91367
91435
|
close: () => new Promise((resolve) => {
|
|
91368
91436
|
watcher.close();
|
|
91437
|
+
autoPublisher?.close();
|
|
91369
91438
|
relay?.close();
|
|
91370
91439
|
direct.close();
|
|
91371
91440
|
selections.clearAll();
|
|
@@ -91472,7 +91541,7 @@ function openReady(payload) {
|
|
|
91472
91541
|
}
|
|
91473
91542
|
|
|
91474
91543
|
// package.json
|
|
91475
|
-
var version = "1.
|
|
91544
|
+
var version = "1.26.0";
|
|
91476
91545
|
|
|
91477
91546
|
// src/server/main.ts
|
|
91478
91547
|
async function main() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{n as t,t as n}from"./jsx-runtime-CldxteV5.js";import{a as r}from"./useSandboxFrame-8NPM2cx_.js";import{t as i}from"./index.js";import a from"./CloudDocument-DbBCNw2D.js";import{DocumentView as o,t as s}from"./DocumentPage-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{n as t,t as n}from"./jsx-runtime-CldxteV5.js";import{a as r}from"./useSandboxFrame-8NPM2cx_.js";import{t as i}from"./index.js";import a from"./CloudDocument-DbBCNw2D.js";import{DocumentView as o,t as s}from"./DocumentPage-xPmcnWV1.js";var c=e(t(),1),l=`1.26.0`,u=e=>/^(\d+)\.(\d+)\./.exec(e??``)?.slice(1,3).join(`.`)??null;function d(e,t){let n=u(e);return n!==null&&n===u(t)}var f=(e,t)=>`电脑上的 ryugi 是 ${t??`未知版本`},网页是 ${e},版本对上之前只能评论`,p=n();function m({id:e,state:t,contentBase:n,liveContentBase:u,comments:m}){let{transport:h,presence:g}=s(e,u??n??``),_=g?.online??!1;r(e,{online:g?.online??null});let[v,y]=(0,c.useState)(!1);if((0,c.useEffect)(()=>{_&&y(!0)},[_]),!h||!(v||_))return!t||!n?(0,p.jsx)(i,{children:g===null?`正在连接…`:`还没发布。电脑在线时,这里会实时显示。`}):(0,p.jsx)(a,{id:e,state:t,contentBase:n,comments:m,offline:g!==null&&!_});let b=_&&d(l,g?.version??null),x=_&&!b?f(l,g?.version??null):null;return(0,p.jsx)(o,{id:e,transport:h,live:_,cloud:{online:_,canEdit:b,reason:x}})}export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{n as t,t as n}from"./jsx-runtime-CldxteV5.js";import{S as r,_ as i,a,b as o,f as s,hi as c,ka as l,l as u,o as d,p as f,x as p,y as m}from"./useSandboxFrame-8NPM2cx_.js";import{C as h,S as g,_,a as v,b as y,c as b,g as x,h as S,i as C,l as w,m as ee,n as te,o as ne,p as re,pn as T,r as E,s as ie,t as ae,u as oe,x as D}from"./DocumentLayout-Ds9A-4Ya.js";import{a as se,c as O,d as k,f as A,i as j,l as M,n as N,o as ce,r as P,s as F,u as le}from"./index.js";var I={name:`message-square`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]};I.node;var L=c(I),R=e(t(),1);function ue({streaming:e,pending:t,agentActiveAt:n,now:r}){if(e)return{kind:`editing`};if(t===0)return{kind:`idle`};if(n===void 0)return{kind:`working`,pending:t,idleMs:null};let i=Math.max(0,r-n);return i>3e5?{kind:`stale`,pending:t,idleMs:i}:{kind:`working`,pending:t,idleMs:i}}function z(e){return e<6e4?`${Math.floor(e/1e3)} 秒`:e<36e5?`${Math.floor(e/6e4)} 分钟`:`${Math.floor(e/36e5)} 小时`}function B(e,t,n){switch(e.kind){case`editing`:return`${t} 正在编辑${n?` ${n}`:``}`;case`idle`:return null;case`working`:{let n=`${t} 还有 ${e.pending} 节待写`;return e.idleMs===null?n:`${n} · ${e.idleMs<1e4?`刚刚`:`${z(e.idleMs)}前`}更新`}case`stale`:return`${t} ${z(e.idleMs)}没有更新 · 还有 ${e.pending} 节待写`}}var V=n();function H({left:e,top:t,quote:n,initial:r,restored:a,leaving:o,onChange:s,onSubmit:c,onCancel:l,ref:u}){return(0,V.jsx)(`div`,{ref:u,...{0:{className:`x10l6tqk x1u8a7rm xj6ak53 xowlrko xllfotl xatqbsq x1u6ievf`},1:{className:`x10l6tqk x1u8a7rm xj6ak53 x1u6ievf xxp0q0x x12l1aco xn0cd8s x47corl`}}[!!o|0],style:{left:e,top:t},children:(0,V.jsxs)(te,{active:!0,children:[(0,V.jsxs)(`div`,{className:`x78zum5 x1pha0wt x167g77z xz9dl7a x1hr3lfm xqfszdh x1j6dyjg`,children:[(0,V.jsxs)(`span`,{className:`x98rzlu xeuugli xb3r6kr xuxw1ft xlyipyv xddlp02`,children:[`“`,n,`”`]}),a?(0,V.jsx)(`span`,{className:`x2lah0s x7zghnd`,children:`已恢复上次的草稿`}):null]}),(0,V.jsx)(i,{autoFocus:!0,initial:r,placeholder:`写下你的问题或意见…`,onChange:s,onSubmit:c,onCancel:l})]})})}function U({left:e,top:t,onComment:n,onCopy:r,ref:i}){return(0,V.jsxs)(`div`,{ref:i,className:`x10l6tqk x1u8a7rm x78zum5 x6s0dn4 x195vfkc xc9qbxq x9f619 x9ms5i6 xmkeg23 x1y0btm7 xgcsv5v x1q4ynmn x12ilycc x1d5q07e xi1bcxy x773k2o xa3vuyk`,style:{left:e,top:t},onMouseDown:e=>e.preventDefault(),children:[n?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`button`,{type:`button`,onClick:n,className:`x78zum5 x6s0dn4 x17d4w8g x1fgtraw xt970qd x1awh872 xc342km xu4hgxq xjbqb8w xj0l527 x2230gt xo2rkog xqfszdh xfifm61 xk50ysn x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x1fkwv27`,children:[(0,V.jsx)(L,{size:14,className:`x2lah0s x17nrqe2`}),`评论`]}),(0,V.jsx)(`span`,{"aria-hidden":`true`,className:`x2lah0s x1i1rx1s xlup9mm xj3msbq xcn5yip`})]}):null,(0,V.jsx)(`button`,{type:`button`,onClick:r,className:`x78zum5 x6s0dn4 x17d4w8g x1fgtraw xt970qd x1awh872 xc342km xu4hgxq xjbqb8w xj0l527 x2230gt xqfszdh xfifm61 xk50ysn x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x1fkwv27 x1bo0w0s`,children:`复制`})]})}var W=(e,t)=>`${e}\n${t}`;function de(){let e=new Map;return{save(t,n){n.trim()?e.set(t,n):e.delete(t)},take(t){return e.get(t)??``}}}function fe(e){let t=(0,R.useMemo)(de,[]),[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1),o=(0,R.useRef)(``),s=(0,R.useRef)(0),c=(0,R.useRef)(null),l=(0,R.useRef)(null);v(i?null:n?.target.range??null);let u=(0,R.useCallback)(n=>{window.clearTimeout(s.current);let i=t.take(W(n.blockId,n.quote));o.current=i,a(!1),r({target:n,initial:i}),window.getSelection()?.removeAllRanges(),e()},[t,e]),d=(0,R.useCallback)(e=>{n&&(t.save(W(n.target.blockId,n.target.quote),e?o.current:``),a(!0),s.current=window.setTimeout(()=>{r(null),a(!1)},120))},[n,t]);return(0,R.useEffect)(()=>{if(!n||i)return;let e=e=>{let t=e.target;c.current?.contains(t)||l.current?.contains(t)||d(!0)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[n,i,d]),(0,R.useEffect)(()=>()=>window.clearTimeout(s.current),[]),{draft:n,leaving:i,restored:!!n?.initial,open:u,close:d,onText:e=>{o.current=e},panelRef:c,toolbarRef:l}}function G(e){return{left:e.offsetLeft,right:Math.min(e.offsetLeft+e.offsetWidth,window.innerWidth-16)}}function pe({editor:e,threads:t,actions:n,agent:r,canComment:i,selection:a,clearSelection:o,onCreate:s,onMain:c,children:l}){let u=fe(o),{draft:d}=u;return(0,V.jsx)(ae,{editor:e,threads:t,actions:n,agent:r,onMain:c,overlay:e=>(0,V.jsxs)(V.Fragment,{children:[a&&!d?(0,V.jsx)(U,{ref:u.toolbarRef,...w(a,G(e),128,36,8),onComment:i?()=>u.open(a):void 0,onCopy:()=>{navigator.clipboard?.writeText(a.quote),window.getSelection()?.removeAllRanges(),o()}}):null,d?(0,V.jsx)(H,{ref:u.panelRef,...b(d.target,G(e),340,8),quote:d.target.quote,initial:d.initial,restored:u.restored,leaving:u.leaving,onChange:u.onText,onSubmit:e=>s(d.target,e).then(e=>(e&&u.close(!1),e)),onCancel:()=>u.close(!0)},`${d.target.blockId}:${d.target.quote}`):null]}),children:l})}function me({id:e,title:t,activity:n,agentSection:r,offline:i,openComments:o,cloud:s,compact:c=!1,onDone:l,agent:u=`Agent`}){let d=B(n,u,r);return a(e,s?{...t?{title:t}:{},online:s.online,comments:o,activity:d,activityTone:n.kind===`stale`?`warning`:n.kind===`working`?`quiet`:`live`,retrying:i,reason:s.reason}:null)&&!c?null:(0,V.jsxs)(`header`,{...{0:{className:`x7wzq59 x13vifvy x1n327nk xdd8jsf x78zum5 x6s0dn4 x1v2ro7d x4l9tsp x1rozbrz xqfszdh`},1:{className:`x7wzq59 x13vifvy x1n327nk xdd8jsf x78zum5 x6s0dn4 x1rozbrz xqfszdh x1hr3lfm x883omv`}}[!!c|0],children:[c?null:(0,V.jsxs)(`span`,{className:`xddlp02 xfifm61 xuxw1ft`,children:[`document / `,(0,V.jsx)(`span`,{className:`xo2rkog x1s688f`,children:e})]}),d?(0,V.jsxs)(`span`,{...{0:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla xlssvyo x19ay2w6 x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv`},2:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xahzvm9 x1bo0w0s`},1:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xqdcvd7 x7zghnd`},3:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xqdcvd7 x7zghnd`}}[(n.kind===`working`)<<1|n.kind===`stale`],children:[n.kind===`stale`?null:(0,V.jsx)(`i`,{className:`x1v4s8kt xols6we x16rqkct xtwfq29`}),d]}):null,i?(0,V.jsx)(`span`,{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xqdcvd7 x7zghnd`,children:`未同步,正在重试`}):null,s?.reason&&!c?(0,V.jsx)(`span`,{className:`xb3r6kr xddlp02 xfifm61 xuxw1ft xlyipyv`,children:s.reason}):null,(0,V.jsx)(`span`,{className:`x98rzlu`}),s?(0,V.jsxs)(`span`,{className:`x78zum5 x6s0dn4 x17d4w8g x1bo0w0s xfifm61 xuxw1ft`,children:[(0,V.jsx)(`i`,{...{0:{className:`xci0xqf x1hagigm x16rqkct xxwmxtg`},1:{className:`xci0xqf x1hagigm x16rqkct xux1nz0`}}[!!s.online|0]}),s.online?`电脑在线`:`电脑离线`]}):null,c?null:(0,V.jsxs)(`span`,{className:`xddlp02 xfifm61 xuxw1ft`,children:[`评论 `,o]}),l?(0,V.jsx)(`button`,{type:`button`,onClick:l,className:`x12ulsxz xaope02 xc342km x1kogg8i x19ckca5 xs0jrwl xqfszdh x4z9k3i x1s688f x1ypdohk`,children:`完成`}):s||c?null:(0,V.jsx)(A,{artifact:`document/${e}`})]})}function K(e,t,n){let[r,i]=t<=n?[t,n]:[n,t];return{blockIds:e.slice(r,i+1).flatMap(e=>e.id?[e.id]:[]).slice(0,M.blockIds),heading:e.slice(0,r+1).filter(e=>e.heading).pop()?.text??``}}var q=crypto.randomUUID(),J=300,Y={quote:``,blockIds:[],heading:``};function he(e){let t=window.getSelection(),n=e.getRootElement();if(!t||t.isCollapsed||!n?.contains(t.anchorNode)||!n.contains(t.focusNode))return Y;let r=t.toString().trim().slice(0,M.quote);return r?e.read(()=>{let e=g().getChildren(),n=t=>{let n=t&&D(t)?.getTopLevelElement();return n?e.findIndex(e=>e.is(n)):-1},i=n(t.anchorNode),a=n(t.focusNode);if(i<0||a<0)return{...Y,quote:r};let o=e.map(e=>({id:h(e,y)||``,heading:e.getType()===`heading`,text:e.getTextContent().slice(0,M.heading)}));return{quote:r,...K(o,i,a)}}):Y}function ge(e,t,n,r){let i=(0,R.useRef)(Y);(0,R.useEffect)(()=>{if(!e)return;let n=0,a=()=>{let n=he(e);JSON.stringify(n)!==JSON.stringify(i.current)&&(i.current=n,r({type:`selection`,artifact:t,tab:q,human:!0,...n}))},o=()=>{clearTimeout(n),n=window.setTimeout(a,J)};return document.addEventListener(`selectionchange`,o),()=>{clearTimeout(n),document.removeEventListener(`selectionchange`,o)}},[e,t,r]),(0,R.useEffect)(()=>{n&&i.current.quote&&r({type:`selection`,artifact:t,tab:q,human:!1,...i.current})},[n,t,r])}var X=[`pending`],_e=`x-ryugi-document-features`,ve=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)};function ye({id:e,channel:t,send:n}){let r=(t,n,r)=>fetch(`/api/document/${e}/${t}`,{method:`POST`,headers:{"Content-Type":r,[_e]:X.join(`,`)},body:n});return{artifact:`document/${e}`,channel:t,send:n,async meta(){let t=await fetch(`/api/artifacts/document/${e}`,{cache:`no-store`});return t.ok?await t.json():null},async state(){let t=await fetch(`/api/document/${e}/state`,{cache:`no-store`}),n=await t.json();if(!t.ok||!n.snapshot)throw Error(n.error??`load failed (${t.status})`);return n},async update(e){let t=await r(`update`,e,`application/octet-stream`);if(!t.ok)throw Error(`update failed (${t.status})`)},async comment(e){let t=await r(`comments`,JSON.stringify(e),`application/json`);if(!t.ok)throw Error(`comment failed (${t.status})`);return(await t.json()).comments}}}function be(e){let t=_(),n=(e.connect??j)({url:e.url,artifact:e.artifact,WebSocket:e.WebSocket,retryMs:e.retryMs,onPresence:e.onPresence,onEvent:e=>t.emit(e),onOnline:()=>t.emit({type:`open`})});return{artifact:e.artifact,channel:t,close:n.close,async meta(){let t=await n.request({op:`meta`});return/^https?:\/\//.test(t.contentBase??``)?t:{...t,contentBase:e.contentBase}},state:()=>n.request({op:`state`}),async update(e){await n.request({op:`update`,bytes:ve(e),features:X})},async comment(e){return(await n.request({op:`comment`,comment:e})).comments},send(e){let{type:t}=e;t===`selection`?n.request({op:`selection`,selection:e}).catch(()=>{}):(t===`loaded`||t===`runtime-error`)&&n.request({op:`client`,message:e}).catch(()=>{})}}}function xe(e){let t=(0,R.useMemo)(_,[]),n=`document/${e}`,{live:r,send:i}=k(e=>{e.artifact===n&&t.emit(e)},()=>t.emit({type:`open`}));return{transport:(0,R.useMemo)(()=>ye({id:e,channel:t,send:i}),[e,t,i]),live:r}}function Se(e,t){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(null);return(0,R.useEffect)(()=>{let n=be({url:N(e),artifact:`document/${e}`,contentBase:t,onPresence:a,connect:t=>P({...t,cloudId:e,known:se()})});return r(n),()=>{n.close(),r(null),a(null)}},[e,t]),{transport:n,presence:i}}var Ce={count:0,firstKey:null},we=e=>e.read(()=>{let e=g().getChildren().filter(e=>e.getType()===`pending`).map(e=>e.getKey());return{count:e.length,firstKey:e[0]??null}});function Te(e){let[t,n]=(0,R.useState)(Ce);return(0,R.useEffect)(()=>{if(!e){n(Ce);return}let t=e=>n(t=>t.count===e.count&&t.firstKey===e.firstKey?t:e);return t(we(e.getEditorState())),e.registerUpdateListener(({editorState:e})=>t(we(e)))},[e]),t}function Ee(e,t=15e3){let[n,r]=(0,R.useState)(()=>Date.now());return(0,R.useEffect)(()=>{if(!e)return;r(Date.now());let n=setInterval(()=>r(Date.now()),t);return()=>clearInterval(n)},[e,t]),n}function De({left:e,top:t,placement:n,canComment:r,canEdit:i,onComment:a,onEdit:o}){let s=(0,R.useRef)(null),c=[r?{label:`评论`,Icon:L,run:a,primary:!0}:null,i?{label:`改字`,Icon:T,run:o,primary:!1}:null].filter(e=>e!==null);return(0,R.useLayoutEffect)(()=>{u(s.current,[{opacity:0,transform:`scale(0.96)`},{opacity:1,transform:`none`}],{duration:160,easing:d})},[]),c.length===0?null:(0,V.jsxs)(`div`,{ref:s,"data-edit-menu":!0,"data-placement":n,...{0:{className:`x10l6tqk x1u8a7rm x78zum5 xdt5ytf x1cy8zhl`},1:{className:`x10l6tqk x1u8a7rm x78zum5 x1cy8zhl x3ieub6`}}[n===`above`|0],style:{left:e,top:t,transformOrigin:n===`above`?`22px 100%`:`22px 0`},onMouseDown:e=>e.preventDefault(),children:[(0,V.jsx)(`span`,{className:`xsmyaan x1kpxq89 xyqm7xq x1qp53xl x1cum3z5 xf6xdpg x1158fpu`}),(0,V.jsx)(`div`,{className:`x78zum5 xn3w4p2 xfn1xvj x4pepcl xf6xdpg x1dam6yx`,children:c.map(({label:e,Icon:t,run:n,primary:r})=>(0,V.jsxs)(`button`,{type:`button`,onClick:n,...{0:{className:`x78zum5 x6s0dn4 x17d4w8g xn3w4p2 xt970qd xaope02 xc342km x1q4ynmn xjbqb8w x116urgp xqirfc3 xqfszdh xif65rj x1ypdohk`},1:{className:`x78zum5 x6s0dn4 x17d4w8g xn3w4p2 xt970qd xaope02 xc342km x1q4ynmn xjbqb8w x116urgp xqfszdh xif65rj x1ypdohk xfungia x1s688f`}}[!!r|0],children:[(0,V.jsx)(t,{size:16,"aria-hidden":!0}),e]},e))})]})}var Z={state:{kmuXW:`x2lah0s`,kGuDYH:`xfifm61`,$$css:!0},waitingAgent:{kMwMTN:`x7zghnd`,$$css:!0},answered:{kMwMTN:`xh0clw4`,$$css:!0},resolved:{kMwMTN:`xddlp02`,$$css:!0}},Oe=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function ke({thread:e,agent:t=`Agent`,actions:n,active:a=!1,offline:s=!1}){let c=r(e),u=e.status===`resolved`,d=u?{label:`已解决`,tone:Z.resolved}:c===`agent`?{label:`等 ${t} 回复`,tone:Z.waitingAgent}:c===`human`?{label:`${t} 已回复`,tone:Z.answered}:null;return(0,V.jsxs)(`div`,{"data-thread":e.id,...{0:{className:`xxlmvz2 x178xt8z x13fuv20 xxu5053 xqfszdh xo2rkog`},1:{className:`xxlmvz2 x178xt8z x13fuv20 xxu5053 xqfszdh xo2rkog xggygye`}}[!!a|0],children:[(0,V.jsxs)(`div`,{className:`x78zum5 x1pha0wt x167g77z x1lqa7cf x1vo0akb x19ypqd9 x13ym6ox x4z9k3i`,children:[(0,V.jsx)(`span`,{className:`x98rzlu xeuugli xb3r6kr xuxw1ft xlyipyv x1bo0w0s`,children:e.anchor.quote||`整段`}),d?(0,V.jsx)(`span`,{...l(Z.state,d.tone),children:d.label}):null]}),u&&!a?null:e.messages.map(e=>{let{label:t,initial:n}=o(e);return(0,V.jsxs)(`div`,{className:`x14vqqas`,children:[(0,V.jsxs)(`div`,{className:`x78zum5 x6s0dn4 x167g77z x4z9k3i x1s688f`,children:[(0,V.jsx)(m,{human:e.author===`human`,initial:n,name:e.name,src:e.avatar}),t,(0,V.jsx)(`span`,{className:`xddlp02 xo1l8bm xfifm61`,children:Oe(e.editedAt??e.at)})]}),(0,V.jsx)(`div`,{...{0:{className:`x1gslohp xxpkpgd x1jvydc1 x1dbl2gt x126k92a xj0a0fe`},1:{className:`x1gslohp xxpkpgd x1jvydc1 x1dbl2gt x126k92a xj0a0fe xc7n51q`}}[!!e.deleted|0],children:e.deleted?`已删除`:e.text})]},e.id)}),n?(0,V.jsxs)(`div`,{className:`x78zum5 x6s0dn4 xou54vl x1anpbxc xxpkpgd`,children:[u?null:(0,V.jsx)(`div`,{className:`x98rzlu xeuugli x1qyh8g1 xso031l x1q0q8m5 x1iz93xd`,children:(0,V.jsx)(i,{placeholder:`回复…`,onSubmit:t=>n.reply(e.id,t)})}),s?null:(0,V.jsx)(`button`,{type:`button`,onClick:()=>u?n.reopen(e.id):n.resolve(e.id),className:`x2lah0s x1gg8mnh xt970qd xdqyycr x1w5wx5t xc342km xjbqb8w x1bo0w0s xqfszdh x4z9k3i x1ypdohk`,children:u?`重新打开`:`解决`})]}):null]})}var Q=.5,Ae=e=>e===78?Q:e;function je({threads:e,agent:t=`Agent`,actions:n,offline:a,draft:o,onCreate:s,onCancelDraft:c,activeId:l,snap:f,onSnap:p}){let m=(0,R.useRef)(null),h=e.filter(e=>!e.messages.every(e=>e.deleted)),g=h.filter(e=>r(e)===`agent`).length,_=a?`电脑离线,暂时不能评论`:g>0?`${g} 条等 ${t} 回复`:null;return(0,R.useEffect)(()=>{let e=l?m.current?.querySelector(`[data-thread="${CSS.escape(l)}"]`):null,t=e?.closest(`[data-sheet-body]`);e&&t&&(t.scrollTo({top:t.scrollTop+e.getBoundingClientRect().top-t.getBoundingClientRect().top-8,behavior:`smooth`}),u(e,[{backgroundColor:`rgba(232, 194, 74, 0.24)`},{backgroundColor:`transparent`}],{duration:600,delay:250,easing:d}))},[l]),(0,V.jsx)(F,{snaps:[78,Q,1],snap:f,onSnap:p,onScrim:()=>p(Q),header:(0,V.jsxs)(`span`,{className:`x78zum5 x1pha0wt x17d4w8g xu0aao5 x17qtykl xwib8y2 xqfszdh x1jvydc1 x1s688f`,children:[`评论 `,h.length,_?(0,V.jsxs)(`span`,{className:`xddlp02 xfifm61 xo1l8bm`,children:[`· `,_]}):null]}),children:(0,V.jsxs)(`div`,{ref:m,className:`x17qtykl xwxc41k`,children:[o&&n?(0,V.jsxs)(`div`,{className:`x10dr8xq xqfszdh`,children:[(0,V.jsxs)(`div`,{className:`x78zum5 x1pha0wt x167g77z x4z9k3i`,children:[(0,V.jsx)(`span`,{className:`x98rzlu xeuugli x1lqa7cf x1vo0akb x19ypqd9 x13ym6ox xb3r6kr xuxw1ft xlyipyv x1bo0w0s`,children:o.quote}),(0,V.jsx)(`button`,{type:`button`,onClick:c,className:`x1717udv xc342km xjbqb8w xddlp02 x4z9k3i x1ypdohk`,children:`取消`})]}),(0,V.jsx)(`div`,{className:`x1xmf6yo x1qyh8g1 xso031l x1q0q8m5 x1iz93xd`,children:(0,V.jsx)(i,{autoFocus:!0,placeholder:`写给 agent 的评论…`,onSubmit:e=>s(o,e).then(e=>(e&&c(),e))})})]}):null,h.length===0&&!o?(0,V.jsx)(`div`,{className:`xr9q8rw xddlp02 xqfszdh x4z9k3i x2b8uid`,children:`还没有评论。选中文字就能评论。`}):null,h.map(e=>(0,V.jsx)(ke,{thread:e,agent:t,actions:n,active:e.id===l,offline:a},e.id))]})})}var Me=52;function Ne({editor:e,threads:t,actions:n,agent:r,canComment:i,canEdit:a,offline:o,selection:s,clearSelection:c,onCreate:l,onEdit:u,onMain:d,children:f}){let[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(null),[_,y]=(0,R.useState)(78),[b,x]=(0,R.useState)(null),S=C(e,t,p);ne(S,t,h),v(b?.range??null);let w=()=>{window.getSelection()?.removeAllRanges(),c()};return(0,V.jsxs)(`main`,{ref:e=>{m(e),d?.(e)},className:`x1n2onr6 x1cnzs8 x17qtykl x1ffnkcp`,children:[(0,V.jsx)(`article`,{onClick:e=>{let t=E(S,e.clientX,e.clientY);g(t),t&&y(Ae)},children:f}),s&&!b?(0,V.jsx)(De,{...ie(s,{left:8,right:(p?.clientWidth??0)-8},170,44,{top:p?.getBoundingClientRect().top??0,height:window.innerHeight,reserved:O(_,window.innerHeight-Me)}),canComment:i,canEdit:a,onComment:()=>{x(s),y(Q),w()},onEdit:()=>{u(s),c()}}):null,(0,V.jsx)(`div`,{className:`xixxii4 x1ozmhy9 xu96u03 x3m8u43 x1ey2m1c x1355qak x47corl`,children:(0,V.jsx)(je,{threads:t,agent:r,actions:n,offline:o,draft:b,onCreate:l,onCancelDraft:()=>x(null),activeId:h,snap:_,onSnap:y})})]})}var Pe=200;function Fe(e,t){let[n,r]=(0,R.useState)(null);return(0,R.useEffect)(()=>{if(!e||!t)return;let n=0,i=()=>{let n=window.getSelection(),i=e.getRootElement();if(!n||n.isCollapsed||n.rangeCount===0||!i?.contains(n.anchorNode)){r(null);return}let a=n.toString().trim(),o=e.read(()=>{let e=n.anchorNode&&D(n.anchorNode)?.getTopLevelElement(),t=n.focusNode&&D(n.focusNode)?.getTopLevelElement();return!e||!t||!e.is(t)?null:h(e,y)||null});if(!o||!a){r(null);return}let s=n.getRangeAt(0),c=[...s.getClientRects()],l=c[0]??s.getBoundingClientRect(),u=c.at(-1)??l,d=t.getBoundingClientRect();r({blockId:o,quote:a.slice(0,500),left:l.left-d.left,bottom:u.bottom-d.top,top:l.top-d.top,right:u.right-d.left,range:s.cloneRange()})},a=()=>{clearTimeout(n),n=window.setTimeout(i,Pe)};return document.addEventListener(`selectionchange`,a),()=>{clearTimeout(n),document.removeEventListener(`selectionchange`,a)}},[e,t]),[n,()=>r(null)]}function Ie(){let e=(0,R.useMemo)(()=>window.matchMedia(`(prefers-color-scheme: dark)`),[]),[t,n]=(0,R.useState)(e.matches);return(0,R.useEffect)(()=>{let t=()=>n(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[e]),t}function Le(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.createElement(`base`);return t.href=e,document.head.prepend(t),()=>t.remove()},[e])}function Re({id:e}){let{transport:t,live:n}=xe(e);return(0,V.jsx)($,{id:e,transport:t,live:n})}function $({id:e,transport:t,live:n,cloud:r}){let[i,a]=(0,R.useState)(null),[o,c]=(0,R.useState)(null),[l,u]=(0,R.useState)(p),[d,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(!1),[_,v]=(0,R.useState)(void 0),[y,b]=(0,R.useState)(0),C=(0,R.useCallback)(e=>{e!==void 0&&b(e-Date.now())},[]),[w,te]=(0,R.useState)(null),[ne,T]=(0,R.useState)(!1),[E,ie]=(0,R.useState)(null),[ae,D]=(0,R.useState)(null),se=Ie(),{artifact:O,channel:k}=t,A=!r||r.online,j=!r||r.canEdit,M=f(s),[N,P]=(0,R.useState)(!1),F=M?N&&j:j,I=(0,R.useCallback)(async()=>{let e=await t.meta();e&&a(e)},[t]);(0,R.useEffect)(()=>{let e=!1;return(async()=>{try{await I();let n=await t.state();if(e)return;let r=new S;r.setRecordTimestamp(!0),r.setChangeMergeInterval(20),r.import(ee(n.snapshot)),g(!!n.streaming),v(n.agentActiveAt),C(n.now),u(n.comments??p()),c(r)}catch(t){e||m(t.message)}})(),()=>{e=!0}},[t,I,C]),(0,R.useEffect)(()=>k.subscribe(e=>{e.type===`change`?I():e.type===`doc-status`?(g(e.streaming),v(e.agentActiveAt),C(e.now)):e.type===`doc-comments`&&u(e.comments)}),[k,I,C]),(0,R.useEffect)(()=>{E?.setEditable(F)},[E,F]),(0,R.useEffect)(()=>{j||P(!1)},[j]);let L=(0,R.useCallback)(e=>{g(!!e.streaming),v(e.agentActiveAt),C(e.now),e.comments&&u(e.comments)},[C]);Le(i?.contentBase),ge(E,O,n,t.send);let z=(0,R.useMemo)(()=>({artifact:O,contentBase:i?.contentBase??``,channel:k,send:t.send}),[O,i?.contentBase,k,t]);(0,R.useEffect)(()=>{document.title=i?.title||e},[i?.title,e]),le(`document`);let B=Te(E),H=Ee(B.count>0&&!h),U=ue({streaming:h,pending:B.count,agentActiveAt:_,now:H+y}),W=i?.agent??`Agent`,de=(0,R.useMemo)(()=>({nextKey:B.firstKey,agent:W,activity:U.kind}),[B.firstKey,W,U.kind]),fe=l.threads.filter(e=>e.status===`open`).length,[G,K]=Fe(E,ae),q=(0,R.useCallback)(async e=>{try{return u(await t.comment(e)),!0}catch{return!1}},[t]),J=(0,R.useMemo)(()=>({reply:(e,t)=>q({op:`reply`,threadId:e,text:t}),edit:(e,t,n)=>void q({op:`edit`,threadId:e,messageId:t,text:n}),remove:(e,t)=>void q({op:`delete`,threadId:e,messageId:t}),resolve:e=>void q({op:`resolve`,threadId:e}),reopen:e=>void q({op:`reopen`,threadId:e})}),[q]),Y=(0,R.useCallback)((e,t)=>q({op:`create`,blockId:e.blockId,quote:e.quote,text:t}),[q]),he=(0,R.useCallback)(e=>{if(!E)return;E.setEditable(!0),P(!0),E.getRootElement()?.focus({preventScroll:!0});let t=window.getSelection();t?.removeAllRanges(),t?.addRange(e.range)},[E]);if(d)return(0,V.jsx)(`div`,{className:`x1o8uwn5 x2b8uid x1bo0w0s xqfszdh xif65rj`,children:d});if(!o)return(0,V.jsx)(`div`,{className:`x1o8uwn5 x2b8uid x1bo0w0s xqfszdh xif65rj`,children:`Loading…`});let X=(0,V.jsx)(x.Provider,{value:z,children:(0,V.jsx)(re.Provider,{value:de,children:(0,V.jsx)(oe,{transport:t,agent:i?.agent,doc:o,theme:se?`dark`:`light`,onAgentSection:te,onOffline:T,onState:L,onEditorReady:ie})})});return(0,V.jsxs)(`div`,{className:`x1us19tq x1rozbrz xo2rkog`,className:`ryugi-doc ${{className:`x1us19tq x1rozbrz xo2rkog`}.className??``}`,children:[(0,V.jsx)(me,{id:e,title:i?.title||e,agent:i?.agent,activity:U,agentSection:w,offline:ne,openComments:fe,cloud:r,compact:M,onDone:M&&N?()=>P(!1):void 0}),M?(0,V.jsx)(Ne,{editor:E,threads:l.threads,actions:J,agent:i?.agent,canComment:A,canEdit:j,offline:!(!r||r.online),selection:N?null:G,clearSelection:K,onCreate:Y,onEdit:he,onMain:D,children:X}):(0,V.jsx)(pe,{editor:E,threads:l.threads,actions:J,agent:i?.agent,canComment:A,selection:G,clearSelection:K,onCreate:Y,onMain:D,children:X}),(0,V.jsx)(ce,{warnings:i?.warnings??[]})]})}export{$ as DocumentView,Re as default,Se as t};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{n as t,t as n}from"./jsx-runtime-CldxteV5.js";import{S as r,_ as i,a,b as o,f as s,hi as c,ka as l,l as u,o as d,p as f,x as p,y as m}from"./useSandboxFrame-8NPM2cx_.js";import{C as h,S as g,_,a as v,b as y,c as b,g as x,h as S,i as C,l as w,m as ee,n as te,o as ne,p as re,pn as T,r as E,s as ie,t as ae,u as oe,x as D}from"./DocumentLayout-Ds9A-4Ya.js";import{a as se,c as O,d as k,f as A,i as j,l as M,n as N,o as ce,r as P,s as F,u as le}from"./index.js";var I={name:`message-square`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]};I.node;var L=c(I),R=e(t(),1);function ue({streaming:e,pending:t,agentActiveAt:n,now:r}){if(e)return{kind:`editing`};if(t===0)return{kind:`idle`};if(n===void 0)return{kind:`working`,pending:t,idleMs:null};let i=Math.max(0,r-n);return i>3e5?{kind:`stale`,pending:t,idleMs:i}:{kind:`working`,pending:t,idleMs:i}}function z(e){return e<6e4?`${Math.floor(e/1e3)} 秒`:e<36e5?`${Math.floor(e/6e4)} 分钟`:`${Math.floor(e/36e5)} 小时`}function B(e,t,n){switch(e.kind){case`editing`:return`${t} 正在编辑${n?` ${n}`:``}`;case`idle`:return null;case`working`:{let n=`${t} 还有 ${e.pending} 节待写`;return e.idleMs===null?n:`${n} · ${e.idleMs<1e4?`刚刚`:`${z(e.idleMs)}前`}更新`}case`stale`:return`${t} ${z(e.idleMs)}没有更新 · 还有 ${e.pending} 节待写`}}var V=n();function H({left:e,top:t,quote:n,initial:r,restored:a,leaving:o,onChange:s,onSubmit:c,onCancel:l,ref:u}){return(0,V.jsx)(`div`,{ref:u,...{0:{className:`x10l6tqk x1u8a7rm xj6ak53 xowlrko xllfotl xatqbsq x1u6ievf`},1:{className:`x10l6tqk x1u8a7rm xj6ak53 x1u6ievf xxp0q0x x12l1aco xn0cd8s x47corl`}}[!!o|0],style:{left:e,top:t},children:(0,V.jsxs)(te,{active:!0,children:[(0,V.jsxs)(`div`,{className:`x78zum5 x1pha0wt x167g77z xz9dl7a x1hr3lfm xqfszdh x1j6dyjg`,children:[(0,V.jsxs)(`span`,{className:`x98rzlu xeuugli xb3r6kr xuxw1ft xlyipyv xddlp02`,children:[`“`,n,`”`]}),a?(0,V.jsx)(`span`,{className:`x2lah0s x7zghnd`,children:`已恢复上次的草稿`}):null]}),(0,V.jsx)(i,{autoFocus:!0,initial:r,placeholder:`写下你的问题或意见…`,onChange:s,onSubmit:c,onCancel:l})]})})}function U({left:e,top:t,onComment:n,onCopy:r,ref:i}){return(0,V.jsxs)(`div`,{ref:i,className:`x10l6tqk x1u8a7rm x78zum5 x6s0dn4 x195vfkc xc9qbxq x9f619 x9ms5i6 xmkeg23 x1y0btm7 xgcsv5v x1q4ynmn x12ilycc x1d5q07e xi1bcxy x773k2o xa3vuyk`,style:{left:e,top:t},onMouseDown:e=>e.preventDefault(),children:[n?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`button`,{type:`button`,onClick:n,className:`x78zum5 x6s0dn4 x17d4w8g x1fgtraw xt970qd x1awh872 xc342km xu4hgxq xjbqb8w xj0l527 x2230gt xo2rkog xqfszdh xfifm61 xk50ysn x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x1fkwv27`,children:[(0,V.jsx)(L,{size:14,className:`x2lah0s x17nrqe2`}),`评论`]}),(0,V.jsx)(`span`,{"aria-hidden":`true`,className:`x2lah0s x1i1rx1s xlup9mm xj3msbq xcn5yip`})]}):null,(0,V.jsx)(`button`,{type:`button`,onClick:r,className:`x78zum5 x6s0dn4 x17d4w8g x1fgtraw xt970qd x1awh872 xc342km xu4hgxq xjbqb8w xj0l527 x2230gt xqfszdh xfifm61 xk50ysn x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x1fkwv27 x1bo0w0s`,children:`复制`})]})}var W=(e,t)=>`${e}\n${t}`;function de(){let e=new Map;return{save(t,n){n.trim()?e.set(t,n):e.delete(t)},take(t){return e.get(t)??``}}}function fe(e){let t=(0,R.useMemo)(de,[]),[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(!1),o=(0,R.useRef)(``),s=(0,R.useRef)(0),c=(0,R.useRef)(null),l=(0,R.useRef)(null);v(i?null:n?.target.range??null);let u=(0,R.useCallback)(n=>{window.clearTimeout(s.current);let i=t.take(W(n.blockId,n.quote));o.current=i,a(!1),r({target:n,initial:i}),window.getSelection()?.removeAllRanges(),e()},[t,e]),d=(0,R.useCallback)(e=>{n&&(t.save(W(n.target.blockId,n.target.quote),e?o.current:``),a(!0),s.current=window.setTimeout(()=>{r(null),a(!1)},120))},[n,t]);return(0,R.useEffect)(()=>{if(!n||i)return;let e=e=>{let t=e.target;c.current?.contains(t)||l.current?.contains(t)||d(!0)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[n,i,d]),(0,R.useEffect)(()=>()=>window.clearTimeout(s.current),[]),{draft:n,leaving:i,restored:!!n?.initial,open:u,close:d,onText:e=>{o.current=e},panelRef:c,toolbarRef:l}}function G(e){return{left:e.offsetLeft,right:Math.min(e.offsetLeft+e.offsetWidth,window.innerWidth-16)}}function pe({editor:e,threads:t,actions:n,agent:r,canComment:i,selection:a,clearSelection:o,onCreate:s,onMain:c,children:l}){let u=fe(o),{draft:d}=u;return(0,V.jsx)(ae,{editor:e,threads:t,actions:n,agent:r,onMain:c,overlay:e=>(0,V.jsxs)(V.Fragment,{children:[a&&!d?(0,V.jsx)(U,{ref:u.toolbarRef,...w(a,G(e),128,36,8),onComment:i?()=>u.open(a):void 0,onCopy:()=>{navigator.clipboard?.writeText(a.quote),window.getSelection()?.removeAllRanges(),o()}}):null,d?(0,V.jsx)(H,{ref:u.panelRef,...b(d.target,G(e),340,8),quote:d.target.quote,initial:d.initial,restored:u.restored,leaving:u.leaving,onChange:u.onText,onSubmit:e=>s(d.target,e).then(e=>(e&&u.close(!1),e)),onCancel:()=>u.close(!0)},`${d.target.blockId}:${d.target.quote}`):null]}),children:l})}function me({id:e,title:t,activity:n,agentSection:r,offline:i,openComments:o,cloud:s,compact:c=!1,onDone:l,agent:u=`Agent`}){let d=B(n,u,r);return a(e,s?{...t?{title:t}:{},online:s.online,comments:o,activity:d,activityTone:n.kind===`stale`?`warning`:n.kind===`working`?`quiet`:`live`,retrying:i,reason:s.reason}:null)&&!c?null:(0,V.jsxs)(`header`,{...{0:{className:`x7wzq59 x13vifvy x1n327nk xdd8jsf x78zum5 x6s0dn4 x1v2ro7d x4l9tsp x1rozbrz xqfszdh`},1:{className:`x7wzq59 x13vifvy x1n327nk xdd8jsf x78zum5 x6s0dn4 x1rozbrz xqfszdh x1hr3lfm x883omv`}}[!!c|0],children:[c?null:(0,V.jsxs)(`span`,{className:`xddlp02 xfifm61 xuxw1ft`,children:[`document / `,(0,V.jsx)(`span`,{className:`xo2rkog x1s688f`,children:e})]}),d?(0,V.jsxs)(`span`,{...{0:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla xlssvyo x19ay2w6 x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv`},2:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xahzvm9 x1bo0w0s`},1:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xqdcvd7 x7zghnd`},3:{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xqdcvd7 x7zghnd`}}[(n.kind===`working`)<<1|n.kind===`stale`],children:[n.kind===`stale`?null:(0,V.jsx)(`i`,{className:`x1v4s8kt xols6we x16rqkct xtwfq29`}),d]}):null,i?(0,V.jsx)(`span`,{className:`x78zum5 x6s0dn4 x17d4w8g xj8oexa x1awh872 x1e6avla x1j6dyjg xuxw1ft xeuugli xb3r6kr xlyipyv xqdcvd7 x7zghnd`,children:`未同步,正在重试`}):null,s?.reason&&!c?(0,V.jsx)(`span`,{className:`xb3r6kr xddlp02 xfifm61 xuxw1ft xlyipyv`,children:s.reason}):null,(0,V.jsx)(`span`,{className:`x98rzlu`}),s?(0,V.jsxs)(`span`,{className:`x78zum5 x6s0dn4 x17d4w8g x1bo0w0s xfifm61 xuxw1ft`,children:[(0,V.jsx)(`i`,{...{0:{className:`xci0xqf x1hagigm x16rqkct xxwmxtg`},1:{className:`xci0xqf x1hagigm x16rqkct xux1nz0`}}[!!s.online|0]}),s.online?`电脑在线`:`电脑离线`]}):null,c?null:(0,V.jsxs)(`span`,{className:`xddlp02 xfifm61 xuxw1ft`,children:[`评论 `,o]}),l?(0,V.jsx)(`button`,{type:`button`,onClick:l,className:`x12ulsxz xaope02 xc342km x1kogg8i x19ckca5 xs0jrwl xqfszdh x4z9k3i x1s688f x1ypdohk`,children:`完成`}):s||c?null:(0,V.jsx)(k,{artifact:`document/${e}`})]})}function K(e,t,n){let[r,i]=t<=n?[t,n]:[n,t];return{blockIds:e.slice(r,i+1).flatMap(e=>e.id?[e.id]:[]).slice(0,M.blockIds),heading:e.slice(0,r+1).filter(e=>e.heading).pop()?.text??``}}var q=crypto.randomUUID(),J=300,Y={quote:``,blockIds:[],heading:``};function he(e){let t=window.getSelection(),n=e.getRootElement();if(!t||t.isCollapsed||!n?.contains(t.anchorNode)||!n.contains(t.focusNode))return Y;let r=t.toString().trim().slice(0,M.quote);return r?e.read(()=>{let e=g().getChildren(),n=t=>{let n=t&&D(t)?.getTopLevelElement();return n?e.findIndex(e=>e.is(n)):-1},i=n(t.anchorNode),a=n(t.focusNode);if(i<0||a<0)return{...Y,quote:r};let o=e.map(e=>({id:h(e,y)||``,heading:e.getType()===`heading`,text:e.getTextContent().slice(0,M.heading)}));return{quote:r,...K(o,i,a)}}):Y}function ge(e,t,n,r){let i=(0,R.useRef)(Y);(0,R.useEffect)(()=>{if(!e)return;let n=0,a=()=>{let n=he(e);JSON.stringify(n)!==JSON.stringify(i.current)&&(i.current=n,r({type:`selection`,artifact:t,tab:q,human:!0,...n}))},o=()=>{clearTimeout(n),n=window.setTimeout(a,J)};return document.addEventListener(`selectionchange`,o),()=>{clearTimeout(n),document.removeEventListener(`selectionchange`,o)}},[e,t,r]),(0,R.useEffect)(()=>{n&&i.current.quote&&r({type:`selection`,artifact:t,tab:q,human:!1,...i.current})},[n,t,r])}var X=[`pending`],_e=`x-ryugi-document-features`,ve=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)};function ye({id:e,channel:t,send:n}){let r=(t,n,r)=>fetch(`/api/document/${e}/${t}`,{method:`POST`,headers:{"Content-Type":r,[_e]:X.join(`,`)},body:n});return{artifact:`document/${e}`,channel:t,send:n,async meta(){let t=await fetch(`/api/artifacts/document/${e}`,{cache:`no-store`});return t.ok?await t.json():null},async state(){let t=await fetch(`/api/document/${e}/state`,{cache:`no-store`}),n=await t.json();if(!t.ok||!n.snapshot)throw Error(n.error??`load failed (${t.status})`);return n},async update(e){let t=await r(`update`,e,`application/octet-stream`);if(!t.ok)throw Error(`update failed (${t.status})`)},async comment(e){let t=await r(`comments`,JSON.stringify(e),`application/json`);if(!t.ok)throw Error(`comment failed (${t.status})`);return(await t.json()).comments}}}function be(e){let t=_(),n=(e.connect??j)({url:e.url,artifact:e.artifact,WebSocket:e.WebSocket,retryMs:e.retryMs,onPresence:e.onPresence,onEvent:e=>t.emit(e),onOnline:()=>t.emit({type:`open`})});return{artifact:e.artifact,channel:t,close:n.close,async meta(){let t=await n.request({op:`meta`});return/^https?:\/\//.test(t.contentBase??``)?t:{...t,contentBase:e.contentBase}},state:()=>n.request({op:`state`}),async update(e){await n.request({op:`update`,bytes:ve(e),features:X})},async comment(e){return(await n.request({op:`comment`,comment:e})).comments},send(e){let{type:t}=e;t===`selection`?n.request({op:`selection`,selection:e}).catch(()=>{}):(t===`loaded`||t===`runtime-error`)&&n.request({op:`client`,message:e}).catch(()=>{})}}}function xe(e){let t=(0,R.useMemo)(_,[]),n=`document/${e}`,{live:r,send:i}=A(e=>{e.artifact===n&&t.emit(e)},()=>t.emit({type:`open`}));return{transport:(0,R.useMemo)(()=>ye({id:e,channel:t,send:i}),[e,t,i]),live:r}}function Se(e,t){let[n,r]=(0,R.useState)(null),[i,a]=(0,R.useState)(null);return(0,R.useEffect)(()=>{let n=be({url:N(e),artifact:`document/${e}`,contentBase:t,onPresence:a,connect:t=>P({...t,cloudId:e,known:se()})});return r(n),()=>{n.close(),r(null),a(null)}},[e,t]),{transport:n,presence:i}}var Ce={count:0,firstKey:null},we=e=>e.read(()=>{let e=g().getChildren().filter(e=>e.getType()===`pending`).map(e=>e.getKey());return{count:e.length,firstKey:e[0]??null}});function Te(e){let[t,n]=(0,R.useState)(Ce);return(0,R.useEffect)(()=>{if(!e){n(Ce);return}let t=e=>n(t=>t.count===e.count&&t.firstKey===e.firstKey?t:e);return t(we(e.getEditorState())),e.registerUpdateListener(({editorState:e})=>t(we(e)))},[e]),t}function Ee(e,t=15e3){let[n,r]=(0,R.useState)(()=>Date.now());return(0,R.useEffect)(()=>{if(!e)return;r(Date.now());let n=setInterval(()=>r(Date.now()),t);return()=>clearInterval(n)},[e,t]),n}function De({left:e,top:t,placement:n,canComment:r,canEdit:i,onComment:a,onEdit:o}){let s=(0,R.useRef)(null),c=[r?{label:`评论`,Icon:L,run:a,primary:!0}:null,i?{label:`改字`,Icon:T,run:o,primary:!1}:null].filter(e=>e!==null);return(0,R.useLayoutEffect)(()=>{u(s.current,[{opacity:0,transform:`scale(0.96)`},{opacity:1,transform:`none`}],{duration:160,easing:d})},[]),c.length===0?null:(0,V.jsxs)(`div`,{ref:s,"data-edit-menu":!0,"data-placement":n,...{0:{className:`x10l6tqk x1u8a7rm x78zum5 xdt5ytf x1cy8zhl`},1:{className:`x10l6tqk x1u8a7rm x78zum5 x1cy8zhl x3ieub6`}}[n===`above`|0],style:{left:e,top:t,transformOrigin:n===`above`?`22px 100%`:`22px 0`},onMouseDown:e=>e.preventDefault(),children:[(0,V.jsx)(`span`,{className:`xsmyaan x1kpxq89 xyqm7xq x1qp53xl x1cum3z5 xf6xdpg x1158fpu`}),(0,V.jsx)(`div`,{className:`x78zum5 xn3w4p2 xfn1xvj x4pepcl xf6xdpg x1dam6yx`,children:c.map(({label:e,Icon:t,run:n,primary:r})=>(0,V.jsxs)(`button`,{type:`button`,onClick:n,...{0:{className:`x78zum5 x6s0dn4 x17d4w8g xn3w4p2 xt970qd xaope02 xc342km x1q4ynmn xjbqb8w x116urgp xqirfc3 xqfszdh xif65rj x1ypdohk`},1:{className:`x78zum5 x6s0dn4 x17d4w8g xn3w4p2 xt970qd xaope02 xc342km x1q4ynmn xjbqb8w x116urgp xqfszdh xif65rj x1ypdohk xfungia x1s688f`}}[!!r|0],children:[(0,V.jsx)(t,{size:16,"aria-hidden":!0}),e]},e))})]})}var Z={state:{kmuXW:`x2lah0s`,kGuDYH:`xfifm61`,$$css:!0},waitingAgent:{kMwMTN:`x7zghnd`,$$css:!0},answered:{kMwMTN:`xh0clw4`,$$css:!0},resolved:{kMwMTN:`xddlp02`,$$css:!0}},Oe=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function ke({thread:e,agent:t=`Agent`,actions:n,active:a=!1,offline:s=!1}){let c=r(e),u=e.status===`resolved`,d=u?{label:`已解决`,tone:Z.resolved}:c===`agent`?{label:`等 ${t} 回复`,tone:Z.waitingAgent}:c===`human`?{label:`${t} 已回复`,tone:Z.answered}:null;return(0,V.jsxs)(`div`,{"data-thread":e.id,...{0:{className:`xxlmvz2 x178xt8z x13fuv20 xxu5053 xqfszdh xo2rkog`},1:{className:`xxlmvz2 x178xt8z x13fuv20 xxu5053 xqfszdh xo2rkog xggygye`}}[!!a|0],children:[(0,V.jsxs)(`div`,{className:`x78zum5 x1pha0wt x167g77z x1lqa7cf x1vo0akb x19ypqd9 x13ym6ox x4z9k3i`,children:[(0,V.jsx)(`span`,{className:`x98rzlu xeuugli xb3r6kr xuxw1ft xlyipyv x1bo0w0s`,children:e.anchor.quote||`整段`}),d?(0,V.jsx)(`span`,{...l(Z.state,d.tone),children:d.label}):null]}),u&&!a?null:e.messages.map(e=>{let{label:t,initial:n}=o(e);return(0,V.jsxs)(`div`,{className:`x14vqqas`,children:[(0,V.jsxs)(`div`,{className:`x78zum5 x6s0dn4 x167g77z x4z9k3i x1s688f`,children:[(0,V.jsx)(m,{human:e.author===`human`,initial:n,name:e.name,src:e.avatar}),t,(0,V.jsx)(`span`,{className:`xddlp02 xo1l8bm xfifm61`,children:Oe(e.editedAt??e.at)})]}),(0,V.jsx)(`div`,{...{0:{className:`x1gslohp xxpkpgd x1jvydc1 x1dbl2gt x126k92a xj0a0fe`},1:{className:`x1gslohp xxpkpgd x1jvydc1 x1dbl2gt x126k92a xj0a0fe xc7n51q`}}[!!e.deleted|0],children:e.deleted?`已删除`:e.text})]},e.id)}),n?(0,V.jsxs)(`div`,{className:`x78zum5 x6s0dn4 xou54vl x1anpbxc xxpkpgd`,children:[u?null:(0,V.jsx)(`div`,{className:`x98rzlu xeuugli x1qyh8g1 xso031l x1q0q8m5 x1iz93xd`,children:(0,V.jsx)(i,{placeholder:`回复…`,onSubmit:t=>n.reply(e.id,t)})}),s?null:(0,V.jsx)(`button`,{type:`button`,onClick:()=>u?n.reopen(e.id):n.resolve(e.id),className:`x2lah0s x1gg8mnh xt970qd xdqyycr x1w5wx5t xc342km xjbqb8w x1bo0w0s xqfszdh x4z9k3i x1ypdohk`,children:u?`重新打开`:`解决`})]}):null]})}var Q=.5,Ae=e=>e===78?Q:e;function je({threads:e,agent:t=`Agent`,actions:n,offline:a,draft:o,onCreate:s,onCancelDraft:c,activeId:l,snap:f,onSnap:p}){let m=(0,R.useRef)(null),h=e.filter(e=>!e.messages.every(e=>e.deleted)),g=h.filter(e=>r(e)===`agent`).length,_=a?`电脑离线,暂时不能评论`:g>0?`${g} 条等 ${t} 回复`:null;return(0,R.useEffect)(()=>{let e=l?m.current?.querySelector(`[data-thread="${CSS.escape(l)}"]`):null,t=e?.closest(`[data-sheet-body]`);e&&t&&(t.scrollTo({top:t.scrollTop+e.getBoundingClientRect().top-t.getBoundingClientRect().top-8,behavior:`smooth`}),u(e,[{backgroundColor:`rgba(232, 194, 74, 0.24)`},{backgroundColor:`transparent`}],{duration:600,delay:250,easing:d}))},[l]),(0,V.jsx)(F,{snaps:[78,Q,1],snap:f,onSnap:p,onScrim:()=>p(Q),header:(0,V.jsxs)(`span`,{className:`x78zum5 x1pha0wt x17d4w8g xu0aao5 x17qtykl xwib8y2 xqfszdh x1jvydc1 x1s688f`,children:[`评论 `,h.length,_?(0,V.jsxs)(`span`,{className:`xddlp02 xfifm61 xo1l8bm`,children:[`· `,_]}):null]}),children:(0,V.jsxs)(`div`,{ref:m,className:`x17qtykl xwxc41k`,children:[o&&n?(0,V.jsxs)(`div`,{className:`x10dr8xq xqfszdh`,children:[(0,V.jsxs)(`div`,{className:`x78zum5 x1pha0wt x167g77z x4z9k3i`,children:[(0,V.jsx)(`span`,{className:`x98rzlu xeuugli x1lqa7cf x1vo0akb x19ypqd9 x13ym6ox xb3r6kr xuxw1ft xlyipyv x1bo0w0s`,children:o.quote}),(0,V.jsx)(`button`,{type:`button`,onClick:c,className:`x1717udv xc342km xjbqb8w xddlp02 x4z9k3i x1ypdohk`,children:`取消`})]}),(0,V.jsx)(`div`,{className:`x1xmf6yo x1qyh8g1 xso031l x1q0q8m5 x1iz93xd`,children:(0,V.jsx)(i,{autoFocus:!0,placeholder:`写给 agent 的评论…`,onSubmit:e=>s(o,e).then(e=>(e&&c(),e))})})]}):null,h.length===0&&!o?(0,V.jsx)(`div`,{className:`xr9q8rw xddlp02 xqfszdh x4z9k3i x2b8uid`,children:`还没有评论。选中文字就能评论。`}):null,h.map(e=>(0,V.jsx)(ke,{thread:e,agent:t,actions:n,active:e.id===l,offline:a},e.id))]})})}var Me=52;function Ne({editor:e,threads:t,actions:n,agent:r,canComment:i,canEdit:a,offline:o,selection:s,clearSelection:c,onCreate:l,onEdit:u,onMain:d,children:f}){let[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(null),[_,y]=(0,R.useState)(78),[b,x]=(0,R.useState)(null),S=C(e,t,p);ne(S,t,h),v(b?.range??null);let w=()=>{window.getSelection()?.removeAllRanges(),c()};return(0,V.jsxs)(`main`,{ref:e=>{m(e),d?.(e)},className:`x1n2onr6 x1cnzs8 x17qtykl x1ffnkcp`,children:[(0,V.jsx)(`article`,{onClick:e=>{let t=E(S,e.clientX,e.clientY);g(t),t&&y(Ae)},children:f}),s&&!b?(0,V.jsx)(De,{...ie(s,{left:8,right:(p?.clientWidth??0)-8},170,44,{top:p?.getBoundingClientRect().top??0,height:window.innerHeight,reserved:O(_,window.innerHeight-Me)}),canComment:i,canEdit:a,onComment:()=>{x(s),y(Q),w()},onEdit:()=>{u(s),c()}}):null,(0,V.jsx)(`div`,{className:`xixxii4 x1ozmhy9 xu96u03 x3m8u43 x1ey2m1c x1355qak x47corl`,children:(0,V.jsx)(je,{threads:t,agent:r,actions:n,offline:o,draft:b,onCreate:l,onCancelDraft:()=>x(null),activeId:h,snap:_,onSnap:y})})]})}var Pe=200;function Fe(e,t){let[n,r]=(0,R.useState)(null);return(0,R.useEffect)(()=>{if(!e||!t)return;let n=0,i=()=>{let n=window.getSelection(),i=e.getRootElement();if(!n||n.isCollapsed||n.rangeCount===0||!i?.contains(n.anchorNode)){r(null);return}let a=n.toString().trim(),o=e.read(()=>{let e=n.anchorNode&&D(n.anchorNode)?.getTopLevelElement(),t=n.focusNode&&D(n.focusNode)?.getTopLevelElement();return!e||!t||!e.is(t)?null:h(e,y)||null});if(!o||!a){r(null);return}let s=n.getRangeAt(0),c=[...s.getClientRects()],l=c[0]??s.getBoundingClientRect(),u=c.at(-1)??l,d=t.getBoundingClientRect();r({blockId:o,quote:a.slice(0,500),left:l.left-d.left,bottom:u.bottom-d.top,top:l.top-d.top,right:u.right-d.left,range:s.cloneRange()})},a=()=>{clearTimeout(n),n=window.setTimeout(i,Pe)};return document.addEventListener(`selectionchange`,a),()=>{clearTimeout(n),document.removeEventListener(`selectionchange`,a)}},[e,t]),[n,()=>r(null)]}function Ie(){let e=(0,R.useMemo)(()=>window.matchMedia(`(prefers-color-scheme: dark)`),[]),[t,n]=(0,R.useState)(e.matches);return(0,R.useEffect)(()=>{let t=()=>n(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[e]),t}function Le(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.createElement(`base`);return t.href=e,document.head.prepend(t),()=>t.remove()},[e])}function Re({id:e}){let{transport:t,live:n}=xe(e);return(0,V.jsx)($,{id:e,transport:t,live:n})}function $({id:e,transport:t,live:n,cloud:r}){let[i,a]=(0,R.useState)(null),[o,c]=(0,R.useState)(null),[l,u]=(0,R.useState)(p),[d,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(!1),[_,v]=(0,R.useState)(void 0),[y,b]=(0,R.useState)(0),C=(0,R.useCallback)(e=>{e!==void 0&&b(e-Date.now())},[]),[w,te]=(0,R.useState)(null),[ne,T]=(0,R.useState)(!1),[E,ie]=(0,R.useState)(null),[ae,D]=(0,R.useState)(null),se=Ie(),{artifact:O,channel:k}=t,A=!r||r.online,j=!r||r.canEdit,M=f(s),[N,P]=(0,R.useState)(!1),F=M?N&&j:j,I=(0,R.useCallback)(async()=>{let e=await t.meta();e&&a(e)},[t]);(0,R.useEffect)(()=>{let e=!1;return(async()=>{try{await I();let n=await t.state();if(e)return;let r=new S;r.setRecordTimestamp(!0),r.setChangeMergeInterval(20),r.import(ee(n.snapshot)),g(!!n.streaming),v(n.agentActiveAt),C(n.now),u(n.comments??p()),c(r)}catch(t){e||m(t.message)}})(),()=>{e=!0}},[t,I,C]),(0,R.useEffect)(()=>k.subscribe(e=>{e.type===`change`?I():e.type===`doc-status`?(g(e.streaming),v(e.agentActiveAt),C(e.now)):e.type===`doc-comments`&&u(e.comments)}),[k,I,C]),(0,R.useEffect)(()=>{E?.setEditable(F)},[E,F]),(0,R.useEffect)(()=>{j||P(!1)},[j]);let L=(0,R.useCallback)(e=>{g(!!e.streaming),v(e.agentActiveAt),C(e.now),e.comments&&u(e.comments)},[C]);Le(i?.contentBase),ge(E,O,n,t.send);let z=(0,R.useMemo)(()=>({artifact:O,contentBase:i?.contentBase??``,channel:k,send:t.send}),[O,i?.contentBase,k,t]);(0,R.useEffect)(()=>{document.title=i?.title||e},[i?.title,e]),le(`document`);let B=Te(E),H=Ee(B.count>0&&!h),U=ue({streaming:h,pending:B.count,agentActiveAt:_,now:H+y}),W=i?.agent??`Agent`,de=(0,R.useMemo)(()=>({nextKey:B.firstKey,agent:W,activity:U.kind}),[B.firstKey,W,U.kind]),fe=l.threads.filter(e=>e.status===`open`).length,[G,K]=Fe(E,ae),q=(0,R.useCallback)(async e=>{try{return u(await t.comment(e)),!0}catch{return!1}},[t]),J=(0,R.useMemo)(()=>({reply:(e,t)=>q({op:`reply`,threadId:e,text:t}),edit:(e,t,n)=>void q({op:`edit`,threadId:e,messageId:t,text:n}),remove:(e,t)=>void q({op:`delete`,threadId:e,messageId:t}),resolve:e=>void q({op:`resolve`,threadId:e}),reopen:e=>void q({op:`reopen`,threadId:e})}),[q]),Y=(0,R.useCallback)((e,t)=>q({op:`create`,blockId:e.blockId,quote:e.quote,text:t}),[q]),he=(0,R.useCallback)(e=>{if(!E)return;E.setEditable(!0),P(!0),E.getRootElement()?.focus({preventScroll:!0});let t=window.getSelection();t?.removeAllRanges(),t?.addRange(e.range)},[E]);if(d)return(0,V.jsx)(`div`,{className:`x1o8uwn5 x2b8uid x1bo0w0s xqfszdh xif65rj`,children:d});if(!o)return(0,V.jsx)(`div`,{className:`x1o8uwn5 x2b8uid x1bo0w0s xqfszdh xif65rj`,children:`Loading…`});let X=(0,V.jsx)(x.Provider,{value:z,children:(0,V.jsx)(re.Provider,{value:de,children:(0,V.jsx)(oe,{transport:t,agent:i?.agent,doc:o,theme:se?`dark`:`light`,onAgentSection:te,onOffline:T,onState:L,onEditorReady:ie})})});return(0,V.jsxs)(`div`,{className:`x1us19tq x1rozbrz xo2rkog`,className:`ryugi-doc ${{className:`x1us19tq x1rozbrz xo2rkog`}.className??``}`,children:[(0,V.jsx)(me,{id:e,title:i?.title||e,agent:i?.agent,activity:U,agentSection:w,offline:ne,openComments:fe,cloud:r,compact:M,onDone:M&&N?()=>P(!1):void 0}),M?(0,V.jsx)(Ne,{editor:E,threads:l.threads,actions:J,agent:i?.agent,canComment:A,canEdit:j,offline:!(!r||r.online),selection:N?null:G,clearSelection:K,onCreate:Y,onEdit:he,onMain:D,children:X}):(0,V.jsx)(pe,{editor:E,threads:l.threads,actions:J,agent:i?.agent,canComment:A,selection:G,clearSelection:K,onCreate:Y,onMain:D,children:X}),(0,V.jsx)(ce,{warnings:i?.warnings??[]})]})}export{$ as DocumentView,Re as default,Se as t};
|