@seafile/sdoc-editor 1.0.66 → 1.0.67

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.
@@ -18,6 +18,7 @@ const TEXT_STYLE = exports.TEXT_STYLE = 'text_style';
18
18
  const ITALIC = exports.ITALIC = 'italic';
19
19
  const BOLD = exports.BOLD = 'bold';
20
20
  const UNDERLINE = 'underline';
21
+ const INLINE_CODE = 'inline_code';
21
22
  const HIGHLIGHT_COLOR = 'highlight_color';
22
23
  const COLOR = 'color';
23
24
 
@@ -110,6 +111,12 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
110
111
  text: 'Underline',
111
112
  ariaLabel: 'underline',
112
113
  type: TEXT_STYLE_MAP.UNDERLINE
114
+ }, {
115
+ id: INLINE_CODE,
116
+ iconClass: 'sdocfont sdoc-inline-code',
117
+ text: 'Inline_code',
118
+ ariaLabel: 'code',
119
+ type: TEXT_STYLE_MAP.CODE
113
120
  }, {
114
121
  id: `sdoc-${HIGHLIGHT_COLOR}`,
115
122
  iconClass: 'sdocfont sdoc-highlight-color',
@@ -7,12 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _isHotkey = _interopRequireDefault(require("is-hotkey"));
9
9
  var _slate = require("@seafile/slate");
10
+ var _core = require("../../../core");
10
11
  var _constants = require("../../../constants");
11
12
  const withParagraph = editor => {
12
13
  const {
13
14
  handleTab,
14
15
  insertText,
15
- deleteBackward
16
+ deleteBackward,
17
+ onHotKeyDown
16
18
  } = editor;
17
19
  const newEditor = editor;
18
20
  newEditor.handleTab = event => {
@@ -77,6 +79,53 @@ const withParagraph = editor => {
77
79
  }
78
80
  return deleteBackward(unit);
79
81
  };
82
+ newEditor.onHotKeyDown = event => {
83
+ const selectedParagraph = (0, _core.getSelectedNodeByType)(editor, _constants.PARAGRAPH);
84
+ if (selectedParagraph) {
85
+ const {
86
+ selection
87
+ } = newEditor;
88
+ if (_slate.Range.isCollapsed(selection)) {
89
+ if ((0, _isHotkey.default)('ArrowRight', event)) {
90
+ const lastLeaf = selectedParagraph.children.slice(-1)[0];
91
+ // When the last character of a paragraph is code text, right-click to move the cursor and insert a new text node
92
+ // Avoid being unable to enter new text when the code text is at the end of the paragraph
93
+ if (lastLeaf !== null && lastLeaf !== void 0 && lastLeaf.code) {
94
+ const {
95
+ focus
96
+ } = selection;
97
+ const [, lastPoint] = _slate.Editor.edges(newEditor, [focus.path[0]]);
98
+ if (_slate.Point.equals(focus, lastPoint)) {
99
+ event.preventDefault();
100
+ _slate.Editor.insertFragment(newEditor, [(0, _core.generateDefaultText)(' ')]);
101
+ return;
102
+ }
103
+ }
104
+ }
105
+ if ((0, _isHotkey.default)('Enter', event)) {
106
+ const lastLeaf = selectedParagraph.children.slice(-1)[0];
107
+ // The last text node style in a paragraph is code. When pressing Enter, insert an empty node first and then split the node.
108
+ // Avoid empty inline nodes at the beginning of new lines
109
+ if (lastLeaf !== null && lastLeaf !== void 0 && lastLeaf.code) {
110
+ const {
111
+ focus
112
+ } = selection;
113
+ const [, leafPath] = _slate.Editor.leaf(newEditor, selection);
114
+ const [, lastPoint] = _slate.Editor.edges(newEditor, leafPath);
115
+ if (_slate.Point.equals(focus, lastPoint)) {
116
+ event.preventDefault();
117
+ _slate.Editor.insertFragment(newEditor, [(0, _core.generateDefaultText)(' ')]);
118
+ _slate.Transforms.splitNodes(newEditor, {
119
+ always: true
120
+ });
121
+ return;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ }
127
+ return onHotKeyDown && onHotKeyDown(event);
128
+ };
80
129
  return newEditor;
81
130
  };
82
131
  var _default = exports.default = withParagraph;
@@ -99,14 +99,16 @@ const withSdocLink = editor => {
99
99
  }
100
100
  if (e.key === 'ArrowRight') {
101
101
  const nextPoint = _slate.Editor.after(newEditor, selection);
102
- const [nextNode, nextPath] = _slate.Editor.node(newEditor, nextPoint.path, {
103
- depth: 2
104
- });
105
- if ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === _constants.SDOC_LINK) {
106
- const afterPointSdocLink = _slate.Editor.after(newEditor, nextPath);
107
- _slate.Transforms.select(newEditor, afterPointSdocLink);
108
- e.preventDefault();
109
- return;
102
+ if (nextPoint) {
103
+ const [nextNode, nextPath] = _slate.Editor.node(newEditor, nextPoint.path, {
104
+ depth: 2
105
+ });
106
+ if ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === _constants.SDOC_LINK) {
107
+ const afterPointSdocLink = _slate.Editor.after(newEditor, nextPath);
108
+ _slate.Transforms.select(newEditor, afterPointSdocLink);
109
+ e.preventDefault();
110
+ return;
111
+ }
110
112
  }
111
113
  }
112
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.66",
3
+ "version": "1.0.67",
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-inline-code" unicode="&#58998;" d="M1024 384l-272-288-67.2 70.4 204.8 217.6-204.8 217.6L752 672l272-288zM0 384l272-288 67.2 70.4L134.4 384l204.8 217.6L272 672 0 384z m451.2-512l-99.2 3.2L579.2 896h99.2l-227.2-1024z" horiz-adv-x="1024" />
18
+
17
19
  <glyph glyph-name="sdoc-sort" unicode="&#58996;" d="M294.4 790.4l201.6-204.8c19.2-19.2 19.2-51.2 0-73.6-19.2-19.2-51.2-19.2-70.4 0L320 620.8v-604.8c0-25.6-22.4-48-48-48S224-9.6 224 16V620.8L118.4 512c-19.2-19.2-48-19.2-67.2-3.2l-3.2 3.2c-19.2 19.2-19.2 51.2 0 73.6l201.6 204.8c12.8 12.8 32 12.8 44.8 0zM752 800c25.6 0 48-22.4 48-48v-604.8l105.6 108.8c19.2 19.2 51.2 19.2 70.4 0 19.2-19.2 19.2-51.2 0-73.6l-201.6-204.8c-12.8-12.8-32-12.8-44.8 0l-201.6 204.8c-19.2 19.2-19.2 51.2 0 73.6l3.2 3.2c19.2 16 48 16 67.2-3.2l105.6-108.8V752c0 25.6 22.4 48 48 48z" horiz-adv-x="1024" />
18
20
 
19
21
  <glyph glyph-name="sdoc-set-up" unicode="&#58997;" d="M598.52384 809.6l12.8-92.8 6.4-38.4 35.2-16c12.8-6.4 28.8-16 41.6-25.6l32-19.2 35.2 12.8 92.8 35.2 86.4-140.8-76.8-54.4-32-25.6 3.2-38.4v-44.8l-3.2-38.4 32-25.6 76.8-57.6-83.2-140.8-92.8 35.2-35.2 12.8-32-19.2c-12.8-9.6-28.8-19.2-41.6-25.6l-35.2-16-6.4-38.4-12.8-92.8h-172.8l-12.8 92.8-6.4 38.4-35.2 16c-12.8 6.4-28.8 16-41.6 25.6l-32 19.2-35.2-12.8-92.8-35.2-86.4 140.8L160.12384 297.6l32 25.6-3.2 38.4V384v22.4l3.2 38.4-32 25.6-76.8 57.6 83.2 140.8 92.8-35.2 35.2-12.8 32 19.2c12.8 9.6 28.8 19.2 41.6 25.6l35.2 16 6.4 38.4 12.8 92.8h176m12.8 83.2H416.12384c-32 0-57.6-22.4-60.8-51.2l-16-105.6c-19.2-9.6-35.2-19.2-54.4-32L182.52384 748.8c-9.6 3.2-16 3.2-22.4 3.2-22.4 0-41.6-9.6-54.4-28.8L6.52384 560c-12.8-28.8-6.4-60.8 16-80l86.4-67.2c0-9.6-3.2-22.4-3.2-28.8 0-9.6 0-19.2 3.2-28.8L22.52384 288c-22.4-19.2-28.8-51.2-16-76.8l96-163.2c9.6-19.2 32-32 54.4-32 6.4 0 12.8 0 22.4 3.2l102.4 41.6c16-12.8 35.2-22.4 54.4-28.8l16-105.6c3.2-28.8 28.8-51.2 60.8-51.2H608.12384c32 0 57.6 22.4 60.8 51.2l16 105.6c19.2 9.6 35.2 19.2 54.4 28.8l102.4-41.6c6.4-3.2 16-3.2 22.4-3.2 22.4 0 41.6 9.6 54.4 28.8l99.2 166.4c16 25.6 9.6 57.6-16 76.8l-86.4 67.2c0 9.6 3.2 19.2 3.2 28.8s0 22.4-3.2 28.8l86.4 67.2c22.4 19.2 28.8 51.2 16 76.8l-96 163.2c-9.6 19.2-32 32-54.4 32-6.4 0-12.8 0-22.4-3.2l-102.4-41.6c-16 12.8-35.2 22.4-54.4 28.8L672.12384 844.8C665.72384 873.6 640.12384 896 611.32384 896zM512.12384 512c70.4 0 128-57.6 128-128s-57.6-128-128-128-128 57.6-128 128 57.6 128 128 128m0 86.4a214.4 214.4 0 1 1 0-428.8 214.4 214.4 0 0 1 0 428.8z" horiz-adv-x="1026" />
@@ -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=1722915152576'); /* IE9 */
4
- src: url('./sdoc-editor-font/iconfont.eot?t=1722915152576#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
- url('./sdoc-editor-font/iconfont.woff2?t=1722915152576') format('woff2'),
6
- url('./sdoc-editor-font/iconfont.woff?t=1722915152576') format('woff'),
7
- url('./sdoc-editor-font/iconfont.ttf?t=1722915152576') format('truetype'),
8
- url('./sdoc-editor-font/iconfont.svg?t=1722915152576#sdocfont') format('svg');
3
+ src: url('./sdoc-editor-font/iconfont.eot?t=1724747529924'); /* IE9 */
4
+ src: url('./sdoc-editor-font/iconfont.eot?t=1724747529924#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
+ url('./sdoc-editor-font/iconfont.woff2?t=1724747529924') format('woff2'),
6
+ url('./sdoc-editor-font/iconfont.woff?t=1724747529924') format('woff'),
7
+ url('./sdoc-editor-font/iconfont.ttf?t=1724747529924') format('truetype'),
8
+ url('./sdoc-editor-font/iconfont.svg?t=1724747529924#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-inline-code:before {
20
+ content: "\e676";
21
+ }
22
+
19
23
  .sdoc-sort:before {
20
24
  content: "\e674";
21
25
  }