@seafile/sea-email-editor 0.0.3 → 0.0.5

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.
@@ -1,7 +1,7 @@
1
1
  .sea-email-table-context-menu {
2
2
  height: fit-content;
3
3
  width: fit-content;
4
- position: absolute;
4
+ position: fixed;
5
5
  }
6
6
 
7
7
  .sea-email-table-context-menu .popover {
@@ -45,9 +45,15 @@ const ContextMenu = _ref => {
45
45
  top,
46
46
  left
47
47
  } = position;
48
+ const {
49
+ width,
50
+ height
51
+ } = contextMenuRef.current.getBoundingClientRect();
52
+ const validTop = window.innerHeight - top >= height ? top : window.innerHeight - height;
53
+ const validLeft = window.innerWidth - left >= width ? left : window.innerWidth - width;
48
54
  setContextMenuStyle({
49
- top,
50
- left,
55
+ top: validTop,
56
+ left: validLeft,
51
57
  zIndex: '1071',
52
58
  display: 'block'
53
59
  });
@@ -66,11 +72,11 @@ const ContextMenu = _ref => {
66
72
  };
67
73
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
68
74
  contentEditable: false,
69
- ref: contextMenuRef,
70
75
  style: contextMenuStyle,
71
76
  className: "sea-email-option-editor-popover show sea-email-table-context-menu",
72
77
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
73
78
  className: "popover show bs-popover-auto",
79
+ ref: contextMenuRef,
74
80
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
75
81
  className: "popover-inner",
76
82
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
@@ -12,7 +12,6 @@ var _slate = require("slate");
12
12
  var _classnames = _interopRequireDefault(require("classnames"));
13
13
  var _constant = require("../constant");
14
14
  var _contextMenu = _interopRequireDefault(require("../context-menu"));
15
- var _helper = require("../helper");
16
15
  var _core = require("../../../core");
17
16
  var _constants = require("../../../constants");
18
17
  var _eventBus = _interopRequireDefault(require("../../../../utils/event-bus"));
@@ -165,8 +164,14 @@ const RenderTableContainer = (_ref, editor) => {
165
164
  }
166
165
  e.preventDefault();
167
166
  e.stopPropagation();
168
- const position = (0, _helper.getContextMenuPosition)(e, tableRef);
169
- setContextMenuPosition(position);
167
+ const {
168
+ clientY,
169
+ clientX
170
+ } = e;
171
+ setContextMenuPosition({
172
+ left: clientX,
173
+ top: clientY
174
+ });
170
175
  setIsShowContextMenu(true);
171
176
  }, []);
172
177
  const handleCloseContextMenu = () => {
@@ -133,7 +133,7 @@ Object.defineProperty(exports, "UNORDERED_LIST", {
133
133
  }
134
134
  });
135
135
  var _elementTypes = require("../../extension/constants/element-types");
136
- const TOP_LEVEL_TYPES = exports.TOP_LEVEL_TYPES = [_elementTypes.BLOCKQUOTE, _elementTypes.HEADER1, _elementTypes.HEADER2, _elementTypes.HEADER3, _elementTypes.HEADER4, _elementTypes.HEADER5, _elementTypes.HEADER6, _elementTypes.ORDERED_LIST, _elementTypes.UNORDERED_LIST, _elementTypes.CHECK_LIST_ITEM, _elementTypes.PARAGRAPH, _elementTypes.CODE_BLOCK, _elementTypes.TABLE];
136
+ const TOP_LEVEL_TYPES = exports.TOP_LEVEL_TYPES = [_elementTypes.BLOCKQUOTE, _elementTypes.HEADER1, _elementTypes.HEADER2, _elementTypes.HEADER3, _elementTypes.HEADER4, _elementTypes.HEADER5, _elementTypes.HEADER6, _elementTypes.ORDERED_LIST, _elementTypes.UNORDERED_LIST, _elementTypes.CHECK_LIST_ITEM, _elementTypes.PARAGRAPH, _elementTypes.CODE_BLOCK, _elementTypes.TABLE, _elementTypes.P, _elementTypes.BR];
137
137
  const INLINE_LEVEL_TYPES = exports.INLINE_LEVEL_TYPES = [_elementTypes.IMAGE, _elementTypes.LINK];
138
138
  const HEADER_LIST = exports.HEADER_LIST = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
139
139
  const HEADER_TYPE_MAP = exports.HEADER_TYPE_MAP = {
@@ -78,6 +78,24 @@ const deserializeElements = function () {
78
78
  });
79
79
  return (0, _helper.formatInlineNodes)(nodes);
80
80
  };
81
+
82
+ // const formatTableNode = (node, path) => {
83
+ // if (node.type === TABLE) {
84
+ // const columnsCount = Math.max(...node.children.map(row => row.children.length));
85
+ // node.children = node.children.map(row => {
86
+ // for (let i = row.children.length; i < columnsCount; i++) {
87
+ // row.children.push(generateTableCell());
88
+ // }
89
+ // return row;
90
+ // });
91
+ // return node;
92
+ // }
93
+ // if (Array.isArray(node.children)) {
94
+ // node.children = node.children.map((child, index) => formatTableNode(child, [...path, index]));
95
+ // }
96
+ // return node;
97
+ // };
98
+
81
99
  const formatElementNodes = nodes => {
82
100
  if (nodes.length === 0) {
83
101
  return [{
@@ -39,7 +39,7 @@ const tableRule = (element, parseChild) => {
39
39
  }
40
40
  if (nodeName === 'TH' || nodeName === 'TD') {
41
41
  const children = Array.from(childNodes);
42
- const cellChildren = children.flatMap(child => {
42
+ const cellChildren = children.length > 0 ? children.flatMap(child => {
43
43
  // Replace paragraph node with text node
44
44
  if (child.nodeName === 'P') {
45
45
  const textContent = Array.from(child.childNodes).map(child => child.textContent).join('');
@@ -51,7 +51,11 @@ const tableRule = (element, parseChild) => {
51
51
  return (0, _helper.mergeElementOther2SlateNode)(child, node);
52
52
  }
53
53
  return parseChild([child]);
54
- });
54
+ }) : [{
55
+ id: _slugid.default.nice(),
56
+ type: 'text',
57
+ text: ''
58
+ }];
55
59
  const node = {
56
60
  id: _slugid.default.nice(),
57
61
  type: _constants.TABLE_CELL,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.findElementByPath = exports.default = void 0;
7
7
  var _slate = require("slate");
8
8
  var _constants = require("../../extension/constants");
9
9
  const isContentValid = value => {
@@ -31,11 +31,15 @@ const translateElement = (value, element, path) => {
31
31
  ...(style || {})
32
32
  };
33
33
  if (element.type === _constants.ElementTypes.TABLE_CELL) {
34
- const tablePath = path.slice(0, -2);
35
- const tableElement = findElementByPath(value, tablePath);
36
- const tdIndex = path.at(-1);
37
- const align = tableElement.align[tdIndex] || 'left';
38
- customizeStyle['textAlign'] = align;
34
+ try {
35
+ const tablePath = path.slice(0, -2);
36
+ const tableElement = findElementByPath(value, tablePath);
37
+ const tdIndex = path.at(-1);
38
+ const align = tableElement.align[tdIndex] || 'left';
39
+ customizeStyle['textAlign'] = align;
40
+ } catch {
41
+ //
42
+ }
39
43
  }
40
44
  let styleString = Object.keys(customizeStyle).map(styleKey => `${styleKey.split(/(?=[A-Z])/).join('-').toLowerCase()}: ${customizeStyle[styleKey]};`).join('');
41
45
  styleString = styleString ? ` style="${styleString}"` : '';
@@ -69,8 +73,9 @@ const ELEMENT_HTML_TAG = {
69
73
  [_constants.ElementTypes.TABLE_CELL]: 'td'
70
74
  };
71
75
  const findElementByPath = (value, path) => {
72
- return path.reduce((element, pathIndex) => element[pathIndex], value);
76
+ return path.reduce((element, pathIndex, currentIndex) => currentIndex === 0 ? element[pathIndex] : element === null || element === void 0 ? void 0 : element.children[pathIndex], value);
73
77
  };
78
+ exports.findElementByPath = findElementByPath;
74
79
  const element2Html = (value, element, path) => {
75
80
  const {
76
81
  type
@@ -138,6 +143,7 @@ const slateToHtml = value => {
138
143
  value.forEach((element, index) => {
139
144
  html += element2Html(value, element, [index]);
140
145
  });
146
+ console.log(html);
141
147
  return html;
142
148
  };
143
149
  var _default = exports.default = slateToHtml;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sea-email-editor",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {