Skip to content

feat: add MS Office-like WYSIWYG editor (@office-kit/docx-editor)#21

Open
baseballyama wants to merge 1 commit into
mainfrom
worktree-jiggly-humming-hummingbird
Open

feat: add MS Office-like WYSIWYG editor (@office-kit/docx-editor)#21
baseballyama wants to merge 1 commit into
mainfrom
worktree-jiggly-humming-hummingbird

Conversation

@baseballyama

Copy link
Copy Markdown
Collaborator

Summary

Adds @office-kit/docx-editor — an interactive, Word/Google-Docs-like editing experience on top of @office-kit/docx, shipped as a live UI at the site's /editor route. Every edit routes through the @office-kit/docx public API (the library stays the single source of truth), and a capability ledger over the full ECMA-376 element universe mechanically guarantees that no document representation is silently dropped.

Motivation

Goal: an MS Office-like editing UI that can realize all docx representations, with a mechanism that guarantees feature coverage — then raise the actual editing experience to at least match Google Docs. The ledger answers "when is it done?" objectively (unclassified elements fail the build), and the two-tier raw-XML inspector makes every element reachable, so preserve is 0 (everything is editable or rendered). The editing surface was then made genuinely usable: real caret handling, paragraph split/merge, undo/redo, find & replace, selection-precise formatting, and localization.

No pre-existing issue — this is the feature work requested directly.

Changes

  • New package @office-kit/docx-editor: EditorModel (undo/redo), command layer, AST→HTML canvas renderer with caret preservation, DOM-selection mapping, capability ledger + enforcing test.
  • Interactive editing: Enter splits at the caret; Backspace/Delete merge paragraphs; caret survives structural re-renders; Ctrl+Z/Y undo/redo; plain-text paste; live word/char count; find & replace; zoom; caret-synced font/size/style; heading-styled rendering.
  • Bug fix: bolding (or any run format on) a partial selection now splits runs at the selection boundaries and formats only the selected text instead of the whole line.
  • i18n: ribbon UI localized into 6 languages (English, 日本語, Español, Français, Deutsch, 中文) with a switcher.
  • New @office-kit/docx public API: generic run/paragraph/container property setters; settings/style/numbering editors; image resize & alt-text; raw element + raw XML part editors (getRawPartRoot/xmlPartNames/…); caret-level structure ops splitParagraphAt / mergeParagraphIntoPrevious; selection ops isolateParagraphRunRange / runTextLength. Also re-exports XmlElement/XmlNode/XmlAttr/QName and several option/property types.

Testing

  • pnpm test — 524 passing / 5 skipped, including new suites: selection-aware formatting (text-selection.test.ts), split/merge (split-merge.test.ts), all-operations integration (integration.test.ts), library primitives (paragraph-edit.test.ts), and the raw-XML/part editors (raw.test.ts).
  • pnpm lint (0), pnpm format:check (clean), pnpm typecheck + editor tsc (clean), pnpm --filter word-kit-site check (svelte-check 0 errors).
  • Capability ledger: edit 1190 / render 8 / preserve 0 / unclassified 0.
  • Verified in a real browser (Playwright) against the built bundles: partial-selection bold isolates only the selected run; Enter/Backspace/undo preserve the caret; find & replace; language switching; DrawingML + arbitrary-part raw editing; and edited documents download → reopen with validate() == 0.

Breaking changes

None. All changes are additive (new package + new exports).

Checklist

  • I have read CLAUDE.md and followed the project's conventions.
  • I have added or updated tests for the change.
  • I have added or updated documentation where user-visible behavior changed.
  • If this is a breaking change, I have added a changeset / CHANGELOG entry and flagged it above.
  • I have re-read my own diff and removed dead code, debug prints, and stale comments.
  • If I used an LLM to draft this PR, I have verified each change myself, the PR represents real work that warrants a maintainer's review, and I am willing to defend each line in review.

🤖 Generated with Claude Code

Introduce an interactive Word/Google-Docs-like editing experience on top of
@office-kit/docx, plus the library primitives it needs.

- New @office-kit/docx-editor package: EditorModel (undo/redo), a command
  layer routed entirely through the @office-kit/docx public API, an AST→HTML
  canvas renderer with caret preservation, and DOM-selection mapping.
- Completeness is enforced by a capability ledger over the ECMA-376 schema
  universe (1198 elements): every element is classified edit/render/preserve
  and a test fails on any unclassified element or dangling command. A two-tier
  raw-XML inspector (document-inline + any XML part) makes every element
  editable, so preserve is 0.
- Interactive editing: Enter splits at the caret, Backspace/Delete merge
  paragraphs, caret survives structural re-renders, Ctrl+Z/Y undo/redo,
  plain-text paste, live word/char count, find & replace, zoom.
- Selection-precise character formatting: bolding part of a line now splits
  runs at the selection boundaries and formats only the selected text
  (previously the whole line was affected).
- Ribbon UI localized into 6 languages (en/ja/es/fr/de/zh) with a switcher.

Library gains generic property setters, settings/style/numbering/part editors,
image resize/alt-text, and caret-level structure ops (splitParagraphAt,
mergeParagraphIntoPrevious, isolateParagraphRunRange, runTextLength).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XVrzeDdRi264e3WVfuMHak
Copilot AI review requested due to automatic review settings July 6, 2026 02:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants