@kids-reporter/draft-editor 1.0.2 → 1.0.4
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 +7 -10
- package/lib/block-renderers/embedded-code.js +7 -10
- package/lib/block-renderers/image.js +7 -10
- package/lib/block-renderers/info-box.js +7 -10
- package/lib/block-renderers/slideshow.js +7 -10
- package/lib/block-renderers/styled.js +10 -3
- package/lib/buttons/anchor.js +51 -0
- package/lib/buttons/annotation.js +3 -3
- package/lib/buttons/bg-color.js +3 -4
- package/lib/buttons/blockquote.js +2 -2
- package/lib/buttons/bt-names.js +4 -4
- package/lib/buttons/control-buttons.js +159 -0
- package/lib/buttons/embedded-code.js +45 -3
- package/lib/buttons/font-color.js +3 -4
- package/lib/buttons/image.js +2 -2
- package/lib/buttons/index.js +41 -0
- package/lib/buttons/info-box.js +3 -3
- package/lib/buttons/link.js +2 -2
- package/lib/buttons/news-reading.js +2 -2
- package/lib/buttons/selector/align-selector.js +2 -2
- package/lib/buttons/selector/image-selector.js +2 -2
- package/lib/buttons/selector/search-box.js +2 -2
- package/lib/buttons/slideshow.js +2 -2
- package/lib/draft-editor.js +115 -457
- package/lib/entity-decorators/anchor.js +111 -0
- package/lib/index.js +2 -3
- package/lib/styled.js +98 -0
- package/package.json +2 -2
- package/lib/buttons/form/array-field.js +0 -30
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.editableAnchorDecorator = 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 EditableAnchor = 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 editableAnchorDecorator = exports.editableAnchorDecorator = {
|
|
109
|
+
strategy: _draftRenderer.findAnchorEntities,
|
|
110
|
+
component: EditableAnchor
|
|
111
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -25,9 +25,8 @@ exports.default = void 0;
|
|
|
25
25
|
var _draftEditor = require("./draft-editor");
|
|
26
26
|
var _btNames = _interopRequireDefault(require("./buttons/bt-names"));
|
|
27
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
-
var _default = {
|
|
28
|
+
var _default = exports.default = {
|
|
29
29
|
RichTextEditor: _draftEditor.RichTextEditor,
|
|
30
30
|
buttonNames: _btNames.default,
|
|
31
31
|
decorator: _draftEditor.decorator
|
|
32
|
-
};
|
|
33
|
-
exports.default = _default;
|
|
32
|
+
};
|
package/lib/styled.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TextEditorWrapper = exports.EnlargeButtonWrapper = exports.DraftEditorWrapper = exports.DraftEditorControlsWrapper = exports.DraftEditorControls = exports.DraftEditorContainer = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
10
|
+
const DraftEditorWrapper = exports.DraftEditorWrapper = _styledComponents.default.div`
|
|
11
|
+
/* Rich-editor default setting (.RichEditor-root)*/
|
|
12
|
+
background: #fff;
|
|
13
|
+
border: 1px solid #ddd;
|
|
14
|
+
font-family: 'Georgia', serif;
|
|
15
|
+
font-size: 14px;
|
|
16
|
+
padding: 15px;
|
|
17
|
+
|
|
18
|
+
/* Custom setting */
|
|
19
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
20
|
+
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
|
|
21
|
+
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
background: rgb(255, 255, 255);
|
|
25
|
+
border-radius: 6px;
|
|
26
|
+
padding: 0 1rem 1rem;
|
|
27
|
+
`;
|
|
28
|
+
const DraftEditorControls = exports.DraftEditorControls = _styledComponents.default.div`
|
|
29
|
+
padding-top: 1rem;
|
|
30
|
+
width: 100%;
|
|
31
|
+
background: rgb(255, 255, 255);
|
|
32
|
+
`;
|
|
33
|
+
const DraftEditorControlsWrapper = exports.DraftEditorControlsWrapper = _styledComponents.default.div`
|
|
34
|
+
width: 100%;
|
|
35
|
+
position: relative;
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: row;
|
|
38
|
+
flex-wrap: wrap;
|
|
39
|
+
padding-right: 45px;
|
|
40
|
+
gap: 2px;
|
|
41
|
+
`;
|
|
42
|
+
const TextEditorWrapper = exports.TextEditorWrapper = _styledComponents.default.div`
|
|
43
|
+
/* Rich-editor default setting (.RichEditor-editor)*/
|
|
44
|
+
border-top: 1px solid #ddd;
|
|
45
|
+
cursor: text;
|
|
46
|
+
font-size: 16px;
|
|
47
|
+
margin-top: 10px;
|
|
48
|
+
`;
|
|
49
|
+
const DraftEditorContainer = exports.DraftEditorContainer = _styledComponents.default.div`
|
|
50
|
+
overflow-x: hidden;
|
|
51
|
+
position: relative;
|
|
52
|
+
margin-top: 4px;
|
|
53
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
54
|
+
position: fixed;
|
|
55
|
+
width: 100%;
|
|
56
|
+
height: 100%;
|
|
57
|
+
top: 0;
|
|
58
|
+
left: 0;
|
|
59
|
+
z-index: 30;
|
|
60
|
+
padding-left: 3em;
|
|
61
|
+
padding-right: 3em;
|
|
62
|
+
background: rgba(0, 0, 0, 0.5);
|
|
63
|
+
` : ''}
|
|
64
|
+
${DraftEditorWrapper} {
|
|
65
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
66
|
+
width: 100%;
|
|
67
|
+
height: 100%;
|
|
68
|
+
padding: 0 1rem 0;
|
|
69
|
+
overflow: scroll;
|
|
70
|
+
` : ''}
|
|
71
|
+
}
|
|
72
|
+
${DraftEditorControls} {
|
|
73
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
74
|
+
position: sticky;
|
|
75
|
+
top: 0;
|
|
76
|
+
z-index: 12;
|
|
77
|
+
` : ''}
|
|
78
|
+
}
|
|
79
|
+
${DraftEditorControlsWrapper} {
|
|
80
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
81
|
+
overflow: auto;
|
|
82
|
+
padding-bottom: 0;
|
|
83
|
+
` : ''}
|
|
84
|
+
}
|
|
85
|
+
${TextEditorWrapper} {
|
|
86
|
+
${props => props.isEnlarged ? (0, _styledComponents.css)`
|
|
87
|
+
max-width: 100%;
|
|
88
|
+
min-height: 100vh;
|
|
89
|
+
padding-bottom: 0;
|
|
90
|
+
` : ''}
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
const EnlargeButtonWrapper = exports.EnlargeButtonWrapper = _styledComponents.default.div`
|
|
94
|
+
position: absolute;
|
|
95
|
+
top: 0;
|
|
96
|
+
right: 0;
|
|
97
|
+
margin: 0;
|
|
98
|
+
`;
|
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.4",
|
|
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.4",
|
|
27
27
|
"@twreporter/errors": "^1.1.2",
|
|
28
28
|
"draft-js": "^0.11.7"
|
|
29
29
|
},
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ArrayField = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _button = require("@keystone-ui/button");
|
|
9
|
-
var _fields = require("@keystone-ui/fields");
|
|
10
|
-
var _PlusCircleIcon = require("@keystone-ui/icons/icons/PlusCircleIcon");
|
|
11
|
-
var _core = require("@keystone-ui/core");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
const ArrayField = function ({
|
|
14
|
-
label
|
|
15
|
-
}) {
|
|
16
|
-
return /*#__PURE__*/_react.default.createElement(_core.Stack, {
|
|
17
|
-
gap: "medium"
|
|
18
|
-
}, label && /*#__PURE__*/_react.default.createElement(_fields.FieldLabel, null, label), /*#__PURE__*/_react.default.createElement(_fields.TextInput, null), /*#__PURE__*/_react.default.createElement(_fields.TextInput, null), /*#__PURE__*/_react.default.createElement(_button.Button, {
|
|
19
|
-
onClick: () => {
|
|
20
|
-
//props.onChange([...props.elements.map(x => ({ key: x.key })), { key: undefined }]);
|
|
21
|
-
},
|
|
22
|
-
tone: "active"
|
|
23
|
-
}, /*#__PURE__*/_react.default.createElement(_core.Stack, {
|
|
24
|
-
gap: "small",
|
|
25
|
-
across: true
|
|
26
|
-
}, /*#__PURE__*/_react.default.createElement(_PlusCircleIcon.PlusCircleIcon, {
|
|
27
|
-
size: "smallish"
|
|
28
|
-
}), " ", /*#__PURE__*/_react.default.createElement("span", null, "Add"))));
|
|
29
|
-
};
|
|
30
|
-
exports.ArrayField = ArrayField;
|