@kids-reporter/draft-editor 0.4.27 → 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.
package/lib/block-renderer-fn.js
CHANGED
|
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.atomicBlockRenderer = atomicBlockRenderer;
|
|
7
7
|
var _blockquote = require("./block-renderers/blockquote");
|
|
8
|
-
var
|
|
8
|
+
var _embeddedCode = require("./block-renderers/embedded-code");
|
|
9
9
|
var _image = require("./block-renderers/image");
|
|
10
|
+
var _infoBox = require("./block-renderers/info-box");
|
|
10
11
|
var _slideshow = require("./block-renderers/slideshow");
|
|
11
12
|
var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
12
13
|
const {
|
|
13
14
|
Divider,
|
|
14
|
-
EmbeddedCodeInArticleBody,
|
|
15
15
|
NewsReading
|
|
16
16
|
} = _draftRenderer.blockRenderers;
|
|
17
17
|
const AtomicBlock = props => {
|
|
@@ -37,9 +37,7 @@ const AtomicBlock = props => {
|
|
|
37
37
|
}
|
|
38
38
|
case 'EMBEDDEDCODE':
|
|
39
39
|
{
|
|
40
|
-
return
|
|
41
|
-
data: entityData
|
|
42
|
-
});
|
|
40
|
+
return (0, _embeddedCode.EditableEmbeddedCode)(props);
|
|
43
41
|
}
|
|
44
42
|
case 'INFOBOX':
|
|
45
43
|
{
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EditableEmbeddedCode = EditableEmbeddedCode;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
|
+
var _embeddedCode = require("../buttons/embedded-code");
|
|
10
|
+
var _styled = require("./styled");
|
|
11
|
+
var _fields = require("@keystone-ui/fields");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
function EmbeddedCode({
|
|
16
|
+
className,
|
|
17
|
+
embeddedCode
|
|
18
|
+
}) {
|
|
19
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
20
|
+
className: className
|
|
21
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, "Embedded Code:"), /*#__PURE__*/_react.default.createElement(_fields.TextArea, {
|
|
22
|
+
disabled: true,
|
|
23
|
+
type: "text",
|
|
24
|
+
value: embeddedCode
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
const StyledEmbeddedCode = (0, _styledComponents.default)(EmbeddedCode)`
|
|
28
|
+
max-width: 700px;
|
|
29
|
+
margin: 0 auto 30px auto;
|
|
30
|
+
background-color: #fafbfc;
|
|
31
|
+
`;
|
|
32
|
+
const EditableBlock = (0, _styledComponents.default)(_styled.EditableBlock)`
|
|
33
|
+
&:hover {
|
|
34
|
+
${StyledEmbeddedCode} {
|
|
35
|
+
background-color: #f0f0f0;
|
|
36
|
+
opacity: 0.3;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
function EditableEmbeddedCode(props) {
|
|
40
|
+
const [isInputOpen, setIsInputOpen] = (0, _react.useState)(false);
|
|
41
|
+
const {
|
|
42
|
+
block,
|
|
43
|
+
blockProps,
|
|
44
|
+
contentState
|
|
45
|
+
} = props;
|
|
46
|
+
const {
|
|
47
|
+
onEditStart,
|
|
48
|
+
onEditFinish
|
|
49
|
+
} = blockProps;
|
|
50
|
+
const entityKey = block.getEntityAt(0);
|
|
51
|
+
const entity = contentState.getEntity(entityKey);
|
|
52
|
+
const data = entity.getData();
|
|
53
|
+
const onInputChange = inputValue => {
|
|
54
|
+
// close `EmbeddedCodeInput`
|
|
55
|
+
setIsInputOpen(false);
|
|
56
|
+
onEditFinish({
|
|
57
|
+
entityKey,
|
|
58
|
+
entityData: inputValue
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_embeddedCode.EmbeddedCodeInput, {
|
|
62
|
+
isOpen: isInputOpen,
|
|
63
|
+
onCancel: () => {
|
|
64
|
+
setIsInputOpen(false);
|
|
65
|
+
onEditFinish();
|
|
66
|
+
},
|
|
67
|
+
onConfirm: onInputChange,
|
|
68
|
+
inputValue: data
|
|
69
|
+
}), /*#__PURE__*/_react.default.createElement(EditableBlock, null, /*#__PURE__*/_react.default.createElement(StyledEmbeddedCode, {
|
|
70
|
+
embeddedCode: data === null || data === void 0 ? void 0 : data.embeddedCode
|
|
71
|
+
}), /*#__PURE__*/_react.default.createElement(_styled.EditButton, {
|
|
72
|
+
onClick: () => {
|
|
73
|
+
// call `onEditStart` prop as we are trying to update the blockquote entity
|
|
74
|
+
onEditStart();
|
|
75
|
+
// open `BlockquoteInput`
|
|
76
|
+
setIsInputOpen(true);
|
|
77
|
+
}
|
|
78
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
79
|
+
className: "fa-solid fa-pen"
|
|
80
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
|
|
81
|
+
}
|
|
@@ -4,49 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.EmbeddedCodeButton = EmbeddedCodeButton;
|
|
7
|
+
exports.EmbeddedCodeInput = EmbeddedCodeInput;
|
|
7
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
9
|
var _draftJs = require("draft-js");
|
|
9
10
|
var _modals = require("@keystone-ui/modals");
|
|
10
11
|
var _fields = require("@keystone-ui/fields");
|
|
11
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); }
|
|
12
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; }
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const [
|
|
20
|
-
const [inputValue, setInputValue] = (0, _react.useState)({
|
|
21
|
-
caption: '',
|
|
22
|
-
embeddedCode: ''
|
|
23
|
-
});
|
|
24
|
-
const promptForInput = () => {
|
|
25
|
-
setToShowInput(true);
|
|
26
|
-
setInputValue({
|
|
27
|
-
caption: '',
|
|
28
|
-
embeddedCode: ''
|
|
29
|
-
});
|
|
30
|
-
};
|
|
14
|
+
function EmbeddedCodeInput({
|
|
15
|
+
isOpen,
|
|
16
|
+
onConfirm,
|
|
17
|
+
onCancel,
|
|
18
|
+
inputValue
|
|
19
|
+
}) {
|
|
20
|
+
const [inputValueState, setInputValue] = (0, _react.useState)(inputValue);
|
|
31
21
|
const confirmInput = () => {
|
|
32
|
-
|
|
33
|
-
const contentStateWithEntity = contentState.createEntity('EMBEDDEDCODE', 'IMMUTABLE', inputValue);
|
|
34
|
-
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
35
|
-
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
36
|
-
currentContent: contentStateWithEntity
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// The third parameter here is a space string, not an empty string
|
|
40
|
-
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
41
|
-
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
42
|
-
setToShowInput(false);
|
|
43
|
-
setInputValue({
|
|
44
|
-
caption: '',
|
|
45
|
-
embeddedCode: ''
|
|
46
|
-
});
|
|
22
|
+
onConfirm(inputValueState);
|
|
47
23
|
};
|
|
48
|
-
|
|
49
|
-
isOpen:
|
|
24
|
+
return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
25
|
+
isOpen: isOpen
|
|
50
26
|
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
51
27
|
title: "\u9472\u5D4C\u7A0B\u5F0F\u78BC\uFF08Embedded Code\uFF09"
|
|
52
28
|
//isOpen={toShowInput}
|
|
@@ -54,9 +30,7 @@ function EmbeddedCodeButton(props) {
|
|
|
54
30
|
actions: {
|
|
55
31
|
cancel: {
|
|
56
32
|
label: 'Cancel',
|
|
57
|
-
action:
|
|
58
|
-
setToShowInput(false);
|
|
59
|
-
}
|
|
33
|
+
action: onCancel
|
|
60
34
|
},
|
|
61
35
|
confirm: {
|
|
62
36
|
label: 'Confirm',
|
|
@@ -65,29 +39,64 @@ function EmbeddedCodeButton(props) {
|
|
|
65
39
|
}
|
|
66
40
|
}, /*#__PURE__*/_react.default.createElement(_fields.TextArea, {
|
|
67
41
|
onChange: e => setInputValue({
|
|
68
|
-
caption:
|
|
42
|
+
caption: inputValueState.caption,
|
|
69
43
|
embeddedCode: e.target.value
|
|
70
44
|
}),
|
|
71
45
|
placeholder: "Embedded Code",
|
|
72
46
|
type: "text",
|
|
73
|
-
value:
|
|
47
|
+
value: inputValueState.embeddedCode,
|
|
74
48
|
style: {
|
|
75
49
|
marginBottom: '30px'
|
|
76
50
|
}
|
|
77
51
|
}), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
78
52
|
onChange: e => setInputValue({
|
|
79
53
|
caption: e.target.value,
|
|
80
|
-
embeddedCode:
|
|
54
|
+
embeddedCode: inputValueState.embeddedCode
|
|
81
55
|
}),
|
|
82
56
|
type: "text",
|
|
83
57
|
placeholder: "Caption",
|
|
84
|
-
value:
|
|
58
|
+
value: inputValueState.caption,
|
|
85
59
|
style: {
|
|
86
60
|
marginBottom: '10px',
|
|
87
61
|
marginTop: '30px'
|
|
88
62
|
}
|
|
89
63
|
})));
|
|
90
|
-
|
|
64
|
+
}
|
|
65
|
+
function EmbeddedCodeButton(props) {
|
|
66
|
+
const {
|
|
67
|
+
editorState,
|
|
68
|
+
onChange,
|
|
69
|
+
className
|
|
70
|
+
} = props;
|
|
71
|
+
const [isInputOpen, setIsInputOpen] = (0, _react.useState)(false);
|
|
72
|
+
const promptForInput = () => {
|
|
73
|
+
setIsInputOpen(true);
|
|
74
|
+
};
|
|
75
|
+
const onInputChange = inputValue => {
|
|
76
|
+
const contentState = editorState.getCurrentContent();
|
|
77
|
+
const contentStateWithEntity = contentState.createEntity('EMBEDDEDCODE', 'IMMUTABLE', inputValue);
|
|
78
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
79
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
80
|
+
currentContent: contentStateWithEntity
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// The third parameter here is a space string, not an empty string
|
|
84
|
+
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
85
|
+
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
86
|
+
setIsInputOpen(false);
|
|
87
|
+
};
|
|
88
|
+
const onInputCancel = () => {
|
|
89
|
+
setIsInputOpen(false);
|
|
90
|
+
};
|
|
91
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isInputOpen && /*#__PURE__*/_react.default.createElement(EmbeddedCodeInput, {
|
|
92
|
+
isOpen: isInputOpen,
|
|
93
|
+
onConfirm: onInputChange,
|
|
94
|
+
onCancel: onInputCancel,
|
|
95
|
+
inputValue: {
|
|
96
|
+
caption: '',
|
|
97
|
+
embeddedCode: ''
|
|
98
|
+
}
|
|
99
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
91
100
|
onClick: () => {
|
|
92
101
|
promptForInput();
|
|
93
102
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kids-reporter/draft-editor",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.29",
|
|
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": "^0.4.
|
|
26
|
+
"@kids-reporter/draft-renderer": "^0.4.29",
|
|
27
27
|
"@twreporter/errors": "^1.1.2",
|
|
28
28
|
"draft-js": "^0.11.7"
|
|
29
29
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|