@univerjs/docs 0.25.0-insiders.20260623-012b5a8 → 0.25.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/LICENSE +176 -0
- package/README.md +1 -1
- package/lib/cjs/index.js +35 -372
- package/lib/es/index.js +34 -360
- package/lib/index.js +34 -360
- package/lib/types/index.d.ts +3 -10
- package/lib/types/utils/custom-range-factory.d.ts +5 -1
- package/lib/umd/index.js +1 -1
- package/package.json +5 -15
- package/lib/cjs/facade.js +0 -1979
- package/lib/es/facade.js +0 -1965
- package/lib/facade.js +0 -1965
- package/lib/types/commands/commands/core-editing.command.d.ts +0 -57
- package/lib/types/facade/doc-element-registry.d.ts +0 -84
- package/lib/types/facade/f-doc-block-range.d.ts +0 -139
- package/lib/types/facade/f-doc-body.d.ts +0 -535
- package/lib/types/facade/f-doc-custom-block.d.ts +0 -94
- package/lib/types/facade/f-doc-element.d.ts +0 -177
- package/lib/types/facade/f-doc-paragraph.d.ts +0 -194
- package/lib/types/facade/f-doc-table.d.ts +0 -94
- package/lib/types/facade/f-document.d.ts +0 -205
- package/lib/types/facade/f-univer.d.ts +0 -64
- package/lib/types/facade/index.d.ts +0 -25
- package/lib/types/facade/utils.d.ts +0 -26
- package/lib/types/services/doc-content-insert.service.d.ts +0 -28
- package/lib/types/services/doc-state-change-manager.service.d.ts +0 -53
- package/lib/umd/facade.js +0 -5
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
|
|
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";
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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);
|
|
@@ -322,16 +322,15 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing";
|
|
|
322
322
|
const RichTextEditingMutation = {
|
|
323
323
|
id: RichTextEditingMutationId,
|
|
324
324
|
type: CommandType.MUTATION,
|
|
325
|
-
handler: (accessor, params
|
|
325
|
+
handler: (accessor, params) => {
|
|
326
326
|
var _renderManagerService, _docSelectionManagerS;
|
|
327
|
-
const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync
|
|
328
|
-
const isSync = paramsIsSync || (options === null || options === void 0 ? void 0 : options.fromCollab) || (options === null || options === void 0 ? void 0 : options.fromChangeset);
|
|
327
|
+
const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync, syncer } = params;
|
|
329
328
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
330
329
|
const renderManagerService = accessor.get(IRenderManagerService);
|
|
331
330
|
const docStateEmitService = accessor.get(DocStateEmitService);
|
|
332
|
-
const documentDataModel = univerInstanceService.
|
|
333
|
-
const documentViewModel = (_renderManagerService = renderManagerService.
|
|
334
|
-
if (documentDataModel == null) throw new Error(`DocumentDataModel not found for unitId: ${unitId}`);
|
|
331
|
+
const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
|
|
332
|
+
const documentViewModel = (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getViewModel();
|
|
333
|
+
if (documentDataModel == null || documentViewModel == null) throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
|
|
335
334
|
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
336
335
|
const docRanges = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
|
|
337
336
|
const disabled = !!documentDataModel.getSnapshot().disabled;
|
|
@@ -342,7 +341,7 @@ const RichTextEditingMutation = {
|
|
|
342
341
|
};
|
|
343
342
|
const undoActions = JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
|
|
344
343
|
documentDataModel.apply(actions);
|
|
345
|
-
documentViewModel
|
|
344
|
+
documentViewModel.reset(documentDataModel);
|
|
346
345
|
if (!noNeedSetTextRange && textRanges && trigger != null && !isSync) queueMicrotask(() => {
|
|
347
346
|
docSelectionManagerService.replaceDocRanges(textRanges, {
|
|
348
347
|
unitId,
|
|
@@ -377,162 +376,10 @@ const RichTextEditingMutation = {
|
|
|
377
376
|
}
|
|
378
377
|
};
|
|
379
378
|
|
|
380
|
-
//#endregion
|
|
381
|
-
//#region src/commands/commands/core-editing.command.ts
|
|
382
|
-
/**
|
|
383
|
-
* The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
|
|
384
|
-
*/
|
|
385
|
-
const InsertTextCommand = {
|
|
386
|
-
id: "doc.command.insert-text",
|
|
387
|
-
type: CommandType.COMMAND,
|
|
388
|
-
handler: (accessor, params) => {
|
|
389
|
-
var _activeRange$segmentI;
|
|
390
|
-
const commandService = accessor.get(ICommandService);
|
|
391
|
-
const { range, segmentId, body, unitId, cursorOffset } = params;
|
|
392
|
-
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
393
|
-
const docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
394
|
-
if (docDataModel == null) return false;
|
|
395
|
-
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
396
|
-
const originBody = docDataModel.getSelfOrHeaderFooterModel((_activeRange$segmentI = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "").getBody();
|
|
397
|
-
if (originBody == null) return false;
|
|
398
|
-
const { startOffset, collapsed } = range;
|
|
399
|
-
const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
|
|
400
|
-
const textRanges = [{
|
|
401
|
-
startOffset: startOffset + cursorMove,
|
|
402
|
-
endOffset: startOffset + cursorMove,
|
|
403
|
-
style: activeRange === null || activeRange === void 0 ? void 0 : activeRange.style,
|
|
404
|
-
collapsed
|
|
405
|
-
}];
|
|
406
|
-
const doMutation = {
|
|
407
|
-
id: RichTextEditingMutation.id,
|
|
408
|
-
params: {
|
|
409
|
-
unitId,
|
|
410
|
-
actions: [],
|
|
411
|
-
textRanges,
|
|
412
|
-
debounce: true
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
const textX = new TextX();
|
|
416
|
-
const jsonX = JSONX.getInstance();
|
|
417
|
-
if (collapsed) {
|
|
418
|
-
if (startOffset > 0) textX.push({
|
|
419
|
-
t: TextXActionType.RETAIN,
|
|
420
|
-
len: startOffset
|
|
421
|
-
});
|
|
422
|
-
textX.push({
|
|
423
|
-
t: TextXActionType.INSERT,
|
|
424
|
-
body,
|
|
425
|
-
len: body.dataStream.length
|
|
426
|
-
});
|
|
427
|
-
} else {
|
|
428
|
-
const dos = BuildTextUtils.selection.delete([range], originBody, 0, body);
|
|
429
|
-
textX.push(...dos);
|
|
430
|
-
}
|
|
431
|
-
doMutation.params.textRanges = [{
|
|
432
|
-
startOffset: startOffset + cursorMove,
|
|
433
|
-
endOffset: startOffset + cursorMove,
|
|
434
|
-
collapsed
|
|
435
|
-
}];
|
|
436
|
-
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
437
|
-
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
438
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
439
|
-
return Boolean(result);
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
/**
|
|
443
|
-
* The command to delete text, mainly used in BACKSPACE and DELETE when collapsed is true. ONLY handle collapsed range!!!
|
|
444
|
-
*/
|
|
445
|
-
const DeleteTextCommand = {
|
|
446
|
-
id: "doc.command.delete-text",
|
|
447
|
-
type: CommandType.COMMAND,
|
|
448
|
-
handler: (accessor, params) => {
|
|
449
|
-
var _body$customRanges;
|
|
450
|
-
const commandService = accessor.get(ICommandService);
|
|
451
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
452
|
-
const { range, segmentId, unitId, direction, len = 1 } = params;
|
|
453
|
-
const docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
454
|
-
const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
455
|
-
if (docDataModel == null || body == null) return false;
|
|
456
|
-
const { startOffset } = range;
|
|
457
|
-
let start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset;
|
|
458
|
-
let end = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset + len - 1;
|
|
459
|
-
const customRange = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((customRange) => customRange.startIndex <= start && customRange.endIndex >= end);
|
|
460
|
-
if (customRange === null || customRange === void 0 ? void 0 : customRange.wholeEntity) {
|
|
461
|
-
start = customRange.startIndex;
|
|
462
|
-
end = Math.max(end, customRange.endIndex);
|
|
463
|
-
}
|
|
464
|
-
const doMutation = {
|
|
465
|
-
id: RichTextEditingMutation.id,
|
|
466
|
-
params: {
|
|
467
|
-
unitId,
|
|
468
|
-
actions: [],
|
|
469
|
-
textRanges: [{
|
|
470
|
-
startOffset: start,
|
|
471
|
-
endOffset: start,
|
|
472
|
-
collapsed: true
|
|
473
|
-
}],
|
|
474
|
-
debounce: true
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
const textX = new TextX();
|
|
478
|
-
const jsonX = JSONX.getInstance();
|
|
479
|
-
textX.push({
|
|
480
|
-
t: TextXActionType.RETAIN,
|
|
481
|
-
len: start - 0
|
|
482
|
-
});
|
|
483
|
-
textX.push({
|
|
484
|
-
t: TextXActionType.DELETE,
|
|
485
|
-
len: end - start + 1
|
|
486
|
-
});
|
|
487
|
-
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
488
|
-
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
489
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
490
|
-
return Boolean(result);
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
/**
|
|
494
|
-
* The command to update text properties, mainly used in BACKSPACE.
|
|
495
|
-
*/
|
|
496
|
-
const UpdateTextCommand = {
|
|
497
|
-
id: "doc.command.update-text",
|
|
498
|
-
type: CommandType.COMMAND,
|
|
499
|
-
handler: (accessor, params) => {
|
|
500
|
-
const { range, segmentId, updateBody, coverType, unitId, textRanges } = params;
|
|
501
|
-
const commandService = accessor.get(ICommandService);
|
|
502
|
-
const docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
503
|
-
if (docDataModel == null) return false;
|
|
504
|
-
const doMutation = {
|
|
505
|
-
id: RichTextEditingMutation.id,
|
|
506
|
-
params: {
|
|
507
|
-
unitId,
|
|
508
|
-
actions: [],
|
|
509
|
-
textRanges
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
const textX = new TextX();
|
|
513
|
-
const jsonX = JSONX.getInstance();
|
|
514
|
-
const { startOffset, endOffset } = range;
|
|
515
|
-
textX.push({
|
|
516
|
-
t: TextXActionType.RETAIN,
|
|
517
|
-
len: startOffset
|
|
518
|
-
});
|
|
519
|
-
textX.push({
|
|
520
|
-
t: TextXActionType.RETAIN,
|
|
521
|
-
body: updateBody,
|
|
522
|
-
len: endOffset - startOffset,
|
|
523
|
-
coverType
|
|
524
|
-
});
|
|
525
|
-
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
526
|
-
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
527
|
-
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
528
|
-
return Boolean(result);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
|
|
532
379
|
//#endregion
|
|
533
380
|
//#region package.json
|
|
534
381
|
var name = "@univerjs/docs";
|
|
535
|
-
var version = "0.25.
|
|
382
|
+
var version = "0.25.1";
|
|
536
383
|
|
|
537
384
|
//#endregion
|
|
538
385
|
//#region src/commands/mutations/docs-rename.mutation.ts
|
|
@@ -621,192 +468,6 @@ DocCustomRangeController = __decorate([
|
|
|
621
468
|
__decorateParam(2, IUniverInstanceService)
|
|
622
469
|
], DocCustomRangeController);
|
|
623
470
|
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region src/services/doc-content-insert.service.ts
|
|
626
|
-
/**
|
|
627
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
628
|
-
*
|
|
629
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
630
|
-
* you may not use this file except in compliance with the License.
|
|
631
|
-
* You may obtain a copy of the License at
|
|
632
|
-
*
|
|
633
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
634
|
-
*
|
|
635
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
636
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
637
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
638
|
-
* See the License for the specific language governing permissions and
|
|
639
|
-
* limitations under the License.
|
|
640
|
-
*/
|
|
641
|
-
var DocContentInsertService = class extends Disposable {
|
|
642
|
-
constructor(..._args) {
|
|
643
|
-
super(..._args);
|
|
644
|
-
_defineProperty(this, "_range", null);
|
|
645
|
-
}
|
|
646
|
-
setInsertRange(range) {
|
|
647
|
-
this._range = range;
|
|
648
|
-
}
|
|
649
|
-
consumeInsertRange(unitId) {
|
|
650
|
-
if (!this._range) return null;
|
|
651
|
-
if (unitId && this._range.unitId !== unitId) return null;
|
|
652
|
-
const range = this._range;
|
|
653
|
-
this._range = null;
|
|
654
|
-
return range;
|
|
655
|
-
}
|
|
656
|
-
clearInsertRange() {
|
|
657
|
-
this._range = null;
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
//#endregion
|
|
662
|
-
//#region src/services/doc-state-change-manager.service.ts
|
|
663
|
-
const DEBOUNCE_DELAY = 300;
|
|
664
|
-
const IDocStateChangeInterceptorService = createIdentifier("doc.state-change-interceptor-service");
|
|
665
|
-
let DocStateChangeManagerService = class DocStateChangeManagerService extends RxDisposable {
|
|
666
|
-
constructor(_undoRedoService, _commandService, _univerInstanceService, _docStateEmitService, _docStateChangeInterceptorService) {
|
|
667
|
-
super();
|
|
668
|
-
this._undoRedoService = _undoRedoService;
|
|
669
|
-
this._commandService = _commandService;
|
|
670
|
-
this._univerInstanceService = _univerInstanceService;
|
|
671
|
-
this._docStateEmitService = _docStateEmitService;
|
|
672
|
-
this._docStateChangeInterceptorService = _docStateChangeInterceptorService;
|
|
673
|
-
_defineProperty(this, "_docStateChange$", new BehaviorSubject(null));
|
|
674
|
-
_defineProperty(this, "docStateChange$", this._docStateChange$.asObservable());
|
|
675
|
-
_defineProperty(this, "_historyStateCache", /* @__PURE__ */ new Map());
|
|
676
|
-
_defineProperty(this, "_changeStateCache", /* @__PURE__ */ new Map());
|
|
677
|
-
_defineProperty(this, "_historyTimer", null);
|
|
678
|
-
_defineProperty(this, "_changeStateCacheTimer", null);
|
|
679
|
-
this._initialize();
|
|
680
|
-
this._listenDocStateChange();
|
|
681
|
-
}
|
|
682
|
-
getStateCache(unitId) {
|
|
683
|
-
var _this$_historyStateCa, _this$_changeStateCac;
|
|
684
|
-
return {
|
|
685
|
-
history: (_this$_historyStateCa = this._historyStateCache.get(unitId)) !== null && _this$_historyStateCa !== void 0 ? _this$_historyStateCa : [],
|
|
686
|
-
collaboration: (_this$_changeStateCac = this._changeStateCache.get(unitId)) !== null && _this$_changeStateCac !== void 0 ? _this$_changeStateCac : []
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
setStateCache(unitId, cache) {
|
|
690
|
-
this._historyStateCache.set(unitId, cache.history);
|
|
691
|
-
this._changeStateCache.set(unitId, cache.collaboration);
|
|
692
|
-
}
|
|
693
|
-
_setChangeState(changeState) {
|
|
694
|
-
this._cacheChangeState(changeState, "history");
|
|
695
|
-
this._cacheChangeState(changeState, "collaboration");
|
|
696
|
-
}
|
|
697
|
-
_initialize() {
|
|
698
|
-
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
699
|
-
if (command.id === UndoCommandId || command.id === RedoCommandId) {
|
|
700
|
-
const univerDoc = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
701
|
-
if (univerDoc == null) return;
|
|
702
|
-
const unitId = univerDoc.getUnitId();
|
|
703
|
-
this._pushHistory(unitId);
|
|
704
|
-
this._emitChangeState(unitId);
|
|
705
|
-
}
|
|
706
|
-
}));
|
|
707
|
-
}
|
|
708
|
-
_listenDocStateChange() {
|
|
709
|
-
this._docStateEmitService.docStateChangeParams$.pipe(takeUntil(this.dispose$)).subscribe((changeStateInfo) => {
|
|
710
|
-
var _this$_docStateChange, _this$_docStateChange2;
|
|
711
|
-
if (changeStateInfo == null) return;
|
|
712
|
-
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;
|
|
713
|
-
if (interceptedChangeStateInfo == null) return;
|
|
714
|
-
if (interceptedChangeStateInfo.isSync) return;
|
|
715
|
-
const { isCompositionEnd: _isCompositionEnd, isSync: _isSync, syncer: _syncer, ...changeState } = interceptedChangeStateInfo;
|
|
716
|
-
this._setChangeState(changeState);
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
_cacheChangeState(changeState, type = "history") {
|
|
720
|
-
const { trigger, unitId, noHistory, debounce = false } = changeState;
|
|
721
|
-
if (noHistory || type === "history" && trigger == null) return;
|
|
722
|
-
if (type === "history" && (trigger === RedoCommandId || trigger === UndoCommandId)) return;
|
|
723
|
-
const stateCache = type === "history" ? this._historyStateCache : this._changeStateCache;
|
|
724
|
-
const cb = type === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
|
|
725
|
-
if (stateCache.has(unitId)) {
|
|
726
|
-
const cacheStates = stateCache.get(unitId);
|
|
727
|
-
cacheStates === null || cacheStates === void 0 || cacheStates.push(changeState);
|
|
728
|
-
} else stateCache.set(unitId, [changeState]);
|
|
729
|
-
if (debounce) if (type === "history") {
|
|
730
|
-
if (this._historyTimer) clearTimeout(this._historyTimer);
|
|
731
|
-
this._historyTimer = setTimeout(() => {
|
|
732
|
-
cb(unitId);
|
|
733
|
-
}, DEBOUNCE_DELAY);
|
|
734
|
-
} else {
|
|
735
|
-
if (this._changeStateCacheTimer) clearTimeout(this._changeStateCacheTimer);
|
|
736
|
-
this._changeStateCacheTimer = setTimeout(() => {
|
|
737
|
-
cb(unitId);
|
|
738
|
-
}, DEBOUNCE_DELAY);
|
|
739
|
-
}
|
|
740
|
-
else cb(unitId);
|
|
741
|
-
}
|
|
742
|
-
_pushHistory(unitId) {
|
|
743
|
-
const undoRedoService = this._undoRedoService;
|
|
744
|
-
const cacheStates = this._historyStateCache.get(unitId);
|
|
745
|
-
if (undoRedoService == null || !Array.isArray(cacheStates) || cacheStates.length === 0) return;
|
|
746
|
-
const len = cacheStates.length;
|
|
747
|
-
const commandId = cacheStates[0].commandId;
|
|
748
|
-
const firstState = cacheStates[0];
|
|
749
|
-
const lastState = cacheStates[len - 1];
|
|
750
|
-
const redoParams = {
|
|
751
|
-
unitId,
|
|
752
|
-
actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
|
|
753
|
-
textRanges: lastState.redoState.textRanges
|
|
754
|
-
};
|
|
755
|
-
const undoParams = {
|
|
756
|
-
unitId,
|
|
757
|
-
actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
|
|
758
|
-
textRanges: firstState.undoState.textRanges
|
|
759
|
-
};
|
|
760
|
-
undoRedoService.pushUndoRedo({
|
|
761
|
-
unitID: unitId,
|
|
762
|
-
undoMutations: [{
|
|
763
|
-
id: commandId,
|
|
764
|
-
params: undoParams
|
|
765
|
-
}],
|
|
766
|
-
redoMutations: [{
|
|
767
|
-
id: commandId,
|
|
768
|
-
params: redoParams
|
|
769
|
-
}]
|
|
770
|
-
});
|
|
771
|
-
cacheStates.length = 0;
|
|
772
|
-
}
|
|
773
|
-
_emitChangeState(unitId) {
|
|
774
|
-
const cacheStates = this._changeStateCache.get(unitId);
|
|
775
|
-
if (!Array.isArray(cacheStates) || cacheStates.length === 0) return;
|
|
776
|
-
const len = cacheStates.length;
|
|
777
|
-
const { commandId, trigger, segmentId, noHistory, debounce } = cacheStates[0];
|
|
778
|
-
const firstState = cacheStates[0];
|
|
779
|
-
const lastState = cacheStates[len - 1];
|
|
780
|
-
const changeState = {
|
|
781
|
-
commandId,
|
|
782
|
-
unitId,
|
|
783
|
-
trigger,
|
|
784
|
-
redoState: {
|
|
785
|
-
unitId,
|
|
786
|
-
actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
|
|
787
|
-
textRanges: lastState.redoState.textRanges
|
|
788
|
-
},
|
|
789
|
-
undoState: {
|
|
790
|
-
unitId,
|
|
791
|
-
actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
|
|
792
|
-
textRanges: firstState.undoState.textRanges
|
|
793
|
-
},
|
|
794
|
-
segmentId,
|
|
795
|
-
noHistory,
|
|
796
|
-
debounce
|
|
797
|
-
};
|
|
798
|
-
cacheStates.length = 0;
|
|
799
|
-
this._docStateChange$.next(changeState);
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
DocStateChangeManagerService = __decorate([
|
|
803
|
-
__decorateParam(0, Optional(IUndoRedoService)),
|
|
804
|
-
__decorateParam(1, ICommandService),
|
|
805
|
-
__decorateParam(2, IUniverInstanceService),
|
|
806
|
-
__decorateParam(3, Inject(DocStateEmitService)),
|
|
807
|
-
__decorateParam(4, Optional(IDocStateChangeInterceptorService))
|
|
808
|
-
], DocStateChangeManagerService);
|
|
809
|
-
|
|
810
471
|
//#endregion
|
|
811
472
|
//#region src/plugin.ts
|
|
812
473
|
let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
|
|
@@ -824,9 +485,6 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
|
|
|
824
485
|
}
|
|
825
486
|
_initializeCommands() {
|
|
826
487
|
[
|
|
827
|
-
InsertTextCommand,
|
|
828
|
-
DeleteTextCommand,
|
|
829
|
-
UpdateTextCommand,
|
|
830
488
|
RichTextEditingMutation,
|
|
831
489
|
DocsRenameMutation,
|
|
832
490
|
SetTextSelectionsOperation
|
|
@@ -838,13 +496,10 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
|
|
|
838
496
|
[
|
|
839
497
|
[DocSelectionManagerService],
|
|
840
498
|
[DocStateEmitService],
|
|
841
|
-
[DocStateChangeManagerService],
|
|
842
|
-
[DocContentInsertService],
|
|
843
499
|
[DocCustomRangeController]
|
|
844
500
|
].forEach((d) => this._injector.add(d));
|
|
845
501
|
}
|
|
846
502
|
onReady() {
|
|
847
|
-
this._injector.get(DocStateChangeManagerService);
|
|
848
503
|
this._injector.get(DocCustomRangeController);
|
|
849
504
|
}
|
|
850
505
|
};
|
|
@@ -932,6 +587,25 @@ DocInterceptorService = __decorate([__decorateParam(1, Inject(DocSkeletonManager
|
|
|
932
587
|
|
|
933
588
|
//#endregion
|
|
934
589
|
//#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
|
+
}
|
|
935
609
|
function addCustomRangeFactory(accessor, param, body) {
|
|
936
610
|
const { unitId, segmentId } = param;
|
|
937
611
|
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
@@ -1064,4 +738,4 @@ function replaceSelectionFactory(accessor, params) {
|
|
|
1064
738
|
}
|
|
1065
739
|
|
|
1066
740
|
//#endregion
|
|
1067
|
-
export { DOC_INTERCEPTOR_POINT,
|
|
741
|
+
export { DOC_INTERCEPTOR_POINT, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateEmitService, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory, replaceSelectionFactory };
|