@univerjs/docs 1.0.0-beta.0 → 1.0.0-beta.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BooleanNumber, ColumnSeparatorType, DashStyleType, DataStreamTreeTokenType, DocumentFlavor, ICommandService, IResourceLoaderService, IUniverInstanceService, Inject, Injector, JSONX, PageOrientType, PresetListType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommand, SectionType, TextX, TextXActionType, Tools, UndoCommand, UniverInstanceType, UpdateDocsAttributeType, createParagraphId, createSectionId, generateRandomId, getParagraphContentStartOffset, getRichTextEditPath, getSectionHeaderFooterReferenceKey, regexp, resolveSectionHeaderFooterReference } from "@univerjs/core";
2
2
  import { FBaseInitialable, FEnum, FUniver } from "@univerjs/core/facade";
3
- import { CreateHeaderFooterCommand, DeleteDocumentSectionBreakCommand, HeaderFooterType, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, RichTextEditingMutation, SetSectionHeaderFooterLinkCommand, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, createSectionColumnProperties, generateParagraphs, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks } from "@univerjs/docs";
3
+ import { CreateHeaderFooterCommand, DeleteDocumentSectionBreakCommand, HeaderFooterType, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentNameCommand, SetSectionHeaderFooterLinkCommand, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, createSectionColumnProperties, generateParagraphs, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks } from "@univerjs/docs";
4
4
 
5
5
  //#region src/facade/utils.ts
6
6
  function cloneParagraphStyle(paragraphStyle) {
@@ -32,31 +32,24 @@ function buildPlainTextInsertBody(dataStream, options = {}) {
32
32
  if (paragraphs.length > 0) body.paragraphs = paragraphs;
33
33
  return body;
34
34
  }
35
- function replaceBodyRange(range, insertBody, docDataModel, injector) {
35
+ function replaceBodyRange(range, insertBody, docDataModel, commandService) {
36
36
  const { startOffset, endOffset, segmentId } = range;
37
- const textX = new TextX();
38
- if (startOffset > 0) textX.push({
39
- t: TextXActionType.RETAIN,
40
- len: startOffset
41
- });
42
- if (endOffset > startOffset) textX.push({
43
- t: TextXActionType.DELETE,
44
- len: endOffset - startOffset
45
- });
46
- if (insertBody.dataStream.length > 0) textX.push({
47
- t: TextXActionType.INSERT,
48
- body: insertBody,
49
- len: insertBody.dataStream.length
50
- });
51
- const actions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(docDataModel, segmentId));
52
- const result = injector.get(ICommandService).syncExecuteCommand(RichTextEditingMutation.id, {
37
+ const result = commandService.syncExecuteCommand(InsertTextCommand.id, {
53
38
  unitId: docDataModel.getUnitId(),
39
+ body: insertBody,
40
+ range: {
41
+ startOffset,
42
+ endOffset,
43
+ collapsed: startOffset === endOffset,
44
+ segmentId
45
+ },
54
46
  segmentId,
55
- actions,
47
+ debounce: false,
56
48
  textRanges: [],
49
+ noNeedSetTextRange: true,
57
50
  isEditing: false
58
51
  });
59
- return Boolean((result === null || result === void 0 ? void 0 : result.actions) && result.actions.length > 0);
52
+ return Boolean(result);
60
53
  }
61
54
  function retainBodyRange(range, updateBody, coverType, docDataModel, injector) {
62
55
  var _updateBody$textRuns, _docDataModel$getSelf;
@@ -97,23 +90,34 @@ function stripBlockTokens(text) {
97
90
  return Array.from(text).map((char) => char === DataStreamTreeTokenType.PARAGRAPH ? "\n" : char).filter((char) => char !== DataStreamTreeTokenType.BLOCK_START && char !== DataStreamTreeTokenType.BLOCK_END && char !== DataStreamTreeTokenType.SECTION_BREAK).join("").replace(/\n$/, "");
98
91
  }
99
92
 
93
+ //#endregion
94
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
95
+ function __decorateParam(paramIndex, decorator) {
96
+ return function(target, key) {
97
+ decorator(target, key, paramIndex);
98
+ };
99
+ }
100
+
101
+ //#endregion
102
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
103
+ function __decorate(decorators, target, key, desc) {
104
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
105
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
106
+ 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;
107
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
108
+ }
109
+
100
110
  //#endregion
101
111
  //#region src/facade/f-document-text-range.ts
102
- /**
103
- * Facade wrapper for reading and styling a fixed document text range.
104
- *
105
- * Offsets are fixed when the wrapper is created. Create a new range after edits
106
- * that insert or remove content before it.
107
- * @hideconstructor
108
- */
109
- var FDocumentTextRange = class extends FBaseInitialable {
110
- constructor(_document, _startOffset, _endOffset, _segmentId, _injector) {
112
+ let FDocumentTextRange = class FDocumentTextRange extends FBaseInitialable {
113
+ constructor(_document, _startOffset, _endOffset, _segmentId, _injector, _commandService) {
111
114
  super(_injector);
112
115
  this._document = _document;
113
116
  this._startOffset = _startOffset;
114
117
  this._endOffset = _endOffset;
115
118
  this._segmentId = _segmentId;
116
119
  this._injector = _injector;
120
+ this._commandService = _commandService;
117
121
  this._validateRange();
118
122
  }
119
123
  /**
@@ -232,7 +236,7 @@ var FDocumentTextRange = class extends FBaseInitialable {
232
236
  * ```
233
237
  */
234
238
  setText(text) {
235
- return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._injector);
239
+ return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
236
240
  }
237
241
  _validateRange() {
238
242
  const bodyLength = this._document.getBody(this._segmentId).dataStream.length;
@@ -259,27 +263,11 @@ var FDocumentTextRange = class extends FBaseInitialable {
259
263
  return segments;
260
264
  }
261
265
  };
266
+ FDocumentTextRange = __decorate([__decorateParam(5, ICommandService)], FDocumentTextRange);
262
267
  function isDeepEqual(left, right) {
263
268
  return JSON.stringify(left) === JSON.stringify(right);
264
269
  }
265
270
 
266
- //#endregion
267
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
268
- function __decorateParam(paramIndex, decorator) {
269
- return function(target, key) {
270
- decorator(target, key, paramIndex);
271
- };
272
- }
273
-
274
- //#endregion
275
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
276
- function __decorate(decorators, target, key, desc) {
277
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
278
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
279
- 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;
280
- return c > 3 && r && Object.defineProperty(target, key, r), r;
281
- }
282
-
283
271
  //#endregion
284
272
  //#region src/facade/f-document-paragraph.ts
285
273
  let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
@@ -477,7 +465,7 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
477
465
  startOffset,
478
466
  endOffset,
479
467
  segmentId: this._segmentId
480
- }, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._injector);
468
+ }, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
481
469
  }
482
470
  /**
483
471
  * Append plain text before this paragraph's trailing paragraph break.
@@ -1335,6 +1323,24 @@ let FDocument = class FDocument extends FBaseInitialable {
1335
1323
  return this._documentDataModel.getTitle() || "";
1336
1324
  }
1337
1325
  /**
1326
+ * Set the document name.
1327
+ * @param {string} name The new document name.
1328
+ * @returns {FDocument} The current document for chaining.
1329
+ *
1330
+ * @example
1331
+ * ```ts
1332
+ * const document = univerAPI.getActiveDocument();
1333
+ * document?.setName('Quarterly Report');
1334
+ * ```
1335
+ */
1336
+ setName(name) {
1337
+ this._commandService.syncExecuteCommand(SetDocumentNameCommand.id, {
1338
+ unitId: this.id,
1339
+ name
1340
+ });
1341
+ return this;
1342
+ }
1343
+ /**
1338
1344
  * Returns the document's explicit layout flavor.
1339
1345
  *
1340
1346
  * Use this method when all three states matter. Do not infer a Traditional
@@ -1491,7 +1497,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1491
1497
  startOffset: index,
1492
1498
  endOffset: index,
1493
1499
  segmentId
1494
- }, buildPlainTextInsertBody(text), this._documentDataModel, this._injector);
1500
+ }, buildPlainTextInsertBody(text), this._documentDataModel, this._commandService);
1495
1501
  }
1496
1502
  /**
1497
1503
  * Returns document-level header/footer switches and margins. Margin values use 96-DPI layout pixels.
@@ -1712,7 +1718,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1712
1718
  }, {
1713
1719
  dataStream: DataStreamTreeTokenType.PARAGRAPH,
1714
1720
  paragraphs
1715
- }, this._documentDataModel, this._injector) ? this.getParagraph(paragraphId, segmentId) : null;
1721
+ }, this._documentDataModel, this._commandService) ? this.getParagraph(paragraphId, segmentId) : null;
1716
1722
  }
1717
1723
  /**
1718
1724
  * Get all paragraphs in the document body or header/footer body by the segment id.
@@ -1825,7 +1831,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1825
1831
  startOffset: offset,
1826
1832
  endOffset: offset,
1827
1833
  segmentId
1828
- }, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this._injector)) throw new Error("Failed to insert paragraph.");
1834
+ }, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this._commandService)) throw new Error("Failed to insert paragraph.");
1829
1835
  const { paragraphs = [] } = this.getBody(segmentId);
1830
1836
  const paragraph = paragraphs[index];
1831
1837
  if (!paragraph) throw new Error("Failed to insert paragraph.");
@@ -1867,7 +1873,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1867
1873
  deleteRange(range) {
1868
1874
  const normalizedRange = this._normalizeDeleteRange(range);
1869
1875
  if (normalizedRange.startOffset >= normalizedRange.endOffset) return false;
1870
- return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this._injector);
1876
+ return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this._commandService);
1871
1877
  }
1872
1878
  _createFDocumentParagraph(paragraphId, segmentId = "") {
1873
1879
  return this._injector.createInstance(FDocumentParagraph, this, paragraphId, segmentId, this._injector);
package/lib/index.js CHANGED
@@ -348,6 +348,7 @@ const RichTextEditingMutation = {
348
348
  if (documentDataModel == null) throw new Error(`DocumentDataModel not found for unitId: ${unitId}`);
349
349
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
350
350
  const docRanges = docSelectionManagerService.getDocRanges() ?? [];
351
+ const selectionInfo = docSelectionManagerService.getSelectionInfo();
351
352
  const disabled = !!documentDataModel.getSnapshot().disabled;
352
353
  if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled) return {
353
354
  unitId,
@@ -378,11 +379,15 @@ const RichTextEditingMutation = {
378
379
  debounce,
379
380
  redoState: {
380
381
  actions,
381
- textRanges
382
+ textRanges,
383
+ options: params.options,
384
+ isEditing
382
385
  },
383
386
  undoState: {
384
387
  actions: undoActions,
385
- textRanges: prevTextRanges ?? docRanges
388
+ textRanges: prevTextRanges ?? docRanges,
389
+ options: selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.options,
390
+ isEditing: selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isEditing
386
391
  },
387
392
  isCompositionEnd,
388
393
  isSync,
@@ -408,59 +413,63 @@ const InsertTextCommand = {
408
413
  handler: (accessor, params) => {
409
414
  var _docDataModel$getSelf;
410
415
  const commandService = accessor.get(ICommandService);
411
- const { range, segmentId, body, unitId, cursorOffset } = params;
416
+ const { range, segmentId, body, unitId, cursorOffset, debounce = true, textRanges, noNeedSetTextRange, isEditing } = params;
412
417
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
413
418
  const docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
414
419
  if (docDataModel == null) return false;
415
420
  const activeRange = docSelectionManagerService.getActiveTextRange();
416
- const rangeSegmentId = "segmentId" in range ? range.segmentId : void 0;
421
+ const rangeSegmentId = "segmentId" in range && typeof range.segmentId === "string" ? range.segmentId : void 0;
417
422
  const targetSegmentId = segmentId ?? rangeSegmentId ?? (activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) ?? "";
418
423
  const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(targetSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
419
424
  if (originBody == null) return false;
420
425
  const { startOffset, collapsed } = range;
421
426
  const cursorMove = cursorOffset ?? body.dataStream.length;
422
- const textRanges = [{
427
+ const mutationTextRanges = textRanges ?? [{
423
428
  startOffset: startOffset + cursorMove,
424
429
  endOffset: startOffset + cursorMove,
425
- style: activeRange === null || activeRange === void 0 ? void 0 : activeRange.style,
426
430
  collapsed
427
431
  }];
428
432
  const doMutation = {
429
433
  id: RichTextEditingMutation.id,
430
434
  params: {
431
435
  unitId,
436
+ segmentId: targetSegmentId,
432
437
  actions: [],
433
- textRanges,
434
- debounce: true
438
+ textRanges: mutationTextRanges,
439
+ debounce,
440
+ noNeedSetTextRange,
441
+ isEditing
435
442
  }
436
443
  };
437
- const textX = new TextX();
438
- const jsonX = JSONX.getInstance();
439
- if (collapsed) {
440
- if (startOffset > 0) textX.push({
441
- t: TextXActionType.RETAIN,
442
- len: startOffset
443
- });
444
- textX.push({
445
- t: TextXActionType.INSERT,
446
- body,
447
- len: body.dataStream.length
448
- });
449
- } else {
450
- const dos = BuildTextUtils.selection.delete([range], originBody, 0, body);
451
- textX.push(...dos);
452
- }
453
- doMutation.params.textRanges = [{
454
- startOffset: startOffset + cursorMove,
455
- endOffset: startOffset + cursorMove,
456
- collapsed
457
- }];
458
- const path = getRichTextEditPath(docDataModel, segmentId);
459
- doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
444
+ doMutation.params.actions = buildInsertTextActions(docDataModel, originBody, range, body, targetSegmentId);
460
445
  const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
461
446
  return Boolean(result);
462
447
  }
463
448
  };
449
+ function buildInsertTextActions(documentDataModel, originBody, range, insertBody, segmentId) {
450
+ const { startOffset, endOffset, collapsed } = range;
451
+ const textX = new TextX();
452
+ if (collapsed) {
453
+ if (startOffset > 0) textX.push({
454
+ t: TextXActionType.RETAIN,
455
+ len: startOffset
456
+ });
457
+ textX.push({
458
+ t: TextXActionType.INSERT,
459
+ body: insertBody,
460
+ len: insertBody.dataStream.length
461
+ });
462
+ } else textX.push(...BuildTextUtils.selection.delete([range], originBody, 0, insertBody));
463
+ const textActions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(documentDataModel, segmentId));
464
+ return collapsed ? textActions : appendRemovedDrawingActions(textActions, documentDataModel, originBody, startOffset, endOffset);
465
+ }
466
+ function appendRemovedDrawingActions(textActions, documentDataModel, body, startOffset, endOffset) {
467
+ return [textActions, ...BuildTextUtils.drawing.remove(documentDataModel.getSnapshot(), [{
468
+ startOffset,
469
+ endOffset,
470
+ collapsed: false
471
+ }], body)].reduce((accumulator, action) => JSONX.compose(accumulator, action));
472
+ }
464
473
  /**
465
474
  * The command to delete text, mainly used in BACKSPACE and DELETE when collapsed is true. ONLY handle collapsed range!!!
466
475
  */
@@ -487,6 +496,7 @@ const DeleteTextCommand = {
487
496
  id: RichTextEditingMutation.id,
488
497
  params: {
489
498
  unitId,
499
+ segmentId,
490
500
  actions: [],
491
501
  textRanges: [{
492
502
  startOffset: start,
@@ -505,7 +515,7 @@ const DeleteTextCommand = {
505
515
  collapsed: false
506
516
  }], body));
507
517
  const path = getRichTextEditPath(docDataModel, segmentId);
508
- doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
518
+ doMutation.params.actions = appendRemovedDrawingActions(jsonX.editOp(textX.serialize(), path), docDataModel, body, start, end + 1);
509
519
  const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
510
520
  return Boolean(result);
511
521
  }
@@ -737,6 +747,53 @@ const SetDocumentDefaultParagraphStyleCommand = {
737
747
  }
738
748
  };
739
749
 
750
+ //#endregion
751
+ //#region src/commands/mutations/docs-rename.mutation.ts
752
+ const DocsRenameMutation = {
753
+ id: "doc.mutation.rename-doc",
754
+ type: CommandType.MUTATION,
755
+ handler: (accessor, params) => {
756
+ const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
757
+ if (!doc) return false;
758
+ doc.setName(params.name);
759
+ return true;
760
+ }
761
+ };
762
+
763
+ //#endregion
764
+ //#region src/commands/commands/set-document-name.command.ts
765
+ const SetDocumentNameCommand = {
766
+ id: "doc.command.set-name",
767
+ type: CommandType.COMMAND,
768
+ handler: (accessor, params) => {
769
+ if (!params) return false;
770
+ const document = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
771
+ if (!document) return false;
772
+ const commandService = accessor.get(ICommandService);
773
+ const redoParams = {
774
+ unitId: params.unitId,
775
+ name: params.name
776
+ };
777
+ const undoParams = {
778
+ unitId: params.unitId,
779
+ name: document.getTitle() || ""
780
+ };
781
+ if (!commandService.syncExecuteCommand(DocsRenameMutation.id, redoParams)) return false;
782
+ accessor.get(IUndoRedoService).pushUndoRedo({
783
+ unitID: params.unitId,
784
+ redoMutations: [{
785
+ id: DocsRenameMutation.id,
786
+ params: redoParams
787
+ }],
788
+ undoMutations: [{
789
+ id: DocsRenameMutation.id,
790
+ params: undoParams
791
+ }]
792
+ });
793
+ return true;
794
+ }
795
+ };
796
+
740
797
  //#endregion
741
798
  //#region src/utils/sections.ts
742
799
  /** Returns document-level section breaks, excluding table-cell and modern-column sentinels. */
@@ -1146,7 +1203,7 @@ const InsertDocumentColumnBreakCommand = {
1146
1203
  rangeId: `docx-break-${generateRandomId()}`,
1147
1204
  rangeType: CustomRangeType.CUSTOM,
1148
1205
  wholeEntity: true,
1149
- properties: { docxBreakType: DocxBreakType.COLUMN }
1206
+ properties: { breakType: DocxBreakType.COLUMN }
1150
1207
  }]
1151
1208
  });
1152
1209
  return executeSectionTextX(context.commandService, context.documentDataModel, textX, InsertDocumentColumnBreakCommand.id);
@@ -1386,20 +1443,7 @@ function composeActions(actions) {
1386
1443
  //#endregion
1387
1444
  //#region package.json
1388
1445
  var name = "@univerjs/docs";
1389
- var version = "1.0.0-beta.0";
1390
-
1391
- //#endregion
1392
- //#region src/commands/mutations/docs-rename.mutation.ts
1393
- const DocsRenameMutation = {
1394
- id: "doc.mutation.rename-doc",
1395
- type: CommandType.MUTATION,
1396
- handler: (accessor, params) => {
1397
- const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
1398
- if (!doc) return false;
1399
- doc.setName(params.name);
1400
- return true;
1401
- }
1402
- };
1446
+ var version = "1.0.0-beta.2";
1403
1447
 
1404
1448
  //#endregion
1405
1449
  //#region src/config/config.ts
@@ -1570,6 +1614,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
1570
1614
  this._historyStateCache.set(unitId, cache.history);
1571
1615
  this._changeStateCache.set(unitId, cache.collaboration);
1572
1616
  }
1617
+ clearHistory(unitId) {
1618
+ this._historyStateCache.delete(unitId);
1619
+ }
1573
1620
  _setChangeState(changeState) {
1574
1621
  this._cacheChangeState(changeState, "history");
1575
1622
  this._cacheChangeState(changeState, "collaboration");
@@ -1602,6 +1649,8 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
1602
1649
  if (type === "history" && (trigger === RedoCommandId || trigger === UndoCommandId)) return;
1603
1650
  const stateCache = type === "history" ? this._historyStateCache : this._changeStateCache;
1604
1651
  const cb = type === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
1652
+ const pendingStates = stateCache.get(unitId);
1653
+ if ((pendingStates === null || pendingStates === void 0 ? void 0 : pendingStates.length) && pendingStates[pendingStates.length - 1].segmentId !== changeState.segmentId) cb(unitId);
1605
1654
  if (stateCache.has(unitId)) {
1606
1655
  const cacheStates = stateCache.get(unitId);
1607
1656
  cacheStates === null || cacheStates === void 0 || cacheStates.push(changeState);
@@ -1630,12 +1679,18 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
1630
1679
  const redoParams = {
1631
1680
  unitId,
1632
1681
  actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
1633
- textRanges: lastState.redoState.textRanges
1682
+ textRanges: lastState.redoState.textRanges,
1683
+ segmentId: lastState.segmentId,
1684
+ options: lastState.redoState.options,
1685
+ isEditing: lastState.redoState.isEditing
1634
1686
  };
1635
1687
  const undoParams = {
1636
1688
  unitId,
1637
1689
  actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
1638
- textRanges: firstState.undoState.textRanges
1690
+ textRanges: firstState.undoState.textRanges,
1691
+ segmentId: firstState.segmentId,
1692
+ options: firstState.undoState.options,
1693
+ isEditing: firstState.undoState.isEditing
1639
1694
  };
1640
1695
  undoRedoService.pushUndoRedo({
1641
1696
  unitID: unitId,
@@ -1664,12 +1719,18 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
1664
1719
  redoState: {
1665
1720
  unitId,
1666
1721
  actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
1667
- textRanges: lastState.redoState.textRanges
1722
+ textRanges: lastState.redoState.textRanges,
1723
+ segmentId: lastState.segmentId,
1724
+ options: lastState.redoState.options,
1725
+ isEditing: lastState.redoState.isEditing
1668
1726
  },
1669
1727
  undoState: {
1670
1728
  unitId,
1671
1729
  actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
1672
- textRanges: firstState.undoState.textRanges
1730
+ textRanges: firstState.undoState.textRanges,
1731
+ segmentId: firstState.segmentId,
1732
+ options: firstState.undoState.options,
1733
+ isEditing: firstState.undoState.isEditing
1673
1734
  },
1674
1735
  segmentId,
1675
1736
  noHistory,
@@ -1782,6 +1843,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
1782
1843
  UpdateTextCommand,
1783
1844
  CreateHeaderFooterCommand,
1784
1845
  SetDocumentDefaultParagraphStyleCommand,
1846
+ SetDocumentNameCommand,
1785
1847
  SetSectionHeaderFooterLinkCommand,
1786
1848
  UpdateDocumentParagraphStyleCommand,
1787
1849
  UpdateDocumentSectionCommand,
@@ -2133,4 +2195,4 @@ function normalizeTextRange(textRange) {
2133
2195
  }
2134
2196
 
2135
2197
  //#endregion
2136
- export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformToDocDrawingPosition };
2198
+ export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetDocumentNameCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformToDocDrawingPosition };
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { ICommand, IDocumentBody, IDocumentData, ITextRange, UpdateDocsAttributeType } from '@univerjs/core';
16
+ import type { ICommand, IDocumentBody, IDocumentData, ITextRange, Nullable, UpdateDocsAttributeType } from '@univerjs/core';
17
17
  import type { ITextRangeWithStyle } from '@univerjs/engine-render';
18
18
  import { DeleteDirection } from '@univerjs/core';
19
19
  export interface IInsertTextCommandParams {
@@ -22,6 +22,10 @@ export interface IInsertTextCommandParams {
22
22
  range: ITextRange;
23
23
  segmentId?: string;
24
24
  cursorOffset?: number;
25
+ debounce?: boolean;
26
+ textRanges?: Nullable<ITextRangeWithStyle[]>;
27
+ noNeedSetTextRange?: boolean;
28
+ isEditing?: boolean;
25
29
  }
26
30
  /**
27
31
  * The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
@@ -0,0 +1,21 @@
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 } from '@univerjs/core';
17
+ export interface ISetDocumentNameCommandParams {
18
+ unitId: string;
19
+ name: string;
20
+ }
21
+ export declare const SetDocumentNameCommand: ICommand<ISetDocumentNameCommandParams>;
@@ -13,9 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { ICommand } from '@univerjs/core';
16
+ import type { IMutation } from '@univerjs/core';
17
17
  export interface IDocsRenameMutationParams {
18
18
  name: string;
19
19
  unitId: string;
20
20
  }
21
- export declare const DocsRenameMutation: ICommand;
21
+ export declare const DocsRenameMutation: IMutation<IDocsRenameMutationParams>;
@@ -16,6 +16,7 @@
16
16
  import type { Injector, ITextStyle } from '@univerjs/core';
17
17
  import type { FDocument } from './f-document';
18
18
  import type { IFDocumentTextRange } from './utils';
19
+ import { ICommandService } from '@univerjs/core';
19
20
  import { FBaseInitialable } from '@univerjs/core/facade';
20
21
  /** A clipped text-style run in document offsets. */
21
22
  export interface IFDocumentTextStyleRun {
@@ -48,7 +49,8 @@ export declare class FDocumentTextRange extends FBaseInitialable {
48
49
  protected readonly _endOffset: number;
49
50
  protected readonly _segmentId: string;
50
51
  protected readonly _injector: Injector;
51
- constructor(_document: FDocument, _startOffset: number, _endOffset: number, _segmentId: string, _injector: Injector);
52
+ private readonly _commandService;
53
+ constructor(_document: FDocument, _startOffset: number, _endOffset: number, _segmentId: string, _injector: Injector, _commandService: ICommandService);
52
54
  /**
53
55
  * Returns the serializable document range.
54
56
  * @example
@@ -132,6 +132,18 @@ export declare class FDocument extends FBaseInitialable {
132
132
  * ```
133
133
  */
134
134
  getName(): string;
135
+ /**
136
+ * Set the document name.
137
+ * @param {string} name The new document name.
138
+ * @returns {FDocument} The current document for chaining.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const document = univerAPI.getActiveDocument();
143
+ * document?.setName('Quarterly Report');
144
+ * ```
145
+ */
146
+ setName(name: string): this;
135
147
  /**
136
148
  * Returns the document's explicit layout flavor.
137
149
  *
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { DocumentDataModel, IDocumentBody, Injector, IParagraphStyle, UpdateDocsAttributeType } from '@univerjs/core';
17
+ import { ICommandService } from '@univerjs/core';
17
18
  export interface IBuildPlainTextInsertBodyOptions {
18
19
  paragraphStyle?: IParagraphStyle;
19
20
  removeLeadingParagraphBreak?: boolean;
@@ -33,6 +34,6 @@ export declare function getRemovedLeadingParagraphBreakLength(dataStream: string
33
34
  export declare function getNormalizedPlainTextCursorOffset(dataStream: string, cursorOffset: number, removeLeadingParagraphBreak?: boolean): number;
34
35
  export declare function getParagraphStyleAtOffset(body: IDocumentBody, offset: number): IParagraphStyle | undefined;
35
36
  export declare function buildPlainTextInsertBody(dataStream: string, options?: IBuildPlainTextInsertBodyOptions): IDocumentBody;
36
- export declare function replaceBodyRange(range: IFDocumentTextRange, insertBody: IDocumentBody, docDataModel: DocumentDataModel, injector: Injector): boolean;
37
+ export declare function replaceBodyRange(range: IFDocumentTextRange, insertBody: IDocumentBody, docDataModel: DocumentDataModel, commandService: ICommandService): boolean;
37
38
  export declare function retainBodyRange(range: IFDocumentTextRange, updateBody: IDocumentBody, coverType: UpdateDocsAttributeType, docDataModel: DocumentDataModel, injector: Injector): boolean;
38
39
  export declare function stripBlockTokens(text: string): string;
@@ -19,6 +19,8 @@ export { CreateHeaderFooterCommand, HeaderFooterType } from './commands/commands
19
19
  export type { HeaderFooterCreateMode, ICreateHeaderFooterCommandParams, IHeaderFooterProps, } from './commands/commands/create-header-footer.command';
20
20
  export { SetDocumentDefaultParagraphStyleCommand } from './commands/commands/set-document-default-paragraph-style.command';
21
21
  export type { IDocumentDefaultParagraphStylePatch, ISetDocumentDefaultParagraphStyleCommandParams, } from './commands/commands/set-document-default-paragraph-style.command';
22
+ export { SetDocumentNameCommand } from './commands/commands/set-document-name.command';
23
+ export type { ISetDocumentNameCommandParams } from './commands/commands/set-document-name.command';
22
24
  export { SetSectionHeaderFooterLinkCommand } from './commands/commands/set-section-header-footer-link.command';
23
25
  export type { ISetSectionHeaderFooterLinkCommandParams } from './commands/commands/set-section-header-footer-link.command';
24
26
  export { UpdateDocumentParagraphStyleCommand } from './commands/commands/update-document-paragraph-style.command';
@@ -43,6 +43,7 @@ export declare class DocStateChangeManagerService extends RxDisposable {
43
43
  collaboration: IDocStateChangeParams[];
44
44
  };
45
45
  setStateCache(unitId: string, cache: IStateCache): void;
46
+ clearHistory(unitId: string): void;
46
47
  private _setChangeState;
47
48
  private _initialize;
48
49
  private _listenDocStateChange;
@@ -19,6 +19,10 @@ import { RxDisposable } from '@univerjs/core';
19
19
  interface IDocChangeState {
20
20
  actions: JSONXActions;
21
21
  textRanges: Nullable<ITextRangeWithStyle[]>;
22
+ options?: {
23
+ [key: string]: boolean;
24
+ };
25
+ isEditing?: boolean;
22
26
  }
23
27
  export interface IDocStateChangeParams {
24
28
  commandId: string;