@kids-reporter/draft-editor 0.1.1 → 0.2.1

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 (38) hide show
  1. package/lib/buttons/annotation.js +1 -14
  2. package/lib/buttons/image.js +0 -3
  3. package/lib/buttons/info-box.js +1 -4
  4. package/lib/draft-editor.js +61 -363
  5. package/package.json +7 -2
  6. package/lib/block-renderer/background-image-block.js +0 -141
  7. package/lib/block-renderer/background-video-block.js +0 -151
  8. package/lib/block-renderer/color-box-block.js +0 -86
  9. package/lib/block-renderer/info-box-block.js +0 -86
  10. package/lib/block-renderer/side-index-block.js +0 -90
  11. package/lib/block-renderer/table-block.js +0 -408
  12. package/lib/block-renderer-fn.js +0 -125
  13. package/lib/buttons/audio.js +0 -65
  14. package/lib/buttons/background-color.js +0 -122
  15. package/lib/buttons/background-image.js +0 -223
  16. package/lib/buttons/background-video.js +0 -223
  17. package/lib/buttons/color-box.js +0 -173
  18. package/lib/buttons/divider.js +0 -63
  19. package/lib/buttons/font-color.js +0 -115
  20. package/lib/buttons/media.js +0 -121
  21. package/lib/buttons/related-post.js +0 -71
  22. package/lib/buttons/selector/audio-selector.js +0 -279
  23. package/lib/buttons/selector/post-selector.js +0 -317
  24. package/lib/buttons/selector/video-selector.js +0 -281
  25. package/lib/buttons/side-index.js +0 -200
  26. package/lib/buttons/table.js +0 -67
  27. package/lib/buttons/text-align.js +0 -88
  28. package/lib/buttons/video.js +0 -65
  29. package/lib/buttons/youtube.js +0 -147
  30. package/lib/const.js +0 -18
  31. package/lib/draft-converter/api-data-instance.js +0 -58
  32. package/lib/draft-converter/atomic-block-processor.js +0 -233
  33. package/lib/draft-converter/entities.js +0 -76
  34. package/lib/draft-converter/index.js +0 -201
  35. package/lib/draft-converter/inline-styles-processor.js +0 -236
  36. package/lib/entity-decorator.js +0 -20
  37. package/lib/modifier.js +0 -68
  38. package/lib/theme/index.js +0 -39
@@ -1,201 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _immutable = require("immutable");
9
-
10
- var _lodash = _interopRequireDefault(require("lodash"));
11
-
12
- var InlineStylesProcessor = _interopRequireWildcard(require("./inline-styles-processor"));
13
-
14
- var _apiDataInstance = _interopRequireDefault(require("./api-data-instance"));
15
-
16
- var _atomicBlockProcessor = _interopRequireDefault(require("./atomic-block-processor"));
17
-
18
- var _entities = _interopRequireDefault(require("./entities"));
19
-
20
- 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); }
21
-
22
- 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; }
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- // Modified from https://github.com/dburrows/draft-js-basic-html-editor/blob/master/src/utils/draftRawToHtml.js
27
- // 'use strict';
28
- let defaultBlockTagMap = {
29
- atomic: `<div>%content%</div>`,
30
- blockquote: `<blockquote>%content%</blockquote>`,
31
- 'code-block': `<code>%content%</code>`,
32
- default: `<p>%content%</p>`,
33
- 'header-two': `<h2>%content%</h2>`,
34
- 'header-three': `<h3>%content%</h3>`,
35
- 'header-four': `<h4>%content%</h4>`,
36
- 'ordered-list-item': `<li>%content%</li>`,
37
- paragraph: `<p>%content%</p>`,
38
- 'unordered-list-item': `<li>%content%</li>`,
39
- unstyled: `<p>%content%</p>`
40
- };
41
- let inlineTagMap = {
42
- BOLD: ['<strong>', '</strong>'],
43
- CODE: ['<code>', '</code>'],
44
- default: ['<span>', '</span>'],
45
- ITALIC: ['<em>', '</em>'],
46
- UNDERLINE: ['<u>', '</u>']
47
- };
48
- let defaultEntityTagMap = {
49
- [_entities.default.DIVIDER.type]: ['<hr>', ''],
50
- [_entities.default.ANNOTATION.type]: ['<abbr title="<%= data.body %>"><%= data.text %>', '</abbr>'],
51
- [_entities.default.AUDIO.type]: ['<div class="audio-container center"><div class="audio-title"><%= data.name %></div><!-- <div class="audio-desc"><%= data.description %></div> --><audio src="<%= data.url %>" />', '</div>'],
52
- [_entities.default.BLOCKQUOTE.type]: ['<blockquote class="center"><div><%= data.quote %></div><div><%= data.quotedBy %></div>', '<blockquote>'],
53
- [_entities.default.EMBEDDEDCODE.type]: ['<div class="embedded <%= data.alignment %>" title="<%= data.caption %>"><%= data.code%>', '</div>'],
54
- [_entities.default.INFOBOX.type]: ['<div class="info-box-container center"><div class="info-box-title"><%= data.title %></div><div class="info-box-body"><%= data.body %></div>', '</div>'],
55
- [_entities.default.STOREDIMAGE.type]: ['<img alt="<%= data.name %>" src="<%= data.url %>" srcset="<%= data.urlMobileSized %> 800w, <%= data.urlTabletSized %> 1280w, <%= data.urlDesktopSized %> 2400w" class="center">', '</img>'],
56
- [_entities.default.IMAGE.type]: ['<img alt="<%=data.name%>" src="<%=data.url%>" srcset="<%= data.mobile.url %> 800w, <%= data.tablet.url %> 1280w, <%= data.desktop.url %> 2400w" class="center">', '</img>'],
57
-
58
- /*[ENTITY.IMAGEDIFF.type]: ['<!-- imageDiff component start --> <ol class="image-diff-container"> <% _.forEach(data, function(image, index) { if (index > 1) { return; } %><li class="image-diff-item"><img src="<%- image.url %>" /></li><% }); %>', '</ol><!-- imageDiff component end-->'],
59
- [ENTITY.IMAGELINK.type]: ['<img alt="<%= data.description %>" src="<%= data.url %>" class="<%= data.alignment %>">', '</img>'],*/
60
- [_entities.default.LINK.type]: ['<a target="_blank" href="<%= data.url %>">', '</a>'],
61
- [_entities.default.SLIDESHOW.type]: ['<!-- slideshow component start --> <ol class="slideshow-container"> <% _.forEach(data, function(image) { %><li class="slideshow-slide"><img alt="<%- image.name %>" src="<%- image.url %>" srcset="<%= image.mobile.url %> 800w, <%= image.tablet.url %> 1280w, <%= image.desktop.url %> 2400w" /></li><% }); %>', '</ol><!-- slideshow component end -->'],
62
- [_entities.default.VIDEO.type]: ['<div controls class="video-container <%= data.alignment %>"><div class="video-name"><%= data.title %></div><div class="video-desc"><%= data.description %></div><video src="<%= data.url %>" />', '</div>'],
63
- [_entities.default.YOUTUBE.type]: ['<iframe width="560" alt="<%= data.description %>" height="315" src="https://www.youtube.com/embed/<%= data.id %>" frameborder="0" allowfullscreen>', '</iframe>']
64
- };
65
- let nestedTagMap = {
66
- 'ordered-list-item': ['<ol>', '</ol>'],
67
- 'unordered-list-item': ['<ul>', '</ul>']
68
- };
69
-
70
- function _convertInlineStyle(block, entityMap, blockTagMap, entityTagMap) {
71
- return blockTagMap[block.type] ? blockTagMap[block.type].replace('%content%', InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block)) : blockTagMap.default.replace('%content%', InlineStylesProcessor.convertToHtml(inlineTagMap, block));
72
- }
73
-
74
- function _convertBlocksToHtml(blocks, entityMap, blockTagMap, entityTagMap) {
75
- let html = '';
76
- let nestLevel = []; // store the list type of the previous item: null/ol/ul
77
-
78
- blocks.forEach(block => {
79
- // create tag for <ol> or <ul>: deal with ordered/unordered list item
80
- // if the block is a list-item && the previous block is not a list-item
81
- if (nestedTagMap[block.type] && nestLevel[0] !== block.type) {
82
- html += nestedTagMap[block.type][0]; // start with <ol> or <ul>
83
-
84
- nestLevel.unshift(block.type);
85
- } // end tag with </ol> or </ul>: deal with ordered/unordered list item
86
-
87
-
88
- if (nestLevel.length > 0 && nestLevel[0] !== block.type) {
89
- html += nestedTagMap[nestLevel.shift()][1]; // close with </ol> or </ul>
90
- }
91
-
92
- html += _convertInlineStyle(block, entityMap, blockTagMap, entityTagMap);
93
- }); // end tag with </ol> or </ul>: or if it is the last block
94
-
95
- if (blocks.length > 0 && nestedTagMap[blocks[blocks.length - 1].type]) {
96
- html += nestedTagMap[nestLevel.shift()][1]; // close with </ol> or </ul>
97
- }
98
-
99
- return html;
100
- }
101
-
102
- function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
103
- let apiDataArr = (0, _immutable.List)();
104
- let content = [];
105
- let nestLevel = [];
106
- blocks.forEach(block => {
107
- // block is not a list-item
108
- if (!nestedTagMap[block.type]) {
109
- // if previous block is a list-item
110
- if (content.length > 0 && nestLevel.length > 0) {
111
- apiDataArr = apiDataArr.push(new _apiDataInstance.default({
112
- type: nestLevel[0],
113
- content: [content]
114
- }));
115
- content = [];
116
- nestLevel.shift();
117
- }
118
-
119
- if (block.type.startsWith('atomic') || block.type.startsWith('media')) {
120
- try {
121
- apiDataArr = apiDataArr.push(_atomicBlockProcessor.default.convertBlock(entityMap, block));
122
- } catch (e) {
123
- console.error(e);
124
- }
125
- } else {
126
- var _block$data;
127
-
128
- let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block);
129
- const type = block.type;
130
- const textAlign = (_block$data = block.data) === null || _block$data === void 0 ? void 0 : _block$data.textAlign;
131
- apiDataArr = apiDataArr.push(new _apiDataInstance.default({
132
- id: block.key,
133
- type,
134
- content: [converted],
135
- textAlign
136
- }));
137
- }
138
- } else {
139
- let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block); // previous block is not an item-list block
140
-
141
- if (nestLevel.length === 0) {
142
- nestLevel.unshift(block.type);
143
- content.push(converted);
144
- } else if (nestLevel[0] === block.type) {
145
- // previous block is a item-list and current block is the same item-list
146
- content.push(converted);
147
- } else if (nestLevel[0] !== block.type) {
148
- // previous block is a different item-list.
149
- apiDataArr = apiDataArr.push(new _apiDataInstance.default({
150
- id: block.key,
151
- type: nestLevel[0],
152
- content: [content]
153
- }));
154
- content = [converted];
155
- nestLevel[0] = block.type;
156
- }
157
- }
158
- }); // last block is a item-list
159
-
160
- if (blocks.length > 0 && nestLevel.length > 0) {
161
- let block = blocks[blocks.length - 1];
162
- apiDataArr = apiDataArr.push(new _apiDataInstance.default({
163
- id: block.key,
164
- type: block.type,
165
- content: content
166
- }));
167
- }
168
-
169
- return apiDataArr;
170
- }
171
-
172
- function convertRawToHtml(raw, blockTagMap, entityTagMap) {
173
- blockTagMap = _lodash.default.merge({}, defaultBlockTagMap, blockTagMap);
174
- entityTagMap = entityTagMap || defaultEntityTagMap;
175
- let html = '';
176
- raw = raw || {};
177
- const blocks = Array.isArray(raw.blocks) ? raw.blocks : [];
178
- const entityMap = typeof raw.entityMap === 'object' ? raw.entityMap : {};
179
- html = _convertBlocksToHtml(blocks, entityMap, blockTagMap, entityTagMap);
180
- return html;
181
- }
182
-
183
- function convertRawToApiData(raw) {
184
- let apiData;
185
- raw = raw || {};
186
- const blocks = Array.isArray(raw.blocks) ? raw.blocks : [];
187
- const entityMap = typeof raw.entityMap === 'object' ? raw.entityMap : {};
188
-
189
- let entityTagMap = _lodash.default.merge({}, defaultEntityTagMap, {
190
- [_entities.default.ANNOTATION.type]: [`<span data-entity-type="annotation" data-annotation-body="<%= data.bodyEscapedHTML %>">`, '</span>']
191
- });
192
-
193
- apiData = convertBlocksToApiData(blocks, entityMap, entityTagMap);
194
- return apiData;
195
- }
196
-
197
- var _default = {
198
- convertToHtml: convertRawToHtml,
199
- convertToApiData: convertRawToApiData
200
- };
201
- exports.default = _default;
@@ -1,236 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.convertToHtml = convertToHtml;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
-
10
- var _const = require("../const");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- // Modified from https://github.com/dburrows/draft-js-basic-html-editor/blob/master/src/utils/processInlineStylesAndEntities.js
15
- function tagForCustomInlineStyle(style) {
16
- const customInlineStylePrefixs = [_const.CUSTOM_STYLE_PREFIX_FONT_COLOR, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR];
17
- const stylePrefix = customInlineStylePrefixs.find(prefix => style.startsWith(prefix));
18
- let tag, value;
19
-
20
- switch (stylePrefix) {
21
- case _const.CUSTOM_STYLE_PREFIX_FONT_COLOR:
22
- value = style.split(_const.CUSTOM_STYLE_PREFIX_FONT_COLOR)[1];
23
- tag = [`<span style="color: ${value}">`, '</span>'];
24
- break;
25
-
26
- case _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR:
27
- value = style.split(_const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR)[1];
28
- tag = [`<span style="background-color: ${value}">`, '</span>'];
29
- break;
30
-
31
- default:
32
- break;
33
- }
34
-
35
- return tag;
36
- }
37
-
38
- function _fullfilIntersection(block) {
39
- // SORT BEFORE PROCESSING
40
- let sortedISRanges = _lodash.default.sortBy(block.inlineStyleRanges, 'offset');
41
-
42
- let sortedEntityRanges = _lodash.default.sortBy(block.entityRanges, 'offset');
43
-
44
- let splitedISInline = [];
45
-
46
- for (let i = 0; i < sortedEntityRanges.length; i++) {
47
- let entityRange = sortedEntityRanges[i];
48
-
49
- for (let j = 0; j < sortedISRanges.length; j++) {
50
- let entityOffset = _lodash.default.get(entityRange, 'offset', 0);
51
-
52
- let entityLength = _lodash.default.get(entityRange, 'length', 0);
53
-
54
- let inlineLength = _lodash.default.get(sortedISRanges, [j, 'length'], 0);
55
-
56
- let inlineOffset = _lodash.default.get(sortedISRanges, [j, 'offset'], 0);
57
-
58
- let inlineStyle = _lodash.default.get(sortedISRanges, [j, 'style'], '');
59
-
60
- let nextEntityOffset = _lodash.default.get(sortedEntityRanges, [i + 1, 'offset'], 0);
61
-
62
- let nextEntityLength = _lodash.default.get(sortedEntityRanges, [i + 1, 'length'], 0); // handle intersections of inline style and entity
63
- // <a></a> is entity
64
- // <abbr></abbr> is next entity
65
- // <strong></strong> is inline style
66
-
67
-
68
- if (nextEntityOffset >= inlineOffset && nextEntityOffset < inlineOffset + inlineLength && nextEntityOffset + nextEntityLength > inlineOffset + inlineLength && // <a><strong></a></strong>
69
- entityOffset < inlineOffset && entityOffset + entityLength > inlineOffset && entityOffset + entityLength <= inlineOffset + inlineLength) {
70
- // <strong><abbr></strong></abbr>
71
- // situation: <a><strong></a><abbr></strong></abbr>
72
- // should be: <a><strong></strong></a><strong></strong><abbr><strong></strong></abbr>
73
- // skip next entity checking
74
- i = i + 1;
75
- splitedISInline.push({
76
- index: j,
77
- replace: [{
78
- length: entityOffset + entityLength - inlineOffset,
79
- offset: inlineOffset,
80
- style: inlineStyle
81
- }, {
82
- length: nextEntityOffset - (entityOffset + entityLength),
83
- offset: entityOffset + entityLength,
84
- style: inlineStyle
85
- }, {
86
- length: inlineOffset + inlineLength - nextEntityOffset,
87
- offset: nextEntityOffset,
88
- style: inlineStyle
89
- }]
90
- });
91
- } else if (entityOffset >= inlineOffset && entityOffset < inlineOffset + inlineLength && entityOffset + entityLength > inlineOffset + inlineLength) {
92
- // situation: <strong><a></strong></a>
93
- // should be: <strong></strong><a><strong></strong></a>
94
- splitedISInline.push({
95
- index: j,
96
- replace: [{
97
- length: entityOffset - inlineOffset,
98
- offset: inlineOffset,
99
- style: inlineStyle
100
- }, {
101
- length: inlineOffset + inlineLength - entityOffset,
102
- offset: entityOffset,
103
- style: inlineStyle
104
- }]
105
- });
106
- } else if (entityOffset < inlineOffset && entityOffset + entityLength > inlineOffset && entityOffset + entityLength <= inlineOffset + inlineLength) {
107
- // situation: <a><strong></a></strong>
108
- // should be: <a><strong></strong></a><strong></strong>
109
- splitedISInline.push({
110
- index: j,
111
- replace: [{
112
- length: entityOffset + entityLength - inlineOffset,
113
- offset: inlineOffset,
114
- style: inlineStyle
115
- }, {
116
- length: inlineOffset + inlineLength - entityOffset - entityLength,
117
- offset: entityOffset + entityLength,
118
- style: inlineStyle
119
- }]
120
- });
121
- }
122
- }
123
- }
124
-
125
- _lodash.default.forEachRight(splitedISInline, ele => {
126
- sortedISRanges.splice(ele.index, 1, ...ele.replace);
127
- });
128
-
129
- return sortedISRanges;
130
- }
131
-
132
- function _inlineTag(inlineTagMap, inlineStyleRanges, tagInsertMap = {}) {
133
- // SORT BEFORE PROCESSING
134
- let sortedRanges = _lodash.default.sortBy(inlineStyleRanges, 'offset'); // map all the tag insertions we're going to do
135
-
136
-
137
- sortedRanges.forEach(function (range) {
138
- let tag = inlineTagMap[range.style]; // handle dynamic inline style
139
-
140
- if (!tag) {
141
- tag = tagForCustomInlineStyle(range.style);
142
- }
143
-
144
- if (!tagInsertMap[range.offset]) {
145
- tagInsertMap[range.offset] = [];
146
- } // add starting tag to the end of the array to form the tag nesting
147
-
148
-
149
- tagInsertMap[range.offset].push(tag[0]);
150
-
151
- if (tag[1]) {
152
- if (!tagInsertMap[range.offset + range.length]) {
153
- tagInsertMap[range.offset + range.length] = [];
154
- } // add closing tags to start of array, otherwise tag nesting will be invalid
155
-
156
-
157
- tagInsertMap[range.offset + range.length].unshift(tag[1]);
158
- }
159
- });
160
- return tagInsertMap;
161
- }
162
-
163
- function _entityTag(entityTagMap, entityMap, entityRanges, tagInsertMap = {}) {
164
- _lodash.default.forEach(entityRanges, range => {
165
- let entity = entityMap[range.key];
166
- let type = entity.type && entity.type.toUpperCase();
167
- let tag = entityTagMap[type];
168
- let data = entity.data;
169
-
170
- let compiledTag0 = _lodash.default.template(tag[0], {
171
- variable: 'data'
172
- })(data);
173
-
174
- let compiledTag1 = _lodash.default.template(tag[1], {
175
- variable: 'data'
176
- })(data);
177
-
178
- if (!tagInsertMap[range.offset]) {
179
- tagInsertMap[range.offset] = [];
180
- } // add starting tag
181
-
182
-
183
- tagInsertMap[range.offset].push(compiledTag0);
184
-
185
- if (tag[1]) {
186
- if (!tagInsertMap[range.offset + range.length]) {
187
- tagInsertMap[range.offset + range.length] = [];
188
- } // add closing tags to start of array, otherwise tag nesting will be invalid
189
-
190
-
191
- tagInsertMap[range.offset + range.length].unshift(compiledTag1);
192
- }
193
- });
194
-
195
- return tagInsertMap;
196
- }
197
-
198
- function convertToHtml(inlineTagMap, entityTagMap, entityMap, block) {
199
- // exit if there is no inlineStyleRanges/entityRanges or length === 0 as well
200
- if (!block.inlineStyleRanges && !block.entityRanges || block.inlineStyleRanges.length === 0 && block.entityRanges.length === 0) {
201
- return block.text;
202
- }
203
-
204
- let html = block.text;
205
-
206
- let inlineStyleRanges = _fullfilIntersection(block);
207
-
208
- let tagInsertMap = {};
209
- tagInsertMap = _entityTag(entityTagMap, entityMap, block.entityRanges, tagInsertMap);
210
- tagInsertMap = _inlineTag(inlineTagMap, inlineStyleRanges, tagInsertMap); // sort on position, as we'll need to keep track of offset
211
-
212
- let orderedKeys = Object.keys(tagInsertMap).sort(function (a, b) {
213
- a = Number(a);
214
- b = Number(b);
215
-
216
- if (a > b) {
217
- return 1;
218
- }
219
-
220
- if (a < b) {
221
- return -1;
222
- }
223
-
224
- return 0;
225
- }); // insert tags into string, keep track of offset caused by our text insertions
226
-
227
- let offset = 0;
228
- orderedKeys.forEach(function (pos) {
229
- let index = Number(pos);
230
- tagInsertMap[pos].forEach(function (tag) {
231
- html = html.substr(0, offset + index) + tag + html.substr(offset + index);
232
- offset += tag.length;
233
- });
234
- });
235
- return html;
236
- }
@@ -1,20 +0,0 @@
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 _draftRenderer = _interopRequireDefault(require("@kids-reporter/draft-renderer"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const {
15
- annotationDecorator,
16
- linkDecorator
17
- } = _draftRenderer.default.entityDecorators;
18
- const decorators = new _draftJs.CompositeDecorator([annotationDecorator, linkDecorator]);
19
- var _default = decorators;
20
- exports.default = _default;
package/lib/modifier.js DELETED
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Modifier = void 0;
7
-
8
- var _draftJs = require("draft-js");
9
-
10
- var _immutable = require("immutable");
11
-
12
- const Modifier = { ..._draftJs.Modifier
13
- };
14
- /*
15
- This method is specified for custom inline style such as 'FONT_COLOR_#ffffff'.
16
- For this kind of inline style there may be more than one style name 'FONT_COLOR_#ffffff', 'FONT_COLOR_#000000'.
17
- To prevent any nested specific inline style got rendered after the outer inline style being removed,
18
- clear all specific inline styles when custom inline style is applied or removed.
19
-
20
- Since getCurrentInlineStyle only return the inline style the starting position contains,
21
- loop through all char of blocks to remove all nested inline styles.
22
-
23
- Reference: https://github.com/facebook/draft-js/blob/main/src/model/transaction/ContentStateInlineStyle.js#L39-L88
24
- */
25
-
26
- exports.Modifier = Modifier;
27
-
28
- Modifier.removeInlineStyleByPrefix = (contentState, selectionState, inlineStylePrefix) => {
29
- const blockMap = contentState.getBlockMap();
30
- const startKey = selectionState.getStartKey();
31
- const startOffset = selectionState.getStartOffset();
32
- const endKey = selectionState.getEndKey();
33
- const endOffset = selectionState.getEndOffset(); // loop through all selected blocks and every block chars to remove specific inline style
34
-
35
- const newBlocks = blockMap.skipUntil((_, k) => k === startKey).takeUntil((_, k) => k === endKey).concat((0, _immutable.Map)([[endKey, blockMap.get(endKey)]])).map((block, blockKey) => {
36
- let sliceStart;
37
- let sliceEnd;
38
-
39
- if (startKey === endKey) {
40
- sliceStart = startOffset;
41
- sliceEnd = endOffset;
42
- } else {
43
- sliceStart = blockKey === startKey ? startOffset : 0;
44
- sliceEnd = blockKey === endKey ? endOffset : block.getLength();
45
- }
46
-
47
- let chars = block.getCharacterList();
48
- let current;
49
-
50
- while (sliceStart < sliceEnd) {
51
- current = chars.get(sliceStart);
52
- const inlineStyle = current.getStyle().find(styleName => styleName.startsWith(inlineStylePrefix));
53
-
54
- if (inlineStyle) {
55
- chars = chars.set(sliceStart, _draftJs.CharacterMetadata.removeStyle(current, inlineStyle));
56
- }
57
-
58
- sliceStart++;
59
- }
60
-
61
- return block.set('characterList', chars);
62
- });
63
- return contentState.merge({
64
- blockMap: blockMap.merge(newBlocks),
65
- selectionBefore: selectionState,
66
- selectionAfter: selectionState
67
- });
68
- };
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.theme = exports.mediaSize = exports.default = void 0;
7
- const mediaSize = {
8
- xs: 0,
9
- sm: 576,
10
- md: 768,
11
- lg: 960,
12
- xl: 1200,
13
- xxl: 1400
14
- };
15
- exports.mediaSize = mediaSize;
16
- const theme = {
17
- breakpoint: {
18
- xs: `@media (min-width: ${mediaSize.xs}px)`,
19
- sm: `@media (min-width: ${mediaSize.sm}px)`,
20
- md: `@media (min-width: ${mediaSize.md}px)`,
21
- lg: `@media (min-width: ${mediaSize.lg}px)`,
22
- xl: `@media (min-width: ${mediaSize.xl}px)`,
23
- xxl: `@media (min-width: ${mediaSize.xxl}px)`
24
- },
25
- fontSize: {
26
- xs: 'font-size: 14px;',
27
- sm: 'font-size: 16px;',
28
- md: 'font-size: 18px;',
29
- lg: 'font-size: 24px;',
30
- xl: 'font-size: 28px;'
31
- },
32
- margin: {
33
- default: 'margin: 32px auto;',
34
- narrow: 'margin: 16px auto;'
35
- }
36
- };
37
- exports.theme = theme;
38
- var _default = theme;
39
- exports.default = _default;