This repository contains a React example that demonstrates how to build reusable documents by dragging and dropping predefined document fragments into the Syncfusion® React DOCX Editor (Document Editor).
The sample provides a collection of reusable SFDT document fragments that can be inserted into the editor either by:
- Selecting a fragment from the list.
- Dragging and dropping a fragment directly into the document.
When a fragment is dropped into the editor, the application determines the drop position, places the cursor at that location, and inserts the selected SFDT fragment using the editor.paste() API. This preserves the original formatting, styles, lists, tables, images, and other document elements contained in the fragment.
The sample also includes a read-only document preview dialog for viewing individual fragments before inserting them into the document.
- Drag and drop reusable document fragments
- Insert SFDT fragments using the
editor.paste()API - Preserve complete document formatting during insertion
- Insert content at the drop location
- Preview document fragments in a read-only dialog
Before running the sample, ensure the following software is installed:
- Node.js (LTS)
- npm
git clone <repository-url>
cd react-docx-editor-drag-drop-fragmentsNavigate to the project folder.
npm installnpm startThe application starts on the default React development server.
Example:
http://localhost:3000
The application contains a predefined collection of document fragments stored as SFDT objects.
Users can:
- Select a fragment from the list.
- Drag a fragment into the editor.
- Drop the fragment at the required location.
During the drop operation, the application:
- Detects the drop position.
- Moves the editor selection to the cursor location.
- Retrieves the corresponding SFDT fragment.
- Inserts the fragment using the
DocumentEditor.editor.paste()API. - Preserves all formatting and document structure of the inserted fragment.
Because the fragment is inserted as SFDT instead of plain text, complex content such as:
- Headings
- Tables
- Lists
- Images
- Paragraph formatting
- Character formatting
- Sections
User
│
▼
Select or Drag a Document Fragment
│
▼
Retrieve Corresponding SFDT Fragment
│
▼
Determine Drop Position
│
▼
Move Cursor to Drop Location
│
▼
DocumentEditor.editor.paste(fragment)
│
▼
Fragment Inserted with Original Formatting
-
Product page: Syncfusion® React DOCX Editor
-
Documentation: Syncfusion® React DOCX Editor - Documentation
-
Online demo: Syncfusion® React DOCX Editor - Online demo
For any other queries, reach our Syncfusion® support team or post the queries through the community forums.
Request new feature through Syncfusion® feedback portal.
This is a commercial product and requires a paid license for possession or use Syncfusion's licensed software, including this component, is subject to the terms and conditions of Syncfusion's EULA. You can purchase a licnense here or start a free 30-day trial here.
