@kids-reporter/draft-editor 1.0.4 → 1.0.5
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.
- package/lib/buttons/anchor.js +4 -5
- package/lib/buttons/annotation.js +3 -2
- package/lib/buttons/bt-names.js +1 -0
- package/lib/buttons/index.js +3 -1
- package/lib/buttons/info-box.js +1 -1
- package/lib/buttons/link.js +8 -6
- package/lib/buttons/toc-anchor.js +51 -0
- package/lib/draft-editor.js +16 -14
- package/lib/entity-decorators/anchor.js +16 -15
- package/lib/entity-decorators/toc-anchor.js +111 -0
- package/package.json +2 -2
package/lib/buttons/anchor.js
CHANGED
|
@@ -25,9 +25,8 @@ const AnchorButton = props => {
|
|
|
25
25
|
const start = selection.getStartOffset();
|
|
26
26
|
const end = selection.getEndOffset();
|
|
27
27
|
const selectedText = block.getText().slice(start, end);
|
|
28
|
-
const contentStateWithEntity = contentState.createEntity(_draftRenderer.
|
|
29
|
-
|
|
30
|
-
anchorLabel: selectedText
|
|
28
|
+
const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.Anchor, 'MUTABLE', {
|
|
29
|
+
anchorID: selectedText
|
|
31
30
|
});
|
|
32
31
|
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
33
32
|
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
@@ -45,7 +44,7 @@ const AnchorButton = props => {
|
|
|
45
44
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
46
45
|
className: props.className,
|
|
47
46
|
onMouseDown: isActive ? removeAnchor : promptForAnchor,
|
|
48
|
-
title: "\
|
|
49
|
-
}, /*#__PURE__*/_react.default.createElement("span", null, "\
|
|
47
|
+
title: "\u9328\u9EDE"
|
|
48
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, "\u9328"));
|
|
50
49
|
};
|
|
51
50
|
exports.AnchorButton = AnchorButton;
|
|
@@ -8,10 +8,11 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _btNames = _interopRequireDefault(require("./bt-names"));
|
|
9
9
|
var _draftJs = require("draft-js");
|
|
10
10
|
var _modals = require("@keystone-ui/modals");
|
|
11
|
+
var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
-
const disabledButtons = [_btNames.default.h2, _btNames.default.h3, _btNames.default.code, _btNames.default.codeBlock, _btNames.default.blockquote, _btNames.default.annotation, _btNames.default.embed, _btNames.default.image, _btNames.default.infoBox, _btNames.default.slideshow, _btNames.default.newsReading, _btNames.default.anchor];
|
|
15
|
+
const disabledButtons = [_btNames.default.h2, _btNames.default.h3, _btNames.default.code, _btNames.default.codeBlock, _btNames.default.blockquote, _btNames.default.annotation, _btNames.default.embed, _btNames.default.image, _btNames.default.infoBox, _btNames.default.slideshow, _btNames.default.newsReading, _btNames.default.tocAnchor, _btNames.default.anchor];
|
|
15
16
|
function createAnnotationButton({
|
|
16
17
|
InnerEditor,
|
|
17
18
|
decorator
|
|
@@ -38,7 +39,7 @@ function createAnnotationButton({
|
|
|
38
39
|
const confirmAnnotation = () => {
|
|
39
40
|
const contentState = editorStateOfOuterEditor.getCurrentContent();
|
|
40
41
|
const rawContentState = (0, _draftJs.convertToRaw)(inputValue.editorStateOfInnerEditor.getCurrentContent());
|
|
41
|
-
const contentStateWithEntity = contentState.createEntity(
|
|
42
|
+
const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.Annotation, 'MUTABLE', {
|
|
42
43
|
rawContentState
|
|
43
44
|
});
|
|
44
45
|
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
package/lib/buttons/bt-names.js
CHANGED
package/lib/buttons/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.withStyle = exports.InlineStyleControls = exports.CustomSlideshowButton = exports.CustomNewsReadingButton = exports.CustomLinkButton = exports.CustomImageButton = exports.CustomFontColorButton = exports.CustomEnlargeButton = exports.CustomEmbeddedCodeButton = exports.CustomDividerButton = exports.CustomBlockquoteButton = exports.CustomBackgroundColorButton = exports.CustomAnchorButton = exports.BlockStyleControls = void 0;
|
|
6
|
+
exports.withStyle = exports.InlineStyleControls = exports.CustomTOCAnchorButton = exports.CustomSlideshowButton = exports.CustomNewsReadingButton = exports.CustomLinkButton = exports.CustomImageButton = exports.CustomFontColorButton = exports.CustomEnlargeButton = exports.CustomEmbeddedCodeButton = exports.CustomDividerButton = exports.CustomBlockquoteButton = exports.CustomBackgroundColorButton = exports.CustomAnchorButton = exports.BlockStyleControls = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
8
|
var _controlButtons = require("./control-buttons");
|
|
9
9
|
var _bgColor = require("./bg-color");
|
|
@@ -13,6 +13,7 @@ var _embeddedCode = require("./embedded-code");
|
|
|
13
13
|
var _enlarge = require("./enlarge");
|
|
14
14
|
var _fontColor = require("./font-color");
|
|
15
15
|
var _image = require("./image");
|
|
16
|
+
var _tocAnchor = require("./toc-anchor");
|
|
16
17
|
var _anchor = require("./anchor");
|
|
17
18
|
var _link = require("./link");
|
|
18
19
|
var _slideshow = require("./slideshow");
|
|
@@ -27,6 +28,7 @@ exports.withStyle = withStyle;
|
|
|
27
28
|
const BlockStyleControls = exports.BlockStyleControls = _controlButtons.BlockStyleControls;
|
|
28
29
|
const InlineStyleControls = exports.InlineStyleControls = _controlButtons.InlineStyleControls;
|
|
29
30
|
const CustomBlockquoteButton = exports.CustomBlockquoteButton = withStyle(_blockquote.BlockquoteButton);
|
|
31
|
+
const CustomTOCAnchorButton = exports.CustomTOCAnchorButton = withStyle(_tocAnchor.TOCAnchorButton);
|
|
30
32
|
const CustomAnchorButton = exports.CustomAnchorButton = withStyle(_anchor.AnchorButton);
|
|
31
33
|
const CustomLinkButton = exports.CustomLinkButton = withStyle(_link.LinkButton);
|
|
32
34
|
const CustomEnlargeButton = exports.CustomEnlargeButton = (0, _styledComponents.default)(withStyle(_enlarge.EnlargeButton))`
|
package/lib/buttons/info-box.js
CHANGED
|
@@ -13,7 +13,7 @@ var _select = require("./form/select");
|
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
-
const disabledButtons = [_btNames.default.h2, _btNames.default.h3, _btNames.default.code, _btNames.default.codeBlock, _btNames.default.blockquote, _btNames.default.infoBox, _btNames.default.slideshow, _btNames.default.newsReading, _btNames.default.anchor];
|
|
16
|
+
const disabledButtons = [_btNames.default.h2, _btNames.default.h3, _btNames.default.code, _btNames.default.codeBlock, _btNames.default.blockquote, _btNames.default.infoBox, _btNames.default.slideshow, _btNames.default.newsReading, _btNames.default.tocAnchor, _btNames.default.anchor];
|
|
17
17
|
var InfoBoxTypeEnum = /*#__PURE__*/function (InfoBoxTypeEnum) {
|
|
18
18
|
InfoBoxTypeEnum["newsChargeStation"] = "news-charge-station";
|
|
19
19
|
InfoBoxTypeEnum["headerBorder"] = "header-border";
|
package/lib/buttons/link.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.LinkButton =
|
|
6
|
+
exports.LinkButton = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _modals = require("@keystone-ui/modals");
|
|
9
9
|
var _draftJs = require("draft-js");
|
|
10
10
|
var _fields = require("@keystone-ui/fields");
|
|
11
|
+
var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
11
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
14
|
const styles = {
|
|
@@ -17,7 +18,7 @@ const styles = {
|
|
|
17
18
|
padding: 10
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
+
const LinkButton = props => {
|
|
21
22
|
const {
|
|
22
23
|
isActive,
|
|
23
24
|
editorState,
|
|
@@ -35,7 +36,7 @@ function LinkButton(props) {
|
|
|
35
36
|
};
|
|
36
37
|
const confirmLink = () => {
|
|
37
38
|
const contentState = editorState.getCurrentContent();
|
|
38
|
-
const contentStateWithEntity = contentState.createEntity(
|
|
39
|
+
const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.Link, 'MUTABLE', {
|
|
39
40
|
url: urlValue
|
|
40
41
|
});
|
|
41
42
|
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
@@ -63,7 +64,7 @@ function LinkButton(props) {
|
|
|
63
64
|
props.onEditFinish();
|
|
64
65
|
};
|
|
65
66
|
const urlInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
|
|
66
|
-
title: "
|
|
67
|
+
title: "\u7DE8\u8F2F\u5916\u90E8\u9023\u7D50\u6216\u5167\u90E8\u9328\u9EDE(ID)",
|
|
67
68
|
isOpen: toShowUrlInput,
|
|
68
69
|
actions: {
|
|
69
70
|
cancel: {
|
|
@@ -75,7 +76,7 @@ function LinkButton(props) {
|
|
|
75
76
|
action: confirmLink
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
|
-
}, /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
79
|
+
}, /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("br", null), "\u5916\u90E8\u9023\u7D50\u7BC4\u4F8B:", /*#__PURE__*/_react.default.createElement("br", null), "https://kids.twreporter.org/article/article1#part1", /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), "\u5167\u90E8\u9328\u9EDE\u7BC4\u4F8B:", /*#__PURE__*/_react.default.createElement("br", null), "#part1"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
79
80
|
onChange: e => setUrlValue(e.target.value),
|
|
80
81
|
style: styles.urlInput,
|
|
81
82
|
type: "text",
|
|
@@ -88,4 +89,5 @@ function LinkButton(props) {
|
|
|
88
89
|
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
89
90
|
className: "fas fa-link"
|
|
90
91
|
})));
|
|
91
|
-
}
|
|
92
|
+
};
|
|
93
|
+
exports.LinkButton = LinkButton;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TOCAnchorButton = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const TOCAnchorButton = props => {
|
|
12
|
+
const toggleEntity = _draftJs.RichUtils.toggleLink;
|
|
13
|
+
const {
|
|
14
|
+
isActive,
|
|
15
|
+
editorState,
|
|
16
|
+
onChange
|
|
17
|
+
} = props;
|
|
18
|
+
const promptForAnchor = e => {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
const selection = editorState.getSelection();
|
|
21
|
+
if (!selection.isCollapsed()) {
|
|
22
|
+
const contentState = editorState.getCurrentContent();
|
|
23
|
+
const startKey = selection.getStartKey();
|
|
24
|
+
const block = contentState.getBlockForKey(startKey);
|
|
25
|
+
const start = selection.getStartOffset();
|
|
26
|
+
const end = selection.getEndOffset();
|
|
27
|
+
const selectedText = block.getText().slice(start, end);
|
|
28
|
+
const contentStateWithEntity = contentState.createEntity(_draftRenderer.ENTITY.TOCAnchor, 'IMMUTABLE', {
|
|
29
|
+
anchorKey: `createdAt-${Date.now()}`,
|
|
30
|
+
anchorLabel: selectedText
|
|
31
|
+
});
|
|
32
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
33
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
34
|
+
currentContent: contentStateWithEntity
|
|
35
|
+
});
|
|
36
|
+
onChange(toggleEntity(newEditorState, newEditorState.getSelection(), entityKey));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const removeAnchor = () => {
|
|
40
|
+
const selection = editorState.getSelection();
|
|
41
|
+
if (!selection.isCollapsed()) {
|
|
42
|
+
onChange(toggleEntity(editorState, selection, null));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
46
|
+
className: props.className,
|
|
47
|
+
onMouseDown: isActive ? removeAnchor : promptForAnchor,
|
|
48
|
+
title: "\u7D22\u5F15"
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, "\u7D22"));
|
|
50
|
+
};
|
|
51
|
+
exports.TOCAnchorButton = TOCAnchorButton;
|
package/lib/draft-editor.js
CHANGED
|
@@ -16,19 +16,13 @@ var _annotation = require("./buttons/annotation");
|
|
|
16
16
|
var _infoBox = require("./buttons/info-box");
|
|
17
17
|
var _bgColor = require("./buttons/bg-color");
|
|
18
18
|
var _fontColor = require("./buttons/font-color");
|
|
19
|
+
var _tocAnchor = require("./entity-decorators/toc-anchor");
|
|
19
20
|
var _anchor = require("./entity-decorators/anchor");
|
|
20
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
22
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
22
|
-
const styleSource =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type: "text/css"
|
|
26
|
-
}), /*#__PURE__*/_react.default.createElement("link", {
|
|
27
|
-
href: "https://storage.googleapis.com/static-readr-tw-dev/cdn/draft-js/rich-editor.css",
|
|
28
|
-
rel: "stylesheet",
|
|
29
|
-
type: "text/css"
|
|
30
|
-
}), /*#__PURE__*/_react.default.createElement("link", {
|
|
31
|
-
href: "https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css",
|
|
23
|
+
const styleSource = ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css', 'https://storage.googleapis.com/static-readr-tw-dev/cdn/draft-js/rich-editor.css', 'https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css'].map((src, index) => /*#__PURE__*/_react.default.createElement("link", {
|
|
24
|
+
key: `style-src-${index}`,
|
|
25
|
+
href: src,
|
|
32
26
|
rel: "stylesheet",
|
|
33
27
|
type: "text/css"
|
|
34
28
|
}));
|
|
@@ -42,6 +36,11 @@ class RichTextEditor extends _react.default.Component {
|
|
|
42
36
|
readOnly: false
|
|
43
37
|
};
|
|
44
38
|
this.editorDecorator = new _draftJs.CompositeDecorator([_draftRenderer.annotationDecorator, _draftRenderer.linkDecorator, {
|
|
39
|
+
..._tocAnchor.editableTOCAnchorDecorator,
|
|
40
|
+
props: {
|
|
41
|
+
...this.customEditProps
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
45
44
|
..._anchor.editableAnchorDecorator,
|
|
46
45
|
props: {
|
|
47
46
|
...this.customEditProps
|
|
@@ -205,12 +204,15 @@ class RichTextEditor extends _react.default.Component {
|
|
|
205
204
|
}), /*#__PURE__*/_react.default.createElement(_styled.EnlargeButtonWrapper, null, /*#__PURE__*/_react.default.createElement(_buttons.CustomEnlargeButton, {
|
|
206
205
|
onToggle: this.toggleEnlarge,
|
|
207
206
|
isEnlarged: isEnlarged
|
|
208
|
-
})), /*#__PURE__*/_react.default.createElement(_buttons.
|
|
207
|
+
})), /*#__PURE__*/_react.default.createElement(_buttons.CustomTOCAnchorButton, _extends({
|
|
208
|
+
isDisabled: disabledButtons.includes(_btNames.default.tocAnchor),
|
|
209
|
+
isActive: entityType === _draftRenderer.ENTITY.TOCAnchor
|
|
210
|
+
}, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomAnchorButton, _extends({
|
|
209
211
|
isDisabled: disabledButtons.includes(_btNames.default.anchor),
|
|
210
|
-
isActive: entityType === _draftRenderer.
|
|
212
|
+
isActive: entityType === _draftRenderer.ENTITY.Anchor
|
|
211
213
|
}, commonProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomLinkButton, _extends({
|
|
212
214
|
isDisabled: disabledButtons.includes(_btNames.default.link),
|
|
213
|
-
isActive: entityType ===
|
|
215
|
+
isActive: entityType === _draftRenderer.ENTITY.Link
|
|
214
216
|
}, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomBackgroundColorButton, _extends({
|
|
215
217
|
isDisabled: disabledButtons.includes(_btNames.default.backgroundColor),
|
|
216
218
|
isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_bgColor.customStylePrefix)) !== undefined
|
|
@@ -221,7 +223,7 @@ class RichTextEditor extends _react.default.Component {
|
|
|
221
223
|
isDisabled: disabledButtons.includes(_btNames.default.blockquote)
|
|
222
224
|
}, commonProps)), /*#__PURE__*/_react.default.createElement(CustomAnnotationButton, _extends({
|
|
223
225
|
isDisabled: disabledButtons.includes(_btNames.default.annotation),
|
|
224
|
-
isActive: entityType ===
|
|
226
|
+
isActive: entityType === _draftRenderer.ENTITY.Annotation
|
|
225
227
|
}, commonProps, this.commonEditProps)), /*#__PURE__*/_react.default.createElement(_buttons.CustomImageButton, _extends({
|
|
226
228
|
isDisabled: disabledButtons.includes(_btNames.default.image),
|
|
227
229
|
ImageSelector: _imageSelector.ImageSelector
|
|
@@ -26,9 +26,12 @@ const AnchorEditButton = _styledComponents.default.div`
|
|
|
26
26
|
display: inline;
|
|
27
27
|
cursor: pointer;
|
|
28
28
|
&::before {
|
|
29
|
-
content: '
|
|
29
|
+
content: '錨點:${props => props.anchorLabel !== undefined ? `(${props.anchorLabel}) ` : ''}';
|
|
30
30
|
}
|
|
31
31
|
`;
|
|
32
|
+
const Warning = _styledComponents.default.p`
|
|
33
|
+
color: red;
|
|
34
|
+
`;
|
|
32
35
|
const StyledTextInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
33
36
|
margin: 10px;
|
|
34
37
|
`;
|
|
@@ -41,7 +44,7 @@ const AnchorLabelEditor = props => {
|
|
|
41
44
|
} = props;
|
|
42
45
|
const [anchorLabel, setTOCLabel] = (0, _react.useState)(anchorLabelValue);
|
|
43
46
|
return /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
|
|
44
|
-
title: "\u7DE8\u8F2F\
|
|
47
|
+
title: "\u7DE8\u8F2F\u9328\u9EDE\u6587\u5B57(ID)",
|
|
45
48
|
isOpen: isOpen,
|
|
46
49
|
actions: {
|
|
47
50
|
cancel: {
|
|
@@ -53,8 +56,8 @@ const AnchorLabelEditor = props => {
|
|
|
53
56
|
action: () => onConfirm(anchorLabel)
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
}, /*#__PURE__*/_react.default.createElement(StyledTextInput, {
|
|
57
|
-
placeholder: "\
|
|
59
|
+
}, /*#__PURE__*/_react.default.createElement(Warning, null, "\u6CE8\u610F\uFF01\u540C\u7BC7\u6587\u7AE0ID\u4E0D\u53EF\u91CD\u8907\uFF01"), /*#__PURE__*/_react.default.createElement(StyledTextInput, {
|
|
60
|
+
placeholder: "\u9328\u9EDE\u6587\u5B57(ID)",
|
|
58
61
|
type: "text",
|
|
59
62
|
value: anchorLabel,
|
|
60
63
|
onChange: e => setTOCLabel(e.target.value)
|
|
@@ -69,33 +72,31 @@ const EditableAnchor = props => {
|
|
|
69
72
|
} = props;
|
|
70
73
|
const tocContent = props.decoratedText;
|
|
71
74
|
const [isModalOpen, setIsModalOpen] = (0, _react.useState)(false);
|
|
72
|
-
const [
|
|
75
|
+
const [anchorID, setAnchorID] = (0, _react.useState)(contentState === null || contentState === void 0 || (_contentState$getEnti = contentState.getEntity(entityKey)) === null || _contentState$getEnti === void 0 || (_contentState$getEnti = _contentState$getEnti.getData()) === null || _contentState$getEnti === void 0 ? void 0 : _contentState$getEnti.anchorID);
|
|
73
76
|
(0, _react.useEffect)(() => {
|
|
74
77
|
var _contentState$getEnti2;
|
|
75
|
-
|
|
78
|
+
setAnchorID((_contentState$getEnti2 = contentState.getEntity(entityKey).getData()) === null || _contentState$getEnti2 === void 0 ? void 0 : _contentState$getEnti2.anchorID);
|
|
76
79
|
});
|
|
77
|
-
const
|
|
78
|
-
var _contentState$getEnti3;
|
|
80
|
+
const onAnchorIDChange = anchorID => {
|
|
79
81
|
setIsModalOpen(false);
|
|
80
|
-
|
|
82
|
+
setAnchorID(anchorID);
|
|
81
83
|
props.onEditFinish({
|
|
82
84
|
entityKey,
|
|
83
85
|
entityData: {
|
|
84
|
-
|
|
85
|
-
anchorLabel: labelValue
|
|
86
|
+
anchorID: anchorID
|
|
86
87
|
}
|
|
87
88
|
});
|
|
88
89
|
};
|
|
89
90
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isModalOpen && /*#__PURE__*/_react.default.createElement(AnchorLabelEditor, {
|
|
90
91
|
isOpen: isModalOpen,
|
|
91
|
-
anchorLabelValue:
|
|
92
|
-
onConfirm:
|
|
92
|
+
anchorLabelValue: anchorID,
|
|
93
|
+
onConfirm: onAnchorIDChange,
|
|
93
94
|
onCancel: () => {
|
|
94
95
|
setIsModalOpen(false);
|
|
95
96
|
props.onEditFinish();
|
|
96
97
|
}
|
|
97
98
|
}), /*#__PURE__*/_react.default.createElement(AnchorWrapper, null, /*#__PURE__*/_react.default.createElement(AnchorEditButton, {
|
|
98
|
-
anchorLabel:
|
|
99
|
+
anchorLabel: anchorID !== tocContent ? anchorID : undefined,
|
|
99
100
|
onClick: e => {
|
|
100
101
|
e.preventDefault();
|
|
101
102
|
setIsModalOpen(true);
|
|
@@ -106,6 +107,6 @@ const EditableAnchor = props => {
|
|
|
106
107
|
})), /*#__PURE__*/_react.default.createElement("span", null, children)));
|
|
107
108
|
};
|
|
108
109
|
const editableAnchorDecorator = exports.editableAnchorDecorator = {
|
|
109
|
-
strategy: _draftRenderer.
|
|
110
|
+
strategy: (0, _draftRenderer.findEntitiesByType)(_draftRenderer.ENTITY.Anchor),
|
|
110
111
|
component: EditableAnchor
|
|
111
112
|
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.editableTOCAnchorDecorator = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
|
+
var _modals = require("@keystone-ui/modals");
|
|
10
|
+
var _fields = require("@keystone-ui/fields");
|
|
11
|
+
var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
const AnchorWrapper = _styledComponents.default.span`
|
|
16
|
+
display: inline;
|
|
17
|
+
color: #8e8e8e;
|
|
18
|
+
&::before {
|
|
19
|
+
content: '[';
|
|
20
|
+
}
|
|
21
|
+
&::after {
|
|
22
|
+
content: ']';
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
const AnchorEditButton = _styledComponents.default.div`
|
|
26
|
+
display: inline;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
&::before {
|
|
29
|
+
content: '索引:${props => props.anchorLabel !== undefined ? `(${props.anchorLabel}) ` : ''}';
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const StyledTextInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
33
|
+
margin: 10px;
|
|
34
|
+
`;
|
|
35
|
+
const AnchorLabelEditor = props => {
|
|
36
|
+
const {
|
|
37
|
+
isOpen,
|
|
38
|
+
anchorLabelValue,
|
|
39
|
+
onConfirm,
|
|
40
|
+
onCancel
|
|
41
|
+
} = props;
|
|
42
|
+
const [anchorLabel, setTOCLabel] = (0, _react.useState)(anchorLabelValue);
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
|
|
44
|
+
title: "\u7DE8\u8F2F\u7D22\u5F15\u986F\u793A\u6587\u5B57",
|
|
45
|
+
isOpen: isOpen,
|
|
46
|
+
actions: {
|
|
47
|
+
cancel: {
|
|
48
|
+
label: 'Cancel',
|
|
49
|
+
action: () => onCancel()
|
|
50
|
+
},
|
|
51
|
+
confirm: {
|
|
52
|
+
label: 'Confirm',
|
|
53
|
+
action: () => onConfirm(anchorLabel)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(StyledTextInput, {
|
|
57
|
+
placeholder: "\u7D22\u5F15\u5728\u76EE\u9304\u5167\u986F\u793A\u6587\u5B57",
|
|
58
|
+
type: "text",
|
|
59
|
+
value: anchorLabel,
|
|
60
|
+
onChange: e => setTOCLabel(e.target.value)
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
const EditableTOCAnchor = props => {
|
|
64
|
+
var _contentState$getEnti;
|
|
65
|
+
const {
|
|
66
|
+
children,
|
|
67
|
+
contentState,
|
|
68
|
+
entityKey
|
|
69
|
+
} = props;
|
|
70
|
+
const tocContent = props.decoratedText;
|
|
71
|
+
const [isModalOpen, setIsModalOpen] = (0, _react.useState)(false);
|
|
72
|
+
const [anchorLabel, setTOCLabel] = (0, _react.useState)(contentState === null || contentState === void 0 || (_contentState$getEnti = contentState.getEntity(entityKey)) === null || _contentState$getEnti === void 0 || (_contentState$getEnti = _contentState$getEnti.getData()) === null || _contentState$getEnti === void 0 ? void 0 : _contentState$getEnti.anchorLabel);
|
|
73
|
+
(0, _react.useEffect)(() => {
|
|
74
|
+
var _contentState$getEnti2;
|
|
75
|
+
setTOCLabel((_contentState$getEnti2 = contentState.getEntity(entityKey).getData()) === null || _contentState$getEnti2 === void 0 ? void 0 : _contentState$getEnti2.anchorLabel);
|
|
76
|
+
});
|
|
77
|
+
const onTOCLabelChange = labelValue => {
|
|
78
|
+
var _contentState$getEnti3;
|
|
79
|
+
setIsModalOpen(false);
|
|
80
|
+
setTOCLabel(labelValue);
|
|
81
|
+
props.onEditFinish({
|
|
82
|
+
entityKey,
|
|
83
|
+
entityData: {
|
|
84
|
+
anchorKey: contentState === null || contentState === void 0 || (_contentState$getEnti3 = contentState.getEntity(entityKey)) === null || _contentState$getEnti3 === void 0 || (_contentState$getEnti3 = _contentState$getEnti3.getData()) === null || _contentState$getEnti3 === void 0 ? void 0 : _contentState$getEnti3.anchorKey,
|
|
85
|
+
anchorLabel: labelValue
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isModalOpen && /*#__PURE__*/_react.default.createElement(AnchorLabelEditor, {
|
|
90
|
+
isOpen: isModalOpen,
|
|
91
|
+
anchorLabelValue: anchorLabel,
|
|
92
|
+
onConfirm: onTOCLabelChange,
|
|
93
|
+
onCancel: () => {
|
|
94
|
+
setIsModalOpen(false);
|
|
95
|
+
props.onEditFinish();
|
|
96
|
+
}
|
|
97
|
+
}), /*#__PURE__*/_react.default.createElement(AnchorWrapper, null, /*#__PURE__*/_react.default.createElement(AnchorEditButton, {
|
|
98
|
+
anchorLabel: anchorLabel !== tocContent ? anchorLabel : undefined,
|
|
99
|
+
onClick: e => {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
setIsModalOpen(true);
|
|
102
|
+
props.onEditStart();
|
|
103
|
+
}
|
|
104
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
105
|
+
className: "fas fa-pen"
|
|
106
|
+
})), /*#__PURE__*/_react.default.createElement("span", null, children)));
|
|
107
|
+
};
|
|
108
|
+
const editableTOCAnchorDecorator = exports.editableTOCAnchorDecorator = {
|
|
109
|
+
strategy: (0, _draftRenderer.findEntitiesByType)(_draftRenderer.ENTITY.TOCAnchor),
|
|
110
|
+
component: EditableTOCAnchor
|
|
111
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kids-reporter/draft-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@kids-reporter/draft-renderer": "1.0.
|
|
26
|
+
"@kids-reporter/draft-renderer": "1.0.5",
|
|
27
27
|
"@twreporter/errors": "^1.1.2",
|
|
28
28
|
"draft-js": "^0.11.7"
|
|
29
29
|
},
|