@kids-reporter/draft-editor 0.1.0 → 0.2.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/lib/buttons/annotation.js +1 -14
- package/lib/buttons/image.js +0 -3
- package/lib/buttons/info-box.js +1 -4
- package/lib/buttons/selector/image-selector.js +3 -1
- package/lib/buttons/slideshow.js +2 -3
- package/lib/draft-editor.js +61 -363
- package/package.json +12 -7
- package/lib/block-renderer/background-image-block.js +0 -141
- package/lib/block-renderer/background-video-block.js +0 -151
- package/lib/block-renderer/color-box-block.js +0 -86
- package/lib/block-renderer/info-box-block.js +0 -86
- package/lib/block-renderer/side-index-block.js +0 -90
- package/lib/block-renderer/table-block.js +0 -408
- package/lib/block-renderer-fn.js +0 -131
- package/lib/buttons/audio.js +0 -65
- package/lib/buttons/background-color.js +0 -122
- package/lib/buttons/background-image.js +0 -223
- package/lib/buttons/background-video.js +0 -223
- package/lib/buttons/color-box.js +0 -173
- package/lib/buttons/divider.js +0 -63
- package/lib/buttons/font-color.js +0 -115
- package/lib/buttons/media.js +0 -121
- package/lib/buttons/related-post.js +0 -71
- package/lib/buttons/selector/audio-selector.js +0 -279
- package/lib/buttons/selector/post-selector.js +0 -317
- package/lib/buttons/selector/video-selector.js +0 -281
- package/lib/buttons/side-index.js +0 -200
- package/lib/buttons/table.js +0 -67
- package/lib/buttons/text-align.js +0 -88
- package/lib/buttons/video.js +0 -65
- package/lib/buttons/youtube.js +0 -147
- package/lib/const.js +0 -18
- package/lib/draft-converter/api-data-instance.js +0 -58
- package/lib/draft-converter/atomic-block-processor.js +0 -233
- package/lib/draft-converter/entities.js +0 -76
- package/lib/draft-converter/index.js +0 -201
- package/lib/draft-converter/inline-styles-processor.js +0 -236
- package/lib/entity-decorator.js +0 -20
- package/lib/modifier.js +0 -68
- package/lib/theme/index.js +0 -39
package/lib/buttons/color-box.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/buttons/divider.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/buttons/media.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.MediaButton = MediaButton;
|
|
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
|
-
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
|
-
const styles = {
|
|
21
|
-
buttons: {
|
|
22
|
-
marginBottom: 10,
|
|
23
|
-
display: 'flex'
|
|
24
|
-
},
|
|
25
|
-
urlInputContainer: {
|
|
26
|
-
marginBottom: 10
|
|
27
|
-
},
|
|
28
|
-
urlInput: {
|
|
29
|
-
fontFamily: "'Georgia', serif",
|
|
30
|
-
marginRight: 10,
|
|
31
|
-
padding: 3
|
|
32
|
-
},
|
|
33
|
-
button: {
|
|
34
|
-
marginTop: '10px',
|
|
35
|
-
marginRight: '10px',
|
|
36
|
-
cursor: 'pointer'
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function MediaButton(props) {
|
|
41
|
-
const {
|
|
42
|
-
editorState,
|
|
43
|
-
onChange,
|
|
44
|
-
customStyles
|
|
45
|
-
} = props;
|
|
46
|
-
const [toShowUrlInput, setToShowUrlInput] = (0, _react.useState)(false);
|
|
47
|
-
const [urlValue, setUrlValue] = (0, _react.useState)('');
|
|
48
|
-
const [urlType, setUrlType] = (0, _react.useState)('');
|
|
49
|
-
|
|
50
|
-
const promptForMedia = mediaType => {
|
|
51
|
-
setToShowUrlInput(true);
|
|
52
|
-
setUrlValue('');
|
|
53
|
-
setUrlType(mediaType);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const confirmMedia = () => {
|
|
57
|
-
const contentState = editorState.getCurrentContent();
|
|
58
|
-
const contentStateWithEntity = contentState.createEntity(urlType, 'IMMUTABLE', {
|
|
59
|
-
src: urlValue
|
|
60
|
-
});
|
|
61
|
-
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
62
|
-
|
|
63
|
-
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
64
|
-
currentContent: contentStateWithEntity
|
|
65
|
-
}); // The third parameter here is a space string, not an empty string
|
|
66
|
-
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
70
|
-
setToShowUrlInput(false);
|
|
71
|
-
setUrlType('');
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const urlInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
|
|
75
|
-
title: `Insert ${urlType.toUpperCase()} LINK`,
|
|
76
|
-
isOpen: toShowUrlInput,
|
|
77
|
-
actions: {
|
|
78
|
-
confirm: {
|
|
79
|
-
label: 'Confirm',
|
|
80
|
-
action: confirmMedia
|
|
81
|
-
},
|
|
82
|
-
cancel: {
|
|
83
|
-
label: 'Cancel',
|
|
84
|
-
action: () => {
|
|
85
|
-
setToShowUrlInput(false);
|
|
86
|
-
setUrlValue('');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
91
|
-
onChange: e => setUrlValue(e.target.value),
|
|
92
|
-
style: styles.urlInput,
|
|
93
|
-
type: "text",
|
|
94
|
-
value: urlValue
|
|
95
|
-
}));
|
|
96
|
-
|
|
97
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, urlInput, /*#__PURE__*/_react.default.createElement("div", {
|
|
98
|
-
style: styles.buttons
|
|
99
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
100
|
-
onClick: () => {
|
|
101
|
-
promptForMedia('imageLink');
|
|
102
|
-
},
|
|
103
|
-
style: customStyles || styles.button
|
|
104
|
-
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
105
|
-
className: "fas fa-arrow-up-right-from-square"
|
|
106
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, " Image Link")), /*#__PURE__*/_react.default.createElement("div", {
|
|
107
|
-
onClick: () => {
|
|
108
|
-
promptForMedia('audioLink');
|
|
109
|
-
},
|
|
110
|
-
style: customStyles || styles.button
|
|
111
|
-
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
112
|
-
className: "far fa-file-audio"
|
|
113
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, " Audio Link")), /*#__PURE__*/_react.default.createElement("div", {
|
|
114
|
-
onClick: () => {
|
|
115
|
-
promptForMedia('videoLink');
|
|
116
|
-
},
|
|
117
|
-
style: customStyles || styles.button
|
|
118
|
-
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
119
|
-
className: "far fa-file-video"
|
|
120
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, " Video Link"))));
|
|
121
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RelatedPostButton = RelatedPostButton;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _draftJs = require("draft-js");
|
|
11
|
-
|
|
12
|
-
var _postSelector = require("./selector/post-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 RelatedPostButton(props) {
|
|
19
|
-
const {
|
|
20
|
-
editorState,
|
|
21
|
-
onChange,
|
|
22
|
-
className,
|
|
23
|
-
PostSelector = _postSelector.PostSelector
|
|
24
|
-
} = props;
|
|
25
|
-
const [toShowPostSelector, setToShowPostSelector] = (0, _react.useState)(false);
|
|
26
|
-
|
|
27
|
-
const promptForPostSelector = () => {
|
|
28
|
-
setToShowPostSelector(true);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const onPostSelectorChange = selected => {
|
|
32
|
-
if (!selected.length) {
|
|
33
|
-
setToShowPostSelector(false);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const contentState = editorState.getCurrentContent();
|
|
38
|
-
const contentStateWithEntity = contentState.createEntity('RELATEDPOST', 'IMMUTABLE', {
|
|
39
|
-
posts: selected.map(ele => ele.post)
|
|
40
|
-
});
|
|
41
|
-
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
42
|
-
|
|
43
|
-
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
44
|
-
currentContent: contentStateWithEntity
|
|
45
|
-
}); // The third parameter here is a space string, not an empty string
|
|
46
|
-
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
50
|
-
setToShowPostSelector(false);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowPostSelector && /*#__PURE__*/_react.default.createElement(PostSelector, {
|
|
54
|
-
onChange: onPostSelectorChange,
|
|
55
|
-
enableMultiSelect: true,
|
|
56
|
-
minSelectCount: 1,
|
|
57
|
-
maxSelectCount: 3
|
|
58
|
-
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
59
|
-
className: className,
|
|
60
|
-
onClick: promptForPostSelector
|
|
61
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
62
|
-
width: "16",
|
|
63
|
-
height: "14",
|
|
64
|
-
viewBox: "0 0 16 14",
|
|
65
|
-
fill: "none",
|
|
66
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
67
|
-
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
68
|
-
d: "M14.675 0H10.7917C9.45556 0 8.29445 1.11291 8.00278 2.6837C7.70833 1.11291 6.55 0 5.21389 0H1.33333C0.597222 0 0 0.718549 0 1.6042V9.81905C0 10.7047 0.597222 11.4233 1.33333 11.4233H3.825C6.66389 11.4233 7.51111 12.2387 7.91667 13.9298C7.93611 14.0234 8.06111 14.0234 8.08333 13.9298C8.49167 12.2387 9.33889 11.4233 12.175 11.4233H14.6667C15.4028 11.4233 16 10.7047 16 9.81905V1.60754C16 0.725233 15.4083 0.00668417 14.675 0ZM6.72222 8.8699C6.72222 8.9334 6.68056 8.98687 6.625 8.98687H2.17222C2.11944 8.98687 2.075 8.93674 2.075 8.8699V8.10456C2.075 8.04106 2.11667 7.98759 2.17222 7.98759H6.62778C6.68056 7.98759 6.725 8.03772 6.725 8.10456V8.8699H6.72222ZM6.72222 6.83457C6.72222 6.89807 6.68056 6.95154 6.625 6.95154H2.17222C2.11944 6.95154 2.075 6.90141 2.075 6.83457V6.06923C2.075 6.00573 2.11667 5.95226 2.17222 5.95226H6.62778C6.68056 5.95226 6.725 6.00239 6.725 6.06923V6.83457H6.72222ZM6.72222 4.79924C6.72222 4.86274 6.68056 4.91621 6.625 4.91621H2.17222C2.11944 4.91621 2.075 4.86608 2.075 4.79924V4.0339C2.075 3.9704 2.11667 3.91693 2.17222 3.91693H6.62778C6.68056 3.91693 6.725 3.96706 6.725 4.0339V4.79924H6.72222ZM13.925 8.86656C13.925 8.93005 13.8833 8.98353 13.8278 8.98353H9.375C9.32222 8.98353 9.27778 8.9334 9.27778 8.86656V8.10122C9.27778 8.03772 9.31944 7.98424 9.375 7.98424H13.8306C13.8833 7.98424 13.9278 8.03438 13.9278 8.10122V8.86656H13.925ZM13.925 6.83122C13.925 6.89472 13.8833 6.9482 13.8278 6.9482H9.375C9.32222 6.9482 9.27778 6.89807 9.27778 6.83122V6.06589C9.27778 6.00239 9.31944 5.94891 9.375 5.94891H13.8306C13.8833 5.94891 13.9278 5.99905 13.9278 6.06589V6.83122H13.925ZM13.925 4.79589C13.925 4.85939 13.8833 4.91287 13.8278 4.91287H9.375C9.32222 4.91287 9.27778 4.86274 9.27778 4.79589V4.0339C9.27778 3.9704 9.31944 3.91693 9.375 3.91693H13.8306C13.8833 3.91693 13.9278 3.96706 13.9278 4.0339V4.79589H13.925Z",
|
|
69
|
-
fill: "#6b7280"
|
|
70
|
-
})), /*#__PURE__*/_react.default.createElement("span", null, "Related Post")));
|
|
71
|
-
}
|