$withCompactExport
functionRun `f` writing the compact form of the document (or, with `false`, the legacy form), for any export it performs: the `@lexical/clipboard` selection export, a serialization walk of your own, and the nested editors those serialize. A whole document states its form at the call site instead — `editorState.toJSON(true)` — which is what lets its return type say which shape it is; this is for the walks that have no such argument to take. The compact form omits every property parsing would restore anyway — one whose value is its schema default, one the parser derives rather than reads, and the deprecated `version` — so the two forms describe the same document. It can only be read by a Lexical new enough to restore them, so keep writing the legacy form until every reader is upgraded. `f` must be synchronous. The form is restored as soon as it returns, so an `async` callback would give up the form at its first `await` and export in whatever form is ambient when it resumes. A callback whose return type is a promise is rejected at the call site by the trailing parameter, which is an empty tuple for every other type; the runtime check behind it is for an untyped caller, and runs in every build, because the failure it catches is a document written in the wrong form rather than a degraded experience.
Import
import { $withCompactExport } from '@modular/sdk/editor';Notes
- example
- ```ts const selectionJSON = $withCompactExport(true, () => $generateJSONFromSelectedNodes(editor, $getSelection()), ); ```