@seafile/sdoc-editor 0.1.87 → 0.1.88-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.
Files changed (57) hide show
  1. package/dist/assets/css/simple-editor.css +11 -0
  2. package/dist/basic-sdk/assets/css/dropdown-menu.css +6 -0
  3. package/dist/basic-sdk/editor.js +12 -38
  4. package/dist/{components/modal-portal.js → basic-sdk/extension/commons/element-popover/index.js} +11 -8
  5. package/dist/basic-sdk/extension/constants/color.js +2 -1
  6. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  7. package/dist/basic-sdk/extension/constants/index.js +25 -3
  8. package/dist/basic-sdk/extension/index.js +1 -2
  9. package/dist/basic-sdk/{comment → extension/menu}/color-menu/color-item.js +2 -2
  10. package/dist/basic-sdk/{comment → extension/menu}/color-menu/index.css +61 -9
  11. package/dist/basic-sdk/{comment → extension/menu}/color-menu/index.js +57 -32
  12. package/dist/basic-sdk/extension/menu/index.js +1 -2
  13. package/dist/basic-sdk/extension/menu/menu-item.js +1 -0
  14. package/dist/basic-sdk/extension/menu/menu.css +52 -1
  15. package/dist/basic-sdk/extension/plugins/clear-format/helpers.js +56 -0
  16. package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +25 -0
  17. package/dist/{components/code-block-hover-menu → basic-sdk/extension/plugins/code-block/hover-menu}/index.js +4 -4
  18. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +1 -1
  19. package/dist/basic-sdk/extension/plugins/html/rules/code-block.js +1 -1
  20. package/dist/basic-sdk/extension/plugins/table/constants/index.js +2 -1
  21. package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +1 -1
  22. package/dist/basic-sdk/extension/plugins/table/index.js +2 -3
  23. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +9 -5
  24. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.css +19 -3
  25. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +9 -6
  26. package/dist/basic-sdk/extension/plugins/table/menu/index.js +2 -2
  27. package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.js +15 -11
  28. package/dist/basic-sdk/extension/plugins/table/render/hooks.js +51 -1
  29. package/dist/basic-sdk/extension/plugins/table/render/index.css +0 -34
  30. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +19 -7
  31. package/dist/basic-sdk/extension/plugins/table/render/table-root.js +12 -3
  32. package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +81 -110
  33. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +73 -73
  34. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +3 -0
  35. package/dist/basic-sdk/extension/toolbar/index.js +3 -0
  36. package/dist/basic-sdk/highlight-decorate/setNodeToDecorations.js +1 -1
  37. package/dist/basic-sdk/hooks/use-selection-position.js +11 -3
  38. package/dist/components/more-dropdown/index.js +36 -73
  39. package/dist/utils/local-storage-utils.js +16 -2
  40. package/package.json +1 -1
  41. package/public/locales/en/sdoc-editor.json +4 -1
  42. package/public/locales/zh-CN/sdoc-editor.json +4 -1
  43. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  44. package/public/media/sdoc-editor-font/iconfont.svg +6 -0
  45. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  46. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  47. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  48. package/public/media/sdoc-editor-font.css +18 -6
  49. package/dist/basic-sdk/extension/menu/context-menu/index.css +0 -1
  50. package/dist/basic-sdk/extension/menu/context-menu/index.js +0 -38
  51. package/dist/basic-sdk/extension/plugins/text-align/menu/style.css +0 -53
  52. package/dist/components/more-dropdown/style.css +0 -64
  53. /package/dist/{components/code-block-hover-menu → basic-sdk/extension/plugins/code-block/hover-menu}/index.css +0 -0
  54. /package/dist/basic-sdk/{utils → extension/plugins/code-block}/prismjs.js +0 -0
  55. /package/dist/basic-sdk/extension/plugins/table/{number-input.js → dialog/custom-table-size-dialog/number-input.js} +0 -0
  56. /package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.css +0 -0
  57. /package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/insert-table-element.js +0 -0
@@ -1,116 +1,87 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useRef, useState, useCallback } from 'react';
3
+ import { UncontrolledPopover } from 'reactstrap';
6
4
  import { withTranslation } from 'react-i18next';
7
5
  import classnames from 'classnames';
8
6
  import { getAlignType, isMenuDisabled, setAlignType } from '../helpers';
9
7
  import { TEXT_ALIGN, MENUS_CONFIG_MAP } from '../../../constants';
10
- import './style.css';
11
- var TextAlignMenu = /*#__PURE__*/function (_React$Component) {
12
- _inherits(TextAlignMenu, _React$Component);
13
- var _super = _createSuper(TextAlignMenu);
14
- function TextAlignMenu(props) {
15
- var _this;
16
- _classCallCheck(this, TextAlignMenu);
17
- _this = _super.call(this, props);
18
- _this.registerEventHandler = function () {
19
- document.addEventListener('click', _this.onHideTextAlignMenu, true);
20
- };
21
- _this.unregisterEventHandler = function () {
22
- document.removeEventListener('click', _this.onHideTextAlignMenu, true);
23
- };
24
- _this.onHideTextAlignMenu = function (e) {
25
- var menu = _this.menu;
26
- var clickIsInMenu = menu && menu.contains(e.target) && menu !== e.target;
27
- if (clickIsInMenu) return;
28
- _this.setState({
29
- isDropdownMenuOpen: false
30
- }, function () {
31
- _this.unregisterEventHandler();
32
- });
33
- };
34
- _this.getCurrentType = function () {
35
- var editor = _this.props.editor;
36
- return getAlignType(editor);
37
- };
38
- _this.isActive = function (type) {
39
- return _this.getCurrentType() === type;
40
- };
41
- _this.isDisabled = function () {
42
- var editor = _this.props.editor;
43
- return isMenuDisabled(editor);
44
- };
45
- _this.onToggleClick = function (event) {
46
- event.stopPropagation();
47
- event.nativeEvent.stopImmediatePropagation();
48
- var isDropdownMenuOpen = !_this.state.isDropdownMenuOpen;
49
- if (isDropdownMenuOpen) {
50
- _this.setState({
51
- isDropdownMenuOpen: isDropdownMenuOpen
52
- }, function () {
53
- _this.registerEventHandler();
54
- });
55
- } else {
56
- _this.setState({
57
- isDropdownMenuOpen: isDropdownMenuOpen
58
- }, function () {
59
- _this.unregisterEventHandler();
60
- });
8
+ var TextAlignMenu = function TextAlignMenu(_ref) {
9
+ var isRichEditor = _ref.isRichEditor,
10
+ className = _ref.className,
11
+ editor = _ref.editor;
12
+ var _useState = useState(false),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ isShowMenu = _useState2[0],
15
+ setMenuShow = _useState2[1];
16
+ var popoverRef = useRef(null);
17
+ var disabled = isMenuDisabled(editor);
18
+ var buttonId = 'sdoc-button-text-align';
19
+ var toggle = useCallback(function (event) {
20
+ popoverRef.current.toggle();
21
+ setMenuShow(!isShowMenu);
22
+
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ }, [isShowMenu]);
25
+ var getCurrentType = useCallback(function () {
26
+ return getAlignType(editor);
27
+ }, [editor]);
28
+ var setType = useCallback(function (type) {
29
+ setAlignType(editor, type);
30
+ toggle();
31
+
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, [editor, isShowMenu]);
34
+ var validClassName = classnames(className, 'sdoc-menu-with-dropdown', {
35
+ 'menu-show': isShowMenu,
36
+ 'disabled': disabled,
37
+ 'rich-icon-btn d-flex': isRichEditor,
38
+ 'rich-icon-btn-disabled': isRichEditor && disabled,
39
+ 'rich-icon-btn-hover': isRichEditor && !disabled,
40
+ 'btn btn-icon btn-secondary btn-active d-flex': !isRichEditor
41
+ });
42
+ var curType = getCurrentType();
43
+ var curIcon = MENUS_CONFIG_MAP[TEXT_ALIGN].filter(function (item) {
44
+ return item.type === curType;
45
+ })[0].iconClass;
46
+ var caretIconClass = "sdoc-menu-with-dropdown-triangle-icon sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down');
47
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
48
+ type: "button",
49
+ className: validClassName,
50
+ id: buttonId,
51
+ disabled: disabled
52
+ }, /*#__PURE__*/React.createElement("div", {
53
+ className: "sdoc-menu-with-dropdown-icon"
54
+ }, /*#__PURE__*/React.createElement("span", {
55
+ className: curIcon
56
+ })), !disabled && /*#__PURE__*/React.createElement("div", {
57
+ className: "sdoc-menu-with-dropdown-triangle"
58
+ }, /*#__PURE__*/React.createElement("span", {
59
+ className: caretIconClass
60
+ }))), !disabled && /*#__PURE__*/React.createElement(UncontrolledPopover, {
61
+ target: buttonId,
62
+ className: "sdoc-menu-popover sdoc-dropdown-menu",
63
+ trigger: "legacy",
64
+ placement: "bottom-start",
65
+ hideArrow: true,
66
+ toggle: toggle,
67
+ fade: false,
68
+ ref: popoverRef
69
+ }, /*#__PURE__*/React.createElement("div", {
70
+ className: "pt-2 pb-2"
71
+ }, MENUS_CONFIG_MAP[TEXT_ALIGN].map(function (item, index) {
72
+ return /*#__PURE__*/React.createElement("div", {
73
+ key: index,
74
+ className: "sdoc-dropdown-menu-item",
75
+ onClick: function onClick() {
76
+ return setType(item.type);
61
77
  }
62
- };
63
- _this.setType = function (type) {
64
- var editor = _this.props.editor;
65
- setAlignType(editor, type);
66
- _this.setState({
67
- isDropdownMenuOpen: false
68
- }, function () {
69
- _this.unregisterEventHandler();
70
- });
71
- };
72
- _this.setMenuRef = function (ref) {
73
- _this.menu = ref;
74
- };
75
- _this.state = {
76
- isDropdownMenuOpen: false
77
- };
78
- return _this;
79
- }
80
- _createClass(TextAlignMenu, [{
81
- key: "render",
82
- value: function render() {
83
- var _this2 = this;
84
- var isDropdownMenuOpen = this.state.isDropdownMenuOpen;
85
- var caretIconClass = "caret-icon sdocfont sdoc-".concat(isDropdownMenuOpen ? 'caret-up' : 'drop-down');
86
- var curType = this.getCurrentType();
87
- var curIcon = MENUS_CONFIG_MAP[TEXT_ALIGN].filter(function (item) {
88
- return item.type == curType;
89
- })[0].iconClass;
90
- var disabled = this.isDisabled();
91
- return /*#__PURE__*/React.createElement("div", {
92
- className: "align-menu"
93
- }, /*#__PURE__*/React.createElement("div", {
94
- className: classnames('align-toggle px-2', {
95
- 'align-toggle-disabled': disabled
96
- }),
97
- onClick: disabled ? function () {} : this.onToggleClick
98
- }, /*#__PURE__*/React.createElement("span", {
99
- className: "mr-1 ".concat(curIcon)
100
- }), !disabled && /*#__PURE__*/React.createElement("span", {
101
- className: caretIconClass
102
- })), isDropdownMenuOpen && /*#__PURE__*/React.createElement("div", {
103
- ref: this.setMenuRef,
104
- className: "align-popover sdoc-dropdown-menu"
105
- }, MENUS_CONFIG_MAP[TEXT_ALIGN].map(function (item, index) {
106
- return /*#__PURE__*/React.createElement("span", {
107
- key: index,
108
- className: "sdoc-dropdown-menu-item ".concat(item.iconClass),
109
- onClick: _this2.setType.bind(_this2, item.type)
110
- });
111
- })));
112
- }
113
- }]);
114
- return TextAlignMenu;
115
- }(React.Component);
78
+ }, /*#__PURE__*/React.createElement("i", {
79
+ className: item.iconClass
80
+ }));
81
+ }))));
82
+ };
83
+ TextAlignMenu.defaultProps = {
84
+ isRichEditor: true,
85
+ className: 'menu-group-item'
86
+ };
116
87
  export default withTranslation('sdoc-editor')(TextAlignMenu);
@@ -1,80 +1,80 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
- import React from 'react';
7
- import { TEXT_STYLE, TEXT_STYLE_MORE, MENUS_CONFIG_MAP } from '../../../constants';
2
+ import React, { useCallback } from 'react';
3
+ import { withTranslation } from 'react-i18next';
4
+ import { Editor } from '@seafile/slate';
5
+ import { TEXT_STYLE, TEXT_STYLE_MORE, MENUS_CONFIG_MAP, ELEMENT_TYPE } from '../../../constants';
8
6
  import { focusEditor } from '../../../core';
9
7
  import { MenuItem } from '../../../menu';
10
8
  import { getValue, isMenuDisabled, addMark, removeMark } from '../helpers';
11
9
  import MoreDropdown from '../../../../../components/more-dropdown';
12
- var TextStyleMenuList = /*#__PURE__*/function (_React$Component) {
13
- _inherits(TextStyleMenuList, _React$Component);
14
- var _super = _createSuper(TextStyleMenuList);
15
- function TextStyleMenuList() {
16
- var _this;
17
- _classCallCheck(this, TextStyleMenuList);
18
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
19
- args[_key] = arguments[_key];
10
+ import ColorMenu from '../../../menu/color-menu';
11
+ var TextStyleMenuList = function TextStyleMenuList(_ref) {
12
+ var editor = _ref.editor,
13
+ t = _ref.t,
14
+ isRichEditor = _ref.isRichEditor,
15
+ className = _ref.className;
16
+ var isActive = useCallback(function (type) {
17
+ var isMark = getValue(editor, type);
18
+ return !!isMark;
19
+
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ }, [editor]);
22
+ var isDisabled = useCallback(function () {
23
+ return isMenuDisabled(editor);
24
+
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, [editor]);
27
+ var onMouseDown = useCallback(function (event, type) {
28
+ event.preventDefault();
29
+ event.stopPropagation();
30
+ if (isDisabled()) return;
31
+ var active = isActive(type);
32
+ if (active) {
33
+ removeMark(editor, type);
34
+ } else {
35
+ addMark(editor, type);
20
36
  }
21
- _this = _super.call.apply(_super, [this].concat(args));
22
- _this.isActive = function (editor, type) {
23
- var isMark = getValue(editor, type);
24
- return !!isMark;
25
- };
26
- _this.isDisabled = function () {
27
- var editor = _this.props.editor;
28
- return isMenuDisabled(editor);
29
- };
30
- _this.onMouseDown = function (e, type) {
31
- e.preventDefault();
32
- e.stopPropagation();
33
- if (_this.isDisabled()) return;
34
- var editor = _this.props.editor;
35
- var active = _this.isActive(editor, type);
36
- if (active) {
37
- removeMark(editor, type);
38
- } else {
39
- addMark(editor, type);
40
- }
41
- focusEditor(editor);
42
- };
43
- _this.getTextStyleList = function (key) {
44
- var _this$props = _this.props,
45
- isRichEditor = _this$props.isRichEditor,
46
- className = _this$props.className,
47
- editor = _this$props.editor;
48
- var list = MENUS_CONFIG_MAP[key].map(function (item) {
49
- var itemProps = {
50
- isRichEditor: isRichEditor,
51
- className: className,
52
- disabled: _this.isDisabled(),
53
- isActive: _this.isActive(editor, item.type),
54
- onMouseDown: _this.onMouseDown
37
+ focusEditor(editor);
38
+
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [editor]);
41
+ var setColor = useCallback(function (type, color) {
42
+ Editor.addMark(editor, type, color);
43
+ focusEditor(editor);
44
+
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ }, [editor]);
47
+ var getTextStyleList = useCallback(function (key) {
48
+ return MENUS_CONFIG_MAP[key].map(function (item) {
49
+ var itemProps = {
50
+ isRichEditor: isRichEditor,
51
+ className: className,
52
+ disabled: isDisabled(),
53
+ isActive: isActive(item.type),
54
+ onMouseDown: item.isColor ? function () {} : onMouseDown
55
+ };
56
+ if (item.isColor) {
57
+ itemProps['setColor'] = function (color) {
58
+ return setColor(item.type, color);
55
59
  };
56
- return _objectSpread(_objectSpread({}, itemProps), item);
57
- });
58
- return list;
59
- };
60
- return _this;
61
- }
62
- _createClass(TextStyleMenuList, [{
63
- key: "render",
64
- value: function render() {
65
- var list = this.getTextStyleList(TEXT_STYLE);
66
- var dropdownList = this.getTextStyleList(TEXT_STYLE_MORE);
67
- return /*#__PURE__*/React.createElement(React.Fragment, null, list.map(function (itemProps, index) {
68
- return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
69
- key: index
70
- }, itemProps));
71
- }), /*#__PURE__*/React.createElement(MoreDropdown, null, dropdownList.map(function (itemProps, index) {
72
- return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
73
- key: index
74
- }, itemProps));
75
- })));
76
- }
77
- }]);
78
- return TextStyleMenuList;
79
- }(React.Component);
80
- export default TextStyleMenuList;
60
+ itemProps['defaultColorTip'] = item.type === ELEMENT_TYPE.COLOR ? t('Default') : '';
61
+ }
62
+ return _objectSpread(_objectSpread({}, itemProps), item);
63
+ });
64
+
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, [editor]);
67
+ var list = getTextStyleList(TEXT_STYLE);
68
+ var dropdownList = getTextStyleList(TEXT_STYLE_MORE);
69
+ return /*#__PURE__*/React.createElement(React.Fragment, null, list.map(function (itemProps, index) {
70
+ var Component = itemProps.isColor ? ColorMenu : MenuItem;
71
+ return /*#__PURE__*/React.createElement(Component, Object.assign({
72
+ key: index
73
+ }, itemProps));
74
+ }), /*#__PURE__*/React.createElement(MoreDropdown, null, dropdownList.map(function (itemProps, index) {
75
+ return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
76
+ key: index
77
+ }, itemProps));
78
+ })));
79
+ };
80
+ export default withTranslation('sdoc-editor')(TextStyleMenuList);
@@ -21,6 +21,9 @@ var renderText = function renderText(props, editor) {
21
21
  if (leaf.color) {
22
22
  style['color'] = leaf.color;
23
23
  }
24
+ if (leaf['highlight-color']) {
25
+ style['backgroundColor'] = leaf['highlight-color'];
26
+ }
24
27
  if (leaf.BOLD) {
25
28
  markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
26
29
  }
@@ -13,6 +13,7 @@ import CodeBlockMenu from '../plugins/code-block/menu';
13
13
  import TextAlignMenu from '../plugins/text-align/menu';
14
14
  import HistoryMenu from './redo-undo';
15
15
  import { TableMenu, ActiveTableMenu } from '../plugins/table/menu';
16
+ import ClearFormatMenu from '../plugins/clear-format/menu';
16
17
  var Toolbar = function Toolbar(_ref) {
17
18
  var editor = _ref.editor;
18
19
  useSelectionUpdate();
@@ -20,6 +21,8 @@ var Toolbar = function Toolbar(_ref) {
20
21
  className: "sdoc-editor-toolbar"
21
22
  }, /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(HistoryMenu, {
22
23
  editor: editor
24
+ })), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(ClearFormatMenu, {
25
+ editor: editor
23
26
  })), /*#__PURE__*/React.createElement(HeaderMenu, {
24
27
  editor: editor
25
28
  }), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenuList, {
@@ -4,7 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
5
  import { Node, Element, Editor } from '@seafile/slate';
6
6
  import { useSlateStatic } from '@seafile/slate-react';
7
- import Prism, { normalizeTokens, normalizeTokensByLanguageType } from '../utils/prismjs';
7
+ import Prism, { normalizeTokens, normalizeTokensByLanguageType } from '../extension/plugins/code-block/prismjs';
8
8
  import { CODE_BLOCK } from '../extension/constants';
9
9
  var mergeMaps = function mergeMaps() {
10
10
  var map = new Map();
@@ -17,9 +17,17 @@ export var useSelectionPosition = function useSelectionPosition() {
17
17
  x: 0,
18
18
  y: 0
19
19
  };
20
- var domNode = ReactEditor.toDOMNode(editor, node[0]);
21
- var rect = domNode.getBoundingClientRect();
22
- return rect;
20
+ try {
21
+ var domNode = ReactEditor.toDOMNode(editor, node[0]);
22
+ var rect = domNode.getBoundingClientRect();
23
+ return rect;
24
+ } catch (error) {
25
+ // A new node has not yet been indexed, it cannot be retrieved, and the new node has no comment information, just do not display it
26
+ return {
27
+ x: 0,
28
+ y: 0
29
+ };
30
+ }
23
31
  };
24
32
  export var useCommentListPosition = function useCommentListPosition() {
25
33
  var selectionPosition = useSelectionPosition();
@@ -1,75 +1,38 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
1
  import React from 'react';
6
- import './style.css';
7
- var MoreDropdownMenu = /*#__PURE__*/function (_React$Component) {
8
- _inherits(MoreDropdownMenu, _React$Component);
9
- var _super = _createSuper(MoreDropdownMenu);
10
- function MoreDropdownMenu(props) {
11
- var _this;
12
- _classCallCheck(this, MoreDropdownMenu);
13
- _this = _super.call(this, props);
14
- _this.registerEventHandler = function () {
15
- document.addEventListener('click', _this.onHideMoreDropdownMenu, true);
16
- };
17
- _this.unregisterEventHandler = function () {
18
- document.removeEventListener('click', _this.onHideMoreDropdownMenu, true);
19
- };
20
- _this.onHideMoreDropdownMenu = function (e) {
21
- var menu = _this.menu;
22
- var clickIsInMenu = menu && menu.contains(e.target) && menu !== e.target;
23
- if (clickIsInMenu) return;
24
- _this.setState({
25
- isDropdownMenuOpen: false
26
- }, function () {
27
- _this.unregisterEventHandler();
28
- });
29
- };
30
- _this.onToggleClick = function (event) {
31
- event.stopPropagation();
32
- event.nativeEvent.stopImmediatePropagation();
33
- var isDropdownMenuOpen = !_this.state.isDropdownMenuOpen;
34
- if (isDropdownMenuOpen) {
35
- _this.setState({
36
- isDropdownMenuOpen: isDropdownMenuOpen
37
- }, function () {
38
- _this.registerEventHandler();
39
- });
40
- } else {
41
- _this.setState({
42
- isDropdownMenuOpen: isDropdownMenuOpen
43
- }, function () {
44
- _this.unregisterEventHandler();
45
- });
46
- }
47
- };
48
- _this.setMenuRef = function (ref) {
49
- _this.menu = ref;
50
- };
51
- _this.state = {
52
- isDropdownMenuOpen: false
53
- };
54
- return _this;
55
- }
56
- _createClass(MoreDropdownMenu, [{
57
- key: "render",
58
- value: function render() {
59
- var isDropdownMenuOpen = this.state.isDropdownMenuOpen;
60
- return /*#__PURE__*/React.createElement("div", {
61
- className: "sdoc-more-menu"
62
- }, /*#__PURE__*/React.createElement("div", {
63
- className: "more-toggle px-2",
64
- onClick: this.onToggleClick
65
- }, /*#__PURE__*/React.createElement("span", {
66
- className: "sdocfont sdoc-more"
67
- })), isDropdownMenuOpen && /*#__PURE__*/React.createElement("div", {
68
- ref: this.setMenuRef,
69
- className: "more-popover"
70
- }, this.props.children));
71
- }
72
- }]);
73
- return MoreDropdownMenu;
74
- }(React.Component);
2
+ import classnames from 'classnames';
3
+ import { UncontrolledPopover } from 'reactstrap';
4
+ var MoreDropdownMenu = function MoreDropdownMenu(_ref) {
5
+ var className = _ref.className,
6
+ disabled = _ref.disabled,
7
+ isRichEditor = _ref.isRichEditor,
8
+ children = _ref.children;
9
+ var validClassName = classnames(className, 'sdoc-more-text-button', {
10
+ 'disabled': disabled,
11
+ 'rich-icon-btn': isRichEditor,
12
+ 'rich-icon-btn-disabled': isRichEditor && disabled,
13
+ 'rich-icon-btn-hover': isRichEditor && !disabled,
14
+ 'btn btn-icon btn-secondary btn-active': !isRichEditor
15
+ });
16
+ var buttonId = 'sdoc-more-text-operations';
17
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
18
+ className: validClassName,
19
+ type: "button",
20
+ id: buttonId
21
+ }, /*#__PURE__*/React.createElement("i", {
22
+ className: "sdocfont sdoc-more"
23
+ })), /*#__PURE__*/React.createElement(UncontrolledPopover, {
24
+ target: buttonId,
25
+ className: "sdoc-menu-popover sdoc-dropdown-menu",
26
+ trigger: "legacy",
27
+ placement: "bottom-end",
28
+ hideArrow: true,
29
+ fade: false
30
+ }, /*#__PURE__*/React.createElement("div", {
31
+ className: "menu-group"
32
+ }, children)));
33
+ };
34
+ MoreDropdownMenu.defaultProps = {
35
+ isRichEditor: true,
36
+ className: 'menu-group-item'
37
+ };
75
38
  export default MoreDropdownMenu;
@@ -7,12 +7,26 @@ var LocalStorage = /*#__PURE__*/function () {
7
7
  _createClass(LocalStorage, null, [{
8
8
  key: "setItem",
9
9
  value: function setItem(key, value) {
10
- return window.localStorage.setItem(key, JSON.stringify(value));
10
+ var savedValue;
11
+ var valueType = typeof value;
12
+ if (valueType === 'string') {
13
+ savedValue = value;
14
+ } else if (valueType === 'number') {
15
+ savedValue = value + '';
16
+ } else {
17
+ savedValue = JSON.stringify(value);
18
+ }
19
+ return window.localStorage.setItem(key, savedValue);
11
20
  }
12
21
  }, {
13
22
  key: "getItem",
14
23
  value: function getItem(key, defaultValue) {
15
- return JSON.parse(window.localStorage.getItem(key)) || defaultValue;
24
+ var value = window.localStorage.getItem(key);
25
+ try {
26
+ return JSON.parse(value) || defaultValue;
27
+ } catch (_unused) {
28
+ return value || defaultValue;
29
+ }
16
30
  }
17
31
  }, {
18
32
  key: "removeItem",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.87",
3
+ "version": "0.1.88beta",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -305,5 +305,8 @@
305
305
  "Standard_light_blue": "Standard light blue",
306
306
  "Standard_blue": "Standard blue",
307
307
  "Standard_dark_blue": "Standard dark blue",
308
- "Standard_purple": "Standard purple"
308
+ "Standard_purple": "Standard purple",
309
+ "Highlight_color": "Highlight",
310
+ "Font_color": "Font color",
311
+ "Default": "Default"
309
312
  }
@@ -305,5 +305,8 @@
305
305
  "Standard_light_blue": "标准浅蓝",
306
306
  "Standard_blue": "标准蓝",
307
307
  "Standard_dark_blue": "标准深蓝",
308
- "Standard_purple": "标准紫"
308
+ "Standard_purple": "标准紫",
309
+ "Highlight_color": "突出显示",
310
+ "Font_color": "字体颜色",
311
+ "Default": "默认"
309
312
  }
@@ -14,6 +14,12 @@
14
14
  />
15
15
  <missing-glyph />
16
16
 
17
+ <glyph glyph-name="sdoc-font-color" unicode="&#58886;" d="M960-96h-160l-80 224h-416L224-96H64L403.2 864h211.2L960-96zM512 704l-160-448h320L512 704z" horiz-adv-x="1024" />
18
+
19
+ <glyph glyph-name="sdoc-highlight-color" unicode="&#58885;" d="M992 528L640-67.2l-144 80-64-108.8H32l163.2 278.4L32 275.2 380.8 896 992 528zM198.4 320l406.4-224 233.6 390.4L428.8 736 198.4 320z" horiz-adv-x="1024" />
20
+
21
+ <glyph glyph-name="sdoc-format-clear" unicode="&#58883;" d="M519.488 64H279.552L64 279.552 584.448 800l384.64-384.64L617.728 64h-98.176z m64 64l92.608 92.608-288.64 288.64L161.28 282.88 316.16 128h267.328zM128 0h832v-64H128v64z" horiz-adv-x="1024" />
22
+
17
23
  <glyph glyph-name="sdoc-bg-color" unicode="&#58884;" d="M906.4-64c60.8 0 105.6 48 105.6 105.6 0 38.4-35.2 124.8-105.6 246.4C836 160 800.8 80 800.8 41.6c0-60.8 48-105.6 105.6-105.6zM512.8 761.6l358.4-352c35.2-35.2 35.2-92.8 0-128l-358.4-352c-35.2-35.2-92.8-35.2-131.2 0l-355.2 352c-35.2 35.2-35.2 92.8 0 128L356 736l-19.2 19.2c-25.6 22.4-25.6 64 0 89.6s64 22.4 89.6 0l86.4-83.2z m-368-400h614.4L452 649.6c0-3.2-307.2-288-307.2-288z" horiz-adv-x="1024" />
18
24
 
19
25
  <glyph glyph-name="sdoc-right-slide" unicode="&#58882;" d="M806.4 438.4L336 812.8c-54.4 44.8-144 9.6-144-54.4v-748.8c0-64 86.4-99.2 144-54.4l470.4 374.4c35.2 28.8 35.2 80 0 108.8z" horiz-adv-x="1024" />