{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "docx-editor-mail-merge",
  "framework": "javascript",
  "type": "registry:component",
  "component": "DocxEditor",
  "variant": "mail-merge",
  "dependencies": [
    "@syncfusion/ej2-documenteditor",
    "@syncfusion/ej2-lists",
    "@syncfusion/ej2-navigations",
    "@syncfusion/ej2-popups"
  ],
  "description": "Document editor mail merge sample generating personalized letters from template data.",
  "meta": {
    "essentialStudioRelease": "2026 Volume 3 (v35.1.37)",
    "license": "commercial-or-community",
    "licenseNote": "The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md",
    "requiresLicenseKey": true,
    "requiresServerEndpoint": true,
    "platformIndex": "https://ai.syncfusion.com/javascript/llms.txt",
    "skillPack": "syncfusion/javascript-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/javascript/docx-editor-mail-merge.md"
  },
  "files": [
    {
      "target": "src/components/docx-editor-mail-merge/docx-editor.html",
      "content": "<div class=\"control-section\" style=\"border-right: none;\">\n    <div id='documenteditor_titlebar' class=\"e-de-ctn-title\"></div>\n<div class=\"col-lg-2 property-section\" style=\"padding-right: inherit;padding-left: 5px;height: 590px;border-left: 1px solid rgb(238, 238, 238);border-bottom:  1px solid rgb(238, 238, 238) ;\"> \n   \n    <h5><label style=\"display:block;margin:1px;padding-top: 18px;padding-top: 5px\">Select Field to Insert</label></h5>\n    <div id=\"listview\" >\n    </div>\n</div>\n<div class=\"col-lg-10 control-section\" style='padding-left: 0px;padding-right: 0px;padding-top: 0px;'>\n  <div id=\"container\">\n  </div>\n</div>\n\n\n<div class=\"overlay\" id=\"popup-overlay\" style=\"display: none;height: 590px;\"></div>\n    <div id='waiting-popup'>\n        <svg class=\"circular\" height=\"40\" width=\"40\">\n            <circle class=\"circle-path\" cx=\"25\" cy=\"25\" r=\"20\" fill=\"none\" stroke-width=\"6\" stroke-miterlimit=\"10\" />\n        </svg>\n    </div>\n</div>\n\n<style>\n    .ej2-new {\n        height: 590px;\n    }\n#documenteditor_titlebar {\n    border-bottom: 1px solid #2B3481;\n    height: 36px;\n    line-height: 26px;\n    width: 100%;\n    font-size: 12px;\n    padding-left: 15px;\n    padding-right: 10px;\n    font-family: inherit;\n}\n\n#documenteditor_title_contentEditor {\n    height: 26px;\n    max-width: 85%;\n    width: auto;\n    overflow: hidden;\n    display: inline-block;\n    padding-left: 4px;\n    padding-right: 4px;\n    margin: 5px;\n}\n.overlay {\n    z-index: 10;\n    display: none;\n    position:relative;\n    background-color: #383838;\n    height: 100%;\n    width: 100%;\n    opacity: .5;\n    cursor: not-allowed;\n}\n#waiting-popup {\n    width: 56px;\n    height: 56px;\n    position: absolute;\n    top: calc(50% - 28px);\n    left: calc(50% - 28px);\n    border-radius: 50%;\n    padding: 3px;\n    box-shadow: 0px 3px 1px -2px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 1px 5px 0px rgba(0, 0, 0, 0.12);\n    overflow: hidden;\n    background-position: center;\n    background-color: white;\n    z-index: 20;\n    display: none;\n}\n\n\n.circular {\n    animation: rotate 2s linear infinite;\n    height: 50px;\n    width: 50px;\n    border-radius: 50%;\n}\n\n.circle-path {\n    stroke-dasharray: 1, 200;\n    stroke-dashoffset: 0;\n    animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;\n    stroke-linecap: round;\n    stroke: #ff4081;\n}\n\n@keyframes rotate {\n    100% {\n        transform: rotate(360deg);\n    }\n}\n\n@keyframes dash {\n    0% {\n        stroke-dasharray: 1, 200;\n        stroke-dashoffset: 0;\n    }\n\n    50% {\n        stroke-dasharray: 89, 200;\n        stroke-dashoffset: -35;\n    }\n\n    100% {\n        stroke-dasharray: 89, 200;\n        stroke-dashoffset: -124;\n    }\n}\n\n.single-line {\n    cursor: text !important;\n    outline: none;\n}\n\n.heading-section {\n    padding-bottom: 20px;\n    padding-top: 20px;\n}\n\n.single-line:hover {\n    border-color: #e4e4e4 !important;\n}\n\n[contenteditable=\"true\"].single-line {\n    white-space: nowrap;\n    border-color: #e4e4e4 !important;\n}\n\n/** Document editor sample level font icons*/\n@font-face {\nfont-family: 'Font Mail merge icon';\nsrc:\nfont-weight: normal;\nfont-style: normal;\n}\n\n[class^=\"sf-icon-\"], [class*=\" sf-icon-\"] {\nfont-family: 'Font Mail merge icon' !important;\ncolor: rgba(0, 0, 0, 0.54);\nfont-weight: 600;\nfont-size: 14px;\n}\n.sf-icon-FinishMerge:before { content: \"\\e700\"; }\n.sf-icon-InsertMergeField:before { content: \"\\e701\"; }\n@font-face {\n    font-family: 'Sample brower icons';\n    font-weight: normal;\n    font-style: normal;\n}\n[class^=\"e-de-icon-\"],\n[class*=\" e-de-icon-\"] {\n    font-family: 'Sample brower icons' !important;\n}\n.e-de-icon-Print:before {\n    content: \"\\e723\";\n}\n\n.e-de-icon-Download:before {\n    content: \"\\e728\";\n}\n\n/** sample level font icons ends*/\n</style>\n<script>\nwindow.addEventListener(\"beforeunload\", onbeforeunload);\nfunction onbeforeunload() {\n    return 'Want to save your changes?';\n};\n</script>\n"
    },
    {
      "target": "src/components/docx-editor-mail-merge/docx-editor.ts",
      "content": "import { DocumentEditorContainer, Toolbar } from '@syncfusion/ej2-documenteditor';\nimport { ListView, type SelectEventArgs } from '@syncfusion/ej2-lists';\nimport type { ClickEventArgs } from '@syncfusion/ej2-navigations/src/toolbar/toolbar';\nimport { Dialog, DialogUtility } from '@syncfusion/ej2-popups';\nimport { sfdtdata } from '../datasource/docx-editor-data';\n/**\n * Default document editor sample\n */\n// tslint:disable:max-func-body-length\nexport function initDocxEditorMailMerge(): void {\n    let hostUrl: string = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';\n    let container: DocumentEditorContainer = new DocumentEditorContainer({ serviceUrl:hostUrl,enableToolbar: true, height: '590px',\n     toolbarItems: [\n            'New', 'Open', 'Separator', 'Undo',\n            'Redo',\n            'Separator',\n            {\n                prefixIcon: 'sf-icon-InsertMergeField',\n                tooltipText: 'Insert Field',\n                text: onWrapText('Insert Field'),\n                id: 'InsertField'\n            },\n            {\n                prefixIcon: 'sf-icon-FinishMerge',\n                tooltipText: 'Merge Document',\n                text: onWrapText('Merge Document'),\n                id: 'MergeDocument'\n            },\n            'Separator',\n            'Image',\n            'Table',\n            'Hyperlink',\n            'Bookmark',\n            'TableOfContents',\n            'Separator',\n            'Header',\n            'Footer',\n            'PageSetup',\n            'PageNumber',\n            'Break',\n            'Separator',\n            'Find',\n            'Separator',\n            'Comments',\n            'TrackChanges',\n            'Separator',\n            'LocalClipboard',\n            'RestrictEditing',\n            'Separator',\n            'FormFields',\n            'UpdateFields',\n        ],\n        documentEditorSettings:{ showRuler: true}\n    });\n    DocumentEditorContainer.Inject(Toolbar);\n    container.appendTo('#container');\n    container.documentEditor.open(JSON.stringify({ sfdt: sfdtdata }));\n    container.documentEditor.documentName = 'Mail Merge';\n    container.documentChange = (): void => {\n        container.documentEditor.focusIn();\n    };\n    function onWrapText(text: string): string {\n        let content: string = '';\n        let index: number = text.lastIndexOf(' ');\n        content = text.slice(0, index);\n        text.slice(index);\n        content += '<div class=\"e-de-text-wrap\">' + text.slice(index) + '</div>';\n        return content;\n    }\n    container.toolbarClick = (args: ClickEventArgs): void => {\n        switch (args.item.id) {\n            case 'MergeDocument':\n                mergeDocument();\n                break;\n            case 'InsertField':\n                showInsertFielddialog();\n                break;\n        }\n    };\n    let waitingPopUp: HTMLElement;\n    let inActiveDiv: HTMLElement;\n    let listData: { [key: string]: Object }[] = [\n        {\n            text: 'ProductName',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'ShipName',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'CustomerID',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'Quantity',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'UnitPrice',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'Discount',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'ShipAddress',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'ShipCity',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'ShipCountry',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'OrderId',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        },\n        {\n            text: 'OrderDate',\n            category: 'Drag or click the field to insert.',\n            htmlAttributes: { draggable: true }\n        }\n    ];\n    let listDivElement: HTMLElement = document.getElementById('listview');\n    let listView: ListView = new ListView({\n        dataSource: listData,\n        fields: { tooltip: 'category' },\n        select: onselect\n    });\n    listView.appendTo(listDivElement);\n    document.getElementById('listview').addEventListener('dragstart', (event: any): void => {\n        event.dataTransfer.setData('Text', event.target.innerText);\n        event.target.classList.add('de-drag-target');\n    });\n    function onselect(args: SelectEventArgs): void {\n        let fieldName: any = args.text;\n        listView.selectItem(undefined);\n        insertField(fieldName);\n    }\n    function insertField(fieldName: any): void {\n        let fileName: any = fieldName.replace(/\\n/g, '').replace(/\\r/g, '').replace(/\\r\\n/g, '');\n        let fieldCode: any = 'MERGEFIELD  ' + fileName + '  \\\\* MERGEFORMAT ';\n        container.documentEditor.editor.insertField(fieldCode, '«' + fieldName + '»');\n        container.documentEditor.focusIn();\n    }\n\n    // Prevent default drag over for document editor element\n    document.getElementById('container').addEventListener('dragover', (event: any): void => {\n        event.preventDefault();\n    });\n\n    // Drop Event for document editor element\n    document.getElementById('container').addEventListener('drop', (e: any) => {\n        let text: string = e.dataTransfer.getData('Text');\n        container.documentEditor.selection.select({ x: e.offsetX, y: e.offsetY, extend: false });\n        insertField(text);\n    });\n\n    document.addEventListener('dragend', (event: any) => {\n        if (event.target.classList.contains('de-drag-target')) {\n            event.target.classList.remove('de-drag-target');\n        }\n    });\n    function showInsertFielddialog(): void {\n        let instance: any = this;\n        if (document.getElementById('insert_merge_field') === null || document.getElementById('insert_merge_field') === undefined) {\n            let fieldcontainer: any = document.createElement('div');\n            fieldcontainer.id = 'insert_merge_field';\n            document.body.appendChild(fieldcontainer);\n            insertFieldDialogObj.appendTo('#insert_merge_field');\n            fieldcontainer.parentElement.style.position = 'fixed';\n            fieldcontainer.style.width = 'auto';\n            fieldcontainer.style.height = 'auto';\n        }\n        insertFieldDialogObj.close = (): void => { container.documentEditor.focusIn(); };\n        insertFieldDialogObj.beforeOpen = (): void => { container.documentEditor.focusIn(); };\n        insertFieldDialogObj.show();\n        let fieldNameTextBox: any = document.getElementById('field_text');\n        fieldNameTextBox.value = '';\n    }\n    function closeFieldDialog(): void {\n        insertFieldDialogObj.hide();\n        container.documentEditor.focusIn();\n    }\n    let insertFieldDialogObj: Dialog = new Dialog({\n        header: 'Merge Field',\n        content:\n            '<div class=\"dialogContent\">'\n            // tslint:disable-next-line:max-line-length\n            + '<label class=\"e-insert-field-label\">Name:</label></br><input type=\"text\" id=\"field_text\" class=\"e-input\" placeholder=\"Type a field to insert eg. FirstName\">'\n            + '</div>',\n        showCloseIcon: true,\n        isModal: true,\n        width: 'auto',\n        height: 'auto',\n        close: closeFieldDialog,\n        buttons: [\n            {\n                'click': (): void => {\n                    let fieldNameTextBox: any = document.getElementById('field_text');\n                    let fieldName: any = fieldNameTextBox.value;\n                    if (fieldName !== '') {\n                        container.documentEditor.editor.insertField('MERGEFIELD ' + fieldName + ' \\\\* MERGEFORMAT');\n                    }\n                    insertFieldDialogObj.hide();\n                    container.documentEditor.focusIn();\n                },\n                buttonModel: {\n                    content: 'Ok',\n                    cssClass: 'e-flat',\n                    isPrimary: true,\n                },\n            },\n            {\n                'click': (): void => {\n                    insertFieldDialogObj.hide();\n                    container.documentEditor.focusIn();\n                },\n                buttonModel: {\n                    content: 'Cancel',\n                    cssClass: 'e-flat',\n                },\n            },\n        ],\n    });\n\n    function mergeDocument(): void {\n        container.documentEditor.saveAsBlob('Docx').then((blob: Blob) => {\n            let exportedDocumment: Blob = blob;\n            let fileReader: any = new FileReader();\n            fileReader.onload = (): void => {\n                let base64String: any = fileReader.result;\n                let responseData: any = {\n                    fileName: container.documentEditor.documentName + '.docx',\n                    documentData: base64String\n                };\n                waitingPopUp = document.getElementById('waiting-popup');\n                inActiveDiv = document.getElementById('popup-overlay');\n                showHideWaitingIndicator(true);\n                let baseUrl: string = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/MailMerge';\n                let httpRequest: XMLHttpRequest = new XMLHttpRequest();\n                httpRequest.open('POST', baseUrl, true);\n                httpRequest.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');\n                httpRequest.onreadystatechange = () => {\n                    if (httpRequest.readyState === 4) {\n                        if (httpRequest.status === 200 || httpRequest.status === 304) {\n                            container.documentEditor.open(httpRequest.responseText);\n                        } else {\n                            // Failed to merge document\n                            DialogUtility.alert({\n                                title: 'Information',\n                                content: 'failure to merge document',\n                                showCloseIcon: true,\n                                closeOnEscape: true,\n                            });\n                        }\n                        showHideWaitingIndicator(false);\n                    }\n                };\n                httpRequest.send(JSON.stringify((<any>responseData)));\n            };\n            fileReader.readAsDataURL(blob);\n        });\n    }\n    function showHideWaitingIndicator(show: boolean): void {\n        inActiveDiv.style.display = show ? 'block' : 'none';\n        waitingPopUp.style.display = show ? 'block' : 'none';\n    }\n}\n"
    }
  ]
}