Skip to content

[lexical-list] Feature: opt-in Word list paste overlay - #9082

Merged
etrepum merged 6 commits into
meta:mainfrom
smrifat1411:feat/word-list-paste-overlay
Aug 20, 2026
Merged

etrepum merged 6 commits into
meta:mainfrom
smrifat1411:feat/word-list-paste-overlay

Conversation

@smrifat1411

@smrifat1411 smrifat1411 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

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">, with style="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/list that should be fine"), this ships the handling as an opt-in extension. ListExtension does not depend on it, so an editor that never pastes from Word pays nothing:

defineExtension({
  dependencies: [WordListImportExtension],
  name: 'my-editor',
});

The preprocess looks once for <meta name="Generator" content="Microsoft Word…"> and only then pushes the overlay onto ImportOverlays; the overlay's rule walks forward through siblings to collect a complete run and rebuilds it as a nested ListNode tree following the $isNestedListNode convention. 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 names WordListImportExtension drops 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.ts
  • the inline copy in packages/lexical-list/src/__tests__/unit/ListImportExtension.test.ts

Net −112 lines.

The data-mso-list snapshot

The shipped version keeps the example's behaviour, which the test copy lacked. Real Word output carries a <style> block, so the default $inlineStylesFromStyleSheets preprocess rewrites every matched element's style attribute through CSSStyleDeclaration.setProperty — which re-serializes it and silently drops mso-list, a non-standard property. The overlay's preprocess runs first and snapshots mso-list onto data-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 preprocess closes 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, eslint and prettier --check all 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.md that hand-rolled this same overlay now points at the shipped extension.

@vercel

vercel Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 20, 2026 12:22pm
lexical-playground Ready Ready Preview Aug 20, 2026 12:22pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 19, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Aug 19, 2026

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@smrifat1411

Copy link
Copy Markdown
Contributor Author

Done — WordListImportExtension is the export now and $installWordListPasteOverlay is module-private. Every call site got shorter: the dev-example, the test harness and the docs snippet all went from a configExtension(DOMImportExtension, …) block to one dependency.

One deviation from your snippet worth a second: I also put ListExtension in the extension's dependencies, since the overlay builds ListNodes and an editor that added only WordListImportExtension would otherwise construct nodes it hasn't registered. Happy to drop it back to just the DOMImportExtension config if you'd rather the caller own that.

@etrepum
etrepum added this pull request to the merge queue Aug 20, 2026
Merged via the queue into meta:main with commit cc28480 Aug 20, 2026
40 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 1a12d6a3 Deployed Aug 20, 2026 by vercel[bot]
Preview – lexical-playground — 1a12d6a3 Deployed Aug 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Pasting nested lists doesn't work which copied from word

2 participants