@kids-reporter/draft-editor 1.0.2 → 1.0.3
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/block-renderer-fn.js +9 -23
- package/lib/block-renderers/blockquote.js +5 -8
- package/lib/block-renderers/embedded-code.js +5 -8
- package/lib/block-renderers/image.js +5 -8
- package/lib/block-renderers/info-box.js +5 -8
- package/lib/block-renderers/slideshow.js +5 -8
- package/lib/block-renderers/styled.js +10 -3
- package/lib/buttons/anchor.js +51 -0
- package/lib/buttons/annotation.js +1 -1
- package/lib/buttons/bt-names.js +2 -1
- package/lib/buttons/control-buttons.js +160 -0
- package/lib/buttons/index.js +54 -0
- package/lib/buttons/info-box.js +1 -1
- package/lib/buttons/inner-anchor.js +53 -0
- package/lib/draft-editor.js +113 -452
- package/lib/entity-decorators/anchor.js +112 -0
- package/lib/entity-decorators/inner-anchor.js +110 -0
- package/lib/styled.js +104 -0
- package/package.json +2 -2
- package/lib/buttons/form/array-field.js +0 -30
package/lib/block-renderer-fn.js
CHANGED
|
@@ -20,35 +20,21 @@ const AtomicBlock = props => {
|
|
|
20
20
|
const entityData = entity.getData();
|
|
21
21
|
switch (entityType) {
|
|
22
22
|
case 'BLOCKQUOTE':
|
|
23
|
-
|
|
24
|
-
return (0, _blockquote.EditableBlockquote)(props);
|
|
25
|
-
}
|
|
23
|
+
return (0, _blockquote.EditableBlockquote)(props);
|
|
26
24
|
case 'DIVIDER':
|
|
27
|
-
|
|
28
|
-
return Divider();
|
|
29
|
-
}
|
|
25
|
+
return Divider();
|
|
30
26
|
case 'IMAGE':
|
|
31
|
-
|
|
32
|
-
return (0, _image.EditableImage)(props);
|
|
33
|
-
}
|
|
27
|
+
return (0, _image.EditableImage)(props);
|
|
34
28
|
case 'SLIDESHOW':
|
|
35
|
-
|
|
36
|
-
return (0, _slideshow.EditableSlideshow)(props);
|
|
37
|
-
}
|
|
29
|
+
return (0, _slideshow.EditableSlideshow)(props);
|
|
38
30
|
case 'EMBEDDEDCODE':
|
|
39
|
-
|
|
40
|
-
return (0, _embeddedCode.EditableEmbeddedCode)(props);
|
|
41
|
-
}
|
|
31
|
+
return (0, _embeddedCode.EditableEmbeddedCode)(props);
|
|
42
32
|
case 'INFOBOX':
|
|
43
|
-
|
|
44
|
-
return (0, _infoBox.EditableInfoBox)(props);
|
|
45
|
-
}
|
|
33
|
+
return (0, _infoBox.EditableInfoBox)(props);
|
|
46
34
|
case 'NEWS_READING':
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
35
|
+
return NewsReading({
|
|
36
|
+
data: entityData
|
|
37
|
+
});
|
|
52
38
|
}
|
|
53
39
|
return null;
|
|
54
40
|
};
|
|
@@ -53,16 +53,13 @@ function EditableBlockquote(props) {
|
|
|
53
53
|
},
|
|
54
54
|
onConfirm: onInputChange,
|
|
55
55
|
inputValue: data
|
|
56
|
-
}), /*#__PURE__*/_react.default.createElement(EditableBlock,
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
}), /*#__PURE__*/_react.default.createElement(EditableBlock, {
|
|
57
|
+
component: /*#__PURE__*/_react.default.createElement(StyledBlockquote, {
|
|
58
|
+
data: data
|
|
59
|
+
}),
|
|
59
60
|
onClick: () => {
|
|
60
|
-
// call `onEditStart` prop as we are trying to update the blockquote entity
|
|
61
61
|
onEditStart();
|
|
62
|
-
// open `BlockquoteInput`
|
|
63
62
|
setIsInputOpen(true);
|
|
64
63
|
}
|
|
65
|
-
}
|
|
66
|
-
className: "fa-solid fa-pen"
|
|
67
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
|
|
64
|
+
}));
|
|
68
65
|
}
|
|
@@ -66,16 +66,13 @@ function EditableEmbeddedCode(props) {
|
|
|
66
66
|
},
|
|
67
67
|
onConfirm: onInputChange,
|
|
68
68
|
inputValue: data
|
|
69
|
-
}), /*#__PURE__*/_react.default.createElement(EditableBlock,
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
}), /*#__PURE__*/_react.default.createElement(EditableBlock, {
|
|
70
|
+
component: /*#__PURE__*/_react.default.createElement(StyledEmbeddedCode, {
|
|
71
|
+
embeddedCode: data === null || data === void 0 ? void 0 : data.embeddedCode
|
|
72
|
+
}),
|
|
72
73
|
onClick: () => {
|
|
73
|
-
// call `onEditStart` prop as we are trying to update the blockquote entity
|
|
74
74
|
onEditStart();
|
|
75
|
-
// open `BlockquoteInput`
|
|
76
75
|
setIsInputOpen(true);
|
|
77
76
|
}
|
|
78
|
-
}
|
|
79
|
-
className: "fa-solid fa-pen"
|
|
80
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
|
|
77
|
+
}));
|
|
81
78
|
}
|
|
@@ -63,16 +63,13 @@ function EditableImage(props) {
|
|
|
63
63
|
enableAlignment: true,
|
|
64
64
|
alignment: data.alignment,
|
|
65
65
|
selected: [imageWithMeta]
|
|
66
|
-
}), /*#__PURE__*/_react.default.createElement(EditableBlock,
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
}), /*#__PURE__*/_react.default.createElement(EditableBlock, {
|
|
67
|
+
component: /*#__PURE__*/_react.default.createElement(StyledImage, {
|
|
68
|
+
data: data
|
|
69
|
+
}),
|
|
69
70
|
onClick: () => {
|
|
70
|
-
// call `onEditStart` prop as we are trying to update the blockquote entity
|
|
71
71
|
onEditStart();
|
|
72
|
-
// open `BlockquoteInput`
|
|
73
72
|
setIsSelectorOpen(true);
|
|
74
73
|
}
|
|
75
|
-
}
|
|
76
|
-
className: "fa-solid fa-pen"
|
|
77
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
|
|
74
|
+
}));
|
|
78
75
|
}
|
|
@@ -57,16 +57,13 @@ function EditableInfoBox(props) {
|
|
|
57
57
|
inputValue: data,
|
|
58
58
|
Editor: Editor,
|
|
59
59
|
decorator: decorator
|
|
60
|
-
}), /*#__PURE__*/_react.default.createElement(EditableBlock,
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
}), /*#__PURE__*/_react.default.createElement(EditableBlock, {
|
|
61
|
+
component: /*#__PURE__*/_react.default.createElement(StyledInfoBox, {
|
|
62
|
+
data: data
|
|
63
|
+
}),
|
|
63
64
|
onClick: () => {
|
|
64
|
-
// call `onEditStart` prop as we are trying to update the blockquote entity
|
|
65
65
|
onEditStart();
|
|
66
|
-
// open `BlockquoteInput`
|
|
67
66
|
setIsInputOpen(true);
|
|
68
67
|
}
|
|
69
|
-
}
|
|
70
|
-
className: "fa-solid fa-pen"
|
|
71
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
|
|
68
|
+
}));
|
|
72
69
|
}
|
|
@@ -60,16 +60,13 @@ function EditableSlideshow(props) {
|
|
|
60
60
|
enableMultiSelect: true,
|
|
61
61
|
alignment: data.alignment,
|
|
62
62
|
selected: data.images
|
|
63
|
-
}), /*#__PURE__*/_react.default.createElement(EditableBlock,
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
}), /*#__PURE__*/_react.default.createElement(EditableBlock, {
|
|
64
|
+
component: /*#__PURE__*/_react.default.createElement(StyledSlideshow, {
|
|
65
|
+
data: data
|
|
66
|
+
}),
|
|
66
67
|
onClick: () => {
|
|
67
|
-
// call `onEditStart` prop as we are trying to update the blockquote entity
|
|
68
68
|
onEditStart();
|
|
69
|
-
// open `BlockquoteInput`
|
|
70
69
|
setIsSelectorOpen(true);
|
|
71
70
|
}
|
|
72
|
-
}
|
|
73
|
-
className: "fa-solid fa-pen"
|
|
74
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
|
|
71
|
+
}));
|
|
75
72
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.EditableBlock =
|
|
6
|
+
exports.EditableBlock = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
8
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
const EditButton = _styledComponents.default.div`
|
|
@@ -14,8 +15,7 @@ const EditButton = _styledComponents.default.div`
|
|
|
14
15
|
left: 50%;
|
|
15
16
|
transform: translate(-50%, -50%);
|
|
16
17
|
`;
|
|
17
|
-
|
|
18
|
-
const EditableBlock = _styledComponents.default.div`
|
|
18
|
+
const _EditableBlock = _styledComponents.default.div`
|
|
19
19
|
position: relative;
|
|
20
20
|
|
|
21
21
|
&:hover {
|
|
@@ -25,4 +25,11 @@ const EditableBlock = _styledComponents.default.div`
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
`;
|
|
28
|
+
const EditableBlock = props => {
|
|
29
|
+
return /*#__PURE__*/_react.default.createElement(_EditableBlock, null, props.component, /*#__PURE__*/_react.default.createElement(EditButton, {
|
|
30
|
+
onClick: props.onClick
|
|
31
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
32
|
+
className: "fa-solid fa-pen"
|
|
33
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify")));
|
|
34
|
+
};
|
|
28
35
|
exports.EditableBlock = EditableBlock;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AnchorButton = 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 AnchorButton = 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.ANCHOR_ENTITY_TYPE, '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.AnchorButton = AnchorButton;
|
|
@@ -11,7 +11,7 @@ var _modals = require("@keystone-ui/modals");
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
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];
|
|
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
15
|
function createAnnotationButton({
|
|
16
16
|
InnerEditor,
|
|
17
17
|
decorator
|
package/lib/buttons/bt-names.js
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buttonStyle = exports.InlineStyleControls = exports.BlockStyleControls = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const buttonStyle = (0, _styledComponents.css)`
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
border-radius: 6px;
|
|
15
|
+
text-align: center;
|
|
16
|
+
font-size: 1rem;
|
|
17
|
+
padding: 0 12px;
|
|
18
|
+
margin: ${props => props.isDisabled ? '0' : '0 0 10px 0'};
|
|
19
|
+
background-color: #fff;
|
|
20
|
+
border: solid 1px rgb(193, 199, 208);
|
|
21
|
+
align-items: center;
|
|
22
|
+
height: 40px;
|
|
23
|
+
|
|
24
|
+
cursor: ${props => props.readOnly ? 'not-allowed' : 'pointer'};
|
|
25
|
+
color: ${props => {
|
|
26
|
+
if (props.readOnly) {
|
|
27
|
+
return '#c1c7d0';
|
|
28
|
+
}
|
|
29
|
+
if (props.isActive) {
|
|
30
|
+
return '#3b82f6';
|
|
31
|
+
}
|
|
32
|
+
return '#6b7280';
|
|
33
|
+
}};
|
|
34
|
+
border: solid 1px
|
|
35
|
+
${props => {
|
|
36
|
+
if (props.readOnly) {
|
|
37
|
+
return '#c1c7d0';
|
|
38
|
+
}
|
|
39
|
+
if (props.isActive) {
|
|
40
|
+
return '#3b82f6';
|
|
41
|
+
}
|
|
42
|
+
return '#6b7280';
|
|
43
|
+
}};
|
|
44
|
+
box-shadow: ${props => {
|
|
45
|
+
if (props.readOnly) {
|
|
46
|
+
return 'unset';
|
|
47
|
+
}
|
|
48
|
+
if (props.isActive) {
|
|
49
|
+
return 'rgba(38, 132, 255, 20%) 0px 1px 4px ';
|
|
50
|
+
}
|
|
51
|
+
return 'unset';
|
|
52
|
+
}};
|
|
53
|
+
transition: box-shadow 100ms linear;
|
|
54
|
+
|
|
55
|
+
display: ${props => {
|
|
56
|
+
if (props.isDisabled) {
|
|
57
|
+
return 'none';
|
|
58
|
+
}
|
|
59
|
+
return 'inline-flex';
|
|
60
|
+
}};
|
|
61
|
+
`;
|
|
62
|
+
exports.buttonStyle = buttonStyle;
|
|
63
|
+
const CustomButton = _styledComponents.default.div`
|
|
64
|
+
${buttonStyle}
|
|
65
|
+
`;
|
|
66
|
+
class StyleButton extends _react.default.Component {
|
|
67
|
+
onToggle = e => {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
this.props.onToggle(this.props.style);
|
|
70
|
+
};
|
|
71
|
+
render() {
|
|
72
|
+
return /*#__PURE__*/_react.default.createElement(CustomButton, {
|
|
73
|
+
isDisabled: this.props.isDisabled,
|
|
74
|
+
isActive: this.props.active,
|
|
75
|
+
onMouseDown: this.onToggle,
|
|
76
|
+
readOnly: this.props.readOnly
|
|
77
|
+
}, this.props.icon && /*#__PURE__*/_react.default.createElement("i", {
|
|
78
|
+
className: this.props.icon
|
|
79
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, !this.props.icon ? this.props.label : ''));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const blockStyles = [{
|
|
83
|
+
label: 'H2',
|
|
84
|
+
style: 'header-two',
|
|
85
|
+
icon: ''
|
|
86
|
+
}, {
|
|
87
|
+
label: 'H3',
|
|
88
|
+
style: 'header-three',
|
|
89
|
+
icon: ''
|
|
90
|
+
}, {
|
|
91
|
+
label: 'H4',
|
|
92
|
+
style: 'header-four',
|
|
93
|
+
icon: ''
|
|
94
|
+
}, {
|
|
95
|
+
label: 'H5',
|
|
96
|
+
style: 'header-five',
|
|
97
|
+
icon: ''
|
|
98
|
+
}, {
|
|
99
|
+
label: 'UL',
|
|
100
|
+
style: 'unordered-list-item',
|
|
101
|
+
icon: 'fas fa-list-ul'
|
|
102
|
+
}, {
|
|
103
|
+
label: 'OL',
|
|
104
|
+
style: 'ordered-list-item',
|
|
105
|
+
icon: 'fas fa-list-ol'
|
|
106
|
+
}, {
|
|
107
|
+
label: 'Code Block',
|
|
108
|
+
style: 'code-block',
|
|
109
|
+
icon: 'fas fa-code'
|
|
110
|
+
}];
|
|
111
|
+
const BlockStyleControls = props => {
|
|
112
|
+
const {
|
|
113
|
+
editorState,
|
|
114
|
+
disabledButtons
|
|
115
|
+
} = props;
|
|
116
|
+
const selection = editorState.getSelection();
|
|
117
|
+
const blockType = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
|
|
118
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, blockStyles.map(type => /*#__PURE__*/_react.default.createElement(StyleButton, {
|
|
119
|
+
isDisabled: disabledButtons.includes(type.style),
|
|
120
|
+
key: type.label,
|
|
121
|
+
active: type.style === blockType,
|
|
122
|
+
label: type.label,
|
|
123
|
+
onToggle: props.onToggle,
|
|
124
|
+
style: type.style,
|
|
125
|
+
icon: type.icon,
|
|
126
|
+
readOnly: props.readOnly
|
|
127
|
+
})));
|
|
128
|
+
};
|
|
129
|
+
exports.BlockStyleControls = BlockStyleControls;
|
|
130
|
+
const inlineStyles = [{
|
|
131
|
+
label: 'Bold',
|
|
132
|
+
style: 'BOLD',
|
|
133
|
+
icon: 'fas fa-bold'
|
|
134
|
+
}, {
|
|
135
|
+
label: 'Italic',
|
|
136
|
+
style: 'ITALIC',
|
|
137
|
+
icon: 'fas fa-italic'
|
|
138
|
+
}, {
|
|
139
|
+
label: 'Underline',
|
|
140
|
+
style: 'UNDERLINE',
|
|
141
|
+
icon: 'fas fa-underline'
|
|
142
|
+
}, {
|
|
143
|
+
label: 'Monospace',
|
|
144
|
+
style: 'CODE',
|
|
145
|
+
icon: 'fas fa-terminal'
|
|
146
|
+
}];
|
|
147
|
+
const InlineStyleControls = props => {
|
|
148
|
+
const currentStyle = props.editorState.getCurrentInlineStyle();
|
|
149
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, inlineStyles.map(type => /*#__PURE__*/_react.default.createElement(StyleButton, {
|
|
150
|
+
isDisabled: props.disabledButtons.includes(type.style.toLowerCase()),
|
|
151
|
+
key: type.label,
|
|
152
|
+
active: currentStyle.has(type.style),
|
|
153
|
+
label: type.label,
|
|
154
|
+
onToggle: props.onToggle,
|
|
155
|
+
style: type.style,
|
|
156
|
+
icon: type.icon,
|
|
157
|
+
readOnly: props.readOnly
|
|
158
|
+
})));
|
|
159
|
+
};
|
|
160
|
+
exports.InlineStyleControls = InlineStyleControls;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
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;
|
|
7
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
var _controlButtons = require("./control-buttons");
|
|
9
|
+
var _bgColor = require("./bg-color");
|
|
10
|
+
var _blockquote = require("./blockquote");
|
|
11
|
+
var _divider = require("./divider");
|
|
12
|
+
var _embeddedCode = require("./embedded-code");
|
|
13
|
+
var _enlarge = require("./enlarge");
|
|
14
|
+
var _fontColor = require("./font-color");
|
|
15
|
+
var _image = require("./image");
|
|
16
|
+
var _anchor = require("./anchor");
|
|
17
|
+
var _link = require("./link");
|
|
18
|
+
var _slideshow = require("./slideshow");
|
|
19
|
+
var _newsReading = require("./news-reading");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
const withStyle = Button => {
|
|
22
|
+
return (0, _styledComponents.default)(Button)`
|
|
23
|
+
${_controlButtons.buttonStyle}
|
|
24
|
+
`;
|
|
25
|
+
};
|
|
26
|
+
exports.withStyle = withStyle;
|
|
27
|
+
const BlockStyleControls = _controlButtons.BlockStyleControls;
|
|
28
|
+
exports.BlockStyleControls = BlockStyleControls;
|
|
29
|
+
const InlineStyleControls = _controlButtons.InlineStyleControls;
|
|
30
|
+
exports.InlineStyleControls = InlineStyleControls;
|
|
31
|
+
const CustomBlockquoteButton = withStyle(_blockquote.BlockquoteButton);
|
|
32
|
+
exports.CustomBlockquoteButton = CustomBlockquoteButton;
|
|
33
|
+
const CustomAnchorButton = withStyle(_anchor.AnchorButton);
|
|
34
|
+
exports.CustomAnchorButton = CustomAnchorButton;
|
|
35
|
+
const CustomLinkButton = withStyle(_link.LinkButton);
|
|
36
|
+
exports.CustomLinkButton = CustomLinkButton;
|
|
37
|
+
const CustomEnlargeButton = (0, _styledComponents.default)(withStyle(_enlarge.EnlargeButton))`
|
|
38
|
+
color: #999;
|
|
39
|
+
`;
|
|
40
|
+
exports.CustomEnlargeButton = CustomEnlargeButton;
|
|
41
|
+
const CustomImageButton = withStyle(_image.ImageButton);
|
|
42
|
+
exports.CustomImageButton = CustomImageButton;
|
|
43
|
+
const CustomSlideshowButton = withStyle(_slideshow.SlideshowButton);
|
|
44
|
+
exports.CustomSlideshowButton = CustomSlideshowButton;
|
|
45
|
+
const CustomEmbeddedCodeButton = withStyle(_embeddedCode.EmbeddedCodeButton);
|
|
46
|
+
exports.CustomEmbeddedCodeButton = CustomEmbeddedCodeButton;
|
|
47
|
+
const CustomNewsReadingButton = withStyle(_newsReading.NewsReadingButton);
|
|
48
|
+
exports.CustomNewsReadingButton = CustomNewsReadingButton;
|
|
49
|
+
const CustomBackgroundColorButton = withStyle(_bgColor.BackgroundColorButton);
|
|
50
|
+
exports.CustomBackgroundColorButton = CustomBackgroundColorButton;
|
|
51
|
+
const CustomFontColorButton = withStyle(_fontColor.FontColorButton);
|
|
52
|
+
exports.CustomFontColorButton = CustomFontColorButton;
|
|
53
|
+
const CustomDividerButton = withStyle(_divider.DividerButton);
|
|
54
|
+
exports.CustomDividerButton = CustomDividerButton;
|
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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
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];
|
|
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];
|
|
17
17
|
var InfoBoxTypeEnum = /*#__PURE__*/function (InfoBoxTypeEnum) {
|
|
18
18
|
InfoBoxTypeEnum["newsChargeStation"] = "news-charge-station";
|
|
19
19
|
InfoBoxTypeEnum["headerBorder"] = "header-border";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InnerAnchorButton = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
// import { ANCHOR_ENTITY_TYPE } from '@kids-reporter/draft-renderer'
|
|
11
|
+
|
|
12
|
+
const InnerAnchorButton = props => {
|
|
13
|
+
const toggleEntity = _draftJs.RichUtils.toggleLink;
|
|
14
|
+
const {
|
|
15
|
+
isActive,
|
|
16
|
+
editorState,
|
|
17
|
+
onChange
|
|
18
|
+
} = props;
|
|
19
|
+
const promptForAnchor = e => {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
const selection = editorState.getSelection();
|
|
22
|
+
if (!selection.isCollapsed()) {
|
|
23
|
+
const contentState = editorState.getCurrentContent();
|
|
24
|
+
const startKey = selection.getStartKey();
|
|
25
|
+
const block = contentState.getBlockForKey(startKey);
|
|
26
|
+
const start = selection.getStartOffset();
|
|
27
|
+
const end = selection.getEndOffset();
|
|
28
|
+
const selectedText = block.getText().slice(start, end);
|
|
29
|
+
const contentStateWithEntity = contentState.createEntity('ANCHOR',
|
|
30
|
+
// TODO: ANCHOR_ENTITY_TYPE
|
|
31
|
+
'MUTABLE', {
|
|
32
|
+
anchorID: selectedText
|
|
33
|
+
});
|
|
34
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
35
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
36
|
+
currentContent: contentStateWithEntity
|
|
37
|
+
});
|
|
38
|
+
onChange(toggleEntity(newEditorState, newEditorState.getSelection(), entityKey));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const removeAnchor = () => {
|
|
42
|
+
const selection = editorState.getSelection();
|
|
43
|
+
if (!selection.isCollapsed()) {
|
|
44
|
+
onChange(toggleEntity(editorState, selection, null));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
48
|
+
className: props.className,
|
|
49
|
+
onMouseDown: isActive ? removeAnchor : promptForAnchor,
|
|
50
|
+
title: "\u9328\u9EDE"
|
|
51
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, "\u9328"));
|
|
52
|
+
};
|
|
53
|
+
exports.InnerAnchorButton = InnerAnchorButton;
|