facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.98k stars 1.7k forks source link

[lexical] Feature: Add onUpdate function during update with $onUpdate (correct baselline) #6773

Closed landisdesign closed 3 weeks ago

landisdesign commented 4 weeks ago

Description

Adds $onUpdate(fn) to allow an in-progress update/command to append a function to the _deferred stack.

Closes #6767

Test plan

Before

This functionality did not exist. Calling editor.update with an onUpdate function was the only way to perform an action after an update.

After

Performing an update such as:

editor.update(() => {
  // perform updates
  $onUpdate(() => {
    console.log('second onUpdate);
  });
}, {
  onUpdate: () => {
    console.log('first onUpdate');
  }
});

would emit first onUpdate, followed by second onUpdate, once the updates were flushed. This is essentially what the unit test does.

Successful unit test results
vercel[bot] commented 4 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 3:45pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 3:45pm
github-actions[bot] commented 4 weeks ago

size-limit report 📦

Path Size
lexical - cjs 29.92 KB (0%)
lexical - esm 29.75 KB (0%)
@lexical/rich-text - cjs 38.57 KB (0%)
@lexical/rich-text - esm 31.65 KB (0%)
@lexical/plain-text - cjs 37.18 KB (0%)
@lexical/plain-text - esm 28.94 KB (0%)
@lexical/react - cjs 40.24 KB (0%)
@lexical/react - esm 33.01 KB (0%)
landisdesign commented 4 weeks ago

Looks good to me! I think the only thing missing here is a flow definition

Doh! TS fanboy here. Let me get that in.