@univerjs/docs 0.24.0 → 0.25.0-insiders.20260608-e4336f7
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/README.md +1 -1
- package/lib/cjs/facade.js +351 -0
- package/lib/cjs/index.js +372 -35
- package/lib/es/facade.js +345 -0
- package/lib/es/index.js +360 -34
- package/lib/facade.js +345 -0
- package/lib/index.js +360 -34
- package/lib/types/commands/commands/core-editing.command.d.ts +57 -0
- package/lib/types/facade/f-document.d.ts +178 -0
- package/lib/types/facade/f-univer.d.ts +64 -0
- package/lib/types/facade/index.d.ts +18 -0
- package/lib/types/facade/utils.d.ts +26 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/services/doc-content-insert.service.d.ts +28 -0
- package/lib/types/services/doc-state-change-manager.service.d.ts +53 -0
- package/lib/types/utils/custom-range-factory.d.ts +1 -5
- package/lib/umd/facade.js +5 -0
- package/lib/umd/index.js +1 -1
- package/package.json +15 -5
- package/LICENSE +0 -176
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.
|
|
16
|
+
//#region \0@oxc-project+runtime@0.134.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.
|
|
27
|
+
//#region \0@oxc-project+runtime@0.134.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.
|
|
40
|
+
//#region \0@oxc-project+runtime@0.134.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.
|
|
47
|
+
//#region \0@oxc-project+runtime@0.134.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.
|
|
58
|
+
//#region \0@oxc-project+runtime@0.134.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.
|
|
66
|
+
//#region \0@oxc-project+runtime@0.134.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.
|
|
333
|
-
const documentViewModel = (_renderManagerService = renderManagerService.
|
|
334
|
-
if (documentDataModel == null
|
|
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: async (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: async (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: async (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.
|
|
536
|
+
var version = "0.25.0-insiders.20260608-e4336f7";
|
|
384
537
|
|
|
385
538
|
//#endregion
|
|
386
539
|
//#region src/commands/mutations/docs-rename.mutation.ts
|
|
@@ -469,6 +622,192 @@ DocCustomRangeController = __decorate([
|
|
|
469
622
|
__decorateParam(2, _univerjs_core.IUniverInstanceService)
|
|
470
623
|
], DocCustomRangeController);
|
|
471
624
|
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/services/doc-content-insert.service.ts
|
|
627
|
+
/**
|
|
628
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
629
|
+
*
|
|
630
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
631
|
+
* you may not use this file except in compliance with the License.
|
|
632
|
+
* You may obtain a copy of the License at
|
|
633
|
+
*
|
|
634
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
635
|
+
*
|
|
636
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
637
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
638
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
639
|
+
* See the License for the specific language governing permissions and
|
|
640
|
+
* limitations under the License.
|
|
641
|
+
*/
|
|
642
|
+
var DocContentInsertService = class extends _univerjs_core.Disposable {
|
|
643
|
+
constructor(..._args) {
|
|
644
|
+
super(..._args);
|
|
645
|
+
_defineProperty(this, "_range", null);
|
|
646
|
+
}
|
|
647
|
+
setInsertRange(range) {
|
|
648
|
+
this._range = range;
|
|
649
|
+
}
|
|
650
|
+
consumeInsertRange(unitId) {
|
|
651
|
+
if (!this._range) return null;
|
|
652
|
+
if (unitId && this._range.unitId !== unitId) return null;
|
|
653
|
+
const range = this._range;
|
|
654
|
+
this._range = null;
|
|
655
|
+
return range;
|
|
656
|
+
}
|
|
657
|
+
clearInsertRange() {
|
|
658
|
+
this._range = null;
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/services/doc-state-change-manager.service.ts
|
|
664
|
+
const DEBOUNCE_DELAY = 300;
|
|
665
|
+
const IDocStateChangeInterceptorService = (0, _univerjs_core.createIdentifier)("doc.state-change-interceptor-service");
|
|
666
|
+
let DocStateChangeManagerService = class DocStateChangeManagerService extends _univerjs_core.RxDisposable {
|
|
667
|
+
constructor(_undoRedoService, _commandService, _univerInstanceService, _docStateEmitService, _docStateChangeInterceptorService) {
|
|
668
|
+
super();
|
|
669
|
+
this._undoRedoService = _undoRedoService;
|
|
670
|
+
this._commandService = _commandService;
|
|
671
|
+
this._univerInstanceService = _univerInstanceService;
|
|
672
|
+
this._docStateEmitService = _docStateEmitService;
|
|
673
|
+
this._docStateChangeInterceptorService = _docStateChangeInterceptorService;
|
|
674
|
+
_defineProperty(this, "_docStateChange$", new rxjs.BehaviorSubject(null));
|
|
675
|
+
_defineProperty(this, "docStateChange$", this._docStateChange$.asObservable());
|
|
676
|
+
_defineProperty(this, "_historyStateCache", /* @__PURE__ */ new Map());
|
|
677
|
+
_defineProperty(this, "_changeStateCache", /* @__PURE__ */ new Map());
|
|
678
|
+
_defineProperty(this, "_historyTimer", null);
|
|
679
|
+
_defineProperty(this, "_changeStateCacheTimer", null);
|
|
680
|
+
this._initialize();
|
|
681
|
+
this._listenDocStateChange();
|
|
682
|
+
}
|
|
683
|
+
getStateCache(unitId) {
|
|
684
|
+
var _this$_historyStateCa, _this$_changeStateCac;
|
|
685
|
+
return {
|
|
686
|
+
history: (_this$_historyStateCa = this._historyStateCache.get(unitId)) !== null && _this$_historyStateCa !== void 0 ? _this$_historyStateCa : [],
|
|
687
|
+
collaboration: (_this$_changeStateCac = this._changeStateCache.get(unitId)) !== null && _this$_changeStateCac !== void 0 ? _this$_changeStateCac : []
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
setStateCache(unitId, cache) {
|
|
691
|
+
this._historyStateCache.set(unitId, cache.history);
|
|
692
|
+
this._changeStateCache.set(unitId, cache.collaboration);
|
|
693
|
+
}
|
|
694
|
+
_setChangeState(changeState) {
|
|
695
|
+
this._cacheChangeState(changeState, "history");
|
|
696
|
+
this._cacheChangeState(changeState, "collaboration");
|
|
697
|
+
}
|
|
698
|
+
_initialize() {
|
|
699
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
700
|
+
if (command.id === _univerjs_core.UndoCommandId || command.id === _univerjs_core.RedoCommandId) {
|
|
701
|
+
const univerDoc = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
702
|
+
if (univerDoc == null) return;
|
|
703
|
+
const unitId = univerDoc.getUnitId();
|
|
704
|
+
this._pushHistory(unitId);
|
|
705
|
+
this._emitChangeState(unitId);
|
|
706
|
+
}
|
|
707
|
+
}));
|
|
708
|
+
}
|
|
709
|
+
_listenDocStateChange() {
|
|
710
|
+
this._docStateEmitService.docStateChangeParams$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((changeStateInfo) => {
|
|
711
|
+
var _this$_docStateChange, _this$_docStateChange2;
|
|
712
|
+
if (changeStateInfo == null) return;
|
|
713
|
+
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;
|
|
714
|
+
if (interceptedChangeStateInfo == null) return;
|
|
715
|
+
if (interceptedChangeStateInfo.isSync) return;
|
|
716
|
+
const { isCompositionEnd: _isCompositionEnd, isSync: _isSync, syncer: _syncer, ...changeState } = interceptedChangeStateInfo;
|
|
717
|
+
this._setChangeState(changeState);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
_cacheChangeState(changeState, type = "history") {
|
|
721
|
+
const { trigger, unitId, noHistory, debounce = false } = changeState;
|
|
722
|
+
if (noHistory || type === "history" && trigger == null) return;
|
|
723
|
+
if (type === "history" && (trigger === _univerjs_core.RedoCommandId || trigger === _univerjs_core.UndoCommandId)) return;
|
|
724
|
+
const stateCache = type === "history" ? this._historyStateCache : this._changeStateCache;
|
|
725
|
+
const cb = type === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
|
|
726
|
+
if (stateCache.has(unitId)) {
|
|
727
|
+
const cacheStates = stateCache.get(unitId);
|
|
728
|
+
cacheStates === null || cacheStates === void 0 || cacheStates.push(changeState);
|
|
729
|
+
} else stateCache.set(unitId, [changeState]);
|
|
730
|
+
if (debounce) if (type === "history") {
|
|
731
|
+
if (this._historyTimer) clearTimeout(this._historyTimer);
|
|
732
|
+
this._historyTimer = setTimeout(() => {
|
|
733
|
+
cb(unitId);
|
|
734
|
+
}, DEBOUNCE_DELAY);
|
|
735
|
+
} else {
|
|
736
|
+
if (this._changeStateCacheTimer) clearTimeout(this._changeStateCacheTimer);
|
|
737
|
+
this._changeStateCacheTimer = setTimeout(() => {
|
|
738
|
+
cb(unitId);
|
|
739
|
+
}, DEBOUNCE_DELAY);
|
|
740
|
+
}
|
|
741
|
+
else cb(unitId);
|
|
742
|
+
}
|
|
743
|
+
_pushHistory(unitId) {
|
|
744
|
+
const undoRedoService = this._undoRedoService;
|
|
745
|
+
const cacheStates = this._historyStateCache.get(unitId);
|
|
746
|
+
if (undoRedoService == null || !Array.isArray(cacheStates) || cacheStates.length === 0) return;
|
|
747
|
+
const len = cacheStates.length;
|
|
748
|
+
const commandId = cacheStates[0].commandId;
|
|
749
|
+
const firstState = cacheStates[0];
|
|
750
|
+
const lastState = cacheStates[len - 1];
|
|
751
|
+
const redoParams = {
|
|
752
|
+
unitId,
|
|
753
|
+
actions: cacheStates.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.redoState.actions), null),
|
|
754
|
+
textRanges: lastState.redoState.textRanges
|
|
755
|
+
};
|
|
756
|
+
const undoParams = {
|
|
757
|
+
unitId,
|
|
758
|
+
actions: cacheStates.reverse().reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.undoState.actions), null),
|
|
759
|
+
textRanges: firstState.undoState.textRanges
|
|
760
|
+
};
|
|
761
|
+
undoRedoService.pushUndoRedo({
|
|
762
|
+
unitID: unitId,
|
|
763
|
+
undoMutations: [{
|
|
764
|
+
id: commandId,
|
|
765
|
+
params: undoParams
|
|
766
|
+
}],
|
|
767
|
+
redoMutations: [{
|
|
768
|
+
id: commandId,
|
|
769
|
+
params: redoParams
|
|
770
|
+
}]
|
|
771
|
+
});
|
|
772
|
+
cacheStates.length = 0;
|
|
773
|
+
}
|
|
774
|
+
_emitChangeState(unitId) {
|
|
775
|
+
const cacheStates = this._changeStateCache.get(unitId);
|
|
776
|
+
if (!Array.isArray(cacheStates) || cacheStates.length === 0) return;
|
|
777
|
+
const len = cacheStates.length;
|
|
778
|
+
const { commandId, trigger, segmentId, noHistory, debounce } = cacheStates[0];
|
|
779
|
+
const firstState = cacheStates[0];
|
|
780
|
+
const lastState = cacheStates[len - 1];
|
|
781
|
+
const changeState = {
|
|
782
|
+
commandId,
|
|
783
|
+
unitId,
|
|
784
|
+
trigger,
|
|
785
|
+
redoState: {
|
|
786
|
+
unitId,
|
|
787
|
+
actions: cacheStates.reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.redoState.actions), null),
|
|
788
|
+
textRanges: lastState.redoState.textRanges
|
|
789
|
+
},
|
|
790
|
+
undoState: {
|
|
791
|
+
unitId,
|
|
792
|
+
actions: cacheStates.reverse().reduce((acc, cur) => _univerjs_core.JSONX.compose(acc, cur.undoState.actions), null),
|
|
793
|
+
textRanges: firstState.undoState.textRanges
|
|
794
|
+
},
|
|
795
|
+
segmentId,
|
|
796
|
+
noHistory,
|
|
797
|
+
debounce
|
|
798
|
+
};
|
|
799
|
+
cacheStates.length = 0;
|
|
800
|
+
this._docStateChange$.next(changeState);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
DocStateChangeManagerService = __decorate([
|
|
804
|
+
__decorateParam(0, (0, _univerjs_core.Optional)(_univerjs_core.IUndoRedoService)),
|
|
805
|
+
__decorateParam(1, _univerjs_core.ICommandService),
|
|
806
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
807
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(DocStateEmitService)),
|
|
808
|
+
__decorateParam(4, (0, _univerjs_core.Optional)(IDocStateChangeInterceptorService))
|
|
809
|
+
], DocStateChangeManagerService);
|
|
810
|
+
|
|
472
811
|
//#endregion
|
|
473
812
|
//#region src/plugin.ts
|
|
474
813
|
let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
@@ -486,6 +825,9 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
|
486
825
|
}
|
|
487
826
|
_initializeCommands() {
|
|
488
827
|
[
|
|
828
|
+
InsertTextCommand,
|
|
829
|
+
DeleteTextCommand,
|
|
830
|
+
UpdateTextCommand,
|
|
489
831
|
RichTextEditingMutation,
|
|
490
832
|
DocsRenameMutation,
|
|
491
833
|
SetTextSelectionsOperation
|
|
@@ -497,10 +839,13 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
|
497
839
|
[
|
|
498
840
|
[DocSelectionManagerService],
|
|
499
841
|
[DocStateEmitService],
|
|
842
|
+
[DocStateChangeManagerService],
|
|
843
|
+
[DocContentInsertService],
|
|
500
844
|
[DocCustomRangeController]
|
|
501
845
|
].forEach((d) => this._injector.add(d));
|
|
502
846
|
}
|
|
503
847
|
onReady() {
|
|
848
|
+
this._injector.get(DocStateChangeManagerService);
|
|
504
849
|
this._injector.get(DocCustomRangeController);
|
|
505
850
|
}
|
|
506
851
|
};
|
|
@@ -588,25 +933,6 @@ DocInterceptorService = __decorate([__decorateParam(1, (0, _univerjs_core.Inject
|
|
|
588
933
|
|
|
589
934
|
//#endregion
|
|
590
935
|
//#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
936
|
function addCustomRangeFactory(accessor, param, body) {
|
|
611
937
|
const { unitId, segmentId } = param;
|
|
612
938
|
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
@@ -625,7 +951,7 @@ function addCustomRangeFactory(accessor, param, body) {
|
|
|
625
951
|
body
|
|
626
952
|
});
|
|
627
953
|
if (!textX) return false;
|
|
628
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
954
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
629
955
|
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
630
956
|
return doMutation;
|
|
631
957
|
}
|
|
@@ -665,7 +991,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
665
991
|
},
|
|
666
992
|
textX
|
|
667
993
|
};
|
|
668
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
994
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
669
995
|
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
670
996
|
return doMutation;
|
|
671
997
|
}
|
|
@@ -690,7 +1016,7 @@ function deleteCustomRangeFactory(accessor, params) {
|
|
|
690
1016
|
segmentId
|
|
691
1017
|
});
|
|
692
1018
|
if (!textX) return false;
|
|
693
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
1019
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
694
1020
|
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
695
1021
|
doMutation.params.textRanges = textX.selections;
|
|
696
1022
|
return doMutation;
|
|
@@ -740,6 +1066,8 @@ function replaceSelectionFactory(accessor, params) {
|
|
|
740
1066
|
|
|
741
1067
|
//#endregion
|
|
742
1068
|
exports.DOC_INTERCEPTOR_POINT = DOC_INTERCEPTOR_POINT;
|
|
1069
|
+
exports.DeleteTextCommand = DeleteTextCommand;
|
|
1070
|
+
exports.DocContentInsertService = DocContentInsertService;
|
|
743
1071
|
Object.defineProperty(exports, 'DocInterceptorService', {
|
|
744
1072
|
enumerable: true,
|
|
745
1073
|
get: function () {
|
|
@@ -758,7 +1086,15 @@ Object.defineProperty(exports, 'DocSkeletonManagerService', {
|
|
|
758
1086
|
return DocSkeletonManagerService;
|
|
759
1087
|
}
|
|
760
1088
|
});
|
|
1089
|
+
Object.defineProperty(exports, 'DocStateChangeManagerService', {
|
|
1090
|
+
enumerable: true,
|
|
1091
|
+
get: function () {
|
|
1092
|
+
return DocStateChangeManagerService;
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
761
1095
|
exports.DocStateEmitService = DocStateEmitService;
|
|
1096
|
+
exports.IDocStateChangeInterceptorService = IDocStateChangeInterceptorService;
|
|
1097
|
+
exports.InsertTextCommand = InsertTextCommand;
|
|
762
1098
|
exports.RichTextEditingMutation = RichTextEditingMutation;
|
|
763
1099
|
exports.SetTextSelectionsOperation = SetTextSelectionsOperation;
|
|
764
1100
|
Object.defineProperty(exports, 'UniverDocsPlugin', {
|
|
@@ -767,6 +1103,7 @@ Object.defineProperty(exports, 'UniverDocsPlugin', {
|
|
|
767
1103
|
return UniverDocsPlugin;
|
|
768
1104
|
}
|
|
769
1105
|
});
|
|
1106
|
+
exports.UpdateTextCommand = UpdateTextCommand;
|
|
770
1107
|
exports.addCustomRangeBySelectionFactory = addCustomRangeBySelectionFactory;
|
|
771
1108
|
exports.addCustomRangeFactory = addCustomRangeFactory;
|
|
772
1109
|
exports.deleteCustomRangeFactory = deleteCustomRangeFactory;
|