@seafile/seafile-editor 1.0.117-alpha.94 → 1.0.118-beta

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