@univerjs/docs-toc-ui 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +36 -18
- package/lib/es/index.js +35 -21
- package/lib/index.js +35 -21
- package/lib/types/controllers/table-of-contents-ribbon.controller.d.ts +2 -2
- package/lib/types/index.d.ts +3 -1
- package/lib/types/menu/schema.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let _univerjs_docs_toc = require("@univerjs/docs-toc");
|
|
3
|
-
let _univerjs_ui = require("@univerjs/ui");
|
|
4
2
|
let _univerjs_core = require("@univerjs/core");
|
|
5
3
|
let _univerjs_design = require("@univerjs/design");
|
|
6
4
|
let _univerjs_docs = require("@univerjs/docs");
|
|
5
|
+
let _univerjs_docs_toc = require("@univerjs/docs-toc");
|
|
6
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
9
|
let _univerjs_docs_ui = require("@univerjs/docs-ui");
|
|
@@ -188,7 +188,8 @@ function showNoHeadingsMessage(accessor) {
|
|
|
188
188
|
}
|
|
189
189
|
async function insertTableOfContents(accessor, value, title) {
|
|
190
190
|
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
191
|
-
if (!doc ||
|
|
191
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL) return false;
|
|
192
|
+
if ((0, _univerjs_docs_toc.countTableOfContentsHeadings)(doc.getBody(), value.levels, doc.getSnapshot().styles) === 0) {
|
|
192
193
|
showNoHeadingsMessage(accessor);
|
|
193
194
|
return false;
|
|
194
195
|
}
|
|
@@ -207,7 +208,8 @@ const InsertTableOfContentsOperation = {
|
|
|
207
208
|
return insertTableOfContents(accessor, DEFAULT_INSERT_VALUE, title);
|
|
208
209
|
}
|
|
209
210
|
if ((params === null || params === void 0 ? void 0 : params.mode) !== "custom") return false;
|
|
210
|
-
|
|
211
|
+
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
212
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL) return false;
|
|
211
213
|
const confirmService = accessor.get(_univerjs_core.IConfirmService);
|
|
212
214
|
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
213
215
|
const state = { options: { ...DEFAULT_INSERT_VALUE } };
|
|
@@ -240,7 +242,7 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
240
242
|
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
241
243
|
const selection = accessor.get(_univerjs_docs.DocSelectionManagerService).getActiveTextRange();
|
|
242
244
|
const toc = (0, _univerjs_docs_toc.findTableOfContentsAtOffset)(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection === null || selection === void 0 ? void 0 : selection.startOffset);
|
|
243
|
-
if (!doc || !toc || ((_toc$properties = toc.properties) === null || _toc$properties === void 0 ? void 0 : _toc$properties.locked) === _univerjs_core.BooleanNumber.TRUE) return false;
|
|
245
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL || !toc || ((_toc$properties = toc.properties) === null || _toc$properties === void 0 ? void 0 : _toc$properties.locked) === _univerjs_core.BooleanNumber.TRUE) return false;
|
|
244
246
|
const confirmService = accessor.get(_univerjs_core.IConfirmService);
|
|
245
247
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
246
248
|
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
@@ -260,6 +262,7 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
260
262
|
} },
|
|
261
263
|
onConfirm: async () => {
|
|
262
264
|
try {
|
|
265
|
+
if (doc.getDocumentStyle().documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL) return;
|
|
263
266
|
await commandService.executeCommand(_univerjs_docs_toc.UpdateTableOfContentsCommand.id, {
|
|
264
267
|
unitId: doc.getUnitId(),
|
|
265
268
|
rangeId: toc.rangeId,
|
|
@@ -277,6 +280,13 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
277
280
|
|
|
278
281
|
// src/menu/menu.ts
|
|
279
282
|
const INSERT_TABLE_OF_CONTENTS_MENU_ID = "doc.menu.insert-table-of-contents";
|
|
283
|
+
function getTableOfContentsHiddenObservable(accessor) {
|
|
284
|
+
return (0, rxjs.combineLatest)([
|
|
285
|
+
(0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC),
|
|
286
|
+
accessor.get(_univerjs_core.IUniverInstanceService).getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC),
|
|
287
|
+
accessor.get(_univerjs_docs.DocStateChangeManagerService).docStateChange$.pipe((0, rxjs.startWith)(null))
|
|
288
|
+
]).pipe((0, rxjs.map)(([hidden, doc]) => hidden || (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== _univerjs_core.DocumentFlavor.TRADITIONAL), (0, rxjs.distinctUntilChanged)());
|
|
289
|
+
}
|
|
280
290
|
function getActiveTableOfContentsObservable(accessor) {
|
|
281
291
|
const selectionManager = accessor.get(_univerjs_docs.DocSelectionManagerService);
|
|
282
292
|
const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
@@ -284,7 +294,7 @@ function getActiveTableOfContentsObservable(accessor) {
|
|
|
284
294
|
const emit = () => {
|
|
285
295
|
const doc = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
286
296
|
const selection = selectionManager.getActiveTextRange();
|
|
287
|
-
subscriber.next((
|
|
297
|
+
subscriber.next((doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== _univerjs_core.DocumentFlavor.TRADITIONAL || (selection === null || selection === void 0 ? void 0 : selection.segmentId) ? void 0 : (0, _univerjs_docs_toc.findTableOfContentsAtOffset)(doc.getBody(), selection === null || selection === void 0 ? void 0 : selection.startOffset));
|
|
288
298
|
};
|
|
289
299
|
emit();
|
|
290
300
|
const selectionSubscription = selectionManager.textSelection$.subscribe(emit);
|
|
@@ -304,14 +314,16 @@ function getInsertTableOfContentsDisabledObservable(accessor) {
|
|
|
304
314
|
const emit = () => {
|
|
305
315
|
const doc = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
306
316
|
const selection = selectionManager.getActiveTextRange();
|
|
307
|
-
subscriber.next(!selection || selection.startOffset !== selection.endOffset || Boolean(selection.segmentId) || Boolean((0, _univerjs_docs_toc.findTableOfContentsAtOffset)(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection.startOffset)));
|
|
317
|
+
subscriber.next((doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== _univerjs_core.DocumentFlavor.TRADITIONAL || !selection || selection.startOffset !== selection.endOffset || Boolean(selection.segmentId) || Boolean((0, _univerjs_docs_toc.findTableOfContentsAtOffset)(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection.startOffset)));
|
|
308
318
|
};
|
|
309
319
|
emit();
|
|
310
320
|
const selectionSubscription = selectionManager.textSelection$.subscribe(emit);
|
|
311
321
|
const unitSubscription = instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).subscribe(emit);
|
|
322
|
+
const documentSubscription = accessor.get(_univerjs_docs.DocStateChangeManagerService).docStateChange$.subscribe(emit);
|
|
312
323
|
return () => {
|
|
313
324
|
selectionSubscription.unsubscribe();
|
|
314
325
|
unitSubscription.unsubscribe();
|
|
326
|
+
documentSubscription.unsubscribe();
|
|
315
327
|
};
|
|
316
328
|
});
|
|
317
329
|
}
|
|
@@ -335,7 +347,7 @@ function InsertTableOfContentsMenuFactory(accessor) {
|
|
|
335
347
|
params: { mode: "custom" }
|
|
336
348
|
}],
|
|
337
349
|
disabled$: (0, rxjs.combineLatest)([permissionDisabled$, getInsertTableOfContentsDisabledObservable(accessor)]).pipe((0, rxjs.map)(([permissionDisabled, unavailable]) => permissionDisabled || unavailable)),
|
|
338
|
-
hidden$: (
|
|
350
|
+
hidden$: getTableOfContentsHiddenObservable(accessor)
|
|
339
351
|
};
|
|
340
352
|
}
|
|
341
353
|
function UpdateTableOfContentsMenuFactory(accessor) {
|
|
@@ -419,21 +431,21 @@ const DocsTocUIMenuSchema = {
|
|
|
419
431
|
|
|
420
432
|
// package.json
|
|
421
433
|
var name = "@univerjs/docs-toc-ui";
|
|
422
|
-
var version = "1.
|
|
434
|
+
var version = "1.6.0";
|
|
423
435
|
|
|
424
436
|
// src/config/config.ts
|
|
425
437
|
const DOCS_TOC_UI_PLUGIN_CONFIG_KEY = "docs-toc-ui.config";
|
|
426
438
|
const configSymbol = Symbol(DOCS_TOC_UI_PLUGIN_CONFIG_KEY);
|
|
427
439
|
const defaultPluginConfig = {};
|
|
428
440
|
|
|
429
|
-
// \0@oxc-project+runtime@0.
|
|
441
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
430
442
|
function __decorateParam(paramIndex, decorator) {
|
|
431
443
|
return function(target, key) {
|
|
432
444
|
decorator(target, key, paramIndex);
|
|
433
445
|
};
|
|
434
446
|
}
|
|
435
447
|
|
|
436
|
-
// \0@oxc-project+runtime@0.
|
|
448
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
437
449
|
function __decorate(decorators, target, key, desc) {
|
|
438
450
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
439
451
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -466,7 +478,7 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
|
|
|
466
478
|
};
|
|
467
479
|
ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))], ComponentsController);
|
|
468
480
|
|
|
469
|
-
// \0@oxc-project+runtime@0.
|
|
481
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
470
482
|
function _typeof(o) {
|
|
471
483
|
"@babel/helpers - typeof";
|
|
472
484
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -476,7 +488,7 @@ function _typeof(o) {
|
|
|
476
488
|
}, _typeof(o);
|
|
477
489
|
}
|
|
478
490
|
|
|
479
|
-
// \0@oxc-project+runtime@0.
|
|
491
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
480
492
|
function toPrimitive(t, e) {
|
|
481
493
|
if ("object" != _typeof(t) || !t) return t;
|
|
482
494
|
var r;
|
|
@@ -488,13 +500,13 @@ function toPrimitive(t, e) {
|
|
|
488
500
|
return ("string" === e ? String : Number)(t);
|
|
489
501
|
}
|
|
490
502
|
|
|
491
|
-
// \0@oxc-project+runtime@0.
|
|
503
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
492
504
|
function toPropertyKey(t) {
|
|
493
505
|
var i = toPrimitive(t, "string");
|
|
494
506
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
495
507
|
}
|
|
496
508
|
|
|
497
|
-
// \0@oxc-project+runtime@0.
|
|
509
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
498
510
|
function _defineProperty(e, r, t) {
|
|
499
511
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
500
512
|
value: t,
|
|
@@ -612,20 +624,21 @@ function getPointGroupBounds(pointsGroup) {
|
|
|
612
624
|
|
|
613
625
|
// src/controllers/table-of-contents-ribbon.controller.ts
|
|
614
626
|
let TableOfContentsRibbonController = class TableOfContentsRibbonController extends _univerjs_core.Disposable {
|
|
615
|
-
constructor(_instanceService, _selectionManager, _ribbonService) {
|
|
627
|
+
constructor(_instanceService, _selectionManager, changes, _ribbonService) {
|
|
616
628
|
super();
|
|
617
629
|
this._instanceService = _instanceService;
|
|
618
630
|
this._selectionManager = _selectionManager;
|
|
619
631
|
this._ribbonService = _ribbonService;
|
|
620
632
|
_defineProperty(this, "_visible", false);
|
|
621
633
|
this.disposeWithMe(this._selectionManager.textSelection$.subscribe(() => this._update()));
|
|
634
|
+
this.disposeWithMe(changes.docStateChange$.subscribe(() => this._update()));
|
|
622
635
|
this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).subscribe(() => this._update()));
|
|
623
636
|
this._update();
|
|
624
637
|
}
|
|
625
638
|
_update() {
|
|
626
639
|
const doc = this._instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
627
640
|
const selection = this._selectionManager.getActiveTextRange();
|
|
628
|
-
const visible = Boolean(doc && selection && !selection.segmentId && (0, _univerjs_docs_toc.findTableOfContentsAtOffset)(doc.getBody(), selection.startOffset));
|
|
641
|
+
const visible = Boolean(doc && doc.getDocumentStyle().documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL && selection && !selection.segmentId && (0, _univerjs_docs_toc.findTableOfContentsAtOffset)(doc.getBody(), selection.startOffset));
|
|
629
642
|
if (visible === this._visible) return;
|
|
630
643
|
this._visible = visible;
|
|
631
644
|
if (visible) this._ribbonService.showContextualTab(DOC_TABLE_OF_CONTENTS_RIBBON_TAB, { activate: true });
|
|
@@ -639,7 +652,8 @@ let TableOfContentsRibbonController = class TableOfContentsRibbonController exte
|
|
|
639
652
|
TableOfContentsRibbonController = __decorate([
|
|
640
653
|
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
641
654
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
|
|
642
|
-
__decorateParam(2,
|
|
655
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_docs.DocStateChangeManagerService)),
|
|
656
|
+
__decorateParam(3, _univerjs_ui.IRibbonService)
|
|
643
657
|
], TableOfContentsRibbonController);
|
|
644
658
|
|
|
645
659
|
// src/controllers/ui.controller.ts
|
|
@@ -708,7 +722,11 @@ UniverDocsTocUIPlugin = __decorate([
|
|
|
708
722
|
__decorateParam(3, _univerjs_engine_render.IRenderManagerService)
|
|
709
723
|
], UniverDocsTocUIPlugin);
|
|
710
724
|
|
|
725
|
+
exports.DOC_TABLE_OF_CONTENTS_RIBBON_GROUP = DOC_TABLE_OF_CONTENTS_RIBBON_GROUP;
|
|
726
|
+
exports.DOC_TABLE_OF_CONTENTS_RIBBON_TAB = DOC_TABLE_OF_CONTENTS_RIBBON_TAB;
|
|
711
727
|
exports.DocsTocUIMenuSchema = DocsTocUIMenuSchema;
|
|
728
|
+
exports.InsertTableOfContentsMenuFactory = InsertTableOfContentsMenuFactory;
|
|
729
|
+
exports.OpenTableOfContentsDialogOperation = OpenTableOfContentsDialogOperation;
|
|
712
730
|
Object.defineProperty(exports, "UniverDocsTocUIPlugin", {
|
|
713
731
|
enumerable: true,
|
|
714
732
|
get: function () {
|
package/lib/es/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IRibbonService, MenuItemType, MenuManagerPosition, RibbonInsertGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
3
|
-
import { BooleanNumber, ColorKit, CommandType, DependentOn, Disposable, ICommandService, IConfigService, IConfirmService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RxDisposable, ThemeService, UniverInstanceType, generateRandomId, merge } from "@univerjs/core";
|
|
1
|
+
import { BooleanNumber, ColorKit, CommandType, DependentOn, Disposable, DocumentFlavor, ICommandService, IConfigService, IConfirmService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RxDisposable, ThemeService, UniverInstanceType, generateRandomId, merge } from "@univerjs/core";
|
|
4
2
|
import { Checkbox, MessageType, Radio, RadioGroup, Select, clsx } from "@univerjs/design";
|
|
5
3
|
import { DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, UniverDocsPlugin } from "@univerjs/docs";
|
|
4
|
+
import { DeleteTableOfContentsCommand, InsertTableOfContentsCommand, UniverDocsTocPlugin, UpdateTableOfContentsCommand, countTableOfContentsHeadings, findTableOfContentsAtOffset } from "@univerjs/docs-toc";
|
|
5
|
+
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IRibbonService, MenuItemType, MenuManagerPosition, RibbonInsertGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { NodePositionConvertToCursor, TEXT_RANGE_LAYER_INDEX, UniverDocsUIPlugin, disableMenuWithoutDocumentUnitPermission } from "@univerjs/docs-ui";
|
|
9
9
|
import { UnitAction } from "@univerjs/protocol";
|
|
10
|
-
import { Observable, combineLatest, map, takeUntil } from "rxjs";
|
|
10
|
+
import { Observable, combineLatest, distinctUntilChanged, map, startWith, takeUntil } from "rxjs";
|
|
11
11
|
import { IRenderManagerService, Rect, RegularPolygon, UniverRenderEnginePlugin } from "@univerjs/engine-render";
|
|
12
12
|
|
|
13
13
|
// src/views/InsertTableOfContentsDialog.tsx
|
|
@@ -187,7 +187,8 @@ function showNoHeadingsMessage(accessor) {
|
|
|
187
187
|
}
|
|
188
188
|
async function insertTableOfContents(accessor, value, title) {
|
|
189
189
|
const doc = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
190
|
-
if (!doc ||
|
|
190
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
|
|
191
|
+
if (countTableOfContentsHeadings(doc.getBody(), value.levels, doc.getSnapshot().styles) === 0) {
|
|
191
192
|
showNoHeadingsMessage(accessor);
|
|
192
193
|
return false;
|
|
193
194
|
}
|
|
@@ -206,7 +207,8 @@ const InsertTableOfContentsOperation = {
|
|
|
206
207
|
return insertTableOfContents(accessor, DEFAULT_INSERT_VALUE, title);
|
|
207
208
|
}
|
|
208
209
|
if ((params === null || params === void 0 ? void 0 : params.mode) !== "custom") return false;
|
|
209
|
-
|
|
210
|
+
const doc = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
211
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
|
|
210
212
|
const confirmService = accessor.get(IConfirmService);
|
|
211
213
|
const localeService = accessor.get(LocaleService);
|
|
212
214
|
const state = { options: { ...DEFAULT_INSERT_VALUE } };
|
|
@@ -239,7 +241,7 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
239
241
|
const doc = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
240
242
|
const selection = accessor.get(DocSelectionManagerService).getActiveTextRange();
|
|
241
243
|
const toc = findTableOfContentsAtOffset(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection === null || selection === void 0 ? void 0 : selection.startOffset);
|
|
242
|
-
if (!doc || !toc || ((_toc$properties = toc.properties) === null || _toc$properties === void 0 ? void 0 : _toc$properties.locked) === BooleanNumber.TRUE) return false;
|
|
244
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL || !toc || ((_toc$properties = toc.properties) === null || _toc$properties === void 0 ? void 0 : _toc$properties.locked) === BooleanNumber.TRUE) return false;
|
|
243
245
|
const confirmService = accessor.get(IConfirmService);
|
|
244
246
|
const commandService = accessor.get(ICommandService);
|
|
245
247
|
const localeService = accessor.get(LocaleService);
|
|
@@ -259,6 +261,7 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
259
261
|
} },
|
|
260
262
|
onConfirm: async () => {
|
|
261
263
|
try {
|
|
264
|
+
if (doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return;
|
|
262
265
|
await commandService.executeCommand(UpdateTableOfContentsCommand.id, {
|
|
263
266
|
unitId: doc.getUnitId(),
|
|
264
267
|
rangeId: toc.rangeId,
|
|
@@ -276,6 +279,13 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
276
279
|
|
|
277
280
|
// src/menu/menu.ts
|
|
278
281
|
const INSERT_TABLE_OF_CONTENTS_MENU_ID = "doc.menu.insert-table-of-contents";
|
|
282
|
+
function getTableOfContentsHiddenObservable(accessor) {
|
|
283
|
+
return combineLatest([
|
|
284
|
+
getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
285
|
+
accessor.get(IUniverInstanceService).getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC),
|
|
286
|
+
accessor.get(DocStateChangeManagerService).docStateChange$.pipe(startWith(null))
|
|
287
|
+
]).pipe(map(([hidden, doc]) => hidden || (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== DocumentFlavor.TRADITIONAL), distinctUntilChanged());
|
|
288
|
+
}
|
|
279
289
|
function getActiveTableOfContentsObservable(accessor) {
|
|
280
290
|
const selectionManager = accessor.get(DocSelectionManagerService);
|
|
281
291
|
const instanceService = accessor.get(IUniverInstanceService);
|
|
@@ -283,7 +293,7 @@ function getActiveTableOfContentsObservable(accessor) {
|
|
|
283
293
|
const emit = () => {
|
|
284
294
|
const doc = instanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
285
295
|
const selection = selectionManager.getActiveTextRange();
|
|
286
|
-
subscriber.next((
|
|
296
|
+
subscriber.next((doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== DocumentFlavor.TRADITIONAL || (selection === null || selection === void 0 ? void 0 : selection.segmentId) ? void 0 : findTableOfContentsAtOffset(doc.getBody(), selection === null || selection === void 0 ? void 0 : selection.startOffset));
|
|
287
297
|
};
|
|
288
298
|
emit();
|
|
289
299
|
const selectionSubscription = selectionManager.textSelection$.subscribe(emit);
|
|
@@ -303,14 +313,16 @@ function getInsertTableOfContentsDisabledObservable(accessor) {
|
|
|
303
313
|
const emit = () => {
|
|
304
314
|
const doc = instanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
305
315
|
const selection = selectionManager.getActiveTextRange();
|
|
306
|
-
subscriber.next(!selection || selection.startOffset !== selection.endOffset || Boolean(selection.segmentId) || Boolean(findTableOfContentsAtOffset(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection.startOffset)));
|
|
316
|
+
subscriber.next((doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== DocumentFlavor.TRADITIONAL || !selection || selection.startOffset !== selection.endOffset || Boolean(selection.segmentId) || Boolean(findTableOfContentsAtOffset(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection.startOffset)));
|
|
307
317
|
};
|
|
308
318
|
emit();
|
|
309
319
|
const selectionSubscription = selectionManager.textSelection$.subscribe(emit);
|
|
310
320
|
const unitSubscription = instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).subscribe(emit);
|
|
321
|
+
const documentSubscription = accessor.get(DocStateChangeManagerService).docStateChange$.subscribe(emit);
|
|
311
322
|
return () => {
|
|
312
323
|
selectionSubscription.unsubscribe();
|
|
313
324
|
unitSubscription.unsubscribe();
|
|
325
|
+
documentSubscription.unsubscribe();
|
|
314
326
|
};
|
|
315
327
|
});
|
|
316
328
|
}
|
|
@@ -334,7 +346,7 @@ function InsertTableOfContentsMenuFactory(accessor) {
|
|
|
334
346
|
params: { mode: "custom" }
|
|
335
347
|
}],
|
|
336
348
|
disabled$: combineLatest([permissionDisabled$, getInsertTableOfContentsDisabledObservable(accessor)]).pipe(map(([permissionDisabled, unavailable]) => permissionDisabled || unavailable)),
|
|
337
|
-
hidden$:
|
|
349
|
+
hidden$: getTableOfContentsHiddenObservable(accessor)
|
|
338
350
|
};
|
|
339
351
|
}
|
|
340
352
|
function UpdateTableOfContentsMenuFactory(accessor) {
|
|
@@ -418,21 +430,21 @@ const DocsTocUIMenuSchema = {
|
|
|
418
430
|
|
|
419
431
|
// package.json
|
|
420
432
|
var name = "@univerjs/docs-toc-ui";
|
|
421
|
-
var version = "1.
|
|
433
|
+
var version = "1.6.0";
|
|
422
434
|
|
|
423
435
|
// src/config/config.ts
|
|
424
436
|
const DOCS_TOC_UI_PLUGIN_CONFIG_KEY = "docs-toc-ui.config";
|
|
425
437
|
const configSymbol = Symbol(DOCS_TOC_UI_PLUGIN_CONFIG_KEY);
|
|
426
438
|
const defaultPluginConfig = {};
|
|
427
439
|
|
|
428
|
-
// \0@oxc-project+runtime@0.
|
|
440
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
429
441
|
function __decorateParam(paramIndex, decorator) {
|
|
430
442
|
return function(target, key) {
|
|
431
443
|
decorator(target, key, paramIndex);
|
|
432
444
|
};
|
|
433
445
|
}
|
|
434
446
|
|
|
435
|
-
// \0@oxc-project+runtime@0.
|
|
447
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
436
448
|
function __decorate(decorators, target, key, desc) {
|
|
437
449
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
438
450
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -465,7 +477,7 @@ let ComponentsController = class ComponentsController extends Disposable {
|
|
|
465
477
|
};
|
|
466
478
|
ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))], ComponentsController);
|
|
467
479
|
|
|
468
|
-
// \0@oxc-project+runtime@0.
|
|
480
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
469
481
|
function _typeof(o) {
|
|
470
482
|
"@babel/helpers - typeof";
|
|
471
483
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -475,7 +487,7 @@ function _typeof(o) {
|
|
|
475
487
|
}, _typeof(o);
|
|
476
488
|
}
|
|
477
489
|
|
|
478
|
-
// \0@oxc-project+runtime@0.
|
|
490
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
479
491
|
function toPrimitive(t, e) {
|
|
480
492
|
if ("object" != _typeof(t) || !t) return t;
|
|
481
493
|
var r;
|
|
@@ -487,13 +499,13 @@ function toPrimitive(t, e) {
|
|
|
487
499
|
return ("string" === e ? String : Number)(t);
|
|
488
500
|
}
|
|
489
501
|
|
|
490
|
-
// \0@oxc-project+runtime@0.
|
|
502
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
491
503
|
function toPropertyKey(t) {
|
|
492
504
|
var i = toPrimitive(t, "string");
|
|
493
505
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
494
506
|
}
|
|
495
507
|
|
|
496
|
-
// \0@oxc-project+runtime@0.
|
|
508
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
497
509
|
function _defineProperty(e, r, t) {
|
|
498
510
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
499
511
|
value: t,
|
|
@@ -611,20 +623,21 @@ function getPointGroupBounds(pointsGroup) {
|
|
|
611
623
|
|
|
612
624
|
// src/controllers/table-of-contents-ribbon.controller.ts
|
|
613
625
|
let TableOfContentsRibbonController = class TableOfContentsRibbonController extends Disposable {
|
|
614
|
-
constructor(_instanceService, _selectionManager, _ribbonService) {
|
|
626
|
+
constructor(_instanceService, _selectionManager, changes, _ribbonService) {
|
|
615
627
|
super();
|
|
616
628
|
this._instanceService = _instanceService;
|
|
617
629
|
this._selectionManager = _selectionManager;
|
|
618
630
|
this._ribbonService = _ribbonService;
|
|
619
631
|
_defineProperty(this, "_visible", false);
|
|
620
632
|
this.disposeWithMe(this._selectionManager.textSelection$.subscribe(() => this._update()));
|
|
633
|
+
this.disposeWithMe(changes.docStateChange$.subscribe(() => this._update()));
|
|
621
634
|
this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).subscribe(() => this._update()));
|
|
622
635
|
this._update();
|
|
623
636
|
}
|
|
624
637
|
_update() {
|
|
625
638
|
const doc = this._instanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
626
639
|
const selection = this._selectionManager.getActiveTextRange();
|
|
627
|
-
const visible = Boolean(doc && selection && !selection.segmentId && findTableOfContentsAtOffset(doc.getBody(), selection.startOffset));
|
|
640
|
+
const visible = Boolean(doc && doc.getDocumentStyle().documentFlavor === DocumentFlavor.TRADITIONAL && selection && !selection.segmentId && findTableOfContentsAtOffset(doc.getBody(), selection.startOffset));
|
|
628
641
|
if (visible === this._visible) return;
|
|
629
642
|
this._visible = visible;
|
|
630
643
|
if (visible) this._ribbonService.showContextualTab(DOC_TABLE_OF_CONTENTS_RIBBON_TAB, { activate: true });
|
|
@@ -638,7 +651,8 @@ let TableOfContentsRibbonController = class TableOfContentsRibbonController exte
|
|
|
638
651
|
TableOfContentsRibbonController = __decorate([
|
|
639
652
|
__decorateParam(0, IUniverInstanceService),
|
|
640
653
|
__decorateParam(1, Inject(DocSelectionManagerService)),
|
|
641
|
-
__decorateParam(2,
|
|
654
|
+
__decorateParam(2, Inject(DocStateChangeManagerService)),
|
|
655
|
+
__decorateParam(3, IRibbonService)
|
|
642
656
|
], TableOfContentsRibbonController);
|
|
643
657
|
|
|
644
658
|
// src/controllers/ui.controller.ts
|
|
@@ -707,4 +721,4 @@ UniverDocsTocUIPlugin = __decorate([
|
|
|
707
721
|
__decorateParam(3, IRenderManagerService)
|
|
708
722
|
], UniverDocsTocUIPlugin);
|
|
709
723
|
|
|
710
|
-
export { DocsTocUIMenuSchema, UniverDocsTocUIPlugin };
|
|
724
|
+
export { DOC_TABLE_OF_CONTENTS_RIBBON_GROUP, DOC_TABLE_OF_CONTENTS_RIBBON_TAB, DocsTocUIMenuSchema, InsertTableOfContentsMenuFactory, OpenTableOfContentsDialogOperation, UniverDocsTocUIPlugin };
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IRibbonService, MenuItemType, MenuManagerPosition, RibbonInsertGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
3
|
-
import { BooleanNumber, ColorKit, CommandType, DependentOn, Disposable, ICommandService, IConfigService, IConfirmService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RxDisposable, ThemeService, UniverInstanceType, generateRandomId, merge } from "@univerjs/core";
|
|
1
|
+
import { BooleanNumber, ColorKit, CommandType, DependentOn, Disposable, DocumentFlavor, ICommandService, IConfigService, IConfirmService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RxDisposable, ThemeService, UniverInstanceType, generateRandomId, merge } from "@univerjs/core";
|
|
4
2
|
import { Checkbox, MessageType, Radio, RadioGroup, Select, clsx } from "@univerjs/design";
|
|
5
3
|
import { DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, UniverDocsPlugin } from "@univerjs/docs";
|
|
4
|
+
import { DeleteTableOfContentsCommand, InsertTableOfContentsCommand, UniverDocsTocPlugin, UpdateTableOfContentsCommand, countTableOfContentsHeadings, findTableOfContentsAtOffset } from "@univerjs/docs-toc";
|
|
5
|
+
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IRibbonService, MenuItemType, MenuManagerPosition, RibbonInsertGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { NodePositionConvertToCursor, TEXT_RANGE_LAYER_INDEX, UniverDocsUIPlugin, disableMenuWithoutDocumentUnitPermission } from "@univerjs/docs-ui";
|
|
9
9
|
import { UnitAction } from "@univerjs/protocol";
|
|
10
|
-
import { Observable, combineLatest, map, takeUntil } from "rxjs";
|
|
10
|
+
import { Observable, combineLatest, distinctUntilChanged, map, startWith, takeUntil } from "rxjs";
|
|
11
11
|
import { IRenderManagerService, Rect, RegularPolygon, UniverRenderEnginePlugin } from "@univerjs/engine-render";
|
|
12
12
|
|
|
13
13
|
// src/views/InsertTableOfContentsDialog.tsx
|
|
@@ -187,7 +187,8 @@ function showNoHeadingsMessage(accessor) {
|
|
|
187
187
|
}
|
|
188
188
|
async function insertTableOfContents(accessor, value, title) {
|
|
189
189
|
const doc = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
190
|
-
if (!doc ||
|
|
190
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
|
|
191
|
+
if (countTableOfContentsHeadings(doc.getBody(), value.levels, doc.getSnapshot().styles) === 0) {
|
|
191
192
|
showNoHeadingsMessage(accessor);
|
|
192
193
|
return false;
|
|
193
194
|
}
|
|
@@ -206,7 +207,8 @@ const InsertTableOfContentsOperation = {
|
|
|
206
207
|
return insertTableOfContents(accessor, DEFAULT_INSERT_VALUE, title);
|
|
207
208
|
}
|
|
208
209
|
if ((params === null || params === void 0 ? void 0 : params.mode) !== "custom") return false;
|
|
209
|
-
|
|
210
|
+
const doc = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
211
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
|
|
210
212
|
const confirmService = accessor.get(IConfirmService);
|
|
211
213
|
const localeService = accessor.get(LocaleService);
|
|
212
214
|
const state = { options: { ...DEFAULT_INSERT_VALUE } };
|
|
@@ -239,7 +241,7 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
239
241
|
const doc = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
240
242
|
const selection = accessor.get(DocSelectionManagerService).getActiveTextRange();
|
|
241
243
|
const toc = findTableOfContentsAtOffset(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection === null || selection === void 0 ? void 0 : selection.startOffset);
|
|
242
|
-
if (!doc || !toc || ((_toc$properties = toc.properties) === null || _toc$properties === void 0 ? void 0 : _toc$properties.locked) === BooleanNumber.TRUE) return false;
|
|
244
|
+
if (!doc || doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL || !toc || ((_toc$properties = toc.properties) === null || _toc$properties === void 0 ? void 0 : _toc$properties.locked) === BooleanNumber.TRUE) return false;
|
|
243
245
|
const confirmService = accessor.get(IConfirmService);
|
|
244
246
|
const commandService = accessor.get(ICommandService);
|
|
245
247
|
const localeService = accessor.get(LocaleService);
|
|
@@ -259,6 +261,7 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
259
261
|
} },
|
|
260
262
|
onConfirm: async () => {
|
|
261
263
|
try {
|
|
264
|
+
if (doc.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return;
|
|
262
265
|
await commandService.executeCommand(UpdateTableOfContentsCommand.id, {
|
|
263
266
|
unitId: doc.getUnitId(),
|
|
264
267
|
rangeId: toc.rangeId,
|
|
@@ -276,6 +279,13 @@ const OpenTableOfContentsDialogOperation = {
|
|
|
276
279
|
|
|
277
280
|
// src/menu/menu.ts
|
|
278
281
|
const INSERT_TABLE_OF_CONTENTS_MENU_ID = "doc.menu.insert-table-of-contents";
|
|
282
|
+
function getTableOfContentsHiddenObservable(accessor) {
|
|
283
|
+
return combineLatest([
|
|
284
|
+
getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
285
|
+
accessor.get(IUniverInstanceService).getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC),
|
|
286
|
+
accessor.get(DocStateChangeManagerService).docStateChange$.pipe(startWith(null))
|
|
287
|
+
]).pipe(map(([hidden, doc]) => hidden || (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== DocumentFlavor.TRADITIONAL), distinctUntilChanged());
|
|
288
|
+
}
|
|
279
289
|
function getActiveTableOfContentsObservable(accessor) {
|
|
280
290
|
const selectionManager = accessor.get(DocSelectionManagerService);
|
|
281
291
|
const instanceService = accessor.get(IUniverInstanceService);
|
|
@@ -283,7 +293,7 @@ function getActiveTableOfContentsObservable(accessor) {
|
|
|
283
293
|
const emit = () => {
|
|
284
294
|
const doc = instanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
285
295
|
const selection = selectionManager.getActiveTextRange();
|
|
286
|
-
subscriber.next((
|
|
296
|
+
subscriber.next((doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== DocumentFlavor.TRADITIONAL || (selection === null || selection === void 0 ? void 0 : selection.segmentId) ? void 0 : findTableOfContentsAtOffset(doc.getBody(), selection === null || selection === void 0 ? void 0 : selection.startOffset));
|
|
287
297
|
};
|
|
288
298
|
emit();
|
|
289
299
|
const selectionSubscription = selectionManager.textSelection$.subscribe(emit);
|
|
@@ -303,14 +313,16 @@ function getInsertTableOfContentsDisabledObservable(accessor) {
|
|
|
303
313
|
const emit = () => {
|
|
304
314
|
const doc = instanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
305
315
|
const selection = selectionManager.getActiveTextRange();
|
|
306
|
-
subscriber.next(!selection || selection.startOffset !== selection.endOffset || Boolean(selection.segmentId) || Boolean(findTableOfContentsAtOffset(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection.startOffset)));
|
|
316
|
+
subscriber.next((doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) !== DocumentFlavor.TRADITIONAL || !selection || selection.startOffset !== selection.endOffset || Boolean(selection.segmentId) || Boolean(findTableOfContentsAtOffset(doc === null || doc === void 0 ? void 0 : doc.getBody(), selection.startOffset)));
|
|
307
317
|
};
|
|
308
318
|
emit();
|
|
309
319
|
const selectionSubscription = selectionManager.textSelection$.subscribe(emit);
|
|
310
320
|
const unitSubscription = instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).subscribe(emit);
|
|
321
|
+
const documentSubscription = accessor.get(DocStateChangeManagerService).docStateChange$.subscribe(emit);
|
|
311
322
|
return () => {
|
|
312
323
|
selectionSubscription.unsubscribe();
|
|
313
324
|
unitSubscription.unsubscribe();
|
|
325
|
+
documentSubscription.unsubscribe();
|
|
314
326
|
};
|
|
315
327
|
});
|
|
316
328
|
}
|
|
@@ -334,7 +346,7 @@ function InsertTableOfContentsMenuFactory(accessor) {
|
|
|
334
346
|
params: { mode: "custom" }
|
|
335
347
|
}],
|
|
336
348
|
disabled$: combineLatest([permissionDisabled$, getInsertTableOfContentsDisabledObservable(accessor)]).pipe(map(([permissionDisabled, unavailable]) => permissionDisabled || unavailable)),
|
|
337
|
-
hidden$:
|
|
349
|
+
hidden$: getTableOfContentsHiddenObservable(accessor)
|
|
338
350
|
};
|
|
339
351
|
}
|
|
340
352
|
function UpdateTableOfContentsMenuFactory(accessor) {
|
|
@@ -418,21 +430,21 @@ const DocsTocUIMenuSchema = {
|
|
|
418
430
|
|
|
419
431
|
// package.json
|
|
420
432
|
var name = "@univerjs/docs-toc-ui";
|
|
421
|
-
var version = "1.
|
|
433
|
+
var version = "1.6.0";
|
|
422
434
|
|
|
423
435
|
// src/config/config.ts
|
|
424
436
|
const DOCS_TOC_UI_PLUGIN_CONFIG_KEY = "docs-toc-ui.config";
|
|
425
437
|
const configSymbol = Symbol(DOCS_TOC_UI_PLUGIN_CONFIG_KEY);
|
|
426
438
|
const defaultPluginConfig = {};
|
|
427
439
|
|
|
428
|
-
// \0@oxc-project+runtime@0.
|
|
440
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
429
441
|
function __decorateParam(paramIndex, decorator) {
|
|
430
442
|
return function(target, key) {
|
|
431
443
|
decorator(target, key, paramIndex);
|
|
432
444
|
};
|
|
433
445
|
}
|
|
434
446
|
|
|
435
|
-
// \0@oxc-project+runtime@0.
|
|
447
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
436
448
|
function __decorate(decorators, target, key, desc) {
|
|
437
449
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
438
450
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -465,7 +477,7 @@ let ComponentsController = class ComponentsController extends Disposable {
|
|
|
465
477
|
};
|
|
466
478
|
ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))], ComponentsController);
|
|
467
479
|
|
|
468
|
-
// \0@oxc-project+runtime@0.
|
|
480
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
469
481
|
function _typeof(o) {
|
|
470
482
|
"@babel/helpers - typeof";
|
|
471
483
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -475,7 +487,7 @@ function _typeof(o) {
|
|
|
475
487
|
}, _typeof(o);
|
|
476
488
|
}
|
|
477
489
|
|
|
478
|
-
// \0@oxc-project+runtime@0.
|
|
490
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
479
491
|
function toPrimitive(t, e) {
|
|
480
492
|
if ("object" != _typeof(t) || !t) return t;
|
|
481
493
|
var r;
|
|
@@ -487,13 +499,13 @@ function toPrimitive(t, e) {
|
|
|
487
499
|
return ("string" === e ? String : Number)(t);
|
|
488
500
|
}
|
|
489
501
|
|
|
490
|
-
// \0@oxc-project+runtime@0.
|
|
502
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
491
503
|
function toPropertyKey(t) {
|
|
492
504
|
var i = toPrimitive(t, "string");
|
|
493
505
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
494
506
|
}
|
|
495
507
|
|
|
496
|
-
// \0@oxc-project+runtime@0.
|
|
508
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
497
509
|
function _defineProperty(e, r, t) {
|
|
498
510
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
499
511
|
value: t,
|
|
@@ -611,20 +623,21 @@ function getPointGroupBounds(pointsGroup) {
|
|
|
611
623
|
|
|
612
624
|
// src/controllers/table-of-contents-ribbon.controller.ts
|
|
613
625
|
let TableOfContentsRibbonController = class TableOfContentsRibbonController extends Disposable {
|
|
614
|
-
constructor(_instanceService, _selectionManager, _ribbonService) {
|
|
626
|
+
constructor(_instanceService, _selectionManager, changes, _ribbonService) {
|
|
615
627
|
super();
|
|
616
628
|
this._instanceService = _instanceService;
|
|
617
629
|
this._selectionManager = _selectionManager;
|
|
618
630
|
this._ribbonService = _ribbonService;
|
|
619
631
|
_defineProperty(this, "_visible", false);
|
|
620
632
|
this.disposeWithMe(this._selectionManager.textSelection$.subscribe(() => this._update()));
|
|
633
|
+
this.disposeWithMe(changes.docStateChange$.subscribe(() => this._update()));
|
|
621
634
|
this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).subscribe(() => this._update()));
|
|
622
635
|
this._update();
|
|
623
636
|
}
|
|
624
637
|
_update() {
|
|
625
638
|
const doc = this._instanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
626
639
|
const selection = this._selectionManager.getActiveTextRange();
|
|
627
|
-
const visible = Boolean(doc && selection && !selection.segmentId && findTableOfContentsAtOffset(doc.getBody(), selection.startOffset));
|
|
640
|
+
const visible = Boolean(doc && doc.getDocumentStyle().documentFlavor === DocumentFlavor.TRADITIONAL && selection && !selection.segmentId && findTableOfContentsAtOffset(doc.getBody(), selection.startOffset));
|
|
628
641
|
if (visible === this._visible) return;
|
|
629
642
|
this._visible = visible;
|
|
630
643
|
if (visible) this._ribbonService.showContextualTab(DOC_TABLE_OF_CONTENTS_RIBBON_TAB, { activate: true });
|
|
@@ -638,7 +651,8 @@ let TableOfContentsRibbonController = class TableOfContentsRibbonController exte
|
|
|
638
651
|
TableOfContentsRibbonController = __decorate([
|
|
639
652
|
__decorateParam(0, IUniverInstanceService),
|
|
640
653
|
__decorateParam(1, Inject(DocSelectionManagerService)),
|
|
641
|
-
__decorateParam(2,
|
|
654
|
+
__decorateParam(2, Inject(DocStateChangeManagerService)),
|
|
655
|
+
__decorateParam(3, IRibbonService)
|
|
642
656
|
], TableOfContentsRibbonController);
|
|
643
657
|
|
|
644
658
|
// src/controllers/ui.controller.ts
|
|
@@ -707,4 +721,4 @@ UniverDocsTocUIPlugin = __decorate([
|
|
|
707
721
|
__decorateParam(3, IRenderManagerService)
|
|
708
722
|
], UniverDocsTocUIPlugin);
|
|
709
723
|
|
|
710
|
-
export { DocsTocUIMenuSchema, UniverDocsTocUIPlugin };
|
|
724
|
+
export { DOC_TABLE_OF_CONTENTS_RIBBON_GROUP, DOC_TABLE_OF_CONTENTS_RIBBON_TAB, DocsTocUIMenuSchema, InsertTableOfContentsMenuFactory, OpenTableOfContentsDialogOperation, UniverDocsTocUIPlugin };
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Disposable, IUniverInstanceService } from '@univerjs/core';
|
|
17
|
-
import { DocSelectionManagerService } from '@univerjs/docs';
|
|
17
|
+
import { DocSelectionManagerService, DocStateChangeManagerService } from '@univerjs/docs';
|
|
18
18
|
import { IRibbonService } from '@univerjs/ui';
|
|
19
19
|
export declare class TableOfContentsRibbonController extends Disposable {
|
|
20
20
|
private readonly _instanceService;
|
|
21
21
|
private readonly _selectionManager;
|
|
22
22
|
private readonly _ribbonService;
|
|
23
23
|
private _visible;
|
|
24
|
-
constructor(_instanceService: IUniverInstanceService, _selectionManager: DocSelectionManagerService, _ribbonService: IRibbonService);
|
|
24
|
+
constructor(_instanceService: IUniverInstanceService, _selectionManager: DocSelectionManagerService, changes: DocStateChangeManagerService, _ribbonService: IRibbonService);
|
|
25
25
|
private _update;
|
|
26
26
|
dispose(): void;
|
|
27
27
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -14,5 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import './global.css';
|
|
17
|
-
export {
|
|
17
|
+
export { OpenTableOfContentsDialogOperation } from './commands/table-of-contents-dialog.operation';
|
|
18
|
+
export { InsertTableOfContentsMenuFactory } from './menu/menu';
|
|
19
|
+
export { DOC_TABLE_OF_CONTENTS_RIBBON_GROUP, DOC_TABLE_OF_CONTENTS_RIBBON_TAB, DocsTocUIMenuSchema } from './menu/schema';
|
|
18
20
|
export { UniverDocsTocUIPlugin } from './plugin';
|
|
@@ -15,5 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { MenuSchemaType } from '@univerjs/ui';
|
|
17
17
|
export declare const DOC_TABLE_OF_CONTENTS_RIBBON_TAB = "ribbon.table-of-contents";
|
|
18
|
+
export declare const DOC_TABLE_OF_CONTENTS_RIBBON_GROUP = "ribbon.table-of-contents.manage";
|
|
18
19
|
export declare const tableOfContentsRibbonMenuSchema: MenuSchemaType;
|
|
19
20
|
export declare const DocsTocUIMenuSchema: MenuSchemaType;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/docs-toc"),require("@univerjs/ui"),require("@univerjs/core"),require("@univerjs/design"),require("@univerjs/docs"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui"),require("@univerjs/protocol"),require("rxjs"),require("@univerjs/engine-render")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/docs-toc`,`@univerjs/ui`,`@univerjs/core`,`@univerjs/design`,`@univerjs/docs`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`,`@univerjs/protocol`,`rxjs`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsTocUi={},e.UniverDocsToc,e.UniverUi,e.UniverCore,e.UniverDesign,e.UniverDocs,e.React,e.React,e.UniverDocsUi,e.UniverProtocol,e.rxjs,e.UniverEngineRender))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let f=`doc.insert-table-of-contents-dialog`,p=[[`fromTemplate`,`docs-toc-ui.tableOfContents.formatFromTemplate`],[`classic`,`docs-toc-ui.tableOfContents.formatClassic`],[`modern`,`docs-toc-ui.tableOfContents.formatModern`],[`simple`,`docs-toc-ui.tableOfContents.formatSimple`]],m=[[`none`,`docs-toc-ui.tableOfContents.leaderNone`],[`dots`,`docs-toc-ui.tableOfContents.leaderDots`],[`dashes`,`docs-toc-ui.tableOfContents.leaderDashes`],[`underline`,`docs-toc-ui.tableOfContents.leaderUnderline`]];function h(e){let t=(0,n.useDependency)(r.LocaleService),[a,c]=(0,o.useState)(e.options),l=t=>{let n={...a,...t};c(n),e.onChange(n)},u={none:``,dots:`··········`,dashes:`----------`,underline:`__________`}[a.tabLeader],d={fromTemplate:18,classic:14,modern:20,simple:12}[a.format];return/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-gap-4 univer-py-2`,"data-testid":`table-of-contents-insert-dialog`,children:[/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-3`,children:[/* @__PURE__ */ (0,s.jsxs)(`label`,{className:`univer-grid univer-gap-1 univer-text-sm`,children:[/* @__PURE__ */ (0,s.jsx)(`span`,{children:t.t(`docs-toc-ui.tableOfContents.levels`)}),/* @__PURE__ */ (0,s.jsx)(i.Select,{"aria-label":t.t(`docs-toc-ui.tableOfContents.levels`),value:String(a.levels),options:Array.from({length:9},(e,t)=>({value:String(t+1),label:String(t+1)})),onChange:e=>l({levels:Number(e)})})]}),/* @__PURE__ */ (0,s.jsxs)(`label`,{className:`univer-grid univer-gap-1 univer-text-sm`,children:[/* @__PURE__ */ (0,s.jsx)(`span`,{children:t.t(`docs-toc-ui.tableOfContents.format`)}),/* @__PURE__ */ (0,s.jsx)(i.Select,{"aria-label":t.t(`docs-toc-ui.tableOfContents.format`),value:a.format,options:p.map(([e,n])=>({value:e,label:t.t(n)})),onChange:e=>l({format:e})})]})]}),/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-gap-2 univer-text-sm`,children:[/* @__PURE__ */ (0,s.jsx)(i.Checkbox,{checked:a.showPageNumbers,onChange:e=>l({showPageNumbers:!!e,rightAlignPageNumbers:!!e&&a.rightAlignPageNumbers}),children:t.t(`docs-toc-ui.tableOfContents.showPageNumbers`)}),/* @__PURE__ */ (0,s.jsx)(i.Checkbox,{checked:a.rightAlignPageNumbers,disabled:!a.showPageNumbers,onChange:e=>l({rightAlignPageNumbers:!!e}),children:t.t(`docs-toc-ui.tableOfContents.rightAlignPageNumbers`)}),/* @__PURE__ */ (0,s.jsxs)(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,s.jsx)(`span`,{children:t.t(`docs-toc-ui.tableOfContents.tabLeader`)}),/* @__PURE__ */ (0,s.jsx)(i.Select,{"aria-label":t.t(`docs-toc-ui.tableOfContents.tabLeader`),className:`univer-min-w-40`,value:a.tabLeader,disabled:!a.showPageNumbers||!a.rightAlignPageNumbers,options:m.map(([e,n])=>({value:e,label:t.t(n)})),onChange:e=>l({tabLeader:e})})]})]}),/* @__PURE__ */ (0,s.jsxs)(`section`,{className:`univer-rounded-lg univer-border univer-bg-gray-50 univer-p-4 dark:univer-bg-gray-900`,children:[/* @__PURE__ */ (0,s.jsx)(`div`,{className:`univer-mb-3 univer-text-xs univer-font-medium univer-text-gray-500`,children:t.t(`docs-toc-ui.tableOfContents.preview`)}),Array.from({length:Math.min(a.levels,3)},(e,t)=>t).map(e=>/* @__PURE__ */ (0,s.jsxs)(`div`,{className:(0,i.clsx)(`univer-flex univer-items-baseline univer-text-sm`,a.format===`modern`?`univer-mb-2`:`univer-mb-1`),style:{marginInlineStart:`${e*d}px`},children:[/* @__PURE__ */ (0,s.jsxs)(`span`,{children:[t.t(`docs-toc-ui.tableOfContents.previewHeading`),` `,e+1]}),a.showPageNumbers&&a.rightAlignPageNumbers&&/* @__PURE__ */ (0,s.jsx)(`span`,{className:`univer-mx-2 univer-flex-1 univer-overflow-hidden univer-whitespace-nowrap univer-text-gray-400`,children:u}),a.showPageNumbers&&/* @__PURE__ */ (0,s.jsx)(`span`,{className:a.rightAlignPageNumbers?``:`univer-ml-2`,children:e+1})]},e))]})]})}let g=`doc.table-of-contents-dialog`;function _(e){let t=(0,n.useDependency)(r.LocaleService),[a,c]=(0,o.useState)(e.mode);return/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-gap-4 univer-py-2`,"data-testid":`table-of-contents-update-dialog`,children:[/* @__PURE__ */ (0,s.jsx)(`p`,{className:`univer-m-0 univer-text-sm`,children:t.t(`docs-toc-ui.tableOfContents.updateHint`)}),/* @__PURE__ */ (0,s.jsx)(i.RadioGroup,{direction:`vertical`,className:`univer-gap-3`,value:a,onChange:t=>{let n=t;c(n),e.onModeChange(n)},children:[[`pageNumbersOnly`,`docs-toc-ui.tableOfContents.updatePageNumbersOnly`],[`entireTable`,`docs-toc-ui.tableOfContents.updateEntireTable`]].map(([e,n])=>/* @__PURE__ */ (0,s.jsx)(i.Radio,{name:`toc-update-mode`,value:e,className:`univer-flex univer-gap-3 univer-rounded-lg univer-border univer-p-3`,children:t.t(n)},e))})]})}let v=`doc.dialog.update-table-of-contents`,y=`doc.dialog.insert-table-of-contents`,b={levels:3,showPageNumbers:!0,rightAlignPageNumbers:!0,tabLeader:`dots`,format:`fromTemplate`};function x(e){e.get(n.IMessageService).show({type:i.MessageType.Warning,content:e.get(r.LocaleService).t(`docs-toc-ui.tableOfContents.noHeadings`)})}async function S(e,n,i){let a=e.get(r.IUniverInstanceService).getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC);return!a||(0,t.countTableOfContentsHeadings)(a.getBody(),n.levels)===0?(x(e),!1):!!await e.get(r.ICommandService).executeCommand(t.InsertTableOfContentsCommand.id,{unitId:a.getUnitId(),...n,title:i})}let C={id:`doc.operation.insert-table-of-contents`,type:r.CommandType.OPERATION,async handler(e,t){if((t==null?void 0:t.mode)===`automatic`){let t=e.get(r.LocaleService).t(`docs-toc-ui.tableOfContents.contentsTitle`);return S(e,b,t)}if((t==null?void 0:t.mode)!==`custom`||!e.get(r.IUniverInstanceService).getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC))return!1;let n=e.get(r.IConfirmService),i=e.get(r.LocaleService),a={options:{...b}};return await n.open({id:y,width:520,title:{title:i.t(`docs-toc-ui.tableOfContents.customTitle`)},children:{label:{name:f,props:{options:a.options,onChange:e=>{a.options=e}}}},onConfirm:async()=>{await S(e,a.options)&&n.close(y)},onClose:()=>n.close(y)}),!0}},w={id:`doc.operation.open-table-of-contents-dialog`,type:r.CommandType.OPERATION,async handler(e){var n;let i=e.get(r.IUniverInstanceService).getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC),o=e.get(a.DocSelectionManagerService).getActiveTextRange(),s=(0,t.findTableOfContentsAtOffset)(i==null?void 0:i.getBody(),o==null?void 0:o.startOffset);if(!i||!s||((n=s.properties)==null?void 0:n.locked)===r.BooleanNumber.TRUE)return!1;let c=e.get(r.IConfirmService),l=e.get(r.ICommandService),u=e.get(r.LocaleService),d={mode:`pageNumbersOnly`};return await c.open({id:v,width:420,title:{title:u.t(`docs-toc-ui.tableOfContents.updateTitle`)},children:{label:{name:g,props:{mode:d.mode,onModeChange:e=>{d.mode=e}}}},onConfirm:async()=>{try{await l.executeCommand(t.UpdateTableOfContentsCommand.id,{unitId:i.getUnitId(),rangeId:s.rangeId,mode:d.mode})}finally{c.close(v)}},onClose:()=>c.close(v)}),!0}},T=`doc.menu.insert-table-of-contents`;function E(e){let n=e.get(a.DocSelectionManagerService),i=e.get(r.IUniverInstanceService);return new u.Observable(o=>{let s=()=>{let e=i.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC),a=n.getActiveTextRange();o.next(a!=null&&a.segmentId?void 0:(0,t.findTableOfContentsAtOffset)(e==null?void 0:e.getBody(),a==null?void 0:a.startOffset))};s();let c=n.textSelection$.subscribe(s),l=i.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC).subscribe(s),u=e.get(a.DocStateChangeManagerService).docStateChange$.subscribe(s);return()=>{c.unsubscribe(),l.unsubscribe(),u.unsubscribe()}})}function D(e){let n=e.get(a.DocSelectionManagerService),i=e.get(r.IUniverInstanceService);return new u.Observable(e=>{let a=()=>{let a=i.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC),o=n.getActiveTextRange();e.next(!o||o.startOffset!==o.endOffset||!!o.segmentId||!!(0,t.findTableOfContentsAtOffset)(a==null?void 0:a.getBody(),o.startOffset))};a();let o=n.textSelection$.subscribe(a),s=i.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC).subscribe(a);return()=>{o.unsubscribe(),s.unsubscribe()}})}function O(e){let t=(0,c.disableMenuWithoutDocumentUnitPermission)(e,l.UnitAction.Edit);return{id:T,type:n.MenuItemType.SUBITEMS,icon:`UnorderIcon`,title:`docs-toc-ui.tableOfContents.insertTitle`,selectionsCommandId:C.id,selections:[{value:`automatic`,label:`docs-toc-ui.tableOfContents.automaticTitle`,icon:`UnorderIcon`,params:{mode:`automatic`}},{value:`custom`,label:`docs-toc-ui.tableOfContents.customTitle`,icon:`DocSettingIcon`,params:{mode:`custom`}}],disabled$:(0,u.combineLatest)([t,D(e)]).pipe((0,u.map)(([e,t])=>e||t)),hidden$:(0,n.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_DOC)}}function k(e){return{id:w.id,commandId:w.id,type:n.MenuItemType.BUTTON,icon:`UnorderIcon`,title:`docs-toc-ui.tableOfContents.updateTitle`,disabled$:(0,u.combineLatest)([(0,c.disableMenuWithoutDocumentUnitPermission)(e,l.UnitAction.Edit),E(e)]).pipe((0,u.map)(([e,t])=>{var n;return e||!t||((n=t.properties)==null?void 0:n.locked)===r.BooleanNumber.TRUE})),hidden$:(0,u.combineLatest)([(0,n.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_DOC),E(e)]).pipe((0,u.map)(([e,t])=>e||!t))}}function A(e){return{id:t.DeleteTableOfContentsCommand.id,commandId:t.DeleteTableOfContentsCommand.id,type:n.MenuItemType.BUTTON,icon:`DeleteIcon`,title:`docs-toc-ui.tableOfContents.removeTitle`,disabled$:(0,c.disableMenuWithoutDocumentUnitPermission)(e,l.UnitAction.Edit),hidden$:(0,u.combineLatest)([(0,n.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_DOC),E(e)]).pipe((0,u.map)(([e,t])=>e||!t))}}let j=`ribbon.table-of-contents`,M={[n.MenuManagerPosition.RIBBON]:{[j]:{order:100,title:`docs-toc-ui.tableOfContents.title`,contextual:!0,"ribbon.table-of-contents.manage":{order:0,[w.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:k},[t.DeleteTableOfContentsCommand.id]:{order:1,gridLayout:{row:1,column:2,rowSpan:2,showLabel:!0},menuItemFactory:A}}}}},N={[n.RibbonInsertGroup.CELL]:{[T]:{order:7,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:O}},[n.ContextMenuPosition.MAIN_AREA]:{[n.ContextMenuGroup.LAYOUT]:{[w.id]:{order:-1,menuItemFactory:k},[t.DeleteTableOfContentsCommand.id]:{order:-.5,menuItemFactory:A}}}};var P=`@univerjs/docs-toc-ui`,F=`1.5.2`;let I={};function L(e,t){return function(n,r){t(n,r,e)}}function R(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 z=class extends r.Disposable{constructor(e){super(),this.disposeWithMe(e.register(g,_)),this.disposeWithMe(e.register(f,h))}};z=R([L(0,(0,r.Inject)(n.ComponentManager))],z);function B(e){"@babel/helpers - typeof";return B=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},B(e)}function V(e,t){if(B(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(B(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function H(e){var t=V(e,`string`);return B(t)==`symbol`?t:t+``}function U(e,t,n){return(t=H(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let W=class extends r.RxDisposable{constructor(e,t,n,i,a){super(),this._context=e,this._instanceService=t,this._selectionManager=n,this._skeletonManager=i,this._themeService=a,U(this,`_range`,null),U(this,`_outline`,null),U(this,`_rangeId`,null),this._selectionManager.textSelection$.pipe((0,u.takeUntil)(this.dispose$)).subscribe(()=>this._update()),this._skeletonManager.currentSkeleton$.pipe((0,u.takeUntil)(this.dispose$)).subscribe(()=>this._update(!0)),this._instanceService.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC).pipe((0,u.takeUntil)(this.dispose$)).subscribe(()=>this._update()),this._update()}_update(e=!1){let n=this._instanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC),i=this._selectionManager.getActiveTextRange(),a=(n==null?void 0:n.getUnitId())===this._context.unitId&&!(i!=null&&i.segmentId)?(0,t.findTableOfContentsAtOffset)(this._context.unit.getBody(),i==null?void 0:i.startOffset):void 0;if(!a){this._clear();return}if(!e&&a.rangeId===this._rangeId)return;this._clear();let o=this._context.mainComponent,s=Math.max(a.startIndex+1,a.endIndex-1);if(!o)return;let l=this._themeService.getColorFromTheme(`primary.600`),u=this._skeletonManager.getSkeleton(),f=u.findNodePositionByCharIndex(a.startIndex+1,!0,``,-1),p=u.findNodePositionByCharIndex(s,!0,``,-1);if(!f||!p)return;let m=o.getOffsetConfig(),{borderBoxPointGroup:h}=new c.NodePositionConvertToCursor(m,u).getRangePointData(f,p),g=G(h);if(!g)return;let _=new d.RegularPolygon(`__DocTocFill__${(0,r.generateRandomId)()}`,{pointsGroup:h,left:m.docsLeft,top:m.docsTop,fill:new r.ColorKit(l).setAlpha(.08).toRgbString(),evented:!1,debounceParentDirty:!1}),v=new d.Rect(`__DocTocRange__${a.rangeId}`,{left:g.left+m.docsLeft-4,top:g.top+m.docsTop-4,width:g.width+8,height:g.height+8,radius:2,fill:`rgba(0, 0, 0, 0)`,stroke:new r.ColorKit(l).setAlpha(.8).toRgbString(),strokeWidth:1,evented:!1,debounceParentDirty:!1});this._context.scene.addObject(_,c.TEXT_RANGE_LAYER_INDEX),this._context.scene.addObject(v,c.TEXT_RANGE_LAYER_INDEX),this._range=_,this._outline=v,this._rangeId=a.rangeId,this._context.scene.makeDirty()}_clear(){var e,t;!this._range&&!this._outline?this._rangeId=null:((e=this._range)==null||e.dispose(),(t=this._outline)==null||t.dispose(),this._range=null,this._outline=null,this._rangeId=null,this._context.scene.makeDirty())}dispose(){this._clear(),super.dispose()}};W=R([L(1,r.IUniverInstanceService),L(2,(0,r.Inject)(a.DocSelectionManagerService)),L(3,(0,r.Inject)(a.DocSkeletonManagerService)),L(4,(0,r.Inject)(r.ThemeService))],W);function G(e){let t=e.flat();if(!t.length)return null;let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.x)),a=Math.max(...t.map(e=>e.y));return{left:n,top:r,width:i-n,height:a-r}}let K=class extends r.Disposable{constructor(e,t,n){super(),this._instanceService=e,this._selectionManager=t,this._ribbonService=n,U(this,`_visible`,!1),this.disposeWithMe(this._selectionManager.textSelection$.subscribe(()=>this._update())),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC).subscribe(()=>this._update())),this._update()}_update(){let e=this._instanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC),n=this._selectionManager.getActiveTextRange(),i=!!(e&&n&&!n.segmentId&&(0,t.findTableOfContentsAtOffset)(e.getBody(),n.startOffset));i!==this._visible&&(this._visible=i,i?this._ribbonService.showContextualTab(j,{activate:!0}):this._ribbonService.hideContextualTab(j))}dispose(){this._visible&&this._ribbonService.hideContextualTab(j),super.dispose()}};K=R([L(0,r.IUniverInstanceService),L(1,(0,r.Inject)(a.DocSelectionManagerService)),L(2,n.IRibbonService)],K);let q=class extends r.Disposable{constructor(e,t){super(),this.disposeWithMe(e.registerCommand(w)),this.disposeWithMe(e.registerCommand(C)),t.appendRootMenu(M),t.mergeMenu(N)}};q=R([L(0,r.ICommandService),L(1,n.IMenuManagerService)],q);let J=class extends r.Plugin{constructor(e=I,t,n,i){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=i;let{menu:a,...o}=(0,r.merge)({},I,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-toc-ui.config`,o)}onStarting(){[[z],[q],[K]].forEach(e=>this._injector.add(e)),this._injector.get(z),this._injector.get(q)}onReady(){this._injector.get(K)}onRendered(){this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_DOC,[W]))}};U(J,`pluginName`,`DOCS_TOC_UI_PLUGIN`),U(J,`packageName`,P),U(J,`version`,F),U(J,`type`,r.UniverInstanceType.UNIVER_DOC),J=R([(0,r.DependentOn)(a.UniverDocsPlugin,d.UniverRenderEnginePlugin,t.UniverDocsTocPlugin,c.UniverDocsUIPlugin),L(1,(0,r.Inject)(r.Injector)),L(2,r.IConfigService),L(3,d.IRenderManagerService)],J),e.DocsTocUIMenuSchema=N,Object.defineProperty(e,"UniverDocsTocUIPlugin",{enumerable:!0,get:function(){return J}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/docs-toc"),require("@univerjs/ui"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui"),require("@univerjs/protocol"),require("rxjs"),require("@univerjs/engine-render")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/docs-toc`,`@univerjs/ui`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`,`@univerjs/protocol`,`rxjs`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsTocUi={},e.UniverCore,e.UniverDesign,e.UniverDocs,e.UniverDocsToc,e.UniverUi,e.React,e.React,e.UniverDocsUi,e.UniverProtocol,e.rxjs,e.UniverEngineRender))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let f=`doc.insert-table-of-contents-dialog`,p=[[`fromTemplate`,`docs-toc-ui.tableOfContents.formatFromTemplate`],[`classic`,`docs-toc-ui.tableOfContents.formatClassic`],[`modern`,`docs-toc-ui.tableOfContents.formatModern`],[`simple`,`docs-toc-ui.tableOfContents.formatSimple`]],m=[[`none`,`docs-toc-ui.tableOfContents.leaderNone`],[`dots`,`docs-toc-ui.tableOfContents.leaderDots`],[`dashes`,`docs-toc-ui.tableOfContents.leaderDashes`],[`underline`,`docs-toc-ui.tableOfContents.leaderUnderline`]];function h(e){let r=(0,a.useDependency)(t.LocaleService),[i,c]=(0,o.useState)(e.options),l=t=>{let n={...i,...t};c(n),e.onChange(n)},u={none:``,dots:`··········`,dashes:`----------`,underline:`__________`}[i.tabLeader],d={fromTemplate:18,classic:14,modern:20,simple:12}[i.format];return/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-gap-4 univer-py-2`,"data-testid":`table-of-contents-insert-dialog`,children:[/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-3`,children:[/* @__PURE__ */ (0,s.jsxs)(`label`,{className:`univer-grid univer-gap-1 univer-text-sm`,children:[/* @__PURE__ */ (0,s.jsx)(`span`,{children:r.t(`docs-toc-ui.tableOfContents.levels`)}),/* @__PURE__ */ (0,s.jsx)(n.Select,{"aria-label":r.t(`docs-toc-ui.tableOfContents.levels`),value:String(i.levels),options:Array.from({length:9},(e,t)=>({value:String(t+1),label:String(t+1)})),onChange:e=>l({levels:Number(e)})})]}),/* @__PURE__ */ (0,s.jsxs)(`label`,{className:`univer-grid univer-gap-1 univer-text-sm`,children:[/* @__PURE__ */ (0,s.jsx)(`span`,{children:r.t(`docs-toc-ui.tableOfContents.format`)}),/* @__PURE__ */ (0,s.jsx)(n.Select,{"aria-label":r.t(`docs-toc-ui.tableOfContents.format`),value:i.format,options:p.map(([e,t])=>({value:e,label:r.t(t)})),onChange:e=>l({format:e})})]})]}),/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-gap-2 univer-text-sm`,children:[/* @__PURE__ */ (0,s.jsx)(n.Checkbox,{checked:i.showPageNumbers,onChange:e=>l({showPageNumbers:!!e,rightAlignPageNumbers:!!e&&i.rightAlignPageNumbers}),children:r.t(`docs-toc-ui.tableOfContents.showPageNumbers`)}),/* @__PURE__ */ (0,s.jsx)(n.Checkbox,{checked:i.rightAlignPageNumbers,disabled:!i.showPageNumbers,onChange:e=>l({rightAlignPageNumbers:!!e}),children:r.t(`docs-toc-ui.tableOfContents.rightAlignPageNumbers`)}),/* @__PURE__ */ (0,s.jsxs)(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,s.jsx)(`span`,{children:r.t(`docs-toc-ui.tableOfContents.tabLeader`)}),/* @__PURE__ */ (0,s.jsx)(n.Select,{"aria-label":r.t(`docs-toc-ui.tableOfContents.tabLeader`),className:`univer-min-w-40`,value:i.tabLeader,disabled:!i.showPageNumbers||!i.rightAlignPageNumbers,options:m.map(([e,t])=>({value:e,label:r.t(t)})),onChange:e=>l({tabLeader:e})})]})]}),/* @__PURE__ */ (0,s.jsxs)(`section`,{className:`univer-rounded-lg univer-border univer-bg-gray-50 univer-p-4 dark:univer-bg-gray-900`,children:[/* @__PURE__ */ (0,s.jsx)(`div`,{className:`univer-mb-3 univer-text-xs univer-font-medium univer-text-gray-500`,children:r.t(`docs-toc-ui.tableOfContents.preview`)}),Array.from({length:Math.min(i.levels,3)},(e,t)=>t).map(e=>/* @__PURE__ */ (0,s.jsxs)(`div`,{className:(0,n.clsx)(`univer-flex univer-items-baseline univer-text-sm`,i.format===`modern`?`univer-mb-2`:`univer-mb-1`),style:{marginInlineStart:`${e*d}px`},children:[/* @__PURE__ */ (0,s.jsxs)(`span`,{children:[r.t(`docs-toc-ui.tableOfContents.previewHeading`),` `,e+1]}),i.showPageNumbers&&i.rightAlignPageNumbers&&/* @__PURE__ */ (0,s.jsx)(`span`,{className:`univer-mx-2 univer-flex-1 univer-overflow-hidden univer-whitespace-nowrap univer-text-gray-400`,children:u}),i.showPageNumbers&&/* @__PURE__ */ (0,s.jsx)(`span`,{className:i.rightAlignPageNumbers?``:`univer-ml-2`,children:e+1})]},e))]})]})}let g=`doc.table-of-contents-dialog`;function _(e){let r=(0,a.useDependency)(t.LocaleService),[i,c]=(0,o.useState)(e.mode);return/* @__PURE__ */ (0,s.jsxs)(`div`,{className:`univer-grid univer-gap-4 univer-py-2`,"data-testid":`table-of-contents-update-dialog`,children:[/* @__PURE__ */ (0,s.jsx)(`p`,{className:`univer-m-0 univer-text-sm`,children:r.t(`docs-toc-ui.tableOfContents.updateHint`)}),/* @__PURE__ */ (0,s.jsx)(n.RadioGroup,{direction:`vertical`,className:`univer-gap-3`,value:i,onChange:t=>{let n=t;c(n),e.onModeChange(n)},children:[[`pageNumbersOnly`,`docs-toc-ui.tableOfContents.updatePageNumbersOnly`],[`entireTable`,`docs-toc-ui.tableOfContents.updateEntireTable`]].map(([e,t])=>/* @__PURE__ */ (0,s.jsx)(n.Radio,{name:`toc-update-mode`,value:e,className:`univer-flex univer-gap-3 univer-rounded-lg univer-border univer-p-3`,children:r.t(t)},e))})]})}let v=`doc.dialog.update-table-of-contents`,y=`doc.dialog.insert-table-of-contents`,b={levels:3,showPageNumbers:!0,rightAlignPageNumbers:!0,tabLeader:`dots`,format:`fromTemplate`};function x(e){e.get(a.IMessageService).show({type:n.MessageType.Warning,content:e.get(t.LocaleService).t(`docs-toc-ui.tableOfContents.noHeadings`)})}async function S(e,n,r){let a=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);return!a||a.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL?!1:(0,i.countTableOfContentsHeadings)(a.getBody(),n.levels,a.getSnapshot().styles)===0?(x(e),!1):!!await e.get(t.ICommandService).executeCommand(i.InsertTableOfContentsCommand.id,{unitId:a.getUnitId(),...n,title:r})}let C={id:`doc.operation.insert-table-of-contents`,type:t.CommandType.OPERATION,async handler(e,n){if((n==null?void 0:n.mode)===`automatic`){let n=e.get(t.LocaleService).t(`docs-toc-ui.tableOfContents.contentsTitle`);return S(e,b,n)}if((n==null?void 0:n.mode)!==`custom`)return!1;let r=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!r||r.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL)return!1;let i=e.get(t.IConfirmService),a=e.get(t.LocaleService),o={options:{...b}};return await i.open({id:y,width:520,title:{title:a.t(`docs-toc-ui.tableOfContents.customTitle`)},children:{label:{name:f,props:{options:o.options,onChange:e=>{o.options=e}}}},onConfirm:async()=>{await S(e,o.options)&&i.close(y)},onClose:()=>i.close(y)}),!0}},w={id:`doc.operation.open-table-of-contents-dialog`,type:t.CommandType.OPERATION,async handler(e){var n;let a=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC),o=e.get(r.DocSelectionManagerService).getActiveTextRange(),s=(0,i.findTableOfContentsAtOffset)(a==null?void 0:a.getBody(),o==null?void 0:o.startOffset);if(!a||a.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL||!s||((n=s.properties)==null?void 0:n.locked)===t.BooleanNumber.TRUE)return!1;let c=e.get(t.IConfirmService),l=e.get(t.ICommandService),u=e.get(t.LocaleService),d={mode:`pageNumbersOnly`};return await c.open({id:v,width:420,title:{title:u.t(`docs-toc-ui.tableOfContents.updateTitle`)},children:{label:{name:g,props:{mode:d.mode,onModeChange:e=>{d.mode=e}}}},onConfirm:async()=>{try{if(a.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL)return;await l.executeCommand(i.UpdateTableOfContentsCommand.id,{unitId:a.getUnitId(),rangeId:s.rangeId,mode:d.mode})}finally{c.close(v)}},onClose:()=>c.close(v)}),!0}},T=`doc.menu.insert-table-of-contents`;function E(e){return(0,u.combineLatest)([(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC),e.get(t.IUniverInstanceService).getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC),e.get(r.DocStateChangeManagerService).docStateChange$.pipe((0,u.startWith)(null))]).pipe((0,u.map)(([e,n])=>e||(n==null?void 0:n.getDocumentStyle().documentFlavor)!==t.DocumentFlavor.TRADITIONAL),(0,u.distinctUntilChanged)())}function D(e){let n=e.get(r.DocSelectionManagerService),a=e.get(t.IUniverInstanceService);return new u.Observable(o=>{let s=()=>{let e=a.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC),r=n.getActiveTextRange();o.next((e==null?void 0:e.getDocumentStyle().documentFlavor)!==t.DocumentFlavor.TRADITIONAL||r!=null&&r.segmentId?void 0:(0,i.findTableOfContentsAtOffset)(e.getBody(),r==null?void 0:r.startOffset))};s();let c=n.textSelection$.subscribe(s),l=a.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).subscribe(s),u=e.get(r.DocStateChangeManagerService).docStateChange$.subscribe(s);return()=>{c.unsubscribe(),l.unsubscribe(),u.unsubscribe()}})}function O(e){let n=e.get(r.DocSelectionManagerService),a=e.get(t.IUniverInstanceService);return new u.Observable(o=>{let s=()=>{let e=a.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC),r=n.getActiveTextRange();o.next((e==null?void 0:e.getDocumentStyle().documentFlavor)!==t.DocumentFlavor.TRADITIONAL||!r||r.startOffset!==r.endOffset||!!r.segmentId||!!(0,i.findTableOfContentsAtOffset)(e==null?void 0:e.getBody(),r.startOffset))};s();let c=n.textSelection$.subscribe(s),l=a.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).subscribe(s),u=e.get(r.DocStateChangeManagerService).docStateChange$.subscribe(s);return()=>{c.unsubscribe(),l.unsubscribe(),u.unsubscribe()}})}function k(e){let t=(0,c.disableMenuWithoutDocumentUnitPermission)(e,l.UnitAction.Edit);return{id:T,type:a.MenuItemType.SUBITEMS,icon:`UnorderIcon`,title:`docs-toc-ui.tableOfContents.insertTitle`,selectionsCommandId:C.id,selections:[{value:`automatic`,label:`docs-toc-ui.tableOfContents.automaticTitle`,icon:`UnorderIcon`,params:{mode:`automatic`}},{value:`custom`,label:`docs-toc-ui.tableOfContents.customTitle`,icon:`DocSettingIcon`,params:{mode:`custom`}}],disabled$:(0,u.combineLatest)([t,O(e)]).pipe((0,u.map)(([e,t])=>e||t)),hidden$:E(e)}}function A(e){return{id:w.id,commandId:w.id,type:a.MenuItemType.BUTTON,icon:`UnorderIcon`,title:`docs-toc-ui.tableOfContents.updateTitle`,disabled$:(0,u.combineLatest)([(0,c.disableMenuWithoutDocumentUnitPermission)(e,l.UnitAction.Edit),D(e)]).pipe((0,u.map)(([e,n])=>{var r;return e||!n||((r=n.properties)==null?void 0:r.locked)===t.BooleanNumber.TRUE})),hidden$:(0,u.combineLatest)([(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC),D(e)]).pipe((0,u.map)(([e,t])=>e||!t))}}function j(e){return{id:i.DeleteTableOfContentsCommand.id,commandId:i.DeleteTableOfContentsCommand.id,type:a.MenuItemType.BUTTON,icon:`DeleteIcon`,title:`docs-toc-ui.tableOfContents.removeTitle`,disabled$:(0,c.disableMenuWithoutDocumentUnitPermission)(e,l.UnitAction.Edit),hidden$:(0,u.combineLatest)([(0,a.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC),D(e)]).pipe((0,u.map)(([e,t])=>e||!t))}}let M=`ribbon.table-of-contents`,N=`ribbon.table-of-contents.manage`,P={[a.MenuManagerPosition.RIBBON]:{[M]:{order:100,title:`docs-toc-ui.tableOfContents.title`,contextual:!0,[N]:{order:0,[w.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:A},[i.DeleteTableOfContentsCommand.id]:{order:1,gridLayout:{row:1,column:2,rowSpan:2,showLabel:!0},menuItemFactory:j}}}}},F={[a.RibbonInsertGroup.CELL]:{[T]:{order:7,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:k}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.LAYOUT]:{[w.id]:{order:-1,menuItemFactory:A},[i.DeleteTableOfContentsCommand.id]:{order:-.5,menuItemFactory:j}}}};var I=`@univerjs/docs-toc-ui`,L=`1.6.0`;let R={};function z(e,t){return function(n,r){t(n,r,e)}}function B(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 V=class extends t.Disposable{constructor(e){super(),this.disposeWithMe(e.register(g,_)),this.disposeWithMe(e.register(f,h))}};V=B([z(0,(0,t.Inject)(a.ComponentManager))],V);function H(e){"@babel/helpers - typeof";return H=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},H(e)}function U(e,t){if(H(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function W(e){var t=U(e,`string`);return H(t)==`symbol`?t:t+``}function G(e,t,n){return(t=W(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let K=class extends t.RxDisposable{constructor(e,n,r,i,a){super(),this._context=e,this._instanceService=n,this._selectionManager=r,this._skeletonManager=i,this._themeService=a,G(this,`_range`,null),G(this,`_outline`,null),G(this,`_rangeId`,null),this._selectionManager.textSelection$.pipe((0,u.takeUntil)(this.dispose$)).subscribe(()=>this._update()),this._skeletonManager.currentSkeleton$.pipe((0,u.takeUntil)(this.dispose$)).subscribe(()=>this._update(!0)),this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,u.takeUntil)(this.dispose$)).subscribe(()=>this._update()),this._update()}_update(e=!1){let n=this._instanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC),r=this._selectionManager.getActiveTextRange(),a=(n==null?void 0:n.getUnitId())===this._context.unitId&&!(r!=null&&r.segmentId)?(0,i.findTableOfContentsAtOffset)(this._context.unit.getBody(),r==null?void 0:r.startOffset):void 0;if(!a){this._clear();return}if(!e&&a.rangeId===this._rangeId)return;this._clear();let o=this._context.mainComponent,s=Math.max(a.startIndex+1,a.endIndex-1);if(!o)return;let l=this._themeService.getColorFromTheme(`primary.600`),u=this._skeletonManager.getSkeleton(),f=u.findNodePositionByCharIndex(a.startIndex+1,!0,``,-1),p=u.findNodePositionByCharIndex(s,!0,``,-1);if(!f||!p)return;let m=o.getOffsetConfig(),{borderBoxPointGroup:h}=new c.NodePositionConvertToCursor(m,u).getRangePointData(f,p),g=q(h);if(!g)return;let _=new d.RegularPolygon(`__DocTocFill__${(0,t.generateRandomId)()}`,{pointsGroup:h,left:m.docsLeft,top:m.docsTop,fill:new t.ColorKit(l).setAlpha(.08).toRgbString(),evented:!1,debounceParentDirty:!1}),v=new d.Rect(`__DocTocRange__${a.rangeId}`,{left:g.left+m.docsLeft-4,top:g.top+m.docsTop-4,width:g.width+8,height:g.height+8,radius:2,fill:`rgba(0, 0, 0, 0)`,stroke:new t.ColorKit(l).setAlpha(.8).toRgbString(),strokeWidth:1,evented:!1,debounceParentDirty:!1});this._context.scene.addObject(_,c.TEXT_RANGE_LAYER_INDEX),this._context.scene.addObject(v,c.TEXT_RANGE_LAYER_INDEX),this._range=_,this._outline=v,this._rangeId=a.rangeId,this._context.scene.makeDirty()}_clear(){var e,t;!this._range&&!this._outline?this._rangeId=null:((e=this._range)==null||e.dispose(),(t=this._outline)==null||t.dispose(),this._range=null,this._outline=null,this._rangeId=null,this._context.scene.makeDirty())}dispose(){this._clear(),super.dispose()}};K=B([z(1,t.IUniverInstanceService),z(2,(0,t.Inject)(r.DocSelectionManagerService)),z(3,(0,t.Inject)(r.DocSkeletonManagerService)),z(4,(0,t.Inject)(t.ThemeService))],K);function q(e){let t=e.flat();if(!t.length)return null;let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.x)),a=Math.max(...t.map(e=>e.y));return{left:n,top:r,width:i-n,height:a-r}}let J=class extends t.Disposable{constructor(e,n,r,i){super(),this._instanceService=e,this._selectionManager=n,this._ribbonService=i,G(this,`_visible`,!1),this.disposeWithMe(this._selectionManager.textSelection$.subscribe(()=>this._update())),this.disposeWithMe(r.docStateChange$.subscribe(()=>this._update())),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).subscribe(()=>this._update())),this._update()}_update(){let e=this._instanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC),n=this._selectionManager.getActiveTextRange(),r=!!(e&&e.getDocumentStyle().documentFlavor===t.DocumentFlavor.TRADITIONAL&&n&&!n.segmentId&&(0,i.findTableOfContentsAtOffset)(e.getBody(),n.startOffset));r!==this._visible&&(this._visible=r,r?this._ribbonService.showContextualTab(M,{activate:!0}):this._ribbonService.hideContextualTab(M))}dispose(){this._visible&&this._ribbonService.hideContextualTab(M),super.dispose()}};J=B([z(0,t.IUniverInstanceService),z(1,(0,t.Inject)(r.DocSelectionManagerService)),z(2,(0,t.Inject)(r.DocStateChangeManagerService)),z(3,a.IRibbonService)],J);let Y=class extends t.Disposable{constructor(e,t){super(),this.disposeWithMe(e.registerCommand(w)),this.disposeWithMe(e.registerCommand(C)),t.appendRootMenu(P),t.mergeMenu(F)}};Y=B([z(0,t.ICommandService),z(1,a.IMenuManagerService)],Y);let X=class extends t.Plugin{constructor(e=R,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerService=i;let{menu:a,...o}=(0,t.merge)({},R,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-toc-ui.config`,o)}onStarting(){[[V],[Y],[J]].forEach(e=>this._injector.add(e)),this._injector.get(V),this._injector.get(Y)}onReady(){this._injector.get(J)}onRendered(){this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,[K]))}};G(X,`pluginName`,`DOCS_TOC_UI_PLUGIN`),G(X,`packageName`,I),G(X,`version`,L),G(X,`type`,t.UniverInstanceType.UNIVER_DOC),X=B([(0,t.DependentOn)(r.UniverDocsPlugin,d.UniverRenderEnginePlugin,i.UniverDocsTocPlugin,c.UniverDocsUIPlugin),z(1,(0,t.Inject)(t.Injector)),z(2,t.IConfigService),z(3,d.IRenderManagerService)],X),e.DOC_TABLE_OF_CONTENTS_RIBBON_GROUP=N,e.DOC_TABLE_OF_CONTENTS_RIBBON_TAB=M,e.DocsTocUIMenuSchema=F,e.InsertTableOfContentsMenuFactory=k,e.OpenTableOfContentsDialogOperation=w,Object.defineProperty(e,"UniverDocsTocUIPlugin",{enumerable:!0,get:function(){return X}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-toc-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Table of contents UI for Univer Docs.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -58,24 +58,24 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "1.
|
|
62
|
-
"@univerjs/design": "1.
|
|
63
|
-
"@univerjs/docs": "1.
|
|
64
|
-
"@univerjs/docs-toc": "1.
|
|
65
|
-
"@univerjs/docs-ui": "1.
|
|
66
|
-
"@univerjs/engine-render": "1.
|
|
67
|
-
"@univerjs/protocol": "1.
|
|
68
|
-
"@univerjs/ui": "1.
|
|
61
|
+
"@univerjs/core": "1.6.0",
|
|
62
|
+
"@univerjs/design": "1.6.0",
|
|
63
|
+
"@univerjs/docs": "1.6.0",
|
|
64
|
+
"@univerjs/docs-toc": "1.6.0",
|
|
65
|
+
"@univerjs/docs-ui": "1.6.0",
|
|
66
|
+
"@univerjs/engine-render": "1.6.0",
|
|
67
|
+
"@univerjs/protocol": "1.6.0",
|
|
68
|
+
"@univerjs/ui": "1.6.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@univerjs-infra/shared": "1.
|
|
72
|
-
"postcss": "^8.5.
|
|
71
|
+
"@univerjs-infra/shared": "1.6.0",
|
|
72
|
+
"postcss": "^8.5.33",
|
|
73
73
|
"react": "18.3.1",
|
|
74
74
|
"react-dom": "18.3.1",
|
|
75
75
|
"rxjs": "7.8.2",
|
|
76
76
|
"tailwindcss": "3.4.18",
|
|
77
|
-
"tsrs": "
|
|
78
|
-
"vitest": "^5.1.
|
|
77
|
+
"tsrs": "7.1.0-beta.tsrs2",
|
|
78
|
+
"vitest": "^5.1.1"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"test": "vitest run",
|