@seafile/seafile-editor 1.0.118-beta2 → 1.0.118

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.
@@ -38,18 +38,15 @@ const ArticleInfo = _ref => {
38
38
  }
39
39
  }, []);
40
40
  const resizeWidthEnd = (0, _react.useCallback)(width => {
41
- const settings = JSON.parse(window.localStorage.getItem('sf-editor') || '{}');
42
- window.localStorage.setItem('sf-editor', JSON.stringify({
43
- ...settings,
44
- panelWidth: width
41
+ const panelWidth = JSON.parse(window.localStorage.getItem('sf-editor-panel-width') || '{}');
42
+ window.localStorage.setItem('sf-editor-panel-width', JSON.stringify({
43
+ ...panelWidth,
44
+ width
45
45
  }));
46
46
  }, []);
47
47
  (0, _react.useEffect)(() => {
48
- const settings = JSON.parse(window.localStorage.getItem('sf-editor', '{}')) || {};
49
- const {
50
- panelWidth
51
- } = settings;
52
- const width = Math.max(MIN_PANEL_WIDTH, Math.min(parseInt(panelWidth, 10) || MIN_PANEL_WIDTH, MAX_PANEL_WIDTH));
48
+ const panelWidth = JSON.parse(window.localStorage.getItem('sf-editor-panel-width', '{}')) || {};
49
+ const width = Math.max(MIN_PANEL_WIDTH, Math.min(parseInt(panelWidth.width, 10) || MIN_PANEL_WIDTH, MAX_PANEL_WIDTH));
53
50
  setWidth(width);
54
51
  }, []);
55
52
  const handleFileDetails = (0, _react.useCallback)(fileDetails => {
@@ -5,32 +5,15 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.setOutlineSetting = exports.getOutlineSetting = exports.default = void 0;
8
+ exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _reactI18next = require("react-i18next");
11
- var _classnames = _interopRequireDefault(require("classnames"));
12
11
  var _outlineItem = _interopRequireDefault(require("./outline-item"));
13
12
  var _useScrollContext = require("../../hooks/use-scroll-context");
14
13
  var _constants = require("../../constants");
15
14
  var _eventBus = _interopRequireDefault(require("../../utils/event-bus"));
16
15
  var _eventTypes = require("../../constants/event-types");
17
16
  require("./style.css");
18
- const getOutlineSetting = () => {
19
- const currentValue = localStorage.getItem('sf-editor');
20
- const config = currentValue ? JSON.parse(currentValue) : {};
21
- const {
22
- outlineOpen = false
23
- } = config;
24
- return outlineOpen;
25
- };
26
- exports.getOutlineSetting = getOutlineSetting;
27
- const setOutlineSetting = isShown => {
28
- const currentValue = localStorage.getItem('sf-editor');
29
- const config = currentValue ? JSON.parse(currentValue) : {};
30
- config['outlineOpen'] = isShown;
31
- localStorage.setItem('sf-editor', JSON.stringify(config));
32
- };
33
- exports.setOutlineSetting = setOutlineSetting;
34
17
  const getHeaderList = children => {
35
18
  const headerList = [];
36
19
  children.forEach(node => {
@@ -49,22 +32,52 @@ const Outline = _ref => {
49
32
  } = (0, _reactI18next.useTranslation)(_constants.TRANSLATE_NAMESPACE);
50
33
  const scrollRef = (0, _useScrollContext.useScrollContext)();
51
34
  const [headerList, setHeaderList] = (0, _react.useState)([]);
35
+ const [activeId, setActiveId] = (0, _react.useState)('');
52
36
  const [isShown, setIsShown] = (0, _react.useState)(false);
53
37
  const [scrollLeft, setScrollLeft] = (0, _react.useState)(0);
54
38
  (0, _react.useEffect)(() => {
55
39
  const headerList = getHeaderList(editor.children);
56
40
  setHeaderList(headerList);
57
41
  }, [editor.children]);
58
- const updateOutlineState = (0, _react.useCallback)(nextState => {
59
- setOutlineSetting(nextState);
60
- setIsShown(nextState);
61
- const eventBus = _eventBus.default.getInstance();
62
- eventBus.dispatch(_eventTypes.INTERNAL_EVENTS.OUTLINE_STATE_CHANGED);
63
- }, []);
42
+ const handleScroll = (0, _react.useCallback)(e => {
43
+ const scrollTop = scrollRef.current.scrollTop;
44
+ const styles = getComputedStyle(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current);
45
+ const paddingTop = parseInt(styles.paddingTop);
46
+ for (let i = 0; i < headerList.length; i++) {
47
+ const headerItem = headerList[i];
48
+ const dom = document.getElementById(headerItem.id);
49
+ const {
50
+ offsetTop,
51
+ offsetHeight
52
+ } = dom;
53
+ const styles = getComputedStyle(dom);
54
+ const marginTop = parseInt(styles.marginTop);
55
+ if (offsetTop + offsetHeight + marginTop > scrollTop - paddingTop) {
56
+ setActiveId(headerItem.id);
57
+ break;
58
+ }
59
+ }
60
+ }, [headerList, scrollRef]);
61
+ (0, _react.useEffect)(() => {
62
+ let observerRefValue = null;
63
+ if (scrollRef.current) {
64
+ scrollRef.current.addEventListener('scroll', handleScroll);
65
+ observerRefValue = scrollRef.current;
66
+ }
67
+ return () => {
68
+ observerRefValue.removeEventListener('scroll', handleScroll);
69
+ };
70
+ }, [handleScroll, scrollRef]);
64
71
  const toggleShow = (0, _react.useCallback)(() => {
65
- const nextState = !isShown;
66
- updateOutlineState(nextState);
67
- }, [isShown, updateOutlineState]);
72
+ setIsShown(prevIsShown => {
73
+ const newIsShown = !prevIsShown;
74
+ setTimeout(() => {
75
+ const eventBus = _eventBus.default.getInstance();
76
+ eventBus.dispatch(_eventTypes.INTERNAL_EVENTS.OUTLINE_STATE_CHANGED, newIsShown);
77
+ }, 0);
78
+ return newIsShown;
79
+ });
80
+ }, []);
68
81
  (0, _react.useEffect)(() => {
69
82
  if (!scrollRef.current) return;
70
83
  const updateScrollLeft = () => {
@@ -75,21 +88,11 @@ const Outline = _ref => {
75
88
  scrollRef.current.removeEventListener('scroll', updateScrollLeft);
76
89
  };
77
90
  }, [scrollRef]);
78
- (0, _react.useEffect)(() => {
79
- const outlineState = getOutlineSetting();
80
- console.log(outlineState);
81
- updateOutlineState(outlineState);
82
- // eslint-disable-next-line react-hooks/exhaustive-deps
83
- }, []);
84
91
  return /*#__PURE__*/_react.default.createElement("div", {
85
- className: (0, _classnames.default)('sf-editor-outline-wrapper', {
86
- 'active': isShown
87
- }),
92
+ className: "sf-editor-outline",
88
93
  style: {
89
94
  left: -scrollLeft
90
95
  }
91
- }, /*#__PURE__*/_react.default.createElement("div", {
92
- className: "sf-editor-outline"
93
96
  }, isShown && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
94
97
  className: "sf-editor-outline-header"
95
98
  }, /*#__PURE__*/_react.default.createElement("h2", {
@@ -103,13 +106,14 @@ const Outline = _ref => {
103
106
  className: "sf-editor-outline-list-container"
104
107
  }, headerList.map((node, index) => /*#__PURE__*/_react.default.createElement(_outlineItem.default, {
105
108
  key: index,
106
- node: node
107
- }))))), !isShown && /*#__PURE__*/_react.default.createElement("span", {
109
+ node: node,
110
+ activeId: activeId
111
+ })))), !isShown && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
108
112
  id: "sf-editor-outline-menu",
109
- className: "sf-editor-outline-menu sf-editor-tooltip iconfont icon-outline",
113
+ className: "sf-editor-outline-menu sf-edito-tooltip iconfont icon-outline",
110
114
  onClick: toggleShow
111
115
  }, /*#__PURE__*/_react.default.createElement("span", {
112
116
  className: "custom-tooltip"
113
- }, t('Outline'))));
117
+ }, t('Outline')))));
114
118
  };
115
119
  var _default = exports.default = Outline;
@@ -10,31 +10,23 @@ var _react = _interopRequireWildcard(require("react"));
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
  const OutlineItem = _ref => {
12
12
  let {
13
- node
13
+ node,
14
+ activeId
14
15
  } = _ref;
15
- const [isHighlighted, setIsHighlighted] = (0, _react.useState)(false);
16
- const onMouseOver = (0, _react.useCallback)(() => {
17
- setIsHighlighted(true);
18
- }, []);
19
- const onMouseOut = (0, _react.useCallback)(() => {
20
- setIsHighlighted(false);
21
- }, []);
22
16
  const onItemClick = (0, _react.useCallback)(() => {
23
17
  const {
24
18
  id
25
19
  } = node;
26
20
  document.getElementById(id).scrollIntoView();
27
21
  }, [node]);
28
- const className = (0, _classnames.default)('sf-editor-outline-item', {
29
- 'pl-5': node.type === 'header2',
30
- 'pl-7': node.type === 'header3',
31
- 'active': isHighlighted
22
+ const className = (0, _classnames.default)({
23
+ 'outline-h2': node.type === 'header2',
24
+ 'outline-h3': node.type === 'header3',
25
+ 'active': node.id === activeId
32
26
  });
33
27
  return /*#__PURE__*/_react.default.createElement("div", {
34
28
  className: className,
35
- onClick: onItemClick,
36
- onMouseOver: onMouseOver,
37
- onMouseOut: onMouseOut
29
+ onClick: onItemClick
38
30
  }, node.children.map(child => child.text).join(''));
39
31
  };
40
32
  var _default = exports.default = OutlineItem;
@@ -1,26 +1,12 @@
1
- .sf-editor-outline-wrapper {
2
- display: flex;
3
- margin: 20px 30px 20px 16px;
4
- min-height: 0;
5
- pointer-events: none;
6
- position: fixed;
7
- bottom: 0;
8
- top: 100px;
9
- z-index: 101;
10
- }
11
-
12
- .sf-editor-outline-wrapper.active {
13
- pointer-events: all;
14
- }
15
-
16
1
  .sf-editor-outline {
2
+ width: 220px;
17
3
  display: flex;
18
- flex: 1 1;
4
+ min-height: 0;
19
5
  flex-direction: column;
20
6
  font-size: 14px;
21
- min-height: 0;
22
- position: relative;
23
- width: 220px;
7
+ position: fixed;
8
+ margin: 20px 30px 20px 16px;
9
+ top: 100px;
24
10
  }
25
11
 
26
12
  .sf-editor-outline.active {
@@ -52,27 +38,23 @@
52
38
  }
53
39
 
54
40
  .sf-editor-outline-list-container {
55
- display: flex;
41
+ padding: 0.5rem 0;
56
42
  flex: 1 1;
43
+ display: flex;
57
44
  flex-direction: column;
58
- list-style: none;
59
45
  overflow-x: hidden;
60
46
  overflow-y: auto;
61
- padding: .5rem 0;
62
- word-break: break-word;
47
+ max-height: 400px;
63
48
  }
64
49
 
65
50
  .sf-editor-outline-item {
66
- padding: 4px 6px 4px 0;
67
- width: 100%;
51
+ padding: 4px 0;
52
+ padding-right: 6px;
53
+ max-width: 100%;
68
54
  overflow-wrap: anywhere;
69
55
  cursor: pointer;
70
56
  }
71
57
 
72
- .sf-editor-outline-item.active {
73
- color: #eb8205;
74
- }
75
-
76
58
  .sf-editor-outline-menu {
77
59
  line-height: 1;
78
60
  font-size: 14px;
@@ -88,7 +70,7 @@
88
70
  justify-content: center;
89
71
  position: absolute;
90
72
  top: 20px;
91
- left: -15px;;
73
+ left: -15px;
92
74
  pointer-events: all;
93
75
  }
94
76
 
@@ -122,7 +104,43 @@
122
104
  color: #333;
123
105
  }
124
106
 
107
+ .sf-editor-outline .outline-h2,
108
+ .sf-editor-outline .outline-h3 {
109
+ white-space: nowrap;
110
+ overflow: hidden;
111
+ text-overflow: ellipsis;
112
+ }
113
+
114
+ .sf-editor-outline .outline-h2 {
115
+ margin-left: 20px;
116
+ line-height: 2.5;
117
+ color:#364149;
118
+ white-space: nowrap;
119
+ cursor:pointer;
120
+ }
121
+
122
+ .sf-editor-outline .outline-h2:hover {
123
+ color: #eb8205;
124
+ }
125
+
126
+ .sf-editor-outline .outline-h3 {
127
+ margin-left: 40px;
128
+ line-height: 2.5;
129
+ color:#364149;
130
+ white-space: nowrap;
131
+ cursor:pointer;
132
+ }
133
+
134
+ .sf-editor-outline .outline-h3:hover {
135
+ color: #eb8205;
136
+ }
137
+
125
138
  .sf-editor-outline .empty-container {
126
139
  margin-top: 10px;
127
140
  text-align: center;
128
141
  }
142
+
143
+ .sf-editor-outline .outline-h2.active,
144
+ .sf-editor-outline .outline-h3.active {
145
+ color: #eb8205;
146
+ }
@@ -18,7 +18,7 @@ var _core = require("../../extension/core");
18
18
  var _useScrollContext = require("../../hooks/use-scroll-context");
19
19
  var _useInsertImage = _interopRequireDefault(require("../../hooks/use-insert-image"));
20
20
  var _common = require("../../utils/common");
21
- var _outline = _interopRequireWildcard(require("../../containers/outline"));
21
+ var _outline = _interopRequireDefault(require("../../containers/outline"));
22
22
  var _eventTypes = require("../../constants/event-types");
23
23
  require("./style.css");
24
24
  const isMacOS = (0, _common.isMac)();
@@ -45,33 +45,24 @@ function SlateEditor(_ref) {
45
45
  (0, _useInsertImage.default)(editor);
46
46
  const decorate = (0, _extension.useHighlight)(editor);
47
47
 
48
- // Adjust article container margin-left value according to isShown of the outline and width of window
49
- const handleWindowResize = (0, _react.useCallback)(() => {
48
+ //Adjust article container margin-left value according to isShown of the outline and width of window
49
+ const handleWindowResize = newIsShown => {
50
50
  const rect = scrollRef.current.getBoundingClientRect();
51
51
  const articleElement = document.querySelector('.article');
52
52
  const articleRect = articleElement ? articleElement.getBoundingClientRect() : null;
53
- const isOutlineShow = (0, _outline.getOutlineSetting)();
54
- if (isOutlineShow && articleRect && (rect.width - articleRect.width) / 2 < 280) {
53
+ if (newIsShown && articleRect && (rect.width - articleRect.width) / 2 < 280) {
55
54
  setContainerStyle({
56
- marginLeft: 280
55
+ marginLeft: '280px'
57
56
  });
58
57
  } else {
59
58
  setContainerStyle({});
60
59
  }
61
- }, []);
60
+ };
62
61
  (0, _react.useEffect)(() => {
63
62
  const eventBus = _eventBus.default.getInstance();
64
63
  const unsubscribeOutline = eventBus.subscribe(_eventTypes.INTERNAL_EVENTS.OUTLINE_STATE_CHANGED, handleWindowResize);
65
64
  return unsubscribeOutline;
66
65
  }, [handleWindowResize]);
67
- (0, _react.useEffect)(() => {
68
- handleWindowResize();
69
- window.addEventListener('resize', handleWindowResize);
70
- return () => {
71
- window.removeEventListener('resize', handleWindowResize);
72
- };
73
- // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, []);
75
66
  const onChange = (0, _react.useCallback)(value => {
76
67
  setSlateValue(value);
77
68
  if (editor.forceNormalize) return;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _slate = require("slate");
8
8
  var _seafileEditor = require("@seafile/seafile-editor");
9
- const PREVIEW_TEXT_LENGTH = 150;
10
9
  const getPreviewContent = function (content) {
11
10
  let isMarkdown = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
12
11
  const slateNodes = isMarkdown ? (0, _seafileEditor.mdStringToSlate)(content) : content;
@@ -49,8 +48,7 @@ const getPreviewText = (content, previewContent) => {
49
48
  for (let index = 0; index < content.length; index++) {
50
49
  previewText += getTextOfNode(content[index]) + ' ';
51
50
  let textLength = previewText.length;
52
- if (textLength >= PREVIEW_TEXT_LENGTH) {
53
- previewText = textLength > PREVIEW_TEXT_LENGTH ? previewText.slice(0, PREVIEW_TEXT_LENGTH) : previewText;
51
+ if (textLength >= 150) {
54
52
  break;
55
53
  }
56
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.118beta2",
3
+ "version": "1.0.118",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {