@nutrient-sdk/document-authoring 1.9.0-preview.202511031041.d2efec9ac26d9fc0413fb4d08ac87fa1b08c30bb → 1.9.0-preview.202511131316.377b000364a35312f8f23fe4ff69cca7240f68c6
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/README.md +2 -2
- package/lib/docauth.mjs +3 -3
- package/lib/docauth.umd.js +4 -4
- package/lib/index.d.cts +1203 -127
- package/lib/index.d.mts +1203 -127
- package/package.json +1 -1
package/lib/index.d.mts
CHANGED
|
@@ -1,34 +1,109 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Action definition that users can register
|
|
3
|
+
* @since 1.9.0
|
|
3
4
|
* @public
|
|
5
|
+
* @sidebarGroup actions
|
|
6
|
+
* @sidebarGroupOrder 2
|
|
4
7
|
*/
|
|
5
8
|
export declare type Action = BuiltInAction | CustomAction;
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* @public
|
|
12
|
+
* @sidebarGroup core
|
|
13
|
+
* @sidebarGroupOrder 3
|
|
14
|
+
* @see {@link CreateDocAuthSystemOptions} for all available options when creating a DocAuthSystem.
|
|
9
15
|
*/
|
|
10
16
|
export declare type Assets = {
|
|
11
17
|
/**
|
|
12
18
|
* The base path to the Document Authoring assets.
|
|
13
19
|
* If not set, assets will be fetched from a public CDN.
|
|
14
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/self-hosting-assets/" target="_blank">Self-hosting assets guide</a> for information about hosting assets elsewhere.
|
|
15
22
|
*/
|
|
16
23
|
base?: string;
|
|
17
24
|
};
|
|
18
25
|
|
|
19
26
|
/**
|
|
27
|
+
* Input type for binary data like DOCX files or font files.
|
|
28
|
+
* Used by {@link DocAuthSystem.importDOCX} and font loading functions.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // From a Blob (e.g. file input)
|
|
33
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
34
|
+
* const blob = fileInput.files[0];
|
|
35
|
+
* const doc = await system.importDOCX(blob);
|
|
36
|
+
*
|
|
37
|
+
* // From an ArrayBuffer
|
|
38
|
+
* const arrayBuffer = await fetch('/document.docx').then(r => r.arrayBuffer());
|
|
39
|
+
* const doc = await system.importDOCX(arrayBuffer);
|
|
40
|
+
*
|
|
41
|
+
* // From a fetch Response
|
|
42
|
+
* const response = await fetch('/document.docx');
|
|
43
|
+
* const doc = await system.importDOCX(response);
|
|
44
|
+
*
|
|
45
|
+
* // From a Promise (automatically awaited)
|
|
46
|
+
* const doc = await system.importDOCX(fetch('/document.docx'));
|
|
47
|
+
*
|
|
48
|
+
* // From a Promise that resolves to ArrayBuffer
|
|
49
|
+
* const bufferPromise = fetch('/document.docx').then(r => r.arrayBuffer());
|
|
50
|
+
* const doc = await system.importDOCX(bufferPromise);
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
20
53
|
* @public
|
|
54
|
+
* @sidebarGroup core
|
|
55
|
+
* @sidebarGroupOrder 10
|
|
56
|
+
* @see {@link DocAuthSystem.importDOCX} for importing DOCX files.
|
|
57
|
+
* @see {@link FontFile} for using BlobInput with fonts.
|
|
21
58
|
*/
|
|
22
59
|
export declare type BlobInput = Promise<Response | Blob | ArrayBuffer> | Response | Blob | ArrayBuffer;
|
|
23
60
|
|
|
24
61
|
/**
|
|
25
|
-
* Built-in
|
|
62
|
+
* Built-in actions have pre-defined IDs from {@link BuiltInActionId} and automatically use
|
|
63
|
+
* default handlers if not provided. This allows you to customize things without having to
|
|
64
|
+
* reimplement internal functionality.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { defaultActions } from '@nutrient-sdk/document-authoring';
|
|
69
|
+
*
|
|
70
|
+
* // Remove all built-in actions except bold built-in (handler auto-populated)
|
|
71
|
+
* editor.setActions([
|
|
72
|
+
* { id: 'formatting.bold', label: 'Bold', shortcuts: ['Mod+B'] },
|
|
73
|
+
* ]);
|
|
74
|
+
*
|
|
75
|
+
* // Override the default handler for bold
|
|
76
|
+
* editor.setActions([
|
|
77
|
+
* ...defaultActions.filter(({ id }) => id !== 'formatting.bold'),
|
|
78
|
+
* {
|
|
79
|
+
* id: 'formatting.bold',
|
|
80
|
+
* label: 'Bold',
|
|
81
|
+
* shortcuts: ['Mod+B'],
|
|
82
|
+
* handler: () => {
|
|
83
|
+
* console.log('Custom bold implementation');
|
|
84
|
+
* },
|
|
85
|
+
* },
|
|
86
|
+
* ]);
|
|
87
|
+
*
|
|
88
|
+
* // Customize shortcuts and labels while keeping default behavior
|
|
89
|
+
* editor.setActions([
|
|
90
|
+
* ...defaultActions.filter(({ id }) => id !== 'document.export-pdf'),
|
|
91
|
+
* { id: 'document.export-pdf', label: 'Download PDF', shortcuts: ['Mod+P'] },
|
|
92
|
+
* ]);
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @since 1.9.0
|
|
26
96
|
* @public
|
|
97
|
+
* @sidebarGroup actions
|
|
98
|
+
* @sidebarGroupOrder 3
|
|
99
|
+
* @see {@link BuiltInActionId} for available built-in action IDs.
|
|
100
|
+
* @see {@link CustomAction} for defining custom actions.
|
|
27
101
|
*/
|
|
28
102
|
export declare type BuiltInAction = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
103
|
+
/** Built-in action ID from {@link BuiltInActionId} */
|
|
104
|
+
id: BuiltInActionId;
|
|
105
|
+
label: string;
|
|
106
|
+
description?: string;
|
|
32
107
|
/**
|
|
33
108
|
* Keyboard shortcuts for the action.
|
|
34
109
|
* Use "Mod" as the primary modifier key - it will be automatically resolved to:
|
|
@@ -39,21 +114,23 @@ export declare type BuiltInAction = {
|
|
|
39
114
|
* - "Mod+B" becomes "Ctrl+B" on Windows, "⌘B" on Mac
|
|
40
115
|
* - "Mod+Shift+P" becomes "Ctrl+Shift+P" on Windows, "⌘⇧P" on Mac
|
|
41
116
|
*/
|
|
42
|
-
|
|
117
|
+
shortcuts?: string[];
|
|
43
118
|
/** Icon as data URI (e.g., data:image/svg+xml;base64,... or data:image/png;base64,...). Only data:image/ URIs are allowed for security. */
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
119
|
+
icon?: string;
|
|
120
|
+
isEnabled?: () => boolean;
|
|
121
|
+
/** Handler function - optional for built-in actions (defaults will be used if omitted) */
|
|
122
|
+
handler?: (...args: unknown[]) => void | Promise<void>;
|
|
48
123
|
};
|
|
49
124
|
|
|
50
125
|
/**
|
|
51
126
|
* Actions API - Type definitions for registering and executing editor actions
|
|
52
|
-
* @public
|
|
53
127
|
*/
|
|
54
128
|
/**
|
|
55
129
|
* Built-in action IDs that have default implementations
|
|
130
|
+
* @since 1.9.0
|
|
56
131
|
* @public
|
|
132
|
+
* @sidebarGroup actions
|
|
133
|
+
* @sidebarGroupOrder 5
|
|
57
134
|
*/
|
|
58
135
|
export declare type BuiltInActionId = 'document.undo' | 'document.redo' | 'document.export-pdf' | 'document.export-docx' | 'formatting.bold' | 'formatting.italic' | 'formatting.underline' | 'formatting.strikethrough' | 'formatting.subscript' | 'formatting.superscript' | 'formatting.clear' | 'insert.page-break' | 'insert.section-break-next-page' | 'insert.section-break-continuous' | 'insert.column-break' | 'insert.image' | 'insert.link' | 'table.insert' | 'table.delete' | 'table.insert-row-above' | 'table.insert-row-below' | 'table.insert-column-left' | 'table.insert-column-right' | 'table.delete-row' | 'table.delete-column' | 'table.merge-cells' | 'table.split-cells' | 'view.zoom-in' | 'view.zoom-out' | 'view.zoom-reset' | 'view.toggle-ruler' | 'view.toggle-formatting-marks' | 'layout.align-left' | 'layout.align-center' | 'layout.align-right' | 'layout.align-justify' | 'layout.increase-indent' | 'layout.decrease-indent' | 'layout.bulleted-list' | 'layout.numbered-list' | 'style.apply';
|
|
59
136
|
|
|
@@ -62,27 +139,169 @@ export declare type BuiltInActionId = 'document.undo' | 'document.redo' | 'docum
|
|
|
62
139
|
* like creating editors, importing Word documents or creating PDFs.
|
|
63
140
|
*
|
|
64
141
|
* This loads the JavaScript and WASM code and manages the font cache.
|
|
142
|
+
*
|
|
143
|
+
* @see <a href="https://www.nutrient.io/sdk/document-authoring/getting-started/" target="_blank">Getting started guide</a>
|
|
65
144
|
* @public
|
|
145
|
+
* @sidebarGroup core
|
|
146
|
+
* @sidebarGroupOrder 1
|
|
66
147
|
*/
|
|
67
|
-
export declare
|
|
148
|
+
export declare function createDocAuthSystem(options?: CreateDocAuthSystemOptions): Promise<DocAuthSystem>;
|
|
68
149
|
|
|
69
150
|
/**
|
|
151
|
+
* Configuration options for creating a Document Authoring system.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* // Basic setup with CDN assets
|
|
156
|
+
* // Don't forget your license key with all the examples below
|
|
157
|
+
* const system = await createDocAuthSystem({
|
|
158
|
+
* licenseKey: 'YOUR_LICENSE_KEY'
|
|
159
|
+
* });
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // Self-hosted assets
|
|
165
|
+
* const system = await createDocAuthSystem({
|
|
166
|
+
* assets: {
|
|
167
|
+
* base: '/static/assets/'
|
|
168
|
+
* }
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* // With custom fonts using FontFile
|
|
175
|
+
* import { defaultFontIndex } from '@nutrient-sdk/document-authoring';
|
|
176
|
+
*
|
|
177
|
+
* const system = await createDocAuthSystem({
|
|
178
|
+
* fontConfig: {
|
|
179
|
+
* fonts: [
|
|
180
|
+
* defaultFontIndex,
|
|
181
|
+
* { type: 'file', blob: fetch('/fonts/custom-font.ttf') },
|
|
182
|
+
* { type: 'file', blob: fetch('/fonts/another-font.ttf') }
|
|
183
|
+
* ]
|
|
184
|
+
* }
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* // With custom font index for large font libraries
|
|
191
|
+
* const system = await createDocAuthSystem({
|
|
192
|
+
* fontConfig: {
|
|
193
|
+
* fonts: [
|
|
194
|
+
* defaultFontIndex,
|
|
195
|
+
* {
|
|
196
|
+
* type: 'index',
|
|
197
|
+
* index: fetch('/fonts/font-index.json'),
|
|
198
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
199
|
+
* },
|
|
200
|
+
* ],
|
|
201
|
+
* },
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* // Complete configuration
|
|
208
|
+
* const system = await createDocAuthSystem({
|
|
209
|
+
* licenseKey: 'YOUR_LICENSE_KEY',
|
|
210
|
+
* assets: {
|
|
211
|
+
* base: '/static/docauth/'
|
|
212
|
+
* },
|
|
213
|
+
* fontConfig: {
|
|
214
|
+
* fonts: [
|
|
215
|
+
* defaultFontIndex,
|
|
216
|
+
* {
|
|
217
|
+
* type: 'index',
|
|
218
|
+
* index: fetch('/fonts/corporate-fonts.json'),
|
|
219
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
220
|
+
* },
|
|
221
|
+
* ],
|
|
222
|
+
* },
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
70
226
|
* @public
|
|
227
|
+
* @sidebarGroup core
|
|
228
|
+
* @sidebarGroupOrder 2
|
|
229
|
+
* @see {@link createDocAuthSystem} for creating a system instance.
|
|
230
|
+
* @see {@link FontConfig} for font configuration details.
|
|
231
|
+
* @see {@link Assets} for asset hosting configuration.
|
|
71
232
|
*/
|
|
72
233
|
export declare type CreateDocAuthSystemOptions = {
|
|
73
234
|
licenseKey?: string;
|
|
74
235
|
/**
|
|
75
236
|
* Assets configuration. If unset the system will use the assets from a CDN.
|
|
237
|
+
*
|
|
238
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/self-hosting-assets/" target="_blank">Self-hosting assets guide</a> for information about hosting assets elsewhere.
|
|
76
239
|
*/
|
|
77
240
|
assets?: Assets;
|
|
78
241
|
/**
|
|
242
|
+
* @since v1.0.26
|
|
243
|
+
*
|
|
79
244
|
* Font configuration.
|
|
80
245
|
*/
|
|
81
246
|
fontConfig?: FontConfig;
|
|
82
247
|
};
|
|
83
248
|
|
|
84
249
|
/**
|
|
250
|
+
* Options for creating documents from plain text.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* // Create document with default page settings
|
|
255
|
+
* const doc = await system.createDocumentFromPlaintext('Hello World');
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* // Create document with standard page size
|
|
261
|
+
* const doc = await system.createDocumentFromPlaintext('My content', {
|
|
262
|
+
* pageSize: 'A4'
|
|
263
|
+
* });
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* // Create document with custom page size (in points, 72 points = 1 inch)
|
|
269
|
+
* const doc = await system.createDocumentFromPlaintext('My content', {
|
|
270
|
+
* pageSize: { width: 612, height: 792 } // US Letter in points
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* // Create document with custom margins
|
|
277
|
+
* const doc = await system.createDocumentFromPlaintext('My content', {
|
|
278
|
+
* pageSize: 'Letter',
|
|
279
|
+
* pageMargins: {
|
|
280
|
+
* left: 72, // 1 inch
|
|
281
|
+
* right: 72, // 1 inch
|
|
282
|
+
* top: 72, // 1 inch
|
|
283
|
+
* bottom: 72, // 1 inch
|
|
284
|
+
* },
|
|
285
|
+
* });
|
|
286
|
+
* ```
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* // Process multi-paragraph text
|
|
291
|
+
* const text = `First paragraph
|
|
292
|
+
*
|
|
293
|
+
* Second paragraph with line break\nand continuation.
|
|
294
|
+
*
|
|
295
|
+
* Third paragraph with\ttab character.`;
|
|
296
|
+
* const doc = await system.createDocumentFromPlaintext(text, {
|
|
297
|
+
* pageSize: 'Letter'
|
|
298
|
+
* });
|
|
299
|
+
* ```
|
|
300
|
+
*
|
|
85
301
|
* @public
|
|
302
|
+
* @sidebarGroup core
|
|
303
|
+
* @sidebarGroupOrder 8
|
|
304
|
+
* @see {@link DocAuthSystem.createDocumentFromPlaintext} for creating documents from text.
|
|
86
305
|
*/
|
|
87
306
|
export declare type CreateDocumentFromPlaintextOptions = {
|
|
88
307
|
/**
|
|
@@ -107,19 +326,78 @@ export declare type CreateDocumentFromPlaintextOptions = {
|
|
|
107
326
|
};
|
|
108
327
|
|
|
109
328
|
/**
|
|
329
|
+
* Options for creating an editor instance.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* // Create editor with empty document
|
|
334
|
+
* const editor = await system.createEditor(targetElement);
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* // Create editor with existing document
|
|
340
|
+
* const doc = await system.loadDocument(docJSON);
|
|
341
|
+
* const editor = await system.createEditor(targetElement, { document: doc });
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* // Create editor with custom UI settings
|
|
347
|
+
* const editor = await system.createEditor(targetElement, {
|
|
348
|
+
* ui: {
|
|
349
|
+
* locale: 'de',
|
|
350
|
+
* unit: 'cm',
|
|
351
|
+
* ruler: { enabled: false },
|
|
352
|
+
* },
|
|
353
|
+
* });
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* // Create editor with custom actions and toolbar
|
|
359
|
+
* const editor = await system.createEditor(targetElement, {
|
|
360
|
+
* ui: {
|
|
361
|
+
* actions: [
|
|
362
|
+
* ...defaultActions,
|
|
363
|
+
* {
|
|
364
|
+
* id: 'custom.save',
|
|
365
|
+
* label: 'Save',
|
|
366
|
+
* shortcuts: ['Mod+S'],
|
|
367
|
+
* handler: async () => {
|
|
368
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
369
|
+
* await fetch('/api/save', { method: 'POST', body: JSON.stringify(doc) });
|
|
370
|
+
* },
|
|
371
|
+
* },
|
|
372
|
+
* ],
|
|
373
|
+
* toolbar: {
|
|
374
|
+
* items: [
|
|
375
|
+
* { type: 'built-in', id: 'undo', builtInType: 'undo' },
|
|
376
|
+
* { type: 'built-in', id: 'redo', builtInType: 'redo' },
|
|
377
|
+
* { type: 'separator', id: 'sep-1' },
|
|
378
|
+
* { type: 'action', id: 'save-btn', actionId: 'custom.save' },
|
|
379
|
+
* ],
|
|
380
|
+
* },
|
|
381
|
+
* },
|
|
382
|
+
* });
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
110
385
|
* @public
|
|
386
|
+
* @sidebarGroup core
|
|
387
|
+
* @sidebarGroupOrder 6
|
|
388
|
+
* @see {@link DocAuthSystem.createEditor} for creating editors.
|
|
389
|
+
* @see {@link UIOptions} for available UI configuration options.
|
|
111
390
|
*/
|
|
112
391
|
export declare type CreateEditorOptions = {
|
|
113
392
|
/**
|
|
114
393
|
* The document to attach to this editor.
|
|
115
394
|
* If no document is provided, an empty document will be created.
|
|
116
|
-
* @see {@link DocAuthEditor.setCurrentDocument}
|
|
395
|
+
* @see {@link DocAuthEditor.setCurrentDocument} for setting the document after the editor is created.
|
|
117
396
|
*/
|
|
118
397
|
document?: DocAuthDocument;
|
|
119
398
|
/**
|
|
399
|
+
* @since 1.5.0
|
|
120
400
|
* Allows toggling/changing various UI options.
|
|
121
|
-
*
|
|
122
|
-
* See {@link UIOptions}
|
|
123
401
|
*/
|
|
124
402
|
ui?: UIOptions;
|
|
125
403
|
/**
|
|
@@ -133,13 +411,70 @@ export declare type CreateEditorOptions = {
|
|
|
133
411
|
};
|
|
134
412
|
|
|
135
413
|
/**
|
|
136
|
-
* Custom
|
|
414
|
+
* Custom actions allow you to add your own functionality to the editor.
|
|
415
|
+
* Unlike {@link BuiltInAction}, custom actions must provide a handler function.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* import { defaultActions } from '@nutrient-sdk/document-authoring';
|
|
420
|
+
*
|
|
421
|
+
* // Add a custom action with keyboard shortcut
|
|
422
|
+
* editor.setActions([
|
|
423
|
+
* ...defaultActions,
|
|
424
|
+
* {
|
|
425
|
+
* id: 'custom.insert-signature',
|
|
426
|
+
* label: 'Insert Signature',
|
|
427
|
+
* shortcuts: ['Mod+Shift+S'],
|
|
428
|
+
* handler: () => {
|
|
429
|
+
* editor.insertTextAtCursor('\n\nBest regards,\nJohn Doe');
|
|
430
|
+
* },
|
|
431
|
+
* },
|
|
432
|
+
* ]);
|
|
433
|
+
*
|
|
434
|
+
* // Add a custom action with custom icon
|
|
435
|
+
* editor.setActions([
|
|
436
|
+
* ...defaultActions,
|
|
437
|
+
* {
|
|
438
|
+
* id: 'custom.save',
|
|
439
|
+
* label: 'Save Document',
|
|
440
|
+
* icon: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiPi4uLjwvc3ZnPg==',
|
|
441
|
+
* handler: async () => {
|
|
442
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
443
|
+
* await fetch('/api/save', {
|
|
444
|
+
* method: 'POST',
|
|
445
|
+
* body: JSON.stringify(doc)
|
|
446
|
+
* });
|
|
447
|
+
* },
|
|
448
|
+
* },
|
|
449
|
+
* ]);
|
|
450
|
+
*
|
|
451
|
+
* // Add a conditional action (disabled when no cursor/selection)
|
|
452
|
+
* editor.setActions([
|
|
453
|
+
* ...defaultActions,
|
|
454
|
+
* {
|
|
455
|
+
* id: 'custom.insert-date',
|
|
456
|
+
* label: 'Insert Today\'s Date',
|
|
457
|
+
* isEnabled: () => editor.hasActiveCursor(),
|
|
458
|
+
* handler: () => {
|
|
459
|
+
* const date = new Date().toLocaleDateString();
|
|
460
|
+
* editor.insertTextAtCursor(date);
|
|
461
|
+
* },
|
|
462
|
+
* },
|
|
463
|
+
* ]);
|
|
464
|
+
* ```
|
|
465
|
+
*
|
|
466
|
+
* @since 1.9.0
|
|
137
467
|
* @public
|
|
468
|
+
* @sidebarGroup actions
|
|
469
|
+
* @sidebarGroupOrder 4
|
|
470
|
+
* @see {@link BuiltInAction} for built-in actions with default implementations.
|
|
471
|
+
* @see {@link ToolbarActionItem} for adding custom actions to the toolbar.
|
|
138
472
|
*/
|
|
139
473
|
export declare type CustomAction = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
474
|
+
/** Unique identifier for this action (must not be a {@link BuiltInActionId}) */
|
|
475
|
+
id: string;
|
|
476
|
+
label: string;
|
|
477
|
+
description?: string;
|
|
143
478
|
/**
|
|
144
479
|
* Keyboard shortcuts for the action.
|
|
145
480
|
* Use "Cmd" as the modifier key - it will be resolved to:
|
|
@@ -151,19 +486,20 @@ export declare type CustomAction = {
|
|
|
151
486
|
* - "Cmd+B" becomes "Ctrl+B" on Windows, "⌘B" on Mac
|
|
152
487
|
* - "Cmd+Shift+P" becomes "Ctrl+Shift+P" on Windows, "⌘⇧P" on Mac
|
|
153
488
|
*/
|
|
154
|
-
|
|
489
|
+
shortcuts?: string[];
|
|
155
490
|
/** Icon as data URI (e.g., data:image/svg+xml;base64,... or data:image/png;base64,...). Only data:image/ URIs are allowed for security. */
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
491
|
+
icon?: string;
|
|
492
|
+
/** Optional function to determine if this action should be enabled */
|
|
493
|
+
isEnabled?: () => boolean;
|
|
494
|
+
/** Handler function that executes when the action is triggered (required for custom actions) */
|
|
495
|
+
handler: (...args: unknown[]) => void | Promise<void>;
|
|
160
496
|
};
|
|
161
497
|
|
|
162
498
|
/**
|
|
163
499
|
* @hidden
|
|
164
500
|
*/
|
|
165
501
|
declare const _default: {
|
|
166
|
-
createDocAuthSystem:
|
|
502
|
+
createDocAuthSystem: typeof createDocAuthSystem;
|
|
167
503
|
defaultFontIndex: DefaultFontIndex;
|
|
168
504
|
defaultActions: BuiltInAction[];
|
|
169
505
|
defaultToolbarConfig: ToolbarConfig;
|
|
@@ -171,8 +507,7 @@ declare const _default: {
|
|
|
171
507
|
export default _default;
|
|
172
508
|
|
|
173
509
|
/**
|
|
174
|
-
* Get the default set of actions available in the editor.
|
|
175
|
-
* Can be combined with custom actions using spread operator.
|
|
510
|
+
* Get the default set of actions available in the editor. Can be combined with custom actions.
|
|
176
511
|
*
|
|
177
512
|
* Note: Built-in actions (those with IDs from {@link BuiltInActionId}) can omit handlers -
|
|
178
513
|
* they will be automatically populated with default implementations when passed to
|
|
@@ -183,18 +518,18 @@ export default _default;
|
|
|
183
518
|
* Custom actions (those with any other string ID) must provide a handler function.
|
|
184
519
|
*
|
|
185
520
|
* @example
|
|
186
|
-
* ```
|
|
521
|
+
* ```ts
|
|
187
522
|
* import { defaultActions } from '@nutrient-sdk/document-authoring';
|
|
188
523
|
*
|
|
189
524
|
* // Customize a built-in action's metadata (handlers auto-populate for built-in actions)
|
|
190
525
|
* editor.setActions([
|
|
191
|
-
* ...defaultActions,
|
|
526
|
+
* ...defaultActions.filter(({ id }) => id !== 'formatting.bold'),
|
|
192
527
|
* { id: 'formatting.bold', label: 'Make Bold', shortcuts: ['Ctrl+B'] }
|
|
193
528
|
* ]);
|
|
194
529
|
*
|
|
195
530
|
* // Override a built-in action's behavior
|
|
196
531
|
* editor.setActions([
|
|
197
|
-
* ...defaultActions,
|
|
532
|
+
* ...defaultActions.filter(({ id }) => id !== 'formatting.bold'),
|
|
198
533
|
* { id: 'formatting.bold', label: 'Bold', handler: () => console.log('custom bold!') }
|
|
199
534
|
* ]);
|
|
200
535
|
*
|
|
@@ -205,7 +540,10 @@ export default _default;
|
|
|
205
540
|
* ]);
|
|
206
541
|
* ```
|
|
207
542
|
*
|
|
543
|
+
* @since 1.9.0
|
|
208
544
|
* @public
|
|
545
|
+
* @sidebarGroup actions
|
|
546
|
+
* @sidebarGroupOrder 1
|
|
209
547
|
*/
|
|
210
548
|
export declare const defaultActions: BuiltInAction[];
|
|
211
549
|
|
|
@@ -215,6 +553,10 @@ export declare const defaultActions: BuiltInAction[];
|
|
|
215
553
|
* See {@link FontConfig} for how to customize the set of fonts used by the SDK.
|
|
216
554
|
*
|
|
217
555
|
* @public
|
|
556
|
+
* @sidebarGroup fonts
|
|
557
|
+
* @sidebarGroupOrder 2
|
|
558
|
+
* @since v1.0.26
|
|
559
|
+
* @see {@link FontConfig} for configuring fonts, including using the default font index.
|
|
218
560
|
*/
|
|
219
561
|
export declare type DefaultFontIndex = {
|
|
220
562
|
type: 'default-index';
|
|
@@ -225,7 +567,10 @@ export declare type DefaultFontIndex = {
|
|
|
225
567
|
*
|
|
226
568
|
* See {@link FontConfig} for how to customize the set of fonts used by the SDK.
|
|
227
569
|
*
|
|
570
|
+
* @since v1.0.26
|
|
228
571
|
* @public
|
|
572
|
+
* @sidebarGroup fonts
|
|
573
|
+
* @sidebarGroupOrder 1
|
|
229
574
|
*/
|
|
230
575
|
export declare const defaultFontIndex: DefaultFontIndex;
|
|
231
576
|
|
|
@@ -234,41 +579,62 @@ export declare const defaultFontIndex: DefaultFontIndex;
|
|
|
234
579
|
* Can be used as-is or customized.
|
|
235
580
|
*
|
|
236
581
|
* @example
|
|
237
|
-
* ```
|
|
582
|
+
* ```ts
|
|
238
583
|
* import { defaultToolbarConfig } from '@nutrient-sdk/document-authoring';
|
|
239
584
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
585
|
+
* // remove the first two items
|
|
586
|
+
* editor.setToolbarConfig(defaultToolbarConfig.slice(2));
|
|
587
|
+
*
|
|
588
|
+
* // add a custom item
|
|
242
589
|
* editor.setToolbarConfig({
|
|
243
590
|
* items: [...defaultToolbarConfig.items, myCustomItem]
|
|
244
591
|
* });
|
|
245
592
|
* ```
|
|
246
593
|
*
|
|
594
|
+
* @since 1.9.0
|
|
247
595
|
* @public
|
|
596
|
+
* @sidebarGroup toolbar
|
|
597
|
+
* @sidebarGroupOrder 1
|
|
598
|
+
*
|
|
599
|
+
* @see {@link CustomAction} for the shape of custom items.
|
|
248
600
|
*/
|
|
249
601
|
export declare const defaultToolbarConfig: ToolbarConfig;
|
|
250
602
|
|
|
251
603
|
/**
|
|
604
|
+
* A document instance. Holds the content and provides methods for saving, exporting to PDF/DOCX, and more.
|
|
605
|
+
*
|
|
606
|
+
* Create documents via {@link DocAuthEditor} and/or {@link DocAuthSystem}.
|
|
607
|
+
*
|
|
252
608
|
* @public
|
|
609
|
+
* @sidebarGroup core
|
|
610
|
+
* @sidebarGroupOrder 9
|
|
253
611
|
*/
|
|
254
612
|
export declare type DocAuthDocument = {
|
|
255
613
|
/**
|
|
256
614
|
* Returns the current document in the Document Authoring format as a JavaScript object.
|
|
257
615
|
* This object can be safely persisted.
|
|
616
|
+
*
|
|
617
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docjson/" target="_blank">DocJSON guide</a>
|
|
258
618
|
*/
|
|
259
619
|
saveDocument(): Promise<object>;
|
|
260
620
|
/**
|
|
261
621
|
* Returns the current document in the Document Authoring format as a JSON string.
|
|
262
622
|
* This string can be safely persisted.
|
|
623
|
+
*
|
|
263
624
|
* @see {@link DocAuthDocument.saveDocument}
|
|
625
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docjson/" target="_blank">DocJSON guide</a>
|
|
264
626
|
*/
|
|
265
627
|
saveDocumentJSONString(): Promise<string>;
|
|
266
628
|
/**
|
|
267
629
|
* Exports a snapshot of the current document as a PDF file.
|
|
630
|
+
*
|
|
631
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/pdf/" target="_blank">PDF export guide</a>
|
|
268
632
|
*/
|
|
269
633
|
exportPDF(options?: ExportPDFOptions): Promise<ArrayBuffer>;
|
|
270
634
|
/**
|
|
271
635
|
* Exports a snapshot of the current document as a DOCX file.
|
|
636
|
+
*
|
|
637
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docx/" target="_blank">DOCX export guide</a>
|
|
272
638
|
*/
|
|
273
639
|
exportDOCX(options?: ExportDOCXOptions): Promise<ArrayBuffer>;
|
|
274
640
|
/**
|
|
@@ -286,12 +652,64 @@ export declare type DocAuthDocument = {
|
|
|
286
652
|
* An `object` will be treated as a JavaScript representation of a Document Authoring document
|
|
287
653
|
* (e.g. the result of `JSON.parse` on a Document Authoring JSON string).
|
|
288
654
|
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* // Load from JSON
|
|
658
|
+
* const docString = '{"version":"7.0","content":[...]}';
|
|
659
|
+
* const docFromString = await system.loadDocument(docString);
|
|
660
|
+
* ```
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```ts
|
|
664
|
+
* // Load from a JavaScript object
|
|
665
|
+
* const docObject = { version: '7.0', content: [...] };
|
|
666
|
+
* const docFromObject = await system.loadDocument(docObject);
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* // Load from a Blob (e.g. from a file input)
|
|
672
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
673
|
+
* const blob = fileInput.files[0];
|
|
674
|
+
* const docFromBlob = await system.loadDocument(blob);
|
|
675
|
+
* ```
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* ```ts
|
|
679
|
+
* // Load from a fetch Response
|
|
680
|
+
* const response = await fetch('/api/document.json');
|
|
681
|
+
* const docFromResponse = await system.loadDocument(response);
|
|
682
|
+
* ```
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* // Load from a Promise (fetch is automatically awaited)
|
|
687
|
+
* const docFromPromise = await system.loadDocument(fetch('/api/document.json'));
|
|
688
|
+
* ```
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* ```ts
|
|
692
|
+
* // Load from a Promise that resolves to a Blob
|
|
693
|
+
* const blobPromise = fetch('/api/document.json').then(r => r.blob());
|
|
694
|
+
* const docFromBlobPromise = await system.loadDocument(blobPromise);
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
289
697
|
* @public
|
|
698
|
+
* @sidebarGroup core
|
|
699
|
+
* @sidebarGroupOrder 5
|
|
700
|
+
* @see {@link DocAuthSystem.loadDocument} for how this is used.
|
|
701
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docjson/" target="_blank">DocJSON guide</a>
|
|
290
702
|
*/
|
|
291
703
|
export declare type DocAuthDocumentInput = string | object | Blob | Response | Promise<string | object | Blob | Response>;
|
|
292
704
|
|
|
293
705
|
/**
|
|
706
|
+
* The visual editor UI. Binds to a DOM element and lets users edit documents.
|
|
707
|
+
*
|
|
708
|
+
* Create editors using {@link createDocAuthSystem}.
|
|
709
|
+
*
|
|
294
710
|
* @public
|
|
711
|
+
* @sidebarGroup core
|
|
712
|
+
* @sidebarGroupOrder 7
|
|
295
713
|
*/
|
|
296
714
|
export declare type DocAuthEditor = {
|
|
297
715
|
/**
|
|
@@ -316,6 +734,7 @@ export declare type DocAuthEditor = {
|
|
|
316
734
|
* If there's a selection, it will be replaced with the provided text.
|
|
317
735
|
*
|
|
318
736
|
* @param text - The text to insert at the cursor position
|
|
737
|
+
* @since 1.8.0
|
|
319
738
|
*/
|
|
320
739
|
insertTextAtCursor(text: string): void;
|
|
321
740
|
/**
|
|
@@ -323,63 +742,9 @@ export declare type DocAuthEditor = {
|
|
|
323
742
|
* This is useful for custom actions to determine if they should be enabled.
|
|
324
743
|
*
|
|
325
744
|
* @returns true if cursor is active and insertion is possible, false otherwise
|
|
326
|
-
*
|
|
327
|
-
* @internal
|
|
745
|
+
* @since 1.9.0
|
|
328
746
|
*/
|
|
329
747
|
hasActiveCursor(): boolean;
|
|
330
|
-
/**
|
|
331
|
-
* Adds an event listener that will be called every time the specified event is emitted.
|
|
332
|
-
*
|
|
333
|
-
* @param event - The event name to listen for
|
|
334
|
-
* @param handler - The function to call when the event is emitted
|
|
335
|
-
* @returns The editor instance for method chaining
|
|
336
|
-
*
|
|
337
|
-
* @example
|
|
338
|
-
* ```typescript
|
|
339
|
-
* // Get the latest document content
|
|
340
|
-
* editor.on('content.change', async () => console.log(await editor.currentDocument().saveDocument()));
|
|
341
|
-
* ```
|
|
342
|
-
*
|
|
343
|
-
* @eventMap DocAuthEditorEvents
|
|
344
|
-
*/
|
|
345
|
-
on: <EventName extends keyof DocAuthEditorEvents>(event: EventName, handler: DocAuthEditorEventHandler<EventName>) => DocAuthEditor;
|
|
346
|
-
/**
|
|
347
|
-
* Removes an event listener. If no handler is provided, removes all listeners for the event.
|
|
348
|
-
*
|
|
349
|
-
* @param event - The event name to remove listeners from
|
|
350
|
-
* @param handler - The specific handler to remove (optional)
|
|
351
|
-
* @returns The editor instance for method chaining
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* ```typescript
|
|
355
|
-
* // Remove specific handler
|
|
356
|
-
* editor.off('content.change', myHandler);
|
|
357
|
-
*
|
|
358
|
-
* // Remove all handlers for an event
|
|
359
|
-
* editor.off('content.change');
|
|
360
|
-
* ```
|
|
361
|
-
*
|
|
362
|
-
* @eventMap DocAuthEditorEvents
|
|
363
|
-
*/
|
|
364
|
-
off: <EventName extends keyof DocAuthEditorEvents>(event: EventName, handler?: DocAuthEditorEventHandler<EventName>) => DocAuthEditor;
|
|
365
|
-
/**
|
|
366
|
-
* Adds an event listener that will be called only once when the specified event is emitted.
|
|
367
|
-
* The listener is automatically removed after being called.
|
|
368
|
-
*
|
|
369
|
-
* @param event - The event name to listen for
|
|
370
|
-
* @param handler - The function to call when the event is emitted
|
|
371
|
-
* @returns The editor instance for method chaining
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* ```typescript
|
|
375
|
-
* editor.once('document.load', () => {
|
|
376
|
-
* console.log('Document loaded for the first time');
|
|
377
|
-
* });
|
|
378
|
-
* ```
|
|
379
|
-
*
|
|
380
|
-
* @eventMap DocAuthEditorEvents
|
|
381
|
-
*/
|
|
382
|
-
once: <EventName extends keyof DocAuthEditorEvents>(event: EventName, handler: DocAuthEditorEventHandler<EventName>) => DocAuthEditor;
|
|
383
748
|
/**
|
|
384
749
|
* Set all actions (replaces any existing actions).
|
|
385
750
|
* Allows setting and executing editor actions programmatically.
|
|
@@ -387,7 +752,7 @@ export declare type DocAuthEditor = {
|
|
|
387
752
|
* @param actions - Array of actions to register
|
|
388
753
|
*
|
|
389
754
|
* @example
|
|
390
|
-
* ```
|
|
755
|
+
* ```ts
|
|
391
756
|
* import { defaultActions } from '@nutrient-sdk/document-authoring';
|
|
392
757
|
*
|
|
393
758
|
* // Register custom actions alongside default actions
|
|
@@ -399,12 +764,15 @@ export declare type DocAuthEditor = {
|
|
|
399
764
|
* handler: () => {
|
|
400
765
|
* editor.insertTextAtCursor('\n\nBest regards,\nJohn Doe');
|
|
401
766
|
* },
|
|
402
|
-
* shortcuts: [
|
|
403
|
-
* }
|
|
767
|
+
* shortcuts: ['Mod+Shift+S'],
|
|
768
|
+
* },
|
|
404
769
|
* ]);
|
|
405
770
|
* ```
|
|
406
771
|
*
|
|
772
|
+
* @since 1.9.0
|
|
407
773
|
* @public
|
|
774
|
+
* @sidebarGroup actions
|
|
775
|
+
* @sidebarGroupOrder 6
|
|
408
776
|
*/
|
|
409
777
|
setActions(actions: Action[]): void;
|
|
410
778
|
/**
|
|
@@ -414,11 +782,17 @@ export declare type DocAuthEditor = {
|
|
|
414
782
|
* @param config - Toolbar configuration object
|
|
415
783
|
*
|
|
416
784
|
* @example
|
|
417
|
-
* ```
|
|
785
|
+
* ```ts
|
|
418
786
|
* import { defaultToolbarConfig } from '@nutrient-sdk/document-authoring';
|
|
419
787
|
*
|
|
420
|
-
* // Use default toolbar
|
|
421
|
-
* editor.setToolbarConfig(
|
|
788
|
+
* // Use default toolbar config but add a custom item
|
|
789
|
+
* editor.setToolbarConfig({
|
|
790
|
+
* ...defaultToolbarConfig,
|
|
791
|
+
* items: [
|
|
792
|
+
* ...defaultToolbarConfig.items,
|
|
793
|
+
* { type: 'action', id: 'custom', actionId: 'custom.insert-signature' }
|
|
794
|
+
* ]
|
|
795
|
+
* });
|
|
422
796
|
*
|
|
423
797
|
* // Or create a minimal toolbar
|
|
424
798
|
* editor.setToolbarConfig({
|
|
@@ -433,9 +807,132 @@ export declare type DocAuthEditor = {
|
|
|
433
807
|
* });
|
|
434
808
|
* ```
|
|
435
809
|
*
|
|
810
|
+
* @since 1.9.0
|
|
436
811
|
* @public
|
|
812
|
+
* @sidebarGroup toolbar
|
|
813
|
+
* @sidebarGroupOrder 7
|
|
437
814
|
*/
|
|
438
815
|
setToolbarConfig(config: ToolbarConfig): void;
|
|
816
|
+
/**
|
|
817
|
+
* Adds an event listener that will be called every time the specified event is emitted.
|
|
818
|
+
*
|
|
819
|
+
* @param event - The event name to listen for
|
|
820
|
+
* @param handler - The function to call when the event is emitted
|
|
821
|
+
* @returns The editor instance for method chaining
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```ts
|
|
825
|
+
* // Auto-save on content changes
|
|
826
|
+
* editor.on('content.change', async () => {
|
|
827
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
828
|
+
* localStorage.setItem('draft', JSON.stringify(doc));
|
|
829
|
+
* });
|
|
830
|
+
*
|
|
831
|
+
* // Track document load
|
|
832
|
+
* editor.on('document.load', () => {
|
|
833
|
+
* console.log('Document loaded successfully');
|
|
834
|
+
* });
|
|
835
|
+
*
|
|
836
|
+
* // Debounced save to prevent excessive API calls
|
|
837
|
+
* let saveTimeout;
|
|
838
|
+
* editor.on('content.change', async () => {
|
|
839
|
+
* clearTimeout(saveTimeout);
|
|
840
|
+
* saveTimeout = setTimeout(async () => {
|
|
841
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
842
|
+
* await fetch('/api/save', {
|
|
843
|
+
* method: 'POST',
|
|
844
|
+
* body: JSON.stringify(doc)
|
|
845
|
+
* });
|
|
846
|
+
* }, 1000);
|
|
847
|
+
* });
|
|
848
|
+
*
|
|
849
|
+
* // Method chaining
|
|
850
|
+
* editor
|
|
851
|
+
* .on('document.load', () => console.log('loaded'))
|
|
852
|
+
* .on('content.change', () => console.log('changed'));
|
|
853
|
+
* ```
|
|
854
|
+
*
|
|
855
|
+
* @since 1.8.0
|
|
856
|
+
* @eventMap DocAuthEditorEvents
|
|
857
|
+
*/
|
|
858
|
+
on<EventName extends keyof DocAuthEditorEvents>(event: EventName, handler: DocAuthEditorEventHandler<EventName>): DocAuthEditor;
|
|
859
|
+
/**
|
|
860
|
+
* Removes an event listener. If no handler is provided, removes all listeners for the event.
|
|
861
|
+
*
|
|
862
|
+
* @param event - The event name to remove listeners from
|
|
863
|
+
* @param handler - The specific handler to remove (optional)
|
|
864
|
+
* @returns The editor instance for method chaining
|
|
865
|
+
*
|
|
866
|
+
* @example
|
|
867
|
+
* ```ts
|
|
868
|
+
* // Remove specific handler (prevent memory leaks)
|
|
869
|
+
* const handleChange = async () => {
|
|
870
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
871
|
+
* localStorage.setItem('draft', JSON.stringify(doc));
|
|
872
|
+
* };
|
|
873
|
+
* editor.on('content.change', handleChange);
|
|
874
|
+
* // ... later ...
|
|
875
|
+
* editor.off('content.change', handleChange);
|
|
876
|
+
*
|
|
877
|
+
* // Remove all handlers for an event
|
|
878
|
+
* editor.off('content.change');
|
|
879
|
+
*
|
|
880
|
+
* // Cleanup pattern
|
|
881
|
+
* const setupEditor = (target) => {
|
|
882
|
+
* const editor = await system.createEditor(target);
|
|
883
|
+
*
|
|
884
|
+
* const handleChange = () => console.log('changed');
|
|
885
|
+
* const handleLoad = () => console.log('loaded');
|
|
886
|
+
*
|
|
887
|
+
* editor.on('content.change', handleChange);
|
|
888
|
+
* editor.on('document.load', handleLoad);
|
|
889
|
+
*
|
|
890
|
+
* return () => {
|
|
891
|
+
* editor.off('content.change', handleChange);
|
|
892
|
+
* editor.off('document.load', handleLoad);
|
|
893
|
+
* editor.destroy();
|
|
894
|
+
* };
|
|
895
|
+
* };
|
|
896
|
+
* ```
|
|
897
|
+
*
|
|
898
|
+
* @since 1.8.0
|
|
899
|
+
* @eventMap DocAuthEditorEvents
|
|
900
|
+
*/
|
|
901
|
+
off<EventName extends keyof DocAuthEditorEvents>(event: EventName, handler?: DocAuthEditorEventHandler<EventName>): DocAuthEditor;
|
|
902
|
+
/**
|
|
903
|
+
* Adds an event listener that will be called only once when the specified event is emitted.
|
|
904
|
+
* The listener is automatically removed after being called.
|
|
905
|
+
*
|
|
906
|
+
* @param event - The event name to listen for
|
|
907
|
+
* @param handler - The function to call when the event is emitted
|
|
908
|
+
* @returns The editor instance for method chaining
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```ts
|
|
912
|
+
* // Wait for initial document load
|
|
913
|
+
* editor.once('document.load', () => {
|
|
914
|
+
* console.log('Document loaded for the first time');
|
|
915
|
+
* });
|
|
916
|
+
*
|
|
917
|
+
* // Perform action after first change
|
|
918
|
+
* editor.once('content.change', () => {
|
|
919
|
+
* console.log('User made their first edit');
|
|
920
|
+
* });
|
|
921
|
+
*
|
|
922
|
+
* // Promise-based pattern for waiting on load
|
|
923
|
+
* const waitForLoad = (editor) => {
|
|
924
|
+
* return new Promise((resolve) => {
|
|
925
|
+
* editor.once('document.load', resolve);
|
|
926
|
+
* });
|
|
927
|
+
* };
|
|
928
|
+
* await waitForLoad(editor);
|
|
929
|
+
* console.log('Ready to use');
|
|
930
|
+
* ```
|
|
931
|
+
*
|
|
932
|
+
* @since 1.8.0
|
|
933
|
+
* @eventMap DocAuthEditorEvents
|
|
934
|
+
*/
|
|
935
|
+
once<EventName extends keyof DocAuthEditorEvents>(event: EventName, handler: DocAuthEditorEventHandler<EventName>): DocAuthEditor;
|
|
439
936
|
};
|
|
440
937
|
|
|
441
938
|
/**
|
|
@@ -465,21 +962,122 @@ export declare type DocAuthEditorEvents = {
|
|
|
465
962
|
* A `DocAuthSystem` instance holds the internal WASM engine and loaded fonts.
|
|
466
963
|
* It is used to load or import documents and create `DocAuthEditor` instances.
|
|
467
964
|
*
|
|
965
|
+
* @see <a href="https://www.nutrient.io/sdk/document-authoring/getting-started/" target="_blank">Getting started guide</a>
|
|
468
966
|
* @public
|
|
967
|
+
* @sidebarGroup core
|
|
968
|
+
* @sidebarGroupOrder 4
|
|
469
969
|
*/
|
|
470
970
|
export declare type DocAuthSystem = {
|
|
471
971
|
/**
|
|
472
972
|
* Loads a document stored in the Document Authoring format.
|
|
473
973
|
* The document can be provided as a JSON string or a JavaScript object.
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* // Load from JSON string
|
|
978
|
+
* const doc = await system.loadDocument('{"version":"7.0","content":[...]}');
|
|
979
|
+
* ```
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* ```ts
|
|
983
|
+
* // Load from object
|
|
984
|
+
* const docData = { version: '7.0', content: [...] };
|
|
985
|
+
* const doc = await system.loadDocument(docData);
|
|
986
|
+
* ```
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* ```ts
|
|
990
|
+
* // Load from server
|
|
991
|
+
* const doc = await system.loadDocument(fetch('/api/documents/123'));
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```ts
|
|
996
|
+
* // Load and create editor
|
|
997
|
+
* const doc = await system.loadDocument(savedDocJSON);
|
|
998
|
+
* const editor = await system.createEditor(targetElement, { document: doc });
|
|
999
|
+
* ```
|
|
1000
|
+
*
|
|
1001
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docjson/#loading-docjson" target="_blank">DocJSON guide</a>
|
|
1002
|
+
* @see {@link DocAuthDocumentInput} for supported input types.
|
|
474
1003
|
*/
|
|
475
1004
|
loadDocument(documentInput: DocAuthDocumentInput): Promise<DocAuthDocument>;
|
|
476
1005
|
/**
|
|
477
1006
|
* Imports a DOCX document.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* // Import from file input
|
|
1011
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
1012
|
+
* const file = fileInput.files[0];
|
|
1013
|
+
* const doc = await system.importDOCX(file);
|
|
1014
|
+
* ```
|
|
1015
|
+
*
|
|
1016
|
+
* @example
|
|
1017
|
+
* ```ts
|
|
1018
|
+
* // Import from URL
|
|
1019
|
+
* const doc = await system.importDOCX(fetch('/documents/template.docx'));
|
|
1020
|
+
* ```
|
|
1021
|
+
*
|
|
1022
|
+
* @example
|
|
1023
|
+
* ```ts
|
|
1024
|
+
* // Import with abort signal
|
|
1025
|
+
* const controller = new AbortController();
|
|
1026
|
+
* const doc = await system.importDOCX(file, {
|
|
1027
|
+
* abortSignal: controller.signal
|
|
1028
|
+
* });
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```ts
|
|
1033
|
+
* // Complete workflow: import DOCX, edit, export PDF
|
|
1034
|
+
* const doc = await system.importDOCX(fetch('/template.docx'));
|
|
1035
|
+
* const editor = await system.createEditor(targetElement, { document: doc });
|
|
1036
|
+
* // ... user edits document ...
|
|
1037
|
+
* const pdfBuffer = await editor.currentDocument().exportPDF();
|
|
1038
|
+
* ```
|
|
1039
|
+
*
|
|
1040
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docx/#importing-docx" target="_blank">DOCX import guide</a>
|
|
1041
|
+
* @see {@link BlobInput} for supported input types.
|
|
478
1042
|
*/
|
|
479
1043
|
importDOCX(docx: BlobInput, options?: ImportDOCXOptions): Promise<DocAuthDocument>;
|
|
480
1044
|
/**
|
|
481
1045
|
* Creates an editor in the specified HTML element.
|
|
482
1046
|
* **IMPORTANT**: The `position` of the target element cannot be `static` or unset. If unsure, use `relative`.
|
|
1047
|
+
*
|
|
1048
|
+
* @example
|
|
1049
|
+
* ```ts
|
|
1050
|
+
* // Shared code for the examples below - ensure target element has proper positioning
|
|
1051
|
+
* const target = document.getElementById('editor');
|
|
1052
|
+
* target.style.position = 'relative';
|
|
1053
|
+
* target.style.height = '600px';
|
|
1054
|
+
* ```
|
|
1055
|
+
*
|
|
1056
|
+
* @example
|
|
1057
|
+
* ```ts
|
|
1058
|
+
* // Create editor with empty document
|
|
1059
|
+
* const editor = await system.createEditor(target);
|
|
1060
|
+
* ```
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```ts
|
|
1064
|
+
* // Create editor with existing document
|
|
1065
|
+
* const doc = await system.loadDocument(docJSON);
|
|
1066
|
+
* const editor = await system.createEditor(target, { document: doc });
|
|
1067
|
+
* ```
|
|
1068
|
+
*
|
|
1069
|
+
* @example
|
|
1070
|
+
* ```ts
|
|
1071
|
+
* // Complete workflow with event handling
|
|
1072
|
+
* const editor = await system.createEditor(target);
|
|
1073
|
+
* editor.on('content.change', async () => {
|
|
1074
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
1075
|
+
* localStorage.setItem('draft', JSON.stringify(doc));
|
|
1076
|
+
* });
|
|
1077
|
+
* ```
|
|
1078
|
+
*
|
|
1079
|
+
* @see <a href="https://www.nutrient.io/sdk/document-authoring/getting-started/using-npm/#integrating-into-your-project" target="_blank">Getting started guide</a>
|
|
1080
|
+
* @see {@link CreateEditorOptions} for available options.
|
|
483
1081
|
*/
|
|
484
1082
|
createEditor(target: HTMLElement, options?: CreateEditorOptions): Promise<DocAuthEditor>;
|
|
485
1083
|
/**
|
|
@@ -488,17 +1086,71 @@ export declare type DocAuthSystem = {
|
|
|
488
1086
|
* - `\n` creates a line break in a paragraph
|
|
489
1087
|
* - `\n\n` separates paragraphs
|
|
490
1088
|
* - `\t` is replaced with spaces
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
1091
|
+
* ```ts
|
|
1092
|
+
* // Simple text document
|
|
1093
|
+
* const doc = await system.createDocumentFromPlaintext('Hello World');
|
|
1094
|
+
* ```
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```ts
|
|
1098
|
+
* // Multi-paragraph document
|
|
1099
|
+
* const text = `First paragraph.
|
|
1100
|
+
*
|
|
1101
|
+
* Second paragraph with line break\nand continuation.`;
|
|
1102
|
+
* const doc = await system.createDocumentFromPlaintext(text);
|
|
1103
|
+
* ```
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* // With custom page settings
|
|
1108
|
+
* const doc = await system.createDocumentFromPlaintext('My content', {
|
|
1109
|
+
* pageSize: 'A4',
|
|
1110
|
+
* pageMargins: { left: 72, right: 72, top: 72, bottom: 72 }
|
|
1111
|
+
* });
|
|
1112
|
+
* ```
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
* ```ts
|
|
1116
|
+
* // Create document and editor in one flow
|
|
1117
|
+
* const doc = await system.createDocumentFromPlaintext('Initial content');
|
|
1118
|
+
* const editor = await system.createEditor(targetElement, { document: doc });
|
|
1119
|
+
* ```
|
|
1120
|
+
*
|
|
1121
|
+
* @see {@link CreateDocumentFromPlaintextOptions} for available options.
|
|
491
1122
|
*/
|
|
492
1123
|
createDocumentFromPlaintext(text: string, options?: CreateDocumentFromPlaintextOptions): Promise<DocAuthDocument>;
|
|
493
1124
|
/**
|
|
494
1125
|
* Releases resources held by the system.
|
|
495
1126
|
* **IMPORTANT**: The system and any editors created by this system can no longer be used after calling this.
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* ```ts
|
|
1130
|
+
* // Clean up when done
|
|
1131
|
+
* editor.destroy();
|
|
1132
|
+
* system.destroy();
|
|
1133
|
+
*
|
|
1134
|
+
* // Or use try-finally pattern
|
|
1135
|
+
* const system = await createDocAuthSystem();
|
|
1136
|
+
* try {
|
|
1137
|
+
* const editor = await system.createEditor(target);
|
|
1138
|
+
* // ... use editor ...
|
|
1139
|
+
* editor.destroy();
|
|
1140
|
+
* } finally {
|
|
1141
|
+
* system.destroy();
|
|
1142
|
+
* }
|
|
1143
|
+
* ```
|
|
496
1144
|
*/
|
|
497
1145
|
destroy(): void;
|
|
498
1146
|
};
|
|
499
1147
|
|
|
500
1148
|
/**
|
|
1149
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docx/#exporting-docx" target="_blank">DOCX export guide</a>
|
|
501
1150
|
* @public
|
|
1151
|
+
* @sidebarGroup import / export
|
|
1152
|
+
* @sidebarGroupOrder 1
|
|
1153
|
+
* @see {@link DocAuthDocument.exportDOCX} for exporting documents to DOCX with these options.
|
|
502
1154
|
*/
|
|
503
1155
|
export declare type ExportDOCXOptions = {
|
|
504
1156
|
/**
|
|
@@ -508,7 +1160,11 @@ export declare type ExportDOCXOptions = {
|
|
|
508
1160
|
};
|
|
509
1161
|
|
|
510
1162
|
/**
|
|
1163
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/pdf/" target="_blank">PDF export guide</a>
|
|
511
1164
|
* @public
|
|
1165
|
+
* @sidebarGroup import / export
|
|
1166
|
+
* @sidebarGroupOrder 2
|
|
1167
|
+
* @see {@link DocAuthDocument.exportPDF} for exporting documents to PDF with these options.
|
|
512
1168
|
*/
|
|
513
1169
|
export declare type ExportPDFOptions = {
|
|
514
1170
|
/**
|
|
@@ -516,13 +1172,97 @@ export declare type ExportPDFOptions = {
|
|
|
516
1172
|
*/
|
|
517
1173
|
abortSignal?: AbortSignal;
|
|
518
1174
|
/**
|
|
1175
|
+
* @since v1.1.0
|
|
519
1176
|
* Generate a PDF/A compliant PDF. Defaults to `false`.
|
|
520
1177
|
*/
|
|
521
1178
|
PDF_A?: boolean;
|
|
522
1179
|
};
|
|
523
1180
|
|
|
524
1181
|
/**
|
|
1182
|
+
* Font configuration for the Document Authoring system.
|
|
1183
|
+
*
|
|
1184
|
+
* The font system supports three approaches:
|
|
1185
|
+
* - {@link DefaultFontIndex}: Built-in fonts (included by default)
|
|
1186
|
+
* - {@link FontFile}: Individual font files loaded upfront
|
|
1187
|
+
* - {@link FontIndex}: Efficient lazy-loading from a font index
|
|
1188
|
+
*
|
|
1189
|
+
* @example
|
|
1190
|
+
* Quick start - add individual fonts (loaded during initialization):
|
|
1191
|
+
* ```ts
|
|
1192
|
+
* import { createDocAuthSystem, defaultFontIndex } from '@nutrient-sdk/document-authoring';
|
|
1193
|
+
*
|
|
1194
|
+
* const system = await createDocAuthSystem({
|
|
1195
|
+
* fontConfig: {
|
|
1196
|
+
* fonts: [
|
|
1197
|
+
* defaultFontIndex,
|
|
1198
|
+
* { type: 'file', blob: fetch('/fonts/custom-font.ttf') },
|
|
1199
|
+
* { type: 'file', blob: fetch('/fonts/another-font.ttf') }
|
|
1200
|
+
* ]
|
|
1201
|
+
* }
|
|
1202
|
+
* });
|
|
1203
|
+
* ```
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* Production setup - use font index for lazy loading (recommended):
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* // Step 1: Generate font index using CLI
|
|
1209
|
+
* // $ npx document-authoring create-font-index --scan-directory ./fonts --write-to public/fonts/font-index.json
|
|
1210
|
+
*
|
|
1211
|
+
* // Step 2: Configure system to use the index
|
|
1212
|
+
* import { createDocAuthSystem, defaultFontIndex } from '@nutrient-sdk/document-authoring';
|
|
1213
|
+
*
|
|
1214
|
+
* const system = await createDocAuthSystem({
|
|
1215
|
+
* fontConfig: {
|
|
1216
|
+
* fonts: [
|
|
1217
|
+
* defaultFontIndex, // Built-in fonts
|
|
1218
|
+
* {
|
|
1219
|
+
* type: 'index',
|
|
1220
|
+
* index: fetch('/fonts/font-index.json'),
|
|
1221
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
1222
|
+
* },
|
|
1223
|
+
* ],
|
|
1224
|
+
* },
|
|
1225
|
+
* });
|
|
1226
|
+
*
|
|
1227
|
+
* // Fonts from the index are loaded on-demand as documents use them
|
|
1228
|
+
* ```
|
|
1229
|
+
*
|
|
1230
|
+
* @example
|
|
1231
|
+
* Complete workflow with custom fonts:
|
|
1232
|
+
* ```ts
|
|
1233
|
+
* import { createDocAuthSystem, defaultFontIndex } from '@nutrient-sdk/document-authoring';
|
|
1234
|
+
*
|
|
1235
|
+
* // Configure font sources
|
|
1236
|
+
* const system = await createDocAuthSystem({
|
|
1237
|
+
* fontConfig: {
|
|
1238
|
+
* fonts: [
|
|
1239
|
+
* defaultFontIndex,
|
|
1240
|
+
* {
|
|
1241
|
+
* type: 'index',
|
|
1242
|
+
* index: fetch('/fonts/corporate-fonts.json'),
|
|
1243
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
1244
|
+
* },
|
|
1245
|
+
* ],
|
|
1246
|
+
* },
|
|
1247
|
+
* });
|
|
1248
|
+
*
|
|
1249
|
+
* // Import a DOCX that uses custom fonts
|
|
1250
|
+
* const doc = await system.importDOCX(fetch('/template.docx'));
|
|
1251
|
+
* // System automatically loads required fonts from the index
|
|
1252
|
+
*
|
|
1253
|
+
* // Create editor with the document
|
|
1254
|
+
* const editor = await system.createEditor(targetElement, { document: doc });
|
|
1255
|
+
* // Users can now select from all available fonts in the UI
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
525
1258
|
* @public
|
|
1259
|
+
* @sidebarGroup fonts
|
|
1260
|
+
* @sidebarGroupOrder 3
|
|
1261
|
+
* @since v1.0.26
|
|
1262
|
+
* @see {@link CreateDocAuthSystemOptions} for all available options when creating a DocAuthSystem.
|
|
1263
|
+
* @see {@link FontFile} for loading individual fonts.
|
|
1264
|
+
* @see {@link FontIndex} for efficient font loading.
|
|
1265
|
+
* @see {@link DefaultFontIndex} for built-in fonts.
|
|
526
1266
|
*/
|
|
527
1267
|
export declare type FontConfig = {
|
|
528
1268
|
/**
|
|
@@ -530,31 +1270,8 @@ export declare type FontConfig = {
|
|
|
530
1270
|
* If unset the {@link DefaultFontIndex} is used.
|
|
531
1271
|
*
|
|
532
1272
|
* Individual fonts can be added directly using a {@link FontFile} or loaded by the system as they are needed using
|
|
533
|
-
* a pre-built {@link FontIndex} that
|
|
1273
|
+
* a pre-built {@link FontIndex} that lists all available fonts. A {@link FontIndex} is the recommended way to provide
|
|
534
1274
|
* a set of fonts to the system in a production environment.
|
|
535
|
-
*
|
|
536
|
-
* @example
|
|
537
|
-
* Providing two additional fonts next to the built-in default fonts. In this scenario the system will load both fonts during initialization:
|
|
538
|
-
* ```TypeScript
|
|
539
|
-
* fonts: [
|
|
540
|
-
* DocAuth.defaultFontIndex,
|
|
541
|
-
* { type: 'file', blob: fetch('/fonts/awesome.ttf') },
|
|
542
|
-
* { type: 'file', blob: fetch('/fonts/more-awesome.ttf') },
|
|
543
|
-
* ],
|
|
544
|
-
* ```
|
|
545
|
-
*
|
|
546
|
-
* @example
|
|
547
|
-
* Providing multiple additional fonts using a font index in addition to the built-in default fonts. In this scenario the system will only load the fonts that are actually needed:
|
|
548
|
-
* ```TypeScript
|
|
549
|
-
* fonts: [
|
|
550
|
-
* DocAuth.defaultFontIndex,
|
|
551
|
-
* {
|
|
552
|
-
* type: 'index',
|
|
553
|
-
* index: fetch('/fonts/font-index.json'),
|
|
554
|
-
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
555
|
-
* },
|
|
556
|
-
* ],
|
|
557
|
-
* ```
|
|
558
1275
|
*/
|
|
559
1276
|
fonts?: (DefaultFontIndex | FontIndex | FontFile)[];
|
|
560
1277
|
};
|
|
@@ -567,11 +1284,15 @@ export declare type FontConfig = {
|
|
|
567
1284
|
* the system to load only fonts that are actually needed.
|
|
568
1285
|
*
|
|
569
1286
|
* @example
|
|
570
|
-
* ```
|
|
1287
|
+
* ```ts
|
|
571
1288
|
* { type:'file', blob: fetch('/fonts/awesome.ttf') }
|
|
572
1289
|
* ```
|
|
573
1290
|
*
|
|
574
1291
|
* @public
|
|
1292
|
+
* @sidebarGroup fonts
|
|
1293
|
+
* @sidebarGroupOrder 4
|
|
1294
|
+
* @since v1.0.26
|
|
1295
|
+
* @see {@link FontConfig} for configuring fonts, including using FontFile.
|
|
575
1296
|
*/
|
|
576
1297
|
export declare type FontFile = {
|
|
577
1298
|
type: 'file';
|
|
@@ -594,7 +1315,7 @@ export declare type FontFile = {
|
|
|
594
1315
|
* This will generate a `font-index.json` file that you can then host and load using the `FontIndex` configuration.
|
|
595
1316
|
*
|
|
596
1317
|
* @example
|
|
597
|
-
* ```
|
|
1318
|
+
* ```ts
|
|
598
1319
|
* {
|
|
599
1320
|
* type: 'index',
|
|
600
1321
|
* index: fetch('/fonts/font-index.json'),
|
|
@@ -603,6 +1324,10 @@ export declare type FontFile = {
|
|
|
603
1324
|
* ```
|
|
604
1325
|
*
|
|
605
1326
|
* @public
|
|
1327
|
+
* @sidebarGroup fonts
|
|
1328
|
+
* @sidebarGroupOrder 5
|
|
1329
|
+
* @since v1.0.26
|
|
1330
|
+
* @see {@link FontConfig} for configuring fonts, including using FontIndex.
|
|
606
1331
|
*/
|
|
607
1332
|
export declare type FontIndex = {
|
|
608
1333
|
type: 'index';
|
|
@@ -611,7 +1336,11 @@ export declare type FontIndex = {
|
|
|
611
1336
|
};
|
|
612
1337
|
|
|
613
1338
|
/**
|
|
1339
|
+
* @see <a href="https://www.nutrient.io/guides/document-authoring/working-with-documents/docx/#importing-docx" target="_blank">DOCX import guide</a>
|
|
614
1340
|
* @public
|
|
1341
|
+
* @sidebarGroup import / export
|
|
1342
|
+
* @sidebarGroupOrder 3
|
|
1343
|
+
* @see {@link DocAuthSystem.importDOCX} for importing DOCX files with these options.
|
|
615
1344
|
*/
|
|
616
1345
|
export declare type ImportDOCXOptions = {
|
|
617
1346
|
/**
|
|
@@ -625,18 +1354,28 @@ export declare type ImportDOCXOptions = {
|
|
|
625
1354
|
*
|
|
626
1355
|
* See {@link UIOptions | UIOptions.locale}
|
|
627
1356
|
*
|
|
1357
|
+
* @since 1.5.0
|
|
628
1358
|
* @public
|
|
1359
|
+
* @sidebarGroup ui
|
|
1360
|
+
* @sidebarGroupOrder 2
|
|
629
1361
|
*/
|
|
630
1362
|
export declare type Locale = 'en' | 'fr' | 'de';
|
|
631
1363
|
|
|
632
1364
|
/**
|
|
633
1365
|
* @alpha
|
|
1366
|
+
* @sidebarGroup programmatic api
|
|
634
1367
|
*/
|
|
635
1368
|
export declare namespace Programmatic {
|
|
1369
|
+
/**
|
|
1370
|
+
* @sidebarGroup programmatic api
|
|
1371
|
+
*/
|
|
636
1372
|
export type Range = {
|
|
637
1373
|
begin: number;
|
|
638
1374
|
end?: number;
|
|
639
1375
|
};
|
|
1376
|
+
/**
|
|
1377
|
+
* @sidebarGroup programmatic api
|
|
1378
|
+
*/
|
|
640
1379
|
export type Formatting = {
|
|
641
1380
|
font: string | null;
|
|
642
1381
|
fontSize: number | null;
|
|
@@ -647,18 +1386,39 @@ export declare namespace Programmatic {
|
|
|
647
1386
|
strikeout: boolean | null;
|
|
648
1387
|
underline: boolean | null;
|
|
649
1388
|
};
|
|
1389
|
+
/**
|
|
1390
|
+
* @sidebarGroup programmatic api
|
|
1391
|
+
*/
|
|
650
1392
|
export type SearchFor = string | RegExp;
|
|
1393
|
+
/**
|
|
1394
|
+
* @sidebarGroup programmatic api
|
|
1395
|
+
*/
|
|
651
1396
|
export type Replacement = {
|
|
652
1397
|
text?: string;
|
|
653
1398
|
formatting?: Partial<Formatting>;
|
|
654
1399
|
};
|
|
1400
|
+
/**
|
|
1401
|
+
* @sidebarGroup programmatic api
|
|
1402
|
+
*/
|
|
655
1403
|
export type ReplaceFn = (value: string) => Replacement | string;
|
|
1404
|
+
/**
|
|
1405
|
+
* @sidebarGroup programmatic api
|
|
1406
|
+
*/
|
|
656
1407
|
export type ReplacementOrReplaceFn = Replacement | ReplaceFn | string;
|
|
1408
|
+
/**
|
|
1409
|
+
* @sidebarGroup programmatic api
|
|
1410
|
+
*/
|
|
657
1411
|
export type ReplaceTextSignature = (searchFor: SearchFor, replace: ReplacementOrReplaceFn) => number;
|
|
1412
|
+
/**
|
|
1413
|
+
* @sidebarGroup programmatic api
|
|
1414
|
+
*/
|
|
658
1415
|
export type SearchResult = {
|
|
659
1416
|
range: Range;
|
|
660
1417
|
text: string;
|
|
661
1418
|
};
|
|
1419
|
+
/**
|
|
1420
|
+
* @sidebarGroup programmatic api
|
|
1421
|
+
*/
|
|
662
1422
|
export type TextView = {
|
|
663
1423
|
getPlainText(range?: Range): string;
|
|
664
1424
|
searchText(searchFor: SearchFor, after?: Range): SearchResult | undefined;
|
|
@@ -676,64 +1436,118 @@ export declare namespace Programmatic {
|
|
|
676
1436
|
}): InlineText;
|
|
677
1437
|
removeInline(index?: number): Inline | undefined;
|
|
678
1438
|
};
|
|
1439
|
+
/**
|
|
1440
|
+
* @sidebarGroup programmatic api
|
|
1441
|
+
*/
|
|
679
1442
|
export type Extent = {
|
|
680
1443
|
width: number;
|
|
681
1444
|
height: number;
|
|
682
1445
|
};
|
|
1446
|
+
/**
|
|
1447
|
+
* @sidebarGroup programmatic api
|
|
1448
|
+
*/
|
|
683
1449
|
export type Image = {
|
|
684
1450
|
type: 'image';
|
|
685
1451
|
extent(): Extent;
|
|
686
1452
|
setExtent(extent: Partial<Extent>): void;
|
|
687
1453
|
};
|
|
1454
|
+
/**
|
|
1455
|
+
* @sidebarGroup programmatic api
|
|
1456
|
+
*/
|
|
688
1457
|
export type Field = {
|
|
689
1458
|
type: 'field';
|
|
690
1459
|
};
|
|
1460
|
+
/**
|
|
1461
|
+
* @sidebarGroup programmatic api
|
|
1462
|
+
*/
|
|
691
1463
|
export type Footnote = {
|
|
692
1464
|
type: 'footnote';
|
|
693
1465
|
};
|
|
1466
|
+
/**
|
|
1467
|
+
* @sidebarGroup programmatic api
|
|
1468
|
+
*/
|
|
694
1469
|
export type FootnoteRef = {
|
|
695
1470
|
type: 'footnote/ref';
|
|
696
1471
|
};
|
|
1472
|
+
/**
|
|
1473
|
+
* @sidebarGroup programmatic api
|
|
1474
|
+
*/
|
|
697
1475
|
export type Endnote = {
|
|
698
1476
|
type: 'endnote';
|
|
699
1477
|
};
|
|
1478
|
+
/**
|
|
1479
|
+
* @sidebarGroup programmatic api
|
|
1480
|
+
*/
|
|
700
1481
|
export type EndnoteRef = {
|
|
701
1482
|
type: 'endnote/ref';
|
|
702
1483
|
};
|
|
1484
|
+
/**
|
|
1485
|
+
* @sidebarGroup programmatic api
|
|
1486
|
+
*/
|
|
703
1487
|
export type LineBreak = {
|
|
704
1488
|
type: 'line-break';
|
|
705
1489
|
};
|
|
1490
|
+
/**
|
|
1491
|
+
* @sidebarGroup programmatic api
|
|
1492
|
+
*/
|
|
706
1493
|
export type PageBreak = {
|
|
707
1494
|
type: 'page-break';
|
|
708
1495
|
};
|
|
1496
|
+
/**
|
|
1497
|
+
* @sidebarGroup programmatic api
|
|
1498
|
+
*/
|
|
709
1499
|
export type Tab = {
|
|
710
1500
|
type: 'tab';
|
|
711
1501
|
};
|
|
1502
|
+
/**
|
|
1503
|
+
* @sidebarGroup programmatic api
|
|
1504
|
+
*/
|
|
712
1505
|
export type Separator = {
|
|
713
1506
|
type: 'sep';
|
|
714
1507
|
};
|
|
1508
|
+
/**
|
|
1509
|
+
* @sidebarGroup programmatic api
|
|
1510
|
+
*/
|
|
715
1511
|
export type InlineText = {
|
|
716
1512
|
type: 'text';
|
|
717
1513
|
plainText(): string;
|
|
718
1514
|
formatting(): Formatting;
|
|
719
1515
|
};
|
|
1516
|
+
/**
|
|
1517
|
+
* @sidebarGroup programmatic api
|
|
1518
|
+
*/
|
|
720
1519
|
export type Inline = InlineText | Tab | Separator | LineBreak | PageBreak | Image | Field | Footnote | FootnoteRef | Endnote | EndnoteRef;
|
|
1520
|
+
/**
|
|
1521
|
+
* @sidebarGroup programmatic api
|
|
1522
|
+
*/
|
|
721
1523
|
export type RangeInline = {
|
|
722
1524
|
range: Range;
|
|
723
1525
|
inline: Inline;
|
|
724
1526
|
};
|
|
1527
|
+
/**
|
|
1528
|
+
* @sidebarGroup programmatic api
|
|
1529
|
+
*/
|
|
725
1530
|
export type Paragraph = {
|
|
726
1531
|
type: 'paragraph';
|
|
727
1532
|
asTextView(): TextView;
|
|
728
1533
|
replaceText: ReplaceTextSignature;
|
|
729
1534
|
};
|
|
1535
|
+
/**
|
|
1536
|
+
* @sidebarGroup programmatic api
|
|
1537
|
+
*/
|
|
730
1538
|
export type TableCell = BlockLevelContainer;
|
|
1539
|
+
/**
|
|
1540
|
+
* @sidebarGroup programmatic api
|
|
1541
|
+
*/
|
|
731
1542
|
export type TableRow = {
|
|
732
1543
|
cells(): TableCell[];
|
|
733
1544
|
addCell(index?: number): TableCell;
|
|
734
1545
|
removeCell(index: number): TableCell | undefined;
|
|
735
1546
|
replaceText: ReplaceTextSignature;
|
|
736
1547
|
};
|
|
1548
|
+
/**
|
|
1549
|
+
* @sidebarGroup programmatic api
|
|
1550
|
+
*/
|
|
737
1551
|
export type Table = {
|
|
738
1552
|
type: 'table';
|
|
739
1553
|
rows(): TableRow[];
|
|
@@ -741,7 +1555,13 @@ export declare namespace Programmatic {
|
|
|
741
1555
|
removeRow(index: number): TableRow | undefined;
|
|
742
1556
|
replaceText: ReplaceTextSignature;
|
|
743
1557
|
};
|
|
1558
|
+
/**
|
|
1559
|
+
* @sidebarGroup programmatic api
|
|
1560
|
+
*/
|
|
744
1561
|
export type BlockLevel = Paragraph | Table;
|
|
1562
|
+
/**
|
|
1563
|
+
* @sidebarGroup programmatic api
|
|
1564
|
+
*/
|
|
745
1565
|
export type BlockLevelContainer = {
|
|
746
1566
|
blocklevels(): BlockLevel[];
|
|
747
1567
|
addParagraph(index?: number): Paragraph;
|
|
@@ -749,45 +1569,72 @@ export declare namespace Programmatic {
|
|
|
749
1569
|
removeElement(index: number): BlockLevel | undefined;
|
|
750
1570
|
replaceText: ReplaceTextSignature;
|
|
751
1571
|
};
|
|
1572
|
+
/**
|
|
1573
|
+
* @sidebarGroup programmatic api
|
|
1574
|
+
*/
|
|
752
1575
|
export type PageSize = {
|
|
753
1576
|
width: number;
|
|
754
1577
|
height: number;
|
|
755
1578
|
};
|
|
1579
|
+
/**
|
|
1580
|
+
* @sidebarGroup programmatic api
|
|
1581
|
+
*/
|
|
756
1582
|
export type PageMargins = {
|
|
757
1583
|
left: number;
|
|
758
1584
|
right: number;
|
|
759
1585
|
top: number;
|
|
760
1586
|
bottom: number;
|
|
761
1587
|
};
|
|
1588
|
+
/**
|
|
1589
|
+
* @sidebarGroup programmatic api
|
|
1590
|
+
*/
|
|
762
1591
|
export type PageSetup = {
|
|
763
1592
|
setPageSize(size: Partial<PageSize>): void;
|
|
764
1593
|
setPageMargins(margins: Partial<PageMargins>): void;
|
|
765
1594
|
pageSize(): PageSize;
|
|
766
1595
|
pageMargins(): PageMargins;
|
|
767
1596
|
};
|
|
1597
|
+
/**
|
|
1598
|
+
* @sidebarGroup programmatic api
|
|
1599
|
+
*/
|
|
768
1600
|
export type HeaderFooter = BlockLevelContainer;
|
|
1601
|
+
/**
|
|
1602
|
+
* @sidebarGroup programmatic api
|
|
1603
|
+
*/
|
|
769
1604
|
export type HeadersFooters = {
|
|
770
1605
|
default(): HeaderFooter | null;
|
|
771
1606
|
first(): HeaderFooter | null;
|
|
772
1607
|
even(): HeaderFooter | null;
|
|
773
1608
|
replaceText: ReplaceTextSignature;
|
|
774
1609
|
};
|
|
1610
|
+
/**
|
|
1611
|
+
* @sidebarGroup programmatic api
|
|
1612
|
+
*/
|
|
775
1613
|
export type HeadersAndFooters = {
|
|
776
1614
|
headers(): HeadersFooters;
|
|
777
1615
|
footers(): HeadersFooters;
|
|
778
1616
|
replaceText: ReplaceTextSignature;
|
|
779
1617
|
};
|
|
1618
|
+
/**
|
|
1619
|
+
* @sidebarGroup programmatic api
|
|
1620
|
+
*/
|
|
780
1621
|
export type Section = {
|
|
781
1622
|
pageSetup(): PageSetup;
|
|
782
1623
|
headersAndFooters(): HeadersAndFooters;
|
|
783
1624
|
content(): BlockLevelContainer;
|
|
784
1625
|
};
|
|
1626
|
+
/**
|
|
1627
|
+
* @sidebarGroup programmatic api
|
|
1628
|
+
*/
|
|
785
1629
|
export type Body = {
|
|
786
1630
|
sections(): Section[];
|
|
787
1631
|
addSection(index?: number): Section;
|
|
788
1632
|
removeSection(index: number): Section | undefined;
|
|
789
1633
|
replaceText: ReplaceTextSignature;
|
|
790
1634
|
};
|
|
1635
|
+
/**
|
|
1636
|
+
* @sidebarGroup programmatic api
|
|
1637
|
+
*/
|
|
791
1638
|
export type Document = {
|
|
792
1639
|
body(): Body;
|
|
793
1640
|
replaceText: ReplaceTextSignature;
|
|
@@ -797,32 +1644,155 @@ export declare namespace Programmatic {
|
|
|
797
1644
|
|
|
798
1645
|
/**
|
|
799
1646
|
* Toolbar API - Type definitions for customizing the editor toolbar
|
|
800
|
-
* @public
|
|
801
1647
|
*/
|
|
802
1648
|
/**
|
|
803
1649
|
* Action toolbar item - references an action by ID
|
|
1650
|
+
*
|
|
1651
|
+
* Use this to add custom actions to the toolbar. The action must be registered
|
|
1652
|
+
* via {@link DocAuthEditor.setActions} or {@link UIOptions.actions}.
|
|
1653
|
+
*
|
|
1654
|
+
* @example
|
|
1655
|
+
* ```ts
|
|
1656
|
+
* // First, register a custom action
|
|
1657
|
+
* editor.setActions([
|
|
1658
|
+
* {
|
|
1659
|
+
* id: 'custom.insert-signature',
|
|
1660
|
+
* label: 'Insert Signature',
|
|
1661
|
+
* handler: () => editor.insertTextAtCursor('\n\nBest regards,\nJohn Doe'),
|
|
1662
|
+
* },
|
|
1663
|
+
* ]);
|
|
1664
|
+
*
|
|
1665
|
+
* // Then add it to the toolbar
|
|
1666
|
+
* editor.setToolbarConfig({
|
|
1667
|
+
* items: [
|
|
1668
|
+
* { type: 'action', id: 'sig-btn', actionId: 'custom.insert-signature' }
|
|
1669
|
+
* ]
|
|
1670
|
+
* });
|
|
1671
|
+
* ```
|
|
1672
|
+
*
|
|
1673
|
+
* @since 1.9.0
|
|
804
1674
|
* @public
|
|
1675
|
+
* @sidebarGroup toolbar
|
|
1676
|
+
* @sidebarGroupOrder 4
|
|
1677
|
+
* @see {@link Action} for defining actions.
|
|
1678
|
+
* @see {@link ToolbarConfig} for full toolbar configuration.
|
|
805
1679
|
*/
|
|
806
1680
|
export declare type ToolbarActionItem = {
|
|
807
1681
|
type: 'action';
|
|
1682
|
+
/** Unique ID for this toolbar item */
|
|
808
1683
|
id: string;
|
|
1684
|
+
/** ID of the action to trigger when this item is clicked */
|
|
809
1685
|
actionId: string;
|
|
810
1686
|
};
|
|
811
1687
|
|
|
812
1688
|
/**
|
|
813
1689
|
* Built-in toolbar item - uses original toolbar components directly
|
|
814
|
-
*
|
|
1690
|
+
*
|
|
1691
|
+
* These are pre-built toolbar components that come with the SDK.
|
|
1692
|
+
* Each has its own UI and functionality built-in.
|
|
1693
|
+
*
|
|
1694
|
+
* @example
|
|
1695
|
+
* ```ts
|
|
1696
|
+
* // Add undo/redo buttons
|
|
1697
|
+
* editor.setToolbarConfig({
|
|
1698
|
+
* items: [
|
|
1699
|
+
* { type: 'built-in', id: 'undo-btn', builtInType: 'undo' },
|
|
1700
|
+
* { type: 'built-in', id: 'redo-btn', builtInType: 'redo' },
|
|
1701
|
+
* ]
|
|
1702
|
+
* });
|
|
1703
|
+
*
|
|
1704
|
+
* // Add text formatting buttons
|
|
1705
|
+
* editor.setToolbarConfig({
|
|
1706
|
+
* items: [
|
|
1707
|
+
* { type: 'built-in', id: 'bold-btn', builtInType: 'bold' },
|
|
1708
|
+
* { type: 'built-in', id: 'italic-btn', builtInType: 'italic' },
|
|
1709
|
+
* { type: 'built-in', id: 'underline-btn', builtInType: 'underline' },
|
|
1710
|
+
* ]
|
|
1711
|
+
* });
|
|
1712
|
+
*
|
|
1713
|
+
* // Add dropdown menus
|
|
1714
|
+
* editor.setToolbarConfig({
|
|
1715
|
+
* items: [
|
|
1716
|
+
* { type: 'built-in', id: 'font-menu', builtInType: 'font-family' },
|
|
1717
|
+
* { type: 'built-in', id: 'size-menu', builtInType: 'font-size' },
|
|
1718
|
+
* { type: 'built-in', id: 'insert', builtInType: 'insert-menu' },
|
|
1719
|
+
* ]
|
|
1720
|
+
* });
|
|
1721
|
+
* ```
|
|
1722
|
+
*
|
|
1723
|
+
* @since 1.9.0
|
|
815
1724
|
* @public
|
|
1725
|
+
* @sidebarGroup toolbar
|
|
1726
|
+
* @sidebarGroupOrder 5
|
|
1727
|
+
* @see {@link ToolbarConfig} for full toolbar configuration.
|
|
816
1728
|
*/
|
|
817
1729
|
export declare type ToolbarBuiltInItem = {
|
|
818
1730
|
type: 'built-in';
|
|
1731
|
+
/** Unique ID for this toolbar item */
|
|
819
1732
|
id: string;
|
|
1733
|
+
/** The type of built-in toolbar component to use */
|
|
820
1734
|
builtInType: 'undo' | 'redo' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'subscript' | 'superscript' | 'text-color' | 'highlight-color' | 'align-left' | 'align-center' | 'align-right' | 'align-justify' | 'bulleted-list' | 'numbered-list' | 'decrease-indent' | 'increase-indent' | 'clear-formatting' | 'formatting-marks' | 'zoom' | 'mobile-lock' | 'font-family' | 'font-size' | 'style-menu' | 'line-spacing-menu' | 'page-setup-menu' | 'insert-menu' | 'table-menu' | 'download-menu' | 'ui-settings-menu';
|
|
821
1735
|
};
|
|
822
1736
|
|
|
823
1737
|
/**
|
|
824
1738
|
* Toolbar configuration
|
|
1739
|
+
*
|
|
1740
|
+
* @example
|
|
1741
|
+
* ```ts
|
|
1742
|
+
* import { defaultToolbarConfig, defaultActions } from '@nutrient-sdk/document-authoring';
|
|
1743
|
+
*
|
|
1744
|
+
* // Add custom action and toolbar button
|
|
1745
|
+
* editor.setActions([
|
|
1746
|
+
* ...defaultActions,
|
|
1747
|
+
* {
|
|
1748
|
+
* id: 'custom.save',
|
|
1749
|
+
* label: 'Save',
|
|
1750
|
+
* handler: async () => {
|
|
1751
|
+
* const doc = await editor.currentDocument().saveDocument();
|
|
1752
|
+
* await fetch('/api/save', { method: 'POST', body: JSON.stringify(doc) });
|
|
1753
|
+
* },
|
|
1754
|
+
* },
|
|
1755
|
+
* ]);
|
|
1756
|
+
* editor.setToolbarConfig({
|
|
1757
|
+
* ...defaultToolbarConfig,
|
|
1758
|
+
* items: [
|
|
1759
|
+
* ...defaultToolbarConfig.items,
|
|
1760
|
+
* { type: 'separator', id: 'sep-custom' },
|
|
1761
|
+
* { type: 'action', id: 'save-btn', actionId: 'custom.save' }
|
|
1762
|
+
* ]
|
|
1763
|
+
* });
|
|
1764
|
+
*
|
|
1765
|
+
* // Create a minimal toolbar with essential formatting
|
|
1766
|
+
* editor.setToolbarConfig({
|
|
1767
|
+
* items: [
|
|
1768
|
+
* { type: 'built-in', id: 'undo', builtInType: 'undo' },
|
|
1769
|
+
* { type: 'built-in', id: 'redo', builtInType: 'redo' },
|
|
1770
|
+
* { type: 'separator', id: 'sep-1' },
|
|
1771
|
+
* { type: 'built-in', id: 'bold', builtInType: 'bold' },
|
|
1772
|
+
* { type: 'built-in', id: 'italic', builtInType: 'italic' },
|
|
1773
|
+
* { type: 'built-in', id: 'underline', builtInType: 'underline' },
|
|
1774
|
+
* { type: 'separator', id: 'sep-2' },
|
|
1775
|
+
* { type: 'built-in', id: 'align-left', builtInType: 'align-left' },
|
|
1776
|
+
* { type: 'built-in', id: 'align-center', builtInType: 'align-center' },
|
|
1777
|
+
* { type: 'built-in', id: 'align-right', builtInType: 'align-right' },
|
|
1778
|
+
* ]
|
|
1779
|
+
* });
|
|
1780
|
+
*
|
|
1781
|
+
* // Customize default toolbar by filtering/adding items
|
|
1782
|
+
* const customItems = [
|
|
1783
|
+
* ...defaultToolbarConfig.items.filter(item => item.id !== 'download-menu'),
|
|
1784
|
+
* { type: 'separator', id: 'custom-sep' },
|
|
1785
|
+
* { type: 'action', id: 'save-btn', actionId: 'custom.save' }
|
|
1786
|
+
* ];
|
|
1787
|
+
* editor.setToolbarConfig({ ...defaultToolbarConfig, items: customItems });
|
|
1788
|
+
* ```
|
|
1789
|
+
*
|
|
1790
|
+
* @since 1.9.0
|
|
825
1791
|
* @public
|
|
1792
|
+
* @sidebarGroup toolbar
|
|
1793
|
+
* @sidebarGroupOrder 2
|
|
1794
|
+
* @see {@link ToolbarItem} for the different types of toolbar items.
|
|
1795
|
+
* @see {@link UIOptions.toolbar} for setting toolbar during editor creation.
|
|
826
1796
|
*/
|
|
827
1797
|
export declare type ToolbarConfig = {
|
|
828
1798
|
/**
|
|
@@ -833,21 +1803,50 @@ export declare type ToolbarConfig = {
|
|
|
833
1803
|
|
|
834
1804
|
/**
|
|
835
1805
|
* Union type for all toolbar items
|
|
1806
|
+
* @since 1.9.0
|
|
836
1807
|
* @public
|
|
1808
|
+
* @sidebarGroup toolbar
|
|
1809
|
+
* @sidebarGroupOrder 3
|
|
837
1810
|
*/
|
|
838
1811
|
export declare type ToolbarItem = ToolbarActionItem | ToolbarBuiltInItem | ToolbarSeparatorItem;
|
|
839
1812
|
|
|
840
1813
|
/**
|
|
841
|
-
* Visual separator
|
|
1814
|
+
* Visual separator - adds a vertical line between toolbar items
|
|
1815
|
+
*
|
|
1816
|
+
* Use separators to visually group related toolbar items.
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* ```ts
|
|
1820
|
+
* editor.setToolbarConfig({
|
|
1821
|
+
* items: [
|
|
1822
|
+
* { type: 'built-in', id: 'undo', builtInType: 'undo' },
|
|
1823
|
+
* { type: 'built-in', id: 'redo', builtInType: 'redo' },
|
|
1824
|
+
* { type: 'separator', id: 'sep-1' }, // Separate undo/redo from formatting
|
|
1825
|
+
* { type: 'built-in', id: 'bold', builtInType: 'bold' },
|
|
1826
|
+
* { type: 'built-in', id: 'italic', builtInType: 'italic' },
|
|
1827
|
+
* { type: 'separator', id: 'sep-2' }, // Separate formatting from alignment
|
|
1828
|
+
* { type: 'built-in', id: 'align-left', builtInType: 'align-left' },
|
|
1829
|
+
* { type: 'built-in', id: 'align-center', builtInType: 'align-center' },
|
|
1830
|
+
* ]
|
|
1831
|
+
* });
|
|
1832
|
+
* ```
|
|
1833
|
+
*
|
|
1834
|
+
* @since 1.9.0
|
|
842
1835
|
* @public
|
|
1836
|
+
* @sidebarGroup toolbar
|
|
1837
|
+
* @sidebarGroupOrder 6
|
|
1838
|
+
* @see {@link ToolbarConfig} for full toolbar configuration.
|
|
843
1839
|
*/
|
|
844
1840
|
export declare type ToolbarSeparatorItem = {
|
|
845
1841
|
type: 'separator';
|
|
1842
|
+
/** Unique ID for this separator */
|
|
846
1843
|
id: string;
|
|
847
1844
|
};
|
|
848
1845
|
|
|
849
1846
|
/**
|
|
850
1847
|
* @alpha
|
|
1848
|
+
* @sidebarGroup programmatic api
|
|
1849
|
+
* @see {@link DocAuthDocument.transaction} for running transactions with this callback type.
|
|
851
1850
|
*/
|
|
852
1851
|
export declare type TransactionCallback<T = void> = (context: {
|
|
853
1852
|
draft: Programmatic.Document;
|
|
@@ -855,6 +1854,8 @@ export declare type TransactionCallback<T = void> = (context: {
|
|
|
855
1854
|
|
|
856
1855
|
/**
|
|
857
1856
|
* @alpha
|
|
1857
|
+
* @sidebarGroup programmatic api
|
|
1858
|
+
* @see {@link TransactionCallback} for the callback signature that returns this result type.
|
|
858
1859
|
*/
|
|
859
1860
|
export declare type TransactionResult<T = void> = undefined | boolean | {
|
|
860
1861
|
commit: boolean;
|
|
@@ -867,7 +1868,11 @@ export declare type TransactionResult<T = void> = undefined | boolean | {
|
|
|
867
1868
|
/**
|
|
868
1869
|
* Configuration options for the user interface.
|
|
869
1870
|
*
|
|
1871
|
+
* @since 1.5.0
|
|
870
1872
|
* @public
|
|
1873
|
+
* @sidebarGroup ui
|
|
1874
|
+
* @sidebarGroupOrder 1
|
|
1875
|
+
* @see {@link CreateEditorOptions} for all available options when creating an editor.
|
|
871
1876
|
*/
|
|
872
1877
|
export declare type UIOptions = {
|
|
873
1878
|
/**
|
|
@@ -909,6 +1914,72 @@ export declare type UIOptions = {
|
|
|
909
1914
|
* Initial toolbar configuration.
|
|
910
1915
|
*
|
|
911
1916
|
* The toolbar can also be customized at runtime using `editor.setToolbarConfig()`.
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```ts
|
|
1920
|
+
* import { defaultToolbarConfig, defaultActions } from '@nutrient-sdk/document-authoring';
|
|
1921
|
+
*
|
|
1922
|
+
* // Add a separator and custom action to the default toolbar
|
|
1923
|
+
* const editor = await system.createEditor(target, {
|
|
1924
|
+
* ui: {
|
|
1925
|
+
* actions: [
|
|
1926
|
+
* ...defaultActions,
|
|
1927
|
+
* { id: 'custom.hello', label: 'Say Hello', handler: () => alert('Hello!') },
|
|
1928
|
+
* ],
|
|
1929
|
+
* toolbar: {
|
|
1930
|
+
* items: [
|
|
1931
|
+
* ...defaultToolbarConfig.items,
|
|
1932
|
+
* { type: 'separator', id: 'sep-custom' },
|
|
1933
|
+
* { type: 'action', id: 'custom-action', actionId: 'custom.hello' },
|
|
1934
|
+
* ],
|
|
1935
|
+
* },
|
|
1936
|
+
* },
|
|
1937
|
+
* });
|
|
1938
|
+
* ```
|
|
1939
|
+
*
|
|
1940
|
+
* @example
|
|
1941
|
+
* ```ts
|
|
1942
|
+
* // Create a minimal toolbar with just undo/redo and bold/italic
|
|
1943
|
+
* const editor = await system.createEditor(target, {
|
|
1944
|
+
* ui: {
|
|
1945
|
+
* toolbar: {
|
|
1946
|
+
* items: [
|
|
1947
|
+
* { type: 'built-in', id: 'undo', builtInType: 'undo' },
|
|
1948
|
+
* { type: 'built-in', id: 'redo', builtInType: 'redo' },
|
|
1949
|
+
* { type: 'separator', id: 'sep-1' },
|
|
1950
|
+
* { type: 'built-in', id: 'bold', builtInType: 'bold' },
|
|
1951
|
+
* { type: 'built-in', id: 'italic', builtInType: 'italic' },
|
|
1952
|
+
* ],
|
|
1953
|
+
* },
|
|
1954
|
+
* },
|
|
1955
|
+
* });
|
|
1956
|
+
* ```
|
|
1957
|
+
*
|
|
1958
|
+
* @example
|
|
1959
|
+
* ```ts
|
|
1960
|
+
* // Mix built-in items with custom actions
|
|
1961
|
+
* const editor = await system.createEditor(target, {
|
|
1962
|
+
* ui: {
|
|
1963
|
+
* toolbar: {
|
|
1964
|
+
* items: [
|
|
1965
|
+
* { type: 'built-in', id: 'undo', builtInType: 'undo' },
|
|
1966
|
+
* { type: 'action', id: 'custom-btn', actionId: 'custom.my-action' }
|
|
1967
|
+
* ]
|
|
1968
|
+
* },
|
|
1969
|
+
* actions: [
|
|
1970
|
+
* {
|
|
1971
|
+
* id: 'custom.my-action',
|
|
1972
|
+
* label: 'My Action',
|
|
1973
|
+
* handler: () => console.log('clicked!'),
|
|
1974
|
+
* },
|
|
1975
|
+
* ],
|
|
1976
|
+
* },
|
|
1977
|
+
* });
|
|
1978
|
+
* ```
|
|
1979
|
+
*
|
|
1980
|
+
* @since 1.9.0
|
|
1981
|
+
* @see {@link ToolbarConfig} for the toolbar configuration type.
|
|
1982
|
+
* @see {@link defaultToolbarConfig} for the default toolbar configuration.
|
|
912
1983
|
*/
|
|
913
1984
|
toolbar?: ToolbarConfig;
|
|
914
1985
|
/**
|
|
@@ -917,7 +1988,7 @@ export declare type UIOptions = {
|
|
|
917
1988
|
* Actions can also be customized at runtime using `editor.setActions()`.
|
|
918
1989
|
*
|
|
919
1990
|
* @example
|
|
920
|
-
* ```
|
|
1991
|
+
* ```ts
|
|
921
1992
|
* import { defaultActions } from '@nutrient-sdk/document-authoring';
|
|
922
1993
|
*
|
|
923
1994
|
* const editor = await system.createEditor(target, {
|
|
@@ -928,11 +1999,13 @@ export declare type UIOptions = {
|
|
|
928
1999
|
* id: 'custom.hello',
|
|
929
2000
|
* label: 'Say Hello',
|
|
930
2001
|
* handler: () => alert('Hello!'),
|
|
931
|
-
* }
|
|
932
|
-
* ]
|
|
933
|
-
* }
|
|
2002
|
+
* },
|
|
2003
|
+
* ],
|
|
2004
|
+
* },
|
|
934
2005
|
* });
|
|
935
2006
|
* ```
|
|
2007
|
+
*
|
|
2008
|
+
* @since 1.9.0
|
|
936
2009
|
*/
|
|
937
2010
|
actions?: Action[];
|
|
938
2011
|
};
|
|
@@ -942,7 +2015,10 @@ export declare type UIOptions = {
|
|
|
942
2015
|
*
|
|
943
2016
|
* See {@link UIOptions | UIOptions.unit}
|
|
944
2017
|
*
|
|
2018
|
+
* @since 1.5.0
|
|
945
2019
|
* @public
|
|
2020
|
+
* @sidebarGroup ui
|
|
2021
|
+
* @sidebarGroupOrder 3
|
|
946
2022
|
*/
|
|
947
2023
|
export declare type Unit = 'cm' | 'in' | 'pt' | 'pc' | 'mm';
|
|
948
2024
|
|