Your Name 1912bcd25b
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
chore: sync all remaining local workspace changes
2026-05-08 11:26:57 +08:00

274 lines
9.7 KiB
JavaScript

/*
* Extracted from browser-delivered Turbopack chunk: 939e07c76f4b30f0.294c1bf0d6.js
* Module id: 749619
* For reading/searching only; this factory depends on the original Turbopack runtime.
*/
const moduleFactory = (e) => {
"use strict";
var t = e.i(462214),
i = e.i(358379),
r = e.i(325528),
a = e.i(640958),
n = e.i(955595),
A = e.i(532527),
s = e.i(41671),
o = e.i(733077),
l = e.i(216257),
c = e.i(777784);
let d = Number("1776439503000") || 0,
u = {
idle: "立即刷新",
saving: "保存草稿中…",
saved: "草稿已保存",
reloading: "即将刷新…",
};
function g() {
let e = (0, l.useCanvasStore)((e) => e.syncStatus),
g = (0, i.useRef)(e),
p = (0, i.useRef)(!1),
h = (0, i.useRef)(0),
m = (0, i.useRef)(null),
I = (0, i.useRef)(null),
[f, C] = (0, i.useState)(null),
[E, B] = (0, i.useState)("idle"),
b = (0, i.useCallback)((e, t) => {
if ("217-c4e65df7" === e) {
I.current = null;
return;
}
if (m.current === e) return;
if (t) {
(I.current = null),
C((i) =>
i?.version === e && i.force === t
? i
: { version: e, force: t },
);
return;
}
let i = I.current;
if (null === i) {
I.current = e;
return;
}
i === e
? ((I.current = null),
C((i) =>
i?.version === e && i.force === t
? i
: { version: e, force: t },
))
: (I.current = e);
}, []);
(0, i.useEffect)(() => {
g.current = e;
}, [e]);
let y = (0, i.useCallback)(() => {
f?.version && (m.current = f.version), C(null), B("idle");
}, [f]),
w = (0, i.useCallback)(() => {
let e = l.stores.canvas;
if (!e?.projectId) throw Error("MISSING_PROJECT_ID");
let t = {
nodes: e.nodes,
edges: e.edges,
savedAt: Date.now(),
version: e.syncVersion,
},
i = {
projectUuid: e.projectId,
draftJson: JSON.stringify(t),
viewportX: e.viewport.position.x.toString(),
viewportY: e.viewport.position.y.toString(),
viewportZoom: e.viewport.zoom.toString(),
},
n = JSON.stringify(i),
A = `${r.config.tv.apiHost}/api/canvas/project/draft/update`;
try {
let e = new Blob([n], { type: "application/json" });
if (navigator.sendBeacon(A, e)) return Promise.resolve();
} catch {}
let s = a.getUsertokenFromCookie?.() ?? "";
try {
return (
fetch(A, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(s ? { token: s } : {}),
},
body: n,
keepalive: !0,
}).catch(() => {}),
Promise.resolve()
);
} catch {
return (0, o.updateProjectDraft)(i);
}
}, []),
Q = (0, i.useCallback)(async () => {
if ("idle" === E) {
B("saving");
try {
let e = await l.stores.canvas?.saveFullSnapshotAsUpdate();
if (!e?.ok) {
c.Notify.warn(e?.msg || "保存失败,已取消刷新以避免丢失内容"),
B("idle");
return;
}
try {
w();
} catch {}
} catch {
c.Notify.warn("保存失败,已取消刷新以避免丢失内容"), B("idle");
return;
}
B("saved"),
await new Promise((e) => window.setTimeout(e, 600)),
B("reloading"),
window.location.reload();
}
}, [E, w]),
S = (0, i.useCallback)(async () => {
try {
let e = new AbortController(),
t = window.setTimeout(() => {
e.abort();
}, 8e3),
i = await fetch("/actions/version-check", {
method: "GET",
cache: "no-store",
signal: e.signal,
});
if ((window.clearTimeout(t), !i.ok)) return;
let r = await i.json(),
a = r.buildVersion?.trim();
if (!a) return;
let n = r.buildTime ?? 0;
if (n > 0 && d > 0 && n < d) return;
b(a, !!r.forceUpdate);
} catch {}
}, [b]);
(0, i.useEffect)(() => {
let e = async () => {
if (p.current) return;
let e = Date.now();
if (!(e - h.current < 3e4)) {
(p.current = !0), (h.current = e);
try {
await S();
} finally {
p.current = !1;
}
}
};
e();
let t = window.setInterval(() => {
e();
}, 6e5),
i = () => {
"visible" === document.visibilityState && e();
};
return (
document.addEventListener("visibilitychange", i),
() => {
window.clearInterval(t),
document.removeEventListener("visibilitychange", i);
}
);
}, [S]);
let k = "idle" !== E,
v = (0, l.useCanvasStore)((e) => e.editingClipNodeId);
return (0, t.jsx)("div", {
className: `${v ? "z-(--z-panel)" : "z-(--z-toast)"} pointer-events-none fixed left-1/2 top-8 -translate-x-1/2`,
children: (0, t.jsx)(n.AnimatePresence, {
children:
f &&
(0, t.jsxs)(
A.motion.div,
{
initial: { y: -40, opacity: 0 },
animate: { y: 0, opacity: 1 },
exit: { y: -40, opacity: 0 },
transition: { duration: 0.26, ease: "easeInOut" },
className:
"border-border-default bg-bg-surface pointer-events-auto flex items-center gap-3 rounded-xl border py-3 pl-4 pr-3 shadow-[0_4px_10px_rgba(0,0,0,0.12)]",
children: [
(0, t.jsxs)("div", {
className: "flex min-w-0 flex-1 items-center gap-2",
children: [
(0, t.jsx)(s.Icons.CircleF, {
width: 18,
height: 18,
className: "text-fg-default shrink-0",
}),
(0, t.jsx)("p", {
className:
"text-fg-default min-w-0 text-sm leading-normal",
children: f.force
? "检测到关键更新,请尽快刷新页面"
: "检测到新版本,刷新后可使用最新功能",
}),
],
}),
(0, t.jsxs)("div", {
className: "flex shrink-0 items-center gap-2",
children: [
!f.force &&
(0, t.jsx)("button", {
type: "button",
onClick: y,
disabled: k,
className:
"bg-white-alpha-10 text-fg-muted hover:bg-btn-ghost-hover hover:text-fg-default inline-flex h-8 items-center justify-center rounded-lg px-2 text-[13px] transition disabled:pointer-events-none disabled:opacity-40",
children: "稍后再试",
}),
(0, t.jsxs)("button", {
type: "button",
onClick: () => void Q(),
disabled: k,
className:
"bg-btn-primary text-btn-primary-text hover:bg-btn-primary-hover inline-flex h-8 items-center justify-center gap-1.5 rounded-lg px-3 text-[13px] transition disabled:cursor-not-allowed disabled:opacity-80",
children: [
k &&
(0, t.jsxs)("svg", {
className: "animate-spin",
width: "14",
height: "14",
viewBox: "0 0 14 14",
fill: "none",
children: [
(0, t.jsx)("circle", {
cx: "7",
cy: "7",
r: "5.5",
stroke: "currentColor",
strokeOpacity: "0.3",
strokeWidth: "2",
}),
(0, t.jsx)("path", {
d: "M12.5 7a5.5 5.5 0 0 0-5.5-5.5",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
}),
],
}),
u[E],
],
}),
],
}),
],
},
f.version,
),
}),
});
}
e.s(["default", () => g]);
};
export default moduleFactory;