mirror of https://github.com/openclaw/openclaw.git
refactor(feishu): remove docx table lint suppressions
This commit is contained in:
parent
8f44bd6426
commit
69e67a764d
|
|
@ -0,0 +1,53 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { cleanBlocksForDescendant } from "./docx-table-ops.js";
|
||||
|
||||
describe("cleanBlocksForDescendant", () => {
|
||||
it("removes parent links and read-only table fields while normalizing table cells", () => {
|
||||
const blocks = [
|
||||
{
|
||||
block_id: "table-1",
|
||||
parent_id: "parent-1",
|
||||
block_type: 31,
|
||||
children: "cell-1",
|
||||
table: {
|
||||
property: {
|
||||
row_size: 1,
|
||||
column_size: 1,
|
||||
column_width: [240],
|
||||
},
|
||||
cells: ["cell-1"],
|
||||
merge_info: [{ row_span: 1, col_span: 1 }],
|
||||
},
|
||||
},
|
||||
{
|
||||
block_id: "cell-1",
|
||||
parent_id: "table-1",
|
||||
block_type: 32,
|
||||
children: "text-1",
|
||||
},
|
||||
{
|
||||
block_id: "text-1",
|
||||
parent_id: "cell-1",
|
||||
block_type: 2,
|
||||
text: {
|
||||
elements: [{ text_run: { content: "hello" } }],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const cleaned = cleanBlocksForDescendant(blocks);
|
||||
|
||||
expect(cleaned[0]).not.toHaveProperty("parent_id");
|
||||
expect(cleaned[1]).not.toHaveProperty("parent_id");
|
||||
expect(cleaned[2]).not.toHaveProperty("parent_id");
|
||||
|
||||
expect(cleaned[0]?.table).toEqual({
|
||||
property: {
|
||||
row_size: 1,
|
||||
column_size: 1,
|
||||
column_width: [240],
|
||||
},
|
||||
});
|
||||
expect(cleaned[1]?.children).toEqual(["text-1"]);
|
||||
});
|
||||
});
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import type * as Lark from "@larksuiteoapi/node-sdk";
|
||||
import type { FeishuDocxBlock } from "./docx-types.js";
|
||||
import type { FeishuBlockTable, FeishuDocxBlock } from "./docx-types.js";
|
||||
|
||||
// ============ Table Utilities ============
|
||||
|
||||
|
|
@ -41,6 +41,26 @@ function normalizeChildBlockIds(children: string[] | string | undefined): string
|
|||
return typeof children === "string" ? [children] : [];
|
||||
}
|
||||
|
||||
function omitParentId(block: FeishuDocxBlock): FeishuDocxBlock {
|
||||
const cleanBlock = { ...block };
|
||||
delete cleanBlock.parent_id;
|
||||
return cleanBlock;
|
||||
}
|
||||
|
||||
function createDescendantTable(
|
||||
table: FeishuBlockTable,
|
||||
adaptiveWidths: number[] | undefined,
|
||||
): FeishuBlockTable {
|
||||
const { row_size, column_size } = table.property || {};
|
||||
return {
|
||||
property: {
|
||||
row_size,
|
||||
column_size,
|
||||
...(adaptiveWidths?.length ? { column_width: adaptiveWidths } : {}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function calculateAdaptiveColumnWidths(
|
||||
blocks: FeishuDocxBlock[],
|
||||
tableBlockId: string,
|
||||
|
|
@ -178,8 +198,7 @@ export function cleanBlocksForDescendant(blocks: FeishuDocxBlock[]): FeishuDocxB
|
|||
}
|
||||
|
||||
return blocks.map((block) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { parent_id: _parentId, ...cleanBlock } = block;
|
||||
const cleanBlock = omitParentId(block);
|
||||
|
||||
// Fix: Convert API sometimes returns children as string for TableCell
|
||||
if (cleanBlock.block_type === 32 && typeof cleanBlock.children === "string") {
|
||||
|
|
@ -188,18 +207,8 @@ export function cleanBlocksForDescendant(blocks: FeishuDocxBlock[]): FeishuDocxB
|
|||
|
||||
// Clean table blocks
|
||||
if (cleanBlock.block_type === 31 && cleanBlock.table) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { cells: _cells, ...tableWithoutCells } = cleanBlock.table;
|
||||
const { row_size, column_size } = tableWithoutCells.property || {};
|
||||
const adaptiveWidths = block.block_id ? tableWidths.get(block.block_id) : undefined;
|
||||
|
||||
cleanBlock.table = {
|
||||
property: {
|
||||
row_size,
|
||||
column_size,
|
||||
...(adaptiveWidths?.length && { column_width: adaptiveWidths }),
|
||||
},
|
||||
};
|
||||
cleanBlock.table = createDescendantTable(cleanBlock.table, adaptiveWidths);
|
||||
}
|
||||
|
||||
return cleanBlock;
|
||||
|
|
|
|||
Loading…
Reference in New Issue