@seafile/comment-editor 0.0.1-alpha.0 → 0.0.1-alpha.10
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/README.md +2 -4
- package/dist/basic-sdk/assets/css/layout.css +1 -45
- package/dist/basic-sdk/assets/css/sdoc-comment-editor-plugin.css +4 -4
- package/dist/basic-sdk/comment/utils.js +39 -0
- package/dist/basic-sdk/constants/index.js +1 -2
- package/dist/basic-sdk/context.js +9 -8
- package/dist/basic-sdk/editor/comment-editor.css +138 -0
- package/dist/basic-sdk/editor/comment-editor.js +289 -0
- package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/mention/render-elem/participant-popover.js +3 -6
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +1 -2
- package/dist/basic-sdk/extension/render/render-comment-editor-element.js +1 -1
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +3 -3
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/post-comment/index.js +2 -2
- package/dist/basic-sdk/hooks/use-comment.js +53 -0
- package/dist/basic-sdk/index.js +12 -39
- package/dist/pages/seafile-comment-editor.js +30 -54
- package/package.json +2 -1
- package/dist/assets/css/plugin-editor.css +0 -7
- package/dist/assets/css/simple-viewer.css +0 -6
- package/dist/basic-sdk/comment/components/comment-all-participants/index.css +0 -83
- package/dist/basic-sdk/comment/components/comment-all-participants/index.js +0 -67
- package/dist/basic-sdk/comment/components/comment-all-participants/participant-avatar.js +0 -43
- package/dist/basic-sdk/comment/components/comment-context-menu/index.css +0 -16
- package/dist/basic-sdk/comment/components/comment-context-menu/index.js +0 -43
- package/dist/basic-sdk/comment/components/comment-context-menu/menu-item.js +0 -57
- package/dist/basic-sdk/comment/components/comment-delete-popover.js +0 -80
- package/dist/basic-sdk/comment/components/comment-editor.js +0 -165
- package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +0 -160
- package/dist/basic-sdk/comment/components/comment-item-content.js +0 -156
- package/dist/basic-sdk/comment/components/comment-item-reply.js +0 -124
- package/dist/basic-sdk/comment/components/comment-item-resolved-reply.js +0 -38
- package/dist/basic-sdk/comment/components/comment-item-wrapper.js +0 -368
- package/dist/basic-sdk/comment/components/comment-list.css +0 -422
- package/dist/basic-sdk/comment/components/comment-list.js +0 -216
- package/dist/basic-sdk/comment/components/comment-operation/index.css +0 -26
- package/dist/basic-sdk/comment/components/comment-operation/index.js +0 -31
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.css +0 -132
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +0 -69
- package/dist/basic-sdk/comment/components/comment-participants-editor/searched-collaborators.js +0 -62
- package/dist/basic-sdk/comment/components/comment-participants-editor/selected-participants.js +0 -48
- package/dist/basic-sdk/comment/components/editor-comment.js +0 -183
- package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +0 -64
- package/dist/basic-sdk/comment/components/elements-comment-count/index.css +0 -29
- package/dist/basic-sdk/comment/components/elements-comment-count/index.js +0 -49
- package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +0 -87
- package/dist/basic-sdk/comment/components/global-comment/global-comment-editor.js +0 -36
- package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +0 -82
- package/dist/basic-sdk/comment/components/global-comment/index.css +0 -326
- package/dist/basic-sdk/comment/components/global-comment/index.js +0 -212
- package/dist/basic-sdk/comment/components/index.js +0 -21
- package/dist/basic-sdk/comment/components/style.css +0 -40
- package/dist/basic-sdk/comment/helper.js +0 -184
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-list.js +0 -45
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +0 -58
- package/dist/basic-sdk/comment/hooks/notification-hooks/index.js +0 -25
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +0 -74
- package/dist/basic-sdk/comment/hooks/use-participants.js +0 -26
- package/dist/basic-sdk/comment/index.js +0 -67
- package/dist/basic-sdk/comment/provider/comment-context-provider.js +0 -37
- package/dist/basic-sdk/comment/provider/index.js +0 -23
- package/dist/basic-sdk/comment/provider/notification-context-provider.js +0 -31
- package/dist/basic-sdk/comment/provider/participants-content-provider.js +0 -96
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +0 -353
- package/dist/basic-sdk/comment/reducer/notification-reducer.js +0 -89
- package/dist/basic-sdk/comment/utils/get-event-transfer.js +0 -77
- package/dist/basic-sdk/comment/utils/index.js +0 -281
- package/dist/basic-sdk/comment/utils/notification-utils.js +0 -62
- package/dist/basic-sdk/editor/comment-article.js +0 -104
- package/dist/basic-sdk/editor/sdoc-comment-editor.js +0 -128
- package/dist/basic-sdk/editor/sdoc-editor.js +0 -50
- package/dist/basic-sdk/hooks/use-collaborators.js +0 -62
- package/dist/basic-sdk/hooks/use-plugins.js +0 -9
- package/dist/basic-sdk/layout/article-container.js +0 -89
- package/dist/basic-sdk/layout/editor-container.js +0 -32
- package/dist/basic-sdk/layout/index.js +0 -20
- package/dist/basic-sdk/right-panel/index.css +0 -15
- package/dist/basic-sdk/right-panel/index.js +0 -86
- package/dist/basic-sdk/right-panel/resize-width/index.css +0 -38
- package/dist/basic-sdk/right-panel/resize-width/index.js +0 -132
- package/dist/basic-sdk/socket/helpers.js +0 -299
- package/dist/basic-sdk/socket/index.js +0 -20
- package/dist/basic-sdk/socket/socket-client.js +0 -211
- package/dist/basic-sdk/socket/socket-manager.js +0 -386
- package/dist/basic-sdk/socket/with-socket-io.js +0 -73
- package/dist/hooks/index.js +0 -12
- package/dist/hooks/use-document.js +0 -75
- /package/dist/basic-sdk/comment/{constants/index.js → constants.js} +0 -0
package/README.md
CHANGED
|
@@ -17,7 +17,6 @@ comment-editor/
|
|
|
17
17
|
assets // css 文件, 图片文件
|
|
18
18
|
commons // 公共组件
|
|
19
19
|
components // 应用组件
|
|
20
|
-
containers // 容器组件
|
|
21
20
|
pages // 页面组件
|
|
22
21
|
app.js // 应用对象
|
|
23
22
|
index.html // 主页
|
|
@@ -27,11 +26,10 @@ comment-editor/
|
|
|
27
26
|
setting.local.dist // 用户基于 setting.local.dist.js copy 一份的配置文件
|
|
28
27
|
src/(组件库)
|
|
29
28
|
assets // css 文件, 资源文件
|
|
29
|
+
basic-sdk // 编辑器元素包
|
|
30
30
|
components // 封装的视图组件
|
|
31
|
-
editor // 封装的编辑器组件
|
|
32
|
-
lib // 底层接口
|
|
33
31
|
utils // 工具接口
|
|
34
|
-
|
|
32
|
+
pages // 封装的视图组件
|
|
35
33
|
index.js // 组件库导出内容入口文件
|
|
36
34
|
tests // 测试
|
|
37
35
|
webpack // site 打包文件
|
|
@@ -113,48 +113,4 @@
|
|
|
113
113
|
margin: 0 auto;
|
|
114
114
|
padding-top: 20px;
|
|
115
115
|
padding-bottom: 20px;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/* article style --> ./sdoc-editor-article.css */
|
|
119
|
-
|
|
120
|
-
.sdoc-editor-container .seafile-block-container {
|
|
121
|
-
position: relative;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.sdoc-editor-container .seafile-block-container .comment-count {
|
|
125
|
-
position: absolute;
|
|
126
|
-
right: -55px;
|
|
127
|
-
top: 0px;
|
|
128
|
-
border-radius: 4px;
|
|
129
|
-
width: 15px;
|
|
130
|
-
height: 15px;
|
|
131
|
-
line-height: 18px;
|
|
132
|
-
pointer-events: none;
|
|
133
|
-
display: flex;
|
|
134
|
-
align-items: center;
|
|
135
|
-
justify-content: center;
|
|
136
|
-
color: #fff;
|
|
137
|
-
background: rgba(0, 0, 0, .3);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
.sdoc-editor-container .seafile-block-container .comment-count__btn {
|
|
141
|
-
font-size: 12px;
|
|
142
|
-
transform: scale(.75);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
.sdoc-comment-editor-toolbar {
|
|
146
|
-
display: flex;
|
|
147
|
-
justify-content: space-between;
|
|
148
|
-
align-items: center;
|
|
149
|
-
height: 32px;
|
|
150
|
-
user-select: none;
|
|
151
|
-
border-top: 1px solid #e5e6e8;
|
|
152
|
-
z-index: 102;
|
|
153
|
-
margin: 0 8px;
|
|
154
|
-
margin-top: 5px;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.sdoc-comment-editor-menu-group {
|
|
158
|
-
border-right: none;
|
|
159
|
-
padding-left: 0 !important;
|
|
160
|
-
}
|
|
116
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/* List */
|
|
2
|
-
.sdoc-editor-container .
|
|
2
|
+
.sdoc-editor-container .comment-editor .list-container {
|
|
3
3
|
padding-left: 2em !important;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
.
|
|
6
|
+
.comment-editor .list-container li p {
|
|
7
7
|
margin: 0 !important;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/* Paragraph */
|
|
11
|
-
.
|
|
11
|
+
.comment-editor .comment-editor-paragraph {
|
|
12
12
|
margin: 0.8em 0 !important;
|
|
13
13
|
padding: 0 !important;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/* Image */
|
|
17
|
-
.
|
|
17
|
+
.comment-editor .sdoc-image-wrapper {
|
|
18
18
|
padding: 1px !important;
|
|
19
19
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.searchCollaborators = void 0;
|
|
7
|
+
var _helper = require("../extension/plugins/mention/helper");
|
|
8
|
+
const searchCollaborators = (collaborators, searchValue, editor) => {
|
|
9
|
+
const validSearchValue = searchValue ? searchValue.trim().toLowerCase() : '';
|
|
10
|
+
const validCollaborators = Array.isArray(collaborators) && collaborators.length > 0 ? collaborators : [];
|
|
11
|
+
if (!validSearchValue) return validCollaborators;
|
|
12
|
+
|
|
13
|
+
// The current character is '@' and the previous character is a null character
|
|
14
|
+
const beforeStr = (0, _helper.getPreCharacters)(editor);
|
|
15
|
+
const isEmptyStr = beforeStr.slice(-2, -1).trim().length === 0;
|
|
16
|
+
if (beforeStr.slice(-1) === '@' && isEmptyStr) {
|
|
17
|
+
return validCollaborators;
|
|
18
|
+
}
|
|
19
|
+
return validCollaborators.filter(collaborator => {
|
|
20
|
+
const {
|
|
21
|
+
name,
|
|
22
|
+
name_pinyin = ''
|
|
23
|
+
} = collaborator;
|
|
24
|
+
if (name.toString().toLowerCase().indexOf(validSearchValue) > -1) return true;
|
|
25
|
+
if (!name_pinyin) return false;
|
|
26
|
+
const validNamePinyin = name_pinyin.toString().toLowerCase();
|
|
27
|
+
const validSearchPinyinValue = validSearchValue.replace(/ |'/g, '');
|
|
28
|
+
|
|
29
|
+
// complete: For example, seatable can be retrieved when searching for sea.
|
|
30
|
+
if (validNamePinyin.indexOf(validSearchPinyinValue) > -1) return true;
|
|
31
|
+
if (validNamePinyin.replace(/'/g, '').indexOf(validSearchPinyinValue) > -1) return true;
|
|
32
|
+
const validNamePinyinList = validNamePinyin.split('\'');
|
|
33
|
+
// acronym: For example, sea table can be retrieved when searching for st.
|
|
34
|
+
const namePinyinAcronym = validNamePinyinList.map(item => item && item.trim() ? item.trim().slice(0, 1) : '');
|
|
35
|
+
if (namePinyinAcronym.join('').indexOf(validSearchPinyinValue) > -1) return true;
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
exports.searchCollaborators = searchCollaborators;
|
|
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "PLUGIN_DISPLAY_TYPE", {
|
|
|
19
19
|
return _plugin.PLUGIN_DISPLAY_TYPE;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
exports.Z_INDEX = exports.WIKI_OUTLINE = exports.
|
|
22
|
+
exports.Z_INDEX = exports.WIKI_OUTLINE = exports.WIKI_EDITOR = exports.SDOC_STORAGE = exports.REBASE_TYPES = exports.REBASE_TYPE = exports.REBASE_ORIGIN = exports.REBASE_MARK_KEY = exports.REBASE_MARKS = void 0;
|
|
23
23
|
var _keyCodes = _interopRequireDefault(require("./key-codes"));
|
|
24
24
|
var _plugin = require("./plugin");
|
|
25
25
|
var _Z_INDEX = _interopRequireWildcard(require("./z-index"));
|
|
@@ -72,7 +72,6 @@ const INTERNAL_EVENT = exports.INTERNAL_EVENT = {
|
|
|
72
72
|
};
|
|
73
73
|
const PAGE_EDIT_AREA_WIDTH = exports.PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
|
74
74
|
const COMMENT_EDITOR_EDIT_AREA_WIDTH = exports.COMMENT_EDITOR_EDIT_AREA_WIDTH = 364;
|
|
75
|
-
const WIKI_EDITOR_EDIT_AREA_WIDTH = exports.WIKI_EDITOR_EDIT_AREA_WIDTH = 714;
|
|
76
75
|
const COMMENT_EDITOR = exports.COMMENT_EDITOR = 'comment_editor';
|
|
77
76
|
const WIKI_EDITOR = exports.WIKI_EDITOR = 'wiki_editor';
|
|
78
77
|
const DOCUMENT_PLUGIN_EDITOR = exports.DOCUMENT_PLUGIN_EDITOR = 'document_plugin_editor';
|
|
@@ -55,15 +55,16 @@ class Context {
|
|
|
55
55
|
this.api = null;
|
|
56
56
|
this.config = null;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
init(api) {
|
|
59
59
|
this.initSettings(); // lazy init context class
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
this.api = api;
|
|
61
|
+
// const server = this.getSetting('serviceUrl');
|
|
62
|
+
// const token = this.getSetting('accessToken');
|
|
63
|
+
// this.api = new SeafileAPI(server, token);
|
|
64
|
+
// const isOpenSocket = this.getSetting('isOpenSocket');
|
|
65
|
+
// if (isOpenSocket) {
|
|
66
|
+
// this.sdocServerApi = new SDocServerApi(this.settings);
|
|
67
|
+
// }
|
|
67
68
|
}
|
|
68
69
|
getSettings() {
|
|
69
70
|
return this.settings;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
.comment-editor-wrapper {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
cursor: text;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.comment-editor-wrapper .comment-editor-container {
|
|
9
|
+
flex: 1;
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
min-height: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.comment-editor-wrapper .comment-editor-content {
|
|
16
|
+
border: 1px solid #ececec;
|
|
17
|
+
border-radius: 3px;
|
|
18
|
+
transition: border-color .3s ease;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.comment-editor-wrapper .comment-editor-content:focus-within {
|
|
22
|
+
border-color: #ff8e03;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* comment-editor */
|
|
26
|
+
.comment-editor-wrapper .comment-editor-content .article.comment-editor {
|
|
27
|
+
width: 100%;
|
|
28
|
+
padding: 8px;
|
|
29
|
+
padding-bottom: 0;
|
|
30
|
+
min-height: 60px;
|
|
31
|
+
max-height: 130px;
|
|
32
|
+
box-shadow: none;
|
|
33
|
+
overflow-y: auto;
|
|
34
|
+
overflow-x: hidden;
|
|
35
|
+
border: none;
|
|
36
|
+
background-color: transparent;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.comment-editor-wrapper .comment-editor-content .article.comment-editor :first-child {
|
|
40
|
+
margin-top: 0 !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.comment-editor-wrapper .comment-editor:empty:before {
|
|
44
|
+
content: attr(placeholder);
|
|
45
|
+
opacity: .6;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.comment-editor-wrapper .comment-editor:focus-visible {
|
|
49
|
+
outline: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.comment-editor-wrapper .comment-editor:focus {
|
|
53
|
+
border: 1px solid rgba(0, 0, 0, .12);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.comment-editor-wrapper .comment-editor-user-info {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
margin-bottom: 10px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.comment-editor-wrapper .comment-editor-user-info .comment-editor-user-img {
|
|
63
|
+
height: 30px;
|
|
64
|
+
width: 30px;
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
margin-right: 8px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.comment-editor-wrapper .comment-editor-user-info .comment-editor-user-name {
|
|
71
|
+
flex: 1;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
text-overflow: ellipsis;
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
user-select: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.comment-editor-wrapper .comment-operations {
|
|
79
|
+
display: flex;
|
|
80
|
+
justify-content: flex-end;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* comment-editor-toolbar */
|
|
84
|
+
.comment-editor-wrapper .comment-editor-toolbar {
|
|
85
|
+
display: flex;
|
|
86
|
+
justify-content: space-between;
|
|
87
|
+
align-items: center;
|
|
88
|
+
height: 32px;
|
|
89
|
+
user-select: none;
|
|
90
|
+
z-index: 102;
|
|
91
|
+
margin: 0 8px;
|
|
92
|
+
margin-top: 5px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.comment-editor-wrapper .comment-editor-toolbar .comment-editor-menu-group {
|
|
96
|
+
border-right: none !important;
|
|
97
|
+
padding-left: 0 !important;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group {
|
|
101
|
+
height: 100%;
|
|
102
|
+
padding: 6px 0 6px 8px;
|
|
103
|
+
font-size: 0.75rem;
|
|
104
|
+
border-right: 1px solid #e5e6e8;
|
|
105
|
+
border-radius: 0 !important;
|
|
106
|
+
color: #444;
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
justify-content: center;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item {
|
|
113
|
+
width: 24px;
|
|
114
|
+
height: 24px;
|
|
115
|
+
line-height: 24px;
|
|
116
|
+
margin-right: 8px;
|
|
117
|
+
border: none !important;
|
|
118
|
+
color: #444;
|
|
119
|
+
background-color: transparent;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item:disabled {
|
|
123
|
+
color: #BDBDBD;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item:hover {
|
|
127
|
+
background-color: #F2F2F2;
|
|
128
|
+
border-radius: 2px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item[data-active='true'] {
|
|
132
|
+
color: #eb8205;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item .sdocfont,
|
|
136
|
+
.sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-icon .sdocfont {
|
|
137
|
+
font-size: 12px;
|
|
138
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactI18next = require("react-i18next");
|
|
11
|
+
var _slate = require("@seafile/slate");
|
|
12
|
+
var _slateReact = require("@seafile/slate-react");
|
|
13
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
|
+
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
15
|
+
var _scrollIntoViewIfNeeded = _interopRequireDefault(require("scroll-into-view-if-needed"));
|
|
16
|
+
var _constants = require("../constants");
|
|
17
|
+
var _context = _interopRequireDefault(require("../context"));
|
|
18
|
+
var _useCursors = require("../cursor/use-cursors");
|
|
19
|
+
var _decorates = require("../decorates");
|
|
20
|
+
var _extension = require("../extension");
|
|
21
|
+
var _insertElementDialog = _interopRequireDefault(require("../extension/commons/insert-element-dialog"));
|
|
22
|
+
var _constants2 = require("../extension/constants");
|
|
23
|
+
var _core = require("../extension/core");
|
|
24
|
+
var _renderCommentEditorElement = _interopRequireDefault(require("../extension/render/render-comment-editor-element"));
|
|
25
|
+
var _commentEditorToolbar = _interopRequireDefault(require("../extension/toolbar/comment-editor-toolbar"));
|
|
26
|
+
var _useComment = require("../hooks/use-comment");
|
|
27
|
+
var _useScrollContext = require("../hooks/use-scroll-context");
|
|
28
|
+
var _nodeId = _interopRequireDefault(require("../node-id"));
|
|
29
|
+
var _mdToSlate = _interopRequireDefault(require("../slate-convert/md-to-slate"));
|
|
30
|
+
var _slateToMd = _interopRequireDefault(require("../slate-convert/slate-to-md"));
|
|
31
|
+
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
|
|
32
|
+
var _eventHandler = _interopRequireDefault(require("../utils/event-handler"));
|
|
33
|
+
require("./comment-editor.css");
|
|
34
|
+
const getSubmitTip = (type, content) => {
|
|
35
|
+
if (content) return 'Save';
|
|
36
|
+
return type === 'comment' ? 'Comment' : 'Reply';
|
|
37
|
+
};
|
|
38
|
+
const DEFAULT_PLACEHOLDER = 'Enter_comment_shift_enter_for_new_line_Enter_to_send';
|
|
39
|
+
const CommentEditor = _ref => {
|
|
40
|
+
let {
|
|
41
|
+
content,
|
|
42
|
+
commentContent,
|
|
43
|
+
placeholder = DEFAULT_PLACEHOLDER,
|
|
44
|
+
insertContent,
|
|
45
|
+
updateContent,
|
|
46
|
+
onContentChange,
|
|
47
|
+
setIsEditing,
|
|
48
|
+
hiddenComment,
|
|
49
|
+
hiddenUserInfo,
|
|
50
|
+
closeComment,
|
|
51
|
+
addParticipants
|
|
52
|
+
} = _ref;
|
|
53
|
+
const commentWrapperRef = (0, _react.useRef)();
|
|
54
|
+
const {
|
|
55
|
+
t
|
|
56
|
+
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
57
|
+
const {
|
|
58
|
+
className,
|
|
59
|
+
userInfo,
|
|
60
|
+
type
|
|
61
|
+
} = (0, _useComment.useComment)();
|
|
62
|
+
const submitTip = (0, _react.useMemo)(() => getSubmitTip(type, content), [content, type]);
|
|
63
|
+
const document = (0, _react.useMemo)(() => {
|
|
64
|
+
const cursor = {};
|
|
65
|
+
let elements = null;
|
|
66
|
+
elements = [(0, _core.generateEmptyElement)(_constants2.PARAGRAPH, {
|
|
67
|
+
placeholder
|
|
68
|
+
})];
|
|
69
|
+
return {
|
|
70
|
+
elements,
|
|
71
|
+
cursor
|
|
72
|
+
};
|
|
73
|
+
}, [placeholder]);
|
|
74
|
+
const [slateValue, setSlateValue] = (0, _react.useState)(document.elements);
|
|
75
|
+
const commentEditorContainerRef = (0, _react.useRef)(null);
|
|
76
|
+
const editor = (0, _react.useMemo)(() => {
|
|
77
|
+
const defaultEditor = (0, _extension.createCommentEditor)();
|
|
78
|
+
const newEditor = (0, _nodeId.default)(defaultEditor);
|
|
79
|
+
const {
|
|
80
|
+
cursors
|
|
81
|
+
} = document;
|
|
82
|
+
newEditor.cursors = cursors || {};
|
|
83
|
+
newEditor.width = _constants.COMMENT_EDITOR_EDIT_AREA_WIDTH; // default width
|
|
84
|
+
newEditor.editorType = _constants.COMMENT_EDITOR;
|
|
85
|
+
return newEditor;
|
|
86
|
+
}, [document]);
|
|
87
|
+
const {
|
|
88
|
+
cursors
|
|
89
|
+
} = (0, _useCursors.useCursors)(editor);
|
|
90
|
+
const decorate = (0, _decorates.usePipDecorate)(editor);
|
|
91
|
+
// init eventHandler
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
const eventProxy = (0, _react.useMemo)(() => new _eventHandler.default(editor), []);
|
|
94
|
+
const updateValue = (0, _react.useCallback)(value => {
|
|
95
|
+
if (!value || value.trim() === '') return;
|
|
96
|
+
if (!content) return insertContent(value);
|
|
97
|
+
updateContent && updateContent(value);
|
|
98
|
+
}, [content, insertContent, updateContent]);
|
|
99
|
+
const onSubmit = (0, _react.useCallback)(event => {
|
|
100
|
+
event && event.stopPropagation();
|
|
101
|
+
const mdString = (0, _slateToMd.default)(editor.children);
|
|
102
|
+
updateValue(mdString);
|
|
103
|
+
addParticipants(userInfo.username);
|
|
104
|
+
editor.children = [(0, _core.generateEmptyElement)(_constants2.PARAGRAPH, {
|
|
105
|
+
placeholder
|
|
106
|
+
})];
|
|
107
|
+
_slate.Transforms.select(editor, _slate.Editor.start(editor, []));
|
|
108
|
+
onContentChange && onContentChange(null);
|
|
109
|
+
closeComment && closeComment();
|
|
110
|
+
}, [editor, updateValue, addParticipants, userInfo.username, placeholder, onContentChange, closeComment]);
|
|
111
|
+
const onSubmitByEnterKey = (0, _react.useCallback)(event => {
|
|
112
|
+
if (!_slateReact.ReactEditor.isFocused(editor)) return;
|
|
113
|
+
onSubmit(event);
|
|
114
|
+
}, [editor, onSubmit]);
|
|
115
|
+
|
|
116
|
+
// addEventListener
|
|
117
|
+
(0, _react.useEffect)(() => {
|
|
118
|
+
const eventBus = _eventBus.default.getInstance();
|
|
119
|
+
const unsubscribePostComment = eventBus.subscribe(_constants.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmitByEnterKey);
|
|
120
|
+
return () => {
|
|
121
|
+
unsubscribePostComment();
|
|
122
|
+
};
|
|
123
|
+
}, [onSubmitByEnterKey]);
|
|
124
|
+
const onCancel = (0, _react.useCallback)(event => {
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
const {
|
|
127
|
+
type: eventType,
|
|
128
|
+
keyCode,
|
|
129
|
+
target
|
|
130
|
+
} = event;
|
|
131
|
+
if (eventType === 'keydown' && keyCode !== _constants.KeyCodes.Esc) return;
|
|
132
|
+
if (eventType === 'click') {
|
|
133
|
+
const isSdocContentWrapper = target.classList.contains('sdoc-content-wrapper');
|
|
134
|
+
const listContainer = window.document.querySelector('#global-comment-list-container');
|
|
135
|
+
const resizeContainer = window.document.querySelector('.sdoc-comment-resize-handler');
|
|
136
|
+
const isClickOnListContainer = listContainer && listContainer.contains(target);
|
|
137
|
+
const isClickOnCommentEditorContainer = commentWrapperRef.current.contains(target);
|
|
138
|
+
const isClickResizeContainer = resizeContainer && resizeContainer.contains(target);
|
|
139
|
+
const isPreventCancel = isClickOnListContainer || isClickOnCommentEditorContainer || isClickResizeContainer || isSdocContentWrapper;
|
|
140
|
+
if (isPreventCancel) return;
|
|
141
|
+
}
|
|
142
|
+
setIsEditing && setIsEditing(false);
|
|
143
|
+
hiddenComment && hiddenComment(false);
|
|
144
|
+
if (onContentChange) {
|
|
145
|
+
if (editor.children.find(n => _slate.Node.string(n).trim())) {
|
|
146
|
+
onContentChange((0, _slateToMd.default)(editor.children));
|
|
147
|
+
} else {
|
|
148
|
+
onContentChange(null);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
152
|
+
}, [setIsEditing]);
|
|
153
|
+
|
|
154
|
+
// set editor children
|
|
155
|
+
(0, _react.useEffect)(() => {
|
|
156
|
+
let children = (0, _mdToSlate.default)(content);
|
|
157
|
+
if (commentContent) {
|
|
158
|
+
children = (0, _mdToSlate.default)(commentContent);
|
|
159
|
+
}
|
|
160
|
+
editor.children = children;
|
|
161
|
+
_slate.Transforms.select(editor, _slate.Editor.end(editor, []));
|
|
162
|
+
}, [editor, content, commentContent]);
|
|
163
|
+
|
|
164
|
+
// useMount: focus editor
|
|
165
|
+
(0, _react.useEffect)(() => {
|
|
166
|
+
const [firstNode] = editor.children;
|
|
167
|
+
if (firstNode) {
|
|
168
|
+
const [firstNodeFirstChild] = firstNode.children;
|
|
169
|
+
if (firstNodeFirstChild) {
|
|
170
|
+
const endOfFirstNode = _slate.Editor.end(editor, [0, 0]);
|
|
171
|
+
const range = {
|
|
172
|
+
anchor: endOfFirstNode,
|
|
173
|
+
focus: endOfFirstNode
|
|
174
|
+
};
|
|
175
|
+
(0, _core.focusEditor)(editor, range);
|
|
176
|
+
}
|
|
177
|
+
// Force refresh to fix comment list
|
|
178
|
+
setSlateValue([...editor.children]);
|
|
179
|
+
}
|
|
180
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
181
|
+
}, []);
|
|
182
|
+
const handleFocusEditor = e => {
|
|
183
|
+
if (e.target === commentEditorContainerRef.current) {
|
|
184
|
+
const focusPoint = _slate.Editor.end(editor, []);
|
|
185
|
+
(0, _core.focusEditor)(editor, focusPoint);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const handleScrollIntoView = (0, _react.useCallback)((editor, domRange) => {
|
|
189
|
+
try {
|
|
190
|
+
const {
|
|
191
|
+
selection
|
|
192
|
+
} = editor;
|
|
193
|
+
// Do not scroll into view, when focus on image
|
|
194
|
+
const [imageNodeEntry] = _slate.Editor.nodes(editor, {
|
|
195
|
+
match: n => [_constants2.IMAGE, _constants2.IMAGE_BLOCK].includes(n.type),
|
|
196
|
+
at: selection
|
|
197
|
+
});
|
|
198
|
+
if (imageNodeEntry) return;
|
|
199
|
+
const focusedNode = _slate.Node.get(editor, selection.focus.path);
|
|
200
|
+
const domNode = _slateReact.ReactEditor.toDOMNode(editor, focusedNode);
|
|
201
|
+
if (!domNode) return;
|
|
202
|
+
(0, _scrollIntoViewIfNeeded.default)(domNode, {
|
|
203
|
+
'scrollMode': 'if-needed'
|
|
204
|
+
});
|
|
205
|
+
} catch (error) {
|
|
206
|
+
//
|
|
207
|
+
}
|
|
208
|
+
}, []);
|
|
209
|
+
const onMouseDown = (0, _react.useCallback)(event => {
|
|
210
|
+
if (event.button === 0) {
|
|
211
|
+
// Compatible with the editor which unload table plugin
|
|
212
|
+
editor.reSetTableSelectedRange && editor.reSetTableSelectedRange();
|
|
213
|
+
const eventBus = _eventBus.default.getInstance();
|
|
214
|
+
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
215
|
+
}
|
|
216
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
217
|
+
}, []);
|
|
218
|
+
const onKeyDown = (0, _react.useCallback)(event => {
|
|
219
|
+
if ((0, _isHotkey.default)('enter', event)) {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
const eventBus = _eventBus.default.getInstance();
|
|
222
|
+
eventBus.dispatch(_constants.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, event);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if ((0, _isHotkey.default)('shift+enter', event)) {
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
_slate.Editor.insertBreak(editor);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
eventProxy.onKeyDown(event);
|
|
231
|
+
}, [eventProxy, editor]);
|
|
232
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
233
|
+
className: (0, _classnames.default)('comment-editor-wrapper', className),
|
|
234
|
+
ref: commentWrapperRef
|
|
235
|
+
}, type === 'comment' && !hiddenUserInfo && /*#__PURE__*/_react.default.createElement("div", {
|
|
236
|
+
className: "comment-editor-user-info"
|
|
237
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
238
|
+
className: "comment-editor-user-img"
|
|
239
|
+
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
240
|
+
src: userInfo.avatar_url,
|
|
241
|
+
alt: "",
|
|
242
|
+
height: "100%",
|
|
243
|
+
width: "100%"
|
|
244
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
245
|
+
className: "comment-editor-user-name"
|
|
246
|
+
}, userInfo.name)), /*#__PURE__*/_react.default.createElement("div", {
|
|
247
|
+
className: "comment-editor-container"
|
|
248
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
249
|
+
className: "comment-editor-content"
|
|
250
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
251
|
+
ref: commentEditorContainerRef,
|
|
252
|
+
className: "article comment-editor",
|
|
253
|
+
onClick: handleFocusEditor
|
|
254
|
+
}, /*#__PURE__*/_react.default.createElement(_useScrollContext.ScrollContext.Provider, {
|
|
255
|
+
value: {
|
|
256
|
+
scrollRef: commentEditorContainerRef
|
|
257
|
+
}
|
|
258
|
+
}, /*#__PURE__*/_react.default.createElement(_slateReact.Slate, {
|
|
259
|
+
editor: editor,
|
|
260
|
+
value: slateValue,
|
|
261
|
+
onChange: setSlateValue
|
|
262
|
+
}, /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
|
|
263
|
+
id: "sdoc-editor",
|
|
264
|
+
scrollSelectionIntoView: handleScrollIntoView,
|
|
265
|
+
cursors: cursors,
|
|
266
|
+
renderElement: props => (0, _renderCommentEditorElement.default)({
|
|
267
|
+
...props,
|
|
268
|
+
commentType: type
|
|
269
|
+
}),
|
|
270
|
+
renderLeaf: _extension.renderLeaf,
|
|
271
|
+
onMouseDown: onMouseDown,
|
|
272
|
+
decorate: decorate,
|
|
273
|
+
onCut: eventProxy.onCut,
|
|
274
|
+
onCopy: eventProxy.onCopy,
|
|
275
|
+
onCompositionStart: eventProxy.onCompositionStart,
|
|
276
|
+
onCompositionUpdate: eventProxy.onCompositionUpdate,
|
|
277
|
+
onCompositionEnd: eventProxy.onCompositionEnd,
|
|
278
|
+
onKeyDown: onKeyDown,
|
|
279
|
+
onBeforeInput: eventProxy.onBeforeInput
|
|
280
|
+
})))), /*#__PURE__*/_react.default.createElement(_commentEditorToolbar.default, {
|
|
281
|
+
editor: editor,
|
|
282
|
+
onSubmit: onSubmit,
|
|
283
|
+
submitBtnText: t(submitTip),
|
|
284
|
+
onCancel: onCancel
|
|
285
|
+
}))), /*#__PURE__*/_react.default.createElement(_insertElementDialog.default, {
|
|
286
|
+
editor: editor
|
|
287
|
+
}));
|
|
288
|
+
};
|
|
289
|
+
var _default = exports.default = CommentEditor;
|
|
@@ -291,7 +291,7 @@ const handleBase64Image = (editor, path, imgData) => {
|
|
|
291
291
|
const file = new File([blob], `${_slugid.default.nice()}.jpg`, {
|
|
292
292
|
type: unit8Array.mime
|
|
293
293
|
});
|
|
294
|
-
_context.default.uploadLocalImage([file]).then(res => {
|
|
294
|
+
_context.default.api.uploadLocalImage([file]).then(res => {
|
|
295
295
|
const _data = {
|
|
296
296
|
...imgData,
|
|
297
297
|
src: res[0]
|
|
@@ -51,7 +51,7 @@ const useCopyImage = _ref => {
|
|
|
51
51
|
const file = new File([blob], 'downloaded_image.png', {
|
|
52
52
|
type: blob.type
|
|
53
53
|
});
|
|
54
|
-
const imageUrl = await _context.default.uploadLocalImage([file]);
|
|
54
|
+
const imageUrl = await _context.default.api.uploadLocalImage([file]);
|
|
55
55
|
if (imageUrl && imageUrl[0]) {
|
|
56
56
|
updateImageNode(editor, element, imageUrl[0]);
|
|
57
57
|
}
|
|
@@ -42,7 +42,8 @@ const useUploadImage = _ref => {
|
|
|
42
42
|
const uploadCurrentImage = async () => {
|
|
43
43
|
try {
|
|
44
44
|
const fileItem = _imageCache.default.getImage(file_uuid);
|
|
45
|
-
|
|
45
|
+
console.log(111, _context.default.api.uploadLocalImage);
|
|
46
|
+
const imageUrl = await _context.default.api.uploadLocalImage([fileItem]);
|
|
46
47
|
if (imageUrl && imageUrl[0]) {
|
|
47
48
|
updateImageNode(editor, element, imageUrl[0]);
|
|
48
49
|
}
|
|
@@ -44,7 +44,7 @@ const LinkMenu = _ref => {
|
|
|
44
44
|
isActive: false,
|
|
45
45
|
onMouseDown: openLinkDialog
|
|
46
46
|
};
|
|
47
|
-
menuProps.id = '
|
|
47
|
+
menuProps.id = 'comment-editor' + menuConfig.id;
|
|
48
48
|
return /*#__PURE__*/_react.default.createElement(_commons.MenuItem, menuProps);
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -9,10 +9,9 @@ exports.default = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _slate = require("@seafile/slate");
|
|
11
11
|
var _constants = require("../../../../comment/constants");
|
|
12
|
-
var _useParticipants = require("../../../../comment/hooks/use-participants");
|
|
13
12
|
var _utils = require("../../../../comment/utils");
|
|
14
13
|
var _constants2 = require("../../../../constants");
|
|
15
|
-
var
|
|
14
|
+
var _useComment = require("../../../../hooks/use-comment");
|
|
16
15
|
var _eventBus = _interopRequireDefault(require("../../../../utils/event-bus"));
|
|
17
16
|
var _mouseEvent = require("../../../../utils/mouse-event");
|
|
18
17
|
var _commons = require("../../../commons");
|
|
@@ -27,12 +26,10 @@ const ParticipantPopover = _ref => {
|
|
|
27
26
|
} = _ref;
|
|
28
27
|
const collaboratorsPopoverRef = (0, _react.useRef)(null);
|
|
29
28
|
const {
|
|
30
|
-
collaborators
|
|
31
|
-
} = (0, _useCollaborators.useCollaborators)();
|
|
32
|
-
const {
|
|
29
|
+
collaborators,
|
|
33
30
|
addParticipants,
|
|
34
31
|
participants
|
|
35
|
-
} = (0,
|
|
32
|
+
} = (0, _useComment.useComment)();
|
|
36
33
|
const [searchedCollaborators, setSearchedCollaborators] = (0, _react.useState)([]);
|
|
37
34
|
const [activeCollaboratorIndex, setActiveCollaboratorIndex] = (0, _react.useState)(-1);
|
|
38
35
|
const [validCollaborators, setValidCollaborators] = (0, _react.useState)([]);
|