Conversation
|
@botverse I'm very keen to be able to use content controls in documents I'm authoring, so thanks for your work on this! How stable is your code in this PR - if I was to install your fork from github instead of npm, would it Just Work? I'd be happy to feedback any issues I have. |
|
@wildhart unfortunately I don't know how to make my way around the procedures for collaborating here, took like 5 weeks last time for these to run and I was already on something else:
The code works for me but I would be very vigilant using it in your project. Cheers. |
|
Unfortunately I can't get it to install from Github - There's no pre-bulit |
|
Hi @dolanmiu, please would you have a look here? Thank you. |
|
@botverse There are no changes here. I'm also interested in adding these capabilities to DOCX.js. |

Add comprehensive Content Controls implementation
What this PR does
This adds full support for Content Controls to the docx library. Content Controls are the interactive elements you see in Word documents - things like dropdown menus, date pickers, checkboxes, and text input fields that users can interact with.
Why we need this
Content Controls are essential for creating professional document templates and forms. They allow developers to build documents where users can fill in specific areas without breaking the document structure or formatting.
More importantly, Content Controls serve as reliable markers that plugins and external systems can use to identify and manipulate specific document sections. Unlike bookmarks or styles, Content Controls provide a robust tagging system that survives document editing.
What's included
I've implemented all five main types of Content Controls:
Block Content Control - For wrapping paragraphs and tables
Run Content Control - For inline text with rich formatting
Checkbox Content Control - Interactive checkboxes
Date Picker Content Control - Calendar date selection
Dropdown Content Control - Selection menus with predefined options
Each control supports the standard features you'd expect: custom appearance (bounding box, tags, or hidden), data binding to XML stores, locking mechanisms, and visual styling options like custom colors and placeholder text.
Plugin development example
Here's how a developer might use Content Controls to build a document processing plugin:
This approach gives plugin developers reliable anchor points in documents that won't break when users edit other parts of the document. The tags act as a stable API between the document template and the processing system.
Technical details
The implementation follows Microsoft's OOXML specification closely to ensure compatibility with Word 2010 and later versions. I've added comprehensive validation to prevent common issues that can corrupt Word documents, particularly around nesting controls and generating proper GUIDs.
All the code is fully typed with TypeScript - no more
anytypes floating around. I fixed 125 ESLint errors in the process and added over 600 test cases covering edge cases, OOXML compliance, and error conditions.Documentation and examples
I've written extensive documentation including a complete implementation specification and usage guide with practical examples. There's also a demo file showing how to use each type of control, including plugin development patterns.
The API is designed to be intuitive. Here's what creating a simple block control looks like:
Testing
The implementation is thoroughly tested with particular attention to preventing Word document corruption. I've included tests for nesting validation, OOXML compliance, and all the edge cases I could think of.
This is a purely additive feature - existing code won't be affected at all.