Skip to content

RoosterJs 9.5.0

Compare
Choose a tag to compare
@JiuqingSong JiuqingSong released this 10 Jun 18:34
· 219 commits to release since this release
a681123

Breaking change notification

When upgrade to 9.5.0, you may see build time failure that complains some object is readonly. This is expected.

From 9.5.0, the API formatContentModel will give you a readonly content model. To modify it, you need to call mutateBlock
to the blocks that you want to modify. For example:

const block = model.blocks[0]; // Assume we have a block here

block.format.direction = 'ltr'; // Error: Cannot modify readonly properties

const mutableBlock = mutateBlock(block);

mutableBlock.format.direction = 'ltr'; // OK

Similary, if you want to modify a segment under a block, you can do any of below:

function test1(para: ReadonlyContentModelParagraph) {
  para.segments[0].format.fontSize = '10pt'; // Error, segments[0] is readonly
  
  const mutableBlock = mutateBlock(para); // Once convert to mutable object, all its segments are also mutable now
  
  mutableBlock.segments[0].format.fontSize = '10pt'; // OK
}

function test2(para: ReadonlyContentModelParagraph, segment: ReadonlyContentModelSegment) {
  mutateSegment(para, segment, (mutablePara, mutableSegment) => {
    mutableSegment.format.fontSize = '10pt'; // OK
  }
}

With API mutateSegment, it allows you convert a segment to be mutable without re-retrieving it from the paragraph.
Note that this API only work when thet given segment is actually a direct child of the given paragraph, otherwise
the callback will not be called.

There are some other functions that can also convert result to be mutable by adding a parameter, for example

const segments = getSelectedSegments(model, false /*includingFormatHolder*/, true /*mutate*/);

The 3rd parameter "true" makes the return value mutable. This parameter is also supported by the following functions:

  • getSelectedSegmentsAndParagraphs
  • getSelectedSegments
  • getSelectedParagraphs

Please note that when convert a block to be mutable, it will lose its cached DOM element. So next time when rewrite to DOM tree,
it will need to be regenerated. So to improve performance (this need to turn on an experimental feature "PersistCache" for now),
try not convert object to be mutable until you really need to.

To enable the experimental feature to improve cache, do

const editor = new Editor(div, {
   ...
   experimentalFeatures: ['PersistCache']
});

Bug fix

  • Fix cut table issue (#2659)
  • Fix paste narrow content issue (#2661)
  • Fix scroll issue when press SHIFT+TAB in table (#2654)
  • Table edit back fixes (#2664, #2678)
  • Fix auto format trigger event (#2684)

Improvement

  • Readonly types improvement (#2649, #2650, #2651)
  • Fix line height issue when paste from Word (#2677)
  • Port ImageEdit plugin (#2670, #2561)
  • Merge Link & Image Format when using MergeModel (#2681)
  • Provide our own implementation of scrollCaretIntoView (#2685)
  • Let Content Model handle ENTER key (#2610)
  • Allow customization of color key generation (#2682)
  • Skip same format from LI (#2683)

Engineering improvement

  • Fix test issue in TableEditPlugin (#2675)
  • Add readme file for roosterjs-editor-adapter package (#2674)
  • Delete legacy packages (#2660)