@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/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 };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,22 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export {
|
|
17
|
-
export
|
|
18
|
-
export { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
|
|
19
|
-
export type { IRichTextEditingMutationParams } from './commands/mutations/core-editing.mutation';
|
|
20
|
-
export { SetTextSelectionsOperation } from './commands/operations/text-selection.operation';
|
|
21
|
-
export type { ISetTextSelectionsOperationParams } from './commands/operations/text-selection.operation';
|
|
16
|
+
export { type IRichTextEditingMutationParams, RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
|
|
17
|
+
export { type ISetTextSelectionsOperationParams, SetTextSelectionsOperation } from './commands/operations/text-selection.operation';
|
|
22
18
|
export type { IUniverDocsConfig } from './config/config';
|
|
23
19
|
export { UniverDocsPlugin } from './plugin';
|
|
24
|
-
export { DocContentInsertService } from './services/doc-content-insert.service';
|
|
25
|
-
export type { IDocContentInsertRange } from './services/doc-content-insert.service';
|
|
26
20
|
export { DocInterceptorService } from './services/doc-interceptor/doc-interceptor.service';
|
|
27
21
|
export { DOC_INTERCEPTOR_POINT } from './services/doc-interceptor/interceptor-const';
|
|
28
22
|
export { DocSelectionManagerService } from './services/doc-selection-manager.service';
|
|
29
23
|
export { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';
|
|
30
|
-
export { DocStateChangeManagerService, IDocStateChangeInterceptorService, } from './services/doc-state-change-manager.service';
|
|
31
24
|
export type { IDocStateChangeInfo, IDocStateChangeParams } from './services/doc-state-emit.service';
|
|
32
25
|
export { DocStateEmitService } from './services/doc-state-emit.service';
|
|
33
|
-
export { addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory
|
|
26
|
+
export { addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory } from './utils/custom-range-factory';
|
|
34
27
|
export { replaceSelectionFactory } from './utils/replace-selection-factory';
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { CustomRangeType, IAccessor, IAddCustomRangeTextXParam, IDocumentBody, IMutationInfo, ITextRangeParam, Nullable, TextX } from '@univerjs/core';
|
|
16
|
+
import type { CustomRangeType, DocumentDataModel, IAccessor, IAddCustomRangeTextXParam, IDocumentBody, IMutationInfo, ITextRangeParam, Nullable, TextX } from '@univerjs/core';
|
|
17
17
|
import type { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
|
|
18
18
|
interface IAddCustomRangeParam extends IAddCustomRangeTextXParam {
|
|
19
19
|
unitId: string;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated This is a duplication from docs-ui to avoid making too much breaking changes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getRichTextEditPath(docDataModel: DocumentDataModel, segmentId?: string): string[];
|
|
21
25
|
export declare function addCustomRangeFactory(accessor: IAccessor, param: IAddCustomRangeParam, body: IDocumentBody): false | IMutationInfo<IRichTextEditingMutationParams>;
|
|
22
26
|
interface IAddCustomRangeFactoryParam {
|
|
23
27
|
rangeId: string;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocs={},e.UniverCore,e.UniverEngineRender,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i={id:`doc.operation.set-selections`,type:t.CommandType.OPERATION,handler:()=>!0};function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends t.RxDisposable{constructor(e,t){super(),this._commandService=e,this._univerInstanceService=t,c(this,`_currentSelection`,null),c(this,`_textSelectionInfo`,new Map),c(this,`_textSelection$`,new r.Subject),c(this,`textSelection$`,this._textSelection$.asObservable()),c(this,`_refreshSelection$`,new r.BehaviorSubject(null)),c(this,`refreshSelection$`,this._refreshSelection$.asObservable()),this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{if(e==null)return;let t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var t,n;let r=(t=this.getTextRanges(e))==null?[]:t,i=(n=this.getRectRanges(e))==null?[]:n;return[...r,...i].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0)}getActiveTextRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{textRanges:t}=e;return t.find(e=>e.isActive)}getActiveRectRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{rectRanges:t}=e;return t.find(e=>e.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:``,segmentPage:-1,isEditing:t,style:n.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,r){if(t==null)return;let{unitId:i,subUnitId:a}=t;this._refreshSelection$.next({unitId:i,subUnitId:a,docRanges:e,isEditing:n,options:r})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;let n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);let{unitId:r,subUnitId:a,segmentId:o,style:s,textRanges:c,rectRanges:l,isEditing:u}=n,d=[...c,...l].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0);this._commandService.executeCommand(i.id,{unitId:r,subUnitId:a,segmentId:o,style:s,isEditing:u,ranges:d})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var t;if(e==null)return;let{unitId:n,subUnitId:r=``}=e;return(t=this._textSelectionInfo.get(n))==null?void 0:t.get(r)}_refresh(e){let t=this._getTextRanges(e);if(t==null)return;let{textRanges:n,rectRanges:r}=t,i=[...n,...r],{unitId:a,subUnitId:o}=e;this._refreshSelection$.next({unitId:a,subUnitId:o,docRanges:i,isEditing:!1})}_replaceByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...r})}_addByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);let i=this._textSelectionInfo.get(t);i.has(n)?i.get(n).textRanges.push(...e.textRanges):i.set(n,{...r})}};d=u([l(0,t.ICommandService),l(1,t.IUniverInstanceService)],d);let f=class extends t.RxDisposable{constructor(e,n,i){super(),this._context=e,this._localeService=n,this._univerInstanceService=i,c(this,`_skeleton`,void 0),c(this,`_docViewModel`,void 0),c(this,`_currentSkeleton$`,new r.BehaviorSubject(null)),c(this,`currentSkeleton$`,this._currentSkeleton$.asObservable()),c(this,`_currentSkeletonBefore$`,new r.BehaviorSubject(null)),c(this,`currentSkeletonBefore$`,this._currentSkeletonBefore$.asObservable()),c(this,`_currentViewModel$`,new r.BehaviorSubject(null)),c(this,`currentViewModel$`,this._currentViewModel$.asObservable()),this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{e&&e.getUnitId()===this._context.unitId&&this._update(e)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){let e=this._context.unit;this._update(e)}_update(e){let n=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&(0,t.isInternalEditorID)(n)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));let r=this._skeleton;r.calculate(),this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return n.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new n.DocumentViewModel(e)}};f=u([l(1,(0,t.Inject)(t.LocaleService)),l(2,t.IUniverInstanceService)],f);var p=class extends t.RxDisposable{constructor(){super(),c(this,`_docStateChangeParams$`,new r.BehaviorSubject(null)),c(this,`docStateChangeParams$`,this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};let m=`doc.mutation.rich-text-editing`,h={id:m,type:t.CommandType.MUTATION,handler:(e,r,i)=>{var a,o;let{unitId:s,segmentId:c=``,actions:l,textRanges:u,prevTextRanges:h,trigger:g,noHistory:_,isCompositionEnd:v,noNeedSetTextRange:y,debounce:b,isEditing:x=!0,isSync:S,syncer:C}=r,w=S||(i==null?void 0:i.fromCollab)||(i==null?void 0:i.fromChangeset),T=e.get(t.IUniverInstanceService),E=e.get(n.IRenderManagerService),D=e.get(p),O=T.getUnit(s,t.UniverInstanceType.UNIVER_DOC),k=(a=E.getRenderUnitById(s))==null?void 0:a.with(f).getViewModel();if(O==null)throw Error(`DocumentDataModel not found for unitId: ${s}`);let A=e.get(d),j=(o=A.getDocRanges())==null?[]:o,M=!!O.getSnapshot().disabled;if(t.JSONX.isNoop(l)||l&&l.length===0||M)return{unitId:s,actions:[],textRanges:j};let N=t.JSONX.invertWithDoc(l,O.getSnapshot());O.apply(l),k==null||k.reset(O),!y&&u&&g!=null&&!w&&queueMicrotask(()=>{A.replaceDocRanges(u,{unitId:s,subUnitId:s},x,r.options)});let P={commandId:m,unitId:s,segmentId:c,trigger:g,noHistory:_,debounce:b,redoState:{actions:l,textRanges:u},undoState:{actions:N,textRanges:h==null?j:h},isCompositionEnd:v,isSync:w,syncer:C};return D.emitStateChangeInfo(P),{unitId:s,actions:N,textRanges:j}}},g={id:`doc.command.insert-text`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r;let i=e.get(t.ICommandService),{range:a,segmentId:o,body:s,unitId:c,cursorOffset:l}=n,u=e.get(d),f=e.get(t.IUniverInstanceService).getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(f==null)return!1;let p=u.getActiveTextRange(),m=f.getSelfOrHeaderFooterModel((r=p==null?void 0:p.segmentId)==null?``:r).getBody();if(m==null)return!1;let{startOffset:g,collapsed:_}=a,v=l==null?s.dataStream.length:l,y=[{startOffset:g+v,endOffset:g+v,style:p==null?void 0:p.style,collapsed:_}],b={id:h.id,params:{unitId:c,actions:[],textRanges:y,debounce:!0}},x=new t.TextX,S=t.JSONX.getInstance();if(_)g>0&&x.push({t:t.TextXActionType.RETAIN,len:g}),x.push({t:t.TextXActionType.INSERT,body:s,len:s.dataStream.length});else{let e=t.BuildTextUtils.selection.delete([a],m,0,s);x.push(...e)}b.params.textRanges=[{startOffset:g+v,endOffset:g+v,collapsed:_}];let C=(0,t.getRichTextEditPath)(f,o);return b.params.actions=S.editOp(x.serialize(),C),!!i.syncExecuteCommand(b.id,b.params)}},_={id:`doc.command.delete-text`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r;let i=e.get(t.ICommandService),a=e.get(t.IUniverInstanceService),{range:o,segmentId:s,unitId:c,direction:l,len:u=1}=n,d=a.getUnit(c,t.UniverInstanceType.UNIVER_DOC),f=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getBody();if(d==null||f==null)return!1;let{startOffset:p}=o,m=l===t.DeleteDirection.LEFT?p-u:p,g=l===t.DeleteDirection.LEFT?p-1:p+u-1,_=(r=f.customRanges)==null?void 0:r.find(e=>e.startIndex<=m&&e.endIndex>=g);_!=null&&_.wholeEntity&&(m=_.startIndex,g=Math.max(g,_.endIndex));let v={id:h.id,params:{unitId:c,actions:[],textRanges:[{startOffset:m,endOffset:m,collapsed:!0}],debounce:!0}},y=new t.TextX,b=t.JSONX.getInstance();y.push({t:t.TextXActionType.RETAIN,len:m-0}),y.push({t:t.TextXActionType.DELETE,len:g-m+1});let x=(0,t.getRichTextEditPath)(d,s);return v.params.actions=b.editOp(y.serialize(),x),!!i.syncExecuteCommand(v.id,v.params)}},v={id:`doc.command.update-text`,type:t.CommandType.COMMAND,handler:(e,n)=>{let{range:r,segmentId:i,updateBody:a,coverType:o,unitId:s,textRanges:c}=n,l=e.get(t.ICommandService),u=e.get(t.IUniverInstanceService).getCurrentUniverDocInstance();if(u==null)return!1;let d={id:h.id,params:{unitId:s,actions:[],textRanges:c}},f=new t.TextX,p=t.JSONX.getInstance(),{startOffset:m,endOffset:g}=r;f.push({t:t.TextXActionType.RETAIN,len:m}),f.push({t:t.TextXActionType.RETAIN,body:a,len:g-m,coverType:o});let _=(0,t.getRichTextEditPath)(u,i);return d.params.actions=p.editOp(f.serialize(),_),!!l.syncExecuteCommand(d.id,d.params)}};var y=`@univerjs/docs`,b=`0.25.0-insiders.20260623-012b5a8`;let x={id:`doc.mutation.rename-doc`,type:t.CommandType.MUTATION,handler:(e,n)=>{let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);return r?(r.setName(n.name),!0):!1}},S={},C=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._initSelectionChange()}_transformCustomRange(e,n){var r;let{startOffset:i,endOffset:a,collapsed:o}=n,s=(r=e.getCustomRanges())==null?void 0:r.filter(e=>!e.wholeEntity||i<=e.startIndex&&a>e.endIndex?!1:o?e.startIndex<i&&e.endIndex>=a:t.BuildTextUtils.range.isIntersects(i,a-1,e.startIndex,e.endIndex));if(s!=null&&s.length){let e=i,t=a;return s.forEach(n=>{e=Math.min(n.startIndex,e),t=Math.max(n.endIndex+1,t)}),{...n,startOffset:e,endOffset:t,collapsed:e===t}}return n}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.id){let{unitId:t,ranges:n,isEditing:r}=e.params,i=this._univerInstanceService.getUnit(t);if(!i)return;let a=n.map(e=>this._transformCustomRange(i,e));a.some((e,t)=>n[t]!==e)&&this._textSelectionManagerService.replaceTextRanges(a,r)}}))}};C=u([l(0,t.ICommandService),l(1,(0,t.Inject)(d)),l(2,t.IUniverInstanceService)],C);var w=class extends t.Disposable{constructor(...e){super(...e),c(this,`_range`,null)}setInsertRange(e){this._range=e}consumeInsertRange(e){if(!this._range||e&&this._range.unitId!==e)return null;let t=this._range;return this._range=null,t}clearInsertRange(){this._range=null}};let T=(0,t.createIdentifier)(`doc.state-change-interceptor-service`),E=class extends t.RxDisposable{constructor(e,t,n,i,a){super(),this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._docStateEmitService=i,this._docStateChangeInterceptorService=a,c(this,`_docStateChange$`,new r.BehaviorSubject(null)),c(this,`docStateChange$`,this._docStateChange$.asObservable()),c(this,`_historyStateCache`,new Map),c(this,`_changeStateCache`,new Map),c(this,`_historyTimer`,null),c(this,`_changeStateCacheTimer`,null),this._initialize(),this._listenDocStateChange()}getStateCache(e){var t,n;return{history:(t=this._historyStateCache.get(e))==null?[]:t,collaboration:(n=this._changeStateCache.get(e))==null?[]:n}}setStateCache(e,t){this._historyStateCache.set(e,t.history),this._changeStateCache.set(e,t.collaboration)}_setChangeState(e){this._cacheChangeState(e,`history`),this._cacheChangeState(e,`collaboration`)}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===t.UndoCommandId||e.id===t.RedoCommandId){let e=this._univerInstanceService.getCurrentUniverDocInstance();if(e==null)return;let t=e.getUnitId();this._pushHistory(t),this._emitChangeState(t)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{var t,n;if(e==null)return;let r=(t=(n=this._docStateChangeInterceptorService)==null?void 0:n.transformChangeStateInfo(e))==null?e:t;if(r==null||r.isSync)return;let{isCompositionEnd:i,isSync:a,syncer:o,...s}=r;this._setChangeState(s)})}_cacheChangeState(e,n=`history`){let{trigger:r,unitId:i,noHistory:a,debounce:o=!1}=e;if(a||n===`history`&&r==null||n===`history`&&(r===t.RedoCommandId||r===t.UndoCommandId))return;let s=n===`history`?this._historyStateCache:this._changeStateCache,c=n===`history`?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(s.has(i)){let t=s.get(i);t==null||t.push(e)}else s.set(i,[e]);o?n===`history`?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{c(i)},300)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{c(i)},300)):c(i)}_pushHistory(e){let n=this._undoRedoService,r=this._historyStateCache.get(e);if(n==null||!Array.isArray(r)||r.length===0)return;let i=r.length,a=r[0].commandId,o=r[0],s=r[i-1],c={unitId:e,actions:r.reduce((e,n)=>t.JSONX.compose(e,n.redoState.actions),null),textRanges:s.redoState.textRanges},l={unitId:e,actions:r.reverse().reduce((e,n)=>t.JSONX.compose(e,n.undoState.actions),null),textRanges:o.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:l}],redoMutations:[{id:a,params:c}]}),r.length=0}_emitChangeState(e){let n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;let r=n.length,{commandId:i,trigger:a,segmentId:o,noHistory:s,debounce:c}=n[0],l=n[0],u=n[r-1],d={commandId:i,unitId:e,trigger:a,redoState:{unitId:e,actions:n.reduce((e,n)=>t.JSONX.compose(e,n.redoState.actions),null),textRanges:u.redoState.textRanges},undoState:{unitId:e,actions:n.reverse().reduce((e,n)=>t.JSONX.compose(e,n.undoState.actions),null),textRanges:l.undoState.textRanges},segmentId:o,noHistory:s,debounce:c};n.length=0,this._docStateChange$.next(d)}};E=u([l(0,(0,t.Optional)(t.IUndoRedoService)),l(1,t.ICommandService),l(2,t.IUniverInstanceService),l(3,(0,t.Inject)(p)),l(4,(0,t.Optional)(T))],E);let D=class extends t.Plugin{constructor(e=S,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},S,this._config);this._configService.setConfig(`docs.config`,i)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[g,_,v,h,x,i].forEach(e=>{this._injector.get(t.ICommandService).registerCommand(e)})}_initializeDependencies(){[[d],[p],[E],[w],[C]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(E),this._injector.get(C)}};c(D,`pluginName`,`DOCS_PLUGIN`),c(D,`packageName`,y),c(D,`version`,b),D=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.IConfigService)],D);let O={CUSTOM_RANGE:(0,t.createInterceptorKey)(`CUSTOM_RANGE`),CUSTOM_DECORATION:(0,t.createInterceptorKey)(`CUSTOM_DECORATION`)},k=class extends t.Disposable{constructor(e,n){super(),this._context=e,this._docSkeletonManagerService=n,c(this,`_interceptorsByName`,new Map);let r=this._docSkeletonManagerService.getViewModel(),i=r.getDataModel().getUnitId();if(i===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(r)),this.disposeWithMe(this.intercept(O.CUSTOM_RANGE,{priority:-1,handler:(e,t,n)=>n(e)}));let a=new t.DisposableCollection;r.segmentViewModels$.subscribe(e=>{a.dispose(),a=new t.DisposableCollection,e.forEach(e=>{a.add(this.interceptDocumentViewModel(e))})}),this.disposeWithMe(a)}intercept(e,n){let r=e;this._interceptorsByName.has(r)||this._interceptorsByName.set(r,[]);let i=this._interceptorsByName.get(r);return i.push(n),this._interceptorsByName.set(r,i.sort((e,t)=>{var n,r;return((n=t.priority)==null?0:n)-((r=e.priority)==null?0:r)})),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._interceptorsByName.get(r),n)))}fetchThroughInterceptors(e){let n=e;return(0,t.composeInterceptors)(this._interceptorsByName.get(n)||[])}interceptDocumentViewModel(e){let n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:t=>{var n;return this.fetchThroughInterceptors(O.CUSTOM_RANGE)(e.getCustomRangeRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customRanges:(n=e.getDataModel().getCustomRanges())==null?[]:n})},getCustomDecoration:t=>{var n;return this.fetchThroughInterceptors(O.CUSTOM_DECORATION)(e.getCustomDecorationRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customDecorations:(n=e.getDataModel().getCustomDecorations())==null?[]:n})}})),n}};k=u([l(1,(0,t.Inject)(f))],k);function A(e,n,r){let{unitId:i,segmentId:a}=n,o=e.get(t.IUniverInstanceService).getUnit(i);if(!o)return!1;let s={id:h.id,params:{unitId:n.unitId,actions:[],textRanges:void 0}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.add({...n,body:r});if(!l)return!1;let u=(0,t.getRichTextEditPath)(o,a);return s.params.actions=c.editOp(l.serialize(),u),s}function j(e,n){var r;let{rangeId:i,rangeType:a,wholeEntity:o,properties:s,unitId:c,selections:l}=n,u=e.get(d),f=e.get(t.IUniverInstanceService),p=l==null?u.getTextRanges({unitId:c,subUnitId:c}):l,m=p==null||(r=p[0])==null?void 0:r.segmentId;if(!(p!=null&&p.length))return!1;let g=f.getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(!g)return!1;let _=g.getSelfOrHeaderFooterModel(m).getBody();if(!_)return!1;let v=t.BuildTextUtils.customRange.add({ranges:p,rangeId:i,rangeType:a,segmentId:m,wholeEntity:o,properties:s,body:_});if(!v)return!1;let y=t.JSONX.getInstance(),b={id:h.id,params:{unitId:c,actions:[],textRanges:v.selections,segmentId:m},textX:v},x=(0,t.getRichTextEditPath)(g,m);return b.params.actions=y.editOp(v.serialize(),x),b}function M(e,n){let{unitId:r,segmentId:i,insert:a}=n,o=e.get(t.IUniverInstanceService).getUnit(r);if(!o)return!1;let s={id:h.id,params:{unitId:n.unitId,actions:[],textRanges:void 0,segmentId:i}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:n.rangeId,insert:a,segmentId:i});if(!l)return!1;let u=(0,t.getRichTextEditPath)(o,i);return s.params.actions=c.editOp(l.serialize(),u),s.params.textRanges=l.selections,s}function N(e,n){var r,i,a,o;let{unitId:s,body:c,doc:l}=n,u=l;if(u||(u=e.get(t.IUniverInstanceService).getUnit(s)),!u)return!1;let f=(r=n.selection)==null?void 0:r.segmentId,p=(i=u.getSelfOrHeaderFooterModel(f))==null?void 0:i.getBody();if(!p)return!1;let m=e.get(d),g=(a=n.selection)==null?m.getActiveTextRange():a;if(!g||!p)return!1;let _=(o=n.textRanges)==null?[{startOffset:g.startOffset+c.dataStream.length,endOffset:g.startOffset+c.dataStream.length,collapsed:!0,segmentId:f}]:o,v=t.BuildTextUtils.selection.replace({selection:g,body:c,doc:u});if(!v)return!1;let y={id:h.id,params:{unitId:s,actions:[],textRanges:_,debounce:!0,segmentId:f},textX:v},b=t.JSONX.getInstance();return y.params.actions=b.editOp(v.serialize()),y}e.DOC_INTERCEPTOR_POINT=O,e.DeleteTextCommand=_,e.DocContentInsertService=w,Object.defineProperty(e,"DocInterceptorService",{enumerable:!0,get:function(){return k}}),Object.defineProperty(e,"DocSelectionManagerService",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"DocSkeletonManagerService",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DocStateChangeManagerService",{enumerable:!0,get:function(){return E}}),e.DocStateEmitService=p,e.IDocStateChangeInterceptorService=T,e.InsertTextCommand=g,e.RichTextEditingMutation=h,e.SetTextSelectionsOperation=i,Object.defineProperty(e,"UniverDocsPlugin",{enumerable:!0,get:function(){return D}}),e.UpdateTextCommand=v,e.addCustomRangeBySelectionFactory=j,e.addCustomRangeFactory=A,e.deleteCustomRangeFactory=M,e.replaceSelectionFactory=N});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocs={},e.UniverCore,e.UniverEngineRender,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i={id:`doc.operation.set-selections`,type:t.CommandType.OPERATION,handler:()=>!0};function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends t.RxDisposable{constructor(e,t){super(),this._commandService=e,this._univerInstanceService=t,c(this,`_currentSelection`,null),c(this,`_textSelectionInfo`,new Map),c(this,`_textSelection$`,new r.Subject),c(this,`textSelection$`,this._textSelection$.asObservable()),c(this,`_refreshSelection$`,new r.BehaviorSubject(null)),c(this,`refreshSelection$`,this._refreshSelection$.asObservable()),this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{if(e==null)return;let t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var t,n;let r=(t=this.getTextRanges(e))==null?[]:t,i=(n=this.getRectRanges(e))==null?[]:n;return[...r,...i].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0)}getActiveTextRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{textRanges:t}=e;return t.find(e=>e.isActive)}getActiveRectRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{rectRanges:t}=e;return t.find(e=>e.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:``,segmentPage:-1,isEditing:t,style:n.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,r){if(t==null)return;let{unitId:i,subUnitId:a}=t;this._refreshSelection$.next({unitId:i,subUnitId:a,docRanges:e,isEditing:n,options:r})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;let n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);let{unitId:r,subUnitId:a,segmentId:o,style:s,textRanges:c,rectRanges:l,isEditing:u}=n,d=[...c,...l].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0);this._commandService.executeCommand(i.id,{unitId:r,subUnitId:a,segmentId:o,style:s,isEditing:u,ranges:d})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var t;if(e==null)return;let{unitId:n,subUnitId:r=``}=e;return(t=this._textSelectionInfo.get(n))==null?void 0:t.get(r)}_refresh(e){let t=this._getTextRanges(e);if(t==null)return;let{textRanges:n,rectRanges:r}=t,i=[...n,...r],{unitId:a,subUnitId:o}=e;this._refreshSelection$.next({unitId:a,subUnitId:o,docRanges:i,isEditing:!1})}_replaceByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...r})}_addByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);let i=this._textSelectionInfo.get(t);i.has(n)?i.get(n).textRanges.push(...e.textRanges):i.set(n,{...r})}};d=u([l(0,t.ICommandService),l(1,t.IUniverInstanceService)],d);let f=class extends t.RxDisposable{constructor(e,n,i){super(),this._context=e,this._localeService=n,this._univerInstanceService=i,c(this,`_skeleton`,void 0),c(this,`_docViewModel`,void 0),c(this,`_currentSkeleton$`,new r.BehaviorSubject(null)),c(this,`currentSkeleton$`,this._currentSkeleton$.asObservable()),c(this,`_currentSkeletonBefore$`,new r.BehaviorSubject(null)),c(this,`currentSkeletonBefore$`,this._currentSkeletonBefore$.asObservable()),c(this,`_currentViewModel$`,new r.BehaviorSubject(null)),c(this,`currentViewModel$`,this._currentViewModel$.asObservable()),this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{e&&e.getUnitId()===this._context.unitId&&this._update(e)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){let e=this._context.unit;this._update(e)}_update(e){let n=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&(0,t.isInternalEditorID)(n)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));let r=this._skeleton;r.calculate(),this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return n.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new n.DocumentViewModel(e)}};f=u([l(1,(0,t.Inject)(t.LocaleService)),l(2,t.IUniverInstanceService)],f);var p=class extends t.RxDisposable{constructor(){super(),c(this,`_docStateChangeParams$`,new r.BehaviorSubject(null)),c(this,`docStateChangeParams$`,this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};let m=`doc.mutation.rich-text-editing`,h={id:m,type:t.CommandType.MUTATION,handler:(e,r)=>{var i,a;let{unitId:o,segmentId:s=``,actions:c,textRanges:l,prevTextRanges:u,trigger:h,noHistory:g,isCompositionEnd:_,noNeedSetTextRange:v,debounce:y,isEditing:b=!0,isSync:x,syncer:S}=r,C=e.get(t.IUniverInstanceService),w=e.get(n.IRenderManagerService),T=e.get(p),E=C.getUniverDocInstance(o),D=(i=w.getRenderById(o))==null?void 0:i.with(f).getViewModel();if(E==null||D==null)throw Error(`DocumentDataModel or documentViewModel not found for unitId: ${o}`);let O=e.get(d),k=(a=O.getDocRanges())==null?[]:a,A=!!E.getSnapshot().disabled;if(t.JSONX.isNoop(c)||c&&c.length===0||A)return{unitId:o,actions:[],textRanges:k};let j=t.JSONX.invertWithDoc(c,E.getSnapshot());E.apply(c),D.reset(E),!v&&l&&h!=null&&!x&&queueMicrotask(()=>{O.replaceDocRanges(l,{unitId:o,subUnitId:o},b,r.options)});let M={commandId:m,unitId:o,segmentId:s,trigger:h,noHistory:g,debounce:y,redoState:{actions:c,textRanges:l},undoState:{actions:j,textRanges:u==null?k:u},isCompositionEnd:_,isSync:x,syncer:S};return T.emitStateChangeInfo(M),{unitId:o,actions:j,textRanges:k}}};var g=`@univerjs/docs`,_=`0.25.1`;let v={id:`doc.mutation.rename-doc`,type:t.CommandType.MUTATION,handler:(e,n)=>{let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);return r?(r.setName(n.name),!0):!1}},y={},b=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._initSelectionChange()}_transformCustomRange(e,n){var r;let{startOffset:i,endOffset:a,collapsed:o}=n,s=(r=e.getCustomRanges())==null?void 0:r.filter(e=>!e.wholeEntity||i<=e.startIndex&&a>e.endIndex?!1:o?e.startIndex<i&&e.endIndex>=a:t.BuildTextUtils.range.isIntersects(i,a-1,e.startIndex,e.endIndex));if(s!=null&&s.length){let e=i,t=a;return s.forEach(n=>{e=Math.min(n.startIndex,e),t=Math.max(n.endIndex+1,t)}),{...n,startOffset:e,endOffset:t,collapsed:e===t}}return n}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.id){let{unitId:t,ranges:n,isEditing:r}=e.params,i=this._univerInstanceService.getUnit(t);if(!i)return;let a=n.map(e=>this._transformCustomRange(i,e));a.some((e,t)=>n[t]!==e)&&this._textSelectionManagerService.replaceTextRanges(a,r)}}))}};b=u([l(0,t.ICommandService),l(1,(0,t.Inject)(d)),l(2,t.IUniverInstanceService)],b);let x=class extends t.Plugin{constructor(e=y,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},y,this._config);this._configService.setConfig(`docs.config`,i)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[h,v,i].forEach(e=>{this._injector.get(t.ICommandService).registerCommand(e)})}_initializeDependencies(){[[d],[p],[b]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(b)}};c(x,`pluginName`,`DOCS_PLUGIN`),c(x,`packageName`,g),c(x,`version`,_),x=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.IConfigService)],x);let S={CUSTOM_RANGE:(0,t.createInterceptorKey)(`CUSTOM_RANGE`),CUSTOM_DECORATION:(0,t.createInterceptorKey)(`CUSTOM_DECORATION`)},C=class extends t.Disposable{constructor(e,n){super(),this._context=e,this._docSkeletonManagerService=n,c(this,`_interceptorsByName`,new Map);let r=this._docSkeletonManagerService.getViewModel(),i=r.getDataModel().getUnitId();if(i===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(r)),this.disposeWithMe(this.intercept(S.CUSTOM_RANGE,{priority:-1,handler:(e,t,n)=>n(e)}));let a=new t.DisposableCollection;r.segmentViewModels$.subscribe(e=>{a.dispose(),a=new t.DisposableCollection,e.forEach(e=>{a.add(this.interceptDocumentViewModel(e))})}),this.disposeWithMe(a)}intercept(e,n){let r=e;this._interceptorsByName.has(r)||this._interceptorsByName.set(r,[]);let i=this._interceptorsByName.get(r);return i.push(n),this._interceptorsByName.set(r,i.sort((e,t)=>{var n,r;return((n=t.priority)==null?0:n)-((r=e.priority)==null?0:r)})),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._interceptorsByName.get(r),n)))}fetchThroughInterceptors(e){let n=e;return(0,t.composeInterceptors)(this._interceptorsByName.get(n)||[])}interceptDocumentViewModel(e){let n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:t=>{var n;return this.fetchThroughInterceptors(S.CUSTOM_RANGE)(e.getCustomRangeRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customRanges:(n=e.getDataModel().getCustomRanges())==null?[]:n})},getCustomDecoration:t=>{var n;return this.fetchThroughInterceptors(S.CUSTOM_DECORATION)(e.getCustomDecorationRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customDecorations:(n=e.getDataModel().getCustomDecorations())==null?[]:n})}})),n}};C=u([l(1,(0,t.Inject)(f))],C);function w(e,t=``){if(!t)return[`body`];let{headers:n,footers:r}=e.getSnapshot();if(n==null&&r==null)throw Error(`Document data model must have headers or footers when update by segment id`);if((n==null?void 0:n[t])!=null)return[`headers`,t,`body`];if((r==null?void 0:r[t])!=null)return[`footers`,t,`body`];throw Error(`Segment id not found in headers or footers`)}function T(e,n,r){let{unitId:i,segmentId:a}=n,o=e.get(t.IUniverInstanceService).getUnit(i);if(!o)return!1;let s={id:h.id,params:{unitId:n.unitId,actions:[],textRanges:void 0}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.add({...n,body:r});if(!l)return!1;let u=w(o,a);return s.params.actions=c.editOp(l.serialize(),u),s}function E(e,n){var r;let{rangeId:i,rangeType:a,wholeEntity:o,properties:s,unitId:c,selections:l}=n,u=e.get(d),f=e.get(t.IUniverInstanceService),p=l==null?u.getTextRanges({unitId:c,subUnitId:c}):l,m=p==null||(r=p[0])==null?void 0:r.segmentId;if(!(p!=null&&p.length))return!1;let g=f.getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(!g)return!1;let _=g.getSelfOrHeaderFooterModel(m).getBody();if(!_)return!1;let v=t.BuildTextUtils.customRange.add({ranges:p,rangeId:i,rangeType:a,segmentId:m,wholeEntity:o,properties:s,body:_});if(!v)return!1;let y=t.JSONX.getInstance(),b={id:h.id,params:{unitId:c,actions:[],textRanges:v.selections,segmentId:m},textX:v},x=w(g,m);return b.params.actions=y.editOp(v.serialize(),x),b}function D(e,n){let{unitId:r,segmentId:i,insert:a}=n,o=e.get(t.IUniverInstanceService).getUnit(r);if(!o)return!1;let s={id:h.id,params:{unitId:n.unitId,actions:[],textRanges:void 0,segmentId:i}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:n.rangeId,insert:a,segmentId:i});if(!l)return!1;let u=w(o,i);return s.params.actions=c.editOp(l.serialize(),u),s.params.textRanges=l.selections,s}function O(e,n){var r,i,a,o;let{unitId:s,body:c,doc:l}=n,u=l;if(u||(u=e.get(t.IUniverInstanceService).getUnit(s)),!u)return!1;let f=(r=n.selection)==null?void 0:r.segmentId,p=(i=u.getSelfOrHeaderFooterModel(f))==null?void 0:i.getBody();if(!p)return!1;let m=e.get(d),g=(a=n.selection)==null?m.getActiveTextRange():a;if(!g||!p)return!1;let _=(o=n.textRanges)==null?[{startOffset:g.startOffset+c.dataStream.length,endOffset:g.startOffset+c.dataStream.length,collapsed:!0,segmentId:f}]:o,v=t.BuildTextUtils.selection.replace({selection:g,body:c,doc:u});if(!v)return!1;let y={id:h.id,params:{unitId:s,actions:[],textRanges:_,debounce:!0,segmentId:f},textX:v},b=t.JSONX.getInstance();return y.params.actions=b.editOp(v.serialize()),y}e.DOC_INTERCEPTOR_POINT=S,Object.defineProperty(e,"DocInterceptorService",{enumerable:!0,get:function(){return C}}),Object.defineProperty(e,"DocSelectionManagerService",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"DocSkeletonManagerService",{enumerable:!0,get:function(){return f}}),e.DocStateEmitService=p,e.RichTextEditingMutation=h,e.SetTextSelectionsOperation=i,Object.defineProperty(e,"UniverDocsPlugin",{enumerable:!0,get:function(){return x}}),e.addCustomRangeBySelectionFactory=E,e.addCustomRangeFactory=T,e.deleteCustomRangeFactory=D,e.replaceSelectionFactory=O});
|