@teamias/rex-design 0.0.12 → 0.0.13
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.
|
@@ -17,6 +17,9 @@ export default (function () {
|
|
|
17
17
|
messages: _objectSpread({}, crush(enUS))
|
|
18
18
|
})
|
|
19
19
|
},
|
|
20
|
-
children: /*#__PURE__*/_jsx(TiptapEditor, {
|
|
20
|
+
children: /*#__PURE__*/_jsx(TiptapEditor, {
|
|
21
|
+
readOnly: true,
|
|
22
|
+
defaultValue: "<p>Hello World</p>"
|
|
23
|
+
})
|
|
21
24
|
});
|
|
22
25
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GetProps } from 'antd';
|
|
1
|
+
import { Extensions, useEditor } from '@tiptap/react';
|
|
3
2
|
import { FC, ReactNode } from 'react';
|
|
4
3
|
/**
|
|
5
4
|
* https://v2.tiptap.dev/docs/editor/extensions/nodes/task-item
|
|
@@ -34,7 +33,8 @@ export interface TiptapEditorProps {
|
|
|
34
33
|
/**
|
|
35
34
|
* @desc 传递给 EditorContent 的属性
|
|
36
35
|
*/
|
|
37
|
-
|
|
36
|
+
/** 是否只读 */
|
|
37
|
+
readOnly?: boolean;
|
|
38
38
|
}
|
|
39
39
|
interface IConfigItem {
|
|
40
40
|
title: string;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
1
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
2
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -36,7 +30,6 @@ import { Box } from "./styles";
|
|
|
36
30
|
* https://v2.tiptap.dev/docs/editor/extensions/nodes/task-item
|
|
37
31
|
*/
|
|
38
32
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
39
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
40
33
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
41
34
|
export var TiptapEditor = function TiptapEditor(_ref) {
|
|
42
35
|
var _ref$type = _ref.type,
|
|
@@ -52,9 +45,11 @@ export var TiptapEditor = function TiptapEditor(_ref) {
|
|
|
52
45
|
preventLineBreaks = _ref.preventLineBreaks,
|
|
53
46
|
renderToolBar = _ref.renderToolBar,
|
|
54
47
|
extensions = _ref.extensions,
|
|
55
|
-
|
|
48
|
+
_ref$readOnly = _ref.readOnly,
|
|
49
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly;
|
|
56
50
|
var intl = useIntl();
|
|
57
51
|
var editor = useEditor({
|
|
52
|
+
editable: !readOnly,
|
|
58
53
|
extensions: [].concat(_toConsumableArray(extensions || []), [BulletList, OrderedList, StarterKit.configure({
|
|
59
54
|
paragraph: {
|
|
60
55
|
HTMLAttributes: {
|
|
@@ -476,6 +471,9 @@ export var TiptapEditor = function TiptapEditor(_ref) {
|
|
|
476
471
|
editor === null || editor === void 0 || editor.destroy();
|
|
477
472
|
};
|
|
478
473
|
}, []);
|
|
474
|
+
useEffect(function () {
|
|
475
|
+
editor === null || editor === void 0 || editor.setEditable(!readOnly);
|
|
476
|
+
}, [readOnly]);
|
|
479
477
|
useEffect(function () {
|
|
480
478
|
if (type === 'text') {
|
|
481
479
|
if (value && value === (editor === null || editor === void 0 ? void 0 : editor.getText())) return;
|
|
@@ -493,7 +491,8 @@ export var TiptapEditor = function TiptapEditor(_ref) {
|
|
|
493
491
|
}, 0);
|
|
494
492
|
},
|
|
495
493
|
children: [function () {
|
|
496
|
-
|
|
494
|
+
// || !editor?.isEditable
|
|
495
|
+
// if (hiddenToolBar) return <></>;
|
|
497
496
|
var oldNode = /*#__PURE__*/_jsx(Flex, {
|
|
498
497
|
wrap: true,
|
|
499
498
|
gap: "small",
|
|
@@ -503,7 +502,7 @@ export var TiptapEditor = function TiptapEditor(_ref) {
|
|
|
503
502
|
borderBottom: '1px solid #ddd',
|
|
504
503
|
background: '#f8f8f8'
|
|
505
504
|
},
|
|
506
|
-
children: config.map(function (item, index) {
|
|
505
|
+
children: (hiddenToolBar || !(editor !== null && editor !== void 0 && editor.isEditable) ? [] : config).map(function (item, index) {
|
|
507
506
|
if (item.key === 'divider') {
|
|
508
507
|
return /*#__PURE__*/_jsx(Divider, {
|
|
509
508
|
type: "vertical"
|
|
@@ -529,8 +528,8 @@ export var TiptapEditor = function TiptapEditor(_ref) {
|
|
|
529
528
|
return renderToolBar(oldNode, editor, config);
|
|
530
529
|
}
|
|
531
530
|
return oldNode;
|
|
532
|
-
}(), /*#__PURE__*/_jsx(EditorContent,
|
|
531
|
+
}(), /*#__PURE__*/_jsx(EditorContent, {
|
|
533
532
|
editor: editor
|
|
534
|
-
})
|
|
533
|
+
})]
|
|
535
534
|
});
|
|
536
535
|
};
|