@kids-reporter/draft-editor 1.0.17 → 1.0.18
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 +1 -1
- package/lib/block-renderers/blockquote.js +21 -18
- package/lib/block-renderers/embedded-code.js +31 -25
- package/lib/block-renderers/image-link.js +78 -73
- package/lib/block-renderers/image.js +23 -21
- package/lib/block-renderers/info-box.js +22 -19
- package/lib/block-renderers/slideshow.js +22 -19
- package/lib/block-renderers/styled.js +12 -8
- package/lib/buttons/anchor.js +18 -14
- package/lib/buttons/annotation.js +19 -15
- package/lib/buttons/bg-color.js +31 -23
- package/lib/buttons/blockquote.js +68 -62
- package/lib/buttons/control-buttons.js +31 -25
- package/lib/buttons/divider.js +29 -21
- package/lib/buttons/embedded-code.js +84 -76
- package/lib/buttons/enlarge.js +7 -5
- package/lib/buttons/font-color.js +21 -16
- package/lib/buttons/form/select.js +14 -10
- package/lib/buttons/image-link.js +26 -22
- package/lib/buttons/image.js +18 -12
- package/lib/buttons/index.js +6 -6
- package/lib/buttons/info-box.js +79 -73
- package/lib/buttons/link.js +17 -15
- package/lib/buttons/news-reading.js +65 -56
- package/lib/buttons/selector/align-selector.js +20 -16
- package/lib/buttons/selector/image-selector.js +119 -88
- package/lib/buttons/selector/pagination.js +45 -33
- package/lib/buttons/selector/search-box.js +19 -18
- package/lib/buttons/slideshow.js +18 -12
- package/lib/buttons/toc-anchor.js +9 -5
- package/lib/entity-decorators/anchor.js +46 -33
- package/lib/entity-decorators/annotation.js +53 -52
- package/lib/entity-decorators/link.js +38 -36
- package/lib/entity-decorators/toc-anchor.js +41 -35
- package/lib/entity-decorators/wrapper.js +9 -6
- package/lib/index.js +7 -6
- package/lib/local-types/kids-reporter__draft-renderer.d.js +1 -0
- package/lib/rich-text-editor.js +110 -84
- package/lib/styled.js +14 -3
- package/package.json +12 -10
- package/lib/buttons/form/array-field.js +0 -30
package/lib/rich-text-editor.js
CHANGED
|
@@ -4,31 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.RichTextEditor = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _draftJs = require("draft-js");
|
|
9
7
|
var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
10
|
-
var
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
10
|
var _blockRendererFn = require("./block-renderer-fn");
|
|
12
|
-
var _styled = require("./styled");
|
|
13
11
|
var _buttons = require("./buttons");
|
|
14
|
-
var _imageSelector = require("./buttons/selector/image-selector");
|
|
15
12
|
var _bgColor = require("./buttons/bg-color");
|
|
13
|
+
var _btNames = _interopRequireDefault(require("./buttons/bt-names"));
|
|
16
14
|
var _fontColor = require("./buttons/font-color");
|
|
15
|
+
var _imageSelector = require("./buttons/selector/image-selector");
|
|
16
|
+
var _styled = require("./styled");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
const styleSource = ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'].map((src, index) => /*#__PURE__*/_react.default.createElement("link", {
|
|
20
|
-
key: `style-src-${index}`,
|
|
19
|
+
const styleSource = ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'].map((src, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)("link", {
|
|
21
20
|
href: src,
|
|
22
21
|
rel: "stylesheet",
|
|
23
22
|
type: "text/css"
|
|
24
|
-
}));
|
|
23
|
+
}, `style-src-${index}`));
|
|
25
24
|
class RichTextEditor extends _react.default.Component {
|
|
26
25
|
editorRef = null;
|
|
27
26
|
constructor(props) {
|
|
28
|
-
var _props$decorators;
|
|
29
27
|
super(props);
|
|
30
28
|
// Assign edit props to decorators
|
|
31
|
-
const editableDecorators = new _draftJs.CompositeDecorator(
|
|
29
|
+
const editableDecorators = new _draftJs.CompositeDecorator(props.decorators?.map(editableDecorator => {
|
|
32
30
|
return {
|
|
33
31
|
...editableDecorator,
|
|
34
32
|
props: {
|
|
@@ -177,79 +175,107 @@ class RichTextEditor extends _react.default.Component {
|
|
|
177
175
|
onChange: this.onChange,
|
|
178
176
|
readOnly: readOnly
|
|
179
177
|
};
|
|
180
|
-
return /*#__PURE__*/
|
|
181
|
-
isEnlarged: isEnlarged
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
178
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styled.DraftEditorContainer, {
|
|
179
|
+
isEnlarged: isEnlarged,
|
|
180
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styled.DraftEditorWrapper, {
|
|
181
|
+
children: [styleSource, /*#__PURE__*/(0, _jsxRuntime.jsx)(_styled.DraftEditorControls, {
|
|
182
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styled.DraftEditorControlsWrapper, {
|
|
183
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.BlockStyleControls, {
|
|
184
|
+
disabledButtons: disabledButtons,
|
|
185
|
+
editorState: editorState,
|
|
186
|
+
onToggle: this.toggleBlockType,
|
|
187
|
+
readOnly: readOnly
|
|
188
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.InlineStyleControls, {
|
|
189
|
+
disabledButtons: disabledButtons,
|
|
190
|
+
editorState: editorState,
|
|
191
|
+
onToggle: this.toggleInlineStyle,
|
|
192
|
+
readOnly: readOnly
|
|
193
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styled.EnlargeButtonWrapper, {
|
|
194
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomEnlargeButton, {
|
|
195
|
+
onToggle: this.toggleEnlarge,
|
|
196
|
+
isEnlarged: isEnlarged
|
|
197
|
+
})
|
|
198
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomTOCAnchorButton, {
|
|
199
|
+
isDisabled: disabledButtons.includes(_btNames.default.tocAnchor),
|
|
200
|
+
isActive: entityType === _draftRenderer.ENTITY.TOCAnchor,
|
|
201
|
+
...commonProps
|
|
202
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomAnchorButton, {
|
|
203
|
+
isDisabled: disabledButtons.includes(_btNames.default.anchor),
|
|
204
|
+
isActive: entityType === _draftRenderer.ENTITY.Anchor,
|
|
205
|
+
...commonProps,
|
|
206
|
+
...this.commonEditProps
|
|
207
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomLinkButton, {
|
|
208
|
+
isDisabled: disabledButtons.includes(_btNames.default.link),
|
|
209
|
+
isActive: entityType === _draftRenderer.ENTITY.Link,
|
|
210
|
+
...commonProps,
|
|
211
|
+
...this.commonEditProps
|
|
212
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomBackgroundColorButton, {
|
|
213
|
+
isDisabled: disabledButtons.includes(_btNames.default.backgroundColor),
|
|
214
|
+
isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_bgColor.customStylePrefix)) !== undefined,
|
|
215
|
+
...commonProps,
|
|
216
|
+
...this.commonEditProps
|
|
217
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomFontColorButton, {
|
|
218
|
+
isDisabled: disabledButtons.includes(_btNames.default.fontColor),
|
|
219
|
+
isActive: editorState.getCurrentInlineStyle().find(styleName => typeof styleName === 'string' && styleName.startsWith(_fontColor.customStylePrefix)) !== undefined,
|
|
220
|
+
...commonProps,
|
|
221
|
+
...this.commonEditProps
|
|
222
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomBlockquoteButton, {
|
|
223
|
+
isDisabled: disabledButtons.includes(_btNames.default.blockquote),
|
|
224
|
+
...commonProps
|
|
225
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomAnnotationButton, {
|
|
226
|
+
isDisabled: disabledButtons.includes(_btNames.default.annotation),
|
|
227
|
+
isActive: entityType === _draftRenderer.ENTITY.Annotation,
|
|
228
|
+
...commonProps,
|
|
229
|
+
...this.commonEditProps
|
|
230
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomImageButton, {
|
|
231
|
+
isDisabled: disabledButtons.includes(_btNames.default.image),
|
|
232
|
+
ImageSelector: _imageSelector.ImageSelector,
|
|
233
|
+
...commonProps
|
|
234
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomImageLinkButton, {
|
|
235
|
+
isDisabled: disabledButtons.includes(_btNames.default.imageLink),
|
|
236
|
+
...commonProps
|
|
237
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomSlideshowButton, {
|
|
238
|
+
isDisabled: disabledButtons.includes(_btNames.default.slideshow),
|
|
239
|
+
ImageSelector: _imageSelector.ImageSelector,
|
|
240
|
+
...commonProps
|
|
241
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomInfoBoxButton, {
|
|
242
|
+
isDisabled: disabledButtons.includes(_btNames.default.infoBox),
|
|
243
|
+
...commonProps
|
|
244
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomEmbeddedCodeButton, {
|
|
245
|
+
isDisabled: disabledButtons.includes(_btNames.default.embed),
|
|
246
|
+
...commonProps
|
|
247
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomNewsReadingButton, {
|
|
248
|
+
isDisabled: disabledButtons.includes(_btNames.default.newsReading),
|
|
249
|
+
...commonProps
|
|
250
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.CustomDividerButton, {
|
|
251
|
+
isDisabled: disabledButtons.includes(_btNames.default.divider),
|
|
252
|
+
...commonProps
|
|
253
|
+
})]
|
|
254
|
+
})
|
|
255
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styled.TextEditorWrapper, {
|
|
256
|
+
onClick: () => {
|
|
257
|
+
if (this.editorRef) {
|
|
258
|
+
;
|
|
259
|
+
this.editorRef?.focus();
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_draftJs.Editor, {
|
|
263
|
+
blockRenderMap: _draftRenderer.blockRenderMap,
|
|
264
|
+
blockRendererFn: this.blockRendererFn,
|
|
265
|
+
customStyleFn: _draftRenderer.customStyleFn,
|
|
266
|
+
editorState: editorState,
|
|
267
|
+
handleKeyCommand: this.handleKeyCommand,
|
|
268
|
+
handleReturn: this.handleReturn,
|
|
269
|
+
keyBindingFn: this.mapKeyToEditorCommand,
|
|
270
|
+
onChange: this.onChange,
|
|
271
|
+
placeholder: "Tell a story...",
|
|
272
|
+
ref: this.editorRef,
|
|
273
|
+
spellCheck: true,
|
|
274
|
+
readOnly: readOnly
|
|
275
|
+
})
|
|
276
|
+
})]
|
|
277
|
+
})
|
|
278
|
+
});
|
|
253
279
|
}
|
|
254
280
|
}
|
|
255
281
|
exports.RichTextEditor = RichTextEditor;
|
package/lib/styled.js
CHANGED
|
@@ -16,9 +16,20 @@ const DraftEditorWrapper = exports.DraftEditorWrapper = _styledComponents.defaul
|
|
|
16
16
|
padding: 15px;
|
|
17
17
|
|
|
18
18
|
/* Custom setting */
|
|
19
|
-
font-family:
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
font-family:
|
|
20
|
+
system-ui,
|
|
21
|
+
-apple-system,
|
|
22
|
+
BlinkMacSystemFont,
|
|
23
|
+
'Segoe UI',
|
|
24
|
+
Roboto,
|
|
25
|
+
'Helvetica Neue',
|
|
26
|
+
Arial,
|
|
27
|
+
'Noto Sans',
|
|
28
|
+
sans-serif,
|
|
29
|
+
'Apple Color Emoji',
|
|
30
|
+
'Segoe UI Emoji',
|
|
31
|
+
'Segoe UI Symbol',
|
|
32
|
+
'Noto Color Emoji';
|
|
22
33
|
width: 100%;
|
|
23
34
|
height: 100%;
|
|
24
35
|
background: rgb(255, 255, 255);
|
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.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"dev": "make dev",
|
|
9
9
|
"build": "make build",
|
|
10
10
|
"clean": "make clean",
|
|
11
|
-
"build-lib": "make build-lib"
|
|
11
|
+
"build-lib": "make build-lib",
|
|
12
|
+
"lint:check": "eslint src --ext .ts,.tsx,.js,.jsx",
|
|
13
|
+
"type-check": "tsc --noEmit"
|
|
12
14
|
},
|
|
13
15
|
"repository": {
|
|
14
16
|
"type": "git",
|
|
@@ -23,23 +25,23 @@
|
|
|
23
25
|
],
|
|
24
26
|
"license": "MIT",
|
|
25
27
|
"dependencies": {
|
|
26
|
-
"@kids-reporter/draft-renderer": "1.0.
|
|
28
|
+
"@kids-reporter/draft-renderer": "^1.0.13",
|
|
27
29
|
"@twreporter/errors": "^1.1.2",
|
|
28
30
|
"draft-js": "^0.11.7"
|
|
29
31
|
},
|
|
30
32
|
"peerDependencies": {
|
|
31
|
-
"@keystone-6/core": "5.
|
|
33
|
+
"@keystone-6/core": "6.5.1",
|
|
32
34
|
"@keystone-ui/button": "^7.0.2",
|
|
33
35
|
"@keystone-ui/fields": "^7.2.0",
|
|
34
36
|
"@keystone-ui/modals": "^6.0.3",
|
|
35
|
-
"react": "18.
|
|
36
|
-
"react-dom": "18.
|
|
37
|
-
"styled-components": "
|
|
37
|
+
"react": "18.3.1",
|
|
38
|
+
"react-dom": "18.3.1",
|
|
39
|
+
"styled-components": "6.1.19"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"react": "18.
|
|
41
|
-
"react-dom": "18.
|
|
42
|
-
"styled-components": "
|
|
42
|
+
"react": "18.3.1",
|
|
43
|
+
"react-dom": "18.3.1",
|
|
44
|
+
"styled-components": "6.1.19"
|
|
43
45
|
},
|
|
44
46
|
"files": [
|
|
45
47
|
"lib"
|
|
@@ -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;
|