@seafile/sdoc-editor 0.1.27 → 0.1.28-beta1

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.
Files changed (29) hide show
  1. package/dist/assets/css/diff-viewer.css +13 -0
  2. package/dist/basic-sdk/assets/css/layout.css +0 -5
  3. package/dist/basic-sdk/assets/css/sdoc-editor-plugins.css +61 -0
  4. package/dist/basic-sdk/extension/constants/element-type.js +29 -0
  5. package/dist/basic-sdk/extension/constants/index.js +15 -31
  6. package/dist/basic-sdk/extension/plugins/header/menu/index.js +1 -0
  7. package/dist/basic-sdk/extension/plugins/image/dialogs/image-previewer.js +95 -0
  8. package/dist/basic-sdk/extension/plugins/image/dialogs/insert-web-image-dialog.js +69 -0
  9. package/dist/basic-sdk/extension/plugins/image/helpers.js +54 -0
  10. package/dist/basic-sdk/extension/plugins/image/index.js +14 -0
  11. package/dist/basic-sdk/extension/plugins/image/menu/index.js +150 -0
  12. package/dist/basic-sdk/extension/plugins/image/menu/style.css +43 -0
  13. package/dist/basic-sdk/extension/plugins/image/model.js +14 -0
  14. package/dist/basic-sdk/extension/plugins/image/plugin.js +37 -0
  15. package/dist/basic-sdk/extension/plugins/image/render-elem.js +146 -0
  16. package/dist/basic-sdk/extension/plugins/index.js +3 -2
  17. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +2 -2
  18. package/dist/basic-sdk/extension/render/render-element.js +8 -2
  19. package/dist/basic-sdk/extension/toolbar/index.js +5 -3
  20. package/dist/basic-sdk/utils/diff.js +210 -0
  21. package/dist/basic-sdk/utils/object-utils.js +54 -0
  22. package/dist/context.js +29 -1
  23. package/dist/pages/diff-viewer/diff-viewer.js +89 -0
  24. package/dist/pages/diff-viewer/history-version-viewer.js +10 -0
  25. package/dist/pages/diff-viewer/index.js +32 -0
  26. package/dist/utils/index.js +4 -0
  27. package/package.json +1 -1
  28. package/dist/config.js +0 -16
  29. /package/dist/basic-sdk/{assets/css/sdoc-editor-toolbar.css → extension/plugins/header/menu/style.css} +0 -0
@@ -0,0 +1,13 @@
1
+ .sdoc-diff-added {
2
+ background-color: #e6ffed;
3
+ padding: 0 5px;
4
+ margin: 0 -5px;
5
+ overflow: hidden;
6
+ }
7
+
8
+ .sdoc-diff-removed {
9
+ background-color: #ffeef0;
10
+ padding: 0 5px;
11
+ margin: 0 -5px;
12
+ overflow: hidden;
13
+ }
@@ -1,8 +1,3 @@
1
- .dlThau {
2
- margin: 0;
3
- padding-inline-start: 24px;
4
- }
5
-
6
1
  .sdoc-editor-container {
7
2
  flex: 1;
8
3
  display: flex;
@@ -8,3 +8,64 @@
8
8
  margin: 0;
9
9
  padding-inline-start: 24px;
10
10
  }
11
+
12
+ /* image */
13
+ .sdoc-editor-container .article .sdoc-image {
14
+ position: relative;
15
+ display: inline-block;
16
+ margin: 0 3px;
17
+ }
18
+
19
+ .sdoc-editor-container .article .image-selected {
20
+ box-shadow: 0 0 0 2px #007bff;
21
+ }
22
+
23
+ .sdoc-editor-container .article .image-resizer {
24
+ width: 10px;
25
+ height: 10px;
26
+ position: absolute;
27
+ right: -5px;
28
+ bottom: -5px;
29
+ background-color: #007bff;
30
+ border: 1px solid #fff;
31
+ cursor: se-resize;
32
+ }
33
+
34
+ .sdoc-editor-container .article .image-full-screen {
35
+ position: absolute;
36
+ height: 26px;
37
+ display: inline-block;
38
+ width: 26px;
39
+ top: 0;
40
+ right: -32px;
41
+ text-align: center;
42
+ line-height: 20px;
43
+ padding: 2px;
44
+ box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.2);
45
+ border-radius: 3px;
46
+ border: 1px solid rgba(0, 40, 100, 0.12);
47
+ background-color: #fff;
48
+ user-select: none!important;
49
+ z-index: 1000;
50
+ }
51
+
52
+ .sdoc-editor-container .article .image-full-screen:hover {
53
+ display: block;
54
+ background-color: #efefef;
55
+ }
56
+
57
+ .sdoc-editor-container .article .image-size {
58
+ display: inline-block;
59
+ padding: 5px;
60
+ height: 22px;
61
+ position: absolute;
62
+ bottom: -25px;
63
+ left: 100%;
64
+ transform: translateX(5px);
65
+ border-radius: 3px;
66
+ line-height: 12px;
67
+ color: #fff;
68
+ background-color: #4c4c4c;
69
+ font-size: 12px;
70
+ }
71
+
@@ -0,0 +1,29 @@
1
+ export var BLOCKQUOTE = 'blockquote';
2
+ export var BOLD = 'bold';
3
+ export var ITALIC = 'italic';
4
+ export var HEADER = 'header';
5
+ export var HEADER1 = 'header1';
6
+ export var HEADER2 = 'header2';
7
+ export var HEADER3 = 'header3';
8
+ export var HEADER4 = 'header4';
9
+ export var HEADER5 = 'header5';
10
+ export var HEADER6 = 'header6';
11
+ export var ORDERED_LIST = 'ordered_list';
12
+ export var UNORDERED_LIST = 'unordered_list'; // unordered_list can not work
13
+ export var LIST_ITEM = 'list-item';
14
+ export var LIST_LIC = 'list-lic'; // placeholder
15
+ export var CHECK_LIST = 'check-list';
16
+ export var CHECK_LIST_ITEM = 'check-list-item';
17
+ export var PARAGRAPH = 'paragraph';
18
+ export var LINK = 'link';
19
+ export var HTML = 'html';
20
+ export var CODE_BLOCK = 'code-block';
21
+ export var CODE_LINE = 'code-line';
22
+ export var IMAGE = 'image';
23
+ export var TABLE = 'table';
24
+ export var TABLE_CELL = 'table-cell';
25
+ export var TABLE_ROW = 'table-row';
26
+ export var FORMULA = 'formula';
27
+ export var COLUMN = 'column';
28
+ export var TEXT_STYLE = 'text-style';
29
+ export var BOLD_ITALIC = 'bold-italic';
@@ -1,35 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
3
3
  // extension plugin
4
- export var BLOCKQUOTE = 'blockquote';
5
- export var BOLD = 'bold';
6
- export var ITALIC = 'italic';
7
- export var HEADER = 'header';
8
- export var HEADER1 = 'header1';
9
- export var HEADER2 = 'header2';
10
- export var HEADER3 = 'header3';
11
- export var HEADER4 = 'header4';
12
- export var HEADER5 = 'header5';
13
- export var HEADER6 = 'header6';
14
- export var ORDERED_LIST = 'ordered_list';
15
- export var UNORDERED_LIST = 'unordered_list'; // unordered_list can not work
16
- export var LIST_ITEM = 'list-item';
17
- export var LIST_LIC = 'list-lic'; // placeholder
18
- export var CHECK_LIST = 'check-list';
19
- export var CHECK_LIST_ITEM = 'check-list-item';
20
- export var PARAGRAPH = 'paragraph';
21
- export var LINK = 'link';
22
- export var HTML = 'html';
23
- export var CODE_BLOCK = 'code-block';
24
- export var CODE_LINE = 'code-line';
25
- export var IMAGE = 'image';
26
- export var TABLE = 'table';
27
- export var TABLE_CELL = 'table-cell';
28
- export var TABLE_ROW = 'table-row';
29
- export var FORMULA = 'formula';
30
- export var COLUMN = 'column';
31
- export var TEXTSTYLE = 'text-style';
32
- export var BOLD_ITALIC = 'bold-italic';
4
+ import * as ELEMENT_TYPE from './element-type';
5
+ import { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC } from './element-type';
33
6
 
34
7
  // history
35
8
  export var UNDO = 'undo';
@@ -60,7 +33,11 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
60
33
  id: "sdoc_".concat(LINK),
61
34
  iconClass: 'iconfont icon-link',
62
35
  text: 'insert_link'
63
- }), _defineProperty(_MENUS_CONFIG_MAP, TEXTSTYLE, [{
36
+ }), _defineProperty(_MENUS_CONFIG_MAP, IMAGE, {
37
+ id: "sdoc_".concat(IMAGE),
38
+ iconClass: 'iconfont icon-image',
39
+ text: 'insert_image'
40
+ }), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE, [{
64
41
  id: ITALIC,
65
42
  iconClass: 'iconfont icon-italic',
66
43
  text: 'italic',
@@ -81,4 +58,11 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
81
58
  text: 'redo',
82
59
  type: 'redo'
83
60
  }), _MENUS_CONFIG_MAP);
84
- export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'paragraph'), _HEADER_TITLE_MAP);
61
+ export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'paragraph'), _HEADER_TITLE_MAP);
62
+ export var DIFF_TYPE = {
63
+ ADD: 'add',
64
+ DELETE: 'delete',
65
+ MODIFY: 'modify',
66
+ COMMON: 'common'
67
+ };
68
+ export { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC, ELEMENT_TYPE };
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  import { withTranslation } from 'react-i18next';
7
7
  import { getHeaderType, isMenuDisabled, setHeaderType } from '../helpers';
8
8
  import { HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, HEADER_TITLE_MAP, PARAGRAPH } from '../../../constants';
9
+ import './style.css';
9
10
  var HeaderMenu = /*#__PURE__*/function (_React$Component) {
10
11
  _inherits(HeaderMenu, _React$Component);
11
12
  var _super = _createSuper(HeaderMenu);
@@ -0,0 +1,95 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
+ import React from 'react';
7
+ import Lightbox from '@seafile/react-image-lightbox';
8
+ import '@seafile/react-image-lightbox/style.css';
9
+ var ImagePreviewer = /*#__PURE__*/function (_React$Component) {
10
+ _inherits(ImagePreviewer, _React$Component);
11
+ var _super = _createSuper(ImagePreviewer);
12
+ function ImagePreviewer(props) {
13
+ var _this;
14
+ _classCallCheck(this, ImagePreviewer);
15
+ _this = _super.call(this, props);
16
+ _this.getImageNodes = function (nodes) {
17
+ var nodeIndex = 0;
18
+ var list = [];
19
+ while (nodes && nodeIndex <= nodes.length - 1) {
20
+ var currentNode = nodes[nodeIndex];
21
+ if (currentNode.type === 'image') {
22
+ currentNode.data.src && list.push(currentNode.data.src);
23
+ } else {
24
+ list.push.apply(list, _toConsumableArray(_this.getImageNodes(currentNode.children)));
25
+ }
26
+ nodeIndex++;
27
+ }
28
+ return list;
29
+ };
30
+ _this.moveToPrevImage = function () {
31
+ _this.setState(function (prevState) {
32
+ return {
33
+ imageIndex: (prevState.imageIndex + _this.images.length - 1) % _this.images.length
34
+ };
35
+ });
36
+ };
37
+ _this.moveToNextImage = function () {
38
+ _this.setState(function (prevState) {
39
+ return {
40
+ imageIndex: (prevState.imageIndex + 1) % _this.images.length
41
+ };
42
+ });
43
+ };
44
+ var editor = props.editor,
45
+ imageUrl = props.imageUrl;
46
+ _this.images = _this.getImageNodes(editor.children);
47
+ _this.state = {
48
+ imageIndex: _this.images.findIndex(function (item) {
49
+ return item === imageUrl;
50
+ })
51
+ };
52
+ return _this;
53
+ }
54
+ _createClass(ImagePreviewer, [{
55
+ key: "render",
56
+ value: function render() {
57
+ var imageIndex = this.state.imageIndex;
58
+ var imageItemsLength = this.images.length;
59
+ var mainSrc = this.images[imageIndex] || '';
60
+ var imageTitle = '';
61
+ try {
62
+ imageTitle = mainSrc ? decodeURI(mainSrc.slice(mainSrc.lastIndexOf('/') + 1)) : '';
63
+ } catch (error) {
64
+ // eslint-disable-next-line no-console
65
+ console.log(error);
66
+ }
67
+ var imageTitleEl = /*#__PURE__*/React.createElement("span", {
68
+ className: "d-flex"
69
+ }, /*#__PURE__*/React.createElement("span", {
70
+ className: "text-truncate"
71
+ }, imageTitle), /*#__PURE__*/React.createElement("span", {
72
+ className: "flex-shrink-0"
73
+ }, "(", imageIndex + 1, "/", this.images.length, ")"));
74
+ return /*#__PURE__*/React.createElement(Lightbox, {
75
+ wrapperClassName: "sf-editor-image-previewer",
76
+ imageTitle: imageTitleEl,
77
+ mainSrc: mainSrc,
78
+ toolbarButtons: [],
79
+ nextSrc: this.images[(imageIndex + 1) % imageItemsLength],
80
+ prevSrc: this.images[(imageIndex + imageItemsLength - 1) % imageItemsLength],
81
+ onCloseRequest: this.props.toggleImagePreviewer,
82
+ onMovePrevRequest: this.moveToPrevImage,
83
+ onMoveNextRequest: this.moveToNextImage,
84
+ imagePadding: 70,
85
+ reactModalStyle: {
86
+ overlay: {
87
+ zIndex: 1071
88
+ }
89
+ }
90
+ });
91
+ }
92
+ }]);
93
+ return ImagePreviewer;
94
+ }(React.Component);
95
+ export default ImagePreviewer;
@@ -0,0 +1,69 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React, { Component } from 'react';
6
+ import { withTranslation } from 'react-i18next';
7
+ import { Modal, ModalHeader, ModalBody, ModalFooter, FormGroup, Label, Input, Button } from 'reactstrap';
8
+ var InsertWebImageDialog = /*#__PURE__*/function (_Component) {
9
+ _inherits(InsertWebImageDialog, _Component);
10
+ var _super = _createSuper(InsertWebImageDialog);
11
+ function InsertWebImageDialog(props) {
12
+ var _this;
13
+ _classCallCheck(this, InsertWebImageDialog);
14
+ _this = _super.call(this, props);
15
+ _this.onValueChanged = function (event) {
16
+ var value = event.target.value;
17
+ _this.setState({
18
+ url: value
19
+ });
20
+ };
21
+ _this.onKeyDown = function (event) {
22
+ if (event.keyCode === 13) {
23
+ _this.handleSubmit();
24
+ return;
25
+ }
26
+ };
27
+ _this.handleSubmit = function () {
28
+ var url = _this.state.url;
29
+ if (!url) return;
30
+ _this.props.onInsertImage(url);
31
+ };
32
+ _this.onDialogToggle = function () {
33
+ _this.props.onDialogToggle();
34
+ };
35
+ _this.state = {
36
+ url: ''
37
+ };
38
+ return _this;
39
+ }
40
+ _createClass(InsertWebImageDialog, [{
41
+ key: "render",
42
+ value: function render() {
43
+ var t = this.props.t;
44
+ var url = this.state.url;
45
+ return /*#__PURE__*/React.createElement(Modal, {
46
+ isOpen: true,
47
+ toggle: this.onDialogToggle,
48
+ autoFocus: false
49
+ }, /*#__PURE__*/React.createElement(ModalHeader, null, t('insert_image')), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(FormGroup, null, /*#__PURE__*/React.createElement(Label, {
50
+ for: "insert_image"
51
+ }, t('image_address')), /*#__PURE__*/React.createElement(Input, {
52
+ id: "insert_image",
53
+ autoFocus: true,
54
+ value: url,
55
+ onChange: this.onValueChanged,
56
+ onKeyDown: this.onKeyDown
57
+ }))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
58
+ color: "secondary",
59
+ onClick: this.onDialogToggle
60
+ }, t('cancel')), /*#__PURE__*/React.createElement(Button, {
61
+ color: "primary",
62
+ disabled: url.length === 0,
63
+ onClick: this.handleSubmit
64
+ }, t('submit'))));
65
+ }
66
+ }]);
67
+ return InsertWebImageDialog;
68
+ }(Component);
69
+ export default withTranslation('sdoc-editor')(InsertWebImageDialog);
@@ -0,0 +1,54 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import { Editor, Range, Transforms } from '@seafile/slate';
4
+ import { BLOCKQUOTE, CODE_BLOCK, IMAGE, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
5
+ import { generateEmptyElement, getNodeType } from '../../core';
6
+ export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor) {
7
+ var selection = editor.selection;
8
+ if (selection === null) return true;
9
+ if (!Range.isCollapsed(selection)) return true;
10
+ var _Editor$nodes = Editor.nodes(editor, {
11
+ match: function match(n) {
12
+ var type = getNodeType(n);
13
+ if (type === CODE_BLOCK) return true;
14
+ if (type === ORDERED_LIST) return true;
15
+ if (type === UNORDERED_LIST) return true;
16
+ if (type.startsWith('header')) return true;
17
+ if (type === BLOCKQUOTE) return true;
18
+ if (Editor.isVoid(editor, n)) return true;
19
+ return false;
20
+ },
21
+ universal: true
22
+ }),
23
+ _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
24
+ match = _Editor$nodes2[0];
25
+ if (match) return true;
26
+ return false;
27
+ };
28
+ export var generateImageNode = function generateImageNode(src) {
29
+ var element = generateEmptyElement(IMAGE);
30
+ return _objectSpread(_objectSpread({}, element), {}, {
31
+ data: {
32
+ src: src
33
+ }
34
+ });
35
+ };
36
+ export var insertImage = function insertImage(editor, src, selection) {
37
+ if (!src) return;
38
+ if (isInsertImageMenuDisabled(editor)) return;
39
+ var imageNode = generateImageNode(src);
40
+ Transforms.insertNodes(editor, imageNode, {
41
+ at: selection
42
+ });
43
+ };
44
+ export var updateImage = function updateImage(editor, data) {
45
+ Transforms.setNodes(editor, {
46
+ data: data
47
+ }, {
48
+ match: function match(n) {
49
+ return getNodeType(n) === IMAGE;
50
+ },
51
+ at: editor.selection,
52
+ voids: true
53
+ });
54
+ };
@@ -0,0 +1,14 @@
1
+ import { IMAGE } from '../../constants';
2
+ import ImageMenu from './menu';
3
+ import Image from './model';
4
+ import withImage from './plugin';
5
+ import renderImage from './render-elem';
6
+ var ImagePlugin = {
7
+ type: IMAGE,
8
+ nodeType: 'element',
9
+ model: Image,
10
+ editorMenus: [ImageMenu],
11
+ editorPlugin: withImage,
12
+ renderElements: [renderImage]
13
+ };
14
+ export default ImagePlugin;
@@ -0,0 +1,150 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
+ import React, { Fragment } from 'react';
7
+ import { withTranslation } from 'react-i18next';
8
+ import { insertImage, isInsertImageMenuDisabled } from '../helpers';
9
+ import context from '../../../../../context';
10
+ import { IMAGE, MENUS_CONFIG_MAP } from '../../../constants';
11
+ import { MenuItem } from '../../../menu';
12
+ import InsertWebImageDialog from '../dialogs/insert-web-image-dialog';
13
+ import './style.css';
14
+ var ImageMenu = /*#__PURE__*/function (_React$Component) {
15
+ _inherits(ImageMenu, _React$Component);
16
+ var _super = _createSuper(ImageMenu);
17
+ function ImageMenu(props) {
18
+ var _this;
19
+ _classCallCheck(this, ImageMenu);
20
+ _this = _super.call(this, props);
21
+ _this.registerEventHandler = function () {
22
+ document.addEventListener('mousedown', _this.onHideImageMenu);
23
+ };
24
+ _this.unregisterEventHandler = function () {
25
+ document.removeEventListener('mousedown', _this.onHideImageMenu);
26
+ };
27
+ _this.onHideImageMenu = function () {
28
+ _this.setState({
29
+ isShowImagePopover: false
30
+ }, function () {
31
+ _this.unregisterEventHandler();
32
+ });
33
+ };
34
+ _this.isActive = function () {
35
+ return false;
36
+ };
37
+ _this.isDisabled = function () {
38
+ var editor = _this.props.editor;
39
+ return isInsertImageMenuDisabled(editor);
40
+ };
41
+ _this.onToggleClick = function (event) {
42
+ event.stopPropagation();
43
+ event.nativeEvent.stopImmediatePropagation();
44
+ var isShowImagePopover = !_this.state.isShowImagePopover;
45
+ if (isShowImagePopover) {
46
+ _this.setState({
47
+ isShowImagePopover: isShowImagePopover
48
+ }, function () {
49
+ _this.registerEventHandler();
50
+ });
51
+ } else {
52
+ _this.setState({
53
+ isShowImagePopover: isShowImagePopover
54
+ }, function () {
55
+ _this.unregisterEventHandler();
56
+ });
57
+ }
58
+ };
59
+ _this.onInsertWebImageToggle = function () {
60
+ var editor = _this.props.editor;
61
+ _this.selection = editor.selection;
62
+ _this.setState({
63
+ isShowInsertImageDialog: true,
64
+ isShowImagePopover: false
65
+ }, function () {
66
+ _this.unregisterEventHandler();
67
+ });
68
+ };
69
+ _this.onInsertLocalImageToggle = function () {
70
+ var editor = _this.props.editor;
71
+ _this.selection = editor.selection;
72
+ _this.input.click();
73
+ _this.setState({
74
+ isShowImagePopover: false
75
+ }, function () {
76
+ _this.unregisterEventHandler();
77
+ });
78
+ };
79
+ _this.onInsertImage = function (url) {
80
+ var editor = _this.props.editor;
81
+ insertImage(editor, url, _this.selection);
82
+ _this.onCloseInsertDialog();
83
+ };
84
+ _this.onCloseInsertDialog = function () {
85
+ _this.setState({
86
+ isShowInsertImageDialog: false
87
+ });
88
+ };
89
+ _this.onFileChanged = function (event) {
90
+ var editor = _this.props.editor;
91
+ var file = event.target.files[0];
92
+ context.uploadLocalImage(file).then(function (fileUrl) {
93
+ console.log(fileUrl);
94
+ insertImage(editor, fileUrl, _this.selection);
95
+ console.log(editor.children);
96
+ });
97
+ };
98
+ _this.setInputRef = function (ref) {
99
+ _this.input = ref;
100
+ };
101
+ _this.state = {
102
+ isShowImagePopover: false,
103
+ isShowInsertImageDialog: false
104
+ };
105
+ return _this;
106
+ }
107
+ _createClass(ImageMenu, [{
108
+ key: "render",
109
+ value: function render() {
110
+ var _this$props = this.props,
111
+ isRichEditor = _this$props.isRichEditor,
112
+ className = _this$props.className,
113
+ t = _this$props.t;
114
+ var _this$state = this.state,
115
+ isShowImagePopover = _this$state.isShowImagePopover,
116
+ isShowInsertImageDialog = _this$state.isShowInsertImageDialog;
117
+ var menuConfig = MENUS_CONFIG_MAP[IMAGE];
118
+ var props = _objectSpread(_objectSpread({
119
+ isRichEditor: isRichEditor,
120
+ className: className
121
+ }, menuConfig), {}, {
122
+ disabled: this.isDisabled(),
123
+ isActive: this.isActive(),
124
+ onMouseDown: this.onToggleClick
125
+ });
126
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
127
+ className: "image-menu"
128
+ }, /*#__PURE__*/React.createElement("input", {
129
+ ref: this.setInputRef,
130
+ type: "file",
131
+ accept: "image/*",
132
+ className: "locale-image-uploader",
133
+ onChange: this.onFileChanged
134
+ }), /*#__PURE__*/React.createElement(MenuItem, props), isShowImagePopover && /*#__PURE__*/React.createElement("div", {
135
+ className: "image-popover"
136
+ }, /*#__PURE__*/React.createElement("div", {
137
+ className: "image-menu-item",
138
+ onMouseDown: this.onInsertWebImageToggle
139
+ }, t('insert_network_image')), /*#__PURE__*/React.createElement("div", {
140
+ className: "image-menu-item",
141
+ onMouseDown: this.onInsertLocalImageToggle
142
+ }, t('upload_local_image')))), isShowInsertImageDialog && /*#__PURE__*/React.createElement(InsertWebImageDialog, {
143
+ onInsertImage: this.onInsertImage,
144
+ onDialogToggle: this.onCloseInsertDialog
145
+ }));
146
+ }
147
+ }]);
148
+ return ImageMenu;
149
+ }(React.Component);
150
+ export default withTranslation('sdoc-editor')(ImageMenu);
@@ -0,0 +1,43 @@
1
+ .image-menu {
2
+ position: relative;
3
+ }
4
+
5
+ .image-menu .image-popover {
6
+ position: absolute;
7
+ top: 36px;
8
+ left: 0px;
9
+ padding: 8px 0;
10
+ background-color: #fff;
11
+ border: 1px solid #e5e6e8;
12
+ border-radius: 2px;
13
+ box-shadow: 0 0 10px #ccc;
14
+ display: flex;
15
+ flex-direction: column;
16
+ align-items: flex-start;
17
+ z-index: 10;
18
+ white-space:nowrap;
19
+ }
20
+
21
+ .image-menu .image-popover .image-menu-item {
22
+ cursor: pointer;
23
+ height: 30px;
24
+ padding: 4px 24px;
25
+ user-select: none;
26
+ display: flex;
27
+ align-items: center;
28
+ font-size: 0.9375rem;
29
+ }
30
+
31
+ .image-menu .image-popover .image-menu-item:hover {
32
+ background-color: rgb(245, 245, 245);
33
+ }
34
+
35
+ .image-menu .locale-image-uploader {
36
+ position: absolute;
37
+ top: 0;
38
+ left: 0;
39
+ width: 0;
40
+ height: 0;
41
+ opacity: 0;
42
+ font-size: 0;
43
+ }
@@ -0,0 +1,14 @@
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import { IMAGE } from '../../constants';
4
+ var Image = /*#__PURE__*/_createClass(function Image(options) {
5
+ _classCallCheck(this, Image);
6
+ this.type = options.type || IMAGE;
7
+ this.data = options.data || {
8
+ src: ''
9
+ };
10
+ this.children = options.children || [{
11
+ text: ''
12
+ }];
13
+ });
14
+ export default Image;
@@ -0,0 +1,37 @@
1
+ import context from '../../../../context';
2
+ import { insertImage } from './helpers';
3
+ var withImage = function withImage(editor) {
4
+ var isInline = editor.isInline,
5
+ isVoid = editor.isVoid,
6
+ insertData = editor.insertData;
7
+ var newEditor = editor;
8
+
9
+ // rewrite isInline
10
+ newEditor.isInline = function (elem) {
11
+ var type = elem.type;
12
+ if (type === 'image') {
13
+ return true;
14
+ }
15
+ return isInline(elem);
16
+ };
17
+
18
+ // rewrite isVoid
19
+ newEditor.isVoid = function (elem) {
20
+ var type = elem.type;
21
+ if (type === 'image') {
22
+ return true;
23
+ }
24
+ return isVoid(elem);
25
+ };
26
+ newEditor.insertData = function (data) {
27
+ if (data.types && data.types.includes('Files') && data.files[0].type.includes('image')) {
28
+ context.uploadLocalImage(data.files[0]).then(function (fileUrl) {
29
+ insertImage(newEditor, fileUrl, editor.selection);
30
+ });
31
+ return;
32
+ }
33
+ insertData(data);
34
+ };
35
+ return newEditor;
36
+ };
37
+ export default withImage;