@kids-reporter/draft-editor 0.1.0
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/README.md +51 -0
- package/lib/.selector/align-selector.js +71 -0
- package/lib/.selector/audio-selector.js +268 -0
- package/lib/.selector/image-selector.js +430 -0
- package/lib/.selector/pagination.js +82 -0
- package/lib/.selector/post-selector.js +311 -0
- package/lib/.selector/search-box.js +46 -0
- package/lib/.selector/video-selector.js +285 -0
- package/lib/block-renderer/background-image-block.js +141 -0
- package/lib/block-renderer/background-video-block.js +151 -0
- package/lib/block-renderer/color-box-block.js +86 -0
- package/lib/block-renderer/info-box-block.js +86 -0
- package/lib/block-renderer/side-index-block.js +90 -0
- package/lib/block-renderer/table-block.js +408 -0
- package/lib/block-renderer-fn.js +131 -0
- package/lib/buttons/annotation.js +117 -0
- package/lib/buttons/audio.js +65 -0
- package/lib/buttons/background-color.js +122 -0
- package/lib/buttons/background-image.js +223 -0
- package/lib/buttons/background-video.js +223 -0
- package/lib/buttons/color-box.js +173 -0
- package/lib/buttons/divider.js +63 -0
- package/lib/buttons/embedded-code.js +109 -0
- package/lib/buttons/enlarge.js +24 -0
- package/lib/buttons/font-color.js +115 -0
- package/lib/buttons/image.js +70 -0
- package/lib/buttons/info-box.js +148 -0
- package/lib/buttons/link.js +107 -0
- package/lib/buttons/media.js +121 -0
- package/lib/buttons/related-post.js +71 -0
- package/lib/buttons/selector/align-selector.js +71 -0
- package/lib/buttons/selector/audio-selector.js +279 -0
- package/lib/buttons/selector/image-selector.js +417 -0
- package/lib/buttons/selector/pagination.js +82 -0
- package/lib/buttons/selector/post-selector.js +317 -0
- package/lib/buttons/selector/search-box.js +46 -0
- package/lib/buttons/selector/video-selector.js +281 -0
- package/lib/buttons/side-index.js +200 -0
- package/lib/buttons/slideshow.js +71 -0
- package/lib/buttons/table.js +67 -0
- package/lib/buttons/text-align.js +88 -0
- package/lib/buttons/video.js +65 -0
- package/lib/buttons/youtube.js +147 -0
- package/lib/const.js +18 -0
- package/lib/draft-converter/api-data-instance.js +58 -0
- package/lib/draft-converter/atomic-block-processor.js +233 -0
- package/lib/draft-converter/entities.js +76 -0
- package/lib/draft-converter/index.js +201 -0
- package/lib/draft-converter/inline-styles-processor.js +236 -0
- package/lib/draft-editor.js +918 -0
- package/lib/entity-decorator.js +20 -0
- package/lib/index.js +15 -0
- package/lib/modifier.js +68 -0
- package/lib/theme/index.js +39 -0
- package/package.json +41 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ColorBoxButton = ColorBoxButton;
|
|
7
|
+
exports.ColorBoxInput = ColorBoxInput;
|
|
8
|
+
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
|
|
11
|
+
var _draftJs = require("draft-js");
|
|
12
|
+
|
|
13
|
+
var _modals = require("@keystone-ui/modals");
|
|
14
|
+
|
|
15
|
+
var _fields = require("@keystone-ui/fields");
|
|
16
|
+
|
|
17
|
+
var _draftConverter = _interopRequireDefault(require("../draft-converter"));
|
|
18
|
+
|
|
19
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
20
|
+
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
|
|
23
|
+
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); }
|
|
24
|
+
|
|
25
|
+
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; }
|
|
26
|
+
|
|
27
|
+
const Label = _styledComponents.default.label`
|
|
28
|
+
display: block;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
margin: 10px 0;
|
|
31
|
+
`;
|
|
32
|
+
const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
33
|
+
margin-bottom: 10px;
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
function ColorBoxInput(props) {
|
|
37
|
+
const {
|
|
38
|
+
isOpen,
|
|
39
|
+
onChange,
|
|
40
|
+
onCancel,
|
|
41
|
+
color,
|
|
42
|
+
rawContentStateForColorBoxEditor,
|
|
43
|
+
renderBasicEditor,
|
|
44
|
+
decorators
|
|
45
|
+
} = props;
|
|
46
|
+
const rawContentState = rawContentStateForColorBoxEditor || {
|
|
47
|
+
blocks: [],
|
|
48
|
+
entityMap: {}
|
|
49
|
+
};
|
|
50
|
+
const initialInputValue = {
|
|
51
|
+
color: color || '',
|
|
52
|
+
// create an `editorState` from raw content state object
|
|
53
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
|
|
54
|
+
};
|
|
55
|
+
const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
|
|
56
|
+
|
|
57
|
+
const clearInputValue = () => {
|
|
58
|
+
setInputValue({
|
|
59
|
+
color: '',
|
|
60
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
|
|
61
|
+
blocks: [],
|
|
62
|
+
entityMap: {}
|
|
63
|
+
}), decorators)
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
(0, _react.useEffect)(() => {
|
|
68
|
+
if (isOpen) {
|
|
69
|
+
setInputValue(initialInputValue);
|
|
70
|
+
}
|
|
71
|
+
}, [isOpen]);
|
|
72
|
+
const basicEditorJsx = renderBasicEditor({
|
|
73
|
+
editorState: inputValue.editorStateOfBasicEditor,
|
|
74
|
+
onChange: editorStateOfBasicEditor => {
|
|
75
|
+
setInputValue({
|
|
76
|
+
color: inputValue.color,
|
|
77
|
+
editorStateOfBasicEditor
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
82
|
+
isOpen: isOpen
|
|
83
|
+
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
84
|
+
title: `Insert Color Box`,
|
|
85
|
+
actions: {
|
|
86
|
+
cancel: {
|
|
87
|
+
label: 'Cancel',
|
|
88
|
+
action: () => {
|
|
89
|
+
clearInputValue();
|
|
90
|
+
onCancel();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
confirm: {
|
|
94
|
+
label: 'Confirm',
|
|
95
|
+
action: () => {
|
|
96
|
+
onChange({
|
|
97
|
+
color: inputValue.color,
|
|
98
|
+
// convert `contentState` of the `editorState` into raw content state object
|
|
99
|
+
rawContentState: (0, _draftJs.convertToRaw)(inputValue.editorStateOfBasicEditor.getCurrentContent())
|
|
100
|
+
});
|
|
101
|
+
clearInputValue();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, /*#__PURE__*/_react.default.createElement(Label, null, "Hex Color Code (#ffffff)"), /*#__PURE__*/_react.default.createElement(ColorHexInput, {
|
|
106
|
+
onChange: e => setInputValue({
|
|
107
|
+
color: e.target.value,
|
|
108
|
+
editorStateOfBasicEditor: inputValue.editorStateOfBasicEditor
|
|
109
|
+
}),
|
|
110
|
+
type: "text",
|
|
111
|
+
placeholder: "Color",
|
|
112
|
+
value: inputValue.color
|
|
113
|
+
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function ColorBoxButton(props) {
|
|
117
|
+
const [toShowInput, setToShowInput] = (0, _react.useState)(false);
|
|
118
|
+
const {
|
|
119
|
+
className,
|
|
120
|
+
editorState,
|
|
121
|
+
onChange: onEditorStateChange,
|
|
122
|
+
renderBasicEditor
|
|
123
|
+
} = props;
|
|
124
|
+
|
|
125
|
+
const onChange = ({
|
|
126
|
+
color,
|
|
127
|
+
rawContentState
|
|
128
|
+
}) => {
|
|
129
|
+
const contentState = editorState.getCurrentContent(); // create an ColorBox entity
|
|
130
|
+
|
|
131
|
+
const contentStateWithEntity = contentState.createEntity('COLORBOX', 'IMMUTABLE', {
|
|
132
|
+
color,
|
|
133
|
+
rawContentState,
|
|
134
|
+
body: _draftConverter.default.convertToHtml(rawContentState)
|
|
135
|
+
});
|
|
136
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
137
|
+
|
|
138
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
139
|
+
currentContent: contentStateWithEntity
|
|
140
|
+
}); //The third parameter here is a space string, not an empty string
|
|
141
|
+
//If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
145
|
+
setToShowInput(false);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ColorBoxInput, {
|
|
149
|
+
renderBasicEditor: renderBasicEditor,
|
|
150
|
+
onChange: onChange,
|
|
151
|
+
onCancel: () => {
|
|
152
|
+
setToShowInput(false);
|
|
153
|
+
},
|
|
154
|
+
isOpen: toShowInput
|
|
155
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
156
|
+
className: className,
|
|
157
|
+
onClick: () => {
|
|
158
|
+
setToShowInput(true);
|
|
159
|
+
}
|
|
160
|
+
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
161
|
+
width: "16",
|
|
162
|
+
height: "16",
|
|
163
|
+
viewBox: "0 0 16 16",
|
|
164
|
+
fill: "none",
|
|
165
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
166
|
+
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
167
|
+
d: "M14 0H2C0.895431 0 0 0.895431 0 2V14C0 15.1046 0.895431 16 2 16H14C15.1046 16 16 15.1046 16 14V2C16 0.895431 15.1046 0 14 0Z",
|
|
168
|
+
fill: "#6b7280"
|
|
169
|
+
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
170
|
+
d: "M12.3867 2.66667H3.61332C3.36225 2.66667 3.12146 2.76641 2.94393 2.94394C2.76639 3.12148 2.66666 3.36227 2.66666 3.61334V5.51112C2.68312 5.75156 2.79025 5.97678 2.96639 6.14127C3.14253 6.30576 3.37454 6.39725 3.61555 6.39725C3.85655 6.39725 4.08856 6.30576 4.2647 6.14127C4.44084 5.97678 4.54797 5.75156 4.56443 5.51112V4.56445H6.94221V11.4356H5.99555C5.86547 11.4267 5.73496 11.4446 5.61211 11.4882C5.48926 11.5319 5.3767 11.6003 5.28141 11.6893C5.18612 11.7783 5.11015 11.8859 5.0582 12.0055C5.00626 12.1251 4.97946 12.2541 4.97946 12.3844C4.97946 12.5148 5.00626 12.6438 5.0582 12.7634C5.11015 12.883 5.18612 12.9906 5.28141 13.0796C5.3767 13.1686 5.48926 13.237 5.61211 13.2807C5.73496 13.3243 5.86547 13.3422 5.99555 13.3333H9.78666C10.0271 13.3169 10.2523 13.2097 10.4168 13.0336C10.5813 12.8575 10.6728 12.6255 10.6728 12.3844C10.6728 12.1434 10.5813 11.9114 10.4168 11.7353C10.2523 11.5592 10.0271 11.452 9.78666 11.4356H8.83999V4.56445H11.4355V5.51112C11.452 5.75156 11.5591 5.97678 11.7353 6.14127C11.9114 6.30576 12.1434 6.39725 12.3844 6.39725C12.6254 6.39725 12.8575 6.30576 13.0336 6.14127C13.2097 5.97678 13.3169 5.75156 13.3333 5.51112V3.61334C13.3333 3.36227 13.2336 3.12148 13.0561 2.94394C12.8785 2.76641 12.6377 2.66667 12.3867 2.66667Z",
|
|
171
|
+
fill: "white"
|
|
172
|
+
})), /*#__PURE__*/_react.default.createElement("span", null, " ColorBox")));
|
|
173
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DividerButton = DividerButton;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _draftJs = require("draft-js");
|
|
11
|
+
|
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const IconWrapper = _styledComponents.default.span`
|
|
17
|
+
display: inline-block;
|
|
18
|
+
position: relative;
|
|
19
|
+
top: 2px;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
function DividerButton(props) {
|
|
23
|
+
const {
|
|
24
|
+
editorState,
|
|
25
|
+
onChange,
|
|
26
|
+
className
|
|
27
|
+
} = props;
|
|
28
|
+
|
|
29
|
+
const onClick = () => {
|
|
30
|
+
const contentState = editorState.getCurrentContent();
|
|
31
|
+
const contentStateWithEntity = contentState.createEntity('DIVIDER', 'IMMUTABLE', {});
|
|
32
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
33
|
+
|
|
34
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
35
|
+
currentContent: contentStateWithEntity
|
|
36
|
+
}); // The third parameter here is a space string, not an empty string
|
|
37
|
+
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
44
|
+
onClick: onClick,
|
|
45
|
+
className: className
|
|
46
|
+
}, /*#__PURE__*/_react.default.createElement(IconWrapper, null, /*#__PURE__*/_react.default.createElement("svg", {
|
|
47
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
48
|
+
height: "16",
|
|
49
|
+
viewBox: "0 0 16 16",
|
|
50
|
+
width: "16"
|
|
51
|
+
}, /*#__PURE__*/_react.default.createElement("g", {
|
|
52
|
+
fill: "none",
|
|
53
|
+
fillRule: "evenodd"
|
|
54
|
+
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
55
|
+
d: "M0 0h16v16H0z"
|
|
56
|
+
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
57
|
+
d: "M15 10.501a0.5 0.5 0 0 1 0.496 0.442l0.004 0.059v2.031a2.468 2.468 0 0 1 -2.361 2.466l-0.107 0.003H2.967a2.467 2.467 0 0 1 -2.465 -2.36L0.5 13.032v-2.03a0.5 0.5 0 0 1 0.997 -0.058l0.004 0.059v2.03a1.468 1.468 0 0 0 1.381 1.464l0.086 0.003h10.065a1.468 1.468 0 0 0 1.466 -1.382l0.003 -0.086v-2.031a0.5 0.5 0 0 1 0.5 -0.5zM15.5 7.5a0.5 0.5 0 0 1 0 1H0.5a0.5 0.5 0 0 1 0 -1zM13.029 0.5a2.471 2.471 0 0 1 2.469 2.364l0.003 0.107v2.031a0.5 0.5 0 0 1 -0.997 0.058L14.5 5.003V2.971a1.471 1.471 0 0 0 -1.385 -1.468L13.029 1.5H2.97a1.47 1.47 0 0 0 -1.467 1.383L1.5 2.97V5a0.5 0.5 0 0 1 -0.997 0.058L0.5 5V2.97a2.47 2.47 0 0 1 2.362 -2.467L2.97 0.5z",
|
|
58
|
+
fill: "#6b7280",
|
|
59
|
+
fillRule: "nonzero",
|
|
60
|
+
stroke: "#6b7280",
|
|
61
|
+
strokeWidth: "0.5"
|
|
62
|
+
}))))));
|
|
63
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EmbeddedCodeButton = EmbeddedCodeButton;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _draftJs = require("draft-js");
|
|
11
|
+
|
|
12
|
+
var _modals = require("@keystone-ui/modals");
|
|
13
|
+
|
|
14
|
+
var _fields = require("@keystone-ui/fields");
|
|
15
|
+
|
|
16
|
+
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); }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
function EmbeddedCodeButton(props) {
|
|
21
|
+
const {
|
|
22
|
+
editorState,
|
|
23
|
+
onChange,
|
|
24
|
+
className
|
|
25
|
+
} = props;
|
|
26
|
+
const [toShowInput, setToShowInput] = (0, _react.useState)(false);
|
|
27
|
+
const [inputValue, setInputValue] = (0, _react.useState)({
|
|
28
|
+
caption: '',
|
|
29
|
+
embeddedCode: ''
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const promptForInput = () => {
|
|
33
|
+
setToShowInput(true);
|
|
34
|
+
setInputValue({
|
|
35
|
+
caption: '',
|
|
36
|
+
embeddedCode: ''
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const confirmInput = () => {
|
|
41
|
+
const contentState = editorState.getCurrentContent();
|
|
42
|
+
const contentStateWithEntity = contentState.createEntity('EMBEDDEDCODE', 'IMMUTABLE', inputValue);
|
|
43
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
44
|
+
|
|
45
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
46
|
+
currentContent: contentStateWithEntity
|
|
47
|
+
}); // The third parameter here is a space string, not an empty string
|
|
48
|
+
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
52
|
+
setToShowInput(false);
|
|
53
|
+
setInputValue({
|
|
54
|
+
caption: '',
|
|
55
|
+
embeddedCode: ''
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const input = /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
60
|
+
isOpen: toShowInput
|
|
61
|
+
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
62
|
+
title: `Insert Embedded Code` //isOpen={toShowInput}
|
|
63
|
+
,
|
|
64
|
+
actions: {
|
|
65
|
+
cancel: {
|
|
66
|
+
label: 'Cancel',
|
|
67
|
+
action: () => {
|
|
68
|
+
setToShowInput(false);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
confirm: {
|
|
72
|
+
label: 'Confirm',
|
|
73
|
+
action: confirmInput
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
77
|
+
onChange: e => setInputValue({
|
|
78
|
+
caption: e.target.value,
|
|
79
|
+
embeddedCode: inputValue.embeddedCode
|
|
80
|
+
}),
|
|
81
|
+
type: "text",
|
|
82
|
+
placeholder: "Caption",
|
|
83
|
+
value: inputValue.caption,
|
|
84
|
+
style: {
|
|
85
|
+
marginBottom: '10px',
|
|
86
|
+
marginTop: '30px'
|
|
87
|
+
}
|
|
88
|
+
}), /*#__PURE__*/_react.default.createElement(_fields.TextArea, {
|
|
89
|
+
onChange: e => setInputValue({
|
|
90
|
+
caption: inputValue.caption,
|
|
91
|
+
embeddedCode: e.target.value
|
|
92
|
+
}),
|
|
93
|
+
placeholder: "Embedded Code",
|
|
94
|
+
type: "text",
|
|
95
|
+
value: inputValue.embeddedCode,
|
|
96
|
+
style: {
|
|
97
|
+
marginBottom: '30px'
|
|
98
|
+
}
|
|
99
|
+
})));
|
|
100
|
+
|
|
101
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, input, /*#__PURE__*/_react.default.createElement("div", {
|
|
102
|
+
onClick: () => {
|
|
103
|
+
promptForInput();
|
|
104
|
+
},
|
|
105
|
+
className: className
|
|
106
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
107
|
+
className: "far"
|
|
108
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, "Embed")));
|
|
109
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EnlargeButton = EnlargeButton;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function EnlargeButton(props) {
|
|
13
|
+
const {
|
|
14
|
+
onToggle,
|
|
15
|
+
isEnlarged,
|
|
16
|
+
className
|
|
17
|
+
} = props;
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
19
|
+
className: className,
|
|
20
|
+
onClick: onToggle
|
|
21
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
22
|
+
className: isEnlarged ? 'fas fa-compress' : 'fas fa-expand'
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FontColorButton = FontColorButton;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _modals = require("@keystone-ui/modals");
|
|
11
|
+
|
|
12
|
+
var _draftJs = require("draft-js");
|
|
13
|
+
|
|
14
|
+
var _fields = require("@keystone-ui/fields");
|
|
15
|
+
|
|
16
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
17
|
+
|
|
18
|
+
var _modifier = require("../modifier");
|
|
19
|
+
|
|
20
|
+
var _const = require("../const");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
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); }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
29
|
+
font-family: Georgia, serif;
|
|
30
|
+
margin-right: 10px;
|
|
31
|
+
padding: 10px;
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
function FontColorButton(props) {
|
|
35
|
+
const {
|
|
36
|
+
isActive,
|
|
37
|
+
editorState,
|
|
38
|
+
onChange
|
|
39
|
+
} = props;
|
|
40
|
+
const [toShowColorInput, setToShowColorInput] = (0, _react.useState)(false);
|
|
41
|
+
const [colorValue, setColorValue] = (0, _react.useState)('');
|
|
42
|
+
|
|
43
|
+
const promptForColor = e => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
const selection = editorState.getSelection();
|
|
46
|
+
|
|
47
|
+
if (!selection.isCollapsed()) {
|
|
48
|
+
setToShowColorInput(true);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const confirmColor = () => {
|
|
53
|
+
const selection = editorState.getSelection();
|
|
54
|
+
const contentState = editorState.getCurrentContent();
|
|
55
|
+
|
|
56
|
+
let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_FONT_COLOR);
|
|
57
|
+
|
|
58
|
+
if (colorValue) {
|
|
59
|
+
newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, _const.CUSTOM_STYLE_PREFIX_FONT_COLOR + colorValue);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
|
|
63
|
+
setToShowColorInput(false);
|
|
64
|
+
setColorValue('');
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const onColorInputKeyDown = e => {
|
|
68
|
+
if (e.which === 13) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
confirmColor();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const removeColor = () => {
|
|
75
|
+
const selection = editorState.getSelection();
|
|
76
|
+
|
|
77
|
+
if (!selection.isCollapsed()) {
|
|
78
|
+
const contentState = editorState.getCurrentContent();
|
|
79
|
+
|
|
80
|
+
const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_FONT_COLOR);
|
|
81
|
+
|
|
82
|
+
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setToShowColorInput(false);
|
|
86
|
+
setColorValue('');
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const colorInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
|
|
90
|
+
title: "Hex Color Code (#ffffff)",
|
|
91
|
+
isOpen: toShowColorInput,
|
|
92
|
+
actions: {
|
|
93
|
+
cancel: {
|
|
94
|
+
label: 'Cancel',
|
|
95
|
+
action: removeColor
|
|
96
|
+
},
|
|
97
|
+
confirm: {
|
|
98
|
+
label: 'Confirm',
|
|
99
|
+
action: confirmColor
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, /*#__PURE__*/_react.default.createElement(ColorHexInput, {
|
|
103
|
+
onChange: e => setColorValue(e.target.value),
|
|
104
|
+
type: "text",
|
|
105
|
+
value: colorValue,
|
|
106
|
+
onKeyDown: onColorInputKeyDown
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, colorInput, /*#__PURE__*/_react.default.createElement("div", {
|
|
110
|
+
className: props.className,
|
|
111
|
+
onMouseDown: isActive ? removeColor : promptForColor
|
|
112
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
113
|
+
className: "fas fa-palette"
|
|
114
|
+
})));
|
|
115
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ImageButton = ImageButton;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _draftJs = require("draft-js");
|
|
11
|
+
|
|
12
|
+
var _imageSelector = require("./selector/image-selector");
|
|
13
|
+
|
|
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
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
function ImageButton(props) {
|
|
19
|
+
const {
|
|
20
|
+
editorState,
|
|
21
|
+
onChange,
|
|
22
|
+
className,
|
|
23
|
+
ImageSelector = _imageSelector.ImageSelector
|
|
24
|
+
} = props;
|
|
25
|
+
const [toShowImageSelector, setToShowImageSelector] = (0, _react.useState)(false);
|
|
26
|
+
|
|
27
|
+
const promptForImageSelector = () => {
|
|
28
|
+
setToShowImageSelector(true);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const onImageSelectorChange = (selectedImagesWithMeta, align) => {
|
|
32
|
+
var _selected$image, _selected$image$image;
|
|
33
|
+
|
|
34
|
+
const selected = selectedImagesWithMeta === null || selectedImagesWithMeta === void 0 ? void 0 : selectedImagesWithMeta[0];
|
|
35
|
+
|
|
36
|
+
if (!selected) {
|
|
37
|
+
setToShowImageSelector(false);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const contentState = editorState.getCurrentContent();
|
|
42
|
+
const contentStateWithEntity = contentState.createEntity('image', 'IMMUTABLE', { ...(selected === null || selected === void 0 ? void 0 : selected.image),
|
|
43
|
+
desc: selected === null || selected === void 0 ? void 0 : selected.desc,
|
|
44
|
+
url: selected === null || selected === void 0 ? void 0 : (_selected$image = selected.image) === null || _selected$image === void 0 ? void 0 : (_selected$image$image = _selected$image.imageFile) === null || _selected$image$image === void 0 ? void 0 : _selected$image$image.url,
|
|
45
|
+
alignment: align
|
|
46
|
+
});
|
|
47
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
48
|
+
|
|
49
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
50
|
+
currentContent: contentStateWithEntity
|
|
51
|
+
}); // The third parameter here is a space string, not an empty string
|
|
52
|
+
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
56
|
+
setToShowImageSelector(false);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowImageSelector && /*#__PURE__*/_react.default.createElement(ImageSelector, {
|
|
60
|
+
onChange: onImageSelectorChange,
|
|
61
|
+
enableCaption: true,
|
|
62
|
+
enableUrl: true,
|
|
63
|
+
enableAlignment: true
|
|
64
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
65
|
+
className: className,
|
|
66
|
+
onClick: promptForImageSelector
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
68
|
+
className: "far fa-image"
|
|
69
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, " Image")));
|
|
70
|
+
}
|