Skip to content

Commit

Permalink
feat:Add autho and date to insert / delete (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb authored Dec 20, 2019
1 parent e634a8b commit ef0b04a
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 51 deletions.
44 changes: 32 additions & 12 deletions docx-wasm/pkg/docx_rs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
export function createLevel(id: number, start: number, format: string, text: string, jc: string): Level;
/**
* @param {Run} run
* @returns {Delete}
*/
export function createDelete(run: Run): Delete;
/**
* @param {Run} run
* @returns {Insert}
*/
export function createInsert(run: Run): Insert;
Expand All @@ -23,10 +18,10 @@ export function createInsert(run: Run): Insert;
*/
export function createDocx(): Docx;
/**
* @param {number} id
* @returns {Numbering}
* @param {Run} run
* @returns {Delete}
*/
export function createNumbering(id: number): Numbering;
export function createDelete(run: Run): Delete;
/**
* @returns {Table}
*/
Expand All @@ -36,22 +31,27 @@ export function createTable(): Table;
*/
export function createParagraph(): Paragraph;
/**
* @returns {Run}
* @param {number} id
* @returns {Numbering}
*/
export function createRun(): Run;
export function createNumbering(id: number): Numbering;
/**
* @returns {TableCell}
*/
export function createTableCell(): TableCell;
/**
* @returns {TableRow}
* @returns {Run}
*/
export function createTableRow(): TableRow;
export function createRun(): Run;
/**
* @param {number} id
* @returns {Comment}
*/
export function createComment(id: number): Comment;
/**
* @returns {TableRow}
*/
export function createTableRow(): TableRow;
export enum StyleType {
Paragraph,
Character,
Expand Down Expand Up @@ -146,6 +146,16 @@ export class Comment {
*/
export class Delete {
free(): void;
/**
* @param {string} author
* @returns {Delete}
*/
author(author: string): Delete;
/**
* @param {string} date
* @returns {Delete}
*/
date(date: string): Delete;
}
/**
*/
Expand Down Expand Up @@ -175,6 +185,16 @@ export class Docx {
*/
export class Insert {
free(): void;
/**
* @param {string} author
* @returns {Insert}
*/
author(author: string): Insert;
/**
* @param {string} date
* @returns {Insert}
*/
date(date: string): Insert;
}
/**
*/
Expand Down
90 changes: 65 additions & 25 deletions docx-wasm/pkg/docx_rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ function _assertClass(instance, klass) {
}
return instance.ptr;
}
/**
* @param {Run} run
* @returns {Delete}
*/
export function createDelete(run) {
_assertClass(run, Run);
const ptr0 = run.ptr;
run.ptr = 0;
const ret = wasm.createDelete(ptr0);
return Delete.__wrap(ret);
}

/**
* @param {Run} run
* @returns {Insert}
Expand Down Expand Up @@ -121,12 +109,15 @@ function getArrayU8FromWasm(ptr, len) {
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @param {number} id
* @returns {Numbering}
* @param {Run} run
* @returns {Delete}
*/
export function createNumbering(id) {
const ret = wasm.createNumbering(id);
return Numbering.__wrap(ret);
export function createDelete(run) {
_assertClass(run, Run);
const ptr0 = run.ptr;
run.ptr = 0;
const ret = wasm.createDelete(ptr0);
return Delete.__wrap(ret);
}

/**
Expand Down Expand Up @@ -160,11 +151,12 @@ export function createParagraph() {
}

/**
* @returns {Run}
* @param {number} id
* @returns {Numbering}
*/
export function createRun() {
const ret = wasm.createRun();
return Run.__wrap(ret);
export function createNumbering(id) {
const ret = wasm.createNumbering(id);
return Numbering.__wrap(ret);
}

/**
Expand All @@ -176,11 +168,11 @@ export function createTableCell() {
}

/**
* @returns {TableRow}
* @returns {Run}
*/
export function createTableRow() {
const ret = wasm.createTableRow();
return TableRow.__wrap(ret);
export function createRun() {
const ret = wasm.createRun();
return Run.__wrap(ret);
}

/**
Expand All @@ -192,6 +184,14 @@ export function createComment(id) {
return Comment.__wrap(ret);
}

/**
* @returns {TableRow}
*/
export function createTableRow() {
const ret = wasm.createTableRow();
return TableRow.__wrap(ret);
}

let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();
Expand Down Expand Up @@ -332,6 +332,26 @@ export class Delete {

wasm.__wbg_delete_free(ptr);
}
/**
* @param {string} author
* @returns {Delete}
*/
author(author) {
const ptr = this.ptr;
this.ptr = 0;
const ret = wasm.delete_author(ptr, passStringToWasm(author), WASM_VECTOR_LEN);
return Delete.__wrap(ret);
}
/**
* @param {string} date
* @returns {Delete}
*/
date(date) {
const ptr = this.ptr;
this.ptr = 0;
const ret = wasm.delete_date(ptr, passStringToWasm(date), WASM_VECTOR_LEN);
return Delete.__wrap(ret);
}
}
/**
*/
Expand Down Expand Up @@ -418,6 +438,26 @@ export class Insert {

wasm.__wbg_insert_free(ptr);
}
/**
* @param {string} author
* @returns {Insert}
*/
author(author) {
const ptr = this.ptr;
this.ptr = 0;
const ret = wasm.insert_author(ptr, passStringToWasm(author), WASM_VECTOR_LEN);
return Insert.__wrap(ret);
}
/**
* @param {string} date
* @returns {Insert}
*/
date(date) {
const ptr = this.ptr;
this.ptr = 0;
const ret = wasm.insert_date(ptr, passStringToWasm(date), WASM_VECTOR_LEN);
return Insert.__wrap(ret);
}
}
/**
*/
Expand Down
32 changes: 18 additions & 14 deletions docx-wasm/pkg/docx_rs_bg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ export const memory: WebAssembly.Memory;
export function __wbg_level_free(a: number): void;
export function createLevel(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number;
export function level_indent(a: number, b: number, c: number, d: number, e: number): number;
export function __wbg_delete_free(a: number): void;
export function createDelete(a: number): number;
export function __wbg_insert_free(a: number): void;
export function createInsert(a: number): number;
export function insert_author(a: number, b: number, c: number): number;
export function insert_date(a: number, b: number, c: number): number;
export function __wbg_docx_free(a: number): void;
export function createDocx(): number;
export function docx_add_paragraph(a: number, b: number): number;
export function docx_add_table(a: number, b: number): number;
export function docx_add_numbering(a: number, b: number): number;
export function docx_build(a: number, b: number): void;
export function __wbg_numbering_free(a: number): void;
export function createNumbering(a: number): number;
export function numbering_add_level(a: number, b: number): number;
export function __wbg_delete_free(a: number): void;
export function createDelete(a: number): number;
export function delete_author(a: number, b: number, c: number): number;
export function delete_date(a: number, b: number, c: number): number;
export function __wbg_table_free(a: number): void;
export function createTable(): number;
export function table_add_row(a: number, b: number): number;
Expand All @@ -36,6 +37,15 @@ export function paragraph_align(a: number, b: number): number;
export function paragraph_style(a: number, b: number, c: number): number;
export function paragraph_indent(a: number, b: number, c: number, d: number, e: number): number;
export function paragraph_numbering(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;
export function __wbg_tablecell_free(a: number): void;
export function createTableCell(): number;
export function tablecell_add_paragraph(a: number, b: number): number;
export function tablecell_vertical_merge(a: number, b: number): number;
export function tablecell_grid_span(a: number, b: number): number;
export function tablecell_width(a: number, b: number): number;
export function __wbg_run_free(a: number): void;
export function createRun(): number;
export function run_add_text(a: number, b: number, c: number): number;
Expand All @@ -49,21 +59,15 @@ export function run_bold(a: number): number;
export function run_italic(a: number): number;
export function run_underline(a: number, b: number, c: number): number;
export function run_vanish(a: number): number;
export function __wbg_tablecell_free(a: number): void;
export function createTableCell(): number;
export function tablecell_add_paragraph(a: number, b: number): number;
export function tablecell_vertical_merge(a: number, b: number): number;
export function tablecell_grid_span(a: number, b: number): number;
export function tablecell_width(a: number, b: number): number;
export function __wbg_tablerow_free(a: number): void;
export function createTableRow(): number;
export function tablerow_add_cell(a: number, b: number): number;
export function __wbg_comment_free(a: number): void;
export function createComment(a: number): number;
export function comment_author(a: number, b: number, c: number): number;
export function comment_date(a: number, b: number, c: number): number;
export function comment_paragraph(a: number, b: number): number;
export function comment_id(a: number): number;
export function __wbg_tablerow_free(a: number): void;
export function createTableRow(): number;
export function tablerow_add_cell(a: number, b: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export function __wbindgen_free(a: number, b: number): void;
Binary file modified docx-wasm/pkg/docx_rs_bg.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions docx-wasm/src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ impl Delete {
pub fn take(self) -> docx_core::Delete {
self.0
}
}

#[wasm_bindgen]
impl Delete {
pub fn author(mut self, author: String) -> Delete {
self.0.author = author;
self
Expand Down
3 changes: 3 additions & 0 deletions docx-wasm/src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ impl Insert {
pub fn take(self) -> docx_core::Insert {
self.0
}
}

#[wasm_bindgen]
impl Insert {
pub fn author(mut self, author: String) -> Insert {
self.0.author = author;
self
Expand Down

0 comments on commit ef0b04a

Please sign in to comment.