@seafile/sdoc-editor 1.0.25-alpha.4 → 1.0.25-alpha.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.
@@ -2,6 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { Editor, Transforms, Range } from '@seafile/slate';
3
3
  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
+ import { INSERT_POSITION } from '../../constants';
5
6
  import { focusEditor, getNodeType } from '../../core';
6
7
  import Column from './model';
7
8
  import * as CellType from './constants/cell-types';
@@ -46,10 +47,19 @@ export const getColumnType = editor => {
46
47
  const [n] = match;
47
48
  return getNodeType(n);
48
49
  };
49
- export const insertSeaTableColumn = (editor, active, option) => {
50
+ export const insertSeaTableColumn = function (editor, active, option) {
51
+ let insertPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : INSERT_POSITION.CURRENT;
50
52
  if (!active) {
51
53
  const column = new Column(option);
52
54
  column.id = slugid.nice();
55
+ if (insertPosition === INSERT_POSITION.AFTER) {
56
+ const path = Editor.path(editor, editor.selection);
57
+ path && Transforms.insertNodes(editor, _objectSpread({}, column), {
58
+ at: [path[0] + 1]
59
+ });
60
+ focusEditor(editor);
61
+ return;
62
+ }
53
63
  Transforms.insertNodes(editor, _objectSpread({}, column));
54
64
  }
55
65
  focusEditor(editor);
@@ -6,7 +6,8 @@ import './column-list-menu.css';
6
6
  const NOT_SUPPORT_COLUMN_TYPES = ['button', 'file'];
7
7
  export default function ColumnListMenu(_ref) {
8
8
  let {
9
- editor
9
+ editor,
10
+ insertPosition
10
11
  } = _ref;
11
12
  const columns = useMemo(() => {
12
13
  if (!editor.columns) return [];
@@ -27,8 +28,8 @@ export default function ColumnListMenu(_ref) {
27
28
  };
28
29
  const onMousedown = useCallback(option => {
29
30
  const active = isActive(editor);
30
- insertSeaTableColumn(editor, active, option);
31
- }, [editor]);
31
+ insertSeaTableColumn(editor, active, option, insertPosition);
32
+ }, [editor, insertPosition]);
32
33
  return /*#__PURE__*/React.createElement("div", {
33
34
  className: "column-list-menu"
34
35
  }, options.map(option => {
@@ -28,7 +28,8 @@ const SeaTableColumnMenu = _ref => {
28
28
  popperClassName: "seatable-column-popover"
29
29
  }, /*#__PURE__*/React.createElement(ColumnListMenu, {
30
30
  editor: editor,
31
- readonly: readonly
31
+ readonly: readonly,
32
+ insertPosition: insertPosition
32
33
  }))));
33
34
  };
34
35
  export default SeaTableColumnMenu;
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { Editor, Transforms } from '@seafile/slate';
3
3
  import slugId from 'slugid';
4
4
  import { getNodeType, isTextNode, getParentNode, generateDefaultText } from '../../core';
5
- import { ELEMENT_TYPE, SEATABLE_TABLE } from '../../constants';
5
+ import { ELEMENT_TYPE, SEATABLE_TABLE, INSERT_POSITION } from '../../constants';
6
6
  export const isInsertSeaTableTableDisabled = (editor, readonly) => {
7
7
  if (readonly) return true;
8
8
  const {
@@ -51,8 +51,16 @@ export const generateSeaTableTable = (table_id, editor) => {
51
51
  children: [generateDefaultText()]
52
52
  };
53
53
  };
54
- export const insertSeaTableTable = (editor, item) => {
54
+ export const insertSeaTableTable = function (editor, item) {
55
+ let insertPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INSERT_POSITION.CURRENT;
55
56
  const node = generateSeaTableTable(item._id, editor);
57
+ if (insertPosition === INSERT_POSITION.AFTER) {
58
+ const path = Editor.path(editor, editor.selection);
59
+ path && Transforms.insertNodes(editor, node, {
60
+ at: [path[0] + 1]
61
+ });
62
+ return;
63
+ }
56
64
  Transforms.setNodes(editor, node);
57
65
  };
58
66
  export const updateSeaTableTable = (editor, props) => {
@@ -11,12 +11,11 @@ const SeaTableTableMenu = _ref => {
11
11
  } = _ref;
12
12
  const disabled = isInsertSeaTableTableDisabled(editor, readonly);
13
13
  const menuConfig = MENUS_CONFIG_MAP[SEATABLE_TABLE];
14
- console.log('insertPosition', insertPosition);
15
14
  menuConfig.id = insertPosition ? "side_toolbar_".concat(menuConfig.id) : menuConfig.id;
16
15
  const tables = editor.tables;
17
16
  const onViewClick = useCallback(item => {
18
- insertSeaTableTable(editor, item);
19
- }, [editor]);
17
+ insertSeaTableTable(editor, item, insertPosition);
18
+ }, [editor, insertPosition]);
20
19
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownMenuItem, {
21
20
  disabled: disabled,
22
21
  menuConfig: menuConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.25-alpha.4",
3
+ "version": "1.0.25-alpha.5",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",