@seafile/sdoc-editor 1.0.210 → 1.0.211-test-0.1
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/api/seafile-api.js +2 -0
- package/dist/basic-sdk/assets/css/sdoc-editor-plugins.css +83 -0
- package/dist/basic-sdk/extension/core/queries/index.js +22 -1
- package/dist/basic-sdk/extension/plugins/check-list/plugin.js +13 -10
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +48 -37
- package/dist/basic-sdk/extension/plugins/header/plugin.js +8 -0
- package/dist/basic-sdk/extension/plugins/image/helpers.js +8 -0
- package/dist/basic-sdk/extension/plugins/image/plugin.js +19 -0
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +92 -18
- package/dist/basic-sdk/extension/plugins/link/helpers.js +18 -19
- package/dist/basic-sdk/extension/plugins/link/plugin.js +1 -1
- package/dist/basic-sdk/extension/plugins/paragraph/plugin.js +17 -1
- package/dist/context.js +1 -0
- package/package.json +1 -1
- package/public/locales/cs/sdoc-editor.json +3 -1
- package/public/locales/de/sdoc-editor.json +308 -306
- package/public/locales/en/sdoc-editor.json +3 -1
- package/public/locales/es/sdoc-editor.json +3 -1
- package/public/locales/es_AR/sdoc-editor.json +3 -1
- package/public/locales/es_MX/sdoc-editor.json +3 -1
- package/public/locales/fr/sdoc-editor.json +3 -1
- package/public/locales/it/sdoc-editor.json +3 -1
- package/public/locales/ru/sdoc-editor.json +4 -2
- package/public/locales/zh_CN/sdoc-editor.json +3 -1
package/dist/api/seafile-api.js
CHANGED
|
@@ -41,6 +41,7 @@ class SeafileAPI {
|
|
|
41
41
|
const url = '/api/v2.1/seadoc/upload-image/' + docUuid + '/';
|
|
42
42
|
const form = new FormData();
|
|
43
43
|
for (const fileItem of imageFiles) {
|
|
44
|
+
console.log(imageFiles, fileItem);
|
|
44
45
|
if (fileItem.type.startsWith('image/')) {
|
|
45
46
|
const fileName = this.getImageFileNameWithUuid(fileItem);
|
|
46
47
|
const file = new File([fileItem], fileName, {
|
|
@@ -49,6 +50,7 @@ class SeafileAPI {
|
|
|
49
50
|
form.append('file', file);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
53
|
+
console.log(this.req.post(url, form));
|
|
52
54
|
return this.req.post(url, form);
|
|
53
55
|
}
|
|
54
56
|
getSdocDownloadImageUrl(docUuid, imageName) {
|
|
@@ -62,6 +62,89 @@
|
|
|
62
62
|
caret-color: transparent;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
.sdoc-editor__article .sdoc-image-wrapper .sdoc-image-placeholder-wrapper {
|
|
66
|
+
width: 360px;
|
|
67
|
+
/* vertical-align: middle; */
|
|
68
|
+
aspect-ratio: 1 / 1;
|
|
69
|
+
background-color: #f0f0f0;
|
|
70
|
+
border: 1px solid #ccc;
|
|
71
|
+
/* position: relative; */
|
|
72
|
+
/* overflow: hidden; */
|
|
73
|
+
padding: 0 3%;
|
|
74
|
+
/* font-size: 1.2vw; */
|
|
75
|
+
/* transform-origin: top left; */
|
|
76
|
+
/* transform: scale(1); */
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.sdoc-editor__article .sdoc-image-wrapper .sdoc-image-title {
|
|
80
|
+
/* width: 100%;
|
|
81
|
+
height: 5%;
|
|
82
|
+
flex-direction: row;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
gap: 0.5em; */
|
|
87
|
+
user-select: none;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.sdoc-editor__article .sdoc-image-title .sdoc-exclamation-circle {
|
|
91
|
+
/* width: 10%;
|
|
92
|
+
height: 10%; */
|
|
93
|
+
font-size: 18px;
|
|
94
|
+
align-items: center;
|
|
95
|
+
justify-content: center;
|
|
96
|
+
color: red;
|
|
97
|
+
display: flex;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.sdoc-editor__article .sdoc-image-title .sdoc-image-tip-title {
|
|
101
|
+
color: red;
|
|
102
|
+
font-size: 18px;
|
|
103
|
+
user-select: none;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.sdoc-editor__article .sdoc-image-wrapper .sdoc-image-tip-content {
|
|
107
|
+
/* width: 100%;
|
|
108
|
+
font-size: 0.7em;
|
|
109
|
+
margin-top: 2%;
|
|
110
|
+
text-align: center;
|
|
111
|
+
white-space: nowrap; */
|
|
112
|
+
user-select: none;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* .sdoc-editor__article .sdoc-image-title .sdoc-exclamation-circle { */
|
|
116
|
+
/* width: 10%;
|
|
117
|
+
height: 10%;
|
|
118
|
+
font-size: 1em; */
|
|
119
|
+
/* align-items: center;
|
|
120
|
+
justify-content: center; */
|
|
121
|
+
/* color: red; */
|
|
122
|
+
/* display: flex; */
|
|
123
|
+
/* } */
|
|
124
|
+
|
|
125
|
+
.sdoc-editor__article .sdoc-image-process-container {
|
|
126
|
+
/* background-color: #F2F2F2; */
|
|
127
|
+
width: 40px;
|
|
128
|
+
height: 40px;
|
|
129
|
+
display: flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.sdoc-editor__article .sdoc-image-process-container .loading-spinner {
|
|
134
|
+
border: 5px solid #d8d8d8;
|
|
135
|
+
border-top: 5px solid #939393;
|
|
136
|
+
border-radius: 50%;
|
|
137
|
+
width: 30px;
|
|
138
|
+
height: 30px;
|
|
139
|
+
animation: spin 1s linear infinite;
|
|
140
|
+
user-select: none;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@keyframes spin {
|
|
144
|
+
0% { transform: rotate(0deg); }
|
|
145
|
+
100% { transform: rotate(360deg); }
|
|
146
|
+
}
|
|
147
|
+
|
|
65
148
|
.sdoc-editor__article .sdoc-image-inner {
|
|
66
149
|
position: relative;
|
|
67
150
|
display: inline-block;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isMiddlePoint = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isEmptyArticle = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isContainsVoidElement = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
7
|
+
exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isMiddlePoint = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isEmptyArticle = exports.isCursorAtBlockStart = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isContainsVoidElement = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
8
8
|
var _slate = require("@seafile/slate");
|
|
9
9
|
var _slateReact = require("@seafile/slate-react");
|
|
10
10
|
var _utils = require("../utils");
|
|
@@ -455,6 +455,27 @@ const isBlockAboveEmpty = editor => {
|
|
|
455
455
|
return isAncestorEmpty(editor, block);
|
|
456
456
|
};
|
|
457
457
|
exports.isBlockAboveEmpty = isBlockAboveEmpty;
|
|
458
|
+
const isCursorAtBlockStart = (editor, options) => {
|
|
459
|
+
const {
|
|
460
|
+
selection
|
|
461
|
+
} = editor;
|
|
462
|
+
if (!selection) return false;
|
|
463
|
+
const nodeEntry = getAboveBlockNode(editor, options);
|
|
464
|
+
let [node, path] = nodeEntry || [];
|
|
465
|
+
if (!path) return false;
|
|
466
|
+
|
|
467
|
+
// Special handling of placeholders, such as link, inline image
|
|
468
|
+
if (_slate.Node.string(node.children[0]).length === 0) {
|
|
469
|
+
const {
|
|
470
|
+
offset,
|
|
471
|
+
path: point
|
|
472
|
+
} = selection.focus;
|
|
473
|
+
if (offset !== 0) return false;
|
|
474
|
+
return _slate.Path.equals(point, [path[0], 1, 0]);
|
|
475
|
+
}
|
|
476
|
+
return isStartPoint(editor, selection.focus, path);
|
|
477
|
+
};
|
|
478
|
+
exports.isCursorAtBlockStart = isCursorAtBlockStart;
|
|
458
479
|
const isSelectionAtBlockStart = (editor, options) => {
|
|
459
480
|
const {
|
|
460
481
|
selection
|
|
@@ -40,19 +40,22 @@ const withCheckList = editor => {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// If it is check-list-item, handle your own business logic
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
checked: false
|
|
49
|
-
}, {
|
|
50
|
-
at: node[1]
|
|
43
|
+
if ((0, _core.isCursorAtBlockStart)(editor)) {
|
|
44
|
+
const path = (0, _core.findPath)(editor, node);
|
|
45
|
+
const newNode = (0, _core.generateEmptyElement)(_constants.CHECK_LIST_ITEM);
|
|
46
|
+
_slate.Transforms.insertNodes(editor, newNode, {
|
|
47
|
+
at: path
|
|
51
48
|
});
|
|
52
49
|
return;
|
|
53
50
|
}
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
_slate.Transforms.splitNodes(editor, {
|
|
52
|
+
always: true
|
|
53
|
+
});
|
|
54
|
+
_slate.Transforms.setNodes(editor, {
|
|
55
|
+
checked: false
|
|
56
|
+
}, {
|
|
57
|
+
at: node[1]
|
|
58
|
+
});
|
|
56
59
|
};
|
|
57
60
|
newEditor.deleteBackward = unit => {
|
|
58
61
|
const {
|
|
@@ -68,47 +68,47 @@ const withCodeBlock = editor => {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
return insertFragment(data);
|
|
71
|
-
}
|
|
72
|
-
// Paste into code block
|
|
73
|
-
if ((0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
|
|
74
|
-
// Pasted data is code block split with code-line
|
|
75
|
-
data.forEach((node, index) => {
|
|
76
|
-
if (node.type === _constants.CODE_BLOCK) {
|
|
77
|
-
const codeLineArr = node.children.map(line => line);
|
|
78
|
-
data.splice(index, 1, ...codeLineArr);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
const newData = data.map(node => {
|
|
82
|
-
const text = _slate.Node.string(node);
|
|
83
|
-
const codeLine = {
|
|
84
|
-
id: _slugid.default.nice(),
|
|
85
|
-
type: _constants.CODE_LINE,
|
|
86
|
-
children: [{
|
|
87
|
-
text: text,
|
|
88
|
-
id: _slugid.default.nice()
|
|
89
|
-
}]
|
|
90
|
-
};
|
|
91
|
-
return codeLine;
|
|
92
|
-
});
|
|
71
|
+
}
|
|
93
72
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
insertBreak();
|
|
102
|
-
insertFragment(restNode);
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
73
|
+
// Paste into code block
|
|
74
|
+
if ((0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
|
|
75
|
+
// Pasted data is code block split with code-line
|
|
76
|
+
data.forEach((node, index) => {
|
|
77
|
+
if (node.type === _constants.CODE_BLOCK) {
|
|
78
|
+
const codeLineArr = node.children.map(line => line);
|
|
79
|
+
data.splice(index, 1, ...codeLineArr);
|
|
105
80
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
81
|
+
});
|
|
82
|
+
const newData = data.map(node => {
|
|
83
|
+
const text = _slate.Node.string(node);
|
|
84
|
+
const codeLine = {
|
|
85
|
+
id: _slugid.default.nice(),
|
|
86
|
+
type: _constants.CODE_LINE,
|
|
87
|
+
children: [{
|
|
88
|
+
text: text,
|
|
89
|
+
id: _slugid.default.nice()
|
|
90
|
+
}]
|
|
91
|
+
};
|
|
92
|
+
return codeLine;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// current focus code-line string not empty
|
|
96
|
+
const string = _slate.Editor.string(newEditor, newEditor.selection.focus.path);
|
|
97
|
+
if (string.length !== 0 && _slate.Range.isCollapsed(newEditor.selection)) {
|
|
98
|
+
const [node, ...restNode] = newData;
|
|
99
|
+
const text = _slate.Node.string(node);
|
|
100
|
+
insertText(text);
|
|
101
|
+
if (restNode.length !== 0) {
|
|
102
|
+
insertBreak();
|
|
103
|
+
insertFragment(restNode);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
110
106
|
}
|
|
107
|
+
return insertFragment(newData);
|
|
111
108
|
}
|
|
109
|
+
|
|
110
|
+
// Paste into not a code block
|
|
111
|
+
return insertFragment(data);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// Rewrite normalizeNode
|
|
@@ -213,6 +213,17 @@ const withCodeBlock = editor => {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
|
+
newEditor.insertBreak = () => {
|
|
217
|
+
const selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants.CODE_LINE);
|
|
218
|
+
if (selectedNode != null && (0, _core.isCursorAtBlockStart)(newEditor)) {
|
|
219
|
+
const line = (0, _core.generateEmptyElement)(_constants.CODE_LINE);
|
|
220
|
+
_slate.Transforms.insertNodes(editor, line, {
|
|
221
|
+
at: selectedNode[1]
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
insertBreak();
|
|
226
|
+
};
|
|
216
227
|
return newEditor;
|
|
217
228
|
};
|
|
218
229
|
var _default = exports.default = withCodeBlock;
|
|
@@ -55,6 +55,14 @@ const withHeader = editor => {
|
|
|
55
55
|
insertBreak();
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
+
if ((0, _core.isCursorAtBlockStart)(newEditor)) {
|
|
59
|
+
const [currentNode, path] = match;
|
|
60
|
+
const newNode = (0, _core.generateEmptyElement)(currentNode.type);
|
|
61
|
+
_slate.Transforms.insertNodes(editor, newNode, {
|
|
62
|
+
at: path
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
58
66
|
const isAtLineEnd = isSelectionAtLineEnd(editor, match[1]);
|
|
59
67
|
const nextNode = _slate.Editor.next(editor, {
|
|
60
68
|
at: match[1]
|
|
@@ -134,6 +134,7 @@ const updateImage = (editor, data) => {
|
|
|
134
134
|
};
|
|
135
135
|
exports.updateImage = updateImage;
|
|
136
136
|
const getImageURL = (data, editor) => {
|
|
137
|
+
console.log(5, data);
|
|
137
138
|
const {
|
|
138
139
|
src: url,
|
|
139
140
|
column_key
|
|
@@ -277,4 +278,11 @@ const handleBase64Image = (editor, path, imgData) => {
|
|
|
277
278
|
});
|
|
278
279
|
});
|
|
279
280
|
};
|
|
281
|
+
|
|
282
|
+
// export const updateFontSize = () => {
|
|
283
|
+
// const placeholder = document.querySelector('.sdoc-image-placeholder-wrapper');
|
|
284
|
+
// const parentWidth = placeholder.offsetWidth;
|
|
285
|
+
// placeholder.style.fontSize = `${parentWidth * 0.05}px`;
|
|
286
|
+
// console.log(parentWidth * 0.05);
|
|
287
|
+
// };
|
|
280
288
|
exports.handleBase64Image = handleBase64Image;
|
|
@@ -51,6 +51,7 @@ const withImage = editor => {
|
|
|
51
51
|
const fragment = data.getData(`application/${_constants.CLIPBOARD_FORMAT_KEY}`) || (0, _documentUtils.getSlateFragmentAttribute)(data);
|
|
52
52
|
const originSdocUuid = data.getData(`text/${_constants.CLIPBOARD_ORIGIN_SDOC_KEY}`);
|
|
53
53
|
if (fragment && originSdocUuid) {
|
|
54
|
+
console.log('1');
|
|
54
55
|
const decoded = decodeURIComponent(window.atob(fragment));
|
|
55
56
|
const fragmentData = JSON.parse(decoded);
|
|
56
57
|
if ((0, _helpers.hasSdocImages)(originSdocUuid, fragmentData)) {
|
|
@@ -75,11 +76,29 @@ const withImage = editor => {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
if (data.types && data.types.includes('Files') && data.files[0].type.includes(_constants.IMAGE)) {
|
|
79
|
+
console.log(data.files);
|
|
78
80
|
_context.default.uploadLocalImage(data.files).then(fileUrl => {
|
|
79
81
|
(0, _helpers.insertImage)(newEditor, fileUrl, editor.selection, _constants.INSERT_POSITION.CURRENT);
|
|
80
82
|
});
|
|
81
83
|
return;
|
|
82
84
|
}
|
|
85
|
+
|
|
86
|
+
// const otherDataTypes = data.types.filter(
|
|
87
|
+
// (type) => type !== 'text/html' && type !== 'text/plain' && type !== 'Files'
|
|
88
|
+
// );
|
|
89
|
+
// if (otherDataTypes.length > 0) {
|
|
90
|
+
// otherDataTypes.forEach((type) => {
|
|
91
|
+
// if(data.getData(type).includes(IMAGE)) {
|
|
92
|
+
// const url;
|
|
93
|
+
// }
|
|
94
|
+
// conti
|
|
95
|
+
|
|
96
|
+
// });
|
|
97
|
+
// };
|
|
98
|
+
|
|
99
|
+
const notionBlockData = data.getData('text/_notion-blocks-v3-production');
|
|
100
|
+
const notionPageSourceData = data.getData('text/_notion-page-source-production');
|
|
101
|
+
console.log(notionBlockData, notionPageSourceData);
|
|
83
102
|
insertData(data);
|
|
84
103
|
};
|
|
85
104
|
newEditor.insertFragment = data => {
|
|
@@ -20,9 +20,8 @@ var _useScrollContext = require("../../../hooks/use-scroll-context");
|
|
|
20
20
|
var _constants2 = require("./constants");
|
|
21
21
|
var _constants3 = require("../../constants");
|
|
22
22
|
var _constants4 = require("../../../../constants");
|
|
23
|
-
var _imagePlaceholder = _interopRequireDefault(require("../../../assets/images/image-placeholder.png"));
|
|
24
23
|
const Image = _ref => {
|
|
25
|
-
var _imageRef$current, _imageRef$current2;
|
|
24
|
+
var _imageRef$current, _imageRef$current2, _imageRef$current3;
|
|
26
25
|
let {
|
|
27
26
|
element,
|
|
28
27
|
editor,
|
|
@@ -57,6 +56,7 @@ const Image = _ref => {
|
|
|
57
56
|
const [isShowImageHoverMenu, setIsShowImageHoverMenu] = (0, _react.useState)(false);
|
|
58
57
|
const [menuPosition, setMenuPosition] = (0, _react.useState)({});
|
|
59
58
|
const [caption, setCaption] = (0, _react.useState)((data === null || data === void 0 ? void 0 : data.caption) || '');
|
|
59
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
60
60
|
const registerEvent = (0, _react.useCallback)(eventList => {
|
|
61
61
|
eventList.forEach(element => {
|
|
62
62
|
document.addEventListener(element.eventName, element.event);
|
|
@@ -72,11 +72,21 @@ const Image = _ref => {
|
|
|
72
72
|
event.preventDefault();
|
|
73
73
|
event.stopPropagation();
|
|
74
74
|
const changeX = event.clientX - ((_resizerRef$current = resizerRef.current) === null || _resizerRef$current === void 0 ? void 0 : _resizerRef$current.getBoundingClientRect().left) - 5;
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
console.log(3, isShowImagePlaceholder);
|
|
76
|
+
if (isShowImagePlaceholder) {
|
|
77
|
+
const imageWidth = imageRef.current.getBoundingClientRect().width + changeX;
|
|
78
|
+
if (imageWidth < 20) return;
|
|
79
|
+
imageRef.current.width.baseVal.value = imageWidth;
|
|
80
|
+
setMovingWidth(imageWidth);
|
|
81
|
+
// updateFontSize();
|
|
82
|
+
} else {
|
|
83
|
+
const imageWidth = imageRef.current.width + changeX;
|
|
84
|
+
if (imageWidth < 20) return;
|
|
85
|
+
imageRef.current.width = imageWidth;
|
|
86
|
+
setMovingWidth(imageWidth);
|
|
87
|
+
}
|
|
88
|
+
// console.log(44, imageRef.current.width, imageRef.current.width.baseVal)
|
|
89
|
+
}, [isShowImagePlaceholder]);
|
|
80
90
|
const onResizeEnd = (0, _react.useCallback)(event => {
|
|
81
91
|
event.preventDefault();
|
|
82
92
|
event.stopPropagation();
|
|
@@ -118,9 +128,10 @@ const Image = _ref => {
|
|
|
118
128
|
let imageWidth = element.data.width || '';
|
|
119
129
|
if (movingWidth) imageWidth = movingWidth;
|
|
120
130
|
return {
|
|
121
|
-
width: imageWidth
|
|
131
|
+
width: imageWidth,
|
|
132
|
+
display: isLoading ? 'none' : 'inline-block'
|
|
122
133
|
};
|
|
123
|
-
}, [element.data, movingWidth]);
|
|
134
|
+
}, [element.data, movingWidth, isLoading]);
|
|
124
135
|
const onScroll = (0, _react.useCallback)(() => {
|
|
125
136
|
setPosition();
|
|
126
137
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -192,12 +203,16 @@ const Image = _ref => {
|
|
|
192
203
|
setIsShowImageHoverMenu(true);
|
|
193
204
|
}, [setPosition]);
|
|
194
205
|
const reloadImage = (0, _react.useCallback)(() => {
|
|
206
|
+
setIsLoading(false);
|
|
207
|
+
console.log(66666);
|
|
195
208
|
if (imageRef.current) {
|
|
196
209
|
imageRef.current['src'] = (0, _helpers.getImageURL)(data, editor);
|
|
197
210
|
setIsShowImagePlaceholder(false);
|
|
198
211
|
}
|
|
199
212
|
}, [data, editor]);
|
|
200
213
|
const onImageLoadError = (0, _react.useCallback)(() => {
|
|
214
|
+
setIsLoading(false);
|
|
215
|
+
console.log(666, data.src);
|
|
201
216
|
// Check is due to the image is pasted from the clipboard in base64
|
|
202
217
|
if (data.src.startsWith('data:image/jpeg;base64')) {
|
|
203
218
|
return (0, _helpers.handleBase64Image)(editor, path, data);
|
|
@@ -208,6 +223,7 @@ const Image = _ref => {
|
|
|
208
223
|
const eventBus = _eventBus.default.getInstance();
|
|
209
224
|
eventBus.subscribe(_constants.INTERNAL_EVENT.RELOAD_IMAGE, reloadImage);
|
|
210
225
|
}
|
|
226
|
+
console.log(5);
|
|
211
227
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
228
|
}, []);
|
|
213
229
|
const onSetCaption = (0, _react.useCallback)(e => {
|
|
@@ -224,7 +240,13 @@ const Image = _ref => {
|
|
|
224
240
|
});
|
|
225
241
|
}
|
|
226
242
|
}, [data, editor, element]);
|
|
227
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null,
|
|
243
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isLoading && /*#__PURE__*/_react.default.createElement("div", {
|
|
244
|
+
className: "sdoc-image-process-container"
|
|
245
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
246
|
+
className: "loading-spinner"
|
|
247
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
248
|
+
className: "spinner"
|
|
249
|
+
})), children), isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement("span", Object.assign({
|
|
228
250
|
className: (0, _classnames.default)('sdoc-image-wrapper', className)
|
|
229
251
|
}, attributes, {
|
|
230
252
|
style: {
|
|
@@ -233,18 +255,70 @@ const Image = _ref => {
|
|
|
233
255
|
onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
|
|
234
256
|
contentEditable: "false",
|
|
235
257
|
suppressContentEditableWarning: true
|
|
236
|
-
}), /*#__PURE__*/_react.default.createElement("
|
|
258
|
+
}), /*#__PURE__*/_react.default.createElement("svg", {
|
|
259
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
260
|
+
viewBox: "0 0 360 360",
|
|
261
|
+
preserveAspectRatio: "xMinYMin meet",
|
|
262
|
+
className: (0, _classnames.default)('sdoc-image-placeholder-wrapper', {
|
|
263
|
+
'image-selected': isSelected
|
|
264
|
+
}),
|
|
237
265
|
ref: imageRef,
|
|
238
|
-
src: _imagePlaceholder.default,
|
|
239
266
|
style: getImageStyle(),
|
|
240
|
-
draggable: false
|
|
241
|
-
|
|
242
|
-
|
|
267
|
+
draggable: false
|
|
268
|
+
}, /*#__PURE__*/_react.default.createElement("rect", {
|
|
269
|
+
width: "100%",
|
|
270
|
+
height: "100%",
|
|
271
|
+
fill: "#f0f0f0"
|
|
272
|
+
}), /*#__PURE__*/_react.default.createElement("g", {
|
|
273
|
+
className: "sdoc-image-content-wrapper",
|
|
274
|
+
textAnchor: "middle",
|
|
275
|
+
dominantBaseline: "middle",
|
|
276
|
+
transform: "translate(180, 180)"
|
|
277
|
+
}, /*#__PURE__*/_react.default.createElement("g", {
|
|
278
|
+
className: "sdoc-image-title",
|
|
279
|
+
transform: "translate(0, 0)"
|
|
280
|
+
}, /*#__PURE__*/_react.default.createElement("foreignObject", {
|
|
281
|
+
x: "-22%",
|
|
282
|
+
y: "-16",
|
|
283
|
+
width: "20",
|
|
284
|
+
height: "28"
|
|
285
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
286
|
+
className: "sdocfont sdoc-exclamation-circle"
|
|
287
|
+
})), /*#__PURE__*/_react.default.createElement("text", {
|
|
288
|
+
className: "sdoc-image-tip-title",
|
|
289
|
+
x: "5%",
|
|
290
|
+
fontSize: "20",
|
|
291
|
+
fill: "red",
|
|
292
|
+
fontFamily: "Arial, sans-serif"
|
|
293
|
+
}, t('Image_copy_error'))), /*#__PURE__*/_react.default.createElement("text", {
|
|
294
|
+
className: "sdoc-image-tip-content",
|
|
295
|
+
x: "0",
|
|
296
|
+
y: "10%",
|
|
297
|
+
fontSize: "12",
|
|
298
|
+
textAnchor: "middle",
|
|
299
|
+
fill: "black",
|
|
300
|
+
fontFamily: "Arial, sans-serif"
|
|
301
|
+
}, t('Image_cannot_be_copied_Please_download_the_source_image')), /*#__PURE__*/_react.default.createElement("text", {
|
|
302
|
+
className: "sdoc-image-tip-content",
|
|
303
|
+
x: "0",
|
|
304
|
+
y: "16%",
|
|
305
|
+
fontSize: "12",
|
|
306
|
+
textAnchor: "middle",
|
|
307
|
+
fill: "black",
|
|
308
|
+
fontFamily: "Arial, sans-serif"
|
|
309
|
+
}, t('And_select_insert_-_image_to_upload')))), isSelected && /*#__PURE__*/_react.default.createElement("span", {
|
|
310
|
+
className: "image-resizer",
|
|
311
|
+
ref: resizerRef,
|
|
312
|
+
onMouseDown: onResizeStart
|
|
313
|
+
}), isResizing && /*#__PURE__*/_react.default.createElement("span", {
|
|
314
|
+
className: "image-size"
|
|
315
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.clientWidth))), /*#__PURE__*/_react.default.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/_react.default.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight)), children), !isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", Object.assign({
|
|
243
316
|
"data-id": element.id,
|
|
244
317
|
className: (0, _classnames.default)('sdoc-image-wrapper', className)
|
|
245
318
|
}, attributes, {
|
|
246
319
|
style: {
|
|
247
|
-
...style
|
|
320
|
+
...style,
|
|
321
|
+
userSelect: 'none'
|
|
248
322
|
},
|
|
249
323
|
onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
|
|
250
324
|
contentEditable: "false",
|
|
@@ -272,12 +346,12 @@ const Image = _ref => {
|
|
|
272
346
|
onMouseDown: onResizeStart
|
|
273
347
|
}), isResizing && /*#__PURE__*/_react.default.createElement("span", {
|
|
274
348
|
className: "image-size"
|
|
275
|
-
}, /*#__PURE__*/_react.default.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$
|
|
349
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current2 = imageRef.current) === null || _imageRef$current2 === void 0 ? void 0 : _imageRef$current2.clientWidth))), /*#__PURE__*/_react.default.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/_react.default.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), nodeEntry[0].type === _constants3.IMAGE_BLOCK && show_caption && /*#__PURE__*/_react.default.createElement("input", {
|
|
276
350
|
id: "sdoc-image-caption-input",
|
|
277
351
|
ref: imageCaptionInputRef,
|
|
278
352
|
className: "sdoc-image-caption-input-wrapper",
|
|
279
353
|
style: {
|
|
280
|
-
width: (data === null || data === void 0 ? void 0 : data.width) || ((_imageRef$
|
|
354
|
+
width: (data === null || data === void 0 ? void 0 : data.width) || ((_imageRef$current3 = imageRef.current) === null || _imageRef$current3 === void 0 ? void 0 : _imageRef$current3.clientWidth)
|
|
281
355
|
},
|
|
282
356
|
placeholder: t('Caption'),
|
|
283
357
|
autoComplete: "off",
|
|
@@ -62,8 +62,8 @@ const insertLink = function (editor, title, url) {
|
|
|
62
62
|
let slateNode = arguments.length > 4 ? arguments[4] : undefined;
|
|
63
63
|
if (position === _constants.INSERT_POSITION.CURRENT && isMenuDisabled(editor)) return;
|
|
64
64
|
if (!title || !url) return;
|
|
65
|
+
const linkNode = genLinkNode(url, title);
|
|
65
66
|
if (position === _constants.INSERT_POSITION.AFTER) {
|
|
66
|
-
const linkNode = genLinkNode(url, title);
|
|
67
67
|
let path = _slate.Editor.path(editor, editor.selection);
|
|
68
68
|
if (slateNode && (slateNode === null || slateNode === void 0 ? void 0 : slateNode.type) === _constants.LIST_ITEM) {
|
|
69
69
|
path = _slateReact.ReactEditor.findPath(editor, slateNode);
|
|
@@ -88,26 +88,25 @@ const insertLink = function (editor, title, url) {
|
|
|
88
88
|
if (selection == null) return;
|
|
89
89
|
const isCollapsed = _slate.Range.isCollapsed(selection);
|
|
90
90
|
if (isCollapsed) {
|
|
91
|
-
const linkNode = genLinkNode(url, title);
|
|
92
91
|
_slate.Transforms.insertNodes(editor, linkNode);
|
|
93
|
-
|
|
94
|
-
const selectedText = _slate.Editor.string(editor, selection); // Selected text
|
|
95
|
-
if (selectedText !== title) {
|
|
96
|
-
// If the selected text is different from the typed text, delete the text and insert the link
|
|
97
|
-
editor.deleteFragment();
|
|
98
|
-
const linkNode = genLinkNode(url, title);
|
|
99
|
-
_slate.Transforms.insertNodes(editor, linkNode);
|
|
100
|
-
} else {
|
|
101
|
-
// If the selected text is the same as the entered text, only the link can be wrapped
|
|
102
|
-
const linkNode = genLinkNode(url, title);
|
|
103
|
-
_slate.Transforms.wrapNodes(editor, linkNode, {
|
|
104
|
-
split: true
|
|
105
|
-
});
|
|
106
|
-
_slate.Transforms.collapse(editor, {
|
|
107
|
-
edge: 'end'
|
|
108
|
-
});
|
|
109
|
-
}
|
|
92
|
+
return;
|
|
110
93
|
}
|
|
94
|
+
const selectedText = _slate.Editor.string(editor, selection); // Selected text
|
|
95
|
+
|
|
96
|
+
// If the selected text is different from the typed text, delete the text and insert the link
|
|
97
|
+
if (selectedText !== title) {
|
|
98
|
+
editor.deleteFragment();
|
|
99
|
+
_slate.Transforms.insertNodes(editor, linkNode);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If the selected text is the same as the entered text, only the link can be wrapped
|
|
104
|
+
_slate.Transforms.wrapNodes(editor, linkNode, {
|
|
105
|
+
split: true
|
|
106
|
+
});
|
|
107
|
+
_slate.Transforms.collapse(editor, {
|
|
108
|
+
edge: 'end'
|
|
109
|
+
});
|
|
111
110
|
};
|
|
112
111
|
exports.insertLink = insertLink;
|
|
113
112
|
const updateLink = (editor, newText, newUrl) => {
|
|
@@ -16,7 +16,8 @@ const withParagraph = editor => {
|
|
|
16
16
|
insertText,
|
|
17
17
|
deleteBackward,
|
|
18
18
|
onHotKeyDown,
|
|
19
|
-
insertFragment
|
|
19
|
+
insertFragment,
|
|
20
|
+
insertBreak
|
|
20
21
|
} = editor;
|
|
21
22
|
const newEditor = editor;
|
|
22
23
|
newEditor.handleTab = event => {
|
|
@@ -135,6 +136,21 @@ const withParagraph = editor => {
|
|
|
135
136
|
}
|
|
136
137
|
return onHotKeyDown && onHotKeyDown(event);
|
|
137
138
|
};
|
|
139
|
+
newEditor.insertBreak = () => {
|
|
140
|
+
const selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants.PARAGRAPH);
|
|
141
|
+
if (selectedNode != null && (0, _core.isCursorAtBlockStart)(newEditor)) {
|
|
142
|
+
const paragraph = (0, _core.generateDefaultParagraph)();
|
|
143
|
+
const targetPath = (0, _core.findPath)(editor, selectedNode);
|
|
144
|
+
const parentNode = (0, _core.getParentNode)(newEditor.children, selectedNode.id);
|
|
145
|
+
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== _constants.LIST_ITEM) {
|
|
146
|
+
_slate.Transforms.insertNodes(editor, paragraph, {
|
|
147
|
+
at: targetPath
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
insertBreak();
|
|
153
|
+
};
|
|
138
154
|
newEditor.insertFragment = data => {
|
|
139
155
|
const paragraphBlock = (0, _core.getSelectedNodeByType)(editor, _constants.PARAGRAPH);
|
|
140
156
|
const onlyOneListItem = data.length === 1 && (0, _helpers.isSingleListItem)(data[0]);
|
package/dist/context.js
CHANGED
|
@@ -36,6 +36,7 @@ class Context {
|
|
|
36
36
|
(0, _defineProperty2.default)(this, "uploadLocalImage", imageFiles => {
|
|
37
37
|
const docUuid = this.getSetting('docUuid');
|
|
38
38
|
return this.api.uploadSdocImage(docUuid, imageFiles).then(res => {
|
|
39
|
+
console.log('res', res);
|
|
39
40
|
const {
|
|
40
41
|
relative_path
|
|
41
42
|
} = res.data;
|