Repository navigation
[lexical-list] Feature: opt-in Word list paste overlay - #9082
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
You can still define a WordListImportExtension that simply configures DOMImportExtension appropriately, e.g.
const WordListImportExtension = defineExtension({
name: '@lexical/list/WordListImport',
dependencies: [configExtension(DOMImportExtension, {
preprocess: [$installWordListPasteOverlay],
})],
});We don't actually need to export $installWordListPasteOverlay
Replaces the $installWordListPasteOverlay export with a WordListImportExtension that configures DOMImportExtension itself, so opting in is one dependency rather than a configExtension block. The preprocess is now module-private.
|
Done — One deviation from your snippet worth a second: I also put |
Closes #4922.
MS Word pastes have no
<ol>/<ul>/<li>at all: a list is a flat run of<p class="MsoListParagraph*">siblings whose marker ("1.", "·", "a)") lives in a nested<span style="mso-list:Ignore">, withstyle="mso-list:l<N> level<M> lfo<X>"on the paragraph naming the list and its nesting depth. Nothing in the import pipeline reads that, so a pasted Word list arrives as a run of paragraphs.Per @etrepum on #4922 ("If it can be opt-in and tree-shakeable in
@lexical/listthat should be fine"), this ships the handling as an opt-in extension.ListExtensiondoes not depend on it, so an editor that never pastes from Word pays nothing:The preprocess looks once for
<meta name="Generator" content="Microsoft Word…">and only then pushes the overlay ontoImportOverlays; the overlay's rule walks forward through siblings to collect a complete run and rebuilds it as a nestedListNodetree following the$isNestedListNodeconvention. Pastes from other sources pay only the detection cost.The rules, the overlay, the import state and the extension are module-scope
/* @__PURE__ */calls in a module of their own, so a bundle that never namesWordListImportExtensiondrops all of it. The preprocess itself is module-private.Deduplication
The logic was already in the repo twice, in two versions that disagreed. Both are deleted and now use the shipped export:
dev-examples/dom-import/src/wordPaste.tspackages/lexical-list/src/__tests__/unit/ListImportExtension.test.tsNet −112 lines.
The
data-mso-listsnapshotThe shipped version keeps the example's behaviour, which the test copy lacked. Real Word output carries a
<style>block, so the default$inlineStylesFromStyleSheetspreprocess rewrites every matched element's style attribute throughCSSStyleDeclaration.setProperty— which re-serializes it and silently dropsmso-list, a non-standard property. The overlay's preprocess runs first and snapshotsmso-listontodata-mso-list, which survives that pass.The test copy had no snapshot and its fixture had no
<style>block, so nothing exercised it.survives the stylesheet-inlining preprocesscloses that gap with realistic Word CSS: without the snapshot every item reads as level 1 and the nested outline collapses (3 top-level items become 4); with it, the tree is correct.Test plan
pnpm run test-unit packages/lexical-list— 126 passed.tsc,flow,eslintandprettier --checkall clean.The
<o:p>rule (Office's paragraph-end marker, emitted inside every Word paragraph) rides along in the overlay since the list paragraphs contain them. Happy to drop it if it doesn't belong in@lexical/list.The docs section in
serialization/dom-import.mdthat hand-rolled this same overlay now points at the shipped extension.