@seafile/sdoc-editor 0.5.35 → 0.5.36

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.
@@ -22,7 +22,8 @@ export const INTERNAL_EVENT = {
22
22
  UPDATE_MENTION_TEMP_CONTENT: 'update_mention_temp_content',
23
23
  TABLE_COLUMN_START_DRAG: 'table_column_start_drag',
24
24
  TABLE_SHOW_DRAG_HANDLER: 'table_show_drag_handler',
25
- TABLE_HIDE_DRAG_HANDLER: 'table_show_drag_handler'
25
+ TABLE_HIDE_DRAG_HANDLER: 'table_show_drag_handler',
26
+ ON_PRINT: 'on_print'
26
27
  };
27
28
  export const REVISION_DIFF_KEY = 'diff';
28
29
  export const REVISION_DIFF_VALUE = '1';
@@ -177,7 +177,8 @@ const EditableArticle = _ref => {
177
177
  onMouseDown: onMouseDown,
178
178
  decorate: decorate,
179
179
  onCut: eventProxy.onCut,
180
- onCopy: eventProxy.onCopy
180
+ onCopy: eventProxy.onCopy,
181
+ id: "sdoc-editor"
181
182
  })), /*#__PURE__*/React.createElement(SideToolbar, null), isShowComment && /*#__PURE__*/React.createElement(CommentWrapper, {
182
183
  editor: editor,
183
184
  type: "editor"
@@ -33,9 +33,11 @@ const Paragraph = _ref => {
33
33
  }
34
34
  const style = {
35
35
  textAlign: element.align,
36
+ paddingTop: '5px',
37
+ paddingBottom: '5px',
36
38
  paddingLeft: indent ? '28px' : ''
37
39
  };
38
- return /*#__PURE__*/React.createElement("p", Object.assign({
40
+ return /*#__PURE__*/React.createElement("div", Object.assign({
39
41
  "data-id": element.id
40
42
  }, attributes, {
41
43
  style: _objectSpread({
@@ -1,6 +1,7 @@
1
1
  .sdoc-table-wrapper {
2
2
  width: 100%;
3
3
  margin: 16px 0;
4
+ page-break-inside:avoid;
4
5
  }
5
6
 
6
7
  .sdoc-table-wrapper+.sdoc-table-wrapper {
@@ -41,7 +41,7 @@ const ColumnsHeader = _ref => {
41
41
  // eslint-disable-next-line react-hooks/exhaustive-deps
42
42
  }, [table, columns, tableSize]);
43
43
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
44
- className: "sdoc-table-columns-header position-absolute",
44
+ className: "sdoc-table-columns-header position-absolute d-print-none",
45
45
  contentEditable: false
46
46
  }, /*#__PURE__*/React.createElement("div", {
47
47
  className: "sdoc-table-columns-header-container h-100 d-flex position-absolute",
@@ -15,7 +15,7 @@ const RowsColumnsHeader = _ref => {
15
15
  maxColIndex: tableSize[1] - 1
16
16
  });
17
17
  return /*#__PURE__*/React.createElement("div", {
18
- className: classnames('sdoc-table-rows-columns-header', {
18
+ className: classnames('sdoc-table-rows-columns-header d-print-none', {
19
19
  'range-selected': isSelectedAllTableCells
20
20
  }),
21
21
  contentEditable: false,
@@ -45,7 +45,7 @@ const RowsHeader = _ref => {
45
45
  // eslint-disable-next-line react-hooks/exhaustive-deps
46
46
  }, [tableSize, table]);
47
47
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
48
- className: "sdoc-table-rows-header h-100 position-absolute d-flex flex-column",
48
+ className: "sdoc-table-rows-header h-100 position-absolute d-flex flex-column d-print-none",
49
49
  contentEditable: false
50
50
  }, children.map((row, index) => {
51
51
  return /*#__PURE__*/React.createElement(RowHeader, {
@@ -67,6 +67,11 @@ class EventProxy {
67
67
  if (isHotkey('tab', event) || isHotkey('shift+tab', event)) {
68
68
  editor.handleTab && editor.handleTab(event);
69
69
  }
70
+ if (isHotkey('mod+p', event)) {
71
+ event.preventDefault();
72
+ const eventBus = EventBus.getInstance();
73
+ eventBus.dispatch(INTERNAL_EVENT.ON_PRINT);
74
+ }
70
75
  const node = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE);
71
76
  if (node) {
72
77
  this.editor.tableOnKeyDown(event);
@@ -1,9 +1,11 @@
1
- import React, { useCallback, useState } from 'react';
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
2
  import { withTranslation } from 'react-i18next';
3
3
  import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
4
+ import printJS from '@seafile/print-js';
4
5
  import { EventBus } from '../../basic-sdk';
5
6
  import { EXTERNAL_EVENT } from '../../constants';
6
7
  import context from '../../context';
8
+ import { INTERNAL_EVENT } from '../../basic-sdk/constants';
7
9
  const MoreOperations = _ref => {
8
10
  let {
9
11
  t
@@ -15,9 +17,28 @@ const MoreOperations = _ref => {
15
17
  const docPerm = context.getSetting('docPerm');
16
18
  const historyURL = context.getSetting('historyURL');
17
19
  const isSdocRevision = context.getSetting('isSdocRevision');
20
+ const cssUrls = context.getPrintCss();
21
+ useEffect(() => {
22
+ const eventBus = EventBus.getInstance();
23
+ const unSubscribe = eventBus.subscribe(INTERNAL_EVENT.ON_PRINT, handlePrint);
24
+ return () => {
25
+ unSubscribe();
26
+ };
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, []);
18
29
  const toggleDropdown = useCallback(isDropdownOpen => {
19
30
  setIsDropdownOpen(!isDropdownOpen);
20
31
  }, []);
32
+ const handlePrint = useCallback(() => {
33
+ printJS({
34
+ printable: 'sdoc-editor',
35
+ type: 'html',
36
+ scanStyles: true,
37
+ targetStyles: ['*'],
38
+ style: '@page { size: auto A4 landscape;margin:20px auto; padding: 0;} .d-print-none{display:none !important;}',
39
+ css: cssUrls
40
+ });
41
+ }, [cssUrls]);
21
42
  const onFreezeDocument = useCallback(() => {
22
43
  const eventBus = EventBus.getInstance();
23
44
  eventBus.dispatch(EXTERNAL_EVENT.FREEZE_DOCUMENT);
@@ -51,7 +72,10 @@ const MoreOperations = _ref => {
51
72
  }, t('Open_parent_folder')), isPro && isFreezed && /*#__PURE__*/React.createElement(DropdownItem, {
52
73
  className: "sdoc-dropdown-menu-item",
53
74
  onClick: unFreeze
54
- }, t('Unfreeze')), isPro && !isFreezed && /*#__PURE__*/React.createElement(DropdownItem, {
75
+ }, t('Unfreeze')), /*#__PURE__*/React.createElement(DropdownItem, {
76
+ className: "sdoc-dropdown-menu-item",
77
+ onClick: handlePrint
78
+ }, t('Print')), isPro && !isFreezed && /*#__PURE__*/React.createElement(DropdownItem, {
55
79
  className: "sdoc-dropdown-menu-item",
56
80
  onClick: onFreezeDocument
57
81
  }, t('Freeze_document')), /*#__PURE__*/React.createElement(DropdownItem, {
package/dist/context.js CHANGED
@@ -57,6 +57,13 @@ class Context {
57
57
  if (this.settings[key] === false) return this.settings[key];
58
58
  return this.settings[key] || '';
59
59
  }
60
+ getPrintCss() {
61
+ const server = this.getSetting('serviceUrl');
62
+ const mediaUrl = this.getSetting('mediaUrl');
63
+ const commonCss = "".concat(server).concat(mediaUrl, "css/seafile-ui.css");
64
+ const fontCss = "".concat(server).concat(mediaUrl, "/sdoc-editor/sdoc-editor-font.css");
65
+ return [commonCss, fontCss];
66
+ }
60
67
  updateSettings(update) {
61
68
  for (let key in update) {
62
69
  this.settings[key] = update[key];
@@ -1,3 +1,8 @@
1
+ body {
2
+ -webkit-print-color-adjust: exact;
3
+ color-adjust: exact;
4
+ }
5
+
1
6
  #root, #wrapper {
2
7
  height: 100%;
3
8
  width: 100%;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.35",
3
+ "version": "0.5.36",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
7
7
  "dependencies": {
8
+ "@seafile/print-js": "^1.6.2",
8
9
  "@seafile/react-image-lightbox": "2.0.4",
9
10
  "@seafile/slate": "0.91.8",
10
11
  "@seafile/slate-history": "0.86.2",
@@ -452,5 +452,6 @@
452
452
  "Move_column_count": "Moving {{count}} column(s)",
453
453
  "Move_row_count": "Moving {{count}} row(s)",
454
454
  "Mark_all_as_read": "Mark all as read",
455
- "Alignment_type": "Alignment"
455
+ "Alignment_type": "Alignment",
456
+ "Print": "Print"
456
457
  }
@@ -452,5 +452,6 @@
452
452
  "Move_column_count": "移动{{count}}列",
453
453
  "Move_row_count": "移动{{count}}行",
454
454
  "Mark_all_as_read": "全部标记为已读",
455
- "Alignment_type": "对齐方式"
455
+ "Alignment_type": "对齐方式",
456
+ "Print": "打印"
456
457
  }