@seafile/sdoc-editor 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.
@@ -7,17 +7,19 @@ const listRule = (element, parseChild) => {
7
7
  childNodes
8
8
  } = element;
9
9
  if (nodeName === 'UL') {
10
+ const validChildNodes = Array.from(childNodes).filter(item => item.nodeName === 'LI');
10
11
  return {
11
12
  id: slugid.nice(),
12
13
  type: UNORDERED_LIST,
13
- children: parseChild(childNodes)
14
+ children: parseChild(validChildNodes)
14
15
  };
15
16
  }
16
17
  if (nodeName === 'OL') {
18
+ const validChildNodes = Array.from(childNodes).filter(item => item.nodeName === 'LI');
17
19
  return {
18
20
  id: slugid.nice(),
19
21
  type: ORDERED_LIST,
20
- children: parseChild(childNodes)
22
+ children: parseChild(validChildNodes)
21
23
  };
22
24
  }
23
25
  if (nodeName === 'LI' && PARAGRAPH_TAGS.includes(element.firstChild.nodeName)) {
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { withTranslation } from 'react-i18next';
3
+ import classnames from 'classnames';
4
+ const ColorItem = _ref => {
5
+ let {
6
+ t,
7
+ color,
8
+ lastUsedColor
9
+ } = _ref;
10
+ return /*#__PURE__*/React.createElement("div", {
11
+ className: classnames('sdoc-color-item', {
12
+ 'selected': lastUsedColor === color.value
13
+ }),
14
+ style: {
15
+ backgroundColor: color.value
16
+ },
17
+ color: color.value,
18
+ "data-color": color.value,
19
+ title: color.index ? t(color.name, {
20
+ value: color.index
21
+ }) : t(color.name)
22
+ });
23
+ };
24
+ export default withTranslation('sdoc-editor')(ColorItem);
@@ -0,0 +1,171 @@
1
+ import React, { useCallback, useRef, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { UncontrolledPopover } from 'reactstrap';
4
+ import classnames from 'classnames';
5
+ import { ChromePicker } from 'react-color';
6
+ import { LocalStorage } from '../../../../../../utils';
7
+ import { DEFAULT_COLORS, DEFAULT_RECENT_USED_LIST, RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY, STANDARD_COLORS } from '../../../../constants';
8
+ import ColorItem from './color-item';
9
+ import { eventStopPropagation } from '../../../../../utils/mouse-event';
10
+ import { setCellStyle } from '../../helpers';
11
+ import { useColorContext } from '../../../../../hooks/use-color-context';
12
+ import './style.css';
13
+ const recentUsedColorsKey = RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY;
14
+ const ColorSelectorPopover = _ref => {
15
+ let {
16
+ target,
17
+ editor,
18
+ readonly,
19
+ isRichEditor = true
20
+ } = _ref;
21
+ const {
22
+ t
23
+ } = useTranslation();
24
+ const {
25
+ lastUsedTableCellBackgroundColor: lastUsedColor,
26
+ updateLastUsedTableCellBackgroundColor: updateLastUsedColor
27
+ } = useColorContext();
28
+ const popoverRef = useRef(null);
29
+ const moreColorsPopoverRef = useRef(null);
30
+ const [recentUsedColors, setRecentUsedColors] = useState(LocalStorage.getItem(recentUsedColorsKey, DEFAULT_RECENT_USED_LIST));
31
+ const [isShowMenu, setMenuShow] = useState(false);
32
+ const [isPickerShow, setPickerShow] = useState(false);
33
+ const setColor = useCallback(color => {
34
+ setCellStyle(editor, {
35
+ background_color: color
36
+ });
37
+ }, [editor]);
38
+ const onSetColor = useCallback(function (color) {
39
+ let shouldClose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
40
+ if (readonly) return;
41
+ const validColor = color || '';
42
+ setColor(validColor);
43
+ if (validColor !== '' && recentUsedColors[0] !== validColor) {
44
+ let newRecentUsedColors = recentUsedColors.slice(0, 9);
45
+ newRecentUsedColors.unshift(validColor);
46
+ LocalStorage.setItem(recentUsedColorsKey, newRecentUsedColors);
47
+ setRecentUsedColors(newRecentUsedColors);
48
+ }
49
+ updateLastUsedColor && updateLastUsedColor(validColor);
50
+ if (shouldClose) {
51
+ popoverRef.current.toggle();
52
+ setMenuShow(!isShowMenu);
53
+ }
54
+
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, [recentUsedColors, recentUsedColorsKey, isShowMenu, isPickerShow, readonly]);
57
+ const setColorProxy = useCallback(event => {
58
+ if (event.target.className.includes('sdoc-color-item')) {
59
+ const color = event.target.dataset.color;
60
+ onSetColor(color);
61
+ }
62
+
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ }, [recentUsedColors, recentUsedColorsKey, isShowMenu, isPickerShow]);
65
+ const toggle = useCallback(() => {
66
+ if (isPickerShow) return;
67
+ popoverRef.current.toggle();
68
+ setMenuShow(!isShowMenu);
69
+
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, [isShowMenu, isPickerShow]);
72
+ const moreColorsPopoverToggle = useCallback(() => {
73
+ moreColorsPopoverRef.current.toggle();
74
+ setPickerShow(!isPickerShow);
75
+
76
+ // eslint-disable-next-line react-hooks/exhaustive-deps
77
+ }, [moreColorsPopoverRef, isPickerShow]);
78
+ const onMouseDown = useCallback(event => {
79
+ eventStopPropagation(event);
80
+
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, []);
83
+ const onChange = useCallback(color => {
84
+ const validColor = color.hex;
85
+ onSetColor(validColor, false);
86
+
87
+ // eslint-disable-next-line react-hooks/exhaustive-deps
88
+ }, [readonly]);
89
+ return /*#__PURE__*/React.createElement(UncontrolledPopover, {
90
+ target: target,
91
+ trigger: "hover",
92
+ placement: "right-start",
93
+ hideArrow: true,
94
+ fade: false,
95
+ className: "sdoc-color-menu-popover sdoc-table-cell-bg-colors-popover",
96
+ toggle: toggle,
97
+ ref: popoverRef
98
+ }, /*#__PURE__*/React.createElement("div", {
99
+ className: "sdoc-dropdown-menu sdoc-color-dropdown-menu"
100
+ }, /*#__PURE__*/React.createElement("div", {
101
+ className: "p-3 d-flex flex-column"
102
+ }, /*#__PURE__*/React.createElement("div", {
103
+ className: "sdoc-color-no-color-container"
104
+ }, /*#__PURE__*/React.createElement("div", {
105
+ className: "sdoc-color-no-color-content",
106
+ onMouseDown: () => onSetColor()
107
+ }, t('No_color'))), /*#__PURE__*/React.createElement("div", {
108
+ className: "sdoc-color-default-colors-container",
109
+ onMouseDown: setColorProxy
110
+ }, DEFAULT_COLORS.map((color, index) => {
111
+ return /*#__PURE__*/React.createElement(ColorItem, {
112
+ key: "default-color-".concat(index),
113
+ color: color,
114
+ lastUsedColor: lastUsedColor
115
+ });
116
+ })), /*#__PURE__*/React.createElement("div", {
117
+ className: "sdoc-color-standard-colors-container"
118
+ }, /*#__PURE__*/React.createElement("div", {
119
+ className: "sdoc-color-sub-title"
120
+ }, t('Standard_color')), /*#__PURE__*/React.createElement("div", {
121
+ className: "d-flex",
122
+ onMouseDown: setColorProxy
123
+ }, STANDARD_COLORS.map((color, index) => {
124
+ return /*#__PURE__*/React.createElement(ColorItem, {
125
+ key: "standard-color-".concat(index),
126
+ color: color,
127
+ lastUsedColor: lastUsedColor
128
+ });
129
+ }))), /*#__PURE__*/React.createElement("div", {
130
+ className: "sdoc-color-recent-used-colors-container"
131
+ }, /*#__PURE__*/React.createElement("div", {
132
+ className: "sdoc-color-sub-title"
133
+ }, t('Recently_used')), /*#__PURE__*/React.createElement("div", {
134
+ className: "d-flex",
135
+ onMouseDown: setColorProxy
136
+ }, recentUsedColors.map((color, index) => {
137
+ return /*#__PURE__*/React.createElement(ColorItem, {
138
+ key: "standard-color-".concat(index),
139
+ color: {
140
+ value: color,
141
+ name: color
142
+ }
143
+ });
144
+ })))), /*#__PURE__*/React.createElement("div", {
145
+ className: "sdoc-colors-divider"
146
+ }), /*#__PURE__*/React.createElement("div", {
147
+ className: classnames('sdoc-more-colors pr-2', {
148
+ 'show-pick': isPickerShow
149
+ }),
150
+ id: "sdoc-more-colors"
151
+ }, /*#__PURE__*/React.createElement("span", null, t('More_color')), /*#__PURE__*/React.createElement("i", {
152
+ className: "sdocfont sdoc-right-slide"
153
+ })), /*#__PURE__*/React.createElement(UncontrolledPopover, {
154
+ target: "sdoc-more-colors",
155
+ className: "sdoc-more-colors-popover sdoc-table-more-colors",
156
+ trigger: "hover",
157
+ placement: "right-end",
158
+ hideArrow: true,
159
+ fade: false,
160
+ toggle: moreColorsPopoverToggle,
161
+ ref: moreColorsPopoverRef
162
+ }, /*#__PURE__*/React.createElement("div", {
163
+ className: "sdoc-more-colors-container",
164
+ onMouseDown: onMouseDown
165
+ }, /*#__PURE__*/React.createElement(ChromePicker, {
166
+ disableAlpha: true,
167
+ color: lastUsedColor || '',
168
+ onChange: onChange
169
+ })))));
170
+ };
171
+ export default ColorSelectorPopover;
@@ -0,0 +1,169 @@
1
+ .menu-group .sdoc-color-menu.menu-show {
2
+ background: #e5e5e5;
3
+ border-radius: 2px;
4
+ }
5
+
6
+ .menu-group .sdoc-color-menu .last-used-color-container {
7
+ height: 100%;
8
+ display: flex;
9
+ flex-direction: column;
10
+ justify-content: center;
11
+ align-items: center;
12
+ }
13
+
14
+ .menu-group .sdoc-color-menu .last-used-color-container.disabled {
15
+ padding-right: 0;
16
+ }
17
+
18
+ .menu-group .sdoc-color-menu .sdoc-color-toggle {
19
+ height: 100%;
20
+ display: flex;
21
+ align-items: center;
22
+ justify-content: center;
23
+ }
24
+
25
+ .menu-group .sdoc-color-menu .sdoc-color-toggle:hover,
26
+ .menu-group .sdoc-color-menu .last-used-color-container:not(.disabled):hover {
27
+ background-color: #E5E5E5;
28
+ }
29
+
30
+ .menu-group .sdoc-color-menu.disabled .sdoc-color-toggle {
31
+ display: none;
32
+ }
33
+
34
+ .sdoc-color-menu .sdoc-color-icon {
35
+ height: 12px;
36
+ width: 12px;
37
+ transform: scale(.85);
38
+ line-height: 12px;
39
+ }
40
+
41
+ .sdoc-color-menu .last-used-color {
42
+ width: 14px;
43
+ height: 3px;
44
+ border-radius: 1px;
45
+ margin-top: 1px;
46
+ border: 1px solid rgba(0, 0, 0, .08);
47
+ }
48
+
49
+ .sdoc-color-menu-popover .popover {
50
+ left: -24px !important;
51
+ }
52
+
53
+ .sdoc-color-menu-popover .sdoc-color-dropdown-menu {
54
+ width: 251px;
55
+ padding: 0 0 12px 0;
56
+ }
57
+
58
+ .sdoc-color-menu-popover .sdoc-color-no-color-container {
59
+ width: 100%;
60
+ height: 24px;
61
+ margin-bottom: 5px;
62
+ }
63
+
64
+ .sdoc-color-menu-popover .sdoc-color-no-color-content {
65
+ height: 100%;
66
+ width: 100%;
67
+ text-align: center;
68
+ border: 1px solid rgba(0, 0, 0, .12);
69
+ border-radius: 2px;
70
+ font-size: 12px;
71
+ line-height: 22px;
72
+ cursor: pointer;
73
+ }
74
+
75
+ .sdoc-color-menu-popover .sdoc-color-default-colors-container {
76
+ display: flex;
77
+ flex-wrap: wrap;
78
+ }
79
+
80
+ .sdoc-color-menu-popover .sdoc-color-item {
81
+ position: relative;
82
+ height: 20px;
83
+ width: 20px;
84
+ margin-right: 3px;
85
+ margin-bottom: 3px;
86
+ border: 0.5px solid rgba(0, 0, 0, .08);
87
+ }
88
+
89
+ .sdoc-color-menu-popover .sdoc-color-item:not(.selected):hover::before {
90
+ content: '';
91
+ position: absolute;
92
+ width: calc(100% + 5px);
93
+ height: calc((100% + 5px));
94
+ top: -2.5px;
95
+ left: -2.5px;
96
+ pointer-events: none;
97
+ border: 1px solid rgba(0, 0, 0, .24);
98
+ }
99
+
100
+ .sdoc-color-menu-popover .sdoc-color-item.selected::after {
101
+ content: '';
102
+ position: absolute;
103
+ width: calc(100% + 5px);
104
+ height: calc((100% + 5px));
105
+ top: -2.5px;
106
+ left: -2.5px;
107
+ pointer-events: none;
108
+ border: 1px solid rgba(0, 0, 0, .88);
109
+ }
110
+
111
+ .sdoc-color-menu-popover .sdoc-color-item:hover {
112
+ cursor: pointer;
113
+ }
114
+
115
+ .sdoc-color-menu-popover .sdoc-color-item:nth-child(10n) {
116
+ margin-right: 0px;
117
+ }
118
+
119
+ .sdoc-color-menu-popover .sdoc-color-sub-title {
120
+ font-size: 11px;
121
+ line-height: 16px;
122
+ margin: 7px 0;
123
+ color: rgba(0, 0, 0, 0.4);
124
+ }
125
+
126
+ .sdoc-color-menu-popover .sdoc-colors-divider {
127
+ width: 100%;
128
+ height: 1px;
129
+ border-bottom: 1px solid rgba(0, 0, 0, 0.08);
130
+ margin: 0px 0 8px 0;
131
+ }
132
+
133
+ .sdoc-color-menu-popover .sdoc-more-colors {
134
+ display: flex;
135
+ align-items: center;
136
+ justify-content: space-between;
137
+ height: 30px;
138
+ font-size: 12px;
139
+ padding: 0 12px;
140
+ }
141
+
142
+ .sdoc-color-menu-popover .sdoc-more-colors .sdocfont {
143
+ font-size: 12px;
144
+ transform: scale(.6);
145
+ color: #888;
146
+ }
147
+
148
+ .sdoc-color-menu-popover .sdoc-more-colors.show-pick {
149
+ cursor: pointer;
150
+ background-color: rgba(51, 77, 102, .06);
151
+ }
152
+
153
+ .sdoc-more-colors-popover .popover {
154
+ left: 10px !important;
155
+ }
156
+
157
+ /* commission */
158
+ .menu-group #button-sdoc-highlight-color .sdoc-color-icon {
159
+ position: relative;
160
+ left: 1px;
161
+ }
162
+
163
+ .sdoc-table-cell-bg-colors-popover .popover {
164
+ margin-left: 30px;
165
+ }
166
+
167
+ .sdoc-table-more-colors.sdoc-more-colors-popover .popover {
168
+ margin-left: -8px;
169
+ }
@@ -1,4 +1,3 @@
1
1
  import TableMenu from './table-menu';
2
- import ActiveTableMenu from './active-table-menu';
3
2
  import TableContextMenu from './table-context-menu';
4
- export { TableMenu, ActiveTableMenu, TableContextMenu };
3
+ export { TableMenu, TableContextMenu };
@@ -13,6 +13,7 @@ import { INTERNAL_EVENT } from '../../../../../constants';
13
13
  import VerticalAlignPopover from '../vertical-align-popover';
14
14
  import HorizontalAlignPopover from '../horizontal-align-popover';
15
15
  import KebabToCamel from '../../../../../utils/Kebab-to-camel';
16
+ import ColorSelectorPopover from '../color-selector-popover';
16
17
  import './index.css';
17
18
  class TableContextMenu extends React.Component {
18
19
  constructor(props) {
@@ -76,6 +77,7 @@ class TableContextMenu extends React.Component {
76
77
  this.eventBus = EventBus.getInstance();
77
78
  this.horizontalAlignRef = React.createRef();
78
79
  this.verticalAlignRef = React.createRef();
80
+ this.colorSelectorRef = React.createRef();
79
81
  }
80
82
  componentDidMount() {
81
83
  this.position = this.props.contextMenuPosition;
@@ -203,6 +205,15 @@ class TableContextMenu extends React.Component {
203
205
  editor: editor,
204
206
  readonly: readonly,
205
207
  verticalAlign: verticalAlign
208
+ }), /*#__PURE__*/React.createElement("button", {
209
+ ref: this.colorSelectorRef,
210
+ className: "dropdown-item side-extendable"
211
+ }, /*#__PURE__*/React.createElement("span", null, t('Background_color')), /*#__PURE__*/React.createElement("i", {
212
+ className: "sdocfont sdoc-right-slide"
213
+ })), /*#__PURE__*/React.createElement(ColorSelectorPopover, {
214
+ target: this.colorSelectorRef,
215
+ editor: editor,
216
+ readonly: readonly
206
217
  }), /*#__PURE__*/React.createElement("div", {
207
218
  className: 'seafile-divider dropdown-divider'
208
219
  }), /*#__PURE__*/React.createElement("button", {
@@ -12,7 +12,6 @@ import ClearFormatMenu from '../../plugins/clear-format/menu';
12
12
  import HistoryMenu from './redo-undo';
13
13
  import Font from '../../plugins/font/menu';
14
14
  import InsertToolbar from './insert-toolbar';
15
- import ActiveTableMenu from '../../plugins/table/menu/active-table-menu';
16
15
  import CalloutMenu from '../../plugins/callout/menu';
17
16
  import SearchReplaceMenu from '../../plugins/search-replace/menu';
18
17
  import { getSelectedNodeByType } from '../../core';
@@ -63,10 +62,7 @@ const HeaderToolbar = _ref => {
63
62
  }), /*#__PURE__*/React.createElement(CalloutMenu, {
64
63
  editor: editor,
65
64
  readonly: readonly
66
- })), /*#__PURE__*/React.createElement(ActiveTableMenu, {
67
- editor: editor,
68
- readonly: readonly
69
- }), /*#__PURE__*/React.createElement(MenuGroup, {
65
+ })), /*#__PURE__*/React.createElement(MenuGroup, {
70
66
  className: "menu-group sdoc-editor-toolbar-right-menu"
71
67
  }, /*#__PURE__*/React.createElement(SearchReplaceMenu, {
72
68
  editor: editor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -1,42 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import React, { useCallback } from 'react';
3
- import { ColorMenu } from '../../../../commons';
4
- import { RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY } from '../../../../constants';
5
- import { setCellStyle } from '../../helpers';
6
- import { useColorContext } from '../../../../../hooks/use-color-context';
7
- const menuConfig = {
8
- id: 'sdoc_background_color',
9
- iconClass: 'sdocfont sdoc-bg-color',
10
- text: 'Background_color'
11
- };
12
- const CellBackgroundColorMenu = _ref => {
13
- let {
14
- isRichEditor,
15
- className,
16
- editor
17
- } = _ref;
18
- const {
19
- lastUsedTableCellBackgroundColor,
20
- updateLastUsedTableCellBackgroundColor
21
- } = useColorContext();
22
- const setColor = useCallback(color => {
23
- setCellStyle(editor, {
24
- background_color: color
25
- });
26
- }, [editor]);
27
- const props = _objectSpread(_objectSpread({
28
- isRichEditor,
29
- className,
30
- disabled: false,
31
- isActive: false
32
- }, menuConfig), {}, {
33
- onMouseDown: () => {},
34
- setColor: setColor,
35
- recentUsedColorsKey: RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY,
36
- lastUsedColor: lastUsedTableCellBackgroundColor,
37
- updateLastUsedColor: updateLastUsedTableCellBackgroundColor,
38
- popoverClassName: 'sdoc-table-cell-bg-colors-popover'
39
- });
40
- return /*#__PURE__*/React.createElement(ColorMenu, props);
41
- };
42
- export default CellBackgroundColorMenu;
@@ -1,15 +0,0 @@
1
- .sdoc-table-menu-group .sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-icon {
2
- width: 24px;
3
- }
4
-
5
- .sdoc-table-menu-group .sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-triangle {
6
- width: 12px;
7
- }
8
-
9
- .sdoc-table-menu-group .sdoc-color-menu .last-used-color-container {
10
- height: 100%;
11
- }
12
-
13
- .sdoc-table-menu-popover .sdoc-dropdown-menu-item {
14
- font-size: 14px;
15
- }
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { withTranslation } from 'react-i18next';
3
- import { MenuGroup } from '../../../../commons';
4
- import { isAllInTable } from '../../helpers';
5
- import CellBackgroundColorMenu from './cell-bg-color-menu';
6
- import './index.css';
7
- const ActiveTableMenu = _ref => {
8
- let {
9
- isRichEditor,
10
- className,
11
- editor,
12
- readonly
13
- } = _ref;
14
- if (!isAllInTable(editor)) return null;
15
- return /*#__PURE__*/React.createElement(MenuGroup, {
16
- className: "menu-group sdoc-table-menu-group"
17
- }, /*#__PURE__*/React.createElement(CellBackgroundColorMenu, {
18
- editor: editor,
19
- isRichEditor: isRichEditor,
20
- className: className,
21
- readonly: readonly
22
- }));
23
- };
24
- export default withTranslation('sdoc-editor')(ActiveTableMenu);