|
| 1 | +import { createRoot } from 'react-dom/client'; |
| 2 | +import * as React from 'react'; |
| 3 | +import { DocumentEditorContainerComponent, Ribbon } from '@syncfusion/ej2-react-documenteditor'; |
| 4 | +import './index.css'; |
| 5 | +DocumentEditorContainerComponent.Inject(Ribbon); |
| 6 | + |
| 7 | +// tslint:disable:max-line-length |
| 8 | +const WebMCPApp = () => { |
| 9 | + let webMcpSettings = { |
| 10 | + name: 'container' |
| 11 | + }; |
| 12 | + let container; |
| 13 | + |
| 14 | + React.useEffect(() => { |
| 15 | + if(container){ |
| 16 | + container.documentEditor.documentName = 'WebMCP Tool Demo'; |
| 17 | + } |
| 18 | + document.title = 'WebMCP Tool Demo - DocumentEditorContainer'; |
| 19 | + }, []); |
| 20 | + |
| 21 | + const beforeWebMcpToolExecute = (args) => { |
| 22 | + const { toolName, toolArgs } = args; |
| 23 | + |
| 24 | + console.log(`[WebMCP] Executing: ${toolName}`, toolArgs); |
| 25 | + |
| 26 | + const commandName = toolName?.includes('_') |
| 27 | + ? toolName.substring(toolName.indexOf('_') + 1) |
| 28 | + : toolName; |
| 29 | + |
| 30 | + if (commandName === 'saveDocument') { |
| 31 | + args.cancel = true; |
| 32 | + args.cancellationResponse = 'The saveDocument operation has been restricted.'; |
| 33 | + } |
| 34 | + }; |
| 35 | + |
| 36 | + return ( |
| 37 | + <div style={{ height: 'calc(100vh - 16px)' }}> |
| 38 | + <DocumentEditorContainerComponent |
| 39 | + id="container" |
| 40 | + ref={(scope) => { container = scope; }} |
| 41 | + serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/" |
| 42 | + height="100%" |
| 43 | + enableToolbar={true} |
| 44 | + toolbarMode="Ribbon" |
| 45 | + enableWebMcp={true} |
| 46 | + webMcpSettings={webMcpSettings} |
| 47 | + beforeWebMcpToolExecute={beforeWebMcpToolExecute} |
| 48 | + > |
| 49 | + </DocumentEditorContainerComponent> |
| 50 | + </div> |
| 51 | + ); |
| 52 | +}; |
| 53 | +export default WebMCPApp; |
| 54 | +createRoot(document.getElementById('sample')).render(<WebMCPApp />); |
0 commit comments