feat(est-test): preserve nested JDL details

This commit is contained in:
2026-11-09 19:25:37 +09:00
parent cdf0e46914
commit 7317dbe4e5
12 changed files with 405 additions and 32 deletions
+10 -15
View File
@@ -1,5 +1,6 @@
const zlib = require("node:zlib");
const quantity = require("./native-quantity.cjs");
const { rowParser } = require("./wpt-parse.cjs");
const { calculateQuantity } = require("./quantity-calculate.cjs");
const { memoryRows } = require("./import-estx.cjs");
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
@@ -162,8 +163,7 @@ function editDocument(text, oldSheet, sheet) {
oldSheet.rows.length !== sheet.rows.length
)
throw Error("수량산출서 목록·연결·행 구조 변경은 ESTX 저장을 지원하지 않습니다.");
const declarations = [...text.matchAll(/<(?:cs|begin)\b[^>]*>/gi)].map((m) => m[0]).join("");
const parse = (div) => quantity.fromWpt("", "", declarations + div, [], {}).rows;
const parse = rowParser(text);
let rowIndex = 0;
const result = text.replace(/<div\b[^>]*>[\s\S]*?<\/div>/gi, (div) => {
const parsed = parse(div);
@@ -258,11 +258,11 @@ function insertRows(text, sheet, inserts) {
staged = next;
return { at, snippet };
});
const declarations = [...text.matchAll(/<(?:cs|begin)\b[^>]*>/gi)].map((m) => m[0]).join("");
const parse = rowParser(text);
let index = 0;
const stylePosition = text.search(/<cs\s+nr=1\b/i);
const updated = text.replace(/<div\b[^>]*>[\s\S]*?<\/div>/gi, (div, offset) => {
if (!quantity.fromWpt("", "", declarations + div, [], {}).rows.length) return div;
if (!parse(div).length) return div;
const before = snippets
.filter((item) => item.at === index)
.map((item) => item.snippet)
@@ -282,13 +282,13 @@ function insertRows(text, sheet, inserts) {
}
function removeRows(text, sheet, codes, plainIndexes = new Set()) {
const declarations = [...text.matchAll(/<(?:cs|begin)\b[^>]*>/gi)].map((m) => m[0]).join("");
const parse = rowParser(text);
const tags = tagCounts(text);
let index = 0;
const removed = new Set();
const removedPlain = new Set();
const document = text.replace(/<div\b[^>]*>[\s\S]*?<\/div>/gi, (div) => {
const parsed = quantity.fromWpt("", "", declarations + div, [], {}).rows;
const parsed = parse(div);
if (!parsed.length) return div;
const rowIndex = index++,
row = sheet.rows[rowIndex],
@@ -368,17 +368,12 @@ function reorderRows(text, sheet, rows) {
}
if (order.length !== sheet.rows.length || order.every((value, index) => value === index))
return { text, rows: sheet.rows };
const declarations = [...text.matchAll(/<(?:cs|begin)\b[^>]*>/gi)].map((m) => m[0]).join("");
const parse = rowParser(text);
const divs = [...text.matchAll(/<div\b[^>]*>[\s\S]*?<\/div>/gi)].filter(
(match) => quantity.fromWpt("", "", declarations + match[0], [], {}).rows.length,
(match) => parse(match[0]).length,
);
if (divs.length !== sheet.rows.length) throw Error("수량산출서 원본 행 대응 오류");
if (
divs.some(
(match, index) =>
!same(quantity.fromWpt("", "", declarations + match[0], [], {}).rows[0], sheet.rows[index]),
)
)
if (divs.some((match, index) => !same(parse(match[0])[0], sheet.rows[index])))
throw Error("수량산출서 원본 행 대응 오류");
const changed = order
.map((source, index) => (source === index ? -1 : index))
@@ -413,7 +408,7 @@ function reorderRows(text, sheet, rows) {
}
let index = 0;
const document = text.replace(/<div\b[^>]*>[\s\S]*?<\/div>/gi, (div) => {
if (!quantity.fromWpt("", "", declarations + div, [], {}).rows.length) return div;
if (!parse(div).length) return div;
return divs[order[index++]][0];
});
return { text: document, rows: order.map((source) => sheet.rows[source]) };