@kids-reporter/draft-editor 0.4.26 → 0.4.28

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.
@@ -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 _infoBox = require("./block-renderers/info-box");
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 EmbeddedCodeInArticleBody({
41
- data: entityData
42
- });
40
+ return (0, _embeddedCode.EditableEmbeddedCode)(props);
43
41
  }
44
42
  case 'INFOBOX':
45
43
  {
@@ -0,0 +1,80 @@
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
+ margin-bottom: 30px;
29
+ background-color: #fafbfc;
30
+ `;
31
+ const EditableBlock = (0, _styledComponents.default)(_styled.EditableBlock)`
32
+ &:hover {
33
+ ${StyledEmbeddedCode} {
34
+ background-color: #f0f0f0;
35
+ opacity: 0.3;
36
+ }
37
+ `;
38
+ function EditableEmbeddedCode(props) {
39
+ const [isInputOpen, setIsInputOpen] = (0, _react.useState)(false);
40
+ const {
41
+ block,
42
+ blockProps,
43
+ contentState
44
+ } = props;
45
+ const {
46
+ onEditStart,
47
+ onEditFinish
48
+ } = blockProps;
49
+ const entityKey = block.getEntityAt(0);
50
+ const entity = contentState.getEntity(entityKey);
51
+ const data = entity.getData();
52
+ const onInputChange = inputValue => {
53
+ // close `EmbeddedCodeInput`
54
+ setIsInputOpen(false);
55
+ onEditFinish({
56
+ entityKey,
57
+ entityData: inputValue
58
+ });
59
+ };
60
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_embeddedCode.EmbeddedCodeInput, {
61
+ isOpen: isInputOpen,
62
+ onCancel: () => {
63
+ setIsInputOpen(false);
64
+ onEditFinish();
65
+ },
66
+ onConfirm: onInputChange,
67
+ inputValue: data
68
+ }), /*#__PURE__*/_react.default.createElement(EditableBlock, null, /*#__PURE__*/_react.default.createElement(StyledEmbeddedCode, {
69
+ embeddedCode: data === null || data === void 0 ? void 0 : data.embeddedCode
70
+ }), /*#__PURE__*/_react.default.createElement(_styled.EditButton, {
71
+ onClick: () => {
72
+ // call `onEditStart` prop as we are trying to update the blockquote entity
73
+ onEditStart();
74
+ // open `BlockquoteInput`
75
+ setIsInputOpen(true);
76
+ }
77
+ }, /*#__PURE__*/_react.default.createElement("i", {
78
+ className: "fa-solid fa-pen"
79
+ }), /*#__PURE__*/_react.default.createElement("span", null, "Modify"))));
80
+ }
@@ -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 EmbeddedCodeButton(props) {
14
- const {
15
- editorState,
16
- onChange,
17
- className
18
- } = props;
19
- const [toShowInput, setToShowInput] = (0, _react.useState)(false);
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
- const contentState = editorState.getCurrentContent();
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
- const input = /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
49
- isOpen: toShowInput
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: inputValue.caption,
42
+ caption: inputValueState.caption,
69
43
  embeddedCode: e.target.value
70
44
  }),
71
45
  placeholder: "Embedded Code",
72
46
  type: "text",
73
- value: inputValue.embeddedCode,
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: inputValue.embeddedCode
54
+ embeddedCode: inputValueState.embeddedCode
81
55
  }),
82
56
  type: "text",
83
57
  placeholder: "Caption",
84
- value: inputValue.caption,
58
+ value: inputValueState.caption,
85
59
  style: {
86
60
  marginBottom: '10px',
87
61
  marginTop: '30px'
88
62
  }
89
63
  })));
90
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, input, /*#__PURE__*/_react.default.createElement("div", {
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.26",
3
+ "version": "0.4.28",
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",
26
+ "@kids-reporter/draft-renderer": "^0.4.28",
27
27
  "@twreporter/errors": "^1.1.2",
28
28
  "draft-js": "^0.11.7"
29
29
  },
@@ -1 +0,0 @@
1
- "use strict";