@seafile/sdoc-editor 0.1.157 → 0.1.159-beta9

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 (26) hide show
  1. package/dist/basic-sdk/editor.js +27 -0
  2. package/dist/basic-sdk/extension/constants/element-type.js +8 -8
  3. package/dist/basic-sdk/extension/constants/menus-config.js +27 -16
  4. package/dist/basic-sdk/extension/plugins/file-link/render-elem.css +4 -0
  5. package/dist/basic-sdk/extension/plugins/file-link/render-elem.js +1 -4
  6. package/dist/basic-sdk/extension/plugins/font/helpers.js +16 -12
  7. package/dist/basic-sdk/extension/plugins/html/rules/text.js +5 -5
  8. package/dist/basic-sdk/extension/plugins/markdown/plugin.js +4 -4
  9. package/dist/basic-sdk/extension/plugins/table/constants/index.js +5 -2
  10. package/dist/basic-sdk/extension/plugins/table/helpers.js +13 -8
  11. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-bg-color-menu.js +1 -1
  12. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-text-align-menu.js +3 -3
  13. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -2
  14. package/dist/basic-sdk/extension/plugins/table/render/render-row.js +7 -9
  15. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +3 -3
  16. package/dist/basic-sdk/extension/plugins/text-style/plugin.js +3 -2
  17. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +20 -19
  18. package/dist/basic-sdk/utils/diff.js +16 -16
  19. package/dist/components/doc-operations/revision-operations/more-revision-operations/index.js +2 -1
  20. package/dist/constants/index.js +1 -0
  21. package/package.json +1 -1
  22. package/public/locales/en/sdoc-editor.json +2 -1
  23. package/public/locales/fr/sdoc-editor.json +154 -152
  24. package/public/locales/ru/sdoc-editor.json +50 -48
  25. package/public/locales/zh_CN/sdoc-editor.json +2 -1
  26. package/dist/basic-sdk/extension/plugins/text-style/model.js +0 -11
@@ -1,3 +1,4 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
3
4
  import { Editor } from '@seafile/slate';
@@ -11,6 +12,8 @@ import context from '../context';
11
12
  import { EditorContainer, EditorContent } from './layout';
12
13
  import SlateEditor from './slate-editor';
13
14
  import InsertElementDialog from './extension/commons/insert-element-dialog';
15
+ import { REVISION_FIRST_LOAD_KEY } from '../constants';
16
+ import toaster from '../components/toast';
14
17
  var SDocEditor = forwardRef(function (_ref, ref) {
15
18
  var document = _ref.document,
16
19
  config = _ref.config;
@@ -85,6 +88,30 @@ var SDocEditor = forwardRef(function (_ref, ref) {
85
88
  var originFilename = context.getSetting('originFilename');
86
89
  if (isSdocRevision) {
87
90
  window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
91
+ var searchParams = window.location.search || window.location.hash;
92
+ if (searchParams) {
93
+ var searchParamsIndex = searchParams.indexOf('?');
94
+ var validSearchParams = new URLSearchParams(searchParams.slice(searchParamsIndex + 1));
95
+ var _iterator = _createForOfIteratorHelper(validSearchParams),
96
+ _step;
97
+ try {
98
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
99
+ var query = _step.value;
100
+ var key = query[0];
101
+ var value = query[1];
102
+ if (key === REVISION_FIRST_LOAD_KEY && value === '1') {
103
+ var revisionId = context.getSetting('revisionId');
104
+ toaster.success(t('Revision_created', {
105
+ id: revisionId
106
+ }));
107
+ }
108
+ }
109
+ } catch (err) {
110
+ _iterator.e(err);
111
+ } finally {
112
+ _iterator.f();
113
+ }
114
+ }
88
115
  }
89
116
 
90
117
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -10,16 +10,16 @@ export var HEADER5 = 'header5';
10
10
  export var HEADER6 = 'header6';
11
11
  export var ORDERED_LIST = 'ordered_list';
12
12
  export var UNORDERED_LIST = 'unordered_list';
13
- export var LIST_ITEM = 'list-item';
14
- export var LIST_LIC = 'list-lic'; // placeholder
15
- export var CHECK_LIST_ITEM = 'check-list-item';
13
+ export var LIST_ITEM = 'list_item';
14
+ export var LIST_LIC = 'list_lic'; // placeholder
15
+ export var CHECK_LIST_ITEM = 'check_list_item';
16
16
  export var PARAGRAPH = 'paragraph';
17
- export var CODE_BLOCK = 'code-block';
18
- export var CODE_LINE = 'code-line';
17
+ export var CODE_BLOCK = 'code_block';
18
+ export var CODE_LINE = 'code_line';
19
19
  export var TABLE = 'table';
20
- export var TABLE_ROW = 'table-row';
21
- export var TABLE_CELL = 'table-cell';
20
+ export var TABLE_ROW = 'table_row';
21
+ export var TABLE_CELL = 'table_cell';
22
22
  export var LINK = 'link';
23
- export var SDOC_LINK = 'sdoc-link';
23
+ export var SDOC_LINK = 'sdoc_link';
24
24
  export var FILE_LINK = 'file_link';
25
25
  export var IMAGE = 'image';
@@ -8,18 +8,12 @@ export var CLEAR_FORMAT = 'clear_format';
8
8
  export var REMOVE_TABLE = 'remove_table';
9
9
 
10
10
  // text style
11
+ export var TEXT_STYLE = 'text_style';
11
12
  var ITALIC = 'italic';
12
13
  var BOLD = 'bold';
13
14
  var UNDERLINE = 'underline';
14
- var HIGHLIGHT_COLOR = 'highlight-color';
15
+ var HIGHLIGHT_COLOR = 'highlight_color';
15
16
  var COLOR = 'color';
16
- export var TEXT_STYLE = 'text_style';
17
- export var TEXT_STYLE_MAP = {
18
- ITALIC: ITALIC,
19
- BOLD: BOLD,
20
- BOLD_ITALIC: "".concat(BOLD, "-").concat(ITALIC),
21
- COLOR: COLOR
22
- };
23
17
 
24
18
  // text-align
25
19
  export var TEXT_ALIGN = 'text_align';
@@ -33,6 +27,23 @@ var SUBSCRIPT = 'subscript';
33
27
  // const FONT_SIZE_INCREASE = 'font-size-increase';
34
28
  // const FONT_SIZE_REDUCE = 'font-size-reduce';
35
29
 
30
+ export var TEXT_STYLE_MAP = {
31
+ COLOR: COLOR,
32
+ HIGHLIGHT_COLOR: HIGHLIGHT_COLOR,
33
+ FONT_SIZE: 'font_size',
34
+ FONT: 'font',
35
+ BOLD: BOLD,
36
+ ITALIC: ITALIC,
37
+ BOLD_ITALIC: "".concat(BOLD, "_").concat(ITALIC),
38
+ UNDERLINE: UNDERLINE,
39
+ STRIKETHROUGH: STRIKETHROUGH,
40
+ SUPERSCRIPT: SUPERSCRIPT,
41
+ SUBSCRIPT: SUBSCRIPT,
42
+ CODE: 'code',
43
+ DELETE: 'delete',
44
+ ADD: 'add'
45
+ };
46
+
36
47
  // header menu config
37
48
  export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CONFIG_MAP, BLOCKQUOTE, {
38
49
  id: "sdoc_".concat(BLOCKQUOTE),
@@ -74,22 +85,22 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
74
85
  id: ITALIC,
75
86
  iconClass: 'sdocfont sdoc-italic',
76
87
  text: 'Italic',
77
- type: 'ITALIC'
88
+ type: TEXT_STYLE_MAP.ITALIC
78
89
  }, {
79
90
  id: BOLD,
80
91
  iconClass: 'sdocfont sdoc-bold',
81
92
  text: 'Bold',
82
- type: 'BOLD'
93
+ type: TEXT_STYLE_MAP.BOLD
83
94
  }, {
84
95
  id: UNDERLINE,
85
96
  iconClass: 'sdocfont sdoc-underline',
86
97
  text: 'Underline',
87
- type: 'UNDERLINE'
98
+ type: TEXT_STYLE_MAP.UNDERLINE
88
99
  }, {
89
100
  id: "sdoc-".concat(HIGHLIGHT_COLOR),
90
101
  iconClass: 'sdocfont sdoc-highlight-color',
91
102
  text: 'Highlight_color',
92
- type: HIGHLIGHT_COLOR,
103
+ type: TEXT_STYLE_MAP.HIGHLIGHT_COLOR,
93
104
  isColor: true,
94
105
  recentUsedColorsKey: RECENT_USED_HIGHLIGHT_COLORS_KEY,
95
106
  defaultLastUsedColor: DEFAULT_LAST_USED_HIGHLIGHT_COLOR
@@ -97,7 +108,7 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
97
108
  id: "sdoc-font-".concat(COLOR),
98
109
  iconClass: 'sdocfont sdoc-font-color',
99
110
  text: 'Font_color',
100
- type: COLOR,
111
+ type: TEXT_STYLE_MAP.COLOR,
101
112
  defaultColor: DEFAULT_FONT_COLOR,
102
113
  isColor: true,
103
114
  recentUsedColorsKey: RECENT_USED_FONT_COLORS_KEY,
@@ -108,17 +119,17 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
108
119
  id: STRIKETHROUGH,
109
120
  iconClass: 'sdocfont sdoc-strikethrough',
110
121
  text: 'Strikethrough',
111
- type: 'STRIKETHROUGH'
122
+ type: TEXT_STYLE_MAP.STRIKETHROUGH
112
123
  }, {
113
124
  id: SUPERSCRIPT,
114
125
  iconClass: 'sdocfont sdoc-subscripts',
115
126
  text: 'Superscript',
116
- type: 'SUPERSCRIPT'
127
+ type: TEXT_STYLE_MAP.SUPERSCRIPT
117
128
  }, {
118
129
  id: SUBSCRIPT,
119
130
  iconClass: 'sdocfont sdoc-subscripts',
120
131
  text: 'Subscript',
121
- type: 'SUBSCRIPT'
132
+ type: TEXT_STYLE_MAP.SUBSCRIPT
122
133
  }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_ALIGN, [{
123
134
  id: ALIGN_LEFT,
124
135
  iconClass: 'sdocfont sdoc-align-left',
@@ -33,6 +33,10 @@
33
33
  position: absolute;
34
34
  top: 16px;
35
35
  left: 42px;
36
+ width: 330px;
37
+ overflow: hidden;
38
+ text-overflow: ellipsis;
39
+ white-space: nowrap;
36
40
  }
37
41
 
38
42
  .sdoc-file-card-link .sdoc-file-text-link a {
@@ -2,8 +2,6 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useCallback, useEffect, useState, useRef } from 'react';
4
4
  import classnames from 'classnames';
5
- import { Range } from '@seafile/slate';
6
- import { useReadOnly } from '@seafile/slate-react';
7
5
  import { useScrollContext } from '../../../hooks/use-scroll-context';
8
6
  import { unwrapLinkNode, getUrl } from './helpers';
9
7
  import HoverMenu from './hover-menu';
@@ -25,7 +23,6 @@ var FileLink = function FileLink(_ref) {
25
23
  _useState4 = _slicedToArray(_useState3, 2),
26
24
  menuPosition = _useState4[0],
27
25
  setMenuPosition = _useState4[1];
28
- var readOnly = useReadOnly();
29
26
  var registerEventHandle = useCallback(function () {
30
27
  document.addEventListener('click', onHideInsertHoverMenu);
31
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -125,7 +122,7 @@ var FileLink = function FileLink(_ref) {
125
122
  e.preventDefault();
126
123
  },
127
124
  title: element.title
128
- }, children))), isShowInsertHoverMenu && (!readOnly && Range.isCollapsed(editor.selection) || readOnly) && /*#__PURE__*/React.createElement(HoverMenu, {
125
+ }, children))), isShowInsertHoverMenu && /*#__PURE__*/React.createElement(HoverMenu, {
129
126
  editor: editor,
130
127
  menuPosition: menuPosition,
131
128
  element: element,
@@ -1,7 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import { Editor, Element } from '@seafile/slate';
4
- import { CODE_BLOCK, IMAGE, DEFAULT_FONT, GOOGLE_FONT_CLASS, FONT, SDOC_FONT_SIZE, HEADERS, TITLE, SUBTITLE, CODE_LINE } from '../../constants';
4
+ import { CODE_BLOCK, IMAGE, DEFAULT_FONT, GOOGLE_FONT_CLASS, FONT, SDOC_FONT_SIZE, HEADERS, TITLE, SUBTITLE, CODE_LINE, TEXT_STYLE_MAP } from '../../constants';
5
5
  import { focusEditor, getParentNode } from '../../core';
6
6
  import context from '../../../../context';
7
7
  import { isMac } from '../../../../utils';
@@ -28,13 +28,15 @@ export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
28
28
  export var getFontSize = function getFontSize(editor) {
29
29
  var selection = editor.selection;
30
30
  var marks = Editor.marks(editor);
31
- if (marks && marks['font-size']) return marks['font-size'];
31
+ if (marks && marks[TEXT_STYLE_MAP.FONT_SIZE]) {
32
+ return marks[TEXT_STYLE_MAP.FONT_SIZE];
33
+ }
32
34
  if (!selection) return SDOC_FONT_SIZE.DEFAULT;
33
35
  var _Editor$nodes3 = Editor.nodes(editor, {
34
36
  at: Editor.unhangRange(editor, selection),
35
37
  match: function match(n) {
36
38
  if (!Editor.isEditor(n) && !Element.isElement(n)) {
37
- if (n['font-size']) return true;
39
+ if (n[TEXT_STYLE_MAP.FONT_SIZE]) return true;
38
40
  var _parentNode = getParentNode(editor.children, n.id);
39
41
  if (!_parentNode) return false;
40
42
  if ([TITLE, SUBTITLE].concat(_toConsumableArray(HEADERS), [CODE_LINE]).includes(_parentNode.type)) {
@@ -48,14 +50,16 @@ export var getFontSize = function getFontSize(editor) {
48
50
  _Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1),
49
51
  match = _Editor$nodes4[0];
50
52
  if (!match) return SDOC_FONT_SIZE.DEFAULT;
51
- // has font-size attrubute
53
+ // has font-size attribute
52
54
  var matched = match[0];
53
- if (matched['font-size']) return matched['font-size'];
55
+ if (matched[TEXT_STYLE_MAP.FONT_SIZE]) {
56
+ return matched[TEXT_STYLE_MAP.FONT_SIZE];
57
+ }
54
58
  var parentNode = getParentNode(editor.children, matched.id);
55
59
  return SDOC_FONT_SIZE[parentNode.type];
56
60
  };
57
61
  export var setFontSize = function setFontSize(editor, value) {
58
- Editor.addMark(editor, 'font-size', value);
62
+ Editor.addMark(editor, TEXT_STYLE_MAP.FONT_SIZE, value);
59
63
  focusEditor(editor);
60
64
  };
61
65
  export var scaleFontSize = function scaleFontSize(editor, type) {
@@ -77,7 +81,9 @@ export var scaleFontSize = function scaleFontSize(editor, type) {
77
81
  export var getFont = function getFont(editor) {
78
82
  var selection = editor.selection;
79
83
  var marks = Editor.marks(editor);
80
- if (marks && marks['font']) return marks['font'];
84
+ if (marks && marks[TEXT_STYLE_MAP.FONT]) {
85
+ return marks[TEXT_STYLE_MAP.FONT];
86
+ }
81
87
  if (!selection) return DEFAULT_FONT;
82
88
  var _Editor$nodes5 = Editor.nodes(editor, {
83
89
  at: Editor.unhangRange(editor, selection),
@@ -88,10 +94,10 @@ export var getFont = function getFont(editor) {
88
94
  _Editor$nodes6 = _slicedToArray(_Editor$nodes5, 1),
89
95
  match = _Editor$nodes6[0];
90
96
  if (!match) return DEFAULT_FONT;
91
- return match[0]['font'];
97
+ return match[0][TEXT_STYLE_MAP.FONT];
92
98
  };
93
99
  export var setFont = function setFont(editor, value) {
94
- Editor.addMark(editor, 'font', value);
100
+ Editor.addMark(editor, TEXT_STYLE_MAP.FONT, value);
95
101
  focusEditor(editor);
96
102
  };
97
103
  export var hasFontLoaded = function hasFontLoaded() {
@@ -126,9 +132,7 @@ export var loadFont = function loadFont() {
126
132
  fontLink.className = GOOGLE_FONT_CLASS;
127
133
  document.body.appendChild(fontLink);
128
134
  };
129
- export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight, leaf) {
130
- var isCodeBlock = leaf && Object.keys(leaf).includes('token');
131
- if (isCodeBlock) return '';
135
+ export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight) {
132
136
  var lang = context.getSetting('lang') || 'zh-cn';
133
137
  if (fontName === DEFAULT_FONT) {
134
138
  return "'Arial', ".concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");
@@ -13,7 +13,7 @@ var textRule = function textRule(element, parseChild) {
13
13
  return {
14
14
  level: 'level3',
15
15
  id: slugid.nice(),
16
- BOLD: true,
16
+ bold: true,
17
17
  text: element.textContent
18
18
  };
19
19
  }
@@ -21,7 +21,7 @@ var textRule = function textRule(element, parseChild) {
21
21
  return {
22
22
  level: 'level3',
23
23
  id: slugid.nice(),
24
- CODE: true,
24
+ code: true,
25
25
  text: element.textContent
26
26
  };
27
27
  }
@@ -29,7 +29,7 @@ var textRule = function textRule(element, parseChild) {
29
29
  return {
30
30
  level: 'level3',
31
31
  id: slugid.nice(),
32
- DELETE: true,
32
+ delete: true,
33
33
  text: element.textContent
34
34
  };
35
35
  }
@@ -37,7 +37,7 @@ var textRule = function textRule(element, parseChild) {
37
37
  return {
38
38
  level: 'level3',
39
39
  id: slugid.nice(),
40
- ITALIC: true,
40
+ italic: true,
41
41
  text: element.textContent
42
42
  };
43
43
  }
@@ -45,7 +45,7 @@ var textRule = function textRule(element, parseChild) {
45
45
  return {
46
46
  level: 'level3',
47
47
  id: slugid.nice(),
48
- ADD: true,
48
+ add: true,
49
49
  text: element.textContent
50
50
  };
51
51
  }
@@ -92,8 +92,8 @@ var withMarkDown = function withMarkDown(editor) {
92
92
  voids: true
93
93
  });
94
94
  var newText = beforeText.slice(startOffset + 3, endOffset - 3);
95
- Editor.addMark(editor, 'BOLD', true);
96
- Editor.addMark(editor, 'ITALIC', true);
95
+ Editor.addMark(editor, TEXT_STYLE_MAP.BOLD, true);
96
+ Editor.addMark(editor, TEXT_STYLE_MAP.ITALIC, true);
97
97
  return insertText(newText);
98
98
  }
99
99
  }
@@ -114,7 +114,7 @@ var withMarkDown = function withMarkDown(editor) {
114
114
  },
115
115
  voids: true
116
116
  });
117
- var newType = boldType.toUpperCase();
117
+ var newType = boldType.toLowerCase();
118
118
  var _newText = beforeText.slice(_startOffset + 2, _endOffset - 2);
119
119
  Editor.addMark(editor, newType, true);
120
120
  return insertText(_newText);
@@ -134,7 +134,7 @@ var withMarkDown = function withMarkDown(editor) {
134
134
  },
135
135
  voids: true
136
136
  });
137
- var _newType = italicType.toUpperCase();
137
+ var _newType = italicType.toLowerCase();
138
138
  var _newText2 = beforeText.slice(_startOffset2 + 1, _endOffset2 - 1);
139
139
  Editor.addMark(editor, _newType, true);
140
140
  return insertText(_newText2);
@@ -23,6 +23,9 @@ export var TABLE_ELEMENT_POSITION = {
23
23
  };
24
24
  export var SELECTED_TABLE_CELL_BACKGROUND_COLOR = '#dee8fe';
25
25
  export var TABLE_CELL_STYLE = {
26
- TEXT_ALIGN: 'textAlign',
27
- BACKGROUND_COLOR: 'bg_color'
26
+ TEXT_ALIGN: 'text_align',
27
+ BACKGROUND_COLOR: 'background_color'
28
+ };
29
+ export var TABLE_ROW_STYLE = {
30
+ MIN_HEIGHT: 'min_height'
28
31
  };
@@ -1,13 +1,14 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
5
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
6
  import slugid from 'slugid';
6
7
  import { Editor, Range, Transforms, Point, Node } from '@seafile/slate';
7
8
  import { ReactEditor } from '@seafile/slate-react';
8
9
  import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, focusEditor, getNode, findPath, replaceNodeChildren } from '../../core';
9
10
  import { ELEMENT_TYPE, KEYBOARD, CLIPBOARD_FORMAT_KEY, INSERT_POSITION } from '../../constants';
10
- import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
11
+ import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, TABLE_ROW_STYLE } from './constants';
11
12
  import EventBus from '../../../utils/event-bus';
12
13
  import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../constants';
13
14
  import ObjectUtils from '../../../utils/object-utils';
@@ -64,9 +65,7 @@ export var generateTableRow = function generateTableRow(colsCount) {
64
65
  id: slugid.nice(),
65
66
  type: ELEMENT_TYPE.TABLE_ROW,
66
67
  children: children,
67
- style: {
68
- minHeight: TABLE_ROW_MIN_HEIGHT
69
- }
68
+ style: _defineProperty({}, TABLE_ROW_STYLE.MIN_HEIGHT, TABLE_ROW_MIN_HEIGHT)
70
69
  };
71
70
  };
72
71
  export var generateEmptyTable = function generateEmptyTable(editor) {
@@ -389,11 +388,11 @@ export var setTableSelectedRange = function setTableSelectedRange(editor, range)
389
388
  export var updateTableRowHeight = function updateTableRowHeight(editor, element, rowHeight) {
390
389
  var path = findPath(editor, element);
391
390
  var targetNode = getNode(editor, path);
392
- if (targetNode.style && targetNode.style.minHeight === rowHeight) return;
391
+ var _targetNode$style = targetNode.style,
392
+ style = _targetNode$style === void 0 ? {} : _targetNode$style;
393
+ if (style[TABLE_ROW_STYLE.MIN_HEIGHT] === rowHeight) return;
393
394
  Transforms.setNodes(editor, {
394
- style: _objectSpread(_objectSpread({}, targetNode.style), {}, {
395
- minHeight: rowHeight
396
- })
395
+ style: _objectSpread(_objectSpread({}, style), {}, _defineProperty({}, TABLE_ROW_STYLE.MIN_HEIGHT, rowHeight))
397
396
  }, {
398
397
  at: path
399
398
  });
@@ -878,4 +877,10 @@ export var colorBlend = function colorBlend(c1, c2, ratio) {
878
877
  g = ('0' + (g || 0).toString(16)).slice(-2);
879
878
  b = ('0' + (b || 0).toString(16)).slice(-2);
880
879
  return '#' + r + g + b;
880
+ };
881
+ export var getRowHeight = function getRowHeight(element, rowIndex) {
882
+ var _element$style = element.style,
883
+ style = _element$style === void 0 ? {} : _element$style;
884
+ var rowHeight = style[TABLE_ROW_STYLE.MIN_HEIGHT] || TABLE_ROW_MIN_HEIGHT;
885
+ return rowIndex === 0 ? rowHeight + 1 : rowHeight;
881
886
  };
@@ -18,7 +18,7 @@ var CellBackgroundColorMenu = function CellBackgroundColorMenu(_ref) {
18
18
  updateLastUsedTableCellBackgroundColor = _useColorContext.updateLastUsedTableCellBackgroundColor;
19
19
  var setColor = useCallback(function (color) {
20
20
  setCellStyle(editor, {
21
- bg_color: color
21
+ background_color: color
22
22
  });
23
23
  }, [editor]);
24
24
  var props = _objectSpread(_objectSpread({
@@ -1,7 +1,9 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import React, { useCallback, useRef } from 'react';
2
3
  import { useTranslation } from 'react-i18next';
3
4
  import CommonMenu from './common-menu';
4
5
  import { setCellStyle } from '../../helpers';
6
+ import { TABLE_CELL_STYLE } from '../../constants';
5
7
  var CellTextAlignMenu = function CellTextAlignMenu(_ref) {
6
8
  var editor = _ref.editor,
7
9
  readonly = _ref.readonly;
@@ -10,9 +12,7 @@ var CellTextAlignMenu = function CellTextAlignMenu(_ref) {
10
12
  t = _useTranslation.t;
11
13
  var setTextAlignStyle = useCallback(function (textAlign) {
12
14
  if (readonly) return;
13
- setCellStyle(editor, {
14
- textAlign: textAlign
15
- });
15
+ setCellStyle(editor, _defineProperty({}, TABLE_CELL_STYLE.TEXT_ALIGN, textAlign));
16
16
  textAlignRef.current && textAlignRef.current.hidePopover();
17
17
  }, [editor, readonly]);
18
18
  return /*#__PURE__*/React.createElement(CommonMenu, {
@@ -40,7 +40,7 @@ var TableCell = function TableCell(_ref) {
40
40
  }, [editor, element]);
41
41
  var style = attributes.style || {};
42
42
  if (ObjectUtils.hasProperty(element.style, TABLE_CELL_STYLE.TEXT_ALIGN)) {
43
- style[TABLE_CELL_STYLE.TEXT_ALIGN] = element.style[TABLE_CELL_STYLE.TEXT_ALIGN];
43
+ style['textAlign'] = element.style[TABLE_CELL_STYLE.TEXT_ALIGN];
44
44
  }
45
45
  if (isSelected) {
46
46
  style['backgroundColor'] = SELECTED_TABLE_CELL_BACKGROUND_COLOR;
@@ -86,7 +86,7 @@ function renderTableCell(props) {
86
86
  // const cellValue = element;
87
87
  var style = attributes.style || {};
88
88
  if (ObjectUtils.hasProperty(element.style, TABLE_CELL_STYLE.TEXT_ALIGN)) {
89
- style[TABLE_CELL_STYLE.TEXT_ALIGN] = element[TABLE_CELL_STYLE.TEXT_ALIGN];
89
+ style['textAlign'] = element.style[TABLE_CELL_STYLE.TEXT_ALIGN];
90
90
  }
91
91
  if (ObjectUtils.hasProperty(element.style, TABLE_CELL_STYLE.BACKGROUND_COLOR) && element.style[TABLE_CELL_STYLE.BACKGROUND_COLOR]) {
92
92
  style['backgroundColor'] = element.style[TABLE_CELL_STYLE.BACKGROUND_COLOR];
@@ -6,12 +6,11 @@ import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
6
6
  import { ReactEditor } from '@seafile/slate-react';
7
7
  import { findPath } from '../../../core';
8
8
  import { TABLE_ROW_MIN_HEIGHT } from '../constants';
9
- import { updateTableRowHeight } from '../helpers';
9
+ import { getRowHeight, updateTableRowHeight } from '../helpers';
10
10
  import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
11
11
  import { useSettingSelectRangeContext, useResizeHandlersContext } from './hooks';
12
12
  import { useScrollContext } from '../../../../hooks/use-scroll-context';
13
13
  var TableRow = function TableRow(_ref) {
14
- var _element$style;
15
14
  var element = _ref.element,
16
15
  attributes = _ref.attributes,
17
16
  children = _ref.children;
@@ -29,10 +28,9 @@ var TableRow = function TableRow(_ref) {
29
28
  var rowPath = findPath(editor, element);
30
29
  var pathLength = rowPath ? rowPath.length : 0;
31
30
  var rowIndex = rowPath ? rowPath[pathLength - 1] : -1;
32
- var minHeight = ((_element$style = element.style) === null || _element$style === void 0 ? void 0 : _element$style.minHeight) || TABLE_ROW_MIN_HEIGHT;
33
- var initHeight = rowIndex === 0 ? minHeight + 1 : minHeight;
34
- var tableRow = useRef(initHeight);
35
- var _useState5 = useState(initHeight),
31
+ var rowHeight = getRowHeight(element, rowIndex);
32
+ var tableRow = useRef(rowHeight);
33
+ var _useState5 = useState(rowHeight),
36
34
  _useState6 = _slicedToArray(_useState5, 2),
37
35
  height = _useState6[0],
38
36
  setHeight = _useState6[1];
@@ -107,13 +105,13 @@ function renderTableRow(props) {
107
105
 
108
106
  // eslint-disable-next-line react-hooks/rules-of-hooks
109
107
  var editor = useSlateStatic();
110
- var style = element.style;
111
108
  var rowPath = findPath(editor, element);
112
109
  if (!rowPath) return null;
113
110
  var pathLength = rowPath.length;
114
111
  var rowIndex = rowPath[pathLength - 1];
115
- var minHeight = (style === null || style === void 0 ? void 0 : style.minHeight) || TABLE_ROW_MIN_HEIGHT;
116
- var height = rowIndex === 0 ? minHeight + 1 : minHeight;
112
+ var _element$style = element.style,
113
+ style = _element$style === void 0 ? {} : _element$style;
114
+ var height = getRowHeight(element, rowIndex);
117
115
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
118
116
  className: classnames('table-row', attributes.className),
119
117
  style: _objectSpread(_objectSpread(_objectSpread({}, attributes.style), style), {}, {
@@ -8,9 +8,8 @@ import { useResizeHandlersContext, useTableSelectedRangeContext } from '../../ho
8
8
  import { useScrollContext } from '../../../../../../hooks/use-scroll-context';
9
9
  import { ELEMENT_TYPE } from '../../../../../constants';
10
10
  import { findPath, getSelectedNodeByType } from '../../../../../core';
11
- import { elementHasImage } from '../../../helpers';
11
+ import { elementHasImage, getRowHeight } from '../../../helpers';
12
12
  var RowHeader = function RowHeader(_ref) {
13
- var _row$style;
14
13
  var row = _ref.row,
15
14
  index = _ref.index,
16
15
  addIconPosition = _ref.addIconPosition,
@@ -18,8 +17,9 @@ var RowHeader = function RowHeader(_ref) {
18
17
  setInsertRowIndex = _ref.setInsertRowIndex,
19
18
  selectRange = _ref.selectRange,
20
19
  tableSize = _ref.tableSize;
20
+ var oldRowHeight = getRowHeight(row);
21
21
  var editor = useSlateStatic();
22
- var _useState = useState(row === null || row === void 0 ? void 0 : (_row$style = row.style) === null || _row$style === void 0 ? void 0 : _row$style.minHeight),
22
+ var _useState = useState(oldRowHeight),
23
23
  _useState2 = _slicedToArray(_useState, 2),
24
24
  rowHeight = _useState2[0],
25
25
  setRowHeight = _useState2[1];
@@ -1,3 +1,4 @@
1
+ import { TEXT_STYLE_MAP } from '../../constants';
1
2
  import { getValue, isMenuDisabled, addMark, removeMark } from './helpers';
2
3
  var withTextStyle = function withTextStyle(editor) {
3
4
  var toggleTextStyle = function toggleTextStyle(type) {
@@ -13,10 +14,10 @@ var withTextStyle = function withTextStyle(editor) {
13
14
  }
14
15
  };
15
16
  editor.toggleTextBold = function () {
16
- toggleTextStyle('BOLD');
17
+ toggleTextStyle(TEXT_STYLE_MAP.BOLD);
17
18
  };
18
19
  editor.toggleTextItalic = function () {
19
- toggleTextStyle('ITALIC');
20
+ toggleTextStyle(TEXT_STYLE_MAP.ITALIC);
20
21
  };
21
22
  return editor;
22
23
  };
@@ -2,7 +2,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
2
2
  var _excluded = ["text"];
3
3
  import React from 'react';
4
4
  import Caret from './caret';
5
- import { DEFAULT_FONT } from '../../constants';
5
+ import { DEFAULT_FONT, TEXT_STYLE_MAP } from '../../constants';
6
6
  import { generatorFontFamily } from '../font/helpers';
7
7
  var renderText = function renderText(props, editor) {
8
8
  var attributes = props.attributes,
@@ -20,54 +20,55 @@ var renderText = function renderText(props, editor) {
20
20
  if (leaf.computed_background_color) {
21
21
  style['backgroundColor'] = leaf.computed_background_color;
22
22
  }
23
- if (leaf.color) {
24
- style['color'] = leaf.color;
23
+ if (leaf[TEXT_STYLE_MAP.COLOR]) {
24
+ style['color'] = leaf[TEXT_STYLE_MAP.COLOR];
25
25
  }
26
- if (leaf['highlight-color']) {
27
- style['backgroundColor'] = leaf['highlight-color'];
26
+ if (leaf[TEXT_STYLE_MAP.HIGHLIGHT_COLOR]) {
27
+ style['backgroundColor'] = leaf[TEXT_STYLE_MAP.HIGHLIGHT_COLOR];
28
28
  }
29
- if (leaf['font-size']) {
30
- var fontSize = leaf['font-size'];
29
+ if (leaf[TEXT_STYLE_MAP.FONT_SIZE]) {
30
+ var fontSize = leaf[TEXT_STYLE_MAP.FONT_SIZE];
31
31
  if (typeof fontSize === 'number') {
32
32
  style['fontSize'] = "".concat(fontSize, "pt");
33
33
  }
34
34
  }
35
- var font = leaf['font'] || DEFAULT_FONT;
36
- var fontWeight = leaf.BOLD ? 600 : 400;
37
- style['fontFamily'] = generatorFontFamily(font, fontWeight, leaf);
38
- if (leaf.BOLD) {
35
+ if (leaf[TEXT_STYLE_MAP.FONT]) {
36
+ var fontWeight = leaf[TEXT_STYLE_MAP.BOLD] ? 600 : 400;
37
+ style['fontFamily'] = generatorFontFamily(leaf[TEXT_STYLE_MAP.FONT], fontWeight);
38
+ }
39
+ if (leaf[TEXT_STYLE_MAP.BOLD]) {
39
40
  markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
40
41
  }
41
- if (leaf.ITALIC) {
42
+ if (leaf[TEXT_STYLE_MAP.ITALIC]) {
42
43
  markedChildren = /*#__PURE__*/React.createElement("i", null, markedChildren);
43
44
  }
44
- if (leaf.UNDERLINE) {
45
+ if (leaf[TEXT_STYLE_MAP.UNDERLINE]) {
45
46
  markedChildren = /*#__PURE__*/React.createElement("span", {
46
47
  style: {
47
48
  textDecoration: 'underline'
48
49
  }
49
50
  }, markedChildren);
50
51
  }
51
- if (leaf.STRIKETHROUGH) {
52
+ if (leaf[TEXT_STYLE_MAP.STRIKETHROUGH]) {
52
53
  markedChildren = /*#__PURE__*/React.createElement("span", {
53
54
  style: {
54
55
  textDecoration: 'line-through'
55
56
  }
56
57
  }, markedChildren);
57
58
  }
58
- if (leaf.SUPERSCRIPT) {
59
+ if (leaf[TEXT_STYLE_MAP.SUPERSCRIPT]) {
59
60
  markedChildren = /*#__PURE__*/React.createElement("sup", null, markedChildren);
60
61
  }
61
- if (leaf.SUBSCRIPT) {
62
+ if (leaf[TEXT_STYLE_MAP.SUBSCRIPT]) {
62
63
  markedChildren = /*#__PURE__*/React.createElement("sub", null, markedChildren);
63
64
  }
64
- if (leaf.CODE) {
65
+ if (leaf[TEXT_STYLE_MAP.CODE]) {
65
66
  markedChildren = /*#__PURE__*/React.createElement("code", null, markedChildren);
66
67
  }
67
- if (leaf.DELETE) {
68
+ if (leaf[TEXT_STYLE_MAP.DELETE]) {
68
69
  markedChildren = /*#__PURE__*/React.createElement("del", null, markedChildren);
69
70
  }
70
- if (leaf.ADD) {
71
+ if (leaf[TEXT_STYLE_MAP.ADD]) {
71
72
  markedChildren = /*#__PURE__*/React.createElement("span", null, markedChildren);
72
73
  }
73
74
  if (leaf.decoration) {