@seafile/sdoc-editor 1.0.198-test0.2 → 1.0.198-test0.4

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.
@@ -53,11 +53,6 @@ const SelectSdocFileDialog = _ref => {
53
53
  insertFileLinkCallback,
54
54
  insertSdocFileLinkCallback
55
55
  } = insertLinkCallback;
56
- if (dialogType === _constants.ELEMENT_TYPE.FILE_LINK) {
57
- insertFileLinkCallback && insertFileLinkCallback(editor, fileInfo.name, fileInfo.file_uuid);
58
- } else {
59
- insertSdocFileLinkCallback && insertSdocFileLinkCallback(editor, fileInfo.name, fileInfo.file_uuid);
60
- }
61
56
  switch (dialogType) {
62
57
  case _constants.ELEMENT_TYPE.FILE_LINK:
63
58
  insertFileLinkCallback && insertFileLinkCallback(editor, fileInfo.name, fileInfo.file_uuid);
@@ -66,7 +61,7 @@ const SelectSdocFileDialog = _ref => {
66
61
  insertSdocFileLinkCallback && insertSdocFileLinkCallback(editor, fileInfo.name, fileInfo.file_uuid);
67
62
  break;
68
63
  case _constants.ELEMENT_TYPE.WHITEBOARD:
69
- insertWhiteboardFile && insertWhiteboardFile(editor, fileInfo.name, fileInfo.file_uuid);
64
+ insertWhiteboardFile && insertWhiteboardFile(editor, fileInfo.name, fileInfo.path);
70
65
  break;
71
66
  default:
72
67
  break;
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.onCreateWhiteboardFile = exports.isInsertWhiteboardMenuDisabled = exports.insertWhiteboard = void 0;
7
+ exports.onCreateWhiteboardFile = exports.isInsertWhiteboardMenuDisabled = exports.insertWhiteboard = exports.generateWhiteboardNode = void 0;
8
8
  var _slate = require("@seafile/slate");
9
+ var _slugid = _interopRequireDefault(require("slugid"));
9
10
  var _core = require("../../core");
10
11
  var _constants = require("../../constants");
11
12
  var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
@@ -42,7 +43,45 @@ const isInsertWhiteboardMenuDisabled = (editor, readonly) => {
42
43
  return false;
43
44
  };
44
45
  exports.isInsertWhiteboardMenuDisabled = isInsertWhiteboardMenuDisabled;
45
- const insertWhiteboard = () => {};
46
+ const generateWhiteboardNode = function (repoID) {
47
+ let filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
48
+ let filePath = arguments.length > 2 ? arguments[2] : undefined;
49
+ const whiteboardNode = {
50
+ id: _slugid.default.nice(),
51
+ type: _constants.WHITEBOARD,
52
+ repoID: repoID,
53
+ title: filename,
54
+ filePath: filePath,
55
+ children: [{
56
+ id: _slugid.default.nice(),
57
+ text: ''
58
+ }]
59
+ };
60
+ return whiteboardNode;
61
+ };
62
+ exports.generateWhiteboardNode = generateWhiteboardNode;
63
+ const insertWhiteboard = (editor, filename, filePath) => {
64
+ if (isInsertWhiteboardMenuDisabled(editor)) return;
65
+ const {
66
+ repoID
67
+ } = window.app.pageOptions;
68
+ const {
69
+ selection
70
+ } = editor;
71
+ if (selection == null) return;
72
+ // const isCollapsed = Range.isCollapsed(selection);
73
+
74
+ const whiteboardNode = generateWhiteboardNode(repoID, filename, filePath);
75
+ let path = _slate.Editor.path(editor, editor.selection);
76
+ const position = 'after';
77
+ if (position === _constants.INSERT_POSITION.AFTER) {
78
+ _slate.Transforms.insertNodes(editor, whiteboardNode, {
79
+ at: [path[0] + 1]
80
+ });
81
+ (0, _core.focusEditor)(editor, [path[0] + 1, 2]);
82
+ return;
83
+ }
84
+ };
46
85
  exports.insertWhiteboard = insertWhiteboard;
47
86
  const onCreateWhiteboardFile = editor => {
48
87
  // e.stopPropagation();
@@ -52,7 +91,6 @@ const onCreateWhiteboardFile = editor => {
52
91
  fileType: 'draw',
53
92
  editor
54
93
  };
55
- console.log(2, external_props.insertWhiteboard);
56
94
  eventBus.dispatch(_constants2.EXTERNAL_EVENT.CREATE_WHITEBOARD_FILE, {
57
95
  ...external_props
58
96
  });
@@ -12,13 +12,18 @@ var _constants = require("../../../../constants");
12
12
  require("./index.css");
13
13
  const Whiteboard = _ref => {
14
14
  let {
15
- editor
15
+ editor,
16
+ repoID,
17
+ filePath
16
18
  } = _ref;
17
19
  // const whiteboardContainer = document.getElementById('sdoc-whiteboard-container');
18
20
  const [tldraw, setTldraw] = (0, _react.useState)(null);
19
21
  const renderWhiteboardEditor = Tldraw => {
20
22
  console.log(4, Tldraw);
21
- setTldraw( /*#__PURE__*/_react.default.createElement(Tldraw, null));
23
+ setTldraw( /*#__PURE__*/_react.default.createElement(Tldraw, {
24
+ repoID: repoID,
25
+ filePath: filePath
26
+ }));
22
27
  };
23
28
  (0, _react.useEffect)(() => {
24
29
  const eventBus = _eventBus.default.getInstance();
@@ -33,6 +38,7 @@ const Whiteboard = _ref => {
33
38
  }, tldraw);
34
39
  };
35
40
  function renderWhiteboard(props, editor) {
41
+ console.log(3, editor, props);
36
42
  return /*#__PURE__*/_react.default.createElement(Whiteboard, Object.assign({}, props, {
37
43
  editor: editor
38
44
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.198-test0.2",
3
+ "version": "1.0.198-test0.4",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",