@seafile/sdoc-editor 2.0.60 → 2.0.62

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.
@@ -11,7 +11,8 @@ class Column {
11
11
  this.children = [(0, _core.generateDefaultText)()];
12
12
  this.data = {
13
13
  key: option.value,
14
- name: option.label
14
+ name: option.label,
15
+ icon_class: option.iconClass
15
16
  };
16
17
  }
17
18
  }
@@ -0,0 +1,36 @@
1
+ .sdoc-seatable-column-label-container {
2
+ position: absolute;
3
+ height: 42px;
4
+ z-index: 101;
5
+ width: fit-content;
6
+ max-width: 250px;
7
+ }
8
+
9
+ .sdoc-seatable-column-label-container .label-container {
10
+ height: 36px;
11
+ width: 100%;
12
+ padding: 7px 8px;
13
+ background-color: #fff;
14
+ display: flex;
15
+ justify-content: space-around;
16
+ align-items: center;
17
+ border-radius: 3px;
18
+ box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
19
+ border: 1px solid #e8e8e8;
20
+ }
21
+
22
+ .sdoc-seatable-column-label-container .label-container .control-icon {
23
+ cursor: default;
24
+ margin-right: 5px;
25
+ flex-shrink: 0;
26
+ font-size: 12px;
27
+ color: #444;
28
+ }
29
+
30
+ .sdoc-seatable-column-label-container .label-container .control-label {
31
+ white-space: nowrap;
32
+ overflow: hidden;
33
+ text-overflow: ellipsis;
34
+ flex-grow: 1;
35
+ font-size: 14px;
36
+ }
@@ -9,6 +9,10 @@ exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _slateReact = require("@seafile/slate-react");
11
11
  var _mdToHtml = _interopRequireDefault(require("../../../../slate-convert/md-to-html"));
12
+ var _useScrollContext = require("../../../hooks/use-scroll-context");
13
+ var _utils = require("../../utils");
14
+ var _commons = require("../../commons");
15
+ require("./render-elem.css");
12
16
  const Column = _ref => {
13
17
  let {
14
18
  props,
@@ -20,7 +24,13 @@ const Column = _ref => {
20
24
  children
21
25
  } = props;
22
26
  const isReadOnly = (0, _slateReact.useReadOnly)();
23
- const isSelected = (0, _slateReact.useSelected)();
27
+ const scrollRef = (0, _useScrollContext.useScrollContext)();
28
+ const seaTableColumnRef = (0, _react.useRef)(null);
29
+ const [menuPosition, setMenuPosition] = (0, _react.useState)({
30
+ top: '',
31
+ left: ''
32
+ });
33
+ const [isShowLabel, setIsShowLabel] = (0, _react.useState)(false);
24
34
  const [columnValue, setColumnValue] = (0, _react.useState)('');
25
35
  const data = element.data || {};
26
36
  const {
@@ -49,14 +59,24 @@ const Column = _ref => {
49
59
  });
50
60
  }
51
61
  }, [editor, element.data, isLongTextColumn, editor.currentRowIdx]);
52
- const [isClicked, setIsClicked] = (0, _react.useState)(false);
62
+ const handleScroll = (0, _react.useCallback)(e => {
63
+ if (isReadOnly) return;
64
+ if (e.currentTarget.scrollTop) {
65
+ const menuPosition = (0, _utils.getMenuPosition)(seaTableColumnRef.current, editor);
66
+ setMenuPosition(menuPosition);
67
+ }
68
+ }, [editor, isReadOnly]);
53
69
  (0, _react.useEffect)(() => {
54
- if (isSelected && !isReadOnly) {
55
- setIsClicked(true);
56
- } else {
57
- setIsClicked(false);
70
+ if (isReadOnly) return;
71
+ let observerRefValue = null;
72
+ if (scrollRef.current) {
73
+ scrollRef.current.addEventListener('scroll', handleScroll);
74
+ observerRefValue = scrollRef.current;
58
75
  }
59
- }, [isSelected, isReadOnly]);
76
+ return () => {
77
+ observerRefValue.removeEventListener('scroll', handleScroll);
78
+ };
79
+ }, [handleScroll, isReadOnly, scrollRef]);
60
80
  const {
61
81
  font_size = null,
62
82
  font = null,
@@ -72,8 +92,8 @@ const Column = _ref => {
72
92
  border: '1px solid transparent',
73
93
  userSelect: 'none',
74
94
  display: 'inline-block',
75
- ...(isClicked && {
76
- border: '1px solid red'
95
+ ...(isShowLabel && {
96
+ border: '1px solid #007bff'
77
97
  }),
78
98
  ...(font_size && {
79
99
  fontSize: font_size
@@ -100,16 +120,60 @@ const Column = _ref => {
100
120
  textDecoration: 'line-through'
101
121
  })
102
122
  };
123
+ const onColumnClick = (0, _react.useCallback)(event => {
124
+ event.stopPropagation();
125
+ if (isReadOnly || isShowLabel) return;
126
+ const {
127
+ top,
128
+ left
129
+ } = seaTableColumnRef.current.getBoundingClientRect();
130
+ const menuTop = top - 42; // top = top distance - menu height
131
+ const newMenuPosition = {
132
+ top: menuTop,
133
+ left: left // left = callout left distance
134
+ };
135
+ // 201 is distance with browser top
136
+ if (menuTop <= 201) {
137
+ newMenuPosition['display'] = 'none';
138
+ }
139
+ setMenuPosition(newMenuPosition);
140
+ setIsShowLabel(true);
141
+ }, [isReadOnly, isShowLabel]);
142
+ (0, _react.useEffect)(() => {
143
+ const onHideColumnLabel = event => {
144
+ if (seaTableColumnRef.current && !seaTableColumnRef.current.contains(event.target)) {
145
+ setIsShowLabel(false);
146
+ }
147
+ };
148
+ document.addEventListener('click', onHideColumnLabel, true);
149
+ return () => {
150
+ document.removeEventListener('click', onHideColumnLabel, true);
151
+ };
152
+ }, []);
103
153
  return /*#__PURE__*/_react.default.createElement("span", Object.assign({}, attributes, {
104
- style: style
105
- }), !isLongTextColumn && columnValue, isLongTextColumn && /*#__PURE__*/_react.default.createElement("div", {
154
+ style: style,
155
+ ref: seaTableColumnRef,
156
+ onClick: onColumnClick
157
+ }), /*#__PURE__*/_react.default.createElement("span", null, !isLongTextColumn && columnValue, isLongTextColumn && /*#__PURE__*/_react.default.createElement("div", {
106
158
  style: {
107
159
  padding: '10px'
108
160
  },
109
161
  dangerouslySetInnerHTML: {
110
162
  __html: columnValue
111
163
  }
112
- }), children);
164
+ }), children), isShowLabel && /*#__PURE__*/_react.default.createElement(_commons.ElementPopover, null, /*#__PURE__*/_react.default.createElement("div", {
165
+ className: "sdoc-seatable-column-label-container",
166
+ style: menuPosition,
167
+ contentEditable: false,
168
+ "data-slate-node": null,
169
+ "data-slate-editor": false
170
+ }, /*#__PURE__*/_react.default.createElement("div", {
171
+ className: "label-container"
172
+ }, /*#__PURE__*/_react.default.createElement("span", {
173
+ className: `control-icon ${data.icon_class}`
174
+ }), /*#__PURE__*/_react.default.createElement("span", {
175
+ className: "control-label"
176
+ }, data.name)))));
113
177
  };
114
178
  const renderColumn = (props, editor) => {
115
179
  return /*#__PURE__*/_react.default.createElement(Column, {
@@ -21,7 +21,7 @@
21
21
  }
22
22
 
23
23
  .seatable-view-container.selected {
24
- box-shadow: 0 0 0 2px #0aba45;
24
+ box-shadow: 0 0 0 2px #007bff;
25
25
  }
26
26
 
27
27
  .seatable-view-container .seatable-view-records {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.60",
3
+ "version": "2.0.62",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
7
7
  "dependencies": {
8
8
  "@seafile/print-js": "1.6.6",
9
9
  "@seafile/react-image-lightbox": "4.0.2",
10
- "@seafile/sdoc-editor": "2.0.59",
10
+ "@seafile/sdoc-editor": "2.0.60",
11
11
  "@seafile/slate": "0.91.8",
12
12
  "@seafile/slate-history": "0.86.2",
13
13
  "@seafile/slate-hyperscript": "0.81.7",