@eigenpal/docx-js-editor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +191 -0
- package/dist/colorResolver-C-tITrbI.d.cts +1037 -0
- package/dist/colorResolver-Yakhydrt.d.ts +1037 -0
- package/dist/core-plugins.cjs +7131 -0
- package/dist/core-plugins.cjs.map +1 -0
- package/dist/core-plugins.d.cts +27 -0
- package/dist/core-plugins.d.ts +27 -0
- package/dist/core-plugins.js +7102 -0
- package/dist/core-plugins.js.map +1 -0
- package/dist/headless.cjs +10984 -0
- package/dist/headless.cjs.map +1 -0
- package/dist/headless.d.cts +361 -0
- package/dist/headless.d.ts +361 -0
- package/dist/headless.js +10852 -0
- package/dist/headless.js.map +1 -0
- package/dist/index.cjs +45026 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +369 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +4579 -0
- package/dist/index.d.ts +4579 -0
- package/dist/index.js +44701 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-cli.js +9657 -0
- package/dist/mcp-cli.js.map +1 -0
- package/dist/mcp.cjs +8715 -0
- package/dist/mcp.cjs.map +1 -0
- package/dist/mcp.d.cts +155 -0
- package/dist/mcp.d.ts +155 -0
- package/dist/mcp.js +8667 -0
- package/dist/mcp.js.map +1 -0
- package/dist/registry-D3zhko7n.d.ts +165 -0
- package/dist/registry-DeeU0bQB.d.cts +165 -0
- package/dist/styles.css +1 -0
- package/dist/types-BJXChtaM.d.cts +2216 -0
- package/dist/types-BJXChtaM.d.ts +2216 -0
- package/package.json +132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 EigenPal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# @eigenpal/docx-js-editor
|
|
2
|
+
|
|
3
|
+
An open-source, extendable WYSIWYG DOCX editor for JavaScript.
|
|
4
|
+
|
|
5
|
+
## Demo
|
|
6
|
+
|
|
7
|
+
<!-- Add video here -->
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @eigenpal/docx-js-editor
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import DocxEditor from '@eigenpal/docx-js-editor';
|
|
21
|
+
import '@eigenpal/docx-js-editor/styles.css';
|
|
22
|
+
|
|
23
|
+
function App() {
|
|
24
|
+
return <DocxEditor onChange={(doc) => console.log(doc)} />;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Load from backend
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { useState, useEffect } from 'react';
|
|
32
|
+
import DocxEditor, { parseDocx, type Document } from '@eigenpal/docx-js-editor';
|
|
33
|
+
|
|
34
|
+
function App() {
|
|
35
|
+
const [document, setDocument] = useState<Document | null>(null);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
async function loadDocument() {
|
|
39
|
+
const response = await fetch('/api/documents/123');
|
|
40
|
+
const buffer = await response.arrayBuffer();
|
|
41
|
+
const doc = await parseDocx(buffer);
|
|
42
|
+
setDocument(doc);
|
|
43
|
+
}
|
|
44
|
+
loadDocument();
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
if (!document) return <div>Loading...</div>;
|
|
48
|
+
|
|
49
|
+
return <DocxEditor document={document} />;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Save to backend
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { useRef } from 'react';
|
|
57
|
+
import DocxEditor, { type DocxEditorRef } from '@eigenpal/docx-js-editor';
|
|
58
|
+
|
|
59
|
+
function App() {
|
|
60
|
+
const editorRef = useRef<DocxEditorRef>(null);
|
|
61
|
+
|
|
62
|
+
const handleSave = async () => {
|
|
63
|
+
const buffer = await editorRef.current?.save();
|
|
64
|
+
if (buffer) {
|
|
65
|
+
await fetch('/api/documents/123', {
|
|
66
|
+
method: 'PUT',
|
|
67
|
+
body: buffer,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<button onClick={handleSave}>Save</button>
|
|
75
|
+
<DocxEditor ref={editorRef} />
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Full example (load + save)
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { useState, useEffect, useRef } from 'react';
|
|
85
|
+
import DocxEditor, { parseDocx, type Document, type DocxEditorRef } from '@eigenpal/docx-js-editor';
|
|
86
|
+
import '@eigenpal/docx-js-editor/styles.css';
|
|
87
|
+
|
|
88
|
+
function App() {
|
|
89
|
+
const editorRef = useRef<DocxEditorRef>(null);
|
|
90
|
+
const [document, setDocument] = useState<Document | null>(null);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
fetch('/api/documents/123')
|
|
94
|
+
.then((r) => r.arrayBuffer())
|
|
95
|
+
.then((buffer) => parseDocx(buffer))
|
|
96
|
+
.then(setDocument);
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
const handleSave = async () => {
|
|
100
|
+
const buffer = await editorRef.current?.save();
|
|
101
|
+
if (buffer) {
|
|
102
|
+
await fetch('/api/documents/123', { method: 'PUT', body: buffer });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (!document) return <div>Loading...</div>;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<button onClick={handleSave}>Save</button>
|
|
111
|
+
<DocxEditor ref={editorRef} document={document} />
|
|
112
|
+
</>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Ref methods
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
const editorRef = useRef<DocxEditorRef>(null);
|
|
121
|
+
|
|
122
|
+
// Save and get buffer
|
|
123
|
+
const buffer = await editorRef.current?.save();
|
|
124
|
+
|
|
125
|
+
// Get current document object
|
|
126
|
+
const doc = editorRef.current?.getDocument();
|
|
127
|
+
|
|
128
|
+
// Zoom controls
|
|
129
|
+
editorRef.current?.setZoom(1.5); // 150%
|
|
130
|
+
const zoom = editorRef.current?.getZoom();
|
|
131
|
+
|
|
132
|
+
// Navigation
|
|
133
|
+
editorRef.current?.focus();
|
|
134
|
+
editorRef.current?.scrollToPage(3);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Headless mode (bring your own UI)
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
<DocxEditor ref={editorRef} showToolbar={false} showVariablePanel={false} />
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Standalone components
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import {
|
|
147
|
+
Toolbar,
|
|
148
|
+
FontPicker,
|
|
149
|
+
ColorPicker,
|
|
150
|
+
parseDocx,
|
|
151
|
+
serializeDocx,
|
|
152
|
+
} from '@eigenpal/docx-js-editor';
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Template variables
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { processTemplate } from '@eigenpal/docx-js-editor';
|
|
159
|
+
|
|
160
|
+
const result = await processTemplate(docxBuffer, {
|
|
161
|
+
name: 'John Doe',
|
|
162
|
+
company: 'Acme Inc',
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Features
|
|
167
|
+
|
|
168
|
+
- Full WYSIWYG editing with Microsoft Word fidelity
|
|
169
|
+
- Open, edit, and save DOCX files in the browser
|
|
170
|
+
- Standalone components (Toolbar, FontPicker, ColorPicker, etc.)
|
|
171
|
+
- Template variable support (`{{variable}}`)
|
|
172
|
+
- Extendable plugin architecture
|
|
173
|
+
- Zero server dependencies
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
bun install
|
|
179
|
+
bun run dev
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Contributing
|
|
183
|
+
|
|
184
|
+
This is an open-source project. Contributions are welcome!
|
|
185
|
+
|
|
186
|
+
- [Open an issue](https://github.com/eigenpal/docx-js-editor/issues) to report bugs or request features
|
|
187
|
+
- Submit pull requests to help improve the editor
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT
|