@yudaocode/univer-docs 0.0.0-stage → 1.6.204
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 +190 -0
- package/README.md +24 -2
- package/lib/cjs/facade/index.js +1842 -0
- package/lib/cjs/facade/index.js.map +1 -0
- package/lib/cjs/index.js +31844 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/es/facade/index.js +2020 -0
- package/lib/es/facade/index.js.map +1 -0
- package/lib/es/index.js +31503 -0
- package/lib/es/index.js.map +1 -0
- package/lib/types/facade/index.d.ts +364 -0
- package/lib/types/index.d.ts +3687 -0
- package/package.json +61 -3
|
@@ -0,0 +1,2020 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
|
|
13
|
+
// src/facade/f-doc-ext.ts
|
|
14
|
+
import {
|
|
15
|
+
generateRandomId,
|
|
16
|
+
ICommandService,
|
|
17
|
+
Inject,
|
|
18
|
+
Injector
|
|
19
|
+
} from "@univerjs/core";
|
|
20
|
+
import { DocSelectionManagerService } from "@univerjs/docs";
|
|
21
|
+
import {
|
|
22
|
+
convertDocTableToText,
|
|
23
|
+
ConvertTextToDocTableCommand,
|
|
24
|
+
DeleteDocSdtCommand,
|
|
25
|
+
diffDocSnapshots,
|
|
26
|
+
EvaluateDocTableFormulasCommand,
|
|
27
|
+
exportBatchDocPdfBytes,
|
|
28
|
+
exportBatchDocxFiles,
|
|
29
|
+
exportDocHtmlString,
|
|
30
|
+
extractDocCatalog,
|
|
31
|
+
extractDocFormValues,
|
|
32
|
+
FillDocDatasetCommand,
|
|
33
|
+
getDocumentStats,
|
|
34
|
+
IDocAiCopilotService,
|
|
35
|
+
IDocIoService,
|
|
36
|
+
IDocSdtService,
|
|
37
|
+
InsertDocBookmarkCommand,
|
|
38
|
+
InsertDocCalloutCommand,
|
|
39
|
+
InsertDocChartCommand,
|
|
40
|
+
InsertDocCodeBlockCommand,
|
|
41
|
+
InsertDocInlineFormulaCommand,
|
|
42
|
+
InsertDocLatexFormulaCommand,
|
|
43
|
+
InsertDocMedicalFormulaCommand,
|
|
44
|
+
InsertDocQrOrBarcodeBlockCommand,
|
|
45
|
+
InsertDocQuoteCommand,
|
|
46
|
+
InsertDocRepeatingSectionCommand,
|
|
47
|
+
InsertDocSdtCommand,
|
|
48
|
+
InsertDocShapeCommand,
|
|
49
|
+
InsertDocTableOfContentsCommand,
|
|
50
|
+
listDocBookmarks,
|
|
51
|
+
listDocCallouts,
|
|
52
|
+
listDocInlineFormulas,
|
|
53
|
+
listDocQuotes,
|
|
54
|
+
listDocSdtControls,
|
|
55
|
+
listDocTables,
|
|
56
|
+
listLiveDocCharts,
|
|
57
|
+
listLiveDocShapes,
|
|
58
|
+
listLiveLatexFormulas,
|
|
59
|
+
RecalculateDocInlineFormulasCommand,
|
|
60
|
+
RecordDocRevisionCommand,
|
|
61
|
+
RefreshDocTableOfContentsCommand,
|
|
62
|
+
RemoveDocBookmarkCommand,
|
|
63
|
+
RemoveDocCalloutCommand,
|
|
64
|
+
RemoveDocChartCommand,
|
|
65
|
+
RemoveDocLatexFormulaCommand,
|
|
66
|
+
RemoveDocQuoteCommand,
|
|
67
|
+
RemoveDocShapeCommand,
|
|
68
|
+
ReplaceDocUnitSnapshotCommand,
|
|
69
|
+
ResolveDocRevisionCommand,
|
|
70
|
+
RestoreDocVersionCommand,
|
|
71
|
+
SetDocActiveRoleCommand,
|
|
72
|
+
SetDocModeCommand,
|
|
73
|
+
SetDocTableRepeatHeaderCommand,
|
|
74
|
+
SetDocTableRowLoopCommand,
|
|
75
|
+
SetDocTrackChangesCommand,
|
|
76
|
+
SortDocTableCommand,
|
|
77
|
+
UpdateDocCalloutCommand,
|
|
78
|
+
UpdateDocChartCommand,
|
|
79
|
+
UpdateDocLatexFormulaCommand,
|
|
80
|
+
UpdateDocQuoteCommand,
|
|
81
|
+
UpdateDocSdtPropertiesCommand,
|
|
82
|
+
UpdateDocSdtValueCommand,
|
|
83
|
+
UpdateDocShapeCommand,
|
|
84
|
+
validateDocForm,
|
|
85
|
+
checkDocumentSpellingAndTerms,
|
|
86
|
+
DeleteDocTableColumnCommand,
|
|
87
|
+
DeleteDocTableRowCommand,
|
|
88
|
+
FindAndReplaceDocTextCommand,
|
|
89
|
+
getCollapsedHeadingsFromSnapshot,
|
|
90
|
+
getColumnGroupConfigFromSnapshot,
|
|
91
|
+
getDocImageTransformFromSnapshot,
|
|
92
|
+
getDocPrintConfigFromSnapshot,
|
|
93
|
+
getDocumentStatistics,
|
|
94
|
+
getParagraphBorderAndShading,
|
|
95
|
+
getParagraphPagination,
|
|
96
|
+
getParagraphTabStops,
|
|
97
|
+
importLegacyDocBytes,
|
|
98
|
+
InsertDocBibliographyCommand,
|
|
99
|
+
InsertDocBuildingBlockCommand,
|
|
100
|
+
InsertDocCaptionCommand,
|
|
101
|
+
InsertDocCitationCommand,
|
|
102
|
+
InsertDocColumnGroupCommand,
|
|
103
|
+
InsertDocCrossReferenceCommand,
|
|
104
|
+
InsertDocFieldCommand,
|
|
105
|
+
InsertDocPageBreakCommand,
|
|
106
|
+
InsertDocSectionBreakCommand,
|
|
107
|
+
InsertDocSmartArtCommand,
|
|
108
|
+
InsertDocTableColumnCommand,
|
|
109
|
+
InsertDocTableRowCommand,
|
|
110
|
+
InsertHorizontalDividerCommand,
|
|
111
|
+
listDocCaptions,
|
|
112
|
+
listDocCitations,
|
|
113
|
+
listDocFields,
|
|
114
|
+
listLiveSmartArts,
|
|
115
|
+
MergeDocTableCellsCommand,
|
|
116
|
+
RemoveDocSmartArtCommand,
|
|
117
|
+
runMailMergeBatchOnSnapshot,
|
|
118
|
+
SetDocPrintConfigCommand,
|
|
119
|
+
SetParagraphBorderAndShadingCommand,
|
|
120
|
+
SetParagraphPaginationCommand,
|
|
121
|
+
SetParagraphTabStopsCommand,
|
|
122
|
+
SplitDocTableCellCommand,
|
|
123
|
+
ToggleHeadingCollapseCommand,
|
|
124
|
+
UpdateAllDocFieldsCommand,
|
|
125
|
+
UpdateDocImageTransformCommand,
|
|
126
|
+
UpdateDocSmartArtCommand,
|
|
127
|
+
AddDocCascadeRuleCommand,
|
|
128
|
+
AddDocGraffitiStrokeCommand,
|
|
129
|
+
ApplyDocMacrosCommand,
|
|
130
|
+
ClearDocGraffitiStrokesCommand,
|
|
131
|
+
DeleteDocAreaCommand,
|
|
132
|
+
EvaluateDocCascadeRulesCommand,
|
|
133
|
+
evaluateDocCascadeRules,
|
|
134
|
+
getDocAreaBadgeFromSnapshot,
|
|
135
|
+
getDocAreasFromSnapshot,
|
|
136
|
+
getDocAreaValueFromSnapshot,
|
|
137
|
+
getDocCascadeRulesFromSnapshot,
|
|
138
|
+
getDocEmbedBlocksFromSnapshot,
|
|
139
|
+
getDocGraffitiStrokesFromSnapshot,
|
|
140
|
+
getDocLabelBadgesFromSnapshot,
|
|
141
|
+
getDocMainBadgeFromSnapshot,
|
|
142
|
+
getStyledSeparatorsFromSnapshot,
|
|
143
|
+
InsertDocAreaCommand,
|
|
144
|
+
InsertDocEmbedBlockCommand,
|
|
145
|
+
InsertDocLabelBadgeCommand,
|
|
146
|
+
InsertStyledSeparatorCommand,
|
|
147
|
+
isOffsetReadonlyByArea,
|
|
148
|
+
normalizeMacroName,
|
|
149
|
+
registerDocMacro,
|
|
150
|
+
RemoveDocCascadeRuleCommand,
|
|
151
|
+
RemoveDocEmbedBlockCommand,
|
|
152
|
+
RemoveDocLabelBadgeCommand,
|
|
153
|
+
SetDocAreaBadgeCommand,
|
|
154
|
+
SetDocAreaPropertiesCommand,
|
|
155
|
+
SetDocAreaValueCommand,
|
|
156
|
+
SetDocCascadeRulesCommand,
|
|
157
|
+
SetDocMainBadgeCommand,
|
|
158
|
+
unregisterDocMacro,
|
|
159
|
+
AutoFitDocTableCommand,
|
|
160
|
+
CleanUpDocFormattingCommand,
|
|
161
|
+
CompareDocSnapshotsToTrackCommand,
|
|
162
|
+
DeleteDocColumnGroupCommand,
|
|
163
|
+
DeleteDocNoteCommand,
|
|
164
|
+
exportDocToMarkdown,
|
|
165
|
+
getDocCopyPastePolicyFromSnapshot,
|
|
166
|
+
getDocCustomPropertiesFromSnapshot,
|
|
167
|
+
getDocListsFromSnapshot,
|
|
168
|
+
getDocNoteSettingsFromSnapshot,
|
|
169
|
+
getDocTableCellProperties,
|
|
170
|
+
HighlightInvalidDocSdtCommand,
|
|
171
|
+
IDocActionMacroService,
|
|
172
|
+
importMarkdownToDocData,
|
|
173
|
+
InsertDocEndnoteCommand,
|
|
174
|
+
InsertDocFootnoteCommand,
|
|
175
|
+
InsertDocListCommand,
|
|
176
|
+
JumpDocSdtControlCommand,
|
|
177
|
+
listDocNotesFromSnapshot,
|
|
178
|
+
RemoveDocTableOfContentsCommand,
|
|
179
|
+
SetDocCopyPastePolicyCommand,
|
|
180
|
+
SetDocCustomPropertiesCommand,
|
|
181
|
+
SetDocListGlyphTypeCommand,
|
|
182
|
+
SetDocListLevelCommand,
|
|
183
|
+
SetDocNoteSettingsCommand,
|
|
184
|
+
SetDocSectionOrientationCommand,
|
|
185
|
+
SetDocTableBorderPresetCommand,
|
|
186
|
+
SetDocTableCellPropertiesCommand,
|
|
187
|
+
SetDocTextDirectionCommand,
|
|
188
|
+
ToggleDocListCheckboxCommand,
|
|
189
|
+
UpdateDocColumnGroupCommand,
|
|
190
|
+
UpdateDocNoteCommand,
|
|
191
|
+
AddDocCommentCommand,
|
|
192
|
+
CancelDocHyperlinkCommand,
|
|
193
|
+
DeleteDocCommentCommand,
|
|
194
|
+
DeleteDocHyperlinkCommand,
|
|
195
|
+
extractDocCatalogTree,
|
|
196
|
+
getDocTitleEntriesFromSnapshot,
|
|
197
|
+
getDocTitleValueFromSnapshot,
|
|
198
|
+
getReadabilityStatistics,
|
|
199
|
+
IDocExtensionRegistryService,
|
|
200
|
+
importHtmlToDocData,
|
|
201
|
+
InsertDocHyperlinkCommand,
|
|
202
|
+
InsertDocTitleCommand,
|
|
203
|
+
listDocCommentsFromSnapshot,
|
|
204
|
+
listDocHyperlinks,
|
|
205
|
+
ReplyDocCommentCommand,
|
|
206
|
+
ResolveDocCommentCommand,
|
|
207
|
+
SetDocTitlePropertiesCommand,
|
|
208
|
+
ToggleDocSubscriptCommand,
|
|
209
|
+
ToggleDocSuperscriptCommand,
|
|
210
|
+
UpdateDocHyperlinkCommand
|
|
211
|
+
} from "@yudaocode/univer-docs";
|
|
212
|
+
var FEnterpriseDoc = class {
|
|
213
|
+
constructor(_docModel, _injector, _commandService) {
|
|
214
|
+
this._docModel = _docModel;
|
|
215
|
+
this._injector = _injector;
|
|
216
|
+
this._commandService = _commandService;
|
|
217
|
+
}
|
|
218
|
+
getId() {
|
|
219
|
+
return this._docModel.getUnitId();
|
|
220
|
+
}
|
|
221
|
+
getTitle() {
|
|
222
|
+
return this._docModel.getSnapshot().title || "";
|
|
223
|
+
}
|
|
224
|
+
save() {
|
|
225
|
+
return this._docModel.getSnapshot();
|
|
226
|
+
}
|
|
227
|
+
getMode() {
|
|
228
|
+
return this._injector.get(IDocSdtService).getDocMode(this.getId());
|
|
229
|
+
}
|
|
230
|
+
setMode(mode) {
|
|
231
|
+
return this._commandService.syncExecuteCommand(SetDocModeCommand.id, {
|
|
232
|
+
unitId: this.getId(),
|
|
233
|
+
mode
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
setTemplateMetadata(metadata) {
|
|
237
|
+
this._injector.get(IDocSdtService).setTemplateMetadata(this.getId(), metadata);
|
|
238
|
+
}
|
|
239
|
+
getTemplateMetadata() {
|
|
240
|
+
return this._injector.get(IDocSdtService).getTemplateMetadata(this.getId());
|
|
241
|
+
}
|
|
242
|
+
getTables() {
|
|
243
|
+
return listDocTables(this.save());
|
|
244
|
+
}
|
|
245
|
+
setTableRowLoop(tableId, rowIndex, config) {
|
|
246
|
+
return this._commandService.syncExecuteCommand(SetDocTableRowLoopCommand.id, {
|
|
247
|
+
unitId: this.getId(),
|
|
248
|
+
tableId,
|
|
249
|
+
rowIndex,
|
|
250
|
+
config
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
insertSdtControl(spec, initialValue, offset, segmentId) {
|
|
254
|
+
return this._commandService.syncExecuteCommand(InsertDocSdtCommand.id, {
|
|
255
|
+
unitId: this.getId(),
|
|
256
|
+
offset,
|
|
257
|
+
segmentId,
|
|
258
|
+
spec,
|
|
259
|
+
initialValue
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
updateSdtValue(controlId, value, force = false, segmentId) {
|
|
263
|
+
return this._commandService.syncExecuteCommand(UpdateDocSdtValueCommand.id, {
|
|
264
|
+
unitId: this.getId(),
|
|
265
|
+
controlId,
|
|
266
|
+
value,
|
|
267
|
+
force,
|
|
268
|
+
segmentId
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
updateSdtProperties(controlId, patch, segmentId) {
|
|
272
|
+
return this._commandService.syncExecuteCommand(UpdateDocSdtPropertiesCommand.id, {
|
|
273
|
+
unitId: this.getId(),
|
|
274
|
+
controlId,
|
|
275
|
+
patch,
|
|
276
|
+
segmentId
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
deleteSdtControl(controlId, keepText = false, force = false, segmentId) {
|
|
280
|
+
return this._commandService.syncExecuteCommand(DeleteDocSdtCommand.id, {
|
|
281
|
+
unitId: this.getId(),
|
|
282
|
+
controlId,
|
|
283
|
+
keepText,
|
|
284
|
+
force,
|
|
285
|
+
segmentId
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
getSdtControls(options) {
|
|
289
|
+
return listDocSdtControls(this.save(), options);
|
|
290
|
+
}
|
|
291
|
+
getFormValues() {
|
|
292
|
+
return extractDocFormValues(this.save());
|
|
293
|
+
}
|
|
294
|
+
validateForm() {
|
|
295
|
+
return validateDocForm(this.save());
|
|
296
|
+
}
|
|
297
|
+
fillDataset(data) {
|
|
298
|
+
return this._commandService.syncExecuteCommand(FillDocDatasetCommand.id, {
|
|
299
|
+
unitId: this.getId(),
|
|
300
|
+
data
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// ---- Contract Track Changes (`修订留痕`) ----
|
|
304
|
+
setTrackChanges(enabled, author) {
|
|
305
|
+
return this._commandService.syncExecuteCommand(SetDocTrackChangesCommand.id, {
|
|
306
|
+
unitId: this.getId(),
|
|
307
|
+
enabled,
|
|
308
|
+
author
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
insertTrackedText(text, index, author) {
|
|
312
|
+
return this._commandService.syncExecuteCommand(RecordDocRevisionCommand.id, {
|
|
313
|
+
unitId: this.getId(),
|
|
314
|
+
type: "insert",
|
|
315
|
+
text,
|
|
316
|
+
index,
|
|
317
|
+
author
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
markTrackedDeletion(startIndex, endIndex, author) {
|
|
321
|
+
const stream = this.save().body?.dataStream ?? "";
|
|
322
|
+
const text = stream.slice(startIndex, endIndex).replace(/[\r\n\u0000-\u001F]/g, "");
|
|
323
|
+
return this._commandService.syncExecuteCommand(RecordDocRevisionCommand.id, {
|
|
324
|
+
unitId: this.getId(),
|
|
325
|
+
type: "delete",
|
|
326
|
+
text,
|
|
327
|
+
index: startIndex,
|
|
328
|
+
endIndex,
|
|
329
|
+
author
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
acceptRevision(revisionId) {
|
|
333
|
+
return this._commandService.syncExecuteCommand(ResolveDocRevisionCommand.id, {
|
|
334
|
+
unitId: this.getId(),
|
|
335
|
+
revisionId,
|
|
336
|
+
action: "accept"
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
rejectRevision(revisionId) {
|
|
340
|
+
return this._commandService.syncExecuteCommand(ResolveDocRevisionCommand.id, {
|
|
341
|
+
unitId: this.getId(),
|
|
342
|
+
revisionId,
|
|
343
|
+
action: "reject"
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
acceptAllRevisions() {
|
|
347
|
+
return this._commandService.syncExecuteCommand(ResolveDocRevisionCommand.id, {
|
|
348
|
+
unitId: this.getId(),
|
|
349
|
+
action: "accept",
|
|
350
|
+
all: true
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
rejectAllRevisions() {
|
|
354
|
+
return this._commandService.syncExecuteCommand(ResolveDocRevisionCommand.id, {
|
|
355
|
+
unitId: this.getId(),
|
|
356
|
+
action: "reject",
|
|
357
|
+
all: true
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
getRevisions() {
|
|
361
|
+
return this.getTemplateMetadata().revisions ?? [];
|
|
362
|
+
}
|
|
363
|
+
// ---- AI Contract Risk Auditor & Clause Drafter ----
|
|
364
|
+
async auditContractRisks() {
|
|
365
|
+
return this._injector.get(IDocAiCopilotService).auditContract(this.getId(), this.save());
|
|
366
|
+
}
|
|
367
|
+
async draftClauseByAi(prompt) {
|
|
368
|
+
return this._injector.get(IDocAiCopilotService).draftClause(this.getId(), this.save(), prompt);
|
|
369
|
+
}
|
|
370
|
+
// ---- IO & Export ----
|
|
371
|
+
getIoCapabilities() {
|
|
372
|
+
return this._injector.get(IDocIoService).getIoCapabilities();
|
|
373
|
+
}
|
|
374
|
+
async importDocFileWithReport(file, options) {
|
|
375
|
+
const outcome = await this._injector.get(IDocIoService).importDocWithReport(file, {
|
|
376
|
+
unitId: this.getId(),
|
|
377
|
+
target: options?.target
|
|
378
|
+
});
|
|
379
|
+
if (outcome.documentData.body) {
|
|
380
|
+
this._commandService.syncExecuteCommand(ReplaceDocUnitSnapshotCommand.id, {
|
|
381
|
+
unitId: this.getId(),
|
|
382
|
+
snapshot: outcome.documentData
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
return outcome;
|
|
386
|
+
}
|
|
387
|
+
async importDocFile(file, options) {
|
|
388
|
+
const outcome = await this.importDocFileWithReport(file, options);
|
|
389
|
+
return outcome.documentData;
|
|
390
|
+
}
|
|
391
|
+
async exportDocx(data, options) {
|
|
392
|
+
return this._injector.get(IDocIoService).exportDoc({
|
|
393
|
+
unitId: this.getId(),
|
|
394
|
+
snapshot: this.save(),
|
|
395
|
+
format: "docx",
|
|
396
|
+
data,
|
|
397
|
+
pdfOptions: options?.signatureImageDataUrl ? { signatureImageDataUrl: options.signatureImageDataUrl } : void 0,
|
|
398
|
+
target: options?.target
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
async exportPdf(pdfOptions, options) {
|
|
402
|
+
return this._injector.get(IDocIoService).exportDoc({
|
|
403
|
+
unitId: this.getId(),
|
|
404
|
+
snapshot: this.save(),
|
|
405
|
+
format: "pdf",
|
|
406
|
+
data: options?.data ?? pdfOptions?.data,
|
|
407
|
+
pdfOptions,
|
|
408
|
+
target: options?.target
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
getCatalog() {
|
|
412
|
+
return extractDocCatalog(this.save());
|
|
413
|
+
}
|
|
414
|
+
getDocumentOutline() {
|
|
415
|
+
return extractDocCatalog(this.save());
|
|
416
|
+
}
|
|
417
|
+
evaluateTableFormulas() {
|
|
418
|
+
return this._commandService.syncExecuteCommand(EvaluateDocTableFormulasCommand.id, {
|
|
419
|
+
unitId: this.getId()
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
saveVersion(label) {
|
|
423
|
+
return this._injector.get(IDocSdtService).saveVersionSnapshot(this.getId(), label);
|
|
424
|
+
}
|
|
425
|
+
getVersions() {
|
|
426
|
+
return this._injector.get(IDocSdtService).listVersionSnapshots(this.getId());
|
|
427
|
+
}
|
|
428
|
+
restoreVersion(versionId) {
|
|
429
|
+
return this._commandService.syncExecuteCommand(RestoreDocVersionCommand.id, {
|
|
430
|
+
unitId: this.getId(),
|
|
431
|
+
versionId
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
async exportHtml(data, printOptions, options) {
|
|
435
|
+
if (printOptions && options?.target !== "server") {
|
|
436
|
+
return exportDocHtmlString(this.save(), data, printOptions);
|
|
437
|
+
}
|
|
438
|
+
const bytes = await this._injector.get(IDocIoService).exportDoc({
|
|
439
|
+
unitId: this.getId(),
|
|
440
|
+
snapshot: this.save(),
|
|
441
|
+
format: "html",
|
|
442
|
+
data,
|
|
443
|
+
target: options?.target
|
|
444
|
+
});
|
|
445
|
+
return new TextDecoder().decode(bytes);
|
|
446
|
+
}
|
|
447
|
+
async saveToHost() {
|
|
448
|
+
return this._injector.get(IDocIoService).saveToHost({
|
|
449
|
+
unitId: this.getId(),
|
|
450
|
+
snapshot: this.save()
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
// ---- v1.6.203 Medical Formulas, Code/Barcode Blocks, Co-Signing Roles, Stats, Diff & Batch Mail-Merge ----
|
|
454
|
+
insertMedicalFormula(spec, offset, blockId) {
|
|
455
|
+
return this._commandService.syncExecuteCommand(InsertDocMedicalFormulaCommand.id, {
|
|
456
|
+
unitId: this.getId(),
|
|
457
|
+
offset,
|
|
458
|
+
blockId,
|
|
459
|
+
spec
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
insertCodeBlock(codeOrSpec, language, offset) {
|
|
463
|
+
const code = typeof codeOrSpec === "string" ? codeOrSpec : codeOrSpec.code;
|
|
464
|
+
const resolvedLang = typeof codeOrSpec === "string" ? language : codeOrSpec.language ?? language;
|
|
465
|
+
const id = typeof codeOrSpec === "string" ? void 0 : codeOrSpec.id;
|
|
466
|
+
return this._commandService.syncExecuteCommand(InsertDocCodeBlockCommand.id, {
|
|
467
|
+
unitId: this.getId(),
|
|
468
|
+
id,
|
|
469
|
+
code,
|
|
470
|
+
language: resolvedLang,
|
|
471
|
+
offset
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
insertBarcodeOrQrBlock(spec, offset, blockId) {
|
|
475
|
+
return this._commandService.syncExecuteCommand(InsertDocQrOrBarcodeBlockCommand.id, {
|
|
476
|
+
unitId: this.getId(),
|
|
477
|
+
offset,
|
|
478
|
+
blockId,
|
|
479
|
+
spec
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
setActiveRole(role) {
|
|
483
|
+
return this._commandService.syncExecuteCommand(SetDocActiveRoleCommand.id, {
|
|
484
|
+
unitId: this.getId(),
|
|
485
|
+
role
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
getActiveRole() {
|
|
489
|
+
return this._injector.get(IDocSdtService).getActiveRole(this.getId());
|
|
490
|
+
}
|
|
491
|
+
getStats() {
|
|
492
|
+
return getDocumentStats(this.save());
|
|
493
|
+
}
|
|
494
|
+
diffWith(other) {
|
|
495
|
+
const targetSnapshot = other instanceof FEnterpriseDoc ? other.save() : other;
|
|
496
|
+
return diffDocSnapshots(this.save(), targetSnapshot);
|
|
497
|
+
}
|
|
498
|
+
async exportBatchPdf(records, pdfOptions) {
|
|
499
|
+
return exportBatchDocPdfBytes(this.save(), records, pdfOptions);
|
|
500
|
+
}
|
|
501
|
+
async exportBatchDocx(records, fileNamePattern) {
|
|
502
|
+
return exportBatchDocxFiles(this.save(), records, fileNamePattern);
|
|
503
|
+
}
|
|
504
|
+
// ---- v1.6.204 Callout & Quote Blocks ----
|
|
505
|
+
insertCallout(spec, offset) {
|
|
506
|
+
const id = spec.id || `callout_${generateRandomId(6)}`;
|
|
507
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocCalloutCommand.id, {
|
|
508
|
+
unitId: this.getId(),
|
|
509
|
+
offset,
|
|
510
|
+
spec: { ...spec, id }
|
|
511
|
+
});
|
|
512
|
+
if (!ok) return null;
|
|
513
|
+
return this.getCallouts().find((c) => c.id === id) ?? null;
|
|
514
|
+
}
|
|
515
|
+
updateCallout(id, patch) {
|
|
516
|
+
return this._commandService.syncExecuteCommand(UpdateDocCalloutCommand.id, {
|
|
517
|
+
unitId: this.getId(),
|
|
518
|
+
id,
|
|
519
|
+
patch
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
removeCallout(id) {
|
|
523
|
+
return this._commandService.syncExecuteCommand(RemoveDocCalloutCommand.id, {
|
|
524
|
+
unitId: this.getId(),
|
|
525
|
+
id
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
getCallouts() {
|
|
529
|
+
return listDocCallouts(this.save());
|
|
530
|
+
}
|
|
531
|
+
insertQuote(spec, offset) {
|
|
532
|
+
const id = spec.id || `quote_${generateRandomId(6)}`;
|
|
533
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocQuoteCommand.id, {
|
|
534
|
+
unitId: this.getId(),
|
|
535
|
+
offset,
|
|
536
|
+
spec: { ...spec, id }
|
|
537
|
+
});
|
|
538
|
+
if (!ok) return null;
|
|
539
|
+
return this.getQuotes().find((q) => q.id === id) ?? null;
|
|
540
|
+
}
|
|
541
|
+
updateQuote(id, patch) {
|
|
542
|
+
return this._commandService.syncExecuteCommand(UpdateDocQuoteCommand.id, {
|
|
543
|
+
unitId: this.getId(),
|
|
544
|
+
id,
|
|
545
|
+
patch
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
removeQuote(id) {
|
|
549
|
+
return this._commandService.syncExecuteCommand(RemoveDocQuoteCommand.id, {
|
|
550
|
+
unitId: this.getId(),
|
|
551
|
+
id
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
getQuotes() {
|
|
555
|
+
return listDocQuotes(this.save());
|
|
556
|
+
}
|
|
557
|
+
// ---- v1.6.204 General-Purpose LaTeX Mathematical Formula Engine ----
|
|
558
|
+
insertLatexFormula(spec, offset) {
|
|
559
|
+
const id = spec.id || `latex_${generateRandomId(6)}`;
|
|
560
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocLatexFormulaCommand.id, {
|
|
561
|
+
unitId: this.getId(),
|
|
562
|
+
offset,
|
|
563
|
+
spec: { ...spec, id }
|
|
564
|
+
});
|
|
565
|
+
if (!ok) return null;
|
|
566
|
+
return this.getLatexFormulas().find((f) => f.id === id) ?? null;
|
|
567
|
+
}
|
|
568
|
+
updateLatexFormula(id, latexOrPatch) {
|
|
569
|
+
return this._commandService.syncExecuteCommand(UpdateDocLatexFormulaCommand.id, {
|
|
570
|
+
unitId: this.getId(),
|
|
571
|
+
id,
|
|
572
|
+
...typeof latexOrPatch === "string" ? { latex: latexOrPatch } : { patch: latexOrPatch }
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
removeLatexFormula(id) {
|
|
576
|
+
return this._commandService.syncExecuteCommand(RemoveDocLatexFormulaCommand.id, {
|
|
577
|
+
unitId: this.getId(),
|
|
578
|
+
id
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
getLatexFormulas() {
|
|
582
|
+
return listLiveLatexFormulas(this.save());
|
|
583
|
+
}
|
|
584
|
+
findLatexFormulaByText(substr) {
|
|
585
|
+
const needle = (substr ?? "").trim();
|
|
586
|
+
if (!needle) return void 0;
|
|
587
|
+
return this.getLatexFormulas().find((f) => f.latex.includes(needle) || f.id === needle);
|
|
588
|
+
}
|
|
589
|
+
// ---- v1.6.204 Inline Document Data Formulas + Embedded Charts + Shapes ----
|
|
590
|
+
insertInlineFormula(spec, offset, extraVars) {
|
|
591
|
+
const id = spec.id || `ifml_${generateRandomId(6)}`;
|
|
592
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocInlineFormulaCommand.id, {
|
|
593
|
+
unitId: this.getId(),
|
|
594
|
+
offset,
|
|
595
|
+
spec: { ...spec, id },
|
|
596
|
+
extraVars
|
|
597
|
+
});
|
|
598
|
+
if (!ok) return null;
|
|
599
|
+
return this.getInlineFormulas().find((f) => f.id === id) ?? null;
|
|
600
|
+
}
|
|
601
|
+
recalculateInlineFormulas(extraVars) {
|
|
602
|
+
return this._commandService.syncExecuteCommand(RecalculateDocInlineFormulasCommand.id, {
|
|
603
|
+
unitId: this.getId(),
|
|
604
|
+
extraVars
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
getInlineFormulas() {
|
|
608
|
+
return listDocInlineFormulas(this.save());
|
|
609
|
+
}
|
|
610
|
+
insertDocChart(spec, offset) {
|
|
611
|
+
const id = spec.id || `chart_${generateRandomId(6)}`;
|
|
612
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocChartCommand.id, {
|
|
613
|
+
unitId: this.getId(),
|
|
614
|
+
offset,
|
|
615
|
+
spec: { ...spec, id }
|
|
616
|
+
});
|
|
617
|
+
if (!ok) return null;
|
|
618
|
+
return this.getDocCharts().find((c) => c.id === id) ?? null;
|
|
619
|
+
}
|
|
620
|
+
updateDocChart(id, patch) {
|
|
621
|
+
return this._commandService.syncExecuteCommand(UpdateDocChartCommand.id, {
|
|
622
|
+
unitId: this.getId(),
|
|
623
|
+
id,
|
|
624
|
+
patch
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
removeDocChart(id) {
|
|
628
|
+
return this._commandService.syncExecuteCommand(RemoveDocChartCommand.id, {
|
|
629
|
+
unitId: this.getId(),
|
|
630
|
+
id
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
getDocCharts() {
|
|
634
|
+
return listLiveDocCharts(this.save());
|
|
635
|
+
}
|
|
636
|
+
insertDocShape(spec, offset) {
|
|
637
|
+
const id = spec.id || `shape_${generateRandomId(6)}`;
|
|
638
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocShapeCommand.id, {
|
|
639
|
+
unitId: this.getId(),
|
|
640
|
+
offset,
|
|
641
|
+
spec: { ...spec, id }
|
|
642
|
+
});
|
|
643
|
+
if (!ok) return null;
|
|
644
|
+
return this.getDocShapes().find((s) => s.id === id) ?? null;
|
|
645
|
+
}
|
|
646
|
+
updateDocShape(id, patch) {
|
|
647
|
+
return this._commandService.syncExecuteCommand(UpdateDocShapeCommand.id, {
|
|
648
|
+
unitId: this.getId(),
|
|
649
|
+
id,
|
|
650
|
+
patch
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
removeDocShape(id) {
|
|
654
|
+
return this._commandService.syncExecuteCommand(RemoveDocShapeCommand.id, {
|
|
655
|
+
unitId: this.getId(),
|
|
656
|
+
id
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
getDocShapes() {
|
|
660
|
+
return listLiveDocShapes(this.save());
|
|
661
|
+
}
|
|
662
|
+
// ---- v1.6.204 Enhanced Document Tables (Sort, Repeat Header, Text/Table Conversion) ----
|
|
663
|
+
sortTableByColumn(tableIndex, columnIndex, direction = "asc", headerRowCount = 1) {
|
|
664
|
+
return this._commandService.syncExecuteCommand(SortDocTableCommand.id, {
|
|
665
|
+
unitId: this.getId(),
|
|
666
|
+
tableIndex,
|
|
667
|
+
columnIndex,
|
|
668
|
+
direction,
|
|
669
|
+
headerRowCount
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
setTableRepeatHeader(tableIndex, headerRowCount) {
|
|
673
|
+
return this._commandService.syncExecuteCommand(SetDocTableRepeatHeaderCommand.id, {
|
|
674
|
+
unitId: this.getId(),
|
|
675
|
+
tableIndex,
|
|
676
|
+
headerRowCount
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
convertTextToTable(text, delimiter, offset) {
|
|
680
|
+
return this._commandService.syncExecuteCommand(ConvertTextToDocTableCommand.id, {
|
|
681
|
+
unitId: this.getId(),
|
|
682
|
+
text,
|
|
683
|
+
delimiter,
|
|
684
|
+
offset
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
convertTableToText(tableIndex, delimiter = " ") {
|
|
688
|
+
return convertDocTableToText(this.save(), tableIndex, delimiter);
|
|
689
|
+
}
|
|
690
|
+
// ---- v1.6.204 Repeating Section SDT, Bookmarks & Table of Contents ----
|
|
691
|
+
insertRepeatingSection(spec, offset) {
|
|
692
|
+
const id = spec.id || `rep_${generateRandomId(6)}`;
|
|
693
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocRepeatingSectionCommand.id, {
|
|
694
|
+
unitId: this.getId(),
|
|
695
|
+
offset,
|
|
696
|
+
spec: { ...spec, id }
|
|
697
|
+
});
|
|
698
|
+
if (!ok) return null;
|
|
699
|
+
return this.getSdtControls().find((c) => c.id === id) ?? null;
|
|
700
|
+
}
|
|
701
|
+
insertBookmark(spec) {
|
|
702
|
+
const id = spec.id || `bm_${generateRandomId(6)}`;
|
|
703
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocBookmarkCommand.id, {
|
|
704
|
+
unitId: this.getId(),
|
|
705
|
+
spec: { ...spec, id }
|
|
706
|
+
});
|
|
707
|
+
if (!ok) return null;
|
|
708
|
+
return this.getBookmarks().find((b) => b.id === id || b.name === spec.name) ?? null;
|
|
709
|
+
}
|
|
710
|
+
getBookmarks() {
|
|
711
|
+
return listDocBookmarks(this.save());
|
|
712
|
+
}
|
|
713
|
+
removeBookmark(nameOrId) {
|
|
714
|
+
return this._commandService.syncExecuteCommand(RemoveDocBookmarkCommand.id, {
|
|
715
|
+
unitId: this.getId(),
|
|
716
|
+
nameOrId
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
insertTableOfContents(spec, offset) {
|
|
720
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocTableOfContentsCommand.id, {
|
|
721
|
+
unitId: this.getId(),
|
|
722
|
+
offset,
|
|
723
|
+
spec
|
|
724
|
+
});
|
|
725
|
+
if (!ok) return null;
|
|
726
|
+
return this.getTemplateMetadata().tocConfig ?? null;
|
|
727
|
+
}
|
|
728
|
+
refreshTableOfContents() {
|
|
729
|
+
return this._commandService.syncExecuteCommand(RefreshDocTableOfContentsCommand.id, {
|
|
730
|
+
unitId: this.getId()
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
// ---- v1.6.204 Wave 2: Paragraph Borders/Shading/Divider, Tab Stops, Collapsible Headings & Find/Replace ----
|
|
734
|
+
setParagraphBorderAndShading(paragraphIndex, spec) {
|
|
735
|
+
return this._commandService.syncExecuteCommand(SetParagraphBorderAndShadingCommand.id, {
|
|
736
|
+
unitId: this.getId(),
|
|
737
|
+
paragraphIndex,
|
|
738
|
+
spec
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
getParagraphBorderAndShading(paragraphIndex) {
|
|
742
|
+
return getParagraphBorderAndShading(this.save(), paragraphIndex);
|
|
743
|
+
}
|
|
744
|
+
insertHorizontalDivider(style = "single", offset) {
|
|
745
|
+
return this._commandService.syncExecuteCommand(InsertHorizontalDividerCommand.id, {
|
|
746
|
+
unitId: this.getId(),
|
|
747
|
+
style,
|
|
748
|
+
offset
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
setParagraphTabStops(paragraphIndex, tabStops) {
|
|
752
|
+
return this._commandService.syncExecuteCommand(SetParagraphTabStopsCommand.id, {
|
|
753
|
+
unitId: this.getId(),
|
|
754
|
+
paragraphIndex,
|
|
755
|
+
tabStops
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
getParagraphTabStops(paragraphIndex) {
|
|
759
|
+
return getParagraphTabStops(this.save(), paragraphIndex);
|
|
760
|
+
}
|
|
761
|
+
toggleHeadingCollapse(headingParagraphIndex) {
|
|
762
|
+
return this._commandService.syncExecuteCommand(ToggleHeadingCollapseCommand.id, {
|
|
763
|
+
unitId: this.getId(),
|
|
764
|
+
headingParagraphIndex
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
getCollapsedHeadings() {
|
|
768
|
+
return getCollapsedHeadingsFromSnapshot(this.save());
|
|
769
|
+
}
|
|
770
|
+
findAndReplaceDocText(query, replacement, options) {
|
|
771
|
+
let count = 0;
|
|
772
|
+
this._commandService.syncExecuteCommand(FindAndReplaceDocTextCommand.id, {
|
|
773
|
+
unitId: this.getId(),
|
|
774
|
+
query,
|
|
775
|
+
replacement,
|
|
776
|
+
options,
|
|
777
|
+
onResult: (n) => {
|
|
778
|
+
count = n;
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
return count;
|
|
782
|
+
}
|
|
783
|
+
findAndReplace(query, replacement, options) {
|
|
784
|
+
return this.findAndReplaceDocText(query, replacement, options);
|
|
785
|
+
}
|
|
786
|
+
getDocumentStatistics() {
|
|
787
|
+
return getDocumentStatistics(this.save());
|
|
788
|
+
}
|
|
789
|
+
checkDocumentSpellingAndTerms(customGlossary) {
|
|
790
|
+
return checkDocumentSpellingAndTerms(this.save(), customGlossary);
|
|
791
|
+
}
|
|
792
|
+
// ---- v1.6.204 Wave 2: Breaks, Proportional Column Groups (`2..5`), Pagination & Print Setup ----
|
|
793
|
+
insertPageBreak(offset) {
|
|
794
|
+
return this._commandService.syncExecuteCommand(InsertDocPageBreakCommand.id, {
|
|
795
|
+
unitId: this.getId(),
|
|
796
|
+
offset
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
insertSectionBreak(type = "nextPage", offset, orientation) {
|
|
800
|
+
return this._commandService.syncExecuteCommand(InsertDocSectionBreakCommand.id, {
|
|
801
|
+
unitId: this.getId(),
|
|
802
|
+
breakType: type,
|
|
803
|
+
offset,
|
|
804
|
+
orientation
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
insertColumnGroup(columnCount, options) {
|
|
808
|
+
return this._commandService.syncExecuteCommand(InsertDocColumnGroupCommand.id, {
|
|
809
|
+
unitId: this.getId(),
|
|
810
|
+
columnCount,
|
|
811
|
+
options
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
getColumnGroupConfig() {
|
|
815
|
+
return getColumnGroupConfigFromSnapshot(this.save());
|
|
816
|
+
}
|
|
817
|
+
setParagraphPagination(paragraphIndex, spec) {
|
|
818
|
+
return this._commandService.syncExecuteCommand(SetParagraphPaginationCommand.id, {
|
|
819
|
+
unitId: this.getId(),
|
|
820
|
+
paragraphIndex,
|
|
821
|
+
spec
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
getParagraphPagination(paragraphIndex) {
|
|
825
|
+
return getParagraphPagination(this.save(), paragraphIndex);
|
|
826
|
+
}
|
|
827
|
+
setPrintConfig(config) {
|
|
828
|
+
return this._commandService.syncExecuteCommand(SetDocPrintConfigCommand.id, {
|
|
829
|
+
unitId: this.getId(),
|
|
830
|
+
config
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
getPrintConfig() {
|
|
834
|
+
return getDocPrintConfigFromSnapshot(this.save());
|
|
835
|
+
}
|
|
836
|
+
// ---- v1.6.204 Wave 2: Image Transform, SmartArt Diagrams & Programmatic Table Manipulation ----
|
|
837
|
+
updateDocImageTransform(drawingId, spec) {
|
|
838
|
+
return this._commandService.syncExecuteCommand(UpdateDocImageTransformCommand.id, {
|
|
839
|
+
unitId: this.getId(),
|
|
840
|
+
drawingId,
|
|
841
|
+
spec
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
getDocImageTransform(drawingId) {
|
|
845
|
+
return getDocImageTransformFromSnapshot(this.save(), drawingId);
|
|
846
|
+
}
|
|
847
|
+
insertSmartArt(spec, offset) {
|
|
848
|
+
const id = spec.id || `smartart_${generateRandomId(6)}`;
|
|
849
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocSmartArtCommand.id, {
|
|
850
|
+
unitId: this.getId(),
|
|
851
|
+
offset,
|
|
852
|
+
spec: { ...spec, id }
|
|
853
|
+
});
|
|
854
|
+
if (!ok) return null;
|
|
855
|
+
return this.getSmartArts().find((s) => s.id === id) ?? null;
|
|
856
|
+
}
|
|
857
|
+
updateSmartArt(id, patch) {
|
|
858
|
+
return this._commandService.syncExecuteCommand(UpdateDocSmartArtCommand.id, {
|
|
859
|
+
unitId: this.getId(),
|
|
860
|
+
id,
|
|
861
|
+
patch
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
removeSmartArt(id) {
|
|
865
|
+
return this._commandService.syncExecuteCommand(RemoveDocSmartArtCommand.id, {
|
|
866
|
+
unitId: this.getId(),
|
|
867
|
+
id
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
getSmartArts() {
|
|
871
|
+
return listLiveSmartArts(this.save());
|
|
872
|
+
}
|
|
873
|
+
insertTableRow(tableIndex, rowIndex, position = "below") {
|
|
874
|
+
return this._commandService.syncExecuteCommand(InsertDocTableRowCommand.id, {
|
|
875
|
+
unitId: this.getId(),
|
|
876
|
+
tableIndex,
|
|
877
|
+
rowIndex,
|
|
878
|
+
position
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
deleteTableRow(tableIndex, rowIndex) {
|
|
882
|
+
return this._commandService.syncExecuteCommand(DeleteDocTableRowCommand.id, {
|
|
883
|
+
unitId: this.getId(),
|
|
884
|
+
tableIndex,
|
|
885
|
+
rowIndex
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
insertTableColumn(tableIndex, colIndex, position = "right") {
|
|
889
|
+
return this._commandService.syncExecuteCommand(InsertDocTableColumnCommand.id, {
|
|
890
|
+
unitId: this.getId(),
|
|
891
|
+
tableIndex,
|
|
892
|
+
colIndex,
|
|
893
|
+
position
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
deleteTableColumn(tableIndex, colIndex) {
|
|
897
|
+
return this._commandService.syncExecuteCommand(DeleteDocTableColumnCommand.id, {
|
|
898
|
+
unitId: this.getId(),
|
|
899
|
+
tableIndex,
|
|
900
|
+
colIndex
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
mergeTableCells(tableIndex, startRow, startCol, endRow, endCol) {
|
|
904
|
+
return this._commandService.syncExecuteCommand(MergeDocTableCellsCommand.id, {
|
|
905
|
+
unitId: this.getId(),
|
|
906
|
+
tableIndex,
|
|
907
|
+
startRow,
|
|
908
|
+
startCol,
|
|
909
|
+
endRow,
|
|
910
|
+
endCol
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
splitTableCell(tableIndex, row, col) {
|
|
914
|
+
return this._commandService.syncExecuteCommand(SplitDocTableCellCommand.id, {
|
|
915
|
+
unitId: this.getId(),
|
|
916
|
+
tableIndex,
|
|
917
|
+
row,
|
|
918
|
+
col
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
// ---- v1.6.204 Wave 2: Word Dynamic Fields, Captions, Cross-References, Citations, Building Blocks, Mail Merge & Legacy IO ----
|
|
922
|
+
insertDocField(fieldType, instructionArgs, offset, context) {
|
|
923
|
+
let fieldId = "";
|
|
924
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocFieldCommand.id, {
|
|
925
|
+
unitId: this.getId(),
|
|
926
|
+
fieldType,
|
|
927
|
+
instructionArgs,
|
|
928
|
+
offset,
|
|
929
|
+
context,
|
|
930
|
+
fieldIdOut: (id) => {
|
|
931
|
+
fieldId = id;
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
if (!ok) return null;
|
|
935
|
+
return this.getDocFields().find((f) => f.id === fieldId) ?? null;
|
|
936
|
+
}
|
|
937
|
+
updateAllDocFields(context) {
|
|
938
|
+
return this._commandService.syncExecuteCommand(UpdateAllDocFieldsCommand.id, {
|
|
939
|
+
unitId: this.getId(),
|
|
940
|
+
context
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
getDocFields() {
|
|
944
|
+
return listDocFields(this.save());
|
|
945
|
+
}
|
|
946
|
+
insertCaption(category, title, offset) {
|
|
947
|
+
let captionId = "";
|
|
948
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocCaptionCommand.id, {
|
|
949
|
+
unitId: this.getId(),
|
|
950
|
+
category,
|
|
951
|
+
title,
|
|
952
|
+
offset,
|
|
953
|
+
captionIdOut: (id) => {
|
|
954
|
+
captionId = id;
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
if (!ok) return null;
|
|
958
|
+
return this.getCaptions().find((c) => c.id === captionId) ?? null;
|
|
959
|
+
}
|
|
960
|
+
getCaptions() {
|
|
961
|
+
return listDocCaptions(this.save());
|
|
962
|
+
}
|
|
963
|
+
insertCrossReference(targetBookmarkOrCaptionId, offset) {
|
|
964
|
+
let fieldId = "";
|
|
965
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocCrossReferenceCommand.id, {
|
|
966
|
+
unitId: this.getId(),
|
|
967
|
+
targetBookmarkOrCaptionId,
|
|
968
|
+
offset,
|
|
969
|
+
fieldIdOut: (id) => {
|
|
970
|
+
fieldId = id;
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
if (!ok) return null;
|
|
974
|
+
return this.getDocFields().find((f) => f.id === fieldId) ?? null;
|
|
975
|
+
}
|
|
976
|
+
insertCitation(source, offset) {
|
|
977
|
+
return this._commandService.syncExecuteCommand(InsertDocCitationCommand.id, {
|
|
978
|
+
unitId: this.getId(),
|
|
979
|
+
source,
|
|
980
|
+
offset
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
getCitations() {
|
|
984
|
+
return listDocCitations(this.save());
|
|
985
|
+
}
|
|
986
|
+
insertBibliography(offset, title) {
|
|
987
|
+
return this._commandService.syncExecuteCommand(InsertDocBibliographyCommand.id, {
|
|
988
|
+
unitId: this.getId(),
|
|
989
|
+
offset,
|
|
990
|
+
title
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
saveBuildingBlock(spec) {
|
|
994
|
+
return this._injector.get(IDocSdtService).saveBuildingBlock(this.getId(), spec);
|
|
995
|
+
}
|
|
996
|
+
insertBuildingBlock(blockId, offset) {
|
|
997
|
+
return this._commandService.syncExecuteCommand(InsertDocBuildingBlockCommand.id, {
|
|
998
|
+
unitId: this.getId(),
|
|
999
|
+
blockId,
|
|
1000
|
+
offset
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
getBuildingBlocks() {
|
|
1004
|
+
return this._injector.get(IDocSdtService).getBuildingBlocks(this.getId());
|
|
1005
|
+
}
|
|
1006
|
+
removeBuildingBlock(blockId) {
|
|
1007
|
+
return this._injector.get(IDocSdtService).removeBuildingBlock(this.getId(), blockId);
|
|
1008
|
+
}
|
|
1009
|
+
async runMailMergeBatch(records, format) {
|
|
1010
|
+
const workingSnap = this.save();
|
|
1011
|
+
return runMailMergeBatchOnSnapshot(workingSnap, records, format);
|
|
1012
|
+
}
|
|
1013
|
+
importLegacyDocBytes(bytes, title) {
|
|
1014
|
+
const parsed = importLegacyDocBytes(bytes, title || this.getTitle() || "\u5BFC\u5165\u6587\u6863");
|
|
1015
|
+
if (parsed.body) {
|
|
1016
|
+
this._commandService.syncExecuteCommand(ReplaceDocUnitSnapshotCommand.id, {
|
|
1017
|
+
unitId: this.getId(),
|
|
1018
|
+
snapshot: parsed
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
return parsed;
|
|
1022
|
+
}
|
|
1023
|
+
async exportRtf(data, options) {
|
|
1024
|
+
const bytes = await this._injector.get(IDocIoService).exportDoc({
|
|
1025
|
+
unitId: this.getId(),
|
|
1026
|
+
snapshot: this.save(),
|
|
1027
|
+
format: "rtf",
|
|
1028
|
+
data,
|
|
1029
|
+
target: options?.target
|
|
1030
|
+
});
|
|
1031
|
+
return new TextDecoder().decode(bytes);
|
|
1032
|
+
}
|
|
1033
|
+
async exportOdt(data, options) {
|
|
1034
|
+
return this._injector.get(IDocIoService).exportDoc({
|
|
1035
|
+
unitId: this.getId(),
|
|
1036
|
+
snapshot: this.save(),
|
|
1037
|
+
format: "odt",
|
|
1038
|
+
data,
|
|
1039
|
+
target: options?.target
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
// ---- v1.6.204 Batch 3: Named Sub-Regions (`Area`/`Zone`) + Corner & Label Badges ----
|
|
1043
|
+
insertDocArea(spec, offset) {
|
|
1044
|
+
let created = null;
|
|
1045
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocAreaCommand.id, {
|
|
1046
|
+
unitId: this.getId(),
|
|
1047
|
+
offset,
|
|
1048
|
+
spec,
|
|
1049
|
+
onResult: (area) => {
|
|
1050
|
+
created = area;
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
if (!ok) return null;
|
|
1054
|
+
return created ?? this.getDocAreas().find((a) => a.id === spec.id || a.name === spec.name) ?? null;
|
|
1055
|
+
}
|
|
1056
|
+
getDocAreas() {
|
|
1057
|
+
return getDocAreasFromSnapshot(this.save());
|
|
1058
|
+
}
|
|
1059
|
+
getDocAreaValue(areaId) {
|
|
1060
|
+
return getDocAreaValueFromSnapshot(this.save(), areaId);
|
|
1061
|
+
}
|
|
1062
|
+
setDocAreaValue(areaId, newText) {
|
|
1063
|
+
return this._commandService.syncExecuteCommand(SetDocAreaValueCommand.id, {
|
|
1064
|
+
unitId: this.getId(),
|
|
1065
|
+
areaId,
|
|
1066
|
+
newText
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
setDocAreaProperties(areaId, patch) {
|
|
1070
|
+
return this._commandService.syncExecuteCommand(SetDocAreaPropertiesCommand.id, {
|
|
1071
|
+
unitId: this.getId(),
|
|
1072
|
+
areaId,
|
|
1073
|
+
patch
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
deleteDocArea(areaId, options) {
|
|
1077
|
+
return this._commandService.syncExecuteCommand(DeleteDocAreaCommand.id, {
|
|
1078
|
+
unitId: this.getId(),
|
|
1079
|
+
areaId,
|
|
1080
|
+
force: options?.force,
|
|
1081
|
+
keepContent: options?.keepContent
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
isOffsetReadonlyByArea(offset, globalMode) {
|
|
1085
|
+
return isOffsetReadonlyByArea(this.save(), offset, globalMode ?? this.getMode());
|
|
1086
|
+
}
|
|
1087
|
+
setDocMainBadge(badge) {
|
|
1088
|
+
return this._commandService.syncExecuteCommand(SetDocMainBadgeCommand.id, {
|
|
1089
|
+
unitId: this.getId(),
|
|
1090
|
+
badge
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
getDocMainBadge() {
|
|
1094
|
+
return getDocMainBadgeFromSnapshot(this.save());
|
|
1095
|
+
}
|
|
1096
|
+
setDocAreaBadge(areaId, badge) {
|
|
1097
|
+
return this._commandService.syncExecuteCommand(SetDocAreaBadgeCommand.id, {
|
|
1098
|
+
unitId: this.getId(),
|
|
1099
|
+
areaId,
|
|
1100
|
+
badge
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
getDocAreaBadge(areaId) {
|
|
1104
|
+
return getDocAreaBadgeFromSnapshot(this.save(), areaId);
|
|
1105
|
+
}
|
|
1106
|
+
insertDocLabelBadge(spec, offset) {
|
|
1107
|
+
let created = null;
|
|
1108
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocLabelBadgeCommand.id, {
|
|
1109
|
+
unitId: this.getId(),
|
|
1110
|
+
offset,
|
|
1111
|
+
spec,
|
|
1112
|
+
onResult: (b) => {
|
|
1113
|
+
created = b;
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
if (!ok) return null;
|
|
1117
|
+
return created;
|
|
1118
|
+
}
|
|
1119
|
+
getDocLabelBadges() {
|
|
1120
|
+
return getDocLabelBadgesFromSnapshot(this.save());
|
|
1121
|
+
}
|
|
1122
|
+
removeDocLabelBadge(id) {
|
|
1123
|
+
return this._commandService.syncExecuteCommand(RemoveDocLabelBadgeCommand.id, {
|
|
1124
|
+
unitId: this.getId(),
|
|
1125
|
+
id
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
// ---- v1.6.204 Batch 3: Declarative Control Cascade Engine ----
|
|
1129
|
+
setDocCascadeRules(rules) {
|
|
1130
|
+
return this._commandService.syncExecuteCommand(SetDocCascadeRulesCommand.id, {
|
|
1131
|
+
unitId: this.getId(),
|
|
1132
|
+
rules
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
addDocCascadeRule(rule) {
|
|
1136
|
+
return this._commandService.syncExecuteCommand(AddDocCascadeRuleCommand.id, {
|
|
1137
|
+
unitId: this.getId(),
|
|
1138
|
+
rule
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
removeDocCascadeRule(ruleId) {
|
|
1142
|
+
return this._commandService.syncExecuteCommand(RemoveDocCascadeRuleCommand.id, {
|
|
1143
|
+
unitId: this.getId(),
|
|
1144
|
+
ruleId
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
getDocCascadeRules() {
|
|
1148
|
+
return getDocCascadeRulesFromSnapshot(this.save());
|
|
1149
|
+
}
|
|
1150
|
+
evaluateDocCascadeRules(extraData) {
|
|
1151
|
+
let out = null;
|
|
1152
|
+
this._commandService.syncExecuteCommand(EvaluateDocCascadeRulesCommand.id, {
|
|
1153
|
+
unitId: this.getId(),
|
|
1154
|
+
extraData,
|
|
1155
|
+
onResult: (res) => {
|
|
1156
|
+
out = res;
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
return out ?? evaluateDocCascadeRules(this.save(), extraData);
|
|
1160
|
+
}
|
|
1161
|
+
// ---- v1.6.204 Batch 3: Styled Separators, Embed Blocks, Macros & Freehand Graffiti ----
|
|
1162
|
+
insertStyledSeparator(dashStyle = "single", color, widthPt, offset) {
|
|
1163
|
+
let created = null;
|
|
1164
|
+
const ok = this._commandService.syncExecuteCommand(InsertStyledSeparatorCommand.id, {
|
|
1165
|
+
unitId: this.getId(),
|
|
1166
|
+
dashStyle,
|
|
1167
|
+
color,
|
|
1168
|
+
widthPt,
|
|
1169
|
+
offset,
|
|
1170
|
+
onResult: (sep) => {
|
|
1171
|
+
created = sep;
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
if (!ok) return null;
|
|
1175
|
+
return created;
|
|
1176
|
+
}
|
|
1177
|
+
getStyledSeparators() {
|
|
1178
|
+
return getStyledSeparatorsFromSnapshot(this.save());
|
|
1179
|
+
}
|
|
1180
|
+
insertDocEmbedBlock(spec, offset) {
|
|
1181
|
+
let created = null;
|
|
1182
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocEmbedBlockCommand.id, {
|
|
1183
|
+
unitId: this.getId(),
|
|
1184
|
+
offset,
|
|
1185
|
+
spec,
|
|
1186
|
+
onResult: (eb) => {
|
|
1187
|
+
created = eb;
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
if (!ok) return null;
|
|
1191
|
+
return created;
|
|
1192
|
+
}
|
|
1193
|
+
getDocEmbedBlocks() {
|
|
1194
|
+
return getDocEmbedBlocksFromSnapshot(this.save());
|
|
1195
|
+
}
|
|
1196
|
+
removeDocEmbedBlock(id) {
|
|
1197
|
+
return this._commandService.syncExecuteCommand(RemoveDocEmbedBlockCommand.id, {
|
|
1198
|
+
unitId: this.getId(),
|
|
1199
|
+
id
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
registerDocMacro(name, resolverOrValue) {
|
|
1203
|
+
const key = normalizeMacroName(name);
|
|
1204
|
+
if (!key) return;
|
|
1205
|
+
registerDocMacro(key, resolverOrValue, this.getId());
|
|
1206
|
+
if (typeof resolverOrValue !== "function") {
|
|
1207
|
+
const prev = this.getTemplateMetadata();
|
|
1208
|
+
this.setTemplateMetadata({
|
|
1209
|
+
...prev,
|
|
1210
|
+
macros: {
|
|
1211
|
+
...prev.macros ?? {},
|
|
1212
|
+
[key]: String(resolverOrValue)
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
unregisterDocMacro(name) {
|
|
1218
|
+
const key = normalizeMacroName(name);
|
|
1219
|
+
const removedRuntime = unregisterDocMacro(key, this.getId());
|
|
1220
|
+
const prev = this.getTemplateMetadata();
|
|
1221
|
+
if (prev.macros && Object.prototype.hasOwnProperty.call(prev.macros, key)) {
|
|
1222
|
+
const nextMacros = { ...prev.macros };
|
|
1223
|
+
delete nextMacros[key];
|
|
1224
|
+
this.setTemplateMetadata({
|
|
1225
|
+
...prev,
|
|
1226
|
+
macros: nextMacros
|
|
1227
|
+
});
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
return removedRuntime;
|
|
1231
|
+
}
|
|
1232
|
+
applyDocMacros(extraMacros) {
|
|
1233
|
+
let count = 0;
|
|
1234
|
+
this._commandService.syncExecuteCommand(ApplyDocMacrosCommand.id, {
|
|
1235
|
+
unitId: this.getId(),
|
|
1236
|
+
extraMacros,
|
|
1237
|
+
onResult: (n) => {
|
|
1238
|
+
count = n;
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
return count;
|
|
1242
|
+
}
|
|
1243
|
+
addDocGraffitiStroke(spec) {
|
|
1244
|
+
let created = null;
|
|
1245
|
+
const ok = this._commandService.syncExecuteCommand(AddDocGraffitiStrokeCommand.id, {
|
|
1246
|
+
unitId: this.getId(),
|
|
1247
|
+
spec,
|
|
1248
|
+
onResult: (stroke) => {
|
|
1249
|
+
created = stroke;
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
if (!ok) return null;
|
|
1253
|
+
return created;
|
|
1254
|
+
}
|
|
1255
|
+
getDocGraffitiStrokes(pageIndex) {
|
|
1256
|
+
return getDocGraffitiStrokesFromSnapshot(this.save(), pageIndex);
|
|
1257
|
+
}
|
|
1258
|
+
clearDocGraffitiStrokes(pageIndex) {
|
|
1259
|
+
return this._commandService.syncExecuteCommand(ClearDocGraffitiStrokesCommand.id, {
|
|
1260
|
+
unitId: this.getId(),
|
|
1261
|
+
pageIndex
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
// ---- Round 1: Footnotes & Endnotes ----
|
|
1265
|
+
insertFootnote(text, offset, id) {
|
|
1266
|
+
let created = null;
|
|
1267
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocFootnoteCommand.id, {
|
|
1268
|
+
unitId: this.getId(),
|
|
1269
|
+
text,
|
|
1270
|
+
offset,
|
|
1271
|
+
id,
|
|
1272
|
+
onResult: (note) => {
|
|
1273
|
+
created = note;
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
if (!ok) return null;
|
|
1277
|
+
return created ?? this.getNotes("footnote").slice(-1)[0] ?? null;
|
|
1278
|
+
}
|
|
1279
|
+
insertEndnote(text, offset, id) {
|
|
1280
|
+
let created = null;
|
|
1281
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocEndnoteCommand.id, {
|
|
1282
|
+
unitId: this.getId(),
|
|
1283
|
+
text,
|
|
1284
|
+
offset,
|
|
1285
|
+
id,
|
|
1286
|
+
onResult: (note) => {
|
|
1287
|
+
created = note;
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
if (!ok) return null;
|
|
1291
|
+
return created ?? this.getNotes("endnote").slice(-1)[0] ?? null;
|
|
1292
|
+
}
|
|
1293
|
+
updateNote(noteId, text) {
|
|
1294
|
+
return this._commandService.syncExecuteCommand(UpdateDocNoteCommand.id, {
|
|
1295
|
+
unitId: this.getId(),
|
|
1296
|
+
noteId,
|
|
1297
|
+
text
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
deleteNote(noteId) {
|
|
1301
|
+
return this._commandService.syncExecuteCommand(DeleteDocNoteCommand.id, {
|
|
1302
|
+
unitId: this.getId(),
|
|
1303
|
+
noteId
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
getNotes(noteType) {
|
|
1307
|
+
return listDocNotesFromSnapshot(this.save(), noteType);
|
|
1308
|
+
}
|
|
1309
|
+
setNoteSettings(noteType, settings) {
|
|
1310
|
+
return this._commandService.syncExecuteCommand(SetDocNoteSettingsCommand.id, {
|
|
1311
|
+
unitId: this.getId(),
|
|
1312
|
+
noteType,
|
|
1313
|
+
settings
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
getNoteSettings(noteType) {
|
|
1317
|
+
return getDocNoteSettingsFromSnapshot(this.save(), noteType);
|
|
1318
|
+
}
|
|
1319
|
+
// ---- Round 1: Multi-Level Lists, TOC Remove, Column Update/Delete & Custom Properties ----
|
|
1320
|
+
insertDocList(spec) {
|
|
1321
|
+
let created = null;
|
|
1322
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocListCommand.id, {
|
|
1323
|
+
unitId: this.getId(),
|
|
1324
|
+
...spec ?? {},
|
|
1325
|
+
onResult: (res) => {
|
|
1326
|
+
created = res;
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
if (!ok) return null;
|
|
1330
|
+
return created;
|
|
1331
|
+
}
|
|
1332
|
+
setDocListGlyphType(listIdOrParagraphId, glyphType, level) {
|
|
1333
|
+
return this._commandService.syncExecuteCommand(SetDocListGlyphTypeCommand.id, {
|
|
1334
|
+
unitId: this.getId(),
|
|
1335
|
+
listIdOrParagraphId,
|
|
1336
|
+
glyphType,
|
|
1337
|
+
level
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
setDocListLevel(paragraphIdOrOffset, nestingLevel) {
|
|
1341
|
+
return this._commandService.syncExecuteCommand(SetDocListLevelCommand.id, {
|
|
1342
|
+
unitId: this.getId(),
|
|
1343
|
+
paragraphIdOrOffset,
|
|
1344
|
+
nestingLevel
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
toggleDocListCheckbox(paragraphId, checked) {
|
|
1348
|
+
return this._commandService.syncExecuteCommand(ToggleDocListCheckboxCommand.id, {
|
|
1349
|
+
unitId: this.getId(),
|
|
1350
|
+
paragraphId,
|
|
1351
|
+
checked
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
getDocLists() {
|
|
1355
|
+
return getDocListsFromSnapshot(this.save());
|
|
1356
|
+
}
|
|
1357
|
+
removeTableOfContents() {
|
|
1358
|
+
return this._commandService.syncExecuteCommand(RemoveDocTableOfContentsCommand.id, {
|
|
1359
|
+
unitId: this.getId()
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
updateColumnGroup(patch) {
|
|
1363
|
+
return this._commandService.syncExecuteCommand(UpdateDocColumnGroupCommand.id, {
|
|
1364
|
+
unitId: this.getId(),
|
|
1365
|
+
patch
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
deleteColumnGroup() {
|
|
1369
|
+
return this._commandService.syncExecuteCommand(DeleteDocColumnGroupCommand.id, {
|
|
1370
|
+
unitId: this.getId()
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
setCustomProperties(customProperties, company, title) {
|
|
1374
|
+
return this._commandService.syncExecuteCommand(SetDocCustomPropertiesCommand.id, {
|
|
1375
|
+
unitId: this.getId(),
|
|
1376
|
+
customProperties,
|
|
1377
|
+
company,
|
|
1378
|
+
title
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
getCustomProperties() {
|
|
1382
|
+
return getDocCustomPropertiesFromSnapshot(this.save());
|
|
1383
|
+
}
|
|
1384
|
+
// ---- Round 1: Bidirectional Markdown (`.md`) ----
|
|
1385
|
+
importMarkdown(markdown, title) {
|
|
1386
|
+
const parsed = importMarkdownToDocData(markdown, title || this.getTitle() || "\u672A\u547D\u540D\u6587\u6863");
|
|
1387
|
+
if (parsed.body) {
|
|
1388
|
+
this._commandService.syncExecuteCommand(ReplaceDocUnitSnapshotCommand.id, {
|
|
1389
|
+
unitId: this.getId(),
|
|
1390
|
+
snapshot: parsed
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
return parsed;
|
|
1394
|
+
}
|
|
1395
|
+
async exportMarkdown(data, options) {
|
|
1396
|
+
if (options?.target !== "server") {
|
|
1397
|
+
return exportDocToMarkdown(this.save(), data);
|
|
1398
|
+
}
|
|
1399
|
+
const bytes = await this._injector.get(IDocIoService).exportDoc({
|
|
1400
|
+
unitId: this.getId(),
|
|
1401
|
+
snapshot: this.save(),
|
|
1402
|
+
format: "md",
|
|
1403
|
+
data,
|
|
1404
|
+
target: options?.target
|
|
1405
|
+
});
|
|
1406
|
+
return new TextDecoder().decode(bytes);
|
|
1407
|
+
}
|
|
1408
|
+
// ---- Round 1: Advanced SDT Validation Highlight & Tab Jump ----
|
|
1409
|
+
highlightInvalidControls(clear = false) {
|
|
1410
|
+
return this._commandService.syncExecuteCommand(HighlightInvalidDocSdtCommand.id, {
|
|
1411
|
+
unitId: this.getId(),
|
|
1412
|
+
clear
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
jumpToControl(directionOrOptions) {
|
|
1416
|
+
const opts = typeof directionOrOptions === "string" ? { direction: directionOrOptions } : directionOrOptions ?? {};
|
|
1417
|
+
return this._commandService.syncExecuteCommand(JumpDocSdtControlCommand.id, {
|
|
1418
|
+
unitId: this.getId(),
|
|
1419
|
+
...opts
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
// ---- Round 1: Bidi/RTL, Copy/Paste Policy, Table Presets/Slash/AutoFit, Orientation, WordTool, Macros & Visual Diff ----
|
|
1423
|
+
setTextDirection(direction, target) {
|
|
1424
|
+
return this._commandService.syncExecuteCommand(SetDocTextDirectionCommand.id, {
|
|
1425
|
+
unitId: this.getId(),
|
|
1426
|
+
direction,
|
|
1427
|
+
...target ?? {}
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
setCopyPastePolicy(policy) {
|
|
1431
|
+
return this._commandService.syncExecuteCommand(SetDocCopyPastePolicyCommand.id, {
|
|
1432
|
+
unitId: this.getId(),
|
|
1433
|
+
policy
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
getCopyPastePolicy() {
|
|
1437
|
+
return getDocCopyPastePolicyFromSnapshot(this.save());
|
|
1438
|
+
}
|
|
1439
|
+
setTableBorderPreset(tableIndexOrId, preset, color, widthPt) {
|
|
1440
|
+
return this._commandService.syncExecuteCommand(SetDocTableBorderPresetCommand.id, {
|
|
1441
|
+
unitId: this.getId(),
|
|
1442
|
+
tableIndexOrId,
|
|
1443
|
+
preset,
|
|
1444
|
+
color,
|
|
1445
|
+
widthPt
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
setTableCellProperties(tableIndexOrId, rowIndex, colIndex, properties) {
|
|
1449
|
+
return this._commandService.syncExecuteCommand(SetDocTableCellPropertiesCommand.id, {
|
|
1450
|
+
unitId: this.getId(),
|
|
1451
|
+
tableIndexOrId,
|
|
1452
|
+
rowIndex,
|
|
1453
|
+
colIndex,
|
|
1454
|
+
properties
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
getTableCellProperties(tableId, rowIndex, colIndex) {
|
|
1458
|
+
return getDocTableCellProperties(this.save(), tableId, rowIndex, colIndex);
|
|
1459
|
+
}
|
|
1460
|
+
autoFitTable(tableIndexOrId, mode = "window") {
|
|
1461
|
+
return this._commandService.syncExecuteCommand(AutoFitDocTableCommand.id, {
|
|
1462
|
+
unitId: this.getId(),
|
|
1463
|
+
tableIndexOrId,
|
|
1464
|
+
mode
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
setSectionOrientation(orientation, sectionKeyOrOffset) {
|
|
1468
|
+
return this._commandService.syncExecuteCommand(SetDocSectionOrientationCommand.id, {
|
|
1469
|
+
unitId: this.getId(),
|
|
1470
|
+
orientation,
|
|
1471
|
+
sectionKeyOrOffset
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
cleanUpFormatting(options) {
|
|
1475
|
+
let result = {
|
|
1476
|
+
removedBlankParagraphs: 0,
|
|
1477
|
+
trimmedParagraphs: 0,
|
|
1478
|
+
indentedParagraphs: 0,
|
|
1479
|
+
normalizedPunctuationCount: 0
|
|
1480
|
+
};
|
|
1481
|
+
this._commandService.syncExecuteCommand(CleanUpDocFormattingCommand.id, {
|
|
1482
|
+
unitId: this.getId(),
|
|
1483
|
+
options,
|
|
1484
|
+
onResult: (res) => {
|
|
1485
|
+
result = res;
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
return result;
|
|
1489
|
+
}
|
|
1490
|
+
startMacroRecording(name) {
|
|
1491
|
+
this._injector.get(IDocActionMacroService).startRecording(name);
|
|
1492
|
+
}
|
|
1493
|
+
stopMacroRecording(name) {
|
|
1494
|
+
return this._injector.get(IDocActionMacroService).stopRecording(name);
|
|
1495
|
+
}
|
|
1496
|
+
async playActionMacro(macroIdOrName) {
|
|
1497
|
+
return this._injector.get(IDocActionMacroService).playMacro(macroIdOrName);
|
|
1498
|
+
}
|
|
1499
|
+
getActionMacros() {
|
|
1500
|
+
return this._injector.get(IDocActionMacroService).getMacros();
|
|
1501
|
+
}
|
|
1502
|
+
exportActionMacros() {
|
|
1503
|
+
return this._injector.get(IDocActionMacroService).exportMacros();
|
|
1504
|
+
}
|
|
1505
|
+
importActionMacros(jsonOrList) {
|
|
1506
|
+
return this._injector.get(IDocActionMacroService).importMacros(jsonOrList);
|
|
1507
|
+
}
|
|
1508
|
+
compareWithSnapshot(baseSnapshot, options) {
|
|
1509
|
+
const base = baseSnapshot instanceof FEnterpriseDoc ? baseSnapshot.save() : baseSnapshot;
|
|
1510
|
+
let out = null;
|
|
1511
|
+
const ok = this._commandService.syncExecuteCommand(CompareDocSnapshotsToTrackCommand.id, {
|
|
1512
|
+
unitId: this.getId(),
|
|
1513
|
+
baseSnapshot: base,
|
|
1514
|
+
options,
|
|
1515
|
+
onResult: (res) => {
|
|
1516
|
+
out = res;
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
if (!ok) return null;
|
|
1520
|
+
return out;
|
|
1521
|
+
}
|
|
1522
|
+
// ---- Round 3: Hyperlinks, Comments, Sub/Superscript, Extensibility, Print, Catalog Tree, Title & Events ----
|
|
1523
|
+
insertHyperlink(spec) {
|
|
1524
|
+
let insertedId = null;
|
|
1525
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocHyperlinkCommand.id, {
|
|
1526
|
+
unitId: this.getId(),
|
|
1527
|
+
spec,
|
|
1528
|
+
onInserted: (entry) => {
|
|
1529
|
+
insertedId = entry.id;
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
return ok ? insertedId : null;
|
|
1533
|
+
}
|
|
1534
|
+
updateHyperlink(idOrOffset, patch) {
|
|
1535
|
+
return this._commandService.syncExecuteCommand(UpdateDocHyperlinkCommand.id, {
|
|
1536
|
+
unitId: this.getId(),
|
|
1537
|
+
idOrOffset,
|
|
1538
|
+
patch
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
cancelHyperlink(idOrOffset) {
|
|
1542
|
+
return this._commandService.syncExecuteCommand(CancelDocHyperlinkCommand.id, {
|
|
1543
|
+
unitId: this.getId(),
|
|
1544
|
+
idOrOffset
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
deleteHyperlink(idOrOffset) {
|
|
1548
|
+
return this._commandService.syncExecuteCommand(DeleteDocHyperlinkCommand.id, {
|
|
1549
|
+
unitId: this.getId(),
|
|
1550
|
+
idOrOffset
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
getHyperlinks() {
|
|
1554
|
+
return listDocHyperlinks(this.save());
|
|
1555
|
+
}
|
|
1556
|
+
addComment(specOrContent, author, startOffset, endOffset) {
|
|
1557
|
+
const spec = typeof specOrContent === "string" ? { content: specOrContent, author, startOffset, endOffset } : specOrContent;
|
|
1558
|
+
let addedId = null;
|
|
1559
|
+
const ok = this._commandService.syncExecuteCommand(AddDocCommentCommand.id, {
|
|
1560
|
+
unitId: this.getId(),
|
|
1561
|
+
spec,
|
|
1562
|
+
onAdded: (cmt) => {
|
|
1563
|
+
addedId = cmt.id;
|
|
1564
|
+
}
|
|
1565
|
+
});
|
|
1566
|
+
return ok ? addedId : null;
|
|
1567
|
+
}
|
|
1568
|
+
replyComment(commentId, specOrContent, author) {
|
|
1569
|
+
const spec = typeof specOrContent === "string" ? { content: specOrContent, author } : specOrContent;
|
|
1570
|
+
let replyId = null;
|
|
1571
|
+
const ok = this._commandService.syncExecuteCommand(ReplyDocCommentCommand.id, {
|
|
1572
|
+
unitId: this.getId(),
|
|
1573
|
+
commentId,
|
|
1574
|
+
spec,
|
|
1575
|
+
onReplied: (rep) => {
|
|
1576
|
+
replyId = rep.id;
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
return ok ? replyId : null;
|
|
1580
|
+
}
|
|
1581
|
+
resolveComment(commentId, resolved = true) {
|
|
1582
|
+
return this._commandService.syncExecuteCommand(ResolveDocCommentCommand.id, {
|
|
1583
|
+
unitId: this.getId(),
|
|
1584
|
+
commentId,
|
|
1585
|
+
resolved
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
deleteComment(commentId) {
|
|
1589
|
+
return this._commandService.syncExecuteCommand(DeleteDocCommentCommand.id, {
|
|
1590
|
+
unitId: this.getId(),
|
|
1591
|
+
commentId
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
getComments() {
|
|
1595
|
+
return listDocCommentsFromSnapshot(this.save());
|
|
1596
|
+
}
|
|
1597
|
+
locateComment(commentId) {
|
|
1598
|
+
const target = this.getComments().find((c) => c.id === commentId);
|
|
1599
|
+
if (!target) return false;
|
|
1600
|
+
try {
|
|
1601
|
+
const selService = this._injector.get(DocSelectionManagerService);
|
|
1602
|
+
const selParam = { unitId: this.getId(), subUnitId: this.getId() };
|
|
1603
|
+
const startOffset = target.startIndex;
|
|
1604
|
+
const endOffset = target.endIndex + 1;
|
|
1605
|
+
selService.replaceDocRanges([{ startOffset, endOffset }], selParam);
|
|
1606
|
+
if (selService.getActiveTextRange()?.startOffset !== startOffset) {
|
|
1607
|
+
selService.__TEST_ONLY_setCurrentSelection(selParam);
|
|
1608
|
+
selService.__TEST_ONLY_add([
|
|
1609
|
+
{ startOffset, endOffset, collapsed: startOffset === endOffset, isActive: true }
|
|
1610
|
+
]);
|
|
1611
|
+
}
|
|
1612
|
+
} catch {
|
|
1613
|
+
}
|
|
1614
|
+
return true;
|
|
1615
|
+
}
|
|
1616
|
+
toggleSuperscript(startOffset, endOffset) {
|
|
1617
|
+
return this._commandService.syncExecuteCommand(ToggleDocSuperscriptCommand.id, {
|
|
1618
|
+
unitId: this.getId(),
|
|
1619
|
+
startOffset,
|
|
1620
|
+
endOffset
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
toggleSubscript(startOffset, endOffset) {
|
|
1624
|
+
return this._commandService.syncExecuteCommand(ToggleDocSubscriptCommand.id, {
|
|
1625
|
+
unitId: this.getId(),
|
|
1626
|
+
startOffset,
|
|
1627
|
+
endOffset
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
importHtml(html, title) {
|
|
1631
|
+
const parsed = importHtmlToDocData(html, title || this.getTitle() || "\u672A\u547D\u540D\u6587\u6863");
|
|
1632
|
+
return this._commandService.syncExecuteCommand(ReplaceDocUnitSnapshotCommand.id, {
|
|
1633
|
+
unitId: this.getId(),
|
|
1634
|
+
snapshot: parsed
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
registerContextMenuList(items) {
|
|
1638
|
+
const reg = this._injector.get(IDocExtensionRegistryService);
|
|
1639
|
+
reg.setDocApiResolver((uid) => uid === this.getId() ? this : null);
|
|
1640
|
+
return reg.registerContextMenuList(items);
|
|
1641
|
+
}
|
|
1642
|
+
registerShortcutList(shortcuts) {
|
|
1643
|
+
const reg = this._injector.get(IDocExtensionRegistryService);
|
|
1644
|
+
reg.setDocApiResolver((uid) => uid === this.getId() ? this : null);
|
|
1645
|
+
return reg.registerShortcutList(shortcuts);
|
|
1646
|
+
}
|
|
1647
|
+
getContextMenuList(ctx) {
|
|
1648
|
+
return this._injector.get(IDocExtensionRegistryService).getContextMenuList(ctx);
|
|
1649
|
+
}
|
|
1650
|
+
async print(options) {
|
|
1651
|
+
const pdfBytes = await this.exportPdf(options);
|
|
1652
|
+
if (!pdfBytes || pdfBytes.byteLength < 10) return false;
|
|
1653
|
+
if (typeof document !== "undefined" && typeof URL !== "undefined" && typeof URL.createObjectURL === "function") {
|
|
1654
|
+
try {
|
|
1655
|
+
const ab = pdfBytes.buffer.slice(
|
|
1656
|
+
pdfBytes.byteOffset,
|
|
1657
|
+
pdfBytes.byteOffset + pdfBytes.byteLength
|
|
1658
|
+
);
|
|
1659
|
+
const blob = new Blob([ab], { type: "application/pdf" });
|
|
1660
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
1661
|
+
const iframe = document.createElement("iframe");
|
|
1662
|
+
iframe.style.position = "fixed";
|
|
1663
|
+
iframe.style.right = "0";
|
|
1664
|
+
iframe.style.bottom = "0";
|
|
1665
|
+
iframe.style.width = "0";
|
|
1666
|
+
iframe.style.height = "0";
|
|
1667
|
+
iframe.style.border = "0";
|
|
1668
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
1669
|
+
let printed = false;
|
|
1670
|
+
const cleanup = () => {
|
|
1671
|
+
setTimeout(() => {
|
|
1672
|
+
try {
|
|
1673
|
+
iframe.remove();
|
|
1674
|
+
} catch {
|
|
1675
|
+
}
|
|
1676
|
+
try {
|
|
1677
|
+
URL.revokeObjectURL(blobUrl);
|
|
1678
|
+
} catch {
|
|
1679
|
+
}
|
|
1680
|
+
}, 1500);
|
|
1681
|
+
};
|
|
1682
|
+
iframe.onload = () => {
|
|
1683
|
+
if (printed) return;
|
|
1684
|
+
printed = true;
|
|
1685
|
+
try {
|
|
1686
|
+
iframe.contentWindow?.focus?.();
|
|
1687
|
+
iframe.contentWindow?.print?.();
|
|
1688
|
+
} catch {
|
|
1689
|
+
}
|
|
1690
|
+
cleanup();
|
|
1691
|
+
};
|
|
1692
|
+
document.body.appendChild(iframe);
|
|
1693
|
+
iframe.src = blobUrl;
|
|
1694
|
+
setTimeout(() => {
|
|
1695
|
+
if (!printed) {
|
|
1696
|
+
printed = true;
|
|
1697
|
+
try {
|
|
1698
|
+
iframe.contentWindow?.print?.();
|
|
1699
|
+
} catch {
|
|
1700
|
+
}
|
|
1701
|
+
cleanup();
|
|
1702
|
+
}
|
|
1703
|
+
}, 300);
|
|
1704
|
+
} catch {
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
getCatalogTree() {
|
|
1710
|
+
return extractDocCatalogTree(this.save());
|
|
1711
|
+
}
|
|
1712
|
+
locateCatalog(idOrParagraphId) {
|
|
1713
|
+
const target = this.getCatalog().find(
|
|
1714
|
+
(c) => c.id === idOrParagraphId || c.paragraphId === idOrParagraphId || c.title === idOrParagraphId
|
|
1715
|
+
);
|
|
1716
|
+
if (!target) return false;
|
|
1717
|
+
try {
|
|
1718
|
+
const selService = this._injector.get(DocSelectionManagerService);
|
|
1719
|
+
const selParam = { unitId: this.getId(), subUnitId: this.getId() };
|
|
1720
|
+
const startOffset = target.startIndex;
|
|
1721
|
+
selService.replaceDocRanges([{ startOffset, endOffset: startOffset }], selParam);
|
|
1722
|
+
if (selService.getActiveTextRange()?.startOffset !== startOffset) {
|
|
1723
|
+
selService.__TEST_ONLY_setCurrentSelection(selParam);
|
|
1724
|
+
selService.__TEST_ONLY_add([
|
|
1725
|
+
{ startOffset, endOffset: startOffset, collapsed: true, isActive: true }
|
|
1726
|
+
]);
|
|
1727
|
+
}
|
|
1728
|
+
} catch {
|
|
1729
|
+
}
|
|
1730
|
+
return true;
|
|
1731
|
+
}
|
|
1732
|
+
getReadabilityStatistics() {
|
|
1733
|
+
return getReadabilityStatistics(this.save());
|
|
1734
|
+
}
|
|
1735
|
+
insertTitle(spec) {
|
|
1736
|
+
let insertedId = null;
|
|
1737
|
+
const ok = this._commandService.syncExecuteCommand(InsertDocTitleCommand.id, {
|
|
1738
|
+
unitId: this.getId(),
|
|
1739
|
+
spec,
|
|
1740
|
+
onInserted: (entry) => {
|
|
1741
|
+
insertedId = entry.id;
|
|
1742
|
+
}
|
|
1743
|
+
});
|
|
1744
|
+
return ok ? insertedId : null;
|
|
1745
|
+
}
|
|
1746
|
+
setTitleProperties(idOrConceptId, patch) {
|
|
1747
|
+
return this._commandService.syncExecuteCommand(SetDocTitlePropertiesCommand.id, {
|
|
1748
|
+
unitId: this.getId(),
|
|
1749
|
+
idOrConceptId,
|
|
1750
|
+
patch
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
getTitleValue(conceptId) {
|
|
1754
|
+
return getDocTitleValueFromSnapshot(this.save(), conceptId);
|
|
1755
|
+
}
|
|
1756
|
+
getTitles() {
|
|
1757
|
+
return getDocTitleEntriesFromSnapshot(this.save());
|
|
1758
|
+
}
|
|
1759
|
+
onBeforeSave(cb) {
|
|
1760
|
+
return this._injector.get(IDocIoService).onBeforeSave(cb, this.getId());
|
|
1761
|
+
}
|
|
1762
|
+
onSaved(cb) {
|
|
1763
|
+
return this._injector.get(IDocIoService).onSaved(cb, this.getId());
|
|
1764
|
+
}
|
|
1765
|
+
onControlChange(cb) {
|
|
1766
|
+
const unitId = this.getId();
|
|
1767
|
+
const sub = this._injector.get(IDocSdtService).controlChange$.subscribe((ev) => {
|
|
1768
|
+
if (!ev.unitId || ev.unitId === unitId) {
|
|
1769
|
+
cb(ev);
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1772
|
+
return { dispose: () => sub.unsubscribe() };
|
|
1773
|
+
}
|
|
1774
|
+
onControlValueChange(cb) {
|
|
1775
|
+
const unitId = this.getId();
|
|
1776
|
+
const sub = this._injector.get(IDocSdtService).controlValueChange$.subscribe((ev) => {
|
|
1777
|
+
if (ev.unitId === unitId) {
|
|
1778
|
+
cb(ev);
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
return { dispose: () => sub.unsubscribe() };
|
|
1782
|
+
}
|
|
1783
|
+
onModeChange(cb) {
|
|
1784
|
+
const unitId = this.getId();
|
|
1785
|
+
const sub = this._injector.get(IDocSdtService).modeChange$.subscribe((ev) => {
|
|
1786
|
+
if (ev.unitId === unitId) {
|
|
1787
|
+
cb(ev);
|
|
1788
|
+
}
|
|
1789
|
+
});
|
|
1790
|
+
return { dispose: () => sub.unsubscribe() };
|
|
1791
|
+
}
|
|
1792
|
+
onContentChange(cb) {
|
|
1793
|
+
const unitId = this.getId();
|
|
1794
|
+
const sub = this._injector.get(IDocSdtService).contentChange$.subscribe((ev) => {
|
|
1795
|
+
if (ev.unitId === unitId) {
|
|
1796
|
+
cb(ev);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
return { dispose: () => sub.unsubscribe() };
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
FEnterpriseDoc = __decorateClass([
|
|
1803
|
+
__decorateParam(1, Inject(Injector)),
|
|
1804
|
+
__decorateParam(2, ICommandService)
|
|
1805
|
+
], FEnterpriseDoc);
|
|
1806
|
+
|
|
1807
|
+
// src/facade/f-univer.ts
|
|
1808
|
+
import {
|
|
1809
|
+
ICommandService as ICommandService2,
|
|
1810
|
+
UniverInstanceType
|
|
1811
|
+
} from "@univerjs/core";
|
|
1812
|
+
import { FUniver } from "@univerjs/core/facade";
|
|
1813
|
+
import {
|
|
1814
|
+
buildStructuredDocData,
|
|
1815
|
+
IDocAiCopilotService as IDocAiCopilotService2,
|
|
1816
|
+
IDocIoService as IDocIoService2,
|
|
1817
|
+
IDocSdtService as IDocSdtService2,
|
|
1818
|
+
ReplaceDocUnitSnapshotCommand as ReplaceDocUnitSnapshotCommand2
|
|
1819
|
+
} from "@yudaocode/univer-docs";
|
|
1820
|
+
function coerceInputToFile(fileOrInput, options) {
|
|
1821
|
+
if (typeof File !== "undefined" && fileOrInput instanceof File && !options?.format && !options?.fileName) {
|
|
1822
|
+
return fileOrInput;
|
|
1823
|
+
}
|
|
1824
|
+
let ext = options?.format ? `.${options.format}` : "";
|
|
1825
|
+
if (!ext && options?.fileName) {
|
|
1826
|
+
const m = options.fileName.match(/(\.[^.]+)$/);
|
|
1827
|
+
if (m) ext = m[1].toLowerCase();
|
|
1828
|
+
}
|
|
1829
|
+
if (!ext && typeof File !== "undefined" && fileOrInput instanceof File) {
|
|
1830
|
+
const m = fileOrInput.name.match(/(\.[^.]+)$/);
|
|
1831
|
+
if (m) ext = m[1].toLowerCase();
|
|
1832
|
+
}
|
|
1833
|
+
if (typeof fileOrInput === "string") {
|
|
1834
|
+
const trimmed = fileOrInput.trimStart();
|
|
1835
|
+
if (!ext) {
|
|
1836
|
+
if (trimmed.startsWith("{")) ext = ".json";
|
|
1837
|
+
else if (/^<!doctype\s+html|^<html[\s>]|^<(?:p|h[1-6]|div|table)\b/i.test(trimmed)) ext = ".html";
|
|
1838
|
+
else if (trimmed.startsWith("{\\rtf")) ext = ".rtf";
|
|
1839
|
+
else ext = ".md";
|
|
1840
|
+
}
|
|
1841
|
+
const baseName2 = options?.fileName || `${options?.title || "imported"}${ext}`;
|
|
1842
|
+
return new File([fileOrInput], baseName2, { type: "text/plain;charset=utf-8" });
|
|
1843
|
+
}
|
|
1844
|
+
if (fileOrInput instanceof Uint8Array || fileOrInput instanceof ArrayBuffer) {
|
|
1845
|
+
const bytes = fileOrInput instanceof Uint8Array ? fileOrInput : new Uint8Array(fileOrInput);
|
|
1846
|
+
if (!ext) {
|
|
1847
|
+
if (bytes.length >= 4 && bytes[0] === 80 && bytes[1] === 75) {
|
|
1848
|
+
ext = ".docx";
|
|
1849
|
+
} else if (bytes.length >= 5 && bytes[0] === 123 && bytes[1] === 92 && bytes[2] === 114) {
|
|
1850
|
+
ext = ".rtf";
|
|
1851
|
+
} else {
|
|
1852
|
+
ext = ".docx";
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
const ab = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
1856
|
+
const baseName2 = options?.fileName || `${options?.title || "imported"}${ext}`;
|
|
1857
|
+
return new File([ab], baseName2);
|
|
1858
|
+
}
|
|
1859
|
+
const baseName = options?.fileName || `${options?.title || "imported"}${ext || ".docx"}`;
|
|
1860
|
+
return new File([fileOrInput], baseName, { type: fileOrInput.type || "application/octet-stream" });
|
|
1861
|
+
}
|
|
1862
|
+
var FUniverDocsExtMixin = class extends FUniver {
|
|
1863
|
+
createEnterpriseDoc(data, metadata, options) {
|
|
1864
|
+
const initialData = data?.body != null ? data : {
|
|
1865
|
+
...buildStructuredDocData({
|
|
1866
|
+
id: data?.id,
|
|
1867
|
+
title: data?.title || "\u672A\u547D\u540D\u6587\u6863",
|
|
1868
|
+
paragraphs: [{ segments: [""] }]
|
|
1869
|
+
}),
|
|
1870
|
+
...data
|
|
1871
|
+
};
|
|
1872
|
+
const model = this._univerInstanceService.createUnit(
|
|
1873
|
+
UniverInstanceType.UNIVER_DOC,
|
|
1874
|
+
initialData,
|
|
1875
|
+
options
|
|
1876
|
+
);
|
|
1877
|
+
if (metadata) {
|
|
1878
|
+
this._injector.get(IDocSdtService2).setTemplateMetadata(model.getUnitId(), metadata);
|
|
1879
|
+
}
|
|
1880
|
+
return this._injector.createInstance(FEnterpriseDoc, model);
|
|
1881
|
+
}
|
|
1882
|
+
getActiveEnterpriseDoc() {
|
|
1883
|
+
const model = this._univerInstanceService.getCurrentUnitOfType(
|
|
1884
|
+
UniverInstanceType.UNIVER_DOC
|
|
1885
|
+
);
|
|
1886
|
+
if (!model) return null;
|
|
1887
|
+
return this._injector.createInstance(FEnterpriseDoc, model);
|
|
1888
|
+
}
|
|
1889
|
+
getEnterpriseDoc(unitId) {
|
|
1890
|
+
const model = this._univerInstanceService.getUnit(
|
|
1891
|
+
unitId,
|
|
1892
|
+
UniverInstanceType.UNIVER_DOC
|
|
1893
|
+
);
|
|
1894
|
+
if (!model) return null;
|
|
1895
|
+
return this._injector.createInstance(FEnterpriseDoc, model);
|
|
1896
|
+
}
|
|
1897
|
+
setDocIoAdapter(adapter) {
|
|
1898
|
+
this._injector.get(IDocIoService2).setAdapter(adapter);
|
|
1899
|
+
}
|
|
1900
|
+
getDocIoAdapter() {
|
|
1901
|
+
return this._injector.get(IDocIoService2).getAdapter();
|
|
1902
|
+
}
|
|
1903
|
+
setDocAiCopilotAdapter(adapter) {
|
|
1904
|
+
this._injector.get(IDocAiCopilotService2).setAdapter(adapter);
|
|
1905
|
+
}
|
|
1906
|
+
getDocAiCopilotAdapter() {
|
|
1907
|
+
return this._injector.get(IDocAiCopilotService2).getAdapter();
|
|
1908
|
+
}
|
|
1909
|
+
setTrackChanges(enabled, author) {
|
|
1910
|
+
return this.getActiveEnterpriseDoc()?.setTrackChanges(enabled, author) ?? false;
|
|
1911
|
+
}
|
|
1912
|
+
insertTrackedText(text, index, author) {
|
|
1913
|
+
return this.getActiveEnterpriseDoc()?.insertTrackedText(text, index, author) ?? false;
|
|
1914
|
+
}
|
|
1915
|
+
markTrackedDeletion(startIndex, endIndex, author) {
|
|
1916
|
+
return this.getActiveEnterpriseDoc()?.markTrackedDeletion(startIndex, endIndex, author) ?? false;
|
|
1917
|
+
}
|
|
1918
|
+
acceptRevision(revisionId) {
|
|
1919
|
+
return this.getActiveEnterpriseDoc()?.acceptRevision(revisionId) ?? false;
|
|
1920
|
+
}
|
|
1921
|
+
rejectRevision(revisionId) {
|
|
1922
|
+
return this.getActiveEnterpriseDoc()?.rejectRevision(revisionId) ?? false;
|
|
1923
|
+
}
|
|
1924
|
+
acceptAllRevisions() {
|
|
1925
|
+
return this.getActiveEnterpriseDoc()?.acceptAllRevisions() ?? false;
|
|
1926
|
+
}
|
|
1927
|
+
rejectAllRevisions() {
|
|
1928
|
+
return this.getActiveEnterpriseDoc()?.rejectAllRevisions() ?? false;
|
|
1929
|
+
}
|
|
1930
|
+
getRevisions() {
|
|
1931
|
+
return this.getActiveEnterpriseDoc()?.getRevisions() ?? [];
|
|
1932
|
+
}
|
|
1933
|
+
async auditContractRisks() {
|
|
1934
|
+
const doc = this.getActiveEnterpriseDoc();
|
|
1935
|
+
if (!doc) return [];
|
|
1936
|
+
return doc.auditContractRisks();
|
|
1937
|
+
}
|
|
1938
|
+
async draftClauseByAi(prompt) {
|
|
1939
|
+
const doc = this.getActiveEnterpriseDoc();
|
|
1940
|
+
if (!doc) return "";
|
|
1941
|
+
return doc.draftClauseByAi(prompt);
|
|
1942
|
+
}
|
|
1943
|
+
async importDocToSnapshotAsync(fileOrInput, options) {
|
|
1944
|
+
const file = coerceInputToFile(fileOrInput, options);
|
|
1945
|
+
const partial = await this._injector.get(IDocIoService2).importDoc(file, void 0, {
|
|
1946
|
+
target: options?.target
|
|
1947
|
+
});
|
|
1948
|
+
if (partial.body) {
|
|
1949
|
+
return {
|
|
1950
|
+
id: partial.id || `doc_${Date.now().toString(36)}`,
|
|
1951
|
+
title: options?.title || partial.title || file.name.replace(/\.[^.]+$/, "") || "\u672A\u547D\u540D\u6587\u6863",
|
|
1952
|
+
documentStyle: partial.documentStyle ?? {
|
|
1953
|
+
pageSize: { width: 595.28, height: 841.89 },
|
|
1954
|
+
marginTop: 56,
|
|
1955
|
+
marginBottom: 56,
|
|
1956
|
+
marginLeft: 64,
|
|
1957
|
+
marginRight: 64
|
|
1958
|
+
},
|
|
1959
|
+
...partial
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
return buildStructuredDocData({
|
|
1963
|
+
id: partial.id,
|
|
1964
|
+
title: options?.title || partial.title || "\u672A\u547D\u540D\u6587\u6863",
|
|
1965
|
+
paragraphs: [{ segments: [""] }]
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
async importDocToUnitIdAsync(unitId, fileOrInput, options) {
|
|
1969
|
+
if (!unitId) return false;
|
|
1970
|
+
const snapshot = await this.importDocToSnapshotAsync(fileOrInput, options);
|
|
1971
|
+
snapshot.id = unitId;
|
|
1972
|
+
const existing = this._univerInstanceService.getUnit(
|
|
1973
|
+
unitId,
|
|
1974
|
+
UniverInstanceType.UNIVER_DOC
|
|
1975
|
+
);
|
|
1976
|
+
if (existing) {
|
|
1977
|
+
return this._injector.get(ICommandService2).syncExecuteCommand(
|
|
1978
|
+
ReplaceDocUnitSnapshotCommand2.id,
|
|
1979
|
+
{
|
|
1980
|
+
unitId,
|
|
1981
|
+
snapshot
|
|
1982
|
+
}
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
this._univerInstanceService.createUnit(
|
|
1986
|
+
UniverInstanceType.UNIVER_DOC,
|
|
1987
|
+
snapshot
|
|
1988
|
+
);
|
|
1989
|
+
return true;
|
|
1990
|
+
}
|
|
1991
|
+
async exportDocBySnapshotAsync(snapshot, format = "docx", options) {
|
|
1992
|
+
return this._injector.get(IDocIoService2).exportDoc({
|
|
1993
|
+
unitId: snapshot.id || "snapshot-export",
|
|
1994
|
+
snapshot,
|
|
1995
|
+
format,
|
|
1996
|
+
data: options?.data,
|
|
1997
|
+
pdfOptions: options?.pdfOptions,
|
|
1998
|
+
target: options?.target
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
async exportDocByUnitIdAsync(unitId, format = "docx", options) {
|
|
2002
|
+
const doc = this.getEnterpriseDoc(unitId);
|
|
2003
|
+
if (!doc) return null;
|
|
2004
|
+
return this._injector.get(IDocIoService2).exportDoc({
|
|
2005
|
+
unitId,
|
|
2006
|
+
snapshot: doc.save(),
|
|
2007
|
+
format,
|
|
2008
|
+
data: options?.data,
|
|
2009
|
+
pdfOptions: options?.pdfOptions,
|
|
2010
|
+
target: options?.target
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
FUniver.extend(FUniverDocsExtMixin);
|
|
2015
|
+
export {
|
|
2016
|
+
FEnterpriseDoc as FDocumentExtMixin,
|
|
2017
|
+
FEnterpriseDoc,
|
|
2018
|
+
FUniverDocsExtMixin
|
|
2019
|
+
};
|
|
2020
|
+
//# sourceMappingURL=index.js.map
|