Merge branch 'sub_laptop_1' of C:/Aislo_wt/sub_laptop_1 into main_laptop_1

This commit is contained in:
2026-11-15 13:52:01 +09:00
16 changed files with 191 additions and 108 deletions
+40 -9
View File
@@ -13,6 +13,7 @@
* M02 사본(`copy`) — 저장 몸 {문서, 끊음(받은 그대로), 판} · 판 바뀜(409)은 문서가 그대로면 새 판으로 한 번 더
* 기계 줄 · 옵션 가로 기계 = 기계 창(827-1 · `line_stack_machine`) — 초안은 문서 칸(캐시) · [저장] 때 서버가 내 기계로
* [단가 갱신] · [재생성] = 미리 셈 → 알림 → 저장(`formula_doc_copy.ts` · 고친 것 먼저 저장)
* 저장 전 문서(`memory` · 836-5 · 불러오기 미리 보기) = 빈 키 + 서버에 문서째(`본`) 읽음 · 왼쪽 줄 쌓기는 보기만(inert) · 디스크 쓰기 0
* ========================================================================== */
import { API_BASE_URL } from "@config/config_frontend";
@@ -74,6 +75,8 @@ export interface StackScreenOptions {
page?: () => void;
/** 페이지 머리 칸(808-1 · 요구 701-3) — 있으면 [단가 갱신] · [재생성] 등 화면 단추를 여기에(화면 위 단추 줄 대신) */
tools?: HTMLElement;
/** 저장 전 SK 문서(836-5 · 불러오기 미리 보기) — 빈 키일 때 이 문서를 서버가 읽어 줌(파일 안 읽음 · 안 씀) */
memory?: () => Record<string, unknown> | null;
}
type Docs = Record<string, FormulaDoc>;
@@ -126,14 +129,21 @@ export function createStackScreen(opt: StackScreenOptions) {
let paired = ""; // 짝 강조 자리(679 — 항목 `k` · 줄 `k.j`)
const blocks = new Set<string>(); // 풀린 공식 묶음
const mem = (): Record<string, unknown> | null => (cp && !key ? (opt.memory?.() ?? null) : null);
const call = async <T>(path: string, body?: unknown, signal?: AbortSignal): Promise<T> => {
const r = await fetch(`${API_BASE_URL}${cp ? cp.route(key, path) : opt.base + path}`, {
method: body === undefined ? "GET" : "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
...(body === undefined ? {} : { body: JSON.stringify(body) }),
signal,
});
const saved = mem(); // 저장 전 문서 = 길 키 「-」 · 몸 `본`
const r = await fetch(
`${API_BASE_URL}${cp ? cp.route(saved ? "-" : key, path) : opt.base + path}`,
{
method: body === undefined ? "GET" : "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
...(body === undefined
? {}
: { body: JSON.stringify(saved ? { ...(body as object), 본: saved } : body) }),
signal,
},
);
const data = (await r.json().catch(() => ({}))) as T & { detail?: unknown };
if (!r.ok) {
const why = data.detail;
@@ -346,9 +356,9 @@ export function createStackScreen(opt: StackScreenOptions) {
);
opt.tools?.replaceChildren(...tools);
const items = stackOf(doc);
root.dataset.edit = edit() ? "1" : "";
root.dataset.edit = edit() || mem() ? "1" : "";
left.replaceChildren(
...(edit()
...(edit() || mem()
? [
buildEdit({
doc,
@@ -368,6 +378,7 @@ export function createStackScreen(opt: StackScreenOptions) {
]
: []),
);
left.inert = !!mem(); // 저장 전 문서 = 보기만(고침은 저장 뒤)
right.replaceChildren(
items.length || doc.결과
? buildOut(doc, answer, {
@@ -494,6 +505,26 @@ export function createStackScreen(opt: StackScreenOptions) {
[cut, mark, version] = [{}, undefined, ""];
draw();
if (!next) {
if (mem()) {
// 저장 전 문서(836-5) — 서버가 이 문서째 읽어 줌
const mine = ++seq;
try {
const got = await call<Loaded>("/read", {});
if (mine !== seq || key !== next) return;
take(got);
recalc();
return draw();
} catch (e) {
if (mine === seq)
head.replaceChildren(
el("p", {
className: "ui-text ui-text--muted",
text: `${ft("Load_Failed")} — ${e instanceof Error ? e.message : ""}`,
}),
);
return;
}
}
if (cp)
return void right.replaceChildren(
el("p", { className: "ui-text ui-text--muted", text: lt("Unsaved_New") }),