Skip to content

how to design/insert a table without too many events #868

@sunnyawake5

Description

@sunnyawake5

hi,
i'm experimenting implementing a richtext editor based on canvas.
my loro doc structrue look like this:


LoroDoc{
    body:LoroList[
        paragraph:LoroMap{
            pPr:{},
            text:LoroText
        },
        table:LoroMap{
            tblPr:{},
            columns:number[],
            rows:LoroList[
                row:LoroMap{
                    rowPr:{},
                    cells:LoroList[
                        LoroMap{
                            cellPr:{},
                            body:body
                        }
                    ]
                }
            ]
        }
    ]
}

insert table code:

let table = {
    sid: p.sid,
    rows,
    columns,
  } as Tbl;
  let lbody = body.lbody as LoroList;
  let index = body.blocks.indexOf(p);
  tbl2ltable(lbody, table,index + 1);

  model.ldoc.commit()

tbl2ltable:


export function tbl2ltable(lbody:LoroList, tbl: Tbl,index) {
  let lb = index===-1?lbody.pushContainer(new LoroMap()):lbody.insertContainer(index,new LoroMap);
  lb.set("type", "tbl");
  let lrows = lb.setContainer("content", new LoroList());
  for (let row of tbl.rows) {
    let lrow = lrows.pushContainer(new LoroMap());
    let lcells = lrow.setContainer("content", new LoroList());
    for (let cell of row.cells) {
      let lcell = lcells.pushContainer(new LoroMap());
      let lbody = lcell.setContainer("content", new LoroList());
      body2lbody(cell, lbody);
    }
  }
}

my problem is when inserting a new table, too many events in subscribe call back.
what i want is only captureing the main event: inserting table(LoroMap) and ignore the other child events.
how to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions