Merge remote-tracking branch 'origin/dev' into sub_laptop_6
# Conflicts: # A00_Common/spreadsheet/spreadsheet_grid.ts # A00_Common/spreadsheet/spreadsheet_links.ts
This commit is contained in:
@@ -3,10 +3,9 @@
|
||||
* 복사 · 잘라내기 · 붙여넣기 — `copy` · `cut` · `paste` 사건만(허락 창 없음 · navigator.clipboard 안 씀).
|
||||
* 형 · 수식 살리기 규칙은 `spreadsheet_types.ts` `ClipBlock` 머리. 잘라내기 = 복사 + `내용지움`(누른 순간
|
||||
* 바로 지움) · 붙여넣기 = `칸` 명령(식은 A `moveFormula` · 구글 R1C1 은 `r1c1ToA1`) + 서식 · 병합 명령
|
||||
* 묶음(칸 하나하나). ⚠ 잘라내기는 OS 클립보드를 거치는 비동기 사건(다른 창 · 다른 앱에 붙일 수 있음)이라
|
||||
* `옮기기` 명령(같은 문서 안에서 그 칸을 가리키던 다른 식도 따라감) 은 못 씀 — 잘라낸 칸을 가리키던
|
||||
* 다른 칸의 식은 안 따라옴(엑셀의 「점선 테두리 유지 · 붙일 때만 지움」 도 아님). 편집 중
|
||||
* (`ctx.editor.editing()`)이면 사건을 편집기에 맡김.
|
||||
* 묶음(칸 하나하나). 잘라낸 것을 같은 문서에 처음 붙이면(클립보드 HTML 의 `aislo-cut` 표 · 그 사이 잘라낸
|
||||
* 자리에 새로 안 씀) 지운 칸을 되살려 `옮기기` 명령으로 — 그 칸을 가리키던 다른 식도 따라감(엑셀).
|
||||
* 다른 앱 · 두 번째 붙여넣기는 보통 붙여넣기. 편집 중(`ctx.editor.editing()`)이면 사건을 편집기에 맡김.
|
||||
*
|
||||
* 이음(D `spreadsheet.ts` 잇는 자리) — `attachClipboard(ctx)` 한 번 부름(반환 `root` 없음 · 안 붙여도 됨).
|
||||
* `ctx.root` 의 copy/cut/paste 사건을 직접 받으므로 그 요소가 포커스를 받을 수 있어야 함
|
||||
@@ -14,7 +13,7 @@
|
||||
* ========================================================================== */
|
||||
|
||||
import { showToast } from "@ui/ui_template_elements";
|
||||
import { colName, parseRange, toA1 } from "./spreadsheet_address";
|
||||
import { colName, parseA1, parseRange, toA1 } from "./spreadsheet_address";
|
||||
import { formatValue } from "./spreadsheet_numfmt";
|
||||
import { moveFormula, r1c1ToA1 } from "./spreadsheet_refshift";
|
||||
import { st } from "./spreadsheet_text";
|
||||
@@ -514,23 +513,79 @@ function pasteBlock(ctx: SpreadsheetContext, block: ClipBlock, at: CellAddress):
|
||||
ctx.dispatch(commands.length === 1 ? commands[0] : { 종류: "묶음", 명령: commands });
|
||||
}
|
||||
|
||||
/** A1 칸이 범위 안인가 */
|
||||
function inside(rg: CellRange, a1: string): boolean {
|
||||
const p = parseA1(a1);
|
||||
return !!p && p.r >= rg.r0 && p.r <= rg.r1 && p.c >= rg.c0 && p.c <= rg.c1;
|
||||
}
|
||||
|
||||
interface PendingCut {
|
||||
token: string;
|
||||
sheet: string;
|
||||
range: CellRange;
|
||||
/** 지우기 전 칸 — 같은 문서에 붙일 때 되살려 `옮기기` 로 넘김 */
|
||||
cells: Record<string, Cell>;
|
||||
}
|
||||
|
||||
/** 병합을 가르는지(통째로 든 병합은 됨) — `옮기기` 명령과 같은 규칙 */
|
||||
function cutsMerge(sheet: Sheet, rg: CellRange): boolean {
|
||||
return (sheet.병합 ?? [])
|
||||
.map((m) => parseRange(m))
|
||||
.some((m) => !!m && rangesOverlap(m, rg) && !rangeContains(rg, m));
|
||||
}
|
||||
|
||||
/** `ctx.root` 의 copy · cut · paste 를 받음(root null) */
|
||||
export function attachClipboard(ctx: SpreadsheetContext): PartHandle {
|
||||
function onCopy(ev: ClipboardEvent): void {
|
||||
if (ctx.editor.editing()) return;
|
||||
/** 마지막 잘라내기 — 같은 문서에 붙이면 칸을 옮김(그 칸을 가리키던 식도 따라감 · 엑셀) */
|
||||
let cut: PendingCut | null = null;
|
||||
|
||||
function write(ev: ClipboardEvent, prefix = ""): void {
|
||||
const range = activeRange(ctx);
|
||||
const { html, text } = blockToClipboard(ctx.book, ctx.selection.시트, range, (r, c) =>
|
||||
ctx.engine.value(ctx.selection.시트, r, c),
|
||||
);
|
||||
ev.clipboardData?.setData("text/html", html);
|
||||
ev.clipboardData?.setData("text/html", prefix + html);
|
||||
ev.clipboardData?.setData("text/plain", text);
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
function onCopy(ev: ClipboardEvent): void {
|
||||
if (ctx.editor.editing()) return;
|
||||
cut = null;
|
||||
write(ev);
|
||||
}
|
||||
|
||||
function onCut(ev: ClipboardEvent): void {
|
||||
if (ctx.editor.editing() || ctx.readOnly) return;
|
||||
onCopy(ev);
|
||||
ctx.dispatch({ 종류: "내용지움", 시트: ctx.selection.시트, 범위: [activeRange(ctx)] });
|
||||
const range = activeRange(ctx);
|
||||
const sheet = ctx.sheet();
|
||||
const cells: Record<string, Cell> = {};
|
||||
for (const [a1, cell] of Object.entries(sheet.칸))
|
||||
if (inside(range, a1)) cells[a1] = structuredClone(cell);
|
||||
const token = Math.random().toString(36).slice(2);
|
||||
write(ev, `<!--aislo-cut:${token}-->`);
|
||||
cut = { token, sheet: sheet.id, range, cells };
|
||||
ctx.dispatch({ 종류: "내용지움", 시트: sheet.id, 범위: [range] });
|
||||
}
|
||||
|
||||
/** 잘라낸 칸을 같은 문서 안으로 — 되살린 뒤 `옮기기`(한 번에 되돌림) · 못 하면 false(보통 붙여넣기) */
|
||||
function pasteCut(pending: PendingCut, at: CellAddress): boolean {
|
||||
const src = ctx.book.시트.find((s) => s.id === pending.sheet);
|
||||
if (!src) return false;
|
||||
const { r0, c0, r1, c1 } = pending.range;
|
||||
for (const [a1, cell] of Object.entries(src.칸))
|
||||
if (inside(pending.range, a1) && (cell.값 !== undefined || cell.식 !== undefined))
|
||||
return false; // 잘라낸 뒤 그 자리에 새로 씀
|
||||
const dst = { r0: at.r, c0: at.c, r1: at.r + r1 - r0, c1: at.c + c1 - c0 };
|
||||
if (cutsMerge(src, pending.range) || cutsMerge(ctx.sheet(), dst)) return false;
|
||||
ctx.dispatch({
|
||||
종류: "묶음",
|
||||
명령: [
|
||||
{ 종류: "칸", 시트: src.id, 칸: pending.cells },
|
||||
{ 종류: "옮기기", 시트: src.id, 범위: pending.range, 대상시트: ctx.selection.시트, ...at },
|
||||
],
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
function onPaste(ev: ClipboardEvent): void {
|
||||
@@ -538,6 +593,11 @@ export function attachClipboard(ctx: SpreadsheetContext): PartHandle {
|
||||
const html = ev.clipboardData?.getData("text/html") ?? "";
|
||||
const text = ev.clipboardData?.getData("text/plain") ?? "";
|
||||
const at = ctx.selection.활성;
|
||||
const pending = cut;
|
||||
if (pending && html.includes(`<!--aislo-cut:${pending.token}-->`)) {
|
||||
cut = null; // 엑셀처럼 한 번만 옮김 — 다음부터는 보통 붙여넣기
|
||||
if (pasteCut(pending, at)) return void ev.preventDefault();
|
||||
}
|
||||
const block = parseClipboard(html, text, at);
|
||||
if (!block) {
|
||||
showToast(st("ClipboardPasteFailed"), "error");
|
||||
|
||||
@@ -15,7 +15,8 @@ import type { FuncHelp } from "./spreadsheet_func_help";
|
||||
import { parseFormula, tokenize } from "./spreadsheet_parser";
|
||||
import { cellsOf, move, selectCell } from "./spreadsheet_selection";
|
||||
import { checkValue, findValidation } from "./spreadsheet_validation";
|
||||
import type { Cell, CellAddress, CellStyle, Sheet } from "./spreadsheet_types";
|
||||
import { cellStyleAt } from "./spreadsheet_cellstyle";
|
||||
import type { Cell, CellAddress, CellStyle, Command, Sheet } from "./spreadsheet_types";
|
||||
import type {
|
||||
CellBox,
|
||||
EditorHandle,
|
||||
@@ -89,6 +90,39 @@ export function textToCell(text: string, old?: Cell): Cell | null {
|
||||
return { ...base, 값: text };
|
||||
}
|
||||
|
||||
/** 친 모양대로 숫자 형식(엑셀) — `50%` → `0%` · `12.5%` → `0.0%` · `1,234.5` → `#,##0.0` · 아니면 null */
|
||||
export function typedFormat(text: string): string | null {
|
||||
const t = text.trim();
|
||||
if (parseNumber(t) === null || /e/i.test(t)) return null;
|
||||
const dec = /\.(\d+)/.exec(t)?.[1].length ?? 0;
|
||||
const frac = dec ? "." + "0".repeat(dec) : "";
|
||||
if (t.endsWith("%")) return `0${frac}%`;
|
||||
if (t.includes(",")) return `#,##0${frac}`;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 식 글(앞 `=` 뺌) — 함수 · 참조 · 참거짓을 대문자로(엑셀) · 시트 이름 · 글 · 정의된 이름은 그대로 */
|
||||
export function upperFormula(body: string): string {
|
||||
return tokenize(body)
|
||||
.map((t) => {
|
||||
if (t.kind === "func" || t.kind === "bool") return t.text.toUpperCase();
|
||||
if (t.kind !== "ref") return t.text;
|
||||
const bang = t.text.lastIndexOf("!") + 1;
|
||||
return t.text.slice(0, bang) + t.text.slice(bang).toUpperCase();
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
/** 닫는 괄호만 모자란 식이면 채운 식(엑셀 자동 고침) · 아니면 null */
|
||||
export function closeParens(value: string): string | null {
|
||||
let depth = 0;
|
||||
for (const t of tokenize(value.slice(1)))
|
||||
if (t.kind === "paren") depth += t.text === "(" ? 1 : -1;
|
||||
if (depth <= 0) return null;
|
||||
const fixed = value + ")".repeat(depth);
|
||||
return parseFormula(fixed).ok ? fixed : null;
|
||||
}
|
||||
|
||||
/** 칸 → 편집 글(식은 `=` 붙임 · 수처럼 읽힐 글은 `'` 붙임) */
|
||||
export function cellToText(cell: Cell | undefined): string {
|
||||
if (!cell) return "";
|
||||
@@ -360,7 +394,10 @@ export function createEditor(ctx: SpreadsheetContext): Editor {
|
||||
/** 칸에 적음 — 식이 틀렸거나(인자 수 등) 유효성(sub4) 「막음」 을 어기면 안 적고 false(편집 그대로 · 엑셀처럼 다시 치게) */
|
||||
function write(cells: CellAddress[], value: string, from: CellAddress): boolean {
|
||||
if (!st) return true;
|
||||
const parsed = value.length > 1 && value[0] === "=" ? parseFormula(value) : null;
|
||||
const isFormula = value.length > 1 && value[0] === "=";
|
||||
if (isFormula && !parseFormula(value).ok) value = closeParens(value) ?? value;
|
||||
const parsed = isFormula ? parseFormula(value) : null;
|
||||
if (parsed?.ok) value = "=" + upperFormula(value.slice(1));
|
||||
if (parsed && !parsed.ok) {
|
||||
showToast(parsed.message, "error");
|
||||
const node = src();
|
||||
@@ -389,7 +426,33 @@ export function createEditor(ctx: SpreadsheetContext): Editor {
|
||||
out[key] = next;
|
||||
}
|
||||
for (const m of warn) showToast(m, "warning");
|
||||
if (Object.keys(out).length) ctx.dispatch({ 종류: "칸", 시트: sheet.id, 칸: out });
|
||||
if (!Object.keys(out).length) return true;
|
||||
const cellCmd: Command = { 종류: "칸", 시트: sheet.id, 칸: out };
|
||||
const fmt = isFormula ? null : typedFormat(value);
|
||||
// `%` 는 글 형식(`@`) · 이미 % 형식만 빼고 바꿈 · 천 단위 쉼표는 일반 형식일 때만(엑셀)
|
||||
const takes = (code?: string): boolean =>
|
||||
!code ||
|
||||
/^(general|g\/표준)$/i.test(code) ||
|
||||
(fmt!.endsWith("%") && !code.includes("%") && code.trim() !== "@");
|
||||
const fmtAt = fmt
|
||||
? cells.filter((a) => takes(cellStyleAt(ctx.book, sheet, a.r, a.c).형식))
|
||||
: [];
|
||||
ctx.dispatch(
|
||||
fmtAt.length
|
||||
? {
|
||||
종류: "묶음",
|
||||
명령: [
|
||||
cellCmd,
|
||||
{
|
||||
종류: "서식",
|
||||
시트: sheet.id,
|
||||
범위: fmtAt.map((a) => ({ r0: a.r, c0: a.c, r1: a.r, c1: a.c })),
|
||||
바꿀: { 형식: fmt! },
|
||||
},
|
||||
],
|
||||
}
|
||||
: cellCmd,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
|
||||
.ss-fmtdlg__row select,
|
||||
.ss-fmtdlg__row input[type="text"],
|
||||
.ss-fmtdlg__row input:not([type]),
|
||||
.ss-fmtdlg__row input[type="number"],
|
||||
.ss-fmtdlg__code {
|
||||
height: 28px;
|
||||
|
||||
@@ -185,7 +185,7 @@
|
||||
}
|
||||
|
||||
.aislo-cell.is-error {
|
||||
color: #c00;
|
||||
color: var(--color-danger, #c00);
|
||||
}
|
||||
|
||||
/* 오류 칸 — 엑셀 오류 검사 초록 세모(왼 위 · sub3 오류 까닭은 title 풍선). */
|
||||
@@ -248,3 +248,18 @@
|
||||
.aislo-grid__overlay > * {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* 긴 글 넘침(`spreadsheet_spill.ts`) — 옆 빈 칸 위로 글을 폄 · 덮은 칸 사이 눈금선은 감춤(엑셀) ·
|
||||
* 고치는 중에는 활성 칸 넘침을 감춤(편집기와 안 겹치게). */
|
||||
.aislo-cell.is-spill {
|
||||
overflow: visible;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.aislo-grid--gridlines .aislo-cell.is-spill-r {
|
||||
border-right-color: transparent;
|
||||
}
|
||||
|
||||
.ss--editing .aislo-cell.is-selected.is-spill > .aislo-cell__text {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
} from "./spreadsheet_headers";
|
||||
import { resolveCondFmtStyle, type CondFmtValue } from "./spreadsheet_condfmt";
|
||||
import { formatValue } from "./spreadsheet_numfmt";
|
||||
import { spillOf, type SpillAlign, type SpillSlot } from "./spreadsheet_spill";
|
||||
import { MAX_COLS, MAX_ROWS } from "./spreadsheet_types";
|
||||
import type {
|
||||
CellRange,
|
||||
@@ -139,6 +140,19 @@ function buildMergeMap(sheet: Sheet): Map<string, CellRange> {
|
||||
let measureRuler: CanvasRenderingContext2D | null = null;
|
||||
|
||||
/** 글 너비(px) — 칸 재기용(수가 칸 폭보다 길면 `#####`). */
|
||||
const SPILL_ALIGN: Partial<Record<HAlign, SpillAlign>> = {
|
||||
general: "left",
|
||||
left: "left",
|
||||
right: "right",
|
||||
center: "center",
|
||||
};
|
||||
|
||||
function resetSpill(cell: HTMLElement): void {
|
||||
cell.classList.remove("is-spill", "is-spill-r");
|
||||
const t = cell.firstElementChild as HTMLElement | null;
|
||||
if (t) t.style.width = t.style.marginLeft = t.style.clipPath = "";
|
||||
}
|
||||
|
||||
function measureText(text: string, font: string): number {
|
||||
measureRuler ??= document.createElement("canvas").getContext("2d");
|
||||
if (!measureRuler) return text.length * 7;
|
||||
@@ -417,6 +431,16 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
const sheet = ctx.sheet();
|
||||
const book = ctx.book;
|
||||
const keep = new Set<string>();
|
||||
// 긴 글 넘침 — 줄마다 칸 자리를 모았다가 판을 다 그린 뒤 폄(옆 칸이 빈지 알아야 해서)
|
||||
const slots = new Map<number, Map<number, SpillSlot>>();
|
||||
const longs: {
|
||||
r: number;
|
||||
c: number;
|
||||
el: HTMLElement;
|
||||
own: number;
|
||||
need: number;
|
||||
align: SpillAlign;
|
||||
}[] = [];
|
||||
for (const r of rowsVisible) {
|
||||
for (const c of colsVisible) {
|
||||
const merge = merges.get(`${r},${c}`);
|
||||
@@ -475,6 +499,16 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
}
|
||||
}
|
||||
setCellText(cellEl, text, display.title || comment || undefined);
|
||||
resetSpill(cellEl);
|
||||
if (!merge) {
|
||||
(slots.get(r0) ?? slots.set(r0, new Map()).get(r0)!).set(c0, { w, empty: text === "" });
|
||||
const align = SPILL_ALIGN[display.hAlign];
|
||||
if (align && text && !display.isNumeric && !display.isError && !style.줄바꿈) {
|
||||
// 캔버스 폭은 거르기만(글꼴 대체로 조금 어긋남) — 정확한 폭은 아래서 글 요소 scrollWidth 로
|
||||
const need = measureText(text, cellFont(style, book, zoom)) + 4;
|
||||
if (need > w * 0.9) longs.push({ r: r0, c: c0, el: cellEl, own: w, need, align });
|
||||
}
|
||||
}
|
||||
cellEl.classList.toggle("is-error", display.isError);
|
||||
cellEl.classList.toggle("has-comment", !!comment);
|
||||
cellEl.classList.toggle(
|
||||
@@ -483,6 +517,20 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
);
|
||||
}
|
||||
}
|
||||
// 글 폭 + 칸 안 여백(양쪽 2px) · 오른 선 1px — 읽기를 먼저 몰아 한 번만 배치 계산
|
||||
for (const l of longs) l.need = (l.el.firstElementChild as HTMLElement).scrollWidth + 5;
|
||||
for (const l of longs) {
|
||||
const sp = spillOf(slots.get(l.r)!, l.c, l.own, l.need, l.align);
|
||||
if (!sp) continue;
|
||||
l.el.classList.add("is-spill");
|
||||
const t = l.el.firstElementChild as HTMLElement;
|
||||
t.style.width = `calc(100% + ${sp.left + sp.right}px)`;
|
||||
t.style.marginLeft = `${-sp.left}px`;
|
||||
if (sp.clipLeft || sp.clipRight)
|
||||
t.style.clipPath = `inset(0 ${sp.clipRight}px 0 ${sp.clipLeft}px)`;
|
||||
for (let k = sp.from; k < sp.to; k++)
|
||||
pool.used.get(`${l.r},${k}`)?.classList.add("is-spill-r");
|
||||
}
|
||||
poolSweep(pool, keep);
|
||||
}
|
||||
|
||||
@@ -652,9 +700,9 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
const scrollW = Math.max(0, w - headColW() - frozenW);
|
||||
const scrollH = Math.max(0, h - headRowH() - frozenH);
|
||||
const frozenColsVisible = visibleIndices(colGeo, 0, frozenCols - 1);
|
||||
// 본문 판의 스크롤 0 = 틀고정 경계(frozenW · frozenH) — 시트 자리로 바꿔 재야 아래 · 오른쪽 끝까지 그림
|
||||
const left = frozenW + paneBR.scrollLeft;
|
||||
const top = frozenH + paneBR.scrollTop;
|
||||
// 본문 판 스크롤 0 = 틀고정 바로 다음 칸(`offset(frozen)`) — 그만큼 더해 재야 오른 · 아래 끝이 안 빔.
|
||||
const left = paneBR.scrollLeft + frozenW;
|
||||
const top = paneBR.scrollTop + frozenH;
|
||||
const scrollColFrom = Math.max(frozenCols, colGeo.indexAt(left));
|
||||
const scrollColTo = Math.min(extent.cols - 1, colGeo.indexAt(left + scrollW) + 1);
|
||||
const scrollColsVisible = visibleIndices(
|
||||
@@ -824,14 +872,32 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
node.style.borderWidth = i === 0 ? "2px" : "1px";
|
||||
selLayer!.append(node);
|
||||
}
|
||||
const active = overlayBoxOf(sel.활성.r, sel.활성.c);
|
||||
// 활성 칸 테두리 — 칸 다시 그리기(`renderRowOfCells`) 없이 고름만 바뀌어도 옛 칸에 남지 않게.
|
||||
const activeKey = `${sel.활성.r},${sel.활성.c}`;
|
||||
const anchor = merges.get(activeKey);
|
||||
const activeAddr = toA1(anchor?.r0 ?? sel.활성.r, anchor?.c0 ?? sel.활성.c);
|
||||
for (const el of root.querySelectorAll<HTMLElement>(".aislo-cell.is-selected"))
|
||||
if (el.dataset.addr !== activeAddr) el.classList.remove("is-selected");
|
||||
for (const el of root.querySelectorAll<HTMLElement>(`.aislo-cell[data-addr="${activeAddr}"]`))
|
||||
el.classList.add("is-selected");
|
||||
const handleAt = fillHandleCell();
|
||||
if (!handleAt) return;
|
||||
const corner = overlayBoxOf(handleAt.r, handleAt.c);
|
||||
const handle = document.createElement("div");
|
||||
handle.className = "aislo-grid__fill-handle";
|
||||
handle.style.left = `${active.x + active.w - 4}px`;
|
||||
handle.style.top = `${active.y + active.h - 4}px`;
|
||||
handle.style.left = `${corner.x + corner.w - 4}px`;
|
||||
handle.style.top = `${corner.y + corner.h - 4}px`;
|
||||
selLayer!.append(handle);
|
||||
}
|
||||
|
||||
/** 채우기 손잡이 자리 — 고른 범위 오른아래 칸(엑셀) · 범위가 여럿이거나 읽기 전용이면 없음. */
|
||||
function fillHandleCell(): { r: number; c: number } | null {
|
||||
const sel = ctx.selection;
|
||||
if (ctx.readOnly || !sel || sel.범위.length !== 1) return null;
|
||||
const g = sel.범위[0];
|
||||
return { r: g.r1, c: g.c1 };
|
||||
}
|
||||
|
||||
function setRefHighlights(list: RefHighlight[]): void {
|
||||
let refLayer = overlay.querySelector<HTMLElement>(".aislo-grid__ref-layer");
|
||||
if (!refLayer) {
|
||||
@@ -886,12 +952,11 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
const c = colGeo.indexAt(contentX);
|
||||
const r = rowGeo.indexAt(contentY);
|
||||
const sel = ctx.selection;
|
||||
if (sel && sel.시트 === ctx.sheet().id) {
|
||||
const active = boxOf(sel.활성.r, sel.활성.c);
|
||||
const screen = screenBoxOf(sel.활성.r, sel.활성.c);
|
||||
void active;
|
||||
const handleAt = sel && sel.시트 === ctx.sheet().id ? fillHandleCell() : null;
|
||||
if (handleAt) {
|
||||
const screen = screenBoxOf(handleAt.r, handleAt.c);
|
||||
if (Math.abs(x - (screen.x + screen.w)) <= 5 && Math.abs(y - (screen.y + screen.h)) <= 5) {
|
||||
return { kind: "fillHandle", r: sel.활성.r, c: sel.활성.c };
|
||||
return { kind: "fillHandle", r: handleAt.r, c: handleAt.c };
|
||||
}
|
||||
}
|
||||
return { kind: "cell", r, c };
|
||||
@@ -923,11 +988,11 @@ export function createGrid(ctx: SpreadsheetContext): GridHandle {
|
||||
function visibleRange(): CellRange {
|
||||
const scrollW = Math.max(0, root.clientWidth - headColW() - frozenW);
|
||||
const scrollH = Math.max(0, root.clientHeight - headRowH() - frozenH);
|
||||
const top = frozenH + paneBR.scrollTop;
|
||||
const left = frozenW + paneBR.scrollLeft;
|
||||
const left = paneBR.scrollLeft + frozenW;
|
||||
const top = paneBR.scrollTop + frozenH;
|
||||
return {
|
||||
r0: Math.max(frozenRows, rowGeo.indexAt(top)),
|
||||
c0: Math.max(frozenCols, colGeo.indexAt(left)),
|
||||
r0: rowGeo.indexAt(top),
|
||||
c0: colGeo.indexAt(left),
|
||||
r1: Math.min(extent.rows - 1, rowGeo.indexAt(top + scrollH)),
|
||||
c1: Math.min(extent.cols - 1, colGeo.indexAt(left + scrollW)),
|
||||
};
|
||||
|
||||
@@ -209,7 +209,7 @@ export function mountLinks(
|
||||
e.preventDefault();
|
||||
const inList = opts?.모드 === "자재" && items.some((i) => i.키 === item.키);
|
||||
if (ctx.readOnly || !(hit || inList)) return;
|
||||
const o = ctx.root.getBoundingClientRect(); // 메뉴는 부품 뿌리 기준 자리
|
||||
const o = ctx.root.getBoundingClientRect(); // 메뉴는 부품 안 절대 위치 — 누른 자리에 뜨게
|
||||
menu.open(e.clientX - o.left, e.clientY - o.top, [
|
||||
...(hit ? [[TEXT.unlink, () => (unlink(), back())] as [string, () => void]] : []),
|
||||
...(inList
|
||||
|
||||
@@ -184,7 +184,7 @@ export function parseFormula(formula: string): ParseResult {
|
||||
};
|
||||
const primary = (): FormulaNode => {
|
||||
const t = peek();
|
||||
if (!t) throw new Fail("식이 끝남", text.length);
|
||||
if (!t) throw new Fail("식이 덜 끝남", text.length);
|
||||
p++;
|
||||
switch (t.kind) {
|
||||
case "number":
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* =============================================================================
|
||||
* spreadsheet_spill.ts
|
||||
* 긴 글 넘침(엑셀) — 칸보다 긴 글을 옆 빈 칸 위로 보임. 왼쪽 · 일반 맞춤은 오른쪽으로 · 오른쪽 맞춤은
|
||||
* 왼쪽으로 · 가운데는 양쪽으로. 비지 않은 칸 · 병합 칸 · 판 끝(틀 고정 경계 · 그린 범위 밖)에서 멈춤.
|
||||
* 격자(`spreadsheet_grid.ts`)가 판 하나를 그릴 때 줄마다 칸 자리(`slots`)를 모아 부름 — 계산만 여기.
|
||||
* ========================================================================== */
|
||||
|
||||
/** 같은 판 · 같은 줄 · 병합 아닌 칸 하나(병합 칸 · 안 그린 칸은 넣지 않음 → 거기서 멈춤) */
|
||||
export interface SpillSlot {
|
||||
w: number;
|
||||
empty: boolean;
|
||||
}
|
||||
|
||||
/** 넘침 — 왼 · 오른쪽으로 더 쓸 폭(px) · 덮은 칸 열 범위 · 가운데 맞춤이 한쪽만 막혀 잘라 낼 폭 */
|
||||
export interface Spill {
|
||||
left: number;
|
||||
right: number;
|
||||
from: number;
|
||||
to: number;
|
||||
/** 가운데 맞춤 — 글 상자는 양쪽 반씩 늘리고 막힌 쪽은 이만큼 잘라 냄(글은 칸 가운데 그대로) */
|
||||
clipLeft: number;
|
||||
clipRight: number;
|
||||
}
|
||||
|
||||
export type SpillAlign = "left" | "right" | "center";
|
||||
|
||||
/** 칸 c(폭 own)의 글 폭 need 가 넘치면 정렬 쪽 빈 칸으로 늘린 결과 · 안 넘치거나 못 늘리면 null */
|
||||
export function spillOf(
|
||||
slots: Map<number, SpillSlot>,
|
||||
c: number,
|
||||
own: number,
|
||||
need: number,
|
||||
align: SpillAlign,
|
||||
): Spill | null {
|
||||
if (need <= own) return null;
|
||||
let from = c;
|
||||
let to = c;
|
||||
const grow = (dir: -1 | 1, want: number): number => {
|
||||
let got = 0;
|
||||
for (let k = c + dir; got < want; k += dir) {
|
||||
const s = slots.get(k);
|
||||
if (!s || !s.empty) break;
|
||||
got += s.w;
|
||||
if (dir < 0) from = k;
|
||||
else to = k;
|
||||
}
|
||||
return got;
|
||||
};
|
||||
if (align === "center") {
|
||||
const half = (need - own) / 2;
|
||||
const l = Math.min(grow(-1, half), half);
|
||||
const r = Math.min(grow(1, half), half);
|
||||
if (!l && !r) return null;
|
||||
return { left: half, right: half, from, to, clipLeft: half - l, clipRight: half - r };
|
||||
}
|
||||
const got = grow(align === "right" ? -1 : 1, need - own);
|
||||
if (!got) return null;
|
||||
return align === "right"
|
||||
? { left: got, right: 0, from, to, clipLeft: 0, clipRight: 0 }
|
||||
: { left: 0, right: got, from, to, clipLeft: 0, clipRight: 0 };
|
||||
}
|
||||
Reference in New Issue
Block a user