@difizen/libro-toc 1.0.2 → 1.0.4

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/es/index.less CHANGED
@@ -15,6 +15,10 @@
15
15
  padding-top: 12px;
16
16
  overflow-y: auto;
17
17
 
18
+ &.collapse {
19
+ width: 50px;
20
+ }
21
+
18
22
  .markdown-toc-container-title {
19
23
  box-sizing: border-box;
20
24
  height: 24px;
@@ -33,6 +37,12 @@
33
37
  }
34
38
  }
35
39
 
40
+ .markdown-toc-expand-action {
41
+ display: inline-block;
42
+ cursor: pointer;
43
+ margin-left: 6px;
44
+ }
45
+
36
46
  .markdown-toc-container-anchor {
37
47
  position: relative;
38
48
  display: block;
@@ -1,6 +1,7 @@
1
1
  import type { ConfigurationNode } from '@difizen/libro-common/app';
2
2
  import { ConfigurationContribution } from '@difizen/libro-common/app';
3
3
  export declare const TOCVisible: ConfigurationNode<boolean>;
4
+ export declare const EnableExpandCollapse: ConfigurationNode<boolean>;
4
5
  export declare class TOCSettingContribution implements ConfigurationContribution {
5
6
  registerConfigurations(): ConfigurationNode<boolean>[];
6
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"toc-configuration.d.ts","sourceRoot":"","sources":["../src/toc-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAItE,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,OAAO,CASjD,CAAC;AAEF,qBACa,sBAAuB,YAAW,yBAAyB;IACtE,sBAAsB;CAGvB"}
1
+ {"version":3,"file":"toc-configuration.d.ts","sourceRoot":"","sources":["../src/toc-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAItE,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,OAAO,CASjD,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,OAAO,CAS3D,CAAC;AAEF,qBACa,sBAAuB,YAAW,yBAAyB;IACtE,sBAAsB;CAGvB"}
@@ -18,6 +18,16 @@ export var TOCVisible = {
18
18
  type: 'boolean'
19
19
  }
20
20
  };
21
+ export var EnableExpandCollapse = {
22
+ id: 'libro.toc.expand.collapse',
23
+ description: l10n.t('是否支持展开与收起侧边的TOC'),
24
+ title: 'TOC',
25
+ type: 'checkbox',
26
+ defaultValue: false,
27
+ schema: {
28
+ type: 'boolean'
29
+ }
30
+ };
21
31
  export var TOCSettingContribution = (_dec = singleton({
22
32
  contrib: ConfigurationContribution
23
33
  }), _dec(_class = /*#__PURE__*/function () {
@@ -27,7 +37,7 @@ export var TOCSettingContribution = (_dec = singleton({
27
37
  _createClass(TOCSettingContribution, [{
28
38
  key: "registerConfigurations",
29
39
  value: function registerConfigurations() {
30
- return [TOCVisible];
40
+ return [TOCVisible, EnableExpandCollapse];
31
41
  }
32
42
  }]);
33
43
  return TOCSettingContribution;
package/es/toc-view.d.ts CHANGED
@@ -15,6 +15,8 @@ export declare class TOCView extends BaseView implements DisplayView {
15
15
  protected configurationService: ConfigurationService;
16
16
  view: () => import("react/jsx-runtime").JSX.Element;
17
17
  isDisplay: boolean;
18
+ isExpand: boolean;
19
+ supportExpand: boolean;
18
20
  tocProvider?: LibroTOCProvider;
19
21
  activeHeading: IHeading | undefined;
20
22
  protected libroTOCManager: LibroTOCManager;
@@ -1 +1 @@
1
- {"version":3,"file":"toc-view.d.ts","sourceRoot":"","sources":["../src/toc-view.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAsB,MAAM,2B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,EAAE,QAAQ;IAIpC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAU/D,OAAO;CAGjB"}
package/es/toc-view.js CHANGED
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7;
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
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; }
@@ -19,6 +19,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
19
19
  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; }
20
20
  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.'); }
21
21
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
22
+ import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons';
22
23
  import { ArrowDown, ArrowRight } from '@difizen/libro-core';
23
24
  import { ConfigurationService } from '@difizen/libro-common/app';
24
25
  import { getOrigin, prop, useInject } from '@difizen/libro-common/app';
@@ -26,7 +27,7 @@ import { BaseView, view, ViewInstance } from '@difizen/libro-common/app';
26
27
  import { inject, transient } from '@difizen/libro-common/app';
27
28
  import { l10n } from '@difizen/libro-common/l10n';
28
29
  import React, { useRef } from 'react';
29
- import { TOCVisible } from "./toc-configuration.js";
30
+ import { EnableExpandCollapse, TOCVisible } from "./toc-configuration.js";
30
31
  import { LibroTOCManager } from "./toc-manager.js";
31
32
  import "./index.less";
32
33
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -86,12 +87,20 @@ export var TocRender = function TocRender() {
86
87
  (_instance$tocProvider = instance.tocProvider) === null || _instance$tocProvider === void 0 || _instance$tocProvider.selectCellByHeading(heading);
87
88
  };
88
89
  return /*#__PURE__*/_jsxs("div", {
89
- className: "markdown-toc-container",
90
+ className: "markdown-toc-container ".concat(instance.isExpand ? 'expand' : 'collapse'),
90
91
  ref: containRef,
91
- children: [/*#__PURE__*/_jsx("div", {
92
- className: "markdown-toc-container-title",
93
- children: instance.tocTitle
94
- }), instance.getDisplayHeadings().map(function (heading) {
92
+ children: [/*#__PURE__*/_jsxs("div", {
93
+ className: "markdown-toc-container-header",
94
+ children: [/*#__PURE__*/_jsx("span", {
95
+ children: instance.tocTitle
96
+ }), instance.supportExpand && /*#__PURE__*/_jsx("div", {
97
+ className: "markdown-toc-expand-action",
98
+ onClick: function onClick() {
99
+ instance.isExpand = !instance.isExpand;
100
+ },
101
+ children: instance.isExpand ? /*#__PURE__*/_jsx(EyeInvisibleOutlined, {}) : /*#__PURE__*/_jsx(EyeOutlined, {})
102
+ })]
103
+ }), instance.isExpand && instance.getDisplayHeadings().map(function (heading) {
95
104
  var _instance$activeHeadi;
96
105
  var collapsed = instance.isHeadingCollapsed(heading);
97
106
  return /*#__PURE__*/_jsx(TocItem, {
@@ -108,7 +117,7 @@ export var TocRender = function TocRender() {
108
117
  })]
109
118
  });
110
119
  };
111
- export var TOCView = (_dec = transient(), _dec2 = view('libro-toc-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
120
+ export var TOCView = (_dec = transient(), _dec2 = view('libro-toc-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec9 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
112
121
  _inherits(TOCView, _BaseView);
113
122
  var _super = _createSuper(TOCView);
114
123
  function TOCView(libroTOCManager, configurationService) {
@@ -118,10 +127,12 @@ export var TOCView = (_dec = transient(), _dec2 = view('libro-toc-view'), _dec3
118
127
  _this.parent = undefined;
119
128
  _this.view = TocRender;
120
129
  _initializerDefineProperty(_this, "isDisplay", _descriptor, _assertThisInitialized(_this));
121
- _initializerDefineProperty(_this, "tocProvider", _descriptor2, _assertThisInitialized(_this));
122
- _initializerDefineProperty(_this, "activeHeading", _descriptor3, _assertThisInitialized(_this));
123
- _initializerDefineProperty(_this, "tocTitle", _descriptor4, _assertThisInitialized(_this));
124
- _initializerDefineProperty(_this, "headingCollapseState", _descriptor5, _assertThisInitialized(_this));
130
+ _initializerDefineProperty(_this, "isExpand", _descriptor2, _assertThisInitialized(_this));
131
+ _initializerDefineProperty(_this, "supportExpand", _descriptor3, _assertThisInitialized(_this));
132
+ _initializerDefineProperty(_this, "tocProvider", _descriptor4, _assertThisInitialized(_this));
133
+ _initializerDefineProperty(_this, "activeHeading", _descriptor5, _assertThisInitialized(_this));
134
+ _initializerDefineProperty(_this, "tocTitle", _descriptor6, _assertThisInitialized(_this));
135
+ _initializerDefineProperty(_this, "headingCollapseState", _descriptor7, _assertThisInitialized(_this));
125
136
  _this.libroTOCManager = libroTOCManager;
126
137
  _this.configurationService = configurationService;
127
138
  _this.configurationService.get(TOCVisible).then(function (value) {
@@ -130,6 +141,12 @@ export var TOCView = (_dec = transient(), _dec2 = view('libro-toc-view'), _dec3
130
141
  }).catch(function () {
131
142
  //
132
143
  });
144
+ _this.configurationService.get(EnableExpandCollapse).then(function (value) {
145
+ _this.supportExpand = value;
146
+ return;
147
+ }).catch(function () {
148
+ //
149
+ });
133
150
  return _this;
134
151
  }
135
152
  TOCView = inject(ConfigurationService)(TOCView, undefined, 1) || TOCView;
@@ -219,24 +236,36 @@ export var TOCView = (_dec = transient(), _dec2 = view('libro-toc-view'), _dec3
219
236
  enumerable: true,
220
237
  writable: true,
221
238
  initializer: null
222
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tocProvider", [_dec4], {
239
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "isExpand", [_dec4], {
240
+ configurable: true,
241
+ enumerable: true,
242
+ writable: true,
243
+ initializer: function initializer() {
244
+ return true;
245
+ }
246
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "supportExpand", [_dec5], {
247
+ configurable: true,
248
+ enumerable: true,
249
+ writable: true,
250
+ initializer: null
251
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "tocProvider", [_dec6], {
223
252
  configurable: true,
224
253
  enumerable: true,
225
254
  writable: true,
226
255
  initializer: null
227
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "activeHeading", [_dec5], {
256
+ }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "activeHeading", [_dec7], {
228
257
  configurable: true,
229
258
  enumerable: true,
230
259
  writable: true,
231
260
  initializer: null
232
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "tocTitle", [_dec6], {
261
+ }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "tocTitle", [_dec8], {
233
262
  configurable: true,
234
263
  enumerable: true,
235
264
  writable: true,
236
265
  initializer: function initializer() {
237
266
  return l10n.t('大纲');
238
267
  }
239
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "headingCollapseState", [_dec7], {
268
+ }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "headingCollapseState", [_dec9], {
240
269
  configurable: true,
241
270
  enumerable: true,
242
271
  writable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-toc",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -33,10 +33,11 @@
33
33
  "src"
34
34
  ],
35
35
  "dependencies": {
36
- "@difizen/libro-common": "^1.0.2",
37
- "@difizen/libro-core": "^1.0.2",
38
- "@difizen/libro-markdown": "^1.0.2",
39
- "@difizen/libro-rendermime": "^1.0.2"
36
+ "@difizen/libro-common": "^1.0.4",
37
+ "@difizen/libro-core": "^1.0.4",
38
+ "@difizen/libro-markdown": "^1.0.4",
39
+ "@difizen/libro-rendermime": "^1.0.4",
40
+ "@ant-design/icons": "^6.0.0"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "react": ">=16"
package/src/index.less CHANGED
@@ -15,6 +15,10 @@
15
15
  padding-top: 12px;
16
16
  overflow-y: auto;
17
17
 
18
+ &.collapse {
19
+ width: 50px;
20
+ }
21
+
18
22
  .markdown-toc-container-title {
19
23
  box-sizing: border-box;
20
24
  height: 24px;
@@ -33,6 +37,12 @@
33
37
  }
34
38
  }
35
39
 
40
+ .markdown-toc-expand-action {
41
+ display: inline-block;
42
+ cursor: pointer;
43
+ margin-left: 6px;
44
+ }
45
+
36
46
  .markdown-toc-container-anchor {
37
47
  position: relative;
38
48
  display: block;
@@ -14,9 +14,20 @@ export const TOCVisible: ConfigurationNode<boolean> = {
14
14
  },
15
15
  };
16
16
 
17
+ export const EnableExpandCollapse: ConfigurationNode<boolean> = {
18
+ id: 'libro.toc.expand.collapse',
19
+ description: l10n.t('是否支持展开与收起侧边的TOC'),
20
+ title: 'TOC',
21
+ type: 'checkbox',
22
+ defaultValue: false,
23
+ schema: {
24
+ type: 'boolean',
25
+ },
26
+ };
27
+
17
28
  @singleton({ contrib: ConfigurationContribution })
18
29
  export class TOCSettingContribution implements ConfigurationContribution {
19
30
  registerConfigurations() {
20
- return [TOCVisible];
31
+ return [TOCVisible, EnableExpandCollapse];
21
32
  }
22
33
  }
package/src/toc-view.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons';
2
3
  import { ArrowDown, ArrowRight } from '@difizen/libro-core';
3
4
  import type { DisplayView, LibroView } from '@difizen/libro-core';
4
5
  import { ConfigurationService } from '@difizen/libro-common/app';
@@ -8,7 +9,7 @@ import { inject, transient } from '@difizen/libro-common/app';
8
9
  import { l10n } from '@difizen/libro-common/l10n';
9
10
  import React, { useRef } from 'react';
10
11
 
11
- import { TOCVisible } from './toc-configuration.js';
12
+ import { EnableExpandCollapse, TOCVisible } from './toc-configuration.js';
12
13
  import { LibroTOCManager } from './toc-manager.js';
13
14
  import type { IHeading } from './toc-protocol.js';
14
15
  import type { LibroTOCProvider } from './toc-provider.js';
@@ -81,32 +82,47 @@ const TocItem: React.FC<TocItemProps> = ({
81
82
  export const TocRender = () => {
82
83
  const instance = useInject<TOCView>(ViewInstance);
83
84
  const containRef = useRef<HTMLDivElement>(null);
84
-
85
85
  const handleClick = (heading: IHeading) => {
86
86
  instance.activeHeading = heading;
87
87
  instance.tocProvider?.selectCellByHeading(heading);
88
88
  };
89
89
 
90
90
  return (
91
- <div className="markdown-toc-container" ref={containRef}>
92
- <div className="markdown-toc-container-title">{instance.tocTitle}</div>
93
- {instance.getDisplayHeadings().map((heading) => {
94
- const collapsed = instance.isHeadingCollapsed(heading);
95
- return (
96
- <TocItem
97
- active={instance.activeHeading?.id === heading.id}
98
- heading={heading}
99
- key={heading.id}
100
- onClick={handleClick}
101
- headingCollapsed={collapsed}
102
- onToggle={() => {
103
- if (heading.id) {
104
- instance.headingCollapseState.set(heading.id, !collapsed);
105
- }
91
+ <div
92
+ className={`markdown-toc-container ${instance.isExpand ? 'expand' : 'collapse'}`}
93
+ ref={containRef}
94
+ >
95
+ <div className="markdown-toc-container-header">
96
+ <span>{instance.tocTitle}</span>
97
+ {instance.supportExpand && (
98
+ <div
99
+ className="markdown-toc-expand-action"
100
+ onClick={() => {
101
+ instance.isExpand = !instance.isExpand;
106
102
  }}
107
- />
108
- );
109
- })}
103
+ >
104
+ {instance.isExpand ? <EyeInvisibleOutlined /> : <EyeOutlined />}
105
+ </div>
106
+ )}
107
+ </div>
108
+ {instance.isExpand &&
109
+ instance.getDisplayHeadings().map((heading) => {
110
+ const collapsed = instance.isHeadingCollapsed(heading);
111
+ return (
112
+ <TocItem
113
+ active={instance.activeHeading?.id === heading.id}
114
+ heading={heading}
115
+ key={heading.id}
116
+ onClick={handleClick}
117
+ headingCollapsed={collapsed}
118
+ onToggle={() => {
119
+ if (heading.id) {
120
+ instance.headingCollapseState.set(heading.id, !collapsed);
121
+ }
122
+ }}
123
+ />
124
+ );
125
+ })}
110
126
  </div>
111
127
  );
112
128
  };
@@ -122,6 +138,12 @@ export class TOCView extends BaseView implements DisplayView {
122
138
  @prop()
123
139
  isDisplay: boolean;
124
140
 
141
+ @prop()
142
+ isExpand = true;
143
+
144
+ @prop()
145
+ supportExpand: boolean;
146
+
125
147
  @prop()
126
148
  tocProvider?: LibroTOCProvider;
127
149
 
@@ -152,6 +174,15 @@ export class TOCView extends BaseView implements DisplayView {
152
174
  .catch(() => {
153
175
  //
154
176
  });
177
+ this.configurationService
178
+ .get(EnableExpandCollapse)
179
+ .then((value) => {
180
+ this.supportExpand = value;
181
+ return;
182
+ })
183
+ .catch(() => {
184
+ //
185
+ });
155
186
  }
156
187
 
157
188
  getHeadingIndentSize(level: number): number {