@univerjs/docs 0.25.1 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -13,7 +13,7 @@ const SetTextSelectionsOperation = {
13
13
  };
14
14
 
15
15
  //#endregion
16
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
16
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
17
17
  function _typeof(o) {
18
18
  "@babel/helpers - typeof";
19
19
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -24,7 +24,7 @@ function _typeof(o) {
24
24
  }
25
25
 
26
26
  //#endregion
27
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
27
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
28
28
  function toPrimitive(t, r) {
29
29
  if ("object" != _typeof(t) || !t) return t;
30
30
  var e = t[Symbol.toPrimitive];
@@ -37,14 +37,14 @@ function toPrimitive(t, r) {
37
37
  }
38
38
 
39
39
  //#endregion
40
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
40
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
41
41
  function toPropertyKey(t) {
42
42
  var i = toPrimitive(t, "string");
43
43
  return "symbol" == _typeof(i) ? i : i + "";
44
44
  }
45
45
 
46
46
  //#endregion
47
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
47
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
48
48
  function _defineProperty(e, r, t) {
49
49
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
50
50
  value: t,
@@ -55,7 +55,7 @@ function _defineProperty(e, r, t) {
55
55
  }
56
56
 
57
57
  //#endregion
58
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
58
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
59
59
  function __decorateParam(paramIndex, decorator) {
60
60
  return function(target, key) {
61
61
  decorator(target, key, paramIndex);
@@ -63,7 +63,7 @@ function __decorateParam(paramIndex, decorator) {
63
63
  }
64
64
 
65
65
  //#endregion
66
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
66
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
67
67
  function __decorate(decorators, target, key, desc) {
68
68
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
69
69
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -323,15 +323,16 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing";
323
323
  const RichTextEditingMutation = {
324
324
  id: RichTextEditingMutationId,
325
325
  type: _univerjs_core.CommandType.MUTATION,
326
- handler: (accessor, params) => {
326
+ handler: (accessor, params, options) => {
327
327
  var _renderManagerService, _docSelectionManagerS;
328
- const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync, syncer } = params;
328
+ const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync: paramsIsSync, syncer } = params;
329
+ const isSync = paramsIsSync || (options === null || options === void 0 ? void 0 : options.fromCollab) || (options === null || options === void 0 ? void 0 : options.fromChangeset);
329
330
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
330
331
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
331
332
  const docStateEmitService = accessor.get(DocStateEmitService);
332
- const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
333
- const documentViewModel = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getViewModel();
334
- if (documentDataModel == null || documentViewModel == null) throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
333
+ const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
334
+ const documentViewModel = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getViewModel();
335
+ if (documentDataModel == null) throw new Error(`DocumentDataModel not found for unitId: ${unitId}`);
335
336
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
336
337
  const docRanges = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
337
338
  const disabled = !!documentDataModel.getSnapshot().disabled;
@@ -342,7 +343,7 @@ const RichTextEditingMutation = {
342
343
  };
343
344
  const undoActions = _univerjs_core.JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
344
345
  documentDataModel.apply(actions);
345
- documentViewModel.reset(documentDataModel);
346
+ documentViewModel === null || documentViewModel === void 0 || documentViewModel.reset(documentDataModel);
346
347
  if (!noNeedSetTextRange && textRanges && trigger != null && !isSync) queueMicrotask(() => {
347
348
  docSelectionManagerService.replaceDocRanges(textRanges, {
348
349
  unitId,
@@ -377,10 +378,162 @@ const RichTextEditingMutation = {
377
378
  }
378
379
  };
379
380
 
381
+ //#endregion
382
+ //#region src/commands/commands/core-editing.command.ts
383
+ /**
384
+ * The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
385
+ */
386
+ const InsertTextCommand = {
387
+ id: "doc.command.insert-text",
388
+ type: _univerjs_core.CommandType.COMMAND,
389
+ handler: (accessor, params) => {
390
+ var _activeRange$segmentI;
391
+ const commandService = accessor.get(_univerjs_core.ICommandService);
392
+ const { range, segmentId, body, unitId, cursorOffset } = params;
393
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService);
394
+ const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
395
+ if (docDataModel == null) return false;
396
+ const activeRange = docSelectionManagerService.getActiveTextRange();
397
+ const originBody = docDataModel.getSelfOrHeaderFooterModel((_activeRange$segmentI = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "").getBody();
398
+ if (originBody == null) return false;
399
+ const { startOffset, collapsed } = range;
400
+ const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
401
+ const textRanges = [{
402
+ startOffset: startOffset + cursorMove,
403
+ endOffset: startOffset + cursorMove,
404
+ style: activeRange === null || activeRange === void 0 ? void 0 : activeRange.style,
405
+ collapsed
406
+ }];
407
+ const doMutation = {
408
+ id: RichTextEditingMutation.id,
409
+ params: {
410
+ unitId,
411
+ actions: [],
412
+ textRanges,
413
+ debounce: true
414
+ }
415
+ };
416
+ const textX = new _univerjs_core.TextX();
417
+ const jsonX = _univerjs_core.JSONX.getInstance();
418
+ if (collapsed) {
419
+ if (startOffset > 0) textX.push({
420
+ t: _univerjs_core.TextXActionType.RETAIN,
421
+ len: startOffset
422
+ });
423
+ textX.push({
424
+ t: _univerjs_core.TextXActionType.INSERT,
425
+ body,
426
+ len: body.dataStream.length
427
+ });
428
+ } else {
429
+ const dos = _univerjs_core.BuildTextUtils.selection.delete([range], originBody, 0, body);
430
+ textX.push(...dos);
431
+ }
432
+ doMutation.params.textRanges = [{
433
+ startOffset: startOffset + cursorMove,
434
+ endOffset: startOffset + cursorMove,
435
+ collapsed
436
+ }];
437
+ const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
438
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
439
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
440
+ return Boolean(result);
441
+ }
442
+ };
443
+ /**
444
+ * The command to delete text, mainly used in BACKSPACE and DELETE when collapsed is true. ONLY handle collapsed range!!!
445
+ */
446
+ const DeleteTextCommand = {
447
+ id: "doc.command.delete-text",
448
+ type: _univerjs_core.CommandType.COMMAND,
449
+ handler: (accessor, params) => {
450
+ var _body$customRanges;
451
+ const commandService = accessor.get(_univerjs_core.ICommandService);
452
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
453
+ const { range, segmentId, unitId, direction, len = 1 } = params;
454
+ const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
455
+ const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
456
+ if (docDataModel == null || body == null) return false;
457
+ const { startOffset } = range;
458
+ let start = direction === _univerjs_core.DeleteDirection.LEFT ? startOffset - len : startOffset;
459
+ let end = direction === _univerjs_core.DeleteDirection.LEFT ? startOffset - 1 : startOffset + len - 1;
460
+ const customRange = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((customRange) => customRange.startIndex <= start && customRange.endIndex >= end);
461
+ if (customRange === null || customRange === void 0 ? void 0 : customRange.wholeEntity) {
462
+ start = customRange.startIndex;
463
+ end = Math.max(end, customRange.endIndex);
464
+ }
465
+ const doMutation = {
466
+ id: RichTextEditingMutation.id,
467
+ params: {
468
+ unitId,
469
+ actions: [],
470
+ textRanges: [{
471
+ startOffset: start,
472
+ endOffset: start,
473
+ collapsed: true
474
+ }],
475
+ debounce: true
476
+ }
477
+ };
478
+ const textX = new _univerjs_core.TextX();
479
+ const jsonX = _univerjs_core.JSONX.getInstance();
480
+ textX.push({
481
+ t: _univerjs_core.TextXActionType.RETAIN,
482
+ len: start - 0
483
+ });
484
+ textX.push({
485
+ t: _univerjs_core.TextXActionType.DELETE,
486
+ len: end - start + 1
487
+ });
488
+ const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
489
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
490
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
491
+ return Boolean(result);
492
+ }
493
+ };
494
+ /**
495
+ * The command to update text properties, mainly used in BACKSPACE.
496
+ */
497
+ const UpdateTextCommand = {
498
+ id: "doc.command.update-text",
499
+ type: _univerjs_core.CommandType.COMMAND,
500
+ handler: (accessor, params) => {
501
+ const { range, segmentId, updateBody, coverType, unitId, textRanges } = params;
502
+ const commandService = accessor.get(_univerjs_core.ICommandService);
503
+ const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance();
504
+ if (docDataModel == null) return false;
505
+ const doMutation = {
506
+ id: RichTextEditingMutation.id,
507
+ params: {
508
+ unitId,
509
+ actions: [],
510
+ textRanges
511
+ }
512
+ };
513
+ const textX = new _univerjs_core.TextX();
514
+ const jsonX = _univerjs_core.JSONX.getInstance();
515
+ const { startOffset, endOffset } = range;
516
+ textX.push({
517
+ t: _univerjs_core.TextXActionType.RETAIN,
518
+ len: startOffset
519
+ });
520
+ textX.push({
521
+ t: _univerjs_core.TextXActionType.RETAIN,
522
+ body: updateBody,
523
+ len: endOffset - startOffset,
524
+ coverType
525
+ });
526
+ const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
527
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
528
+ const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
529
+ return Boolean(result);
530
+ }
531
+ };
532
+
380
533
  //#endregion
381
534
  //#region package.json
382
535
  var name = "@univerjs/docs";
383
- var version = "0.25.1";
536
+ var version = "1.0.0-alpha.1";
384
537
 
385
538
  //#endregion
386
539
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -469,6 +622,219 @@ DocCustomRangeController = __decorate([
469
622
  __decorateParam(2, _univerjs_core.IUniverInstanceService)
470
623
  ], DocCustomRangeController);
471
624
 
625
+ //#endregion
626
+ //#region src/services/doc-block-move-validator.service.ts
627
+ var DocBlockMoveValidatorService = class extends _univerjs_core.Disposable {
628
+ constructor(..._args) {
629
+ super(..._args);
630
+ _defineProperty(this, "_validators", []);
631
+ _defineProperty(this, "_transformers", []);
632
+ }
633
+ registerValidator(validator) {
634
+ this._validators.push(validator);
635
+ return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._validators, validator)));
636
+ }
637
+ registerTransformer(transformer) {
638
+ this._transformers.push(transformer);
639
+ return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._transformers, transformer)));
640
+ }
641
+ canMoveBlock(context) {
642
+ return this._validators.every((validator) => validator(context));
643
+ }
644
+ transformMoveResult(context) {
645
+ return this._transformers.reduce((result, transformer) => transformer({
646
+ ...context,
647
+ result
648
+ }), context.result);
649
+ }
650
+ };
651
+
652
+ //#endregion
653
+ //#region src/services/doc-content-insert.service.ts
654
+ /**
655
+ * Copyright 2023-present DreamNum Co., Ltd.
656
+ *
657
+ * Licensed under the Apache License, Version 2.0 (the "License");
658
+ * you may not use this file except in compliance with the License.
659
+ * You may obtain a copy of the License at
660
+ *
661
+ * http://www.apache.org/licenses/LICENSE-2.0
662
+ *
663
+ * Unless required by applicable law or agreed to in writing, software
664
+ * distributed under the License is distributed on an "AS IS" BASIS,
665
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
666
+ * See the License for the specific language governing permissions and
667
+ * limitations under the License.
668
+ */
669
+ var DocContentInsertService = class extends _univerjs_core.Disposable {
670
+ constructor(..._args) {
671
+ super(..._args);
672
+ _defineProperty(this, "_range", null);
673
+ }
674
+ setInsertRange(range) {
675
+ this._range = range;
676
+ }
677
+ consumeInsertRange(unitId) {
678
+ if (!this._range) return null;
679
+ if (unitId && this._range.unitId !== unitId) return null;
680
+ const range = this._range;
681
+ this._range = null;
682
+ return range;
683
+ }
684
+ clearInsertRange() {
685
+ this._range = null;
686
+ }
687
+ };
688
+
689
+ //#endregion
690
+ //#region src/services/doc-state-change-manager.service.ts
691
+ const DEBOUNCE_DELAY = 300;
692
+ const IDocStateChangeInterceptorService = (0, _univerjs_core.createIdentifier)("doc.state-change-interceptor-service");
693
+ let DocStateChangeManagerService = class DocStateChangeManagerService extends _univerjs_core.RxDisposable {
694
+ constructor(_undoRedoService, _commandService, _univerInstanceService, _docStateEmitService, _docStateChangeInterceptorService) {
695
+ super();
696
+ this._undoRedoService = _undoRedoService;
697
+ this._commandService = _commandService;
698
+ this._univerInstanceService = _univerInstanceService;
699
+ this._docStateEmitService = _docStateEmitService;
700
+ this._docStateChangeInterceptorService = _docStateChangeInterceptorService;
701
+ _defineProperty(this, "_docStateChange$", new rxjs.BehaviorSubject(null));
702
+ _defineProperty(this, "docStateChange$", this._docStateChange$.asObservable());
703
+ _defineProperty(this, "_historyStateCache", /* @__PURE__ */ new Map());
704
+ _defineProperty(this, "_changeStateCache", /* @__PURE__ */ new Map());
705
+ _defineProperty(this, "_historyTimer", null);
706
+ _defineProperty(this, "_changeStateCacheTimer", null);
707
+ this._initialize();
708
+ this._listenDocStateChange();
709
+ }
710
+ getStateCache(unitId) {
711
+ var _this$_historyStateCa, _this$_changeStateCac;
712
+ return {
713
+ history: (_this$_historyStateCa = this._historyStateCache.get(unitId)) !== null && _this$_historyStateCa !== void 0 ? _this$_historyStateCa : [],
714
+ collaboration: (_this$_changeStateCac = this._changeStateCache.get(unitId)) !== null && _this$_changeStateCac !== void 0 ? _this$_changeStateCac : []
715
+ };
716
+ }
717
+ setStateCache(unitId, cache) {
718
+ this._historyStateCache.set(unitId, cache.history);
719
+ this._changeStateCache.set(unitId, cache.collaboration);
720
+ }
721
+ _setChangeState(changeState) {
722
+ this._cacheChangeState(changeState, "history");
723
+ this._cacheChangeState(changeState, "collaboration");
724
+ }
725
+ _initialize() {
726
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
727
+ if (command.id === _univerjs_core.UndoCommandId || command.id === _univerjs_core.RedoCommandId) {
728
+ const univerDoc = this._univerInstanceService.getCurrentUniverDocInstance();
729
+ if (univerDoc == null) return;
730
+ const unitId = univerDoc.getUnitId();
731
+ this._pushHistory(unitId);
732
+ this._emitChangeState(unitId);
733
+ }
734
+ }));
735
+ }
736
+ _listenDocStateChange() {
737
+ this._docStateEmitService.docStateChangeParams$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((changeStateInfo) => {
738
+ var _this$_docStateChange, _this$_docStateChange2;
739
+ if (changeStateInfo == null) return;
740
+ const interceptedChangeStateInfo = (_this$_docStateChange = (_this$_docStateChange2 = this._docStateChangeInterceptorService) === null || _this$_docStateChange2 === void 0 ? void 0 : _this$_docStateChange2.transformChangeStateInfo(changeStateInfo)) !== null && _this$_docStateChange !== void 0 ? _this$_docStateChange : changeStateInfo;
741
+ if (interceptedChangeStateInfo == null) return;
742
+ if (interceptedChangeStateInfo.isSync) return;
743
+ const { isCompositionEnd: _isCompositionEnd, isSync: _isSync, syncer: _syncer, ...changeState } = interceptedChangeStateInfo;
744
+ this._setChangeState(changeState);
745
+ });
746
+ }
747
+ _cacheChangeState(changeState, type = "history") {
748
+ const { trigger, unitId, noHistory, debounce = false } = changeState;
749
+ if (noHistory || type === "history" && trigger == null) return;
750
+ if (type === "history" && (trigger === _univerjs_core.RedoCommandId || trigger === _univerjs_core.UndoCommandId)) return;
751
+ const stateCache = type === "history" ? this._historyStateCache : this._changeStateCache;
752
+ const cb = type === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
753
+ if (stateCache.has(unitId)) {
754
+ const cacheStates = stateCache.get(unitId);
755
+ cacheStates === null || cacheStates === void 0 || cacheStates.push(changeState);
756
+ } else stateCache.set(unitId, [changeState]);
757
+ if (debounce) if (type === "history") {
758
+ if (this._historyTimer) clearTimeout(this._historyTimer);
759
+ this._historyTimer = setTimeout(() => {
760
+ cb(unitId);
761
+ }, DEBOUNCE_DELAY);
762
+ } else {
763
+ if (this._changeStateCacheTimer) clearTimeout(this._changeStateCacheTimer);
764
+ this._changeStateCacheTimer = setTimeout(() => {
765
+ cb(unitId);
766
+ }, DEBOUNCE_DELAY);
767
+ }
768
+ else cb(unitId);
769
+ }
770
+ _pushHistory(unitId) {
771
+ const undoRedoService = this._undoRedoService;
772
+ const cacheStates = this._historyStateCache.get(unitId);
773
+ if (undoRedoService == null || !Array.isArray(cacheStates) || cacheStates.length === 0) return;
774
+ const len = cacheStates.length;
775
+ const commandId = cacheStates[0].commandId;
776
+ const firstState = cacheStates[0];
777
+ const lastState = cacheStates[len - 1];
778
+ const redoParams = {
779
+ unitId,
780
+ actions: cacheStates.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.redoState.actions), null),
781
+ textRanges: lastState.redoState.textRanges
782
+ };
783
+ const undoParams = {
784
+ unitId,
785
+ actions: cacheStates.reverse().reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.undoState.actions), null),
786
+ textRanges: firstState.undoState.textRanges
787
+ };
788
+ undoRedoService.pushUndoRedo({
789
+ unitID: unitId,
790
+ undoMutations: [{
791
+ id: commandId,
792
+ params: undoParams
793
+ }],
794
+ redoMutations: [{
795
+ id: commandId,
796
+ params: redoParams
797
+ }]
798
+ });
799
+ cacheStates.length = 0;
800
+ }
801
+ _emitChangeState(unitId) {
802
+ const cacheStates = this._changeStateCache.get(unitId);
803
+ if (!Array.isArray(cacheStates) || cacheStates.length === 0) return;
804
+ const len = cacheStates.length;
805
+ const { commandId, trigger, segmentId, noHistory, debounce } = cacheStates[0];
806
+ const firstState = cacheStates[0];
807
+ const lastState = cacheStates[len - 1];
808
+ const changeState = {
809
+ commandId,
810
+ unitId,
811
+ trigger,
812
+ redoState: {
813
+ unitId,
814
+ actions: cacheStates.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.redoState.actions), null),
815
+ textRanges: lastState.redoState.textRanges
816
+ },
817
+ undoState: {
818
+ unitId,
819
+ actions: cacheStates.reverse().reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.undoState.actions), null),
820
+ textRanges: firstState.undoState.textRanges
821
+ },
822
+ segmentId,
823
+ noHistory,
824
+ debounce
825
+ };
826
+ cacheStates.length = 0;
827
+ this._docStateChange$.next(changeState);
828
+ }
829
+ };
830
+ DocStateChangeManagerService = __decorate([
831
+ __decorateParam(0, (0, _univerjs_core.Optional)(_univerjs_core.IUndoRedoService)),
832
+ __decorateParam(1, _univerjs_core.ICommandService),
833
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
834
+ __decorateParam(3, (0, _univerjs_core.Inject)(DocStateEmitService)),
835
+ __decorateParam(4, (0, _univerjs_core.Optional)(IDocStateChangeInterceptorService))
836
+ ], DocStateChangeManagerService);
837
+
472
838
  //#endregion
473
839
  //#region src/plugin.ts
474
840
  let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
@@ -486,6 +852,9 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
486
852
  }
487
853
  _initializeCommands() {
488
854
  [
855
+ InsertTextCommand,
856
+ DeleteTextCommand,
857
+ UpdateTextCommand,
489
858
  RichTextEditingMutation,
490
859
  DocsRenameMutation,
491
860
  SetTextSelectionsOperation
@@ -497,10 +866,14 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
497
866
  [
498
867
  [DocSelectionManagerService],
499
868
  [DocStateEmitService],
869
+ [DocStateChangeManagerService],
870
+ [DocBlockMoveValidatorService],
871
+ [DocContentInsertService],
500
872
  [DocCustomRangeController]
501
873
  ].forEach((d) => this._injector.add(d));
502
874
  }
503
875
  onReady() {
876
+ this._injector.get(DocStateChangeManagerService);
504
877
  this._injector.get(DocCustomRangeController);
505
878
  }
506
879
  };
@@ -588,25 +961,6 @@ DocInterceptorService = __decorate([__decorateParam(1, (0, _univerjs_core.Inject
588
961
 
589
962
  //#endregion
590
963
  //#region src/utils/custom-range-factory.ts
591
- /**
592
- * @deprecated This is a duplication from docs-ui to avoid making too much breaking changes.
593
- */
594
- function getRichTextEditPath(docDataModel, segmentId = "") {
595
- if (!segmentId) return ["body"];
596
- const { headers, footers } = docDataModel.getSnapshot();
597
- if (headers == null && footers == null) throw new Error("Document data model must have headers or footers when update by segment id");
598
- if ((headers === null || headers === void 0 ? void 0 : headers[segmentId]) != null) return [
599
- "headers",
600
- segmentId,
601
- "body"
602
- ];
603
- else if ((footers === null || footers === void 0 ? void 0 : footers[segmentId]) != null) return [
604
- "footers",
605
- segmentId,
606
- "body"
607
- ];
608
- else throw new Error("Segment id not found in headers or footers");
609
- }
610
964
  function addCustomRangeFactory(accessor, param, body) {
611
965
  const { unitId, segmentId } = param;
612
966
  const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
@@ -625,7 +979,7 @@ function addCustomRangeFactory(accessor, param, body) {
625
979
  body
626
980
  });
627
981
  if (!textX) return false;
628
- const path = getRichTextEditPath(documentDataModel, segmentId);
982
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
629
983
  doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
630
984
  return doMutation;
631
985
  }
@@ -665,7 +1019,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
665
1019
  },
666
1020
  textX
667
1021
  };
668
- const path = getRichTextEditPath(documentDataModel, segmentId);
1022
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
669
1023
  doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
670
1024
  return doMutation;
671
1025
  }
@@ -690,7 +1044,7 @@ function deleteCustomRangeFactory(accessor, params) {
690
1044
  segmentId
691
1045
  });
692
1046
  if (!textX) return false;
693
- const path = getRichTextEditPath(documentDataModel, segmentId);
1047
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
694
1048
  doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
695
1049
  doMutation.params.textRanges = textX.selections;
696
1050
  return doMutation;
@@ -740,6 +1094,9 @@ function replaceSelectionFactory(accessor, params) {
740
1094
 
741
1095
  //#endregion
742
1096
  exports.DOC_INTERCEPTOR_POINT = DOC_INTERCEPTOR_POINT;
1097
+ exports.DeleteTextCommand = DeleteTextCommand;
1098
+ exports.DocBlockMoveValidatorService = DocBlockMoveValidatorService;
1099
+ exports.DocContentInsertService = DocContentInsertService;
743
1100
  Object.defineProperty(exports, 'DocInterceptorService', {
744
1101
  enumerable: true,
745
1102
  get: function () {
@@ -758,7 +1115,15 @@ Object.defineProperty(exports, 'DocSkeletonManagerService', {
758
1115
  return DocSkeletonManagerService;
759
1116
  }
760
1117
  });
1118
+ Object.defineProperty(exports, 'DocStateChangeManagerService', {
1119
+ enumerable: true,
1120
+ get: function () {
1121
+ return DocStateChangeManagerService;
1122
+ }
1123
+ });
761
1124
  exports.DocStateEmitService = DocStateEmitService;
1125
+ exports.IDocStateChangeInterceptorService = IDocStateChangeInterceptorService;
1126
+ exports.InsertTextCommand = InsertTextCommand;
762
1127
  exports.RichTextEditingMutation = RichTextEditingMutation;
763
1128
  exports.SetTextSelectionsOperation = SetTextSelectionsOperation;
764
1129
  Object.defineProperty(exports, 'UniverDocsPlugin', {
@@ -767,6 +1132,7 @@ Object.defineProperty(exports, 'UniverDocsPlugin', {
767
1132
  return UniverDocsPlugin;
768
1133
  }
769
1134
  });
1135
+ exports.UpdateTextCommand = UpdateTextCommand;
770
1136
  exports.addCustomRangeBySelectionFactory = addCustomRangeBySelectionFactory;
771
1137
  exports.addCustomRangeFactory = addCustomRangeFactory;
772
1138
  exports.deleteCustomRangeFactory = deleteCustomRangeFactory;