@seafile/sdoc-editor 0.4.28 → 0.4.29

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.
@@ -1,5 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useCallback, useEffect, useState, useRef } from 'react';
3
+ import { useReadOnly } from '@seafile/slate-react';
3
4
  import classnames from 'classnames';
4
5
  import { useScrollContext } from '../../../hooks/use-scroll-context';
5
6
  import { unwrapLinkNode, getUrl } from './helpers';
@@ -16,6 +17,7 @@ const FileLink = _ref => {
16
17
  } = _ref;
17
18
  const fileRef = useRef(null);
18
19
  const scrollRef = useScrollContext();
20
+ const readOnly = useReadOnly();
19
21
  const [isShowInsertHoverMenu, setIsShowInsertHoverMenu] = useState(false);
20
22
  const [menuPosition, setMenuPosition] = useState({});
21
23
  const registerEventHandle = useCallback(() => {
@@ -68,6 +70,10 @@ const FileLink = _ref => {
68
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
69
71
  }, [isShowInsertHoverMenu]);
70
72
  const onClickFile = useCallback(e => {
73
+ if (readOnly) {
74
+ window.open(getUrl(element.doc_uuid));
75
+ return;
76
+ }
71
77
  if (isShowInsertHoverMenu) {
72
78
  e.stopPropagation();
73
79
  }
@@ -71,13 +71,22 @@ class LinkHoverMenuComponent extends React.Component {
71
71
  attributes,
72
72
  children,
73
73
  element,
74
- editor
74
+ editor,
75
+ readonly
75
76
  } = this.props;
76
77
  const {
77
78
  isShowLinkMenu,
78
79
  menuPosition
79
80
  } = this.state;
80
81
  const className = isShowLinkMenu ? 'seafile-ed-hovermenu-mouseclick' : null;
82
+ if (readonly) {
83
+ return /*#__PURE__*/React.createElement("span", Object.assign({
84
+ className: className
85
+ }, attributes), /*#__PURE__*/React.createElement("a", {
86
+ href: element.href,
87
+ title: element.title
88
+ }, children));
89
+ }
81
90
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", Object.assign({
82
91
  className: className
83
92
  }, attributes, {
@@ -70,6 +70,10 @@ const SdocFileLink = _ref => {
70
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
71
  }, [isShowInsertHoverMenu]);
72
72
  const onClickFile = useCallback(e => {
73
+ if (readOnly) {
74
+ window.open(getUrl(element.doc_uuid));
75
+ return;
76
+ }
73
77
  if (isShowInsertHoverMenu) {
74
78
  e.stopPropagation();
75
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",