@univerjs/docs 0.24.0 → 0.25.0-insiders.20260604-29ebbff

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/lib/facade.js ADDED
@@ -0,0 +1,299 @@
1
+ import { ICommandService, IResourceLoaderService, IUniverInstanceService, Inject, Injector, RedoCommand, UndoCommand, UniverInstanceType } from "@univerjs/core";
2
+ import { FBaseInitialable, FUniver } from "@univerjs/core/facade";
3
+ import { InsertTextCommand } from "@univerjs/docs";
4
+
5
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
6
+ function _typeof(o) {
7
+ "@babel/helpers - typeof";
8
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
9
+ return typeof o;
10
+ } : function(o) {
11
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
12
+ }, _typeof(o);
13
+ }
14
+
15
+ //#endregion
16
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
17
+ function toPrimitive(t, r) {
18
+ if ("object" != _typeof(t) || !t) return t;
19
+ var e = t[Symbol.toPrimitive];
20
+ if (void 0 !== e) {
21
+ var i = e.call(t, r || "default");
22
+ if ("object" != _typeof(i)) return i;
23
+ throw new TypeError("@@toPrimitive must return a primitive value.");
24
+ }
25
+ return ("string" === r ? String : Number)(t);
26
+ }
27
+
28
+ //#endregion
29
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
30
+ function toPropertyKey(t) {
31
+ var i = toPrimitive(t, "string");
32
+ return "symbol" == _typeof(i) ? i : i + "";
33
+ }
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
37
+ function _defineProperty(e, r, t) {
38
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
39
+ value: t,
40
+ enumerable: !0,
41
+ configurable: !0,
42
+ writable: !0
43
+ }) : e[r] = t, e;
44
+ }
45
+
46
+ //#endregion
47
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
48
+ function __decorateParam(paramIndex, decorator) {
49
+ return function(target, key) {
50
+ decorator(target, key, paramIndex);
51
+ };
52
+ }
53
+
54
+ //#endregion
55
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
56
+ function __decorate(decorators, target, key, desc) {
57
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
58
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
59
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
60
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
61
+ }
62
+
63
+ //#endregion
64
+ //#region src/facade/f-document.ts
65
+ let FDocument = class FDocument extends FBaseInitialable {
66
+ constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService) {
67
+ super(_injector);
68
+ this._documentDataModel = _documentDataModel;
69
+ this._injector = _injector;
70
+ this._univerInstanceService = _univerInstanceService;
71
+ this._resourceLoaderService = _resourceLoaderService;
72
+ this._commandService = _commandService;
73
+ _defineProperty(this, "id", void 0);
74
+ this.id = this._documentDataModel.getUnitId();
75
+ }
76
+ /**
77
+ * Get the document data model of the document.
78
+ * @returns {DocumentDataModel} The document data model.
79
+ * @example
80
+ * ```typescript
81
+ * const fDocument = univerAPI.getActiveDocument();
82
+ * const documentDataModel = fDocument.getDocumentDataModel();
83
+ * console.log(documentDataModel);
84
+ * ```
85
+ */
86
+ getDocumentDataModel() {
87
+ return this._documentDataModel;
88
+ }
89
+ dispose() {
90
+ super.dispose();
91
+ }
92
+ /**
93
+ * Get the document id.
94
+ * @returns {string} The document id.
95
+ * @example
96
+ * ```typescript
97
+ * const fDocument = univerAPI.getActiveDocument();
98
+ * const unitId = fDocument.getId();
99
+ * console.log(unitId);
100
+ * ```
101
+ */
102
+ getId() {
103
+ return this.id;
104
+ }
105
+ /**
106
+ * Get the document name.
107
+ * @returns {string} The document name.
108
+ * @example
109
+ * ```typescript
110
+ * const fDocument = univerAPI.getActiveDocument();
111
+ * const name = fDocument.getName();
112
+ * console.log(name);
113
+ * ```
114
+ */
115
+ getName() {
116
+ return this._documentDataModel.getTitle() || "";
117
+ }
118
+ /**
119
+ * Save the document snapshot data, including the document content and resource data, etc.
120
+ * @returns {IDocumentData} The document snapshot data.
121
+ * @example
122
+ * ```typescript
123
+ * const fDocument = univerAPI.getActiveDocument();
124
+ * const snapshot = fDocument.save();
125
+ * console.log(snapshot);
126
+ * ```
127
+ */
128
+ save() {
129
+ return this._resourceLoaderService.saveUnit(this._documentDataModel.getUnitId());
130
+ }
131
+ /**
132
+ * Undo the last operation in the document.
133
+ * @returns {Promise<boolean>} A promise that resolves to true if the undo operation was successful, or false if it failed.
134
+ * @example
135
+ * ```typescript
136
+ * const fDocument = univerAPI.getActiveDocument();
137
+ * await fDocument.undo();
138
+ * ```
139
+ */
140
+ undo() {
141
+ this._univerInstanceService.focusUnit(this.id);
142
+ return this._commandService.executeCommand(UndoCommand.id);
143
+ }
144
+ /**
145
+ * Redo the last undone operation in the document.
146
+ * @returns {Promise<boolean>} A promise that resolves to true if the redo operation was successful, or false if it failed.
147
+ * @example
148
+ * ```typescript
149
+ * const fDocument = univerAPI.getActiveDocument();
150
+ * await fDocument.redo();
151
+ * ```
152
+ */
153
+ redo() {
154
+ this._univerInstanceService.focusUnit(this.id);
155
+ return this._commandService.executeCommand(RedoCommand.id);
156
+ }
157
+ /**
158
+ * Adds the specified text to the end of this text region.
159
+ * @param {string} text - The text to be added to the end of this text region.
160
+ * @return {Promise<boolean>} A promise that resolves to true if the text was successfully appended, or false if it failed.
161
+ * @example
162
+ * ```typescript
163
+ * const fDocument = univerAPI.getActiveDocument();
164
+ * await fDocument.appendText('Hello, world!');
165
+ * ```
166
+ */
167
+ appendText(text) {
168
+ const { body } = this.save();
169
+ if (!body) throw new Error("The document body is empty");
170
+ const lastPosition = body.dataStream.length - 2;
171
+ return this.insertText(text, {
172
+ startOffset: lastPosition,
173
+ endOffset: lastPosition,
174
+ segmentId: ""
175
+ });
176
+ }
177
+ /**
178
+ * Inserts text at the provided document range. Defaults to appending before the final section break.
179
+ * @param {string} text - The text to insert.
180
+ * @param {IDocumentInsertTextFacadeOptions} options - Optional target range, segment id, and cursor offset.
181
+ * @returns {Promise<boolean>} A promise that resolves to true if the text was successfully inserted, or false if it failed.
182
+ * @example
183
+ *
184
+ * // Insert text at a specific range in the document body
185
+ * ```typescript
186
+ * const fDocument = univerAPI.getActiveDocument();
187
+ * await fDocument.insertText('Hello, world!', {
188
+ * startOffset: 5,
189
+ * endOffset: 5,
190
+ * segmentId: '',
191
+ * cursorOffset: 13,
192
+ * });
193
+ * ```
194
+ *
195
+ * // Insert text at the beginning of a header or footer segment
196
+ * ```typescript
197
+ * const fDocument = univerAPI.getActiveDocument();
198
+ * const snapshot = fDocument.save();
199
+ * const { headers, footers } = snapshot;
200
+ *
201
+ * if (headers) {
202
+ * for (const headerId in headers) {
203
+ * if (headerId === 'target-header-id') {
204
+ * await fDocument.insertText('Hello, header!', {
205
+ * startOffset: 0,
206
+ * endOffset: 0,
207
+ * segmentId: headerId,
208
+ * });
209
+ * }
210
+ * }
211
+ * }
212
+ *
213
+ * if (footers) {
214
+ * for (const footerId in footers) {
215
+ * if (footerId === 'target-footer-id') {
216
+ * await fDocument.insertText('Hello, footer!', {
217
+ * startOffset: 0,
218
+ * endOffset: 0,
219
+ * segmentId: footerId,
220
+ * });
221
+ * }
222
+ * }
223
+ * }
224
+ * ```
225
+ */
226
+ insertText(text, options = {}) {
227
+ var _options$startOffset, _options$endOffset, _options$segmentId;
228
+ const unitId = this.id;
229
+ const { body } = this.save();
230
+ if (!body) throw new Error("The document body is empty");
231
+ const startOffset = (_options$startOffset = options.startOffset) !== null && _options$startOffset !== void 0 ? _options$startOffset : Math.max(0, body.dataStream.length - 2);
232
+ const endOffset = (_options$endOffset = options.endOffset) !== null && _options$endOffset !== void 0 ? _options$endOffset : startOffset;
233
+ const segmentId = (_options$segmentId = options.segmentId) !== null && _options$segmentId !== void 0 ? _options$segmentId : "";
234
+ const activeRange = {
235
+ startOffset,
236
+ endOffset,
237
+ collapsed: startOffset === endOffset,
238
+ segmentId
239
+ };
240
+ return this._commandService.executeCommand(InsertTextCommand.id, {
241
+ unitId,
242
+ body: { dataStream: text },
243
+ range: activeRange,
244
+ segmentId,
245
+ ...options.cursorOffset == null ? {} : { cursorOffset: options.cursorOffset }
246
+ });
247
+ }
248
+ /**
249
+ * Inserts one or more plain-text paragraphs at the provided document range.
250
+ * @param {string} text - The paragraph text to insert. Newlines are normalized to document paragraph separators.
251
+ * @param {IDocumentInsertTextFacadeOptions} options - Optional target range, segment id, and cursor offset.
252
+ * @returns {Promise<boolean>} A promise that resolves to true if the paragraphs were successfully inserted, or false if it failed.
253
+ * @example
254
+ * ```typescript
255
+ * const fDocument = univerAPI.getActiveDocument();
256
+ * await fDocument.insertParagraph('Hello, world! This is a new paragraph.', {
257
+ * startOffset: 5,
258
+ * endOffset: 5,
259
+ * });
260
+ * ```
261
+ */
262
+ insertParagraph(text = "", options = {}) {
263
+ var _options$cursorOffset;
264
+ const dataStream = `${text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").join("\r\n")}\r\n`;
265
+ return this.insertText(dataStream, {
266
+ ...options,
267
+ cursorOffset: (_options$cursorOffset = options.cursorOffset) !== null && _options$cursorOffset !== void 0 ? _options$cursorOffset : dataStream.length
268
+ });
269
+ }
270
+ };
271
+ FDocument = __decorate([
272
+ __decorateParam(1, Inject(Injector)),
273
+ __decorateParam(2, IUniverInstanceService),
274
+ __decorateParam(3, Inject(IResourceLoaderService)),
275
+ __decorateParam(4, ICommandService)
276
+ ], FDocument);
277
+
278
+ //#endregion
279
+ //#region src/facade/f-univer.ts
280
+ var FUniverDocsUIMixin = class extends FUniver {
281
+ createDocument(data) {
282
+ const document = this._injector.get(IUniverInstanceService).createUnit(UniverInstanceType.UNIVER_DOC, data);
283
+ return this._injector.createInstance(FDocument, document);
284
+ }
285
+ getActiveDocument() {
286
+ const document = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
287
+ if (!document) return null;
288
+ return this._injector.createInstance(FDocument, document);
289
+ }
290
+ getDocument(id) {
291
+ const document = this._univerInstanceService.getUnit(id, UniverInstanceType.UNIVER_DOC);
292
+ if (!document) return null;
293
+ return this._injector.createInstance(FDocument, document);
294
+ }
295
+ };
296
+ FUniver.extend(FUniverDocsUIMixin);
297
+
298
+ //#endregion
299
+ export { FDocument };
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, JSONX, LocaleService, Plugin, RxDisposable, UniverInstanceType, composeInterceptors, createInterceptorKey, isInternalEditorID, merge, remove, toDisposable } from "@univerjs/core";
1
+ import { BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DeleteDirection, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, JSONX, LocaleService, Plugin, RxDisposable, TextX, TextXActionType, UniverInstanceType, composeInterceptors, createInterceptorKey, getRichTextEditPath, isInternalEditorID, merge, remove, toDisposable } from "@univerjs/core";
2
2
  import { DocumentSkeleton, DocumentViewModel, IRenderManagerService, NORMAL_TEXT_SELECTION_PLUGIN_STYLE } from "@univerjs/engine-render";
3
3
  import { BehaviorSubject, Subject, takeUntil } from "rxjs";
4
4
 
@@ -12,7 +12,7 @@ const SetTextSelectionsOperation = {
12
12
  };
13
13
 
14
14
  //#endregion
15
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
15
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
16
16
  function _typeof(o) {
17
17
  "@babel/helpers - typeof";
18
18
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -23,7 +23,7 @@ function _typeof(o) {
23
23
  }
24
24
 
25
25
  //#endregion
26
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
26
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
27
27
  function toPrimitive(t, r) {
28
28
  if ("object" != _typeof(t) || !t) return t;
29
29
  var e = t[Symbol.toPrimitive];
@@ -36,14 +36,14 @@ function toPrimitive(t, r) {
36
36
  }
37
37
 
38
38
  //#endregion
39
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
39
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
40
40
  function toPropertyKey(t) {
41
41
  var i = toPrimitive(t, "string");
42
42
  return "symbol" == _typeof(i) ? i : i + "";
43
43
  }
44
44
 
45
45
  //#endregion
46
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
46
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
47
47
  function _defineProperty(e, r, t) {
48
48
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
49
49
  value: t,
@@ -54,7 +54,7 @@ function _defineProperty(e, r, t) {
54
54
  }
55
55
 
56
56
  //#endregion
57
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
57
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
58
58
  function __decorateParam(paramIndex, decorator) {
59
59
  return function(target, key) {
60
60
  decorator(target, key, paramIndex);
@@ -62,7 +62,7 @@ function __decorateParam(paramIndex, decorator) {
62
62
  }
63
63
 
64
64
  //#endregion
65
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
65
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
66
66
  function __decorate(decorators, target, key, desc) {
67
67
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
68
68
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -376,10 +376,162 @@ const RichTextEditingMutation = {
376
376
  }
377
377
  };
378
378
 
379
+ //#endregion
380
+ //#region src/commands/commands/core-editing.command.ts
381
+ /**
382
+ * The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
383
+ */
384
+ const InsertTextCommand = {
385
+ id: "doc.command.insert-text",
386
+ type: CommandType.COMMAND,
387
+ handler: async (accessor, params) => {
388
+ var _activeRange$segmentI;
389
+ const commandService = accessor.get(ICommandService);
390
+ const { range, segmentId, body, unitId, cursorOffset } = params;
391
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService);
392
+ const docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
393
+ if (docDataModel == null) return false;
394
+ const activeRange = docSelectionManagerService.getActiveTextRange();
395
+ const originBody = docDataModel.getSelfOrHeaderFooterModel((_activeRange$segmentI = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "").getBody();
396
+ if (originBody == null) return false;
397
+ const { startOffset, collapsed } = range;
398
+ const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
399
+ const textRanges = [{
400
+ startOffset: startOffset + cursorMove,
401
+ endOffset: startOffset + cursorMove,
402
+ style: activeRange === null || activeRange === void 0 ? void 0 : activeRange.style,
403
+ collapsed
404
+ }];
405
+ const doMutation = {
406
+ id: RichTextEditingMutation.id,
407
+ params: {
408
+ unitId,
409
+ actions: [],
410
+ textRanges,
411
+ debounce: true
412
+ }
413
+ };
414
+ const textX = new TextX();
415
+ const jsonX = JSONX.getInstance();
416
+ if (collapsed) {
417
+ if (startOffset > 0) textX.push({
418
+ t: TextXActionType.RETAIN,
419
+ len: startOffset
420
+ });
421
+ textX.push({
422
+ t: TextXActionType.INSERT,
423
+ body,
424
+ len: body.dataStream.length
425
+ });
426
+ } else {
427
+ const dos = BuildTextUtils.selection.delete([range], originBody, 0, body);
428
+ textX.push(...dos);
429
+ }
430
+ doMutation.params.textRanges = [{
431
+ startOffset: startOffset + cursorMove,
432
+ endOffset: startOffset + cursorMove,
433
+ collapsed
434
+ }];
435
+ const path = getRichTextEditPath(docDataModel, segmentId);
436
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
437
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
438
+ return Boolean(result);
439
+ }
440
+ };
441
+ /**
442
+ * The command to delete text, mainly used in BACKSPACE and DELETE when collapsed is true. ONLY handle collapsed range!!!
443
+ */
444
+ const DeleteTextCommand = {
445
+ id: "doc.command.delete-text",
446
+ type: CommandType.COMMAND,
447
+ handler: async (accessor, params) => {
448
+ var _body$customRanges;
449
+ const commandService = accessor.get(ICommandService);
450
+ const univerInstanceService = accessor.get(IUniverInstanceService);
451
+ const { range, segmentId, unitId, direction, len = 1 } = params;
452
+ const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
453
+ const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
454
+ if (docDataModel == null || body == null) return false;
455
+ const { startOffset } = range;
456
+ let start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset;
457
+ let end = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset + len - 1;
458
+ const customRange = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((customRange) => customRange.startIndex <= start && customRange.endIndex >= end);
459
+ if (customRange === null || customRange === void 0 ? void 0 : customRange.wholeEntity) {
460
+ start = customRange.startIndex;
461
+ end = Math.max(end, customRange.endIndex);
462
+ }
463
+ const doMutation = {
464
+ id: RichTextEditingMutation.id,
465
+ params: {
466
+ unitId,
467
+ actions: [],
468
+ textRanges: [{
469
+ startOffset: start,
470
+ endOffset: start,
471
+ collapsed: true
472
+ }],
473
+ debounce: true
474
+ }
475
+ };
476
+ const textX = new TextX();
477
+ const jsonX = JSONX.getInstance();
478
+ textX.push({
479
+ t: TextXActionType.RETAIN,
480
+ len: start - 0
481
+ });
482
+ textX.push({
483
+ t: TextXActionType.DELETE,
484
+ len: end - start + 1
485
+ });
486
+ const path = getRichTextEditPath(docDataModel, segmentId);
487
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
488
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
489
+ return Boolean(result);
490
+ }
491
+ };
492
+ /**
493
+ * The command to update text properties, mainly used in BACKSPACE.
494
+ */
495
+ const UpdateTextCommand = {
496
+ id: "doc.command.update-text",
497
+ type: CommandType.COMMAND,
498
+ handler: async (accessor, params) => {
499
+ const { range, segmentId, updateBody, coverType, unitId, textRanges } = params;
500
+ const commandService = accessor.get(ICommandService);
501
+ const docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
502
+ if (docDataModel == null) return false;
503
+ const doMutation = {
504
+ id: RichTextEditingMutation.id,
505
+ params: {
506
+ unitId,
507
+ actions: [],
508
+ textRanges
509
+ }
510
+ };
511
+ const textX = new TextX();
512
+ const jsonX = JSONX.getInstance();
513
+ const { startOffset, endOffset } = range;
514
+ textX.push({
515
+ t: TextXActionType.RETAIN,
516
+ len: startOffset
517
+ });
518
+ textX.push({
519
+ t: TextXActionType.RETAIN,
520
+ body: updateBody,
521
+ len: endOffset - startOffset,
522
+ coverType
523
+ });
524
+ const path = getRichTextEditPath(docDataModel, segmentId);
525
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
526
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
527
+ return Boolean(result);
528
+ }
529
+ };
530
+
379
531
  //#endregion
380
532
  //#region package.json
381
533
  var name = "@univerjs/docs";
382
- var version = "0.24.0";
534
+ var version = "0.25.0-insiders.20260604-29ebbff";
383
535
 
384
536
  //#endregion
385
537
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -468,6 +620,43 @@ DocCustomRangeController = __decorate([
468
620
  __decorateParam(2, IUniverInstanceService)
469
621
  ], DocCustomRangeController);
470
622
 
623
+ //#endregion
624
+ //#region src/services/doc-content-insert.service.ts
625
+ /**
626
+ * Copyright 2023-present DreamNum Co., Ltd.
627
+ *
628
+ * Licensed under the Apache License, Version 2.0 (the "License");
629
+ * you may not use this file except in compliance with the License.
630
+ * You may obtain a copy of the License at
631
+ *
632
+ * http://www.apache.org/licenses/LICENSE-2.0
633
+ *
634
+ * Unless required by applicable law or agreed to in writing, software
635
+ * distributed under the License is distributed on an "AS IS" BASIS,
636
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
637
+ * See the License for the specific language governing permissions and
638
+ * limitations under the License.
639
+ */
640
+ var DocContentInsertService = class extends Disposable {
641
+ constructor(..._args) {
642
+ super(..._args);
643
+ _defineProperty(this, "_range", null);
644
+ }
645
+ setInsertRange(range) {
646
+ this._range = range;
647
+ }
648
+ consumeInsertRange(unitId) {
649
+ if (!this._range) return null;
650
+ if (unitId && this._range.unitId !== unitId) return null;
651
+ const range = this._range;
652
+ this._range = null;
653
+ return range;
654
+ }
655
+ clearInsertRange() {
656
+ this._range = null;
657
+ }
658
+ };
659
+
471
660
  //#endregion
472
661
  //#region src/plugin.ts
473
662
  let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
@@ -485,6 +674,9 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
485
674
  }
486
675
  _initializeCommands() {
487
676
  [
677
+ InsertTextCommand,
678
+ DeleteTextCommand,
679
+ UpdateTextCommand,
488
680
  RichTextEditingMutation,
489
681
  DocsRenameMutation,
490
682
  SetTextSelectionsOperation
@@ -496,6 +688,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
496
688
  [
497
689
  [DocSelectionManagerService],
498
690
  [DocStateEmitService],
691
+ [DocContentInsertService],
499
692
  [DocCustomRangeController]
500
693
  ].forEach((d) => this._injector.add(d));
501
694
  }
@@ -587,25 +780,6 @@ DocInterceptorService = __decorate([__decorateParam(1, Inject(DocSkeletonManager
587
780
 
588
781
  //#endregion
589
782
  //#region src/utils/custom-range-factory.ts
590
- /**
591
- * @deprecated This is a duplication from docs-ui to avoid making too much breaking changes.
592
- */
593
- function getRichTextEditPath(docDataModel, segmentId = "") {
594
- if (!segmentId) return ["body"];
595
- const { headers, footers } = docDataModel.getSnapshot();
596
- if (headers == null && footers == null) throw new Error("Document data model must have headers or footers when update by segment id");
597
- if ((headers === null || headers === void 0 ? void 0 : headers[segmentId]) != null) return [
598
- "headers",
599
- segmentId,
600
- "body"
601
- ];
602
- else if ((footers === null || footers === void 0 ? void 0 : footers[segmentId]) != null) return [
603
- "footers",
604
- segmentId,
605
- "body"
606
- ];
607
- else throw new Error("Segment id not found in headers or footers");
608
- }
609
783
  function addCustomRangeFactory(accessor, param, body) {
610
784
  const { unitId, segmentId } = param;
611
785
  const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
@@ -738,4 +912,4 @@ function replaceSelectionFactory(accessor, params) {
738
912
  }
739
913
 
740
914
  //#endregion
741
- export { DOC_INTERCEPTOR_POINT, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory, replaceSelectionFactory };
915
+ export { DOC_INTERCEPTOR_POINT, DeleteTextCommand, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService, InsertTextCommand, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory, replaceSelectionFactory };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand, IDocumentBody, IDocumentData, ITextRange, UpdateDocsAttributeType } from '@univerjs/core';
17
+ import type { ITextRangeWithStyle } from '@univerjs/engine-render';
18
+ import { DeleteDirection } from '@univerjs/core';
19
+ export interface IInsertTextCommandParams {
20
+ unitId: string;
21
+ body: IDocumentBody;
22
+ range: ITextRange;
23
+ segmentId?: string;
24
+ cursorOffset?: number;
25
+ }
26
+ /**
27
+ * The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
28
+ */
29
+ export declare const InsertTextCommand: ICommand<IInsertTextCommandParams>;
30
+ export interface IDeleteTextCommandParams {
31
+ unitId: string;
32
+ range: ITextRange;
33
+ direction: DeleteDirection;
34
+ len?: number;
35
+ segmentId?: string;
36
+ }
37
+ /**
38
+ * The command to delete text, mainly used in BACKSPACE and DELETE when collapsed is true. ONLY handle collapsed range!!!
39
+ */
40
+ export declare const DeleteTextCommand: ICommand<IDeleteTextCommandParams>;
41
+ export interface IUpdateTextCommandParams {
42
+ unitId: string;
43
+ updateBody: IDocumentBody;
44
+ range: ITextRange;
45
+ coverType: UpdateDocsAttributeType;
46
+ textRanges: ITextRangeWithStyle[];
47
+ segmentId?: string;
48
+ }
49
+ /**
50
+ * The command to update text properties, mainly used in BACKSPACE.
51
+ */
52
+ export declare const UpdateTextCommand: ICommand<IUpdateTextCommandParams>;
53
+ export interface ICoverCommandParams {
54
+ unitId: string;
55
+ snapshot?: IDocumentData;
56
+ clearUndoRedoStack?: boolean;
57
+ }