diff --git a/docx-core/src/documents/elements/table.rs b/docx-core/src/documents/elements/table.rs index c072a8a..1b6b1ee 100644 --- a/docx-core/src/documents/elements/table.rs +++ b/docx-core/src/documents/elements/table.rs @@ -5,8 +5,8 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Table { pub rows: Vec, + pub grid: Vec, property: TableProperty, - grid: Vec, } impl Table { diff --git a/docx-wasm/pkg/.gitignore b/docx-wasm/pkg/.gitignore index 234d3f7..f59ec20 100644 --- a/docx-wasm/pkg/.gitignore +++ b/docx-wasm/pkg/.gitignore @@ -1 +1 @@ -# * \ No newline at end of file +* \ No newline at end of file diff --git a/docx-wasm/pkg/index.d.ts b/docx-wasm/pkg/index.d.ts index 730691c..7ff0ee3 100644 --- a/docx-wasm/pkg/index.d.ts +++ b/docx-wasm/pkg/index.d.ts @@ -321,6 +321,11 @@ export class Table { * @returns {Table} */ add_row(row: TableRow): Table; +/** +* @param {Uint32Array} grid +* @returns {Table} +*/ + set_grid(grid: Uint32Array): Table; } /** */ diff --git a/docx-wasm/pkg/index.js b/docx-wasm/pkg/index.js index d39d22c..b1bef5f 100644 --- a/docx-wasm/pkg/index.js +++ b/docx-wasm/pkg/index.js @@ -160,6 +160,20 @@ export function createTable() { return Table.__wrap(ret); } +let cachegetUint32Memory = null; +function getUint32Memory() { + if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) { + cachegetUint32Memory = new Uint32Array(wasm.memory.buffer); + } + return cachegetUint32Memory; +} + +function passArray32ToWasm(arg) { + const ptr = wasm.__wbindgen_malloc(arg.length * 4); + getUint32Memory().set(arg, ptr / 4); + WASM_VECTOR_LEN = arg.length; + return ptr; +} /** * @param {number} id * @returns {Numbering} @@ -912,6 +926,18 @@ export class Table { const ret = wasm.table_add_row(ptr, ptr0); return Table.__wrap(ret); } + /** + * @param {Uint32Array} grid + * @returns {Table} + */ + set_grid(grid) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.table_set_grid(ptr, passArray32ToWasm(grid), WASM_VECTOR_LEN); + return Table.__wrap(ret); + } } /** */ diff --git a/docx-wasm/pkg/index_bg.d.ts b/docx-wasm/pkg/index_bg.d.ts index bed9c88..1d4ff33 100644 --- a/docx-wasm/pkg/index_bg.d.ts +++ b/docx-wasm/pkg/index_bg.d.ts @@ -40,6 +40,7 @@ export function createInsert(): number; export function __wbg_table_free(a: number): void; export function createTable(): number; export function table_add_row(a: number, b: number): number; +export function table_set_grid(a: number, b: number, c: number): number; export function __wbg_numbering_free(a: number): void; export function createNumbering(a: number): number; export function numbering_add_level(a: number, b: number): number; diff --git a/docx-wasm/pkg/index_bg.wasm b/docx-wasm/pkg/index_bg.wasm index b7e9305..e32ff36 100644 Binary files a/docx-wasm/pkg/index_bg.wasm and b/docx-wasm/pkg/index_bg.wasm differ diff --git a/docx-wasm/src/table.rs b/docx-wasm/src/table.rs index c531bb3..c5ba9eb 100644 --- a/docx-wasm/src/table.rs +++ b/docx-wasm/src/table.rs @@ -23,4 +23,9 @@ impl Table { self.0.rows.push(row.take()); self } + + pub fn set_grid(mut self, grid: Vec) -> Table { + self.0.grid = grid; + self + } }