@difizen/libro-toc 0.0.2-alpha.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/LICENSE +21 -0
- package/README.md +1 -0
- package/es/cell-toc-provider.d.ts +9 -0
- package/es/cell-toc-provider.d.ts.map +1 -0
- package/es/cell-toc-provider.js +46 -0
- package/es/index.d.ts +6 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +5 -0
- package/es/index.less +66 -0
- package/es/libro-toc-color-registry.d.ts +6 -0
- package/es/libro-toc-color-registry.d.ts.map +1 -0
- package/es/libro-toc-color-registry.js +46 -0
- package/es/module.d.ts +14 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +40 -0
- package/es/provider/html.d.ts +39 -0
- package/es/provider/html.d.ts.map +1 -0
- package/es/provider/html.js +54 -0
- package/es/provider/markdown-toc-provider.d.ts +11 -0
- package/es/provider/markdown-toc-provider.d.ts.map +1 -0
- package/es/provider/markdown-toc-provider.js +43 -0
- package/es/provider/markdown.d.ts +23 -0
- package/es/provider/markdown.d.ts.map +1 -0
- package/es/provider/markdown.js +142 -0
- package/es/provider/output-toc-provider.d.ts +10 -0
- package/es/provider/output-toc-provider.d.ts.map +1 -0
- package/es/provider/output-toc-provider.js +67 -0
- package/es/toc-collapse-service.d.ts +10 -0
- package/es/toc-collapse-service.d.ts.map +1 -0
- package/es/toc-collapse-service.js +141 -0
- package/es/toc-configuration.d.ts +7 -0
- package/es/toc-configuration.d.ts.map +1 -0
- package/es/toc-configuration.js +34 -0
- package/es/toc-contribution.d.ts +11 -0
- package/es/toc-contribution.d.ts.map +1 -0
- package/es/toc-contribution.js +63 -0
- package/es/toc-manager.d.ts +10 -0
- package/es/toc-manager.d.ts.map +1 -0
- package/es/toc-manager.js +32 -0
- package/es/toc-protocol.d.ts +107 -0
- package/es/toc-protocol.d.ts.map +1 -0
- package/es/toc-protocol.js +35 -0
- package/es/toc-provider.d.ts +37 -0
- package/es/toc-provider.d.ts.map +1 -0
- package/es/toc-provider.js +181 -0
- package/es/toc-view.d.ts +33 -0
- package/es/toc-view.d.ts.map +1 -0
- package/es/toc-view.js +245 -0
- package/package.json +62 -0
- package/src/cell-toc-provider.ts +31 -0
- package/src/index.less +66 -0
- package/src/index.ts +5 -0
- package/src/libro-toc-color-registry.ts +27 -0
- package/src/module.ts +58 -0
- package/src/provider/html.ts +61 -0
- package/src/provider/markdown-toc-provider.ts +34 -0
- package/src/provider/markdown.ts +182 -0
- package/src/provider/output-toc-provider.ts +53 -0
- package/src/toc-collapse-service.ts +96 -0
- package/src/toc-configuration.ts +22 -0
- package/src/toc-contribution.ts +34 -0
- package/src/toc-manager.ts +27 -0
- package/src/toc-protocol.ts +130 -0
- package/src/toc-provider.ts +154 -0
- package/src/toc-view.tsx +225 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _class, _class2, _descriptor;
|
|
3
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
10
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
11
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
12
|
+
import { ExecutableCellView } from '@difizen/libro-core';
|
|
13
|
+
import { RenderMimeRegistry } from '@difizen/libro-rendermime';
|
|
14
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
15
|
+
import { watch } from '@difizen/mana-app';
|
|
16
|
+
import { CellTOCProviderContribution } from "../toc-protocol.js";
|
|
17
|
+
import { getHTMLHeadings } from "./html.js";
|
|
18
|
+
import { isMarkdown, MarkdownMimeType } from "./markdown.js";
|
|
19
|
+
export var OutputTOCProvider = (_dec = singleton({
|
|
20
|
+
contrib: [CellTOCProviderContribution]
|
|
21
|
+
}), _dec2 = inject(RenderMimeRegistry), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
22
|
+
function OutputTOCProvider() {
|
|
23
|
+
_classCallCheck(this, OutputTOCProvider);
|
|
24
|
+
_initializerDefineProperty(this, "renderMimeRegistry", _descriptor, this);
|
|
25
|
+
}
|
|
26
|
+
_createClass(OutputTOCProvider, [{
|
|
27
|
+
key: "canHandle",
|
|
28
|
+
value: function canHandle(cell) {
|
|
29
|
+
return ExecutableCellView.is(cell) ? 100 : 0;
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "factory",
|
|
33
|
+
value: function factory(cell) {
|
|
34
|
+
var _this = this;
|
|
35
|
+
if (!ExecutableCellView.is(cell)) {
|
|
36
|
+
throw new Error('expected EditorCellView');
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
getHeadings: function getHeadings() {
|
|
40
|
+
return cell.outputArea.outputs.filter(function (item) {
|
|
41
|
+
var defaultRenderMimeType = _this.renderMimeRegistry.preferredMimeType(item);
|
|
42
|
+
if (!defaultRenderMimeType) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return isMarkdown(defaultRenderMimeType);
|
|
46
|
+
}).map(function (item) {
|
|
47
|
+
var _this$renderMimeRegis;
|
|
48
|
+
var html = (_this$renderMimeRegis = _this.renderMimeRegistry.markdownParser) === null || _this$renderMimeRegis === void 0 ? void 0 : _this$renderMimeRegis.render(concatMultilineString(item.data[MarkdownMimeType]), {
|
|
49
|
+
cellId: cell.model.id
|
|
50
|
+
});
|
|
51
|
+
var head = getHTMLHeadings(html !== null && html !== void 0 ? html : '');
|
|
52
|
+
return head;
|
|
53
|
+
}).flat();
|
|
54
|
+
},
|
|
55
|
+
updateWatcher: function updateWatcher(update) {
|
|
56
|
+
return watch(cell.outputArea, 'outputs', update);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}]);
|
|
61
|
+
return OutputTOCProvider;
|
|
62
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "renderMimeRegistry", [_dec2], {
|
|
63
|
+
configurable: true,
|
|
64
|
+
enumerable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
initializer: null
|
|
67
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-core';
|
|
2
|
+
import { DefaultCollapseService } from '@difizen/libro-core';
|
|
3
|
+
import { LibroTOCManager } from './toc-manager.js';
|
|
4
|
+
export declare class TOCCollapseService extends DefaultCollapseService {
|
|
5
|
+
libroTOCManager: LibroTOCManager;
|
|
6
|
+
collapserVisible: boolean;
|
|
7
|
+
setHeadingCollapse(cell: CellView, collapsing: boolean): void;
|
|
8
|
+
getCollapsibleChildNumber(cell: CellView): number;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=toc-collapse-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-collapse-service.d.ts","sourceRoot":"","sources":["../src/toc-collapse-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAEL,sBAAsB,EAEvB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,qBACa,kBAAmB,SAAQ,sBAAsB;IACnC,eAAe,EAAE,eAAe,CAAC;IAGjD,gBAAgB,UAAQ;IAExB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO;IAwCtD,yBAAyB,CAAC,IAAI,EAAE,QAAQ;CAoClD"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2;
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
19
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
21
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
22
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
23
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
24
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
25
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
26
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
27
|
+
import { CellCollapsible, DefaultCollapseService, CollapseService } from '@difizen/libro-core';
|
|
28
|
+
import { prop } from '@difizen/mana-app';
|
|
29
|
+
import { inject, transient } from '@difizen/mana-app';
|
|
30
|
+
import { LibroTOCManager } from "./toc-manager.js";
|
|
31
|
+
import { HeadingType } from "./toc-protocol.js";
|
|
32
|
+
export var TOCCollapseService = (_dec = transient({
|
|
33
|
+
token: CollapseService
|
|
34
|
+
}), _dec2 = inject(LibroTOCManager), _dec3 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function (_DefaultCollapseServi) {
|
|
35
|
+
_inherits(TOCCollapseService, _DefaultCollapseServi);
|
|
36
|
+
var _super = _createSuper(TOCCollapseService);
|
|
37
|
+
function TOCCollapseService() {
|
|
38
|
+
var _this;
|
|
39
|
+
_classCallCheck(this, TOCCollapseService);
|
|
40
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
41
|
+
args[_key] = arguments[_key];
|
|
42
|
+
}
|
|
43
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
44
|
+
_initializerDefineProperty(_this, "libroTOCManager", _descriptor, _assertThisInitialized(_this));
|
|
45
|
+
_initializerDefineProperty(_this, "collapserVisible", _descriptor2, _assertThisInitialized(_this));
|
|
46
|
+
return _this;
|
|
47
|
+
}
|
|
48
|
+
_createClass(TOCCollapseService, [{
|
|
49
|
+
key: "setHeadingCollapse",
|
|
50
|
+
value: function setHeadingCollapse(cell, collapsing) {
|
|
51
|
+
if (!CellCollapsible.is(cell)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
cell.headingCollapsed = collapsing;
|
|
55
|
+
var currentIndex = this.view.model.cells.findIndex(function (item) {
|
|
56
|
+
return item.model.id === cell.model.id;
|
|
57
|
+
});
|
|
58
|
+
if (currentIndex < 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var childNumber = this.getCollapsibleChildNumber(cell);
|
|
62
|
+
cell.collapsibleChildNumber = childNumber;
|
|
63
|
+
var childCells = this.view.model.cells.filter(function (_item, index) {
|
|
64
|
+
return index > currentIndex && index <= currentIndex + childNumber;
|
|
65
|
+
});
|
|
66
|
+
if (collapsing === true) {
|
|
67
|
+
childCells.forEach(function (item) {
|
|
68
|
+
item.collapsedHidden = collapsing;
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
var i = 0;
|
|
72
|
+
while (i < childNumber) {
|
|
73
|
+
var element = childCells[i];
|
|
74
|
+
element.collapsedHidden = false;
|
|
75
|
+
/**
|
|
76
|
+
* 展开时子项的折叠不需要展开
|
|
77
|
+
*/
|
|
78
|
+
if (CellCollapsible.is(element) && element.headingCollapsed) {
|
|
79
|
+
i = i + element.collapsibleChildNumber + 1;
|
|
80
|
+
} else {
|
|
81
|
+
i = i + 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "getCollapsibleChildNumber",
|
|
88
|
+
value: function getCollapsibleChildNumber(cell) {
|
|
89
|
+
var _withMaxLevel$find$ch, _withMaxLevel$find;
|
|
90
|
+
var providerList = this.libroTOCManager.getTOCProvider(this.view).getCellTocProviderList();
|
|
91
|
+
var withMaxLevel = providerList.map(function (item) {
|
|
92
|
+
var maxLevel = 100;
|
|
93
|
+
if (item.tocProvider) {
|
|
94
|
+
var _item$tocProvider;
|
|
95
|
+
// 最大的标题是level最小的
|
|
96
|
+
var headings = (_item$tocProvider = item.tocProvider) === null || _item$tocProvider === void 0 ? void 0 : _item$tocProvider.getHeadings().filter(function (heading) {
|
|
97
|
+
return heading.type === HeadingType.Markdown;
|
|
98
|
+
});
|
|
99
|
+
if (headings.length > 0) {
|
|
100
|
+
maxLevel = Math.min.apply(Math, _toConsumableArray(headings.map(function (heading) {
|
|
101
|
+
return heading.level;
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
106
|
+
maxLevel: maxLevel
|
|
107
|
+
});
|
|
108
|
+
}).map(function (item, index, array) {
|
|
109
|
+
var childNumber = 0;
|
|
110
|
+
for (var i = index + 1; i < array.length; i++) {
|
|
111
|
+
var element = array[i];
|
|
112
|
+
if (item.maxLevel < element.maxLevel) {
|
|
113
|
+
childNumber = childNumber + 1;
|
|
114
|
+
} else {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
119
|
+
childNumber: childNumber
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
var number = (_withMaxLevel$find$ch = (_withMaxLevel$find = withMaxLevel.find(function (item) {
|
|
123
|
+
return item.cellId === cell.model.id;
|
|
124
|
+
})) === null || _withMaxLevel$find === void 0 ? void 0 : _withMaxLevel$find.childNumber) !== null && _withMaxLevel$find$ch !== void 0 ? _withMaxLevel$find$ch : 0;
|
|
125
|
+
return number;
|
|
126
|
+
}
|
|
127
|
+
}]);
|
|
128
|
+
return TOCCollapseService;
|
|
129
|
+
}(DefaultCollapseService), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroTOCManager", [_dec2], {
|
|
130
|
+
configurable: true,
|
|
131
|
+
enumerable: true,
|
|
132
|
+
writable: true,
|
|
133
|
+
initializer: null
|
|
134
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "collapserVisible", [_dec3], {
|
|
135
|
+
configurable: true,
|
|
136
|
+
enumerable: true,
|
|
137
|
+
writable: true,
|
|
138
|
+
initializer: function initializer() {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigurationContribution } from '@difizen/mana-app';
|
|
2
|
+
import type { ConfigurationNode } from '@difizen/mana-app';
|
|
3
|
+
export declare const TOCVisible: ConfigurationNode<boolean>;
|
|
4
|
+
export declare class TOCSettingContribution implements ConfigurationContribution {
|
|
5
|
+
registerConfigurations(): ConfigurationNode<boolean>[];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=toc-configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-configuration.d.ts","sourceRoot":"","sources":["../src/toc-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,OAAO,CASjD,CAAC;AAEF,qBACa,sBAAuB,YAAW,yBAAyB;IACtE,sBAAsB;CAGvB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
import { ConfigurationContribution } from '@difizen/mana-app';
|
|
9
|
+
import { singleton } from '@difizen/mana-app';
|
|
10
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
11
|
+
export var TOCVisible = {
|
|
12
|
+
id: 'libro.toc.visible',
|
|
13
|
+
description: l10n.t('是否显示侧边的TOC'),
|
|
14
|
+
title: 'TOC',
|
|
15
|
+
type: 'checkbox',
|
|
16
|
+
defaultValue: true,
|
|
17
|
+
schema: {
|
|
18
|
+
type: 'boolean'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export var TOCSettingContribution = (_dec = singleton({
|
|
22
|
+
contrib: ConfigurationContribution
|
|
23
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
24
|
+
function TOCSettingContribution() {
|
|
25
|
+
_classCallCheck(this, TOCSettingContribution);
|
|
26
|
+
}
|
|
27
|
+
_createClass(TOCSettingContribution, [{
|
|
28
|
+
key: "registerConfigurations",
|
|
29
|
+
value: function registerConfigurations() {
|
|
30
|
+
return [TOCVisible];
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
return TOCSettingContribution;
|
|
34
|
+
}()) || _class);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LibroExtensionSlotFactory, LibroSlot } from '@difizen/libro-core';
|
|
2
|
+
import { LibroExtensionSlotContribution } from '@difizen/libro-core';
|
|
3
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
4
|
+
import { TOCView } from './toc-view.js';
|
|
5
|
+
export declare class LibroTocSlotContribution implements LibroExtensionSlotContribution {
|
|
6
|
+
viewManager: ViewManager;
|
|
7
|
+
protected viewMap: Map<string, TOCView>;
|
|
8
|
+
readonly slot: LibroSlot;
|
|
9
|
+
factory: LibroExtensionSlotFactory;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=toc-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-contribution.d.ts","sourceRoot":"","sources":["../src/toc-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,yBAAyB,EACzB,SAAS,EACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,qBACa,wBAAyB,YAAW,8BAA8B;IACxD,WAAW,EAAE,WAAW,CAAC;IAC9C,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAEpD,SAAgB,IAAI,EAAE,SAAS,CAAW;IAE1C,OAAO,EAAE,yBAAyB,CAUhC;CAKH"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _class, _class2, _descriptor;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
13
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
14
|
+
import { LibroExtensionSlotContribution } from '@difizen/libro-core';
|
|
15
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
16
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
17
|
+
import { TOCView } from "./toc-view.js";
|
|
18
|
+
export var LibroTocSlotContribution = (_dec = singleton({
|
|
19
|
+
contrib: [LibroExtensionSlotContribution]
|
|
20
|
+
}), _dec2 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/_createClass(function LibroTocSlotContribution() {
|
|
21
|
+
var _this = this;
|
|
22
|
+
_classCallCheck(this, LibroTocSlotContribution);
|
|
23
|
+
_initializerDefineProperty(this, "viewManager", _descriptor, this);
|
|
24
|
+
this.viewMap = new Map();
|
|
25
|
+
this.slot = 'right';
|
|
26
|
+
this.factory = /*#__PURE__*/function () {
|
|
27
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(libro) {
|
|
28
|
+
var view;
|
|
29
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
30
|
+
while (1) switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_context.next = 2;
|
|
33
|
+
return _this.viewManager.getOrCreateView(TOCView, {
|
|
34
|
+
parentId: libro.id
|
|
35
|
+
});
|
|
36
|
+
case 2:
|
|
37
|
+
view = _context.sent;
|
|
38
|
+
view.parent = libro;
|
|
39
|
+
_this.viewMap.set(libro.id, view);
|
|
40
|
+
view.onDisposed(function () {
|
|
41
|
+
_this.viewMap.delete(libro.id);
|
|
42
|
+
});
|
|
43
|
+
return _context.abrupt("return", view);
|
|
44
|
+
case 7:
|
|
45
|
+
case "end":
|
|
46
|
+
return _context.stop();
|
|
47
|
+
}
|
|
48
|
+
}, _callee);
|
|
49
|
+
}));
|
|
50
|
+
return function (_x) {
|
|
51
|
+
return _ref.apply(this, arguments);
|
|
52
|
+
};
|
|
53
|
+
}();
|
|
54
|
+
} // viewOpenOption = {
|
|
55
|
+
// reveal: true,
|
|
56
|
+
// order: 'a',
|
|
57
|
+
// };
|
|
58
|
+
), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
|
|
59
|
+
configurable: true,
|
|
60
|
+
enumerable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
initializer: null
|
|
63
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LibroView } from '@difizen/libro-core';
|
|
2
|
+
import type { LibroTOCProvider } from './toc-provider.js';
|
|
3
|
+
import { LibroTOCProviderFactory } from './toc-provider.js';
|
|
4
|
+
export declare class LibroTOCManager {
|
|
5
|
+
protected tocProviderMap: Map<LibroView, LibroTOCProvider>;
|
|
6
|
+
protected libroTOCProviderFactory: LibroTOCProviderFactory;
|
|
7
|
+
constructor(libroTOCProviderFactory: LibroTOCProviderFactory);
|
|
8
|
+
getTOCProvider(view: LibroView): LibroTOCProvider;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=toc-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-manager.d.ts","sourceRoot":"","sources":["../src/toc-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBACa,eAAe;IAC1B,SAAS,CAAC,cAAc,mCAA0C;IAClE,SAAS,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;gBAGxB,uBAAuB,EAAE,uBAAuB;IAKnF,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,gBAAgB;CASlD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
9
|
+
import { LibroTOCProviderFactory } from "./toc-provider.js";
|
|
10
|
+
export var LibroTOCManager = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
11
|
+
function LibroTOCManager(libroTOCProviderFactory) {
|
|
12
|
+
_classCallCheck(this, LibroTOCManager);
|
|
13
|
+
this.tocProviderMap = new Map();
|
|
14
|
+
this.libroTOCProviderFactory = libroTOCProviderFactory;
|
|
15
|
+
}
|
|
16
|
+
LibroTOCManager = inject(LibroTOCProviderFactory)(LibroTOCManager, undefined, 0) || LibroTOCManager;
|
|
17
|
+
_createClass(LibroTOCManager, [{
|
|
18
|
+
key: "getTOCProvider",
|
|
19
|
+
value: function getTOCProvider(view) {
|
|
20
|
+
var provider = this.tocProviderMap.get(view);
|
|
21
|
+
if (provider) {
|
|
22
|
+
return provider;
|
|
23
|
+
}
|
|
24
|
+
provider = this.libroTOCProviderFactory({
|
|
25
|
+
view: view
|
|
26
|
+
});
|
|
27
|
+
this.tocProviderMap.set(view, provider);
|
|
28
|
+
return provider;
|
|
29
|
+
}
|
|
30
|
+
}]);
|
|
31
|
+
return LibroTOCManager;
|
|
32
|
+
}()) || _class);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-core';
|
|
2
|
+
import type { View } from '@difizen/mana-app';
|
|
3
|
+
import type { Disposable } from '@difizen/mana-app';
|
|
4
|
+
import { Syringe } from '@difizen/mana-app';
|
|
5
|
+
/**
|
|
6
|
+
* Table of Contents configuration
|
|
7
|
+
*
|
|
8
|
+
* #### Notes
|
|
9
|
+
* A document model may ignore some of those options.
|
|
10
|
+
*/
|
|
11
|
+
export interface TOCOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Base level for the highest headings
|
|
14
|
+
*/
|
|
15
|
+
baseNumbering: number;
|
|
16
|
+
/**
|
|
17
|
+
* Maximal depth of headings to display
|
|
18
|
+
*/
|
|
19
|
+
maximalDepth: number;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to number first-level headings or not.
|
|
22
|
+
*/
|
|
23
|
+
numberingH1: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to number headings in document or not.
|
|
26
|
+
*/
|
|
27
|
+
numberHeaders: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether to include cell outputs in headings or not.
|
|
30
|
+
*/
|
|
31
|
+
includeOutput: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to synchronize heading collapse state between the ToC and the document or not.
|
|
34
|
+
*/
|
|
35
|
+
syncCollapseState: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Default table of content configuration
|
|
39
|
+
*/
|
|
40
|
+
export declare const defaultConfig: TOCOptions;
|
|
41
|
+
/**
|
|
42
|
+
* Interface describing a heading.
|
|
43
|
+
*/
|
|
44
|
+
export interface IHeading {
|
|
45
|
+
/**
|
|
46
|
+
* Type of heading
|
|
47
|
+
*/
|
|
48
|
+
type: HeadingType;
|
|
49
|
+
/**
|
|
50
|
+
* Heading text.
|
|
51
|
+
*/
|
|
52
|
+
text: string;
|
|
53
|
+
/**
|
|
54
|
+
* HTML heading level.
|
|
55
|
+
*/
|
|
56
|
+
level: number;
|
|
57
|
+
/**
|
|
58
|
+
* Heading prefix.
|
|
59
|
+
*/
|
|
60
|
+
prefix?: string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Dataset to add to the item node
|
|
63
|
+
*/
|
|
64
|
+
dataset?: Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the heading is marked to skip or not
|
|
67
|
+
*/
|
|
68
|
+
skip?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Index of the output containing the heading
|
|
71
|
+
*/
|
|
72
|
+
outputIndex?: number;
|
|
73
|
+
/**
|
|
74
|
+
* HTML id
|
|
75
|
+
*/
|
|
76
|
+
id?: string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Type of headings
|
|
80
|
+
*/
|
|
81
|
+
export declare enum HeadingType {
|
|
82
|
+
/**
|
|
83
|
+
* Heading from HTML output
|
|
84
|
+
*/
|
|
85
|
+
HTML = 0,
|
|
86
|
+
/**
|
|
87
|
+
* Heading from Markdown cell or Markdown output
|
|
88
|
+
*/
|
|
89
|
+
Markdown = 1
|
|
90
|
+
}
|
|
91
|
+
export interface CellTOCProvider {
|
|
92
|
+
getHeadings: () => IHeading[];
|
|
93
|
+
updateWatcher: (fn: () => void) => Disposable;
|
|
94
|
+
}
|
|
95
|
+
export interface CellTOCProviderContribution {
|
|
96
|
+
canHandle: (cell: CellView) => number;
|
|
97
|
+
factory: (cell: CellView) => CellTOCProvider;
|
|
98
|
+
}
|
|
99
|
+
export declare const CellTOCProviderContribution: Syringe.DefinedToken;
|
|
100
|
+
export interface TOCProviderOption {
|
|
101
|
+
/**
|
|
102
|
+
* libro view
|
|
103
|
+
*/
|
|
104
|
+
view: View;
|
|
105
|
+
}
|
|
106
|
+
export declare const TOCProviderOption: unique symbol;
|
|
107
|
+
//# sourceMappingURL=toc-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-protocol.d.ts","sourceRoot":"","sources":["../src/toc-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UAO3B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,oBAAY,WAAW;IACrB;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;CACT;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,QAAQ,EAAE,CAAC;IAC9B,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,UAAU,CAAC;CAC/C;AAED,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC;IACtC,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,eAAe,CAAC;CAC9C;AAED,eAAO,MAAM,2BAA2B,sBAEvC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ;AACD,eAAO,MAAM,iBAAiB,eAA8B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Syringe } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Table of Contents configuration
|
|
5
|
+
*
|
|
6
|
+
* #### Notes
|
|
7
|
+
* A document model may ignore some of those options.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default table of content configuration
|
|
12
|
+
*/
|
|
13
|
+
export var defaultConfig = {
|
|
14
|
+
baseNumbering: 1,
|
|
15
|
+
maximalDepth: 4,
|
|
16
|
+
numberingH1: true,
|
|
17
|
+
numberHeaders: false,
|
|
18
|
+
includeOutput: true,
|
|
19
|
+
syncCollapseState: false
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Interface describing a heading.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Type of headings
|
|
28
|
+
*/
|
|
29
|
+
export var HeadingType = /*#__PURE__*/function (HeadingType) {
|
|
30
|
+
HeadingType[HeadingType["HTML"] = 0] = "HTML";
|
|
31
|
+
HeadingType[HeadingType["Markdown"] = 1] = "Markdown";
|
|
32
|
+
return HeadingType;
|
|
33
|
+
}({});
|
|
34
|
+
export var CellTOCProviderContribution = Syringe.defineToken('CellTOCProviderContribution');
|
|
35
|
+
export var TOCProviderOption = Symbol('TOCProviderOption');
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LibroView } from '@difizen/libro-core';
|
|
2
|
+
import type { Disposable, Event } from '@difizen/mana-app';
|
|
3
|
+
import { Emitter, DisposableCollection } from '@difizen/mana-app';
|
|
4
|
+
import { LibroCellTOCProvider } from './cell-toc-provider.js';
|
|
5
|
+
import type { CellTOCProvider, IHeading } from './toc-protocol.js';
|
|
6
|
+
import { TOCProviderOption } from './toc-protocol.js';
|
|
7
|
+
export type LibroTOCProviderFactory = (option: TOCProviderOption) => LibroTOCProvider;
|
|
8
|
+
export declare const LibroTOCProviderFactory: unique symbol;
|
|
9
|
+
export declare class LibroTOCProvider implements Disposable {
|
|
10
|
+
protected libroCellTOCProvider: LibroCellTOCProvider;
|
|
11
|
+
protected providerMap: Map<string, CellTOCProvider>;
|
|
12
|
+
headings: IHeading[];
|
|
13
|
+
protected view: LibroView;
|
|
14
|
+
protected toDispose: DisposableCollection;
|
|
15
|
+
protected toDisposeWatcher: DisposableCollection;
|
|
16
|
+
disposed: boolean;
|
|
17
|
+
protected activeCellChangeEmitter: Emitter<IHeading>;
|
|
18
|
+
get activeCellChange(): Event<IHeading>;
|
|
19
|
+
constructor(option: TOCProviderOption, libroCellTOCProvider: LibroCellTOCProvider);
|
|
20
|
+
protected initUpdateWatch(): void;
|
|
21
|
+
protected setupUpdaterWatcher(): void;
|
|
22
|
+
protected handleActiveCellChange: () => void;
|
|
23
|
+
protected updateTOC: () => void;
|
|
24
|
+
protected onActiveCellChanged: () => void;
|
|
25
|
+
protected onCellsChanged: () => void;
|
|
26
|
+
protected onContentChanged: () => void;
|
|
27
|
+
getCellTocProviderList(): {
|
|
28
|
+
cellId: string;
|
|
29
|
+
tocProvider: CellTOCProvider | undefined;
|
|
30
|
+
}[];
|
|
31
|
+
protected getCellTocProviders(): CellTOCProvider[];
|
|
32
|
+
protected getHeadings(): IHeading[];
|
|
33
|
+
selectCellByHeading(heading: IHeading): void;
|
|
34
|
+
getHeadingByCellIndex(index: number): IHeading | undefined;
|
|
35
|
+
dispose(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=toc-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-provider.d.ts","sourceRoot":"","sources":["../src/toc-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,iBAAiB,KAAK,gBAAgB,CAAC;AACtF,eAAO,MAAM,uBAAuB,eAAoC,CAAC;AAEzE,qBACa,gBAAiB,YAAW,UAAU;IACjD,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;IAE7C,SAAS,CAAC,WAAW,+BAAsC;IAE3D,QAAQ,EAAE,QAAQ,EAAE,CAAM;IAGlC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC;IAE1B,SAAS,CAAC,SAAS,uBAA8B;IACjD,SAAS,CAAC,gBAAgB,uBAA8B;IAExD,QAAQ,UAAS;IAEjB,SAAS,CAAC,uBAAuB,oBAA2B;IAE5D,IAAI,gBAAgB,IAAI,KAAK,CAAC,QAAQ,CAAC,CAEtC;gBAG4B,MAAM,EAAE,iBAAiB,EACtB,oBAAoB,EAAE,oBAAoB;IAS1E,SAAS,CAAC,eAAe;IAQzB,SAAS,CAAC,mBAAmB;IAQ7B,SAAS,CAAC,sBAAsB,aAK9B;IAEF,SAAS,CAAC,SAAS,aAEjB;IAEF,SAAS,CAAC,mBAAmB,aAE3B;IAEF,SAAS,CAAC,cAAc,aAGtB;IAEF,SAAS,CAAC,gBAAgB,aAExB;IAEF,sBAAsB;;;;IAoBtB,SAAS,CAAC,mBAAmB;IAM7B,SAAS,CAAC,WAAW;IAiBrB,mBAAmB,CAAC,OAAO,EAAE,QAAQ;IAWrC,qBAAqB,CAAC,KAAK,EAAE,MAAM;IAKnC,OAAO;CASR"}
|