@seafile/sdoc-editor 0.1.120 → 0.1.121
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.
- package/dist/basic-sdk/extension/commons/tooltip/index.css +12 -1
- package/dist/basic-sdk/extension/plugins/font/helpers.js +4 -3
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +40 -28
- package/dist/basic-sdk/extension/plugins/header/menu/style.css +32 -0
- package/dist/basic-sdk/extension/plugins/header/plugin.js +9 -0
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +1 -1
- package/dist/basic-sdk/utils/event-handler.js +11 -1
- package/package.json +1 -1
|
@@ -4,7 +4,18 @@
|
|
|
4
4
|
background-color: #303133;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
.bs-tooltip-bottom.sdoc-tooltip .arrow::before,
|
|
8
7
|
.sdoc-tooltip.bs-tooltip-auto[x-placement^="bottom"] .arrow::before {
|
|
9
8
|
border-bottom-color: #303133;
|
|
10
9
|
}
|
|
10
|
+
|
|
11
|
+
.sdoc-tooltip.bs-tooltip-auto[x-placement^="top"] .arrow::before {
|
|
12
|
+
border-top-color: #303133;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.sdoc-tooltip.bs-tooltip-auto[x-placement^="right"] .arrow::before {
|
|
16
|
+
border-right-color: #303133;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.sdoc-tooltip.bs-tooltip-auto[x-placement^="left"] .arrow::before {
|
|
20
|
+
border-left-color: #303133;
|
|
21
|
+
}
|
|
@@ -130,10 +130,11 @@ export var loadFont = function loadFont() {
|
|
|
130
130
|
fontLink.className = GOOGLE_FONT_CLASS;
|
|
131
131
|
document.body.appendChild(fontLink);
|
|
132
132
|
};
|
|
133
|
-
export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight) {
|
|
133
|
+
export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight, leaf) {
|
|
134
|
+
var isCodeBlock = leaf && Object.keys(leaf).includes('token');
|
|
134
135
|
var lang = context.getSetting('lang') || 'zh-cn';
|
|
135
136
|
if (fontName === DEFAULT_FONT) {
|
|
136
|
-
return "'Arial', ".concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");
|
|
137
|
+
return "".concat(isCodeBlock ? 'monospace' : 'Arial', ", ").concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");
|
|
137
138
|
}
|
|
138
139
|
var fontObject = FONT.find(function (item) {
|
|
139
140
|
return item.name === fontName;
|
|
@@ -142,5 +143,5 @@ export var generatorFontFamily = function generatorFontFamily(fontName, fontWeig
|
|
|
142
143
|
fontFamilyName = fontObject.fontFamilyName;
|
|
143
144
|
loadFont(fontObject, fontWeight);
|
|
144
145
|
var validFontName = fontFamilyName && isMac() ? fontFamilyName['mac'] : fontName;
|
|
145
|
-
return "".concat(validFontName, ", ").concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", ").concat(usuallyFontFamilyName || 'sans-serif');
|
|
146
|
+
return "".concat(isCodeBlock ? 'monospace' : validFontName, ", ").concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", ").concat(usuallyFontFamilyName || 'sans-serif');
|
|
146
147
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
4
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
5
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
-
import React from 'react';
|
|
6
|
+
import React, { Fragment } from 'react';
|
|
6
7
|
import { withTranslation } from 'react-i18next';
|
|
7
8
|
import classnames from 'classnames';
|
|
8
9
|
import { getHeaderType, isMenuDisabled, setHeaderType } from '../helpers';
|
|
9
|
-
import {
|
|
10
|
+
import { HEADERS, HEADER_TITLE_MAP, PARAGRAPH } from '../../../constants';
|
|
11
|
+
import Tooltip from '../../../commons/tooltip';
|
|
10
12
|
import './style.css';
|
|
11
13
|
var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
12
14
|
_inherits(HeaderMenu, _React$Component);
|
|
@@ -78,6 +80,11 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
78
80
|
_this.setMenuRef = function (ref) {
|
|
79
81
|
_this.menu = ref;
|
|
80
82
|
};
|
|
83
|
+
_this.getToolTip = function (index) {
|
|
84
|
+
//chrome in Mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
|
|
85
|
+
var isMac = window.navigator.userAgent.indexOf('Macintosh') != -1;
|
|
86
|
+
return isMac ? "\u2318 +\u2325 +".concat(index) : "ctrl+alt+".concat(index);
|
|
87
|
+
};
|
|
81
88
|
_this.state = {
|
|
82
89
|
isShowHeaderPopover: false
|
|
83
90
|
};
|
|
@@ -86,11 +93,13 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
86
93
|
_createClass(HeaderMenu, [{
|
|
87
94
|
key: "render",
|
|
88
95
|
value: function render() {
|
|
96
|
+
var _this2 = this;
|
|
89
97
|
var t = this.props.t;
|
|
90
98
|
var isShowHeaderPopover = this.state.isShowHeaderPopover;
|
|
91
99
|
var headerIconClass = "sdocfont sdoc-".concat(isShowHeaderPopover ? 'caret-up' : 'drop-down');
|
|
92
|
-
var
|
|
100
|
+
var currentType = this.getValue();
|
|
93
101
|
var disabled = this.isDisabled();
|
|
102
|
+
var itemList = [PARAGRAPH, 'divider'].concat(_toConsumableArray(HEADERS));
|
|
94
103
|
return /*#__PURE__*/React.createElement("div", {
|
|
95
104
|
className: "header-menu"
|
|
96
105
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -100,35 +109,38 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
100
109
|
onClick: disabled ? function () {} : this.onToggleClick
|
|
101
110
|
}, /*#__PURE__*/React.createElement("span", {
|
|
102
111
|
className: "active"
|
|
103
|
-
}, t(HEADER_TITLE_MAP[
|
|
112
|
+
}, t(HEADER_TITLE_MAP[currentType])), !disabled && /*#__PURE__*/React.createElement("span", {
|
|
104
113
|
className: headerIconClass
|
|
105
114
|
})), isShowHeaderPopover && /*#__PURE__*/React.createElement("div", {
|
|
106
115
|
ref: this.setMenuRef,
|
|
107
116
|
className: "header-popover sdoc-dropdown-menu"
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
117
|
+
}, itemList.map(function (item, index) {
|
|
118
|
+
if (item == 'divider') {
|
|
119
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
120
|
+
key: index,
|
|
121
|
+
className: "sdoc-dropdown-menu-divider"
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
var isSelected = currentType == item;
|
|
125
|
+
var titleIndex = index == 0 ? 0 : index - 1;
|
|
126
|
+
var id = "".concat(item, "-").concat(titleIndex);
|
|
127
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
128
|
+
key: index
|
|
129
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
130
|
+
id: id,
|
|
131
|
+
className: classnames('sdoc-dropdown-menu-item', {
|
|
132
|
+
'position-relative': isSelected
|
|
133
|
+
}),
|
|
134
|
+
onClick: _this2.onMouseDown(item)
|
|
135
|
+
}, isSelected && /*#__PURE__*/React.createElement("i", {
|
|
136
|
+
className: "sdocfont sdoc-check-mark"
|
|
137
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
138
|
+
className: item
|
|
139
|
+
}, t(HEADER_TITLE_MAP[item]))), /*#__PURE__*/React.createElement(Tooltip, {
|
|
140
|
+
target: id,
|
|
141
|
+
placement: "right"
|
|
142
|
+
}, _this2.getToolTip(titleIndex)));
|
|
143
|
+
})));
|
|
132
144
|
}
|
|
133
145
|
}]);
|
|
134
146
|
return HeaderMenu;
|
|
@@ -62,3 +62,35 @@
|
|
|
62
62
|
.header-menu .header-popover .sdoc-dropdown-menu-item {
|
|
63
63
|
font-size: 14px;
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
.header-menu .header-popover .sdoc-dropdown-menu-item .sdoc-check-mark {
|
|
67
|
+
position: absolute;
|
|
68
|
+
left: 8px;
|
|
69
|
+
transform: scale(.8);
|
|
70
|
+
color: #798d99;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.header-menu .header-popover .header1 {
|
|
74
|
+
font-size: 18px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.header-menu .header-popover .header2 {
|
|
78
|
+
font-size: 16px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.header-menu .header-popover .header3 {
|
|
82
|
+
font-size: 14px;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.header-menu .header-popover .header4 {
|
|
86
|
+
font-size: 12px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.header-menu .header-popover .header5 {
|
|
90
|
+
font-size: 11px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.header-menu .header-popover .header6 {
|
|
94
|
+
font-size: 11px;
|
|
95
|
+
}
|
|
96
|
+
|
|
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
2
2
|
import { Editor, Element, Transforms, Node } from '@seafile/slate';
|
|
3
3
|
import { PARAGRAPH, HEADER_TYPE_ARRAY, LIST_TYPE_ARRAY } from '../../constants';
|
|
4
4
|
import { generateEmptyElement, getSelectedNodeByTypes } from '../../core';
|
|
5
|
+
import { isMenuDisabled, setHeaderType } from './helpers';
|
|
5
6
|
var isSelectionAtLineEnd = function isSelectionAtLineEnd(editor, path) {
|
|
6
7
|
var selection = editor.selection;
|
|
7
8
|
if (!selection) return false;
|
|
@@ -68,6 +69,14 @@ var withHeader = function withHeader(editor) {
|
|
|
68
69
|
}
|
|
69
70
|
return insertFragment(data);
|
|
70
71
|
};
|
|
72
|
+
|
|
73
|
+
// for hotkey
|
|
74
|
+
newEditor.setParagraphHeadingType = function (type) {
|
|
75
|
+
if (isMenuDisabled(newEditor)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
setHeaderType(newEditor, type);
|
|
79
|
+
};
|
|
71
80
|
return newEditor;
|
|
72
81
|
};
|
|
73
82
|
export default withHeader;
|
|
@@ -51,7 +51,7 @@ var renderText = function renderText(props, editor) {
|
|
|
51
51
|
}
|
|
52
52
|
var font = leaf['font'] || DEFAULT_FONT;
|
|
53
53
|
var fontWeight = leaf.BOLD ? 600 : 400;
|
|
54
|
-
style['fontFamily'] = generatorFontFamily(font, fontWeight);
|
|
54
|
+
style['fontFamily'] = generatorFontFamily(font, fontWeight, leaf);
|
|
55
55
|
if (leaf.BOLD) {
|
|
56
56
|
markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
|
|
57
57
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
3
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
4
|
import isHotkey from 'is-hotkey';
|
|
4
5
|
import EventBus from '../utils/event-bus';
|
|
5
6
|
import { getSelectedNodeByType } from '../extension/core/queries/';
|
|
6
|
-
import { ELEMENT_TYPE } from '../extension/constants';
|
|
7
|
+
import { ELEMENT_TYPE, PARAGRAPH, HEADERS } from '../extension/constants';
|
|
7
8
|
import { INTERNAL_EVENT } from '../constants';
|
|
8
9
|
var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
|
|
9
10
|
var _this = this;
|
|
@@ -11,6 +12,15 @@ var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
|
|
|
11
12
|
this.onKeyDown = function (event) {
|
|
12
13
|
var editor = _this.editor;
|
|
13
14
|
|
|
15
|
+
// paragrah, headings
|
|
16
|
+
var paragraphHeadingList = [PARAGRAPH].concat(_toConsumableArray(HEADERS));
|
|
17
|
+
paragraphHeadingList.forEach(function (item, index) {
|
|
18
|
+
if (isHotkey("cmd+opt+".concat(index), event) || isHotkey("ctrl+alt+".concat(index), event)) {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
editor.setParagraphHeadingType(item);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
14
24
|
// bold
|
|
15
25
|
if (isHotkey('mod+b', event)) {
|
|
16
26
|
event.preventDefault();
|