@kids-reporter/draft-renderer 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.
Files changed (50) hide show
  1. package/README.md +86 -0
  2. package/lib/assets/annotation-arrow.png +0 -0
  3. package/lib/assets/audio-pause.png +0 -0
  4. package/lib/assets/audio-play.png +0 -0
  5. package/lib/assets/citation-download.png +0 -0
  6. package/lib/assets/default-og-img.png +0 -0
  7. package/lib/assets/slideshow-arrow-down-dark.png +0 -0
  8. package/lib/assets/slideshow-arrow-down.png +0 -0
  9. package/lib/assets/slideshow-arrow-up.png +0 -0
  10. package/lib/assets/slideshow-close-cross.png +0 -0
  11. package/lib/block-renderer-fn.js +123 -0
  12. package/lib/block-renderers/audio-block.js +162 -0
  13. package/lib/block-renderers/background-image-block.js +257 -0
  14. package/lib/block-renderers/background-video-block.js +272 -0
  15. package/lib/block-renderers/color-box-block.js +94 -0
  16. package/lib/block-renderers/divider-block.js +27 -0
  17. package/lib/block-renderers/embedded-code-block.js +121 -0
  18. package/lib/block-renderers/image-block.js +72 -0
  19. package/lib/block-renderers/index.js +53 -0
  20. package/lib/block-renderers/info-box-block.js +124 -0
  21. package/lib/block-renderers/media-block.js +65 -0
  22. package/lib/block-renderers/related-post-block.js +73 -0
  23. package/lib/block-renderers/side-index-block.js +49 -0
  24. package/lib/block-renderers/slideshow-block.js +253 -0
  25. package/lib/block-renderers/table-block.js +455 -0
  26. package/lib/block-renderers/video-block.js +37 -0
  27. package/lib/components/slideshow-lightbox.js +134 -0
  28. package/lib/components/slideshow-sidebar.js +148 -0
  29. package/lib/const.js +10 -0
  30. package/lib/draft-renderer.js +234 -0
  31. package/lib/entity-decorator.js +18 -0
  32. package/lib/entity-decorators/annotation-decorator.js +155 -0
  33. package/lib/entity-decorators/index.js +16 -0
  34. package/lib/entity-decorators/link-decorator.js +48 -0
  35. package/lib/index.js +30 -0
  36. package/lib/public/07d1287fd390346af0c15b930148a5e4.png +0 -0
  37. package/lib/public/5b3cb1a908786c8750f1041860699cc1.png +0 -0
  38. package/lib/public/679d63b1846e81ada28c2f76edbd2931.png +0 -0
  39. package/lib/public/722f90c535fa64c27555ec6ee5f22393.png +0 -0
  40. package/lib/public/903cf84ef5c5ad76634c30bdc0ff8c49.png +0 -0
  41. package/lib/public/dc249b3412c5af890a004508287a3c3d.png +0 -0
  42. package/lib/public/dd45f0788d9c70cabe72430bf08e7413.png +0 -0
  43. package/lib/public/f96d4b486ba2061c460962ae694f4670.png +0 -0
  44. package/lib/shared-style/content-type.js +163 -0
  45. package/lib/shared-style/index.js +108 -0
  46. package/lib/theme/index.js +39 -0
  47. package/lib/types/index.js +32 -0
  48. package/lib/utils/common.js +44 -0
  49. package/lib/utils/post.js +147 -0
  50. package/package.json +44 -0
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = SlideshowSideBar;
7
+
8
+ var _reactImage = _interopRequireDefault(require("@readr-media/react-image"));
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const defaultImage = "https://unpkg.com/@kids-reporter/draft-renderer@0.1.0/lib/public/722f90c535fa64c27555ec6ee5f22393.png";
21
+ const arrowDown = "https://unpkg.com/@kids-reporter/draft-renderer@0.1.0/lib/public/f96d4b486ba2061c460962ae694f4670.png";
22
+ const arrowUp = "https://unpkg.com/@kids-reporter/draft-renderer@0.1.0/lib/public/679d63b1846e81ada28c2f76edbd2931.png";
23
+ const arrowShareStyle = (0, _styledComponents.css)`
24
+ width: 64px;
25
+ height: 64px;
26
+ margin: auto;
27
+ background-repeat: no-repeat;
28
+ background-position: center center;
29
+ background-size: 64px;
30
+ cursor: pointer;
31
+ border-radius: 50%;
32
+ visibility: ${props => props.shouldHideArrow ? 'hidden' : 'visible'};
33
+
34
+ &:hover {
35
+ background-color: rgba(255, 255, 255, 0.2);
36
+ }
37
+ `;
38
+ const SideBarWrapper = _styledComponents.default.div`
39
+ width: 64px;
40
+ position: relative;
41
+
42
+ .sidebar-images {
43
+ overflow-y: scroll;
44
+ max-height: 520px;
45
+ scrollbar-width: none;
46
+ margin: 12px auto;
47
+
48
+ &::-webkit-scrollbar {
49
+ display: none; /* for Chrome, Safari, and Opera */
50
+ }
51
+ }
52
+ `;
53
+ const ArrowUp = _styledComponents.default.div`
54
+ ${arrowShareStyle}
55
+ background-image: url(${arrowUp});
56
+ `;
57
+ const ArrowDown = _styledComponents.default.div`
58
+ ${arrowShareStyle}
59
+ background-image: url(${arrowDown});
60
+ `;
61
+ const SideBarImage = _styledComponents.default.div`
62
+ width: 100%;
63
+ aspect-ratio: 1/1;
64
+ cursor: pointer;
65
+ filter: ${props => props.isfocused ? 'none' : 'brightness(35%)'};
66
+
67
+ &:hover {
68
+ filter: ${props => props.isfocused ? 'none' : 'brightness(60%)'};
69
+ }
70
+
71
+ & + * {
72
+ margin-top: 12px;
73
+ }
74
+ `;
75
+
76
+ function SlideshowSideBar({
77
+ focusImageIndex,
78
+ images,
79
+ setFocusImageIndex,
80
+ imagesRefs
81
+ }) {
82
+ const handleScrollUp = () => {
83
+ if (focusImageIndex > 0) {
84
+ var _imagesRefs$current;
85
+
86
+ setFocusImageIndex(focusImageIndex - 1);
87
+ imagesRefs === null || imagesRefs === void 0 ? void 0 : (_imagesRefs$current = imagesRefs.current[focusImageIndex - 1]) === null || _imagesRefs$current === void 0 ? void 0 : _imagesRefs$current.scrollIntoView({
88
+ behavior: 'smooth',
89
+ block: 'center'
90
+ });
91
+ }
92
+ };
93
+
94
+ const handleScrollDown = () => {
95
+ if (focusImageIndex < (images === null || images === void 0 ? void 0 : images.length) - 1) {
96
+ var _imagesRefs$current2;
97
+
98
+ setFocusImageIndex(focusImageIndex + 1);
99
+ imagesRefs === null || imagesRefs === void 0 ? void 0 : (_imagesRefs$current2 = imagesRefs.current[focusImageIndex + 1]) === null || _imagesRefs$current2 === void 0 ? void 0 : _imagesRefs$current2.scrollIntoView({
100
+ behavior: 'smooth',
101
+ block: 'center'
102
+ });
103
+ }
104
+ };
105
+
106
+ const handleScrollIntoView = index => {
107
+ var _imagesRefs$current$i;
108
+
109
+ setFocusImageIndex(index);
110
+ imagesRefs === null || imagesRefs === void 0 ? void 0 : (_imagesRefs$current$i = imagesRefs.current[index]) === null || _imagesRefs$current$i === void 0 ? void 0 : _imagesRefs$current$i.scrollIntoView({
111
+ behavior: 'smooth',
112
+ block: 'center'
113
+ });
114
+ };
115
+
116
+ const sideBarImages = images.map((image, index) => {
117
+ return /*#__PURE__*/_react.default.createElement(SideBarImage, {
118
+ key: image === null || image === void 0 ? void 0 : image.id,
119
+ isfocused: focusImageIndex === index,
120
+ onClick: () => {
121
+ handleScrollIntoView(index);
122
+ },
123
+ ref: el => {
124
+ if (imagesRefs !== null && imagesRefs !== void 0 && imagesRefs.current) {
125
+ imagesRefs.current[index] = el;
126
+ }
127
+ }
128
+ }, /*#__PURE__*/_react.default.createElement(_reactImage.default, {
129
+ images: image === null || image === void 0 ? void 0 : image.resized,
130
+ defaultImage: defaultImage,
131
+ alt: image === null || image === void 0 ? void 0 : image.name,
132
+ rwd: {
133
+ desktop: '64px',
134
+ default: '100%'
135
+ },
136
+ priority: true
137
+ }));
138
+ });
139
+ return /*#__PURE__*/_react.default.createElement(SideBarWrapper, null, /*#__PURE__*/_react.default.createElement(ArrowUp, {
140
+ onClick: handleScrollUp,
141
+ shouldHideArrow: focusImageIndex === 0
142
+ }), /*#__PURE__*/_react.default.createElement("div", {
143
+ className: "sidebar-images"
144
+ }, sideBarImages), /*#__PURE__*/_react.default.createElement(ArrowDown, {
145
+ onClick: handleScrollDown,
146
+ shouldHideArrow: focusImageIndex + 1 === (images === null || images === void 0 ? void 0 : images.length)
147
+ }));
148
+ }
package/lib/const.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CUSTOM_STYLE_PREFIX_FONT_COLOR = exports.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR = void 0;
7
+ const CUSTOM_STYLE_PREFIX_FONT_COLOR = 'FONT_COLOR_';
8
+ exports.CUSTOM_STYLE_PREFIX_FONT_COLOR = CUSTOM_STYLE_PREFIX_FONT_COLOR;
9
+ const CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR = 'BACKGROUND_COLOR_';
10
+ exports.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR = CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = DraftRenderer;
7
+
8
+ var _draftJs = require("draft-js");
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
13
+
14
+ var _const = require("./const");
15
+
16
+ var _blockRendererFn = require("./block-renderer-fn");
17
+
18
+ var _entityDecorator = _interopRequireDefault(require("./entity-decorator"));
19
+
20
+ var _contentType = require("./shared-style/content-type");
21
+
22
+ var _index = require("./shared-style/index");
23
+
24
+ var _theme = _interopRequireDefault(require("./theme"));
25
+
26
+ var _types = require("./types");
27
+
28
+ var _common = require("./utils/common");
29
+
30
+ var _post = require("./utils/post");
31
+
32
+ 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); }
33
+
34
+ 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; }
35
+
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+
38
+ const DraftEditorWrapper = _styledComponents.default.div`
39
+ /* Rich-editor default setting (.RichEditor-root)*/
40
+ font-family: 'Georgia', serif;
41
+ text-align: left;
42
+
43
+ /* Custom setting */
44
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
45
+ 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
46
+ 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
47
+ width: 100%;
48
+ height: 100%;
49
+ letter-spacing: 0.01em;
50
+ color: rgba(0, 9, 40, 0.87);
51
+
52
+ *:has(.bg) + *:has(.bg) {
53
+ section {
54
+ margin-top: 0 !important;
55
+ }
56
+ }
57
+
58
+ /* Draft built-in buttons' style */
59
+ .public-DraftStyleDefault-header-two {
60
+ ${_index.defaultH2Style}
61
+
62
+ & + * {
63
+ ${_index.narrowSpacingBetweenContent}
64
+ }
65
+ }
66
+
67
+ .public-DraftStyleDefault-ul {
68
+ ${_index.defaultUlStyle}
69
+ }
70
+
71
+ .public-DraftStyleDefault-ol {
72
+ ${_index.defaultOlStyle}
73
+ }
74
+
75
+ /* code-block */
76
+ .public-DraftStyleDefault-pre {
77
+ overflow: hidden;
78
+ }
79
+
80
+ .alignCenter * {
81
+ text-align: center;
82
+ }
83
+ .alignLeft * {
84
+ text-align: left;
85
+ }
86
+
87
+ /* image-block: text-around-picture */
88
+ figure.left {
89
+ ${({
90
+ theme
91
+ }) => theme.breakpoint.xl} {
92
+ ${_index.textAroundPictureStyle};
93
+ float: left;
94
+ transform: translateX(calc(-50% - 32px));
95
+ }
96
+ }
97
+
98
+ figure.right {
99
+ ${({
100
+ theme
101
+ }) => theme.breakpoint.xl} {
102
+ ${_index.textAroundPictureStyle};
103
+ float: right;
104
+ transform: translateX(32px);
105
+ }
106
+ }
107
+
108
+ ${({
109
+ contentType
110
+ }) => {
111
+ switch (contentType) {
112
+ case _types.ValidPostContentType.NORMAL:
113
+ case _types.ValidPostContentType.ACTIONLIST:
114
+ return _contentType.NormalStyle;
115
+
116
+ case _types.ValidPostContentType.SUMMARY:
117
+ return _contentType.SummaryStyle;
118
+
119
+ case _types.ValidPostContentType.CITATION:
120
+ return _contentType.CitationStyle;
121
+
122
+ default:
123
+ return _contentType.NormalStyle;
124
+ }
125
+ }}
126
+ `;
127
+ const customStyleMap = {
128
+ CODE: {
129
+ backgroundColor: 'rgba(0, 0, 0, 0.05)',
130
+ fontFamily: '"Inconsolata", "Menlo", "Consolas", monospace',
131
+ fontSize: 16,
132
+ padding: 2
133
+ }
134
+ };
135
+
136
+ const customStyleFn = style => {
137
+ return style.reduce((styles, styleName) => {
138
+ if (styleName !== null && styleName !== void 0 && styleName.startsWith(_const.CUSTOM_STYLE_PREFIX_FONT_COLOR)) {
139
+ styles['color'] = styleName.split(_const.CUSTOM_STYLE_PREFIX_FONT_COLOR)[1];
140
+ }
141
+
142
+ if (styleName !== null && styleName !== void 0 && styleName.startsWith(_const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR)) {
143
+ const highlightColor = styleName.split(_const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR)[1];
144
+ styles['background'] = `linear-gradient(to top, transparent 25%, ${highlightColor} 25% 75%, transparent 75%)`;
145
+ }
146
+
147
+ return styles;
148
+ }, {});
149
+ };
150
+
151
+ const blockStyleFn = (editorState, block) => {
152
+ var _entity$getData;
153
+
154
+ const entityKey = block.getEntityAt(0);
155
+ const entity = entityKey ? editorState.getCurrentContent().getEntity(entityKey) : null;
156
+ let result = '';
157
+ const blockData = block.getData();
158
+
159
+ if (blockData) {
160
+ const textAlign = blockData === null || blockData === void 0 ? void 0 : blockData.get('textAlign');
161
+
162
+ if (textAlign === 'center') {
163
+ result += 'alignCenter ';
164
+ } else if (textAlign === 'left') {
165
+ result += 'alignLeft ';
166
+ }
167
+ }
168
+
169
+ switch (block.getType()) {
170
+ case 'header-two':
171
+ case 'header-three':
172
+ case 'header-four':
173
+ case 'blockquote':
174
+ result += 'public-DraftStyleDefault-' + block.getType();
175
+ break;
176
+
177
+ case 'atomic':
178
+ if ((_entity$getData = entity.getData()) !== null && _entity$getData !== void 0 && _entity$getData.alignment) {
179
+ // support all atomic block to set alignment
180
+ result += ' ' + entity.getData().alignment;
181
+ }
182
+
183
+ break;
184
+
185
+ default:
186
+ break;
187
+ }
188
+
189
+ return result;
190
+ };
191
+
192
+ const blockRendererFn = block => {
193
+ const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
194
+ return atomicBlockObj;
195
+ };
196
+
197
+ function DraftRenderer({
198
+ rawContentBlock,
199
+ insertRecommend = [],
200
+ contentType = _types.ValidPostContentType.NORMAL
201
+ }) {
202
+ //if `rawContentBlock` has no data, throw error
203
+ if (!rawContentBlock || !rawContentBlock.blocks || !rawContentBlock.blocks.length) {
204
+ throw new Error('There is no content in rawContentBlock, please check again.');
205
+ }
206
+
207
+ let contentState; //if `rawContentBlock` data need to insert recommends, use `insertRecommendInContent` utils
208
+
209
+ if (insertRecommend.length) {
210
+ const contentWithRecommend = (0, _post.insertRecommendInContentBlock)(rawContentBlock, insertRecommend);
211
+ contentState = (0, _draftJs.convertFromRaw)(contentWithRecommend);
212
+ } else {
213
+ //if `rawContentBlock` data has no recommends, only remove empty content blocks
214
+ const contentRemoveEmpty = (0, _common.removeEmptyContentBlock)(rawContentBlock);
215
+ contentState = (0, _draftJs.convertFromRaw)(contentRemoveEmpty);
216
+ }
217
+
218
+ const editorState = _draftJs.EditorState.createWithContent(contentState, _entityDecorator.default);
219
+
220
+ return /*#__PURE__*/_react.default.createElement(_styledComponents.ThemeProvider, {
221
+ theme: _theme.default
222
+ }, /*#__PURE__*/_react.default.createElement(DraftEditorWrapper, {
223
+ contentType: contentType
224
+ }, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
225
+ editorState: editorState,
226
+ customStyleMap: customStyleMap,
227
+ blockStyleFn: blockStyleFn.bind(null, editorState),
228
+ blockRendererFn: blockRendererFn,
229
+ customStyleFn: customStyleFn,
230
+ readOnly: true // eslint-disable-next-line @typescript-eslint/no-empty-function
231
+ ,
232
+ onChange: () => {}
233
+ })));
234
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _draftJs = require("draft-js");
9
+
10
+ var _entityDecorators = require("./entity-decorators");
11
+
12
+ const {
13
+ annotationDecorator,
14
+ linkDecorator
15
+ } = _entityDecorators.entityDecorators;
16
+ const decorators = new _draftJs.CompositeDecorator([annotationDecorator, linkDecorator]);
17
+ var _default = decorators;
18
+ exports.default = _default;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.annotationDecorator = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
11
+
12
+ var _sharedStyle = require("../shared-style");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 annotationArrow = "https://unpkg.com/@kids-reporter/draft-renderer@0.1.0/lib/public/07d1287fd390346af0c15b930148a5e4.png";
21
+ const annotationDefaultSpacing = 8;
22
+ const AnnotationText = _styledComponents.default.span`
23
+ ${_sharedStyle.defaultLinkStyle};
24
+ `;
25
+ const AnnotationWrapper = _styledComponents.default.span`
26
+ display: inline-block;
27
+ cursor: pointer;
28
+
29
+ &:hover ${AnnotationText} {
30
+ border-bottom: 2px solid #04295e;
31
+ }
32
+ `;
33
+ const AnnotationBody = _styledComponents.default.div`
34
+ border-radius: 2px;
35
+ background-color: #f6f6fb;
36
+ padding: 12px 24px;
37
+ margin: 8px 0 32px;
38
+ font-size: 16px;
39
+ font-weight: 400;
40
+ line-height: 1.6;
41
+ display: inline-block;
42
+ text-align: left;
43
+ width: 100%;
44
+ color: rgba(0, 9, 40, 0.87);
45
+
46
+ ${({
47
+ theme
48
+ }) => theme.breakpoint.md} {
49
+ padding: 16px 32px;
50
+ }
51
+
52
+ > * + * {
53
+ margin: ${annotationDefaultSpacing}px 0 0;
54
+ min-height: 0.01px; //to make margins between paragraphs effective
55
+ }
56
+
57
+ h2 {
58
+ ${_sharedStyle.defaultH2Style}
59
+ }
60
+
61
+ ul {
62
+ ${_sharedStyle.defaultUlStyle}
63
+ margin-top: ${annotationDefaultSpacing}px;
64
+
65
+ > li {
66
+ ${_sharedStyle.defaultUnorderedListStyle}
67
+ }
68
+ }
69
+
70
+ ol {
71
+ ${_sharedStyle.defaultOlStyle}
72
+ margin-top: ${annotationDefaultSpacing}px;
73
+
74
+ > li {
75
+ ${_sharedStyle.defaultOrderedListStyle}
76
+ }
77
+ }
78
+
79
+ a {
80
+ ${_sharedStyle.defaultLinkStyle}
81
+ }
82
+
83
+ blockquote {
84
+ ${_sharedStyle.defaultBlockQuoteStyle}
85
+ }
86
+ `;
87
+ const ArrowIcon = _styledComponents.default.span`
88
+ width: 24px;
89
+ height: 24px;
90
+ background-image: url(${annotationArrow});
91
+ background-repeat: no-repeat;
92
+ background-position: center center;
93
+ background-size: 24px;
94
+ margin: auto 4px;
95
+ transition: transform 0.3s;
96
+ display: inline-flex;
97
+ vertical-align: text-top;
98
+ transform: ${props => props.showContent ? 'rotate(-180deg)' : ''};
99
+ `;
100
+
101
+ function AnnotationBlock(props) {
102
+ const {
103
+ children: annotated
104
+ } = props;
105
+ const [showContent, setShowContent] = (0, _react.useState)(false);
106
+ /**
107
+ * to support k5 old annotation data, check if annotation key exist
108
+ * k5
109
+ * {
110
+ * text: string,
111
+ * annotation: html string,
112
+ * draftRawObj: DraftBlocks
113
+ * }
114
+ * k6
115
+ * {
116
+ * bodyHTML: string,
117
+ * bodyEscapedHTML: string,
118
+ * rawContentState: DraftBlocks
119
+ * }
120
+ */
121
+
122
+ const {
123
+ bodyHTML,
124
+ annotation
125
+ } = props.contentState.getEntity(props.entityKey).getData();
126
+ const annotationBodyHtml = bodyHTML || annotation.trim();
127
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(AnnotationWrapper, {
128
+ onClick: e => {
129
+ e.preventDefault();
130
+ setShowContent(!showContent);
131
+ }
132
+ }, /*#__PURE__*/_react.default.createElement(AnnotationText, {
133
+ className: "text"
134
+ }, annotated), /*#__PURE__*/_react.default.createElement(ArrowIcon, {
135
+ showContent: showContent
136
+ })), showContent ? /*#__PURE__*/_react.default.createElement(AnnotationBody, {
137
+ contentEditable: false,
138
+ dangerouslySetInnerHTML: {
139
+ __html: annotationBodyHtml
140
+ }
141
+ }) : null);
142
+ }
143
+
144
+ function findAnnotationEntities(contentBlock, callback, contentState) {
145
+ contentBlock.findEntityRanges(character => {
146
+ const entityKey = character.getEntity();
147
+ return entityKey !== null && contentState.getEntity(entityKey).getType() === 'ANNOTATION';
148
+ }, callback);
149
+ }
150
+
151
+ const annotationDecorator = {
152
+ strategy: findAnnotationEntities,
153
+ component: AnnotationBlock
154
+ };
155
+ exports.annotationDecorator = annotationDecorator;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.entityDecorators = void 0;
7
+
8
+ var _annotationDecorator = require("./annotation-decorator");
9
+
10
+ var _linkDecorator = require("./link-decorator");
11
+
12
+ const entityDecorators = {
13
+ annotationDecorator: _annotationDecorator.annotationDecorator,
14
+ linkDecorator: _linkDecorator.linkDecorator
15
+ };
16
+ exports.entityDecorators = entityDecorators;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.linkDecorator = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const LinkWrapper = _styledComponents.default.a`
15
+ display: inline;
16
+ border-bottom: 2px solid #ebf02c;
17
+ letter-spacing: 0.01em;
18
+ text-align: justify;
19
+ color: rgba(0, 9, 40, 0.87);
20
+ padding-bottom: 2px;
21
+
22
+ &:hover {
23
+ border-bottom: 2px solid #04295e;
24
+ }
25
+ `;
26
+
27
+ function findLinkEntities(contentBlock, callback, contentState) {
28
+ contentBlock.findEntityRanges(character => {
29
+ const entityKey = character.getEntity();
30
+ return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK';
31
+ }, callback);
32
+ }
33
+
34
+ const linkDecorator = {
35
+ strategy: findLinkEntities,
36
+ component: Link
37
+ };
38
+ exports.linkDecorator = linkDecorator;
39
+
40
+ function Link(props) {
41
+ const {
42
+ url
43
+ } = props.contentState.getEntity(props.entityKey).getData();
44
+ return /*#__PURE__*/_react.default.createElement(LinkWrapper, {
45
+ href: url,
46
+ target: "_blank"
47
+ }, props.children);
48
+ }
package/lib/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _blockRenderers = require("./block-renderers");
9
+
10
+ var _draftRenderer = _interopRequireDefault(require("./draft-renderer"));
11
+
12
+ var _entityDecorators = require("./entity-decorators");
13
+
14
+ var _common = require("./utils/common");
15
+
16
+ var _post = require("./utils/post");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ var _default = {
21
+ DraftRenderer: _draftRenderer.default,
22
+ blockRenderers: _blockRenderers.blockRenderers,
23
+ entityDecorators: _entityDecorators.entityDecorators,
24
+ hasContentInRawContentBlock: _common.hasContentInRawContentBlock,
25
+ removeEmptyContentBlock: _common.removeEmptyContentBlock,
26
+ getSideIndexEntityData: _post.getSideIndexEntityData,
27
+ insertRecommendInContentBlock: _post.insertRecommendInContentBlock,
28
+ getFirstBlockEntityType: _post.getFirstBlockEntityType
29
+ };
30
+ exports.default = _default;