@seafile/sdoc-editor 0.1.0 → 0.1.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.
Files changed (144) hide show
  1. package/dist/{new-editors/editor.js → editor.js} +23 -17
  2. package/dist/index.js +2 -36
  3. package/dist/slate-extension/plugins/index.js +3 -2
  4. package/dist/slate-extension/plugins/socket/index.js +6 -0
  5. package/dist/slate-extension/plugins/socket/plugin.js +17 -0
  6. package/dist/slate-extension/socket/socket-client.js +84 -0
  7. package/dist/slate-extension/socket/socket-manager.js +61 -0
  8. package/dist/slate-extension/toolbar/index.js +1 -1
  9. package/package.json +3 -23
  10. package/dist/assets/css/comment-dialog.css +0 -50
  11. package/dist/assets/css/diff-viewer.css +0 -105
  12. package/dist/assets/css/formula.css +0 -19
  13. package/dist/assets/css/history-viewer.css +0 -104
  14. package/dist/assets/css/image.css +0 -134
  15. package/dist/assets/css/issue-card.css +0 -43
  16. package/dist/assets/css/keyboard-shortcuts.css +0 -58
  17. package/dist/assets/css/link.css +0 -7
  18. package/dist/assets/css/markdown-editor.css +0 -12
  19. package/dist/assets/css/markdown-viewer.css +0 -69
  20. package/dist/assets/css/navbar-imgbutton.css +0 -83
  21. package/dist/assets/css/outline.css +0 -29
  22. package/dist/assets/css/table.css +0 -57
  23. package/dist/assets/css/textlink-hovermenu.css +0 -47
  24. package/dist/assets/css/topbar.css +0 -350
  25. package/dist/assets/css/tree-view.css +0 -67
  26. package/dist/assets/css/user-help.css +0 -84
  27. package/dist/assets/editor/plain-editor.css +0 -30
  28. package/dist/assets/editor/seatable-editor.css +0 -77
  29. package/dist/assets/editor/simple-editor.css +0 -77
  30. package/dist/components/click-outside.js +0 -46
  31. package/dist/components/context-menu.js +0 -97
  32. package/dist/components/dialogs/add-formula-dialog.js +0 -116
  33. package/dist/components/dialogs/add-image-dialog.js +0 -69
  34. package/dist/components/dialogs/add-link-dialog.js +0 -133
  35. package/dist/components/dialogs/comment-dialog.js +0 -97
  36. package/dist/components/dialogs/shortcut-dialog.js +0 -131
  37. package/dist/components/error-boundary.js +0 -28
  38. package/dist/components/load-script/index.js +0 -69
  39. package/dist/components/loading.js +0 -25
  40. package/dist/components/markdown-lint.js +0 -72
  41. package/dist/components/menu/index.js +0 -4
  42. package/dist/components/menu/item.js +0 -49
  43. package/dist/components/menu/menu.js +0 -38
  44. package/dist/components/menu/style.css +0 -42
  45. package/dist/components/modal-portal.js +0 -38
  46. package/dist/components/outline/index.js +0 -92
  47. package/dist/components/outline/outline-item.js +0 -58
  48. package/dist/components/select/_option.js +0 -44
  49. package/dist/components/select/field-setting.js +0 -106
  50. package/dist/components/select/index.js +0 -149
  51. package/dist/components/select/style.css +0 -144
  52. package/dist/components/svg-icons/check-mark-icon.js +0 -14
  53. package/dist/components/svg-icons/column-icon.js +0 -17
  54. package/dist/components/svg-icons/text-icon.js +0 -34
  55. package/dist/components/text-link-hover-menu/index.js +0 -123
  56. package/dist/components/toast/alert.js +0 -138
  57. package/dist/components/toast/index.js +0 -3
  58. package/dist/components/toast/toast.js +0 -159
  59. package/dist/components/toast/toastManager.js +0 -139
  60. package/dist/components/toast/toaster.js +0 -65
  61. package/dist/components/toolbar/header-list.js +0 -114
  62. package/dist/components/toolbar/help-group.js +0 -33
  63. package/dist/components/toolbar/index.js +0 -4
  64. package/dist/components/toolbar/insert-image.js +0 -106
  65. package/dist/components/toolbar/insert-table.js +0 -136
  66. package/dist/components/toolbar/table-group.js +0 -74
  67. package/dist/components/toolbar/toolbar.js +0 -317
  68. package/dist/components/toolbar/widgets/button-group.js +0 -24
  69. package/dist/components/toolbar/widgets/button-item.js +0 -129
  70. package/dist/components/toolbar/widgets/drop-list.js +0 -88
  71. package/dist/components/user-help/index.js +0 -179
  72. package/dist/config-0.js +0 -15
  73. package/dist/config.js +0 -16
  74. package/dist/constants/cell-types.js +0 -29
  75. package/dist/constants/column.js +0 -4
  76. package/dist/containers/code-highlight-package.js +0 -14
  77. package/dist/containers/controller/block-element-controller.js +0 -375
  78. package/dist/containers/controller/index.js +0 -5
  79. package/dist/containers/controller/inline-element-controller.js +0 -134
  80. package/dist/containers/controller/normalize-controller.js +0 -95
  81. package/dist/containers/controller/shortcut-controller.js +0 -385
  82. package/dist/containers/controller/void-element-controller.js +0 -9
  83. package/dist/containers/custom/custom.js +0 -18
  84. package/dist/containers/custom/get-event-transfer.js +0 -33
  85. package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
  86. package/dist/containers/custom/insertNodes.js +0 -120
  87. package/dist/containers/custom/is-empty-paragraph.js +0 -9
  88. package/dist/containers/custom/set-event-transfer.js +0 -30
  89. package/dist/containers/custom/split-nodes-at-point.js +0 -136
  90. package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
  91. package/dist/containers/editor-context.js +0 -85
  92. package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
  93. package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
  94. package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
  95. package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
  96. package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
  97. package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
  98. package/dist/containers/editor-utils/clear-format-utils.js +0 -84
  99. package/dist/containers/editor-utils/common-editor-utils.js +0 -492
  100. package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
  101. package/dist/containers/editor-utils/mark-utils.js +0 -20
  102. package/dist/containers/editor-utils/range-utils.js +0 -7
  103. package/dist/containers/editor-utils/selection-utils.js +0 -30
  104. package/dist/containers/editor-utils/text-utils.js +0 -117
  105. package/dist/containers/editor-widgets/check-list-item.js +0 -53
  106. package/dist/containers/editor-widgets/code-block.js +0 -128
  107. package/dist/containers/editor-widgets/column.js +0 -100
  108. package/dist/containers/editor-widgets/formula.js +0 -67
  109. package/dist/containers/editor-widgets/image.js +0 -237
  110. package/dist/containers/editor-widgets/link.js +0 -9
  111. package/dist/containers/editor-widgets/table.js +0 -144
  112. package/dist/containers/element-model/blockquote.js +0 -13
  113. package/dist/containers/element-model/column.js +0 -19
  114. package/dist/containers/element-model/image.js +0 -16
  115. package/dist/containers/element-model/link.js +0 -16
  116. package/dist/containers/element-model/table.js +0 -57
  117. package/dist/containers/element-model/text.js +0 -10
  118. package/dist/containers/render-utils/common-utils.js +0 -80
  119. package/dist/containers/render-utils/editor-utils.js +0 -133
  120. package/dist/containers/render-utils/viewer-utils.js +0 -198
  121. package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
  122. package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
  123. package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
  124. package/dist/editors/index.js +0 -78
  125. package/dist/editors/markdown-editor.js +0 -280
  126. package/dist/editors/plain-markdown-editor.js +0 -285
  127. package/dist/editors/seatable-editor.js +0 -210
  128. package/dist/editors/simple-editor.js +0 -200
  129. package/dist/utils/deserialize-html.js +0 -260
  130. package/dist/utils/diff/compare-strings.js +0 -35
  131. package/dist/utils/diff/diff.js +0 -769
  132. package/dist/utils/diff/index.js +0 -2
  133. package/dist/utils/seafile-markdown2html.js +0 -52
  134. package/dist/utils/slate2markdown/deserialize.js +0 -588
  135. package/dist/utils/slate2markdown/index.js +0 -3
  136. package/dist/utils/slate2markdown/serialize.js +0 -366
  137. package/dist/utils/utils.js +0 -69
  138. package/dist/viewer/diff-viewer.js +0 -85
  139. package/dist/viewer/index.js +0 -4
  140. package/dist/viewer/markdown-viewer.js +0 -121
  141. package/dist/viewer/seatable-viewer.js +0 -63
  142. package/dist/viewer/slate-viewer.js +0 -71
  143. /package/dist/assets/css/{new-editor-toolbar.css → sdoc-editor-toolbar.css} +0 -0
  144. /package/dist/assets/css/{new-editor.css → sdoc-editor.css} +0 -0
@@ -1,210 +0,0 @@
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 from 'react';
6
- import { withTranslation } from 'react-i18next';
7
- import { Node, Editor } from 'slate';
8
- import { Editable, Slate } from '@seafile/slate-react';
9
- import Toolbar, { HelpGroup } from '../components/toolbar';
10
- import ModalPortal from '../components/modal-portal';
11
- import ContextMenu from '../components/context-menu';
12
- import TextLinkHoverMenu from '../components/text-link-hover-menu';
13
- import AddLinkDialog from '../components/dialogs/add-link-dialog';
14
- import KeyboardShortcuts from '../components/dialogs/shortcut-dialog';
15
- import ErrorBoundary from '../components/error-boundary';
16
- import { deserialize, serialize } from '../utils/slate2markdown/index';
17
- import { isRangeCollapsed } from '../containers/editor-utils/range-utils';
18
- import { renderNode, renderLeaf, decorationNode } from '../containers/render-utils/editor-utils';
19
- import EditorContext from '../containers/editor-context';
20
- import '../containers/code-highlight-package';
21
- import '../assets/editor/seatable-editor.css';
22
- import '../assets/css/image.css';
23
- import '../assets/css/link.css';
24
- import '../assets/css/navbar-imgbutton.css';
25
- var SeatableEditor = /*#__PURE__*/function (_React$Component) {
26
- _inherits(SeatableEditor, _React$Component);
27
- var _super = _createSuper(SeatableEditor);
28
- function SeatableEditor(props) {
29
- var _this;
30
- _classCallCheck(this, SeatableEditor);
31
- _this = _super.call(this, props);
32
- _this.onChange = function (value) {
33
- _this.setState({
34
- value: value
35
- });
36
-
37
- // hide context menu when content change
38
- if (_this.state.isShowContextMenu === true) {
39
- _this.setState({
40
- isShowContextMenu: false
41
- });
42
- _this.contextMenuPosition = {};
43
- }
44
- var operations = _this.editor.operations;
45
- var hasChange = operations.some(function (o) {
46
- return o.type !== 'set_selection' && o.type !== 'set_value';
47
- });
48
- if (hasChange) _this.contentChanged = true;
49
- };
50
- _this.onFocusEditor = function () {
51
- var value = _this.state.value;
52
- if (value.length === 1 && value[0].type === 'paragraph' && Node.text(value[0].children[0]).length === 0) {
53
- _this.editorRef.firstChild.focus();
54
- }
55
- };
56
- _this.focusText = function () {
57
- // In dtable long text editor, press the key to open the editor.
58
- // Then the cursor should move to the end of this character.
59
- var _this$props = _this.props,
60
- focusEnd = _this$props.focusEnd,
61
- value = _this$props.value;
62
- if (focusEnd === true && value.length === 1) {
63
- setTimeout(function () {
64
- Editor.select(_this.editor, {
65
- path: [0, 0],
66
- offset: 1
67
- });
68
- }, 1);
69
- }
70
- };
71
- _this.hasContentChange = function () {
72
- return _this.contentChanged;
73
- };
74
- _this.onContextMenu = function (event) {
75
- if (_this.tableUtils.isInTable()) {
76
- event.preventDefault();
77
- _this.contextMenuPosition = {
78
- left: event.clientX,
79
- top: event.clientY
80
- };
81
- _this.setState({
82
- isShowContextMenu: !_this.state.isShowContextMenu
83
- });
84
- }
85
- };
86
- _this.onCut = function (event) {
87
- _this.editorUtils.onCut(event);
88
- };
89
- _this.onCopy = function (event) {
90
- _this.editorUtils.onCopy(event, _this.editor);
91
- };
92
- _this.onKeyDown = function (event) {
93
- _this.editorUtils.onKeyDown(event);
94
- };
95
- _this.toggleShortcutDialog = function () {
96
- _this.setState({
97
- isShowShortcutDialog: !_this.state.isShowShortcutDialog
98
- });
99
- };
100
- _this.onToggleLinkDialog = function () {
101
- _this.setState({
102
- isShowLinkDialog: !_this.state.isShowLinkDialog
103
- });
104
- };
105
- _this.setEditorRef = function (ref) {
106
- _this.editorRef = ref;
107
- };
108
- var _value = props.value ? JSON.parse(props.value) : deserialize('');
109
- _this.state = {
110
- value: _value,
111
- isShowBigImage: false,
112
- isShowContextMenu: false,
113
- isShowShortcutDialog: false,
114
- isShowLinkDialog: false
115
- };
116
- _this.editor = EditorContext.getEditor(props);
117
- _this.editorUtils = EditorContext.getEditorUtils();
118
- _this.tableUtils = EditorContext.getTableUtils();
119
- _this.contextMenuPosition = {};
120
- return _this;
121
- }
122
- _createClass(SeatableEditor, [{
123
- key: "componentDidMount",
124
- value: function componentDidMount() {
125
- this.props.onRef(this);
126
- this.focusText();
127
- }
128
- }, {
129
- key: "componentWillUnmount",
130
- value: function componentWillUnmount() {
131
- EditorContext.resetEditor();
132
- }
133
- }, {
134
- key: "getMarkdown",
135
- value: function getMarkdown() {
136
- this.contentChanged = false;
137
- return serialize(this.state.value);
138
- }
139
- }, {
140
- key: "getValue",
141
- value: function getValue() {
142
- return JSON.stringify(this.state.value);
143
- }
144
- }, {
145
- key: "render",
146
- value: function render() {
147
- var editor = this.editor;
148
- var value = this.state.value;
149
- var toolbarStatus = this.editorUtils.getToolbarStatus();
150
- var _this$props2 = this.props,
151
- readOnly = _this$props2.readOnly,
152
- canInsertColumn = _this$props2.canInsertColumn,
153
- columns = _this$props2.columns,
154
- t = _this$props2.t;
155
- var supportInsertColumn = canInsertColumn && columns.length > 0;
156
- var selectionCollapsed = isRangeCollapsed(editor.selection);
157
- return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement("div", {
158
- className: "seatable-simple-editor"
159
- }, /*#__PURE__*/React.createElement("div", {
160
- className: "seafile-editor-topbar"
161
- }, /*#__PURE__*/React.createElement(Toolbar, {
162
- isSimpleEditor: true,
163
- canInsertColumn: supportInsertColumn
164
- }), /*#__PURE__*/React.createElement(HelpGroup, {
165
- onHelpToggle: this.toggleShortcutDialog
166
- })), /*#__PURE__*/React.createElement(Slate, {
167
- editor: this.editor,
168
- value: value,
169
- onChange: this.onChange
170
- }, /*#__PURE__*/React.createElement("div", {
171
- className: "seafile-editor-module editor-container"
172
- }, /*#__PURE__*/React.createElement("div", {
173
- ref: this.setEditorRef,
174
- onClick: this.onFocusEditor,
175
- className: "editor article"
176
- }, /*#__PURE__*/React.createElement(Editable, {
177
- autoFocus: true,
178
- className: 'editor-component',
179
- renderElement: function renderElement(props) {
180
- return renderNode(props, editor, readOnly);
181
- },
182
- renderLeaf: renderLeaf,
183
- onContextMenu: this.onContextMenu,
184
- onCut: this.onCut,
185
- onCopy: this.onCopy,
186
- onKeyDown: this.onKeyDown,
187
- decorate: decorationNode
188
- })), toolbarStatus.isLinkActive && selectionCollapsed ? /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(TextLinkHoverMenu, {
189
- onToggleLinkDialog: this.onToggleLinkDialog,
190
- editorUtils: this.editorUtils
191
- })) : null, this.state.isShowContextMenu && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(ContextMenu, {
192
- tableUtils: this.tableUtils,
193
- contextMenuPosition: this.contextMenuPosition
194
- })), this.state.isShowShortcutDialog && /*#__PURE__*/React.createElement(KeyboardShortcuts, {
195
- userHelp: t('userHelp', {
196
- returnObjects: true
197
- }),
198
- toggleShortcutDialog: this.toggleShortcutDialog
199
- }), this.state.isShowLinkDialog && /*#__PURE__*/React.createElement(AddLinkDialog, {
200
- toggleLinkDialog: this.onToggleLinkDialog
201
- })))));
202
- }
203
- }]);
204
- return SeatableEditor;
205
- }(React.Component);
206
- SeatableEditor.defaultProps = {
207
- columns: [],
208
- canInsertColumn: false
209
- };
210
- export default withTranslation('seafile-editor')(SeatableEditor);
@@ -1,200 +0,0 @@
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 from 'react';
6
- import { withTranslation } from 'react-i18next';
7
- import { Node, Editor } from 'slate';
8
- import { Editable, Slate } from '@seafile/slate-react';
9
- import Toolbar, { HelpGroup } from '../components/toolbar';
10
- import ModalPortal from '../components/modal-portal';
11
- import ContextMenu from '../components/context-menu';
12
- import TextLinkHoverMenu from '../components//text-link-hover-menu';
13
- import AddLinkDialog from '../components/dialogs/add-link-dialog';
14
- import KeyboardShortcuts from '../components/dialogs/shortcut-dialog';
15
- import { deserialize, serialize } from '../utils/slate2markdown/index';
16
- import { isRangeCollapsed } from '../containers/editor-utils/range-utils';
17
- import { renderNode, renderLeaf, decorationNode } from '../containers/render-utils/editor-utils';
18
- import EditorContext from '../containers/editor-context';
19
- import '../containers/code-highlight-package';
20
- import '../assets/editor/simple-editor.css';
21
- import '../assets/css/image.css';
22
- import '../assets/css/link.css';
23
- import '../assets/css/navbar-imgbutton.css';
24
- var SimpleEditor = /*#__PURE__*/function (_React$Component) {
25
- _inherits(SimpleEditor, _React$Component);
26
- var _super = _createSuper(SimpleEditor);
27
- function SimpleEditor(props) {
28
- var _this;
29
- _classCallCheck(this, SimpleEditor);
30
- _this = _super.call(this, props);
31
- _this.onChange = function (value) {
32
- _this.setState({
33
- value: value
34
- });
35
-
36
- // hide context menu when content change
37
- if (_this.state.isShowContextMenu === true) {
38
- _this.setState({
39
- isShowContextMenu: false
40
- });
41
- _this.contextMenuPosition = {};
42
- }
43
- var operations = _this.editor.operations;
44
- var hasChange = operations.some(function (o) {
45
- return o.type !== 'set_selection' && o.type !== 'set_value';
46
- });
47
- if (hasChange) _this.contentChanged = true;
48
- };
49
- _this.onFocusEditor = function () {
50
- var value = _this.state.value;
51
- if (value.length === 1 && value[0].type === 'paragraph' && Node.text(value[0].children[0]).length === 0) {
52
- _this.editorRef.firstChild.focus();
53
- }
54
- };
55
- _this.focusText = function () {
56
- // In dtable long text editor, press the key to open the editor.
57
- // Then the cursor should move to the end of this character.
58
- var _this$props = _this.props,
59
- focusEnd = _this$props.focusEnd,
60
- value = _this$props.value;
61
- if (focusEnd === true && value.length === 1) {
62
- setTimeout(function () {
63
- Editor.select(_this.editor, {
64
- path: [0, 0],
65
- offset: 1
66
- });
67
- }, 1);
68
- }
69
- };
70
- _this.hasContentChange = function () {
71
- return _this.contentChanged;
72
- };
73
- _this.onContextMenu = function (event) {
74
- if (_this.tableUtils.isInTable()) {
75
- event.preventDefault();
76
- _this.contextMenuPosition = {
77
- left: event.clientX,
78
- top: event.clientY
79
- };
80
- _this.setState({
81
- isShowContextMenu: !_this.state.isShowContextMenu
82
- });
83
- }
84
- };
85
- _this.onCut = function (event) {
86
- _this.editorUtils.onCut(event);
87
- };
88
- _this.onCopy = function (event) {
89
- _this.editorUtils.onCopy(event, _this.editor);
90
- };
91
- _this.onKeyDown = function (event) {
92
- _this.editorUtils.onKeyDown(event);
93
- };
94
- _this.toggleShortcutDialog = function () {
95
- _this.setState({
96
- isShowShortcutDialog: !_this.state.isShowShortcutDialog
97
- });
98
- };
99
- _this.onToggleLinkDialog = function () {
100
- _this.setState({
101
- isShowLinkDialog: !_this.state.isShowLinkDialog
102
- });
103
- };
104
- _this.setEditorRef = function (ref) {
105
- _this.editorRef = ref;
106
- };
107
- _this.state = {
108
- value: deserialize(props.value),
109
- isShowBigImage: false,
110
- isShowContextMenu: false,
111
- isShowShortcutDialog: false,
112
- isShowLinkDialog: false
113
- };
114
- _this.editor = EditorContext.getEditor(props);
115
- _this.editorUtils = EditorContext.getEditorUtils();
116
- _this.tableUtils = EditorContext.getTableUtils();
117
- _this.contextMenuPosition = {};
118
- return _this;
119
- }
120
- _createClass(SimpleEditor, [{
121
- key: "componentDidMount",
122
- value: function componentDidMount() {
123
- this.props.onRef(this);
124
- this.focusText();
125
- }
126
- }, {
127
- key: "componentWillUnmount",
128
- value: function componentWillUnmount() {
129
- EditorContext.resetEditor();
130
- }
131
- }, {
132
- key: "getMarkdown",
133
- value: function getMarkdown() {
134
- this.contentChanged = false;
135
- return serialize(this.state.value);
136
- }
137
- }, {
138
- key: "getValue",
139
- value: function getValue() {
140
- return this.state.value;
141
- }
142
- }, {
143
- key: "render",
144
- value: function render() {
145
- var editor = this.editor;
146
- var value = this.state.value;
147
- var toolbarStatus = this.editorUtils.getToolbarStatus();
148
- var _this$props2 = this.props,
149
- readOnly = _this$props2.readOnly,
150
- t = _this$props2.t;
151
- var selectionCollapsed = isRangeCollapsed(editor.selection);
152
- return /*#__PURE__*/React.createElement("div", {
153
- className: "seafile-simple-editor"
154
- }, /*#__PURE__*/React.createElement("div", {
155
- className: "seafile-editor-topbar"
156
- }, /*#__PURE__*/React.createElement(Toolbar, {
157
- isSimpleEditor: true
158
- }), /*#__PURE__*/React.createElement(HelpGroup, {
159
- onHelpToggle: this.toggleShortcutDialog
160
- })), /*#__PURE__*/React.createElement(Slate, {
161
- editor: this.editor,
162
- value: value,
163
- onChange: this.onChange
164
- }, /*#__PURE__*/React.createElement("div", {
165
- className: "seafile-editor-module editor-container"
166
- }, /*#__PURE__*/React.createElement("div", {
167
- ref: this.setEditorRef,
168
- onClick: this.onFocusEditor,
169
- className: "editor article"
170
- }, /*#__PURE__*/React.createElement(Editable, {
171
- autoFocus: true,
172
- renderElement: function renderElement(props) {
173
- return renderNode(props, editor, readOnly);
174
- },
175
- className: 'editor-component',
176
- renderLeaf: renderLeaf,
177
- onContextMenu: this.onContextMenu,
178
- onCut: this.onCut,
179
- onCopy: this.onCopy,
180
- onKeyDown: this.onKeyDown,
181
- decorate: decorationNode
182
- })), toolbarStatus.isLinkActive && selectionCollapsed ? /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(TextLinkHoverMenu, {
183
- onToggleLinkDialog: this.onToggleLinkDialog,
184
- editorUtils: this.editorUtils
185
- })) : null, this.state.isShowContextMenu && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(ContextMenu, {
186
- tableUtils: this.tableUtils,
187
- contextMenuPosition: this.contextMenuPosition
188
- })), this.state.isShowShortcutDialog && /*#__PURE__*/React.createElement(KeyboardShortcuts, {
189
- userHelp: t('userHelp', {
190
- returnObjects: true
191
- }),
192
- toggleShortcutDialog: this.toggleShortcutDialog
193
- }), this.state.isShowLinkDialog && /*#__PURE__*/React.createElement(AddLinkDialog, {
194
- toggleLinkDialog: this.onToggleLinkDialog
195
- }))));
196
- }
197
- }]);
198
- return SimpleEditor;
199
- }(React.Component);
200
- export default withTranslation('seafile-editor')(SimpleEditor);
@@ -1,260 +0,0 @@
1
- import { generateTableRow, generateTableCell } from '../containers/element-model/table';
2
- import { jsx } from 'slate-hyperscript';
3
- var ELEMENT_TAGS = {
4
- A: function A(el) {
5
- return {
6
- type: 'link',
7
- data: {
8
- href: el.getAttribute('href')
9
- }
10
- };
11
- },
12
- BLOCKQUOTE: function BLOCKQUOTE() {
13
- return {
14
- type: 'blockquote'
15
- };
16
- },
17
- H1: function H1() {
18
- return {
19
- type: 'header_one'
20
- };
21
- },
22
- H2: function H2() {
23
- return {
24
- type: 'header_two'
25
- };
26
- },
27
- H3: function H3() {
28
- return {
29
- type: 'header_three'
30
- };
31
- },
32
- H4: function H4() {
33
- return {
34
- type: 'header_four'
35
- };
36
- },
37
- H5: function H5() {
38
- return {
39
- type: 'header_five'
40
- };
41
- },
42
- H6: function H6() {
43
- return {
44
- type: 'header_six'
45
- };
46
- },
47
- IMG: function IMG(el) {
48
- return {
49
- type: 'image',
50
- children: [{
51
- text: ''
52
- }],
53
- data: {
54
- src: el.getAttribute('src')
55
- }
56
- };
57
- },
58
- LI: function LI() {
59
- return {
60
- type: 'list_item',
61
- data: {}
62
- };
63
- },
64
- OL: function OL() {
65
- return {
66
- type: 'ordered_list'
67
- };
68
- },
69
- P: function P() {
70
- return {
71
- type: 'paragraph'
72
- };
73
- },
74
- UL: function UL() {
75
- return {
76
- type: 'unordered_list'
77
- };
78
- },
79
- TABLE: function TABLE() {
80
- return {
81
- type: 'table'
82
- };
83
- },
84
- BR: function BR() {
85
- return {
86
- text: ''
87
- };
88
- }
89
- };
90
- var HEADER_LIST = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
91
- var TEXT_TAGS = {
92
- CODE: function CODE() {
93
- return {
94
- CODE: true
95
- };
96
- },
97
- DEL: function DEL() {
98
- return {
99
- DELETE: true
100
- };
101
- },
102
- EM: function EM() {
103
- return {
104
- ITALIC: true
105
- };
106
- },
107
- I: function I() {
108
- return {
109
- ITALIC: true
110
- };
111
- },
112
- STRONG: function STRONG() {
113
- return {
114
- BOLD: true
115
- };
116
- },
117
- INS: function INS() {
118
- return {
119
- INS: true
120
- };
121
- }
122
- };
123
- var parseTable = function parseTable(el) {
124
- if (el.parentNode.nodeName !== 'BODY') {
125
- return null;
126
- }
127
- var tableWidth = 0;
128
- Array.from(el.rows[0].childNodes).forEach(function (cell, index) {
129
- if (cell.nodeName === 'TD' || cell.nodeName === 'TH') {
130
- tableWidth += Number(cell.getAttribute('colspan')) || 1;
131
- }
132
- });
133
- var rowList = [];
134
- for (var rowIndex = 0; rowIndex < el.rows.length; rowIndex++) {
135
- var cells = el.rows[rowIndex].cells;
136
- var cellsList = [];
137
- for (var columnIndex = 0; columnIndex < cells.length; columnIndex++) {
138
- var cell = cells[columnIndex];
139
- cellsList.push(generateTableCell({
140
- children: [{
141
- type: 'paragraph',
142
- children: [{
143
- text: cell.textContent
144
- }]
145
- }]
146
- }));
147
- }
148
- if (cellsList.length < tableWidth) {
149
- var count = tableWidth - cellsList.length;
150
- for (var i = 0; i < count; i++) {
151
- cellsList.push(generateTableCell({
152
- children: [{
153
- type: 'paragraph',
154
- children: [{
155
- text: ''
156
- }]
157
- }]
158
- }));
159
- }
160
- }
161
- rowList.push(generateTableRow({
162
- children: cellsList
163
- }));
164
- }
165
- return rowList;
166
- };
167
- var deserializeHtml = function deserializeHtml(el) {
168
- if (el.nodeType === 3) {
169
- // remove \n character
170
- if (el.textContent === '\n' || el.textContent === '\r') {
171
- return null;
172
- }
173
- if (el.parentElement.nodeName === 'BODY') {
174
- var text = el.textContent.replace(/(\n|\r\n)/g, '');
175
- if (text.length === 0) return null;
176
- return {
177
- type: 'paragraph',
178
- children: [{
179
- text: text
180
- }]
181
- };
182
- }
183
- return el.textContent;
184
- } else if (el.nodeType !== 1) {
185
- return null;
186
- }
187
- var nodeName = el.nodeName;
188
- var parent = el;
189
- var children = Array.from(parent.childNodes).map(deserializeHtml).flat();
190
-
191
- // deserialize task list
192
- if (nodeName === 'LI') {
193
- if (el.className && el.className.indexOf('task-list-item') >= 0) {
194
- return jsx('element', {
195
- data: {
196
- checked: false
197
- },
198
- type: 'list_item'
199
- }, children);
200
- }
201
- }
202
- if (nodeName === 'PRE' && el.childNodes[0] && el.childNodes[0].nodeName === 'CODE') {
203
- // deserialize code block
204
- var code = el.childNodes[0];
205
- var codeChildren = [];
206
- code.childNodes.forEach(function (codeLine, index) {
207
- if (codeLine.innerText) {
208
- codeChildren.push({
209
- type: 'code_line',
210
- children: [{
211
- text: codeLine.innerText
212
- }]
213
- });
214
- }
215
- });
216
- return {
217
- data: {
218
- syntax: null
219
- },
220
- children: codeChildren,
221
- type: 'code_block'
222
- };
223
- }
224
- if (el.nodeName === 'BODY') {
225
- return jsx('fragment', {}, children);
226
- }
227
- if (ELEMENT_TAGS[nodeName]) {
228
- var attrs = ELEMENT_TAGS[nodeName](el);
229
- if (nodeName === 'IMG') {
230
- return jsx('element', attrs, [{
231
- text: ''
232
- }]);
233
- }
234
-
235
- // modify BR into an empty text node
236
- if (nodeName === 'BR') {
237
- return '';
238
- }
239
- if (nodeName === 'TABLE') {
240
- return jsx('element', attrs, parseTable(el));
241
- }
242
- if (nodeName === 'A' || HEADER_LIST.includes(nodeName)) {
243
- return jsx('element', attrs, [{
244
- text: el.textContent
245
- }]);
246
- }
247
- return jsx('element', attrs, children);
248
- }
249
- if (TEXT_TAGS[nodeName]) {
250
- var _attrs = TEXT_TAGS[nodeName](el);
251
- return children.map(function (child) {
252
- return jsx('text', _attrs, child);
253
- });
254
- }
255
- return children;
256
- };
257
- export var htmlDeserializer = function htmlDeserializer(html) {
258
- var parsed = new DOMParser().parseFromString(html, 'text/html');
259
- return deserializeHtml(parsed.body);
260
- };
@@ -1,35 +0,0 @@
1
- function compareTwoStrings(str1, str2) {
2
- if (!str1.length && !str2.length) return 1; // if both are empty strings
3
- if (!str1.length || !str2.length) return 0; // if only one is empty string
4
- if (str1.toUpperCase() === str2.toUpperCase()) return 1; // identical
5
- if (str1.length === 1 && str2.length === 1) return 0; // both are 1-letter strings
6
-
7
- var pairs1 = wordLetterPairs(str1);
8
- var pairs2 = wordLetterPairs(str2);
9
- var union = pairs1.length + pairs2.length;
10
- var intersection = 0;
11
- pairs1.forEach(function (pair1) {
12
- for (var i = 0, pair2; pair2 = pairs2[i]; i++) {
13
- if (pair1 !== pair2) continue;
14
- intersection++;
15
- pairs2.splice(i, 1);
16
- break;
17
- }
18
- });
19
- return intersection * 2 / union;
20
- }
21
- function flattenDeep(arr) {
22
- return Array.isArray(arr) ? arr.reduce(function (a, b) {
23
- return a.concat(flattenDeep(b));
24
- }, []) : [arr];
25
- }
26
- function letterPairs(str) {
27
- var pairs = [];
28
- for (var i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2);
29
- return pairs;
30
- }
31
- function wordLetterPairs(str) {
32
- var pairs = str.toUpperCase().split(' ').map(letterPairs);
33
- return flattenDeep(pairs);
34
- }
35
- export { compareTwoStrings };