@seafile/sdoc-editor 0.5.71 → 0.5.73

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 (33) hide show
  1. package/dist/basic-sdk/extension/constants/element-type.js +1 -0
  2. package/dist/basic-sdk/extension/constants/index.js +2 -2
  3. package/dist/basic-sdk/extension/constants/menus-config.js +8 -2
  4. package/dist/basic-sdk/extension/plugins/index.js +4 -3
  5. package/dist/basic-sdk/extension/plugins/{column → seatable-column}/helpers.js +46 -0
  6. package/dist/basic-sdk/extension/plugins/{column → seatable-column}/index.js +2 -2
  7. package/dist/basic-sdk/extension/plugins/{column → seatable-column/menu}/column-list-menu.js +3 -3
  8. package/dist/basic-sdk/extension/plugins/{column/menu/seatable-column.js → seatable-column/menu/index.js} +3 -3
  9. package/dist/basic-sdk/extension/plugins/{column → seatable-column}/render-elem.js +0 -1
  10. package/dist/basic-sdk/extension/plugins/seatable-views/helpers.js +50 -0
  11. package/dist/basic-sdk/extension/plugins/seatable-views/index.js +14 -0
  12. package/dist/basic-sdk/extension/plugins/seatable-views/menu/index.js +40 -0
  13. package/dist/basic-sdk/extension/plugins/seatable-views/model.js +12 -0
  14. package/dist/basic-sdk/extension/plugins/seatable-views/plugin.js +71 -0
  15. package/dist/basic-sdk/extension/plugins/seatable-views/render-element/index.css +21 -0
  16. package/dist/basic-sdk/extension/plugins/seatable-views/render-element/index.js +8 -0
  17. package/dist/basic-sdk/extension/plugins/seatable-views/render-element/record-header.js +19 -0
  18. package/dist/basic-sdk/extension/plugins/seatable-views/render-element/record-item.js +22 -0
  19. package/dist/basic-sdk/extension/plugins/seatable-views/render-element/record-list.js +19 -0
  20. package/dist/basic-sdk/extension/plugins/seatable-views/render-element/seatable-view.js +57 -0
  21. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/index.js +0 -1
  22. package/dist/basic-sdk/extension/render/custom-element.js +11 -6
  23. package/dist/basic-sdk/extension/toolbar/header-toolbar/insert-toolbar/index.js +4 -3
  24. package/dist/index.js +1 -2
  25. package/dist/pages/document-plugin-editor.js +24 -6
  26. package/package.json +1 -1
  27. package/public/locales/en/sdoc-editor.json +4 -3
  28. package/dist/pages/document-plugin-viewer.js +0 -55
  29. /package/dist/basic-sdk/extension/plugins/{column → seatable-column}/constants/cell-types.js +0 -0
  30. /package/dist/basic-sdk/extension/plugins/{column → seatable-column}/constants/column.js +0 -0
  31. /package/dist/basic-sdk/extension/plugins/{column → seatable-column/menu}/column-list-menu.css +0 -0
  32. /package/dist/basic-sdk/extension/plugins/{column → seatable-column}/model.js +0 -0
  33. /package/dist/basic-sdk/extension/plugins/{column → seatable-column}/plugin.js +0 -0
@@ -30,6 +30,7 @@ export const MENTION_TEMP = 'mention_temp';
30
30
  export const FILE_LINK_INSET_INPUT_TEMP = 'file_link_insert_input_temp';
31
31
  export const QUICK_INSERT = 'quick_insert';
32
32
  export const COLUMN = 'column';
33
+ export const SEATABLE_VIEW = 'seatable_view';
33
34
 
34
35
  // font
35
36
  export const FONT_SIZE = 'font-size';
@@ -1,7 +1,7 @@
1
1
  // extension plugin
2
2
  import * as ELEMENT_TYPE from './element-type';
3
3
  // eslint-disable-next-line no-duplicate-imports
4
- import { BLOCKQUOTE, TITLE, SUBTITLE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, TABLE, TABLE_CELL, TABLE_ROW, LINK, SDOC_LINK, FILE_LINK, IMAGE, IMAGE_BLOCK, TOP_LEVEL_TYPES, INLINE_LEVEL_TYPES, CALL_OUT, MENTION, MENTION_TEMP, FILE_LINK_INSET_INPUT_TEMP, QUICK_INSERT, COLUMN } from './element-type';
4
+ import { BLOCKQUOTE, TITLE, SUBTITLE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, TABLE, TABLE_CELL, TABLE_ROW, LINK, SDOC_LINK, FILE_LINK, IMAGE, IMAGE_BLOCK, TOP_LEVEL_TYPES, INLINE_LEVEL_TYPES, CALL_OUT, MENTION, MENTION_TEMP, FILE_LINK_INSET_INPUT_TEMP, QUICK_INSERT, COLUMN, SEATABLE_VIEW } from './element-type';
5
5
  export { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR } from './color';
6
6
  export { FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, SDOC_FONT_SIZE } from './font';
7
7
  export { DIFF_TYPE, ADDED_STYLE, DELETED_STYLE } from './diff-view';
@@ -57,4 +57,4 @@ export const MOUSE_ENTER_EVENT_DISABLED_MAP = {
57
57
  [CALL_OUT]: [CALL_OUT]
58
58
  };
59
59
  export const ROOT_ELEMENT_TYPES = [PARAGRAPH, TITLE, SUBTITLE, CHECK_LIST_ITEM, ORDERED_LIST, UNORDERED_LIST, BLOCKQUOTE, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, CALL_OUT, TABLE, CODE_BLOCK, IMAGE_BLOCK];
60
- export { ELEMENT_TYPE, BLOCKQUOTE, TITLE, SUBTITLE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, TABLE, TABLE_CELL, TABLE_ROW, LINK, SDOC_LINK, FILE_LINK, IMAGE, IMAGE_BLOCK, TOP_LEVEL_TYPES, INLINE_LEVEL_TYPES, CALL_OUT, MENTION, MENTION_TEMP, FILE_LINK_INSET_INPUT_TEMP, QUICK_INSERT };
60
+ export { ELEMENT_TYPE, BLOCKQUOTE, TITLE, SUBTITLE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, TABLE, TABLE_CELL, TABLE_ROW, LINK, SDOC_LINK, FILE_LINK, IMAGE, IMAGE_BLOCK, TOP_LEVEL_TYPES, INLINE_LEVEL_TYPES, CALL_OUT, MENTION, MENTION_TEMP, FILE_LINK_INSET_INPUT_TEMP, QUICK_INSERT, SEATABLE_VIEW };
@@ -1,5 +1,5 @@
1
1
  import { RECENT_USED_HIGHLIGHT_COLORS_KEY, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, RECENT_USED_FONT_COLORS_KEY, DEFAULT_FONT_COLOR, DEFAULT_LAST_USED_FONT_COLOR } from './color';
2
- import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST_ITEM, CODE_BLOCK, LINK, IMAGE, TABLE, SDOC_LINK, FILE_LINK, PARAGRAPH, CALL_OUT, COLUMN } from './element-type';
2
+ import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST_ITEM, CODE_BLOCK, LINK, IMAGE, TABLE, SDOC_LINK, FILE_LINK, PARAGRAPH, CALL_OUT, COLUMN, SEATABLE_VIEW } from './element-type';
3
3
  export const UNDO = 'undo';
4
4
  export const REDO = 'redo';
5
5
  export const CLEAR_FORMAT = 'clear_format';
@@ -195,7 +195,13 @@ export const MENUS_CONFIG_MAP = {
195
195
  [COLUMN]: {
196
196
  id: "sdoc".concat(COLUMN),
197
197
  iconClass: 'sdocfont sdoc-choose-column',
198
- text: 'Insert_column'
198
+ text: 'SeaTable_column'
199
+ },
200
+ [SEATABLE_VIEW]: {
201
+ id: SEATABLE_VIEW,
202
+ iconClass: 'sdocfont sdoc-header4',
203
+ type: SEATABLE_VIEW,
204
+ text: 'SeaTable_view'
199
205
  }
200
206
  };
201
207
 
@@ -18,10 +18,11 @@ import CalloutPlugin from './callout';
18
18
  import SearchReplacePlugin from './search-replace';
19
19
  import MentionPlugin from './mention';
20
20
  import QuickInsertPlugin from './quick-insert';
21
- import ColumnPlugin from './column';
22
21
  import WikiLinkPlugin from './wiki-link';
22
+ import SeaTableColumnPlugin from './seatable-column';
23
+ import SeaTableViewsPlugin from './seatable-views';
23
24
  const Plugins = [MarkDownPlugin, HtmlPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin];
24
- const WikiPlugins = [MarkDownPlugin, HtmlPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin, QuickInsertPlugin, WikiLinkPlugin];
25
+ const WikiPlugins = [...Plugins, QuickInsertPlugin, WikiLinkPlugin];
25
26
  const CommentPlugins = [MarkDownPlugin, HtmlPlugin, ParagraphPlugin, TextPlugin, ListPlugin, ImagePlugin, LinkPlugin, MentionPlugin, BlockquotePlugin];
26
27
  export default Plugins;
27
- export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, HtmlPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin, MentionPlugin, QuickInsertPlugin, CommentPlugins, WikiPlugins, ColumnPlugin, WikiLinkPlugin };
28
+ export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, HtmlPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin, MentionPlugin, QuickInsertPlugin, CommentPlugins, WikiPlugins, WikiLinkPlugin, SeaTableColumnPlugin, SeaTableViewsPlugin };
@@ -4,6 +4,7 @@ import slugid from 'slugid';
4
4
  import { BLOCKQUOTE, CHECK_LIST_ITEM, COLUMN, IMAGE, ORDERED_LIST, PARAGRAPH, TABLE_CELL, UNORDERED_LIST } from '../../constants/element-type';
5
5
  import { focusEditor, getNodeType } from '../../core';
6
6
  import Column from './model';
7
+ import * as CellType from './constants/cell-types';
7
8
  export const isMenuDisabled = (editor, readonly) => {
8
9
  if (readonly) return true;
9
10
  const {
@@ -64,4 +65,49 @@ export const setSeaTableColumn = (editor, data) => {
64
65
  export const getColumnByKey = (columns, key) => {
65
66
  const column = columns.find(item => item.key === key);
66
67
  return column || null;
68
+ };
69
+ export const getColumnWidth = column => {
70
+ let {
71
+ type,
72
+ data
73
+ } = column;
74
+ switch (type) {
75
+ case CellType.DATE:
76
+ {
77
+ let isShowHourAndMinute = data && data.format && data.format.indexOf('HH:mm') > -1;
78
+ return isShowHourAndMinute ? 160 : 100;
79
+ }
80
+ case CellType.CTIME:
81
+ case CellType.MTIME:
82
+ case CellType.LINK:
83
+ case CellType.GEOLOCATION:
84
+ {
85
+ return 160;
86
+ }
87
+ case CellType.COLLABORATOR:
88
+ {
89
+ return 100;
90
+ }
91
+ case CellType.CHECKBOX:
92
+ {
93
+ return 40;
94
+ }
95
+ case CellType.NUMBER:
96
+ case CellType.AUTO_NUMBER:
97
+ {
98
+ return 120;
99
+ }
100
+ case CellType.RATE:
101
+ {
102
+ const {
103
+ rate_max_number
104
+ } = data || {};
105
+ const rateMaxNumber = rate_max_number || 5;
106
+ return 16 * rateMaxNumber + 20;
107
+ }
108
+ default:
109
+ {
110
+ return 100;
111
+ }
112
+ }
67
113
  };
@@ -1,10 +1,10 @@
1
1
  import { COLUMN } from '../../constants/element-type';
2
2
  import withColumn from './plugin';
3
3
  import renderColumn from './render-elem';
4
- const ColumnPlugin = {
4
+ const SeaTableColumnPlugin = {
5
5
  type: COLUMN,
6
6
  nodeType: 'element',
7
7
  editorPlugin: withColumn,
8
8
  renderElements: [renderColumn]
9
9
  };
10
- export default ColumnPlugin;
10
+ export default SeaTableColumnPlugin;
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo, useCallback } from 'react';
2
- import { COLUMNS_ICON_CONFIG } from './constants/column';
3
- import { insertSeaTableColumn, getColumnType } from './helpers';
4
- import { COLUMN } from '../../constants/element-type';
2
+ import { COLUMNS_ICON_CONFIG } from '../constants/column';
3
+ import { insertSeaTableColumn, getColumnType } from '../helpers';
4
+ import { COLUMN } from '../../../constants/element-type';
5
5
  import './column-list-menu.css';
6
6
  const NOT_SUPPORT_COLUMN_TYPES = ['button', 'file'];
7
7
  export default function ColumnListMenu(_ref) {
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import { MENUS_CONFIG_MAP, ELEMENT_TYPE } from '../../../constants';
3
3
  import DropdownMenuItem from '../../../commons/dropdown-menu-item';
4
- import ColumnListMenu from '../column-list-menu';
4
+ import ColumnListMenu from './column-list-menu';
5
5
  import { UncontrolledPopover } from 'reactstrap';
6
6
  import { isMenuDisabled } from '../helpers';
7
- const SeatableColumnMenu = _ref => {
7
+ const SeaTableColumnMenu = _ref => {
8
8
  let {
9
9
  editor,
10
10
  readonly
@@ -28,4 +28,4 @@ const SeatableColumnMenu = _ref => {
28
28
  readonly: readonly
29
29
  })));
30
30
  };
31
- export default SeatableColumnMenu;
31
+ export default SeaTableColumnMenu;
@@ -6,7 +6,6 @@ const Column = _ref => {
6
6
  props,
7
7
  editor
8
8
  } = _ref;
9
- // eslint-disable-next-line react-hooks/rules-of-hooks
10
9
  const {
11
10
  attributes,
12
11
  element,
@@ -0,0 +1,50 @@
1
+ import { Editor, Transforms } from '@seafile/slate';
2
+ import slugId from 'slugid';
3
+ import { getNodeType, isTextNode, getParentNode, generateDefaultText } from '../../core';
4
+ import { ELEMENT_TYPE, SEATABLE_VIEW } from '../../constants';
5
+ export const isInsertSeaTableViewDisabled = (editor, readonly) => {
6
+ if (readonly) return true;
7
+ const {
8
+ selection
9
+ } = editor;
10
+ if (selection === null) return true;
11
+ const [match] = Editor.nodes(editor, {
12
+ match: n => {
13
+ let type = getNodeType(n);
14
+ if (!type && isTextNode(n) && n.id) {
15
+ const parentNode = getParentNode(editor.children, n.id);
16
+ type = getNodeType(parentNode);
17
+ }
18
+ if (type.startsWith('header')) return true;
19
+ if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
20
+ if (type === ELEMENT_TYPE.ORDERED_LIST) return true;
21
+ if (type === ELEMENT_TYPE.UNORDERED_LIST) return true;
22
+ if (type === ELEMENT_TYPE.BLOCKQUOTE) return true;
23
+ if (type === ELEMENT_TYPE.LIST_ITEM) return true;
24
+ if (type === ELEMENT_TYPE.TABLE) return true;
25
+ if (type === ELEMENT_TYPE.TABLE_CELL) return true;
26
+ if (type === ELEMENT_TYPE.TABLE_ROW) return true;
27
+ if (type === ELEMENT_TYPE.CALL_OUT) return true;
28
+ if (Editor.isVoid(editor, n)) return true;
29
+ return false;
30
+ },
31
+ universal: true
32
+ });
33
+ if (match) return true;
34
+ return false;
35
+ };
36
+ export const generateSeaTableView = (table_id, view_id) => {
37
+ return {
38
+ id: slugId.nice(),
39
+ type: SEATABLE_VIEW,
40
+ table_id,
41
+ view_id,
42
+ children: [generateDefaultText()]
43
+ };
44
+ };
45
+ export const insertSeaTableView = (editor, item) => {
46
+ const table_id = editor.table_id;
47
+ const view_id = item._id;
48
+ const node = generateSeaTableView(table_id, view_id);
49
+ Transforms.setNodes(editor, node);
50
+ };
@@ -0,0 +1,14 @@
1
+ import { SEATABLE_VIEW } from '../../constants';
2
+ import ImageMenu from './menu';
3
+ import SeaTableView from './model';
4
+ import withSeaTableView from './plugin';
5
+ import renderSeaTableView from './render-element';
6
+ const SeaTableViewsPlugin = {
7
+ type: SEATABLE_VIEW,
8
+ nodeType: 'element',
9
+ model: SeaTableView,
10
+ editorMenus: [ImageMenu],
11
+ editorPlugin: withSeaTableView,
12
+ renderElements: [renderSeaTableView]
13
+ };
14
+ export default SeaTableViewsPlugin;
@@ -0,0 +1,40 @@
1
+ import React, { useCallback } from 'react';
2
+ import { UncontrolledPopover } from 'reactstrap';
3
+ import { insertSeaTableView, isInsertSeaTableViewDisabled } from '../helpers';
4
+ import { MENUS_CONFIG_MAP, SEATABLE_VIEW } from '../../../constants';
5
+ import DropdownMenuItem from '../../../commons/dropdown-menu-item';
6
+ const SeaTableViewMenu = _ref => {
7
+ let {
8
+ editor,
9
+ readonly
10
+ } = _ref;
11
+ const disabled = isInsertSeaTableViewDisabled(editor, readonly);
12
+ const menuConfig = MENUS_CONFIG_MAP[SEATABLE_VIEW];
13
+ const views = editor.views;
14
+ const onViewClick = useCallback(item => {
15
+ insertSeaTableView(editor, item);
16
+ }, [editor]);
17
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownMenuItem, {
18
+ disabled: disabled,
19
+ menuConfig: menuConfig,
20
+ className: "pr-2"
21
+ }, !disabled && /*#__PURE__*/React.createElement("i", {
22
+ className: "sdocfont sdoc-right-slide sdoc-dropdown-item-right-icon"
23
+ })), !disabled && /*#__PURE__*/React.createElement(UncontrolledPopover, {
24
+ target: menuConfig.id,
25
+ trigger: "hover",
26
+ className: "sdoc-menu-popover sdoc-dropdown-menu sdoc-sub-dropdown-menu",
27
+ placement: "right-start",
28
+ hideArrow: true,
29
+ fade: false
30
+ }, /*#__PURE__*/React.createElement("div", {
31
+ className: "sdoc-dropdown-menu-container"
32
+ }, views.map(item => {
33
+ return /*#__PURE__*/React.createElement("div", {
34
+ key: item._id,
35
+ className: "sdoc-dropdown-menu-item",
36
+ onClick: () => onViewClick(item)
37
+ }, item.name);
38
+ }))));
39
+ };
40
+ export default SeaTableViewMenu;
@@ -0,0 +1,12 @@
1
+ import { SEATABLE_VIEW } from '../../constants/element-type';
2
+ class SeaTableView {
3
+ constructor(options) {
4
+ this.type = options.type || SEATABLE_VIEW;
5
+ this.table_id = options.table_id;
6
+ this.view_id = options.view_id;
7
+ this.children = options.children || [{
8
+ text: ''
9
+ }];
10
+ }
11
+ }
12
+ export default SeaTableView;
@@ -0,0 +1,71 @@
1
+ import { Transforms, Path, Editor, Element, Range } from '@seafile/slate';
2
+ import { focusEditor, generateEmptyElement, getNodeType, isBlockAboveEmpty, isLastNode } from '../../core';
3
+ import { PARAGRAPH, SEATABLE_VIEW } from '../../constants/element-type';
4
+ const withSeaTableView = editor => {
5
+ const {
6
+ isVoid,
7
+ deleteBackward,
8
+ normalizeNode
9
+ } = editor;
10
+ const newEditor = editor;
11
+
12
+ // rewrite isVoid
13
+ newEditor.isVoid = elem => {
14
+ const {
15
+ type
16
+ } = elem;
17
+ if (type === SEATABLE_VIEW) {
18
+ return true;
19
+ }
20
+ return isVoid(elem);
21
+ };
22
+ newEditor.deleteBackward = unit => {
23
+ const {
24
+ selection
25
+ } = editor;
26
+ const focusPoint = Editor.before(editor, selection);
27
+ const point = Editor.before(editor, selection, {
28
+ distance: 1
29
+ });
30
+ if (!point) return deleteBackward(unit);
31
+ const [node, path] = Editor.node(editor, [point.path[0], point.path[1]]);
32
+ const isPerviousSeaTableView = node.type === SEATABLE_VIEW;
33
+ if (isPerviousSeaTableView && Range.isCollapsed(selection) && isBlockAboveEmpty(editor) && !Path.isCommon(path, selection.anchor.path)) {
34
+ deleteBackward(unit);
35
+ focusEditor(newEditor, Editor.end(newEditor, focusPoint));
36
+ return;
37
+ }
38
+ if (Element.isElement(node) && node.type === SEATABLE_VIEW) {
39
+ // If the wrapping element is image_block, delete the wrapping element
40
+ const [parentNode, p] = Editor.node(editor, [path[0]]);
41
+ if (parentNode.type === SEATABLE_VIEW) {
42
+ Transforms.removeNodes(editor, {
43
+ at: p
44
+ });
45
+ return;
46
+ }
47
+ focusEditor(editor, Path.next(path));
48
+ }
49
+ deleteBackward(unit);
50
+ };
51
+
52
+ // Rewrite normalizeNode
53
+ newEditor.normalizeNode = _ref => {
54
+ let [node, path] = _ref;
55
+ const type = getNodeType(node);
56
+ if (type !== SEATABLE_VIEW) {
57
+ return normalizeNode([node, path]);
58
+ }
59
+
60
+ // insert empty node,continue editor
61
+ const isLast = isLastNode(newEditor, node);
62
+ if (isLast) {
63
+ const p = generateEmptyElement(PARAGRAPH);
64
+ Transforms.insertNodes(newEditor, p, {
65
+ at: [path[0] + 1]
66
+ });
67
+ }
68
+ };
69
+ return newEditor;
70
+ };
71
+ export default withSeaTableView;
@@ -0,0 +1,21 @@
1
+ .seatable-view-container {
2
+ width: 100%;
3
+ min-height: 200px;
4
+ max-height: 400px;
5
+ overflow: auto;
6
+ }
7
+
8
+ .seatable-view-container.selected {
9
+ border: 1px solid red;
10
+ }
11
+
12
+ .seatable-view-container .seatable-view-records {
13
+ margin: 0;
14
+ }
15
+
16
+ .seatable-view-body-column-cell {
17
+ white-space: nowrap;
18
+ text-overflow: ellipsis;
19
+ overflow: hidden;
20
+ word-break: break-all;
21
+ }
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import SeaTableView from './seatable-view';
3
+ const renderSeaTableView = (props, editor) => {
4
+ return /*#__PURE__*/React.createElement(SeaTableView, Object.assign({}, props, {
5
+ editor: editor
6
+ }));
7
+ };
8
+ export default renderSeaTableView;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { getColumnWidth } from '../../seatable-column/helpers';
3
+ export default function RecordHeader(_ref) {
4
+ let {
5
+ columns
6
+ } = _ref;
7
+ return /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", {
8
+ className: "seatable-view-column-header-row"
9
+ }, columns.map(column => {
10
+ const width = getColumnWidth(column);
11
+ return /*#__PURE__*/React.createElement("th", {
12
+ className: "seatable-view-column-header-cell",
13
+ key: column.key,
14
+ style: {
15
+ width
16
+ }
17
+ }, column.name);
18
+ })));
19
+ }
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { getColumnWidth } from '../../seatable-column/helpers';
3
+ export default function RecordItem(_ref) {
4
+ let {
5
+ editor,
6
+ record,
7
+ columns,
8
+ getViewCellValue
9
+ } = _ref;
10
+ return /*#__PURE__*/React.createElement("tr", {
11
+ className: "seatable-view-body-column-row"
12
+ }, columns.map(column => {
13
+ const width = getColumnWidth(column);
14
+ return /*#__PURE__*/React.createElement("td", {
15
+ className: "seatable-view-body-column-cell",
16
+ key: record._id + '_' + column.key,
17
+ style: {
18
+ width
19
+ }
20
+ }, getViewCellValue(record, column));
21
+ }));
22
+ }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import RecordItem from './record-item';
3
+ export default function RecordList(_ref) {
4
+ let {
5
+ records,
6
+ columns,
7
+ editor,
8
+ getViewCellValue
9
+ } = _ref;
10
+ return /*#__PURE__*/React.createElement("tbody", null, records.map(record => {
11
+ return /*#__PURE__*/React.createElement(RecordItem, {
12
+ key: record._id,
13
+ record: record,
14
+ columns: columns,
15
+ editor: editor,
16
+ getViewCellValue: getViewCellValue
17
+ });
18
+ }));
19
+ }
@@ -0,0 +1,57 @@
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import classNames from 'classnames';
3
+ import { useSelected } from '@seafile/slate-react';
4
+ import Loading from '../../../../../components/loading';
5
+ import RecordHeader from './record-header';
6
+ import RecordList from './record-list';
7
+ import './index.css';
8
+ function SeaTableView(_ref) {
9
+ let {
10
+ element,
11
+ className,
12
+ attributes,
13
+ children,
14
+ editor,
15
+ t
16
+ } = _ref;
17
+ const isSelected = useSelected();
18
+ const [isLoading, setIsLoading] = useState(true);
19
+ const [records, setRecords] = useState([]);
20
+ const [columns, setColumns] = useState([]);
21
+ useEffect(() => {
22
+ const {
23
+ table_id,
24
+ view_id
25
+ } = element;
26
+ const rows = editor.getViewRowsById(table_id, view_id);
27
+ const columns = editor.getViewColsById(table_id, view_id);
28
+ setRecords(rows);
29
+ setColumns(columns);
30
+ setIsLoading(false);
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, [element]);
33
+ const containerClass = classNames('seatable-view-container', {
34
+ selected: isSelected
35
+ });
36
+ const getViewCellValue = useCallback((row, column) => {
37
+ const {
38
+ table_id,
39
+ view_id
40
+ } = element;
41
+ return editor.getViewCellValue(table_id, view_id, row, column);
42
+ }, [editor, element]);
43
+ return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
44
+ className: containerClass,
45
+ contentEditable: false
46
+ }), isLoading && /*#__PURE__*/React.createElement(Loading, null), !isLoading && /*#__PURE__*/React.createElement("table", {
47
+ className: "seatable-view-records"
48
+ }, /*#__PURE__*/React.createElement(RecordHeader, {
49
+ columns: columns
50
+ }), /*#__PURE__*/React.createElement(RecordList, {
51
+ editor: editor,
52
+ records: records,
53
+ columns: columns,
54
+ getViewCellValue: getViewCellValue
55
+ })), children);
56
+ }
57
+ export default SeaTableView;
@@ -64,7 +64,6 @@ const RowsHeader = _ref => {
64
64
  className: classnames('position-fixed sdoc-table-add-element-icon-content', {
65
65
  'background-color-tip-blue': isHoverInAddIcon
66
66
  }),
67
- contentEditable: false,
68
67
  style: addIconPosition,
69
68
  onMouseEnter: () => onMouseEnter(addIconPosition),
70
69
  onMouseLeave: onMouseLeave,
@@ -1,11 +1,11 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { useReadOnly, useSlateStatic } from '@seafile/slate-react';
3
3
  import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, CODE_LINE, IMAGE, IMAGE_BLOCK, ELEMENT_TYPE, SDOC_LINK, FILE_LINK, TITLE, SUBTITLE, CALL_OUT, SUPPORTED_SIDE_OPERATION_TYPE, MENTION, MENTION_TEMP, FILE_LINK_INSET_INPUT_TEMP, QUICK_INSERT } from '../constants';
4
- import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, MentionPlugin, QuickInsertPlugin, ColumnPlugin, WikiLinkPlugin } from '../plugins';
4
+ import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, MentionPlugin, QuickInsertPlugin, WikiLinkPlugin, SeaTableColumnPlugin, SeaTableViewsPlugin } from '../plugins';
5
5
  import { onDragOver, onDragLeave, onDrop } from '../toolbar/side-toolbar/event';
6
6
  import { getParentNode } from '../core';
7
7
  import { setDataRoot, setMouseEnter } from './helper';
8
- import { COLUMN, WIKI_LINK } from '../constants/element-type';
8
+ import { COLUMN, WIKI_LINK, SEATABLE_VIEW } from '../constants/element-type';
9
9
  import { WIKI_EDITOR, DIFF_VIEWER } from '../../constants';
10
10
  const CustomRenderElement = props => {
11
11
  const editor = useSlateStatic();
@@ -169,15 +169,20 @@ const CustomRenderElement = props => {
169
169
  const [renderQuickInsert] = QuickInsertPlugin.renderElements;
170
170
  return renderQuickInsert(props, editor);
171
171
  }
172
+ case WIKI_LINK:
173
+ {
174
+ const [renderWikiLink] = WikiLinkPlugin.renderElements;
175
+ return renderWikiLink(props, editor);
176
+ }
172
177
  case COLUMN:
173
178
  {
174
- const [renderColumn] = ColumnPlugin.renderElements;
179
+ const [renderColumn] = SeaTableColumnPlugin.renderElements;
175
180
  return renderColumn(props, editor);
176
181
  }
177
- case WIKI_LINK:
182
+ case SEATABLE_VIEW:
178
183
  {
179
- const [renderWikiLink] = WikiLinkPlugin.renderElements;
180
- return renderWikiLink(props, editor);
184
+ const [renderSeaTableView] = SeaTableViewsPlugin.renderElements;
185
+ return renderSeaTableView(props, editor);
181
186
  }
182
187
  default:
183
188
  {
@@ -6,9 +6,10 @@ import ImageMenu from '../../../plugins/image/menu';
6
6
  import TableMenu from '../../../plugins/table/menu/table-menu';
7
7
  import LinkMenu from '../../../plugins/link/menu';
8
8
  import CodeBlockMenu from '../../../plugins/code-block/menu';
9
- import SeatableColumnMenu from '../../../plugins/column/menu/seatable-column';
10
9
  import SdocLinkMenu from '../../../plugins/sdoc-link/menu';
11
10
  import FileLinkMenu from '../../../plugins/file-link/menu';
11
+ import SeaTableColumnMenu from '../../../plugins/seatable-column/menu';
12
+ import SeaTableViewMenu from '../../../plugins/seatable-views/menu';
12
13
  import EventBus from '../../../../utils/event-bus';
13
14
  import './index.css';
14
15
  const InsertToolbar = _ref => {
@@ -84,9 +85,9 @@ const InsertToolbar = _ref => {
84
85
  style: {
85
86
  maxHeight: window.innerHeight - bottom - 100
86
87
  }
87
- }, /*#__PURE__*/React.createElement(ImageMenu, props), /*#__PURE__*/React.createElement(TableMenu, props), /*#__PURE__*/React.createElement(LinkMenu, props), /*#__PURE__*/React.createElement(CodeBlockMenu, props), editor.getColumnCellValue && /*#__PURE__*/React.createElement(SeatableColumnMenu, props), /*#__PURE__*/React.createElement("div", {
88
+ }, /*#__PURE__*/React.createElement(ImageMenu, props), /*#__PURE__*/React.createElement(TableMenu, props), /*#__PURE__*/React.createElement(LinkMenu, props), /*#__PURE__*/React.createElement(CodeBlockMenu, props), /*#__PURE__*/React.createElement("div", {
88
89
  className: "sdoc-dropdown-menu-divider"
89
- }), /*#__PURE__*/React.createElement(SdocLinkMenu, props), /*#__PURE__*/React.createElement(FileLinkMenu, props))));
90
+ }), editor.columns && /*#__PURE__*/React.createElement(SeaTableColumnMenu, props), editor.views && /*#__PURE__*/React.createElement(SeaTableViewMenu, props), /*#__PURE__*/React.createElement(SdocLinkMenu, props), /*#__PURE__*/React.createElement(FileLinkMenu, props))));
90
91
  };
91
92
  InsertToolbar.defaultProps = {
92
93
  isRichEditor: true,
package/dist/index.js CHANGED
@@ -7,5 +7,4 @@ import PublishedRevisionViewer from './pages/published-revision-viewer';
7
7
  import WikiViewer from './pages/wiki-viewer';
8
8
  import SdocWikiViewer from './pages/sdoc-wiki-viewer';
9
9
  import DocumentPluginEditor from './pages/document-plugin-editor';
10
- import DocumentPluginViewer from './pages/document-plugin-viewer';
11
- export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT, DiffViewer, PublishedRevisionViewer, WikiViewer, SdocWikiViewer, DocumentPluginEditor, DocumentPluginViewer };
10
+ export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT, DiffViewer, PublishedRevisionViewer, WikiViewer, SdocWikiViewer, DocumentPluginEditor };
@@ -1,4 +1,4 @@
1
- import React, { useMemo } from 'react';
1
+ import React, { useEffect, useMemo } from 'react';
2
2
  import { withTranslation } from 'react-i18next';
3
3
  import context from '../context';
4
4
  import { SDocEditor } from '../basic-sdk';
@@ -6,8 +6,9 @@ import { PAGE_EDIT_AREA_WIDTH } from '../basic-sdk/constants';
6
6
  import { createDefaultEditor } from '../basic-sdk/extension';
7
7
  import withNodeId from '../basic-sdk/node-id';
8
8
  import { withSocketIO } from '../basic-sdk/socket';
9
- import { ColumnPlugin } from '../basic-sdk/extension/plugins';
9
+ import { SeaTableColumnPlugin, SeaTableViewsPlugin } from '../basic-sdk/extension/plugins';
10
10
  import ErrorBoundary from './error-boundary';
11
+ import useForceUpdate from '../basic-sdk/hooks/use-force-update';
11
12
  import '../assets/css/simple-editor.css';
12
13
  import '../assets/css/plugin-editor.css';
13
14
  const DocumentPluginEditor = _ref => {
@@ -15,13 +16,20 @@ const DocumentPluginEditor = _ref => {
15
16
  document,
16
17
  showOutline,
17
18
  scrollRef,
19
+ tableId,
18
20
  columns,
19
- getColumnCellValue
21
+ views,
22
+ getViewRowsById,
23
+ getViewColsById,
24
+ getColumnCellValue,
25
+ getViewCellValue
20
26
  } = _ref;
21
27
  context.initApi();
28
+ const forceUpdate = useForceUpdate();
22
29
  const validEditor = useMemo(() => {
23
- const withColumnPlugin = ColumnPlugin.editorPlugin;
24
- const defaultEditor = withColumnPlugin(createDefaultEditor());
30
+ const withColumnPlugin = SeaTableColumnPlugin.editorPlugin;
31
+ const withViewsPlugin = SeaTableViewsPlugin.editorPlugin;
32
+ const defaultEditor = withViewsPlugin(withColumnPlugin(createDefaultEditor()));
25
33
  const editorConfig = context.getEditorConfig();
26
34
  const newEditor = withNodeId(withSocketIO(defaultEditor, {
27
35
  document,
@@ -30,13 +38,23 @@ const DocumentPluginEditor = _ref => {
30
38
  const {
31
39
  cursors
32
40
  } = document;
33
- newEditor.columns = columns || [];
34
41
  newEditor.getColumnCellValue = getColumnCellValue;
42
+ newEditor.table_id = tableId;
43
+ newEditor.views = views || [];
44
+ newEditor.columns = columns || [];
45
+ newEditor.getViewRowsById = getViewRowsById;
46
+ newEditor.getViewColsById = getViewColsById;
47
+ newEditor.getViewCellValue = getViewCellValue;
35
48
  newEditor.cursors = cursors || {};
36
49
  newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
50
+
37
51
  return newEditor;
38
52
  // eslint-disable-next-line react-hooks/exhaustive-deps
39
53
  }, []);
54
+ useEffect(() => {
55
+ validEditor.getColumnCellValue = getColumnCellValue ? getColumnCellValue : null;
56
+ forceUpdate();
57
+ }, [forceUpdate, getColumnCellValue, validEditor.getColumnCellValue]);
40
58
  return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(SDocEditor, {
41
59
  editor: validEditor,
42
60
  scrollRef: scrollRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.71",
3
+ "version": "0.5.73",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -43,7 +43,6 @@
43
43
  "Delete_row": "Delete row",
44
44
  "Delete_column": "Delete column",
45
45
  "Insert_row": "Insert row",
46
- "Insert_column": "Insert column",
47
46
  "Set_align": "Set align",
48
47
  "Left": "Left",
49
48
  "Center": "Center",
@@ -461,5 +460,7 @@
461
460
  "Fit_table_to_page_width": "Fit table to page width",
462
461
  "Enter_text_or_press_forward_slash_to_insert_element": "Enter text or press '/' to insert element",
463
462
  "Vertical_align": "Vertical alignment",
464
- "Horizontal_align": "Horizontal alignment"
465
- }
463
+ "Horizontal_align": "Horizontal alignment",
464
+ "SeaTable_column": "SeaTable column",
465
+ "SeaTable_view": "SeaTable view"
466
+ }
@@ -1,55 +0,0 @@
1
- import React, { useEffect, useMemo } from 'react';
2
- import { withTranslation } from 'react-i18next';
3
- import context from '../context';
4
- import { SDocViewer } from '../basic-sdk';
5
- import { PAGE_EDIT_AREA_WIDTH } from '../basic-sdk/constants';
6
- import { createDefaultEditor } from '../basic-sdk/extension';
7
- import withNodeId from '../basic-sdk/node-id';
8
- import { withSocketIO } from '../basic-sdk/socket';
9
- import { ColumnPlugin } from '../basic-sdk/extension/plugins';
10
- import ErrorBoundary from './error-boundary';
11
- import useForceUpdate from '../basic-sdk/hooks/use-force-update';
12
- import '../assets/css/simple-editor.css';
13
- import '../assets/css/plugin-editor.css';
14
- const DocumentPluginViewer = _ref => {
15
- let {
16
- scrollRef,
17
- document,
18
- showOutline,
19
- columns,
20
- getColumnCellValue
21
- } = _ref;
22
- context.initApi();
23
- const forceUpdate = useForceUpdate();
24
- const validEditor = useMemo(() => {
25
- const withColumnPlugin = ColumnPlugin.editorPlugin;
26
- const defaultEditor = withColumnPlugin(createDefaultEditor());
27
- const editorConfig = context.getEditorConfig();
28
- const newEditor = withNodeId(withSocketIO(defaultEditor, {
29
- document,
30
- config: editorConfig
31
- }));
32
- const {
33
- cursors
34
- } = document;
35
- newEditor.columns = columns || [];
36
- newEditor.getColumnCellValue = getColumnCellValue;
37
- newEditor.cursors = cursors || {};
38
- newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
39
- return newEditor;
40
- // eslint-disable-next-line react-hooks/exhaustive-deps
41
- }, []);
42
- useEffect(() => {
43
- validEditor.getColumnCellValue = getColumnCellValue ? getColumnCellValue : null;
44
- forceUpdate();
45
- }, [forceUpdate, getColumnCellValue, validEditor.getColumnCellValue]);
46
- return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(SDocViewer, {
47
- editor: validEditor,
48
- scrollRef: scrollRef,
49
- document: document,
50
- showComment: false,
51
- showToolbar: true,
52
- showOutline: showOutline
53
- }));
54
- };
55
- export default withTranslation('sdoc-editor')(DocumentPluginViewer);