@seafile/sdoc-editor 0.1.129 → 0.1.131-test

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.
@@ -0,0 +1,6 @@
1
+ .sdoc-share-permission {
2
+ font-size: 12px;
3
+ padding: 2px 6px;
4
+ border-radius: 4px;
5
+ border: solid 1px rgba(0, 0, 0, 0.12);
6
+ }
@@ -23,7 +23,8 @@
23
23
  .sdoc-code-block-code .sdoc-code-line::before {
24
24
  content: counter(number);
25
25
  color: #ccc;
26
- margin-right: 24px;
26
+ display: inline-block;
27
+ width: 40px;
27
28
  }
28
29
 
29
30
  .sdoc-code-line
@@ -121,4 +121,11 @@ export var setClipboardData = function setClipboardData(value) {
121
121
  data.setData('text/code-block', JSON.stringify(value));
122
122
  }
123
123
  });
124
+ };
125
+ export var deleteBackwardByLength = function deleteBackwardByLength(editor, len) {
126
+ var i = len >= 4 ? 4 : len;
127
+ while (i > 0) {
128
+ Editor.deleteBackward(editor, 'word');
129
+ i--;
130
+ }
124
131
  };
@@ -1,9 +1,12 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import _toArray from "@babel/runtime/helpers/esm/toArray";
3
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
5
  import slugid from 'slugid';
5
- import { Transforms, Node, Range, Editor } from '@seafile/slate';
6
+ import isHotkey from 'is-hotkey';
7
+ import { Transforms, Node, Range, Editor, Path } from '@seafile/slate';
6
8
  import { getNodeType, isLastNode, getSelectedNodeByType, generateEmptyElement } from '../../core';
9
+ import { deleteBackwardByLength } from './helpers';
7
10
  import { CODE_BLOCK, PARAGRAPH, CODE_LINE } from '../../constants';
8
11
  var withCodeBlock = function withCodeBlock(editor) {
9
12
  var normalizeNode = editor.normalizeNode,
@@ -22,6 +25,25 @@ var withCodeBlock = function withCodeBlock(editor) {
22
25
  return insertText(data);
23
26
  };
24
27
  newEditor.insertData = function (data) {
28
+ if (!newEditor.insertFragmentData(data)) {
29
+ var plaintext = data.getData('text/plain') || '';
30
+ if (plaintext) {
31
+ var fragmentData = [];
32
+ plaintext.split('\n').forEach(function (item) {
33
+ var codeLine = {
34
+ id: slugid.nice(),
35
+ type: CODE_LINE,
36
+ children: [{
37
+ text: item,
38
+ id: slugid.nice()
39
+ }]
40
+ };
41
+ fragmentData.push(codeLine);
42
+ });
43
+ newEditor.insertFragment(fragmentData);
44
+ return;
45
+ }
46
+ }
25
47
  if (data.types.includes('text/code-block') && !getSelectedNodeByType(editor, CODE_BLOCK)) {
26
48
  var codeBlockNode = JSON.parse(data.getData('text/code-block'));
27
49
  return insertNode(codeBlockNode);
@@ -147,6 +169,34 @@ var withCodeBlock = function withCodeBlock(editor) {
147
169
  // Perform default behavior
148
170
  return normalizeNode([node, path]);
149
171
  };
172
+ newEditor.codeBlockOnKeyDown = function (event) {
173
+ if (isHotkey('command+enter', event)) {
174
+ if (newEditor.selection && !Range.isExpanded(newEditor.selection)) {
175
+ var path = Editor.path(newEditor, newEditor.selection);
176
+ var p = generateEmptyElement(PARAGRAPH);
177
+ Transforms.insertNodes(newEditor, p, {
178
+ at: [path[0] + 1]
179
+ });
180
+ Transforms.select(newEditor, [path[0] + 1]);
181
+ }
182
+ }
183
+ if (isHotkey('tab', event)) {
184
+ newEditor.insertText(' ');
185
+ }
186
+ if (isHotkey('shift+tab', event)) {
187
+ var range = {
188
+ anchor: {
189
+ offset: 0,
190
+ path: newEditor.selection.focus.path
191
+ },
192
+ focus: _objectSpread({}, newEditor.selection.focus)
193
+ };
194
+ var str = Editor.string(newEditor, range);
195
+ if (str.trim() === '') {
196
+ deleteBackwardByLength(newEditor, str.length);
197
+ }
198
+ }
199
+ };
150
200
  return newEditor;
151
201
  };
152
202
  export default withCodeBlock;
@@ -1,9 +1,11 @@
1
1
  import { deserializeHtml } from './helper';
2
+ import { getSelectedNodeByType } from '../../core';
3
+ import { CODE_BLOCK } from '../../constants';
2
4
  var withHtml = function withHtml(editor) {
3
5
  var insertData = editor.insertData;
4
6
  var newEditor = editor;
5
7
  newEditor.insertData = function (data) {
6
- if (!newEditor.insertFragmentData(data)) {
8
+ if (!newEditor.insertFragmentData(data) && !getSelectedNodeByType(editor, CODE_BLOCK)) {
7
9
  var htmlContent = data.getData('text/html') || '';
8
10
  if (htmlContent) {
9
11
  var content = deserializeHtml(htmlContent);
@@ -79,6 +79,7 @@ var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
79
79
  _this.editor.imageOnKeyDown(event);
80
80
  }
81
81
  if (getSelectedNodeByType(editor, ELEMENT_TYPE.CODE_BLOCK)) {
82
+ _this.editor.codeBlockOnKeyDown(event);
82
83
  var eventBus = EventBus.getInstance();
83
84
  eventBus.dispatch(INTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU);
84
85
  }
package/dist/config.js ADDED
@@ -0,0 +1,16 @@
1
+ var serverConfig = {
2
+ //serviceUrl: "http://127.0.0.1:8000",
3
+ serviceUrl: "http://192.168.1.100:8000",
4
+ username: "lj@11.com",
5
+ password: "11",
6
+ repoID: "79d1fa93-4b5f-4d6c-8fb5-ad3958e1fa47",
7
+ userInfo: {
8
+ username: 'lj@11.com',
9
+ name: 'lj-',
10
+ contact_email: 'lj@11.com'
11
+ },
12
+ filePath: '/xxx.md',
13
+ fileName: 'xxx.md',
14
+ dirPath: '/'
15
+ };
16
+ export { serverConfig };
@@ -12,6 +12,7 @@ import Loading from '../components/loading';
12
12
  import Layout, { Header, Content } from '../layout';
13
13
  import { generateDefaultDocContent } from '../utils';
14
14
  import ErrorBoundary from './error-boundary';
15
+ import '../assets/css/simple-viewer.css';
15
16
  var SimpleViewer = /*#__PURE__*/function (_React$Component) {
16
17
  _inherits(SimpleViewer, _React$Component);
17
18
  var _super = _createSuper(SimpleViewer);
@@ -19,10 +20,6 @@ var SimpleViewer = /*#__PURE__*/function (_React$Component) {
19
20
  var _this;
20
21
  _classCallCheck(this, SimpleViewer);
21
22
  _this = _super.call(this, props);
22
- _this.onValueChanged = function (value) {
23
- _this.isValueChanged = true;
24
- _this.value = value;
25
- };
26
23
  _this.state = {
27
24
  isContextInit: false,
28
25
  errorMessage: null,
@@ -95,10 +92,27 @@ var SimpleViewer = /*#__PURE__*/function (_React$Component) {
95
92
  className: "d-flex justify-content-center"
96
93
  }, t(errorMessage));
97
94
  }
98
- var docName = context.getSetting('docName');
99
- return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", null, docName)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocViewer, {
95
+ var _context$getSettings = context.getSettings(),
96
+ docName = _context$getSettings.docName,
97
+ sharePermissionText = _context$getSettings.sharePermissionText,
98
+ downloadURL = _context$getSettings.downloadURL;
99
+ return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", {
100
+ className: "doc-info"
101
+ }, /*#__PURE__*/React.createElement("h2", {
102
+ className: "doc-name my-0"
103
+ }, docName), sharePermissionText && /*#__PURE__*/React.createElement("span", {
104
+ className: "sdoc-share-permission ml-2"
105
+ }, sharePermissionText)), /*#__PURE__*/React.createElement("div", {
106
+ className: "doc-ops"
107
+ }, downloadURL && /*#__PURE__*/React.createElement("a", {
108
+ href: downloadURL,
109
+ className: "op-item"
110
+ }, /*#__PURE__*/React.createElement("i", {
111
+ className: "sdocfont sdoc-download"
112
+ })))), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocViewer, {
100
113
  document: document,
101
- onValueChanged: this.onValueChanged
114
+ showToolbar: true,
115
+ showOutline: true
102
116
  }))));
103
117
  }
104
118
  }]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.129",
3
+ "version": "0.1.131-test",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -14,6 +14,8 @@
14
14
  />
15
15
  <missing-glyph />
16
16
 
17
+ <glyph glyph-name="sdoc-download" unicode="&#58962;" d="M582.4 326.4V793.6c0 41.6-32 70.4-70.4 70.4s-70.4-28.8-70.4-70.4v-467.2l-172.8 172.8c-25.6 25.6-70.4 25.6-96-3.2-25.6-25.6-25.6-70.4 0-96l291.2-291.2c25.6-25.6 70.4-25.6 96 0l291.2 291.2c25.6 25.6 25.6 70.4 3.2 96-25.6 25.6-70.4 25.6-96 3.2l-3.2-3.2-172.8-169.6z m-480-284.8h822.4c38.4 0 70.4-28.8 70.4-70.4s-32-67.2-73.6-67.2H102.4C60.8-96 32-67.2 32-25.6c0 35.2 28.8 67.2 70.4 67.2z" horiz-adv-x="1024" />
18
+
17
19
  <glyph glyph-name="sdoc-next-page" unicode="&#58918;" d="M342.4 768c12.8 0 28.8-6.4 38.4-16l329.6-329.6c22.4-22.4 22.4-57.6 0-76.8L380.8 16c-22.4-22.4-57.6-22.4-76.8 0-22.4 22.4-22.4 57.6 0 76.8L595.2 384 304 675.2c-22.4 22.4-22.4 57.6 0 76.8 9.6 9.6 25.6 16 38.4 16z" horiz-adv-x="1024" />
18
20
 
19
21
  <glyph glyph-name="sdoc-previous-page" unicode="&#58961;" d="M672 768c-12.8 0-28.8-6.4-38.4-16L304 422.4c-22.4-22.4-22.4-57.6 0-76.8L633.6 16c22.4-22.4 57.6-22.4 76.8 0 22.4 22.4 22.4 57.6 0 76.8L419.2 384l291.2 291.2c22.4 22.4 22.4 57.6 0 76.8-9.6 9.6-25.6 16-38.4 16z" horiz-adv-x="1024" />
@@ -1,11 +1,11 @@
1
1
  @font-face {
2
2
  font-family: "sdocfont"; /* Project id 4097705 */
3
- src: url('./sdoc-editor-font/iconfont.eot?t=1692935854632'); /* IE9 */
4
- src: url('./sdoc-editor-font/iconfont.eot?t=1692935854632#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
- url('./sdoc-editor-font/iconfont.woff2?t=1692935854632') format('woff2'),
6
- url('./sdoc-editor-font/iconfont.woff?t=1692935854632') format('woff'),
7
- url('./sdoc-editor-font/iconfont.ttf?t=1692935854632') format('truetype'),
8
- url('./sdoc-editor-font/iconfont.svg?t=1692935854632#sdocfont') format('svg');
3
+ src: url('./sdoc-editor-font/iconfont.eot?t=1693362307040'); /* IE9 */
4
+ src: url('./sdoc-editor-font/iconfont.eot?t=1693362307040#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
+ url('./sdoc-editor-font/iconfont.woff2?t=1693362307040') format('woff2'),
6
+ url('./sdoc-editor-font/iconfont.woff?t=1693362307040') format('woff'),
7
+ url('./sdoc-editor-font/iconfont.ttf?t=1693362307040') format('truetype'),
8
+ url('./sdoc-editor-font/iconfont.svg?t=1693362307040#sdocfont') format('svg');
9
9
  }
10
10
 
11
11
  .sdocfont {
@@ -16,6 +16,10 @@
16
16
  -moz-osx-font-smoothing: grayscale;
17
17
  }
18
18
 
19
+ .sdoc-download:before {
20
+ content: "\e652";
21
+ }
22
+
19
23
  .sdoc-next-page:before {
20
24
  content: "\e626";
21
25
  }